\&write_active_workers);
-our $bond_modes = { 'balance-rr' => 0,
- 'active-backup' => 1,
- 'balance-xor' => 2,
- 'broadcast' => 3,
- '802.3ad' => 4,
- 'balance-tlb' => 5,
- 'balance-alb' => 6,
- };
+our $bond_modes = {
+ 'balance-rr' => 0,
+ 'active-backup' => 1,
+ 'balance-xor' => 2,
+ 'broadcast' => 3,
+ '802.3ad' => 4,
+ 'balance-tlb' => 5,
+ 'balance-alb' => 6,
+};
my $ovs_bond_modes = {
'active-backup' => 1,
'bond_miimon' => 1,
'bond_xmit_hash_policy' => 1,
'bond-primary' => 1,
+ 'link-type' => 1,
'uplink-id' => 1,
'vlan-protocol' => 1,
'vlan-raw-device' => 1,
} elsif ($iface =~ m/^vmbr\d+$/) {
if (!$d->{ovs_type}) {
$d->{type} = 'bridge';
-
- if (!defined ($d->{bridge_fd})) {
- $d->{bridge_fd} = 0;
- }
if (!defined ($d->{bridge_stp})) {
$d->{bridge_stp} = 'off';
}
+ if (!defined($d->{bridge_fd}) && $d->{bridge_stp} eq 'off') {
+ $d->{bridge_fd} = 0;
+ }
} elsif ($d->{ovs_type} eq 'OVSBridge') {
$d->{type} = $d->{ovs_type};
}
$ifaces->{$1}->{exists} = 0;
$d->{exists} = 0;
}
- } elsif ($iface =~ m/^(\S+)\.\d+$/ || $d->{'vlan-raw-device'}) {
+ } elsif ($iface =~ m/^(\S+)\.(\d+)$/ || $d->{'vlan-raw-device'}) {
$d->{type} = 'vlan';
- my $raw_iface = $d->{'vlan-raw-device'} ? $d->{'vlan-raw-device'} : $1;
+ my ($dev, $id) = ($1, $2);
+ $d->{'vlan-raw-device'} = $dev if defined($dev) && !$d->{'vlan-raw-device'};
+
+ if (!$id && $iface =~ m/^vlan(\d+)$/) { # VLAN id 0 is not valid, so truthy check it is
+ $id = $1;
+ }
+ $d->{'vlan-id'} = $id if $id;
+
+ my $raw_iface = $d->{'vlan-raw-device'};
+
if (defined ($ifaces->{$raw_iface})) {
$d->{exists} = $ifaces->{$raw_iface}->{exists};
} else {
my $tag = &$extract_ovs_option($d, 'tag');
$d->{ovs_tag} = $tag if defined($tag);
}
+ } elsif (defined($d->{'link-type'})) {
+ $d->{type} = $d->{'link-type'} if $d->{'link-type'} eq 'dummy';
}
}
$d->{method} = 'manual' if !$d->{method};
$d->{method6} = 'manual' if !$d->{method6};
+ if (my $comments6 = delete $d->{comments6}) {
+ $d->{comments} = ($d->{comments} // '') . $comments6;
+ }
+
$d->{families} ||= ['inet'];
}
my $done = { type => 1, priority => 1, method => 1, active => 1, exists => 1,
comments => 1, autostart => 1, options => 1,
address => 1, netmask => 1, gateway => 1, broadcast => 1,
- method6 => 1, families => 1, options6 => 1,
+ method6 => 1, families => 1, options6 => 1, comments6 => 1,
address6 => 1, netmask6 => 1, gateway6 => 1, broadcast6 => 1, 'uplink-id' => 1 };
if (!$first_block) {
$done->{bridge_ports} = 1;
my $v = defined($d->{bridge_stp}) ? $d->{bridge_stp} : 'off';
+ my $no_stp = $v eq 'off';
+
$raw .= "\tbridge-stp $v\n";
$done->{bridge_stp} = 1;
$v = defined($d->{bridge_fd}) ? $d->{bridge_fd} : 0;
- $raw .= "\tbridge-fd $v\n";
+ # 0 is only allowed when STP is disabled
+ if ($v || $no_stp) {
+ $raw .= "\tbridge-fd $v\n";
+ }
$done->{bridge_fd} = 1;
if( defined($d->{bridge_vlan_aware})) {
# check bond
foreach my $iface (keys %$ifaces) {
my $d = $ifaces->{$iface};
- if ($d->{type} eq 'bond' && $d->{slaves}) {
- my $bond_primary_is_slave = undef;
- foreach my $p (split (/\s+/, $d->{slaves})) {
- my $n = $ifaces->{$p};
- $n->{autostart} = 1;
+ next if !($d->{type} eq 'bond' && $d->{slaves});
- die "bond '$iface' - unable to find slave '$p'\n"
- if !$n;
- die "bond '$iface' - wrong interface type on slave '$p' " .
- "('$n->{type}' != 'eth')\n" if $n->{type} ne 'eth';
- &$check_mtu($ifaces, $iface, $p);
- $bond_primary_is_slave = 1 if $d->{'bond-primary'} && $d->{'bond-primary'} eq $p;
- }
- die "bond '$iface' - bond-primary interface is not a slave" if $d->{'bond-primary'} && !$bond_primary_is_slave;
+ my $bond_primary_is_slave = undef;
+ foreach my $p (split (/\s+/, $d->{slaves})) {
+ my $n = $ifaces->{$p};
+ $n->{autostart} = 1;
+
+ die "bond '$iface' - unable to find slave '$p'\n" if !$n;
+ die "bond '$iface' - wrong interface type on slave '$p' ('$n->{type}' != 'eth or bond')\n"
+ if ($n->{type} ne 'eth' && $n->{type} ne 'bond');
+
+ $check_mtu->($ifaces, $iface, $p);
+ $bond_primary_is_slave = 1 if $d->{'bond-primary'} && $d->{'bond-primary'} eq $p;
}
+ die "bond '$iface' - bond-primary interface is not a slave" if $d->{'bond-primary'} && !$bond_primary_is_slave;
}
# check vxlan
$p = $1;
$vlanid = $2;
delete $d->{'vlan-raw-device'} if $d->{'vlan-raw-device'};
+ delete $d->{'vlan-id'} if $d->{'vlan-id'};
+
} else {
die "missing vlan-raw-device option" if !$d->{'vlan-raw-device'};
$p = $d->{'vlan-raw-device'};
die "bridge '$iface' - unable to find bridge port '$p'\n" if !$n;
die "iface $p - ip address can't be set on interface if bridged in $iface\n"
if ($n->{method} && $n->{method} eq 'static' && $n->{address} ne '0.0.0.0') ||
- ($n->{method6} && $n->{method6} eq 'static' && $n->{address} ne '::');
+ ($n->{method6} && $n->{method6} eq 'static' && $n->{address6} ne '::');
&$check_mtu($ifaces_copy, $p, $iface);
$bridgeports->{$p} = $iface;
}
my $if_type_hash = {
loopback => 100000,
+ dummy => 100000,
eth => 200000,
OVSPort => 200000,
OVSIntPort => 300000,
my ($rootiface, @rest) = split(/[.:]/, $iface);
my $childlevel = scalar(@rest);
- my $n = $ifaces->{$rootiface};
-
- my $pri = $if_type_hash->{$n->{type}} + $childlevel
- if $n->{type} && $n->{type} ne 'unknown';
+ my $type = $ifaces->{$rootiface}->{type};
+ return if !$type || $type eq 'unknown';
- return $pri;
+ return $if_type_hash->{$type} + $childlevel
};
foreach my $iface (sort {
}
}
+ # if 'inet6' is the only family
+ if (scalar($d->{families}->@*) == 1 && $d->{families}[0] eq 'inet6') {
+ $d->{comments6} = delete $d->{comments};
+ }
+
my $i = 0; # some options should be printed only once
$raw .= __interface_to_string($iface, $d, $_, !$i++, $ifupdown2) foreach @{$d->{families}};
}
my $raw = '';
- foreach my $machine (sort keys %$data) {
+ # sort longer entries first, so machine definitions with higher granularity are preferred
+ for my $machine (sort { length($b) <=> length($a) || $a cmp $b} keys %$data) {
my $d = $data->{$machine};
+ next if !defined($d); # allow "deleting" set entries
+
$raw .= "machine $machine\n";
$raw .= " login $d->{login}\n" if $d->{login};
$raw .= " password $d->{password}\n" if $d->{password};
sub write_apt_auth {
my ($filename, $fh, $data) = @_;
- my $raw = &$format_apt_auth_data($data);
+ my $raw = $format_apt_auth_data->($data);
die "write failed: $!" unless print $fh "$raw\n";
$orig->{$machine} = $data->{$machine};
}
- return &$format_apt_auth_data($orig);
+ return $format_apt_auth_data->($orig);
}
-register_file('apt-auth', "/etc/apt/auth.conf",
- \&read_apt_auth, \&write_apt_auth,
- \&update_apt_auth, perm => 0640);
+register_file(
+ 'apt-auth',
+ "/etc/apt/auth.conf",
+ \&read_apt_auth,
+ \&write_apt_auth,
+ \&update_apt_auth,
+ perm => 0640,
+);
1;