line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id: ETH.pm,v ce68fbcc7f6d 2019/05/23 05:58:40 gomor $ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
package Net::Frame::Layer::ETH; |
5
|
2
|
|
|
2
|
|
5673
|
use strict; |
|
2
|
|
|
|
|
29
|
|
|
2
|
|
|
|
|
101
|
|
6
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
61
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
407
|
use Net::Frame::Layer qw(:consts :subs); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
550
|
|
9
|
|
|
|
|
|
|
require Exporter; |
10
|
|
|
|
|
|
|
our @ISA = qw(Net::Frame::Layer Exporter); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( |
13
|
|
|
|
|
|
|
consts => [qw( |
14
|
|
|
|
|
|
|
NF_ETH_HDR_LEN |
15
|
|
|
|
|
|
|
NF_ETH_ADDR_BROADCAST |
16
|
|
|
|
|
|
|
NF_ETH_TYPE_IPv4 |
17
|
|
|
|
|
|
|
NF_ETH_TYPE_X25 |
18
|
|
|
|
|
|
|
NF_ETH_TYPE_ARP |
19
|
|
|
|
|
|
|
NF_ETH_TYPE_CGMP |
20
|
|
|
|
|
|
|
NF_ETH_TYPE_80211 |
21
|
|
|
|
|
|
|
NF_ETH_TYPE_PPPIPCP |
22
|
|
|
|
|
|
|
NF_ETH_TYPE_RARP |
23
|
|
|
|
|
|
|
NF_ETH_TYPE_DDP |
24
|
|
|
|
|
|
|
NF_ETH_TYPE_AARP |
25
|
|
|
|
|
|
|
NF_ETH_TYPE_PPPCCP |
26
|
|
|
|
|
|
|
NF_ETH_TYPE_WCP |
27
|
|
|
|
|
|
|
NF_ETH_TYPE_8021Q |
28
|
|
|
|
|
|
|
NF_ETH_TYPE_IPX |
29
|
|
|
|
|
|
|
NF_ETH_TYPE_STP |
30
|
|
|
|
|
|
|
NF_ETH_TYPE_IPv6 |
31
|
|
|
|
|
|
|
NF_ETH_TYPE_WLCCP |
32
|
|
|
|
|
|
|
NF_ETH_TYPE_MPLS |
33
|
|
|
|
|
|
|
NF_ETH_TYPE_PPPoED |
34
|
|
|
|
|
|
|
NF_ETH_TYPE_PPPoES |
35
|
|
|
|
|
|
|
NF_ETH_TYPE_8021X |
36
|
|
|
|
|
|
|
NF_ETH_TYPE_AoE |
37
|
|
|
|
|
|
|
NF_ETH_TYPE_80211I |
38
|
|
|
|
|
|
|
NF_ETH_TYPE_LLDP |
39
|
|
|
|
|
|
|
NF_ETH_TYPE_LLTD |
40
|
|
|
|
|
|
|
NF_ETH_TYPE_LOOP |
41
|
|
|
|
|
|
|
NF_ETH_TYPE_VLAN |
42
|
|
|
|
|
|
|
NF_ETH_TYPE_PPPPAP |
43
|
|
|
|
|
|
|
NF_ETH_TYPE_PPPCHAP |
44
|
|
|
|
|
|
|
)], |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
our @EXPORT_OK = ( |
47
|
|
|
|
|
|
|
@{$EXPORT_TAGS{consts}}, |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
2
|
|
|
2
|
|
16
|
use constant NF_ETH_HDR_LEN => 14; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
118
|
|
51
|
2
|
|
|
2
|
|
12
|
use constant NF_ETH_ADDR_BROADCAST => 'ff:ff:ff:ff:ff:ff'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
113
|
|
52
|
2
|
|
|
2
|
|
11
|
use constant NF_ETH_TYPE_IPv4 => 0x0800; |
|
2
|
|
|
|
|
16
|
|
|
2
|
|
|
|
|
82
|
|
53
|
2
|
|
|
2
|
|
9
|
use constant NF_ETH_TYPE_X25 => 0x0805; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
99
|
|
54
|
2
|
|
|
2
|
|
10
|
use constant NF_ETH_TYPE_ARP => 0x0806; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
188
|
|
55
|
2
|
|
|
2
|
|
10
|
use constant NF_ETH_TYPE_CGMP => 0x2001; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
82
|
|
56
|
2
|
|
|
2
|
|
9
|
use constant NF_ETH_TYPE_80211 => 0x2452; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
71
|
|
57
|
2
|
|
|
2
|
|
10
|
use constant NF_ETH_TYPE_PPPIPCP => 0x8021; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
67
|
|
58
|
2
|
|
|
2
|
|
8
|
use constant NF_ETH_TYPE_RARP => 0x8035; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
82
|
|
59
|
2
|
|
|
2
|
|
10
|
use constant NF_ETH_TYPE_DDP => 0x809b; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
74
|
|
60
|
2
|
|
|
2
|
|
10
|
use constant NF_ETH_TYPE_AARP => 0x80f3; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
81
|
|
61
|
2
|
|
|
2
|
|
9
|
use constant NF_ETH_TYPE_PPPCCP => 0x80fd; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
116
|
|
62
|
2
|
|
|
2
|
|
12
|
use constant NF_ETH_TYPE_WCP => 0x80ff; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
72
|
|
63
|
2
|
|
|
2
|
|
9
|
use constant NF_ETH_TYPE_8021Q => 0x8100; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
89
|
|
64
|
2
|
|
|
2
|
|
12
|
use constant NF_ETH_TYPE_IPX => 0x8137; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
77
|
|
65
|
2
|
|
|
2
|
|
9
|
use constant NF_ETH_TYPE_STP => 0x8181; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
82
|
|
66
|
2
|
|
|
2
|
|
11
|
use constant NF_ETH_TYPE_IPv6 => 0x86dd; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
76
|
|
67
|
2
|
|
|
2
|
|
8
|
use constant NF_ETH_TYPE_WLCCP => 0x872d; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
73
|
|
68
|
2
|
|
|
2
|
|
9
|
use constant NF_ETH_TYPE_MPLS => 0x8847; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
75
|
|
69
|
2
|
|
|
2
|
|
10
|
use constant NF_ETH_TYPE_PPPoED => 0x8863; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
99
|
|
70
|
2
|
|
|
2
|
|
11
|
use constant NF_ETH_TYPE_PPPoES => 0x8864; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
231
|
|
71
|
2
|
|
|
2
|
|
14
|
use constant NF_ETH_TYPE_8021X => 0x888e; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
78
|
|
72
|
2
|
|
|
2
|
|
8
|
use constant NF_ETH_TYPE_AoE => 0x88a2; |
|
2
|
|
|
|
|
16
|
|
|
2
|
|
|
|
|
85
|
|
73
|
2
|
|
|
2
|
|
9
|
use constant NF_ETH_TYPE_80211I => 0x88c7; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
74
|
|
74
|
2
|
|
|
2
|
|
15
|
use constant NF_ETH_TYPE_LLDP => 0x88cc; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
84
|
|
75
|
2
|
|
|
2
|
|
10
|
use constant NF_ETH_TYPE_LLTD => 0x88d9; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
74
|
|
76
|
2
|
|
|
2
|
|
9
|
use constant NF_ETH_TYPE_LOOP => 0x9000; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
96
|
|
77
|
2
|
|
|
2
|
|
20
|
use constant NF_ETH_TYPE_VLAN => 0x9100; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
98
|
|
78
|
2
|
|
|
2
|
|
11
|
use constant NF_ETH_TYPE_PPPPAP => 0xc023; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
83
|
|
79
|
2
|
|
|
2
|
|
11
|
use constant NF_ETH_TYPE_PPPCHAP => 0xc223; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
178
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
our @AS = qw( |
82
|
|
|
|
|
|
|
dst |
83
|
|
|
|
|
|
|
src |
84
|
|
|
|
|
|
|
type |
85
|
|
|
|
|
|
|
); |
86
|
|
|
|
|
|
|
__PACKAGE__->cgBuildIndices; |
87
|
|
|
|
|
|
|
__PACKAGE__->cgBuildAccessorsScalar(\@AS); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
BEGIN { |
90
|
2
|
|
|
2
|
|
62
|
*length = \&type; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
2
|
|
|
2
|
|
10
|
no strict 'vars'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1443
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub new { |
96
|
1
|
|
|
1
|
1
|
21
|
my $self = shift->SUPER::new( |
97
|
|
|
|
|
|
|
src => '00:00:00:00:00:00', |
98
|
|
|
|
|
|
|
dst => NF_ETH_ADDR_BROADCAST, |
99
|
|
|
|
|
|
|
type => NF_ETH_TYPE_IPv4, |
100
|
|
|
|
|
|
|
@_, |
101
|
|
|
|
|
|
|
); |
102
|
|
|
|
|
|
|
|
103
|
1
|
50
|
|
|
|
278
|
$self->[$__src] = lc($self->[$__src]) if $self->[$__src]; |
104
|
1
|
50
|
|
|
|
5
|
$self->[$__dst] = lc($self->[$__dst]) if $self->[$__dst]; |
105
|
|
|
|
|
|
|
|
106
|
1
|
|
|
|
|
3
|
$self; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
0
|
1
|
0
|
sub getLength { NF_ETH_HDR_LEN } |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub pack { |
112
|
1
|
|
|
1
|
1
|
5
|
my $self = shift; |
113
|
|
|
|
|
|
|
|
114
|
1
|
|
|
|
|
6
|
(my $dst = $self->[$__dst]) =~ s/://g; |
115
|
1
|
|
|
|
|
4
|
(my $src = $self->[$__src]) =~ s/://g; |
116
|
|
|
|
|
|
|
|
117
|
1
|
50
|
|
|
|
9
|
$self->[$__raw] = $self->SUPER::pack('H12H12n', $dst, $src, $self->[$__type]) |
118
|
|
|
|
|
|
|
or return undef; |
119
|
|
|
|
|
|
|
|
120
|
1
|
|
|
|
|
3
|
$self->[$__raw]; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub unpack { |
124
|
1
|
|
|
1
|
1
|
5
|
my $self = shift; |
125
|
|
|
|
|
|
|
|
126
|
1
|
50
|
|
|
|
7
|
my ($dst, $src, $type, $payload) = |
127
|
|
|
|
|
|
|
$self->SUPER::unpack('H12H12n a*', $self->[$__raw]) |
128
|
|
|
|
|
|
|
or return undef; |
129
|
|
|
|
|
|
|
|
130
|
1
|
|
|
|
|
4
|
$self->[$__dst] = convertMac($dst); |
131
|
1
|
|
|
|
|
2
|
$self->[$__src] = convertMac($src); |
132
|
|
|
|
|
|
|
|
133
|
1
|
|
|
|
|
2
|
$self->[$__type] = $type; |
134
|
1
|
|
|
|
|
3
|
$self->[$__payload] = $payload; |
135
|
|
|
|
|
|
|
|
136
|
1
|
|
|
|
|
2
|
$self; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub computeLengths { |
140
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
141
|
0
|
|
|
|
|
0
|
my ($layers) = @_; |
142
|
0
|
0
|
|
|
|
0
|
if ($self->[$__type] <= 1500) { |
143
|
0
|
|
|
|
|
0
|
my $len = 0; |
144
|
0
|
|
|
|
|
0
|
for my $l (@$layers) { |
145
|
0
|
0
|
|
|
|
0
|
next if $l->layer eq 'ETH'; |
146
|
|
|
|
|
|
|
# We do not use getLength(), because the layer may |
147
|
|
|
|
|
|
|
# have a fake length, due to fuzzing or stress |
148
|
|
|
|
|
|
|
# testing attempts from the user |
149
|
0
|
|
|
|
|
0
|
$len += CORE::length($l->pack), |
150
|
|
|
|
|
|
|
} |
151
|
0
|
|
|
|
|
0
|
$self->type($len); |
152
|
|
|
|
|
|
|
} |
153
|
0
|
|
|
|
|
0
|
return 1; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
our $Next = { |
157
|
|
|
|
|
|
|
NF_ETH_TYPE_IPv4() => 'IPv4', |
158
|
|
|
|
|
|
|
NF_ETH_TYPE_X25() => 'X25', |
159
|
|
|
|
|
|
|
NF_ETH_TYPE_ARP() => 'ARP', |
160
|
|
|
|
|
|
|
NF_ETH_TYPE_CGMP() => 'CGMP', |
161
|
|
|
|
|
|
|
NF_ETH_TYPE_80211() => '80211', |
162
|
|
|
|
|
|
|
NF_ETH_TYPE_PPPIPCP() => 'PPPIPCP', |
163
|
|
|
|
|
|
|
NF_ETH_TYPE_RARP() => 'RARP', |
164
|
|
|
|
|
|
|
NF_ETH_TYPE_DDP () => 'DDP', |
165
|
|
|
|
|
|
|
NF_ETH_TYPE_AARP() => 'AARP', |
166
|
|
|
|
|
|
|
NF_ETH_TYPE_PPPCCP() => 'PPPCCP', |
167
|
|
|
|
|
|
|
NF_ETH_TYPE_WCP() => 'WCP', |
168
|
|
|
|
|
|
|
NF_ETH_TYPE_8021Q() => '8021Q', |
169
|
|
|
|
|
|
|
NF_ETH_TYPE_IPX() => 'IPX', |
170
|
|
|
|
|
|
|
NF_ETH_TYPE_STP() => 'STP', |
171
|
|
|
|
|
|
|
NF_ETH_TYPE_IPv6() => 'IPv6', |
172
|
|
|
|
|
|
|
NF_ETH_TYPE_WLCCP() => 'WLCCP', |
173
|
|
|
|
|
|
|
NF_ETH_TYPE_MPLS() => 'MPLS', |
174
|
|
|
|
|
|
|
NF_ETH_TYPE_PPPoED() => 'PPPoED', |
175
|
|
|
|
|
|
|
NF_ETH_TYPE_PPPoES() => 'PPPoES', |
176
|
|
|
|
|
|
|
NF_ETH_TYPE_8021X() => '8021X', |
177
|
|
|
|
|
|
|
NF_ETH_TYPE_AoE() => 'AoE', |
178
|
|
|
|
|
|
|
NF_ETH_TYPE_80211I() => '80211I', |
179
|
|
|
|
|
|
|
NF_ETH_TYPE_LLDP() => 'LLDP', |
180
|
|
|
|
|
|
|
NF_ETH_TYPE_LLTD() => 'LLTD', |
181
|
|
|
|
|
|
|
NF_ETH_TYPE_LOOP() => 'LOOP', |
182
|
|
|
|
|
|
|
NF_ETH_TYPE_VLAN() => 'VLAN', |
183
|
|
|
|
|
|
|
NF_ETH_TYPE_PPPPAP() => 'PPPPAP', |
184
|
|
|
|
|
|
|
NF_ETH_TYPE_PPPCHAP() => 'PPPCHAP', |
185
|
|
|
|
|
|
|
}; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub encapsulate { |
188
|
1
|
|
|
1
|
1
|
9
|
my $self = shift; |
189
|
|
|
|
|
|
|
|
190
|
1
|
50
|
|
|
|
5
|
return $self->[$__nextLayer] if $self->[$__nextLayer]; |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
# Is this a 802.3 layer ? |
193
|
1
|
0
|
33
|
|
|
21
|
if ($self->[$__type] <= 1500 && $self->[$__payload]) { |
194
|
0
|
|
|
|
|
0
|
my $payload = CORE::unpack('H*', $self->[$__payload]); |
195
|
|
|
|
|
|
|
# We consider this is a LLC layer if the payload is more than 6 bytes long |
196
|
0
|
0
|
|
|
|
0
|
if (CORE::length($payload) > 6) { |
197
|
0
|
|
|
|
|
0
|
return 'LLC'; |
198
|
|
|
|
|
|
|
} |
199
|
0
|
|
|
|
|
0
|
return NF_LAYER_UNKNOWN; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
1
|
50
|
|
|
|
7
|
$Next->{$self->[$__type]} || NF_LAYER_UNKNOWN; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub print { |
206
|
1
|
|
|
1
|
1
|
5
|
my $self = shift; |
207
|
|
|
|
|
|
|
|
208
|
1
|
|
|
|
|
5
|
my $l = $self->layer; |
209
|
1
|
|
|
|
|
7
|
my $buf = sprintf "$l: dst:%s src:%s ", $self->[$__dst], $self->[$__src]; |
210
|
|
|
|
|
|
|
|
211
|
1
|
50
|
|
|
|
4
|
if ($self->[$__type] <= 1500) { |
212
|
0
|
|
|
|
|
0
|
$buf .= sprintf "length:%d", $self->[$__type]; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
else { |
215
|
1
|
|
|
|
|
5
|
$buf .= sprintf "type:0x%04x", $self->[$__type]; |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
1
|
|
|
|
|
40
|
$buf; |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
1; |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
__END__ |