interfaces: avoid recursion by giving proper interface name

Tested both VLAN configuration spots and other callers already
look sane.
This commit is contained in:
Franco Fichtner 2021-11-22 11:37:34 +01:00
parent c86c868cb2
commit 4d38eea089
2 changed files with 15 additions and 28 deletions

View File

@ -3501,31 +3501,23 @@ function DHCP_Config_File_Substitutions($wancfg, $wanif, $dhclientconf)
/* convert fxp0 -> wan, etc. */
function convert_real_interface_to_friendly_interface_name($interface = 'wan')
{
global $config;
if (!isset($config['interfaces'])) {
/* some people do trigger this, I don't know why :) */
return null;
}
// search direct
$all_interfaces = legacy_config_get_interfaces();
foreach ($all_interfaces as $if => $ifname) {
if ($if == $interface || $ifname['if'] == $interface) {
return $if;
foreach ($all_interfaces as $ifname => $ifcfg) {
if ($ifname == $interface || $ifcfg['if'] == $interface) {
return $ifname;
}
}
// search related
foreach ($all_interfaces as $if => $ifname) {
if (get_real_interface($if) == $interface) {
return $if;
foreach (array_keys($all_interfaces) as $ifname) {
if (get_real_interface($ifname) == $interface) {
return $ifname;
}
foreach (get_parent_interface($if, true) as $iface) {
if ($iface == $interface) {
return $if;
}
list ($ifparent) = get_parent_interface($ifname);
if ($ifparent == $interface) {
return $ifparent;
}
}
@ -3599,7 +3591,7 @@ function convert_friendly_interface_to_friendly_descr($interface)
* -- returns empty array if an invalid interface is passed
* (Only handles ppps and vlans now.)
*/
function get_parent_interface($interface, $avoidrecurse = false)
function get_parent_interface($interface)
{
global $config;
@ -3607,11 +3599,6 @@ function get_parent_interface($interface, $avoidrecurse = false)
$realif = get_real_interface($interface);
// If we got a real interface, find it's friendly assigned name
if ($interface == $realif && $avoidrecurse == false) {
$interface = convert_real_interface_to_friendly_interface_name($interface);
}
if (!empty($interface) && isset($config['interfaces'][$interface])) {
$ifcfg = $config['interfaces'][$interface];
switch ($ifcfg['ipaddr']) {

View File

@ -884,20 +884,20 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$input_errors[] = sprintf(gettext('The MTU must be greater than %s bytes and less than %s.'), $mtu_low, $mtu_high);
}
if (stristr($a_interfaces[$if]['if'], "_vlan")) {
list ($parentif) = get_parent_interface($a_interfaces[$if]['if']);
if (strstr($a_interfaces[$if]['if'], '_vlan')) {
list ($parentif) = get_parent_interface($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.");
}
} else {
foreach ($config['interfaces'] as $idx => $ifdata) {
if (($idx == $if) || !preg_match('/_vlan[0-9]/', $ifdata['if'])) {
if ($idx == $if || !strstr($ifdata['if'], '_vlan')) {
continue;
}
list ($parent_realhwif) = get_parent_interface($ifdata['if']);
if ($parent_realhwif != $a_interfaces[$if]['if']) {
list ($parentif) = get_parent_interface($idx);
if ($parentif != $a_interfaces[$if]['if']) {
continue;
}