Seastar
High performance C++ framework for concurrent servers
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
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 <system_error>
25#include <vector>
26#include <unordered_map>
27#include <memory>
28#include <seastar/util/std-compat.hh>
29
30#include <seastar/core/future.hh>
31#include <seastar/core/sstring.hh>
32#include <seastar/core/shared_ptr.hh>
33#include <seastar/net/inet_address.hh>
34
35namespace seastar {
36
37struct ipv4_addr;
38
39class socket_address;
40class network_stack;
41
48namespace net {
49
53struct hostent {
54 // Primary name is always first
55 std::vector<sstring> names;
56 // Primary address is also always first.
57 std::vector<inet_address> addr_list;
58};
59
60typedef std::optional<inet_address::family> opt_family;
61
62struct srv_record {
63 unsigned short priority;
64 unsigned short weight;
65 unsigned short port;
66 sstring target;
67};
68
78public:
79 struct options {
80 std::optional<bool>
81 use_tcp_query;
82 std::optional<std::vector<inet_address>>
83 servers;
84 std::optional<std::chrono::milliseconds>
85 timeout;
86 std::optional<uint16_t>
87 tcp_port, udp_port;
88 std::optional<std::vector<sstring>>
89 domains;
90 };
91
92 enum class srv_proto {
93 tcp, udp
94 };
95 using srv_records = std::vector<srv_record>;
96
98 dns_resolver(dns_resolver&&) noexcept;
99 explicit dns_resolver(const options&);
100 explicit dns_resolver(network_stack&, const options& = {});
101 ~dns_resolver();
102
103 dns_resolver& operator=(dns_resolver&&) noexcept;
104
108 future<hostent> get_host_by_name(const sstring&, opt_family = {});
113
117 future<inet_address> resolve_name(const sstring&, opt_family = {});
122
127 const sstring& service,
128 const sstring& domain);
129
134private:
135 class impl;
136 shared_ptr<impl> _impl;
137};
138
139namespace dns {
140
141// See above. These functions simply queries using a shard-local
142// default-stack, default-opts resolver
143future<hostent> get_host_by_name(const sstring&, opt_family = {});
144future<hostent> get_host_by_addr(const inet_address&);
145
146future<inet_address> resolve_name(const sstring&, opt_family = {});
147future<sstring> resolve_addr(const inet_address&);
148
149future<std::vector<srv_record>> get_srv_records(dns_resolver::srv_proto proto,
150 const sstring& service,
151 const sstring& domain);
152
158 const std::error_category& error_category();
159
160}
161
162}
163
164}
A representation of a possibly not-yet-computed value.
Definition: future.hh:1240
Definition: dns.hh:77
future< inet_address > resolve_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< hostent > get_host_by_name(const sstring &, opt_family={})
future< sstring > resolve_addr(const inet_address &)
Definition: inet_address.hh:50
Definition: tcp.hh:291
Definition: api.hh:447
holds the implementation parts of the metrics layer, do not use directly.
Definition: dns.hh:53
Definition: dns.hh:62
Seastar API namespace.
Definition: abort_on_ebadf.hh:26