1 unstable release
Uses old Rust 2015
0.1.0 | Sep 1, 2021 |
---|
#25 in #netfilter
Used in rsmnl-linux
17KB
403 lines
rsmnl-derive
I just want to write rsmnl-core examples shorter and more compact, and to try using Rust procedual macro. See examples in rsmnl-linux.
what is, by example
see examples/netfilter/nfct-daemon.rs and src/netfilter/nfnetlink_conntrack.rs.
define:
use { Msghdr, Attr, AttrTbl, Result };
#[repr(u16)]
#[derive(..., NlaType)
pub enum Parent {
None = 0,
One,
Two,
Three,
_MAX
}
will implements std::convert::TryFrom and a few for Parent.
simple type
Then define nla_type by macro attribute:
[#nla_type(u32, one)]
One,
putting value to nlh: Msghdr (e.g. Nlmsghdr) can be done by:
use mnl:: { AttrTbl, Msghdr };
Parent::put_one(&mut nlv, 1234u32)
create tb data from read Msghdr, specify its table name:
#[tbname="ParentTbl"]
pub enum Parent {
Then, value can be accessed via:
let tb = ParentTbl::from_nlmsg(header_offset, nlh)?;
let one: Option<u32> = tb.one()?;
let attr: Option<&Attr> = tb[Parent::One]?;
nested type
Two is nested which is defined:
#[repr(u16)]
#[derive(..., NlaType)
#[tbname="ChildTbl"]
pub enum Child {
None = 0,
[#nla_type(str, one)]
Ichi,
Ni,
San,
_MAX
}
In enum Parent, define:
[#nla_nest(ChildTbl, two)]
Two,
Then Two can be acquire and access:
let two = tb.two()?;
let ichi = two.ichi()?;
Dependencies
~1.5MB
~35K SLoC