| 1 | package IPTables::Rule; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.000000; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 10 | ### PRECOMPILED REGEX | ||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | my $qr_fqdn = qr/(([A-Z0-9]|[A-Z0-9][A-Z0-9\-]*[A-Z0-9])\.)*([A-Z]|[A-Z][A-Z0-9\-]*[A-Z0-9])/io; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | my $qr_mac_addr = qr/(([A-F0-9]{2}[:.-]?){6})/io; | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | my $qr_ip4_addr = qr/(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/o; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | my $qr_ip6_addr; | |||||||||||||||||||||||||||||||||||||||||
| 16 | { | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # This block courtesy of Regexp::IPv6 0.03 by Salvador FandiƱo | ||||||||||||||||||||||||||||||||||||||||||
| 18 | # http://search.cpan.org/~salva/Regexp-IPv6/ | ||||||||||||||||||||||||||||||||||||||||||
| 19 | # http://cpansearch.perl.org/src/SALVA/Regexp-IPv6-0.03/lib/Regexp/IPv6.pm | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | my $IPv4 = "((25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})[.](25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2}))"; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | my $G = "[0-9a-fA-F]{1,4}"; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | my @tail = ( ":", | |||||||||||||||||||||||||||||||||||||||||
| 23 | "(:($G)?|$IPv4)", | ||||||||||||||||||||||||||||||||||||||||||
| 24 | ":($IPv4|$G(:$G)?|)", | ||||||||||||||||||||||||||||||||||||||||||
| 25 | "(:$IPv4|:$G(:$IPv4|(:$G){0,2})|:)", | ||||||||||||||||||||||||||||||||||||||||||
| 26 | "((:$G){0,2}(:$IPv4|(:$G){1,2})|:)", | ||||||||||||||||||||||||||||||||||||||||||
| 27 | "((:$G){0,3}(:$IPv4|(:$G){1,2})|:)", | ||||||||||||||||||||||||||||||||||||||||||
| 28 | "((:$G){0,4}(:$IPv4|(:$G){1,2})|:)" ); | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | my $IPv6_re = $G; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | $IPv6_re = "$G:($IPv6_re|$_)" for @tail; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | $IPv6_re = qq/:(:$G){0,5}((:$G){1,2}|:$IPv4)|$IPv6_re/; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | $IPv6_re =~ s/\(/(?:/g; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | $qr_ip6_addr = qr/$IPv6_re/; | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # and the CIDR versions of the above | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | my $qr_ip4_cidr = qr/$qr_ip4_addr\/[0-9]{1,2}/o; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | my $qr_ip6_cidr = qr/$qr_ip6_addr\/[0-9]{1,3}/io; | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 40 | ### METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 27 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 27 | my $self = { | |||||||||||||||||||||||||||||||||||||||||
| 44 | ip4binary => 'iptables', | ||||||||||||||||||||||||||||||||||||||||||
| 45 | ip6binary => 'ip6tables', | ||||||||||||||||||||||||||||||||||||||||||
| 46 | iptaction => '-A', | ||||||||||||||||||||||||||||||||||||||||||
| 47 | ipver => '4', # IPv4 by default | ||||||||||||||||||||||||||||||||||||||||||
| 48 | table => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 49 | chain => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 50 | target => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 51 | in => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 52 | out => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | src => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 54 | dst => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 55 | proto => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 56 | dpt => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | spt => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | mac => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | state => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | comment => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 61 | logprefix => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 62 | icmp_type => undef, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 27 | bless $self; | |||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | sub dump { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | my %dump_hash; | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | foreach my $key ( keys %$self ) { | |||||||||||||||||||||||||||||||||||||||||
| 73 | 19 | ▶ | $dump_hash{$key} = $self->{$key} if ( defined($self->{$key}) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | return \%dump_hash; | |||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | ▶ | sub errstr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
errstr: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | return $self->{errstr}; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 3 | ▶ | sub ip4binary { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ip4binary: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 3 | my ($arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 3 | ▶ | if ( $arg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 3 | ▶ | unless ( $arg =~ m|\A/.+\z| ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | __errstr($self, 'invalid path: '.$arg); | |||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 2 | $self->{ip4binary} = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 2 | return $self->{ip4binary}; | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 3 | ▶ | sub ip6binary { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ip6binary: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 3 | my ($arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 3 | ▶ | if ( $arg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 3 | ▶ | unless ( $arg =~ m|\A/.+\z| ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | __errstr($self, 'invalid path: '.$arg); | |||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 2 | $self->{ip6binary} = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 2 | return $self->{ip6binary}; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 14 | ▶ | sub iptaction { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
iptaction: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 14 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 14 | my ($arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 14 | ▶ | if ( $arg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | 14 | ▶ | unless ( $arg =~ m/\A-[ADIRLSFZNXPE]\z/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 2 | __errstr($self, 'invalid action: '.$arg); | |||||||||||||||||||||||||||||||||||||||||
| 121 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 12 | $self->{iptaction} = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 12 | return $self->{iptaction}; | |||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 12 | ▶ | sub ipversion { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ipversion: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 12 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 12 | my ($arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 12 | ▶ | if ( $arg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | # Valid arguments are 4 and 6 | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 12 | ▶ | unless ( $arg =~ m/\A[46]\z/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 4 | __errstr($self, 'invalid ip version: '.$arg); | |||||||||||||||||||||||||||||||||||||||||
| 137 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 8 | $self->{ipver} = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 8 | return $self->{ipver}; | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 8 | ▶ | sub table { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
table: called CC=7 SCAR=21.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 8 | my ($arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 8 | ▶ | if ( $arg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 8 | my $need_to_barf; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 8 | ▶ | $need_to_barf = 1 if ( $self->{ipver} eq '4' and $arg !~ m/\A(filter|nat|mangle|raw)\z/i ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"ipver"} eq 4 and not $arg =~ /\A(filter|nat|mangle|raw)\z/i
MC/DC0%0/2
$self->{"ipver"} eq 4 and not $arg =~ /\A(filter|nat|mangle|raw)\z/i
$self->{"ipver"} eq 4
not $arg =~ /\A(filter|nat|mangle|raw)\z/i
Truth table66%2/3
A and not(B)
A= $self->{"ipver"} eq 4B= not $arg =~ /\A(filter|nat|mangle|raw)\z/i
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 8 | ▶ | $need_to_barf = 1 if ( $self->{ipver} eq '6' and $arg !~ m/\A(filter|mangle|raw)\z/i ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"ipver"} eq 6 and not $arg =~ /\A(filter|mangle|raw)\z/i
MC/DC0%0/2
$self->{"ipver"} eq 6 and not $arg =~ /\A(filter|mangle|raw)\z/i
$self->{"ipver"} eq 6
not $arg =~ /\A(filter|mangle|raw)\z/i
Truth table66%2/3
A and not(B)
A= $self->{"ipver"} eq 6B= not $arg =~ /\A(filter|mangle|raw)\z/i
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 8 | ▶ | if ( $need_to_barf ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | __errstr($self, sprintf('invalid table "%s" for ip version: %s', $arg, $self->{ipver})); | |||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | 8 | $self->{table} = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 8 | return $self->{table}; | |||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 8 | ▶ | sub chain { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
chain: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 167 | 8 | my ($arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 8 | ▶ | if ( $arg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 8 | $self->{chain} = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 8 | return $self->{chain}; | |||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 10 | ▶ | sub target { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
target: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 178 | 10 | my ($arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | 10 | ▶ | if ( $arg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | 10 | $self->{target} = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 10 | return $self->{target}; | |||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 1 | *protocol = \&proto; | |||||||||||||||||||||||||||||||||||||||||
| 188 | 11 | ▶ | sub proto { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
proto: called CC=7 SCAR=19.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 11 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 11 | my ($arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 11 | ▶ | if ( $arg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 11 | ▶ | unless ( $arg =~ m/\A[a-z0-9]+\z/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | __errstr($self, 'invalid protocol: '.$arg); | |||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 11 | ▶ | if ( $self->{ipver} eq '6' and $arg eq 'icmp' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"ipver"} eq 6 and $arg eq "icmp"
MC/DC100%2/2
$self->{"ipver"} eq 6 and $arg eq "icmp"
$self->{"ipver"} eq 6
$arg eq "icmp"
Truth table100%3/3
A and B
A= $self->{"ipver"} eq 6B= $arg eq "icmp"
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | __errstr($self, 'icmp not valid protocol for IPv6. Perhaps you meant "icmpv6"?'); | |||||||||||||||||||||||||||||||||||||||||
| 199 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | 10 | ▶ | if ( $self->{ipver} eq '4' and $arg eq 'icmpv6' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"ipver"} eq 4 and $arg eq "icmpv6"
MC/DC100%2/2
$self->{"ipver"} eq 4 and $arg eq "icmpv6"
$self->{"ipver"} eq 4
$arg eq "icmpv6"
Truth table100%3/3
A and B
A= $self->{"ipver"} eq 4B= $arg eq "icmpv6"
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | __errstr($self, 'icmpv6 not valid protocol for IPv4. Perhaps you meant "icmp"?'); | |||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 9 | $self->{proto} = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 9 | return $self->{proto}; | |||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 9 | ▶ | sub in { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
in: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 214 | 9 | my ($arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 9 | ▶ | if ( $arg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 9 | $self->{in} = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | 9 | return $self->{in}; | |||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 8 | ▶ | sub out { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
out: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 225 | 8 | my ($arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 8 | ▶ | if ( $arg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 8 | $self->{out} = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 8 | return $self->{out}; | |||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 1 | *source = \&src; | |||||||||||||||||||||||||||||||||||||||||
| 235 | 17 | ▶ | sub src { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
src: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 17 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 237 | 17 | my ($arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | 17 | ▶ | if ( $arg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 17 | ▶ | unless ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
__is_valid_inet_host($arg) or __is_valid_inet_cidr($arg) or __is_valid_inet_range($arg)
__is_valid_inet_host($arg) or __is_valid_inet_cidr($arg)
MC/DC66%2/3
__is_valid_inet_host($arg) or __is_valid_inet_cidr($arg) or __is_valid_inet_range($arg)
__is_valid_inet_host($arg)
__is_valid_inet_cidr($arg)
__is_valid_inet_range($arg)
Truth table75%3/4
A or B or C
A= __is_valid_inet_host($arg)B= __is_valid_inet_cidr($arg)C= __is_valid_inet_range($arg)
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | __is_valid_inet_host($arg) or | ||||||||||||||||||||||||||||||||||||||||||
| 242 | __is_valid_inet_cidr($arg) or | ||||||||||||||||||||||||||||||||||||||||||
| 243 | __is_valid_inet_range($arg) | ||||||||||||||||||||||||||||||||||||||||||
| 244 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 7 | __errstr($self, 'invalid source address: '.$arg); | |||||||||||||||||||||||||||||||||||||||||
| 246 | 7 | return; | |||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 10 | $self->{src} = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 10 | return $self->{src}; | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 1 | *dest = \&dst; | |||||||||||||||||||||||||||||||||||||||||
| 256 | 1 | *destination = \&dst; | |||||||||||||||||||||||||||||||||||||||||
| 257 | 16 | ▶ | sub dst { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dst: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 16 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 259 | 16 | my ($arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 16 | ▶ | if ( $arg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 16 | ▶ | unless ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
__is_valid_inet_host($arg) or __is_valid_inet_cidr($arg) or __is_valid_inet_range($arg)
__is_valid_inet_host($arg) or __is_valid_inet_cidr($arg)
MC/DC66%2/3
__is_valid_inet_host($arg) or __is_valid_inet_cidr($arg) or __is_valid_inet_range($arg)
__is_valid_inet_host($arg)
__is_valid_inet_cidr($arg)
__is_valid_inet_range($arg)
Truth table75%3/4
A or B or C
A= __is_valid_inet_host($arg)B= __is_valid_inet_cidr($arg)C= __is_valid_inet_range($arg)
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | __is_valid_inet_host($arg) or | ||||||||||||||||||||||||||||||||||||||||||
| 264 | __is_valid_inet_cidr($arg) or | ||||||||||||||||||||||||||||||||||||||||||
| 265 | __is_valid_inet_range($arg) | ||||||||||||||||||||||||||||||||||||||||||
| 266 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 7 | __errstr($self, 'invalid destination address: '.$arg); | |||||||||||||||||||||||||||||||||||||||||
| 268 | 7 | return; | |||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 9 | $self->{dst} = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | 9 | return $self->{dst}; | |||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | 1 | *port = \&dpt; | |||||||||||||||||||||||||||||||||||||||||
| 278 | 1 | *dport = \&dpt; | |||||||||||||||||||||||||||||||||||||||||
| 279 | 14 | ▶ | sub dpt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dpt: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 14 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 281 | 14 | my ($arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | 14 | ▶ | if ( $arg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 14 | ▶ | unless ( __is_valid_inet_port($arg) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 5 | __errstr($self, 'invalid destination port: '.$arg); | |||||||||||||||||||||||||||||||||||||||||
| 286 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 9 | $self->{dpt} = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | 9 | return $self->{dpt}; | |||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | 1 | *sport = \&spt; | |||||||||||||||||||||||||||||||||||||||||
| 296 | 11 | ▶ | sub spt { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
spt: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | 11 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 298 | 11 | my ($arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | 11 | ▶ | if ( $arg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 301 | 11 | ▶ | unless ( __is_valid_inet_port($arg) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 5 | __errstr($self, 'invalid source port: '.$arg); | |||||||||||||||||||||||||||||||||||||||||
| 303 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | 6 | $self->{spt} = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | 6 | return $self->{spt}; | |||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | 4 | ▶ | sub mac { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mac: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 314 | 4 | my ($arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | 4 | ▶ | if ( $arg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 4 | ▶ | unless ( __is_valid_mac_address($arg) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 3 | __errstr($self, 'invalid mac address: '.$arg); | |||||||||||||||||||||||||||||||||||||||||
| 319 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | 1 | $self->{mac} = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | 1 | return $self->{mac}; | |||||||||||||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 11 | ▶ | sub state { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
state: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | 11 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 330 | 11 | my ($arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | 11 | ▶ | if ( $arg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | 11 | my @states = split(",",$arg); | |||||||||||||||||||||||||||||||||||||||||
| 334 | 11 | for (@states) { | |||||||||||||||||||||||||||||||||||||||||
| 335 | 14 | ▶ | unless ( $_ =~ m/\A(NEW|ESTABLISHED|RELATED|INVALID|UNTRACKED)\z/i ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 3 | __errstr($self, 'invalid connection tracking state: '.$_); | |||||||||||||||||||||||||||||||||||||||||
| 337 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 8 | $self->{state} = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | 8 | return $self->{state}; | |||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 1 | *rate_limit = \&limit; | |||||||||||||||||||||||||||||||||||||||||
| 347 | 17 | ▶ | sub limit { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
limit: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | 17 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 349 | 17 | my ($arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 17 | ▶ | if ( $arg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | # --limit rate[/second|/minute|/hour|/day] | ||||||||||||||||||||||||||||||||||||||||||
| 353 | 17 | ▶ | unless ( $arg =~ m/\A\d+\/(s(ec(ond)?)?|m(in(ute)?)?|h(our)?|d(ay)?)\z/i ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | 6 | __errstr($self, 'invalid rate limit: '.$arg); | |||||||||||||||||||||||||||||||||||||||||
| 355 | 6 | return; | |||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 11 | $self->{limit} = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | 11 | return $self->{limit}; | |||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | 10 | ▶ | sub icmp_type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
icmp_type: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 365 | 10 | my ($arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | 10 | ▶ | if ( $arg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | 10 | ▶ | unless ( $arg =~ m|\A[a-z0-9\-]+(/[a-z0-9\-]+)?\z|i ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | 2 | __errstr($self, 'invalid icmp type: '.$arg); | |||||||||||||||||||||||||||||||||||||||||
| 370 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | 8 | $self->{icmp_type} = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | 8 | return $self->{icmp_type}; | |||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | 6 | ▶ | sub logprefix { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
logprefix: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 381 | 6 | my ($arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||
| 383 | 6 | my $max_length = 29; | |||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||
| 385 | 6 | ▶ | if ( $arg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | 6 | ▶ | if ( length($arg) > $max_length ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | 3 | __errstr($self, 'log prefix too long (>'.$max_length.'): '.$arg); | |||||||||||||||||||||||||||||||||||||||||
| 388 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | 3 | ▶ | if ( $arg =~ m/[\"\']/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | __errstr($self, 'quotes not permitted: '.$arg); | |||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | 3 | $self->{logprefix} = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | 3 | return $self->{logprefix}; | |||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | 7 | ▶ | sub comment { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
comment: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 403 | 7 | my ($arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | 7 | my $max_length = 256; | |||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | 7 | ▶ | if ( $arg ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | 7 | ▶ | if ( length($arg) > $max_length ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 409 | 1 | __errstr($self, 'comment too long (>'.$max_length.'): '.$arg); | |||||||||||||||||||||||||||||||||||||||||
| 410 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 412 | 6 | ▶ | if ( $arg =~ m/[\"\']/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | 1 | __errstr($self, 'quotes not permitted: '.$arg); | |||||||||||||||||||||||||||||||||||||||||
| 414 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | 5 | $self->{comment} = $arg; | |||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | 5 | return $self->{comment}; | |||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | 1 | *compile = \&generate; | |||||||||||||||||||||||||||||||||||||||||
| 424 | 6 | ▶ | sub generate { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate: called CC=49 SCAR=59.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 425 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | # what is required? | ||||||||||||||||||||||||||||||||||||||||||
| 428 | 6 | ▶ | unless ( $self->{chain} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | __errstr($self, 'Chain must be specified'); | |||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||
| 432 | # ports are only valid with protocol tcp and udp | ||||||||||||||||||||||||||||||||||||||||||
| 433 | 6 | ▶ | if ( defined($self->{spt}) and $self->{proto} !~ m/\A(tcp|udp)\z/i ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"spt"} and not $self->{"proto"} =~ /\A(tcp|udp)\z/i
MC/DC0%0/2
defined $self->{"spt"} and not $self->{"proto"} =~ /\A(tcp|udp)\z/i
defined $self->{"spt"}
not $self->{"proto"} =~ /\A(tcp|udp)\z/i
Truth table33%1/3
A and not(B)
A= defined $self->{"spt"}B= not $self->{"proto"} =~ /\A(tcp|udp)\z/i
| |||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | __errstr($self, 'Protocol must be TCP or UDP when specifying source port'); | |||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||
| 437 | 6 | ▶ | if ( defined($self->{dpt}) and $self->{proto} !~ m/\A(tcp|udp)\z/i ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->{"dpt"} and not $self->{"proto"} =~ /\A(tcp|udp)\z/i
MC/DC0%0/2
defined $self->{"dpt"} and not $self->{"proto"} =~ /\A(tcp|udp)\z/i
defined $self->{"dpt"}
not $self->{"proto"} =~ /\A(tcp|udp)\z/i
Truth table66%2/3
A and not(B)
A= defined $self->{"dpt"}B= not $self->{"proto"} =~ /\A(tcp|udp)\z/i
| |||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | __errstr($self, 'Protocol must be TCP or UDP when specifying destinatipn port'); | |||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||
| 441 | # cant use 'logprefix' unless the target is 'log' | ||||||||||||||||||||||||||||||||||||||||||
| 442 | 6 | ▶ | if ( defined($self->{logprefix}) and $self->{target} !~ m/\Alog\z/i ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"logprefix"} and not $self->{"target"} =~ /\Alog\z/i
MC/DC0%0/2
defined $self->{"logprefix"} and not $self->{"target"} =~ /\Alog\z/i
defined $self->{"logprefix"}
not $self->{"target"} =~ /\Alog\z/i
Truth table33%1/3
A and not(B)
A= defined $self->{"logprefix"}B= not $self->{"target"} =~ /\Alog\z/i
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | __errstr($self, 'Target must be LOG when specifying log prefix'); | |||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||
| 446 | # ipversion matches the source/dest addresses? | ||||||||||||||||||||||||||||||||||||||||||
| 447 | 6 | ▶ | if ( $self->{ipver} eq '4' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | 5 | ▶ | if ( $self->{src} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | # make sure it's ipv4 | ||||||||||||||||||||||||||||||||||||||||||
| 450 | 1 | ▶ | unless ( __is_valid_inet4($self->{src}) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 451 | 1 | __errstr($self, 'IP Version is 4 but source is not valid IPv4'); | |||||||||||||||||||||||||||||||||||||||||
| 452 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||
| 455 | 4 | ▶ | if ( $self->{dst} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 456 | # make sure it's ipv4 | ||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | ▶ | unless ( __is_valid_inet4($self->{dst}) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | __errstr($self, 'IP Version is 4 but destination is not valid IPv4'); | |||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||
| 461 | } | ||||||||||||||||||||||||||||||||||||||||||
| 462 | } elsif ( $self->{ipver} eq '6' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 463 | 1 | ▶ | if ( $self->{src} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 464 | # make sure it's ipv6 | ||||||||||||||||||||||||||||||||||||||||||
| 465 | 1 | ▶ | unless ( __is_valid_inet6($self->{src}) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 466 | 1 | __errstr($self, 'IP Version is 6 but source is not valid IPv6'); | |||||||||||||||||||||||||||||||||||||||||
| 467 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | ▶ | if ( $self->{dst} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 471 | # make sure it's ipv6 | ||||||||||||||||||||||||||||||||||||||||||
| 472 | 0 | ▶ | unless ( __is_valid_inet6($self->{dst}) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | __errstr($self, 'IP Version is 6 but destination is not valid IPv6'); | |||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 478 | # should never happen; the ipversion sub validates user input | ||||||||||||||||||||||||||||||||||||||||||
| 479 | 0 | __errstr($self, 'Code bug 0x01; Please report to developer.'); | |||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||
| 482 | # if icmp_type is set, protocol must be icmp or icmpv6 | ||||||||||||||||||||||||||||||||||||||||||
| 483 | 4 | ▶ | if ( defined($self->{icmp_type}) and $self->{proto} !~ m/\Aicmp(v6)?\z/i ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->{"icmp_type"} and not $self->{"proto"} =~ /\Aicmp(v6)?\z/i
MC/DC0%0/2
defined $self->{"icmp_type"} and not $self->{"proto"} =~ /\Aicmp(v6)?\z/i
defined $self->{"icmp_type"}
not $self->{"proto"} =~ /\Aicmp(v6)?\z/i
Truth table33%1/3
A and not(B)
A= defined $self->{"icmp_type"}B= not $self->{"proto"} =~ /\Aicmp(v6)?\z/i
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | __errstr($self, 'icmp_type is set, but protocol is: '.$self->{proto}); | |||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | 4 | my $rule_prefix; | |||||||||||||||||||||||||||||||||||||||||
| 489 | my $rule_criteria; | ||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | 4 | ▶ | $rule_prefix = $self->{ip4binary} if $self->{ipver} eq '4'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 492 | 4 | ▶ | $rule_prefix = $self->{ip6binary} if $self->{ipver} eq '6'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 493 | 4 | ▶ | $rule_prefix .= ' -t '.$self->{table} if ( defined($self->{'table'}) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 494 | 4 | $rule_prefix .= ' '.$self->{iptaction}; | |||||||||||||||||||||||||||||||||||||||||
| 495 | 4 | $rule_prefix .= ' '.$self->{chain}; | |||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||
| 497 | # Source and Destination Addresses | ||||||||||||||||||||||||||||||||||||||||||
| 498 | 4 | ▶ | if ( defined($self->{src}) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | ▶ | if ( __is_valid_inet_host($self->{src}) or __is_valid_inet_cidr($self->{src}) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
__is_valid_inet_host($self->{"src"}) or __is_valid_inet_cidr($self->{"src"})
MC/DC0%0/2
__is_valid_inet_host($self->{"src"}) or __is_valid_inet_cidr($self->{"src"})
__is_valid_inet_host($self->{"src"})
__is_valid_inet_cidr($self->{"src"})
Truth table0%0/3
A or B
A= __is_valid_inet_host($self->{"src"})B= __is_valid_inet_cidr($self->{"src"})
| |||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | $rule_criteria .= sprintf(' -s %s', $self->{src}); | |||||||||||||||||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||||||||||||||||
| 502 | 0 | ▶ | if ( __is_valid_inet_range($self->{src}) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | $rule_criteria .= sprintf(' -m iprange --src-range %s', $self->{'src'}); | |||||||||||||||||||||||||||||||||||||||||
| 504 | } | ||||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||
| 506 | 4 | ▶ | if ( defined($self->{dst}) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | ▶ | if ( __is_valid_inet_host($self->{dst}) or __is_valid_inet_cidr($self->{dst}) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
__is_valid_inet_host($self->{"dst"}) or __is_valid_inet_cidr($self->{"dst"})
MC/DC0%0/2
__is_valid_inet_host($self->{"dst"}) or __is_valid_inet_cidr($self->{"dst"})
__is_valid_inet_host($self->{"dst"})
__is_valid_inet_cidr($self->{"dst"})
Truth table0%0/3
A or B
A= __is_valid_inet_host($self->{"dst"})B= __is_valid_inet_cidr($self->{"dst"})
| |||||||||||||||||||||||||||||||||||||||||||
| 508 | 0 | $rule_criteria .= sprintf(' -d %s', $self->{dst}); | |||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | ▶ | if ( __is_valid_inet_range($self->{dst}) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | $rule_criteria .= sprintf(' -m iprange --dst-range %s', $self->{'dst'}); | |||||||||||||||||||||||||||||||||||||||||
| 512 | } | ||||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | # this needs to be written out before we output the src/dst port (if they are present) | ||||||||||||||||||||||||||||||||||||||||||
| 516 | # otherwise iptables/ip6tables complains at the command. | ||||||||||||||||||||||||||||||||||||||||||
| 517 | 4 | ▶ | $rule_criteria .= sprintf(' -p %s', $self->{proto}) if ( defined($self->{proto}) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | # Source and Destination Ports | ||||||||||||||||||||||||||||||||||||||||||
| 520 | 4 | ▶ | if ( defined($self->{spt}) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | ▶ | if ( $self->{spt} =~ m/\A\w+\z/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 522 | # just a single port | ||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | $rule_criteria .= sprintf(' --sport %s', $self->{'spt'}); | |||||||||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | ▶ | if ( $self->{spt} =~ m/\A\w+(:\w+)+\z/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 526 | # port range | ||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | $rule_criteria .= sprintf(' --sport %s', $self->{'spt'}); | |||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | ▶ | if ( $self->{spt} =~ m/\A\w+(:\w+)+\z/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 530 | # multiport | ||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | $rule_criteria .= sprintf(' -m multiport --sports %s', $self->{'spt'}); | |||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||
| 533 | } | ||||||||||||||||||||||||||||||||||||||||||
| 534 | 4 | ▶ | if ( defined($self->{dpt}) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 535 | 1 | ▶ | if ( $self->{dpt} =~ m/\A\w+\z/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 536 | # just a single port | ||||||||||||||||||||||||||||||||||||||||||
| 537 | 1 | $rule_criteria .= sprintf(' --dport %s', $self->{'dpt'}); | |||||||||||||||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||||||||||||||||
| 539 | 1 | ▶ | if ( $self->{dpt} =~ m/\A\w+(:\w+)+\z/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 540 | # port range | ||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | $rule_criteria .= sprintf(' --dport %s', $self->{'dpt'}); | |||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||
| 543 | 1 | ▶ | if ( $self->{dpt} =~ m/\A\w+(:\w+)+\z/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 544 | # multiport | ||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | $rule_criteria .= sprintf(' -m multiport --dports %s', $self->{'dpt'}); | |||||||||||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||
| 549 | 4 | ▶ | $rule_criteria .= sprintf(' -i %s', $self->{in}) if ( defined($self->{in}) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 550 | 4 | ▶ | $rule_criteria .= sprintf(' -o %s', $self->{out}) if ( defined($self->{out}) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 551 | 4 | ▶ | $rule_criteria .= sprintf(' -m mac --mac-source %s', $self->{mac}) if ( defined($self->{mac}) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 552 | 4 | ▶ | $rule_criteria .= sprintf(' -m conntrack --ctstate %s', $self->{state}) if ( defined($self->{state}) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 553 | 4 | ▶ | $rule_criteria .= sprintf(' --icmp-type %s', $self->{icmp_type}) if ( defined($self->{icmp_type}) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 554 | 4 | ▶ | $rule_criteria .= sprintf(' -m comment --comment "%s"', $self->{comment}) if ( defined($self->{comment}) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 555 | 4 | ▶ | $rule_criteria .= sprintf(' -m limit --limit %s', $self->{limit}) if ( defined($self->{limit}) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 556 | 4 | ▶ | $rule_criteria .= sprintf(' -j %s', $self->{'target'}) if ( defined($self->{'target'}) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 557 | 4 | ▶ | $rule_criteria .= sprintf(' --log-prefix "[%s] "', $self->{logprefix}) if ( defined($self->{logprefix}) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||
| 559 | # $ipt_rule .= sprintf(' -m statistic %s', $criteria{'statistic'}) if (defined($criteria{'statistic'})); | ||||||||||||||||||||||||||||||||||||||||||
| 560 | # $ipt_rule .= sprintf(' -m time %s', $criteria{'time'}) if (defined($criteria{'time'})); | ||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||
| 562 | 4 | my $full_cmd = $rule_prefix.$rule_criteria; | |||||||||||||||||||||||||||||||||||||||||
| 563 | 4 | return $full_cmd; | |||||||||||||||||||||||||||||||||||||||||
| 564 | } | ||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||
| 566 | ############################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 567 | ### INTERNAL HELPERS | ||||||||||||||||||||||||||||||||||||||||||
| 568 | # These are subs that are NOT expected to be used outside this module itself. | ||||||||||||||||||||||||||||||||||||||||||
| 569 | # They are for internal code reuse only. | ||||||||||||||||||||||||||||||||||||||||||
| 570 | # All sub named should be prefixed with double underslash (__) to indicate they | ||||||||||||||||||||||||||||||||||||||||||
| 571 | # are internal use only. | ||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||
| 573 | 4 | ▶ | sub __is_valid_mac_address { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__is_valid_mac_address: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 574 | 4 | my ( $arg ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 575 | 4 | chomp($arg); | |||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||
| 577 | 4 | ▶ | return unless ( $arg ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||
| 579 | 4 | ▶ | if ( $arg =~ m/\A$qr_mac_addr\z/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 580 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||
| 583 | # fail by default | ||||||||||||||||||||||||||||||||||||||||||
| 584 | 3 | return; | |||||||||||||||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||
| 587 | 1 | ▶ | sub __is_valid_inet4 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__is_valid_inet4: called CC=6 SCAR=19.1
| |||||||||||||||||||||||||||||||||||||||||||
| 588 | 1 | my ( $arg ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 589 | 1 | chomp($arg); | |||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||
| 591 | 1 | ▶ | return unless ( $arg ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||
| 593 | # ipv4 address? | ||||||||||||||||||||||||||||||||||||||||||
| 594 | 1 | ▶ | return 1 if ( __is_inet4_host($arg) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||
| 596 | # ipv4 cidr? | ||||||||||||||||||||||||||||||||||||||||||
| 597 | 1 | ▶ | return 1 if ( __is_inet4_cidr($arg) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||
| 599 | # ipv4 range? | ||||||||||||||||||||||||||||||||||||||||||
| 600 | 1 | ▶ | return 1 if ( __is_inet4_range($arg) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||
| 602 | # fqdn? | ||||||||||||||||||||||||||||||||||||||||||
| 603 | 1 | ▶ | return 1 if ( $arg =~ m/\A$qr_fqdn\z/ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||
| 605 | # fail by default | ||||||||||||||||||||||||||||||||||||||||||
| 606 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||
| 609 | 1 | ▶ | sub __is_valid_inet6 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__is_valid_inet6: called CC=6 SCAR=19.1
| |||||||||||||||||||||||||||||||||||||||||||
| 610 | 1 | my ( $arg ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 611 | 1 | chomp($arg); | |||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||
| 613 | 1 | ▶ | return unless ( $arg ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||
| 615 | # ipv6 address? | ||||||||||||||||||||||||||||||||||||||||||
| 616 | 1 | ▶ | return 1 if ( __is_inet6_host($arg) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||
| 618 | # ipv4 cidr? | ||||||||||||||||||||||||||||||||||||||||||
| 619 | 1 | ▶ | return 1 if ( __is_inet6_cidr($arg) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||
| 621 | # ipv4 range? | ||||||||||||||||||||||||||||||||||||||||||
| 622 | 1 | ▶ | return 1 if ( __is_inet6_range($arg) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||
| 624 | # fqdn? | ||||||||||||||||||||||||||||||||||||||||||
| 625 | 1 | ▶ | return 1 if ( $arg =~ m/\A$qr_fqdn\z/ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||
| 627 | # fail by default | ||||||||||||||||||||||||||||||||||||||||||
| 628 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||
| 631 | 33 | ▶ | sub __is_valid_inet_host { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__is_valid_inet_host: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 632 | 33 | my ( $arg ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 633 | 33 | chomp($arg); | |||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||
| 635 | 33 | ▶ | return unless ( $arg ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||||||||||||||||
| 637 | # ipv4 address? | ||||||||||||||||||||||||||||||||||||||||||
| 638 | 33 | ▶ | return 1 if ( __is_inet4_host($arg) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||
| 640 | # ipv6 address? | ||||||||||||||||||||||||||||||||||||||||||
| 641 | 30 | ▶ | return 1 if ( __is_inet6_host($arg) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||
| 643 | # fqdn? | ||||||||||||||||||||||||||||||||||||||||||
| 644 | 26 | ▶ | return 1 if ( $arg =~ m/\A$qr_fqdn\z/ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||||||||
| 646 | # fail by default | ||||||||||||||||||||||||||||||||||||||||||
| 647 | 21 | return; | |||||||||||||||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||
| 650 | 34 | ▶ | sub __is_inet4_host { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__is_inet4_host: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 651 | 34 | my ( $arg ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 652 | 34 | chomp($arg); | |||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||
| 654 | 34 | ▶ | return unless ( $arg ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||
| 656 | # ipv4 address? | ||||||||||||||||||||||||||||||||||||||||||
| 657 | 34 | ▶ | return 1 if ( $arg =~ m/\A$qr_ip4_addr\z/ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||||||||||
| 659 | # fail by default | ||||||||||||||||||||||||||||||||||||||||||
| 660 | 31 | return; | |||||||||||||||||||||||||||||||||||||||||
| 661 | } | ||||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||
| 663 | 31 | ▶ | sub __is_inet6_host { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__is_inet6_host: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 664 | 31 | my ( $arg ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 665 | 31 | chomp($arg); | |||||||||||||||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||||||||||||||||
| 667 | 31 | ▶ | return unless ( $arg ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 668 | |||||||||||||||||||||||||||||||||||||||||||
| 669 | # ipv6 address? | ||||||||||||||||||||||||||||||||||||||||||
| 670 | 31 | ▶ | return 1 if ( $arg =~ m/\A$qr_ip6_addr\z/ ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||
| 672 | # fail by default | ||||||||||||||||||||||||||||||||||||||||||
| 673 | 27 | return; | |||||||||||||||||||||||||||||||||||||||||
| 674 | } | ||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||
| 676 | 21 | ▶ | sub __is_valid_inet_cidr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__is_valid_inet_cidr: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 677 | 21 | my ( $arg ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 678 | 21 | chomp($arg); | |||||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||||||
| 680 | 21 | ▶ | return unless ( $arg ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||
| 682 | # ipv4 cidr? | ||||||||||||||||||||||||||||||||||||||||||
| 683 | 21 | ▶ | return 1 if ( __is_inet4_cidr($arg) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||
| 685 | # ipv6 cidr? | ||||||||||||||||||||||||||||||||||||||||||
| 686 | 19 | ▶ | return 1 if ( __is_inet6_cidr($arg) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||||
| 688 | # fail by default | ||||||||||||||||||||||||||||||||||||||||||
| 689 | 14 | return; | |||||||||||||||||||||||||||||||||||||||||
| 690 | } | ||||||||||||||||||||||||||||||||||||||||||
| 691 | |||||||||||||||||||||||||||||||||||||||||||
| 692 | 22 | ▶ | sub __is_inet4_cidr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__is_inet4_cidr: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||
| 693 | 22 | my ( $arg ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 694 | 22 | chomp($arg); | |||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||
| 696 | 22 | ▶ | return unless ( $arg ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||||||||||||||||
| 698 | # ipv4 cidr? | ||||||||||||||||||||||||||||||||||||||||||
| 699 | 22 | ▶ | if ( $arg =~ m/\A$qr_ip4_cidr\z/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 700 | # validate the cidr | ||||||||||||||||||||||||||||||||||||||||||
| 701 | 4 | my ($host, $cidr) = split(/\//, $arg); | |||||||||||||||||||||||||||||||||||||||||
| 702 | 4 | ▶ | return if ( $cidr < 0 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 703 | 4 | ▶ | return if ( $cidr > 32 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||||
| 705 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||||||||||||
| 708 | # fail by default | ||||||||||||||||||||||||||||||||||||||||||
| 709 | 18 | return; | |||||||||||||||||||||||||||||||||||||||||
| 710 | } | ||||||||||||||||||||||||||||||||||||||||||
| 711 | |||||||||||||||||||||||||||||||||||||||||||
| 712 | 20 | ▶ | sub __is_inet6_cidr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__is_inet6_cidr: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||
| 713 | 20 | my ( $arg ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 714 | 20 | chomp($arg); | |||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||
| 716 | 20 | ▶ | return unless ( $arg ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||
| 718 | # ipv6 cidr? | ||||||||||||||||||||||||||||||||||||||||||
| 719 | 20 | ▶ | if ( $arg =~ m/\A$qr_ip6_cidr\z/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 720 | # validate the cidr | ||||||||||||||||||||||||||||||||||||||||||
| 721 | 9 | my ($host, $cidr) = split(/\//, $arg); | |||||||||||||||||||||||||||||||||||||||||
| 722 | 9 | ▶ | return if ( $cidr < 0 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 723 | 9 | ▶ | return if ( $cidr > 128 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||||||||||||||||
| 725 | 5 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 726 | } | ||||||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||||
| 728 | # fail by default | ||||||||||||||||||||||||||||||||||||||||||
| 729 | 11 | return; | |||||||||||||||||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||||||||||||
| 732 | 14 | ▶ | sub __is_valid_inet_range { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__is_valid_inet_range: called CC=4 SCAR=14.5
| |||||||||||||||||||||||||||||||||||||||||||
| 733 | 14 | my ( $arg ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 734 | 14 | chomp($arg); | |||||||||||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||||||||||||
| 736 | 14 | ▶ | return unless ( $arg ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||
| 738 | # ipv4 address range? | ||||||||||||||||||||||||||||||||||||||||||
| 739 | 14 | ▶ | return 1 if ( __is_inet4_range($arg) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||
| 741 | # ipv6 address range? | ||||||||||||||||||||||||||||||||||||||||||
| 742 | 14 | ▶ | return 1 if ( __is_inet6_range($arg) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 743 | |||||||||||||||||||||||||||||||||||||||||||
| 744 | # fail by default | ||||||||||||||||||||||||||||||||||||||||||
| 745 | 14 | return; | |||||||||||||||||||||||||||||||||||||||||
| 746 | } | ||||||||||||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||||||||||||
| 748 | 15 | ▶ | sub __is_inet4_range { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__is_inet4_range: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||
| 749 | 15 | my ( $arg ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 750 | 15 | chomp($arg); | |||||||||||||||||||||||||||||||||||||||||
| 751 | |||||||||||||||||||||||||||||||||||||||||||
| 752 | 15 | ▶ | return unless ( $arg ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||||
| 754 | # ipv4 address range? | ||||||||||||||||||||||||||||||||||||||||||
| 755 | 15 | ▶ | return 1 if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 756 | $arg =~ m/\A$qr_ip4_addr\-$qr_ip4_addr\z/ | ||||||||||||||||||||||||||||||||||||||||||
| 757 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||||||||||||||||
| 759 | # fail by default | ||||||||||||||||||||||||||||||||||||||||||
| 760 | 15 | return; | |||||||||||||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||||||||||||
| 763 | 15 | ▶ | sub __is_inet6_range { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__is_inet6_range: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||
| 764 | 15 | my ( $arg ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 765 | 15 | chomp($arg); | |||||||||||||||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||||||||||||||||
| 767 | 15 | ▶ | return unless ( $arg ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 768 | |||||||||||||||||||||||||||||||||||||||||||
| 769 | # ipv6 address range? | ||||||||||||||||||||||||||||||||||||||||||
| 770 | 15 | ▶ | return 1 if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 771 | $arg =~ m/\A$qr_ip6_addr\-$qr_ip6_addr\z/ | ||||||||||||||||||||||||||||||||||||||||||
| 772 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||
| 774 | # fail by default | ||||||||||||||||||||||||||||||||||||||||||
| 775 | 15 | return; | |||||||||||||||||||||||||||||||||||||||||
| 776 | } | ||||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||
| 778 | 41 | ▶ | sub __is_valid_inet_port { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__is_valid_inet_port: called CC=19 SCAR=31.7
| |||||||||||||||||||||||||||||||||||||||||||
| 779 | 41 | my ( $arg ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 780 | 41 | chomp($arg); | |||||||||||||||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||||||||||||||||
| 782 | 41 | ▶ | return unless ( $arg ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||
| 784 | # just a numeric port? | ||||||||||||||||||||||||||||||||||||||||||
| 785 | 41 | ▶ | if ( __is_a_number($arg) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 786 | 21 | ▶ | return if ( $arg < 0 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 787 | 21 | ▶ | return if ( $arg > 65535 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||||||
| 789 | 19 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 790 | } | ||||||||||||||||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||||||||||||||||
| 792 | # just a named port? | ||||||||||||||||||||||||||||||||||||||||||
| 793 | 20 | ▶ | if ( $arg =~ m/\A[a-z]+\z/i ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 794 | 6 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 795 | } | ||||||||||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||||||||||
| 797 | # numeric port range? | ||||||||||||||||||||||||||||||||||||||||||
| 798 | 14 | ▶ | if ( $arg =~ /\A\d+:\d+\z/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 799 | 4 | my ( $lower, $upper) = split(/:/, $arg, 2); | |||||||||||||||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||||||||||||||||
| 801 | # recursive call to this sub to validate individal ports in multiport | ||||||||||||||||||||||||||||||||||||||||||
| 802 | 4 | ▶ | return unless ( __is_valid_inet_port($lower) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 803 | 4 | ▶ | return unless ( __is_valid_inet_port($upper) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||||||||||||||||
| 805 | # lower is higher than upper? | ||||||||||||||||||||||||||||||||||||||||||
| 806 | 4 | ▶ | return if ( $upper < $lower ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||||||||||
| 808 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 809 | } | ||||||||||||||||||||||||||||||||||||||||||
| 810 | |||||||||||||||||||||||||||||||||||||||||||
| 811 | # named port range? | ||||||||||||||||||||||||||||||||||||||||||
| 812 | 10 | ▶ | if ( $arg =~ /\A[a-z]+:[a-z]+\z/i ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 813 | 0 | my ( $lower, $upper) = split(/:/, $arg, 2); | |||||||||||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||||||||||||
| 815 | # recursive call to this sub to validate individal ports in multiport | ||||||||||||||||||||||||||||||||||||||||||
| 816 | 0 | ▶ | return unless ( __is_valid_inet_port($lower) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 817 | 0 | ▶ | return unless ( __is_valid_inet_port($upper) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||||||||||||||||
| 819 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 820 | } | ||||||||||||||||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||||||||||||||||
| 822 | # numeric multiport? | ||||||||||||||||||||||||||||||||||||||||||
| 823 | 10 | ▶ | if ( $arg =~ /\A\d+(,\d+)+\z/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 824 | 2 | my @ports = split(/,/, $arg); | |||||||||||||||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||||||||||||||||
| 826 | 2 | foreach my $port ( @ports ) { | |||||||||||||||||||||||||||||||||||||||||
| 827 | # recursive call to this sub to validate individal ports in multiport | ||||||||||||||||||||||||||||||||||||||||||
| 828 | 4 | ▶ | return unless ( __is_valid_inet_port($port) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 829 | } | ||||||||||||||||||||||||||||||||||||||||||
| 830 | |||||||||||||||||||||||||||||||||||||||||||
| 831 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 832 | } | ||||||||||||||||||||||||||||||||||||||||||
| 833 | |||||||||||||||||||||||||||||||||||||||||||
| 834 | # named multiport? | ||||||||||||||||||||||||||||||||||||||||||
| 835 | 8 | ▶ | if ( $arg =~ /\A[a-z]+(,[a-z]+)+\z/i ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 836 | 2 | my @ports = split(/,/, $arg); | |||||||||||||||||||||||||||||||||||||||||
| 837 | |||||||||||||||||||||||||||||||||||||||||||
| 838 | 2 | foreach my $port ( @ports ) { | |||||||||||||||||||||||||||||||||||||||||
| 839 | # recursive call to this sub to validate individal ports in multiport | ||||||||||||||||||||||||||||||||||||||||||
| 840 | 4 | ▶ | return unless ( __is_valid_inet_port($port) ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 841 | } | ||||||||||||||||||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||||||||||||||||
| 843 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 844 | } | ||||||||||||||||||||||||||||||||||||||||||
| 845 | |||||||||||||||||||||||||||||||||||||||||||
| 846 | # fail by default | ||||||||||||||||||||||||||||||||||||||||||
| 847 | 6 | return; | |||||||||||||||||||||||||||||||||||||||||
| 848 | } | ||||||||||||||||||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||||||||||||||||
| 850 | 41 | ▶ | sub __is_a_number { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__is_a_number: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 851 | 41 | my ( $arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 852 | 41 | ▶ | return 1 if ( $arg =~ /\A-?\d+\z/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 853 | 20 | return; | |||||||||||||||||||||||||||||||||||||||||
| 854 | } | ||||||||||||||||||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||||||||||||||||
| 856 | 55 | ▶ | sub __errstr { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__errstr: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 857 | 55 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 858 | 55 | my $errstr = shift; | |||||||||||||||||||||||||||||||||||||||||
| 859 | 55 | $self->{errstr} = $errstr; | |||||||||||||||||||||||||||||||||||||||||
| 860 | 55 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 861 | } | ||||||||||||||||||||||||||||||||||||||||||
| 862 | |||||||||||||||||||||||||||||||||||||||||||
| 863 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 864 | __END__ | ||||||||||||||||||||||||||||||||||||||||||