From fac8f85a514e934c2a2d1a60f763a4d9715dc157 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Wed, 16 Aug 2023 14:45:31 +0200 Subject: [PATCH] interfaces: refactor interface_parent_devices() to take device name instead This simplifies the call a little and allows us to do better recursion away from config-based interfaces. We could just pass the device as the interface and it would work but then we pass it down twice and it's not very readable. --- src/etc/inc/interfaces.inc | 22 ++++++++-------------- src/www/interfaces.php | 4 ++-- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/etc/inc/interfaces.inc b/src/etc/inc/interfaces.inc index 30706e2ce..7054cd021 100644 --- a/src/etc/inc/interfaces.inc +++ b/src/etc/inc/interfaces.inc @@ -2341,7 +2341,7 @@ function interface_configure($verbose = false, $interface = 'wan', $reload = fal /* XXX the parent lookup works for 'vlan' but misses final parent for 'qinq' */ if (strstr($realhwif, 'vlan') || strstr($realhwif, 'qinq')) { - $parent_realif = interface_parent_devices($interface)[0]; + $parent_realif = interface_parent_devices($realhwif)[0]; $parent_details = $ifconfig_details[$parent_realif]; $parent_mtu = $mtu; @@ -3435,27 +3435,21 @@ function get_ppp_parent($ifcfg_if) } /* collect hardware device parents for VLAN, LAGG and bridges */ -function interface_parent_devices($interface) +function interface_parent_devices($device) { $parents = []; - $realif = get_real_interface($interface); - if (strstr($realif, 'pppoe')) { - /* handle lookup mismatch */ - $realif = get_ppp_parent($realif); - } - - if (strstr($realif, 'vlan') || strstr($realif, 'qinq')) { + if (strstr($device, 'vlan') || strstr($device, 'qinq')) { /* XXX maybe if we have a qinq type return both parents? */ foreach (config_read_array('vlans', 'vlan') as $vlan) { - if ($realif == $vlan['vlanif']) { + if ($device == $vlan['vlanif']) { $parents[] = $vlan['if']; break; } } - } elseif (strstr($realif, 'bridge')) { + } elseif (strstr($device, 'bridge')) { foreach (config_read_array('bridges', 'bridged') as $bridge) { - if ($realif == $bridge['bridgeif']) { + if ($device == $bridge['bridgeif']) { foreach (explode(',', $bridge['members']) as $member) { /* bridge stores members as configured interfaces */ $parents[] = get_real_interface($member); @@ -3463,9 +3457,9 @@ function interface_parent_devices($interface) break; } } - } elseif (strstr($realif, 'lagg')) { + } elseif (strstr($device, 'lagg')) { foreach (config_read_array('laggs', 'lagg') as $lagg) { - if ($realif == $lagg['laggif']) { + if ($device == $lagg['laggif']) { foreach (explode(',', $lagg['members']) as $member) { $parents[] = $member; } diff --git a/src/www/interfaces.php b/src/www/interfaces.php index 5169f244c..f1153e548 100644 --- a/src/www/interfaces.php +++ b/src/www/interfaces.php @@ -897,7 +897,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { } if (strstr($a_interfaces[$if]['if'], 'vlan') || strstr($a_interfaces[$if]['if'], 'qinq')) { - list ($parentif) = interface_parent_devices($if); + list ($parentif) = interface_parent_devices($a_interfaces[$if]['if']); $intf_details = legacy_interface_details($parentif); if ($intf_details['mtu'] < $pconfig['mtu']) { $input_errors[] = gettext("MTU of a VLAN should not be bigger than parent interface."); @@ -908,7 +908,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { continue; } - list ($parentif) = interface_parent_devices($idx); + list ($parentif) = interface_parent_devices($ifdata['if']); if ($parentif != $a_interfaces[$if]['if']) { continue; }