[pve-devel] [PATCH V2 pve-common 2/2] improve lookup_type_prio

Alexandre Derumier aderumier at odiso.com
Mon Oct 1 11:14:50 CEST 2018


- use d->{type} instead regex on ifname
- add stacked vlan support
---
 src/PVE/INotify.pm | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm
index 1a60708..c42f885 100644
--- a/src/PVE/INotify.pm
+++ b/src/PVE/INotify.pm
@@ -1506,39 +1506,40 @@ NETWORKDOC
     my $if_type_hash = {
 	loopback => 100000,
 	eth => 200000,
+	OVSPort => 200000,
+	OVSIntPort => 200000,
 	bond => 300000,
 	bridge => 400000,
+	OVSBridge => 400000,
 	vxlan => 500000,
    };
 
     my $lookup_type_prio = sub {
-	my $iface = shift;
-
+	my ($iface, $ifaces) = @_;
 	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};
-	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.
-- 
2.11.0




More information about the pve-devel mailing list