xref: /dragonfly/sys/net/netmsg.h (revision 896f2e3a)
1 /*
2  * Copyright (c) 2003 Jeffrey Hsu
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *	This product includes software developed by Jeffrey M. Hsu.
16  * 4. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * $DragonFly: src/sys/net/netmsg.h,v 1.10 2008/10/27 02:56:30 sephe Exp $
31  */
32 
33 #ifndef _NET_NETMSG_H_
34 #define _NET_NETMSG_H_
35 
36 #ifndef _SYS_THREAD_H_
37 #include <sys/thread.h>
38 #endif
39 #ifndef _SYS_PROTOSW_H_
40 #include <sys/protosw.h>
41 #endif
42 
43 struct pktinfo;
44 
45 typedef void (*netisr_fn_t)(netmsg_t);
46 typedef void (*netisr_ru_t)(void);
47 typedef void (*netisr_hashfn_t)(struct mbuf **, int);
48 typedef void (*netisr_hashck_t)(struct mbuf *, const struct pktinfo *);
49 
50 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
51 
52 /*
53  * The base netmsg prefixes all netmsgs and includes an embedded LWKT
54  * message.
55  */
56 struct netmsg_base {
57 	struct lwkt_msg		lmsg;
58 	netisr_fn_t		nm_dispatch;
59 	struct socket		*nm_so;
60 };
61 
62 #define MSGF_IGNSOPORT		MSGF_USER0	/* don't check so_port */
63 #define MSGF_PROTO1		MSGF_USER1	/* protocol specific */
64 
65 typedef struct netmsg_base *netmsg_base_t;
66 
67 /*
68  * NETISR messages
69  *
70  * NOTE:
71  * - netmsg_packet is embedded in mbufs.
72  * - netmsg_pru_send is embedded in mbufs.
73  * - netmsg_inarp is embedded in mbufs.
74  * - netmsg_ctlinput is embedded in mbufs.
75  */
76 TAILQ_HEAD(notifymsglist, netmsg_so_notify);
77 
78 struct netmsg_packet {
79 	struct netmsg_base	base;
80 	struct mbuf		*nm_packet;
81 	int			nm_nxt;
82 };
83 
84 struct netmsg_inarp {
85 	struct netmsg_base	base;
86 	struct mbuf		*m;
87 	in_addr_t		saddr;
88 	in_addr_t		taddr;
89 	in_addr_t		myaddr;
90 };
91 
92 struct netmsg_ctlinput {
93 	struct netmsg_base	base;
94 	struct mbuf		*m;
95 	int			cmd;
96 	int			hlen;
97 	int			proto;
98 };
99 
100 struct netmsg_pr_timeout {
101 	struct netmsg_base	base;
102 };
103 
104 struct netmsg_so_notify;
105 typedef __boolean_t (*msg_predicate_fn_t)(struct netmsg_so_notify *);
106 
107 struct netmsg_so_notify {
108 	struct netmsg_base	base;
109 	msg_predicate_fn_t	nm_predicate;
110 	int			nm_fflags; /* flags e.g. FNONBLOCK */
111 	int			nm_etype;  /* receive or send event */
112 	TAILQ_ENTRY(netmsg_so_notify) nm_list;
113 };
114 
115 struct netmsg_so_notify_abort {
116 	struct netmsg_base	base;
117 	struct netmsg_so_notify	*nm_notifymsg;
118 };
119 
120 #define NM_REVENT	0x1		/* event on receive buffer */
121 #define NM_SEVENT	0x2		/* event on send buffer */
122 
123 /*
124  * User protocol requests messages.
125  */
126 struct netmsg_pru_abort {
127 	struct netmsg_base	base;
128 };
129 
130 struct netmsg_pru_accept {
131 	struct netmsg_base	base;
132 	struct sockaddr		**nm_nam;
133 };
134 
135 struct netmsg_pru_attach {
136 	struct netmsg_base	base;
137 	int			nm_proto;
138 	struct pru_attach_info	*nm_ai;
139 };
140 
141 struct netmsg_pru_bind {
142 	struct netmsg_base	base;
143 	struct sockaddr		*nm_nam;
144 	struct thread		*nm_td;
145 };
146 
147 struct netmsg_pru_connect {
148 	struct netmsg_base	base;
149 	struct sockaddr		*nm_nam;
150 	struct thread		*nm_td;
151 	struct mbuf		*nm_m;		/* connect with send */
152 	int			nm_sndflags;	/* connect with send, PRUS_ */
153 	int			nm_flags;	/* message control */
154 };
155 
156 #define PRUC_RECONNECT		0x0001		/* thread port change */
157 #define PRUC_PUSH		0x0004		/* call tcp_output */
158 #define PRUC_ASYNC		0x0010
159 #define PRUC_HELDTD		0x0020
160 #define PRUC_HASLADDR		0x0040
161 
162 struct netmsg_pru_connect2 {
163 	struct netmsg_base	base;
164 	struct socket		*nm_so1;
165 	struct socket		*nm_so2;
166 };
167 
168 struct netmsg_pru_control {
169 	struct netmsg_base	base;
170 	u_long			nm_cmd;
171 	caddr_t			nm_data;
172 	struct ifnet		*nm_ifp;
173 	struct thread		*nm_td;
174 };
175 
176 struct netmsg_pru_detach {
177 	struct netmsg_base	base;
178 };
179 
180 struct netmsg_pru_disconnect {
181 	struct netmsg_base	base;
182 };
183 
184 struct netmsg_pru_listen {
185 	struct netmsg_base	base;
186 	struct thread		*nm_td;
187 	int			nm_flags;	/* PRUL_xxx */
188 };
189 
190 #define PRUL_RELINK		0x1
191 
192 struct netmsg_pru_peeraddr {
193 	struct netmsg_base	base;
194 	struct sockaddr		**nm_nam;
195 };
196 
197 struct netmsg_pru_rcvd {
198 	struct netmsg_base	base;
199 	int			nm_flags;
200 	int			nm_pru_flags;	/* PRUR_xxx */
201 };
202 
203 #define PRUR_ASYNC		0x1
204 #define PRUR_DEAD		0x2
205 
206 struct netmsg_pru_rcvoob {
207 	struct netmsg_base	base;
208 	struct mbuf		*nm_m;
209 	int			nm_flags;
210 };
211 
212 struct netmsg_pru_send {
213 	struct netmsg_base	base;
214 	int			nm_flags;	/* PRUS_xxx */
215 	int			nm_priv;	/* proto priv. */
216 	struct mbuf		*nm_m;
217 	struct sockaddr		*nm_addr;
218 	struct mbuf		*nm_control;
219 	struct thread		*nm_td;
220 };
221 
222 #define PRUS_OOB		0x1
223 #define PRUS_EOF		0x2
224 #define PRUS_MORETOCOME		0x4
225 #define PRUS_NAMALLOC		0x8
226 #define PRUS_NOREPLY		0x10
227 #define PRUS_DONTROUTE		0x20
228 #define PRUS_FREEADDR		0x40
229 #define PRUS_HELDTD		0x80
230 
231 struct netmsg_pru_sense {
232 	struct netmsg_base	base;
233 	struct stat		*nm_stat;
234 };
235 
236 struct netmsg_pru_shutdown {
237 	struct netmsg_base	base;
238 };
239 
240 struct netmsg_pru_sockaddr {
241 	struct netmsg_base	base;
242 	struct sockaddr		**nm_nam;
243 };
244 
245 struct netmsg_pru_sosend {
246 	struct netmsg_base	base;
247 	struct sockaddr		*nm_addr;
248 	struct uio		*nm_uio;
249 	struct mbuf		*nm_top;
250 	struct mbuf		*nm_control;
251 	int			nm_flags;
252 	struct thread		*nm_td;
253 };
254 
255 struct netmsg_pru_soreceive {
256 	struct netmsg_base	base;
257 	struct sockaddr		*nm_addr;
258 	struct sockaddr		**nm_paddr;
259 	struct uio		*nm_uio;
260 	struct sockbuf		*nm_sio;
261 	struct mbuf		**nm_controlp;
262 	int			*nm_flagsp;
263 };
264 
265 struct netmsg_pr_ctloutput {
266 	struct netmsg_base	base;
267 	struct sockopt		*nm_sopt;
268 };
269 
270 struct netmsg_pr_ctlinput {
271 	struct netmsg_base	base;
272 	int			nm_cmd;
273 	int			nm_direct;
274 	struct sockaddr		*nm_arg;
275 	void			*nm_extra;
276 };
277 
278 /*
279  * Union of all possible netmsgs.  Note that when a netmsg is sent the
280  * actual allocated storage is likely only the size of the particular
281  * class of message, and not sizeof(union netmsg).
282  */
283 union netmsg {
284 	struct lwkt_msg			lmsg;		/* base embedded */
285 	struct netmsg_base		base;		/* base embedded */
286 
287 	struct netmsg_packet		packet;		/* mbuf embedded */
288 	struct netmsg_pr_timeout	timeout;
289 	struct netmsg_so_notify		notify;
290 	struct netmsg_so_notify_abort	notify_abort;
291 
292 	struct netmsg_pr_ctloutput	ctloutput;
293 	struct netmsg_pr_ctlinput	ctlinput;
294 
295 	struct netmsg_pru_abort		abort;
296 	struct netmsg_pru_accept	accept;		/* synchronous */
297 	struct netmsg_pru_attach	attach;
298 	struct netmsg_pru_bind		bind;
299 	struct netmsg_pru_connect	connect;
300 	struct netmsg_pru_connect2	connect2;
301 	struct netmsg_pru_control	control;	/* synchronous */
302 	struct netmsg_pru_detach	detach;
303 	struct netmsg_pru_disconnect	disconnect;
304 	struct netmsg_pru_listen	listen;
305 	struct netmsg_pru_peeraddr	peeraddr;
306 	struct netmsg_pru_rcvd		rcvd;
307 	struct netmsg_pru_rcvoob	rcvoob;
308 	struct netmsg_pru_send		send;
309 	struct netmsg_pru_sense		sense;
310 	struct netmsg_pru_shutdown	shutdown;
311 	struct netmsg_pru_sockaddr	sockaddr;
312 	struct netmsg_pru_sosend	sosend;		/* synchronous */
313 	struct netmsg_pru_soreceive	soreceive;	/* synchronous */
314 };
315 
316 #endif	/* _KERNEL || _KERNEL_STRUCTURES */
317 
318 #endif	/* !_NET_NETMSG_H_ */
319