vdetelweb 1.2
[vde.git] / ipn / af_ipn.h
blob57d51dcbaccabaf0132b09ff468a4b96c209faaa
1 #ifndef __LINUX_NET_AFIPN_H
2 #define __LINUX_NET_AFIPN_H
3 #include <linux/socket.h>
4 #include <linux/version.h>
6 #ifdef IPN_STEALING
7 /* AF_NETBEUI seems to be unused */
8 #define AF_IPN AF_NETBEUI
9 #define PF_IPN AF_IPN
10 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37)
11 #define ipn_handle_frame_hook br_handle_frame_hook
12 #endif
13 #else
14 #ifndef AF_IPN
15 /* waiting for the official assigment of our AF */
16 /* #define AF_IPN ??? */
17 #define AF_IPN AF_NETBEUI
18 #define PF_IPN AF_IPN
19 #endif
20 #define AF_IPN_STOLEN AF_NETBEUI
21 #define PF_IPN_STOLEN AF_IPN_STOLEN
22 #endif
24 #define IPN_ANY 0
25 #define IPN_BROADCAST 1
26 #define IPN_HUB 1
27 #define IPN_VDESWITCH 2
28 #define IPN_VDESWITCH_L3 3
30 #define IPN_SO_PREBIND 0x80
31 #define IPN_SO_PORT 0
32 #define IPN_SO_DESCR 1
33 #define IPN_SO_CHANGE_NUMNODES 2
34 #define IPN_SO_HANDLE_OOB 3
35 #define IPN_SO_WANT_OOB_NUMNODES 4
36 #define IPN_SO_MTU (IPN_SO_PREBIND | 0)
37 #define IPN_SO_NUMNODES (IPN_SO_PREBIND | 1)
38 #define IPN_SO_MSGPOOLSIZE (IPN_SO_PREBIND | 2)
39 #define IPN_SO_FLAGS (IPN_SO_PREBIND | 3)
40 #define IPN_SO_MODE (IPN_SO_PREBIND | 4)
42 #define IPN_PORTNO_ANY -1
44 #define IPN_DESCRLEN 128
46 #define IPN_FLAG_LOSSLESS 1
47 #define IPN_FLAG_EXCL 2
48 #define IPN_FLAG_FLEXMTU 4
49 #define IPN_FLAG_TERMINATED 0x1000
51 /* ioctl request for IPN_REGISTER_CHRDEV
52 * @dev: first device (if major==0 alloc a dynamic major)
53 * @count: num of minors
54 * @name: device name
55 * */
56 struct chrdevreq {
57 unsigned int major;
58 unsigned int minor;
59 int count;
60 char name[64];
63 /* Ioctl defines */
65 #define IPN_CHECK _IO('I', 199)
66 #define IPN_SETPERSIST_NETDEV _IOR('I', 200, struct ifreq)
67 #define IPN_CLRPERSIST_NETDEV _IOR('I', 201, struct ifreq)
68 #define IPN_CONN_NETDEV _IOR('I', 202, struct ifreq)
69 #define IPN_JOIN_NETDEV _IOR('I', 203, struct ifreq)
70 #define IPN_SETPERSIST _IOR('I', 204, struct ifreq)
71 #define IPN_REGISTER_CHRDEV _IOWR('I', 301, struct chrdevreq)
72 #define IPN_UNREGISTER_CHRDEV _IO('I', 302)
73 #define IPN_JOIN_CHRDEV _IOR('I', 303, struct chrdevreq)
74 #define IPN_CHRDEV_PERSIST _IOR('I', 304, int)
76 #define IPN_OOB_NUMNODE_TAG 0
78 /* OOB message for change of numnodes
79 * Common fields for oob IPN signaling:
80 * @level=level of the service who generated the oob
81 * @tag=tag of the message
82 * Specific fields:
83 * @numreaders=number of readers
84 * @numwriters=number of writers
85 * */
86 struct numnode_oob {
87 int level;
88 int tag;
89 int numreaders;
90 int numwriters;
93 /* these flags are used in IPN_CONN_NETDEV*/
94 #define IPN_NODEFLAG_TAP 0x10 /* This is a tap interface */
95 #define IPN_NODEFLAG_GRAB 0x20 /* This is a grab of a real interface */
97 #ifdef __KERNEL__
98 #include <linux/version.h>
100 #include <linux/mutex.h>
101 #include <linux/un.h>
102 #include <linux/poll.h>
103 #include <linux/device.h>
104 #include <net/sock.h>
105 #include <linux/netdevice.h>
107 #define IPN_HASH_SIZE 256
109 /* The AF_IPN socket */
110 struct msgpool_item;
111 struct ipn_network;
112 struct pre_bind_parms;
115 * ipn_node
117 * @nodelist=pointers for connectqueue or unconnectqueue (see network)
118 * @protocol=kind of service 0->standard broadcast
119 * @flags= see IPN_NODEFLAG_xxx
120 * @shutdown= SEND_SHUTDOWN/RCV_SHUTDOWN and OOBRCV_SHUTDOWN
121 * @descr=description of this port
122 * @portno=when connected: port of the netowrk (<0 means unconnected)
123 * @msglock=mutex on the msg queue
124 * @totmsgcount=total # of pending msgs
125 * @oobmsgcount=# of pending oob msgs
126 * @msgqueue=queue of messages
127 * @oobmsgqueue=queue of messages
128 * @read_wait=waitqueue for reading
129 * @net=current network
130 * @dev=device (TAP or GRAB)
131 * @ipn=network we are connected to
132 * @pbp=temporary storage for parms that must be set prior to bind
133 * @proto_private=handle for protocol private data
135 struct ipn_node {
136 struct list_head nodelist;
137 int protocol;
138 volatile unsigned char flags;
139 unsigned char shutdown;
140 char descr[IPN_DESCRLEN];
141 int portno;
142 spinlock_t msglock;
143 unsigned short totmsgcount;
144 unsigned short oobmsgcount;
145 struct list_head msgqueue;
146 struct list_head oobmsgqueue;
147 wait_queue_head_t read_wait;
148 struct net *net;
149 struct net_device *netdev;
150 dev_t chrdev;
151 struct ipn_network *ipn;
152 struct pre_bind_parms *pbp;
153 void *proto_private;
155 #define IPN_NODEFLAG_BOUND 0x1 /* bind succeeded */
156 #define IPN_NODEFLAG_INUSE 0x2 /* is currently "used" (0 for persistent, unbound interfaces) */
157 #define IPN_NODEFLAG_PERSIST 0x4 /* if persist does not disappear on close (net interfaces) */
158 #if 0
159 /* these flags are used in IPN_CONN_NETDEV*/
160 #define IPN_NODEFLAG_TAP 0x10 /* This is a tap interface */
161 #define IPN_NODEFLAG_GRAB 0x20 /* This is a grab of a real interface */
162 #endif
163 #define IPN_NODEFLAG_DEVMASK 0x30 /* True if this is a device */
164 #define IPN_NODEFLAG_OOB_NUMNODES 0x40 /* Node wants OOB for NNODES */
167 * ipn_sock
169 * unfortunately we must use a struct sock (most of the fields are useless) as
170 * this is the standard "agnostic" structure for socket implementation.
171 * This proofs that it is not "agnostic" enough!
174 struct ipn_sock {
175 struct sock sk;
176 struct ipn_node *node;
179 /* ipn_chrdev cdev to ipn_dev mapping, defined in ipn_chrdev.c */
180 struct ipn_chrdev;
183 * ipn_network network descriptor
185 * @hnode=hash to find this entry (looking for i-node)
186 * @unconnectqueue=queue of unconnected (bound) nodes
187 * @connectqueue=queue of connected nodes (faster for broadcasting)
188 * @refcnt=reference count (bound or connected sockets)
189 * @dentry/@mnt=to keep the file system descriptor into memory
190 * @ipnn_lock=lock for protocol functions
191 * @protocol=kind of service
192 * @flags=flags (IPN_FLAG_LOSSLESS)
193 * @maxports=number of ports available in this network
194 * @msgpool_nelem=number of pending messages
195 * @msgpool_size=max number of pending messages *per net* when IPN_FLAG_LOSSLESS
196 * @msgpool_size=max number of pending messages *per port*when LOSSY
197 * @mtu=MTU
198 * @send_wait=wait queue waiting for a message in the msgpool (IPN_FLAG_LOSSLESS)
199 * @msgpool_cache=slab for msgpool (unused yet)
200 * @proto_private=handle for protocol private data
201 * @connports=array of connected sockets
202 * @chrdev=chr device(s) connected to this ipn_network
204 struct ipn_network {
205 struct hlist_node hnode;
206 struct list_head unconnectqueue;
207 struct list_head connectqueue;
208 int refcnt;
209 struct dentry *dentry;
210 struct vfsmount *mnt;
211 struct semaphore ipnn_mutex;
212 int sunaddr_len;
213 struct sockaddr_un sunaddr;
214 unsigned int protocol;
215 unsigned int flags;
216 int numreaders;
217 int numwriters;
218 atomic_t msgpool_nelem;
219 unsigned short maxports;
220 unsigned short msgpool_size;
221 unsigned short mtu;
222 wait_queue_head_t send_wait;
223 struct kmem_cache *msgpool_cache;
224 void *proto_private;
225 struct ipn_node **connport;
226 struct ipn_chrdev *chrdev;
229 /* struct msgpool_item
230 * the local copy of the message for dispatching
231 * @count refcount
232 * @len packet len
233 * @data payload
235 struct msgpool_item {
236 atomic_t count;
237 int len;
238 unsigned char data[0];
241 struct msgpool_item *ipn_msgpool_alloc(struct ipn_network *ipnn,int leaky,int len);
242 void ipn_msgpool_put(struct msgpool_item *old, struct ipn_network *ipnn);
245 * protocol service:
247 * @refcnt: number of networks using this protocol
248 * @newport=upcall for reporting a new port. returns the portno, -1=error
249 * @handlemsg=dispatch a message.
250 * should call ipn_proto_sendmsg for each desctination
251 * can allocate other msgitems using ipn_msgpool_alloc to send
252 * different messages to different destinations;
253 * @delport=(may be null) reports the terminatio of a port
254 * @postnewport,@predelport: similar to newport/delport but during these calls
255 * the node is (still) connected. Useful when protocols need
256 * welcome and goodbye messages.
257 * @ipn_p_setsockopt
258 * @ipn_p_getsockopt
259 * @ipn_p_ioctl=(may be null) upcall to manage specific options or ctls.
261 struct ipn_protocol {
262 int refcnt;
263 int (*ipn_p_newport)(struct ipn_node *newport);
264 int (*ipn_p_handlemsg)(struct ipn_node *from,struct msgpool_item *msgitem);
265 void (*ipn_p_delport)(struct ipn_node *oldport);
266 void (*ipn_p_postnewport)(struct ipn_node *newport);
267 void (*ipn_p_predelport)(struct ipn_node *oldport);
268 int (*ipn_p_newnet)(struct ipn_network *newnet);
269 int (*ipn_p_resizenet)(struct ipn_network *net,int oldsize,int newsize);
270 void (*ipn_p_delnet)(struct ipn_network *oldnet);
271 int (*ipn_p_setsockopt)(struct ipn_node *port,int optname,
272 char __user *optval, int optlen);
273 int (*ipn_p_getsockopt)(struct ipn_node *port,int optname,
274 char __user *optval, int *optlen);
275 int (*ipn_p_ioctl)(struct ipn_node *port,unsigned int request,
276 unsigned long arg);
279 int ipn_proto_register(int protocol,struct ipn_protocol *ipn_service);
280 int ipn_proto_deregister(int protocol);
282 int ipn_proto_injectmsg(struct ipn_node *from, struct msgpool_item *msg);
283 void ipn_proto_sendmsg(struct ipn_node *to, struct msgpool_item *msg);
284 void ipn_proto_oobsendmsg(struct ipn_node *to, struct msgpool_item *msg);
286 struct ipn_node *ipn_node_create(struct net *net);
287 int ipn_node_connect(struct ipn_node *ipn_node);
288 int ipn_node_create_connect(struct ipn_node **ipn_node_out,
289 struct ipn_network *(* ipnn_map)(void *),void *ipnn_map_arg);
290 int ipn_node_release(struct ipn_node *ipn_node);
291 unsigned int ipn_node_poll(struct ipn_node *ipn_node, struct file *file, poll_table *wait);
292 int ipn_node_ioctl(struct ipn_node *ipn_node, unsigned int cmd, unsigned long arg);
293 int ipn_node_write(struct ipn_node *ipn_node, struct iovec *msg_iov, int len);
294 int ipn_node_read(struct ipn_node *ipn_node, struct iovec *msg_iov, size_t len, int *msg_flags, int flags);
295 struct ipn_network *ipn_find_network_byfun(
296 int (*fun)(struct ipn_network *,void *),void *funarg);
298 #ifndef IPN_STEALING
299 extern struct sk_buff *(*ipn_handle_frame_hook)(struct ipn_node *p,
300 struct sk_buff *skb);
301 #endif
302 #endif
303 #endif