netstack3_ip/raw/counters.rs
1// Copyright 2024 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5//! Declares counters for observability/debugging of raw IP sockets.
6
7use net_types::ip::{Ip, IpVersionMarker};
8use netstack3_base::{Counter, Inspectable, Inspector, InspectorExt};
9
10/// Raw IP socket counters.
11///
12/// These counters are used both on a per-socket basis, and in a stack-wide
13/// aggregate.
14#[derive(Default)]
15pub struct RawIpSocketCounters<I: Ip> {
16 _marker: IpVersionMarker<I>,
17 /// Count of incoming IP packets that were delivered to the socket.
18 ///
19 /// Note that a single IP packet may be delivered to multiple raw IP
20 /// sockets. Thus this counter, when tracking the stack-wide aggregate, may
21 /// exceed the total number of IP packets received by the stack.
22 pub(super) rx_packets: Counter,
23 /// Count of incoming IP packets that could not be delivered to a socket
24 /// because its receive buffer was full.
25 pub rx_queue_full: Counter,
26 /// Count of outgoing IP packets that were sent by the socket.
27 pub(super) tx_packets: Counter,
28 /// Count of incoming IP packets that were not delivered due to an invalid
29 /// checksum.
30 pub(super) rx_checksum_errors: Counter,
31 /// Count of outgoing IP packets that were not sent because a checksum could
32 /// not be computed.
33 pub(super) tx_checksum_errors: Counter,
34 /// Count of incoming IP packets that were not delivered because they failed
35 /// the socket's ICMP filter.
36 pub(super) rx_icmp_filtered: Counter,
37}
38
39impl<I: Ip> Inspectable for RawIpSocketCounters<I> {
40 fn record<II: Inspector>(&self, inspector: &mut II) {
41 let Self {
42 _marker,
43 rx_packets,
44 rx_queue_full,
45 tx_packets,
46 rx_checksum_errors,
47 tx_checksum_errors,
48 rx_icmp_filtered,
49 } = self;
50 inspector.record_child("Rx", |inspector| {
51 inspector.record_counter("DeliveredPackets", rx_packets);
52 inspector.record_counter("ChecksumErrors", rx_checksum_errors);
53 inspector.record_counter("IcmpPacketsFiltered", rx_icmp_filtered);
54 inspector.record_counter("DroppedQueueFull", rx_queue_full);
55 });
56 inspector.record_child("Tx", |inspector| {
57 inspector.record_counter("SentPackets", tx_packets);
58 inspector.record_counter("ChecksumErrors", tx_checksum_errors);
59 });
60 }
61}