1 #ifndef __LINUX_NET_AFIPN_H
2 #define __LINUX_NET_AFIPN_H
3 #include <linux/socket.h>
4 #include <linux/version.h>
7 /* AF_NETBEUI seems to be unused */
8 #define AF_IPN AF_NETBEUI
10 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37)
11 #define ipn_handle_frame_hook br_handle_frame_hook
15 /* waiting for the official assigment of our AF */
16 /* #define AF_IPN ??? */
17 #define AF_IPN AF_NETBEUI
20 #define AF_IPN_STOLEN AF_NETBEUI
21 #define PF_IPN_STOLEN AF_IPN_STOLEN
25 #define IPN_BROADCAST 1
27 #define IPN_VDESWITCH 2
28 #define IPN_VDESWITCH_L3 3
30 #define IPN_SO_PREBIND 0x80
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
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
83 * @numreaders=number of readers
84 * @numwriters=number of writers
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 */
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 */
112 struct pre_bind_parms
;
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
136 struct list_head nodelist
;
138 volatile unsigned char flags
;
139 unsigned char shutdown
;
140 char descr
[IPN_DESCRLEN
];
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
;
149 struct net_device
*netdev
;
151 struct ipn_network
*ipn
;
152 struct pre_bind_parms
*pbp
;
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) */
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 */
163 #define IPN_NODEFLAG_DEVMASK 0x30 /* True if this is a device */
164 #define IPN_NODEFLAG_OOB_NUMNODES 0x40 /* Node wants OOB for NNODES */
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!
176 struct ipn_node
*node
;
179 /* ipn_chrdev cdev to ipn_dev mapping, defined in ipn_chrdev.c */
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
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
205 struct hlist_node hnode
;
206 struct list_head unconnectqueue
;
207 struct list_head connectqueue
;
209 struct dentry
*dentry
;
210 struct vfsmount
*mnt
;
211 struct semaphore ipnn_mutex
;
213 struct sockaddr_un sunaddr
;
214 unsigned int protocol
;
218 atomic_t msgpool_nelem
;
219 unsigned short maxports
;
220 unsigned short msgpool_size
;
222 wait_queue_head_t send_wait
;
223 struct kmem_cache
*msgpool_cache
;
225 struct ipn_node
**connport
;
226 struct ipn_chrdev
*chrdev
;
229 /* struct msgpool_item
230 * the local copy of the message for dispatching
235 struct msgpool_item
{
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
);
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.
259 * @ipn_p_ioctl=(may be null) upcall to manage specific options or ctls.
261 struct ipn_protocol
{
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
,
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
);
299 extern struct sk_buff
*(*ipn_handle_frame_hook
)(struct ipn_node
*p
,
300 struct sk_buff
*skb
);