Kea  2.1.7-git
cfg_iface.h
Go to the documentation of this file.
1 // Copyright (C) 2014-2022 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 
132 public:
133 
135  enum SocketType {
139  SOCKET_UDP
140  };
141 
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) const;
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 
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 
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 
344  uint32_t getServiceSocketsMaxRetries() const {
345  return (service_sockets_max_retries_);
346  }
347 
350  typedef std::function<void(util::ReconnectCtlPtr)> OpenSocketsFailedCallback;
351 
354  static OpenSocketsFailedCallback open_sockets_failed_callback_;
355 
356 private:
357 
370  static bool multipleAddressesPerInterfaceActive();
371 
383  void setState(const uint16_t family, const bool inactive,
384  const bool loopback_inactive) const;
385 
396  void setIfaceAddrsState(const uint16_t family, const bool active,
397  Iface& iface) const;
398 
407  static void socketOpenErrorHandler(const std::string& errmsg);
408 
425  static std::pair<bool, bool> openSocketsForFamily(const uint16_t family,
426  const uint16_t port,
427  const bool can_use_bcast,
428  const bool skip_opened);
429 
435  util::ReconnectCtlPtr makeReconnectCtl() const;
436 
447  static bool openSocketsWithRetry(util::ReconnectCtlPtr reconnect_ctl,
448  const uint16_t family, const uint16_t port,
449  const bool can_use_bcast);
450 
452  typedef std::set<std::string> IfaceSet;
453 
455  IfaceSet iface_set_;
456 
459  typedef std::multimap<std::string, asiolink::IOAddress> ExplicitAddressMap;
460 
463  ExplicitAddressMap address_map_;
464 
467  bool wildcard_used_;
468 
470  SocketType socket_type_;
471 
473  bool re_detect_;
474 
476  bool service_socket_require_all_;
477 
479  uint32_t service_sockets_retry_wait_time_;
480 
482  uint32_t service_sockets_max_retries_;
483 
485  OutboundIface outbound_iface_;
486 };
487 
489 typedef boost::shared_ptr<CfgIface> CfgIfacePtr;
490 
492 typedef boost::shared_ptr<const CfgIface> ConstCfgIfacePtr;
493 
494 }
495 }
496 
497 #endif // CFG_IFACE_H
void setServiceSocketsRequireAll(bool require_all)
Set flag that Kea must successfully bind all socket services on init.
Definition: cfg_iface.h:309
bool operator==(const CfgIface &other) const
Equality operator.
Definition: cfg_iface.h:281
Exception thrown when invalid socket type has been specified for the given family.
Definition: cfg_iface.h:61
SocketType getSocketType() const
Returns DHCP socket type used by the server.
Definition: cfg_iface.h:241
NoSuchAddress(const char *file, size_t line, const char *what)
Definition: cfg_iface.h:55
boost::shared_ptr< ReconnectCtl > ReconnectCtlPtr
Pointer to an instance of ReconnectCtl.
Exception thrown when specified interface name is invalid.
Definition: cfg_iface.h:31
Base class for user context.
Definition: user_context.h:22
NoSuchIface(const char *file, size_t line, const char *what)
Definition: cfg_iface.h:40
SocketType
Socket type used by the DHCPv4 server.
Definition: cfg_iface.h:135
Raw socket, used for direct DHCPv4 traffic.
Definition: cfg_iface.h:137
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
boost::shared_ptr< CfgIface > CfgIfacePtr
A pointer to the CfgIface .
Definition: cfg_iface.h:489
Exception thrown when specified unicast address is not assigned to the interface specified.
Definition: cfg_iface.h:53
InvalidIfaceName(const char *file, size_t line, const char *what)
Definition: cfg_iface.h:33
Exception thrown when specified interface doesn&#39;t exist in a system.
Definition: cfg_iface.h:38
Represents a single network interface.
Definition: iface_mgr.h:118
static OpenSocketsFailedCallback open_sockets_failed_callback_
Optional callback function to invoke if all retries of the opening sockets fail.
Definition: cfg_iface.h:354
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
DuplicateAddress(const char *file, size_t line, const char *what)
Definition: cfg_iface.h:47
void setReDetect(bool re_detect)
Set the re-detect flag.
Definition: cfg_iface.h:302
Abstract class for configuration Cfg_* classes.
void setServiceSocketsRetryWaitTime(uint32_t interval)
Set the socket service binding retry interval between attempts.
Definition: cfg_iface.h:323
static const char * ALL_IFACES_KEYWORD
Keyword used to enable all interfaces.
Definition: cfg_iface.h:155
uint32_t getServiceSocketsMaxRetries() const
Indicates the maximum number of service sockets bind attempts.
Definition: cfg_iface.h:344
InvalidSocketType(const char *file, size_t line, const char *what)
Definition: cfg_iface.h:63
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-lfc.
DuplicateIfaceName(const char *file, size_t line, const char *what)
Definition: cfg_iface.h:26
bool getServiceSocketsRequireAll() const
Indicates that Kea must successfully bind all socket services on init.
Definition: cfg_iface.h:316
uint32_t getServiceSocketsRetryWaitTime() const
Indicates the socket service binding retry interval between attempts.
Definition: cfg_iface.h:330
Exception thrown when duplicated interface names specified.
Definition: cfg_iface.h:24
Server sends responses over the same interface on which queries are received.
Definition: cfg_iface.h:146
boost::shared_ptr< const CfgIface > ConstCfgIfacePtr
A pointer to the const CfgIface.
Definition: cfg_iface.h:492
Exception thrown when duplicated address specified.
Definition: cfg_iface.h:45
void setServiceSocketsMaxRetries(uint32_t max_retries)
Set a maximum number of service sockets bind attempts.
Definition: cfg_iface.h:337
bool operator!=(const CfgIface &other) const
Inequality operator.
Definition: cfg_iface.h:290
std::function< void(util::ReconnectCtlPtr)> OpenSocketsFailedCallback
Represents a callback invoked if all retries of the opening sockets fail.
Definition: cfg_iface.h:350
OutboundIface
Indicates how outbound interface is selected for relayed traffic.
Definition: cfg_iface.h:143