1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _INET_IPCLASSIFIER_H 27 #define _INET_IPCLASSIFIER_H 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 #include <inet/common.h> 34 #include <inet/ip.h> 35 #include <inet/mi.h> 36 #include <inet/tcp.h> 37 #include <inet/ip6.h> 38 #include <netinet/in.h> /* for IPPROTO_* constants */ 39 #include <sys/sdt.h> 40 41 typedef void (*edesc_spf)(void *, mblk_t *, void *, int); 42 typedef void (*edesc_rpf)(void *, mblk_t *, void *); 43 44 /* 45 * ============================== 46 * = The CONNECTION = 47 * ============================== 48 */ 49 50 /* 51 * The connection structure contains the common information/flags/ref needed. 52 * Implementation will keep the connection struct, the layers (with their 53 * respective data for event i.e. tcp_t if event was tcp_input) all in one 54 * contiguous memory location. 55 */ 56 57 /* Conn Flags */ 58 /* Unused 0x00020000 */ 59 /* Unused 0x00040000 */ 60 #define IPCL_FULLY_BOUND 0x00080000 /* Bound to correct squeue */ 61 #define IPCL_CHECK_POLICY 0x00100000 /* Needs policy checking */ 62 #define IPCL_SOCKET 0x00200000 /* Sockfs connection */ 63 #define IPCL_ACCEPTOR 0x00400000 /* Sockfs priv acceptor */ 64 #define IPCL_CL_LISTENER 0x00800000 /* Cluster listener */ 65 #define IPCL_EAGER 0x01000000 /* Incoming connection */ 66 /* Unused 0x02000000 */ 67 #define IPCL_TCP6 0x04000000 /* AF_INET6 TCP */ 68 #define IPCL_TCP4 0x08000000 /* IPv4 packet format TCP */ 69 /* Unused 0x10000000 */ 70 /* Unused 0x20000000 */ 71 #define IPCL_CONNECTED 0x40000000 /* Conn in connected table */ 72 #define IPCL_BOUND 0x80000000 /* Conn in bind table */ 73 74 /* Flags identifying the type of conn */ 75 #define IPCL_TCPCONN 0x00000001 /* From tcp_conn_cache */ 76 #define IPCL_SCTPCONN 0x00000002 /* From sctp_conn_cache */ 77 #define IPCL_IPCCONN 0x00000004 /* From ip_conn_cache */ 78 #define IPCL_UDPCONN 0x00000008 /* From udp_conn_cache */ 79 #define IPCL_RAWIPCONN 0x00000010 /* From rawip_conn_cache */ 80 #define IPCL_RTSCONN 0x00000020 /* From rts_conn_cache */ 81 #define IPCL_ISV6 0x00000040 /* AF_INET6 */ 82 #define IPCL_IPTUN 0x00000080 /* Has "tun" plumbed above it */ 83 84 /* Conn Masks */ 85 #define IPCL_TCP (IPCL_TCP4|IPCL_TCP6) 86 #define IPCL_REMOVED 0x00000100 87 #define IPCL_REUSED 0x00000200 88 89 /* The packet format is IPv4; could be an AF_INET or AF_INET6 socket */ 90 #define IPCL_IS_TCP4(connp) \ 91 (((connp)->conn_flags & IPCL_TCP4)) 92 93 /* Connected AF_INET with no IPsec policy */ 94 #define IPCL_IS_TCP4_CONNECTED_NO_POLICY(connp) \ 95 (((connp)->conn_flags & \ 96 (IPCL_TCP4|IPCL_CONNECTED|IPCL_CHECK_POLICY|IPCL_TCP6)) \ 97 == (IPCL_TCP4|IPCL_CONNECTED)) 98 99 #define IPCL_IS_CONNECTED(connp) \ 100 ((connp)->conn_flags & IPCL_CONNECTED) 101 102 #define IPCL_IS_BOUND(connp) \ 103 ((connp)->conn_flags & IPCL_BOUND) 104 105 /* AF_INET TCP that is bound */ 106 #define IPCL_IS_TCP4_BOUND(connp) \ 107 (((connp)->conn_flags & \ 108 (IPCL_TCP4|IPCL_BOUND|IPCL_TCP6)) == \ 109 (IPCL_TCP4|IPCL_BOUND)) 110 111 #define IPCL_IS_FULLY_BOUND(connp) \ 112 ((connp)->conn_flags & IPCL_FULLY_BOUND) 113 114 /* 115 * Can't use conn_protocol since we need to tell difference 116 * between a real TCP socket and a SOCK_RAW, IPPROTO_TCP. 117 */ 118 #define IPCL_IS_TCP(connp) \ 119 ((connp)->conn_flags & IPCL_TCPCONN) 120 121 #define IPCL_IS_SCTP(connp) \ 122 ((connp)->conn_flags & IPCL_SCTPCONN) 123 124 #define IPCL_IS_UDP(connp) \ 125 ((connp)->conn_flags & IPCL_UDPCONN) 126 127 #define IPCL_IS_RAWIP(connp) \ 128 ((connp)->conn_flags & IPCL_RAWIPCONN) 129 130 #define IPCL_IS_RTS(connp) \ 131 ((connp)->conn_flags & IPCL_RTSCONN) 132 133 /* FIXME: Isn't it sufficient to check IPCL_IPTUN? */ 134 #define IPCL_IS_IPTUN(connp) \ 135 (((connp)->conn_ulp == IPPROTO_ENCAP || \ 136 (connp)->conn_ulp == IPPROTO_IPV6) && \ 137 ((connp)->conn_flags & IPCL_IPTUN)) 138 139 typedef struct connf_s connf_t; 140 141 typedef struct 142 { 143 int ctb_depth; 144 #define CONN_STACK_DEPTH 15 145 pc_t ctb_stack[CONN_STACK_DEPTH]; 146 } conn_trace_t; 147 148 /* 149 * The initial fields in the conn_t are setup by the kmem_cache constructor, 150 * and are preserved when it is freed. Fields after that are bzero'ed when 151 * the conn_t is freed. 152 */ 153 struct conn_s { 154 kmutex_t conn_lock; 155 uint32_t conn_ref; /* Reference counter */ 156 uint32_t conn_flags; /* Conn Flags */ 157 158 159 union { 160 tcp_t *cp_tcp; /* Pointer to the tcp struct */ 161 struct udp_s *cp_udp; /* Pointer to the udp struct */ 162 struct icmp_s *cp_icmp; /* Pointer to rawip struct */ 163 struct rts_s *cp_rts; /* Pointer to rts struct */ 164 void *cp_priv; 165 } conn_proto_priv; 166 #define conn_tcp conn_proto_priv.cp_tcp 167 #define conn_udp conn_proto_priv.cp_udp 168 #define conn_icmp conn_proto_priv.cp_icmp 169 #define conn_rts conn_proto_priv.cp_rts 170 #define conn_priv conn_proto_priv.cp_priv 171 172 kcondvar_t conn_cv; 173 uint8_t conn_ulp; /* protocol type */ 174 175 edesc_rpf conn_recv; /* Pointer to recv routine */ 176 177 /* Fields after this are bzero'ed when the conn_t is freed. */ 178 179 squeue_t *conn_sqp; /* Squeue for processing */ 180 uint_t conn_state_flags; /* IP state flags */ 181 #define conn_start_clr conn_state_flags 182 183 ire_t *conn_ire_cache; /* outbound ire cache */ 184 unsigned int 185 conn_on_sqp : 1, /* Conn is being processed */ 186 conn_dontroute : 1, /* SO_DONTROUTE state */ 187 conn_loopback : 1, /* SO_LOOPBACK state */ 188 conn_broadcast : 1, /* SO_BROADCAST state */ 189 190 conn_reuseaddr : 1, /* SO_REUSEADDR state */ 191 conn_multicast_loop : 1, /* IP_MULTICAST_LOOP */ 192 conn_multi_router : 1, /* Wants all multicast pkts */ 193 conn_draining : 1, /* ip_wsrv running */ 194 195 conn_did_putbq : 1, /* ip_wput did a putbq */ 196 conn_unspec_src : 1, /* IP_UNSPEC_SRC */ 197 conn_policy_cached : 1, /* Is policy cached/latched ? */ 198 conn_in_enforce_policy : 1, /* Enforce Policy on inbound */ 199 200 conn_out_enforce_policy : 1, /* Enforce Policy on outbound */ 201 conn_af_isv6 : 1, /* ip address family ver 6 */ 202 conn_pkt_isv6 : 1, /* ip packet format ver 6 */ 203 conn_ip_recvpktinfo : 1, /* IPV*_RECVPKTINFO option */ 204 205 conn_ipv6_recvhoplimit : 1, /* IPV6_RECVHOPLIMIT option */ 206 conn_ipv6_recvhopopts : 1, /* IPV6_RECVHOPOPTS option */ 207 conn_ipv6_recvdstopts : 1, /* IPV6_RECVDSTOPTS option */ 208 conn_ipv6_recvrthdr : 1, /* IPV6_RECVRTHDR option */ 209 210 conn_ipv6_recvrtdstopts : 1, /* IPV6_RECVRTHDRDSTOPTS */ 211 conn_ipv6_v6only : 1, /* IPV6_V6ONLY */ 212 conn_ipv6_recvtclass : 1, /* IPV6_RECVTCLASS */ 213 conn_ipv6_recvpathmtu : 1, /* IPV6_RECVPATHMTU */ 214 215 conn_pathmtu_valid : 1, /* The cached mtu is valid. */ 216 conn_ipv6_dontfrag : 1, /* IPV6_DONTFRAG */ 217 conn_fully_bound : 1, /* Fully bound connection */ 218 conn_recvif : 1, /* IP_RECVIF option */ 219 220 conn_recvslla : 1, /* IP_RECVSLLA option */ 221 conn_mdt_ok : 1, /* MDT is permitted */ 222 conn_nexthop_set : 1, 223 conn_allzones : 1; /* SO_ALLZONES */ 224 225 unsigned int 226 conn_lso_ok : 1; /* LSO is usable */ 227 228 squeue_t *conn_initial_sqp; /* Squeue at open time */ 229 squeue_t *conn_final_sqp; /* Squeue after connect */ 230 ill_t *conn_nofailover_ill; /* Failover ill */ 231 ill_t *conn_dhcpinit_ill; /* IP_DHCPINIT_IF */ 232 ipsec_latch_t *conn_latch; /* latched state */ 233 ill_t *conn_outgoing_ill; /* IP{,V6}_BOUND_IF */ 234 edesc_spf conn_send; /* Pointer to send routine */ 235 queue_t *conn_rq; /* Read queue */ 236 queue_t *conn_wq; /* Write queue */ 237 dev_t conn_dev; /* Minor number */ 238 vmem_t *conn_minor_arena; /* Minor arena */ 239 240 cred_t *conn_cred; /* Credentials */ 241 connf_t *conn_g_fanout; /* Global Hash bucket head */ 242 struct conn_s *conn_g_next; /* Global Hash chain next */ 243 struct conn_s *conn_g_prev; /* Global Hash chain prev */ 244 struct ipsec_policy_head_s *conn_policy; /* Configured policy */ 245 in6_addr_t conn_bound_source_v6; 246 #define conn_bound_source V4_PART_OF_V6(conn_bound_source_v6) 247 248 connf_t *conn_fanout; /* Hash bucket we're part of */ 249 struct conn_s *conn_next; /* Hash chain next */ 250 struct conn_s *conn_prev; /* Hash chain prev */ 251 struct { 252 in6_addr_t connua_laddr; /* Local address */ 253 in6_addr_t connua_faddr; /* Remote address */ 254 } connua_v6addr; 255 #define conn_src V4_PART_OF_V6(connua_v6addr.connua_laddr) 256 #define conn_rem V4_PART_OF_V6(connua_v6addr.connua_faddr) 257 #define conn_srcv6 connua_v6addr.connua_laddr 258 #define conn_remv6 connua_v6addr.connua_faddr 259 union { 260 /* Used for classifier match performance */ 261 uint32_t conn_ports2; 262 struct { 263 in_port_t tcpu_fport; /* Remote port */ 264 in_port_t tcpu_lport; /* Local port */ 265 } tcpu_ports; 266 } u_port; 267 #define conn_fport u_port.tcpu_ports.tcpu_fport 268 #define conn_lport u_port.tcpu_ports.tcpu_lport 269 #define conn_ports u_port.conn_ports2 270 #define conn_upq conn_rq 271 uint8_t conn_unused_byte; 272 273 uint_t conn_proto; /* SO_PROTOTYPE state */ 274 ill_t *conn_incoming_ill; /* IP{,V6}_BOUND_IF */ 275 ill_t *conn_outgoing_pill; /* IP{,V6}_BOUND_PIF */ 276 ill_t *conn_oper_pending_ill; /* pending shared ioctl */ 277 278 ilg_t *conn_ilg; /* Group memberships */ 279 int conn_ilg_allocated; /* Number allocated */ 280 int conn_ilg_inuse; /* Number currently used */ 281 int conn_ilg_walker_cnt; /* No of ilg walkers */ 282 /* XXXX get rid of this, once ilg_delete_all is fixed */ 283 kcondvar_t conn_refcv; 284 285 struct ipif_s *conn_multicast_ipif; /* IP_MULTICAST_IF */ 286 ill_t *conn_multicast_ill; /* IPV6_MULTICAST_IF */ 287 int conn_orig_bound_ifindex; /* BOUND_IF before MOVE */ 288 int conn_orig_multicast_ifindex; 289 /* IPv6 MC IF before MOVE */ 290 struct conn_s *conn_drain_next; /* Next conn in drain list */ 291 struct conn_s *conn_drain_prev; /* Prev conn in drain list */ 292 idl_t *conn_idl; /* Ptr to the drain list head */ 293 mblk_t *conn_ipsec_opt_mp; /* ipsec option mblk */ 294 uint32_t conn_src_preferences; /* prefs for src addr select */ 295 /* mtuinfo from IPV6_PACKET_TOO_BIG conditional on conn_pathmtu_valid */ 296 struct ip6_mtuinfo mtuinfo; 297 zoneid_t conn_zoneid; /* zone connection is in */ 298 in6_addr_t conn_nexthop_v6; /* nexthop IP address */ 299 uchar_t conn_broadcast_ttl; /* IP_BROADCAST_TTL */ 300 #define conn_nexthop_v4 V4_PART_OF_V6(conn_nexthop_v6) 301 cred_t *conn_peercred; /* Peer credentials, if any */ 302 303 unsigned int 304 conn_ulp_labeled : 1, /* ULP label is synced */ 305 conn_mlp_type : 2, /* mlp_type_t; tsol/tndb.h */ 306 conn_anon_mlp : 1, /* user wants anon MLP */ 307 308 conn_anon_port : 1, /* user bound anonymously */ 309 conn_mac_exempt : 1, /* unlabeled with loose MAC */ 310 conn_spare : 26; 311 netstack_t *conn_netstack; /* Corresponds to a netstack_hold */ 312 #ifdef CONN_DEBUG 313 #define CONN_TRACE_MAX 10 314 int conn_trace_last; /* ndx of last used tracebuf */ 315 conn_trace_t conn_trace_buf[CONN_TRACE_MAX]; 316 #endif 317 }; 318 319 #define CONN_CRED(connp) ((connp)->conn_peercred == NULL ? \ 320 (connp)->conn_cred : (connp)->conn_peercred) 321 #define BEST_CRED(mp, connp) ((DB_CRED(mp) != NULL && \ 322 crgetlabel(DB_CRED(mp)) != NULL) ? DB_CRED(mp) : CONN_CRED(connp)) 323 324 /* 325 * connf_t - connection fanout data. 326 * 327 * The hash tables and their linkage (conn_t.{hashnextp, hashprevp} are 328 * protected by the per-bucket lock. Each conn_t inserted in the list 329 * points back at the connf_t that heads the bucket. 330 */ 331 struct connf_s { 332 struct conn_s *connf_head; 333 kmutex_t connf_lock; 334 }; 335 336 #define CONN_INC_REF(connp) { \ 337 mutex_enter(&(connp)->conn_lock); \ 338 DTRACE_PROBE1(conn__inc__ref, conn_t *, connp); \ 339 ASSERT(conn_trace_ref(connp)); \ 340 (connp)->conn_ref++; \ 341 ASSERT((connp)->conn_ref != 0); \ 342 mutex_exit(&(connp)->conn_lock); \ 343 } 344 345 #define CONN_INC_REF_LOCKED(connp) { \ 346 DTRACE_PROBE1(conn__inc__ref, conn_t *, connp); \ 347 ASSERT(MUTEX_HELD(&(connp)->conn_lock)); \ 348 ASSERT(conn_trace_ref(connp)); \ 349 (connp)->conn_ref++; \ 350 ASSERT((connp)->conn_ref != 0); \ 351 } 352 353 #define CONN_DEC_REF(connp) { \ 354 mutex_enter(&(connp)->conn_lock); \ 355 DTRACE_PROBE1(conn__dec__ref, conn_t *, connp); \ 356 /* \ 357 * The squeue framework always does a CONN_DEC_REF after return \ 358 * from TCP. Hence the refcnt must be at least 2 if conn_on_sqp \ 359 * is B_TRUE and conn_ref is being decremented. This is to \ 360 * account for the mblk being currently processed. \ 361 */ \ 362 if ((connp)->conn_ref <= 0 || \ 363 ((connp)->conn_ref == 1 && (connp)->conn_on_sqp)) \ 364 cmn_err(CE_PANIC, "CONN_DEC_REF: connp(%p) has ref " \ 365 "= %d\n", (void *)(connp), (connp)->conn_ref); \ 366 ASSERT(conn_untrace_ref(connp)); \ 367 (connp)->conn_ref--; \ 368 if ((connp)->conn_ref == 0) { \ 369 /* Refcnt can't increase again, safe to drop lock */ \ 370 mutex_exit(&(connp)->conn_lock); \ 371 ipcl_conn_destroy(connp); \ 372 } else { \ 373 cv_broadcast(&(connp)->conn_cv); \ 374 mutex_exit(&(connp)->conn_lock); \ 375 } \ 376 } 377 378 /* 379 * For use with subsystems within ip which use ALL_ZONES as a wildcard 380 */ 381 #define IPCL_ZONEID(connp) \ 382 ((connp)->conn_allzones ? ALL_ZONES : (connp)->conn_zoneid) 383 384 /* 385 * For matching between a conn_t and a zoneid. 386 */ 387 #define IPCL_ZONE_MATCH(connp, zoneid) \ 388 (((connp)->conn_allzones) || \ 389 ((zoneid) == ALL_ZONES) || \ 390 (connp)->conn_zoneid == (zoneid)) 391 392 393 #define _IPCL_V4_MATCH(v6addr, v4addr) \ 394 (V4_PART_OF_V6((v6addr)) == (v4addr) && IN6_IS_ADDR_V4MAPPED(&(v6addr))) 395 396 #define _IPCL_V4_MATCH_ANY(addr) \ 397 (IN6_IS_ADDR_V4MAPPED_ANY(&(addr)) || IN6_IS_ADDR_UNSPECIFIED(&(addr))) 398 399 400 /* 401 * IPCL_PROTO_MATCH() only matches conns with the specified zoneid, while 402 * IPCL_PROTO_MATCH_V6() can match other conns in the multicast case, see 403 * ip_fanout_proto(). 404 */ 405 #define IPCL_PROTO_MATCH(connp, protocol, ipha, ill, \ 406 fanout_flags, zoneid) \ 407 ((((connp)->conn_src == INADDR_ANY) || \ 408 (((connp)->conn_src == ((ipha)->ipha_dst)) && \ 409 (((connp)->conn_rem == INADDR_ANY) || \ 410 ((connp)->conn_rem == ((ipha)->ipha_src))))) && \ 411 IPCL_ZONE_MATCH(connp, zoneid) && \ 412 (conn_wantpacket((connp), (ill), (ipha), (fanout_flags), \ 413 (zoneid)) || ((protocol) == IPPROTO_PIM) || \ 414 ((protocol) == IPPROTO_RSVP))) 415 416 #define IPCL_PROTO_MATCH_V6(connp, protocol, ip6h, ill, \ 417 fanout_flags, zoneid) \ 418 ((IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_srcv6) || \ 419 (IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &((ip6h)->ip6_dst)) && \ 420 (IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_remv6) || \ 421 IN6_ARE_ADDR_EQUAL(&(connp)->conn_remv6, &((ip6h)->ip6_src))))) && \ 422 (conn_wantpacket_v6((connp), (ill), (ip6h), \ 423 (fanout_flags), (zoneid)) || ((protocol) == IPPROTO_RSVP))) 424 425 #define IPCL_CONN_HASH(src, ports, ipst) \ 426 ((unsigned)(ntohl((src)) ^ ((ports) >> 24) ^ ((ports) >> 16) ^ \ 427 ((ports) >> 8) ^ (ports)) % (ipst)->ips_ipcl_conn_fanout_size) 428 429 #define IPCL_CONN_HASH_V6(src, ports, ipst) \ 430 IPCL_CONN_HASH(V4_PART_OF_V6((src)), (ports), (ipst)) 431 432 #define IPCL_CONN_MATCH(connp, proto, src, dst, ports) \ 433 ((connp)->conn_ulp == (proto) && \ 434 (connp)->conn_ports == (ports) && \ 435 _IPCL_V4_MATCH((connp)->conn_remv6, (src)) && \ 436 _IPCL_V4_MATCH((connp)->conn_srcv6, (dst)) && \ 437 !(connp)->conn_ipv6_v6only) 438 439 #define IPCL_CONN_MATCH_V6(connp, proto, src, dst, ports) \ 440 ((connp)->conn_ulp == (proto) && \ 441 (connp)->conn_ports == (ports) && \ 442 IN6_ARE_ADDR_EQUAL(&(connp)->conn_remv6, &(src)) && \ 443 IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &(dst))) 444 445 #define IPCL_CONN_INIT(connp, protocol, src, rem, ports) { \ 446 (connp)->conn_ulp = protocol; \ 447 IN6_IPADDR_TO_V4MAPPED(src, &(connp)->conn_srcv6); \ 448 IN6_IPADDR_TO_V4MAPPED(rem, &(connp)->conn_remv6); \ 449 (connp)->conn_ports = ports; \ 450 } 451 452 #define IPCL_CONN_INIT_V6(connp, protocol, src, rem, ports) { \ 453 (connp)->conn_ulp = protocol; \ 454 (connp)->conn_srcv6 = src; \ 455 (connp)->conn_remv6 = rem; \ 456 (connp)->conn_ports = ports; \ 457 } 458 459 #define IPCL_PORT_HASH(port, size) \ 460 ((((port) >> 8) ^ (port)) & ((size) - 1)) 461 462 #define IPCL_BIND_HASH(lport, ipst) \ 463 ((unsigned)(((lport) >> 8) ^ (lport)) % \ 464 (ipst)->ips_ipcl_bind_fanout_size) 465 466 #define IPCL_BIND_MATCH(connp, proto, laddr, lport) \ 467 ((connp)->conn_ulp == (proto) && \ 468 (connp)->conn_lport == (lport) && \ 469 (_IPCL_V4_MATCH_ANY((connp)->conn_srcv6) || \ 470 _IPCL_V4_MATCH((connp)->conn_srcv6, (laddr))) && \ 471 !(connp)->conn_ipv6_v6only) 472 473 #define IPCL_BIND_MATCH_V6(connp, proto, laddr, lport) \ 474 ((connp)->conn_ulp == (proto) && \ 475 (connp)->conn_lport == (lport) && \ 476 (IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &(laddr)) || \ 477 IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_srcv6))) 478 479 #define IPCL_UDP_MATCH(connp, lport, laddr, fport, faddr) \ 480 (((connp)->conn_lport == (lport)) && \ 481 ((_IPCL_V4_MATCH_ANY((connp)->conn_srcv6) || \ 482 (_IPCL_V4_MATCH((connp)->conn_srcv6, (laddr)) && \ 483 (_IPCL_V4_MATCH_ANY((connp)->conn_remv6) || \ 484 (_IPCL_V4_MATCH((connp)->conn_remv6, (faddr)) && \ 485 (connp)->conn_fport == (fport)))))) && \ 486 !(connp)->conn_ipv6_v6only) 487 488 #define IPCL_UDP_MATCH_V6(connp, lport, laddr, fport, faddr) \ 489 (((connp)->conn_lport == (lport)) && \ 490 (IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_srcv6) || \ 491 (IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &(laddr)) && \ 492 (IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_remv6) || \ 493 (IN6_ARE_ADDR_EQUAL(&(connp)->conn_remv6, &(faddr)) && \ 494 (connp)->conn_fport == (fport)))))) 495 496 #define IPCL_TCP_EAGER_INIT(connp, protocol, src, rem, ports) { \ 497 (connp)->conn_flags |= (IPCL_TCP4|IPCL_EAGER); \ 498 IN6_IPADDR_TO_V4MAPPED(src, &(connp)->conn_srcv6); \ 499 IN6_IPADDR_TO_V4MAPPED(rem, &(connp)->conn_remv6); \ 500 (connp)->conn_ports = ports; \ 501 (connp)->conn_send = ip_output; \ 502 (connp)->conn_sqp = IP_SQUEUE_GET(lbolt); \ 503 (connp)->conn_initial_sqp = (connp)->conn_sqp; \ 504 } 505 506 #define IPCL_TCP_EAGER_INIT_V6(connp, protocol, src, rem, ports) { \ 507 (connp)->conn_flags |= (IPCL_TCP6|IPCL_EAGER|IPCL_ISV6); \ 508 (connp)->conn_srcv6 = src; \ 509 (connp)->conn_remv6 = rem; \ 510 (connp)->conn_ports = ports; \ 511 (connp)->conn_send = ip_output_v6; \ 512 (connp)->conn_sqp = IP_SQUEUE_GET(lbolt); \ 513 (connp)->conn_initial_sqp = (connp)->conn_sqp; \ 514 } 515 516 #define IPCL_UDP_HASH(lport, ipst) \ 517 IPCL_PORT_HASH(lport, (ipst)->ips_ipcl_udp_fanout_size) 518 519 #define CONN_G_HASH_SIZE 1024 520 521 /* Raw socket hash function. */ 522 #define IPCL_RAW_HASH(lport, ipst) \ 523 IPCL_PORT_HASH(lport, (ipst)->ips_ipcl_raw_fanout_size) 524 525 /* 526 * This is similar to IPCL_BIND_MATCH except that the local port check 527 * is changed to a wildcard port check. 528 */ 529 #define IPCL_RAW_MATCH(connp, proto, laddr) \ 530 ((connp)->conn_ulp == (proto) && \ 531 (connp)->conn_lport == 0 && \ 532 (_IPCL_V4_MATCH_ANY((connp)->conn_srcv6) || \ 533 _IPCL_V4_MATCH((connp)->conn_srcv6, (laddr)))) 534 535 #define IPCL_RAW_MATCH_V6(connp, proto, laddr) \ 536 ((connp)->conn_ulp == (proto) && \ 537 (connp)->conn_lport == 0 && \ 538 (IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_srcv6) || \ 539 IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &(laddr)))) 540 541 /* Function prototypes */ 542 extern void ipcl_g_init(void); 543 extern void ipcl_init(ip_stack_t *); 544 extern void ipcl_g_destroy(void); 545 extern void ipcl_destroy(ip_stack_t *); 546 extern conn_t *ipcl_conn_create(uint32_t, int, netstack_t *); 547 extern void ipcl_conn_destroy(conn_t *); 548 549 void ipcl_hash_insert_wildcard(connf_t *, conn_t *); 550 void ipcl_hash_remove(conn_t *); 551 void ipcl_hash_remove_locked(conn_t *connp, connf_t *connfp); 552 553 extern int ipcl_bind_insert(conn_t *, uint8_t, ipaddr_t, uint16_t); 554 extern int ipcl_bind_insert_v6(conn_t *, uint8_t, const in6_addr_t *, 555 uint16_t); 556 extern int ipcl_conn_insert(conn_t *, uint8_t, ipaddr_t, ipaddr_t, 557 uint32_t); 558 extern int ipcl_conn_insert_v6(conn_t *, uint8_t, const in6_addr_t *, 559 const in6_addr_t *, uint32_t, uint_t); 560 extern conn_t *ipcl_get_next_conn(connf_t *, conn_t *, uint32_t); 561 562 void ipcl_proto_insert(conn_t *, uint8_t); 563 void ipcl_proto_insert_v6(conn_t *, uint8_t); 564 conn_t *ipcl_classify_v4(mblk_t *, uint8_t, uint_t, zoneid_t, ip_stack_t *); 565 conn_t *ipcl_classify_v6(mblk_t *, uint8_t, uint_t, zoneid_t, ip_stack_t *); 566 conn_t *ipcl_classify(mblk_t *, zoneid_t, ip_stack_t *); 567 conn_t *ipcl_classify_raw(mblk_t *, uint8_t, zoneid_t, uint32_t, ipha_t *, 568 ip_stack_t *); 569 void ipcl_globalhash_insert(conn_t *); 570 void ipcl_globalhash_remove(conn_t *); 571 void ipcl_walk(pfv_t, void *, ip_stack_t *); 572 conn_t *ipcl_tcp_lookup_reversed_ipv4(ipha_t *, tcph_t *, int, ip_stack_t *); 573 conn_t *ipcl_tcp_lookup_reversed_ipv6(ip6_t *, tcpha_t *, int, uint_t, 574 ip_stack_t *); 575 conn_t *ipcl_lookup_listener_v4(uint16_t, ipaddr_t, zoneid_t, ip_stack_t *); 576 conn_t *ipcl_lookup_listener_v6(uint16_t, in6_addr_t *, uint_t, zoneid_t, 577 ip_stack_t *); 578 int conn_trace_ref(conn_t *); 579 int conn_untrace_ref(conn_t *); 580 void ipcl_conn_cleanup(conn_t *); 581 conn_t *ipcl_conn_tcp_lookup_reversed_ipv4(conn_t *, ipha_t *, tcph_t *, 582 ip_stack_t *); 583 conn_t *ipcl_conn_tcp_lookup_reversed_ipv6(conn_t *, ip6_t *, tcph_t *, 584 ip_stack_t *); 585 #ifdef __cplusplus 586 } 587 #endif 588 589 #endif /* _INET_IPCLASSIFIER_H */ 590