From: Thomas Lamprecht Date: Thu, 12 Mar 2020 14:21:55 +0000 (+0100) Subject: inotify: fix compatibillity with address + netmask separate passed X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=commitdiff_plain;h=f6c9d9a4f375cd54e683b7d4658c5df61db38b1f inotify: fix compatibillity with address + netmask separate passed 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 Reviewed-By: Stoiko Ivanov Tested-By: Stoiko Ivanov --- diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm index 86d5459..d170cc1 100644 --- a/src/PVE/INotify.pm +++ b/src/PVE/INotify.pm @@ -1171,7 +1171,20 @@ sub __interface_to_string { 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, diff --git a/test/etc_network_interfaces/t.create_network.pl b/test/etc_network_interfaces/t.create_network.pl index 9bb26bd..22e7142 100644 --- a/test/etc_network_interfaces/t.create_network.pl +++ b/test/etc_network_interfaces/t.create_network.pl @@ -503,7 +503,7 @@ iface eth0 inet manual auto eth1 iface eth1 inet6 static - address $ip + address $ip/$nm gateway $gw iface eth2 inet manual