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 /* 23*d045b987Smasputra * Copyright 2006 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 */ 61ff550d0eSmasputra #define IPCL_UDPMOD 0x00020000 /* Is UDP module instance */ 62ff550d0eSmasputra #define IPCL_TCPMOD 0x00040000 /* Is TCP module instance */ 637c478bd9Sstevel@tonic-gate #define IPCL_FULLY_BOUND 0x00080000 /* Bound to correct squeue */ 64ff550d0eSmasputra #define IPCL_CHECK_POLICY 0x00100000 /* Needs policy checking */ 65ff550d0eSmasputra #define IPCL_SOCKET 0x00200000 /* Sockfs connection */ 66ff550d0eSmasputra #define IPCL_ACCEPTOR 0x00400000 /* Sockfs priv acceptor */ 67ff550d0eSmasputra #define IPCL_CL_LISTENER 0x00800000 /* Cluster listener */ 68ff550d0eSmasputra #define IPCL_EAGER 0x01000000 /* Incoming connection */ 69ff550d0eSmasputra #define IPCL_UDP 0x02000000 /* A UDP connection */ 70ff550d0eSmasputra #define IPCL_TCP6 0x04000000 /* A TCP6 connection */ 71ff550d0eSmasputra #define IPCL_TCP4 0x08000000 /* A TCP connection */ 72ff550d0eSmasputra #define IPCL_CONNECTED 0x40000000 /* Conn in connected table */ 73ff550d0eSmasputra #define IPCL_BOUND 0x80000000 /* Conn in bind table */ 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate /* Flags identifying the type of conn */ 767c478bd9Sstevel@tonic-gate #define IPCL_TCPCONN 0x00000001 /* Flag to indicate cache */ 777c478bd9Sstevel@tonic-gate #define IPCL_SCTPCONN 0x00000002 787c478bd9Sstevel@tonic-gate #define IPCL_IPCCONN 0x00000004 797c478bd9Sstevel@tonic-gate #define IPCL_ISV6 0x00000008 /* Is a V6 connection */ 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate /* Conn Masks */ 827c478bd9Sstevel@tonic-gate #define IPCL_TCP (IPCL_TCP4|IPCL_TCP6) 837c478bd9Sstevel@tonic-gate #define IPCL_REMOVED 0x00000020 847c478bd9Sstevel@tonic-gate #define IPCL_REUSED 0x00000040 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 111ff550d0eSmasputra /* 112ff550d0eSmasputra * IPCL_UDP is set on the conn when udp is directly above ip; 113ff550d0eSmasputra * this flag is cleared the moment udp is popped. 114ff550d0eSmasputra */ 115ff550d0eSmasputra #define IPCL_IS_UDP(connp) \ 116ff550d0eSmasputra ((connp)->conn_flags & IPCL_UDP) 117ff550d0eSmasputra 1187c478bd9Sstevel@tonic-gate #define IPCL_IS_IPTUN(connp) \ 1197c478bd9Sstevel@tonic-gate ((connp)->conn_ulp == IPPROTO_ENCAP || \ 1207c478bd9Sstevel@tonic-gate (connp)->conn_ulp == IPPROTO_IPV6) 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate typedef struct connf_s connf_t; 1237c478bd9Sstevel@tonic-gate typedef struct 1247c478bd9Sstevel@tonic-gate { 1257c478bd9Sstevel@tonic-gate int ctb_depth; 1267c478bd9Sstevel@tonic-gate #define IP_STACK_DEPTH 15 1277c478bd9Sstevel@tonic-gate pc_t ctb_stack[IP_STACK_DEPTH]; 1287c478bd9Sstevel@tonic-gate } conn_trace_t; 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate struct conn_s { 1317c478bd9Sstevel@tonic-gate kmutex_t conn_lock; 1327c478bd9Sstevel@tonic-gate uint32_t conn_ref; /* Reference counter */ 1337c478bd9Sstevel@tonic-gate uint_t conn_state_flags; /* IP state flags */ 1347c478bd9Sstevel@tonic-gate ire_t *conn_ire_cache; /* outbound ire cache */ 1357c478bd9Sstevel@tonic-gate uint32_t conn_flags; /* Conn Flags */ 1367c478bd9Sstevel@tonic-gate unsigned int 1377c478bd9Sstevel@tonic-gate conn_on_sqp : 1, /* Conn is being processed */ 1387c478bd9Sstevel@tonic-gate conn_dontroute : 1, /* SO_DONTROUTE state */ 1397c478bd9Sstevel@tonic-gate conn_loopback : 1, /* SO_LOOPBACK state */ 1407c478bd9Sstevel@tonic-gate conn_broadcast : 1, /* SO_BROADCAST state */ 1417c478bd9Sstevel@tonic-gate conn_reuseaddr : 1, /* SO_REUSEADDR state */ 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate conn_multicast_loop : 1, /* IP_MULTICAST_LOOP */ 1447c478bd9Sstevel@tonic-gate conn_multi_router : 1, /* Wants all multicast pkts */ 1457c478bd9Sstevel@tonic-gate conn_draining : 1, /* ip_wsrv running */ 1467c478bd9Sstevel@tonic-gate conn_did_putbq : 1, /* ip_wput did a putbq */ 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate conn_unspec_src : 1, /* IP_UNSPEC_SRC */ 1497c478bd9Sstevel@tonic-gate conn_policy_cached : 1, /* Is policy cached/latched ? */ 1507c478bd9Sstevel@tonic-gate conn_in_enforce_policy : 1, /* Enforce Policy on inbound */ 1517c478bd9Sstevel@tonic-gate conn_out_enforce_policy : 1, /* Enforce Policy on outbound */ 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate conn_af_isv6 : 1, /* ip address family ver 6 */ 1547c478bd9Sstevel@tonic-gate conn_pkt_isv6 : 1, /* ip packet format ver 6 */ 1557c478bd9Sstevel@tonic-gate conn_ipv6_recvpktinfo : 1, /* IPV6_RECVPKTINFO option */ 1567c478bd9Sstevel@tonic-gate conn_ipv6_recvhoplimit : 1, /* IPV6_RECVHOPLIMIT option */ 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate conn_ipv6_recvhopopts : 1, /* IPV6_RECVHOPOPTS option */ 1597c478bd9Sstevel@tonic-gate conn_ipv6_recvdstopts : 1, /* IPV6_RECVDSTOPTS option */ 1607c478bd9Sstevel@tonic-gate conn_ipv6_recvrthdr : 1, /* IPV6_RECVRTHDR option */ 1617c478bd9Sstevel@tonic-gate conn_ipv6_recvrtdstopts : 1, /* IPV6_RECVRTHDRDSTOPTS */ 1627c478bd9Sstevel@tonic-gate conn_ipv6_v6only : 1, /* IPV6_V6ONLY */ 1637c478bd9Sstevel@tonic-gate conn_ipv6_recvtclass : 1, /* IPV6_RECVTCLASS */ 1647c478bd9Sstevel@tonic-gate conn_ipv6_recvpathmtu : 1, /* IPV6_RECVPATHMTU */ 1657c478bd9Sstevel@tonic-gate conn_pathmtu_valid : 1, /* The cached mtu is valid. */ 1667c478bd9Sstevel@tonic-gate conn_ipv6_dontfrag : 1, /* IPV6_DONTFRAG */ 1677c478bd9Sstevel@tonic-gate /* 1687c478bd9Sstevel@tonic-gate * This option can take on values in [-1, 1] so we store it 1697c478bd9Sstevel@tonic-gate * +1. Manifest constants IPV6_USE_MIN_MTU_* describe these 1707c478bd9Sstevel@tonic-gate * values. 1717c478bd9Sstevel@tonic-gate */ 1727c478bd9Sstevel@tonic-gate conn_fully_bound : 1, /* Fully bound connection */ 1737c478bd9Sstevel@tonic-gate conn_recvif : 1, /* IP_RECVIF option */ 1747c478bd9Sstevel@tonic-gate conn_recvslla : 1, /* IP_RECVSLLA option */ 1757c478bd9Sstevel@tonic-gate conn_mdt_ok : 1, /* MDT is permitted */ 17643d18f1cSpriyanka conn_nexthop_set : 1, 17743d18f1cSpriyanka pad_to_bit_31 : 1; 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate tcp_t *conn_tcp; /* Pointer to the tcp struct */ 180*d045b987Smasputra struct udp_s *conn_udp; /* Pointer to the udp struct */ 181ff550d0eSmasputra 1827c478bd9Sstevel@tonic-gate squeue_t *conn_sqp; /* Squeue for processing */ 1837c478bd9Sstevel@tonic-gate edesc_rpf conn_recv; /* Pointer to recv routine */ 1847c478bd9Sstevel@tonic-gate void *conn_pad1; 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate ill_t *conn_xmit_if_ill; /* Outbound ill */ 1877c478bd9Sstevel@tonic-gate ill_t *conn_nofailover_ill; /* Failover ill */ 1887c478bd9Sstevel@tonic-gate ipsec_latch_t *conn_latch; /* latched state */ 1897c478bd9Sstevel@tonic-gate ill_t *conn_outgoing_ill; /* IP{,V6}_BOUND_IF */ 1907c478bd9Sstevel@tonic-gate edesc_spf conn_send; /* Pointer to send routine */ 1917c478bd9Sstevel@tonic-gate queue_t *conn_rq; /* Read queue */ 1927c478bd9Sstevel@tonic-gate queue_t *conn_wq; /* Write queue */ 1937c478bd9Sstevel@tonic-gate dev_t conn_dev; /* Minor number */ 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate cred_t *conn_cred; /* Credentials */ 1967c478bd9Sstevel@tonic-gate connf_t *conn_g_fanout; /* Global Hash bucket head */ 1977c478bd9Sstevel@tonic-gate struct conn_s *conn_g_next; /* Global Hash chain next */ 1987c478bd9Sstevel@tonic-gate struct conn_s *conn_g_prev; /* Global Hash chain prev */ 1997c478bd9Sstevel@tonic-gate struct ipsec_policy_head_s *conn_policy; /* Configured policy */ 2007c478bd9Sstevel@tonic-gate in6_addr_t conn_bound_source_v6; 2017c478bd9Sstevel@tonic-gate #define conn_bound_source V4_PART_OF_V6(conn_bound_source_v6) 2027c478bd9Sstevel@tonic-gate void *conn_void[1]; 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate connf_t *conn_fanout; /* Hash bucket we're part of */ 2057c478bd9Sstevel@tonic-gate struct conn_s *conn_next; /* Hash chain next */ 2067c478bd9Sstevel@tonic-gate struct conn_s *conn_prev; /* Hash chain prev */ 2077c478bd9Sstevel@tonic-gate struct { 2087c478bd9Sstevel@tonic-gate in6_addr_t connua_laddr; /* Local address */ 2097c478bd9Sstevel@tonic-gate in6_addr_t connua_faddr; /* Remote address */ 2107c478bd9Sstevel@tonic-gate } connua_v6addr; 2117c478bd9Sstevel@tonic-gate #define conn_src V4_PART_OF_V6(connua_v6addr.connua_laddr) 2127c478bd9Sstevel@tonic-gate #define conn_rem V4_PART_OF_V6(connua_v6addr.connua_faddr) 2137c478bd9Sstevel@tonic-gate #define conn_srcv6 connua_v6addr.connua_laddr 2147c478bd9Sstevel@tonic-gate #define conn_remv6 connua_v6addr.connua_faddr 2157c478bd9Sstevel@tonic-gate union { 2167c478bd9Sstevel@tonic-gate /* Used for classifier match performance */ 2177c478bd9Sstevel@tonic-gate uint32_t conn_ports2; 2187c478bd9Sstevel@tonic-gate struct { 2197c478bd9Sstevel@tonic-gate in_port_t tcpu_fport; /* Remote port */ 2207c478bd9Sstevel@tonic-gate in_port_t tcpu_lport; /* Local port */ 2217c478bd9Sstevel@tonic-gate } tcpu_ports; 2227c478bd9Sstevel@tonic-gate } u_port; 2237c478bd9Sstevel@tonic-gate #define conn_fport u_port.tcpu_ports.tcpu_fport 2247c478bd9Sstevel@tonic-gate #define conn_lport u_port.tcpu_ports.tcpu_lport 2257c478bd9Sstevel@tonic-gate #define conn_ports u_port.conn_ports2 2267c478bd9Sstevel@tonic-gate #define conn_upq conn_rq 2277c478bd9Sstevel@tonic-gate uint8_t conn_ulp; /* protocol type */ 2287c478bd9Sstevel@tonic-gate uint8_t conn_unused_byte; 2297c478bd9Sstevel@tonic-gate kcondvar_t conn_cv; 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate uint_t conn_proto; /* SO_PROTOTYPE state */ 2327c478bd9Sstevel@tonic-gate ill_t *conn_incoming_ill; /* IP{,V6}_BOUND_IF */ 2337c478bd9Sstevel@tonic-gate ill_t *conn_outgoing_pill; /* IP{,V6}_BOUND_PIF */ 2347c478bd9Sstevel@tonic-gate ill_t *conn_oper_pending_ill; /* pending shared ioctl */ 2357c478bd9Sstevel@tonic-gate ill_t *conn_xioctl_pending_ill; /* pending excl ioctl */ 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate /* this is used only when an unbind is in progress.. */ 2387c478bd9Sstevel@tonic-gate struct sq_s *conn_pending_sq; /* waiting for ioctl on sq */ 2397c478bd9Sstevel@tonic-gate ilg_t *conn_ilg; /* Group memberships */ 2407c478bd9Sstevel@tonic-gate int conn_ilg_allocated; /* Number allocated */ 2417c478bd9Sstevel@tonic-gate int conn_ilg_inuse; /* Number currently used */ 2427c478bd9Sstevel@tonic-gate int conn_ilg_walker_cnt; /* No of ilg walkers */ 2437c478bd9Sstevel@tonic-gate /* XXXX get rid of this, once ilg_delete_all is fixed */ 2447c478bd9Sstevel@tonic-gate kcondvar_t conn_refcv; 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate struct ipif_s *conn_multicast_ipif; /* IP_MULTICAST_IF */ 2477c478bd9Sstevel@tonic-gate ill_t *conn_multicast_ill; /* IPV6_MULTICAST_IF */ 2487c478bd9Sstevel@tonic-gate int conn_orig_bound_ifindex; /* BOUND_IF before MOVE */ 2497c478bd9Sstevel@tonic-gate int conn_orig_multicast_ifindex; 2507c478bd9Sstevel@tonic-gate /* IPv6 MC IF before MOVE */ 2517c478bd9Sstevel@tonic-gate int conn_orig_xmit_ifindex; /* IP_XMIT_IF before move */ 2527c478bd9Sstevel@tonic-gate struct conn_s *conn_drain_next; /* Next conn in drain list */ 2537c478bd9Sstevel@tonic-gate struct conn_s *conn_drain_prev; /* Prev conn in drain list */ 2547c478bd9Sstevel@tonic-gate idl_t *conn_idl; /* Ptr to the drain list head */ 2557c478bd9Sstevel@tonic-gate mblk_t *conn_ipsec_opt_mp; /* ipsec option mblk */ 2567c478bd9Sstevel@tonic-gate uint32_t conn_src_preferences; /* prefs for src addr select */ 2577c478bd9Sstevel@tonic-gate /* mtuinfo from IPV6_PACKET_TOO_BIG conditional on conn_pathmtu_valid */ 2587c478bd9Sstevel@tonic-gate struct ip6_mtuinfo mtuinfo; 2597c478bd9Sstevel@tonic-gate zoneid_t conn_zoneid; /* zone connection is in */ 26043d18f1cSpriyanka in6_addr_t conn_nexthop_v6; /* nexthop IP address */ 26143d18f1cSpriyanka #define conn_nexthop_v4 V4_PART_OF_V6(conn_nexthop_v6) 2627c478bd9Sstevel@tonic-gate #ifdef CONN_DEBUG 2637c478bd9Sstevel@tonic-gate #define CONN_TRACE_MAX 10 2647c478bd9Sstevel@tonic-gate int conn_trace_last; /* ndx of last used tracebuf */ 2657c478bd9Sstevel@tonic-gate conn_trace_t conn_trace_buf[CONN_TRACE_MAX]; 2667c478bd9Sstevel@tonic-gate #endif 2677c478bd9Sstevel@tonic-gate }; 2687c478bd9Sstevel@tonic-gate 2697c478bd9Sstevel@tonic-gate /* 2707c478bd9Sstevel@tonic-gate * connf_t - connection fanout data. 2717c478bd9Sstevel@tonic-gate * 2727c478bd9Sstevel@tonic-gate * The hash tables and their linkage (conn_t.{hashnextp, hashprevp} are 2737c478bd9Sstevel@tonic-gate * protected by the per-bucket lock. Each conn_t inserted in the list 2747c478bd9Sstevel@tonic-gate * points back at the connf_t that heads the bucket. 2757c478bd9Sstevel@tonic-gate */ 2767c478bd9Sstevel@tonic-gate 2777c478bd9Sstevel@tonic-gate struct connf_s { 2787c478bd9Sstevel@tonic-gate struct conn_s *connf_head; 2797c478bd9Sstevel@tonic-gate kmutex_t connf_lock; 2807c478bd9Sstevel@tonic-gate }; 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate #define CONN_INC_REF(connp) { \ 2837c478bd9Sstevel@tonic-gate DTRACE_PROBE1(conn__inc__ref, conn_t *, connp); \ 2847c478bd9Sstevel@tonic-gate mutex_enter(&(connp)->conn_lock); \ 2857c478bd9Sstevel@tonic-gate ASSERT(conn_trace_ref(connp)); \ 2867c478bd9Sstevel@tonic-gate (connp)->conn_ref++; \ 2877c478bd9Sstevel@tonic-gate ASSERT((connp)->conn_ref != 0); \ 2887c478bd9Sstevel@tonic-gate mutex_exit(&(connp)->conn_lock); \ 2897c478bd9Sstevel@tonic-gate } 2907c478bd9Sstevel@tonic-gate 2917c478bd9Sstevel@tonic-gate #define CONN_INC_REF_LOCKED(connp) { \ 2927c478bd9Sstevel@tonic-gate DTRACE_PROBE1(conn__inc__ref, conn_t *, connp); \ 2937c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&(connp)->conn_lock)); \ 2947c478bd9Sstevel@tonic-gate ASSERT(conn_trace_ref(connp)); \ 2957c478bd9Sstevel@tonic-gate (connp)->conn_ref++; \ 2967c478bd9Sstevel@tonic-gate ASSERT((connp)->conn_ref != 0); \ 2977c478bd9Sstevel@tonic-gate } 2987c478bd9Sstevel@tonic-gate 2997c478bd9Sstevel@tonic-gate #define CONN_DEC_REF(connp) { \ 3007c478bd9Sstevel@tonic-gate DTRACE_PROBE1(conn__dec__ref, conn_t *, connp); \ 3017c478bd9Sstevel@tonic-gate mutex_enter(&(connp)->conn_lock); \ 3027c478bd9Sstevel@tonic-gate if ((connp)->conn_ref <= 0) \ 3037c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "CONN_DEC_REF: connp(%p) has ref " \ 3047c478bd9Sstevel@tonic-gate "= %d\n", (void *)(connp), (connp)->conn_ref); \ 3057c478bd9Sstevel@tonic-gate ASSERT(conn_untrace_ref(connp)); \ 3067c478bd9Sstevel@tonic-gate (connp)->conn_ref--; \ 3077c478bd9Sstevel@tonic-gate if ((connp)->conn_ref == 0) { \ 3087c478bd9Sstevel@tonic-gate /* Refcnt can't increase again, safe to drop lock */ \ 3097c478bd9Sstevel@tonic-gate mutex_exit(&(connp)->conn_lock); \ 3107c478bd9Sstevel@tonic-gate ipcl_conn_destroy(connp); \ 3117c478bd9Sstevel@tonic-gate } else { \ 3127c478bd9Sstevel@tonic-gate cv_broadcast(&(connp)->conn_cv); \ 3137c478bd9Sstevel@tonic-gate mutex_exit(&(connp)->conn_lock); \ 3147c478bd9Sstevel@tonic-gate } \ 3157c478bd9Sstevel@tonic-gate } 3167c478bd9Sstevel@tonic-gate 3177c478bd9Sstevel@tonic-gate #define _IPCL_V4_MATCH(v6addr, v4addr) \ 3187c478bd9Sstevel@tonic-gate (V4_PART_OF_V6((v6addr)) == (v4addr) && IN6_IS_ADDR_V4MAPPED(&(v6addr))) 3197c478bd9Sstevel@tonic-gate 3207c478bd9Sstevel@tonic-gate #define _IPCL_V4_MATCH_ANY(addr) \ 3217c478bd9Sstevel@tonic-gate (IN6_IS_ADDR_V4MAPPED_ANY(&(addr)) || IN6_IS_ADDR_UNSPECIFIED(&(addr))) 3227c478bd9Sstevel@tonic-gate 3237c478bd9Sstevel@tonic-gate /* 3247c478bd9Sstevel@tonic-gate * IPCL_PROTO_MATCH() only matches conns with the specified zoneid, while 3257c478bd9Sstevel@tonic-gate * IPCL_PROTO_MATCH_V6() can match other conns in the multicast case, see 3267c478bd9Sstevel@tonic-gate * ip_fanout_proto(). 3277c478bd9Sstevel@tonic-gate */ 3287c478bd9Sstevel@tonic-gate #define IPCL_PROTO_MATCH(connp, protocol, ipha, ill, \ 3297c478bd9Sstevel@tonic-gate fanout_flags, zoneid) \ 3307c478bd9Sstevel@tonic-gate ((((connp)->conn_src == INADDR_ANY) || \ 3317c478bd9Sstevel@tonic-gate (((connp)->conn_src == ((ipha)->ipha_dst)) && \ 3327c478bd9Sstevel@tonic-gate (((connp)->conn_rem == INADDR_ANY) || \ 3337c478bd9Sstevel@tonic-gate ((connp)->conn_rem == ((ipha)->ipha_src))))) && \ 3347c478bd9Sstevel@tonic-gate ((connp)->conn_zoneid == (zoneid)) && \ 3357c478bd9Sstevel@tonic-gate (conn_wantpacket((connp), (ill), (ipha), \ 3367c478bd9Sstevel@tonic-gate (fanout_flags), (zoneid)) || ((protocol) == IPPROTO_PIM) || \ 3377c478bd9Sstevel@tonic-gate ((protocol) == IPPROTO_RSVP))) 3387c478bd9Sstevel@tonic-gate 3397c478bd9Sstevel@tonic-gate #define IPCL_PROTO_MATCH_V6(connp, protocol, ip6h, ill, \ 3407c478bd9Sstevel@tonic-gate fanout_flags, zoneid) \ 3417c478bd9Sstevel@tonic-gate ((IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_srcv6) || \ 3427c478bd9Sstevel@tonic-gate (IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &((ip6h)->ip6_dst)) && \ 3437c478bd9Sstevel@tonic-gate (IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_remv6) || \ 3447c478bd9Sstevel@tonic-gate IN6_ARE_ADDR_EQUAL(&(connp)->conn_remv6, &((ip6h)->ip6_src))))) && \ 3457c478bd9Sstevel@tonic-gate (conn_wantpacket_v6((connp), (ill), (ip6h), \ 3467c478bd9Sstevel@tonic-gate (fanout_flags), (zoneid)) || ((protocol) == IPPROTO_RSVP))) 3477c478bd9Sstevel@tonic-gate 3487c478bd9Sstevel@tonic-gate #define IPCL_CONN_HASH(src, ports) \ 3497c478bd9Sstevel@tonic-gate ((unsigned)(ntohl((src)) ^ ((ports) >> 24) ^ ((ports) >> 16) ^ \ 3507c478bd9Sstevel@tonic-gate ((ports) >> 8) ^ (ports)) % ipcl_conn_fanout_size) 3517c478bd9Sstevel@tonic-gate 3527c478bd9Sstevel@tonic-gate #define IPCL_CONN_HASH_V6(src, ports) \ 3537c478bd9Sstevel@tonic-gate IPCL_CONN_HASH(V4_PART_OF_V6((src)), (ports)) 3547c478bd9Sstevel@tonic-gate 3557c478bd9Sstevel@tonic-gate #define IPCL_CONN_MATCH(connp, proto, src, dst, ports) \ 3567c478bd9Sstevel@tonic-gate ((connp)->conn_ulp == (proto) && \ 3577c478bd9Sstevel@tonic-gate (connp)->conn_ports == (ports) && \ 3587c478bd9Sstevel@tonic-gate _IPCL_V4_MATCH((connp)->conn_remv6, (src)) && \ 3597c478bd9Sstevel@tonic-gate _IPCL_V4_MATCH((connp)->conn_srcv6, (dst)) && \ 3607c478bd9Sstevel@tonic-gate !(connp)->conn_ipv6_v6only) 3617c478bd9Sstevel@tonic-gate 3627c478bd9Sstevel@tonic-gate #define IPCL_CONN_MATCH_V6(connp, proto, src, dst, ports) \ 3637c478bd9Sstevel@tonic-gate ((connp)->conn_ulp == (proto) && \ 3647c478bd9Sstevel@tonic-gate (connp)->conn_ports == (ports) && \ 3657c478bd9Sstevel@tonic-gate IN6_ARE_ADDR_EQUAL(&(connp)->conn_remv6, &(src)) && \ 3667c478bd9Sstevel@tonic-gate IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &(dst))) 3677c478bd9Sstevel@tonic-gate 3687c478bd9Sstevel@tonic-gate #define IPCL_CONN_INIT(connp, protocol, src, rem, ports) { \ 3697c478bd9Sstevel@tonic-gate (connp)->conn_ulp = protocol; \ 3707c478bd9Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(src, &(connp)->conn_srcv6); \ 3717c478bd9Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(rem, &(connp)->conn_remv6); \ 3727c478bd9Sstevel@tonic-gate (connp)->conn_ports = ports; \ 3737c478bd9Sstevel@tonic-gate } 3747c478bd9Sstevel@tonic-gate 3757c478bd9Sstevel@tonic-gate #define IPCL_CONN_INIT_V6(connp, protocol, src, rem, ports) { \ 3767c478bd9Sstevel@tonic-gate (connp)->conn_ulp = protocol; \ 3777c478bd9Sstevel@tonic-gate (connp)->conn_srcv6 = src; \ 3787c478bd9Sstevel@tonic-gate (connp)->conn_remv6 = rem; \ 3797c478bd9Sstevel@tonic-gate (connp)->conn_ports = ports; \ 3807c478bd9Sstevel@tonic-gate } 3817c478bd9Sstevel@tonic-gate 3827c478bd9Sstevel@tonic-gate #define IPCL_BIND_HASH(lport) \ 3837c478bd9Sstevel@tonic-gate ((unsigned)(((lport) >> 8) ^ (lport)) % ipcl_bind_fanout_size) 3847c478bd9Sstevel@tonic-gate 3857c478bd9Sstevel@tonic-gate #define IPCL_BIND_MATCH(connp, proto, laddr, lport) \ 3867c478bd9Sstevel@tonic-gate ((connp)->conn_ulp == (proto) && \ 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 !(connp)->conn_ipv6_v6only) 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate #define IPCL_BIND_MATCH_V6(connp, proto, laddr, lport) \ 3937c478bd9Sstevel@tonic-gate ((connp)->conn_ulp == (proto) && \ 3947c478bd9Sstevel@tonic-gate (connp)->conn_lport == (lport) && \ 3957c478bd9Sstevel@tonic-gate (IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &(laddr)) || \ 3967c478bd9Sstevel@tonic-gate IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_srcv6))) 3977c478bd9Sstevel@tonic-gate 3987c478bd9Sstevel@tonic-gate #define IPCL_UDP_MATCH(connp, lport, laddr, fport, faddr) \ 3997c478bd9Sstevel@tonic-gate (((connp)->conn_lport == (lport)) && \ 4007c478bd9Sstevel@tonic-gate ((_IPCL_V4_MATCH_ANY((connp)->conn_srcv6) || \ 4017c478bd9Sstevel@tonic-gate (_IPCL_V4_MATCH((connp)->conn_srcv6, (laddr)) && \ 4027c478bd9Sstevel@tonic-gate (_IPCL_V4_MATCH_ANY((connp)->conn_remv6) || \ 4037c478bd9Sstevel@tonic-gate (_IPCL_V4_MATCH((connp)->conn_remv6, (faddr)) && \ 4047c478bd9Sstevel@tonic-gate (connp)->conn_fport == (fport)))))) && \ 4057c478bd9Sstevel@tonic-gate !(connp)->conn_ipv6_v6only) 4067c478bd9Sstevel@tonic-gate 4077c478bd9Sstevel@tonic-gate #define IPCL_UDP_MATCH_V6(connp, lport, laddr, fport, faddr) \ 4087c478bd9Sstevel@tonic-gate (((connp)->conn_lport == (lport)) && \ 4097c478bd9Sstevel@tonic-gate (IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_srcv6) || \ 4107c478bd9Sstevel@tonic-gate (IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &(laddr)) && \ 4117c478bd9Sstevel@tonic-gate (IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_remv6) || \ 4127c478bd9Sstevel@tonic-gate (IN6_ARE_ADDR_EQUAL(&(connp)->conn_remv6, &(faddr)) && \ 4137c478bd9Sstevel@tonic-gate (connp)->conn_fport == (fport)))))) 4147c478bd9Sstevel@tonic-gate 4157c478bd9Sstevel@tonic-gate #define IPCL_TCP_EAGER_INIT(connp, protocol, src, rem, ports) { \ 4167c478bd9Sstevel@tonic-gate (connp)->conn_flags |= (IPCL_TCP4|IPCL_EAGER); \ 4177c478bd9Sstevel@tonic-gate (connp)->conn_ulp = protocol; \ 4187c478bd9Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(src, &(connp)->conn_srcv6); \ 4197c478bd9Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(rem, &(connp)->conn_remv6); \ 4207c478bd9Sstevel@tonic-gate (connp)->conn_ports = ports; \ 4217c478bd9Sstevel@tonic-gate (connp)->conn_send = ip_output; \ 4227c478bd9Sstevel@tonic-gate (connp)->conn_sqp = IP_SQUEUE_GET(lbolt); \ 4237c478bd9Sstevel@tonic-gate } 4247c478bd9Sstevel@tonic-gate 4257c478bd9Sstevel@tonic-gate #define IPCL_TCP_EAGER_INIT_V6(connp, protocol, src, rem, ports) { \ 4267c478bd9Sstevel@tonic-gate (connp)->conn_flags |= (IPCL_TCP6|IPCL_EAGER); \ 4277c478bd9Sstevel@tonic-gate (connp)->conn_ulp = protocol; \ 4287c478bd9Sstevel@tonic-gate (connp)->conn_srcv6 = src; \ 4297c478bd9Sstevel@tonic-gate (connp)->conn_remv6 = rem; \ 4307c478bd9Sstevel@tonic-gate (connp)->conn_ports = ports; \ 4317c478bd9Sstevel@tonic-gate (connp)->conn_send = ip_output_v6; \ 4327c478bd9Sstevel@tonic-gate (connp)->conn_sqp = IP_SQUEUE_GET(lbolt); \ 4337c478bd9Sstevel@tonic-gate } 4347c478bd9Sstevel@tonic-gate 4357c478bd9Sstevel@tonic-gate #define ipcl_proto_search(protocol) \ 4367c478bd9Sstevel@tonic-gate (ipcl_proto_fanout[(protocol)].connf_head) 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN 4397c478bd9Sstevel@tonic-gate #define IPCL_UDP_HASH(port) ((port) & 0xFF) 4407c478bd9Sstevel@tonic-gate #else /* _BIG_ENDIAN */ 4417c478bd9Sstevel@tonic-gate #define IPCL_UDP_HASH(port) (((uint16_t)(port)) >> 8) 4427c478bd9Sstevel@tonic-gate #endif /* _BIG_ENDIAN */ 4437c478bd9Sstevel@tonic-gate 4447c478bd9Sstevel@tonic-gate #define CONN_G_HASH_SIZE 1024 4457c478bd9Sstevel@tonic-gate 4467c478bd9Sstevel@tonic-gate /* Raw socket hash function. */ 4477c478bd9Sstevel@tonic-gate #define IPCL_RAW_HASH(lport) (((lport) * 31) & (ipcl_raw_fanout_size - 1)) 4487c478bd9Sstevel@tonic-gate 4497c0c0508Skcpoon /* 4507c0c0508Skcpoon * This is similar to IPCL_BIND_MATCH except that the local port check 4517c0c0508Skcpoon * is changed to a wildcard port check. 4527c0c0508Skcpoon */ 4537c0c0508Skcpoon #define IPCL_RAW_MATCH(connp, proto, laddr) \ 4547c0c0508Skcpoon ((connp)->conn_ulp == (proto) && \ 4557c0c0508Skcpoon (connp)->conn_lport == 0 && \ 4567c0c0508Skcpoon (_IPCL_V4_MATCH_ANY((connp)->conn_srcv6) || \ 4577c0c0508Skcpoon _IPCL_V4_MATCH((connp)->conn_srcv6, (laddr)))) 4587c0c0508Skcpoon 4597c0c0508Skcpoon #define IPCL_RAW_MATCH_V6(connp, proto, laddr) \ 4607c0c0508Skcpoon ((connp)->conn_ulp == (proto) && \ 4617c0c0508Skcpoon (connp)->conn_lport == 0 && \ 4627c0c0508Skcpoon (IN6_IS_ADDR_UNSPECIFIED(&(connp)->conn_srcv6) || \ 4637c0c0508Skcpoon IN6_ARE_ADDR_EQUAL(&(connp)->conn_srcv6, &(laddr)))) 4647c0c0508Skcpoon 4657c478bd9Sstevel@tonic-gate /* hash tables */ 4667c478bd9Sstevel@tonic-gate extern connf_t rts_clients; 4677c478bd9Sstevel@tonic-gate extern connf_t *ipcl_conn_fanout; 4687c478bd9Sstevel@tonic-gate extern connf_t *ipcl_bind_fanout; 4697c478bd9Sstevel@tonic-gate extern connf_t ipcl_proto_fanout[IPPROTO_MAX + 1]; 4707c478bd9Sstevel@tonic-gate extern connf_t ipcl_proto_fanout_v6[IPPROTO_MAX + 1]; 4717c478bd9Sstevel@tonic-gate extern connf_t *ipcl_udp_fanout; 4727c478bd9Sstevel@tonic-gate extern connf_t *ipcl_globalhash_fanout; 4737c478bd9Sstevel@tonic-gate extern connf_t *ipcl_raw_fanout; 4747c478bd9Sstevel@tonic-gate extern uint_t ipcl_conn_fanout_size; 4757c478bd9Sstevel@tonic-gate extern uint_t ipcl_bind_fanout_size; 4767c478bd9Sstevel@tonic-gate extern uint_t ipcl_udp_fanout_size; 4777c478bd9Sstevel@tonic-gate extern uint_t ipcl_raw_fanout_size; 4787c478bd9Sstevel@tonic-gate 4797c478bd9Sstevel@tonic-gate /* Function prototypes */ 4807c478bd9Sstevel@tonic-gate extern void ipcl_init(void); 4817c478bd9Sstevel@tonic-gate extern void ipcl_destroy(void); 4827c478bd9Sstevel@tonic-gate extern conn_t *ipcl_conn_create(uint32_t, int); 4837c478bd9Sstevel@tonic-gate extern void ipcl_conn_destroy(conn_t *); 4847c478bd9Sstevel@tonic-gate 4857c478bd9Sstevel@tonic-gate void ipcl_hash_insert_connected(connf_t *, conn_t *); 4867c478bd9Sstevel@tonic-gate void ipcl_hash_insert_bound(connf_t *, conn_t *); 4877c478bd9Sstevel@tonic-gate void ipcl_hash_insert_wildcard(connf_t *, conn_t *); 4887c478bd9Sstevel@tonic-gate void ipcl_hash_remove(conn_t *); 4897c478bd9Sstevel@tonic-gate void ipcl_hash_remove_locked(conn_t *connp, connf_t *connfp); 4907c478bd9Sstevel@tonic-gate 4917c478bd9Sstevel@tonic-gate extern int ipcl_bind_insert(conn_t *, uint8_t, ipaddr_t, uint16_t); 4927c478bd9Sstevel@tonic-gate extern int ipcl_bind_insert_v6(conn_t *, uint8_t, const in6_addr_t *, 4937c478bd9Sstevel@tonic-gate uint16_t); 4947c478bd9Sstevel@tonic-gate extern int ipcl_conn_insert(conn_t *, uint8_t, ipaddr_t, ipaddr_t, 4957c478bd9Sstevel@tonic-gate uint32_t); 4967c478bd9Sstevel@tonic-gate extern int ipcl_conn_insert_v6(conn_t *, uint8_t, const in6_addr_t *, 4977c478bd9Sstevel@tonic-gate const in6_addr_t *, uint32_t, uint_t); 498ff550d0eSmasputra extern conn_t *ipcl_get_next_conn(connf_t *, conn_t *, uint32_t); 4997c478bd9Sstevel@tonic-gate 5007c478bd9Sstevel@tonic-gate void ipcl_proto_insert(conn_t *, uint8_t); 5017c478bd9Sstevel@tonic-gate void ipcl_proto_insert_v6(conn_t *, uint8_t); 5027c478bd9Sstevel@tonic-gate conn_t *ipcl_classify_v4(mblk_t *, uint8_t, uint_t, zoneid_t); 5037c478bd9Sstevel@tonic-gate conn_t *ipcl_classify_v6(mblk_t *, uint8_t, uint_t, zoneid_t); 5047c478bd9Sstevel@tonic-gate conn_t *ipcl_classify(mblk_t *, zoneid_t); 5057c478bd9Sstevel@tonic-gate conn_t *ipcl_classify_raw(uint8_t, zoneid_t, uint32_t, ipha_t *); 5067c478bd9Sstevel@tonic-gate void ipcl_globalhash_insert(conn_t *); 5077c478bd9Sstevel@tonic-gate void ipcl_globalhash_remove(conn_t *); 5087c478bd9Sstevel@tonic-gate void ipcl_walk(pfv_t, void *); 5097c478bd9Sstevel@tonic-gate conn_t *ipcl_tcp_lookup_reversed_ipv4(ipha_t *, tcph_t *, int); 5107c478bd9Sstevel@tonic-gate conn_t *ipcl_tcp_lookup_reversed_ipv6(ip6_t *, tcpha_t *, int, uint_t); 5117c478bd9Sstevel@tonic-gate conn_t *ipcl_lookup_listener_v4(uint16_t, ipaddr_t, zoneid_t); 5127c478bd9Sstevel@tonic-gate conn_t *ipcl_lookup_listener_v6(uint16_t, in6_addr_t *, uint_t, zoneid_t); 5137c478bd9Sstevel@tonic-gate int conn_trace_ref(conn_t *); 5147c478bd9Sstevel@tonic-gate int conn_untrace_ref(conn_t *); 5157c478bd9Sstevel@tonic-gate conn_t *ipcl_conn_tcp_lookup_reversed_ipv4(conn_t *, ipha_t *, tcph_t *); 5167c478bd9Sstevel@tonic-gate conn_t *ipcl_conn_tcp_lookup_reversed_ipv6(conn_t *, ip6_t *, tcph_t *); 5177c478bd9Sstevel@tonic-gate #ifdef __cplusplus 5187c478bd9Sstevel@tonic-gate } 5197c478bd9Sstevel@tonic-gate #endif 5207c478bd9Sstevel@tonic-gate 5217c478bd9Sstevel@tonic-gate #endif /* _INET_IPCLASSIFIER_H */ 522