line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::Milter::Authentication::Handler::LocalIP; |
2
|
30
|
|
|
30
|
|
17493
|
use 5.20.0; |
|
30
|
|
|
|
|
195
|
|
3
|
30
|
|
|
30
|
|
226
|
use strict; |
|
30
|
|
|
|
|
96
|
|
|
30
|
|
|
|
|
722
|
|
4
|
30
|
|
|
30
|
|
176
|
use warnings; |
|
30
|
|
|
|
|
85
|
|
|
30
|
|
|
|
|
1071
|
|
5
|
30
|
|
|
30
|
|
223
|
use Mail::Milter::Authentication::Pragmas; |
|
30
|
|
|
|
|
82
|
|
|
30
|
|
|
|
|
363
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Handler class for Local IP Connections |
7
|
|
|
|
|
|
|
our $VERSION = '3.20230629'; # VERSION |
8
|
30
|
|
|
30
|
|
7685
|
use base 'Mail::Milter::Authentication::Handler'; |
|
30
|
|
|
|
|
162
|
|
|
30
|
|
|
|
|
16967
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub default_config { |
11
|
1
|
|
|
1
|
0
|
1748
|
return {}; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub grafana_rows { |
15
|
1
|
|
|
1
|
0
|
4035
|
my ( $self ) = @_; |
16
|
1
|
|
|
|
|
4
|
my @rows; |
17
|
1
|
|
|
|
|
12
|
push @rows, $self->get_json( 'LocalIP_metrics' ); |
18
|
1
|
|
|
|
|
9
|
return \@rows; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub is_local_ip_address { |
22
|
80
|
|
|
80
|
1
|
365
|
my ( $self, $ip ) = @_; |
23
|
80
|
|
|
|
|
341
|
my $ip_address = $ip->ip(); |
24
|
80
|
|
|
|
|
898
|
my $ip_type = $ip->iptype(); |
25
|
80
|
|
|
|
|
22298
|
my $type_map = { |
26
|
|
|
|
|
|
|
'PRIVATE' => 1, |
27
|
|
|
|
|
|
|
'SHARED' => 1, |
28
|
|
|
|
|
|
|
'LOOPBACK' => 1, |
29
|
|
|
|
|
|
|
'LINK-LOCAL' => 1, |
30
|
|
|
|
|
|
|
'RESERVED' => 1, |
31
|
|
|
|
|
|
|
'TEST-NET' => 0, |
32
|
|
|
|
|
|
|
'6TO4-RELAY' => 0, |
33
|
|
|
|
|
|
|
'MULTICAST' => 0, |
34
|
|
|
|
|
|
|
'BROADCAST' => 0, |
35
|
|
|
|
|
|
|
'UNSPECIFIED' => 0, |
36
|
|
|
|
|
|
|
'IPV4MAP' => 0, |
37
|
|
|
|
|
|
|
'DISCARD' => 0, |
38
|
|
|
|
|
|
|
'GLOBAL-UNICAST' => 0, |
39
|
|
|
|
|
|
|
'TEREDO' => 0, |
40
|
|
|
|
|
|
|
'BMWG' => 0, |
41
|
|
|
|
|
|
|
'DOCUMENTATION' => 0, |
42
|
|
|
|
|
|
|
'ORCHID' => 0, |
43
|
|
|
|
|
|
|
'6TO4' => 0, |
44
|
|
|
|
|
|
|
'UNIQUE-LOCAL-UNICAST' => 1, |
45
|
|
|
|
|
|
|
'LINK-LOCAL-UNICAST' => 1, |
46
|
|
|
|
|
|
|
}; |
47
|
80
|
|
|
|
|
1060
|
$self->dbgout( 'IPAddress', "Address $ip_address detected as type $ip_type", LOG_DEBUG ); |
48
|
80
|
|
100
|
|
|
1524
|
return $type_map->{ $ip_type } || 0; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub register_metrics { |
52
|
|
|
|
|
|
|
return { |
53
|
29
|
|
|
29
|
1
|
303
|
'localip_connect_total' => 'The number of connections from a local IP', |
54
|
|
|
|
|
|
|
}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub connect_callback { |
58
|
80
|
|
|
80
|
0
|
414
|
my ( $self, $hostname, $ip ) = @_; |
59
|
80
|
|
|
|
|
466
|
$self->{'is_local_ip_address'} = 0; |
60
|
80
|
100
|
|
|
|
542
|
if ( $self->is_local_ip_address($ip) ) { |
61
|
17
|
|
|
|
|
94
|
$self->dbgout( 'LocalIP', 'pass', LOG_DEBUG ); |
62
|
17
|
|
|
|
|
428
|
my $header = Mail::AuthenticationResults::Header::Entry->new()->set_key( 'x-local-ip' )->safe_set_value( 'pass' ); |
63
|
17
|
|
|
|
|
3446
|
$self->add_c_auth_header( $header ); |
64
|
17
|
|
|
|
|
56
|
$self->{'is_local_ip_address'} = 1; |
65
|
17
|
|
|
|
|
125
|
$self->metric_count( 'localip_connect_total' ); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub close_callback { |
70
|
105
|
|
|
105
|
0
|
326
|
my ( $self ) = @_; |
71
|
105
|
|
|
|
|
462
|
delete $self->{'is_local_ip_address'}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=pod |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=encoding UTF-8 |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 NAME |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Mail::Milter::Authentication::Handler::LocalIP - Handler class for Local IP Connections |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 VERSION |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
version 3.20230629 |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 DESCRIPTION |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Detect a Local IP address and act accordingly. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 CONFIGURATION |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
No configuration options exist for this handler. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 AUTHOR |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Marc Bradshaw <marc@marcbradshaw.net> |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
This software is copyright (c) 2020 by Marc Bradshaw. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
107
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |