1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #ifndef _INET_IPCLASSIFIER_H 28*7c478bd9Sstevel@tonic-gate #define _INET_IPCLASSIFIER_H 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 33*7c478bd9Sstevel@tonic-gate extern "C" { 34*7c478bd9Sstevel@tonic-gate #endif 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate #include <inet/common.h> 37*7c478bd9Sstevel@tonic-gate #include <inet/ip.h> 38*7c478bd9Sstevel@tonic-gate #include <inet/mi.h> 39*7c478bd9Sstevel@tonic-gate #include <inet/tcp.h> 40*7c478bd9Sstevel@tonic-gate #include <inet/ip6.h> 41*7c478bd9Sstevel@tonic-gate #include <netinet/in.h> /* for IPPROTO_* constants */ 42*7c478bd9Sstevel@tonic-gate #include <sys/sdt.h> 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate typedef void (*edesc_spf)(void *, mblk_t *, void *, int); 45*7c478bd9Sstevel@tonic-gate typedef void (*edesc_rpf)(void *, mblk_t *, void *); 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate /* 48*7c478bd9Sstevel@tonic-gate * ============================== 49*7c478bd9Sstevel@tonic-gate * = The CONNECTION = 50*7c478bd9Sstevel@tonic-gate * ============================== 51*7c478bd9Sstevel@tonic-gate */ 52*7c478bd9Sstevel@tonic-gate 53*7c478bd9Sstevel@tonic-gate /* 54*7c478bd9Sstevel@tonic-gate * The connection structure contains the common information/flags/ref needed. 55*7c478bd9Sstevel@tonic-gate * Implementation will keep the connection struct, the layers (with their 56*7c478bd9Sstevel@tonic-gate * respective data for event i.e. tcp_t if event was tcp_input) all in one 57*7c478bd9Sstevel@tonic-gate * contiguous memory location. 58*7c478bd9Sstevel@tonic-gate */ 59*7c478bd9Sstevel@tonic-gate 60*7c478bd9Sstevel@tonic-gate /* Conn Flags */ 61*7c478bd9Sstevel@tonic-gate #define IPCL_BOUND 0x80000000 /* Conn in bind table */ 62*7c478bd9Sstevel@tonic-gate #define IPCL_CONNECTED 0x40000000 /* Conn in connected table */ 63*7c478bd9Sstevel@tonic-gate #define IPCL_TCP4 0x08000000 /* A TCP connection */ 64*7c478bd9Sstevel@tonic-gate #define IPCL_TCP6 0x04000000 /* A TCP6 connection */ 65*7c478bd9Sstevel@tonic-gate #define IPCL_EAGER 0x01000000 /* Incoming connection */ 66*7c478bd9Sstevel@tonic-gate #define IPCL_CL_LISTENER 0x00800000 /* Cluster listener */ 67*7c478bd9Sstevel@tonic-gate #define IPCL_ACCEPTOR 0x00400000 /* Sockfs priv acceptor */ 68*7c478bd9Sstevel@tonic-gate #define IPCL_SOCKET 0x00200000 /* Sockfs connection */ 69*7c478bd9Sstevel@tonic-gate #define IPCL_CHECK_POLICY 0x00100000 /* Needs policy checking */ 70*7c478bd9Sstevel@tonic-gate #define IPCL_FULLY_BOUND 0x00080000 /* Bound to correct squeue */ 71*7c478bd9Sstevel@tonic-gate #define IPCL_TCPMOD 0x00040000 /* Is tcp module instance */ 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate /* Flags identifying the type of conn */ 74*7c478bd9Sstevel@tonic-gate #define IPCL_TCPCONN 0x00000001 /* Flag to indicate cache */ 75*7c478bd9Sstevel@tonic-gate #define IPCL_SCTPCONN 0x00000002 76*7c478bd9Sstevel@tonic-gate #define IPCL_IPCCONN 0x00000004 77*7c478bd9Sstevel@tonic-gate #define IPCL_ISV6 0x00000008 /* Is a V6 connection */ 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate /* Conn Masks */ 80*7c478bd9Sstevel@tonic-gate #define IPCL_TCP (IPCL_TCP4|IPCL_TCP6) 81*7c478bd9Sstevel@tonic-gate #define IPCL_REMOVED 0x00000020 82*7c478bd9Sstevel@tonic-gate #define IPCL_REUSED 0x00000040 83*7c478bd9Sstevel@tonic-gate 84*7c478bd9Sstevel@tonic-gate #define IS_TCP_CONN(connp) (((connp)->conn_flags & IPCL_TCP) != 0) 85*7c478bd9Sstevel@tonic-gate 86*7c478bd9Sstevel@tonic-gate #define IPCL_IS_TCP4(connp) \ 87*7c478bd9Sstevel@tonic-gate (((connp)->conn_flags & IPCL_TCP4)) 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate #define IPCL_IS_TCP4_CONNECTED_NO_POLICY(connp) \ 90*7c478bd9Sstevel@tonic-gate (((connp)->conn_flags & \ 91*7c478bd9Sstevel@tonic-gate (IPCL_TCP4|IPCL_CONNECTED|IPCL_CHECK_POLICY|IPCL_TCP6)) \ 92*7c478bd9Sstevel@tonic-gate == (IPCL_TCP4|IPCL_CONNECTED)) 93*7c478bd9Sstevel@tonic-gate 94*7c478bd9Sstevel@tonic-gate #define IPCL_IS_CONNECTED(connp) \ 95*7c478bd9Sstevel@tonic-gate ((connp)->conn_flags & IPCL_CONNECTED) 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate #define IPCL_IS_BOUND(connp) \ 98*7c478bd9Sstevel@tonic-gate ((connp)->conn_flags & IPCL_BOUND) 99*7c478bd9Sstevel@tonic-gate 100*7c478bd9Sstevel@tonic-gate #define IPCL_IS_TCP4_BOUND(connp) \ 101*7c478bd9Sstevel@tonic-gate (((connp)->conn_flags & \ 102*7c478bd9Sstevel@tonic-gate (IPCL_TCP4|IPCL_BOUND|IPCL_TCP6)) == \ 103*7c478bd9Sstevel@tonic-gate (IPCL_TCP4|IPCL_BOUND)) 104*7c478bd9Sstevel@tonic-gate 105*7c478bd9Sstevel@tonic-gate #define IPCL_IS_FULLY_BOUND(connp) \ 106*7c478bd9Sstevel@tonic-gate ((connp)->conn_flags & IPCL_FULLY_BOUND) 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate #define IPCL_IS_TCP(connp) \ 109*7c478bd9Sstevel@tonic-gate ((connp)->conn_flags & (IPCL_TCP4|IPCL_TCP6)) 110*7c478bd9Sstevel@tonic-gate 111*7c478bd9Sstevel@tonic-gate #define IPCL_IS_IPTUN(connp) \ 112*7c478bd9Sstevel@tonic-gate ((connp)->conn_ulp == IPPROTO_ENCAP || \ 113*7c478bd9Sstevel@tonic-gate (connp)->conn_ulp == IPPROTO_IPV6) 114*7c478bd9Sstevel@tonic-gate 115*7c478bd9Sstevel@tonic-gate typedef struct connf_s connf_t; 116*7c478bd9Sstevel@tonic-gate typedef struct 117*7c478bd9Sstevel@tonic-gate { 118*7c478bd9Sstevel@tonic-gate int ctb_depth; 119*7c478bd9Sstevel@tonic-gate #define IP_STACK_DEPTH 15 120*7c478bd9Sstevel@tonic-gate pc_t ctb_stack[IP_STACK_DEPTH]; 121*7c478bd9Sstevel@tonic-gate } conn_trace_t; 122*7c478bd9Sstevel@tonic-gate 123*7c478bd9Sstevel@tonic-gate struct conn_s { 124*7c478bd9Sstevel@tonic-gate kmutex_t conn_lock; 125*7c478bd9Sstevel@tonic-gate uint32_t conn_ref; /* Reference counter */ 126*7c478bd9Sstevel@tonic-gate uint_t conn_state_flags; /* IP state flags */ 127*7c478bd9Sstevel@tonic-gate ire_t *conn_ire_cache; /* outbound ire cache */ 128*7c478bd9Sstevel@tonic-gate uint32_t conn_flags; /* Conn Flags */ 129*7c478bd9Sstevel@tonic-gate unsigned int 130*7c478bd9Sstevel@tonic-gate conn_on_sqp : 1, /* Conn is being processed */ 131*7c478bd9Sstevel@tonic-gate conn_dontroute : 1, /* SO_DONTROUTE state */ 132*7c478bd9Sstevel@tonic-gate conn_loopback : 1, /* SO_LOOPBACK state */ 133*7c478bd9Sstevel@tonic-gate conn_broadcast : 1, /* SO_BROADCAST state */ 134*7c478bd9Sstevel@tonic-gate conn_reuseaddr : 1, /* SO_REUSEADDR state */ 135*7c478bd9Sstevel@tonic-gate 136*7c478bd9Sstevel@tonic-gate conn_multicast_loop : 1, /* IP_MULTICAST_LOOP */ 137*7c478bd9Sstevel@tonic-gate conn_multi_router : 1, /* Wants all multicast pkts */ 138*7c478bd9Sstevel@tonic-gate conn_draining : 1, /* ip_wsrv running */ 139*7c478bd9Sstevel@tonic-gate conn_did_putbq : 1, /* ip_wput did a putbq */ 140*7c478bd9Sstevel@tonic-gate 141*7c478bd9Sstevel@tonic-gate conn_unspec_src : 1, /* IP_UNSPEC_SRC */ 142*7c478bd9Sstevel@tonic-gate conn_policy_cached : 1, /* Is policy cached/latched ? */ 143*7c478bd9Sstevel@tonic-gate conn_in_enforce_policy : 1, /* Enforce Policy on inbound */ 144*7c478bd9Sstevel@tonic-gate conn_out_enforce_policy : 1, /* Enforce Policy on outbound */ 145*7c478bd9Sstevel@tonic-gate 146*7c478bd9Sstevel@tonic-gate conn_af_isv6 : 1, /* ip address family ver 6 */ 147*7c478bd9Sstevel@tonic-gate conn_pkt_isv6 : 1, /* ip packet format ver 6 */ 148*7c478bd9Sstevel@tonic-gate conn_ipv6_recvpktinfo : 1, /* IPV6_RECVPKTINFO option */ 149*7c478bd9Sstevel@tonic-gate conn_ipv6_recvhoplimit : 1, /* IPV6_RECVHOPLIMIT option */ 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate conn_ipv6_recvhopopts : 1, /* IPV6_RECVHOPOPTS option */ 152*7c478bd9Sstevel@tonic-gate conn_ipv6_recvdstopts : 1, /* IPV6_RECVDSTOPTS option */ 153*7c478bd9Sstevel@tonic-gate conn_ipv6_recvrthdr : 1, /* IPV6_RECVRTHDR option */ 154*7c478bd9Sstevel@tonic-gate conn_ipv6_recvrtdstopts : 1, /* IPV6_RECVRTHDRDSTOPTS */ 155*7c478bd9Sstevel@tonic-gate conn_ipv6_v6only : 1, /* IPV6_V6ONLY */ 156*7c478bd9Sstevel@tonic-gate conn_ipv6_recvtclass : 1, /* IPV6_RECVTCLASS */ 157*7c478bd9Sstevel@tonic-gate conn_ipv6_recvpathmtu : 1, /* IPV6_RECVPATHMTU */ 158*7c478bd9Sstevel@tonic-gate conn_pathmtu_valid : 1, /* The cached mtu is valid. */ 159*7c478bd9Sstevel@tonic-gate conn_ipv6_dontfrag : 1, /* IPV6_DONTFRAG */ 160*7c478bd9Sstevel@tonic-gate /* 161*7c478bd9Sstevel@tonic-gate * This option can take on values in [-1, 1] so we store it 162*7c478bd9Sstevel@tonic-gate * +1. Manifest constants IPV6_USE_MIN_MTU_* describe these 163*7c478bd9Sstevel@tonic-gate * values. 164*7c478bd9Sstevel@tonic-gate */ 165*7c478bd9Sstevel@tonic-gate conn_fully_bound : 1, /* Fully bound connection */ 166*7c478bd9Sstevel@tonic-gate conn_recvif : 1, /* IP_RECVIF option */ 167*7c478bd9Sstevel@tonic-gate conn_recvslla : 1, /* IP_RECVSLLA option */ 168*7c478bd9Sstevel@tonic-gate conn_mdt_ok : 1, /* MDT is permitted */ 169*7c478bd9Sstevel@tonic-gate pad_to_bit_31 : 2; 170*7c478bd9Sstevel@tonic-gate 171*7c478bd9Sstevel@tonic-gate tcp_t *conn_tcp; /* Pointer to the tcp struct */ 172*7c478bd9Sstevel@tonic-gate squeue_t *conn_sqp; /* Squeue for processing */ 173*7c478bd9Sstevel@tonic-gate edesc_rpf conn_recv; /* Pointer to recv routine */ 174*7c478bd9Sstevel@tonic-gate void *conn_pad1; 175*7c478bd9Sstevel@tonic-gate 176*7c478bd9Sstevel@tonic-gate ill_t *conn_xmit_if_ill; /* Outbound ill */ 177*7c478bd9Sstevel@tonic-gate ill_t *conn_nofailover_ill; /* Failover ill */ 178*7c478bd9Sstevel@tonic-gate ipsec_latch_t *conn_latch; /* latched state */ 179*7c478bd9Sstevel@tonic-gate ill_t *conn_outgoing_ill; /* IP{,V6}_BOUND_IF */ 180*7c478bd9Sstevel@tonic-gate edesc_spf conn_send; /* Pointer to send routine */ 181*7c478bd9Sstevel@tonic-gate queue_t *conn_rq; /* Read queue */ 182*7c478bd9Sstevel@tonic-gate queue_t *conn_wq; /* Write queue */ 183*7c478bd9Sstevel@tonic-gate dev_t conn_dev; /* Minor number */ 184*7c478bd9Sstevel@tonic-gate 185*7c478bd9Sstevel@tonic-gate cred_t *conn_cred; /* Credentials */ 186*7c478bd9Sstevel@tonic-gate connf_t *conn_g_fanout; /* Global Hash bucket head */ 187*7c478bd9Sstevel@tonic-gate struct conn_s *conn_g_next; /* Global Hash chain next */ 188*7c478bd9Sstevel@tonic-gate struct conn_s *conn_g_prev; /* Global Hash chain prev */ 189*7c478bd9Sstevel@tonic-gate struct ipsec_policy_head_s *conn_policy; /* Configured policy */ 190*7c478bd9Sstevel@tonic-gate in6_addr_t conn_bound_source_v6; 191*7c478bd9Sstevel@tonic-gate #define conn_bound_source V4_PART_OF_V6(conn_bound_source_v6) 192*7c478bd9Sstevel@tonic-gate void *conn_void[1]; 193*7c478bd9Sstevel@tonic-gate 194*7c478bd9Sstevel@tonic-gate connf_t *conn_fanout; /* Hash bucket we're part of */ 195*7c478bd9Sstevel@tonic-gate struct conn_s *conn_next; /* Hash chain next */ 196*7c478bd9Sstevel@tonic-gate struct conn_s *conn_prev; /* Hash chain prev */ 197*7c478bd9Sstevel@tonic-gate struct { 198*7c478bd9Sstevel@tonic-gate in6_addr_t connua_laddr; /* Local address */ 199*7c478bd9Sstevel@tonic-gate in6_addr_t connua_faddr; /* Remote address */ 200*7c478bd9Sstevel@tonic-gate } connua_v6addr; 201*7c478bd9Sstevel@tonic-gate #define conn_src V4_PART_OF_V6(connua_v6addr.connua_laddr) 202*7c478bd9Sstevel@tonic-gate #define conn_rem V4_PART_OF_V6(connua_v6addr.connua_faddr) 203*7c478bd9Sstevel@tonic-gate #define conn_srcv6 connua_v6addr.connua_laddr 204*7c478bd9Sstevel@tonic-gate #define conn_remv6 connua_v6addr.connua_faddr 205*7c478bd9Sstevel@tonic-gate union { 206*7c478bd9Sstevel@tonic-gate /* Used for classifier match performance */ 207*7c478bd9Sstevel@tonic-gate uint32_t conn_ports2; 208*7c478bd9Sstevel@tonic-gate struct { 209*7c478bd9Sstevel@tonic-gate in_port_t tcpu_fport; /* Remote port */ 210*7c478bd9Sstevel@tonic-gate in_port_t tcpu_lport; /* Local port */ 211*7c478bd9Sstevel@tonic-gate } tcpu_ports; 212*7c478bd9Sstevel@tonic-gate } u_port; 213*7c478bd9Sstevel@tonic-gate #define conn_fport u_port.tcpu_ports.tcpu_fport 214*7c478bd9Sstevel@tonic-gate #define conn_lport u_port.tcpu_ports.tcpu_lport 215*7c478bd9Sstevel@tonic-gate #define conn_ports u_port.conn_ports2 216*7c478bd9Sstevel@tonic-gate #define conn_upq conn_rq 217*7c478bd9Sstevel@tonic-gate uint8_t conn_ulp; /* protocol type */ 218*7c478bd9Sstevel@tonic-gate uint8_t conn_unused_byte; 219*7c478bd9Sstevel@tonic-gate kcondvar_t conn_cv; 220*7c478bd9Sstevel@tonic-gate 221*7c478bd9Sstevel@tonic-gate uint_t conn_proto; /* SO_PROTOTYPE state */ 222*7c478bd9Sstevel@tonic-gate ill_t *conn_incoming_ill; /* IP{,V6}_BOUND_IF */ 223*7c478bd9Sstevel@tonic-gate ill_t *conn_outgoing_pill; /* IP{,V6}_BOUND_PIF */ 224*7c478bd9Sstevel@tonic-gate ill_t *conn_oper_pending_ill; /* pending shared ioctl */ 225*7c478bd9Sstevel@tonic-gate ill_t *conn_xioctl_pending_ill; /* pending excl ioctl */ 226*7c478bd9Sstevel@tonic-gate 227*7c478bd9Sstevel@tonic-gate /* this is used only when an unbind is in progress.. */ 228*7c478bd9Sstevel@tonic-gate struct sq_s *conn_pending_sq; /* waiting for ioctl on sq */ 229*7c478bd9Sstevel@tonic-gate ilg_t *conn_ilg; /* Group memberships */ 230*7c478bd9Sstevel@tonic-gate int conn_ilg_allocated; /* Number allocated */ 231*7c478bd9Sstevel@tonic-gate int conn_ilg_inuse; /* Number currently used */ 232*7c478bd9Sstevel@tonic-gate int conn_ilg_walker_cnt; /* No of ilg walkers */ 233*7c478bd9Sstevel@tonic-gate /* XXXX get rid of this, once ilg_delete_all is fixed */ 234*7c478bd9Sstevel@tonic-gate kcondvar_t conn_refcv; 235*7c478bd9Sstevel@tonic-gate 236*7c478bd9Sstevel@tonic-gate struct ipif_s *conn_multicast_ipif; /* IP_MULTICAST_IF */ 237*7c478bd9Sstevel@tonic-gate ill_t *conn_multicast_ill; /* IPV6_MULTICAST_IF */ 238*7c478bd9Sstevel@tonic-gate int conn_orig_bound_ifindex; /* BOUND_IF before MOVE */ 239*7c478bd9Sstevel@tonic-gate int conn_orig_multicast_ifindex; 240*7c478bd9Sstevel@tonic-gate /* IPv6 MC IF before MOVE */ 241*7c478bd9Sstevel@tonic-gate int conn_orig_xmit_ifindex; /* IP_XMIT_IF before move */ 242*7c478bd9Sstevel@tonic-gate struct conn_s *conn_drain_next; /* Next conn in drain list */ 243*7c478bd9Sstevel@tonic-gate struct conn_s *conn_drain_prev; /* Prev conn in drain list */ 244*7c478bd9Sstevel@tonic-gate idl_t *conn_idl; /* Ptr to the drain list head */ 245*7c478bd9Sstevel@tonic-gate mblk_t *conn_ipsec_opt_mp; /* ipsec option mblk */ 246*7c478bd9Sstevel@tonic-gate uint32_t conn_src_preferences; /* prefs for src addr select */ 247*7c478bd9Sstevel@tonic-gate /* mtuinfo from IPV6_PACKET_TOO_BIG conditional on conn_pathmtu_valid */ 248*7c478bd9Sstevel@tonic-gate struct ip6_mtuinfo mtuinfo; 249*7c478bd9Sstevel@tonic-gate zoneid_t conn_zoneid; /* zone connection is in */ 250*7c478bd9Sstevel@tonic-gate #ifdef CONN_DEBUG 251*7c478bd9Sstevel@tonic-gate #define CONN_TRACE_MAX 10 252*7c478bd9Sstevel@tonic-gate int conn_trace_last; /* ndx of last used tracebuf */ 253*7c478bd9Sstevel@tonic-gate conn_trace_t conn_trace_buf[CONN_TRACE_MAX]; 254*7c478bd9Sstevel@tonic-gate #endif 255*7c478bd9Sstevel@tonic-gate }; 256*7c478bd9Sstevel@tonic-gate 257*7c478bd9Sstevel@tonic-gate /* 258*7c478bd9Sstevel@tonic-gate * connf_t - connection fanout data. 259*7c478bd9Sstevel@tonic-gate * 260*7c478bd9Sstevel@tonic-gate * The hash tables and their linkage (conn_t.{hashnextp, hashprevp} are 261*7c478bd9Sstevel@tonic-gate * protected by the per-bucket lock. Each conn_t inserted in the list 262*7c478bd9Sstevel@tonic-gate * points back at the connf_t that heads the bucket. 263*7c478bd9Sstevel@tonic-gate */ 264*7c478bd9Sstevel@tonic-gate 265*7c478bd9Sstevel@tonic-gate struct connf_s { 266*7c478bd9Sstevel@tonic-gate struct conn_s *connf_head; 267*7c478bd9Sstevel@tonic-gate kmutex_t connf_lock; 268*7c478bd9Sstevel@tonic-gate }; 269*7c478bd9Sstevel@tonic-gate 270*7c478bd9Sstevel@tonic-gate #define CONN_INC_REF(connp) { \ 271*7c478bd9Sstevel@tonic-gate DTRACE_PROBE1(conn__inc__ref, conn_t *, connp); \ 272*7c478bd9Sstevel@tonic-gate mutex_enter(&(connp)->conn_lock); \ 273*7c478bd9Sstevel@tonic-gate ASSERT(conn_trace_ref(connp)); \ 274*7c478bd9Sstevel@tonic-gate (connp)->conn_ref++; \ 275*7c478bd9Sstevel@tonic-gate ASSERT((connp)->conn_ref != 0); \ 276*7c478bd9Sstevel@tonic-gate mutex_exit(&(connp)->conn_lock); \ 277*7c478bd9Sstevel@tonic-gate } 278*7c478bd9Sstevel@tonic-gate 279*7c478bd9Sstevel@tonic-gate #define CONN_INC_REF_LOCKED(connp) { \ 280*7c478bd9Sstevel@tonic-gate DTRACE_PROBE1(conn__inc__ref, conn_t *, connp); \ 281*7c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&(connp)->conn_lock)); \ 282*7c478bd9Sstevel@tonic-gate ASSERT(conn_trace_ref(connp)); \ 283*7c478bd9Sstevel@tonic-gate (connp)->conn_ref++; \ 284*7c478bd9Sstevel@tonic-gate ASSERT((connp)->conn_ref != 0); \ 285*7c478bd9Sstevel@tonic-gate } 286*7c478bd9Sstevel@tonic-gate 287*7c478bd9Sstevel@tonic-gate #define CONN_DEC_REF(connp) { \ 288*7c478bd9Sstevel@tonic-gate DTRACE_PROBE1(conn__dec__ref, conn_t *, connp); \ 289*7c478bd9Sstevel@tonic-gate mutex_enter(&(connp)->conn_lock); \ 290*7c478bd9Sstevel@tonic-gate if ((connp)->conn_ref <= 0) \ 291*7c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "CONN_DEC_REF: connp(%p) has ref " \ 292*7c478bd9Sstevel@tonic-gate "= %d\n", (void *)(connp), (connp)->conn_ref); \ 293*7c478bd9Sstevel@tonic-gate ASSERT(conn_untrace_ref(connp)); \ 294*7c478bd9Sstevel@tonic-gate (connp)->conn_ref--; \ 295*7c478bd9Sstevel@tonic-gate if ((connp)->conn_ref == 0) { \ 296*7c478bd9Sstevel@tonic-gate /* Refcnt can't increase again, safe to drop lock */ \ 297*7c478bd9Sstevel@tonic-gate mutex_exit(&(connp)->conn_lock); \ 298*7c478bd9Sstevel@tonic-gate ipcl_conn_destroy(connp); \ 299*7c478bd9Sstevel@tonic-gate } else { \ 300*7c478bd9Sstevel@tonic-gate cv_broadcast(&(connp)->conn_cv); \ 301*7c478bd9Sstevel@tonic-gate mutex_exit(&(connp)->conn_lock); \ 302*7c478bd9Sstevel@tonic-gate } \ 303*7c478bd9Sstevel@tonic-gate } 304*7c478bd9Sstevel@tonic-gate 305*7c478bd9Sstevel@tonic-gate #define _IPCL_V4_MATCH(v6addr, v4addr) \ 306*7c478bd9Sstevel@tonic-gate (V4_PART_OF_V6((v6addr)) == (v4addr) && IN6_IS_ADDR_V4MAPPED(&(v6addr))) 307*7c478bd9Sstevel@tonic-gate 308*7c478bd9Sstevel@tonic-gate #define _IPCL_V4_MATCH_ANY(addr) \ 309*7c478bd9Sstevel@tonic-gate (IN6_IS_ADDR_V4MAPPED_ANY(&(addr)) || IN6_IS_ADDR_UNSPECIFIED(&(addr))) 310*7c478bd9Sstevel@tonic-gate 311*7c478bd9Sstevel@tonic-gate /* 312*7c478bd9Sstevel@tonic-gate * IPCL_PROTO_MATCH() only matches conns with the specified zoneid, while 313*7c478bd9Sstevel@tonic-gate * IPCL_PROTO_MATCH_V6() can match other conns in the multicast case, see 314*7c478bd9Sstevel@tonic-gate * ip_fanout_proto(). 315*7c478bd9Sstevel@tonic-gate */ 316*7c478bd9Sstevel@tonic-gate #define IPCL_PROTO_MATCH(connp, protocol, ipha, ill, \ 317*7c478bd9Sstevel@tonic-gate fanout_flags, zoneid) \ 318*7c478bd9Sstevel@tonic-gate ((((connp)->conn_src == INADDR_ANY) || \ 319*7c478bd9Sstevel@tonic-gate (((connp)->conn_src == ((ipha)->ipha_dst)) && \ 320*7c478bd9Sstevel@tonic-gate (((connp)->conn_rem == INADDR_ANY) || \ 321*7c478bd9Sstevel@tonic-gate ((connp)->conn_rem == ((ipha)->ipha_src))))) && \ 322*7c478bd9Sstevel@tonic-gate ((connp)->conn_zoneid == (zoneid)) && \ 323*7c478bd9Sstevel@tonic-gate (conn_wantpacket((connp), (ill), (ipha), \ 324*7c478bd9Sstevel@tonic-gate (fanout_flags), (zoneid)) || ((protocol) == IPPROTO_PIM) || \ 325*7c478bd9Sstevel@tonic-gate ((protocol) == IPPROTO_RSVP))) 326*7c478bd9Sstevel@tonic-gate 327*7c478bd9Sstevel@tonic-gate #define IPCL_PROTO_MATCH_V6(connp, protocol, ip6h, ill, \ 328*7c478bd9Sstevel@tonic-gate fanout_flags, zoneid) \ 329*7c478bd9Sstevel@tonic-gate ((IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_srcv6) || \ 330*7c478bd9Sstevel@tonic-gate (IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &((ip6h)->ip6_dst)) && \ 331*7c478bd9Sstevel@tonic-gate (IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_remv6) || \ 332*7c478bd9Sstevel@tonic-gate IN6_ARE_ADDR_EQUAL(&(connp)->conn_remv6, &((ip6h)->ip6_src))))) && \ 333*7c478bd9Sstevel@tonic-gate (conn_wantpacket_v6((connp), (ill), (ip6h), \ 334*7c478bd9Sstevel@tonic-gate (fanout_flags), (zoneid)) || ((protocol) == IPPROTO_RSVP))) 335*7c478bd9Sstevel@tonic-gate 336*7c478bd9Sstevel@tonic-gate #define IPCL_CONN_HASH(src, ports) \ 337*7c478bd9Sstevel@tonic-gate ((unsigned)(ntohl((src)) ^ ((ports) >> 24) ^ ((ports) >> 16) ^ \ 338*7c478bd9Sstevel@tonic-gate ((ports) >> 8) ^ (ports)) % ipcl_conn_fanout_size) 339*7c478bd9Sstevel@tonic-gate 340*7c478bd9Sstevel@tonic-gate #define IPCL_CONN_HASH_V6(src, ports) \ 341*7c478bd9Sstevel@tonic-gate IPCL_CONN_HASH(V4_PART_OF_V6((src)), (ports)) 342*7c478bd9Sstevel@tonic-gate 343*7c478bd9Sstevel@tonic-gate #define IPCL_CONN_MATCH(connp, proto, src, dst, ports) \ 344*7c478bd9Sstevel@tonic-gate ((connp)->conn_ulp == (proto) && \ 345*7c478bd9Sstevel@tonic-gate (connp)->conn_ports == (ports) && \ 346*7c478bd9Sstevel@tonic-gate _IPCL_V4_MATCH((connp)->conn_remv6, (src)) && \ 347*7c478bd9Sstevel@tonic-gate _IPCL_V4_MATCH((connp)->conn_srcv6, (dst)) && \ 348*7c478bd9Sstevel@tonic-gate !(connp)->conn_ipv6_v6only) 349*7c478bd9Sstevel@tonic-gate 350*7c478bd9Sstevel@tonic-gate #define IPCL_CONN_MATCH_V6(connp, proto, src, dst, ports) \ 351*7c478bd9Sstevel@tonic-gate ((connp)->conn_ulp == (proto) && \ 352*7c478bd9Sstevel@tonic-gate (connp)->conn_ports == (ports) && \ 353*7c478bd9Sstevel@tonic-gate IN6_ARE_ADDR_EQUAL(&(connp)->conn_remv6, &(src)) && \ 354*7c478bd9Sstevel@tonic-gate IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &(dst))) 355*7c478bd9Sstevel@tonic-gate 356*7c478bd9Sstevel@tonic-gate #define IPCL_CONN_INIT(connp, protocol, src, rem, ports) { \ 357*7c478bd9Sstevel@tonic-gate (connp)->conn_ulp = protocol; \ 358*7c478bd9Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(src, &(connp)->conn_srcv6); \ 359*7c478bd9Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(rem, &(connp)->conn_remv6); \ 360*7c478bd9Sstevel@tonic-gate (connp)->conn_ports = ports; \ 361*7c478bd9Sstevel@tonic-gate } 362*7c478bd9Sstevel@tonic-gate 363*7c478bd9Sstevel@tonic-gate #define IPCL_CONN_INIT_V6(connp, protocol, src, rem, ports) { \ 364*7c478bd9Sstevel@tonic-gate (connp)->conn_ulp = protocol; \ 365*7c478bd9Sstevel@tonic-gate (connp)->conn_srcv6 = src; \ 366*7c478bd9Sstevel@tonic-gate (connp)->conn_remv6 = rem; \ 367*7c478bd9Sstevel@tonic-gate (connp)->conn_ports = ports; \ 368*7c478bd9Sstevel@tonic-gate } 369*7c478bd9Sstevel@tonic-gate 370*7c478bd9Sstevel@tonic-gate #define IPCL_BIND_HASH(lport) \ 371*7c478bd9Sstevel@tonic-gate ((unsigned)(((lport) >> 8) ^ (lport)) % ipcl_bind_fanout_size) 372*7c478bd9Sstevel@tonic-gate 373*7c478bd9Sstevel@tonic-gate #define IPCL_BIND_MATCH(connp, proto, laddr, lport) \ 374*7c478bd9Sstevel@tonic-gate ((connp)->conn_ulp == (proto) && \ 375*7c478bd9Sstevel@tonic-gate (connp)->conn_lport == (lport) && \ 376*7c478bd9Sstevel@tonic-gate (_IPCL_V4_MATCH_ANY((connp)->conn_srcv6) || \ 377*7c478bd9Sstevel@tonic-gate _IPCL_V4_MATCH((connp)->conn_srcv6, (laddr))) && \ 378*7c478bd9Sstevel@tonic-gate !(connp)->conn_ipv6_v6only) 379*7c478bd9Sstevel@tonic-gate 380*7c478bd9Sstevel@tonic-gate #define IPCL_BIND_MATCH_V6(connp, proto, laddr, lport) \ 381*7c478bd9Sstevel@tonic-gate ((connp)->conn_ulp == (proto) && \ 382*7c478bd9Sstevel@tonic-gate (connp)->conn_lport == (lport) && \ 383*7c478bd9Sstevel@tonic-gate (IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &(laddr)) || \ 384*7c478bd9Sstevel@tonic-gate IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_srcv6))) 385*7c478bd9Sstevel@tonic-gate 386*7c478bd9Sstevel@tonic-gate #define IPCL_UDP_MATCH(connp, lport, laddr, fport, faddr) \ 387*7c478bd9Sstevel@tonic-gate (((connp)->conn_lport == (lport)) && \ 388*7c478bd9Sstevel@tonic-gate ((_IPCL_V4_MATCH_ANY((connp)->conn_srcv6) || \ 389*7c478bd9Sstevel@tonic-gate (_IPCL_V4_MATCH((connp)->conn_srcv6, (laddr)) && \ 390*7c478bd9Sstevel@tonic-gate (_IPCL_V4_MATCH_ANY((connp)->conn_remv6) || \ 391*7c478bd9Sstevel@tonic-gate (_IPCL_V4_MATCH((connp)->conn_remv6, (faddr)) && \ 392*7c478bd9Sstevel@tonic-gate (connp)->conn_fport == (fport)))))) && \ 393*7c478bd9Sstevel@tonic-gate !(connp)->conn_ipv6_v6only) 394*7c478bd9Sstevel@tonic-gate 395*7c478bd9Sstevel@tonic-gate #define IPCL_UDP_MATCH_V6(connp, lport, laddr, fport, faddr) \ 396*7c478bd9Sstevel@tonic-gate (((connp)->conn_lport == (lport)) && \ 397*7c478bd9Sstevel@tonic-gate (IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_srcv6) || \ 398*7c478bd9Sstevel@tonic-gate (IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &(laddr)) && \ 399*7c478bd9Sstevel@tonic-gate (IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_remv6) || \ 400*7c478bd9Sstevel@tonic-gate (IN6_ARE_ADDR_EQUAL(&(connp)->conn_remv6, &(faddr)) && \ 401*7c478bd9Sstevel@tonic-gate (connp)->conn_fport == (fport)))))) 402*7c478bd9Sstevel@tonic-gate 403*7c478bd9Sstevel@tonic-gate #define IPCL_TCP_EAGER_INIT(connp, protocol, src, rem, ports) { \ 404*7c478bd9Sstevel@tonic-gate (connp)->conn_flags |= (IPCL_TCP4|IPCL_EAGER); \ 405*7c478bd9Sstevel@tonic-gate (connp)->conn_ulp = protocol; \ 406*7c478bd9Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(src, &(connp)->conn_srcv6); \ 407*7c478bd9Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(rem, &(connp)->conn_remv6); \ 408*7c478bd9Sstevel@tonic-gate (connp)->conn_ports = ports; \ 409*7c478bd9Sstevel@tonic-gate (connp)->conn_send = ip_output; \ 410*7c478bd9Sstevel@tonic-gate (connp)->conn_sqp = IP_SQUEUE_GET(lbolt); \ 411*7c478bd9Sstevel@tonic-gate } 412*7c478bd9Sstevel@tonic-gate 413*7c478bd9Sstevel@tonic-gate #define IPCL_TCP_EAGER_INIT_V6(connp, protocol, src, rem, ports) { \ 414*7c478bd9Sstevel@tonic-gate (connp)->conn_flags |= (IPCL_TCP6|IPCL_EAGER); \ 415*7c478bd9Sstevel@tonic-gate (connp)->conn_ulp = protocol; \ 416*7c478bd9Sstevel@tonic-gate (connp)->conn_srcv6 = src; \ 417*7c478bd9Sstevel@tonic-gate (connp)->conn_remv6 = rem; \ 418*7c478bd9Sstevel@tonic-gate (connp)->conn_ports = ports; \ 419*7c478bd9Sstevel@tonic-gate (connp)->conn_send = ip_output_v6; \ 420*7c478bd9Sstevel@tonic-gate (connp)->conn_sqp = IP_SQUEUE_GET(lbolt); \ 421*7c478bd9Sstevel@tonic-gate } 422*7c478bd9Sstevel@tonic-gate 423*7c478bd9Sstevel@tonic-gate #define ipcl_proto_search(protocol) \ 424*7c478bd9Sstevel@tonic-gate (ipcl_proto_fanout[(protocol)].connf_head) 425*7c478bd9Sstevel@tonic-gate 426*7c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN 427*7c478bd9Sstevel@tonic-gate #define IPCL_UDP_HASH(port) ((port) & 0xFF) 428*7c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */ 429*7c478bd9Sstevel@tonic-gate #define IPCL_UDP_HASH(port) (((uint16_t)(port)) >> 8) 430*7c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */ 431*7c478bd9Sstevel@tonic-gate 432*7c478bd9Sstevel@tonic-gate #define CONN_G_HASH_SIZE 1024 433*7c478bd9Sstevel@tonic-gate 434*7c478bd9Sstevel@tonic-gate /* Raw socket hash function. */ 435*7c478bd9Sstevel@tonic-gate #define IPCL_RAW_HASH(lport) (((lport) * 31) & (ipcl_raw_fanout_size - 1)) 436*7c478bd9Sstevel@tonic-gate 437*7c478bd9Sstevel@tonic-gate /* hash tables */ 438*7c478bd9Sstevel@tonic-gate extern connf_t rts_clients; 439*7c478bd9Sstevel@tonic-gate extern connf_t *ipcl_conn_fanout; 440*7c478bd9Sstevel@tonic-gate extern connf_t *ipcl_bind_fanout; 441*7c478bd9Sstevel@tonic-gate extern connf_t ipcl_proto_fanout[IPPROTO_MAX + 1]; 442*7c478bd9Sstevel@tonic-gate extern connf_t ipcl_proto_fanout_v6[IPPROTO_MAX + 1]; 443*7c478bd9Sstevel@tonic-gate extern connf_t *ipcl_udp_fanout; 444*7c478bd9Sstevel@tonic-gate extern connf_t *ipcl_globalhash_fanout; 445*7c478bd9Sstevel@tonic-gate extern connf_t *ipcl_raw_fanout; 446*7c478bd9Sstevel@tonic-gate extern uint_t ipcl_conn_fanout_size; 447*7c478bd9Sstevel@tonic-gate extern uint_t ipcl_bind_fanout_size; 448*7c478bd9Sstevel@tonic-gate extern uint_t ipcl_udp_fanout_size; 449*7c478bd9Sstevel@tonic-gate extern uint_t ipcl_raw_fanout_size; 450*7c478bd9Sstevel@tonic-gate 451*7c478bd9Sstevel@tonic-gate /* Function prototypes */ 452*7c478bd9Sstevel@tonic-gate extern void ipcl_init(void); 453*7c478bd9Sstevel@tonic-gate extern void ipcl_destroy(void); 454*7c478bd9Sstevel@tonic-gate extern conn_t *ipcl_conn_create(uint32_t, int); 455*7c478bd9Sstevel@tonic-gate extern void ipcl_conn_destroy(conn_t *); 456*7c478bd9Sstevel@tonic-gate 457*7c478bd9Sstevel@tonic-gate void ipcl_hash_insert_connected(connf_t *, conn_t *); 458*7c478bd9Sstevel@tonic-gate void ipcl_hash_insert_bound(connf_t *, conn_t *); 459*7c478bd9Sstevel@tonic-gate void ipcl_hash_insert_wildcard(connf_t *, conn_t *); 460*7c478bd9Sstevel@tonic-gate void ipcl_hash_remove(conn_t *); 461*7c478bd9Sstevel@tonic-gate void ipcl_hash_remove_locked(conn_t *connp, connf_t *connfp); 462*7c478bd9Sstevel@tonic-gate 463*7c478bd9Sstevel@tonic-gate extern int ipcl_bind_insert(conn_t *, uint8_t, ipaddr_t, uint16_t); 464*7c478bd9Sstevel@tonic-gate extern int ipcl_bind_insert_v6(conn_t *, uint8_t, const in6_addr_t *, 465*7c478bd9Sstevel@tonic-gate uint16_t); 466*7c478bd9Sstevel@tonic-gate extern int ipcl_conn_insert(conn_t *, uint8_t, ipaddr_t, ipaddr_t, 467*7c478bd9Sstevel@tonic-gate uint32_t); 468*7c478bd9Sstevel@tonic-gate extern int ipcl_conn_insert_v6(conn_t *, uint8_t, const in6_addr_t *, 469*7c478bd9Sstevel@tonic-gate const in6_addr_t *, uint32_t, uint_t); 470*7c478bd9Sstevel@tonic-gate 471*7c478bd9Sstevel@tonic-gate void ipcl_proto_insert(conn_t *, uint8_t); 472*7c478bd9Sstevel@tonic-gate void ipcl_proto_insert_v6(conn_t *, uint8_t); 473*7c478bd9Sstevel@tonic-gate conn_t *ipcl_classify_v4(mblk_t *, uint8_t, uint_t, zoneid_t); 474*7c478bd9Sstevel@tonic-gate conn_t *ipcl_classify_v6(mblk_t *, uint8_t, uint_t, zoneid_t); 475*7c478bd9Sstevel@tonic-gate conn_t *ipcl_classify(mblk_t *, zoneid_t); 476*7c478bd9Sstevel@tonic-gate conn_t *ipcl_classify_raw(uint8_t, zoneid_t, uint32_t, ipha_t *); 477*7c478bd9Sstevel@tonic-gate void ipcl_globalhash_insert(conn_t *); 478*7c478bd9Sstevel@tonic-gate void ipcl_globalhash_remove(conn_t *); 479*7c478bd9Sstevel@tonic-gate void ipcl_walk(pfv_t, void *); 480*7c478bd9Sstevel@tonic-gate conn_t *ipcl_tcp_lookup_reversed_ipv4(ipha_t *, tcph_t *, int); 481*7c478bd9Sstevel@tonic-gate conn_t *ipcl_tcp_lookup_reversed_ipv6(ip6_t *, tcpha_t *, int, uint_t); 482*7c478bd9Sstevel@tonic-gate conn_t *ipcl_lookup_listener_v4(uint16_t, ipaddr_t, zoneid_t); 483*7c478bd9Sstevel@tonic-gate conn_t *ipcl_lookup_listener_v6(uint16_t, in6_addr_t *, uint_t, zoneid_t); 484*7c478bd9Sstevel@tonic-gate int conn_trace_ref(conn_t *); 485*7c478bd9Sstevel@tonic-gate int conn_untrace_ref(conn_t *); 486*7c478bd9Sstevel@tonic-gate conn_t *ipcl_conn_tcp_lookup_reversed_ipv4(conn_t *, ipha_t *, tcph_t *); 487*7c478bd9Sstevel@tonic-gate conn_t *ipcl_conn_tcp_lookup_reversed_ipv6(conn_t *, ip6_t *, tcph_t *); 488*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 489*7c478bd9Sstevel@tonic-gate } 490*7c478bd9Sstevel@tonic-gate #endif 491*7c478bd9Sstevel@tonic-gate 492*7c478bd9Sstevel@tonic-gate #endif /* _INET_IPCLASSIFIER_H */ 493