]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/INotify.pm
INotify: add bond-primary option
[pve-common.git] / src / PVE / INotify.pm
index 65b2d9113f993898b0bd66941472ac7c501a898f..e3e43c1ade054228631b19863a140db841e0a75c 100644 (file)
@@ -312,7 +312,7 @@ sub parse_ccache_options {
            # noclone flag for large read-only data chunks like aplinfo
            $ccinfo->{$opt} = $v;
        } elsif ($opt eq 'always_call_parser') {
-           # when set, we call parser even when the file does not exists.
+           # when set, we call parser even when the file does not exist.
            # this allows the parser to return some default
            $ccinfo->{$opt} = $v;
        } else {
@@ -901,9 +901,10 @@ sub __read_etc_network_interfaces {
     SECTION: while (defined ($line = <$fh>)) {
        chomp ($line);
        next if $line =~ m/^\s*#/;
+       next if $line =~ m/^\s*(allow-hotplug)\s+(.*)$/;
 
-       if ($line =~ m/^\s*auto\s+(.*)$/) {
-           my @aa = split (/\s+/, $1);
+       if ($line =~ m/^\s*(auto|allow-ovs)\s+(.*)$/) {
+           my @aa = split (/\s+/, $2);
 
            foreach my $a (@aa) {
                $ifaces->{$a}->{autostart} = 1;
@@ -955,6 +956,7 @@ sub __read_etc_network_interfaces {
                        'bridge-multicast-flood' => 1,
                        'bond_miimon' => 1,
                        'bond_xmit_hash_policy' => 1,
+                       'bond-primary' => 1,
                        'uplink-id' => 1,
                        'vlan-protocol' => 1,
                        'vxlan-id' => 1,
@@ -1233,6 +1235,12 @@ sub __interface_to_string {
            $raw .= "\tbond-xmit-hash-policy $d->{'bond_xmit_hash_policy'}\n";
        }
        $done->{'bond_xmit_hash_policy'} = 1;
+
+       if ($d->{'bond_mode'} && $d->{'bond_mode'} eq 'active-backup' && $d->{'bond-primary'}) {
+           $raw .= "\tbond-primary $d->{'bond-primary'}\n";
+       }
+       $done->{'bond-primary'} = 1;
+
     } elsif ($d->{type} eq 'vlan') {
        die "$iface: wrong vlan-protocol $d->{'vlan-protocol'}\n"
            if $d->{'vlan-protocol'} && $d->{'vlan-protocol'} ne '802.1ad' && $d->{'vlan-protocol'} ne '802.1q';
@@ -1426,15 +1434,18 @@ sub __write_etc_network_interfaces {
     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};
-
+               
                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;
        }
     }
 
@@ -1473,9 +1484,7 @@ sub __write_etc_network_interfaces {
            die "vlan '$iface' - unable to find parent '$p'\n"
                if !$n;
 
-           if ($n->{type} eq 'bridge' && !$n->{bridge_vlan_aware}) {
-               die "vlan '$iface' - bridge vlan aware is not enabled on parent '$p'\n";
-           } elsif ($n->{type} ne 'eth' && $n->{type} ne 'bridge' && $n->{type} ne 'bond' && $n->{type} ne 'vlan') {
+           if ($n->{type} ne 'eth' && $n->{type} ne 'bridge' && $n->{type} ne 'bond' && $n->{type} ne 'vlan') {
                die "vlan '$iface' - wrong interface type on parent '$p' " .
                    "('$n->{type}' != 'eth|bond|bridge|vlan' )\n";
            }
@@ -1511,6 +1520,10 @@ sub __write_etc_network_interfaces {
                my $n = $ifaces->{$p};
                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} eq 'static' && $n->{address} ne '0.0.0.0') || 
+                       ($n->{method6} eq 'static' && $n->{address} ne "\:\:");
+
                &$check_mtu($ifaces, $iface, $p);
                $bridgeports->{$p} = $iface;
            }
@@ -1599,11 +1612,13 @@ NETWORKDOC
        }
 
        $printed->{$iface} = 1;
-       if ($d->{type} eq 'OVSBridge') {
-           # cannot use 'auto' for OVS, would add race with systemd ifup@.service
-           $raw .= "allow-ovs $iface\n";
-       } elsif ($d->{autostart}) {
-           $raw .= "auto $iface\n";
+       if ($d->{autostart}) {
+           if ($d->{type} eq 'OVSBridge') {
+               # cannot use 'auto' for OVS, would add race with systemd ifup@.service
+               $raw .= "allow-ovs $iface\n";
+           } else {
+               $raw .= "auto $iface\n";
+           }
        }
 
        my $i = 0; # some options should be printed only once