diff --git a/internal/scans/runner.go b/internal/scans/runner.go index 33810c2..54d3f35 100644 --- a/internal/scans/runner.go +++ b/internal/scans/runner.go @@ -227,12 +227,21 @@ func probePortDevices(client *gosnmp.GoSNMP, ip string, checkedAt time.Time) []P basePortIfIndex := walkAsMap(client, ".1.3.6.1.2.1.17.1.4.1.2") // dot1dTpFdbPort: mac(6 octets) -> bridge-port fdbMacToBridgePort := walkAsMap(client, ".1.3.6.1.2.1.17.4.3.1.2") + // dot1qTpFdbPort (Q-BRIDGE-MIB): vlan + mac(6 octets) -> bridge-port + qFdbMacToBridgePort := walkAsMap(client, ".1.3.6.1.2.1.17.7.1.2.2.1.2") // ipNetToMediaPhysAddress: ifIndex.ip -> mac arpIfIPToMac := walkAsMap(client, ".1.3.6.1.2.1.4.22.1.2") - if len(basePortIfIndex) == 0 || len(fdbMacToBridgePort) == 0 { + if len(basePortIfIndex) == 0 || (len(fdbMacToBridgePort) == 0 && len(qFdbMacToBridgePort) == 0) { return nil } + combinedFdb := make(map[string]string, len(fdbMacToBridgePort)+len(qFdbMacToBridgePort)) + for k, v := range fdbMacToBridgePort { + combinedFdb[k] = v + } + for k, v := range qFdbMacToBridgePort { + combinedFdb[k] = v + } macToIPs := make(map[string]map[string]struct{}) for key, mac := range arpIfIPToMac { @@ -255,9 +264,9 @@ func probePortDevices(client *gosnmp.GoSNMP, ip string, checkedAt time.Time) []P } seen := make(map[string]struct{}) - out := make([]PortDeviceResult, 0, len(fdbMacToBridgePort)) - for macTail, bridgePortRaw := range fdbMacToBridgePort { - mac := dottedDecimalToMAC(macTail) + out := make([]PortDeviceResult, 0, len(combinedFdb)) + for macTail, bridgePortRaw := range combinedFdb { + mac := dottedDecimalToMACTail(macTail) if mac == "" { continue } @@ -322,11 +331,12 @@ func probePortDevices(client *gosnmp.GoSNMP, ip string, checkedAt time.Time) []P return out } -func dottedDecimalToMAC(s string) string { +func dottedDecimalToMACTail(s string) string { p := strings.Split(strings.TrimSpace(s), ".") - if len(p) != 6 { + if len(p) < 6 { return "" } + p = p[len(p)-6:] b := make([]byte, 6) for i := 0; i < 6; i++ { n, err := strconv.Atoi(p[i])