From 79fabc8fac5f8c8444f8374748572040e96bee24 Mon Sep 17 00:00:00 2001 From: Renato Botelho Date: Thu, 11 Dec 2014 15:03:50 -0200 Subject: Fix #3790: - Do not let 2 interfaces to setup the same track6 prefix id - Show correct prefix id range for each interface --- usr/local/www/interfaces.php | 53 +++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 15 deletions(-) (limited to 'usr/local/www/interfaces.php') diff --git a/usr/local/www/interfaces.php b/usr/local/www/interfaces.php index b79da65..b3992e9 100644 --- a/usr/local/www/interfaces.php +++ b/usr/local/www/interfaces.php @@ -409,9 +409,6 @@ if (isset($wancfg['wireless'])) { } } -$ipv6_delegation_length = calculate_ipv6_delegation_length($pconfig['track6-interface']); -$ipv6_num_prefix_ids = pow(2, $ipv6_delegation_length); - if ($_POST['apply']) { unset($input_errors); if (!is_subsystem_dirty('interfaces')) @@ -470,11 +467,6 @@ if ($_POST['apply']) { unset($input_errors); $pconfig = $_POST; - if (isset($_POST['track6-interface'])) { - $ipv6_delegation_length = calculate_ipv6_delegation_length($_POST['track6-interface']); - $ipv6_num_prefix_ids = pow(2, $ipv6_delegation_length); - } - if (is_numeric("0x" . $_POST['track6-prefix-id--hex'])) $pconfig['track6-prefix-id'] = intval($_POST['track6-prefix-id--hex'], 16); else @@ -614,8 +606,17 @@ if ($_POST['apply']) { $input_errors[] = gettext("You must enter a valid hexadecimal number for the IPv6 prefix ID."); } else { $track6_prefix_id = intval($_POST['track6-prefix-id--hex'], 16); - if ($track6_prefix_id < 0 || $track6_prefix_id >= $ipv6_num_prefix_ids) { - $input_errors[] = gettext("You specified an IPv6 prefix ID that is out of range."); + if ($track6_prefix_id < 0 || $track6_prefix_id >= $_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]) { + $input_errors[] = gettext("You specified an IPv6 prefix ID that is out of range. ({$_POST['track6-interface']}) - ({$_POST['ipv6-num-prefix-ids-' . $_POST['track6-interface']]}) - ({$ipv6_delegation_length})"); + } else { + foreach ($ifdescrs as $ifent => $ifdescr) { + if ($if == $ifent) + continue; + if ($config['interfaces'][$ifent]['ipaddrv6'] == 'track6' && + $config['interfaces'][$ifent]['track6-interface'] == $_POST['track6-interface'] && + $config['interfaces'][$ifent]['track6-prefix-id'] == $track6_prefix_id) + $input_errors[] = sprintf(gettext("This track6 prefix id is already being used in %s."), $ifdescr); + } } } break; @@ -1481,6 +1482,7 @@ $types6 = array("none" => gettext("None"), "staticv6" => gettext("Static IPv6"), } case "track6": { jQuery('#none, #dhcp6, #staticv6, #_6rd, #_6to4, #slaac').hide(); + update_track6_prefix(); break; } } @@ -1609,6 +1611,17 @@ $types6 = array("none" => gettext("None"), "staticv6" => gettext("Static IPv6"), }); } + function update_track6_prefix() { + var iface = jQuery("#track6-interface").val(); + if (iface == null) + return; + var track6_prefix_ids = jQuery('#ipv6-num-prefix-ids-' + iface).val(); + if (track6_prefix_ids == null) + return; + track6_prefix_ids = parseInt(track6_prefix_ids).toString(16); + jQuery('#track6-prefix-id-range').html('(hexadecimal from 0 to ' + track6_prefix_ids + ')'); + } + //]]> @@ -2502,7 +2515,7 @@ $types6 = array("none" => gettext("None"), "staticv6" => gettext("Static IPv6"), - gettext("None"), "staticv6" => gettext("Static IPv6"), case "6to4": case "6rd": case "dhcp6": - $dynv6ifs[$iface] = $ifacename; + $dynv6ifs[$iface] = array( + 'name' => $ifacename, + 'ipv6_num_prefix_ids' => pow(2, calculate_ipv6_delegation_length($iface)) - 1 + ); break; default: continue; } } $rowIndex = 0; - foreach($dynv6ifs as $iface => $ifacename) { + foreach($dynv6ifs as $iface => $ifacedata) { $rowIndex++; echo ""; + echo ">" . htmlspecialchars($ifacedata['name']) . ""; } if ($rowIndex == 0) echo ""; ?>
+ $ifacedata) { + echo "\n"; + } + ?>

@@ -2542,10 +2563,12 @@ $types6 = array("none" => gettext("None"), "staticv6" => gettext("Static IPv6"), $track6_prefix_id_hex = sprintf("%x", $pconfig['track6-prefix-id']); ?> + +

- hexadecimal value between %x and %x here, default value is 0."), 0, $ipv6_num_prefix_ids - 1); ?> + -- cgit v1.1