git: 3535546a8684 - main - udp: honor IPV6_TCLASS socket option for UDP/IPv4 packets

From: Michael Tuexen <tuexen_at_FreeBSD.org>
Date: Sun, 26 Oct 2025 17:55:41 UTC
The branch main has been updated by tuexen:

URL: https://cgit.FreeBSD.org/src/commit/?id=3535546a86846ddb0ca5fe4a0689ac635b504459

commit 3535546a86846ddb0ca5fe4a0689ac635b504459
Author:     Michael Tuexen <tuexen@FreeBSD.org>
AuthorDate: 2025-10-26 17:52:33 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2025-10-26 17:52:33 +0000

    udp: honor IPV6_TCLASS socket option for UDP/IPv4 packets
    
    Honor the IPPROTO_IPV6-level socket option IPV6_TCLASS when sending
    an UDP/IPv4 packet on an AF_INET6 socket.
    
    Reviewed by:            bz, glebius
    MFC after:              3 days
    Sponsored by:           Netflix, Inc.
    Differential Revision:  https://reviews.freebsd.org/D53346
---
 sys/netinet/udp_usrreq.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c
index 04d01099d54a..6ce1bcce6fc6 100644
--- a/sys/netinet/udp_usrreq.c
+++ b/sys/netinet/udp_usrreq.c
@@ -1172,7 +1172,19 @@ udp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
 	else
 		INP_RLOCK(inp);
 	NET_EPOCH_ENTER(et);
+#ifdef INET6
+	if ((flags & PRUS_IPV6) != 0) {
+		if ((inp->in6p_outputopts != NULL) &&
+		    (inp->in6p_outputopts->ip6po_tclass != -1))
+			tos = (u_char)inp->in6p_outputopts->ip6po_tclass;
+		else
+			tos = 0;
+	} else {
+		tos = inp->inp_ip_tos;
+	}
+#else
 	tos = inp->inp_ip_tos;
+#endif
 	if (control != NULL) {
 		/*
 		 * XXX: Currently, we assume all the optional information is