/// Configure an ethernet interface.
///
/// If the device is a WLAN AP, it will be configured as a WLAN AP (see
/// `configure_wlan_ap_and_dhcp_server` for more details). Otherwise, it
/// will be configured as a host (see `configure_host` for more details).
Configure an ethernet interface.
If the device is a WLAN AP, it will be configured as a WLAN AP (see
`configure_wlan_ap_and_dhcp_server` for more details). Otherwise, it
will be configured as a host .
Configure an ethernet interface . If the device is a WLAN AP it will be configured as a WLAN AP ( see ` configure_wlan_ap_and_dhcp_server ` for more details ) . Otherwise it will be configured as a host .
async fn configure_eth_interface(
        &mut self,
        interface_id: u64,
        topological_path: &str,
        interface_name: String,
        info: &DeviceInfo,
    ) -> Result<(), errors::Error> {
        let interface_id_u32: u32 = interface_id.try_into().expect("NIC ID should fit in a u32");
        if info.is_wlan_ap(topological_path) {
            if let Some(id) = self.interface_states.iter().find_map(|(id, state)| {
                if state.is_wlan_ap() {
                    Some(id)
                } else {
                    None
                }
            }) {
                return Err(errors::Error::NonFatal(anyhow::anyhow!("multiple WLAN AP interfaces are not supported, have WLAN AP interface with id = {}", id)));
            }
            match self.interface_states.entry(interface_id) {
                Entry::Occupied(entry) => {
                    return Err(errors::Error::Fatal(anyhow::anyhow!("multiple interfaces with the same ID = {}; attempting to add state for a WLAN AP, existing state = {:?}", entry.key(), entry.get())));
                }
                Entry::Vacant(entry) => {
                    let _: &mut InterfaceState = entry.insert(InterfaceState::new_wlan_ap());
                }
            }
            info!(
                "discovered WLAN AP interface with id={}, configuring interface and DHCP server",
                interface_id
            );
            let () = self
                .configure_wlan_ap_and_dhcp_server(interface_id_u32, interface_name)
                .await
                .context("error configuring wlan ap and dhcp server")?;
        } else {
            match self.interface_states.entry(interface_id) {
                Entry::Occupied(entry) => {
                    return Err(errors::Error::Fatal(anyhow::anyhow!("multiple interfaces with the same ID = {}; attempting to add state for a host, existing state = {:?}", entry.key(), entry.get())));
                }
                Entry::Vacant(entry) => {
                    let _: &mut InterfaceState = entry.insert(InterfaceState::new_host());
                }
            }
            info!("discovered host interface with id={}, configuring interface", interface_id);
            let () = self
                .configure_host(interface_id_u32, info)
                .await
                .context("error configuring host")?;
        }
        self.netstack
            .set_interface_status(interface_id_u32, true)
            .context("error sending set interface status request")
            .map_err(errors::Error::Fatal)
    }
async fn configure_eth_interface ( & mut self , interface_id : u64 , topological_path : & str , interface_name : String , info : & DeviceInfo , ) -> Result < ( ) , errors :: Error > { let interface_id_u32 : u32 = interface_id . try_into ( ) . expect ( " " ) ; if info . is_wlan_ap ( topological_path ) { if let Some ( id ) = self . interface_states . iter ( ) . find_map ( | ( id , state ) | { if state . is_wlan_ap ( ) { Some ( id ) } else { None } } ) { return Err ( errors :: Error :: NonFatal ( anyhow :: anyhow ! ( " " id ) ) ) ; } match self . interface_states . entry ( interface_id ) { Entry :: Occupied ( entry ) => { return Err ( errors :: Error :: Fatal ( anyhow :: anyhow ! ( " " entry key ( ) entry get ( ) ) ) ) ; } Entry :: Vacant ( entry ) => { let _ : & mut InterfaceState = entry . insert ( InterfaceState :: new_wlan_ap ( ) ) ; } } info ! ( " " interface_id ) ; let ( ) = self . configure_wlan_ap_and_dhcp_server ( interface_id_u32 , interface_name ) . await . context ( " " ) ? ; } else { match self . interface_states . entry ( interface_id ) { Entry :: Occupied ( entry ) => { return Err ( errors :: Error :: Fatal ( anyhow :: anyhow ! ( " " entry key ( ) entry get ( ) ) ) ) ; } Entry :: Vacant ( entry ) => { let _ : & mut InterfaceState = entry . insert ( InterfaceState :: new_host ( ) ) ; } } info ! ( " " interface_id ) ; let ( ) = self . configure_host ( interface_id_u32 , info ) . await . context ( " " ) ? ; } self . netstack . set_interface_status ( interface_id_u32 , true ) . context ( " " ) . map_err ( errors :: Error :: Fatal ) }
Configure an ethernet interface.
Configure an ethernet interface .
&mut self
interface_id
u64
topological_path
&str
interface_name
String
info
&DeviceInfo