]> git.proxmox.com Git - pve-firewall.git/blobdiff - PVE/Firewall.pm
fix Ping macro
[pve-firewall.git] / PVE / Firewall.pm
index 05720d56ca24eaba7fd09eb3b5022723314a654f..8fc3898f53ae3e136c77d1774ca49a620b4ae470 100644 (file)
@@ -224,7 +224,7 @@ my $pve_fw_macros = {
        { action => 'PARAM', proto => 'tcp', dport => '1723' },
     ],
     'Ping' => [
-       { action => 'PARAM', proto => 'icmp', dport => '8' },
+       { action => 'PARAM', proto => 'icmp', dport => 'echo-request' },
     ],
     'PostgreSQL' => [
        { action => 'PARAM', proto => 'tcp', dport => '5432' },
@@ -322,7 +322,7 @@ my $pve_fw_macros = {
     ],
     'Trcrt' => [
        { action => 'PARAM', proto => 'udp', dport => '33434:33524' },
-       { action => 'PARAM', proto => 'icmp', dport => '8' },
+       { action => 'PARAM', proto => 'icmp', dport => 'echo-request' },
     ],
     'VNC' => [
        { action => 'PARAM', proto => 'tcp', dport => '5900:5909' },
@@ -714,6 +714,8 @@ sub iptables_rule_exist {
 sub ruleset_generate_rule {
     my ($ruleset, $chain, $rule, $actions, $goto) = @_;
 
+    return if $rule->{disable};
+
     my $cmd = '';
 
     $cmd .= " -m iprange --src-range" if $rule->{nbsource} && $rule->{nbsource} > 1;
@@ -730,7 +732,7 @@ sub ruleset_generate_rule {
     if ($rule->{dport}) {
        if ($rule->{proto} && $rule->{proto} eq 'icmp') {
            # Note: we use dport to store --icmp-type
-           die "unknown icmp-type\n" if !$icmp_type_names->{$rule->{dport}};
+           die "unknown icmp-type '$rule->{dport}'\n" if !$icmp_type_names->{$rule->{dport}};
            $cmd .= " -m icmp --icmp-type $rule->{dport}";
        } else {
            if ($rule->{nbdport} && $rule->{nbdport} > 1) {
@@ -836,6 +838,10 @@ sub generate_tap_rules_direction {
        ruleset_addrule($ruleset, $tapchain, "-m conntrack --ctstate INVALID,NEW -j PVEFW-smurfs");
     }
 
+    if (!(defined($options->{dhcp}) && $options->{dhcp} == 0)) {
+       ruleset_addrule($ruleset, $tapchain, "-p udp -m udp --dport 67:68 -j ACCEPT");
+    }
+
     if ($options->{tcpflags}) {
        ruleset_addrule($ruleset, $tapchain, "-p tcp -j PVEFW-tcpflags");
     }
@@ -1009,7 +1015,11 @@ sub parse_fw_rule {
 
     my ($action, $iface, $source, $dest, $proto, $dport, $sport);
 
-    $line =~ s/#.*$//;
+    # we can add single line comments to the end of the rule
+    my $comment = $1 if $line =~ s/#\s*(.*?)\s*$//;
+
+    # we can disable a rule when prefixed with '|'
+    my $disable = 1 if  $line =~ s/^\|//;
 
     my @data = split(/\s+/, $line);
     my $expected_elements = $need_iface ? 7 : 6;
@@ -1068,6 +1078,8 @@ sub parse_fw_rule {
     my $rules = [];
 
     my $param = {
+       disable => $disable,
+       comment => $comment,
        action => $action,
        iface => $iface,
        source => $source,
@@ -1130,7 +1142,7 @@ sub parse_fw_option {
 
     my ($opt, $value);
 
-    if ($line =~ m/^(enable|macfilter|nosmurfs|tcpflags):\s*(0|1)\s*$/i) {
+    if ($line =~ m/^(enable|dhcp|macfilter|nosmurfs|tcpflags):\s*(0|1)\s*$/i) {
        $opt = lc($1);
        $value = int($2);
     } elsif ($line =~ m/^(policy-(in|out)):\s*(ACCEPT|DROP|REJECT)\s*$/i) {