1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use std::fmt::Debug;
use crate::{AckMessage, ErrorMessage, NetlinkSerializable};
pub const NLMSG_NOOP: u16 = 1;
pub const NLMSG_ERROR: u16 = 2;
pub const NLMSG_DONE: u16 = 3;
pub const NLMSG_OVERRUN: u16 = 4;
pub const NLMSG_ALIGNTO: u16 = 4;
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum NetlinkPayload<I> {
Done,
Error(ErrorMessage),
Ack(AckMessage),
Noop,
Overrun(Vec<u8>),
InnerMessage(I),
}
impl<I> NetlinkPayload<I>
where
I: NetlinkSerializable,
{
pub fn message_type(&self) -> u16 {
match self {
NetlinkPayload::Done => NLMSG_DONE,
NetlinkPayload::Error(_) | NetlinkPayload::Ack(_) => NLMSG_ERROR,
NetlinkPayload::Noop => NLMSG_NOOP,
NetlinkPayload::Overrun(_) => NLMSG_OVERRUN,
NetlinkPayload::InnerMessage(message) => message.message_type(),
}
}
}