git: a4925f0f8cf7 - stable/14 - udplite: make socketoption available on IPv6 sockets

From: Ed Maste <emaste_at_FreeBSD.org>
Date: Thu, 11 Jan 2024 01:23:12 UTC
The branch stable/14 has been updated by emaste:

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

commit a4925f0f8cf76c32140d7c2077aa9628de20630f
Author:     Michael Tuexen <tuexen@FreeBSD.org>
AuthorDate: 2023-11-05 14:28:54 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2024-01-11 01:22:52 +0000

    udplite: make socketoption available on IPv6 sockets
    
    This patch allows the IPPROTO_UDPLITE-level socket options
    UDPLITE_SEND_CSCOV and UDPLITE_RECV_CSCOV to be used on
    AF_INET6 sockets in addition to AF_INET sockets.
    
    Reviewed by:            ae, rscheff
    MFC after:              1 week
    Differential Revision:  https://reviews.freebsd.org/D42430
    
    (cherry picked from commit 03c3a70abe5e9fa259b954de78ae69229fa9c99f)
---
 sys/netinet/udp_usrreq.c   | 8 ++++++++
 sys/netinet6/udp6_usrreq.c | 2 +-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c
index 4ea0efad3491..7329600ecc79 100644
--- a/sys/netinet/udp_usrreq.c
+++ b/sys/netinet/udp_usrreq.c
@@ -897,6 +897,10 @@ udp_ctloutput(struct socket *so, struct sockopt *sopt)
 #if defined(IPSEC) || defined(IPSEC_SUPPORT)
 #ifdef INET
 		case UDP_ENCAP:
+			if (!INP_CHECK_SOCKAF(so, AF_INET)) {
+				INP_WUNLOCK(inp);
+				return (EINVAL);
+			}
 			if (!IPSEC_ENABLED(ipv4)) {
 				INP_WUNLOCK(inp);
 				return (ENOPROTOOPT);
@@ -944,6 +948,10 @@ udp_ctloutput(struct socket *so, struct sockopt *sopt)
 #if defined(IPSEC) || defined(IPSEC_SUPPORT)
 #ifdef INET
 		case UDP_ENCAP:
+			if (!INP_CHECK_SOCKAF(so, AF_INET)) {
+				INP_WUNLOCK(inp);
+				return (EINVAL);
+			}
 			if (!IPSEC_ENABLED(ipv4)) {
 				INP_WUNLOCK(inp);
 				return (ENOPROTOOPT);
diff --git a/sys/netinet6/udp6_usrreq.c b/sys/netinet6/udp6_usrreq.c
index 35d68e164145..c8b38c24d193 100644
--- a/sys/netinet6/udp6_usrreq.c
+++ b/sys/netinet6/udp6_usrreq.c
@@ -1243,7 +1243,7 @@ udp6_disconnect(struct socket *so)
 #define	UDP6_PROTOSW							\
 	.pr_type =		SOCK_DGRAM,				\
 	.pr_flags =		PR_ATOMIC|PR_ADDR|PR_CAPATTACH,		\
-	.pr_ctloutput =		ip6_ctloutput,				\
+	.pr_ctloutput =		udp_ctloutput,				\
 	.pr_abort =		udp6_abort,				\
 	.pr_attach =		udp6_attach,				\
 	.pr_bind =		udp6_bind,				\