From: David Härdeman Date: Wed, 24 Sep 2025 13:44:13 +0000 (+0200) Subject: dhcpv4: dhcpv4_fr_rand_delay() fixups X-Git-Url: http://git.openwrt.org/?a=commitdiff_plain;h=031e1c799f5930e2e27278a629ef2e61de91679f;p=project%2Fodhcpd.git dhcpv4: dhcpv4_fr_rand_delay() fixups Move constants to dhcpv4.h, and make their names more descriptive. Also, use abs() instead of labs(), since "msecs" is an int. Signed-off-by: David Härdeman Link: https://github.com/openwrt/odhcpd/pull/266 Signed-off-by: Álvaro Fernández Rojas --- diff --git a/src/dhcpv4.c b/src/dhcpv4.c index 15425a5..25fcdb6 100644 --- a/src/dhcpv4.c +++ b/src/dhcpv4.c @@ -280,13 +280,11 @@ static void dhcpv4_fr_delay_timer(struct uloop_timeout *event) static void dhcpv4_fr_rand_delay(struct dhcp_assignment *a) { -#define MIN_DELAY 500 -#define MAX_FUZZ 500 int msecs; odhcpd_urandom(&msecs, sizeof(msecs)); - msecs = labs(msecs)%MAX_FUZZ + MIN_DELAY; + msecs = abs(msecs) % DHCPV4_FR_MAX_FUZZ + DHCPV4_FR_MIN_DELAY; uloop_timeout_set(&a->fr_timer, msecs); a->fr_timer.cb = dhcpv4_fr_delay_timer; diff --git a/src/dhcpv4.h b/src/dhcpv4.h index 7db5c52..d54aedb 100644 --- a/src/dhcpv4.h +++ b/src/dhcpv4.h @@ -21,6 +21,9 @@ #define DHCPV4_MIN_PACKET_SIZE 300 +#define DHCPV4_FR_MIN_DELAY 500 +#define DHCPV4_FR_MAX_FUZZ 500 + enum dhcpv4_op { DHCPV4_BOOTREQUEST = 1, DHCPV4_BOOTREPLY = 2