diff options
author | smos <seth.mos@dds.nl> | 2012-05-20 13:13:03 +0200 |
---|---|---|
committer | smos <seth.mos@dds.nl> | 2012-05-20 13:13:03 +0200 |
commit | 3930a9c0ea49014e08e266c33defd8b077829c6e (patch) | |
tree | 012f68661bd1b93cc1e5f223c6b8190bf6219cee | |
parent | d23ef852b368b3a1ee8615eac0c15c63e42b2b8d (diff) | |
download | pfsense-3930a9c0ea49014e08e266c33defd8b077829c6e.zip pfsense-3930a9c0ea49014e08e266c33defd8b077829c6e.tar.gz |
Prevent duplicate gateways from showing up if the interface is down. Redmine ticket #2442
-rw-r--r-- | etc/inc/gwlb.inc | 70 |
1 files changed, 50 insertions, 20 deletions
diff --git a/etc/inc/gwlb.inc b/etc/inc/gwlb.inc index 7c072cb..1e694cf 100644 --- a/etc/inc/gwlb.inc +++ b/etc/inc/gwlb.inc @@ -328,6 +328,9 @@ function return_gateways_array($disabled = false) { $found_defaultv4 = 0; $found_defaultv6 = 0; + $interfaces_v4 = array(); + $interfaces_v6 = array(); + $i = 0; /* Process/add all the configured gateways. */ if (is_array($config['gateways']['gateway_item'])) { @@ -336,31 +339,45 @@ function return_gateways_array($disabled = false) { if(!isset($config['interfaces'][$gateway['interface']]['enable'])) continue; - /* if the gateway is dynamic and we can find the IP, Great! */ + $wancfg = $config['interfaces'][$gateway['interface']]; + /* if the gateway is dynamic and we can find the IPv4, Great! */ if(empty($gateway['gateway']) || ($gateway['gateway'] == "dynamic")) { - $gateway['ipprotocol'] = "inet"; - $gateway['gateway'] = get_interface_gateway($gateway['interface']); - if($gateway['gateway'] == "dynamic") { - $dynstr = $gateway['gateway']; - } - /* no IP address found, set to dynamic */ - if(! is_ipaddrv4($gateway['gateway'])) { - $gateway['gateway'] = "{$dynstr}"; + /* we know which interfaces is dynamic, this should be made a function */ + switch($wancfg['ipaddr']) { + case "dhcp": + case "pppoe": + case "pptp": + case "ppp": + $gateway['ipprotocol'] = "inet"; + $gateway['gateway'] = get_interface_gateway($gateway['interface']); + if($gateway['gateway'] == "dynamic") { + $dynstr = $gateway['gateway']; + } + /* no IP address found, set to dynamic */ + if(! is_ipaddrv4($gateway['gateway'])) { + $gateway['gateway'] = "{$dynstr}"; + } + $gateway['dynamic'] = true; + break; } - $gateway['dynamic'] = true; } /* if the gateway is dynamic6 and we can find the IPv6, Great! */ if(empty($gateway['gateway']) || ($gateway['gateway'] == "dynamic6")) { - $gateway['ipprotocol'] = "inet6"; - $gateway['gateway'] = get_interface_gateway_v6($gateway['interface']); - if($gateway['gateway'] == "dynamic6") { - $dynstr = $gateway['gateway']; - } - /* no IPv6 address found, set to dynamic6 */ - if(! is_ipaddrv6($gateway['gateway'])) { - $gateway['gateway'] = "{$dynstr}"; + /* we know which interfaces is dynamic, this should be made a function, and for v6 too */ + switch($wancfg['ipaddrv6']) { + case "dhcp6": + $gateway['ipprotocol'] = "inet6"; + $gateway['gateway'] = get_interface_gateway_v6($gateway['interface']); + if($gateway['gateway'] == "dynamic6") { + $dynstr = $gateway['gateway']; + } + /* no IPv6 address found, set to dynamic6 */ + if(! is_ipaddrv6($gateway['gateway'])) { + $gateway['gateway'] = "{$dynstr}"; + } + $gateway['dynamic'] = true; + break; } - $gateway['dynamic'] = true; } if(is_ipaddrv4($gateway['gateway'])) $gateway['ipprotocol'] = "inet"; @@ -388,7 +405,7 @@ function return_gateways_array($disabled = false) { /* FIXME: Should this be enabled. * Some interface like wan might be default but have no info recorded * the config. */ - /* this is a fallback if all else fails and we want to get packet out @smos */ + /* this is a fallback if all else fails and we want to get packets out @smos */ if (!isset($gateway['defaultgw'])) { if (($gateway['friendlyiface'] == "wan") && ($found_defaultv4 == 0)) { if (file_exists("{$g['tmp_path']}/{$gateway['interface']}_defaultgw")) { @@ -406,6 +423,13 @@ function return_gateways_array($disabled = false) { /* include the gateway index as the attribute */ $gateway['attribute'] = $i; + /* tack a item on the array to keep track of dynamic interfaces */ + if($gateway['ipprotocol'] == "inet") + $interfaces_v4[] = $gateway['friendlyiface']; + + if($gateway['ipprotocol'] == "inet6") + $interfaces_v6[] = $gateway['friendlyiface']; + $gateways_arr[$gateway['name']] = $gateway; unset($gateway); $i++; @@ -432,6 +456,9 @@ function return_gateways_array($disabled = false) { if(!isset($ifcfg['enable'])) continue; + + if(in_array($ifname, $interfaces_v4)) + continue; $ctype = ""; switch($ifcfg['ipaddr']) { @@ -496,6 +523,9 @@ function return_gateways_array($disabled = false) { if(!isset($ifcfg['enable'])) continue; + if(in_array($ifname, $interfaces_v6)) + continue; + $ctype = ""; switch($ifcfg['ipaddrv6']) { case "slaac": |