10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51213Skcpoon * Common Development and Distribution License (the "License"). 61213Skcpoon * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 211213Skcpoon 220Sstevel@tonic-gate /* 23*3448Sdh155122 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <sys/types.h> 300Sstevel@tonic-gate #include <sys/stream.h> 310Sstevel@tonic-gate #include <sys/strsubr.h> 320Sstevel@tonic-gate #include <sys/stropts.h> 330Sstevel@tonic-gate #include <sys/strsun.h> 340Sstevel@tonic-gate #define _SUN_TPI_VERSION 2 350Sstevel@tonic-gate #include <sys/tihdr.h> 360Sstevel@tonic-gate #include <sys/ddi.h> 370Sstevel@tonic-gate #include <sys/sunddi.h> 380Sstevel@tonic-gate #include <sys/xti_inet.h> 390Sstevel@tonic-gate #include <sys/cmn_err.h> 400Sstevel@tonic-gate #include <sys/debug.h> 410Sstevel@tonic-gate #include <sys/vtrace.h> 420Sstevel@tonic-gate #include <sys/kmem.h> 430Sstevel@tonic-gate #include <sys/cpuvar.h> 440Sstevel@tonic-gate #include <sys/random.h> 451676Sjpk #include <sys/priv.h> 46*3448Sdh155122 #include <sys/sunldi.h> 470Sstevel@tonic-gate 480Sstevel@tonic-gate #include <sys/errno.h> 490Sstevel@tonic-gate #include <sys/signal.h> 500Sstevel@tonic-gate #include <sys/socket.h> 510Sstevel@tonic-gate #include <sys/isa_defs.h> 520Sstevel@tonic-gate #include <netinet/in.h> 530Sstevel@tonic-gate #include <netinet/tcp.h> 540Sstevel@tonic-gate #include <netinet/ip6.h> 550Sstevel@tonic-gate #include <netinet/icmp6.h> 560Sstevel@tonic-gate #include <netinet/sctp.h> 570Sstevel@tonic-gate #include <net/if.h> 580Sstevel@tonic-gate 590Sstevel@tonic-gate #include <inet/common.h> 600Sstevel@tonic-gate #include <inet/ip.h> 610Sstevel@tonic-gate #include <inet/ip6.h> 620Sstevel@tonic-gate #include <inet/mi.h> 630Sstevel@tonic-gate #include <inet/mib2.h> 64*3448Sdh155122 #include <inet/kstatcom.h> 650Sstevel@tonic-gate #include <inet/nd.h> 660Sstevel@tonic-gate #include <inet/optcom.h> 670Sstevel@tonic-gate #include <inet/ipclassifier.h> 680Sstevel@tonic-gate #include <inet/ipsec_impl.h> 690Sstevel@tonic-gate #include <inet/sctp_ip.h> 700Sstevel@tonic-gate #include <inet/sctp_crc32.h> 710Sstevel@tonic-gate 720Sstevel@tonic-gate #include "sctp_impl.h" 730Sstevel@tonic-gate #include "sctp_addr.h" 74852Svi117747 #include "sctp_asconf.h" 750Sstevel@tonic-gate 760Sstevel@tonic-gate extern major_t SCTP6_MAJ; 770Sstevel@tonic-gate extern major_t SCTP_MAJ; 780Sstevel@tonic-gate 790Sstevel@tonic-gate int sctpdebug; 800Sstevel@tonic-gate sin6_t sctp_sin6_null; /* Zero address for quick clears */ 810Sstevel@tonic-gate 82*3448Sdh155122 /* 83*3448Sdh155122 * Have to ensure that sctp_g_q_close is not done by an 84*3448Sdh155122 * interrupt thread. 85*3448Sdh155122 */ 86*3448Sdh155122 static taskq_t *sctp_taskq; 870Sstevel@tonic-gate 880Sstevel@tonic-gate static void sctp_closei_local(sctp_t *sctp); 890Sstevel@tonic-gate static int sctp_init_values(sctp_t *, sctp_t *, int); 900Sstevel@tonic-gate static void sctp_icmp_error_ipv6(sctp_t *sctp, mblk_t *mp); 910Sstevel@tonic-gate static void sctp_process_recvq(void *); 92*3448Sdh155122 static void sctp_rq_tq_init(sctp_stack_t *); 93*3448Sdh155122 static void sctp_rq_tq_fini(sctp_stack_t *); 940Sstevel@tonic-gate static void sctp_conn_cache_init(); 950Sstevel@tonic-gate static void sctp_conn_cache_fini(); 960Sstevel@tonic-gate static int sctp_conn_cache_constructor(); 970Sstevel@tonic-gate static void sctp_conn_cache_destructor(); 98*3448Sdh155122 void sctp_g_q_setup(sctp_stack_t *); 99*3448Sdh155122 void sctp_g_q_create(sctp_stack_t *); 100*3448Sdh155122 void sctp_g_q_destroy(sctp_stack_t *); 101*3448Sdh155122 102*3448Sdh155122 static void *sctp_stack_init(netstackid_t stackid, netstack_t *ns); 103*3448Sdh155122 static void sctp_stack_shutdown(netstackid_t stackid, void *arg); 104*3448Sdh155122 static void sctp_stack_fini(netstackid_t stackid, void *arg); 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate /* 1070Sstevel@tonic-gate * SCTP receive queue taskq 1080Sstevel@tonic-gate * 1090Sstevel@tonic-gate * At SCTP initialization time, a default taskq is created for 1100Sstevel@tonic-gate * servicing packets received when the interrupt thread cannot 1110Sstevel@tonic-gate * get a hold on the sctp_t. The number of taskq can be increased in 1120Sstevel@tonic-gate * sctp_find_next_tq() when an existing taskq cannot be dispatched. 1130Sstevel@tonic-gate * The taskqs are never removed. But the max number of taskq which 1140Sstevel@tonic-gate * can be created is controlled by sctp_recvq_tq_list_max_sz. Note 1150Sstevel@tonic-gate * that SCTP recvq taskq is not tied to any specific CPU or ill. 1160Sstevel@tonic-gate * 1170Sstevel@tonic-gate * Those taskqs are stored in an array recvq_tq_list. And they are 1180Sstevel@tonic-gate * used in a round robin fashion. The current taskq being used is 1190Sstevel@tonic-gate * determined by recvq_tq_list_cur. 1200Sstevel@tonic-gate */ 1210Sstevel@tonic-gate 122*3448Sdh155122 /* /etc/system variables */ 1230Sstevel@tonic-gate /* The minimum number of threads for each taskq. */ 1240Sstevel@tonic-gate int sctp_recvq_tq_thr_min = 4; 1250Sstevel@tonic-gate /* The maximum number of threads for each taskq. */ 1260Sstevel@tonic-gate int sctp_recvq_tq_thr_max = 16; 1270Sstevel@tonic-gate /* The minimum number of tasks for each taskq. */ 1280Sstevel@tonic-gate int sctp_recvq_tq_task_min = 5; 1290Sstevel@tonic-gate /* The maxiimum number of tasks for each taskq. */ 1300Sstevel@tonic-gate int sctp_recvq_tq_task_max = 50; 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate /* sctp_t/conn_t kmem cache */ 1330Sstevel@tonic-gate struct kmem_cache *sctp_conn_cache; 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate #define SCTP_CONDEMNED(sctp) \ 1360Sstevel@tonic-gate mutex_enter(&(sctp)->sctp_reflock); \ 1370Sstevel@tonic-gate ((sctp)->sctp_condemned = B_TRUE); \ 1381213Skcpoon mutex_exit(&(sctp)->sctp_reflock); 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate /* Link/unlink a sctp_t to/from the global list. */ 141*3448Sdh155122 #define SCTP_LINK(sctp, sctps) \ 142*3448Sdh155122 mutex_enter(&(sctps)->sctps_g_lock); \ 143*3448Sdh155122 list_insert_tail(&sctps->sctps_g_list, (sctp)); \ 144*3448Sdh155122 mutex_exit(&(sctps)->sctps_g_lock); 1450Sstevel@tonic-gate 146*3448Sdh155122 #define SCTP_UNLINK(sctp, sctps) \ 147*3448Sdh155122 mutex_enter(&(sctps)->sctps_g_lock); \ 1480Sstevel@tonic-gate ASSERT((sctp)->sctp_condemned); \ 149*3448Sdh155122 list_remove(&(sctps)->sctps_g_list, (sctp)); \ 150*3448Sdh155122 mutex_exit(&(sctps)->sctps_g_lock); 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate /* 153852Svi117747 * Hooks for Sun Cluster. On non-clustered nodes these will remain NULL. 154852Svi117747 * PSARC/2005/602. 155852Svi117747 */ 156852Svi117747 void (*cl_sctp_listen)(sa_family_t, uchar_t *, uint_t, in_port_t) = NULL; 157852Svi117747 void (*cl_sctp_unlisten)(sa_family_t, uchar_t *, uint_t, in_port_t) = NULL; 158852Svi117747 void (*cl_sctp_connect)(sa_family_t, uchar_t *, uint_t, in_port_t, 159852Svi117747 uchar_t *, uint_t, in_port_t, boolean_t, cl_sctp_handle_t) = NULL; 160852Svi117747 void (*cl_sctp_disconnect)(sa_family_t, cl_sctp_handle_t) = NULL; 161852Svi117747 void (*cl_sctp_assoc_change)(sa_family_t, uchar_t *, size_t, uint_t, 162852Svi117747 uchar_t *, size_t, uint_t, int, cl_sctp_handle_t) = NULL; 163852Svi117747 void (*cl_sctp_check_addrs)(sa_family_t, in_port_t, uchar_t **, size_t, 164852Svi117747 uint_t *, boolean_t) = NULL; 165852Svi117747 /* 1660Sstevel@tonic-gate * Return the version number of the SCTP kernel interface. 1670Sstevel@tonic-gate */ 1680Sstevel@tonic-gate int 1690Sstevel@tonic-gate sctp_itf_ver(int cl_ver) 1700Sstevel@tonic-gate { 1710Sstevel@tonic-gate if (cl_ver != SCTP_ITF_VER) 1720Sstevel@tonic-gate return (-1); 1730Sstevel@tonic-gate return (SCTP_ITF_VER); 1740Sstevel@tonic-gate } 1750Sstevel@tonic-gate 1760Sstevel@tonic-gate /* 1770Sstevel@tonic-gate * Called when we need a new sctp instantiation but don't really have a 1780Sstevel@tonic-gate * new q to hang it off of. Copy the priv flag from the passed in structure. 1790Sstevel@tonic-gate */ 1800Sstevel@tonic-gate sctp_t * 1810Sstevel@tonic-gate sctp_create_eager(sctp_t *psctp) 1820Sstevel@tonic-gate { 1830Sstevel@tonic-gate sctp_t *sctp; 1840Sstevel@tonic-gate mblk_t *ack_mp, *hb_mp; 1850Sstevel@tonic-gate conn_t *connp, *pconnp; 1861676Sjpk cred_t *credp; 187*3448Sdh155122 sctp_stack_t *sctps = psctp->sctp_sctps; 1880Sstevel@tonic-gate 189*3448Sdh155122 if ((connp = ipcl_conn_create(IPCL_SCTPCONN, KM_NOSLEEP, 190*3448Sdh155122 sctps->sctps_netstack)) == NULL) { 1910Sstevel@tonic-gate return (NULL); 192*3448Sdh155122 } 1931676Sjpk 1941676Sjpk connp->conn_ulp_labeled = is_system_labeled(); 1951676Sjpk 1960Sstevel@tonic-gate sctp = CONN2SCTP(connp); 197*3448Sdh155122 sctp->sctp_sctps = sctps; 1980Sstevel@tonic-gate 1990Sstevel@tonic-gate if ((ack_mp = sctp_timer_alloc(sctp, sctp_ack_timer)) == NULL || 2000Sstevel@tonic-gate (hb_mp = sctp_timer_alloc(sctp, sctp_heartbeat_timer)) == NULL) { 2010Sstevel@tonic-gate if (ack_mp != NULL) 2020Sstevel@tonic-gate freeb(ack_mp); 203*3448Sdh155122 netstack_rele(sctps->sctps_netstack); 204*3448Sdh155122 connp->conn_netstack = NULL; 205*3448Sdh155122 sctp->sctp_sctps = NULL; 206*3448Sdh155122 SCTP_G_Q_REFRELE(sctps); 2070Sstevel@tonic-gate kmem_cache_free(sctp_conn_cache, connp); 2080Sstevel@tonic-gate return (NULL); 2090Sstevel@tonic-gate } 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate sctp->sctp_ack_mp = ack_mp; 2120Sstevel@tonic-gate sctp->sctp_heartbeat_mp = hb_mp; 2130Sstevel@tonic-gate 2140Sstevel@tonic-gate /* Inherit information from the "parent" */ 2150Sstevel@tonic-gate sctp->sctp_ipversion = psctp->sctp_ipversion; 2160Sstevel@tonic-gate sctp->sctp_family = psctp->sctp_family; 2170Sstevel@tonic-gate pconnp = psctp->sctp_connp; 2180Sstevel@tonic-gate connp->conn_af_isv6 = pconnp->conn_af_isv6; 2190Sstevel@tonic-gate connp->conn_pkt_isv6 = pconnp->conn_pkt_isv6; 2200Sstevel@tonic-gate connp->conn_ipv6_v6only = pconnp->conn_ipv6_v6only; 2210Sstevel@tonic-gate if (sctp_init_values(sctp, psctp, KM_NOSLEEP) != 0) { 2220Sstevel@tonic-gate freeb(ack_mp); 2230Sstevel@tonic-gate freeb(hb_mp); 224*3448Sdh155122 netstack_rele(sctps->sctps_netstack); 225*3448Sdh155122 connp->conn_netstack = NULL; 226*3448Sdh155122 sctp->sctp_sctps = NULL; 227*3448Sdh155122 SCTP_G_Q_REFRELE(sctps); 2280Sstevel@tonic-gate kmem_cache_free(sctp_conn_cache, connp); 2290Sstevel@tonic-gate return (NULL); 2300Sstevel@tonic-gate } 2311676Sjpk 2321676Sjpk /* 2331676Sjpk * If the parent is multilevel, then we'll fix up the remote cred 2341676Sjpk * when we do sctp_accept_comm. 2351676Sjpk */ 2361676Sjpk if ((credp = pconnp->conn_cred) != NULL) { 2371676Sjpk connp->conn_cred = credp; 2381676Sjpk crhold(credp); 2391676Sjpk /* 2401676Sjpk * If the caller has the process-wide flag set, then default to 2411676Sjpk * MAC exempt mode. This allows read-down to unlabeled hosts. 2421676Sjpk */ 2431676Sjpk if (getpflags(NET_MAC_AWARE, credp) != 0) 2441676Sjpk connp->conn_mac_exempt = B_TRUE; 2450Sstevel@tonic-gate } 2462263Ssommerfe 2472263Ssommerfe connp->conn_allzones = pconnp->conn_allzones; 2482263Ssommerfe connp->conn_zoneid = pconnp->conn_zoneid; 2492263Ssommerfe 2500Sstevel@tonic-gate sctp->sctp_mss = psctp->sctp_mss; 2510Sstevel@tonic-gate sctp->sctp_detached = B_TRUE; 2520Sstevel@tonic-gate /* 2530Sstevel@tonic-gate * Link to the global as soon as possible so that this sctp_t 2540Sstevel@tonic-gate * can be found. 2550Sstevel@tonic-gate */ 256*3448Sdh155122 SCTP_LINK(sctp, sctps); 2570Sstevel@tonic-gate 2580Sstevel@tonic-gate return (sctp); 2590Sstevel@tonic-gate } 2600Sstevel@tonic-gate 2610Sstevel@tonic-gate /* 2620Sstevel@tonic-gate * We are dying for some reason. Try to do it gracefully. 2630Sstevel@tonic-gate */ 2640Sstevel@tonic-gate void 2650Sstevel@tonic-gate sctp_clean_death(sctp_t *sctp, int err) 2660Sstevel@tonic-gate { 2670Sstevel@tonic-gate ASSERT(sctp != NULL); 2680Sstevel@tonic-gate ASSERT((sctp->sctp_family == AF_INET && 2690Sstevel@tonic-gate sctp->sctp_ipversion == IPV4_VERSION) || 2700Sstevel@tonic-gate (sctp->sctp_family == AF_INET6 && 2710Sstevel@tonic-gate (sctp->sctp_ipversion == IPV4_VERSION || 2720Sstevel@tonic-gate sctp->sctp_ipversion == IPV6_VERSION))); 2730Sstevel@tonic-gate 2741676Sjpk dprint(3, ("sctp_clean_death %p, state %d\n", (void *)sctp, 2751676Sjpk sctp->sctp_state)); 2760Sstevel@tonic-gate 2770Sstevel@tonic-gate sctp->sctp_client_errno = err; 2780Sstevel@tonic-gate /* 2790Sstevel@tonic-gate * Check to see if we need to notify upper layer. 2800Sstevel@tonic-gate */ 2810Sstevel@tonic-gate if ((sctp->sctp_state >= SCTPS_COOKIE_WAIT) && 2820Sstevel@tonic-gate !SCTP_IS_DETACHED(sctp)) { 2830Sstevel@tonic-gate if (sctp->sctp_xmit_head || sctp->sctp_xmit_unsent) { 2840Sstevel@tonic-gate sctp_regift_xmitlist(sctp); 2850Sstevel@tonic-gate } 2860Sstevel@tonic-gate if (sctp->sctp_ulp_disconnected(sctp->sctp_ulpd, err)) { 2870Sstevel@tonic-gate /* 2880Sstevel@tonic-gate * Socket is gone, detach. 2890Sstevel@tonic-gate */ 2900Sstevel@tonic-gate sctp->sctp_detached = B_TRUE; 2910Sstevel@tonic-gate sctp->sctp_ulpd = NULL; 2920Sstevel@tonic-gate bzero(&sctp->sctp_upcalls, sizeof (sctp_upcalls_t)); 2930Sstevel@tonic-gate } 2940Sstevel@tonic-gate } 2950Sstevel@tonic-gate 2960Sstevel@tonic-gate /* Remove this sctp from all hashes. */ 2970Sstevel@tonic-gate sctp_closei_local(sctp); 2980Sstevel@tonic-gate 2990Sstevel@tonic-gate /* 3000Sstevel@tonic-gate * If the sctp_t is detached, we need to finish freeing up 3010Sstevel@tonic-gate * the resources. At this point, ip_fanout_sctp() should have 3020Sstevel@tonic-gate * a hold on this sctp_t. Some thread doing snmp stuff can 3030Sstevel@tonic-gate * have a hold. And a taskq can also have a hold waiting to 3040Sstevel@tonic-gate * work. sctp_unlink() the sctp_t from the global list so 3050Sstevel@tonic-gate * that no new thread can find it. Then do a SCTP_REFRELE(). 3060Sstevel@tonic-gate * The sctp_t will be freed after all those threads are done. 3070Sstevel@tonic-gate */ 3080Sstevel@tonic-gate if (SCTP_IS_DETACHED(sctp)) { 3090Sstevel@tonic-gate SCTP_CONDEMNED(sctp); 3100Sstevel@tonic-gate SCTP_REFRELE(sctp); 3110Sstevel@tonic-gate } 3120Sstevel@tonic-gate } 3130Sstevel@tonic-gate 3140Sstevel@tonic-gate /* 3150Sstevel@tonic-gate * Called by upper layer when it wants to close this association. 3160Sstevel@tonic-gate * Depending on the state of this assoication, we need to do 3170Sstevel@tonic-gate * different things. 3180Sstevel@tonic-gate * 3190Sstevel@tonic-gate * If the state is below COOKIE_ECHOED or it is COOKIE_ECHOED but with 3200Sstevel@tonic-gate * no sent data, just remove this sctp from all the hashes. This 3210Sstevel@tonic-gate * makes sure that all packets from the other end will go to the default 3220Sstevel@tonic-gate * sctp handling. The upper layer will then do a sctp_close() to clean 3230Sstevel@tonic-gate * up. 3240Sstevel@tonic-gate * 3250Sstevel@tonic-gate * Otherwise, check and see if SO_LINGER is set. If it is set, check 3260Sstevel@tonic-gate * the value. If the value is 0, consider this an abortive close. Send 3270Sstevel@tonic-gate * an ABORT message and kill the associatiion. 3280Sstevel@tonic-gate * 3290Sstevel@tonic-gate */ 3300Sstevel@tonic-gate int 3310Sstevel@tonic-gate sctp_disconnect(sctp_t *sctp) 3320Sstevel@tonic-gate { 3330Sstevel@tonic-gate int error = 0; 3340Sstevel@tonic-gate 3351676Sjpk dprint(3, ("sctp_disconnect %p, state %d\n", (void *)sctp, 3361676Sjpk sctp->sctp_state)); 3370Sstevel@tonic-gate 3380Sstevel@tonic-gate RUN_SCTP(sctp); 3390Sstevel@tonic-gate 3400Sstevel@tonic-gate switch (sctp->sctp_state) { 3410Sstevel@tonic-gate case SCTPS_IDLE: 3420Sstevel@tonic-gate case SCTPS_BOUND: 3430Sstevel@tonic-gate case SCTPS_LISTEN: 3440Sstevel@tonic-gate break; 3450Sstevel@tonic-gate case SCTPS_COOKIE_WAIT: 3460Sstevel@tonic-gate case SCTPS_COOKIE_ECHOED: 3470Sstevel@tonic-gate /* 3480Sstevel@tonic-gate * Close during the connect 3-way handshake 3490Sstevel@tonic-gate * but here there may or may not be pending data 3500Sstevel@tonic-gate * already on queue. Process almost same as in 3510Sstevel@tonic-gate * the ESTABLISHED state. 3520Sstevel@tonic-gate */ 3530Sstevel@tonic-gate if (sctp->sctp_xmit_head == NULL && 3540Sstevel@tonic-gate sctp->sctp_xmit_unsent == NULL) { 3550Sstevel@tonic-gate break; 3560Sstevel@tonic-gate } 3570Sstevel@tonic-gate /* FALLTHRU */ 3580Sstevel@tonic-gate default: 3590Sstevel@tonic-gate /* 3600Sstevel@tonic-gate * If SO_LINGER has set a zero linger time, abort the 3610Sstevel@tonic-gate * connection with a reset. 3620Sstevel@tonic-gate */ 3630Sstevel@tonic-gate if (sctp->sctp_linger && sctp->sctp_lingertime == 0) { 3640Sstevel@tonic-gate sctp_user_abort(sctp, NULL, B_FALSE); 3650Sstevel@tonic-gate break; 3660Sstevel@tonic-gate } 3670Sstevel@tonic-gate 3680Sstevel@tonic-gate /* 369852Svi117747 * In there is unread data, send an ABORT 370852Svi117747 */ 371852Svi117747 if (sctp->sctp_rxqueued > 0 || sctp->sctp_irwnd > 372852Svi117747 sctp->sctp_rwnd) { 373852Svi117747 sctp_user_abort(sctp, NULL, B_FALSE); 374852Svi117747 break; 375852Svi117747 } 376852Svi117747 /* 3770Sstevel@tonic-gate * Transmit the shutdown before detaching the sctp_t. 3780Sstevel@tonic-gate * After sctp_detach returns this queue/perimeter 3790Sstevel@tonic-gate * no longer owns the sctp_t thus others can modify it. 3800Sstevel@tonic-gate */ 3810Sstevel@tonic-gate sctp_send_shutdown(sctp, 0); 3820Sstevel@tonic-gate 3830Sstevel@tonic-gate /* Pass gathered wisdom to IP for keeping */ 3841735Skcpoon sctp_update_ire(sctp); 3850Sstevel@tonic-gate 3860Sstevel@tonic-gate /* 3870Sstevel@tonic-gate * If lingering on close then wait until the shutdown 3880Sstevel@tonic-gate * is complete, or the SO_LINGER time passes, or an 3890Sstevel@tonic-gate * ABORT is sent/received. Note that sctp_disconnect() 3900Sstevel@tonic-gate * can be called more than once. Make sure that only 3910Sstevel@tonic-gate * one thread waits. 3920Sstevel@tonic-gate */ 3930Sstevel@tonic-gate if (sctp->sctp_linger && sctp->sctp_lingertime > 0 && 3940Sstevel@tonic-gate sctp->sctp_state >= SCTPS_ESTABLISHED && 3950Sstevel@tonic-gate !sctp->sctp_lingering) { 3960Sstevel@tonic-gate clock_t stoptime; /* in ticks */ 3970Sstevel@tonic-gate clock_t ret; 3980Sstevel@tonic-gate 3990Sstevel@tonic-gate /* 4000Sstevel@tonic-gate * Process the sendq to send the SHUTDOWN out 4010Sstevel@tonic-gate * before waiting. 4020Sstevel@tonic-gate */ 4030Sstevel@tonic-gate sctp_process_sendq(sctp); 4040Sstevel@tonic-gate 4050Sstevel@tonic-gate sctp->sctp_lingering = 1; 4060Sstevel@tonic-gate sctp->sctp_client_errno = 0; 4070Sstevel@tonic-gate stoptime = lbolt + sctp->sctp_lingertime; 4080Sstevel@tonic-gate 4090Sstevel@tonic-gate mutex_enter(&sctp->sctp_lock); 4100Sstevel@tonic-gate sctp->sctp_running = B_FALSE; 4110Sstevel@tonic-gate while (sctp->sctp_state >= SCTPS_ESTABLISHED && 4120Sstevel@tonic-gate sctp->sctp_client_errno == 0) { 4130Sstevel@tonic-gate cv_broadcast(&sctp->sctp_cv); 4140Sstevel@tonic-gate ret = cv_timedwait_sig(&sctp->sctp_cv, 4150Sstevel@tonic-gate &sctp->sctp_lock, stoptime); 4160Sstevel@tonic-gate if (ret < 0) { 4170Sstevel@tonic-gate /* Stoptime has reached. */ 4180Sstevel@tonic-gate sctp->sctp_client_errno = EWOULDBLOCK; 4190Sstevel@tonic-gate break; 4200Sstevel@tonic-gate } else if (ret == 0) { 4210Sstevel@tonic-gate /* Got a signal. */ 4220Sstevel@tonic-gate break; 4230Sstevel@tonic-gate } 4240Sstevel@tonic-gate } 4250Sstevel@tonic-gate error = sctp->sctp_client_errno; 4260Sstevel@tonic-gate sctp->sctp_client_errno = 0; 4270Sstevel@tonic-gate mutex_exit(&sctp->sctp_lock); 4280Sstevel@tonic-gate } 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate WAKE_SCTP(sctp); 4310Sstevel@tonic-gate sctp_process_sendq(sctp); 4320Sstevel@tonic-gate return (error); 4330Sstevel@tonic-gate } 4340Sstevel@tonic-gate 4350Sstevel@tonic-gate 4360Sstevel@tonic-gate /* Remove this sctp from all hashes so nobody can find it. */ 4370Sstevel@tonic-gate sctp_closei_local(sctp); 4380Sstevel@tonic-gate WAKE_SCTP(sctp); 4390Sstevel@tonic-gate return (error); 4400Sstevel@tonic-gate } 4410Sstevel@tonic-gate 4420Sstevel@tonic-gate void 4430Sstevel@tonic-gate sctp_close(sctp_t *sctp) 4440Sstevel@tonic-gate { 4451676Sjpk dprint(3, ("sctp_close %p, state %d\n", (void *)sctp, 4461676Sjpk sctp->sctp_state)); 4470Sstevel@tonic-gate 4480Sstevel@tonic-gate RUN_SCTP(sctp); 4490Sstevel@tonic-gate sctp->sctp_detached = 1; 4500Sstevel@tonic-gate sctp->sctp_ulpd = NULL; 4510Sstevel@tonic-gate bzero(&sctp->sctp_upcalls, sizeof (sctp_upcalls_t)); 4520Sstevel@tonic-gate bzero(&sctp->sctp_events, sizeof (sctp->sctp_events)); 4530Sstevel@tonic-gate 4540Sstevel@tonic-gate /* If the graceful shutdown has not been completed, just return. */ 4550Sstevel@tonic-gate if (sctp->sctp_state != SCTPS_IDLE) { 4560Sstevel@tonic-gate WAKE_SCTP(sctp); 4570Sstevel@tonic-gate return; 4580Sstevel@tonic-gate } 4590Sstevel@tonic-gate 4600Sstevel@tonic-gate /* 4610Sstevel@tonic-gate * Since sctp_t is in SCTPS_IDLE state, so the only thread which 4620Sstevel@tonic-gate * can have a hold on the sctp_t is doing snmp stuff. Just do 4630Sstevel@tonic-gate * a SCTP_REFRELE() here after the SCTP_UNLINK(). It will 4640Sstevel@tonic-gate * be freed when the other thread is done. 4650Sstevel@tonic-gate */ 4660Sstevel@tonic-gate SCTP_CONDEMNED(sctp); 4670Sstevel@tonic-gate WAKE_SCTP(sctp); 4680Sstevel@tonic-gate SCTP_REFRELE(sctp); 4690Sstevel@tonic-gate } 4700Sstevel@tonic-gate 4710Sstevel@tonic-gate /* 4720Sstevel@tonic-gate * Unlink from global list and do the eager close. 4730Sstevel@tonic-gate * Remove the refhold implicit in being on the global list. 4740Sstevel@tonic-gate */ 4750Sstevel@tonic-gate void 4760Sstevel@tonic-gate sctp_close_eager(sctp_t *sctp) 4770Sstevel@tonic-gate { 4780Sstevel@tonic-gate SCTP_CONDEMNED(sctp); 4790Sstevel@tonic-gate sctp_closei_local(sctp); 4800Sstevel@tonic-gate SCTP_REFRELE(sctp); 4810Sstevel@tonic-gate } 4820Sstevel@tonic-gate 4830Sstevel@tonic-gate /* 4840Sstevel@tonic-gate * The sctp_t is going away. Remove it from all lists and set it 4850Sstevel@tonic-gate * to SCTPS_IDLE. The caller has to remove it from the 4860Sstevel@tonic-gate * global list. The freeing up of memory is deferred until 4870Sstevel@tonic-gate * sctp_free(). This is needed since a thread in sctp_input() might have 4880Sstevel@tonic-gate * done a SCTP_REFHOLD on this structure before it was removed from the 4890Sstevel@tonic-gate * hashes. 4900Sstevel@tonic-gate */ 4910Sstevel@tonic-gate static void 4920Sstevel@tonic-gate sctp_closei_local(sctp_t *sctp) 4930Sstevel@tonic-gate { 4940Sstevel@tonic-gate mblk_t *mp; 4950Sstevel@tonic-gate ire_t *ire = NULL; 4960Sstevel@tonic-gate conn_t *connp = sctp->sctp_connp; 4970Sstevel@tonic-gate 4980Sstevel@tonic-gate /* Stop and free the timers */ 4990Sstevel@tonic-gate sctp_free_faddr_timers(sctp); 5000Sstevel@tonic-gate if ((mp = sctp->sctp_heartbeat_mp) != NULL) { 5010Sstevel@tonic-gate sctp_timer_free(mp); 5020Sstevel@tonic-gate sctp->sctp_heartbeat_mp = NULL; 5030Sstevel@tonic-gate } 5040Sstevel@tonic-gate if ((mp = sctp->sctp_ack_mp) != NULL) { 5050Sstevel@tonic-gate sctp_timer_free(mp); 5060Sstevel@tonic-gate sctp->sctp_ack_mp = NULL; 5070Sstevel@tonic-gate } 5080Sstevel@tonic-gate 5090Sstevel@tonic-gate /* Set the CONN_CLOSING flag so that IP will not cache IRE again. */ 5100Sstevel@tonic-gate mutex_enter(&connp->conn_lock); 5110Sstevel@tonic-gate connp->conn_state_flags |= CONN_CLOSING; 5120Sstevel@tonic-gate ire = connp->conn_ire_cache; 5130Sstevel@tonic-gate connp->conn_ire_cache = NULL; 5140Sstevel@tonic-gate mutex_exit(&connp->conn_lock); 5150Sstevel@tonic-gate if (ire != NULL) 5160Sstevel@tonic-gate IRE_REFRELE_NOTR(ire); 5170Sstevel@tonic-gate 5180Sstevel@tonic-gate /* Remove from all hashes. */ 5190Sstevel@tonic-gate sctp_bind_hash_remove(sctp); 5200Sstevel@tonic-gate sctp_conn_hash_remove(sctp); 5210Sstevel@tonic-gate sctp_listen_hash_remove(sctp); 5220Sstevel@tonic-gate sctp->sctp_state = SCTPS_IDLE; 5230Sstevel@tonic-gate 5240Sstevel@tonic-gate /* 5250Sstevel@tonic-gate * Clean up the recvq as much as possible. All those packets 5260Sstevel@tonic-gate * will be silently dropped as this sctp_t is now in idle state. 5270Sstevel@tonic-gate */ 5280Sstevel@tonic-gate mutex_enter(&sctp->sctp_recvq_lock); 5290Sstevel@tonic-gate while ((mp = sctp->sctp_recvq) != NULL) { 5300Sstevel@tonic-gate mblk_t *ipsec_mp; 5310Sstevel@tonic-gate 5320Sstevel@tonic-gate sctp->sctp_recvq = mp->b_next; 5330Sstevel@tonic-gate mp->b_next = NULL; 5340Sstevel@tonic-gate if ((ipsec_mp = mp->b_prev) != NULL) { 5350Sstevel@tonic-gate freeb(ipsec_mp); 5360Sstevel@tonic-gate mp->b_prev = NULL; 5370Sstevel@tonic-gate } 5380Sstevel@tonic-gate freemsg(mp); 5390Sstevel@tonic-gate } 5400Sstevel@tonic-gate mutex_exit(&sctp->sctp_recvq_lock); 5410Sstevel@tonic-gate } 5420Sstevel@tonic-gate 5430Sstevel@tonic-gate /* 5440Sstevel@tonic-gate * Free memory associated with the sctp/ip header template. 5450Sstevel@tonic-gate */ 5460Sstevel@tonic-gate static void 5470Sstevel@tonic-gate sctp_headers_free(sctp_t *sctp) 5480Sstevel@tonic-gate { 5490Sstevel@tonic-gate if (sctp->sctp_iphc != NULL) { 5500Sstevel@tonic-gate kmem_free(sctp->sctp_iphc, sctp->sctp_iphc_len); 5510Sstevel@tonic-gate sctp->sctp_iphc = NULL; 5520Sstevel@tonic-gate sctp->sctp_ipha = NULL; 5530Sstevel@tonic-gate sctp->sctp_hdr_len = 0; 5540Sstevel@tonic-gate sctp->sctp_ip_hdr_len = 0; 5550Sstevel@tonic-gate sctp->sctp_iphc_len = 0; 5560Sstevel@tonic-gate sctp->sctp_sctph = NULL; 5570Sstevel@tonic-gate sctp->sctp_hdr_len = 0; 5580Sstevel@tonic-gate } 5590Sstevel@tonic-gate if (sctp->sctp_iphc6 != NULL) { 5600Sstevel@tonic-gate kmem_free(sctp->sctp_iphc6, sctp->sctp_iphc6_len); 5610Sstevel@tonic-gate sctp->sctp_iphc6 = NULL; 5620Sstevel@tonic-gate sctp->sctp_ip6h = NULL; 5630Sstevel@tonic-gate sctp->sctp_hdr6_len = 0; 5640Sstevel@tonic-gate sctp->sctp_ip_hdr6_len = 0; 5650Sstevel@tonic-gate sctp->sctp_iphc6_len = 0; 5660Sstevel@tonic-gate sctp->sctp_sctph6 = NULL; 5670Sstevel@tonic-gate sctp->sctp_hdr6_len = 0; 5680Sstevel@tonic-gate } 5690Sstevel@tonic-gate } 5700Sstevel@tonic-gate 5710Sstevel@tonic-gate static void 5720Sstevel@tonic-gate sctp_free_xmit_data(sctp_t *sctp) 5730Sstevel@tonic-gate { 5740Sstevel@tonic-gate mblk_t *ump = NULL; 5750Sstevel@tonic-gate mblk_t *nump; 5760Sstevel@tonic-gate mblk_t *mp; 5770Sstevel@tonic-gate mblk_t *nmp; 5780Sstevel@tonic-gate 5790Sstevel@tonic-gate sctp->sctp_xmit_unacked = NULL; 5800Sstevel@tonic-gate ump = sctp->sctp_xmit_head; 5810Sstevel@tonic-gate sctp->sctp_xmit_tail = sctp->sctp_xmit_head = NULL; 5820Sstevel@tonic-gate free_unsent: 5830Sstevel@tonic-gate for (; ump != NULL; ump = nump) { 5840Sstevel@tonic-gate for (mp = ump->b_cont; mp != NULL; mp = nmp) { 5850Sstevel@tonic-gate nmp = mp->b_next; 5860Sstevel@tonic-gate mp->b_next = NULL; 5870Sstevel@tonic-gate mp->b_prev = NULL; 5880Sstevel@tonic-gate freemsg(mp); 5890Sstevel@tonic-gate } 5900Sstevel@tonic-gate ASSERT(DB_REF(ump) == 1); 5910Sstevel@tonic-gate nump = ump->b_next; 5920Sstevel@tonic-gate ump->b_next = NULL; 5930Sstevel@tonic-gate ump->b_prev = NULL; 5940Sstevel@tonic-gate ump->b_cont = NULL; 5950Sstevel@tonic-gate freeb(ump); 5960Sstevel@tonic-gate } 5970Sstevel@tonic-gate if ((ump = sctp->sctp_xmit_unsent) == NULL) { 5980Sstevel@tonic-gate ASSERT(sctp->sctp_xmit_unsent_tail == NULL); 5990Sstevel@tonic-gate return; 6000Sstevel@tonic-gate } 6010Sstevel@tonic-gate sctp->sctp_xmit_unsent = sctp->sctp_xmit_unsent_tail = NULL; 6020Sstevel@tonic-gate goto free_unsent; 6030Sstevel@tonic-gate } 6040Sstevel@tonic-gate 6050Sstevel@tonic-gate /* 6060Sstevel@tonic-gate * Cleanup all the messages in the stream queue and the reassembly lists. 6070Sstevel@tonic-gate * If 'free' is true, then delete the streams as well. 6080Sstevel@tonic-gate */ 6090Sstevel@tonic-gate void 6100Sstevel@tonic-gate sctp_instream_cleanup(sctp_t *sctp, boolean_t free) 6110Sstevel@tonic-gate { 6120Sstevel@tonic-gate int i; 6130Sstevel@tonic-gate mblk_t *mp; 6140Sstevel@tonic-gate mblk_t *mp1; 6150Sstevel@tonic-gate 6160Sstevel@tonic-gate if (sctp->sctp_instr != NULL) { 6170Sstevel@tonic-gate /* walk thru and flush out anything remaining in the Q */ 6180Sstevel@tonic-gate for (i = 0; i < sctp->sctp_num_istr; i++) { 6190Sstevel@tonic-gate mp = sctp->sctp_instr[i].istr_msgs; 6200Sstevel@tonic-gate while (mp != NULL) { 6210Sstevel@tonic-gate mp1 = mp->b_next; 6220Sstevel@tonic-gate mp->b_next = mp->b_prev = NULL; 6230Sstevel@tonic-gate freemsg(mp); 6240Sstevel@tonic-gate mp = mp1; 6250Sstevel@tonic-gate } 6260Sstevel@tonic-gate sctp->sctp_instr[i].istr_msgs = NULL; 6270Sstevel@tonic-gate sctp_free_reass((sctp->sctp_instr) + i); 6280Sstevel@tonic-gate sctp->sctp_instr[i].nextseq = 0; 6290Sstevel@tonic-gate } 6300Sstevel@tonic-gate if (free) { 6310Sstevel@tonic-gate kmem_free(sctp->sctp_instr, 6320Sstevel@tonic-gate sizeof (*sctp->sctp_instr) * sctp->sctp_num_istr); 6330Sstevel@tonic-gate sctp->sctp_instr = NULL; 6340Sstevel@tonic-gate sctp->sctp_num_istr = 0; 6350Sstevel@tonic-gate } 6360Sstevel@tonic-gate } 6370Sstevel@tonic-gate /* un-ordered fragments */ 6380Sstevel@tonic-gate if (sctp->sctp_uo_frags != NULL) { 6390Sstevel@tonic-gate for (mp = sctp->sctp_uo_frags; mp != NULL; mp = mp1) { 6400Sstevel@tonic-gate mp1 = mp->b_next; 6410Sstevel@tonic-gate mp->b_next = mp->b_prev = NULL; 6420Sstevel@tonic-gate freemsg(mp); 6430Sstevel@tonic-gate } 6440Sstevel@tonic-gate } 6450Sstevel@tonic-gate } 6460Sstevel@tonic-gate 6470Sstevel@tonic-gate /* 6480Sstevel@tonic-gate * Last reference to the sctp_t is gone. Free all memory associated with it. 6490Sstevel@tonic-gate * Called from SCTP_REFRELE. Called inline in sctp_close() 6500Sstevel@tonic-gate */ 6510Sstevel@tonic-gate void 6520Sstevel@tonic-gate sctp_free(conn_t *connp) 6530Sstevel@tonic-gate { 6540Sstevel@tonic-gate sctp_t *sctp = CONN2SCTP(connp); 6550Sstevel@tonic-gate int cnt; 656*3448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 657*3448Sdh155122 netstack_t *ns; 6580Sstevel@tonic-gate 659*3448Sdh155122 ASSERT(sctps != NULL); 6600Sstevel@tonic-gate /* Unlink it from the global list */ 661*3448Sdh155122 SCTP_UNLINK(sctp, sctps); 6620Sstevel@tonic-gate 6630Sstevel@tonic-gate ASSERT(connp->conn_ref == 0); 6640Sstevel@tonic-gate ASSERT(connp->conn_ulp == IPPROTO_SCTP); 6650Sstevel@tonic-gate ASSERT(!MUTEX_HELD(&sctp->sctp_reflock)); 6660Sstevel@tonic-gate ASSERT(sctp->sctp_refcnt == 0); 6670Sstevel@tonic-gate 6680Sstevel@tonic-gate ASSERT(sctp->sctp_ptpbhn == NULL && sctp->sctp_bind_hash == NULL); 6690Sstevel@tonic-gate ASSERT(sctp->sctp_conn_hash_next == NULL && 6700Sstevel@tonic-gate sctp->sctp_conn_hash_prev == NULL); 6710Sstevel@tonic-gate 6720Sstevel@tonic-gate 6730Sstevel@tonic-gate /* Free up all the resources. */ 6740Sstevel@tonic-gate 6750Sstevel@tonic-gate /* blow away sctp stream management */ 6760Sstevel@tonic-gate if (sctp->sctp_ostrcntrs != NULL) { 6770Sstevel@tonic-gate kmem_free(sctp->sctp_ostrcntrs, 6780Sstevel@tonic-gate sizeof (uint16_t) * sctp->sctp_num_ostr); 6790Sstevel@tonic-gate sctp->sctp_ostrcntrs = NULL; 6800Sstevel@tonic-gate } 6810Sstevel@tonic-gate sctp_instream_cleanup(sctp, B_TRUE); 6820Sstevel@tonic-gate 6830Sstevel@tonic-gate /* Remove all data transfer resources. */ 6840Sstevel@tonic-gate sctp->sctp_istr_nmsgs = 0; 6850Sstevel@tonic-gate sctp->sctp_rxqueued = 0; 6860Sstevel@tonic-gate sctp_free_xmit_data(sctp); 6870Sstevel@tonic-gate sctp->sctp_unacked = 0; 6880Sstevel@tonic-gate sctp->sctp_unsent = 0; 689852Svi117747 if (sctp->sctp_cxmit_list != NULL) 690852Svi117747 sctp_asconf_free_cxmit(sctp, NULL); 691852Svi117747 6920Sstevel@tonic-gate sctp->sctp_lastdata = NULL; 6930Sstevel@tonic-gate 6940Sstevel@tonic-gate /* Clear out default xmit settings */ 6950Sstevel@tonic-gate sctp->sctp_def_stream = 0; 6960Sstevel@tonic-gate sctp->sctp_def_flags = 0; 6970Sstevel@tonic-gate sctp->sctp_def_ppid = 0; 6980Sstevel@tonic-gate sctp->sctp_def_context = 0; 6990Sstevel@tonic-gate sctp->sctp_def_timetolive = 0; 7000Sstevel@tonic-gate 7010Sstevel@tonic-gate if (sctp->sctp_sack_info != NULL) { 7020Sstevel@tonic-gate sctp_free_set(sctp->sctp_sack_info); 7030Sstevel@tonic-gate sctp->sctp_sack_info = NULL; 7040Sstevel@tonic-gate } 7050Sstevel@tonic-gate sctp->sctp_sack_gaps = 0; 7060Sstevel@tonic-gate 7070Sstevel@tonic-gate if (sctp->sctp_cookie_mp != NULL) { 7080Sstevel@tonic-gate freemsg(sctp->sctp_cookie_mp); 7090Sstevel@tonic-gate sctp->sctp_cookie_mp = NULL; 7100Sstevel@tonic-gate } 7110Sstevel@tonic-gate 7120Sstevel@tonic-gate /* Remove all the address resources. */ 7130Sstevel@tonic-gate sctp_zap_addrs(sctp); 7140Sstevel@tonic-gate for (cnt = 0; cnt < SCTP_IPIF_HASH; cnt++) { 7150Sstevel@tonic-gate ASSERT(sctp->sctp_saddrs[cnt].ipif_count == 0); 7160Sstevel@tonic-gate list_destroy(&sctp->sctp_saddrs[cnt].sctp_ipif_list); 7170Sstevel@tonic-gate } 7180Sstevel@tonic-gate 7191676Sjpk ip6_pkt_free(&sctp->sctp_sticky_ipp); 7200Sstevel@tonic-gate 7210Sstevel@tonic-gate if (sctp->sctp_hopopts != NULL) { 7220Sstevel@tonic-gate mi_free(sctp->sctp_hopopts); 7230Sstevel@tonic-gate sctp->sctp_hopopts = NULL; 7240Sstevel@tonic-gate sctp->sctp_hopoptslen = 0; 7250Sstevel@tonic-gate } 7260Sstevel@tonic-gate ASSERT(sctp->sctp_hopoptslen == 0); 7270Sstevel@tonic-gate if (sctp->sctp_dstopts != NULL) { 7280Sstevel@tonic-gate mi_free(sctp->sctp_dstopts); 7290Sstevel@tonic-gate sctp->sctp_dstopts = NULL; 7300Sstevel@tonic-gate sctp->sctp_dstoptslen = 0; 7310Sstevel@tonic-gate } 7320Sstevel@tonic-gate ASSERT(sctp->sctp_dstoptslen == 0); 7330Sstevel@tonic-gate if (sctp->sctp_rtdstopts != NULL) { 7340Sstevel@tonic-gate mi_free(sctp->sctp_rtdstopts); 7350Sstevel@tonic-gate sctp->sctp_rtdstopts = NULL; 7360Sstevel@tonic-gate sctp->sctp_rtdstoptslen = 0; 7370Sstevel@tonic-gate } 7380Sstevel@tonic-gate ASSERT(sctp->sctp_rtdstoptslen == 0); 7390Sstevel@tonic-gate if (sctp->sctp_rthdr != NULL) { 7400Sstevel@tonic-gate mi_free(sctp->sctp_rthdr); 7410Sstevel@tonic-gate sctp->sctp_rthdr = NULL; 7420Sstevel@tonic-gate sctp->sctp_rthdrlen = 0; 7430Sstevel@tonic-gate } 7440Sstevel@tonic-gate ASSERT(sctp->sctp_rthdrlen == 0); 7450Sstevel@tonic-gate sctp_headers_free(sctp); 7460Sstevel@tonic-gate 7470Sstevel@tonic-gate sctp->sctp_shutdown_faddr = NULL; 7480Sstevel@tonic-gate 7490Sstevel@tonic-gate /* Clear all the bitfields. */ 7500Sstevel@tonic-gate bzero(&sctp->sctp_bits, sizeof (sctp->sctp_bits)); 7510Sstevel@tonic-gate 7520Sstevel@tonic-gate /* It is time to update the global statistics. */ 753*3448Sdh155122 UPDATE_MIB(&sctps->sctps_mib, sctpOutSCTPPkts, sctp->sctp_opkts); 754*3448Sdh155122 UPDATE_MIB(&sctps->sctps_mib, sctpOutCtrlChunks, sctp->sctp_obchunks); 755*3448Sdh155122 UPDATE_MIB(&sctps->sctps_mib, sctpOutOrderChunks, sctp->sctp_odchunks); 756*3448Sdh155122 UPDATE_MIB(&sctps->sctps_mib, 757*3448Sdh155122 sctpOutUnorderChunks, sctp->sctp_oudchunks); 758*3448Sdh155122 UPDATE_MIB(&sctps->sctps_mib, sctpRetransChunks, sctp->sctp_rxtchunks); 759*3448Sdh155122 UPDATE_MIB(&sctps->sctps_mib, sctpInSCTPPkts, sctp->sctp_ipkts); 760*3448Sdh155122 UPDATE_MIB(&sctps->sctps_mib, sctpInCtrlChunks, sctp->sctp_ibchunks); 761*3448Sdh155122 UPDATE_MIB(&sctps->sctps_mib, sctpInOrderChunks, sctp->sctp_idchunks); 762*3448Sdh155122 UPDATE_MIB(&sctps->sctps_mib, 763*3448Sdh155122 sctpInUnorderChunks, sctp->sctp_iudchunks); 764*3448Sdh155122 UPDATE_MIB(&sctps->sctps_mib, sctpFragUsrMsgs, sctp->sctp_fragdmsgs); 765*3448Sdh155122 UPDATE_MIB(&sctps->sctps_mib, sctpReasmUsrMsgs, sctp->sctp_reassmsgs); 7660Sstevel@tonic-gate sctp->sctp_opkts = 0; 7670Sstevel@tonic-gate sctp->sctp_obchunks = 0; 7680Sstevel@tonic-gate sctp->sctp_odchunks = 0; 7690Sstevel@tonic-gate sctp->sctp_oudchunks = 0; 7700Sstevel@tonic-gate sctp->sctp_rxtchunks = 0; 7710Sstevel@tonic-gate sctp->sctp_ipkts = 0; 7720Sstevel@tonic-gate sctp->sctp_ibchunks = 0; 7730Sstevel@tonic-gate sctp->sctp_idchunks = 0; 7740Sstevel@tonic-gate sctp->sctp_iudchunks = 0; 7750Sstevel@tonic-gate sctp->sctp_fragdmsgs = 0; 7760Sstevel@tonic-gate sctp->sctp_reassmsgs = 0; 7770Sstevel@tonic-gate 7780Sstevel@tonic-gate sctp->sctp_autoclose = 0; 7790Sstevel@tonic-gate sctp->sctp_tx_adaption_code = 0; 7800Sstevel@tonic-gate 7812283Skp158701 sctp->sctp_v6label_len = 0; 7822283Skp158701 sctp->sctp_v4label_len = 0; 7832283Skp158701 7840Sstevel@tonic-gate /* Clean up conn_t stuff */ 7850Sstevel@tonic-gate connp->conn_policy_cached = B_FALSE; 7860Sstevel@tonic-gate if (connp->conn_latch != NULL) { 787*3448Sdh155122 IPLATCH_REFRELE(connp->conn_latch, connp->conn_netstack); 7880Sstevel@tonic-gate connp->conn_latch = NULL; 7890Sstevel@tonic-gate } 7900Sstevel@tonic-gate if (connp->conn_policy != NULL) { 791*3448Sdh155122 IPPH_REFRELE(connp->conn_policy, connp->conn_netstack); 7920Sstevel@tonic-gate connp->conn_policy = NULL; 7930Sstevel@tonic-gate } 7940Sstevel@tonic-gate if (connp->conn_ipsec_opt_mp != NULL) { 7950Sstevel@tonic-gate freemsg(connp->conn_ipsec_opt_mp); 7960Sstevel@tonic-gate connp->conn_ipsec_opt_mp = NULL; 7970Sstevel@tonic-gate } 7980Sstevel@tonic-gate if (connp->conn_cred != NULL) { 7990Sstevel@tonic-gate crfree(connp->conn_cred); 8000Sstevel@tonic-gate connp->conn_cred = NULL; 8010Sstevel@tonic-gate } 8020Sstevel@tonic-gate 803*3448Sdh155122 /* Every sctp_t holds one reference on the default queue */ 804*3448Sdh155122 sctp->sctp_sctps = NULL; 805*3448Sdh155122 SCTP_G_Q_REFRELE(sctps); 806*3448Sdh155122 807*3448Sdh155122 ns = connp->conn_netstack; 808*3448Sdh155122 connp->conn_netstack = NULL; 809*3448Sdh155122 netstack_rele(ns); 8100Sstevel@tonic-gate kmem_cache_free(sctp_conn_cache, connp); 8110Sstevel@tonic-gate } 8120Sstevel@tonic-gate 8130Sstevel@tonic-gate /* Diagnostic routine used to return a string associated with the sctp state. */ 8140Sstevel@tonic-gate char * 8150Sstevel@tonic-gate sctp_display(sctp_t *sctp, char *sup_buf) 8160Sstevel@tonic-gate { 8170Sstevel@tonic-gate char *buf; 8180Sstevel@tonic-gate char buf1[30]; 8190Sstevel@tonic-gate static char priv_buf[INET6_ADDRSTRLEN * 2 + 80]; 8200Sstevel@tonic-gate char *cp; 8210Sstevel@tonic-gate 8220Sstevel@tonic-gate if (sctp == NULL) 8230Sstevel@tonic-gate return ("NULL_SCTP"); 8240Sstevel@tonic-gate 8250Sstevel@tonic-gate buf = (sup_buf != NULL) ? sup_buf : priv_buf; 8260Sstevel@tonic-gate 8270Sstevel@tonic-gate switch (sctp->sctp_state) { 8280Sstevel@tonic-gate case SCTPS_IDLE: 8290Sstevel@tonic-gate cp = "SCTP_IDLE"; 8300Sstevel@tonic-gate break; 8310Sstevel@tonic-gate case SCTPS_BOUND: 8320Sstevel@tonic-gate cp = "SCTP_BOUND"; 8330Sstevel@tonic-gate break; 8340Sstevel@tonic-gate case SCTPS_LISTEN: 8350Sstevel@tonic-gate cp = "SCTP_LISTEN"; 8360Sstevel@tonic-gate break; 8370Sstevel@tonic-gate case SCTPS_COOKIE_WAIT: 8380Sstevel@tonic-gate cp = "SCTP_COOKIE_WAIT"; 8390Sstevel@tonic-gate break; 8400Sstevel@tonic-gate case SCTPS_COOKIE_ECHOED: 8410Sstevel@tonic-gate cp = "SCTP_COOKIE_ECHOED"; 8420Sstevel@tonic-gate break; 8430Sstevel@tonic-gate case SCTPS_ESTABLISHED: 8440Sstevel@tonic-gate cp = "SCTP_ESTABLISHED"; 8450Sstevel@tonic-gate break; 8460Sstevel@tonic-gate case SCTPS_SHUTDOWN_PENDING: 8470Sstevel@tonic-gate cp = "SCTP_SHUTDOWN_PENDING"; 8480Sstevel@tonic-gate break; 8490Sstevel@tonic-gate case SCTPS_SHUTDOWN_SENT: 8500Sstevel@tonic-gate cp = "SCTPS_SHUTDOWN_SENT"; 8510Sstevel@tonic-gate break; 8520Sstevel@tonic-gate case SCTPS_SHUTDOWN_RECEIVED: 8530Sstevel@tonic-gate cp = "SCTPS_SHUTDOWN_RECEIVED"; 8540Sstevel@tonic-gate break; 8550Sstevel@tonic-gate case SCTPS_SHUTDOWN_ACK_SENT: 8560Sstevel@tonic-gate cp = "SCTPS_SHUTDOWN_ACK_SENT"; 8570Sstevel@tonic-gate break; 8580Sstevel@tonic-gate default: 8590Sstevel@tonic-gate (void) mi_sprintf(buf1, "SCTPUnkState(%d)", sctp->sctp_state); 8600Sstevel@tonic-gate cp = buf1; 8610Sstevel@tonic-gate break; 8620Sstevel@tonic-gate } 8630Sstevel@tonic-gate (void) mi_sprintf(buf, "[%u, %u] %s", 8640Sstevel@tonic-gate ntohs(sctp->sctp_lport), ntohs(sctp->sctp_fport), cp); 8650Sstevel@tonic-gate 8660Sstevel@tonic-gate return (buf); 8670Sstevel@tonic-gate } 8680Sstevel@tonic-gate 8690Sstevel@tonic-gate /* 8700Sstevel@tonic-gate * Initialize protocol control block. If a parent exists, inherit 8710Sstevel@tonic-gate * all values set through setsockopt(). 8720Sstevel@tonic-gate */ 8730Sstevel@tonic-gate static int 8740Sstevel@tonic-gate sctp_init_values(sctp_t *sctp, sctp_t *psctp, int sleep) 8750Sstevel@tonic-gate { 8760Sstevel@tonic-gate int err; 8770Sstevel@tonic-gate int cnt; 878*3448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 8792263Ssommerfe conn_t *connp, *pconnp; 8800Sstevel@tonic-gate 8810Sstevel@tonic-gate ASSERT((sctp->sctp_family == AF_INET && 8820Sstevel@tonic-gate sctp->sctp_ipversion == IPV4_VERSION) || 8830Sstevel@tonic-gate (sctp->sctp_family == AF_INET6 && 8840Sstevel@tonic-gate (sctp->sctp_ipversion == IPV4_VERSION || 8850Sstevel@tonic-gate sctp->sctp_ipversion == IPV6_VERSION))); 8860Sstevel@tonic-gate 8870Sstevel@tonic-gate sctp->sctp_nsaddrs = 0; 8880Sstevel@tonic-gate for (cnt = 0; cnt < SCTP_IPIF_HASH; cnt++) { 8890Sstevel@tonic-gate sctp->sctp_saddrs[cnt].ipif_count = 0; 8900Sstevel@tonic-gate list_create(&sctp->sctp_saddrs[cnt].sctp_ipif_list, 8910Sstevel@tonic-gate sizeof (sctp_saddr_ipif_t), offsetof(sctp_saddr_ipif_t, 8920Sstevel@tonic-gate saddr_ipif)); 8930Sstevel@tonic-gate } 8940Sstevel@tonic-gate sctp->sctp_ports = 0; 8950Sstevel@tonic-gate sctp->sctp_running = B_FALSE; 8960Sstevel@tonic-gate sctp->sctp_state = SCTPS_IDLE; 8970Sstevel@tonic-gate 8980Sstevel@tonic-gate sctp->sctp_refcnt = 1; 8990Sstevel@tonic-gate 9000Sstevel@tonic-gate sctp->sctp_strikes = 0; 9010Sstevel@tonic-gate 9020Sstevel@tonic-gate sctp->sctp_last_mtu_probe = lbolt64; 903*3448Sdh155122 sctp->sctp_mtu_probe_intvl = sctps->sctps_mtu_probe_interval; 9040Sstevel@tonic-gate 9050Sstevel@tonic-gate sctp->sctp_sack_gaps = 0; 9060Sstevel@tonic-gate sctp->sctp_sack_toggle = 2; 9070Sstevel@tonic-gate 9080Sstevel@tonic-gate if (psctp != NULL) { 9090Sstevel@tonic-gate /* 9100Sstevel@tonic-gate * Inherit from parent 9110Sstevel@tonic-gate */ 9120Sstevel@tonic-gate sctp->sctp_iphc = kmem_zalloc(psctp->sctp_iphc_len, 9130Sstevel@tonic-gate KM_NOSLEEP); 9140Sstevel@tonic-gate if (sctp->sctp_iphc == NULL) 9150Sstevel@tonic-gate return (ENOMEM); 9160Sstevel@tonic-gate sctp->sctp_iphc_len = psctp->sctp_iphc_len; 9170Sstevel@tonic-gate sctp->sctp_hdr_len = psctp->sctp_hdr_len; 9180Sstevel@tonic-gate 9190Sstevel@tonic-gate sctp->sctp_iphc6 = kmem_zalloc(psctp->sctp_iphc6_len, 9200Sstevel@tonic-gate KM_NOSLEEP); 9210Sstevel@tonic-gate if (sctp->sctp_iphc6 == NULL) { 9220Sstevel@tonic-gate sctp->sctp_iphc6_len = 0; 9230Sstevel@tonic-gate return (ENOMEM); 9240Sstevel@tonic-gate } 9250Sstevel@tonic-gate sctp->sctp_iphc6_len = psctp->sctp_iphc6_len; 9260Sstevel@tonic-gate sctp->sctp_hdr6_len = psctp->sctp_hdr6_len; 9270Sstevel@tonic-gate 9280Sstevel@tonic-gate sctp->sctp_ip_hdr_len = psctp->sctp_ip_hdr_len; 9290Sstevel@tonic-gate sctp->sctp_ip_hdr6_len = psctp->sctp_ip_hdr6_len; 9300Sstevel@tonic-gate 9310Sstevel@tonic-gate /* 9320Sstevel@tonic-gate * Copy the IP+SCTP header templates from listener 9330Sstevel@tonic-gate */ 9340Sstevel@tonic-gate bcopy(psctp->sctp_iphc, sctp->sctp_iphc, 9350Sstevel@tonic-gate psctp->sctp_hdr_len); 9360Sstevel@tonic-gate sctp->sctp_ipha = (ipha_t *)sctp->sctp_iphc; 9370Sstevel@tonic-gate sctp->sctp_sctph = (sctp_hdr_t *)(sctp->sctp_iphc + 9380Sstevel@tonic-gate sctp->sctp_ip_hdr_len); 9390Sstevel@tonic-gate 9400Sstevel@tonic-gate bcopy(psctp->sctp_iphc6, sctp->sctp_iphc6, 9410Sstevel@tonic-gate psctp->sctp_hdr6_len); 9420Sstevel@tonic-gate if (((ip6i_t *)(sctp->sctp_iphc6))->ip6i_nxt == IPPROTO_RAW) { 9430Sstevel@tonic-gate sctp->sctp_ip6h = (ip6_t *)(sctp->sctp_iphc6 + 9440Sstevel@tonic-gate sizeof (ip6i_t)); 9450Sstevel@tonic-gate } else { 9460Sstevel@tonic-gate sctp->sctp_ip6h = (ip6_t *)sctp->sctp_iphc6; 9470Sstevel@tonic-gate } 9480Sstevel@tonic-gate sctp->sctp_sctph6 = (sctp_hdr_t *)(sctp->sctp_iphc6 + 9490Sstevel@tonic-gate sctp->sctp_ip_hdr6_len); 9500Sstevel@tonic-gate 9510Sstevel@tonic-gate sctp->sctp_cookie_lifetime = psctp->sctp_cookie_lifetime; 9520Sstevel@tonic-gate sctp->sctp_xmit_lowater = psctp->sctp_xmit_lowater; 9530Sstevel@tonic-gate sctp->sctp_xmit_hiwater = psctp->sctp_xmit_hiwater; 9540Sstevel@tonic-gate sctp->sctp_cwnd_max = psctp->sctp_cwnd_max; 9550Sstevel@tonic-gate sctp->sctp_rwnd = psctp->sctp_rwnd; 956852Svi117747 sctp->sctp_irwnd = psctp->sctp_rwnd; 9570Sstevel@tonic-gate 9580Sstevel@tonic-gate sctp->sctp_rto_max = psctp->sctp_rto_max; 9590Sstevel@tonic-gate sctp->sctp_init_rto_max = psctp->sctp_init_rto_max; 9600Sstevel@tonic-gate sctp->sctp_rto_min = psctp->sctp_rto_min; 9610Sstevel@tonic-gate sctp->sctp_rto_initial = psctp->sctp_rto_initial; 9620Sstevel@tonic-gate sctp->sctp_pa_max_rxt = psctp->sctp_pa_max_rxt; 9630Sstevel@tonic-gate sctp->sctp_pp_max_rxt = psctp->sctp_pp_max_rxt; 9640Sstevel@tonic-gate sctp->sctp_max_init_rxt = psctp->sctp_max_init_rxt; 9650Sstevel@tonic-gate 9660Sstevel@tonic-gate sctp->sctp_def_stream = psctp->sctp_def_stream; 9670Sstevel@tonic-gate sctp->sctp_def_flags = psctp->sctp_def_flags; 9680Sstevel@tonic-gate sctp->sctp_def_ppid = psctp->sctp_def_ppid; 9690Sstevel@tonic-gate sctp->sctp_def_context = psctp->sctp_def_context; 9700Sstevel@tonic-gate sctp->sctp_def_timetolive = psctp->sctp_def_timetolive; 9710Sstevel@tonic-gate 9720Sstevel@tonic-gate sctp->sctp_num_istr = psctp->sctp_num_istr; 9730Sstevel@tonic-gate sctp->sctp_num_ostr = psctp->sctp_num_ostr; 9740Sstevel@tonic-gate 9750Sstevel@tonic-gate sctp->sctp_hb_interval = psctp->sctp_hb_interval; 9760Sstevel@tonic-gate sctp->sctp_autoclose = psctp->sctp_autoclose; 9770Sstevel@tonic-gate sctp->sctp_tx_adaption_code = psctp->sctp_tx_adaption_code; 9780Sstevel@tonic-gate 9790Sstevel@tonic-gate /* xxx should be a better way to copy these flags xxx */ 9800Sstevel@tonic-gate sctp->sctp_debug = psctp->sctp_debug; 9810Sstevel@tonic-gate sctp->sctp_bound_to_all = psctp->sctp_bound_to_all; 9820Sstevel@tonic-gate sctp->sctp_cansleep = psctp->sctp_cansleep; 9830Sstevel@tonic-gate sctp->sctp_send_adaption = psctp->sctp_send_adaption; 9840Sstevel@tonic-gate sctp->sctp_ndelay = psctp->sctp_ndelay; 9850Sstevel@tonic-gate sctp->sctp_events = psctp->sctp_events; 9860Sstevel@tonic-gate sctp->sctp_ipv6_recvancillary = psctp->sctp_ipv6_recvancillary; 9872263Ssommerfe 9882263Ssommerfe /* Copy IP-layer options */ 9892263Ssommerfe connp = sctp->sctp_connp; 9902263Ssommerfe pconnp = psctp->sctp_connp; 9912263Ssommerfe 9922263Ssommerfe connp->conn_broadcast = pconnp->conn_broadcast; 9932263Ssommerfe connp->conn_loopback = pconnp->conn_loopback; 9942263Ssommerfe connp->conn_dontroute = pconnp->conn_dontroute; 9952263Ssommerfe connp->conn_reuseaddr = pconnp->conn_reuseaddr; 9962263Ssommerfe 9970Sstevel@tonic-gate } else { 9980Sstevel@tonic-gate /* 9990Sstevel@tonic-gate * Initialize the header template 10000Sstevel@tonic-gate */ 10010Sstevel@tonic-gate if ((err = sctp_header_init_ipv4(sctp, sleep)) != 0) { 10020Sstevel@tonic-gate return (err); 10030Sstevel@tonic-gate } 10040Sstevel@tonic-gate if ((err = sctp_header_init_ipv6(sctp, sleep)) != 0) { 10050Sstevel@tonic-gate return (err); 10060Sstevel@tonic-gate } 10070Sstevel@tonic-gate 10080Sstevel@tonic-gate /* 10090Sstevel@tonic-gate * Set to system defaults 10100Sstevel@tonic-gate */ 1011*3448Sdh155122 sctp->sctp_cookie_lifetime = 1012*3448Sdh155122 MSEC_TO_TICK(sctps->sctps_cookie_life); 1013*3448Sdh155122 sctp->sctp_xmit_lowater = sctps->sctps_xmit_lowat; 1014*3448Sdh155122 sctp->sctp_xmit_hiwater = sctps->sctps_xmit_hiwat; 1015*3448Sdh155122 sctp->sctp_cwnd_max = sctps->sctps_cwnd_max_; 1016*3448Sdh155122 sctp->sctp_rwnd = sctps->sctps_recv_hiwat; 1017852Svi117747 sctp->sctp_irwnd = sctp->sctp_rwnd; 1018*3448Sdh155122 sctp->sctp_rto_max = MSEC_TO_TICK(sctps->sctps_rto_maxg); 10190Sstevel@tonic-gate sctp->sctp_init_rto_max = sctp->sctp_rto_max; 1020*3448Sdh155122 sctp->sctp_rto_min = MSEC_TO_TICK(sctps->sctps_rto_ming); 1021*3448Sdh155122 sctp->sctp_rto_initial = MSEC_TO_TICK( 1022*3448Sdh155122 sctps->sctps_rto_initialg); 1023*3448Sdh155122 sctp->sctp_pa_max_rxt = sctps->sctps_pa_max_retr; 1024*3448Sdh155122 sctp->sctp_pp_max_rxt = sctps->sctps_pp_max_retr; 1025*3448Sdh155122 sctp->sctp_max_init_rxt = sctps->sctps_max_init_retr; 10260Sstevel@tonic-gate 1027*3448Sdh155122 sctp->sctp_num_istr = sctps->sctps_max_in_streams; 1028*3448Sdh155122 sctp->sctp_num_ostr = sctps->sctps_initial_out_streams; 10290Sstevel@tonic-gate 1030*3448Sdh155122 sctp->sctp_hb_interval = 1031*3448Sdh155122 MSEC_TO_TICK(sctps->sctps_heartbeat_interval); 10320Sstevel@tonic-gate } 10330Sstevel@tonic-gate sctp->sctp_understands_asconf = B_TRUE; 10340Sstevel@tonic-gate sctp->sctp_understands_addip = B_TRUE; 10350Sstevel@tonic-gate sctp->sctp_prsctp_aware = B_FALSE; 10360Sstevel@tonic-gate 10370Sstevel@tonic-gate sctp->sctp_connp->conn_ref = 1; 10380Sstevel@tonic-gate sctp->sctp_connp->conn_fully_bound = B_FALSE; 10390Sstevel@tonic-gate 10400Sstevel@tonic-gate sctp->sctp_prsctpdrop = 0; 10410Sstevel@tonic-gate sctp->sctp_msgcount = 0; 10420Sstevel@tonic-gate 10430Sstevel@tonic-gate return (0); 10440Sstevel@tonic-gate } 10450Sstevel@tonic-gate 10460Sstevel@tonic-gate /* 10470Sstevel@tonic-gate * Extracts the init tag from an INIT chunk and checks if it matches 10480Sstevel@tonic-gate * the sctp's verification tag. Returns 0 if it doesn't match, 1 if 10490Sstevel@tonic-gate * it does. 10500Sstevel@tonic-gate */ 10510Sstevel@tonic-gate static boolean_t 10520Sstevel@tonic-gate sctp_icmp_verf(sctp_t *sctp, sctp_hdr_t *sh, mblk_t *mp) 10530Sstevel@tonic-gate { 10540Sstevel@tonic-gate sctp_chunk_hdr_t *sch; 10550Sstevel@tonic-gate uint32_t verf, *vp; 10560Sstevel@tonic-gate 10570Sstevel@tonic-gate sch = (sctp_chunk_hdr_t *)(sh + 1); 10580Sstevel@tonic-gate vp = (uint32_t *)(sch + 1); 10590Sstevel@tonic-gate 10600Sstevel@tonic-gate /* Need at least the data chunk hdr and the first 4 bytes of INIT */ 10610Sstevel@tonic-gate if ((unsigned char *)(vp + 1) > mp->b_wptr) { 10620Sstevel@tonic-gate return (B_FALSE); 10630Sstevel@tonic-gate } 10640Sstevel@tonic-gate 10650Sstevel@tonic-gate bcopy(vp, &verf, sizeof (verf)); 10660Sstevel@tonic-gate 10670Sstevel@tonic-gate if (verf == sctp->sctp_lvtag) { 10680Sstevel@tonic-gate return (B_TRUE); 10690Sstevel@tonic-gate } 10700Sstevel@tonic-gate return (B_FALSE); 10710Sstevel@tonic-gate } 10720Sstevel@tonic-gate 10730Sstevel@tonic-gate /* 10740Sstevel@tonic-gate * sctp_icmp_error is called by sctp_input() to process ICMP error messages 10750Sstevel@tonic-gate * passed up by IP. The queue is the default queue. We need to find a sctp_t 10760Sstevel@tonic-gate * that corresponds to the returned datagram. Passes the message back in on 10770Sstevel@tonic-gate * the correct queue once it has located the connection. 10780Sstevel@tonic-gate * Assumes that IP has pulled up everything up to and including 10790Sstevel@tonic-gate * the ICMP header. 10800Sstevel@tonic-gate */ 10810Sstevel@tonic-gate void 10820Sstevel@tonic-gate sctp_icmp_error(sctp_t *sctp, mblk_t *mp) 10830Sstevel@tonic-gate { 10840Sstevel@tonic-gate icmph_t *icmph; 10850Sstevel@tonic-gate ipha_t *ipha; 10860Sstevel@tonic-gate int iph_hdr_length; 10870Sstevel@tonic-gate sctp_hdr_t *sctph; 10880Sstevel@tonic-gate mblk_t *first_mp; 10890Sstevel@tonic-gate uint32_t new_mtu; 10900Sstevel@tonic-gate in6_addr_t dst; 10910Sstevel@tonic-gate sctp_faddr_t *fp; 1092*3448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 10930Sstevel@tonic-gate 10941676Sjpk dprint(1, ("sctp_icmp_error: sctp=%p, mp=%p\n", (void *)sctp, 10951676Sjpk (void *)mp)); 10960Sstevel@tonic-gate 10970Sstevel@tonic-gate first_mp = mp; 10980Sstevel@tonic-gate 10990Sstevel@tonic-gate ipha = (ipha_t *)mp->b_rptr; 11000Sstevel@tonic-gate if (IPH_HDR_VERSION(ipha) != IPV4_VERSION) { 11010Sstevel@tonic-gate ASSERT(IPH_HDR_VERSION(ipha) == IPV6_VERSION); 11020Sstevel@tonic-gate sctp_icmp_error_ipv6(sctp, first_mp); 11030Sstevel@tonic-gate return; 11040Sstevel@tonic-gate } 11050Sstevel@tonic-gate 11060Sstevel@tonic-gate iph_hdr_length = IPH_HDR_LENGTH(ipha); 11070Sstevel@tonic-gate icmph = (icmph_t *)&mp->b_rptr[iph_hdr_length]; 11080Sstevel@tonic-gate ipha = (ipha_t *)&icmph[1]; 11090Sstevel@tonic-gate iph_hdr_length = IPH_HDR_LENGTH(ipha); 11100Sstevel@tonic-gate sctph = (sctp_hdr_t *)((char *)ipha + iph_hdr_length); 11110Sstevel@tonic-gate if ((uchar_t *)(sctph + 1) >= mp->b_wptr) { 11120Sstevel@tonic-gate /* not enough data for SCTP header */ 11130Sstevel@tonic-gate freemsg(first_mp); 11140Sstevel@tonic-gate return; 11150Sstevel@tonic-gate } 11160Sstevel@tonic-gate 11170Sstevel@tonic-gate switch (icmph->icmph_type) { 11180Sstevel@tonic-gate case ICMP_DEST_UNREACHABLE: 11190Sstevel@tonic-gate switch (icmph->icmph_code) { 11200Sstevel@tonic-gate case ICMP_FRAGMENTATION_NEEDED: 11210Sstevel@tonic-gate /* 11220Sstevel@tonic-gate * Reduce the MSS based on the new MTU. This will 11230Sstevel@tonic-gate * eliminate any fragmentation locally. 11240Sstevel@tonic-gate * N.B. There may well be some funny side-effects on 11250Sstevel@tonic-gate * the local send policy and the remote receive policy. 11260Sstevel@tonic-gate * Pending further research, we provide 11270Sstevel@tonic-gate * sctp_ignore_path_mtu just in case this proves 11280Sstevel@tonic-gate * disastrous somewhere. 11290Sstevel@tonic-gate * 11300Sstevel@tonic-gate * After updating the MSS, retransmit part of the 11310Sstevel@tonic-gate * dropped segment using the new mss by calling 11320Sstevel@tonic-gate * sctp_wput_slow(). Need to adjust all those 11330Sstevel@tonic-gate * params to make sure sctp_wput_slow() work properly. 11340Sstevel@tonic-gate */ 1135*3448Sdh155122 if (sctps->sctps_ignore_path_mtu) 11360Sstevel@tonic-gate break; 11370Sstevel@tonic-gate 11380Sstevel@tonic-gate /* find the offending faddr */ 11390Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(ipha->ipha_dst, &dst); 11400Sstevel@tonic-gate fp = sctp_lookup_faddr(sctp, &dst); 11410Sstevel@tonic-gate if (fp == NULL) { 11420Sstevel@tonic-gate break; 11430Sstevel@tonic-gate } 11440Sstevel@tonic-gate 11450Sstevel@tonic-gate new_mtu = ntohs(icmph->icmph_du_mtu); 11460Sstevel@tonic-gate 11470Sstevel@tonic-gate if (new_mtu - sctp->sctp_hdr_len >= fp->sfa_pmss) 11480Sstevel@tonic-gate break; 11490Sstevel@tonic-gate 11500Sstevel@tonic-gate /* 11510Sstevel@tonic-gate * Make sure that sfa_pmss is a multiple of 11520Sstevel@tonic-gate * SCTP_ALIGN. 11530Sstevel@tonic-gate */ 11540Sstevel@tonic-gate fp->sfa_pmss = (new_mtu - sctp->sctp_hdr_len) & 11550Sstevel@tonic-gate ~(SCTP_ALIGN - 1); 11560Sstevel@tonic-gate fp->pmtu_discovered = 1; 11570Sstevel@tonic-gate 11580Sstevel@tonic-gate break; 11590Sstevel@tonic-gate case ICMP_PORT_UNREACHABLE: 11600Sstevel@tonic-gate case ICMP_PROTOCOL_UNREACHABLE: 11610Sstevel@tonic-gate switch (sctp->sctp_state) { 11620Sstevel@tonic-gate case SCTPS_COOKIE_WAIT: 11630Sstevel@tonic-gate case SCTPS_COOKIE_ECHOED: 11640Sstevel@tonic-gate /* make sure the verification tag matches */ 11650Sstevel@tonic-gate if (!sctp_icmp_verf(sctp, sctph, mp)) { 11660Sstevel@tonic-gate break; 11670Sstevel@tonic-gate } 1168*3448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpAborted); 11693314Skcpoon sctp_assoc_event(sctp, SCTP_CANT_STR_ASSOC, 0, 11703314Skcpoon NULL); 11710Sstevel@tonic-gate sctp_clean_death(sctp, ECONNREFUSED); 11720Sstevel@tonic-gate break; 11730Sstevel@tonic-gate } 11740Sstevel@tonic-gate break; 11750Sstevel@tonic-gate case ICMP_HOST_UNREACHABLE: 11760Sstevel@tonic-gate case ICMP_NET_UNREACHABLE: 11770Sstevel@tonic-gate /* Record the error in case we finally time out. */ 11780Sstevel@tonic-gate sctp->sctp_client_errno = (icmph->icmph_code == 11790Sstevel@tonic-gate ICMP_HOST_UNREACHABLE) ? EHOSTUNREACH : ENETUNREACH; 11800Sstevel@tonic-gate break; 11810Sstevel@tonic-gate default: 11820Sstevel@tonic-gate break; 11830Sstevel@tonic-gate } 11840Sstevel@tonic-gate break; 11850Sstevel@tonic-gate case ICMP_SOURCE_QUENCH: { 11860Sstevel@tonic-gate /* Reduce the sending rate as if we got a retransmit timeout */ 11870Sstevel@tonic-gate break; 11880Sstevel@tonic-gate } 11890Sstevel@tonic-gate } 11900Sstevel@tonic-gate freemsg(first_mp); 11910Sstevel@tonic-gate } 11920Sstevel@tonic-gate 11930Sstevel@tonic-gate /* 11940Sstevel@tonic-gate * sctp_icmp_error_ipv6() is called by sctp_icmp_error() to process ICMPv6 11950Sstevel@tonic-gate * error messages passed up by IP. 11960Sstevel@tonic-gate * Assumes that IP has pulled up all the extension headers as well 11970Sstevel@tonic-gate * as the ICMPv6 header. 11980Sstevel@tonic-gate */ 11990Sstevel@tonic-gate static void 12000Sstevel@tonic-gate sctp_icmp_error_ipv6(sctp_t *sctp, mblk_t *mp) 12010Sstevel@tonic-gate { 12020Sstevel@tonic-gate icmp6_t *icmp6; 12030Sstevel@tonic-gate ip6_t *ip6h; 12040Sstevel@tonic-gate uint16_t iph_hdr_length; 12050Sstevel@tonic-gate sctp_hdr_t *sctpha; 12060Sstevel@tonic-gate uint8_t *nexthdrp; 12070Sstevel@tonic-gate uint32_t new_mtu; 12080Sstevel@tonic-gate sctp_faddr_t *fp; 1209*3448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 12100Sstevel@tonic-gate 12110Sstevel@tonic-gate ip6h = (ip6_t *)mp->b_rptr; 12120Sstevel@tonic-gate iph_hdr_length = (ip6h->ip6_nxt != IPPROTO_SCTP) ? 12130Sstevel@tonic-gate ip_hdr_length_v6(mp, ip6h) : IPV6_HDR_LEN; 12140Sstevel@tonic-gate 12150Sstevel@tonic-gate icmp6 = (icmp6_t *)&mp->b_rptr[iph_hdr_length]; 12160Sstevel@tonic-gate ip6h = (ip6_t *)&icmp6[1]; 12170Sstevel@tonic-gate if (!ip_hdr_length_nexthdr_v6(mp, ip6h, &iph_hdr_length, &nexthdrp)) { 12180Sstevel@tonic-gate freemsg(mp); 12190Sstevel@tonic-gate return; 12200Sstevel@tonic-gate } 12210Sstevel@tonic-gate ASSERT(*nexthdrp == IPPROTO_SCTP); 12220Sstevel@tonic-gate 12230Sstevel@tonic-gate /* XXX need ifindex to find connection */ 12240Sstevel@tonic-gate sctpha = (sctp_hdr_t *)((char *)ip6h + iph_hdr_length); 12250Sstevel@tonic-gate if ((uchar_t *)sctpha >= mp->b_wptr) { 12260Sstevel@tonic-gate /* not enough data for SCTP header */ 12270Sstevel@tonic-gate freemsg(mp); 12280Sstevel@tonic-gate return; 12290Sstevel@tonic-gate } 12300Sstevel@tonic-gate switch (icmp6->icmp6_type) { 12310Sstevel@tonic-gate case ICMP6_PACKET_TOO_BIG: 12320Sstevel@tonic-gate /* 12330Sstevel@tonic-gate * Reduce the MSS based on the new MTU. This will 12340Sstevel@tonic-gate * eliminate any fragmentation locally. 12350Sstevel@tonic-gate * N.B. There may well be some funny side-effects on 12360Sstevel@tonic-gate * the local send policy and the remote receive policy. 12370Sstevel@tonic-gate * Pending further research, we provide 12380Sstevel@tonic-gate * sctp_ignore_path_mtu just in case this proves 12390Sstevel@tonic-gate * disastrous somewhere. 12400Sstevel@tonic-gate * 12410Sstevel@tonic-gate * After updating the MSS, retransmit part of the 12420Sstevel@tonic-gate * dropped segment using the new mss by calling 12430Sstevel@tonic-gate * sctp_wput_slow(). Need to adjust all those 12440Sstevel@tonic-gate * params to make sure sctp_wput_slow() work properly. 12450Sstevel@tonic-gate */ 1246*3448Sdh155122 if (sctps->sctps_ignore_path_mtu) 12470Sstevel@tonic-gate break; 12480Sstevel@tonic-gate 12490Sstevel@tonic-gate /* find the offending faddr */ 12500Sstevel@tonic-gate fp = sctp_lookup_faddr(sctp, &ip6h->ip6_dst); 12510Sstevel@tonic-gate if (fp == NULL) { 12520Sstevel@tonic-gate break; 12530Sstevel@tonic-gate } 12540Sstevel@tonic-gate 12550Sstevel@tonic-gate new_mtu = ntohs(icmp6->icmp6_mtu); 12560Sstevel@tonic-gate 12570Sstevel@tonic-gate if (new_mtu - sctp->sctp_hdr6_len >= fp->sfa_pmss) 12580Sstevel@tonic-gate break; 12590Sstevel@tonic-gate 12600Sstevel@tonic-gate /* Make sure that sfa_pmss is a multiple of SCTP_ALIGN. */ 12610Sstevel@tonic-gate fp->sfa_pmss = (new_mtu - sctp->sctp_hdr6_len) & 12620Sstevel@tonic-gate ~(SCTP_ALIGN - 1); 12630Sstevel@tonic-gate fp->pmtu_discovered = 1; 12640Sstevel@tonic-gate 12650Sstevel@tonic-gate break; 12660Sstevel@tonic-gate 12670Sstevel@tonic-gate case ICMP6_DST_UNREACH: 12680Sstevel@tonic-gate switch (icmp6->icmp6_code) { 12690Sstevel@tonic-gate case ICMP6_DST_UNREACH_NOPORT: 12700Sstevel@tonic-gate /* make sure the verification tag matches */ 12710Sstevel@tonic-gate if (!sctp_icmp_verf(sctp, sctpha, mp)) { 12720Sstevel@tonic-gate break; 12730Sstevel@tonic-gate } 12740Sstevel@tonic-gate if (sctp->sctp_state == SCTPS_COOKIE_WAIT || 12750Sstevel@tonic-gate sctp->sctp_state == SCTPS_COOKIE_ECHOED) { 1276*3448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpAborted); 12773314Skcpoon sctp_assoc_event(sctp, SCTP_CANT_STR_ASSOC, 0, 12783314Skcpoon NULL); 12790Sstevel@tonic-gate sctp_clean_death(sctp, ECONNREFUSED); 12800Sstevel@tonic-gate } 12810Sstevel@tonic-gate break; 12820Sstevel@tonic-gate 12830Sstevel@tonic-gate case ICMP6_DST_UNREACH_ADMIN: 12840Sstevel@tonic-gate case ICMP6_DST_UNREACH_NOROUTE: 12850Sstevel@tonic-gate case ICMP6_DST_UNREACH_NOTNEIGHBOR: 12860Sstevel@tonic-gate case ICMP6_DST_UNREACH_ADDR: 12870Sstevel@tonic-gate /* Record the error in case we finally time out. */ 12880Sstevel@tonic-gate sctp->sctp_client_errno = EHOSTUNREACH; 12890Sstevel@tonic-gate break; 12900Sstevel@tonic-gate default: 12910Sstevel@tonic-gate break; 12920Sstevel@tonic-gate } 12930Sstevel@tonic-gate break; 12940Sstevel@tonic-gate 12950Sstevel@tonic-gate case ICMP6_PARAM_PROB: 12960Sstevel@tonic-gate /* If this corresponds to an ICMP_PROTOCOL_UNREACHABLE */ 12970Sstevel@tonic-gate if (icmp6->icmp6_code == ICMP6_PARAMPROB_NEXTHEADER && 12980Sstevel@tonic-gate (uchar_t *)ip6h + icmp6->icmp6_pptr == 12990Sstevel@tonic-gate (uchar_t *)nexthdrp) { 13000Sstevel@tonic-gate /* make sure the verification tag matches */ 13010Sstevel@tonic-gate if (!sctp_icmp_verf(sctp, sctpha, mp)) { 13020Sstevel@tonic-gate break; 13030Sstevel@tonic-gate } 13040Sstevel@tonic-gate if (sctp->sctp_state == SCTPS_COOKIE_WAIT) { 1305*3448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpAborted); 13063314Skcpoon sctp_assoc_event(sctp, SCTP_CANT_STR_ASSOC, 0, 13073314Skcpoon NULL); 13080Sstevel@tonic-gate sctp_clean_death(sctp, ECONNREFUSED); 13090Sstevel@tonic-gate } 13100Sstevel@tonic-gate break; 13110Sstevel@tonic-gate } 13120Sstevel@tonic-gate break; 13130Sstevel@tonic-gate 13140Sstevel@tonic-gate case ICMP6_TIME_EXCEEDED: 13150Sstevel@tonic-gate default: 13160Sstevel@tonic-gate break; 13170Sstevel@tonic-gate } 13180Sstevel@tonic-gate freemsg(mp); 13190Sstevel@tonic-gate } 13200Sstevel@tonic-gate 13210Sstevel@tonic-gate /* 13220Sstevel@tonic-gate * Called by sockfs to create a new sctp instance. 13230Sstevel@tonic-gate * 13240Sstevel@tonic-gate * If parent pointer is passed in, inherit settings from it. 13250Sstevel@tonic-gate */ 13260Sstevel@tonic-gate sctp_t * 13270Sstevel@tonic-gate sctp_create(void *sctp_ulpd, sctp_t *parent, int family, int flags, 13280Sstevel@tonic-gate const sctp_upcalls_t *sctp_upcalls, sctp_sockbuf_limits_t *sbl, 13290Sstevel@tonic-gate cred_t *credp) 13300Sstevel@tonic-gate { 13310Sstevel@tonic-gate sctp_t *sctp, *psctp; 13320Sstevel@tonic-gate conn_t *sctp_connp; 13330Sstevel@tonic-gate mblk_t *ack_mp, *hb_mp; 13340Sstevel@tonic-gate int sleep = flags & SCTP_CAN_BLOCK ? KM_SLEEP : KM_NOSLEEP; 1335*3448Sdh155122 zoneid_t zoneid; 1336*3448Sdh155122 sctp_stack_t *sctps; 13370Sstevel@tonic-gate 13380Sstevel@tonic-gate /* User must supply a credential. */ 13390Sstevel@tonic-gate if (credp == NULL) 13400Sstevel@tonic-gate return (NULL); 13410Sstevel@tonic-gate 1342*3448Sdh155122 psctp = (sctp_t *)parent; 1343*3448Sdh155122 if (psctp != NULL) { 1344*3448Sdh155122 sctps = psctp->sctp_sctps; 1345*3448Sdh155122 /* Increase here to have common decrease at end */ 1346*3448Sdh155122 netstack_hold(sctps->sctps_netstack); 1347*3448Sdh155122 } else { 1348*3448Sdh155122 netstack_t *ns; 1349*3448Sdh155122 1350*3448Sdh155122 ns = netstack_find_by_cred(credp); 1351*3448Sdh155122 ASSERT(ns != NULL); 1352*3448Sdh155122 sctps = ns->netstack_sctp; 1353*3448Sdh155122 ASSERT(sctps != NULL); 1354*3448Sdh155122 1355*3448Sdh155122 /* 1356*3448Sdh155122 * For exclusive stacks we set the zoneid to zero 1357*3448Sdh155122 * to make SCTP operate as if in the global zone. 1358*3448Sdh155122 */ 1359*3448Sdh155122 if (sctps->sctps_netstack->netstack_stackid != 1360*3448Sdh155122 GLOBAL_NETSTACKID) 1361*3448Sdh155122 zoneid = GLOBAL_ZONEID; 1362*3448Sdh155122 else 1363*3448Sdh155122 zoneid = crgetzoneid(credp); 1364*3448Sdh155122 1365*3448Sdh155122 /* 1366*3448Sdh155122 * For stackid zero this is done from strplumb.c, but 1367*3448Sdh155122 * non-zero stackids are handled here. 1368*3448Sdh155122 */ 1369*3448Sdh155122 if (sctps->sctps_g_q == NULL && 1370*3448Sdh155122 sctps->sctps_netstack->netstack_stackid != 1371*3448Sdh155122 GLOBAL_NETSTACKID) { 1372*3448Sdh155122 sctp_g_q_setup(sctps); 1373*3448Sdh155122 } 1374*3448Sdh155122 } 1375*3448Sdh155122 if ((sctp_connp = ipcl_conn_create(IPCL_SCTPCONN, sleep, 1376*3448Sdh155122 sctps->sctps_netstack)) == NULL) { 1377*3448Sdh155122 netstack_rele(sctps->sctps_netstack); 1378*3448Sdh155122 SCTP_KSTAT(sctps, sctp_conn_create); 13790Sstevel@tonic-gate return (NULL); 13801735Skcpoon } 1381*3448Sdh155122 /* 1382*3448Sdh155122 * ipcl_conn_create did a netstack_hold. Undo the hold that was 1383*3448Sdh155122 * done at top of sctp_create. 1384*3448Sdh155122 */ 1385*3448Sdh155122 netstack_rele(sctps->sctps_netstack); 1386*3448Sdh155122 sctp = CONN2SCTP(sctp_connp); 1387*3448Sdh155122 sctp->sctp_sctps = sctps; 13881676Sjpk 1389*3448Sdh155122 sctp_connp->conn_ulp_labeled = is_system_labeled(); 13900Sstevel@tonic-gate if ((ack_mp = sctp_timer_alloc(sctp, sctp_ack_timer)) == NULL || 13910Sstevel@tonic-gate (hb_mp = sctp_timer_alloc(sctp, sctp_heartbeat_timer)) == NULL) { 13920Sstevel@tonic-gate if (ack_mp != NULL) 13930Sstevel@tonic-gate freeb(ack_mp); 1394*3448Sdh155122 netstack_rele(sctp_connp->conn_netstack); 1395*3448Sdh155122 sctp_connp->conn_netstack = NULL; 1396*3448Sdh155122 sctp->sctp_sctps = NULL; 1397*3448Sdh155122 SCTP_G_Q_REFRELE(sctps); 13980Sstevel@tonic-gate kmem_cache_free(sctp_conn_cache, sctp_connp); 13990Sstevel@tonic-gate return (NULL); 14000Sstevel@tonic-gate } 14010Sstevel@tonic-gate 14020Sstevel@tonic-gate sctp->sctp_ack_mp = ack_mp; 14030Sstevel@tonic-gate sctp->sctp_heartbeat_mp = hb_mp; 14040Sstevel@tonic-gate 14050Sstevel@tonic-gate switch (family) { 14060Sstevel@tonic-gate case AF_INET6: 14070Sstevel@tonic-gate sctp_connp->conn_af_isv6 = B_TRUE; 14080Sstevel@tonic-gate sctp->sctp_ipversion = IPV6_VERSION; 14090Sstevel@tonic-gate sctp->sctp_family = AF_INET6; 14100Sstevel@tonic-gate break; 14110Sstevel@tonic-gate 14120Sstevel@tonic-gate case AF_INET: 14130Sstevel@tonic-gate sctp_connp->conn_af_isv6 = B_FALSE; 14140Sstevel@tonic-gate sctp_connp->conn_pkt_isv6 = B_FALSE; 14150Sstevel@tonic-gate sctp->sctp_ipversion = IPV4_VERSION; 14160Sstevel@tonic-gate sctp->sctp_family = AF_INET; 14170Sstevel@tonic-gate break; 14180Sstevel@tonic-gate default: 14190Sstevel@tonic-gate ASSERT(0); 14200Sstevel@tonic-gate break; 14210Sstevel@tonic-gate } 14220Sstevel@tonic-gate if (sctp_init_values(sctp, psctp, sleep) != 0) { 14230Sstevel@tonic-gate freeb(ack_mp); 14240Sstevel@tonic-gate freeb(hb_mp); 1425*3448Sdh155122 netstack_rele(sctp_connp->conn_netstack); 1426*3448Sdh155122 sctp_connp->conn_netstack = NULL; 1427*3448Sdh155122 sctp->sctp_sctps = NULL; 1428*3448Sdh155122 SCTP_G_Q_REFRELE(sctps); 14290Sstevel@tonic-gate kmem_cache_free(sctp_conn_cache, sctp_connp); 14300Sstevel@tonic-gate return (NULL); 14310Sstevel@tonic-gate } 14320Sstevel@tonic-gate sctp->sctp_cansleep = ((flags & SCTP_CAN_BLOCK) == SCTP_CAN_BLOCK); 14330Sstevel@tonic-gate 1434*3448Sdh155122 sctp->sctp_mss = sctps->sctps_initial_mtu - ((family == AF_INET6) ? 14350Sstevel@tonic-gate sctp->sctp_hdr6_len : sctp->sctp_hdr_len); 14360Sstevel@tonic-gate 14370Sstevel@tonic-gate if (psctp != NULL) { 14380Sstevel@tonic-gate RUN_SCTP(psctp); 14390Sstevel@tonic-gate /* 14400Sstevel@tonic-gate * Inherit local address list, local port. Parent is either 14410Sstevel@tonic-gate * in SCTPS_BOUND, or SCTPS_LISTEN state. 14420Sstevel@tonic-gate */ 14430Sstevel@tonic-gate ASSERT((psctp->sctp_state == SCTPS_BOUND) || 14440Sstevel@tonic-gate (psctp->sctp_state == SCTPS_LISTEN)); 14450Sstevel@tonic-gate if (sctp_dup_saddrs(psctp, sctp, sleep)) { 14460Sstevel@tonic-gate WAKE_SCTP(psctp); 14470Sstevel@tonic-gate freeb(ack_mp); 14480Sstevel@tonic-gate freeb(hb_mp); 14490Sstevel@tonic-gate sctp_headers_free(sctp); 1450*3448Sdh155122 netstack_rele(sctps->sctps_netstack); 1451*3448Sdh155122 sctp_connp->conn_netstack = NULL; 1452*3448Sdh155122 sctp->sctp_sctps = NULL; 1453*3448Sdh155122 SCTP_G_Q_REFRELE(sctps); 14540Sstevel@tonic-gate kmem_cache_free(sctp_conn_cache, sctp_connp); 14550Sstevel@tonic-gate return (NULL); 14560Sstevel@tonic-gate } 14570Sstevel@tonic-gate 14580Sstevel@tonic-gate /* 14590Sstevel@tonic-gate * If the parent is specified, it'll be immediatelly 14600Sstevel@tonic-gate * followed by sctp_connect(). So don't add this guy to 14610Sstevel@tonic-gate * bind hash. 14620Sstevel@tonic-gate */ 14630Sstevel@tonic-gate sctp->sctp_lport = psctp->sctp_lport; 14640Sstevel@tonic-gate sctp->sctp_state = SCTPS_BOUND; 14652263Ssommerfe sctp->sctp_allzones = psctp->sctp_allzones; 14660Sstevel@tonic-gate sctp->sctp_zoneid = psctp->sctp_zoneid; 14670Sstevel@tonic-gate WAKE_SCTP(psctp); 14680Sstevel@tonic-gate } else { 1469*3448Sdh155122 sctp->sctp_zoneid = zoneid; 14700Sstevel@tonic-gate } 14710Sstevel@tonic-gate 14720Sstevel@tonic-gate sctp_connp->conn_cred = credp; 14730Sstevel@tonic-gate crhold(credp); 14740Sstevel@tonic-gate 14751676Sjpk /* 14761676Sjpk * If the caller has the process-wide flag set, then default to MAC 14771676Sjpk * exempt mode. This allows read-down to unlabeled hosts. 14781676Sjpk */ 14791676Sjpk if (getpflags(NET_MAC_AWARE, credp) != 0) 14801676Sjpk sctp_connp->conn_mac_exempt = B_TRUE; 14811676Sjpk 14820Sstevel@tonic-gate /* Initialize SCTP instance values, our verf tag must never be 0 */ 14830Sstevel@tonic-gate (void) random_get_pseudo_bytes((uint8_t *)&sctp->sctp_lvtag, 14840Sstevel@tonic-gate sizeof (sctp->sctp_lvtag)); 14850Sstevel@tonic-gate if (sctp->sctp_lvtag == 0) 14860Sstevel@tonic-gate sctp->sctp_lvtag = (uint32_t)gethrtime(); 14870Sstevel@tonic-gate ASSERT(sctp->sctp_lvtag != 0); 14880Sstevel@tonic-gate 14890Sstevel@tonic-gate sctp->sctp_ltsn = sctp->sctp_lvtag + 1; 14900Sstevel@tonic-gate sctp->sctp_lcsn = sctp->sctp_ltsn; 14910Sstevel@tonic-gate sctp->sctp_recovery_tsn = sctp->sctp_lastack_rxd = sctp->sctp_ltsn - 1; 14920Sstevel@tonic-gate sctp->sctp_adv_pap = sctp->sctp_lastack_rxd; 14930Sstevel@tonic-gate 14940Sstevel@tonic-gate /* Information required by upper layer */ 14950Sstevel@tonic-gate if (sctp_ulpd != NULL) { 14960Sstevel@tonic-gate sctp->sctp_ulpd = sctp_ulpd; 14970Sstevel@tonic-gate 14980Sstevel@tonic-gate ASSERT(sctp_upcalls != NULL); 14990Sstevel@tonic-gate bcopy(sctp_upcalls, &sctp->sctp_upcalls, 15000Sstevel@tonic-gate sizeof (sctp_upcalls_t)); 15010Sstevel@tonic-gate ASSERT(sbl != NULL); 15020Sstevel@tonic-gate /* Fill in the socket buffer limits for sctpsockfs */ 15030Sstevel@tonic-gate sbl->sbl_txlowat = sctp->sctp_xmit_lowater; 15040Sstevel@tonic-gate sbl->sbl_txbuf = sctp->sctp_xmit_hiwater; 15050Sstevel@tonic-gate sbl->sbl_rxbuf = sctp->sctp_rwnd; 15060Sstevel@tonic-gate sbl->sbl_rxlowat = SCTP_RECV_LOWATER; 15070Sstevel@tonic-gate } 15080Sstevel@tonic-gate /* If no sctp_ulpd, must be creating the default sctp */ 1509*3448Sdh155122 ASSERT(sctp_ulpd != NULL || sctps->sctps_gsctp == NULL); 15100Sstevel@tonic-gate 15110Sstevel@tonic-gate /* Insert this in the global list. */ 1512*3448Sdh155122 SCTP_LINK(sctp, sctps); 15130Sstevel@tonic-gate 15140Sstevel@tonic-gate return (sctp); 15150Sstevel@tonic-gate } 15160Sstevel@tonic-gate 1517*3448Sdh155122 /* 1518*3448Sdh155122 * Make sure we wait until the default queue is setup, yet allow 1519*3448Sdh155122 * sctp_g_q_create() to open a SCTP stream. 1520*3448Sdh155122 * We need to allow sctp_g_q_create() do do an open 1521*3448Sdh155122 * of sctp, hence we compare curhread. 1522*3448Sdh155122 * All others have to wait until the sctps_g_q has been 1523*3448Sdh155122 * setup. 1524*3448Sdh155122 */ 15250Sstevel@tonic-gate void 1526*3448Sdh155122 sctp_g_q_setup(sctp_stack_t *sctps) 1527*3448Sdh155122 { 1528*3448Sdh155122 mutex_enter(&sctps->sctps_g_q_lock); 1529*3448Sdh155122 if (sctps->sctps_g_q != NULL) { 1530*3448Sdh155122 mutex_exit(&sctps->sctps_g_q_lock); 1531*3448Sdh155122 return; 1532*3448Sdh155122 } 1533*3448Sdh155122 if (sctps->sctps_g_q_creator == NULL) { 1534*3448Sdh155122 /* This thread will set it up */ 1535*3448Sdh155122 sctps->sctps_g_q_creator = curthread; 1536*3448Sdh155122 mutex_exit(&sctps->sctps_g_q_lock); 1537*3448Sdh155122 sctp_g_q_create(sctps); 1538*3448Sdh155122 mutex_enter(&sctps->sctps_g_q_lock); 1539*3448Sdh155122 ASSERT(sctps->sctps_g_q_creator == curthread); 1540*3448Sdh155122 sctps->sctps_g_q_creator = NULL; 1541*3448Sdh155122 cv_signal(&sctps->sctps_g_q_cv); 1542*3448Sdh155122 ASSERT(sctps->sctps_g_q != NULL); 1543*3448Sdh155122 mutex_exit(&sctps->sctps_g_q_lock); 1544*3448Sdh155122 return; 1545*3448Sdh155122 } 1546*3448Sdh155122 /* Everybody but the creator has to wait */ 1547*3448Sdh155122 if (sctps->sctps_g_q_creator != curthread) { 1548*3448Sdh155122 while (sctps->sctps_g_q == NULL) 1549*3448Sdh155122 cv_wait(&sctps->sctps_g_q_cv, &sctps->sctps_g_q_lock); 1550*3448Sdh155122 } 1551*3448Sdh155122 mutex_exit(&sctps->sctps_g_q_lock); 1552*3448Sdh155122 } 1553*3448Sdh155122 1554*3448Sdh155122 major_t IP_MAJ; 1555*3448Sdh155122 #define IP "ip" 1556*3448Sdh155122 1557*3448Sdh155122 #define SCTP6DEV "/devices/pseudo/sctp6@0:sctp6" 1558*3448Sdh155122 1559*3448Sdh155122 /* 1560*3448Sdh155122 * Create a default sctp queue here instead of in strplumb 1561*3448Sdh155122 */ 1562*3448Sdh155122 void 1563*3448Sdh155122 sctp_g_q_create(sctp_stack_t *sctps) 15640Sstevel@tonic-gate { 1565*3448Sdh155122 int error; 1566*3448Sdh155122 ldi_handle_t lh = NULL; 1567*3448Sdh155122 ldi_ident_t li = NULL; 1568*3448Sdh155122 int rval; 1569*3448Sdh155122 cred_t *cr; 1570*3448Sdh155122 1571*3448Sdh155122 #ifdef NS_DEBUG 1572*3448Sdh155122 (void) printf("sctp_g_q_create()for stack %d\n", 1573*3448Sdh155122 sctps->sctps_netstack->netstack_stackid); 1574*3448Sdh155122 #endif 1575*3448Sdh155122 1576*3448Sdh155122 ASSERT(sctps->sctps_g_q_creator == curthread); 1577*3448Sdh155122 1578*3448Sdh155122 error = ldi_ident_from_major(IP_MAJ, &li); 1579*3448Sdh155122 if (error) { 1580*3448Sdh155122 #ifdef DEBUG 1581*3448Sdh155122 printf("sctp_g_q_create: lyr ident get failed error %d\n", 1582*3448Sdh155122 error); 1583*3448Sdh155122 #endif 1584*3448Sdh155122 return; 1585*3448Sdh155122 } 1586*3448Sdh155122 1587*3448Sdh155122 cr = zone_get_kcred(netstackid_to_zoneid( 1588*3448Sdh155122 sctps->sctps_netstack->netstack_stackid)); 1589*3448Sdh155122 ASSERT(cr != NULL); 1590*3448Sdh155122 /* 1591*3448Sdh155122 * We set the sctp default queue to IPv6 because IPv4 falls 1592*3448Sdh155122 * back to IPv6 when it can't find a client, but 1593*3448Sdh155122 * IPv6 does not fall back to IPv4. 1594*3448Sdh155122 */ 1595*3448Sdh155122 error = ldi_open_by_name(SCTP6DEV, FREAD|FWRITE, cr, &lh, li); 1596*3448Sdh155122 if (error) { 1597*3448Sdh155122 #ifdef DEBUG 1598*3448Sdh155122 printf("sctp_g_q_create: open of SCTP6DEV failed error %d\n", 1599*3448Sdh155122 error); 1600*3448Sdh155122 #endif 1601*3448Sdh155122 goto out; 1602*3448Sdh155122 } 1603*3448Sdh155122 1604*3448Sdh155122 /* 1605*3448Sdh155122 * This ioctl causes the sctp framework to cache a pointer to 1606*3448Sdh155122 * this stream, so we don't want to close the stream after 1607*3448Sdh155122 * this operation. 1608*3448Sdh155122 * Use the kernel credentials that are for the zone we're in. 1609*3448Sdh155122 */ 1610*3448Sdh155122 error = ldi_ioctl(lh, SCTP_IOC_DEFAULT_Q, 1611*3448Sdh155122 (intptr_t)0, FKIOCTL, cr, &rval); 1612*3448Sdh155122 if (error) { 1613*3448Sdh155122 #ifdef DEBUG 1614*3448Sdh155122 printf("sctp_g_q_create: ioctl SCTP_IOC_DEFAULT_Q failed " 1615*3448Sdh155122 "error %d\n", error); 1616*3448Sdh155122 #endif 1617*3448Sdh155122 goto out; 1618*3448Sdh155122 } 1619*3448Sdh155122 sctps->sctps_g_q_lh = lh; /* For sctp_g_q_inactive */ 1620*3448Sdh155122 lh = NULL; 1621*3448Sdh155122 out: 1622*3448Sdh155122 /* Close layered handles */ 1623*3448Sdh155122 if (li) 1624*3448Sdh155122 ldi_ident_release(li); 1625*3448Sdh155122 /* Keep cred around until _inactive needs it */ 1626*3448Sdh155122 sctps->sctps_g_q_cr = cr; 1627*3448Sdh155122 } 16280Sstevel@tonic-gate 1629*3448Sdh155122 /* 1630*3448Sdh155122 * Remove the sctp_default queue so that new connections will not find it. 1631*3448Sdh155122 * SCTP uses sctp_g_q for all transmission, so all sctp'ts implicitly 1632*3448Sdh155122 * refer to it. Hence have each one have a reference on sctp_g_q_ref! 1633*3448Sdh155122 * 1634*3448Sdh155122 * We decrement the refcnt added in sctp_g_q_create. Once all the 1635*3448Sdh155122 * sctp_t's which use the default go away, sctp_g_q_close will be called 1636*3448Sdh155122 * and close the sctp_g_q. Once sctp_g_q is closed, sctp_close() will drop the 1637*3448Sdh155122 * last reference count on the stack by calling netstack_rele(). 1638*3448Sdh155122 */ 1639*3448Sdh155122 void 1640*3448Sdh155122 sctp_g_q_destroy(sctp_stack_t *sctps) 1641*3448Sdh155122 { 1642*3448Sdh155122 if (sctps->sctps_g_q == NULL) { 1643*3448Sdh155122 return; /* Nothing to cleanup */ 1644*3448Sdh155122 } 1645*3448Sdh155122 /* 1646*3448Sdh155122 * Keep sctps_g_q and sctps_gsctp until the last reference has 1647*3448Sdh155122 * dropped, since the output is always done using those. 1648*3448Sdh155122 * Need to decrement twice to take sctp_g_q_create and 1649*3448Sdh155122 * the gsctp reference into account so that sctp_g_q_inactive is called 1650*3448Sdh155122 * when all but the default queue remains. 1651*3448Sdh155122 */ 1652*3448Sdh155122 #ifdef NS_DEBUG 1653*3448Sdh155122 (void) printf("sctp_g_q_destroy: ref %d\n", 1654*3448Sdh155122 sctps->sctps_g_q_ref); 1655*3448Sdh155122 #endif 1656*3448Sdh155122 SCTP_G_Q_REFRELE(sctps); 1657*3448Sdh155122 } 1658*3448Sdh155122 1659*3448Sdh155122 /* 1660*3448Sdh155122 * Called when last user (could be sctp_g_q_destroy) drops reference count 1661*3448Sdh155122 * using SCTP_G_Q_REFRELE. 1662*3448Sdh155122 * Run by sctp_q_q_inactive using a taskq. 1663*3448Sdh155122 */ 1664*3448Sdh155122 static void 1665*3448Sdh155122 sctp_g_q_close(void *arg) 1666*3448Sdh155122 { 1667*3448Sdh155122 sctp_stack_t *sctps = arg; 1668*3448Sdh155122 int error; 1669*3448Sdh155122 ldi_handle_t lh = NULL; 1670*3448Sdh155122 ldi_ident_t li = NULL; 1671*3448Sdh155122 cred_t *cr; 1672*3448Sdh155122 1673*3448Sdh155122 lh = sctps->sctps_g_q_lh; 1674*3448Sdh155122 if (lh == NULL) 1675*3448Sdh155122 return; /* Nothing to cleanup */ 1676*3448Sdh155122 1677*3448Sdh155122 error = ldi_ident_from_major(IP_MAJ, &li); 1678*3448Sdh155122 if (error) { 1679*3448Sdh155122 #ifdef NS_DEBUG 1680*3448Sdh155122 printf("sctp_g_q_inactive: lyr ident get failed error %d\n", 1681*3448Sdh155122 error); 1682*3448Sdh155122 #endif 1683*3448Sdh155122 return; 1684*3448Sdh155122 } 16850Sstevel@tonic-gate 1686*3448Sdh155122 cr = sctps->sctps_g_q_cr; 1687*3448Sdh155122 sctps->sctps_g_q_cr = NULL; 1688*3448Sdh155122 ASSERT(cr != NULL); 1689*3448Sdh155122 1690*3448Sdh155122 /* 1691*3448Sdh155122 * Make sure we can break the recursion when sctp_close decrements 1692*3448Sdh155122 * the reference count causing g_q_inactive to be called again. 1693*3448Sdh155122 */ 1694*3448Sdh155122 sctps->sctps_g_q_lh = NULL; 1695*3448Sdh155122 1696*3448Sdh155122 /* close the default queue */ 1697*3448Sdh155122 (void) ldi_close(lh, FREAD|FWRITE, cr); 1698*3448Sdh155122 1699*3448Sdh155122 /* Close layered handles */ 1700*3448Sdh155122 ldi_ident_release(li); 1701*3448Sdh155122 crfree(cr); 1702*3448Sdh155122 1703*3448Sdh155122 ASSERT(sctps->sctps_g_q != NULL); 1704*3448Sdh155122 sctps->sctps_g_q = NULL; 1705*3448Sdh155122 /* 1706*3448Sdh155122 * Now free sctps_gsctp. 1707*3448Sdh155122 */ 1708*3448Sdh155122 ASSERT(sctps->sctps_gsctp != NULL); 1709*3448Sdh155122 sctp_closei_local(sctps->sctps_gsctp); 1710*3448Sdh155122 SCTP_CONDEMNED(sctps->sctps_gsctp); 1711*3448Sdh155122 SCTP_REFRELE(sctps->sctps_gsctp); 1712*3448Sdh155122 sctps->sctps_gsctp = NULL; 1713*3448Sdh155122 } 17140Sstevel@tonic-gate 1715*3448Sdh155122 /* 1716*3448Sdh155122 * Called when last sctp_t drops reference count using SCTP_G_Q_REFRELE. 1717*3448Sdh155122 * 1718*3448Sdh155122 * Have to ensure that the ldi routines are not used by an 1719*3448Sdh155122 * interrupt thread by using a taskq. 1720*3448Sdh155122 */ 1721*3448Sdh155122 void 1722*3448Sdh155122 sctp_g_q_inactive(sctp_stack_t *sctps) 1723*3448Sdh155122 { 1724*3448Sdh155122 if (sctps->sctps_g_q_lh == NULL) 1725*3448Sdh155122 return; /* Nothing to cleanup */ 1726*3448Sdh155122 1727*3448Sdh155122 ASSERT(sctps->sctps_g_q_ref == 0); 1728*3448Sdh155122 SCTP_G_Q_REFHOLD(sctps); /* Compensate for what g_q_destroy did */ 1729*3448Sdh155122 1730*3448Sdh155122 if (servicing_interrupt()) { 1731*3448Sdh155122 (void) taskq_dispatch(sctp_taskq, sctp_g_q_close, 1732*3448Sdh155122 (void *) sctps, TQ_SLEEP); 1733*3448Sdh155122 } else { 1734*3448Sdh155122 sctp_g_q_close(sctps); 17350Sstevel@tonic-gate } 1736*3448Sdh155122 } 1737*3448Sdh155122 1738*3448Sdh155122 /* Run at module load time */ 1739*3448Sdh155122 void 1740*3448Sdh155122 sctp_ddi_g_init(void) 1741*3448Sdh155122 { 1742*3448Sdh155122 IP_MAJ = ddi_name_to_major(IP); 17430Sstevel@tonic-gate 17440Sstevel@tonic-gate /* Create sctp_t/conn_t cache */ 17450Sstevel@tonic-gate sctp_conn_cache_init(); 17460Sstevel@tonic-gate 17470Sstevel@tonic-gate /* Create the faddr cache */ 17480Sstevel@tonic-gate sctp_faddr_init(); 17490Sstevel@tonic-gate 17500Sstevel@tonic-gate /* Create the sets cache */ 17510Sstevel@tonic-gate sctp_sets_init(); 17520Sstevel@tonic-gate 17530Sstevel@tonic-gate /* Create the PR-SCTP sets cache */ 17540Sstevel@tonic-gate sctp_ftsn_sets_init(); 17550Sstevel@tonic-gate 17560Sstevel@tonic-gate /* Initialize tables used for CRC calculation */ 17570Sstevel@tonic-gate sctp_crc32_init(); 17580Sstevel@tonic-gate 1759*3448Sdh155122 sctp_taskq = taskq_create("sctp_taskq", 1, minclsyspri, 1, 1, 1760*3448Sdh155122 TASKQ_PREPOPULATE); 1761*3448Sdh155122 1762*3448Sdh155122 /* 1763*3448Sdh155122 * We want to be informed each time a stack is created or 1764*3448Sdh155122 * destroyed in the kernel, so we can maintain the 1765*3448Sdh155122 * set of sctp_stack_t's. 1766*3448Sdh155122 */ 1767*3448Sdh155122 netstack_register(NS_SCTP, sctp_stack_init, sctp_stack_shutdown, 1768*3448Sdh155122 sctp_stack_fini); 17690Sstevel@tonic-gate } 17700Sstevel@tonic-gate 1771*3448Sdh155122 static void * 1772*3448Sdh155122 sctp_stack_init(netstackid_t stackid, netstack_t *ns) 17730Sstevel@tonic-gate { 1774*3448Sdh155122 sctp_stack_t *sctps; 1775*3448Sdh155122 1776*3448Sdh155122 sctps = kmem_zalloc(sizeof (*sctps), KM_SLEEP); 1777*3448Sdh155122 sctps->sctps_netstack = ns; 1778*3448Sdh155122 1779*3448Sdh155122 /* Initialize locks */ 1780*3448Sdh155122 mutex_init(&sctps->sctps_g_q_lock, NULL, MUTEX_DEFAULT, NULL); 1781*3448Sdh155122 cv_init(&sctps->sctps_g_q_cv, NULL, CV_DEFAULT, NULL); 1782*3448Sdh155122 mutex_init(&sctps->sctps_g_lock, NULL, MUTEX_DEFAULT, NULL); 1783*3448Sdh155122 mutex_init(&sctps->sctps_epriv_port_lock, NULL, MUTEX_DEFAULT, NULL); 1784*3448Sdh155122 sctps->sctps_g_num_epriv_ports = SCTP_NUM_EPRIV_PORTS; 1785*3448Sdh155122 sctps->sctps_g_epriv_ports[0] = 2049; 1786*3448Sdh155122 sctps->sctps_g_epriv_ports[1] = 4045; 1787*3448Sdh155122 1788*3448Sdh155122 /* Initialize SCTP hash arrays. */ 1789*3448Sdh155122 sctp_hash_init(sctps); 1790*3448Sdh155122 1791*3448Sdh155122 sctps->sctps_pad_mp = allocb(SCTP_ALIGN, BPRI_MED); 1792*3448Sdh155122 bzero(sctps->sctps_pad_mp->b_rptr, SCTP_ALIGN); 1793*3448Sdh155122 ASSERT(sctps->sctps_pad_mp); 1794*3448Sdh155122 1795*3448Sdh155122 if (!sctp_nd_init(sctps)) { 1796*3448Sdh155122 sctp_nd_free(sctps); 1797*3448Sdh155122 } 17980Sstevel@tonic-gate 1799*3448Sdh155122 /* Initialize the recvq taskq. */ 1800*3448Sdh155122 sctp_rq_tq_init(sctps); 1801*3448Sdh155122 1802*3448Sdh155122 /* saddr init */ 1803*3448Sdh155122 sctp_saddr_init(sctps); 1804*3448Sdh155122 1805*3448Sdh155122 /* Global SCTP PCB list. */ 1806*3448Sdh155122 list_create(&sctps->sctps_g_list, sizeof (sctp_t), 1807*3448Sdh155122 offsetof(sctp_t, sctp_list)); 1808*3448Sdh155122 1809*3448Sdh155122 /* Initialize sctp kernel stats. */ 1810*3448Sdh155122 sctps->sctps_mibkp = sctp_kstat_init(stackid); 1811*3448Sdh155122 sctps->sctps_kstat = 1812*3448Sdh155122 sctp_kstat2_init(stackid, &sctps->sctps_statistics); 1813*3448Sdh155122 1814*3448Sdh155122 return (sctps); 1815*3448Sdh155122 } 1816*3448Sdh155122 1817*3448Sdh155122 /* 1818*3448Sdh155122 * Called when the module is about to be unloaded. 1819*3448Sdh155122 */ 1820*3448Sdh155122 void 1821*3448Sdh155122 sctp_ddi_g_destroy(void) 1822*3448Sdh155122 { 18230Sstevel@tonic-gate /* Destroy sctp_t/conn_t caches */ 18240Sstevel@tonic-gate sctp_conn_cache_fini(); 18250Sstevel@tonic-gate 18260Sstevel@tonic-gate /* Destroy the faddr cache */ 18270Sstevel@tonic-gate sctp_faddr_fini(); 18280Sstevel@tonic-gate 18290Sstevel@tonic-gate /* Destroy the sets cache */ 18300Sstevel@tonic-gate sctp_sets_fini(); 18310Sstevel@tonic-gate 18320Sstevel@tonic-gate /* Destroy the PR-SCTP sets cache */ 18330Sstevel@tonic-gate sctp_ftsn_sets_fini(); 18340Sstevel@tonic-gate 1835*3448Sdh155122 netstack_unregister(NS_SCTP); 1836*3448Sdh155122 taskq_destroy(sctp_taskq); 1837*3448Sdh155122 } 1838*3448Sdh155122 1839*3448Sdh155122 /* 1840*3448Sdh155122 * Shut down the SCTP stack instance. 1841*3448Sdh155122 */ 1842*3448Sdh155122 /* ARGSUSED */ 1843*3448Sdh155122 static void 1844*3448Sdh155122 sctp_stack_shutdown(netstackid_t stackid, void *arg) 1845*3448Sdh155122 { 1846*3448Sdh155122 sctp_stack_t *sctps = (sctp_stack_t *)arg; 1847*3448Sdh155122 1848*3448Sdh155122 sctp_g_q_destroy(sctps); 1849*3448Sdh155122 } 1850*3448Sdh155122 1851*3448Sdh155122 /* 1852*3448Sdh155122 * Free the SCTP stack instance. 1853*3448Sdh155122 */ 1854*3448Sdh155122 static void 1855*3448Sdh155122 sctp_stack_fini(netstackid_t stackid, void *arg) 1856*3448Sdh155122 { 1857*3448Sdh155122 sctp_stack_t *sctps = (sctp_stack_t *)arg; 1858*3448Sdh155122 1859*3448Sdh155122 sctp_nd_free(sctps); 1860*3448Sdh155122 18610Sstevel@tonic-gate /* Destroy the recvq taskqs. */ 1862*3448Sdh155122 sctp_rq_tq_fini(sctps); 18630Sstevel@tonic-gate 18640Sstevel@tonic-gate /* Destroy saddr */ 1865*3448Sdh155122 sctp_saddr_fini(sctps); 18660Sstevel@tonic-gate 18670Sstevel@tonic-gate /* Global SCTP PCB list. */ 1868*3448Sdh155122 list_destroy(&sctps->sctps_g_list); 18690Sstevel@tonic-gate 18700Sstevel@tonic-gate /* Destroy SCTP hash arrays. */ 1871*3448Sdh155122 sctp_hash_destroy(sctps); 1872*3448Sdh155122 1873*3448Sdh155122 /* Destroy SCTP kernel stats. */ 1874*3448Sdh155122 sctp_kstat2_fini(stackid, sctps->sctps_kstat); 1875*3448Sdh155122 sctps->sctps_kstat = NULL; 1876*3448Sdh155122 bzero(&sctps->sctps_statistics, sizeof (sctps->sctps_statistics)); 1877*3448Sdh155122 1878*3448Sdh155122 sctp_kstat_fini(stackid, sctps->sctps_mibkp); 1879*3448Sdh155122 sctps->sctps_mibkp = NULL; 18800Sstevel@tonic-gate 1881*3448Sdh155122 freeb(sctps->sctps_pad_mp); 1882*3448Sdh155122 sctps->sctps_pad_mp = NULL; 18830Sstevel@tonic-gate 1884*3448Sdh155122 mutex_destroy(&sctps->sctps_g_lock); 1885*3448Sdh155122 mutex_destroy(&sctps->sctps_epriv_port_lock); 1886*3448Sdh155122 mutex_destroy(&sctps->sctps_g_q_lock); 1887*3448Sdh155122 cv_destroy(&sctps->sctps_g_q_cv); 1888*3448Sdh155122 1889*3448Sdh155122 kmem_free(sctps, sizeof (*sctps)); 18900Sstevel@tonic-gate } 18910Sstevel@tonic-gate 18920Sstevel@tonic-gate void 1893*3448Sdh155122 sctp_display_all(sctp_stack_t *sctps) 18940Sstevel@tonic-gate { 18950Sstevel@tonic-gate sctp_t *sctp_walker; 18960Sstevel@tonic-gate 1897*3448Sdh155122 mutex_enter(&sctps->sctps_g_lock); 1898*3448Sdh155122 for (sctp_walker = sctps->sctps_gsctp; sctp_walker != NULL; 1899*3448Sdh155122 sctp_walker = (sctp_t *)list_next(&sctps->sctps_g_list, 1900*3448Sdh155122 sctp_walker)) { 19010Sstevel@tonic-gate (void) sctp_display(sctp_walker, NULL); 19020Sstevel@tonic-gate } 1903*3448Sdh155122 mutex_exit(&sctps->sctps_g_lock); 19040Sstevel@tonic-gate } 19050Sstevel@tonic-gate 19060Sstevel@tonic-gate static void 1907*3448Sdh155122 sctp_rq_tq_init(sctp_stack_t *sctps) 19080Sstevel@tonic-gate { 1909*3448Sdh155122 sctps->sctps_recvq_tq_list_max_sz = 16; 1910*3448Sdh155122 sctps->sctps_recvq_tq_list_cur_sz = 1; 19110Sstevel@tonic-gate /* 19120Sstevel@tonic-gate * Initialize the recvq_tq_list and create the first recvq taskq. 19130Sstevel@tonic-gate * What to do if it fails? 19140Sstevel@tonic-gate */ 1915*3448Sdh155122 sctps->sctps_recvq_tq_list = 1916*3448Sdh155122 kmem_zalloc(sctps->sctps_recvq_tq_list_max_sz * sizeof (taskq_t *), 1917*3448Sdh155122 KM_SLEEP); 1918*3448Sdh155122 sctps->sctps_recvq_tq_list[0] = taskq_create("sctp_def_recvq_taskq", 19190Sstevel@tonic-gate MIN(sctp_recvq_tq_thr_max, MAX(sctp_recvq_tq_thr_min, ncpus)), 19200Sstevel@tonic-gate minclsyspri, sctp_recvq_tq_task_min, sctp_recvq_tq_task_max, 19210Sstevel@tonic-gate TASKQ_PREPOPULATE); 1922*3448Sdh155122 mutex_init(&sctps->sctps_rq_tq_lock, NULL, MUTEX_DEFAULT, NULL); 19230Sstevel@tonic-gate } 19240Sstevel@tonic-gate 19250Sstevel@tonic-gate static void 1926*3448Sdh155122 sctp_rq_tq_fini(sctp_stack_t *sctps) 19270Sstevel@tonic-gate { 19280Sstevel@tonic-gate int i; 19290Sstevel@tonic-gate 1930*3448Sdh155122 for (i = 0; i < sctps->sctps_recvq_tq_list_cur_sz; i++) { 1931*3448Sdh155122 ASSERT(sctps->sctps_recvq_tq_list[i] != NULL); 1932*3448Sdh155122 taskq_destroy(sctps->sctps_recvq_tq_list[i]); 19330Sstevel@tonic-gate } 1934*3448Sdh155122 kmem_free(sctps->sctps_recvq_tq_list, 1935*3448Sdh155122 sctps->sctps_recvq_tq_list_max_sz * sizeof (taskq_t *)); 1936*3448Sdh155122 sctps->sctps_recvq_tq_list = NULL; 19370Sstevel@tonic-gate } 19380Sstevel@tonic-gate 19390Sstevel@tonic-gate /* Add another taskq for a new ill. */ 19400Sstevel@tonic-gate void 1941*3448Sdh155122 sctp_inc_taskq(sctp_stack_t *sctps) 19420Sstevel@tonic-gate { 19430Sstevel@tonic-gate taskq_t *tq; 19440Sstevel@tonic-gate char tq_name[TASKQ_NAMELEN]; 19450Sstevel@tonic-gate 1946*3448Sdh155122 mutex_enter(&sctps->sctps_rq_tq_lock); 1947*3448Sdh155122 if (sctps->sctps_recvq_tq_list_cur_sz + 1 > 1948*3448Sdh155122 sctps->sctps_recvq_tq_list_max_sz) { 1949*3448Sdh155122 mutex_exit(&sctps->sctps_rq_tq_lock); 19500Sstevel@tonic-gate cmn_err(CE_NOTE, "Cannot create more SCTP recvq taskq"); 19510Sstevel@tonic-gate return; 19520Sstevel@tonic-gate } 19530Sstevel@tonic-gate 19540Sstevel@tonic-gate (void) snprintf(tq_name, sizeof (tq_name), "sctp_recvq_taskq_%u", 1955*3448Sdh155122 sctps->sctps_recvq_tq_list_cur_sz); 19560Sstevel@tonic-gate tq = taskq_create(tq_name, 19570Sstevel@tonic-gate MIN(sctp_recvq_tq_thr_max, MAX(sctp_recvq_tq_thr_min, ncpus)), 19580Sstevel@tonic-gate minclsyspri, sctp_recvq_tq_task_min, sctp_recvq_tq_task_max, 19590Sstevel@tonic-gate TASKQ_PREPOPULATE); 19600Sstevel@tonic-gate if (tq == NULL) { 1961*3448Sdh155122 mutex_exit(&sctps->sctps_rq_tq_lock); 19620Sstevel@tonic-gate cmn_err(CE_NOTE, "SCTP recvq taskq creation failed"); 19630Sstevel@tonic-gate return; 19640Sstevel@tonic-gate } 1965*3448Sdh155122 ASSERT(sctps->sctps_recvq_tq_list[ 1966*3448Sdh155122 sctps->sctps_recvq_tq_list_cur_sz] == NULL); 1967*3448Sdh155122 sctps->sctps_recvq_tq_list[sctps->sctps_recvq_tq_list_cur_sz] = tq; 1968*3448Sdh155122 atomic_add_32(&sctps->sctps_recvq_tq_list_cur_sz, 1); 1969*3448Sdh155122 mutex_exit(&sctps->sctps_rq_tq_lock); 19700Sstevel@tonic-gate } 19710Sstevel@tonic-gate 19720Sstevel@tonic-gate #ifdef DEBUG 19730Sstevel@tonic-gate uint32_t sendq_loop_cnt = 0; 19740Sstevel@tonic-gate uint32_t sendq_collision = 0; 19750Sstevel@tonic-gate uint32_t sendq_empty = 0; 19760Sstevel@tonic-gate #endif 19770Sstevel@tonic-gate 19780Sstevel@tonic-gate void 19790Sstevel@tonic-gate sctp_add_sendq(sctp_t *sctp, mblk_t *mp) 19800Sstevel@tonic-gate { 19810Sstevel@tonic-gate mutex_enter(&sctp->sctp_sendq_lock); 19820Sstevel@tonic-gate if (sctp->sctp_sendq == NULL) { 19830Sstevel@tonic-gate sctp->sctp_sendq = mp; 19840Sstevel@tonic-gate sctp->sctp_sendq_tail = mp; 19850Sstevel@tonic-gate } else { 19860Sstevel@tonic-gate sctp->sctp_sendq_tail->b_next = mp; 19870Sstevel@tonic-gate sctp->sctp_sendq_tail = mp; 19880Sstevel@tonic-gate } 19890Sstevel@tonic-gate mutex_exit(&sctp->sctp_sendq_lock); 19900Sstevel@tonic-gate } 19910Sstevel@tonic-gate 19920Sstevel@tonic-gate void 19930Sstevel@tonic-gate sctp_process_sendq(sctp_t *sctp) 19940Sstevel@tonic-gate { 19950Sstevel@tonic-gate mblk_t *mp; 19960Sstevel@tonic-gate #ifdef DEBUG 19970Sstevel@tonic-gate uint32_t loop_cnt = 0; 19980Sstevel@tonic-gate #endif 19990Sstevel@tonic-gate 20000Sstevel@tonic-gate mutex_enter(&sctp->sctp_sendq_lock); 20010Sstevel@tonic-gate if (sctp->sctp_sendq == NULL || sctp->sctp_sendq_sending) { 20020Sstevel@tonic-gate #ifdef DEBUG 20030Sstevel@tonic-gate if (sctp->sctp_sendq == NULL) 20040Sstevel@tonic-gate sendq_empty++; 20050Sstevel@tonic-gate else 20060Sstevel@tonic-gate sendq_collision++; 20070Sstevel@tonic-gate #endif 20080Sstevel@tonic-gate mutex_exit(&sctp->sctp_sendq_lock); 20090Sstevel@tonic-gate return; 20100Sstevel@tonic-gate } 20110Sstevel@tonic-gate sctp->sctp_sendq_sending = B_TRUE; 20120Sstevel@tonic-gate 20130Sstevel@tonic-gate /* 20140Sstevel@tonic-gate * Note that while we are in this loop, other thread can put 20150Sstevel@tonic-gate * new packets in the receive queue. We may be looping for 20160Sstevel@tonic-gate * quite a while. This is OK even for an interrupt thread. 20170Sstevel@tonic-gate * The reason is that SCTP should only able to send a limited 20180Sstevel@tonic-gate * number of packets out in a burst. So the number of times 20190Sstevel@tonic-gate * we go through this loop should not be many. 20200Sstevel@tonic-gate */ 20210Sstevel@tonic-gate while ((mp = sctp->sctp_sendq) != NULL) { 20220Sstevel@tonic-gate sctp->sctp_sendq = mp->b_next; 20230Sstevel@tonic-gate ASSERT(sctp->sctp_connp->conn_ref > 0); 20240Sstevel@tonic-gate mutex_exit(&sctp->sctp_sendq_lock); 20250Sstevel@tonic-gate mp->b_next = NULL; 20260Sstevel@tonic-gate CONN_INC_REF(sctp->sctp_connp); 20270Sstevel@tonic-gate mp->b_flag |= MSGHASREF; 20280Sstevel@tonic-gate /* If we don't have sctp_current, default to IPv4 */ 20290Sstevel@tonic-gate IP_PUT(mp, sctp->sctp_connp, sctp->sctp_current == NULL ? 20300Sstevel@tonic-gate B_TRUE : sctp->sctp_current->isv4); 20310Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_opkts); 20320Sstevel@tonic-gate #ifdef DEBUG 20330Sstevel@tonic-gate loop_cnt++; 20340Sstevel@tonic-gate #endif 20350Sstevel@tonic-gate mutex_enter(&sctp->sctp_sendq_lock); 20360Sstevel@tonic-gate } 20370Sstevel@tonic-gate 20380Sstevel@tonic-gate sctp->sctp_sendq_tail = NULL; 20390Sstevel@tonic-gate sctp->sctp_sendq_sending = B_FALSE; 20400Sstevel@tonic-gate #ifdef DEBUG 20410Sstevel@tonic-gate if (loop_cnt > sendq_loop_cnt) 20420Sstevel@tonic-gate sendq_loop_cnt = loop_cnt; 20430Sstevel@tonic-gate #endif 20440Sstevel@tonic-gate mutex_exit(&sctp->sctp_sendq_lock); 20450Sstevel@tonic-gate } 20460Sstevel@tonic-gate 20470Sstevel@tonic-gate #ifdef DEBUG 20480Sstevel@tonic-gate uint32_t recvq_loop_cnt = 0; 20490Sstevel@tonic-gate uint32_t recvq_call = 0; 20500Sstevel@tonic-gate #endif 20510Sstevel@tonic-gate 20520Sstevel@tonic-gate /* 20530Sstevel@tonic-gate * Find the next recvq_tq to use. This routine will go thru all the 20540Sstevel@tonic-gate * taskqs until it can dispatch a job for the sctp. If this fails, 20550Sstevel@tonic-gate * it will create a new taskq and try it. 20560Sstevel@tonic-gate */ 20570Sstevel@tonic-gate static boolean_t 20580Sstevel@tonic-gate sctp_find_next_tq(sctp_t *sctp) 20590Sstevel@tonic-gate { 20600Sstevel@tonic-gate int next_tq, try; 20610Sstevel@tonic-gate taskq_t *tq; 2062*3448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 20630Sstevel@tonic-gate 20640Sstevel@tonic-gate /* 20650Sstevel@tonic-gate * Note that since we don't hold a lock on sctp_rq_tq_lock for 20660Sstevel@tonic-gate * performance reason, recvq_ta_list_cur_sz can be changed during 20670Sstevel@tonic-gate * this loop. The problem this will create is that the loop may 20680Sstevel@tonic-gate * not have tried all the recvq_tq. This should be OK. 20690Sstevel@tonic-gate */ 2070*3448Sdh155122 next_tq = atomic_add_32_nv(&sctps->sctps_recvq_tq_list_cur, 1) % 2071*3448Sdh155122 sctps->sctps_recvq_tq_list_cur_sz; 2072*3448Sdh155122 for (try = 0; try < sctps->sctps_recvq_tq_list_cur_sz; try++) { 2073*3448Sdh155122 tq = sctps->sctps_recvq_tq_list[next_tq]; 20740Sstevel@tonic-gate if (taskq_dispatch(tq, sctp_process_recvq, sctp, 20750Sstevel@tonic-gate TQ_NOSLEEP) != NULL) { 20760Sstevel@tonic-gate sctp->sctp_recvq_tq = tq; 20770Sstevel@tonic-gate return (B_TRUE); 20780Sstevel@tonic-gate } 2079*3448Sdh155122 next_tq = (next_tq + 1) % sctps->sctps_recvq_tq_list_cur_sz; 20800Sstevel@tonic-gate } 20810Sstevel@tonic-gate 20820Sstevel@tonic-gate /* 20830Sstevel@tonic-gate * Create one more taskq and try it. Note that sctp_inc_taskq() 20840Sstevel@tonic-gate * may not have created another taskq if the number of recvq 20850Sstevel@tonic-gate * taskqs is at the maximum. We are probably in a pretty bad 20860Sstevel@tonic-gate * shape if this actually happens... 20870Sstevel@tonic-gate */ 2088*3448Sdh155122 sctp_inc_taskq(sctps); 2089*3448Sdh155122 tq = sctps->sctps_recvq_tq_list[sctps->sctps_recvq_tq_list_cur_sz - 1]; 20900Sstevel@tonic-gate if (taskq_dispatch(tq, sctp_process_recvq, sctp, TQ_NOSLEEP) != NULL) { 20910Sstevel@tonic-gate sctp->sctp_recvq_tq = tq; 20920Sstevel@tonic-gate return (B_TRUE); 20930Sstevel@tonic-gate } 2094*3448Sdh155122 SCTP_KSTAT(sctps, sctp_find_next_tq); 20950Sstevel@tonic-gate return (B_FALSE); 20960Sstevel@tonic-gate } 20970Sstevel@tonic-gate 20980Sstevel@tonic-gate /* 20990Sstevel@tonic-gate * To add a message to the recvq. Note that the sctp_timer_fire() 21000Sstevel@tonic-gate * routine also uses this function to add the timer message to the 21010Sstevel@tonic-gate * receive queue for later processing. And it should be the only 21020Sstevel@tonic-gate * caller of sctp_add_recvq() which sets the try_harder argument 21030Sstevel@tonic-gate * to B_TRUE. 21040Sstevel@tonic-gate * 21050Sstevel@tonic-gate * If the try_harder argument is B_TRUE, this routine sctp_find_next_tq() 21060Sstevel@tonic-gate * will try very hard to dispatch the task. Refer to the comment 21070Sstevel@tonic-gate * for that routine on how it does that. 21080Sstevel@tonic-gate */ 21090Sstevel@tonic-gate boolean_t 21100Sstevel@tonic-gate sctp_add_recvq(sctp_t *sctp, mblk_t *mp, boolean_t caller_hold_lock) 21110Sstevel@tonic-gate { 21120Sstevel@tonic-gate if (!caller_hold_lock) 21130Sstevel@tonic-gate mutex_enter(&sctp->sctp_recvq_lock); 21140Sstevel@tonic-gate 21150Sstevel@tonic-gate /* If the taskq dispatch has not been scheduled, do it now. */ 21160Sstevel@tonic-gate if (sctp->sctp_recvq_tq == NULL) { 21170Sstevel@tonic-gate ASSERT(sctp->sctp_recvq == NULL); 21180Sstevel@tonic-gate if (!sctp_find_next_tq(sctp)) { 21190Sstevel@tonic-gate if (!caller_hold_lock) 21200Sstevel@tonic-gate mutex_exit(&sctp->sctp_recvq_lock); 21210Sstevel@tonic-gate return (B_FALSE); 21220Sstevel@tonic-gate } 21230Sstevel@tonic-gate /* Make sure the sctp_t will not go away. */ 21240Sstevel@tonic-gate SCTP_REFHOLD(sctp); 21250Sstevel@tonic-gate } 21260Sstevel@tonic-gate 21270Sstevel@tonic-gate if (sctp->sctp_recvq == NULL) { 21280Sstevel@tonic-gate sctp->sctp_recvq = mp; 21290Sstevel@tonic-gate sctp->sctp_recvq_tail = mp; 21300Sstevel@tonic-gate } else { 21310Sstevel@tonic-gate sctp->sctp_recvq_tail->b_next = mp; 21320Sstevel@tonic-gate sctp->sctp_recvq_tail = mp; 21330Sstevel@tonic-gate } 21340Sstevel@tonic-gate 21350Sstevel@tonic-gate if (!caller_hold_lock) 21360Sstevel@tonic-gate mutex_exit(&sctp->sctp_recvq_lock); 21370Sstevel@tonic-gate return (B_TRUE); 21380Sstevel@tonic-gate } 21390Sstevel@tonic-gate 21400Sstevel@tonic-gate static void 21410Sstevel@tonic-gate sctp_process_recvq(void *arg) 21420Sstevel@tonic-gate { 21430Sstevel@tonic-gate sctp_t *sctp = (sctp_t *)arg; 21440Sstevel@tonic-gate mblk_t *mp; 21450Sstevel@tonic-gate mblk_t *ipsec_mp; 21460Sstevel@tonic-gate #ifdef DEBUG 21470Sstevel@tonic-gate uint32_t loop_cnt = 0; 21480Sstevel@tonic-gate #endif 21490Sstevel@tonic-gate 21500Sstevel@tonic-gate #ifdef _BIG_ENDIAN 21510Sstevel@tonic-gate #define IPVER(ip6h) ((((uint32_t *)ip6h)[0] >> 28) & 0x7) 21520Sstevel@tonic-gate #else 21530Sstevel@tonic-gate #define IPVER(ip6h) ((((uint32_t *)ip6h)[0] >> 4) & 0x7) 21540Sstevel@tonic-gate #endif 21550Sstevel@tonic-gate 21560Sstevel@tonic-gate RUN_SCTP(sctp); 21570Sstevel@tonic-gate mutex_enter(&sctp->sctp_recvq_lock); 21580Sstevel@tonic-gate 21590Sstevel@tonic-gate #ifdef DEBUG 21600Sstevel@tonic-gate recvq_call++; 21610Sstevel@tonic-gate #endif 21620Sstevel@tonic-gate /* 21630Sstevel@tonic-gate * Note that while we are in this loop, other thread can put 21640Sstevel@tonic-gate * new packets in the receive queue. We may be looping for 21650Sstevel@tonic-gate * quite a while. 21660Sstevel@tonic-gate */ 21670Sstevel@tonic-gate while ((mp = sctp->sctp_recvq) != NULL) { 21680Sstevel@tonic-gate sctp->sctp_recvq = mp->b_next; 21690Sstevel@tonic-gate mutex_exit(&sctp->sctp_recvq_lock); 21700Sstevel@tonic-gate mp->b_next = NULL; 21710Sstevel@tonic-gate #ifdef DEBUG 21720Sstevel@tonic-gate loop_cnt++; 21730Sstevel@tonic-gate #endif 21740Sstevel@tonic-gate ipsec_mp = mp->b_prev; 21750Sstevel@tonic-gate mp->b_prev = NULL; 21760Sstevel@tonic-gate sctp_input_data(sctp, mp, ipsec_mp); 21770Sstevel@tonic-gate 21780Sstevel@tonic-gate mutex_enter(&sctp->sctp_recvq_lock); 21790Sstevel@tonic-gate } 21800Sstevel@tonic-gate 21810Sstevel@tonic-gate sctp->sctp_recvq_tail = NULL; 21820Sstevel@tonic-gate sctp->sctp_recvq_tq = NULL; 21830Sstevel@tonic-gate 21840Sstevel@tonic-gate mutex_exit(&sctp->sctp_recvq_lock); 21850Sstevel@tonic-gate 21860Sstevel@tonic-gate WAKE_SCTP(sctp); 21870Sstevel@tonic-gate 21880Sstevel@tonic-gate /* We may have sent something when processing the receive queue. */ 21890Sstevel@tonic-gate sctp_process_sendq(sctp); 21900Sstevel@tonic-gate #ifdef DEBUG 21910Sstevel@tonic-gate if (loop_cnt > recvq_loop_cnt) 21920Sstevel@tonic-gate recvq_loop_cnt = loop_cnt; 21930Sstevel@tonic-gate #endif 21940Sstevel@tonic-gate /* Now it can go away. */ 21950Sstevel@tonic-gate SCTP_REFRELE(sctp); 21960Sstevel@tonic-gate } 21970Sstevel@tonic-gate 21980Sstevel@tonic-gate /* ARGSUSED */ 21990Sstevel@tonic-gate static int 22000Sstevel@tonic-gate sctp_conn_cache_constructor(void *buf, void *cdrarg, int kmflags) 22010Sstevel@tonic-gate { 22020Sstevel@tonic-gate conn_t *sctp_connp = (conn_t *)buf; 22030Sstevel@tonic-gate sctp_t *sctp = (sctp_t *)&sctp_connp[1]; 22040Sstevel@tonic-gate 22050Sstevel@tonic-gate bzero(buf, (char *)&sctp[1] - (char *)buf); 22060Sstevel@tonic-gate 22070Sstevel@tonic-gate sctp->sctp_connp = sctp_connp; 22080Sstevel@tonic-gate mutex_init(&sctp->sctp_reflock, NULL, MUTEX_DEFAULT, NULL); 22090Sstevel@tonic-gate mutex_init(&sctp->sctp_lock, NULL, MUTEX_DEFAULT, NULL); 22100Sstevel@tonic-gate mutex_init(&sctp->sctp_recvq_lock, NULL, MUTEX_DEFAULT, NULL); 22110Sstevel@tonic-gate cv_init(&sctp->sctp_cv, NULL, CV_DEFAULT, NULL); 22120Sstevel@tonic-gate mutex_init(&sctp->sctp_sendq_lock, NULL, MUTEX_DEFAULT, NULL); 22130Sstevel@tonic-gate 22140Sstevel@tonic-gate sctp_connp->conn_rq = sctp_connp->conn_wq = NULL; 22150Sstevel@tonic-gate sctp_connp->conn_multicast_loop = IP_DEFAULT_MULTICAST_LOOP; 22160Sstevel@tonic-gate sctp_connp->conn_ulp = IPPROTO_SCTP; 22170Sstevel@tonic-gate mutex_init(&sctp_connp->conn_lock, NULL, MUTEX_DEFAULT, NULL); 22180Sstevel@tonic-gate cv_init(&sctp_connp->conn_cv, NULL, CV_DEFAULT, NULL); 22190Sstevel@tonic-gate 22200Sstevel@tonic-gate return (0); 22210Sstevel@tonic-gate } 22220Sstevel@tonic-gate 22230Sstevel@tonic-gate /* ARGSUSED */ 22240Sstevel@tonic-gate static void 22250Sstevel@tonic-gate sctp_conn_cache_destructor(void *buf, void *cdrarg) 22260Sstevel@tonic-gate { 22270Sstevel@tonic-gate conn_t *sctp_connp = (conn_t *)buf; 22280Sstevel@tonic-gate sctp_t *sctp = (sctp_t *)&sctp_connp[1]; 22290Sstevel@tonic-gate 22300Sstevel@tonic-gate ASSERT(!MUTEX_HELD(&sctp->sctp_lock)); 22310Sstevel@tonic-gate ASSERT(!MUTEX_HELD(&sctp->sctp_reflock)); 22320Sstevel@tonic-gate ASSERT(!MUTEX_HELD(&sctp->sctp_recvq_lock)); 22330Sstevel@tonic-gate ASSERT(!MUTEX_HELD(&sctp->sctp_sendq_lock)); 22340Sstevel@tonic-gate ASSERT(!MUTEX_HELD(&sctp->sctp_connp->conn_lock)); 22350Sstevel@tonic-gate 22360Sstevel@tonic-gate ASSERT(sctp->sctp_conn_hash_next == NULL); 22370Sstevel@tonic-gate ASSERT(sctp->sctp_conn_hash_prev == NULL); 22380Sstevel@tonic-gate ASSERT(sctp->sctp_listen_hash_next == NULL); 22390Sstevel@tonic-gate ASSERT(sctp->sctp_listen_hash_prev == NULL); 22400Sstevel@tonic-gate ASSERT(sctp->sctp_listen_tfp == NULL); 22410Sstevel@tonic-gate ASSERT(sctp->sctp_conn_tfp == NULL); 22420Sstevel@tonic-gate 22430Sstevel@tonic-gate ASSERT(sctp->sctp_faddrs == NULL); 22440Sstevel@tonic-gate ASSERT(sctp->sctp_nsaddrs == 0); 22450Sstevel@tonic-gate 22460Sstevel@tonic-gate ASSERT(sctp->sctp_ulpd == NULL); 22470Sstevel@tonic-gate 22480Sstevel@tonic-gate ASSERT(sctp->sctp_lastfaddr == NULL); 22490Sstevel@tonic-gate ASSERT(sctp->sctp_primary == NULL); 22500Sstevel@tonic-gate ASSERT(sctp->sctp_current == NULL); 22510Sstevel@tonic-gate ASSERT(sctp->sctp_lastdata == NULL); 22520Sstevel@tonic-gate 22530Sstevel@tonic-gate ASSERT(sctp->sctp_xmit_head == NULL); 22540Sstevel@tonic-gate ASSERT(sctp->sctp_xmit_tail == NULL); 22550Sstevel@tonic-gate ASSERT(sctp->sctp_xmit_unsent == NULL); 22560Sstevel@tonic-gate ASSERT(sctp->sctp_xmit_unsent_tail == NULL); 22570Sstevel@tonic-gate 22580Sstevel@tonic-gate ASSERT(sctp->sctp_ostrcntrs == NULL); 22590Sstevel@tonic-gate 22600Sstevel@tonic-gate ASSERT(sctp->sctp_sack_info == NULL); 22610Sstevel@tonic-gate ASSERT(sctp->sctp_ack_mp == NULL); 22620Sstevel@tonic-gate ASSERT(sctp->sctp_instr == NULL); 22630Sstevel@tonic-gate 22640Sstevel@tonic-gate ASSERT(sctp->sctp_iphc == NULL); 22650Sstevel@tonic-gate ASSERT(sctp->sctp_iphc6 == NULL); 22660Sstevel@tonic-gate ASSERT(sctp->sctp_ipha == NULL); 22670Sstevel@tonic-gate ASSERT(sctp->sctp_ip6h == NULL); 22680Sstevel@tonic-gate ASSERT(sctp->sctp_sctph == NULL); 22690Sstevel@tonic-gate ASSERT(sctp->sctp_sctph6 == NULL); 22700Sstevel@tonic-gate 22710Sstevel@tonic-gate ASSERT(sctp->sctp_cookie_mp == NULL); 22720Sstevel@tonic-gate 22730Sstevel@tonic-gate ASSERT(sctp->sctp_refcnt == 0); 22740Sstevel@tonic-gate ASSERT(sctp->sctp_timer_mp == NULL); 22750Sstevel@tonic-gate ASSERT(sctp->sctp_connp->conn_ref == 0); 22760Sstevel@tonic-gate ASSERT(sctp->sctp_heartbeat_mp == NULL); 22770Sstevel@tonic-gate ASSERT(sctp->sctp_ptpbhn == NULL && sctp->sctp_bind_hash == NULL); 22780Sstevel@tonic-gate 22790Sstevel@tonic-gate ASSERT(sctp->sctp_shutdown_faddr == NULL); 22800Sstevel@tonic-gate 22810Sstevel@tonic-gate ASSERT(sctp->sctp_cxmit_list == NULL); 22820Sstevel@tonic-gate 22830Sstevel@tonic-gate ASSERT(sctp->sctp_recvq == NULL); 22840Sstevel@tonic-gate ASSERT(sctp->sctp_recvq_tail == NULL); 22850Sstevel@tonic-gate ASSERT(sctp->sctp_recvq_tq == NULL); 22860Sstevel@tonic-gate 22870Sstevel@tonic-gate ASSERT(sctp->sctp_sendq == NULL); 22880Sstevel@tonic-gate ASSERT(sctp->sctp_sendq_tail == NULL); 22890Sstevel@tonic-gate ASSERT(sctp->sctp_sendq_sending == B_FALSE); 22900Sstevel@tonic-gate 22912283Skp158701 ASSERT(sctp->sctp_ipp_hopopts == NULL); 22922283Skp158701 ASSERT(sctp->sctp_ipp_rtdstopts == NULL); 22932283Skp158701 ASSERT(sctp->sctp_ipp_rthdr == NULL); 22942283Skp158701 ASSERT(sctp->sctp_ipp_dstopts == NULL); 22952283Skp158701 ASSERT(sctp->sctp_ipp_pathmtu == NULL); 22962283Skp158701 22970Sstevel@tonic-gate mutex_destroy(&sctp->sctp_reflock); 22980Sstevel@tonic-gate mutex_destroy(&sctp->sctp_lock); 22990Sstevel@tonic-gate mutex_destroy(&sctp->sctp_recvq_lock); 23000Sstevel@tonic-gate cv_destroy(&sctp->sctp_cv); 23010Sstevel@tonic-gate mutex_destroy(&sctp->sctp_sendq_lock); 23020Sstevel@tonic-gate 23030Sstevel@tonic-gate mutex_destroy(&sctp_connp->conn_lock); 23040Sstevel@tonic-gate cv_destroy(&sctp_connp->conn_cv); 23050Sstevel@tonic-gate } 23060Sstevel@tonic-gate 23070Sstevel@tonic-gate static void 23080Sstevel@tonic-gate sctp_conn_cache_init() 23090Sstevel@tonic-gate { 23100Sstevel@tonic-gate sctp_conn_cache = kmem_cache_create("sctp_conn_cache", 23110Sstevel@tonic-gate sizeof (sctp_t) + sizeof (conn_t), 0, sctp_conn_cache_constructor, 23120Sstevel@tonic-gate sctp_conn_cache_destructor, NULL, NULL, NULL, 0); 23130Sstevel@tonic-gate } 23140Sstevel@tonic-gate 23150Sstevel@tonic-gate static void 23160Sstevel@tonic-gate sctp_conn_cache_fini() 23170Sstevel@tonic-gate { 23180Sstevel@tonic-gate kmem_cache_destroy(sctp_conn_cache); 23190Sstevel@tonic-gate } 2320