Make the vpn configuration add static routes on interfaces other then WAN.

link_carp_interface_to_parent() now correctly returns parent interface instead of always WAN.
This commit is contained in:
Seth Mos 2008-06-05 08:51:10 +00:00
parent 2f306bdbc6
commit 20fdc10f37
2 changed files with 21 additions and 9 deletions

View File

@ -1211,20 +1211,26 @@ function link_carp_interface_to_parent($interface) {
global $config;
if($interface == "") return;
$ifdescrs = array('wan', 'lan');
$ifdescrs = array("wan" => "wan", "lan" => "lan");
for ($j = 1; isset($config['interfaces']['opt' . $j]); $j++)
$ifdescrs['opt' . $j] = "opt" . $j;
$carp_int = $interface;
$carp_ip = find_interface_ip($interface);
$carp_subnet = find_virtual_ip_netmask($carp_ip);
$starting_ip = gen_subnet("{$carp_ip}", "{$carp_subnet}");
$carp_ints = "";
$num_carp_ints = find_number_of_created_carp_interfaces();
foreach ($ifdescrs as $ifdescr => $ifname) {
$carp_int = $interface;
$carp_ip = find_interface_ip($interface);
$carp_subnet = find_virtual_ip_netmask($carp_ip);
$starting_ip = gen_subnet("{$carp_ip}", "{$carp_subnet}");
if(ip_in_subnet($starting_ip, "{$carp_ip}/{$carp_subnet}"))
if(!stristr($carp_ints, $carp_int))
if(interface_has_gateway($ifname)) {
$interfaceip = $config['interfaces'][$ifname]['ipaddr'];
$subnet_bits = $config['interfaces'][$ifname]['subnet'];
$subnet_ip = gen_subnet("{$interfaceip}", "{$subnet_bits}");
if(ip_in_subnet($carp_ip, "{$subnet_ip}/{$subnet_bits}")) {
return $ifname;
}
}
}
return $carp_ints;
}

View File

@ -245,8 +245,14 @@ function vpn_ipsec_configure($ipchg = false) {
if($tunnel['interface'] <> "wan") {
/* static route needed? */
if(strstr("carp", $tunnel['interface'])) {
if(preg_match("/^carp/i", $tunnel['interface'])) {
/* add endpoint routes to correct gateway on interface */
$parentinterface = link_carp_interface_to_parent($tunnel['interface']);
$gatewayip = get_interface_gateway("$parentinterface");
if($gatewayip) {
log_error("IPSEC interface is not WAN but {$tunnel['interface']}, adding static route for VPN endpoint {$tunnel['remote-gateway']} via {$gatewayip}");
mwexec("/sbin/route add -host {$tunnel['remote-gateway']} {$gatewayip}");
}
}
}
}