FIB: how to get actually FIB of application

Colleagues, please tell me how I can get the current FIB from a running application or thread? An application can be launched using a setfib(1) wrapper and have some non-zero FIB.
I know the setfib(2) system call, but haven't found anything like getfib.

Thanks for the advice,
Ogogon.
 
hi mate

netstat has a -r -F fibnumber option

Code:
netstat -r -F 0

Code:
netstat -r -F 1

which shows the routing table

you have to enable multiple filbs

in /boot/loader.conf

Code:
net.fibs=2

and then run an application with a setfib prefix

such as

Code:
setfib 1 chrome

by default applications will be in fib 0
unless you start them with setfib 1

sockstat doesnt seem to have a fib option

cant think of anything off the top of my head
 
Here is an example of small patch that add fib support to dhclient:
Code:
diff --git a/sbin/dhclient/bpf.c b/sbin/dhclient/bpf.c
index a50abca62fd..ac46626b5a9 100644
--- a/sbin/dhclient/bpf.c
+++ b/sbin/dhclient/bpf.c
@@ -185,6 +185,8 @@ if_register_send(struct interface_info *info)
     if (setsockopt(sock, IPPROTO_IP, IP_HDRINCL, &on,
         sizeof(on)) == -1)
         error("setsockopt(IP_HDRINCL): %m");
+    if (setsockopt(sock, SOL_SOCKET, SO_SETFIB, &info->fib, sizeof(info->fib)))
+        error("setsockopt(SOL_SOCKET, SO_SETFIB): %m");
     info->ufdesc = sock;
 }
 
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index 8c2615e4c3d..83c18b70172 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -375,6 +375,7 @@ main(int argc, char *argv[])
     int             ch, fd, quiet = 0, i = 0;
     int             pipe_fd[2];
     int             immediate_daemon = 0;
+    uint32_t     fib = 0;
     struct passwd        *pw;
     pid_t             otherpid;
     cap_rights_t         rights;
@@ -396,6 +397,9 @@ main(int argc, char *argv[])
         case 'd':
             no_daemon = 1;
             break;
+        case 'f':
+            fib = atoi(optarg);
+            break;
         case 'l':
             path_dhclient_db = optarg;
             break;
@@ -444,6 +448,7 @@ main(int argc, char *argv[])
     if (quiet)
         log_perror = 0;
 
+    ifi->fib = fib;
     tzset();
     time(&cur_time);
 
@@ -575,7 +580,7 @@ usage(void)
 {
 
     fprintf(stderr, "usage: %s [-bdqu] ", getprogname());
-    fprintf(stderr, "[-c conffile] [-l leasefile] interface\n");
+    fprintf(stderr, "[-c conffile] [-l leasefile] [-f fib] interface\n");
     exit(1);
 }
 
diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h
index b151daa90a1..48690c80778 100644
--- a/sbin/dhclient/dhcpd.h
+++ b/sbin/dhclient/dhcpd.h
@@ -216,6 +216,7 @@ struct interface_info {
     int             dead;
     u_int16_t         index;
     int             linkstat;
+    uint32_t     fib;
 };
 
 struct timeout {
 
Back
Top