summaryrefslogtreecommitdiff
path: root/net/core
diff options
context:
space:
mode:
authorBrian Haley <haleyb.dev@gmail.com>2023-01-30 12:14:28 -0500
committerJakub Kicinski <kuba@kernel.org>2023-02-01 21:02:54 -0800
commit62e395f82d04510b0f86e5e603e29412be88596f (patch)
tree0389f920c74480c2b9d32661450987891fa7f979 /net/core
parent983f507c3043e90b2c6429cd67903c4ca8208b5c (diff)
downloadlinux-rpi-62e395f82d04510b0f86e5e603e29412be88596f.tar.gz
linux-rpi-62e395f82d04510b0f86e5e603e29412be88596f.tar.bz2
linux-rpi-62e395f82d04510b0f86e5e603e29412be88596f.zip
neighbor: fix proxy_delay usage when it is zero
When set to zero, the neighbor sysctl proxy_delay value does not cause an immediate reply for ARP/ND requests as expected, it instead causes a random delay between [0, U32_MAX). Looking at this comment from __get_random_u32_below() explains the reason: /* * This function is technically undefined for ceil == 0, and in fact * for the non-underscored constant version in the header, we build bug * on that. But for the non-constant case, it's convenient to have that * evaluate to being a straight call to get_random_u32(), so that * get_random_u32_inclusive() can work over its whole range without * undefined behavior. */ Added helper function that does not call get_random_u32_below() if proxy_delay is zero and just uses the current value of jiffies instead, causing pneigh_enqueue() to respond immediately. Also added definition of proxy_delay to ip-sysctl.txt since it was missing. Signed-off-by: Brian Haley <haleyb.dev@gmail.com> Link: https://lore.kernel.org/r/20230130171428.367111-1-haleyb.dev@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'net/core')
-rw-r--r--net/core/neighbour.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index f00a79fc301b..57258110bccd 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -1662,11 +1662,21 @@ static void neigh_proxy_process(struct timer_list *t)
spin_unlock(&tbl->proxy_queue.lock);
}
+static unsigned long neigh_proxy_delay(struct neigh_parms *p)
+{
+ /* If proxy_delay is zero, do not call get_random_u32_below()
+ * as it is undefined behavior.
+ */
+ unsigned long proxy_delay = NEIGH_VAR(p, PROXY_DELAY);
+
+ return proxy_delay ?
+ jiffies + get_random_u32_below(proxy_delay) : jiffies;
+}
+
void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p,
struct sk_buff *skb)
{
- unsigned long sched_next = jiffies +
- get_random_u32_below(NEIGH_VAR(p, PROXY_DELAY));
+ unsigned long sched_next = neigh_proxy_delay(p);
if (p->qlen > NEIGH_VAR(p, PROXY_QLEN)) {
kfree_skb(skb);