| 1 | #!/bin/false | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Domain Search List option (code 24) -- RFC 1035 domain names | ||||||||||||||||||||||||||||
| 3 | # PODNAME: Net::DHCPv6::Option::DomainList | ||||||||||||||||||||||||||||
| 4 | 15 | ▶ | use strictures 2; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | package Net::DHCPv6::Option::DomainList; | ||||||||||||||||||||||||||||
| 7 | 15 | $Net::DHCPv6::Option::DomainList::VERSION = '0.003'; | |||||||||||||||||||||||||||
| 8 | 15 | ▶ | use Net::DHCPv6::OptionList (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 15 | ▶ | use Net::DHCPv6::Option (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 15 | ▶ | use Net::DHCPv6::Constants qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | $DN_COMPRESS_MASK $DN_LABEL_MASK $OPTION_DOMAIN_LIST | ||||||||||||||||||||||||||||
| 12 | 15 | ); | |||||||||||||||||||||||||||
| 13 | 15 | ▶ | use Net::DHCPv6::X::Truncated (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 15 | ▶ | use Net::DHCPv6::X::BadOption (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 15 | ▶ | use parent 'Net::DHCPv6::Option'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 15 | ▶ | use Ref::Util qw( is_plain_arrayref ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 15 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 15 | my $EMPTY = q(); | |||||||||||||||||||||||||||
| 19 | 15 | my $MAX_PTR_DEPTH = 255; ## no critic (ValuesAndExpressions::ProhibitMagicNumbers) | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 10 | ▶ | sub _encode_domain { | ||||||||||||||||||||||||||
|
Subroutine
_encode_domain: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||
| 22 | 10 | my ( $domain ) = @_; | |||||||||||||||||||||||||||
| 23 | 10 | ▶ | return chr( 0 ) unless defined $domain && CORE::length( $domain ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $domain and length $domain
MC/DC0%0/2
defined $domain and length $domain
defined $domain
length $domain
Truth table33%1/3
A and B
A= defined $domainB= length $domain
| |||||||||||||||||||||||||||||
| 24 | 10 | my @labels = split m/[.]/, $domain; | |||||||||||||||||||||||||||
| 25 | 10 | return join( $EMPTY, map { pack( 'C', CORE::length ) . $_ } @labels ) . chr( 0 ); | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 15 | ▶ | sub _read_labels_at { | ||||||||||||||||||||||||||
|
Subroutine
_read_labels_at: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||
| 29 | 15 | my ( $payload, $offset_ref, $len, $depth ) = @_; | |||||||||||||||||||||||||||
| 30 | 15 | ▶ | $depth //= 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
$depth //= 0
MC/DC100%1/1
$depth //= 0
$depth
Truth table100%2/2
A
A= $depth
| |||||||||||||||||||||||||||||
| 31 | 15 | my @labels; | |||||||||||||||||||||||||||
| 32 | 15 | ▶ | while ( ${$offset_ref} < $len ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 36 | my $llen = unpack( 'C', substr( $payload, ${$offset_ref}, 1 ) ); | |||||||||||||||||||||||||||
| 34 | 36 | ▶ | if ( $llen == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 9 | ++${$offset_ref}; | |||||||||||||||||||||||||||
| 36 | 9 | last; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | 27 | ▶ | if ( ( $llen & $DN_COMPRESS_MASK ) == $DN_COMPRESS_MASK ) { ## no critic (Bangs::ProhibitBitwiseOperators ValuesAndExpressions::ProhibitMagicNumbers) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 3 | ▶ | if ( $Net::DHCPv6::Option::FOLLOW_COMPRESSION ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | Net::DHCPv6::X::Truncated->throw( message => 'Truncated compression pointer' ) | ||||||||||||||||||||||||||||
| 41 | 2 | ▶ | if ${$offset_ref} + 2 > $len; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | my $ptr = | ||||||||||||||||||||||||||||
| 43 | 2 | ( ( $llen & $DN_LABEL_MASK ) << 8 ) | unpack( 'C', substr( $payload, ${$offset_ref} + 1, 1 ) ); ## no critic (Bangs::ProhibitBitwiseOperators ValuesAndExpressions::ProhibitMagicNumbers) | |||||||||||||||||||||||||||
| 44 | 2 | ▶ | Net::DHCPv6::X::BadOption->throw( message => 'Compression pointer out of range' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | if $ptr >= $len; | ||||||||||||||||||||||||||||
| 46 | 1 | ▶ | Net::DHCPv6::X::BadOption->throw( message => 'Compression pointer depth exceeded' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | if $depth > $MAX_PTR_DEPTH; | ||||||||||||||||||||||||||||
| 48 | 1 | ${$offset_ref} += 2; | |||||||||||||||||||||||||||
| 49 | 1 | my $ptr_ref = \$ptr; | |||||||||||||||||||||||||||
| 50 | 1 | push @labels, _read_labels_at( $payload, $ptr_ref, $len, $depth + 1 ); | |||||||||||||||||||||||||||
| 51 | 1 | last; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 1 | Net::DHCPv6::X::BadOption->throw( message => 'Compression pointer in domain name' ); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 24 | ▶ | Net::DHCPv6::X::BadOption->throw( message => 'Invalid domain label length' ) if $llen > $DN_LABEL_MASK; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 23 | ++${$offset_ref}; | |||||||||||||||||||||||||||
| 57 | Net::DHCPv6::X::Truncated->throw( message => 'Truncated domain label' ) | ||||||||||||||||||||||||||||
| 58 | 23 | ▶ | if ${$offset_ref} + $llen > $len; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 21 | push @labels, substr( $payload, ${$offset_ref}, $llen ); | |||||||||||||||||||||||||||
| 60 | 21 | ${$offset_ref} += $llen; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | 10 | return @labels; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 11 | ▶ | sub _decode_domains { | ||||||||||||||||||||||||||
|
Subroutine
_decode_domains: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 66 | 11 | my ( $payload ) = @_; | |||||||||||||||||||||||||||
| 67 | 11 | my @domain_list; | |||||||||||||||||||||||||||
| 68 | 11 | my $offset = 0; | |||||||||||||||||||||||||||
| 69 | 11 | my $len = CORE::length( $payload ); | |||||||||||||||||||||||||||
| 70 | 11 | ▶ | while ( $offset < $len ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 14 | my @labels = _read_labels_at( $payload, \$offset, $len ); | |||||||||||||||||||||||||||
| 72 | 9 | ▶ | push @domain_list, @labels ? join( q{.}, @labels ) : $EMPTY; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | 6 | return \@domain_list; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 8 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.4
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | 8 | my ( $class, %args ) = @_; | |||||||||||||||||||||||||||
| 79 | 8 | ▶ | my $domains = $args{domains} // $args{data} // []; | ||||||||||||||||||||||||||
|
Condition40%2/5
($args{"domains"} // $args{"data"}) // []
$args{"domains"} // $args{"data"}
MC/DC0%0/2
($args{"domains"} // $args{"data"}) // []
$args{"domains"}
$args{"data"}
Truth table33%1/3
A // B
A= $args{"domains"}B= $args{"data"}
| |||||||||||||||||||||||||||||
| 80 | 8 | ▶ | $domains = [$domains] unless is_plain_arrayref( $domains ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 8 | $args{code} = $OPTION_DOMAIN_LIST; | |||||||||||||||||||||||||||
| 82 | 8 | $args{data} = join( $EMPTY, map { _encode_domain( $_ ) } @{$domains} ); | |||||||||||||||||||||||||||
| 83 | 8 | my $self = $class->SUPER::new( %args ); | |||||||||||||||||||||||||||
| 84 | 8 | $self->{domains} = $domains; | |||||||||||||||||||||||||||
| 85 | 8 | return bless $self, $class; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 4 | ▶ | sub domains { return shift->{domains} } | ||||||||||||||||||||||||||
|
Subroutine
domains: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 11 | ▶ | sub from_bytes_inner { | ||||||||||||||||||||||||||
|
Subroutine
from_bytes_inner: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 91 | 11 | my ( $class, $code, $payload ) = @_; | |||||||||||||||||||||||||||
| 92 | 11 | my $domains = _decode_domains( $payload ); | |||||||||||||||||||||||||||
| 93 | 6 | return $class->new( domains => $domains ); | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 15 | $Net::DHCPv6::OptionList::OPTION_CLASS{$OPTION_DOMAIN_LIST} = __PACKAGE__; | |||||||||||||||||||||||||||
| 97 | 15 | 1; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | __END__ | ||||||||||||||||||||||||||||