Print this page
dccp: conn_t
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/inet/ipclassifier.h
+++ new/usr/src/uts/common/inet/ipclassifier.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 #ifndef _INET_IPCLASSIFIER_H
↓ open down ↓ |
26 lines elided |
↑ open up ↑ |
27 27 #define _INET_IPCLASSIFIER_H
28 28
29 29 #ifdef __cplusplus
30 30 extern "C" {
31 31 #endif
32 32
33 33 #include <inet/common.h>
34 34 #include <inet/ip.h>
35 35 #include <inet/mi.h>
36 36 #include <inet/tcp.h>
37 +#include <inet/dccp.h>
37 38 #include <inet/ip6.h>
38 39 #include <netinet/in.h> /* for IPPROTO_* constants */
39 40 #include <sys/sdt.h>
40 41 #include <sys/socket_proto.h>
41 42 #include <sys/sunddi.h>
42 43 #include <sys/sunldi.h>
43 44
44 45 typedef void (*edesc_rpf)(void *, mblk_t *, void *, ip_recv_attr_t *);
45 46 struct icmph_s;
46 47 struct icmp6_hdr;
47 48 typedef boolean_t (*edesc_vpf)(conn_t *, void *, struct icmph_s *,
48 49 struct icmp6_hdr *, ip_recv_attr_t *);
49 50
50 51 /*
51 52 * ==============================
52 53 * = The CONNECTION =
53 54 * ==============================
54 55 */
55 56
56 57 /*
57 58 * The connection structure contains the common information/flags/ref needed.
58 59 * Implementation will keep the connection struct, the layers (with their
59 60 * respective data for event i.e. tcp_t if event was tcp_input_data) all in one
60 61 * contiguous memory location.
61 62 */
62 63
63 64 /* Conn Flags */
64 65 /* Unused 0x00020000 */
65 66 /* Unused 0x00040000 */
66 67 #define IPCL_FULLY_BOUND 0x00080000 /* Bound to correct squeue */
67 68 /* Unused 0x00100000 */
68 69 /* Unused 0x00200000 */
69 70 /* Unused 0x00400000 */
70 71 #define IPCL_CL_LISTENER 0x00800000 /* Cluster listener */
71 72 /* Unused 0x01000000 */
72 73 /* Unused 0x02000000 */
73 74 /* Unused 0x04000000 */
74 75 /* Unused 0x08000000 */
75 76 /* Unused 0x10000000 */
76 77 /* Unused 0x20000000 */
↓ open down ↓ |
30 lines elided |
↑ open up ↑ |
77 78 #define IPCL_CONNECTED 0x40000000 /* Conn in connected table */
78 79 #define IPCL_BOUND 0x80000000 /* Conn in bind table */
79 80
80 81 /* Flags identifying the type of conn */
81 82 #define IPCL_TCPCONN 0x00000001 /* From tcp_conn_cache */
82 83 #define IPCL_SCTPCONN 0x00000002 /* From sctp_conn_cache */
83 84 #define IPCL_IPCCONN 0x00000004 /* From ip_conn_cache */
84 85 #define IPCL_UDPCONN 0x00000008 /* From udp_conn_cache */
85 86 #define IPCL_RAWIPCONN 0x00000010 /* From rawip_conn_cache */
86 87 #define IPCL_RTSCONN 0x00000020 /* From rts_conn_cache */
87 -/* Unused 0x00000040 */
88 +#define IPCL_DCCPCONN 0x00000040 /* From dccp_conn_cache */
88 89 #define IPCL_IPTUN 0x00000080 /* iptun module above us */
89 90
90 91 #define IPCL_NONSTR 0x00001000 /* A non-STREAMS socket */
91 92 /* Unused 0x10000000 */
92 93
93 94 #define IPCL_REMOVED 0x00000100
94 95 #define IPCL_REUSED 0x00000200
95 96
96 97 #define IPCL_IS_CONNECTED(connp) \
97 98 ((connp)->conn_flags & IPCL_CONNECTED)
98 99
99 100 #define IPCL_IS_BOUND(connp) \
100 101 ((connp)->conn_flags & IPCL_BOUND)
101 102
102 103 /*
103 104 * Can't use conn_proto since we need to tell difference
104 105 * between a real TCP socket and a SOCK_RAW, IPPROTO_TCP.
105 106 */
106 107 #define IPCL_IS_TCP(connp) \
107 108 ((connp)->conn_flags & IPCL_TCPCONN)
108 109
109 110 #define IPCL_IS_SCTP(connp) \
110 111 ((connp)->conn_flags & IPCL_SCTPCONN)
111 112
112 113 #define IPCL_IS_UDP(connp) \
113 114 ((connp)->conn_flags & IPCL_UDPCONN)
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
114 115
115 116 #define IPCL_IS_RAWIP(connp) \
116 117 ((connp)->conn_flags & IPCL_RAWIPCONN)
117 118
118 119 #define IPCL_IS_RTS(connp) \
119 120 ((connp)->conn_flags & IPCL_RTSCONN)
120 121
121 122 #define IPCL_IS_IPTUN(connp) \
122 123 ((connp)->conn_flags & IPCL_IPTUN)
123 124
125 +#define IPCL_IS_DCCP(connp) \
126 + ((connp)->conn_flags & IPCL_DCCPCONN)
127 +
124 128 #define IPCL_IS_NONSTR(connp) ((connp)->conn_flags & IPCL_NONSTR)
125 129
126 130 typedef struct connf_s connf_t;
127 131
128 132 typedef struct
129 133 {
130 134 int ctb_depth;
131 135 #define CONN_STACK_DEPTH 15
132 136 pc_t ctb_stack[CONN_STACK_DEPTH];
133 137 } conn_trace_t;
134 138
135 139 typedef struct ip_helper_minor_info_s {
136 140 dev_t ip_minfo_dev; /* Device */
137 141 vmem_t *ip_minfo_arena; /* Arena */
138 142 } ip_helper_minfo_t;
139 143
140 144 /*
141 145 * ip helper stream info
142 146 */
143 147 typedef struct ip_helper_stream_info_s {
144 148 ldi_handle_t iphs_handle;
145 149 queue_t *iphs_rq;
146 150 queue_t *iphs_wq;
147 151 ip_helper_minfo_t *iphs_minfo;
148 152 } ip_helper_stream_info_t;
149 153
150 154 /*
151 155 * Mandatory Access Control mode, in conn_t's conn_mac_mode field.
152 156 * CONN_MAC_DEFAULT: strict enforcement of MAC.
153 157 * CONN_MAC_AWARE: allows communications between unlabeled systems
154 158 * and privileged daemons
155 159 * CONN_MAC_IMPLICIT: allows communications without explicit labels
156 160 * on the wire with privileged daemons.
157 161 *
158 162 * CONN_MAC_IMPLICIT is intended specifically for labeled IPsec key management
159 163 * in networks which don't pass CIPSO-labeled packets.
160 164 */
161 165 #define CONN_MAC_DEFAULT 0
162 166 #define CONN_MAC_AWARE 1
163 167 #define CONN_MAC_IMPLICIT 2
164 168
165 169 /*
166 170 * conn receive ancillary definition.
167 171 *
168 172 * These are the set of socket options that make the receive side
169 173 * potentially pass up ancillary data items.
170 174 * We have a union with an integer so that we can quickly check whether
171 175 * any ancillary data items need to be added.
172 176 */
173 177 typedef struct crb_s {
174 178 union {
175 179 uint32_t crbu_all;
176 180 struct {
177 181 uint32_t
178 182 crbb_recvdstaddr : 1, /* IP_RECVDSTADDR option */
179 183 crbb_recvopts : 1, /* IP_RECVOPTS option */
180 184 crbb_recvif : 1, /* IP_RECVIF option */
181 185 crbb_recvslla : 1, /* IP_RECVSLLA option */
182 186
183 187 crbb_recvttl : 1, /* IP_RECVTTL option */
184 188 crbb_ip_recvpktinfo : 1, /* IP*_RECVPKTINFO option */
185 189 crbb_ipv6_recvhoplimit : 1, /* IPV6_RECVHOPLIMIT option */
186 190 crbb_ipv6_recvhopopts : 1, /* IPV6_RECVHOPOPTS option */
187 191
188 192 crbb_ipv6_recvdstopts : 1, /* IPV6_RECVDSTOPTS option */
189 193 crbb_ipv6_recvrthdr : 1, /* IPV6_RECVRTHDR option */
190 194 crbb_old_ipv6_recvdstopts : 1, /* old form of IPV6_DSTOPTS */
191 195 crbb_ipv6_recvrthdrdstopts : 1, /* IPV6_RECVRTHDRDSTOPTS */
192 196
193 197 crbb_ipv6_recvtclass : 1, /* IPV6_RECVTCLASS */
194 198 crbb_recvucred : 1, /* IP_RECVUCRED option */
195 199 crbb_timestamp : 1; /* SO_TIMESTAMP "socket" option */
196 200
197 201 } crbb;
198 202 } crbu;
199 203 } crb_t;
200 204
201 205 #define crb_all crbu.crbu_all
202 206 #define crb_recvdstaddr crbu.crbb.crbb_recvdstaddr
203 207 #define crb_recvopts crbu.crbb.crbb_recvopts
204 208 #define crb_recvif crbu.crbb.crbb_recvif
205 209 #define crb_recvslla crbu.crbb.crbb_recvslla
206 210 #define crb_recvttl crbu.crbb.crbb_recvttl
207 211 #define crb_ip_recvpktinfo crbu.crbb.crbb_ip_recvpktinfo
208 212 #define crb_ipv6_recvhoplimit crbu.crbb.crbb_ipv6_recvhoplimit
209 213 #define crb_ipv6_recvhopopts crbu.crbb.crbb_ipv6_recvhopopts
210 214 #define crb_ipv6_recvdstopts crbu.crbb.crbb_ipv6_recvdstopts
211 215 #define crb_ipv6_recvrthdr crbu.crbb.crbb_ipv6_recvrthdr
212 216 #define crb_old_ipv6_recvdstopts crbu.crbb.crbb_old_ipv6_recvdstopts
213 217 #define crb_ipv6_recvrthdrdstopts crbu.crbb.crbb_ipv6_recvrthdrdstopts
214 218 #define crb_ipv6_recvtclass crbu.crbb.crbb_ipv6_recvtclass
215 219 #define crb_recvucred crbu.crbb.crbb_recvucred
216 220 #define crb_timestamp crbu.crbb.crbb_timestamp
217 221
218 222 /*
219 223 * The initial fields in the conn_t are setup by the kmem_cache constructor,
220 224 * and are preserved when it is freed. Fields after that are bzero'ed when
221 225 * the conn_t is freed.
222 226 *
223 227 * Much of the conn_t is protected by conn_lock.
224 228 *
225 229 * conn_lock is also used by some ULPs (like UDP and RAWIP) to protect
226 230 * their state.
227 231 */
228 232 struct conn_s {
229 233 kmutex_t conn_lock;
↓ open down ↓ |
96 lines elided |
↑ open up ↑ |
230 234 uint32_t conn_ref; /* Reference counter */
231 235 uint32_t conn_flags; /* Conn Flags */
232 236
233 237 union {
234 238 tcp_t *cp_tcp; /* Pointer to the tcp struct */
235 239 struct udp_s *cp_udp; /* Pointer to the udp struct */
236 240 struct icmp_s *cp_icmp; /* Pointer to rawip struct */
237 241 struct rts_s *cp_rts; /* Pointer to rts struct */
238 242 struct iptun_s *cp_iptun; /* Pointer to iptun_t */
239 243 struct sctp_s *cp_sctp; /* For IPCL_SCTPCONN */
244 + struct dccp_s *cp_dccp; /* Pointer to dccp struct */
240 245 void *cp_priv;
241 246 } conn_proto_priv;
242 247 #define conn_tcp conn_proto_priv.cp_tcp
243 248 #define conn_udp conn_proto_priv.cp_udp
244 249 #define conn_icmp conn_proto_priv.cp_icmp
245 250 #define conn_rts conn_proto_priv.cp_rts
246 251 #define conn_iptun conn_proto_priv.cp_iptun
247 252 #define conn_sctp conn_proto_priv.cp_sctp
253 +#define conn_dccp conn_proto_priv.cp_dccp
248 254 #define conn_priv conn_proto_priv.cp_priv
249 255
250 256 kcondvar_t conn_cv;
251 257 uint8_t conn_proto; /* protocol type */
252 258
253 259 edesc_rpf conn_recv; /* Pointer to recv routine */
254 260 edesc_rpf conn_recvicmp; /* For ICMP error */
255 261 edesc_vpf conn_verifyicmp; /* Verify ICMP error */
256 262
257 263 ip_xmit_attr_t *conn_ixa; /* Options if no ancil data */
258 264
259 265 /* Fields after this are bzero'ed when the conn_t is freed. */
260 266 #define conn_start_clr conn_recv_ancillary
261 267
262 268 /* Options for receive-side ancillary data */
263 269 crb_t conn_recv_ancillary;
264 270
265 271 squeue_t *conn_sqp; /* Squeue for processing */
266 272 uint_t conn_state_flags; /* IP state flags */
267 273
268 274 int conn_lingertime; /* linger time (in seconds) */
269 275
270 276 unsigned int
271 277 conn_on_sqp : 1, /* Conn is being processed */
272 278 conn_linger : 1, /* SO_LINGER state */
273 279 conn_useloopback : 1, /* SO_USELOOPBACK state */
274 280 conn_broadcast : 1, /* SO_BROADCAST state */
275 281
276 282 conn_reuseaddr : 1, /* SO_REUSEADDR state */
277 283 conn_keepalive : 1, /* SO_KEEPALIVE state */
278 284 conn_multi_router : 1, /* Wants all multicast pkts */
279 285 conn_unspec_src : 1, /* IP_UNSPEC_SRC */
280 286
281 287 conn_policy_cached : 1, /* Is policy cached/latched ? */
282 288 conn_in_enforce_policy : 1, /* Enforce Policy on inbound */
283 289 conn_out_enforce_policy : 1, /* Enforce Policy on outbound */
284 290 conn_debug : 1, /* SO_DEBUG */
285 291
286 292 conn_ipv6_v6only : 1, /* IPV6_V6ONLY */
287 293 conn_oobinline : 1, /* SO_OOBINLINE state */
288 294 conn_dgram_errind : 1, /* SO_DGRAM_ERRIND state */
289 295 conn_exclbind : 1, /* SO_EXCLBIND state */
290 296
291 297 conn_mdt_ok : 1, /* MDT is permitted */
292 298 conn_allzones : 1, /* SO_ALLZONES */
293 299 conn_ipv6_recvpathmtu : 1, /* IPV6_RECVPATHMTU */
294 300 conn_mcbc_bind : 1, /* Bound to multi/broadcast */
295 301
296 302 conn_pad_to_bit_31 : 12;
297 303
298 304 boolean_t conn_blocked; /* conn is flow-controlled */
299 305
300 306 squeue_t *conn_initial_sqp; /* Squeue at open time */
301 307 squeue_t *conn_final_sqp; /* Squeue after connect */
302 308 ill_t *conn_dhcpinit_ill; /* IP_DHCPINIT_IF */
303 309 ipsec_latch_t *conn_latch; /* latched IDS */
304 310 struct ipsec_policy_s *conn_latch_in_policy; /* latched policy (in) */
305 311 struct ipsec_action_s *conn_latch_in_action; /* latched action (in) */
306 312 uint_t conn_bound_if; /* IP*_BOUND_IF */
307 313 queue_t *conn_rq; /* Read queue */
308 314 queue_t *conn_wq; /* Write queue */
309 315 dev_t conn_dev; /* Minor number */
310 316 vmem_t *conn_minor_arena; /* Minor arena */
311 317 ip_helper_stream_info_t *conn_helper_info;
312 318
313 319 cred_t *conn_cred; /* Credentials */
314 320 pid_t conn_cpid; /* pid from open/connect */
315 321 uint64_t conn_open_time; /* time when this was opened */
316 322
317 323 connf_t *conn_g_fanout; /* Global Hash bucket head */
318 324 struct conn_s *conn_g_next; /* Global Hash chain next */
319 325 struct conn_s *conn_g_prev; /* Global Hash chain prev */
320 326 struct ipsec_policy_head_s *conn_policy; /* Configured policy */
321 327 in6_addr_t conn_bound_addr_v6; /* Address in bind() */
322 328 #define conn_bound_addr_v4 V4_PART_OF_V6(conn_bound_addr_v6)
323 329 connf_t *conn_fanout; /* Hash bucket we're part of */
324 330 struct conn_s *conn_next; /* Hash chain next */
325 331 struct conn_s *conn_prev; /* Hash chain prev */
326 332
327 333 struct {
328 334 in6_addr_t connua_laddr; /* Local address - match */
329 335 in6_addr_t connua_faddr; /* Remote address */
330 336 } connua_v6addr;
331 337 #define conn_laddr_v4 V4_PART_OF_V6(connua_v6addr.connua_laddr)
332 338 #define conn_faddr_v4 V4_PART_OF_V6(connua_v6addr.connua_faddr)
333 339 #define conn_laddr_v6 connua_v6addr.connua_laddr
334 340 #define conn_faddr_v6 connua_v6addr.connua_faddr
335 341 in6_addr_t conn_saddr_v6; /* Local address - source */
336 342 #define conn_saddr_v4 V4_PART_OF_V6(conn_saddr_v6)
337 343
338 344 union {
339 345 /* Used for classifier match performance */
340 346 uint32_t connu_ports2;
341 347 struct {
342 348 in_port_t connu_fport; /* Remote port */
343 349 in_port_t connu_lport; /* Local port */
344 350 } connu_ports;
345 351 } u_port;
346 352 #define conn_fport u_port.connu_ports.connu_fport
347 353 #define conn_lport u_port.connu_ports.connu_lport
348 354 #define conn_ports u_port.connu_ports2
349 355
350 356 uint_t conn_incoming_ifindex; /* IP{,V6}_BOUND_IF, scopeid */
351 357 ill_t *conn_oper_pending_ill; /* pending shared ioctl */
352 358
353 359 krwlock_t conn_ilg_lock; /* Protects conn_ilg_* */
354 360 ilg_t *conn_ilg; /* Group memberships */
355 361
356 362 kcondvar_t conn_refcv; /* For conn_oper_pending_ill */
357 363
358 364 struct conn_s *conn_drain_next; /* Next conn in drain list */
359 365 struct conn_s *conn_drain_prev; /* Prev conn in drain list */
360 366 idl_t *conn_idl; /* Ptr to the drain list head */
361 367 mblk_t *conn_ipsec_opt_mp; /* ipsec option mblk */
362 368 zoneid_t conn_zoneid; /* zone connection is in */
363 369 int conn_rtaware; /* RT_AWARE sockopt value */
364 370 kcondvar_t conn_sq_cv; /* For non-STREAMS socket IO */
365 371 sock_upcalls_t *conn_upcalls; /* Upcalls to sockfs */
366 372 sock_upper_handle_t conn_upper_handle; /* Upper handle: sonode * */
367 373
368 374 unsigned int
369 375 conn_mlp_type : 2, /* mlp_type_t; tsol/tndb.h */
370 376 conn_anon_mlp : 1, /* user wants anon MLP */
371 377 conn_anon_port : 1, /* user bound anonymously */
372 378
373 379 conn_mac_mode : 2, /* normal/loose/implicit MAC */
374 380 conn_anon_priv_bind : 1, /* *_ANON_PRIV_BIND state */
375 381 conn_zone_is_global : 1, /* GLOBAL_ZONEID */
376 382 conn_isvrrp : 1, /* VRRP control socket */
377 383 conn_spare : 23;
378 384
379 385 boolean_t conn_flow_cntrld;
380 386 netstack_t *conn_netstack; /* Corresponds to a netstack_hold */
381 387
382 388 /*
383 389 * IP format that packets received for this struct should use.
384 390 * Value can be IP4_VERSION or IPV6_VERSION.
385 391 * The sending version is encoded using IXAF_IS_IPV4.
386 392 */
387 393 ushort_t conn_ipversion;
388 394
389 395 /* Written to only once at the time of opening the endpoint */
390 396 sa_family_t conn_family; /* Family from socket() call */
391 397 uint_t conn_so_type; /* Type from socket() call */
392 398
393 399 uint_t conn_sndbuf; /* SO_SNDBUF state */
394 400 uint_t conn_rcvbuf; /* SO_RCVBUF state */
395 401 uint_t conn_wroff; /* Current write offset */
396 402
397 403 uint_t conn_sndlowat; /* Send buffer low water mark */
398 404 uint_t conn_rcvlowat; /* Recv buffer low water mark */
399 405
400 406 uint8_t conn_default_ttl; /* Default TTL/hoplimit */
401 407
402 408 uint32_t conn_flowinfo; /* Connected flow id and tclass */
403 409
404 410 /*
405 411 * The most recent address for sendto. Initially set to zero
406 412 * which is always different than then the destination address
407 413 * since the send interprets zero as the loopback address.
408 414 */
409 415 in6_addr_t conn_v6lastdst;
410 416 #define conn_v4lastdst V4_PART_OF_V6(conn_v6lastdst)
411 417 ushort_t conn_lastipversion;
412 418 in_port_t conn_lastdstport;
413 419 uint32_t conn_lastflowinfo; /* IPv6-only */
414 420 uint_t conn_lastscopeid; /* IPv6-only */
415 421 uint_t conn_lastsrcid; /* Only for AF_INET6 */
416 422 /*
417 423 * When we are not connected conn_saddr might be unspecified.
418 424 * We track the source that was used with conn_v6lastdst here.
419 425 */
420 426 in6_addr_t conn_v6lastsrc;
421 427 #define conn_v4lastsrc V4_PART_OF_V6(conn_v6lastsrc)
422 428
423 429 /* Templates for transmitting packets */
424 430 ip_pkt_t conn_xmit_ipp; /* Options if no ancil data */
425 431
426 432 /*
427 433 * Header template - conn_ht_ulp is a pointer into conn_ht_iphc.
428 434 * Note that ixa_ip_hdr_length indicates the offset of ht_ulp in
429 435 * ht_iphc
430 436 *
431 437 * The header template is maintained for connected endpoints (and
432 438 * updated when sticky options are changed) and also for the lastdst.
433 439 * There is no conflict between those usages since SOCK_DGRAM and
434 440 * SOCK_RAW can not be used to specify a destination address (with
435 441 * sendto/sendmsg) if the socket has been connected.
436 442 */
437 443 uint8_t *conn_ht_iphc; /* Start of IP header */
438 444 uint_t conn_ht_iphc_allocated; /* Allocated buffer size */
439 445 uint_t conn_ht_iphc_len; /* IP+ULP size */
440 446 uint8_t *conn_ht_ulp; /* Upper-layer header */
441 447 uint_t conn_ht_ulp_len; /* ULP header len */
442 448
443 449 /* Checksum to compensate for source routed packets. Host byte order */
444 450 uint32_t conn_sum;
445 451
446 452 uint32_t conn_ioctlref; /* ioctl ref count */
447 453 #ifdef CONN_DEBUG
448 454 #define CONN_TRACE_MAX 10
449 455 int conn_trace_last; /* ndx of last used tracebuf */
450 456 conn_trace_t conn_trace_buf[CONN_TRACE_MAX];
451 457 #endif
452 458 };
453 459
454 460 /*
455 461 * connf_t - connection fanout data.
456 462 *
457 463 * The hash tables and their linkage (conn_t.{hashnextp, hashprevp} are
458 464 * protected by the per-bucket lock. Each conn_t inserted in the list
459 465 * points back at the connf_t that heads the bucket.
460 466 */
461 467 struct connf_s {
462 468 struct conn_s *connf_head;
463 469 kmutex_t connf_lock;
464 470 };
465 471
466 472 #define CONN_INC_REF(connp) { \
467 473 mutex_enter(&(connp)->conn_lock); \
468 474 DTRACE_PROBE1(conn__inc__ref, conn_t *, connp); \
469 475 ASSERT(conn_trace_ref(connp)); \
470 476 (connp)->conn_ref++; \
471 477 ASSERT((connp)->conn_ref != 0); \
472 478 mutex_exit(&(connp)->conn_lock); \
473 479 }
474 480
475 481 #define CONN_INC_REF_LOCKED(connp) { \
476 482 DTRACE_PROBE1(conn__inc__ref, conn_t *, connp); \
477 483 ASSERT(MUTEX_HELD(&(connp)->conn_lock)); \
478 484 ASSERT(conn_trace_ref(connp)); \
479 485 (connp)->conn_ref++; \
480 486 ASSERT((connp)->conn_ref != 0); \
481 487 }
482 488
483 489 #define CONN_DEC_REF(connp) { \
484 490 mutex_enter(&(connp)->conn_lock); \
485 491 DTRACE_PROBE1(conn__dec__ref, conn_t *, connp); \
486 492 /* \
487 493 * The squeue framework always does a CONN_DEC_REF after return \
488 494 * from TCP. Hence the refcnt must be at least 2 if conn_on_sqp \
489 495 * is B_TRUE and conn_ref is being decremented. This is to \
490 496 * account for the mblk being currently processed. \
491 497 */ \
492 498 if ((connp)->conn_ref == 0 || \
493 499 ((connp)->conn_ref == 1 && (connp)->conn_on_sqp)) \
494 500 cmn_err(CE_PANIC, "CONN_DEC_REF: connp(%p) has ref " \
495 501 "= %d\n", (void *)(connp), (connp)->conn_ref); \
496 502 ASSERT(conn_untrace_ref(connp)); \
497 503 (connp)->conn_ref--; \
498 504 if ((connp)->conn_ref == 0) { \
499 505 /* Refcnt can't increase again, safe to drop lock */ \
500 506 mutex_exit(&(connp)->conn_lock); \
501 507 ipcl_conn_destroy(connp); \
502 508 } else { \
503 509 cv_broadcast(&(connp)->conn_cv); \
504 510 mutex_exit(&(connp)->conn_lock); \
505 511 } \
506 512 }
507 513
508 514 /*
509 515 * For use with subsystems within ip which use ALL_ZONES as a wildcard
510 516 */
511 517 #define IPCL_ZONEID(connp) \
512 518 ((connp)->conn_allzones ? ALL_ZONES : (connp)->conn_zoneid)
513 519
514 520 /*
515 521 * For matching between a conn_t and a zoneid.
516 522 */
517 523 #define IPCL_ZONE_MATCH(connp, zoneid) \
518 524 (((connp)->conn_allzones) || \
519 525 ((zoneid) == ALL_ZONES) || \
520 526 (connp)->conn_zoneid == (zoneid))
521 527
522 528 /*
523 529 * On a labeled system, we must treat bindings to ports
524 530 * on shared IP addresses by sockets with MAC exemption
525 531 * privilege as being in all zones, as there's
526 532 * otherwise no way to identify the right receiver.
527 533 */
528 534
529 535 #define IPCL_CONNS_MAC(conn1, conn2) \
530 536 (((conn1)->conn_mac_mode != CONN_MAC_DEFAULT) || \
531 537 ((conn2)->conn_mac_mode != CONN_MAC_DEFAULT))
532 538
533 539 #define IPCL_BIND_ZONE_MATCH(conn1, conn2) \
534 540 (IPCL_CONNS_MAC(conn1, conn2) || \
535 541 IPCL_ZONE_MATCH(conn1, conn2->conn_zoneid) || \
536 542 IPCL_ZONE_MATCH(conn2, conn1->conn_zoneid))
537 543
538 544
539 545 #define _IPCL_V4_MATCH(v6addr, v4addr) \
540 546 (V4_PART_OF_V6((v6addr)) == (v4addr) && IN6_IS_ADDR_V4MAPPED(&(v6addr)))
541 547
542 548 #define _IPCL_V4_MATCH_ANY(addr) \
543 549 (IN6_IS_ADDR_V4MAPPED_ANY(&(addr)) || IN6_IS_ADDR_UNSPECIFIED(&(addr)))
544 550
545 551
546 552 /*
547 553 * IPCL_PROTO_MATCH() and IPCL_PROTO_MATCH_V6() only matches conns with
548 554 * the specified ira_zoneid or conn_allzones by calling conn_wantpacket.
549 555 */
550 556 #define IPCL_PROTO_MATCH(connp, ira, ipha) \
551 557 ((((connp)->conn_laddr_v4 == INADDR_ANY) || \
552 558 (((connp)->conn_laddr_v4 == ((ipha)->ipha_dst)) && \
553 559 (((connp)->conn_faddr_v4 == INADDR_ANY) || \
554 560 ((connp)->conn_faddr_v4 == ((ipha)->ipha_src))))) && \
555 561 conn_wantpacket((connp), (ira), (ipha)))
556 562
557 563 #define IPCL_PROTO_MATCH_V6(connp, ira, ip6h) \
558 564 ((IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_laddr_v6) || \
559 565 (IN6_ARE_ADDR_EQUAL(&(connp)->conn_laddr_v6, &((ip6h)->ip6_dst)) && \
560 566 (IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_faddr_v6) || \
561 567 IN6_ARE_ADDR_EQUAL(&(connp)->conn_faddr_v6, &((ip6h)->ip6_src))))) && \
562 568 (conn_wantpacket_v6((connp), (ira), (ip6h))))
563 569
564 570 #define IPCL_CONN_HASH(src, ports, ipst) \
565 571 ((unsigned)(ntohl((src)) ^ ((ports) >> 24) ^ ((ports) >> 16) ^ \
566 572 ((ports) >> 8) ^ (ports)) % (ipst)->ips_ipcl_conn_fanout_size)
567 573
568 574 #define IPCL_CONN_HASH_V6(src, ports, ipst) \
569 575 IPCL_CONN_HASH(V4_PART_OF_V6((src)), (ports), (ipst))
570 576
571 577 #define IPCL_CONN_MATCH(connp, proto, src, dst, ports) \
572 578 ((connp)->conn_proto == (proto) && \
573 579 (connp)->conn_ports == (ports) && \
574 580 _IPCL_V4_MATCH((connp)->conn_faddr_v6, (src)) && \
575 581 _IPCL_V4_MATCH((connp)->conn_laddr_v6, (dst)) && \
576 582 !(connp)->conn_ipv6_v6only)
577 583
578 584 #define IPCL_CONN_MATCH_V6(connp, proto, src, dst, ports) \
579 585 ((connp)->conn_proto == (proto) && \
580 586 (connp)->conn_ports == (ports) && \
581 587 IN6_ARE_ADDR_EQUAL(&(connp)->conn_faddr_v6, &(src)) && \
582 588 IN6_ARE_ADDR_EQUAL(&(connp)->conn_laddr_v6, &(dst)))
583 589
584 590 #define IPCL_PORT_HASH(port, size) \
585 591 ((((port) >> 8) ^ (port)) & ((size) - 1))
586 592
587 593 #define IPCL_BIND_HASH(lport, ipst) \
588 594 ((unsigned)(((lport) >> 8) ^ (lport)) % \
589 595 (ipst)->ips_ipcl_bind_fanout_size)
590 596
591 597 #define IPCL_BIND_MATCH(connp, proto, laddr, lport) \
592 598 ((connp)->conn_proto == (proto) && \
593 599 (connp)->conn_lport == (lport) && \
594 600 (_IPCL_V4_MATCH_ANY((connp)->conn_laddr_v6) || \
595 601 _IPCL_V4_MATCH((connp)->conn_laddr_v6, (laddr))) && \
596 602 !(connp)->conn_ipv6_v6only)
597 603
598 604 #define IPCL_BIND_MATCH_V6(connp, proto, laddr, lport) \
599 605 ((connp)->conn_proto == (proto) && \
600 606 (connp)->conn_lport == (lport) && \
601 607 (IN6_ARE_ADDR_EQUAL(&(connp)->conn_laddr_v6, &(laddr)) || \
602 608 IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_laddr_v6)))
603 609
604 610 /*
605 611 * We compare conn_laddr since it captures both connected and a bind to
606 612 * a multicast or broadcast address.
607 613 * The caller needs to match the zoneid and also call conn_wantpacket
608 614 * for multicast, broadcast, or when conn_incoming_ifindex is set.
609 615 */
610 616 #define IPCL_UDP_MATCH(connp, lport, laddr, fport, faddr) \
611 617 (((connp)->conn_lport == (lport)) && \
612 618 ((_IPCL_V4_MATCH_ANY((connp)->conn_laddr_v6) || \
613 619 (_IPCL_V4_MATCH((connp)->conn_laddr_v6, (laddr)) && \
614 620 (_IPCL_V4_MATCH_ANY((connp)->conn_faddr_v6) || \
615 621 (_IPCL_V4_MATCH((connp)->conn_faddr_v6, (faddr)) && \
616 622 (connp)->conn_fport == (fport)))))) && \
617 623 !(connp)->conn_ipv6_v6only)
618 624
619 625 /*
620 626 * We compare conn_laddr since it captures both connected and a bind to
621 627 * a multicast or broadcast address.
622 628 * The caller needs to match the zoneid and also call conn_wantpacket_v6
623 629 * for multicast or when conn_incoming_ifindex is set.
624 630 */
625 631 #define IPCL_UDP_MATCH_V6(connp, lport, laddr, fport, faddr) \
626 632 (((connp)->conn_lport == (lport)) && \
627 633 (IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_laddr_v6) || \
628 634 (IN6_ARE_ADDR_EQUAL(&(connp)->conn_laddr_v6, &(laddr)) && \
629 635 (IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_faddr_v6) || \
630 636 (IN6_ARE_ADDR_EQUAL(&(connp)->conn_faddr_v6, &(faddr)) && \
631 637 (connp)->conn_fport == (fport))))))
632 638
633 639 #define IPCL_IPTUN_HASH(laddr, faddr) \
634 640 ((ntohl(laddr) ^ ((ntohl(faddr) << 24) | (ntohl(faddr) >> 8))) % \
635 641 ipcl_iptun_fanout_size)
636 642
637 643 #define IPCL_IPTUN_HASH_V6(laddr, faddr) \
638 644 IPCL_IPTUN_HASH((laddr)->s6_addr32[0] ^ (laddr)->s6_addr32[1] ^ \
639 645 (faddr)->s6_addr32[2] ^ (faddr)->s6_addr32[3], \
640 646 (faddr)->s6_addr32[0] ^ (faddr)->s6_addr32[1] ^ \
641 647 (laddr)->s6_addr32[2] ^ (laddr)->s6_addr32[3])
642 648
643 649 #define IPCL_IPTUN_MATCH(connp, laddr, faddr) \
↓ open down ↓ |
386 lines elided |
↑ open up ↑ |
644 650 (_IPCL_V4_MATCH((connp)->conn_laddr_v6, (laddr)) && \
645 651 _IPCL_V4_MATCH((connp)->conn_faddr_v6, (faddr)))
646 652
647 653 #define IPCL_IPTUN_MATCH_V6(connp, laddr, faddr) \
648 654 (IN6_ARE_ADDR_EQUAL(&(connp)->conn_laddr_v6, (laddr)) && \
649 655 IN6_ARE_ADDR_EQUAL(&(connp)->conn_faddr_v6, (faddr)))
650 656
651 657 #define IPCL_UDP_HASH(lport, ipst) \
652 658 IPCL_PORT_HASH(lport, (ipst)->ips_ipcl_udp_fanout_size)
653 659
660 +#define IPCL_DCCP_CONN_HASH(src, ports, ipst) \
661 + ((unsigned)(ntohl((src)) ^ ((ports) >> 24) ^ ((ports) >> 16) ^ \
662 + ((ports) >> 8) ^ (ports)) % (ipst)->ips_ipcl_dccp_conn_fanout_size)
663 +
664 +#define IPCL_DCCP_CONN_HASH_V6(src, ports, ipst) \
665 + IPCL_DCCP_CONN_HASH(V4_PART_OF_V6((src)), (ports), (ipst))
666 +
667 +#define IPCL_DCCP_BIND_HASH(lport, ipst) \
668 + ((unsigned)(((lport) >> 8) ^ (lport)) % \
669 + (ipst)->ips_ipcl_dccp_bind_fanout_size)
670 +
671 +
654 672 #define CONN_G_HASH_SIZE 1024
655 673
656 674 /* Raw socket hash function. */
657 675 #define IPCL_RAW_HASH(lport, ipst) \
658 676 IPCL_PORT_HASH(lport, (ipst)->ips_ipcl_raw_fanout_size)
659 677
660 678 /*
661 679 * This is similar to IPCL_BIND_MATCH except that the local port check
662 680 * is changed to a wildcard port check.
663 681 * We compare conn_laddr since it captures both connected and a bind to
664 682 * a multicast or broadcast address.
665 683 */
666 684 #define IPCL_RAW_MATCH(connp, proto, laddr) \
667 685 ((connp)->conn_proto == (proto) && \
668 686 (connp)->conn_lport == 0 && \
669 687 (_IPCL_V4_MATCH_ANY((connp)->conn_laddr_v6) || \
670 688 _IPCL_V4_MATCH((connp)->conn_laddr_v6, (laddr))))
671 689
672 690 #define IPCL_RAW_MATCH_V6(connp, proto, laddr) \
673 691 ((connp)->conn_proto == (proto) && \
674 692 (connp)->conn_lport == 0 && \
675 693 (IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_laddr_v6) || \
676 694 IN6_ARE_ADDR_EQUAL(&(connp)->conn_laddr_v6, &(laddr))))
677 695
678 696 /* Function prototypes */
679 697 extern void ipcl_g_init(void);
680 698 extern void ipcl_init(ip_stack_t *);
681 699 extern void ipcl_g_destroy(void);
682 700 extern void ipcl_destroy(ip_stack_t *);
683 701 extern conn_t *ipcl_conn_create(uint32_t, int, netstack_t *);
684 702 extern void ipcl_conn_destroy(conn_t *);
685 703
686 704 void ipcl_hash_insert_wildcard(connf_t *, conn_t *);
687 705 void ipcl_hash_remove(conn_t *);
688 706 void ipcl_hash_remove_locked(conn_t *connp, connf_t *connfp);
689 707
690 708 extern int ipcl_bind_insert(conn_t *);
691 709 extern int ipcl_bind_insert_v4(conn_t *);
692 710 extern int ipcl_bind_insert_v6(conn_t *);
693 711 extern int ipcl_conn_insert(conn_t *);
694 712 extern int ipcl_conn_insert_v4(conn_t *);
695 713 extern int ipcl_conn_insert_v6(conn_t *);
696 714 extern conn_t *ipcl_get_next_conn(connf_t *, conn_t *, uint32_t);
697 715
698 716 conn_t *ipcl_classify_v4(mblk_t *, uint8_t, uint_t, ip_recv_attr_t *,
699 717 ip_stack_t *);
700 718 conn_t *ipcl_classify_v6(mblk_t *, uint8_t, uint_t, ip_recv_attr_t *,
701 719 ip_stack_t *);
702 720 conn_t *ipcl_classify(mblk_t *, ip_recv_attr_t *, ip_stack_t *);
↓ open down ↓ |
39 lines elided |
↑ open up ↑ |
703 721 conn_t *ipcl_classify_raw(mblk_t *, uint8_t, uint32_t, ipha_t *,
704 722 ip6_t *, ip_recv_attr_t *, ip_stack_t *);
705 723 conn_t *ipcl_iptun_classify_v4(ipaddr_t *, ipaddr_t *, ip_stack_t *);
706 724 conn_t *ipcl_iptun_classify_v6(in6_addr_t *, in6_addr_t *, ip_stack_t *);
707 725 void ipcl_globalhash_insert(conn_t *);
708 726 void ipcl_globalhash_remove(conn_t *);
709 727 void ipcl_walk(pfv_t, void *, ip_stack_t *);
710 728 conn_t *ipcl_tcp_lookup_reversed_ipv4(ipha_t *, tcpha_t *, int, ip_stack_t *);
711 729 conn_t *ipcl_tcp_lookup_reversed_ipv6(ip6_t *, tcpha_t *, int, uint_t,
712 730 ip_stack_t *);
731 +/*
732 +conn_t *ipcl_dccp_lookup_reversed_ipv4(ipha_t *, dccpha_t *, int, ip_stack_t *);
733 +conn_t *ipcl_dccp_lookup_reversed_ipv6(ip6_t *, dccpha_t *, int, uint_t,
734 + ip_stack_t *);
735 +*/
713 736 conn_t *ipcl_lookup_listener_v4(uint16_t, ipaddr_t, zoneid_t, ip_stack_t *);
714 737 conn_t *ipcl_lookup_listener_v6(uint16_t, in6_addr_t *, uint_t, zoneid_t,
715 738 ip_stack_t *);
716 739 int conn_trace_ref(conn_t *);
717 740 int conn_untrace_ref(conn_t *);
718 741 void ipcl_conn_cleanup(conn_t *);
719 742 extern uint_t conn_recvancillary_size(conn_t *, crb_t, ip_recv_attr_t *,
720 743 mblk_t *, ip_pkt_t *);
721 744 extern void conn_recvancillary_add(conn_t *, crb_t, ip_recv_attr_t *,
722 745 ip_pkt_t *, uchar_t *, uint_t);
723 746 conn_t *ipcl_conn_tcp_lookup_reversed_ipv4(conn_t *, ipha_t *, tcpha_t *,
724 747 ip_stack_t *);
725 748 conn_t *ipcl_conn_tcp_lookup_reversed_ipv6(conn_t *, ip6_t *, tcpha_t *,
726 749 ip_stack_t *);
727 750
728 751 extern int ip_create_helper_stream(conn_t *, ldi_ident_t);
729 752 extern void ip_free_helper_stream(conn_t *);
730 753 extern int ip_helper_stream_setup(queue_t *, dev_t *, int, int,
731 754 cred_t *, boolean_t);
732 755
733 756 #ifdef __cplusplus
734 757 }
735 758 #endif
736 759
737 760 #endif /* _INET_IPCLASSIFIER_H */
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX