Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: fix off-by-one in udp_flow_src_port() / psp_write_headers()

udp_flow_src_port() and psp_write_headers() use ip_local_port_range.

ip_local_port_range is inclusive : all ports between min and max
can be used.

Before this patch, if ip_local_port_range was set to 40000-40001
40001 would not be used as a source port.

Use reciprocal_scale() to help code readability.

Not tagged for stable trees, as this change could break user
expectations.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Willem de Bruijn <willemb@google.com>
Link: https://patch.msgid.link/20260302163933.1754393-1-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Eric Dumazet and committed by
Jakub Kicinski
c26b8c4e 98d95000

+3 -2
+2 -1
include/net/udp.h
··· 29 29 #include <linux/seq_file.h> 30 30 #include <linux/poll.h> 31 31 #include <linux/indirect_call_wrapper.h> 32 + #include <linux/math.h> 32 33 33 34 /** 34 35 * struct udp_skb_cb - UDP(-Lite) private variables ··· 377 376 */ 378 377 hash ^= hash << 16; 379 378 380 - return htons((((u64) hash * (max - min)) >> 32) + min); 379 + return htons(reciprocal_scale(hash, max - min + 1) + min); 381 380 } 382 381 383 382 static inline int udp_rqueue_get(struct sock *sk)
+1 -1
net/psp/psp_main.c
··· 202 202 * reciprocal divide. 203 203 */ 204 204 hash ^= hash << 16; 205 - uh->source = htons((((u64)hash * (max - min)) >> 32) + min); 205 + uh->source = htons(reciprocal_scale(hash, max - min + 1) + min); 206 206 } else { 207 207 uh->source = udp_flow_src_port(net, skb, 0, 0, false); 208 208 }