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)
This commit is contained in:
Mark Johnston 2025-02-06 14:17:19 +00:00
parent ce80cdeb13
commit b0f2df45e7
3 changed files with 10 additions and 3 deletions

View file

@ -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

View file

@ -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;

View file

@ -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) */