Add extra check in LLDP local interface determination to improve H3C support

This commit is contained in:
Jeroen van Ingen
2012-12-17 16:15:32 +01:00
parent badfb12243
commit 3741010044

View File

@@ -99,20 +99,26 @@ sub lldp_if {
my $addr = $lldp->lldp_rem_pid($partial) || {};
my $i_descr = $lldp->i_description() || {};
my $i_alias = $lldp->i_alias() || {};
my %r_i_descr = reverse %$i_descr;
my %r_i_alias = reverse %$i_alias;
my %lldp_if;
foreach my $key ( keys %$addr ) {
my @aOID = split( '\.', $key );
my $port = $aOID[1];
next unless $port;
# Local LLDP port may not equate to ifIndex
# Cross reference lldpLocPortDesc with ifDescr to get ifIndex
# Local LLDP port may not equate to ifIndex, see LldpPortNumber TEXTUAL-CONVENTION in LLDP-MIB.
# Cross reference lldpLocPortDesc with ifDescr and ifAlias to get ifIndex,
# prefer ifDescr over ifAlias because using cross ref with description is correct behavior
# according to the LLDP-MIB. Some devices (eg H3C gear) seem to use ifAlias though.
my $lldp_desc = $lldp->lldpLocPortDesc($port);
my $desc = $lldp_desc->{$port};
# If cross reference is successful use it, otherwise stick with lldpRemLocalPortNum
if ( exists $r_i_descr{$desc} ) {
$port = $r_i_descr{$desc};
} elsif ( exists $r_i_alias{$desc} ) {
$port = $r_i_alias{$desc};
}
$lldp_if{$key} = $port;
@@ -411,9 +417,9 @@ with the remote system.
=item $lldp->lldp_if()
Returns the mapping to the SNMP Interface Table. Trys to cross reference
(C<lldpLocPortDesc>) with (C<ifDescr>) to get (C<ifIndex>), if unable
defaults to (C<lldpRemLocalPortNum>).
Returns the mapping to the SNMP Interface Table. Triess to cross reference
(C<lldpLocPortDesc>) with (C<ifDescr>) and (C<ifAlias>) to get (C<ifIndex>),
if unable defaults to (C<lldpRemLocalPortNum>).
=item $lldp->lldp_ip()