Skip to contentSkip to conversation

udp: don't be set unconnected if only UDP cmsg

PATCH In review Yick Xie 4 participants 7 messages Apr 16, 2024 – Apr 20, 2024

Subsystems (4)
lore
Share & tools
lore

Yick Xie

author
#0 lore raw

PATCH v2 1/1 udp: don't be set unconnected if only UDP cmsg

If "udp_cmsg_send()" returned 0 (i.e. only UDP cmsg), "connected" should not be set to 0. Otherwise it stops the connected socket from using the cached route.

Fixes 2e8de8576343 ("udp: add gso segment cmsg")

---
v2: Add Fixes tag
v1: https://lore.kernel.org/netdev/[email protected]/

---
 net/ipv4/udp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/ipv4/udp.c +3 -2
index c02bf011d4a6..420905be5f30 100644
@@ -1123,16 +1123,17 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 
 	if (msg->msg_controllen) {
 		err = udp_cmsg_send(sk, msg, &ipc.gso_size);
-		if (err > 0)
+		if (err > 0) {
 			err = ip_cmsg_send(sk, msg, &ipc,
 					   sk->sk_family == AF_INET6);
+			connected = 0;
+		}
 		if (unlikely(err < 0)) {
 			kfree(ipc.opt);
 			return err;
 		}
 		if (ipc.opt)
 			free = 1;
-		connected = 0;
 	}
 	if (!ipc.opt) {
 		struct ip_options_rcu *inet_opt;
Signature · 1 line
2.34.1
maintainer
#2 lore raw
In reply to Yick Xie

Hi,

Quoted 7 lines · Yick Xie

If "udp_cmsg_send()" returned 0 (i.e. only UDP cmsg), "connected" should not be set to 0. Otherwise it stops the connected socket from using the cached route.

Fixes 2e8de8576343 ("udp: add gso segment cmsg")

Minor: the patch subj is IMHO a bit confusing, what about removing the double negation?

preserve connect status with UDP-only cmsg

net/ipv4/udp.c

Quoted 11 lines

---
v2: Add Fixes tag
v1: https://lore.kernel.org/netdev/[email protected]/

---
 net/ipv4/udp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/ipv4/udp.c +0 -0
index c02bf011d4a6..420905be5f30 100644

What about ipv6? why this fix does not apply there, too?

Thanks!

Paolo

maintainer
#3 lore raw
Quoted 23 lines · Paolo Abeni

Hi,

Quoted 7 lines · Yick Xie

If "udp_cmsg_send()" returned 0 (i.e. only UDP cmsg), "connected" should not be set to 0. Otherwise it stops the connected socket from using the cached route.

Fixes 2e8de8576343 ("udp: add gso segment cmsg")

Minor: the patch subj is IMHO a bit confusing, what about removing the double negation?

preserve connect status with UDP-only cmsg

Quoted 7 lines

---
v2: Add Fixes tag
v1: https://lore.kernel.org/netdev/[email protected]/

---
 net/ipv4/udp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 6 lines

net/ipv4/udp.c

Quoted 4 lines
net/ipv4/udp.c +0 -0
index c02bf011d4a6..420905be5f30 100644

What about ipv6? why this fix does not apply there, too?

Oops. Thanks Paolo. Yes, this definitely also applies to ipv6.

author
#4 lore raw

PATCH v3 1/1 udp: preserve the connected status if only UDP cmsg

If "udp_cmsg_send()" returned 0 (i.e. only UDP cmsg), "connected" should not be set to 0. Otherwise it stops the connected socket from using the cached route.

Fixes 2e8de8576343 ("udp: add gso segment cmsg")

---
v3: Fix the IPV6 counterpart and revise the subject
v2: Add Fixes tag
v1: https://lore.kernel.org/netdev/[email protected]/

---
 net/ipv4/udp.c | 5 +++--
 net/ipv6/udp.c | 5 +++--
 2 files changed, 6 insertions(+), 4 deletions(-)
net/ipv4/udp.c +3 -2
index c02bf011d4a6..420905be5f30 100644
@@ -1123,16 +1123,17 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 
 	if (msg->msg_controllen) {
 		err = udp_cmsg_send(sk, msg, &ipc.gso_size);
-		if (err > 0)
+		if (err > 0) {
 			err = ip_cmsg_send(sk, msg, &ipc,
 					   sk->sk_family == AF_INET6);
+			connected = 0;
+		}
 		if (unlikely(err < 0)) {
 			kfree(ipc.opt);
 			return err;
 		}
 		if (ipc.opt)
 			free = 1;
-		connected = 0;
 	}
 	if (!ipc.opt) {
 		struct ip_options_rcu *inet_opt;
net/ipv6/udp.c +3 -2
index 8b1dd7f51249..1a4cccdd40c9 100644
@@ -1474,9 +1474,11 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 		ipc6.opt = opt;
 
 		err = udp_cmsg_send(sk, msg, &ipc6.gso_size);
-		if (err > 0)
+		if (err > 0) {
 			err = ip6_datagram_send_ctl(sock_net(sk), sk, msg, fl6,
 						    &ipc6);
+			connected = false;
+		}
 		if (err < 0) {
 			fl6_sock_release(flowlabel);
 			return err;
@@ -1488,7 +1490,6 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 		}
 		if (!(opt->opt_nflen|opt->opt_flen))
 			opt = NULL;
-		connected = false;
 	}
 	if (!opt) {
 		opt = txopt_get(np);
Signature · 1 line
2.34.1
maintainer Reviewed-by on v3 1/1
#5 lore raw

Re: [PATCH net v3] udp: preserve the connected status if only UDP cmsg

Quoted 7 lines · Yick Xie

If "udp_cmsg_send()" returned 0 (i.e. only UDP cmsg), "connected" should not be set to 0. Otherwise it stops the connected socket from using the cached route.

Fixes 2e8de8576343 ("udp: add gso segment cmsg")
#6 lore raw

Re: [PATCH net v3] udp: preserve the connected status if only UDP cmsg

In reply to Yick Xie
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Fri, 19 Apr 2024 01:06:10 +0800 you wrote:

If "udp_cmsg_send()" returned 0 (i.e. only UDP cmsg), "connected" should not be set to 0. Otherwise it stops the connected socket from using the cached route.

Fixes 2e8de8576343 ("udp: add gso segment cmsg")

[...]

Here is the summary with links:
- [net,v3] udp: preserve the connected status if only UDP cmsg

    https://git.kernel.org/netdev/net/c/680d11f6e542

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html