Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ pub use crate::{
LinkAddRequest, LinkBond, LinkBondPort, LinkBridge, LinkBridgePort,
LinkBridgeVlan, LinkDelPropRequest, LinkDelRequest, LinkDummy,
LinkGetRequest, LinkHandle, LinkMacSec, LinkMacVlan, LinkMacVtap,
LinkMessageBuilder, LinkNetkit, LinkSetRequest, LinkUnspec, LinkVeth,
LinkVlan, LinkVrf, LinkVxcan, LinkVxlan, LinkWireguard, LinkXfrm,
QosMapping,
LinkMessageBuilder, LinkNetkit, LinkNlmon, LinkSetRequest, LinkUnspec,
LinkVeth, LinkVlan, LinkVrf, LinkVxcan, LinkVxlan, LinkWireguard,
LinkXfrm, QosMapping,
},
multicast::MulticastGroup,
neighbour::{
Expand Down
2 changes: 2 additions & 0 deletions src/link/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ mod mac_vlan;
mod mac_vtap;
mod macsec;
mod netkit;
mod nlmon;
mod property_add;
mod property_del;
mod set;
Expand All @@ -42,6 +43,7 @@ pub use self::{
mac_vtap::LinkMacVtap,
macsec::LinkMacSec,
netkit::LinkNetkit,
nlmon::LinkNlmon,
property_add::LinkNewPropRequest,
property_del::LinkDelPropRequest,
set::LinkSetRequest,
Expand Down
38 changes: 38 additions & 0 deletions src/link/nlmon.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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())
}
}
Comment on lines +1 to +38
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

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.

Loading