On Sun, Apr 10, 2022 at 02:54:38PM +0300, Серж ИвановЪ wrote:
> пт, 8 апр. 2022 г. в 17:55, Серж ИвановЪ <evasive.gy...@gmail.com>:
> > пт, 8 апр. 2022 г. в 17:46, Geert Stappers <stapp...@stappers.nl>:
> >> On Fri, Apr 08, 2022 at 04:34:11PM +0300, Серж ИвановЪ wrote:
> >> > I am talking about this part of code in src/dhcp.c
> >> > ```
> >> > struct ping_result *do_icmp_ping(time_t now, struct in_addr addr, 
> >> > unsigned
> >> > int h
> >> > {
> >> > static struct ping_result dummy;
> >> > struct ping_result *r, *victim = NULL;
> >> > int count, max = (int)(0.6 * (((float)PING_CACHE_TIME)/
> >> >                                            ((float)PING_WAIT)));
> >> > ```
> >> >
> >> > 0.6 should be configurable via compile-time constants, not hard-coded
> >>
> >> That should be expressed as a patch.
> >>

> From d93e601e5d02221ae8a82770aa8771c8c0700beb Mon Sep 17 00:00:00 2001
> From: s3rj1k <evasive.gy...@gmail.com>
> Date: Sun, 10 Apr 2022 14:40:27 +0300
> Subject: [PATCH] Add PING_CHECKS_THRESHOLD compile-time variable
> 
> Signed-off-by: s3rj1k <evasive.gy...@gmail.com>
> ---
>  src/config.h | 1 +
>  src/dhcp.c   | 4 ++--
>  2 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/src/config.h b/src/config.h
> index cd37900..75c5d05 100644
> --- a/src/config.h
> +++ b/src/config.h
> @@ -35,6 +35,7 @@
>  #define MAXLEASES 1000 /* maximum number of DHCP leases */
>  #define PING_WAIT 3 /* wait for ping address-in-use test */
>  #define PING_CACHE_TIME 30 /* Ping test assumed to be valid this long. */
> +#define PING_CHECKS_THRESHOLD 60 /* threshold percent of possible ping 
> checks in the last PING_CACHE_TIME */
>  #define DECLINE_BACKOFF 600 /* disable DECLINEd static addresses for this 
> long */
>  #define DHCP_PACKET_MAX 16384 /* hard limit on DHCP packet size */
>  #define SMALLDNAME 50 /* most domain names are smaller than this */
> diff --git a/src/dhcp.c b/src/dhcp.c
> index 6104c87..3187e3f 100644
> --- a/src/dhcp.c
> +++ b/src/dhcp.c
> @@ -723,14 +723,14 @@ struct ping_result *do_icmp_ping(time_t now, struct 
> in_addr addr, unsigned int h
>  {
>    static struct ping_result dummy;
>    struct ping_result *r, *victim = NULL;
> -  int count, max = (int)(0.6 * (((float)PING_CACHE_TIME)/
> +  int count, max = (int)(((float)PING_CHECKS_THRESHOLD / 100) * 
> (((float)PING_CACHE_TIME)/
>                               ((float)PING_WAIT)));
>  
>    /* check if we failed to ping addr sometime in the last
>       PING_CACHE_TIME seconds. If so, assume the same situation still exists.
>       This avoids problems when a stupid client bangs
>       on us repeatedly. As a final check, if we did more
> -     than 60% of the possible ping checks in the last 
> +     than PING_CHECKS_THRESHOLD% of the possible ping checks in the last

FWIW:  I can't tell if that 60% is very same as the 0.6,
       but this patch does make that connection / relation.

>       PING_CACHE_TIME, we are in high-load mode, so don't do any more. */
>    for (count = 0, r = daemon->ping_results; r; r = r->next)
>      if (difftime(now, r->time) >  (float)PING_CACHE_TIME)


Groeten
Geert Stappers
-- 
Silence is hard to parse

_______________________________________________
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
https://lists.thekelleys.org.uk/cgi-bin/mailman/listinfo/dnsmasq-discuss

Reply via email to