32 << subnet->getID() <<
"' is already in use");
38 << subnet->toText() <<
"' already exists");
42 .arg(subnet->toText());
43 static_cast<void>(subnets_.insert(subnet));
49 const SubnetID& subnet_id = subnet->getID();
51 auto subnet_it = index.find(subnet_id);
52 if (subnet_it == index.end()) {
56 bool ret = index.replace(subnet_it, subnet);
59 .arg(subnet_id).arg(ret);
75 auto subnet_it = index.find(subnet_id);
76 if (subnet_it == index.end()) {
83 index.erase(subnet_it);
86 .arg(subnet->toText());
98 auto const& other_subnets = other.
getAll();
99 for (
auto const& other_subnet : (*other_subnets)) {
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);
160 other_subnet->getCfgOption()->encapsulate();
163 for (
auto const& pool : other_subnet->getPoolsWritable(
Lease::TYPE_V4)) {
164 pool->getCfgOption()->createOptions(cfg_def);
165 pool->getCfgOption()->encapsulate();
169 static_cast<void>(subnets_.insert(other_subnet));
173 std::string network_name = other_subnet->getSharedNetworkName();
174 if (!network_name.empty()) {
177 network->add(other_subnet);
182 << other_subnet->getID()
183 <<
" to shared network: " << network_name
184 <<
", network does not exist");
188 other_subnet->createAllocators();
195 auto subnet_it = index.find(subnet_text);
196 return ((subnet_it != index.cend()) ? (*subnet_it) :
ConstSubnet4Ptr());
202 auto subnet_it = index.find(server_id);
203 return (subnet_it != index.cend());
209 selector.
ciaddr_ = query->getCiaddr();
210 selector.
giaddr_ = query->getGiaddr();
227 boost::dynamic_pointer_cast<OptionCustom>(rai);
233 getIgnoreRAILinkSelection();
234 if (!ignore_link_sel) {
239 if (link_select_buf.size() ==
sizeof(uint32_t)) {
254 boost::dynamic_pointer_cast<OptionCustom>(sbnsel);
264 for (
auto const& subnet : subnets_) {
265 Cfg4o6& cfg4o6 = subnet->get4o6();
273 std::pair<asiolink::IOAddress, uint8_t> pref = cfg4o6.
getSubnet4o6();
274 if (!pref.first.isV6Zero()) {
321 for (
auto const& subnet : subnets_) {
325 if (subnet->hasRelays()) {
326 if (!subnet->hasRelayAddress(selector.
giaddr_)) {
333 subnet->getSharedNetwork(network);
334 if (!network || !(network->hasRelayAddress(selector.
giaddr_))) {
343 .arg(subnet->toText())
384 <<
" doesn't exist and therefore it is impossible"
385 " to find a suitable subnet for its IPv4 address");
399 iface->getAddress4(address);
419 for (
auto const& subnet : subnets_) {
425 subnet_selected = subnet;
433 subnet->getSharedNetwork(network);
436 subnet_selected = subnet;
440 if (subnet_selected) {
442 if (subnet_selected->clientSupported(client_classes)) {
445 .arg(subnet->toText())
447 return (subnet_selected);
463 auto subnet_it = index.find(subnet_id);
464 return ((subnet_it != index.cend()) ? (*subnet_it) :
Subnet4Ptr());
470 for (
auto const& subnet : subnets_) {
473 if (!subnet->inRange(address)) {
478 if (subnet->clientSupported(client_classes)) {
480 .arg(subnet->toText())
497 for (
auto const& subnet : subnets_) {
498 if (!subnet->inRange(link_addr)) {
501 links.insert(subnet->getID());
512 for (
auto const& subnet4 : subnets_) {
513 SubnetID subnet_id = subnet4->getID();
518 "assigned-addresses"));
521 "cumulative-assigned-addresses"));
524 "declined-addresses"));
527 "reclaimed-declined-addresses"));
530 "reclaimed-leases"));
535 "total-addresses")));
539 "assigned-addresses")));
543 "cumulative-assigned-addresses")));
547 "declined-addresses")));
551 "reclaimed-declined-addresses")));
555 "reclaimed-leases")));
565 for (
auto const& subnet4 : subnets_) {
566 SubnetID subnet_id = subnet4->getID();
569 generateName(
"subnet", subnet_id,
"total-addresses"),
572 "cumulative-assigned-addresses"));
574 stats_mgr.
setValue(name,
static_cast<int64_t
>(0));
580 stats_mgr.
setValue(name_reuses, int64_t(0));
584 "v4-reservation-conflicts"));
586 stats_mgr.
setValue(name_conflicts,
static_cast<int64_t
>(0));
592 "total-addresses")));
594 stats_mgr.
setValue(name_total,
static_cast<int64_t
>(pool->getCapacity()));
596 stats_mgr.
addValue(name_total,
static_cast<int64_t
>(pool->getCapacity()));
601 "cumulative-assigned-addresses")));
603 stats_mgr.
setValue(name_ca,
static_cast<int64_t
>(0));
609 if (subnets_.begin() != subnets_.end()) {
617 for (
auto const& subnet : subnets_) {
618 subnet->initAllocatorsAfterConfigure();
631 for (
auto const& subnet : subnets_) {
632 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)
static const IOAddress & IPV4_ZERO_ADDRESS()
Returns an address set to all zeros.
bool isV4Zero() const
Convenience function to check if it is an IPv4 zero address.
std::string toText() const
Convert the address to a string.
bool isV4Bcast() const
Convenience function to check if it is an IPv4 broadcast address.
static IOAddress fromBytes(short family, const uint8_t *data)
Creates an address from over wire data.
static ElementPtr createList(const Position &pos=ZERO_POSITION())
Creates an empty ListElement type ElementPtr.
static CfgMgr & instance()
returns a single instance of Configuration Manager
SrvConfigPtr getCurrentCfg()
Returns a pointer to the current configuration.
Holds subnets configured for the DHCPv4 server.
ConstSubnet4Ptr getBySubnetId(const SubnetID &subnet_id) const
Returns const pointer to a subnet identified by the specified subnet identifier.
SubnetIDSet getLinks(const asiolink::IOAddress &link_addr) const
Convert a link address into a link set.
ConstSubnet4Ptr selectSubnet(const SubnetSelector &selector) const
Returns a pointer to the selected subnet.
void del(const ConstSubnet4Ptr &subnet)
Removes subnet from the configuration.
virtual isc::data::ElementPtr toElement() const
Unparse a configuration object.
void clear()
Clears all subnets from the configuration.
bool hasSubnetWithServerId(const asiolink::IOAddress &server_id) const
Checks if specified server identifier has been specified for any subnet.
ConstSubnet4Ptr getByPrefix(const std::string &subnet_prefix) const
Returns const pointer to a subnet which matches the specified prefix in the canonical form.
void updateStatistics()
Updates statistics.
void merge(CfgOptionDefPtr cfg_def, CfgSharedNetworks4Ptr networks, CfgSubnets4 &other)
Merges specified subnet configuration into this configuration.
ConstSubnet4Ptr selectSubnet4o6(const SubnetSelector &selector) const
Attempts to do subnet selection based on DHCP4o6 information.
Subnet4Ptr getSubnet(const SubnetID id) const
Returns subnet with specified subnet-id value.
Subnet4Ptr replace(const Subnet4Ptr &subnet)
Replaces subnet in the configuration.
void initAllocatorsAfterConfigure()
Calls initAllocatorsAfterConfigure for each subnet.
void add(const Subnet4Ptr &subnet)
Adds new subnet to the configuration.
void removeStatistics()
Removes statistics.
const Subnet4Collection * getAll() const
Returns pointer to the collection of all IPv4 subnets.
static SubnetSelector initSelector(const Pkt4Ptr &query)
Build selector from a client's message.
Container for storing client class names.
Exception thrown upon attempt to add subnet with an ID that belongs to the subnet that already exists...
IfacePtr getIface(const unsigned int ifindex)
Returns interface specified interface index.
static IfaceMgr & instance()
IfaceMgr is a singleton class.
static TrackingLeaseMgr & instance()
Return current lease manager.
void recountLeaseStats4()
Recalculates per-subnet and global stats for IPv4 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.
bool empty() const
Specialization of the Optional::empty method for strings.
#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.
IOAddress firstAddrInPrefix(const IOAddress &prefix, uint8_t len)
This code is based on similar code from the Dibbler project.
IOAddress lastAddrInPrefix(const IOAddress &prefix, uint8_t len)
returns a last address in a given prefix
boost::shared_ptr< Element > ElementPtr
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
const isc::log::MessageID DHCPSRV_SUBNET4_SELECT_BY_INTERFACE_NO_MATCH
const isc::log::MessageID DHCPSRV_SUBNET4_SELECT_BY_ADDRESS_NO_MATCH
const isc::log::MessageID DHCPSRV_CFGMGR_SUBNET4_IFACE
boost::shared_ptr< Subnet4 > Subnet4Ptr
A pointer to a Subnet4 object.
std::set< dhcp::SubnetID > SubnetIDSet
Ordered list aka set of subnetIDs.
const isc::log::MessageID DHCPSRV_CFGMGR_UPDATE_SUBNET4
const isc::log::MessageID DHCPSRV_CFGMGR_ADD_SUBNET4
const isc::log::MessageID DHCPSRV_SUBNET4O6_SELECT_FAILED
boost::shared_ptr< const Subnet4 > ConstSubnet4Ptr
A const pointer to a Subnet4 object.
boost::shared_ptr< OptionCustom > OptionCustomPtr
A pointer to the OptionCustom object.
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
boost::shared_ptr< CfgOptionDef > CfgOptionDefPtr
Non-const pointer.
boost::shared_ptr< Iface > IfacePtr
Type definition for the pointer to an Iface object.
const isc::log::MessageID DHCPSRV_SUBNET4_SELECT_NO_RELAY_ADDRESS
const isc::log::MessageID DHCPSRV_CFGMGR_DEL_SUBNET4
const isc::log::MessageID DHCPSRV_SUBNET4_SELECT_NO_USABLE_ADDRESS
const isc::log::MessageID DHCPSRV_CFGMGR_SUBNET4_ADDR
const isc::log::MessageID DHCPSRV_SUBNET4_SELECT_NO_RAI_OPTIONS
const isc::log::MessageID DHCPSRV_CFGMGR_SUBNET4_RELAY
uint32_t SubnetID
Defines unique IPv4 or IPv6 subnet identifier.
const isc::log::MessageID DHCPSRV_SUBNET4_SELECT_BY_RELAY_ADDRESS_NO_MATCH
std::vector< uint8_t > OptionBuffer
buffer types used in DHCP code.
boost::shared_ptr< CfgSharedNetworks4 > CfgSharedNetworks4Ptr
Pointer to the configuration of IPv4 shared networks.
@ RAI_OPTION_LINK_SELECTION
boost::shared_ptr< SharedNetwork4 > SharedNetwork4Ptr
Pointer to SharedNetwork4 object.
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.
This structure contains information about DHCP4o6 (RFC7341)
util::Optional< std::string > getIface4o6() const
Returns the DHCP4o6 interface.
util::Optional< std::pair< asiolink::IOAddress, uint8_t > > getSubnet4o6() const
Returns prefix/len for the IPv6 subnet.
bool enabled() const
Returns whether the DHCP4o6 is enabled or not.
OptionPtr getInterfaceId() const
Returns the interface-id.
Tag for the index for searching by subnet prefix.
Subnet selector used to specify parameters used to select a subnet.
asiolink::IOAddress local_address_
Address on which the message was received.
asiolink::IOAddress option_select_
RAI link select or subnet select option.
std::string iface_name_
Name of the interface on which the message was received.
asiolink::IOAddress ciaddr_
ciaddr from the client's message.
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 giaddr_
giaddr from the client's message.
Tag for the index for searching by server identifier.
Tag for the index for searching by subnet identifier.