rsmnl_linux/
genetlink.rs

1use errno::Errno;
2use mnl::{Attr, AttrTbl, MsgVec, Result};
3use netlink;
4use std::mem;
5
6pub const GENL_NAMSIZ: usize = 16;
7
8pub const GENL_MIN_ID: u16 = netlink::NLMSG_MIN_TYPE;
9pub const GENL_MAX_ID: u16 = 1023;
10
11#[repr(C)]
12#[derive(Debug, Clone, Copy)]
13pub struct Genlmsghdr {
14    pub cmd: u8,
15    pub version: u8,
16    pub reserved: u16,
17}
18
19pub const fn genl_hdrlen() -> u32 {
20    netlink::nlmsg_align(mem::size_of::<Genlmsghdr>() as u32)
21}
22
23pub const GENL_ADMIN_PERM: u8 = 0x01;
24pub const GENL_CMD_CAP_DO: u8 = 0x02;
25pub const GENL_CMD_CAP_DUMP: u8 = 0x04;
26pub const GENL_CMD_CAP_HASPOL: u8 = 0x08;
27pub const GENL_UNS_ADMIN_PERM: u8 = 0x10;
28
29// List of reserved static generic netlink identifiers:
30pub const GENL_ID_CTRL: u16 = netlink::NLMSG_MIN_TYPE;
31pub const GENL_ID_VFS_DQUOT: u16 = netlink::NLMSG_MIN_TYPE + 1;
32pub const GENL_ID_PMCRAID: u16 = netlink::NLMSG_MIN_TYPE + 2;
33// must be last reserved + 1
34pub const GENL_START_ALLOC: u16 = netlink::NLMSG_MIN_TYPE + 3;
35
36// Controller
37#[repr(u8)]
38#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
39pub enum CtrlCmd {
40    // CTRL_CMD_
41    Unspec,
42    Newfamily,
43    Delfamily,
44    Getfamily,
45    Newops,
46    Delops,
47    Getops,
48    NewmcastGrp,
49    DelmcastGrp,
50    GetmcastGrp, // unused
51    Getpolicy,
52    _MAX,
53}
54pub const CTRL_CMD_UNSPEC: u8 = CtrlCmd::Unspec as u8;
55pub const CTRL_CMD_NEWFAMILY: u8 = CtrlCmd::Newfamily as u8;
56pub const CTRL_CMD_DELFAMILY: u8 = CtrlCmd::Delfamily as u8;
57pub const CTRL_CMD_GETFAMILY: u8 = CtrlCmd::Getfamily as u8;
58pub const CTRL_CMD_NEWOPS: u8 = CtrlCmd::Newops as u8;
59pub const CTRL_CMD_DELOPS: u8 = CtrlCmd::Delops as u8;
60pub const CTRL_CMD_GETOPS: u8 = CtrlCmd::Getops as u8;
61pub const CTRL_CMD_NEWMCAST_GRP: u8 = CtrlCmd::NewmcastGrp as u8;
62pub const CTRL_CMD_DELMCAST_GRP: u8 = CtrlCmd::DelmcastGrp as u8;
63pub const CTRL_CMD_GETMCAST_GRP: u8 = CtrlCmd::GetmcastGrp as u8;
64pub const CTRL_CMD_GETPOLICY: u8 = CtrlCmd::Getpolicy as u8;
65pub const __CTRL_CMD_MAX: u8 = CtrlCmd::_MAX as u8;
66pub const CTRL_CMD_MAX: u8 = __CTRL_CMD_MAX - 1;
67
68#[repr(u16)]
69#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, NlaType)]
70#[tbname = "CtrlAttrTbl"]
71pub enum CtrlAttr {
72    // CTRL_ATTR_
73    Unspec,
74
75    #[nla_type(u16, family_id)]
76    FamilyId,
77
78    // #[nla_type(nulstr, family_name)]
79    #[nla_type(cstr, family_name)]
80    FamilyName,
81
82    #[nla_type(u32, version)]
83    Version,
84
85    #[nla_type(u32, hdrsize)]
86    Hdrsize,
87
88    #[nla_type(u32, maxattr)]
89    Maxattr,
90
91    #[nla_nest([CtrlAttrOpTbl], ops)]
92    Ops,
93
94    #[nla_nest([CtrlAttrMcastGrpTbl], mcast_groups)]
95    McastGroups,
96
97    #[nla_nest(netlink::NetlinkPolicyTypeAttrTbl, policy)]
98    Policy,
99    _MAX,
100}
101
102#[repr(u16)]
103#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, NlaType)]
104#[tbname = "CtrlAttrOpTbl"]
105pub enum CtrlAttrOp {
106    // CTRL_ATTR_OP_
107    Unspec,
108
109    #[nla_type(u32, id)]
110    Id,
111
112    #[nla_type(u32, flags)]
113    Flags,
114    _MAX,
115}
116
117#[repr(u16)]
118#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, NlaType)]
119#[tbname = "CtrlAttrMcastGrpTbl"]
120pub enum CtrlAttrMcastGrp {
121    // CTRL_ATTR_MCAST_GRP_
122    Unspec,
123
124    #[nla_type(cstr, name)]
125    #[nla_type(bytes, name_bytes)]
126    Name,
127
128    #[nla_type(u32, id)]
129    Id,
130    _MAX,
131}