netlink_packet_route/neighbour/
cache_info.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// SPDX-License-Identifier: MIT

use netlink_packet_utils::traits::{Emitable, Parseable};
use netlink_packet_utils::DecodeError;

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
#[non_exhaustive]
pub struct NeighbourCacheInfo {
    pub confirmed: u32,
    pub used: u32,
    pub updated: u32,
    pub refcnt: u32,
}

const NEIGHBOUR_CACHE_INFO_LEN: usize = 16;

buffer!(NeighbourCacheInfoBuffer(NEIGHBOUR_CACHE_INFO_LEN) {
    confirmed: (u32, 0..4),
    used: (u32, 4..8),
    updated: (u32, 8..12),
    refcnt: (u32, 12..16),
});

impl<T: AsRef<[u8]>> Parseable<NeighbourCacheInfoBuffer<T>> for NeighbourCacheInfo {
    type Error = DecodeError;
    fn parse(buf: &NeighbourCacheInfoBuffer<T>) -> Result<Self, DecodeError> {
        Ok(Self {
            confirmed: buf.confirmed(),
            used: buf.used(),
            updated: buf.updated(),
            refcnt: buf.refcnt(),
        })
    }
}

impl Emitable for NeighbourCacheInfo {
    fn buffer_len(&self) -> usize {
        NEIGHBOUR_CACHE_INFO_LEN
    }

    fn emit(&self, buffer: &mut [u8]) {
        let mut buffer = NeighbourCacheInfoBuffer::new(buffer);
        buffer.set_confirmed(self.confirmed);
        buffer.set_used(self.used);
        buffer.set_updated(self.updated);
        buffer.set_refcnt(self.refcnt);
    }
}