IPTables-Rule
view release on metacpan or search on metacpan
lib/IPTables/Rule.pm view on Meta::CPAN
if ( $self->{dst} ) {
# make sure it's ipv4
unless ( __is_valid_inet4($self->{dst}) ) {
__errstr($self, 'IP Version is 4 but destination is not valid IPv4');
return;
}
}
} elsif ( $self->{ipver} eq '6' ) {
if ( $self->{src} ) {
# make sure it's ipv6
unless ( __is_valid_inet6($self->{src}) ) {
__errstr($self, 'IP Version is 6 but source is not valid IPv6');
return;
}
}
if ( $self->{dst} ) {
# make sure it's ipv6
unless ( __is_valid_inet6($self->{dst}) ) {
__errstr($self, 'IP Version is 6 but destination is not valid IPv6');
return;
}
}
} else {
# should never happen; the ipversion sub validates user input
__errstr($self, 'Code bug 0x01; Please report to developer.');
return;
}
# if icmp_type is set, protocol must be icmp or icmpv6
lib/IPTables/Rule.pm view on Meta::CPAN
# ipv4 range?
return 1 if ( __is_inet4_range($arg) );
# fqdn?
return 1 if ( $arg =~ m/\A$qr_fqdn\z/ );
# fail by default
return;
}
sub __is_valid_inet6 {
my ( $arg ) = @_;
chomp($arg);
return unless ( $arg );
# ipv6 address?
return 1 if ( __is_inet6_host($arg) );
# ipv4 cidr?
return 1 if ( __is_inet6_cidr($arg) );
# ipv4 range?
return 1 if ( __is_inet6_range($arg) );
# fqdn?
return 1 if ( $arg =~ m/\A$qr_fqdn\z/ );
# fail by default
return;
}
sub __is_valid_inet_host {
my ( $arg ) = @_;
chomp($arg);
return unless ( $arg );
# ipv4 address?
return 1 if ( __is_inet4_host($arg) );
# ipv6 address?
return 1 if ( __is_inet6_host($arg) );
# fqdn?
return 1 if ( $arg =~ m/\A$qr_fqdn\z/ );
# fail by default
return;
}
sub __is_inet4_host {
my ( $arg ) = @_;
lib/IPTables/Rule.pm view on Meta::CPAN
return unless ( $arg );
# ipv4 address?
return 1 if ( $arg =~ m/\A$qr_ip4_addr\z/ );
# fail by default
return;
}
sub __is_inet6_host {
my ( $arg ) = @_;
chomp($arg);
return unless ( $arg );
# ipv6 address?
return 1 if ( $arg =~ m/\A$qr_ip6_addr\z/ );
# fail by default
return;
lib/IPTables/Rule.pm view on Meta::CPAN
sub __is_valid_inet_cidr {
my ( $arg ) = @_;
chomp($arg);
return unless ( $arg );
# ipv4 cidr?
return 1 if ( __is_inet4_cidr($arg) );
# ipv6 cidr?
return 1 if ( __is_inet6_cidr($arg) );
# fail by default
return;
}
sub __is_inet4_cidr {
my ( $arg ) = @_;
chomp($arg);
return unless ( $arg );
lib/IPTables/Rule.pm view on Meta::CPAN
return if ( $cidr < 0 );
return if ( $cidr > 32 );
return 1;
}
# fail by default
return;
}
sub __is_inet6_cidr {
my ( $arg ) = @_;
chomp($arg);
return unless ( $arg );
# ipv6 cidr?
if ( $arg =~ m/\A$qr_ip6_cidr\z/ ) {
# validate the cidr
my ($host, $cidr) = split(/\//, $arg);
return if ( $cidr < 0 );
lib/IPTables/Rule.pm view on Meta::CPAN
sub __is_valid_inet_range {
my ( $arg ) = @_;
chomp($arg);
return unless ( $arg );
# ipv4 address range?
return 1 if ( __is_inet4_range($arg) );
# ipv6 address range?
return 1 if ( __is_inet6_range($arg) );
# fail by default
return;
}
sub __is_inet4_range {
my ( $arg ) = @_;
chomp($arg);
return unless ( $arg );
# ipv4 address range?
return 1 if (
$arg =~ m/\A$qr_ip4_addr\-$qr_ip4_addr\z/
);
# fail by default
return;
}
sub __is_inet6_range {
my ( $arg ) = @_;
chomp($arg);
return unless ( $arg );
# ipv6 address range?
return 1 if (
$arg =~ m/\A$qr_ip6_addr\-$qr_ip6_addr\z/
);
( run in 1.251 second using v1.01-cache-2.11-cpan-87723dcf8b7 )