| 1 | #!/bin/false | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Base class for DHCPv6 relay messages (RelayForw/RelayReply) | ||||||||||||||||||||||||||||
| 3 | # PODNAME: Net::DHCPv6::Packet::Relay | ||||||||||||||||||||||||||||
| 4 | 29 | ▶ | use strictures 2; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | package Net::DHCPv6::Packet::Relay; | ||||||||||||||||||||||||||||
| 7 | 29 | $Net::DHCPv6::Packet::Relay::VERSION = '0.003'; | |||||||||||||||||||||||||||
| 8 | 29 | ▶ | use Net::DHCPv6::Constants qw( $IPV6_ADDR_LEN ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 29 | ▶ | use Net::DHCPv6::Packet (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 29 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 29 | ▶ | use Net::DHCPv6::OptionList (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 29 | ▶ | use Net::DHCPv6::X::BadMessage (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 29 | ▶ | use parent 'Net::DHCPv6::Helpers', 'Net::DHCPv6::Packet'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 29 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 29 | my $RELAY_HDR_SIZE = 34; ## no critic (ValuesAndExpressions::ProhibitMagicNumbers) | |||||||||||||||||||||||||||
| 17 | 29 | my $LINK_ADDR_OFFSET = 2; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=21.3
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 2 | my ( $class, %args ) = @_; | |||||||||||||||||||||||||||
| 21 | 2 | ▶ | croak 'Relay->new: hop_count is required' unless defined $args{hop_count}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 2 | my $link_addr = $class->_pick_addr( \%args, 'link_address' ); | |||||||||||||||||||||||||||
| 23 | 2 | ▶ | croak 'Relay->new: link_address is required' unless defined $link_addr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 2 | ▶ | croak 'Relay->new: link_address must be 16 bytes' unless CORE::length( $link_addr ) == $IPV6_ADDR_LEN; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 2 | my $peer_addr = $class->_pick_addr( \%args, 'peer_address' ); | |||||||||||||||||||||||||||
| 26 | 2 | ▶ | croak 'Relay->new: peer_address is required' unless defined $peer_addr; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 2 | ▶ | croak 'Relay->new: peer_address must be 16 bytes' unless CORE::length( $peer_addr ) == $IPV6_ADDR_LEN; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 2 | ▶ | $args{options} = $args{options} // Net::DHCPv6::OptionList->new; | ||||||||||||||||||||||||||
|
Condition33%1/3
$args{"options"} // "Net::DHCPv6::OptionList"->new
MC/DC0%0/2
$args{"options"} // "Net::DHCPv6::OptionList"->new
$args{"options"}
"Net::DHCPv6::OptionList"->new
Truth table33%1/3
A // B
A= $args{"options"}B= "Net::DHCPv6::OptionList"->new
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | return bless { | ||||||||||||||||||||||||||||
| 32 | msg_type => $args{msg_type}, | ||||||||||||||||||||||||||||
| 33 | hop_count => $args{hop_count}, | ||||||||||||||||||||||||||||
| 34 | link_address => $link_addr, | ||||||||||||||||||||||||||||
| 35 | peer_address => $peer_addr, | ||||||||||||||||||||||||||||
| 36 | options => $args{options}, | ||||||||||||||||||||||||||||
| 37 | 2 | }, $class; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 4 | ▶ | sub hop_count { return shift->{hop_count} } | ||||||||||||||||||||||||||
|
Subroutine
hop_count: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 4 | ▶ | sub link_address { | ||||||||||||||||||||||||||
|
Subroutine
link_address: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 44 | 4 | return $self->_format_ipv6( $self->{link_address} ); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | 4 | ▶ | sub link_address_raw { return shift->{link_address} } | ||||||||||||||||||||||||||
|
Subroutine
link_address_raw: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 4 | ▶ | sub peer_address { | ||||||||||||||||||||||||||
|
Subroutine
peer_address: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 50 | 4 | return $self->_format_ipv6( $self->{peer_address} ); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | 4 | ▶ | sub peer_address_raw { return shift->{peer_address} } | ||||||||||||||||||||||||||
|
Subroutine
peer_address_raw: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 5 | ▶ | sub from_bytes { | ||||||||||||||||||||||||||
|
Subroutine
from_bytes: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 5 | my ( $class, $bytes ) = @_; | |||||||||||||||||||||||||||
| 56 | 5 | ▶ | Net::DHCPv6::X::BadMessage->throw( message => 'Empty relay data' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $bytes or length $bytes < $RELAY_HDR_SIZE
MC/DC50%1/2
not defined $bytes or length $bytes < $RELAY_HDR_SIZE
not defined $bytes
length $bytes < $RELAY_HDR_SIZE
Truth table66%2/3
not(A) or B
A= not defined $bytesB= length $bytes < $RELAY_HDR_SIZE
| |||||||||||||||||||||||||||||
| 57 | if !defined $bytes || CORE::length( $bytes ) < $RELAY_HDR_SIZE; | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 3 | my $msg_type = unpack( 'C', substr( $bytes, 0, 1 ) ); | |||||||||||||||||||||||||||
| 60 | 3 | my $hop_count = unpack( 'C', substr( $bytes, 1, 1 ) ); | |||||||||||||||||||||||||||
| 61 | 3 | my $link_addr = substr( $bytes, $LINK_ADDR_OFFSET, $IPV6_ADDR_LEN ); | |||||||||||||||||||||||||||
| 62 | 3 | my $peer_addr = substr( $bytes, $LINK_ADDR_OFFSET + $IPV6_ADDR_LEN, $IPV6_ADDR_LEN ); | |||||||||||||||||||||||||||
| 63 | 3 | my $opts_bytes = substr( $bytes, $RELAY_HDR_SIZE ); | |||||||||||||||||||||||||||
| 64 | 3 | my $opts = Net::DHCPv6::OptionList->from_bytes( $opts_bytes ); | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 3 | ▶ | my $subclass = $Net::DHCPv6::Packet::MESSAGE_CLASS{$msg_type} || $class; | ||||||||||||||||||||||||||
|
Condition33%1/3
$Net::DHCPv6::Packet::MESSAGE_CLASS{$msg_type} || $class
MC/DC0%0/2
$Net::DHCPv6::Packet::MESSAGE_CLASS{$msg_type} || $class
$Net::DHCPv6::Packet::MESSAGE_CLASS{$msg_type}
$class
Truth table33%1/3
A || B
A= $Net::DHCPv6::Packet::MESSAGE_CLASS{$msg_type}B= $class
| |||||||||||||||||||||||||||||
| 67 | 3 | return bless { | |||||||||||||||||||||||||||
| 68 | msg_type => $msg_type, | ||||||||||||||||||||||||||||
| 69 | hop_count => $hop_count, | ||||||||||||||||||||||||||||
| 70 | link_address => $link_addr, | ||||||||||||||||||||||||||||
| 71 | peer_address => $peer_addr, | ||||||||||||||||||||||||||||
| 72 | options => $opts, | ||||||||||||||||||||||||||||
| 73 | }, $subclass; | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 2 | ▶ | sub as_bytes { | ||||||||||||||||||||||||||
|
Subroutine
as_bytes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 77 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 78 | return | ||||||||||||||||||||||||||||
| 79 | pack( 'C C a16 a16', $self->{msg_type}, $self->{hop_count}, $self->{link_address}, $self->{peer_address} ) | ||||||||||||||||||||||||||||
| 80 | 2 | . $self->{options}->as_bytes; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 29 | 1; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | __END__ | ||||||||||||||||||||||||||||