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