Skip to main content

NlSocketHandle

Struct NlSocketHandle 

Source
pub struct NlSocketHandle { /* private fields */ }
Expand description

Tokio-enabled Netlink socket struct

Implementations§

Source§

impl NlSocketHandle

Source

pub fn connect( proto: NlFamily, pid: Option<u32>, groups: Groups, ) -> Result<Self, SocketError>

Set up asynchronous socket handle.

Source

pub fn add_mcast_membership(&self, groups: Groups) -> Result<(), SocketError>

Join multicast groups for a socket.

Source

pub fn drop_mcast_membership(&self, groups: Groups) -> Result<(), SocketError>

Leave multicast groups for a socket.

Source

pub fn list_mcast_membership(&self) -> Result<NetlinkBitArray, SocketError>

List joined groups for a socket.

Source

pub fn pid(&self) -> u32

Get the PID for the current socket.

Source

pub async fn send<T, P>(&self, msg: &Nlmsghdr<T, P>) -> Result<(), SocketError>
where T: NlType, P: Size + ToBytes,

Send a message on the socket asynchronously.

Source

pub async fn recv<T, P>( &self, ) -> Result<(NlBufferIter<T, P, BufferPoolGuard<'_>>, Groups), SocketError>
where T: NlType, P: Size + FromBytesWithInput<Input = usize>,

Receive a message from the socket asynchronously.

Source

pub async fn recv_all<T, P>( &self, ) -> Result<(NlBuffer<T, P>, Groups), SocketError>
where T: NlType + Debug, P: Size + FromBytesWithInput<Input = usize> + Debug,

Parse all Nlmsghdr structs sent in one network packet and return them all in a list.

Failure to parse any packet will cause the entire operation to fail. If an error is detected at the application level, this method will discard any non-error Nlmsghdr structs and only return the error. For a more granular approach, use either NlSocketHandle::recv.

Source

pub fn set_recv_buffer_size(&self, size: usize) -> Result<(), SocketError>

Set the size of the receive buffer for the socket.

This can be useful when communicating with a service that sends a high volume of messages (especially multicast), and your application cannot process them fast enough, leading to the kernel dropping messages. A larger buffer may help mitigate this.

The value passed is a hint to the kernel to set the size of the receive buffer. The kernel will double the value provided to account for bookkeeping overhead. The doubled value is capped by the value in /proc/sys/net/core/rmem_max.

The default value is /proc/sys/net/core/rmem_default

See socket(7) documentation for SO_RCVBUF for more information.

Source

pub fn enable_ext_ack(&self, enable: bool) -> Result<(), SocketError>

If true is passed in, enable extended ACKs for this socket. If false is passed in, disable extended ACKs for this socket.

Source

pub fn get_ext_ack_enabled(&self) -> Result<bool, SocketError>

Return true if an extended ACK is enabled for this socket.

Source

pub fn enable_strict_checking(&self, enable: bool) -> Result<(), SocketError>

If true is passed in, enable strict checking for this socket. If false is passed in, disable strict checking for for this socket. Only supported by NlFamily::Route sockets. Requires Linux >= 4.20.

Source

pub fn get_strict_checking_enabled(&self) -> Result<bool, SocketError>

Return true if strict checking is enabled for this socket. Only supported by NlFamily::Route sockets. Requires Linux >= 4.20.

Trait Implementations§

Source§

impl AsRawFd for NlSocketHandle

Source§

fn as_raw_fd(&self) -> RawFd

Extracts the raw file descriptor. Read more
Source§

impl From<NlSocketHandle> for NlSocket

Available on crate feature async only.
Source§

fn from(s: NlSocketHandle) -> Self

Converts to this type from the input type.
Source§

impl IntoRawFd for NlSocketHandle

Source§

fn into_raw_fd(self) -> RawFd

Consumes this object, returning the raw underlying file descriptor. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.