From: Francis Dupont Date: Mon, 29 Jan 2018 16:38:08 +0000 (+0100) Subject: [5425a] Reported some changes X-Git-Tag: trac5524_base~19^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=352532410e51e7f9c7e2bf7d7f0aa50ca06e6bf6;p=thirdparty%2Fkea.git [5425a] Reported some changes --- diff --git a/doc/guide/dhcp6-srv.xml b/doc/guide/dhcp6-srv.xml index 4b667a2a47..ad10322ffc 100644 --- a/doc/guide/dhcp6-srv.xml +++ b/doc/guide/dhcp6-srv.xml @@ -1961,7 +1961,7 @@ should include options from the isc option space: Client classification can also be used to restrict access to specific pools within a subnet. This is useful when to segregate clients belonging - to the same subnet into different address ranges. + to the same subnet into different address or prefix ranges. diff --git a/src/lib/dhcpsrv/alloc_engine.h b/src/lib/dhcpsrv/alloc_engine.h index ba8d95bc0d..382a30f520 100644 --- a/src/lib/dhcpsrv/alloc_engine.h +++ b/src/lib/dhcpsrv/alloc_engine.h @@ -1,4 +1,4 @@ -// Copyright (C) 2012-2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2012-2018 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -83,7 +83,6 @@ protected: /// /// @param subnet next address will be returned from pool of that subnet /// @param client_classes list of classes client belongs to - /// @param duid Client's DUID /// @param hint client's hint /// diff --git a/src/lib/dhcpsrv/parsers/dhcp_parsers.h b/src/lib/dhcpsrv/parsers/dhcp_parsers.h index e195cd4bad..12dd20cb0b 100644 --- a/src/lib/dhcpsrv/parsers/dhcp_parsers.h +++ b/src/lib/dhcpsrv/parsers/dhcp_parsers.h @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2013-2018 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -651,8 +651,14 @@ private: /// A storage for pool specific option values. CfgOptionPtr options_; + /// @brief User context (optional, may be null) + /// + /// User context is arbitrary user data, to be used by hooks. isc::data::ConstElementPtr user_context_; + /// @brief Client class (a client has to belong to to use this pd-pool) + /// + /// If null, everyone is allowed. isc::data::ConstElementPtr client_class_; }; diff --git a/src/lib/dhcpsrv/pool.cc b/src/lib/dhcpsrv/pool.cc index dc169b0bae..5375ad1055 100644 --- a/src/lib/dhcpsrv/pool.cc +++ b/src/lib/dhcpsrv/pool.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2012-2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2012-2018 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -340,6 +340,7 @@ Pool6::toElement() const { isc_throw(ToElementError, "invalid prefix range " << prefix.toText() << "-" << last.toText()); } + map->set("prefix-len", Element::create(prefix_len)); // Set delegated-len uint8_t len = getLength(); @@ -354,10 +355,14 @@ Pool6::toElement() const { uint8_t xlen = xopt->getExcludedPrefixLength(); map->set("excluded-prefix-len", Element::create(static_cast(xlen))); - } else { - map->set("excluded-prefix", Element::create(std::string("::"))); - map->set("excluded-prefix-len", Element::create(0)); } + // Let's not insert empty excluded-prefix values. If we ever + // decide to insert it after all, here's the code to do it: + // else { + // map->set("excluded-prefix", + // Element::create(std::string("::"))); + // map->set("excluded-prefix-len", Element::create(0)); + /// } break; } diff --git a/src/lib/dhcpsrv/pool.h b/src/lib/dhcpsrv/pool.h index 46423f6fa8..bba123cfcf 100644 --- a/src/lib/dhcpsrv/pool.h +++ b/src/lib/dhcpsrv/pool.h @@ -100,8 +100,7 @@ public: /// @brief Checks whether this pool supports client that belongs to /// specified classes. /// - /// @todo: currently doing the same than network which - /// is known to be improved. + /// @todo: currently doing the same as network which needs improving. /// /// @param client_classes list of all classes the client belongs to /// @return true if client can be supported, false otherwise @@ -204,6 +203,9 @@ protected: /// @brief Optional definition of a client class /// + /// If empty, all classes are allowed. If non-empty, only those listed + /// here are allowed. + /// /// @ref Network::white_list_ ClientClasses white_list_; diff --git a/src/lib/dhcpsrv/subnet.cc b/src/lib/dhcpsrv/subnet.cc index 3b27412280..86b05f1609 100644 --- a/src/lib/dhcpsrv/subnet.cc +++ b/src/lib/dhcpsrv/subnet.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2012-2017 Internet Systems Consortium, Inc. ("ISC") +// Copyright (C) 2012-2018 Internet Systems Consortium, Inc. ("ISC") // // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this @@ -709,94 +709,16 @@ Subnet6::toElement() const { ElementPtr pool_list = Element::createList(); for (PoolCollection::const_iterator pool = pools.cbegin(); pool != pools.cend(); ++pool) { - // Prepare the map for a pool (@todo move this code to pool.cc) - ElementPtr pool_map = Element::createMap(); - // Set user-context - (*pool)->contextToElement(pool_map); - // Set pool - const IOAddress& first = (*pool)->getFirstAddress(); - const IOAddress& last = (*pool)->getLastAddress(); - std::string range = first.toText() + "-" + last.toText(); - // Try to output a prefix (vs a range) - int prefix_len = prefixLengthFromRange(first, last); - if (prefix_len >= 0) { - std::ostringstream oss; - oss << first.toText() << "/" << prefix_len; - range = oss.str(); - } - pool_map->set("pool", Element::create(range)); - // Set pool options - ConstCfgOptionPtr opts = (*pool)->getCfgOption(); - pool_map->set("option-data", opts->toElement()); - // Set client-class - const ClientClasses& cclasses = (*pool)->getClientClasses(); - if (cclasses.size() > 1) { - isc_throw(ToElementError, "client-class has too many items: " - << cclasses.size()); - } else if (!cclasses.empty()) { - pool_map->set("client-class", Element::create(*cclasses.cbegin())); - } - // Push on the pool list - pool_list->add(pool_map); + pool_list->add((*pool)->toElement()); } map->set("pools", pool_list); + // Set pd-pools const PoolCollection& pdpools = getPools(Lease::TYPE_PD); ElementPtr pdpool_list = Element::createList(); for (PoolCollection::const_iterator pool = pdpools.cbegin(); pool != pdpools.cend(); ++pool) { - // Get it as a Pool6 (@todo move this code to pool.cc) - const Pool6* pdpool = dynamic_cast(pool->get()); - if (!pdpool) { - isc_throw(ToElementError, "invalid pd-pool pointer"); - } - // Prepare the map for a pd-pool - ElementPtr pool_map = Element::createMap(); - // Set user-context - pdpool->contextToElement(pool_map); - // Set prefix - const IOAddress& prefix = pdpool->getFirstAddress(); - pool_map->set("prefix", Element::create(prefix.toText())); - // Set prefix-len (get it from min - max) - const IOAddress& last = pdpool->getLastAddress(); - int prefix_len = prefixLengthFromRange(prefix, last); - if (prefix_len < 0) { - // The pool is bad: give up - isc_throw(ToElementError, "invalid prefix range " - << prefix.toText() << "-" << last.toText()); - } - pool_map->set("prefix-len", Element::create(prefix_len)); - // Set delegated-len - uint8_t len = pdpool->getLength(); - pool_map->set("delegated-len", - Element::create(static_cast(len))); - - // Set excluded prefix - const Option6PDExcludePtr& xopt = - pdpool->getPrefixExcludeOption(); - if (xopt) { - const IOAddress& xprefix = - xopt->getExcludedPrefix(prefix, len); - pool_map->set("excluded-prefix", - Element::create(xprefix.toText())); - uint8_t xlen = xopt->getExcludedPrefixLength(); - pool_map->set("excluded-prefix-len", - Element::create(static_cast(xlen))); - } - - // Set pool options - ConstCfgOptionPtr opts = pdpool->getCfgOption(); - pool_map->set("option-data", opts->toElement()); - // Set client-class - const ClientClasses& cclasses = pdpool->getClientClasses(); - if (cclasses.size() > 1) { - isc_throw(ToElementError, "client-class has too many items: " - << cclasses.size()); - } else if (!cclasses.empty()) { - pool_map->set("client-class", Element::create(*cclasses.cbegin())); - } - // Push on the pool list - pdpool_list->add(pool_map); + pdpool_list->add((*pool)->toElement()); } map->set("pd-pools", pdpool_list);