Kea 2.5.8
isc::dhcp::CfgIface Class Reference

Represents selection of interfaces for DHCP server. More...

#include <cfg_iface.h>

+ Inheritance diagram for isc::dhcp::CfgIface:

Public Types

typedef std::function< void(util::ReconnectCtlPtr)> OpenSocketsFailedCallback
 Represents a callback invoked if all retries of the opening sockets fail.
 
enum  OutboundIface { SAME_AS_INBOUND , USE_ROUTING }
 Indicates how outbound interface is selected for relayed traffic. More...
 
enum  SocketType { SOCKET_RAW , SOCKET_UDP }
 Socket type used by the DHCPv4 server. More...
 

Public Member Functions

 CfgIface ()
 Constructor.
 
void closeSockets () const
 Convenience function which closes all open sockets.
 
bool equals (const CfgIface &other) const
 Compares two CfgIface objects for equality.
 
OutboundIface getOutboundIface () const
 Returns outbound interface selection mode.
 
util::ReconnectCtlPtr getReconnectCtl () const
 Get the reconnect controller.
 
uint32_t getServiceSocketsMaxRetries () const
 Indicates the maximum number of service sockets bind attempts.
 
bool getServiceSocketsRequireAll () const
 Indicates that Kea must successfully bind all socket services on init.
 
uint32_t getServiceSocketsRetryWaitTime () const
 Indicates the socket service binding retry interval between attempts.
 
SocketType getSocketType () const
 Returns DHCP socket type used by the server.
 
void openSockets (const uint16_t family, const uint16_t port, const bool use_bcast=true)
 Tries to open sockets on selected interfaces.
 
bool operator!= (const CfgIface &other) const
 Inequality operator.
 
bool operator== (const CfgIface &other) const
 Equality operator.
 
std::string outboundTypeToText () const
 Returns outbound interface selection mode as string.
 
void reset ()
 Puts the interface configuration into default state.
 
void setOutboundIface (const OutboundIface &outbound_iface)
 Sets outbound interface selection mode.
 
void setReDetect (bool re_detect)
 Set the re-detect flag.
 
void setServiceSocketsMaxRetries (uint32_t max_retries)
 Set a maximum number of service sockets bind attempts.
 
void setServiceSocketsRequireAll (bool require_all)
 Set flag that Kea must successfully bind all socket services on init.
 
void setServiceSocketsRetryWaitTime (uint32_t interval)
 Set the socket service binding retry interval between attempts.
 
std::string socketTypeToText () const
 Returns the socket type in the textual format.
 
SocketType textToSocketType (const std::string &socket_type_name) const
 Converts the socket type in the textual format to the type represented by the SocketType.
 
virtual isc::data::ElementPtr toElement () const
 Unparse a configuration object.
 
void use (const uint16_t family, const std::string &iface_name)
 Select interface to be used to receive DHCP traffic.
 
void useSocketType (const uint16_t family, const SocketType &socket_type)
 Sets the specified socket type to be used by the server.
 
void useSocketType (const uint16_t family, const std::string &socket_type_name)
 Sets the specified socket type specified in textual format.
 
- Public Member Functions inherited from isc::data::UserContext
void contextToElement (data::ElementPtr map) const
 Merge unparse a user_context object.
 
data::ConstElementPtr getContext () const
 Returns const pointer to the user context.
 
void setContext (const data::ConstElementPtr &ctx)
 Sets user context.
 
- Public Member Functions inherited from isc::data::CfgToElement
virtual ~CfgToElement ()
 Destructor.
 
virtual isc::data::ElementPtr toElement () const =0
 Unparse a configuration object.
 

Static Public Member Functions

static OutboundIface textToOutboundIface (const std::string &txt)
 Converts text to outbound interface selection mode.
 
- Static Public Member Functions inherited from isc::data::UserContext
static data::ElementPtr toElement (data::ConstElementPtr map)
 Copy an Element map.
 

Static Public Attributes

static const char * ALL_IFACES_KEYWORD = "*"
 Keyword used to enable all interfaces.
 
static OpenSocketsFailedCallback open_sockets_failed_callback_ = 0
 Optional callback function to invoke if all retries of the opening sockets fail.
 

Additional Inherited Members

- Protected Attributes inherited from isc::data::UserContext
data::ConstElementPtr user_context_
 Pointer to the user context (may be NULL)
 

Detailed Description

Represents selection of interfaces for DHCP server.

This class manages selection of interfaces on which the DHCP server is listening to queries. The interfaces are selected in the server configuration by their names or by the pairs of interface names and addresses, e.g. eth0/2001:db8:1::1 (DHCPv6) or e.g. eth0/192.168.8.1 (DHCPv4).

This class also accepts "wildcard" interface name which, if specified, instructs the server to listen on all available interfaces.

Once interfaces have been specified the sockets (either IPv4 or IPv6) can be opened by calling CfgIface::openSockets function. Kea offers configuration parameters to control the types of sockets to be opened by the DHCPv4 server. In small deployments it is requires that the server can handle messages from the directly connected clients which don't have an address yet. Unicasting the response to such client is possible by the use of raw sockets. In larger deployments it is often the case that whole traffic is received via relays, and in such case the use of UDP sockets is preferred. The type of the sockets to be opened is specified using one of the CfgIface::useSocketType method variants. The CfgIface::SocketType enumeration specifies the possible values.

Warning
This class makes use of the AF_INET and AF_INET6 family literals, but it doesn't verify that the address family value passed as uint16_t parameter is equal to one of them. It is a callers responsibility to guarantee that the address family value is correct.

The interface name is passed as an argument of the CfgIface::use function which controls the selection of the interface on which the DHCP queries should be received by the server. The interface name passed as the argument of this function may appear in one of the following formats:

  • interface-name, e.g. eth0
  • interface-name/address, e.g. eth0/2001:db8:1::1 or eth0/192.168.8.1

Extraneous spaces surrounding the interface name and/or address are accepted. For example: eth0 / 2001:db8:1::1 will be accepted.

When only interface name is specified (without an address) it is allowed to use the "wildcard" interface name (*) which indicates that the server should open sockets on all interfaces. When IPv6 is in use, the sockets will be bound to the link local addresses. Wildcard interface names are not allowed when specifying a unicast address. For example: *‍/2001:db8:1::1 is not allowed.

The DHCPv6 configuration accepts simultaneous use of the "interface-name" and "interface-name/address" tuple for the same interface, e.g. "eth0", "eth0/2001:db8:1::1" specifies that the server should open a socket and bind to link local address as well as open a socket bound to the specified unicast address.

The DHCPv4 configuration doesn't accept the simultaneous use of the "interface-name" and the "interface-name/address" tuple for the given interface. When the "interface-name" is specified it implies that the sockets will be opened on for all addresses configured on this interface. If the tuple of "interface-name/address" is specified there will be only one socket opened and bound to the specified address. This socket will be configured to listen to the broadcast messages reaching the interface as well as unicast messages sent to the address to which it is bound. It is allowed to select multiple addresses on the particular interface explicitly, e.g. "eth0/192.168.8.1", "eth0/192.168.8.2".

Definition at line 131 of file cfg_iface.h.

Member Typedef Documentation

◆ OpenSocketsFailedCallback

Represents a callback invoked if all retries of the opening sockets fail.

Definition at line 357 of file cfg_iface.h.

Member Enumeration Documentation

◆ OutboundIface

Indicates how outbound interface is selected for relayed traffic.

Enumerator
SAME_AS_INBOUND 

Server sends responses over the same interface on which queries are received.

USE_ROUTING 

Server uses routing to determine the right interface to send response.

Definition at line 143 of file cfg_iface.h.

◆ SocketType

Socket type used by the DHCPv4 server.

Enumerator
SOCKET_RAW 

Raw socket, used for direct DHCPv4 traffic.

SOCKET_UDP 

Datagram socket, i.e. IP/UDP socket.

Definition at line 135 of file cfg_iface.h.

Constructor & Destructor Documentation

◆ CfgIface()

isc::dhcp::CfgIface::CfgIface ( )

Constructor.

Definition at line 30 of file cfg_iface.cc.

Member Function Documentation

◆ closeSockets()

void isc::dhcp::CfgIface::closeSockets ( ) const

Convenience function which closes all open sockets.

It stops the receiver thread too.

Definition at line 38 of file cfg_iface.cc.

References isc::dhcp::IfaceMgr::closeSockets(), and isc::dhcp::IfaceMgr::instance().

Referenced by openSockets().

+ Here is the call graph for this function:

◆ equals()

bool isc::dhcp::CfgIface::equals ( const CfgIface other) const

Compares two CfgIface objects for equality.

Parameters
otherAn object to be compared with this object.
Returns
true if objects are equal, false otherwise.

Definition at line 43 of file cfg_iface.cc.

Referenced by operator!=(), and operator==().

◆ getOutboundIface()

CfgIface::OutboundIface isc::dhcp::CfgIface::getOutboundIface ( ) const

Returns outbound interface selection mode.

Returns
Outbound interface selection mode.

Definition at line 343 of file cfg_iface.cc.

◆ getReconnectCtl()

util::ReconnectCtlPtr isc::dhcp::CfgIface::getReconnectCtl ( ) const
inline

Get the reconnect controller.

Returns
the reconnect controller

Definition at line 351 of file cfg_iface.h.

◆ getServiceSocketsMaxRetries()

uint32_t isc::dhcp::CfgIface::getServiceSocketsMaxRetries ( ) const
inline

Indicates the maximum number of service sockets bind attempts.

Returns
Number of attempts.

Definition at line 344 of file cfg_iface.h.

◆ getServiceSocketsRequireAll()

bool isc::dhcp::CfgIface::getServiceSocketsRequireAll ( ) const
inline

Indicates that Kea must successfully bind all socket services on init.

Returns
true if all sockets must be bound, false otherwise.

Definition at line 316 of file cfg_iface.h.

◆ getServiceSocketsRetryWaitTime()

uint32_t isc::dhcp::CfgIface::getServiceSocketsRetryWaitTime ( ) const
inline

Indicates the socket service binding retry interval between attempts.

Returns
Milliseconds between attempts.

Definition at line 330 of file cfg_iface.h.

◆ getSocketType()

SocketType isc::dhcp::CfgIface::getSocketType ( ) const
inline

Returns DHCP socket type used by the server.

Definition at line 241 of file cfg_iface.h.

◆ openSockets()

void isc::dhcp::CfgIface::openSockets ( const uint16_t  family,
const uint16_t  port,
const bool  use_bcast = true 
)

Tries to open sockets on selected interfaces.

This function opens sockets bound to link-local address as well as sockets bound to unicast address. See CfgIface::use function documentation for details how to specify interfaces and unicast addresses to bind the sockets to. This function starts the family receiver.

Parameters
familyAddress family (AF_INET or AF_INET6).
portPort number to be used to bind sockets to.
use_bcastA boolean flag which indicates if the broadcast traffic should be received through the socket. This parameter is ignored for IPv6.

Definition at line 61 of file cfg_iface.cc.

References isc::dhcp::IfaceMgr::clearUnicasts(), closeSockets(), isc::dhcp::DHCPSRV_CFGMGR_SOCKET_RAW_UNSUPPORTED, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_MULTIPLE_RAW_SOCKETS_PER_IFACE, isc::dhcp::DHCPSRV_NO_SOCKETS_OPEN, isc::dhcp::IfaceMgr::getIface(), isc::dhcp::IfaceMgr::instance(), isc_throw, isc::dhcp::IfaceMgr::isDirectResponseSupported(), LOG_WARN, isc::dhcp::IfaceMgr::setAllowLoopBack(), isc::dhcp::IfaceMgr::setMatchingPacketFilter(), SOCKET_RAW, and SOCKET_UDP.

+ Here is the call graph for this function:

◆ operator!=()

bool isc::dhcp::CfgIface::operator!= ( const CfgIface other) const
inline

Inequality operator.

Parameters
otherObject to be compared with this object.
Returns
true if objects are not equal, false otherwise.

Definition at line 290 of file cfg_iface.h.

References equals().

+ Here is the call graph for this function:

◆ operator==()

bool isc::dhcp::CfgIface::operator== ( const CfgIface other) const
inline

Equality operator.

Parameters
otherObject to be compared with this object.
Returns
true if objects are equal, false otherwise.

Definition at line 281 of file cfg_iface.h.

References equals().

+ Here is the call graph for this function:

◆ outboundTypeToText()

std::string isc::dhcp::CfgIface::outboundTypeToText ( ) const

Returns outbound interface selection mode as string.

Returns
text representation of the outbound interface selection mode.

Definition at line 348 of file cfg_iface.cc.

References isc_throw, SAME_AS_INBOUND, and USE_ROUTING.

Referenced by toElement().

◆ reset()

void isc::dhcp::CfgIface::reset ( )

Puts the interface configuration into default state.

This function removes interface names from the set.

Definition at line 273 of file cfg_iface.cc.

References SOCKET_RAW, and useSocketType().

+ Here is the call graph for this function:

◆ setOutboundIface()

void isc::dhcp::CfgIface::setOutboundIface ( const OutboundIface outbound_iface)

Sets outbound interface selection mode.

Parameters
outbound_ifaceNew outbound interface selection mode setting.

Definition at line 375 of file cfg_iface.cc.

◆ setReDetect()

void isc::dhcp::CfgIface::setReDetect ( bool  re_detect)
inline

Set the re-detect flag.

Parameters
re_detectthe new value of the flag

Definition at line 302 of file cfg_iface.h.

◆ setServiceSocketsMaxRetries()

void isc::dhcp::CfgIface::setServiceSocketsMaxRetries ( uint32_t  max_retries)
inline

Set a maximum number of service sockets bind attempts.

Parameters
max_retriesNumber of attempts. The value 0 disables retries.

Definition at line 337 of file cfg_iface.h.

◆ setServiceSocketsRequireAll()

void isc::dhcp::CfgIface::setServiceSocketsRequireAll ( bool  require_all)
inline

Set flag that Kea must successfully bind all socket services on init.

Parameters
require_alltrue if all sockets must be bound, false otherwise.

Definition at line 309 of file cfg_iface.h.

◆ setServiceSocketsRetryWaitTime()

void isc::dhcp::CfgIface::setServiceSocketsRetryWaitTime ( uint32_t  interval)
inline

Set the socket service binding retry interval between attempts.

Parameters
intervalMilliseconds between attempts.

Definition at line 323 of file cfg_iface.h.

◆ socketTypeToText()

std::string isc::dhcp::CfgIface::socketTypeToText ( ) const

Returns the socket type in the textual format.

Definition at line 313 of file cfg_iface.cc.

References isc_throw, SOCKET_RAW, and SOCKET_UDP.

Referenced by useSocketType().

◆ textToOutboundIface()

CfgIface::OutboundIface isc::dhcp::CfgIface::textToOutboundIface ( const std::string &  txt)
static

Converts text to outbound interface selection mode.

Parameters
txteither 'same-as-inbound' or 'use-routing'
Returns
Outbound interface selection mode.

Definition at line 361 of file cfg_iface.cc.

References isc_throw, SAME_AS_INBOUND, and USE_ROUTING.

Referenced by isc::dhcp::IfacesConfigParser::parse().

◆ textToSocketType()

CfgIface::SocketType isc::dhcp::CfgIface::textToSocketType ( const std::string &  socket_type_name) const

Converts the socket type in the textual format to the type represented by the SocketType.

Exceptions
InvalidSocketTypeif the specified value of the socket_type_name is invalid.

Definition at line 329 of file cfg_iface.cc.

References isc_throw, SOCKET_RAW, and SOCKET_UDP.

Referenced by useSocketType().

◆ toElement()

ElementPtr isc::dhcp::CfgIface::toElement ( ) const
virtual

Unparse a configuration object.

Returns
a pointer to unparsed configuration

Implements isc::data::CfgToElement.

Definition at line 553 of file cfg_iface.cc.

References ALL_IFACES_KEYWORD, isc::data::UserContext::contextToElement(), isc::data::Element::create(), isc::data::Element::createList(), isc::data::Element::createMap(), outboundTypeToText(), SAME_AS_INBOUND, and SOCKET_RAW.

+ Here is the call graph for this function:

◆ use()

void isc::dhcp::CfgIface::use ( const uint16_t  family,
const std::string &  iface_name 
)

Select interface to be used to receive DHCP traffic.

CfgIface for a detail explanation of the interface name argument.

Parameters
familyAddress family (AF_INET or AF_INET6).
iface_nameExplicit interface name, a wildcard name (*) of the interface(s) or the pair of interface/unicast-address to be used to receive DHCP traffic.
Exceptions
InvalidIfaceNameIf the interface name is incorrect, e.g. empty.
NoSuchIfaceIf the specified interface is not present.
NoSuchAddressIf the specified unicast address is not assigned to the interface.
DuplicateIfaceNameIf the interface is already selected, i.e.
IOErrorwhen specified unicast address is invalid. CfgIface::use has been already called for this interface.

Definition at line 380 of file cfg_iface.cc.

References ALL_IFACES_KEYWORD, isc::dhcp::DHCPSRV_CFGMGR_ADD_IFACE, isc::dhcp::DHCPSRV_CFGMGR_ALL_IFACES_ACTIVE, isc::dhcp::DHCPSRV_CFGMGR_UNICAST_LINK_LOCAL, isc::dhcp::DHCPSRV_CFGMGR_USE_ADDRESS, isc::dhcp::DHCPSRV_CFGMGR_USE_UNICAST, isc::dhcp::DHCPSRV_DBG_TRACE, isc::dhcp::dhcpsrv_logger, isc::dhcp::IfaceMgr::getIface(), isc::dhcp::IfaceMgr::instance(), isc_throw, isc::asiolink::IOAddress::isV4(), isc::asiolink::IOAddress::isV6(), isc::asiolink::IOAddress::isV6LinkLocal(), isc::asiolink::IOAddress::isV6Multicast(), LOG_DEBUG, LOG_INFO, LOG_WARN, isc::asiolink::IOAddress::toText(), and isc::util::str::trim().

+ Here is the call graph for this function:

◆ useSocketType() [1/2]

void isc::dhcp::CfgIface::useSocketType ( const uint16_t  family,
const SocketType socket_type 
)

Sets the specified socket type to be used by the server.

Supported socket types for DHCPv4 are:

  • SOCKET_RAW
  • SOCKET_UDP
Parameters
familyAddress family (AF_INET or AF_INET6).
socket_typeSocket type.
Exceptions
InvalidSocketTypeif the unsupported socket type has been specified for the address family. Currently, the socket type can only be selected for the AF_INET family.

Definition at line 535 of file cfg_iface.cc.

References isc::dhcp::DHCPSRV_CFGMGR_SOCKET_TYPE_SELECT, isc::dhcp::dhcpsrv_logger, isc_throw, LOG_INFO, and socketTypeToText().

Referenced by reset(), and useSocketType().

+ Here is the call graph for this function:

◆ useSocketType() [2/2]

void isc::dhcp::CfgIface::useSocketType ( const uint16_t  family,
const std::string &  socket_type_name 
)

Sets the specified socket type specified in textual format.

The following names of the socket types are currently supported, and can be passed in the socket_type parameter:

  • raw - for raw sockets,
  • udp - for the IP/UDP datagram sockets,
Parameters
familyAddress family (AF_INET or AF_INET6)
socket_type_nameSocket type in the textual format.
Exceptions
InvalidSocketTypeif the unsupported socket type has been specified for the address family. Currently, the socket type can only be selected for the AF_INET family.

Definition at line 547 of file cfg_iface.cc.

References textToSocketType(), and useSocketType().

+ Here is the call graph for this function:

Member Data Documentation

◆ ALL_IFACES_KEYWORD

const char * isc::dhcp::CfgIface::ALL_IFACES_KEYWORD = "*"
static

Keyword used to enable all interfaces.

This keyword can be used instead of the interface name to specify that DHCP server should listen on all interfaces.

Definition at line 155 of file cfg_iface.h.

Referenced by toElement(), and use().

◆ open_sockets_failed_callback_

CfgIface::OpenSocketsFailedCallback isc::dhcp::CfgIface::open_sockets_failed_callback_ = 0
static

Optional callback function to invoke if all retries of the opening sockets fail.

Definition at line 361 of file cfg_iface.h.

Referenced by isc::dhcp::ControlledDhcpv4Srv::processConfig(), and isc::dhcp::ControlledDhcpv6Srv::processConfig().


The documentation for this class was generated from the following files: