[pve-devel] [PATCH] bypass firewall for non firewalled vms

Alexandre Derumier aderumier at odiso.com
Fri May 9 19:10:36 CEST 2014


-A FORWARD -i fwbr+ -j PVEFW-FORWARD
-A FORWARD -o venet0 -m set --match-set PVEFW-venet0 dst -j PVEFW-FORWARD
-A FORWARD -i venet0 -m set --match-set PVEFW-venet0 src -j PVEFW-FORWARD

we use an ipset PVEFW-venet0 with all venet0 ip address

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 src/PVE/Firewall.pm |   18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/PVE/Firewall.pm b/src/PVE/Firewall.pm
index 1f4d9ce..4934eb0 100644
--- a/src/PVE/Firewall.pm
+++ b/src/PVE/Firewall.pm
@@ -2108,7 +2108,6 @@ sub parse_cluster_fw_rules {
 	    push @{$res->{$section}->{$group}}, $entry;
 	}
     }
-
     return $res;
 }
 
@@ -2521,8 +2520,7 @@ sub compile {
     my $vmdata = read_local_vm_config();
     my $vmfw_configs = read_vm_firewall_configs($vmdata);
 
-    my $ipset_ruleset = {};
-    generate_ipset_chains($ipset_ruleset, $cluster_conf);
+    $cluster_conf->{ipset}->{venet0} = [];
 
     my $ruleset = {};
 
@@ -2620,6 +2618,9 @@ sub compile {
 
 	if ($conf->{ip_address} && $conf->{ip_address}->{value}) {
 	    my $ip = $conf->{ip_address}->{value};
+	    my $venet0ipset = {};
+	    $venet0ipset->{cidr} = $ip;
+	    push @{$cluster_conf->{ipset}->{venet0}}, $venet0ipset;
 	    generate_venet_rules_direction($ruleset, $cluster_conf, $hostfw_conf, $vmfw_conf, $vmid, $ip, 'IN');
 	    generate_venet_rules_direction($ruleset, $cluster_conf, $hostfw_conf, $vmfw_conf, $vmid, $ip, 'OUT');
 	}
@@ -2639,6 +2640,9 @@ sub compile {
 	}
     }
 
+    my $ipset_ruleset = {};
+    generate_ipset_chains($ipset_ruleset, $cluster_conf);
+
     return ($ruleset, $ipset_ruleset);
 }
 
@@ -2704,12 +2708,18 @@ sub get_ruleset_cmdlist {
 	$cmdlist .= ":$chain - [0:0]\n";
     }
 
-    foreach my $h (qw(INPUT OUTPUT FORWARD)) {
+    foreach my $h (qw(INPUT OUTPUT)) {
 	if (!$hooks->{$h}) {
 	    $cmdlist .= "-A $h -j PVEFW-$h\n";
 	}
     }
 
+    if (!$hooks->{"FORWARD"}) {
+	    $cmdlist .= "-A FORWARD -i fwbr+ -j PVEFW-FORWARD\n";
+	    $cmdlist .= "-A FORWARD -o venet0 -m set --match-set PVEFW-venet0 dst -j PVEFW-FORWARD\n";
+	    $cmdlist .= "-A FORWARD -i venet0 -m set --match-set PVEFW-venet0 src -j PVEFW-FORWARD\n";
+    }
+
     foreach my $chain (sort keys %$ruleset) {
 	my $stat = $statushash->{$chain};
 	die "internal error" if !$stat;
-- 
1.7.10.4




More information about the pve-devel mailing list