chiark / gitweb /
5854f9c57c2848646909d43b4c333c09abebad61
[unet] / unet.h
1 /* -*-c-*-
2  *
3  * $Id: unet.h,v 1.2 2001/02/19 19:10:28 mdw Exp $
4  *
5  * User-space network device support.
6  *
7  * (c) 1998 Mark Wooding
8  */
9
10 /*----- Licensing notice --------------------------------------------------*
11  *
12  * This file is part of Usernet.
13  *
14  * Usernet is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  *
19  * Usernet is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with Usernet; if not, write to the Free Software Foundation,
26  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27  */
28
29 /*----- Revision history --------------------------------------------------*
30  *
31  * $Log: unet.h,v $
32  * Revision 1.2  2001/02/19 19:10:28  mdw
33  * New option to allow changing interface flags.
34  *
35  * Revision 1.1  2001/01/25 22:03:39  mdw
36  * Initial check-in (somewhat belated).
37  *
38  */
39
40 #ifndef _LINUX_UNET_H
41 #define _LINUX_UNET_H
42
43 #ifdef __cplusplus
44   extern "C" {
45 #endif
46
47 /*----- What's the story? -------------------------------------------------*
48  *
49  * Based on a conversation with Clive Jones about FreeBSD's tunnel device,
50  * I've decided to try to write something similar.  The basic idea is to
51  * tie together a character device and a network interface, so that anything
52  * written to one pops out the other.  I create a device /dev/unet.
53  * Each open(2) of my device creates a network device, whose name can be
54  * read by calling ioctl(2).  A read(2) on the device fetches the next
55  * packet received from the network interface; conversely, a write(2) sends
56  * a network packet through the interface.
57  *
58  * Permissions on /dev/unet ought to be fairly strict.  Remember that
59  * anyone who can get access to it can inject arbitrary IP packets.
60  *
61  * This is my first stab at hacking Linux, so there'll be mistakes and
62  * infelicities.  All I ask is that you tell me what they are.
63  *
64  *                                              [mdw]
65  *                                              mdw@excessus.demon.co.uk
66  */
67
68 /*----- @ioctl@(2) calls supported ----------------------------------------*/
69
70 /* --- @UNIOCGINFO@ --- *
71  *
72  * Reads useful information about a unet.  The argument is a pointer to a
73  * @unet_info@ structure, which is filled in by the call.  As a special case,
74  * the argument may be a null pointer, in which case the call does nothing
75  * and may be used to verify that a file descriptor refers to a Usernet
76  * attachment.
77  */
78
79 #define UNIOCGINFO _IOR('U', 0, sizeof(struct unet_info))
80
81 #define UNET_NAMEMAX 20
82
83 struct unet_info {
84   char uni_ifname[UNET_NAMEMAX];        /* Interface name string */
85   unsigned short uni_mtu;               /* Maximum transmission unit */
86   unsigned short uni_family;            /* My address family */
87   unsigned short uni_proto;             /* Protocol to stamp on packets */
88   unsigned int uni_flags;               /* Various useful flags */
89 };
90
91 #define UNIF_TRANS 1                    /* This device is transient */
92 #define UNIF_OPEN 2                     /* Not useful to users */
93 #define UNIF_DEBUG 4                    /* Debugging enable flag */
94
95 /* --- @UNIOCSDEBUG@ --- *
96  *
97  * Sets the debugging state for the attachment.  When the debug flag is set,
98  * all packets sent and received by the device will be logged, as will other
99  * events.
100  */
101
102 #define UNIOCSDEBUG _IO('U', 1)
103
104 /* --- @UNIOCGPROTO@ --- *
105  *
106  * Reads the protocol stamped on packets received through the character
107  * device interface.  The default is @ETH_P_IP@; the various values are
108  * defined in @<linux/if_ether.h>@.
109  */
110
111 #define UNIOCGPROTO _IO('U', 2)
112
113 /* --- @UNIOCSPROTO@ --- *
114  *
115  * Sets the protocol to be stamped on outgoing packets.
116  */
117
118 #define UNIOCSPROTO _IO('U', 3)
119
120 /* --- @UNIOCGGDEBUG@ --- *
121  *
122  * Gets the global debugging flag.
123  */
124
125 #define UNIOCGGDEBUG _IO('U', 4)
126
127 /* --- @UNIOCSGDEBUG@ --- *
128  *
129  * Sets the global debugging flag.  This is only available when runtime
130  * debugging configuration is compiled in.
131  */
132
133 #define UNIOCSGDEBUG _IO('U', 5)
134
135 /* --- @UNIOCDUMP@ --- *
136  *
137  * Dumps a unet block's information to the debug device.
138  */
139
140 #define UNIOCDUMP _IO('U', 6)
141
142 /* --- @UNIOCGMAXIF@ --- *
143  *
144  * Returns the maximum number of interfaces allowed.
145  */
146
147 #define UNIOCGMAXIF _IO('U', 7)
148
149 /* --- @UNIOCGMAXIF@ --- *
150  *
151  * Sets the maximum number of interfaces allowed.  It's an error to lower
152  * this below the number of the highest currently-used interface.
153  */
154
155 #define UNIOCSMAXIF _IO('U', 8)
156
157 /* --- @UNIOCGIFFLAGS@ --- *
158  *
159  * Gets interface flags.  To complement @UNIOCSIFFLAGS@.
160  */
161
162 #define UNIOCGIFFLAGS _IO('U', 9)
163
164 /* --- @UNIOCSIFFLAGS@ --- *
165  *
166  * Sets interface flags.  This is required because there's no other sensible
167  * way to (e.g.) change the point-to-point flag.
168  */
169
170 #define UNIOCSIFFLAGS _IO('U', 10)
171
172 /*----- That's all, folks -------------------------------------------------*/
173
174 #ifdef __cplusplus
175   }
176 #endif
177
178 #endif