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
- Check if the message’s family id is resolved. If yes, jump to step 6.
- Query the family id using the builtin resolver.
- If the id is in the cache, returning the id in the cache and skip step 4.
- The resolver sends
CTRL_CMD_GETFAMILYrequest to get the id and records it in the cache. 5. fill the family id usingGenlMessage::set_resolved_family_id(). 6. Serialize the payload toRawGenlMessage. 7. Send it through the connection.- The family id filled into
message_typefield inNetlinkMessage::finalize().
- The family id filled into
- In the response stream, deserialize the payload back to
GenlMessage<F>.
Implementations§
Source§impl GenetlinkHandle
impl GenetlinkHandle
Sourcepub async fn resolve_family_id<F>(&self) -> Result<u16, GenetlinkError>where
F: GenlFamily,
pub async fn resolve_family_id<F>(&self) -> Result<u16, GenetlinkError>where
F: GenlFamily,
Resolve the family id of the given GenlFamily.
Sourcepub async fn clear_family_id_cache(&self)
pub async fn clear_family_id_cache(&self)
Clear the resolver’s fanily id cache
Sourcepub async fn request<F>(
&mut self,
message: NetlinkMessage<GenlMessage<F>>,
) -> Result<impl Stream<Item = Result<NetlinkMessage<GenlMessage<F>>, DecodeError>>, GenetlinkError>
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.
Sourcepub fn send_request<F>(
&mut self,
message: NetlinkMessage<GenlMessage<F>>,
) -> Result<impl Stream<Item = Result<NetlinkMessage<GenlMessage<F>>, DecodeError>>, GenetlinkError>
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.
Sourcepub async fn notify<F>(
&mut self,
message: NetlinkMessage<GenlMessage<F>>,
) -> Result<(), GenetlinkError>
pub async fn notify<F>( &mut self, message: NetlinkMessage<GenlMessage<F>>, ) -> Result<(), GenetlinkError>
Send the generic netlink message without returning the response stream
Sourcepub fn send_notify<F>(
&mut self,
message: NetlinkMessage<GenlMessage<F>>,
) -> Result<(), GenetlinkError>
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
impl Clone for GenetlinkHandle
Source§fn clone(&self) -> GenetlinkHandle
fn clone(&self) -> GenetlinkHandle
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source. Read more