line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DNS::Oterica::Network; |
2
|
|
|
|
|
|
|
# ABSTRACT: a network to which results are served |
3
|
|
|
|
|
|
|
$DNS::Oterica::Network::VERSION = '0.304'; |
4
|
2
|
|
|
2
|
|
936
|
use Moose; |
|
2
|
|
|
|
|
296507
|
|
|
2
|
|
|
|
|
10
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
10185
|
use Net::IP; |
|
2
|
|
|
|
|
62668
|
|
|
2
|
|
|
|
|
319
|
|
7
|
2
|
|
|
2
|
|
21
|
use Moose::Util::TypeConstraints; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
29
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# TODO: move these to a types library |
10
|
|
|
|
|
|
|
subtype 'DNS::Oterica::Type::Network' |
11
|
|
|
|
|
|
|
=> as Object |
12
|
|
|
|
|
|
|
=> where { $_->isa('Net::IP') }; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
coerce 'DNS::Oterica::Type::Network' |
15
|
|
|
|
|
|
|
=> from 'Str' |
16
|
|
|
|
|
|
|
=> via { Net::IP->new($_) || confess( Net::IP::Error() ) }; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
subtype 'DNS::Oterica::Type::Networks' |
19
|
|
|
|
|
|
|
=> as ArrayRef |
20
|
|
|
|
|
|
|
=> where { @$_ == grep {; ref $_ and $_->isa('Net::IP') } @$_ }; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
coerce 'DNS::Oterica::Type::Networks' |
23
|
|
|
|
|
|
|
=> from 'ArrayRef' |
24
|
|
|
|
|
|
|
=> via { [ map {; Net::IP->new($_) || confess( Net::IP::Error() ) } @$_ ] }; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
#pod =head1 OVERVIEW |
27
|
|
|
|
|
|
|
#pod |
28
|
|
|
|
|
|
|
#pod Networks are IP networks to which results are served, and can be used to |
29
|
|
|
|
|
|
|
#pod implement split horizons. |
30
|
|
|
|
|
|
|
#pod |
31
|
|
|
|
|
|
|
#pod Like other DNS::Oterica objects, they should be created through the hub. |
32
|
|
|
|
|
|
|
#pod |
33
|
|
|
|
|
|
|
#pod =attr name |
34
|
|
|
|
|
|
|
#pod |
35
|
|
|
|
|
|
|
#pod This is the network's unique name. |
36
|
|
|
|
|
|
|
#pod |
37
|
|
|
|
|
|
|
#pod =cut |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
has name => (is => 'ro', isa => 'Str', required => 1); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
#pod =attr subnets |
42
|
|
|
|
|
|
|
#pod |
43
|
|
|
|
|
|
|
#pod This is the C<Net::IP> ranges for the network at this network. |
44
|
|
|
|
|
|
|
#pod |
45
|
|
|
|
|
|
|
#pod =cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has subnets => ( |
48
|
|
|
|
|
|
|
isa => 'DNS::Oterica::Type::Networks', |
49
|
|
|
|
|
|
|
traits => [ 'Array' ], |
50
|
|
|
|
|
|
|
handles => { subnets => 'elements' }, |
51
|
|
|
|
|
|
|
required => 1, |
52
|
|
|
|
|
|
|
coerce => 1, |
53
|
|
|
|
|
|
|
); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub _class_prefixes { |
56
|
4
|
|
|
4
|
|
5119
|
my ($self, @ips) = @_; # $ip arg for testing |
57
|
|
|
|
|
|
|
|
58
|
4
|
50
|
|
|
|
10
|
@ips = $self->subnets unless @ips; |
59
|
|
|
|
|
|
|
|
60
|
4
|
|
|
|
|
5
|
my @prefixes; |
61
|
|
|
|
|
|
|
|
62
|
4
|
|
|
|
|
5
|
for my $ip (@ips) { |
63
|
4
|
|
|
|
|
10
|
my $pl = $ip->prefixlen; |
64
|
4
|
|
|
|
|
16
|
my $class = int( $pl / 8 ); |
65
|
4
|
|
|
|
|
10
|
my @quads = split /\./, $ip->ip; |
66
|
4
|
|
|
|
|
21
|
my @keep = splice @quads, 0, $class; |
67
|
4
|
|
|
|
|
7
|
my $fixed = join q{.}, @keep; |
68
|
4
|
|
|
|
|
7
|
my $bits = 8 - ($pl - $class * 8); |
69
|
|
|
|
|
|
|
|
70
|
4
|
100
|
|
|
|
8
|
if ($bits == 8) { |
71
|
2
|
|
|
|
|
32
|
push @prefixes, $fixed; |
72
|
|
|
|
|
|
|
} else { |
73
|
2
|
|
|
|
|
13
|
push @prefixes, map {; "$fixed.$_" } (0 .. (2**$bits - 1)); |
|
256
|
|
|
|
|
260
|
|
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
4
|
|
|
|
|
45
|
return @prefixes; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub as_data_lines { |
81
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
82
|
0
|
|
|
|
|
|
$self->hub->rec->location($self); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# Do we really want to keep this? |
86
|
|
|
|
|
|
|
has delegated => (is => 'ro', isa => 'Bool', required => 0, default => 0); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
has code => (is => 'ro', isa => 'Str', required => 1); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
with 'DNS::Oterica::Role::HasHub'; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
93
|
2
|
|
|
2
|
|
3763
|
no Moose; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
26
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=pod |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=encoding UTF-8 |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 NAME |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
DNS::Oterica::Network - a network to which results are served |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head1 VERSION |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
version 0.304 |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 OVERVIEW |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Networks are IP networks to which results are served, and can be used to |
113
|
|
|
|
|
|
|
implement split horizons. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
Like other DNS::Oterica objects, they should be created through the hub. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 name |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
This is the network's unique name. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 subnets |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
This is the C<Net::IP> ranges for the network at this network. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 AUTHOR |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Ricardo SIGNES <rjbs@cpan.org> |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
This software is copyright (c) 2016 by Ricardo SIGNES. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
136
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=cut |