async fn configure_wlan_ap_and_dhcp_server(
        &mut self,
        interface_id: u32,
        name: String,
    ) -> Result<(), errors::Error> {
        // Calculate and set the interface address based on the network address.
        // The interface address should be the first available address.
        let network_addr_as_u32 = u32::from_be_bytes(WLAN_AP_NETWORK_ADDR.addr);
        let interface_addr_as_u32 = network_addr_as_u32 + 1;
        let addr = fnet::Ipv4Address { addr: interface_addr_as_u32.to_be_bytes() };
        let fnetstack::NetErr { status, message } = self
            .netstack
            .set_interface_address(interface_id, &mut addr.into_ext(), WLAN_AP_PREFIX_LEN)
            .await
            .context("error sending set interface address request")
            .map_err(errors::Error::Fatal)?;
        if status != fnetstack::Status::Ok {
            // Do not consider this a fatal error because the interface could
            // have been removed after it was added, but before we reached
            // this point.
            return Err(errors::Error::NonFatal(anyhow::anyhow!(
                "failed to set interface address for WLAN AP with status = {:?}: {}",
                status,
                message
            )));
        }

        let dhcp_server = if let Some(dhcp_server) = &self.dhcp_server {
            dhcp_server
        } else {
            warn!("cannot configure DHCP server for WLAN AP (interface ID={}) since DHCP server service is not available", interface_id);
            return Ok(());
        };

        // First we clear any leases that the server knows about since the server
        // will be used on a new interface. If leases exist, configuring the DHCP
        // server parameters may fail (AddressPool).
        debug!("clearing DHCP leases");
        let () = dhcp_server
            .clear_leases()
            .await
            .context("error sending clear DHCP leases request")
            .map_err(errors::Error::NonFatal)?
            .map_err(zx::Status::from_raw)
            .context("error clearing DHCP leases request")
            .map_err(errors::Error::NonFatal)?;

        // Configure the DHCP server.
        let v = vec![addr.into()];
        debug!("setting DHCP IpAddrs parameter to {:?}", v);
        let () = dhcp_server
            .set_parameter(&mut fnet_dhcp::Parameter::IpAddrs(v))
            .await
            .context("error sending set DHCP IpAddrs parameter request")
            .map_err(errors::Error::NonFatal)?
            .map_err(zx::Status::from_raw)
            .context("error setting DHCP IpAddrs parameter")
            .map_err(errors::Error::NonFatal)?;

        let v = vec![name];
        debug!("setting DHCP BoundDeviceNames parameter to {:?}", v);
        let () = dhcp_server
            .set_parameter(&mut fnet_dhcp::Parameter::BoundDeviceNames(v))
            .await
            .context("error sending set DHCP BoundDeviceName parameter request")
            .map_err(errors::Error::NonFatal)?
            .map_err(zx::Status::from_raw)
            .context("error setting DHCP BoundDeviceNames parameter")
            .map_err(errors::Error::NonFatal)?;

        let v = fnet_dhcp::LeaseLength {
            default: Some(WLAN_AP_DHCP_LEASE_TIME_SECONDS),
            max: Some(WLAN_AP_DHCP_LEASE_TIME_SECONDS),
            ..fnet_dhcp::LeaseLength::EMPTY
        };
        debug!("setting DHCP LeaseLength parameter to {:?}", v);
        let () = dhcp_server
            .set_parameter(&mut fnet_dhcp::Parameter::Lease(v))
            .await
            .context("error sending set DHCP LeaseLength parameter request")
            .map_err(errors::Error::NonFatal)?
            .map_err(zx::Status::from_raw)
            .context("error setting DHCP LeaseLength parameter")
            .map_err(errors::Error::NonFatal)?;

        let host_mask = dhcp::configuration::SubnetMask::try_from(WLAN_AP_PREFIX_LEN)
            .context("error creating host mask from prefix length")
            .map_err(errors::Error::NonFatal)?;
        let broadcast_addr =
            host_mask.broadcast_of(&std::net::Ipv4Addr::from_fidl(WLAN_AP_NETWORK_ADDR));
        let broadcast_addr_as_u32: u32 = broadcast_addr.into();
        // The start address of the DHCP pool should be the first address after the WLAN AP
        // interface address.
        let dhcp_pool_start =
            fnet::Ipv4Address { addr: (interface_addr_as_u32 + 1).to_be_bytes() }.into();
        // The last address of the DHCP pool should be the last available address
        // in the interface's network. This is the address immediately before the
        // network's broadcast address.
        let dhcp_pool_end = fnet::Ipv4Address { addr: (broadcast_addr_as_u32 - 1).to_be_bytes() };

        let v = fnet_dhcp::AddressPool {
            prefix_length: Some(WLAN_AP_PREFIX_LEN),
            range_start: Some(dhcp_pool_start),
            range_stop: Some(dhcp_pool_end),
            ..fnet_dhcp::AddressPool::EMPTY
        };
        debug!("setting DHCP AddressPool parameter to {:?}", v);
        dhcp_server
            .set_parameter(&mut fnet_dhcp::Parameter::AddressPool(v))
            .await
            .context("error sending set DHCP AddressPool parameter request")
            .map_err(errors::Error::NonFatal)?
            .map_err(zx::Status::from_raw)
            .context("error setting DHCP AddressPool parameter")
            .map_err(errors::Error::NonFatal)
    }
/// Configure the WLAN AP and the DHCP server to serve requests on its network.
///
/// Note, this method will not start the DHCP server, it will only be configured
/// with the parameters so it is ready to be started when an interface UP event
/// is received for the WLAN AP.
Configure the WLAN AP and the DHCP server to serve requests on its network.
Note, this method will not start the DHCP server, it will only be configured
with the parameters so it is ready to be started when an interface UP event
is received for the WLAN AP.
Configure the WLAN AP and the DHCP server to serve requests on its network . Note this method will not start the DHCP server it will only be configured with the parameters so it is ready to be started when an interface UP event is received for the WLAN AP .
async fn configure_wlan_ap_and_dhcp_server(
        &mut self,
        interface_id: u32,
        name: String,
    ) -> Result<(), errors::Error> {
        // Calculate and set the interface address based on the network address.
        // The interface address should be the first available address.
        let network_addr_as_u32 = u32::from_be_bytes(WLAN_AP_NETWORK_ADDR.addr);
        let interface_addr_as_u32 = network_addr_as_u32 + 1;
        let addr = fnet::Ipv4Address { addr: interface_addr_as_u32.to_be_bytes() };
        let fnetstack::NetErr { status, message } = self
            .netstack
            .set_interface_address(interface_id, &mut addr.into_ext(), WLAN_AP_PREFIX_LEN)
            .await
            .context("error sending set interface address request")
            .map_err(errors::Error::Fatal)?;
        if status != fnetstack::Status::Ok {
            // Do not consider this a fatal error because the interface could
            // have been removed after it was added, but before we reached
            // this point.
            return Err(errors::Error::NonFatal(anyhow::anyhow!(
                "failed to set interface address for WLAN AP with status = {:?}: {}",
                status,
                message
            )));
        }
        let dhcp_server = if let Some(dhcp_server) = &self.dhcp_server {
            dhcp_server
        } else {
            warn!("cannot configure DHCP server for WLAN AP (interface ID={}) since DHCP server service is not available", interface_id);
            return Ok(());
        };
        // First we clear any leases that the server knows about since the server
        // will be used on a new interface. If leases exist, configuring the DHCP
        // server parameters may fail (AddressPool).
        debug!("clearing DHCP leases");
        let () = dhcp_server
            .clear_leases()
            .await
            .context("error sending clear DHCP leases request")
            .map_err(errors::Error::NonFatal)?
            .map_err(zx::Status::from_raw)
            .context("error clearing DHCP leases request")
            .map_err(errors::Error::NonFatal)?;
        // Configure the DHCP server.
        let v = vec![addr.into()];
        debug!("setting DHCP IpAddrs parameter to {:?}", v);
        let () = dhcp_server
            .set_parameter(&mut fnet_dhcp::Parameter::IpAddrs(v))
            .await
            .context("error sending set DHCP IpAddrs parameter request")
            .map_err(errors::Error::NonFatal)?
            .map_err(zx::Status::from_raw)
            .context("error setting DHCP IpAddrs parameter")
            .map_err(errors::Error::NonFatal)?;
        let v = vec![name];
        debug!("setting DHCP BoundDeviceNames parameter to {:?}", v);
        let () = dhcp_server
            .set_parameter(&mut fnet_dhcp::Parameter::BoundDeviceNames(v))
            .await
            .context("error sending set DHCP BoundDeviceName parameter request")
            .map_err(errors::Error::NonFatal)?
            .map_err(zx::Status::from_raw)
            .context("error setting DHCP BoundDeviceNames parameter")
            .map_err(errors::Error::NonFatal)?;
        let v = fnet_dhcp::LeaseLength {
            default: Some(WLAN_AP_DHCP_LEASE_TIME_SECONDS),
            max: Some(WLAN_AP_DHCP_LEASE_TIME_SECONDS),
            ..fnet_dhcp::LeaseLength::EMPTY
        };
        debug!("setting DHCP LeaseLength parameter to {:?}", v);
        let () = dhcp_server
            .set_parameter(&mut fnet_dhcp::Parameter::Lease(v))
            .await
            .context("error sending set DHCP LeaseLength parameter request")
            .map_err(errors::Error::NonFatal)?
            .map_err(zx::Status::from_raw)
            .context("error setting DHCP LeaseLength parameter")
            .map_err(errors::Error::NonFatal)?;
        let host_mask = dhcp::configuration::SubnetMask::try_from(WLAN_AP_PREFIX_LEN)
            .context("error creating host mask from prefix length")
            .map_err(errors::Error::NonFatal)?;
        let broadcast_addr =
            host_mask.broadcast_of(&std::net::Ipv4Addr::from_fidl(WLAN_AP_NETWORK_ADDR));
        let broadcast_addr_as_u32: u32 = broadcast_addr.into();
        // The start address of the DHCP pool should be the first address after the WLAN AP
        // interface address.
        let dhcp_pool_start =
            fnet::Ipv4Address { addr: (interface_addr_as_u32 + 1).to_be_bytes() }.into();
        // The last address of the DHCP pool should be the last available address
        // in the interface's network. This is the address immediately before the
        // network's broadcast address.
        let dhcp_pool_end = fnet::Ipv4Address { addr: (broadcast_addr_as_u32 - 1).to_be_bytes() };
        let v = fnet_dhcp::AddressPool {
            prefix_length: Some(WLAN_AP_PREFIX_LEN),
            range_start: Some(dhcp_pool_start),
            range_stop: Some(dhcp_pool_end),
            ..fnet_dhcp::AddressPool::EMPTY
        };
        debug!("setting DHCP AddressPool parameter to {:?}", v);
        dhcp_server
            .set_parameter(&mut fnet_dhcp::Parameter::AddressPool(v))
            .await
            .context("error sending set DHCP AddressPool parameter request")
            .map_err(errors::Error::NonFatal)?
            .map_err(zx::Status::from_raw)
            .context("error setting DHCP AddressPool parameter")
            .map_err(errors::Error::NonFatal)
    }
async fn configure_wlan_ap_and_dhcp_server ( & mut self , interface_id : u32 , name : String , ) -> Result < ( ) , errors :: Error > { // Calculate and set the interface address based on the network address. // The interface address should be the first available address. let network_addr_as_u32 = u32 :: from_be_bytes ( WLAN_AP_NETWORK_ADDR . addr ) ; let interface_addr_as_u32 = network_addr_as_u32 + 1 ; let addr = fnet :: Ipv4Address { addr : interface_addr_as_u32 . to_be_bytes ( ) } ; let fnetstack :: NetErr { status , message } = self . netstack . set_interface_address ( interface_id , & mut addr . into_ext ( ) , WLAN_AP_PREFIX_LEN ) . await . context ( " " ) . map_err ( errors :: Error :: Fatal ) ? ; if status != fnetstack :: Status :: Ok { // Do not consider this a fatal error because the interface could // have been removed after it was added, but before we reached // this point. return Err ( errors :: Error :: NonFatal ( anyhow :: anyhow ! ( " " status message ) ) ) ; } let dhcp_server = if let Some ( dhcp_server ) = & self . dhcp_server { dhcp_server } else { warn ! ( " " interface_id ) ; return Ok ( ( ) ) ; } ; // First we clear any leases that the server knows about since the server // will be used on a new interface. If leases exist, configuring the DHCP // server parameters may fail (AddressPool). debug ! ( " " ) ; let ( ) = dhcp_server . clear_leases ( ) . await . context ( " " ) . map_err ( errors :: Error :: NonFatal ) ? . map_err ( zx :: Status :: from_raw ) . context ( " " ) . map_err ( errors :: Error :: NonFatal ) ? ; // Configure the DHCP server. let v = vec ! [ addr into ( ) ] ; debug ! ( " " v ) ; let ( ) = dhcp_server . set_parameter ( & mut fnet_dhcp :: Parameter :: IpAddrs ( v ) ) . await . context ( " " ) . map_err ( errors :: Error :: NonFatal ) ? . map_err ( zx :: Status :: from_raw ) . context ( " " ) . map_err ( errors :: Error :: NonFatal ) ? ; let v = vec ! [ name ] ; debug ! ( " " v ) ; let ( ) = dhcp_server . set_parameter ( & mut fnet_dhcp :: Parameter :: BoundDeviceNames ( v ) ) . await . context ( " " ) . map_err ( errors :: Error :: NonFatal ) ? . map_err ( zx :: Status :: from_raw ) . context ( " " ) . map_err ( errors :: Error :: NonFatal ) ? ; let v = fnet_dhcp :: LeaseLength { default : Some ( WLAN_AP_DHCP_LEASE_TIME_SECONDS ) , max : Some ( WLAN_AP_DHCP_LEASE_TIME_SECONDS ) , .. fnet_dhcp :: LeaseLength :: EMPTY } ; debug ! ( " " v ) ; let ( ) = dhcp_server . set_parameter ( & mut fnet_dhcp :: Parameter :: Lease ( v ) ) . await . context ( " " ) . map_err ( errors :: Error :: NonFatal ) ? . map_err ( zx :: Status :: from_raw ) . context ( " " ) . map_err ( errors :: Error :: NonFatal ) ? ; let host_mask = dhcp :: configuration :: SubnetMask :: try_from ( WLAN_AP_PREFIX_LEN ) . context ( " " ) . map_err ( errors :: Error :: NonFatal ) ? ; let broadcast_addr = host_mask . broadcast_of ( & std :: net :: Ipv4Addr :: from_fidl ( WLAN_AP_NETWORK_ADDR ) ) ; let broadcast_addr_as_u32 : u32 = broadcast_addr . into ( ) ; // The start address of the DHCP pool should be the first address after the WLAN AP // interface address. let dhcp_pool_start = fnet :: Ipv4Address { addr : ( interface_addr_as_u32 + 1 ) . to_be_bytes ( ) } . into ( ) ; // The last address of the DHCP pool should be the last available address // in the interface's network. This is the address immediately before the // network's broadcast address. let dhcp_pool_end = fnet :: Ipv4Address { addr : ( broadcast_addr_as_u32 - 1 ) . to_be_bytes ( ) } ; let v = fnet_dhcp :: AddressPool { prefix_length : Some ( WLAN_AP_PREFIX_LEN ) , range_start : Some ( dhcp_pool_start ) , range_stop : Some ( dhcp_pool_end ) , .. fnet_dhcp :: AddressPool :: EMPTY } ; debug ! ( " " v ) ; dhcp_server . set_parameter ( & mut fnet_dhcp :: Parameter :: AddressPool ( v ) ) . await . context ( " " ) . map_err ( errors :: Error :: NonFatal ) ? . map_err ( zx :: Status :: from_raw ) . context ( " " ) . map_err ( errors :: Error :: NonFatal ) }
Configure the WLAN AP and the DHCP server to serve requests on its network.
Configure the WLAN AP and the DHCP server to serve requests on its network .
&mut self
interface_id
u32
name
String
&mut self
interface_id
u32
name
String