@@ -863,7 +863,9 @@ sub _setKnownMacAddresses {
863
863
# start with mac addresses seen on default VLAN
864
864
my $addresses = _getKnownMacAddresses(
865
865
snmp => $snmp ,
866
+ macaddresses => ' .1.3.6.1.2.1.17.4.3.1.1' , # dot1dTpFdbAddress
866
867
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
867
869
port2interface => ' .1.3.6.1.2.1.17.1.4.1.2' , # dot1dBasePortIfIndex
868
870
);
869
871
@@ -878,7 +880,9 @@ sub _setKnownMacAddresses {
878
880
# add additional mac addresses for other VLANs
879
881
$addresses = _getKnownMacAddresses(
880
882
snmp => $snmp ,
883
+ macaddresses => ' .1.3.6.1.2.1.17.7.1.2.2.1.1' , # dot1qTpFdbAddress
881
884
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
882
886
port2interface => ' .1.3.6.1.2.1.17.1.4.1.2' , # dot1dBasePortIfIndex
883
887
);
884
888
@@ -912,7 +916,9 @@ sub _setKnownMacAddresses {
912
916
$snmp -> switch_vlan_context($vlan );
913
917
my $mac_addresses = _getKnownMacAddresses(
914
918
snmp => $snmp ,
919
+ macaddresses => ' .1.3.6.1.2.1.17.4.3.1.1' , # dot1dTpFdbAddress
915
920
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
916
922
port2interface => ' .1.3.6.1.2.1.17.1.4.1.2' , # dot1dBasePortIfIndex
917
923
);
918
924
next unless $mac_addresses ;
@@ -994,27 +1000,40 @@ sub _getKnownMacAddresses {
994
1000
my $snmp = $params {snmp };
995
1001
996
1002
my $results ;
1003
+ my $macaddresses = $params {macaddresses } ? $snmp -> walk($params {macaddresses }) : {};
997
1004
my $address2port = $snmp -> walk($params {address2port });
998
1005
my $port2interface = $snmp -> walk($params {port2interface });
1006
+ my $macstatus = $params {macstatus } ? $snmp -> walk($params {macstatus }) : {};
999
1007
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
1002
1010
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
1004
1013
# $prefix.$vlan.a.b.c.d.e.f = $port
1005
1014
1006
1015
# in both case, the last 6 elements of the OID constitutes
1007
1016
# the mac address in decimal format
1017
+
1008
1018
foreach my $suffix (sort keys %{$address2port }) {
1009
1019
my $port_id = $address2port -> {$suffix };
1010
1020
my $interface_id = $port2interface -> {$port_id };
1011
1021
next unless defined $interface_id ;
1012
1022
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
+ }
1018
1037
}
1019
1038
1020
1039
return $results ;
0 commit comments