Commit 7bc5bf4d authored by Ad Schellevis's avatar Ad Schellevis

(filter) move some more static rules

parent 5319b8e5
...@@ -2502,19 +2502,6 @@ function filter_rules_generate(&$FilterIflist) ...@@ -2502,19 +2502,6 @@ function filter_rules_generate(&$FilterIflist)
$log['block'] = !isset($config['syslog']['nologdefaultblock']) ? "log" : ""; $log['block'] = !isset($config['syslog']['nologdefaultblock']) ? "log" : "";
$log['pass'] = !isset($config['syslog']['nologdefaultpass']) ? "log" : ""; $log['pass'] = !isset($config['syslog']['nologdefaultpass']) ? "log" : "";
$ipfrules .= <<<EOD
# We use the mighty pf, we cannot be fooled.
block {$log['block']} quick inet proto { tcp, udp } from any port = 0 to any
block {$log['block']} quick inet proto { tcp, udp } from any to any port = 0
block {$log['block']} quick inet6 proto { tcp, udp } from any port = 0 to any
block {$log['block']} quick inet6 proto { tcp, udp } from any to any port = 0
EOD;
$ipfrules .= filter_process_carp_rules($log);
$ipfrules .= "\n# SSH lockout\n"; $ipfrules .= "\n# SSH lockout\n";
if (!empty($config['system']['ssh']['port'])) { if (!empty($config['system']['ssh']['port'])) {
$ipfrules .= "block in {$log['block']} quick proto tcp from <sshlockout> to (self) port "; $ipfrules .= "block in {$log['block']} quick proto tcp from <sshlockout> to (self) port ";
...@@ -3111,19 +3098,6 @@ function filter_setup_logging_interfaces(&$FilterIflist) ...@@ -3111,19 +3098,6 @@ function filter_setup_logging_interfaces(&$FilterIflist)
return $rules; return $rules;
} }
function filter_process_carp_rules($log)
{
global $config;
$lines = '';
/* return if there are no carp configured items */
if (!empty($config['hasync']) || !empty($config['virtualip']['vip'])) {
$lines .= "block in {$log['block']} quick proto carp from (self) to any \n";
$lines .= "pass {$log['pass']} quick proto carp \n";
}
return $lines;
}
/* Generate IPsec Filter Items */ /* Generate IPsec Filter Items */
function filter_generate_ipsec_rules(&$FilterIflist, $log = array()) function filter_generate_ipsec_rules(&$FilterIflist, $log = array())
{ {
......
...@@ -88,5 +88,20 @@ function filter_core_rules_system($fw, $defaults) ...@@ -88,5 +88,20 @@ function filter_core_rules_system($fw, $defaults)
'to' => 'fe80::/10', 'direction' => 'in' ), 'to' => 'fe80::/10', 'direction' => 'in' ),
$defaults['pass'] $defaults['pass']
); );
// block all targetting port 0
foreach (array('from_port', 'to_port') as $target) {
$fw->registerFilterRule(1,
array('ipprotocol'=>'inet46', 'protocol' => 'tcp/udp', $target => '0'),
$defaults['block']
);
}
// CARP defaults
$carp_disabled = empty($config['hasync']) && empty($config['virtualip']['vip']);
$fw->registerFilterRule(1,
array('protocol' => 'carp', 'from' => '(self)', 'direction' => 'in', 'disabled' => $carp_disabled),
$defaults['block']
);
$fw->registerFilterRule(1,array('protocol' => 'carp'),$defaults['pass']);
} }
...@@ -48,7 +48,9 @@ class FilterRule ...@@ -48,7 +48,9 @@ class FilterRule
'ipprotocol' => 'parsePlain', 'ipprotocol' => 'parsePlain',
'protocol' => 'parseReplaceSimple,tcp/udp:{tcp udp},proto ', 'protocol' => 'parseReplaceSimple,tcp/udp:{tcp udp},proto ',
'from' => 'parsePlain,from {,}', 'from' => 'parsePlain,from {,}',
'from_port' => 'parsePlain, port {,}',
'to' => 'parsePlain,to {,}', 'to' => 'parsePlain,to {,}',
'to_port' => 'parsePlain, port {,}',
'icmp6-type' => 'parsePlain,icmp6-type {,}', 'icmp6-type' => 'parsePlain,icmp6-type {,}',
'state' => 'parseState', 'state' => 'parseState',
'label' => 'parsePlain,label ","' 'label' => 'parsePlain,label ","'
...@@ -71,7 +73,7 @@ class FilterRule ...@@ -71,7 +73,7 @@ class FilterRule
*/ */
private function parsePlain($value, $prefix="", $suffix="") private function parsePlain($value, $prefix="", $suffix="")
{ {
return empty($value) ? "" : $prefix . $value . $suffix . " "; return $value == '' ? "" : $prefix . $value . $suffix . " ";
} }
/** /**
...@@ -183,6 +185,8 @@ class FilterRule ...@@ -183,6 +185,8 @@ class FilterRule
$tmp = $this->rule; $tmp = $this->rule;
$tmp['interface'] = $interface; $tmp['interface'] = $interface;
$tmp['ipprotocol'] = $ipproto; $tmp['ipprotocol'] = $ipproto;
$tmp['from'] = empty($tmp['from']) ? "any" : $tmp['from'];
$tmp['to'] = empty($tmp['to']) ? "any" : $tmp['to'];
// disable rule when interface not found // disable rule when interface not found
if (!empty($interface) && empty($this->interfaceMapping[$interface]['if'])) { if (!empty($interface) && empty($this->interfaceMapping[$interface]['if'])) {
$tmp['disabled'] = true; $tmp['disabled'] = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment