git: b0f2df45e7a6 - stable/14 - socket: Add an option to retrieve a socket's FIB number
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 21 Feb 2025 01:57:23 UTC
The branch stable/14 has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=b0f2df45e7a6f1db28bd96fc5da690618a0c38a6
commit b0f2df45e7a6f1db28bd96fc5da690618a0c38a6
Author: Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2025-02-06 14:17:19 +0000
Commit: Mark Johnston <markj@FreeBSD.org>
CommitDate: 2025-02-21 01:04:50 +0000
socket: Add an option to retrieve a socket's FIB number
The SO_SETFIB option can be used to set a socket's FIB number, but there
is no way to retrieve it. Rename SO_SETFIB to SO_FIB and implement a
handler for it for getsockopt(2).
Reviewed by: glebius
MFC after: 2 weeks
Sponsored by: Klara, Inc.
Sponsored by: Stormshield
Differential Revision: https://reviews.freebsd.org/D48834
(cherry picked from commit ee951eb59f2136a604e3fbb12abf8d8344da0c99)
---
lib/libc/sys/getsockopt.2 | 4 ++--
sys/kern/uipc_socket.c | 6 ++++++
sys/sys/socket.h | 3 ++-
3 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/lib/libc/sys/getsockopt.2 b/lib/libc/sys/getsockopt.2
index 548e2f738e22..868f40e97773 100644
--- a/lib/libc/sys/getsockopt.2
+++ b/lib/libc/sys/getsockopt.2
@@ -177,7 +177,7 @@ for the socket
.It Dv SO_PROTOTYPE Ta "SunOS alias for the Linux SO_PROTOCOL (get only)"
.It Dv SO_ERROR Ta "get and clear error on the socket (get only)"
.It Dv SO_RERROR Ta "enables receive error reporting"
-.It Dv SO_SETFIB Ta "set the associated FIB (routing table) for the socket (set only)"
+.It Dv SO_FIB Ta "get or set the associated FIB (routing table) for the socket"
.El
.Pp
The following options are recognized in
@@ -360,7 +360,7 @@ or with the error
.Er EWOULDBLOCK
if no data were received.
.Pp
-.Dv SO_SETFIB
+.Dv SO_FIB
can be used to over-ride the default FIB (routing table) for the given socket.
The value must be from 0 to one less than the number returned from
the sysctl
diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c
index 58090b28fcc8..58e374d7aed2 100644
--- a/sys/kern/uipc_socket.c
+++ b/sys/kern/uipc_socket.c
@@ -4101,6 +4101,12 @@ integer:
error = sooptcopyout(sopt, &optval, sizeof optval);
break;
+ case SO_FIB:
+ SOCK_LOCK(so);
+ optval = so->so_fibnum;
+ SOCK_UNLOCK(so);
+ goto integer;
+
case SO_DOMAIN:
optval = so->so_proto->pr_domain->dom_family;
goto integer;
diff --git a/sys/sys/socket.h b/sys/sys/socket.h
index 65b5c5ee001d..b2afc735a383 100644
--- a/sys/sys/socket.h
+++ b/sys/sys/socket.h
@@ -166,7 +166,8 @@ typedef __uintptr_t uintptr_t;
#define SO_LISTENQLIMIT 0x1011 /* socket's backlog limit */
#define SO_LISTENQLEN 0x1012 /* socket's complete queue length */
#define SO_LISTENINCQLEN 0x1013 /* socket's incomplete queue length */
-#define SO_SETFIB 0x1014 /* use this FIB to route */
+#define SO_FIB 0x1014 /* get or set socket FIB */
+#define SO_SETFIB SO_FIB /* backward compat alias */
#define SO_USER_COOKIE 0x1015 /* user cookie (dummynet etc.) */
#define SO_PROTOCOL 0x1016 /* get socket protocol (Linux name) */
#define SO_PROTOTYPE SO_PROTOCOL /* alias for SO_PROTOCOL (SunOS name) */