16 #include <boost/foreach.hpp>
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 const& other_subnets = other.
getAll();
97 for (
auto const& other_subnet : *other_subnets) {
100 auto subnet_it = index_id.find(other_subnet->getID());
101 if (subnet_it != index_id.end()) {
104 auto existing_subnet = *subnet_it;
108 if (existing_subnet == other_subnet) {
116 existing_subnet->getSharedNetwork(network);
118 network->del(existing_subnet->getID());
122 index_id.erase(subnet_it);
126 auto subnet_prefix_it = index_prefix.find(other_subnet->toText());
127 if (subnet_prefix_it != index_prefix.end()) {
130 auto existing_subnet = *subnet_prefix_it;
140 existing_subnet->getSharedNetwork(network);
142 network->del(existing_subnet->getID());
146 index_prefix.erase(subnet_prefix_it);
150 other_subnet->getCfgOption()->createOptions(cfg_def);
153 for (
auto const& pool : other_subnet->getPoolsWritable(Lease::TYPE_NA)) {
154 pool->getCfgOption()->createOptions(cfg_def);
158 for (
auto const& pool : other_subnet->getPoolsWritable(Lease::TYPE_PD)) {
159 pool->getCfgOption()->createOptions(cfg_def);
163 static_cast<void>(subnets_.insert(other_subnet));
167 std::string network_name = other_subnet->getSharedNetworkName();
168 if (!network_name.empty()) {
171 network->add(other_subnet);
176 << other_subnet->getID()
177 <<
" to shared network: " << network_name
178 <<
", network does not exist");
185 CfgSubnets6::getBySubnetId(
const SubnetID& subnet_id)
const {
187 auto subnet_it = index.find(subnet_id);
188 return ((subnet_it != index.cend()) ? (*subnet_it) :
ConstSubnet6Ptr());
192 CfgSubnets6::getByPrefix(
const std::string& subnet_text)
const {
194 auto subnet_it = index.find(subnet_text);
195 return ((subnet_it != index.cend()) ? (*subnet_it) :
ConstSubnet6Ptr());
199 CfgSubnets6::initSelector(
const Pkt6Ptr& query) {
208 if (!query->relay_info_.empty()) {
218 Pkt6::RELAY_GET_FIRST);
265 const bool is_relay_address)
const {
268 if (is_relay_address) {
269 for (
auto const& subnet : subnets_) {
273 if (subnet->hasRelays()) {
274 if (!subnet->hasRelayAddress(address)) {
280 subnet->getSharedNetwork(network);
281 if (!network || !network->hasRelayAddress(address)) {
286 if (subnet->clientSupported(client_classes)) {
291 .arg(subnet->toText()).arg(address.
toText());
299 for (
auto const& subnet : subnets_) {
300 if (subnet->inRange(address) && subnet->clientSupported(client_classes)) {
302 .arg(subnet->toText()).arg(address.
toText());
316 CfgSubnets6::selectSubnet(
const std::string& iface_name,
319 if (!iface_name.empty()) {
320 for (
auto const& subnet : subnets_) {
325 if ((subnet->getIface() == iface_name) &&
326 subnet->clientSupported(client_classes)) {
329 .arg(subnet->toText()).arg(iface_name);
344 CfgSubnets6::selectSubnet(
const OptionPtr& interface_id,
345 const ClientClasses& client_classes)
const {
349 for (
auto const& subnet : subnets_) {
353 if (subnet->getInterfaceId() &&
354 subnet->getInterfaceId()->equals(interface_id) &&
355 subnet->clientSupported(client_classes)) {
359 .arg(subnet->toText());
366 .arg(interface_id->toText());
377 for (
auto const& subnet : subnets_) {
378 if (subnet->getID() ==
id) {
386 CfgSubnets6::getLinks(
const IOAddress& link_addr, uint8_t& link_len)
const {
388 bool link_len_set =
false;
389 for (
auto const& subnet : subnets_) {
390 if (!subnet->inRange(link_addr)) {
393 uint8_t plen = subnet->get().second;
394 if (!link_len_set || (plen < link_len)) {
398 links.insert(subnet->getID());
404 CfgSubnets6::removeStatistics() {
407 StatsMgr& stats_mgr = StatsMgr::instance();
409 for (
auto const& subnet6 : subnets_) {
410 SubnetID subnet_id = subnet6->getID();
411 stats_mgr.
del(StatsMgr::generateName(
"subnet", subnet_id,
"total-nas"));
413 stats_mgr.
del(StatsMgr::generateName(
"subnet", subnet_id,
416 stats_mgr.
del(StatsMgr::generateName(
"subnet", subnet_id,
417 "cumulative-assigned-nas"));
419 stats_mgr.
del(StatsMgr::generateName(
"subnet", subnet_id,
"total-pds"));
421 stats_mgr.
del(StatsMgr::generateName(
"subnet", subnet_id,
424 stats_mgr.
del(StatsMgr::generateName(
"subnet", subnet_id,
425 "cumulative-assigned-pds"));
427 stats_mgr.
del(StatsMgr::generateName(
"subnet", subnet_id,
428 "declined-addresses"));
430 stats_mgr.
del(StatsMgr::generateName(
"subnet", subnet_id,
431 "reclaimed-declined-addresses"));
433 stats_mgr.
del(StatsMgr::generateName(
"subnet", subnet_id,
434 "reclaimed-leases"));
439 CfgSubnets6::updateStatistics() {
442 StatsMgr& stats_mgr = StatsMgr::instance();
444 for (
auto const& subnet6 : subnets_) {
445 SubnetID subnet_id = subnet6->getID();
447 stats_mgr.
setValue(StatsMgr::generateName(
"subnet", subnet_id,
450 (subnet6->getPoolCapacity(Lease::TYPE_NA)));
452 stats_mgr.
setValue(StatsMgr::generateName(
"subnet", subnet_id,
455 (subnet6->getPoolCapacity(Lease::TYPE_PD)));
457 const std::string& name_nas =
458 StatsMgr::generateName(
"subnet", subnet_id,
"cumulative-assigned-nas");
460 stats_mgr.
setValue(name_nas,
static_cast<int64_t
>(0));
463 const std::string& name_pds =
464 StatsMgr::generateName(
"subnet", subnet_id,
"cumulative-assigned-pds");
466 stats_mgr.
setValue(name_pds,
static_cast<int64_t
>(0));
471 if (subnets_.begin() != subnets_.end()) {
472 LeaseMgrFactory::instance().recountLeaseStats6();
477 CfgSubnets6::initAllocatorsAfterConfigure() {
478 for (
auto subnet : subnets_) {
479 subnet->initAllocatorsAfterConfigure();
484 CfgSubnets6::toElement()
const {
487 for (
auto const& subnet : subnets_) {
488 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.
bool isV6Zero() const
Convenience function to check if it is an IPv4 zero address.
bool isV6LinkLocal() const
checks whether and address is IPv6 and is link-local
Holds subnets configured for the DHCPv6 server.
const Subnet6Collection * getAll() const
Returns pointer to the collection of all IPv6 subnets.
Container for storing client class names.
Exception thrown upon attempt to add subnet with an ID that belongs to the subnet that already exists...
Statistics Manager class.
ObservationPtr getObservation(const std::string &name) const
Returns an observation.
#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.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
void merge(ElementPtr element, ConstElementPtr other)
Merges the data from other into element.
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.
structure that describes a single relay information
isc::asiolink::IOAddress linkaddr_
fixed field in relay-forw/relay-reply
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.