Skip to main content

Crate nlink_macros

Crate nlink_macros 

Source
Expand description

Proc-macro derives for the nlink Linux-netlink library — typed GENL family / command / attribute / message codecs.

Don’t depend on this crate directly. Use nlink and write use nlink::macros::*; to pull in every macro plus the supporting traits in one shot. See the README + the define-your-own-genl-family recipe for end-to-end usage; the runnable example lives at crates/nlink/examples/macros/define_taskstats.rs.

§Shipped surface (0.16, Plan 154 Phases 1–6)

  • GenlCommand + #[genl_command(repr = "u8"|"u16")] — typed GENL command enum
  • GenlAttribute + #[genl_attribute(repr = "u8"|"u16")] — typed attribute-kind enum
  • GenlEnum + #[genl_enum(repr = "u8"|"u16"|"u32")] — typed value enum encoded inside an attribute payload
  • GenlMessage + #[genl_message(cmd = ...)] + per-field #[genl_attr(...)] — typed request/response body. Pairs with the generic Connection::<F: GenlFamily>::send_typed<M, R> / dump_typed_stream<M, R> dispatch in nlink.
  • genl_family — #[genl_family(name = "...", version = N)] rewrites a unit-struct declaration into a complete family marker (ProtocolState + AsyncProtocolInit + GenlFamily + sealed-trait impls + family_id field + Default / Debug).

The three codec derives (GenlCommand, GenlAttribute, GenlEnum) produce the same shape — From<EnumType> for ReprType + TryFrom<ReprType> for EnumType + a small EnumTypeUnknownValue(repr) error newtype.

§Deferred follow-up

#[derive(NetlinkAttrs)] for nested attribute groups (NLA_F_NESTED) is tracked as a Plan 154 follow-up. The nlink::macros::NetlinkAttrs trait is already in tree so hand-implementations work today; the derive will close the last remaining “hand-roll this bit” gap.

Doc examples in this crate are ```text, not compiled: they show the derives being applied, which needs both this crate and nlink in scope, and nlink-macros cannot depend on nlink without a cycle. The compiled versions live in nlink’s own documentation and in crates/nlink/examples/macros/define_taskstats.rs.

Attribute Macros§

genl_family
Declare a Generic Netlink family marker.

Derive Macros§

GenlAttribute
Derive a typed-enum codec for a Generic Netlink attribute kind enum.
GenlCommand
Derive a typed-enum codec for a Generic Netlink command ID enum.
GenlEnum
Derive a typed-enum codec for a value enum encoded inside an attribute payload (rather than as the attribute kind itself).
GenlMessage
Derive nlink::macros::GenlMessage for a struct-shaped GENL message body.
NetlinkAttrs
Derive NetlinkAttrs for a nested attribute group — a struct the kernel encodes as the contents of a single NLA_F_NESTED attribute.