From: Razvan Becheriu Date: Wed, 22 May 2024 14:57:14 +0000 (+0300) Subject: [#3424] fixed missing pool-id in pd-pool X-Git-Tag: Kea-2.6.0~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=92102cfda82bf19232e7f2a20b9e85aa22a293f8;p=thirdparty%2Fkea.git [#3424] fixed missing pool-id in pd-pool --- diff --git a/doc/examples/kea6/all-keys-netconf.json b/doc/examples/kea6/all-keys-netconf.json index efc8e25235..2466dd1230 100644 --- a/doc/examples/kea6/all-keys-netconf.json +++ b/doc/examples/kea6/all-keys-netconf.json @@ -927,7 +927,25 @@ // List of client classes which must be evaluated // when this prefix pool is selected for client assignments. - "require-client-classes": [] + "require-client-classes": [], + + // PD-pool identifier used to enable statistics for this pd-pool. + // The pd-pool ID does not need to be unique within the subnet + // or across subnets. + // If not unconfigured, it defaults to 0. The statistics + // regarding this pd-pool will be combined with the other statistics + // of all other pd-pools with the same pd-pool ID in this subnet. + "pool-id": 1 + }, + { + // Length of prefixes delegated to clients. + "delegated-len": 64, + + // Prefix range (address) used for client assignments. + "prefix": "2001:db8:2::", + + // Prefix range (length) used for client assignments. + "prefix-len": 48 } ], diff --git a/doc/examples/kea6/all-keys.json b/doc/examples/kea6/all-keys.json index cde5ee61e5..9ccbfc2d84 100644 --- a/doc/examples/kea6/all-keys.json +++ b/doc/examples/kea6/all-keys.json @@ -927,7 +927,25 @@ // List of client classes which must be evaluated // when this prefix pool is selected for client assignments. - "require-client-classes": [] + "require-client-classes": [], + + // PD-pool identifier used to enable statistics for this pd-pool. + // The pd-pool ID does not need to be unique within the subnet + // or across subnets. + // If not unconfigured, it defaults to 0. The statistics + // regarding this pd-pool will be combined with the other statistics + // of all other pd-pools with the same pd-pool ID in this subnet. + "pool-id": 1 + }, + { + // Length of prefixes delegated to clients. + "delegated-len": 64, + + // Prefix range (address) used for client assignments. + "prefix": "2001:db8:2::", + + // Prefix range (length) used for client assignments. + "prefix-len": 48 } ], diff --git a/src/bin/dhcp6/dhcp6_lexer.ll b/src/bin/dhcp6/dhcp6_lexer.ll index 8ff6736571..6c13cdfb52 100644 --- a/src/bin/dhcp6/dhcp6_lexer.ll +++ b/src/bin/dhcp6/dhcp6_lexer.ll @@ -1301,6 +1301,7 @@ ControlCharacterFill [^"\\]|\\["\\/bfnrtu] \"pool-id\" { switch(driver.ctx_) { case isc::dhcp::Parser6Context::POOLS: + case isc::dhcp::Parser6Context::PD_POOLS: return isc::dhcp::Dhcp6Parser::make_POOL_ID(driver.loc_); default: return isc::dhcp::Dhcp6Parser::make_STRING("pool-id", driver.loc_); diff --git a/src/bin/dhcp6/dhcp6_parser.yy b/src/bin/dhcp6/dhcp6_parser.yy index e4ccde453e..834dfbca25 100644 --- a/src/bin/dhcp6/dhcp6_parser.yy +++ b/src/bin/dhcp6/dhcp6_parser.yy @@ -2254,6 +2254,7 @@ pd_pool_params: pd_pool_param pd_pool_param: pd_prefix | pd_prefix_len | pd_delegated_len + | pool_id | option_data_list | client_class | require_client_classes diff --git a/src/lib/dhcpsrv/parsers/dhcp_parsers.cc b/src/lib/dhcpsrv/parsers/dhcp_parsers.cc index 76b7c7f661..45d9db3a1f 100644 --- a/src/lib/dhcpsrv/parsers/dhcp_parsers.cc +++ b/src/lib/dhcpsrv/parsers/dhcp_parsers.cc @@ -1064,37 +1064,37 @@ PdPoolParser::PdPoolParser() { } void -PdPoolParser::parse(PoolStoragePtr pools, ConstElementPtr pd_pool_, +PdPoolParser::parse(PoolStoragePtr pools, ConstElementPtr pd_pool, bool encapsulate_options) { - checkKeywords(SimpleParser6::PD_POOL6_PARAMETERS, pd_pool_); + checkKeywords(SimpleParser6::PD_POOL6_PARAMETERS, pd_pool); - std::string addr_str = getString(pd_pool_, "prefix"); + std::string addr_str = getString(pd_pool, "prefix"); - uint8_t prefix_len = getUint8(pd_pool_, "prefix-len"); + uint8_t prefix_len = getUint8(pd_pool, "prefix-len"); - uint8_t delegated_len = getUint8(pd_pool_, "delegated-len"); + uint8_t delegated_len = getUint8(pd_pool, "delegated-len"); std::string excluded_prefix_str = "::"; - if (pd_pool_->contains("excluded-prefix")) { - excluded_prefix_str = getString(pd_pool_, "excluded-prefix"); + if (pd_pool->contains("excluded-prefix")) { + excluded_prefix_str = getString(pd_pool, "excluded-prefix"); } uint8_t excluded_prefix_len = 0; - if (pd_pool_->contains("excluded-prefix-len")) { - excluded_prefix_len = getUint8(pd_pool_, "excluded-prefix-len"); + if (pd_pool->contains("excluded-prefix-len")) { + excluded_prefix_len = getUint8(pd_pool, "excluded-prefix-len"); } - ConstElementPtr user_context = pd_pool_->get("user-context"); + ConstElementPtr user_context = pd_pool->get("user-context"); if (user_context) { user_context_ = user_context; } - ConstElementPtr client_class = pd_pool_->get("client-class"); + ConstElementPtr client_class = pd_pool->get("client-class"); if (client_class) { client_class_ = client_class; } - ConstElementPtr class_list = pd_pool_->get("require-client-classes"); + ConstElementPtr class_list = pd_pool->get("require-client-classes"); // Check the pool parameters. It will throw an exception if any // of the required parameters are invalid. @@ -1110,7 +1110,21 @@ PdPoolParser::parse(PoolStoragePtr pools, ConstElementPtr pd_pool_, // aware whether they don't exist or are invalid, let's append // the position of the pool map element. isc_throw(isc::dhcp::DhcpConfigError, ex.what() - << " (" << pd_pool_->getPosition() << ")"); + << " (" << pd_pool->getPosition() << ")"); + } + + // If there is a pool-id, store it. + ConstElementPtr pool_id = pd_pool->get("pool-id"); + if (pool_id) { + if (pool_id->intValue() <= 0) { + isc_throw(BadValue, "pool-id " << pool_id->intValue() << " is not" + << " a positive integer greater than 0"); + } else if (pool_id->intValue() > numeric_limits::max()) { + isc_throw(BadValue, "pool-id " << pool_id->intValue() << " is not" + << " a 32 bit unsigned integer"); + } + + pool_->setID(pool_id->intValue()); } // We create subnet first and then parse the options straight into the subnet's @@ -1119,7 +1133,7 @@ PdPoolParser::parse(PoolStoragePtr pools, ConstElementPtr pd_pool_, // it cost performance. Second, copying options reset the isEncapsulated() flag. // If the options have been encapsulated we want to preserve the flag to ensure // they are not encapsulated several times. - ConstElementPtr option_data = pd_pool_->get("option-data"); + ConstElementPtr option_data = pd_pool->get("option-data"); if (option_data) { auto opts_parser = createOptionDataListParser(); opts_parser->parse(pool_->getCfgOption(), option_data, encapsulate_options); diff --git a/src/lib/yang/translator_pd_pool.cc b/src/lib/yang/translator_pd_pool.cc index d0f888050e..b284b6ce83 100644 --- a/src/lib/yang/translator_pd_pool.cc +++ b/src/lib/yang/translator_pd_pool.cc @@ -151,6 +151,8 @@ TranslatorPdPool::getPdPoolKea(DataNode const& data_node) { checkAndGetLeaf(result, data_node, "delegated-len"); checkAndGetLeaf(result, data_node, "require-client-classes"); + checkAndGetLeaf(result, data_node, "pool-id"); + checkAndGetAndJsonifyLeaf(result, data_node, "user-context"); ConstElementPtr options = getOptionDataList(data_node); @@ -218,6 +220,8 @@ TranslatorPdPool::setPdPoolKea(string const& xpath, ConstElementPtr elem) { checkAndSetLeafList(elem, xpath, "require-client-classes", LeafBaseType::String); + checkAndSetLeaf(elem, xpath, "pool-id", LeafBaseType::Dec64); + checkAndSetUserContext(elem, xpath); ConstElementPtr xprefix = elem->get("excluded-prefix");