BlockerHelper/backends/shorewall.pm

filter: Statementstmt 38.1% 131 / 343 Branchbran 33.7% 50 / 148 Conditioncond 50.0% 12 / 24 MC/DCmcdc 18.7% 3 / 16 Subroutinesub 81.8% 18 / 22 Podpod 100% 13 / 13 totaltotal 40.1% 227 / 566 CC 94 SCAR 37.6
CC
94
Cov
37%
re_init
132.0
flush
72.0
teardown
56.0
CRAP 42.9
« BlockerHelper/backends/juniper_srx.pm ↑ Summary BlockerHelper/backends/pfsense.pm »
1 package Net::Firewall::BlockerHelper::backends::shorewall;
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 'Error::Helper';
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::shorewall - Shorewall backend for Net::Firewall::BlockerHelper.
13  
14 =head1 VERSION
15  
16 Version 0.1.0
17  
18 =cut
19  
20 1 our $VERSION = '0.1.0';
21  
22 =head1 SYNOPSIS
23  
24 use Net::Firewall::BlockerHelper;
25  
26 my $fw_helper;
27 eval {
28 $fw_helper = Net::Firewall::BlockerHelper->new(
29 backend => 'shorewall',
30 name => 'derp',
31 options => {
32 type => 'drop',
33 },
34 );
35 };
36 if ($@) {
37 print 'Error: '
38 . $Error::Helper::error
39 . "\nError String: "
40 . $Error::Helper::errorString
41 . "\nError Flag: "
42 . $Error::Helper::errorFlag . "\n";
43 }
44  
45 $fw_helper->init_backend;
46  
47 $fw_helper->ban(ban => '5.6.7.8');
48 $fw_helper->ban(ban => '1.2.3.4');
49  
50 $fw_helper->unban(ban => '5.6.7.8');
51  
52 $fw_helper->teardown;
53  
54 =head1 DESCRIPTION
55  
56 This backend blocks IPs using Shorewall's dynamic blacklisting via the
57 L<shorewall(8)> and L<shorewall6(8)> commands. IPv4 addresses are handled
58 by the C<shorewall> command and IPv6 addresses by the C<shorewall6>
59 command.
60  
61 Dynamic blacklisting is part of Shorewall itself, so there is nothing to
62 create at init time. Banning an IP is a matter of running
63 C<< shorewall <type> <ip> >> and unbanning is a matter of running
64 C<< shorewall allow <ip> >>.
65  
66 This does require the firewall to actually be in the started state and
67 DYNAMIC_BLACKLIST to not have been set to C<No> in L<shorewall.conf(5)>. It
68 is enabled by default, so unless it has been explicitly disabled there is
69 nothing to configure.
70  
71 Requires C<shorewall> and, for IPv6 support, C<shorewall6> to be installed
72 and in the C<PATH> of the process, which must have sufficient privileges to
73 run them.
74  
75 =head1 METHODS
76  
77 =head2 new
78  
79 Initiates the the object.
80  
81 - options :: A hash of options to pass to the backend. See below for further info.
82 Default :: {}
83  
84 - ports :: Not used by this backend but accepted for parity with the others.
85 Default :: []
86  
87 - protocols :: Not used by this backend but accepted for parity with the others.
88 Default :: []
89  
90 - prefix :: Prefix to use.
91 Default :: kur
92  
93 - name :: Name of this specific instance.
94 Default :: undef
95  
96 The options hash accepts the following.
97  
98 - shorewall_cmd :: Path to the shorewall binary, used for IPv4 addresses.
99 Default :: shorewall
100  
101 - shorewall6_cmd :: Path to the shorewall6 binary, used for IPv6 addresses.
102 Default :: shorewall6
103  
104 - type :: The block method to use. One of 'drop' or 'reject'.
105 - drop :: Silently drop the packet.
106 - reject :: Send an ICMP port-unreachable back.
107 Default :: drop
108  
109 All errors are considered fatal, meaning if new fails it will die.
110  
111 my $fw_helper;
112 eval {
113 $fw_helper = Net::Firewall::BlockerHelper->new(
114 backend => 'shorewall',
115 name => 'ssh',
116 options => { type => 'drop' },
117 );
118 };
119 if ($@) {
120 print 'Error: '
121 . $Error::Helper::error
122 . "\nError String: "
123 . $Error::Helper::errorString
124 . "\nError Flag: "
125 . $Error::Helper::errorFlag . "\n";
126 }
127  
128 =cut
129  
130 sub new {
131 3 ▶ my ( $blank, %opts ) = @_;
Subroutine new: called CC=14 SCAR=31.2
Pod documented
132  
133 3 my $self = {
134 perror => undef,
135 error => undef,
136 errorLine => undef,
137 errorFilename => undef,
138 errorString => "",
139 errorExtra => {
140 all_errors_fatal => 1,
141 # all_fatal is what Error::Helper 2.1.0 actually checks; all_errors_fatal
142 # is kept for the name documented in its POD
143 all_fatal => 1,
144 flags => {
145 1 => 'notInited',
146 8 => 'optionsNotHash',
147 9 => 'noBanItem',
148 10 => 'banItemNotIP',
149 12 => 'backendInitError',
150 13 => 'banFailed',
151 14 => 'unbanFailed',
152 15 => 'listFailed',
153 16 => 'reInitFailed',
154 17 => 'teardownFailed',
155 18 => 'alreadyInited',
156 20 => 'typeInvalid',
157 24 => 'checkFailed',
158 25 => 'flushFailed',
159 26 => 'banCidrFailed',
160 27 => 'unbanCidrFailed',
161 28 => 'cidrItemNotCidr',
162 29 => 'cidrNotSupported',
163 30 => 'listCidrFailed',
164 },
165 fatal_flags => {},
166 perror_not_fatal => 0,
167 },
168 options => {
169 shorewall_cmd => 'shorewall',
170 shorewall6_cmd => 'shorewall6',
171 type => 'drop',
172 },
173 ports => [],
174 protocols => [],
175 testing => undef,
176 test_data => undef,
177 prefix => 'kur',
178 name => undef,
179 frontend_obj => undef,
180 inited => 0,
181 banned => {},
182 banned_cidr => {},
183 cidr_supported => 1,
184 };
185 3 bless $self;
186  
187 3 ▶ if ( defined( $opts{prefix} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"prefix"}) 3 0 3
188 3 $self->{prefix} = $opts{prefix};
189 }
190  
191 3 ▶ if ( defined( $opts{name} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"name"}) 3 0 3
192 3 $self->{name} = $opts{name};
193 }
194  
195 # used internally for testing
196 3 ▶ if ( defined( $opts{testing} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"testing"}) 3 0 3
197 3 $self->{testing} = $opts{testing};
198 }
199 3 ▶ if ( defined( $opts{frontend_obj} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"frontend_obj"}) 3 0 3
200 3 $self->{frontend_obj} = $opts{frontend_obj};
201 }
202  
203 3 ▶ if ( defined( $opts{options} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"options"}) 3 0 3
204 3 ▶ if ( ref( $opts{options} ) ne 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $opts{"options"} ne "HASH") 0 3 3
205 0 $self->{perror} = 1;
206 0 $self->{error} = 8;
207 0 $self->{errorString} = 'ref for options is "' . ref( $opts{options} ) . '" and not HASH';
208 0 $self->warn;
209 }
210 3 $self->{options} = $opts{options};
211  
212 3 ▶ if ( !defined( $opts{options}{shorewall_cmd} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts{"options"}{"shorewall_cmd"}) 3 0 3
213 3 $self->{options}{shorewall_cmd} = 'shorewall';
214 }
215 3 ▶ if ( !defined( $opts{options}{shorewall6_cmd} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $opts{"options"}{"shorewall6_cmd"}) 3 0 3
216 3 $self->{options}{shorewall6_cmd} = 'shorewall6';
217 }
218  
219 3 my %valid_types = ( drop => 1, reject => 1 );
220  
221 3 ▶ if ( defined( $opts{options}{type} ) && ref( $opts{options}{type} ) ne '' ) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $opts{'options'}{'type'} and ref $opts{'options'}{'type'} ne '') { } 0 3 3
elsif (defined $opts{'options'}{'type'} and not $valid_types{$opts{'options'}{'type'}}) { } 1 2 3
elsif (not defined $opts{'options'}{'type'}) { } 0 2 2
Condition33%1/3
defined $opts{"options"}{"type"} and ref $opts{"options"}{"type"} ne ""
!ll&&!rl&&r
030
MC/DC0%0/2
defined $opts{"options"}{"type"} and ref $opts{"options"}{"type"} ne ""
defined $opts{"options"}{"type"} ref $opts{"options"}{"type"} ne ""
Truth table33%1/3
A and B
A= defined $opts{"options"}{"type"}B= ref $opts{"options"}{"type"} ne ""
ABresult
0X0
100
111
222 0 $self->{perror} = 1;
223 0 $self->{error} = 20;
224 0 $self->{errorString} = 'ref for $opts{options}{type} is "' . ref( $opts{options}{type} ) . '" and not ""';
225 0 $self->warn;
226 ▶ } elsif ( defined( $opts{options}{type} )
Condition66%2/3
defined $opts{"options"}{"type"} and not $valid_types{$opts{"options"}{"type"}}
!ll&&!rl&&r
021
MC/DC50%1/2
defined $opts{"options"}{"type"} and not $valid_types{$opts{"options"}{"type"}}
defined $opts{"options"}{"type"} not $valid_types{$opts{"options"}{"type"}}
Truth table66%2/3
A and not(B)
A= defined $opts{"options"}{"type"}B= not $valid_types{$opts{"options"}{"type"}}
ABresult
0X0
100
111
227 && !$valid_types{ $opts{options}{type} } )
228 {
229 1 $self->{perror} = 1;
230 1 $self->{error} = 20;
231 $self->{errorString}
232 1 = '$opts{options}{type} is "' . $opts{options}{type} . '" and not one of "drop" or "reject"';
233 1 $self->warn;
234 } elsif ( !defined( $opts{options}{type} ) ) {
235 0 $self->{options}{type} = 'drop';
236 }
237 } ## end if ( defined( $opts{options} ) )
238  
239 2 return $self;
240 } ## end sub new
241  
242 # Internal helper. Returns the shorewall command to use for the passed IP,
243 # picking shorewall_cmd for IPv4 addresses and shorewall6_cmd for IPv6
244 # addresses.
245 sub _cmd_for {
246 10 ▶ my ( $self, $ip ) = @_;
Subroutine _cmd_for: called CC=2 SCAR=6.9
247  
248 10 ▶ if ( $ip =~ /\A$IPv4_re\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ip =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv4_re\z/) 5 5 10
249 5 return $self->{options}{shorewall_cmd};
250 }
251 5 return $self->{options}{shorewall6_cmd};
252 }
253  
254 =head2 init
255  
256 Initiates the backend.
257  
258 Dynamic blacklisting is part of Shorewall itself, so there is nothing to
259 create.
260  
261 Note that for bans to have an effect the firewall must be started and
262 DYNAMIC_BLACKLIST must not have been disabled in shorewall.conf. See
263 L</DESCRIPTION>.
264  
265 No arguments are taken.
266  
267 May called a second time, it will error.
268  
269 $backend->init;
270  
271 =cut
272  
273 sub init {
274 2 ▶ my ( $self, %opts ) = @_;
Subroutine init: called CC=3 SCAR=12.3
Pod documented
275  
276 2 $self->errorblank;
277  
278 2 ▶ if ( $self->{inited} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"inited"}) 0 2 2
279 0 $self->{error} = 18;
280 0 $self->{errorString} = 'backend has already been inited';
281 0 $self->warn;
282 }
283  
284 # dynamic blacklisting is always available, so there are no commands to run
285 2 my @commands;
286  
287 2 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"testing"}) 2 0 2
288 2 $self->{frontend_obj}->{test_data} = \@commands;
289 }
290  
291 2 $self->{inited} = 1;
292 } ## end sub init
293  
294 =head2 ban
295  
296 Bans an IP. The value of ban is validated as being a IPv4 or IPv6 address
297 and lowercased, then C<< shorewall <type> <ip> >> is run, using
298 C<shorewall6> for IPv6 addresses. Banning an already banned IP is a noop.
299  
300 $fw_helper->ban(ban => $ip);
301  
302 =cut
303  
304 sub ban {
305 3 ▶ my ( $self, %opts ) = @_;
Subroutine ban: called CC=11 SCAR=39.1
Pod documented
306  
307 3 $self->errorblank;
308  
309 3 ▶ if ( !$self->{inited} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"inited"}) 0 3 3
310 0 $self->{error} = 1;
311 0 $self->{errorString} = 'backend has not been inited';
312 0 $self->warn;
313 0 return;
314 }
315  
316 3 ▶ if ( !defined( $opts{ban} ) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $opts{'ban'}) { } 0 3 3
elsif (ref $opts{'ban'} ne '') { } 0 3 3
elsif (not $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv6_re\z/) { } 0 3 3
317 0 $self->{error} = 9;
318 0 $self->{errorString} = 'Nothing specified for the value ban';
319 0 $self->warn;
320 0 return;
321 } elsif ( ref( $opts{ban} ) ne '' ) {
322 0 $self->{error} = 10;
323 0 $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"';
324 0 $self->warn;
325 0 return;
326 ▶ } elsif ( $opts{ban} !~ /\A$IPv4_re\z/
Condition66%2/3
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv6_re\z/
l!l&&r!l&&!r
210
MC/DC0%0/2
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv6_re\z/
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv4_re\z/ $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv6_re\z/
Truth table66%2/3
A || B
A= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv4_re\z/B= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv6_re\z/
ABresult
1X1
011
000
327 && $opts{ban} !~ /\A$IPv6_re\z/ )
328 {
329 0 $self->{error} = 10;
330 0 $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 IP';
331 0 $self->warn;
332 0 return;
333 }
334  
335 # lowercase so the same IPv6 IP in differing cases can't result in duplicate entries
336 3 $opts{ban} = lc( $opts{ban} );
337  
338 3 ▶ if ( $self->{banned}{ $opts{ban} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"banned"}{$opts{"ban"}}) 0 3 3
339 0 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"testing"}) 0 0 0
340 0 $self->{frontend_obj}->{test_data} = 'already banned';
341 }
342 0 return;
343 }
344  
345 3 my $command = $self->_cmd_for( $opts{ban} ) . ' ' . $self->{options}{type} . ' ' . $opts{ban};
346  
347 3 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'testing'}) { } 3 0 3
348 3 $self->{frontend_obj}->{test_data} = $command;
349 } else {
350 0 my $output = `$command 2>&1`;
351 # backticks give undef when the command could not be executed at all
352 0 ▶ if ( !defined($output) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $output) 0 0 0
353 0 $output = 'no output, the command could not be executed... ' . $!;
354 }
355 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
356 0 $self->{error} = 13;
357 $self->{errorString}
358 0 = 'ban failed. non-zero exit code for the command... "' . $command . '"... output... ' . $output;
359 0 $self->warn;
360 }
361 }
362  
363 3 $self->{banned}{ $opts{ban} } = 1;
364 } ## end sub ban
365  
366 =head2 unban
367  
368 Unbans an IP. The value of ban is validated as being a IPv4 or IPv6 address
369 and lowercased, then C<< shorewall allow <ip> >> is run, using C<shorewall6>
370 for IPv6 addresses. Unbanning an IP that is not banned is a noop.
371  
372 $fw_helper->unban(ban => $ip);
373  
374 =cut
375  
376 sub unban {
377 1 ▶ my ( $self, %opts ) = @_;
Subroutine unban: called CC=11 SCAR=39.7
Pod documented
378  
379 1 $self->errorblank;
380  
381 1 ▶ if ( !$self->{inited} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"inited"}) 0 1 1
382 0 $self->{error} = 1;
383 0 $self->{errorString} = 'backend has not been inited';
384 0 $self->warn;
385 0 return;
386 }
387  
388 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::shorewall::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv6_re\z/) { } 0 1 1
389 0 $self->{error} = 9;
390 0 $self->{errorString} = 'Nothing specified for the value ban';
391 0 $self->warn;
392 0 return;
393 } elsif ( ref( $opts{ban} ) ne '' ) {
394 0 $self->{error} = 10;
395 0 $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"';
396 0 $self->warn;
397 0 return;
398 ▶ } elsif ( $opts{ban} !~ /\A$IPv4_re\z/
Condition33%1/3
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv6_re\z/
l!l&&r!l&&!r
100
MC/DC0%0/2
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv4_re\z/ || $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv6_re\z/
$opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv4_re\z/ $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv6_re\z/
Truth table33%1/3
A || B
A= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv4_re\z/B= $opts{'ban'} =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv6_re\z/
ABresult
1X1
011
000
399 && $opts{ban} !~ /\A$IPv6_re\z/ )
400 {
401 0 $self->{error} = 10;
402 0 $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 IP';
403 0 $self->warn;
404 0 return;
405 }
406  
407 # lowercase so the same IPv6 IP in differing cases can't result in duplicate entries
408 1 $opts{ban} = lc( $opts{ban} );
409  
410 1 ▶ if ( !$self->{banned}{ $opts{ban} } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"banned"}{$opts{"ban"}}) 0 1 1
411 0 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"testing"}) 0 0 0
412 0 $self->{frontend_obj}->{test_data} = 'not banned';
413 }
414 0 return;
415 }
416  
417 1 my $command = $self->_cmd_for( $opts{ban} ) . ' allow ' . $opts{ban};
418  
419 1 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'testing'}) { } 1 0 1
420 1 $self->{frontend_obj}->{test_data} = $command;
421 } else {
422 0 my $output = `$command 2>&1`;
423 # backticks give undef when the command could not be executed at all
424 0 ▶ if ( !defined($output) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $output) 0 0 0
425 0 $output = 'no output, the command could not be executed... ' . $!;
426 }
427 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
428 0 $self->{error} = 14;
429 $self->{errorString}
430 0 = 'unban failed. non-zero exit code for the command... "' . $command . '"... output... ' . $output;
431 0 $self->warn;
432 }
433 }
434  
435 1 delete( $self->{banned}{ $opts{ban} } );
436 } ## end sub unban
437  
438 # Internal helper. Returns a true value if the passed scalar is a valid IPv4 or
439 # IPv6 CIDR range, that is an address followed by "/" and a prefix length that
440 # is within the range valid for its family (0 to 32 for IPv4, 0 to 128 for
441 # IPv6). Returns false otherwise.
442 sub _valid_cidr {
443 3 ▶ my ( $self, $cidr ) = @_;
Subroutine _valid_cidr: called CC=8 SCAR=24.3
444  
445 3 ▶ return 0 if ( !defined($cidr) || ref($cidr) ne '' );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $cidr or ref $cidr ne "" 0 3 3
Condition33%1/3
not defined $cidr or ref $cidr ne ""
l!l&&r!l&&!r
003
MC/DC0%0/2
not defined $cidr or ref $cidr ne ""
not defined $cidr ref $cidr ne ""
Truth table33%1/3
not(A) or B
A= not defined $cidrB= ref $cidr ne ""
ABresult
1X1
011
000
446  
447 3 ▶ if ( $cidr =~ m!\A(.+)/([0-9]{1,3})\z! ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cidr =~ m[\A(.+)/([0-9]{1,3})\z]) 3 0 3
448 3 my ( $addr, $prefix ) = ( $1, $2 );
449 3 ▶ return 1 if ( $addr =~ /\A$IPv4_re\z/ && $prefix <= 32 );
Branch: 1 branch
BranchTrueFalseTotal
if $addr =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv4_re\z/ and $prefix <= 32 2 1 3
Condition66%2/3
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv4_re\z/ and $prefix <= 32
!ll&&!rl&&r
102
MC/DC50%1/2
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv4_re\z/ and $prefix <= 32
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv4_re\z/ $prefix <= 32
Truth table66%2/3
A and B
A= $addr =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv4_re\z/B= $prefix <= 32
ABresult
0X0
100
111
450 1 ▶ return 1 if ( $addr =~ /\A$IPv6_re\z/ && $prefix <= 128 );
Branch: 1 branch
BranchTrueFalseTotal
if $addr =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv6_re\z/ and $prefix <= 128 1 0 1
Condition33%1/3
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv6_re\z/ and $prefix <= 128
!ll&&!rl&&r
001
MC/DC0%0/2
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv6_re\z/ and $prefix <= 128
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv6_re\z/ $prefix <= 128
Truth table33%1/3
A and B
A= $addr =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv6_re\z/B= $prefix <= 128
ABresult
0X0
100
111
451 }
452  
453 0 return 0;
454 } ## end sub _valid_cidr
455  
456 =head2 ban_cidr
457  
458 Bans a CIDR range. Shorewall's dynamic blacklisting accepts a network prefix
459 in the same manner as a single address, so this runs
460 C<< shorewall <type> <cidr> >>, using C<shorewall6> for IPv6 ranges. The
461 value of ban is validated as being a IPv4 or IPv6 CIDR range and lowercased.
462 Banning an already banned range is a noop.
463  
464 $fw_helper->ban_cidr(ban => '1.2.3.0/24');
465  
466 =cut
467  
468 sub ban_cidr {
469 2 ▶ my ( $self, %opts ) = @_;
Subroutine ban_cidr: called CC=10 SCAR=38.0
Pod documented
470  
471 2 $self->errorblank;
472  
473 2 ▶ if ( !$self->{inited} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"inited"}) 0 2 2
474 0 $self->{error} = 1;
475 0 $self->{errorString} = 'backend has not been inited';
476 0 $self->warn;
477 0 return;
478 }
479  
480 2 ▶ if ( !defined( $opts{ban} ) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $opts{'ban'}) { } 0 2 2
elsif (ref $opts{'ban'} ne '') { } 0 2 2
elsif (not $self->_valid_cidr($opts{'ban'})) { } 0 2 2
481 0 $self->{error} = 9;
482 0 $self->{errorString} = 'Nothing specified for the value ban';
483 0 $self->warn;
484 0 return;
485 } elsif ( ref( $opts{ban} ) ne '' ) {
486 0 $self->{error} = 28;
487 0 $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"';
488 0 $self->warn;
489 0 return;
490 } elsif ( !$self->_valid_cidr( $opts{ban} ) ) {
491 0 $self->{error} = 28;
492 0 $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 CIDR';
493 0 $self->warn;
494 0 return;
495 }
496  
497 # lowercase so the same IPv6 CIDR in differing cases can't result in duplicate entries
498 2 $opts{ban} = lc( $opts{ban} );
499  
500 2 ▶ if ( $self->{banned_cidr}{ $opts{ban} } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"banned_cidr"}{$opts{"ban"}}) 0 2 2
501 0 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"testing"}) 0 0 0
502 0 $self->{frontend_obj}->{test_data} = 'already banned';
503 }
504 0 return;
505 }
506  
507 2 my $command = $self->_cmd_for_cidr( $opts{ban} ) . ' ' . $self->{options}{type} . ' ' . $opts{ban};
508  
509 2 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'testing'}) { } 2 0 2
510 2 $self->{frontend_obj}->{test_data} = $command;
511 } else {
512 0 my $output = `$command 2>&1`;
513 # backticks give undef when the command could not be executed at all
514 0 ▶ if ( !defined($output) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $output) 0 0 0
515 0 $output = 'no output, the command could not be executed... ' . $!;
516 }
517 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
518 0 $self->{error} = 26;
519 $self->{errorString}
520 0 = 'ban failed. non-zero exit code for the command... "' . $command . '"... output... ' . $output;
521 0 $self->warn;
522 }
523 }
524  
525 2 $self->{banned_cidr}{ $opts{ban} } = 1;
526 } ## end sub ban_cidr
527  
528 =head2 unban_cidr
529  
530 Unbans a CIDR range by running C<< shorewall allow <cidr> >>, using
531 C<shorewall6> for IPv6 ranges. The value of ban is validated as being a
532 IPv4 or IPv6 CIDR range and lowercased. Unbanning a range that is not
533 banned is a noop.
534  
535 $fw_helper->unban_cidr(ban => '1.2.3.0/24');
536  
537 =cut
538  
539 sub unban_cidr {
540 1 ▶ my ( $self, %opts ) = @_;
Subroutine unban_cidr: called CC=10 SCAR=38.0
Pod documented
541  
542 1 $self->errorblank;
543  
544 1 ▶ if ( !$self->{inited} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"inited"}) 0 1 1
545 0 $self->{error} = 1;
546 0 $self->{errorString} = 'backend has not been inited';
547 0 $self->warn;
548 0 return;
549 }
550  
551 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
552 0 $self->{error} = 9;
553 0 $self->{errorString} = 'Nothing specified for the value ban';
554 0 $self->warn;
555 0 return;
556 } elsif ( ref( $opts{ban} ) ne '' ) {
557 0 $self->{error} = 28;
558 0 $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"';
559 0 $self->warn;
560 0 return;
561 } elsif ( !$self->_valid_cidr( $opts{ban} ) ) {
562 0 $self->{error} = 28;
563 0 $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 CIDR';
564 0 $self->warn;
565 0 return;
566 }
567  
568 # lowercase so the same IPv6 CIDR in differing cases can't result in duplicate entries
569 1 $opts{ban} = lc( $opts{ban} );
570  
571 1 ▶ if ( !$self->{banned_cidr}{ $opts{ban} } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"banned_cidr"}{$opts{"ban"}}) 0 1 1
572 0 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"testing"}) 0 0 0
573 0 $self->{frontend_obj}->{test_data} = 'not banned';
574 }
575 0 return;
576 }
577  
578 1 my $command = $self->_cmd_for_cidr( $opts{ban} ) . ' allow ' . $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 # backticks give undef when the command could not be executed at all
585 0 ▶ if ( !defined($output) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $output) 0 0 0
586 0 $output = 'no output, the command could not be executed... ' . $!;
587 }
588 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
589 0 $self->{error} = 27;
590 $self->{errorString}
591 0 = 'unban failed. non-zero exit code for the command... "' . $command . '"... output... ' . $output;
592 0 $self->warn;
593 }
594 }
595  
596 1 delete( $self->{banned_cidr}{ $opts{ban} } );
597 } ## end sub unban_cidr
598  
599 # Internal helper. Like _cmd_for but for a CIDR range, picking
600 # shorewall_cmd for IPv4 ranges and shorewall6_cmd for IPv6 ranges based
601 # on the address portion of the range.
602 sub _cmd_for_cidr {
603 6 ▶ my ( $self, $cidr ) = @_;
Subroutine _cmd_for_cidr: called CC=3 SCAR=11.0
604  
605 6 ▶ if ( $cidr =~ m!\A(.+)/[0-9]{1,3}\z! && $1 =~ /\A$IPv4_re\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cidr =~ m[\A(.+)/[0-9]{1,3}\z] and $1 =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv4_re\z/) 4 2 6
Condition66%2/3
$cidr =~ m[\A(.+)/[0-9]{1,3}\z] and $1 =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv4_re\z/
!ll&&!rl&&r
024
MC/DC50%1/2
$cidr =~ m[\A(.+)/[0-9]{1,3}\z] and $1 =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv4_re\z/
$cidr =~ m[\A(.+)/[0-9]{1,3}\z] $1 =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv4_re\z/
Truth table66%2/3
A and B
A= $cidr =~ m[\A(.+)/[0-9]{1,3}\z]B= $1 =~ /\A$Net::Firewall::BlockerHelper::backends::shorewall::IPv4_re\z/
ABresult
0X0
100
111
606 4 return $self->{options}{shorewall_cmd};
607 }
608 2 return $self->{options}{shorewall6_cmd};
609 }
610  
611 =head2 list_cidr
612  
613 List banned CIDR ranges. Returns an array of the currently banned CIDR
614 ranges. Single IPs are not included; for those see L</list>.
615  
616 my @banned_cidrs = $fw_helper->list_cidr;
617  
618 =cut
619  
620 sub list_cidr {
621 2 ▶ my ( $self, %opts ) = @_;
Subroutine list_cidr: called CC=2 SCAR=7.0
Pod documented
622  
623 2 $self->errorblank;
624  
625 2 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"testing"}) 2 0 2
626 2 $self->{frontend_obj}->{test_data} = 'list_cidr';
627 }
628  
629 2 return keys( %{ $self->{banned_cidr} } );
630 }
631  
632 =head2 list
633  
634 List banned IPs. Returns an array of the currently banned single IPs. CIDR
635 ranges are not included; for those see L</list_cidr>.
636  
637 my @banned = $fw_helper->list;
638  
639 =cut
640  
641 sub list {
642 2 ▶ my ( $self, %opts ) = @_;
Subroutine list: called CC=2 SCAR=7.0
Pod documented
643  
644 2 $self->errorblank;
645  
646 2 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"testing"}) 2 0 2
647 2 $self->{frontend_obj}->{test_data} = 'list';
648 }
649  
650 2 return keys( %{ $self->{banned} } );
651 }
652  
653 =head2 re_init
654  
655 Tells the backend to re-init it's self.
656  
657 This will call teardown and init again. After that it will
658 re-add all previously added bans.
659  
660 $fw_helper->re_init;
661  
662 =cut
663  
664 sub re_init {
665 0 ▶ my ( $self, %opts ) = @_;
Subroutine re_init: not called CC=11 SCAR=48.8
Pod documented
666  
667 0 $self->errorblank;
668  
669 0 ▶ if ( !$self->{inited} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"inited"}) 0 0 0
670 0 $self->{error} = 1;
671 0 $self->{errorString} = 'backend has not been inited';
672 0 $self->warn;
673 0 return;
674 }
675  
676 # teardown is best effort here as a partially or fully wiped setup is
677 # exactly what re_init needs to recover from; init cleans up any remnants
678 {
679 0 local $@;
680 0 eval { $self->teardown; };
681 }
682 0 $self->init;
683  
684 0 my @to_ban = keys( %{ $self->{banned} } );
685 0 my @to_ban_cidr = keys( %{ $self->{banned_cidr} } );
686  
687 0 my @re_init_test_data;
688 0 foreach my $item (@to_ban) {
689 0 my $command = $self->_cmd_for($item) . ' ' . $self->{options}{type} . ' ' . $item;
690  
691 0 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'testing'}) { } 0 0 0
692 0 push( @re_init_test_data, $command );
693 } else {
694 0 my $output = `$command 2>&1`;
695 # backticks give undef when the command could not be executed at all
696 0 ▶ if ( !defined($output) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $output) 0 0 0
697 0 $output = 'no output, the command could not be executed... ' . $!;
698 }
699 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
700 0 $self->{error} = 13;
701 $self->{errorString}
702 0 = 'ban failed. non-zero exit code for the command... "' . $command . '"... output... ' . $output;
703 0 $self->warn;
704 }
705 }
706 } ## end foreach my $item (@to_ban)
707  
708 0 foreach my $item (@to_ban_cidr) {
709 0 my $command = $self->_cmd_for_cidr($item) . ' ' . $self->{options}{type} . ' ' . $item;
710  
711 0 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'testing'}) { } 0 0 0
712 0 push( @re_init_test_data, $command );
713 } else {
714 0 my $output = `$command 2>&1`;
715 # backticks give undef when the command could not be executed at all
716 0 ▶ if ( !defined($output) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $output) 0 0 0
717 0 $output = 'no output, the command could not be executed... ' . $!;
718 }
719 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
720 0 $self->{error} = 26;
721 $self->{errorString}
722 0 = 'ban failed. non-zero exit code for the command... "' . $command . '"... output... ' . $output;
723 0 $self->warn;
724 }
725 }
726 } ## end foreach my $item (@to_ban_cidr)
727  
728 0 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"testing"}) 0 0 0
729 0 $self->{frontend_obj}->{test_data} = \@re_init_test_data;
730 }
731  
732 0 $self->{inited} = 1;
733 } ## end sub re_init
734  
735 =head2 teardown
736  
737 Tears down the setup for the backend.
738  
739 This will C<allow> every currently banned IP and CIDR range. The internal
740 list of bans is kept, so a following re_init will re-add them.
741  
742 $fw_helper->teardown;
743  
744 =cut
745  
746 sub teardown {
747 0 ▶ my ( $self, %opts ) = @_;
Subroutine teardown: not called CC=7 SCAR=40.3
Pod documented
748  
749 0 $self->errorblank;
750  
751 0 $self->{inited} = 0;
752  
753 0 my @commands;
754 0 foreach my $item ( keys( %{ $self->{banned} } ) ) {
755 0 push( @commands, $self->_cmd_for($item) . ' allow ' . $item );
756 }
757 0 foreach my $item ( keys( %{ $self->{banned_cidr} } ) ) {
758 0 push( @commands, $self->_cmd_for_cidr($item) . ' allow ' . $item );
759 }
760  
761 0 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'testing'}) { } 0 0 0
762 0 $self->{frontend_obj}->{test_data} = \@commands;
763 } else {
764 0 foreach my $item (@commands) {
765 0 my $output = `$item 2>&1`;
766 # backticks give undef when the command could not be executed at all
767 0 ▶ if ( !defined($output) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $output) 0 0 0
768 0 $output = 'no output, the command could not be executed... ' . $!;
769 }
770 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
771 0 $self->{error} = 17;
772 $self->{errorString}
773 0 = 'teardown failed. non-zero exit code for the command... "' . $item . '"... output... ' . $output;
774 0 $self->warn;
775 }
776 }
777 } ## end else [ if ( $self->{testing} ) ]
778 } ## end sub teardown
779  
780 =head2 stop
781  
782 Alias for L</teardown>, provided for parity with the fail2ban C<actionstop>
783 concept.
784  
785 $fw_helper->stop;
786  
787 =cut
788  
789 sub stop {
790 0 ▶ my ( $self, %opts ) = @_;
Subroutine stop: not called CC=1 SCAR=6.9
Pod documented
791  
792 0 return $self->teardown(%opts);
793 }
794  
795 =head2 check
796  
797 Runs C<< shorewall show dynamic >>, and, when anything IPv6 is currently
798 banned, C<< shorewall6 show dynamic >> as well. A zero exit code from each
799 is treated as healthy. The IPv6 side is only checked when in use so setups
800 without shorewall6 installed are not flagged as unhealthy. This is the
801 equivalent of fail2ban's C<actioncheck>.
802  
803 if ( !$fw_helper->check ) {
804 $fw_helper->re_init;
805 }
806  
807 =cut
808  
809 sub check {
810 7 ▶ my ( $self, %opts ) = @_;
Subroutine check: called CC=6 SCAR=20.2
Pod documented
811  
812 7 $self->errorblank;
813  
814 # the IPv4 side is always checked; the IPv6 side only when something
815 # IPv6 is actually banned, as _cmd_for/_cmd_for_cidr only ever return
816 # shorewall6_cmd for IPv6 items
817 7 my %cmds = ( $self->{options}{shorewall_cmd} => 1 );
818 7 foreach my $item ( keys( %{ $self->{banned} } ) ) {
819 6 $cmds{ $self->_cmd_for($item) } = 1;
820 }
821 7 foreach my $item ( keys( %{ $self->{banned_cidr} } ) ) {
822 3 $cmds{ $self->_cmd_for_cidr($item) } = 1;
823 }
824 7 my @commands = map { $_ . ' show dynamic' } sort( keys(%cmds) );
825  
826 7 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"testing"}) 7 0 7
827 7 $self->{frontend_obj}->{test_data} = \@commands;
828 7 return 1;
829 }
830  
831 0 foreach my $command (@commands) {
832 0 my $output = `$command 2>&1`;
833 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
834 0 return 0;
835 }
836 }
837  
838 0 return 1;
839 } ## end sub check
840  
841 =head2 flush
842  
843 Removes all currently banned IPs and CIDR ranges at once by C<allow>ing each
844 of them and forgetting them. This is the equivalent of fail2ban's
845 C<actionflush>.
846  
847 $fw_helper->flush;
848  
849 =cut
850  
851 sub flush {
852 0 ▶ my ( $self, %opts ) = @_;
Subroutine flush: not called CC=8 SCAR=42.8
Pod documented
853  
854 0 $self->errorblank;
855  
856 0 ▶ if ( !$self->{inited} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"inited"}) 0 0 0
857 0 $self->{error} = 1;
858 0 $self->{errorString} = 'backend has not been inited';
859 0 $self->warn;
860 0 return;
861 }
862  
863 0 my @commands;
864 0 foreach my $item ( keys( %{ $self->{banned} } ) ) {
865 0 push( @commands, $self->_cmd_for($item) . ' allow ' . $item );
866 }
867 0 foreach my $item ( keys( %{ $self->{banned_cidr} } ) ) {
868 0 push( @commands, $self->_cmd_for_cidr($item) . ' allow ' . $item );
869 }
870  
871 0 ▶ if ( $self->{testing} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'testing'}) { } 0 0 0
872 0 $self->{frontend_obj}->{test_data} = \@commands;
873 } else {
874 0 foreach my $item (@commands) {
875 0 my $output = `$item 2>&1`;
876 # backticks give undef when the command could not be executed at all
877 0 ▶ if ( !defined($output) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $output) 0 0 0
878 0 $output = 'no output, the command could not be executed... ' . $!;
879 }
880 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
881 0 $self->{error} = 25;
882 $self->{errorString}
883 0 = 'flush failed. non-zero exit code for the command... "' . $item . '"... output... ' . $output;
884 0 $self->warn;
885 }
886 }
887 } ## end else [ if ( $self->{testing} ) ]
888  
889 0 $self->{banned} = {};
890 0 $self->{banned_cidr} = {};
891 } ## end sub flush
892  
893 =head1 ERROR CODES / FLAGS
894  
895 Error handling is provided by L<Error::Helper>. All
896 errors are considered fatal.
897  
898 =head2 1, notInited
899  
900 The backend has not been inited yet.
901  
902 =head2 8, optionsNotHash
903  
904 The item passed to new for options is not a hash.
905  
906 =head2 9, noBanItem
907  
908 No IP or CIDR range specified to ban or unban.
909  
910 =head2 10, banItemNotIP
911  
912 The item to ban is not an IP. Either wrong ref type or regexp
913 test using L<Regexp::IPv4> and L<Regexp::IPv6> failed.
914  
915 =head2 12, backendInitError
916  
917 Failed to init the backend.
918  
919 =head2 13, banFailed
920  
921 Failed to ban the item.
922  
923 =head2 14, unbanFailed
924  
925 Failed to unban the item.
926  
927 =head2 15, listFailed
928  
929 Failed to get a list of bans.
930  
931 =head2 16, reInitFailed
932  
933 Failed to re_init the backend.
934  
935 =head2 17, teardownFailed
936  
937 Failed to teardown the backend.
938  
939 =head2 18, alreadyInited
940  
941 init called, but the backend has already been inited.
942  
943 =head2 20, typeInvalid
944  
945 The option type is not 'drop' or 'reject'.
946  
947 =head2 24, checkFailed
948  
949 The backend check raised an error.
950  
951 =head2 25, flushFailed
952  
953 Failed to flush the bans.
954  
955 =head2 26, banCidrFailed
956  
957 Failed to ban the CIDR range.
958  
959 =head2 27, unbanCidrFailed
960  
961 Failed to unban the CIDR range.
962  
963 =head2 28, cidrItemNotCidr
964  
965 The item to ban is not a CIDR range. Either wrong ref type or it is not an
966 IPv4 or IPv6 address followed by a prefix length valid for its family.
967  
968 =head2 29, cidrNotSupported
969  
970 The backend does not support CIDR bans.
971  
972 =head2 30, listCidrFailed
973  
974 Failed to get a list of CIDR bans.
975  
976 =head1 AUTHOR
977  
978 Zane C. Bowers-Hadley, C<< <vvelox at vvelox.ent> >>
979  
980 =head1 BUGS
981  
982 Please report any bugs or feature requests to C<bug-net-firewall-blockerhelper at rt.cpan.org>, or through
983 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Firewall-BlockerHelper>. I will be notified, and then you'll
984 automatically be notified of progress on your bug as I make changes.
985  
986  
987  
988  
989 =head1 SUPPORT
990  
991 You can find documentation for this module with the perldoc command.
992  
993 perldoc Net::Firewall::BlockerHelper
994  
995  
996 You can also look for information at:
997  
998 =over 4
999  
1000 =item * RT: CPAN's request tracker (report bugs here)
1001  
1002 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Firewall-BlockerHelper>
1003  
1004 =item * Search CPAN
1005  
1006 L<https://metacpan.org/release/Net-Firewall-BlockerHelper>
1007  
1008 =back
1009  
1010  
1011 =head1 ACKNOWLEDGEMENTS
1012  
1013  
1014 =head1 LICENSE AND COPYRIGHT
1015  
1016 This software is Copyright (c) 2023 by Zane C. Bowers-Hadley.
1017  
1018 This is free software, licensed under:
1019  
1020 The GNU Lesser General Public License, Version 2.1, February 1999
1021  
1022  
1023 =cut
1024  
1025 1 1; # End of Net::Firewall::BlockerHelper
« BlockerHelper/backends/juniper_srx.pm ↑ Summary BlockerHelper/backends/pfsense.pm »