]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/INotify.pm
etc_network_interfaces : add uplink-id option
[pve-common.git] / src / PVE / INotify.pm
index 11b672850c19d5cbe3ab3a4c359612472aff4a07..fd543132a3b5bfdbc2b775a21a694fe8b7887858 100644 (file)
@@ -955,6 +955,7 @@ sub __read_etc_network_interfaces {
                        'bridge-multicast-flood' => 1,
                        'bond_miimon' => 1,
                        'bond_xmit_hash_policy' => 1,
+                       'uplink-id' => 1,
                        'vlan-protocol' => 1,
                        'vxlan-id' => 1,
                        'vxlan-svcnodeip' => 1,
@@ -1106,7 +1107,7 @@ sub __read_etc_network_interfaces {
 
        # map address and netmask to cidr
        if ($d->{address}) {
-           if ($d->{netmask} =~ m/^\d+$/) { # e.g. netmask 20
+           if ($d->{netmask} && $d->{netmask} =~ m/^\d+$/) { # e.g. netmask 20
                $d->{cidr} = $d->{address} . "/" . $d->{netmask};
            } elsif ($d->{netmask} &&
                     (my $cidr = PVE::JSONSchema::get_netmask_bits($d->{netmask}))) { # e.g. netmask 255.255.255.0
@@ -1124,9 +1125,8 @@ sub __read_etc_network_interfaces {
        if ($d->{address6}) {
            $d->{cidr6} = $d->{address6};
            if ($d->{netmask6}) {
-               $d->{cidr6} .= "/" . $d->{netmask6} if $d->{netmask6};
+               $d->{cidr6} .= "/" . $d->{netmask6};
            } elsif ($d->{address6} =~ m!^(.*)/(\d+)$!) {
-               $d->{cidr6} = $d->{address6};
                $d->{address6} = $1;
                $d->{netmask6} = $2;
            }
@@ -1184,7 +1184,7 @@ sub __interface_to_string {
                 comments => 1, autostart => 1, options => 1,
                 address => 1, netmask => 1, gateway => 1, broadcast => 1,
                 method6 => 1, families => 1, options6 => 1,
-                address6 => 1, netmask6 => 1, gateway6 => 1, broadcast6 => 1 };
+                address6 => 1, netmask6 => 1, gateway6 => 1, broadcast6 => 1, 'uplink-id' => 1 };
 
     if (!$first_block) {
        # not printing out options
@@ -1488,6 +1488,21 @@ sub __write_etc_network_interfaces {
        }
     }
 
+    # check uplink
+    my $uplinks = {};
+    foreach my $iface (keys %$ifaces) {
+       my $d = $ifaces->{$iface};
+       if (my $uplinkid = $d->{'uplink-id'}) {
+           die "iface '$iface' - uplink-id $uplinkid is only allowed on physical and linux bond interfaces\n"
+               if $d->{type} ne 'eth' && $d->{type} ne 'bond'; 
+
+           die "iface '$iface' - uplink-id $uplinkid is already assigned on '$uplinks->{$uplinkid}'\n"
+               if $uplinks->{$uplinkid};
+
+           $uplinks->{$uplinkid} = $iface;
+       }
+    }
+
     # check bridgeport option
     my $bridgeports = {};
     my $bridges = {};