Kea 2.5.8
isc::dhcp::CfgSubnets6 Class Reference

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

#include <cfg_subnets6.h>

+ Inheritance diagram for isc::dhcp::CfgSubnets6:

Public Member Functions

void add (const Subnet6Ptr &subnet)
 Adds new subnet to the configuration.
 
void clear ()
 Clears all subnets from the configuration.
 
void del (const ConstSubnet6Ptr &subnet)
 Removes subnet from the configuration.
 
void del (const SubnetID &subnet_id)
 Removes subnet from the configuration.
 
const Subnet6CollectiongetAll () const
 Returns pointer to the collection of all IPv6 subnets.
 
ConstSubnet6Ptr getByPrefix (const std::string &subnet_prefix) const
 Returns const pointer to a subnet which matches the specified prefix in the canonical form.
 
ConstSubnet6Ptr 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.
 
Subnet6Ptr getSubnet (const SubnetID id) const
 Returns subnet with specified subnet-id value.
 
void initAllocatorsAfterConfigure ()
 Calls initAllocatorsAfterConfigure for each subnet.
 
void merge (CfgOptionDefPtr cfg_def, CfgSharedNetworks6Ptr networks, CfgSubnets6 &other)
 Merges specified subnet configuration into this configuration.
 
void removeStatistics ()
 Removes statistics.
 
Subnet6Ptr replace (const Subnet6Ptr &subnet)
 Replaces subnet in the configuration.
 
Subnet6Ptr selectSubnet (const asiolink::IOAddress &address, const ClientClasses &client_classes=ClientClasses(), const bool is_relay_address=false) const
 Selects the subnet using a specified address.
 
Subnet6Ptr selectSubnet (const SubnetSelector &selector) const
 Selects a subnet using parameters specified in the selector.
 
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.
 
virtual isc::data::ElementPtr toElement () const =0
 Unparse a configuration object.
 

Static Public Member Functions

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

Detailed Description

Holds subnets configured for the DHCPv6 server.

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

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

Definition at line 34 of file cfg_subnets6.h.

Member Function Documentation

◆ add()

void isc::dhcp::CfgSubnets6::add ( const Subnet6Ptr 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 29 of file cfg_subnets6.cc.

References isc::dhcp::DHCPSRV_CFGMGR_ADD_SUBNET6, 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::CfgSubnets6::clear ( )

Clears all subnets from the configuration.

Definition at line 562 of file cfg_subnets6.cc.

◆ del() [1/2]

void isc::dhcp::CfgSubnets6::del ( const ConstSubnet6Ptr 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 68 of file cfg_subnets6.cc.

References del().

Referenced by del().

+ Here is the call graph for this function:

◆ del() [2/2]

void isc::dhcp::CfgSubnets6::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 73 of file cfg_subnets6.cc.

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

◆ getAll()

const Subnet6Collection * isc::dhcp::CfgSubnets6::getAll ( ) const
inline

Returns pointer to the collection of all IPv6 subnets.

This is used in a hook (subnet6_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 Subnet6 collection

Definition at line 120 of file cfg_subnets6.h.

Referenced by merge().

◆ getByPrefix()

ConstSubnet6Ptr isc::dhcp::CfgSubnets6::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. 2001:db8:1::/64
Returns
Pointer to the Subnet6 object or null pointer if such subnet doesn't exist.

Definition at line 189 of file cfg_subnets6.cc.

Referenced by add().

◆ getBySubnetId()

ConstSubnet6Ptr isc::dhcp::CfgSubnets6::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 Subnet6 object or null pointer if such subnet doesn't exist.

Definition at line 139 of file cfg_subnets6.h.

References getSubnet().

Referenced by add().

+ Here is the call graph for this function:

◆ getLinks()

SubnetIDSet isc::dhcp::CfgSubnets6::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 378 of file cfg_subnets6.cc.

◆ getSubnet()

Subnet6Ptr isc::dhcp::CfgSubnets6::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 371 of file cfg_subnets6.cc.

Referenced by getBySubnetId().

◆ initAllocatorsAfterConfigure()

void isc::dhcp::CfgSubnets6::initAllocatorsAfterConfigure ( )

Calls initAllocatorsAfterConfigure for each subnet.

Definition at line 555 of file cfg_subnets6.cc.

◆ initSelector()

SubnetSelector isc::dhcp::CfgSubnets6::initSelector ( const Pkt6Ptr query)
static

◆ merge()

void isc::dhcp::CfgSubnets6::merge ( CfgOptionDefPtr  cfg_def,
CfgSharedNetworks6Ptr  networks,
CfgSubnets6 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 90 of file cfg_subnets6.cc.

References getAll(), isc_throw, isc::dhcp::Lease::TYPE_NA, and isc::dhcp::Lease::TYPE_PD.

+ Here is the call graph for this function:

◆ removeStatistics()

void isc::dhcp::CfgSubnets6::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 390 of file cfg_subnets6.cc.

References isc::stats::StatsMgr::del(), isc::dhcp::Lease::TYPE_NA, and isc::dhcp::Lease::TYPE_PD.

+ Here is the call graph for this function:

◆ replace()

Subnet6Ptr isc::dhcp::CfgSubnets6::replace ( const Subnet6Ptr 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 47 of file cfg_subnets6.cc.

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

◆ selectSubnet() [1/2]

Subnet6Ptr isc::dhcp::CfgSubnets6::selectSubnet ( const asiolink::IOAddress address,
const ClientClasses client_classes = ClientClasses(),
const bool  is_relay_address = false 
) const

Selects the subnet using a specified address.

This method searches for the subnet using the specified address. If the specified address is a link address on the relay agent (which is indicated by the 3rd argument) the method will first try to match the specified address with the relay addresses explicitly specified for existing subnets. If no match is found, the method will check if the address is in range with any of the subnets.

If the address is not a relay agent link address (is_relay_address is set to false), the method will simply check if the address is in range with any of the subnets.

Note
This method is mainly to be used in unit tests, which often require sanity-checking if the subnet exists for the particular address. For other purposes the selectSubnet(SubnetSelector) should rather be used instead.
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
addressAddress for which the subnet is searched.
client_classesOptional parameter specifying the classes that the client belongs to.
is_relay_addressSpecifies if the provided address is an address of the relay agent (true) or not (false).
Returns
Pointer to the selected subnet or NULL if no subnet found.

Definition at line 260 of file cfg_subnets6.cc.

References isc::dhcp::DHCPSRV_CFGMGR_SUBNET6, isc::dhcp::DHCPSRV_CFGMGR_SUBNET6_RELAY, isc::dhcp::DHCPSRV_DBG_TRACE, isc::dhcp::dhcpsrv_logger, isc::dhcp::DHCPSRV_SUBNET6_SELECT_BY_ADDRESS_NO_MATCH, LOG_DEBUG, and isc::asiolink::IOAddress::toText().

+ Here is the call graph for this function:

◆ selectSubnet() [2/2]

Subnet6Ptr isc::dhcp::CfgSubnets6::selectSubnet ( const SubnetSelector selector) const

Selects a subnet using parameters specified in the selector.

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

If the relay agent link address is set to zero it is assumed that the subnet is selected for the directly connected client. In this case it is checked if there is any subnet associated with the interface over which the message has been received. If there is no subnet explicitly associated with this interface the client's address will be used to check if the address is in range with any of the subnets.

If the message was relayed it is possible that the relay agent has appended an Interface ID option. If this option is present, the method will check if it matches with any explicitly specified interface id for any subnet. If it does, the subnet is returned. Otherwise, the relay agents link address is used to select the subnet. In this case, the method will first check if this link address is explicitly associated with any subnet. If not, it is checked if the link address is in range with any of the subnets.

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.

Definition at line 222 of file cfg_subnets6.cc.

References isc::dhcp::SubnetSelector::client_classes_, isc::dhcp::SubnetSelector::first_relay_linkaddr_, isc::dhcp::SubnetSelector::iface_name_, isc::dhcp::SubnetSelector::interface_id_, isc::dhcp::SubnetSelector::remote_address_, and selectSubnet().

Referenced by selectSubnet().

+ Here is the call graph for this function:

◆ toElement()

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

Unparse a configuration object.

Returns
a pointer to unparsed configuration

Implements isc::data::CfgToElement.

Definition at line 567 of file cfg_subnets6.cc.

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

+ Here is the call graph for this function:

◆ updateStatistics()

void isc::dhcp::CfgSubnets6::updateStatistics ( )

Updates statistics.

This method updates statistics that are affected by the newly committed configuration. In particular, it updates the number of available addresses and prefixes 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 471 of file cfg_subnets6.cc.

References isc::stats::StatsMgr::addValue(), isc::stats::StatsMgr::getObservation(), isc::dhcp::LeaseMgrFactory::instance(), isc::dhcp::LeaseMgr::recountLeaseStats6(), isc::stats::StatsMgr::setValue(), isc::dhcp::Lease::TYPE_NA, and isc::dhcp::Lease::TYPE_PD.

+ Here is the call graph for this function:

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