]> git.proxmox.com Git - pve-common.git/commitdiff
improve lookup_type_prio
authorAlexandre Derumier <aderumier@odiso.com>
Mon, 1 Oct 2018 09:14:50 +0000 (11:14 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 4 Oct 2018 11:06:54 +0000 (13:06 +0200)
- use d->{type} instead regex on ifname
- add stacked vlan support

src/PVE/INotify.pm

index 1a6070873b950d660638bcbbdd176d1acca2b866..c42f885d65131e6f9a35500f9ff0c1d67e89c892 100644 (file)
@@ -1506,39 +1506,40 @@ NETWORKDOC
     my $if_type_hash = {
        loopback => 100000,
        eth => 200000,
     my $if_type_hash = {
        loopback => 100000,
        eth => 200000,
+       OVSPort => 200000,
+       OVSIntPort => 200000,
        bond => 300000,
        bridge => 400000,
        bond => 300000,
        bridge => 400000,
+       OVSBridge => 400000,
        vxlan => 500000,
    };
 
     my $lookup_type_prio = sub {
        vxlan => 500000,
    };
 
     my $lookup_type_prio = sub {
-       my $iface = shift;
-
+       my ($iface, $ifaces) = @_;
        my $child = 0;
        my $child = 0;
-       if ($iface =~ m/^(\S+)(\.|:)\d+$/) {
-           $iface = $1;
-           $child = 1;
-       }
+       my $n = undef;
 
 
-       my $pri;
-       if ($iface eq 'lo') {
-           $pri = $if_type_hash->{loopback};
-       } elsif ($iface =~ m/^$PVE::Network::PHYSICAL_NIC_RE$/) {
-           $pri = $if_type_hash->{eth} + $child;
-       } elsif ($iface =~ m/^bond\d+$/) {
-           $pri = $if_type_hash->{bond} + $child;
-       } elsif ($iface =~ m/^vmbr\d+$/) {
-           $pri = $if_type_hash->{bridge} + $child;
+       my $i=1;
+       for my $childiface (split(/(\.|:)/, $iface)) {
+           if ($i > 1) {
+               $child++;
+           } else {
+               $n = $ifaces->{$childiface};
+           }
+           $i++;
        }
 
        }
 
+       my $pri = $if_type_hash->{$n->{type}} + $child
+           if $n->{type} && $n->{type} ne 'unknown';
+
        return $pri;
     };
 
     foreach my $iface (sort {
        my $ref1 = $ifaces->{$a};
        my $ref2 = $ifaces->{$b};
        return $pri;
     };
 
     foreach my $iface (sort {
        my $ref1 = $ifaces->{$a};
        my $ref2 = $ifaces->{$b};
-       my $tp1 = &$lookup_type_prio($a);
-       my $tp2 = &$lookup_type_prio($b);
+       my $tp1 = &$lookup_type_prio($a, $ifaces);
+       my $tp2 = &$lookup_type_prio($b, $ifaces);
 
        # Only recognized types are in relation to each other. If one type
        # is unknown then only consider the interfaces' priority attributes.
 
        # Only recognized types are in relation to each other. If one type
        # is unknown then only consider the interfaces' priority attributes.