28 if (getBySubnetId(subnet->getID())) {
30 << subnet->getID() <<
"' is already in use");
32 }
else if (getByPrefix(subnet->toText())) {
36 << subnet->toText() <<
"' already exists");
40 .arg(subnet->toText());
41 static_cast<void>(subnets_.insert(subnet));
47 const SubnetID& subnet_id = subnet->getID();
48 auto& index = subnets_.template get<SubnetSubnetIdIndexTag>();
49 auto subnet_it = index.find(subnet_id);
50 if (subnet_it == index.end()) {
54 bool ret = index.replace(subnet_it, subnet);
57 .arg(subnet_id).arg(ret);
73 auto subnet_it = index.find(subnet_id);
74 if (subnet_it == index.end()) {
81 index.erase(subnet_it);
84 .arg(subnet->toText());
96 auto other_subnets = other.
getAll();
97 for (
auto other_subnet = other_subnets->begin();
98 other_subnet != other_subnets->end();
102 auto subnet_id_it = index_id.find((*other_subnet)->getID());
103 if (subnet_id_it != index_id.end()) {
106 auto existing_subnet = *subnet_id_it;
110 if (existing_subnet == *other_subnet) {
122 existing_subnet->getSharedNetwork(network);
124 network->del(existing_subnet->getID());
128 index_id.erase(subnet_id_it);
132 auto subnet_prefix_it = index_prefix.find((*other_subnet)->toText());
133 if (subnet_prefix_it != index_prefix.end()) {
136 auto existing_subnet = *subnet_prefix_it;
146 existing_subnet->getSharedNetwork(network);
148 network->del(existing_subnet->getID());
152 index_prefix.erase(subnet_prefix_it);
156 (*other_subnet)->getCfgOption()->createOptions(cfg_def);
157 for (
auto pool : (*other_subnet)->getPoolsWritable(Lease::TYPE_V4)) {
158 pool->getCfgOption()->createOptions(cfg_def);
162 static_cast<void>(subnets_.insert(*other_subnet));
166 std::string network_name = (*other_subnet)->getSharedNetworkName();
167 if (!network_name.empty()) {
170 network->add(*other_subnet);
175 << (*other_subnet)->getID()
176 <<
" to shared network: " << network_name
177 <<
", network does not exist");
184 CfgSubnets4::getBySubnetId(
const SubnetID& subnet_id)
const {
186 auto subnet_it = index.find(subnet_id);
187 return ((subnet_it != index.cend()) ? (*subnet_it) :
ConstSubnet4Ptr());
191 CfgSubnets4::getByPrefix(
const std::string& subnet_text)
const {
193 auto subnet_it = index.find(subnet_text);
194 return ((subnet_it != index.cend()) ? (*subnet_it) :
ConstSubnet4Ptr());
200 auto subnet_it = index.find(server_id);
201 return (subnet_it != index.cend());
205 CfgSubnets4::initSelector(
const Pkt4Ptr& query) {
207 selector.
ciaddr_ = query->getCiaddr();
208 selector.
giaddr_ = query->getGiaddr();
228 rai_custom->
getOption(RAI_OPTION_LINK_SELECTION);
231 if (link_select_buf.size() ==
sizeof(uint32_t)) {
256 for (Subnet4Collection::const_iterator subnet = subnets_.begin();
257 subnet != subnets_.end(); ++subnet) {
258 Cfg4o6& cfg4o6 = (*subnet)->get4o6();
266 std::pair<asiolink::IOAddress, uint8_t> pref = cfg4o6.
getSubnet4o6();
267 if (!pref.first.isV6Zero()) {
310 for (Subnet4Collection::const_iterator subnet = subnets_.begin();
311 subnet != subnets_.end(); ++subnet) {
315 if ((*subnet)->hasRelays()) {
316 if (!(*subnet)->hasRelayAddress(selector.
giaddr_)) {
323 (*subnet)->getSharedNetwork(network);
324 if (!network || !(network->hasRelayAddress(selector.
giaddr_))) {
364 <<
" doesn't exist and therefore it is impossible"
365 " to find a suitable subnet for its IPv4 address");
379 iface->getAddress4(address);
394 CfgSubnets4::selectSubnet(
const std::string& iface,
396 for (Subnet4Collection::const_iterator subnet = subnets_.begin();
397 subnet != subnets_.end(); ++subnet) {
404 subnet_selected = (*subnet);
412 (*subnet)->getSharedNetwork(network);
415 subnet_selected = (*subnet);
419 if (subnet_selected) {
422 if (subnet_selected->clientSupported(client_classes)) {
425 .arg((*subnet)->toText())
427 return (subnet_selected);
441 for (
auto subnet = subnets_.begin(); subnet != subnets_.end(); ++subnet) {
442 if ((*subnet)->getID() == id) {
452 for (Subnet4Collection::const_iterator subnet = subnets_.begin();
453 subnet != subnets_.end(); ++subnet) {
456 if (!(*subnet)->inRange(address)) {
461 if ((*subnet)->clientSupported(client_classes)) {
463 .arg((*subnet)->toText())
474 CfgSubnets4::removeStatistics() {
478 StatsMgr& stats_mgr = StatsMgr::instance();
479 for (Subnet4Collection::const_iterator subnet4 = subnets_.begin();
480 subnet4 != subnets_.end(); ++subnet4) {
481 SubnetID subnet_id = (*subnet4)->getID();
482 stats_mgr.
del(StatsMgr::generateName(
"subnet", subnet_id,
485 stats_mgr.
del(StatsMgr::generateName(
"subnet", subnet_id,
486 "assigned-addresses"));
488 stats_mgr.
del(StatsMgr::generateName(
"subnet", subnet_id,
489 "cumulative-assigned-addresses"));
491 stats_mgr.
del(StatsMgr::generateName(
"subnet", subnet_id,
492 "declined-addresses"));
494 stats_mgr.
del(StatsMgr::generateName(
"subnet", subnet_id,
495 "reclaimed-declined-addresses"));
497 stats_mgr.
del(StatsMgr::generateName(
"subnet", subnet_id,
498 "reclaimed-leases"));
503 CfgSubnets4::updateStatistics() {
506 StatsMgr& stats_mgr = StatsMgr::instance();
507 for (Subnet4Collection::const_iterator subnet4 = subnets_.begin();
508 subnet4 != subnets_.end(); ++subnet4) {
509 SubnetID subnet_id = (*subnet4)->getID();
512 generateName(
"subnet", subnet_id,
"total-addresses"),
514 ((*subnet4)->getPoolCapacity(
Lease::
516 const std::string& name =
517 StatsMgr::generateName(
"subnet", subnet_id,
"cumulative-assigned-addresses");
519 stats_mgr.
setValue(name, static_cast<int64_t>(0));
524 if (subnets_.begin() != subnets_.end()) {
525 LeaseMgrFactory::instance().recountLeaseStats4();
530 CfgSubnets4::toElement()
const {
533 for (Subnet4Collection::const_iterator subnet = subnets_.cbegin();
534 subnet != subnets_.cend(); ++subnet) {
535 result->add((*subnet)->toElement());
Exception thrown upon attempt to add subnet with an ID that belongs to the subnet that already exists...
bool isV4Bcast() const
Convenience function to check if it is an IPv4 broadcast address.
asiolink::IOAddress ciaddr_
ciaddr from the client's message.
asiolink::IOAddress remote_address_
Source address of the message.
const Subnet4Collection * getAll() const
Returns pointer to the collection of all IPv4 subnets.
boost::shared_ptr< OptionCustom > OptionCustomPtr
A pointer to the OptionCustom object.
Tag for the index for searching by subnet identifier.
const isc::log::MessageID DHCPSRV_CFGMGR_ADD_SUBNET4
OptionPtr getOption(uint16_t type) const
Returns shared_ptr to suboption of specific type.
boost::shared_ptr< Iface > IfacePtr
Type definition for the pointer to an Iface object.
asiolink::IOAddress option_select_
RAI link select or subnet select option.
OptionPtr interface_id_
Interface id option.
boost::shared_ptr< Option > OptionPtr
boost::shared_ptr< Subnet4 > Subnet4Ptr
A pointer to a Subnet4 object.
const isc::log::MessageID DHCPSRV_CFGMGR_UPDATE_SUBNET4
boost::shared_ptr< Element > ElementPtr
asiolink::IOAddress giaddr_
giaddr from the client's message.
Tag for the index for searching by subnet prefix.
bool enabled() const
Returns whether the DHCP4o6 is enabled or not.
boost::shared_ptr< CfgOptionDef > CfgOptionDefPtr
Non-const pointer.
ObservationPtr getObservation(const std::string &name) const
Returns an observation.
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
Statistics Manager class.
ClientClasses client_classes_
Classes that the client belongs to.
IOAddress firstAddrInPrefix(const IOAddress &prefix, uint8_t len)
This code is based on similar code from the Dibbler project.
util::Optional< std::pair< asiolink::IOAddress, uint8_t > > getSubnet4o6() const
Returns prefix/len for the IPv6 subnet.
Subnet selector used to specify parameters used to select a subnet.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Tag for the index for searching by server identifier.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
boost::shared_ptr< CfgSharedNetworks4 > CfgSharedNetworks4Ptr
Pointer to the configuration of IPv4 shared networks.
static IOAddress fromBytes(short family, const uint8_t *data)
Creates an address from over wire data.
This structure contains information about DHCP4o6 (RFC7341)
bool del(const std::string &name)
Removes specified statistic.
static const IOAddress & IPV4_ZERO_ADDRESS()
Returns an address set to all zeros.
asiolink::IOAddress local_address_
Address on which the message was received.
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
const isc::log::MessageID DHCPSRV_CFGMGR_DEL_SUBNET4
bool isV4Zero() const
Convenience function to check if it is an IPv4 zero address.
Holds subnets configured for the DHCPv4 server.
boost::shared_ptr< SharedNetwork4 > SharedNetwork4Ptr
Pointer to SharedNetwork4 object.
bool empty() const
Checks if the encapsulated value is empty.
Defines the logger used by the top-level component of kea-dhcp-ddns.
boost::shared_ptr< const Subnet4 > ConstSubnet4Ptr
A const pointer to a Subnet4 object.
const isc::log::MessageID DHCPSRV_CFGMGR_SUBNET4_IFACE
void merge(ElementPtr element, ConstElementPtr other)
Merges the data from other into element.
a common structure for IPv4 and IPv6 leases
OptionPtr getInterfaceId() const
Returns the interface-id.
A generic exception that is thrown if a function is called in a prohibited way.
IOAddress lastAddrInPrefix(const IOAddress &prefix, uint8_t len)
returns a last address in a given prefix
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
std::string toText() const
Convert the address to a string.
std::string iface_name_
Name of the interface on which the message was received.
const int DHCPSRV_DBG_TRACE
DHCP server library logging levels.
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
The IOAddress class represents an IP addresses (version agnostic)
Option with defined data fields represented as buffers that can be accessed using data field index...
Container for storing client class names.
util::Optional< std::string > getIface4o6() const
Returns the DHCP4o6 interface.
void setValue(const std::string &name, const int64_t value)
Records absolute integer observation.
uint32_t SubnetID
Unique identifier for a subnet (both v4 and v6)
const isc::log::MessageID DHCPSRV_CFGMGR_SUBNET4_ADDR