Interfaces: Other Types: VLAN - refactor to MVC framework in preparation for https://github.com/opnsense/core/issues/5560

o wrap vlan set pcp in new function legacy_vlan_pcp()
o add legacy_vlan_remove_tag() to detach our vlan
o use legacy_vlan_remove_tag() + legacy_vlan_tag() to update vlan interfaces, in which case configuration remains as it was which would make future modifications which don't rely on "logical" names easier.
This commit is contained in:
Ad Schellevis 2022-02-23 11:51:26 +01:00
parent 5959a23c79
commit 463696a23d
2 changed files with 26 additions and 5 deletions

View File

@ -163,6 +163,26 @@ function legacy_vlan_tag($ifs, $member, $tag, $pcp)
}
}
function legacy_vlan_remove_tag($ifs)
{
$cmd = '/sbin/ifconfig ' . escapeshellarg($ifs) . ' -vlandev';
exec($cmd . ' 2>&1', $out, $ret);
if ($ret) {
log_error('The command `' . $cmd . '\' failed to execute');
}
}
function legacy_vlan_pcp($ifs, $pcp)
{
$cmd = '/sbin/ifconfig ' . escapeshellarg($ifs) . ' vlanpcp ' . escapeshellarg($pcp);
exec($cmd . ' 2>&1', $out, $ret);
if ($ret) {
log_error('The command `' . $cmd . '\' failed to execute');
}
}
function legacy_interface_stats($ifs = null)
{
if ($ifs != null) {

View File

@ -67,14 +67,15 @@ foreach (legacy_interfaces_details() as $ifname => $ifdetails) {
if (empty($vlan)) {
// option 1: removed vlan
legacy_interface_destroy($ifname);
} elseif ($vlan['pcp'] != $cvlan['pcp']) {
// option 2: pcp changed, which can be altered instantly
exec('/sbin/ifconfig ' . escapeshellarg($vlan['vlanif']) . ' vlanpcp ' . escapeshellarg($vlan['pcp']) . ' 2>&1', $out, $ret);
} elseif ($vlan['tag'] != $cvlan['tag'] || $vlan['if'] != $cvlan['parent']) {
// option 3: changed vlan, recreate with appropriate settings
// option 2: changed vlan, unlink and relink
// XXX: legacy code used interface_configure() in these cases, but since you can't change a tag or a parent
// for an assigned interface. At the moment that doesn't seem to make much sense
interface_vlan_configure($vlan);
legacy_vlan_remove_tag($vlan['vlanif']);
legacy_vlan_tag($vlan['vlanif'], $vlan['if'], $vlan['tag'], $vlan['pcp']);
} elseif ($vlan['pcp'] != $cvlan['pcp']) {
// option 3: only pcp changed, which can be altered instantly
legacy_vlan_pcp($vlan['vlanif'], $vlan['pcp']);
}
unset($all_vlans[$ifname]);
}