line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::Milter::Authentication::Handler::LocalIP; |
2
|
30
|
|
|
30
|
|
16550
|
use 5.20.0; |
|
30
|
|
|
|
|
160
|
|
3
|
30
|
|
|
30
|
|
243
|
use strict; |
|
30
|
|
|
|
|
112
|
|
|
30
|
|
|
|
|
964
|
|
4
|
30
|
|
|
30
|
|
199
|
use warnings; |
|
30
|
|
|
|
|
116
|
|
|
30
|
|
|
|
|
1049
|
|
5
|
30
|
|
|
30
|
|
264
|
use Mail::Milter::Authentication::Pragmas; |
|
30
|
|
|
|
|
68
|
|
|
30
|
|
|
|
|
250
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Handler class for Local IP Connections |
7
|
|
|
|
|
|
|
our $VERSION = '3.20230911'; # VERSION |
8
|
30
|
|
|
30
|
|
7230
|
use base 'Mail::Milter::Authentication::Handler'; |
|
30
|
|
|
|
|
105
|
|
|
30
|
|
|
|
|
15918
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub default_config { |
11
|
1
|
|
|
1
|
0
|
1626
|
return {}; |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub grafana_rows { |
15
|
1
|
|
|
1
|
0
|
4332
|
my ( $self ) = @_; |
16
|
1
|
|
|
|
|
2
|
my @rows; |
17
|
1
|
|
|
|
|
14
|
push @rows, $self->get_json( 'LocalIP_metrics' ); |
18
|
1
|
|
|
|
|
4
|
return \@rows; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub is_local_ip_address { |
22
|
80
|
|
|
80
|
1
|
294
|
my ( $self, $ip ) = @_; |
23
|
80
|
|
|
|
|
415
|
my $ip_address = $ip->ip(); |
24
|
80
|
|
|
|
|
852
|
my $ip_type = $ip->iptype(); |
25
|
80
|
|
|
|
|
21456
|
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
|
|
|
|
|
861
|
$self->dbgout( 'IPAddress', "Address $ip_address detected as type $ip_type", LOG_DEBUG ); |
48
|
80
|
|
100
|
|
|
2626
|
return $type_map->{ $ip_type } || 0; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub register_metrics { |
52
|
|
|
|
|
|
|
return { |
53
|
29
|
|
|
29
|
1
|
232
|
'localip_connect_total' => 'The number of connections from a local IP', |
54
|
|
|
|
|
|
|
}; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub connect_callback { |
58
|
80
|
|
|
80
|
0
|
442
|
my ( $self, $hostname, $ip ) = @_; |
59
|
80
|
|
|
|
|
434
|
$self->{'is_local_ip_address'} = 0; |
60
|
80
|
100
|
|
|
|
435
|
if ( $self->is_local_ip_address($ip) ) { |
61
|
17
|
|
|
|
|
104
|
$self->dbgout( 'LocalIP', 'pass', LOG_DEBUG ); |
62
|
17
|
|
|
|
|
439
|
my $header = Mail::AuthenticationResults::Header::Entry->new()->set_key( 'x-local-ip' )->safe_set_value( 'pass' ); |
63
|
17
|
|
|
|
|
2044
|
$self->add_c_auth_header( $header ); |
64
|
17
|
|
|
|
|
67
|
$self->{'is_local_ip_address'} = 1; |
65
|
17
|
|
|
|
|
111
|
$self->metric_count( 'localip_connect_total' ); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub close_callback { |
70
|
105
|
|
|
105
|
0
|
340
|
my ( $self ) = @_; |
71
|
105
|
|
|
|
|
425
|
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.20230911 |
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 |