From 1c07d296490117f87dea7f7d491db849635a232a Mon Sep 17 00:00:00 2001 From: pooka Date: Fri, 29 May 2015 12:32:23 +0000 Subject: [PATCH] Add a rump kernel component for the tap device. from Wei Liu via private email --- sys/rump/net/Makefile.rumpnetcomp | 4 +- sys/rump/net/lib/libtap/Makefile | 15 ++++++ sys/rump/net/lib/libtap/tap_component.c | 64 +++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 sys/rump/net/lib/libtap/Makefile create mode 100644 sys/rump/net/lib/libtap/tap_component.c diff --git a/sys/rump/net/Makefile.rumpnetcomp b/sys/rump/net/Makefile.rumpnetcomp index f74a830b71b2..1251062da57a 100644 --- a/sys/rump/net/Makefile.rumpnetcomp +++ b/sys/rump/net/Makefile.rumpnetcomp @@ -1,10 +1,10 @@ -# $NetBSD: Makefile.rumpnetcomp,v 1.10 2013/11/16 14:00:57 rmind Exp $ +# $NetBSD: Makefile.rumpnetcomp,v 1.11 2015/05/29 12:32:23 pooka Exp $ # .include RUMPNETCOMP= agr bridge net net80211 netbt netinet netinet6 -RUMPNETCOMP+= netmpls npf local shmif +RUMPNETCOMP+= netmpls npf local shmif tap .if ${MKSLJIT} != "no" RUMPNETCOMP+= bpfjit diff --git a/sys/rump/net/lib/libtap/Makefile b/sys/rump/net/lib/libtap/Makefile new file mode 100644 index 000000000000..c4754774502e --- /dev/null +++ b/sys/rump/net/lib/libtap/Makefile @@ -0,0 +1,15 @@ +# $NetBSD: Makefile,v 1.1 2015/05/29 12:32:23 pooka Exp $ +# + +.PATH: ${.CURDIR}/../../../../net + +LIB= rumpnet_tap + +SRCS= if_tap.c + +SRCS+= tap_component.c + +CPPFLAGS+= -I${.CURDIR}/../libnet/opt -I${.CURDIR}/../../../librump/rumpvfs + +.include +.include diff --git a/sys/rump/net/lib/libtap/tap_component.c b/sys/rump/net/lib/libtap/tap_component.c new file mode 100644 index 000000000000..6d9a1f56af3d --- /dev/null +++ b/sys/rump/net/lib/libtap/tap_component.c @@ -0,0 +1,64 @@ +/* $NetBSD: tap_component.c,v 1.1 2015/05/29 12:32:23 pooka Exp $ */ + +/* + * Copyright (c) 2015 Wei Liu. 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 ``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. + */ + +#include +__KERNEL_RCSID(0, "$NetBSD: tap_component.c,v 1.1 2015/05/29 12:32:23 pooka Exp $"); + +#include +#include +#include + +#include "rump_private.h" +#include "rump_net_private.h" +#include "rump_vfs_private.h" + +CFDRIVER_DECL(tap, DV_IFNET, NULL); + +void tapattach(int); + +RUMP_COMPONENT(RUMP_COMPONENT_NET_IF) +{ + extern const struct cdevsw tap_cdevsw; + devmajor_t bmaj, cmaj; + int error; + + config_cfdriver_attach(&tap_cd); + tapattach(0); + + bmaj = cmaj = NODEVMAJOR; + error = devsw_attach("tap", NULL, &bmaj, &tap_cdevsw, &cmaj); + if (error != 0) + panic("tap devsw attach failed: %d", error); + + error = rump_vfs_makeonedevnode(S_IFCHR, "/dev/tap", cmaj, 0xfffff); + if (error != 0) + panic("cannot create tap device node: %d", error); + + error = rump_vfs_makedevnodes(S_IFCHR, "/dev/tap", '0', cmaj, 0, 4); + if (error != 0) + panic("cannot create tap[0-4] device node: %d", error); +}