| 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 '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::linux_ip_route - Blackhole route 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 = 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 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 5 | ▶ | my ( $blank, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=21 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition83%5/6
defined $opts{"ports"} and ref $opts{"ports"} eq "ARRAY" and defined $opts{"ports"}[0]
defined $opts{"ports"} and ref $opts{"ports"} eq "ARRAY"
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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition83%5/6
defined $opts{"protocols"} and ref $opts{"protocols"} eq "ARRAY" and defined $opts{"protocols"}[0]
defined $opts{"protocols"} and ref $opts{"protocols"} eq "ARRAY"
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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $opts{"prefix"} and not $opts{"prefix"} =~ /^[a-zA-Z0-9]+$/
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]+$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 2 | $self->{testing} = $opts{testing}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 3 | ▶ | if ( defined( $opts{frontend_obj} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 2 | $self->{frontend_obj} = $opts{frontend_obj}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 3 | ▶ | if ( defined( $opts{options} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 3 | ▶ | if ( ref( $opts{options} ) ne 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
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"
defined $opts{"options"}{"blocktype"} and $opts{"options"}{"blocktype"} ne "unreachable" and $opts{"options"}{"blocktype"} ne "blackhole"
defined $opts{"options"}{"blocktype"} and $opts{"options"}{"blocktype"} ne "unreachable"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 ip route command for the passed action (add, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | # del, or show) and IP, using -6 for IPv6 IPs. For add and del the route type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | # is given bare as that is what the route spec wants, while for show it is a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # selector and must be given via the type keyword. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | sub _route_command { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 17 | ▶ | my ( $self, $action, $ip ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_route_command: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 17 | ▶ | my $family = ( $ip =~ /\A$IPv4_re\z/ ) ? '' : ' -6'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 17 | ▶ | my $type = ( $action eq 'show' ) ? 'type ' : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 17 | return 'ip' . $family . ' route ' . $action . ' ' . $type . $self->{options}{blocktype} . ' ' . $ip; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | =head2 init | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | Initiates the backend. Null routes need no setup, so no commands are run. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | $backend->init; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | sub init { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 4 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: called CC=3 SCAR=12.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 4 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 4 | ▶ | if ( $self->{inited} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | $self->{error} = 18; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | $self->{errorString} = 'backend has already been inited'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 4 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 4 | $self->{frontend_obj}->{test_data} = 'inited'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 4 | $self->{inited} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } ## end sub init | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | =head2 ban | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | Bans an IP. The value of ban is validated as being a IPv4 or IPv6 address | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | and lowercased, then a route of the configured C<blocktype> is added for it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | via C<ip route add> (C<ip -6 route add> for IPv6). Banning an already | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | banned IP is a noop. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | $backend->ban(ban => $ip); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | sub ban { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 4 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ban: called CC=10 SCAR=33.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 4 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 4 | ▶ | if ( !$self->{inited} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | $self->{errorString} = 'backend has not been inited'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 4 | ▶ | if ( !defined( $opts{ban} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | $self->{error} = 9; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | $self->{errorString} = 'Nothing specified for the value ban'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | } elsif ( ref( $opts{ban} ) ne '' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | $self->{error} = 10; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | ▶ | } 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/
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/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | && $opts{ban} !~ /\A$IPv6_re\z/ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | $self->{error} = 10; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 IP'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | # lowercase so the same IPv6 IP in differing cases can't result in duplicate entries | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 4 | $opts{ban} = lc( $opts{ban} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 4 | ▶ | if ( $self->{banned}{ $opts{ban} } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 1 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 1 | $self->{frontend_obj}->{test_data} = 'already banned'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 3 | my $command = $self->_route_command( 'add', $opts{ban} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 3 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 3 | $self->{frontend_obj}->{test_data} = [$command]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | my $output = `$command 2>&1`; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | ▶ | if ( $? != 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | $self->{error} = 13; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | $self->{errorString} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | = 'ban failed. non-zero exit code for the command... "' . $command . '"... output... ' . $output; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 3 | $self->{banned}{ $opts{ban} } = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } ## end sub ban | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | =head2 unban | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | Unbans an IP. The value of ban is validated as being a IPv4 or IPv6 address | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | and lowercased, then its route is removed via C<ip route del> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | (C<ip -6 route del> for IPv6). Unbanning an IP that is not banned is a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | noop. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | $backend->unban(ban => $ip); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | sub unban { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 1 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unban: called CC=10 SCAR=37.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 1 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 1 | ▶ | if ( !$self->{inited} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | $self->{errorString} = 'backend has not been inited'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 1 | ▶ | if ( !defined( $opts{ban} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | $self->{error} = 9; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | $self->{errorString} = 'Nothing specified for the value ban'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | } elsif ( ref( $opts{ban} ) ne '' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | $self->{error} = 10; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | ▶ | } 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/
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/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | && $opts{ban} !~ /\A$IPv6_re\z/ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | $self->{error} = 10; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 IP'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | # lowercase so the same IPv6 IP in differing cases can't result in duplicate entries | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 1 | $opts{ban} = lc( $opts{ban} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 1 | ▶ | if ( !$self->{banned}{ $opts{ban} } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 0 | $self->{frontend_obj}->{test_data} = 'not banned'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 1 | my $command = $self->_route_command( 'del', $opts{ban} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 1 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 1 | $self->{frontend_obj}->{test_data} = $command; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | my $output = `$command 2>&1`; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | ▶ | if ( $? != 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | $self->{error} = 14; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | $self->{errorString} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | = 'unban failed. non-zero exit code for the command... "' . $command . '"... output... ' . $output; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 1 | delete( $self->{banned}{ $opts{ban} } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } ## end sub unban | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | # Internal helper. Returns a true value if the passed scalar is a valid IPv4 or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | # IPv6 CIDR range, that is an address followed by "/" and a prefix length that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | # is within the range valid for its family (0 to 32 for IPv4, 0 to 128 for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | # IPv6). Returns false otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | sub _valid_cidr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 2 | ▶ | my ( $self, $cidr ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_valid_cidr: called CC=8 SCAR=30.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 2 | ▶ | return 0 if ( !defined($cidr) || ref($cidr) ne '' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $cidr or ref $cidr ne ""
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 ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 2 | ▶ | if ( $cidr =~ m!\A(.+)/([0-9]{1,3})\z! ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 2 | my ( $addr, $prefix ) = ( $1, $2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 2 | ▶ | return 1 if ( $addr =~ /\A$IPv4_re\z/ && $prefix <= 32 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv4_re\z/ and $prefix <= 32
MC/DC0%0/2
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv4_re\z/ and $prefix <= 32
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv4_re\z/
$prefix <= 32
Truth table33%1/3
A and B
A= $addr =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv4_re\z/B= $prefix <= 32
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | return 1 if ( $addr =~ /\A$IPv6_re\z/ && $prefix <= 128 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv6_re\z/ and $prefix <= 128
MC/DC0%0/2
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv6_re\z/ and $prefix <= 128
$addr =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv6_re\z/
$prefix <= 128
Truth table0%0/3
A and B
A= $addr =~ /\A$Net::Firewall::BlockerHelper::backends::linux_ip_route::IPv6_re\z/B= $prefix <= 128
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | } ## end sub _valid_cidr | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | =head2 ban_cidr | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | Bans a CIDR range by adding a route of the configured C<blocktype> for it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | via C<ip route add>, the same way a single IP is handled. The value of ban | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | is validated as being a IPv4 or IPv6 CIDR range and lowercased. Banning an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | already banned range is a noop. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | $backend->ban_cidr(ban => '1.2.3.0/24'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | sub ban_cidr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 1 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ban_cidr: called CC=10 SCAR=36.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 1 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 1 | ▶ | if ( !$self->{inited} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | $self->{errorString} = 'backend has not been inited'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 1 | ▶ | if ( !defined( $opts{ban} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | $self->{error} = 9; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | $self->{errorString} = 'Nothing specified for the value ban'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | } elsif ( ref( $opts{ban} ) ne '' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | $self->{error} = 30; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | } elsif ( !$self->_valid_cidr( $opts{ban} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | $self->{error} = 30; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 CIDR'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | # lowercase so the same IPv6 CIDR in differing cases can't result in duplicate entries | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 1 | $opts{ban} = lc( $opts{ban} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 1 | ▶ | if ( $self->{banned_cidr}{ $opts{ban} } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | $self->{frontend_obj}->{test_data} = 'already banned'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | # _route_command detects the family from the whole string, which a CIDR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | # would break, so the family is taken from the address portion here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 1 | my ($addr) = ( $opts{ban} =~ m!\A(.+)/[0-9]+\z! ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 1 | ▶ | my $family = ( $addr =~ /\A$IPv4_re\z/ ) ? '' : ' -6'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 1 | my $command = 'ip' . $family . ' route add ' . $self->{options}{blocktype} . ' ' . $opts{ban}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 1 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 1 | $self->{frontend_obj}->{test_data} = [$command]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | my $output = `$command 2>&1`; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | ▶ | if ( $? != 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | $self->{error} = 28; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | $self->{errorString} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | = 'ban failed. non-zero exit code for the command... "' . $command . '"... output... ' . $output; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 1 | $self->{banned_cidr}{ $opts{ban} } = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | } ## end sub ban_cidr | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | =head2 unban_cidr | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | Unbans a CIDR range by deleting its route via C<ip route del>. The value of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | ban is validated as being a IPv4 or IPv6 CIDR range and lowercased. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | Unbanning a range that is not banned is a noop. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | $backend->unban_cidr(ban => '1.2.3.0/24'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | sub unban_cidr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 1 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unban_cidr: called CC=10 SCAR=36.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 1 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 1 | ▶ | if ( !$self->{inited} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | $self->{errorString} = 'backend has not been inited'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 1 | ▶ | if ( !defined( $opts{ban} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | $self->{error} = 9; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | $self->{errorString} = 'Nothing specified for the value ban'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | } elsif ( ref( $opts{ban} ) ne '' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | $self->{error} = 30; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | $self->{errorString} = 'Bad ref type for ban... ref is "' . ref( $opts{ban} ) . '"'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | } elsif ( !$self->_valid_cidr( $opts{ban} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | $self->{error} = 30; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 0 | $self->{errorString} = 'ban item,"' . $opts{ban} . '", does not appear to be a IPv4 or IPv6 CIDR'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | # lowercase so the same IPv6 CIDR in differing cases can't result in duplicate entries | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 1 | $opts{ban} = lc( $opts{ban} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 1 | ▶ | if ( !$self->{banned_cidr}{ $opts{ban} } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | $self->{frontend_obj}->{test_data} = 'not banned'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | # _route_command detects the family from the whole string, which a CIDR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | # would break, so the family is taken from the address portion here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 1 | my ($addr) = ( $opts{ban} =~ m!\A(.+)/[0-9]+\z! ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 1 | ▶ | my $family = ( $addr =~ /\A$IPv4_re\z/ ) ? '' : ' -6'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 1 | my $command = 'ip' . $family . ' route del ' . $self->{options}{blocktype} . ' ' . $opts{ban}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 1 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 1 | $self->{frontend_obj}->{test_data} = $command; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | my $output = `$command 2>&1`; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | ▶ | if ( $? != 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | $self->{error} = 29; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | $self->{errorString} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | = 'unban failed. non-zero exit code for the command... "' . $command . '"... output... ' . $output; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 1 | delete( $self->{banned_cidr}{ $opts{ban} } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | } ## end sub unban_cidr | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | =head2 list_cidr | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | List banned CIDR ranges. Returns an array of the currently banned CIDR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | ranges. Single IPs are not included; for those see L</list>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | my @banned_cidrs = $backend->list_cidr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | sub list_cidr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 2 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_cidr: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 2 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 2 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 2 | $self->{frontend_obj}->{test_data} = 'list_cidr'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 2 | return keys( %{ $self->{banned_cidr} } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | =head2 list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | List banned IPs. Returns an array of the currently banned single IPs. CIDR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | ranges are not included; for those see L</list_cidr>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | my @banned = $backend->list; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | sub list { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 2 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 2 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 2 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 2 | $self->{frontend_obj}->{test_data} = 'list'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 2 | return keys( %{ $self->{banned} } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | =head2 re_init | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | Tells the backend to re-init it's self. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | This will call teardown and init again. After that it will | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | re-added all previously added bans. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | $backend->re_init; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | sub re_init { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 1 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
re_init: called CC=10 SCAR=33.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 1 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 1 | ▶ | if ( !$self->{inited} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 0 | $self->{errorString} = 'backend has not been inited'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | # teardown is best effort here as a partially or fully wiped setup is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | # exactly what re_init needs to recover from; init cleans up any remnants | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 1 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 1 | eval { $self->teardown; }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 1 | $self->init; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 1 | my @to_ban = keys( %{ $self->{banned} } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 1 | my @re_init_test_data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 1 | foreach my $item (@to_ban) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 1 | my $command = $self->_route_command( 'add', $item ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 1 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 1 | push( @re_init_test_data, $command ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | my $output = `$command 2>&1`; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | ▶ | if ( $? != 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 0 | $self->{error} = 13; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | $self->{errorString} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 0 | = 'ban failed. non-zero exit code for the command... "' . $command . '"... output... ' . $output; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | } ## end foreach my $item (@to_ban) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | # CIDR ranges are re-added the same way, but the family must be taken from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | # the address portion as _route_command can not detect it from a CIDR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 1 | foreach my $item ( keys( %{ $self->{banned_cidr} } ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 0 | my ($addr) = ( $item =~ m!\A(.+)/[0-9]+\z! ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 0 | ▶ | my $family = ( $addr =~ /\A$IPv4_re\z/ ) ? '' : ' -6'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 0 | my $command = 'ip' . $family . ' route add ' . $self->{options}{blocktype} . ' ' . $item; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | push( @re_init_test_data, $command ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 0 | my $output = `$command 2>&1`; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 0 | ▶ | if ( $? != 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 0 | $self->{error} = 28; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | $self->{errorString} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 0 | = 'ban failed. non-zero exit code for the command... "' . $command . '"... output... ' . $output; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | } ## end foreach my $item ( keys( %{ $self->{banned_cidr}...})) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 1 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 1 | $self->{frontend_obj}->{test_data} = \@re_init_test_data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 1 | $self->{inited} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | } ## end sub re_init | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | =head2 teardown | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | Tears down the setup for the backend by deleting the route for each | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | currently banned IP. Routes that were already removed externally are | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | tolerated, so re_init works after an external wipe. The internal list of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | bans is kept, so a following re_init will re-add them. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | $backend->teardown; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | sub teardown { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 2 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
teardown: called CC=6 SCAR=21.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 2 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 2 | $self->{inited} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 2 | my @commands; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 2 | foreach my $item ( keys( %{ $self->{banned} } ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 2 | push( @commands, $self->_route_command( 'del', $item ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | # CIDR ranges are removed the same way, but the family must be taken from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | # the address portion as _route_command can not detect it from a CIDR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 2 | foreach my $item ( keys( %{ $self->{banned_cidr} } ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 0 | my ($addr) = ( $item =~ m!\A(.+)/[0-9]+\z! ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 0 | ▶ | my $family = ( $addr =~ /\A$IPv4_re\z/ ) ? '' : ' -6'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 0 | push( @commands, 'ip' . $family . ' route del ' . $self->{options}{blocktype} . ' ' . $item ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 2 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 2 | $self->{frontend_obj}->{test_data} = \@commands; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | # failures are tolerated as the route may already have been removed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | # externally, which is exactly what re_init recovers from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | foreach my $item (@commands) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | my $output = `$item 2>&1`; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | } ## end sub teardown | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | =head2 stop | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | Alias for L</teardown>, provided for parity with the fail2ban C<actionstop> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | concept. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | $backend->stop; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | sub stop { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 0 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
stop: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 0 | return $self->teardown(%opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | =head2 check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | Verifies the route for each currently banned single IP is still present. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | Returns a true value if they all are and a false value if any are missing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | Routes for banned CIDR ranges are not checked. This is the equivalent of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | fail2ban's C<actioncheck>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | if ( !$backend->check ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | $backend->re_init; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | sub check { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 8 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check: called CC=6 SCAR=24.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 8 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | 8 | my @commands; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | 8 | foreach my $item ( sort( keys( %{ $self->{banned} } ) ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 9 | push( @commands, $self->_route_command( 'show', $item ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 8 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 8 | $self->{frontend_obj}->{test_data} = \@commands; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 8 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | foreach my $item (@commands) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 0 | my $output = `$item 2>&1`; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | # ip route show exits zero even when nothing matches, so a missing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | # route shows up as a lack of output rather than a non-zero exit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 0 | ▶ | if ( $? != 0 || $output !~ /\S/ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$? != 0 or not $output =~ /\S/
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/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | } ## end sub check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | =head2 flush | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | Removes all currently banned IPs at once by deleting their routes and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | forgetting them. This is the equivalent of fail2ban's C<actionflush>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | $backend->flush; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | sub flush { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 1 | ▶ | my ( $self, %opts ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
flush: called CC=8 SCAR=29.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 1 | $self->errorblank; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 1 | ▶ | if ( !$self->{inited} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 0 | $self->{error} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 0 | $self->{errorString} = 'backend has not been inited'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 1 | my @commands; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | 1 | foreach my $item ( keys( %{ $self->{banned} } ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | 1 | push( @commands, $self->_route_command( 'del', $item ) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | # CIDR ranges are removed the same way, but the family must be taken from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | # the address portion as _route_command can not detect it from a CIDR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 1 | foreach my $item ( keys( %{ $self->{banned_cidr} } ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 0 | my ($addr) = ( $item =~ m!\A(.+)/[0-9]+\z! ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 0 | ▶ | my $family = ( $addr =~ /\A$IPv4_re\z/ ) ? '' : ' -6'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 0 | push( @commands, 'ip' . $family . ' route del ' . $self->{options}{blocktype} . ' ' . $item ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 1 | ▶ | if ( $self->{testing} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 1 | $self->{frontend_obj}->{test_data} = \@commands; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 0 | foreach my $item (@commands) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | 0 | my $output = `$item 2>&1`; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 0 | ▶ | if ( $? != 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 0 | $self->{error} = 25; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | $self->{errorString} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 0 | = 'flush failed. non-zero exit code for the command... "' . $item . '"... output... ' . $output; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | 0 | $self->warn; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | } ## end else [ if ( $self->{testing} ) ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 1 | $self->{banned} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 1 | $self->{banned_cidr} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | } ## end sub flush | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | =head1 ERROR CODES / FLAGS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | Error handling is provided by L<Error::Helper>. All | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | errors are considered fatal. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | =head2 1, notInited | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | The backend has not been inited yet. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | =head2 6, invalidPrefixSpecified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | The specified prefix did not match /^[a-zA-Z0-9]+$/. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | =head2 7, invalidName | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | The name is either undef or does not match /^[a-zA-Z0-9\-]+$/. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | =head2 8, optionsNotHash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | The item passed to new for options is not a hash. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | =head2 9, noBanItem | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | No IP or CIDR range specified to ban or unban. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | =head2 10, banItemNotIP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | The item to ban is not an IP. Either wrong ref type or regexp | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | test using L<Regexp::IPv4> and L<Regexp::IPv6> failed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | =head2 12, backendInitError | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | Failed to init the backend. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | =head2 13, banFailed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | Failed to ban the item. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | =head2 14, unbanFailed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | Failed to unban the item. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | =head2 15, listFailed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | Failed to get a list of bans. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | =head2 16, reInitFailed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | Failed to re_init the backend. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | =head2 17, teardownFailed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | Failed to teardown the backend. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | =head2 18, alreadyInited | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | init called, but the backend has already been inited. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | =head2 20, blocktypeInvalid | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | The option blocktype is not "unreachable", "blackhole", or "prohibit". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | =head2 23, initFailed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | One of the required commands for init failed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | =head2 24, checkFailed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | The backend check raised an error. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | =head2 25, flushFailed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | Failed to flush the bans. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | =head2 26, portsNotSupported | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | Ports were specified, but the backend does not support ports. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | =head2 27, protocolsNotSupported | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | Protocols were specified, but the backend does not support protocols. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | =head2 28, banCidrFailed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | Failed to ban the CIDR range. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | =head2 29, unbanCidrFailed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | Failed to unban the CIDR range. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | =head2 30, cidrItemNotCidr | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | The item to ban is not a CIDR range. Either wrong ref type or it is not an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | IPv4 or IPv6 address followed by a prefix length valid for its family. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | =head2 31, cidrNotSupported | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | The backend does not support CIDR bans. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | =head2 32, listCidrFailed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | Failed to get a list of CIDR bans. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | Zane C. Bowers-Hadley, C<< <vvelox at vvelox.ent> >> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | Please report any bugs or feature requests to C<bug-net-firewall-blockerhelper at rt.cpan.org>, or through | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Firewall-BlockerHelper>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | This software is Copyright (c) 2023 by Zane C. Bowers-Hadley. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | This is free software, licensed under: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | The GNU Lesser General Public License, Version 2.1, February 1999 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | 1 | 1; # End of Net::Firewall::BlockerHelper | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||