line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id: Routing.pm 47 2015-01-20 18:20:28Z gomor $ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
package Net::Frame::Layer::IPv6::Routing; |
5
|
2
|
|
|
2
|
|
844
|
use strict; use warnings; |
|
2
|
|
|
2
|
|
4
|
|
|
2
|
|
|
|
|
63
|
|
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
74
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.07'; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
7
|
use Net::Frame::Layer qw(:consts :subs); |
|
2
|
|
|
|
|
32
|
|
|
2
|
|
|
|
|
334
|
|
10
|
2
|
|
|
2
|
|
9
|
use Exporter; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
188
|
|
11
|
|
|
|
|
|
|
our @ISA = qw(Net::Frame::Layer Exporter); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @AS = qw( |
14
|
|
|
|
|
|
|
nextHeader |
15
|
|
|
|
|
|
|
hdrExtLen |
16
|
|
|
|
|
|
|
routingType |
17
|
|
|
|
|
|
|
segmentsLeft |
18
|
|
|
|
|
|
|
reserved |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
our @AA = qw( |
21
|
|
|
|
|
|
|
addresses |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
__PACKAGE__->cgBuildIndices; |
24
|
|
|
|
|
|
|
__PACKAGE__->cgBuildAccessorsScalar(\@AS); |
25
|
|
|
|
|
|
|
__PACKAGE__->cgBuildAccessorsArray(\@AA); |
26
|
|
|
|
|
|
|
|
27
|
2
|
|
|
2
|
|
9
|
use Net::Frame::Layer::IPv6 qw(:consts); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
1589
|
|
28
|
|
|
|
|
|
|
my $IPv6RoutingComputeSegmentsLeft = 1; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub new { |
31
|
|
|
|
|
|
|
shift->SUPER::new( |
32
|
1
|
|
|
1
|
1
|
16
|
nextHeader => NF_IPv6_PROTOCOL_TCP, |
33
|
|
|
|
|
|
|
hdrExtLen => 2, |
34
|
|
|
|
|
|
|
routingType => 0, |
35
|
|
|
|
|
|
|
segmentsLeft => 1, |
36
|
|
|
|
|
|
|
reserved => 0, |
37
|
|
|
|
|
|
|
addresses => ['::1'], |
38
|
|
|
|
|
|
|
@_, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _getAddressesLength { |
43
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
44
|
0
|
|
|
|
|
0
|
my $len = 0; |
45
|
0
|
|
|
|
|
0
|
$len += 16 for $self->addresses; |
46
|
0
|
|
|
|
|
0
|
return $len; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub getLength { |
50
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
51
|
0
|
|
|
|
|
0
|
return 8 + $self->_getAddressesLength; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub pack { |
55
|
1
|
|
|
1
|
1
|
166
|
my $self = shift; |
56
|
|
|
|
|
|
|
|
57
|
1
|
50
|
|
|
|
3
|
my $raw = $self->SUPER::pack('CCCCN', |
58
|
|
|
|
|
|
|
$self->nextHeader, $self->hdrExtLen, $self->routingType, |
59
|
|
|
|
|
|
|
$self->segmentsLeft, $self->reserved |
60
|
|
|
|
|
|
|
) or return; |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
50
|
for ($self->addresses) { |
63
|
1
|
50
|
|
|
|
18
|
$raw .= $self->SUPER::pack('a16', |
64
|
|
|
|
|
|
|
inet6Aton($_) |
65
|
|
|
|
|
|
|
) or return; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
23
|
return $self->raw($raw); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub unpack { |
72
|
1
|
|
|
1
|
1
|
9
|
my $self = shift; |
73
|
|
|
|
|
|
|
|
74
|
1
|
50
|
|
|
|
3
|
my ($nextHeader, $hdrExtLen, $routingType, $segmentsLeft, $reserved, $rest) = |
75
|
|
|
|
|
|
|
$self->SUPER::unpack('CCCCN a*', $self->raw) |
76
|
|
|
|
|
|
|
or return; |
77
|
|
|
|
|
|
|
|
78
|
1
|
|
|
|
|
19
|
$self->nextHeader($nextHeader); |
79
|
1
|
|
|
|
|
8
|
$self->hdrExtLen($hdrExtLen); |
80
|
1
|
|
|
|
|
6
|
$self->routingType($routingType); |
81
|
1
|
|
|
|
|
7
|
$self->segmentsLeft($segmentsLeft); |
82
|
1
|
|
|
|
|
7
|
$self->reserved($reserved); |
83
|
|
|
|
|
|
|
|
84
|
1
|
|
|
|
|
5
|
my @addresses = (); |
85
|
1
|
|
|
|
|
4
|
for (1..$hdrExtLen/2) { |
86
|
1
|
50
|
|
|
|
6
|
my ($address) = |
87
|
|
|
|
|
|
|
$self->SUPER::unpack('a16', substr $rest, 16*($_-1)) |
88
|
|
|
|
|
|
|
or return; |
89
|
1
|
|
|
|
|
12
|
push @addresses, inet6Ntoa($address) |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
1
|
|
|
|
|
13
|
$self->addresses(\@addresses); |
93
|
|
|
|
|
|
|
|
94
|
1
|
|
|
|
|
14
|
$self->payload(substr $rest, 16*$hdrExtLen/2); |
95
|
|
|
|
|
|
|
|
96
|
1
|
|
|
|
|
15
|
return $self; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub computeSegmentsLeft { |
100
|
0
|
|
|
0
|
1
|
|
my ($self, $arg) = @_; |
101
|
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
|
if (defined($arg)) { |
103
|
0
|
0
|
0
|
|
|
|
if (($arg =~ /^\d$/) && ($arg == 0)) { |
104
|
0
|
|
|
|
|
|
$IPv6RoutingComputeSegmentsLeft = 0 |
105
|
|
|
|
|
|
|
} else { |
106
|
0
|
|
|
|
|
|
$IPv6RoutingComputeSegmentsLeft = 1 |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
0
|
|
|
|
|
|
return $IPv6RoutingComputeSegmentsLeft |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub computeLengths { |
113
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
my $hdrExtLen = 0; |
116
|
0
|
|
|
|
|
|
$hdrExtLen += 2 for $self->addresses; |
117
|
0
|
|
|
|
|
|
$self->hdrExtLen($hdrExtLen); |
118
|
|
|
|
|
|
|
|
119
|
0
|
0
|
|
|
|
|
if ($IPv6RoutingComputeSegmentsLeft) { |
120
|
0
|
|
|
|
|
|
my $segmentsLeft = 0; |
121
|
0
|
|
|
|
|
|
$segmentsLeft += 1 for $self->addresses; |
122
|
0
|
|
|
|
|
|
$self->segmentsLeft($segmentsLeft); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
return 1; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub encapsulate { |
129
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
130
|
|
|
|
|
|
|
|
131
|
0
|
0
|
|
|
|
|
return $self->nextLayer if $self->nextLayer; |
132
|
|
|
|
|
|
|
|
133
|
0
|
0
|
|
|
|
|
if ($self->payload) { |
134
|
0
|
|
|
|
|
|
my $next = $self->nextHeader; |
135
|
0
|
|
|
|
|
|
return Net::Frame::Layer::IPv6->new(nextHeader=>$self->nextHeader)->encapsulate |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
return NF_LAYER_NONE; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub print { |
142
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
my $l = $self->layer; |
145
|
0
|
|
|
|
|
|
my $buf = sprintf |
146
|
|
|
|
|
|
|
"$l: nextHeader:0x%02x hdrExtLen:%d routingType:%d\n". |
147
|
|
|
|
|
|
|
"$l: segmentsLeft:%d reserved:%d", |
148
|
|
|
|
|
|
|
$self->nextHeader, $self->hdrExtLen, $self->routingType, |
149
|
|
|
|
|
|
|
$self->segmentsLeft, $self->reserved; |
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
for ($self->addresses) { |
152
|
0
|
|
|
|
|
|
$buf .= sprintf |
153
|
|
|
|
|
|
|
"\n$l: address:%s", |
154
|
|
|
|
|
|
|
$_ |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
0
|
|
|
|
|
|
return $buf; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
1; |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
__END__ |