From: Thomas Lamprecht Date: Mon, 4 May 2020 12:10:53 +0000 (+0200) Subject: test/simulator: add very basic ICMP type functionallity X-Git-Url: https://git.proxmox.com/?p=pve-firewall.git;a=commitdiff_plain;h=29e5ce15369c288b74fec101bcf0f2ad5ff27a9c test/simulator: add very basic ICMP type functionallity For now without integer to full-name, and vice versa, mapping of ICMP types. Signed-off-by: Thomas Lamprecht --- diff --git a/src/PVE/FirewallSimulator.pm b/src/PVE/FirewallSimulator.pm index 4f46b74..140c46e 100644 --- a/src/PVE/FirewallSimulator.pm +++ b/src/PVE/FirewallSimulator.pm @@ -29,9 +29,7 @@ my $NUMBER_RE = qr/0x[0-9a-fA-F]+|\d+/; sub debug { my $new_value = shift; - $debug = $new_value if defined($new_value); - return $debug; } @@ -140,6 +138,13 @@ sub rule_match { return undef if $atype ne $pkg->{dsttype}; } + if ($rule =~ s/^-m icmp(v6)? --icmp-type (\S+)\s*//) { + my $icmpv6 = !!$1; + my $icmptype = $2; + die "missing destination address type (dsttype)\n" if !defined($pkg->{dport}); + return undef if $icmptype ne $pkg->{dport}; + } + if ($rule =~ s/^-i (\S+)\s*//) { my $devre = $1; die "missing interface (iface_in)\n" if !$pkg->{iface_in}; diff --git a/test/test-basic1/100.fw b/test/test-basic1/100.fw index c9d675e..9dbe2f3 100644 --- a/test/test-basic1/100.fw +++ b/test/test-basic1/100.fw @@ -5,4 +5,6 @@ enable: 1 [RULES] IN ACCEPT -p tcp -dport 443 +IN ACCEPT -p icmp -dport 0 +IN ACCEPT -p icmp -dport host-unreachable OUT REJECT -p tcp -dport 81 diff --git a/test/test-basic1/tests b/test/test-basic1/tests index d575bbe..a993e5d 100644 --- a/test/test-basic1/tests +++ b/test/test-basic1/tests @@ -21,6 +21,10 @@ { from => 'vm110', to => 'vm100', dport => 22, action => 'DROP' } { from => 'vm110', to => 'vm100', dport => 443, action => 'ACCEPT' } +{ from => 'vm110', to => 'vm100', dport => 0, proto => 'icmp', action => 'ACCEPT' } +{ from => 'vm110', to => 'vm100', dport => 'host-unreachable', proto => 'icmp', action => 'ACCEPT' } +{ from => 'vm110', to => 'vm100', dport => 255, proto => 'icmpv6', action => 'DROP' } + { from => 'outside', to => 'ct200', dport => 22, action => 'ACCEPT' } { from => 'outside', to => 'ct200', dport => 23, action => 'DROP' } { from => 'outside', to => 'vm100', dport => 22, action => 'DROP' }