17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 55dddb8baSkcpoon * Common Development and Distribution License (the "License"). 65dddb8baSkcpoon * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 215dddb8baSkcpoon 227c478bd9Sstevel@tonic-gate /* 235dddb8baSkcpoon * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/types.h> 307c478bd9Sstevel@tonic-gate #include <sys/stream.h> 317c478bd9Sstevel@tonic-gate #include <sys/strsubr.h> 327c478bd9Sstevel@tonic-gate #include <sys/stropts.h> 337c478bd9Sstevel@tonic-gate #include <sys/strsun.h> 347c478bd9Sstevel@tonic-gate #define _SUN_TPI_VERSION 2 357c478bd9Sstevel@tonic-gate #include <sys/tihdr.h> 367c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 377c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 387c478bd9Sstevel@tonic-gate #include <sys/xti_inet.h> 397c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 407c478bd9Sstevel@tonic-gate #include <sys/debug.h> 417c478bd9Sstevel@tonic-gate #include <sys/vtrace.h> 427c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 437c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 447c478bd9Sstevel@tonic-gate #include <sys/random.h> 4545916cd2Sjpk #include <sys/priv.h> 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate #include <sys/errno.h> 487c478bd9Sstevel@tonic-gate #include <sys/signal.h> 497c478bd9Sstevel@tonic-gate #include <sys/socket.h> 507c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h> 517c478bd9Sstevel@tonic-gate #include <netinet/in.h> 527c478bd9Sstevel@tonic-gate #include <netinet/tcp.h> 537c478bd9Sstevel@tonic-gate #include <netinet/ip6.h> 547c478bd9Sstevel@tonic-gate #include <netinet/icmp6.h> 557c478bd9Sstevel@tonic-gate #include <netinet/sctp.h> 567c478bd9Sstevel@tonic-gate #include <net/if.h> 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate #include <inet/common.h> 597c478bd9Sstevel@tonic-gate #include <inet/ip.h> 607c478bd9Sstevel@tonic-gate #include <inet/ip6.h> 617c478bd9Sstevel@tonic-gate #include <inet/mi.h> 627c478bd9Sstevel@tonic-gate #include <inet/mib2.h> 637c478bd9Sstevel@tonic-gate #include <inet/nd.h> 647c478bd9Sstevel@tonic-gate #include <inet/optcom.h> 657c478bd9Sstevel@tonic-gate #include <inet/ipclassifier.h> 667c478bd9Sstevel@tonic-gate #include <inet/ipsec_impl.h> 677c478bd9Sstevel@tonic-gate #include <inet/sctp_ip.h> 687c478bd9Sstevel@tonic-gate #include <inet/sctp_crc32.h> 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate #include "sctp_impl.h" 717c478bd9Sstevel@tonic-gate #include "sctp_addr.h" 721d8c4025Svi #include "sctp_asconf.h" 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate extern major_t SCTP6_MAJ; 757c478bd9Sstevel@tonic-gate extern major_t SCTP_MAJ; 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate int sctpdebug; 787c478bd9Sstevel@tonic-gate sin6_t sctp_sin6_null; /* Zero address for quick clears */ 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate extern mblk_t *sctp_pad_mp; /* pad unaligned data chunks */ 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate static void sctp_closei_local(sctp_t *sctp); 837c478bd9Sstevel@tonic-gate static int sctp_init_values(sctp_t *, sctp_t *, int); 847c478bd9Sstevel@tonic-gate static void sctp_icmp_error_ipv6(sctp_t *sctp, mblk_t *mp); 857c478bd9Sstevel@tonic-gate static void sctp_process_recvq(void *); 867c478bd9Sstevel@tonic-gate static void sctp_rq_tq_init(void); 877c478bd9Sstevel@tonic-gate static void sctp_rq_tq_fini(void); 887c478bd9Sstevel@tonic-gate static void sctp_conn_cache_init(); 897c478bd9Sstevel@tonic-gate static void sctp_conn_cache_fini(); 907c478bd9Sstevel@tonic-gate static int sctp_conn_cache_constructor(); 917c478bd9Sstevel@tonic-gate static void sctp_conn_cache_destructor(); 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate /* 947c478bd9Sstevel@tonic-gate * SCTP receive queue taskq 957c478bd9Sstevel@tonic-gate * 967c478bd9Sstevel@tonic-gate * At SCTP initialization time, a default taskq is created for 977c478bd9Sstevel@tonic-gate * servicing packets received when the interrupt thread cannot 987c478bd9Sstevel@tonic-gate * get a hold on the sctp_t. The number of taskq can be increased in 997c478bd9Sstevel@tonic-gate * sctp_find_next_tq() when an existing taskq cannot be dispatched. 1007c478bd9Sstevel@tonic-gate * The taskqs are never removed. But the max number of taskq which 1017c478bd9Sstevel@tonic-gate * can be created is controlled by sctp_recvq_tq_list_max_sz. Note 1027c478bd9Sstevel@tonic-gate * that SCTP recvq taskq is not tied to any specific CPU or ill. 1037c478bd9Sstevel@tonic-gate * 1047c478bd9Sstevel@tonic-gate * Those taskqs are stored in an array recvq_tq_list. And they are 1057c478bd9Sstevel@tonic-gate * used in a round robin fashion. The current taskq being used is 1067c478bd9Sstevel@tonic-gate * determined by recvq_tq_list_cur. 1077c478bd9Sstevel@tonic-gate */ 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate /* This lock protects the SCTP recvq_tq_list array and recvq_tq_list_cur_sz. */ 1107c478bd9Sstevel@tonic-gate static kmutex_t sctp_rq_tq_lock; 1117c478bd9Sstevel@tonic-gate int sctp_recvq_tq_list_max_sz = 16; 1127c478bd9Sstevel@tonic-gate static taskq_t **recvq_tq_list; 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate /* Current number of recvq taskq. At least 1 for the default taskq. */ 1157c478bd9Sstevel@tonic-gate static uint32_t recvq_tq_list_cur_sz = 1; 1167c478bd9Sstevel@tonic-gate static uint32_t recvq_tq_list_cur = 0; 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate /* The minimum number of threads for each taskq. */ 1197c478bd9Sstevel@tonic-gate int sctp_recvq_tq_thr_min = 4; 1207c478bd9Sstevel@tonic-gate /* The maximum number of threads for each taskq. */ 1217c478bd9Sstevel@tonic-gate int sctp_recvq_tq_thr_max = 16; 1227c478bd9Sstevel@tonic-gate /* The minimum number of tasks for each taskq. */ 1237c478bd9Sstevel@tonic-gate int sctp_recvq_tq_task_min = 5; 1247c478bd9Sstevel@tonic-gate /* The maxiimum number of tasks for each taskq. */ 1257c478bd9Sstevel@tonic-gate int sctp_recvq_tq_task_max = 50; 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate /* 1287c478bd9Sstevel@tonic-gate * Default queue used for sending packets. No need to have lock for it 1297c478bd9Sstevel@tonic-gate * as it should never be changed. 1307c478bd9Sstevel@tonic-gate */ 1317c478bd9Sstevel@tonic-gate queue_t *sctp_g_q; 1327c478bd9Sstevel@tonic-gate int sctp_g_q_fd; 1337c478bd9Sstevel@tonic-gate /* The default sctp_t for responding out of the blue packets. */ 1347c478bd9Sstevel@tonic-gate sctp_t *gsctp; 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate /* Protected by sctp_g_lock */ 1377c478bd9Sstevel@tonic-gate list_t sctp_g_list; /* SCTP instance data chain */ 1387c478bd9Sstevel@tonic-gate kmutex_t sctp_g_lock; 1397c478bd9Sstevel@tonic-gate 1407c478bd9Sstevel@tonic-gate /* sctp_t/conn_t kmem cache */ 1417c478bd9Sstevel@tonic-gate struct kmem_cache *sctp_conn_cache; 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate #define SCTP_CONDEMNED(sctp) \ 1447c478bd9Sstevel@tonic-gate mutex_enter(&(sctp)->sctp_reflock); \ 1457c478bd9Sstevel@tonic-gate ((sctp)->sctp_condemned = B_TRUE); \ 1465dddb8baSkcpoon mutex_exit(&(sctp)->sctp_reflock); 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate /* Link/unlink a sctp_t to/from the global list. */ 1497c478bd9Sstevel@tonic-gate #define SCTP_LINK(sctp) \ 1507c478bd9Sstevel@tonic-gate mutex_enter(&sctp_g_lock); \ 1517c478bd9Sstevel@tonic-gate list_insert_tail(&sctp_g_list, (sctp)); \ 1527c478bd9Sstevel@tonic-gate mutex_exit(&sctp_g_lock); 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate #define SCTP_UNLINK(sctp) \ 1557c478bd9Sstevel@tonic-gate mutex_enter(&sctp_g_lock); \ 1567c478bd9Sstevel@tonic-gate ASSERT((sctp)->sctp_condemned); \ 1577c478bd9Sstevel@tonic-gate list_remove(&sctp_g_list, (sctp)); \ 1587c478bd9Sstevel@tonic-gate mutex_exit(&sctp_g_lock); 1597c478bd9Sstevel@tonic-gate 1601d8c4025Svi /* 1611d8c4025Svi * Hooks for Sun Cluster. On non-clustered nodes these will remain NULL. 1621d8c4025Svi * PSARC/2005/602. 1631d8c4025Svi */ 1641d8c4025Svi void (*cl_sctp_listen)(sa_family_t, uchar_t *, uint_t, in_port_t) = NULL; 1651d8c4025Svi void (*cl_sctp_unlisten)(sa_family_t, uchar_t *, uint_t, in_port_t) = NULL; 1661d8c4025Svi void (*cl_sctp_connect)(sa_family_t, uchar_t *, uint_t, in_port_t, 1671d8c4025Svi uchar_t *, uint_t, in_port_t, boolean_t, cl_sctp_handle_t) = NULL; 1681d8c4025Svi void (*cl_sctp_disconnect)(sa_family_t, cl_sctp_handle_t) = NULL; 1691d8c4025Svi void (*cl_sctp_assoc_change)(sa_family_t, uchar_t *, size_t, uint_t, 1701d8c4025Svi uchar_t *, size_t, uint_t, int, cl_sctp_handle_t) = NULL; 1711d8c4025Svi void (*cl_sctp_check_addrs)(sa_family_t, in_port_t, uchar_t **, size_t, 1721d8c4025Svi uint_t *, boolean_t) = NULL; 1737c478bd9Sstevel@tonic-gate /* 1747c478bd9Sstevel@tonic-gate * Return the version number of the SCTP kernel interface. 1757c478bd9Sstevel@tonic-gate */ 1767c478bd9Sstevel@tonic-gate int 1777c478bd9Sstevel@tonic-gate sctp_itf_ver(int cl_ver) 1787c478bd9Sstevel@tonic-gate { 1797c478bd9Sstevel@tonic-gate if (cl_ver != SCTP_ITF_VER) 1807c478bd9Sstevel@tonic-gate return (-1); 1817c478bd9Sstevel@tonic-gate return (SCTP_ITF_VER); 1827c478bd9Sstevel@tonic-gate } 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate /* 1857c478bd9Sstevel@tonic-gate * Called when we need a new sctp instantiation but don't really have a 1867c478bd9Sstevel@tonic-gate * new q to hang it off of. Copy the priv flag from the passed in structure. 1877c478bd9Sstevel@tonic-gate */ 1887c478bd9Sstevel@tonic-gate sctp_t * 1897c478bd9Sstevel@tonic-gate sctp_create_eager(sctp_t *psctp) 1907c478bd9Sstevel@tonic-gate { 1917c478bd9Sstevel@tonic-gate sctp_t *sctp; 1927c478bd9Sstevel@tonic-gate mblk_t *ack_mp, *hb_mp; 1937c478bd9Sstevel@tonic-gate conn_t *connp, *pconnp; 19445916cd2Sjpk cred_t *credp; 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate if ((connp = ipcl_conn_create(IPCL_SCTPCONN, KM_NOSLEEP)) == NULL) 1977c478bd9Sstevel@tonic-gate return (NULL); 19845916cd2Sjpk 19945916cd2Sjpk connp->conn_ulp_labeled = is_system_labeled(); 20045916cd2Sjpk 2017c478bd9Sstevel@tonic-gate sctp = CONN2SCTP(connp); 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate if ((ack_mp = sctp_timer_alloc(sctp, sctp_ack_timer)) == NULL || 2047c478bd9Sstevel@tonic-gate (hb_mp = sctp_timer_alloc(sctp, sctp_heartbeat_timer)) == NULL) { 2057c478bd9Sstevel@tonic-gate if (ack_mp != NULL) 2067c478bd9Sstevel@tonic-gate freeb(ack_mp); 2077c478bd9Sstevel@tonic-gate kmem_cache_free(sctp_conn_cache, connp); 2087c478bd9Sstevel@tonic-gate return (NULL); 2097c478bd9Sstevel@tonic-gate } 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate sctp->sctp_ack_mp = ack_mp; 2127c478bd9Sstevel@tonic-gate sctp->sctp_heartbeat_mp = hb_mp; 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate /* Inherit information from the "parent" */ 2157c478bd9Sstevel@tonic-gate sctp->sctp_ipversion = psctp->sctp_ipversion; 2167c478bd9Sstevel@tonic-gate sctp->sctp_family = psctp->sctp_family; 2177c478bd9Sstevel@tonic-gate pconnp = psctp->sctp_connp; 2187c478bd9Sstevel@tonic-gate connp->conn_af_isv6 = pconnp->conn_af_isv6; 2197c478bd9Sstevel@tonic-gate connp->conn_pkt_isv6 = pconnp->conn_pkt_isv6; 2207c478bd9Sstevel@tonic-gate connp->conn_ipv6_v6only = pconnp->conn_ipv6_v6only; 2217c478bd9Sstevel@tonic-gate if (sctp_init_values(sctp, psctp, KM_NOSLEEP) != 0) { 2227c478bd9Sstevel@tonic-gate freeb(ack_mp); 2237c478bd9Sstevel@tonic-gate freeb(hb_mp); 2247c478bd9Sstevel@tonic-gate kmem_cache_free(sctp_conn_cache, connp); 2257c478bd9Sstevel@tonic-gate return (NULL); 2267c478bd9Sstevel@tonic-gate } 22745916cd2Sjpk 22845916cd2Sjpk /* 22945916cd2Sjpk * If the parent is multilevel, then we'll fix up the remote cred 23045916cd2Sjpk * when we do sctp_accept_comm. 23145916cd2Sjpk */ 23245916cd2Sjpk if ((credp = pconnp->conn_cred) != NULL) { 23345916cd2Sjpk connp->conn_cred = credp; 23445916cd2Sjpk crhold(credp); 23545916cd2Sjpk /* 23645916cd2Sjpk * If the caller has the process-wide flag set, then default to 23745916cd2Sjpk * MAC exempt mode. This allows read-down to unlabeled hosts. 23845916cd2Sjpk */ 23945916cd2Sjpk if (getpflags(NET_MAC_AWARE, credp) != 0) 24045916cd2Sjpk connp->conn_mac_exempt = B_TRUE; 2417c478bd9Sstevel@tonic-gate } 242*5d0bc3edSsommerfe 243*5d0bc3edSsommerfe connp->conn_allzones = pconnp->conn_allzones; 244*5d0bc3edSsommerfe connp->conn_zoneid = pconnp->conn_zoneid; 245*5d0bc3edSsommerfe 2467c478bd9Sstevel@tonic-gate sctp->sctp_mss = psctp->sctp_mss; 2477c478bd9Sstevel@tonic-gate sctp->sctp_detached = B_TRUE; 2487c478bd9Sstevel@tonic-gate /* 2497c478bd9Sstevel@tonic-gate * Link to the global as soon as possible so that this sctp_t 2507c478bd9Sstevel@tonic-gate * can be found. 2517c478bd9Sstevel@tonic-gate */ 2527c478bd9Sstevel@tonic-gate SCTP_LINK(sctp); 2537c478bd9Sstevel@tonic-gate 2547c478bd9Sstevel@tonic-gate return (sctp); 2557c478bd9Sstevel@tonic-gate } 2567c478bd9Sstevel@tonic-gate 2577c478bd9Sstevel@tonic-gate /* 2587c478bd9Sstevel@tonic-gate * We are dying for some reason. Try to do it gracefully. 2597c478bd9Sstevel@tonic-gate */ 2607c478bd9Sstevel@tonic-gate void 2617c478bd9Sstevel@tonic-gate sctp_clean_death(sctp_t *sctp, int err) 2627c478bd9Sstevel@tonic-gate { 2637c478bd9Sstevel@tonic-gate ASSERT(sctp != NULL); 2647c478bd9Sstevel@tonic-gate ASSERT((sctp->sctp_family == AF_INET && 2657c478bd9Sstevel@tonic-gate sctp->sctp_ipversion == IPV4_VERSION) || 2667c478bd9Sstevel@tonic-gate (sctp->sctp_family == AF_INET6 && 2677c478bd9Sstevel@tonic-gate (sctp->sctp_ipversion == IPV4_VERSION || 2687c478bd9Sstevel@tonic-gate sctp->sctp_ipversion == IPV6_VERSION))); 2697c478bd9Sstevel@tonic-gate 27045916cd2Sjpk dprint(3, ("sctp_clean_death %p, state %d\n", (void *)sctp, 27145916cd2Sjpk sctp->sctp_state)); 2727c478bd9Sstevel@tonic-gate 2737c478bd9Sstevel@tonic-gate sctp->sctp_client_errno = err; 2747c478bd9Sstevel@tonic-gate /* 2757c478bd9Sstevel@tonic-gate * Check to see if we need to notify upper layer. 2767c478bd9Sstevel@tonic-gate */ 2777c478bd9Sstevel@tonic-gate if ((sctp->sctp_state >= SCTPS_COOKIE_WAIT) && 2787c478bd9Sstevel@tonic-gate !SCTP_IS_DETACHED(sctp)) { 2797c478bd9Sstevel@tonic-gate if (sctp->sctp_xmit_head || sctp->sctp_xmit_unsent) { 2807c478bd9Sstevel@tonic-gate sctp_regift_xmitlist(sctp); 2817c478bd9Sstevel@tonic-gate } 2827c478bd9Sstevel@tonic-gate if (sctp->sctp_ulp_disconnected(sctp->sctp_ulpd, err)) { 2837c478bd9Sstevel@tonic-gate /* 2847c478bd9Sstevel@tonic-gate * Socket is gone, detach. 2857c478bd9Sstevel@tonic-gate */ 2867c478bd9Sstevel@tonic-gate sctp->sctp_detached = B_TRUE; 2877c478bd9Sstevel@tonic-gate sctp->sctp_ulpd = NULL; 2887c478bd9Sstevel@tonic-gate bzero(&sctp->sctp_upcalls, sizeof (sctp_upcalls_t)); 2897c478bd9Sstevel@tonic-gate } 2907c478bd9Sstevel@tonic-gate } 2917c478bd9Sstevel@tonic-gate 2927c478bd9Sstevel@tonic-gate /* Remove this sctp from all hashes. */ 2937c478bd9Sstevel@tonic-gate sctp_closei_local(sctp); 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate /* 2967c478bd9Sstevel@tonic-gate * If the sctp_t is detached, we need to finish freeing up 2977c478bd9Sstevel@tonic-gate * the resources. At this point, ip_fanout_sctp() should have 2987c478bd9Sstevel@tonic-gate * a hold on this sctp_t. Some thread doing snmp stuff can 2997c478bd9Sstevel@tonic-gate * have a hold. And a taskq can also have a hold waiting to 3007c478bd9Sstevel@tonic-gate * work. sctp_unlink() the sctp_t from the global list so 3017c478bd9Sstevel@tonic-gate * that no new thread can find it. Then do a SCTP_REFRELE(). 3027c478bd9Sstevel@tonic-gate * The sctp_t will be freed after all those threads are done. 3037c478bd9Sstevel@tonic-gate */ 3047c478bd9Sstevel@tonic-gate if (SCTP_IS_DETACHED(sctp)) { 3057c478bd9Sstevel@tonic-gate SCTP_CONDEMNED(sctp); 3067c478bd9Sstevel@tonic-gate SCTP_REFRELE(sctp); 3077c478bd9Sstevel@tonic-gate } 3087c478bd9Sstevel@tonic-gate } 3097c478bd9Sstevel@tonic-gate 3107c478bd9Sstevel@tonic-gate /* 3117c478bd9Sstevel@tonic-gate * Called by upper layer when it wants to close this association. 3127c478bd9Sstevel@tonic-gate * Depending on the state of this assoication, we need to do 3137c478bd9Sstevel@tonic-gate * different things. 3147c478bd9Sstevel@tonic-gate * 3157c478bd9Sstevel@tonic-gate * If the state is below COOKIE_ECHOED or it is COOKIE_ECHOED but with 3167c478bd9Sstevel@tonic-gate * no sent data, just remove this sctp from all the hashes. This 3177c478bd9Sstevel@tonic-gate * makes sure that all packets from the other end will go to the default 3187c478bd9Sstevel@tonic-gate * sctp handling. The upper layer will then do a sctp_close() to clean 3197c478bd9Sstevel@tonic-gate * up. 3207c478bd9Sstevel@tonic-gate * 3217c478bd9Sstevel@tonic-gate * Otherwise, check and see if SO_LINGER is set. If it is set, check 3227c478bd9Sstevel@tonic-gate * the value. If the value is 0, consider this an abortive close. Send 3237c478bd9Sstevel@tonic-gate * an ABORT message and kill the associatiion. 3247c478bd9Sstevel@tonic-gate * 3257c478bd9Sstevel@tonic-gate */ 3267c478bd9Sstevel@tonic-gate int 3277c478bd9Sstevel@tonic-gate sctp_disconnect(sctp_t *sctp) 3287c478bd9Sstevel@tonic-gate { 3297c478bd9Sstevel@tonic-gate int error = 0; 3307c478bd9Sstevel@tonic-gate 33145916cd2Sjpk dprint(3, ("sctp_disconnect %p, state %d\n", (void *)sctp, 33245916cd2Sjpk sctp->sctp_state)); 3337c478bd9Sstevel@tonic-gate 3347c478bd9Sstevel@tonic-gate RUN_SCTP(sctp); 3357c478bd9Sstevel@tonic-gate 3367c478bd9Sstevel@tonic-gate switch (sctp->sctp_state) { 3377c478bd9Sstevel@tonic-gate case SCTPS_IDLE: 3387c478bd9Sstevel@tonic-gate case SCTPS_BOUND: 3397c478bd9Sstevel@tonic-gate case SCTPS_LISTEN: 3407c478bd9Sstevel@tonic-gate break; 3417c478bd9Sstevel@tonic-gate case SCTPS_COOKIE_WAIT: 3427c478bd9Sstevel@tonic-gate case SCTPS_COOKIE_ECHOED: 3437c478bd9Sstevel@tonic-gate /* 3447c478bd9Sstevel@tonic-gate * Close during the connect 3-way handshake 3457c478bd9Sstevel@tonic-gate * but here there may or may not be pending data 3467c478bd9Sstevel@tonic-gate * already on queue. Process almost same as in 3477c478bd9Sstevel@tonic-gate * the ESTABLISHED state. 3487c478bd9Sstevel@tonic-gate */ 3497c478bd9Sstevel@tonic-gate if (sctp->sctp_xmit_head == NULL && 3507c478bd9Sstevel@tonic-gate sctp->sctp_xmit_unsent == NULL) { 3517c478bd9Sstevel@tonic-gate break; 3527c478bd9Sstevel@tonic-gate } 3537c478bd9Sstevel@tonic-gate /* FALLTHRU */ 3547c478bd9Sstevel@tonic-gate default: 3557c478bd9Sstevel@tonic-gate /* 3567c478bd9Sstevel@tonic-gate * If SO_LINGER has set a zero linger time, abort the 3577c478bd9Sstevel@tonic-gate * connection with a reset. 3587c478bd9Sstevel@tonic-gate */ 3597c478bd9Sstevel@tonic-gate if (sctp->sctp_linger && sctp->sctp_lingertime == 0) { 3607c478bd9Sstevel@tonic-gate sctp_user_abort(sctp, NULL, B_FALSE); 3617c478bd9Sstevel@tonic-gate break; 3627c478bd9Sstevel@tonic-gate } 3637c478bd9Sstevel@tonic-gate 3641d8c4025Svi /* 3651d8c4025Svi * In there is unread data, send an ABORT 3661d8c4025Svi */ 3671d8c4025Svi if (sctp->sctp_rxqueued > 0 || sctp->sctp_irwnd > 3681d8c4025Svi sctp->sctp_rwnd) { 3691d8c4025Svi sctp_user_abort(sctp, NULL, B_FALSE); 3701d8c4025Svi break; 3711d8c4025Svi } 3727c478bd9Sstevel@tonic-gate /* 3737c478bd9Sstevel@tonic-gate * Transmit the shutdown before detaching the sctp_t. 3747c478bd9Sstevel@tonic-gate * After sctp_detach returns this queue/perimeter 3757c478bd9Sstevel@tonic-gate * no longer owns the sctp_t thus others can modify it. 3767c478bd9Sstevel@tonic-gate */ 3777c478bd9Sstevel@tonic-gate sctp_send_shutdown(sctp, 0); 3787c478bd9Sstevel@tonic-gate 3797c478bd9Sstevel@tonic-gate /* Pass gathered wisdom to IP for keeping */ 38077c67f2fSkcpoon sctp_update_ire(sctp); 3817c478bd9Sstevel@tonic-gate 3827c478bd9Sstevel@tonic-gate /* 3837c478bd9Sstevel@tonic-gate * If lingering on close then wait until the shutdown 3847c478bd9Sstevel@tonic-gate * is complete, or the SO_LINGER time passes, or an 3857c478bd9Sstevel@tonic-gate * ABORT is sent/received. Note that sctp_disconnect() 3867c478bd9Sstevel@tonic-gate * can be called more than once. Make sure that only 3877c478bd9Sstevel@tonic-gate * one thread waits. 3887c478bd9Sstevel@tonic-gate */ 3897c478bd9Sstevel@tonic-gate if (sctp->sctp_linger && sctp->sctp_lingertime > 0 && 3907c478bd9Sstevel@tonic-gate sctp->sctp_state >= SCTPS_ESTABLISHED && 3917c478bd9Sstevel@tonic-gate !sctp->sctp_lingering) { 3927c478bd9Sstevel@tonic-gate clock_t stoptime; /* in ticks */ 3937c478bd9Sstevel@tonic-gate clock_t ret; 3947c478bd9Sstevel@tonic-gate 3957c478bd9Sstevel@tonic-gate /* 3967c478bd9Sstevel@tonic-gate * Process the sendq to send the SHUTDOWN out 3977c478bd9Sstevel@tonic-gate * before waiting. 3987c478bd9Sstevel@tonic-gate */ 3997c478bd9Sstevel@tonic-gate sctp_process_sendq(sctp); 4007c478bd9Sstevel@tonic-gate 4017c478bd9Sstevel@tonic-gate sctp->sctp_lingering = 1; 4027c478bd9Sstevel@tonic-gate sctp->sctp_client_errno = 0; 4037c478bd9Sstevel@tonic-gate stoptime = lbolt + sctp->sctp_lingertime; 4047c478bd9Sstevel@tonic-gate 4057c478bd9Sstevel@tonic-gate mutex_enter(&sctp->sctp_lock); 4067c478bd9Sstevel@tonic-gate sctp->sctp_running = B_FALSE; 4077c478bd9Sstevel@tonic-gate while (sctp->sctp_state >= SCTPS_ESTABLISHED && 4087c478bd9Sstevel@tonic-gate sctp->sctp_client_errno == 0) { 4097c478bd9Sstevel@tonic-gate cv_broadcast(&sctp->sctp_cv); 4107c478bd9Sstevel@tonic-gate ret = cv_timedwait_sig(&sctp->sctp_cv, 4117c478bd9Sstevel@tonic-gate &sctp->sctp_lock, stoptime); 4127c478bd9Sstevel@tonic-gate if (ret < 0) { 4137c478bd9Sstevel@tonic-gate /* Stoptime has reached. */ 4147c478bd9Sstevel@tonic-gate sctp->sctp_client_errno = EWOULDBLOCK; 4157c478bd9Sstevel@tonic-gate break; 4167c478bd9Sstevel@tonic-gate } else if (ret == 0) { 4177c478bd9Sstevel@tonic-gate /* Got a signal. */ 4187c478bd9Sstevel@tonic-gate break; 4197c478bd9Sstevel@tonic-gate } 4207c478bd9Sstevel@tonic-gate } 4217c478bd9Sstevel@tonic-gate error = sctp->sctp_client_errno; 4227c478bd9Sstevel@tonic-gate sctp->sctp_client_errno = 0; 4237c478bd9Sstevel@tonic-gate mutex_exit(&sctp->sctp_lock); 4247c478bd9Sstevel@tonic-gate } 4257c478bd9Sstevel@tonic-gate 4267c478bd9Sstevel@tonic-gate WAKE_SCTP(sctp); 4277c478bd9Sstevel@tonic-gate sctp_process_sendq(sctp); 4287c478bd9Sstevel@tonic-gate return (error); 4297c478bd9Sstevel@tonic-gate } 4307c478bd9Sstevel@tonic-gate 4317c478bd9Sstevel@tonic-gate 4327c478bd9Sstevel@tonic-gate /* Remove this sctp from all hashes so nobody can find it. */ 4337c478bd9Sstevel@tonic-gate sctp_closei_local(sctp); 4347c478bd9Sstevel@tonic-gate WAKE_SCTP(sctp); 4357c478bd9Sstevel@tonic-gate return (error); 4367c478bd9Sstevel@tonic-gate } 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate void 4397c478bd9Sstevel@tonic-gate sctp_close(sctp_t *sctp) 4407c478bd9Sstevel@tonic-gate { 44145916cd2Sjpk dprint(3, ("sctp_close %p, state %d\n", (void *)sctp, 44245916cd2Sjpk sctp->sctp_state)); 4437c478bd9Sstevel@tonic-gate 4447c478bd9Sstevel@tonic-gate RUN_SCTP(sctp); 4457c478bd9Sstevel@tonic-gate sctp->sctp_detached = 1; 4467c478bd9Sstevel@tonic-gate sctp->sctp_ulpd = NULL; 4477c478bd9Sstevel@tonic-gate bzero(&sctp->sctp_upcalls, sizeof (sctp_upcalls_t)); 4487c478bd9Sstevel@tonic-gate bzero(&sctp->sctp_events, sizeof (sctp->sctp_events)); 4497c478bd9Sstevel@tonic-gate 4507c478bd9Sstevel@tonic-gate /* If the graceful shutdown has not been completed, just return. */ 4517c478bd9Sstevel@tonic-gate if (sctp->sctp_state != SCTPS_IDLE) { 4527c478bd9Sstevel@tonic-gate WAKE_SCTP(sctp); 4537c478bd9Sstevel@tonic-gate return; 4547c478bd9Sstevel@tonic-gate } 4557c478bd9Sstevel@tonic-gate 4567c478bd9Sstevel@tonic-gate /* 4577c478bd9Sstevel@tonic-gate * Since sctp_t is in SCTPS_IDLE state, so the only thread which 4587c478bd9Sstevel@tonic-gate * can have a hold on the sctp_t is doing snmp stuff. Just do 4597c478bd9Sstevel@tonic-gate * a SCTP_REFRELE() here after the SCTP_UNLINK(). It will 4607c478bd9Sstevel@tonic-gate * be freed when the other thread is done. 4617c478bd9Sstevel@tonic-gate */ 4627c478bd9Sstevel@tonic-gate SCTP_CONDEMNED(sctp); 4637c478bd9Sstevel@tonic-gate WAKE_SCTP(sctp); 4647c478bd9Sstevel@tonic-gate SCTP_REFRELE(sctp); 4657c478bd9Sstevel@tonic-gate } 4667c478bd9Sstevel@tonic-gate 4677c478bd9Sstevel@tonic-gate /* 4687c478bd9Sstevel@tonic-gate * Unlink from global list and do the eager close. 4697c478bd9Sstevel@tonic-gate * Remove the refhold implicit in being on the global list. 4707c478bd9Sstevel@tonic-gate */ 4717c478bd9Sstevel@tonic-gate void 4727c478bd9Sstevel@tonic-gate sctp_close_eager(sctp_t *sctp) 4737c478bd9Sstevel@tonic-gate { 4747c478bd9Sstevel@tonic-gate SCTP_CONDEMNED(sctp); 4757c478bd9Sstevel@tonic-gate sctp_closei_local(sctp); 4767c478bd9Sstevel@tonic-gate SCTP_REFRELE(sctp); 4777c478bd9Sstevel@tonic-gate } 4787c478bd9Sstevel@tonic-gate 4797c478bd9Sstevel@tonic-gate /* 4807c478bd9Sstevel@tonic-gate * The sctp_t is going away. Remove it from all lists and set it 4817c478bd9Sstevel@tonic-gate * to SCTPS_IDLE. The caller has to remove it from the 4827c478bd9Sstevel@tonic-gate * global list. The freeing up of memory is deferred until 4837c478bd9Sstevel@tonic-gate * sctp_free(). This is needed since a thread in sctp_input() might have 4847c478bd9Sstevel@tonic-gate * done a SCTP_REFHOLD on this structure before it was removed from the 4857c478bd9Sstevel@tonic-gate * hashes. 4867c478bd9Sstevel@tonic-gate */ 4877c478bd9Sstevel@tonic-gate static void 4887c478bd9Sstevel@tonic-gate sctp_closei_local(sctp_t *sctp) 4897c478bd9Sstevel@tonic-gate { 4907c478bd9Sstevel@tonic-gate mblk_t *mp; 4917c478bd9Sstevel@tonic-gate ire_t *ire = NULL; 4927c478bd9Sstevel@tonic-gate conn_t *connp = sctp->sctp_connp; 4937c478bd9Sstevel@tonic-gate 4947c478bd9Sstevel@tonic-gate /* Stop and free the timers */ 4957c478bd9Sstevel@tonic-gate sctp_free_faddr_timers(sctp); 4967c478bd9Sstevel@tonic-gate if ((mp = sctp->sctp_heartbeat_mp) != NULL) { 4977c478bd9Sstevel@tonic-gate sctp_timer_free(mp); 4987c478bd9Sstevel@tonic-gate sctp->sctp_heartbeat_mp = NULL; 4997c478bd9Sstevel@tonic-gate } 5007c478bd9Sstevel@tonic-gate if ((mp = sctp->sctp_ack_mp) != NULL) { 5017c478bd9Sstevel@tonic-gate sctp_timer_free(mp); 5027c478bd9Sstevel@tonic-gate sctp->sctp_ack_mp = NULL; 5037c478bd9Sstevel@tonic-gate } 5047c478bd9Sstevel@tonic-gate 5057c478bd9Sstevel@tonic-gate /* Set the CONN_CLOSING flag so that IP will not cache IRE again. */ 5067c478bd9Sstevel@tonic-gate mutex_enter(&connp->conn_lock); 5077c478bd9Sstevel@tonic-gate connp->conn_state_flags |= CONN_CLOSING; 5087c478bd9Sstevel@tonic-gate ire = connp->conn_ire_cache; 5097c478bd9Sstevel@tonic-gate connp->conn_ire_cache = NULL; 5107c478bd9Sstevel@tonic-gate mutex_exit(&connp->conn_lock); 5117c478bd9Sstevel@tonic-gate if (ire != NULL) 5127c478bd9Sstevel@tonic-gate IRE_REFRELE_NOTR(ire); 5137c478bd9Sstevel@tonic-gate 5147c478bd9Sstevel@tonic-gate /* Remove from all hashes. */ 5157c478bd9Sstevel@tonic-gate sctp_bind_hash_remove(sctp); 5167c478bd9Sstevel@tonic-gate sctp_conn_hash_remove(sctp); 5177c478bd9Sstevel@tonic-gate sctp_listen_hash_remove(sctp); 5187c478bd9Sstevel@tonic-gate sctp->sctp_state = SCTPS_IDLE; 5197c478bd9Sstevel@tonic-gate 5207c478bd9Sstevel@tonic-gate /* 5217c478bd9Sstevel@tonic-gate * Clean up the recvq as much as possible. All those packets 5227c478bd9Sstevel@tonic-gate * will be silently dropped as this sctp_t is now in idle state. 5237c478bd9Sstevel@tonic-gate */ 5247c478bd9Sstevel@tonic-gate mutex_enter(&sctp->sctp_recvq_lock); 5257c478bd9Sstevel@tonic-gate while ((mp = sctp->sctp_recvq) != NULL) { 5267c478bd9Sstevel@tonic-gate mblk_t *ipsec_mp; 5277c478bd9Sstevel@tonic-gate 5287c478bd9Sstevel@tonic-gate sctp->sctp_recvq = mp->b_next; 5297c478bd9Sstevel@tonic-gate mp->b_next = NULL; 5307c478bd9Sstevel@tonic-gate if ((ipsec_mp = mp->b_prev) != NULL) { 5317c478bd9Sstevel@tonic-gate freeb(ipsec_mp); 5327c478bd9Sstevel@tonic-gate mp->b_prev = NULL; 5337c478bd9Sstevel@tonic-gate } 5347c478bd9Sstevel@tonic-gate freemsg(mp); 5357c478bd9Sstevel@tonic-gate } 5367c478bd9Sstevel@tonic-gate mutex_exit(&sctp->sctp_recvq_lock); 5377c478bd9Sstevel@tonic-gate } 5387c478bd9Sstevel@tonic-gate 5397c478bd9Sstevel@tonic-gate /* 5407c478bd9Sstevel@tonic-gate * Free memory associated with the sctp/ip header template. 5417c478bd9Sstevel@tonic-gate */ 5427c478bd9Sstevel@tonic-gate static void 5437c478bd9Sstevel@tonic-gate sctp_headers_free(sctp_t *sctp) 5447c478bd9Sstevel@tonic-gate { 5457c478bd9Sstevel@tonic-gate if (sctp->sctp_iphc != NULL) { 5467c478bd9Sstevel@tonic-gate kmem_free(sctp->sctp_iphc, sctp->sctp_iphc_len); 5477c478bd9Sstevel@tonic-gate sctp->sctp_iphc = NULL; 5487c478bd9Sstevel@tonic-gate sctp->sctp_ipha = NULL; 5497c478bd9Sstevel@tonic-gate sctp->sctp_hdr_len = 0; 5507c478bd9Sstevel@tonic-gate sctp->sctp_ip_hdr_len = 0; 5517c478bd9Sstevel@tonic-gate sctp->sctp_iphc_len = 0; 5527c478bd9Sstevel@tonic-gate sctp->sctp_sctph = NULL; 5537c478bd9Sstevel@tonic-gate sctp->sctp_hdr_len = 0; 5547c478bd9Sstevel@tonic-gate } 5557c478bd9Sstevel@tonic-gate if (sctp->sctp_iphc6 != NULL) { 5567c478bd9Sstevel@tonic-gate kmem_free(sctp->sctp_iphc6, sctp->sctp_iphc6_len); 5577c478bd9Sstevel@tonic-gate sctp->sctp_iphc6 = NULL; 5587c478bd9Sstevel@tonic-gate sctp->sctp_ip6h = NULL; 5597c478bd9Sstevel@tonic-gate sctp->sctp_hdr6_len = 0; 5607c478bd9Sstevel@tonic-gate sctp->sctp_ip_hdr6_len = 0; 5617c478bd9Sstevel@tonic-gate sctp->sctp_iphc6_len = 0; 5627c478bd9Sstevel@tonic-gate sctp->sctp_sctph6 = NULL; 5637c478bd9Sstevel@tonic-gate sctp->sctp_hdr6_len = 0; 5647c478bd9Sstevel@tonic-gate } 5657c478bd9Sstevel@tonic-gate } 5667c478bd9Sstevel@tonic-gate 5677c478bd9Sstevel@tonic-gate static void 5687c478bd9Sstevel@tonic-gate sctp_free_xmit_data(sctp_t *sctp) 5697c478bd9Sstevel@tonic-gate { 5707c478bd9Sstevel@tonic-gate mblk_t *ump = NULL; 5717c478bd9Sstevel@tonic-gate mblk_t *nump; 5727c478bd9Sstevel@tonic-gate mblk_t *mp; 5737c478bd9Sstevel@tonic-gate mblk_t *nmp; 5747c478bd9Sstevel@tonic-gate 5757c478bd9Sstevel@tonic-gate sctp->sctp_xmit_unacked = NULL; 5767c478bd9Sstevel@tonic-gate ump = sctp->sctp_xmit_head; 5777c478bd9Sstevel@tonic-gate sctp->sctp_xmit_tail = sctp->sctp_xmit_head = NULL; 5787c478bd9Sstevel@tonic-gate free_unsent: 5797c478bd9Sstevel@tonic-gate for (; ump != NULL; ump = nump) { 5807c478bd9Sstevel@tonic-gate for (mp = ump->b_cont; mp != NULL; mp = nmp) { 5817c478bd9Sstevel@tonic-gate nmp = mp->b_next; 5827c478bd9Sstevel@tonic-gate mp->b_next = NULL; 5837c478bd9Sstevel@tonic-gate mp->b_prev = NULL; 5847c478bd9Sstevel@tonic-gate freemsg(mp); 5857c478bd9Sstevel@tonic-gate } 5867c478bd9Sstevel@tonic-gate ASSERT(DB_REF(ump) == 1); 5877c478bd9Sstevel@tonic-gate nump = ump->b_next; 5887c478bd9Sstevel@tonic-gate ump->b_next = NULL; 5897c478bd9Sstevel@tonic-gate ump->b_prev = NULL; 5907c478bd9Sstevel@tonic-gate ump->b_cont = NULL; 5917c478bd9Sstevel@tonic-gate freeb(ump); 5927c478bd9Sstevel@tonic-gate } 5937c478bd9Sstevel@tonic-gate if ((ump = sctp->sctp_xmit_unsent) == NULL) { 5947c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_xmit_unsent_tail == NULL); 5957c478bd9Sstevel@tonic-gate return; 5967c478bd9Sstevel@tonic-gate } 5977c478bd9Sstevel@tonic-gate sctp->sctp_xmit_unsent = sctp->sctp_xmit_unsent_tail = NULL; 5987c478bd9Sstevel@tonic-gate goto free_unsent; 5997c478bd9Sstevel@tonic-gate } 6007c478bd9Sstevel@tonic-gate 6017c478bd9Sstevel@tonic-gate /* 6027c478bd9Sstevel@tonic-gate * Cleanup all the messages in the stream queue and the reassembly lists. 6037c478bd9Sstevel@tonic-gate * If 'free' is true, then delete the streams as well. 6047c478bd9Sstevel@tonic-gate */ 6057c478bd9Sstevel@tonic-gate void 6067c478bd9Sstevel@tonic-gate sctp_instream_cleanup(sctp_t *sctp, boolean_t free) 6077c478bd9Sstevel@tonic-gate { 6087c478bd9Sstevel@tonic-gate int i; 6097c478bd9Sstevel@tonic-gate mblk_t *mp; 6107c478bd9Sstevel@tonic-gate mblk_t *mp1; 6117c478bd9Sstevel@tonic-gate 6127c478bd9Sstevel@tonic-gate if (sctp->sctp_instr != NULL) { 6137c478bd9Sstevel@tonic-gate /* walk thru and flush out anything remaining in the Q */ 6147c478bd9Sstevel@tonic-gate for (i = 0; i < sctp->sctp_num_istr; i++) { 6157c478bd9Sstevel@tonic-gate mp = sctp->sctp_instr[i].istr_msgs; 6167c478bd9Sstevel@tonic-gate while (mp != NULL) { 6177c478bd9Sstevel@tonic-gate mp1 = mp->b_next; 6187c478bd9Sstevel@tonic-gate mp->b_next = mp->b_prev = NULL; 6197c478bd9Sstevel@tonic-gate freemsg(mp); 6207c478bd9Sstevel@tonic-gate mp = mp1; 6217c478bd9Sstevel@tonic-gate } 6227c478bd9Sstevel@tonic-gate sctp->sctp_instr[i].istr_msgs = NULL; 6237c478bd9Sstevel@tonic-gate sctp_free_reass((sctp->sctp_instr) + i); 6247c478bd9Sstevel@tonic-gate sctp->sctp_instr[i].nextseq = 0; 6257c478bd9Sstevel@tonic-gate } 6267c478bd9Sstevel@tonic-gate if (free) { 6277c478bd9Sstevel@tonic-gate kmem_free(sctp->sctp_instr, 6287c478bd9Sstevel@tonic-gate sizeof (*sctp->sctp_instr) * sctp->sctp_num_istr); 6297c478bd9Sstevel@tonic-gate sctp->sctp_instr = NULL; 6307c478bd9Sstevel@tonic-gate sctp->sctp_num_istr = 0; 6317c478bd9Sstevel@tonic-gate } 6327c478bd9Sstevel@tonic-gate } 6337c478bd9Sstevel@tonic-gate /* un-ordered fragments */ 6347c478bd9Sstevel@tonic-gate if (sctp->sctp_uo_frags != NULL) { 6357c478bd9Sstevel@tonic-gate for (mp = sctp->sctp_uo_frags; mp != NULL; mp = mp1) { 6367c478bd9Sstevel@tonic-gate mp1 = mp->b_next; 6377c478bd9Sstevel@tonic-gate mp->b_next = mp->b_prev = NULL; 6387c478bd9Sstevel@tonic-gate freemsg(mp); 6397c478bd9Sstevel@tonic-gate } 6407c478bd9Sstevel@tonic-gate } 6417c478bd9Sstevel@tonic-gate } 6427c478bd9Sstevel@tonic-gate 6437c478bd9Sstevel@tonic-gate /* 6447c478bd9Sstevel@tonic-gate * Last reference to the sctp_t is gone. Free all memory associated with it. 6457c478bd9Sstevel@tonic-gate * Called from SCTP_REFRELE. Called inline in sctp_close() 6467c478bd9Sstevel@tonic-gate */ 6477c478bd9Sstevel@tonic-gate void 6487c478bd9Sstevel@tonic-gate sctp_free(conn_t *connp) 6497c478bd9Sstevel@tonic-gate { 6507c478bd9Sstevel@tonic-gate sctp_t *sctp = CONN2SCTP(connp); 6517c478bd9Sstevel@tonic-gate int cnt; 6527c478bd9Sstevel@tonic-gate 6537c478bd9Sstevel@tonic-gate /* Unlink it from the global list */ 6547c478bd9Sstevel@tonic-gate SCTP_UNLINK(sctp); 6557c478bd9Sstevel@tonic-gate 6567c478bd9Sstevel@tonic-gate ASSERT(connp->conn_ref == 0); 6577c478bd9Sstevel@tonic-gate ASSERT(connp->conn_ulp == IPPROTO_SCTP); 6587c478bd9Sstevel@tonic-gate ASSERT(!MUTEX_HELD(&sctp->sctp_reflock)); 6597c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_refcnt == 0); 6607c478bd9Sstevel@tonic-gate 6617c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_ptpbhn == NULL && sctp->sctp_bind_hash == NULL); 6627c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_conn_hash_next == NULL && 6637c478bd9Sstevel@tonic-gate sctp->sctp_conn_hash_prev == NULL); 6647c478bd9Sstevel@tonic-gate 6657c478bd9Sstevel@tonic-gate 6667c478bd9Sstevel@tonic-gate /* Free up all the resources. */ 6677c478bd9Sstevel@tonic-gate 6687c478bd9Sstevel@tonic-gate /* blow away sctp stream management */ 6697c478bd9Sstevel@tonic-gate if (sctp->sctp_ostrcntrs != NULL) { 6707c478bd9Sstevel@tonic-gate kmem_free(sctp->sctp_ostrcntrs, 6717c478bd9Sstevel@tonic-gate sizeof (uint16_t) * sctp->sctp_num_ostr); 6727c478bd9Sstevel@tonic-gate sctp->sctp_ostrcntrs = NULL; 6737c478bd9Sstevel@tonic-gate } 6747c478bd9Sstevel@tonic-gate sctp_instream_cleanup(sctp, B_TRUE); 6757c478bd9Sstevel@tonic-gate 6767c478bd9Sstevel@tonic-gate /* Remove all data transfer resources. */ 6777c478bd9Sstevel@tonic-gate sctp->sctp_istr_nmsgs = 0; 6787c478bd9Sstevel@tonic-gate sctp->sctp_rxqueued = 0; 6797c478bd9Sstevel@tonic-gate sctp_free_xmit_data(sctp); 6807c478bd9Sstevel@tonic-gate sctp->sctp_unacked = 0; 6817c478bd9Sstevel@tonic-gate sctp->sctp_unsent = 0; 6821d8c4025Svi if (sctp->sctp_cxmit_list != NULL) 6831d8c4025Svi sctp_asconf_free_cxmit(sctp, NULL); 6841d8c4025Svi 6857c478bd9Sstevel@tonic-gate sctp->sctp_lastdata = NULL; 6867c478bd9Sstevel@tonic-gate 6877c478bd9Sstevel@tonic-gate /* Clear out default xmit settings */ 6887c478bd9Sstevel@tonic-gate sctp->sctp_def_stream = 0; 6897c478bd9Sstevel@tonic-gate sctp->sctp_def_flags = 0; 6907c478bd9Sstevel@tonic-gate sctp->sctp_def_ppid = 0; 6917c478bd9Sstevel@tonic-gate sctp->sctp_def_context = 0; 6927c478bd9Sstevel@tonic-gate sctp->sctp_def_timetolive = 0; 6937c478bd9Sstevel@tonic-gate 6947c478bd9Sstevel@tonic-gate if (sctp->sctp_sack_info != NULL) { 6957c478bd9Sstevel@tonic-gate sctp_free_set(sctp->sctp_sack_info); 6967c478bd9Sstevel@tonic-gate sctp->sctp_sack_info = NULL; 6977c478bd9Sstevel@tonic-gate } 6987c478bd9Sstevel@tonic-gate sctp->sctp_sack_gaps = 0; 6997c478bd9Sstevel@tonic-gate 7007c478bd9Sstevel@tonic-gate if (sctp->sctp_cookie_mp != NULL) { 7017c478bd9Sstevel@tonic-gate freemsg(sctp->sctp_cookie_mp); 7027c478bd9Sstevel@tonic-gate sctp->sctp_cookie_mp = NULL; 7037c478bd9Sstevel@tonic-gate } 7047c478bd9Sstevel@tonic-gate 7057c478bd9Sstevel@tonic-gate /* Remove all the address resources. */ 7067c478bd9Sstevel@tonic-gate sctp_zap_addrs(sctp); 7077c478bd9Sstevel@tonic-gate for (cnt = 0; cnt < SCTP_IPIF_HASH; cnt++) { 7087c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_saddrs[cnt].ipif_count == 0); 7097c478bd9Sstevel@tonic-gate list_destroy(&sctp->sctp_saddrs[cnt].sctp_ipif_list); 7107c478bd9Sstevel@tonic-gate } 7117c478bd9Sstevel@tonic-gate 71245916cd2Sjpk ip6_pkt_free(&sctp->sctp_sticky_ipp); 7137c478bd9Sstevel@tonic-gate 7147c478bd9Sstevel@tonic-gate if (sctp->sctp_hopopts != NULL) { 7157c478bd9Sstevel@tonic-gate mi_free(sctp->sctp_hopopts); 7167c478bd9Sstevel@tonic-gate sctp->sctp_hopopts = NULL; 7177c478bd9Sstevel@tonic-gate sctp->sctp_hopoptslen = 0; 7187c478bd9Sstevel@tonic-gate } 7197c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_hopoptslen == 0); 7207c478bd9Sstevel@tonic-gate if (sctp->sctp_dstopts != NULL) { 7217c478bd9Sstevel@tonic-gate mi_free(sctp->sctp_dstopts); 7227c478bd9Sstevel@tonic-gate sctp->sctp_dstopts = NULL; 7237c478bd9Sstevel@tonic-gate sctp->sctp_dstoptslen = 0; 7247c478bd9Sstevel@tonic-gate } 7257c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_dstoptslen == 0); 7267c478bd9Sstevel@tonic-gate if (sctp->sctp_rtdstopts != NULL) { 7277c478bd9Sstevel@tonic-gate mi_free(sctp->sctp_rtdstopts); 7287c478bd9Sstevel@tonic-gate sctp->sctp_rtdstopts = NULL; 7297c478bd9Sstevel@tonic-gate sctp->sctp_rtdstoptslen = 0; 7307c478bd9Sstevel@tonic-gate } 7317c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_rtdstoptslen == 0); 7327c478bd9Sstevel@tonic-gate if (sctp->sctp_rthdr != NULL) { 7337c478bd9Sstevel@tonic-gate mi_free(sctp->sctp_rthdr); 7347c478bd9Sstevel@tonic-gate sctp->sctp_rthdr = NULL; 7357c478bd9Sstevel@tonic-gate sctp->sctp_rthdrlen = 0; 7367c478bd9Sstevel@tonic-gate } 7377c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_rthdrlen == 0); 7387c478bd9Sstevel@tonic-gate sctp_headers_free(sctp); 7397c478bd9Sstevel@tonic-gate 7407c478bd9Sstevel@tonic-gate sctp->sctp_shutdown_faddr = NULL; 7417c478bd9Sstevel@tonic-gate 7427c478bd9Sstevel@tonic-gate /* Clear all the bitfields. */ 7437c478bd9Sstevel@tonic-gate bzero(&sctp->sctp_bits, sizeof (sctp->sctp_bits)); 7447c478bd9Sstevel@tonic-gate 7457c478bd9Sstevel@tonic-gate /* It is time to update the global statistics. */ 7467c478bd9Sstevel@tonic-gate UPDATE_MIB(&sctp_mib, sctpOutSCTPPkts, sctp->sctp_opkts); 7477c478bd9Sstevel@tonic-gate UPDATE_MIB(&sctp_mib, sctpOutCtrlChunks, sctp->sctp_obchunks); 7487c478bd9Sstevel@tonic-gate UPDATE_MIB(&sctp_mib, sctpOutOrderChunks, sctp->sctp_odchunks); 7497c478bd9Sstevel@tonic-gate UPDATE_MIB(&sctp_mib, sctpOutUnorderChunks, sctp->sctp_oudchunks); 7507c478bd9Sstevel@tonic-gate UPDATE_MIB(&sctp_mib, sctpRetransChunks, sctp->sctp_rxtchunks); 7517c478bd9Sstevel@tonic-gate UPDATE_MIB(&sctp_mib, sctpInSCTPPkts, sctp->sctp_ipkts); 7527c478bd9Sstevel@tonic-gate UPDATE_MIB(&sctp_mib, sctpInCtrlChunks, sctp->sctp_ibchunks); 7537c478bd9Sstevel@tonic-gate UPDATE_MIB(&sctp_mib, sctpInOrderChunks, sctp->sctp_idchunks); 7547c478bd9Sstevel@tonic-gate UPDATE_MIB(&sctp_mib, sctpInUnorderChunks, sctp->sctp_iudchunks); 7557c478bd9Sstevel@tonic-gate UPDATE_MIB(&sctp_mib, sctpFragUsrMsgs, sctp->sctp_fragdmsgs); 7567c478bd9Sstevel@tonic-gate UPDATE_MIB(&sctp_mib, sctpReasmUsrMsgs, sctp->sctp_reassmsgs); 7577c478bd9Sstevel@tonic-gate sctp->sctp_opkts = 0; 7587c478bd9Sstevel@tonic-gate sctp->sctp_obchunks = 0; 7597c478bd9Sstevel@tonic-gate sctp->sctp_odchunks = 0; 7607c478bd9Sstevel@tonic-gate sctp->sctp_oudchunks = 0; 7617c478bd9Sstevel@tonic-gate sctp->sctp_rxtchunks = 0; 7627c478bd9Sstevel@tonic-gate sctp->sctp_ipkts = 0; 7637c478bd9Sstevel@tonic-gate sctp->sctp_ibchunks = 0; 7647c478bd9Sstevel@tonic-gate sctp->sctp_idchunks = 0; 7657c478bd9Sstevel@tonic-gate sctp->sctp_iudchunks = 0; 7667c478bd9Sstevel@tonic-gate sctp->sctp_fragdmsgs = 0; 7677c478bd9Sstevel@tonic-gate sctp->sctp_reassmsgs = 0; 7687c478bd9Sstevel@tonic-gate 7697c478bd9Sstevel@tonic-gate sctp->sctp_autoclose = 0; 7707c478bd9Sstevel@tonic-gate sctp->sctp_tx_adaption_code = 0; 7717c478bd9Sstevel@tonic-gate 7727c478bd9Sstevel@tonic-gate /* Clean up conn_t stuff */ 7737c478bd9Sstevel@tonic-gate connp->conn_policy_cached = B_FALSE; 7747c478bd9Sstevel@tonic-gate if (connp->conn_latch != NULL) { 7757c478bd9Sstevel@tonic-gate IPLATCH_REFRELE(connp->conn_latch); 7767c478bd9Sstevel@tonic-gate connp->conn_latch = NULL; 7777c478bd9Sstevel@tonic-gate } 7787c478bd9Sstevel@tonic-gate if (connp->conn_policy != NULL) { 7797c478bd9Sstevel@tonic-gate IPPH_REFRELE(connp->conn_policy); 7807c478bd9Sstevel@tonic-gate connp->conn_policy = NULL; 7817c478bd9Sstevel@tonic-gate } 7827c478bd9Sstevel@tonic-gate if (connp->conn_ipsec_opt_mp != NULL) { 7837c478bd9Sstevel@tonic-gate freemsg(connp->conn_ipsec_opt_mp); 7847c478bd9Sstevel@tonic-gate connp->conn_ipsec_opt_mp = NULL; 7857c478bd9Sstevel@tonic-gate } 7867c478bd9Sstevel@tonic-gate if (connp->conn_cred != NULL) { 7877c478bd9Sstevel@tonic-gate crfree(connp->conn_cred); 7887c478bd9Sstevel@tonic-gate connp->conn_cred = NULL; 7897c478bd9Sstevel@tonic-gate } 7907c478bd9Sstevel@tonic-gate 7917c478bd9Sstevel@tonic-gate kmem_cache_free(sctp_conn_cache, connp); 7927c478bd9Sstevel@tonic-gate } 7937c478bd9Sstevel@tonic-gate 7947c478bd9Sstevel@tonic-gate /* Diagnostic routine used to return a string associated with the sctp state. */ 7957c478bd9Sstevel@tonic-gate char * 7967c478bd9Sstevel@tonic-gate sctp_display(sctp_t *sctp, char *sup_buf) 7977c478bd9Sstevel@tonic-gate { 7987c478bd9Sstevel@tonic-gate char *buf; 7997c478bd9Sstevel@tonic-gate char buf1[30]; 8007c478bd9Sstevel@tonic-gate static char priv_buf[INET6_ADDRSTRLEN * 2 + 80]; 8017c478bd9Sstevel@tonic-gate char *cp; 8027c478bd9Sstevel@tonic-gate 8037c478bd9Sstevel@tonic-gate if (sctp == NULL) 8047c478bd9Sstevel@tonic-gate return ("NULL_SCTP"); 8057c478bd9Sstevel@tonic-gate 8067c478bd9Sstevel@tonic-gate buf = (sup_buf != NULL) ? sup_buf : priv_buf; 8077c478bd9Sstevel@tonic-gate 8087c478bd9Sstevel@tonic-gate switch (sctp->sctp_state) { 8097c478bd9Sstevel@tonic-gate case SCTPS_IDLE: 8107c478bd9Sstevel@tonic-gate cp = "SCTP_IDLE"; 8117c478bd9Sstevel@tonic-gate break; 8127c478bd9Sstevel@tonic-gate case SCTPS_BOUND: 8137c478bd9Sstevel@tonic-gate cp = "SCTP_BOUND"; 8147c478bd9Sstevel@tonic-gate break; 8157c478bd9Sstevel@tonic-gate case SCTPS_LISTEN: 8167c478bd9Sstevel@tonic-gate cp = "SCTP_LISTEN"; 8177c478bd9Sstevel@tonic-gate break; 8187c478bd9Sstevel@tonic-gate case SCTPS_COOKIE_WAIT: 8197c478bd9Sstevel@tonic-gate cp = "SCTP_COOKIE_WAIT"; 8207c478bd9Sstevel@tonic-gate break; 8217c478bd9Sstevel@tonic-gate case SCTPS_COOKIE_ECHOED: 8227c478bd9Sstevel@tonic-gate cp = "SCTP_COOKIE_ECHOED"; 8237c478bd9Sstevel@tonic-gate break; 8247c478bd9Sstevel@tonic-gate case SCTPS_ESTABLISHED: 8257c478bd9Sstevel@tonic-gate cp = "SCTP_ESTABLISHED"; 8267c478bd9Sstevel@tonic-gate break; 8277c478bd9Sstevel@tonic-gate case SCTPS_SHUTDOWN_PENDING: 8287c478bd9Sstevel@tonic-gate cp = "SCTP_SHUTDOWN_PENDING"; 8297c478bd9Sstevel@tonic-gate break; 8307c478bd9Sstevel@tonic-gate case SCTPS_SHUTDOWN_SENT: 8317c478bd9Sstevel@tonic-gate cp = "SCTPS_SHUTDOWN_SENT"; 8327c478bd9Sstevel@tonic-gate break; 8337c478bd9Sstevel@tonic-gate case SCTPS_SHUTDOWN_RECEIVED: 8347c478bd9Sstevel@tonic-gate cp = "SCTPS_SHUTDOWN_RECEIVED"; 8357c478bd9Sstevel@tonic-gate break; 8367c478bd9Sstevel@tonic-gate case SCTPS_SHUTDOWN_ACK_SENT: 8377c478bd9Sstevel@tonic-gate cp = "SCTPS_SHUTDOWN_ACK_SENT"; 8387c478bd9Sstevel@tonic-gate break; 8397c478bd9Sstevel@tonic-gate default: 8407c478bd9Sstevel@tonic-gate (void) mi_sprintf(buf1, "SCTPUnkState(%d)", sctp->sctp_state); 8417c478bd9Sstevel@tonic-gate cp = buf1; 8427c478bd9Sstevel@tonic-gate break; 8437c478bd9Sstevel@tonic-gate } 8447c478bd9Sstevel@tonic-gate (void) mi_sprintf(buf, "[%u, %u] %s", 8457c478bd9Sstevel@tonic-gate ntohs(sctp->sctp_lport), ntohs(sctp->sctp_fport), cp); 8467c478bd9Sstevel@tonic-gate 8477c478bd9Sstevel@tonic-gate return (buf); 8487c478bd9Sstevel@tonic-gate } 8497c478bd9Sstevel@tonic-gate 8507c478bd9Sstevel@tonic-gate /* 8517c478bd9Sstevel@tonic-gate * Initialize protocol control block. If a parent exists, inherit 8527c478bd9Sstevel@tonic-gate * all values set through setsockopt(). 8537c478bd9Sstevel@tonic-gate */ 8547c478bd9Sstevel@tonic-gate static int 8557c478bd9Sstevel@tonic-gate sctp_init_values(sctp_t *sctp, sctp_t *psctp, int sleep) 8567c478bd9Sstevel@tonic-gate { 8577c478bd9Sstevel@tonic-gate int err; 8587c478bd9Sstevel@tonic-gate int cnt; 859*5d0bc3edSsommerfe conn_t *connp, *pconnp; 8607c478bd9Sstevel@tonic-gate 8617c478bd9Sstevel@tonic-gate ASSERT((sctp->sctp_family == AF_INET && 8627c478bd9Sstevel@tonic-gate sctp->sctp_ipversion == IPV4_VERSION) || 8637c478bd9Sstevel@tonic-gate (sctp->sctp_family == AF_INET6 && 8647c478bd9Sstevel@tonic-gate (sctp->sctp_ipversion == IPV4_VERSION || 8657c478bd9Sstevel@tonic-gate sctp->sctp_ipversion == IPV6_VERSION))); 8667c478bd9Sstevel@tonic-gate 8677c478bd9Sstevel@tonic-gate sctp->sctp_nsaddrs = 0; 8687c478bd9Sstevel@tonic-gate for (cnt = 0; cnt < SCTP_IPIF_HASH; cnt++) { 8697c478bd9Sstevel@tonic-gate sctp->sctp_saddrs[cnt].ipif_count = 0; 8707c478bd9Sstevel@tonic-gate list_create(&sctp->sctp_saddrs[cnt].sctp_ipif_list, 8717c478bd9Sstevel@tonic-gate sizeof (sctp_saddr_ipif_t), offsetof(sctp_saddr_ipif_t, 8727c478bd9Sstevel@tonic-gate saddr_ipif)); 8737c478bd9Sstevel@tonic-gate } 8747c478bd9Sstevel@tonic-gate sctp->sctp_ports = 0; 8757c478bd9Sstevel@tonic-gate sctp->sctp_running = B_FALSE; 8767c478bd9Sstevel@tonic-gate sctp->sctp_state = SCTPS_IDLE; 8777c478bd9Sstevel@tonic-gate 8787c478bd9Sstevel@tonic-gate sctp->sctp_refcnt = 1; 8797c478bd9Sstevel@tonic-gate 8807c478bd9Sstevel@tonic-gate sctp->sctp_strikes = 0; 8817c478bd9Sstevel@tonic-gate 8827c478bd9Sstevel@tonic-gate sctp->sctp_last_mtu_probe = lbolt64; 8837c478bd9Sstevel@tonic-gate sctp->sctp_mtu_probe_intvl = sctp_mtu_probe_interval; 8847c478bd9Sstevel@tonic-gate 8857c478bd9Sstevel@tonic-gate sctp->sctp_sack_gaps = 0; 8867c478bd9Sstevel@tonic-gate sctp->sctp_sack_toggle = 2; 8877c478bd9Sstevel@tonic-gate 8887c478bd9Sstevel@tonic-gate if (psctp != NULL) { 8897c478bd9Sstevel@tonic-gate /* 8907c478bd9Sstevel@tonic-gate * Inherit from parent 8917c478bd9Sstevel@tonic-gate */ 8927c478bd9Sstevel@tonic-gate sctp->sctp_iphc = kmem_zalloc(psctp->sctp_iphc_len, 8937c478bd9Sstevel@tonic-gate KM_NOSLEEP); 8947c478bd9Sstevel@tonic-gate if (sctp->sctp_iphc == NULL) 8957c478bd9Sstevel@tonic-gate return (ENOMEM); 8967c478bd9Sstevel@tonic-gate sctp->sctp_iphc_len = psctp->sctp_iphc_len; 8977c478bd9Sstevel@tonic-gate sctp->sctp_hdr_len = psctp->sctp_hdr_len; 8987c478bd9Sstevel@tonic-gate 8997c478bd9Sstevel@tonic-gate sctp->sctp_iphc6 = kmem_zalloc(psctp->sctp_iphc6_len, 9007c478bd9Sstevel@tonic-gate KM_NOSLEEP); 9017c478bd9Sstevel@tonic-gate if (sctp->sctp_iphc6 == NULL) { 9027c478bd9Sstevel@tonic-gate sctp->sctp_iphc6_len = 0; 9037c478bd9Sstevel@tonic-gate return (ENOMEM); 9047c478bd9Sstevel@tonic-gate } 9057c478bd9Sstevel@tonic-gate sctp->sctp_iphc6_len = psctp->sctp_iphc6_len; 9067c478bd9Sstevel@tonic-gate sctp->sctp_hdr6_len = psctp->sctp_hdr6_len; 9077c478bd9Sstevel@tonic-gate 9087c478bd9Sstevel@tonic-gate sctp->sctp_ip_hdr_len = psctp->sctp_ip_hdr_len; 9097c478bd9Sstevel@tonic-gate sctp->sctp_ip_hdr6_len = psctp->sctp_ip_hdr6_len; 9107c478bd9Sstevel@tonic-gate 9117c478bd9Sstevel@tonic-gate /* 9127c478bd9Sstevel@tonic-gate * Copy the IP+SCTP header templates from listener 9137c478bd9Sstevel@tonic-gate */ 9147c478bd9Sstevel@tonic-gate bcopy(psctp->sctp_iphc, sctp->sctp_iphc, 9157c478bd9Sstevel@tonic-gate psctp->sctp_hdr_len); 9167c478bd9Sstevel@tonic-gate sctp->sctp_ipha = (ipha_t *)sctp->sctp_iphc; 9177c478bd9Sstevel@tonic-gate sctp->sctp_sctph = (sctp_hdr_t *)(sctp->sctp_iphc + 9187c478bd9Sstevel@tonic-gate sctp->sctp_ip_hdr_len); 9197c478bd9Sstevel@tonic-gate 9207c478bd9Sstevel@tonic-gate bcopy(psctp->sctp_iphc6, sctp->sctp_iphc6, 9217c478bd9Sstevel@tonic-gate psctp->sctp_hdr6_len); 9227c478bd9Sstevel@tonic-gate if (((ip6i_t *)(sctp->sctp_iphc6))->ip6i_nxt == IPPROTO_RAW) { 9237c478bd9Sstevel@tonic-gate sctp->sctp_ip6h = (ip6_t *)(sctp->sctp_iphc6 + 9247c478bd9Sstevel@tonic-gate sizeof (ip6i_t)); 9257c478bd9Sstevel@tonic-gate } else { 9267c478bd9Sstevel@tonic-gate sctp->sctp_ip6h = (ip6_t *)sctp->sctp_iphc6; 9277c478bd9Sstevel@tonic-gate } 9287c478bd9Sstevel@tonic-gate sctp->sctp_sctph6 = (sctp_hdr_t *)(sctp->sctp_iphc6 + 9297c478bd9Sstevel@tonic-gate sctp->sctp_ip_hdr6_len); 9307c478bd9Sstevel@tonic-gate 9317c478bd9Sstevel@tonic-gate sctp->sctp_cookie_lifetime = psctp->sctp_cookie_lifetime; 9327c478bd9Sstevel@tonic-gate sctp->sctp_xmit_lowater = psctp->sctp_xmit_lowater; 9337c478bd9Sstevel@tonic-gate sctp->sctp_xmit_hiwater = psctp->sctp_xmit_hiwater; 9347c478bd9Sstevel@tonic-gate sctp->sctp_cwnd_max = psctp->sctp_cwnd_max; 9357c478bd9Sstevel@tonic-gate sctp->sctp_rwnd = psctp->sctp_rwnd; 9361d8c4025Svi sctp->sctp_irwnd = psctp->sctp_rwnd; 9377c478bd9Sstevel@tonic-gate 9387c478bd9Sstevel@tonic-gate sctp->sctp_rto_max = psctp->sctp_rto_max; 9397c478bd9Sstevel@tonic-gate sctp->sctp_init_rto_max = psctp->sctp_init_rto_max; 9407c478bd9Sstevel@tonic-gate sctp->sctp_rto_min = psctp->sctp_rto_min; 9417c478bd9Sstevel@tonic-gate sctp->sctp_rto_initial = psctp->sctp_rto_initial; 9427c478bd9Sstevel@tonic-gate sctp->sctp_pa_max_rxt = psctp->sctp_pa_max_rxt; 9437c478bd9Sstevel@tonic-gate sctp->sctp_pp_max_rxt = psctp->sctp_pp_max_rxt; 9447c478bd9Sstevel@tonic-gate sctp->sctp_max_init_rxt = psctp->sctp_max_init_rxt; 9457c478bd9Sstevel@tonic-gate 9467c478bd9Sstevel@tonic-gate sctp->sctp_def_stream = psctp->sctp_def_stream; 9477c478bd9Sstevel@tonic-gate sctp->sctp_def_flags = psctp->sctp_def_flags; 9487c478bd9Sstevel@tonic-gate sctp->sctp_def_ppid = psctp->sctp_def_ppid; 9497c478bd9Sstevel@tonic-gate sctp->sctp_def_context = psctp->sctp_def_context; 9507c478bd9Sstevel@tonic-gate sctp->sctp_def_timetolive = psctp->sctp_def_timetolive; 9517c478bd9Sstevel@tonic-gate 9527c478bd9Sstevel@tonic-gate sctp->sctp_num_istr = psctp->sctp_num_istr; 9537c478bd9Sstevel@tonic-gate sctp->sctp_num_ostr = psctp->sctp_num_ostr; 9547c478bd9Sstevel@tonic-gate 9557c478bd9Sstevel@tonic-gate sctp->sctp_hb_interval = psctp->sctp_hb_interval; 9567c478bd9Sstevel@tonic-gate sctp->sctp_autoclose = psctp->sctp_autoclose; 9577c478bd9Sstevel@tonic-gate sctp->sctp_tx_adaption_code = psctp->sctp_tx_adaption_code; 9587c478bd9Sstevel@tonic-gate 9597c478bd9Sstevel@tonic-gate /* xxx should be a better way to copy these flags xxx */ 9607c478bd9Sstevel@tonic-gate sctp->sctp_debug = psctp->sctp_debug; 9617c478bd9Sstevel@tonic-gate sctp->sctp_bound_to_all = psctp->sctp_bound_to_all; 9627c478bd9Sstevel@tonic-gate sctp->sctp_cansleep = psctp->sctp_cansleep; 9637c478bd9Sstevel@tonic-gate sctp->sctp_send_adaption = psctp->sctp_send_adaption; 9647c478bd9Sstevel@tonic-gate sctp->sctp_ndelay = psctp->sctp_ndelay; 9657c478bd9Sstevel@tonic-gate sctp->sctp_events = psctp->sctp_events; 9667c478bd9Sstevel@tonic-gate sctp->sctp_ipv6_recvancillary = psctp->sctp_ipv6_recvancillary; 967*5d0bc3edSsommerfe 968*5d0bc3edSsommerfe /* Copy IP-layer options */ 969*5d0bc3edSsommerfe connp = sctp->sctp_connp; 970*5d0bc3edSsommerfe pconnp = psctp->sctp_connp; 971*5d0bc3edSsommerfe 972*5d0bc3edSsommerfe connp->conn_broadcast = pconnp->conn_broadcast; 973*5d0bc3edSsommerfe connp->conn_loopback = pconnp->conn_loopback; 974*5d0bc3edSsommerfe connp->conn_dontroute = pconnp->conn_dontroute; 975*5d0bc3edSsommerfe connp->conn_reuseaddr = pconnp->conn_reuseaddr; 976*5d0bc3edSsommerfe 9777c478bd9Sstevel@tonic-gate } else { 9787c478bd9Sstevel@tonic-gate /* 9797c478bd9Sstevel@tonic-gate * Initialize the header template 9807c478bd9Sstevel@tonic-gate */ 9817c478bd9Sstevel@tonic-gate if ((err = sctp_header_init_ipv4(sctp, sleep)) != 0) { 9827c478bd9Sstevel@tonic-gate return (err); 9837c478bd9Sstevel@tonic-gate } 9847c478bd9Sstevel@tonic-gate if ((err = sctp_header_init_ipv6(sctp, sleep)) != 0) { 9857c478bd9Sstevel@tonic-gate return (err); 9867c478bd9Sstevel@tonic-gate } 9877c478bd9Sstevel@tonic-gate 9887c478bd9Sstevel@tonic-gate /* 9897c478bd9Sstevel@tonic-gate * Set to system defaults 9907c478bd9Sstevel@tonic-gate */ 9917c478bd9Sstevel@tonic-gate sctp->sctp_cookie_lifetime = MSEC_TO_TICK(sctp_cookie_life); 9927c478bd9Sstevel@tonic-gate sctp->sctp_xmit_lowater = sctp_xmit_lowat; 9937c478bd9Sstevel@tonic-gate sctp->sctp_xmit_hiwater = sctp_xmit_hiwat; 9947c478bd9Sstevel@tonic-gate sctp->sctp_cwnd_max = sctp_cwnd_max_; 9957c478bd9Sstevel@tonic-gate sctp->sctp_rwnd = sctp_recv_hiwat; 9961d8c4025Svi sctp->sctp_irwnd = sctp->sctp_rwnd; 9977c478bd9Sstevel@tonic-gate sctp->sctp_rto_max = MSEC_TO_TICK(sctp_rto_maxg); 9987c478bd9Sstevel@tonic-gate sctp->sctp_init_rto_max = sctp->sctp_rto_max; 9997c478bd9Sstevel@tonic-gate sctp->sctp_rto_min = MSEC_TO_TICK(sctp_rto_ming); 10007c478bd9Sstevel@tonic-gate sctp->sctp_rto_initial = MSEC_TO_TICK(sctp_rto_initialg); 10017c478bd9Sstevel@tonic-gate sctp->sctp_pa_max_rxt = sctp_pa_max_retr; 10027c478bd9Sstevel@tonic-gate sctp->sctp_pp_max_rxt = sctp_pp_max_retr; 10037c478bd9Sstevel@tonic-gate sctp->sctp_max_init_rxt = sctp_max_init_retr; 10047c478bd9Sstevel@tonic-gate 10057c478bd9Sstevel@tonic-gate sctp->sctp_num_istr = sctp_max_in_streams; 10067c478bd9Sstevel@tonic-gate sctp->sctp_num_ostr = sctp_initial_out_streams; 10077c478bd9Sstevel@tonic-gate 10087c478bd9Sstevel@tonic-gate sctp->sctp_hb_interval = MSEC_TO_TICK(sctp_heartbeat_interval); 10097c478bd9Sstevel@tonic-gate } 10107c478bd9Sstevel@tonic-gate sctp->sctp_understands_asconf = B_TRUE; 10117c478bd9Sstevel@tonic-gate sctp->sctp_understands_addip = B_TRUE; 10127c478bd9Sstevel@tonic-gate sctp->sctp_prsctp_aware = B_FALSE; 10137c478bd9Sstevel@tonic-gate 10147c478bd9Sstevel@tonic-gate sctp->sctp_connp->conn_ref = 1; 10157c478bd9Sstevel@tonic-gate sctp->sctp_connp->conn_fully_bound = B_FALSE; 10167c478bd9Sstevel@tonic-gate 10177c478bd9Sstevel@tonic-gate sctp->sctp_prsctpdrop = 0; 10187c478bd9Sstevel@tonic-gate sctp->sctp_msgcount = 0; 10197c478bd9Sstevel@tonic-gate 10207c478bd9Sstevel@tonic-gate return (0); 10217c478bd9Sstevel@tonic-gate } 10227c478bd9Sstevel@tonic-gate 10237c478bd9Sstevel@tonic-gate /* 10247c478bd9Sstevel@tonic-gate * Extracts the init tag from an INIT chunk and checks if it matches 10257c478bd9Sstevel@tonic-gate * the sctp's verification tag. Returns 0 if it doesn't match, 1 if 10267c478bd9Sstevel@tonic-gate * it does. 10277c478bd9Sstevel@tonic-gate */ 10287c478bd9Sstevel@tonic-gate static boolean_t 10297c478bd9Sstevel@tonic-gate sctp_icmp_verf(sctp_t *sctp, sctp_hdr_t *sh, mblk_t *mp) 10307c478bd9Sstevel@tonic-gate { 10317c478bd9Sstevel@tonic-gate sctp_chunk_hdr_t *sch; 10327c478bd9Sstevel@tonic-gate uint32_t verf, *vp; 10337c478bd9Sstevel@tonic-gate 10347c478bd9Sstevel@tonic-gate sch = (sctp_chunk_hdr_t *)(sh + 1); 10357c478bd9Sstevel@tonic-gate vp = (uint32_t *)(sch + 1); 10367c478bd9Sstevel@tonic-gate 10377c478bd9Sstevel@tonic-gate /* Need at least the data chunk hdr and the first 4 bytes of INIT */ 10387c478bd9Sstevel@tonic-gate if ((unsigned char *)(vp + 1) > mp->b_wptr) { 10397c478bd9Sstevel@tonic-gate return (B_FALSE); 10407c478bd9Sstevel@tonic-gate } 10417c478bd9Sstevel@tonic-gate 10427c478bd9Sstevel@tonic-gate bcopy(vp, &verf, sizeof (verf)); 10437c478bd9Sstevel@tonic-gate 10447c478bd9Sstevel@tonic-gate if (verf == sctp->sctp_lvtag) { 10457c478bd9Sstevel@tonic-gate return (B_TRUE); 10467c478bd9Sstevel@tonic-gate } 10477c478bd9Sstevel@tonic-gate return (B_FALSE); 10487c478bd9Sstevel@tonic-gate } 10497c478bd9Sstevel@tonic-gate 10507c478bd9Sstevel@tonic-gate /* 10517c478bd9Sstevel@tonic-gate * sctp_icmp_error is called by sctp_input() to process ICMP error messages 10527c478bd9Sstevel@tonic-gate * passed up by IP. The queue is the default queue. We need to find a sctp_t 10537c478bd9Sstevel@tonic-gate * that corresponds to the returned datagram. Passes the message back in on 10547c478bd9Sstevel@tonic-gate * the correct queue once it has located the connection. 10557c478bd9Sstevel@tonic-gate * Assumes that IP has pulled up everything up to and including 10567c478bd9Sstevel@tonic-gate * the ICMP header. 10577c478bd9Sstevel@tonic-gate */ 10587c478bd9Sstevel@tonic-gate void 10597c478bd9Sstevel@tonic-gate sctp_icmp_error(sctp_t *sctp, mblk_t *mp) 10607c478bd9Sstevel@tonic-gate { 10617c478bd9Sstevel@tonic-gate icmph_t *icmph; 10627c478bd9Sstevel@tonic-gate ipha_t *ipha; 10637c478bd9Sstevel@tonic-gate int iph_hdr_length; 10647c478bd9Sstevel@tonic-gate sctp_hdr_t *sctph; 10657c478bd9Sstevel@tonic-gate mblk_t *first_mp; 10667c478bd9Sstevel@tonic-gate uint32_t new_mtu; 10677c478bd9Sstevel@tonic-gate in6_addr_t dst; 10687c478bd9Sstevel@tonic-gate sctp_faddr_t *fp; 10697c478bd9Sstevel@tonic-gate 107045916cd2Sjpk dprint(1, ("sctp_icmp_error: sctp=%p, mp=%p\n", (void *)sctp, 107145916cd2Sjpk (void *)mp)); 10727c478bd9Sstevel@tonic-gate 10737c478bd9Sstevel@tonic-gate first_mp = mp; 10747c478bd9Sstevel@tonic-gate 10757c478bd9Sstevel@tonic-gate ipha = (ipha_t *)mp->b_rptr; 10767c478bd9Sstevel@tonic-gate if (IPH_HDR_VERSION(ipha) != IPV4_VERSION) { 10777c478bd9Sstevel@tonic-gate ASSERT(IPH_HDR_VERSION(ipha) == IPV6_VERSION); 10787c478bd9Sstevel@tonic-gate sctp_icmp_error_ipv6(sctp, first_mp); 10797c478bd9Sstevel@tonic-gate return; 10807c478bd9Sstevel@tonic-gate } 10817c478bd9Sstevel@tonic-gate 10827c478bd9Sstevel@tonic-gate iph_hdr_length = IPH_HDR_LENGTH(ipha); 10837c478bd9Sstevel@tonic-gate icmph = (icmph_t *)&mp->b_rptr[iph_hdr_length]; 10847c478bd9Sstevel@tonic-gate ipha = (ipha_t *)&icmph[1]; 10857c478bd9Sstevel@tonic-gate iph_hdr_length = IPH_HDR_LENGTH(ipha); 10867c478bd9Sstevel@tonic-gate sctph = (sctp_hdr_t *)((char *)ipha + iph_hdr_length); 10877c478bd9Sstevel@tonic-gate if ((uchar_t *)(sctph + 1) >= mp->b_wptr) { 10887c478bd9Sstevel@tonic-gate /* not enough data for SCTP header */ 10897c478bd9Sstevel@tonic-gate freemsg(first_mp); 10907c478bd9Sstevel@tonic-gate return; 10917c478bd9Sstevel@tonic-gate } 10927c478bd9Sstevel@tonic-gate 10937c478bd9Sstevel@tonic-gate switch (icmph->icmph_type) { 10947c478bd9Sstevel@tonic-gate case ICMP_DEST_UNREACHABLE: 10957c478bd9Sstevel@tonic-gate switch (icmph->icmph_code) { 10967c478bd9Sstevel@tonic-gate case ICMP_FRAGMENTATION_NEEDED: 10977c478bd9Sstevel@tonic-gate /* 10987c478bd9Sstevel@tonic-gate * Reduce the MSS based on the new MTU. This will 10997c478bd9Sstevel@tonic-gate * eliminate any fragmentation locally. 11007c478bd9Sstevel@tonic-gate * N.B. There may well be some funny side-effects on 11017c478bd9Sstevel@tonic-gate * the local send policy and the remote receive policy. 11027c478bd9Sstevel@tonic-gate * Pending further research, we provide 11037c478bd9Sstevel@tonic-gate * sctp_ignore_path_mtu just in case this proves 11047c478bd9Sstevel@tonic-gate * disastrous somewhere. 11057c478bd9Sstevel@tonic-gate * 11067c478bd9Sstevel@tonic-gate * After updating the MSS, retransmit part of the 11077c478bd9Sstevel@tonic-gate * dropped segment using the new mss by calling 11087c478bd9Sstevel@tonic-gate * sctp_wput_slow(). Need to adjust all those 11097c478bd9Sstevel@tonic-gate * params to make sure sctp_wput_slow() work properly. 11107c478bd9Sstevel@tonic-gate */ 11117c478bd9Sstevel@tonic-gate if (sctp_ignore_path_mtu) 11127c478bd9Sstevel@tonic-gate break; 11137c478bd9Sstevel@tonic-gate 11147c478bd9Sstevel@tonic-gate /* find the offending faddr */ 11157c478bd9Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(ipha->ipha_dst, &dst); 11167c478bd9Sstevel@tonic-gate fp = sctp_lookup_faddr(sctp, &dst); 11177c478bd9Sstevel@tonic-gate if (fp == NULL) { 11187c478bd9Sstevel@tonic-gate break; 11197c478bd9Sstevel@tonic-gate } 11207c478bd9Sstevel@tonic-gate 11217c478bd9Sstevel@tonic-gate new_mtu = ntohs(icmph->icmph_du_mtu); 11227c478bd9Sstevel@tonic-gate 11237c478bd9Sstevel@tonic-gate if (new_mtu - sctp->sctp_hdr_len >= fp->sfa_pmss) 11247c478bd9Sstevel@tonic-gate break; 11257c478bd9Sstevel@tonic-gate 11267c478bd9Sstevel@tonic-gate /* 11277c478bd9Sstevel@tonic-gate * Make sure that sfa_pmss is a multiple of 11287c478bd9Sstevel@tonic-gate * SCTP_ALIGN. 11297c478bd9Sstevel@tonic-gate */ 11307c478bd9Sstevel@tonic-gate fp->sfa_pmss = (new_mtu - sctp->sctp_hdr_len) & 11317c478bd9Sstevel@tonic-gate ~(SCTP_ALIGN - 1); 11327c478bd9Sstevel@tonic-gate fp->pmtu_discovered = 1; 11337c478bd9Sstevel@tonic-gate 11347c478bd9Sstevel@tonic-gate break; 11357c478bd9Sstevel@tonic-gate case ICMP_PORT_UNREACHABLE: 11367c478bd9Sstevel@tonic-gate case ICMP_PROTOCOL_UNREACHABLE: 11377c478bd9Sstevel@tonic-gate switch (sctp->sctp_state) { 11387c478bd9Sstevel@tonic-gate case SCTPS_COOKIE_WAIT: 11397c478bd9Sstevel@tonic-gate case SCTPS_COOKIE_ECHOED: 11407c478bd9Sstevel@tonic-gate /* make sure the verification tag matches */ 11417c478bd9Sstevel@tonic-gate if (!sctp_icmp_verf(sctp, sctph, mp)) { 11427c478bd9Sstevel@tonic-gate break; 11437c478bd9Sstevel@tonic-gate } 11447c478bd9Sstevel@tonic-gate BUMP_MIB(&sctp_mib, sctpAborted); 11457c478bd9Sstevel@tonic-gate sctp_clean_death(sctp, ECONNREFUSED); 11467c478bd9Sstevel@tonic-gate break; 11477c478bd9Sstevel@tonic-gate } 11487c478bd9Sstevel@tonic-gate break; 11497c478bd9Sstevel@tonic-gate case ICMP_HOST_UNREACHABLE: 11507c478bd9Sstevel@tonic-gate case ICMP_NET_UNREACHABLE: 11517c478bd9Sstevel@tonic-gate /* Record the error in case we finally time out. */ 11527c478bd9Sstevel@tonic-gate sctp->sctp_client_errno = (icmph->icmph_code == 11537c478bd9Sstevel@tonic-gate ICMP_HOST_UNREACHABLE) ? EHOSTUNREACH : ENETUNREACH; 11547c478bd9Sstevel@tonic-gate break; 11557c478bd9Sstevel@tonic-gate default: 11567c478bd9Sstevel@tonic-gate break; 11577c478bd9Sstevel@tonic-gate } 11587c478bd9Sstevel@tonic-gate break; 11597c478bd9Sstevel@tonic-gate case ICMP_SOURCE_QUENCH: { 11607c478bd9Sstevel@tonic-gate /* Reduce the sending rate as if we got a retransmit timeout */ 11617c478bd9Sstevel@tonic-gate break; 11627c478bd9Sstevel@tonic-gate } 11637c478bd9Sstevel@tonic-gate } 11647c478bd9Sstevel@tonic-gate freemsg(first_mp); 11657c478bd9Sstevel@tonic-gate } 11667c478bd9Sstevel@tonic-gate 11677c478bd9Sstevel@tonic-gate /* 11687c478bd9Sstevel@tonic-gate * sctp_icmp_error_ipv6() is called by sctp_icmp_error() to process ICMPv6 11697c478bd9Sstevel@tonic-gate * error messages passed up by IP. 11707c478bd9Sstevel@tonic-gate * Assumes that IP has pulled up all the extension headers as well 11717c478bd9Sstevel@tonic-gate * as the ICMPv6 header. 11727c478bd9Sstevel@tonic-gate */ 11737c478bd9Sstevel@tonic-gate static void 11747c478bd9Sstevel@tonic-gate sctp_icmp_error_ipv6(sctp_t *sctp, mblk_t *mp) 11757c478bd9Sstevel@tonic-gate { 11767c478bd9Sstevel@tonic-gate icmp6_t *icmp6; 11777c478bd9Sstevel@tonic-gate ip6_t *ip6h; 11787c478bd9Sstevel@tonic-gate uint16_t iph_hdr_length; 11797c478bd9Sstevel@tonic-gate sctp_hdr_t *sctpha; 11807c478bd9Sstevel@tonic-gate uint8_t *nexthdrp; 11817c478bd9Sstevel@tonic-gate uint32_t new_mtu; 11827c478bd9Sstevel@tonic-gate sctp_faddr_t *fp; 11837c478bd9Sstevel@tonic-gate 11847c478bd9Sstevel@tonic-gate ip6h = (ip6_t *)mp->b_rptr; 11857c478bd9Sstevel@tonic-gate iph_hdr_length = (ip6h->ip6_nxt != IPPROTO_SCTP) ? 11867c478bd9Sstevel@tonic-gate ip_hdr_length_v6(mp, ip6h) : IPV6_HDR_LEN; 11877c478bd9Sstevel@tonic-gate 11887c478bd9Sstevel@tonic-gate icmp6 = (icmp6_t *)&mp->b_rptr[iph_hdr_length]; 11897c478bd9Sstevel@tonic-gate ip6h = (ip6_t *)&icmp6[1]; 11907c478bd9Sstevel@tonic-gate if (!ip_hdr_length_nexthdr_v6(mp, ip6h, &iph_hdr_length, &nexthdrp)) { 11917c478bd9Sstevel@tonic-gate freemsg(mp); 11927c478bd9Sstevel@tonic-gate return; 11937c478bd9Sstevel@tonic-gate } 11947c478bd9Sstevel@tonic-gate ASSERT(*nexthdrp == IPPROTO_SCTP); 11957c478bd9Sstevel@tonic-gate 11967c478bd9Sstevel@tonic-gate /* XXX need ifindex to find connection */ 11977c478bd9Sstevel@tonic-gate sctpha = (sctp_hdr_t *)((char *)ip6h + iph_hdr_length); 11987c478bd9Sstevel@tonic-gate if ((uchar_t *)sctpha >= mp->b_wptr) { 11997c478bd9Sstevel@tonic-gate /* not enough data for SCTP header */ 12007c478bd9Sstevel@tonic-gate freemsg(mp); 12017c478bd9Sstevel@tonic-gate return; 12027c478bd9Sstevel@tonic-gate } 12037c478bd9Sstevel@tonic-gate switch (icmp6->icmp6_type) { 12047c478bd9Sstevel@tonic-gate case ICMP6_PACKET_TOO_BIG: 12057c478bd9Sstevel@tonic-gate /* 12067c478bd9Sstevel@tonic-gate * Reduce the MSS based on the new MTU. This will 12077c478bd9Sstevel@tonic-gate * eliminate any fragmentation locally. 12087c478bd9Sstevel@tonic-gate * N.B. There may well be some funny side-effects on 12097c478bd9Sstevel@tonic-gate * the local send policy and the remote receive policy. 12107c478bd9Sstevel@tonic-gate * Pending further research, we provide 12117c478bd9Sstevel@tonic-gate * sctp_ignore_path_mtu just in case this proves 12127c478bd9Sstevel@tonic-gate * disastrous somewhere. 12137c478bd9Sstevel@tonic-gate * 12147c478bd9Sstevel@tonic-gate * After updating the MSS, retransmit part of the 12157c478bd9Sstevel@tonic-gate * dropped segment using the new mss by calling 12167c478bd9Sstevel@tonic-gate * sctp_wput_slow(). Need to adjust all those 12177c478bd9Sstevel@tonic-gate * params to make sure sctp_wput_slow() work properly. 12187c478bd9Sstevel@tonic-gate */ 12197c478bd9Sstevel@tonic-gate if (sctp_ignore_path_mtu) 12207c478bd9Sstevel@tonic-gate break; 12217c478bd9Sstevel@tonic-gate 12227c478bd9Sstevel@tonic-gate /* find the offending faddr */ 12237c478bd9Sstevel@tonic-gate fp = sctp_lookup_faddr(sctp, &ip6h->ip6_dst); 12247c478bd9Sstevel@tonic-gate if (fp == NULL) { 12257c478bd9Sstevel@tonic-gate break; 12267c478bd9Sstevel@tonic-gate } 12277c478bd9Sstevel@tonic-gate 12287c478bd9Sstevel@tonic-gate new_mtu = ntohs(icmp6->icmp6_mtu); 12297c478bd9Sstevel@tonic-gate 12307c478bd9Sstevel@tonic-gate if (new_mtu - sctp->sctp_hdr6_len >= fp->sfa_pmss) 12317c478bd9Sstevel@tonic-gate break; 12327c478bd9Sstevel@tonic-gate 12337c478bd9Sstevel@tonic-gate /* Make sure that sfa_pmss is a multiple of SCTP_ALIGN. */ 12347c478bd9Sstevel@tonic-gate fp->sfa_pmss = (new_mtu - sctp->sctp_hdr6_len) & 12357c478bd9Sstevel@tonic-gate ~(SCTP_ALIGN - 1); 12367c478bd9Sstevel@tonic-gate fp->pmtu_discovered = 1; 12377c478bd9Sstevel@tonic-gate 12387c478bd9Sstevel@tonic-gate break; 12397c478bd9Sstevel@tonic-gate 12407c478bd9Sstevel@tonic-gate case ICMP6_DST_UNREACH: 12417c478bd9Sstevel@tonic-gate switch (icmp6->icmp6_code) { 12427c478bd9Sstevel@tonic-gate case ICMP6_DST_UNREACH_NOPORT: 12437c478bd9Sstevel@tonic-gate /* make sure the verification tag matches */ 12447c478bd9Sstevel@tonic-gate if (!sctp_icmp_verf(sctp, sctpha, mp)) { 12457c478bd9Sstevel@tonic-gate break; 12467c478bd9Sstevel@tonic-gate } 12477c478bd9Sstevel@tonic-gate if (sctp->sctp_state == SCTPS_COOKIE_WAIT || 12487c478bd9Sstevel@tonic-gate sctp->sctp_state == SCTPS_COOKIE_ECHOED) { 12497c478bd9Sstevel@tonic-gate BUMP_MIB(&sctp_mib, sctpAborted); 12507c478bd9Sstevel@tonic-gate sctp_clean_death(sctp, ECONNREFUSED); 12517c478bd9Sstevel@tonic-gate } 12527c478bd9Sstevel@tonic-gate break; 12537c478bd9Sstevel@tonic-gate 12547c478bd9Sstevel@tonic-gate case ICMP6_DST_UNREACH_ADMIN: 12557c478bd9Sstevel@tonic-gate case ICMP6_DST_UNREACH_NOROUTE: 12567c478bd9Sstevel@tonic-gate case ICMP6_DST_UNREACH_NOTNEIGHBOR: 12577c478bd9Sstevel@tonic-gate case ICMP6_DST_UNREACH_ADDR: 12587c478bd9Sstevel@tonic-gate /* Record the error in case we finally time out. */ 12597c478bd9Sstevel@tonic-gate sctp->sctp_client_errno = EHOSTUNREACH; 12607c478bd9Sstevel@tonic-gate break; 12617c478bd9Sstevel@tonic-gate default: 12627c478bd9Sstevel@tonic-gate break; 12637c478bd9Sstevel@tonic-gate } 12647c478bd9Sstevel@tonic-gate break; 12657c478bd9Sstevel@tonic-gate 12667c478bd9Sstevel@tonic-gate case ICMP6_PARAM_PROB: 12677c478bd9Sstevel@tonic-gate /* If this corresponds to an ICMP_PROTOCOL_UNREACHABLE */ 12687c478bd9Sstevel@tonic-gate if (icmp6->icmp6_code == ICMP6_PARAMPROB_NEXTHEADER && 12697c478bd9Sstevel@tonic-gate (uchar_t *)ip6h + icmp6->icmp6_pptr == 12707c478bd9Sstevel@tonic-gate (uchar_t *)nexthdrp) { 12717c478bd9Sstevel@tonic-gate /* make sure the verification tag matches */ 12727c478bd9Sstevel@tonic-gate if (!sctp_icmp_verf(sctp, sctpha, mp)) { 12737c478bd9Sstevel@tonic-gate break; 12747c478bd9Sstevel@tonic-gate } 12757c478bd9Sstevel@tonic-gate if (sctp->sctp_state == SCTPS_COOKIE_WAIT) { 12767c478bd9Sstevel@tonic-gate BUMP_MIB(&sctp_mib, sctpAborted); 12777c478bd9Sstevel@tonic-gate sctp_clean_death(sctp, ECONNREFUSED); 12787c478bd9Sstevel@tonic-gate } 12797c478bd9Sstevel@tonic-gate break; 12807c478bd9Sstevel@tonic-gate } 12817c478bd9Sstevel@tonic-gate break; 12827c478bd9Sstevel@tonic-gate 12837c478bd9Sstevel@tonic-gate case ICMP6_TIME_EXCEEDED: 12847c478bd9Sstevel@tonic-gate default: 12857c478bd9Sstevel@tonic-gate break; 12867c478bd9Sstevel@tonic-gate } 12877c478bd9Sstevel@tonic-gate freemsg(mp); 12887c478bd9Sstevel@tonic-gate } 12897c478bd9Sstevel@tonic-gate 12907c478bd9Sstevel@tonic-gate /* 12917c478bd9Sstevel@tonic-gate * Called by sockfs to create a new sctp instance. 12927c478bd9Sstevel@tonic-gate * 12937c478bd9Sstevel@tonic-gate * If parent pointer is passed in, inherit settings from it. 12947c478bd9Sstevel@tonic-gate */ 12957c478bd9Sstevel@tonic-gate sctp_t * 12967c478bd9Sstevel@tonic-gate sctp_create(void *sctp_ulpd, sctp_t *parent, int family, int flags, 12977c478bd9Sstevel@tonic-gate const sctp_upcalls_t *sctp_upcalls, sctp_sockbuf_limits_t *sbl, 12987c478bd9Sstevel@tonic-gate cred_t *credp) 12997c478bd9Sstevel@tonic-gate { 13007c478bd9Sstevel@tonic-gate sctp_t *sctp, *psctp; 13017c478bd9Sstevel@tonic-gate conn_t *sctp_connp; 13027c478bd9Sstevel@tonic-gate mblk_t *ack_mp, *hb_mp; 13037c478bd9Sstevel@tonic-gate int sleep = flags & SCTP_CAN_BLOCK ? KM_SLEEP : KM_NOSLEEP; 13047c478bd9Sstevel@tonic-gate 13057c478bd9Sstevel@tonic-gate /* User must supply a credential. */ 13067c478bd9Sstevel@tonic-gate if (credp == NULL) 13077c478bd9Sstevel@tonic-gate return (NULL); 13087c478bd9Sstevel@tonic-gate 130977c67f2fSkcpoon if ((sctp_connp = ipcl_conn_create(IPCL_SCTPCONN, sleep)) == NULL) { 131077c67f2fSkcpoon SCTP_KSTAT(sctp_conn_create); 13117c478bd9Sstevel@tonic-gate return (NULL); 131277c67f2fSkcpoon } 131345916cd2Sjpk sctp_connp->conn_ulp_labeled = is_system_labeled(); 131445916cd2Sjpk 13157c478bd9Sstevel@tonic-gate psctp = (sctp_t *)parent; 13167c478bd9Sstevel@tonic-gate 13177c478bd9Sstevel@tonic-gate sctp = CONN2SCTP(sctp_connp); 13187c478bd9Sstevel@tonic-gate 13197c478bd9Sstevel@tonic-gate if ((ack_mp = sctp_timer_alloc(sctp, sctp_ack_timer)) == NULL || 13207c478bd9Sstevel@tonic-gate (hb_mp = sctp_timer_alloc(sctp, sctp_heartbeat_timer)) == NULL) { 13217c478bd9Sstevel@tonic-gate if (ack_mp != NULL) 13227c478bd9Sstevel@tonic-gate freeb(ack_mp); 13237c478bd9Sstevel@tonic-gate kmem_cache_free(sctp_conn_cache, sctp_connp); 13247c478bd9Sstevel@tonic-gate return (NULL); 13257c478bd9Sstevel@tonic-gate } 13267c478bd9Sstevel@tonic-gate 13277c478bd9Sstevel@tonic-gate sctp->sctp_ack_mp = ack_mp; 13287c478bd9Sstevel@tonic-gate sctp->sctp_heartbeat_mp = hb_mp; 13297c478bd9Sstevel@tonic-gate 13307c478bd9Sstevel@tonic-gate switch (family) { 13317c478bd9Sstevel@tonic-gate case AF_INET6: 13327c478bd9Sstevel@tonic-gate sctp_connp->conn_af_isv6 = B_TRUE; 13337c478bd9Sstevel@tonic-gate sctp->sctp_ipversion = IPV6_VERSION; 13347c478bd9Sstevel@tonic-gate sctp->sctp_family = AF_INET6; 13357c478bd9Sstevel@tonic-gate break; 13367c478bd9Sstevel@tonic-gate 13377c478bd9Sstevel@tonic-gate case AF_INET: 13387c478bd9Sstevel@tonic-gate sctp_connp->conn_af_isv6 = B_FALSE; 13397c478bd9Sstevel@tonic-gate sctp_connp->conn_pkt_isv6 = B_FALSE; 13407c478bd9Sstevel@tonic-gate sctp->sctp_ipversion = IPV4_VERSION; 13417c478bd9Sstevel@tonic-gate sctp->sctp_family = AF_INET; 13427c478bd9Sstevel@tonic-gate break; 13437c478bd9Sstevel@tonic-gate default: 13447c478bd9Sstevel@tonic-gate ASSERT(0); 13457c478bd9Sstevel@tonic-gate break; 13467c478bd9Sstevel@tonic-gate } 13477c478bd9Sstevel@tonic-gate if (sctp_init_values(sctp, psctp, sleep) != 0) { 13487c478bd9Sstevel@tonic-gate freeb(ack_mp); 13497c478bd9Sstevel@tonic-gate freeb(hb_mp); 13507c478bd9Sstevel@tonic-gate kmem_cache_free(sctp_conn_cache, sctp_connp); 13517c478bd9Sstevel@tonic-gate return (NULL); 13527c478bd9Sstevel@tonic-gate } 13537c478bd9Sstevel@tonic-gate sctp->sctp_cansleep = ((flags & SCTP_CAN_BLOCK) == SCTP_CAN_BLOCK); 13547c478bd9Sstevel@tonic-gate 13557c478bd9Sstevel@tonic-gate sctp->sctp_mss = sctp_initial_mtu - ((family == AF_INET6) ? 13567c478bd9Sstevel@tonic-gate sctp->sctp_hdr6_len : sctp->sctp_hdr_len); 13577c478bd9Sstevel@tonic-gate 13587c478bd9Sstevel@tonic-gate if (psctp != NULL) { 13597c478bd9Sstevel@tonic-gate RUN_SCTP(psctp); 13607c478bd9Sstevel@tonic-gate /* 13617c478bd9Sstevel@tonic-gate * Inherit local address list, local port. Parent is either 13627c478bd9Sstevel@tonic-gate * in SCTPS_BOUND, or SCTPS_LISTEN state. 13637c478bd9Sstevel@tonic-gate */ 13647c478bd9Sstevel@tonic-gate ASSERT((psctp->sctp_state == SCTPS_BOUND) || 13657c478bd9Sstevel@tonic-gate (psctp->sctp_state == SCTPS_LISTEN)); 13667c478bd9Sstevel@tonic-gate if (sctp_dup_saddrs(psctp, sctp, sleep)) { 13677c478bd9Sstevel@tonic-gate WAKE_SCTP(psctp); 13687c478bd9Sstevel@tonic-gate freeb(ack_mp); 13697c478bd9Sstevel@tonic-gate freeb(hb_mp); 13707c478bd9Sstevel@tonic-gate sctp_headers_free(sctp); 13717c478bd9Sstevel@tonic-gate kmem_cache_free(sctp_conn_cache, sctp_connp); 13727c478bd9Sstevel@tonic-gate return (NULL); 13737c478bd9Sstevel@tonic-gate } 13747c478bd9Sstevel@tonic-gate 13757c478bd9Sstevel@tonic-gate /* 13767c478bd9Sstevel@tonic-gate * If the parent is specified, it'll be immediatelly 13777c478bd9Sstevel@tonic-gate * followed by sctp_connect(). So don't add this guy to 13787c478bd9Sstevel@tonic-gate * bind hash. 13797c478bd9Sstevel@tonic-gate */ 13807c478bd9Sstevel@tonic-gate sctp->sctp_lport = psctp->sctp_lport; 13817c478bd9Sstevel@tonic-gate sctp->sctp_state = SCTPS_BOUND; 1382*5d0bc3edSsommerfe sctp->sctp_allzones = psctp->sctp_allzones; 13837c478bd9Sstevel@tonic-gate sctp->sctp_zoneid = psctp->sctp_zoneid; 13847c478bd9Sstevel@tonic-gate WAKE_SCTP(psctp); 13857c478bd9Sstevel@tonic-gate } else { 13867c478bd9Sstevel@tonic-gate sctp->sctp_zoneid = getzoneid(); 13877c478bd9Sstevel@tonic-gate } 13887c478bd9Sstevel@tonic-gate 13897c478bd9Sstevel@tonic-gate sctp_connp->conn_cred = credp; 13907c478bd9Sstevel@tonic-gate crhold(credp); 13917c478bd9Sstevel@tonic-gate 139245916cd2Sjpk /* 139345916cd2Sjpk * If the caller has the process-wide flag set, then default to MAC 139445916cd2Sjpk * exempt mode. This allows read-down to unlabeled hosts. 139545916cd2Sjpk */ 139645916cd2Sjpk if (getpflags(NET_MAC_AWARE, credp) != 0) 139745916cd2Sjpk sctp_connp->conn_mac_exempt = B_TRUE; 139845916cd2Sjpk 13997c478bd9Sstevel@tonic-gate /* Initialize SCTP instance values, our verf tag must never be 0 */ 14007c478bd9Sstevel@tonic-gate (void) random_get_pseudo_bytes((uint8_t *)&sctp->sctp_lvtag, 14017c478bd9Sstevel@tonic-gate sizeof (sctp->sctp_lvtag)); 14027c478bd9Sstevel@tonic-gate if (sctp->sctp_lvtag == 0) 14037c478bd9Sstevel@tonic-gate sctp->sctp_lvtag = (uint32_t)gethrtime(); 14047c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_lvtag != 0); 14057c478bd9Sstevel@tonic-gate 14067c478bd9Sstevel@tonic-gate sctp->sctp_ltsn = sctp->sctp_lvtag + 1; 14077c478bd9Sstevel@tonic-gate sctp->sctp_lcsn = sctp->sctp_ltsn; 14087c478bd9Sstevel@tonic-gate sctp->sctp_recovery_tsn = sctp->sctp_lastack_rxd = sctp->sctp_ltsn - 1; 14097c478bd9Sstevel@tonic-gate sctp->sctp_adv_pap = sctp->sctp_lastack_rxd; 14107c478bd9Sstevel@tonic-gate 14117c478bd9Sstevel@tonic-gate /* Information required by upper layer */ 14127c478bd9Sstevel@tonic-gate if (sctp_ulpd != NULL) { 14137c478bd9Sstevel@tonic-gate sctp->sctp_ulpd = sctp_ulpd; 14147c478bd9Sstevel@tonic-gate 14157c478bd9Sstevel@tonic-gate ASSERT(sctp_upcalls != NULL); 14167c478bd9Sstevel@tonic-gate bcopy(sctp_upcalls, &sctp->sctp_upcalls, 14177c478bd9Sstevel@tonic-gate sizeof (sctp_upcalls_t)); 14187c478bd9Sstevel@tonic-gate ASSERT(sbl != NULL); 14197c478bd9Sstevel@tonic-gate /* Fill in the socket buffer limits for sctpsockfs */ 14207c478bd9Sstevel@tonic-gate sbl->sbl_txlowat = sctp->sctp_xmit_lowater; 14217c478bd9Sstevel@tonic-gate sbl->sbl_txbuf = sctp->sctp_xmit_hiwater; 14227c478bd9Sstevel@tonic-gate sbl->sbl_rxbuf = sctp->sctp_rwnd; 14237c478bd9Sstevel@tonic-gate sbl->sbl_rxlowat = SCTP_RECV_LOWATER; 14247c478bd9Sstevel@tonic-gate } 14257c478bd9Sstevel@tonic-gate /* If no sctp_ulpd, must be creating the default sctp */ 14267c478bd9Sstevel@tonic-gate ASSERT(sctp_ulpd != NULL || gsctp == NULL); 14277c478bd9Sstevel@tonic-gate 14287c478bd9Sstevel@tonic-gate /* Insert this in the global list. */ 14297c478bd9Sstevel@tonic-gate SCTP_LINK(sctp); 14307c478bd9Sstevel@tonic-gate 14317c478bd9Sstevel@tonic-gate return (sctp); 14327c478bd9Sstevel@tonic-gate } 14337c478bd9Sstevel@tonic-gate 14347c478bd9Sstevel@tonic-gate void 14357c478bd9Sstevel@tonic-gate sctp_ddi_init(void) 14367c478bd9Sstevel@tonic-gate { 14377c478bd9Sstevel@tonic-gate /* Initialize locks */ 14387c478bd9Sstevel@tonic-gate mutex_init(&sctp_g_lock, NULL, MUTEX_DEFAULT, NULL); 14397c478bd9Sstevel@tonic-gate mutex_init(&sctp_epriv_port_lock, NULL, MUTEX_DEFAULT, NULL); 14407c478bd9Sstevel@tonic-gate 14417c478bd9Sstevel@tonic-gate /* Initialize SCTP hash arrays. */ 14427c478bd9Sstevel@tonic-gate sctp_hash_init(); 14437c478bd9Sstevel@tonic-gate 14447c478bd9Sstevel@tonic-gate sctp_pad_mp = allocb(SCTP_ALIGN, BPRI_MED); 14457c478bd9Sstevel@tonic-gate bzero(sctp_pad_mp->b_rptr, SCTP_ALIGN); 14467c478bd9Sstevel@tonic-gate ASSERT(sctp_pad_mp); 14477c478bd9Sstevel@tonic-gate 14487c478bd9Sstevel@tonic-gate if (!sctp_nd_init()) { 14497c478bd9Sstevel@tonic-gate sctp_nd_free(); 14507c478bd9Sstevel@tonic-gate } 14517c478bd9Sstevel@tonic-gate 14527c478bd9Sstevel@tonic-gate /* Create sctp_t/conn_t cache */ 14537c478bd9Sstevel@tonic-gate sctp_conn_cache_init(); 14547c478bd9Sstevel@tonic-gate 14557c478bd9Sstevel@tonic-gate /* Create the faddr cache */ 14567c478bd9Sstevel@tonic-gate sctp_faddr_init(); 14577c478bd9Sstevel@tonic-gate 14587c478bd9Sstevel@tonic-gate /* Create the sets cache */ 14597c478bd9Sstevel@tonic-gate sctp_sets_init(); 14607c478bd9Sstevel@tonic-gate 14617c478bd9Sstevel@tonic-gate /* Create the PR-SCTP sets cache */ 14627c478bd9Sstevel@tonic-gate sctp_ftsn_sets_init(); 14637c478bd9Sstevel@tonic-gate 14647c478bd9Sstevel@tonic-gate /* Initialize the recvq taskq. */ 14657c478bd9Sstevel@tonic-gate sctp_rq_tq_init(); 14667c478bd9Sstevel@tonic-gate 14677c478bd9Sstevel@tonic-gate /* saddr init */ 14687c478bd9Sstevel@tonic-gate sctp_saddr_init(); 14697c478bd9Sstevel@tonic-gate 14707c478bd9Sstevel@tonic-gate /* Global SCTP PCB list. */ 14717c478bd9Sstevel@tonic-gate list_create(&sctp_g_list, sizeof (sctp_t), 14727c478bd9Sstevel@tonic-gate offsetof(sctp_t, sctp_list)); 14737c478bd9Sstevel@tonic-gate 14747c478bd9Sstevel@tonic-gate /* Initialize tables used for CRC calculation */ 14757c478bd9Sstevel@tonic-gate sctp_crc32_init(); 14767c478bd9Sstevel@tonic-gate 14777c478bd9Sstevel@tonic-gate /* Initialize sctp kernel stats. */ 14787c478bd9Sstevel@tonic-gate sctp_kstat_init(); 14797c478bd9Sstevel@tonic-gate } 14807c478bd9Sstevel@tonic-gate 14817c478bd9Sstevel@tonic-gate void 14827c478bd9Sstevel@tonic-gate sctp_ddi_destroy(void) 14837c478bd9Sstevel@tonic-gate { 14847c478bd9Sstevel@tonic-gate sctp_nd_free(); 14857c478bd9Sstevel@tonic-gate 14867c478bd9Sstevel@tonic-gate /* Destroy sctp_t/conn_t caches */ 14877c478bd9Sstevel@tonic-gate sctp_conn_cache_fini(); 14887c478bd9Sstevel@tonic-gate 14897c478bd9Sstevel@tonic-gate /* Destroy the faddr cache */ 14907c478bd9Sstevel@tonic-gate sctp_faddr_fini(); 14917c478bd9Sstevel@tonic-gate 14927c478bd9Sstevel@tonic-gate /* Destroy the sets cache */ 14937c478bd9Sstevel@tonic-gate sctp_sets_fini(); 14947c478bd9Sstevel@tonic-gate 14957c478bd9Sstevel@tonic-gate /* Destroy the PR-SCTP sets cache */ 14967c478bd9Sstevel@tonic-gate sctp_ftsn_sets_fini(); 14977c478bd9Sstevel@tonic-gate 14987c478bd9Sstevel@tonic-gate /* Destroy the recvq taskqs. */ 14997c478bd9Sstevel@tonic-gate sctp_rq_tq_fini(); 15007c478bd9Sstevel@tonic-gate 15017c478bd9Sstevel@tonic-gate /* Destroy saddr */ 15027c478bd9Sstevel@tonic-gate sctp_saddr_fini(); 15037c478bd9Sstevel@tonic-gate 15047c478bd9Sstevel@tonic-gate /* Global SCTP PCB list. */ 15057c478bd9Sstevel@tonic-gate list_destroy(&sctp_g_list); 15067c478bd9Sstevel@tonic-gate 15077c478bd9Sstevel@tonic-gate /* Destroy SCTP hash arrays. */ 15087c478bd9Sstevel@tonic-gate sctp_hash_destroy(); 15097c478bd9Sstevel@tonic-gate 15107c478bd9Sstevel@tonic-gate /* Destroy SCTP kenrel stats. */ 15117c478bd9Sstevel@tonic-gate sctp_kstat_fini(); 15127c478bd9Sstevel@tonic-gate 15137c478bd9Sstevel@tonic-gate mutex_destroy(&sctp_g_lock); 15147c478bd9Sstevel@tonic-gate mutex_destroy(&sctp_epriv_port_lock); 15157c478bd9Sstevel@tonic-gate } 15167c478bd9Sstevel@tonic-gate 15177c478bd9Sstevel@tonic-gate void 15187c478bd9Sstevel@tonic-gate sctp_display_all() 15197c478bd9Sstevel@tonic-gate { 15207c478bd9Sstevel@tonic-gate sctp_t *sctp_walker; 15217c478bd9Sstevel@tonic-gate 15227c478bd9Sstevel@tonic-gate mutex_enter(&sctp_g_lock); 15237c478bd9Sstevel@tonic-gate for (sctp_walker = gsctp; sctp_walker != NULL; 15247c478bd9Sstevel@tonic-gate sctp_walker = (sctp_t *)list_next(&sctp_g_list, sctp_walker)) { 15257c478bd9Sstevel@tonic-gate (void) sctp_display(sctp_walker, NULL); 15267c478bd9Sstevel@tonic-gate } 15277c478bd9Sstevel@tonic-gate mutex_exit(&sctp_g_lock); 15287c478bd9Sstevel@tonic-gate } 15297c478bd9Sstevel@tonic-gate 15307c478bd9Sstevel@tonic-gate static void 15317c478bd9Sstevel@tonic-gate sctp_rq_tq_init(void) 15327c478bd9Sstevel@tonic-gate { 15337c478bd9Sstevel@tonic-gate /* 15347c478bd9Sstevel@tonic-gate * Initialize the recvq_tq_list and create the first recvq taskq. 15357c478bd9Sstevel@tonic-gate * What to do if it fails? 15367c478bd9Sstevel@tonic-gate */ 15377c478bd9Sstevel@tonic-gate recvq_tq_list = kmem_zalloc(sctp_recvq_tq_list_max_sz * 15387c478bd9Sstevel@tonic-gate sizeof (taskq_t *), KM_SLEEP); 15397c478bd9Sstevel@tonic-gate recvq_tq_list[0] = taskq_create("sctp_def_recvq_taskq", 15407c478bd9Sstevel@tonic-gate MIN(sctp_recvq_tq_thr_max, MAX(sctp_recvq_tq_thr_min, ncpus)), 15417c478bd9Sstevel@tonic-gate minclsyspri, sctp_recvq_tq_task_min, sctp_recvq_tq_task_max, 15427c478bd9Sstevel@tonic-gate TASKQ_PREPOPULATE); 15437c478bd9Sstevel@tonic-gate mutex_init(&sctp_rq_tq_lock, NULL, MUTEX_DEFAULT, NULL); 15447c478bd9Sstevel@tonic-gate } 15457c478bd9Sstevel@tonic-gate 15467c478bd9Sstevel@tonic-gate static void 15477c478bd9Sstevel@tonic-gate sctp_rq_tq_fini(void) 15487c478bd9Sstevel@tonic-gate { 15497c478bd9Sstevel@tonic-gate int i; 15507c478bd9Sstevel@tonic-gate 15517c478bd9Sstevel@tonic-gate for (i = 0; i < recvq_tq_list_cur_sz; i++) { 15527c478bd9Sstevel@tonic-gate ASSERT(recvq_tq_list[i] != NULL); 15537c478bd9Sstevel@tonic-gate taskq_destroy(recvq_tq_list[i]); 15547c478bd9Sstevel@tonic-gate } 15557c478bd9Sstevel@tonic-gate kmem_free(recvq_tq_list, sctp_recvq_tq_list_max_sz * 15567c478bd9Sstevel@tonic-gate sizeof (taskq_t *)); 15577c478bd9Sstevel@tonic-gate } 15587c478bd9Sstevel@tonic-gate 15597c478bd9Sstevel@tonic-gate /* Add another taskq for a new ill. */ 15607c478bd9Sstevel@tonic-gate void 15617c478bd9Sstevel@tonic-gate sctp_inc_taskq(void) 15627c478bd9Sstevel@tonic-gate { 15637c478bd9Sstevel@tonic-gate taskq_t *tq; 15647c478bd9Sstevel@tonic-gate char tq_name[TASKQ_NAMELEN]; 15657c478bd9Sstevel@tonic-gate 15667c478bd9Sstevel@tonic-gate mutex_enter(&sctp_rq_tq_lock); 15677c478bd9Sstevel@tonic-gate if (recvq_tq_list_cur_sz + 1 > sctp_recvq_tq_list_max_sz) { 15687c478bd9Sstevel@tonic-gate mutex_exit(&sctp_rq_tq_lock); 15697c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "Cannot create more SCTP recvq taskq"); 15707c478bd9Sstevel@tonic-gate return; 15717c478bd9Sstevel@tonic-gate } 15727c478bd9Sstevel@tonic-gate 15737c478bd9Sstevel@tonic-gate (void) snprintf(tq_name, sizeof (tq_name), "sctp_recvq_taskq_%u", 15747c478bd9Sstevel@tonic-gate recvq_tq_list_cur_sz); 15757c478bd9Sstevel@tonic-gate tq = taskq_create(tq_name, 15767c478bd9Sstevel@tonic-gate MIN(sctp_recvq_tq_thr_max, MAX(sctp_recvq_tq_thr_min, ncpus)), 15777c478bd9Sstevel@tonic-gate minclsyspri, sctp_recvq_tq_task_min, sctp_recvq_tq_task_max, 15787c478bd9Sstevel@tonic-gate TASKQ_PREPOPULATE); 15797c478bd9Sstevel@tonic-gate if (tq == NULL) { 15807c478bd9Sstevel@tonic-gate mutex_exit(&sctp_rq_tq_lock); 15817c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "SCTP recvq taskq creation failed"); 15827c478bd9Sstevel@tonic-gate return; 15837c478bd9Sstevel@tonic-gate } 15847c478bd9Sstevel@tonic-gate ASSERT(recvq_tq_list[recvq_tq_list_cur_sz] == NULL); 15857c478bd9Sstevel@tonic-gate recvq_tq_list[recvq_tq_list_cur_sz] = tq; 15867c478bd9Sstevel@tonic-gate atomic_add_32(&recvq_tq_list_cur_sz, 1); 15877c478bd9Sstevel@tonic-gate mutex_exit(&sctp_rq_tq_lock); 15887c478bd9Sstevel@tonic-gate } 15897c478bd9Sstevel@tonic-gate 15907c478bd9Sstevel@tonic-gate #ifdef DEBUG 15917c478bd9Sstevel@tonic-gate uint32_t sendq_loop_cnt = 0; 15927c478bd9Sstevel@tonic-gate uint32_t sendq_collision = 0; 15937c478bd9Sstevel@tonic-gate uint32_t sendq_empty = 0; 15947c478bd9Sstevel@tonic-gate #endif 15957c478bd9Sstevel@tonic-gate 15967c478bd9Sstevel@tonic-gate void 15977c478bd9Sstevel@tonic-gate sctp_add_sendq(sctp_t *sctp, mblk_t *mp) 15987c478bd9Sstevel@tonic-gate { 15997c478bd9Sstevel@tonic-gate mutex_enter(&sctp->sctp_sendq_lock); 16007c478bd9Sstevel@tonic-gate if (sctp->sctp_sendq == NULL) { 16017c478bd9Sstevel@tonic-gate sctp->sctp_sendq = mp; 16027c478bd9Sstevel@tonic-gate sctp->sctp_sendq_tail = mp; 16037c478bd9Sstevel@tonic-gate } else { 16047c478bd9Sstevel@tonic-gate sctp->sctp_sendq_tail->b_next = mp; 16057c478bd9Sstevel@tonic-gate sctp->sctp_sendq_tail = mp; 16067c478bd9Sstevel@tonic-gate } 16077c478bd9Sstevel@tonic-gate mutex_exit(&sctp->sctp_sendq_lock); 16087c478bd9Sstevel@tonic-gate } 16097c478bd9Sstevel@tonic-gate 16107c478bd9Sstevel@tonic-gate void 16117c478bd9Sstevel@tonic-gate sctp_process_sendq(sctp_t *sctp) 16127c478bd9Sstevel@tonic-gate { 16137c478bd9Sstevel@tonic-gate mblk_t *mp; 16147c478bd9Sstevel@tonic-gate #ifdef DEBUG 16157c478bd9Sstevel@tonic-gate uint32_t loop_cnt = 0; 16167c478bd9Sstevel@tonic-gate #endif 16177c478bd9Sstevel@tonic-gate 16187c478bd9Sstevel@tonic-gate mutex_enter(&sctp->sctp_sendq_lock); 16197c478bd9Sstevel@tonic-gate if (sctp->sctp_sendq == NULL || sctp->sctp_sendq_sending) { 16207c478bd9Sstevel@tonic-gate #ifdef DEBUG 16217c478bd9Sstevel@tonic-gate if (sctp->sctp_sendq == NULL) 16227c478bd9Sstevel@tonic-gate sendq_empty++; 16237c478bd9Sstevel@tonic-gate else 16247c478bd9Sstevel@tonic-gate sendq_collision++; 16257c478bd9Sstevel@tonic-gate #endif 16267c478bd9Sstevel@tonic-gate mutex_exit(&sctp->sctp_sendq_lock); 16277c478bd9Sstevel@tonic-gate return; 16287c478bd9Sstevel@tonic-gate } 16297c478bd9Sstevel@tonic-gate sctp->sctp_sendq_sending = B_TRUE; 16307c478bd9Sstevel@tonic-gate 16317c478bd9Sstevel@tonic-gate /* 16327c478bd9Sstevel@tonic-gate * Note that while we are in this loop, other thread can put 16337c478bd9Sstevel@tonic-gate * new packets in the receive queue. We may be looping for 16347c478bd9Sstevel@tonic-gate * quite a while. This is OK even for an interrupt thread. 16357c478bd9Sstevel@tonic-gate * The reason is that SCTP should only able to send a limited 16367c478bd9Sstevel@tonic-gate * number of packets out in a burst. So the number of times 16377c478bd9Sstevel@tonic-gate * we go through this loop should not be many. 16387c478bd9Sstevel@tonic-gate */ 16397c478bd9Sstevel@tonic-gate while ((mp = sctp->sctp_sendq) != NULL) { 16407c478bd9Sstevel@tonic-gate sctp->sctp_sendq = mp->b_next; 16417c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_connp->conn_ref > 0); 16427c478bd9Sstevel@tonic-gate mutex_exit(&sctp->sctp_sendq_lock); 16437c478bd9Sstevel@tonic-gate mp->b_next = NULL; 16447c478bd9Sstevel@tonic-gate CONN_INC_REF(sctp->sctp_connp); 16457c478bd9Sstevel@tonic-gate mp->b_flag |= MSGHASREF; 16467c478bd9Sstevel@tonic-gate /* If we don't have sctp_current, default to IPv4 */ 16477c478bd9Sstevel@tonic-gate IP_PUT(mp, sctp->sctp_connp, sctp->sctp_current == NULL ? 16487c478bd9Sstevel@tonic-gate B_TRUE : sctp->sctp_current->isv4); 16497c478bd9Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_opkts); 16507c478bd9Sstevel@tonic-gate #ifdef DEBUG 16517c478bd9Sstevel@tonic-gate loop_cnt++; 16527c478bd9Sstevel@tonic-gate #endif 16537c478bd9Sstevel@tonic-gate mutex_enter(&sctp->sctp_sendq_lock); 16547c478bd9Sstevel@tonic-gate } 16557c478bd9Sstevel@tonic-gate 16567c478bd9Sstevel@tonic-gate sctp->sctp_sendq_tail = NULL; 16577c478bd9Sstevel@tonic-gate sctp->sctp_sendq_sending = B_FALSE; 16587c478bd9Sstevel@tonic-gate #ifdef DEBUG 16597c478bd9Sstevel@tonic-gate if (loop_cnt > sendq_loop_cnt) 16607c478bd9Sstevel@tonic-gate sendq_loop_cnt = loop_cnt; 16617c478bd9Sstevel@tonic-gate #endif 16627c478bd9Sstevel@tonic-gate mutex_exit(&sctp->sctp_sendq_lock); 16637c478bd9Sstevel@tonic-gate } 16647c478bd9Sstevel@tonic-gate 16657c478bd9Sstevel@tonic-gate #ifdef DEBUG 16667c478bd9Sstevel@tonic-gate uint32_t recvq_loop_cnt = 0; 16677c478bd9Sstevel@tonic-gate uint32_t recvq_call = 0; 16687c478bd9Sstevel@tonic-gate #endif 16697c478bd9Sstevel@tonic-gate 16707c478bd9Sstevel@tonic-gate /* 16717c478bd9Sstevel@tonic-gate * Find the next recvq_tq to use. This routine will go thru all the 16727c478bd9Sstevel@tonic-gate * taskqs until it can dispatch a job for the sctp. If this fails, 16737c478bd9Sstevel@tonic-gate * it will create a new taskq and try it. 16747c478bd9Sstevel@tonic-gate */ 16757c478bd9Sstevel@tonic-gate static boolean_t 16767c478bd9Sstevel@tonic-gate sctp_find_next_tq(sctp_t *sctp) 16777c478bd9Sstevel@tonic-gate { 16787c478bd9Sstevel@tonic-gate int next_tq, try; 16797c478bd9Sstevel@tonic-gate taskq_t *tq; 16807c478bd9Sstevel@tonic-gate 16817c478bd9Sstevel@tonic-gate /* 16827c478bd9Sstevel@tonic-gate * Note that since we don't hold a lock on sctp_rq_tq_lock for 16837c478bd9Sstevel@tonic-gate * performance reason, recvq_ta_list_cur_sz can be changed during 16847c478bd9Sstevel@tonic-gate * this loop. The problem this will create is that the loop may 16857c478bd9Sstevel@tonic-gate * not have tried all the recvq_tq. This should be OK. 16867c478bd9Sstevel@tonic-gate */ 16877c478bd9Sstevel@tonic-gate next_tq = atomic_add_32_nv(&recvq_tq_list_cur, 1) % 16887c478bd9Sstevel@tonic-gate recvq_tq_list_cur_sz; 16897c478bd9Sstevel@tonic-gate for (try = 0; try < recvq_tq_list_cur_sz; 16907c478bd9Sstevel@tonic-gate try++, next_tq = (next_tq + 1) % recvq_tq_list_cur_sz) { 16917c478bd9Sstevel@tonic-gate tq = recvq_tq_list[next_tq]; 16927c478bd9Sstevel@tonic-gate if (taskq_dispatch(tq, sctp_process_recvq, sctp, 16937c478bd9Sstevel@tonic-gate TQ_NOSLEEP) != NULL) { 16947c478bd9Sstevel@tonic-gate sctp->sctp_recvq_tq = tq; 16957c478bd9Sstevel@tonic-gate return (B_TRUE); 16967c478bd9Sstevel@tonic-gate } 16977c478bd9Sstevel@tonic-gate } 16987c478bd9Sstevel@tonic-gate 16997c478bd9Sstevel@tonic-gate /* 17007c478bd9Sstevel@tonic-gate * Create one more taskq and try it. Note that sctp_inc_taskq() 17017c478bd9Sstevel@tonic-gate * may not have created another taskq if the number of recvq 17027c478bd9Sstevel@tonic-gate * taskqs is at the maximum. We are probably in a pretty bad 17037c478bd9Sstevel@tonic-gate * shape if this actually happens... 17047c478bd9Sstevel@tonic-gate */ 17057c478bd9Sstevel@tonic-gate sctp_inc_taskq(); 17067c478bd9Sstevel@tonic-gate tq = recvq_tq_list[recvq_tq_list_cur_sz - 1]; 17077c478bd9Sstevel@tonic-gate if (taskq_dispatch(tq, sctp_process_recvq, sctp, TQ_NOSLEEP) != NULL) { 17087c478bd9Sstevel@tonic-gate sctp->sctp_recvq_tq = tq; 17097c478bd9Sstevel@tonic-gate return (B_TRUE); 17107c478bd9Sstevel@tonic-gate } 171177c67f2fSkcpoon SCTP_KSTAT(sctp_find_next_tq); 17127c478bd9Sstevel@tonic-gate return (B_FALSE); 17137c478bd9Sstevel@tonic-gate } 17147c478bd9Sstevel@tonic-gate 17157c478bd9Sstevel@tonic-gate /* 17167c478bd9Sstevel@tonic-gate * To add a message to the recvq. Note that the sctp_timer_fire() 17177c478bd9Sstevel@tonic-gate * routine also uses this function to add the timer message to the 17187c478bd9Sstevel@tonic-gate * receive queue for later processing. And it should be the only 17197c478bd9Sstevel@tonic-gate * caller of sctp_add_recvq() which sets the try_harder argument 17207c478bd9Sstevel@tonic-gate * to B_TRUE. 17217c478bd9Sstevel@tonic-gate * 17227c478bd9Sstevel@tonic-gate * If the try_harder argument is B_TRUE, this routine sctp_find_next_tq() 17237c478bd9Sstevel@tonic-gate * will try very hard to dispatch the task. Refer to the comment 17247c478bd9Sstevel@tonic-gate * for that routine on how it does that. 17257c478bd9Sstevel@tonic-gate */ 17267c478bd9Sstevel@tonic-gate boolean_t 17277c478bd9Sstevel@tonic-gate sctp_add_recvq(sctp_t *sctp, mblk_t *mp, boolean_t caller_hold_lock) 17287c478bd9Sstevel@tonic-gate { 17297c478bd9Sstevel@tonic-gate if (!caller_hold_lock) 17307c478bd9Sstevel@tonic-gate mutex_enter(&sctp->sctp_recvq_lock); 17317c478bd9Sstevel@tonic-gate 17327c478bd9Sstevel@tonic-gate /* If the taskq dispatch has not been scheduled, do it now. */ 17337c478bd9Sstevel@tonic-gate if (sctp->sctp_recvq_tq == NULL) { 17347c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_recvq == NULL); 17357c478bd9Sstevel@tonic-gate if (!sctp_find_next_tq(sctp)) { 17367c478bd9Sstevel@tonic-gate if (!caller_hold_lock) 17377c478bd9Sstevel@tonic-gate mutex_exit(&sctp->sctp_recvq_lock); 17387c478bd9Sstevel@tonic-gate return (B_FALSE); 17397c478bd9Sstevel@tonic-gate } 17407c478bd9Sstevel@tonic-gate /* Make sure the sctp_t will not go away. */ 17417c478bd9Sstevel@tonic-gate SCTP_REFHOLD(sctp); 17427c478bd9Sstevel@tonic-gate } 17437c478bd9Sstevel@tonic-gate 17447c478bd9Sstevel@tonic-gate if (sctp->sctp_recvq == NULL) { 17457c478bd9Sstevel@tonic-gate sctp->sctp_recvq = mp; 17467c478bd9Sstevel@tonic-gate sctp->sctp_recvq_tail = mp; 17477c478bd9Sstevel@tonic-gate } else { 17487c478bd9Sstevel@tonic-gate sctp->sctp_recvq_tail->b_next = mp; 17497c478bd9Sstevel@tonic-gate sctp->sctp_recvq_tail = mp; 17507c478bd9Sstevel@tonic-gate } 17517c478bd9Sstevel@tonic-gate 17527c478bd9Sstevel@tonic-gate if (!caller_hold_lock) 17537c478bd9Sstevel@tonic-gate mutex_exit(&sctp->sctp_recvq_lock); 17547c478bd9Sstevel@tonic-gate return (B_TRUE); 17557c478bd9Sstevel@tonic-gate } 17567c478bd9Sstevel@tonic-gate 17577c478bd9Sstevel@tonic-gate static void 17587c478bd9Sstevel@tonic-gate sctp_process_recvq(void *arg) 17597c478bd9Sstevel@tonic-gate { 17607c478bd9Sstevel@tonic-gate sctp_t *sctp = (sctp_t *)arg; 17617c478bd9Sstevel@tonic-gate mblk_t *mp; 17627c478bd9Sstevel@tonic-gate mblk_t *ipsec_mp; 17637c478bd9Sstevel@tonic-gate #ifdef DEBUG 17647c478bd9Sstevel@tonic-gate uint32_t loop_cnt = 0; 17657c478bd9Sstevel@tonic-gate #endif 17667c478bd9Sstevel@tonic-gate 17677c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN 17687c478bd9Sstevel@tonic-gate #define IPVER(ip6h) ((((uint32_t *)ip6h)[0] >> 28) & 0x7) 17697c478bd9Sstevel@tonic-gate #else 17707c478bd9Sstevel@tonic-gate #define IPVER(ip6h) ((((uint32_t *)ip6h)[0] >> 4) & 0x7) 17717c478bd9Sstevel@tonic-gate #endif 17727c478bd9Sstevel@tonic-gate 17737c478bd9Sstevel@tonic-gate RUN_SCTP(sctp); 17747c478bd9Sstevel@tonic-gate mutex_enter(&sctp->sctp_recvq_lock); 17757c478bd9Sstevel@tonic-gate 17767c478bd9Sstevel@tonic-gate #ifdef DEBUG 17777c478bd9Sstevel@tonic-gate recvq_call++; 17787c478bd9Sstevel@tonic-gate #endif 17797c478bd9Sstevel@tonic-gate /* 17807c478bd9Sstevel@tonic-gate * Note that while we are in this loop, other thread can put 17817c478bd9Sstevel@tonic-gate * new packets in the receive queue. We may be looping for 17827c478bd9Sstevel@tonic-gate * quite a while. 17837c478bd9Sstevel@tonic-gate */ 17847c478bd9Sstevel@tonic-gate while ((mp = sctp->sctp_recvq) != NULL) { 17857c478bd9Sstevel@tonic-gate sctp->sctp_recvq = mp->b_next; 17867c478bd9Sstevel@tonic-gate mutex_exit(&sctp->sctp_recvq_lock); 17877c478bd9Sstevel@tonic-gate mp->b_next = NULL; 17887c478bd9Sstevel@tonic-gate #ifdef DEBUG 17897c478bd9Sstevel@tonic-gate loop_cnt++; 17907c478bd9Sstevel@tonic-gate #endif 17917c478bd9Sstevel@tonic-gate ipsec_mp = mp->b_prev; 17927c478bd9Sstevel@tonic-gate mp->b_prev = NULL; 17937c478bd9Sstevel@tonic-gate sctp_input_data(sctp, mp, ipsec_mp); 17947c478bd9Sstevel@tonic-gate 17957c478bd9Sstevel@tonic-gate mutex_enter(&sctp->sctp_recvq_lock); 17967c478bd9Sstevel@tonic-gate } 17977c478bd9Sstevel@tonic-gate 17987c478bd9Sstevel@tonic-gate sctp->sctp_recvq_tail = NULL; 17997c478bd9Sstevel@tonic-gate sctp->sctp_recvq_tq = NULL; 18007c478bd9Sstevel@tonic-gate 18017c478bd9Sstevel@tonic-gate mutex_exit(&sctp->sctp_recvq_lock); 18027c478bd9Sstevel@tonic-gate 18037c478bd9Sstevel@tonic-gate WAKE_SCTP(sctp); 18047c478bd9Sstevel@tonic-gate 18057c478bd9Sstevel@tonic-gate /* We may have sent something when processing the receive queue. */ 18067c478bd9Sstevel@tonic-gate sctp_process_sendq(sctp); 18077c478bd9Sstevel@tonic-gate #ifdef DEBUG 18087c478bd9Sstevel@tonic-gate if (loop_cnt > recvq_loop_cnt) 18097c478bd9Sstevel@tonic-gate recvq_loop_cnt = loop_cnt; 18107c478bd9Sstevel@tonic-gate #endif 18117c478bd9Sstevel@tonic-gate /* Now it can go away. */ 18127c478bd9Sstevel@tonic-gate SCTP_REFRELE(sctp); 18137c478bd9Sstevel@tonic-gate } 18147c478bd9Sstevel@tonic-gate 18157c478bd9Sstevel@tonic-gate /* ARGSUSED */ 18167c478bd9Sstevel@tonic-gate static int 18177c478bd9Sstevel@tonic-gate sctp_conn_cache_constructor(void *buf, void *cdrarg, int kmflags) 18187c478bd9Sstevel@tonic-gate { 18197c478bd9Sstevel@tonic-gate conn_t *sctp_connp = (conn_t *)buf; 18207c478bd9Sstevel@tonic-gate sctp_t *sctp = (sctp_t *)&sctp_connp[1]; 18217c478bd9Sstevel@tonic-gate 18227c478bd9Sstevel@tonic-gate bzero(buf, (char *)&sctp[1] - (char *)buf); 18237c478bd9Sstevel@tonic-gate 18247c478bd9Sstevel@tonic-gate ASSERT(sctp_g_q != NULL); 18257c478bd9Sstevel@tonic-gate sctp->sctp_connp = sctp_connp; 18267c478bd9Sstevel@tonic-gate mutex_init(&sctp->sctp_reflock, NULL, MUTEX_DEFAULT, NULL); 18277c478bd9Sstevel@tonic-gate mutex_init(&sctp->sctp_lock, NULL, MUTEX_DEFAULT, NULL); 18287c478bd9Sstevel@tonic-gate mutex_init(&sctp->sctp_recvq_lock, NULL, MUTEX_DEFAULT, NULL); 18297c478bd9Sstevel@tonic-gate cv_init(&sctp->sctp_cv, NULL, CV_DEFAULT, NULL); 18307c478bd9Sstevel@tonic-gate mutex_init(&sctp->sctp_sendq_lock, NULL, MUTEX_DEFAULT, NULL); 18317c478bd9Sstevel@tonic-gate 18327c478bd9Sstevel@tonic-gate sctp_connp->conn_rq = sctp_connp->conn_wq = NULL; 18337c478bd9Sstevel@tonic-gate sctp_connp->conn_multicast_loop = IP_DEFAULT_MULTICAST_LOOP; 18347c478bd9Sstevel@tonic-gate sctp_connp->conn_ulp = IPPROTO_SCTP; 18357c478bd9Sstevel@tonic-gate mutex_init(&sctp_connp->conn_lock, NULL, MUTEX_DEFAULT, NULL); 18367c478bd9Sstevel@tonic-gate cv_init(&sctp_connp->conn_cv, NULL, CV_DEFAULT, NULL); 18377c478bd9Sstevel@tonic-gate 18387c478bd9Sstevel@tonic-gate return (0); 18397c478bd9Sstevel@tonic-gate } 18407c478bd9Sstevel@tonic-gate 18417c478bd9Sstevel@tonic-gate /* ARGSUSED */ 18427c478bd9Sstevel@tonic-gate static void 18437c478bd9Sstevel@tonic-gate sctp_conn_cache_destructor(void *buf, void *cdrarg) 18447c478bd9Sstevel@tonic-gate { 18457c478bd9Sstevel@tonic-gate conn_t *sctp_connp = (conn_t *)buf; 18467c478bd9Sstevel@tonic-gate sctp_t *sctp = (sctp_t *)&sctp_connp[1]; 18477c478bd9Sstevel@tonic-gate 18487c478bd9Sstevel@tonic-gate ASSERT(!MUTEX_HELD(&sctp->sctp_lock)); 18497c478bd9Sstevel@tonic-gate ASSERT(!MUTEX_HELD(&sctp->sctp_reflock)); 18507c478bd9Sstevel@tonic-gate ASSERT(!MUTEX_HELD(&sctp->sctp_recvq_lock)); 18517c478bd9Sstevel@tonic-gate ASSERT(!MUTEX_HELD(&sctp->sctp_sendq_lock)); 18527c478bd9Sstevel@tonic-gate ASSERT(!MUTEX_HELD(&sctp->sctp_connp->conn_lock)); 18537c478bd9Sstevel@tonic-gate 18547c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_conn_hash_next == NULL); 18557c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_conn_hash_prev == NULL); 18567c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_listen_hash_next == NULL); 18577c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_listen_hash_prev == NULL); 18587c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_listen_tfp == NULL); 18597c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_conn_tfp == NULL); 18607c478bd9Sstevel@tonic-gate 18617c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_faddrs == NULL); 18627c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_nsaddrs == 0); 18637c478bd9Sstevel@tonic-gate 18647c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_ulpd == NULL); 18657c478bd9Sstevel@tonic-gate 18667c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_lastfaddr == NULL); 18677c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_primary == NULL); 18687c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_current == NULL); 18697c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_lastdata == NULL); 18707c478bd9Sstevel@tonic-gate 18717c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_xmit_head == NULL); 18727c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_xmit_tail == NULL); 18737c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_xmit_unsent == NULL); 18747c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_xmit_unsent_tail == NULL); 18757c478bd9Sstevel@tonic-gate 18767c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_ostrcntrs == NULL); 18777c478bd9Sstevel@tonic-gate 18787c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_sack_info == NULL); 18797c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_ack_mp == NULL); 18807c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_instr == NULL); 18817c478bd9Sstevel@tonic-gate 18827c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_iphc == NULL); 18837c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_iphc6 == NULL); 18847c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_ipha == NULL); 18857c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_ip6h == NULL); 18867c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_sctph == NULL); 18877c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_sctph6 == NULL); 18887c478bd9Sstevel@tonic-gate 18897c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_cookie_mp == NULL); 18907c478bd9Sstevel@tonic-gate 18917c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_refcnt == 0); 18927c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_timer_mp == NULL); 18937c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_connp->conn_ref == 0); 18947c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_heartbeat_mp == NULL); 18957c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_ptpbhn == NULL && sctp->sctp_bind_hash == NULL); 18967c478bd9Sstevel@tonic-gate 18977c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_shutdown_faddr == NULL); 18987c478bd9Sstevel@tonic-gate 18997c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_cxmit_list == NULL); 19007c478bd9Sstevel@tonic-gate 19017c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_recvq == NULL); 19027c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_recvq_tail == NULL); 19037c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_recvq_tq == NULL); 19047c478bd9Sstevel@tonic-gate 19057c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_sendq == NULL); 19067c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_sendq_tail == NULL); 19077c478bd9Sstevel@tonic-gate ASSERT(sctp->sctp_sendq_sending == B_FALSE); 19087c478bd9Sstevel@tonic-gate 19097c478bd9Sstevel@tonic-gate mutex_destroy(&sctp->sctp_reflock); 19107c478bd9Sstevel@tonic-gate mutex_destroy(&sctp->sctp_lock); 19117c478bd9Sstevel@tonic-gate mutex_destroy(&sctp->sctp_recvq_lock); 19127c478bd9Sstevel@tonic-gate cv_destroy(&sctp->sctp_cv); 19137c478bd9Sstevel@tonic-gate mutex_destroy(&sctp->sctp_sendq_lock); 19147c478bd9Sstevel@tonic-gate 19157c478bd9Sstevel@tonic-gate mutex_destroy(&sctp_connp->conn_lock); 19167c478bd9Sstevel@tonic-gate cv_destroy(&sctp_connp->conn_cv); 19177c478bd9Sstevel@tonic-gate } 19187c478bd9Sstevel@tonic-gate 19197c478bd9Sstevel@tonic-gate static void 19207c478bd9Sstevel@tonic-gate sctp_conn_cache_init() 19217c478bd9Sstevel@tonic-gate { 19227c478bd9Sstevel@tonic-gate sctp_conn_cache = kmem_cache_create("sctp_conn_cache", 19237c478bd9Sstevel@tonic-gate sizeof (sctp_t) + sizeof (conn_t), 0, sctp_conn_cache_constructor, 19247c478bd9Sstevel@tonic-gate sctp_conn_cache_destructor, NULL, NULL, NULL, 0); 19257c478bd9Sstevel@tonic-gate } 19267c478bd9Sstevel@tonic-gate 19277c478bd9Sstevel@tonic-gate static void 19287c478bd9Sstevel@tonic-gate sctp_conn_cache_fini() 19297c478bd9Sstevel@tonic-gate { 19307c478bd9Sstevel@tonic-gate kmem_cache_destroy(sctp_conn_cache); 19317c478bd9Sstevel@tonic-gate } 1932