Authentication/Handler/LocalIP.pm

filter: Statementstmt 98.0% 50 / 51 Branchbran 87.5% 7 / 8 Conditioncond 84.6% 11 / 13 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 12 / 12 Podpod 33.3% 2 / 6 totaltotal 89.5% 86 / 96 CC 11 SCAR 16.6
CC
11
Cov
94%
is_local_ip_address
10.1
connect_callback
2.0
BEGIN
1.0
CRAP 5.2
« Authentication/Handler/PTR.pm ↑ Summary Authentication/Handler/SenderID.pm »
1 package Mail::Milter::Authentication::Handler::LocalIP;
2 31 ▶use 5.20.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 31 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 31 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 31 ▶use Mail::Milter::Authentication::Pragmas;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 # ABSTRACT: Handler class for Local IP Connections
7 31 our $VERSION = '4.20261116'; # VERSION
8 31 ▶use base 'Mail::Milter::Authentication::Handler';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 31 ▶use Net::IP;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶sub default_config {
Subroutine default_config: called CC=1 SCAR=0.0
Pod undocumented
12 return {
13 1 'ignore_local_ip_list' => [],
14 };
15 }
16  
17 1 ▶sub grafana_rows {
Subroutine grafana_rows: called CC=1 SCAR=0.0
Pod undocumented
18 1 my ( $self ) = @_;
19 1 my @rows;
20 1 push @rows, $self->get_json( 'LocalIP_metrics' );
21 1 return \@rows;
22 }
23  
24 104 ▶sub is_local_ip_address {
Subroutine is_local_ip_address: called CC=10 SCAR=23.2
Pod documented
25 104 my ( $self, $ip ) = @_;
26 104 my $ip_address = $ip->short();
27 104 my $ip_type = $ip->iptype();
28 104 my $type_map = {
29 'PRIVATE' => 1,
30 'SHARED' => 1,
31 'LOOPBACK' => 1,
32 'LINK-LOCAL' => 1,
33 'RESERVED' => 1,
34 'TEST-NET' => 0,
35 '6TO4-RELAY' => 0,
36 'MULTICAST' => 0,
37 'BROADCAST' => 0,
38 'UNSPECIFIED' => 0,
39 'IPV4MAP' => 0,
40 'DISCARD' => 0,
41 'GLOBAL-UNICAST' => 0,
42 'TEREDO' => 0,
43 'BMWG' => 0,
44 'DOCUMENTATION' => 0,
45 'ORCHID' => 0,
46 '6TO4' => 0,
47 'UNIQUE-LOCAL-UNICAST' => 1,
48 'LINK-LOCAL-UNICAST' => 1,
49 };
50 104 my $config = $self->handler_config();
51 104 ▶ if ( exists $config->{'ignore_local_ip_list'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config->{"ignore_local_ip_list"}) 15 89 104
52 15 foreach my $ignore_ip ( @{ $config->{'ignore_local_ip_list'} } ) {
53 29 my $ignore_ip_obj = Net::IP->new($ignore_ip);
54 29 ▶ if ( !$ignore_ip_obj ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $ignore_ip_obj) { } 0 29 29
55 0 $self->log_error( 'LocalIP: Could not parse ignore IP '.$ignore_ip );
56 }
57 else {
58 29 ▶ my $is_overlap = $ip->overlaps($ignore_ip_obj) || 0;
Condition100%2/2
$ip->overlaps($ignore_ip_obj) || 0
l!l
227
MC/DC100%1/1
$ip->overlaps($ignore_ip_obj) || 0
$ip->overlaps($ignore_ip_obj)
Truth table100%2/2
A
A= $ip->overlaps($ignore_ip_obj)
Aresult
11
00
59 29 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($is_overlap == $Mail::Milter::Authentication::Handler::LocalIP::IP_A_IN_B_OVERLAP or $is_overlap == $Mail::Milter::Authentication::Handler::LocalIP::IP_B_IN_A_OVERLAP or $is_overlap == $Mail::Milter::Authentication::Handler::LocalIP::IP_PARTIAL_OVERLAP or $is_overlap == $Mail::Milter::Authentication::Handler::LocalIP::IP_IDENTICAL) 2 27 29
Condition77%7/9
$is_overlap == $Mail::Milter::Authentication::Handler::LocalIP::IP_A_IN_B_OVERLAP or $is_overlap == $Mail::Milter::Authentication::Handler::LocalIP::IP_B_IN_A_OVERLAP or $is_overlap == $Mail::Milter::Authentication::Handler::LocalIP::IP_PARTIAL_OVERLAP or $is_overlap == $Mail::Milter::Authentication::Handler::LocalIP::IP_IDENTICAL
l!l&&r!l&&!r
1127
$is_overlap == $Mail::Milter::Authentication::Handler::LocalIP::IP_A_IN_B_OVERLAP or $is_overlap == $Mail::Milter::Authentication::Handler::LocalIP::IP_B_IN_A_OVERLAP or $is_overlap == $Mail::Milter::Authentication::Handler::LocalIP::IP_PARTIAL_OVERLAP
l!l&&r!l&&!r
1028
$is_overlap == $Mail::Milter::Authentication::Handler::LocalIP::IP_A_IN_B_OVERLAP or $is_overlap == $Mail::Milter::Authentication::Handler::LocalIP::IP_B_IN_A_OVERLAP
l!l&&r!l&&!r
1028
MC/DC50%2/4
$is_overlap == $Mail::Milter::Authentication::Handler::LocalIP::IP_A_IN_B_OVERLAP or $is_overlap == $Mail::Milter::Authentication::Handler::LocalIP::IP_B_IN_A_OVERLAP or $is_overlap == $Mail::Milter::Authentication::Handler::LocalIP::IP_PARTIAL_OVERLAP or $is_overlap == $Mail::Milter::Authentication::Handler::LocalIP::IP_IDENTICAL
$is_overlap == $Mail::Milter::Authentication::Handler::LocalIP::IP_A_IN_B_OVERLAP $is_overlap == $Mail::Milter::Authentication::Handler::LocalIP::IP_B_IN_A_OVERLAP $is_overlap == $Mail::Milter::Authentication::Handler::LocalIP::IP_PARTIAL_OVERLAP $is_overlap == $Mail::Milter::Authentication::Handler::LocalIP::IP_IDENTICAL
Truth table60%3/5
A or B or C or D
A= $is_overlap == $Mail::Milter::Authentication::Handler::LocalIP::IP_A_IN_B_OVERLAPB= $is_overlap == $Mail::Milter::Authentication::Handler::LocalIP::IP_B_IN_A_OVERLAPC= $is_overlap == $Mail::Milter::Authentication::Handler::LocalIP::IP_PARTIAL_OVERLAPD= $is_overlap == $Mail::Milter::Authentication::Handler::LocalIP::IP_IDENTICAL
ABCDresult
1XXX1
01XX1
001X1
00011
00000
60 $is_overlap == $IP_A_IN_B_OVERLAP
61 || $is_overlap == $IP_B_IN_A_OVERLAP # Should never happen
62 || $is_overlap == $IP_PARTIAL_OVERLAP # Should never happen
63 || $is_overlap == $IP_IDENTICAL
64 )
65 {
66 2 return 0;
67 }
68 }
69 }
70 }
71 102 $self->dbgout( 'IPAddress', "Address $ip_address detected as type $ip_type", LOG_DEBUG );
72 102 ▶ return $type_map->{ $ip_type } || 0;
Condition100%2/2
$type_map->{$ip_type} || 0
l!l
1884
MC/DC100%1/1
$type_map->{$ip_type} || 0
$type_map->{$ip_type}
Truth table100%2/2
A
A= $type_map->{$ip_type}
Aresult
11
00
73 }
74  
75 48 ▶sub register_metrics {
Subroutine register_metrics: called CC=1 SCAR=0.0
Pod documented
76 return {
77 48 'localip_connect_total' => 'The number of connections from a local IP',
78 };
79 }
80  
81 104 ▶sub connect_callback {
Subroutine connect_callback: called CC=2 SCAR=6.9
Pod undocumented
82 104 my ( $self, $hostname, $ip ) = @_;
83 104 $self->{'is_local_ip_address'} = 0;
84 104 ▶ if ( $self->is_local_ip_address($ip) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_local_ip_address($ip)) 18 86 104
85 18 $self->dbgout( 'LocalIP', 'pass', LOG_DEBUG );
86 18 my $header = Mail::AuthenticationResults::Header::Entry->new()->set_key( 'x-local-ip' )->safe_set_value( 'pass' );
87 18 $self->add_c_auth_header( $header );
88 18 $self->{'is_local_ip_address'} = 1;
89 18 $self->metric_count( 'localip_connect_total' );
90 }
91 }
92  
93 126 ▶sub close_callback {
Subroutine close_callback: called CC=1 SCAR=0.0
Pod undocumented
94 126 my ( $self ) = @_;
95 126 delete $self->{'is_local_ip_address'};
96 }
97  
98 31 1;
99  
100 __END__
« Authentication/Handler/PTR.pm ↑ Summary Authentication/Handler/SenderID.pm »