netlink_packet_route/link/proto_info/
inet6.rs1use 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 LinkProtoInfoInet6 {
11 Other(DefaultNla),
12}
13
14pub(crate) struct VecLinkProtoInfoInet6(pub(crate) Vec<LinkProtoInfoInet6>);
15
16impl<'a, T: AsRef<[u8]> + ?Sized> Parseable<NlaBuffer<&'a T>>
17 for VecLinkProtoInfoInet6
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 inet6 IFLA_PROTINFO {:?}",
24 buf.value()
25 ))?;
26 nlas.push(LinkProtoInfoInet6::parse(&nla)?);
27 }
28 Ok(Self(nlas))
29 }
30}
31
32impl Nla for LinkProtoInfoInet6 {
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 LinkProtoInfoInet6
54{
55 fn parse(buf: &NlaBuffer<&'a T>) -> Result<Self, DecodeError> {
56 Ok(Self::Other(DefaultNla::parse(buf).context(format!(
57 "invalid inet6 IFLA_PROTINFO {:?}",
58 buf.value()
59 ))?))
60 }
61}