forked from scylladb/seastar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdns.hh
133 lines (111 loc) · 3.42 KB
/
dns.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* This file is open source software, licensed to you under the terms
* of the Apache License, Version 2.0 (the "License"). See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. 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.
*/
/*
* Copyright 2016 Cloudius Systems
*/
#pragma once
#include <vector>
#include <unordered_map>
#include <memory>
#include <experimental/optional>
#include "../core/future.hh"
#include "../core/sstring.hh"
#include "../core/shared_ptr.hh"
#include "inet_address.hh"
namespace seastar {
struct ipv4_addr;
class socket_address;
class network_stack;
/**
* C-ares based dns query support.
* Handles name- and ip-based resolution.
*
*/
namespace net {
/**
* A c++-esque version of a hostent
*/
struct hostent {
// Primary name is always first
std::vector<sstring> names;
// Primary address is also always first.
std::vector<inet_address> addr_list;
};
typedef std::experimental::optional<inet_address::family> opt_family;
/**
* A DNS resolver object.
* Wraps the query logic & networking.
* Can be instantiated with options and your network
* stack of choice, though for "normal" non-test
* querying, you are probably better of with the
* global calls further down.
*/
class dns_resolver {
public:
struct options {
std::experimental::optional<bool>
use_tcp_query;
std::experimental::optional<std::vector<inet_address>>
servers;
std::experimental::optional<std::chrono::milliseconds>
timeout;
std::experimental::optional<uint16_t>
tcp_port, udp_port;
std::experimental::optional<std::vector<sstring>>
domains;
};
dns_resolver();
dns_resolver(dns_resolver&&) noexcept;
explicit dns_resolver(const options&);
explicit dns_resolver(network_stack&, const options& = {});
~dns_resolver();
dns_resolver& operator=(dns_resolver&&) noexcept;
/**
* Resolves a hostname to one or more addresses and aliases
*/
future<hostent> get_host_by_name(const sstring&, opt_family = {});
/**
* Resolves an address to one or more addresses and aliases
*/
future<hostent> get_host_by_addr(const inet_address&);
/**
* Resolves a hostname to one (primary) address
*/
future<inet_address> resolve_name(const sstring&, opt_family = {});
/**
* Resolves an address to one (primary) name
*/
future<sstring> resolve_addr(const inet_address&);
/**
* Shuts the object down. Great for tests.
*/
future<> close();
private:
class impl;
shared_ptr<impl> _impl;
};
namespace dns {
// See above. These functions simply queries using a shard-local
// default-stack, default-opts resolver
future<hostent> get_host_by_name(const sstring&, opt_family = {});
future<hostent> get_host_by_addr(const inet_address&);
future<inet_address> resolve_name(const sstring&, opt_family = {});
future<sstring> resolve_addr(const inet_address&);
}
}
}