Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 09b71026 authored by Xiao Ma's avatar Xiao Ma
Browse files

Abstract the general dns name server setup to avoid duplicated work.

    - add new method StartDns() in ResolverTest class to avoid duplicated
      start procedure.
    - provide the overload construct function for dns responder class with
      default parameter value.
    - add default value for SetResolversForNetwork() method.
    - define the common const variable in ResolverTest class scope.
    - add copyright information in dns_responder_client.h

Test: atest netd_unit_test netd_integration_test resolv_integration_test
Change-Id: I00812f380be7ab800d625b8cb5401445067e5a1c
parent ef48c322
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -36,6 +36,11 @@ struct DNSHeader;
struct DNSQuestion;
struct DNSRecord;

inline const std::string kDefaultListenAddr = "127.0.0.3";
inline const std::string kDefaultListenService = "53";
inline const int kDefaultPollTimoutMillis = 250;
inline const ns_rcode kDefaultErrorCode = ns_rcode::ns_r_servfail;

/*
 * Simple DNS responder, which replies to queries with the registered response
 * for that type. Class is assumed to be IN. If no response is registered, the
@@ -43,8 +48,10 @@ struct DNSRecord;
 */
class DNSResponder {
  public:
    DNSResponder(std::string listen_address, std::string listen_service, int poll_timeout_ms,
                 ns_rcode error_rcode);
    DNSResponder(std::string listen_address = kDefaultListenAddr,
                 std::string listen_service = kDefaultListenService,
                 int poll_timeout_ms = kDefaultPollTimoutMillis,
                 ns_rcode error_rcode = ns_rcode::ns_r_servfail);
    ~DNSResponder();

    enum class Edns : uint8_t {
+29 −2
Original line number Diff line number Diff line
/*
 * 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 requied 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.
 *
 */

#ifndef DNS_RESPONDER_CLIENT_H
#define DNS_RESPONDER_CLIENT_H

@@ -15,6 +32,15 @@
#include "NetdClient.h"
#include "dns_responder.h"

inline const std::vector<std::string> kDefaultServers = {"127.0.0.3"};
inline const std::vector<std::string> kDefaultSearchDomains = {"example.com"};
inline const std::vector<int> kDefaultParams = {
        300,     // sample validity in seconds
        25,      // success threshod in percent
        8,   8,  // {MIN,MAX}_SAMPLES
        100,     // BASE_TIMEOUT_MSEC
};

class DnsResponderClient {
public:
    struct Mapping {
@@ -29,8 +55,9 @@ public:
    static void SetupMappings(unsigned num_hosts, const std::vector<std::string>& domains,
            std::vector<Mapping>* mappings);

    bool SetResolversForNetwork(const std::vector<std::string>& servers,
            const std::vector<std::string>& domains, const std::vector<int>& params);
    bool SetResolversForNetwork(const std::vector<std::string>& servers = kDefaultServers,
                                const std::vector<std::string>& domains = kDefaultSearchDomains,
                                const std::vector<int>& params = kDefaultParams);

    bool SetResolversForNetwork(const std::vector<std::string>& servers,
            const std::vector<std::string>& searchDomains,
+474 −552

File changed.

Preview size limit exceeded, changes collapsed.