]> git.proxmox.com Git - pve-common.git/commitdiff
inotify: fix compatibillity with address + netmask separate passed
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 12 Mar 2020 14:21:55 +0000 (15:21 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 12 Mar 2020 15:10:18 +0000 (16:10 +0100)
fixes commit 78c6656c9aba1d57786f916717c2622a3059fb6 which dropped
writing out the netmask but missed to add compat code for the case
where the caller did not suplly a address in CIDR format already.

Check if an address ends with /\d+, if not see if a netmask is
available and add that similar how it gets handled on read.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Reviewed-By: Stoiko Ivanov <s.ivanov@proxmox.com>
Tested-By: Stoiko Ivanov <s.ivanov@proxmox.com>
src/PVE/INotify.pm
test/etc_network_interfaces/t.create_network.pl

index 86d5459852234ebe3a61728cdbb19f8d8db769ee..d170cc14163c737ee0c7d90bb64e662272dbbbb8 100644 (file)
@@ -1171,7 +1171,20 @@ sub __interface_to_string {
     my $raw = '';
 
     $raw .= "iface $iface $family " . $d->{"method$suffix"} . "\n";
     my $raw = '';
 
     $raw .= "iface $iface $family " . $d->{"method$suffix"} . "\n";
-    $raw .= "\taddress " . $d->{"address$suffix"} . "\n" if $d->{"address$suffix"};
+
+    if (my $addr = $d->{"address$suffix"}) {
+
+       if ($addr !~ /\/\d+$/ && $d->{"netmask$suffix"}) {
+           if ($d->{"netmask$suffix"} =~ m/^\d+$/) {
+               $addr .= "/" . $d->{"netmask$suffix"};
+           } elsif (my $mask = PVE::JSONSchema::get_netmask_bits($d->{"netmask$suffix"})) {
+               $addr .= "/" . $mask;
+           }
+       }
+
+       $raw .= "\taddress " . $addr . "\n";
+    }
+
     $raw .= "\tgateway " . $d->{"gateway$suffix"} . "\n" if $d->{"gateway$suffix"};
 
     my $done = { type => 1, priority => 1, method => 1, active => 1, exists => 1,
     $raw .= "\tgateway " . $d->{"gateway$suffix"} . "\n" if $d->{"gateway$suffix"};
 
     my $done = { type => 1, priority => 1, method => 1, active => 1, exists => 1,
index 9bb26bd2fc04f904758c572678d4c17cda77c1b9..22e71420b8bd15b55bd4afee5d6828b753342f51 100644 (file)
@@ -503,7 +503,7 @@ iface eth0 inet manual
 
 auto eth1
 iface eth1 inet6 static
 
 auto eth1
 iface eth1 inet6 static
-       address $ip
+       address $ip/$nm
        gateway $gw
 
 iface eth2 inet manual
        gateway $gw
 
 iface eth2 inet manual