xref: /dragonfly/sys/net/netmsg.h (revision ef3ac1d1)
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  */
75 TAILQ_HEAD(notifymsglist, netmsg_so_notify);
76 
77 struct netmsg_packet {
78 	struct netmsg_base	base;
79 	struct mbuf		*nm_packet;
80 	int			nm_nxt;
81 };
82 
83 struct netmsg_inarp {
84 	struct netmsg_base	base;
85 	struct mbuf		*m;
86 	in_addr_t		saddr;
87 	in_addr_t		taddr;
88 	in_addr_t		myaddr;
89 };
90 
91 struct netmsg_pr_timeout {
92 	struct netmsg_base	base;
93 };
94 
95 struct netmsg_so_notify;
96 typedef __boolean_t (*msg_predicate_fn_t)(struct netmsg_so_notify *);
97 
98 struct netmsg_so_notify {
99 	struct netmsg_base	base;
100 	msg_predicate_fn_t	nm_predicate;
101 	int			nm_fflags; /* flags e.g. FNONBLOCK */
102 	int			nm_etype;  /* receive or send event */
103 	TAILQ_ENTRY(netmsg_so_notify) nm_list;
104 };
105 
106 struct netmsg_so_notify_abort {
107 	struct netmsg_base	base;
108 	struct netmsg_so_notify	*nm_notifymsg;
109 };
110 
111 #define NM_REVENT	0x1		/* event on receive buffer */
112 #define NM_SEVENT	0x2		/* event on send buffer */
113 
114 /*
115  * User protocol requests messages.
116  */
117 struct netmsg_pru_abort {
118 	struct netmsg_base	base;
119 };
120 
121 struct netmsg_pru_accept {
122 	struct netmsg_base	base;
123 	struct sockaddr		**nm_nam;
124 };
125 
126 struct netmsg_pru_attach {
127 	struct netmsg_base	base;
128 	int			nm_proto;
129 	struct pru_attach_info	*nm_ai;
130 };
131 
132 struct netmsg_pru_bind {
133 	struct netmsg_base	base;
134 	struct sockaddr		*nm_nam;
135 	struct thread		*nm_td;
136 };
137 
138 struct netmsg_pru_connect {
139 	struct netmsg_base	base;
140 	struct sockaddr		*nm_nam;
141 	struct thread		*nm_td;
142 	struct mbuf		*nm_m;		/* connect with send */
143 	int			nm_sndflags;	/* connect with send, PRUS_ */
144 	int			nm_flags;	/* message control */
145 };
146 
147 #define PRUC_RECONNECT		0x0001		/* thread port change */
148 #define PRUC_NAMALLOC		0x0002		/* nm_nam allocated */
149 #define PRUC_PUSH		0x0004		/* call tcp_output */
150 #define PRUC_FALLBACK		0x0008		/* fallback to ipv4 */
151 #define PRUC_ASYNC		0x0010
152 #define PRUC_HELDTD		0x0020
153 #define PRUC_HASLADDR		0x0040
154 
155 struct netmsg_pru_connect2 {
156 	struct netmsg_base	base;
157 	struct socket		*nm_so1;
158 	struct socket		*nm_so2;
159 };
160 
161 struct netmsg_pru_control {
162 	struct netmsg_base	base;
163 	u_long			nm_cmd;
164 	caddr_t			nm_data;
165 	struct ifnet		*nm_ifp;
166 	struct thread		*nm_td;
167 };
168 
169 struct netmsg_pru_detach {
170 	struct netmsg_base	base;
171 };
172 
173 struct netmsg_pru_disconnect {
174 	struct netmsg_base	base;
175 };
176 
177 struct netmsg_pru_listen {
178 	struct netmsg_base	base;
179 	struct thread		*nm_td;
180 	int			nm_flags;	/* PRUL_xxx */
181 };
182 
183 #define PRUL_RELINK		0x1
184 
185 struct netmsg_pru_peeraddr {
186 	struct netmsg_base	base;
187 	struct sockaddr		**nm_nam;
188 };
189 
190 struct netmsg_pru_rcvd {
191 	struct netmsg_base	base;
192 	int			nm_flags;
193 	int			nm_pru_flags;	/* PRUR_xxx */
194 };
195 
196 #define PRUR_ASYNC		0x1
197 #define PRUR_DEAD		0x2
198 
199 struct netmsg_pru_rcvoob {
200 	struct netmsg_base	base;
201 	struct mbuf		*nm_m;
202 	int			nm_flags;
203 };
204 
205 struct netmsg_pru_send {
206 	struct netmsg_base	base;
207 	int			nm_flags;	/* PRUS_xxx */
208 	int			nm_priv;	/* proto priv. */
209 	struct mbuf		*nm_m;
210 	struct sockaddr		*nm_addr;
211 	struct mbuf		*nm_control;
212 	struct thread		*nm_td;
213 };
214 
215 #define PRUS_OOB		0x1
216 #define PRUS_EOF		0x2
217 #define PRUS_MORETOCOME		0x4
218 #define PRUS_NAMALLOC		0x8
219 #define PRUS_NOREPLY		0x10
220 #define PRUS_DONTROUTE		0x20
221 #define PRUS_FREEADDR		0x40
222 #define PRUS_HELDTD		0x80
223 
224 struct netmsg_pru_sense {
225 	struct netmsg_base	base;
226 	struct stat		*nm_stat;
227 };
228 
229 struct netmsg_pru_shutdown {
230 	struct netmsg_base	base;
231 };
232 
233 struct netmsg_pru_sockaddr {
234 	struct netmsg_base	base;
235 	struct sockaddr		**nm_nam;
236 };
237 
238 struct netmsg_pru_sosend {
239 	struct netmsg_base	base;
240 	struct sockaddr		*nm_addr;
241 	struct uio		*nm_uio;
242 	struct mbuf		*nm_top;
243 	struct mbuf		*nm_control;
244 	int			nm_flags;
245 	struct thread		*nm_td;
246 };
247 
248 struct netmsg_pru_soreceive {
249 	struct netmsg_base	base;
250 	struct sockaddr		*nm_addr;
251 	struct sockaddr		**nm_paddr;
252 	struct uio		*nm_uio;
253 	struct sockbuf		*nm_sio;
254 	struct mbuf		**nm_controlp;
255 	int			*nm_flagsp;
256 };
257 
258 struct netmsg_pr_ctloutput {
259 	struct netmsg_base	base;
260 	struct sockopt		*nm_sopt;
261 };
262 
263 struct netmsg_pru_ctlinput {
264 	struct netmsg_base	base;
265 	int			nm_cmd;
266 	struct sockaddr		*nm_arg;
267 	void			*nm_extra;
268 };
269 
270 /*
271  * Union of all possible netmsgs.  Note that when a netmsg is sent the
272  * actual allocated storage is likely only the size of the particular
273  * class of message, and not sizeof(union netmsg).
274  */
275 union netmsg {
276 	struct lwkt_msg			lmsg;		/* base embedded */
277 	struct netmsg_base		base;		/* base embedded */
278 
279 	struct netmsg_packet		packet;		/* mbuf embedded */
280 	struct netmsg_pr_timeout	timeout;
281 	struct netmsg_so_notify		notify;
282 	struct netmsg_so_notify_abort	notify_abort;
283 
284 	struct netmsg_pr_ctloutput	ctloutput;
285 
286 	struct netmsg_pru_abort		abort;
287 	struct netmsg_pru_accept	accept;		/* synchronous */
288 	struct netmsg_pru_attach	attach;
289 	struct netmsg_pru_bind		bind;
290 	struct netmsg_pru_connect	connect;
291 	struct netmsg_pru_connect2	connect2;
292 	struct netmsg_pru_control	control;	/* synchronous */
293 	struct netmsg_pru_detach	detach;
294 	struct netmsg_pru_disconnect	disconnect;
295 	struct netmsg_pru_listen	listen;
296 	struct netmsg_pru_peeraddr	peeraddr;
297 	struct netmsg_pru_rcvd		rcvd;
298 	struct netmsg_pru_rcvoob	rcvoob;
299 	struct netmsg_pru_send		send;
300 	struct netmsg_pru_sense		sense;
301 	struct netmsg_pru_shutdown	shutdown;
302 	struct netmsg_pru_sockaddr	sockaddr;
303 	struct netmsg_pru_sosend	sosend;		/* synchronous */
304 	struct netmsg_pru_soreceive	soreceive;	/* synchronous */
305 	struct netmsg_pru_ctlinput	ctlinput;
306 };
307 
308 #endif	/* _KERNEL || _KERNEL_STRUCTURES */
309 
310 #endif	/* !_NET_NETMSG_H_ */
311