BlockerHelper/backends/linux_ip_route.pm

filter: Statementstmt 52.9% 171 / 323 Branchbran 46.2% 61 / 132 Conditioncond 66.6% 22 / 33 MC/DCmcdc 33.3% 6 / 18 Subroutinesub 95.0% 19 / 20 Podpod 100% 13 / 13 totaltotal 54.1% 292 / 539 CC 88 SCAR 31.8
CC
88
Cov
52%
unban
41.3
ban_cidr
37.2
unban_cidr
37.2
CRAP 24.1
« BlockerHelper/backends/aws_wafv2.pm ↑ Summary BlockerHelper/backends/npf.pm »
1 package Net::Firewall::BlockerHelper::backends::linux_ip_route;
2  
3 1 ▶use 5.006;
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 1 ▶use base qw( Error::Helper Net::Firewall::BlockerHelper::Util );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Regexp::IPv4 qw($IPv4_re);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Regexp::IPv6 qw($IPv6_re);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 =head1 NAME
11  
12 Net::Firewall::BlockerHelper::backends::linux_ip_route - Blackhole route backend for Net::Firewall::BlockerHelper.
13  
14 =head1 VERSION
15  
16 Version 0.2.0
17  
18 =cut
19  
20 1 our $VERSION = '0.2.0';
21  
22 =head1 SYNOPSIS
23  
24 use Net::Firewall::BlockerHelper;
25  
26 my $fw_helper = Net::Firewall::BlockerHelper->new(
27 backend => 'linux_ip_route',
28 name => 'ssh',
29 );
30  
31 $fw_helper->init_backend;
32 $fw_helper->ban(ban => '1.2.3.4');
33 $fw_helper->unban(ban => '1.2.3.4');
34 $fw_helper->teardown;
35  
36 =head1 DESCRIPTION
37  
38 Blocks whole IPs via null routes using L<ip(8)> from iproute2. Fast for very
39 large numbers of blocked IPs and requires no firewall at all, making it a
40 good fallback. The routes are destination based, so what is directly stopped
41 is traffic headed back to the banned IP, which is enough to keep connections
42 from completing. For the inbound packets themselves to be dropped as well,
43 reverse path filtering, rp_filter, needs to be enabled, in which case they
44 are tossed at the route lookup before entering any firewall chains.
45  
46 Blocking is per IP and never per service; ports and protocols are not
47 supported and specifying them is an error.
48  
49 check verifies the route for each currently banned IP is still present, so
50 externally flushed routes are noticed and self-heal can re-add them.
51 teardown deletes the route for each banned IP, tolerating already-removed
52 routes, and keeps the internal list of bans so re_init can re-add them.
53  
54 =head1 NOTES
55  
56 check looks for a ban's route using the type selector, for example
57 C<ip route show type unreachable 192.0.2.4>. A missing route is reported
58 by iproute2 as a zero exit with no output, which is what check keys off
59 of.
60  
61 CIDR ranges must be passed with the host bits zeroed, such as
62 C<192.0.2.0/24>. iproute2 rejects prefixes with host bits set, such as
63 C<192.0.2.4/24>, with "Invalid prefix for given prefix length", which will
64 show up as a banCidrFailed error.
65  
66 =head1 METHODS
67  
68 =head2 new
69  
70 Initiates the the object.
71  
72 - options :: Backend specific options that will be passed to the backend unchecked
73 outside of making sure it is a hash ref if defined. See below for furhter info.
74 - Default :: {}
75  
76 - prefix :: Prefix to use. Must match the regex /^[a-zA-Z0-9]+$/
77 - default :: kur
78  
79 - name :: Name of this specific instance. This must be specified.
80 - default :: undef
81  
82 Ports and protocols are not supported by this backend and specifying either
83 is an error.
84  
85 The options hash accepts the following.
86  
87 - blocktype :: The route type to use. 'blackhole' silently drops while
88 'unreachable' and 'prohibit' send the corresponding ICMP reject
89 back. See ip-route(8).
90 - Default :: unreachable
91  
92 All errors are considered fatal, meaning if new fails it will die.
93  
94 =cut
95  
96 5 ▶sub new {
Subroutine new: called CC=21 SCAR=34.0
Pod documented
97 5 my ( $blank, %opts ) = @_;
98  
99 5 my $self = {
100 perror => undef,
101 error => undef,
102 errorLine => undef,
103 errorFilename => undef,
104 errorString => "",
105 errorExtra => {
106 all_errors_fatal => 1,
107 # all_fatal is what Error::Helper 2.1.0 actually checks; all_errors_fatal
108 # is kept for the name documented in its POD
109 all_fatal => 1,
110 flags => {
111 1 => 'notInited',
112 6 => 'invalidPrefixSpecified',
113 7 => 'invalidName',
114 8 => 'optionsNotHash',
115 9 => 'noBanItem',
116 10 => 'banItemNotIP',
117 12 => 'backendInitError',
118 13 => 'banFailed',
119 14 => 'unbanFailed',
120 15 => 'listFailed',
121 16 => 'reInitFailed',
122 17 => 'teardownFailed',
123 18 => 'alreadyInited',
124 20 => 'blocktypeInvalid',
125 23 => 'initFailed',
126 24 => 'checkFailed',
127 25 => 'flushFailed',
128 26 => 'portsNotSupported',
129 27 => 'protocolsNotSupported',
130 28 => 'banCidrFailed',
131 29 => 'unbanCidrFailed',
132 30 => 'cidrItemNotCidr',
133 31 => 'cidrNotSupported',
134 32 => 'listCidrFailed',
135 },
136 fatal_flags => {},
137 perror_not_fatal => 0,
138 },
139 options => {
140 blocktype => 'unreachable',
141 },
142 ports => [],
143 protocols => [],
144 testing => undef,
145 test_data => undef,
146 prefix => 'kur',
147 frontend_obj => undef,
148 inited => 0,
149 banned => {},
150 banned_cidr => {},
151 cidr_supported => 1,
152 };
153 5 bless $self;
154  
155 # blocking is per IP; ports and protocols can not be expressed via routes
156 5 ▶ if ( defined( $opts{ports} ) && ref( $opts{ports} ) eq 'ARRAY' && defined( $opts{ports}[0] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"ports"} and ref $opts{"ports"} eq "ARRAY" and defined $opts{"ports"}[0]) 1 4 5
Condition83%5/6
defined $opts{"ports"} and ref $opts{"ports"} eq "ARRAY" and defined $opts{"ports"}[0]
!ll&&!rl&&r
221
defined $opts{"ports"} and ref $opts{"ports"} eq "ARRAY"
!ll&&!rl&&r
203
MC/DC66%2/3
defined $opts{"ports"} and ref $opts{"ports"} eq "ARRAY" and defined $opts{"ports"}[0]
defined $opts{"ports"} ref $opts{"ports"} eq "ARRAY" defined $opts{"ports"}[0]
Truth table75%3/4
A and B and C
A= defined $opts{"ports"}B= ref $opts{"ports"} eq "ARRAY"C= defined $opts{"ports"}[0]
ABCresult
0XX0
10X0
1100
1111
157 1 $self->{perror} = 1;
158 1 $self->{error} = 26;
159 1 $self->{errorString} = 'the route backend blocks whole IPs and does not support ports';
160 1 $self->warn;
161 }
162 4 ▶ if ( defined( $opts{protocols} ) && ref( $opts{protocols} ) eq 'ARRAY' && defined( $opts{protocols}[0] ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"protocols"} and ref $opts{"protocols"} eq "ARRAY" and defined $opts{"protocols"}[0]) 1 3 4
Condition83%5/6
defined $opts{"protocols"} and ref $opts{"protocols"} eq "ARRAY" and defined $opts{"protocols"}[0]
!ll&&!rl&&r
121
defined $opts{"protocols"} and ref $opts{"protocols"} eq "ARRAY"
!ll&&!rl&&r
103
MC/DC66%2/3
defined $opts{"protocols"} and ref $opts{"protocols"} eq "ARRAY" and defined $opts{"protocols"}[0]
defined $opts{"protocols"} ref $opts{"protocols"} eq "ARRAY" defined $opts{"protocols"}[0]
Truth table75%3/4
A and B and C
A= defined $opts{"protocols"}B= ref $opts{"protocols"} eq "ARRAY"C= defined $opts{"protocols"}[0]
ABCresult
0XX0
10X0
1100
1111
163 1 $self->{perror} = 1;
164 1 $self->{error} = 27;
165 1 $self->{errorString} = 'the route backend blocks whole IPs and does not support protocols';
166 1 $self->warn;
167 }
168  
169 # make sure prefix is sane if defiend
170 3 ▶ if ( defined( $opts{prefix} ) && $opts{prefix} !~ /^[a-zA-Z0-9]+$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $opts{'prefix'} and not $opts{'prefix'} =~ /^[a-zA-Z0-9]+$/) { } 0 3 3
elsif (defined $opts{'prefix'}) { } 2 1 3
Condition66%2/3
defined $opts{"prefix"} and not $opts{"prefix"} =~ /^[a-zA-Z0-9]+$/
!ll&&!rl&&r
120
MC/DC0%0/2
defined $opts{"prefix"} and not $opts{"prefix"} =~ /^[a-zA-Z0-9]+$/
defined $opts{"prefix"} not $opts{"prefix"} =~ /^[a-zA-Z0-9]+$/
Truth table66%2/3
A and not(B)
A= defined $opts{"prefix"}B= not $opts{"prefix"} =~ /^[a-zA-Z0-9]+$/
ABresult
0X0
100
111
171 0 $self->{perror} = 1;
172 0 $self->{error} = 6;
173 $self->{errorString}
174 0 = '"' . $opts{prefix} . '" is not a valid prefix as it does not match the regex /^[a-zA-Z0-9]+$/';
175 0 $self->warn;
176 } elsif ( defined( $opts{prefix} ) ) {
177 2 $self->{prefix} = $opts{prefix};
178 }
179  
180 # make sure we have a name and that it is valid
181 3 ▶ if ( !defined( $opts{name} ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $opts{'name'}) { } 0 3 3
elsif (not $opts{'name'} =~ /^[a-zA-Z0-9\-]+$/) { } 0 3 3
182 0 $self->{perror} = 1;
183 0 $self->{error} = 7;
184 0 $self->{errorString} = 'name is undef';
185 0 $self->warn;
186 } elsif ( $opts{name} !~ /^[a-zA-Z0-9\-]+$/ ) {
187 0 $self->{perror} = 1;
188 0 $self->{error} = 7;
189 0 $self->{errorString} = 'name set to "' . $opts{name} . '" which does not match the regexp /^[a-zA-Z0-9\-]+$/';
190 0 $self->warn;
191 }
192 3 $self->{name} = $opts{name};
193  
194 # used internally for testing
195 3 ▶ if ( defined( $opts{testing} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"testing"}) 2 1 3
196 2 $self->{testing} = $opts{testing};
197 }
198 3 ▶ if ( defined( $opts{frontend_obj} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"frontend_obj"}) 2 1 3
199 2 $self->{frontend_obj} = $opts{frontend_obj};
200 }
201  
202 3 ▶ if ( defined( $opts{options} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"options"}) 3 0 3
203 3 ▶ if ( ref( $opts{options} ) ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $opts{"options"} ne "HASH") 0 3 3
204 0 $self->{perror} = 1;
205 0 $self->{error} = 8;
206 0 $self->{errorString} = 'ref for options is "' . ref( $opts{options} ) . '" and not HASH';
207 0 $self->warn;
208 }
209 3 $self->{options} = $opts{options};
210  
211 3 ▶ if ( defined( $opts{options}{blocktype} )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $opts{'options'}{'blocktype'} and $opts{'options'}{'blocktype'} ne 'unreachable' and $opts{'options'}{'blocktype'} ne 'blackhole' and $opts{'options'}{'blocktype'} ne 'prohibit') { } 1 2 3
elsif (not defined $opts{'options'}{'blocktype'}) { } 1 1 2
Condition77%7/9
defined $opts{"options"}{"blocktype"} and $opts{"options"}{"blocktype"} ne "unreachable" and $opts{"options"}{"blocktype"} ne "blackhole" and $opts{"options"}{"blocktype"} ne "prohibit"
!ll&&!rl&&r
201
defined $opts{"options"}{"blocktype"} and $opts{"options"}{"blocktype"} ne "unreachable" and $opts{"options"}{"blocktype"} ne "blackhole"
!ll&&!rl&&r
111
defined $opts{"options"}{"blocktype"} and $opts{"options"}{"blocktype"} ne "unreachable"
!ll&&!rl&&r
102
MC/DC50%2/4
defined $opts{"options"}{"blocktype"} and $opts{"options"}{"blocktype"} ne "unreachable" and $opts{"options"}{"blocktype"} ne "blackhole" and $opts{"options"}{"blocktype"} ne "prohibit"
defined $opts{"options"}{"blocktype"} $opts{"options"}{"blocktype"} ne "unreachable" $opts{"options"}{"blocktype"} ne "blackhole" $opts{"options"}{"blocktype"} ne "prohibit"
Truth table60%3/5
A and B and C and D
A= defined $opts{"options"}{"blocktype"}B= $opts{"options"}{"blocktype"} ne "unreachable"C= $opts{"options"}{"blocktype"} ne "blackhole"D= $opts{"options"}{"blocktype"} ne "prohibit"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
212 && $opts{options}{blocktype} ne 'unreachable'
213 && $opts{options}{blocktype} ne 'blackhole'
214 && $opts{options}{blocktype} ne 'prohibit' )
215 {
216 1 $self->{perror} = 1;
217 1 $self->{error} = 20;
218 $self->{errorString}
219 = '$opts{options}{blocktype} is "'
220 . $opts{options}{blocktype}
221 1 . '" and not "unreachable", "blackhole", or "prohibit"';
222 1 $self->warn;
223 } elsif ( !defined( $opts{options}{blocktype} ) ) {
224 1 $self->{options}{blocktype} = 'unreachable';
225 }
226 } ## end if ( defined( $opts{options} ) )
227  
228 2 return $self;
229 } ## end sub new
230  
231 # Internal helper. Returns the iproute2 command for adding, removing, or
232 # looking up the null route that blocks the passed IP. Every command this
233 # backend runs comes from here.
234 #
235 # The family is chosen per IP rather than per instance, since a single
236 # instance bans both. IPv4 gets no flag, as that is iproute2's default, and
237 # IPv6 gets -6.
238 #
239 # The route type is placed differently depending on the action, which is the
240 # one subtlety worth knowing about. For add and del the type is part of the
241 # route specification and is written bare, immediately before the address. For
242 # show it is a filter on which routes to list rather than part of a spec, and
243 # iproute2 only accepts it there behind the literal "type" keyword. Writing it
244 # bare for show would be a syntax error, and writing "type" for add would be
245 # too.
246 #
247 # Note this only ever builds the command; running it and interpreting the exit
248 # status is the caller's job.
249 #
250 # Args:
251 #
252 # action - The iproute2 route subcommand, as a plain string. One of 'add'
253 # to install the null route, 'del' to remove it, or 'show' to
254 # look it up, which is what check and list use to see whether a
255 # ban is still in place. Anything else is passed through
256 # unchecked and would produce an invalid command.
257 #
258 # ip - The address to route, as a plain string. Expected to be an
259 # already validated and lowercased IPv4 or IPv6 address. The
260 # family is decided by matching against $IPv4_re, so anything
261 # that is not valid IPv4 is treated as IPv6.
262 #
263 # Returns the command as a single string ready to hand to the runner. The
264 # route type comes from the blocktype option, which is 'unreachable' by
265 # default and may also be 'blackhole' or 'prohibit'; the three differ in what,
266 # if anything, is sent back to the sender.
267 #
268 # $self->_route_command( 'add', '10.0.0.1' );
269 # # ip route add unreachable 10.0.0.1
270 #
271 # $self->_route_command( 'del', '2001:db8::1' );
272 # # ip -6 route del unreachable 2001:db8::1
273 #
274 # # show puts the type behind the type keyword
275 # $self->_route_command( 'show', '10.0.0.1' );
276 # # ip route show type unreachable 10.0.0.1
277 #
278 # # with blocktype set to blackhole
279 # $self->_route_command( 'add', '10.0.0.1' );
280 # # ip route add blackhole 10.0.0.1
281 17 ▶sub _route_command {
Subroutine _route_command: called CC=3 SCAR=11.0
282 17 my ( $self, $action, $ip ) = @_;
283  
284 17 ▶ my $family = ( $ip =~ /\A$IPv4_re\z/ ) ? '' : ' -6';
Branch: 1 branch
BranchTrueFalseTotal
$ip =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv4_re\z/ ? : 7 10 17
285 17 ▶ my $type = ( $action eq 'show' ) ? 'type ' : '';
Branch: 1 branch
BranchTrueFalseTotal
$action eq 'show' ? : 9 8 17
286  
287 17 return 'ip' . $family . ' route ' . $action . ' ' . $type . $self->{options}{blocktype} . ' ' . $ip;
288 }
289  
290 =head2 init
291  
292 Initiates the backend. Null routes need no setup, so no commands are run.
293  
294 $backend->init;
295  
296 =cut
297  
298 4 ▶sub init {
Subroutine init: called CC=3 SCAR=12.6
Pod documented
299 4 my ( $self, %opts ) = @_;
300  
301 4 $self->errorblank;
302  
303 4 ▶ if ( $self->{inited} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"inited"}) 0 4 4
304 0 $self->{error} = 18;
305 0 $self->{errorString} = 'backend has already been inited';
306 0 $self->warn;
307 }
308  
309 4 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"testing"}) 4 0 4
310 4 $self->{frontend_obj}->{test_data} = 'inited';
311 }
312  
313 4 $self->{inited} = 1;
314 } ## end sub init
315  
316 =head2 ban
317  
318 Bans an IP. The value of ban is validated as being a IPv4 or IPv6 address
319 and lowercased, then a route of the configured C<blocktype> is added for it
320 via C<ip route add> (C<ip -6 route add> for IPv6). Banning an already
321 banned IP is a noop.
322  
323 $backend->ban(ban => $ip);
324  
325 =cut
326  
327 4 ▶sub ban {
Subroutine ban: called CC=10 SCAR=33.4
Pod documented
328 4 my ( $self, %opts ) = @_;
329  
330 4 $self->errorblank;
331  
332 4 ▶ if ( !$self->{inited} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"inited"}) 0 4 4
333 0 $self->{error} = 1;
334 0 $self->{errorString} = 'backend has not been inited';
335 0 $self->warn;
336 0 return;
337 }
338  
339 4 ▶ if ( !defined( $opts{ban} ) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $opts{'ban'}) { } 0 4 4
elsif (ref $opts{'ban'} ne '') { } 0 4 4
elsif (not $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv6_re\z/) { } 0 4 4
340 0 $self->{error} = 9;
341 0 $self->{errorString} = 'Nothing specified for the value ban';
342 0 $self->warn;
343 0 return;
344 } elsif ( ref( $opts{ban} ) ne '' ) {
345 0 $self->{error} = 10;
346 0 $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"';
347 0 $self->warn;
348 0 return;
349 ▶ } elsif ( $opts{ban} !~ /\A$IPv4_re\z/
Condition66%2/3
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv6_re\z/
l!l&&r!l&&!r
310
MC/DC0%0/2
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv6_re\z/
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv4_re\z/ $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv6_re\z/
Truth table66%2/3
A || B
A= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv4_re\z/B= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv6_re\z/
ABresult
1X1
011
000
350 && $opts{ban} !~ /\A$IPv6_re\z/ )
351 {
352 0 $self->{error} = 10;
353 0 $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 IP';
354 0 $self->warn;
355 0 return;
356 }
357  
358 # lowercase so the same IPv6 IP in differing cases can't result in duplicate entries
359 4 $opts{ban} = lc( $opts{ban} );
360  
361 4 ▶ if ( $self->{banned}{ $opts{ban} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"banned"}{$opts{"ban"}}) 1 3 4
362 1 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"testing"}) 1 0 1
363 1 $self->{frontend_obj}->{test_data} = 'already banned';
364 }
365 1 return;
366 }
367  
368 3 my $command = $self->_route_command( 'add', $opts{ban} );
369  
370 3 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'testing'}) { } 3 0 3
371 3 $self->{frontend_obj}->{test_data} = [$command];
372 } else {
373 0 my $output = `$command 2>&1`;
374 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
375 0 $self->{error} = 13;
376 $self->{errorString}
377 0 = 'ban failed. non-zero exit code for the command... "' . $command . '"... output... ' . $output;
378 0 $self->warn;
379 }
380 }
381  
382 3 $self->{banned}{ $opts{ban} } = 1;
383 } ## end sub ban
384  
385 =head2 unban
386  
387 Unbans an IP. The value of ban is validated as being a IPv4 or IPv6 address
388 and lowercased, then its route is removed via C<ip route del>
389 (C<ip -6 route del> for IPv6). Unbanning an IP that is not banned is a
390 noop.
391  
392 $backend->unban(ban => $ip);
393  
394 =cut
395  
396 1 ▶sub unban {
Subroutine unban: called CC=10 SCAR=37.2
Pod documented
397 1 my ( $self, %opts ) = @_;
398  
399 1 $self->errorblank;
400  
401 1 ▶ if ( !$self->{inited} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"inited"}) 0 1 1
402 0 $self->{error} = 1;
403 0 $self->{errorString} = 'backend has not been inited';
404 0 $self->warn;
405 0 return;
406 }
407  
408 1 ▶ if ( !defined( $opts{ban} ) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $opts{'ban'}) { } 0 1 1
elsif (ref $opts{'ban'} ne '') { } 0 1 1
elsif (not $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv6_re\z/) { } 0 1 1
409 0 $self->{error} = 9;
410 0 $self->{errorString} = 'Nothing specified for the value ban';
411 0 $self->warn;
412 0 return;
413 } elsif ( ref( $opts{ban} ) ne '' ) {
414 0 $self->{error} = 10;
415 0 $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"';
416 0 $self->warn;
417 0 return;
418 ▶ } elsif ( $opts{ban} !~ /\A$IPv4_re\z/
Condition33%1/3
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv6_re\z/
l!l&&r!l&&!r
100
MC/DC0%0/2
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv6_re\z/
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv4_re\z/ $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv6_re\z/
Truth table33%1/3
A || B
A= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv4_re\z/B= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv6_re\z/
ABresult
1X1
011
000
419 && $opts{ban} !~ /\A$IPv6_re\z/ )
420 {
421 0 $self->{error} = 10;
422 0 $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 IP';
423 0 $self->warn;
424 0 return;
425 }
426  
427 # lowercase so the same IPv6 IP in differing cases can't result in duplicate entries
428 1 $opts{ban} = lc( $opts{ban} );
429  
430 1 ▶ if ( !$self->{banned}{ $opts{ban} } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"banned"}{$opts{"ban"}}) 0 1 1
431 0 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"testing"}) 0 0 0
432 0 $self->{frontend_obj}->{test_data} = 'not banned';
433 }
434 0 return;
435 }
436  
437 1 my $command = $self->_route_command( 'del', $opts{ban} );
438  
439 1 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'testing'}) { } 1 0 1
440 1 $self->{frontend_obj}->{test_data} = $command;
441 } else {
442 0 my $output = `$command 2>&1`;
443 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
444 0 $self->{error} = 14;
445 $self->{errorString}
446 0 = 'unban failed. non-zero exit code for the command... "' . $command . '"... output... ' . $output;
447 0 $self->warn;
448 }
449 }
450  
451 1 delete( $self->{banned}{ $opts{ban} } );
452 } ## end sub unban
453  
454 =head2 ban_cidr
455  
456 Bans a CIDR range by adding a route of the configured C<blocktype> for it
457 via C<ip route add>, the same way a single IP is handled. The value of ban
458 is validated as being a IPv4 or IPv6 CIDR range and lowercased. Banning an
459 already banned range is a noop.
460  
461 $backend->ban_cidr(ban => '1.2.3.0/24');
462  
463 =cut
464  
465 1 ▶sub ban_cidr {
Subroutine ban_cidr: called CC=10 SCAR=36.2
Pod documented
466 1 my ( $self, %opts ) = @_;
467  
468 1 $self->errorblank;
469  
470 1 ▶ if ( !$self->{inited} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"inited"}) 0 1 1
471 0 $self->{error} = 1;
472 0 $self->{errorString} = 'backend has not been inited';
473 0 $self->warn;
474 0 return;
475 }
476  
477 1 ▶ if ( !defined( $opts{ban} ) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $opts{'ban'}) { } 0 1 1
elsif (ref $opts{'ban'} ne '') { } 0 1 1
elsif (not $self->_valid_cidr($opts{'ban'})) { } 0 1 1
478 0 $self->{error} = 9;
479 0 $self->{errorString} = 'Nothing specified for the value ban';
480 0 $self->warn;
481 0 return;
482 } elsif ( ref( $opts{ban} ) ne '' ) {
483 0 $self->{error} = 30;
484 0 $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"';
485 0 $self->warn;
486 0 return;
487 } elsif ( !$self->_valid_cidr( $opts{ban} ) ) {
488 0 $self->{error} = 30;
489 0 $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 CIDR';
490 0 $self->warn;
491 0 return;
492 }
493  
494 # lowercase so the same IPv6 CIDR in differing cases can't result in duplicate entries
495 1 $opts{ban} = lc( $opts{ban} );
496  
497 1 ▶ if ( $self->{banned_cidr}{ $opts{ban} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"banned_cidr"}{$opts{"ban"}}) 0 1 1
498 0 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"testing"}) 0 0 0
499 0 $self->{frontend_obj}->{test_data} = 'already banned';
500 }
501 0 return;
502 }
503  
504 # _route_command detects the family from the whole string, which a CIDR
505 # would break, so the family is taken from the address portion here
506 1 my ($addr) = ( $opts{ban} =~ m!\A(.+)/[0-9]+\z! );
507 1 ▶ my $family = ( $addr =~ /\A$IPv4_re\z/ ) ? '' : ' -6';
Branch: 1 branch
BranchTrueFalseTotal
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv4_re\z/ ? : 1 0 1
508 1 my $command = 'ip' . $family . ' route add ' . $self->{options}{blocktype} . ' ' . $opts{ban};
509  
510 1 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'testing'}) { } 1 0 1
511 1 $self->{frontend_obj}->{test_data} = [$command];
512 } else {
513 0 my $output = `$command 2>&1`;
514 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
515 0 $self->{error} = 28;
516 $self->{errorString}
517 0 = 'ban failed. non-zero exit code for the command... "' . $command . '"... output... ' . $output;
518 0 $self->warn;
519 }
520 }
521  
522 1 $self->{banned_cidr}{ $opts{ban} } = 1;
523 } ## end sub ban_cidr
524  
525 =head2 unban_cidr
526  
527 Unbans a CIDR range by deleting its route via C<ip route del>. The value of
528 ban is validated as being a IPv4 or IPv6 CIDR range and lowercased.
529 Unbanning a range that is not banned is a noop.
530  
531 $backend->unban_cidr(ban => '1.2.3.0/24');
532  
533 =cut
534  
535 1 ▶sub unban_cidr {
Subroutine unban_cidr: called CC=10 SCAR=36.2
Pod documented
536 1 my ( $self, %opts ) = @_;
537  
538 1 $self->errorblank;
539  
540 1 ▶ if ( !$self->{inited} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"inited"}) 0 1 1
541 0 $self->{error} = 1;
542 0 $self->{errorString} = 'backend has not been inited';
543 0 $self->warn;
544 0 return;
545 }
546  
547 1 ▶ if ( !defined( $opts{ban} ) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $opts{'ban'}) { } 0 1 1
elsif (ref $opts{'ban'} ne '') { } 0 1 1
elsif (not $self->_valid_cidr($opts{'ban'})) { } 0 1 1
548 0 $self->{error} = 9;
549 0 $self->{errorString} = 'Nothing specified for the value ban';
550 0 $self->warn;
551 0 return;
552 } elsif ( ref( $opts{ban} ) ne '' ) {
553 0 $self->{error} = 30;
554 0 $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"';
555 0 $self->warn;
556 0 return;
557 } elsif ( !$self->_valid_cidr( $opts{ban} ) ) {
558 0 $self->{error} = 30;
559 0 $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 CIDR';
560 0 $self->warn;
561 0 return;
562 }
563  
564 # lowercase so the same IPv6 CIDR in differing cases can't result in duplicate entries
565 1 $opts{ban} = lc( $opts{ban} );
566  
567 1 ▶ if ( !$self->{banned_cidr}{ $opts{ban} } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"banned_cidr"}{$opts{"ban"}}) 0 1 1
568 0 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"testing"}) 0 0 0
569 0 $self->{frontend_obj}->{test_data} = 'not banned';
570 }
571 0 return;
572 }
573  
574 # _route_command detects the family from the whole string, which a CIDR
575 # would break, so the family is taken from the address portion here
576 1 my ($addr) = ( $opts{ban} =~ m!\A(.+)/[0-9]+\z! );
577 1 ▶ my $family = ( $addr =~ /\A$IPv4_re\z/ ) ? '' : ' -6';
Branch: 1 branch
BranchTrueFalseTotal
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv4_re\z/ ? : 1 0 1
578 1 my $command = 'ip' . $family . ' route del ' . $self->{options}{blocktype} . ' ' . $opts{ban};
579  
580 1 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'testing'}) { } 1 0 1
581 1 $self->{frontend_obj}->{test_data} = $command;
582 } else {
583 0 my $output = `$command 2>&1`;
584 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
585 0 $self->{error} = 29;
586 $self->{errorString}
587 0 = 'unban failed. non-zero exit code for the command... "' . $command . '"... output... ' . $output;
588 0 $self->warn;
589 }
590 }
591  
592 1 delete( $self->{banned_cidr}{ $opts{ban} } );
593 } ## end sub unban_cidr
594  
595 =head2 list_cidr
596  
597 List banned CIDR ranges. Returns an array of the currently banned CIDR
598 ranges. Single IPs are not included; for those see L</list>.
599  
600 my @banned_cidrs = $backend->list_cidr;
601  
602 =cut
603  
604 2 ▶sub list_cidr {
Subroutine list_cidr: called CC=2 SCAR=7.0
Pod documented
605 2 my ( $self, %opts ) = @_;
606  
607 2 $self->errorblank;
608  
609 2 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"testing"}) 2 0 2
610 2 $self->{frontend_obj}->{test_data} = 'list_cidr';
611 }
612  
613 2 return keys( %{ $self->{banned_cidr} } );
614 }
615  
616 =head2 list
617  
618 List banned IPs. Returns an array of the currently banned single IPs. CIDR
619 ranges are not included; for those see L</list_cidr>.
620  
621 my @banned = $backend->list;
622  
623 =cut
624  
625 2 ▶sub list {
Subroutine list: called CC=2 SCAR=7.0
Pod documented
626 2 my ( $self, %opts ) = @_;
627  
628 2 $self->errorblank;
629  
630 2 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"testing"}) 2 0 2
631 2 $self->{frontend_obj}->{test_data} = 'list';
632 }
633  
634 2 return keys( %{ $self->{banned} } );
635 }
636  
637 =head2 re_init
638  
639 Tells the backend to re-init it's self.
640  
641 This will call teardown and init again. After that it will
642 re-added all previously added bans.
643  
644 $backend->re_init;
645  
646 =cut
647  
648 1 ▶sub re_init {
Subroutine re_init: called CC=9 SCAR=30.9
Pod documented
649 1 my ( $self, %opts ) = @_;
650  
651 1 $self->errorblank;
652  
653 # teardown is best effort here as a partially or fully wiped setup is
654 # exactly what re_init needs to recover from; init cleans up any remnants
655 {
656 1 local $@;
657 1 eval { $self->teardown; };
658 }
659 1 $self->init;
660  
661 1 my @to_ban = keys( %{ $self->{banned} } );
662  
663 1 my @re_init_test_data;
664 1 foreach my $item (@to_ban) {
665 1 my $command = $self->_route_command( 'add', $item );
666  
667 1 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'testing'}) { } 1 0 1
668 1 push( @re_init_test_data, $command );
669 } else {
670 0 my $output = `$command 2>&1`;
671 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
672 0 $self->{error} = 13;
673 $self->{errorString}
674 0 = 'ban failed. non-zero exit code for the command... "' . $command . '"... output... ' . $output;
675 0 $self->warn;
676 }
677 }
678 } ## end foreach my $item (@to_ban)
679  
680 # CIDR ranges are re-added the same way, but the family must be taken from
681 # the address portion as _route_command can not detect it from a CIDR
682 1 foreach my $item ( keys( %{ $self->{banned_cidr} } ) ) {
683 0 my ($addr) = ( $item =~ m!\A(.+)/[0-9]+\z! );
684 0 ▶ my $family = ( $addr =~ /\A$IPv4_re\z/ ) ? '' : ' -6';
Branch: 1 branch
BranchTrueFalseTotal
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv4_re\z/ ? : 0 0 0
685 0 my $command = 'ip' . $family . ' route add ' . $self->{options}{blocktype} . ' ' . $item;
686  
687 0 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'testing'}) { } 0 0 0
688 0 push( @re_init_test_data, $command );
689 } else {
690 0 my $output = `$command 2>&1`;
691 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
692 0 $self->{error} = 28;
693 $self->{errorString}
694 0 = 'ban failed. non-zero exit code for the command... "' . $command . '"... output... ' . $output;
695 0 $self->warn;
696 }
697 }
698 } ## end foreach my $item ( keys( %{ $self->{banned_cidr}...}))
699  
700 1 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"testing"}) 1 0 1
701 1 $self->{frontend_obj}->{test_data} = \@re_init_test_data;
702 }
703  
704 1 $self->{inited} = 1;
705 } ## end sub re_init
706  
707 =head2 teardown
708  
709 Tears down the setup for the backend by deleting the route for each
710 currently banned IP. Routes that were already removed externally are
711 tolerated, so re_init works after an external wipe. The internal list of
712 bans is kept, so a following re_init will re-add them.
713  
714 $backend->teardown;
715  
716 =cut
717  
718 2 ▶sub teardown {
Subroutine teardown: called CC=6 SCAR=21.2
Pod documented
719 2 my ( $self, %opts ) = @_;
720  
721 2 $self->errorblank;
722  
723 2 $self->{inited} = 0;
724  
725 2 my @commands;
726 2 foreach my $item ( keys( %{ $self->{banned} } ) ) {
727 2 push( @commands, $self->_route_command( 'del', $item ) );
728 }
729  
730 # CIDR ranges are removed the same way, but the family must be taken from
731 # the address portion as _route_command can not detect it from a CIDR
732 2 foreach my $item ( keys( %{ $self->{banned_cidr} } ) ) {
733 0 my ($addr) = ( $item =~ m!\A(.+)/[0-9]+\z! );
734 0 ▶ my $family = ( $addr =~ /\A$IPv4_re\z/ ) ? '' : ' -6';
Branch: 1 branch
BranchTrueFalseTotal
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv4_re\z/ ? : 0 0 0
735 0 push( @commands, 'ip' . $family . ' route del ' . $self->{options}{blocktype} . ' ' . $item );
736 }
737  
738 2 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'testing'}) { } 2 0 2
739 2 $self->{frontend_obj}->{test_data} = \@commands;
740 } else {
741 # failures are tolerated as the route may already have been removed
742 # externally, which is exactly what re_init recovers from
743 0 foreach my $item (@commands) {
744 0 my $output = `$item 2>&1`;
745 }
746 }
747 } ## end sub teardown
748  
749 =head2 stop
750  
751 Alias for L</teardown>, provided for parity with the fail2ban C<actionstop>
752 concept.
753  
754 $backend->stop;
755  
756 =cut
757  
758 0 ▶sub stop {
Subroutine stop: not called CC=1 SCAR=6.9
Pod documented
759 0 my ( $self, %opts ) = @_;
760  
761 0 return $self->teardown(%opts);
762 }
763  
764 =head2 check
765  
766 Verifies the route for each currently banned single IP is still present.
767 Returns a true value if they all are and a false value if any are missing.
768 Routes for banned CIDR ranges are not checked. This is the equivalent of
769 fail2ban's C<actioncheck>.
770  
771 if ( !$backend->check ) {
772 $backend->re_init;
773 }
774  
775 =cut
776  
777 8 ▶sub check {
Subroutine check: called CC=6 SCAR=24.1
Pod documented
778 8 my ( $self, %opts ) = @_;
779  
780 8 $self->errorblank;
781  
782 8 my @commands;
783 8 foreach my $item ( sort( keys( %{ $self->{banned} } ) ) ) {
784 9 push( @commands, $self->_route_command( 'show', $item ) );
785 }
786  
787 8 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"testing"}) 8 0 8
788 8 $self->{frontend_obj}->{test_data} = \@commands;
789 8 return 1;
790 }
791  
792 0 foreach my $item (@commands) {
793 0 my $output = `$item 2>&1`;
794 # ip route show exits zero even when nothing matches, so a missing
795 # route shows up as a lack of output rather than a non-zero exit
796 0 ▶ if ( $? != 0 || $output !~ /\S/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0 or not $output =~ /\S/) 0 0 0
Condition0%0/3
$? != 0 or not $output =~ /\S/
l!l&&r!l&&!r
000
MC/DC0%0/2
$? != 0 or not $output =~ /\S/
$? != 0 not $output =~ /\S/
Truth table0%0/3
A or not(B)
A= $? != 0B= not $output =~ /\S/
ABresult
1X1
011
000
797 0 return 0;
798 }
799 }
800  
801 0 return 1;
802 } ## end sub check
803  
804 =head2 flush
805  
806 Removes all currently banned IPs at once by deleting their routes and
807 forgetting them. This is the equivalent of fail2ban's C<actionflush>.
808  
809 $backend->flush;
810  
811 =cut
812  
813 1 ▶sub flush {
Subroutine flush: called CC=8 SCAR=29.5
Pod documented
814 1 my ( $self, %opts ) = @_;
815  
816 1 $self->errorblank;
817  
818 1 ▶ if ( !$self->{inited} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"inited"}) 0 1 1
819 0 $self->{error} = 1;
820 0 $self->{errorString} = 'backend has not been inited';
821 0 $self->warn;
822 0 return;
823 }
824  
825 1 my @commands;
826 1 foreach my $item ( keys( %{ $self->{banned} } ) ) {
827 1 push( @commands, $self->_route_command( 'del', $item ) );
828 }
829  
830 # CIDR ranges are removed the same way, but the family must be taken from
831 # the address portion as _route_command can not detect it from a CIDR
832 1 foreach my $item ( keys( %{ $self->{banned_cidr} } ) ) {
833 0 my ($addr) = ( $item =~ m!\A(.+)/[0-9]+\z! );
834 0 ▶ my $family = ( $addr =~ /\A$IPv4_re\z/ ) ? '' : ' -6';
Branch: 1 branch
BranchTrueFalseTotal
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv4_re\z/ ? : 0 0 0
835 0 push( @commands, 'ip' . $family . ' route del ' . $self->{options}{blocktype} . ' ' . $item );
836 }
837  
838 1 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'testing'}) { } 1 0 1
839 1 $self->{frontend_obj}->{test_data} = \@commands;
840 } else {
841 0 foreach my $item (@commands) {
842 0 my $output = `$item 2>&1`;
843 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
844 0 $self->{error} = 25;
845 $self->{errorString}
846 0 = 'flush failed. non-zero exit code for the command... "' . $item . '"... output... ' . $output;
847 0 $self->warn;
848 }
849 }
850 } ## end else [ if ( $self->{testing} ) ]
851  
852 1 $self->{banned} = {};
853 1 $self->{banned_cidr} = {};
854 } ## end sub flush
855  
856 =head1 ERROR CODES / FLAGS
857  
858 Error handling is provided by L<Error::Helper>. All
859 errors are considered fatal.
860  
861 =head2 1, notInited
862  
863 The backend has not been inited yet.
864  
865 =head2 6, invalidPrefixSpecified
866  
867 The specified prefix did not match /^[a-zA-Z0-9]+$/.
868  
869 =head2 7, invalidName
870  
871 The name is either undef or does not match /^[a-zA-Z0-9\-]+$/.
872  
873 =head2 8, optionsNotHash
874  
875 The item passed to new for options is not a hash.
876  
877 =head2 9, noBanItem
878  
879 No IP or CIDR range specified to ban or unban.
880  
881 =head2 10, banItemNotIP
882  
883 The item to ban is not an IP. Either wrong ref type or regexp
884 test using L<Regexp::IPv4> and L<Regexp::IPv6> failed.
885  
886 =head2 12, backendInitError
887  
888 Failed to init the backend.
889  
890 =head2 13, banFailed
891  
892 Failed to ban the item.
893  
894 =head2 14, unbanFailed
895  
896 Failed to unban the item.
897  
898 =head2 15, listFailed
899  
900 Failed to get a list of bans.
901  
902 =head2 16, reInitFailed
903  
904 Failed to re_init the backend.
905  
906 =head2 17, teardownFailed
907  
908 Failed to teardown the backend.
909  
910 =head2 18, alreadyInited
911  
912 init called, but the backend has already been inited.
913  
914 =head2 20, blocktypeInvalid
915  
916 The option blocktype is not "unreachable", "blackhole", or "prohibit".
917  
918 =head2 23, initFailed
919  
920 One of the required commands for init failed.
921  
922 =head2 24, checkFailed
923  
924 The backend check raised an error.
925  
926 =head2 25, flushFailed
927  
928 Failed to flush the bans.
929  
930 =head2 26, portsNotSupported
931  
932 Ports were specified, but the backend does not support ports.
933  
934 =head2 27, protocolsNotSupported
935  
936 Protocols were specified, but the backend does not support protocols.
937  
938 =head2 28, banCidrFailed
939  
940 Failed to ban the CIDR range.
941  
942 =head2 29, unbanCidrFailed
943  
944 Failed to unban the CIDR range.
945  
946 =head2 30, cidrItemNotCidr
947  
948 The item to ban is not a CIDR range. Either wrong ref type or it is not an
949 IPv4 or IPv6 address followed by a prefix length valid for its family.
950  
951 =head2 31, cidrNotSupported
952  
953 The backend does not support CIDR bans.
954  
955 =head2 32, listCidrFailed
956  
957 Failed to get a list of CIDR bans.
958  
959 =head1 AUTHOR
960  
961 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.ent> >>
962  
963 =head1 BUGS
964  
965 Please report any bugs or feature requests to C<bug-net-firewall-blockerhelper at rt.cpan.org>, or through
966 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Firewall-BlockerHelper>.
967  
968 =head1 LICENSE AND COPYRIGHT
969  
970 This software is Copyright (c) 2023 by Zane C. Bowers-Hadley.
971  
972 This is free software, licensed under:
973  
974 The GNU Lesser General Public License, Version 2.1, February 1999
975  
976  
977 =cut
978  
979 1 1; # End of Net::Firewall::BlockerHelper
« BlockerHelper/backends/aws_wafv2.pm ↑ Summary BlockerHelper/backends/npf.pm »