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 51676Sjpk * Common Development and Distribution License (the "License"). 61676Sjpk * 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 */ 210Sstevel@tonic-gate 220Sstevel@tonic-gate /* 231676Sjpk * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <sys/socket.h> 300Sstevel@tonic-gate #include <sys/ddi.h> 310Sstevel@tonic-gate #include <sys/sunddi.h> 321676Sjpk #include <sys/tsol/tndb.h> 331676Sjpk #include <sys/tsol/tnet.h> 340Sstevel@tonic-gate 350Sstevel@tonic-gate #include <netinet/in.h> 360Sstevel@tonic-gate #include <netinet/ip6.h> 370Sstevel@tonic-gate 380Sstevel@tonic-gate #include <inet/common.h> 390Sstevel@tonic-gate #include <inet/ip.h> 400Sstevel@tonic-gate #include <inet/ip6.h> 410Sstevel@tonic-gate #include <inet/ipclassifier.h> 420Sstevel@tonic-gate #include <inet/ipsec_impl.h> 430Sstevel@tonic-gate #include <inet/ipp_common.h> 440Sstevel@tonic-gate #include <inet/sctp_ip.h> 450Sstevel@tonic-gate 460Sstevel@tonic-gate #include "sctp_impl.h" 470Sstevel@tonic-gate #include "sctp_addr.h" 480Sstevel@tonic-gate 490Sstevel@tonic-gate /* SCTP bind hash list - all sctp_t with state >= BOUND. */ 500Sstevel@tonic-gate sctp_tf_t sctp_bind_fanout[SCTP_BIND_FANOUT_SIZE]; 510Sstevel@tonic-gate /* SCTP listen hash list - all sctp_t with state == LISTEN. */ 520Sstevel@tonic-gate sctp_tf_t sctp_listen_fanout[SCTP_LISTEN_FANOUT_SIZE]; 530Sstevel@tonic-gate 540Sstevel@tonic-gate /* Default association hash size. The size must be a power of 2. */ 550Sstevel@tonic-gate #define SCTP_CONN_HASH_SIZE 8192 560Sstevel@tonic-gate 570Sstevel@tonic-gate sctp_tf_t *sctp_conn_fanout; 580Sstevel@tonic-gate uint_t sctp_conn_hash_size = SCTP_CONN_HASH_SIZE; 590Sstevel@tonic-gate 60852Svi117747 /* 61852Svi117747 * Cluster networking hook for traversing current assoc list. 62852Svi117747 * This routine is used to extract the current list of live associations 63852Svi117747 * which must continue to to be dispatched to this node. 64852Svi117747 */ 65852Svi117747 int cl_sctp_walk_list(int (*cl_callback)(cl_sctp_info_t *, void *), void *, 66852Svi117747 boolean_t); 67852Svi117747 680Sstevel@tonic-gate void 690Sstevel@tonic-gate sctp_hash_init() 700Sstevel@tonic-gate { 710Sstevel@tonic-gate int i; 720Sstevel@tonic-gate 730Sstevel@tonic-gate if (sctp_conn_hash_size & (sctp_conn_hash_size - 1)) { 740Sstevel@tonic-gate /* Not a power of two. Round up to nearest power of two */ 750Sstevel@tonic-gate for (i = 0; i < 31; i++) { 760Sstevel@tonic-gate if (sctp_conn_hash_size < (1 << i)) 770Sstevel@tonic-gate break; 780Sstevel@tonic-gate } 790Sstevel@tonic-gate sctp_conn_hash_size = 1 << i; 800Sstevel@tonic-gate } 810Sstevel@tonic-gate if (sctp_conn_hash_size < SCTP_CONN_HASH_SIZE) { 820Sstevel@tonic-gate sctp_conn_hash_size = SCTP_CONN_HASH_SIZE; 830Sstevel@tonic-gate cmn_err(CE_CONT, "using sctp_conn_hash_size = %u\n", 840Sstevel@tonic-gate sctp_conn_hash_size); 850Sstevel@tonic-gate } 860Sstevel@tonic-gate sctp_conn_fanout = 870Sstevel@tonic-gate (sctp_tf_t *)kmem_zalloc(sctp_conn_hash_size * 880Sstevel@tonic-gate sizeof (sctp_tf_t), KM_SLEEP); 890Sstevel@tonic-gate for (i = 0; i < sctp_conn_hash_size; i++) { 900Sstevel@tonic-gate mutex_init(&sctp_conn_fanout[i].tf_lock, NULL, 910Sstevel@tonic-gate MUTEX_DEFAULT, NULL); 920Sstevel@tonic-gate } 930Sstevel@tonic-gate for (i = 0; i < A_CNT(sctp_listen_fanout); i++) { 940Sstevel@tonic-gate mutex_init(&sctp_listen_fanout[i].tf_lock, NULL, 950Sstevel@tonic-gate MUTEX_DEFAULT, NULL); 960Sstevel@tonic-gate } 970Sstevel@tonic-gate for (i = 0; i < A_CNT(sctp_bind_fanout); i++) { 980Sstevel@tonic-gate mutex_init(&sctp_bind_fanout[i].tf_lock, NULL, 990Sstevel@tonic-gate MUTEX_DEFAULT, NULL); 1000Sstevel@tonic-gate } 1010Sstevel@tonic-gate } 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate void 1040Sstevel@tonic-gate sctp_hash_destroy() 1050Sstevel@tonic-gate { 1060Sstevel@tonic-gate int i; 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate for (i = 0; i < sctp_conn_hash_size; i++) { 1090Sstevel@tonic-gate mutex_destroy(&sctp_conn_fanout[i].tf_lock); 1100Sstevel@tonic-gate } 1110Sstevel@tonic-gate kmem_free(sctp_conn_fanout, sctp_conn_hash_size * sizeof (sctp_tf_t)); 1120Sstevel@tonic-gate for (i = 0; i < A_CNT(sctp_listen_fanout); i++) { 1130Sstevel@tonic-gate mutex_destroy(&sctp_listen_fanout[i].tf_lock); 1140Sstevel@tonic-gate } 1150Sstevel@tonic-gate for (i = 0; i < A_CNT(sctp_bind_fanout); i++) { 1160Sstevel@tonic-gate mutex_destroy(&sctp_bind_fanout[i].tf_lock); 1170Sstevel@tonic-gate } 1180Sstevel@tonic-gate } 1190Sstevel@tonic-gate 1201932Svi117747 /* 1211932Svi117747 * Walk the SCTP global list and refrele the ire for this ipif 1221932Svi117747 * This is called when an address goes down, so that we release any reference 1231932Svi117747 * to the ire associated with this address. Additionally, for any SCTP if 1241932Svi117747 * this was the only/last address in its source list, we don't kill the 1251932Svi117747 * assoc., if there is no address added subsequently, or if this does not 1261932Svi117747 * come up, then the assoc. will die a natural death (i.e. timeout). 1271932Svi117747 */ 1280Sstevel@tonic-gate void 1290Sstevel@tonic-gate sctp_ire_cache_flush(ipif_t *ipif) 1300Sstevel@tonic-gate { 1310Sstevel@tonic-gate sctp_t *sctp; 1320Sstevel@tonic-gate sctp_t *sctp_prev = NULL; 1330Sstevel@tonic-gate sctp_faddr_t *fp; 1340Sstevel@tonic-gate conn_t *connp; 1350Sstevel@tonic-gate ire_t *ire; 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate sctp = gsctp; 1380Sstevel@tonic-gate mutex_enter(&sctp_g_lock); 1390Sstevel@tonic-gate while (sctp != NULL) { 1400Sstevel@tonic-gate mutex_enter(&sctp->sctp_reflock); 1410Sstevel@tonic-gate if (sctp->sctp_condemned) { 1420Sstevel@tonic-gate mutex_exit(&sctp->sctp_reflock); 1430Sstevel@tonic-gate sctp = list_next(&sctp_g_list, sctp); 1440Sstevel@tonic-gate continue; 1450Sstevel@tonic-gate } 1460Sstevel@tonic-gate sctp->sctp_refcnt++; 1470Sstevel@tonic-gate mutex_exit(&sctp->sctp_reflock); 1480Sstevel@tonic-gate mutex_exit(&sctp_g_lock); 1490Sstevel@tonic-gate if (sctp_prev != NULL) 1500Sstevel@tonic-gate SCTP_REFRELE(sctp_prev); 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate RUN_SCTP(sctp); 1530Sstevel@tonic-gate connp = sctp->sctp_connp; 1540Sstevel@tonic-gate mutex_enter(&connp->conn_lock); 1550Sstevel@tonic-gate ire = connp->conn_ire_cache; 1561932Svi117747 if (ire != NULL && ire->ire_ipif == ipif) { 1570Sstevel@tonic-gate connp->conn_ire_cache = NULL; 1580Sstevel@tonic-gate mutex_exit(&connp->conn_lock); 1590Sstevel@tonic-gate IRE_REFRELE_NOTR(ire); 1600Sstevel@tonic-gate } else { 1610Sstevel@tonic-gate mutex_exit(&connp->conn_lock); 1620Sstevel@tonic-gate } 1630Sstevel@tonic-gate /* check for ires cached in faddr */ 1641932Svi117747 for (fp = sctp->sctp_faddrs; fp != NULL; fp = fp->next) { 1651932Svi117747 /* 1661932Svi117747 * If this ipif is being used as the source address 1671932Svi117747 * we need to update it as well, else we will end 1681932Svi117747 * up using the dead source address. 1691932Svi117747 */ 1700Sstevel@tonic-gate ire = fp->ire; 1711932Svi117747 if (ire != NULL && ire->ire_ipif == ipif) { 1720Sstevel@tonic-gate fp->ire = NULL; 1730Sstevel@tonic-gate IRE_REFRELE_NOTR(ire); 1740Sstevel@tonic-gate } 1751932Svi117747 /* 1761932Svi117747 * This may result in setting the fp as unreachable, 1771932Svi117747 * i.e. if all the source addresses are down. In 1781932Svi117747 * that case the assoc. would timeout. 1791932Svi117747 */ 1801932Svi117747 if (IN6_ARE_ADDR_EQUAL(&ipif->ipif_v6lcl_addr, 1811932Svi117747 &fp->saddr)) { 1821932Svi117747 sctp_set_saddr(sctp, fp); 1831932Svi117747 if (fp == sctp->sctp_current && 1841932Svi117747 fp->state != SCTP_FADDRS_UNREACH) { 1851932Svi117747 sctp_set_faddr_current(sctp, fp); 1861932Svi117747 } 1871932Svi117747 } 1880Sstevel@tonic-gate } 1890Sstevel@tonic-gate WAKE_SCTP(sctp); 1900Sstevel@tonic-gate sctp_prev = sctp; 1910Sstevel@tonic-gate mutex_enter(&sctp_g_lock); 1920Sstevel@tonic-gate sctp = list_next(&sctp_g_list, sctp); 1930Sstevel@tonic-gate } 1940Sstevel@tonic-gate mutex_exit(&sctp_g_lock); 1950Sstevel@tonic-gate if (sctp_prev != NULL) 1960Sstevel@tonic-gate SCTP_REFRELE(sctp_prev); 1970Sstevel@tonic-gate } 1980Sstevel@tonic-gate 199852Svi117747 /* 200852Svi117747 * Exported routine for extracting active SCTP associations. 201852Svi117747 * Like TCP, we terminate the walk if the callback returns non-zero. 202852Svi117747 */ 203852Svi117747 int 204852Svi117747 cl_sctp_walk_list(int (*cl_callback)(cl_sctp_info_t *, void *), void *arg, 205852Svi117747 boolean_t cansleep) 206852Svi117747 { 207852Svi117747 sctp_t *sctp; 208852Svi117747 sctp_t *sctp_prev; 209852Svi117747 cl_sctp_info_t cl_sctpi; 210852Svi117747 uchar_t *slist; 211852Svi117747 uchar_t *flist; 212852Svi117747 213852Svi117747 sctp = gsctp; 214852Svi117747 sctp_prev = NULL; 215852Svi117747 mutex_enter(&sctp_g_lock); 216852Svi117747 while (sctp != NULL) { 217852Svi117747 size_t ssize; 218852Svi117747 size_t fsize; 219852Svi117747 220852Svi117747 mutex_enter(&sctp->sctp_reflock); 221852Svi117747 if (sctp->sctp_condemned || sctp->sctp_state <= SCTPS_LISTEN) { 222852Svi117747 mutex_exit(&sctp->sctp_reflock); 223852Svi117747 sctp = list_next(&sctp_g_list, sctp); 224852Svi117747 continue; 225852Svi117747 } 226852Svi117747 sctp->sctp_refcnt++; 227852Svi117747 mutex_exit(&sctp->sctp_reflock); 228852Svi117747 mutex_exit(&sctp_g_lock); 229852Svi117747 if (sctp_prev != NULL) 230852Svi117747 SCTP_REFRELE(sctp_prev); 231852Svi117747 RUN_SCTP(sctp); 232852Svi117747 ssize = sizeof (in6_addr_t) * sctp->sctp_nsaddrs; 233852Svi117747 fsize = sizeof (in6_addr_t) * sctp->sctp_nfaddrs; 234852Svi117747 235852Svi117747 slist = kmem_alloc(ssize, cansleep ? KM_SLEEP : KM_NOSLEEP); 236852Svi117747 flist = kmem_alloc(fsize, cansleep ? KM_SLEEP : KM_NOSLEEP); 237852Svi117747 if (slist == NULL || flist == NULL) { 238852Svi117747 WAKE_SCTP(sctp); 239852Svi117747 if (slist != NULL) 240852Svi117747 kmem_free(slist, ssize); 241852Svi117747 if (flist != NULL) 242852Svi117747 kmem_free(flist, fsize); 243852Svi117747 SCTP_REFRELE(sctp); 244852Svi117747 return (1); 245852Svi117747 } 246852Svi117747 cl_sctpi.cl_sctpi_version = CL_SCTPI_V1; 247852Svi117747 sctp_get_saddr_list(sctp, slist, ssize); 248852Svi117747 sctp_get_faddr_list(sctp, flist, fsize); 249852Svi117747 cl_sctpi.cl_sctpi_nladdr = sctp->sctp_nsaddrs; 250852Svi117747 cl_sctpi.cl_sctpi_nfaddr = sctp->sctp_nfaddrs; 251852Svi117747 cl_sctpi.cl_sctpi_family = sctp->sctp_family; 252852Svi117747 cl_sctpi.cl_sctpi_ipversion = sctp->sctp_ipversion; 253852Svi117747 cl_sctpi.cl_sctpi_state = sctp->sctp_state; 254852Svi117747 cl_sctpi.cl_sctpi_lport = sctp->sctp_lport; 255852Svi117747 cl_sctpi.cl_sctpi_fport = sctp->sctp_fport; 256852Svi117747 cl_sctpi.cl_sctpi_handle = (cl_sctp_handle_t)sctp; 257852Svi117747 WAKE_SCTP(sctp); 258852Svi117747 cl_sctpi.cl_sctpi_laddrp = slist; 259852Svi117747 cl_sctpi.cl_sctpi_faddrp = flist; 260852Svi117747 if ((*cl_callback)(&cl_sctpi, arg) != 0) { 261852Svi117747 kmem_free(slist, ssize); 262852Svi117747 kmem_free(flist, fsize); 263852Svi117747 SCTP_REFRELE(sctp); 264852Svi117747 return (1); 265852Svi117747 } 266852Svi117747 /* list will be freed by cl_callback */ 267852Svi117747 sctp_prev = sctp; 268852Svi117747 mutex_enter(&sctp_g_lock); 269852Svi117747 sctp = list_next(&sctp_g_list, sctp); 270852Svi117747 } 271852Svi117747 mutex_exit(&sctp_g_lock); 272852Svi117747 if (sctp_prev != NULL) 273852Svi117747 SCTP_REFRELE(sctp_prev); 274852Svi117747 return (0); 275852Svi117747 } 276852Svi117747 2770Sstevel@tonic-gate sctp_t * 2780Sstevel@tonic-gate sctp_conn_match(in6_addr_t *faddr, in6_addr_t *laddr, uint32_t ports, 2790Sstevel@tonic-gate uint_t ipif_seqid, zoneid_t zoneid) 2800Sstevel@tonic-gate { 2810Sstevel@tonic-gate sctp_tf_t *tf; 2820Sstevel@tonic-gate sctp_t *sctp; 2830Sstevel@tonic-gate sctp_faddr_t *fp; 2840Sstevel@tonic-gate 2850Sstevel@tonic-gate tf = &(sctp_conn_fanout[SCTP_CONN_HASH(ports)]); 2860Sstevel@tonic-gate mutex_enter(&tf->tf_lock); 2870Sstevel@tonic-gate 2880Sstevel@tonic-gate for (sctp = tf->tf_sctp; sctp; sctp = sctp->sctp_conn_hash_next) { 2892263Ssommerfe if (ports != sctp->sctp_ports || 2902263Ssommerfe !IPCL_ZONE_MATCH(sctp->sctp_connp, zoneid)) { 2910Sstevel@tonic-gate continue; 2920Sstevel@tonic-gate } 2930Sstevel@tonic-gate 2940Sstevel@tonic-gate /* check for faddr match */ 2950Sstevel@tonic-gate for (fp = sctp->sctp_faddrs; fp; fp = fp->next) { 2960Sstevel@tonic-gate if (IN6_ARE_ADDR_EQUAL(faddr, &fp->faddr)) { 2970Sstevel@tonic-gate break; 2980Sstevel@tonic-gate } 2990Sstevel@tonic-gate } 3000Sstevel@tonic-gate 3010Sstevel@tonic-gate if (!fp) { 3020Sstevel@tonic-gate /* no faddr match; keep looking */ 3030Sstevel@tonic-gate continue; 3040Sstevel@tonic-gate } 3050Sstevel@tonic-gate 3060Sstevel@tonic-gate /* check for laddr match */ 3070Sstevel@tonic-gate if (ipif_seqid == 0) { 308852Svi117747 if (sctp_saddr_lookup(sctp, laddr, 0) != NULL) { 3090Sstevel@tonic-gate SCTP_REFHOLD(sctp); 3100Sstevel@tonic-gate goto done; 3110Sstevel@tonic-gate } 3120Sstevel@tonic-gate } else { 3130Sstevel@tonic-gate if (sctp_ipif_lookup(sctp, ipif_seqid) != NULL) { 3140Sstevel@tonic-gate SCTP_REFHOLD(sctp); 3150Sstevel@tonic-gate goto done; 3160Sstevel@tonic-gate } 3170Sstevel@tonic-gate /* no match; continue to the next in the chain */ 3180Sstevel@tonic-gate } 3190Sstevel@tonic-gate } 3200Sstevel@tonic-gate 3210Sstevel@tonic-gate done: 3220Sstevel@tonic-gate mutex_exit(&tf->tf_lock); 3230Sstevel@tonic-gate return (sctp); 3240Sstevel@tonic-gate } 3250Sstevel@tonic-gate 3260Sstevel@tonic-gate static sctp_t * 3270Sstevel@tonic-gate listen_match(in6_addr_t *laddr, uint32_t ports, uint_t ipif_seqid, 3280Sstevel@tonic-gate zoneid_t zoneid) 3290Sstevel@tonic-gate { 3300Sstevel@tonic-gate sctp_t *sctp; 3310Sstevel@tonic-gate sctp_tf_t *tf; 3320Sstevel@tonic-gate uint16_t lport; 3330Sstevel@tonic-gate 3340Sstevel@tonic-gate lport = ((uint16_t *)&ports)[1]; 3350Sstevel@tonic-gate 3360Sstevel@tonic-gate tf = &(sctp_listen_fanout[SCTP_LISTEN_HASH(ntohs(lport))]); 3370Sstevel@tonic-gate mutex_enter(&tf->tf_lock); 3380Sstevel@tonic-gate 3390Sstevel@tonic-gate for (sctp = tf->tf_sctp; sctp; sctp = sctp->sctp_listen_hash_next) { 3402263Ssommerfe if (lport != sctp->sctp_lport || 3412263Ssommerfe !IPCL_ZONE_MATCH(sctp->sctp_connp, zoneid)) { 3420Sstevel@tonic-gate continue; 3430Sstevel@tonic-gate } 3440Sstevel@tonic-gate 3450Sstevel@tonic-gate if (ipif_seqid == 0) { 346852Svi117747 if (sctp_saddr_lookup(sctp, laddr, 0) != NULL) { 3470Sstevel@tonic-gate SCTP_REFHOLD(sctp); 3480Sstevel@tonic-gate goto done; 3490Sstevel@tonic-gate } 3500Sstevel@tonic-gate } else { 3510Sstevel@tonic-gate if (sctp_ipif_lookup(sctp, ipif_seqid) != NULL) { 3520Sstevel@tonic-gate SCTP_REFHOLD(sctp); 3530Sstevel@tonic-gate goto done; 3540Sstevel@tonic-gate } 3550Sstevel@tonic-gate } 3560Sstevel@tonic-gate /* no match; continue to the next in the chain */ 3570Sstevel@tonic-gate } 3580Sstevel@tonic-gate 3590Sstevel@tonic-gate done: 3600Sstevel@tonic-gate mutex_exit(&tf->tf_lock); 3610Sstevel@tonic-gate return (sctp); 3620Sstevel@tonic-gate } 3630Sstevel@tonic-gate 3641676Sjpk /* called by ipsec_sctp_pol */ 3650Sstevel@tonic-gate conn_t * 3660Sstevel@tonic-gate sctp_find_conn(in6_addr_t *src, in6_addr_t *dst, uint32_t ports, 3670Sstevel@tonic-gate uint_t ipif_seqid, zoneid_t zoneid) 3680Sstevel@tonic-gate { 3690Sstevel@tonic-gate sctp_t *sctp; 3700Sstevel@tonic-gate 3710Sstevel@tonic-gate if ((sctp = sctp_conn_match(src, dst, ports, ipif_seqid, 3720Sstevel@tonic-gate zoneid)) == NULL) { 3730Sstevel@tonic-gate /* Not in conn fanout; check listen fanout */ 3740Sstevel@tonic-gate if ((sctp = listen_match(dst, ports, ipif_seqid, 3750Sstevel@tonic-gate zoneid)) == NULL) { 3760Sstevel@tonic-gate return (NULL); 3770Sstevel@tonic-gate } 3780Sstevel@tonic-gate } 3790Sstevel@tonic-gate return (sctp->sctp_connp); 3800Sstevel@tonic-gate } 3810Sstevel@tonic-gate 3821676Sjpk conn_t * 3831676Sjpk sctp_fanout(in6_addr_t *src, in6_addr_t *dst, uint32_t ports, 3841676Sjpk uint_t ipif_seqid, zoneid_t zoneid, mblk_t *mp) 3851676Sjpk { 3861676Sjpk sctp_t *sctp; 3872776Skp158701 boolean_t shared_addr; 3881676Sjpk 3891676Sjpk if ((sctp = sctp_conn_match(src, dst, ports, ipif_seqid, 3901676Sjpk zoneid)) == NULL) { 3912776Skp158701 shared_addr = (zoneid == ALL_ZONES); 3922776Skp158701 if (shared_addr) { 3931676Sjpk zoneid = tsol_mlp_findzone(IPPROTO_SCTP, 3941676Sjpk htons(ntohl(ports) & 0xFFFF)); 3951676Sjpk /* 3961676Sjpk * If no shared MLP is found, tsol_mlp_findzone returns 3971676Sjpk * ALL_ZONES. In that case, we assume it's SLP, and 3981676Sjpk * search for the zone based on the packet label. 3991676Sjpk * That will also return ALL_ZONES on failure. 4001676Sjpk */ 4011676Sjpk if (zoneid == ALL_ZONES) 4021676Sjpk zoneid = tsol_packet_to_zoneid(mp); 4031676Sjpk if (zoneid == ALL_ZONES) 4041676Sjpk return (NULL); 4051676Sjpk } 4061676Sjpk /* Not in conn fanout; check listen fanout */ 4071676Sjpk if ((sctp = listen_match(dst, ports, ipif_seqid, 4081676Sjpk zoneid)) == NULL) { 4091676Sjpk return (NULL); 4101676Sjpk } 4112776Skp158701 /* 4122776Skp158701 * On systems running trusted extensions, check if dst 4132776Skp158701 * should accept the packet. "IPV6_VERSION" indicates 4142776Skp158701 * that dst is in 16 byte AF_INET6 format. IPv4-mapped 4152776Skp158701 * IPv6 addresses are supported. 4162776Skp158701 */ 4172776Skp158701 if (is_system_labeled() && 4182776Skp158701 !tsol_receive_local(mp, dst, IPV6_VERSION, 4192776Skp158701 shared_addr, sctp->sctp_connp)) { 4202776Skp158701 DTRACE_PROBE3( 4212776Skp158701 tx__ip__log__info__classify__sctp, 4222776Skp158701 char *, 4232776Skp158701 "connp(1) could not receive mp(2)", 4242776Skp158701 conn_t *, sctp->sctp_connp, mblk_t *, mp); 4252776Skp158701 SCTP_REFRELE(sctp); 4262776Skp158701 return (NULL); 4272776Skp158701 } 4281676Sjpk } 4291676Sjpk return (sctp->sctp_connp); 4301676Sjpk } 4311676Sjpk 4320Sstevel@tonic-gate /* 4330Sstevel@tonic-gate * Fanout for SCTP packets 4340Sstevel@tonic-gate * The caller puts <fport, lport> in the ports parameter. 4350Sstevel@tonic-gate */ 4360Sstevel@tonic-gate /* ARGSUSED */ 4370Sstevel@tonic-gate void 4380Sstevel@tonic-gate ip_fanout_sctp(mblk_t *mp, ill_t *recv_ill, ipha_t *ipha, 4390Sstevel@tonic-gate uint32_t ports, uint_t flags, boolean_t mctl_present, boolean_t ip_policy, 4400Sstevel@tonic-gate uint_t ipif_seqid, zoneid_t zoneid) 4410Sstevel@tonic-gate { 4420Sstevel@tonic-gate sctp_t *sctp; 4430Sstevel@tonic-gate boolean_t isv4; 4440Sstevel@tonic-gate conn_t *connp; 4450Sstevel@tonic-gate mblk_t *first_mp; 4460Sstevel@tonic-gate ip6_t *ip6h; 4470Sstevel@tonic-gate in6_addr_t map_src, map_dst; 4480Sstevel@tonic-gate in6_addr_t *src, *dst; 4490Sstevel@tonic-gate 4500Sstevel@tonic-gate first_mp = mp; 4510Sstevel@tonic-gate if (mctl_present) { 4520Sstevel@tonic-gate mp = first_mp->b_cont; 4530Sstevel@tonic-gate ASSERT(mp != NULL); 4540Sstevel@tonic-gate } 4550Sstevel@tonic-gate 4560Sstevel@tonic-gate /* Assume IP provides aligned packets - otherwise toss */ 4570Sstevel@tonic-gate if (!OK_32PTR(mp->b_rptr)) { 4583284Sapersson BUMP_MIB(recv_ill->ill_ip_mib, ipIfStatsInDiscards); 4590Sstevel@tonic-gate freemsg(first_mp); 4600Sstevel@tonic-gate return; 4610Sstevel@tonic-gate } 4620Sstevel@tonic-gate 4630Sstevel@tonic-gate if (IPH_HDR_VERSION(ipha) == IPV6_VERSION) { 4640Sstevel@tonic-gate ip6h = (ip6_t *)ipha; 4650Sstevel@tonic-gate src = &ip6h->ip6_src; 4660Sstevel@tonic-gate dst = &ip6h->ip6_dst; 4670Sstevel@tonic-gate isv4 = B_FALSE; 4680Sstevel@tonic-gate } else { 4690Sstevel@tonic-gate ip6h = NULL; 4700Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(ipha->ipha_src, &map_src); 4710Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(ipha->ipha_dst, &map_dst); 4720Sstevel@tonic-gate src = &map_src; 4730Sstevel@tonic-gate dst = &map_dst; 4740Sstevel@tonic-gate isv4 = B_TRUE; 4750Sstevel@tonic-gate } 4761676Sjpk if ((connp = sctp_fanout(src, dst, ports, ipif_seqid, zoneid, mp)) == 4770Sstevel@tonic-gate NULL) { 4782429Skcpoon ip_fanout_sctp_raw(first_mp, recv_ill, ipha, isv4, 4790Sstevel@tonic-gate ports, mctl_present, flags, ip_policy, 4800Sstevel@tonic-gate ipif_seqid, zoneid); 4810Sstevel@tonic-gate return; 4820Sstevel@tonic-gate } 4830Sstevel@tonic-gate sctp = CONN2SCTP(connp); 4840Sstevel@tonic-gate 4850Sstevel@tonic-gate /* Found a client; up it goes */ 4863284Sapersson BUMP_MIB(recv_ill->ill_ip_mib, ipIfStatsHCInDelivers); 4870Sstevel@tonic-gate 4880Sstevel@tonic-gate /* 4890Sstevel@tonic-gate * We check some fields in conn_t without holding a lock. 4900Sstevel@tonic-gate * This should be fine. 4910Sstevel@tonic-gate */ 4920Sstevel@tonic-gate if (CONN_INBOUND_POLICY_PRESENT(connp) || mctl_present) { 4930Sstevel@tonic-gate first_mp = ipsec_check_inbound_policy(first_mp, connp, 4940Sstevel@tonic-gate ipha, NULL, mctl_present); 4950Sstevel@tonic-gate if (first_mp == NULL) { 4960Sstevel@tonic-gate SCTP_REFRELE(sctp); 4970Sstevel@tonic-gate return; 4980Sstevel@tonic-gate } 4990Sstevel@tonic-gate } 5000Sstevel@tonic-gate 5010Sstevel@tonic-gate /* Initiate IPPF processing for fastpath */ 5020Sstevel@tonic-gate if (IPP_ENABLED(IPP_LOCAL_IN)) { 5030Sstevel@tonic-gate ip_process(IPP_LOCAL_IN, &mp, 5040Sstevel@tonic-gate recv_ill->ill_phyint->phyint_ifindex); 5050Sstevel@tonic-gate if (mp == NULL) { 5060Sstevel@tonic-gate SCTP_REFRELE(sctp); 5070Sstevel@tonic-gate if (mctl_present) 5080Sstevel@tonic-gate freeb(first_mp); 5090Sstevel@tonic-gate return; 5100Sstevel@tonic-gate } else if (mctl_present) { 5110Sstevel@tonic-gate /* 5120Sstevel@tonic-gate * ip_process might return a new mp. 5130Sstevel@tonic-gate */ 5140Sstevel@tonic-gate ASSERT(first_mp != mp); 5150Sstevel@tonic-gate first_mp->b_cont = mp; 5160Sstevel@tonic-gate } else { 5170Sstevel@tonic-gate first_mp = mp; 5180Sstevel@tonic-gate } 5190Sstevel@tonic-gate } 5200Sstevel@tonic-gate 5210Sstevel@tonic-gate if (connp->conn_recvif || connp->conn_recvslla || 522*3318Srshoaib connp->conn_ip_recvpktinfo) { 5230Sstevel@tonic-gate int in_flags = 0; 5240Sstevel@tonic-gate 525*3318Srshoaib if (connp->conn_recvif || connp->conn_ip_recvpktinfo) { 5260Sstevel@tonic-gate in_flags = IPF_RECVIF; 5270Sstevel@tonic-gate } 5280Sstevel@tonic-gate if (connp->conn_recvslla) { 5290Sstevel@tonic-gate in_flags |= IPF_RECVSLLA; 5300Sstevel@tonic-gate } 5310Sstevel@tonic-gate if (isv4) { 532*3318Srshoaib mp = ip_add_info(mp, recv_ill, in_flags, 533*3318Srshoaib IPCL_ZONEID(connp)); 5340Sstevel@tonic-gate } else { 5350Sstevel@tonic-gate mp = ip_add_info_v6(mp, recv_ill, &ip6h->ip6_dst); 5360Sstevel@tonic-gate } 5370Sstevel@tonic-gate if (mp == NULL) { 5380Sstevel@tonic-gate SCTP_REFRELE(sctp); 5390Sstevel@tonic-gate if (mctl_present) 5400Sstevel@tonic-gate freeb(first_mp); 5410Sstevel@tonic-gate return; 5420Sstevel@tonic-gate } else if (mctl_present) { 5430Sstevel@tonic-gate /* 5440Sstevel@tonic-gate * ip_add_info might return a new mp. 5450Sstevel@tonic-gate */ 5460Sstevel@tonic-gate ASSERT(first_mp != mp); 5470Sstevel@tonic-gate first_mp->b_cont = mp; 5480Sstevel@tonic-gate } else { 5490Sstevel@tonic-gate first_mp = mp; 5500Sstevel@tonic-gate } 5510Sstevel@tonic-gate } 5520Sstevel@tonic-gate 5530Sstevel@tonic-gate mutex_enter(&sctp->sctp_lock); 5540Sstevel@tonic-gate if (sctp->sctp_running) { 5550Sstevel@tonic-gate if (mctl_present) 5560Sstevel@tonic-gate mp->b_prev = first_mp; 5570Sstevel@tonic-gate if (!sctp_add_recvq(sctp, mp, B_FALSE)) { 5583284Sapersson BUMP_MIB(recv_ill->ill_ip_mib, ipIfStatsInDiscards); 5590Sstevel@tonic-gate freemsg(first_mp); 5600Sstevel@tonic-gate } 5610Sstevel@tonic-gate mutex_exit(&sctp->sctp_lock); 5620Sstevel@tonic-gate } else { 5630Sstevel@tonic-gate sctp->sctp_running = B_TRUE; 5640Sstevel@tonic-gate mutex_exit(&sctp->sctp_lock); 5650Sstevel@tonic-gate 5660Sstevel@tonic-gate mutex_enter(&sctp->sctp_recvq_lock); 5670Sstevel@tonic-gate if (sctp->sctp_recvq != NULL) { 5680Sstevel@tonic-gate if (mctl_present) 5690Sstevel@tonic-gate mp->b_prev = first_mp; 5700Sstevel@tonic-gate if (!sctp_add_recvq(sctp, mp, B_TRUE)) { 5713284Sapersson BUMP_MIB(recv_ill->ill_ip_mib, 5723284Sapersson ipIfStatsInDiscards); 5730Sstevel@tonic-gate freemsg(first_mp); 5740Sstevel@tonic-gate } 5750Sstevel@tonic-gate mutex_exit(&sctp->sctp_recvq_lock); 5760Sstevel@tonic-gate WAKE_SCTP(sctp); 5770Sstevel@tonic-gate } else { 5780Sstevel@tonic-gate mutex_exit(&sctp->sctp_recvq_lock); 5790Sstevel@tonic-gate sctp_input_data(sctp, mp, (mctl_present ? first_mp : 5800Sstevel@tonic-gate NULL)); 5810Sstevel@tonic-gate WAKE_SCTP(sctp); 5820Sstevel@tonic-gate sctp_process_sendq(sctp); 5830Sstevel@tonic-gate } 5840Sstevel@tonic-gate } 5850Sstevel@tonic-gate SCTP_REFRELE(sctp); 5860Sstevel@tonic-gate } 5870Sstevel@tonic-gate 5880Sstevel@tonic-gate void 5890Sstevel@tonic-gate sctp_conn_hash_remove(sctp_t *sctp) 5900Sstevel@tonic-gate { 5910Sstevel@tonic-gate sctp_tf_t *tf = sctp->sctp_conn_tfp; 5920Sstevel@tonic-gate 5930Sstevel@tonic-gate if (!tf) { 5940Sstevel@tonic-gate return; 5950Sstevel@tonic-gate } 596852Svi117747 /* 597852Svi117747 * On a clustered note send this notification to the clustering 598852Svi117747 * subsystem. 599852Svi117747 */ 600852Svi117747 if (cl_sctp_disconnect != NULL) { 601852Svi117747 (*cl_sctp_disconnect)(sctp->sctp_family, 602852Svi117747 (cl_sctp_handle_t)sctp); 603852Svi117747 } 604852Svi117747 6050Sstevel@tonic-gate mutex_enter(&tf->tf_lock); 6060Sstevel@tonic-gate ASSERT(tf->tf_sctp); 6070Sstevel@tonic-gate if (tf->tf_sctp == sctp) { 6080Sstevel@tonic-gate tf->tf_sctp = sctp->sctp_conn_hash_next; 6090Sstevel@tonic-gate if (sctp->sctp_conn_hash_next) { 6100Sstevel@tonic-gate ASSERT(tf->tf_sctp->sctp_conn_hash_prev == sctp); 6110Sstevel@tonic-gate tf->tf_sctp->sctp_conn_hash_prev = NULL; 6120Sstevel@tonic-gate } 6130Sstevel@tonic-gate } else { 6140Sstevel@tonic-gate ASSERT(sctp->sctp_conn_hash_prev); 6150Sstevel@tonic-gate ASSERT(sctp->sctp_conn_hash_prev->sctp_conn_hash_next == sctp); 6160Sstevel@tonic-gate sctp->sctp_conn_hash_prev->sctp_conn_hash_next = 6170Sstevel@tonic-gate sctp->sctp_conn_hash_next; 6180Sstevel@tonic-gate 6190Sstevel@tonic-gate if (sctp->sctp_conn_hash_next) { 6200Sstevel@tonic-gate ASSERT(sctp->sctp_conn_hash_next->sctp_conn_hash_prev 6210Sstevel@tonic-gate == sctp); 6220Sstevel@tonic-gate sctp->sctp_conn_hash_next->sctp_conn_hash_prev = 6230Sstevel@tonic-gate sctp->sctp_conn_hash_prev; 6240Sstevel@tonic-gate } 6250Sstevel@tonic-gate } 6260Sstevel@tonic-gate sctp->sctp_conn_hash_next = NULL; 6270Sstevel@tonic-gate sctp->sctp_conn_hash_prev = NULL; 6280Sstevel@tonic-gate sctp->sctp_conn_tfp = NULL; 6290Sstevel@tonic-gate mutex_exit(&tf->tf_lock); 6300Sstevel@tonic-gate } 6310Sstevel@tonic-gate 6320Sstevel@tonic-gate void 6330Sstevel@tonic-gate sctp_conn_hash_insert(sctp_tf_t *tf, sctp_t *sctp, int caller_holds_lock) 6340Sstevel@tonic-gate { 6350Sstevel@tonic-gate if (sctp->sctp_conn_tfp) { 6360Sstevel@tonic-gate sctp_conn_hash_remove(sctp); 6370Sstevel@tonic-gate } 6380Sstevel@tonic-gate 6390Sstevel@tonic-gate if (!caller_holds_lock) { 6400Sstevel@tonic-gate mutex_enter(&tf->tf_lock); 6410Sstevel@tonic-gate } else { 6420Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tf->tf_lock)); 6430Sstevel@tonic-gate } 6440Sstevel@tonic-gate 6450Sstevel@tonic-gate sctp->sctp_conn_hash_next = tf->tf_sctp; 6460Sstevel@tonic-gate if (tf->tf_sctp) { 6470Sstevel@tonic-gate tf->tf_sctp->sctp_conn_hash_prev = sctp; 6480Sstevel@tonic-gate } 6490Sstevel@tonic-gate sctp->sctp_conn_hash_prev = NULL; 6500Sstevel@tonic-gate tf->tf_sctp = sctp; 6510Sstevel@tonic-gate sctp->sctp_conn_tfp = tf; 6520Sstevel@tonic-gate if (!caller_holds_lock) { 6530Sstevel@tonic-gate mutex_exit(&tf->tf_lock); 6540Sstevel@tonic-gate } 6550Sstevel@tonic-gate } 6560Sstevel@tonic-gate 6570Sstevel@tonic-gate void 6580Sstevel@tonic-gate sctp_listen_hash_remove(sctp_t *sctp) 6590Sstevel@tonic-gate { 6600Sstevel@tonic-gate sctp_tf_t *tf = sctp->sctp_listen_tfp; 6610Sstevel@tonic-gate 6620Sstevel@tonic-gate if (!tf) { 6630Sstevel@tonic-gate return; 6640Sstevel@tonic-gate } 665852Svi117747 /* 666852Svi117747 * On a clustered note send this notification to the clustering 667852Svi117747 * subsystem. 668852Svi117747 */ 669852Svi117747 if (cl_sctp_unlisten != NULL) { 670852Svi117747 uchar_t *slist; 671852Svi117747 ssize_t ssize; 672852Svi117747 673852Svi117747 ssize = sizeof (in6_addr_t) * sctp->sctp_nsaddrs; 674852Svi117747 slist = kmem_alloc(ssize, KM_SLEEP); 675852Svi117747 sctp_get_saddr_list(sctp, slist, ssize); 676852Svi117747 (*cl_sctp_unlisten)(sctp->sctp_family, slist, 677852Svi117747 sctp->sctp_nsaddrs, sctp->sctp_lport); 678852Svi117747 /* list will be freed by the clustering module */ 679852Svi117747 } 6800Sstevel@tonic-gate 6810Sstevel@tonic-gate mutex_enter(&tf->tf_lock); 6820Sstevel@tonic-gate ASSERT(tf->tf_sctp); 6830Sstevel@tonic-gate if (tf->tf_sctp == sctp) { 6840Sstevel@tonic-gate tf->tf_sctp = sctp->sctp_listen_hash_next; 6850Sstevel@tonic-gate if (sctp->sctp_listen_hash_next) { 6860Sstevel@tonic-gate ASSERT(tf->tf_sctp->sctp_listen_hash_prev == sctp); 6870Sstevel@tonic-gate tf->tf_sctp->sctp_listen_hash_prev = NULL; 6880Sstevel@tonic-gate } 6890Sstevel@tonic-gate } else { 6900Sstevel@tonic-gate ASSERT(sctp->sctp_listen_hash_prev); 6910Sstevel@tonic-gate ASSERT(sctp->sctp_listen_hash_prev->sctp_listen_hash_next == 6920Sstevel@tonic-gate sctp); 6930Sstevel@tonic-gate sctp->sctp_listen_hash_prev->sctp_listen_hash_next = 6940Sstevel@tonic-gate sctp->sctp_listen_hash_next; 6950Sstevel@tonic-gate 6960Sstevel@tonic-gate if (sctp->sctp_listen_hash_next) { 6970Sstevel@tonic-gate ASSERT( 6980Sstevel@tonic-gate sctp->sctp_listen_hash_next->sctp_listen_hash_prev == 6990Sstevel@tonic-gate sctp); 7000Sstevel@tonic-gate sctp->sctp_listen_hash_next->sctp_listen_hash_prev = 7010Sstevel@tonic-gate sctp->sctp_listen_hash_prev; 7020Sstevel@tonic-gate } 7030Sstevel@tonic-gate } 7040Sstevel@tonic-gate sctp->sctp_listen_hash_next = NULL; 7050Sstevel@tonic-gate sctp->sctp_listen_hash_prev = NULL; 7060Sstevel@tonic-gate sctp->sctp_listen_tfp = NULL; 7070Sstevel@tonic-gate mutex_exit(&tf->tf_lock); 7080Sstevel@tonic-gate } 7090Sstevel@tonic-gate 7100Sstevel@tonic-gate void 7110Sstevel@tonic-gate sctp_listen_hash_insert(sctp_tf_t *tf, sctp_t *sctp) 7120Sstevel@tonic-gate { 7130Sstevel@tonic-gate if (sctp->sctp_listen_tfp) { 7140Sstevel@tonic-gate sctp_listen_hash_remove(sctp); 7150Sstevel@tonic-gate } 7160Sstevel@tonic-gate 7170Sstevel@tonic-gate mutex_enter(&tf->tf_lock); 7180Sstevel@tonic-gate sctp->sctp_listen_hash_next = tf->tf_sctp; 7190Sstevel@tonic-gate if (tf->tf_sctp) { 7200Sstevel@tonic-gate tf->tf_sctp->sctp_listen_hash_prev = sctp; 7210Sstevel@tonic-gate } 7220Sstevel@tonic-gate sctp->sctp_listen_hash_prev = NULL; 7230Sstevel@tonic-gate tf->tf_sctp = sctp; 7240Sstevel@tonic-gate sctp->sctp_listen_tfp = tf; 7250Sstevel@tonic-gate mutex_exit(&tf->tf_lock); 726852Svi117747 /* 727852Svi117747 * On a clustered note send this notification to the clustering 728852Svi117747 * subsystem. 729852Svi117747 */ 730852Svi117747 if (cl_sctp_listen != NULL) { 731852Svi117747 uchar_t *slist; 732852Svi117747 ssize_t ssize; 733852Svi117747 734852Svi117747 ssize = sizeof (in6_addr_t) * sctp->sctp_nsaddrs; 735852Svi117747 slist = kmem_alloc(ssize, KM_SLEEP); 736852Svi117747 sctp_get_saddr_list(sctp, slist, ssize); 737852Svi117747 (*cl_sctp_listen)(sctp->sctp_family, slist, 738852Svi117747 sctp->sctp_nsaddrs, sctp->sctp_lport); 739852Svi117747 /* list will be freed by the clustering module */ 740852Svi117747 } 7410Sstevel@tonic-gate } 7420Sstevel@tonic-gate 7430Sstevel@tonic-gate /* 7440Sstevel@tonic-gate * Hash list insertion routine for sctp_t structures. 7450Sstevel@tonic-gate * Inserts entries with the ones bound to a specific IP address first 7460Sstevel@tonic-gate * followed by those bound to INADDR_ANY. 7470Sstevel@tonic-gate */ 7480Sstevel@tonic-gate void 7490Sstevel@tonic-gate sctp_bind_hash_insert(sctp_tf_t *tbf, sctp_t *sctp, int caller_holds_lock) 7500Sstevel@tonic-gate { 7510Sstevel@tonic-gate sctp_t **sctpp; 7520Sstevel@tonic-gate sctp_t *sctpnext; 7530Sstevel@tonic-gate 7540Sstevel@tonic-gate if (sctp->sctp_ptpbhn != NULL) { 7550Sstevel@tonic-gate ASSERT(!caller_holds_lock); 7560Sstevel@tonic-gate sctp_bind_hash_remove(sctp); 7570Sstevel@tonic-gate } 7580Sstevel@tonic-gate sctpp = &tbf->tf_sctp; 7590Sstevel@tonic-gate if (!caller_holds_lock) { 7600Sstevel@tonic-gate mutex_enter(&tbf->tf_lock); 7610Sstevel@tonic-gate } else { 7620Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tbf->tf_lock)); 7630Sstevel@tonic-gate } 7640Sstevel@tonic-gate sctpnext = sctpp[0]; 7650Sstevel@tonic-gate if (sctpnext) { 7660Sstevel@tonic-gate sctpnext->sctp_ptpbhn = &sctp->sctp_bind_hash; 7670Sstevel@tonic-gate } 7680Sstevel@tonic-gate sctp->sctp_bind_hash = sctpnext; 7690Sstevel@tonic-gate sctp->sctp_ptpbhn = sctpp; 7700Sstevel@tonic-gate sctpp[0] = sctp; 7710Sstevel@tonic-gate /* For sctp_*_hash_remove */ 7720Sstevel@tonic-gate sctp->sctp_bind_lockp = &tbf->tf_lock; 7730Sstevel@tonic-gate if (!caller_holds_lock) 7740Sstevel@tonic-gate mutex_exit(&tbf->tf_lock); 7750Sstevel@tonic-gate } 7760Sstevel@tonic-gate 7770Sstevel@tonic-gate /* 7780Sstevel@tonic-gate * Hash list removal routine for sctp_t structures. 7790Sstevel@tonic-gate */ 7800Sstevel@tonic-gate void 7810Sstevel@tonic-gate sctp_bind_hash_remove(sctp_t *sctp) 7820Sstevel@tonic-gate { 7830Sstevel@tonic-gate sctp_t *sctpnext; 7840Sstevel@tonic-gate kmutex_t *lockp; 7850Sstevel@tonic-gate 7860Sstevel@tonic-gate lockp = sctp->sctp_bind_lockp; 7870Sstevel@tonic-gate 7880Sstevel@tonic-gate if (sctp->sctp_ptpbhn == NULL) 7890Sstevel@tonic-gate return; 7900Sstevel@tonic-gate 7910Sstevel@tonic-gate ASSERT(lockp != NULL); 7920Sstevel@tonic-gate mutex_enter(lockp); 7930Sstevel@tonic-gate if (sctp->sctp_ptpbhn) { 7940Sstevel@tonic-gate sctpnext = sctp->sctp_bind_hash; 7950Sstevel@tonic-gate if (sctpnext) { 7960Sstevel@tonic-gate sctpnext->sctp_ptpbhn = sctp->sctp_ptpbhn; 7970Sstevel@tonic-gate sctp->sctp_bind_hash = NULL; 7980Sstevel@tonic-gate } 7990Sstevel@tonic-gate *sctp->sctp_ptpbhn = sctpnext; 8000Sstevel@tonic-gate sctp->sctp_ptpbhn = NULL; 8010Sstevel@tonic-gate } 8020Sstevel@tonic-gate mutex_exit(lockp); 8030Sstevel@tonic-gate sctp->sctp_bind_lockp = NULL; 8040Sstevel@tonic-gate } 8050Sstevel@tonic-gate 8060Sstevel@tonic-gate /* 8070Sstevel@tonic-gate * Similar to but more general than ip_sctp's conn_match(). 8080Sstevel@tonic-gate * 8090Sstevel@tonic-gate * Matches sets of addresses as follows: if the argument addr set is 8100Sstevel@tonic-gate * a complete subset of the corresponding addr set in the sctp_t, it 8110Sstevel@tonic-gate * is a match. 8120Sstevel@tonic-gate * 8130Sstevel@tonic-gate * Caller must hold tf->tf_lock. 8140Sstevel@tonic-gate * 8150Sstevel@tonic-gate * Returns with a SCTP_REFHOLD sctp structure. Caller must do a SCTP_REFRELE. 8160Sstevel@tonic-gate */ 8170Sstevel@tonic-gate sctp_t * 8180Sstevel@tonic-gate sctp_lookup(sctp_t *sctp1, in6_addr_t *faddr, sctp_tf_t *tf, uint32_t *ports, 8190Sstevel@tonic-gate int min_state) 8200Sstevel@tonic-gate { 8210Sstevel@tonic-gate 8220Sstevel@tonic-gate sctp_t *sctp; 8230Sstevel@tonic-gate sctp_faddr_t *fp; 8240Sstevel@tonic-gate 8250Sstevel@tonic-gate ASSERT(MUTEX_HELD(&tf->tf_lock)); 8260Sstevel@tonic-gate 8270Sstevel@tonic-gate for (sctp = tf->tf_sctp; sctp; sctp = sctp->sctp_conn_hash_next) { 8280Sstevel@tonic-gate if (*ports != sctp->sctp_ports || sctp->sctp_state < 8290Sstevel@tonic-gate min_state) { 8300Sstevel@tonic-gate continue; 8310Sstevel@tonic-gate } 8320Sstevel@tonic-gate 8330Sstevel@tonic-gate /* check for faddr match */ 8340Sstevel@tonic-gate for (fp = sctp->sctp_faddrs; fp; fp = fp->next) { 8350Sstevel@tonic-gate if (IN6_ARE_ADDR_EQUAL(faddr, &fp->faddr)) { 8360Sstevel@tonic-gate break; 8370Sstevel@tonic-gate } 8380Sstevel@tonic-gate } 8390Sstevel@tonic-gate 8400Sstevel@tonic-gate if (!fp) { 8410Sstevel@tonic-gate /* no faddr match; keep looking */ 8420Sstevel@tonic-gate continue; 8430Sstevel@tonic-gate } 8440Sstevel@tonic-gate 8450Sstevel@tonic-gate /* check for laddr subset match */ 8460Sstevel@tonic-gate if (sctp_compare_saddrs(sctp1, sctp) <= SCTP_ADDR_SUBSET) { 8470Sstevel@tonic-gate goto done; 8480Sstevel@tonic-gate } 8490Sstevel@tonic-gate 8500Sstevel@tonic-gate /* no match; continue searching */ 8510Sstevel@tonic-gate } 8520Sstevel@tonic-gate 8530Sstevel@tonic-gate done: 8540Sstevel@tonic-gate if (sctp) { 8550Sstevel@tonic-gate SCTP_REFHOLD(sctp); 8560Sstevel@tonic-gate } 8570Sstevel@tonic-gate return (sctp); 8580Sstevel@tonic-gate } 8590Sstevel@tonic-gate 8600Sstevel@tonic-gate boolean_t 8610Sstevel@tonic-gate ip_fanout_sctp_raw_match(conn_t *connp, uint32_t ports, ipha_t *ipha) 8620Sstevel@tonic-gate { 8630Sstevel@tonic-gate uint16_t lport; 8640Sstevel@tonic-gate 8650Sstevel@tonic-gate if (connp->conn_fully_bound) { 8660Sstevel@tonic-gate return (IPCL_CONN_MATCH(connp, IPPROTO_SCTP, ipha->ipha_src, 8670Sstevel@tonic-gate ipha->ipha_dst, ports)); 8680Sstevel@tonic-gate } else { 8690Sstevel@tonic-gate lport = htons(ntohl(ports) & 0xFFFF); 8700Sstevel@tonic-gate return (IPCL_BIND_MATCH(connp, IPPROTO_SCTP, ipha->ipha_dst, 8710Sstevel@tonic-gate lport)); 8720Sstevel@tonic-gate } 8730Sstevel@tonic-gate } 8740Sstevel@tonic-gate 8750Sstevel@tonic-gate boolean_t 8760Sstevel@tonic-gate ip_fanout_sctp_raw_match_v6(conn_t *connp, uint32_t ports, ip6_t *ip6h, 8770Sstevel@tonic-gate boolean_t for_v4) 8780Sstevel@tonic-gate { 8790Sstevel@tonic-gate uint16_t lport; 8800Sstevel@tonic-gate in6_addr_t v6dst; 8810Sstevel@tonic-gate 8820Sstevel@tonic-gate if (!for_v4 && connp->conn_fully_bound) { 8830Sstevel@tonic-gate return (IPCL_CONN_MATCH_V6(connp, IPPROTO_SCTP, ip6h->ip6_src, 8840Sstevel@tonic-gate ip6h->ip6_dst, ports)); 8850Sstevel@tonic-gate } else { 8860Sstevel@tonic-gate lport = htons(ntohl(ports) & 0xFFFF); 8870Sstevel@tonic-gate if (for_v4) 8880Sstevel@tonic-gate v6dst = ipv6_all_zeros; 8890Sstevel@tonic-gate else 8900Sstevel@tonic-gate v6dst = ip6h->ip6_dst; 8910Sstevel@tonic-gate return (IPCL_BIND_MATCH_V6(connp, IPPROTO_SCTP, v6dst, lport)); 8920Sstevel@tonic-gate } 8930Sstevel@tonic-gate } 894