netlink_packet_route/link/proto_info/
bridge.rs1use anyhow::Context;
4use netlink_packet_utils::{
5 nla::{DefaultNla, Nla, NlaBuffer, NlasIterator},
6 traits::Parseable,
7 DecodeError,
8};
9
10#[derive(Clone, Eq, PartialEq, Debug)]
11#[non_exhaustive]
12pub enum LinkProtoInfoBridge {
13 Other(DefaultNla),
14}
15
16pub(crate) struct VecLinkProtoInfoBridge(pub(crate) Vec<LinkProtoInfoBridge>);
17
18impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>>
19 for VecLinkProtoInfoBridge
20{
21 fn parse(buf: &NlaBuffer<&'a T>) -> Result<Self, DecodeError> {
22 let mut nlas = vec![];
23 for nla in NlasIterator::new(buf.into_inner()) {
24 let nla = nla.context(format!(
25 "invalid bridge IFLA_PROTINFO {:?}",
26 buf.value()
27 ))?;
28 nlas.push(LinkProtoInfoBridge::parse(&nla)?);
29 }
30 Ok(Self(nlas))
31 }
32}
33
34impl Nla for LinkProtoInfoBridge {
35 fn value_len(&self) -> usize {
36 match *self {
37 Self::Other(ref nla) => nla.value_len(),
38 }
39 }
40
41 fn emit_value(&self, buffer: &mut [u8]) {
42 match *self {
43 Self::Other(ref nla) => nla.emit_value(buffer),
44 }
45 }
46
47 fn kind(&self) -> u16 {
48 match *self {
49 Self::Other(ref nla) => nla.kind(),
50 }
51 }
52}
53
54impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>>
55 for LinkProtoInfoBridge
56{
57 fn parse(buf: &NlaBuffer<&'a T>) -> Result<Self, DecodeError> {
58 Ok(Self::Other(DefaultNla::parse(buf).context(format!(
59 "invalid bridge IFLA_PROTINFO {:?}",
60 buf.value()
61 ))?))
62 }
63}