Kea 2.7.5
isc::dhcp::CfgSubnets4 Class Reference

Holds subnets configured for the DHCPv4 server. More...

#include <cfg_subnets4.h>

+ Inheritance diagram for isc::dhcp::CfgSubnets4:

Public Member Functions

void add (const Subnet4Ptr &subnet)
 Adds new subnet to the configuration.
 
void clear ()
 Clears all subnets from the configuration.
 
void del (const ConstSubnet4Ptr &subnet)
 Removes subnet from the configuration.
 
void del (const SubnetID &subnet_id)
 Removes subnet from the configuration.
 
const Subnet4CollectiongetAll () const
 Returns pointer to the collection of all IPv4 subnets.
 
ConstSubnet4Ptr getByPrefix (const std::string &subnet_prefix) const
 Returns const pointer to a subnet which matches the specified prefix in the canonical form.
 
ConstSubnet4Ptr getBySubnetId (const SubnetID &subnet_id) const
 Returns const pointer to a subnet identified by the specified subnet identifier.
 
SubnetIDSet getLinks (const asiolink::IOAddress &link_addr) const
 Convert a link address into a link set.
 
Subnet4Ptr getSubnet (const SubnetID id) const
 Returns subnet with specified subnet-id value.
 
bool hasSubnetWithServerId (const asiolink::IOAddress &server_id) const
 Checks if specified server identifier has been specified for any subnet.
 
void initAllocatorsAfterConfigure ()
 Calls initAllocatorsAfterConfigure for each subnet.
 
void merge (CfgOptionDefPtr cfg_def, CfgSharedNetworks4Ptr networks, CfgSubnets4 &other)
 Merges specified subnet configuration into this configuration.
 
void removeStatistics ()
 Removes statistics.
 
Subnet4Ptr replace (const Subnet4Ptr &subnet)
 Replaces subnet in the configuration.
 
ConstSubnet4Ptr selectSubnet (const asiolink::IOAddress &address, const ClientClasses &client_classes=ClientClasses()) const
 Returns a pointer to a subnet if provided address is in its range.
 
ConstSubnet4Ptr selectSubnet (const std::string &iface, const ClientClasses &client_classes) const
 Returns a pointer to a subnet if provided interface name matches.
 
ConstSubnet4Ptr selectSubnet (const SubnetSelector &selector) const
 Returns a pointer to the selected subnet.
 
ConstSubnet4Ptr selectSubnet4o6 (const SubnetSelector &selector) const
 Attempts to do subnet selection based on DHCP4o6 information.
 
virtual isc::data::ElementPtr toElement () const
 Unparse a configuration object.
 
void updateStatistics ()
 Updates statistics.
 
- Public Member Functions inherited from isc::data::CfgToElement
virtual ~CfgToElement ()
 Destructor.
 

Static Public Member Functions

static SubnetSelector initSelector (const Pkt4Ptr &query)
 Build selector from a client's message.
 

Detailed Description

Holds subnets configured for the DHCPv4 server.

This class holds a collection of subnets configured for the DHCPv4 server. It allows for retrieving a subnet for the particular client using various parameters extracted from the DHCPv4 message. These parameters must be assigned to the appropriate members of the CfgSubnets4::Selector structure.

See CfgSubnets4::selectSubnet documentation for more details on how the subnet is selected for the client.

Definition at line 33 of file cfg_subnets4.h.

Member Function Documentation

◆ add()

void isc::dhcp::CfgSubnets4::add ( const Subnet4Ptr & subnet)

Adds new subnet to the configuration.

Parameters
subnetPointer to the subnet being added.
Exceptions
isc::DuplicateSubnetIDIf the subnet id for the new subnet duplicates id of an existing subnet.
Todo
: Check that this new subnet does not cross boundaries of any other already defined subnet.

Definition at line 28 of file cfg_subnets4.cc.

References isc::dhcp::DHCPSRV_CFGMGR_ADD_SUBNET4, isc::dhcp::DHCPSRV_DBG_TRACE, isc::dhcp::dhcpsrv_logger, getByPrefix(), getBySubnetId(), isc_throw, and LOG_DEBUG.

+ Here is the call graph for this function:

◆ clear()

void isc::dhcp::CfgSubnets4::clear ( )

Clears all subnets from the configuration.

Definition at line 621 of file cfg_subnets4.cc.

◆ del() [1/2]

void isc::dhcp::CfgSubnets4::del ( const ConstSubnet4Ptr & subnet)

Removes subnet from the configuration.

Parameters
subnetPointer to the subnet to be removed.
Exceptions
isc::BadValueif such subnet doesn't exist.

Definition at line 67 of file cfg_subnets4.cc.

References del().

Referenced by del().

+ Here is the call graph for this function:

◆ del() [2/2]

void isc::dhcp::CfgSubnets4::del ( const SubnetID & subnet_id)

Removes subnet from the configuration.

Parameters
subnet_idIdentifier of the subnet to be removed.
Exceptions
isc::BadValueif such subnet doesn't exist.

Definition at line 72 of file cfg_subnets4.cc.

References isc::dhcp::DHCPSRV_CFGMGR_DEL_SUBNET4, isc::dhcp::DHCPSRV_DBG_TRACE, isc::dhcp::dhcpsrv_logger, isc_throw, and LOG_DEBUG.

◆ getAll()

const Subnet4Collection * isc::dhcp::CfgSubnets4::getAll ( ) const
inline

Returns pointer to the collection of all IPv4 subnets.

This is used in a hook (subnet4_select), where the hook is able to choose a different subnet. Server code has to offer a list of possible choices (i.e. all subnets).

Returns
A pointer to const Subnet4 collection

Definition at line 119 of file cfg_subnets4.h.

◆ getByPrefix()

ConstSubnet4Ptr isc::dhcp::CfgSubnets4::getByPrefix ( const std::string & subnet_prefix) const

Returns const pointer to a subnet which matches the specified prefix in the canonical form.

The const pointer is returned by this method to prevent a caller from modifying the subnet configuration. Modifications to subnet configuration is dangerous and must be done carefully. The subnets' configuration is held in the multi index container and any modifications to the subnet id or subnet prefix must trigger re-indexing of multi index container. There is no possibility to enforce this when the non-const pointer is returned.

Parameters
subnet_prefixSubnet prefix, e.g. 10.2.3.0/24
Returns
Pointer to the Subnet4 object or null pointer if such subnet doesn't exist.

Definition at line 192 of file cfg_subnets4.cc.

Referenced by add().

◆ getBySubnetId()

ConstSubnet4Ptr isc::dhcp::CfgSubnets4::getBySubnetId ( const SubnetID & subnet_id) const
inline

Returns const pointer to a subnet identified by the specified subnet identifier.

The const pointer is returned by this method to prevent a caller from modifying the subnet configuration. Modifications to subnet configuration is dangerous and must be done carefully. The subnets' configuration is held in the multi index container and any modifications to the subnet id or subnet prefix must trigger re-indexing of multi index container. There is no possibility to enforce this when the non-const pointer is returned.

Parameters
subnet_idSubnet identifier.
Returns
Pointer to the Subnet4 object or null pointer if such subnet doesn't exist.

Definition at line 138 of file cfg_subnets4.h.

References getSubnet().

Referenced by add().

+ Here is the call graph for this function:

◆ getLinks()

SubnetIDSet isc::dhcp::CfgSubnets4::getLinks ( const asiolink::IOAddress & link_addr) const

Convert a link address into a link set.

Given a link address this returns the ordered list aka set of id of subnets the address belongs to.

Todo
: extend to consider whether a shared network is a link.
Parameters
link_addrThe link address.
Returns
The set of subnet ids the link address belongs to.

Definition at line 494 of file cfg_subnets4.cc.

◆ getSubnet()

Subnet4Ptr isc::dhcp::CfgSubnets4::getSubnet ( const SubnetID id) const

Returns subnet with specified subnet-id value.

Please use getBySubnetId instead when possible.

Returns
Subnet (or null)

Definition at line 460 of file cfg_subnets4.cc.

Referenced by getBySubnetId().

◆ hasSubnetWithServerId()

bool isc::dhcp::CfgSubnets4::hasSubnetWithServerId ( const asiolink::IOAddress & server_id) const

Checks if specified server identifier has been specified for any subnet.

Parameters
server_idServer identifier.
Returns
true if there is a subnet with a specified server identifier.

Definition at line 199 of file cfg_subnets4.cc.

◆ initAllocatorsAfterConfigure()

void isc::dhcp::CfgSubnets4::initAllocatorsAfterConfigure ( )

Calls initAllocatorsAfterConfigure for each subnet.

Definition at line 614 of file cfg_subnets4.cc.

◆ initSelector()

SubnetSelector isc::dhcp::CfgSubnets4::initSelector ( const Pkt4Ptr & query)
static

Build selector from a client's message.

Note
: code moved from server.
Parameters
queryclient's message.
Returns
filled selector.

Definition at line 206 of file cfg_subnets4.cc.

References isc::dhcp::SubnetSelector::ciaddr_, isc::dhcp::DHO_DHCP_AGENT_OPTIONS, isc::dhcp::DHO_SUBNET_SELECTION, isc::asiolink::IOAddress::fromBytes(), isc::dhcp::CfgMgr::instance(), and isc::dhcp::RAI_OPTION_LINK_SELECTION.

Referenced by isc::dhcp::Dhcpv4Srv::selectSubnet().

+ Here is the call graph for this function:

◆ merge()

void isc::dhcp::CfgSubnets4::merge ( CfgOptionDefPtr cfg_def,
CfgSharedNetworks4Ptr networks,
CfgSubnets4 & other )

Merges specified subnet configuration into this configuration.

This method merges subnets from the other configuration into this configuration. The general rule is that existing subnets are replaced by the subnets from other. If there is no corresponding subnet in this configuration the subnet from other configuration is inserted.

The complexity of the merge process stems from the associations between the subnets and shared networks. It is assumed that subnets in other are the authority on their shared network assignments. It is also assumed that @ networks is the list of shared networks that should be used in making assignments. The general concept is that the overarching merge process will first merge shared networks and then pass that list of networks into this method. Subnets from other are then merged into this configuration as follows:

For each subnet in other:

  • If a subnet of the same ID already exists in this configuration:
    1. If it belongs to a shared network, remove it from that network
    2. Remove the subnet from this configuration and discard it
  • Create the subnet's option instance, as well as any options that belong to any of the subnet's pools.
  • Add the subnet from other to this configuration.
  • If that subnet is associated to shared network, find that network in @ networks and add that subnet to it.
Warning
The merge operation affects the other configuration. Therefore, the caller must not rely on the data held in the other object after the call to merge. Also, the data held in other must not be modified after the call to merge because it may affect the merged configuration.
Parameters
cfg_defset of user-defined option definitions to use when creating option instances.
networkscollection of shared networks that to which assignments should be added. In other words, the list of shared networks that belong to the same SrvConfig instance we are merging into.
otherthe subnet configuration to be merged into this configuration.

Definition at line 89 of file cfg_subnets4.cc.

References isc_throw, and isc::dhcp::Lease::TYPE_V4.

◆ removeStatistics()

void isc::dhcp::CfgSubnets4::removeStatistics ( )

Removes statistics.

During commitment of a new configuration, we need to get rid of the old statistics for the old configuration. In particular, we need to remove anything related to subnets, as there may be fewer subnets in the new configuration and also subnet-ids may change.

Definition at line 506 of file cfg_subnets4.cc.

References isc::dhcp::Lease::TYPE_V4.

◆ replace()

Subnet4Ptr isc::dhcp::CfgSubnets4::replace ( const Subnet4Ptr & subnet)

Replaces subnet in the configuration.

This method replaces a subnet by another subnet with the same ID. The prefix should be the same too.

Parameters
subnetPointer to the subnet being updated.
Exceptions
BadValueif the subnet to update does not exit.
Returns
Pointer to the replaced subnet or null if it failed.

Definition at line 46 of file cfg_subnets4.cc.

References isc::dhcp::DHCPSRV_CFGMGR_UPDATE_SUBNET4, isc::dhcp::DHCPSRV_DBG_TRACE, isc::dhcp::dhcpsrv_logger, isc_throw, and LOG_DEBUG.

◆ selectSubnet() [1/3]

ConstSubnet4Ptr isc::dhcp::CfgSubnets4::selectSubnet ( const asiolink::IOAddress & address,
const ClientClasses & client_classes = ClientClasses() ) const

Returns a pointer to a subnet if provided address is in its range.

This method returns a pointer to the subnet if the address passed in parameter is in range with this subnet. This is mainly used for unit testing. This method is also called by the selectSubnet(SubnetSelector).

Todo
This method requires performance improvement! It currently iterates over all existing subnets to find the one which fulfills the search criteria. The subnet storage is implemented as a simple STL vector which precludes fast searches using specific keys. Hence, full scan is required. To improve the search performance a different container type is required, e.g. multi-index container, or something of a similar functionality.
Parameters
addressAddress for which the subnet is searched.
client_classesOptional parameter specifying the classes that the client belongs to.
Returns
Pointer to the selected subnet or null if no subnet found.

Definition at line 467 of file cfg_subnets4.cc.

References isc::dhcp::DHCPSRV_CFGMGR_SUBNET4_ADDR, isc::dhcp::DHCPSRV_DBG_TRACE, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_SUBNET4_SELECT_BY_ADDRESS_NO_MATCH, and LOG_DEBUG.

◆ selectSubnet() [2/3]

ConstSubnet4Ptr isc::dhcp::CfgSubnets4::selectSubnet ( const std::string & iface,
const ClientClasses & client_classes ) const

Returns a pointer to a subnet if provided interface name matches.

This method returns a pointer to the subnet if the interface name passed in parameter iface matches that of a subnet. This is mainly used for matching local incoming traffic, even when the addresses on local interfaces do not match a subnet definition. This method is also called by the selectSubnet(SubnetSelector).

Todo
This method requires performance improvement! It currently iterates over all existing subnets to find the one which fulfills the search criteria. The subnet storage is implemented as a simple STL vector which precludes fast searches using specific keys. Hence, full scan is required. To improve the search performance a different container type is required, e.g. multi-index container, or something of a similar functionality.
Parameters
ifacename of the interface to be matched.
client_classesOptional parameter specifying the classes that the client belongs to.
Returns
Pointer to the selected subnet or null if no subnet found.

Definition at line 416 of file cfg_subnets4.cc.

References isc::dhcp::DHCPSRV_CFGMGR_SUBNET4_IFACE, isc::dhcp::DHCPSRV_DBG_TRACE, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_SUBNET4_SELECT_BY_INTERFACE_NO_MATCH, LOG_DEBUG, and isc::dhcp::Network::NONE.

◆ selectSubnet() [3/3]

ConstSubnet4Ptr isc::dhcp::CfgSubnets4::selectSubnet ( const SubnetSelector & selector) const

Returns a pointer to the selected subnet.

This method tries to retrieve the subnet for the client using various parameters extracted from the client's message using the following logic.

First when link select suboption of relay agent information option or subnet select option in this order exists the address is used

If the giaddr value is set in the selector it means that the client's message was relayed. The subnet configuration allows for setting the relay address for each subnet to indicate that the subnet must be assigned when the packet was transmitted over the particular relay. This method first tries to match the giaddr with the relay addresses specified for all subnets. If the relay address for the subnet is equal to the address of the relay through which the message was transmitted, the particular subnet is returned.

If the giaddr is not matched with any of the relay addresses in any subnet or the message was not relayed, the method will need to try to match one of the addresses in the client's message with the prefixes of the existing subnets. Depending whether it is a relayed message, message from the renewing client or a new allocation, the server will pick one of the following addresses for this matching:

  • giaddr - for relayed message
  • ciaddr - for renewing or rebinding client
  • source address - for the renewing client which didn't provide ciaddr
  • address on the local server's interface if this is a new allocation requested by the directly connected client

If the address matches with a subnet, the subnet is returned.

Todo
This method requires performance improvement! It currently iterates over all existing subnets (possibly a couple of times) to find the one which fulfills the search criteria. The subnet storage is implemented as a simple STL vector which precludes fast searches using specific keys. Hence, full scan is required. To improve the search performance a different container type is required, e.g. multi-index container, or something of a similar functionality.
Parameters
selectorConst reference to the selector structure which holds various information extracted from the client's packet which are used to find appropriate subnet.
Returns
Pointer to the selected subnet or null if no subnet found.
Exceptions
isc::BadValueif the values in the subnet selector are invalid or they are insufficient to select a subnet.

Definition at line 304 of file cfg_subnets4.cc.

References isc::dhcp::DHCPSRV_CFGMGR_SUBNET4_RELAY, isc::dhcp::DHCPSRV_DBG_TRACE, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_SUBNET4_SELECT_BY_RELAY_ADDRESS_NO_MATCH, isc::dhcp::DHCPSRV_SUBNET4_SELECT_NO_RAI_OPTIONS, isc::dhcp::DHCPSRV_SUBNET4_SELECT_NO_RELAY_ADDRESS, isc::dhcp::DHCPSRV_SUBNET4_SELECT_NO_USABLE_ADDRESS, isc::dhcp::IfaceMgr::instance(), isc::asiolink::IOAddress::IPV4_ZERO_ADDRESS(), isc_throw, LOG_DEBUG, and selectSubnet().

Referenced by selectSubnet().

+ Here is the call graph for this function:

◆ selectSubnet4o6()

ConstSubnet4Ptr isc::dhcp::CfgSubnets4::selectSubnet4o6 ( const SubnetSelector & selector) const

Attempts to do subnet selection based on DHCP4o6 information.

The algorithm implemented is as follows:

  • First: try to match IPv6 subnet (4o6-subnet parameter) with the remote IPv6 address of the incoming packet
  • Second: try to match interface-id (4o6-interface-id parameter) with the interface-id option in the incoming 4o6 packet
  • Third: try to match interface-name (4o6-interface parameter) with the name of the interface the incoming 4o6 packet was received over.

    Todo
    : Add additional selection criteria. See https://gitlab.isc.org/isc-projects/kea/wikis/designs/dhcpv4o6-design for details.
Parameters
selectorConst reference to the selector structure which holds various information extracted from the client's packet which are used to find appropriate subnet.
Returns
Pointer to the selected subnet or null if no subnet found.

Definition at line 262 of file cfg_subnets4.cc.

References isc::dhcp::DHCPSRV_DBG_TRACE, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_SUBNET4O6_SELECT_FAILED, isc::asiolink::firstAddrInPrefix(), isc::dhcp::Cfg4o6::getSubnet4o6(), isc::asiolink::lastAddrInPrefix(), and LOG_DEBUG.

+ Here is the call graph for this function:

◆ toElement()

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

Unparse a configuration object.

Returns
a pointer to unparsed configuration

Implements isc::data::CfgToElement.

Definition at line 626 of file cfg_subnets4.cc.

References isc::data::Element::createList().

+ Here is the call graph for this function:

◆ updateStatistics()

void isc::dhcp::CfgSubnets4::updateStatistics ( )

Updates statistics.

This method updates statistics that are affected by the newly committed configuration. In particular, it updates the number of available addresses in each subnet. Other statistics may be added in the future. In general, these are statistics that are dependent only on configuration, so they are not expected to change until the next reconfiguration event.

Definition at line 560 of file cfg_subnets4.cc.

References isc::dhcp::LeaseMgrFactory::instance(), and isc::dhcp::Lease::TYPE_V4.

+ Here is the call graph for this function:

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