]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/INotify.pm
INotify: fix mtu check && add test
[pve-common.git] / src / PVE / INotify.pm
index a0712f7e36b1f32a93a3538eae184b895d2d8eb9..6e7a78c4323c06ba1b6803ee508024e5731ae7f1 100644 (file)
@@ -960,6 +960,8 @@ sub __read_etc_network_interfaces {
                        '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,
@@ -1076,12 +1078,14 @@ sub __read_etc_network_interfaces {
                $ifaces->{$1}->{exists} = 0;
                $d->{exists} = 0;
            }
-       } elsif ($iface =~ m/^(\S+)\.\d+$/) {
+       } elsif ($iface =~ m/^(\S+)\.\d+$/ || $d->{'vlan-raw-device'}) {
            $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 {
-               $ifaces->{$1}->{exists} = 0;
+               $ifaces->{$raw_iface}->{exists} = 0;
                $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};
-       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};
 
+           die "vlan '$iface' - vlan-id $vlanid should be <= 4094\n" if $vlanid > 4094;
            die "vlan '$iface' - unable to find parent '$p'\n"
                if !$n;
 
@@ -1535,13 +1560,12 @@ sub __write_etc_network_interfaces {
            foreach my $p (split (/\s+/, $d->{bridge_ports})) {
                $p =~ s/\.\d+$//;
                my $n = $ifaces->{$p};
-               die "bridge '$iface' - unable to find bridge port '$p'\n"
-                   if !$n;
+               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 "\:\:");
+                      ($n->{method6} eq 'static' && $n->{address} ne '::');
 
-               &$check_mtu($ifaces, $iface, $p);
+               &$check_mtu($ifaces, $p, $iface);
                $bridgeports->{$p} = $iface;
            }
            $bridges->{$iface} = $d;
@@ -1585,6 +1609,7 @@ NETWORKDOC
        bond => 300000,
        bridge => 400000,
        OVSBridge => 400000,
+       vlan => 500000,
        vxlan => 500000,
    };