Skip to content

fix(scanners): guard SNMP walk lookups that can disagree (#474) - #475

Merged
TheWitness merged 3 commits into
developfrom
fix/474-undefined-array-keys
Dec 1, 2026
Merged

TheWitness merged 3 commits into
developfrom
fix/474-undefined-array-keys

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Fixes #474

Problem

MacTrack walks each SNMP table column separately, then joins the results by index. If an FDB entry is learned or ages out between walks, it can appear in one column but not another. On the reporter's Extreme X460, each collection logged Undefined array key warnings from mactrack_extreme.php lines 194, 195, 206 and 207. Those lines read $mac_port_list[$mac_key] and $mac_vlan_list[$mac_key], then used the missing results as keys into $ifInterfaces[...] and $vlan_ids[...].

A survey of the other collectors found the same unguarded cross-walk lookups in most vendor scanners, in the shared ARP helper, and in two of the shared dot1d/dot1q helpers. It also found a related regression in Foundry and Enterasys.

Changes

Extreme (the reported bug)

  • MAC scan: skip FDB entries that have no port (they were already dropped implicitly, but with warnings). When the VLAN walk misses an entry, take the VLAN ifIndex from the end of the EXOS FDB index instead of storing N/A.
  • ARP scan (ExtremeWare and EXOS): skip partial rows, and fall back to the raw port/ifIndex when the name lookup misses.

Shared helpers (mactrack_functions.php)

  • get_standard_arp_table: guard the MAC/IP join, matching the guarded sibling function.
  • get_base_wireless_dot1dTpFdbEntry_ports and get_base_dot1qTpFdbEntry_ports: guard the ifOperStatus→ifInterfaces port count.

Other collectors

  • 3Com, Aruba CX, Cabletron, Cisco, Dell, D-Link, Enterasys N7, H3C, HP, HP NGI, Juniper, Linux, Nortel, Nortel NG, TP-Link and Trendnet: guard interface, VLAN and MAC lookups that use a key from a different walk.

Regression from #377 (Foundry and Enterasys)

  • The PHPStan cleanup added $ifInterfaces = []; after the interface table was built. That emptied the table, so trunk counts were always 0. The empty table was also passed to get_base_dot1dTpFdbEntry_ports, so no user ports or MACs were found. The initialisation now comes before the build.
  • Foundry: the active-port loop only advanced its $indexes[$i] counter on matching ports, so it checked the wrong interface. It now iterates by ifIndex.
  • Nortel NG: $ifInterfaces['ifAlias'][$ifIndex] never existed. It now reads $ifInterfaces[$ifIndex]['ifAlias'].

Tests

  • ExtremeIgnorePortsTest: EXOS FDB entries missing from the VLAN walk or the port walk, and partial EXOS IP FDB rows. Both tests fail on develop: the VLAN is stored as N/A and the warnings appear.
  • New InterfaceTableTrunkCountTest: Foundry and Enterasys trunk counts. Both fail on develop (count is 0).
  • Full Pest suite: 1159 passed, 13 skipped (the skips are the DB-backed recovery tests, which need MACTRACK_TEST_DSN).
  • php -l passes on all lib files. PHPStan level 6 reports no new findings compared with develop. php-cs-fixer reports no issues on the changed lines.

Scanners walk each SNMP table column separately and then join the
results by index. An FDB entry learned or aged out between walks is
present in one column and missing from another, which raised
"Undefined array key" warnings on every collection.

* Extreme: skip FDB entries without a port, fall back to the VLAN
  ifIndex at the end of the EXOS index when the VLAN walk misses the
  entry, and skip partial ARP / IP FDB rows in both ExtremeWare and
  EXOS modes.
* Shared helpers: guard the standard ARP table join and the dot1d
  wireless / dot1q port counts.
* 3Com, Aruba CX, Cabletron, Cisco, Dell, D-Link, Enterasys,
  Enterasys N7, Foundry, H3C, HP, HP NGI, Juniper, Linux, Nortel,
  Nortel NG, TP-Link and Trendnet: guard interface, VLAN and MAC
  lookups keyed by a different walk.
* Foundry and Enterasys: initialise the interface table before it is
  built rather than after; the reset added in #377 emptied it, so trunk
  counts were always zero and no user ports were found.
* Foundry: key the active port count by ifIndex; the old counter only
  advanced on matching ports and checked the wrong interface.
* Nortel NG: read ifAlias from the interface row, not a non-existent
  'ifAlias' row.

Fixes #474

Signed-off-by: TheWitness <thewitness@cacti.net>

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings December 1, 2026 15:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The Foundry MAC loop double-counts interfaces already included in ports_active, inflating active-port totals and requiring a counter reset plus a regression assertion.

1 open issue
What changed in this PR

This PR addresses #474 by making Device Tracking’s SNMP collectors tolerate mismatched table walks. It also restores Foundry and Enterasys interface tables cleared by the earlier PHPStan cleanup in #377.

Changes:

  • Guard cross-walk lookups and handle incomplete MAC, ARP, interface, and VLAN data.
  • Restore interface-table use and correct Foundry indexing and Nortel NG alias lookup.
  • Add regression tests for partial Extreme results and Foundry/Enterasys trunk counts.
File Description
tests/​Unit/​InterfaceTableTrunkCountTest.php Add Foundry and Enterasys trunk-count regressions.
tests/​Unit/​ExtremeIgnorePortsTest.php Cover incomplete Extreme FDB and ARP results.
lib/​mactrack_trendnet.php Guard interface-type and alias lookups.
lib/​mactrack_tplink.php Guard interface-type and VLAN-name lookups.
lib/​mactrack_norbay.php Guard interface metadata lookups.
lib/​mactrack_norbay_ng.php Correct alias indexing and guard interface lookups.
lib/​mactrack_linux.php Guard interface types during active-port counting.
lib/​mactrack_juniper.php Guard missing VLAN metadata.
lib/​mactrack_hp.php Guard interface type and name lookups.
lib/​mactrack_hp_ngi.php Guard interface type and name lookups.
lib/​mactrack_h3c_3com.php Guard interface and ARP joins.
lib/​mactrack_functions.php Guard shared port counts and Netscreen ARP joins.
lib/​mactrack_foundry.php Preserve interface data and iterate active ports by index.
lib/​mactrack_extreme.php Skip incomplete rows and add VLAN/port fallbacks.
lib/​mactrack_enterasys.php Preserve interface data and guard metadata lookups.
lib/​mactrack_enterasys_N7.php Guard interface types and reuse resolved port names.
lib/​mactrack_dlink.php Guard interface-type and VLAN-name lookups.
lib/​mactrack_dell.php Guard interface-type and alias lookups.
lib/​mactrack_cisco.php Guard VLAN-name lookups.
lib/​mactrack_cabletron.php Guard interface types and skip missing MAC addresses.
lib/​mactrack_aruba_oscx.php Guard interface-type lookups.
lib/​mactrack_3com.php Guard interface and bridge-port lookups.
CHANGELOG.md Document #474 and interface-table restoration.

Review effort: Balanced

Comment thread lib/mactrack_foundry.php Resolved
TheWitness and others added 2 commits December 1, 2026 11:01
#474)

* Measure the Enterasys, Foundry, HP, HP NGI, Nortel and Nortel NG
  scanners in Clover so their changes are held to the coverage gate.
* Drive each bridge-port scanner with a bridge port that is not an
  ifIndex, the SecureFast and standard ARP joins with partial walks,
  and the ExtremeWare ARP scan with a partial row.
* Guard the Aruba CX and H3C VLAN name lookups, and the Nortel VLAN,
  ifOperStatus and ifDescr reads, which the new tests showed warn.
* Drop the H3C, Enterasys N7 and TP-Link edits that were already
  protected by an enclosing check.

Signed-off-by: TheWitness <thewitness@cacti.net>

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
get_base_dot1dTpFdbEntry_ports() sets ports_active before the Foundry
scanner recounts the up Ethernet ports, so with the interface table
restored every active port was counted twice. Reset the counter before
the Foundry recount, and assert the count in the Foundry test.

Signed-off-by: TheWitness <thewitness@cacti.net>

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sonarqubecloud

sonarqubecloud Bot commented Dec 1, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
11.0% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@TheWitness
TheWitness merged commit 21beb2b into develop Dec 1, 2026
8 of 9 checks passed
@TheWitness
TheWitness deleted the fix/474-undefined-array-keys branch December 1, 2026 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Undefined array key in lib/mactrack_extreme.php

3 participants