blib/lib/Net/DNSBL/MultiDaemon.pm

filter: Statementstmt 71.2% 350 / 491 Branchbran 56.3% 186 / 330 Conditioncond 40.7% 140 / 344 MC/DCmcdc 15.8% 26 / 164 Subroutinesub 83.3% 20 / 24 Podpod 25.0% 3 / 12 totaltotal 53.1% 725 / 1365 CC 292 SCAR 85.1
CC
292
Cov
58%
run
6531.5
setURBLdom
38.1
__ANON__
20.0
CRAP 4958.6
↑ Summary blib/lib/Net/DNSBL/Utilities.pm »
1 #!/usr/bin/perl
2 package Net::DNSBL::MultiDaemon;
3  
4 20 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 #use diagnostics;
6  
7 20 ▶use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
8 $VERSION @ISA @EXPORT_OK %EXPORT_TAGS *R_Sin
9 $D_CLRRUN $D_SHRTHD $D_TIMONLY $D_QRESP $D_NOTME $D_ANSTOP $D_VERBOSE
10 20 );
11 20 require Exporter;
12 20 @ISA = qw(Exporter);
13  
14 # DEBUG is a set of semaphores
15 20 $D_CLRRUN = 0x1; # clear run flag and force unconditional return
16 20 $D_SHRTHD = 0x2; # return short header message
17 20 $D_TIMONLY = 0x4; # exit at end of timer section
18 20 $D_QRESP = 0x8; # return query response message
19 20 $D_NOTME = 0x10; # return received response not for me
20 20 $D_ANSTOP = 0x20; # clear run OK flag if ANSWER present
21 20 $D_VERBOSE = 0x40; # verbose debug statements to STDERR
22  
23 20 $VERSION = do { my @r = (q$Revision: 0.39 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
24  
25 20 @EXPORT_OK = qw(
26 run
27 bl_lookup
28 set_extension
29 );
30 20 %EXPORT_TAGS = (
31 debug => [qw($D_CLRRUN $D_SHRTHD $D_TIMONLY $D_QRESP $D_NOTME $D_ANSTOP $D_VERBOSE uniqueID)],
32 );
33 20 Exporter::export_ok_tags('debug');
34  
35 20 my $FATans = 0; # this causes a response size overflow from some DNSBLS that have
36 # many mirrors, so only the local host authority record is returned
37  
38 10 ▶sub fatreturn { return $FATans }; # for testing
Subroutine fatreturn: called CC=1 SCAR=0.0
Pod undocumented
39  
40 20 my $eXT = undef; # extension code for "Private Use" as defined in outlined in RFC-6195
41 # Query types
42 # Classes
43 # Types
44  
45 20 ▶use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 20 ▶use Net::DNS::Codes qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
47 TypeTxt
48 T_A
49 T_AAAA
50 T_ANY
51 T_MX
52 T_CNAME
53 T_NS
54 T_TXT
55 T_SOA
56 T_AXFR
57 T_PTR
58 C_IN
59 PACKETSZ
60 HFIXEDSZ
61 QUERY
62 NOTIMP
63 FORMERR
64 NOERROR
65 REFUSED
66 NXDOMAIN
67 SERVFAIL
68 BITS_QUERY
69 RD
70 QR
71 CD
72 20 );
73 20 ▶use Net::DNS::ToolKit 0.16 qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
74 newhead
75 gethead
76 get_ns
77 20 );
78 20 ▶use Net::DNS::ToolKit::RR;
Subroutine BEGIN: called CC=1 SCAR=0.0
79 #use Net::DNS::ToolKit::Debug qw(
80 # print_head
81 # print_buf
82 #);
83  
84 #use Data::Dumper;
85  
86 20 ▶use Net::DNSBL::Utilities 0.07 qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
87 s_response
88 not_found
89 write_stats
90 statinit
91 A1271
92 A1272
93 A1274
94 A1275
95 A1276
96 A1277
97 list2NetAddr
98 matchNetAddr
99 setAUTH
100 setRA
101 20 );
102  
103 # target for queries about DNSBL zones, create once per session
104 # this is a global so it can be altered during testing
105 20 *R_Sin = \scalar sockaddr_in(53,scalar get_ns());
106  
107 =head1 NAME
108  
109 Net::DNSBL::MultiDaemon - multi DNSBL prioritization
110  
111 =head1 SYNOPSIS
112  
113 use Net::DNSBL::MultiDaemon qw(
114 :debug
115 run
116 bl_lookup
117 set_extension
118 );
119  
120 run($BLzone,$L,$R,$DNSBL,$STATs,$Run,$Sfile,$StatStamp,$DEBUG)
121 bl_lookup($put,$mp,$rtp,$sinaddr,$alarm,$rid,$id,$rip,$type,$zone,@blist);
122  
123 =head1 DESCRIPTION
124  
125 B<Net::DNSBL::MultiDaemon> is the Perl module that implements the B<multi_dnsbl>
126 daemon.
127  
128 B<multi_dnsbl> is a DNS emulator daemon that increases the efficacy of DNSBL
129 look-ups in a mail system. B<multi_dnsbl> may be used as a stand-alone DNSBL
130 or as a plug-in for a standard BIND 9 installation.
131 B<multi_dnsbl> shares a common configuration file format with the
132 Mail::SpamCannibal sc_BLcheck.pl script so that DNSBL's can be maintained in
133 a common configuration file for an entire mail installation.
134  
135 Because DNSBL usefulness is dependent on the nature and source of spam sent to a
136 specific site and because sometimes DNSBL's may provide intermittant
137 service, B<multi_dnsbl> interrogates them sorted in the order of B<greatest
138 successful hits>. DNSBL's that do not respond within the configured timeout
139 period are not interrogated at all after 6 consecutive failures, and
140 thereafter will be retried not more often than once every hour until they
141 come back online. This eliminates the need to place DNSBL's in a particular order in
142 your MTA's config file or periodically monitor the DNSBL statistics and/or update
143 the MTA config file.
144  
145 In addition to optimizing DNSBL interrogation, B<multi_dnsbl> may be
146 configured to locally accept or reject specified IP's, IP ranges and to
147 reject specified countries by 2 character country code. By adding a DNSBL
148 entry of B<in-addr.arpa>, IP's will be rejected that do not return some kind
149 of valid reverse DNS lookup. In addition, IP's can be rejected that have a
150 PTR record that matchs a configurable GENERIC 'regexp' set.
151  
152 Reject codes are as follows:
153  
154 query 2.0.0.127.{zonename} 127.0.0.2
155 blocked by configured DNSBL 127.0.0.2
156 no reverse DNS 127.0.0.4
157 BLOCKED (local blacklist) 127.0.0.5
158 Blocked by Country 127.0.0.6
159 Blocked GENERIC 127.0.0.7
160  
161 =head1 OPERATION
162  
163 The configuration file for B<multi_dnsbl> contains optional IGNORE (always
164 pass), optional BLOCK (always reject), and optional BBC (block by country) entries against
165 which all received queries are checked before external DNSBL's are queried.
166 IP's which pass IGNORE, BLOCK, and BBC test are then checked against the
167 prioritized list of DNSBL's to try when looking up an IP address for blacklisting.
168 Internally, B<multi_dnsbl> maintains this list in sorted order (including
169 'in-addr.arpa') based on the number of responses that
170 resulted in an acceptable A record being returned from the DNSBL query. For
171 each IP address query sent to B<multi_dnsbl>, a query is sent to each
172 configured DNSBL sequentially until all DNSBL's have been queried or an
173 acceptable A record is returned.
174  
175 Let us say for example that blackholes.easynet.nl (below) will return an A record
176 and list.dsbl.org, bl.spamcop.net, dynablock.easynet.nl, will not.
177  
178 LIST
179 9451 list.dsbl.org
180 6516 bl.spamcop.net
181 2350 dynablock.easynet.nl
182 575 blackholes.easynet.nl
183 327 cbl.abuseat.org
184 309 dnsbl.sorbs.net
185 195 dnsbl.njabl.org
186 167 sbl.spamhaus.org
187 22 spews.dnsbl.net.au
188 6 relays.ordb.org
189 1 proxies.blackholes.easynet.nl
190 0 dsbl.org
191  
192 A query to B<multi_dnsbl> (pseudo.dnsbl in this example) looks like this
193  
194 QUERY
195 1.2.3.4.pseudo.dnsbl
196 |
197 V
198 ####################
199 # multi_dnsbl #
200 ####################
201 | RESPONSE
202 +--> 1.2.3.4.list.dsbl.org NXDOMAIN
203 |
204 +--> 1.2.3.4.bl.spamcop.net NXDOMAIN
205 |
206 +--> 1.2.3.4.dynablock.easynet.nl NXDOMAIN
207 |
208 +--> 1.2.3.4.blackholes.easynet.nl A-127.0.0.2
209  
210 The A record is returned to originator of the Query and the statistics count
211 on blackholes.easynet.nl is incremented by one.
212  
213 =head1 INSTALLATION / CONFIGURATION / OPERATION
214  
215 B<multi_dnsbl> can be installed as either a standalone DNSBL or as a plug-in
216 to a BIND 9 installation on the same host. In either case, copy the
217 rc.multi_daemon script to the appropriate startup directory on your host and
218 modify the start, stop, restart scripts as required. Operation of the script
219 is as follows:
220  
221 Syntax: ./rc.multi_dnsbl start /path/to/config.file
222 ./rc.multi_dnsbl start -v /path/to/config.file
223 ./rc.multi_dnsbl stop /path/to/config.file
224 ./rc.multi_dnsbl restart /path/to/config.file
225  
226 The -v switch will print the scripts
227 actions verbosely to the STDERR.
228  
229 =head2 CONFIGURATION FILE
230  
231 The configuration file for B<multi_dnsbl> shares a common format with the
232 Mail::SpamCannibal sc_BLcheck.pl script, facilitating common maintenance of
233 DNSBL's for your MTA installation.
234  
235 The sample configuration file
236 B<multi_dnsbl.conf.sample> is heavily commented with the details for each
237 configuration element. If you plan to use a common configuration file in a
238 SpamCannibal installation, simply add the following elements to the
239 B<sc_BlackList.conf> file:
240  
241 MDstatfile => '/path/to/statistics/file.txt',
242 MDpidpath => '/path/to/pidfiles', # /var/run
243 MDzone => 'pseudo.dnsbl',
244  
245 # OPTIONAL
246 MDstatrefresh => 300, # seconds
247 MDipaddr => '0.0.0.0', # PROBABLY NOT WHAT YOU WANT
248 MDport => 9953,
249 MDcache => 10000, # an entry takes ~400 bytes
250 # default 10000 (to small)
251
252 ### WARNING ###
253 failure to set MDipaddr to a valid ip address will result
254 in the authority section return an NS record of INADDR_ANY
255 This will return an invalid NS record in stand alone operation
256  
257 =head2 STANDALONE OPERATION
258  
259 For standalone operation, simply set B<MDport = 53>, nothing more is
260 required.
261  
262 Interrogating the installation will then return the first
263 match from the configured list of DNSBL servers.
264  
265 i.e. dig 2.0.0.127.pseudo.dnsbl
266  
267 .... results
268  
269 =head2 PLUGIN to BIND 9
270  
271 B<multi_dnsbl> may be used as a plugin helper for a standard bind 9
272 installation by adding a B<forward> zone to the configuration file as
273 follows:
274  
275 //zone pseudo.dnsbl
276 zone "pseudo.dnsbl" in {
277 type forward;
278 forward only;
279 forwarders {
280 127.0.0.1 port 9953;
281 };
282 };
283  
284 You may also wish to add one or more of the following statements with
285 appropriate address_match_lists to restrict access to the facility.
286  
287 allow-notify {};
288 allow-query { address_match_list };
289 allow-recursion { address_match_list };
290 allow-transfer {};
291  
292 =head2 MTA CONFIGURATION
293  
294 Access to DNSBL lookup is configured in the normal fashion for each MTA.
295 Since MTA's generally must interrogate on port 53, B<multi_dnsbl> must be
296 installed on a stand-alone server or as a plugin for BIND 9.
297  
298 A typical configuration line for B<sendmail M4> configuration file is shown
299 below:
300  
301 FEATURE(`dnsbl',`pseudo.dnsbl',
302 `554 Rejected $&{client_addr} found in http://www.my.blacklist.org')dnl
303  
304 =head1 SYSTEM SIGNALS
305  
306 B<multi_dnsbl> responds to the following system signals:
307  
308 =over 4
309  
310 =item * TERM
311  
312 Operations the statistics file is updated with the internal counts and the
313 daemon then exits.
314  
315 =item * HUP
316  
317 Operations are stopped including an update of the optional statistics file,
318 the configuration file is re-read and operations are restarted.
319  
320 =item * USR1
321  
322 The statistics file is updated on the next second tick.
323  
324 =item * USR2
325  
326 The statistics file is deleted, internal statistics then a new (empty)
327 statistics file is written on the next second tick.
328  
329 =back
330  
331 =head1 PERL MODULE DESCRIPTION
332  
333 B<Net::DNSBL::MultiDaemon> provides most of the functions that implement
334 B<multi_dnsbl> which is an MTA helper that interrogates a list of
335 DNSBL servers in preferential order based on their success rate.
336  
337 The following describes the workings of individual functions
338 used to implement B<multi_dnsbl>.
339  
340 =over 4
341  
342 =item * run($BLzone,$L,$R,$DNSBL,$STATs,$Run,$Sfile,$StatStamp,$DEBUG);
343  
344 This function is the 'run' portion for the DNSBL multidaemon
345  
346 input:
347 $BLzone zone name,
348 $L local listen socket object pointer,
349 $R remote socket object pointer,
350 $DNSBL config hash pointer,
351 $STATs statistics hash pointer
352 $Run pointer to stats refresh time, # must be non-zero
353 $Sfile statistics file path,
354 $StatStamp stat file initial time stamp
355  
356 returns: nothing
357  
358 =over 2
359  
360 =item * $BLzone
361  
362 The fully qualified domain name of the blacklist lookup
363  
364 =item * $L
365  
366 A pointer to a UDP listener object
367  
368 =item * $R
369  
370 A pointer to a unbound UDP socket
371 used for interogation and receiving replies for the multiple DNSBL's
372  
373 =item * $DNSBL
374  
375 A pointer to the configuration hash of the form:
376  
377 $DNSBL = {
378 # Always allow these addresses
379 'IGNORE' => [ # OPTIONAL
380 # a single address
381 '11.22.33.44',
382 # a range of ip's, ONLY VALID WITHIN THE SAME CLASS 'C'
383 '22.33.44.55 - 22.33.44.65',
384 # a CIDR range
385 '5.6.7.16/28',
386 # a range specified with a netmask
387 '7.8.9.128/255.255.255.240',
388 # you may want these
389 '10.0.0.0/8',
390 '172.16.0.0/12',
391 '192.168.0.0/16',
392 # this should ALWAYS be here
393 '127.0.0.0/8', # ignore all test entries and localhost
394 ],
395  
396 # Do rhbl lookups only, default false
397 # all other rejection classes are disabled, IGNORE, BLOCK, BBC, in-addr.arpa
398 # RHBL need only be "true" for operation. If OPTIONAL URBL conditioning
399 # is needed, then the parameters in the has must be added
400 RHBL => { # optional URBL preparation
401 urblwhite => [
402 '/path/to/cached/whitefile',
403 '/path/to/local/file' # see format of spamassassin file
404 ],
405 urblblack => [
406 '/path/to/local/blacklist'
407 ],
408 # NOTE: level 3 tld's should be first before level 2 tld's
409 urbltlds => [
410 '/path/to/cached/tld3file',
411 '/path/to/cached/tld2file'
412 ],
413 urlwhite => [
414 'http://spamassasin.googlecode.com/svn-history/r6/trunk/share/spamassassin/25_uribl.cf',
415 '/path/to/cached/whitefile'
416 ],
417 urltld3 => [
418 'http://george.surbl.org/three-level-tlds',
419 '/path/to/cached/tld3file'
420 ],
421 urltld2 => [
422 'http://george.surbl.org/two-level-tlds',
423 '/path/to/cached/tld2file'
424 ],
425 },
426  
427 # Authoratative answers
428 'AUTH' => 0,
429  
430 # Always reject these addresses
431 'BLOCK' => [ # OPTIONAL
432 # same format as above
433 ],
434  
435 # Always block these countries
436 'BBC' => [qw(CN TW RO )],
437  
438 # Check for reverse lookup failures - OPTIONAL
439 'in-addr.arpa' => {
440 timeout => 15, # default timeout is 30
441 },
442  
443 # RBL zones as follows: OPTIONAL
444 'domain.name' => {
445 # mark this dnsbl to require right hand side domain processing
446 # requires URBL::Prepare
447 # NOT IMPLEMENTED
448 # urbl => 1,
449 acceptany => 'comment - treat any response as valid',
450 # or
451 accept => {
452 '127.0.0.2' => 'comment',
453 '127.0.0.3' => 'comment',
454 },
455 # or
456 # mask the low 8 bits and accept any true result
457 acceptmask => 0x3D, # accepts 0011 1101
458  
459 # timeout => 30, # default seconds to wait for dnsbl
460 },
461  
462 'next.domain' = {
463 etc....
464 # included but extracted external to B<run>
465  
466 MDzone => 'pseudo.dnsbl',
467 MDstatfile => '/path/to/statistics/file.txt',
468 MDpidpath => '/path/to/pidfiles
469 # OPTIONAL, defaults shown
470 # MDstatrefresh => 300, # max seconds for refresh
471 # MDipaddr => '0.0.0.0', # PROBABLY NOT WHAT YOU WANT
472 # MDport => 9953,
473 # syslog. Specify the facility, one of:
474 # LOG_EMERG LOG_ALERT LOG_CRIT LOG_ERR LOG_WARNING LOG_NOTICE LOG_INFO LOG_DEBUG
475 # MDsyslog => 'LOG_WARNING',
476 #
477 # cache lookups using the TTL of the providing DNSBL
478 # each cache entry takes about 400 bytes, minimum size = 1000
479 # MDcache => 1000, # 1000 is too small
480 };
481  
482 Zone labels that are not of the form *.*... are ignored, making this hash
483 table fully compatible with the SpamCannibal sc_Blacklist.conf file.
484  
485 =item * $STATs
486  
487 A pointer to a statistics collection array of the form:
488  
489 $STATs = {
490 'domain.name' => count,
491 etc...,
492 'CountryCode' => count,
493 etc...
494 };
495  
496 Initialize this array with
497 cntinit($DNSBL,$cp) L<Net::DNSBL::Utilities>/cntinit, then
498 list2hash($BBC,$cp) L<Net::DNSBL::Utilities>/list2hash, then
499 statinit($Sfile,$cp) L<Net::DNSBL::Utilities>/statinit, below.
500  
501 =item * $Run
502  
503 A POINTER to the time in seconds to refresh the $STATs backing file. Even if
504 there is not backing file used, this value must be a positive integer.
505 Setting this value to zero will stop the daemon and force a restart. It is
506 used by $SIG{HUP} to restart the daemon.
507  
508 =item * $Sfile
509  
510 The path to the STATISTICS backing file.
511  
512 i.e. /some/path/to/filename.ext
513  
514 If $Sfile is undefined, then the time stamp need not be defined
515  
516 =item * $StatTimestamp
517  
518 Normally the value returned by
519 statinit($Sfile,$cp) L<Net::DNSBL::Utilities>/statinit, below.
520  
521 =back
522  
523 =cut
524  
525 20 my %AVGs = (); # averages
526 20 my %CNTs = (); # current counts
527 20 my $tick = 0; # second ticker
528 20 my $interval = 300; # averaging interval
529 20 my $bucket = 24 * 60 * 60; # 24 hours for now...
530 20 my $weight = 5; # weight new stuff higher than old stuff
531 20 my $csize = 0; # cache size and switch
532 20 my $cused = 0; # cache in use
533 20 my ($now, $next);
534 20 my $newstat; # new statistics flag, used by run
535  
536 578 ▶sub average {
Subroutine average: called CC=4 SCAR=14.0
Pod undocumented
537 578 my $STATs = shift;
538 578 my $multiplier = $bucket / ($bucket + (($now + $interval - $next) * $weight));
539 578 $next = $now + $interval; # next average event
540 578 foreach (keys %$STATs) {
541 1734 ▶ next unless $_ =~ /\./; # only real domains
Branch: 1 branch
BranchTrueFalseTotal
unless $_ =~ /\./ 0 1734 1734
542 1734 ▶ next unless exists $CNTs{"$_"};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $CNTs{"$_"} 0 1734 1734
543 1734 $AVGs{"$_"} = ($AVGs{"$_"} + ($weight * $CNTs{"$_"})) * $multiplier;
544 1734 $CNTs{"$_"} = 0;
545 }
546 }
547  
548 # increment statistics for "real" DNSBL's
549 # input: STATS pointer
550 # DNSBL string
551  
552 1 ▶sub bump_stats {
Subroutine bump_stats: called CC=3 SCAR=11.6
Pod undocumented
553 1 my($STATs, $blist_0) = @_;
554 1 $STATs->{"$blist_0"} += 1; # bump statistics count
555 1 ▶ if (exists $CNTs{"$blist_0"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $CNTs{"$blist_0"}) { } 0 1 1
556 0 $CNTs{"$blist_0"} += 1;
557 } else {
558 1 $CNTs{"$blist_0"} = 1;
559 1 $AVGs{"$blist_0"} = 1;
560 }
561 1 ▶ $newstat = 1 unless $newstat; # notify refresh that update may be needed
Branch: 1 branch
BranchTrueFalseTotal
unless $newstat 1 0 1
562 }
563  
564 465 ▶sub by_average {
Subroutine by_average: called CC=6 SCAR=18.0
Pod undocumented
565 465 my($STATs,$a,$b) = @_;;
566 465 ▶ if (exists $AVGs{"$b"} && exists $AVGs{"$a"}) {
Branch: 3 branches
BranchTrueFalseTotal
if (exists $AVGs{"$b"} and exists $AVGs{"$a"}) { } 4 461 465
elsif (exists $AVGs{"$b"}) { } 2 459 461
elsif (exists $AVGs{"$a"}) { } 1 458 459
Condition100%3/3
exists $AVGs{"$b"} and exists $AVGs{"$a"}
!ll&&!rl&&r
45924
MC/DC100%2/2
exists $AVGs{"$b"} and exists $AVGs{"$a"}
exists $AVGs{"$b"} exists $AVGs{"$a"}
Truth table100%3/3
A and B
A= exists $AVGs{"$b"}B= exists $AVGs{"$a"}
ABresult
0X0
100
111
567 return ($AVGs{"$b"} <=> $AVGs{"$a"})
568 ||
569 4 ▶ ($STATs->{"$b"} <=> $STATs->{"$a"});
Condition33%1/3
$AVGs{"$b"} <=> $AVGs{"$a"} || $$STATs{"$b"} <=> $$STATs{"$a"}
l!l&&r!l&&!r
400
MC/DC0%0/2
$AVGs{"$b"} <=> $AVGs{"$a"} || $$STATs{"$b"} <=> $$STATs{"$a"}
$AVGs{"$b"} <=> $AVGs{"$a"} $$STATs{"$b"} <=> $$STATs{"$a"}
Truth table33%1/3
A || B
A= $AVGs{"$b"} <=> $AVGs{"$a"}B= $$STATs{"$b"} <=> $$STATs{"$a"}
ABresult
1X1
011
000
570 }
571 elsif (exists $AVGs{"$b"}) {
572 2 return 1;
573 }
574 elsif (exists $AVGs{"$a"}) {
575 1 return -1;
576 } else {
577 458 return ($STATs->{"$b"} <=> $STATs->{"$a"});
578 }
579 }
580  
581 # reverse digits in ipV4 address
582 #
583 # input: ip
584 # returns: reversed ip
585 #
586 0 ▶sub revIP {
Subroutine revIP: not called CC=1 SCAR=6.9
Pod undocumented
587 0 join('.',reverse split /\./,$_[0]);
588 }
589  
590 # cache takes about 400 bytes per entry
591 #
592 20 my %cache = (
593 #
594 # ip address => {
595 # expires => time, now + TTL from response or 3600 minimum
596 # used => time, time cache item was last used
597 # who => $blist[0], which DNSBL caused caching
598 # txt => 'string', txt from our config file or empty
599 # },
600 );
601 20 my @topurge; # working array
602  
603 # for testing
604 # set now and next, csize return pointers to internal averaging arrays and cache
605 #
606 580 ▶sub set_nownext {
Subroutine set_nownext: called CC=1 SCAR=0.0
Pod undocumented
607 580 ($now,$next,$csize) = @_;
608 580 return($interval,\%AVGs,\%CNTs,\%cache,\@topurge);
609 }
610  
611 # purge cache when called from "run"
612  
613 20 my $prp = -1; # run pointer, see "mode" below
614 20 my $pai; # array index
615 my $pnd; # array end
616  
617 # piecewise purge of expired cache items performs gnome sort while purging
618 #
619 # followed by conditional purge of cache size overrun of oldest touched
620 # cache items or those that will expire the soonest
621 #
622 # input: nothing
623 # returns: mode
624 # -1 waiting to be initialized
625 # 0 purging expired elements + gnome sort
626 # 1 purging cache overrun
627  
628 324 ▶sub purge_cache {
Subroutine purge_cache: called CC=17 SCAR=28.7
Pod undocumented
629 324 ▶ if ($prp == 0) { # run state to purge expired elements
Branch: 2 branches
BranchTrueFalseTotal
if ($prp == 0) { } 308 16 324
elsif ($prp > 0) { } 12 4 16
630 308 my $k1 = $topurge[$pai];
631 #print STDERR "$pnd, $pai";
632 308 ▶ if (exists $cache{$k1}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $cache{$k1}) { } 307 1 308
633 307 my $j = $pai +1;
634 307 my $k2 = $topurge[$j];
635 307 ▶ if ($cache{$k1}->{expires} < $now) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cache{$k1}{'expires'} < $now) { } 0 307 307
elsif (exists $cache{$k2}) { } 306 1 307
636 0 delete $cache{$k1};
637 0 splice(@topurge,$pai,1); # remove element from cache array
638 0 $pnd--;
639 #print STDERR " delete k1 = $k1\n";
640 }
641 elsif (exists $cache{$k2}) {
642 306 ▶ if ($cache{$k2}->{expires} < $now) {
Branch: 2 branches
BranchTrueFalseTotal
if ($cache{$k2}{'expires'} < $now) { } 6 300 306
elsif ($cache{$k1}{'used'} > $cache{$k2}{'used'} or $cache{$k1}{'used'} == $cache{$k2}{'used'} and $cache{$k1}{'expires'} > $cache{$k2}{'expires'}) { } 133 167 300
643 6 delete $cache{$k2};
644 6 splice(@topurge,$j,1); # remove element from cache array
645 6 $pnd--;
646 #print STDERR " delete k2 = $k2\n";
647 }
648 ▶ elsif ( $cache{$k1}->{used} > $cache{$k2}->{used} # oldest use
Condition50%3/6
$cache{$k1}{"used"} > $cache{$k2}{"used"} or $cache{$k1}{"used"} == $cache{$k2}{"used"} and $cache{$k1}{"expires"} > $cache{$k2}{"expires"}
l!l&&r!l&&!r
1330167
$cache{$k1}{"used"} == $cache{$k2}{"used"} and $cache{$k1}{"expires"} > $cache{$k2}{"expires"}
!ll&&!rl&&r
16700
MC/DC33%1/3
$cache{$k1}{"used"} > $cache{$k2}{"used"} or $cache{$k1}{"used"} == $cache{$k2}{"used"} and $cache{$k1}{"expires"} > $cache{$k2}{"expires"}
$cache{$k1}{"used"} > $cache{$k2}{"used"} $cache{$k1}{"used"} == $cache{$k2}{"used"} $cache{$k1}{"expires"} > $cache{$k2}{"expires"}
Truth table50%2/4
A or B and C
A= $cache{$k1}{"used"} > $cache{$k2}{"used"}B= $cache{$k1}{"used"} == $cache{$k2}{"used"}C= $cache{$k1}{"expires"} > $cache{$k2}{"expires"}
ABCresult
1XX1
0111
00X0
0100
649 || ($cache{$k1}->{used} == $cache{$k2}->{used} # or if equal,
650 && $cache{$k1}->{expires} > $cache{$k2}->{expires}) # expires soonest
651 ) {
652 133 @topurge[$pai,$j] = @topurge[$j,$pai];
653 133 $pai--;
654 133 ▶ $pai = 0 if $pai < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $pai < 0 9 124 133
655 #print STDERR " swap k1, k2 - $k1 <=> $k2\n";
656 }
657 else {
658 167 $pai++;
659 #print STDERR " k1, k2 ok - $k1 : $k2\n";
660 }
661 }
662 else {
663 1 splice(@topurge,$j,1); # remove element from cache array
664 1 $pnd--;
665 #print STDERR " remove k2 = $k2\n";
666 }
667 }
668 else {
669 1 splice(@topurge,$pai,1); # remove element from cache array
670 1 $pnd--;
671 #print STDERR " remove k1 = $k1\n";
672 }
673 308 ▶ return $prp if $pai < $pnd; # reached end?
Branch: 1 branch
BranchTrueFalseTotal
if $pai < $pnd 304 4 308
674 # done, set next state
675 4 $pnd++;
676 4 $pnd -= $csize;
677 4 ▶ if ($pnd > 0) { # must delete overrun elements
Branch: 1 branch
BranchTrueFalseTotal
if ($pnd > 0) { } 2 2 4
678 2 $prp = 1;
679 2 $pai = 0;
680 } else {
681 2 $prp = -1; # set to initialization state
682 }
683 }
684 elsif ($prp > 0) { # remove cache over run
685 12 my $k = $topurge[$pai];
686 12 ▶ delete $cache{$k} if exists $cache{$k};
Branch: 1 branch
BranchTrueFalseTotal
if exists $cache{$k} 12 0 12
687 12 $pai++;
688 12 ▶ unless ($pai < $pnd) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pai < $pnd) 2 10 12
689 2 $prp = -1;
690 }
691 }
692 else {
693 4 ▶ return $prp unless $csize; # not enabled
Branch: 1 branch
BranchTrueFalseTotal
unless $csize 0 4 4
694 4 $pnd = @topurge = keys %cache;
695 4 $cused = $pnd; # update amount of cache in use
696 4 ▶ return $prp unless $pnd; # nothing to do
Branch: 1 branch
BranchTrueFalseTotal
unless $pnd 0 4 4
697 4 $pnd--; # end of array
698 4 $pai = 0; # array index
699 4 $prp = 0; # run state sort
700 }
701 20 return $prp;
702 }
703  
704 # setURBLdom
705 #
706 # sets breadcrumbs for stripped domain for URBL's
707 #
708 # input: remote IP or domain
709 # remote ID
710 # notRHBL
711 # ubl method pointer
712 # blacklist host array pointer UNUSED
713 # remoteThreads ptr
714 # return:
715 # SCALAR $rid
716 # ARRAY ($rid,$whitelistedDomain,$SURBLookupDomain)
717 # or false or false
718  
719 # $bap is unused
720  
721 59 ▶sub setURBLdom {
Subroutine setURBLdom: called CC=8 SCAR=36.4
Pod undocumented
722 59 my($rip,$rid,$notRHBL,$ubl,$bap,$rtp,$n) = @_;
723 59 ▶ if ($notRHBL || ! $ubl) { # don't even need to check
Branch: 1 branch
BranchTrueFalseTotal
if ($notRHBL or not $ubl) 59 0 59
Condition33%1/3
$notRHBL or not $ubl
l!l&&r!l&&!r
5900
MC/DC0%0/2
$notRHBL or not $ubl
$notRHBL not $ubl
Truth table33%1/3
A or not(B)
A= $notRHBLB= not $ubl
ABresult
1X1
011
000
724 59 ▶ return wantarray ? ($rid) : $rid; # or URBL::Prepare not loaded
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 59 59
725 }
726 0 ▶ $rid = uniqueID() unless $rid; # set $rid if it is empty
Branch: 1 branch
BranchTrueFalseTotal
unless $rid 0 0 0
727 0 ▶ $rtp->{$rid} = {} unless exists $rtp->{$rid};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $rtp->{$rid} 0 0 0
728  
729 0 my $domain = '';
730 0 my $white = $ubl->urblwhite($rip);
731 0 ▶ unless ($white) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($white) 0 0 0
732 0 $domain = $ubl->urbldomain($rip);
733 }
734  
735 0 $rtp->{$rid}->{urbl} = $domain;
736 0 $rtp->{$rid}->{N} = $n;
737 0 ▶ return wantarray ? ($rid,$white,$domain) : $rid;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
738 }
739  
740 77 ▶sub run {
Subroutine run: called CC=239 SCAR=87.8
Pod documented
741 77 my ($BLzone,$L,$R,$DNSBL,$STATs,$Run,$Sfile,$StatStamp,$DEBUG) = @_;
742 #open(Tmp,'>>/tmp/multidnsbl.log');
743 #print Tmp "---------------------------\n";
744 77 ▶ local *_alarm = sub {return $DNSBL->{"$_[0]"}->{timeout} || 30};
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%2/2
$$DNSBL{"$_[0]"}{'timeout'} || 30
l!l
557
MC/DC100%1/1
$$DNSBL{"$_[0]"}{'timeout'} || 30
$$DNSBL{"$_[0]"}{'timeout'}
Truth table100%2/2
A
A= $$DNSBL{"$_[0]"}{'timeout'}
Aresult
11
00
745 77 $BLzone = lc $BLzone;
746 77 ▶ my $myip = $DNSBL->{MDipaddr} || '';
Condition50%1/2
$DNSBL->{'MDipaddr'} || ''
l!l
077
MC/DC0%0/1
$DNSBL->{'MDipaddr'} || ''
$DNSBL->{'MDipaddr'}
Truth table50%1/2
A
A= $DNSBL->{'MDipaddr'}
Aresult
11
00
747 77 ▶ if ($myip && $myip ne '0.0.0.0') {
Branch: 1 branch
BranchTrueFalseTotal
if ($myip and $myip ne '0.0.0.0') { } 0 77 77
Condition33%1/3
$myip and $myip ne "0.0.0.0"
!ll&&!rl&&r
7700
MC/DC0%0/2
$myip and $myip ne "0.0.0.0"
$myip $myip ne "0.0.0.0"
Truth table33%1/3
A and B
A= $myipB= $myip ne "0.0.0.0"
ABresult
0X0
100
111
748 0 $myip = inet_aton($myip);
749 } else {
750 77 $myip = A1271;
751 }
752 77 ▶ $DEBUG = 0 unless $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
unless $DEBUG 0 77 77
753 77 ▶ my $ROK = ($DEBUG & $D_CLRRUN) ? 0:1;
Branch: 1 branch
BranchTrueFalseTotal
$DEBUG & $Net::DNSBL::MultiDaemon::D_CLRRUN ? : 28 49 77
754  
755 77 my ( $msg, $t, $targetIP, $cc, $comment,
756 $Oname,$Otype,$Oclass,$Ottl,$Ordlength,$Odata,
757 $off,$id,$qr,$opcode,$aa,$tc,$rd,$ra,$mbz,$ad,$cd,$rcode,
758 $qdcount,$ancount,$nscount,$arcount,
759 $name,$type,$class,
760 $ttl,$rdl,@rdata,
761 $l_Sin,$rip,$zone,@blist,
762 %remoteThreads,$rid,
763 $rin,$rout,$nfound,
764 $BBC,@NAignore,@NAblock,
765 $notRHBL,$ubl);
766  
767 77 my $LogLevel = 0;
768 77 ▶ if ($DNSBL->{MDsyslog}) { # if logging requested
Branch: 1 branch
BranchTrueFalseTotal
if ($DNSBL->{"MDsyslog"}) 0 77 77
769 0 require Unix::Syslog;
770 0 import Unix::Syslog @Unix::Syslog::EXPORT_OK;
771 0 $LogLevel = eval "$DNSBL->{MDsyslog}";
772 ## NOTE, logging must be initiated by the caller
773 }
774  
775 # generate NetAddr objects for addresses to always pass
776 77 ▶ if ($DNSBL->{IGNORE} && ref $DNSBL->{IGNORE} eq 'ARRAY' && @{$DNSBL->{IGNORE}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DNSBL->{"IGNORE"} and ref $DNSBL->{"IGNORE"} eq "ARRAY" and @{$DNSBL->{"IGNORE"};}) 2 75 77
Condition66%4/6
$DNSBL->{"IGNORE"} and ref $DNSBL->{"IGNORE"} eq "ARRAY" and @{$DNSBL->{"IGNORE"};}
!ll&&!rl&&r
7502
$DNSBL->{"IGNORE"} and ref $DNSBL->{"IGNORE"} eq "ARRAY"
!ll&&!rl&&r
7502
MC/DC33%1/3
$DNSBL->{"IGNORE"} and ref $DNSBL->{"IGNORE"} eq "ARRAY" and @{$DNSBL->{"IGNORE"};}
$DNSBL->{"IGNORE"} ref $DNSBL->{"IGNORE"} eq "ARRAY" @{$DNSBL->{"IGNORE"};}
Truth table50%2/4
A and B and C
A= $DNSBL->{"IGNORE"}B= ref $DNSBL->{"IGNORE"} eq "ARRAY"C= @{$DNSBL->{"IGNORE"};}
ABCresult
0XX0
10X0
1100
1111
777 2 list2NetAddr($DNSBL->{IGNORE},\@NAignore);
778 }
779  
780 # generate NetAddr objects for addresses to always reject
781 77 ▶ if ($DNSBL->{BLOCK} && ref $DNSBL->{BLOCK} eq 'ARRAY' && @{$DNSBL->{BLOCK}}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DNSBL->{"BLOCK"} and ref $DNSBL->{"BLOCK"} eq "ARRAY" and @{$DNSBL->{"BLOCK"};}) 1 76 77
Condition66%4/6
$DNSBL->{"BLOCK"} and ref $DNSBL->{"BLOCK"} eq "ARRAY" and @{$DNSBL->{"BLOCK"};}
!ll&&!rl&&r
7601
$DNSBL->{"BLOCK"} and ref $DNSBL->{"BLOCK"} eq "ARRAY"
!ll&&!rl&&r
7601
MC/DC33%1/3
$DNSBL->{"BLOCK"} and ref $DNSBL->{"BLOCK"} eq "ARRAY" and @{$DNSBL->{"BLOCK"};}
$DNSBL->{"BLOCK"} ref $DNSBL->{"BLOCK"} eq "ARRAY" @{$DNSBL->{"BLOCK"};}
Truth table50%2/4
A and B and C
A= $DNSBL->{"BLOCK"}B= ref $DNSBL->{"BLOCK"} eq "ARRAY"C= @{$DNSBL->{"BLOCK"};}
ABCresult
0XX0
10X0
1100
1111
782 1 list2NetAddr($DNSBL->{BLOCK},\@NAblock);
783 }
784  
785 # fetch pointer to Geo::IP methods
786 0 ▶ if ($DNSBL->{BBC} && ref $DNSBL->{BBC} eq 'ARRAY' && @{$DNSBL->{BBC}} && eval { require Geo::IP::PurePerl }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DNSBL->{'BBC'} and ref $DNSBL->{'BBC'} eq 'ARRAY' and @{$DNSBL->{'BBC'};} and eval { do { require Geo::IP::PurePerl } }) { } 0 77 77
Condition33%3/9
$DNSBL->{"BBC"} and ref $DNSBL->{"BBC"} eq "ARRAY" and @{$DNSBL->{"BBC"};} and eval { do { require Geo::IP::PurePerl } }
!ll&&!rl&&r
7700
$DNSBL->{"BBC"} and ref $DNSBL->{"BBC"} eq "ARRAY" and @{$DNSBL->{"BBC"};}
!ll&&!rl&&r
7700
$DNSBL->{"BBC"} and ref $DNSBL->{"BBC"} eq "ARRAY"
!ll&&!rl&&r
7700
MC/DC0%0/4
$DNSBL->{"BBC"} and ref $DNSBL->{"BBC"} eq "ARRAY" and @{$DNSBL->{"BBC"};} and eval { do { require Geo::IP::PurePerl } }
$DNSBL->{"BBC"} ref $DNSBL->{"BBC"} eq "ARRAY" @{$DNSBL->{"BBC"};} eval { do { require Geo::IP::PurePerl } }
Truth table20%1/5
A and B and C and D
A= $DNSBL->{"BBC"}B= ref $DNSBL->{"BBC"} eq "ARRAY"C= @{$DNSBL->{"BBC"};}D= eval { do { require Geo::IP::PurePerl } }
ABCDresult
0XXX0
10XX0
110X0
11100
11111
787 0 $BBC = new Geo::IP::PurePerl;
788 } else {
789 77 $DNSBL->{BBC} = '';
790 }
791  
792 # check for caching
793 77 ▶ if (exists $DNSBL->{MDcache}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $DNSBL->{"MDcache"}) 0 77 77
794 0 $csize = $DNSBL->{MDcache};
795 0 ▶ $csize = 10000 if $DNSBL->{MDcache} < 10000;
Branch: 1 branch
BranchTrueFalseTotal
if $DNSBL->{"MDcache"} < 10000 0 0 0
796 }
797  
798 # check for right hand side block list operation
799 77 ▶ if ($DNSBL->{RHBL}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DNSBL->{'RHBL'}) { } 0 77 77
800 0 $notRHBL = 0;
801 0 ▶ if (ref $DNSBL->{RHBL} &&
Branch: 1 branch
BranchTrueFalseTotal
if (ref $DNSBL->{"RHBL"} and exists $DNSBL->{"RHBL"}{"urbltlds"} && ref $DNSBL->{"RHBL"}{"urbltlds"} eq "ARRAY" || exists $DNSBL->{"RHBL"}{"urblwhite"} && ref $DNSBL->{"RHBL"}{"urblwhite"} eq "ARRAY" || exists $DNSBL->{"RHBL"}{"urblblack"} && ref $DNSBL->{"RHBL"}{"urblblack"} eq "ARRAY" and eval { do { no warnings; require URBL::Prepare } }) 0 0 0
Condition0%0/21
ref $DNSBL->{"RHBL"} and exists $DNSBL->{"RHBL"}{"urbltlds"} && ref $DNSBL->{"RHBL"}{"urbltlds"} eq "ARRAY" || exists $DNSBL->{"RHBL"}{"urblwhite"} && ref $DNSBL->{"RHBL"}{"urblwhite"} eq "ARRAY" || exists $DNSBL->{"RHBL"}{"urblblack"} && ref $DNSBL->{"RHBL"}{"urblblack"} eq "ARRAY" and eval { do { no warnings; require URBL::Prepare } }
!ll&&!rl&&r
000
ref $DNSBL->{"RHBL"} and exists $DNSBL->{"RHBL"}{"urbltlds"} && ref $DNSBL->{"RHBL"}{"urbltlds"} eq "ARRAY" || exists $DNSBL->{"RHBL"}{"urblwhite"} && ref $DNSBL->{"RHBL"}{"urblwhite"} eq "ARRAY" || exists $DNSBL->{"RHBL"}{"urblblack"} && ref $DNSBL->{"RHBL"}{"urblblack"} eq "ARRAY"
!ll&&!rl&&r
000
exists $DNSBL->{"RHBL"}{"urbltlds"} and ref $DNSBL->{"RHBL"}{"urbltlds"} eq "ARRAY" or exists $DNSBL->{"RHBL"}{"urblwhite"} and ref $DNSBL->{"RHBL"}{"urblwhite"} eq "ARRAY" or exists $DNSBL->{"RHBL"}{"urblblack"} and ref $DNSBL->{"RHBL"}{"urblblack"} eq "ARRAY"
l!l&&r!l&&!r
000
exists $DNSBL->{"RHBL"}{"urbltlds"} and ref $DNSBL->{"RHBL"}{"urbltlds"} eq "ARRAY" or exists $DNSBL->{"RHBL"}{"urblwhite"} and ref $DNSBL->{"RHBL"}{"urblwhite"} eq "ARRAY"
l!l&&r!l&&!r
000
exists $DNSBL->{"RHBL"}{"urbltlds"} and ref $DNSBL->{"RHBL"}{"urbltlds"} eq "ARRAY"
!ll&&!rl&&r
000
exists $DNSBL->{"RHBL"}{"urblwhite"} and ref $DNSBL->{"RHBL"}{"urblwhite"} eq "ARRAY"
!ll&&!rl&&r
000
exists $DNSBL->{"RHBL"}{"urblblack"} and ref $DNSBL->{"RHBL"}{"urblblack"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/8
ref $DNSBL->{"RHBL"} and exists $DNSBL->{"RHBL"}{"urbltlds"} && ref $DNSBL->{"RHBL"}{"urbltlds"} eq "ARRAY" || exists $DNSBL->{"RHBL"}{"urblwhite"} && ref $DNSBL->{"RHBL"}{"urblwhite"} eq "ARRAY" || exists $DNSBL->{"RHBL"}{"urblblack"} && ref $DNSBL->{"RHBL"}{"urblblack"} eq "ARRAY" and eval { do { no warnings; require URBL::Prepare } }
ref $DNSBL->{"RHBL"} exists $DNSBL->{"RHBL"}{"urbltlds"} ref $DNSBL->{"RHBL"}{"urbltlds"} eq "ARRAY" exists $DNSBL->{"RHBL"}{"urblwhite"} ref $DNSBL->{"RHBL"}{"urblwhite"} eq "ARRAY" exists $DNSBL->{"RHBL"}{"urblblack"} ref $DNSBL->{"RHBL"}{"urblblack"} eq "ARRAY" eval { do { no warnings; require URBL::Prepare } }
Truth table0%0/23
A and B and C or D and E or F and G and H
A= ref $DNSBL->{"RHBL"}B= exists $DNSBL->{"RHBL"}{"urbltlds"}C= ref $DNSBL->{"RHBL"}{"urbltlds"} eq "ARRAY"D= exists $DNSBL->{"RHBL"}{"urblwhite"}E= ref $DNSBL->{"RHBL"}{"urblwhite"} eq "ARRAY"F= exists $DNSBL->{"RHBL"}{"urblblack"}G= ref $DNSBL->{"RHBL"}{"urblblack"} eq "ARRAY"H= eval { do { no warnings; require URBL::Prepare } }
ABCDEFGHresult
0XXXXXXX0
10X0X0XX0
10X0X10X0
10X100XX0
10X1010X0
1100X0XX0
1100X10X0
110100XX0
1101010X0
111XXXX00
10X11XX00
11011XX00
10X0X1100
10X101100
1100X1100
110101100
111XXXX11
10X11XX11
11011XX11
10X0X1111
10X101111
1100X1111
110101111
802 ((exists $DNSBL->{RHBL}->{urbltlds} && ref($DNSBL->{RHBL}->{urbltlds}) eq 'ARRAY') ||
803 (exists $DNSBL->{RHBL}->{urblwhite} && ref($DNSBL->{RHBL}->{urblwhite}) eq 'ARRAY') ||
804 (exists $DNSBL->{RHBL}->{urblblack} && ref($DNSBL->{RHBL}->{urblblack}) eq 'ARRAY')) &&
805 eval {
806 20 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
807 0 require URBL::Prepare;
808 }
809 ) {
810 0 $ubl = new URBL::Prepare;
811 0 ▶ if (exists $DNSBL->{RHBL}->{urlwhite} && ref($DNSBL->{RHBL}->{urlwhite}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $DNSBL->{"RHBL"}{"urlwhite"} and ref $DNSBL->{"RHBL"}{"urlwhite"} eq "ARRAY") 0 0 0
Condition0%0/3
exists $DNSBL->{"RHBL"}{"urlwhite"} and ref $DNSBL->{"RHBL"}{"urlwhite"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $DNSBL->{"RHBL"}{"urlwhite"} and ref $DNSBL->{"RHBL"}{"urlwhite"} eq "ARRAY"
exists $DNSBL->{"RHBL"}{"urlwhite"} ref $DNSBL->{"RHBL"}{"urlwhite"} eq "ARRAY"
Truth table0%0/3
A and B
A= exists $DNSBL->{"RHBL"}{"urlwhite"}B= ref $DNSBL->{"RHBL"}{"urlwhite"} eq "ARRAY"
ABresult
0X0
100
111
812 0 $ubl->loadcache(@{$DNSBL->{RHBL}->{urlwhite}}); # cache whitelist file
813 }
814 0 ▶ if (exists $DNSBL->{RHBL}->{urltld3} && ref($DNSBL->{RHBL}->{urltld3}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $DNSBL->{"RHBL"}{"urltld3"} and ref $DNSBL->{"RHBL"}{"urltld3"} eq "ARRAY") 0 0 0
Condition0%0/3
exists $DNSBL->{"RHBL"}{"urltld3"} and ref $DNSBL->{"RHBL"}{"urltld3"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $DNSBL->{"RHBL"}{"urltld3"} and ref $DNSBL->{"RHBL"}{"urltld3"} eq "ARRAY"
exists $DNSBL->{"RHBL"}{"urltld3"} ref $DNSBL->{"RHBL"}{"urltld3"} eq "ARRAY"
Truth table0%0/3
A and B
A= exists $DNSBL->{"RHBL"}{"urltld3"}B= ref $DNSBL->{"RHBL"}{"urltld3"} eq "ARRAY"
ABresult
0X0
100
111
815 0 $ubl->loadcache(@{$DNSBL->{RHBL}->{urltld3}}); # cache tld3 file
816 }
817 0 ▶ if (exists $DNSBL->{RHBL}->{urltld2} && ref($DNSBL->{RHBL}->{urltld2}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $DNSBL->{"RHBL"}{"urltld2"} and ref $DNSBL->{"RHBL"}{"urltld2"} eq "ARRAY") 0 0 0
Condition0%0/3
exists $DNSBL->{"RHBL"}{"urltld2"} and ref $DNSBL->{"RHBL"}{"urltld2"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $DNSBL->{"RHBL"}{"urltld2"} and ref $DNSBL->{"RHBL"}{"urltld2"} eq "ARRAY"
exists $DNSBL->{"RHBL"}{"urltld2"} ref $DNSBL->{"RHBL"}{"urltld2"} eq "ARRAY"
Truth table0%0/3
A and B
A= exists $DNSBL->{"RHBL"}{"urltld2"}B= ref $DNSBL->{"RHBL"}{"urltld2"} eq "ARRAY"
ABresult
0X0
100
111
818 0 $ubl->loadcache(@{$DNSBL->{RHBL}->{urltld2}}); # cache tld2 file
819 }
820 0 $ubl->cachetlds($DNSBL->{RHBL}->{urbltlds});
821 0 $ubl->cachewhite($DNSBL->{RHBL}->{urblwhite});
822 0 $ubl->cacheblack($DNSBL->{RHBL}->{urblblack});
823 }
824 } else {
825 77 $notRHBL = 1;
826 }
827 #select Tmp;
828 #$| = 1;
829 #print Tmp "running $$\n";
830 #select STDOUT;
831  
832  
833 # set up GENERIC PTR tests
834 77 my($iptr,$regexptr);
835 77 ▶ if ( exists $DNSBL->{GENERIC} &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $DNSBL->{'GENERIC'} and ref $DNSBL->{'GENERIC'} eq 'HASH' and $regexptr = $DNSBL->{'GENERIC'}{'regexp'} and ref $regexptr eq 'ARRAY' and @$regexptr > 0) { } 0 77 77
Condition33%4/12
exists $DNSBL->{"GENERIC"} and ref $DNSBL->{"GENERIC"} eq "HASH" and $regexptr = $DNSBL->{"GENERIC"}{"regexp"} and ref $regexptr eq "ARRAY" and @$regexptr > 0
!ll&&!rl&&r
7700
exists $DNSBL->{"GENERIC"} and ref $DNSBL->{"GENERIC"} eq "HASH" and $regexptr = $DNSBL->{"GENERIC"}{"regexp"} and ref $regexptr eq "ARRAY"
!ll&&!rl&&r
7700
exists $DNSBL->{"GENERIC"} and ref $DNSBL->{"GENERIC"} eq "HASH" and $regexptr = $DNSBL->{"GENERIC"}{"regexp"}
!ll&&!rl&&r
7700
exists $DNSBL->{"GENERIC"} and ref $DNSBL->{"GENERIC"} eq "HASH"
!ll&&!rl&&r
7700
MC/DC0%0/5
exists $DNSBL->{"GENERIC"} and ref $DNSBL->{"GENERIC"} eq "HASH" and $regexptr = $DNSBL->{"GENERIC"}{"regexp"} and ref $regexptr eq "ARRAY" and @$regexptr > 0
exists $DNSBL->{"GENERIC"} ref $DNSBL->{"GENERIC"} eq "HASH" $regexptr = $DNSBL->{"GENERIC"}{"regexp"} ref $regexptr eq "ARRAY" @$regexptr > 0
Truth table16%1/6
A and B and C and D and E
A= exists $DNSBL->{"GENERIC"}B= ref $DNSBL->{"GENERIC"} eq "HASH"C= $regexptr = $DNSBL->{"GENERIC"}{"regexp"}D= ref $regexptr eq "ARRAY"E= @$regexptr > 0
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
836 ref $DNSBL->{GENERIC} eq 'HASH' &&
837 ($regexptr = $DNSBL->{GENERIC}->{regexp}) &&
838 ref $regexptr eq 'ARRAY' &&
839 @$regexptr > 0 ) {
840 #print Tmp "regexptr setup, @$regexptr\n";
841 0 ▶ unless ( $DNSBL->{GENERIC}->{ignore} &&
Branch: 1 branch
BranchTrueFalseTotal
unless ($DNSBL->{"GENERIC"}{"ignore"} and "ARRAY" eq ref($iptr = $DNSBL->{"GENERIC"}{"ignore"}) and @$iptr > 0) 0 0 0
Condition0%0/6
$DNSBL->{"GENERIC"}{"ignore"} and "ARRAY" eq ref($iptr = $DNSBL->{"GENERIC"}{"ignore"}) and @$iptr > 0
!ll&&!rl&&r
000
$DNSBL->{"GENERIC"}{"ignore"} and "ARRAY" eq ref($iptr = $DNSBL->{"GENERIC"}{"ignore"})
!ll&&!rl&&r
000
MC/DC0%0/3
$DNSBL->{"GENERIC"}{"ignore"} and "ARRAY" eq ref($iptr = $DNSBL->{"GENERIC"}{"ignore"}) and @$iptr > 0
$DNSBL->{"GENERIC"}{"ignore"} "ARRAY" eq ref($iptr = $DNSBL->{"GENERIC"}{"ignore"}) @$iptr > 0
Truth table0%0/4
A and B and C
A= $DNSBL->{"GENERIC"}{"ignore"}B= "ARRAY" eq ref($iptr = $DNSBL->{"GENERIC"}{"ignore"})C= @$iptr > 0
ABCresult
0XX0
10X0
1100
1111
842 'ARRAY' eq ref ($iptr = $DNSBL->{GENERIC}->{ignore}) &&
843 @$iptr > 0 ) {
844 0 undef $iptr;
845 }
846 } else {
847 #print Tmp "regexptr FAILED\n";
848 77 undef $regexptr;
849 }
850  
851 77 my $filenoL = fileno($L);
852 77 my $filenoR = fileno($R);
853  
854 77 $now = time;
855 77 $next = $now + $interval;
856 77 $newstat = 0; # new statistics flag
857 77 my $refresh = $now + $$Run; # update statistics "then"
858  
859 0 ▶ local $SIG{USR1} = sub {$newstat = 2}; # force write of stats now
Subroutine __ANON__: not called CC=1 SCAR=1.2
860 0 ▶ local $SIG{USR2} = sub { # kill and regenerate statfile
Subroutine __ANON__: not called CC=4 SCAR=30.0
861 0 ▶ return unless $Sfile;
Branch: 1 branch
BranchTrueFalseTotal
unless $Sfile 0 0 0
862 0 unlink $Sfile;
863 0 foreach(keys %$STATs) {
864 0 $STATs->{"$_"} = 0;
865 0 %AVGs = ();
866 0 %CNTs = ();
867 }
868 0 $StatStamp = statinit($Sfile,$STATs);
869 0 ▶ syslog($LogLevel,"received USR2, clear stats\n")
Branch: 1 branch
BranchTrueFalseTotal
if $LogLevel 0 0 0
870 if $LogLevel;
871 0 $newstat = 2; # re-write on next second tick
872 77 };
873  
874 77 my $SOAptr = [ # set up bogus SOA
875 $BLzone,
876 &T_SOA,
877 &C_IN,
878 0, # ttl of SOA record
879 $BLzone,
880 'root.'. $BLzone,
881 $now,
882 86400,
883 43200,
884 172800,
885 3600, # cache negative TTL's for an hour
886 ];
887  
888 77 my ($get,$put,$parse) = new Net::DNS::ToolKit::RR;
889  
890 77 my $numberoftries = 6;
891  
892 77 my %deadDNSBL;
893 77 foreach(keys %$STATs) {
894 385 ▶ next unless $_ =~ /\./; # only real domains
Branch: 1 branch
BranchTrueFalseTotal
unless $_ =~ /\./ 231 154 385
895 154 $deadDNSBL{"$_"} = 1; # initialize dead DNSBL timers
896 }
897  
898 77 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$$Run and $ROK and do { do { $rin = ""; vec($rin, $filenoL, 1) = 1; vec($rin, $filenoR, 1) = 1 if %remoteThreads; $nfound = select($rout = $rin, undef, undef, 1); if ($nfound > 0) { while (vec $rout, $filenoL, 1) { last unless $l_Sin = recv($L, $msg, PACKETSZ(), 0); if (length $msg < HFIXEDSZ()) { return "short header" if $DEBUG & $Net::DNSBL::MultiDaemon::D_SHRTHD; last; } ; () = &gethead(\$msg); if ($qr) { return "query response" if $DEBUG & $Net::DNSBL::MultiDaemon::D_QRESP; last; } ; $comment = "no bl"; setAUTH(0); setRA($rd); if ($eXT and exists $eXT->{"OPCODE"} and $eXT->{"OPCODE"}->($eXT, $get, $put, \$msg, $off, $id, $qr, $opcode, $aa, $tc, $rd, $ra, $mbz, $ad, $cd, $rcode, $qdcount, $ancount, $nscount, $arcount)) { $comment = "mdextension opcode"; } elsif ($opcode != QUERY()) { s_response(\$msg, NOTIMP(), $id, 1, 0, 0, 0); $comment = "not implemented"; } elsif ($qdcount != 1 or $ancount or $nscount or $arcount) { s_response(\$msg, FORMERR(), $id, $qdcount, $ancount, $nscount, $arcount); $comment = "format error 1"; } elsif (($off, $name, $type, $class) = $get->Question(\$msg, $off) and not $name) { s_response(\$msg, FORMERR(), $id, 1, 0, 0, 0); $comment = "format error 2"; } elsif (not $eXT && exists $eXT->{"CLASS"} && $eXT->{"CLASS"}->($eXT, $get, $put, $id, $opcode, \$name, \$type, \$class) and $class != C_IN()) { s_response(\$msg, REFUSED(), $id, $qdcount, $ancount, $nscount, $arcount); $comment = "refused"; } elsif ($eXT and exists $eXT->{"NAME"} and $eXT->{"NAME"}->($eXT, $get, $put, $id, $opcode, \$name, \$type, \$class) or not $name =~ /$BLzone$/i) { s_response(\$msg, NXDOMAIN(), $id, 1, 0, 0, 0); $comment = "not this zone"; } else { print STDERR $name, " ", TypeTxt()->{$type}, " " if $DEBUG & $Net::DNSBL::MultiDaemon::D_VERBOSE; if ($eXT and exists $eXT->{"TYPE"} and my $rv = $eXT->{"TYPE"}->($eXT, $get, $put, $id, $opcode, \$name, \$type, \$class)) { $msg = $rv; $comment = "Extension type"; } elsif ($type == T_A() or $type == T_ANY() or $type == T_TXT()) { if ($notRHBL and $name =~ /^((\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3}))\.(.+)/ and $rip = $1 and $targetIP = "$5.$4.$3.$2" and $zone = $6 and $BLzone eq lc $zone or not $notRHBL and $name =~ /^([a-zA-Z0-9][a-zA-Z0-9\.\-]+[a-zA-Z0-9])\.$BLzone$/ and $rip = $1 and $targetIP = 1 and $zone = $BLzone) { my $expires; if ($eXT and exists $eXT->{"CACHE"} and my $rv = $eXT->{"CACHE"}->($eXT, $get, $put, $id, $opcode, $rip, \$name, \$type, \$class, $ubl)) { $msg = $rv; } elsif (not $notRHBL and $ubl and do { if ($ubl->urblwhite($rip)) { not_found($put, $name, $type, $id, \$msg, $SOAptr); $rv = "whitelisted"; } elsif ($ubl->urblblack($rip)) { ($msg) = _ansrbak($put, $id, 1, $rip, $zone, $type, 3600, A1272(), $BLzone, $myip, "blacklisted"); $rv = "blacklisted"; } }) { $comment = $rv; } elsif ($rip eq "2.0.0.127") { ($msg) = _ansrbak($put, $id, 1, $rip, $zone, $type, 3600, A1272(), $BLzone, $myip, "DNSBL test response to 127.0.0.2"); $comment = "just testing"; } elsif ($csize and exists $cache{$rip} and ($expires = $cache{$rip}{"expires"}) > $now) { $cache{$rip}{"used"} = $now; my $blist_0 = $cache{$rip}{"who"}; my $txt = $cache{$rip}{"txt"}; $txt = $txt ? $txt . $targetIP : ""; ($msg) = _ansrbak($put, $id, 1, $rip, $zone, $type, $expires - $now, A1272(), $BLzone, $myip, $txt); $comment = "cache record"; bump_stats($STATs, $blist_0); } elsif ($type == T_TXT()) { not_found($put, $name, $type, $id, \$msg, $SOAptr); $comment = "no TXT"; } elsif ($notRHBL and @NAignore and matchNetAddr($targetIP, \@NAignore)) { not_found($put, $name, $type, $id, \$msg, $SOAptr); $STATs->{"WhiteList"} += 1; $comment = "IGNORE"; } elsif ($notRHBL and @NAblock and matchNetAddr($targetIP, \@NAblock)) { ($msg) = _ansrbak($put, $id, 1, $rip, $zone, $type, 3600, A1275(), $BLzone, $myip); $STATs->{"BlackList"} += 1; $comment = "BLOCK"; } elsif ($notRHBL and $BBC and $cc = $BBC->country_code_by_addr($targetIP) and grep(($cc eq $_), @{$$DNSBL{"BBC"};})) { ($msg) = _ansrbak($put, $id, 1, $rip, $zone, $type, 3600, A1276(), $BLzone, $myip); $STATs->{$cc} += 1; $newstat = 1 unless $newstat; $comment = "block $cc"; } else { @blist = (); foreach $_ (sort {by_average($STATs, $a, $b);} keys %$STATs) { next unless $_ =~ /\./; push @blist, $_; } ; push @blist, "genericPTR" if $regexptr; $rid = undef; if ($eXT and exists $eXT->{"LOOKUP"}) { $rid = uniqueID(); $rid = $eXT->{"LOOKUP"}->($eXT, $get, $put, $rid, $id, $opcode, \$name, \$type, \$class, \%remoteThreads); } ; $rid = setURBLdom($rip, $rid, $notRHBL, $ubl, $$DNSBL{$blist[0]}, \%remoteThreads, 0); bl_lookup($put, \$msg, \%remoteThreads, $l_Sin, _alarm($blist[0]), $rid, $id, $rip, $type, $zone, @blist); send $R, $msg, 0, $Net::DNSBL::MultiDaemon::R_Sin; print STDERR $blist[0] if $DEBUG & $Net::DNSBL::MultiDaemon::D_VERBOSE; last; } ; } elsif ($BLzone eq lc $name and $type != T_TXT()) { my $noff = newhead(\$msg, $id, BITS_QUERY() | QR(), 1, 1, 1, 0); ($noff, my @dnptrs) = $put->Question(\$msg, $noff, $name, $type, C_IN()); ($noff, @dnptrs) = $put->A(\$msg, $noff, \@dnptrs, $name, T_A(), C_IN(), 86400, $myip); ($noff, @dnptrs) = $put->NS(\$msg, $noff, \@dnptrs, $name, T_NS(), C_IN(), 86400, $BLzone); } else { not_found($put, $name, $type, $id, \$msg, $SOAptr); } ; } elsif ($type == T_NS() and $BLzone eq lc $name) { my $noff = newhead(\$msg, $id, BITS_QUERY() | QR(), 1, 1, 0, 1); ($noff, my @dnptrs) = $put->Question(\$msg, $noff, $name, $type, C_IN()); ($noff, @dnptrs) = $put->NS(\$msg, $noff, \@dnptrs, $name, T_NS(), C_IN(), $86400, $BLzone); ($noff, @dnptrs) = $put->A(\$msg, $noff, \@dnptrs, $BLzone, T_A(), C_IN(), 86400, $myip); } elsif ($type == T_NS() or $type == T_MX() or $type == T_SOA() or $type == T_CNAME() or $type == T_TXT()) { not_found($put, $name, $type, $id, \$msg, $SOAptr); } elsif ($type == T_AXFR()) { s_response(\$msg, REFUSED(), $id, 1, 0, 0, 0); $comment = "refused AXFR"; } else { s_response(\$msg, NOTIMP(), $id, 1, 0, 0, 0); $comment = "not implemented"; } ; } ; send $L, $msg, 0, $l_Sin; print STDERR " $comment\n" if $DEBUG & $Net::DNSBL::MultiDaemon::D_VERBOSE; last; } ; while (vec $rout, $filenoR, 1) { undef $msg; last unless recv $R, $msg, PACKETSZ(), 0; if (length $msg < HFIXEDSZ()) { return "short header" if $DEBUG & $Net::DNSBL::MultiDaemon::D_SHRTHD; last; } ; ($off, $rid, $qr, $opcode, $aa, $tc, $rd, $ra, $mbz, $ad, $cd, $rcode, $qdcount, $ancount, $nscount, $arcount) = &gethead(\$msg); unless ($tc == 0 and $qr == 1 and $opcode == QUERY() and $rcode == NOERROR() || $rcode == NXDOMAIN() || $rcode == SERVFAIL() and $qdcount == 1 and exists $remoteThreads{$rid}) { return "not me 1" if $DEBUG & $Net::DNSBL::MultiDaemon::D_NOTME; last; } ; () = @{$remoteThreads{$rid}{"args"};}; my $urbldom = exists $remoteThreads{$rid}{"urbl"} ? $remoteThreads{$rid}{"urbl"} : ""; ($off, $name, $t, $class) = $get->Question(\$msg, $off); my($answer, $attl, @generic); if ($ancount and $rcode == &NOERROR) { $name =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\.(.+)$/ or $name =~ /^([a-zA-Z0-9][a-zA-Z0-9\.\-]+[a-zA-Z0-9])\.($blist[0])$/; my $z = lc $2; $z = $z eq lc $blist[0] || $z eq "in-addr.arpa" && $blist[0] eq "genericPTR" ? 1 : 0; unless ($z and !$urbldom && $rip eq $1 || $urbldom && $urbldom eq $1 and $t == T_A() || $t == T_PTR() and $class == C_IN()) { return "not me 2" if $DEBUG & $Net::DNSBL::MultiDaemon::D_NOTME; last; } ; undef $answer; setAUTH($aa); setRA($rd); ANSWER: foreach $_ (0 .. $ancount - 1) { ($off, $name, $t, $class, $ttl, $rdl, @rdata) = $get->next(\$msg, $off); next if $answer; if ($t == T_A()) { if (exists $$DNSBL{"$blist[0]"}{"acceptany"}) { $answer = A1272(); $attl = $ttl; last ANSWER; } ; my $mask = exists $$DNSBL{"$blist[0]"}{"acceptmask"} ? $$DNSBL{"$blist[0]"}{"acceptmask"} : 0; while ($answer = shift @rdata) { my $IP = inet_ntoa($answer); if ($mask & unpack("N", $answer) or grep(($IP eq $_), keys %{$$DNSBL{"$blist[0]"}{"accept"};})) { $answer = A1272(); $attl = $ttl; last ANSWER; } ; undef $answer; } ; } elsif ($t == T_PTR() and $blist[0] eq "genericPTR") { push @generic, $rdata[0]; } ; } ; $ttl = $attl; } elsif ($t == T_PTR() and $rcode == NXDOMAIN() || $rcode == SERVFAIL()) { $answer = A1274(); $ttl = 3600; $nscount = ($arcount = 0); } ; if (@generic) { my @names; foreach my $g (@generic) { last if $iptr and grep(($g =~ /$_/i), @$iptr); push @names, $g if $g and not grep(($g =~ /$_/i), @$regexptr); } ; $answer = A1277() unless @names; $ttl = 3600; } ; if ($answer) { my $txt = ""; if ($csize and $answer == A1272() || $answer == A1274() || $answer == A1277()) { $txt = $$DNSBL{$blist[0]}{"error"} if exists $$DNSBL{$blist[0]}; my $trailer = $notRHBL ? revIP($rip) : ""; $txt = $txt ? $txt . $trailer : ""; $cache{$rip} = {"expires", $now + $ttl, "used", $now, "who", $blist[0], "txt", $txt}; } ; bump_stats($STATs, $blist[0]); () = $FATans ? _ansrbak($put, $id, $nscount + $arcount + 1, $rip, $zone, $type, $ttl, $answer, $BLzone, $myip, $txt) : _ansrbak($put, $id, 1, $rip, $zone, $type, $ttl, $answer, $BLzone, $myip, $txt); if ($FATans) { foreach $_ (0 .. $nscount - 1) { ($off, $Oname, $Otype, $Oclass, $Ottl, $Ordlength, $Odata) = $get->next(\$msg, $off); () = $put->NS(\$nmsg, $noff, \@dnptrs, $Oname, $Otype, $Oclass, $Ottl, $Odata); } ; foreach $_ (0 .. $arcount - 1) { ($off, $Oname, $Otype, $Oclass, $Ottl, $Ordlength, $Odata) = $get->next(\$msg, $off); if ($Otype == T_A()) { () = $put->A(\$nmsg, $noff, \@dnptrs, $Oname, $Otype, $Oclass, $Ottl, $Odata); } elsif ($Otype == T_AAAA()) { () = $put->AAAA(\$nmsg, $noff, \@dnptrs, $Oname, $Otype, $Oclass, $Ottl, $Odata); } else { next; } ; } ; } ; if ($eXT and exists $eXT->{"ANSWER"} and $eXT->{"ANSWER"}->($eXT, $get, $put, $rid, $ttl, \$nmsg, \%remoteThreads)) { (); } ; delete $remoteThreads{$rid}; $msg = $nmsg; $ROK = 0 if $DEBUG & $Net::DNSBL::MultiDaemon::D_ANSTOP; } elsif (do { print STDERR "+" if $DEBUG & $Net::DNSBL::MultiDaemon::D_VERBOSE; my $rv = 0; until ($rv) { shift @blist; if (@blist) { last unless $deadDNSBL{"$blist[0]"} > $numberoftries; } else { $rv = 1; } ; } ; $rv }) { not_found($put, $rip . '.' . $zone, $type, $id, \$msg, $SOAptr) unless $eXT and exists $eXT->{"NOTFOUND"} and $eXT->{"NOTFOUND"}->($eXT, $get, $put, $rid, $rip, \$type, \$zone, \$msg, \%remoteThreads); delete $remoteThreads{$rid}; $STATs->{"Passed"} += 1; $newstat = 1 unless $newstat; } else { $deadDNSBL{"$blist[0]"} = 1; $rid = setURBLdom($rip, $rid, $notRHBL, $ubl, $$DNSBL{$blist[0]}, \%remoteThreads, 1); bl_lookup($put, \$msg, \%remoteThreads, $l_Sin, _alarm($blist[0]), $rid, $id, $rip, $type, $zone, @blist); print STDERR $blist[0] if $DEBUG & $Net::DNSBL::MultiDaemon::D_VERBOSE; send $R, $msg, 0, $Net::DNSBL::MultiDaemon::R_Sin; last; } ; send $L, $msg, 0, $l_Sin; if ($DEBUG & $Net::DNSBL::MultiDaemon::D_VERBOSE) { if ($answer) { print STDERR " ", inet_ntoa($answer), "\n"; } else { print STDERR " no bl\n"; } ; } ; last; } ; } else { my $prpshadow = $prp; $now = time; unless ($now < $next) { average($STATs); purge_cache() if $prp < 0; } ; purge_cache() unless $prpshadow < 0; foreach $rid (keys %remoteThreads) { next unless $remoteThreads{$rid}{"expire"} < $now; () = @{$remoteThreads{$rid}{"args"};}; if (++$deadDNSBL{"$blist[0]"} > $numberoftries) { $deadDNSBL{"$blist[0]"} = 3600; if ($LogLevel) { syslog($LogLevel, "timeout connecting to $blist[0]\n"); } ; } ; if ($blist[0] eq "in-addr.arpa") { delete $remoteThreads{$rid}; $deadDNSBL{"$blist[0]"} = 0; my $txt = exists $$DNSBL{$blist[0]} ? $$DNSBL{$blist[0]}{"error"} : ""; $cache{$rip} = {"expires", $now + 3600, "used", $now, "who", $blist[0], "txt", $txt}; bump_stats($STATs, $blist[0]); ($msg) = _ansrbak($put, $id, 1, $rip, $zone, $type, 3600, A1274(), $BLzone, $myip, $txt); send $L, $msg, 0, $l_Sin; print STDERR " expired Rdns\n" if $DEBUG & $Net::DNSBL::MultiDaemon::D_VERBOSE; } elsif (do { print STDERR "?" if $DEBUG & $Net::DNSBL::MultiDaemon::D_VERBOSE; my $rv = 0; until ($rv) { shift @blist; if (@blist) { last unless $deadDNSBL{"$blist[0]"} > $numberoftries; } else { $rv = 1; } ; } ; $rv }) { not_found($put, $rip . '.' . $BLzone, $type, $id, \$msg, $SOAptr) unless $eXT and exists $eXT->{"NOTFOUND"} and $eXT->{"NOTFOUND"}->($eXT, $get, $put, $rid, $rip, \$type, \$BLzone, \$msg, \%remoteThreads); delete $remoteThreads{$rid}; $STATs->{"Passed"} += 1; $newstat = 1 unless $newstat; send $L, $msg, 0, $l_Sin; print STDERR " no bl\n" if $DEBUG & $Net::DNSBL::MultiDaemon::D_VERBOSE; } else { bl_lookup($put, \$msg, \%remoteThreads, $l_Sin, _alarm($blist[0]), $rid, $id, $rip, $type, $zone, @blist); send $R, $msg, 0, $Net::DNSBL::MultiDaemon::R_Sin; print STDERR $blist[0] if $DEBUG & $Net::DNSBL::MultiDaemon::D_VERBOSE; } ; } ; foreach $_ (keys %deadDNSBL) { --$deadDNSBL{"$_"} if $deadDNSBL{"$_"} > $numberoftries; } ; if ($newstat > 1 or $refresh < $now and $newstat) { write_stats($Sfile, $STATs, $StatStamp, $csize, $cused); $refresh = $now + $$Run; $newstat = 0; } ; return "caught timer" if $DEBUG & $Net::DNSBL::MultiDaemon::D_TIMONLY; } } } 83 28 111
Condition66%2/3
$$Run and $ROK
!ll&&!rl&&r
02883
MC/DC50%1/2
$$Run and $ROK
$$Run $ROK
Truth table66%2/3
A and B
A= $$RunB= $ROK
ABresult
0X0
100
111
899 160 $rin = '';
900 160 vec($rin,$filenoL,1) = 1; # always listening to local port
901 160 ▶ (vec($rin,$filenoR,1) = 1) # listen to remote only if traffic expected
Branch: 1 branch
BranchTrueFalseTotal
if %remoteThreads 64 96 160
902 if %remoteThreads;
903 160 $nfound = select($rout=$rin,undef,undef,1); # tick each second
904 158 ▶ if ($nfound > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nfound > 0) { } 127 31 158
905 ###################### IF PROCESS REQUEST ########################
906 127 ▶ while (vec($rout,$filenoL,1)) { # process request
Branch: 1 branch
BranchTrueFalseTotal
if (vec $rout, $filenoL, 1) 80 47 127
907 80 ▶ last unless ($l_Sin = recv($L,$msg,PACKETSZ,0)); # ignore receive errors
Branch: 1 branch
BranchTrueFalseTotal
unless $l_Sin = recv($L, $msg, PACKETSZ(), 0) 0 80 80
908 80 ▶ if (length($msg) < HFIXEDSZ) { # ignore if less then header size
Branch: 1 branch
BranchTrueFalseTotal
if (length $msg < HFIXEDSZ()) 4 76 80
909 4 ▶ return 'short header' if $DEBUG & $D_SHRTHD;
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG & $Net::DNSBL::MultiDaemon::D_SHRTHD 4 0 4
910 0 last;
911 }
912 76 ($off,$id,$qr,$opcode,$aa,$tc,$rd,$ra,$mbz,$ad,$cd,$rcode,
913 $qdcount,$ancount,$nscount,$arcount)
914 = gethead(\$msg);
915 76 ▶ if ($qr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($qr) 1 75 76
916 1 ▶ return 'query response' if $DEBUG & $D_QRESP;
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG & $Net::DNSBL::MultiDaemon::D_QRESP 1 0 1
917 0 last;
918 }
919 75 $comment = 'no bl';
920 75 setAUTH(0); # clear authority
921 75 setRA($rd);
922 # if OPCODE
923 75 ▶ if ($eXT && exists $eXT->{OPCODE} && $eXT->{OPCODE}->($eXT,$get,$put,\$msg,
Branch: 6 branches
BranchTrueFalseTotal
if ($eXT and exists $eXT->{'OPCODE'} and $eXT->{'OPCODE'}->($eXT, $get, $put, \$msg, $off, $id, $qr, $opcode, $aa, $tc, $rd, $ra, $mbz, $ad, $cd, $rcode, $qdcount, $ancount, $nscount, $arcount)) { } 0 75 75
elsif ($opcode != QUERY()) { } 1 74 75
elsif ($qdcount != 1 or $ancount or $nscount or $arcount) { } 4 70 74
elsif (($off, $name, $type, $class) = $get->Question(\$msg, $off) and not $name) { } 1 69 70
elsif (not $eXT && exists $eXT->{'CLASS'} && $eXT->{'CLASS'}->($eXT, $get, $put, $id, $opcode, \$name, \$type, \$class) and $class != C_IN()) { } 1 68 69
elsif ($eXT and exists $eXT->{'NAME'} and $eXT->{'NAME'}->($eXT, $get, $put, $id, $opcode, \$name, \$type, \$class) or not $name =~ /$BLzone$/i) { } 1 67 68
Condition33%2/6
$eXT and exists $eXT->{"OPCODE"} and $eXT->{"OPCODE"}->($eXT, $get, $put, \$msg, $off, $id, $qr, $opcode, $aa, $tc, $rd, $ra, $mbz, $ad, $cd, $rcode, $qdcount, $ancount, $nscount, $arcount)
!ll&&!rl&&r
7500
$eXT and exists $eXT->{"OPCODE"}
!ll&&!rl&&r
7500
MC/DC0%0/3
$eXT and exists $eXT->{"OPCODE"} and $eXT->{"OPCODE"}->($eXT, $get, $put, \$msg, $off, $id, $qr, $opcode, $aa, $tc, $rd, $ra, $mbz, $ad, $cd, $rcode, $qdcount, $ancount, $nscount, $arcount)
$eXT exists $eXT->{"OPCODE"} $eXT->{"OPCODE"}->($eXT, $get, $put, \$msg, $off, $id, $qr, $opcode, $aa, $tc, $rd, $ra, $mbz, $ad, $cd, $rcode, $qdcount, $ancount, $nscount, $arcount)
Truth table25%1/4
A and B and C
A= $eXTB= exists $eXT->{"OPCODE"}C= $eXT->{"OPCODE"}->($eXT, $get, $put, \$msg, $off, $id, $qr, $opcode, $aa, $tc, $rd, $ra, $mbz, $ad, $cd, $rcode, $qdcount, $ancount, $nscount, $arcount)
ABCresult
0XX0
10X0
1100
1111
924 $off,$id,$qr,$opcode,$aa,$tc,$rd,$ra,$mbz,$ad,$cd,$rcode,$qdcount,$ancount,$nscount,$arcount)) {
925 ; # message updated
926 0 $comment = 'mdextension opcode';
927 } elsif ($opcode != QUERY) {
928 1 s_response(\$msg,NOTIMP,$id,1,0,0,0);
929 1 $comment = 'not implemented';
930 ▶ } elsif (
Condition66%6/9
$qdcount != 1 or $ancount or $nscount or $arcount
l!l&&r!l&&!r
4070
$qdcount != 1 or $ancount or $nscount
l!l&&r!l&&!r
4070
$qdcount != 1 or $ancount
l!l&&r!l&&!r
4070
MC/DC25%1/4
$qdcount != 1 or $ancount or $nscount or $arcount
$qdcount != 1 $ancount $nscount $arcount
Truth table40%2/5
A or B or C or D
A= $qdcount != 1B= $ancountC= $nscountD= $arcount
ABCDresult
1XXX1
01XX1
001X1
00011
00000
931 $qdcount != 1 ||
932 $ancount ||
933 $nscount ||
934 $arcount
935 ) {
936 4 s_response(\$msg,FORMERR,$id,$qdcount,$ancount,$nscount,$arcount);
937 4 $comment = 'format error 1';
938 ▶ } elsif (
Condition66%2/3
($off, $name, $type, $class) = $get->Question(\$msg, $off) and not $name
!ll&&!rl&&r
0691
MC/DC50%1/2
($off, $name, $type, $class) = $get->Question(\$msg, $off) and not $name
($off, $name, $type, $class) = $get->Question(\$msg, $off) not $name
Truth table66%2/3
A and not(B)
A= ($off, $name, $type, $class) = $get->Question(\$msg, $off)B= not $name
ABresult
0X0
100
111
939 (($off,$name,$type,$class) = $get->Question(\$msg,$off)) &&
940 ! $name) { # name must exist
941 1 s_response(\$msg,FORMERR,$id,1,0,0,0);
942 1 $comment = 'format error 2';
943 # if CLASS
944 ▶ } elsif (!($eXT && exists $eXT->{CLASS} && $eXT->{CLASS}->($eXT,$get,$put,$id,$opcode,\$name,\$type,\$class)) &&
Condition44%4/9
not $eXT && exists $eXT->{"CLASS"} && $eXT->{"CLASS"}->($eXT, $get, $put, $id, $opcode, \$name, \$type, \$class) and $class != C_IN()
!ll&&!rl&&r
0681
$eXT && exists $eXT->{'CLASS'} && $eXT->{'CLASS'}->($eXT, $get, $put, $id, $opcode, \$name, \$type, \$class)
!ll&&!rl&&r
6900
$eXT and exists $eXT->{"CLASS"}
!ll&&!rl&&r
6900
MC/DC25%1/4
not $eXT && exists $eXT->{"CLASS"} && $eXT->{"CLASS"}->($eXT, $get, $put, $id, $opcode, \$name, \$type, \$class) and $class != C_IN()
$eXT exists $eXT->{"CLASS"} $eXT->{'CLASS'}->($eXT, $get, $put, $id, $opcode, \$name, \$type, \$class) $class != C_IN()
Truth table28%2/7
not(A and B && C) and D
A= $eXTB= exists $eXT->{"CLASS"}C= $eXT->{'CLASS'}->($eXT, $get, $put, $id, $opcode, \$name, \$type, \$class)D= $class != C_IN()
ABCDresult
111X0
0XX00
10X00
11000
0XX11
10X11
11011
945 $class != C_IN) { # class must be C_IN
946 1 s_response(\$msg,REFUSED,$id,$qdcount,$ancount,$nscount,$arcount);
947 1 $comment = 'refused';
948 # if NAME
949 ▶ } elsif (($eXT && exists $eXT->{NAME} && $eXT->{NAME}->($eXT,$get,$put,$id,$opcode,\$name,\$type,\$class)) ||
Condition44%4/9
$eXT and exists $eXT->{"NAME"} and $eXT->{"NAME"}->($eXT, $get, $put, $id, $opcode, \$name, \$type, \$class) or not $name =~ /$BLzone$/i
l!l&&r!l&&!r
0167
$eXT and exists $eXT->{"NAME"} and $eXT->{"NAME"}->($eXT, $get, $put, $id, $opcode, \$name, \$type, \$class)
!ll&&!rl&&r
6800
$eXT and exists $eXT->{"NAME"}
!ll&&!rl&&r
6800
MC/DC25%1/4
$eXT and exists $eXT->{"NAME"} and $eXT->{"NAME"}->($eXT, $get, $put, $id, $opcode, \$name, \$type, \$class) or not $name =~ /$BLzone$/i
$eXT exists $eXT->{"NAME"} $eXT->{"NAME"}->($eXT, $get, $put, $id, $opcode, \$name, \$type, \$class) not $name =~ /$BLzone$/i
Truth table28%2/7
A and B and C or not(D)
A= $eXTB= exists $eXT->{"NAME"}C= $eXT->{"NAME"}->($eXT, $get, $put, $id, $opcode, \$name, \$type, \$class)D= not $name =~ /$BLzone$/i
ABCDresult
111X1
0XX11
10X11
11011
0XX00
10X00
11000
950 $name !~ /$BLzone$/i) { # question must be for this zone
951 1 s_response(\$msg,NXDOMAIN,$id,1,0,0,0);
952 1 $comment = 'not this zone';
953 } else {
954 # THIS IS OUR ZONE request, generate a thread to handle it
955  
956 67 ▶ print STDERR $name,' ',TypeTxt->{$type},' ' if $DEBUG & $D_VERBOSE;
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG & $Net::DNSBL::MultiDaemon::D_VERBOSE 0 67 67
957  
958 # if TYPE
959 67 ▶ if ($eXT && exists $eXT->{TYPE} && (my $rv = $eXT->{TYPE}->($eXT,$get,$put,$id,$opcode,\$name,\$type,\$class))) {
Branch: 5 branches
BranchTrueFalseTotal
if ($eXT and exists $eXT->{'TYPE'} and my $rv = $eXT->{'TYPE'}->($eXT, $get, $put, $id, $opcode, \$name, \$type, \$class)) { } 0 67 67
elsif ($type == T_A() or $type == T_ANY() or $type == T_TXT()) { } 61 6 67
elsif ($type == T_NS() and $BLzone eq lc $name) { } 0 6 6
elsif ($type == T_NS() or $type == T_MX() or $type == T_SOA() or $type == T_CNAME() or $type == T_TXT()) { } 4 2 6
elsif ($type == T_AXFR()) { } 1 1 2
Condition33%2/6
$eXT and exists $eXT->{"TYPE"} and my $rv = $eXT->{"TYPE"}->($eXT, $get, $put, $id, $opcode, \$name, \$type, \$class)
!ll&&!rl&&r
6700
$eXT and exists $eXT->{"TYPE"}
!ll&&!rl&&r
6700
MC/DC0%0/3
$eXT and exists $eXT->{"TYPE"} and my $rv = $eXT->{"TYPE"}->($eXT, $get, $put, $id, $opcode, \$name, \$type, \$class)
$eXT exists $eXT->{"TYPE"} my $rv = $eXT->{"TYPE"}->($eXT, $get, $put, $id, $opcode, \$name, \$type, \$class)
Truth table25%1/4
A and B and C
A= $eXTB= exists $eXT->{"TYPE"}C= my $rv = $eXT->{"TYPE"}->($eXT, $get, $put, $id, $opcode, \$name, \$type, \$class)
ABCresult
0XX0
10X0
1100
1111
960 0 $msg = $rv;
961 0 $comment = 'Extension type';
962 ▶ } elsif ( $type == T_A ||
Condition83%5/6
$type == T_A() or $type == T_ANY() or $type == T_TXT()
l!l&&r!l&&!r
6016
$type == T_A() or $type == T_ANY()
l!l&&r!l&&!r
6007
MC/DC66%2/3
$type == T_A() or $type == T_ANY() or $type == T_TXT()
$type == T_A() $type == T_ANY() $type == T_TXT()
Truth table75%3/4
A or B or C
A= $type == T_A()B= $type == T_ANY()C= $type == T_TXT()
ABCresult
1XX1
01X1
0011
0000
963 $type == T_ANY ||
964 $type == T_TXT) {
965 61 ▶ if (( $notRHBL &&
Branch: 2 branches
BranchTrueFalseTotal
if ($notRHBL and $name =~ /^((\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3}))\.(.+)/ and $rip = $1 and $targetIP = "$5.$4.$3.$2" and $zone = $6 and $BLzone eq lc $zone or not $notRHBL and $name =~ /^([a-zA-Z0-9][a-zA-Z0-9\.\-]+[a-zA-Z0-9])\.$BLzone$/ and $rip = $1 and $targetIP = 1 and $zone = $BLzone) { } 59 2 61
elsif ($BLzone eq lc $name and $type != T_TXT()) { } 0 2 2
Condition57%16/28
$notRHBL and $name =~ /^((\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3}))\.(.+)/ and $rip = $1 and $targetIP = "$5.$4.$3.$2" and $zone = $6 and $BLzone eq lc $zone or not $notRHBL and $name =~ /^([a-zA-Z0-9][a-zA-Z0-9\.\-]+[a-zA-Z0-9])\.$BLzone$/ and $rip = $1 and $targetIP = 1 and $zone = $BLzone
l!l&&r!l&&!r
5902
$notRHBL and $name =~ /^((\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3}))\.(.+)/ and $rip = $1 and $targetIP = "$5.$4.$3.$2" and $zone = $6 and $BLzone eq lc $zone
!ll&&!rl&&r
2059
$notRHBL and $name =~ /^((\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3}))\.(.+)/ and $rip = $1 and $targetIP = "$5.$4.$3.$2" and $zone = $6
!ll&&!rl&&r
2059
$notRHBL and $name =~ /^((\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3}))\.(.+)/ and $rip = $1 and $targetIP = "$5.$4.$3.$2"
!ll
259
$notRHBL and $name =~ /^((\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3}))\.(.+)/ and $rip = $1
!ll&&!rl&&r
2059
$notRHBL and $name =~ /^((\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3}))\.(.+)/
!ll&&!rl&&r
0259
not $notRHBL and $name =~ /^([a-zA-Z0-9][a-zA-Z0-9\.\-]+[a-zA-Z0-9])\.$BLzone$/ and $rip = $1 and $targetIP = 1 and $zone = $BLzone
!ll&&!rl&&r
200
not $notRHBL and $name =~ /^([a-zA-Z0-9][a-zA-Z0-9\.\-]+[a-zA-Z0-9])\.$BLzone$/ and $rip = $1 and $targetIP = 1
!ll
20
not $notRHBL and $name =~ /^([a-zA-Z0-9][a-zA-Z0-9\.\-]+[a-zA-Z0-9])\.$BLzone$/ and $rip = $1
!ll&&!rl&&r
200
not $notRHBL and $name =~ /^([a-zA-Z0-9][a-zA-Z0-9\.\-]+[a-zA-Z0-9])\.$BLzone$/
!ll&&!rl&&r
200
MC/DC11%1/9
$notRHBL and $name =~ /^((\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3}))\.(.+)/ and $rip = $1 and $targetIP = "$5.$4.$3.$2" and $zone = $6 and $BLzone eq lc $zone or not $notRHBL and $name =~ /^([a-zA-Z0-9][a-zA-Z0-9\.\-]+[a-zA-Z0-9])\.$BLzone$/ and $rip = $1 and $targetIP = 1 and $zone = $BLzone
$notRHBL $name =~ /^((\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3}))\.(.+)/ $rip = $1 $zone = $6 $BLzone eq lc $zone not $notRHBL $name =~ /^([a-zA-Z0-9][a-zA-Z0-9\.\-]+[a-zA-Z0-9])\.$BLzone$/ $rip = $1 $zone = $BLzone
Truth table7%2/26
A and B and C and D and E or not(F) and G and H and I
A= $notRHBLB= $name =~ /^((\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3}))\.(.+)/C= $rip = $1D= $zone = $6E= $BLzone eq lc $zoneF= not $notRHBLG= $name =~ /^([a-zA-Z0-9][a-zA-Z0-9\.\-]+[a-zA-Z0-9])\.$BLzone$/H= $rip = $1I= $zone = $BLzone
ABCDEFGHIresult
11111XXXX1
0XXXX11111
10XXX11111
110XX11111
1110X11111
1111011111
0XXXX0XXX0
0XXXX10XX0
0XXXX110X0
0XXXX11100
10XXX0XXX0
10XXX10XX0
10XXX110X0
10XXX11100
110XX0XXX0
110XX10XX0
110XX110X0
110XX11100
1110X0XXX0
1110X10XX0
1110X110X0
1110X11100
111100XXX0
1111010XX0
11110110X0
1111011100
966 $name =~ /^((\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3}))\.(.+)/ &&
967 ($rip = $1) &&
968 ($targetIP = "$5.$4.$3.$2") &&
969 ($zone = $6) &&
970 $BLzone eq lc $zone) ||
971 # check for valid RFC1034 domain name, but allow digits in the first character
972 (!$notRHBL && # check RHBL zones
973 ###### CHANGE this REGEXP to alter permissible domain name patterns
974 $name =~ /^([a-zA-Z0-9][a-zA-Z0-9\.\-]+[a-zA-Z0-9])\.$BLzone$/ && # valid domain name
975 ($rip = $1) &&
976 ($targetIP = '' || 1) &&
977 ($zone = $BLzone))) {
978 59 my $expires;
979 # if CACHE
980 59 ▶ if ($eXT && exists $eXT->{CACHE} && (my $rv = $eXT->{CACHE}->($eXT,$get,$put,$id,$opcode,$rip,\$name,\$type,\$class,$ubl))) {
Branch: 8 branches
BranchTrueFalseTotal
if ($eXT and exists $eXT->{'CACHE'} and my $rv = $eXT->{'CACHE'}->($eXT, $get, $put, $id, $opcode, $rip, \$name, \$type, \$class, $ubl)) { } 0 59 59
elsif (not $notRHBL and $ubl and do { if ($ubl->urblwhite($rip)) { not_found($put, $name, $type, $id, \$msg, $SOAptr); $rv = 'whitelisted'; } elsif ($ubl->urblblack($rip)) { ($msg) = _ansrbak($put, $id, 1, $rip, $zone, $type, 3600, A1272(), $BLzone, $myip, 'blacklisted'); $rv = 'blacklisted'; } }) { } 0 59 59
elsif ($rip eq '2.0.0.127') { } 0 59 59
elsif ($csize and exists $cache{$rip} and ($expires = $cache{$rip}{'expires'}) > $now) { } 0 59 59
elsif ($type == T_TXT()) { } 0 59 59
elsif ($notRHBL and @NAignore and matchNetAddr($targetIP, \@NAignore)) { } 1 58 59
elsif ($notRHBL and @NAblock and matchNetAddr($targetIP, \@NAblock)) { } 1 57 58
elsif ($notRHBL and $BBC and $cc = $BBC->country_code_by_addr($targetIP) and grep(($cc eq $_), @{$$DNSBL{'BBC'};})) { } 0 57 57
Condition33%2/6
$eXT and exists $eXT->{"CACHE"} and my $rv = $eXT->{"CACHE"}->($eXT, $get, $put, $id, $opcode, $rip, \$name, \$type, \$class, $ubl)
!ll&&!rl&&r
5900
$eXT and exists $eXT->{"CACHE"}
!ll&&!rl&&r
5900
MC/DC0%0/3
$eXT and exists $eXT->{"CACHE"} and my $rv = $eXT->{"CACHE"}->($eXT, $get, $put, $id, $opcode, $rip, \$name, \$type, \$class, $ubl)
$eXT exists $eXT->{"CACHE"} my $rv = $eXT->{"CACHE"}->($eXT, $get, $put, $id, $opcode, $rip, \$name, \$type, \$class, $ubl)
Truth table25%1/4
A and B and C
A= $eXTB= exists $eXT->{"CACHE"}C= my $rv = $eXT->{"CACHE"}->($eXT, $get, $put, $id, $opcode, $rip, \$name, \$type, \$class, $ubl)
ABCresult
0XX0
10X0
1100
1111
981 0 $msg = $rv;
982 }
983 # if local white/black lists
984 ▶ elsif (!$notRHBL && $ubl && # right side checking and local white/black lists
Condition33%2/6
not $notRHBL and $ubl and do { if ($ubl->urblwhite($rip)) { not_found($put, $name, $type, $id, \$msg, $SOAptr); $rv = "whitelisted"; } elsif ($ubl->urblblack($rip)) { ($msg) = _ansrbak($put, $id, 1, $rip, $zone, $type, 3600, A1272(), $BLzone, $myip, "blacklisted"); $rv = "blacklisted"; } }
!ll&&!rl&&r
5900
not $notRHBL and $ubl
!ll&&!rl&&r
5900
MC/DC0%0/3
not $notRHBL and $ubl and do { if ($ubl->urblwhite($rip)) { not_found($put, $name, $type, $id, \$msg, $SOAptr); $rv = "whitelisted"; } elsif ($ubl->urblblack($rip)) { ($msg) = _ansrbak($put, $id, 1, $rip, $zone, $type, 3600, A1272(), $BLzone, $myip, "blacklisted"); $rv = "blacklisted"; } }
not $notRHBL $ubl do { if ($ubl->urblwhite($rip)) { not_found($put, $name, $type, $id, \$msg, $SOAptr); $rv = "whitelisted"; } elsif ($ubl->urblblack($rip)) { ($msg) = _ansrbak($put, $id, 1, $rip, $zone, $type, 3600, A1272(), $BLzone, $myip, "blacklisted"); $rv = "blacklisted"; } }
Truth table25%1/4
not(A) and B and C
A= not $notRHBLB= $ublC= do { if ($ubl->urblwhite($rip)) { not_found($put, $name, $type, $id, \$msg, $SOAptr); $rv = "whitelisted"; } elsif ($ubl->urblblack($rip)) { ($msg) = _ansrbak($put, $id, 1, $rip, $zone, $type, 3600, A1272(), $BLzone, $myip, "blacklisted"); $rv = "blacklisted"; } }
ABCresult
0XX0
10X0
1100
1111
985 do {
986 0 ▶ if ($ubl->urblwhite($rip)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ubl->urblwhite($rip)) { } 0 0 0
elsif ($ubl->urblblack($rip)) { } 0 0 0
987 0 not_found($put,$name,$type,$id,\$msg,$SOAptr);
988 0 $rv = 'whitelisted';
989 }
990 elsif ($ubl->urblblack($rip)) {
991 0 ($msg) = _ansrbak($put,$id,1,$rip,$zone,$type,3600,A1272,$BLzone,$myip,'blacklisted');
992 0 $rv = 'blacklisted';
993 }
994 }
995 ) {
996 0 $comment = $rv;
997 }
998 elsif ($rip eq '2.0.0.127') { # checkfor DNSBL test
999 0 ($msg) = _ansrbak($put,$id,1,$rip,$zone,$type,3600,A1272,$BLzone,$myip,'DNSBL test response to 127.0.0.2');
1000 0 $comment = 'just testing';
1001 }
1002 ### NOTE, $now does not get updated very often if the host is busy processing in this routine, but at least every 5 minutes.... good enough
1003 ▶ elsif ( $csize && # cacheing enabled
Condition33%2/6
$csize and exists $cache{$rip} and ($expires = $cache{$rip}{"expires"}) > $now
!ll&&!rl&&r
5900
$csize and exists $cache{$rip}
!ll&&!rl&&r
5900
MC/DC0%0/3
$csize and exists $cache{$rip} and ($expires = $cache{$rip}{"expires"}) > $now
$csize exists $cache{$rip} ($expires = $cache{$rip}{"expires"}) > $now
Truth table25%1/4
A and B and C
A= $csizeB= exists $cache{$rip}C= ($expires = $cache{$rip}{"expires"}) > $now
ABCresult
0XX0
10X0
1100
1111
1004 exists $cache{$rip} && # item exists in cache
1005 ($expires = $cache{$rip}->{expires}) > $now ) { # cache not expired
1006 0 $cache{$rip}->{used} = $now; # update last used time
1007 0 my $blist_0 = $cache{$rip}->{who};
1008 0 my $txt = $cache{$rip}->{txt};
1009 0 ▶ $txt = $txt ? $txt . $targetIP : '';
Branch: 1 branch
BranchTrueFalseTotal
$txt ? : 0 0 0
1010 0 ($msg) = _ansrbak($put,$id,1,$rip,$zone,$type,$expires - $now,A1272,$BLzone,$myip,$txt); # send cached record
1011 0 $comment = 'cache record';
1012 0 bump_stats($STATs,$blist_0);
1013 }
1014 elsif ($type == T_TXT) { # none of the rest of static stuff has TXT records
1015 0 not_found($put,$name,$type,$id,\$msg,$SOAptr);
1016 0 $comment = 'no TXT';
1017 }
1018 ▶ elsif ($notRHBL && @NAignore && matchNetAddr($targetIP,\@NAignore)) { # check for IP's to always pass
Condition83%5/6
$notRHBL and @NAignore and matchNetAddr($targetIP, \@NAignore)
!ll&&!rl&&r
5711
$notRHBL and @NAignore
!ll&&!rl&&r
0572
MC/DC66%2/3
$notRHBL and @NAignore and matchNetAddr($targetIP, \@NAignore)
$notRHBL @NAignore matchNetAddr($targetIP, \@NAignore)
Truth table75%3/4
A and B and C
A= $notRHBLB= @NAignoreC= matchNetAddr($targetIP, \@NAignore)
ABCresult
0XX0
10X0
1100
1111
1019 1 not_found($put,$name,$type,$id,\$msg,$SOAptr); # return unconditional NOT FOUND
1020 1 $STATs->{WhiteList} += 1; # bump WhiteList count
1021 1 $comment = 'IGNORE';
1022 }
1023 ▶ elsif ($notRHBL && @NAblock && matchNetAddr($targetIP,\@NAblock)) { # check for IP's to always block
Condition66%4/6
$notRHBL and @NAblock and matchNetAddr($targetIP, \@NAblock)
!ll&&!rl&&r
5701
$notRHBL and @NAblock
!ll&&!rl&&r
0571
MC/DC33%1/3
$notRHBL and @NAblock and matchNetAddr($targetIP, \@NAblock)
$notRHBL @NAblock matchNetAddr($targetIP, \@NAblock)
Truth table50%2/4
A and B and C
A= $notRHBLB= @NAblockC= matchNetAddr($targetIP, \@NAblock)
ABCresult
0XX0
10X0
1100
1111
1024 1 ($msg) = _ansrbak($put,$id,1,$rip,$zone,$type,3600,A1275,$BLzone,$myip); # answer 127.0.0.5
1025 1 $STATs->{BlackList} += 1; # bump BlackList count
1026 1 $comment = 'BLOCK';
1027 }
1028 ▶ elsif ($notRHBL && $BBC && # check for IP's to block by country
Condition33%3/9
$notRHBL and $BBC and $cc = $BBC->country_code_by_addr($targetIP) and grep(($cc eq $_), @{$$DNSBL{"BBC"};})
!ll&&!rl&&r
5700
$notRHBL and $BBC and $cc = $BBC->country_code_by_addr($targetIP)
!ll&&!rl&&r
5700
$notRHBL and $BBC
!ll&&!rl&&r
0570
MC/DC0%0/4
$notRHBL and $BBC and $cc = $BBC->country_code_by_addr($targetIP) and grep(($cc eq $_), @{$$DNSBL{"BBC"};})
$notRHBL $BBC $cc = $BBC->country_code_by_addr($targetIP) grep(($cc eq $_), @{$$DNSBL{"BBC"};})
Truth table20%1/5
A and B and C and D
A= $notRHBLB= $BBCC= $cc = $BBC->country_code_by_addr($targetIP)D= grep(($cc eq $_), @{$$DNSBL{"BBC"};})
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1029 ($cc = $BBC->country_code_by_addr($targetIP)) &&
1030 0 (grep($cc eq $_,@{$DNSBL->{BBC}}))) {
1031 0 ($msg) = _ansrbak($put,$id,1,$rip,$zone,$type,3600,A1276,$BLzone,$myip); # answer 127.0.0.6
1032 0 $STATs->{$cc} += 1; # bump statistics count
1033 0 ▶ $newstat = 1 unless $newstat; # notify refresh that update may be needed
Branch: 1 branch
BranchTrueFalseTotal
unless $newstat 0 0 0
1034 0 $comment = "block $cc";
1035 }
1036 else {
1037 #test here for GENERIC
1038 57 @blist = ();
1039 57 foreach(sort { by_average($STATs,$a,$b) } keys %$STATs) {
1040 285 ▶ next unless $_ =~ /\./; # drop passed,white,black,bbc entries
Branch: 1 branch
BranchTrueFalseTotal
unless $_ =~ /\./ 171 114 285
1041 114 push @blist, $_;
1042 }
1043 57 ▶ push @blist, 'genericPTR' if $regexptr;
Branch: 1 branch
BranchTrueFalseTotal
if $regexptr 0 57 57
1044 # add bread crumbs for Extensions if necessary
1045 57 $rid = undef; # trial remote ID
1046 57 ▶ if ($eXT && exists $eXT->{LOOKUP}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($eXT and exists $eXT->{"LOOKUP"}) 0 57 57
Condition33%1/3
$eXT and exists $eXT->{"LOOKUP"}
!ll&&!rl&&r
5700
MC/DC0%0/2
$eXT and exists $eXT->{"LOOKUP"}
$eXT exists $eXT->{"LOOKUP"}
Truth table33%1/3
A and B
A= $eXTB= exists $eXT->{"LOOKUP"}
ABresult
0X0
100
111
1047 0 $rid = uniqueID();
1048 0 $rid = $eXT->{LOOKUP}->($eXT,$get,$put,$rid,$id,$opcode,\$name,\$type,\$class,\%remoteThreads);
1049 }
1050 57 $rid = setURBLdom($rip,$rid,$notRHBL,$ubl,$DNSBL->{$blist[0]},\%remoteThreads,0); # initialize urbl domain lookup name
1051 57 bl_lookup($put,\$msg,\%remoteThreads,$l_Sin,_alarm($blist[0]),$rid,$id,$rip,$type,$zone,@blist);
1052 57 send($R,$msg,0,$R_Sin); # udp may not block
1053 57 ▶ print STDERR $blist[0] if $DEBUG & $D_VERBOSE;
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG & $Net::DNSBL::MultiDaemon::D_VERBOSE 0 57 57
1054 57 last;
1055 }
1056 }
1057 ▶ elsif ($BLzone eq lc $name && $type != T_TXT) {
Condition66%2/3
$BLzone eq lc $name and $type != T_TXT()
!ll&&!rl&&r
110
MC/DC0%0/2
$BLzone eq lc $name and $type != T_TXT()
$BLzone eq lc $name $type != T_TXT()
Truth table66%2/3
A and B
A= $BLzone eq lc $nameB= $type != T_TXT()
ABresult
0X0
100
111
1058 0 my $noff = newhead(\$msg,
1059 $id,
1060 BITS_QUERY | QR,
1061 1,1,1,0,
1062 );
1063 0 ($noff,my @dnptrs) = $put->Question(\$msg,$noff, # 1 question
1064 $name,$type,C_IN); # type is T_A
1065 0 ($noff,@dnptrs) = $put->A(\$msg,$noff,\@dnptrs, # 1 answer
1066 $name,T_A,C_IN,86400,$myip);
1067 0 ($noff,@dnptrs) = $put->NS(\$msg,$noff,\@dnptrs, # 1 authority
1068 $name,T_NS,C_IN,86400,$BLzone);
1069 }
1070 else {
1071 2 not_found($put,$name,$type,$id,\$msg,$SOAptr);
1072 }
1073 ▶ } elsif ($type == T_NS && $BLzone eq lc $name) { # respond with myip address
Condition66%2/3
$type == T_NS() and $BLzone eq lc $name
!ll&&!rl&&r
510
MC/DC0%0/2
$type == T_NS() and $BLzone eq lc $name
$type == T_NS() $BLzone eq lc $name
Truth table66%2/3
A and B
A= $type == T_NS()B= $BLzone eq lc $name
ABresult
0X0
100
111
1074 0 my $noff = newhead(\$msg,
1075 $id,
1076 BITS_QUERY | QR,
1077 1,1,0,1,
1078 );
1079 0 ($noff,my @dnptrs) = $put->Question(\$msg,$noff, # 1 question
1080 $name,$type,C_IN); # type is T_NS
1081 0 ($noff,@dnptrs) = $put->NS(\$msg,$noff,\@dnptrs, # 1 answer
1082 $name,T_NS,C_IN,$86400,$BLzone);
1083 0 ($noff,@dnptrs) = $put->A(\$msg,$noff,\@dnptrs, # 1 additional glue
1084 $BLzone,T_A,C_IN,86400,$myip);
1085 ▶ } elsif ($type == T_NS || # answer common queries with a not found
Condition91%11/12
$type == T_NS() or $type == T_MX() or $type == T_SOA() or $type == T_CNAME() or $type == T_TXT()
l!l&&r!l&&!r
402
$type == T_NS() or $type == T_MX() or $type == T_SOA() or $type == T_CNAME()
l!l&&r!l&&!r
312
$type == T_NS() or $type == T_MX() or $type == T_SOA()
l!l&&r!l&&!r
213
$type == T_NS() or $type == T_MX()
l!l&&r!l&&!r
114
MC/DC80%4/5
$type == T_NS() or $type == T_MX() or $type == T_SOA() or $type == T_CNAME() or $type == T_TXT()
$type == T_NS() $type == T_MX() $type == T_SOA() $type == T_CNAME() $type == T_TXT()
Truth table83%5/6
A or B or C or D or E
A= $type == T_NS()B= $type == T_MX()C= $type == T_SOA()D= $type == T_CNAME()E= $type == T_TXT()
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
1086 $type == T_MX ||
1087 $type == T_SOA ||
1088 $type == T_CNAME ||
1089 $type == T_TXT) {
1090 4 not_found($put,$name,$type,$id,\$msg,$SOAptr);
1091 } elsif ($type == T_AXFR) {
1092 1 s_response(\$msg,REFUSED,$id,1,0,0,0);
1093 1 $comment = 'refused AXFR';
1094 } else {
1095 1 s_response(\$msg,NOTIMP,$id,1,0,0,0);
1096 1 $comment = 'not implemented';
1097 }
1098 }
1099 18 send($L,$msg,0,$l_Sin); # udp may not block on send
1100 18 ▶ print STDERR " $comment\n" if $DEBUG & $D_VERBOSE;
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG & $Net::DNSBL::MultiDaemon::D_VERBOSE 0 18 18
1101 #print Tmp "$comment\n";
1102 18 last;
1103 }
1104 ##################### IF RESPONSE ###############################
1105 122 ▶ while (vec($rout,$filenoR,1)) { # A response
Branch: 1 branch
BranchTrueFalseTotal
if (vec $rout, $filenoR, 1) 47 75 122
1106 47 undef $msg;
1107 47 ▶ last unless recv($R,$msg,,PACKETSZ,0); # ignore receive errors
Branch: 1 branch
BranchTrueFalseTotal
unless recv $R, $msg, PACKETSZ(), 0 0 47 47
1108 47 ▶ if (length($msg) < HFIXEDSZ) { # ignore if less then header size
Branch: 1 branch
BranchTrueFalseTotal
if (length $msg < HFIXEDSZ()) 9 38 47
1109 9 ▶ return 'short header' if $DEBUG & $D_SHRTHD;
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG & $Net::DNSBL::MultiDaemon::D_SHRTHD 9 0 9
1110 0 last;
1111 }
1112 38 ($off,$rid,$qr,$opcode,$aa,$tc,$rd,$ra,$mbz,$ad,$cd,$rcode,
1113 $qdcount,$ancount,$nscount,$arcount)
1114 = gethead(\$msg);
1115 #print Tmp "GOT $rid, rcode=$rcode\n";
1116 38 ▶ unless ( $tc == 0 &&
Branch: 1 branch
BranchTrueFalseTotal
unless ($tc == 0 and $qr == 1 and $opcode == QUERY() and $rcode == NOERROR() || $rcode == NXDOMAIN() || $rcode == SERVFAIL() and $qdcount == 1 and exists $remoteThreads{$rid}) 8 30 38
Condition38%8/21
$tc == 0 and $qr == 1 and $opcode == QUERY() and $rcode == NOERROR() || $rcode == NXDOMAIN() || $rcode == SERVFAIL() and $qdcount == 1 and exists $remoteThreads{$rid}
!ll&&!rl&&r
0830
$tc == 0 and $qr == 1 and $opcode == QUERY() and $rcode == NOERROR() || $rcode == NXDOMAIN() || $rcode == SERVFAIL() and $qdcount == 1
!ll&&!rl&&r
0038
$tc == 0 and $qr == 1 and $opcode == QUERY() and $rcode == NOERROR() || $rcode == NXDOMAIN() || $rcode == SERVFAIL()
!ll&&!rl&&r
0038
$tc == 0 and $qr == 1 and $opcode == QUERY()
!ll&&!rl&&r
0038
$tc == 0 and $qr == 1
!ll&&!rl&&r
0038
$rcode == NOERROR() or $rcode == NXDOMAIN() or $rcode == SERVFAIL()
l!l&&r!l&&!r
3800
$rcode == NOERROR() or $rcode == NXDOMAIN()
l!l&&r!l&&!r
3800
MC/DC12%1/8
$tc == 0 and $qr == 1 and $opcode == QUERY() and $rcode == NOERROR() || $rcode == NXDOMAIN() || $rcode == SERVFAIL() and $qdcount == 1 and exists $remoteThreads{$rid}
$tc == 0 $qr == 1 $opcode == QUERY() $rcode == NOERROR() $rcode == NXDOMAIN() $rcode == SERVFAIL() $qdcount == 1 exists $remoteThreads{$rid}
Truth table15%2/13
A and B and C and D or E or F and G and H
A= $tc == 0B= $qr == 1C= $opcode == QUERY()D= $rcode == NOERROR()E= $rcode == NXDOMAIN()F= $rcode == SERVFAIL()G= $qdcount == 1H= exists $remoteThreads{$rid}
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
110XXXXX0
111000XX0
1111XX0X0
11101X0X0
1110010X0
1111XX100
11101X100
111001100
1111XX111
11101X111
111001111
1117 $qr == 1 &&
1118 $opcode == QUERY &&
1119 ($rcode == NOERROR || $rcode == NXDOMAIN || $rcode == SERVFAIL) &&
1120 $qdcount == 1 &&
1121 exists $remoteThreads{$rid}) { # must not be my question!
1122 8 ▶ return 'not me 1' if $DEBUG & $D_NOTME;
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG & $Net::DNSBL::MultiDaemon::D_NOTME 8 0 8
1123 0 last;
1124 }
1125 30 ($l_Sin,$rip,$id,$type,$zone,@blist) = @{$remoteThreads{$rid}->{args}};
1126 30 ▶ my $urbldom = exists $remoteThreads{$rid}->{urbl} ? $remoteThreads{$rid}->{urbl} : '';
Branch: 1 branch
BranchTrueFalseTotal
exists $remoteThreads{$rid}{'urbl'} ? : 0 30 30
1127 30 ($off,$name,$t,$class) = $get->Question(\$msg,$off);
1128 30 my($answer,$attl,@generic);
1129 30 ▶ if ($ancount && $rcode == &NOERROR) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ancount and $rcode == &NOERROR) { } 27 3 30
elsif ($t == T_PTR() and $rcode == NXDOMAIN() || $rcode == SERVFAIL()) { } 0 6 6
Condition66%2/3
$ancount and $rcode == &NOERROR
!ll&&!rl&&r
3027
MC/DC50%1/2
$ancount and $rcode == &NOERROR
$ancount $rcode == &NOERROR
Truth table66%2/3
A and B
A= $ancountB= $rcode == &NOERROR
ABresult
0X0
100
111
1130 27 ▶ $name =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\.(.+)$/ || $name =~ /^([a-zA-Z0-9][a-zA-Z0-9\.\-]+[a-zA-Z0-9])\.($blist[0])$/;
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\.(.+)$/ or $name =~ /^([a-zA-Z0-9][a-zA-Z0-9\.\-]+[a-zA-Z0-9])\.($blist[0])$/ 27 0 27
1131 27 my $z = lc $2;
1132 #print Tmp "RESPONSE U $urbldom, R $rip, One $1, N $name, Z $z\n";
1133 27 ▶ $z = ($z eq lc $blist[0]) || ($z eq 'in-addr.arpa' && $blist[0] eq 'genericPTR')
Branch: 1 branch
BranchTrueFalseTotal
$z eq lc $blist[0] || $z eq 'in-addr.arpa' && $blist[0] eq 'genericPTR' ? : 2 25 27
Condition50%3/6
$z eq lc $blist[0] or $z eq "in-addr.arpa" and $blist[0] eq "genericPTR"
l!l&&r!l&&!r
2025
$z eq "in-addr.arpa" and $blist[0] eq "genericPTR"
!ll&&!rl&&r
2500
MC/DC33%1/3
$z eq lc $blist[0] or $z eq "in-addr.arpa" and $blist[0] eq "genericPTR"
$z eq lc $blist[0] $z eq "in-addr.arpa" $blist[0] eq "genericPTR"
Truth table50%2/4
A or B and C
A= $z eq lc $blist[0]B= $z eq "in-addr.arpa"C= $blist[0] eq "genericPTR"
ABCresult
1XX1
0111
00X0
0100
1134 ? 1 : 0;
1135 27 ▶ unless ( $z && # not my question
Branch: 1 branch
BranchTrueFalseTotal
unless ($z and !$urbldom && $rip eq $1 || $urbldom && $urbldom eq $1 and $t == T_A() || $t == T_PTR() and $class == C_IN()) 25 2 27
Condition42%9/21
$z and !$urbldom && $rip eq $1 || $urbldom && $urbldom eq $1 and $t == T_A() || $t == T_PTR() and $class == C_IN()
!ll&&!rl&&r
2502
$z and !$urbldom && $rip eq $1 || $urbldom && $urbldom eq $1 and $t == T_A() || $t == T_PTR()
!ll&&!rl&&r
2502
$z and !$urbldom && $rip eq $1 || $urbldom && $urbldom eq $1
!ll&&!rl&&r
2502
not $urbldom and $rip eq $1 or $urbldom and $urbldom eq $1
l!l&&r!l&&!r
200
not $urbldom and $rip eq $1
!ll&&!rl&&r
002
$urbldom and $urbldom eq $1
!ll&&!rl&&r
000
$t == T_A() or $t == T_PTR()
l!l&&r!l&&!r
200
MC/DC12%1/8
$z and !$urbldom && $rip eq $1 || $urbldom && $urbldom eq $1 and $t == T_A() || $t == T_PTR() and $class == C_IN()
$z not $urbldom $rip eq $1 $urbldom $urbldom eq $1 $t == T_A() $t == T_PTR() $class == C_IN()
Truth table10%2/20
A and not(B) and C or D and E and F or G and H
A= $zB= not $urbldomC= $rip eq $1D= $urbldomE= $urbldom eq $1F= $t == T_A()G= $t == T_PTR()H= $class == C_IN()
ABCDEFGHresult
0XXXXXXX0
10X0XXXX0
10X10XXX0
1100XXXX0
11010XXX0
111XX00X0
10X1100X0
1101100X0
111XX1X00
111XX0100
10X111X00
10X110100
110111X00
110110100
111XX1X11
111XX0111
10X111X11
10X110111
110111X11
110110111
1136 ((!$urbldom && $rip eq $1) ||
1137 ($urbldom && $urbldom eq $1)) && # not my question
1138 ($t == T_A || $t == T_PTR) && # not my question
1139 $class == C_IN) { # not my question
1140 25 ▶ return 'not me 2' if $DEBUG & $D_NOTME;
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG & $Net::DNSBL::MultiDaemon::D_NOTME 25 0 25
1141 0 last;
1142 }
1143 2 undef $answer;
1144  
1145 2 setAUTH($aa); # mirror out authority state
1146 2 setRA($rd);
1147  
1148 ANSWER:
1149 2 foreach(0..$ancount -1) {
1150 2 ($off,$name,$t,$class,$ttl,$rdl,@rdata) = $get->next(\$msg,$off);
1151 2 ▶ next if $answer; # throw away unneeded answers
Branch: 1 branch
BranchTrueFalseTotal
if $answer 0 2 2
1152 2 ▶ if ($t == T_A) {
Branch: 2 branches
BranchTrueFalseTotal
if ($t == T_A()) { } 2 0 2
elsif ($t == T_PTR() and $blist[0] eq 'genericPTR') { } 0 0 0
1153 2 ▶ if (exists $DNSBL->{"$blist[0]"}->{acceptany}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$DNSBL{"$blist[0]"}{"acceptany"}) 0 2 2
1154 0 $answer = A1272;
1155 0 $attl = $ttl;
1156 0 last ANSWER;
1157 }
1158 my $mask = (exists $DNSBL->{"$blist[0]"}->{acceptmask})
1159 2 ▶ ? $DNSBL->{"$blist[0]"}->{acceptmask} : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $$DNSBL{"$blist[0]"}{'acceptmask'} ? : 0 2 2
1160 2 ▶ while($answer = shift @rdata) { # see if answer is on accept list
Branch: 1 branch
BranchTrueFalseTotal
if ($answer = shift @rdata) 2 2 4
1161 2 my $IP = inet_ntoa($answer);
1162 2 ▶ if ($mask & unpack("N",$answer) || grep($IP eq $_,keys %{$DNSBL->{"$blist[0]"}->{accept}})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mask & unpack("N", $answer) or grep(($IP eq $_), keys %{$$DNSBL{"$blist[0]"}{"accept"};})) 0 2 2
Condition33%1/3
$mask & unpack("N", $answer) or grep(($IP eq $_), keys %{$$DNSBL{"$blist[0]"}{"accept"};})
l!l&&r!l&&!r
002
MC/DC0%0/2
$mask & unpack("N", $answer) or grep(($IP eq $_), keys %{$$DNSBL{"$blist[0]"}{"accept"};})
$mask & unpack("N", $answer) grep(($IP eq $_), keys %{$$DNSBL{"$blist[0]"}{"accept"};})
Truth table33%1/3
A or B
A= $mask & unpack("N", $answer)B= grep(($IP eq $_), keys %{$$DNSBL{"$blist[0]"}{"accept"};})
ABresult
1X1
011
000
1163 0 $answer = A1272;
1164 0 $attl = $ttl; # preserve TTL of this responder
1165 0 last ANSWER;
1166 }
1167 2 undef $answer;
1168 } # end of rdata
1169 }
1170 ▶ elsif ($t == T_PTR && $blist[0] eq 'genericPTR') { # duplicates in-addr.arpa lookup, inefficient, but does not happen often
Condition0%0/3
$t == T_PTR() and $blist[0] eq "genericPTR"
!ll&&!rl&&r
000
MC/DC0%0/2
$t == T_PTR() and $blist[0] eq "genericPTR"
$t == T_PTR() $blist[0] eq "genericPTR"
Truth table0%0/3
A and B
A= $t == T_PTR()B= $blist[0] eq "genericPTR"
ABresult
0X0
100
111
1171 #print Tmp "add $rdata[0]\n";
1172 0 push @generic, $rdata[0];
1173 }
1174 } # end of each ANSWER
1175 2 $ttl = $attl; # restore responder TTL
1176 }
1177 ▶ elsif ($t == T_PTR && ($rcode == NXDOMAIN || $rcode == SERVFAIL)) { # no reverse lookup
Condition16%1/6
$t == T_PTR() and $rcode == NXDOMAIN() || $rcode == SERVFAIL()
!ll&&!rl&&r
300
$rcode == NXDOMAIN() or $rcode == SERVFAIL()
l!l&&r!l&&!r
000
MC/DC0%0/3
$t == T_PTR() and $rcode == NXDOMAIN() || $rcode == SERVFAIL()
$t == T_PTR() $rcode == NXDOMAIN() $rcode == SERVFAIL()
Truth table25%1/4
A and B or C
A= $t == T_PTR()B= $rcode == NXDOMAIN()C= $rcode == SERVFAIL()
ABCresult
0XX0
1000
11X1
1011
1178 #print Tmp "PTR w/ NXDOMAIN or SERVFAIL\n";
1179 0 $answer = A1274;
1180 0 $ttl = 3600;
1181 0 $nscount = $arcount = 0;
1182 }
1183  
1184 5 ▶ if (@generic) {
Branch: 1 branch
BranchTrueFalseTotal
if (@generic) 0 5 5
1185 0 my @names;
1186 0 foreach my $g (@generic) {
1187 0 ▶ last if $iptr && grep($g =~ /$_/i, @$iptr);
Branch: 1 branch
BranchTrueFalseTotal
if $iptr and grep(($g =~ /$_/i), @$iptr) 0 0 0
Condition0%0/3
$iptr and grep(($g =~ /$_/i), @$iptr)
!ll&&!rl&&r
000
MC/DC0%0/2
$iptr and grep(($g =~ /$_/i), @$iptr)
$iptr grep(($g =~ /$_/i), @$iptr)
Truth table0%0/3
A and B
A= $iptrB= grep(($g =~ /$_/i), @$iptr)
ABresult
0X0
100
111
1188 0 ▶ push @names, $g if $g && ! grep($g =~ /$_/i, @$regexptr);
Branch: 1 branch
BranchTrueFalseTotal
if $g and not grep(($g =~ /$_/i), @$regexptr) 0 0 0
Condition0%0/3
$g and not grep(($g =~ /$_/i), @$regexptr)
!ll&&!rl&&r
000
MC/DC0%0/2
$g and not grep(($g =~ /$_/i), @$regexptr)
$g not grep(($g =~ /$_/i), @$regexptr)
Truth table0%0/3
A and not(B)
A= $gB= not grep(($g =~ /$_/i), @$regexptr)
ABresult
0X0
100
111
1189 }
1190 0 ▶ $answer = A1277 unless @names;
Branch: 1 branch
BranchTrueFalseTotal
unless @names 0 0 0
1191 0 $ttl = 3600;
1192 }
1193 5 ▶ if ($answer) { # if valid answer
Branch: 2 branches
BranchTrueFalseTotal
if ($answer) { } 0 5 5
elsif (do { print STDERR '+' if $DEBUG & $Net::DNSBL::MultiDaemon::D_VERBOSE; my $rv = 0; until ($rv) { shift @blist; if (@blist) { last unless $deadDNSBL{"$blist[0]"} > $numberoftries; } else { $rv = 1; } ; } ; $rv }) { } 3 2 5
1194 0 my $txt = '';
1195 0 ▶ if ( $csize && # caching enabled && answer is from a real DSNBL
Branch: 1 branch
BranchTrueFalseTotal
if ($csize and $answer == A1272() || $answer == A1274() || $answer == A1277()) 0 0 0
Condition0%0/9
$csize and $answer == A1272() || $answer == A1274() || $answer == A1277()
!ll&&!rl&&r
000
$answer == A1272() or $answer == A1274() or $answer == A1277()
l!l&&r!l&&!r
000
$answer == A1272() or $answer == A1274()
l!l&&r!l&&!r
000
MC/DC0%0/4
$csize and $answer == A1272() || $answer == A1274() || $answer == A1277()
$csize $answer == A1272() $answer == A1274() $answer == A1277()
Truth table0%0/5
A and B or C or D
A= $csizeB= $answer == A1272()C= $answer == A1274()D= $answer == A1277()
ABCDresult
0XXX0
10000
11XX1
101X1
10011
1196 ($answer == A1272 || $answer == A1274 || $answer == A1277) ) {
1197  
1198 # ip address => {
1199 # expires => time, now + TTL from response or 3600 minimum
1200 # used => time, time cache item was last used
1201 # who => $blist[0], which DNSBL caused caching
1202 # txt => 'string', txt from our config file or empty
1203 # },
1204 0 ▶ $txt = $DNSBL->{$blist[0]}->{error} if exists $DNSBL->{$blist[0]};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$DNSBL{$blist[0]} 0 0 0
1205 0 ▶ my $trailer = $notRHBL ? revIP($rip) : '';
Branch: 1 branch
BranchTrueFalseTotal
$notRHBL ? : 0 0 0
1206 0 ▶ $txt = $txt ? $txt . $trailer : '';
Branch: 1 branch
BranchTrueFalseTotal
$txt ? : 0 0 0
1207 0 $cache{$rip} = {
1208 expires => $now + $ttl, # use responding DNSBL remaining ttl
1209 used => $now,
1210 who => $blist[0],
1211 txt => $txt
1212 };
1213 }
1214 0 bump_stats($STATs,$blist[0]);
1215 # $STATs->{"$blist[0]"} += 1; # bump statistics count
1216 # if (exists $CNTs{"$blist[0]"}) {
1217 # $CNTs{"$blist[0]"} += 1;
1218 # } else {
1219 # $CNTs{"$blist[0]"} = 1;
1220 # $AVGs{"$blist[0]"} = 1;
1221 # }
1222 # $newstat = 1 unless $newstat; # notify refresh that update may be needed
1223  
1224 0 ▶ my($nmsg,$noff,@dnptrs) = ($FATans) # make proto answer
Branch: 1 branch
BranchTrueFalseTotal
$FATans ? : 0 0 0
1225 ? _ansrbak($put,$id,$nscount + $arcount +1,$rip,$zone,$type,$ttl,$answer,$BLzone,$myip,$txt)
1226 : _ansrbak($put,$id,1,$rip,$zone,$type,$ttl,$answer,$BLzone,$myip,$txt);
1227 ## add the ns section from original reply into the authority section so we can see where it came from, it won't hurt anything
1228 0 ▶ if ($FATans) {
Branch: 1 branch
BranchTrueFalseTotal
if ($FATans) 0 0 0
1229 0 foreach(0..$nscount -1) {
1230 0 ($off,$Oname,$Otype,$Oclass,$Ottl,$Ordlength,$Odata)
1231 = $get->next(\$msg,$off);
1232 0 ($noff,@dnptrs) = $put->NS(\$nmsg,$noff,\@dnptrs,
1233 $Oname,$Otype,$Oclass,$Ottl,$Odata);
1234 }
1235  
1236 # add the authority section from original reply so we can see where it came from
1237 0 foreach(0..$arcount -1) {
1238 0 ($off,$Oname,$Otype,$Oclass,$Ottl,$Ordlength,$Odata)
1239 = $get->next(\$msg,$off);
1240 0 ▶ if ($Otype == T_A) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Otype == T_A()) { } 0 0 0
elsif ($Otype == T_AAAA()) { } 0 0 0
1241 0 ($noff,@dnptrs) = $put->A(\$nmsg,$noff,\@dnptrs,
1242 $Oname,$Otype,$Oclass,$Ottl,$Odata);
1243 } elsif ($Otype == T_AAAA) {
1244 0 ($noff,@dnptrs) = $put->AAAA(\$nmsg,$noff,\@dnptrs,
1245 $Oname,$Otype,$Oclass,$Ottl,$Odata);
1246 } else {
1247 0 next; # skip unknown authority types
1248 }
1249 }
1250 } # end FATans
1251 # if ANSWER
1252 0 ▶ if ($eXT && exists $eXT->{ANSWER} && $eXT->{ANSWER}->($eXT,$get,$put,$rid,$ttl,\$nmsg,\%remoteThreads)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($eXT and exists $eXT->{"ANSWER"} and $eXT->{"ANSWER"}->($eXT, $get, $put, $rid, $ttl, \$nmsg, \%remoteThreads)) 0 0 0
Condition0%0/6
$eXT and exists $eXT->{"ANSWER"} and $eXT->{"ANSWER"}->($eXT, $get, $put, $rid, $ttl, \$nmsg, \%remoteThreads)
!ll&&!rl&&r
000
$eXT and exists $eXT->{"ANSWER"}
!ll&&!rl&&r
000
MC/DC0%0/3
$eXT and exists $eXT->{"ANSWER"} and $eXT->{"ANSWER"}->($eXT, $get, $put, $rid, $ttl, \$nmsg, \%remoteThreads)
$eXT exists $eXT->{"ANSWER"} $eXT->{"ANSWER"}->($eXT, $get, $put, $rid, $ttl, \$nmsg, \%remoteThreads)
Truth table0%0/4
A and B and C
A= $eXTB= exists $eXT->{"ANSWER"}C= $eXT->{"ANSWER"}->($eXT, $get, $put, $rid, $ttl, \$nmsg, \%remoteThreads)
ABCresult
0XX0
10X0
1100
1111
1253 ; # will update $nmsg
1254 }
1255 0 delete $remoteThreads{$rid};
1256 0 $msg = $nmsg;
1257 0 ▶ $ROK = 0 if $DEBUG & $D_ANSTOP;
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG & $Net::DNSBL::MultiDaemon::D_ANSTOP 0 0 0
1258 }
1259 # no answer
1260 elsif (do {
1261 5 ▶ print STDERR '+' if $DEBUG & $D_VERBOSE;
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG & $Net::DNSBL::MultiDaemon::D_VERBOSE 0 5 5
1262 #print Tmp "While eliminate $rid $blist[0]\n";
1263 5 my $rv = 0;
1264 5 ▶ while(!$rv) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rv) 5 3 8
1265 5 shift @blist;
1266 5 ▶ unless (@blist) {
Branch: 1 branch
BranchTrueFalseTotal
if (@blist) { } 2 3 5
1267 3 $rv = 1;
1268 } else {
1269 2 ▶ last unless $deadDNSBL{"$blist[0]"} > $numberoftries; # ignore hosts that don't answer
Branch: 1 branch
BranchTrueFalseTotal
unless $deadDNSBL{"$blist[0]"} > $numberoftries 2 0 2
1270 }
1271 }
1272 5 $rv;
1273 }) { # if no more hosts
1274 # if NOTFOUND
1275 not_found($put,$rip .'.'. $zone,$type,$id,\$msg,$SOAptr) # send not found response
1276 3 ▶ unless $eXT && exists $eXT->{NOTFOUND} && $eXT->{NOTFOUND}->($eXT,$get,$put,$rid,$rip,\$type,\$zone,\$msg,\%remoteThreads);
Branch: 1 branch
BranchTrueFalseTotal
unless $eXT and exists $eXT->{"NOTFOUND"} and $eXT->{"NOTFOUND"}->($eXT, $get, $put, $rid, $rip, \$type, \$zone, \$msg, \%remoteThreads) 3 0 3
Condition33%2/6
$eXT and exists $eXT->{"NOTFOUND"} and $eXT->{"NOTFOUND"}->($eXT, $get, $put, $rid, $rip, \$type, \$zone, \$msg, \%remoteThreads)
!ll&&!rl&&r
300
$eXT and exists $eXT->{"NOTFOUND"}
!ll&&!rl&&r
300
MC/DC0%0/3
$eXT and exists $eXT->{"NOTFOUND"} and $eXT->{"NOTFOUND"}->($eXT, $get, $put, $rid, $rip, \$type, \$zone, \$msg, \%remoteThreads)
$eXT exists $eXT->{"NOTFOUND"} $eXT->{"NOTFOUND"}->($eXT, $get, $put, $rid, $rip, \$type, \$zone, \$msg, \%remoteThreads)
Truth table25%1/4
A and B and C
A= $eXTB= exists $eXT->{"NOTFOUND"}C= $eXT->{"NOTFOUND"}->($eXT, $get, $put, $rid, $rip, \$type, \$zone, \$msg, \%remoteThreads)
ABCresult
0XX0
10X0
1100
1111
1277 3 delete $remoteThreads{$rid};
1278 # endif
1279 3 $STATs->{Passed} += 1;
1280 3 ▶ $newstat = 1 unless $newstat; # notify refresh that update may be needed
Branch: 1 branch
BranchTrueFalseTotal
unless $newstat 3 0 3
1281 } else {
1282 2 $deadDNSBL{"$blist[0]"} = 1; # reset retry count
1283 #print Tmp "NOTFOUND bl_lookup, R \n";
1284 2 $rid = setURBLdom($rip,$rid,$notRHBL,$ubl,$DNSBL->{$blist[0]},\%remoteThreads,1); # initialize urbl domain lookup name
1285 2 bl_lookup($put,\$msg,\%remoteThreads,$l_Sin,_alarm($blist[0]),$rid,$id,$rip,$type,$zone,@blist);
1286 2 ▶ print STDERR $blist[0] if $DEBUG & $D_VERBOSE;
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG & $Net::DNSBL::MultiDaemon::D_VERBOSE 0 2 2
1287 2 send($R,$msg,0,$R_Sin); # udp may not block
1288 2 last;
1289 }
1290 3 send($L,$msg,0,$l_Sin);
1291  
1292 3 ▶ if ($DEBUG & $D_VERBOSE) {
Branch: 1 branch
BranchTrueFalseTotal
if ($DEBUG & $Net::DNSBL::MultiDaemon::D_VERBOSE) 0 3 3
1293 0 ▶ if ($answer) {
Branch: 1 branch
BranchTrueFalseTotal
if ($answer) { } 0 0 0
1294 0 print STDERR ' ',inet_ntoa($answer),"\n";
1295 } else {
1296 0 print STDERR " no bl\n";
1297 }
1298 }
1299 3 last;
1300 }
1301 }
1302 ##################### TIMEOUT, do busywork #######################
1303 else { # must be timeout
1304 31 my $prpshadow = $prp;
1305 31 $now = time; # check various alarm status
1306 31 ▶ unless ($now < $next) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($now < $next) 0 31 31
1307 0 average($STATs);
1308 0 ▶ purge_cache() if $prp < 0; # initiate cache purge every 5 minutes or so
Branch: 1 branch
BranchTrueFalseTotal
if $prp < 0 0 0 0
1309 }
1310 31 ▶ purge_cache() unless $prpshadow < 0; # run cache purge thread unless just initiated
Branch: 1 branch
BranchTrueFalseTotal
unless $prpshadow < 0 0 31 31
1311 31 foreach $rid (keys %remoteThreads) {
1312 17 ▶ next unless $remoteThreads{$rid}->{expire} < $now; # expired??
Branch: 1 branch
BranchTrueFalseTotal
unless $remoteThreads{$rid}{"expire"} < $now 12 5 17
1313  
1314 5 ($l_Sin,$rip,$id,$type,$zone,@blist) = @{$remoteThreads{$rid}->{args}};
1315  
1316 5 ▶ if (++$deadDNSBL{"$blist[0]"} > $numberoftries) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$deadDNSBL{"$blist[0]"} > $numberoftries) 0 5 5
1317 0 $deadDNSBL{"$blist[0]"} = 3600; # wait an hour to retry
1318 0 ▶ if ($LogLevel) {
Branch: 1 branch
BranchTrueFalseTotal
if ($LogLevel) 0 0 0
1319 0 syslog($LogLevel, "timeout connecting to $blist[0]\n");
1320 }
1321 }
1322  
1323 5 ▶ if ($blist[0] eq 'in-addr.arpa') { # expired reverse DNS lookup ?
Branch: 2 branches
BranchTrueFalseTotal
if ($blist[0] eq 'in-addr.arpa') { } 1 4 5
elsif (do { print STDERR '?' if $DEBUG & $Net::DNSBL::MultiDaemon::D_VERBOSE; my $rv = 0; until ($rv) { shift @blist; if (@blist) { last unless $deadDNSBL{"$blist[0]"} > $numberoftries; } else { $rv = 1; } ; } ; $rv }) { } 1 3 4
1324 1 delete $remoteThreads{$rid};
1325 1 $deadDNSBL{"$blist[0]"} = 0; # reset timeout (this one never expires)
1326 my $txt = exists $DNSBL->{$blist[0]}
1327 ? $DNSBL->{$blist[0]}->{error}
1328 1 ▶ : '';
Branch: 1 branch
BranchTrueFalseTotal
exists $$DNSBL{$blist[0]} ? : 1 0 1
1329 1 $cache{$rip} = {
1330 expires => $now + 3600, # always an hour
1331 used => $now,
1332 who => $blist[0],
1333 txt => $txt
1334 };
1335 1 bump_stats($STATs,$blist[0]);
1336 # $STATs->{"$blist[0]"} += 1; # bump statistics count
1337 # if (exists $CNTs{"$blist[0]"}) {
1338 # $CNTs{"$blist[0]"} += 1;
1339 # } else {
1340 # $CNTs{"$blist[0]"} = 1;
1341 # $AVGs{"$blist[0]"} = 1;
1342 # }
1343 # $newstat = 1 unless $newstat; # notify refresh that update may be needed
1344 1 ($msg) = _ansrbak($put,$id,1,$rip,$zone,$type,3600,A1274,$BLzone,$myip,$txt);
1345 1 send($L,$msg,0,$l_Sin);
1346 1 ▶ print STDERR " expired Rdns\n" if $DEBUG & $D_VERBOSE;
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG & $Net::DNSBL::MultiDaemon::D_VERBOSE 0 1 1
1347 }
1348 elsif (do {
1349 4 ▶ print STDERR '?' if $DEBUG & $D_VERBOSE;
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG & $Net::DNSBL::MultiDaemon::D_VERBOSE 0 4 4
1350 4 my $rv = 0;
1351 4 ▶ while(!$rv) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($rv) 4 1 5
1352 4 shift @blist;
1353 4 ▶ unless (@blist) {
Branch: 1 branch
BranchTrueFalseTotal
if (@blist) { } 3 1 4
1354 1 $rv = 1;
1355 } else {
1356 3 ▶ last unless $deadDNSBL{"$blist[0]"} > $numberoftries; # ignore hosts that don't answer
Branch: 1 branch
BranchTrueFalseTotal
unless $deadDNSBL{"$blist[0]"} > $numberoftries 3 0 3
1357 }
1358 }
1359 4 $rv;
1360 }) { # if no more hosts
1361 # if NOTFOUND
1362 not_found($put,$rip .'.'. $BLzone,$type,$id,\$msg,$SOAptr) # send not found response
1363 1 ▶ unless $eXT && exists $eXT->{NOTFOUND} && $eXT->{NOTFOUND}->($eXT,$get,$put,$rid,$rip,\$type,\$BLzone,\$msg,\%remoteThreads);
Branch: 1 branch
BranchTrueFalseTotal
unless $eXT and exists $eXT->{"NOTFOUND"} and $eXT->{"NOTFOUND"}->($eXT, $get, $put, $rid, $rip, \$type, \$BLzone, \$msg, \%remoteThreads) 1 0 1
Condition33%2/6
$eXT and exists $eXT->{"NOTFOUND"} and $eXT->{"NOTFOUND"}->($eXT, $get, $put, $rid, $rip, \$type, \$BLzone, \$msg, \%remoteThreads)
!ll&&!rl&&r
100
$eXT and exists $eXT->{"NOTFOUND"}
!ll&&!rl&&r
100
MC/DC0%0/3
$eXT and exists $eXT->{"NOTFOUND"} and $eXT->{"NOTFOUND"}->($eXT, $get, $put, $rid, $rip, \$type, \$BLzone, \$msg, \%remoteThreads)
$eXT exists $eXT->{"NOTFOUND"} $eXT->{"NOTFOUND"}->($eXT, $get, $put, $rid, $rip, \$type, \$BLzone, \$msg, \%remoteThreads)
Truth table25%1/4
A and B and C
A= $eXTB= exists $eXT->{"NOTFOUND"}C= $eXT->{"NOTFOUND"}->($eXT, $get, $put, $rid, $rip, \$type, \$BLzone, \$msg, \%remoteThreads)
ABCresult
0XX0
10X0
1100
1111
1364 1 delete $remoteThreads{$rid};
1365 # endif
1366 1 $STATs->{Passed} += 1; # count messages that pass thru this filter
1367 1 ▶ $newstat = 1 unless $newstat; # notify refresh that update may be needed
Branch: 1 branch
BranchTrueFalseTotal
unless $newstat 1 0 1
1368 1 send($L,$msg,0,$l_Sin);
1369 1 ▶ print STDERR " no bl\n" if $DEBUG & $D_VERBOSE;
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG & $Net::DNSBL::MultiDaemon::D_VERBOSE 0 1 1
1370 } else {
1371 #print Tmp "second NOTFOUND\n";
1372 3 bl_lookup($put,\$msg,\%remoteThreads,$l_Sin,_alarm($blist[0]),$rid,$id,$rip,$type,$zone,@blist);
1373 3 send($R,$msg,0,$R_Sin); # udp may not block
1374 3 ▶ print STDERR $blist[0] if $DEBUG & $D_VERBOSE;
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG & $Net::DNSBL::MultiDaemon::D_VERBOSE 0 3 3
1375 }
1376 }
1377 31 foreach(keys %deadDNSBL) { # eventually retry dead DNSBL
1378 68 ▶ --$deadDNSBL{"$_"} if $deadDNSBL{"$_"} > $numberoftries;
Branch: 1 branch
BranchTrueFalseTotal
if $deadDNSBL{"$_"} > $numberoftries 0 68 68
1379 }
1380 31 ▶ if ($newstat > 1 ||
Branch: 1 branch
BranchTrueFalseTotal
if ($newstat > 1 or $refresh < $now and $newstat) 3 28 31
Condition66%4/6
$newstat > 1 or $refresh < $now and $newstat
l!l&&r!l&&!r
0328
$refresh < $now and $newstat
!ll&&!rl&&r
2803
MC/DC33%1/3
$newstat > 1 or $refresh < $now and $newstat
$newstat > 1 $refresh < $now $newstat
Truth table50%2/4
A or B and C
A= $newstat > 1B= $refresh < $nowC= $newstat
ABCresult
1XX1
0111
00X0
0100
1381 ($refresh < $now && $newstat)) { # update stats file
1382 3 write_stats($Sfile,$STATs,$StatStamp,$csize,$cused);
1383 3 $refresh = $now + $$Run;
1384 3 $newstat = 0;
1385 }
1386 31 ▶ return 'caught timer' if $DEBUG & $D_TIMONLY;
Branch: 1 branch
BranchTrueFalseTotal
if $DEBUG & $Net::DNSBL::MultiDaemon::D_TIMONLY 0 31 31
1387 }
1388 } while($$Run && $ROK);
1389 28 ▶ write_stats($Sfile,$STATs,$StatStamp,$csize,$cused) if $newstat; # always update on exit if needed
Branch: 1 branch
BranchTrueFalseTotal
if $newstat 0 28 28
1390 }
1391  
1392 # answer back prototype
1393 #
1394 # input: $put,$id,$arcount,$rip,$zone,$type,$ttl,$answer,$BLzone,$myip,$withtxt,$CD
1395 # returns: $message,$off,@dnptrs
1396 #
1397 2 ▶sub _ansrbak {
Subroutine _ansrbak: called CC=9 SCAR=25.3
1398 2 my($put,$id,$arc,$rip,$zone,$type,$ttl,$ans,$BLzone,$myip,$withtxt,$CD) = @_;
1399 2 ▶ my $haveA = ($type == T_A || $type == T_ANY) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$type == T_A() || $type == T_ANY() ? : 2 0 2
Condition33%1/3
$type == T_A() or $type == T_ANY()
l!l&&r!l&&!r
200
MC/DC0%0/2
$type == T_A() or $type == T_ANY()
$type == T_A() $type == T_ANY()
Truth table33%1/3
A or B
A= $type == T_A()B= $type == T_ANY()
ABresult
1X1
011
000
1400 2 ▶ my $haveT = (($type == T_ANY || $type == T_TXT) && $withtxt) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
($type == T_ANY() || $type == T_TXT()) && $withtxt ? : 0 2 2
Condition33%2/6
$type == T_ANY() || $type == T_TXT() and $withtxt
!ll&&!rl&&r
200
$type == T_ANY() or $type == T_TXT()
l!l&&r!l&&!r
002
MC/DC0%0/3
$type == T_ANY() || $type == T_TXT() and $withtxt
$type == T_ANY() $type == T_TXT() $withtxt
Truth table20%1/5
A or B and C
A= $type == T_ANY()B= $type == T_TXT()C= $withtxt
ABCresult
00X0
1X00
0100
1X11
0111
1401 2 ▶ $CD = $CD ? 0 : CD;
Branch: 1 branch
BranchTrueFalseTotal
$CD ? : 0 2 2
1402 2 my $nmsg;
1403 2 my $nans = $haveA + $haveT;
1404 2 my $noff = newhead(\$nmsg,
1405 $id,
1406 BITS_QUERY | QR,
1407 1,$nans,1,$arc,
1408 );
1409 2 ($noff,my @dnptrs) = $put->Question(\$nmsg,$noff, # 1 question
1410 $rip .'.'. $zone,$type,C_IN); # type is T_A or T_ANY or T_TXT
1411 2 ▶ if ($haveA) {
Branch: 1 branch
BranchTrueFalseTotal
if ($haveA) 2 0 2
1412 2 ($noff,@dnptrs) = $put->A(\$nmsg,$noff,\@dnptrs, # add 1 answer
1413 $rip .'.'. $zone,T_A,C_IN,$ttl,$ans);
1414 }
1415 2 ▶ if ($haveT) {
Branch: 1 branch
BranchTrueFalseTotal
if ($haveT) 0 2 2
1416 0 ($noff,@dnptrs) = $put->TXT(\$nmsg,$noff,\@dnptrs,
1417 $rip .'.'. $zone,T_TXT,C_IN,$ttl,$withtxt);
1418 }
1419 2 ($noff,@dnptrs) = $put->NS(\$nmsg,$noff,\@dnptrs, # 1 authority
1420 $zone,T_NS,C_IN,86400,$BLzone);
1421 2 ($noff,@dnptrs) = $put->A(\$nmsg,$noff,\@dnptrs, # 1 additional glue
1422 $BLzone,T_A,C_IN,86400,$myip); # show MYIP
1423 2 return($nmsg,$noff,@dnptrs)
1424 }
1425  
1426 =item * bl_lookup($put,$mp,$rtp,$sinaddr,$alarm,$rid,$id,$rip,$type,$zone,@blist);
1427  
1428 Generates a query message for the first DNSBL in the @blist array. Creates
1429 a thread entry for the response and subsequent queries should the first one fail.
1430  
1431 input: put,
1432 message pointer,
1433 remote thread pointer,
1434 sockinaddr,
1435 connection timeout,
1436 remote id or undef to create
1437 id of question,
1438 reverse IP address in text
1439 type of query received, (used in response)
1440 ORIGINAL zone (case preserved),
1441 array of remaining DNSBL's in sorted order
1442 returns: nothing, puts stuff in thread queue
1443  
1444 extra: if URBL processing is required,
1445 $remoteThreads{$rid}->{urbl}
1446 is set to the domain to look up
1447  
1448 =cut
1449  
1450 # This function returns an integer between 1 -> 65535 in a pseudo-random
1451 # repeatable order. Seeds with $$ by default, can be seeded with any integer;
1452 #
1453  
1454 20 my $id = $$;
1455  
1456 125 ▶sub uniqueID {
Subroutine uniqueID: called CC=4 SCAR=14.9
Pod undocumented
1457 125 ▶ $id = $_[0] ? ($_[0] % 65536) : $id;
Branch: 1 branch
BranchTrueFalseTotal
$_[0] ? : 68 57 125
1458 125 ▶ $id = 1 if $id < 1 || $id > 65534;
Branch: 1 branch
BranchTrueFalseTotal
if $id < 1 or $id > 65534 0 125 125
Condition33%1/3
$id < 1 or $id > 65534
l!l&&r!l&&!r
00125
MC/DC0%0/2
$id < 1 or $id > 65534
$id < 1 $id > 65534
Truth table33%1/3
A or B
A= $id < 1B= $id > 65534
ABresult
1X1
011
000
1459 125 $id++;
1460 }
1461  
1462 63 ▶sub bl_lookup {
Subroutine bl_lookup: called CC=6 SCAR=18.3
Pod documented
1463 63 my($put,$mp,$rtp,$sinaddr,$alarm,$rid,$id,$rip,$type,$zone,@blist) = @_;
1464 63 ▶ $rid = uniqueID unless $rid;
Branch: 1 branch
BranchTrueFalseTotal
unless $rid 57 6 63
1465 63 my $off = newhead($mp,
1466 $rid,
1467 BITS_QUERY | RD,
1468 1,0,0,0,
1469 );
1470 63 ▶ my $blist = ($blist[0] eq 'genericPTR')
Branch: 1 branch
BranchTrueFalseTotal
$blist[0] eq 'genericPTR' ? : 0 63 63
1471 ? 'in-addr.arpa'
1472 : $blist[0];
1473  
1474 63 ▶ my $Qtype = ($blist eq 'in-addr.arpa')
Branch: 1 branch
BranchTrueFalseTotal
$blist eq 'in-addr.arpa' ? : 1 62 63
1475 ? &T_PTR
1476 : &T_A;
1477  
1478 # send conditioned URBL request if that is what is needed
1479 63 ▶ if ($rtp->{$rid}->{urbl}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rtp->{$rid}{'urbl'}) { } 0 63 63
1480 0 $put->Question($mp,$off,$rtp->{$rid}->{urbl}.'.'. $blist,$Qtype,C_IN);
1481 } else {
1482 63 $put->Question($mp,$off,$rip .'.'. $blist,$Qtype,C_IN);
1483 }
1484 63 ▶ $rtp->{$rid} = {} unless exists $rtp->{$rid};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $rtp->{$rid} 0 63 63
1485 63 $rtp->{$rid}->{args} = [$sinaddr,$rip,$id,$type,$zone,@blist];
1486 63 $rtp->{$rid}->{expire} = time + $alarm;
1487 #print Tmp "$blist => ",Dumper($rtp);
1488 }
1489  
1490 =item * set_extension($pointer);
1491  
1492 This function sets a pointer to user defined extensions to
1493 Net::DNSBL::MultiDaemon.
1494  
1495 Pointer is of the form:
1496  
1497 $Extension ->{
1498 OPCODE => value,
1499 CLASS => subref->($Extension,internal args),
1500 NAME => subref->($Extension,internal args),
1501 TYPE => subref->($Extension,internal args),
1502 LOOKUP => subref->($Extension,internal args),
1503 ANSWER => subref->($Extension,internal args),
1504 NOTFOUND => subref->($Extension,internal args)
1505 };
1506  
1507 The pointer should be blessed into the package of the caller if the calling
1508 package needs to store persistant variables for its own instance. The subref
1509 will be called with the first argument of $Extension.
1510  
1511 Care should be taken to NOT instantiate a %remoteThreads in the CLASS, NAME,
1512 TYPE section unless it is know that it will be found and expired/deleted.
1513  
1514 Read the code if you wish to add an extension
1515  
1516 =back
1517  
1518 =cut
1519  
1520 0 ▶sub set_extension {
Subroutine set_extension: not called CC=1 SCAR=6.9
Pod documented
1521 0 $eXT = shift;
1522 }
1523  
1524 =head1 DEPENDENCIES
1525  
1526 Unix::Syslog
1527 Geo::IP::PurePerl [conditional for country codes]
1528 NetAddr::IP
1529 Net::DNS::Codes
1530 Net::DNS::ToolKit
1531  
1532 =head1 EXPORT_OK
1533  
1534 run
1535 bl_lookup
1536  
1537 =head1 EXPORT_TAGS :debug
1538  
1539 DEBUG is a set of semaphores for the 'run' function
1540  
1541 $D_CLRRUN = 0x1; # clear run flag and force unconditional return
1542 $D_SHRTHD = 0x2; # return short header message
1543 $D_TIMONLY = 0x4; # exit at end of timer section
1544 $D_QRESP = 0x8; # return query response message
1545 $D_NOTME = 0x10; # return received response not for me
1546 $D_ANSTOP = 0x20; # clear run OK flag if ANSWER present
1547 $D_VERBOSE = 0x40; # verbose debug statements to STDERR
1548  
1549 =head1 AUTHOR
1550  
1551 Michael Robinton, michael@bizsystems.com
1552  
1553 =head1 COPYRIGHT
1554  
1555 Copyright 2003 - 2014, Michael Robinton & BizSystems
1556 This program is free software; you can redistribute it and/or modify
1557 it under the terms as Perl itself or the GNU General Public License
1558 as published by the Free Software Foundation; either version 2 of
1559 the License, or (at your option) any later version.
1560  
1561 This program is distributed in the hope that it will be useful,
1562 but WITHOUT ANY WARRANTY; without even the implied warranty of
1563 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1564 GNU General Public License for more details.
1565  
1566 You should have received a copy of the GNU General Public License
1567 along with this program; if not, write to the Free Software
1568 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1569  
1570 =head1 SEE ALSO
1571  
1572 L<URBL::Prepare>, L<Geo::IP::PurePerl>, L<Net::DNSBL::Utilities>, L<Net::DNS::Codes>, L<Net::DNS::ToolKit>, L<Mail::SpamCannibal>
1573  
1574 =cut
1575  
1576 20 1;
↑ Summary blib/lib/Net/DNSBL/Utilities.pm »