From: Wolfgang Bumiller Date: Thu, 25 Jun 2015 09:54:30 +0000 (+0200) Subject: /etc/network/interfaces: deal with OVS allow- lines X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=commitdiff_plain;h=516a50a4ac3b31fb1cfda672d25f99ec50f369e2;hp=cb07ff78cab6f6994cc5b6978e52ed65af8869ec /etc/network/interfaces: deal with OVS allow- lines * __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(). --- diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm index 7fc6978..5fce0c8 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; } @@ -1166,7 +1190,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};