git: 5ad9c6b31504 - stable/14 - sctp: improve handling of SO_SETFIB socket option

From: Michael Tuexen <tuexen_at_FreeBSD.org>
Date: Thu, 29 Oct 2026 06:59:42 UTC
The branch stable/14 has been updated by tuexen:

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

commit 5ad9c6b31504160a487756ba8b7620192da56571
Author:     Albin Hellqvist <albin.hellqvist@ericsson.com>
AuthorDate: 2026-10-26 19:07:03 +0000
Commit:     Michael Tuexen <tuexen@FreeBSD.org>
CommitDate: 2026-10-29 05:54:19 +0000

    sctp: improve handling of SO_SETFIB socket option
    
    Since SCTP keeps fibnum in the SCTP protocol control block,
    the code can't just defer the processing to the IPv4 or IPv6
    layer. Therefore it needs to be implemented in the the SCTP
    layer and it needs to call the socket layer function.
    
    PR:             300091
    Reviewed by:    tuexen
    Fixes:          caccbaef8e26 ("socket: Move SO_SETFIB handling to protocol layers")
    
    (cherry picked from commit 7b8151b0cd1b4f077b382b6be2c02c936d1988fa)
---
 sys/netinet/sctp_usrreq.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/sys/netinet/sctp_usrreq.c b/sys/netinet/sctp_usrreq.c
index 1d062144d322..fe5310f48d8d 100644
--- a/sys/netinet/sctp_usrreq.c
+++ b/sys/netinet/sctp_usrreq.c
@@ -6875,15 +6875,23 @@ sctp_ctloutput(struct socket *so, struct sockopt *sopt)
 
 	if ((sopt->sopt_level == SOL_SOCKET) &&
 	    (sopt->sopt_name == SO_SETFIB)) {
+		int optval;
+
+		error = sooptcopyin(sopt, &optval, sizeof(optval),
+		    sizeof(optval));
+		if (error != 0)
+			return (error);
 		inp = (struct sctp_inpcb *)so->so_pcb;
 		if (inp == NULL) {
 			SCTP_LTRACE_ERR_RET(so->so_pcb, NULL, NULL, SCTP_FROM_SCTP_USRREQ, ENOBUFS);
 			return (EINVAL);
 		}
 		SCTP_INP_WLOCK(inp);
-		inp->fibnum = so->so_fibnum;
+		error = sosetfib(so, optval);
+		if (error == 0)
+			inp->fibnum = optval;
 		SCTP_INP_WUNLOCK(inp);
-		return (0);
+		return (error);
 	}
 	if (sopt->sopt_level != IPPROTO_SCTP) {
 		/* wrong proto level... send back up to IP */