mirror of
https://git.proxmox.com/git/pve-common
synced 2025-08-06 01:41:43 +00:00
INotify: use cidr for address on config change
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>
This commit is contained in:
parent
5bd1e56b7a
commit
378c6656c9
@ -1114,28 +1114,20 @@ sub __read_etc_network_interfaces {
|
|||||||
# map address and netmask to cidr
|
# map address and netmask to cidr
|
||||||
if ($d->{address}) {
|
if ($d->{address}) {
|
||||||
if ($d->{netmask} && $d->{netmask} =~ m/^\d+$/) { # e.g. netmask 20
|
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} &&
|
} elsif ($d->{netmask} &&
|
||||||
(my $cidr = PVE::JSONSchema::get_netmask_bits($d->{netmask}))) { # e.g. netmask 255.255.255.0
|
(my $cidr = PVE::JSONSchema::get_netmask_bits($d->{netmask}))) { # e.g. netmask 255.255.255.0
|
||||||
$d->{cidr} = $d->{address} . "/" . $cidr;
|
$d->{address} = $d->{address} . "/" . $cidr;
|
||||||
} elsif ($d->{address} =~ m!^(.*)/(\d+)$!) {
|
|
||||||
$d->{cidr} = $d->{address};
|
|
||||||
$d->{address} = $1;
|
|
||||||
$d->{netmask} = $2;
|
|
||||||
} else {
|
|
||||||
$d->{cidr} = $d->{address};
|
|
||||||
}
|
}
|
||||||
|
#for api compatibility
|
||||||
|
$d->{cidr} = $d->{address}
|
||||||
}
|
}
|
||||||
|
|
||||||
# map address6 and netmask6 to cidr6
|
# map address6 and netmask6 to cidr6
|
||||||
if ($d->{address6}) {
|
if ($d->{address6}) {
|
||||||
$d->{cidr6} = $d->{address6};
|
$d->{address6} .= "/" . $d->{netmask6} if $d->{address6} !~ m!^(.*)/(\d+)$! && $d->{netmask6};
|
||||||
if ($d->{netmask6}) {
|
#for api compatibility
|
||||||
$d->{cidr6} .= "/" . $d->{netmask6};
|
$d->{cidr6} = $d->{address6}
|
||||||
} elsif ($d->{address6} =~ m!^(.*)/(\d+)$!) {
|
|
||||||
$d->{address6} = $1;
|
|
||||||
$d->{netmask6} = $2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$d->{method} = 'manual' if !$d->{method};
|
$d->{method} = 'manual' if !$d->{method};
|
||||||
@ -1184,9 +1176,7 @@ sub __interface_to_string {
|
|||||||
|
|
||||||
$raw .= "iface $iface $family " . $d->{"method$suffix"} . "\n";
|
$raw .= "iface $iface $family " . $d->{"method$suffix"} . "\n";
|
||||||
$raw .= "\taddress " . $d->{"address$suffix"} . "\n" if $d->{"address$suffix"};
|
$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 .= "\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,
|
my $done = { type => 1, priority => 1, method => 1, active => 1, exists => 1,
|
||||||
comments => 1, autostart => 1, options => 1,
|
comments => 1, autostart => 1, options => 1,
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
my $ip = '10.0.0.2';
|
my $ip = '10.0.0.2/24';
|
||||||
my $nm = '255.255.255.0';
|
|
||||||
my $gw = '10.0.0.1';
|
my $gw = '10.0.0.1';
|
||||||
my $ip6 = 'fc05::1:2';
|
my $ip6 = 'fc05::1:2/112';
|
||||||
my $nm6 = '112';
|
|
||||||
my $gw6 = 'fc05::1:1';
|
my $gw6 = 'fc05::1:1';
|
||||||
|
|
||||||
r(load('base'));
|
r(load('base'));
|
||||||
@ -22,14 +20,12 @@ EOF
|
|||||||
update_iface('vmbr0',
|
update_iface('vmbr0',
|
||||||
[ { family => 'inet',
|
[ { family => 'inet',
|
||||||
address => $ip,
|
address => $ip,
|
||||||
netmask => $nm,
|
|
||||||
gateway => $gw } ],
|
gateway => $gw } ],
|
||||||
autostart => 0);
|
autostart => 0);
|
||||||
|
|
||||||
expect load('base') . <<"EOF";
|
expect load('base') . <<"EOF";
|
||||||
iface vmbr0 inet static
|
iface vmbr0 inet static
|
||||||
address $ip
|
address $ip
|
||||||
netmask $nm
|
|
||||||
gateway $gw
|
gateway $gw
|
||||||
bridge-ports eth0
|
bridge-ports eth0
|
||||||
bridge-stp off
|
bridge-stp off
|
||||||
@ -41,13 +37,11 @@ save('with-ipv4', w());
|
|||||||
update_iface('vmbr0',
|
update_iface('vmbr0',
|
||||||
[ { family => 'inet6',
|
[ { family => 'inet6',
|
||||||
address => $ip6,
|
address => $ip6,
|
||||||
netmask => $nm6,
|
|
||||||
gateway => $gw6 } ]);
|
gateway => $gw6 } ]);
|
||||||
|
|
||||||
expect load('with-ipv4') . <<"EOF";
|
expect load('with-ipv4') . <<"EOF";
|
||||||
iface vmbr0 inet6 static
|
iface vmbr0 inet6 static
|
||||||
address $ip6
|
address $ip6
|
||||||
netmask $nm6
|
|
||||||
gateway $gw6
|
gateway $gw6
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
@ -64,7 +58,6 @@ delete_iface('vmbr0', 'inet');
|
|||||||
expect load('base') . <<"EOF";
|
expect load('base') . <<"EOF";
|
||||||
iface vmbr0 inet6 static
|
iface vmbr0 inet6 static
|
||||||
address $ip6
|
address $ip6
|
||||||
netmask $nm6
|
|
||||||
gateway $gw6
|
gateway $gw6
|
||||||
bridge-ports eth0
|
bridge-ports eth0
|
||||||
bridge-stp off
|
bridge-stp off
|
||||||
|
@ -11,8 +11,7 @@ r(load('brbase'));
|
|||||||
# Variables used for the various interfaces:
|
# Variables used for the various interfaces:
|
||||||
#
|
#
|
||||||
|
|
||||||
my $ip = '192.168.0.2';
|
my $ip = '192.168.0.2/24';
|
||||||
my $nm = '255.255.255.0';
|
|
||||||
my $gw = '192.168.0.1';
|
my $gw = '192.168.0.1';
|
||||||
my $svcnodeip = '239.192.105.237';
|
my $svcnodeip = '239.192.105.237';
|
||||||
my $physdev = 'eth0';
|
my $physdev = 'eth0';
|
||||||
@ -26,8 +25,7 @@ my $remoteip2 = '192.168.0.4';
|
|||||||
my $vmbr0_part = <<"PART";
|
my $vmbr0_part = <<"PART";
|
||||||
auto vmbr0
|
auto vmbr0
|
||||||
iface vmbr0 inet static
|
iface vmbr0 inet static
|
||||||
address 10.0.0.2
|
address 10.0.0.2/24
|
||||||
netmask 255.255.255.0
|
|
||||||
gateway 10.0.0.1
|
gateway 10.0.0.1
|
||||||
bridge-ports eth0
|
bridge-ports eth0
|
||||||
bridge-stp off
|
bridge-stp off
|
||||||
@ -44,7 +42,6 @@ $config->{ifaces}->{eth1} = {
|
|||||||
type => 'eth',
|
type => 'eth',
|
||||||
method => 'static',
|
method => 'static',
|
||||||
address => $ip,
|
address => $ip,
|
||||||
netmask => $nm,
|
|
||||||
gateway => $gw,
|
gateway => $gw,
|
||||||
families => ['inet'],
|
families => ['inet'],
|
||||||
autostart => 1
|
autostart => 1
|
||||||
@ -54,7 +51,6 @@ my $eth1_part = <<"PART";
|
|||||||
auto eth1
|
auto eth1
|
||||||
iface eth1 inet static
|
iface eth1 inet static
|
||||||
address $ip
|
address $ip
|
||||||
netmask $nm
|
|
||||||
gateway $gw
|
gateway $gw
|
||||||
PART
|
PART
|
||||||
chomp $eth1_part;
|
chomp $eth1_part;
|
||||||
@ -435,7 +431,6 @@ iface eth0 inet manual
|
|||||||
auto eth1
|
auto eth1
|
||||||
iface eth1 inet6 static
|
iface eth1 inet6 static
|
||||||
address $ip
|
address $ip
|
||||||
netmask $nm
|
|
||||||
gateway $gw
|
gateway $gw
|
||||||
|
|
||||||
iface eth2 inet manual
|
iface eth2 inet manual
|
||||||
@ -444,8 +439,7 @@ iface eth3 inet manual
|
|||||||
|
|
||||||
auto vmbr0
|
auto vmbr0
|
||||||
iface vmbr0 inet static
|
iface vmbr0 inet static
|
||||||
address 10.0.0.2
|
address 10.0.0.2/24
|
||||||
netmask 255.255.255.0
|
|
||||||
gateway 10.0.0.1
|
gateway 10.0.0.1
|
||||||
bridge-ports eth0
|
bridge-ports eth0
|
||||||
bridge-stp off
|
bridge-stp off
|
||||||
|
@ -16,13 +16,10 @@ eth100:
|
|||||||
/proc/net/dev
|
/proc/net/dev
|
||||||
|
|
||||||
my %wanted = (
|
my %wanted = (
|
||||||
vmbr0 => { address => '192.168.1.2',
|
vmbr0 => { address => '192.168.1.2/24',
|
||||||
netmask => '255.255.255.0',
|
|
||||||
gateway => '192.168.1.1',
|
gateway => '192.168.1.1',
|
||||||
address6 => 'fc05::1:1',
|
address6 => 'fc05::1:1/112'},
|
||||||
netmask6 => '112' },
|
vmbr1 => { address => '10.0.0.5/24'}
|
||||||
vmbr1 => { address => '10.0.0.5',
|
|
||||||
netmask => '255.255.255.0' }
|
|
||||||
);
|
);
|
||||||
|
|
||||||
save('interfaces', <<"/etc/network/interfaces");
|
save('interfaces', <<"/etc/network/interfaces");
|
||||||
@ -40,23 +37,23 @@ iface eth100 inet manual
|
|||||||
|
|
||||||
auto vmbr0
|
auto vmbr0
|
||||||
iface vmbr0 inet static
|
iface vmbr0 inet static
|
||||||
address $wanted{vmbr0}->{address}
|
address 192.168.1.2
|
||||||
netmask $wanted{vmbr0}->{netmask}
|
netmask 24
|
||||||
gateway $wanted{vmbr0}->{gateway}
|
gateway $wanted{vmbr0}->{gateway}
|
||||||
bridge_ports eth0
|
bridge_ports eth0
|
||||||
bridge_stp off
|
bridge_stp off
|
||||||
bridge_fd 0
|
bridge_fd 0
|
||||||
|
|
||||||
iface vmbr0 inet6 static
|
iface vmbr0 inet6 static
|
||||||
address $wanted{vmbr0}->{address6}
|
address fc05::1:1
|
||||||
netmask $wanted{vmbr0}->{netmask6}
|
netmask 112
|
||||||
|
|
||||||
source-directory before-ovs.d
|
source-directory before-ovs.d
|
||||||
|
|
||||||
allow-ovs vmbr1
|
allow-ovs vmbr1
|
||||||
iface vmbr1 inet static
|
iface vmbr1 inet static
|
||||||
address $wanted{vmbr1}->{address}
|
address 10.0.0.5
|
||||||
netmask $wanted{vmbr1}->{netmask}
|
netmask 255.255.255.0
|
||||||
ovs_type OVSBridge
|
ovs_type OVSBridge
|
||||||
ovs_ports eth100
|
ovs_ports eth100
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
my $ip = '192.168.0.100';
|
my $ip = '192.168.0.100/24';
|
||||||
my $nm = '255.255.255.0';
|
|
||||||
my $gw = '192.168.0.1';
|
my $gw = '192.168.0.1';
|
||||||
|
|
||||||
# replace proc_net_dev with one with a bunch of interfaces
|
# replace proc_net_dev with one with a bunch of interfaces
|
||||||
@ -17,7 +16,6 @@ r('');
|
|||||||
new_iface('vmbr0', 'OVSBridge',
|
new_iface('vmbr0', 'OVSBridge',
|
||||||
[ { family => 'inet',
|
[ { family => 'inet',
|
||||||
address => $ip,
|
address => $ip,
|
||||||
netmask => $nm,
|
|
||||||
gateway => $gw } ],
|
gateway => $gw } ],
|
||||||
autostart => 1);
|
autostart => 1);
|
||||||
|
|
||||||
@ -42,7 +40,6 @@ iface eth3 inet manual
|
|||||||
allow-ovs vmbr0
|
allow-ovs vmbr0
|
||||||
iface vmbr0 inet static
|
iface vmbr0 inet static
|
||||||
address $ip
|
address $ip
|
||||||
netmask $nm
|
|
||||||
gateway $gw
|
gateway $gw
|
||||||
ovs_type OVSBridge
|
ovs_type OVSBridge
|
||||||
|
|
||||||
@ -70,7 +67,6 @@ iface eth3 inet manual
|
|||||||
allow-ovs vmbr0
|
allow-ovs vmbr0
|
||||||
iface vmbr0 inet static
|
iface vmbr0 inet static
|
||||||
address $ip
|
address $ip
|
||||||
netmask $nm
|
|
||||||
gateway $gw
|
gateway $gw
|
||||||
ovs_type OVSBridge
|
ovs_type OVSBridge
|
||||||
ovs_ports eth1 eth2
|
ovs_ports eth1 eth2
|
||||||
@ -105,7 +101,6 @@ iface eth2 inet manual
|
|||||||
allow-ovs vmbr0
|
allow-ovs vmbr0
|
||||||
iface vmbr0 inet static
|
iface vmbr0 inet static
|
||||||
address $ip
|
address $ip
|
||||||
netmask $nm
|
|
||||||
gateway $gw
|
gateway $gw
|
||||||
ovs_type OVSBridge
|
ovs_type OVSBridge
|
||||||
ovs_ports eth1
|
ovs_ports eth1
|
||||||
|
@ -18,8 +18,7 @@ iface eth1 inet manual
|
|||||||
|
|
||||||
auto vmbr0
|
auto vmbr0
|
||||||
iface vmbr0 inet static
|
iface vmbr0 inet static
|
||||||
address 10.0.0.2
|
address 10.0.0.2/24
|
||||||
netmask 255.255.255.0
|
|
||||||
gateway 10.0.0.1
|
gateway 10.0.0.1
|
||||||
bridge-ports eth0
|
bridge-ports eth0
|
||||||
bridge-stp off
|
bridge-stp off
|
||||||
|
@ -25,8 +25,7 @@ iface bond0 inet manual
|
|||||||
|
|
||||||
auto bond1
|
auto bond1
|
||||||
iface bond1 inet static
|
iface bond1 inet static
|
||||||
address 10.10.10.$ip
|
address 10.10.10.$ip/24
|
||||||
netmask 255.255.255.0
|
|
||||||
bond-slaves eth2 eth3
|
bond-slaves eth2 eth3
|
||||||
bond-miimon 100
|
bond-miimon 100
|
||||||
bond-mode balance-alb
|
bond-mode balance-alb
|
||||||
@ -41,20 +40,16 @@ iface bond2 inet manual
|
|||||||
|
|
||||||
iface unknown3 inet static
|
iface unknown3 inet static
|
||||||
address 0.0.0.0
|
address 0.0.0.0
|
||||||
netmask 0.0.0.0
|
|
||||||
|
|
||||||
iface unknown4 inet static
|
iface unknown4 inet static
|
||||||
address 0.0.0.0
|
address 0.0.0.0
|
||||||
netmask 0.0.0.0
|
|
||||||
|
|
||||||
iface unknown5 inet static
|
iface unknown5 inet static
|
||||||
address 0.0.0.0
|
address 0.0.0.0
|
||||||
netmask 0.0.0.0
|
|
||||||
|
|
||||||
auto vmbr0
|
auto vmbr0
|
||||||
iface vmbr0 inet static
|
iface vmbr0 inet static
|
||||||
address 192.168.100.13
|
address 192.168.100.13/24
|
||||||
netmask 255.255.255.0
|
|
||||||
gateway 192.168.100.1
|
gateway 192.168.100.1
|
||||||
bridge-ports bond0
|
bridge-ports bond0
|
||||||
bridge-stp off
|
bridge-stp off
|
||||||
@ -62,9 +57,7 @@ iface vmbr0 inet static
|
|||||||
|
|
||||||
auto unknown6
|
auto unknown6
|
||||||
iface unknown6 inet static
|
iface unknown6 inet static
|
||||||
address 10.10.11.13
|
address 10.10.11.13/24
|
||||||
netmask 255.255.255.0
|
|
||||||
network 10.10.11.0
|
|
||||||
pre-up ifconfig bond0 up
|
pre-up ifconfig bond0 up
|
||||||
|
|
||||||
auto vmbr3
|
auto vmbr3
|
||||||
@ -92,7 +85,7 @@ IFACES
|
|||||||
}
|
}
|
||||||
|
|
||||||
r(wanted(13));
|
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);
|
expect wanted(11);
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -3,11 +3,9 @@ eth0:
|
|||||||
eth1:
|
eth1:
|
||||||
/proc/net/dev
|
/proc/net/dev
|
||||||
|
|
||||||
my $ip = '192.168.0.2';
|
my $ip = '192.168.0.2/24';
|
||||||
my $nm = '255.255.255.0';
|
|
||||||
my $gw = '192.168.0.1';
|
my $gw = '192.168.0.1';
|
||||||
my $ip6 = 'fc05::2';
|
my $ip6 = 'fc05::2/112';
|
||||||
my $nm6 = '112';
|
|
||||||
my $gw6 = 'fc05::1';
|
my $gw6 = 'fc05::1';
|
||||||
|
|
||||||
# Load
|
# Load
|
||||||
@ -18,7 +16,6 @@ $config->{ifaces}->{eth1} = {
|
|||||||
type => 'eth',
|
type => 'eth',
|
||||||
method => 'static',
|
method => 'static',
|
||||||
address => $ip,
|
address => $ip,
|
||||||
netmask => $nm,
|
|
||||||
gateway => $gw,
|
gateway => $gw,
|
||||||
families => ['inet'],
|
families => ['inet'],
|
||||||
autostart => 1
|
autostart => 1
|
||||||
@ -33,13 +30,11 @@ iface eth0 inet manual
|
|||||||
auto eth1
|
auto eth1
|
||||||
iface eth1 inet static
|
iface eth1 inet static
|
||||||
address $ip
|
address $ip
|
||||||
netmask $nm
|
|
||||||
gateway $gw
|
gateway $gw
|
||||||
|
|
||||||
auto vmbr0
|
auto vmbr0
|
||||||
iface vmbr0 inet static
|
iface vmbr0 inet static
|
||||||
address 10.0.0.2
|
address 10.0.0.2/24
|
||||||
netmask 255.255.255.0
|
|
||||||
gateway 10.0.0.1
|
gateway 10.0.0.1
|
||||||
bridge-ports eth0
|
bridge-ports eth0
|
||||||
bridge-stp off
|
bridge-stp off
|
||||||
@ -69,18 +64,15 @@ iface eth0 inet manual
|
|||||||
auto eth1
|
auto eth1
|
||||||
iface eth1 inet static
|
iface eth1 inet static
|
||||||
address $ip
|
address $ip
|
||||||
netmask $nm
|
|
||||||
gateway $gw
|
gateway $gw
|
||||||
|
|
||||||
iface eth1 inet6 static
|
iface eth1 inet6 static
|
||||||
address $ip6
|
address $ip6
|
||||||
netmask $nm6
|
|
||||||
gateway $gw6
|
gateway $gw6
|
||||||
|
|
||||||
auto vmbr0
|
auto vmbr0
|
||||||
iface vmbr0 inet static
|
iface vmbr0 inet static
|
||||||
address 10.0.0.2
|
address 10.0.0.2/24
|
||||||
netmask 255.255.255.0
|
|
||||||
gateway 10.0.0.1
|
gateway 10.0.0.1
|
||||||
bridge-ports eth0
|
bridge-ports eth0
|
||||||
bridge-stp off
|
bridge-stp off
|
||||||
|
Loading…
Reference in New Issue
Block a user