blob: 987d28974af1ee92d161ac74b7d4a7f4dd0cda56 [file] [log] [blame]
/*
* 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 <arpa/nameser.h>
#include <netdb.h>
#include <string>
#include <vector>
#include <netdutils/InternetAddresses.h>
#include "ResolverStats.h"
#include "android/net/IDnsResolver.h"
#include "dns_responder/dns_responder.h"
#include "netd_resolv/params.h"
// TODO: make this dynamic and stop depending on implementation details.
constexpr int TEST_NETID = 30;
// Specifying 0 in ai_socktype or ai_protocol of struct addrinfo indicates that any type or
// protocol can be returned by getaddrinfo().
constexpr unsigned int ANY = 0;
static constexpr char kLocalHost[] = "localhost";
static constexpr char kLocalHostAddr[] = "127.0.0.1";
static constexpr char kIp6LocalHost[] = "ip6-localhost";
static constexpr char kIp6LocalHostAddr[] = "::1";
static constexpr char kHelloExampleCom[] = "hello.example.com.";
// Illegal hostnames
static constexpr char kBadCharAfterPeriodHost[] = "hello.example.^com.";
static constexpr char kBadCharBeforePeriodHost[] = "hello.example^.com.";
static constexpr char kBadCharAtTheEndHost[] = "hello.example.com^.";
static constexpr char kBadCharInTheMiddleOfLabelHost[] = "hello.ex^ample.com.";
static const test::DNSHeader kDefaultDnsHeader = {
// Don't need to initialize the flag "id" and "rd" because DNS responder assigns them from
// query to response. See RFC 1035 section 4.1.1.
.id = 0, // unused. should be assigned from query to response
.ra = false, // recursive query support is not available
.rcode = ns_r_noerror, // no error
.qr = true, // message is a response
.opcode = QUERY, // a standard query
.aa = false, // answer/authority portion was not authenticated by the server
.tr = false, // message is not truncated
.rd = false, // unused. should be assigned from query to response
.ad = false, // non-authenticated data is unacceptable
};
size_t GetNumQueries(const test::DNSResponder& dns, const char* name);
size_t GetNumQueriesForType(const test::DNSResponder& dns, ns_type type, const char* name);
std::string ToString(const hostent* he);
std::string ToString(const addrinfo* ai);
std::string ToString(const android::netdutils::ScopedAddrinfo& ai);
std::vector<std::string> ToStrings(const addrinfo* ai);
std::vector<std::string> ToStrings(const android::netdutils::ScopedAddrinfo& ai);
bool GetResolverInfo(android::net::IDnsResolver* dnsResolverService, unsigned netId,
std::vector<std::string>* servers, std::vector<std::string>* domains,
std::vector<std::string>* tlsServers, res_params* params,
std::vector<android::net::ResolverStats>* stats,
int* wait_for_pending_req_timeout_count);