netlink_packet_generic/
traits.rs

1// SPDX-License-Identifier: MIT
2
3//! Traits for implementing generic netlink family
4
5/// Provide the definition for generic netlink family
6///
7/// Family payload type should implement this trait to provide necessary
8/// informations in order to build the packet headers (`nlmsghdr` and
9/// `genlmsghdr`).
10///
11/// If you are looking for an example implementation, you can refer to the
12/// [`crate::ctrl`] module.
13pub trait GenlFamily {
14    /// Return the unique family name registered in the kernel
15    ///
16    /// Let the resolver lookup the dynamically assigned ID
17    fn family_name() -> &'static str;
18
19    /// Return the assigned family ID
20    ///
21    /// # Note
22    /// The implementation of generic family should assign the ID to
23    /// `GENL_ID_GENERATE` (0x0). So the controller can dynamically assign
24    /// the family ID.
25    ///
26    /// Regarding to the reason above, you should not have to implement the
27    /// function unless the family uses static ID.
28    fn family_id(&self) -> u16 {
29        0
30    }
31
32    /// Return the command type of the current message
33    fn command(&self) -> u8;
34
35    /// Indicate the protocol version
36    fn version(&self) -> u8;
37}