Skip to content

Commit

Permalink
Allow the user to specify their own socket
Browse files Browse the repository at this point in the history
This is useful when dealing with multiple network/user namespaces.

Requires rust-netlink/netlink-proto#25
  • Loading branch information
MaxHearnden committed Jan 21, 2025
1 parent 515471f commit 93815aa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,19 @@ where
netlink_proto::new_connection_with_socket(NETLINK_ROUTE)?;
Ok((conn, Handle::new(handle), messages))
}

#[allow(clippy::type_complexity)]
pub fn from_socket<S>(
socket: S,
) -> (
Connection<RouteNetlinkMessage, S>,
Handle,
UnboundedReceiver<(NetlinkMessage<RouteNetlinkMessage>, SocketAddr)>,
)
where
S: AsyncSocket,
{
let (conn, handle, messages) =
netlink_proto::from_socket_with_codec(socket);
(conn, Handle::new(handle), messages)
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ mod traffic_control;
pub use crate::addr::{
AddressAddRequest, AddressDelRequest, AddressGetRequest, AddressHandle,
};
pub use crate::connection::from_socket;
#[cfg(feature = "tokio_socket")]
pub use crate::connection::new_connection;
pub use crate::connection::new_connection_with_socket;
Expand Down

0 comments on commit 93815aa

Please sign in to comment.