[pve-devel] [PULL stable-3 firewall 3/6] Add radv option to VM options.

Wolfgang Bumiller w.bumiller at proxmox.com
Mon Mar 7 14:44:56 CET 2016


By default firewalled VMs should not be allowed to send
router advertisement packets.
---
 src/PVE/API2/Firewall/VM.pm |  5 +++++
 src/PVE/Firewall.pm         | 13 +++++++++----
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/PVE/API2/Firewall/VM.pm b/src/PVE/API2/Firewall/VM.pm
index 9cca0c6..aad973b 100644
--- a/src/PVE/API2/Firewall/VM.pm
+++ b/src/PVE/API2/Firewall/VM.pm
@@ -33,6 +33,11 @@ my $option_properties = {
 	type => 'boolean',
 	optional => 1,
     },
+    radv => {
+	description => "Allow sending Router Advertisement.",
+	type => 'boolean',
+	optional => 1,
+    },
     policy_in => {
 	description => "Input policy.",
 	type => 'string',
diff --git a/src/PVE/Firewall.pm b/src/PVE/Firewall.pm
index 5ec5c81..e9b9ac3 100644
--- a/src/PVE/Firewall.pm
+++ b/src/PVE/Firewall.pm
@@ -1877,11 +1877,13 @@ sub ruleset_add_chain_policy {
 }
 
 sub ruleset_chain_add_ndp {
-    my ($ruleset, $chain, $ipversion, $options) = @_;
+    my ($ruleset, $chain, $ipversion, $options, $direction) = @_;
     return if $ipversion != 6 || (defined($options->{ndp}) && !$options->{ndp});
 
     ruleset_addrule($ruleset, $chain, "-p icmpv6 --icmpv6-type router-solicitation -j ACCEPT");
-    ruleset_addrule($ruleset, $chain, "-p icmpv6 --icmpv6-type router-advertisement -j ACCEPT");
+    if ($direction ne 'OUT' || $options->{radv}) {
+	ruleset_addrule($ruleset, $chain, "-p icmpv6 --icmpv6-type router-advertisement -j ACCEPT");
+    }
     ruleset_addrule($ruleset, $chain, "-p icmpv6 --icmpv6-type neighbor-solicitation -j ACCEPT");
     ruleset_addrule($ruleset, $chain, "-p icmpv6 --icmpv6-type neighbor-advertisement -j ACCEPT");
 }
@@ -1935,12 +1937,15 @@ sub ruleset_create_vm_chain {
 	}
     }
 
-    ruleset_chain_add_ndp($ruleset, $chain, $ipversion, $options);
+    ruleset_chain_add_ndp($ruleset, $chain, $ipversion, $options, $direction);
 
     if ($direction eq 'OUT') {
 	if (defined($macaddr) && !(defined($options->{macfilter}) && $options->{macfilter} == 0)) {
 	    ruleset_addrule($ruleset, $chain, "-m mac ! --mac-source $macaddr -j DROP");
 	}
+	if ($ipversion == 6 && !$options->{radv}) {
+	    ruleset_addrule($ruleset, $chain, '-p icmpv6 --icmpv6-type router-advertisement -j DROP');
+	}
 	if ($ipfilter_ipset) {
 	    ruleset_addrule($ruleset, $chain, "-m set ! --match-set $ipfilter_ipset src -j DROP");
 	}
@@ -2377,7 +2382,7 @@ sub parse_vmfw_option {
 
     my $loglevels = "emerg|alert|crit|err|warning|notice|info|debug|nolog";
 
-    if ($line =~ m/^(enable|dhcp|ndp|macfilter|ips):\s*(0|1)\s*$/i) {
+    if ($line =~ m/^(enable|dhcp|ndp|radv|macfilter|ips):\s*(0|1)\s*$/i) {
 	$opt = lc($1);
 	$value = int($2);
     } elsif ($line =~ m/^(log_level_in|log_level_out):\s*(($loglevels)\s*)?$/i) {
-- 
2.1.4





More information about the pve-devel mailing list