netstack3_base/
inspect.rs1use core::fmt::Display;
12
13pub use diagnostics_traits::{Inspectable, InspectableValue, Inspector, InspectorDeviceExt};
14use net_types::ip::IpAddress;
15use net_types::{AddrAndPortFormatter, ZonedAddr};
16
17use crate::counters::Counter;
18
19pub trait InspectorExt: Inspector {
22 fn record_counter(&mut self, name: &str, value: &Counter) {
24 self.record_uint(name, value.get())
25 }
26
27 fn record_zoned_addr_with_port<I: InspectorDeviceExt<D>, A: IpAddress, D, P: Display>(
30 &mut self,
31 name: &str,
32 addr: ZonedAddr<A, D>,
33 port: P,
34 ) {
35 self.record_display(
36 name,
37 AddrAndPortFormatter::<_, _, A::Version>::new(
38 addr.map_zone(|device| I::device_identifier_as_address_zone(device)),
39 port,
40 ),
41 )
42 }
43
44 fn record_local_socket_addr<I: InspectorDeviceExt<D>, A: IpAddress, D, P: Display>(
46 &mut self,
47 addr_with_port: Option<(ZonedAddr<A, D>, P)>,
48 ) {
49 const NAME: &str = "LocalAddress";
50 if let Some((addr, port)) = addr_with_port {
51 self.record_zoned_addr_with_port::<I, _, _, _>(NAME, addr, port);
52 } else {
53 self.record_str(NAME, "[NOT BOUND]")
54 }
55 }
56
57 fn record_remote_socket_addr<I: InspectorDeviceExt<D>, A: IpAddress, D, P: Display>(
59 &mut self,
60 addr_with_port: Option<(ZonedAddr<A, D>, P)>,
61 ) {
62 const NAME: &str = "RemoteAddress";
63 if let Some((addr, port)) = addr_with_port {
64 self.record_zoned_addr_with_port::<I, _, _, _>(NAME, addr, port);
65 } else {
66 self.record_str(NAME, "[NOT CONNECTED]")
67 }
68 }
69}
70
71impl<T: Inspector> InspectorExt for T {}