async fn enable_interface(&mut self, id: u64) -> Result<(), fidl_net_stack::Error> {
        let (state, disp) = self.ctx.state_and_dispatcher();
        let device = disp.get_device_info(id).ok_or(fidl_net_stack::Error::NotFound)?;

        if device.admin_enabled() && device.phy_up() {
            // TODO(rheacock, NET-2140): Handle core and driver state in two stages: add device to the
            // core to get an id, then reach into the driver to get updated info before triggering the
            // core to allow traffic on the interface.
            let generate_core_id = |info: &DeviceInfo| {
                state.add_ethernet_device(Mac::new(info.mac().octets), info.mtu())
            };
            match disp.devices.activate_device(id, generate_core_id) {
                Ok(device_info) => {
                    // we can unwrap core_id here because activate_device just succeeded.
                    let core_id = device_info.core_id().unwrap();
                    // don't forget to initialize the device in core!
                    initialize_device(&mut self.ctx, core_id);
                    Ok(())
                }
                Err(toggle_error) => {
                    match toggle_error {
                        ToggleError::NoChange => Ok(()),
                        ToggleError::NotFound => Err(fidl_net_stack::Error::NotFound), // Invalid device ID
                    }
                }
            }
        } else {
            Ok(())
        }
    }
/// Enables an interface, adding it to the core if it is not currently enabled.
/// Both `admin_enabled` and `phy_up` must be true for the interface to be enabled.
Enables an interface, adding it to the core if it is not currently enabled.
Both `admin_enabled` and `phy_up` must be true for the interface to be enabled.
Enables an interface adding it to the core if it is not currently enabled . Both ` admin_enabled ` and ` phy_up ` must be true for the interface to be enabled .
async fn enable_interface(&mut self, id: u64) -> Result<(), fidl_net_stack::Error> {
        let (state, disp) = self.ctx.state_and_dispatcher();
        let device = disp.get_device_info(id).ok_or(fidl_net_stack::Error::NotFound)?;
        if device.admin_enabled() && device.phy_up() {
            // TODO(rheacock, NET-2140): Handle core and driver state in two stages: add device to the
            // core to get an id, then reach into the driver to get updated info before triggering the
            // core to allow traffic on the interface.
            let generate_core_id = |info: &DeviceInfo| {
                state.add_ethernet_device(Mac::new(info.mac().octets), info.mtu())
            };
            match disp.devices.activate_device(id, generate_core_id) {
                Ok(device_info) => {
                    // we can unwrap core_id here because activate_device just succeeded.
                    let core_id = device_info.core_id().unwrap();
                    // don't forget to initialize the device in core!
                    initialize_device(&mut self.ctx, core_id);
                    Ok(())
                }
                Err(toggle_error) => {
                    match toggle_error {
                        ToggleError::NoChange => Ok(()),
                        ToggleError::NotFound => Err(fidl_net_stack::Error::NotFound), // Invalid device ID
                    }
                }
            }
        } else {
            Ok(())
        }
    }
async fn enable_interface ( & mut self , id : u64 ) -> Result < ( ) , fidl_net_stack :: Error > { let ( state , disp ) = self . ctx . state_and_dispatcher ( ) ; let device = disp . get_device_info ( id ) . ok_or ( fidl_net_stack :: Error :: NotFound ) ? ; if device . admin_enabled ( ) && device . phy_up ( ) { // TODO(rheacock, NET-2140): Handle core and driver state in two stages: add device to the // core to get an id, then reach into the driver to get updated info before triggering the // core to allow traffic on the interface. let generate_core_id = | info : & DeviceInfo | { state . add_ethernet_device ( Mac :: new ( info . mac ( ) . octets ) , info . mtu ( ) ) } ; match disp . devices . activate_device ( id , generate_core_id ) { Ok ( device_info ) => { // we can unwrap core_id here because activate_device just succeeded. let core_id = device_info . core_id ( ) . unwrap ( ) ; // don't forget to initialize the device in core! initialize_device ( & mut self . ctx , core_id ) ; Ok ( ( ) ) } Err ( toggle_error ) => { match toggle_error { ToggleError :: NoChange => Ok ( ( ) ) , ToggleError :: NotFound => Err ( fidl_net_stack :: Error :: NotFound ) , // Invalid device ID } } } } else { Ok ( ( ) ) } }
Enables an interface, adding it to the core if it is not currently enabled.
Enables an interface adding it to the core if it is not currently enabled .
&mut self
id
u64