SO_SETFIB socket option

Daniel Eischen deischen at freebsd.org
Sat Feb 12 16:52:53 UTC 2011


On Sat, 12 Feb 2011, Naveen Gujje wrote:

> Hi All,
>
> On my FreeBSD 7.2 box, I've two routing tables (FIBs). Fib 0 and Fib 1
> (net.fibs = 2).
>
> I have a simple echo client which is the counterpart of an echo server
> running somewhere.
> If I run this echo client against fib 0 as 'setfib 0 ./echo-client', it
> properly uses Fib 0.
> But, if I run this echo client against Fib 0 by using setsockopt & SO_SETFIB
> option, setsockopt fails with EINVAL.
>
> setsockopt & SO_SETFIB for Fib 1 succeeds. But it fails for Fib 0.
>
> By looking at the man page and /sys/kern/uipc_socket.c

[ snip ]

> Where as both Fib 0 and Fib 1 work fine if I use setfib() call.

Looks like the code is wrong.  Have you tried patching the source
to see if it works for you?  Looks like you already know the fix,
but here is a patch if you'd like to rebuild your kernel to see
if it works.

-- 
DE
-------------- next part --------------
Index: uipc_socket.c
===================================================================
--- uipc_socket.c	(revision 218493)
+++ uipc_socket.c	(working copy)
@@ -2448,15 +2448,16 @@
 		case SO_SETFIB:
 			error = sooptcopyin(sopt, &optval, sizeof optval,
 					    sizeof optval);
-			if (optval < 1 || optval > rt_numfibs) {
+			if (optval < 0 || optval > rt_numfibs) {
 				error = EINVAL;
 				goto bad;
 			}
-			if ((so->so_proto->pr_domain->dom_family == PF_INET) ||
-			    (so->so_proto->pr_domain->dom_family == PF_ROUTE)) {
+			if (so->so_proto != NULL &&
+			   ((so->so_proto->pr_domain->dom_family == PF_INET) ||
+			   (so->so_proto->pr_domain->dom_family == PF_ROUTE))) {
 				so->so_fibnum = optval;
 				/* Note: ignore error */
-				if (so->so_proto && so->so_proto->pr_ctloutput)
+				if (so->so_proto->pr_ctloutput)
 					(*so->so_proto->pr_ctloutput)(so, sopt);
 			} else {
 				so->so_fibnum = 0;


More information about the freebsd-hackers mailing list