pub async fn verify_v6_dns_servers(
    interface_id: u64,
    want_dns_servers: Vec<fnetname::DnsServer_>,
) -> Result<(), Error> {
    let stack = client::connect_to_protocol::<fstack::StackMarker>()
        .context("connecting to stack service")?;
    let info = stack
        .get_interface_info(interface_id)
        .await
        .squash_result()
        .context("getting interface info")?;

    let addr = info
        .properties
        .addresses
        .into_iter()
        .find_map(|addr: fnet::Subnet| match addr.addr {
            fnet::IpAddress::Ipv4(_addr) => None,
            fnet::IpAddress::Ipv6(addr) => {
                // Only use link-local addresses.
                //
                // TODO(https://github.com/rust-lang/rust/issues/27709): use
                // `is_unicast_link_local_strict` when it's available in stable Rust.
                if addr.addr[..8] == [0xfe, 0x80, 0, 0, 0, 0, 0, 0] {
                    Some(addr)
                } else {
                    None
                }
            }
        })
        .ok_or(format_err!("no addresses found to start DHCPv6 client on"))?;

    let provider = client::connect_to_protocol::<fdhcpv6::ClientProviderMarker>()
        .context("connecting to DHCPv6 client")?;

    let (client_end, server_end) = fidl::endpoints::create_endpoints::<fdhcpv6::ClientMarker>()
        .context("creating DHCPv6 client channel")?;
    let () = provider.new_client(
        fdhcpv6::NewClientParams {
            interface_id: Some(interface_id),
            address: Some(fnet::Ipv6SocketAddress {
                address: addr,
                port: fdhcpv6::DEFAULT_CLIENT_PORT,
                zone_index: interface_id,
            }),
            config: Some(fdhcpv6::ClientConfig {
                information_config: Some(fdhcpv6::InformationConfig {
                    dns_servers: Some(true),
                    ..fdhcpv6::InformationConfig::EMPTY
                }),
                ..fdhcpv6::ClientConfig::EMPTY
            }),
            ..fdhcpv6::NewClientParams::EMPTY
        },
        server_end,
    )?;
    let client_proxy = client_end.into_proxy().context("getting client proxy from channel")?;

    let got_dns_servers = client_proxy.watch_servers().await.context("watching DNS servers")?;
    if got_dns_servers == want_dns_servers {
        Ok(())
    } else {
        Err(format_err!(
            "DHCPv6 client received unexpected DNS servers:\ngot dns servers: {:?}\n, want dns servers: {:?}\n",
            got_dns_servers,
            want_dns_servers
        ))
    }
}
/// Verifies a DHCPv6 client can receive an expected list of DNS servers.
///
/// # Arguments
///
/// * `interface_id` - ID identifying the interface to start the DHCPv6 client on.
/// * `want_dns_servers` - Vector of DNS servers that the DHCPv6 client is expected to receive.
Verifies a DHCPv6 client can receive an expected list of DNS servers.
Verifies a DHCPv6 client can receive an expected list of DNS servers .
pub async fn verify_v6_dns_servers(
    interface_id: u64,
    want_dns_servers: Vec<fnetname::DnsServer_>,
) -> Result<(), Error> {
    let stack = client::connect_to_protocol::<fstack::StackMarker>()
        .context("connecting to stack service")?;
    let info = stack
        .get_interface_info(interface_id)
        .await
        .squash_result()
        .context("getting interface info")?;
    let addr = info
        .properties
        .addresses
        .into_iter()
        .find_map(|addr: fnet::Subnet| match addr.addr {
            fnet::IpAddress::Ipv4(_addr) => None,
            fnet::IpAddress::Ipv6(addr) => {
                // Only use link-local addresses.
                //
                // TODO(https://github.com/rust-lang/rust/issues/27709): use
                // `is_unicast_link_local_strict` when it's available in stable Rust.
                if addr.addr[..8] == [0xfe, 0x80, 0, 0, 0, 0, 0, 0] {
                    Some(addr)
                } else {
                    None
                }
            }
        })
        .ok_or(format_err!("no addresses found to start DHCPv6 client on"))?;
    let provider = client::connect_to_protocol::<fdhcpv6::ClientProviderMarker>()
        .context("connecting to DHCPv6 client")?;
    let (client_end, server_end) = fidl::endpoints::create_endpoints::<fdhcpv6::ClientMarker>()
        .context("creating DHCPv6 client channel")?;
    let () = provider.new_client(
        fdhcpv6::NewClientParams {
            interface_id: Some(interface_id),
            address: Some(fnet::Ipv6SocketAddress {
                address: addr,
                port: fdhcpv6::DEFAULT_CLIENT_PORT,
                zone_index: interface_id,
            }),
            config: Some(fdhcpv6::ClientConfig {
                information_config: Some(fdhcpv6::InformationConfig {
                    dns_servers: Some(true),
                    ..fdhcpv6::InformationConfig::EMPTY
                }),
                ..fdhcpv6::ClientConfig::EMPTY
            }),
            ..fdhcpv6::NewClientParams::EMPTY
        },
        server_end,
    )?;
    let client_proxy = client_end.into_proxy().context("getting client proxy from channel")?;
    let got_dns_servers = client_proxy.watch_servers().await.context("watching DNS servers")?;
    if got_dns_servers == want_dns_servers {
        Ok(())
    } else {
        Err(format_err!(
            "DHCPv6 client received unexpected DNS servers:\ngot dns servers: {:?}\n, want dns servers: {:?}\n",
            got_dns_servers,
            want_dns_servers
        ))
    }
}
pub async fn verify_v6_dns_servers ( interface_id : u64 , want_dns_servers : Vec < fnetname :: DnsServer_ > , ) -> Result < ( ) , Error > { let stack = client :: connect_to_protocol :: < fstack :: StackMarker > ( ) . context ( " " ) ? ; let info = stack . get_interface_info ( interface_id ) . await . squash_result ( ) . context ( " " ) ? ; let addr = info . properties . addresses . into_iter ( ) . find_map ( | addr : fnet :: Subnet | match addr . addr { fnet :: IpAddress :: Ipv4 ( _addr ) => None , fnet :: IpAddress :: Ipv6 ( addr ) => { // Only use link-local addresses. // // TODO(https://github.com/rust-lang/rust/issues/27709): use // `is_unicast_link_local_strict` when it's available in stable Rust. if addr . addr [ .. 8 ] == [ 0xfe , 0x80 , 0 , 0 , 0 , 0 , 0 , 0 ] { Some ( addr ) } else { None } } } ) . ok_or ( format_err ! ( " " ) ) ? ; let provider = client :: connect_to_protocol :: < fdhcpv6 :: ClientProviderMarker > ( ) . context ( " " ) ? ; let ( client_end , server_end ) = fidl :: endpoints :: create_endpoints :: < fdhcpv6 :: ClientMarker > ( ) . context ( " " ) ? ; let ( ) = provider . new_client ( fdhcpv6 :: NewClientParams { interface_id : Some ( interface_id ) , address : Some ( fnet :: Ipv6SocketAddress { address : addr , port : fdhcpv6 :: DEFAULT_CLIENT_PORT , zone_index : interface_id , } ) , config : Some ( fdhcpv6 :: ClientConfig { information_config : Some ( fdhcpv6 :: InformationConfig { dns_servers : Some ( true ) , .. fdhcpv6 :: InformationConfig :: EMPTY } ) , .. fdhcpv6 :: ClientConfig :: EMPTY } ) , .. fdhcpv6 :: NewClientParams :: EMPTY } , server_end , ) ? ; let client_proxy = client_end . into_proxy ( ) . context ( " " ) ? ; let got_dns_servers = client_proxy . watch_servers ( ) . await . context ( " " ) ? ; if got_dns_servers == want_dns_servers { Ok ( ( ) ) } else { Err ( format_err ! ( " \n \n \n " got_dns_servers want_dns_servers ) ) } }
Verifies a DHCPv6 client can receive an expected list of DNS servers.
Verifies a DHCPv6 client can receive an expected list of DNS servers .
interface_id
u64
want_dns_servers
Vec<fnetname::DnsServer_>
interface_id
u64
want_dns_servers
Vec<fnetname::DnsServer_>