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 subnets_.push_back(subnet);
47 auto subnet_it = index.find(subnet->getID());
48 if (subnet_it == index.end()) {
52 index.erase(subnet_it);
55 .arg(subnet->toText());
59 CfgSubnets6::getBySubnetId(
const SubnetID& subnet_id)
const {
61 auto subnet_it = index.find(subnet_id);
62 return ((subnet_it != index.cend()) ? (*subnet_it) :
ConstSubnet6Ptr());
66 CfgSubnets6::getByPrefix(
const std::string& subnet_text)
const {
68 auto subnet_it = index.find(subnet_text);
69 return ((subnet_it != index.cend()) ? (*subnet_it) :
ConstSubnet6Ptr());
73 CfgSubnets6::initSelector(
const Pkt6Ptr& query) {
82 if (!query->relay_info_.empty()) {
92 Pkt6::RELAY_GET_FIRST);
140 const bool is_relay_address)
const {
144 if (is_relay_address) {
145 for (Subnet6Collection::const_iterator subnet = subnets_.begin();
146 subnet != subnets_.end(); ++subnet) {
150 if (is_relay_address &&
151 ((*subnet)->hasRelayAddress(address)) &&
152 (*subnet)->clientSupported(client_classes)) {
154 DHCPSRV_CFGMGR_SUBNET6_RELAY)
155 .arg((*subnet)->toText()).arg(address.
toText());
164 for (Subnet6Collection::const_iterator subnet = subnets_.begin();
165 subnet != subnets_.end(); ++subnet) {
166 if ((*subnet)->inRange(address) &&
167 (*subnet)->clientSupported(client_classes)) {
169 .arg((*subnet)->toText()).arg(address.
toText());
180 CfgSubnets6::selectSubnet(
const std::string& iface_name,
184 if (!iface_name.empty()) {
185 for (Subnet6Collection::const_iterator subnet = subnets_.begin();
186 subnet != subnets_.end(); ++subnet) {
191 if ((iface_name == (*subnet)->getIface()) &&
192 (*subnet)->clientSupported(client_classes)) {
195 DHCPSRV_CFGMGR_SUBNET6_IFACE)
196 .arg((*subnet)->toText()).arg(iface_name);
207 CfgSubnets6::selectSubnet(
const OptionPtr& interface_id,
208 const ClientClasses& client_classes)
const {
212 for (Subnet6Collection::const_iterator subnet = subnets_.begin();
213 subnet != subnets_.end(); ++subnet) {
217 if ((*subnet)->getInterfaceId() &&
218 (*subnet)->getInterfaceId()->equals(interface_id) &&
219 (*subnet)->clientSupported(client_classes)) {
222 DHCPSRV_CFGMGR_SUBNET6_IFACE_ID)
223 .arg((*subnet)->toText());
237 for (
auto subnet = subnets_.begin(); subnet != subnets_.end(); ++subnet) {
238 if ((*subnet)->getID() == id) {
246 CfgSubnets6::removeStatistics() {
249 StatsMgr& stats_mgr = StatsMgr::instance();
251 for (Subnet6Collection::const_iterator subnet6 = subnets_.begin();
252 subnet6 != subnets_.end(); ++subnet6) {
253 SubnetID subnet_id = (*subnet6)->getID();
254 stats_mgr.
del(StatsMgr::generateName(
"subnet", subnet_id,
"total-nas"));
256 stats_mgr.
del(StatsMgr::generateName(
"subnet", subnet_id,
259 stats_mgr.
del(StatsMgr::generateName(
"subnet", subnet_id,
"total-pds"));
261 stats_mgr.
del(StatsMgr::generateName(
"subnet", subnet_id,
264 stats_mgr.
del(StatsMgr::generateName(
"subnet", subnet_id,
265 "declined-addresses"));
267 stats_mgr.
del(StatsMgr::generateName(
"subnet", subnet_id,
268 "declined-reclaimed-addresses"));
270 stats_mgr.
del(StatsMgr::generateName(
"subnet", subnet_id,
271 "reclaimed-leases"));
276 CfgSubnets6::updateStatistics() {
279 StatsMgr& stats_mgr = StatsMgr::instance();
281 for (Subnet6Collection::const_iterator subnet6 = subnets_.begin();
282 subnet6 != subnets_.end(); ++subnet6) {
283 SubnetID subnet_id = (*subnet6)->getID();
285 stats_mgr.
setValue(StatsMgr::generateName(
"subnet", subnet_id,
288 ((*subnet6)->getPoolCapacity(Lease::TYPE_NA)));
290 stats_mgr.
setValue(StatsMgr::generateName(
"subnet", subnet_id,
293 ((*subnet6)->getPoolCapacity(Lease::TYPE_PD)));
297 if (subnets_.begin() != subnets_.end()) {
298 LeaseMgrFactory::instance().recountLeaseStats6();
303 CfgSubnets6::toElement()
const {
306 for (Subnet6Collection::const_iterator subnet = subnets_.cbegin();
307 subnet != subnets_.cend(); ++subnet) {
308 result->add((*subnet)->toElement());
Exception thrown upon attempt to add subnet with an ID that belongs to the subnet that already exists...
asiolink::IOAddress remote_address_
Source address of the message.
Tag for the index for searching by subnet identifier.
OptionPtr interface_id_
Interface id option.
boost::shared_ptr< Option > OptionPtr
boost::shared_ptr< Element > ElementPtr
Tag for the index for searching by subnet prefix.
bool isV6LinkLocal() const
checks whether and address is IPv6 and is link-local
Statistics Manager class.
ClientClasses client_classes_
Classes that the client belongs to.
asiolink::IOAddress first_relay_linkaddr_
First relay link address.
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.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
structure that describes a single relay information
bool isV6Zero() const
Convenience function to check if it is an IPv4 zero address.
bool del(const std::string &name)
Removes specified statistic.
boost::shared_ptr< const Subnet6 > ConstSubnet6Ptr
A const pointer to a Subnet6 object.
Defines the logger used by the top-level component of kea-dhcp-ddns.
std::string toText() const
Convert the address to a string.
#define LOG_DEBUG(LOGGER, LEVEL, MESSAGE)
Macro to conveniently test debug output and log it.
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::asiolink::IOAddress linkaddr_
fixed field in relay-forw/relay-reply
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
boost::shared_ptr< Subnet6 > Subnet6Ptr
A pointer to a Subnet6 object.
The IOAddress class represents an IP addresses (version agnostic)
Container for storing client class names.
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)