| 1 | #!/usr/bin/false | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: DUID parse/emit and helper constructors | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # PODNAME: Net::DHCPv6::DUID | ||||||||||||||||||||||||||||||||||||||||||
| 4 | package Net::DHCPv6::DUID; | ||||||||||||||||||||||||||||||||||||||||||
| 5 | 17 | $Net::DHCPv6::DUID::VERSION = '0.001'; | |||||||||||||||||||||||||||||||||||||||||
| 6 | 17 | ▶ | use strictures 2; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 17 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 17 | ▶ | use Net::DHCPv6::Constants; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 17 | ▶ | use Net::DHCPv6::X::BadDUID; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 17 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 13 | 14 | ▶ | my ( $class, %args ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=16 SCAR=29.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 14 | ▶ | my $type = $args{duid_type} // croak 'Net::DHCPv6::DUID->new: duid_type is required'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$args{"duid_type"} // croak("Net::DHCPv6::DUID->new: duid_type is required")
MC/DC0%0/2
$args{"duid_type"} // croak("Net::DHCPv6::DUID->new: duid_type is required")
$args{"duid_type"}
croak("Net::DHCPv6::DUID->new: duid_type is required")
Truth table33%1/3
A // B
A= $args{"duid_type"}B= croak("Net::DHCPv6::DUID->new: duid_type is required")
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 13 | my $self = { duid_type => $type }; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 13 | ▶ | if ( $type == $DUID_LLT ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | croak 'DUID-LLT requires link_layer_type, time, and identifier' | ||||||||||||||||||||||||||||||||||||||||||
| 20 | unless defined $args{link_layer_type} | ||||||||||||||||||||||||||||||||||||||||||
| 21 | && defined $args{time} | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 8 | ▶ | && defined $args{identifier}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $args{"link_layer_type"} and defined $args{"time"} and defined $args{"identifier"}
defined $args{"link_layer_type"} and defined $args{"time"}
MC/DC33%1/3
defined $args{"link_layer_type"} and defined $args{"time"} and defined $args{"identifier"}
defined $args{"link_layer_type"}
defined $args{"time"}
defined $args{"identifier"}
Truth table50%2/4
A and B and C
A= defined $args{"link_layer_type"}B= defined $args{"time"}C= defined $args{"identifier"}
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 7 | $self->{link_layer_type} = $args{link_layer_type}; | |||||||||||||||||||||||||||||||||||||||||
| 24 | 7 | $self->{time} = $args{time}; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 7 | $self->{identifier} = $args{identifier}; | |||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | elsif ( $type == $DUID_EN ) { | ||||||||||||||||||||||||||||||||||||||||||
| 28 | croak 'DUID-EN requires enterprise_number and identifier' | ||||||||||||||||||||||||||||||||||||||||||
| 29 | unless defined $args{enterprise_number} | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | && defined $args{identifier}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $args{"enterprise_number"} and defined $args{"identifier"}
MC/DC0%0/2
defined $args{"enterprise_number"} and defined $args{"identifier"}
defined $args{"enterprise_number"}
defined $args{"identifier"}
Truth table33%1/3
A and B
A= defined $args{"enterprise_number"}B= defined $args{"identifier"}
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | $self->{enterprise_number} = $args{enterprise_number}; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | $self->{identifier} = $args{identifier}; | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | elsif ( $type == $DUID_LL ) { | ||||||||||||||||||||||||||||||||||||||||||
| 35 | croak 'DUID-LL requires link_layer_type and identifier' | ||||||||||||||||||||||||||||||||||||||||||
| 36 | unless defined $args{link_layer_type} | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | && defined $args{identifier}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $args{"link_layer_type"} and defined $args{"identifier"}
MC/DC0%0/2
defined $args{"link_layer_type"} and defined $args{"identifier"}
defined $args{"link_layer_type"}
defined $args{"identifier"}
Truth table33%1/3
A and B
A= defined $args{"link_layer_type"}B= defined $args{"identifier"}
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | $self->{link_layer_type} = $args{link_layer_type}; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | $self->{identifier} = $args{identifier}; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | elsif ( $type == $DUID_UUID ) { | ||||||||||||||||||||||||||||||||||||||||||
| 42 | croak 'DUID-UUID requires identifier (16 bytes)' | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 2 | ▶ | unless defined $args{identifier}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | croak 'DUID-UUID identifier must be 16 bytes' | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | ▶ | unless CORE::length( $args{identifier} ) == 16; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | $self->{identifier} = $args{identifier}; | |||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | ▶ | $self->{identifier} = $args{identifier} // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{"identifier"} // ""
MC/DC0%0/1
$args{"identifier"} // ""
$args{"identifier"}
Truth table50%1/2
A
A= $args{"identifier"}
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 11 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 26 | ▶ | sub duid_type { shift->{duid_type} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
duid_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 12 | ▶ | sub link_layer_type { shift->{link_layer_type} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
link_layer_type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 15 | ▶ | sub time { shift->{time} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
time: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 3 | ▶ | sub enterprise_number { shift->{enterprise_number} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
enterprise_number: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 16 | ▶ | sub identifier { shift->{identifier} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
identifier: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | sub length { | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
length: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | my $type = $self->{duid_type}; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | my $id = $self->{identifier} // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"identifier"} // ""
MC/DC0%0/1
$self->{"identifier"} // ""
$self->{"identifier"}
Truth table0%0/2
A
A= $self->{"identifier"}
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if ( $type == $DUID_LLT ) { return 2 + 2 + 4 + CORE::length( $id ); } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | elsif ( $type == $DUID_EN ) { return 2 + 4 + CORE::length( $id ); } | |||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | elsif ( $type == $DUID_LL ) { return 2 + 2 + CORE::length( $id ); } | |||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | elsif ( $type == $DUID_UUID ) { return 2 + CORE::length( $id ); } | |||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | else { return 2 + CORE::length( $id ); } | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | sub as_bytes { | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 133 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_bytes: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 133 | my $type = $self->{duid_type}; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 133 | ▶ | my $id = $self->{identifier} // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"identifier"} // ""
MC/DC0%0/1
$self->{"identifier"} // ""
$self->{"identifier"}
Truth table50%1/2
A
A= $self->{"identifier"}
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 133 | my $buf = pack( 'n', $type ); | |||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 133 | ▶ | if ( $type == $DUID_LLT ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 97 | $buf .= pack( 'n', $self->{link_layer_type} ); | |||||||||||||||||||||||||||||||||||||||||
| 80 | 97 | $buf .= pack( 'N', $self->{time} ); | |||||||||||||||||||||||||||||||||||||||||
| 81 | 97 | $buf .= $id; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | elsif ( $type == $DUID_EN ) { | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 9 | $buf .= pack( 'N', $self->{enterprise_number} ); | |||||||||||||||||||||||||||||||||||||||||
| 85 | 9 | $buf .= $id; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | elsif ( $type == $DUID_LL ) { | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 25 | $buf .= pack( 'n', $self->{link_layer_type} ); | |||||||||||||||||||||||||||||||||||||||||
| 89 | 25 | $buf .= $id; | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | elsif ( $type == $DUID_UUID ) { | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | $buf .= $id; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | $buf .= $id; | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 133 | return $buf; | |||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | sub as_string { | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | my $bytes = $self->as_bytes; | |||||||||||||||||||||||||||||||||||||||||
| 104 | my $tname = $Net::DHCPv6::Constants::REV_DUID_TYPE{ $self->{duid_type} } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | ▶ | || sprintf( 'TYPE%d', $self->{duid_type} ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$Net::DHCPv6::Constants::REV_DUID_TYPE{$self->{'duid_type'}} || sprintf('TYPE%d', $self->{'duid_type'})
MC/DC0%0/2
$Net::DHCPv6::Constants::REV_DUID_TYPE{$self->{'duid_type'}} || sprintf('TYPE%d', $self->{'duid_type'})
$Net::DHCPv6::Constants::REV_DUID_TYPE{$self->{'duid_type'}}
sprintf('TYPE%d', $self->{'duid_type'})
Truth table33%1/3
A || B
A= $Net::DHCPv6::Constants::REV_DUID_TYPE{$self->{'duid_type'}}B= sprintf('TYPE%d', $self->{'duid_type'})
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | return sprintf( '%s:%s', $tname, unpack( 'H*', $bytes ) ); | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | sub try_from_bytes { | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 126 | ▶ | my ( $class, $bytes ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
try_from_bytes: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 126 | ▶ | return ( undef, 'No data provided' ) unless defined $bytes; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 125 | my $len = CORE::length( $bytes ); | |||||||||||||||||||||||||||||||||||||||||
| 114 | 125 | ▶ | return ( undef, 'Need at least 2 bytes for DUID type' ) if $len < 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 122 | my $type = unpack( 'n', substr( $bytes, 0, 2 ) ); | |||||||||||||||||||||||||||||||||||||||||
| 117 | 122 | my $rest = substr( $bytes, 2 ); | |||||||||||||||||||||||||||||||||||||||||
| 118 | 122 | my $rest_len = CORE::length( $rest ); | |||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 122 | ▶ | if ( $type == $DUID_LLT ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 84 | my $partial = bless( { duid_type => $DUID_LLT }, $class ); | |||||||||||||||||||||||||||||||||||||||||
| 122 | 84 | my $error; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 84 | ▶ | if ( $rest_len >= 2 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 82 | $partial->{link_layer_type} = unpack( 'n', $rest ); | |||||||||||||||||||||||||||||||||||||||||
| 125 | 82 | ▶ | if ( $rest_len >= 6 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 79 | $partial->{time} = unpack( 'x2 N', $rest ); | |||||||||||||||||||||||||||||||||||||||||
| 127 | 79 | $partial->{identifier} = substr( $rest, 6 ); | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 3 | $error = "Need 6 bytes for DUID-LLT hwtype+time, got $rest_len"; | |||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 2 | $error = "Need at least 2 bytes for DUID-LLT hwtype, got $rest_len"; | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 84 | return ( $partial, $error ); | |||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | elsif ( $type == $DUID_EN ) { | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 10 | my $partial = bless( { duid_type => $DUID_EN }, $class ); | |||||||||||||||||||||||||||||||||||||||||
| 140 | 10 | my $error; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 10 | ▶ | if ( $rest_len >= 4 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 9 | $partial->{enterprise_number} = unpack( 'N', $rest ); | |||||||||||||||||||||||||||||||||||||||||
| 143 | 9 | $partial->{identifier} = substr( $rest, 4 ); | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | $error = "Need 4 bytes for DUID-EN enterprise_number, got $rest_len"; | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 10 | return ( $partial, $error ); | |||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | elsif ( $type == $DUID_LL ) { | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 25 | my $partial = bless( { duid_type => $DUID_LL }, $class ); | |||||||||||||||||||||||||||||||||||||||||
| 152 | 25 | my $error; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 25 | ▶ | if ( $rest_len >= 2 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 25 | $partial->{link_layer_type} = unpack( 'n', $rest ); | |||||||||||||||||||||||||||||||||||||||||
| 155 | 25 | $partial->{identifier} = substr( $rest, 2 ); | |||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | $error = "Need at least 2 bytes for DUID-LL hwtype, got $rest_len"; | |||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 25 | return ( $partial, $error ); | |||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | elsif ( $type == $DUID_UUID ) { | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 2 | my $partial = bless( { duid_type => $DUID_UUID }, $class ); | |||||||||||||||||||||||||||||||||||||||||
| 164 | 2 | my $error; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 2 | ▶ | if ( $rest_len >= 16 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 1 | $partial->{identifier} = substr( $rest, 0, 16 ); | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 1 | $error = "Need 16 bytes for DUID-UUID, got $rest_len"; | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 2 | return ( $partial, $error ); | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 174 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 1 | bless( | |||||||||||||||||||||||||||||||||||||||||
| 176 | { | ||||||||||||||||||||||||||||||||||||||||||
| 177 | duid_type => $type, | ||||||||||||||||||||||||||||||||||||||||||
| 178 | identifier => $rest, | ||||||||||||||||||||||||||||||||||||||||||
| 179 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 180 | $class | ||||||||||||||||||||||||||||||||||||||||||
| 181 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 182 | undef | ||||||||||||||||||||||||||||||||||||||||||
| 183 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | sub from_bytes { | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 114 | ▶ | my ( $class, $bytes ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_bytes: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 189 | 114 | my ( $duid, $error ) = $class->try_from_bytes( $bytes ); | |||||||||||||||||||||||||||||||||||||||||
| 190 | 114 | ▶ | Net::DHCPv6::X::BadDUID->throw( message => $error ) if $error; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 112 | return $duid; | |||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | sub new_llt { | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 7 | ▶ | my ( $class, $link_layer_type, $time, $mac_bytes ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_llt: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 7 | return $class->new( | |||||||||||||||||||||||||||||||||||||||||
| 197 | duid_type => $DUID_LLT, | ||||||||||||||||||||||||||||||||||||||||||
| 198 | link_layer_type => $link_layer_type, | ||||||||||||||||||||||||||||||||||||||||||
| 199 | time => $time, | ||||||||||||||||||||||||||||||||||||||||||
| 200 | identifier => $mac_bytes, | ||||||||||||||||||||||||||||||||||||||||||
| 201 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | sub new_en { | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 1 | ▶ | my ( $class, $enterprise_number, $identifier ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_en: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 1 | return $class->new( | |||||||||||||||||||||||||||||||||||||||||
| 207 | duid_type => $DUID_EN, | ||||||||||||||||||||||||||||||||||||||||||
| 208 | enterprise_number => $enterprise_number, | ||||||||||||||||||||||||||||||||||||||||||
| 209 | identifier => $identifier, | ||||||||||||||||||||||||||||||||||||||||||
| 210 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | sub new_ll { | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 1 | ▶ | my ( $class, $link_layer_type, $mac_bytes ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_ll: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 1 | return $class->new( | |||||||||||||||||||||||||||||||||||||||||
| 216 | duid_type => $DUID_LL, | ||||||||||||||||||||||||||||||||||||||||||
| 217 | link_layer_type => $link_layer_type, | ||||||||||||||||||||||||||||||||||||||||||
| 218 | identifier => $mac_bytes, | ||||||||||||||||||||||||||||||||||||||||||
| 219 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | sub new_uuid { | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 2 | ▶ | my ( $class, $uuid_bytes ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_uuid: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 2 | return $class->new( | |||||||||||||||||||||||||||||||||||||||||
| 225 | duid_type => $DUID_UUID, | ||||||||||||||||||||||||||||||||||||||||||
| 226 | identifier => $uuid_bytes, | ||||||||||||||||||||||||||||||||||||||||||
| 227 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 17 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | __END__ | ||||||||||||||||||||||||||||||||||||||||||