From 237c652e4f9e7cbb185e064c9cbd3ac44400dcaa Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Tue, 1 Nov 2016 21:11:46 +0100 Subject: [PATCH] (filter) move block bogons and private nets --- src/etc/inc/filter.inc | 52 -------------------------------------- src/etc/inc/filter.lib.inc | 25 ++++++++++++++++++ 2 files changed, 25 insertions(+), 52 deletions(-) diff --git a/src/etc/inc/filter.inc b/src/etc/inc/filter.inc index e6307d560..13a9f9e56 100644 --- a/src/etc/inc/filter.inc +++ b/src/etc/inc/filter.inc @@ -2504,28 +2504,7 @@ function filter_rules_generate(&$FilterIflist) foreach ($FilterIflist as $on => $oc) { - /* - * Block bogon networks via the following list. Note that "bogons" - * are excluding the four private address ranges for one reason or - * another. They exist in the upstream files but are stripped during - * the upgrade stage. - * - * http://www.cymru.com/Documents/bogon-bn-nonagg.txt - */ - if (!isset($config['syslog']['nologbogons'])) { - $bogonlog = 'log'; - } else { - $bogonlog = ''; - } - if (isset($config['interfaces'][$on]['blockbogons'])) { - $ipfrules .= << to any label "{$fix_rule_label("block bogon IPv4 networks from {$oc['descr']}")}" - -EOD; - } if (isset($config['system']['ipv6allow']) && isset($oc['type6']) && ($oc['type6'] == "slaac" || $oc['type6'] == "dhcp6")) { $ipfrules .= << to any label "{$fix_rule_label("block bogon IPv6 networks from {$oc['descr']}")}" - -EOD; - } - } $isbridged = false; if (isset($config['bridges']['bridged'])) { @@ -2562,27 +2531,6 @@ EOD; $ipfrules .= "antispoof {$log['block']} for \${$oc['descr']} \n"; } - /* block private networks ? */ - if (!isset($config['syslog']['nologprivatenets'])) { - $privnetlog = "log"; - } else { - $privnetlog = ""; - } - - if (isset($config['interfaces'][$on]['blockpriv'])) { - if ($isbridged == false) { - $ipfrules .= << $fw->registerFilterRule(1,array('from' => '', 'label' => 'virusprot overload table'),$defaults['block']); + // block bogons and private nets + $bogontmpl = array('type' => 'block', 'log' => !isset($config['syslog']['nologbogons'])); + $privtmpl = array('type' => 'block', 'log' => !isset($config['syslog']['nologprivatenets']), + 'from' => '10.0.0.0/8,127.0.0.0/8,100.64.0.0/10,172.16.0.0/12,192.168.0.0/16,fc00::/7'); + foreach ($fw->getInterfaceMapping() as $intf => $intfinfo) { + $fw->registerFilterRule(1, + array('from' => "", 'direction' => 'in', 'interface' => $intf, + 'label' => "block bogon IPv4 networks from ".$intfinfo['descr'], + 'disabled' => !isset($intfinfo['blockbogons'])), + $bogontmpl + ); + $fw->registerFilterRule(1, + array('from' => "", 'direction' => 'in', 'interface' => $intf, + 'disabled' => !isset($config['system']['ipv6allow']) || !isset($intfinfo['blockbogons']), + 'label' => "block bogon IPv6 networks from ".$intfinfo['descr']), + $bogontmpl + ); + $fw->registerFilterRule(1, + array('direction' => 'in', 'interface' => $intf, + 'label' => "Block private networks from ".$intfinfo['descr'], + 'disabled' => !isset($intfinfo['blockbogons'])), + $privtmpl + ); + } + }