tagging vde-2 version 2.3.2
[vde.git] / 2.3.2 / src / kvde_switch / af_ipn.h
blobf8eb3498467f17db660ba3e075c50df4ebaa47c1
1 #ifndef __LINUX_NET_AFIPN_H
2 #define __LINUX_NET_AFIPN_H
3 #include <linux/socket.h>
5 #ifdef IPN_STEALING
6 /* AF_NETBEUI seems to be unused */
7 #define AF_IPN AF_NETBEUI
8 #define PF_IPN AF_IPN
9 #define ipn_handle_frame_hook br_handle_frame_hook
10 #else
11 #ifndef AF_IPN
12 /* waiting for the official assigment of our AF */
13 /* #define AF_IPN ??? */
14 #define AF_IPN AF_NETBEUI
15 #define PF_IPN AF_IPN
16 #endif
17 #define AF_IPN_STOLEN AF_NETBEUI
18 #define PF_IPN_STOLEN AF_IPN_STOLEN
19 #endif
21 #define IPN_ANY 0
22 #define IPN_BROADCAST 1
23 #define IPN_HUB 1
24 #define IPN_VDESWITCH 2
25 #define IPN_VDESWITCH_L3 3
27 #define IPN_SO_PREBIND 0x80
28 #define IPN_SO_PORT 0
29 #define IPN_SO_DESCR 1
30 #define IPN_SO_CHANGE_NUMNODES 2
31 #define IPN_SO_HANDLE_OOB 3
32 #define IPN_SO_WANT_OOB_NUMNODES 4
33 #define IPN_SO_MTU (IPN_SO_PREBIND | 0)
34 #define IPN_SO_NUMNODES (IPN_SO_PREBIND | 1)
35 #define IPN_SO_MSGPOOLSIZE (IPN_SO_PREBIND | 2)
36 #define IPN_SO_FLAGS (IPN_SO_PREBIND | 3)
37 #define IPN_SO_MODE (IPN_SO_PREBIND | 4)
39 #define IPN_PORTNO_ANY -1
41 #define IPN_DESCRLEN 128
43 #define IPN_FLAG_LOSSLESS 1
44 #define IPN_FLAG_EXCL 2
45 #define IPN_FLAG_FLEXMTU 4
46 #define IPN_FLAG_TERMINATED 0x1000
48 /* ioctl request for IPN_REGISTER_CHRDEV
49 * @dev: first device (if major==0 alloc a dynamic major)
50 * @count: num of minors
51 * @name: device name
52 * */
53 struct chrdevreq {
54 unsigned int major;
55 unsigned int minor;
56 int count;
57 char name[64];
60 /* Ioctl defines */
62 #define IPN_CHECK _IO('I', 199)
63 #define IPN_SETPERSIST_NETDEV _IOR('I', 200, struct ifreq)
64 #define IPN_CLRPERSIST_NETDEV _IOR('I', 201, struct ifreq)
65 #define IPN_CONN_NETDEV _IOR('I', 202, struct ifreq)
66 #define IPN_JOIN_NETDEV _IOR('I', 203, struct ifreq)
67 #define IPN_SETPERSIST _IOR('I', 204, struct ifreq)
68 #define IPN_REGISTER_CHRDEV _IOWR('I', 301, struct chrdevreq)
69 #define IPN_UNREGISTER_CHRDEV _IO('I', 302)
70 #define IPN_JOIN_CHRDEV _IOR('I', 303, struct chrdevreq)
71 #define IPN_CHRDEV_PERSIST _IOR('I', 304, int)
73 #define IPN_OOB_NUMNODE_TAG 0
75 /* OOB message for change of numnodes
76 * Common fields for oob IPN signaling:
77 * @level=level of the service who generated the oob
78 * @tag=tag of the message
79 * Specific fields:
80 * @numreaders=number of readers
81 * @numwriters=number of writers
82 * */
83 struct numnode_oob {
84 int level;
85 int tag;
86 int numreaders;
87 int numwriters;
90 /* these flags are used in IPN_CONN_NETDEV*/
91 #define IPN_NODEFLAG_TAP 0x10 /* This is a tap interface */
92 #define IPN_NODEFLAG_GRAB 0x20 /* This is a grab of a real interface */
94 #ifdef __KERNEL__
95 #include <linux/version.h>
96 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
97 #define kmem_cache_create(A,B,C,D,E) kmem_cache_create((A),(B),(C),(D),(E),(E))
98 #endif
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