[pve-devel] [PATCH common] inotify: fix compatibillity with address + netmask separate passed
Thomas Lamprecht
t.lamprecht at proxmox.com
Thu Mar 12 15:24:41 CET 2020
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 at proxmox.com>
---
src/PVE/INotify.pm | 15 ++++++++++++++-
test/etc_network_interfaces/t.create_network.pl | 2 +-
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm
index 86d5459..044cda9 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+$/) { # e.g. netmask 20
+ $addr = $addr . "/" . $d->{"netmask$suffix"};
+ } elsif (my $mask = PVE::JSONSchema::get_netmask_bits("netmask$suffix")) {
+ $addr = $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
--
2.20.1
More information about the pve-devel
mailing list