From 1990603a92e16bd1a94c062dc58239daca6694e5 Mon Sep 17 00:00:00 2001 From: Hui Kang Date: Sun, 8 Jan 2017 03:11:05 +0000 Subject: [PATCH] Add tun component driver for rump kernel --- build.sh | 4 +- sys/rump/net/Makefile.rumpnetcomp | 2 +- sys/rump/net/lib/libtun/Makefile | 15 ++++++ sys/rump/net/lib/libtun/TUN.ioconf | 7 +++ sys/rump/net/lib/libtun/tun_component.c | 66 +++++++++++++++++++++++++ 5 files changed, 91 insertions(+), 3 deletions(-) create mode 100644 sys/rump/net/lib/libtun/Makefile create mode 100644 sys/rump/net/lib/libtun/TUN.ioconf create mode 100644 sys/rump/net/lib/libtun/tun_component.c diff --git a/build.sh b/build.sh index d0c6cc2c96..7d384d3912 100755 --- a/build.sh +++ b/build.sh @@ -2101,8 +2101,8 @@ RUMP_LIBSETS=' -lrumpfs_tmpfs -lrumpvfs -lrump, -lrumpfs_ffs -lrumpfs_msdos -lrumpvfs -lrumpdev_disk -lrumpdev -lrump, -lrumpnet_virtif -lrumpnet_netinet -lrumpnet_net -lrumpnet -lrump, - -lrumpnet_sockin -lrumpfs_smbfs -lrumpdev_netsmb - -lrumpkern_crypto -lrumpdev -lrumpnet -lrumpvfs -lrump, + -lrumpnet_sockin -lrumpfs_smbfs -lrumpdev_netsmb -lrumpnet_tap -lrumpnet_tun, + -lrumpkern_crypto -lrumpdev -lrumpnet -lrumpvfs -lrump, -lrumpnet_sockin -lrumpfs_nfs -lrumpnet -lrumpvfs -lrump, -lrumpdev_cgd -lrumpdev_raidframe -lrumpdev_disk -lrumpdev_rnd -lrumpdev_dm -lrumpdev -lrumpvfs -lrumpkern_crypto -lrump' diff --git a/sys/rump/net/Makefile.rumpnetcomp b/sys/rump/net/Makefile.rumpnetcomp index 29f3da964c..dc86a921ac 100644 --- a/sys/rump/net/Makefile.rumpnetcomp +++ b/sys/rump/net/Makefile.rumpnetcomp @@ -4,7 +4,7 @@ .include RUMPNETCOMP= agr bridge net net80211 netbt netinet netinet6 -RUMPNETCOMP+= gif netmpls npf local pppoe shmif tap +RUMPNETCOMP+= gif netmpls npf local pppoe shmif tap tun .if ${MKSLJIT} != "no" || make(rumpdescribe) RUMPNETCOMP+= bpfjit diff --git a/sys/rump/net/lib/libtun/Makefile b/sys/rump/net/lib/libtun/Makefile new file mode 100644 index 0000000000..6fd3c4f2a0 --- /dev/null +++ b/sys/rump/net/lib/libtun/Makefile @@ -0,0 +1,15 @@ +# $NetBSD: Makefile,v 1.1 2016/09/05 02:25:38 ozaki-r Exp $ +# + +.PATH: ${.CURDIR}/../../../../net + +LIB= rumpnet_tun +COMMENT=/dev/tun network tunneling over tty + +IOCONF= TUN.ioconf +SRCS= if_tun.c + +SRCS+= tun_component.c + +.include +.include diff --git a/sys/rump/net/lib/libtun/TUN.ioconf b/sys/rump/net/lib/libtun/TUN.ioconf new file mode 100644 index 0000000000..0c11060e6b --- /dev/null +++ b/sys/rump/net/lib/libtun/TUN.ioconf @@ -0,0 +1,7 @@ +# $NetBSD: TUN.ioconf,v 1.1 2016/09/05 02:25:38 ozaki-r Exp $ + +ioconf tun + +include "conf/files" + +pseudo-device tun diff --git a/sys/rump/net/lib/libtun/tun_component.c b/sys/rump/net/lib/libtun/tun_component.c new file mode 100644 index 0000000000..8eb30de10b --- /dev/null +++ b/sys/rump/net/lib/libtun/tun_component.c @@ -0,0 +1,66 @@ +/* $NetBSD: tun_component.c,v 1.1 2016/09/05 02:25:38 ozaki-r Exp $ */ + +/* + * Copyright (c) 2016 Internet Initiative Japan Inc. + * 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: tun_component.c,v 1.1 2016/09/05 02:25:38 ozaki-r Exp $"); + +#include +#include +#include + +#include +#include + +#include "ioconf.h" + +CFDRIVER_DECL(tun, DV_IFNET, NULL); + +RUMP_COMPONENT(RUMP_COMPONENT_NET_IF) +{ + extern const struct cdevsw tun_cdevsw; + devmajor_t bmaj, cmaj; + int error; + + config_cfdriver_attach(&tun_cd); + tunattach(0); + + bmaj = cmaj = NODEVMAJOR; + error = devsw_attach("tun", NULL, &bmaj, &tun_cdevsw, &cmaj); + if (error != 0) + panic("tun devsw attach failed: %d", error); + + error = rump_vfs_makeonedevnode(S_IFCHR, "/dev/tun", cmaj, + 0xfffff); + if (error != 0) + panic("cannot create tun device node: %d", error); + + error = rump_vfs_makedevnodes(S_IFCHR, "/dev/tun", '0', cmaj, + 0, 4); + if (error != 0) + panic("cannot create tun[0-4] device node: %d", error); +}