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