]> git.proxmox.com Git - pve-firewall.git/blobdiff - src/PVE/Firewall.pm
parse_protocol_file: support lines without end comments
[pve-firewall.git] / src / PVE / Firewall.pm
index f009e58ec93f16a60c5c049bf8454d5031536855..ac4850744a83571a5aec1340ace98997e0dfb48d 100644 (file)
@@ -146,14 +146,15 @@ my $log_level_hash = {
 # %rule
 #
 # name => optional
+# enable => [0|1]
 # action =>
 # proto =>
-# sport =>
-# dport =>
+# sport => port[,port[,port]].. or port:port
+# dport => port[,port[,port]].. or port:port
 # log => optional, loglevel
 # logmsg => optional, logmsg - overwrites default
-# iface_in
-# iface_out
+# iface_in => incomin interface
+# iface_out => outgoing interface
 # match => optional, overwrites generation of match
 # target => optional, overwrites action
 
@@ -875,12 +876,8 @@ sub get_etc_services {
     return $etc_services;
 }
 
-my $etc_protocols;
-
-sub get_etc_protocols {
-    return $etc_protocols if $etc_protocols;
-
-    my $filename = "/etc/protocols";
+sub parse_protocol_file {
+    my ($filename) = @_;
 
     my $fh = IO::File->new($filename, O_RDONLY);
     if (!$fh) {
@@ -895,7 +892,7 @@ sub get_etc_protocols {
        next if $line =~m/^#/;
        next if ($line =~m/^\s*$/);
 
-       if ($line =~ m!^(\S+)\s+(\d+)\s+.*$!) {
+       if ($line =~ m!^(\S+)\s+(\d+)(?:\s+.*)?$!) {
            $protocols->{byid}->{$2}->{name} = $1;
            $protocols->{byname}->{$1} = $protocols->{byid}->{$2};
        }
@@ -903,6 +900,16 @@ sub get_etc_protocols {
 
     close($fh);
 
+    return $protocols;
+}
+
+my $etc_protocols;
+
+sub get_etc_protocols {
+    return $etc_protocols if $etc_protocols;
+
+    my $protocols = parse_protocol_file('/etc/protocols');
+
     # add special case for ICMP v6
     $protocols->{byid}->{icmpv6}->{name} = "icmpv6";
     $protocols->{byname}->{icmpv6} = $protocols->{byid}->{icmpv6};
@@ -1034,12 +1041,13 @@ sub parse_port_name_number_or_range {
     my @elements = split(/,/, $str);
     die "extraneous commas in list\n" if $str ne join(',', @elements);
     foreach my $item (@elements) {
-       $count++;
        if ($item =~ m/^(\d+):(\d+)$/) {
+           $count += 2;
            my ($port1, $port2) = ($1, $2);
            die "invalid port '$port1'\n" if $port1 > 65535;
            die "invalid port '$port2'\n" if $port2 > 65535;
        } elsif ($item =~ m/^(\d+)$/) {
+           $count += 1;
            my $port = $1;
            die "invalid port '$port'\n" if $port > 65535;
        } else {
@@ -1053,9 +1061,15 @@ sub parse_port_name_number_or_range {
        }
     }
 
-    die "ICPM ports not allowed in port range\n" if $icmp_port && $count > 1;
+    die "ICPM ports not allowed in port range\n" if $icmp_port && $count > 0;
+
+    # I really don't like to use the word number here, but it's the only thing
+    # that makes sense in a literal way. The range 1:100 counts as 2, not as
+    # one and not as 100...
+    die "too many entries in port list (> 15 numbers)\n"
+       if $count > 15;
 
-    return $count;
+    return (scalar(@elements) > 1);
 }
 
 PVE::JSONSchema::register_format('pve-fw-sport-spec', \&pve_fw_verify_sport_spec);
@@ -1799,171 +1813,154 @@ sub ipset_get_chains {
     return $res;
 }
 
-sub ruleset_generate_match {
-    my ($ruleset, $chain, $ipversion, $rule, $actions, $goto, $cluster_conf, $fw_conf) = @_;
-
-    return if defined($rule->{enable}) && !$rule->{enable};
-    return if $rule->{errors};
-
-    return $rule->{match} if defined $rule->{match};
-
-    die "unable to emit macro - internal error" if $rule->{macro}; # should not happen
-
-    my $nbdport = defined($rule->{dport}) ? parse_port_name_number_or_range($rule->{dport}, 1) : 0;
-    my $nbsport = defined($rule->{sport}) ? parse_port_name_number_or_range($rule->{sport}, 0) : 0;
-
-    my @cmd = ();
+# substitude action of rule according to action hash
+sub rule_substitude_action {
+    my ($rule, $actions) = @_;
 
-    push @cmd, "-i $rule->{iface_in}" if $rule->{iface_in};
-    push @cmd, "-o $rule->{iface_out}" if $rule->{iface_out};
-
-    my $source = $rule->{source};
-    my $dest = $rule->{dest};
-
-    if ($source) {
-        if ($source =~ m/^\+/) {
-           if ($source =~ m/^\+(${ipset_name_pattern})$/) {
-               my $name = $1;
-               if ($fw_conf && $fw_conf->{ipset}->{$name}) {
-                   my $ipset_chain = compute_ipset_chain_name($fw_conf->{vmid}, $name, $ipversion);
-                   push @cmd, "-m set --match-set ${ipset_chain} src";
-               } elsif ($cluster_conf && $cluster_conf->{ipset}->{$name}) {
-                   my $ipset_chain = compute_ipset_chain_name(0, $name, $ipversion);
-                   push @cmd, "-m set --match-set ${ipset_chain} src";
-               } else {
-                   die "no such ipset '$name'\n";
-               }
-           } else {
-               die "invalid security group name '$source'\n";
-           }
-       } elsif ($source =~ m/^${ip_alias_pattern}$/){
-           my $alias = lc($source);
-           my $e = $fw_conf ? $fw_conf->{aliases}->{$alias} : undef;
-           $e = $cluster_conf->{aliases}->{$alias} if !$e && $cluster_conf;
-           die "no such alias '$source'\n" if !$e;
-           push @cmd, "-s $e->{cidr}";
-        } elsif ($source =~ m/\-/){
-           push @cmd, "-m iprange --src-range $source";
-       } else {
-           push @cmd, "-s $source";
-        }
+    if (my $action = $rule->{action}) {
+       $rule->{action} = $actions->{$action} if defined($actions->{$action});
     }
+}
 
-    if ($dest) {
-        if ($dest =~ m/^\+/) {
-           if ($dest =~ m/^\+(${ipset_name_pattern})$/) {
-               my $name = $1;
-               if ($fw_conf && $fw_conf->{ipset}->{$name}) {
-                   my $ipset_chain = compute_ipset_chain_name($fw_conf->{vmid}, $name, $ipversion);
-                   push @cmd, "-m set --match-set ${ipset_chain} dst";
-               } elsif ($cluster_conf && $cluster_conf->{ipset}->{$name}) {
-                   my $ipset_chain = compute_ipset_chain_name(0, $name, $ipversion);
-                   push @cmd, "-m set --match-set ${ipset_chain} dst";
-               } else {
-                   die "no such ipset '$name'\n";
-               }
+# generate a src or dst match
+# $dir(ection) is either d or s
+sub ipt_gen_src_or_dst_match {
+    my ($adr, $dir, $ipversion, $cluster_conf, $fw_conf) = @_;
+
+    my $srcdst;
+    if ($dir eq 's') {
+       $srcdst = "src";
+    } elsif ($dir eq 'd') {
+       $srcdst = "dst";
+    } else {
+       die "ipt_gen_src_or_dst_match: invalid direction $dir \n";
+    }
+
+    my $match;
+    if ($adr =~ m/^\+/) {
+       if ($adr =~ m/^\+(${ipset_name_pattern})$/) {
+           my $name = $1;
+           my $ipset_chain;
+           if ($fw_conf && $fw_conf->{ipset}->{$name}) {
+               $ipset_chain = compute_ipset_chain_name($fw_conf->{vmid}, $name, $ipversion);
+           } elsif ($cluster_conf && $cluster_conf->{ipset}->{$name}) {
+               $ipset_chain = compute_ipset_chain_name(0, $name, $ipversion);
            } else {
-               die "invalid security group name '$dest'\n";
+               die "no such ipset '$name'\n";
            }
-       } elsif ($dest =~ m/^${ip_alias_pattern}$/){
-           my $alias = lc($dest);
-           my $e = $fw_conf ? $fw_conf->{aliases}->{$alias} : undef;
-           $e = $cluster_conf->{aliases}->{$alias} if !$e && $cluster_conf;
-           die "no such alias '$dest'\n" if !$e;
-           push @cmd, "-d $e->{cidr}";
-        } elsif ($dest =~ m/^(\d+)\.(\d+).(\d+).(\d+)\-(\d+)\.(\d+).(\d+).(\d+)$/){
-           push @cmd, "-m iprange --dst-range $dest";
+           $match = "-m set --match-set ${ipset_chain} ${srcdst}";
        } else {
-           push @cmd, "-d $dest";
-        }
+           die "invalid security group name '$adr'\n";
+       }
+    } elsif ($adr =~ m/^${ip_alias_pattern}$/){
+       my $alias = lc($adr);
+       my $e = $fw_conf ? $fw_conf->{aliases}->{$alias} : undef;
+       $e = $cluster_conf->{aliases}->{$alias} if !$e && $cluster_conf;
+       die "no such alias '$adr'\n" if !$e;
+       $match = "-${dir} $e->{cidr}";
+    } elsif ($adr =~ m/\-/){
+       $match = "-m iprange --${srcdst}-range $adr";
+    } else {
+       $match = "-${dir} $adr";
     }
 
-    if (my $proto = $rule->{proto}) {
-       push @cmd, "-p $proto";
+    return $match;
+}
 
-       my $multiport = 0;
-       $multiport++ if $nbdport > 1;
-       $multiport++ if $nbsport > 1;
+# convert a %rule to an array of iptables commands
+sub ipt_rule_to_cmds {
+    my ($rule, $chain, $ipversion, $cluster_conf, $fw_conf, $vmid) = @_;
 
-       push @cmd, "--match multiport" if $multiport;
+    die "ipt_rule_to_cmds unable to handle macro" if $rule->{macro}; #should not happen
 
-       die "multiport: option '--sports' cannot be used together with '--dports'\n"
-           if ($multiport == 2) && ($rule->{dport} ne $rule->{sport});
+    my @match = ();
 
-       if ($rule->{dport}) {
-           if ($proto eq 'icmp') {
-               # Note: we use dport to store --icmp-type
-               die "unknown icmp-type '$rule->{dport}'\n"
-                   if $rule->{dport} !~ /^\d+$/ && !defined($icmp_type_names->{$rule->{dport}});
-               push @cmd, "-m icmp --icmp-type $rule->{dport}";
-           } elsif ($proto eq 'icmpv6') {
-               # Note: we use dport to store --icmpv6-type
-               die "unknown icmpv6-type '$rule->{dport}'\n"
-                   if $rule->{dport} !~ /^\d+$/ && !defined($icmpv6_type_names->{$rule->{dport}});
-               push @cmd, "-m icmpv6 --icmpv6-type $rule->{dport}";
-           } elsif (!$PROTOCOLS_WITH_PORTS->{$proto}) {
-               die "protocol $proto does not have ports\n";
-           } else {
-               if ($nbdport > 1) {
-                   if ($multiport == 2) {
-                       push @cmd,  "--ports $rule->{dport}";
-                   } else {
-                       push @cmd, "--dports $rule->{dport}";
-                   }
+    if (defined $rule->{match}) {
+       push @match, $rule->{match};
+    } else {
+       push @match, "-i $rule->{iface_in}" if $rule->{iface_in};
+       push @match, "-o $rule->{iface_out}" if $rule->{iface_out};
+
+       if ($rule->{source}) {
+           push @match, ipt_gen_src_or_dst_match($rule->{source}, 's', $ipversion, $cluster_conf, $fw_conf);
+       }
+       if ($rule->{dest}) {
+           push @match, ipt_gen_src_or_dst_match($rule->{dest}, 'd', $ipversion, $cluster_conf, $fw_conf);
+       }
+
+       if (my $proto = $rule->{proto}) {
+           push @match, "-p $proto";
+
+           my $multidport = defined($rule->{dport}) && parse_port_name_number_or_range($rule->{dport}, 1);
+           my $multisport = defined($rule->{sport}) && parse_port_name_number_or_range($rule->{sport}, 0);
+
+           my $add_dport = sub {
+               return if !$rule->{dport};
+
+               if ($proto eq 'icmp') {
+                   # Note: we use dport to store --icmp-type
+                   die "unknown icmp-type '$rule->{dport}'\n"
+                       if $rule->{dport} !~ /^\d+$/ && !defined($icmp_type_names->{$rule->{dport}});
+                   push @match, "-m icmp --icmp-type $rule->{dport}";
+               } elsif ($proto eq 'icmpv6') {
+                   # Note: we use dport to store --icmpv6-type
+                   die "unknown icmpv6-type '$rule->{dport}'\n"
+                       if $rule->{dport} !~ /^\d+$/ && !defined($icmpv6_type_names->{$rule->{dport}});
+                   push @match, "-m icmpv6 --icmpv6-type $rule->{dport}";
+               } elsif (!$PROTOCOLS_WITH_PORTS->{$proto}) {
+                   die "protocol $proto does not have ports\n";
+               } elsif ($multidport) {
+                   push @match, "--match multiport", "--dports $rule->{dport}";
                } else {
-                   push @cmd, "--dport $rule->{dport}";
+                   push @match, "--dport $rule->{dport}";
                }
-           }
-       }
-
-       if ($rule->{sport}) {
-           die "protocol $proto does not have ports\n"
-                if !$PROTOCOLS_WITH_PORTS->{$proto};
-           if ($nbsport > 1) {
-               push @cmd, "--sports $rule->{sport}" if $multiport != 2;
-           } else {
-               push @cmd, "--sport $rule->{sport}";
-           }
-       }
-    } elsif ($rule->{dport} || $rule->{sport}) {
-       die "destination port '$rule->{dport}', but no protocol specified\n" if $rule->{dport};
-       die "source port '$rule->{sport}', but no protocol specified\n" if $rule->{sport};
-    }
-
-    push @cmd, "-m addrtype --dst-type $rule->{dsttype}" if $rule->{dsttype};
-
-    return scalar(@cmd) ? join(' ', @cmd) : undef;
-}
+           };
 
-sub ruleset_generate_action {
-    my ($ruleset, $chain, $ipversion, $rule, $actions, $goto, $cluster_conf, $fw_conf) = @_;
+           my $add_sport = sub {
+               return if !$rule->{sport};
 
-    return $rule->{target} if defined $rule->{target};
+               die "protocol $proto does not have ports\n"
+                   if !$PROTOCOLS_WITH_PORTS->{$proto};
+               if ($multisport) {
+                   push @match, "--match multiport", "--sports $rule->{sport}";
+               } else {
+                   push @match, "--sport $rule->{sport}";
+               }
+           };
 
-    my @cmd = ();
+           # order matters - single port before multiport!
+           $add_dport->() if $multisport;
+           $add_sport->();
+           $add_dport->() if !$multisport;
+       } elsif ($rule->{dport} || $rule->{sport}) {
+           die "destination port '$rule->{dport}', but no protocol specified\n" if $rule->{dport};
+           die "source port '$rule->{sport}', but no protocol specified\n" if $rule->{sport};
+       }
 
-    if (my $action = $rule->{action}) {
-       $action = $actions->{$action} if defined($actions->{$action});
-       $goto = 1 if !defined($goto) && $action eq 'PVEFW-SET-ACCEPT-MARK';
-       push @cmd, $goto ? "-g $action" : "-j $action";
+       push @match, "-m addrtype --dst-type $rule->{dsttype}" if $rule->{dsttype};
     }
+    my $matchstr = scalar(@match) ? join(' ', @match) : "";
 
-    return scalar(@cmd) ? join(' ', @cmd) : undef;
-}
-
-sub ruleset_generate_cmdstr {
-    my ($ruleset, $chain, $ipversion, $rule, $actions, $goto, $cluster_conf, $fw_conf) = @_;
-    my $match = ruleset_generate_match($ruleset, $chain, $ipversion, $rule, $actions, $goto, $cluster_conf, $fw_conf);
-    my $action = ruleset_generate_action($ruleset, $chain, $ipversion, $rule, $actions, $goto, $cluster_conf, $fw_conf);
+    my $targetstr;
+    if (defined $rule->{target}) {
+       $targetstr = $rule->{target};
+    } else {
+       my $action = (defined $rule->{action}) ? $rule->{action} : "";
+       my $goto = 1 if $action eq 'PVEFW-SET-ACCEPT-MARK';
+       $targetstr = ($goto) ? "-g $action" : "-j $action";
+    }
 
-    return undef if !(defined($match) or defined($action));
-    my $ret = defined($match) ? $match : "";
-    $ret = "$ret $action" if defined($action);
-    return $ret;
+    my @iptcmds;
+    if (defined $rule->{log} && $rule->{log}) {
+       my $logaction = get_log_rule_base($chain, $vmid, $rule->{logmsg}, $rule->{log});
+       push @iptcmds, "-A $chain $matchstr $logaction";
+    }
+    push @iptcmds, "-A $chain $matchstr $targetstr";
+    return @iptcmds;
 }
 
 sub ruleset_generate_rule {
-    my ($ruleset, $chain, $ipversion, $rule, $actions, $goto, $cluster_conf, $fw_conf) = @_;
+    my ($ruleset, $chain, $ipversion, $rule, $cluster_conf, $fw_conf) = @_;
 
     my $rules;
 
@@ -1974,37 +1971,12 @@ sub ruleset_generate_rule {
     }
 
     # update all or nothing
-
-    # fixme: lots of temporary ugliness
-    my @mstrs = ();
-    my @astrs = ();
-    my @logging = ();
-    my @logmsg = ();
-    foreach my $tmp (@$rules) {
-       my $m = ruleset_generate_match($ruleset, $chain, $ipversion, $tmp, $actions, $goto, $cluster_conf, $fw_conf);
-       my $a = ruleset_generate_action($ruleset, $chain, $ipversion, $tmp, $actions, $goto, $cluster_conf, $fw_conf);
-       if (defined $m or defined $a) {
-           push @mstrs, defined($m) ? $m : "";
-           push @astrs, defined($a) ? $a : "";
-           push @logging, $tmp->{log};
-           push @logmsg, $tmp->{logmsg};
-       }
+    my @ipt_rule_cmds;
+    foreach my $r (@$rules) {
+       push @ipt_rule_cmds, ipt_rule_to_cmds($r, $chain, $ipversion, $cluster_conf, $fw_conf);
     }
-
-    for my $i (0 .. $#mstrs) {
-       ruleset_addrule($ruleset, $chain, $mstrs[$i], $astrs[$i], $logging[$i], $logmsg[$i]);
-    }
-}
-
-sub ruleset_generate_rule_insert {
-    my ($ruleset, $chain, $ipversion, $rule, $actions, $goto) = @_;
-
-    die "implement me" if $rule->{macro}; # not implemented, because not needed so far
-
-    my $match = ruleset_generate_match($ruleset, $chain, $ipversion, $rule, $actions, $goto);
-    my $action = ruleset_generate_action($ruleset, $chain, $ipversion, $rule, $actions, $goto);
-    if (defined $match && defined $action) {
-       ruleset_insertrule($ruleset, $chain, $match, $action);
+    foreach my $c (@ipt_rule_cmds) {
+       ruleset_add_ipt_cmd($ruleset, $chain, $c);
     }
 }
 
@@ -2025,6 +1997,15 @@ sub ruleset_chain_exist {
     return $ruleset->{$chain} ? 1 : undef;
 }
 
+# add an iptables command (like generated by ipt_rule_to_cmds) to a chain
+sub ruleset_add_ipt_cmd {
+   my ($ruleset, $chain, $iptcmd) = @_;
+
+   die "no such chain '$chain'\n" if !$ruleset->{$chain};
+
+   push @{$ruleset->{$chain}}, $iptcmd;
+}
+
 sub ruleset_addrule {
    my ($ruleset, $chain, $match, $action, $log, $logmsg, $vmid) = @_;
 
@@ -2062,8 +2043,9 @@ sub ruleset_add_chain_policy {
 
     if ($policy eq 'ACCEPT') {
 
-       ruleset_generate_rule($ruleset, $chain, $ipversion, { action => 'ACCEPT' },
-                             { ACCEPT =>  $accept_action});
+       my $rule = { action => 'ACCEPT' };
+       rule_substitude_action($rule, { ACCEPT =>  $accept_action});
+       ruleset_generate_rule($ruleset, $chain, $ipversion, $rule);
 
     } elsif ($policy eq 'DROP') {
 
@@ -2209,13 +2191,11 @@ sub ruleset_generate_vm_rules {
            next if $rule->{type} ne $lc_direction;
            eval {
                if ($direction eq 'OUT') {
-                   ruleset_generate_rule($ruleset, $chain, $ipversion, $rule,
-                                         { ACCEPT => "PVEFW-SET-ACCEPT-MARK", REJECT => "PVEFW-reject" },
-                                         undef, $cluster_conf, $vmfw_conf);
+                   rule_substitude_action($rule, { ACCEPT => "PVEFW-SET-ACCEPT-MARK", REJECT => "PVEFW-reject" });
+                   ruleset_generate_rule($ruleset, $chain, $ipversion, $rule, $cluster_conf, $vmfw_conf);
                } else {
-                   ruleset_generate_rule($ruleset, $chain, $ipversion, $rule,
-                                         { ACCEPT => $in_accept , REJECT => "PVEFW-reject" },
-                                         undef, $cluster_conf, $vmfw_conf);
+                   rule_substitude_action($rule, { ACCEPT => $in_accept , REJECT => "PVEFW-reject" });
+                   ruleset_generate_rule($ruleset, $chain, $ipversion, $rule, $cluster_conf, $vmfw_conf);
                }
            };
            warn $@ if $@;
@@ -2343,9 +2323,8 @@ sub enable_host_firewall {
            if ($rule->{type} eq 'group') {
                ruleset_add_group_rule($ruleset, $cluster_conf, $chain, $rule, 'IN', $accept_action, $ipversion);
            } elsif ($rule->{type} eq 'in') {
-               ruleset_generate_rule($ruleset, $chain, $ipversion, $rule, 
-                                     { ACCEPT => $accept_action, REJECT => "PVEFW-reject" },
-                                     undef, $cluster_conf, $hostfw_conf);
+               rule_substitude_action($rule, { ACCEPT => $accept_action, REJECT => "PVEFW-reject" });
+               ruleset_generate_rule($ruleset, $chain, $ipversion, $rule, $cluster_conf, $hostfw_conf);
            }
        };
        warn $@ if $@;
@@ -2400,9 +2379,8 @@ sub enable_host_firewall {
            if ($rule->{type} eq 'group') {
                ruleset_add_group_rule($ruleset, $cluster_conf, $chain, $rule, 'OUT', $accept_action, $ipversion);
            } elsif ($rule->{type} eq 'out') {
-               ruleset_generate_rule($ruleset, $chain, $ipversion, 
-                                     $rule, { ACCEPT => $accept_action, REJECT => "PVEFW-reject" },
-                                     undef, $cluster_conf, $hostfw_conf);
+               rule_substitude_action($rule, { ACCEPT => $accept_action, REJECT => "PVEFW-reject" });
+               ruleset_generate_rule($ruleset, $chain, $ipversion, $rule, $cluster_conf, $hostfw_conf);
            }
        };
        warn $@ if $@;
@@ -2446,10 +2424,10 @@ sub generate_group_rules {
 
     foreach my $rule (@$rules) {
        next if $rule->{type} ne 'in';
+       next if !$rule->{enable} || $rule->{errors};
        next if $rule->{ipversion} && $rule->{ipversion} ne $ipversion;
-       ruleset_generate_rule($ruleset, $chain, $ipversion, $rule, 
-                             { ACCEPT => "PVEFW-SET-ACCEPT-MARK", REJECT => "PVEFW-reject" }, 
-                             undef, $cluster_conf);
+       rule_substitude_action($rule, { ACCEPT => "PVEFW-SET-ACCEPT-MARK", REJECT => "PVEFW-reject" });
+       ruleset_generate_rule($ruleset, $chain, $ipversion, $rule, $cluster_conf);
     }
 
     $chain = "GROUP-${group}-OUT";
@@ -2459,12 +2437,12 @@ sub generate_group_rules {
 
     foreach my $rule (@$rules) {
        next if $rule->{type} ne 'out';
+       next if !$rule->{enable} || $rule->{errors};
        next if $rule->{ipversion} && $rule->{ipversion} ne $ipversion;
        # we use PVEFW-SET-ACCEPT-MARK (Instead of ACCEPT) because we need to
        # check also other tap rules later
-       ruleset_generate_rule($ruleset, $chain, $ipversion, $rule,
-                             { ACCEPT => 'PVEFW-SET-ACCEPT-MARK', REJECT => "PVEFW-reject" }, 
-                             undef, $cluster_conf);
+       rule_substitude_action($rule, { ACCEPT => 'PVEFW-SET-ACCEPT-MARK', REJECT => "PVEFW-reject" });
+       ruleset_generate_rule($ruleset, $chain, $ipversion, $rule, $cluster_conf);
     }
 }