Commit b4329c84 authored by Franco Fichtner's avatar Franco Fichtner

system: generate far routes for default gateways, fix style

parent b3d14817
...@@ -517,6 +517,8 @@ function system_routing_configure($interface = '') ...@@ -517,6 +517,8 @@ function system_routing_configure($interface = '')
$gatewayipv6 = ""; $gatewayipv6 = "";
$interfacegwv6 = ""; $interfacegwv6 = "";
$foundgwv6 = false; $foundgwv6 = false;
$fargw = false;
/* tack on all the hard defined gateways as well */ /* tack on all the hard defined gateways as well */
if (isset($config['gateways']['gateway_item'])) { if (isset($config['gateways']['gateway_item'])) {
array_map('unlink', glob('/tmp/*_defaultgw{,v6}', GLOB_BRACE)); array_map('unlink', glob('/tmp/*_defaultgw{,v6}', GLOB_BRACE));
...@@ -529,6 +531,7 @@ function system_routing_configure($interface = '') ...@@ -529,6 +531,7 @@ function system_routing_configure($interface = '')
if ($gateway['gateway'] == "dynamic") { if ($gateway['gateway'] == "dynamic") {
$gateway['gateway'] = get_interface_gateway($gateway['interface']); $gateway['gateway'] = get_interface_gateway($gateway['interface']);
} }
$fargw = isset($gateway['fargw']);
$gatewayip = $gateway['gateway']; $gatewayip = $gateway['gateway'];
$interfacegw = $gateway['interface']; $interfacegw = $gateway['interface'];
if (!empty($gateway['interface'])) { if (!empty($gateway['interface'])) {
...@@ -542,6 +545,7 @@ function system_routing_configure($interface = '') ...@@ -542,6 +545,7 @@ function system_routing_configure($interface = '')
if ($gateway['gateway'] == "dynamic") { if ($gateway['gateway'] == "dynamic") {
$gateway['gateway'] = get_interface_gateway_v6($gateway['interface']); $gateway['gateway'] = get_interface_gateway_v6($gateway['interface']);
} }
$fargw = isset($gateway['fargw']);
$gatewayipv6 = $gateway['gateway']; $gatewayipv6 = $gateway['gateway'];
$interfacegwv6 = $gateway['interface']; $interfacegwv6 = $gateway['interface'];
if (!empty($gateway['interface'])) { if (!empty($gateway['interface'])) {
...@@ -574,22 +578,28 @@ function system_routing_configure($interface = '') ...@@ -574,22 +578,28 @@ function system_routing_configure($interface = '')
if (!empty($interface) && $interface != $interfacegw) if (!empty($interface) && $interface != $interfacegw)
; ;
elseif (is_ipaddrv4($gatewayip)) { elseif (is_ipaddrv4($gatewayip)) {
log_error("ROUTING: remove current default route to $gatewayip"); log_error("ROUTING: setting IPv4 default route to {$gatewayip}");
mwexec("/sbin/route delete default"); mwexecf('/sbin/route delete -inet %s', 'default');
log_error("ROUTING: setting default route to $gatewayip"); if ($fargw) {
mwexec("/sbin/route add -inet default " . escapeshellarg($gatewayip)); mwexecf('/sbin/route delete -inet %s -interface %s', array($gatewayip, $interfacegw));
mwexecf('/sbin/route add -inet %s -interface %s', array($gatewayip, $interfacegw));
}
mwexecf('/sbin/route add -inet %s %s', array('default', $gatewayip));
} }
if (!empty($interface) && $interface != $interfacegwv6) if (!empty($interface) && $interface != $interfacegwv6)
; ;
elseif (is_ipaddrv6($gatewayipv6)) { elseif (is_ipaddrv6($gatewayipv6)) {
$ifscope = "";
if (is_linklocal($gatewayipv6)) { if (is_linklocal($gatewayipv6)) {
$ifscope = "%{$defaultifv6}"; $gatewayipv6 .= "%{$defaultifv6}";
}
log_error("ROUTING: setting IPv6 default route to {$gatewayipv6}");
mwexecf('/sbin/route delete -inet6 %s %s', array('default', $gatewayipv6));
if ($fargw) {
mwexecf('/sbin/route delete -inet6 %s -interface %s', array($gatewayipv6, $interfacegwv6));
mwexecf('/sbin/route add -inet6 %s -interface %s', array($gatewayipv6, $interfacegwv6));
} }
log_error("ROUTING: setting IPv6 default route to {$gatewayipv6}{$ifscope}"); mwexecf('/sbin/route add -inet6 %s %s', array('default', $gatewayipv6));
mwexec("/sbin/route delete -inet6 default " . escapeshellarg("{$gatewayipv6}{$ifscope}"));
mwexec("/sbin/route add -inet6 default " . escapeshellarg("{$gatewayipv6}{$ifscope}"));
} }
system_staticroutes_configure($interface, false); system_staticroutes_configure($interface, false);
...@@ -716,15 +726,15 @@ function system_staticroutes_configure($interface = '', $update_dns = false) ...@@ -716,15 +726,15 @@ function system_staticroutes_configure($interface = '', $update_dns = false)
$ip .= "/128"; $ip .= "/128";
} }
$inet = (is_subnetv6($ip) ? "-inet6" : "-inet"); $inet = (is_subnetv6($ip) ? "-inet6" : "-inet");
$iface = $needs_iface ? ' -iface ' . escapeshellarg($interfacegw) . ' ' : ''; $iface = $needs_iface ? ' -interface ' . escapeshellarg($interfacegw) . ' ' : '';
$cmd = " {$inet} {$blackhole} " . escapeshellarg($ip) . " "; $cmd = " {$inet} {$blackhole} " . escapeshellarg($ip) . " ";
if (is_subnet($ip)) { if (is_subnet($ip)) {
if (is_ipaddr($gatewayip)) { if (is_ipaddr($gatewayip)) {
mwexec("/sbin/route delete".$cmd . $iface . escapeshellarg($gatewayip)); mwexec("/sbin/route delete".$cmd . escapeshellarg($gatewayip) . $iface);
mwexec("/sbin/route add".$cmd . $iface . escapeshellarg($gatewayip)); mwexec("/sbin/route add".$cmd . escapeshellarg($gatewayip) . $iface);
} elseif (!empty($interfacegw)) { } elseif (!empty($interfacegw)) {
mwexec("/sbin/route delete".$cmd . "-iface " . escapeshellarg($interfacegw)); mwexec("/sbin/route delete".$cmd . "-interface " . escapeshellarg($interfacegw));
mwexec("/sbin/route add".$cmd . "-iface " . escapeshellarg($interfacegw)); mwexec("/sbin/route add".$cmd . "-interface " . escapeshellarg($interfacegw));
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment