From 25eeb7c9b26afe199ca1bca5b734f24208744c33 Mon Sep 17 00:00:00 2001 From: Ian Matyssik Date: Sun, 26 Feb 2017 07:11:17 +0900 Subject: [PATCH 1/2] Remove filter_generate_network_aliases since it is not used anywhere and redundant with internal ()/(:network) directives --- src/etc/inc/filter.inc | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/src/etc/inc/filter.inc b/src/etc/inc/filter.inc index f4a0811ec..30ea08812 100644 --- a/src/etc/inc/filter.inc +++ b/src/etc/inc/filter.inc @@ -395,7 +395,6 @@ function filter_configure_sync($verbose = false) /* generate aliases */ update_filter_reload_status(gettext("Creating aliases")); $aliases = filter_generate_aliases($FilterIflist); - $aliases .= filter_generate_network_aliases(); $gateways = filter_generate_gateways(); if ($verbose) { @@ -873,35 +872,6 @@ function filter_generate_aliases(&$FilterIflist) return $aliases; } -/** - * generate aliases for internal networks, so eventually we don't need logic in the rule parsing to bind the - * existing network/ip options. - */ -function filter_generate_network_aliases() -{ - global $config; - $result = "### define internal aliases\n"; - $interface_config = legacy_interfaces_details(); - foreach (legacy_config_get_interfaces(array("enable" => true)) as $if => $ifdetail) { - $networks = array(); - $addresses = array(); - if (!empty($ifdetail['if']) && !empty($interface_config[$ifdetail['if']])) { - $properties = $interface_config[$ifdetail['if']]; - if (!empty($properties['ipv4'])) { - $networks[] = gen_subnet($properties['ipv4'][0]['ipaddr'], $properties['ipv4'][0]['subnetbits']); - $addresses[] = $properties['ipv4'][0]['ipaddr']; - } - if (!empty($properties['ipv6']) && empty($properties['ipv6'][0]['link-local'])) { - $networks[] = gen_subnetv6($properties['ipv6'][0]['ipaddr'], $properties['ipv6'][0]['subnetbits']); - $addresses[] = $properties['ipv6'][0]['ipaddr']; - } - } - $result .= "table { " . implode(' ', $networks) . " } \n"; - $result .= "table { " . implode(' ', $addresses) . " } \n"; - } - return $result; -} - function filter_generate_gateways() { global $config, $GatewaysList; From e839ef2c3a65ec95ab9c588af89a438fd05bcbb5 Mon Sep 17 00:00:00 2001 From: Ian Matyssik Date: Sun, 26 Feb 2017 07:34:08 +0900 Subject: [PATCH 2/2] Simplify route-to rules from the firewall, probably can be cleaned even more --- src/etc/inc/filter.inc | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/src/etc/inc/filter.inc b/src/etc/inc/filter.inc index 30ea08812..f886f83f4 100644 --- a/src/etc/inc/filter.inc +++ b/src/etc/inc/filter.inc @@ -2428,27 +2428,13 @@ function filter_rules_generate(&$FilterIflist) $gw = get_interface_gateway($ifdescr); if (is_ipaddrv4($gw) && isset($ifcfg['ip']) && is_ipaddrv4($ifcfg['ip'])) { - $ipfrules .= "pass out {$log['pass']} route-to ( {$ifcfg['if']} {$gw} ) from {$ifcfg['ip']} to !{$ifcfg['sa']}/{$ifcfg['sn']} keep state allow-opts label \"let out anything from firewall host itself\"\n"; - if (isset($ifcfg['vips']) && is_array($ifcfg['vips'])) { - foreach ($ifcfg['vips'] as $vip) { - if (ip_in_subnet($vip['ip'], "{$ifcfg['sa']}/{$ifcfg['sn']}")) { - $ipfrules .= "pass out {$log['pass']} route-to ( {$ifcfg['if']} {$gw} ) from {$vip['ip']} to !{$ifcfg['sa']}/{$ifcfg['sn']} keep state allow-opts label \"let out anything from firewall host itself\"\n"; - } else { - $ipfrules .= "pass out {$log['pass']} route-to ( {$ifcfg['if']} {$gw} ) from {$vip['ip']} to !" . gen_subnet($vip['ip'], $vip['sn']) . "/{$vip['sn']} keep state allow-opts label \"let out anything from firewall host itself\"\n"; - } - } - } + $ipfrules .= "pass out {$log['pass']} route-to ( {$ifcfg['if']} {$gw} ) from ({$ifcfg['if']}) to !({$ifcfg['if']}:network) keep state allow-opts label \"let out anything from firewall host itself\"\n"; } $gwv6 = get_interface_gateway_v6($ifdescr); $stf = get_real_interface($ifdescr, "inet6"); - $pdlen = 64 - calculate_ipv6_delegation_length($ifdescr); if (is_ipaddrv6($gwv6) && is_ipaddrv6($ifcfg['ipv6'])) { - $ipfrules .= "pass out {$log['pass']} route-to ( {$stf} {$gwv6} ) inet6 from {$ifcfg['ipv6']} to !{$ifcfg['ipv6']}/{$pdlen} keep state allow-opts label \"let out anything from firewall host itself\"\n"; - if (is_array($ifcfg['vips6'])) { - foreach ($ifcfg['vips6'] as $vip) - $ipfrules .= "pass out {$log['pass']} route-to ( {$stf} {$gwv6} ) inet6 from {$vip['ip']} to !{$vip['ip']}/{$pdlen} keep state allow-opts label \"let out anything from firewall host itself\"\n"; - } + $ipfrules .= "pass out {$log['pass']} route-to ( {$stf} {$gwv6} ) inet6 from ({$stf}) to !({$stf}:network) keep state allow-opts label \"let out anything from firewall host itself\"\n"; } }