xref: /dflybsd-src/sys/net/netmsg.h (revision a6da5b60c9de99ff97ef13fe72b69d548a0d1f7c)
18a113daeSJeffrey Hsu /*
28a113daeSJeffrey Hsu  * Copyright (c) 2003 Jeffrey Hsu
38a113daeSJeffrey Hsu  * All rights reserved.
48a113daeSJeffrey Hsu  *
58a113daeSJeffrey Hsu  * Redistribution and use in source and binary forms, with or without
68a113daeSJeffrey Hsu  * modification, are permitted provided that the following conditions
78a113daeSJeffrey Hsu  * are met:
88a113daeSJeffrey Hsu  * 1. Redistributions of source code must retain the above copyright
98a113daeSJeffrey Hsu  *    notice, this list of conditions and the following disclaimer.
108a113daeSJeffrey Hsu  * 2. Redistributions in binary form must reproduce the above copyright
118a113daeSJeffrey Hsu  *    notice, this list of conditions and the following disclaimer in the
128a113daeSJeffrey Hsu  *    documentation and/or other materials provided with the distribution.
138a113daeSJeffrey Hsu  * 3. All advertising materials mentioning features or use of this software
148a113daeSJeffrey Hsu  *    must display the following acknowledgement:
158a113daeSJeffrey Hsu  *	This product includes software developed by Jeffrey M. Hsu.
168a113daeSJeffrey Hsu  * 4. The name of the author may not be used to endorse or promote products
178a113daeSJeffrey Hsu  *    derived from this software without specific prior written permission.
188a113daeSJeffrey Hsu  *
198a113daeSJeffrey Hsu  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
208a113daeSJeffrey Hsu  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
218a113daeSJeffrey Hsu  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
228a113daeSJeffrey Hsu  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
238a113daeSJeffrey Hsu  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
248a113daeSJeffrey Hsu  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
258a113daeSJeffrey Hsu  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
268a113daeSJeffrey Hsu  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
278a113daeSJeffrey Hsu  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
288a113daeSJeffrey Hsu  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
298a113daeSJeffrey Hsu  *
30e3873585SSepherosa Ziehau  * $DragonFly: src/sys/net/netmsg.h,v 1.10 2008/10/27 02:56:30 sephe Exp $
318a113daeSJeffrey Hsu  */
328a113daeSJeffrey Hsu 
331bd40720SMatthew Dillon #ifndef _NET_NETMSG_H_
341bd40720SMatthew Dillon #define _NET_NETMSG_H_
351bd40720SMatthew Dillon 
361bd40720SMatthew Dillon #ifndef _SYS_THREAD_H_
371bd40720SMatthew Dillon #include <sys/thread.h>
381bd40720SMatthew Dillon #endif
391bd40720SMatthew Dillon #ifndef _SYS_PROTOSW_H_
401bd40720SMatthew Dillon #include <sys/protosw.h>
411bd40720SMatthew Dillon #endif
428a113daeSJeffrey Hsu 
43e6f77b88SSepherosa Ziehau struct pktinfo;
44e6f77b88SSepherosa Ziehau 
45002c1265SMatthew Dillon typedef void (*netisr_fn_t)(netmsg_t);
46c3c96e44SMatthew Dillon typedef void (*netisr_ru_t)(void);
47ca86d83eSSepherosa Ziehau typedef void (*netisr_hashfn_t)(struct mbuf **, int);
48e6f77b88SSepherosa Ziehau typedef void (*netisr_hashck_t)(struct mbuf *, const struct pktinfo *);
494599cf19SMatthew Dillon 
50002c1265SMatthew Dillon #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
51002c1265SMatthew Dillon 
524599cf19SMatthew Dillon /*
53002c1265SMatthew Dillon  * The base netmsg prefixes all netmsgs and includes an embedded LWKT
54002c1265SMatthew Dillon  * message.
554599cf19SMatthew Dillon  */
56002c1265SMatthew Dillon struct netmsg_base {
57002c1265SMatthew Dillon 	struct lwkt_msg		lmsg;
584599cf19SMatthew Dillon 	netisr_fn_t		nm_dispatch;
5948e7b118SMatthew Dillon 	struct socket		*nm_so;
60002c1265SMatthew Dillon };
614599cf19SMatthew Dillon 
621fe8db06SSepherosa Ziehau #define MSGF_IGNSOPORT		MSGF_USER0	/* don't check so_port */
63be4519a2SSepherosa Ziehau #define MSGF_PROTO1		MSGF_USER1	/* protocol specific */
641fe8db06SSepherosa Ziehau 
65002c1265SMatthew Dillon typedef struct netmsg_base *netmsg_base_t;
66002c1265SMatthew Dillon 
67002c1265SMatthew Dillon /*
68002c1265SMatthew Dillon  * NETISR messages
69002c1265SMatthew Dillon  *
70d80bcfb0SSepherosa Ziehau  * NOTE:
71d80bcfb0SSepherosa Ziehau  * - netmsg_packet is embedded in mbufs.
72d80bcfb0SSepherosa Ziehau  * - netmsg_pru_send is embedded in mbufs.
73858ae8d6SSepherosa Ziehau  * - netmsg_inarp is embedded in mbufs.
74130b7902SSepherosa Ziehau  * - netmsg_ctlinput is embedded in mbufs.
752e59787cSSepherosa Ziehau  * - netmsg_genpkt is embedded in mbufs.
76*a6da5b60SKyle Butt  * - netmsg_forward is embedded in mbufs.
77002c1265SMatthew Dillon  */
78002c1265SMatthew Dillon TAILQ_HEAD(notifymsglist, netmsg_so_notify);
79002c1265SMatthew Dillon 
80002c1265SMatthew Dillon struct netmsg_packet {
81002c1265SMatthew Dillon 	struct netmsg_base	base;
82002c1265SMatthew Dillon 	struct mbuf		*nm_packet;
83002c1265SMatthew Dillon 	int			nm_nxt;
84002c1265SMatthew Dillon };
85002c1265SMatthew Dillon 
86858ae8d6SSepherosa Ziehau struct netmsg_inarp {
87858ae8d6SSepherosa Ziehau 	struct netmsg_base	base;
88858ae8d6SSepherosa Ziehau 	struct mbuf		*m;
89858ae8d6SSepherosa Ziehau 	in_addr_t		saddr;
90858ae8d6SSepherosa Ziehau 	in_addr_t		taddr;
91858ae8d6SSepherosa Ziehau 	in_addr_t		myaddr;
92858ae8d6SSepherosa Ziehau };
93858ae8d6SSepherosa Ziehau 
94130b7902SSepherosa Ziehau struct netmsg_ctlinput {
95130b7902SSepherosa Ziehau 	struct netmsg_base	base;
96130b7902SSepherosa Ziehau 	struct mbuf		*m;
97130b7902SSepherosa Ziehau 	int			cmd;
98130b7902SSepherosa Ziehau 	int			hlen;
99130b7902SSepherosa Ziehau 	int			proto;
100130b7902SSepherosa Ziehau };
101130b7902SSepherosa Ziehau 
1022e59787cSSepherosa Ziehau struct netmsg_genpkt {
1032e59787cSSepherosa Ziehau 	struct netmsg_base	base;
1042e59787cSSepherosa Ziehau 	struct mbuf		*m;
1052e59787cSSepherosa Ziehau 	void			*arg1;
1062e59787cSSepherosa Ziehau 	u_long			arg2;
1072e59787cSSepherosa Ziehau };
1082e59787cSSepherosa Ziehau 
109*a6da5b60SKyle Butt struct netmsg_forward {
110*a6da5b60SKyle Butt 	struct netmsg_base	base;
111*a6da5b60SKyle Butt 	struct mbuf		*nm_packet;
112*a6da5b60SKyle Butt 	__boolean_t		using_srcrt;
113*a6da5b60SKyle Butt };
114*a6da5b60SKyle Butt 
115002c1265SMatthew Dillon struct netmsg_pr_timeout {
116002c1265SMatthew Dillon 	struct netmsg_base	base;
117002c1265SMatthew Dillon };
118002c1265SMatthew Dillon 
119002c1265SMatthew Dillon struct netmsg_so_notify;
120002c1265SMatthew Dillon typedef __boolean_t (*msg_predicate_fn_t)(struct netmsg_so_notify *);
121002c1265SMatthew Dillon 
122002c1265SMatthew Dillon struct netmsg_so_notify {
123002c1265SMatthew Dillon 	struct netmsg_base	base;
124002c1265SMatthew Dillon 	msg_predicate_fn_t	nm_predicate;
125002c1265SMatthew Dillon 	int			nm_fflags; /* flags e.g. FNONBLOCK */
126002c1265SMatthew Dillon 	int			nm_etype;  /* receive or send event */
127002c1265SMatthew Dillon 	TAILQ_ENTRY(netmsg_so_notify) nm_list;
128002c1265SMatthew Dillon };
129002c1265SMatthew Dillon 
130002c1265SMatthew Dillon struct netmsg_so_notify_abort {
131002c1265SMatthew Dillon 	struct netmsg_base	base;
132002c1265SMatthew Dillon 	struct netmsg_so_notify	*nm_notifymsg;
133002c1265SMatthew Dillon };
134002c1265SMatthew Dillon 
135002c1265SMatthew Dillon #define NM_REVENT	0x1		/* event on receive buffer */
136002c1265SMatthew Dillon #define NM_SEVENT	0x2		/* event on send buffer */
1378d420ad8SSepherosa Ziehau 
1388a113daeSJeffrey Hsu /*
1398a113daeSJeffrey Hsu  * User protocol requests messages.
1408a113daeSJeffrey Hsu  */
1418a113daeSJeffrey Hsu struct netmsg_pru_abort {
142002c1265SMatthew Dillon 	struct netmsg_base	base;
1438a113daeSJeffrey Hsu };
1448a113daeSJeffrey Hsu 
1458a113daeSJeffrey Hsu struct netmsg_pru_accept {
146002c1265SMatthew Dillon 	struct netmsg_base	base;
1478a113daeSJeffrey Hsu 	struct sockaddr		**nm_nam;
1488a113daeSJeffrey Hsu };
1498a113daeSJeffrey Hsu 
1508a113daeSJeffrey Hsu struct netmsg_pru_attach {
151002c1265SMatthew Dillon 	struct netmsg_base	base;
1528a113daeSJeffrey Hsu 	int			nm_proto;
1538a113daeSJeffrey Hsu 	struct pru_attach_info	*nm_ai;
1548a113daeSJeffrey Hsu };
1558a113daeSJeffrey Hsu 
1568a113daeSJeffrey Hsu struct netmsg_pru_bind {
157002c1265SMatthew Dillon 	struct netmsg_base	base;
1588a113daeSJeffrey Hsu 	struct sockaddr		*nm_nam;
1598a113daeSJeffrey Hsu 	struct thread		*nm_td;
1607c0074d8SSepherosa Ziehau 	int			nm_flags;	/* PRUB_ */
1618a113daeSJeffrey Hsu };
1628a113daeSJeffrey Hsu 
1637c0074d8SSepherosa Ziehau #define PRUB_RELINK		0x0001
1647c0074d8SSepherosa Ziehau 
1658a113daeSJeffrey Hsu struct netmsg_pru_connect {
166002c1265SMatthew Dillon 	struct netmsg_base	base;
1678a113daeSJeffrey Hsu 	struct sockaddr		*nm_nam;
1688a113daeSJeffrey Hsu 	struct thread		*nm_td;
169002c1265SMatthew Dillon 	struct mbuf		*nm_m;		/* connect with send */
170e368a6e9SSepherosa Ziehau 	int			nm_sndflags;	/* connect with send, PRUS_ */
171e368a6e9SSepherosa Ziehau 	int			nm_flags;	/* message control */
1728a113daeSJeffrey Hsu };
1738a113daeSJeffrey Hsu 
174e368a6e9SSepherosa Ziehau #define PRUC_RECONNECT		0x0001		/* thread port change */
175e368a6e9SSepherosa Ziehau #define PRUC_PUSH		0x0004		/* call tcp_output */
176e368a6e9SSepherosa Ziehau #define PRUC_ASYNC		0x0010
177e368a6e9SSepherosa Ziehau #define PRUC_HELDTD		0x0020
178f5f6af91SSepherosa Ziehau #define PRUC_HASLADDR		0x0040
179002c1265SMatthew Dillon 
1808a113daeSJeffrey Hsu struct netmsg_pru_connect2 {
181002c1265SMatthew Dillon 	struct netmsg_base	base;
1828a113daeSJeffrey Hsu 	struct socket		*nm_so1;
1838a113daeSJeffrey Hsu 	struct socket		*nm_so2;
18422db3608SMatthew Dillon 	struct ucred		*nm_cred;
1858a113daeSJeffrey Hsu };
1868a113daeSJeffrey Hsu 
1878a113daeSJeffrey Hsu struct netmsg_pru_control {
188002c1265SMatthew Dillon 	struct netmsg_base	base;
1898a113daeSJeffrey Hsu 	u_long			nm_cmd;
1908a113daeSJeffrey Hsu 	caddr_t			nm_data;
1918a113daeSJeffrey Hsu 	struct ifnet		*nm_ifp;
1928a113daeSJeffrey Hsu 	struct thread		*nm_td;
1938a113daeSJeffrey Hsu };
1948a113daeSJeffrey Hsu 
1958a113daeSJeffrey Hsu struct netmsg_pru_detach {
196002c1265SMatthew Dillon 	struct netmsg_base	base;
1978a113daeSJeffrey Hsu };
1988a113daeSJeffrey Hsu 
1998a113daeSJeffrey Hsu struct netmsg_pru_disconnect {
200002c1265SMatthew Dillon 	struct netmsg_base	base;
2018a113daeSJeffrey Hsu };
2028a113daeSJeffrey Hsu 
2038a113daeSJeffrey Hsu struct netmsg_pru_listen {
204002c1265SMatthew Dillon 	struct netmsg_base	base;
2058a113daeSJeffrey Hsu 	struct thread		*nm_td;
2061c92f416SSepherosa Ziehau 	int			nm_flags;	/* PRUL_xxx */
2078a113daeSJeffrey Hsu };
2088a113daeSJeffrey Hsu 
2091c92f416SSepherosa Ziehau #define PRUL_RELINK		0x1
2101c92f416SSepherosa Ziehau 
2118a113daeSJeffrey Hsu struct netmsg_pru_peeraddr {
212002c1265SMatthew Dillon 	struct netmsg_base	base;
2138a113daeSJeffrey Hsu 	struct sockaddr		**nm_nam;
2148a113daeSJeffrey Hsu };
2158a113daeSJeffrey Hsu 
2168a113daeSJeffrey Hsu struct netmsg_pru_rcvd {
217002c1265SMatthew Dillon 	struct netmsg_base	base;
2188a113daeSJeffrey Hsu 	int			nm_flags;
21996c6eb29SSepherosa Ziehau 	int			nm_pru_flags;	/* PRUR_xxx */
2208a113daeSJeffrey Hsu };
2218a113daeSJeffrey Hsu 
22296c6eb29SSepherosa Ziehau #define PRUR_ASYNC		0x1
223a77d3dfeSSepherosa Ziehau #define PRUR_DEAD		0x2
22496c6eb29SSepherosa Ziehau 
2258a113daeSJeffrey Hsu struct netmsg_pru_rcvoob {
226002c1265SMatthew Dillon 	struct netmsg_base	base;
2278a113daeSJeffrey Hsu 	struct mbuf		*nm_m;
2288a113daeSJeffrey Hsu 	int			nm_flags;
2298a113daeSJeffrey Hsu };
2308a113daeSJeffrey Hsu 
2318a113daeSJeffrey Hsu struct netmsg_pru_send {
232002c1265SMatthew Dillon 	struct netmsg_base	base;
233002c1265SMatthew Dillon 	int			nm_flags;	/* PRUS_xxx */
2341fe8db06SSepherosa Ziehau 	int			nm_priv;	/* proto priv. */
2358a113daeSJeffrey Hsu 	struct mbuf		*nm_m;
2368a113daeSJeffrey Hsu 	struct sockaddr		*nm_addr;
2378a113daeSJeffrey Hsu 	struct mbuf		*nm_control;
2388a113daeSJeffrey Hsu 	struct thread		*nm_td;
2398a113daeSJeffrey Hsu };
2408a113daeSJeffrey Hsu 
241002c1265SMatthew Dillon #define PRUS_OOB		0x1
242002c1265SMatthew Dillon #define PRUS_EOF		0x2
243002c1265SMatthew Dillon #define PRUS_MORETOCOME		0x4
244002c1265SMatthew Dillon #define PRUS_NAMALLOC		0x8
2450ad8e15eSSepherosa Ziehau #define PRUS_NOREPLY		0x10
24647d61296SSepherosa Ziehau #define PRUS_DONTROUTE		0x20
2477b7dc575SSepherosa Ziehau #define PRUS_FREEADDR		0x40
248c0467c22SSepherosa Ziehau #define PRUS_HELDTD		0x80
249002c1265SMatthew Dillon 
2508a113daeSJeffrey Hsu struct netmsg_pru_sense {
251002c1265SMatthew Dillon 	struct netmsg_base	base;
2528a113daeSJeffrey Hsu 	struct stat		*nm_stat;
2538a113daeSJeffrey Hsu };
2548a113daeSJeffrey Hsu 
2558a113daeSJeffrey Hsu struct netmsg_pru_shutdown {
256002c1265SMatthew Dillon 	struct netmsg_base	base;
2578a113daeSJeffrey Hsu };
2588a113daeSJeffrey Hsu 
2598a113daeSJeffrey Hsu struct netmsg_pru_sockaddr {
260002c1265SMatthew Dillon 	struct netmsg_base	base;
2618a113daeSJeffrey Hsu 	struct sockaddr		**nm_nam;
2628a113daeSJeffrey Hsu };
2638a113daeSJeffrey Hsu 
2648a113daeSJeffrey Hsu struct netmsg_pru_sosend {
265002c1265SMatthew Dillon 	struct netmsg_base	base;
2668a113daeSJeffrey Hsu 	struct sockaddr		*nm_addr;
2678a113daeSJeffrey Hsu 	struct uio		*nm_uio;
2688a113daeSJeffrey Hsu 	struct mbuf		*nm_top;
2698a113daeSJeffrey Hsu 	struct mbuf		*nm_control;
2708a113daeSJeffrey Hsu 	int			nm_flags;
2718a113daeSJeffrey Hsu 	struct thread		*nm_td;
2728a113daeSJeffrey Hsu };
2738a113daeSJeffrey Hsu 
2748a113daeSJeffrey Hsu struct netmsg_pru_soreceive {
275002c1265SMatthew Dillon 	struct netmsg_base	base;
2768a113daeSJeffrey Hsu 	struct sockaddr		*nm_addr;
2778a113daeSJeffrey Hsu 	struct sockaddr		**nm_paddr;
2788a113daeSJeffrey Hsu 	struct uio		*nm_uio;
2796d49aa6fSMatthew Dillon 	struct sockbuf		*nm_sio;
2808a113daeSJeffrey Hsu 	struct mbuf		**nm_controlp;
2818a113daeSJeffrey Hsu 	int			*nm_flagsp;
2828a113daeSJeffrey Hsu };
2838a113daeSJeffrey Hsu 
284002c1265SMatthew Dillon struct netmsg_pr_ctloutput {
285002c1265SMatthew Dillon 	struct netmsg_base	base;
286680c4dd3SSepherosa Ziehau 	int			nm_flags;	/* PRCO_xx */
287e71a125fSAggelos Economopoulos 	struct sockopt		*nm_sopt;
288e71a125fSAggelos Economopoulos };
289e71a125fSAggelos Economopoulos 
290680c4dd3SSepherosa Ziehau #define PRCO_HELDTD		0x1
291680c4dd3SSepherosa Ziehau 
292b5cb4e31SSepherosa Ziehau struct netmsg_pr_ctlinput {
293002c1265SMatthew Dillon 	struct netmsg_base	base;
294e3873585SSepherosa Ziehau 	int			nm_cmd;
295130b7902SSepherosa Ziehau 	int			nm_direct;
296e3873585SSepherosa Ziehau 	struct sockaddr		*nm_arg;
297e3873585SSepherosa Ziehau 	void			*nm_extra;
298e3873585SSepherosa Ziehau };
299e3873585SSepherosa Ziehau 
300002c1265SMatthew Dillon /*
301002c1265SMatthew Dillon  * Union of all possible netmsgs.  Note that when a netmsg is sent the
302002c1265SMatthew Dillon  * actual allocated storage is likely only the size of the particular
303002c1265SMatthew Dillon  * class of message, and not sizeof(union netmsg).
304002c1265SMatthew Dillon  */
305002c1265SMatthew Dillon union netmsg {
306002c1265SMatthew Dillon 	struct lwkt_msg			lmsg;		/* base embedded */
307002c1265SMatthew Dillon 	struct netmsg_base		base;		/* base embedded */
308002c1265SMatthew Dillon 
309002c1265SMatthew Dillon 	struct netmsg_packet		packet;		/* mbuf embedded */
310*a6da5b60SKyle Butt 	struct netmsg_forward		forward;	/* mbuf embedded */
311002c1265SMatthew Dillon 	struct netmsg_pr_timeout	timeout;
312002c1265SMatthew Dillon 	struct netmsg_so_notify		notify;
313002c1265SMatthew Dillon 	struct netmsg_so_notify_abort	notify_abort;
314002c1265SMatthew Dillon 
315002c1265SMatthew Dillon 	struct netmsg_pr_ctloutput	ctloutput;
316b5cb4e31SSepherosa Ziehau 	struct netmsg_pr_ctlinput	ctlinput;
317002c1265SMatthew Dillon 
318002c1265SMatthew Dillon 	struct netmsg_pru_abort		abort;
319002c1265SMatthew Dillon 	struct netmsg_pru_accept	accept;		/* synchronous */
320002c1265SMatthew Dillon 	struct netmsg_pru_attach	attach;
321002c1265SMatthew Dillon 	struct netmsg_pru_bind		bind;
322002c1265SMatthew Dillon 	struct netmsg_pru_connect	connect;
323002c1265SMatthew Dillon 	struct netmsg_pru_connect2	connect2;
324002c1265SMatthew Dillon 	struct netmsg_pru_control	control;	/* synchronous */
325002c1265SMatthew Dillon 	struct netmsg_pru_detach	detach;
326002c1265SMatthew Dillon 	struct netmsg_pru_disconnect	disconnect;
327002c1265SMatthew Dillon 	struct netmsg_pru_listen	listen;
328002c1265SMatthew Dillon 	struct netmsg_pru_peeraddr	peeraddr;
329002c1265SMatthew Dillon 	struct netmsg_pru_rcvd		rcvd;
330002c1265SMatthew Dillon 	struct netmsg_pru_rcvoob	rcvoob;
331002c1265SMatthew Dillon 	struct netmsg_pru_send		send;
332002c1265SMatthew Dillon 	struct netmsg_pru_sense		sense;
333002c1265SMatthew Dillon 	struct netmsg_pru_shutdown	shutdown;
334002c1265SMatthew Dillon 	struct netmsg_pru_sockaddr	sockaddr;
335002c1265SMatthew Dillon 	struct netmsg_pru_sosend	sosend;		/* synchronous */
336002c1265SMatthew Dillon 	struct netmsg_pru_soreceive	soreceive;	/* synchronous */
337002c1265SMatthew Dillon };
338002c1265SMatthew Dillon 
3398d420ad8SSepherosa Ziehau #endif	/* _KERNEL || _KERNEL_STRUCTURES */
3408d420ad8SSepherosa Ziehau 
3418d420ad8SSepherosa Ziehau #endif	/* !_NET_NETMSG_H_ */
342