ndp(8): increase buffer size in rtsock mode

On a router with many connected devices (~10k+) `ndp -an` can fail
with ENOMEM because of some additional NDP records were added
between sysctl() buffer size estimate and data fetch calls.

Allocate more space based on size estimate: 1/64 (~2%) of additional
space, but not less that 4 m_rtmsg structures.

Obtained from:	Yandex LLC
MFC after:	2 weeks
Sponsored by:	Yandex LLC
Differential Revision:	https://reviews.freebsd.org/D43956
This commit is contained in:
Boris Lytochkin 2024-02-19 10:44:52 +03:00 committed by Andrey V. Elsukov
parent a6cef61766
commit 03cc3489a0

View file

@ -652,6 +652,12 @@ again:;
if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
xo_err(1, "sysctl(PF_ROUTE estimate)");
if (needed > 0) {
/*
* Add ~2% additional space in case some records
* will appear between sysctl() calls.
* Round it up so it can fit 4 additional messages at least.
*/
needed += ((needed >> 6) | (sizeof(m_rtmsg) * 4));
if ((buf = malloc(needed)) == NULL)
xo_err(1, "malloc");
if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0)