From 35dc38c2fbb065bb0e2f3c4b8bd382f73da3967a Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Thu, 30 May 2024 07:43:13 +0200 Subject: [PATCH] interfaces: optional prefix tracking for WAN #5630 While here restructure and reword some of the options. Also add a possibility to disable the SLAAC address which complements this nicely and has been known to be problematic for some users. --- src/etc/inc/interfaces.inc | 11 +++- src/www/interfaces.php | 122 +++++++++++++++++++++++++++---------- 2 files changed, 98 insertions(+), 35 deletions(-) diff --git a/src/etc/inc/interfaces.inc b/src/etc/inc/interfaces.inc index 5180d8222..a49599689 100644 --- a/src/etc/inc/interfaces.inc +++ b/src/etc/inc/interfaces.inc @@ -2323,7 +2323,7 @@ function interface_configure($verbose = false, $interface = 'wan', $reload = fal set_single_sysctl('net.inet6.ip6.accept_rtadv', '1'); set_single_sysctl('net.inet6.ip6.rfc6204w3', '1'); - mwexecf('/sbin/ifconfig %s inet6 accept_rtadv -ifdisabled up', $realifv6); + mwexecf('/sbin/ifconfig %s inet6 %saccept_rtadv -ifdisabled up', [$realifv6, isset($wancfg['dhcp6deny_rtadv']) ? '-' : '']); if (!isset($wancfg['dhcp6usev4iface'])) { interface_dhcpv6_prepare($interface, $wancfg); @@ -2924,6 +2924,12 @@ function DHCP6_Config_File_Basic($interface, $wancfg, $wanif, $id = 0) $preflen = 64 - $wancfg['dhcp6-ia-pd-len']; $dhcp6cconf .= " prefix ::/{$preflen} infinity;\n"; } + if (isset($wancfg['dhcp6-prefix-id']) && is_numeric($wancfg['dhcp6-prefix-id'])) { + $dhcp6cconf .= " prefix-interface {$wanif} {\n"; + $dhcp6cconf .= " sla-id {$wancfg['dhcp6-prefix-id']};\n"; + $dhcp6cconf .= " sla-len {$wancfg['dhcp6-ia-pd-len']};\n"; + $dhcp6cconf .= " };\n"; + } foreach (link_interface_to_track6($interface) as $friendly => $lancfg) { if (is_numeric($lancfg['track6-prefix-id'])) { $trackifv6 = get_real_interface($friendly, 'inet6'); @@ -4116,7 +4122,8 @@ function interfaces_has_prefix_only($interface) $ret = empty($interfaces_a[$interface]['adv_dhcp6_config_file_override']) && ((!empty($interfaces_a[$interface]['adv_dhcp6_config_advanced']) && empty($interfaces_a[$interface]['adv_dhcp6_id_assoc_statement_address_enable'])) || - isset($interfaces_a[$interface]['dhcp6prefixonly'])); + (isset($interfaces_a[$interface]['dhcp6prefixonly']) && + !isset($interfaces_a[$interface]['dhcp6-prefix-id']))); break; default: break; diff --git a/src/www/interfaces.php b/src/www/interfaces.php index b4886de6a..cec5835e5 100644 --- a/src/www/interfaces.php +++ b/src/www/interfaces.php @@ -1,7 +1,7 @@ @@ -387,6 +387,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { 'alias-subnet', 'descr', 'dhcp6-ia-pd-len', + 'dhcp6-prefix-id', 'dhcp6vlanprio', 'dhcphostname', 'dhcprejectfrom', @@ -429,7 +430,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { $pconfig['dhcp6prefixonly'] = isset($a_interfaces[$if]['dhcp6prefixonly']); $pconfig['dhcp6usev4iface'] = isset($a_interfaces[$if]['dhcp6usev4iface']); $pconfig['track6-prefix-id--hex'] = sprintf("%x", empty($pconfig['track6-prefix-id']) ? 0 : $pconfig['track6-prefix-id']); + $pconfig['dhcp6-prefix-id--hex'] = isset($pconfig['dhcp6-prefix-id']) && $pconfig['dhcp6-prefix-id'] != '' ? sprintf("%x", $pconfig['dhcp6-prefix-id']) : ''; $pconfig['dhcpd6track6allowoverride'] = isset($a_interfaces[$if]['dhcpd6track6allowoverride']); + $pconfig['dhcp6accept_rtadv'] = !isset($a_interfaces[$if]['dhcp6deny_rtadv']); /* * Due to the settings being split per interface type, we need @@ -724,6 +727,26 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { if (!empty($pconfig['adv_dhcp6_config_file_override'] && !file_exists($pconfig['adv_dhcp6_config_file_override_path']))) { $input_errors[] = sprintf(gettext('The DHCPv6 override file "%s" does not exist.'), $pconfig['adv_dhcp6_config_file_override_path']); } + if (isset($pconfig['dhcp6-prefix-id--hex']) && $pconfig['dhcp6-prefix-id--hex'] != '') { + if (!ctype_xdigit($pconfig['dhcp6-prefix-id--hex'])) { + $input_errors[] = gettext("You must enter a valid hexadecimal number for the IPv6 prefix ID."); + } else { + $ipv6_delegation_length = calculate_ipv6_delegation_length($if); + if ($ipv6_delegation_length >= 0) { + $ipv6_num_prefix_ids = pow(2, $ipv6_delegation_length); + $dhcp6_prefix_id = intval($pconfig['dhcp6-prefix-id--hex'], 16); + if ($dhcp6_prefix_id < 0 || $dhcp6_prefix_id >= $ipv6_num_prefix_ids) { + $input_errors[] = gettext("You specified an IPv6 prefix ID that is out of range."); + } + } + foreach (link_interface_to_track6($pconfig['track6-interface']) as $trackif => $trackcfg) { + if ($trackcfg['track6-prefix-id'] == $dhcp6_prefix_id) { + $input_errors[] = gettext('You specified an IPv6 prefix ID that is already in use.'); + break; + } + } + } + } break; case '6rd': if (empty($pconfig['gateway-6rd']) || !is_ipaddrv4($pconfig['gateway-6rd'])) { @@ -772,6 +795,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { break; } } + if (isset($config['interfaces'][$pconfig['track6-interface']]['dhcp6-prefix-id'])) { + if ($config['interfaces'][$pconfig['track6-interface']]['dhcp6-prefix-id'] == $track6_prefix_id) { + $input_errors[] = gettext('You specified an IPv6 prefix ID that is already in use.'); + } + } } } break; @@ -1163,6 +1191,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { if (isset($pconfig['dhcp6vlanprio']) && $pconfig['dhcp6vlanprio'] !== '') { $new_config['dhcp6vlanprio'] = $pconfig['dhcp6vlanprio']; } + /* flipped in GUI on purpose */ + if (empty($pconfig['dhcp6accept_rtadv'])) { + $new_config['dhcp6deny_rtadv'] = true; + } + if (isset($pconfig['dhcp6-prefix-id--hex']) && ctype_xdigit($pconfig['dhcp6-prefix-id--hex'])) { + $new_config['dhcp6-prefix-id'] = intval($pconfig['dhcp6-prefix-id--hex'], 16); + } $new_config['adv_dhcp6_interface_statement_send_options'] = $pconfig['adv_dhcp6_interface_statement_send_options']; $new_config['adv_dhcp6_interface_statement_request_options'] = $pconfig['adv_dhcp6_interface_statement_request_options']; $new_config['adv_dhcp6_interface_statement_information_only_enable'] = $pconfig['adv_dhcp6_interface_statement_information_only_enable']; @@ -2617,6 +2652,40 @@ include("head.inc"); + + + + + + + + + + + /> + + + + + + /> + + + @@ -2641,15 +2710,6 @@ include("head.inc"); - - - - /> - - - @@ -2687,7 +2747,16 @@ include("head.inc"); - + + + /> + + + + + /> - - + + - /> -