| 1 | # | ||||||||||||||||||||||||||||
| 2 | # $Id: Routing.pm 47 2015-01-20 18:20:28Z gomor $ | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | package Net::Frame::Layer::IPv6::Routing; | ||||||||||||||||||||||||||||
| 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.07'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Net::Frame::Layer qw(:consts :subs); | ||||||||||||||||||||||||||
|
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 @AS = qw( | |||||||||||||||||||||||||||
| 14 | nextHeader | ||||||||||||||||||||||||||||
| 15 | hdrExtLen | ||||||||||||||||||||||||||||
| 16 | routingType | ||||||||||||||||||||||||||||
| 17 | segmentsLeft | ||||||||||||||||||||||||||||
| 18 | reserved | ||||||||||||||||||||||||||||
| 19 | ); | ||||||||||||||||||||||||||||
| 20 | 3 | our @AA = qw( | |||||||||||||||||||||||||||
| 21 | addresses | ||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||
| 23 | 3 | __PACKAGE__->cgBuildIndices; | |||||||||||||||||||||||||||
| 24 | 3 | __PACKAGE__->cgBuildAccessorsScalar(\@AS); | |||||||||||||||||||||||||||
| 25 | 3 | __PACKAGE__->cgBuildAccessorsArray(\@AA); | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 3 | ▶ | use Net::Frame::Layer::IPv6 qw(:consts); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 28 | 3 | my $IPv6RoutingComputeSegmentsLeft = 1; | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | sub new { | ||||||||||||||||||||||||||||
| 31 | shift->SUPER::new( | ||||||||||||||||||||||||||||
| 32 | 1 | ▶ | nextHeader => NF_IPv6_PROTOCOL_TCP, | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | hdrExtLen => 2, | ||||||||||||||||||||||||||||
| 34 | routingType => 0, | ||||||||||||||||||||||||||||
| 35 | segmentsLeft => 1, | ||||||||||||||||||||||||||||
| 36 | reserved => 0, | ||||||||||||||||||||||||||||
| 37 | addresses => ['::1'], | ||||||||||||||||||||||||||||
| 38 | @_, | ||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | sub _getAddressesLength { | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_getAddressesLength: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 44 | 0 | my $len = 0; | |||||||||||||||||||||||||||
| 45 | 0 | $len += 16 for $self->addresses; | |||||||||||||||||||||||||||
| 46 | 0 | return $len; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | sub getLength { | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
getLength: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 51 | 0 | return 8 + $self->_getAddressesLength; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | sub pack { | ||||||||||||||||||||||||||||
| 55 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
pack: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 1 | ▶ | my $raw = $self->SUPER::pack('CCCCN', | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | $self->nextHeader, $self->hdrExtLen, $self->routingType, | ||||||||||||||||||||||||||||
| 59 | $self->segmentsLeft, $self->reserved | ||||||||||||||||||||||||||||
| 60 | ) or return; | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 1 | for ($self->addresses) { | |||||||||||||||||||||||||||
| 63 | 1 | ▶ | $raw .= $self->SUPER::pack('a16', | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | inet6Aton($_) | ||||||||||||||||||||||||||||
| 65 | ) or return; | ||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 1 | return $self->raw($raw); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | sub unpack { | ||||||||||||||||||||||||||||
| 72 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
unpack: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 1 | ▶ | my ($nextHeader, $hdrExtLen, $routingType, $segmentsLeft, $reserved, $rest) = | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | $self->SUPER::unpack('CCCCN a*', $self->raw) | ||||||||||||||||||||||||||||
| 76 | or return; | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 1 | $self->nextHeader($nextHeader); | |||||||||||||||||||||||||||
| 79 | 1 | $self->hdrExtLen($hdrExtLen); | |||||||||||||||||||||||||||
| 80 | 1 | $self->routingType($routingType); | |||||||||||||||||||||||||||
| 81 | 1 | $self->segmentsLeft($segmentsLeft); | |||||||||||||||||||||||||||
| 82 | 1 | $self->reserved($reserved); | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 1 | my @addresses = (); | |||||||||||||||||||||||||||
| 85 | 1 | for (1..$hdrExtLen/2) { | |||||||||||||||||||||||||||
| 86 | 1 | ▶ | my ($address) = | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | $self->SUPER::unpack('a16', substr $rest, 16*($_-1)) | ||||||||||||||||||||||||||||
| 88 | or return; | ||||||||||||||||||||||||||||
| 89 | 1 | push @addresses, inet6Ntoa($address) | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 1 | $self->addresses(\@addresses); | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 1 | $self->payload(substr $rest, 16*$hdrExtLen/2); | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 1 | return $self; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | sub computeSegmentsLeft { | ||||||||||||||||||||||||||||
| 100 | 0 | ▶ | my ($self, $arg) = @_; | ||||||||||||||||||||||||||
|
Subroutine
computeSegmentsLeft: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if (defined($arg)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if (($arg =~ /^\d$/) && ($arg == 0)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$arg =~ /^\d$/ and $arg == 0
MC/DC0%0/2
$arg =~ /^\d$/ and $arg == 0
$arg =~ /^\d$/
$arg == 0
Truth table0%0/3
A and B
A= $arg =~ /^\d$/B= $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 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
computeLengths: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | my $hdrExtLen = 0; | |||||||||||||||||||||||||||
| 116 | 0 | $hdrExtLen += 2 for $self->addresses; | |||||||||||||||||||||||||||
| 117 | 0 | $self->hdrExtLen($hdrExtLen); | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | if ($IPv6RoutingComputeSegmentsLeft) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
encapsulate: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | return $self->nextLayer if $self->nextLayer; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 0 | ▶ | if ($self->payload) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
print: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 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 | 3 | 1; | |||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | __END__ | ||||||||||||||||||||||||||||