Struct GenetlinkHandle

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

The generic netlink connection handle

The handle is used to send messages to the connection. It also resolves the family id automatically before sending messages.

§Family id resolving

There is a resolver with cache inside each connection. When you send generic netlink message, the handle resolves and fills the family id into the message.

Since the resolver is created in new_connection(), the cache state wouldn’t share between different connections.

P.s. The cloned handles use the same connection with the original handle. So, they share the same cache state.

§Detailed process of sending generic messages

  1. Check if the message’s family id is resolved. If yes, jump to step 6.
  2. Query the family id using the builtin resolver.
  3. If the id is in the cache, returning the id in the cache and skip step 4.
  4. The resolver sends CTRL_CMD_GETFAMILY request to get the id and records it in the cache. 5. fill the family id using GenlMessage::set_resolved_family_id(). 6. Serialize the payload to RawGenlMessage. 7. Send it through the connection.
  5. In the response stream, deserialize the payload back to GenlMessage<F>.

Implementations§

Source§

impl GenetlinkHandle

Source

pub async fn resolve_family_id<F>(&self) -> Result<u16, GenetlinkError>
where F: GenlFamily,

Resolve the family id of the given GenlFamily.

Source

pub async fn clear_family_id_cache(&self)

Clear the resolver’s fanily id cache

Source

pub async fn request<F>( &mut self, message: NetlinkMessage<GenlMessage<F>>, ) -> Result<impl Stream<Item = Result<NetlinkMessage<GenlMessage<F>>, DecodeError>>, GenetlinkError>

Send the generic netlink message and get the response stream

The function resolves the family id before sending the request. If the resolving process is failed, the function would return an error.

Source

pub fn send_request<F>( &mut self, message: NetlinkMessage<GenlMessage<F>>, ) -> Result<impl Stream<Item = Result<NetlinkMessage<GenlMessage<F>>, DecodeError>>, GenetlinkError>

Send the request without resolving family id

This function is identical to request() but it doesn’t resolve the family id for you.

Source

pub async fn notify<F>( &mut self, message: NetlinkMessage<GenlMessage<F>>, ) -> Result<(), GenetlinkError>

Send the generic netlink message without returning the response stream

Source

pub fn send_notify<F>( &mut self, message: NetlinkMessage<GenlMessage<F>>, ) -> Result<(), GenetlinkError>

Send the notify without resolving family id

Trait Implementations§

Source§

impl Clone for GenetlinkHandle

Source§

fn clone(&self) -> GenetlinkHandle

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GenetlinkHandle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.