 |
Kea
1.5.0
|
Go to the documentation of this file.
12 #include <boost/bind.hpp>
13 #include <boost/foreach.hpp>
22 const char* CfgIface::ALL_IFACES_KEYWORD =
"*";
25 : wildcard_used_(false), socket_type_(SOCKET_RAW), re_detect_(false),
26 outbound_iface_(SAME_AS_INBOUND) {
36 return (iface_set_ == other.iface_set_ &&
37 address_map_ == other.address_map_ &&
38 wildcard_used_ == other.wildcard_used_ &&
39 socket_type_ == other.socket_type_);
43 CfgIface::multipleAddressesPerInterfaceActive()
const {
45 BOOST_FOREACH(
IfacePtr iface, ifaces) {
46 if (iface->countActive4() > 1) {
55 const bool use_bcast)
const {
62 bool loopback_used_ =
false;
63 if ((family == AF_INET6) || (socket_type_ ==
SOCKET_UDP)) {
65 for (IfaceSet::const_iterator iface_name = iface_set_.begin();
66 iface_name != iface_set_.end(); ++iface_name) {
68 if (iface && iface->flag_loopback_) {
69 loopback_used_ =
true;
73 for (ExplicitAddressMap::const_iterator unicast = address_map_.begin();
74 unicast != address_map_.end(); ++unicast) {
76 if (iface && iface->flag_loopback_) {
77 loopback_used_ =
true;
86 setState(family, !wildcard_used_, !loopback_used_);
107 if (!wildcard_used_) {
108 for (IfaceSet::const_iterator iface_name = iface_set_.begin();
109 iface_name != iface_set_.end(); ++iface_name) {
117 "fail to open socket on interface '"
118 << *iface_name <<
"' as this interface doesn't"
121 }
else if (family == AF_INET) {
122 iface->inactive4_ =
false;
123 setIfaceAddrsState(family,
true, *iface);
126 iface->inactive6_ =
false;
133 for (ExplicitAddressMap::const_iterator unicast = address_map_.begin();
134 unicast != address_map_.end(); ++unicast) {
138 "fail to open unicast socket on interface '"
139 << unicast->first <<
"' as this interface doesn't"
142 if (family == AF_INET6) {
143 iface->addUnicast(unicast->second);
144 iface->inactive6_ =
false;
147 iface->setActive(unicast->second,
true);
148 iface->inactive4_ =
false;
156 boost::bind(&CfgIface::socketOpenErrorHandler, _1);
158 if (family == AF_INET) {
161 const bool can_use_bcast = use_bcast && (socket_type_ ==
SOCKET_RAW);
167 if (can_use_bcast && multipleAddressesPerInterfaceActive()) {
185 wildcard_used_ =
false;
187 address_map_.clear();
192 CfgIface::setState(
const uint16_t family,
const bool inactive,
193 const bool loopback_inactive)
const {
195 BOOST_FOREACH(
IfacePtr iface, ifaces) {
196 bool iface_inactive = iface->flag_loopback_ ? loopback_inactive : inactive;
197 if (family == AF_INET) {
198 iface->inactive4_ = iface_inactive;
200 iface->inactive6_ = iface_inactive;
204 setIfaceAddrsState(family, !inactive, *iface);
209 CfgIface::setIfaceAddrsState(
const uint16_t family,
const bool active,
210 Iface& iface)
const {
213 if (addr.get().getFamily() == family) {
214 iface.setActive(addr.get(), active);
220 CfgIface::socketOpenErrorHandler(
const std::string& errmsg) {
226 switch (socket_type_) {
242 if (socket_type_name ==
"udp") {
245 }
else if (socket_type_name ==
"raw") {
250 << socket_type_name <<
"'");
256 return (outbound_iface_);
261 switch (outbound_iface_) {
263 return (
"same-as-inbound");
265 return (
"use-routing");
274 if (txt ==
"same-as-inbound") {
277 }
else if (txt ==
"use-routing") {
288 outbound_iface_ = outbound_iface;
299 size_t pos = iface_name.find(
"/");
301 std::string addr_str;
303 if (pos == std::string::npos) {
307 "empty interface name used in configuration");
312 <<
"' doesn't exist in the system");
315 }
else if (wildcard_used_) {
321 DHCPSRV_CFGMGR_ALL_IFACES_ACTIVE);
322 wildcard_used_ =
true;
336 "empty interface name specified in the"
337 " interface configuration");
341 if (addr_str.empty()) {
343 "empty address specified in the interface"
344 <<
" configuration");
352 <<
"' must not be used in conjunction with an"
361 <<
"' doesn't exist in the system");
370 if (family == AF_INET6) {
374 " a valid IPv6 unicast address");
381 .arg(addr.
toText()).arg(name);
387 " a valid IPv4 address");
392 if (!iface->hasAddress(addr)) {
394 "interface '" << name <<
"' doesn't have address '"
395 << addr <<
"' assigned");
401 if ((family == AF_INET) && (iface_set_.find(iface->getName()) != iface_set_.end())) {
403 <<
"' has already been selected");
407 std::pair<const std::string, IOAddress> iface_address_tuple(name, addr);
408 if (std::find(address_map_.begin(), address_map_.end(),
409 iface_address_tuple) != address_map_.end()) {
411 << addr <<
"' for interface '" << name <<
"' "
412 "because this address is already selected");
415 if (family == AF_INET6) {
417 .arg(addr.
toText()).arg(name);
421 .arg(addr.
toText()).arg(name);
423 address_map_.insert(std::pair<std::string, IOAddress>(name, addr));
431 if ((iface_set_.find(name) != iface_set_.end()) ||
432 ((family == AF_INET) && address_map_.count(name) > 0)) {
434 <<
"' has already been specified");
439 if (addr_str.empty()) {
442 iface_set_.insert(name);
449 if (family != AF_INET) {
451 " the DHCPv6 server");
453 socket_type_ = socket_type;
460 const std::string& socket_type_name) {
473 if (wildcard_used_) {
476 for (IfaceSet::const_iterator iface = iface_set_.cbegin();
477 iface != iface_set_.cend(); ++iface) {
478 ifaces->add(Element::create(*iface));
480 for (ExplicitAddressMap::const_iterator address = address_map_.cbegin();
481 address != address_map_.cend(); ++address) {
482 std::string spec = address->first +
"/" + address->second.toText();
483 ifaces->add(Element::create(spec));
485 result->set(
"interfaces", ifaces);
490 result->set(
"dhcp-socket-type", Element::create(std::string(
"udp")));
498 result->set(
"re-detect", Element::create(re_detect_));
static const char * ALL_IFACES_KEYWORD
Keyword used to enable all interfaces.
A generic exception that is thrown when an unexpected error condition occurs.
void setOutboundIface(const OutboundIface &outbound_iface)
Sets outbound interface selection mode.
void closeSockets() const
Convenience function which closes all open sockets.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
The IOAddress class represents an IP addresses (version agnostic)
string trim(const string &instring)
Trim Leading and Trailing Spaces.
bool openSockets4(const uint16_t port=DHCP4_SERVER_PORT, const bool use_bcast=true, IfaceMgrErrorMsgCallback error_handler=0)
Opens IPv4 sockets on detected interfaces.
Exception thrown when duplicated address specified.
void clearUnicasts()
Clears unicast addresses on all interfaces.
IfacePtr getIface(int ifindex)
Returns interface specified interface index.
bool isV6() const
Convenience function to check for an IPv6 address.
util::OptionalValue< asiolink::IOAddress > Address
Address type.
void use(const uint16_t family, const std::string &iface_name)
Select interface to be used to receive DHCP traffic.
@ SOCKET_RAW
Raw socket, used for direct DHCPv4 traffic.
bool isV6LinkLocal() const
checks whether and address is IPv6 and is link-local
@ SAME_AS_INBOUND
Server sends responses over the same interface on which queries are received.
boost::function< void(const std::string &errmsg)> IfaceMgrErrorMsgCallback
This type describes the callback function invoked when error occurs in the IfaceMgr.
Defines the logger used by the top-level component of kea-dhcp-ddns.
std::string outboundTypeToText() const
Returns outbound interface selection mode as string.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Exception thrown when specified unicast address is not assigned to the interface specified.
void setAllowLoopBack(const bool allow_loopback)
Allows or disallows the loopback interface.
@ USE_ROUTING
Server uses routing to determine the right interface to send response.
void setMatchingPacketFilter(const bool direct_response_desired=false)
Set Packet Filter object to handle send/receive packets.
const int DHCPSRV_DBG_TRACE
DHCP server library logging levels.
void closeSockets()
Closes all open sockets.
bool isDirectResponseSupported() const
Check if packet be sent directly to the client having no address.
static IfaceMgr & instance()
IfaceMgr is a singleton class.
const IfaceCollection & getIfaces()
Returns container with all interfaces.
Represents selection of interfaces for DHCP server.
bool isV6Multicast() const
checks whether and address is IPv6 and is multicast
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
Handles network interfaces, transmission and reception.
Exception thrown when invalid socket type has been specified for the given family.
std::string toText() const
Convert the address to a string.
Exception thrown when specified interface name is invalid.
Exception thrown when specified interface doesn't exist in a system.
OutboundIface getOutboundIface() const
Returns outbound interface selection mode.
void contextToElement(data::ElementPtr map) const
Merge unparse a user_context object.
std::string socketTypeToText() const
Returns the socket type in the textual format.
@ SOCKET_UDP
Datagram socket, i.e. IP/UDP socket.
Exception thrown when duplicated interface names specified.
SocketType
Socket type used by the DHCPv4 server.
void openSockets(const uint16_t family, const uint16_t port, const bool use_bcast=true) const
Tries to open sockets on selected interfaces.
boost::shared_ptr< Element > ElementPtr
bool openSockets6(const uint16_t port=DHCP6_SERVER_PORT, IfaceMgrErrorMsgCallback error_handler=0)
Opens IPv6 sockets on detected interfaces.
void useSocketType(const uint16_t family, const SocketType &socket_type)
Sets the specified socket type to be used by the server.
static OutboundIface textToOutboundIface(const std::string &txt)
Converts text to outbound interface selection mode.
bool equals(const CfgIface &other) const
Compares two CfgIface objects for equality.
OutboundIface
Indicates how outbound interface is selected for relayed traffic.
std::list< IfacePtr > IfaceCollection
Type that holds a list of pointers to interfaces.
bool isV4() const
Convenience function to check for an IPv4 address.
boost::shared_ptr< Iface > IfacePtr
SocketType textToSocketType(const std::string &socket_type_name) const
Converts the socket type in the textual format to the type represented by the SocketType.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
void reset()
Puts the interface configuration into default state.