1 #ifndef __LINUX_NET_AFIPN_H
2 #define __LINUX_NET_AFIPN_H
3 #include <linux/socket.h>
6 /* AF_NETBEUI seems to be unused */
7 #define AF_IPN AF_NETBEUI
9 #define ipn_handle_frame_hook br_handle_frame_hook
12 /* waiting for the official assigment of our AF */
13 /* #define AF_IPN ??? */
14 #define AF_IPN AF_NETBEUI
17 #define AF_IPN_STOLEN AF_NETBEUI
18 #define PF_IPN_STOLEN AF_IPN_STOLEN
22 #define IPN_BROADCAST 1
24 #define IPN_VDESWITCH 2
25 #define IPN_VDESWITCH_L3 3
27 #define IPN_SO_PREBIND 0x80
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_TERMINATED 0x1000
48 #define IPN_CHECK _IOW('I', 199, int)
49 #define IPN_SETPERSIST_NETDEV _IOW('I', 200, int)
50 #define IPN_CLRPERSIST_NETDEV _IOW('I', 201, int)
51 #define IPN_CONN_NETDEV _IOW('I', 202, int)
52 #define IPN_JOIN_NETDEV _IOW('I', 203, int)
53 #define IPN_SETPERSIST _IOW('I', 204, int)
55 #define IPN_OOB_NUMNODE_TAG 0
57 /* OOB message for change of numnodes
58 * Common fields for oob IPN signaling:
59 * @level=level of the service who generated the oob
60 * @tag=tag of the message
62 * @numreaders=number of readers
63 * @numwriters=number of writers
73 #include <linux/version.h>
74 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
75 #define kmem_cache_create(A,B,C,D,E) kmem_cache_create((A),(B),(C),(D),(E),(E))
78 #include <linux/mutex.h>
81 #include <linux/netdevice.h>
83 #define IPN_HASH_SIZE 256
85 /* The AF_IPN socket */
88 struct pre_bind_parms
;
93 * @nodelist=pointers for connectqueue or unconnectqueue (see network)
94 * @protocol=kind of service 0->standard broadcast
95 * @flags= see IPN_NODEFLAG_xxx
96 * @shutdown= SEND_SHUTDOWN/RCV_SHUTDOWN and OOBRCV_SHUTDOWN
97 * @descr=description of this port
98 * @portno=when connected: port of the netowrk (<0 means unconnected)
99 * @msglock=mutex on the msg queue
100 * @totmsgcount=total # of pending msgs
101 * @oobmsgcount=# of pending oob msgs
102 * @msgqueue=queue of messages
103 * @oobmsgqueue=queue of messages
104 * @read_wait=waitqueue for reading
105 * @net=current network
106 * @dev=device (TAP or GRAB)
107 * @ipn=network we are connected to
108 * @pbp=temporary storage for parms that must be set prior to bind
109 * @proto_private=handle for protocol private data
112 struct list_head nodelist
;
114 volatile unsigned char flags
;
115 unsigned char shutdown
;
116 char descr
[IPN_DESCRLEN
];
119 unsigned short totmsgcount
;
120 unsigned short oobmsgcount
;
121 struct list_head msgqueue
;
122 struct list_head oobmsgqueue
;
123 wait_queue_head_t read_wait
;
125 struct net_device
*dev
;
126 struct ipn_network
*ipn
;
127 struct pre_bind_parms
*pbp
;
130 #define IPN_NODEFLAG_BOUND 0x1 /* bind succeeded */
131 #define IPN_NODEFLAG_INUSE 0x2 /* is currently "used" (0 for persistent, unbound interfaces) */
132 #define IPN_NODEFLAG_PERSIST 0x4 /* if persist does not disappear on close (net interfaces) */
133 #define IPN_NODEFLAG_TAP 0x10 /* This is a tap interface */
134 #define IPN_NODEFLAG_GRAB 0x20 /* This is a grab of a real interface */
135 #define IPN_NODEFLAG_DEVMASK 0x30 /* True if this is a device */
136 #define IPN_NODEFLAG_OOB_NUMNODES 0x40 /* Node wants OOB for NNODES */
141 * unfortunately we must use a struct sock (most of the fields are useless) as
142 * this is the standard "agnostic" structure for socket implementation.
143 * This proofs that it is not "agnostic" enough!
148 struct ipn_node
*node
;
152 * ipn_network network descriptor
154 * @hnode=hash to find this entry (looking for i-node)
155 * @unconnectqueue=queue of unconnected (bound) nodes
156 * @connectqueue=queue of connected nodes (faster for broadcasting)
157 * @refcnt=reference count (bound or connected sockets)
158 * @dentry/@mnt=to keep the file system descriptor into memory
159 * @ipnn_lock=lock for protocol functions
160 * @protocol=kind of service
161 * @flags=flags (IPN_FLAG_LOSSLESS)
162 * @maxports=number of ports available in this network
163 * @msgpool_nelem=number of pending messages
164 * @msgpool_size=max number of pending messages *per net* when IPN_FLAG_LOSSLESS
165 * @msgpool_size=max number of pending messages *per port*when LOSSY
167 * @send_wait=wait queue waiting for a message in the msgpool (IPN_FLAG_LOSSLESS)
168 * @msgpool_cache=slab for msgpool (unused yet)
169 * @proto_private=handle for protocol private data
170 * @connports=array of connected sockets
173 struct hlist_node hnode
;
174 struct list_head unconnectqueue
;
175 struct list_head connectqueue
;
177 struct dentry
*dentry
;
178 struct vfsmount
*mnt
;
179 struct semaphore ipnn_mutex
;
181 struct sockaddr_un sunaddr
;
182 unsigned int protocol
;
186 atomic_t msgpool_nelem
;
187 unsigned short maxports
;
188 unsigned short msgpool_size
;
190 wait_queue_head_t send_wait
;
191 struct kmem_cache
*msgpool_cache
;
193 struct ipn_node
**connport
;
196 /* struct msgpool_item
197 * the local copy of the message for dispatching
202 struct msgpool_item
{
205 unsigned char data
[0];
208 struct msgpool_item
*ipn_msgpool_alloc(struct ipn_network
*ipnn
,int leaky
);
209 void ipn_msgpool_put(struct msgpool_item
*old
, struct ipn_network
*ipnn
);
214 * @refcnt: number of networks using this protocol
215 * @newport=upcall for reporting a new port. returns the portno, -1=error
216 * @handlemsg=dispatch a message.
217 * should call ipn_proto_sendmsg for each desctination
218 * can allocate other msgitems using ipn_msgpool_alloc to send
219 * different messages to different destinations;
220 * @delport=(may be null) reports the terminatio of a port
221 * @postnewport,@predelport: similar to newport/delport but during these calls
222 * the node is (still) connected. Useful when protocols need
223 * welcome and goodbye messages.
226 * @ipn_p_ioctl=(may be null) upcall to manage specific options or ctls.
228 struct ipn_protocol
{
230 int (*ipn_p_newport
)(struct ipn_node
*newport
);
231 int (*ipn_p_handlemsg
)(struct ipn_node
*from
,struct msgpool_item
*msgitem
);
232 void (*ipn_p_delport
)(struct ipn_node
*oldport
);
233 void (*ipn_p_postnewport
)(struct ipn_node
*newport
);
234 void (*ipn_p_predelport
)(struct ipn_node
*oldport
);
235 int (*ipn_p_newnet
)(struct ipn_network
*newnet
);
236 int (*ipn_p_resizenet
)(struct ipn_network
*net
,int oldsize
,int newsize
);
237 void (*ipn_p_delnet
)(struct ipn_network
*oldnet
);
238 int (*ipn_p_setsockopt
)(struct ipn_node
*port
,int optname
,
239 char __user
*optval
, int optlen
);
240 int (*ipn_p_getsockopt
)(struct ipn_node
*port
,int optname
,
241 char __user
*optval
, int *optlen
);
242 int (*ipn_p_ioctl
)(struct ipn_node
*port
,unsigned int request
,
246 int ipn_proto_register(int protocol
,struct ipn_protocol
*ipn_service
);
247 int ipn_proto_deregister(int protocol
);
249 int ipn_proto_injectmsg(struct ipn_node
*from
, struct msgpool_item
*msg
);
250 void ipn_proto_sendmsg(struct ipn_node
*to
, struct msgpool_item
*msg
);
251 void ipn_proto_oobsendmsg(struct ipn_node
*to
, struct msgpool_item
*msg
);
254 extern struct sk_buff
*(*ipn_handle_frame_hook
)(struct ipn_node
*p
,
255 struct sk_buff
*skb
);