17#include <boost/range/adaptor/reversed.hpp>
33 << subnet->getID() <<
"' is already in use");
39 << subnet->toText() <<
"' already exists");
43 .arg(subnet->toText());
44 static_cast<void>(subnets_.insert(subnet));
50 const SubnetID& subnet_id = subnet->getID();
52 auto subnet_it = index.find(subnet_id);
53 if (subnet_it == index.end()) {
57 bool ret = index.replace(subnet_it, subnet);
60 .arg(subnet_id).arg(ret);
76 auto subnet_it = index.find(subnet_id);
77 if (subnet_it == index.end()) {
84 index.erase(subnet_it);
87 .arg(subnet->toText());
99 auto const& other_subnets = other.
getAll();
100 for (
auto const& other_subnet : *other_subnets) {
103 auto subnet_it = index_id.find(other_subnet->getID());
104 if (subnet_it != index_id.end()) {
107 auto existing_subnet = *subnet_it;
111 if (existing_subnet == other_subnet) {
119 existing_subnet->getSharedNetwork(network);
121 network->del(existing_subnet->getID());
125 index_id.erase(subnet_it);
129 auto subnet_prefix_it = index_prefix.find(other_subnet->toText());
130 if (subnet_prefix_it != index_prefix.end()) {
133 auto existing_subnet = *subnet_prefix_it;
143 existing_subnet->getSharedNetwork(network);
145 network->del(existing_subnet->getID());
149 index_prefix.erase(subnet_prefix_it);
153 other_subnet->getCfgOption()->createOptions(cfg_def);
157 other_subnet->getCfgOption()->encapsulate();
160 for (
auto const& pool : other_subnet->getPoolsWritable(
Lease::TYPE_NA)) {
161 pool->getCfgOption()->createOptions(cfg_def);
162 pool->getCfgOption()->encapsulate();
166 for (
auto const& pool : other_subnet->getPoolsWritable(
Lease::TYPE_PD)) {
167 pool->getCfgOption()->createOptions(cfg_def);
168 pool->getCfgOption()->encapsulate();
172 static_cast<void>(subnets_.insert(other_subnet));
176 std::string network_name = other_subnet->getSharedNetworkName();
177 if (!network_name.empty()) {
180 network->add(other_subnet);
185 << other_subnet->getID()
186 <<
" to shared network: " << network_name
187 <<
", network does not exist");
191 other_subnet->createAllocators();
198 auto subnet_it = index.find(subnet_text);
199 return ((subnet_it != index.cend()) ? (*subnet_it) :
ConstSubnet6Ptr());
212 if (!query->relay_info_.empty()) {
213 for (
auto const& relay : boost::adaptors::reverse(query->relay_info_)) {
214 if (!relay.linkaddr_.isV6Zero() &&
215 !relay.linkaddr_.isV6LinkLocal()) {
269 const bool is_relay_address)
const {
272 if (is_relay_address) {
273 for (
auto const& subnet : subnets_) {
277 if (subnet->hasRelays()) {
278 if (!subnet->hasRelayAddress(address)) {
284 subnet->getSharedNetwork(network);
285 if (!network || !network->hasRelayAddress(address)) {
290 if (subnet->clientSupported(client_classes)) {
295 .arg(subnet->toText()).arg(address.
toText());
303 for (
auto const& subnet : subnets_) {
304 if (subnet->inRange(address) && subnet->clientSupported(client_classes)) {
306 .arg(subnet->toText()).arg(address.
toText());
323 if (!iface_name.empty()) {
324 for (
auto const& subnet : subnets_) {
329 if ((subnet->getIface() == iface_name) &&
330 subnet->clientSupported(client_classes)) {
333 .arg(subnet->toText()).arg(iface_name);
353 for (
auto const& subnet : subnets_) {
357 if (subnet->getInterfaceId() &&
358 subnet->getInterfaceId()->equals(interface_id) &&
359 subnet->clientSupported(client_classes)) {
363 .arg(subnet->toText());
370 .arg(interface_id->toText());
380 auto subnet_it = index.find(subnet_id);
381 return ((subnet_it != index.cend()) ? (*subnet_it) :
Subnet6Ptr());
387 for (
auto const& subnet : subnets_) {
388 if (!subnet->inRange(link_addr)) {
391 links.insert(subnet->getID());
402 for (
auto const& subnet6 : subnets_) {
403 SubnetID subnet_id = subnet6->getID();
411 "cumulative-assigned-nas"));
420 "cumulative-assigned-pds"));
423 "declined-addresses"));
426 "reclaimed-declined-addresses"));
429 "reclaimed-leases"));
432 "cumulative-registered-nas"));
448 "cumulative-assigned-nas")));
452 "declined-addresses")));
456 "reclaimed-declined-addresses")));
460 "reclaimed-leases")));
474 "cumulative-assigned-pds")));
478 "reclaimed-leases")));
489 for (
auto const& subnet6 : subnets_) {
490 SubnetID subnet_id = subnet6->getID();
501 "cumulative-assigned-nas"));
503 stats_mgr.
setValue(name_nas,
static_cast<int64_t
>(0));
507 "cumulative-assigned-pds"));
509 stats_mgr.
setValue(name_pds,
static_cast<int64_t
>(0));
513 "v6-ia-na-lease-reuses"));
515 stats_mgr.
setValue(name_ia_na_reuses, int64_t(0));
519 "v6-ia-pd-lease-reuses"));
521 stats_mgr.
setValue(name_ia_pd_reuses, int64_t(0));
525 "cumulative-registered-nas"));
528 stats_mgr.
setValue(name_registered,
static_cast<int64_t
>(0));
536 stats_mgr.
setValue(name_total_nas, pool->getCapacity());
538 stats_mgr.
addValue(name_total_nas, pool->getCapacity());
543 "cumulative-assigned-nas")));
545 stats_mgr.
setValue(name_ca_nas,
static_cast<int64_t
>(0));
554 stats_mgr.
setValue(name_total_pds, pool->getCapacity());
556 stats_mgr.
addValue(name_total_pds, pool->getCapacity());
561 "cumulative-assigned-pds")));
563 stats_mgr.
setValue(name_ca_pds,
static_cast<int64_t
>(0));
569 if (subnets_.begin() != subnets_.end()) {
577 for (
auto const& subnet : subnets_) {
578 subnet->initAllocatorsAfterConfigure();
591 for (
auto const& subnet : subnets_) {
592 result->add(subnet->toElement());
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown if a function is called in a prohibited way.
The IOAddress class represents an IP addresses (version agnostic)
std::string toText() const
Convert the address to a string.
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
Holds subnets configured for the DHCPv6 server.
SubnetIDSet getLinks(const asiolink::IOAddress &link_addr) const
Convert a link address into a link set.
ConstSubnet6Ptr selectSubnet(const SubnetSelector &selector) const
Selects a subnet using parameters specified in the selector.
void updateStatistics()
Updates statistics.
Subnet6Ptr replace(const Subnet6Ptr &subnet)
Replaces subnet in the configuration.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
void merge(CfgOptionDefPtr cfg_def, CfgSharedNetworks6Ptr networks, CfgSubnets6 &other)
Merges specified subnet configuration into this configuration.
Subnet6Ptr getSubnet(const SubnetID id) const
Returns subnet with specified subnet-id value.
void removeStatistics()
Removes statistics.
const Subnet6Collection * getAll() const
Returns pointer to the collection of all IPv6 subnets.
void add(const Subnet6Ptr &subnet)
Adds new subnet to the configuration.
void clear()
Clears all subnets from the configuration.
static SubnetSelector initSelector(const Pkt6Ptr &query)
Build selector from a client's message.
void del(const ConstSubnet6Ptr &subnet)
Removes subnet from the configuration.
ConstSubnet6Ptr getByPrefix(const std::string &subnet_prefix) const
Returns const pointer to a subnet which matches the specified prefix in the canonical form.
void initAllocatorsAfterConfigure()
Calls initAllocatorsAfterConfigure for each subnet.
ConstSubnet6Ptr getBySubnetId(const SubnetID &subnet_id) const
Returns const pointer to a subnet identified by the specified subnet identifier.
Container for storing client class names.
Exception thrown upon attempt to add subnet with an ID that belongs to the subnet that already exists...
static TrackingLeaseMgr & instance()
Return current lease manager.
void recountLeaseStats6()
Recalculates per-subnet and global stats for IPv6 leases.
static void setInUse(bool in_use)
Sets the global in-use flag.
Statistics Manager class.
ObservationPtr getObservation(const std::string &name) const
Returns an observation.
static StatsMgr & instance()
Statistics Manager accessor method.
static std::string generateName(const std::string &context, Type index, const std::string &stat_name)
Generates statistic name in a given context.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
bool del(const std::string &name)
Removes specified statistic.
void setValue(const std::string &name, const int64_t value)
Records absolute integer observation.
void addValue(const std::string &name, const int64_t value)
Records incremental integer observation.
int get(CalloutHandle &handle)
The gss-tsig-get command.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
boost::shared_ptr< Element > ElementPtr
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
const isc::log::MessageID DHCPSRV_CFGMGR_SUBNET6_IFACE
const isc::log::MessageID DHCPSRV_CFGMGR_ADD_SUBNET6
std::set< dhcp::SubnetID > SubnetIDSet
Ordered list aka set of subnetIDs.
const isc::log::MessageID DHCPSRV_CFGMGR_SUBNET6_RELAY
boost::shared_ptr< const Subnet6 > ConstSubnet6Ptr
A const pointer to a Subnet6 object.
boost::shared_ptr< CfgOptionDef > CfgOptionDefPtr
Non-const pointer.
const isc::log::MessageID DHCPSRV_CFGMGR_UPDATE_SUBNET6
boost::shared_ptr< Subnet6 > Subnet6Ptr
A pointer to a Subnet6 object.
boost::shared_ptr< SharedNetwork6 > SharedNetwork6Ptr
Pointer to SharedNetwork6 object.
boost::shared_ptr< CfgSharedNetworks6 > CfgSharedNetworks6Ptr
Pointer to the configuration of IPv6 shared networks.
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
const isc::log::MessageID DHCPSRV_CFGMGR_SUBNET6
const isc::log::MessageID DHCPSRV_CFGMGR_SUBNET6_IFACE_ID
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
const isc::log::MessageID DHCPSRV_CFGMGR_DEL_SUBNET6
const isc::log::MessageID DHCPSRV_SUBNET6_SELECT_BY_INTERFACE_ID_NO_MATCH
const isc::log::MessageID DHCPSRV_SUBNET6_SELECT_BY_ADDRESS_NO_MATCH
const isc::log::MessageID DHCPSRV_SUBNET6_SELECT_BY_INTERFACE_NO_MATCH
const int DHCPSRV_DBG_TRACE
DHCP server library logging levels.
boost::shared_ptr< Option > OptionPtr
Defines the logger used by the top-level component of kea-lfc.
@ TYPE_PD
the lease contains IPv6 prefix (for prefix delegation)
@ TYPE_NA
the lease contains non-temporary IPv6 address
Tag for the index for searching by subnet prefix.
Subnet selector used to specify parameters used to select a subnet.
std::string iface_name_
Name of the interface on which the message was received.
ClientClasses client_classes_
Classes that the client belongs to.
asiolink::IOAddress remote_address_
Source address of the message.
OptionPtr interface_id_
Interface id option.
asiolink::IOAddress first_relay_linkaddr_
First relay link address.
Tag for the index for searching by subnet identifier.