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