Skip to content

Commit 62e395f

Browse files
brianphaleykuba-moo
authored andcommitted
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>
1 parent 983f507 commit 62e395f

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

Documentation/networking/ip-sysctl.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,14 @@ proxy_arp_pvlan - BOOLEAN
15921592
Hewlett-Packard call it Source-Port filtering or port-isolation.
15931593
Ericsson call it MAC-Forced Forwarding (RFC Draft).
15941594

1595+
proxy_delay - INTEGER
1596+
Delay proxy response.
1597+
1598+
Delay response to a neighbor solicitation when proxy_arp
1599+
or proxy_ndp is enabled. A random value between [0, proxy_delay)
1600+
will be chosen, setting to zero means reply with no delay.
1601+
Value in jiffies. Defaults to 80.
1602+
15951603
shared_media - BOOLEAN
15961604
Send(router) or accept(host) RFC1620 shared media redirects.
15971605
Overrides secure_redirects.

net/core/neighbour.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,11 +1662,21 @@ static void neigh_proxy_process(struct timer_list *t)
16621662
spin_unlock(&tbl->proxy_queue.lock);
16631663
}
16641664

1665+
static unsigned long neigh_proxy_delay(struct neigh_parms *p)
1666+
{
1667+
/* If proxy_delay is zero, do not call get_random_u32_below()
1668+
* as it is undefined behavior.
1669+
*/
1670+
unsigned long proxy_delay = NEIGH_VAR(p, PROXY_DELAY);
1671+
1672+
return proxy_delay ?
1673+
jiffies + get_random_u32_below(proxy_delay) : jiffies;
1674+
}
1675+
16651676
void pneigh_enqueue(struct neigh_table *tbl, struct neigh_parms *p,
16661677
struct sk_buff *skb)
16671678
{
1668-
unsigned long sched_next = jiffies +
1669-
get_random_u32_below(NEIGH_VAR(p, PROXY_DELAY));
1679+
unsigned long sched_next = neigh_proxy_delay(p);
16701680

16711681
if (p->qlen > NEIGH_VAR(p, PROXY_QLEN)) {
16721682
kfree_skb(skb);

0 commit comments

Comments
 (0)