diff --git a/src/etc/inc/interfaces.inc b/src/etc/inc/interfaces.inc index 80398f3f2..e74213eb8 100644 --- a/src/etc/inc/interfaces.inc +++ b/src/etc/inc/interfaces.inc @@ -946,8 +946,6 @@ function interfaces_configure($verbose = false) foreach ([$special, $track6, $bridge, $dhcp6c] as $list) { foreach ($list as $if) { interface_configure($verbose, $if); - /* XXX why do we not configure VIPs in interface_configure()? */ - interfaces_vips_configure(false, $if); } } @@ -1647,7 +1645,7 @@ function interface_ipalias_configure(&$vip) { global $config; - if ($vip['mode'] != "ipalias") { + if ($vip['mode'] != 'ipalias') { return; } @@ -1655,13 +1653,17 @@ function interface_ipalias_configure(&$vip) return; } - $if = escapeshellarg(get_real_interface($vip['interface'])); - $af = "inet"; if (is_ipaddrv6($vip['subnet'])) { - $af = "inet6"; + $if = escapeshellarg(get_real_interface($vip['interface']), 'inet6'); + $af = 'inet6'; + } else { + $if = escapeshellarg(get_real_interface($vip['interface'])); + $af = 'inet'; } - $vhid = !empty($vip['vhid']) ? "vhid " . escapeshellarg($vip['vhid']) : ""; - $gateway = !empty($vip['gateway']) ? escapeshellarg($vip['gateway']) . " " : ""; + + $vhid = !empty($vip['vhid']) ? 'vhid ' . escapeshellarg($vip['vhid']) : ''; + $gateway = !empty($vip['gateway']) ? escapeshellarg($vip['gateway']) . ' ' : ''; + mwexec("/sbin/ifconfig " . $if ." {$af} ". escapeshellarg($vip['subnet']) ."/" . escapeshellarg($vip['subnet_bits']) . " alias ".$gateway. $vhid); } @@ -2524,9 +2526,10 @@ function interface_configure($verbose = false, $interface = 'wan', $reload = fal interfaces_bring_up($wancfg['if']); } - if (!file_exists("/var/run/booting")) { - link_interface_to_vips($interface, "update"); + /* always reconfigure VIPs since late boot configuration may need it too */ + interfaces_vips_configure(false, $interface); + if (!file_exists("/var/run/booting")) { unset($gre); $gre = link_interface_to_gre($interface); if (!empty($gre)) { @@ -3838,25 +3841,6 @@ function link_interface_to_track6($wanif, $update = false) return $list; } -function link_interface_to_vips($int, $action = '') -{ - global $config; - - if (isset($config['virtualip']['vip'])) { - $result = array(); - foreach ($config['virtualip']['vip'] as $vip) { - if ($int == $vip['interface']) { - if ($action == 'update') { - interfaces_vips_configure(false, $int); - } else { - $result[] = $vip; - } - } - } - return $result; - } -} - /****f* interfaces/link_interface_to_bridge * NAME * link_interface_to_bridge - Finds out a bridge group for an interface diff --git a/src/etc/rc.newwanip b/src/etc/rc.newwanip index 3750ce56e..ffffc93a7 100755 --- a/src/etc/rc.newwanip +++ b/src/etc/rc.newwanip @@ -89,7 +89,7 @@ if (is_ipaddr($ip)) { @file_put_contents($ip_file, $ip); } -link_interface_to_vips($interface, "update"); +interfaces_vips_configure(false, $interface); $gre = link_interface_to_gre($interface); if (!empty($gre)) { diff --git a/src/etc/rc.newwanipv6 b/src/etc/rc.newwanipv6 index 92c55cb19..bb8b40053 100755 --- a/src/etc/rc.newwanipv6 +++ b/src/etc/rc.newwanipv6 @@ -108,6 +108,8 @@ if (is_ipaddr($ip)) { @file_put_contents($ip_file, $ip); } +interfaces_vips_configure(false, $interface); + $grouptmp = link_interface_to_group($interface); if (!empty($grouptmp)) { array_walk($grouptmp, 'interface_group_add_member'); diff --git a/src/www/system_gateways_edit.php b/src/www/system_gateways_edit.php index fea41be77..d09e80a1e 100644 --- a/src/www/system_gateways_edit.php +++ b/src/www/system_gateways_edit.php @@ -67,6 +67,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $input_errors[] = gettext("A valid gateway IP address must be specified."); } + $vips = []; + + foreach (config_read_array('virtualip', 'vip') as $vip) { + if ($pconfig['interface'] == $vip['interface']) { + $vips[] = $vip; + } + } + if (!empty($pconfig['gateway']) && is_ipaddr($pconfig['gateway'])) { if (is_ipaddrv4($pconfig['gateway'])) { list ($parent_ip, $parent_sn) = explode('/', find_interface_network(get_real_interface($pconfig['interface']), false)); @@ -76,17 +84,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $input_errors[] = gettext("Cannot add IPv4 Gateway Address because no IPv4 address could be found on the interface."); } else { $subnets = array(gen_subnet($parent_ip, $parent_sn) . "/" . $parent_sn); - $vips = link_interface_to_vips($pconfig['interface']); - if (is_array($vips)) { - foreach ($vips as $vip) { - if (!is_ipaddrv4($vip['subnet'])) { - continue; - } - $subnets[] = gen_subnet($vip['subnet'], $vip['subnet_bits']) . "/" . $vip['subnet_bits']; + foreach ($vips as $vip) { + if (!is_ipaddrv4($vip['subnet'])) { + continue; } + $subnets[] = gen_subnet($vip['subnet'], $vip['subnet_bits']) . "/" . $vip['subnet_bits']; } $found = false; + foreach ($subnets as $subnet) { if (ip_in_subnet($pconfig['gateway'], $subnet)) { $found = true; @@ -108,14 +114,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $input_errors[] = gettext("Cannot add IPv6 Gateway Address because no IPv6 address could be found on the interface."); } else { $subnets = array(gen_subnetv6($parent_ip, $parent_sn) . "/" . $parent_sn); - $vips = link_interface_to_vips($pconfig['interface']); - if (is_array($vips)) { - foreach ($vips as $vip) { - if (!is_ipaddrv6($vip['subnet'])) { - continue; - } - $subnets[] = gen_subnetv6($vip['subnet'], $vip['subnet_bits']) . "/" . $vip['subnet_bits']; + foreach ($vips as $vip) { + if (!is_ipaddrv6($vip['subnet'])) { + continue; } + $subnets[] = gen_subnetv6($vip['subnet'], $vip['subnet_bits']) . "/" . $vip['subnet_bits']; } $found = false;