| Kea 3.0.2-git

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
20 namespace isc {
21 namespace dhcp {
22
24 class DuplicateIfaceName : public Exception {
25 public:
26 DuplicateIfaceName(const char* file, size_t line, const char* what) :
27 isc::Exception(file, line, what) { }
28};
29
31 class InvalidIfaceName : public Exception {
32 public:
33 InvalidIfaceName(const char* file, size_t line, const char* what) :
34 isc::Exception(file, line, what) { }
35};
36
38 class NoSuchIface : public Exception {
39 public:
40 NoSuchIface(const char* file, size_t line, const char* what) :
41 isc::Exception(file, line, what) { }
42};
43
45 class DuplicateAddress : public Exception {
46 public:
47 DuplicateAddress(const char* file, size_t line, const char* what) :
48 isc::Exception(file, line, what) { }
49};
50
53 class NoSuchAddress : public Exception {
54 public:
55 NoSuchAddress(const char* file, size_t line, const char* what) :
56 isc::Exception(file, line, what) { }
57};
58
61 class InvalidSocketType : public Exception {
62 public:
63 InvalidSocketType(const char* file, size_t line, const char* what) :
64 isc::Exception(file, line, what) { }
65};
66
131 class CfgIface : public isc::data::UserContext, public isc::data::CfgToElement {
132 public:
133
135 enum SocketType {
137 SOCKET_RAW,
139 SOCKET_UDP
140 };
141
143 enum OutboundIface {
146 SAME_AS_INBOUND,
148 USE_ROUTING
149 };
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
241 SocketType getSocketType() const {
242 return (socket_type_);
243 }
244
246 std::string socketTypeToText() const;
247
251 void setOutboundIface(const OutboundIface& outbound_iface);
252
256 OutboundIface getOutboundIface() const;
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
316 bool getServiceSocketsRequireAll() const {
317 return (service_socket_require_all_);
318 }
319
323 void setServiceSocketsRetryWaitTime(uint32_t interval) {
324 service_sockets_retry_wait_time_ = interval;
325 }
326
330 uint32_t getServiceSocketsRetryWaitTime() const {
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
344 uint32_t getServiceSocketsMaxRetries() const {
345 return (service_sockets_max_retries_);
346 }
347
351 util::ReconnectCtlPtr getReconnectCtl() const {
352 return (reconnect_ctl_);
353 }
354
357 typedef std::function<void(util::ReconnectCtlPtr)> OpenSocketsFailedCallback;
358
361 static OpenSocketsFailedCallback open_sockets_failed_callback_;
362
363 private:
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
501 typedef boost::shared_ptr<CfgIface> CfgIfacePtr;
502
504 typedef boost::shared_ptr<const CfgIface> ConstCfgIfacePtr;
505
506}
507}
508
509#endif // CFG_IFACE_H
cfg_to_element.h
isc::Exception::Exception
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
Definition exceptions/exceptions.cc:17
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition exceptions/exceptions.cc:32
isc::dhcp::CfgIface::ALL_IFACES_KEYWORD
static const char * ALL_IFACES_KEYWORD
Keyword used to enable all interfaces.
Definition cfg_iface.h:155
isc::dhcp::CfgIface::closeSockets
void closeSockets() const
Convenience function which closes all open sockets.
Definition cfg_iface.cc:38
isc::dhcp::CfgIface::socketTypeToText
std::string socketTypeToText() const
Returns the socket type in the textual format.
Definition cfg_iface.cc:313
isc::dhcp::CfgIface::setReDetect
void setReDetect(bool re_detect)
Set the re-detect flag.
Definition cfg_iface.h:302
isc::dhcp::CfgIface::setServiceSocketsRetryWaitTime
void setServiceSocketsRetryWaitTime(uint32_t interval)
Set the socket service binding retry interval between attempts.
Definition cfg_iface.h:323
isc::dhcp::CfgIface::reset
void reset()
Puts the interface configuration into default state.
Definition cfg_iface.cc:273
isc::dhcp::CfgIface::getServiceSocketsRetryWaitTime
uint32_t getServiceSocketsRetryWaitTime() const
Indicates the socket service binding retry interval between attempts.
Definition cfg_iface.h:330
isc::dhcp::CfgIface::OutboundIface
OutboundIface
Indicates how outbound interface is selected for relayed traffic.
Definition cfg_iface.h:143
isc::dhcp::CfgIface::USE_ROUTING
@ USE_ROUTING
Server uses routing to determine the right interface to send response.
Definition cfg_iface.h:148
isc::dhcp::CfgIface::SAME_AS_INBOUND
@ SAME_AS_INBOUND
Server sends responses over the same interface on which queries are received.
Definition cfg_iface.h:146
isc::dhcp::CfgIface::getReconnectCtl
util::ReconnectCtlPtr getReconnectCtl() const
Get the reconnect controller.
Definition cfg_iface.h:351
isc::dhcp::CfgIface::getOutboundIface
OutboundIface getOutboundIface() const
Returns outbound interface selection mode.
Definition cfg_iface.cc:343
isc::dhcp::CfgIface::CfgIface
CfgIface()
Constructor.
Definition cfg_iface.cc:30
isc::dhcp::CfgIface::getSocketType
SocketType getSocketType() const
Returns DHCP socket type used by the server.
Definition cfg_iface.h:241
isc::dhcp::CfgIface::getServiceSocketsRequireAll
bool getServiceSocketsRequireAll() const
Indicates that Kea must successfully bind all socket services on init.
Definition cfg_iface.h:316
isc::dhcp::CfgIface::operator!=
bool operator!=(const CfgIface &other) const
Inequality operator.
Definition cfg_iface.h:290
isc::dhcp::CfgIface::openSockets
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
isc::dhcp::CfgIface::textToOutboundIface
static OutboundIface textToOutboundIface(const std::string &txt)
Converts text to outbound interface selection mode.
Definition cfg_iface.cc:361
isc::dhcp::CfgIface::use
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
isc::dhcp::CfgIface::equals
bool equals(const CfgIface &other) const
Compares two CfgIface objects for equality.
Definition cfg_iface.cc:43
isc::dhcp::CfgIface::SocketType
SocketType
Socket type used by the DHCPv4 server.
Definition cfg_iface.h:135
isc::dhcp::CfgIface::SOCKET_UDP
@ SOCKET_UDP
Datagram socket, i.e. IP/UDP socket.
Definition cfg_iface.h:139
isc::dhcp::CfgIface::SOCKET_RAW
@ SOCKET_RAW
Raw socket, used for direct DHCPv4 traffic.
Definition cfg_iface.h:137
isc::dhcp::CfgIface::toElement
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition cfg_iface.cc:553
isc::dhcp::CfgIface::setServiceSocketsRequireAll
void setServiceSocketsRequireAll(bool require_all)
Set flag that Kea must successfully bind all socket services on init.
Definition cfg_iface.h:309
isc::dhcp::CfgIface::outboundTypeToText
std::string outboundTypeToText() const
Returns outbound interface selection mode as string.
Definition cfg_iface.cc:348
isc::dhcp::CfgIface::setOutboundIface
void setOutboundIface(const OutboundIface &outbound_iface)
Sets outbound interface selection mode.
Definition cfg_iface.cc:375
isc::dhcp::CfgIface::setServiceSocketsMaxRetries
void setServiceSocketsMaxRetries(uint32_t max_retries)
Set a maximum number of service sockets bind attempts.
Definition cfg_iface.h:337
isc::dhcp::CfgIface::textToSocketType
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
isc::dhcp::CfgIface::operator==
bool operator==(const CfgIface &other) const
Equality operator.
Definition cfg_iface.h:281
isc::dhcp::CfgIface::open_sockets_failed_callback_
static OpenSocketsFailedCallback open_sockets_failed_callback_
Optional callback function to invoke if all retries of the opening sockets fail.
Definition cfg_iface.h:361
isc::dhcp::CfgIface::useSocketType
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
isc::dhcp::CfgIface::OpenSocketsFailedCallback
std::function< void(util::ReconnectCtlPtr)> OpenSocketsFailedCallback
Represents a callback invoked if all retries of the opening sockets fail.
Definition cfg_iface.h:357
isc::dhcp::CfgIface::getServiceSocketsMaxRetries
uint32_t getServiceSocketsMaxRetries() const
Indicates the maximum number of service sockets bind attempts.
Definition cfg_iface.h:344
isc::dhcp::DuplicateAddress::DuplicateAddress
DuplicateAddress(const char *file, size_t line, const char *what)
Definition cfg_iface.h:47
isc::dhcp::DuplicateIfaceName::DuplicateIfaceName
DuplicateIfaceName(const char *file, size_t line, const char *what)
Definition cfg_iface.h:26
isc::dhcp::Iface
Represents a single network interface.
Definition iface_mgr.h:118
isc::dhcp::InvalidIfaceName::InvalidIfaceName
InvalidIfaceName(const char *file, size_t line, const char *what)
Definition cfg_iface.h:33
isc::dhcp::InvalidSocketType::InvalidSocketType
InvalidSocketType(const char *file, size_t line, const char *what)
Definition cfg_iface.h:63
isc::dhcp::NoSuchAddress::NoSuchAddress
NoSuchAddress(const char *file, size_t line, const char *what)
Definition cfg_iface.h:55
isc::dhcp::NoSuchIface::NoSuchIface
NoSuchIface(const char *file, size_t line, const char *what)
Definition cfg_iface.h:40
iface_mgr.h
io_address.h
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
isc::dhcp
Definition dhcp4/client_handler.cc:20
isc::dhcp::ConstCfgIfacePtr
boost::shared_ptr< const CfgIface > ConstCfgIfacePtr
A pointer to the const CfgIface.
Definition cfg_iface.h:504
isc::dhcp::CfgIfacePtr
boost::shared_ptr< CfgIface > CfgIfacePtr
A pointer to the CfgIface .
Definition cfg_iface.h:501
isc::util::file
Definition filesystem.cc:28
isc::util::ReconnectCtlPtr
boost::shared_ptr< ReconnectCtl > ReconnectCtlPtr
Pointer to an instance of ReconnectCtl.
Definition reconnect_ctl.h:148
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148
reconnect_ctl.h
isc::data::CfgToElement
Abstract class for configuration Cfg_* classes.
Definition cfg_to_element.h:29
isc::data::UserContext
Base class for user context.
Definition user_context.h:22
user_context.h