Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Support tun devices on rump kernels



details:   https://anonhg.NetBSD.org/src/rev/f594cc68f0f3
branches:  trunk
changeset: 347599:f594cc68f0f3
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Mon Sep 05 02:25:37 2016 +0000

description:
Support tun devices on rump kernels

diffstat:

 distrib/sets/lists/base/shl.mi          |   5 ++-
 distrib/sets/lists/comp/mi              |   4 +-
 distrib/sets/lists/comp/shl.mi          |   3 +-
 distrib/sets/lists/debug/mi             |   3 +-
 distrib/sets/lists/debug/shl.mi         |   3 +-
 sys/net/if_tun.c                        |  15 ++++++-
 sys/rump/net/Makefile.rumpnetcomp       |   4 +-
 sys/rump/net/lib/libtun/Makefile        |  15 +++++++
 sys/rump/net/lib/libtun/TUN.ioconf      |   7 +++
 sys/rump/net/lib/libtun/tun_component.c |  63 +++++++++++++++++++++++++++++++++
 10 files changed, 113 insertions(+), 9 deletions(-)

diffs (251 lines):

diff -r 15e585b20555 -r f594cc68f0f3 distrib/sets/lists/base/shl.mi
--- a/distrib/sets/lists/base/shl.mi    Mon Sep 05 01:57:54 2016 +0000
+++ b/distrib/sets/lists/base/shl.mi    Mon Sep 05 02:25:37 2016 +0000
@@ -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
diff -r 15e585b20555 -r f594cc68f0f3 distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi        Mon Sep 05 01:57:54 2016 +0000
+++ b/distrib/sets/lists/comp/mi        Mon Sep 05 02:25:37 2016 +0000
@@ -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
diff -r 15e585b20555 -r f594cc68f0f3 distrib/sets/lists/comp/shl.mi
--- a/distrib/sets/lists/comp/shl.mi    Mon Sep 05 01:57:54 2016 +0000
+++ b/distrib/sets/lists/comp/shl.mi    Mon Sep 05 02:25:37 2016 +0000
@@ -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
diff -r 15e585b20555 -r f594cc68f0f3 distrib/sets/lists/debug/mi
--- a/distrib/sets/lists/debug/mi       Mon Sep 05 01:57:54 2016 +0000
+++ b/distrib/sets/lists/debug/mi       Mon Sep 05 02:25:37 2016 +0000
@@ -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
diff -r 15e585b20555 -r f594cc68f0f3 distrib/sets/lists/debug/shl.mi
--- a/distrib/sets/lists/debug/shl.mi   Mon Sep 05 01:57:54 2016 +0000
+++ b/distrib/sets/lists/debug/shl.mi   Mon Sep 05 02:25:37 2016 +0000
@@ -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
diff -r 15e585b20555 -r f594cc68f0f3 sys/net/if_tun.c
--- a/sys/net/if_tun.c  Mon Sep 05 01:57:54 2016 +0000
+++ b/sys/net/if_tun.c  Mon Sep 05 02:25:37 2016 +0000
@@ -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@localhost>
@@ -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 @@
        .d_flag = D_OTHER
 };
 
+#ifdef _MODULE
+devmajor_t tun_bmajor = -1, tun_cmajor = -1;
+#endif
+
 void
 tunattach(int unused)
 {
@@ -133,6 +137,9 @@
        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 @@
        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);
diff -r 15e585b20555 -r f594cc68f0f3 sys/rump/net/Makefile.rumpnetcomp
--- a/sys/rump/net/Makefile.rumpnetcomp Mon Sep 05 01:57:54 2016 +0000
+++ b/sys/rump/net/Makefile.rumpnetcomp Mon Sep 05 02:25:37 2016 +0000
@@ -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
diff -r 15e585b20555 -r f594cc68f0f3 sys/rump/net/lib/libtun/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/rump/net/lib/libtun/Makefile  Mon Sep 05 02:25:37 2016 +0000
@@ -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>
diff -r 15e585b20555 -r f594cc68f0f3 sys/rump/net/lib/libtun/TUN.ioconf
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/rump/net/lib/libtun/TUN.ioconf        Mon Sep 05 02:25:37 2016 +0000
@@ -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 -r 15e585b20555 -r f594cc68f0f3 sys/rump/net/lib/libtun/tun_component.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/rump/net/lib/libtun/tun_component.c   Mon Sep 05 02:25:37 2016 +0000
@@ -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);
+}



Home | Main Index | Thread Index | Old Index