Skip to content

support nlmon link type#26

Merged
cathay4t merged 2 commits into
rust-netlink:mainfrom
cathay4t:main
May 24, 2026
Merged

support nlmon link type#26
cathay4t merged 2 commits into
rust-netlink:mainfrom
cathay4t:main

Conversation

@cathay4t

Copy link
Copy Markdown
Member

Introduce nlmon (Netlink monitor) interface support for both creation
and query. Usage:

ip link add name NAME type nlmon

Integration test cases included.

Introduce nlmon (Netlink monitor) interface support for both creation
and query. Usage:

  ip link add name NAME type nlmon

Integration test cases included.

Signed-off-by: Gris Ge <cnfourt@gmail.com>
@cathay4t cathay4t enabled auto-merge (rebase) May 24, 2026 13:00

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for the nlmon link type, including the necessary logic in LinkAddCommand and a new test suite in src/ip/link/tests/nlmon.rs. The reviewer suggested improving the with_nlmon_iface test helper by using std::panic::resume_unwind to preserve panic information during test failures and making the interface cleanup step more robust.

Comment on lines +65 to +71
let result = std::panic::catch_unwind(|| {
test();
});

// clean up
exec_cmd(&["ip", "link", "del", name]);
assert!(result.is_ok())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The current implementation of with_nlmon_iface uses assert!(result.is_ok()) after catching a panic. This is suboptimal because it discards the original panic message and stack trace, making it difficult to debug test failures. Using std::panic::resume_unwind is preferred as it preserves the original panic information. Additionally, the cleanup step should ideally be robust against failures (e.g., if the interface was already removed by the test itself).

    let result = std::panic::catch_unwind(test);

    // clean up
    let _ = exec_cmd(&["ip", "link", "del", name]);

    if let Err(e) = result {
        std::panic::resume_unwind(e);
    }

When creating VLAN parent dummy interface without `address` property
defined, systemd/udevd will generate random MAC address and change it,
hence we have race problem during creation and query.

Fixed by explicitly set MAC address when creating VLAN parent interface
in tests.

Signed-off-by: Gris Ge <cnfourt@gmail.com>
@cathay4t cathay4t merged commit f58ebb9 into rust-netlink:main May 24, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant