| 1 | #!/bin/false | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: NIS Domain Name option (code 29) -- RFC 1035 domain name | ||||||||||||||||||||||||||||
| 3 | # PODNAME: Net::DHCPv6::Option::NisDomainName | ||||||||||||||||||||||||||||
| 4 | 15 | ▶ | use strictures 2; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | package Net::DHCPv6::Option::NisDomainName; | ||||||||||||||||||||||||||||
| 7 | 15 | $Net::DHCPv6::Option::NisDomainName::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 Carp qw( croak ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 15 | ▶ | use Net::DHCPv6::Constants qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | $DN_COMPRESS_MASK $DN_LABEL_MASK $OPTION_NIS_DOMAIN_NAME | ||||||||||||||||||||||||||||
| 13 | 15 | ); | |||||||||||||||||||||||||||
| 14 | 15 | ▶ | use Net::DHCPv6::X::Truncated (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 15 | ▶ | use Net::DHCPv6::X::BadOption (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 15 | ▶ | use parent 'Net::DHCPv6::Option'; | ||||||||||||||||||||||||||
|
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 | 2 | ▶ | sub _encode_domain { | ||||||||||||||||||||||||||
|
Subroutine
_encode_domain: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||
| 22 | 2 | my ( $domain ) = @_; | |||||||||||||||||||||||||||
| 23 | 2 | ▶ | 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 | 2 | my @labels = split m/[.]/, $domain; | |||||||||||||||||||||||||||
| 25 | 2 | return join( $EMPTY, map { pack( 'C', CORE::length ) . $_ } @labels ) . chr( 0 ); | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 1 | ▶ | sub _read_labels_at { | ||||||||||||||||||||||||||
|
Subroutine
_read_labels_at: called CC=11 SCAR=31.7
| |||||||||||||||||||||||||||||
| 29 | 1 | my ( $payload, $offset_ref, $len, $depth ) = @_; | |||||||||||||||||||||||||||
| 30 | 1 | ▶ | $depth //= 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$depth //= 0
MC/DC0%0/1
$depth //= 0
$depth
Truth table50%1/2
A
A= $depth
| |||||||||||||||||||||||||||||
| 31 | 1 | my @labels; | |||||||||||||||||||||||||||
| 32 | 1 | ▶ | while ( ${$offset_ref} < $len ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | 4 | my $llen = unpack( 'C', substr( $payload, ${$offset_ref}, 1 ) ); | |||||||||||||||||||||||||||
| 34 | 4 | ▶ | if ( $llen == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 1 | ++${$offset_ref}; | |||||||||||||||||||||||||||
| 36 | 1 | last; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | 3 | ▶ | if ( ( $llen & $DN_COMPRESS_MASK ) == $DN_COMPRESS_MASK ) { ## no critic (Bangs::ProhibitBitwiseOperators ValuesAndExpressions::ProhibitMagicNumbers) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | if ( $Net::DHCPv6::Option::FOLLOW_COMPRESSION ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | Net::DHCPv6::X::Truncated->throw( message => 'Truncated compression pointer' ) | ||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if ${$offset_ref} + 2 > $len; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | my $ptr = | ||||||||||||||||||||||||||||
| 43 | 0 | ( ( $llen & $DN_LABEL_MASK ) << 8 ) | unpack( 'C', substr( $payload, ${$offset_ref} + 1, 1 ) ); ## no critic (Bangs::ProhibitBitwiseOperators ValuesAndExpressions::ProhibitMagicNumbers) | |||||||||||||||||||||||||||
| 44 | 0 | ▶ | Net::DHCPv6::X::BadOption->throw( message => 'Compression pointer out of range' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | if $ptr >= $len; | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | Net::DHCPv6::X::BadOption->throw( message => 'Compression pointer depth exceeded' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | if $depth > $MAX_PTR_DEPTH; | ||||||||||||||||||||||||||||
| 48 | 0 | ${$offset_ref} += 2; | |||||||||||||||||||||||||||
| 49 | 0 | my $ptr_ref = \$ptr; | |||||||||||||||||||||||||||
| 50 | 0 | push @labels, _read_labels_at( $payload, $ptr_ref, $len, $depth + 1 ); | |||||||||||||||||||||||||||
| 51 | 0 | last; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 0 | Net::DHCPv6::X::BadOption->throw( message => 'Compression pointer in domain name' ); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 3 | ▶ | Net::DHCPv6::X::BadOption->throw( message => 'Invalid domain label length' ) if $llen > $DN_LABEL_MASK; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 3 | ++${$offset_ref}; | |||||||||||||||||||||||||||
| 57 | Net::DHCPv6::X::Truncated->throw( message => 'Truncated domain label' ) | ||||||||||||||||||||||||||||
| 58 | 3 | ▶ | if ${$offset_ref} + $llen > $len; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 3 | push @labels, substr( $payload, ${$offset_ref}, $llen ); | |||||||||||||||||||||||||||
| 60 | 3 | ${$offset_ref} += $llen; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | 1 | return @labels; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 1 | ▶ | sub _decode_domain { | ||||||||||||||||||||||||||
|
Subroutine
_decode_domain: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 66 | 1 | my ( $payload ) = @_; | |||||||||||||||||||||||||||
| 67 | 1 | ▶ | return $EMPTY unless CORE::length( $payload ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 1 | my $offset = 0; | |||||||||||||||||||||||||||
| 69 | 1 | my @labels = _read_labels_at( $payload, \$offset, CORE::length( $payload ) ); | |||||||||||||||||||||||||||
| 70 | 1 | return join( q{.}, @labels ); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 74 | 3 | my ( $class, %args ) = @_; | |||||||||||||||||||||||||||
| 75 | 3 | ▶ | croak 'NisDomainName requires domain_name' unless defined $args{domain_name}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 2 | $args{code} = $OPTION_NIS_DOMAIN_NAME; | |||||||||||||||||||||||||||
| 77 | 2 | $args{data} = _encode_domain( $args{domain_name} ); | |||||||||||||||||||||||||||
| 78 | 2 | my $self = $class->SUPER::new( %args ); | |||||||||||||||||||||||||||
| 79 | 2 | $self->{domain_name} = $args{domain_name}; | |||||||||||||||||||||||||||
| 80 | 2 | return bless $self, $class; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 2 | ▶ | sub domain_name { return shift->{domain_name} } | ||||||||||||||||||||||||||
|
Subroutine
domain_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 1 | ▶ | sub from_bytes_inner { | ||||||||||||||||||||||||||
|
Subroutine
from_bytes_inner: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | 1 | my ( $class, $code, $payload ) = @_; | |||||||||||||||||||||||||||
| 87 | 1 | my $name = _decode_domain( $payload ); | |||||||||||||||||||||||||||
| 88 | 1 | return $class->new( domain_name => $name ); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 15 | $Net::DHCPv6::OptionList::OPTION_CLASS{$OPTION_NIS_DOMAIN_NAME} = __PACKAGE__; | |||||||||||||||||||||||||||
| 92 | 15 | 1; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | __END__ | ||||||||||||||||||||||||||||