netlink_packet_route/rtnl/route/nlas/
mfc_stats.rs1use netlink_packet_utils::{
4 traits::{Emitable, Parseable},
5 DecodeError,
6};
7
8#[derive(Debug, Clone, Copy, Eq, PartialEq)]
9#[non_exhaustive]
10pub struct MfcStats {
11 pub packets: u64,
12 pub bytes: u64,
13 pub wrong_if: u64,
14}
15
16pub const MFC_STATS_LEN: usize = 24;
17
18buffer!(MfcStatsBuffer(MFC_STATS_LEN) {
19 packets: (u64, 0..8),
20 bytes: (u64, 8..16),
21 wrong_if: (u64, 16..24),
22});
23
24impl<T: AsRef<[u8]>> Parseable<MfcStatsBuffer<T>> for MfcStats {
25 fn parse(buf: &MfcStatsBuffer<T>) -> Result<MfcStats, DecodeError> {
26 Ok(MfcStats {
27 packets: buf.packets(),
28 bytes: buf.bytes(),
29 wrong_if: buf.wrong_if(),
30 })
31 }
32}
33
34impl Emitable for MfcStats {
35 fn buffer_len(&self) -> usize {
36 MFC_STATS_LEN
37 }
38
39 fn emit(&self, buffer: &mut [u8]) {
40 let mut buffer = MfcStatsBuffer::new(buffer);
41 buffer.set_packets(self.packets);
42 buffer.set_bytes(self.bytes);
43 buffer.set_wrong_if(self.wrong_if);
44 }
45}