| 1 | #!/usr/bin/false | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: DHCPv6 packet base class | ||||||||||||||||||||||||||||
| 3 | # PODNAME: Net::DHCPv6::Packet | ||||||||||||||||||||||||||||
| 4 | package Net::DHCPv6::Packet; | ||||||||||||||||||||||||||||
| 5 | 29 | $Net::DHCPv6::Packet::VERSION = '0.001'; | |||||||||||||||||||||||||||
| 6 | 29 | ▶ | use strictures 2; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 29 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 29 | ▶ | use Net::DHCPv6::Constants; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 29 | ▶ | use Net::DHCPv6::OptionList; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 29 | ▶ | use Net::DHCPv6::Packet::Relay; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 29 | ▶ | use Net::DHCPv6::X::BadMessage; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 29 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | sub new { | ||||||||||||||||||||||||||||
| 15 | 12 | ▶ | my ( $class, @args ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=22.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | 12 | ▶ | if ( @args == 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | 1 | return $class->from_bytes( $args[0] ); | |||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | 11 | ▶ | croak 'Packet->new: no arguments' unless @args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 11 | my %args = @args; | |||||||||||||||||||||||||||
| 21 | 11 | ▶ | croak 'Packet->new: msg_type is required' unless defined $args{msg_type}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 11 | ▶ | croak 'Packet->new: transaction_id is required' unless defined $args{transaction_id}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | croak 'transaction_id must fit in 24 bits' | ||||||||||||||||||||||||||||
| 24 | 11 | ▶ | if $args{transaction_id} < 0 || $args{transaction_id} > 0xFFFFFF; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args{"transaction_id"} < 0 or $args{"transaction_id"} > 16777215
MC/DC0%0/2
$args{"transaction_id"} < 0 or $args{"transaction_id"} > 16777215
$args{"transaction_id"} < 0
$args{"transaction_id"} > 16777215
Truth table33%1/3
A or B
A= $args{"transaction_id"} < 0B= $args{"transaction_id"} > 16777215
| |||||||||||||||||||||||||||||
| 25 | 11 | ▶ | $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
| |||||||||||||||||||||||||||||
| 26 | my $self = { | ||||||||||||||||||||||||||||
| 27 | msg_type => $args{msg_type}, | ||||||||||||||||||||||||||||
| 28 | transaction_id => $args{transaction_id}, | ||||||||||||||||||||||||||||
| 29 | options => $args{options}, | ||||||||||||||||||||||||||||
| 30 | 11 | }; | |||||||||||||||||||||||||||
| 31 | 11 | bless $self, $class; | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 40 | ▶ | sub msg_type { shift->{msg_type} } | ||||||||||||||||||||||||||
|
Subroutine
msg_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 35 | 34 | ▶ | sub transaction_id { shift->{transaction_id} } | ||||||||||||||||||||||||||
|
Subroutine
transaction_id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | 44 | ▶ | sub options { shift->{options} } | ||||||||||||||||||||||||||
|
Subroutine
options: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | sub add_option { | ||||||||||||||||||||||||||||
| 39 | 8 | ▶ | my ( $self, $option ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
add_option: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 40 | 8 | $self->{options}->add_option( $option ); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | sub get_option { | ||||||||||||||||||||||||||||
| 44 | 11 | ▶ | my ( $self, $code ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_option: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 11 | return $self->{options}->get_option( $code ); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | sub as_bytes { | ||||||||||||||||||||||||||||
| 49 | 9 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
as_bytes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 50 | 9 | my $tid = substr( pack( 'N', $self->{transaction_id} ), 1, 3 ); | |||||||||||||||||||||||||||
| 51 | 9 | my $opts = $self->{options}->as_bytes; | |||||||||||||||||||||||||||
| 52 | 9 | return pack( 'C', $self->{msg_type} ) . $tid . $opts; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | sub from_bytes { | ||||||||||||||||||||||||||||
| 56 | 67 | ▶ | my ( $class, $bytes ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
from_bytes: called CC=6 SCAR=18.2
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | 67 | ▶ | Net::DHCPv6::X::BadMessage->throw( message => 'Empty packet data' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $bytes and length $bytes >= 4
MC/DC0%0/2
defined $bytes and length $bytes >= 4
defined $bytes
length $bytes >= 4
Truth table33%1/3
A and B
A= defined $bytesB= length $bytes >= 4
| |||||||||||||||||||||||||||||
| 58 | unless defined $bytes && CORE::length( $bytes ) >= 4; | ||||||||||||||||||||||||||||
| 59 | 67 | my $msg_type = unpack( 'C', substr( $bytes, 0, 1 ) ); | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 67 | ▶ | if ( $msg_type == $RELAY_FORW || $msg_type == $RELAY_REPLY ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$msg_type == $Net::DHCPv6::Packet::RELAY_FORW or $msg_type == $Net::DHCPv6::Packet::RELAY_REPLY
MC/DC100%2/2
$msg_type == $Net::DHCPv6::Packet::RELAY_FORW or $msg_type == $Net::DHCPv6::Packet::RELAY_REPLY
$msg_type == $Net::DHCPv6::Packet::RELAY_FORW
$msg_type == $Net::DHCPv6::Packet::RELAY_REPLY
Truth table100%3/3
A or B
A= $msg_type == $Net::DHCPv6::Packet::RELAY_FORWB= $msg_type == $Net::DHCPv6::Packet::RELAY_REPLY
| |||||||||||||||||||||||||||||
| 62 | 3 | return Net::DHCPv6::Packet::Relay->from_bytes( $bytes ); | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 64 | my $tid = unpack( 'N', "\x00" . substr( $bytes, 1, 3 ) ); | |||||||||||||||||||||||||||
| 66 | 64 | my $opts_bytes = substr( $bytes, 4 ); | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 64 | ▶ | my $subclass = $Net::DHCPv6::Packet::MESSAGE_CLASS{$msg_type} || $class; | ||||||||||||||||||||||||||
|
Condition66%2/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 table66%2/3
A || B
A= $Net::DHCPv6::Packet::MESSAGE_CLASS{$msg_type}B= $class
| |||||||||||||||||||||||||||||
| 69 | 64 | my $opts = Net::DHCPv6::OptionList->from_bytes( $opts_bytes ); | |||||||||||||||||||||||||||
| 70 | 64 | my $packet = bless { | |||||||||||||||||||||||||||
| 71 | msg_type => $msg_type, | ||||||||||||||||||||||||||||
| 72 | transaction_id => $tid, | ||||||||||||||||||||||||||||
| 73 | options => $opts, | ||||||||||||||||||||||||||||
| 74 | }, $subclass; | ||||||||||||||||||||||||||||
| 75 | 64 | return $packet; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | sub type { | ||||||||||||||||||||||||||||
| 79 | 8 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 80 | 8 | return $Net::DHCPv6::Constants::REV_MESSAGE_TYPE{ $self->{msg_type} }; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub msg_type_name { shift->type } | ||||||||||||||||||||||||||
|
Subroutine
msg_type_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 29 | our %MESSAGE_CLASS; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 29 | 1; | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | __END__ | ||||||||||||||||||||||||||||