/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().
This commit is contained in:
Wolfgang Bumiller 2015-06-25 11:54:30 +02:00 committed by Dietmar Maurer
parent cb07ff78ca
commit 516a50a4ac

View File

@ -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}) {
if ($iface =~ /^eth/) {
$ifaces->{$iface} = { type => 'eth',
exists => 1,
method => 'manual',
families => ['inet'] };
} else {
delete $ifaces->{$iface};
}
next;
}
my $bd = $ifaces->{$brname};