Kea: dns_client.h Source File

| Kea 3.2.0-git

dns_client.h
Go to the documentation of this file.
1// Copyright (C) 2013-2025 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 <asiolink/io_service.h>
11#include <asiodns/io_fetch.h>
12#include <d2srv/d2_tsig_key.h>
13#include <d2srv/d2_update_message.h>
14#include <util/buffer.h>
15
16namespace isc {
17namespace d2 {
18
19class DNSClient;
20 typedef boost::shared_ptr<DNSClient> DNSClientPtr;
21
23class DNSClientImpl;
24
47 class DNSClient {
48public:
49
52 enum Protocol {
53 UDP,
54 TCP
55 };
56
58 enum Status : uint16_t {
59 SUCCESS = 0,
60 TIMEOUT = 1,
61 IO_STOPPED = 2,
62 INVALID_RESPONSE = 3,
63 OTHER = 4,
64 };
65
71 static std::string const& statusToText(Status const& status) {
72 static std::vector<std::string> const text_vector {
73 "SUCCESS",
74 "TIMEOUT",
75 "IO_STOPPED",
76 "INVALID_RESPONSE",
77 "OTHER",
78 };
79 static std::string const unknown("UNKNOWN");
80 return (status < text_vector.size() ? text_vector[status] : unknown);
81 }
82
89 class Callback {
90 public:
92 virtual ~Callback() { }
93
98 virtual void operator()(DNSClient::Status status) = 0;
99 };
100
110 DNSClient(D2UpdateMessagePtr& response_placeholder, Callback* callback,
111 const Protocol proto = UDP);
112
114 ~DNSClient();
115
117 void stop();
118
127
128private:
129 DNSClient(const DNSClient& source);
130 DNSClient& operator=(const DNSClient& source);
132
133public:
134
139 static unsigned int getMaxTimeout();
140
162 void doUpdate(const asiolink::IOServicePtr& io_service,
163 const asiolink::IOAddress& ns_addr,
164 const uint16_t ns_port,
165 D2UpdateMessage& update,
166 const unsigned int wait,
167 const D2TsigKeyPtr& tsig_key = D2TsigKeyPtr());
168
169private:
171 std::unique_ptr<DNSClientImpl> impl_;
172};
173
174} // namespace d2
175} // namespace isc
176
177#endif // DNS_CLIENT_H
buffer.h
isc::asiolink::IOAddress
The IOAddress class represents an IP addresses (version agnostic).
Definition io_address.h:53
isc::d2::D2UpdateMessage
The D2UpdateMessage encapsulates a DNS Update message.
Definition d2_update_message.h:89
isc::d2::DNSClientImpl
Definition dns_client.cc:39
isc::d2::DNSClient::Callback
Callback for the DNSClient class.
Definition dns_client.h:89
isc::d2::DNSClient::Callback::~Callback
virtual ~Callback()
Virtual destructor.
Definition dns_client.h:92
isc::d2::DNSClient::Callback::operator()
virtual void operator()(DNSClient::Status status)=0
Function operator implementing a callback.
isc::d2::DNSClient
The DNSClient class handles communication with the DNS server.
Definition dns_client.h:47
isc::d2::DNSClient::doUpdate
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.
Definition dns_client.cc:344
isc::d2::DNSClient::~DNSClient
~DNSClient()
Virtual destructor, does nothing.
Definition dns_client.cc:328
isc::d2::DNSClient::DNSClient
DNSClient(D2UpdateMessagePtr &response_placeholder, Callback *callback, const Protocol proto=UDP)
Constructor.
Definition dns_client.cc:323
isc::d2::DNSClient::stop
void stop()
Stop the client.
Definition dns_client.cc:333
isc::d2::DNSClient::statusToText
static std::string const & statusToText(Status const &status)
Convert enum to string.
Definition dns_client.h:71
isc::d2::DNSClient::getMaxTimeout
static unsigned int getMaxTimeout()
Returns maximal allowed timeout value accepted by DNSClient::doUpdate.
Definition dns_client.cc:338
isc::d2::DNSClient::Status
Status
A status code of the DNSClient.
Definition dns_client.h:58
isc::d2::DNSClient::IO_STOPPED
@ IO_STOPPED
IO was stopped.
Definition dns_client.h:61
isc::d2::DNSClient::TIMEOUT
@ TIMEOUT
No response, timeout.
Definition dns_client.h:60
isc::d2::DNSClient::OTHER
@ OTHER
Other, unclassified error.
Definition dns_client.h:63
isc::d2::DNSClient::INVALID_RESPONSE
@ INVALID_RESPONSE
Response received but invalid.
Definition dns_client.h:62
isc::d2::DNSClient::SUCCESS
@ SUCCESS
Response received and is ok.
Definition dns_client.h:59
isc::d2::DNSClient::Protocol
Protocol
Transport layer protocol used by a DNS Client to communicate with a server.
Definition dns_client.h:52
isc::d2::DNSClient::TCP
@ TCP
Definition dns_client.h:54
isc::d2::DNSClient::UDP
@ UDP
Definition dns_client.h:53
d2_tsig_key.h
d2_update_message.h
io_fetch.h
io_service.h
isc::asiolink::IOServicePtr
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
Definition io_service.h:35
isc::d2
Definition check_exists_add.cc:19
isc::d2::D2UpdateMessagePtr
boost::shared_ptr< D2UpdateMessage > D2UpdateMessagePtr
Pointer to the DNS Update Message.
Definition d2_update_message.h:73
isc::d2::DNSClientPtr
boost::shared_ptr< DNSClient > DNSClientPtr
Definition dns_client.h:20
isc::d2::D2TsigKeyPtr
boost::shared_ptr< D2TsigKey > D2TsigKeyPtr
Type of pointer to a D2 TSIG key.
Definition d2_tsig_key.h:71
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18