line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# lookup::ethernet Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::Lookup::Ethernet; |
7
|
1
|
|
|
1
|
|
770
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw(Metabrik); |
|
1
|
|
|
|
|
13
|
|
|
1
|
|
|
|
|
627
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable) ], |
16
|
|
|
|
|
|
|
author => 'GomoR ', |
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
18
|
|
|
|
|
|
|
commands => { |
19
|
|
|
|
|
|
|
from_dec => [ qw(dec_number) ], |
20
|
|
|
|
|
|
|
from_hex => [ qw(hex_number) ], |
21
|
|
|
|
|
|
|
from_string => [ qw(ethernet_type) ], |
22
|
|
|
|
|
|
|
}, |
23
|
|
|
|
|
|
|
}; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _lookup { |
27
|
0
|
|
|
0
|
|
|
my $self = shift; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
my $lookup = { |
30
|
|
|
|
|
|
|
'0x0800' => 'ipv4', |
31
|
|
|
|
|
|
|
'0x0805' => 'x25', |
32
|
|
|
|
|
|
|
'0x0806' => 'arp', |
33
|
|
|
|
|
|
|
'0x2001' => 'cgmp', |
34
|
|
|
|
|
|
|
'0x2452' => '802.11', |
35
|
|
|
|
|
|
|
'0x8021' => 'pppipcp', |
36
|
|
|
|
|
|
|
'0x8035' => 'rarp', |
37
|
|
|
|
|
|
|
'0x809b' => 'ddp', |
38
|
|
|
|
|
|
|
'0x80f3' => 'aarp', |
39
|
|
|
|
|
|
|
'0x80fd' => 'pppccp', |
40
|
|
|
|
|
|
|
'0x80ff' => 'wcp', |
41
|
|
|
|
|
|
|
'0x8100' => '802.1q', |
42
|
|
|
|
|
|
|
'0x8137' => 'ipx', |
43
|
|
|
|
|
|
|
'0x8181' => 'stp', |
44
|
|
|
|
|
|
|
'0x86dd' => 'ipv6', |
45
|
|
|
|
|
|
|
'0x872d' => 'wlccp', |
46
|
|
|
|
|
|
|
'0x8847' => 'mpls', |
47
|
|
|
|
|
|
|
'0x8863' => 'pppoed', |
48
|
|
|
|
|
|
|
'0x8864' => 'pppoes', |
49
|
|
|
|
|
|
|
'0x888e' => '802.1x', |
50
|
|
|
|
|
|
|
'0x88a2' => 'aoe', |
51
|
|
|
|
|
|
|
'0x88c7' => '802.11i', |
52
|
|
|
|
|
|
|
'0x88cc' => 'lldp', |
53
|
|
|
|
|
|
|
'0x88d9' => 'lltd', |
54
|
|
|
|
|
|
|
'0x9000' => 'loop', |
55
|
|
|
|
|
|
|
'0x9100' => 'vlan', |
56
|
|
|
|
|
|
|
'0xc023' => 'ppppap', |
57
|
|
|
|
|
|
|
'0xc223' => 'pppchap', |
58
|
|
|
|
|
|
|
}; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
return $lookup; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub from_hex { |
64
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
65
|
0
|
|
|
|
|
|
my ($hex) = @_; |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('from_hex', $hex) or return; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$hex =~ s/^0x//; |
70
|
0
|
0
|
|
|
|
|
if ($hex !~ /^[0-9a-f]+$/i) { |
71
|
0
|
|
|
|
|
|
return $self->log->error("from_hex: invalid format for hex [$hex]"); |
72
|
|
|
|
|
|
|
} |
73
|
0
|
|
|
|
|
|
$hex = sprintf("0x%04s", $hex); |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
0
|
|
|
|
return $self->_lookup->{$hex} || 'undef'; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub from_dec { |
79
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
80
|
0
|
|
|
|
|
|
my ($dec) = @_; |
81
|
|
|
|
|
|
|
|
82
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('from_dec', $dec) or return; |
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
if ($dec !~ /^[0-9]+$/) { |
85
|
0
|
|
|
|
|
|
return $self->log->error("from_dec: invalid format for dec [$dec]"); |
86
|
|
|
|
|
|
|
} |
87
|
0
|
|
|
|
|
|
my $hex = sprintf("0x%04x", $dec); |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
return $self->hex($hex); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub from_string { |
93
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
94
|
0
|
|
|
|
|
|
my ($string) = @_; |
95
|
|
|
|
|
|
|
|
96
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('from_string', $string) or return; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
my $lookup = $self->_lookup; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
my $rev = {}; |
101
|
0
|
|
|
|
|
|
while (my ($key, $val) = each(%$lookup)) { |
102
|
0
|
|
|
|
|
|
$rev->{$val} = $key; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
0
|
|
|
|
return $rev->{$string} || 'undef'; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
__END__ |