Add support of nlmon#165
Conversation
Signed-off-by: Gris Ge <cnfourt@gmail.com>
There was a problem hiding this comment.
Code Review
This pull request introduces support for nlmon (Netlink monitoring) interfaces by adding the LinkNlmon struct and its builder implementation. The reviewer suggested including unit tests in src/link/test.rs to verify the lifecycle of nlmon interfaces, ensuring that the kernel correctly handles the creation and deletion of this interface type.
| // SPDX-License-Identifier: MIT | ||
|
|
||
| use crate::{link::LinkMessageBuilder, packet_route::link::InfoKind}; | ||
|
|
||
| /// Represent nlmon interface. | ||
| /// Example code on creating a nlmon interface | ||
| /// ```no_run | ||
| /// use rtnetlink::{new_connection, LinkNlmon}; | ||
| /// #[tokio::main] | ||
| /// async fn main() -> Result<(), String> { | ||
| /// let (connection, handle, _) = new_connection().unwrap(); | ||
| /// tokio::spawn(connection); | ||
| /// | ||
| /// handle | ||
| /// .link() | ||
| /// .add(LinkNlmon::new("nl0").build()) | ||
| /// .execute() | ||
| /// .await | ||
| /// .map_err(|e| format!("{e}")) | ||
| /// } | ||
| /// ``` | ||
| #[derive(Debug)] | ||
| pub struct LinkNlmon; | ||
|
|
||
| impl LinkNlmon { | ||
| /// Equal to `LinkMessageBuilder::<LinkNlmon>::new()` | ||
| pub fn new(name: &str) -> LinkMessageBuilder<Self> { | ||
| LinkMessageBuilder::<LinkNlmon>::new(name) | ||
| } | ||
| } | ||
|
|
||
| impl LinkMessageBuilder<LinkNlmon> { | ||
| /// Create [LinkMessageBuilder] for nlmon interface type | ||
| pub fn new(name: &str) -> Self { | ||
| LinkMessageBuilder::<LinkNlmon>::new_with_info_kind(InfoKind::Nlmon) | ||
| .name(name.to_string()) | ||
| } | ||
| } |
There was a problem hiding this comment.
While the implementation of LinkNlmon correctly follows the library's patterns, it is missing corresponding unit tests in src/link/test.rs. Adding a test case (e.g., create_get_delete_nlmon) would ensure that the InfoKind::Nlmon variant is correctly handled and that the kernel accepts the interface creation request, similar to existing tests for LinkNetkit or LinkVrf.
No description provided.