![]() |
Kea
1.5.0
|
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. More... | |
| void | del (const ConstSubnet4Ptr &subnet) |
| Removes subnet from the configuration. More... | |
| const Subnet4Collection * | getAll () const |
| Returns pointer to the collection of all IPv4 subnets. More... | |
| ConstSubnet4Ptr | getByPrefix (const std::string &subnet_prefix) const |
| Returns const pointer to a subnet which matches the specified prefix in the canonical form. More... | |
| ConstSubnet4Ptr | getBySubnetId (const SubnetID &subnet_id) const |
| Returns const pointer to a subnet identified by the specified subnet identifier. More... | |
| Subnet4Ptr | getSubnet (const SubnetID id) const |
| Returns subnet with specified subnet-id value. More... | |
| bool | hasSubnetWithServerId (const asiolink::IOAddress &server_id) const |
| Checks if specified server identifier has been specified for any subnet. More... | |
| void | removeStatistics () |
| Removes statistics. More... | |
| Subnet4Ptr | selectSubnet (const SubnetSelector &selector) const |
| Returns a pointer to the selected subnet. More... | |
| Subnet4Ptr | selectSubnet (const asiolink::IOAddress &address, const ClientClasses &client_classes=ClientClasses()) const |
| Returns a pointer to a subnet if provided address is in its range. More... | |
| Subnet4Ptr | selectSubnet (const std::string &iface, const ClientClasses &client_classes) const |
| Returns a pointer to a subnet if provided interface name matches. More... | |
| Subnet4Ptr | selectSubnet4o6 (const SubnetSelector &selector) const |
| Attempts to do subnet selection based on DHCP4o6 information. More... | |
| virtual isc::data::ElementPtr | toElement () const |
| Unparse a configuration object. More... | |
| void | updateStatistics () |
| Updates statistics. More... | |
Public Member Functions inherited from isc::data::CfgToElement | |
| virtual | ~CfgToElement () |
| Destructor. More... | |
Static Public Member Functions | |
| static SubnetSelector | initSelector (const Pkt4Ptr &query) |
| Build selector from a client's message. More... | |
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 32 of file cfg_subnets4.h.
| void isc::dhcp::CfgSubnets4::add | ( | const Subnet4Ptr & | subnet | ) |
Adds new subnet to the configuration.
| subnet | Pointer to the subnet being added. |
| isc::DuplicateSubnetID | If the subnet id for the new subnet duplicates id of an existing subnet. |
Definition at line 27 of file cfg_subnets4.cc.
References isc::dhcp::DHCPSRV_DBG_TRACE, isc::dhcp::dhcpsrv_logger, isc_throw, and LOG_DEBUG.
| void isc::dhcp::CfgSubnets4::del | ( | const ConstSubnet4Ptr & | subnet | ) |
Removes subnet from the configuration.
| subnet | Pointer to the subnet to be removed. |
| isc::BadValue | if such subnet doesn't exist. |
Definition at line 45 of file cfg_subnets4.cc.
References isc::dhcp::DHCPSRV_DBG_TRACE, isc::dhcp::dhcpsrv_logger, isc_throw, and LOG_DEBUG.
|
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).
Definition at line 57 of file cfg_subnets4.h.
| 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.
| subnet_prefix | Subnet prefix, e.g. 10.2.3.0/24 |
Subnet4 object or null pointer if such subnet doesn't exist. Definition at line 66 of file cfg_subnets4.cc.
| ConstSubnet4Ptr isc::dhcp::CfgSubnets4::getBySubnetId | ( | const SubnetID & | subnet_id | ) | const |
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.
| subnet_id | Subnet identifier. |
Subnet4 object or null pointer if such subnet doesn't exist. Definition at line 59 of file cfg_subnets4.cc.
| Subnet4Ptr isc::dhcp::CfgSubnets4::getSubnet | ( | const SubnetID | id | ) | const |
Returns subnet with specified subnet-id value.
Warning: this method uses full scan. Its use is not recommended for packet processing.
Definition at line 311 of file cfg_subnets4.cc.
| bool isc::dhcp::CfgSubnets4::hasSubnetWithServerId | ( | const asiolink::IOAddress & | server_id | ) | const |
Checks if specified server identifier has been specified for any subnet.
| server_id | Server identifier. |
Definition at line 73 of file cfg_subnets4.cc.
|
static |
Build selector from a client's message.
| query | client's message. |
Definition at line 80 of file cfg_subnets4.cc.
References isc::dhcp::SubnetSelector::ciaddr_, isc::dhcp::SubnetSelector::client_classes_, isc::dhcp::DHO_DHCP_AGENT_OPTIONS, isc::dhcp::SubnetSelector::giaddr_, isc::dhcp::SubnetSelector::iface_name_, isc::dhcp::SubnetSelector::local_address_, and isc::dhcp::SubnetSelector::remote_address_.
Referenced by isc::dhcp::Dhcpv4Srv::selectSubnet().
| 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 348 of file cfg_subnets4.cc.
References isc::stats::StatsMgr::del().
Here is the call graph for this function:| Subnet4Ptr 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:
If the address matches with a subnet, the subnet is returned.
| selector | Const reference to the selector structure which holds various information extracted from the client's packet which are used to find appropriate subnet. |
| isc::BadValue | if the values in the subnet selector are invalid or they are insufficient to select a subnet. |
Definition at line 170 of file cfg_subnets4.cc.
References isc::dhcp::SubnetSelector::ciaddr_, isc::dhcp::SubnetSelector::client_classes_, isc::dhcp::SubnetSelector::giaddr_, isc::dhcp::SubnetSelector::iface_name_, isc::asiolink::IOAddress::IPV4_ZERO_ADDRESS(), isc_throw, isc::asiolink::IOAddress::isV4Bcast(), isc::asiolink::IOAddress::isV4Zero(), isc::dhcp::SubnetSelector::local_address_, isc::dhcp::SubnetSelector::option_select_, and isc::dhcp::SubnetSelector::remote_address_.
Here is the call graph for this function:| Subnet4Ptr 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).
| address | Address for which the subnet is searched. |
| client_classes | Optional parameter specifying the classes that the client belongs to. |
Definition at line 324 of file cfg_subnets4.cc.
References isc::dhcp::DHCPSRV_DBG_TRACE, isc::dhcp::dhcpsrv_logger, LOG_DEBUG, and isc::asiolink::IOAddress::toText().
Here is the call graph for this function:| Subnet4Ptr 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).
| iface | name of the interface to be matched. |
| client_classes | Optional parameter specifying the classes that the client belongs to. |
Definition at line 268 of file cfg_subnets4.cc.
References isc::dhcp::DHCPSRV_DBG_TRACE, isc::dhcp::dhcpsrv_logger, and LOG_DEBUG.
| Subnet4Ptr isc::dhcp::CfgSubnets4::selectSubnet4o6 | ( | const SubnetSelector & | selector | ) | const |
Attempts to do subnet selection based on DHCP4o6 information.
The algorithm implemented is as follows:
Third: try to match interface-name (4o6-interface parameter) with the name of the interface the incoming 4o6 packet was received over.
| selector | Const reference to the selector structure which holds various information extracted from the client's packet which are used to find appropriate subnet. |
Definition at line 128 of file cfg_subnets4.cc.
References isc::dhcp::Cfg4o6::enabled(), isc::dhcp::firstAddrInPrefix(), isc::dhcp::Cfg4o6::getIface4o6(), isc::dhcp::Cfg4o6::getInterfaceId(), isc::dhcp::Cfg4o6::getSubnet4o6(), isc::dhcp::SubnetSelector::iface_name_, isc::dhcp::SubnetSelector::interface_id_, isc::dhcp::lastAddrInPrefix(), and isc::dhcp::SubnetSelector::remote_address_.
Here is the call graph for this function:
|
virtual |
Unparse a configuration object.
Implements isc::data::CfgToElement.
Definition at line 396 of file cfg_subnets4.cc.
| 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 374 of file cfg_subnets4.cc.
References isc::stats::StatsMgr::setValue().
Here is the call graph for this function: