ipn_node: dev renamed as netdev, new chrdev field added
[vde.git] / ipn / af_ipn.h
blobcde82fa6aef600b87d3cfd78e7ef9130bde720b1
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 defines */
49 #define IPN_CHECK _IOW('I', 199, int)
50 #define IPN_SETPERSIST_NETDEV _IOW('I', 200, int)
51 #define IPN_CLRPERSIST_NETDEV _IOW('I', 201, int)
52 #define IPN_CONN_NETDEV _IOW('I', 202, int)
53 #define IPN_JOIN_NETDEV _IOW('I', 203, int)
54 #define IPN_SETPERSIST _IOW('I', 204, int)
55 #define IPN_REGISTER_CHRDEV _IOW('I', 301, int)
56 #define IPN_UNREGISTER_CHRDEV _IOW('I', 302, int)
58 #define IPN_OOB_NUMNODE_TAG 0
60 /* ioctl request for IPN_REGISTER_CHRDEV
61 * @dev: first device (if major==0 alloc a dynamic major)
62 * @count: num of minors
63 * @name: device name
64 * */
65 struct chrdevreq {
66 unsigned int major;
67 unsigned int minor;
68 int count;
69 char name[64];
72 /* OOB message for change of numnodes
73 * Common fields for oob IPN signaling:
74 * @level=level of the service who generated the oob
75 * @tag=tag of the message
76 * Specific fields:
77 * @numreaders=number of readers
78 * @numwriters=number of writers
79 * */
80 struct numnode_oob {
81 int level;
82 int tag;
83 int numreaders;
84 int numwriters;
87 #ifdef __KERNEL__
88 #include <linux/version.h>
89 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
90 #define kmem_cache_create(A,B,C,D,E) kmem_cache_create((A),(B),(C),(D),(E),(E))
91 #endif
93 #include <linux/mutex.h>
94 #include <linux/un.h>
95 #include <linux/poll.h>
96 #include <linux/device.h>
97 #include <net/sock.h>
98 #include <linux/netdevice.h>
100 #define IPN_HASH_SIZE 256
102 /* The AF_IPN socket */
103 struct msgpool_item;
104 struct ipn_network;
105 struct pre_bind_parms;
108 * ipn_node
110 * @nodelist=pointers for connectqueue or unconnectqueue (see network)
111 * @protocol=kind of service 0->standard broadcast
112 * @flags= see IPN_NODEFLAG_xxx
113 * @shutdown= SEND_SHUTDOWN/RCV_SHUTDOWN and OOBRCV_SHUTDOWN
114 * @descr=description of this port
115 * @portno=when connected: port of the netowrk (<0 means unconnected)
116 * @msglock=mutex on the msg queue
117 * @totmsgcount=total # of pending msgs
118 * @oobmsgcount=# of pending oob msgs
119 * @msgqueue=queue of messages
120 * @oobmsgqueue=queue of messages
121 * @read_wait=waitqueue for reading
122 * @net=current network
123 * @dev=device (TAP or GRAB)
124 * @ipn=network we are connected to
125 * @pbp=temporary storage for parms that must be set prior to bind
126 * @proto_private=handle for protocol private data
128 struct ipn_node {
129 struct list_head nodelist;
130 int protocol;
131 volatile unsigned char flags;
132 unsigned char shutdown;
133 char descr[IPN_DESCRLEN];
134 int portno;
135 spinlock_t msglock;
136 unsigned short totmsgcount;
137 unsigned short oobmsgcount;
138 struct list_head msgqueue;
139 struct list_head oobmsgqueue;
140 wait_queue_head_t read_wait;
141 struct net *net;
142 struct net_device *netdev;
143 dev_t chrdev;
144 struct ipn_network *ipn;
145 struct pre_bind_parms *pbp;
146 void *proto_private;
148 #define IPN_NODEFLAG_BOUND 0x1 /* bind succeeded */
149 #define IPN_NODEFLAG_INUSE 0x2 /* is currently "used" (0 for persistent, unbound interfaces) */
150 #define IPN_NODEFLAG_PERSIST 0x4 /* if persist does not disappear on close (net interfaces) */
151 #define IPN_NODEFLAG_TAP 0x10 /* This is a tap interface */
152 #define IPN_NODEFLAG_GRAB 0x20 /* This is a grab of a real interface */
153 #define IPN_NODEFLAG_DEVMASK 0x30 /* True if this is a device */
154 #define IPN_NODEFLAG_OOB_NUMNODES 0x40 /* Node wants OOB for NNODES */
157 * ipn_sock
159 * unfortunately we must use a struct sock (most of the fields are useless) as
160 * this is the standard "agnostic" structure for socket implementation.
161 * This proofs that it is not "agnostic" enough!
164 struct ipn_sock {
165 struct sock sk;
166 struct ipn_node *node;
169 /* ipn_chrdev cdev to ipn_dev mapping, defined in ipn_chrdev.c */
170 struct ipn_chrdev;
173 * ipn_network network descriptor
175 * @hnode=hash to find this entry (looking for i-node)
176 * @unconnectqueue=queue of unconnected (bound) nodes
177 * @connectqueue=queue of connected nodes (faster for broadcasting)
178 * @refcnt=reference count (bound or connected sockets)
179 * @dentry/@mnt=to keep the file system descriptor into memory
180 * @ipnn_lock=lock for protocol functions
181 * @protocol=kind of service
182 * @flags=flags (IPN_FLAG_LOSSLESS)
183 * @maxports=number of ports available in this network
184 * @msgpool_nelem=number of pending messages
185 * @msgpool_size=max number of pending messages *per net* when IPN_FLAG_LOSSLESS
186 * @msgpool_size=max number of pending messages *per port*when LOSSY
187 * @mtu=MTU
188 * @send_wait=wait queue waiting for a message in the msgpool (IPN_FLAG_LOSSLESS)
189 * @msgpool_cache=slab for msgpool (unused yet)
190 * @proto_private=handle for protocol private data
191 * @connports=array of connected sockets
192 * @chrdev=chr device(s) connected to this ipn_network
194 struct ipn_network {
195 struct hlist_node hnode;
196 struct list_head unconnectqueue;
197 struct list_head connectqueue;
198 int refcnt;
199 struct dentry *dentry;
200 struct vfsmount *mnt;
201 struct semaphore ipnn_mutex;
202 int sunaddr_len;
203 struct sockaddr_un sunaddr;
204 unsigned int protocol;
205 unsigned int flags;
206 int numreaders;
207 int numwriters;
208 atomic_t msgpool_nelem;
209 unsigned short maxports;
210 unsigned short msgpool_size;
211 unsigned short mtu;
212 wait_queue_head_t send_wait;
213 struct kmem_cache *msgpool_cache;
214 void *proto_private;
215 struct ipn_node **connport;
216 struct ipn_chrdev *chrdev;
219 /* struct msgpool_item
220 * the local copy of the message for dispatching
221 * @count refcount
222 * @len packet len
223 * @data payload
225 struct msgpool_item {
226 atomic_t count;
227 int len;
228 unsigned char data[0];
231 struct msgpool_item *ipn_msgpool_alloc(struct ipn_network *ipnn,int leaky,int len);
232 void ipn_msgpool_put(struct msgpool_item *old, struct ipn_network *ipnn);
235 * protocol service:
237 * @refcnt: number of networks using this protocol
238 * @newport=upcall for reporting a new port. returns the portno, -1=error
239 * @handlemsg=dispatch a message.
240 * should call ipn_proto_sendmsg for each desctination
241 * can allocate other msgitems using ipn_msgpool_alloc to send
242 * different messages to different destinations;
243 * @delport=(may be null) reports the terminatio of a port
244 * @postnewport,@predelport: similar to newport/delport but during these calls
245 * the node is (still) connected. Useful when protocols need
246 * welcome and goodbye messages.
247 * @ipn_p_setsockopt
248 * @ipn_p_getsockopt
249 * @ipn_p_ioctl=(may be null) upcall to manage specific options or ctls.
251 struct ipn_protocol {
252 int refcnt;
253 int (*ipn_p_newport)(struct ipn_node *newport);
254 int (*ipn_p_handlemsg)(struct ipn_node *from,struct msgpool_item *msgitem);
255 void (*ipn_p_delport)(struct ipn_node *oldport);
256 void (*ipn_p_postnewport)(struct ipn_node *newport);
257 void (*ipn_p_predelport)(struct ipn_node *oldport);
258 int (*ipn_p_newnet)(struct ipn_network *newnet);
259 int (*ipn_p_resizenet)(struct ipn_network *net,int oldsize,int newsize);
260 void (*ipn_p_delnet)(struct ipn_network *oldnet);
261 int (*ipn_p_setsockopt)(struct ipn_node *port,int optname,
262 char __user *optval, int optlen);
263 int (*ipn_p_getsockopt)(struct ipn_node *port,int optname,
264 char __user *optval, int *optlen);
265 int (*ipn_p_ioctl)(struct ipn_node *port,unsigned int request,
266 unsigned long arg);
269 int ipn_proto_register(int protocol,struct ipn_protocol *ipn_service);
270 int ipn_proto_deregister(int protocol);
272 int ipn_proto_injectmsg(struct ipn_node *from, struct msgpool_item *msg);
273 void ipn_proto_sendmsg(struct ipn_node *to, struct msgpool_item *msg);
274 void ipn_proto_oobsendmsg(struct ipn_node *to, struct msgpool_item *msg);
276 struct ipn_node *ipn_node_create(struct net *net);
277 int ipn_node_connect(struct ipn_node *ipn_node);
278 int ipn_node_create_connect(struct ipn_node **ipn_node_out,
279 struct ipn_network *(* ipnn_map)(void *),void *ipnn_map_arg);
280 int ipn_node_release(struct ipn_node *ipn_node);
281 unsigned int ipn_node_poll(struct ipn_node *ipn_node, struct file *file, poll_table *wait);
282 int ipn_node_ioctl(struct ipn_node *ipn_node, unsigned int cmd, unsigned long arg);
283 int ipn_node_write(struct ipn_node *ipn_node, struct iovec *msg_iov, int len);
284 int ipn_node_read(struct ipn_node *ipn_node, struct iovec *msg_iov, size_t len, int *msg_flags, int flags);
286 #ifndef IPN_STEALING
287 extern struct sk_buff *(*ipn_handle_frame_hook)(struct ipn_node *p,
288 struct sk_buff *skb);
289 #endif
290 #endif
291 #endif