Commit de88396
committed
dhcp: add configurable backoff parameters for DHCPv4
In cloud and virtual environments the DHCP service is typically
ready within hundreds of milliseconds of the interface coming up,
and once ready, responds within single-digit milliseconds. The
RFC 2131 defaults (4s initial interval, 64s backoff cap) are
designed for congested broadcast networks and are unnecessarily
conservative in this context.
Add three new configuration options to tune DHCPv4 retransmission:
initial_interval - initial retransmission interval (default 4s)
backoff_cutoff - exponential backoff cap (default 64s)
backoff_jitter - random jitter per retry (default ±1000ms)
Defaults match RFC 2131 so existing behaviour is unchanged.
Option naming aligns with dhclient (initial-interval, backoff-cutoff).
Minimum of 1 is enforced at parse time for interval and cutoff;
invalid values are logged and the default is used.
These options are DHCPv4-only; DHCPv6 retransmission follows
RFC 8415 constants and is not user-configurable.
A test harness (tests/backoff/test_backoff.c) was used to validate
timing assumptions and correctness across multiple scenarios
(defaults, min-latency, cloud-recommended) and to confirm rejection
of invalid values. It requires root and network namespaces so may
not be suitable for all CI environments. It can be removed if it
doesn't have long-term value.
Example test output:
```
$ sudo ./tests/backoff/test_backoff -b ./src/dhcpcd -n 128
dhcpcd DHCPDISCOVER backoff integration test
=============================================
Binary: /home/cpatterson/git/dhcpcd/src/dhcpcd
Runs: 128 per test
--- defaults (N=128) ---
dhcpcd.conf: timeout=75
PASS: 128/128 runs produced data
Retry Expected Min Avg Max N Result
------------------------------------------------------
Init 1±1.0s 0.0s 1.0s 2.0s 128 PASS
1 4±1.0s 3.0s 4.0s 5.0s 128 PASS
2 8±1.0s 7.0s 8.0s 9.0s 128 PASS
3 16±1.0s 15.0s 16.0s 17.0s 128 PASS
4 32±1.0s 31.1s 32.1s 33.0s 128 PASS
5 64±1.0s 63.0s 64.0s 65.0s 128 PASS
Elapsed: 75.9s
--- min-latency (N=128) ---
dhcpcd.conf: timeout=12, nodelay, initial_interval=1, backoff_cutoff=1, backoff_jitter=0
PASS: 128/128 runs produced data
Retry Expected Min Avg Max N Result
------------------------------------------------------
Init 0 - - - 128 PASS
1 1±0.0s 1.0s 1.0s 1.0s 128 PASS
2 1±0.0s 1.0s 1.0s 1.0s 128 PASS
3 1±0.0s 1.0s 1.0s 1.0s 128 PASS
4 1±0.0s 1.0s 1.0s 1.0s 128 PASS
5 1±0.0s 1.0s 1.0s 1.0s 128 PASS
6 1±0.0s 1.0s 1.0s 1.0s 128 PASS
7 1±0.0s 1.0s 1.0s 1.0s 128 PASS
8 1±0.0s 1.0s 1.0s 1.0s 128 PASS
9 1±0.0s 1.0s 1.0s 1.0s 128 PASS
10 1±0.0s 1.0s 1.0s 1.0s 128 PASS
Elapsed: 12.9s
--- cloud (N=128) ---
dhcpcd.conf: timeout=12, nodelay, initial_interval=1, backoff_cutoff=1, backoff_jitter=100
PASS: 128/128 runs produced data
Retry Expected Min Avg Max N Result
------------------------------------------------------
Init 0 - - - 128 PASS
1 1±0.1s 0.9s 1.0s 1.1s 128 PASS
2 1±0.1s 0.9s 1.0s 1.1s 128 PASS
3 1±0.1s 0.9s 1.0s 1.1s 128 PASS
4 1±0.1s 0.9s 1.0s 1.1s 128 PASS
5 1±0.1s 0.9s 1.0s 1.1s 128 PASS
6 1±0.1s 0.9s 1.0s 1.1s 128 PASS
7 1±0.1s 0.9s 1.0s 1.1s 128 PASS
8 1±0.1s 0.9s 1.0s 1.1s 128 PASS
9 1±0.1s 0.9s 1.0s 1.1s 128 PASS
10 1±0.1s 0.9s 1.0s 1.1s 128 PASS
Elapsed: 13.0s
--- reject initial_interval=0 ---
dhcpcd.conf: initial_interval 0 (expect rejection)
PASS: dhcpcd rejected initial_interval 0 (exit=0)
output: invalid initial interval: 0
--- reject backoff_cutoff=0 ---
dhcpcd.conf: backoff_cutoff 0 (expect rejection)
PASS: dhcpcd rejected backoff_cutoff 0 (exit=0)
output: invalid backoff cutoff: 0
=============================================
All tests passed.
```
Signed-off-by: Chris Patterson <cpatterson@microsoft.com>1 parent 0edb765 commit de88396
File tree
7 files changed
+1007
-7
lines changed- src
- tests
- backoff
7 files changed
+1007
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1173 | 1173 | | |
1174 | 1174 | | |
1175 | 1175 | | |
1176 | | - | |
| 1176 | + | |
1177 | 1177 | | |
1178 | 1178 | | |
1179 | 1179 | | |
| |||
1864 | 1864 | | |
1865 | 1865 | | |
1866 | 1866 | | |
| 1867 | + | |
| 1868 | + | |
1867 | 1869 | | |
1868 | | - | |
| 1870 | + | |
1869 | 1871 | | |
| 1872 | + | |
| 1873 | + | |
1870 | 1874 | | |
1871 | | - | |
1872 | | - | |
| 1875 | + | |
| 1876 | + | |
1873 | 1877 | | |
| 1878 | + | |
1874 | 1879 | | |
1875 | | - | |
| 1880 | + | |
| 1881 | + | |
1876 | 1882 | | |
1877 | 1883 | | |
1878 | 1884 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
307 | 343 | | |
308 | 344 | | |
309 | 345 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
180 | 183 | | |
181 | 184 | | |
182 | 185 | | |
| |||
2580 | 2583 | | |
2581 | 2584 | | |
2582 | 2585 | | |
| 2586 | + | |
| 2587 | + | |
| 2588 | + | |
| 2589 | + | |
| 2590 | + | |
| 2591 | + | |
| 2592 | + | |
| 2593 | + | |
| 2594 | + | |
| 2595 | + | |
| 2596 | + | |
| 2597 | + | |
| 2598 | + | |
| 2599 | + | |
| 2600 | + | |
| 2601 | + | |
| 2602 | + | |
| 2603 | + | |
| 2604 | + | |
| 2605 | + | |
| 2606 | + | |
| 2607 | + | |
| 2608 | + | |
| 2609 | + | |
| 2610 | + | |
| 2611 | + | |
| 2612 | + | |
2583 | 2613 | | |
2584 | 2614 | | |
2585 | 2615 | | |
| |||
2667 | 2697 | | |
2668 | 2698 | | |
2669 | 2699 | | |
| 2700 | + | |
| 2701 | + | |
| 2702 | + | |
2670 | 2703 | | |
2671 | 2704 | | |
2672 | 2705 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
55 | 58 | | |
56 | 59 | | |
57 | 60 | | |
| |||
190 | 193 | | |
191 | 194 | | |
192 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
193 | 199 | | |
194 | 200 | | |
195 | 201 | | |
| |||
257 | 263 | | |
258 | 264 | | |
259 | 265 | | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
260 | 269 | | |
261 | 270 | | |
262 | 271 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
0 commit comments