From 9fca5b1e4266ddd68c93be0e00651197a712407b Mon Sep 17 00:00:00 2001 From: "Eric A. Miller" Date: Tue, 1 May 2018 23:01:56 -0400 Subject: [PATCH] Change _lldp_addr_index to a method so it can be properly overridden in subclasses --- Changes | 2 ++ lib/SNMP/Info/LLDP.pm | 10 ++++++---- lib/SNMP/Info/Layer3/Timetra.pm | 7 +++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Changes b/Changes index 97d29fc5..fece5e91 100644 --- a/Changes +++ b/Changes @@ -7,6 +7,8 @@ Version 3.59 [ENHANCEMENTS] * Capture base MAC in L3::Huawei + * Change _lldp_addr_index to a method so it can be properly overridden in + subclasses [BUG FIXES] diff --git a/lib/SNMP/Info/LLDP.pm b/lib/SNMP/Info/LLDP.pm index 9e2a410b..35a39b75 100644 --- a/lib/SNMP/Info/LLDP.pm +++ b/lib/SNMP/Info/LLDP.pm @@ -165,7 +165,7 @@ sub lldp_ip { my %lldp_ip; foreach my $key ( keys %$rman_addr ) { - my ( $index, $proto, $addr ) = _lldp_addr_index($key); + my ( $index, $proto, $addr ) = $lldp->_lldp_addr_index($key); next unless defined $index; next unless $proto == 1; $lldp_ip{$index} = $addr; @@ -181,7 +181,7 @@ sub lldp_ipv6 { my %lldp_ipv6; foreach my $key ( keys %$rman_addr ) { - my ( $index, $proto, $addr ) = _lldp_addr_index($key); + my ( $index, $proto, $addr ) = $lldp->_lldp_addr_index($key); next unless defined $index; next unless $proto == 2; $lldp_ipv6{$index} = $addr; @@ -197,7 +197,7 @@ sub lldp_mac { my %lldp_ipv6; foreach my $key ( keys %$rman_addr ) { - my ( $index, $proto, $addr ) = _lldp_addr_index($key); + my ( $index, $proto, $addr ) = $lldp->_lldp_addr_index($key); next unless defined $index; next unless $proto == 6; $lldp_ipv6{$index} = $addr; @@ -213,7 +213,7 @@ sub lldp_addr { my %lldp_ip; foreach my $key ( keys %$rman_addr ) { - my ( $index, $proto, $addr ) = _lldp_addr_index($key); + my ( $index, $proto, $addr ) = $lldp->_lldp_addr_index($key); next unless defined $index; $lldp_ip{$index} = $addr; } @@ -401,7 +401,9 @@ sub lldp_media_cap { # Break up the lldpRemManAddrTable INDEX into common index, protocol, # and address. sub _lldp_addr_index { + my $lldp = shift; my $idx = shift; + my @oids = split( /\./, $idx ); my $index = join( '.', splice( @oids, 0, 3 ) ); my $proto = shift(@oids); diff --git a/lib/SNMP/Info/Layer3/Timetra.pm b/lib/SNMP/Info/Layer3/Timetra.pm index fbee629e..2f3c20fb 100644 --- a/lib/SNMP/Info/Layer3/Timetra.pm +++ b/lib/SNMP/Info/Layer3/Timetra.pm @@ -185,12 +185,11 @@ sub lldp_if { # The proprietary TIMETRA-LLDP-MIB tables are indexed differently than LLDP-MIB # We overwrite the private function so that the we don't have to replicate # the code in SNMP::Info::LLDP that uses it. -# -# We can't use inheritance to override since it is a function, not a method -# in SNMP::Info::LLDP. This brute force redefines the code in the symbol table. -*SNMP::Info::LLDP::_lldp_addr_index = sub { +sub _lldp_addr_index { + my $alu = shift; my $idx = shift; + my @oids = split( /\./, $idx ); # Index has extra field compared to LLDP-MIB