10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51213Skcpoon * Common Development and Distribution License (the "License"). 61213Skcpoon * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 211213Skcpoon 220Sstevel@tonic-gate /* 2312474SGeorge.Shepherd@Sun.COM * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #include <sys/types.h> 270Sstevel@tonic-gate #include <sys/stream.h> 280Sstevel@tonic-gate #include <sys/strsubr.h> 290Sstevel@tonic-gate #include <sys/stropts.h> 300Sstevel@tonic-gate #include <sys/strsun.h> 310Sstevel@tonic-gate #define _SUN_TPI_VERSION 2 320Sstevel@tonic-gate #include <sys/tihdr.h> 330Sstevel@tonic-gate #include <sys/ddi.h> 340Sstevel@tonic-gate #include <sys/sunddi.h> 350Sstevel@tonic-gate #include <sys/xti_inet.h> 360Sstevel@tonic-gate #include <sys/cmn_err.h> 370Sstevel@tonic-gate #include <sys/debug.h> 380Sstevel@tonic-gate #include <sys/vtrace.h> 390Sstevel@tonic-gate #include <sys/kmem.h> 400Sstevel@tonic-gate #include <sys/cpuvar.h> 410Sstevel@tonic-gate #include <sys/random.h> 421676Sjpk #include <sys/priv.h> 433448Sdh155122 #include <sys/sunldi.h> 440Sstevel@tonic-gate 450Sstevel@tonic-gate #include <sys/errno.h> 460Sstevel@tonic-gate #include <sys/signal.h> 470Sstevel@tonic-gate #include <sys/socket.h> 480Sstevel@tonic-gate #include <sys/isa_defs.h> 490Sstevel@tonic-gate #include <netinet/in.h> 500Sstevel@tonic-gate #include <netinet/tcp.h> 510Sstevel@tonic-gate #include <netinet/ip6.h> 520Sstevel@tonic-gate #include <netinet/icmp6.h> 530Sstevel@tonic-gate #include <netinet/sctp.h> 540Sstevel@tonic-gate #include <net/if.h> 550Sstevel@tonic-gate 560Sstevel@tonic-gate #include <inet/common.h> 570Sstevel@tonic-gate #include <inet/ip.h> 5811042SErik.Nordmark@Sun.COM #include <inet/ip_if.h> 5911042SErik.Nordmark@Sun.COM #include <inet/ip_ire.h> 600Sstevel@tonic-gate #include <inet/ip6.h> 610Sstevel@tonic-gate #include <inet/mi.h> 620Sstevel@tonic-gate #include <inet/mib2.h> 633448Sdh155122 #include <inet/kstatcom.h> 640Sstevel@tonic-gate #include <inet/optcom.h> 650Sstevel@tonic-gate #include <inet/ipclassifier.h> 660Sstevel@tonic-gate #include <inet/ipsec_impl.h> 670Sstevel@tonic-gate #include <inet/sctp_ip.h> 680Sstevel@tonic-gate #include <inet/sctp_crc32.h> 690Sstevel@tonic-gate 700Sstevel@tonic-gate #include "sctp_impl.h" 710Sstevel@tonic-gate #include "sctp_addr.h" 72852Svi117747 #include "sctp_asconf.h" 730Sstevel@tonic-gate 740Sstevel@tonic-gate int sctpdebug; 750Sstevel@tonic-gate sin6_t sctp_sin6_null; /* Zero address for quick clears */ 760Sstevel@tonic-gate 770Sstevel@tonic-gate static void sctp_closei_local(sctp_t *sctp); 780Sstevel@tonic-gate static int sctp_init_values(sctp_t *, sctp_t *, int); 790Sstevel@tonic-gate static void sctp_icmp_error_ipv6(sctp_t *sctp, mblk_t *mp); 800Sstevel@tonic-gate static void sctp_process_recvq(void *); 813448Sdh155122 static void sctp_rq_tq_init(sctp_stack_t *); 823448Sdh155122 static void sctp_rq_tq_fini(sctp_stack_t *); 830Sstevel@tonic-gate static void sctp_conn_cache_init(); 840Sstevel@tonic-gate static void sctp_conn_cache_fini(); 850Sstevel@tonic-gate static int sctp_conn_cache_constructor(); 860Sstevel@tonic-gate static void sctp_conn_cache_destructor(); 874691Skcpoon static void sctp_conn_clear(conn_t *); 8811042SErik.Nordmark@Sun.COM static void sctp_notify(void *, ip_xmit_attr_t *, ixa_notify_type_t, 8911042SErik.Nordmark@Sun.COM ixa_notify_arg_t); 903448Sdh155122 913448Sdh155122 static void *sctp_stack_init(netstackid_t stackid, netstack_t *ns); 923448Sdh155122 static void sctp_stack_fini(netstackid_t stackid, void *arg); 930Sstevel@tonic-gate 940Sstevel@tonic-gate /* 950Sstevel@tonic-gate * SCTP receive queue taskq 960Sstevel@tonic-gate * 970Sstevel@tonic-gate * At SCTP initialization time, a default taskq is created for 980Sstevel@tonic-gate * servicing packets received when the interrupt thread cannot 990Sstevel@tonic-gate * get a hold on the sctp_t. The number of taskq can be increased in 1000Sstevel@tonic-gate * sctp_find_next_tq() when an existing taskq cannot be dispatched. 1010Sstevel@tonic-gate * The taskqs are never removed. But the max number of taskq which 1020Sstevel@tonic-gate * can be created is controlled by sctp_recvq_tq_list_max_sz. Note 1030Sstevel@tonic-gate * that SCTP recvq taskq is not tied to any specific CPU or ill. 1040Sstevel@tonic-gate * 1050Sstevel@tonic-gate * Those taskqs are stored in an array recvq_tq_list. And they are 1060Sstevel@tonic-gate * used in a round robin fashion. The current taskq being used is 1070Sstevel@tonic-gate * determined by recvq_tq_list_cur. 1080Sstevel@tonic-gate */ 1090Sstevel@tonic-gate 1103448Sdh155122 /* /etc/system variables */ 1110Sstevel@tonic-gate /* The minimum number of threads for each taskq. */ 112*12869SKacheong.Poon@Sun.COM int sctp_recvq_tq_thr_min = 4; 1130Sstevel@tonic-gate /* The maximum number of threads for each taskq. */ 114*12869SKacheong.Poon@Sun.COM int sctp_recvq_tq_thr_max = 48; 115*12869SKacheong.Poon@Sun.COM /* The mnimum number of tasks for each taskq. */ 116*12869SKacheong.Poon@Sun.COM int sctp_recvq_tq_task_min = 8; 117*12869SKacheong.Poon@Sun.COM /* Default value of sctp_recvq_tq_list_max_sz. */ 118*12869SKacheong.Poon@Sun.COM int sctp_recvq_tq_list_max = 16; 1190Sstevel@tonic-gate 12012016SGirish.Moodalbail@Sun.COM /* 12112016SGirish.Moodalbail@Sun.COM * SCTP tunables related declarations. Definitions are in sctp_tunables.c 12212016SGirish.Moodalbail@Sun.COM */ 12312016SGirish.Moodalbail@Sun.COM extern mod_prop_info_t sctp_propinfo_tbl[]; 12412016SGirish.Moodalbail@Sun.COM extern int sctp_propinfo_count; 12512016SGirish.Moodalbail@Sun.COM 1260Sstevel@tonic-gate /* sctp_t/conn_t kmem cache */ 1270Sstevel@tonic-gate struct kmem_cache *sctp_conn_cache; 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate #define SCTP_CONDEMNED(sctp) \ 1300Sstevel@tonic-gate mutex_enter(&(sctp)->sctp_reflock); \ 1310Sstevel@tonic-gate ((sctp)->sctp_condemned = B_TRUE); \ 1321213Skcpoon mutex_exit(&(sctp)->sctp_reflock); 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate /* Link/unlink a sctp_t to/from the global list. */ 1353448Sdh155122 #define SCTP_LINK(sctp, sctps) \ 1363448Sdh155122 mutex_enter(&(sctps)->sctps_g_lock); \ 1373448Sdh155122 list_insert_tail(&sctps->sctps_g_list, (sctp)); \ 1383448Sdh155122 mutex_exit(&(sctps)->sctps_g_lock); 1390Sstevel@tonic-gate 1403448Sdh155122 #define SCTP_UNLINK(sctp, sctps) \ 1413448Sdh155122 mutex_enter(&(sctps)->sctps_g_lock); \ 1420Sstevel@tonic-gate ASSERT((sctp)->sctp_condemned); \ 1433448Sdh155122 list_remove(&(sctps)->sctps_g_list, (sctp)); \ 1443448Sdh155122 mutex_exit(&(sctps)->sctps_g_lock); 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate /* 147852Svi117747 * Hooks for Sun Cluster. On non-clustered nodes these will remain NULL. 148852Svi117747 * PSARC/2005/602. 149852Svi117747 */ 150852Svi117747 void (*cl_sctp_listen)(sa_family_t, uchar_t *, uint_t, in_port_t) = NULL; 151852Svi117747 void (*cl_sctp_unlisten)(sa_family_t, uchar_t *, uint_t, in_port_t) = NULL; 152852Svi117747 void (*cl_sctp_connect)(sa_family_t, uchar_t *, uint_t, in_port_t, 153852Svi117747 uchar_t *, uint_t, in_port_t, boolean_t, cl_sctp_handle_t) = NULL; 154852Svi117747 void (*cl_sctp_disconnect)(sa_family_t, cl_sctp_handle_t) = NULL; 155852Svi117747 void (*cl_sctp_assoc_change)(sa_family_t, uchar_t *, size_t, uint_t, 156852Svi117747 uchar_t *, size_t, uint_t, int, cl_sctp_handle_t) = NULL; 157852Svi117747 void (*cl_sctp_check_addrs)(sa_family_t, in_port_t, uchar_t **, size_t, 158852Svi117747 uint_t *, boolean_t) = NULL; 159852Svi117747 /* 1600Sstevel@tonic-gate * Return the version number of the SCTP kernel interface. 1610Sstevel@tonic-gate */ 1620Sstevel@tonic-gate int 1630Sstevel@tonic-gate sctp_itf_ver(int cl_ver) 1640Sstevel@tonic-gate { 1650Sstevel@tonic-gate if (cl_ver != SCTP_ITF_VER) 1660Sstevel@tonic-gate return (-1); 1670Sstevel@tonic-gate return (SCTP_ITF_VER); 1680Sstevel@tonic-gate } 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate /* 1710Sstevel@tonic-gate * Called when we need a new sctp instantiation but don't really have a 1720Sstevel@tonic-gate * new q to hang it off of. Copy the priv flag from the passed in structure. 1730Sstevel@tonic-gate */ 1740Sstevel@tonic-gate sctp_t * 1750Sstevel@tonic-gate sctp_create_eager(sctp_t *psctp) 1760Sstevel@tonic-gate { 1770Sstevel@tonic-gate sctp_t *sctp; 1780Sstevel@tonic-gate mblk_t *ack_mp, *hb_mp; 17911042SErik.Nordmark@Sun.COM conn_t *connp; 18011042SErik.Nordmark@Sun.COM cred_t *credp; 1813448Sdh155122 sctp_stack_t *sctps = psctp->sctp_sctps; 1820Sstevel@tonic-gate 1833448Sdh155122 if ((connp = ipcl_conn_create(IPCL_SCTPCONN, KM_NOSLEEP, 1844505Skcpoon sctps->sctps_netstack)) == NULL) { 1850Sstevel@tonic-gate return (NULL); 1863448Sdh155122 } 1871676Sjpk 1880Sstevel@tonic-gate sctp = CONN2SCTP(connp); 1893448Sdh155122 sctp->sctp_sctps = sctps; 1900Sstevel@tonic-gate 1914691Skcpoon if ((ack_mp = sctp_timer_alloc(sctp, sctp_ack_timer, 1924691Skcpoon KM_NOSLEEP)) == NULL || 1934691Skcpoon (hb_mp = sctp_timer_alloc(sctp, sctp_heartbeat_timer, 1944691Skcpoon KM_NOSLEEP)) == NULL) { 1950Sstevel@tonic-gate if (ack_mp != NULL) 1960Sstevel@tonic-gate freeb(ack_mp); 1974691Skcpoon sctp_conn_clear(connp); 1983448Sdh155122 sctp->sctp_sctps = NULL; 1990Sstevel@tonic-gate kmem_cache_free(sctp_conn_cache, connp); 2000Sstevel@tonic-gate return (NULL); 2010Sstevel@tonic-gate } 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate sctp->sctp_ack_mp = ack_mp; 2040Sstevel@tonic-gate sctp->sctp_heartbeat_mp = hb_mp; 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate if (sctp_init_values(sctp, psctp, KM_NOSLEEP) != 0) { 2070Sstevel@tonic-gate freeb(ack_mp); 2080Sstevel@tonic-gate freeb(hb_mp); 2094691Skcpoon sctp_conn_clear(connp); 2103448Sdh155122 sctp->sctp_sctps = NULL; 2110Sstevel@tonic-gate kmem_cache_free(sctp_conn_cache, connp); 2120Sstevel@tonic-gate return (NULL); 2130Sstevel@tonic-gate } 2141676Sjpk 21511042SErik.Nordmark@Sun.COM if ((credp = psctp->sctp_connp->conn_cred) != NULL) { 2161676Sjpk connp->conn_cred = credp; 2171676Sjpk crhold(credp); 2180Sstevel@tonic-gate } 2192263Ssommerfe 2200Sstevel@tonic-gate sctp->sctp_mss = psctp->sctp_mss; 2210Sstevel@tonic-gate sctp->sctp_detached = B_TRUE; 2220Sstevel@tonic-gate /* 2230Sstevel@tonic-gate * Link to the global as soon as possible so that this sctp_t 2240Sstevel@tonic-gate * can be found. 2250Sstevel@tonic-gate */ 2263448Sdh155122 SCTP_LINK(sctp, sctps); 2270Sstevel@tonic-gate 228*12869SKacheong.Poon@Sun.COM /* If the listener has a limit, inherit the counter info. */ 229*12869SKacheong.Poon@Sun.COM sctp->sctp_listen_cnt = psctp->sctp_listen_cnt; 230*12869SKacheong.Poon@Sun.COM 2310Sstevel@tonic-gate return (sctp); 2320Sstevel@tonic-gate } 2330Sstevel@tonic-gate 2340Sstevel@tonic-gate /* 2350Sstevel@tonic-gate * We are dying for some reason. Try to do it gracefully. 2360Sstevel@tonic-gate */ 2370Sstevel@tonic-gate void 2380Sstevel@tonic-gate sctp_clean_death(sctp_t *sctp, int err) 2390Sstevel@tonic-gate { 2400Sstevel@tonic-gate ASSERT(sctp != NULL); 2410Sstevel@tonic-gate 2421676Sjpk dprint(3, ("sctp_clean_death %p, state %d\n", (void *)sctp, 2431676Sjpk sctp->sctp_state)); 2440Sstevel@tonic-gate 2450Sstevel@tonic-gate sctp->sctp_client_errno = err; 2460Sstevel@tonic-gate /* 2470Sstevel@tonic-gate * Check to see if we need to notify upper layer. 2480Sstevel@tonic-gate */ 2490Sstevel@tonic-gate if ((sctp->sctp_state >= SCTPS_COOKIE_WAIT) && 2500Sstevel@tonic-gate !SCTP_IS_DETACHED(sctp)) { 2510Sstevel@tonic-gate if (sctp->sctp_xmit_head || sctp->sctp_xmit_unsent) { 2520Sstevel@tonic-gate sctp_regift_xmitlist(sctp); 2530Sstevel@tonic-gate } 2548348SEric.Yu@Sun.COM if (sctp->sctp_ulp_disconnected(sctp->sctp_ulpd, 0, err)) { 2550Sstevel@tonic-gate /* 2560Sstevel@tonic-gate * Socket is gone, detach. 2570Sstevel@tonic-gate */ 2580Sstevel@tonic-gate sctp->sctp_detached = B_TRUE; 2590Sstevel@tonic-gate sctp->sctp_ulpd = NULL; 2608348SEric.Yu@Sun.COM sctp->sctp_upcalls = NULL; 2610Sstevel@tonic-gate } 2620Sstevel@tonic-gate } 2630Sstevel@tonic-gate 2640Sstevel@tonic-gate /* Remove this sctp from all hashes. */ 2650Sstevel@tonic-gate sctp_closei_local(sctp); 2660Sstevel@tonic-gate 2670Sstevel@tonic-gate /* 2680Sstevel@tonic-gate * If the sctp_t is detached, we need to finish freeing up 2690Sstevel@tonic-gate * the resources. At this point, ip_fanout_sctp() should have 2700Sstevel@tonic-gate * a hold on this sctp_t. Some thread doing snmp stuff can 2710Sstevel@tonic-gate * have a hold. And a taskq can also have a hold waiting to 2720Sstevel@tonic-gate * work. sctp_unlink() the sctp_t from the global list so 2730Sstevel@tonic-gate * that no new thread can find it. Then do a SCTP_REFRELE(). 2740Sstevel@tonic-gate * The sctp_t will be freed after all those threads are done. 2750Sstevel@tonic-gate */ 2760Sstevel@tonic-gate if (SCTP_IS_DETACHED(sctp)) { 2770Sstevel@tonic-gate SCTP_CONDEMNED(sctp); 2780Sstevel@tonic-gate SCTP_REFRELE(sctp); 2790Sstevel@tonic-gate } 2800Sstevel@tonic-gate } 2810Sstevel@tonic-gate 2820Sstevel@tonic-gate /* 2830Sstevel@tonic-gate * Called by upper layer when it wants to close this association. 2840Sstevel@tonic-gate * Depending on the state of this assoication, we need to do 2850Sstevel@tonic-gate * different things. 2860Sstevel@tonic-gate * 2870Sstevel@tonic-gate * If the state is below COOKIE_ECHOED or it is COOKIE_ECHOED but with 2880Sstevel@tonic-gate * no sent data, just remove this sctp from all the hashes. This 2890Sstevel@tonic-gate * makes sure that all packets from the other end will go to the default 2900Sstevel@tonic-gate * sctp handling. The upper layer will then do a sctp_close() to clean 2910Sstevel@tonic-gate * up. 2920Sstevel@tonic-gate * 2930Sstevel@tonic-gate * Otherwise, check and see if SO_LINGER is set. If it is set, check 2940Sstevel@tonic-gate * the value. If the value is 0, consider this an abortive close. Send 2950Sstevel@tonic-gate * an ABORT message and kill the associatiion. 2960Sstevel@tonic-gate * 2970Sstevel@tonic-gate */ 2980Sstevel@tonic-gate int 2990Sstevel@tonic-gate sctp_disconnect(sctp_t *sctp) 3000Sstevel@tonic-gate { 30111042SErik.Nordmark@Sun.COM int error = 0; 30211042SErik.Nordmark@Sun.COM conn_t *connp = sctp->sctp_connp; 3030Sstevel@tonic-gate 3041676Sjpk dprint(3, ("sctp_disconnect %p, state %d\n", (void *)sctp, 3051676Sjpk sctp->sctp_state)); 3060Sstevel@tonic-gate 3070Sstevel@tonic-gate RUN_SCTP(sctp); 3080Sstevel@tonic-gate 3090Sstevel@tonic-gate switch (sctp->sctp_state) { 3100Sstevel@tonic-gate case SCTPS_IDLE: 3110Sstevel@tonic-gate case SCTPS_BOUND: 3120Sstevel@tonic-gate case SCTPS_LISTEN: 3130Sstevel@tonic-gate break; 3140Sstevel@tonic-gate case SCTPS_COOKIE_WAIT: 3150Sstevel@tonic-gate case SCTPS_COOKIE_ECHOED: 3160Sstevel@tonic-gate /* 3170Sstevel@tonic-gate * Close during the connect 3-way handshake 3180Sstevel@tonic-gate * but here there may or may not be pending data 3190Sstevel@tonic-gate * already on queue. Process almost same as in 3200Sstevel@tonic-gate * the ESTABLISHED state. 3210Sstevel@tonic-gate */ 3220Sstevel@tonic-gate if (sctp->sctp_xmit_head == NULL && 3230Sstevel@tonic-gate sctp->sctp_xmit_unsent == NULL) { 3240Sstevel@tonic-gate break; 3250Sstevel@tonic-gate } 3260Sstevel@tonic-gate /* FALLTHRU */ 3270Sstevel@tonic-gate default: 3280Sstevel@tonic-gate /* 3297480SKacheong.Poon@Sun.COM * If SO_LINGER has set a zero linger time, terminate the 3307480SKacheong.Poon@Sun.COM * association and send an ABORT. 3310Sstevel@tonic-gate */ 33211042SErik.Nordmark@Sun.COM if (connp->conn_linger && connp->conn_lingertime == 0) { 3337480SKacheong.Poon@Sun.COM sctp_user_abort(sctp, NULL); 3347480SKacheong.Poon@Sun.COM WAKE_SCTP(sctp); 3357480SKacheong.Poon@Sun.COM return (error); 3360Sstevel@tonic-gate } 3370Sstevel@tonic-gate 3380Sstevel@tonic-gate /* 3397480SKacheong.Poon@Sun.COM * In there is unread data, send an ABORT and terminate the 3407480SKacheong.Poon@Sun.COM * association. 341852Svi117747 */ 342852Svi117747 if (sctp->sctp_rxqueued > 0 || sctp->sctp_irwnd > 343852Svi117747 sctp->sctp_rwnd) { 3447480SKacheong.Poon@Sun.COM sctp_user_abort(sctp, NULL); 3457480SKacheong.Poon@Sun.COM WAKE_SCTP(sctp); 3467480SKacheong.Poon@Sun.COM return (error); 347852Svi117747 } 348852Svi117747 /* 3490Sstevel@tonic-gate * Transmit the shutdown before detaching the sctp_t. 3500Sstevel@tonic-gate * After sctp_detach returns this queue/perimeter 3510Sstevel@tonic-gate * no longer owns the sctp_t thus others can modify it. 3520Sstevel@tonic-gate */ 3530Sstevel@tonic-gate sctp_send_shutdown(sctp, 0); 3540Sstevel@tonic-gate 3550Sstevel@tonic-gate /* Pass gathered wisdom to IP for keeping */ 35611042SErik.Nordmark@Sun.COM sctp_update_dce(sctp); 3570Sstevel@tonic-gate 3580Sstevel@tonic-gate /* 3590Sstevel@tonic-gate * If lingering on close then wait until the shutdown 3600Sstevel@tonic-gate * is complete, or the SO_LINGER time passes, or an 3610Sstevel@tonic-gate * ABORT is sent/received. Note that sctp_disconnect() 3620Sstevel@tonic-gate * can be called more than once. Make sure that only 3630Sstevel@tonic-gate * one thread waits. 3640Sstevel@tonic-gate */ 36511042SErik.Nordmark@Sun.COM if (connp->conn_linger && connp->conn_lingertime > 0 && 3660Sstevel@tonic-gate sctp->sctp_state >= SCTPS_ESTABLISHED && 3670Sstevel@tonic-gate !sctp->sctp_lingering) { 3680Sstevel@tonic-gate clock_t stoptime; /* in ticks */ 3690Sstevel@tonic-gate clock_t ret; 3700Sstevel@tonic-gate 3710Sstevel@tonic-gate sctp->sctp_lingering = 1; 3720Sstevel@tonic-gate sctp->sctp_client_errno = 0; 37311066Srafael.vanoni@sun.com stoptime = ddi_get_lbolt() + 37411066Srafael.vanoni@sun.com connp->conn_lingertime * hz; 3750Sstevel@tonic-gate 3760Sstevel@tonic-gate mutex_enter(&sctp->sctp_lock); 3770Sstevel@tonic-gate sctp->sctp_running = B_FALSE; 3780Sstevel@tonic-gate while (sctp->sctp_state >= SCTPS_ESTABLISHED && 3790Sstevel@tonic-gate sctp->sctp_client_errno == 0) { 380*12869SKacheong.Poon@Sun.COM cv_signal(&sctp->sctp_cv); 3810Sstevel@tonic-gate ret = cv_timedwait_sig(&sctp->sctp_cv, 3820Sstevel@tonic-gate &sctp->sctp_lock, stoptime); 3830Sstevel@tonic-gate if (ret < 0) { 3840Sstevel@tonic-gate /* Stoptime has reached. */ 3850Sstevel@tonic-gate sctp->sctp_client_errno = EWOULDBLOCK; 3860Sstevel@tonic-gate break; 3870Sstevel@tonic-gate } else if (ret == 0) { 3880Sstevel@tonic-gate /* Got a signal. */ 3890Sstevel@tonic-gate break; 3900Sstevel@tonic-gate } 3910Sstevel@tonic-gate } 3920Sstevel@tonic-gate error = sctp->sctp_client_errno; 3930Sstevel@tonic-gate sctp->sctp_client_errno = 0; 3940Sstevel@tonic-gate mutex_exit(&sctp->sctp_lock); 3950Sstevel@tonic-gate } 3960Sstevel@tonic-gate 3970Sstevel@tonic-gate WAKE_SCTP(sctp); 3980Sstevel@tonic-gate return (error); 3990Sstevel@tonic-gate } 4000Sstevel@tonic-gate 4010Sstevel@tonic-gate 4020Sstevel@tonic-gate /* Remove this sctp from all hashes so nobody can find it. */ 4030Sstevel@tonic-gate sctp_closei_local(sctp); 4040Sstevel@tonic-gate WAKE_SCTP(sctp); 4050Sstevel@tonic-gate return (error); 4060Sstevel@tonic-gate } 4070Sstevel@tonic-gate 4080Sstevel@tonic-gate void 4090Sstevel@tonic-gate sctp_close(sctp_t *sctp) 4100Sstevel@tonic-gate { 4111676Sjpk dprint(3, ("sctp_close %p, state %d\n", (void *)sctp, 4121676Sjpk sctp->sctp_state)); 4130Sstevel@tonic-gate 4140Sstevel@tonic-gate RUN_SCTP(sctp); 4150Sstevel@tonic-gate sctp->sctp_detached = 1; 4160Sstevel@tonic-gate sctp->sctp_ulpd = NULL; 4178348SEric.Yu@Sun.COM sctp->sctp_upcalls = NULL; 4180Sstevel@tonic-gate bzero(&sctp->sctp_events, sizeof (sctp->sctp_events)); 4190Sstevel@tonic-gate 4200Sstevel@tonic-gate /* If the graceful shutdown has not been completed, just return. */ 4210Sstevel@tonic-gate if (sctp->sctp_state != SCTPS_IDLE) { 4220Sstevel@tonic-gate WAKE_SCTP(sctp); 4230Sstevel@tonic-gate return; 4240Sstevel@tonic-gate } 4250Sstevel@tonic-gate 4260Sstevel@tonic-gate /* 4270Sstevel@tonic-gate * Since sctp_t is in SCTPS_IDLE state, so the only thread which 4280Sstevel@tonic-gate * can have a hold on the sctp_t is doing snmp stuff. Just do 4290Sstevel@tonic-gate * a SCTP_REFRELE() here after the SCTP_UNLINK(). It will 4300Sstevel@tonic-gate * be freed when the other thread is done. 4310Sstevel@tonic-gate */ 4320Sstevel@tonic-gate SCTP_CONDEMNED(sctp); 4330Sstevel@tonic-gate WAKE_SCTP(sctp); 4340Sstevel@tonic-gate SCTP_REFRELE(sctp); 4350Sstevel@tonic-gate } 4360Sstevel@tonic-gate 4370Sstevel@tonic-gate /* 4380Sstevel@tonic-gate * Unlink from global list and do the eager close. 4390Sstevel@tonic-gate * Remove the refhold implicit in being on the global list. 4400Sstevel@tonic-gate */ 4410Sstevel@tonic-gate void 4420Sstevel@tonic-gate sctp_close_eager(sctp_t *sctp) 4430Sstevel@tonic-gate { 4440Sstevel@tonic-gate SCTP_CONDEMNED(sctp); 4450Sstevel@tonic-gate sctp_closei_local(sctp); 4460Sstevel@tonic-gate SCTP_REFRELE(sctp); 4470Sstevel@tonic-gate } 4480Sstevel@tonic-gate 4490Sstevel@tonic-gate /* 4500Sstevel@tonic-gate * The sctp_t is going away. Remove it from all lists and set it 4510Sstevel@tonic-gate * to SCTPS_IDLE. The caller has to remove it from the 4520Sstevel@tonic-gate * global list. The freeing up of memory is deferred until 4530Sstevel@tonic-gate * sctp_free(). This is needed since a thread in sctp_input() might have 4540Sstevel@tonic-gate * done a SCTP_REFHOLD on this structure before it was removed from the 4550Sstevel@tonic-gate * hashes. 4560Sstevel@tonic-gate */ 4570Sstevel@tonic-gate static void 4580Sstevel@tonic-gate sctp_closei_local(sctp_t *sctp) 4590Sstevel@tonic-gate { 4600Sstevel@tonic-gate mblk_t *mp; 4610Sstevel@tonic-gate conn_t *connp = sctp->sctp_connp; 4620Sstevel@tonic-gate 463*12869SKacheong.Poon@Sun.COM /* The counter is incremented only for established associations. */ 464*12869SKacheong.Poon@Sun.COM if (sctp->sctp_state >= SCTPS_ESTABLISHED) 465*12869SKacheong.Poon@Sun.COM SCTPS_ASSOC_DEC(sctp->sctp_sctps); 466*12869SKacheong.Poon@Sun.COM 467*12869SKacheong.Poon@Sun.COM if (sctp->sctp_listen_cnt != NULL) 468*12869SKacheong.Poon@Sun.COM SCTP_DECR_LISTEN_CNT(sctp); 469*12869SKacheong.Poon@Sun.COM 4704505Skcpoon /* Sanity check, don't do the same thing twice. */ 4714505Skcpoon if (connp->conn_state_flags & CONN_CLOSING) { 4724505Skcpoon ASSERT(sctp->sctp_state == SCTPS_IDLE); 4734505Skcpoon return; 4744505Skcpoon } 4754505Skcpoon 4760Sstevel@tonic-gate /* Stop and free the timers */ 4770Sstevel@tonic-gate sctp_free_faddr_timers(sctp); 4780Sstevel@tonic-gate if ((mp = sctp->sctp_heartbeat_mp) != NULL) { 4790Sstevel@tonic-gate sctp_timer_free(mp); 4800Sstevel@tonic-gate sctp->sctp_heartbeat_mp = NULL; 4810Sstevel@tonic-gate } 4820Sstevel@tonic-gate if ((mp = sctp->sctp_ack_mp) != NULL) { 4830Sstevel@tonic-gate sctp_timer_free(mp); 4840Sstevel@tonic-gate sctp->sctp_ack_mp = NULL; 4850Sstevel@tonic-gate } 4860Sstevel@tonic-gate 4870Sstevel@tonic-gate /* Set the CONN_CLOSING flag so that IP will not cache IRE again. */ 4880Sstevel@tonic-gate mutex_enter(&connp->conn_lock); 4890Sstevel@tonic-gate connp->conn_state_flags |= CONN_CLOSING; 4900Sstevel@tonic-gate mutex_exit(&connp->conn_lock); 4910Sstevel@tonic-gate 4920Sstevel@tonic-gate /* Remove from all hashes. */ 4930Sstevel@tonic-gate sctp_bind_hash_remove(sctp); 4940Sstevel@tonic-gate sctp_conn_hash_remove(sctp); 4950Sstevel@tonic-gate sctp_listen_hash_remove(sctp); 4960Sstevel@tonic-gate sctp->sctp_state = SCTPS_IDLE; 4970Sstevel@tonic-gate 4980Sstevel@tonic-gate /* 4990Sstevel@tonic-gate * Clean up the recvq as much as possible. All those packets 5000Sstevel@tonic-gate * will be silently dropped as this sctp_t is now in idle state. 5010Sstevel@tonic-gate */ 5020Sstevel@tonic-gate mutex_enter(&sctp->sctp_recvq_lock); 5030Sstevel@tonic-gate while ((mp = sctp->sctp_recvq) != NULL) { 5040Sstevel@tonic-gate sctp->sctp_recvq = mp->b_next; 5050Sstevel@tonic-gate mp->b_next = NULL; 50611042SErik.Nordmark@Sun.COM 50711042SErik.Nordmark@Sun.COM if (ip_recv_attr_is_mblk(mp)) 50811042SErik.Nordmark@Sun.COM mp = ip_recv_attr_free_mblk(mp); 50911042SErik.Nordmark@Sun.COM 5100Sstevel@tonic-gate freemsg(mp); 5110Sstevel@tonic-gate } 5120Sstevel@tonic-gate mutex_exit(&sctp->sctp_recvq_lock); 5130Sstevel@tonic-gate } 5140Sstevel@tonic-gate 5150Sstevel@tonic-gate /* 5160Sstevel@tonic-gate * Free memory associated with the sctp/ip header template. 5170Sstevel@tonic-gate */ 5180Sstevel@tonic-gate static void 5190Sstevel@tonic-gate sctp_headers_free(sctp_t *sctp) 5200Sstevel@tonic-gate { 5210Sstevel@tonic-gate if (sctp->sctp_iphc != NULL) { 5220Sstevel@tonic-gate kmem_free(sctp->sctp_iphc, sctp->sctp_iphc_len); 5230Sstevel@tonic-gate sctp->sctp_iphc = NULL; 5240Sstevel@tonic-gate sctp->sctp_ipha = NULL; 5250Sstevel@tonic-gate sctp->sctp_hdr_len = 0; 5260Sstevel@tonic-gate sctp->sctp_ip_hdr_len = 0; 5270Sstevel@tonic-gate sctp->sctp_iphc_len = 0; 5280Sstevel@tonic-gate sctp->sctp_sctph = NULL; 5290Sstevel@tonic-gate sctp->sctp_hdr_len = 0; 5300Sstevel@tonic-gate } 5310Sstevel@tonic-gate if (sctp->sctp_iphc6 != NULL) { 5320Sstevel@tonic-gate kmem_free(sctp->sctp_iphc6, sctp->sctp_iphc6_len); 5330Sstevel@tonic-gate sctp->sctp_iphc6 = NULL; 5340Sstevel@tonic-gate sctp->sctp_ip6h = NULL; 5350Sstevel@tonic-gate sctp->sctp_hdr6_len = 0; 5360Sstevel@tonic-gate sctp->sctp_ip_hdr6_len = 0; 5370Sstevel@tonic-gate sctp->sctp_iphc6_len = 0; 5380Sstevel@tonic-gate sctp->sctp_sctph6 = NULL; 5390Sstevel@tonic-gate sctp->sctp_hdr6_len = 0; 5400Sstevel@tonic-gate } 5410Sstevel@tonic-gate } 5420Sstevel@tonic-gate 5430Sstevel@tonic-gate static void 5440Sstevel@tonic-gate sctp_free_xmit_data(sctp_t *sctp) 5450Sstevel@tonic-gate { 5460Sstevel@tonic-gate mblk_t *ump = NULL; 5470Sstevel@tonic-gate mblk_t *nump; 5480Sstevel@tonic-gate mblk_t *mp; 5490Sstevel@tonic-gate mblk_t *nmp; 5500Sstevel@tonic-gate 5510Sstevel@tonic-gate sctp->sctp_xmit_unacked = NULL; 5520Sstevel@tonic-gate ump = sctp->sctp_xmit_head; 5530Sstevel@tonic-gate sctp->sctp_xmit_tail = sctp->sctp_xmit_head = NULL; 5540Sstevel@tonic-gate free_unsent: 5550Sstevel@tonic-gate for (; ump != NULL; ump = nump) { 5560Sstevel@tonic-gate for (mp = ump->b_cont; mp != NULL; mp = nmp) { 5570Sstevel@tonic-gate nmp = mp->b_next; 5580Sstevel@tonic-gate mp->b_next = NULL; 5590Sstevel@tonic-gate mp->b_prev = NULL; 5600Sstevel@tonic-gate freemsg(mp); 5610Sstevel@tonic-gate } 5620Sstevel@tonic-gate ASSERT(DB_REF(ump) == 1); 5630Sstevel@tonic-gate nump = ump->b_next; 5640Sstevel@tonic-gate ump->b_next = NULL; 5650Sstevel@tonic-gate ump->b_prev = NULL; 5660Sstevel@tonic-gate ump->b_cont = NULL; 5670Sstevel@tonic-gate freeb(ump); 5680Sstevel@tonic-gate } 5690Sstevel@tonic-gate if ((ump = sctp->sctp_xmit_unsent) == NULL) { 5700Sstevel@tonic-gate ASSERT(sctp->sctp_xmit_unsent_tail == NULL); 5710Sstevel@tonic-gate return; 5720Sstevel@tonic-gate } 5730Sstevel@tonic-gate sctp->sctp_xmit_unsent = sctp->sctp_xmit_unsent_tail = NULL; 5740Sstevel@tonic-gate goto free_unsent; 5750Sstevel@tonic-gate } 5760Sstevel@tonic-gate 5770Sstevel@tonic-gate /* 5780Sstevel@tonic-gate * Cleanup all the messages in the stream queue and the reassembly lists. 5790Sstevel@tonic-gate * If 'free' is true, then delete the streams as well. 5800Sstevel@tonic-gate */ 5810Sstevel@tonic-gate void 5820Sstevel@tonic-gate sctp_instream_cleanup(sctp_t *sctp, boolean_t free) 5830Sstevel@tonic-gate { 5840Sstevel@tonic-gate int i; 5850Sstevel@tonic-gate mblk_t *mp; 5860Sstevel@tonic-gate mblk_t *mp1; 5870Sstevel@tonic-gate 5880Sstevel@tonic-gate if (sctp->sctp_instr != NULL) { 5890Sstevel@tonic-gate /* walk thru and flush out anything remaining in the Q */ 5900Sstevel@tonic-gate for (i = 0; i < sctp->sctp_num_istr; i++) { 5910Sstevel@tonic-gate mp = sctp->sctp_instr[i].istr_msgs; 5920Sstevel@tonic-gate while (mp != NULL) { 5930Sstevel@tonic-gate mp1 = mp->b_next; 5940Sstevel@tonic-gate mp->b_next = mp->b_prev = NULL; 5950Sstevel@tonic-gate freemsg(mp); 5960Sstevel@tonic-gate mp = mp1; 5970Sstevel@tonic-gate } 5980Sstevel@tonic-gate sctp->sctp_instr[i].istr_msgs = NULL; 5994116Snh145002 sctp->sctp_instr[i].istr_nmsgs = 0; 6000Sstevel@tonic-gate sctp_free_reass((sctp->sctp_instr) + i); 6010Sstevel@tonic-gate sctp->sctp_instr[i].nextseq = 0; 6020Sstevel@tonic-gate } 6030Sstevel@tonic-gate if (free) { 6040Sstevel@tonic-gate kmem_free(sctp->sctp_instr, 6050Sstevel@tonic-gate sizeof (*sctp->sctp_instr) * sctp->sctp_num_istr); 6060Sstevel@tonic-gate sctp->sctp_instr = NULL; 6070Sstevel@tonic-gate sctp->sctp_num_istr = 0; 6080Sstevel@tonic-gate } 6090Sstevel@tonic-gate } 6100Sstevel@tonic-gate /* un-ordered fragments */ 6110Sstevel@tonic-gate if (sctp->sctp_uo_frags != NULL) { 6120Sstevel@tonic-gate for (mp = sctp->sctp_uo_frags; mp != NULL; mp = mp1) { 6130Sstevel@tonic-gate mp1 = mp->b_next; 6140Sstevel@tonic-gate mp->b_next = mp->b_prev = NULL; 6150Sstevel@tonic-gate freemsg(mp); 6160Sstevel@tonic-gate } 61711373SGeorge.Shepherd@Sun.COM sctp->sctp_uo_frags = NULL; 6180Sstevel@tonic-gate } 6190Sstevel@tonic-gate } 6200Sstevel@tonic-gate 6210Sstevel@tonic-gate /* 6220Sstevel@tonic-gate * Last reference to the sctp_t is gone. Free all memory associated with it. 6230Sstevel@tonic-gate * Called from SCTP_REFRELE. Called inline in sctp_close() 6240Sstevel@tonic-gate */ 6250Sstevel@tonic-gate void 6260Sstevel@tonic-gate sctp_free(conn_t *connp) 6270Sstevel@tonic-gate { 6280Sstevel@tonic-gate sctp_t *sctp = CONN2SCTP(connp); 6290Sstevel@tonic-gate int cnt; 6303448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 6310Sstevel@tonic-gate 6323448Sdh155122 ASSERT(sctps != NULL); 6330Sstevel@tonic-gate /* Unlink it from the global list */ 6343448Sdh155122 SCTP_UNLINK(sctp, sctps); 6350Sstevel@tonic-gate 6360Sstevel@tonic-gate ASSERT(connp->conn_ref == 0); 63711042SErik.Nordmark@Sun.COM ASSERT(connp->conn_proto == IPPROTO_SCTP); 6380Sstevel@tonic-gate ASSERT(!MUTEX_HELD(&sctp->sctp_reflock)); 6390Sstevel@tonic-gate ASSERT(sctp->sctp_refcnt == 0); 6400Sstevel@tonic-gate 6410Sstevel@tonic-gate ASSERT(sctp->sctp_ptpbhn == NULL && sctp->sctp_bind_hash == NULL); 6420Sstevel@tonic-gate ASSERT(sctp->sctp_conn_hash_next == NULL && 6430Sstevel@tonic-gate sctp->sctp_conn_hash_prev == NULL); 6440Sstevel@tonic-gate 6450Sstevel@tonic-gate 6460Sstevel@tonic-gate /* Free up all the resources. */ 6470Sstevel@tonic-gate 6480Sstevel@tonic-gate /* blow away sctp stream management */ 6490Sstevel@tonic-gate if (sctp->sctp_ostrcntrs != NULL) { 6500Sstevel@tonic-gate kmem_free(sctp->sctp_ostrcntrs, 6510Sstevel@tonic-gate sizeof (uint16_t) * sctp->sctp_num_ostr); 6520Sstevel@tonic-gate sctp->sctp_ostrcntrs = NULL; 6530Sstevel@tonic-gate } 6540Sstevel@tonic-gate sctp_instream_cleanup(sctp, B_TRUE); 6550Sstevel@tonic-gate 6560Sstevel@tonic-gate /* Remove all data transfer resources. */ 6570Sstevel@tonic-gate sctp->sctp_istr_nmsgs = 0; 6580Sstevel@tonic-gate sctp->sctp_rxqueued = 0; 6590Sstevel@tonic-gate sctp_free_xmit_data(sctp); 6600Sstevel@tonic-gate sctp->sctp_unacked = 0; 6610Sstevel@tonic-gate sctp->sctp_unsent = 0; 662852Svi117747 if (sctp->sctp_cxmit_list != NULL) 663852Svi117747 sctp_asconf_free_cxmit(sctp, NULL); 664852Svi117747 6650Sstevel@tonic-gate sctp->sctp_lastdata = NULL; 6660Sstevel@tonic-gate 6670Sstevel@tonic-gate /* Clear out default xmit settings */ 6680Sstevel@tonic-gate sctp->sctp_def_stream = 0; 6690Sstevel@tonic-gate sctp->sctp_def_flags = 0; 6700Sstevel@tonic-gate sctp->sctp_def_ppid = 0; 6710Sstevel@tonic-gate sctp->sctp_def_context = 0; 6720Sstevel@tonic-gate sctp->sctp_def_timetolive = 0; 6730Sstevel@tonic-gate 6740Sstevel@tonic-gate if (sctp->sctp_sack_info != NULL) { 6750Sstevel@tonic-gate sctp_free_set(sctp->sctp_sack_info); 6760Sstevel@tonic-gate sctp->sctp_sack_info = NULL; 6770Sstevel@tonic-gate } 6780Sstevel@tonic-gate sctp->sctp_sack_gaps = 0; 6790Sstevel@tonic-gate 6800Sstevel@tonic-gate if (sctp->sctp_cookie_mp != NULL) { 6810Sstevel@tonic-gate freemsg(sctp->sctp_cookie_mp); 6820Sstevel@tonic-gate sctp->sctp_cookie_mp = NULL; 6830Sstevel@tonic-gate } 6840Sstevel@tonic-gate 6850Sstevel@tonic-gate /* Remove all the address resources. */ 6860Sstevel@tonic-gate sctp_zap_addrs(sctp); 6870Sstevel@tonic-gate for (cnt = 0; cnt < SCTP_IPIF_HASH; cnt++) { 6880Sstevel@tonic-gate ASSERT(sctp->sctp_saddrs[cnt].ipif_count == 0); 6890Sstevel@tonic-gate list_destroy(&sctp->sctp_saddrs[cnt].sctp_ipif_list); 6900Sstevel@tonic-gate } 6910Sstevel@tonic-gate 6920Sstevel@tonic-gate if (sctp->sctp_hopopts != NULL) { 6930Sstevel@tonic-gate mi_free(sctp->sctp_hopopts); 6940Sstevel@tonic-gate sctp->sctp_hopopts = NULL; 6950Sstevel@tonic-gate sctp->sctp_hopoptslen = 0; 6960Sstevel@tonic-gate } 6970Sstevel@tonic-gate ASSERT(sctp->sctp_hopoptslen == 0); 6980Sstevel@tonic-gate if (sctp->sctp_dstopts != NULL) { 6990Sstevel@tonic-gate mi_free(sctp->sctp_dstopts); 7000Sstevel@tonic-gate sctp->sctp_dstopts = NULL; 7010Sstevel@tonic-gate sctp->sctp_dstoptslen = 0; 7020Sstevel@tonic-gate } 7030Sstevel@tonic-gate ASSERT(sctp->sctp_dstoptslen == 0); 70411042SErik.Nordmark@Sun.COM if (sctp->sctp_rthdrdstopts != NULL) { 70511042SErik.Nordmark@Sun.COM mi_free(sctp->sctp_rthdrdstopts); 70611042SErik.Nordmark@Sun.COM sctp->sctp_rthdrdstopts = NULL; 70711042SErik.Nordmark@Sun.COM sctp->sctp_rthdrdstoptslen = 0; 7080Sstevel@tonic-gate } 70911042SErik.Nordmark@Sun.COM ASSERT(sctp->sctp_rthdrdstoptslen == 0); 7100Sstevel@tonic-gate if (sctp->sctp_rthdr != NULL) { 7110Sstevel@tonic-gate mi_free(sctp->sctp_rthdr); 7120Sstevel@tonic-gate sctp->sctp_rthdr = NULL; 7130Sstevel@tonic-gate sctp->sctp_rthdrlen = 0; 7140Sstevel@tonic-gate } 7150Sstevel@tonic-gate ASSERT(sctp->sctp_rthdrlen == 0); 7160Sstevel@tonic-gate sctp_headers_free(sctp); 7170Sstevel@tonic-gate 7180Sstevel@tonic-gate sctp->sctp_shutdown_faddr = NULL; 7190Sstevel@tonic-gate 7204964Skcpoon if (sctp->sctp_err_chunks != NULL) { 7214964Skcpoon freemsg(sctp->sctp_err_chunks); 7224964Skcpoon sctp->sctp_err_chunks = NULL; 7234964Skcpoon sctp->sctp_err_len = 0; 7244964Skcpoon } 7254964Skcpoon 7260Sstevel@tonic-gate /* Clear all the bitfields. */ 7270Sstevel@tonic-gate bzero(&sctp->sctp_bits, sizeof (sctp->sctp_bits)); 7280Sstevel@tonic-gate 7290Sstevel@tonic-gate /* It is time to update the global statistics. */ 730*12869SKacheong.Poon@Sun.COM SCTPS_UPDATE_MIB(sctps, sctpOutSCTPPkts, sctp->sctp_opkts); 731*12869SKacheong.Poon@Sun.COM SCTPS_UPDATE_MIB(sctps, sctpOutCtrlChunks, sctp->sctp_obchunks); 732*12869SKacheong.Poon@Sun.COM SCTPS_UPDATE_MIB(sctps, sctpOutOrderChunks, sctp->sctp_odchunks); 733*12869SKacheong.Poon@Sun.COM SCTPS_UPDATE_MIB(sctps, sctpOutUnorderChunks, sctp->sctp_oudchunks); 734*12869SKacheong.Poon@Sun.COM SCTPS_UPDATE_MIB(sctps, sctpRetransChunks, sctp->sctp_rxtchunks); 735*12869SKacheong.Poon@Sun.COM SCTPS_UPDATE_MIB(sctps, sctpInSCTPPkts, sctp->sctp_ipkts); 736*12869SKacheong.Poon@Sun.COM SCTPS_UPDATE_MIB(sctps, sctpInCtrlChunks, sctp->sctp_ibchunks); 737*12869SKacheong.Poon@Sun.COM SCTPS_UPDATE_MIB(sctps, sctpInOrderChunks, sctp->sctp_idchunks); 738*12869SKacheong.Poon@Sun.COM SCTPS_UPDATE_MIB(sctps, sctpInUnorderChunks, sctp->sctp_iudchunks); 739*12869SKacheong.Poon@Sun.COM SCTPS_UPDATE_MIB(sctps, sctpFragUsrMsgs, sctp->sctp_fragdmsgs); 740*12869SKacheong.Poon@Sun.COM SCTPS_UPDATE_MIB(sctps, sctpReasmUsrMsgs, sctp->sctp_reassmsgs); 7410Sstevel@tonic-gate sctp->sctp_opkts = 0; 7420Sstevel@tonic-gate sctp->sctp_obchunks = 0; 7430Sstevel@tonic-gate sctp->sctp_odchunks = 0; 7440Sstevel@tonic-gate sctp->sctp_oudchunks = 0; 7450Sstevel@tonic-gate sctp->sctp_rxtchunks = 0; 7460Sstevel@tonic-gate sctp->sctp_ipkts = 0; 7470Sstevel@tonic-gate sctp->sctp_ibchunks = 0; 7480Sstevel@tonic-gate sctp->sctp_idchunks = 0; 7490Sstevel@tonic-gate sctp->sctp_iudchunks = 0; 7500Sstevel@tonic-gate sctp->sctp_fragdmsgs = 0; 7510Sstevel@tonic-gate sctp->sctp_reassmsgs = 0; 75210751SGeorge.Shepherd@Sun.COM sctp->sctp_outseqtsns = 0; 75310751SGeorge.Shepherd@Sun.COM sctp->sctp_osacks = 0; 75410751SGeorge.Shepherd@Sun.COM sctp->sctp_isacks = 0; 75510751SGeorge.Shepherd@Sun.COM sctp->sctp_idupchunks = 0; 75610751SGeorge.Shepherd@Sun.COM sctp->sctp_gapcnt = 0; 75710751SGeorge.Shepherd@Sun.COM sctp->sctp_cum_obchunks = 0; 75810751SGeorge.Shepherd@Sun.COM sctp->sctp_cum_odchunks = 0; 75910751SGeorge.Shepherd@Sun.COM sctp->sctp_cum_oudchunks = 0; 76010751SGeorge.Shepherd@Sun.COM sctp->sctp_cum_rxtchunks = 0; 76110751SGeorge.Shepherd@Sun.COM sctp->sctp_cum_ibchunks = 0; 76210751SGeorge.Shepherd@Sun.COM sctp->sctp_cum_idchunks = 0; 76310751SGeorge.Shepherd@Sun.COM sctp->sctp_cum_iudchunks = 0; 7640Sstevel@tonic-gate 7650Sstevel@tonic-gate sctp->sctp_autoclose = 0; 7665586Skcpoon sctp->sctp_tx_adaptation_code = 0; 7670Sstevel@tonic-gate 7682283Skp158701 sctp->sctp_v6label_len = 0; 7692283Skp158701 sctp->sctp_v4label_len = 0; 7702283Skp158701 7713448Sdh155122 sctp->sctp_sctps = NULL; 7723448Sdh155122 7734691Skcpoon sctp_conn_clear(connp); 7740Sstevel@tonic-gate kmem_cache_free(sctp_conn_cache, connp); 7750Sstevel@tonic-gate } 7760Sstevel@tonic-gate 7770Sstevel@tonic-gate /* 7780Sstevel@tonic-gate * Initialize protocol control block. If a parent exists, inherit 7790Sstevel@tonic-gate * all values set through setsockopt(). 7800Sstevel@tonic-gate */ 7810Sstevel@tonic-gate static int 7820Sstevel@tonic-gate sctp_init_values(sctp_t *sctp, sctp_t *psctp, int sleep) 7830Sstevel@tonic-gate { 7840Sstevel@tonic-gate int err; 7850Sstevel@tonic-gate int cnt; 7863448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 78711042SErik.Nordmark@Sun.COM conn_t *connp; 7880Sstevel@tonic-gate 78911042SErik.Nordmark@Sun.COM connp = sctp->sctp_connp; 7900Sstevel@tonic-gate 7910Sstevel@tonic-gate sctp->sctp_nsaddrs = 0; 7920Sstevel@tonic-gate for (cnt = 0; cnt < SCTP_IPIF_HASH; cnt++) { 7930Sstevel@tonic-gate sctp->sctp_saddrs[cnt].ipif_count = 0; 7940Sstevel@tonic-gate list_create(&sctp->sctp_saddrs[cnt].sctp_ipif_list, 7950Sstevel@tonic-gate sizeof (sctp_saddr_ipif_t), offsetof(sctp_saddr_ipif_t, 7960Sstevel@tonic-gate saddr_ipif)); 7970Sstevel@tonic-gate } 79811042SErik.Nordmark@Sun.COM connp->conn_ports = 0; 7990Sstevel@tonic-gate sctp->sctp_running = B_FALSE; 8000Sstevel@tonic-gate sctp->sctp_state = SCTPS_IDLE; 8010Sstevel@tonic-gate 8020Sstevel@tonic-gate sctp->sctp_refcnt = 1; 8030Sstevel@tonic-gate 8040Sstevel@tonic-gate sctp->sctp_strikes = 0; 8050Sstevel@tonic-gate 80611066Srafael.vanoni@sun.com sctp->sctp_last_mtu_probe = ddi_get_lbolt64(); 8073448Sdh155122 sctp->sctp_mtu_probe_intvl = sctps->sctps_mtu_probe_interval; 8080Sstevel@tonic-gate 8090Sstevel@tonic-gate sctp->sctp_sack_gaps = 0; 8100Sstevel@tonic-gate sctp->sctp_sack_toggle = 2; 8110Sstevel@tonic-gate 8124691Skcpoon /* Only need to do the allocation if there is no "cached" one. */ 8134691Skcpoon if (sctp->sctp_pad_mp == NULL) { 8144691Skcpoon if (sleep == KM_SLEEP) { 8154691Skcpoon sctp->sctp_pad_mp = allocb_wait(SCTP_ALIGN, BPRI_MED, 8164691Skcpoon STR_NOSIG, NULL); 8174691Skcpoon } else { 8184691Skcpoon sctp->sctp_pad_mp = allocb(SCTP_ALIGN, BPRI_MED); 8194691Skcpoon if (sctp->sctp_pad_mp == NULL) 8204691Skcpoon return (ENOMEM); 8214691Skcpoon } 8224691Skcpoon bzero(sctp->sctp_pad_mp->b_rptr, SCTP_ALIGN); 8234691Skcpoon } 8244691Skcpoon 8250Sstevel@tonic-gate if (psctp != NULL) { 8260Sstevel@tonic-gate /* 8270Sstevel@tonic-gate * Inherit from parent 82811042SErik.Nordmark@Sun.COM * 82911042SErik.Nordmark@Sun.COM * Start by inheriting from the conn_t, including conn_ixa and 83011042SErik.Nordmark@Sun.COM * conn_xmit_ipp. 8310Sstevel@tonic-gate */ 83211042SErik.Nordmark@Sun.COM err = conn_inherit_parent(psctp->sctp_connp, connp); 83311042SErik.Nordmark@Sun.COM if (err != 0) 8344691Skcpoon goto failure; 8350Sstevel@tonic-gate 8360Sstevel@tonic-gate sctp->sctp_cookie_lifetime = psctp->sctp_cookie_lifetime; 83711042SErik.Nordmark@Sun.COM 8380Sstevel@tonic-gate sctp->sctp_cwnd_max = psctp->sctp_cwnd_max; 8390Sstevel@tonic-gate sctp->sctp_rwnd = psctp->sctp_rwnd; 840852Svi117747 sctp->sctp_irwnd = psctp->sctp_rwnd; 8413845Svi117747 sctp->sctp_pd_point = psctp->sctp_pd_point; 8420Sstevel@tonic-gate sctp->sctp_rto_max = psctp->sctp_rto_max; 84312474SGeorge.Shepherd@Sun.COM sctp->sctp_rto_max_init = psctp->sctp_rto_max_init; 8440Sstevel@tonic-gate sctp->sctp_rto_min = psctp->sctp_rto_min; 8450Sstevel@tonic-gate sctp->sctp_rto_initial = psctp->sctp_rto_initial; 8460Sstevel@tonic-gate sctp->sctp_pa_max_rxt = psctp->sctp_pa_max_rxt; 8470Sstevel@tonic-gate sctp->sctp_pp_max_rxt = psctp->sctp_pp_max_rxt; 8480Sstevel@tonic-gate sctp->sctp_max_init_rxt = psctp->sctp_max_init_rxt; 8490Sstevel@tonic-gate 8500Sstevel@tonic-gate sctp->sctp_def_stream = psctp->sctp_def_stream; 8510Sstevel@tonic-gate sctp->sctp_def_flags = psctp->sctp_def_flags; 8520Sstevel@tonic-gate sctp->sctp_def_ppid = psctp->sctp_def_ppid; 8530Sstevel@tonic-gate sctp->sctp_def_context = psctp->sctp_def_context; 8540Sstevel@tonic-gate sctp->sctp_def_timetolive = psctp->sctp_def_timetolive; 8550Sstevel@tonic-gate 8560Sstevel@tonic-gate sctp->sctp_num_istr = psctp->sctp_num_istr; 8570Sstevel@tonic-gate sctp->sctp_num_ostr = psctp->sctp_num_ostr; 8580Sstevel@tonic-gate 8590Sstevel@tonic-gate sctp->sctp_hb_interval = psctp->sctp_hb_interval; 8600Sstevel@tonic-gate sctp->sctp_autoclose = psctp->sctp_autoclose; 8615586Skcpoon sctp->sctp_tx_adaptation_code = psctp->sctp_tx_adaptation_code; 8620Sstevel@tonic-gate 8630Sstevel@tonic-gate /* xxx should be a better way to copy these flags xxx */ 8640Sstevel@tonic-gate sctp->sctp_bound_to_all = psctp->sctp_bound_to_all; 8650Sstevel@tonic-gate sctp->sctp_cansleep = psctp->sctp_cansleep; 8665586Skcpoon sctp->sctp_send_adaptation = psctp->sctp_send_adaptation; 8670Sstevel@tonic-gate sctp->sctp_ndelay = psctp->sctp_ndelay; 8680Sstevel@tonic-gate sctp->sctp_events = psctp->sctp_events; 8690Sstevel@tonic-gate } else { 8700Sstevel@tonic-gate /* 8710Sstevel@tonic-gate * Set to system defaults 8720Sstevel@tonic-gate */ 8733448Sdh155122 sctp->sctp_cookie_lifetime = 8743448Sdh155122 MSEC_TO_TICK(sctps->sctps_cookie_life); 87511042SErik.Nordmark@Sun.COM connp->conn_sndlowat = sctps->sctps_xmit_lowat; 87611042SErik.Nordmark@Sun.COM connp->conn_sndbuf = sctps->sctps_xmit_hiwat; 87711042SErik.Nordmark@Sun.COM connp->conn_rcvbuf = sctps->sctps_recv_hiwat; 87811042SErik.Nordmark@Sun.COM 8793448Sdh155122 sctp->sctp_cwnd_max = sctps->sctps_cwnd_max_; 88011042SErik.Nordmark@Sun.COM sctp->sctp_rwnd = connp->conn_rcvbuf; 881852Svi117747 sctp->sctp_irwnd = sctp->sctp_rwnd; 8823845Svi117747 sctp->sctp_pd_point = sctp->sctp_rwnd; 8833448Sdh155122 sctp->sctp_rto_max = MSEC_TO_TICK(sctps->sctps_rto_maxg); 88412474SGeorge.Shepherd@Sun.COM sctp->sctp_rto_max_init = sctp->sctp_rto_max; 8853448Sdh155122 sctp->sctp_rto_min = MSEC_TO_TICK(sctps->sctps_rto_ming); 8863448Sdh155122 sctp->sctp_rto_initial = MSEC_TO_TICK( 8873448Sdh155122 sctps->sctps_rto_initialg); 8883448Sdh155122 sctp->sctp_pa_max_rxt = sctps->sctps_pa_max_retr; 8893448Sdh155122 sctp->sctp_pp_max_rxt = sctps->sctps_pp_max_retr; 8903448Sdh155122 sctp->sctp_max_init_rxt = sctps->sctps_max_init_retr; 8910Sstevel@tonic-gate 8923448Sdh155122 sctp->sctp_num_istr = sctps->sctps_max_in_streams; 8933448Sdh155122 sctp->sctp_num_ostr = sctps->sctps_initial_out_streams; 8940Sstevel@tonic-gate 8953448Sdh155122 sctp->sctp_hb_interval = 8963448Sdh155122 MSEC_TO_TICK(sctps->sctps_heartbeat_interval); 89711042SErik.Nordmark@Sun.COM 89811042SErik.Nordmark@Sun.COM if (connp->conn_family == AF_INET) 89911042SErik.Nordmark@Sun.COM connp->conn_default_ttl = sctps->sctps_ipv4_ttl; 90011042SErik.Nordmark@Sun.COM else 90111042SErik.Nordmark@Sun.COM connp->conn_default_ttl = sctps->sctps_ipv6_hoplimit; 90211042SErik.Nordmark@Sun.COM 90311042SErik.Nordmark@Sun.COM connp->conn_xmit_ipp.ipp_unicast_hops = 90411042SErik.Nordmark@Sun.COM connp->conn_default_ttl; 90511042SErik.Nordmark@Sun.COM 90611042SErik.Nordmark@Sun.COM /* 90711042SErik.Nordmark@Sun.COM * Initialize the header template 90811042SErik.Nordmark@Sun.COM */ 90911042SErik.Nordmark@Sun.COM if ((err = sctp_build_hdrs(sctp, sleep)) != 0) { 91011042SErik.Nordmark@Sun.COM goto failure; 91111042SErik.Nordmark@Sun.COM } 9120Sstevel@tonic-gate } 91311042SErik.Nordmark@Sun.COM 9140Sstevel@tonic-gate sctp->sctp_understands_asconf = B_TRUE; 9150Sstevel@tonic-gate sctp->sctp_understands_addip = B_TRUE; 9160Sstevel@tonic-gate sctp->sctp_prsctp_aware = B_FALSE; 9170Sstevel@tonic-gate 9180Sstevel@tonic-gate sctp->sctp_connp->conn_ref = 1; 9190Sstevel@tonic-gate 9200Sstevel@tonic-gate sctp->sctp_prsctpdrop = 0; 9210Sstevel@tonic-gate sctp->sctp_msgcount = 0; 9220Sstevel@tonic-gate 9230Sstevel@tonic-gate return (0); 9244691Skcpoon 9254691Skcpoon failure: 92611042SErik.Nordmark@Sun.COM sctp_headers_free(sctp); 9274691Skcpoon return (err); 9280Sstevel@tonic-gate } 9290Sstevel@tonic-gate 9300Sstevel@tonic-gate /* 9310Sstevel@tonic-gate * Extracts the init tag from an INIT chunk and checks if it matches 9320Sstevel@tonic-gate * the sctp's verification tag. Returns 0 if it doesn't match, 1 if 9330Sstevel@tonic-gate * it does. 9340Sstevel@tonic-gate */ 9350Sstevel@tonic-gate static boolean_t 9360Sstevel@tonic-gate sctp_icmp_verf(sctp_t *sctp, sctp_hdr_t *sh, mblk_t *mp) 9370Sstevel@tonic-gate { 9380Sstevel@tonic-gate sctp_chunk_hdr_t *sch; 9390Sstevel@tonic-gate uint32_t verf, *vp; 9400Sstevel@tonic-gate 9410Sstevel@tonic-gate sch = (sctp_chunk_hdr_t *)(sh + 1); 9420Sstevel@tonic-gate vp = (uint32_t *)(sch + 1); 9430Sstevel@tonic-gate 9440Sstevel@tonic-gate /* Need at least the data chunk hdr and the first 4 bytes of INIT */ 9450Sstevel@tonic-gate if ((unsigned char *)(vp + 1) > mp->b_wptr) { 9460Sstevel@tonic-gate return (B_FALSE); 9470Sstevel@tonic-gate } 9480Sstevel@tonic-gate 9490Sstevel@tonic-gate bcopy(vp, &verf, sizeof (verf)); 9500Sstevel@tonic-gate 9510Sstevel@tonic-gate if (verf == sctp->sctp_lvtag) { 9520Sstevel@tonic-gate return (B_TRUE); 9530Sstevel@tonic-gate } 9540Sstevel@tonic-gate return (B_FALSE); 9550Sstevel@tonic-gate } 9560Sstevel@tonic-gate 9570Sstevel@tonic-gate /* 95811042SErik.Nordmark@Sun.COM * Update the SCTP state according to change of PMTU. 95911042SErik.Nordmark@Sun.COM * 96011042SErik.Nordmark@Sun.COM * Path MTU might have changed by either increase or decrease, so need to 96111042SErik.Nordmark@Sun.COM * adjust the MSS based on the value of ixa_pmtu. 96211042SErik.Nordmark@Sun.COM */ 96311042SErik.Nordmark@Sun.COM static void 96411042SErik.Nordmark@Sun.COM sctp_update_pmtu(sctp_t *sctp, sctp_faddr_t *fp, boolean_t decrease_only) 96511042SErik.Nordmark@Sun.COM { 96611042SErik.Nordmark@Sun.COM uint32_t pmtu; 96711042SErik.Nordmark@Sun.COM int32_t mss; 96811042SErik.Nordmark@Sun.COM ip_xmit_attr_t *ixa = fp->ixa; 96911042SErik.Nordmark@Sun.COM 97011042SErik.Nordmark@Sun.COM if (sctp->sctp_state < SCTPS_ESTABLISHED) 97111042SErik.Nordmark@Sun.COM return; 97211042SErik.Nordmark@Sun.COM 97311042SErik.Nordmark@Sun.COM /* 97411042SErik.Nordmark@Sun.COM * Always call ip_get_pmtu() to make sure that IP has updated 97511042SErik.Nordmark@Sun.COM * ixa_flags properly. 97611042SErik.Nordmark@Sun.COM */ 97711042SErik.Nordmark@Sun.COM pmtu = ip_get_pmtu(ixa); 97811042SErik.Nordmark@Sun.COM 97911042SErik.Nordmark@Sun.COM /* 98011042SErik.Nordmark@Sun.COM * Calculate the MSS by decreasing the PMTU by sctp_hdr_len and 98111042SErik.Nordmark@Sun.COM * IPsec overhead if applied. Make sure to use the most recent 98211042SErik.Nordmark@Sun.COM * IPsec information. 98311042SErik.Nordmark@Sun.COM */ 98411042SErik.Nordmark@Sun.COM mss = pmtu - conn_ipsec_length(sctp->sctp_connp); 98511042SErik.Nordmark@Sun.COM if (ixa->ixa_flags & IXAF_IS_IPV4) 98611042SErik.Nordmark@Sun.COM mss -= sctp->sctp_hdr_len; 98711042SErik.Nordmark@Sun.COM else 98811042SErik.Nordmark@Sun.COM mss -= sctp->sctp_hdr6_len; 98911042SErik.Nordmark@Sun.COM 99011042SErik.Nordmark@Sun.COM /* 99111042SErik.Nordmark@Sun.COM * Nothing to change, so just return. 99211042SErik.Nordmark@Sun.COM */ 99311042SErik.Nordmark@Sun.COM if (mss == fp->sfa_pmss) 99411042SErik.Nordmark@Sun.COM return; 99511042SErik.Nordmark@Sun.COM 99611042SErik.Nordmark@Sun.COM /* 99711042SErik.Nordmark@Sun.COM * Currently, for ICMP errors, only PMTU decrease is handled. 99811042SErik.Nordmark@Sun.COM */ 99911042SErik.Nordmark@Sun.COM if (mss > fp->sfa_pmss && decrease_only) 100011042SErik.Nordmark@Sun.COM return; 100111042SErik.Nordmark@Sun.COM 100211042SErik.Nordmark@Sun.COM #ifdef DEBUG 100311042SErik.Nordmark@Sun.COM (void) printf("sctp_update_pmtu mss from %d to %d\n", 100411042SErik.Nordmark@Sun.COM fp->sfa_pmss, mss); 100511042SErik.Nordmark@Sun.COM #endif 100611042SErik.Nordmark@Sun.COM DTRACE_PROBE2(sctp_update_pmtu, int32_t, fp->sfa_pmss, uint32_t, mss); 100711042SErik.Nordmark@Sun.COM 100811042SErik.Nordmark@Sun.COM /* 100911042SErik.Nordmark@Sun.COM * Update ixa_fragsize and ixa_pmtu. 101011042SErik.Nordmark@Sun.COM */ 101111042SErik.Nordmark@Sun.COM ixa->ixa_fragsize = ixa->ixa_pmtu = pmtu; 101211042SErik.Nordmark@Sun.COM 101311042SErik.Nordmark@Sun.COM /* 101411042SErik.Nordmark@Sun.COM * Make sure that sfa_pmss is a multiple of 101511042SErik.Nordmark@Sun.COM * SCTP_ALIGN. 101611042SErik.Nordmark@Sun.COM */ 101711042SErik.Nordmark@Sun.COM fp->sfa_pmss = mss & ~(SCTP_ALIGN - 1); 101811042SErik.Nordmark@Sun.COM fp->pmtu_discovered = 1; 101911042SErik.Nordmark@Sun.COM 102011042SErik.Nordmark@Sun.COM #ifdef notyet 102111042SErik.Nordmark@Sun.COM if (mss < sctp->sctp_sctps->sctps_mss_min) 102211042SErik.Nordmark@Sun.COM ixa->ixa_flags |= IXAF_PMTU_TOO_SMALL; 102311042SErik.Nordmark@Sun.COM #endif 102411042SErik.Nordmark@Sun.COM if (ixa->ixa_flags & IXAF_PMTU_TOO_SMALL) 102511042SErik.Nordmark@Sun.COM ixa->ixa_flags &= ~(IXAF_DONTFRAG | IXAF_PMTU_IPV4_DF); 102611042SErik.Nordmark@Sun.COM 102711042SErik.Nordmark@Sun.COM /* 102811042SErik.Nordmark@Sun.COM * If below the min size then ip_get_pmtu cleared IXAF_PMTU_IPV4_DF. 102911042SErik.Nordmark@Sun.COM * Make sure to clear IXAF_DONTFRAG, which is used by IP to decide 103011042SErik.Nordmark@Sun.COM * whether to fragment the packet. 103111042SErik.Nordmark@Sun.COM */ 103211042SErik.Nordmark@Sun.COM if (ixa->ixa_flags & IXAF_IS_IPV4) { 103311042SErik.Nordmark@Sun.COM if (!(ixa->ixa_flags & IXAF_PMTU_IPV4_DF)) { 103411042SErik.Nordmark@Sun.COM fp->df = B_FALSE; 103511042SErik.Nordmark@Sun.COM if (fp == sctp->sctp_current) { 103611042SErik.Nordmark@Sun.COM sctp->sctp_ipha-> 103711042SErik.Nordmark@Sun.COM ipha_fragment_offset_and_flags = 0; 103811042SErik.Nordmark@Sun.COM } 103911042SErik.Nordmark@Sun.COM } 104011042SErik.Nordmark@Sun.COM } 104111042SErik.Nordmark@Sun.COM } 104211042SErik.Nordmark@Sun.COM 104311042SErik.Nordmark@Sun.COM /* 104411042SErik.Nordmark@Sun.COM * Notify function registered with ip_xmit_attr_t. It's called in the context 104511042SErik.Nordmark@Sun.COM * of conn_ip_output so it's safe to update the SCTP state. 104611042SErik.Nordmark@Sun.COM * Currently only used for pmtu changes. 104711042SErik.Nordmark@Sun.COM */ 104811042SErik.Nordmark@Sun.COM /* ARGSUSED1 */ 104911042SErik.Nordmark@Sun.COM static void 105011042SErik.Nordmark@Sun.COM sctp_notify(void *arg, ip_xmit_attr_t *ixa, ixa_notify_type_t ntype, 105111042SErik.Nordmark@Sun.COM ixa_notify_arg_t narg) 105211042SErik.Nordmark@Sun.COM { 105311042SErik.Nordmark@Sun.COM sctp_t *sctp = (sctp_t *)arg; 105411042SErik.Nordmark@Sun.COM sctp_faddr_t *fp; 105511042SErik.Nordmark@Sun.COM 105611042SErik.Nordmark@Sun.COM switch (ntype) { 105711042SErik.Nordmark@Sun.COM case IXAN_PMTU: 105811042SErik.Nordmark@Sun.COM /* Find the faddr based on the ip_xmit_attr_t pointer */ 105911042SErik.Nordmark@Sun.COM for (fp = sctp->sctp_faddrs; fp != NULL; fp = fp->next) { 106011042SErik.Nordmark@Sun.COM if (fp->ixa == ixa) 106111042SErik.Nordmark@Sun.COM break; 106211042SErik.Nordmark@Sun.COM } 106311042SErik.Nordmark@Sun.COM if (fp != NULL) 106411042SErik.Nordmark@Sun.COM sctp_update_pmtu(sctp, fp, B_FALSE); 106511042SErik.Nordmark@Sun.COM break; 106611042SErik.Nordmark@Sun.COM default: 106711042SErik.Nordmark@Sun.COM break; 106811042SErik.Nordmark@Sun.COM } 106911042SErik.Nordmark@Sun.COM } 107011042SErik.Nordmark@Sun.COM 107111042SErik.Nordmark@Sun.COM /* 10720Sstevel@tonic-gate * sctp_icmp_error is called by sctp_input() to process ICMP error messages 107311042SErik.Nordmark@Sun.COM * passed up by IP. We need to find a sctp_t 10740Sstevel@tonic-gate * that corresponds to the returned datagram. Passes the message back in on 10750Sstevel@tonic-gate * the correct queue once it has located the connection. 10760Sstevel@tonic-gate * Assumes that IP has pulled up everything up to and including 10770Sstevel@tonic-gate * the ICMP header. 10780Sstevel@tonic-gate */ 10790Sstevel@tonic-gate void 10800Sstevel@tonic-gate sctp_icmp_error(sctp_t *sctp, mblk_t *mp) 10810Sstevel@tonic-gate { 10820Sstevel@tonic-gate icmph_t *icmph; 10830Sstevel@tonic-gate ipha_t *ipha; 10840Sstevel@tonic-gate int iph_hdr_length; 10850Sstevel@tonic-gate sctp_hdr_t *sctph; 10860Sstevel@tonic-gate in6_addr_t dst; 10870Sstevel@tonic-gate sctp_faddr_t *fp; 10883448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 10890Sstevel@tonic-gate 10901676Sjpk dprint(1, ("sctp_icmp_error: sctp=%p, mp=%p\n", (void *)sctp, 10911676Sjpk (void *)mp)); 10920Sstevel@tonic-gate 10930Sstevel@tonic-gate ipha = (ipha_t *)mp->b_rptr; 10940Sstevel@tonic-gate if (IPH_HDR_VERSION(ipha) != IPV4_VERSION) { 10950Sstevel@tonic-gate ASSERT(IPH_HDR_VERSION(ipha) == IPV6_VERSION); 109611042SErik.Nordmark@Sun.COM sctp_icmp_error_ipv6(sctp, mp); 10970Sstevel@tonic-gate return; 10980Sstevel@tonic-gate } 10990Sstevel@tonic-gate 110010828SGeorge.Shepherd@Sun.COM /* account for the ip hdr from the icmp message */ 11010Sstevel@tonic-gate iph_hdr_length = IPH_HDR_LENGTH(ipha); 11020Sstevel@tonic-gate icmph = (icmph_t *)&mp->b_rptr[iph_hdr_length]; 110310828SGeorge.Shepherd@Sun.COM /* now the ip hdr of message resulting in this icmp */ 11040Sstevel@tonic-gate ipha = (ipha_t *)&icmph[1]; 11050Sstevel@tonic-gate iph_hdr_length = IPH_HDR_LENGTH(ipha); 11060Sstevel@tonic-gate sctph = (sctp_hdr_t *)((char *)ipha + iph_hdr_length); 110710828SGeorge.Shepherd@Sun.COM /* first_mp must expose the full sctp header. */ 11080Sstevel@tonic-gate if ((uchar_t *)(sctph + 1) >= mp->b_wptr) { 11090Sstevel@tonic-gate /* not enough data for SCTP header */ 111011042SErik.Nordmark@Sun.COM freemsg(mp); 11110Sstevel@tonic-gate return; 11120Sstevel@tonic-gate } 11130Sstevel@tonic-gate 11140Sstevel@tonic-gate switch (icmph->icmph_type) { 11150Sstevel@tonic-gate case ICMP_DEST_UNREACHABLE: 11160Sstevel@tonic-gate switch (icmph->icmph_code) { 11170Sstevel@tonic-gate case ICMP_FRAGMENTATION_NEEDED: 11180Sstevel@tonic-gate /* 11190Sstevel@tonic-gate * Reduce the MSS based on the new MTU. This will 11200Sstevel@tonic-gate * eliminate any fragmentation locally. 11210Sstevel@tonic-gate * N.B. There may well be some funny side-effects on 11220Sstevel@tonic-gate * the local send policy and the remote receive policy. 11230Sstevel@tonic-gate * Pending further research, we provide 11240Sstevel@tonic-gate * sctp_ignore_path_mtu just in case this proves 11250Sstevel@tonic-gate * disastrous somewhere. 11260Sstevel@tonic-gate * 11270Sstevel@tonic-gate * After updating the MSS, retransmit part of the 11280Sstevel@tonic-gate * dropped segment using the new mss by calling 11290Sstevel@tonic-gate * sctp_wput_slow(). Need to adjust all those 11300Sstevel@tonic-gate * params to make sure sctp_wput_slow() work properly. 11310Sstevel@tonic-gate */ 11323448Sdh155122 if (sctps->sctps_ignore_path_mtu) 11330Sstevel@tonic-gate break; 11340Sstevel@tonic-gate 11350Sstevel@tonic-gate /* find the offending faddr */ 11360Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(ipha->ipha_dst, &dst); 11370Sstevel@tonic-gate fp = sctp_lookup_faddr(sctp, &dst); 11380Sstevel@tonic-gate if (fp == NULL) { 11390Sstevel@tonic-gate break; 11400Sstevel@tonic-gate } 114111042SErik.Nordmark@Sun.COM sctp_update_pmtu(sctp, fp, B_TRUE); 114210828SGeorge.Shepherd@Sun.COM /* 114310828SGeorge.Shepherd@Sun.COM * It is possible, even likely that a fast retransmit 114410828SGeorge.Shepherd@Sun.COM * attempt has been dropped by ip as a result of this 114510828SGeorge.Shepherd@Sun.COM * error, retransmission bundles as much as possible. 114610828SGeorge.Shepherd@Sun.COM * A retransmit here prevents significant delays waiting 114710828SGeorge.Shepherd@Sun.COM * on the timer. Analogous to behaviour of TCP after 114810828SGeorge.Shepherd@Sun.COM * ICMP too big. 114910828SGeorge.Shepherd@Sun.COM */ 115010828SGeorge.Shepherd@Sun.COM sctp_rexmit(sctp, fp); 11510Sstevel@tonic-gate break; 11520Sstevel@tonic-gate case ICMP_PORT_UNREACHABLE: 11530Sstevel@tonic-gate case ICMP_PROTOCOL_UNREACHABLE: 11540Sstevel@tonic-gate switch (sctp->sctp_state) { 11550Sstevel@tonic-gate case SCTPS_COOKIE_WAIT: 11560Sstevel@tonic-gate case SCTPS_COOKIE_ECHOED: 11570Sstevel@tonic-gate /* make sure the verification tag matches */ 11580Sstevel@tonic-gate if (!sctp_icmp_verf(sctp, sctph, mp)) { 11590Sstevel@tonic-gate break; 11600Sstevel@tonic-gate } 1161*12869SKacheong.Poon@Sun.COM SCTPS_BUMP_MIB(sctps, sctpAborted); 11623314Skcpoon sctp_assoc_event(sctp, SCTP_CANT_STR_ASSOC, 0, 11633314Skcpoon NULL); 11640Sstevel@tonic-gate sctp_clean_death(sctp, ECONNREFUSED); 11650Sstevel@tonic-gate break; 11660Sstevel@tonic-gate } 11670Sstevel@tonic-gate break; 11680Sstevel@tonic-gate case ICMP_HOST_UNREACHABLE: 11690Sstevel@tonic-gate case ICMP_NET_UNREACHABLE: 11700Sstevel@tonic-gate /* Record the error in case we finally time out. */ 11710Sstevel@tonic-gate sctp->sctp_client_errno = (icmph->icmph_code == 11720Sstevel@tonic-gate ICMP_HOST_UNREACHABLE) ? EHOSTUNREACH : ENETUNREACH; 11730Sstevel@tonic-gate break; 11740Sstevel@tonic-gate default: 11750Sstevel@tonic-gate break; 11760Sstevel@tonic-gate } 11770Sstevel@tonic-gate break; 11780Sstevel@tonic-gate case ICMP_SOURCE_QUENCH: { 11790Sstevel@tonic-gate /* Reduce the sending rate as if we got a retransmit timeout */ 11800Sstevel@tonic-gate break; 11810Sstevel@tonic-gate } 11820Sstevel@tonic-gate } 118311042SErik.Nordmark@Sun.COM freemsg(mp); 11840Sstevel@tonic-gate } 11850Sstevel@tonic-gate 11860Sstevel@tonic-gate /* 11870Sstevel@tonic-gate * sctp_icmp_error_ipv6() is called by sctp_icmp_error() to process ICMPv6 11880Sstevel@tonic-gate * error messages passed up by IP. 11890Sstevel@tonic-gate * Assumes that IP has pulled up all the extension headers as well 11900Sstevel@tonic-gate * as the ICMPv6 header. 11910Sstevel@tonic-gate */ 11920Sstevel@tonic-gate static void 11930Sstevel@tonic-gate sctp_icmp_error_ipv6(sctp_t *sctp, mblk_t *mp) 11940Sstevel@tonic-gate { 11950Sstevel@tonic-gate icmp6_t *icmp6; 11960Sstevel@tonic-gate ip6_t *ip6h; 11970Sstevel@tonic-gate uint16_t iph_hdr_length; 11980Sstevel@tonic-gate sctp_hdr_t *sctpha; 11990Sstevel@tonic-gate uint8_t *nexthdrp; 12000Sstevel@tonic-gate sctp_faddr_t *fp; 12013448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 12020Sstevel@tonic-gate 12030Sstevel@tonic-gate ip6h = (ip6_t *)mp->b_rptr; 12040Sstevel@tonic-gate iph_hdr_length = (ip6h->ip6_nxt != IPPROTO_SCTP) ? 12050Sstevel@tonic-gate ip_hdr_length_v6(mp, ip6h) : IPV6_HDR_LEN; 12060Sstevel@tonic-gate 12070Sstevel@tonic-gate icmp6 = (icmp6_t *)&mp->b_rptr[iph_hdr_length]; 12080Sstevel@tonic-gate ip6h = (ip6_t *)&icmp6[1]; 12090Sstevel@tonic-gate if (!ip_hdr_length_nexthdr_v6(mp, ip6h, &iph_hdr_length, &nexthdrp)) { 12100Sstevel@tonic-gate freemsg(mp); 12110Sstevel@tonic-gate return; 12120Sstevel@tonic-gate } 12130Sstevel@tonic-gate ASSERT(*nexthdrp == IPPROTO_SCTP); 12140Sstevel@tonic-gate 12150Sstevel@tonic-gate /* XXX need ifindex to find connection */ 12160Sstevel@tonic-gate sctpha = (sctp_hdr_t *)((char *)ip6h + iph_hdr_length); 12170Sstevel@tonic-gate if ((uchar_t *)sctpha >= mp->b_wptr) { 12180Sstevel@tonic-gate /* not enough data for SCTP header */ 12190Sstevel@tonic-gate freemsg(mp); 12200Sstevel@tonic-gate return; 12210Sstevel@tonic-gate } 12220Sstevel@tonic-gate switch (icmp6->icmp6_type) { 12230Sstevel@tonic-gate case ICMP6_PACKET_TOO_BIG: 12240Sstevel@tonic-gate /* 12250Sstevel@tonic-gate * Reduce the MSS based on the new MTU. This will 12260Sstevel@tonic-gate * eliminate any fragmentation locally. 12270Sstevel@tonic-gate * N.B. There may well be some funny side-effects on 12280Sstevel@tonic-gate * the local send policy and the remote receive policy. 12290Sstevel@tonic-gate * Pending further research, we provide 12300Sstevel@tonic-gate * sctp_ignore_path_mtu just in case this proves 12310Sstevel@tonic-gate * disastrous somewhere. 12320Sstevel@tonic-gate * 12330Sstevel@tonic-gate * After updating the MSS, retransmit part of the 12340Sstevel@tonic-gate * dropped segment using the new mss by calling 12350Sstevel@tonic-gate * sctp_wput_slow(). Need to adjust all those 12360Sstevel@tonic-gate * params to make sure sctp_wput_slow() work properly. 12370Sstevel@tonic-gate */ 12383448Sdh155122 if (sctps->sctps_ignore_path_mtu) 12390Sstevel@tonic-gate break; 12400Sstevel@tonic-gate 12410Sstevel@tonic-gate /* find the offending faddr */ 12420Sstevel@tonic-gate fp = sctp_lookup_faddr(sctp, &ip6h->ip6_dst); 12430Sstevel@tonic-gate if (fp == NULL) { 12440Sstevel@tonic-gate break; 12450Sstevel@tonic-gate } 12460Sstevel@tonic-gate 124711042SErik.Nordmark@Sun.COM sctp_update_pmtu(sctp, fp, B_TRUE); 124811042SErik.Nordmark@Sun.COM /* 124911042SErik.Nordmark@Sun.COM * It is possible, even likely that a fast retransmit 125011042SErik.Nordmark@Sun.COM * attempt has been dropped by ip as a result of this 125111042SErik.Nordmark@Sun.COM * error, retransmission bundles as much as possible. 125211042SErik.Nordmark@Sun.COM * A retransmit here prevents significant delays waiting 125311042SErik.Nordmark@Sun.COM * on the timer. Analogous to behaviour of TCP after 125411042SErik.Nordmark@Sun.COM * ICMP too big. 125511042SErik.Nordmark@Sun.COM */ 125611042SErik.Nordmark@Sun.COM sctp_rexmit(sctp, fp); 12570Sstevel@tonic-gate break; 12580Sstevel@tonic-gate 12590Sstevel@tonic-gate case ICMP6_DST_UNREACH: 12600Sstevel@tonic-gate switch (icmp6->icmp6_code) { 12610Sstevel@tonic-gate case ICMP6_DST_UNREACH_NOPORT: 12620Sstevel@tonic-gate /* make sure the verification tag matches */ 12630Sstevel@tonic-gate if (!sctp_icmp_verf(sctp, sctpha, mp)) { 12640Sstevel@tonic-gate break; 12650Sstevel@tonic-gate } 12660Sstevel@tonic-gate if (sctp->sctp_state == SCTPS_COOKIE_WAIT || 12670Sstevel@tonic-gate sctp->sctp_state == SCTPS_COOKIE_ECHOED) { 1268*12869SKacheong.Poon@Sun.COM SCTPS_BUMP_MIB(sctps, sctpAborted); 12693314Skcpoon sctp_assoc_event(sctp, SCTP_CANT_STR_ASSOC, 0, 12703314Skcpoon NULL); 12710Sstevel@tonic-gate sctp_clean_death(sctp, ECONNREFUSED); 12720Sstevel@tonic-gate } 12730Sstevel@tonic-gate break; 12740Sstevel@tonic-gate 12750Sstevel@tonic-gate case ICMP6_DST_UNREACH_ADMIN: 12760Sstevel@tonic-gate case ICMP6_DST_UNREACH_NOROUTE: 12770Sstevel@tonic-gate case ICMP6_DST_UNREACH_NOTNEIGHBOR: 12780Sstevel@tonic-gate case ICMP6_DST_UNREACH_ADDR: 12790Sstevel@tonic-gate /* Record the error in case we finally time out. */ 12800Sstevel@tonic-gate sctp->sctp_client_errno = EHOSTUNREACH; 12810Sstevel@tonic-gate break; 12820Sstevel@tonic-gate default: 12830Sstevel@tonic-gate break; 12840Sstevel@tonic-gate } 12850Sstevel@tonic-gate break; 12860Sstevel@tonic-gate 12870Sstevel@tonic-gate case ICMP6_PARAM_PROB: 12880Sstevel@tonic-gate /* If this corresponds to an ICMP_PROTOCOL_UNREACHABLE */ 12890Sstevel@tonic-gate if (icmp6->icmp6_code == ICMP6_PARAMPROB_NEXTHEADER && 12900Sstevel@tonic-gate (uchar_t *)ip6h + icmp6->icmp6_pptr == 12910Sstevel@tonic-gate (uchar_t *)nexthdrp) { 12920Sstevel@tonic-gate /* make sure the verification tag matches */ 12930Sstevel@tonic-gate if (!sctp_icmp_verf(sctp, sctpha, mp)) { 12940Sstevel@tonic-gate break; 12950Sstevel@tonic-gate } 12960Sstevel@tonic-gate if (sctp->sctp_state == SCTPS_COOKIE_WAIT) { 1297*12869SKacheong.Poon@Sun.COM SCTPS_BUMP_MIB(sctps, sctpAborted); 12983314Skcpoon sctp_assoc_event(sctp, SCTP_CANT_STR_ASSOC, 0, 12993314Skcpoon NULL); 13000Sstevel@tonic-gate sctp_clean_death(sctp, ECONNREFUSED); 13010Sstevel@tonic-gate } 13020Sstevel@tonic-gate break; 13030Sstevel@tonic-gate } 13040Sstevel@tonic-gate break; 13050Sstevel@tonic-gate 13060Sstevel@tonic-gate case ICMP6_TIME_EXCEEDED: 13070Sstevel@tonic-gate default: 13080Sstevel@tonic-gate break; 13090Sstevel@tonic-gate } 13100Sstevel@tonic-gate freemsg(mp); 13110Sstevel@tonic-gate } 13120Sstevel@tonic-gate 13130Sstevel@tonic-gate /* 13140Sstevel@tonic-gate * Called by sockfs to create a new sctp instance. 13150Sstevel@tonic-gate * 13160Sstevel@tonic-gate * If parent pointer is passed in, inherit settings from it. 13170Sstevel@tonic-gate */ 13180Sstevel@tonic-gate sctp_t * 131911042SErik.Nordmark@Sun.COM sctp_create(void *ulpd, sctp_t *parent, int family, int type, int flags, 13208348SEric.Yu@Sun.COM sock_upcalls_t *upcalls, sctp_sockbuf_limits_t *sbl, 13210Sstevel@tonic-gate cred_t *credp) 13220Sstevel@tonic-gate { 13230Sstevel@tonic-gate sctp_t *sctp, *psctp; 132411042SErik.Nordmark@Sun.COM conn_t *connp; 13250Sstevel@tonic-gate mblk_t *ack_mp, *hb_mp; 13260Sstevel@tonic-gate int sleep = flags & SCTP_CAN_BLOCK ? KM_SLEEP : KM_NOSLEEP; 13273448Sdh155122 zoneid_t zoneid; 13283448Sdh155122 sctp_stack_t *sctps; 13290Sstevel@tonic-gate 13300Sstevel@tonic-gate /* User must supply a credential. */ 13310Sstevel@tonic-gate if (credp == NULL) 13320Sstevel@tonic-gate return (NULL); 13330Sstevel@tonic-gate 13343448Sdh155122 psctp = (sctp_t *)parent; 13353448Sdh155122 if (psctp != NULL) { 13363448Sdh155122 sctps = psctp->sctp_sctps; 13373448Sdh155122 /* Increase here to have common decrease at end */ 13383448Sdh155122 netstack_hold(sctps->sctps_netstack); 1339*12869SKacheong.Poon@Sun.COM ASSERT(sctps->sctps_recvq_tq_list_cur_sz > 0); 13403448Sdh155122 } else { 13413448Sdh155122 netstack_t *ns; 13423448Sdh155122 13433448Sdh155122 ns = netstack_find_by_cred(credp); 13443448Sdh155122 sctps = ns->netstack_sctp; 1345*12869SKacheong.Poon@Sun.COM /* 1346*12869SKacheong.Poon@Sun.COM * Check if the receive queue taskq for this sctp_stack_t has 1347*12869SKacheong.Poon@Sun.COM * been set up. 1348*12869SKacheong.Poon@Sun.COM */ 1349*12869SKacheong.Poon@Sun.COM if (sctps->sctps_recvq_tq_list_cur_sz == 0) 1350*12869SKacheong.Poon@Sun.COM sctp_rq_tq_init(sctps); 13513448Sdh155122 13523448Sdh155122 /* 13533448Sdh155122 * For exclusive stacks we set the zoneid to zero 13543448Sdh155122 * to make SCTP operate as if in the global zone. 13553448Sdh155122 */ 13563448Sdh155122 if (sctps->sctps_netstack->netstack_stackid != 13573448Sdh155122 GLOBAL_NETSTACKID) 13583448Sdh155122 zoneid = GLOBAL_ZONEID; 13593448Sdh155122 else 13603448Sdh155122 zoneid = crgetzoneid(credp); 13613448Sdh155122 } 136211042SErik.Nordmark@Sun.COM if ((connp = ipcl_conn_create(IPCL_SCTPCONN, sleep, 13634505Skcpoon sctps->sctps_netstack)) == NULL) { 13643448Sdh155122 netstack_rele(sctps->sctps_netstack); 13653448Sdh155122 SCTP_KSTAT(sctps, sctp_conn_create); 13660Sstevel@tonic-gate return (NULL); 13671735Skcpoon } 13683448Sdh155122 /* 13693448Sdh155122 * ipcl_conn_create did a netstack_hold. Undo the hold that was 13703448Sdh155122 * done at top of sctp_create. 13713448Sdh155122 */ 13723448Sdh155122 netstack_rele(sctps->sctps_netstack); 137311042SErik.Nordmark@Sun.COM sctp = CONN2SCTP(connp); 13743448Sdh155122 sctp->sctp_sctps = sctps; 13751676Sjpk 13764691Skcpoon if ((ack_mp = sctp_timer_alloc(sctp, sctp_ack_timer, sleep)) == NULL || 13774691Skcpoon (hb_mp = sctp_timer_alloc(sctp, sctp_heartbeat_timer, 13784691Skcpoon sleep)) == NULL) { 13790Sstevel@tonic-gate if (ack_mp != NULL) 13800Sstevel@tonic-gate freeb(ack_mp); 138111042SErik.Nordmark@Sun.COM sctp_conn_clear(connp); 13823448Sdh155122 sctp->sctp_sctps = NULL; 138311042SErik.Nordmark@Sun.COM kmem_cache_free(sctp_conn_cache, connp); 13840Sstevel@tonic-gate return (NULL); 13850Sstevel@tonic-gate } 13860Sstevel@tonic-gate 13870Sstevel@tonic-gate sctp->sctp_ack_mp = ack_mp; 13880Sstevel@tonic-gate sctp->sctp_heartbeat_mp = hb_mp; 13890Sstevel@tonic-gate 139011042SErik.Nordmark@Sun.COM /* 139111042SErik.Nordmark@Sun.COM * Have conn_ip_output drop packets should our outer source 139211042SErik.Nordmark@Sun.COM * go invalid, and tell us about mtu changes. 139311042SErik.Nordmark@Sun.COM */ 139411042SErik.Nordmark@Sun.COM connp->conn_ixa->ixa_flags |= IXAF_SET_ULP_CKSUM | IXAF_VERIFY_SOURCE | 139511042SErik.Nordmark@Sun.COM IXAF_VERIFY_PMTU; 139611042SErik.Nordmark@Sun.COM connp->conn_family = family; 139711042SErik.Nordmark@Sun.COM connp->conn_so_type = type; 13980Sstevel@tonic-gate 13990Sstevel@tonic-gate if (sctp_init_values(sctp, psctp, sleep) != 0) { 14000Sstevel@tonic-gate freeb(ack_mp); 14010Sstevel@tonic-gate freeb(hb_mp); 140211042SErik.Nordmark@Sun.COM sctp_conn_clear(connp); 14033448Sdh155122 sctp->sctp_sctps = NULL; 140411042SErik.Nordmark@Sun.COM kmem_cache_free(sctp_conn_cache, connp); 14050Sstevel@tonic-gate return (NULL); 14060Sstevel@tonic-gate } 14070Sstevel@tonic-gate sctp->sctp_cansleep = ((flags & SCTP_CAN_BLOCK) == SCTP_CAN_BLOCK); 14080Sstevel@tonic-gate 14093448Sdh155122 sctp->sctp_mss = sctps->sctps_initial_mtu - ((family == AF_INET6) ? 14104505Skcpoon sctp->sctp_hdr6_len : sctp->sctp_hdr_len); 14110Sstevel@tonic-gate 14120Sstevel@tonic-gate if (psctp != NULL) { 141311042SErik.Nordmark@Sun.COM conn_t *pconnp = psctp->sctp_connp; 141411042SErik.Nordmark@Sun.COM 14150Sstevel@tonic-gate RUN_SCTP(psctp); 14160Sstevel@tonic-gate /* 14170Sstevel@tonic-gate * Inherit local address list, local port. Parent is either 14180Sstevel@tonic-gate * in SCTPS_BOUND, or SCTPS_LISTEN state. 14190Sstevel@tonic-gate */ 14200Sstevel@tonic-gate ASSERT((psctp->sctp_state == SCTPS_BOUND) || 14210Sstevel@tonic-gate (psctp->sctp_state == SCTPS_LISTEN)); 14220Sstevel@tonic-gate if (sctp_dup_saddrs(psctp, sctp, sleep)) { 14230Sstevel@tonic-gate WAKE_SCTP(psctp); 14240Sstevel@tonic-gate freeb(ack_mp); 14250Sstevel@tonic-gate freeb(hb_mp); 14260Sstevel@tonic-gate sctp_headers_free(sctp); 142711042SErik.Nordmark@Sun.COM sctp_conn_clear(connp); 14283448Sdh155122 sctp->sctp_sctps = NULL; 142911042SErik.Nordmark@Sun.COM kmem_cache_free(sctp_conn_cache, connp); 14300Sstevel@tonic-gate return (NULL); 14310Sstevel@tonic-gate } 14320Sstevel@tonic-gate 14330Sstevel@tonic-gate /* 14340Sstevel@tonic-gate * If the parent is specified, it'll be immediatelly 14350Sstevel@tonic-gate * followed by sctp_connect(). So don't add this guy to 14360Sstevel@tonic-gate * bind hash. 14370Sstevel@tonic-gate */ 143811042SErik.Nordmark@Sun.COM connp->conn_lport = pconnp->conn_lport; 14390Sstevel@tonic-gate sctp->sctp_state = SCTPS_BOUND; 14400Sstevel@tonic-gate WAKE_SCTP(psctp); 14410Sstevel@tonic-gate } else { 144211042SErik.Nordmark@Sun.COM ASSERT(connp->conn_cred == NULL); 144311042SErik.Nordmark@Sun.COM connp->conn_zoneid = zoneid; 144411042SErik.Nordmark@Sun.COM /* 144511042SErik.Nordmark@Sun.COM * conn_allzones can not be set this early, hence 144611042SErik.Nordmark@Sun.COM * no IPCL_ZONEID 144711042SErik.Nordmark@Sun.COM */ 144811042SErik.Nordmark@Sun.COM connp->conn_ixa->ixa_zoneid = zoneid; 144911066Srafael.vanoni@sun.com connp->conn_open_time = ddi_get_lbolt64(); 145011042SErik.Nordmark@Sun.COM connp->conn_cred = credp; 145111042SErik.Nordmark@Sun.COM crhold(credp); 145211042SErik.Nordmark@Sun.COM connp->conn_cpid = curproc->p_pid; 14538778SErik.Nordmark@Sun.COM 145411042SErik.Nordmark@Sun.COM /* 145511042SErik.Nordmark@Sun.COM * If the caller has the process-wide flag set, then default to 145611042SErik.Nordmark@Sun.COM * MAC exempt mode. This allows read-down to unlabeled hosts. 145711042SErik.Nordmark@Sun.COM */ 145811042SErik.Nordmark@Sun.COM if (getpflags(NET_MAC_AWARE, credp) != 0) 145911042SErik.Nordmark@Sun.COM connp->conn_mac_mode = CONN_MAC_AWARE; 14600Sstevel@tonic-gate 146111042SErik.Nordmark@Sun.COM connp->conn_zone_is_global = 146211042SErik.Nordmark@Sun.COM (crgetzoneid(credp) == GLOBAL_ZONEID); 146311042SErik.Nordmark@Sun.COM } 14641676Sjpk 14650Sstevel@tonic-gate /* Initialize SCTP instance values, our verf tag must never be 0 */ 14660Sstevel@tonic-gate (void) random_get_pseudo_bytes((uint8_t *)&sctp->sctp_lvtag, 14670Sstevel@tonic-gate sizeof (sctp->sctp_lvtag)); 14680Sstevel@tonic-gate if (sctp->sctp_lvtag == 0) 14690Sstevel@tonic-gate sctp->sctp_lvtag = (uint32_t)gethrtime(); 14700Sstevel@tonic-gate ASSERT(sctp->sctp_lvtag != 0); 14710Sstevel@tonic-gate 14720Sstevel@tonic-gate sctp->sctp_ltsn = sctp->sctp_lvtag + 1; 14730Sstevel@tonic-gate sctp->sctp_lcsn = sctp->sctp_ltsn; 14740Sstevel@tonic-gate sctp->sctp_recovery_tsn = sctp->sctp_lastack_rxd = sctp->sctp_ltsn - 1; 14750Sstevel@tonic-gate sctp->sctp_adv_pap = sctp->sctp_lastack_rxd; 14760Sstevel@tonic-gate 14770Sstevel@tonic-gate /* Information required by upper layer */ 147811042SErik.Nordmark@Sun.COM ASSERT(ulpd != NULL); 147911042SErik.Nordmark@Sun.COM sctp->sctp_ulpd = ulpd; 14800Sstevel@tonic-gate 148111042SErik.Nordmark@Sun.COM ASSERT(upcalls != NULL); 148211042SErik.Nordmark@Sun.COM sctp->sctp_upcalls = upcalls; 148311042SErik.Nordmark@Sun.COM ASSERT(sbl != NULL); 148411042SErik.Nordmark@Sun.COM /* Fill in the socket buffer limits for sctpsockfs */ 148511042SErik.Nordmark@Sun.COM sbl->sbl_txlowat = connp->conn_sndlowat; 148611042SErik.Nordmark@Sun.COM sbl->sbl_txbuf = connp->conn_sndbuf; 148711042SErik.Nordmark@Sun.COM sbl->sbl_rxbuf = sctp->sctp_rwnd; 148811042SErik.Nordmark@Sun.COM sbl->sbl_rxlowat = SCTP_RECV_LOWATER; 14890Sstevel@tonic-gate 14900Sstevel@tonic-gate /* Insert this in the global list. */ 14913448Sdh155122 SCTP_LINK(sctp, sctps); 14920Sstevel@tonic-gate 14930Sstevel@tonic-gate return (sctp); 14940Sstevel@tonic-gate } 14950Sstevel@tonic-gate 14963448Sdh155122 /* Run at module load time */ 14973448Sdh155122 void 14983448Sdh155122 sctp_ddi_g_init(void) 14993448Sdh155122 { 15000Sstevel@tonic-gate /* Create sctp_t/conn_t cache */ 15010Sstevel@tonic-gate sctp_conn_cache_init(); 15020Sstevel@tonic-gate 15030Sstevel@tonic-gate /* Create the faddr cache */ 15040Sstevel@tonic-gate sctp_faddr_init(); 15050Sstevel@tonic-gate 15060Sstevel@tonic-gate /* Create the sets cache */ 15070Sstevel@tonic-gate sctp_sets_init(); 15080Sstevel@tonic-gate 15090Sstevel@tonic-gate /* Create the PR-SCTP sets cache */ 15100Sstevel@tonic-gate sctp_ftsn_sets_init(); 15110Sstevel@tonic-gate 15120Sstevel@tonic-gate /* Initialize tables used for CRC calculation */ 15130Sstevel@tonic-gate sctp_crc32_init(); 15140Sstevel@tonic-gate 15153448Sdh155122 /* 15163448Sdh155122 * We want to be informed each time a stack is created or 15173448Sdh155122 * destroyed in the kernel, so we can maintain the 15183448Sdh155122 * set of sctp_stack_t's. 15193448Sdh155122 */ 152011042SErik.Nordmark@Sun.COM netstack_register(NS_SCTP, sctp_stack_init, NULL, sctp_stack_fini); 15210Sstevel@tonic-gate } 15220Sstevel@tonic-gate 15233448Sdh155122 static void * 15243448Sdh155122 sctp_stack_init(netstackid_t stackid, netstack_t *ns) 15250Sstevel@tonic-gate { 15263448Sdh155122 sctp_stack_t *sctps; 152712016SGirish.Moodalbail@Sun.COM size_t arrsz; 1528*12869SKacheong.Poon@Sun.COM int i; 15293448Sdh155122 15303448Sdh155122 sctps = kmem_zalloc(sizeof (*sctps), KM_SLEEP); 15313448Sdh155122 sctps->sctps_netstack = ns; 15323448Sdh155122 15333448Sdh155122 /* Initialize locks */ 15343448Sdh155122 mutex_init(&sctps->sctps_g_lock, NULL, MUTEX_DEFAULT, NULL); 15353448Sdh155122 mutex_init(&sctps->sctps_epriv_port_lock, NULL, MUTEX_DEFAULT, NULL); 15363448Sdh155122 sctps->sctps_g_num_epriv_ports = SCTP_NUM_EPRIV_PORTS; 153712016SGirish.Moodalbail@Sun.COM sctps->sctps_g_epriv_ports[0] = ULP_DEF_EPRIV_PORT1; 153812016SGirish.Moodalbail@Sun.COM sctps->sctps_g_epriv_ports[1] = ULP_DEF_EPRIV_PORT2; 15393448Sdh155122 15403448Sdh155122 /* Initialize SCTP hash arrays. */ 15413448Sdh155122 sctp_hash_init(sctps); 15423448Sdh155122 154312016SGirish.Moodalbail@Sun.COM arrsz = sctp_propinfo_count * sizeof (mod_prop_info_t); 154412016SGirish.Moodalbail@Sun.COM sctps->sctps_propinfo_tbl = (mod_prop_info_t *)kmem_alloc(arrsz, 154512016SGirish.Moodalbail@Sun.COM KM_SLEEP); 154612016SGirish.Moodalbail@Sun.COM bcopy(sctp_propinfo_tbl, sctps->sctps_propinfo_tbl, arrsz); 15470Sstevel@tonic-gate 15483448Sdh155122 /* saddr init */ 15493448Sdh155122 sctp_saddr_init(sctps); 15503448Sdh155122 15513448Sdh155122 /* Global SCTP PCB list. */ 15523448Sdh155122 list_create(&sctps->sctps_g_list, sizeof (sctp_t), 15533448Sdh155122 offsetof(sctp_t, sctp_list)); 15543448Sdh155122 1555*12869SKacheong.Poon@Sun.COM /* Initialize SCTP kstats. */ 15563448Sdh155122 sctps->sctps_mibkp = sctp_kstat_init(stackid); 1557*12869SKacheong.Poon@Sun.COM sctps->sctps_kstat = sctp_kstat2_init(stackid); 1558*12869SKacheong.Poon@Sun.COM 1559*12869SKacheong.Poon@Sun.COM mutex_init(&sctps->sctps_reclaim_lock, NULL, MUTEX_DEFAULT, NULL); 1560*12869SKacheong.Poon@Sun.COM sctps->sctps_reclaim = B_FALSE; 1561*12869SKacheong.Poon@Sun.COM sctps->sctps_reclaim_tid = 0; 1562*12869SKacheong.Poon@Sun.COM sctps->sctps_reclaim_period = sctps->sctps_rto_maxg; 1563*12869SKacheong.Poon@Sun.COM 1564*12869SKacheong.Poon@Sun.COM /* Allocate the per netstack stats */ 1565*12869SKacheong.Poon@Sun.COM mutex_enter(&cpu_lock); 1566*12869SKacheong.Poon@Sun.COM sctps->sctps_sc_cnt = MAX(ncpus, boot_ncpus); 1567*12869SKacheong.Poon@Sun.COM mutex_exit(&cpu_lock); 1568*12869SKacheong.Poon@Sun.COM sctps->sctps_sc = kmem_zalloc(max_ncpus * sizeof (sctp_stats_cpu_t *), 1569*12869SKacheong.Poon@Sun.COM KM_SLEEP); 1570*12869SKacheong.Poon@Sun.COM for (i = 0; i < sctps->sctps_sc_cnt; i++) { 1571*12869SKacheong.Poon@Sun.COM sctps->sctps_sc[i] = kmem_zalloc(sizeof (sctp_stats_cpu_t), 1572*12869SKacheong.Poon@Sun.COM KM_SLEEP); 1573*12869SKacheong.Poon@Sun.COM } 1574*12869SKacheong.Poon@Sun.COM 1575*12869SKacheong.Poon@Sun.COM mutex_init(&sctps->sctps_listener_conf_lock, NULL, MUTEX_DEFAULT, NULL); 1576*12869SKacheong.Poon@Sun.COM list_create(&sctps->sctps_listener_conf, sizeof (sctp_listener_t), 1577*12869SKacheong.Poon@Sun.COM offsetof(sctp_listener_t, sl_link)); 15783448Sdh155122 15793448Sdh155122 return (sctps); 15803448Sdh155122 } 15813448Sdh155122 15823448Sdh155122 /* 15833448Sdh155122 * Called when the module is about to be unloaded. 15843448Sdh155122 */ 15853448Sdh155122 void 15863448Sdh155122 sctp_ddi_g_destroy(void) 15873448Sdh155122 { 15880Sstevel@tonic-gate /* Destroy sctp_t/conn_t caches */ 15890Sstevel@tonic-gate sctp_conn_cache_fini(); 15900Sstevel@tonic-gate 15910Sstevel@tonic-gate /* Destroy the faddr cache */ 15920Sstevel@tonic-gate sctp_faddr_fini(); 15930Sstevel@tonic-gate 15940Sstevel@tonic-gate /* Destroy the sets cache */ 15950Sstevel@tonic-gate sctp_sets_fini(); 15960Sstevel@tonic-gate 15970Sstevel@tonic-gate /* Destroy the PR-SCTP sets cache */ 15980Sstevel@tonic-gate sctp_ftsn_sets_fini(); 15990Sstevel@tonic-gate 16003448Sdh155122 netstack_unregister(NS_SCTP); 16013448Sdh155122 } 16023448Sdh155122 16033448Sdh155122 /* 16043448Sdh155122 * Free the SCTP stack instance. 16053448Sdh155122 */ 16063448Sdh155122 static void 16073448Sdh155122 sctp_stack_fini(netstackid_t stackid, void *arg) 16083448Sdh155122 { 16093448Sdh155122 sctp_stack_t *sctps = (sctp_stack_t *)arg; 1610*12869SKacheong.Poon@Sun.COM int i; 1611*12869SKacheong.Poon@Sun.COM 1612*12869SKacheong.Poon@Sun.COM /* 1613*12869SKacheong.Poon@Sun.COM * Set sctps_reclaim to false tells sctp_reclaim_timer() not to restart 1614*12869SKacheong.Poon@Sun.COM * the timer. 1615*12869SKacheong.Poon@Sun.COM */ 1616*12869SKacheong.Poon@Sun.COM mutex_enter(&sctps->sctps_reclaim_lock); 1617*12869SKacheong.Poon@Sun.COM sctps->sctps_reclaim = B_FALSE; 1618*12869SKacheong.Poon@Sun.COM mutex_exit(&sctps->sctps_reclaim_lock); 1619*12869SKacheong.Poon@Sun.COM if (sctps->sctps_reclaim_tid != 0) 1620*12869SKacheong.Poon@Sun.COM (void) untimeout(sctps->sctps_reclaim_tid); 1621*12869SKacheong.Poon@Sun.COM mutex_destroy(&sctps->sctps_reclaim_lock); 1622*12869SKacheong.Poon@Sun.COM 1623*12869SKacheong.Poon@Sun.COM sctp_listener_conf_cleanup(sctps); 16243448Sdh155122 162512016SGirish.Moodalbail@Sun.COM kmem_free(sctps->sctps_propinfo_tbl, 162612016SGirish.Moodalbail@Sun.COM sctp_propinfo_count * sizeof (mod_prop_info_t)); 162712016SGirish.Moodalbail@Sun.COM sctps->sctps_propinfo_tbl = NULL; 16283448Sdh155122 16290Sstevel@tonic-gate /* Destroy the recvq taskqs. */ 16303448Sdh155122 sctp_rq_tq_fini(sctps); 16310Sstevel@tonic-gate 16320Sstevel@tonic-gate /* Destroy saddr */ 16333448Sdh155122 sctp_saddr_fini(sctps); 16340Sstevel@tonic-gate 16350Sstevel@tonic-gate /* Global SCTP PCB list. */ 16363448Sdh155122 list_destroy(&sctps->sctps_g_list); 16370Sstevel@tonic-gate 16380Sstevel@tonic-gate /* Destroy SCTP hash arrays. */ 16393448Sdh155122 sctp_hash_destroy(sctps); 16403448Sdh155122 16413448Sdh155122 /* Destroy SCTP kernel stats. */ 1642*12869SKacheong.Poon@Sun.COM for (i = 0; i < sctps->sctps_sc_cnt; i++) 1643*12869SKacheong.Poon@Sun.COM kmem_free(sctps->sctps_sc[i], sizeof (sctp_stats_cpu_t)); 1644*12869SKacheong.Poon@Sun.COM kmem_free(sctps->sctps_sc, max_ncpus * sizeof (sctp_stats_cpu_t *)); 16453448Sdh155122 16463448Sdh155122 sctp_kstat_fini(stackid, sctps->sctps_mibkp); 16473448Sdh155122 sctps->sctps_mibkp = NULL; 1648*12869SKacheong.Poon@Sun.COM sctp_kstat2_fini(stackid, sctps->sctps_kstat); 1649*12869SKacheong.Poon@Sun.COM sctps->sctps_kstat = NULL; 16500Sstevel@tonic-gate 16513448Sdh155122 mutex_destroy(&sctps->sctps_g_lock); 16523448Sdh155122 mutex_destroy(&sctps->sctps_epriv_port_lock); 16533448Sdh155122 16543448Sdh155122 kmem_free(sctps, sizeof (*sctps)); 16550Sstevel@tonic-gate } 16560Sstevel@tonic-gate 16570Sstevel@tonic-gate static void 16583448Sdh155122 sctp_rq_tq_init(sctp_stack_t *sctps) 16590Sstevel@tonic-gate { 1660*12869SKacheong.Poon@Sun.COM char tq_name[TASKQ_NAMELEN]; 1661*12869SKacheong.Poon@Sun.COM int thrs; 1662*12869SKacheong.Poon@Sun.COM int max_tasks; 1663*12869SKacheong.Poon@Sun.COM 1664*12869SKacheong.Poon@Sun.COM thrs = MIN(sctp_recvq_tq_thr_max, MAX(sctp_recvq_tq_thr_min, 1665*12869SKacheong.Poon@Sun.COM MAX(ncpus, boot_ncpus))); 1666*12869SKacheong.Poon@Sun.COM /* 1667*12869SKacheong.Poon@Sun.COM * Make sure that the maximum number of tasks is at least thrice as 1668*12869SKacheong.Poon@Sun.COM * large as the number of threads. 1669*12869SKacheong.Poon@Sun.COM */ 1670*12869SKacheong.Poon@Sun.COM max_tasks = MAX(sctp_recvq_tq_task_min, thrs) * 3; 1671*12869SKacheong.Poon@Sun.COM 1672*12869SKacheong.Poon@Sun.COM /* 1673*12869SKacheong.Poon@Sun.COM * This helps differentiate the default taskqs in different IP stacks. 1674*12869SKacheong.Poon@Sun.COM */ 1675*12869SKacheong.Poon@Sun.COM (void) snprintf(tq_name, sizeof (tq_name), "sctp_def_rq_taskq_%d", 1676*12869SKacheong.Poon@Sun.COM sctps->sctps_netstack->netstack_stackid); 1677*12869SKacheong.Poon@Sun.COM 1678*12869SKacheong.Poon@Sun.COM sctps->sctps_recvq_tq_list_max_sz = sctp_recvq_tq_list_max; 16793448Sdh155122 sctps->sctps_recvq_tq_list_cur_sz = 1; 1680*12869SKacheong.Poon@Sun.COM 16810Sstevel@tonic-gate /* 16820Sstevel@tonic-gate * Initialize the recvq_tq_list and create the first recvq taskq. 16830Sstevel@tonic-gate * What to do if it fails? 16840Sstevel@tonic-gate */ 16853448Sdh155122 sctps->sctps_recvq_tq_list = 16863448Sdh155122 kmem_zalloc(sctps->sctps_recvq_tq_list_max_sz * sizeof (taskq_t *), 16874505Skcpoon KM_SLEEP); 1688*12869SKacheong.Poon@Sun.COM sctps->sctps_recvq_tq_list[0] = taskq_create(tq_name, thrs, 1689*12869SKacheong.Poon@Sun.COM minclsyspri, sctp_recvq_tq_task_min, max_tasks, TASKQ_PREPOPULATE); 16903448Sdh155122 mutex_init(&sctps->sctps_rq_tq_lock, NULL, MUTEX_DEFAULT, NULL); 16910Sstevel@tonic-gate } 16920Sstevel@tonic-gate 16930Sstevel@tonic-gate static void 16943448Sdh155122 sctp_rq_tq_fini(sctp_stack_t *sctps) 16950Sstevel@tonic-gate { 16960Sstevel@tonic-gate int i; 16970Sstevel@tonic-gate 1698*12869SKacheong.Poon@Sun.COM if (sctps->sctps_recvq_tq_list_cur_sz == 0) 1699*12869SKacheong.Poon@Sun.COM return; 1700*12869SKacheong.Poon@Sun.COM 17013448Sdh155122 for (i = 0; i < sctps->sctps_recvq_tq_list_cur_sz; i++) { 17023448Sdh155122 ASSERT(sctps->sctps_recvq_tq_list[i] != NULL); 17033448Sdh155122 taskq_destroy(sctps->sctps_recvq_tq_list[i]); 17040Sstevel@tonic-gate } 17053448Sdh155122 kmem_free(sctps->sctps_recvq_tq_list, 17063448Sdh155122 sctps->sctps_recvq_tq_list_max_sz * sizeof (taskq_t *)); 17073448Sdh155122 sctps->sctps_recvq_tq_list = NULL; 17080Sstevel@tonic-gate } 17090Sstevel@tonic-gate 17100Sstevel@tonic-gate /* Add another taskq for a new ill. */ 17110Sstevel@tonic-gate void 17123448Sdh155122 sctp_inc_taskq(sctp_stack_t *sctps) 17130Sstevel@tonic-gate { 17140Sstevel@tonic-gate taskq_t *tq; 17150Sstevel@tonic-gate char tq_name[TASKQ_NAMELEN]; 1716*12869SKacheong.Poon@Sun.COM int thrs; 1717*12869SKacheong.Poon@Sun.COM int max_tasks; 1718*12869SKacheong.Poon@Sun.COM 1719*12869SKacheong.Poon@Sun.COM thrs = MIN(sctp_recvq_tq_thr_max, MAX(sctp_recvq_tq_thr_min, 1720*12869SKacheong.Poon@Sun.COM MAX(ncpus, boot_ncpus))); 1721*12869SKacheong.Poon@Sun.COM /* 1722*12869SKacheong.Poon@Sun.COM * Make sure that the maximum number of tasks is at least thrice as 1723*12869SKacheong.Poon@Sun.COM * large as the number of threads. 1724*12869SKacheong.Poon@Sun.COM */ 1725*12869SKacheong.Poon@Sun.COM max_tasks = MAX(sctp_recvq_tq_task_min, thrs) * 3; 17260Sstevel@tonic-gate 17273448Sdh155122 mutex_enter(&sctps->sctps_rq_tq_lock); 17283448Sdh155122 if (sctps->sctps_recvq_tq_list_cur_sz + 1 > 17293448Sdh155122 sctps->sctps_recvq_tq_list_max_sz) { 17303448Sdh155122 mutex_exit(&sctps->sctps_rq_tq_lock); 17310Sstevel@tonic-gate cmn_err(CE_NOTE, "Cannot create more SCTP recvq taskq"); 17320Sstevel@tonic-gate return; 17330Sstevel@tonic-gate } 17340Sstevel@tonic-gate 1735*12869SKacheong.Poon@Sun.COM (void) snprintf(tq_name, sizeof (tq_name), "sctp_rq_taskq_%d_%u", 1736*12869SKacheong.Poon@Sun.COM sctps->sctps_netstack->netstack_stackid, 17373448Sdh155122 sctps->sctps_recvq_tq_list_cur_sz); 1738*12869SKacheong.Poon@Sun.COM tq = taskq_create(tq_name, thrs, minclsyspri, sctp_recvq_tq_task_min, 1739*12869SKacheong.Poon@Sun.COM max_tasks, TASKQ_PREPOPULATE); 17400Sstevel@tonic-gate if (tq == NULL) { 17413448Sdh155122 mutex_exit(&sctps->sctps_rq_tq_lock); 17420Sstevel@tonic-gate cmn_err(CE_NOTE, "SCTP recvq taskq creation failed"); 17430Sstevel@tonic-gate return; 17440Sstevel@tonic-gate } 17453448Sdh155122 ASSERT(sctps->sctps_recvq_tq_list[ 17464505Skcpoon sctps->sctps_recvq_tq_list_cur_sz] == NULL); 17473448Sdh155122 sctps->sctps_recvq_tq_list[sctps->sctps_recvq_tq_list_cur_sz] = tq; 17483448Sdh155122 atomic_add_32(&sctps->sctps_recvq_tq_list_cur_sz, 1); 17493448Sdh155122 mutex_exit(&sctps->sctps_rq_tq_lock); 17500Sstevel@tonic-gate } 17510Sstevel@tonic-gate 17520Sstevel@tonic-gate #ifdef DEBUG 17530Sstevel@tonic-gate uint32_t recvq_loop_cnt = 0; 17540Sstevel@tonic-gate uint32_t recvq_call = 0; 17550Sstevel@tonic-gate #endif 17560Sstevel@tonic-gate 17570Sstevel@tonic-gate /* 17580Sstevel@tonic-gate * Find the next recvq_tq to use. This routine will go thru all the 17590Sstevel@tonic-gate * taskqs until it can dispatch a job for the sctp. If this fails, 17600Sstevel@tonic-gate * it will create a new taskq and try it. 17610Sstevel@tonic-gate */ 17620Sstevel@tonic-gate static boolean_t 17630Sstevel@tonic-gate sctp_find_next_tq(sctp_t *sctp) 17640Sstevel@tonic-gate { 17650Sstevel@tonic-gate int next_tq, try; 17660Sstevel@tonic-gate taskq_t *tq; 17673448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 17680Sstevel@tonic-gate 17690Sstevel@tonic-gate /* 17700Sstevel@tonic-gate * Note that since we don't hold a lock on sctp_rq_tq_lock for 17710Sstevel@tonic-gate * performance reason, recvq_ta_list_cur_sz can be changed during 17720Sstevel@tonic-gate * this loop. The problem this will create is that the loop may 17730Sstevel@tonic-gate * not have tried all the recvq_tq. This should be OK. 17740Sstevel@tonic-gate */ 17753448Sdh155122 next_tq = atomic_add_32_nv(&sctps->sctps_recvq_tq_list_cur, 1) % 17763448Sdh155122 sctps->sctps_recvq_tq_list_cur_sz; 17773448Sdh155122 for (try = 0; try < sctps->sctps_recvq_tq_list_cur_sz; try++) { 17783448Sdh155122 tq = sctps->sctps_recvq_tq_list[next_tq]; 17790Sstevel@tonic-gate if (taskq_dispatch(tq, sctp_process_recvq, sctp, 17800Sstevel@tonic-gate TQ_NOSLEEP) != NULL) { 17810Sstevel@tonic-gate sctp->sctp_recvq_tq = tq; 17820Sstevel@tonic-gate return (B_TRUE); 17830Sstevel@tonic-gate } 17843448Sdh155122 next_tq = (next_tq + 1) % sctps->sctps_recvq_tq_list_cur_sz; 17850Sstevel@tonic-gate } 17860Sstevel@tonic-gate 17870Sstevel@tonic-gate /* 17880Sstevel@tonic-gate * Create one more taskq and try it. Note that sctp_inc_taskq() 17890Sstevel@tonic-gate * may not have created another taskq if the number of recvq 17900Sstevel@tonic-gate * taskqs is at the maximum. We are probably in a pretty bad 17910Sstevel@tonic-gate * shape if this actually happens... 17920Sstevel@tonic-gate */ 17933448Sdh155122 sctp_inc_taskq(sctps); 17943448Sdh155122 tq = sctps->sctps_recvq_tq_list[sctps->sctps_recvq_tq_list_cur_sz - 1]; 17950Sstevel@tonic-gate if (taskq_dispatch(tq, sctp_process_recvq, sctp, TQ_NOSLEEP) != NULL) { 17960Sstevel@tonic-gate sctp->sctp_recvq_tq = tq; 17970Sstevel@tonic-gate return (B_TRUE); 17980Sstevel@tonic-gate } 17993448Sdh155122 SCTP_KSTAT(sctps, sctp_find_next_tq); 18000Sstevel@tonic-gate return (B_FALSE); 18010Sstevel@tonic-gate } 18020Sstevel@tonic-gate 18030Sstevel@tonic-gate /* 18040Sstevel@tonic-gate * To add a message to the recvq. Note that the sctp_timer_fire() 18050Sstevel@tonic-gate * routine also uses this function to add the timer message to the 18060Sstevel@tonic-gate * receive queue for later processing. And it should be the only 18070Sstevel@tonic-gate * caller of sctp_add_recvq() which sets the try_harder argument 18080Sstevel@tonic-gate * to B_TRUE. 18090Sstevel@tonic-gate * 18100Sstevel@tonic-gate * If the try_harder argument is B_TRUE, this routine sctp_find_next_tq() 18110Sstevel@tonic-gate * will try very hard to dispatch the task. Refer to the comment 18120Sstevel@tonic-gate * for that routine on how it does that. 181311042SErik.Nordmark@Sun.COM * 181411042SErik.Nordmark@Sun.COM * On failure the message has been freed i.e., this routine always consumes the 181511042SErik.Nordmark@Sun.COM * message. It bumps ipIfStatsInDiscards and and uses ip_drop_input to drop. 18160Sstevel@tonic-gate */ 181711042SErik.Nordmark@Sun.COM void 181811042SErik.Nordmark@Sun.COM sctp_add_recvq(sctp_t *sctp, mblk_t *mp, boolean_t caller_hold_lock, 181911042SErik.Nordmark@Sun.COM ip_recv_attr_t *ira) 18200Sstevel@tonic-gate { 182111042SErik.Nordmark@Sun.COM mblk_t *attrmp; 182211042SErik.Nordmark@Sun.COM ip_stack_t *ipst = sctp->sctp_sctps->sctps_netstack->netstack_ip; 182311042SErik.Nordmark@Sun.COM 182411042SErik.Nordmark@Sun.COM ASSERT(ira->ira_ill == NULL); 182511042SErik.Nordmark@Sun.COM 18260Sstevel@tonic-gate if (!caller_hold_lock) 18270Sstevel@tonic-gate mutex_enter(&sctp->sctp_recvq_lock); 18280Sstevel@tonic-gate 18290Sstevel@tonic-gate /* If the taskq dispatch has not been scheduled, do it now. */ 18300Sstevel@tonic-gate if (sctp->sctp_recvq_tq == NULL) { 18310Sstevel@tonic-gate ASSERT(sctp->sctp_recvq == NULL); 18320Sstevel@tonic-gate if (!sctp_find_next_tq(sctp)) { 18330Sstevel@tonic-gate if (!caller_hold_lock) 18340Sstevel@tonic-gate mutex_exit(&sctp->sctp_recvq_lock); 183511042SErik.Nordmark@Sun.COM BUMP_MIB(&ipst->ips_ip_mib, ipIfStatsInDiscards); 183611042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards", mp, NULL); 183711042SErik.Nordmark@Sun.COM freemsg(mp); 183811042SErik.Nordmark@Sun.COM return; 18390Sstevel@tonic-gate } 18400Sstevel@tonic-gate /* Make sure the sctp_t will not go away. */ 18410Sstevel@tonic-gate SCTP_REFHOLD(sctp); 18420Sstevel@tonic-gate } 18430Sstevel@tonic-gate 184411042SErik.Nordmark@Sun.COM attrmp = ip_recv_attr_to_mblk(ira); 184511042SErik.Nordmark@Sun.COM if (attrmp == NULL) { 184611042SErik.Nordmark@Sun.COM if (!caller_hold_lock) 184711042SErik.Nordmark@Sun.COM mutex_exit(&sctp->sctp_recvq_lock); 184811042SErik.Nordmark@Sun.COM BUMP_MIB(&ipst->ips_ip_mib, ipIfStatsInDiscards); 184911042SErik.Nordmark@Sun.COM ip_drop_input("ipIfStatsInDiscards", mp, NULL); 185011042SErik.Nordmark@Sun.COM freemsg(mp); 185111042SErik.Nordmark@Sun.COM return; 185211042SErik.Nordmark@Sun.COM } 185311042SErik.Nordmark@Sun.COM ASSERT(attrmp->b_cont == NULL); 185411042SErik.Nordmark@Sun.COM attrmp->b_cont = mp; 185511042SErik.Nordmark@Sun.COM mp = attrmp; 185611042SErik.Nordmark@Sun.COM 18570Sstevel@tonic-gate if (sctp->sctp_recvq == NULL) { 18580Sstevel@tonic-gate sctp->sctp_recvq = mp; 18590Sstevel@tonic-gate sctp->sctp_recvq_tail = mp; 18600Sstevel@tonic-gate } else { 18610Sstevel@tonic-gate sctp->sctp_recvq_tail->b_next = mp; 18620Sstevel@tonic-gate sctp->sctp_recvq_tail = mp; 18630Sstevel@tonic-gate } 18640Sstevel@tonic-gate 18650Sstevel@tonic-gate if (!caller_hold_lock) 18660Sstevel@tonic-gate mutex_exit(&sctp->sctp_recvq_lock); 18670Sstevel@tonic-gate } 18680Sstevel@tonic-gate 18690Sstevel@tonic-gate static void 18700Sstevel@tonic-gate sctp_process_recvq(void *arg) 18710Sstevel@tonic-gate { 18720Sstevel@tonic-gate sctp_t *sctp = (sctp_t *)arg; 18730Sstevel@tonic-gate mblk_t *mp; 18740Sstevel@tonic-gate #ifdef DEBUG 18750Sstevel@tonic-gate uint32_t loop_cnt = 0; 18760Sstevel@tonic-gate #endif 187711042SErik.Nordmark@Sun.COM ip_recv_attr_t iras; 18780Sstevel@tonic-gate 18790Sstevel@tonic-gate #ifdef _BIG_ENDIAN 18800Sstevel@tonic-gate #define IPVER(ip6h) ((((uint32_t *)ip6h)[0] >> 28) & 0x7) 18810Sstevel@tonic-gate #else 18820Sstevel@tonic-gate #define IPVER(ip6h) ((((uint32_t *)ip6h)[0] >> 4) & 0x7) 18830Sstevel@tonic-gate #endif 18840Sstevel@tonic-gate 18850Sstevel@tonic-gate RUN_SCTP(sctp); 18860Sstevel@tonic-gate mutex_enter(&sctp->sctp_recvq_lock); 18870Sstevel@tonic-gate 18880Sstevel@tonic-gate #ifdef DEBUG 18890Sstevel@tonic-gate recvq_call++; 18900Sstevel@tonic-gate #endif 18910Sstevel@tonic-gate /* 18920Sstevel@tonic-gate * Note that while we are in this loop, other thread can put 18930Sstevel@tonic-gate * new packets in the receive queue. We may be looping for 18940Sstevel@tonic-gate * quite a while. 18950Sstevel@tonic-gate */ 18960Sstevel@tonic-gate while ((mp = sctp->sctp_recvq) != NULL) { 189711042SErik.Nordmark@Sun.COM mblk_t *data_mp; 189811042SErik.Nordmark@Sun.COM 18990Sstevel@tonic-gate sctp->sctp_recvq = mp->b_next; 19000Sstevel@tonic-gate mutex_exit(&sctp->sctp_recvq_lock); 19010Sstevel@tonic-gate mp->b_next = NULL; 19020Sstevel@tonic-gate #ifdef DEBUG 19030Sstevel@tonic-gate loop_cnt++; 19040Sstevel@tonic-gate #endif 19050Sstevel@tonic-gate mp->b_prev = NULL; 19060Sstevel@tonic-gate 190711042SErik.Nordmark@Sun.COM data_mp = mp->b_cont; 190811042SErik.Nordmark@Sun.COM mp->b_cont = NULL; 190911042SErik.Nordmark@Sun.COM if (!ip_recv_attr_from_mblk(mp, &iras)) { 191011042SErik.Nordmark@Sun.COM ip_drop_input("ip_recv_attr_from_mblk", mp, NULL); 191111042SErik.Nordmark@Sun.COM freemsg(mp); 191211042SErik.Nordmark@Sun.COM ira_cleanup(&iras, B_TRUE); 191311042SErik.Nordmark@Sun.COM continue; 191411042SErik.Nordmark@Sun.COM } 191511042SErik.Nordmark@Sun.COM 191611042SErik.Nordmark@Sun.COM if (iras.ira_flags & IRAF_ICMP_ERROR) 191711042SErik.Nordmark@Sun.COM sctp_icmp_error(sctp, data_mp); 191811042SErik.Nordmark@Sun.COM else 191911042SErik.Nordmark@Sun.COM sctp_input_data(sctp, data_mp, &iras); 192011042SErik.Nordmark@Sun.COM 192111042SErik.Nordmark@Sun.COM ira_cleanup(&iras, B_TRUE); 19220Sstevel@tonic-gate mutex_enter(&sctp->sctp_recvq_lock); 19230Sstevel@tonic-gate } 19240Sstevel@tonic-gate 19250Sstevel@tonic-gate sctp->sctp_recvq_tail = NULL; 19260Sstevel@tonic-gate sctp->sctp_recvq_tq = NULL; 19270Sstevel@tonic-gate 19280Sstevel@tonic-gate mutex_exit(&sctp->sctp_recvq_lock); 19290Sstevel@tonic-gate 19300Sstevel@tonic-gate WAKE_SCTP(sctp); 19310Sstevel@tonic-gate 19320Sstevel@tonic-gate #ifdef DEBUG 19330Sstevel@tonic-gate if (loop_cnt > recvq_loop_cnt) 19340Sstevel@tonic-gate recvq_loop_cnt = loop_cnt; 19350Sstevel@tonic-gate #endif 19360Sstevel@tonic-gate /* Now it can go away. */ 19370Sstevel@tonic-gate SCTP_REFRELE(sctp); 19380Sstevel@tonic-gate } 19390Sstevel@tonic-gate 19400Sstevel@tonic-gate /* ARGSUSED */ 19410Sstevel@tonic-gate static int 19420Sstevel@tonic-gate sctp_conn_cache_constructor(void *buf, void *cdrarg, int kmflags) 19430Sstevel@tonic-gate { 194411042SErik.Nordmark@Sun.COM conn_t *connp = (conn_t *)buf; 194511042SErik.Nordmark@Sun.COM sctp_t *sctp = (sctp_t *)&connp[1]; 194611373SGeorge.Shepherd@Sun.COM int cnt; 19470Sstevel@tonic-gate 194811042SErik.Nordmark@Sun.COM bzero(connp, sizeof (conn_t)); 19490Sstevel@tonic-gate bzero(buf, (char *)&sctp[1] - (char *)buf); 19500Sstevel@tonic-gate 19510Sstevel@tonic-gate mutex_init(&sctp->sctp_reflock, NULL, MUTEX_DEFAULT, NULL); 19520Sstevel@tonic-gate mutex_init(&sctp->sctp_lock, NULL, MUTEX_DEFAULT, NULL); 19530Sstevel@tonic-gate mutex_init(&sctp->sctp_recvq_lock, NULL, MUTEX_DEFAULT, NULL); 19540Sstevel@tonic-gate cv_init(&sctp->sctp_cv, NULL, CV_DEFAULT, NULL); 195511373SGeorge.Shepherd@Sun.COM for (cnt = 0; cnt < SCTP_IPIF_HASH; cnt++) { 195611373SGeorge.Shepherd@Sun.COM rw_init(&sctp->sctp_saddrs[cnt].ipif_hash_lock, NULL, 195711373SGeorge.Shepherd@Sun.COM RW_DEFAULT, NULL); 195811373SGeorge.Shepherd@Sun.COM } 19590Sstevel@tonic-gate 196011042SErik.Nordmark@Sun.COM mutex_init(&connp->conn_lock, NULL, MUTEX_DEFAULT, NULL); 196111042SErik.Nordmark@Sun.COM cv_init(&connp->conn_cv, NULL, CV_DEFAULT, NULL); 196211042SErik.Nordmark@Sun.COM connp->conn_flags = IPCL_SCTPCONN; 196311042SErik.Nordmark@Sun.COM connp->conn_proto = IPPROTO_SCTP; 196411042SErik.Nordmark@Sun.COM connp->conn_sctp = sctp; 196511042SErik.Nordmark@Sun.COM sctp->sctp_connp = connp; 196611042SErik.Nordmark@Sun.COM rw_init(&connp->conn_ilg_lock, NULL, RW_DEFAULT, NULL); 196711042SErik.Nordmark@Sun.COM 196811042SErik.Nordmark@Sun.COM connp->conn_ixa = kmem_zalloc(sizeof (ip_xmit_attr_t), kmflags); 196911042SErik.Nordmark@Sun.COM if (connp->conn_ixa == NULL) { 197011042SErik.Nordmark@Sun.COM return (ENOMEM); 197111042SErik.Nordmark@Sun.COM } 197211042SErik.Nordmark@Sun.COM connp->conn_ixa->ixa_refcnt = 1; 197311042SErik.Nordmark@Sun.COM connp->conn_ixa->ixa_protocol = connp->conn_proto; 197411042SErik.Nordmark@Sun.COM connp->conn_ixa->ixa_xmit_hint = CONN_TO_XMIT_HINT(connp); 19750Sstevel@tonic-gate return (0); 19760Sstevel@tonic-gate } 19770Sstevel@tonic-gate 19780Sstevel@tonic-gate /* ARGSUSED */ 19790Sstevel@tonic-gate static void 19800Sstevel@tonic-gate sctp_conn_cache_destructor(void *buf, void *cdrarg) 19810Sstevel@tonic-gate { 198211042SErik.Nordmark@Sun.COM conn_t *connp = (conn_t *)buf; 198311042SErik.Nordmark@Sun.COM sctp_t *sctp = (sctp_t *)&connp[1]; 198411373SGeorge.Shepherd@Sun.COM int cnt; 19850Sstevel@tonic-gate 198611042SErik.Nordmark@Sun.COM ASSERT(sctp->sctp_connp == connp); 19870Sstevel@tonic-gate ASSERT(!MUTEX_HELD(&sctp->sctp_lock)); 19880Sstevel@tonic-gate ASSERT(!MUTEX_HELD(&sctp->sctp_reflock)); 19890Sstevel@tonic-gate ASSERT(!MUTEX_HELD(&sctp->sctp_recvq_lock)); 19900Sstevel@tonic-gate 19910Sstevel@tonic-gate ASSERT(sctp->sctp_conn_hash_next == NULL); 19920Sstevel@tonic-gate ASSERT(sctp->sctp_conn_hash_prev == NULL); 19930Sstevel@tonic-gate ASSERT(sctp->sctp_listen_hash_next == NULL); 19940Sstevel@tonic-gate ASSERT(sctp->sctp_listen_hash_prev == NULL); 19950Sstevel@tonic-gate ASSERT(sctp->sctp_listen_tfp == NULL); 19960Sstevel@tonic-gate ASSERT(sctp->sctp_conn_tfp == NULL); 19970Sstevel@tonic-gate 19980Sstevel@tonic-gate ASSERT(sctp->sctp_faddrs == NULL); 19990Sstevel@tonic-gate ASSERT(sctp->sctp_nsaddrs == 0); 20000Sstevel@tonic-gate 20010Sstevel@tonic-gate ASSERT(sctp->sctp_ulpd == NULL); 20020Sstevel@tonic-gate 20030Sstevel@tonic-gate ASSERT(sctp->sctp_lastfaddr == NULL); 20040Sstevel@tonic-gate ASSERT(sctp->sctp_primary == NULL); 20050Sstevel@tonic-gate ASSERT(sctp->sctp_current == NULL); 20060Sstevel@tonic-gate ASSERT(sctp->sctp_lastdata == NULL); 20070Sstevel@tonic-gate 20080Sstevel@tonic-gate ASSERT(sctp->sctp_xmit_head == NULL); 20090Sstevel@tonic-gate ASSERT(sctp->sctp_xmit_tail == NULL); 20100Sstevel@tonic-gate ASSERT(sctp->sctp_xmit_unsent == NULL); 20110Sstevel@tonic-gate ASSERT(sctp->sctp_xmit_unsent_tail == NULL); 20120Sstevel@tonic-gate 20130Sstevel@tonic-gate ASSERT(sctp->sctp_ostrcntrs == NULL); 20140Sstevel@tonic-gate 20150Sstevel@tonic-gate ASSERT(sctp->sctp_sack_info == NULL); 20160Sstevel@tonic-gate ASSERT(sctp->sctp_ack_mp == NULL); 20170Sstevel@tonic-gate ASSERT(sctp->sctp_instr == NULL); 20180Sstevel@tonic-gate 20190Sstevel@tonic-gate ASSERT(sctp->sctp_iphc == NULL); 20200Sstevel@tonic-gate ASSERT(sctp->sctp_iphc6 == NULL); 20210Sstevel@tonic-gate ASSERT(sctp->sctp_ipha == NULL); 20220Sstevel@tonic-gate ASSERT(sctp->sctp_ip6h == NULL); 20230Sstevel@tonic-gate ASSERT(sctp->sctp_sctph == NULL); 20240Sstevel@tonic-gate ASSERT(sctp->sctp_sctph6 == NULL); 20250Sstevel@tonic-gate 20260Sstevel@tonic-gate ASSERT(sctp->sctp_cookie_mp == NULL); 20270Sstevel@tonic-gate 20280Sstevel@tonic-gate ASSERT(sctp->sctp_refcnt == 0); 20290Sstevel@tonic-gate ASSERT(sctp->sctp_timer_mp == NULL); 20300Sstevel@tonic-gate ASSERT(sctp->sctp_connp->conn_ref == 0); 20310Sstevel@tonic-gate ASSERT(sctp->sctp_heartbeat_mp == NULL); 20320Sstevel@tonic-gate ASSERT(sctp->sctp_ptpbhn == NULL && sctp->sctp_bind_hash == NULL); 20330Sstevel@tonic-gate 20340Sstevel@tonic-gate ASSERT(sctp->sctp_shutdown_faddr == NULL); 20350Sstevel@tonic-gate 20360Sstevel@tonic-gate ASSERT(sctp->sctp_cxmit_list == NULL); 20370Sstevel@tonic-gate 20380Sstevel@tonic-gate ASSERT(sctp->sctp_recvq == NULL); 20390Sstevel@tonic-gate ASSERT(sctp->sctp_recvq_tail == NULL); 20400Sstevel@tonic-gate ASSERT(sctp->sctp_recvq_tq == NULL); 20410Sstevel@tonic-gate 20424691Skcpoon /* 20434691Skcpoon * sctp_pad_mp can be NULL if the memory allocation fails 20444691Skcpoon * in sctp_init_values() and the conn_t is freed. 20454691Skcpoon */ 20464691Skcpoon if (sctp->sctp_pad_mp != NULL) { 20474691Skcpoon freeb(sctp->sctp_pad_mp); 20484691Skcpoon sctp->sctp_pad_mp = NULL; 20494691Skcpoon } 20504691Skcpoon 20510Sstevel@tonic-gate mutex_destroy(&sctp->sctp_reflock); 20520Sstevel@tonic-gate mutex_destroy(&sctp->sctp_lock); 20530Sstevel@tonic-gate mutex_destroy(&sctp->sctp_recvq_lock); 20540Sstevel@tonic-gate cv_destroy(&sctp->sctp_cv); 205511373SGeorge.Shepherd@Sun.COM for (cnt = 0; cnt < SCTP_IPIF_HASH; cnt++) { 205611373SGeorge.Shepherd@Sun.COM rw_destroy(&sctp->sctp_saddrs[cnt].ipif_hash_lock); 205711373SGeorge.Shepherd@Sun.COM } 205811042SErik.Nordmark@Sun.COM 205911042SErik.Nordmark@Sun.COM mutex_destroy(&connp->conn_lock); 206011042SErik.Nordmark@Sun.COM cv_destroy(&connp->conn_cv); 206111042SErik.Nordmark@Sun.COM rw_destroy(&connp->conn_ilg_lock); 20620Sstevel@tonic-gate 206311042SErik.Nordmark@Sun.COM /* Can be NULL if constructor failed */ 206411042SErik.Nordmark@Sun.COM if (connp->conn_ixa != NULL) { 206511042SErik.Nordmark@Sun.COM ASSERT(connp->conn_ixa->ixa_refcnt == 1); 206611042SErik.Nordmark@Sun.COM ASSERT(connp->conn_ixa->ixa_ire == NULL); 206711042SErik.Nordmark@Sun.COM ASSERT(connp->conn_ixa->ixa_nce == NULL); 206811042SErik.Nordmark@Sun.COM ixa_refrele(connp->conn_ixa); 206911042SErik.Nordmark@Sun.COM } 20700Sstevel@tonic-gate } 20710Sstevel@tonic-gate 20720Sstevel@tonic-gate static void 20730Sstevel@tonic-gate sctp_conn_cache_init() 20740Sstevel@tonic-gate { 20750Sstevel@tonic-gate sctp_conn_cache = kmem_cache_create("sctp_conn_cache", 20760Sstevel@tonic-gate sizeof (sctp_t) + sizeof (conn_t), 0, sctp_conn_cache_constructor, 2077*12869SKacheong.Poon@Sun.COM sctp_conn_cache_destructor, sctp_conn_reclaim, NULL, NULL, 0); 20780Sstevel@tonic-gate } 20790Sstevel@tonic-gate 20800Sstevel@tonic-gate static void 20810Sstevel@tonic-gate sctp_conn_cache_fini() 20820Sstevel@tonic-gate { 20830Sstevel@tonic-gate kmem_cache_destroy(sctp_conn_cache); 20840Sstevel@tonic-gate } 20854691Skcpoon 20864691Skcpoon void 20874691Skcpoon sctp_conn_init(conn_t *connp) 20884691Skcpoon { 208911042SErik.Nordmark@Sun.COM ASSERT(connp->conn_flags == IPCL_SCTPCONN); 20904691Skcpoon connp->conn_rq = connp->conn_wq = NULL; 209111042SErik.Nordmark@Sun.COM connp->conn_ixa->ixa_flags |= IXAF_SET_ULP_CKSUM | IXAF_VERIFY_SOURCE | 209211042SErik.Nordmark@Sun.COM IXAF_VERIFY_PMTU; 209311042SErik.Nordmark@Sun.COM 209411042SErik.Nordmark@Sun.COM ASSERT(connp->conn_proto == IPPROTO_SCTP); 209511042SErik.Nordmark@Sun.COM ASSERT(connp->conn_ixa->ixa_protocol == connp->conn_proto); 20964691Skcpoon connp->conn_state_flags |= CONN_INCIPIENT; 209711042SErik.Nordmark@Sun.COM 209811042SErik.Nordmark@Sun.COM ASSERT(connp->conn_sctp != NULL); 209911042SErik.Nordmark@Sun.COM 210011042SErik.Nordmark@Sun.COM /* 210111042SErik.Nordmark@Sun.COM * Register sctp_notify to listen to capability changes detected by IP. 210211042SErik.Nordmark@Sun.COM * This upcall is made in the context of the call to conn_ip_output 210311042SErik.Nordmark@Sun.COM * thus it holds whatever locks sctp holds across conn_ip_output. 210411042SErik.Nordmark@Sun.COM */ 210511042SErik.Nordmark@Sun.COM connp->conn_ixa->ixa_notify = sctp_notify; 210611042SErik.Nordmark@Sun.COM connp->conn_ixa->ixa_notify_cookie = connp->conn_sctp; 21074691Skcpoon } 21084691Skcpoon 21094691Skcpoon static void 21104691Skcpoon sctp_conn_clear(conn_t *connp) 21114691Skcpoon { 21124691Skcpoon /* Clean up conn_t stuff */ 211311042SErik.Nordmark@Sun.COM if (connp->conn_latch != NULL) { 211411042SErik.Nordmark@Sun.COM IPLATCH_REFRELE(connp->conn_latch); 211511042SErik.Nordmark@Sun.COM connp->conn_latch = NULL; 211611042SErik.Nordmark@Sun.COM } 211711042SErik.Nordmark@Sun.COM if (connp->conn_latch_in_policy != NULL) { 211811042SErik.Nordmark@Sun.COM IPPOL_REFRELE(connp->conn_latch_in_policy); 211911042SErik.Nordmark@Sun.COM connp->conn_latch_in_policy = NULL; 212011042SErik.Nordmark@Sun.COM } 212111042SErik.Nordmark@Sun.COM if (connp->conn_latch_in_action != NULL) { 212211042SErik.Nordmark@Sun.COM IPACT_REFRELE(connp->conn_latch_in_action); 212311042SErik.Nordmark@Sun.COM connp->conn_latch_in_action = NULL; 212411042SErik.Nordmark@Sun.COM } 212511042SErik.Nordmark@Sun.COM if (connp->conn_policy != NULL) { 21264691Skcpoon IPPH_REFRELE(connp->conn_policy, connp->conn_netstack); 212711042SErik.Nordmark@Sun.COM connp->conn_policy = NULL; 212811042SErik.Nordmark@Sun.COM } 212911042SErik.Nordmark@Sun.COM if (connp->conn_ipsec_opt_mp != NULL) { 21304691Skcpoon freemsg(connp->conn_ipsec_opt_mp); 213111042SErik.Nordmark@Sun.COM connp->conn_ipsec_opt_mp = NULL; 213211042SErik.Nordmark@Sun.COM } 21334691Skcpoon netstack_rele(connp->conn_netstack); 213411042SErik.Nordmark@Sun.COM connp->conn_netstack = NULL; 213511042SErik.Nordmark@Sun.COM 213611042SErik.Nordmark@Sun.COM /* Leave conn_ixa and other constructed fields in place */ 213711042SErik.Nordmark@Sun.COM ipcl_conn_cleanup(connp); 21384691Skcpoon } 2139