From f60003faf1343a532f52a3f03a5e9c6687b470e3 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Thu, 27 Feb 2014 18:54:51 -0800 Subject: [PATCH 1/4] Return GWG IP protocol (version) when no gateway IP This is a resubmit of an older pull request I had closed. It came up again in the forum, with a user setting up a VM environment and wondering why he cannot make policy-routing rules to a gateway group. The gateway group names did not display because all his WANs were down at the time and so the existing code was too dumb to determine the IP protocol (version 4 or 6) when none of the WANs in the gateway group actually have an IP address yet. --- etc/inc/gwlb.inc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/etc/inc/gwlb.inc b/etc/inc/gwlb.inc index 27271d72ce..faf2a00cb6 100644 --- a/etc/inc/gwlb.inc +++ b/etc/inc/gwlb.inc @@ -827,15 +827,17 @@ function return_gateway_groups_array() { else if (!empty($int)) $gatewayip = get_interface_gateway($gateway['friendlyiface']); - if (!empty($int) && is_ipaddr($gatewayip)) { - $groupmember = array(); - $groupmember['int'] = $int; - $groupmember['gwip'] = $gatewayip; - $groupmember['weight'] = isset($gateway['weight']) ? $gateway['weight'] : 1; - if (is_array($gwvip_arr[$group['name']])&& !empty($gwvip_arr[$group['name']][$member])) - $groupmember['vip'] = $gwvip_arr[$group['name']][$member]; + if (!empty($int)) { $gateway_groups_array[$group['name']]['ipprotocol'] = $gateway['ipprotocol']; - $gateway_groups_array[$group['name']][] = $groupmember; + if (is_ipaddr($gatewayip)) { + $groupmember = array(); + $groupmember['int'] = $int; + $groupmember['gwip'] = $gatewayip; + $groupmember['weight'] = isset($gateway['weight']) ? $gateway['weight'] : 1; + if (is_array($gwvip_arr[$group['name']])&& !empty($gwvip_arr[$group['name']][$member])) + $groupmember['vip'] = $gwvip_arr[$group['name']][$member]; + $gateway_groups_array[$group['name']][] = $groupmember; + } } } } From d47e25c7775cbb150a59d56ddb4b2e360014eb12 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Thu, 27 Feb 2014 23:48:28 -0800 Subject: [PATCH 2/4] Use return_gateway_groups_array() to build correct GWG list Now return_gateway_groups_array() always returns at least the IP version 'ipprotocol' of each GWG, even if all its members are down at present. It is better to use this to check what IP version the GWG is. The previous check was using the IP address of the first member of the GWG to deduce 'ipprotocol'. That would fail if the WAN was DHCP and was down. --- usr/local/www/firewall_rules_edit.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/usr/local/www/firewall_rules_edit.php b/usr/local/www/firewall_rules_edit.php index 9eafdd302c..e3dd9558ca 100755 --- a/usr/local/www/firewall_rules_edit.php +++ b/usr/local/www/firewall_rules_edit.php @@ -205,6 +205,7 @@ read_dummynet_config(); /* XXX: */ $dnqlist =& get_unique_dnqueue_list(); read_layer7_config(); $l7clist =& get_l7_unique_list(); +$a_gatewaygroups = return_gateway_groups_array(); if ($_POST) { unset($input_errors); @@ -216,7 +217,6 @@ if ($_POST) { } if (($_POST['ipprotocol'] <> "") && ($_POST['gateway'] <> "")) { - $a_gatewaygroups = return_gateway_groups_array(); if(is_array($config['gateways']['gateway_group'])) { foreach($config['gateways']['gateway_group'] as $gw_group) { if($gw_group['name'] == $_POST['gateway']) { @@ -1471,23 +1471,20 @@ $i--): ?> echo "\n"; } /* add gateway groups to the list */ - if (is_array($config['gateways']['gateway_group'])) { - foreach($config['gateways']['gateway_group'] as $gw_group) { - $af = explode("|", $gw_group['item'][0]); + if (is_array($a_gatewaygroups)) { + foreach($a_gatewaygroups as $gwg_name => $gwg_data) { if(($pconfig['ipprotocol'] == "inet46")) continue; - if(($pconfig['ipprotocol'] == "inet6") && !is_ipaddrv6(lookup_gateway_ip_by_name($af[0]))) + if(($pconfig['ipprotocol'] == "inet6") && ($gwg_data['ipprotocol'] != "inet6")) continue; - if(($pconfig['ipprotocol'] == "inet") && !is_ipaddrv4(lookup_gateway_ip_by_name($af[0]))) + if(($pconfig['ipprotocol'] == "inet") && ($gwg_data['ipprotocol'] != "inet")) continue; - if($gw_group['name'] == "") - continue; - if($pconfig['gateway'] == $gw_group['name']) { + if($pconfig['gateway'] == $gwg_name) { $selected = " selected=\"selected\""; } else { $selected = ""; } - echo "\n"; + echo "\n"; } } ?> From fa94f1e17e3cce657adb2a3e9182f4d1c0c545fd Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Fri, 28 Feb 2014 03:28:28 -0800 Subject: [PATCH 3/4] Tidy "gateway name - IP" in dropdown list While I notice this also, for a plain gateway, the current IP address is also listed in the dropdown list text, like "WAN_DHCP - 10.42.11.1". If there is no IP address currently, it might say "WAN_DHCP - dynamic". But for some DHCP gateways that have not had any non-default manual settings done, it can say "OPT1_DHCP -". This gets rid of the silly-looking "-" --- usr/local/www/firewall_rules_edit.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/usr/local/www/firewall_rules_edit.php b/usr/local/www/firewall_rules_edit.php index e3dd9558ca..daa5d119fa 100755 --- a/usr/local/www/firewall_rules_edit.php +++ b/usr/local/www/firewall_rules_edit.php @@ -1468,7 +1468,8 @@ $i--): ?> } else { $selected = ""; } - echo "\n"; + $gateway_addr_str = empty($gw['gateway']) ? "" : " - " . $gw[gateway]; + echo "\n"; } /* add gateway groups to the list */ if (is_array($a_gatewaygroups)) { From 088a4eed18e192c7577ce79406fc914a9b4a708a Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Fri, 28 Feb 2014 06:00:46 -0800 Subject: [PATCH 4/4] Tidy up GWG dropdown selection tests Tested this making a new rule, and editing existing IPv4, IPv6 and IPv4+Ipv6 rules, and switching the IP version on an existing rule. Seems to work! --- usr/local/www/firewall_rules_edit.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/usr/local/www/firewall_rules_edit.php b/usr/local/www/firewall_rules_edit.php index daa5d119fa..9020ac0d94 100755 --- a/usr/local/www/firewall_rules_edit.php +++ b/usr/local/www/firewall_rules_edit.php @@ -1474,18 +1474,14 @@ $i--): ?> /* add gateway groups to the list */ if (is_array($a_gatewaygroups)) { foreach($a_gatewaygroups as $gwg_name => $gwg_data) { - if(($pconfig['ipprotocol'] == "inet46")) - continue; - if(($pconfig['ipprotocol'] == "inet6") && ($gwg_data['ipprotocol'] != "inet6")) - continue; - if(($pconfig['ipprotocol'] == "inet") && ($gwg_data['ipprotocol'] != "inet")) - continue; - if($pconfig['gateway'] == $gwg_name) { - $selected = " selected=\"selected\""; - } else { - $selected = ""; + if((empty($pconfig['ipprotocol'])) || ($pconfig['ipprotocol'] == $gwg_data['ipprotocol'])) { + if($pconfig['gateway'] == $gwg_name) { + $selected = " selected=\"selected\""; + } else { + $selected = ""; + } + echo "\n"; } - echo "\n"; } } ?>