]> git.proxmox.com Git - pve-common.git/commitdiff
don't reorder unknown interface types
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 7 Oct 2015 08:42:17 +0000 (10:42 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 7 Oct 2015 11:43:28 +0000 (13:43 +0200)
Giving unknown interfaces an order-id of 0 caused them to
always be on top of the interfaces file. This is often
undesired. Instead we now only take type-ordering into
account when both interfaces which are being compared have a
known type, and otherwise only use the priority attribute.
This should result in a more stable modification of
interfaces.

Fixes #747

src/PVE/INotify.pm
test/etc_network_interfaces/t.unknown_order.pl [new file with mode: 0644]

index a68c262a577cc2478ff5ec8bb05b7af16659f210..a9dbf21265417d56979df15e30729135079a6ada 100644 (file)
@@ -1289,7 +1289,6 @@ NETWORKDOC
     my $printed = {};
 
     my $if_type_hash = {
-       unknown => 0,
        loopback => 100000,
        eth => 200000,
        bond => 300000,
@@ -1316,17 +1315,21 @@ NETWORKDOC
            $pri = $if_type_hash->{bridge} + $child;
        }
 
-       return $pri || ($if_type_hash->{unknown} + $child);
+       return $pri;
     };
 
     foreach my $iface (sort {
        my $ref1 = $ifaces->{$a};
        my $ref2 = $ifaces->{$b};
-       my $p1 = &$lookup_type_prio($a);
-       my $p2 = &$lookup_type_prio($b);
+       my $tp1 = &$lookup_type_prio($a);
+       my $tp2 = &$lookup_type_prio($b);
 
-       $p1 += $ref1->{priority} // 50000;
-       $p2 += $ref2->{priority} // 50000;
+       # Only recognized types are in relation to each other. If one type
+       # is unknown then only consider the interfaces' priority attributes.
+       $tp1 = $tp2 = 0 if !defined($tp1) || !defined($tp2);
+
+       my $p1 = $tp1 + ($ref1->{priority} // 50000);
+       my $p2 = $tp2 + ($ref2->{priority} // 50000);
 
        return $p1 <=> $p2 if $p1 != $p2;
 
diff --git a/test/etc_network_interfaces/t.unknown_order.pl b/test/etc_network_interfaces/t.unknown_order.pl
new file mode 100644 (file)
index 0000000..5ed958f
--- /dev/null
@@ -0,0 +1,102 @@
+my $base = load('loopback');
+sub wanted($) {
+    my ($ip) = @_;
+    return $base . <<"IFACES";
+iface eth0 inet manual
+
+iface eth1 inet manual
+
+iface eth2 inet manual
+
+iface eth3 inet manual
+
+iface eth4 inet manual
+
+iface eth5 inet manual
+
+iface eth6 inet manual
+
+iface eth7 inet manual
+
+iface bond0 inet manual
+       slaves eth0 eth1
+       bond_miimon 100
+       bond_mode balance-alb
+
+auto bond1
+iface bond1 inet static
+       address  10.10.10.$ip
+       netmask  255.255.255.0
+       slaves eth2 eth3
+       bond_miimon 100
+       bond_mode balance-alb
+#       pre-up ifconfig bond1 mtu 9000
+
+auto bond2
+iface bond2 inet manual
+       slaves eth4 eth5
+       bond_miimon 100
+       bond_mode balance-alb
+# Private networking
+
+iface vlan3 inet static
+       address  0.0.0.0
+       netmask  0.0.0.0
+       vlan_raw_device bond2
+
+iface vlan4 inet static
+       address  0.0.0.0
+       netmask  0.0.0.0
+       vlan_raw_device bond2
+
+iface vlan5 inet static
+       address  0.0.0.0
+       netmask  0.0.0.0
+       vlan_raw_device bond2
+
+auto vmbr0
+iface vmbr0 inet static
+       address  192.168.100.13
+       netmask  255.255.255.0
+       gateway  192.168.100.1
+       bridge_ports bond0
+       bridge_stp off
+       bridge_fd 0
+
+auto vlan6
+iface vlan6 inet static
+       address  10.10.11.13
+       netmask  255.255.255.0
+       vlan_raw_device bond0
+       network 10.10.11.0
+       pre-up ifconfig bond0 up
+
+auto vmbr3
+iface vmbr3 inet manual
+       bridge_ports vlan3
+       bridge_stp off
+       bridge_fd 0
+       pre-up ifup vlan3
+
+auto vmbr4
+iface vmbr4 inet manual
+       bridge_ports vlan4
+       bridge_stp off
+       bridge_fd 0
+       pre-up ifup vlan4
+
+auto vmbr5
+iface vmbr5 inet manual
+       bridge_ports vlan5
+       bridge_stp off
+       bridge_fd 0
+       pre-up ifup vlan5
+
+IFACES
+}
+
+r(wanted(13));
+update_iface('bond1', [ { family => 'inet', address => '10.10.10.11' } ]);
+expect wanted(11);
+
+1;