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.
This commit is contained in:
Franco Fichtner 2023-05-17 09:45:48 +02:00
parent 3e457864c7
commit 21f1ccda94

View File

@ -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;