Skip to contentSkip to conversation

udp6: allow SO_MARK ctrl msg to affect routing

PATCH Applied Jakub Kicinski 4 participants 8 messages Oct 29, 2021 – Nov 1, 2021

Subsystems (4)
lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

cover udp6: allow SO_MARK ctrl msg to affect routing

Hi!

Looks like SO_MARK from cmsg does not affect routing policy. This seems accidental.

I opted for net because of the discrepancy between IPv4 and IPv6, but it never worked and doesn't cause crashes..

Jakub Kicinski (2):
udp6: allow SO_MARK ctrl msg to affect routing
selftests: udp: test for passing SO_MARK as cmsg

 net/ipv6/udp.c                              |  2 +-
 tools/testing/selftests/net/.gitignore      |  1 +
 tools/testing/selftests/net/Makefile        |  2 +
 tools/testing/selftests/net/cmsg_so_mark.c  | 67 +++++++++++++++++++++
 tools/testing/selftests/net/cmsg_so_mark.sh | 61 +++++++++++++++++++
 5 files changed, 132 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/net/cmsg_so_mark.c
 create mode 100755 tools/testing/selftests/net/cmsg_so_mark.sh

base-commit: 6de6e46d27ef386feecdbea56b3bfd6c3b3bc1f9

Signature · 1 line
2.31.1
author maintainer
#1 lore raw

PATCH 1/2 udp6: allow SO_MARK ctrl msg to affect routing

Commit c6af0c227a22 ("ip: support SO_MARK cmsg") added propagation of SO_MARK from cmsg to skb->mark. For IPv4 and raw sockets the mark also affects route lookup, but in case of IPv6 the flow info is initialized before cmsg is parsed.

Fixes c6af0c227a22 ("ip: support SO_MARK cmsg")
Reported-and-tested-by Xintong Hu <[email protected]>
---
 net/ipv6/udp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/udp.c +1 -1
index 8d785232b479..be6dc64ece29 100644
@@ -1435,7 +1435,6 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 	if (!fl6.flowi6_oif)
 		fl6.flowi6_oif = np->sticky_pktinfo.ipi6_ifindex;
 
-	fl6.flowi6_mark = ipc6.sockc.mark;
 	fl6.flowi6_uid = sk->sk_uid;
 
 	if (msg->msg_controllen) {
@@ -1471,6 +1470,7 @@ int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, size_t len)
 	ipc6.opt = opt;
 
 	fl6.flowi6_proto = sk->sk_protocol;
+	fl6.flowi6_mark = ipc6.sockc.mark;
 	fl6.daddr = *daddr;
 	if (ipv6_addr_any(&fl6.saddr) && !ipv6_addr_any(&np->saddr))
 		fl6.saddr = np->saddr;
Signature · 1 line
2.31.1
Reviewed-by on v1 1/2
#2 lore raw
Quoted 6 lines · Jakub Kicinski

Commit c6af0c227a22 ("ip: support SO_MARK cmsg") added propagation of SO_MARK from cmsg to skb->mark. For IPv4 and raw sockets the mark also affects route lookup, but in case of IPv6 the flow info is initialized before cmsg is parsed.

Quoted 7 lines
Fixes c6af0c227a22 ("ip: support SO_MARK cmsg")
Reported-and-tested-by Xintong Hu <[email protected]>
---
 net/ipv6/udp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
maintainer Reviewed-by
#3 lore raw
Quoted 16 lines · David Ahern
Quoted 6 lines · Jakub Kicinski

Commit c6af0c227a22 ("ip: support SO_MARK cmsg") added propagation of SO_MARK from cmsg to skb->mark. For IPv4 and raw sockets the mark also affects route lookup, but in case of IPv6 the flow info is initialized before cmsg is parsed.

Quoted 7 lines
Fixes c6af0c227a22 ("ip: support SO_MARK cmsg")
Reported-and-tested-by Xintong Hu <[email protected]>
---
 net/ipv6/udp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 1 line

Thanks!

author maintainer
#4 lore raw

PATCH 2/2 selftests: udp: test for passing SO_MARK as cmsg

In reply to Jakub Kicinski

Before fix:
| Case IPv6 rejection returned 0, expected 1
|FAIL - 1/4 cases failed

With the fix:
| OK

--
CC: [email protected]
CC: [email protected]

---
 tools/testing/selftests/net/.gitignore      |  1 +
 tools/testing/selftests/net/Makefile        |  2 +
 tools/testing/selftests/net/cmsg_so_mark.c  | 67 +++++++++++++++++++++
 tools/testing/selftests/net/cmsg_so_mark.sh | 61 +++++++++++++++++++
 4 files changed, 131 insertions(+)
 create mode 100644 tools/testing/selftests/net/cmsg_so_mark.c
 create mode 100755 tools/testing/selftests/net/cmsg_so_mark.sh
tools/testing/selftests/net/.gitignore +1 -0
index 501550501216..7581a7348e1b 100644
@@ -35,3 +35,4 @@ test_unix_oob
 gro
 ioam6_parser
 toeplitz
+cmsg_so_mark
tools/testing/selftests/net/Makefile +2 -0
index 492b273743b4..f56b652d5cc6 100644
@@ -28,6 +28,7 @@ TEST_PROGS += veth.sh
 TEST_PROGS += ioam6.sh
 TEST_PROGS += gro.sh
 TEST_PROGS += gre_gso.sh
+TEST_PROGS += cmsg_so_mark.sh
 TEST_PROGS_EXTENDED := in_netns.sh
 TEST_GEN_FILES =  socket nettest
 TEST_GEN_FILES += psock_fanout psock_tpacket msg_zerocopy reuseport_addr_any
@@ -44,6 +45,7 @@ TEST_GEN_FILES += gro
 TEST_GEN_PROGS = reuseport_bpf reuseport_bpf_cpu reuseport_bpf_numa
 TEST_GEN_PROGS += reuseport_dualstack reuseaddr_conflict tls
 TEST_GEN_FILES += toeplitz
+TEST_GEN_FILES += cmsg_so_mark
 
 TEST_FILES := settings
 
tools/testing/selftests/net/cmsg_so_mark.c new file +67 -0

67 lines not on this page · raw message

tools/testing/selftests/net/cmsg_so_mark.sh new file +61 -0

61 lines not on this page · raw message

Signature · 1 line
2.31.1
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH net 2/2] selftests: udp: test for passing SO_MARK as cmsg

Quoted 11 lines · Jakub Kicinski

Before fix:
| Case IPv6 rejection returned 0, expected 1
|FAIL - 1/4 cases failed

With the fix:
| OK

--
CC: [email protected]
CC: [email protected]

Quoted 9 lines
---
 tools/testing/selftests/net/.gitignore      |  1 +
 tools/testing/selftests/net/Makefile        |  2 +
 tools/testing/selftests/net/cmsg_so_mark.c  | 67 +++++++++++++++++++++
 tools/testing/selftests/net/cmsg_so_mark.sh | 61 +++++++++++++++++++
 4 files changed, 131 insertions(+)
 create mode 100644 tools/testing/selftests/net/cmsg_so_mark.c
 create mode 100755 tools/testing/selftests/net/cmsg_so_mark.sh
maintainer Reviewed-by
#6 lore raw

Re: [PATCH net 2/2] selftests: udp: test for passing SO_MARK as cmsg

Quoted 22 lines · David Ahern
Quoted 11 lines · Jakub Kicinski

Before fix:
| Case IPv6 rejection returned 0, expected 1
|FAIL - 1/4 cases failed

With the fix:
| OK

--
CC: [email protected]
CC: [email protected]

Quoted 9 lines
---
 tools/testing/selftests/net/.gitignore      |  1 +
 tools/testing/selftests/net/Makefile        |  2 +
 tools/testing/selftests/net/cmsg_so_mark.c  | 67 +++++++++++++++++++++
 tools/testing/selftests/net/cmsg_so_mark.sh | 61 +++++++++++++++++++
 4 files changed, 131 insertions(+)
 create mode 100644 tools/testing/selftests/net/cmsg_so_mark.c
 create mode 100755 tools/testing/selftests/net/cmsg_so_mark.sh
Quoted 1 line
#7 lore raw
In reply to Jakub Kicinski
This series was applied to netdev/net.git (master) by David S. Miller <[email protected]>:

Hello:

This series was applied to netdev/net.git (master) by David S. Miller <[email protected]>:

Quoted 9 lines · On Fri, 29 Oct 2021 08:51:33 -0700 you wrote:

Hi!

Looks like SO_MARK from cmsg does not affect routing policy. This seems accidental.

I opted for net because of the discrepancy between IPv4 and IPv6, but it never worked and doesn't cause crashes..

[...]

Here is the summary with links:
- [net,1/2] udp6: allow SO_MARK ctrl msg to affect routing

    https://git.kernel.org/netdev/net/c/42dcfd850e51
  - [net,2/2] selftests: udp: test for passing SO_MARK as cmsg
    https://git.kernel.org/netdev/net/c/b0ced8f290fb

You are awesome, thank you!

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