chg: usr: Enforce bounds of prefetch configuration option

The prefetch configuration option now enforces boundaries. The configuration (including when using `named-checkconf`) now fails if the trigger (first value) is above 10, and if the eligibility (second optional value) isn't at least six seconds greater than the trigger value.

Merge branch 'colin/prefetch-enforcebounds' into 'main'

See merge request isc-projects/bind9!11243
This commit is contained in:
Colin Vidal 2025-11-18 11:04:49 +01:00
commit 103799ac23
6 changed files with 95 additions and 6 deletions

View file

@ -0,0 +1,16 @@
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* SPDX-License-Identifier: MPL-2.0
*
* 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
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
options {
prefetch 11;
};

View file

@ -0,0 +1,16 @@
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* SPDX-License-Identifier: MPL-2.0
*
* 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
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
options {
prefetch 2 7;
};

View file

@ -0,0 +1,16 @@
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* SPDX-License-Identifier: MPL-2.0
*
* 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
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
view foo {
prefetch 11;
};

View file

@ -0,0 +1,16 @@
/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* SPDX-License-Identifier: MPL-2.0
*
* 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
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
view foo {
prefetch 9 13;
};

View file

@ -1999,6 +1999,37 @@ check_options(const cfg_obj_t *options, const cfg_obj_t *config,
}
}
obj = NULL;
(void)cfg_map_get(options, "prefetch", &obj);
if (obj != NULL) {
const cfg_obj_t *trigger = cfg_tuple_get(obj, "trigger");
const cfg_obj_t *eligible = cfg_tuple_get(obj, "eligible");
uint32_t tvalue = cfg_obj_asuint32(trigger);
if (tvalue > 10) {
cfg_obj_log(obj, ISC_LOG_ERROR,
"prefetch '%u' out of range (0..10)",
tvalue);
if (result == ISC_R_SUCCESS) {
result = ISC_R_RANGE;
}
}
if (!cfg_obj_isvoid(eligible)) {
uint32_t evalue = cfg_obj_asuint32(eligible);
if (evalue < tvalue + 6) {
cfg_obj_log(obj, ISC_LOG_ERROR,
"prefetch eligibility '%u' must be "
"at least six seconds longer than "
"the trigger value '%u'",
evalue, tvalue);
if (result == ISC_R_SUCCESS) {
result = ISC_R_RANGE;
}
}
}
}
if (aclctx != NULL) {
cfg_aclconfctx_detach(&aclctx);
}

View file

@ -2237,9 +2237,6 @@ prefetch_merge(cfg_obj_t *effectiveobj, const cfg_obj_t *defaultobj) {
trigger = (cfg_obj_t *)cfg_tuple_get(effectiveobj, "trigger");
INSIST(cfg_obj_isuint32(trigger));
if (cfg_obj_asuint32(trigger) > 10) {
trigger->value.uint32 = 10;
}
eligible = (cfg_obj_t *)cfg_tuple_get(effectiveobj, "eligible");
if (cfg_obj_isvoid(eligible)) {
@ -2253,9 +2250,6 @@ prefetch_merge(cfg_obj_t *effectiveobj, const cfg_obj_t *defaultobj) {
}
INSIST(cfg_obj_isuint32(eligible));
if (cfg_obj_asuint32(eligible) < cfg_obj_asuint32(trigger) + 6) {
eligible->value.uint32 = cfg_obj_asuint32(trigger) + 6;
}
}
static void