]> git.proxmox.com Git - pve-common.git/commitdiff
/etc/network/interfaces: deal with OVS allow- lines
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 25 Jun 2015 09:54:30 +0000 (11:54 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 26 Jun 2015 05:48:06 +0000 (07:48 +0200)
* __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

index 7fc6978cfdb4beeaa555d9aa89579c53e31dc73f..5fce0c8656f7405f48826ef894f56b63d9c72247 100644 (file)
@@ -996,6 +996,30 @@ sub __read_etc_network_interfaces {
        close ($proc_net_if_inet6);
     }
 
        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;
 }
 
     return $config;
 }
 
@@ -1166,7 +1190,14 @@ sub __write_etc_network_interfaces {
            $d->{type} eq 'OVSBond') {
            my $brname = $used_ports->{$iface};
            if (!$brname || !$ifaces->{$brname}) { 
            $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};
                next;
            }
            my $bd = $ifaces->{$brname};