netstack3_device/
config.rs

1// Copyright 2023 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//! Device link layer configuration types.
6
7use net_types::ip::Ip;
8use netstack3_base::{Device, DeviceIdContext};
9use netstack3_ip::nud::{NudUserConfig, NudUserConfigUpdate};
10
11/// Device ARP configuration.
12#[derive(Clone, Debug)]
13pub struct ArpConfiguration {
14    /// NUD over ARP configuration.
15    pub nud: NudUserConfig,
16}
17
18/// Device NDP configuration.
19#[derive(Clone, Debug)]
20pub struct NdpConfiguration {
21    /// NUD over NDP configuration.
22    pub nud: NudUserConfig,
23}
24
25/// Device link layer configuration.
26#[derive(Clone, Debug)]
27pub struct DeviceConfiguration {
28    /// ARP configurations.
29    ///
30    /// Only present if the device supports ARP.
31    pub arp: Option<ArpConfiguration>,
32    /// NDP configurations.
33    ///
34    /// Only present if the device supports NDP.
35    pub ndp: Option<NdpConfiguration>,
36}
37/// An update to apply to ARP configurations.
38///
39/// Only fields with variant `Some` are requested to be updated.
40#[derive(Clone, Debug, Default)]
41pub struct ArpConfigurationUpdate {
42    /// NUD over ARP configuration update.
43    pub nud: Option<NudUserConfigUpdate>,
44}
45
46/// An update to apply to NDP configurations.
47///
48/// Only fields with variant `Some` are requested to be updated.
49#[derive(Clone, Debug, Default)]
50pub struct NdpConfigurationUpdate {
51    /// NUD over NDP configuration update.
52    pub nud: Option<NudUserConfigUpdate>,
53}
54
55/// An update to apply to device configurations.
56///
57/// Only fields with variant `Some` are requested to be updated.
58#[derive(Clone, Debug, Default)]
59pub struct DeviceConfigurationUpdate {
60    /// ARP configuration update.
61    pub arp: Option<ArpConfigurationUpdate>,
62    /// NDP configuration update.
63    pub ndp: Option<NdpConfigurationUpdate>,
64}
65
66/// Errors observed updating device configuration.
67#[derive(Debug)]
68pub enum DeviceConfigurationUpdateError {
69    /// ARP is not supported for the requested device.
70    ArpNotSupported,
71    /// NDP is not supported for the requested device.
72    NdpNotSupported,
73}
74
75/// A trait abstracting device configuration.
76///
77/// This trait allows the device API to perform device confiuration at the
78/// device layer.
79pub trait DeviceConfigurationContext<D: Device>: DeviceIdContext<D> {
80    /// Calls the callback with a mutable reference to the NUD user
81    /// configuration for IP version `I`.
82    ///
83    /// If the device does not support NUD, the callback is called with `None`,
84    fn with_nud_config<I: Ip, O, F: FnOnce(Option<&NudUserConfig>) -> O>(
85        &mut self,
86        device_id: &Self::DeviceId,
87        f: F,
88    ) -> O;
89
90    /// Calls the callback with a mutable reference to the NUD user
91    /// configuration for IP version `I`.
92    ///
93    /// If the device does not support NUD, the callback is called with `None`,
94    fn with_nud_config_mut<I: Ip, O, F: FnOnce(Option<&mut NudUserConfig>) -> O>(
95        &mut self,
96        device_id: &Self::DeviceId,
97        f: F,
98    ) -> O;
99}