17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #ifndef _INET_IPCLASSIFIER_H 287c478bd9Sstevel@tonic-gate #define _INET_IPCLASSIFIER_H 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #ifdef __cplusplus 337c478bd9Sstevel@tonic-gate extern "C" { 347c478bd9Sstevel@tonic-gate #endif 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #include <inet/common.h> 377c478bd9Sstevel@tonic-gate #include <inet/ip.h> 387c478bd9Sstevel@tonic-gate #include <inet/mi.h> 397c478bd9Sstevel@tonic-gate #include <inet/tcp.h> 407c478bd9Sstevel@tonic-gate #include <inet/ip6.h> 417c478bd9Sstevel@tonic-gate #include <netinet/in.h> /* for IPPROTO_* constants */ 427c478bd9Sstevel@tonic-gate #include <sys/sdt.h> 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate typedef void (*edesc_spf)(void *, mblk_t *, void *, int); 457c478bd9Sstevel@tonic-gate typedef void (*edesc_rpf)(void *, mblk_t *, void *); 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate /* 487c478bd9Sstevel@tonic-gate * ============================== 497c478bd9Sstevel@tonic-gate * = The CONNECTION = 507c478bd9Sstevel@tonic-gate * ============================== 517c478bd9Sstevel@tonic-gate */ 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate /* 547c478bd9Sstevel@tonic-gate * The connection structure contains the common information/flags/ref needed. 557c478bd9Sstevel@tonic-gate * Implementation will keep the connection struct, the layers (with their 567c478bd9Sstevel@tonic-gate * respective data for event i.e. tcp_t if event was tcp_input) all in one 577c478bd9Sstevel@tonic-gate * contiguous memory location. 587c478bd9Sstevel@tonic-gate */ 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate /* Conn Flags */ 617c478bd9Sstevel@tonic-gate #define IPCL_BOUND 0x80000000 /* Conn in bind table */ 627c478bd9Sstevel@tonic-gate #define IPCL_CONNECTED 0x40000000 /* Conn in connected table */ 637c478bd9Sstevel@tonic-gate #define IPCL_TCP4 0x08000000 /* A TCP connection */ 647c478bd9Sstevel@tonic-gate #define IPCL_TCP6 0x04000000 /* A TCP6 connection */ 657c478bd9Sstevel@tonic-gate #define IPCL_EAGER 0x01000000 /* Incoming connection */ 667c478bd9Sstevel@tonic-gate #define IPCL_CL_LISTENER 0x00800000 /* Cluster listener */ 677c478bd9Sstevel@tonic-gate #define IPCL_ACCEPTOR 0x00400000 /* Sockfs priv acceptor */ 687c478bd9Sstevel@tonic-gate #define IPCL_SOCKET 0x00200000 /* Sockfs connection */ 697c478bd9Sstevel@tonic-gate #define IPCL_CHECK_POLICY 0x00100000 /* Needs policy checking */ 707c478bd9Sstevel@tonic-gate #define IPCL_FULLY_BOUND 0x00080000 /* Bound to correct squeue */ 717c478bd9Sstevel@tonic-gate #define IPCL_TCPMOD 0x00040000 /* Is tcp module instance */ 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate /* Flags identifying the type of conn */ 747c478bd9Sstevel@tonic-gate #define IPCL_TCPCONN 0x00000001 /* Flag to indicate cache */ 757c478bd9Sstevel@tonic-gate #define IPCL_SCTPCONN 0x00000002 767c478bd9Sstevel@tonic-gate #define IPCL_IPCCONN 0x00000004 777c478bd9Sstevel@tonic-gate #define IPCL_ISV6 0x00000008 /* Is a V6 connection */ 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate /* Conn Masks */ 807c478bd9Sstevel@tonic-gate #define IPCL_TCP (IPCL_TCP4|IPCL_TCP6) 817c478bd9Sstevel@tonic-gate #define IPCL_REMOVED 0x00000020 827c478bd9Sstevel@tonic-gate #define IPCL_REUSED 0x00000040 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate #define IS_TCP_CONN(connp) (((connp)->conn_flags & IPCL_TCP) != 0) 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate #define IPCL_IS_TCP4(connp) \ 877c478bd9Sstevel@tonic-gate (((connp)->conn_flags & IPCL_TCP4)) 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate #define IPCL_IS_TCP4_CONNECTED_NO_POLICY(connp) \ 907c478bd9Sstevel@tonic-gate (((connp)->conn_flags & \ 917c478bd9Sstevel@tonic-gate (IPCL_TCP4|IPCL_CONNECTED|IPCL_CHECK_POLICY|IPCL_TCP6)) \ 927c478bd9Sstevel@tonic-gate == (IPCL_TCP4|IPCL_CONNECTED)) 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate #define IPCL_IS_CONNECTED(connp) \ 957c478bd9Sstevel@tonic-gate ((connp)->conn_flags & IPCL_CONNECTED) 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate #define IPCL_IS_BOUND(connp) \ 987c478bd9Sstevel@tonic-gate ((connp)->conn_flags & IPCL_BOUND) 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate #define IPCL_IS_TCP4_BOUND(connp) \ 1017c478bd9Sstevel@tonic-gate (((connp)->conn_flags & \ 1027c478bd9Sstevel@tonic-gate (IPCL_TCP4|IPCL_BOUND|IPCL_TCP6)) == \ 1037c478bd9Sstevel@tonic-gate (IPCL_TCP4|IPCL_BOUND)) 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate #define IPCL_IS_FULLY_BOUND(connp) \ 1067c478bd9Sstevel@tonic-gate ((connp)->conn_flags & IPCL_FULLY_BOUND) 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate #define IPCL_IS_TCP(connp) \ 1097c478bd9Sstevel@tonic-gate ((connp)->conn_flags & (IPCL_TCP4|IPCL_TCP6)) 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate #define IPCL_IS_IPTUN(connp) \ 1127c478bd9Sstevel@tonic-gate ((connp)->conn_ulp == IPPROTO_ENCAP || \ 1137c478bd9Sstevel@tonic-gate (connp)->conn_ulp == IPPROTO_IPV6) 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate typedef struct connf_s connf_t; 1167c478bd9Sstevel@tonic-gate typedef struct 1177c478bd9Sstevel@tonic-gate { 1187c478bd9Sstevel@tonic-gate int ctb_depth; 1197c478bd9Sstevel@tonic-gate #define IP_STACK_DEPTH 15 1207c478bd9Sstevel@tonic-gate pc_t ctb_stack[IP_STACK_DEPTH]; 1217c478bd9Sstevel@tonic-gate } conn_trace_t; 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate struct conn_s { 1247c478bd9Sstevel@tonic-gate kmutex_t conn_lock; 1257c478bd9Sstevel@tonic-gate uint32_t conn_ref; /* Reference counter */ 1267c478bd9Sstevel@tonic-gate uint_t conn_state_flags; /* IP state flags */ 1277c478bd9Sstevel@tonic-gate ire_t *conn_ire_cache; /* outbound ire cache */ 1287c478bd9Sstevel@tonic-gate uint32_t conn_flags; /* Conn Flags */ 1297c478bd9Sstevel@tonic-gate unsigned int 1307c478bd9Sstevel@tonic-gate conn_on_sqp : 1, /* Conn is being processed */ 1317c478bd9Sstevel@tonic-gate conn_dontroute : 1, /* SO_DONTROUTE state */ 1327c478bd9Sstevel@tonic-gate conn_loopback : 1, /* SO_LOOPBACK state */ 1337c478bd9Sstevel@tonic-gate conn_broadcast : 1, /* SO_BROADCAST state */ 1347c478bd9Sstevel@tonic-gate conn_reuseaddr : 1, /* SO_REUSEADDR state */ 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate conn_multicast_loop : 1, /* IP_MULTICAST_LOOP */ 1377c478bd9Sstevel@tonic-gate conn_multi_router : 1, /* Wants all multicast pkts */ 1387c478bd9Sstevel@tonic-gate conn_draining : 1, /* ip_wsrv running */ 1397c478bd9Sstevel@tonic-gate conn_did_putbq : 1, /* ip_wput did a putbq */ 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate conn_unspec_src : 1, /* IP_UNSPEC_SRC */ 1427c478bd9Sstevel@tonic-gate conn_policy_cached : 1, /* Is policy cached/latched ? */ 1437c478bd9Sstevel@tonic-gate conn_in_enforce_policy : 1, /* Enforce Policy on inbound */ 1447c478bd9Sstevel@tonic-gate conn_out_enforce_policy : 1, /* Enforce Policy on outbound */ 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate conn_af_isv6 : 1, /* ip address family ver 6 */ 1477c478bd9Sstevel@tonic-gate conn_pkt_isv6 : 1, /* ip packet format ver 6 */ 1487c478bd9Sstevel@tonic-gate conn_ipv6_recvpktinfo : 1, /* IPV6_RECVPKTINFO option */ 1497c478bd9Sstevel@tonic-gate conn_ipv6_recvhoplimit : 1, /* IPV6_RECVHOPLIMIT option */ 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate conn_ipv6_recvhopopts : 1, /* IPV6_RECVHOPOPTS option */ 1527c478bd9Sstevel@tonic-gate conn_ipv6_recvdstopts : 1, /* IPV6_RECVDSTOPTS option */ 1537c478bd9Sstevel@tonic-gate conn_ipv6_recvrthdr : 1, /* IPV6_RECVRTHDR option */ 1547c478bd9Sstevel@tonic-gate conn_ipv6_recvrtdstopts : 1, /* IPV6_RECVRTHDRDSTOPTS */ 1557c478bd9Sstevel@tonic-gate conn_ipv6_v6only : 1, /* IPV6_V6ONLY */ 1567c478bd9Sstevel@tonic-gate conn_ipv6_recvtclass : 1, /* IPV6_RECVTCLASS */ 1577c478bd9Sstevel@tonic-gate conn_ipv6_recvpathmtu : 1, /* IPV6_RECVPATHMTU */ 1587c478bd9Sstevel@tonic-gate conn_pathmtu_valid : 1, /* The cached mtu is valid. */ 1597c478bd9Sstevel@tonic-gate conn_ipv6_dontfrag : 1, /* IPV6_DONTFRAG */ 1607c478bd9Sstevel@tonic-gate /* 1617c478bd9Sstevel@tonic-gate * This option can take on values in [-1, 1] so we store it 1627c478bd9Sstevel@tonic-gate * +1. Manifest constants IPV6_USE_MIN_MTU_* describe these 1637c478bd9Sstevel@tonic-gate * values. 1647c478bd9Sstevel@tonic-gate */ 1657c478bd9Sstevel@tonic-gate conn_fully_bound : 1, /* Fully bound connection */ 1667c478bd9Sstevel@tonic-gate conn_recvif : 1, /* IP_RECVIF option */ 1677c478bd9Sstevel@tonic-gate conn_recvslla : 1, /* IP_RECVSLLA option */ 1687c478bd9Sstevel@tonic-gate conn_mdt_ok : 1, /* MDT is permitted */ 1697c478bd9Sstevel@tonic-gate pad_to_bit_31 : 2; 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate tcp_t *conn_tcp; /* Pointer to the tcp struct */ 1727c478bd9Sstevel@tonic-gate squeue_t *conn_sqp; /* Squeue for processing */ 1737c478bd9Sstevel@tonic-gate edesc_rpf conn_recv; /* Pointer to recv routine */ 1747c478bd9Sstevel@tonic-gate void *conn_pad1; 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate ill_t *conn_xmit_if_ill; /* Outbound ill */ 1777c478bd9Sstevel@tonic-gate ill_t *conn_nofailover_ill; /* Failover ill */ 1787c478bd9Sstevel@tonic-gate ipsec_latch_t *conn_latch; /* latched state */ 1797c478bd9Sstevel@tonic-gate ill_t *conn_outgoing_ill; /* IP{,V6}_BOUND_IF */ 1807c478bd9Sstevel@tonic-gate edesc_spf conn_send; /* Pointer to send routine */ 1817c478bd9Sstevel@tonic-gate queue_t *conn_rq; /* Read queue */ 1827c478bd9Sstevel@tonic-gate queue_t *conn_wq; /* Write queue */ 1837c478bd9Sstevel@tonic-gate dev_t conn_dev; /* Minor number */ 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate cred_t *conn_cred; /* Credentials */ 1867c478bd9Sstevel@tonic-gate connf_t *conn_g_fanout; /* Global Hash bucket head */ 1877c478bd9Sstevel@tonic-gate struct conn_s *conn_g_next; /* Global Hash chain next */ 1887c478bd9Sstevel@tonic-gate struct conn_s *conn_g_prev; /* Global Hash chain prev */ 1897c478bd9Sstevel@tonic-gate struct ipsec_policy_head_s *conn_policy; /* Configured policy */ 1907c478bd9Sstevel@tonic-gate in6_addr_t conn_bound_source_v6; 1917c478bd9Sstevel@tonic-gate #define conn_bound_source V4_PART_OF_V6(conn_bound_source_v6) 1927c478bd9Sstevel@tonic-gate void *conn_void[1]; 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate connf_t *conn_fanout; /* Hash bucket we're part of */ 1957c478bd9Sstevel@tonic-gate struct conn_s *conn_next; /* Hash chain next */ 1967c478bd9Sstevel@tonic-gate struct conn_s *conn_prev; /* Hash chain prev */ 1977c478bd9Sstevel@tonic-gate struct { 1987c478bd9Sstevel@tonic-gate in6_addr_t connua_laddr; /* Local address */ 1997c478bd9Sstevel@tonic-gate in6_addr_t connua_faddr; /* Remote address */ 2007c478bd9Sstevel@tonic-gate } connua_v6addr; 2017c478bd9Sstevel@tonic-gate #define conn_src V4_PART_OF_V6(connua_v6addr.connua_laddr) 2027c478bd9Sstevel@tonic-gate #define conn_rem V4_PART_OF_V6(connua_v6addr.connua_faddr) 2037c478bd9Sstevel@tonic-gate #define conn_srcv6 connua_v6addr.connua_laddr 2047c478bd9Sstevel@tonic-gate #define conn_remv6 connua_v6addr.connua_faddr 2057c478bd9Sstevel@tonic-gate union { 2067c478bd9Sstevel@tonic-gate /* Used for classifier match performance */ 2077c478bd9Sstevel@tonic-gate uint32_t conn_ports2; 2087c478bd9Sstevel@tonic-gate struct { 2097c478bd9Sstevel@tonic-gate in_port_t tcpu_fport; /* Remote port */ 2107c478bd9Sstevel@tonic-gate in_port_t tcpu_lport; /* Local port */ 2117c478bd9Sstevel@tonic-gate } tcpu_ports; 2127c478bd9Sstevel@tonic-gate } u_port; 2137c478bd9Sstevel@tonic-gate #define conn_fport u_port.tcpu_ports.tcpu_fport 2147c478bd9Sstevel@tonic-gate #define conn_lport u_port.tcpu_ports.tcpu_lport 2157c478bd9Sstevel@tonic-gate #define conn_ports u_port.conn_ports2 2167c478bd9Sstevel@tonic-gate #define conn_upq conn_rq 2177c478bd9Sstevel@tonic-gate uint8_t conn_ulp; /* protocol type */ 2187c478bd9Sstevel@tonic-gate uint8_t conn_unused_byte; 2197c478bd9Sstevel@tonic-gate kcondvar_t conn_cv; 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate uint_t conn_proto; /* SO_PROTOTYPE state */ 2227c478bd9Sstevel@tonic-gate ill_t *conn_incoming_ill; /* IP{,V6}_BOUND_IF */ 2237c478bd9Sstevel@tonic-gate ill_t *conn_outgoing_pill; /* IP{,V6}_BOUND_PIF */ 2247c478bd9Sstevel@tonic-gate ill_t *conn_oper_pending_ill; /* pending shared ioctl */ 2257c478bd9Sstevel@tonic-gate ill_t *conn_xioctl_pending_ill; /* pending excl ioctl */ 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate /* this is used only when an unbind is in progress.. */ 2287c478bd9Sstevel@tonic-gate struct sq_s *conn_pending_sq; /* waiting for ioctl on sq */ 2297c478bd9Sstevel@tonic-gate ilg_t *conn_ilg; /* Group memberships */ 2307c478bd9Sstevel@tonic-gate int conn_ilg_allocated; /* Number allocated */ 2317c478bd9Sstevel@tonic-gate int conn_ilg_inuse; /* Number currently used */ 2327c478bd9Sstevel@tonic-gate int conn_ilg_walker_cnt; /* No of ilg walkers */ 2337c478bd9Sstevel@tonic-gate /* XXXX get rid of this, once ilg_delete_all is fixed */ 2347c478bd9Sstevel@tonic-gate kcondvar_t conn_refcv; 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate struct ipif_s *conn_multicast_ipif; /* IP_MULTICAST_IF */ 2377c478bd9Sstevel@tonic-gate ill_t *conn_multicast_ill; /* IPV6_MULTICAST_IF */ 2387c478bd9Sstevel@tonic-gate int conn_orig_bound_ifindex; /* BOUND_IF before MOVE */ 2397c478bd9Sstevel@tonic-gate int conn_orig_multicast_ifindex; 2407c478bd9Sstevel@tonic-gate /* IPv6 MC IF before MOVE */ 2417c478bd9Sstevel@tonic-gate int conn_orig_xmit_ifindex; /* IP_XMIT_IF before move */ 2427c478bd9Sstevel@tonic-gate struct conn_s *conn_drain_next; /* Next conn in drain list */ 2437c478bd9Sstevel@tonic-gate struct conn_s *conn_drain_prev; /* Prev conn in drain list */ 2447c478bd9Sstevel@tonic-gate idl_t *conn_idl; /* Ptr to the drain list head */ 2457c478bd9Sstevel@tonic-gate mblk_t *conn_ipsec_opt_mp; /* ipsec option mblk */ 2467c478bd9Sstevel@tonic-gate uint32_t conn_src_preferences; /* prefs for src addr select */ 2477c478bd9Sstevel@tonic-gate /* mtuinfo from IPV6_PACKET_TOO_BIG conditional on conn_pathmtu_valid */ 2487c478bd9Sstevel@tonic-gate struct ip6_mtuinfo mtuinfo; 2497c478bd9Sstevel@tonic-gate zoneid_t conn_zoneid; /* zone connection is in */ 2507c478bd9Sstevel@tonic-gate #ifdef CONN_DEBUG 2517c478bd9Sstevel@tonic-gate #define CONN_TRACE_MAX 10 2527c478bd9Sstevel@tonic-gate int conn_trace_last; /* ndx of last used tracebuf */ 2537c478bd9Sstevel@tonic-gate conn_trace_t conn_trace_buf[CONN_TRACE_MAX]; 2547c478bd9Sstevel@tonic-gate #endif 2557c478bd9Sstevel@tonic-gate }; 2567c478bd9Sstevel@tonic-gate 2577c478bd9Sstevel@tonic-gate /* 2587c478bd9Sstevel@tonic-gate * connf_t - connection fanout data. 2597c478bd9Sstevel@tonic-gate * 2607c478bd9Sstevel@tonic-gate * The hash tables and their linkage (conn_t.{hashnextp, hashprevp} are 2617c478bd9Sstevel@tonic-gate * protected by the per-bucket lock. Each conn_t inserted in the list 2627c478bd9Sstevel@tonic-gate * points back at the connf_t that heads the bucket. 2637c478bd9Sstevel@tonic-gate */ 2647c478bd9Sstevel@tonic-gate 2657c478bd9Sstevel@tonic-gate struct connf_s { 2667c478bd9Sstevel@tonic-gate struct conn_s *connf_head; 2677c478bd9Sstevel@tonic-gate kmutex_t connf_lock; 2687c478bd9Sstevel@tonic-gate }; 2697c478bd9Sstevel@tonic-gate 2707c478bd9Sstevel@tonic-gate #define CONN_INC_REF(connp) { \ 2717c478bd9Sstevel@tonic-gate DTRACE_PROBE1(conn__inc__ref, conn_t *, connp); \ 2727c478bd9Sstevel@tonic-gate mutex_enter(&(connp)->conn_lock); \ 2737c478bd9Sstevel@tonic-gate ASSERT(conn_trace_ref(connp)); \ 2747c478bd9Sstevel@tonic-gate (connp)->conn_ref++; \ 2757c478bd9Sstevel@tonic-gate ASSERT((connp)->conn_ref != 0); \ 2767c478bd9Sstevel@tonic-gate mutex_exit(&(connp)->conn_lock); \ 2777c478bd9Sstevel@tonic-gate } 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate #define CONN_INC_REF_LOCKED(connp) { \ 2807c478bd9Sstevel@tonic-gate DTRACE_PROBE1(conn__inc__ref, conn_t *, connp); \ 2817c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&(connp)->conn_lock)); \ 2827c478bd9Sstevel@tonic-gate ASSERT(conn_trace_ref(connp)); \ 2837c478bd9Sstevel@tonic-gate (connp)->conn_ref++; \ 2847c478bd9Sstevel@tonic-gate ASSERT((connp)->conn_ref != 0); \ 2857c478bd9Sstevel@tonic-gate } 2867c478bd9Sstevel@tonic-gate 2877c478bd9Sstevel@tonic-gate #define CONN_DEC_REF(connp) { \ 2887c478bd9Sstevel@tonic-gate DTRACE_PROBE1(conn__dec__ref, conn_t *, connp); \ 2897c478bd9Sstevel@tonic-gate mutex_enter(&(connp)->conn_lock); \ 2907c478bd9Sstevel@tonic-gate if ((connp)->conn_ref <= 0) \ 2917c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "CONN_DEC_REF: connp(%p) has ref " \ 2927c478bd9Sstevel@tonic-gate "= %d\n", (void *)(connp), (connp)->conn_ref); \ 2937c478bd9Sstevel@tonic-gate ASSERT(conn_untrace_ref(connp)); \ 2947c478bd9Sstevel@tonic-gate (connp)->conn_ref--; \ 2957c478bd9Sstevel@tonic-gate if ((connp)->conn_ref == 0) { \ 2967c478bd9Sstevel@tonic-gate /* Refcnt can't increase again, safe to drop lock */ \ 2977c478bd9Sstevel@tonic-gate mutex_exit(&(connp)->conn_lock); \ 2987c478bd9Sstevel@tonic-gate ipcl_conn_destroy(connp); \ 2997c478bd9Sstevel@tonic-gate } else { \ 3007c478bd9Sstevel@tonic-gate cv_broadcast(&(connp)->conn_cv); \ 3017c478bd9Sstevel@tonic-gate mutex_exit(&(connp)->conn_lock); \ 3027c478bd9Sstevel@tonic-gate } \ 3037c478bd9Sstevel@tonic-gate } 3047c478bd9Sstevel@tonic-gate 3057c478bd9Sstevel@tonic-gate #define _IPCL_V4_MATCH(v6addr, v4addr) \ 3067c478bd9Sstevel@tonic-gate (V4_PART_OF_V6((v6addr)) == (v4addr) && IN6_IS_ADDR_V4MAPPED(&(v6addr))) 3077c478bd9Sstevel@tonic-gate 3087c478bd9Sstevel@tonic-gate #define _IPCL_V4_MATCH_ANY(addr) \ 3097c478bd9Sstevel@tonic-gate (IN6_IS_ADDR_V4MAPPED_ANY(&(addr)) || IN6_IS_ADDR_UNSPECIFIED(&(addr))) 3107c478bd9Sstevel@tonic-gate 3117c478bd9Sstevel@tonic-gate /* 3127c478bd9Sstevel@tonic-gate * IPCL_PROTO_MATCH() only matches conns with the specified zoneid, while 3137c478bd9Sstevel@tonic-gate * IPCL_PROTO_MATCH_V6() can match other conns in the multicast case, see 3147c478bd9Sstevel@tonic-gate * ip_fanout_proto(). 3157c478bd9Sstevel@tonic-gate */ 3167c478bd9Sstevel@tonic-gate #define IPCL_PROTO_MATCH(connp, protocol, ipha, ill, \ 3177c478bd9Sstevel@tonic-gate fanout_flags, zoneid) \ 3187c478bd9Sstevel@tonic-gate ((((connp)->conn_src == INADDR_ANY) || \ 3197c478bd9Sstevel@tonic-gate (((connp)->conn_src == ((ipha)->ipha_dst)) && \ 3207c478bd9Sstevel@tonic-gate (((connp)->conn_rem == INADDR_ANY) || \ 3217c478bd9Sstevel@tonic-gate ((connp)->conn_rem == ((ipha)->ipha_src))))) && \ 3227c478bd9Sstevel@tonic-gate ((connp)->conn_zoneid == (zoneid)) && \ 3237c478bd9Sstevel@tonic-gate (conn_wantpacket((connp), (ill), (ipha), \ 3247c478bd9Sstevel@tonic-gate (fanout_flags), (zoneid)) || ((protocol) == IPPROTO_PIM) || \ 3257c478bd9Sstevel@tonic-gate ((protocol) == IPPROTO_RSVP))) 3267c478bd9Sstevel@tonic-gate 3277c478bd9Sstevel@tonic-gate #define IPCL_PROTO_MATCH_V6(connp, protocol, ip6h, ill, \ 3287c478bd9Sstevel@tonic-gate fanout_flags, zoneid) \ 3297c478bd9Sstevel@tonic-gate ((IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_srcv6) || \ 3307c478bd9Sstevel@tonic-gate (IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &((ip6h)->ip6_dst)) && \ 3317c478bd9Sstevel@tonic-gate (IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_remv6) || \ 3327c478bd9Sstevel@tonic-gate IN6_ARE_ADDR_EQUAL(&(connp)->conn_remv6, &((ip6h)->ip6_src))))) && \ 3337c478bd9Sstevel@tonic-gate (conn_wantpacket_v6((connp), (ill), (ip6h), \ 3347c478bd9Sstevel@tonic-gate (fanout_flags), (zoneid)) || ((protocol) == IPPROTO_RSVP))) 3357c478bd9Sstevel@tonic-gate 3367c478bd9Sstevel@tonic-gate #define IPCL_CONN_HASH(src, ports) \ 3377c478bd9Sstevel@tonic-gate ((unsigned)(ntohl((src)) ^ ((ports) >> 24) ^ ((ports) >> 16) ^ \ 3387c478bd9Sstevel@tonic-gate ((ports) >> 8) ^ (ports)) % ipcl_conn_fanout_size) 3397c478bd9Sstevel@tonic-gate 3407c478bd9Sstevel@tonic-gate #define IPCL_CONN_HASH_V6(src, ports) \ 3417c478bd9Sstevel@tonic-gate IPCL_CONN_HASH(V4_PART_OF_V6((src)), (ports)) 3427c478bd9Sstevel@tonic-gate 3437c478bd9Sstevel@tonic-gate #define IPCL_CONN_MATCH(connp, proto, src, dst, ports) \ 3447c478bd9Sstevel@tonic-gate ((connp)->conn_ulp == (proto) && \ 3457c478bd9Sstevel@tonic-gate (connp)->conn_ports == (ports) && \ 3467c478bd9Sstevel@tonic-gate _IPCL_V4_MATCH((connp)->conn_remv6, (src)) && \ 3477c478bd9Sstevel@tonic-gate _IPCL_V4_MATCH((connp)->conn_srcv6, (dst)) && \ 3487c478bd9Sstevel@tonic-gate !(connp)->conn_ipv6_v6only) 3497c478bd9Sstevel@tonic-gate 3507c478bd9Sstevel@tonic-gate #define IPCL_CONN_MATCH_V6(connp, proto, src, dst, ports) \ 3517c478bd9Sstevel@tonic-gate ((connp)->conn_ulp == (proto) && \ 3527c478bd9Sstevel@tonic-gate (connp)->conn_ports == (ports) && \ 3537c478bd9Sstevel@tonic-gate IN6_ARE_ADDR_EQUAL(&(connp)->conn_remv6, &(src)) && \ 3547c478bd9Sstevel@tonic-gate IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &(dst))) 3557c478bd9Sstevel@tonic-gate 3567c478bd9Sstevel@tonic-gate #define IPCL_CONN_INIT(connp, protocol, src, rem, ports) { \ 3577c478bd9Sstevel@tonic-gate (connp)->conn_ulp = protocol; \ 3587c478bd9Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(src, &(connp)->conn_srcv6); \ 3597c478bd9Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(rem, &(connp)->conn_remv6); \ 3607c478bd9Sstevel@tonic-gate (connp)->conn_ports = ports; \ 3617c478bd9Sstevel@tonic-gate } 3627c478bd9Sstevel@tonic-gate 3637c478bd9Sstevel@tonic-gate #define IPCL_CONN_INIT_V6(connp, protocol, src, rem, ports) { \ 3647c478bd9Sstevel@tonic-gate (connp)->conn_ulp = protocol; \ 3657c478bd9Sstevel@tonic-gate (connp)->conn_srcv6 = src; \ 3667c478bd9Sstevel@tonic-gate (connp)->conn_remv6 = rem; \ 3677c478bd9Sstevel@tonic-gate (connp)->conn_ports = ports; \ 3687c478bd9Sstevel@tonic-gate } 3697c478bd9Sstevel@tonic-gate 3707c478bd9Sstevel@tonic-gate #define IPCL_BIND_HASH(lport) \ 3717c478bd9Sstevel@tonic-gate ((unsigned)(((lport) >> 8) ^ (lport)) % ipcl_bind_fanout_size) 3727c478bd9Sstevel@tonic-gate 3737c478bd9Sstevel@tonic-gate #define IPCL_BIND_MATCH(connp, proto, laddr, lport) \ 3747c478bd9Sstevel@tonic-gate ((connp)->conn_ulp == (proto) && \ 3757c478bd9Sstevel@tonic-gate (connp)->conn_lport == (lport) && \ 3767c478bd9Sstevel@tonic-gate (_IPCL_V4_MATCH_ANY((connp)->conn_srcv6) || \ 3777c478bd9Sstevel@tonic-gate _IPCL_V4_MATCH((connp)->conn_srcv6, (laddr))) && \ 3787c478bd9Sstevel@tonic-gate !(connp)->conn_ipv6_v6only) 3797c478bd9Sstevel@tonic-gate 3807c478bd9Sstevel@tonic-gate #define IPCL_BIND_MATCH_V6(connp, proto, laddr, lport) \ 3817c478bd9Sstevel@tonic-gate ((connp)->conn_ulp == (proto) && \ 3827c478bd9Sstevel@tonic-gate (connp)->conn_lport == (lport) && \ 3837c478bd9Sstevel@tonic-gate (IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &(laddr)) || \ 3847c478bd9Sstevel@tonic-gate IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_srcv6))) 3857c478bd9Sstevel@tonic-gate 3867c478bd9Sstevel@tonic-gate #define IPCL_UDP_MATCH(connp, lport, laddr, fport, faddr) \ 3877c478bd9Sstevel@tonic-gate (((connp)->conn_lport == (lport)) && \ 3887c478bd9Sstevel@tonic-gate ((_IPCL_V4_MATCH_ANY((connp)->conn_srcv6) || \ 3897c478bd9Sstevel@tonic-gate (_IPCL_V4_MATCH((connp)->conn_srcv6, (laddr)) && \ 3907c478bd9Sstevel@tonic-gate (_IPCL_V4_MATCH_ANY((connp)->conn_remv6) || \ 3917c478bd9Sstevel@tonic-gate (_IPCL_V4_MATCH((connp)->conn_remv6, (faddr)) && \ 3927c478bd9Sstevel@tonic-gate (connp)->conn_fport == (fport)))))) && \ 3937c478bd9Sstevel@tonic-gate !(connp)->conn_ipv6_v6only) 3947c478bd9Sstevel@tonic-gate 3957c478bd9Sstevel@tonic-gate #define IPCL_UDP_MATCH_V6(connp, lport, laddr, fport, faddr) \ 3967c478bd9Sstevel@tonic-gate (((connp)->conn_lport == (lport)) && \ 3977c478bd9Sstevel@tonic-gate (IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_srcv6) || \ 3987c478bd9Sstevel@tonic-gate (IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &(laddr)) && \ 3997c478bd9Sstevel@tonic-gate (IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_remv6) || \ 4007c478bd9Sstevel@tonic-gate (IN6_ARE_ADDR_EQUAL(&(connp)->conn_remv6, &(faddr)) && \ 4017c478bd9Sstevel@tonic-gate (connp)->conn_fport == (fport)))))) 4027c478bd9Sstevel@tonic-gate 4037c478bd9Sstevel@tonic-gate #define IPCL_TCP_EAGER_INIT(connp, protocol, src, rem, ports) { \ 4047c478bd9Sstevel@tonic-gate (connp)->conn_flags |= (IPCL_TCP4|IPCL_EAGER); \ 4057c478bd9Sstevel@tonic-gate (connp)->conn_ulp = protocol; \ 4067c478bd9Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(src, &(connp)->conn_srcv6); \ 4077c478bd9Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(rem, &(connp)->conn_remv6); \ 4087c478bd9Sstevel@tonic-gate (connp)->conn_ports = ports; \ 4097c478bd9Sstevel@tonic-gate (connp)->conn_send = ip_output; \ 4107c478bd9Sstevel@tonic-gate (connp)->conn_sqp = IP_SQUEUE_GET(lbolt); \ 4117c478bd9Sstevel@tonic-gate } 4127c478bd9Sstevel@tonic-gate 4137c478bd9Sstevel@tonic-gate #define IPCL_TCP_EAGER_INIT_V6(connp, protocol, src, rem, ports) { \ 4147c478bd9Sstevel@tonic-gate (connp)->conn_flags |= (IPCL_TCP6|IPCL_EAGER); \ 4157c478bd9Sstevel@tonic-gate (connp)->conn_ulp = protocol; \ 4167c478bd9Sstevel@tonic-gate (connp)->conn_srcv6 = src; \ 4177c478bd9Sstevel@tonic-gate (connp)->conn_remv6 = rem; \ 4187c478bd9Sstevel@tonic-gate (connp)->conn_ports = ports; \ 4197c478bd9Sstevel@tonic-gate (connp)->conn_send = ip_output_v6; \ 4207c478bd9Sstevel@tonic-gate (connp)->conn_sqp = IP_SQUEUE_GET(lbolt); \ 4217c478bd9Sstevel@tonic-gate } 4227c478bd9Sstevel@tonic-gate 4237c478bd9Sstevel@tonic-gate #define ipcl_proto_search(protocol) \ 4247c478bd9Sstevel@tonic-gate (ipcl_proto_fanout[(protocol)].connf_head) 4257c478bd9Sstevel@tonic-gate 4267c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN 4277c478bd9Sstevel@tonic-gate #define IPCL_UDP_HASH(port) ((port) & 0xFF) 4287c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */ 4297c478bd9Sstevel@tonic-gate #define IPCL_UDP_HASH(port) (((uint16_t)(port)) >> 8) 4307c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */ 4317c478bd9Sstevel@tonic-gate 4327c478bd9Sstevel@tonic-gate #define CONN_G_HASH_SIZE 1024 4337c478bd9Sstevel@tonic-gate 4347c478bd9Sstevel@tonic-gate /* Raw socket hash function. */ 4357c478bd9Sstevel@tonic-gate #define IPCL_RAW_HASH(lport) (((lport) * 31) & (ipcl_raw_fanout_size - 1)) 4367c478bd9Sstevel@tonic-gate 437*7c0c0508Skcpoon /* 438*7c0c0508Skcpoon * This is similar to IPCL_BIND_MATCH except that the local port check 439*7c0c0508Skcpoon * is changed to a wildcard port check. 440*7c0c0508Skcpoon */ 441*7c0c0508Skcpoon #define IPCL_RAW_MATCH(connp, proto, laddr) \ 442*7c0c0508Skcpoon ((connp)->conn_ulp == (proto) && \ 443*7c0c0508Skcpoon (connp)->conn_lport == 0 && \ 444*7c0c0508Skcpoon (_IPCL_V4_MATCH_ANY((connp)->conn_srcv6) || \ 445*7c0c0508Skcpoon _IPCL_V4_MATCH((connp)->conn_srcv6, (laddr)))) 446*7c0c0508Skcpoon 447*7c0c0508Skcpoon #define IPCL_RAW_MATCH_V6(connp, proto, laddr) \ 448*7c0c0508Skcpoon ((connp)->conn_ulp == (proto) && \ 449*7c0c0508Skcpoon (connp)->conn_lport == 0 && \ 450*7c0c0508Skcpoon (IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_srcv6) || \ 451*7c0c0508Skcpoon IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &(laddr)))) 452*7c0c0508Skcpoon 4537c478bd9Sstevel@tonic-gate /* hash tables */ 4547c478bd9Sstevel@tonic-gate extern connf_t rts_clients; 4557c478bd9Sstevel@tonic-gate extern connf_t *ipcl_conn_fanout; 4567c478bd9Sstevel@tonic-gate extern connf_t *ipcl_bind_fanout; 4577c478bd9Sstevel@tonic-gate extern connf_t ipcl_proto_fanout[IPPROTO_MAX + 1]; 4587c478bd9Sstevel@tonic-gate extern connf_t ipcl_proto_fanout_v6[IPPROTO_MAX + 1]; 4597c478bd9Sstevel@tonic-gate extern connf_t *ipcl_udp_fanout; 4607c478bd9Sstevel@tonic-gate extern connf_t *ipcl_globalhash_fanout; 4617c478bd9Sstevel@tonic-gate extern connf_t *ipcl_raw_fanout; 4627c478bd9Sstevel@tonic-gate extern uint_t ipcl_conn_fanout_size; 4637c478bd9Sstevel@tonic-gate extern uint_t ipcl_bind_fanout_size; 4647c478bd9Sstevel@tonic-gate extern uint_t ipcl_udp_fanout_size; 4657c478bd9Sstevel@tonic-gate extern uint_t ipcl_raw_fanout_size; 4667c478bd9Sstevel@tonic-gate 4677c478bd9Sstevel@tonic-gate /* Function prototypes */ 4687c478bd9Sstevel@tonic-gate extern void ipcl_init(void); 4697c478bd9Sstevel@tonic-gate extern void ipcl_destroy(void); 4707c478bd9Sstevel@tonic-gate extern conn_t *ipcl_conn_create(uint32_t, int); 4717c478bd9Sstevel@tonic-gate extern void ipcl_conn_destroy(conn_t *); 4727c478bd9Sstevel@tonic-gate 4737c478bd9Sstevel@tonic-gate void ipcl_hash_insert_connected(connf_t *, conn_t *); 4747c478bd9Sstevel@tonic-gate void ipcl_hash_insert_bound(connf_t *, conn_t *); 4757c478bd9Sstevel@tonic-gate void ipcl_hash_insert_wildcard(connf_t *, conn_t *); 4767c478bd9Sstevel@tonic-gate void ipcl_hash_remove(conn_t *); 4777c478bd9Sstevel@tonic-gate void ipcl_hash_remove_locked(conn_t *connp, connf_t *connfp); 4787c478bd9Sstevel@tonic-gate 4797c478bd9Sstevel@tonic-gate extern int ipcl_bind_insert(conn_t *, uint8_t, ipaddr_t, uint16_t); 4807c478bd9Sstevel@tonic-gate extern int ipcl_bind_insert_v6(conn_t *, uint8_t, const in6_addr_t *, 4817c478bd9Sstevel@tonic-gate uint16_t); 4827c478bd9Sstevel@tonic-gate extern int ipcl_conn_insert(conn_t *, uint8_t, ipaddr_t, ipaddr_t, 4837c478bd9Sstevel@tonic-gate uint32_t); 4847c478bd9Sstevel@tonic-gate extern int ipcl_conn_insert_v6(conn_t *, uint8_t, const in6_addr_t *, 4857c478bd9Sstevel@tonic-gate const in6_addr_t *, uint32_t, uint_t); 4867c478bd9Sstevel@tonic-gate 4877c478bd9Sstevel@tonic-gate void ipcl_proto_insert(conn_t *, uint8_t); 4887c478bd9Sstevel@tonic-gate void ipcl_proto_insert_v6(conn_t *, uint8_t); 4897c478bd9Sstevel@tonic-gate conn_t *ipcl_classify_v4(mblk_t *, uint8_t, uint_t, zoneid_t); 4907c478bd9Sstevel@tonic-gate conn_t *ipcl_classify_v6(mblk_t *, uint8_t, uint_t, zoneid_t); 4917c478bd9Sstevel@tonic-gate conn_t *ipcl_classify(mblk_t *, zoneid_t); 4927c478bd9Sstevel@tonic-gate conn_t *ipcl_classify_raw(uint8_t, zoneid_t, uint32_t, ipha_t *); 4937c478bd9Sstevel@tonic-gate void ipcl_globalhash_insert(conn_t *); 4947c478bd9Sstevel@tonic-gate void ipcl_globalhash_remove(conn_t *); 4957c478bd9Sstevel@tonic-gate void ipcl_walk(pfv_t, void *); 4967c478bd9Sstevel@tonic-gate conn_t *ipcl_tcp_lookup_reversed_ipv4(ipha_t *, tcph_t *, int); 4977c478bd9Sstevel@tonic-gate conn_t *ipcl_tcp_lookup_reversed_ipv6(ip6_t *, tcpha_t *, int, uint_t); 4987c478bd9Sstevel@tonic-gate conn_t *ipcl_lookup_listener_v4(uint16_t, ipaddr_t, zoneid_t); 4997c478bd9Sstevel@tonic-gate conn_t *ipcl_lookup_listener_v6(uint16_t, in6_addr_t *, uint_t, zoneid_t); 5007c478bd9Sstevel@tonic-gate int conn_trace_ref(conn_t *); 5017c478bd9Sstevel@tonic-gate int conn_untrace_ref(conn_t *); 5027c478bd9Sstevel@tonic-gate conn_t *ipcl_conn_tcp_lookup_reversed_ipv4(conn_t *, ipha_t *, tcph_t *); 5037c478bd9Sstevel@tonic-gate conn_t *ipcl_conn_tcp_lookup_reversed_ipv6(conn_t *, ip6_t *, tcph_t *); 5047c478bd9Sstevel@tonic-gate #ifdef __cplusplus 5057c478bd9Sstevel@tonic-gate } 5067c478bd9Sstevel@tonic-gate #endif 5077c478bd9Sstevel@tonic-gate 5087c478bd9Sstevel@tonic-gate #endif /* _INET_IPCLASSIFIER_H */ 509