Kea 3.3.3
dns_client.h
Go to the documentation of this file.
1// Copyright (C) 2013-2026 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef DNS_CLIENT_H
8#define DNS_CLIENT_H
9
10#include <asiodns/io_fetch.h>
11#include <asiolink/io_service.h>
12#include <d2srv/d2_tsig_key.h>
14#include <util/buffer.h>
15
16#include <cstdint>
17
18namespace isc {
19namespace d2 {
20
21class DNSClient;
22typedef boost::shared_ptr<DNSClient> DNSClientPtr;
23
25class DNSClientImpl;
26
49class DNSClient {
50public:
51
54 enum Protocol : uint16_t {
57 };
58
60 enum Status : uint16_t {
61 SUCCESS = 0,
62 TIMEOUT = 1,
65 OTHER = 4,
66 };
67
73 static std::string const& statusToText(Status const& status) {
74 static std::vector<std::string> const text_vector {
75 "SUCCESS",
76 "TIMEOUT",
77 "IO_STOPPED",
78 "INVALID_RESPONSE",
79 "OTHER",
80 };
81 static std::string const unknown("UNKNOWN");
82 return (status < text_vector.size() ? text_vector[status] : unknown);
83 }
84
91 class Callback {
92 public:
94 virtual ~Callback() { }
95
100 virtual void operator()(DNSClient::Status status) = 0;
101 };
102
112 DNSClient(D2UpdateMessagePtr& response_placeholder, Callback* callback,
113 const Protocol proto = UDP);
114
116 ~DNSClient();
117
119 void stop();
120
129
130private:
131 DNSClient(const DNSClient& source);
132 DNSClient& operator=(const DNSClient& source);
134
135public:
136
141 static unsigned int getMaxTimeout();
142
164 void doUpdate(const asiolink::IOServicePtr& io_service,
165 const asiolink::IOAddress& ns_addr,
166 const uint16_t ns_port,
167 D2UpdateMessage& update,
168 const unsigned int wait,
169 const D2TsigKeyPtr& tsig_key = D2TsigKeyPtr());
170
171private:
173 std::unique_ptr<DNSClientImpl> impl_;
174};
175
176} // namespace d2
177} // namespace isc
178
179#endif // DNS_CLIENT_H
The D2UpdateMessage encapsulates a DNS Update message.
Callback for the DNSClient class.
Definition dns_client.h:91
virtual ~Callback()
Virtual destructor.
Definition dns_client.h:94
virtual void operator()(DNSClient::Status status)=0
Function operator implementing a callback.
The DNSClient class handles communication with the DNS server.
Definition dns_client.h:49
void doUpdate(const asiolink::IOServicePtr &io_service, const asiolink::IOAddress &ns_addr, const uint16_t ns_port, D2UpdateMessage &update, const unsigned int wait, const D2TsigKeyPtr &tsig_key=D2TsigKeyPtr())
Start asynchronous DNS Update with TSIG.
~DNSClient()
Virtual destructor, does nothing.
Protocol
Transport layer protocol used by a DNS Client to communicate with a server.
Definition dns_client.h:54
DNSClient(D2UpdateMessagePtr &response_placeholder, Callback *callback, const Protocol proto=UDP)
Constructor.
void stop()
Stop the client.
static std::string const & statusToText(Status const &status)
Convert enum to string.
Definition dns_client.h:73
static unsigned int getMaxTimeout()
Returns maximal allowed timeout value accepted by DNSClient::doUpdate.
Status
A status code of the DNSClient.
Definition dns_client.h:60
@ IO_STOPPED
IO was stopped.
Definition dns_client.h:63
@ TIMEOUT
No response, timeout.
Definition dns_client.h:62
@ OTHER
Other, unclassified error.
Definition dns_client.h:65
@ INVALID_RESPONSE
Response received but invalid.
Definition dns_client.h:64
@ SUCCESS
Response received and is ok.
Definition dns_client.h:61
boost::shared_ptr< D2UpdateMessage > D2UpdateMessagePtr
Pointer to the DNS Update Message.
boost::shared_ptr< DNSClient > DNSClientPtr
Definition dns_client.h:22
boost::shared_ptr< D2TsigKey > D2TsigKeyPtr
Type of pointer to a D2 TSIG key.
Definition d2_tsig_key.h:71
Defines the logger used by the top-level component of kea-lfc.