blib/lib/POE/Component/Proxy/SOCKS.pm

filter: Statementstmt 14.0% 59 / 420 Branchbran 4.2% 8 / 188 Conditioncond 0.0% 0 / 53 MC/DCmcdc 0.0% 0 / 32 Subroutinesub 22.4% 11 / 49 Podpod 100% 12 / 12 totaltotal 11.9% 90 / 754 CC 127 SCAR 42.1
CC
127
Cov
10%
_conn_input
380.0
_parse_input
90.0
_ident_done
72.0
CRAP 67.4
↑ Summary
1 package POE::Component::Proxy::SOCKS;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use POE qw(Component::Client::Ident Component::Client::DNS Wheel::SocketFactory Wheel::ReadWrite Filter::Stream);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Net::Netmask;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 $VERSION = '1.02';
11  
12 sub spawn {
13 1 ▶ my $package = shift;
Subroutine spawn: called CC=3 SCAR=11.0
Pod documented
14 1 my %opts = @_;
15 1 $opts{lc $_} = delete $opts{$_} for keys %opts;
16 1 my $options = delete $opts{options};
17 1 my $self = bless \%opts, $package;
18 1 ▶ $self->{session_id} = POE::Session->create(
Branch: 1 branch
BranchTrueFalseTotal
ref $options eq 'HASH' ? : 0 1 1
19 object_states => [
20 $self => { shutdown => '_shutdown',
21 send_event => '__send_event',
22 ident_agent_reply => '_ident_agent_reply',
23 ident_agent_error => '_ident_agent_error',
24 },
25 $self => [ qw(
26 _start
27 register
28 unregister
29 _accept_client
30 _accept_failed
31 _conn_input
32 _conn_error
33 _conn_alarm
34 __send_event
35 _ident_done
36 _reject_client
37 _dns_response
38 _do_connect
39 _do_bind
40 _sock_connection
41 _sock_up
42 _sock_failed
43 _sock_input
44 _sock_down
45 _sock_alarm
46 _bind_request
47 )
48 ],
49 ],
50 heap => $self,
51 ( ref($options) eq 'HASH' ? ( options => $options ) : () ),
52 )->ID();
53 1 return $self;
54 }
55  
56 sub session_id {
57 1 ▶ return $_[0]->{session_id};
Subroutine session_id: called CC=1 SCAR=0.0
Pod documented
58 }
59  
60 sub _conn_exists {
61 0 ▶ my ($self,$wheel_id) = @_;
Subroutine _conn_exists: not called CC=3 SCAR=24.8
62 0 ▶ return 0 unless $wheel_id and defined $self->{clients}->{ $wheel_id };
Branch: 1 branch
BranchTrueFalseTotal
unless $wheel_id and defined $self->{"clients"}{$wheel_id} 0 0 0
Condition0%0/3
$wheel_id and defined $self->{"clients"}{$wheel_id}
!ll&&!rl&&r
000
MC/DC0%0/2
$wheel_id and defined $self->{"clients"}{$wheel_id}
$wheel_id defined $self->{"clients"}{$wheel_id}
Truth table0%0/3
A and B
A= $wheel_idB= defined $self->{"clients"}{$wheel_id}
ABresult
0X0
100
111
63 0 return 1;
64 }
65  
66 sub _link_exists {
67 0 ▶ my ($self,$wheel_id) = @_;
Subroutine _link_exists: not called CC=3 SCAR=24.8
68 0 ▶ return 0 unless $wheel_id and defined $self->{links}->{ $wheel_id };
Branch: 1 branch
BranchTrueFalseTotal
unless $wheel_id and defined $self->{"links"}{$wheel_id} 0 0 0
Condition0%0/3
$wheel_id and defined $self->{"links"}{$wheel_id}
!ll&&!rl&&r
000
MC/DC0%0/2
$wheel_id and defined $self->{"links"}{$wheel_id}
$wheel_id defined $self->{"links"}{$wheel_id}
Truth table0%0/3
A and B
A= $wheel_idB= defined $self->{"links"}{$wheel_id}
ABresult
0X0
100
111
69 0 return 1;
70 }
71  
72 sub _sock_exists {
73 0 ▶ my ($self,$wheel_id) = @_;
Subroutine _sock_exists: not called CC=3 SCAR=24.8
74 0 ▶ return 0 unless $wheel_id and defined $self->{sockets}->{ $wheel_id };
Branch: 1 branch
BranchTrueFalseTotal
unless $wheel_id and defined $self->{"sockets"}{$wheel_id} 0 0 0
Condition0%0/3
$wheel_id and defined $self->{"sockets"}{$wheel_id}
!ll&&!rl&&r
000
MC/DC0%0/2
$wheel_id and defined $self->{"sockets"}{$wheel_id}
$wheel_id defined $self->{"sockets"}{$wheel_id}
Truth table0%0/3
A and B
A= $wheel_idB= defined $self->{"sockets"}{$wheel_id}
ABresult
0X0
100
111
75 0 return 1;
76 }
77  
78 sub _bind_request {
79 0 ▶ my ($self,$id) = @_;
Subroutine _bind_request: not called CC=6 SCAR=37.4
80 0 ▶ return unless $self->_conn_exists( $id );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_conn_exists($id) 0 0 0
81 0 my $client = $self->{clients}->{ $id };
82 0 my $match;
83 0 foreach my $cid ( keys %{ $self->{clients} } ) {
84 0 ▶ next if $cid eq $id;
Branch: 1 branch
BranchTrueFalseTotal
if $cid eq $id 0 0 0
85 0 ▶ next if $self->{clients}->{ $cid }->{dstip} ne $client->{dstip};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"clients"}{$cid}{"dstip"} ne $client->{"dstip"} 0 0 0
86 0 ▶ next if $self->{clients}->{ $cid }->{dstport} ne $client->{dstport};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"clients"}{$cid}{"dstport"} ne $client->{"dstport"} 0 0 0
87 0 $match = $cid;
88 0 last;
89 }
90 0 return $match;
91 }
92  
93 sub shutdown {
94 0 ▶ my $self = shift;
Subroutine shutdown: not called CC=1 SCAR=6.9
Pod documented
95 0 $poe_kernel->post( $self->{session_id}, 'shutdown' );
96 }
97  
98 sub _start {
99 1 ▶ my ($kernel,$self,$sender) = @_[KERNEL,OBJECT,SENDER];
Subroutine _start: called CC=5 SCAR=16.6
100 1 $self->{session_id} = $_[SESSION]->ID();
101 1 ▶ if ( $self->{alias} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'alias'}) { } 0 1 1
102 0 $kernel->alias_set( $self->{alias} );
103 }
104 else {
105 1 $kernel->refcount_increment( $self->{session_id} => __PACKAGE__ );
106 }
107 1 ▶ if ( $kernel != $sender ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($kernel != $sender) 1 0 1
108 1 my $sender_id = $sender->ID;
109 1 $self->{events}->{'socksd_all'}->{$sender_id} = $sender_id;
110 1 $self->{sessions}->{$sender_id}->{'ref'} = $sender_id;
111 1 $kernel->refcount_increment($sender_id, __PACKAGE__);
112 1 $kernel->post( $sender, 'socksd_registered', $self );
113 }
114  
115 1 $self->{resolver} = POE::Component::Client::DNS->spawn( Alias => 'socksd' . $self->{session_id}, Timeout => 10 );
116  
117 1 $self->{filter} = POE::Filter::Stream->new();
118  
119 $self->{listener} = POE::Wheel::SocketFactory->new(
120 ( defined $self->{address} ? ( BindAddress => $self->{address} ) : () ),
121 1 ▶ ( defined $self->{port} ? ( BindPort => $self->{port} ) : ( BindPort => 1080 ) ),
Branch: 2 branches
BranchTrueFalseTotal
defined $self->{'address'} ? : 0 1 1
defined $self->{'port'} ? : 1 0 1
122 SuccessEvent => '_accept_client',
123 FailureEvent => '_accept_failed',
124 SocketDomain => AF_INET, # Sets the socket() domain
125 SocketType => SOCK_STREAM, # Sets the socket() type
126 SocketProtocol => 'tcp', # Sets the socket() protocol
127 Reuse => 'on', # Lets the port be reused
128 );
129 1 return;
130 }
131  
132 sub _shutdown {
133 1 ▶ my ($kernel,$self) = @_[KERNEL,OBJECT];
Subroutine _shutdown: called CC=3 SCAR=11.0
134 1 delete $self->{listener};
135 1 delete $self->{clients};
136 1 delete $self->{sockets};
137 1 $kernel->alarm_remove_all();
138 1 $kernel->alias_remove( $_ ) for $kernel->alias_list();
139 1 ▶ $kernel->refcount_decrement( $self->{session_id} => __PACKAGE__ ) unless $self->{alias};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"alias"} 1 0 1
140 1 $self->_unregister_sessions();
141 1 $self->{resolver}->shutdown();
142 1 return;
143 }
144  
145 sub _accept_client {
146 0 ▶ my ($kernel,$self,$socket,$peeraddr,$peerport) = @_[KERNEL,OBJECT,ARG0..ARG2];
Subroutine _accept_client: not called CC=5 SCAR=34.0
147 0 my $sockaddr = inet_ntoa( ( unpack_sockaddr_in ( getsockname $socket ) )[1] );
148 0 my $sockport = ( unpack_sockaddr_in ( getsockname $socket ) )[0];
149 0 $peeraddr = inet_ntoa( $peeraddr );
150  
151 0 ▶ if ( $self->denied( $peeraddr ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->denied($peeraddr)) 0 0 0
152 0 $self->_send_event( 'socksd_denied', $peeraddr, $peerport );
153 0 return;
154 }
155  
156 my $wheel = POE::Wheel::ReadWrite->new(
157 Handle => $socket,
158 Filter => $self->{filter},
159 0 InputEvent => '_conn_input',
160 ErrorEvent => '_conn_error',
161 FlushedEvent => '_conn_flushed',
162 );
163  
164 0 ▶ return unless $wheel;
Branch: 1 branch
BranchTrueFalseTotal
unless $wheel 0 0 0
165
166 0 my $id = $wheel->ID();
167 0 $self->{clients}->{ $id } =
168 {
169 wheel => $wheel,
170 peeraddr => $peeraddr,
171 peerport => $peerport,
172 sockaddr => $sockaddr,
173 sockport => $sockport,
174 };
175 0 $self->_send_event( 'socksd_connection', $id, $peeraddr, $peerport, $sockaddr, $sockport );
176  
177 0 ▶ $self->{clients}->{ $id }->{alarm} = $kernel->delay_set( '_conn_alarm', $self->{time_out} || 120, $id );
Condition0%0/2
$self->{'time_out'} || 120
l!l
00
MC/DC0%0/1
$self->{'time_out'} || 120
$self->{'time_out'}
Truth table0%0/2
A
A= $self->{'time_out'}
Aresult
11
00
178  
179 0 ▶ if ( $self->{ident} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ident"}) 0 0 0
180 0 POE::Component::Client::Ident::Agent->spawn(
181 PeerAddr => $peeraddr,
182 PeerPort => $peerport,
183 SockAddr => $sockaddr,
184 SockPort => $sockport,
185 BuggyIdentd => 1,
186 TimeOut => 10,
187 Reference => $id );
188 }
189  
190 0 return;
191 }
192  
193 sub _accept_failed {
194 0 ▶ my ($kernel,$self,$operation,$errnum,$errstr,$wheel_id) = @_[KERNEL,OBJECT,ARG0..ARG3];
Subroutine _accept_failed: not called CC=1 SCAR=6.9
195 0 warn "Wheel $wheel_id generated $operation error $errnum: $errstr\n";
196 0 delete $self->{listener};
197 0 $self->_send_event( 'socksd_listener_failed', $operation, $errnum, $errstr );
198 0 return;
199 }
200  
201 sub _ident_agent_reply {
202 0 ▶ my ($kernel,$self,$ref,$opsys,$other) = @_[KERNEL,OBJECT,ARG0,ARG1,ARG2];
Subroutine _ident_agent_reply: not called CC=2 SCAR=17.9
203 0 my $wheel_id = $ref->{Reference};
204 0 ▶ return unless $self->_conn_exists( $wheel_id );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_conn_exists($wheel_id) 0 0 0
205 0 my $ident = '';
206 #$ident = $other if uc ( $opsys ) ne 'OTHER';
207 0 $ident = $other;
208 0 $self->{clients}->{ $wheel_id }->{ident} = $ident;
209 0 $kernel->yield( '_ident_done' => $wheel_id );
210 0 return;
211 }
212  
213 sub _ident_agent_error {
214 0 ▶ my ($kernel,$self,$ref,$error) = @_[KERNEL,OBJECT,ARG0,ARG1];
Subroutine _ident_agent_error: not called CC=2 SCAR=17.9
215 0 my $wheel_id = $ref->{Reference};
216 0 ▶ return unless $self->_conn_exists( $wheel_id );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_conn_exists($wheel_id) 0 0 0
217 0 $self->{clients}->{ $wheel_id }->{ident} = '';
218 0 $kernel->yield( '_ident_done' => $wheel_id );
219 0 return;
220 }
221  
222 sub _ident_done {
223 0 ▶ my ($kernel,$self,$id) = @_[KERNEL,OBJECT,ARG0];
Subroutine _ident_done: not called CC=8 SCAR=42.8
224 0 ▶ return unless $self->_conn_exists( $id );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_conn_exists($id) 0 0 0
225 0 ▶ return unless defined $self->{clients}->{ $id }->{user_id};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"clients"}{$id}{"user_id"} 0 0 0
226 0 ▶ return unless defined $self->{clients}->{ $id }->{ident};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"clients"}{$id}{"ident"} 0 0 0
227 0 my $client = $self->{clients}->{ $id };
228 0 ▶ unless ( $client->{ident} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($client->{"ident"}) 0 0 0
229 0 $kernel->yield( '_reject_client', $id, '92', 'No Ident Response' );
230 0 return;
231 }
232 0 ▶ unless ( $client->{ident} eq $client->{user_id} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($client->{"ident"} eq $client->{"user_id"}) 0 0 0
233 0 $kernel->yield( '_reject_client', $id, '93', 'Ident and user_id mismatch' );
234 0 return;
235 }
236 0 ▶ $kernel->yield( '_do_connect', $id ) if $client->{cd} eq '1';
Branch: 1 branch
BranchTrueFalseTotal
if $client->{"cd"} eq 1 0 0 0
237 0 ▶ $kernel->yield( '_do_bind', $id ) if $client->{cd} eq '2';
Branch: 1 branch
BranchTrueFalseTotal
if $client->{"cd"} eq 2 0 0 0
238 0 return;
239 }
240  
241 sub _reject_client {
242 0 ▶ my ($kernel,$self,$id,$reject_id,$reason) = @_[KERNEL,OBJECT,ARG0,ARG1,ARG2];
Subroutine _reject_client: not called CC=2 SCAR=17.9
243 0 ▶ return unless $self->_conn_exists( $id );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_conn_exists($id) 0 0 0
244 0 my $client = $self->{clients}->{ $id };
245 0 $client->{reject} = $reject_id;
246 0 my $response = pack "CCnN", 0, $reject_id, $client->{dstport}, inet_aton( $client->{dstip} );
247 0 $client->{wheel}->put( $response );
248 0 $self->_send_event( 'socksd_rejected', $id, $reject_id, $reason );
249 0 return;
250 }
251  
252 sub _parse_input {
253 0 ▶ my $input = shift || return;
Subroutine _parse_input: not called CC=9 SCAR=45.0
Condition0%0/2
shift() || (return)
l!l
00
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
254 0 my $null_idx = index $input, "\0";
255 0 ▶ return if $null_idx == -1;
Branch: 1 branch
BranchTrueFalseTotal
if $null_idx == -1 0 0 0
256 0 my $request = substr $input, 0, $null_idx;
257 0 ▶ return unless $request;
Branch: 1 branch
BranchTrueFalseTotal
unless $request 0 0 0
258 0 my $packet = substr $input, 0, 4;
259 0 ▶ return unless $packet or length $packet == 4;
Branch: 1 branch
BranchTrueFalseTotal
unless $packet or length $packet == 4 0 0 0
Condition0%0/3
$packet or length $packet == 4
l!l&&r!l&&!r
000
MC/DC0%0/2
$packet or length $packet == 4
$packet length $packet == 4
Truth table0%0/3
A or B
A= $packetB= length $packet == 4
ABresult
1X1
011
000
260 0 my @results = unpack "CCn", $packet;
261 0 ▶ return unless scalar @results == 3;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @results == 3 0 0 0
262 0 my $dstip = substr $input, 4, 4;
263 0 ▶ return unless $dstip;
Branch: 1 branch
BranchTrueFalseTotal
unless $dstip 0 0 0
264 0 push @results, $dstip;
265 0 my $remainder = substr $input, 8;
266 0 $remainder =~ s/\0$//g;
267 0 my ($id,$host) = split /\0/, $remainder;
268 0 ▶ $id = '' unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 0 0
269 0 push @results, $id, $host;
270 0 return @results;
271 }
272  
273 sub _conn_input {
274 0 ▶ my ($kernel,$self,$input,$id) = @_[KERNEL,OBJECT,ARG0,ARG1];
Subroutine _conn_input: not called CC=19 SCAR=59.4
275 0 ▶ return unless $self->_conn_exists( $id );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_conn_exists($id) 0 0 0
276 0 my $client = $self->{clients}->{ $id };
277 0 ▶ $kernel->delay_adjust( $client->{alarm}, $self->{time_out} || 120 );
Condition0%0/2
$self->{'time_out'} || 120
l!l
00
MC/DC0%0/1
$self->{'time_out'} || 120
$self->{'time_out'}
Truth table0%0/2
A
A= $self->{'time_out'}
Aresult
11
00
278 0 ▶ unless ( $client->{link_id} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($client->{"link_id"}) 0 0 0
279 # No uplink the client must be negotiating
280 0 my @args = _parse_input( $input );
281 0 ▶ unless ( @args ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@args) 0 0 0
282 0 delete $self->{clients}->{ $id };
283 0 return;
284 }
285 0 my ($vn,$cd,$dstport,$dstip,$userid,$host) = @args;
286 0 $dstip = inet_ntoa( $dstip );
287 0 ▶ unless ( $dstip ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dstip) 0 0 0
288 0 delete $self->{clients}->{ $id };
289 0 return;
290 }
291 0 $client->{dstip} = $dstip;
292 0 $client->{dstport} = $dstport;
293 0 $client->{user_id} = $userid;
294 0 ▶ if ( $vn ne '4' or $cd !~ /^(1|2)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vn ne 4 or not $cd =~ /^(1|2)$/) 0 0 0
Condition0%0/3
$vn ne 4 or not $cd =~ /^(1|2)$/
l!l&&r!l&&!r
000
MC/DC0%0/2
$vn ne 4 or not $cd =~ /^(1|2)$/
$vn ne 4 not $cd =~ /^(1|2)$/
Truth table0%0/3
A or not(B)
A= $vn ne 4B= not $cd =~ /^(1|2)$/
ABresult
1X1
011
000
295 0 $kernel->yield( '_reject_client', $id, '91', 'Invalid request' );
296 0 return;
297 }
298 0 ▶ if ( $dstip =~ /^0\.0\.0\./ and $cd ne '2' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dstip =~ /^0\.0\.0\./ and $cd ne 2) 0 0 0
Condition0%0/3
$dstip =~ /^0\.0\.0\./ and $cd ne 2
!ll&&!rl&&r
000
MC/DC0%0/2
$dstip =~ /^0\.0\.0\./ and $cd ne 2
$dstip =~ /^0\.0\.0\./ $cd ne 2
Truth table0%0/3
A and B
A= $dstip =~ /^0\.0\.0\./B= $cd ne 2
ABresult
0X0
100
111
299 # SOCKS 4a request
300 0 ▶ unless ( $host ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($host) 0 0 0
301 0 $kernel->yield( '_reject_client', $id, '91', 'SOCKS4a request. No host' );
302 0 return;
303 }
304 my $response = $self->{resolver}->resolve(
305 0 event => '_dns_response',
306 host => $host,
307 context => { id => $id },
308 );
309 0 ▶ if ( $response ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response) 0 0 0
310 0 $kernel->yield( _dns_response => $response );
311 }
312 0 return;
313 }
314 0 ▶ if ( $cd eq '2' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cd eq 2) 0 0 0
315 0 my $cid = $self->_bind_request( $id );
316 0 ▶ unless ( $cid ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cid) 0 0 0
317 0 $kernel->yield( '_reject_client', $id, '91', 'Invalid request' );
318 0 return;
319 }
320 0 $client->{primary} = $cid;
321 0 ▶ $kernel->yield( '_ident_done', $id ) if $self->{ident};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ident"} 0 0 0
322 0 ▶ $kernel->yield( '_do_bind', $id ) unless $self->{ident};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"ident"} 0 0 0
323 0 return;
324 }
325 0 ▶ $kernel->yield( '_ident_done', $id ) if $self->{ident};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ident"} 0 0 0
326 0 ▶ $kernel->yield( '_do_connect', $id ) unless $self->{ident};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"ident"} 0 0 0
327 0 return;
328 }
329 0 ▶ return unless $self->_link_exists( $client->{link_id} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_link_exists($client->{"link_id"}) 0 0 0
330 0 $self->{links}->{ $client->{link_id} }->{wheel}->put( $input );
331 0 return;
332 }
333  
334 sub _dns_response {
335 0 ▶ my ($kernel,$self,$arg) = @_[KERNEL,OBJECT,ARG0];
Subroutine _dns_response: not called CC=8 SCAR=42.8
336 0 my $net_dns_packet = $arg->{response};
337 0 my $net_dns_errorstring = $arg->{error};
338 0 my $id = $arg->{context}->{id};
339 0 ▶ return unless $self->_conn_exists( $id );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_conn_exists($id) 0 0 0
340 0 ▶ unless( defined $net_dns_packet ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $net_dns_packet) 0 0 0
341 0 $kernel->yield( '_reject_client', $id, '91', 'DNS failed' );
342 0 return;
343 }
344 0 my @net_dns_answers = $net_dns_packet->answer;
345 0 ▶ unless ( @net_dns_answers ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@net_dns_answers) 0 0 0
346 0 $kernel->yield( '_reject_client', $id, '91', 'No DNS answers' );
347 0 return;
348 }
349 0 foreach my $net_dns_answer (@net_dns_answers) {
350 0 ▶ next unless $net_dns_answer->type eq 'A';
Branch: 1 branch
BranchTrueFalseTotal
unless $net_dns_answer->type eq "A" 0 0 0
351 0 $self->{clients}->{ $id }->{dstip} = $net_dns_answer->rdatastr;
352 0 $self->_send_event( 'socksd_dns_lookup', $id, $arg->{host}, $self->{clients}->{ $id }->{dstip} );
353 0 ▶ $kernel->yield( '_ident_done', $id ) if $self->{ident};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ident"} 0 0 0
354 0 ▶ $kernel->yield( '_do_connect', $id ) unless $self->{ident};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"ident"} 0 0 0
355 0 return;
356 }
357 0 $kernel->yield( '_reject_client', $id, '91', 'No DNS records found' );
358 0 return;
359 }
360  
361 sub _conn_error {
362 0 ▶ my ($self,$errstr,$id) = @_[OBJECT,ARG2,ARG3];
Subroutine _conn_error: not called CC=2 SCAR=17.9
363 0 ▶ return unless $self->_conn_exists( $id );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_conn_exists($id) 0 0 0
364 0 $self->_delete_client( $id );
365 0 $self->_send_event( 'socksd_disconnected', $id, $errstr );
366 0 return;
367 }
368  
369 sub _conn_flushed {
370 0 ▶ my ($self,$id) = @_[OBJECT,ARG0];
Subroutine _conn_flushed: not called CC=4 SCAR=30.0
371 0 ▶ return unless $self->_conn_exists( $id );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_conn_exists($id) 0 0 0
372 0 ▶ return if $self->{clients}->{ $id }->{link_id};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"clients"}{$id}{"link_id"} 0 0 0
373 0 ▶ return unless $self->{clients}->{ $id }->{reject};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"clients"}{$id}{"reject"} 0 0 0
374 0 $self->_delete_client( $id );
375 0 return;
376 }
377  
378 sub _conn_alarm {
379 0 ▶ my ($kernel,$self,$id) = @_[KERNEL,OBJECT,ARG0];
Subroutine _conn_alarm: not called CC=2 SCAR=17.9
380 0 ▶ return unless $self->_conn_exists( $id );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_conn_exists($id) 0 0 0
381 0 $self->_delete_client( $id );
382 0 $self->_send_event( 'socksd_disconnected', $id );
383 0 return;
384 }
385  
386 sub _delete_client {
387 0 ▶ my ($self,$id) = @_;
Subroutine _delete_client: not called CC=6 SCAR=37.4
388 0 ▶ return unless $self->_conn_exists( $id );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_conn_exists($id) 0 0 0
389 0 my $client = delete $self->{clients}->{ $id };
390 0 ▶ if ( $client->{link_id} and $self->_link_exists( $client->{link_id} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($client->{"link_id"} and $self->_link_exists($client->{"link_id"})) 0 0 0
Condition0%0/3
$client->{"link_id"} and $self->_link_exists($client->{"link_id"})
!ll&&!rl&&r
000
MC/DC0%0/2
$client->{"link_id"} and $self->_link_exists($client->{"link_id"})
$client->{"link_id"} $self->_link_exists($client->{"link_id"})
Truth table0%0/3
A and B
A= $client->{"link_id"}B= $self->_link_exists($client->{"link_id"})
ABresult
0X0
100
111
391 0 delete $self->{links}->{ $client->{link_id} };
392 }
393 0 ▶ if ( $client->{factory} and $self->_sock_exists( $client->{factory} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($client->{"factory"} and $self->_sock_exists($client->{"factory"})) 0 0 0
Condition0%0/3
$client->{"factory"} and $self->_sock_exists($client->{"factory"})
!ll&&!rl&&r
000
MC/DC0%0/2
$client->{"factory"} and $self->_sock_exists($client->{"factory"})
$client->{"factory"} $self->_sock_exists($client->{"factory"})
Truth table0%0/3
A and B
A= $client->{"factory"}B= $self->_sock_exists($client->{"factory"})
ABresult
0X0
100
111
394 0 delete $self->{sockets}->{ $client->{factory} };
395 }
396 0 return 1;
397 }
398  
399 sub _do_connect {
400 0 ▶ my ($kernel,$self,$id) = @_[KERNEL,OBJECT,ARG0];
Subroutine _do_connect: not called CC=2 SCAR=17.9
401 0 ▶ return unless $self->_conn_exists( $id );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_conn_exists($id) 0 0 0
402 0 my $client = $self->{clients}->{ $id };
403 my $factory = POE::Wheel::SocketFactory->new(
404 SocketDomain => AF_INET,
405 SocketType => SOCK_STREAM,
406 SocketProtocol => 'tcp',
407 RemoteAddress => $client->{dstip},
408 RemotePort => $client->{dstport},
409 0 SuccessEvent => '_sock_up',
410 FailureEvent => '_sock_failed',
411 );
412 0 my $fact_id = $factory->ID();
413 0 $client->{factory} = $fact_id;
414 0 $self->{sockets}->{ $fact_id } = { client => $id, factory => $factory };
415 0 return;
416 }
417  
418 sub _do_bind {
419 0 ▶ my ($kernel,$self,$id) = @_[KERNEL,OBJECT,ARG0];
Subroutine _do_bind: not called CC=7 SCAR=40.3
420 0 ▶ return unless $self->_conn_exists( $id );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_conn_exists($id) 0 0 0
421 0 my $client = $self->{clients}->{ $id };
422 0 my $primary = $client->{primary};
423 0 ▶ return unless $self->_conn_exists( $primary );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_conn_exists($primary) 0 0 0
424 0 my $link_id = $self->{clients}->{ $primary }->{link_id};
425 0 ▶ return unless $link_id or $self->_link_exists( $link_id );
Branch: 1 branch
BranchTrueFalseTotal
unless $link_id or $self->_link_exists($link_id) 0 0 0
Condition0%0/3
$link_id or $self->_link_exists($link_id)
l!l&&r!l&&!r
000
MC/DC0%0/2
$link_id or $self->_link_exists($link_id)
$link_id $self->_link_exists($link_id)
Truth table0%0/3
A or B
A= $link_idB= $self->_link_exists($link_id)
ABresult
1X1
011
000
426 0 my $bindaddr = $self->{links}->{ $link_id }->{sockaddr};
427 0 my $factory = POE::Wheel::SocketFactory->new(
428 SocketDomain => AF_INET,
429 SocketType => SOCK_STREAM,
430 SocketProtocol => 'tcp',
431 BindAddress => $bindaddr,
432 BindPort => 0,
433 Reuse => 'yes',
434 SuccessEvent => '_sock_connection',
435 FailureEvent => '_sock_failed',
436 );
437 0 my $sockname = $factory->getsockname();
438 0 ▶ unless ( $sockname ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sockname) 0 0 0
439 0 $kernel->yield( '_reject_client', $id, '91', 'Socket failed' );
440 0 return;
441 }
442 0 my ($port, $myaddr) = sockaddr_in( $sockname );
443 0 my $fact_id = $factory->ID();
444 0 $client->{factory} = $fact_id;
445 0 $self->{sockets}->{ $fact_id } = { client => $id, factory => $factory };
446 0 ▶ $self->{sockets}->{ $fact_id }->{alarm} = $kernel->delay_set( '_sock_alarm', $self->{time_out} || 120, $fact_id, $id );
Condition0%0/2
$self->{'time_out'} || 120
l!l
00
MC/DC0%0/1
$self->{'time_out'} || 120
$self->{'time_out'}
Truth table0%0/2
A
A= $self->{'time_out'}
Aresult
11
00
447 0 my $response = pack "CCnN", 0, 90, $port, $myaddr;
448 0 $client->{wheel}->put( $response );
449 0 $self->_send_event( 'socksd_bind_up', $id, $fact_id, inet_ntoa( $myaddr ), $port );
450 0 return;
451 }
452  
453 sub _sock_failed {
454 0 ▶ my ($kernel,$self,$op,$errno,$errstr,$fact_id) = @_[KERNEL,OBJECT,ARG0..ARG3];
Subroutine _sock_failed: not called CC=2 SCAR=17.9
455 0 my $factory = delete $self->{sockets}->{ $fact_id };
456 0 $kernel->alarm_remove( $factory->{alarm} );
457 0 my $client_id = $factory->{client};
458 0 ▶ delete $self->{clients}->{ $client_id }->{factory} if $self->_conn_exists( $client_id );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_conn_exists($client_id) 0 0 0
459 0 $kernel->yield( '_reject_client', $client_id, '91', 'Socket failed', $op, $errno, $errstr );
460 0 return;
461 }
462  
463 sub _sock_up {
464 0 ▶ my ($kernel,$self,$socket,$fact_id) = @_[KERNEL,OBJECT,ARG0,ARG3];
Subroutine _sock_up: not called CC=2 SCAR=17.9
465 0 my $sockaddr = inet_ntoa( ( unpack_sockaddr_in ( getsockname $socket ) )[1] );
466 0 my $sockport = ( unpack_sockaddr_in ( getsockname $socket ) )[0];
467 0 my $factory = delete $self->{sockets}->{ $fact_id };
468 0 my $client_id = $factory->{client};
469 0 ▶ return unless $self->_conn_exists( $client_id );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_conn_exists($client_id) 0 0 0
470 0 my $wheel = POE::Wheel::ReadWrite->new(
471 Handle => $socket,
472 Filter => POE::Filter::Stream->new(),
473 InputEvent => '_sock_input',
474 ErrorEvent => '_sock_down',
475 );
476 0 my $link_id = $wheel->ID();
477 0 $self->{clients}->{ $client_id }->{link_id} = $link_id;
478 0 $self->{links}->{ $link_id } = { client => $client_id, wheel => $wheel, sockaddr => $sockaddr, sockport => $sockport };
479 0 my $client = $self->{clients}->{ $client_id };
480 0 my $response = pack "CCnN", 0, 90, $client->{dstport}, unpack("N", inet_aton( $client->{dstip}) );
481 0 $client->{wheel}->put( $response );
482 0 $self->_send_event( 'socksd_sock_up', $client_id, $link_id, $client->{dstip}, $client->{dstport} );
483 0 return;
484 }
485  
486 sub _sock_connection {
487 0 ▶ my ($kernel,$self,$socket,$peeraddr,$fact_id) = @_[KERNEL,OBJECT,ARG0,ARG1,ARG3];
Subroutine _sock_connection: not called CC=3 SCAR=24.8
488 0 my $sockaddr = inet_ntoa( ( unpack_sockaddr_in ( getsockname $socket ) )[1] );
489 0 my $sockport = ( unpack_sockaddr_in ( getsockname $socket ) )[0];
490 0 $peeraddr = inet_ntoa( $peeraddr );
491 0 my $factory = delete $self->{sockets}->{ $fact_id };
492 0 $kernel->alarm_remove( $factory->{alarm} );
493 0 my $client_id = $factory->{client};
494 0 ▶ return unless $self->_conn_exists( $client_id );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_conn_exists($client_id) 0 0 0
495 0 my $client = $self->{clients}->{ $client_id };
496 0 ▶ unless ( $peeraddr eq $client->{dstip} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($peeraddr eq $client->{"dstip"}) 0 0 0
497 0 $kernel->yield( '_reject_client', $client_id, '91', 'dstip and connecting ip differ' );
498 0 return;
499 }
500 0 my $wheel = POE::Wheel::ReadWrite->new(
501 Handle => $socket,
502 Filter => POE::Filter::Stream->new(),
503 InputEvent => '_sock_input',
504 ErrorEvent => '_sock_down',
505 );
506 0 my $link_id = $wheel->ID();
507 0 $client->{link_id} = $link_id;
508 0 $self->{links}->{ $link_id } = { client => $client_id, wheel => $wheel, sockaddr => $sockaddr, sockport => $sockport };
509 0 my $response = pack "CCnN", 0, 90, $sockport, inet_aton( $sockaddr );
510 0 $client->{wheel}->put( $response );
511 0 $self->_send_event( 'socksd_sock_up', $client_id, $link_id, $sockaddr, $sockport );
512 0 return;
513 }
514  
515 sub _sock_alarm {
516 0 ▶ my ($kernel,$self,$fact_id,$client_id) = @_[KERNEL,OBJECT,ARG0..ARG1];
Subroutine _sock_alarm: not called CC=1 SCAR=6.9
517 0 delete $self->{sockets}->{ $fact_id };
518 0 delete $self->{clients}->{ $client_id };
519 0 return;
520 }
521  
522 sub _sock_input {
523 0 ▶ my ($kernel,$self,$input,$link_id) = @_[KERNEL,OBJECT,ARG0,ARG1];
Subroutine _sock_input: not called CC=3 SCAR=24.8
524 0 ▶ return unless $self->_link_exists( $link_id );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_link_exists($link_id) 0 0 0
525 0 my $client_id = $self->{links}->{ $link_id }->{client};
526 0 ▶ return unless $self->_conn_exists( $client_id );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_conn_exists($client_id) 0 0 0
527 0 $self->{clients}->{ $client_id }->{wheel}->put( $input );
528 0 return;
529 }
530  
531 sub _sock_down {
532 0 ▶ my ($self,$errstr,$link_id) = @_[OBJECT,ARG2,ARG3];
Subroutine _sock_down: not called CC=4 SCAR=30.0
533 0 ▶ return unless $self->_link_exists( $link_id );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_link_exists($link_id) 0 0 0
534 0 my $client_id = $self->{links}->{ $link_id }->{client};
535 0 $self->{clients}->{$client_id}->{wheel}->flush;
536 0 my $link = delete $self->{links}->{ $link_id };
537 0 ▶ if ( $link->{client} and $self->_conn_exists( $link->{client} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($link->{"client"} and $self->_conn_exists($link->{"client"})) 0 0 0
Condition0%0/3
$link->{"client"} and $self->_conn_exists($link->{"client"})
!ll&&!rl&&r
000
MC/DC0%0/2
$link->{"client"} and $self->_conn_exists($link->{"client"})
$link->{"client"} $self->_conn_exists($link->{"client"})
Truth table0%0/3
A and B
A= $link->{"client"}B= $self->_conn_exists($link->{"client"})
ABresult
0X0
100
111
538 0 delete $self->{clients}->{ $link->{client} };
539 }
540 0 $self->_send_event( 'socksd_sock_down', $link->{client}, $link_id, $errstr );
541 0 $self->_send_event( 'socksd_disconnected', $link->{client} );
542 0 return;
543 }
544  
545 sub register {
546 0 ▶ my ($kernel, $self, $session, $sender, @events) =
Subroutine register: not called CC=6 SCAR=37.4
Pod documented
547 @_[KERNEL, OBJECT, SESSION, SENDER, ARG0 .. $#_];
548  
549 0 ▶ unless (@events) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@events) 0 0 0
550 0 warn "register: Not enough arguments";
551 0 return;
552 }
553  
554 0 my $sender_id = $sender->ID();
555  
556 0 foreach (@events) {
557 0 ▶ $_ = "socksd_" . $_ unless /^_/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^_/ 0 0 0
558 0 $self->{events}->{$_}->{$sender_id} = $sender_id;
559 0 $self->{sessions}->{$sender_id}->{'ref'} = $sender_id;
560 0 ▶ unless ($self->{sessions}->{$sender_id}->{refcnt}++ or $session == $sender) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"sessions"}{$sender_id}{"refcnt"}++ or $session == $sender) 0 0 0
Condition0%0/3
$self->{"sessions"}{$sender_id}{"refcnt"}++ or $session == $sender
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"sessions"}{$sender_id}{"refcnt"}++ or $session == $sender
$self->{"sessions"}{$sender_id}{"refcnt"}++ $session == $sender
Truth table0%0/3
A or B
A= $self->{"sessions"}{$sender_id}{"refcnt"}++B= $session == $sender
ABresult
1X1
011
000
561 0 $kernel->refcount_increment($sender_id, __PACKAGE__);
562 }
563 }
564  
565 0 $kernel->post( $sender, 'socksd_registered', $self );
566 0 return;
567 }
568  
569 sub unregister {
570 0 ▶ my ($kernel, $self, $session, $sender, @events) =
Subroutine unregister: not called CC=2 SCAR=17.9
Pod documented
571 @_[KERNEL, OBJECT, SESSION, SENDER, ARG0 .. $#_];
572  
573 0 ▶ unless (@events) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@events) 0 0 0
574 0 warn "unregister: Not enough arguments";
575 0 return;
576 }
577  
578 0 $self->_unregister($session,$sender,@events);
579 0 undef;
580 }
581  
582 sub _unregister {
583 0 ▶ my ($self,$session,$sender) = splice @_,0,3;
Subroutine _unregister: not called CC=6 SCAR=37.4
584 0 my $sender_id = $sender->ID();
585  
586 0 foreach (@_) {
587 0 ▶ $_ = "socksd_" . $_ unless /^_/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^_/ 0 0 0
588 0 my $blah = delete $self->{events}->{$_}->{$sender_id};
589 0 ▶ unless ( $blah ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($blah) 0 0 0
590 0 warn "$sender_id hasn't registered for '$_' events\n";
591 0 next;
592 }
593 0 ▶ if (--$self->{sessions}->{$sender_id}->{refcnt} <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$self->{"sessions"}{$sender_id}{"refcnt"} <= 0) 0 0 0
594 0 delete $self->{sessions}->{$sender_id};
595 0 ▶ unless ($session == $sender) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($session == $sender) 0 0 0
596 0 $poe_kernel->refcount_decrement($sender_id, __PACKAGE__);
597 }
598 }
599 }
600 0 undef;
601 }
602  
603 sub _unregister_sessions {
604 1 ▶ my $self = shift;
Subroutine _unregister_sessions: called CC=4 SCAR=14.1
605 1 my $socksd_id = $self->session_id();
606 1 foreach my $session_id ( keys %{ $self->{sessions} } ) {
607 1 ▶ if (--$self->{sessions}->{$session_id}->{refcnt} <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$self->{"sessions"}{$session_id}{"refcnt"} <= 0) 1 0 1
608 1 delete $self->{sessions}->{$session_id};
609 1 ▶ $poe_kernel->refcount_decrement($session_id, __PACKAGE__)
Branch: 1 branch
BranchTrueFalseTotal
unless $session_id eq $socksd_id 1 0 1
610 unless ( $session_id eq $socksd_id );
611 }
612 }
613 }
614  
615 sub __send_event {
616 0 ▶ my( $self, $event, @args ) = @_[ OBJECT, ARG0, ARG1 .. $#_ ];
Subroutine __send_event: not called CC=1 SCAR=6.9
617 0 $self->_send_event( $event, @args );
618 0 return;
619 }
620  
621 sub send_event {
622 0 ▶ my $self = shift;
Subroutine send_event: not called CC=1 SCAR=6.9
Pod documented
623 0 $poe_kernel->post( $self->{session_id}, '__send_event', @_ );
624 }
625  
626 sub _send_event {
627 0 ▶ my $self = shift;
Subroutine _send_event: not called CC=3 SCAR=24.8
628 0 my ($event, @args) = @_;
629 0 my $kernel = $POE::Kernel::poe_kernel;
630 0 my $session = $kernel->get_active_session()->ID();
631 0 my %sessions;
632  
633 0 $sessions{$_} = $_ for (values %{$self->{events}->{'socksd_all'}}, values %{$self->{events}->{$event}});
634  
635 0 $kernel->post( $_ => $event => @args ) for values %sessions;
636 0 undef;
637 }
638  
639 ##################
640 # Access Control #
641 ##################
642  
643 sub add_denial {
644 0 ▶ my $self = shift;
Subroutine add_denial: not called CC=3 SCAR=24.8
Pod documented
645 0 ▶ my $netmask = shift || return;
Condition0%0/2
shift() || (return)
l!l
00
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
646 0 ▶ return unless $netmask->isa('Net::Netmask');
Branch: 1 branch
BranchTrueFalseTotal
unless $netmask->isa("Net::Netmask") 0 0 0
647 0 $self->{denials}->{ $netmask } = $netmask;
648 0 return 1;
649 }
650
651 sub del_denial {
652 0 ▶ my $self = shift;
Subroutine del_denial: not called CC=4 SCAR=30.0
Pod documented
653 0 ▶ my $netmask = shift || return;
Condition0%0/2
shift() || (return)
l!l
00
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
654 0 ▶ return unless $netmask->isa('Net::Netmask');
Branch: 1 branch
BranchTrueFalseTotal
unless $netmask->isa("Net::Netmask") 0 0 0
655 0 ▶ return unless $self->{denials}->{ $netmask };
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"denials"}{$netmask} 0 0 0
656 0 delete $self->{denials}->{ $netmask };
657 0 return 1;
658 }
659  
660 sub add_exemption {
661 0 ▶ my $self = shift;
Subroutine add_exemption: not called CC=4 SCAR=30.0
Pod documented
662 0 ▶ my $netmask = shift || return;
Condition0%0/2
shift() || (return)
l!l
00
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
663 0 ▶ return unless $netmask->isa('Net::Netmask');
Branch: 1 branch
BranchTrueFalseTotal
unless $netmask->isa("Net::Netmask") 0 0 0
664 0 ▶ $self->{exemptions}->{ $netmask } = $netmask unless $self->{exemptions}->{ $netmask };
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"exemptions"}{$netmask} 0 0 0
665 0 return 1;
666 }
667  
668 sub del_exemption {
669 0 ▶ my $self = shift;
Subroutine del_exemption: not called CC=4 SCAR=30.0
Pod documented
670 0 ▶ my $netmask = shift || return;
Condition0%0/2
shift() || (return)
l!l
00
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
671 0 ▶ return unless $netmask->isa('Net::Netmask');
Branch: 1 branch
BranchTrueFalseTotal
unless $netmask->isa("Net::Netmask") 0 0 0
672 0 ▶ return unless $self->{exemptions}->{ $netmask };
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"exemptions"}{$netmask} 0 0 0
673 0 delete $self->{exemptions}->{ $netmask };
674 0 return 1;
675 }
676  
677 sub denied {
678 0 ▶ my $self = shift;
Subroutine denied: not called CC=5 SCAR=34.0
Pod documented
679 0 ▶ my $ipaddr = shift || return;
Condition0%0/2
shift() || (return)
l!l
00
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
680 0 ▶ return 0 if $self->exempted( $ipaddr );
Branch: 1 branch
BranchTrueFalseTotal
if $self->exempted($ipaddr) 0 0 0
681 0 foreach my $mask ( keys %{ $self->{denials} } ) {
682 0 ▶ return 1 if $self->{denials}->{ $mask }->match($ipaddr);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"denials"}{$mask}->match($ipaddr) 0 0 0
683 }
684 0 return 0;
685 }
686  
687 sub exempted {
688 0 ▶ my $self = shift;
Subroutine exempted: not called CC=4 SCAR=30.0
Pod documented
689 0 ▶ my $ipaddr = shift || return;
Condition0%0/2
shift() || (return)
l!l
00
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
690 0 foreach my $mask ( keys %{ $self->{exemptions} } ) {
691 0 ▶ return 1 if $self->{exemptions}->{ $mask }->match($ipaddr);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"exemptions"}{$mask}->match($ipaddr) 0 0 0
692 }
693 0 return 0;
694 }
695  
696 3 1;
697 __END__
↑ Summary