Kea 2.7.5
cfg_iface.h
Go to the documentation of this file.
1// Copyright (C) 2014-2024 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 CFG_IFACE_H
8#define CFG_IFACE_H
9
10#include <asiolink/io_address.h>
11#include <dhcp/iface_mgr.h>
12#include <util/reconnect_ctl.h>
13#include <cc/cfg_to_element.h>
14#include <cc/user_context.h>
15#include <boost/shared_ptr.hpp>
16#include <map>
17#include <set>
18#include <string>
19
20namespace isc {
21namespace dhcp {
22
25public:
26 DuplicateIfaceName(const char* file, size_t line, const char* what) :
27 isc::Exception(file, line, what) { }
28};
29
32public:
33 InvalidIfaceName(const char* file, size_t line, const char* what) :
34 isc::Exception(file, line, what) { }
35};
36
38class NoSuchIface : public Exception {
39public:
40 NoSuchIface(const char* file, size_t line, const char* what) :
41 isc::Exception(file, line, what) { }
42};
43
46public:
47 DuplicateAddress(const char* file, size_t line, const char* what) :
48 isc::Exception(file, line, what) { }
49};
50
53class NoSuchAddress : public Exception {
54public:
55 NoSuchAddress(const char* file, size_t line, const char* what) :
56 isc::Exception(file, line, what) { }
57};
58
62public:
63 InvalidSocketType(const char* file, size_t line, const char* what) :
64 isc::Exception(file, line, what) { }
65};
66
132public:
133
141
150
155 static const char* ALL_IFACES_KEYWORD;
156
158 CfgIface();
159
162 void closeSockets() const;
163
169 bool equals(const CfgIface& other) const;
170
184 void openSockets(const uint16_t family, const uint16_t port,
185 const bool use_bcast = true);
186
190 void reset();
191
208 void use(const uint16_t family, const std::string& iface_name);
209
222 void useSocketType(const uint16_t family, const SocketType& socket_type);
223
237 void useSocketType(const uint16_t family,
238 const std::string& socket_type_name);
239
242 return (socket_type_);
243 }
244
246 std::string socketTypeToText() const;
247
251 void setOutboundIface(const OutboundIface& outbound_iface);
252
257
261 std::string outboundTypeToText() const;
262
267 static OutboundIface textToOutboundIface(const std::string& txt);
268
274 SocketType textToSocketType(const std::string& socket_type_name) const;
275
281 bool operator==(const CfgIface& other) const {
282 return (equals(other));
283 }
284
290 bool operator!=(const CfgIface& other) const {
291 return (!equals(other));
292 }
293
297 virtual isc::data::ElementPtr toElement() const;
298
302 void setReDetect(bool re_detect) {
303 re_detect_ = re_detect;
304 }
305
309 void setServiceSocketsRequireAll(bool require_all) {
310 service_socket_require_all_ = require_all;
311 }
312
317 return (service_socket_require_all_);
318 }
319
323 void setServiceSocketsRetryWaitTime(uint32_t interval) {
324 service_sockets_retry_wait_time_ = interval;
325 }
326
331 return (service_sockets_retry_wait_time_);
332 }
333
337 void setServiceSocketsMaxRetries(uint32_t max_retries) {
338 service_sockets_max_retries_ = max_retries;
339 }
340
345 return (service_sockets_max_retries_);
346 }
347
352 return (reconnect_ctl_);
353 }
354
358
362
363private:
364
377 static bool multipleAddressesPerInterfaceActive();
378
390 void setState(const uint16_t family, const bool inactive,
391 const bool loopback_inactive) const;
392
403 void setIfaceAddrsState(const uint16_t family, const bool active,
404 Iface& iface) const;
405
414 static void socketOpenErrorHandler(const std::string& errmsg);
415
432 static std::pair<bool, bool> openSocketsForFamily(const uint16_t family,
433 const uint16_t port,
434 const bool can_use_bcast,
435 const bool skip_opened);
436
442 util::ReconnectCtlPtr makeReconnectCtl() const;
443
456 static bool openSocketsWithRetry(util::ReconnectCtlPtr reconnect_ctl,
457 const uint16_t family, const uint16_t port,
458 const bool can_use_bcast);
459
461 typedef std::set<std::string> IfaceSet;
462
464 IfaceSet iface_set_;
465
468 typedef std::multimap<std::string, asiolink::IOAddress> ExplicitAddressMap;
469
472 ExplicitAddressMap address_map_;
473
476 bool wildcard_used_;
477
479 SocketType socket_type_;
480
482 bool re_detect_;
483
485 bool service_socket_require_all_;
486
488 uint32_t service_sockets_retry_wait_time_;
489
491 uint32_t service_sockets_max_retries_;
492
494 OutboundIface outbound_iface_;
495
497 util::ReconnectCtlPtr reconnect_ctl_;
498};
499
501typedef boost::shared_ptr<CfgIface> CfgIfacePtr;
502
504typedef boost::shared_ptr<const CfgIface> ConstCfgIfacePtr;
505
506}
507}
508
509#endif // CFG_IFACE_H
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Represents selection of interfaces for DHCP server.
Definition cfg_iface.h:131
static const char * ALL_IFACES_KEYWORD
Keyword used to enable all interfaces.
Definition cfg_iface.h:155
void closeSockets() const
Convenience function which closes all open sockets.
Definition cfg_iface.cc:38
std::string socketTypeToText() const
Returns the socket type in the textual format.
Definition cfg_iface.cc:313
void setReDetect(bool re_detect)
Set the re-detect flag.
Definition cfg_iface.h:302
void setServiceSocketsRetryWaitTime(uint32_t interval)
Set the socket service binding retry interval between attempts.
Definition cfg_iface.h:323
void reset()
Puts the interface configuration into default state.
Definition cfg_iface.cc:273
uint32_t getServiceSocketsRetryWaitTime() const
Indicates the socket service binding retry interval between attempts.
Definition cfg_iface.h:330
OutboundIface
Indicates how outbound interface is selected for relayed traffic.
Definition cfg_iface.h:143
@ USE_ROUTING
Server uses routing to determine the right interface to send response.
Definition cfg_iface.h:148
@ SAME_AS_INBOUND
Server sends responses over the same interface on which queries are received.
Definition cfg_iface.h:146
util::ReconnectCtlPtr getReconnectCtl() const
Get the reconnect controller.
Definition cfg_iface.h:351
OutboundIface getOutboundIface() const
Returns outbound interface selection mode.
Definition cfg_iface.cc:343
CfgIface()
Constructor.
Definition cfg_iface.cc:30
SocketType getSocketType() const
Returns DHCP socket type used by the server.
Definition cfg_iface.h:241
bool getServiceSocketsRequireAll() const
Indicates that Kea must successfully bind all socket services on init.
Definition cfg_iface.h:316
bool operator!=(const CfgIface &other) const
Inequality operator.
Definition cfg_iface.h:290
void openSockets(const uint16_t family, const uint16_t port, const bool use_bcast=true)
Tries to open sockets on selected interfaces.
Definition cfg_iface.cc:61
static OutboundIface textToOutboundIface(const std::string &txt)
Converts text to outbound interface selection mode.
Definition cfg_iface.cc:361
void use(const uint16_t family, const std::string &iface_name)
Select interface to be used to receive DHCP traffic.
Definition cfg_iface.cc:380
bool equals(const CfgIface &other) const
Compares two CfgIface objects for equality.
Definition cfg_iface.cc:43
SocketType
Socket type used by the DHCPv4 server.
Definition cfg_iface.h:135
@ SOCKET_UDP
Datagram socket, i.e. IP/UDP socket.
Definition cfg_iface.h:139
@ SOCKET_RAW
Raw socket, used for direct DHCPv4 traffic.
Definition cfg_iface.h:137
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition cfg_iface.cc:553
void setServiceSocketsRequireAll(bool require_all)
Set flag that Kea must successfully bind all socket services on init.
Definition cfg_iface.h:309
std::string outboundTypeToText() const
Returns outbound interface selection mode as string.
Definition cfg_iface.cc:348
void setOutboundIface(const OutboundIface &outbound_iface)
Sets outbound interface selection mode.
Definition cfg_iface.cc:375
void setServiceSocketsMaxRetries(uint32_t max_retries)
Set a maximum number of service sockets bind attempts.
Definition cfg_iface.h:337
SocketType textToSocketType(const std::string &socket_type_name) const
Converts the socket type in the textual format to the type represented by the SocketType.
Definition cfg_iface.cc:329
bool operator==(const CfgIface &other) const
Equality operator.
Definition cfg_iface.h:281
static OpenSocketsFailedCallback open_sockets_failed_callback_
Optional callback function to invoke if all retries of the opening sockets fail.
Definition cfg_iface.h:361
void useSocketType(const uint16_t family, const SocketType &socket_type)
Sets the specified socket type to be used by the server.
Definition cfg_iface.cc:535
std::function< void(util::ReconnectCtlPtr)> OpenSocketsFailedCallback
Represents a callback invoked if all retries of the opening sockets fail.
Definition cfg_iface.h:357
uint32_t getServiceSocketsMaxRetries() const
Indicates the maximum number of service sockets bind attempts.
Definition cfg_iface.h:344
Exception thrown when duplicated address specified.
Definition cfg_iface.h:45
DuplicateAddress(const char *file, size_t line, const char *what)
Definition cfg_iface.h:47
Exception thrown when duplicated interface names specified.
Definition cfg_iface.h:24
DuplicateIfaceName(const char *file, size_t line, const char *what)
Definition cfg_iface.h:26
Represents a single network interface.
Definition iface_mgr.h:118
Exception thrown when specified interface name is invalid.
Definition cfg_iface.h:31
InvalidIfaceName(const char *file, size_t line, const char *what)
Definition cfg_iface.h:33
Exception thrown when invalid socket type has been specified for the given family.
Definition cfg_iface.h:61
InvalidSocketType(const char *file, size_t line, const char *what)
Definition cfg_iface.h:63
Exception thrown when specified unicast address is not assigned to the interface specified.
Definition cfg_iface.h:53
NoSuchAddress(const char *file, size_t line, const char *what)
Definition cfg_iface.h:55
Exception thrown when specified interface doesn't exist in a system.
Definition cfg_iface.h:38
NoSuchIface(const char *file, size_t line, const char *what)
Definition cfg_iface.h:40
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
boost::shared_ptr< const CfgIface > ConstCfgIfacePtr
A pointer to the const CfgIface.
Definition cfg_iface.h:504
boost::shared_ptr< CfgIface > CfgIfacePtr
A pointer to the CfgIface .
Definition cfg_iface.h:501
boost::shared_ptr< ReconnectCtl > ReconnectCtlPtr
Pointer to an instance of ReconnectCtl.
Defines the logger used by the top-level component of kea-lfc.
Abstract class for configuration Cfg_* classes.
Base class for user context.