line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id: VRRP.pm 49 2009-05-31 13:15:34Z VinsWorldcom $ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
package Net::Frame::Layer::VRRP; |
5
|
2
|
|
|
2
|
|
19994
|
use strict; use warnings; |
|
2
|
|
|
2
|
|
5
|
|
|
2
|
|
|
|
|
62
|
|
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
121
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
2215
|
use Net::Frame::Layer qw(:consts :subs); |
|
2
|
|
|
|
|
1966028
|
|
|
2
|
|
|
|
|
625
|
|
10
|
2
|
|
|
2
|
|
19
|
use Exporter; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
231
|
|
11
|
|
|
|
|
|
|
our @ISA = qw(Net::Frame::Layer Exporter); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
14
|
|
|
|
|
|
|
consts => [qw( |
15
|
|
|
|
|
|
|
NF_VRRP_ALLVRRPRTRS |
16
|
|
|
|
|
|
|
NF_VRRP_ALLVRRPRTRS_MAC |
17
|
|
|
|
|
|
|
NF_VRRP_VERSION |
18
|
|
|
|
|
|
|
NF_VRRP_TYPE_ADVERT |
19
|
|
|
|
|
|
|
NF_VRRP_PRIORITY_OWNER |
20
|
|
|
|
|
|
|
NF_VRRP_PRIORITY_DEFAULT |
21
|
|
|
|
|
|
|
NF_VRRP_PRIORITY_NOMASTER |
22
|
|
|
|
|
|
|
NF_VRRP_AUTH_NO |
23
|
|
|
|
|
|
|
NF_VRRP_AUTH_TEXT |
24
|
|
|
|
|
|
|
NF_VRRP_AUTH_AH |
25
|
|
|
|
|
|
|
)], |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
our @EXPORT_OK = ( |
28
|
|
|
|
|
|
|
@{$EXPORT_TAGS{consts}}, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
2
|
|
11
|
use constant NF_VRRP_ALLVRRPRTRS => '224.0.0.18'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
132
|
|
32
|
2
|
|
|
2
|
|
11
|
use constant NF_VRRP_ALLVRRPRTRS_MAC => '01:00:5e:00:00:12'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
102
|
|
33
|
2
|
|
|
2
|
|
11
|
use constant NF_VRRP_VERSION => 2; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
102
|
|
34
|
2
|
|
|
2
|
|
10
|
use constant NF_VRRP_TYPE_ADVERT => 1; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
101
|
|
35
|
2
|
|
|
2
|
|
11
|
use constant NF_VRRP_PRIORITY_OWNER => 255; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
100
|
|
36
|
2
|
|
|
2
|
|
27
|
use constant NF_VRRP_PRIORITY_DEFAULT => 100; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
103
|
|
37
|
2
|
|
|
2
|
|
12
|
use constant NF_VRRP_PRIORITY_NOMASTER => 0; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
101
|
|
38
|
2
|
|
|
2
|
|
12
|
use constant NF_VRRP_AUTH_NO => 0; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
108
|
|
39
|
2
|
|
|
2
|
|
12
|
use constant NF_VRRP_AUTH_TEXT => 1; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
107
|
|
40
|
2
|
|
|
2
|
|
18
|
use constant NF_VRRP_AUTH_AH => 2; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
289
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
our @AS = qw( |
43
|
|
|
|
|
|
|
version |
44
|
|
|
|
|
|
|
type |
45
|
|
|
|
|
|
|
vrId |
46
|
|
|
|
|
|
|
priority |
47
|
|
|
|
|
|
|
countIp |
48
|
|
|
|
|
|
|
authType |
49
|
|
|
|
|
|
|
interval |
50
|
|
|
|
|
|
|
checksum |
51
|
|
|
|
|
|
|
authentication |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
our @AA = qw( |
54
|
|
|
|
|
|
|
ipAddresses |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
__PACKAGE__->cgBuildIndices; |
57
|
|
|
|
|
|
|
__PACKAGE__->cgBuildAccessorsScalar(\@AS); |
58
|
|
|
|
|
|
|
__PACKAGE__->cgBuildAccessorsArray(\@AA); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
#no strict 'vars'; |
61
|
|
|
|
|
|
|
|
62
|
2
|
|
|
2
|
|
1883
|
use Bit::Vector; |
|
2
|
|
|
|
|
3287
|
|
|
2
|
|
|
|
|
2160
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub new { |
65
|
|
|
|
|
|
|
shift->SUPER::new( |
66
|
1
|
|
|
1
|
1
|
37
|
version => NF_VRRP_VERSION, |
67
|
|
|
|
|
|
|
type => NF_VRRP_TYPE_ADVERT, |
68
|
|
|
|
|
|
|
vrId => 1, |
69
|
|
|
|
|
|
|
priority => NF_VRRP_PRIORITY_DEFAULT, |
70
|
|
|
|
|
|
|
countIp => 1, |
71
|
|
|
|
|
|
|
authType => NF_VRRP_AUTH_NO, |
72
|
|
|
|
|
|
|
interval => 1, |
73
|
|
|
|
|
|
|
checksum => 0, |
74
|
|
|
|
|
|
|
ipAddresses => ['127.0.0.1'], |
75
|
|
|
|
|
|
|
authentication => '', |
76
|
|
|
|
|
|
|
@_, |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub getLength { |
81
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
82
|
0
|
|
|
|
|
0
|
my $len = 16; |
83
|
0
|
|
|
|
|
0
|
$len += 4 for $self->ipAddresses; |
84
|
0
|
|
|
|
|
0
|
return $len; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub pack { |
88
|
1
|
|
|
1
|
1
|
434
|
my $self = shift; |
89
|
|
|
|
|
|
|
|
90
|
1
|
|
|
|
|
28
|
my $version = Bit::Vector->new_Dec(4, $self->version); |
91
|
1
|
|
|
|
|
58
|
my $type = Bit::Vector->new_Dec(4, $self->type); |
92
|
1
|
|
|
|
|
25
|
my $bvlist = $version->Concat_List($type); |
93
|
|
|
|
|
|
|
|
94
|
1
|
50
|
|
|
|
14
|
my $raw = $self->SUPER::pack('CCCCCCn', |
95
|
|
|
|
|
|
|
$bvlist->to_Dec, |
96
|
|
|
|
|
|
|
$self->vrId, |
97
|
|
|
|
|
|
|
$self->priority, |
98
|
|
|
|
|
|
|
$self->countIp, |
99
|
|
|
|
|
|
|
$self->authType, |
100
|
|
|
|
|
|
|
$self->interval, |
101
|
|
|
|
|
|
|
$self->checksum, |
102
|
|
|
|
|
|
|
) or return; |
103
|
|
|
|
|
|
|
|
104
|
1
|
|
|
|
|
103
|
for ($self->ipAddresses) { |
105
|
1
|
|
|
|
|
26
|
$raw .= inetAton($_); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
1
|
50
|
|
|
|
18
|
$raw .= $self->SUPER::pack('a8', |
109
|
|
|
|
|
|
|
$self->authentication, |
110
|
|
|
|
|
|
|
) or return; |
111
|
|
|
|
|
|
|
|
112
|
1
|
|
|
|
|
32
|
return $self->raw($raw); |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub unpack { |
116
|
1
|
|
|
1
|
1
|
24
|
my $self = shift; |
117
|
|
|
|
|
|
|
|
118
|
1
|
50
|
|
|
|
5
|
my ($bv, $vrId, $priority, $countIp, $authType, |
119
|
|
|
|
|
|
|
$interval, $checksum, $payload) = |
120
|
|
|
|
|
|
|
$self->SUPER::unpack('CCCCCCn a*', $self->raw) |
121
|
|
|
|
|
|
|
or return; |
122
|
|
|
|
|
|
|
|
123
|
1
|
|
|
|
|
44
|
my $bvlist = Bit::Vector->new_Dec(8, $bv); |
124
|
1
|
|
|
|
|
12
|
$self->version ($bvlist->Chunk_Read(4, 4)); |
125
|
1
|
|
|
|
|
17
|
$self->type ($bvlist->Chunk_Read(4, 0)); |
126
|
|
|
|
|
|
|
|
127
|
1
|
|
|
|
|
14
|
$self->vrId($vrId); |
128
|
1
|
|
|
|
|
12
|
$self->priority($priority); |
129
|
1
|
|
|
|
|
12
|
$self->countIp($countIp); |
130
|
1
|
|
|
|
|
12
|
$self->authType($authType); |
131
|
1
|
|
|
|
|
12
|
$self->interval($interval); |
132
|
1
|
|
|
|
|
13
|
$self->checksum($checksum); |
133
|
|
|
|
|
|
|
|
134
|
1
|
|
|
|
|
12
|
my @ipAddresses = (); |
135
|
1
|
|
|
|
|
5
|
for my $num (0..$countIp-1) { |
136
|
1
|
50
|
33
|
|
|
11
|
if (defined($payload) && (length($payload) >= 4)) { |
137
|
1
|
|
|
|
|
4
|
my $addr = unpack 'a4', $payload; |
138
|
1
|
|
|
|
|
6
|
push @ipAddresses, inetNtoa($addr); |
139
|
1
|
|
|
|
|
14
|
$payload = substr $payload, 4; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
} |
142
|
1
|
|
|
|
|
5
|
$self->ipAddresses(\@ipAddresses); |
143
|
|
|
|
|
|
|
|
144
|
1
|
|
|
|
|
14
|
my $authentication = unpack 'a8', $payload; |
145
|
1
|
|
|
|
|
3
|
$payload = substr $payload, 8; |
146
|
|
|
|
|
|
|
|
147
|
1
|
|
|
|
|
4
|
$self->authentication($authentication); |
148
|
|
|
|
|
|
|
|
149
|
1
|
|
|
|
|
18
|
$self->payload($payload); |
150
|
|
|
|
|
|
|
|
151
|
1
|
|
|
|
|
14
|
return $self; |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub computeChecksums { |
155
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
156
|
0
|
|
|
|
|
0
|
my ($layers) = @_; |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
0
|
my $version = Bit::Vector->new_Dec(4, $self->version); |
159
|
0
|
|
|
|
|
0
|
my $type = Bit::Vector->new_Dec(4, $self->type); |
160
|
0
|
|
|
|
|
0
|
my $bvlist = $version->Concat_List($type); |
161
|
|
|
|
|
|
|
|
162
|
0
|
0
|
|
|
|
0
|
my $phpkt = $self->SUPER::pack('CCCCCCn', |
163
|
|
|
|
|
|
|
$bvlist->to_Dec, |
164
|
|
|
|
|
|
|
$self->vrId, |
165
|
|
|
|
|
|
|
$self->priority, |
166
|
|
|
|
|
|
|
$self->countIp, |
167
|
|
|
|
|
|
|
$self->authType, |
168
|
|
|
|
|
|
|
$self->interval, |
169
|
|
|
|
|
|
|
0, |
170
|
|
|
|
|
|
|
) or return; |
171
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
0
|
for ($self->ipAddresses) { |
173
|
0
|
|
|
|
|
0
|
$phpkt .= inetAton($_); |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
0
|
0
|
|
|
|
0
|
$phpkt .= $self->SUPER::pack('a8', |
177
|
|
|
|
|
|
|
$self->authentication, |
178
|
|
|
|
|
|
|
) or return; |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
0
|
my $start = 0; |
181
|
0
|
|
|
|
|
0
|
my $last = $self; |
182
|
0
|
|
|
|
|
0
|
my $payload = ''; |
183
|
0
|
|
|
|
|
0
|
for my $l (@$layers) { |
184
|
0
|
|
|
|
|
0
|
$last = $l; |
185
|
0
|
0
|
|
|
|
0
|
if (! $start) { |
186
|
0
|
0
|
|
|
|
0
|
$start++ if $l->layer eq 'VRRP'; |
187
|
0
|
|
|
|
|
0
|
next; |
188
|
|
|
|
|
|
|
} |
189
|
0
|
|
|
|
|
0
|
$payload .= $l->pack; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
0
|
0
|
0
|
|
|
0
|
if (defined($last->payload) && length($last->payload)) { |
193
|
0
|
|
|
|
|
0
|
$payload .= $last->payload; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
0
|
0
|
|
|
|
0
|
if (length($payload)) { |
197
|
0
|
0
|
|
|
|
0
|
$phpkt .= $self->SUPER::pack('a*', $payload) |
198
|
|
|
|
|
|
|
or return; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
0
|
|
|
|
|
0
|
$self->checksum(inetChecksum($phpkt)); |
202
|
|
|
|
|
|
|
|
203
|
0
|
|
|
|
|
0
|
return 1; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
sub encapsulate { |
207
|
1
|
|
|
1
|
1
|
6
|
my $self = shift; |
208
|
|
|
|
|
|
|
|
209
|
1
|
50
|
|
|
|
8
|
return $self->nextLayer if $self->nextLayer; |
210
|
|
|
|
|
|
|
|
211
|
1
|
|
|
|
|
23
|
NF_LAYER_NONE; |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
sub computeLengths { |
215
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
# Calculate countIp from ipAddresses array items |
218
|
0
|
0
|
0
|
|
|
0
|
if (scalar($self->ipAddresses) && ($self->countIp == 0)) { |
219
|
0
|
|
|
|
|
0
|
$self->countIp(scalar($self->ipAddresses)) |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
0
|
|
|
|
|
0
|
return 1; |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
sub print { |
226
|
1
|
|
|
1
|
1
|
6
|
my $self = shift; |
227
|
|
|
|
|
|
|
|
228
|
1
|
|
|
|
|
8
|
my $l = $self->layer; |
229
|
1
|
|
|
|
|
20
|
my $buf = sprintf |
230
|
|
|
|
|
|
|
"$l: version:%d type:%d vrId:%d priority:%d\n". |
231
|
|
|
|
|
|
|
"$l: countIp:%d authType:%d interval:%d checksum:0x%04x", |
232
|
|
|
|
|
|
|
$self->version, $self->type, $self->vrId, $self->priority, |
233
|
|
|
|
|
|
|
$self->countIp, $self->authType, $self->interval, $self->checksum; |
234
|
|
|
|
|
|
|
|
235
|
1
|
|
|
|
|
74
|
for ($self->ipAddresses) { |
236
|
1
|
|
|
|
|
18
|
$buf .= sprintf |
237
|
|
|
|
|
|
|
"\n$l: ipAddresses:%s", |
238
|
|
|
|
|
|
|
$_ |
239
|
|
|
|
|
|
|
} |
240
|
|
|
|
|
|
|
|
241
|
1
|
|
|
|
|
6
|
$buf .= sprintf |
242
|
|
|
|
|
|
|
"\n$l: authentication:%s", |
243
|
|
|
|
|
|
|
$self->authentication; |
244
|
|
|
|
|
|
|
|
245
|
1
|
|
|
|
|
35
|
return $buf; |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
1; |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
__END__ |