netlink_packet_route/neighbour/
header.rsuse netlink_packet_utils::nla::{NlaBuffer, NlaError, NlasIterator};
use netlink_packet_utils::traits::{Emitable, Parseable};
use netlink_packet_utils::DecodeError;
use super::flags::NeighbourFlags;
use super::NeighbourState;
use crate::route::RouteType;
use crate::AddressFamily;
const NEIGHBOUR_HEADER_LEN: usize = 12;
buffer!(NeighbourMessageBuffer(NEIGHBOUR_HEADER_LEN) {
family: (u8, 0),
ifindex: (u32, 4..8),
state: (u16, 8..10),
flags: (u8, 10),
kind: (u8, 11),
payload:(slice, NEIGHBOUR_HEADER_LEN..),
});
impl<'a, T: AsRef<[u8]> + ?Sized> NeighbourMessageBuffer<&'a T> {
pub fn attributes(&self) -> impl Iterator<Item = Result<NlaBuffer<&'a [u8]>, NlaError>> {
NlasIterator::new(self.payload())
}
}
#[derive(Debug, PartialEq, Eq, Clone, Default)]
pub struct NeighbourHeader {
pub family: AddressFamily,
pub ifindex: u32,
pub state: NeighbourState,
pub flags: NeighbourFlags,
pub kind: RouteType,
}
impl<T: AsRef<[u8]>> Parseable<NeighbourMessageBuffer<T>> for NeighbourHeader {
type Error = ();
fn parse(buf: &NeighbourMessageBuffer<T>) -> Result<Self, ()> {
Ok(Self {
family: buf.family().into(),
ifindex: buf.ifindex(),
state: buf.state().into(),
flags: NeighbourFlags::from_bits_retain(buf.flags()),
kind: buf.kind().into(),
})
}
}
impl Emitable for NeighbourHeader {
fn buffer_len(&self) -> usize {
NEIGHBOUR_HEADER_LEN
}
fn emit(&self, buffer: &mut [u8]) {
let mut packet = NeighbourMessageBuffer::new(buffer);
packet.set_family(self.family.into());
packet.set_ifindex(self.ifindex);
packet.set_state(self.state.into());
packet.set_flags(self.flags.bits());
packet.set_kind(self.kind.into());
}
}