Gaussian distribution for range values, Gilbert bursty model for packet loss.
[vde.git] / ipn / af_ipn.h
blob7940aab3dfc9859f8b25927e167e8d045483387a
1 #ifndef __LINUX_NET_AFIPN_H
2 #define __LINUX_NET_AFIPN_H
4 #ifdef IPN_STEALING
5 /* AF_NETBEUI seems to be unused */
6 #define AF_IPN AF_NETBEUI
7 #define PF_IPN AF_IPN
8 #define ipn_handle_frame_hook br_handle_frame_hook
9 #endif
11 #define IPN_ANY 0
12 #define IPN_BROADCAST 1
13 #define IPN_HUB 1
14 #define IPN_VDESWITCH 2
15 #define IPN_VDESWITCH_L3 3
17 #define IPN_SO_PREBIND 0x80
18 #define IPN_SO_PORT 0
19 #define IPN_SO_DESCR 1
20 #define IPN_SO_CHANGE_NUMNODES 2
21 #define IPN_SO_HANDLE_OOB 3
22 #define IPN_SO_WANT_OOB_NUMNODES 4
23 #define IPN_SO_MTU (IPN_SO_PREBIND | 0)
24 #define IPN_SO_NUMNODES (IPN_SO_PREBIND | 1)
25 #define IPN_SO_MSGPOOLSIZE (IPN_SO_PREBIND | 2)
26 #define IPN_SO_FLAGS (IPN_SO_PREBIND | 3)
27 #define IPN_SO_MODE (IPN_SO_PREBIND | 4)
29 #define IPN_PORTNO_ANY -1
31 #define IPN_DESCRLEN 128
33 #define IPN_FLAG_LOSSLESS 1
34 #define IPN_FLAG_EXCL 2
35 #define IPN_FLAG_TERMINATED 0x1000
37 /* Ioctl defines */
38 #define IPN_CHECK _IOW('I', 199, int)
39 #define IPN_SETPERSIST_NETDEV _IOW('I', 200, int)
40 #define IPN_CLRPERSIST_NETDEV _IOW('I', 201, int)
41 #define IPN_CONN_NETDEV _IOW('I', 202, int)
42 #define IPN_JOIN_NETDEV _IOW('I', 203, int)
43 #define IPN_SETPERSIST _IOW('I', 204, int)
45 #define IPN_OOB_NUMNODE_TAG 0
47 /* OOB message for change of numnodes
48 * Common fields for oob IPN signaling:
49 * @level=level of the service who generated the oob
50 * @tag=tag of the message
51 * Specific fields:
52 * @numreaders=number of readers
53 * @numwriters=number of writers
54 * */
55 struct numnode_oob {
56 int level;
57 int tag;
58 int numreaders;
59 int numwriters;
62 #ifdef __KERNEL__
63 #include <linux/version.h>
64 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
65 #define kmem_cache_create(A,B,C,D,E) kmem_cache_create((A),(B),(C),(D),(E),(E))
66 #endif
68 #include <linux/socket.h>
69 #include <linux/mutex.h>
70 #include <linux/un.h>
71 #include <net/sock.h>
72 #include <linux/netdevice.h>
74 #define IPN_HASH_SIZE 256
76 /* The AF_IPN socket */
77 struct msgpool_item;
78 struct ipn_network;
79 struct pre_bind_parms;
81 /*
82 * ipn_node
84 * @nodelist=pointers for connectqueue or unconnectqueue (see network)
85 * @protocol=kind of service 0->standard broadcast
86 * @flags= see IPN_NODEFLAG_xxx
87 * @shutdown= SEND_SHUTDOWN/RCV_SHUTDOWN and OOBRCV_SHUTDOWN
88 * @descr=description of this port
89 * @portno=when connected: port of the netowrk (<0 means unconnected)
90 * @msglock=mutex on the msg queue
91 * @totmsgcount=total # of pending msgs
92 * @oobmsgcount=# of pending oob msgs
93 * @msgqueue=queue of messages
94 * @oobmsgqueue=queue of messages
95 * @read_wait=waitqueue for reading
96 * @net=current network
97 * @dev=device (TAP or GRAB)
98 * @ipn=network we are connected to
99 * @pbp=temporary storage for parms that must be set prior to bind
100 * @proto_private=handle for protocol private data
102 struct ipn_node {
103 struct list_head nodelist;
104 int protocol;
105 volatile unsigned char flags;
106 unsigned char shutdown;
107 char descr[IPN_DESCRLEN];
108 int portno;
109 spinlock_t msglock;
110 unsigned short totmsgcount;
111 unsigned short oobmsgcount;
112 struct list_head msgqueue;
113 struct list_head oobmsgqueue;
114 wait_queue_head_t read_wait;
115 struct net *net;
116 struct net_device *dev;
117 struct ipn_network *ipn;
118 struct pre_bind_parms *pbp;
119 void *proto_private;
121 #define IPN_NODEFLAG_BOUND 0x1 /* bind succeeded */
122 #define IPN_NODEFLAG_INUSE 0x2 /* is currently "used" (0 for persistent, unbound interfaces) */
123 #define IPN_NODEFLAG_PERSIST 0x4 /* if persist does not disappear on close (net interfaces) */
124 #define IPN_NODEFLAG_TAP 0x10 /* This is a tap interface */
125 #define IPN_NODEFLAG_GRAB 0x20 /* This is a grab of a real interface */
126 #define IPN_NODEFLAG_DEVMASK 0x30 /* True if this is a device */
127 #define IPN_NODEFLAG_OOB_NUMNODES 0x40 /* Node wants OOB for NNODES */
130 * ipn_sock
132 * unfortunately we must use a struct sock (most of the fields are useless) as
133 * this is the standard "agnostic" structure for socket implementation.
134 * This proofs that it is not "agnostic" enough!
137 struct ipn_sock {
138 struct sock sk;
139 struct ipn_node *node;
143 * ipn_network network descriptor
145 * @hnode=hash to find this entry (looking for i-node)
146 * @unconnectqueue=queue of unconnected (bound) nodes
147 * @connectqueue=queue of connected nodes (faster for broadcasting)
148 * @refcnt=reference count (bound or connected sockets)
149 * @dentry/@mnt=to keep the file system descriptor into memory
150 * @ipnn_lock=lock for protocol functions
151 * @protocol=kind of service
152 * @flags=flags (IPN_FLAG_LOSSLESS)
153 * @maxports=number of ports available in this network
154 * @msgpool_nelem=number of pending messages
155 * @msgpool_size=max number of pending messages *per net* when IPN_FLAG_LOSSLESS
156 * @msgpool_size=max number of pending messages *per port*when LOSSY
157 * @mtu=MTU
158 * @send_wait=wait queue waiting for a message in the msgpool (IPN_FLAG_LOSSLESS)
159 * @msgpool_cache=slab for msgpool (unused yet)
160 * @proto_private=handle for protocol private data
161 * @connports=array of connected sockets
163 struct ipn_network {
164 struct hlist_node hnode;
165 struct list_head unconnectqueue;
166 struct list_head connectqueue;
167 int refcnt;
168 struct dentry *dentry;
169 struct vfsmount *mnt;
170 struct semaphore ipnn_mutex;
171 int sunaddr_len;
172 struct sockaddr_un sunaddr;
173 unsigned int protocol;
174 unsigned int flags;
175 int numreaders;
176 int numwriters;
177 atomic_t msgpool_nelem;
178 unsigned short maxports;
179 unsigned short msgpool_size;
180 unsigned short mtu;
181 wait_queue_head_t send_wait;
182 struct kmem_cache *msgpool_cache;
183 void *proto_private;
184 struct ipn_node **connport;
187 /* struct msgpool_item
188 * the local copy of the message for dispatching
189 * @count refcount
190 * @len packet len
191 * @data payload
193 struct msgpool_item {
194 atomic_t count;
195 int len;
196 unsigned char data[0];
199 struct msgpool_item *ipn_msgpool_alloc(struct ipn_network *ipnn,int leaky);
200 void ipn_msgpool_put(struct msgpool_item *old, struct ipn_network *ipnn);
203 * protocol service:
205 * @refcnt: number of networks using this protocol
206 * @newport=upcall for reporting a new port. returns the portno, -1=error
207 * @handlemsg=dispatch a message.
208 * should call ipn_proto_sendmsg for each desctination
209 * can allocate other msgitems using ipn_msgpool_alloc to send
210 * different messages to different destinations;
211 * @delport=(may be null) reports the terminatio of a port
212 * @postnewport,@predelport: similar to newport/delport but during these calls
213 * the node is (still) connected. Useful when protocols need
214 * welcome and goodbye messages.
215 * @ipn_p_setsockopt
216 * @ipn_p_getsockopt
217 * @ipn_p_ioctl=(may be null) upcall to manage specific options or ctls.
219 struct ipn_protocol {
220 int refcnt;
221 int (*ipn_p_newport)(struct ipn_node *newport);
222 int (*ipn_p_handlemsg)(struct ipn_node *from,struct msgpool_item *msgitem);
223 void (*ipn_p_delport)(struct ipn_node *oldport);
224 void (*ipn_p_postnewport)(struct ipn_node *newport);
225 void (*ipn_p_predelport)(struct ipn_node *oldport);
226 int (*ipn_p_newnet)(struct ipn_network *newnet);
227 int (*ipn_p_resizenet)(struct ipn_network *net,int oldsize,int newsize);
228 void (*ipn_p_delnet)(struct ipn_network *oldnet);
229 int (*ipn_p_setsockopt)(struct ipn_node *port,int optname,
230 char __user *optval, int optlen);
231 int (*ipn_p_getsockopt)(struct ipn_node *port,int optname,
232 char __user *optval, int *optlen);
233 int (*ipn_p_ioctl)(struct ipn_node *port,unsigned int request,
234 unsigned long arg);
237 int ipn_proto_register(int protocol,struct ipn_protocol *ipn_service);
238 int ipn_proto_deregister(int protocol);
240 int ipn_proto_injectmsg(struct ipn_node *from, struct msgpool_item *msg);
241 void ipn_proto_sendmsg(struct ipn_node *to, struct msgpool_item *msg);
242 void ipn_proto_oobsendmsg(struct ipn_node *to, struct msgpool_item *msg);
244 #ifndef IPN_STEALING
245 extern struct sk_buff *(*ipn_handle_frame_hook)(struct ipn_node *p,
246 struct sk_buff *skb);
247 #endif
248 #endif
249 #endif