neighbor: fix proxy_delay usage when it is zero
Subsystems (3)
PATCH v2 1/1 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.
--- Documentation/networking/ip-sysctl.rst | 8 ++++++++ net/core/neighbour.c | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-)
Documentation/networking/ip-sysctl.rst +8 -0
@@ -1589,6 +1589,14 @@ proxy_arp_pvlan - BOOLEAN Hewlett-Packard call it Source-Port filtering or port-isolation. Ericsson call it MAC-Forced Forwarding (RFC Draft). +proxy_delay - INTEGER + Delay proxy response. + + Delay response to a neighbor solicitation when proxy_arp + or proxy_ndp is enabled. A random value between [0, proxy_delay] + will be chosen, setting to zero means reply with no delay. + Value in jiffies. Defaults to 80. + shared_media - BOOLEAN Send(router) or accept(host) RFC1620 shared media redirects. Overrides secure_redirects.
net/core/neighbour.c +12 -2
@@ -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);
Signature · 1 line
2.34.1
Jakub Kicinski
maintainerDocumentation/networking/ip-sysctl.rst proxy_arp_pvlan - BOOLEAN · line 1596
Quoted 1 line · On Wed, 25 Jan 2023 14:51:14 -0500 Brian Haley wrote:
Documentation/networking/ip-sysctl.rst +1
-0+ or proxy_ndp is enabled. A random value between [0, proxy_delay]
Do you mean: [0, proxy_delay) or there's something that can give us an extra jiffy (IOW shouldn't the upper limit be open) ?
it's
random() % MAX - (1 - noise)
where (1 - noise) is the fraction of jiffy which already passed since the tick.
Sorry if I'm slow to get it..
Quoted 6 lines · Jakub Kicinski
Documentation/networking/ip-sysctl.rst proxy_arp_pvlan - BOOLEAN · line 1596
Quoted 1 line · On Wed, 25 Jan 2023 14:51:14 -0500 Brian Haley wrote:
Documentation/networking/ip-sysctl.rst +1
-0+ or proxy_ndp is enabled. A random value between [0, proxy_delay]Do you mean: [0,
proxy_delay) or there's something that can give us an extra jiffy (IOW shouldn't the upper limit be open) ?
Quoted 7 lines
it's
random()% MAX - (1 - noise)where (1 - noise) is the fraction of jiffy which already passed since the tick.
Sorry if I'm slow to get it..
Yes, it's [0, proxy_delay), should have just copied that right from the get_random_u32_below() definition. I'll send a v3 fixing the commit message and sysctl doc.
-Brian