Kea  1.9.9-git
cfg_iface.h
Go to the documentation of this file.
1 // Copyright (C) 2014-2018 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 <cc/cfg_to_element.h>
13 #include <cc/user_context.h>
14 #include <boost/shared_ptr.hpp>
15 #include <map>
16 #include <set>
17 #include <string>
18 
19 namespace isc {
20 namespace dhcp {
21 
23 class DuplicateIfaceName : public Exception {
24 public:
25  DuplicateIfaceName(const char* file, size_t line, const char* what) :
26  isc::Exception(file, line, what) { };
27 };
28 
30 class InvalidIfaceName : public Exception {
31 public:
32  InvalidIfaceName(const char* file, size_t line, const char* what) :
33  isc::Exception(file, line, what) { };
34 };
35 
37 class NoSuchIface : public Exception {
38 public:
39  NoSuchIface(const char* file, size_t line, const char* what) :
40  isc::Exception(file, line, what) { };
41 };
42 
44 class DuplicateAddress : public Exception {
45 public:
46  DuplicateAddress(const char* file, size_t line, const char* what) :
47  isc::Exception(file, line, what) { };
48 };
49 
52 class NoSuchAddress : public Exception {
53 public:
54  NoSuchAddress(const char* file, size_t line, const char* what) :
55  isc::Exception(file, line, what) { };
56 };
57 
60 class InvalidSocketType : public Exception {
61 public:
62  InvalidSocketType(const char* file, size_t line, const char* what) :
63  isc::Exception(file, line, what) { };
64 };
65 
131 public:
132 
134  enum SocketType {
139  };
140 
148  };
149 
154  static const char* ALL_IFACES_KEYWORD;
155 
157  CfgIface();
158 
161  void closeSockets() const;
162 
168  bool equals(const CfgIface& other) const;
169 
183  void openSockets(const uint16_t family, const uint16_t port,
184  const bool use_bcast = true) const;
185 
189  void reset();
190 
207  void use(const uint16_t family, const std::string& iface_name);
208 
221  void useSocketType(const uint16_t family, const SocketType& socket_type);
222 
236  void useSocketType(const uint16_t family,
237  const std::string& socket_type_name);
238 
241  return (socket_type_);
242  }
243 
245  std::string socketTypeToText() const;
246 
250  void setOutboundIface(const OutboundIface& outbound_iface);
251 
256 
260  std::string outboundTypeToText() const;
261 
266  static OutboundIface textToOutboundIface(const std::string& txt);
267 
273  SocketType textToSocketType(const std::string& socket_type_name) const;
274 
280  bool operator==(const CfgIface& other) const {
281  return (equals(other));
282  }
283 
289  bool operator!=(const CfgIface& other) const {
290  return (!equals(other));
291  }
292 
296  virtual isc::data::ElementPtr toElement() const;
297 
301  void setReDetect(bool re_detect) {
302  re_detect_ = re_detect;
303  }
304 
305 private:
306 
319  bool multipleAddressesPerInterfaceActive() const;
320 
332  void setState(const uint16_t family, const bool inactive,
333  const bool loopback_inactive) const;
334 
345  void setIfaceAddrsState(const uint16_t family, const bool active,
346  Iface& iface) const;
347 
356  static void socketOpenErrorHandler(const std::string& errmsg);
357 
359  typedef std::set<std::string> IfaceSet;
360 
362  IfaceSet iface_set_;
363 
366  typedef std::multimap<std::string, asiolink::IOAddress> ExplicitAddressMap;
367 
370  ExplicitAddressMap address_map_;
371 
374  bool wildcard_used_;
375 
377  SocketType socket_type_;
378 
380  bool re_detect_;
381 
383  OutboundIface outbound_iface_;
384 };
385 
387 typedef boost::shared_ptr<CfgIface> CfgIfacePtr;
388 
390 typedef boost::shared_ptr<const CfgIface> ConstCfgIfacePtr;
391 
392 }
393 }
394 
395 #endif // CFG_IFACE_H
Exception thrown when invalid socket type has been specified for the given family.
Definition: cfg_iface.h:60
CfgIface()
Constructor.
Definition: cfg_iface.cc:24
NoSuchAddress(const char *file, size_t line, const char *what)
Definition: cfg_iface.h:54
static OutboundIface textToOutboundIface(const std::string &txt)
Converts text to outbound interface selection mode.
Definition: cfg_iface.cc:271
Exception thrown when specified interface name is invalid.
Definition: cfg_iface.h:30
Base class for user context.
Definition: user_context.h:22
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition: cfg_iface.cc:463
NoSuchIface(const char *file, size_t line, const char *what)
Definition: cfg_iface.h:39
SocketType
Socket type used by the DHCPv4 server.
Definition: cfg_iface.h:134
Raw socket, used for direct DHCPv4 traffic.
Definition: cfg_iface.h:136
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
std::string socketTypeToText() const
Returns the socket type in the textual format.
Definition: cfg_iface.cc:223
boost::shared_ptr< CfgIface > CfgIfacePtr
A pointer to the CfgIface .
Definition: cfg_iface.h:387
Exception thrown when specified unicast address is not assigned to the interface specified.
Definition: cfg_iface.h:52
InvalidIfaceName(const char *file, size_t line, const char *what)
Definition: cfg_iface.h:32
Exception thrown when specified interface doesn't exist in a system.
Definition: cfg_iface.h:37
Represents a single network interface.
Definition: iface_mgr.h:118
Server uses routing to determine the right interface to send response.
Definition: cfg_iface.h:147
bool equals(const CfgIface &other) const
Compares two CfgIface objects for equality.
Definition: cfg_iface.cc:35
DuplicateAddress(const char *file, size_t line, const char *what)
Definition: cfg_iface.h:46
bool operator==(const CfgIface &other) const
Equality operator.
Definition: cfg_iface.h:280
void setReDetect(bool re_detect)
Set the re-detect flag.
Definition: cfg_iface.h:301
Abstract class for configuration Cfg_* classes.
static const char * ALL_IFACES_KEYWORD
Keyword used to enable all interfaces.
Definition: cfg_iface.h:154
InvalidSocketType(const char *file, size_t line, const char *what)
Definition: cfg_iface.h:62
void use(const uint16_t family, const std::string &iface_name)
Select interface to be used to receive DHCP traffic.
Definition: cfg_iface.cc:290
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:445
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
bool operator!=(const CfgIface &other) const
Inequality operator.
Definition: cfg_iface.h:289
Datagram socket, i.e. IP/UDP socket.
Definition: cfg_iface.h:138
DuplicateIfaceName(const char *file, size_t line, const char *what)
Definition: cfg_iface.h:25
void reset()
Puts the interface configuration into default state.
Definition: cfg_iface.cc:183
Exception thrown when duplicated interface names specified.
Definition: cfg_iface.h:23
Server sends responses over the same interface on which queries are received.
Definition: cfg_iface.h:145
boost::shared_ptr< const CfgIface > ConstCfgIfacePtr
A pointer to the const CfgIface.
Definition: cfg_iface.h:390
void openSockets(const uint16_t family, const uint16_t port, const bool use_bcast=true) const
Tries to open sockets on selected interfaces.
Definition: cfg_iface.cc:53
Exception thrown when duplicated address specified.
Definition: cfg_iface.h:44
void setOutboundIface(const OutboundIface &outbound_iface)
Sets outbound interface selection mode.
Definition: cfg_iface.cc:285
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:239
std::string outboundTypeToText() const
Returns outbound interface selection mode as string.
Definition: cfg_iface.cc:258
SocketType getSocketType() const
Returns DHCP socket type used by the server.
Definition: cfg_iface.h:240
void closeSockets() const
Convenience function which closes all open sockets.
Definition: cfg_iface.cc:30
OutboundIface getOutboundIface() const
Returns outbound interface selection mode.
Definition: cfg_iface.cc:253
OutboundIface
Indicates how outbound interface is selected for relayed traffic.
Definition: cfg_iface.h:142