pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/net/netbsd-tap Initial import of netbsd-tap into the N...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/f9f945961f6d
branches:  trunk
changeset: 487809:f9f945961f6d
user:      cube <cube%pkgsrc.org@localhost>
date:      Thu Jan 20 18:02:38 2005 +0000

description:
Initial import of netbsd-tap into the NetBSD Packages Collection.

netbsd-tap is the "pkgsrcized" version of the implementation of tap(4) that
can be found in NetBSD-current.  It is compatible with NetBSD 2.0 and
above.

diffstat:

 net/netbsd-tap/DESCR                    |    10 +
 net/netbsd-tap/MESSAGE                  |    12 +
 net/netbsd-tap/Makefile                 |    28 +
 net/netbsd-tap/PLIST                    |     7 +
 net/netbsd-tap/buildlink3.mk            |    18 +
 net/netbsd-tap/builtin.mk               |    10 +
 net/netbsd-tap/files/Makefile           |    23 +
 net/netbsd-tap/files/if_tap.c           |  1396 +++++++++++++++++++++++++++++++
 net/netbsd-tap/files/if_tap.h           |    40 +
 net/netbsd-tap/files/if_tap_lkm.c       |   197 ++++
 net/netbsd-tap/files/if_tap_stub.c      |    49 +
 net/netbsd-tap/files/if_tap_stub.h      |     9 +
 net/netbsd-tap/files/tap.4              |   198 ++++
 net/netbsd-tap/files/tap_postinstall.sh |     8 +
 net/netbsd-tap/options.mk               |    11 +
 15 files changed, 2016 insertions(+), 0 deletions(-)

diffs (truncated from 2076 to 300 lines):

diff -r a98a2bd83698 -r f9f945961f6d net/netbsd-tap/DESCR
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/net/netbsd-tap/DESCR      Thu Jan 20 18:02:38 2005 +0000
@@ -0,0 +1,10 @@
+tap(4) is a virtual Ethernet device driver.  Each tap(4) device appears as a
+regular Ethernet NIC to the kernel, with a MAC address and a set of media
+interfaces.  It is a clonable network interface, which means any number of
+such devices can be created by the administrator.
+
+Just like tun(4), tap(4) offers a TTY interface to each of its devices which
+allows an application to read and inject Ethernet frames into the network
+stack.  tap(4) devices can be created and used individually for system-wide
+configurations, but an application can also use a special clonable device
+node to create interfaces on demand.
diff -r a98a2bd83698 -r f9f945961f6d net/netbsd-tap/MESSAGE
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/net/netbsd-tap/MESSAGE    Thu Jan 20 18:02:38 2005 +0000
@@ -0,0 +1,12 @@
+==========================================================================
+To have the tap(4) module automatically loaded at boot time, add the
+following to /etc/lkm.conf:
+
+${PREFIX}/lkm/tap.o - - ${PREFIX}/sbin/tap_postinstall - -
+
+And then add 'lkm=YES' to /etc/rc.conf.  Refer to lkm.conf(5) for
+additional details.
+
+The script ${PREFIX}/sbin/tap_postinstall creates the relevant device
+nodes in /dev, and can be used independently.
+==========================================================================
diff -r a98a2bd83698 -r f9f945961f6d net/netbsd-tap/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/net/netbsd-tap/Makefile   Thu Jan 20 18:02:38 2005 +0000
@@ -0,0 +1,28 @@
+# $NetBSD: Makefile,v 1.1.1.1 2005/01/20 18:02:38 cube Exp $
+
+DISTNAME=      netbsd-tap-20050120
+CATEGORIES=    net
+MASTER_SITES=  # empty
+DISTFILES=     # empty
+
+MAINTAINER=    cube%NetBSD.org@localhost
+COMMENT=       NetBSD kernel module for virtual Ethernet devices
+
+NO_CONFIGURE=  yes
+NO_CHECKSUM=   yes
+INSTALL_TARGET=        includes install
+
+ONLY_FOR_PLATFORM=     NetBSD-[2-9]*-*
+INSTALLATION_DIRS=     lkm
+
+.include "options.mk"
+
+SUBST_CLASSES+=        tap_postinstall
+SUBST_STAGE.tap_postinstall=   post-build
+SUBST_FILES.tap_postinstall=   tap_postinstall.sh
+SUBST_SED.tap_postinstall=     -e s,@SH@,${SH:Q},
+
+do-extract:
+       @${CP} -R ${FILESDIR} ${WRKSRC}
+
+.include "../../mk/bsd.pkg.mk"
diff -r a98a2bd83698 -r f9f945961f6d net/netbsd-tap/PLIST
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/net/netbsd-tap/PLIST      Thu Jan 20 18:02:38 2005 +0000
@@ -0,0 +1,7 @@
+@comment $NetBSD: PLIST,v 1.1.1.1 2005/01/20 18:02:39 cube Exp $
+include/net/if_tap.h
+lkm/tap.o
+man/cat4/tap.0
+man/man4/tap.4
+sbin/tap_postinstall
+@unexec ${RMDIR} %D/include/net || ${TRUE}
diff -r a98a2bd83698 -r f9f945961f6d net/netbsd-tap/buildlink3.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/net/netbsd-tap/buildlink3.mk      Thu Jan 20 18:02:38 2005 +0000
@@ -0,0 +1,18 @@
+# $NetBSD: buildlink3.mk,v 1.1.1.1 2005/01/20 18:02:39 cube Exp $
+
+BUILDLINK_DEPTH:=              ${BUILDLINK_DEPTH}+
+NETBSD_TAP_BUILDLINK3_MK:=     ${NETBSD_TAP_BUILDLINK3_MK}+
+
+.if !empty(BUILDLINK_DEPTH:M+)
+BUILDLINK_DEPENDS+=    netbsd-tap
+.endif
+
+BUILDLINK_PACKAGES:=   ${BUILDLINK_PACKAGES:Nnetbsd-tap}
+BUILDLINK_PACKAGES+=   netbsd-tap
+
+.if !empty(NETBSD_TAP_BUILDLINK3_MK:M+)
+BUILDLINK_DEPENDS.netbsd-tap+= netbsd-tap>=20050120
+BUILDLINK_PKGSRCDIR.netbsd-tap?=       ../../local/netbsd-tap
+.endif # NETBSD_TAP_BUILDLINK3_MK
+
+BUILDLINK_DEPTH:=     ${BUILDLINK_DEPTH:S/+$//}
diff -r a98a2bd83698 -r f9f945961f6d net/netbsd-tap/builtin.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/net/netbsd-tap/builtin.mk Thu Jan 20 18:02:38 2005 +0000
@@ -0,0 +1,10 @@
+# $NetBSD: builtin.mk,v 1.1.1.1 2005/01/20 18:02:39 cube Exp $
+
+.if !defined(IS_BUILTIN.netbsd-tap)
+. if exists(/usr/include/net/if_tap.h)
+IS_BUILTIN.netbsd-tap=         YES
+. else
+IS_BUILTIN.netbsd-tap=         NO
+.endif # IS_BUILTIN.netbsd-tap
+
+USE_BUILTIN.netbsd-tap?=       ${IS_BUILTIN.netbsd-tap}
diff -r a98a2bd83698 -r f9f945961f6d net/netbsd-tap/files/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/net/netbsd-tap/files/Makefile     Thu Jan 20 18:02:38 2005 +0000
@@ -0,0 +1,23 @@
+# $NetBSD: Makefile,v 1.1.1.1 2005/01/20 18:02:40 cube Exp $
+
+SRCS=  if_tap_lkm.c if_tap.c if_tap_stub.c
+KMOD=  tap
+WARNS= 3
+
+INCSDIR=       ${PREFIX}/include/net
+INCS=          if_tap.h
+
+KMODDIR=       ${PREFIX}/lkm
+MANDIR=                ${PREFIX}/man
+
+.if defined(USE_BPF) && !empty(USE_BPF:M[Yy][Ee][Ss])
+CPPFLAGS+=     -DNBPFILTER=1
+.endif
+
+install: install-postinstall
+
+install-postinstall:
+       ${BSD_INSTALL_SCRIPT} tap_postinstall.sh ${PREFIX}/sbin/tap_postinstall
+
+.include <bsd.kinc.mk>
+.include <bsd.kmod.mk>
diff -r a98a2bd83698 -r f9f945961f6d net/netbsd-tap/files/if_tap.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/net/netbsd-tap/files/if_tap.c     Thu Jan 20 18:02:38 2005 +0000
@@ -0,0 +1,1396 @@
+/*     $NetBSD: if_tap.c,v 1.1.1.1 2005/01/20 18:02:40 cube Exp $      */
+
+/*
+ *  Copyright (c) 2003, 2004 The NetBSD Foundation.
+ *  All rights reserved.
+ *
+ *  This code is derived from software contributed to the NetBSD Foundation
+ *   by Quentin Garnier.
+ * 
+ *  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.
+ *  3. All advertising materials mentioning features or use of this software
+ *     must display the following acknowledgement:
+ *         This product includes software developed by the NetBSD
+ *         Foundation, Inc. and its contributors.
+ *  4. Neither the name of The NetBSD Foundation nor the names of its
+ *     contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ * 
+ *  THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+/*
+ * tap(4) is a virtual Ethernet interface.  It appears as a real Ethernet
+ * device to the system, but can also be accessed by userland through a
+ * character device interface, which allows reading and injecting frames.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.1.1.1 2005/01/20 18:02:40 cube Exp $");
+
+#if defined(_KERNEL_OPT)
+#include "bpfilter.h"
+#endif
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/conf.h>
+#include <sys/device.h>
+#include <sys/file.h>
+#include <sys/filedesc.h>
+#include <sys/ksyms.h>
+#include <sys/poll.h>
+#include <sys/select.h>
+#include <sys/sockio.h>
+#include <sys/sysctl.h>
+
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/if_ether.h>
+#include <net/if_media.h>
+#if NBPFILTER > 0
+#include <net/bpf.h>
+#endif
+
+#include "if_tap.h"
+#include "if_tap_stub.h"
+
+/*
+ * sysctl node management
+ *
+ * It's not really possible to use a SYSCTL_SETUP block with
+ * current LKM implementation, so it is easier to just define
+ * our own function.
+ *
+ * The handler function is a "helper" in Andrew Brown's sysctl
+ * framework terminology.  It is used as a gateway for sysctl
+ * requests over the nodes.
+ *
+ * tap_log allows the module to log creations of nodes and
+ * destroy them all at once using sysctl_teardown.
+ */
+static int tap_node;
+static int     tap_sysctl_handler(SYSCTLFN_PROTO);
+SYSCTL_SETUP_PROTO(sysctl_tap_setup);
+
+/*
+ * Since we're an Ethernet device, we need the 3 following
+ * components: a leading struct device, a struct ethercom,
+ * and also a struct ifmedia since we don't attach a PHY to
+ * ourselves. We could emulate one, but there's no real
+ * point.
+ */
+
+struct tap_softc {
+       struct device   sc_dev;
+       struct ifmedia  sc_im;
+       struct ethercom sc_ec;
+       int             sc_flags;
+#define        TAP_INUSE       0x00000001      /* tap device can only be opened once */
+#define TAP_ASYNCIO    0x00000002      /* user is using async I/O (SIGIO) on the device */
+#define TAP_NBIO       0x00000004      /* user wants calls to avoid blocking */
+#define TAP_GOING      0x00000008      /* interface is being destroyed */
+       struct selinfo  sc_rsel;
+       pid_t           sc_pgid; /* For async. IO */
+       struct lock     sc_rdlock;
+       struct simplelock       sc_kqlock;
+};
+
+/* autoconf(9) glue */
+
+void   tapattach(int);
+
+static int     tap_match(struct device *, struct cfdata *, void *);
+static void    tap_attach(struct device *, struct device *, void *);
+static int     tap_detach(struct device*, int);
+
+/* Ethernet address helper functions */
+
+static char    *tap_ether_sprintf(char *, const u_char *);
+static int     tap_ether_aton(u_char *, char *);
+
+CFATTACH_DECL(tap, sizeof(struct tap_softc),
+    tap_match, tap_attach, tap_detach, NULL);
+extern struct cfdriver tap_cd;
+
+/* Real device access routines */
+static int     tap_dev_close(struct tap_softc *);
+static int     tap_dev_read(int, struct uio *, int);
+static int     tap_dev_write(int, struct uio *, int);
+static int     tap_dev_ioctl(int, u_long, caddr_t, struct proc *);
+static int     tap_dev_poll(int, int, struct proc *);
+static int     tap_dev_kqfilter(int, struct knote *);
+
+/* Fileops access routines */
+static int     tap_fops_close(struct file *, struct proc *);
+static int     tap_fops_read(struct file *, off_t *, struct uio *,
+    struct ucred *, int);
+static int     tap_fops_write(struct file *, off_t *, struct uio *,
+    struct ucred *, int);
+static int     tap_fops_ioctl(struct file *, u_long, void *,
+    struct proc *);
+static int     tap_fops_poll(struct file *, int, struct proc *);
+static int     tap_fops_kqfilter(struct file *, struct knote *);
+
+static struct fileops tap_fileops = {
+       tap_fops_read,
+       tap_fops_write,
+       tap_fops_ioctl,
+       tap_fnullop_fcntl,
+       tap_fops_poll,
+       tap_fbadop_stat,



Home | Main Index | Thread Index | Old Index