| 1 | # | ||||||||||||||||||||||||||||
| 2 | # $Id: 8021Q.pm 7 2010-06-03 12:35:18Z gomor $ | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | package Net::Frame::Layer::8021Q; | ||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use strict; use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | our $VERSION = '1.02'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Net::Frame::Layer qw(:consts); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Exporter; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | our @ISA = qw(Net::Frame::Layer Exporter); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 3 | our %EXPORT_TAGS = ( | |||||||||||||||||||||||||||
| 14 | consts => [qw( | ||||||||||||||||||||||||||||
| 15 | NF_8021Q_HDR_LEN | ||||||||||||||||||||||||||||
| 16 | NF_8021Q_TYPE_IPv4 | ||||||||||||||||||||||||||||
| 17 | NF_8021Q_TYPE_X25 | ||||||||||||||||||||||||||||
| 18 | NF_8021Q_TYPE_ARP | ||||||||||||||||||||||||||||
| 19 | NF_8021Q_TYPE_CGMP | ||||||||||||||||||||||||||||
| 20 | NF_8021Q_TYPE_80211 | ||||||||||||||||||||||||||||
| 21 | NF_8021Q_TYPE_PPPIPCP | ||||||||||||||||||||||||||||
| 22 | NF_8021Q_TYPE_RARP | ||||||||||||||||||||||||||||
| 23 | NF_8021Q_TYPE_DDP | ||||||||||||||||||||||||||||
| 24 | NF_8021Q_TYPE_AARP | ||||||||||||||||||||||||||||
| 25 | NF_8021Q_TYPE_PPPCCP | ||||||||||||||||||||||||||||
| 26 | NF_8021Q_TYPE_WCP | ||||||||||||||||||||||||||||
| 27 | NF_8021Q_TYPE_8021Q | ||||||||||||||||||||||||||||
| 28 | NF_8021Q_TYPE_IPX | ||||||||||||||||||||||||||||
| 29 | NF_8021Q_TYPE_STP | ||||||||||||||||||||||||||||
| 30 | NF_8021Q_TYPE_IPv6 | ||||||||||||||||||||||||||||
| 31 | NF_8021Q_TYPE_WLCCP | ||||||||||||||||||||||||||||
| 32 | NF_8021Q_TYPE_MPLS | ||||||||||||||||||||||||||||
| 33 | NF_8021Q_TYPE_PPPoED | ||||||||||||||||||||||||||||
| 34 | NF_8021Q_TYPE_PPPoES | ||||||||||||||||||||||||||||
| 35 | NF_8021Q_TYPE_8021X | ||||||||||||||||||||||||||||
| 36 | NF_8021Q_TYPE_AoE | ||||||||||||||||||||||||||||
| 37 | NF_8021Q_TYPE_80211I | ||||||||||||||||||||||||||||
| 38 | NF_8021Q_TYPE_LLDP | ||||||||||||||||||||||||||||
| 39 | NF_8021Q_TYPE_LLTD | ||||||||||||||||||||||||||||
| 40 | NF_8021Q_TYPE_LOOP | ||||||||||||||||||||||||||||
| 41 | NF_8021Q_TYPE_VLAN | ||||||||||||||||||||||||||||
| 42 | NF_8021Q_TYPE_PPPPAP | ||||||||||||||||||||||||||||
| 43 | NF_8021Q_TYPE_PPPCHAP | ||||||||||||||||||||||||||||
| 44 | )], | ||||||||||||||||||||||||||||
| 45 | ); | ||||||||||||||||||||||||||||
| 46 | our @EXPORT_OK = ( | ||||||||||||||||||||||||||||
| 47 | 3 | @{$EXPORT_TAGS{consts}}, | |||||||||||||||||||||||||||
| 48 | ); | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 3 | ▶ | use constant NF_8021Q_HDR_LEN => 4; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | 3 | ▶ | use constant NF_8021Q_TYPE_IPv4 => 0x0800; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 52 | 3 | ▶ | use constant NF_8021Q_TYPE_X25 => 0x0805; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 53 | 3 | ▶ | use constant NF_8021Q_TYPE_ARP => 0x0806; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 54 | 3 | ▶ | use constant NF_8021Q_TYPE_CGMP => 0x2001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | 3 | ▶ | use constant NF_8021Q_TYPE_80211 => 0x2452; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 56 | 3 | ▶ | use constant NF_8021Q_TYPE_PPPIPCP => 0x8021; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 57 | 3 | ▶ | use constant NF_8021Q_TYPE_RARP => 0x8035; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 58 | 3 | ▶ | use constant NF_8021Q_TYPE_DDP => 0x809b; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 59 | 3 | ▶ | use constant NF_8021Q_TYPE_AARP => 0x80f3; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 60 | 3 | ▶ | use constant NF_8021Q_TYPE_PPPCCP => 0x80fd; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 61 | 3 | ▶ | use constant NF_8021Q_TYPE_WCP => 0x80ff; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 62 | 3 | ▶ | use constant NF_8021Q_TYPE_8021Q => 0x8100; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 63 | 3 | ▶ | use constant NF_8021Q_TYPE_IPX => 0x8137; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 64 | 3 | ▶ | use constant NF_8021Q_TYPE_STP => 0x8181; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 65 | 3 | ▶ | use constant NF_8021Q_TYPE_IPv6 => 0x86dd; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 66 | 3 | ▶ | use constant NF_8021Q_TYPE_WLCCP => 0x872d; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 67 | 3 | ▶ | use constant NF_8021Q_TYPE_MPLS => 0x8847; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 68 | 3 | ▶ | use constant NF_8021Q_TYPE_PPPoED => 0x8863; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 69 | 3 | ▶ | use constant NF_8021Q_TYPE_PPPoES => 0x8864; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 70 | 3 | ▶ | use constant NF_8021Q_TYPE_8021X => 0x888e; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 71 | 3 | ▶ | use constant NF_8021Q_TYPE_AoE => 0x88a2; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 72 | 3 | ▶ | use constant NF_8021Q_TYPE_80211I => 0x88c7; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 73 | 3 | ▶ | use constant NF_8021Q_TYPE_LLDP => 0x88cc; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 74 | 3 | ▶ | use constant NF_8021Q_TYPE_LLTD => 0x88d9; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 75 | 3 | ▶ | use constant NF_8021Q_TYPE_LOOP => 0x9000; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 76 | 3 | ▶ | use constant NF_8021Q_TYPE_VLAN => 0x9100; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 77 | 3 | ▶ | use constant NF_8021Q_TYPE_PPPPAP => 0xc023; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 78 | 3 | ▶ | use constant NF_8021Q_TYPE_PPPCHAP => 0xc223; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 3 | our @AS = qw( | |||||||||||||||||||||||||||
| 81 | priority | ||||||||||||||||||||||||||||
| 82 | cfi | ||||||||||||||||||||||||||||
| 83 | id | ||||||||||||||||||||||||||||
| 84 | type | ||||||||||||||||||||||||||||
| 85 | ); | ||||||||||||||||||||||||||||
| 86 | 3 | __PACKAGE__->cgBuildIndices; | |||||||||||||||||||||||||||
| 87 | 3 | __PACKAGE__->cgBuildAccessorsScalar(\@AS); | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 3 | ▶ | no strict 'vars'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 3 | require Bit::Vector; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | sub new { | ||||||||||||||||||||||||||||
| 94 | shift->SUPER::new( | ||||||||||||||||||||||||||||
| 95 | 1 | ▶ | priority => 0, | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 96 | cfi => 0, | ||||||||||||||||||||||||||||
| 97 | id => 0, | ||||||||||||||||||||||||||||
| 98 | type => NF_8021Q_TYPE_IPv4, | ||||||||||||||||||||||||||||
| 99 | @_, | ||||||||||||||||||||||||||||
| 100 | ); | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | sub getLength { NF_8021Q_HDR_LEN } | ||||||||||||||||||||||||||
|
Subroutine
getLength: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | sub pack { | ||||||||||||||||||||||||||||
| 106 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
pack: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 1 | my $v3 = Bit::Vector->new_Dec( 3, $self->[$__priority]); | |||||||||||||||||||||||||||
| 109 | 1 | my $v1 = Bit::Vector->new_Dec( 1, $self->[$__cfi]); | |||||||||||||||||||||||||||
| 110 | 1 | my $v12 = Bit::Vector->new_Dec(12, $self->[$__id]); | |||||||||||||||||||||||||||
| 111 | 1 | my $v16 = $v3->Concat_List($v1, $v12); | |||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 1 | ▶ | $self->[$__raw] = $self->SUPER::pack('nn', | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | $v16->to_Dec, | ||||||||||||||||||||||||||||
| 115 | $self->[$__type], | ||||||||||||||||||||||||||||
| 116 | ) or return undef; | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 1 | $self->[$__raw]; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | sub unpack { | ||||||||||||||||||||||||||||
| 122 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
unpack: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 1 | ▶ | my ($pCfiId, $type, $payload) = | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | $self->SUPER::unpack('nn a*', $self->[$__raw]) | ||||||||||||||||||||||||||||
| 126 | or return undef; | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 1 | my $v16 = Bit::Vector->new_Dec(16, $pCfiId); | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 1 | $self->[$__priority] = $v16->Chunk_Read( 3, 13); | |||||||||||||||||||||||||||
| 131 | 1 | $self->[$__cfi] = $v16->Chunk_Read( 1, 12); | |||||||||||||||||||||||||||
| 132 | 1 | $self->[$__id] = $v16->Chunk_Read(12, 0); | |||||||||||||||||||||||||||
| 133 | 1 | $self->[$__type] = $type; | |||||||||||||||||||||||||||
| 134 | 1 | $self->[$__payload] = $payload; | |||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 1 | $self; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | sub encapsulate { | ||||||||||||||||||||||||||||
| 140 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
encapsulate: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 0 | ▶ | return $self->[$__nextLayer] if $self->[$__nextLayer]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 0 | my $types = { | |||||||||||||||||||||||||||
| 145 | NF_8021Q_TYPE_IPv4() => 'IPv4', | ||||||||||||||||||||||||||||
| 146 | NF_8021Q_TYPE_X25() => 'X25', | ||||||||||||||||||||||||||||
| 147 | NF_8021Q_TYPE_ARP() => 'ARP', | ||||||||||||||||||||||||||||
| 148 | NF_8021Q_TYPE_CGMP() => 'CGMP', | ||||||||||||||||||||||||||||
| 149 | NF_8021Q_TYPE_80211() => '80211', | ||||||||||||||||||||||||||||
| 150 | NF_8021Q_TYPE_PPPIPCP() => 'PPPIPCP', | ||||||||||||||||||||||||||||
| 151 | NF_8021Q_TYPE_RARP() => 'RARP', | ||||||||||||||||||||||||||||
| 152 | NF_8021Q_TYPE_DDP() => 'DDP', | ||||||||||||||||||||||||||||
| 153 | NF_8021Q_TYPE_AARP() => 'AARP', | ||||||||||||||||||||||||||||
| 154 | NF_8021Q_TYPE_PPPCCP() => 'PPPCCP', | ||||||||||||||||||||||||||||
| 155 | NF_8021Q_TYPE_WCP() => 'WCP', | ||||||||||||||||||||||||||||
| 156 | NF_8021Q_TYPE_8021Q() => '8021Q', | ||||||||||||||||||||||||||||
| 157 | NF_8021Q_TYPE_IPX() => 'IPX', | ||||||||||||||||||||||||||||
| 158 | NF_8021Q_TYPE_STP() => 'STP', | ||||||||||||||||||||||||||||
| 159 | NF_8021Q_TYPE_IPv6() => 'IPv6', | ||||||||||||||||||||||||||||
| 160 | NF_8021Q_TYPE_WLCCP() => 'WLCCP', | ||||||||||||||||||||||||||||
| 161 | NF_8021Q_TYPE_MPLS() => 'MPLS', | ||||||||||||||||||||||||||||
| 162 | NF_8021Q_TYPE_PPPoED() => 'PPPoED', | ||||||||||||||||||||||||||||
| 163 | NF_8021Q_TYPE_PPPoES() => 'PPPoES', | ||||||||||||||||||||||||||||
| 164 | NF_8021Q_TYPE_8021X() => '8021X', | ||||||||||||||||||||||||||||
| 165 | NF_8021Q_TYPE_AoE() => 'AoE', | ||||||||||||||||||||||||||||
| 166 | NF_8021Q_TYPE_80211I() => '80211I', | ||||||||||||||||||||||||||||
| 167 | NF_8021Q_TYPE_LLDP() => 'LLDP', | ||||||||||||||||||||||||||||
| 168 | NF_8021Q_TYPE_LLTD() => 'LLTD', | ||||||||||||||||||||||||||||
| 169 | NF_8021Q_TYPE_LOOP() => 'LOOP', | ||||||||||||||||||||||||||||
| 170 | NF_8021Q_TYPE_VLAN() => 'VLAN', | ||||||||||||||||||||||||||||
| 171 | NF_8021Q_TYPE_PPPPAP() => 'PPPPAP', | ||||||||||||||||||||||||||||
| 172 | NF_8021Q_TYPE_PPPCHAP() => 'PPPCHAP', | ||||||||||||||||||||||||||||
| 173 | }; | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | 0 | ▶ | if ($self->[$__type] <= 1500 && $self->[$__payload]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->[$__type] <= 1500 and $self->[$__payload]
MC/DC0%0/2
$self->[$__type] <= 1500 and $self->[$__payload]
$self->[$__type] <= 1500
$self->[$__payload]
Truth table0%0/3
A and B
A= $self->[$__type] <= 1500B= $self->[$__payload]
| |||||||||||||||||||||||||||||
| 176 | 0 | my $payload = CORE::unpack('H*', $self->[$__payload]); | |||||||||||||||||||||||||||
| 177 | 0 | ▶ | if ($payload =~ /^aaaa/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | 0 | return 'LLC'; | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | 0 | return NF_LAYER_UNKNOWN; | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 0 | ▶ | $types->{$self->type} || NF_LAYER_UNKNOWN; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | sub print { | ||||||||||||||||||||||||||||
| 187 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
print: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 0 | my $l = $self->layer; | |||||||||||||||||||||||||||
| 190 | 0 | sprintf "$l: priority:0x%01x cfi:0x%01x id:%d type:0x%02x", | |||||||||||||||||||||||||||
| 191 | $self->[$__priority], $self->[$__cfi], $self->[$__id], $self->[$__type]; | ||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 3 | 1; | |||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | __END__ | ||||||||||||||||||||||||||||