From 77639d2d452e989f57df7b83fdcd8c1ae9c47aab Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Wed, 26 Feb 2025 10:55:48 -0800 Subject: [PATCH] blacklist: allow configuration to disable the blacklist Certain use cases may not need or want this feature so allowing it to be disabled is a much cleaner way than doing something like setting the timeouts very low. Now [Blacklist].InitialTimeout can be set to zero which will prevent any blacklisting. In addition some other small changes were added: - Warn if the multiplier is 0, and set to 1 if so. - Warn if the initial timeout exceeds the maximum timeout. - Log if the blacklist is disabled - Use L_USEC_PER_SEC instead of magic numbers. --- src/blacklist.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/blacklist.c b/src/blacklist.c index 04e4b8e3..21f85a75 100644 --- a/src/blacklist.c +++ b/src/blacklist.c @@ -91,6 +91,9 @@ void blacklist_add_bss(const uint8_t *addr) { struct blacklist_entry *entry; + if (!blacklist_initial_timeout) + return; + blacklist_prune(); entry = l_queue_find(blacklist, match_addr, addr); @@ -162,19 +165,31 @@ static int blacklist_init(void) blacklist_initial_timeout = BLACKLIST_DEFAULT_TIMEOUT; /* For easier user configuration the timeout values are in seconds */ - blacklist_initial_timeout *= 1000000; + blacklist_initial_timeout *= L_USEC_PER_SEC; if (!l_settings_get_uint64(config, "Blacklist", "Multiplier", &blacklist_multiplier)) blacklist_multiplier = BLACKLIST_DEFAULT_MULTIPLIER; + if (blacklist_multiplier == 0) { + l_warn("[Blacklist].Multiplier cannot be zero, setting to 1"); + blacklist_multiplier = 1; + } + if (!l_settings_get_uint64(config, "Blacklist", "MaximumTimeout", &blacklist_max_timeout)) blacklist_max_timeout = BLACKLIST_DEFAULT_MAX_TIMEOUT; - blacklist_max_timeout *= 1000000; + blacklist_max_timeout *= L_USEC_PER_SEC; + + if (blacklist_initial_timeout > blacklist_max_timeout) + l_warn("[Blacklist].InitialTimeout exceeded " + "[Blacklist].MaximumTimeout!"); + + if (!blacklist_initial_timeout) + l_debug("initial timeout was zero, blacklist will be disabled"); blacklist = l_queue_new();