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