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_)) {
215 if (!relay.linkaddr_.isV6Zero() &&
216 !relay.linkaddr_.isV6LinkLocal()) {
271 const bool is_relay_address)
const {
274 if (is_relay_address) {
275 for (
auto const& subnet : subnets_) {
279 if (subnet->hasRelays()) {
280 if (!subnet->hasRelayAddress(address)) {
286 subnet->getSharedNetwork(network);
287 if (!network || !network->hasRelayAddress(address)) {
292 if (subnet->clientSupported(client_classes)) {
297 .arg(subnet->toText()).arg(address.
toText());
305 for (
auto const& subnet : subnets_) {
306 if (subnet->inRange(address) && subnet->clientSupported(client_classes)) {
308 .arg(subnet->toText()).arg(address.
toText());
325 if (!iface_name.empty()) {
326 for (
auto const& subnet : subnets_) {
331 if ((subnet->getIface() == iface_name) &&
332 subnet->clientSupported(client_classes)) {
335 .arg(subnet->toText()).arg(iface_name);
355 for (
auto const& subnet : subnets_) {
359 if (subnet->getInterfaceId() &&
360 subnet->getInterfaceId()->equals(interface_id) &&
361 subnet->clientSupported(client_classes)) {
365 .arg(subnet->toText());
372 .arg(interface_id->toText());
382 auto subnet_it = index.find(subnet_id);
383 return ((subnet_it != index.cend()) ? (*subnet_it) :
Subnet6Ptr());
389 for (
auto const& subnet : subnets_) {
390 if (!subnet->inRange(link_addr)) {
393 links.insert(subnet->getID());
404 for (
auto const& subnet6 : subnets_) {
405 SubnetID subnet_id = subnet6->getID();
413 "cumulative-assigned-nas"));
422 "cumulative-assigned-pds"));
425 "declined-addresses"));
428 "reclaimed-declined-addresses"));
431 "reclaimed-leases"));
434 "cumulative-registered-nas"));
450 "cumulative-assigned-nas")));
454 "declined-addresses")));
458 "reclaimed-declined-addresses")));
462 "reclaimed-leases")));
476 "cumulative-assigned-pds")));
480 "reclaimed-leases")));
491 for (
auto const& subnet6 : subnets_) {
492 SubnetID subnet_id = subnet6->getID();
503 "cumulative-assigned-nas"));
505 stats_mgr.
setValue(name_nas,
static_cast<int64_t
>(0));
509 "cumulative-assigned-pds"));
511 stats_mgr.
setValue(name_pds,
static_cast<int64_t
>(0));
515 "v6-ia-na-lease-reuses"));
517 stats_mgr.
setValue(name_ia_na_reuses, int64_t(0));
521 "v6-ia-pd-lease-reuses"));
523 stats_mgr.
setValue(name_ia_pd_reuses, int64_t(0));
527 "cumulative-registered-nas"));
530 stats_mgr.
setValue(name_registered,
static_cast<int64_t
>(0));
538 stats_mgr.
setValue(name_total_nas, pool->getCapacity());
540 stats_mgr.
addValue(name_total_nas, pool->getCapacity());
545 "cumulative-assigned-nas")));
547 stats_mgr.
setValue(name_ca_nas,
static_cast<int64_t
>(0));
556 stats_mgr.
setValue(name_total_pds, pool->getCapacity());
558 stats_mgr.
addValue(name_total_pds, pool->getCapacity());
563 "cumulative-assigned-pds")));
565 stats_mgr.
setValue(name_ca_pds,
static_cast<int64_t
>(0));
571 if (subnets_.begin() != subnets_.end()) {
579 for (
auto const& subnet : subnets_) {
580 subnet->initAllocatorsAfterConfigure();
593 for (
auto const& subnet : subnets_) {
594 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.