Commit 510e7def authored by Ad Schellevis's avatar Ad Schellevis

firewall, nat cleanup $localport switcheroo

parent 58001db0
...@@ -1677,25 +1677,29 @@ function filter_nat_rules_generate(&$FilterIflist) ...@@ -1677,25 +1677,29 @@ function filter_nat_rules_generate(&$FilterIflist)
$dstport = explode("-", $rule['destination']['port']); $dstport = explode("-", $rule['destination']['port']);
} }
/* if item is an alias, expand */
$localport = alias_expand($rule['local-port']); if (!empty($rule['protocol']) && in_array($rule['protocol'], array('tcp/udp', 'udp', 'tcp', 'sctp', 'dccp'))) {
if (!$localport || $dstport[0] == $localport) { $localport = alias_expand($rule['local-port']);
$localport = ""; if (!$localport || $dstport[0] == $localport) {
} else if (is_alias($rule['local-port'])) { $localport = "";
$localport = filter_expand_alias($rule['local-port']); } else if (is_alias($rule['local-port'])) {
if ($localport) { $localport = filter_expand_alias($rule['local-port']);
$localport = explode(" ", trim($localport)); if ($localport) {
$localport = $localport[0]; $localport = explode(" ", trim($localport));
$localport = $localport[0];
$localport = " port {$localport}";
}
} elseif (is_alias($rule['destination']['port'])) {
$localport = " port {$localport}";
} else {
if (($dstport[1]) && ($dstport[0] != $dstport[1])) {
$localendport = $localport + ($dstport[1] - $dstport[0]);
$localport .= ":$localendport";
}
$localport = " port {$localport}"; $localport = " port {$localport}";
} }
} elseif (is_alias($rule['destination']['port'])) {
$localport = " port {$localport}";
} else { } else {
if (($dstport[1]) && ($dstport[0] != $dstport[1])) { $localport = "";
$localendport = $localport + ($dstport[1] - $dstport[0]);
$localport .= ":$localendport";
}
$localport = " port {$localport}";
} }
$address_family = !empty($rule['ipprotocol']) ? $rule['ipprotocol'] : ""; $address_family = !empty($rule['ipprotocol']) ? $rule['ipprotocol'] : "";
...@@ -1703,17 +1707,8 @@ function filter_nat_rules_generate(&$FilterIflist) ...@@ -1703,17 +1707,8 @@ function filter_nat_rules_generate(&$FilterIflist)
case "tcp/udp": case "tcp/udp":
$protocol = "{ tcp udp }"; $protocol = "{ tcp udp }";
break; break;
case "tcp":
case "udp":
$protocol = strtolower($rule['protocol']);
break;
case "icmp":
$protocol = $address_family == 'inet6' ? "ipv6-icmp" : $protocol;
$localport = "";
break;
default: default:
$protocol = strtolower($rule['protocol']); $protocol = strtolower($rule['protocol']);
$localport = "";
break; break;
} }
...@@ -1787,7 +1782,6 @@ function filter_nat_rules_generate(&$FilterIflist) ...@@ -1787,7 +1782,6 @@ function filter_nat_rules_generate(&$FilterIflist)
$localport_nat = " port " . $dstaddr_port[2]; $localport_nat = " port " . $dstaddr_port[2];
} }
if ($srcaddr <> "" && $dstaddr <> "" && $natif) { if ($srcaddr <> "" && $dstaddr <> "" && $natif) {
$protocol_keyword = !empty($protocol) ? "proto" : ""; $protocol_keyword = !empty($protocol) ? "proto" : "";
$natrules .= "{$nordr}rdr {$rdrpass}on {$natif} {$address_family} {$protocol_keyword} {$protocol} from {$srcaddr} to {$dstaddr}" . ($nordr == "" ? " -> {$target}{$localport}" : ""); $natrules .= "{$nordr}rdr {$rdrpass}on {$natif} {$address_family} {$protocol_keyword} {$protocol} from {$srcaddr} to {$dstaddr}" . ($nordr == "" ? " -> {$target}{$localport}" : "");
......
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