diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index f437d9d..5d17c71 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -219,7 +219,9 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum, first = (((u64)rand * remaining) >> 32) + low; } else { rand = 1; - first = hint; + first = hint + smp_processor_id(); + if (first > high) + first = low + (first - low) % remaining; } /* * force rand to be an odd multiple of UDP_HTABLE_SIZE @@ -243,8 +245,12 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum, do { if (low <= snum && snum <= high && !test_bit(snum >> udptable->log, bitmap)) { - if (unlikely(!sysctl_udp_port_randomization)) - hint = snum; + if (unlikely(!sysctl_udp_port_randomization)) { + int cur_hint = snum - smp_processor_id(); + if (cur_hint < low) + cur_hint = high - (low - cur_hint) % remaining; + hint = cur_hint; + } goto found; } snum += rand;