-
Notifications
You must be signed in to change notification settings - Fork 141
dhcp: add configurable backoff parameters for DHCPv4 #593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -177,6 +177,9 @@ const struct option cf_options[] = { | |
| {"fallback_time", required_argument, NULL, O_FALLBACK_TIME}, | ||
| {"ipv4ll_time", required_argument, NULL, O_IPV4LL_TIME}, | ||
| {"nosyslog", no_argument, NULL, O_NOSYSLOG}, | ||
| {"initial_interval", required_argument, NULL, O_INITIAL_INTERVAL}, | ||
| {"backoff_cutoff", required_argument, NULL, O_BACKOFF_CUTOFF}, | ||
| {"backoff_jitter", required_argument, NULL, O_BACKOFF_JITTER}, | ||
| {NULL, 0, NULL, '\0'} | ||
| }; | ||
|
|
||
|
|
@@ -2580,6 +2583,33 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, | |
| logsetopts(logopts); | ||
| } | ||
| break; | ||
| case O_INITIAL_INTERVAL: | ||
| ARG_REQUIRED; | ||
| ifo->initial_interval = | ||
| (uint32_t)strtou(arg, NULL, 0, 1, UINT32_MAX, &e); | ||
| if (e) { | ||
| logerrx("invalid initial interval: %s", arg); | ||
| return -1; | ||
| } | ||
| break; | ||
| case O_BACKOFF_CUTOFF: | ||
| ARG_REQUIRED; | ||
| ifo->backoff_cutoff = | ||
| (uint32_t)strtou(arg, NULL, 0, 1, UINT32_MAX, &e); | ||
| if (e) { | ||
| logerrx("invalid backoff cutoff: %s", arg); | ||
| return -1; | ||
| } | ||
| break; | ||
|
Comment on lines
+2586
to
+2603
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validate the new knobs together, not just individually. Right now 🛠️ Possible clamp in
|
||
| case O_BACKOFF_JITTER: | ||
| ARG_REQUIRED; | ||
| ifo->backoff_jitter = | ||
| (uint32_t)strtou(arg, NULL, 0, 0, UINT32_MAX, &e); | ||
| if (e) { | ||
| logerrx("invalid backoff jitter: %s", arg); | ||
| return -1; | ||
| } | ||
| break; | ||
| default: | ||
| return 0; | ||
| } | ||
|
|
@@ -2667,6 +2697,9 @@ default_config(struct dhcpcd_ctx *ctx) | |
| #ifdef INET | ||
| ifo->fallback_time = DEFAULT_FALLBACK; | ||
| ifo->ipv4ll_time = DEFAULT_IPV4LL; | ||
| ifo->initial_interval = DEFAULT_INITIAL_INTERVAL; | ||
| ifo->backoff_cutoff = DEFAULT_BACKOFF_CUTOFF; | ||
| ifo->backoff_jitter = DEFAULT_BACKOFF_JITTER; | ||
| #endif | ||
| ifo->metric = -1; | ||
| ifo->auth.options |= DHCPCD_AUTH_REQUIRE; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| PROG= test_backoff | ||
| SRCS= test_backoff.c | ||
|
|
||
| CFLAGS+= -Wall -Wextra -std=c99 -D_DEFAULT_SOURCE | ||
| LDFLAGS+= -lm | ||
|
|
||
| all: ${PROG} | ||
|
|
||
| ${PROG}: ${SRCS} | ||
| ${CC} ${CFLAGS} -o ${PROG} ${SRCS} ${LDFLAGS} | ||
|
|
||
| test: ${PROG} | ||
| @echo "Run as root: sudo ./${PROG} [-b path-to-dhcpcd]" | ||
|
|
||
| clean: | ||
| rm -f ${PROG} | ||
|
|
||
| distclean: clean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 969
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 53
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 112
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 168
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 176
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 93
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 415
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 2107
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 529
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 282
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 991
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 3882
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 55
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 6139
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 53
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 5685
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 53
🏁 Script executed:
# Try looking in if-options.h fd if-options.h srcRepository: NetworkConfiguration/dhcpcd
Length of output: 87
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 87
🏁 Script executed:
cat src/if-options.h | head -300Repository: NetworkConfiguration/dhcpcd
Length of output: 9442
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 53
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 1520
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 1186
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 582
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 53
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 337
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 356
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 53
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 736
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 363
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 53
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 581
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 3172
🏁 Script executed:
Repository: NetworkConfiguration/dhcpcd
Length of output: 199
Fix unsigned integer arithmetic wrapping in the DHCP retransmission timeout calculation.
The expression
arc4random_uniform(jitter * 2) - jitterwraps when the random value is less thanjitter, since both operands areunsigned int. With default config (initial_interval 4andbackoff_jitter 1000), a random value under 500 causesRTto wrap to nearUINT_MAX, scheduling an incorrect timeout. The scenario withinitial_interval 1andbackoff_jitter 2000reliably triggers wrap on any random value below 2000.Perform the jitter calculation in signed or wider integer space and clamp the result before assigning to
RT.🤖 Prompt for AI Agents