6 releases

0.3.3 Jul 10, 2023
0.3.2 Jan 29, 2023
0.3.1 Jun 23, 2022
0.3.0 Dec 29, 2021
0.1.0 Sep 21, 2021

#96 in Unix APIs

Download history 2108/week @ 2024-01-22 1498/week @ 2024-01-29 1726/week @ 2024-02-05 1306/week @ 2024-02-12 1967/week @ 2024-02-19 1734/week @ 2024-02-26 1985/week @ 2024-03-04 1901/week @ 2024-03-11 2651/week @ 2024-03-18 2736/week @ 2024-03-25 2155/week @ 2024-04-01 1739/week @ 2024-04-08 2259/week @ 2024-04-15 1789/week @ 2024-04-22 2428/week @ 2024-04-29 1838/week @ 2024-05-06

8,427 downloads per month
Used in 16 crates (7 directly)

MIT license


Rust crate for generic netlink packet types


This crate provides the packet of generic netlink family and its controller.

The [GenlMessage] provides a generic netlink family message which is sub-protocol independant. You can wrap your message into the type, then it can be used in netlink-proto crate.

Implementing a generic netlink family

A generic netlink family contains several commands, and a version number in the header.

The payload usually consists of netlink attributes, carrying the messages to the peer. In order to help you to make your payload into a valid netlink packet, this crate requires the informations about the family id, and the informations in the generic header. So, you need to implement some traits on your types.

All the things in the payload including all netlink attributes used and the optional header should be handled by your implementation.

Serializaion / Deserialization

To implement your generic netlink family, you should handle the payload serialization process including its specific header (if any) and the netlink attributes.

To achieve this, you should implement netlink_packet_utils::Emitable trait for the payload type.

For deserialization, netlink_packet_utils::ParseableParametrized<[u8], GenlHeader> trait should be implemented. As mention above, to provide more scalability, we use the simplest buffer type: [u8] here. You can turn it into other buffer type easily during deserializing.

GenlFamily trait

The trait is aim to provide some necessary informations in order to build the packet headers of netlink (nlmsghdr) and generic netlink (genlmsghdr).


The method let the resolver to obtain the name registered in the kernel.


Few netlink family has static family ID (e.g. controller). The method is mainly used to let those family to return their familt ID.

If you don't know what is this, please DO NOT implement this method. Since the default implementation return GENL_ID_GENERATE, which means the family ID is allocated by the kernel dynamically.


This method tells the generic netlink command id of the packet The return value is used to fill the cmd field in the generic netlink header.


This method return the family version of the payload. The return value is used to fill the version field in the generic netlink header.

Family Header

Few family would use a family specific message header. For simplification and scalability, this crate treats it as a part of the payload, and make implementations to handle the header by themselves.

If you are implementing such a generic family, note that you should define the header data structure in your payload type and handle the serialization.


~24K SLoC