]> git.proxmox.com Git - pve-common.git/commitdiff
INotify: improve vlan interface parsing
authorAlexandre Derumier <aderumier@odiso.com>
Sat, 25 Jan 2020 09:27:03 +0000 (10:27 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Sat, 25 Jan 2020 15:01:34 +0000 (16:01 +0100)
Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
src/PVE/INotify.pm

index 2aa70707cbdaaa0ff5a2d7f90856623024146399..9bfd6fbe5429e299d7587724ccebcc460e225782 100644 (file)
@@ -960,6 +960,8 @@ sub __read_etc_network_interfaces {
                        'bond-primary' => 1,
                        'uplink-id' => 1,
                        'vlan-protocol' => 1,
                        'bond-primary' => 1,
                        'uplink-id' => 1,
                        'vlan-protocol' => 1,
+                       'vlan-raw-device' => 1,
+                       'vlan-id' => 1,
                        'vxlan-id' => 1,
                        'vxlan-svcnodeip' => 1,
                        'vxlan-physdev' => 1,
                        'vxlan-id' => 1,
                        'vxlan-svcnodeip' => 1,
                        'vxlan-physdev' => 1,
@@ -1076,12 +1078,14 @@ sub __read_etc_network_interfaces {
                $ifaces->{$1}->{exists} = 0;
                $d->{exists} = 0;
            }
                $ifaces->{$1}->{exists} = 0;
                $d->{exists} = 0;
            }
-       } elsif ($iface =~ m/^(\S+)\.\d+$/) {
+       } elsif ($iface =~ m/^(\S+)\.\d+$/ || $d->{'vlan-raw-device'}) {
            $d->{type} = 'vlan';
            $d->{type} = 'vlan';
-           if (defined ($ifaces->{$1})) {
-               $d->{exists} = $ifaces->{$1}->{exists};
+
+           my $raw_iface = $d->{'vlan-raw-device'} ? $d->{'vlan-raw-device'} : $1;
+           if (defined ($ifaces->{$raw_iface})) {
+               $d->{exists} = $ifaces->{$raw_iface}->{exists};
            } else {
            } else {
-               $ifaces->{$1}->{exists} = 0;
+               $ifaces->{$raw_iface}->{exists} = 0;
                $d->{exists} = 0;
            }
        } elsif ($iface =~ m/^$PVE::Network::PHYSICAL_NIC_RE$/) {
                $d->{exists} = 0;
            }
        } elsif ($iface =~ m/^$PVE::Network::PHYSICAL_NIC_RE$/) {
@@ -1494,10 +1498,31 @@ sub __write_etc_network_interfaces {
     # check vlan
     foreach my $iface (keys %$ifaces) {
        my $d = $ifaces->{$iface};
     # check vlan
     foreach my $iface (keys %$ifaces) {
        my $d = $ifaces->{$iface};
-       if ($d->{type} eq 'vlan' && $iface =~ m/^(\S+)\.\d+$/) {
-           my $p = $1;
+       if ($d->{type} eq 'vlan') {
+
+           my $p = undef;
+           my $vlanid = undef;
+
+           if ($iface =~ m/^(\S+)\.(\d+)$/) {
+               $p = $1;
+               $vlanid = $2;
+               delete $d->{'vlan-raw-device'} if $d->{'vlan-raw-device'};
+           } else {
+               die "missing vlan-raw-device option" if !$d->{'vlan-raw-device'};
+               $p = $d->{'vlan-raw-device'};
+
+               if ($iface =~ m/^vlan(\d+)$/) {
+                   $vlanid = $1;
+                   delete $d->{'vlan-id'} if $d->{'vlan-id'};
+               } else {
+                   die "custom vlan interface name need ifupdown2" if !$ifupdown2;
+                   die "missing vlan-id option" if !$d->{'vlan-id'};
+                   $vlanid = $d->{'vlan-id'};
+               }
+           }
            my $n = $ifaces->{$p};
 
            my $n = $ifaces->{$p};
 
+           die "vlan '$iface' - vlan-id $vlanid should be <= 4094\n" if $vlanid > 4094;
            die "vlan '$iface' - unable to find parent '$p'\n"
                if !$n;
 
            die "vlan '$iface' - unable to find parent '$p'\n"
                if !$n;
 
@@ -1584,6 +1609,7 @@ NETWORKDOC
        bond => 300000,
        bridge => 400000,
        OVSBridge => 400000,
        bond => 300000,
        bridge => 400000,
        OVSBridge => 400000,
+       vlan => 500000,
        vxlan => 500000,
    };
 
        vxlan => 500000,
    };