#define Q0_INSTANT_LIMIT 1000000 // ns
#define KRU_CAPACITY (1<<19) // same as ratelimiting default
-#define BASE_PRICE(nsec) ((uint64_t)KRU_LIMIT * LOADS_THRESHOLDS[0] / (1<<16) * (nsec) / Q0_INSTANT_LIMIT)
+#define BASE_PRICE(nsec) ((nsec) >= UINT64_MAX / ((uint64_t)KRU_LIMIT * LOADS_THRESHOLDS[0] / (1<<16)) ? UINT64_MAX : \
+ (uint64_t)KRU_LIMIT * LOADS_THRESHOLDS[0] / (1<<16) * (nsec) / Q0_INSTANT_LIMIT)
+ // with current settings BASE_PRICE(x) is approximately x
+ // with nsec > ~(2<<32) the KRU limit is reached, so rounding >~(2<<44) to ~(2<<64) is OK
#define MAX_DECAY (BASE_PRICE(1000000) / 2) // max value at 50% utilization of single cpu
// see log written by defer_str_conf for details
// compute adjusted prices, using standard rounding
kru_price_t prices[V6_PREFIXES_CNT];
for (int i = 0; i < V6_PREFIXES_CNT; ++i) {
- prices[i] = (req->qsource.price_factor16
+ uint64_t price = (req->qsource.price_factor16
* (uint64_t)ratelimiting->v6_prices[i] + (1<<15)) >> 16;
+ prices[i] = price > (kru_price_t)-1 ? -1 : price;
}
limited_prefix = KRU.limited_multi_prefix_or((struct kru *)ratelimiting->kru, time_now,
1, key, V6_PREFIXES, prices, V6_PREFIXES_CNT, NULL);
// compute adjusted prices, using standard rounding
kru_price_t prices[V4_PREFIXES_CNT];
for (int i = 0; i < V4_PREFIXES_CNT; ++i) {
- prices[i] = (req->qsource.price_factor16
+ uint64_t price = (req->qsource.price_factor16
* (uint64_t)ratelimiting->v4_prices[i] + (1<<15)) >> 16;
+ prices[i] = price > (kru_price_t)-1 ? -1 : price;
}
limited_prefix = KRU.limited_multi_prefix_or((struct kru *)ratelimiting->kru, time_now,
0, key, V4_PREFIXES, prices, V4_PREFIXES_CNT, NULL);
from typing import List, Literal, Optional
-from knot_resolver.datamodel.types import FloatNonNegative, IDPattern, IPNetwork
+from knot_resolver.datamodel.types import Float0_65535, IDPattern, IPNetwork
from knot_resolver.utils.modeling import ConfigSchema
minimize: bool = True
dns64: bool = True
- price_factor: FloatNonNegative = FloatNonNegative(1.0)
+ price_factor: Float0_65535 = Float0_65535(1.0)
fallback: bool = True