[pve-devel] [PATCH 12/16] /etc/network/interfaces: deal with OVS allow- lines

Wolfgang Bumiller w.bumiller at proxmox.com
Wed Jun 24 14:33:26 CEST 2015


* __read_etc_interfaces:
Delete OVS ports from "allow-$OVS_BRIDGE" option lines in
order to prevent them from being duplicated or kept after
removing the port from the bridge.

* __write_etc_interfaces:
Deleting unused OVSPorts has the side effect of them not
being written out at all. If, however, they are
physical interfaces they'll reappear the next time the
configuration is read, because they're added from
/proc/net/dev.
Fix: if the deleted interface matches the same condition as
in read_etc_interfaces, readd it with the standard options:
{exists => 1, method => manual }
This is a purely aesthetical change in order to make sure a
write()->read()->write() chain doesn't produce two
different files each write().
---
 src/PVE/INotify.pm | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm
index 0675538..13c55bc 100644
--- a/src/PVE/INotify.pm
+++ b/src/PVE/INotify.pm
@@ -996,6 +996,30 @@ sub __read_etc_network_interfaces {
 	close ($proc_net_if_inet6);
     }
 
+    # OVS bridges create "allow-$BRIDGE $IFACE" lines which we need to remove
+    # from the {options} hash for them to be removed correctly.
+    @$options = grep {defined($_)} map {
+	my ($pri, $line) = @$_;
+	if ($line =~ /^allow-(\S+)\s+(.*)$/) {
+	    my $bridge = $1;
+	    my @ports = split(/\s+/, $2);
+	    if (defined(my $br = $ifaces->{$bridge})) {
+		# if this port is part of a bridge, remove it
+		my %in_ovs_ports = map {$_=>1} split(/\s+/, $br->{ovs_ports});
+		@ports = grep { not $in_ovs_ports{$_} } @ports;
+	    }
+	    # create the allow line for the remaining ports, or delete if empty
+	    if (@ports) {
+		[$pri, "allow-$bridge " . join(' ', @ports)];
+	    } else {
+		undef;
+	    }
+	} else {
+	    # don't modify other lines
+	    $_;
+	}
+    } @$options;
+
     return $config;
 }
 
@@ -1171,7 +1195,14 @@ sub __write_etc_network_interfaces {
 	    $d->{type} eq 'OVSBond') {
 	    my $brname = $used_ports->{$iface};
 	    if (!$brname || !$ifaces->{$brname}) { 
-		delete $ifaces->{$iface}; 
+		if ($iface =~ /^eth/) {
+		    $ifaces->{$iface} = { type => 'eth',
+					  exists => 1,
+					  method => 'manual',
+					  families => ['inet'] };
+		} else {
+		    delete $ifaces->{$iface};
+		}
 		next;
 	    }
 	    my $bd = $ifaces->{$brname};
-- 
2.1.4




More information about the pve-devel mailing list