neli/consts/
genl.rs

1use crate as neli;
2
3use std::{io::Cursor, mem::size_of};
4
5use neli_proc_macros::neli_enum;
6
7use crate::{Size, TypeSize};
8
9use crate::{
10    consts::netfilter::{NfLogAttr, NfLogCfg},
11    err::{DeError, SerError},
12    FromBytes, ToBytes,
13};
14
15impl_trait!(
16    /// Trait marking constants valid for use in
17    /// [`Genlmsghdr`][crate::genl::Genlmsghdr] field, `cmd`.
18    pub Cmd,
19    u8,
20    /// Wrapper valid for use with all values in the [`Genlmsghdr`]
21    /// field, `cmd`
22    CmdConsts,
23    CtrlCmd
24);
25
26/// Values for `cmd` in [`Genlmsghdr`][crate::genl::Genlmsghdr].
27#[neli_enum(serialized_type = "u8")]
28pub enum CtrlCmd {
29    Unspec = libc::CTRL_CMD_UNSPEC as u8,
30    Newfamily = libc::CTRL_CMD_NEWFAMILY as u8,
31    Delfamily = libc::CTRL_CMD_DELFAMILY as u8,
32    Getfamily = libc::CTRL_CMD_GETFAMILY as u8,
33    Newops = libc::CTRL_CMD_NEWOPS as u8,
34    Delops = libc::CTRL_CMD_DELOPS as u8,
35    Getops = libc::CTRL_CMD_GETOPS as u8,
36    NewmcastGrp = libc::CTRL_CMD_NEWMCAST_GRP as u8,
37    DelmcastGrp = libc::CTRL_CMD_DELMCAST_GRP as u8,
38    GetmcastGrp = libc::CTRL_CMD_GETMCAST_GRP as u8,
39}
40
41impl_trait!(
42    /// Marker trait for types usable in the
43    /// [`Nlattr`][crate::genl::Nlattr] field, `nla_type`
44    pub NlAttrType,
45    u16,
46    /// Wrapper that is usable with all values in the
47    /// [`Nlattr`][crate::genl::Nlattr] field, `nla_type`.
48    pub NlAttrTypeWrapper,
49    CtrlAttr,
50    CtrlAttrMcastGrp,
51    NfLogAttr,
52    NfLogCfg,
53    Index
54);
55
56/// Values for `nla_type` in [`Nlattr`][crate::genl::Nlattr]
57#[neli_enum(serialized_type = "u16")]
58pub enum CtrlAttr {
59    Unspec = libc::CTRL_ATTR_UNSPEC as u16,
60    FamilyId = libc::CTRL_ATTR_FAMILY_ID as u16,
61    FamilyName = libc::CTRL_ATTR_FAMILY_NAME as u16,
62    Version = libc::CTRL_ATTR_VERSION as u16,
63    Hdrsize = libc::CTRL_ATTR_HDRSIZE as u16,
64    Maxattr = libc::CTRL_ATTR_MAXATTR as u16,
65    Ops = libc::CTRL_ATTR_OPS as u16,
66    McastGroups = libc::CTRL_ATTR_MCAST_GROUPS as u16,
67}
68
69/// Values for `nla_type` in [`Nlattr`][crate::genl::Nlattr]
70#[neli_enum(serialized_type = "u16")]
71pub enum CtrlAttrMcastGrp {
72    Unspec = libc::CTRL_ATTR_MCAST_GRP_UNSPEC as u16,
73    Name = libc::CTRL_ATTR_MCAST_GRP_NAME as u16,
74    Id = libc::CTRL_ATTR_MCAST_GRP_ID as u16,
75}
76
77/// Type representing attribute list types as indices
78#[derive(Debug, PartialEq, Eq, Clone, Copy, Size)]
79pub struct Index(u16);
80
81impl Index {
82    fn is_unrecognized(self) -> bool {
83        false
84    }
85}
86
87impl TypeSize for Index {
88    fn type_size() -> usize {
89        size_of::<u16>()
90    }
91}
92
93impl ToBytes for Index {
94    fn to_bytes(&self, buffer: &mut Cursor<Vec<u8>>) -> Result<(), SerError> {
95        self.0.to_bytes(buffer)
96    }
97}
98
99impl<'lt> FromBytes<'lt> for Index {
100    fn from_bytes(buffer: &mut Cursor<&'lt [u8]>) -> Result<Self, DeError> {
101        Ok(Index(u16::from_bytes(buffer)?))
102    }
103}
104
105impl From<Index> for u16 {
106    fn from(i: Index) -> Self {
107        i.0
108    }
109}
110
111impl From<u16> for Index {
112    fn from(v: u16) -> Self {
113        Index(v)
114    }
115}