From 10392fc08e657b3f7d7c2605a06a6c79260bf6f9 Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Fri, 2 Feb 2018 16:41:05 +0000 Subject: [PATCH] IPv6 Prefix Length support via IPv6::ipv6_addr_prefixlength --- Changes | 10 ++++++++++ lib/SNMP/Info/IPv6.pm | 45 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index eee95294..668794c5 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,13 @@ +version 3.42 (2018-02-02) + + [ENHANCEMENTS] + + * IPv6 Prefix Length support via IPv6::ipv6_addr_prefixlength + + [BUG FIXES] + + * Fix test for updated snmplabs.com data + version 3.41 (2018-02-01) [BUG FIXES] diff --git a/lib/SNMP/Info/IPv6.pm b/lib/SNMP/Info/IPv6.pm index ae946bb5..4f766f92 100644 --- a/lib/SNMP/Info/IPv6.pm +++ b/lib/SNMP/Info/IPv6.pm @@ -72,15 +72,18 @@ $VERSION = '3.41'; 'ip_pfx_origin' => 'ipAddressPrefixOrigin', # IP-MIB 'c_pfx_origin' => 'cIpAddressPfxOrigin', # CISCO-IETF-IP-MIB - 'ip_addr6_pfx' => 'ipAddressPrefix', # IP-MIB + 'ip_addr6_pfx' => 'ipAddressPrefix', # IP-MIB 'c_addr6_pfx' => 'cIpAddressPrefix', # CISCO-IETF-IP-MIB + 'ip_addr6_pfxlen' => 'ipAddressPrefixLength', # IP-MIB + 'c_addr6_pfxlen' => 'cIpAddressPfxLength', # CISCO-IETF-IP-MIB + 'i6_addr_pfxlen' => 'ipv6AddrPfxLength', # IPV6-MIB + 'ip_addr6_index' => 'ipAddressIfIndex', # IP-MIB 'c_addr6_index' => 'cIpAddressIfIndex', # CISCO-IETF-IP-MIB 'ip_addr6_type' => 'ipAddressType', # IP-MIB 'c_addr6_type' => 'cIpAddressType', # CISCO-IETF-IP-MIB - ); %MUNGE = ( @@ -329,6 +332,38 @@ sub ipv6_addr_prefix { return $return; } +sub ipv6_addr_prefixlength { + my $info = shift; + my $return; + my $index = $info->ipv6_index or return; + my $ipv6_addr_prefixlength = &_test_methods( $info, { + ip_addr6_pfxlen => IPMIB, + c_addr6_pfxlen => CISCO, + i6_addr_pfxlen => IPV6MIB, + }); + return unless defined $ipv6_addr_prefixlength; + # might be returned with ipv6_index value at the start instead + # of type+bits, so we need to map via ipv6_index + foreach my $row (keys %$ipv6_addr_prefixlength){ + my $new_row = undef; + # only if ipv6_index value at the start + if ($row =~ m/^(\d+)\.((?:\d+\.){15}\d+)/) { + my ($iid, $addr) = ($1, $2); + foreach my $i (keys %$index) { + if ($index->{$i} eq $iid and $i =~ m/\.${addr}$/) { + $new_row = $i; + last; + } + } + next unless $new_row; + } + # this should alow IPMIB and CISCO to pass through unmunged + $return->{$new_row || $row} = $ipv6_addr_prefixlength->{$row}; + } + printf("%s: data comes from %s.\n", &_my_sub_name, $info->_method_used() ) if $info->debug(); + return $return; +} + sub ipv6_addr { my $info = shift; my $return; @@ -355,6 +390,7 @@ sub ipv6_addr { sub _method_used { my $info = shift; my $return = 'none of the MIBs'; + # FIXME ugh! a global. makes order of calls important for debug. if (defined $info::METHOD) { if ($info::METHOD eq IPMIB) { $return = 'IP-MIB'; @@ -374,6 +410,7 @@ sub _test_methods { foreach my $method (sort {$test->{$a} <=> $test->{$b}} keys %$test) { $return = $info->$method || {}; if (scalar keys %$return) { + # FIXME ugh! a global. makes order of calls important for debug. $info::METHOD = $test->{$method}; last; } @@ -490,6 +527,10 @@ Maps an IPv6 prefix with its origin (manual, well-known, dhcp, etc.) Maps IPv6 addresses with their prefixes +=item $info->ipv6_addr_prefixlength() + +Maps IPv6 addresses with their prefix length + =item $info->ipv6_addr() Maps a table instance to an IPv6 address