async fn network_layer_state(
    mut addresses: impl Iterator<Item = LifIpAddr>,
    routes: &Option<Vec<hal::Route>>,
    info: &NetworkInfo,
    p: &dyn Pinger,
) -> State {
    // This interface is not configured for L3, Nothing to check.
    if !info.is_l3 {
        return info.state;
    }

    if info.state != State::LinkLayerUp || !has_local_neighbors() {
        return info.state;
    }

    // TODO(dpradilla): add support for multiple addresses.
    let address = addresses.next();
    if address.is_none() {
        return info.state;
    }

    let route_table = match routes {
        Some(r) => r,
        _ => return State::Local,
    };

    // Has local gateway.
    let rs = local_routes(&address.unwrap(), &route_table);
    if rs.is_empty() {
        return State::Local;
    }

    let mut gateway_active = false;
    for r in rs.iter() {
        if let Some(gw_ip) = r.gateway {
            if p.ping(&gw_ip.to_string()) {
                gateway_active = true;
                break;
            }
        }
    }
    if !gateway_active {
        return State::Local;
    }

    if !p.ping(INTERNET_CONNECTIVITY_CHECK_ADDRESS) {
        return State::Gateway;
    }
    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(
    mut addresses: impl Iterator<Item = LifIpAddr>,
    routes: &Option<Vec<hal::Route>>,
    info: &NetworkInfo,
    p: &dyn Pinger,
) -> State {
    // This interface is not configured for L3, Nothing to check.
    if !info.is_l3 {
        return info.state;
    }
    if info.state != State::LinkLayerUp || !has_local_neighbors() {
        return info.state;
    }
    // TODO(dpradilla): add support for multiple addresses.
    let address = addresses.next();
    if address.is_none() {
        return info.state;
    }
    let route_table = match routes {
        Some(r) => r,
        _ => return State::Local,
    };
    // Has local gateway.
    let rs = local_routes(&address.unwrap(), &route_table);
    if rs.is_empty() {
        return State::Local;
    }
    let mut gateway_active = false;
    for r in rs.iter() {
        if let Some(gw_ip) = r.gateway {
            if p.ping(&gw_ip.to_string()) {
                gateway_active = true;
                break;
            }
        }
    }
    if !gateway_active {
        return State::Local;
    }
    if !p.ping(INTERNET_CONNECTIVITY_CHECK_ADDRESS) {
        return State::Gateway;
    }
    State::Internet
}
async fn network_layer_state ( mut addresses : impl Iterator < Item = LifIpAddr > , routes : & Option < Vec < hal :: Route > > , info : & NetworkInfo , p : & dyn Pinger , ) -> State { // This interface is not configured for L3, Nothing to check. if ! info . is_l3 { return info . state ; } if info . state != State :: LinkLayerUp || ! has_local_neighbors ( ) { return info . state ; } // TODO(dpradilla): add support for multiple addresses. let address = addresses . next ( ) ; if address . is_none ( ) { return info . state ; } let route_table = match routes { Some ( r ) => r , _ => return State :: Local , } ; // Has local gateway. let rs = local_routes ( & address . unwrap ( ) , & route_table ) ; if rs . is_empty ( ) { return State :: Local ; } let mut gateway_active = false ; for r in rs . iter ( ) { if let Some ( gw_ip ) = r . gateway { if p . ping ( & gw_ip . to_string ( ) ) { gateway_active = true ; break ; } } } if ! gateway_active { return State :: Local ; } if ! p . ping ( INTERNET_CONNECTIVITY_CHECK_ADDRESS ) { return State :: Gateway ; } State :: Internet }
`network_layer_state` determines the L3 reachability state.
` network_layer_state ` determines the L3 reachability state .
addresses
impl Iterator<Item = LifIpAddr>
routes
&Option<Vec<hal::Route>>
info
&NetworkInfo
p
&dyn Pinger