diff options
author | bz <bz@FreeBSD.org> | 2011-07-03 12:22:02 +0000 |
---|---|---|
committer | bz <bz@FreeBSD.org> | 2011-07-03 12:22:02 +0000 |
commit | 9cad5bfef3ce97c030d30e66deb6371458c2281b (patch) | |
tree | 84813f5c322ca01ea7d1b10025c5fa8621a31765 /sbin/ifconfig | |
parent | 9cb2f04853640f386dd7db2d61d981a14cd67729 (diff) | |
download | FreeBSD-src-9cad5bfef3ce97c030d30e66deb6371458c2281b.zip FreeBSD-src-9cad5bfef3ce97c030d30e66deb6371458c2281b.tar.gz |
Add infrastructure to allow all frames/packets received on an interface
to be assigned to a non-default FIB instance.
You may need to recompile world or ports due to the change of struct ifnet.
Submitted by: cjsp
Submitted by: Alexander V. Chernikov (melifaro ipfw.ru)
(original versions)
Reviewed by: julian
Reviewed by: Alexander V. Chernikov (melifaro ipfw.ru)
MFC after: 2 weeks
X-MFC: use spare in struct ifnet
Diffstat (limited to 'sbin/ifconfig')
-rw-r--r-- | sbin/ifconfig/Makefile | 1 | ||||
-rw-r--r-- | sbin/ifconfig/ifconfig.8 | 15 | ||||
-rw-r--r-- | sbin/ifconfig/iffib.c | 103 |
3 files changed, 118 insertions, 1 deletions
diff --git a/sbin/ifconfig/Makefile b/sbin/ifconfig/Makefile index 461de71..d4bdd1e 100644 --- a/sbin/ifconfig/Makefile +++ b/sbin/ifconfig/Makefile @@ -29,6 +29,7 @@ SRCS+= af_nd6.c # ND6 support SRCS+= ifclone.c # clone device support SRCS+= ifmac.c # MAC support SRCS+= ifmedia.c # SIOC[GS]IFMEDIA support +SRCS+= iffib.c # non-default FIB support SRCS+= ifvlan.c # SIOC[GS]ETVLAN support SRCS+= ifgre.c # GRE keys etc SRCS+= ifgif.c # GIF reversed header workaround diff --git a/sbin/ifconfig/ifconfig.8 b/sbin/ifconfig/ifconfig.8 index 45cf59b..cec32c5 100644 --- a/sbin/ifconfig/ifconfig.8 +++ b/sbin/ifconfig/ifconfig.8 @@ -28,7 +28,7 @@ .\" From: @(#)ifconfig.8 8.3 (Berkeley) 1/5/94 .\" $FreeBSD$ .\" -.Dd May 31, 2011 +.Dd July 3, 2011 .Dt IFCONFIG 8 .Os .Sh NAME @@ -296,6 +296,19 @@ Remove the interface from the given Fill interface index (lowermost 64bit of an IPv6 address) automatically. +.It Cm fib Ar fib_number +Specify interface FIB. +A FIB +.Ar fib_number +is assigned to all frames or packets received on that interface. +The FIB is not inherited, e.g. vlans or other sub-interfaces will use +the default FIB (0) irrespective of the parent interface's FIB. +The kernel needs to be tuned to support more than the default FIB +using the +.Va ROUTETABLES +kernel configuration option, or the +.Va net.fibs +tunable. .It Cm ipdst This is used to specify an Internet host who is willing to receive IP packets encapsulating IPX packets bound for a remote network. diff --git a/sbin/ifconfig/iffib.c b/sbin/ifconfig/iffib.c new file mode 100644 index 0000000..f3498b4 --- /dev/null +++ b/sbin/ifconfig/iffib.c @@ -0,0 +1,103 @@ +/*- + * Copyright (c) 2011 Alexander V. Chernikov + * Copyright (c) 2011 Christian S.J. Peron + * Copyright (c) 2011 Bjoern A. Zeeb + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include <sys/param.h> +#include <sys/ioctl.h> +#include <sys/socket.h> +#include <sys/sockio.h> + +#include <net/if.h> +#include <net/route.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <err.h> + +#include "ifconfig.h" + +static void +fib_status(int s) +{ + struct ifreq ifr; + + memset(&ifr, 0, sizeof(ifr)); + strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); + + if (ioctl(s, SIOCGIFFIB, (caddr_t)&ifr) < 0) + return; + + /* Ignore if it is the default. */ + if (ifr.ifr_fib == 0) + return; + + printf("\tfib: %u\n", ifr.ifr_fib); +} + +static void +setiffib(const char *val, int dummy __unused, int s, + const struct afswtch *afp) +{ + unsigned long fib; + char *ep; + + fib = strtoul(val, &ep, 0); + if (*ep != '\0' || fib > UINT_MAX) { + warn("fib %s not valid", val); + return; + } + + strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); + ifr.ifr_fib = fib; + if (ioctl(s, SIOCSIFFIB, (caddr_t)&ifr) < 0) + warn("ioctl (SIOCSIFFIB)"); +} + +static struct cmd fib_cmds[] = { + DEF_CMD_ARG("fib", setiffib), +}; + +static struct afswtch af_fib = { + .af_name = "af_fib", + .af_af = AF_UNSPEC, + .af_other_status = fib_status, +}; + +static __constructor void +fib_ctor(void) +{ +#define N(a) (sizeof(a) / sizeof(a[0])) + size_t i; + + for (i = 0; i < N(fib_cmds); i++) + cmd_register(&fib_cmds[i]); + af_register(&af_fib); +#undef N +} |