netlink_packet_route/link/
event.rs1use netlink_packet_core::{
4 emit_u32, parse_u32, DecodeError, Emitable, ErrorContext, Parseable,
5};
6
7const IFLA_EVENT_NONE: u32 = 0;
8const IFLA_EVENT_REBOOT: u32 = 1;
9const IFLA_EVENT_FEATURES: u32 = 2;
10const IFLA_EVENT_BONDING_FAILOVER: u32 = 3;
11const IFLA_EVENT_NOTIFY_PEERS: u32 = 4;
12const IFLA_EVENT_IGMP_RESEND: u32 = 5;
13const IFLA_EVENT_BONDING_OPTIONS: u32 = 6;
14
15#[derive(Debug, PartialEq, Eq, Clone, Copy, Default)]
16#[non_exhaustive]
17pub enum LinkEvent {
18 #[default]
19 None,
20 Reboot,
21 Features,
22 BondingFailover,
23 NotifyPeers,
24 IgmpResend,
25 BondingOptions,
26 Other(u32),
27}
28
29impl From<u32> for LinkEvent {
30 fn from(d: u32) -> Self {
31 match d {
32 IFLA_EVENT_NONE => Self::None,
33 IFLA_EVENT_REBOOT => Self::Reboot,
34 IFLA_EVENT_FEATURES => Self::Features,
35 IFLA_EVENT_BONDING_FAILOVER => Self::BondingFailover,
36 IFLA_EVENT_NOTIFY_PEERS => Self::NotifyPeers,
37 IFLA_EVENT_IGMP_RESEND => Self::IgmpResend,
38 IFLA_EVENT_BONDING_OPTIONS => Self::BondingOptions,
39 _ => Self::Other(d),
40 }
41 }
42}
43
44impl From<LinkEvent> for u32 {
45 fn from(v: LinkEvent) -> u32 {
46 match v {
47 LinkEvent::None => IFLA_EVENT_NONE,
48 LinkEvent::Reboot => IFLA_EVENT_REBOOT,
49 LinkEvent::Features => IFLA_EVENT_FEATURES,
50 LinkEvent::BondingFailover => IFLA_EVENT_BONDING_FAILOVER,
51 LinkEvent::NotifyPeers => IFLA_EVENT_NOTIFY_PEERS,
52 LinkEvent::IgmpResend => IFLA_EVENT_IGMP_RESEND,
53 LinkEvent::BondingOptions => IFLA_EVENT_BONDING_OPTIONS,
54 LinkEvent::Other(d) => d,
55 }
56 }
57}
58
59impl<T: AsRef<[u8]> + ?Sized> Parseable<T> for LinkEvent {
60 fn parse(buf: &T) -> Result<Self, DecodeError> {
61 Ok(LinkEvent::from(
62 parse_u32(buf.as_ref()).context("invalid IFLA_EVENT value")?,
63 ))
64 }
65}
66
67impl Emitable for LinkEvent {
68 fn buffer_len(&self) -> usize {
69 4
70 }
71
72 fn emit(&self, buffer: &mut [u8]) {
73 emit_u32(buffer, u32::from(*self)).unwrap();
74 }
75}