Kea 2.0.3
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
19namespace isc {
20namespace dhcp {
21
24public:
25 DuplicateIfaceName(const char* file, size_t line, const char* what) :
26 isc::Exception(file, line, what) { };
27};
28
31public:
32 InvalidIfaceName(const char* file, size_t line, const char* what) :
33 isc::Exception(file, line, what) { };
34};
35
37class NoSuchIface : public Exception {
38public:
39 NoSuchIface(const char* file, size_t line, const char* what) :
40 isc::Exception(file, line, what) { };
41};
42
45public:
46 DuplicateAddress(const char* file, size_t line, const char* what) :
47 isc::Exception(file, line, what) { };
48};
49
52class NoSuchAddress : public Exception {
53public:
54 NoSuchAddress(const char* file, size_t line, const char* what) :
55 isc::Exception(file, line, what) { };
56};
57
61public:
62 InvalidSocketType(const char* file, size_t line, const char* what) :
63 isc::Exception(file, line, what) { };
64};
65
131public:
132
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
305private:
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
387typedef boost::shared_ptr<CfgIface> CfgIfacePtr;
388
390typedef boost::shared_ptr<const CfgIface> ConstCfgIfacePtr;
391
392}
393}
394
395#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:130
static const char * ALL_IFACES_KEYWORD
Keyword used to enable all interfaces.
Definition: cfg_iface.h:154
void closeSockets() const
Convenience function which closes all open sockets.
Definition: cfg_iface.cc:30
std::string socketTypeToText() const
Returns the socket type in the textual format.
Definition: cfg_iface.cc:223
void setReDetect(bool re_detect)
Set the re-detect flag.
Definition: cfg_iface.h:301
void reset()
Puts the interface configuration into default state.
Definition: cfg_iface.cc:183
OutboundIface
Indicates how outbound interface is selected for relayed traffic.
Definition: cfg_iface.h:142
@ USE_ROUTING
Server uses routing to determine the right interface to send response.
Definition: cfg_iface.h:147
@ SAME_AS_INBOUND
Server sends responses over the same interface on which queries are received.
Definition: cfg_iface.h:145
OutboundIface getOutboundIface() const
Returns outbound interface selection mode.
Definition: cfg_iface.cc:253
CfgIface()
Constructor.
Definition: cfg_iface.cc:24
SocketType getSocketType() const
Returns DHCP socket type used by the server.
Definition: cfg_iface.h:240
bool operator!=(const CfgIface &other) const
Inequality operator.
Definition: cfg_iface.h:289
static OutboundIface textToOutboundIface(const std::string &txt)
Converts text to outbound interface selection mode.
Definition: cfg_iface.cc:271
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
bool equals(const CfgIface &other) const
Compares two CfgIface objects for equality.
Definition: cfg_iface.cc:35
SocketType
Socket type used by the DHCPv4 server.
Definition: cfg_iface.h:134
@ SOCKET_UDP
Datagram socket, i.e. IP/UDP socket.
Definition: cfg_iface.h:138
@ SOCKET_RAW
Raw socket, used for direct DHCPv4 traffic.
Definition: cfg_iface.h:136
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
Definition: cfg_iface.cc:463
std::string outboundTypeToText() const
Returns outbound interface selection mode as string.
Definition: cfg_iface.cc:258
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
bool operator==(const CfgIface &other) const
Equality operator.
Definition: cfg_iface.h:280
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
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
DuplicateAddress(const char *file, size_t line, const char *what)
Definition: cfg_iface.h:46
Exception thrown when duplicated interface names specified.
Definition: cfg_iface.h:23
DuplicateIfaceName(const char *file, size_t line, const char *what)
Definition: cfg_iface.h:25
Represents a single network interface.
Definition: iface_mgr.h:118
Exception thrown when specified interface name is invalid.
Definition: cfg_iface.h:30
InvalidIfaceName(const char *file, size_t line, const char *what)
Definition: cfg_iface.h:32
Exception thrown when invalid socket type has been specified for the given family.
Definition: cfg_iface.h:60
InvalidSocketType(const char *file, size_t line, const char *what)
Definition: cfg_iface.h:62
Exception thrown when specified unicast address is not assigned to the interface specified.
Definition: cfg_iface.h:52
NoSuchAddress(const char *file, size_t line, const char *what)
Definition: cfg_iface.h:54
Exception thrown when specified interface doesn't exist in a system.
Definition: cfg_iface.h:37
NoSuchIface(const char *file, size_t line, const char *what)
Definition: cfg_iface.h:39
boost::shared_ptr< Element > ElementPtr
Definition: data.h:24
boost::shared_ptr< const CfgIface > ConstCfgIfacePtr
A pointer to the const CfgIface.
Definition: cfg_iface.h:390
boost::shared_ptr< CfgIface > CfgIfacePtr
A pointer to the CfgIface .
Definition: cfg_iface.h:387
Defines the logger used by the top-level component of kea-lfc.
Abstract class for configuration Cfg_* classes.
Base class for user context.
Definition: user_context.h:22