Commit 89c55e1b authored by Ad Schellevis's avatar Ad Schellevis

(filter) refactor inet46 to single rule and add some more tags

parent b9c8e159
...@@ -46,6 +46,9 @@ class FilterRule ...@@ -46,6 +46,9 @@ class FilterRule
'interface' => 'parseInterface', 'interface' => 'parseInterface',
'ipprotocol' => 'parsePlain', 'ipprotocol' => 'parsePlain',
'protocol' => 'parseReplaceSimple,tcp/udp:{tcp udp}', 'protocol' => 'parseReplaceSimple,tcp/udp:{tcp udp}',
'from' => 'parsePlain',
'to' => 'parsePlain',
'icmp6-type' => 'parsePlain,{,}',
'state' => 'parseState', 'state' => 'parseState',
'label' => 'parsePlain,label ","' 'label' => 'parsePlain,label ","'
); );
...@@ -161,57 +164,53 @@ class FilterRule ...@@ -161,57 +164,53 @@ class FilterRule
$result = array(); $result = array();
$interfaces = empty($this->rule['interface']) ? array(null) : explode(',', $this->rule['interface']); $interfaces = empty($this->rule['interface']) ? array(null) : explode(',', $this->rule['interface']);
foreach ($interfaces as $interface) { foreach ($interfaces as $interface) {
if (isset($this->rule['ipprotocol']) && $this->rule['ipprotocol'] == 'inet46') { $tmp = $this->rule;
$ipprotos = array('inet', 'inet6'); // protocol handling
} elseif (isset($this->rule['ipprotocol'])) { if (empty($this->rule['ipprotocol']) || $this->rule['ipprotocol'] == 'inet46') {
$ipprotos = array($this->rule['ipprotocol']); $tmp['ipprotocol'] = "";
} else { } else {
$ipprotos = array(null); $tmp['ipprotocol'] = $this->rule['ipprotocol'];
} }
foreach ($ipprotos as $ipproto) { $tmp['interface'] = $interface;
$tmp = $this->rule; // disable rule when interface not found
$tmp['interface'] = $interface; if (!empty($interface) && empty($this->interfaceMapping[$interface]['if'])) {
$tmp['ipprotocol'] = $ipproto; $tmp['disabled'] = true;
// disable rule when interface not found }
if (!empty($interface) && empty($this->interfaceMapping[$interface]['if'])) { if (!isset($tmp['quick'])) {
$tmp['disabled'] = true; // all rules are quick by default except floating
$tmp['quick'] = !isset($rule['floating']) ? true : false ;
}
// restructure state settings for easier output parsing
if (!empty($tmp['statetype'])) {
$tmp['state'] = array('type' => 'keep', 'options' => array());
switch ($tmp['statetype']) {
case 'none':
$tmp['state']['type'] = 'no';
break;
case 'sloppy state':
$tmp['state']['type'] = 'keep';
$tmp['state']['options'][] = "sloppy ";
break;
default:
$tmp['state']['type'] = explode(' ', $tmp['statetype'])[0];
} }
if (!isset($tmp['quick'])) { if (!empty($tmp['nopfsync'])) {
// all rules are quick by default except floating $tmp['state']['options'][] = "no-sync ";
$tmp['quick'] = !isset($rule['floating']) ? true : false ;
} }
// restructure state settings for easier output parsing foreach (array('max', 'max-src-nodes', 'max-src-conn', 'max-src-states') as $state_tag) {
if (!empty($tmp['statetype'])) { if (!empty($tmp[$state_tag])) {
$tmp['state'] = array('type' => 'keep', 'options' => array()); $tmp['state']['options'][] = $state_tag . " " . $tmp[$state_tag];
switch ($tmp['statetype']) {
case 'none':
$tmp['state']['type'] = 'no';
break;
case 'sloppy state':
$tmp['state']['type'] = 'keep';
$tmp['state']['options'][] = "sloppy ";
break;
default:
$tmp['state']['type'] = explode(' ', $tmp['statetype'])[0];
}
if (!empty($tmp['nopfsync'])) {
$tmp['state']['options'][] = "no-sync ";
}
foreach (array('max', 'max-src-nodes', 'max-src-conn', 'max-src-states') as $state_tag) {
if (!empty($tmp[$state_tag])) {
$tmp['state']['options'][] = $state_tag . " " . $tmp[$state_tag];
}
}
if (!empty($tmp['statetimeout'])) {
$tmp['state']['options'][] = "tcp.established " . $tmp['statetimeout'];
}
if (!empty($tmp['max-src-conn-rate']) && !empty($tmp['max-src-conn-rates'])) {
$tmp['state']['options'][] = "max-src-conn-rate " . $tmp['max-src-conn-rate'] . " " .
"/" . $tmp['max-src-conn-rates'] . ", overload <virusprot> flush global ";
} }
} }
$result[] = $tmp; if (!empty($tmp['statetimeout'])) {
$tmp['state']['options'][] = "tcp.established " . $tmp['statetimeout'];
}
if (!empty($tmp['max-src-conn-rate']) && !empty($tmp['max-src-conn-rates'])) {
$tmp['state']['options'][] = "max-src-conn-rate " . $tmp['max-src-conn-rate'] . " " .
"/" . $tmp['max-src-conn-rates'] . ", overload <virusprot> flush global ";
}
} }
$result[] = $tmp;
} }
return $result; return $result;
} }
......
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