netlink_packet_route/link/link_info/
bridge_boolopt.rs1const BUFF_LEN: usize = 8;
4
5use netlink_packet_core::{
6 emit_u32, parse_u32, DecodeError, Emitable, Parseable,
7};
8
9#[derive(Debug, PartialEq, Eq, Clone, Copy)]
12pub struct BridgeBooleanOptions {
13 pub value: BridgeBooleanOptionFlags,
14 pub mask: BridgeBooleanOptionFlags,
15}
16
17impl<T: AsRef<[u8]> + ?Sized> Parseable<T> for BridgeBooleanOptions {
18 fn parse(buf: &T) -> Result<Self, DecodeError> {
19 let buf = buf.as_ref();
20 if buf.len() < BUFF_LEN {
21 return Err(DecodeError::from(format!(
22 "Invalid length for IFLA_BR_MULTI_BOOLOPT data, expecting {}, \
23 but got {}",
24 BUFF_LEN,
25 buf.len()
26 )));
27 }
28
29 Ok(Self {
30 value: BridgeBooleanOptionFlags::from_bits_retain(parse_u32(
31 &buf[..4],
32 )?),
33 mask: BridgeBooleanOptionFlags::from_bits_retain(parse_u32(
34 &buf[4..],
35 )?),
36 })
37 }
38}
39
40impl Emitable for BridgeBooleanOptions {
41 fn buffer_len(&self) -> usize {
42 BUFF_LEN
43 }
44
45 fn emit(&self, buffer: &mut [u8]) {
46 emit_u32(&mut buffer[..4], self.value.bits()).unwrap();
47 emit_u32(&mut buffer[4..], self.mask.bits()).unwrap();
48 }
49}
50
51const BR_BOOLOPT_NO_LL_LEARN: u32 = 1 << 0;
52const BR_BOOLOPT_MCAST_VLAN_SNOOPING: u32 = 1 << 1;
53const BR_BOOLOPT_MST_ENABLE: u32 = 1 << 2;
54const BR_BOOLOPT_MDB_OFFLOAD_FAIL_NOTIFICATION: u32 = 1 << 3;
55const BR_BOOLOPT_FDB_LOCAL_VLAN_0: u32 = 1 << 4;
56
57bitflags! {
58 #[derive(Clone, Eq, PartialEq, Debug, Copy, Default)]
59 #[non_exhaustive]
60 pub struct BridgeBooleanOptionFlags: u32 {
61 const NoLinkLocalLearn= BR_BOOLOPT_NO_LL_LEARN;
62 const VlanMulticastSnooping = BR_BOOLOPT_MCAST_VLAN_SNOOPING;
63 const MstEnable = BR_BOOLOPT_MST_ENABLE;
64 const MdbOffloadFailNotif = BR_BOOLOPT_MDB_OFFLOAD_FAIL_NOTIFICATION;
65 const FdbLocalVlan0 = BR_BOOLOPT_FDB_LOCAL_VLAN_0;
66 const _ = !0;
67 }
68}