also add support for ipv6
Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
use PVE::JSONSchema qw(register_standard_option get_standard_option);
use PVE::Cluster;
use PVE::ProcFSTools;
use PVE::JSONSchema qw(register_standard_option get_standard_option);
use PVE::Cluster;
use PVE::ProcFSTools;
-use PVE::Tools qw($IPV4RE);
+use PVE::Tools qw($IPV4RE $IPV6RE);
use File::Basename;
use File::Path;
use IO::File;
use File::Basename;
use File::Path;
use IO::File;
sub pve_verify_ipv4_or_cidr {
my ($cidr, $noerr) = @_;
sub pve_verify_ipv4_or_cidr {
my ($cidr, $noerr) = @_;
- if ($cidr =~ m!^(?:$IPV4RE)(/(\d+))?$!) {
+ if ($cidr =~ m!^(?:$IPV6RE|$IPV4RE)(/(\d+))?$!) {
return $cidr if Net::IP->new($cidr);
return undef if $noerr;
die Net::IP::Error() . "\n";
return $cidr if Net::IP->new($cidr);
return undef if $noerr;
die Net::IP::Error() . "\n";
} elsif ($value =~ m/^${ip_alias_pattern}$/){
my $alias = lc($value);
&$add_error($name, "no such alias '$value'")
} elsif ($value =~ m/^${ip_alias_pattern}$/){
my $alias = lc($value);
&$add_error($name, "no such alias '$value'")
- if !($cluster_conf->{aliases}->{$alias} || ($fw_conf && $fw_conf->{aliases}->{$alias}))
+ if !($cluster_conf->{aliases}->{$alias} || ($fw_conf && $fw_conf->{aliases}->{$alias}));
+
+ my $e = $fw_conf->{aliases}->{$alias} if $fw_conf;
+ $e = $cluster_conf->{aliases}->{$alias} if !$e && $cluster_conf;
+
+ $ipversion = $e->{ipversion};
if ($line =~ m/^(\S+)\s(\S+)$/) {
my ($name, $cidr) = ($1, $2);
$cidr =~ s|/32$||;
if ($line =~ m/^(\S+)\s(\S+)$/) {
my ($name, $cidr) = ($1, $2);
$cidr =~ s|/32$||;
pve_verify_ipv4_or_cidr($cidr);
pve_verify_ipv4_or_cidr($cidr);
+ my $ipversion = get_ip_version($cidr);
my $data = {
name => $name,
cidr => $cidr,
my $data = {
name => $name,
cidr => $cidr,
+ ipversion => $ipversion,
};
$data->{comment} = $comment if $comment;
return $data;
};
$data->{comment} = $comment if $comment;
return $data;
+sub get_ip_version {
+ my ($cidr) = @_;
+
+ my $ipversion = undef;
+
+ if ($cidr =~ m!^(?:$IPV4RE)(/(\d+))?$!) {
+ $ipversion = '4';
+ }elsif ($cidr =~ m!^(?:$IPV6RE)(/(\d+))?$!) {
+ $ipversion = '6';
+ }
+
+ return $ipversion;
+}
+
sub generic_fw_config_parser {
my ($filename, $fh, $verbose, $cluster_conf, $empty_conf, $rule_env) = @_;
sub generic_fw_config_parser {
my ($filename, $fh, $verbose, $cluster_conf, $empty_conf, $rule_env) = @_;