diff --git a/htdocs/management/ip.html b/htdocs/management/ip.html index 8cd9951ee..0ef169334 100644 --- a/htdocs/management/ip.html +++ b/htdocs/management/ip.html @@ -102,16 +102,15 @@ $BLOCK_VIEW_MAX = Netdot->config->get('CONTAINER_BLOCK_VIEW_MAX_PREFIX'); } if ( $o->version == 4 ){ - $dns_address_record_label = 'A'; if ( $view_format eq 'block' ){ if ( $BLOCK_VIEW_MAX && ($o->prefix < $BLOCK_VIEW_MAX) ){ $view_format = 'list'; } } }elsif ( $o->version == 6 ){ - $dns_address_record_label = 'AAAA'; $view_format = 'list' if $view_format eq 'block'; } + $dns_address_record_label = $o->dns_address_record_label; }else{ $title = "Search"; @@ -337,6 +336,7 @@ $id = $block->id; if( $o->is_address ) { $added_ip = 1; + $dns_address_record_label = $o->dns_address_record_label; }else { $added_block = 1; } diff --git a/lib/Netdot/Model/Ipblock.pm b/lib/Netdot/Model/Ipblock.pm index ac2649d94..afe8cd0b1 100644 --- a/lib/Netdot/Model/Ipblock.pm +++ b/lib/Netdot/Model/Ipblock.pm @@ -1568,6 +1568,37 @@ sub is_address { ################################################################## +=head2 dns_address_record_label - A or AAAA + + DNS address records have different labels for IPv4 or IPv6. Return the + correct label depending on the version of this object. + + Arguments: + None + Returns: + 'A' for IPv4 + 'AAAA' for IPv6 + undef for anything else + +=cut + +sub dns_address_record_label { + my $self = shift; + $self->isa_object_method('dns_address_record_label'); + + if ($self->version == 4) { + return 'A'; + } + elsif ($self->version == 6) { + return 'AAAA'; + } + else { + return undef; + } +} + +################################################################## + =head2 update - Update an Ipblock object in DB Modify given fields of an Ipblock and (optionally) all its descendants. diff --git a/t/Ipblock.t b/t/Ipblock.t index 056fbfb53..f9d4abea2 100644 --- a/t/Ipblock.t +++ b/t/Ipblock.t @@ -37,6 +37,8 @@ is($address->status->name, 'Static', 'insert address'); is($address->is_address, 1, 'is_address'); +is($address->dns_address_record_label, 'A', 'DNS IPv4 address record label'); + is($address->parent, $subnet, 'address/subnet hierarchy'); is($subnet->parent, $container, 'subnet/container hierarchy'); @@ -155,6 +157,14 @@ my $v6subnet = Ipblock->insert({ status => 'Subnet', }); +my $v6address = Ipblock->insert({ + address => "2001:db8::beef:cafe", + prefix => '128', + version => 6, + status => 'Static', +}); +is($v6address->dns_address_record_label, 'AAAA', 'DNS IPv6 address record label'); + is($v6subnet->parent, $v6container, 'v6_parent'); is(($v6subnet->get_dot_arpa_names)[0], '0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa',