diff options
author | luigi <luigi@FreeBSD.org> | 2013-05-30 14:07:14 +0000 |
---|---|---|
committer | luigi <luigi@FreeBSD.org> | 2013-05-30 14:07:14 +0000 |
commit | f8c8cdb1f0ad6e4ded054e34e583cd6c7ae38e99 (patch) | |
tree | e0f45e5fcd2bc6f7fab3d4c32912971d7a02c5b6 /tools | |
parent | 93cb261dd8dc721ae8ea515803443a2a18122021 (diff) | |
download | FreeBSD-src-f8c8cdb1f0ad6e4ded054e34e583cd6c7ae38e99.zip FreeBSD-src-f8c8cdb1f0ad6e4ded054e34e583cd6c7ae38e99.tar.gz |
Bring in a number of new features, mostly implemented by Michio Honda:
- the VALE switch now support up to 254 destinations per switch,
unicast or broadcast (multicast goes to all ports).
- we can attach hw interfaces and the host stack to a VALE switch,
which means we will be able to use it more or less as a native bridge
(minor tweaks still necessary).
A 'vale-ctl' program is supplied in tools/tools/netmap
to attach/detach ports the switch, and list current configuration.
- the lookup function in the VALE switch can be reassigned to
something else, similar to the pf hooks. This will enable
attaching the firewall, or other processing functions (e.g. in-kernel
openvswitch) directly on the netmap port.
The internal API used by device drivers does not change.
Userspace applications should be recompiled because we
bump NETMAP_API as we now use some fields in the struct nmreq
that were previously ignored -- otherwise, data structures
are the same.
Manpages will be committed separately.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/tools/netmap/Makefile | 2 | ||||
-rw-r--r-- | tools/tools/netmap/vale-ctl.c | 163 |
2 files changed, 164 insertions, 1 deletions
diff --git a/tools/tools/netmap/Makefile b/tools/tools/netmap/Makefile index 2593a27..d737bac 100644 --- a/tools/tools/netmap/Makefile +++ b/tools/tools/netmap/Makefile @@ -3,7 +3,7 @@ # # For multiple programs using a single source file each, # we can just define 'progs' and create custom targets. -PROGS = pkt-gen bridge testpcap libnetmap.so +PROGS = pkt-gen bridge vale-ctl testpcap libnetmap.so CLEANFILES = $(PROGS) pcap.o nm_util.o NO_MAN= diff --git a/tools/tools/netmap/vale-ctl.c b/tools/tools/netmap/vale-ctl.c new file mode 100644 index 0000000..0a478ba --- /dev/null +++ b/tools/tools/netmap/vale-ctl.c @@ -0,0 +1,163 @@ +/* + * Copyright (C) 2013 Michio Honda. 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 <errno.h> +#include <stdio.h> +#include <inttypes.h> /* PRI* macros */ +#include <string.h> /* strcmp */ +#include <fcntl.h> /* open */ +#include <unistd.h> /* close */ +#include <sys/ioctl.h> /* ioctl */ +#include <sys/param.h> +#include <net/if.h> /* ifreq */ +#include <net/netmap.h> +#include <net/netmap_user.h> +#include <libgen.h> /* basename */ + +/* debug support */ +#define ND(format, ...) do {} while(0) +#define D(format, ...) \ + fprintf(stderr, "%s [%d] " format "\n", \ + __FUNCTION__, __LINE__, ##__VA_ARGS__) + +static int +bdg_ctl(const char *name, int nr_cmd, int nr_arg) +{ + struct nmreq nmr; + int error = 0; + int fd = open("/dev/netmap", O_RDWR); + + if (fd == -1) { + D("Unable to open /dev/netmap"); + return -1; + } + + bzero(&nmr, sizeof(nmr)); + nmr.nr_version = NETMAP_API; + if (name != NULL) /* might be NULL */ + strncpy(nmr.nr_name, name, sizeof(nmr.nr_name)); + nmr.nr_cmd = nr_cmd; + + switch (nr_cmd) { + case NETMAP_BDG_ATTACH: + case NETMAP_BDG_DETACH: + if (nr_arg && nr_arg != NETMAP_BDG_HOST) + nr_arg = 0; + nmr.nr_arg1 = nr_arg; + error = ioctl(fd, NIOCREGIF, &nmr); + if (error == -1) + D("Unable to %s %s to the bridge", nr_cmd == + NETMAP_BDG_DETACH?"detach":"attach", name); + else + D("Success to %s %s to the bridge\n", nr_cmd == + NETMAP_BDG_DETACH?"detach":"attach", name); + break; + + case NETMAP_BDG_LIST: + if (strlen(nmr.nr_name)) { /* name to bridge/port info */ + error = ioctl(fd, NIOCGINFO, &nmr); + if (error) + D("Unable to obtain info for %s", name); + else + D("%s at bridge:%d port:%d", name, nmr.nr_arg1, + nmr.nr_arg2); + break; + } + + /* scan all the bridges and ports */ + nmr.nr_arg1 = nmr.nr_arg2 = 0; + for (; !ioctl(fd, NIOCGINFO, &nmr); nmr.nr_arg2++) { + D("bridge:%d port:%d %s", nmr.nr_arg1, nmr.nr_arg2, + nmr.nr_name); + nmr.nr_name[0] = '\0'; + } + + break; + + default: /* GINFO */ + nmr.nr_cmd = nmr.nr_arg1 = nmr.nr_arg2 = 0; + error = ioctl(fd, NIOCGINFO, &nmr); + if (error) + D("Unable to get if info for %s", name); + else + D("%s: %d queues.", name, nmr.nr_rx_rings); + break; + } + close(fd); + return error; +} + +int +main(int argc, char *argv[]) +{ + int ch, nr_cmd = 0, nr_arg = 0; + const char *command = basename(argv[0]); + char *name = NULL; + + if (argc != 3 && argc != 1 /* list all */ ) { +usage: + fprintf(stderr, + "Usage:\n" + "%s arguments\n" + "\t-g interface interface name to get info\n" + "\t-d interface interface name to be detached\n" + "\t-a interface interface name to be attached\n" + "\t-h interface interface name to be attached with the host stack\n" + "\t-l list all or specified bridge's interfaces\n" + "", command); + return 0; + } + + while ((ch = getopt(argc, argv, "d:a:h:g:l:")) != -1) { + switch (ch) { + default: + fprintf(stderr, "bad option %c %s", ch, optarg); + goto usage; + case 'd': + nr_cmd = NETMAP_BDG_DETACH; + break; + case 'a': + nr_cmd = NETMAP_BDG_ATTACH; + break; + case 'h': + nr_cmd = NETMAP_BDG_ATTACH; + nr_arg = NETMAP_BDG_HOST; + break; + case 'g': + nr_cmd = 0; + break; + case 'l': + nr_cmd = NETMAP_BDG_LIST; + break; + } + name = optarg; + } + if (argc == 1) + nr_cmd = NETMAP_BDG_LIST; + bdg_ctl(name, nr_cmd, nr_arg); + return 0; +} |