PATCH: if_tap device cloning (final)

2001-08-31 Thread Maksim Yevmenkin

Hackers,

Attached some patches that implements device cloning 
(with devfs(5) support) for tap(4). The implementation is based 
on resource manager (see tun(4) and gif(4)).
Brooks Davis ([EMAIL PROTECTED]) took a quick
look at the patch and seems has no objection. Please review, 
test and if there is no objection Brooks Davis will commit it.
If there are any problems, please let me know. 

thanks,
max

p.s. i'm not on freebsd-net list, so please reply directly

p.p.s.

Brooks Davis wrote:

[...] 

 Looks good.  If could post a copy to freebsd-net and give it another
 24hrs or so for other responses, I'll commit it if nothing else comes
 up.

diff -ru /usr/src/share/man/man4/tap.4 ./src/share/man/man4/tap.4
--- /usr/src/share/man/man4/tap.4   Thu Aug 30 14:23:44 2001
+++ ./src/share/man/man4/tap.4  Thu Aug 30 15:14:40 2001
@@ -1,4 +1,4 @@
-.\ $FreeBSD: src/share/man/man4/tap.4,v 1.8 2001/08/07 15:48:39 ru Exp $
+.\ $FreeBSD: src/share/man/man4/tap.4,v 1.7 2001/05/01 09:15:13 schweikh Exp $
 .\ Based on PR#2411
 .\
 .Dd July 9, 2000
@@ -36,11 +36,50 @@
 interface.
 .Pp
 The network interfaces are named
-.Sy tap Ns Ar 0 ,
-.Sy tap Ns Ar 1 ,
-etc, as many as were made by
-.Xr MAKEDEV 8 .
-Each one supports the usual Ethernet network-interface
+.Dq Li tap0 ,
+.Dq Li tap1 ,
+etc., one for each control device that has been opened.
+These Ethernet network interfaces persist until
+.Pa if_tap.ko
+module is unloaded (if
+.Nm
+is built into your kernel, the network interfaces can not be removed).
+.Pp
+On older systems without
+.Xr devfs 5
+support,
+.Xr MAKEDEV 8
+should be used to create the initial control devices and the task
+of locating an unused device is left up to the opener (a
+.Nm
+device is usually obtained by attempting to open
+.Pa /dev/tap0 ,
+and if that fails
+.Pa /dev/tap1
+etc., until an
+.Va errno
+of
+.Er EBUSY
+is not received).
+.Pp
+On systems with
+.Xr devfs 5
+support,
+.Nm
+permits opens on the special control device
+.Pa /dev/tap .
+When this device is opened,
+.Nm
+will return a handle for the lowest unused
+.Nm
+device (use
+.Xr devname 3
+to determine which).
+Control devices (once successfully opened) persist until
+.Pa if_tap.ko
+is unloaded in the same way that network interfaces persist (see above).
+.Pp
+Each interface supports the usual Ethernet network interface
 .Xr ioctl 2 Ns s ,
 such as
 .Dv SIOCSIFADDR
@@ -56,7 +95,7 @@
 there);
 writing an Ethernet frame to the control device generates an input frame on
 the network interface, as if the
-(non-existent)
+.Pq non-existent
 hardware had just received it.
 .Pp
 The Ethernet tunnel device, normally
@@ -91,15 +130,14 @@
 .Fn write .
 Writes will not block; if the frame cannot be accepted
 for a transient reason
-(e.g., no buffer space available),
+.Pq e.g., no buffer space available ,
 it is silently dropped; if the reason is not transient
-(e.g., frame too large),
+.Pq e.g., frame too large ,
 an error is returned.
 The following
 .Xr ioctl 2
 calls are supported
-(defined in
-.Aq Pa net/if_tap.h ) :
+.Pq defined in Aq Pa net/if_tap.h Ns :
 .Bl -tag -width VMIO_SIOCSETMACADDR
 .It Dv TAPSDEBUG
 The argument should be a pointer to an
@@ -115,7 +153,7 @@
 Turn non-blocking I/O for reads off or on, according as the argument
 .Va int Ns 's
 value is or isn't zero
-(Writes are always nonblocking).
+.Pq Writes are always nonblocking .
 .It Dv FIOASYNC
 Turn asynchronous I/O for reads
 (i.e., generation of
@@ -172,8 +210,7 @@
 .Dq remote
 side. This command is used by VMware port and expected to be executed on
 a descriptor, associated with control device
-(usually
-.Pa /dev/vmnet Ns Sy N ) .
+.Pq usually Pa /dev/vmnet Ns Sy N .
 .El
 .Pp
 The control device also supports
@@ -199,7 +236,7 @@
 and
 .Nm vmnet
 devices. VMnet minor numbers begin at
-.Va 0x1
+.Va 0x80
 +
 .Va N .
 Where
diff -ru /usr/src/sys/net/if_tap.c ./src/sys/net/if_tap.c
--- /usr/src/sys/net/if_tap.c   Mon Mar 26 04:41:17 2001
+++ ./src/sys/net/if_tap.c  Thu Aug 30 17:51:00 2001
@@ -54,6 +54,9 @@
 #include sys/ttycom.h
 #include sys/uio.h
 #include sys/vnode.h
+#include machine/bus.h   /* XXX: Shouldn't really be required! */
+#include sys/rman.h
+#include sys/queue.h
 
 #include net/bpf.h
 #include net/ethernet.h
@@ -73,7 +76,9 @@
 
 #define TAPtap
 #define VMNET  vmnet
-#define VMNET_DEV_MASK 0x0001
+#define TAPMAXUNIT 0x7fff
+#define VMNET_DEV_MASK 0x0080
+   /*  0x007f00ff  */
 
 /* module */
 static int tapmodevent __P((module_t, int, void *));
@@ -111,9 +116,12 @@
/* flags */ 0,
 };
 
-static int taprefcnt = 0;  /* module ref. counter   */
-static int taplastunit = -1;   /* max. open unit number */
-static int tapdebug = 0;   /* debug flag*/
+static int tapdebug = 0;/* debug flag   */
+static SLIST_HEAD(, tap_softc) taphead; /* first 

PATCH: if_tap device cloning

2001-08-30 Thread Maksim Yevmenkin

Hackers,

Below some patches that implements device cloning (with devfs(5) 
support) for tap(4) device. The implementation is based on resource
manager (just like tun(4) and gif(4)). Please review, test and if 
there is no objection commit. If there are any problems, please let
me know.

http://home.earthlink.net/~evmax/tap-current/if_tap.c.context.diff.gz 
http://home.earthlink.net/~evmax/tap-current/if_tapvar.h.context.diff.gz 
http://home.earthlink.net/~evmax/tap-current/tap.4.context.diff.gz 

if you do not like context diff substitute context with unified :)

thanks,
max

To Unsubscribe: send mail to [EMAIL PROTECTED]
with unsubscribe freebsd-current in the body of the message