netlink_packet_route/link/proto_info/
bridge.rs

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