API2: Network: allow cidr-list && use cidr for address

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
This commit is contained in:
Alexandre Derumier 2020-03-04 17:17:59 +01:00 committed by Thomas Lamprecht
parent 806edfe19f
commit a665f24d29

View File

@ -152,7 +152,7 @@ my $confdesc = {
},
cidr => {
description => 'IPv4 CIDR.',
type => 'string', format => 'CIDRv4',
type => 'string', format => 'CIDRv4-list',
optional => 1,
},
mtu => {
@ -181,7 +181,7 @@ my $confdesc = {
},
cidr6 => {
description => 'IPv6 CIDR.',
type => 'string', format => 'CIDRv6',
type => 'string', format => 'CIDRv6-list',
optional => 1,
},
};
@ -326,11 +326,14 @@ my $map_cidr_to_address_netmask = sub {
if $param->{address};
raise_param_exc({ netmask => "netmask conflicts with cidr" })
if $param->{netmask};
my @cidrs = split /,/, $param->{cidr};
foreach my $cidr (@cidrs) {
push @{$param->{address}}, $cidr;
}
my ($address, $netmask) = $param->{cidr} =~ m!^(.*)/(\d+)$!;
$param->{address} = $address;
$param->{netmask} = $netmask;
delete $param->{cidr};
} elsif ($param->{address} && $param->{netmask}) {
$param->{address} = ["$param->{address}/$param->{netmask}"];
}
if ($param->{cidr6}) {
@ -339,10 +342,14 @@ my $map_cidr_to_address_netmask = sub {
raise_param_exc({ netmask6 => "netmask6 conflicts with cidr6" })
if $param->{netmask6};
my ($address, $netmask) = $param->{cidr6} =~ m!^(.*)/(\d+)$!;
$param->{address6} = $address;
$param->{netmask6} = $netmask;
my @cidrs = split /,/, $param->{cidr6};
foreach my $cidr (@cidrs) {
push @{$param->{address6}}, $cidr;
}
delete $param->{cidr6};
} elsif ($param->{address6} && $param->{netmask6}) {
$param->{address} = ["$param->{address6}/$param->{netmask6}"];
}
};