fidl_fuchsia_net_neighbor_ext/
lib.rs

1// Copyright 2020 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//! Extensions for types in the `fidl_fuchsia_net_neighbor` crate.
6
7#![deny(missing_docs)]
8
9use fidl_table_validation::*;
10use {
11    fidl_fuchsia_net as fnet, fidl_fuchsia_net_ext as fnet_ext,
12    fidl_fuchsia_net_neighbor as fnet_neighbor, zx_types as zx,
13};
14
15/// Information on a neighboring device in the local network.
16#[derive(Clone, Debug, Eq, PartialEq, ValidFidlTable)]
17#[fidl_table_src(fnet_neighbor::Entry)]
18#[fidl_table_strict]
19pub struct Entry {
20    /// Identifier for the interface used for communicating with the neighbor.
21    pub interface: u64,
22    /// IP address of the neighbor.
23    pub neighbor: fnet::IpAddress,
24    /// State of the entry within the Neighbor Unreachability Detection (NUD)
25    /// state machine.
26    pub state: fnet_neighbor::EntryState,
27    /// MAC address of the neighboring device's network interface controller.
28    #[fidl_field_type(optional)]
29    pub mac: Option<fnet::MacAddress>,
30    /// Timestamp when this entry has changed `state`.
31    // TODO(https://fxbug.dev/42155335): Replace with zx::MonotonicInstant once there is
32    // support for custom conversion functions.
33    pub updated_at: zx::zx_time_t,
34}
35
36/// Returns a &str suitable for display representing the EntryState parameter.
37pub fn display_entry_state(state: &fnet_neighbor::EntryState) -> &'static str {
38    match state {
39        fnet_neighbor::EntryState::Incomplete => "INCOMPLETE",
40        fnet_neighbor::EntryState::Reachable => "REACHABLE",
41        fnet_neighbor::EntryState::Stale => "STALE",
42        fnet_neighbor::EntryState::Delay => "DELAY",
43        fnet_neighbor::EntryState::Probe => "PROBE",
44        fnet_neighbor::EntryState::Static => "STATIC",
45        fnet_neighbor::EntryState::Unreachable => "UNREACHABLE",
46    }
47}
48
49impl std::fmt::Display for Entry {
50    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
51        let Self { interface, neighbor, mac, state, updated_at: _ } = self;
52        write!(f, "Interface {} | IP {} | MAC ", interface, fnet_ext::IpAddress::from(*neighbor))?;
53        if let Some(mac) = mac {
54            write!(f, "{}", fnet_ext::MacAddress::from(*mac))?;
55        } else {
56            write!(f, "?")?;
57        }
58        write!(f, " | {}", display_entry_state(state))
59    }
60}
61
62/// Options for modifying the behavior of `EntryIterator`.
63#[derive(Clone, Debug, Eq, PartialEq, ValidFidlTable)]
64#[fidl_table_src(fnet_neighbor::EntryIteratorOptions)]
65#[fidl_table_strict]
66pub struct EntryIteratorOptions {}