Skip to content

fix(inventory): network card mapping and port linking#24471

Draft
eduardomozart wants to merge 66 commits into
glpi-project:11.0/bugfixesfrom
eduardomozart:fix-inventory-netadapter-model-backport
Draft

fix(inventory): network card mapping and port linking#24471
eduardomozart wants to merge 66 commits into
glpi-project:11.0/bugfixesfrom
eduardomozart:fix-inventory-netadapter-model-backport

Conversation

@eduardomozart

@eduardomozart eduardomozart commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Checklist before requesting a review

Please delete options that are not relevant.

  • I have read the CONTRIBUTING document.
  • I have performed a self-review of my code.
  • I have added tests that prove my fix is effective or that my feature works.
  • This change requires a documentation update.

Description

This PR addresses several interconnected issues regarding Device Network Cards (components) and Network Ports during native inventory imports, improving component identification, physical hardware grouping, and database relationships:
1. Accurate Hardware Model & Component Naming
Previously, network cards were being uniformly added as a generic "Network card item" without distinct names, causing them to group incorrectly in the Components tab and lack proper model identification. Because the networks schema doesn't have a name tag at all, this mapping fails to do anything. The parser now accurately sets the component's name (designation) to the interface's model, replacing the generic "Network card item" label on PCIVendor's product name fallback and resulting in much more accurate, user-friendly hardware identification.
image
2. Improved Controller Matching (Model Fallback)
The current logic strictly required the network interface's string description to perfectly match the controller's type or name. The controller matching loop has been expanded to also validate the controller's type against the network interface's model property.
3. Network Port Data Mapping (Speed and MTU)
Previously, key network interface data provided by the agent—such as speed and mtu—was being ignored on the base logical port due to GLPI's database schema split (glpi_networkports vs glpi_networkportethernets). InventoryNetworkPort and NetworkCard have been patched to correctly map these properties.
SCR-20260606-rdkr
4. Fixing Controller Component Duplication
Previously, network cards were showing up on the Components page (once as "Controller" and twice as "Network card"). The root cause was that when a controller was mapped to a network interface, the parser attempted to add the interface's name ($val->name) to the ignored controllers list instead of the controller's name. Since network interfaces lack a name property in the inventory XML/JSON, the controller was never actually ignored. We fixed this by correctly using $found_controller->name.
Server-grade physical network cards very frequently have dual-ports or quad-ports (e.g., an Intel I350 Dual Port Gigabit adapter). On the hardware level, there is only one physical PCI controller chip processing the data. However, the operating system recognizes two separate logical network interfaces (eth0 and eth1). Therefore, the GLPI Agent accurately reports one CONTROLLER and two NETWORKS that both correctly point to that exact same controller.
5. Fixing Identical Interfaces Being Deleted
Fixing the bug above exposed another hidden bug: the controller matching logic previously skipped checking any controllers that had already been ignored (&& !isset($this->ignored['controllers'][$controller->name])). This meant that multi-port NICs (which have multiple network interfaces mapping to the exact same controller) would cause all subsequent network interfaces to fail to find a match and get entirely deleted from the NETWORKS inventory. We resolved this by removing the isset check, correctly allowing multiple interfaces to map to the same physical controller while keeping them neatly linked and successfully ignored as a standalone controller.
6. Network Ports failing to link to Network Card Components
During the inventory processing workflow in MainAsset.php, handlePorts() was being executed before handleAssets(). Because network ports rely on matching the MAC address of the network card components to establish their database link, this resulted in ports occasionally failing to associate with the hardware cards since the component rows hadn't been fully inserted into the database yet.

  • Fix: Reordered the execution block in MainAsset::rulepassed() so that handlePorts() runs sequentially after handleAssets().
image

7. Testing & PHPStan Baseline Synchronization
Updated PHPUnit tests in NetworkCardTest.php to include a new test (testPhysicalAndVirtualNetworkCardsFallback) that proves virtual logical interfaces successfully separate from physical hardware controllers, and correctly handles multi-port interface assertions. The legacy test expectations in GenericNetworkAssetInventoryTest.php were also updated to accurately reflect the new port ordering logic. The .phpstan-baseline.php has been recalculated to align perfectly with the updated property definitions.

How to test

  1. Ensure you are using a GLPI Agent build that includes glpi-agent#1176 so that network interfaces fallback with a MODEL and MANUFACTURER.
  2. Import a native JSON/XML inventory containing network interfaces (including virtual/loopback interfaces and physical cards where the description does not match the controller->type string).
  3. Go to Assets > Computers > [Your Computer] > Components. You should see virtual/unknown interfaces correctly omitted from the hardware list, while valid physical components successfully appear. The same component shouldn't appear twice as a Controller and a Network Card.
  4. Verify that the components are named cleanly (using the PCIVendor's product name, falling back to the interface's model).
  5. Go to the Network Ports tab and verify that the logical ports (e.g., eth0, lo, tun0) are correctly listed and successfully linked to their respective physical Network Card components where applicable.
  6. Ensure the "MTU" and "Speed" columns are visible and accurately populated. Verify that the speed is correctly displayed in "Mbps" or "Gbps" and matches the expected hardware speed, and that the MTU reflects the agent's natively reported values.

Screenshots (if appropriate):

Add icon entries to CommonDevice menu options using getIcon() so device/type menu items include icons. In NetworkCard, map 'model' to devicenetworkcardmodels_id and populate designation from model or description when designation is missing, ensuring cards have a sensible name when model data is present.
Add icon entries to CommonDevice menu options using getIcon() so device/type menu items include icons. In NetworkCard, map 'model' to devicenetworkcardmodels_id and populate designation from model or description when designation is missing, ensuring cards have a sensible name when model data is present.
Include the "designation" field in expected JSON for multiple NetworkCard functional tests to reflect the parsed/designated interface name. Update the PHPStan baseline: increment the existing undefined-property count for $designation and add a new ignored property-notFound entry for $devicenetworkcardmodels_id in src/Glpi/Inventory/Asset/NetworkCard.php. These changes keep tests and static analysis expectations in sync with the code behavior.
@cedric-anne cedric-anne requested review from stonebuzz and trasher June 4, 2026 09:07

@trasher trasher 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.

PR is incorrect. Changes are unrelated, no tests are added, etc.

@eduardomozart

Copy link
Copy Markdown
Contributor Author

PR is incorrect. Changes are unrelated, no tests are added, etc.

Hello @trasher, thank you for your comment. In a later discussion, the GLPI team requested me to agglutinate my PRs for easier review, and I merged multiple fixes related to the network device in the same PR.
Beside the tests, can you provide me more details why do you think the PR is wrong? Thank you!

@cconard96

Copy link
Copy Markdown
Contributor

In a later discussion, the GLPI team requested me to agglutinate my PRs for easier review, and I merged multiple fixes related to the network device in the same PR. Beside the tests, can you provide me more details why do you think the PR is wrong? Thank you!

Orthagh and I did ask for that, but specified that they need to be logically related. One of your PRs mixes KB, installer, and clipboard changes all in a single PR which are obviously not logically related.

In this PR the issue still exists but to a lesser degree. You have changes related to the inventorying of network cards mixed with component breadcrumb changes. I know it can be difficult from an external contributor perspective, but try to keep in mind that different areas of concern have different GLPI developers that are suitable for review. For example, I can easily review a PR that changes breadcrumbs but I am almost useless with any changes related to the inventory side so therefore I cannot truly approve this PR.

Try to think of logical groups of changes by their underlying feature area/module and if your PR titles need to have commas or descriptions need many sections, it is a good indicator that they need to be split. If you are addressing a bug in the inventory code, it shouldn't contain UI changes for somewhere else in the code. If a bug fix ends up causing issues, we don't want to have to sort through unrelated changes in the commit to troubleshoot or try to extract only the relevant changes for a revert commit.

Removed icon retrieval from menu options for items.
@eduardomozart eduardomozart changed the title fix(inventory): network card inventory mapping and missing breadcrumb icons for devices fix(inventory): network card inventory mapping Jun 4, 2026
Improve controller matching in NetworkCard: when comparing detected network entries to known controllers, also consider the network 'model' field (with case-insensitive match and optional " controller" suffix) in addition to the existing description checks. Add a functional test (testInventoryUpdateModernAgent) that covers modern GLPI agent XML containing MODEL fields and verifies correct card creation and designation, while ensuring virtual/multiplexor interfaces are handled as expected.
Move the ports handling block in MainAsset so ports are processed later (after wireless controller and asset handling), ensuring port processing happens at the correct point in the import flow. Update NetworkCardTest XML fixtures to properly escape backslashes in PNPDEVICEID values and remove some manufacturer/model nodes from the fixtures. Adjust the test assertion to expect the updated NIC designation ('NetXtreme BCM5720 Gigabit Ethernet PCIe'). These changes align processing order with dependencies and fix the test data/expectation to match actual parsed values.
Streamline NetworkCard controller matching by removing the model-based comparisons (previously using $val->model) and keeping only description-based equality and case-insensitive " description + ' controller'" checks. This removes a fragile/unused branch and avoids referencing the $val variable in that context. Also delete the long, outdated functional test testInventoryUpdateModernAgent from NetworkCardTest, which exercised the removed matching behavior and appeared redundant.
Parse pciid values in NetworkCard to populate manufacturer and product info. When a pciid with a vendor:product format is present, the code now queries pcivendor for manufacturer and product names and sets manufacturers_id, designation and devicenetworkcardmodels_id accordingly instead of discarding the entry. Updated the functional test to expect one prepared result (assertCount(1)) to reflect this new behavior.
@eduardomozart eduardomozart changed the title fix(inventory): network card inventory mapping fix(inventory): network card mapping, port linking, and PCI model fallback Jun 4, 2026
Replace string-based type checks in MainAsset with instanceof for NetworkEquipment and Printer to more reliably determine when ports are handled differently. Update functional test expectations to reflect that one DeviceNetworkCard is imported: change the count from 0 to 1 and add the expected component entry (devicenetworkcards_id 54, MAC 44:85:00:2b:90:bc, etc.). Include a test comment explaining the physical USB adapter is not imported due to missing PCI ID.
Change port-handling condition in MainAsset to check the asset class ($this instanceof NetworkEquipment/Printer) instead of $this->item, ensuring handlePorts is skipped for appropriate MainAsset subclasses. Update functional tests to match the new behavior: adjust expected port entries in GenericNetworkAssetInventoryTest and update network card counts, log counts, and an Item_DeviceNetworkCard fixture in InventoryTest to reflect the corrected import/port handling behavior.
Remove the Printer exclusion from the port-handling conditional in src/Glpi/Inventory/MainAsset/MainAsset.php so printers are now processed by handlePorts; simplifies the instanceof logic. Update .phpstan-baseline.php counts for NetworkCard.php to reflect newly reported occurrences (count 3->4 and 1->2).
Increment the phpstan baseline 'count' for the property.notFound entry in src/Glpi/Inventory/Asset/NetworkCard.php from 3 to 4 to account for an additional ignored occurrence of the `Access to an undefined property object::$manufacturers_id` error.
Remove the 'description' => 'designation' mapping in NetworkCard::prepare so network cards no longer populate a separate 'designation' field. Update NetworkCard tests to remove 'designation' from the expected JSON outputs. Affected files: src/Glpi/Inventory/Asset/NetworkCard.php, tests/functional/Glpi/Inventory/Assets/NetworkCardTest.php.
Expand controller matching in NetworkCard to also consider the scanned value's model. Previously the code compared $val->description (and description + " controller") against controller->type; now it additionally checks $val->model (and model + " controller") when the model property exists. This improves controller identification when the model field contains the type while keeping the existing ignored-controller logic.
Add 'model' => 'designation' to the NetworkCard::prepare mapping so the network card model is correctly mapped to GLPI's 'designation' field when preparing inventory data.
Change NetworkCard prepare mapping to use devicenetworkcardmodels_id for the model field and populate designation from the controller's caption or name when available. Also update the PHPStan baseline counts for related undefined-property warnings in src/Glpi/Inventory/Asset/NetworkCard.php to reflect these code changes.
Remove network_ports from NetworkCard extra_data and simplify port normalization logic: set logical_number only when missing and normalize virtualdev to 0 unless explicitly 1. This removes the previous cross-check against extra_data['network_ports'] (matching by MAC/name) to derive logical_number. Add a functional test (testComputerNetworkPortMetrics) that exercises NetworkCard then NetworkPort processing, asserting that network port metrics are saved and that logical_number is set as expected.
Add use statement for NetworkCard and replace fully-qualified instantiations with imported class names (Converter, Conf, NetworkCard) in tests/functional/Glpi/Inventory/Assets/NetworkPortTest.php. Also apply minor whitespace cleanup to improve readability and consistency in the test.
Add support for linking extra_data['network_ports'] entries to inventory ports and using their ifnumber as the port's logical_number. Introduce 'network_ports' to NetworkCard::extra_data, adjust virtualdev/logical_number initialization, and iterate network_ports to match by mac and name, setting logical_number when a match with ifnumber is found. Update phpstan baseline: add an ignore for undefined property $mtu in NetworkCard.php and increment a related classConstant.nonObject count for NetworkPort.php.
Increment the 'count' for the offsetAccess.invalidOffset entry in .phpstan-baseline.specific.php (path: src/Glpi/Inventory/Asset/NetworkPort.php) from 4 to 5 to account for an additional reported issue.
Add a phpstan-baseline entry to ignore the "Access to an undefined property object::$mtu" error for src/Glpi/Inventory/Asset/NetworkCard.php. Also reorder the field mapping in NetworkCard.php so 'mtu' appears before 'speed' (no functional change).
Adjust NetworkCard functional tests to expect the updated device model name ('Broadcom NetXtreme Gigabit Ethernet') and remove explicit devicenetworkcardmodels_id imports from two test fixtures. Also update .phpstan-baseline.php counts for undefined property errors in src/Glpi/Inventory/Asset/NetworkCard.php to reflect the reduced occurrences. These changes align tests with the current model naming/fixture behavior and keep the PHPStan baseline in sync.
@eduardomozart eduardomozart changed the title fix(inventory): network card mapping, port linking, and PCI model fallback fix(inventory): network card mapping and port linking Jun 11, 2026
@trasher trasher marked this pull request as draft June 12, 2026 05:34
@trasher

trasher commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Back to draft since Agent changes are not validated

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.

4 participants