]> git.proxmox.com Git - pve-common.git/commitdiff
INotify: use cidr for address on config change
authorAlexandre Derumier <aderumier@odiso.com>
Thu, 20 Feb 2020 11:55:18 +0000 (12:55 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 4 Mar 2020 13:59:34 +0000 (14:59 +0100)
netmask/broadcast options are deprecated since buster
https://manpages.debian.org/buster/ifupdown/interfaces.5.en.html

This still read both "old address/netmask" or "address cidr" format,
but always convert it to cidr address format

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
src/PVE/INotify.pm
test/etc_network_interfaces/t.bridge-v4-v6.pl
test/etc_network_interfaces/t.create_network.pl
test/etc_network_interfaces/t.list-interfaces.pl
test/etc_network_interfaces/t.ovs_bridge_allow.pl
test/etc_network_interfaces/t.parsed_options.pl
test/etc_network_interfaces/t.unknown_order.pl
test/etc_network_interfaces/t.update_network.pl

index ba952e3b731e95a9087f8dc4387c914c309ca142..6c1ebf530fb1455ef2652935fd49ba966eddffc1 100644 (file)
@@ -1114,28 +1114,20 @@ sub __read_etc_network_interfaces {
        # map address and netmask to cidr
        if ($d->{address}) {
            if ($d->{netmask} && $d->{netmask} =~ m/^\d+$/) { # e.g. netmask 20
-               $d->{cidr} = $d->{address} . "/" . $d->{netmask};
+               $d->{address} = $d->{address} . "/" . $d->{netmask};
            } elsif ($d->{netmask} &&
                     (my $cidr = PVE::JSONSchema::get_netmask_bits($d->{netmask}))) { # e.g. netmask 255.255.255.0
-               $d->{cidr} = $d->{address} . "/" . $cidr;
-           } elsif ($d->{address} =~ m!^(.*)/(\d+)$!) {
-               $d->{cidr} = $d->{address};
-               $d->{address} = $1;
-               $d->{netmask} = $2;
-           } else {
-               $d->{cidr} = $d->{address};
+               $d->{address} = $d->{address} . "/" . $cidr;
            }
+           #for api compatibility
+           $d->{cidr} = $d->{address} 
        }
 
        # map address6 and netmask6 to cidr6
        if ($d->{address6}) {
-           $d->{cidr6} = $d->{address6};
-           if ($d->{netmask6}) {
-               $d->{cidr6} .= "/" . $d->{netmask6};
-           } elsif ($d->{address6} =~ m!^(.*)/(\d+)$!) {
-               $d->{address6} = $1;
-               $d->{netmask6} = $2;
-           }
+           $d->{address6} .= "/" . $d->{netmask6} if $d->{address6} !~ m!^(.*)/(\d+)$! && $d->{netmask6};
+            #for api compatibility
+           $d->{cidr6} = $d->{address6} 
        }
 
        $d->{method} = 'manual' if !$d->{method};
@@ -1184,9 +1176,7 @@ sub __interface_to_string {
 
     $raw .= "iface $iface $family " . $d->{"method$suffix"} . "\n";
     $raw .= "\taddress  " . $d->{"address$suffix"} . "\n" if $d->{"address$suffix"};
-    $raw .= "\tnetmask  " . $d->{"netmask$suffix"} . "\n" if $d->{"netmask$suffix"};
     $raw .= "\tgateway  " . $d->{"gateway$suffix"} . "\n" if $d->{"gateway$suffix"};
-    $raw .= "\tbroadcast  " . $d->{"broadcast$suffix"} . "\n" if $d->{"broadcast$suffix"};
 
     my $done = { type => 1, priority => 1, method => 1, active => 1, exists => 1,
                 comments => 1, autostart => 1, options => 1,
index 78181266759c033890ed71646d41e84282500639..8a8007443fcf7c3e6be541a081d085bb2530ec2b 100644 (file)
@@ -1,8 +1,6 @@
-my $ip = '10.0.0.2';
-my $nm = '255.255.255.0';
+my $ip = '10.0.0.2/24';
 my $gw = '10.0.0.1';
-my $ip6 = 'fc05::1:2';
-my $nm6 = '112';
+my $ip6 = 'fc05::1:2/112';
 my $gw6 = 'fc05::1:1';
 
 r(load('base'));
@@ -22,14 +20,12 @@ EOF
 update_iface('vmbr0',
     [ { family => 'inet',
        address => $ip,
-       netmask => $nm,
        gateway => $gw } ],
     autostart => 0);
 
 expect load('base') . <<"EOF";
 iface vmbr0 inet static
        address  $ip
-       netmask  $nm
        gateway  $gw
        bridge-ports eth0
        bridge-stp off
@@ -41,13 +37,11 @@ save('with-ipv4', w());
 update_iface('vmbr0',
     [ { family => 'inet6',
        address => $ip6,
-       netmask => $nm6,
        gateway => $gw6 } ]);
 
 expect load('with-ipv4') . <<"EOF";
 iface vmbr0 inet6 static
        address  $ip6
-       netmask  $nm6
        gateway  $gw6
 
 EOF
@@ -64,7 +58,6 @@ delete_iface('vmbr0', 'inet');
 expect load('base') . <<"EOF";
 iface vmbr0 inet6 static
        address  $ip6
-       netmask  $nm6
        gateway  $gw6
        bridge-ports eth0
        bridge-stp off
index 700eeef6bed1a4da3b27ecfd28bba766162723a6..dbbe3a333151d719cfbcce2f51c86451613d86e4 100644 (file)
@@ -11,8 +11,7 @@ r(load('brbase'));
 # Variables used for the various interfaces:
 #
 
-my $ip = '192.168.0.2';
-my $nm = '255.255.255.0';
+my $ip = '192.168.0.2/24';
 my $gw = '192.168.0.1';
 my $svcnodeip = '239.192.105.237';
 my $physdev = 'eth0';
@@ -26,8 +25,7 @@ my $remoteip2 = '192.168.0.4';
 my $vmbr0_part = <<"PART";
 auto vmbr0
 iface vmbr0 inet static
-       address  10.0.0.2
-       netmask  255.255.255.0
+       address  10.0.0.2/24
        gateway  10.0.0.1
        bridge-ports eth0
        bridge-stp off
@@ -44,7 +42,6 @@ $config->{ifaces}->{eth1} = {
     type => 'eth',
     method => 'static',
     address => $ip,
-    netmask => $nm,
     gateway => $gw,
     families => ['inet'],
     autostart => 1
@@ -54,7 +51,6 @@ my $eth1_part = <<"PART";
 auto eth1
 iface eth1 inet static
        address  $ip
-       netmask  $nm
        gateway  $gw
 PART
 chomp $eth1_part;
@@ -435,7 +431,6 @@ iface eth0 inet manual
 auto eth1
 iface eth1 inet6 static
        address  $ip
-       netmask  $nm
        gateway  $gw
 
 iface eth2 inet manual
@@ -444,8 +439,7 @@ iface eth3 inet manual
 
 auto vmbr0
 iface vmbr0 inet static
-       address  10.0.0.2
-       netmask  255.255.255.0
+       address  10.0.0.2/24
        gateway  10.0.0.1
        bridge-ports eth0
        bridge-stp off
index 7e37afaffdf19c23cac340a8e43f06061e63781c..5925c35878422b04fd821a6f6f436c5c080a34c8 100644 (file)
@@ -16,13 +16,10 @@ eth100:
 /proc/net/dev
 
 my %wanted = (
-    vmbr0 => { address => '192.168.1.2',
-              netmask => '255.255.255.0',
+    vmbr0 => { address => '192.168.1.2/24',
               gateway => '192.168.1.1',
-              address6 => 'fc05::1:1',
-              netmask6 => '112' },
-    vmbr1 => { address => '10.0.0.5',
-              netmask => '255.255.255.0' }
+              address6 => 'fc05::1:1/112'},
+    vmbr1 => { address => '10.0.0.5/24'}
 );
 
 save('interfaces', <<"/etc/network/interfaces");
@@ -40,23 +37,23 @@ iface eth100 inet manual
 
 auto vmbr0
 iface vmbr0 inet static
-       address  $wanted{vmbr0}->{address}
-       netmask  $wanted{vmbr0}->{netmask}
+       address  192.168.1.2
+       netmask  24
        gateway  $wanted{vmbr0}->{gateway}
        bridge_ports eth0
        bridge_stp off
        bridge_fd 0
 
 iface vmbr0 inet6 static
-       address  $wanted{vmbr0}->{address6}
-       netmask  $wanted{vmbr0}->{netmask6}
+       address  fc05::1:1
+       netmask  112
 
 source-directory before-ovs.d
 
 allow-ovs vmbr1
 iface vmbr1 inet static
-       address  $wanted{vmbr1}->{address}
-       netmask  $wanted{vmbr1}->{netmask}
+       address  10.0.0.5
+       netmask  255.255.255.0
        ovs_type OVSBridge
        ovs_ports eth100
 
index 45fad2e494f3078e4fa3e8d81f73be869bdf537a..159b7d4d07449992878801357ac85c2bb7db235d 100644 (file)
@@ -1,7 +1,6 @@
 use strict;
 
-my $ip = '192.168.0.100';
-my $nm = '255.255.255.0';
+my $ip = '192.168.0.100/24';
 my $gw = '192.168.0.1';
 
 # replace proc_net_dev with one with a bunch of interfaces
@@ -17,7 +16,6 @@ r('');
 new_iface('vmbr0', 'OVSBridge',
     [ { family => 'inet',
         address => $ip,
-        netmask => $nm,
         gateway => $gw } ],
     autostart => 1);
 
@@ -42,7 +40,6 @@ iface eth3 inet manual
 allow-ovs vmbr0
 iface vmbr0 inet static
        address  $ip
-       netmask  $nm
        gateway  $gw
        ovs_type OVSBridge
 
@@ -70,7 +67,6 @@ iface eth3 inet manual
 allow-ovs vmbr0
 iface vmbr0 inet static
        address  $ip
-       netmask  $nm
        gateway  $gw
        ovs_type OVSBridge
        ovs_ports eth1 eth2
@@ -105,7 +101,6 @@ iface eth2 inet manual
 allow-ovs vmbr0
 iface vmbr0 inet static
        address  $ip
-       netmask  $nm
        gateway  $gw
        ovs_type OVSBridge
        ovs_ports eth1
index 40b5b1185a90ce4562d07a3760e7872eb25f7051..7a3230277a61d1073eb8b2a00485ea973529cf22 100644 (file)
@@ -18,8 +18,7 @@ iface eth1 inet manual
 
 auto vmbr0
 iface vmbr0 inet static
-       address  10.0.0.2
-       netmask  255.255.255.0
+       address  10.0.0.2/24
        gateway  10.0.0.1
        bridge-ports eth0
        bridge-stp off
index 862e7b8d73079e424e9f573fc42a64c6ec0e66fd..780c5ec8867db6983a798918ee975a0b91f6dd00 100644 (file)
@@ -25,8 +25,7 @@ iface bond0 inet manual
 
 auto bond1
 iface bond1 inet static
-       address  10.10.10.$ip
-       netmask  255.255.255.0
+       address  10.10.10.$ip/24
        bond-slaves eth2 eth3
        bond-miimon 100
        bond-mode balance-alb
@@ -41,20 +40,16 @@ iface bond2 inet manual
 
 iface unknown3 inet static
        address  0.0.0.0
-       netmask  0.0.0.0
 
 iface unknown4 inet static
        address  0.0.0.0
-       netmask  0.0.0.0
 
 iface unknown5 inet static
        address  0.0.0.0
-       netmask  0.0.0.0
 
 auto vmbr0
 iface vmbr0 inet static
-       address  192.168.100.13
-       netmask  255.255.255.0
+       address  192.168.100.13/24
        gateway  192.168.100.1
        bridge-ports bond0
        bridge-stp off
@@ -62,9 +57,7 @@ iface vmbr0 inet static
 
 auto unknown6
 iface unknown6 inet static
-       address  10.10.11.13
-       netmask  255.255.255.0
-       network 10.10.11.0
+       address  10.10.11.13/24
        pre-up ifconfig bond0 up
 
 auto vmbr3
@@ -92,7 +85,7 @@ IFACES
 }
 
 r(wanted(13));
-update_iface('bond1', [ { family => 'inet', address => '10.10.10.11' } ]);
+update_iface('bond1', [ { family => 'inet', address => '10.10.10.11/24' } ]);
 expect wanted(11);
 
 1;
index 4bf70cf7a773ac1015d2b448a823daebc721d378..e205e4fcda782f1087a5ce195f07c51b49de819e 100644 (file)
@@ -3,11 +3,9 @@ eth0:
 eth1:
 /proc/net/dev
 
-my $ip = '192.168.0.2';
-my $nm = '255.255.255.0';
+my $ip = '192.168.0.2/24';
 my $gw = '192.168.0.1';
-my $ip6 = 'fc05::2';
-my $nm6 = '112';
+my $ip6 = 'fc05::2/112';
 my $gw6 = 'fc05::1';
 
 # Load
@@ -18,7 +16,6 @@ $config->{ifaces}->{eth1} = {
     type => 'eth',
     method => 'static',
     address => $ip,
-    netmask => $nm,
     gateway => $gw,
     families => ['inet'],
     autostart => 1
@@ -33,13 +30,11 @@ iface eth0 inet manual
 auto eth1
 iface eth1 inet static
        address  $ip
-       netmask  $nm
        gateway  $gw
 
 auto vmbr0
 iface vmbr0 inet static
-       address  10.0.0.2
-       netmask  255.255.255.0
+       address  10.0.0.2/24
        gateway  10.0.0.1
        bridge-ports eth0
        bridge-stp off
@@ -69,18 +64,15 @@ iface eth0 inet manual
 auto eth1
 iface eth1 inet static
        address  $ip
-       netmask  $nm
        gateway  $gw
 
 iface eth1 inet6 static
        address  $ip6
-       netmask  $nm6
        gateway  $gw6
 
 auto vmbr0
 iface vmbr0 inet static
-       address  10.0.0.2
-       netmask  255.255.255.0
+       address  10.0.0.2/24
        gateway  10.0.0.1
        bridge-ports eth0
        bridge-stp off