line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::Milter::Authentication::Handler::LocalIP; |
2
|
27
|
|
|
27
|
|
14737
|
use strict; |
|
27
|
|
|
|
|
78
|
|
|
27
|
|
|
|
|
829
|
|
3
|
27
|
|
|
27
|
|
156
|
use warnings; |
|
27
|
|
|
|
|
60
|
|
|
27
|
|
|
|
|
790
|
|
4
|
27
|
|
|
27
|
|
142
|
use base 'Mail::Milter::Authentication::Handler'; |
|
27
|
|
|
|
|
66
|
|
|
27
|
|
|
|
|
3246
|
|
5
|
|
|
|
|
|
|
our $VERSION = '20191206'; # VERSION |
6
|
|
|
|
|
|
|
|
7
|
27
|
|
|
27
|
|
195
|
use Sys::Syslog qw{:standard :macros}; |
|
27
|
|
|
|
|
98
|
|
|
27
|
|
|
|
|
9024
|
|
8
|
27
|
|
|
27
|
|
200
|
use Mail::AuthenticationResults::Header::Entry; |
|
27
|
|
|
|
|
67
|
|
|
27
|
|
|
|
|
710
|
|
9
|
27
|
|
|
27
|
|
143
|
use Mail::AuthenticationResults::Header::SubEntry; |
|
27
|
|
|
|
|
65
|
|
|
27
|
|
|
|
|
626
|
|
10
|
27
|
|
|
27
|
|
141
|
use Mail::AuthenticationResults::Header::Comment; |
|
27
|
|
|
|
|
75
|
|
|
27
|
|
|
|
|
9805
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub default_config { |
13
|
1
|
|
|
1
|
0
|
1262
|
return {}; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub grafana_rows { |
17
|
1
|
|
|
1
|
0
|
3302
|
my ( $self ) = @_; |
18
|
1
|
|
|
|
|
2
|
my @rows; |
19
|
1
|
|
|
|
|
8
|
push @rows, $self->get_json( 'LocalIP_metrics' ); |
20
|
1
|
|
|
|
|
4
|
return \@rows; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub is_local_ip_address { |
24
|
80
|
|
|
80
|
1
|
296
|
my ( $self, $ip ) = @_; |
25
|
80
|
|
|
|
|
383
|
my $ip_address = $ip->ip(); |
26
|
80
|
|
|
|
|
823
|
my $ip_type = $ip->iptype(); |
27
|
80
|
|
|
|
|
18522
|
my $type_map = { |
28
|
|
|
|
|
|
|
'PRIVATE' => 1, |
29
|
|
|
|
|
|
|
'SHARED' => 1, |
30
|
|
|
|
|
|
|
'LOOPBACK' => 1, |
31
|
|
|
|
|
|
|
'LINK-LOCAL' => 1, |
32
|
|
|
|
|
|
|
'RESERVED' => 1, |
33
|
|
|
|
|
|
|
'TEST-NET' => 0, |
34
|
|
|
|
|
|
|
'6TO4-RELAY' => 0, |
35
|
|
|
|
|
|
|
'MULTICAST' => 0, |
36
|
|
|
|
|
|
|
'BROADCAST' => 0, |
37
|
|
|
|
|
|
|
'UNSPECIFIED' => 0, |
38
|
|
|
|
|
|
|
'IPV4MAP' => 0, |
39
|
|
|
|
|
|
|
'DISCARD' => 0, |
40
|
|
|
|
|
|
|
'GLOBAL-UNICAST' => 0, |
41
|
|
|
|
|
|
|
'TEREDO' => 0, |
42
|
|
|
|
|
|
|
'BMWG' => 0, |
43
|
|
|
|
|
|
|
'DOCUMENTATION' => 0, |
44
|
|
|
|
|
|
|
'ORCHID' => 0, |
45
|
|
|
|
|
|
|
'6TO4' => 0, |
46
|
|
|
|
|
|
|
'UNIQUE-LOCAL-UNICAST' => 1, |
47
|
|
|
|
|
|
|
'LINK-LOCAL-UNICAST' => 1, |
48
|
|
|
|
|
|
|
}; |
49
|
80
|
|
|
|
|
1432
|
$self->dbgout( 'IPAddress', "Address $ip_address detected as type $ip_type", LOG_DEBUG ); |
50
|
80
|
|
100
|
|
|
966
|
return $type_map->{ $ip_type } || 0; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub register_metrics { |
54
|
|
|
|
|
|
|
return { |
55
|
26
|
|
|
26
|
1
|
169
|
'localip_connect_total' => 'The number of connections from a local IP', |
56
|
|
|
|
|
|
|
}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub connect_callback { |
60
|
80
|
|
|
80
|
0
|
332
|
my ( $self, $hostname, $ip ) = @_; |
61
|
80
|
|
|
|
|
416
|
$self->{'is_local_ip_address'} = 0; |
62
|
80
|
100
|
|
|
|
485
|
if ( $self->is_local_ip_address($ip) ) { |
63
|
17
|
|
|
|
|
86
|
$self->dbgout( 'LocalIP', 'pass', LOG_DEBUG ); |
64
|
17
|
|
|
|
|
297
|
my $header = Mail::AuthenticationResults::Header::Entry->new()->set_key( 'x-local-ip' )->safe_set_value( 'pass' ); |
65
|
17
|
|
|
|
|
1674
|
$self->add_c_auth_header( $header ); |
66
|
17
|
|
|
|
|
37
|
$self->{'is_local_ip_address'} = 1; |
67
|
17
|
|
|
|
|
276
|
$self->metric_count( 'localip_connect_total' ); |
68
|
|
|
|
|
|
|
} |
69
|
80
|
|
|
|
|
285
|
return; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub close_callback { |
73
|
105
|
|
|
105
|
0
|
313
|
my ( $self ) = @_; |
74
|
105
|
|
|
|
|
464
|
delete $self->{'is_local_ip_address'}; |
75
|
105
|
|
|
|
|
292
|
return; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=pod |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=encoding UTF-8 |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 NAME |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Mail::Milter::Authentication::Handler::LocalIP |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 VERSION |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
version 20191206 |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 DESCRIPTION |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Detect a Local IP address and act accordingly. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 CONFIGURATION |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
No configuration options exist for this handler. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 AUTHOR |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Marc Bradshaw <marc@marcbradshaw.net> |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This software is copyright (c) 2018 by Marc Bradshaw. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
111
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |