/* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ #pragma once #include #include #include #include #include #include "ResolverStats.h" // TODO: stop depending on this internal header #include "dns_responder.h" #include "dns_tls_certificate.h" #include "params.h" inline const std::vector kDefaultServers = {"127.0.0.3"}; inline const std::vector kDefaultSearchDomains = {"example.com"}; inline const std::vector kDefaultParams = { 300, // sample validity in seconds 25, // success threshod in percent 8, 8, // {MIN,MAX}_SAMPLES 1000, // BASE_TIMEOUT_MSEC 2, // retry count }; #define SKIP_IF_REMOTE_VERSION_LESS_THAN(service, version) \ do { \ if (!DnsResponderClient::isRemoteVersionSupported(service, version)) { \ std::cerr << " Skip test. Remote version is too old, required version: " << version \ << std::endl; \ return; \ } \ } while (0) // TODO: Remove dns_responder_client_ndk.{h,cpp} after replacing the binder usage of // dns_responder_client.* class DnsResponderClient { public: struct Mapping { std::string host; std::string entry; std::string ip4; std::string ip6; }; virtual ~DnsResponderClient() = default; static void SetupMappings(unsigned num_hosts, const std::vector& domains, std::vector* mappings); // This function is deprecated. Please use SetResolversFromParcel() instead. bool SetResolversForNetwork(const std::vector& servers = kDefaultServers, const std::vector& domains = kDefaultSearchDomains, const std::vector& params = kDefaultParams); // This function is deprecated. Please use SetResolversFromParcel() instead. bool SetResolversWithTls(const std::vector& servers, const std::vector& searchDomains, const std::vector& params, const std::string& name) { // Pass servers as both network-assigned and TLS servers. Tests can // determine on which server and by which protocol queries arrived. return SetResolversWithTls(servers, searchDomains, params, servers, name); } // This function is deprecated. Please use SetResolversFromParcel() instead. bool SetResolversWithTls(const std::vector& servers, const std::vector& searchDomains, const std::vector& params, const std::vector& tlsServers, const std::string& name); bool SetResolversFromParcel(const aidl::android::net::ResolverParamsParcel& resolverParams); static bool isRemoteVersionSupported(aidl::android::net::IDnsResolver* dnsResolverService, int enabledVersion); static bool GetResolverInfo(aidl::android::net::IDnsResolver* dnsResolverService, unsigned netId, std::vector* servers, std::vector* domains, std::vector* tlsServers, res_params* params, std::vector* stats, int* waitForPendingReqTimeoutCount); // Return a default resolver configuration for opportunistic mode. static aidl::android::net::ResolverParamsParcel GetDefaultResolverParamsParcel(); static void SetupDNSServers(unsigned numServers, const std::vector& mappings, std::vector>* dns, std::vector* servers); static aidl::android::net::ResolverParamsParcel makeResolverParamsParcel( int netId, const std::vector& params, const std::vector& servers, const std::vector& domains, const std::string& tlsHostname, const std::vector& tlsServers, const std::string& caCert = ""); int SetupOemNetwork(); void TearDownOemNetwork(int oemNetId); virtual void SetUp(); virtual void TearDown(); aidl::android::net::IDnsResolver* resolvService() const { return mDnsResolvSrv.get(); } aidl::android::net::INetd* netdService() const { return mNetdSrv.get(); } private: std::shared_ptr mNetdSrv; std::shared_ptr mDnsResolvSrv; int mOemNetId = -1; };