- if ($rule =~ s/^-p (tcp|udp)\s*//) {
- die "missing proto" if !$pkg->{proto};
- return undef if $pkg->{proto} ne $1; # no match
- }
-
- if ($rule =~ s/^--dport (\d+):(\d+)\s*//) {
- die "missing dport" if !$pkg->{dport};
- return undef if ($pkg->{dport} < $1) || ($pkg->{dport} > $2); # no match
- }
-
- if ($rule =~ s/^--dport (\d+)\s*//) {
- die "missing dport" if !$pkg->{dport};
- return undef if $pkg->{dport} != $1; # no match
- }
-
- if ($rule =~ s/^-s (\S+)\s*//) {
- die "missing source" if !$pkg->{source};
- return undef if $pkg->{source} ne $1; # no match
- }
-
- if ($rule =~ s/^-d (\S+)\s*//) {
- die "missing destination" if !$pkg->{dest};
- return undef if $pkg->{dest} ne $1; # no match
- }
-
- if ($rule =~ s/^-m mac ! --mac-source (\S+)\s*//) {
- die "missing source mac" if !$pkg->{mac_source};
- return undef if $pkg->{mac_source} eq $1; # no match
- }
-
- if ($rule =~ s/^-m physdev --physdev-is-bridged --physdev-in (\S+)\s*//) {
- my $devre = $1;
- $devre =~ s/\+/\.\*/;
- return undef if !$pkg->{physdev_in};
- return undef if $pkg->{physdev_in} !~ m/^${devre}$/;
- }
-
- if ($rule =~ s/^-m physdev --physdev-is-bridged --physdev-out (\S+)\s*//) {
- my $devre = $1;
- $devre =~ s/\+/\.\*/;
- return undef if !$pkg->{physdev_out};
- return undef if $pkg->{physdev_out} !~ m/^${devre}$/;
- }
-
- if ($rule =~ s/^-j MARK --set-mark (\d+)\s*$//) {
- $mark = $1;
- return undef;
- }
-
- if ($rule =~ s/^-j (\S+)\s*$//) {
- return (0, $1);
- }
-
- if ($rule =~ s/^-g (\S+)\s*$//) {
- return (1, $1);
- }
-
- die "unable to parse rule: $rule";
-}
-
-sub ruleset_simulate_chain {
- my ($ruleset, $chain, $pkg) = @_;
-
- $trace .= "ENTER chain $chain\n";
-
- if ($chain eq 'PVEFW-Drop') {
- $trace .= "LEAVE chain $chain\n";
- return 'DROP';
- }
- if ($chain eq 'PVEFW-reject') {
- $trace .= "LEAVE chain $chain\n";
- return 'REJECT';
- }
-
- if ($chain eq 'PVEFW-tcpflags') {
- $trace .= "LEAVE chain $chain\n";
- return undef;
- }
-
- my $rules = $ruleset->{$chain} ||
- die "no such chain '$chain'";