git: ee951eb59f21 - main - socket: Add an option to retrieve a socket's FIB number
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 06 Feb 2025 16:27:33 UTC
The branch main has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=ee951eb59f2136a604e3fbb12abf8d8344da0c99
commit ee951eb59f2136a604e3fbb12abf8d8344da0c99
Author: Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2025-02-06 14:17:19 +0000
Commit: Mark Johnston <markj@FreeBSD.org>
CommitDate: 2025-02-06 14:17:19 +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
---
lib/libsys/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/libsys/getsockopt.2 b/lib/libsys/getsockopt.2
index 15e4b76311d8..619540b53fae 100644
--- a/lib/libsys/getsockopt.2
+++ b/lib/libsys/getsockopt.2
@@ -175,7 +175,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
@@ -358,7 +358,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 65cea2e067cf..03bfea721dd2 100644
--- a/sys/kern/uipc_socket.c
+++ b/sys/kern/uipc_socket.c
@@ -4106,6 +4106,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 cc82d97e9dd5..2ef455991491 100644
--- a/sys/sys/socket.h
+++ b/sys/sys/socket.h
@@ -164,7 +164,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) */