xref: /dragonfly/sys/net/netmsg.h (revision 81c11cd3)
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 typedef void (*netisr_fn_t)(netmsg_t);
44 typedef void (*netisr_ru_t)(void);
45 typedef void (*netisr_cpufn_t)(struct mbuf **, int);
46 
47 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
48 
49 /*
50  * The base netmsg prefixes all netmsgs and includes an embedded LWKT
51  * message.
52  */
53 struct netmsg_base {
54 	struct lwkt_msg		lmsg;
55 	netisr_fn_t		nm_dispatch;
56 	struct socket		*nm_so;
57 };
58 
59 typedef struct netmsg_base *netmsg_base_t;
60 
61 /*
62  * NETISR messages
63  *
64  * NOTE: netmsg_packet is embedded in mbufs.
65  */
66 TAILQ_HEAD(notifymsglist, netmsg_so_notify);
67 
68 struct netmsg_packet {
69 	struct netmsg_base	base;
70 	struct mbuf		*nm_packet;
71 	int			nm_nxt;
72 };
73 
74 struct netmsg_pr_timeout {
75 	struct netmsg_base	base;
76 };
77 
78 struct netmsg_so_notify;
79 typedef __boolean_t (*msg_predicate_fn_t)(struct netmsg_so_notify *);
80 
81 struct netmsg_so_notify {
82 	struct netmsg_base	base;
83 	msg_predicate_fn_t	nm_predicate;
84 	int			nm_fflags; /* flags e.g. FNONBLOCK */
85 	int			nm_etype;  /* receive or send event */
86 	TAILQ_ENTRY(netmsg_so_notify) nm_list;
87 };
88 
89 struct netmsg_so_notify_abort {
90 	struct netmsg_base	base;
91 	struct netmsg_so_notify	*nm_notifymsg;
92 };
93 
94 #define NM_REVENT	0x1		/* event on receive buffer */
95 #define NM_SEVENT	0x2		/* event on send buffer */
96 
97 /*
98  * User protocol requests messages.
99  */
100 struct netmsg_pru_abort {
101 	struct netmsg_base	base;
102 };
103 
104 struct netmsg_pru_accept {
105 	struct netmsg_base	base;
106 	struct sockaddr		**nm_nam;
107 };
108 
109 struct netmsg_pru_attach {
110 	struct netmsg_base	base;
111 	int			nm_proto;
112 	struct pru_attach_info	*nm_ai;
113 };
114 
115 struct netmsg_pru_bind {
116 	struct netmsg_base	base;
117 	struct sockaddr		*nm_nam;
118 	struct thread		*nm_td;
119 };
120 
121 struct netmsg_pru_connect {
122 	struct netmsg_base	base;
123 	struct sockaddr		*nm_nam;
124 	struct thread		*nm_td;
125 	struct mbuf		*nm_m;		/* connect with send */
126 	int			nm_flags;	/* connect with send */
127 	int			nm_reconnect;	/* message control */
128 };
129 
130 #define NMSG_RECONNECT_RECONNECT	0x0001	/* thread port change */
131 #define NMSG_RECONNECT_NAMALLOC		0x0002	/* nm_nam allocated */
132 #define NMSG_RECONNECT_PUSH		0x0004	/* call tcp_output */
133 #define NMSG_RECONNECT_FALLBACK		0x0008	/* fallback to ipv4 */
134 
135 struct netmsg_pru_connect2 {
136 	struct netmsg_base	base;
137 	struct socket		*nm_so1;
138 	struct socket		*nm_so2;
139 };
140 
141 struct netmsg_pru_control {
142 	struct netmsg_base	base;
143 	u_long			nm_cmd;
144 	caddr_t			nm_data;
145 	struct ifnet		*nm_ifp;
146 	struct thread		*nm_td;
147 };
148 
149 struct netmsg_pru_detach {
150 	struct netmsg_base	base;
151 };
152 
153 struct netmsg_pru_disconnect {
154 	struct netmsg_base	base;
155 };
156 
157 struct netmsg_pru_listen {
158 	struct netmsg_base	base;
159 	struct thread		*nm_td;
160 };
161 
162 struct netmsg_pru_peeraddr {
163 	struct netmsg_base	base;
164 	struct sockaddr		**nm_nam;
165 };
166 
167 struct netmsg_pru_rcvd {
168 	struct netmsg_base	base;
169 	int			nm_flags;
170 };
171 
172 struct netmsg_pru_rcvoob {
173 	struct netmsg_base	base;
174 	struct mbuf		*nm_m;
175 	int			nm_flags;
176 };
177 
178 struct netmsg_pru_send {
179 	struct netmsg_base	base;
180 	int			nm_flags;	/* PRUS_xxx */
181 	struct mbuf		*nm_m;
182 	struct sockaddr		*nm_addr;
183 	struct mbuf		*nm_control;
184 	struct thread		*nm_td;
185 	/*
186 	 * XXX hack to be 100% certain netmsg_pru_send can be overwritten
187 	 * by netmsg_pru_connect
188 	 */
189 	char			nm_dummy[sizeof(struct netmsg_pru_connect) -
190 					 sizeof(struct netmsg_base)];
191 };
192 
193 #define PRUS_OOB		0x1
194 #define PRUS_EOF		0x2
195 #define PRUS_MORETOCOME		0x4
196 #define PRUS_NAMALLOC		0x8
197 
198 struct netmsg_pru_sense {
199 	struct netmsg_base	base;
200 	struct stat		*nm_stat;
201 };
202 
203 struct netmsg_pru_shutdown {
204 	struct netmsg_base	base;
205 };
206 
207 struct netmsg_pru_sockaddr {
208 	struct netmsg_base	base;
209 	struct sockaddr		**nm_nam;
210 };
211 
212 struct netmsg_pru_sosend {
213 	struct netmsg_base	base;
214 	struct sockaddr		*nm_addr;
215 	struct uio		*nm_uio;
216 	struct mbuf		*nm_top;
217 	struct mbuf		*nm_control;
218 	int			nm_flags;
219 	struct thread		*nm_td;
220 };
221 
222 struct netmsg_pru_soreceive {
223 	struct netmsg_base	base;
224 	struct sockaddr		*nm_addr;
225 	struct sockaddr		**nm_paddr;
226 	struct uio		*nm_uio;
227 	struct sockbuf		*nm_sio;
228 	struct mbuf		**nm_controlp;
229 	int			*nm_flagsp;
230 };
231 
232 struct netmsg_pr_ctloutput {
233 	struct netmsg_base	base;
234 	struct sockopt		*nm_sopt;
235 };
236 
237 struct netmsg_pru_ctlinput {
238 	struct netmsg_base	base;
239 	int			nm_cmd;
240 	struct sockaddr		*nm_arg;
241 	void			*nm_extra;
242 };
243 
244 /*
245  * Union of all possible netmsgs.  Note that when a netmsg is sent the
246  * actual allocated storage is likely only the size of the particular
247  * class of message, and not sizeof(union netmsg).
248  */
249 union netmsg {
250 	struct lwkt_msg			lmsg;		/* base embedded */
251 	struct netmsg_base		base;		/* base embedded */
252 
253 	struct netmsg_packet		packet;		/* mbuf embedded */
254 	struct netmsg_pr_timeout	timeout;
255 	struct netmsg_so_notify		notify;
256 	struct netmsg_so_notify_abort	notify_abort;
257 
258 	struct netmsg_pr_ctloutput	ctloutput;
259 
260 	struct netmsg_pru_abort		abort;
261 	struct netmsg_pru_accept	accept;		/* synchronous */
262 	struct netmsg_pru_attach	attach;
263 	struct netmsg_pru_bind		bind;
264 	struct netmsg_pru_connect	connect;
265 	struct netmsg_pru_connect2	connect2;
266 	struct netmsg_pru_control	control;	/* synchronous */
267 	struct netmsg_pru_detach	detach;
268 	struct netmsg_pru_disconnect	disconnect;
269 	struct netmsg_pru_listen	listen;
270 	struct netmsg_pru_peeraddr	peeraddr;
271 	struct netmsg_pru_rcvd		rcvd;
272 	struct netmsg_pru_rcvoob	rcvoob;
273 	struct netmsg_pru_send		send;
274 	struct netmsg_pru_sense		sense;
275 	struct netmsg_pru_shutdown	shutdown;
276 	struct netmsg_pru_sockaddr	sockaddr;
277 	struct netmsg_pru_sosend	sosend;		/* synchronous */
278 	struct netmsg_pru_soreceive	soreceive;	/* synchronous */
279 	struct netmsg_pru_ctlinput	ctlinput;
280 };
281 
282 #endif	/* _KERNEL || _KERNEL_STRUCTURES */
283 
284 #endif	/* !_NET_NETMSG_H_ */
285