async fn network_layer_state(
    addresses: impl IntoIterator<Item = LifIpAddr>,
    routes: &[hal::Route],
    p: &mut dyn Pinger,
    ping_address: &str,
) -> State {
    // TODO(https://fxbug.dev/36242) Check neighbor reachability and upgrade state to Local.
    let mut gateway_reachable = false;
    'outer: for a in addresses {
        for r in local_routes(&a, routes) {
            if let Some(gw_ip) = r.gateway {
                let gw_url = match gw_ip {
                    std::net::IpAddr::V4(_) => gw_ip.to_string(),
                    std::net::IpAddr::V6(v6) => {
                        if let Some(id) = r.port_id {
                            if net_types::ip::Ipv6Addr::new(v6.octets()).scope()
                                != net_types::ip::Ipv6Scope::Global
                            {
                                format!("{}%{}", gw_ip, id.to_u64())
                            } else {
                                gw_ip.to_string()
                            }
                        } else {
                            gw_ip.to_string()
                        }
                    }
                };
                if p.ping(&gw_url).await {
                    gateway_reachable = true;
                    break 'outer;
                }
            }
        }
    }
    if !gateway_reachable {
        return State::Local;
    }

    if !p.ping(ping_address).await {
        return State::Gateway;
    }
    return State::Internet;
}
// `network_layer_state` determines the L3 reachability state.
`network_layer_state` determines the L3 reachability state.
` network_layer_state ` determines the L3 reachability state .
async fn network_layer_state(
    addresses: impl IntoIterator<Item = LifIpAddr>,
    routes: &[hal::Route],
    p: &mut dyn Pinger,
    ping_address: &str,
) -> State {
    // TODO(https://fxbug.dev/36242) Check neighbor reachability and upgrade state to Local.
    let mut gateway_reachable = false;
    'outer: for a in addresses {
        for r in local_routes(&a, routes) {
            if let Some(gw_ip) = r.gateway {
                let gw_url = match gw_ip {
                    std::net::IpAddr::V4(_) => gw_ip.to_string(),
                    std::net::IpAddr::V6(v6) => {
                        if let Some(id) = r.port_id {
                            if net_types::ip::Ipv6Addr::new(v6.octets()).scope()
                                != net_types::ip::Ipv6Scope::Global
                            {
                                format!("{}%{}", gw_ip, id.to_u64())
                            } else {
                                gw_ip.to_string()
                            }
                        } else {
                            gw_ip.to_string()
                        }
                    }
                };
                if p.ping(&gw_url).await {
                    gateway_reachable = true;
                    break 'outer;
                }
            }
        }
    }
    if !gateway_reachable {
        return State::Local;
    }
    if !p.ping(ping_address).await {
        return State::Gateway;
    }
    return State::Internet;
}
async fn network_layer_state ( addresses : impl IntoIterator < Item = LifIpAddr > , routes : & [ hal :: Route ] , p : & mut dyn Pinger , ping_address : & str , ) -> State { // TODO(https://fxbug.dev/36242) Check neighbor reachability and upgrade state to Local. let mut gateway_reachable = false ; ' outer : for a in addresses { for r in local_routes ( & a , routes ) { if let Some ( gw_ip ) = r . gateway { let gw_url = match gw_ip { std :: net :: IpAddr :: V4 ( _ ) => gw_ip . to_string ( ) , std :: net :: IpAddr :: V6 ( v6 ) => { if let Some ( id ) = r . port_id { if net_types :: ip :: Ipv6Addr :: new ( v6 . octets ( ) ) . scope ( ) != net_types :: ip :: Ipv6Scope :: Global { format ! ( " " gw_ip id to_u64 ( ) ) } else { gw_ip . to_string ( ) } } else { gw_ip . to_string ( ) } } } ; if p . ping ( & gw_url ) . await { gateway_reachable = true ; break ' outer ; } } } } if ! gateway_reachable { return State :: Local ; } if ! p . ping ( ping_address ) . await { return State :: Gateway ; } return State :: Internet ; }
`network_layer_state` determines the L3 reachability state.
` network_layer_state ` determines the L3 reachability state .
addresses
impl IntoIterator<Item = LifIpAddr>
routes
&[hal::Route]
p
&mut dyn Pinger
ping_address
&str
addresses
impl IntoIterator<Item = LifIpAddr>
routes
&[hal::Route]
p
&mut dyn Pinger
ping_address
&str