From 21f1ccda942bda703abce550ac55cc7edc47b2db Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Wed, 17 May 2023 09:45:48 +0200 Subject: [PATCH] interfaces: add "autoconf" to details output While adding noticed that it wasn't added which was due to ending interation one cycle too early (last word on the line) so changed the parsing to slightly. Reaching forward with certain keywords in place is safe, just need to make sure to skip what we have read then. Same for IPv4 although less relevant. --- src/etc/inc/interfaces.lib.inc | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/etc/inc/interfaces.lib.inc b/src/etc/inc/interfaces.lib.inc index 28f1098dc..3a39c1f84 100644 --- a/src/etc/inc/interfaces.lib.inc +++ b/src/etc/inc/interfaces.lib.inc @@ -303,11 +303,15 @@ function legacy_interfaces_details($intf = null) // IPv4 information unset($mask); unset($vhid); - for ($i = 0; $i < count($line_parts) - 1; ++$i) { + for ($i = 0; $i < count($line_parts); ++$i) { if ($line_parts[$i] == 'netmask') { + /* look-ahead due to keyword match */ $mask = substr_count(base_convert(hexdec($line_parts[$i + 1]), 10, 2), '1'); + ++$i; } elseif ($line_parts[$i] == 'vhid') { + /* look-ahead due to keyword match */ $vhid = $line_parts[$i + 1]; + ++$i; } } if (isset($mask)) { @@ -325,26 +329,34 @@ function legacy_interfaces_details($intf = null) // IPv6 information $addr = strtok($line_parts[1], '%'); $tmp = [ + 'autoconf' => false, 'deprecated' => false, 'ipaddr' => $addr, 'link-local' => !!preg_match('/^fe[89ab][0-9a-f]:/i', $addr), 'tentative' => false, 'tunnel' => false, ]; - for ($i = 0; $i < count($line_parts) - 1; ++$i) { + for ($i = 0; $i < count($line_parts); ++$i) { if ($line_parts[$i] == 'prefixlen') { + /* look-ahead due to keyword match */ $tmp['subnetbits'] = intval($line_parts[$i + 1]); + ++$i; } elseif ($line_parts[$i] == 'vhid') { + /* look-ahead due to keyword match */ $tmp['vhid'] = $line_parts[$i + 1]; + ++$i; + } elseif ($line_parts[$i] == '-->') { + /* look-ahead due to keyword match */ + $tmp['endpoint'] = $line_parts[$i + 1]; + $tmp['tunnel'] = true; + ++$i; + } elseif ($line_parts[$i] == 'autoconf') { + $tmp['autoconf'] = true; } elseif ($line_parts[$i] == 'deprecated') { $tmp['deprecated'] = true; } elseif ($line_parts[$i] == 'tentative') { $tmp['tentative'] = true; } - if ($line_parts[$i] == '-->') { - $tmp['tunnel'] = true; - $tmp['endpoint'] = $line_parts[$i + 1]; - } } if (isset($tmp['subnetbits'])) { $result[$current_interface]['ipv6'][] = $tmp;