Skip to contentSkip to conversation

udp: compute_score and sk_bound_dev_if regression

PATCH In review Peter Kosyh 2 participants 2 messages Jun 9, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 udp: compute_score and sk_bound_dev_if regression

udp: commit 6da5b0f027a825df2aebc1927a27bda185dc03d4
introduced regression in compute_score() Previously for addr_any sockets an interface bound socket had a higher priority than an unbound socket that seems right. For example, this feature is used in dhcprelay daemon and now it is broken.
So, this patch returns the old behavior and gives higher score for sk_bound_dev_if sockets.

---
 net/ipv4/udp.c | 3 ++-
 net/ipv6/udp.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
net/ipv4/udp.c +2 -1
index 15f5504adf5b..4239ffa93c6f 100644
@@ -390,7 +390,8 @@ static int compute_score(struct sock *sk, struct net *net,
 					dif, sdif);
 	if (!dev_match)
 		return -1;
-	score += 4;
+	if (sk->sk_bound_dev_if)
+		score += 4;
 
 	if (READ_ONCE(sk->sk_incoming_cpu) == raw_smp_processor_id())
 		score++;
net/ipv6/udp.c +2 -1
index 199b080d418a..c2f88b5def25 100644
@@ -133,7 +133,8 @@ static int compute_score(struct sock *sk, struct net *net,
 	dev_match = udp_sk_bound_dev_eq(net, sk->sk_bound_dev_if, dif, sdif);
 	if (!dev_match)
 		return -1;
-	score++;
+	if (sk->sk_bound_dev_if)
+		score++;
 
 	if (READ_ONCE(sk->sk_incoming_cpu) == raw_smp_processor_id())
 		score++;

--
2.31.1

maintainer
#1 lore raw
Quoted 3 lines · Peter Kosyh

udp: commit 6da5b0f027a825df2aebc1927a27bda185dc03d4

For completeness, this is commit 6da5b0f027a8 ("net: ensure unbound datagram socket to be chosen when not in a VRF"). Adding the author.

Quoted 42 lines

introduced regression in compute_score() Previously for addr_any sockets an interface bound socket had a higher priority than an unbound socket that seems right. For example, this feature is used in dhcprelay daemon and now it is broken.
So, this patch returns the old behavior and gives higher score for sk_bound_dev_if sockets.

---
 net/ipv4/udp.c | 3 ++-
 net/ipv6/udp.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
net/ipv4/udp.c +2 -1
index 15f5504adf5b..4239ffa93c6f 100644
@@ -390,7 +390,8 @@ static int compute_score(struct sock *sk, struct net *net,
                                        dif, sdif);
        if (!dev_match)
                return -1;
-       score += 4;
+       if (sk->sk_bound_dev_if)
+               score += 4;
 
        if (READ_ONCE(sk->sk_incoming_cpu) == raw_smp_processor_id())
                score++;
net/ipv6/udp.c +2 -2
index 199b080d418a..c2f88b5def25 100644
@@ -133,7 +133,8 @@ static int compute_score(struct sock *sk, struct net *net,
        dev_match = udp_sk_bound_dev_eq(net, sk->sk_bound_dev_if, dif, sdif);
        if (!dev_match)
                return -1;
-       score++;
+       if (sk->sk_bound_dev_if)
+               score++;
 
        if (READ_ONCE(sk->sk_incoming_cpu) == raw_smp_processor_id())
                score++;
--

2.31.1