line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id: Routing.pm 45 2014-04-09 07:51:48Z gomor $ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
package Net::Frame::Layer::IPv6::Routing; |
5
|
2
|
|
|
2
|
|
1621
|
use strict; use warnings; |
|
2
|
|
|
2
|
|
4
|
|
|
2
|
|
|
|
|
81
|
|
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
101
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
11
|
use Net::Frame::Layer qw(:consts :subs); |
|
2
|
|
|
|
|
49
|
|
|
2
|
|
|
|
|
415
|
|
10
|
2
|
|
|
2
|
|
11
|
use Exporter; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
273
|
|
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
|
|
11
|
use Net::Frame::Layer::IPv6 qw(:consts); |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
2516
|
|
28
|
|
|
|
|
|
|
my $IPv6RoutingComputeSegmentsLeft = 1; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub new { |
31
|
|
|
|
|
|
|
shift->SUPER::new( |
32
|
1
|
|
|
1
|
1
|
19
|
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
|
223
|
my $self = shift; |
56
|
|
|
|
|
|
|
|
57
|
1
|
50
|
|
|
|
5
|
my $raw = $self->SUPER::pack('CCCCN', |
58
|
|
|
|
|
|
|
$self->nextHeader, $self->hdrExtLen, $self->routingType, |
59
|
|
|
|
|
|
|
$self->segmentsLeft, $self->reserved |
60
|
|
|
|
|
|
|
) or return; |
61
|
|
|
|
|
|
|
|
62
|
1
|
|
|
|
|
84
|
for ($self->addresses) { |
63
|
1
|
50
|
|
|
|
21
|
$raw .= $self->SUPER::pack('a16', |
64
|
|
|
|
|
|
|
inet6Aton($_) |
65
|
|
|
|
|
|
|
) or return; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
29
|
return $self->raw($raw); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub unpack { |
72
|
1
|
|
|
1
|
1
|
13
|
my $self = shift; |
73
|
|
|
|
|
|
|
|
74
|
1
|
50
|
|
|
|
4
|
my ($nextHeader, $hdrExtLen, $routingType, $segmentsLeft, $reserved, $rest) = |
75
|
|
|
|
|
|
|
$self->SUPER::unpack('CCCCN a*', $self->raw) |
76
|
|
|
|
|
|
|
or return; |
77
|
|
|
|
|
|
|
|
78
|
1
|
|
|
|
|
25
|
$self->nextHeader($nextHeader); |
79
|
1
|
|
|
|
|
11
|
$self->hdrExtLen($hdrExtLen); |
80
|
1
|
|
|
|
|
11
|
$self->routingType($routingType); |
81
|
1
|
|
|
|
|
10
|
$self->segmentsLeft($segmentsLeft); |
82
|
1
|
|
|
|
|
10
|
$self->reserved($reserved); |
83
|
|
|
|
|
|
|
|
84
|
1
|
|
|
|
|
7
|
my @addresses = (); |
85
|
1
|
|
|
|
|
5
|
for (1..$hdrExtLen/2) { |
86
|
1
|
50
|
|
|
|
8
|
my ($address) = |
87
|
|
|
|
|
|
|
$self->SUPER::unpack('a16', substr $rest, 16*($_-1)) |
88
|
|
|
|
|
|
|
or return; |
89
|
1
|
|
|
|
|
15
|
push @addresses, inet6Ntoa($address) |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
1
|
|
|
|
|
20
|
$self->addresses(\@addresses); |
93
|
|
|
|
|
|
|
|
94
|
1
|
|
|
|
|
19
|
$self->payload(substr $rest, 16*$hdrExtLen/2); |
95
|
|
|
|
|
|
|
|
96
|
1
|
|
|
|
|
21
|
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__ |