Support tun devices on rump kernels

This commit is contained in:
ozaki-r 2016-09-05 02:25:37 +00:00
parent 586dc438d1
commit 6dc1297521
10 changed files with 113 additions and 9 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: shl.mi,v 1.783 2016/08/20 11:34:49 christos Exp $
# $NetBSD: shl.mi,v 1.784 2016/09/05 02:25:37 ozaki-r Exp $
#
# Note: Don't delete entries from here - mark them as "obsolete" instead,
# unless otherwise stated below.
@ -736,6 +736,9 @@
./usr/lib/librumpnet_tap.so base-rump-shlib rump
./usr/lib/librumpnet_tap.so.0 base-rump-shlib rump
./usr/lib/librumpnet_tap.so.0.0 base-rump-shlib rump
./usr/lib/librumpnet_tun.so base-rump-shlib rump
./usr/lib/librumpnet_tun.so.0 base-rump-shlib rump
./usr/lib/librumpnet_tun.so.0.0 base-rump-shlib rump
./usr/lib/librumpnet_virtif.so base-rump-shlib rump
./usr/lib/librumpnet_virtif.so.0 base-rump-shlib rump
./usr/lib/librumpnet_virtif.so.0.0 base-rump-shlib rump

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.2059 2016/08/27 08:03:47 dholland Exp $
# $NetBSD: mi,v 1.2060 2016/09/05 02:25:37 ozaki-r Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
./etc/mtree/set.comp comp-sys-root
@ -3563,6 +3563,8 @@
./usr/lib/librumpnet_sockin_p.a comp-c-proflib rump,profile
./usr/lib/librumpnet_tap.a comp-c-lib rump
./usr/lib/librumpnet_tap_p.a comp-c-proflib rump,profile
./usr/lib/librumpnet_tun.a comp-c-lib rump
./usr/lib/librumpnet_tun_p.a comp-c-proflib rump,profile
./usr/lib/librumpnet_virtif.a comp-c-lib rump
./usr/lib/librumpnet_virtif_p.a comp-c-proflib rump,profile
./usr/lib/librumpuser.a comp-c-lib compatfile,rump

View File

@ -1,4 +1,4 @@
# $NetBSD: shl.mi,v 1.294 2016/08/27 07:54:31 christos Exp $
# $NetBSD: shl.mi,v 1.295 2016/09/05 02:25:37 ozaki-r Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@ -231,6 +231,7 @@
./usr/lib/librumpnet_shmif_pic.a comp-c-piclib picinstall,rump
./usr/lib/librumpnet_sockin_pic.a comp-c-piclib picinstall,rump
./usr/lib/librumpnet_tap_pic.a comp-c-piclib picinstall,rump
./usr/lib/librumpnet_tun_pic.a comp-c-piclib picinstall,rump
./usr/lib/librumpnet_virtif_pic.a comp-c-piclib picinstall,rump
./usr/lib/librumpuser_pic.a comp-c-piclib compatfile,picinstall,rump
./usr/lib/librumpvfs_aio_pic.a comp-c-piclib picinstall,rump

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.166 2016/08/31 14:05:09 maya Exp $
# $NetBSD: mi,v 1.167 2016/09/05 02:25:38 ozaki-r Exp $
./etc/mtree/set.debug comp-sys-root
./usr/lib comp-sys-usr compatdir
./usr/lib/i18n/libBIG5_g.a comp-c-debuglib debuglib,compatfile
@ -223,6 +223,7 @@
./usr/lib/librumpnet_shmif_g.a comp-c-debuglib debuglib,rump
./usr/lib/librumpnet_sockin_g.a comp-c-debuglib debuglib,rump
./usr/lib/librumpnet_tap_g.a comp-c-debuglib debuglib,rump
./usr/lib/librumpnet_tun_g.a comp-c-debuglib debuglib,rump
./usr/lib/librumpnet_virtif_g.a comp-c-debuglib debuglib,rump
./usr/lib/librumpuser_g.a comp-c-debuglib debuglib,compatfile,rump
./usr/lib/librumpvfs_aio_g.a comp-c-debuglib debuglib,rump

View File

@ -1,4 +1,4 @@
# $NetBSD: shl.mi,v 1.143 2016/08/20 11:34:49 christos Exp $
# $NetBSD: shl.mi,v 1.144 2016/09/05 02:25:38 ozaki-r Exp $
./usr/libdata/debug/lib base-sys-usr debug,dynamicroot,compatdir
./usr/libdata/debug/lib/libblacklist.so.0.0.debug comp-sys-debug debug,dynamicroot
./usr/libdata/debug/lib/libc.so.12.203.debug comp-sys-debug debug,dynamicroot
@ -250,6 +250,7 @@
./usr/libdata/debug/usr/lib/librumpnet_shmif.so.0.0.debug comp-rump-debug debug,rump
./usr/libdata/debug/usr/lib/librumpnet_sockin.so.0.0.debug comp-rump-debug debug,rump
./usr/libdata/debug/usr/lib/librumpnet_tap.so.0.0.debug comp-rump-debug debug,rump
./usr/libdata/debug/usr/lib/librumpnet_tun.so.0.0.debug comp-rump-debug debug,rump
./usr/libdata/debug/usr/lib/librumpnet_virtif.so.0.0.debug comp-rump-debug debug,rump
./usr/libdata/debug/usr/lib/librumpuser.so.0.1.debug comp-rump-debug debug,compatfile,rump
./usr/libdata/debug/usr/lib/librumpvfs.so.0.0.debug comp-rump-debug debug,compatfile,rump

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_tun.c,v 1.129 2016/09/05 01:57:54 ozaki-r Exp $ */
/* $NetBSD: if_tun.c,v 1.130 2016/09/05 02:25:37 ozaki-r Exp $ */
/*
* Copyright (c) 1988, Julian Onions <jpo@cs.nott.ac.uk>
@ -15,7 +15,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.129 2016/09/05 01:57:54 ozaki-r Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_tun.c,v 1.130 2016/09/05 02:25:37 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -115,6 +115,10 @@ const struct cdevsw tun_cdevsw = {
.d_flag = D_OTHER
};
#ifdef _MODULE
devmajor_t tun_bmajor = -1, tun_cmajor = -1;
#endif
void
tunattach(int unused)
{
@ -133,6 +137,9 @@ tuninit(void)
LIST_INIT(&tun_softc_list);
LIST_INIT(&tunz_softc_list);
if_clone_attach(&tun_cloner);
#ifdef _MODULE
devsw_attach("tun", NULL, &tun_bmajor, &tun_cdevsw, &tun_cmajor);
#endif
}
static int
@ -143,6 +150,10 @@ tundetach(void)
if (!LIST_EMPTY(&tun_softc_list) || !LIST_EMPTY(&tunz_softc_list))
error = EBUSY;
#ifdef _MODULE
if (error == 0)
error = devsw_detach(NULL, &tun_cdevsw);
#endif
if (error == 0) {
if_clone_detach(&tun_cloner);
mutex_destroy(&tun_softc_lock);

View File

@ -1,10 +1,10 @@
# $NetBSD: Makefile.rumpnetcomp,v 1.14 2016/04/15 01:35:26 ozaki-r Exp $
# $NetBSD: Makefile.rumpnetcomp,v 1.15 2016/09/05 02:25:38 ozaki-r Exp $
#
.include <bsd.own.mk>
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

View File

@ -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 <bsd.lib.mk>
.include <bsd.klinks.mk>

View File

@ -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

View File

@ -0,0 +1,63 @@
/* $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 <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: tun_component.c,v 1.1 2016/09/05 02:25:38 ozaki-r Exp $");
#include <sys/param.h>
#include <sys/device.h>
#include <sys/stat.h>
#include <rump-sys/kern.h>
#include <rump-sys/vfs.h>
#include "ioconf.h"
RUMP_COMPONENT(RUMP_COMPONENT_NET_IF)
{
extern const struct cdevsw tun_cdevsw;
extern devmajor_t tun_bmajor, tun_cmajor;
int error;
error = devsw_attach("tun", NULL, &tun_bmajor,
&tun_cdevsw, &tun_cmajor);
if (error != 0)
panic("tun devsw attach failed: %d", error);
error = rump_vfs_makeonedevnode(S_IFCHR, "/dev/tun", tun_cmajor,
0xfffff);
if (error != 0)
panic("cannot create tun device node: %d", error);
error = rump_vfs_makedevnodes(S_IFCHR, "/dev/tun", '0', tun_cmajor,
0, 4);
if (error != 0)
panic("cannot create tun[0-4] device node: %d", error);
devsw_detach(NULL, &tun_cdevsw);
}