From 463696a23d842a79dd8a2ce4ad3aa5b07fff72fe Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Wed, 23 Feb 2022 11:51:26 +0100 Subject: [PATCH] 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. --- src/etc/inc/interfaces.lib.inc | 20 +++++++++++++++++++ .../scripts/interfaces/reconfigure_vlans.php | 11 +++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/etc/inc/interfaces.lib.inc b/src/etc/inc/interfaces.lib.inc index bdf8f52b9..9f9d608cd 100644 --- a/src/etc/inc/interfaces.lib.inc +++ b/src/etc/inc/interfaces.lib.inc @@ -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) { diff --git a/src/opnsense/scripts/interfaces/reconfigure_vlans.php b/src/opnsense/scripts/interfaces/reconfigure_vlans.php index c12f2913a..8b09ae4bb 100755 --- a/src/opnsense/scripts/interfaces/reconfigure_vlans.php +++ b/src/opnsense/scripts/interfaces/reconfigure_vlans.php @@ -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]); }