Skip to content

Commit 1ca4a77

Browse files
committed
fix: Fix switch known macaddresses analysis
1 parent d5ed8e5 commit 1ca4a77

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

Changes

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ netdiscovery/netinventory:
2929
* PR #836 from @eduardomozart: Enhanced HP wireless printers by reporting wifi ports
3030
as wireless
3131
* Fix network ports ip support to avoid wrong allocation in rare cases, seen on a Ricoh printer
32+
* Fix switch known macaddresses analysis
3233

3334
deploy:
3435
* fix #854: Deploy task was not run when forced via httpd interface

lib/GLPI/Agent/Tools/Hardware.pm

+27-8
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,9 @@ sub _setKnownMacAddresses {
863863
# start with mac addresses seen on default VLAN
864864
my $addresses = _getKnownMacAddresses(
865865
snmp => $snmp,
866+
macaddresses => '.1.3.6.1.2.1.17.4.3.1.1', # dot1dTpFdbAddress
866867
address2port => '.1.3.6.1.2.1.17.4.3.1.2', # dot1dTpFdbPort
868+
macstatus => '.1.3.6.1.2.1.17.4.3.1.3', # dot1dTpFdbStatus
867869
port2interface => '.1.3.6.1.2.1.17.1.4.1.2', # dot1dBasePortIfIndex
868870
);
869871

@@ -878,7 +880,9 @@ sub _setKnownMacAddresses {
878880
# add additional mac addresses for other VLANs
879881
$addresses = _getKnownMacAddresses(
880882
snmp => $snmp,
883+
macaddresses => '.1.3.6.1.2.1.17.7.1.2.2.1.1', # dot1qTpFdbAddress
881884
address2port => '.1.3.6.1.2.1.17.7.1.2.2.1.2', # dot1qTpFdbPort
885+
macstatus => '.1.3.6.1.2.1.17.7.1.2.2.1.3', # dot1qTpFdbStatus
882886
port2interface => '.1.3.6.1.2.1.17.1.4.1.2', # dot1dBasePortIfIndex
883887
);
884888

@@ -912,7 +916,9 @@ sub _setKnownMacAddresses {
912916
$snmp->switch_vlan_context($vlan);
913917
my $mac_addresses = _getKnownMacAddresses(
914918
snmp => $snmp,
919+
macaddresses => '.1.3.6.1.2.1.17.4.3.1.1', # dot1dTpFdbAddress
915920
address2port => '.1.3.6.1.2.1.17.4.3.1.2', # dot1dTpFdbPort
921+
macstatus => '.1.3.6.1.2.1.17.4.3.1.3', # dot1dTpFdbStatus
916922
port2interface => '.1.3.6.1.2.1.17.1.4.1.2', # dot1dBasePortIfIndex
917923
);
918924
next unless $mac_addresses;
@@ -994,27 +1000,40 @@ sub _getKnownMacAddresses {
9941000
my $snmp = $params{snmp};
9951001

9961002
my $results;
1003+
my $macaddresses = $params{macaddresses} ? $snmp->walk($params{macaddresses}) : {};
9971004
my $address2port = $snmp->walk($params{address2port});
9981005
my $port2interface = $snmp->walk($params{port2interface});
1006+
my $macstatus = $params{macstatus} ? $snmp->walk($params{macstatus}) : {};
9991007

1000-
# dot1dTpFdbPort values matches the following scheme:
1001-
# $prefix.a.b.c.d.e.f = $port
1008+
# dot1dTpFdbAddress is the known mac addresses table
1009+
# dot1dTpFdbStatus is the mac addresses status table, only learned(3) ones should be kept
10021010

1003-
# dot1qTpFdbPort values matches the following scheme:
1011+
# dot1dTpFdbPort values may match one of the following scheme:
1012+
# $prefix.a.b.c.d.e.f = $port
10041013
# $prefix.$vlan.a.b.c.d.e.f = $port
10051014

10061015
# in both case, the last 6 elements of the OID constitutes
10071016
# the mac address in decimal format
1017+
10081018
foreach my $suffix (sort keys %{$address2port}) {
10091019
my $port_id = $address2port->{$suffix};
10101020
my $interface_id = $port2interface->{$port_id};
10111021
next unless defined $interface_id;
10121022

1013-
my @bytes = split(/\./, $suffix);
1014-
shift @bytes while @bytes > 6;
1015-
1016-
push @{$results->{$interface_id}},
1017-
sprintf "%02x:%02x:%02x:%02x:%02x:%02x", @bytes;
1023+
if ($macaddresses && $macaddresses->{$suffix}) {
1024+
my $mac = getCanonicalMacAddress($macaddresses->{$suffix});
1025+
next unless $mac;
1026+
# Assume mac status is learned(3) if not found
1027+
my $status = $macstatus && defined($macstatus->{$suffix}) && $macstatus->{$suffix} =~ /(\d+)/ ? int($1) : 3;
1028+
next unless $status == 3;
1029+
push @{$results->{$interface_id}}, $mac;
1030+
} else {
1031+
my @bytes = split(/\./, $suffix);
1032+
shift @bytes while @bytes > 6;
1033+
next unless @bytes == 6;
1034+
push @{$results->{$interface_id}},
1035+
sprintf "%02x:%02x:%02x:%02x:%02x:%02x", @bytes;
1036+
}
10181037
}
10191038

10201039
return $results;

0 commit comments

Comments
 (0)