netlink_packet_route/link/af_spec/
inet6_icmp.rs1use netlink_packet_core::{DecodeError, Emitable, Parseable};
4
5pub(crate) const ICMP6_STATS_LEN: usize = 56;
6
7#[derive(Clone, Copy, Eq, PartialEq, Debug, Default)]
8#[non_exhaustive]
9pub struct Icmp6Stats {
10 pub num: i64,
11 pub in_msgs: i64,
12 pub in_errors: i64,
13 pub out_msgs: i64,
14 pub out_errors: i64,
15 pub csum_errors: i64,
16 pub rate_limit_host: i64,
17}
18
19buffer!(Icmp6StatsBuffer(ICMP6_STATS_LEN) {
20 num: (i64, 0..8),
21 in_msgs: (i64, 8..16),
22 in_errors: (i64, 16..24),
23 out_msgs: (i64, 24..32),
24 out_errors: (i64, 32..40),
25 csum_errors: (i64, 40..48),
26 rate_limit_host: (i64, 48..56),
27});
28
29impl<T: AsRef<[u8]>> Parseable<Icmp6StatsBuffer<T>> for Icmp6Stats {
30 fn parse(buf: &Icmp6StatsBuffer<T>) -> Result<Self, DecodeError> {
31 Ok(Self {
32 num: buf.num(),
33 in_msgs: buf.in_msgs(),
34 in_errors: buf.in_errors(),
35 out_msgs: buf.out_msgs(),
36 out_errors: buf.out_errors(),
37 csum_errors: buf.csum_errors(),
38 rate_limit_host: buf.rate_limit_host(),
39 })
40 }
41}
42
43impl Emitable for Icmp6Stats {
44 fn buffer_len(&self) -> usize {
45 ICMP6_STATS_LEN
46 }
47
48 fn emit(&self, buffer: &mut [u8]) {
49 let mut buffer = Icmp6StatsBuffer::new(buffer);
50 buffer.set_num(self.num);
51 buffer.set_in_msgs(self.in_msgs);
52 buffer.set_in_errors(self.in_errors);
53 buffer.set_out_msgs(self.out_msgs);
54 buffer.set_out_errors(self.out_errors);
55 buffer.set_csum_errors(self.csum_errors);
56 buffer.set_rate_limit_host(self.rate_limit_host);
57 }
58}