Seastar
High performance C++ framework for concurrent servers
dns.hh
1 /*
2  * This file is open source software, licensed to you under the terms
3  * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4  * distributed with this work for additional information regarding copyright
5  * ownership. You may not use this file except in compliance with the License.
6  *
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an
13  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14  * KIND, either express or implied. See the License for the
15  * specific language governing permissions and limitations
16  * under the License.
17  */
18 /*
19  * Copyright 2016 Cloudius Systems
20  */
21 
22 #pragma once
23 
24 #include <vector>
25 #include <unordered_map>
26 #include <memory>
27 #include <seastar/util/std-compat.hh>
28 
29 #include <seastar/core/future.hh>
30 #include <seastar/core/sstring.hh>
31 #include <seastar/core/shared_ptr.hh>
32 #include <seastar/net/inet_address.hh>
33 
34 namespace seastar {
35 
36 struct ipv4_addr;
37 
38 class socket_address;
39 class network_stack;
40 
47 namespace net {
48 
52 struct hostent {
53  // Primary name is always first
54  std::vector<sstring> names;
55  // Primary address is also always first.
56  std::vector<inet_address> addr_list;
57 };
58 
59 typedef std::optional<inet_address::family> opt_family;
60 
61 struct srv_record {
62  unsigned short priority;
63  unsigned short weight;
64  unsigned short port;
65  sstring target;
66 };
67 
76 class dns_resolver {
77 public:
78  struct options {
79  std::optional<bool>
80  use_tcp_query;
81  std::optional<std::vector<inet_address>>
82  servers;
83  std::optional<std::chrono::milliseconds>
84  timeout;
85  std::optional<uint16_t>
86  tcp_port, udp_port;
87  std::optional<std::vector<sstring>>
88  domains;
89  };
90 
91  enum class srv_proto {
92  tcp, udp
93  };
94  using srv_records = std::vector<srv_record>;
95 
96  dns_resolver();
97  dns_resolver(dns_resolver&&) noexcept;
98  explicit dns_resolver(const options&);
99  explicit dns_resolver(network_stack&, const options& = {});
100  ~dns_resolver();
101 
102  dns_resolver& operator=(dns_resolver&&) noexcept;
103 
107  future<hostent> get_host_by_name(const sstring&, opt_family = {});
112 
116  future<inet_address> resolve_name(const sstring&, opt_family = {});
121 
126  const sstring& service,
127  const sstring& domain);
128 
133 private:
134  class impl;
135  shared_ptr<impl> _impl;
136 };
137 
138 namespace dns {
139 
140 // See above. These functions simply queries using a shard-local
141 // default-stack, default-opts resolver
142 future<hostent> get_host_by_name(const sstring&, opt_family = {});
143 future<hostent> get_host_by_addr(const inet_address&);
144 
145 future<inet_address> resolve_name(const sstring&, opt_family = {});
146 future<sstring> resolve_addr(const inet_address&);
147 
148 future<std::vector<srv_record>> get_srv_records(dns_resolver::srv_proto proto,
149  const sstring& service,
150  const sstring& domain);
151 
152 }
153 
154 }
155 
156 }
A representation of a possibly not-yet-computed value.
Definition: future.hh:1238
Definition: dns.hh:76
future< hostent > get_host_by_name(const sstring &, opt_family={})
future< srv_records > get_srv_records(srv_proto proto, const sstring &service, const sstring &domain)
future< hostent > get_host_by_addr(const inet_address &)
future< sstring > resolve_addr(const inet_address &)
future< inet_address > resolve_name(const sstring &, opt_family={})
Definition: inet_address.hh:49
Definition: tcp.hh:294
Definition: api.hh:427
holds the implementation parts of the metrics layer, do not use directly.
Definition: dns.hh:52
Definition: dns.hh:61
Seastar API namespace.
Definition: abort_on_ebadf.hh:26