[pve-devel] [PATCH pve-common] Inotify: keep address != cidr

Alexandre Derumier aderumier at odiso.com
Fri Mar 13 10:59:57 CET 2020


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 src/PVE/INotify.pm                            | 36 ++++++++++++-------
 .../t.list-interfaces.pl                      | 32 ++++++++++++-----
 2 files changed, 46 insertions(+), 22 deletions(-)

diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm
index d170cc1..b07cecd 100644
--- a/src/PVE/INotify.pm
+++ b/src/PVE/INotify.pm
@@ -1108,23 +1108,33 @@ sub __read_etc_network_interfaces {
 
 	# map address and netmask to cidr
 	if ($d->{address}) {
-	    if ($d->{netmask}) {
-		if ($d->{netmask} =~ m/^\d+$/) { # e.g. netmask 20
-		    $d->{address} = $d->{address} . "/" . $d->{netmask};
-		} elsif (my $mask = PVE::JSONSchema::get_netmask_bits($d->{netmask})) {
-		    $d->{address} = $d->{address} . "/" . $mask;
+
+	    if($d->{address} =~ m!^(.*)/(\d+)$! ) {
+		$d->{cidr} = $d->{address};
+		$d->{address} = $1;
+		$d->{netmask} = $2;
+	    } else {
+		if ($d->{netmask}) {
+		    if ($d->{netmask} =~ m/^\d+$/) { # e.g. netmask 20
+			$d->{cidr} = $d->{address} . "/" . $d->{netmask};
+		    } elsif (my $mask = PVE::JSONSchema::get_netmask_bits($d->{netmask})) {
+			$d->{cidr} = $d->{address} . "/" . $mask;
+		    }
 		}
 	    }
-	   # for api compatibility
-	   $d->{cidr} = $d->{address};
 	}
 
-	# map address6 and netmask6 to cidr6
-	if ($d->{address6}) {
-	    $d->{address6} .= "/" . $d->{netmask6} if $d->{address6} !~ m!^(.*)/(\d+)$! && $d->{netmask6};
-	    # for api compatibility
-	    $d->{cidr6} = $d->{address6};
-	}
+        # map address and netmask to cidr
+        if ($d->{address6}) {
+
+            if($d->{address6} =~ m!^(.*)/(\d+)$! ) {
+                $d->{cidr6} = $d->{address6};
+                $d->{address6} = $1;
+                $d->{netmask6} = $2;
+            } else {
+               $d->{cidr6} = $d->{address6} . "/" . $d->{netmask6} if $d->{netmask6};
+            }
+        }
 
 	$d->{method} = 'manual' if !$d->{method};
 	$d->{method6} = 'manual' if !$d->{method6};
diff --git a/test/etc_network_interfaces/t.list-interfaces.pl b/test/etc_network_interfaces/t.list-interfaces.pl
index 5925c35..6495a4a 100644
--- a/test/etc_network_interfaces/t.list-interfaces.pl
+++ b/test/etc_network_interfaces/t.list-interfaces.pl
@@ -16,10 +16,17 @@ eth100:
 /proc/net/dev
 
 my %wanted = (
-    vmbr0 => { address => '192.168.1.2/24',
+    vmbr0 => { address => '192.168.1.2',
+	       netmask => '24',
 	       gateway => '192.168.1.1',
-	       address6 => 'fc05::1:1/112'},
-    vmbr1 => { address => '10.0.0.5/24'}
+	       address6 => 'fc05::1:1',
+	       netmask6 => '112'},
+    vmbr1 => { address => '10.0.0.5',
+	       netmask => '255.255.255.0'},
+    eth2 => { address => '172.16.0.1',
+	       netmask => '24',
+	       address6 => 'fc05::1:1',
+               netmask6 => '64'}
 );
 
 save('interfaces', <<"/etc/network/interfaces");
@@ -30,6 +37,13 @@ source-directory interfaces.d
 
 iface eth0 inet manual
 
+auto eth2
+iface eth2 inet static
+	address  $wanted{eth2}->{address}/$wanted{eth2}->{netmask}
+
+iface eth2 inet6 static
+	address  $wanted{eth2}->{address6}/$wanted{eth2}->{netmask6}
+
 allow-vmbr1 eth100
 iface eth100 inet manual
 	ovs_type OVSPort
@@ -37,23 +51,23 @@ iface eth100 inet manual
 
 auto vmbr0
 iface vmbr0 inet static
-	address  192.168.1.2
-	netmask  24
+	address  $wanted{vmbr0}->{address}
+	netmask  $wanted{vmbr0}->{netmask}
 	gateway  $wanted{vmbr0}->{gateway}
 	bridge_ports eth0
 	bridge_stp off
 	bridge_fd 0
 
 iface vmbr0 inet6 static
-	address  fc05::1:1
-	netmask  112
+	address  $wanted{vmbr0}->{address6}
+	netmask  $wanted{vmbr0}->{netmask6}
 
 source-directory before-ovs.d
 
 allow-ovs vmbr1
 iface vmbr1 inet static
-	address  10.0.0.5
-	netmask  255.255.255.0
+	address  $wanted{vmbr1}->{address}
+	netmask  $wanted{vmbr1}->{netmask}
 	ovs_type OVSBridge
 	ovs_ports eth100
 
-- 
2.20.1




More information about the pve-devel mailing list