Kea  1.5.0
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 {
138  SOCKET_UDP
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
isc::dhcp::CfgIface::ALL_IFACES_KEYWORD
static const char * ALL_IFACES_KEYWORD
Keyword used to enable all interfaces.
Definition: cfg_iface.h:154
isc::dhcp::DuplicateIfaceName::DuplicateIfaceName
DuplicateIfaceName(const char *file, size_t line, const char *what)
Definition: cfg_iface.h:25
isc::dhcp::CfgIface::setOutboundIface
void setOutboundIface(const OutboundIface &outbound_iface)
Sets outbound interface selection mode.
Definition: cfg_iface.cc:287
user_context.h
iface_mgr.h
isc::dhcp::CfgIface::getSocketType
SocketType getSocketType() const
Returns DHCP socket type used by the server.
Definition: cfg_iface.h:240
isc::dhcp::CfgIface::closeSockets
void closeSockets() const
Convenience function which closes all open sockets.
Definition: cfg_iface.cc:30
isc::dhcp::CfgIface::toElement
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition: cfg_iface.cc:465
io_address.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
isc::dhcp::DuplicateAddress
Exception thrown when duplicated address specified.
Definition: cfg_iface.h:44
isc::dhcp::CfgIface::operator==
bool operator==(const CfgIface &other) const
Equality operator.
Definition: cfg_iface.h:280
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:292
isc::dhcp::Iface
Represents a single network interface.
Definition: iface_mgr.h:114
isc::dhcp::CfgIface::SOCKET_RAW
@ SOCKET_RAW
Raw socket, used for direct DHCPv4 traffic.
Definition: cfg_iface.h:136
isc::Exception
This is a base class for exceptions thrown from the DNS library module.
Definition: exceptions/exceptions.h:23
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:145
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
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::outboundTypeToText
std::string outboundTypeToText() const
Returns outbound interface selection mode as string.
Definition: cfg_iface.cc:260
isc::dhcp::NoSuchAddress
Exception thrown when specified unicast address is not assigned to the interface specified.
Definition: cfg_iface.h:52
isc::dhcp::CfgIface::USE_ROUTING
@ USE_ROUTING
Server uses routing to determine the right interface to send response.
Definition: cfg_iface.h:147
isc::dhcp::DuplicateAddress::DuplicateAddress
DuplicateAddress(const char *file, size_t line, const char *what)
Definition: cfg_iface.h:46
isc::dhcp::CfgIface::operator!=
bool operator!=(const CfgIface &other) const
Inequality operator.
Definition: cfg_iface.h:289
isc::dhcp::CfgIface::CfgIface
CfgIface()
Constructor.
Definition: cfg_iface.cc:24
isc::dhcp::ConstCfgIfacePtr
boost::shared_ptr< const CfgIface > ConstCfgIfacePtr
A pointer to the const CfgIface.
Definition: cfg_iface.h:390
isc::dhcp::CfgIface
Represents selection of interfaces for DHCP server.
Definition: cfg_iface.h:130
isc::dhcp::NoSuchIface::NoSuchIface
NoSuchIface(const char *file, size_t line, const char *what)
Definition: cfg_iface.h:39
isc::dhcp::InvalidSocketType
Exception thrown when invalid socket type has been specified for the given family.
Definition: cfg_iface.h:60
isc::dhcp::InvalidIfaceName
Exception thrown when specified interface name is invalid.
Definition: cfg_iface.h:30
isc::dhcp::NoSuchIface
Exception thrown when specified interface doesn't exist in a system.
Definition: cfg_iface.h:37
cfg_to_element.h
isc::dhcp::CfgIface::getOutboundIface
OutboundIface getOutboundIface() const
Returns outbound interface selection mode.
Definition: cfg_iface.cc:255
isc::dhcp::CfgIface::setReDetect
void setReDetect(bool re_detect)
Set the re-detect flag.
Definition: cfg_iface.h:301
isc::dhcp::CfgIface::socketTypeToText
std::string socketTypeToText() const
Returns the socket type in the textual format.
Definition: cfg_iface.cc:225
isc::dhcp::InvalidIfaceName::InvalidIfaceName
InvalidIfaceName(const char *file, size_t line, const char *what)
Definition: cfg_iface.h:32
isc::dhcp::CfgIface::SOCKET_UDP
@ SOCKET_UDP
Datagram socket, i.e. IP/UDP socket.
Definition: cfg_iface.h:138
isc::dhcp::InvalidSocketType::InvalidSocketType
InvalidSocketType(const char *file, size_t line, const char *what)
Definition: cfg_iface.h:62
isc::dhcp::DuplicateIfaceName
Exception thrown when duplicated interface names specified.
Definition: cfg_iface.h:23
isc::dhcp::CfgIface::SocketType
SocketType
Socket type used by the DHCPv4 server.
Definition: cfg_iface.h:134
isc::dhcp::CfgIface::openSockets
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:54
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition: data.h:20
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:447
isc::dhcp::CfgIface::textToOutboundIface
static OutboundIface textToOutboundIface(const std::string &txt)
Converts text to outbound interface selection mode.
Definition: cfg_iface.cc:273
isc::dhcp::CfgIface::equals
bool equals(const CfgIface &other) const
Compares two CfgIface objects for equality.
Definition: cfg_iface.cc:35
isc::dhcp::CfgIface::OutboundIface
OutboundIface
Indicates how outbound interface is selected for relayed traffic.
Definition: cfg_iface.h:142
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:241
isc::dhcp::CfgIfacePtr
boost::shared_ptr< CfgIface > CfgIfacePtr
A pointer to the CfgIface .
Definition: cfg_iface.h:387
isc::dhcp::CfgIface::reset
void reset()
Puts the interface configuration into default state.
Definition: cfg_iface.cc:184
isc::dhcp::NoSuchAddress::NoSuchAddress
NoSuchAddress(const char *file, size_t line, const char *what)
Definition: cfg_iface.h:54