diff options
author | Boris Lytochkin <lytboris@gmail.com> | 2024-02-19 07:44:52 +0000 |
---|---|---|
committer | Andrey V. Elsukov <ae@FreeBSD.org> | 2024-02-19 07:44:52 +0000 |
commit | 03cc3489a02da0eba3b2737210486723d1072b21 (patch) | |
tree | c2604f2451761cc056842f764b1e75e56d11d6ee /usr.sbin/ndp | |
parent | a6cef617660a424fcaa8343787f96d0ae720a284 (diff) | |
download | src-03cc3489a02da0eba3b2737210486723d1072b21.tar.gz src-03cc3489a02da0eba3b2737210486723d1072b21.zip |
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
Diffstat (limited to 'usr.sbin/ndp')
-rw-r--r-- | usr.sbin/ndp/ndp.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/usr.sbin/ndp/ndp.c b/usr.sbin/ndp/ndp.c index 9ade2469742e..9d9ae02dc1e2 100644 --- a/usr.sbin/ndp/ndp.c +++ b/usr.sbin/ndp/ndp.c @@ -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) |