git: 434994d73c5e - stable/15 - sctp: improve handling of SO_SETFIB socket option

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

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

commit 434994d73c5e9628fb777518e4b63045e0620d9b
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 06:51:06 +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 7c615b4cd02c..9352fcaff506 100644
--- a/sys/netinet/sctp_usrreq.c
+++ b/sys/netinet/sctp_usrreq.c
@@ -6869,15 +6869,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 */