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 5*1676Sjpk * Common Development and Distribution License (the "License"). 6*1676Sjpk * 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 /* 22*1676Sjpk * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <sys/types.h> 290Sstevel@tonic-gate #include <sys/systm.h> 300Sstevel@tonic-gate #include <sys/stream.h> 310Sstevel@tonic-gate #include <sys/ddi.h> 320Sstevel@tonic-gate #include <sys/sunddi.h> 330Sstevel@tonic-gate #include <sys/kmem.h> 340Sstevel@tonic-gate #include <sys/socket.h> 350Sstevel@tonic-gate #include <sys/sysmacros.h> 360Sstevel@tonic-gate #include <sys/list.h> 370Sstevel@tonic-gate 380Sstevel@tonic-gate #include <netinet/in.h> 390Sstevel@tonic-gate #include <netinet/ip6.h> 400Sstevel@tonic-gate #include <netinet/sctp.h> 410Sstevel@tonic-gate 420Sstevel@tonic-gate #include <inet/common.h> 430Sstevel@tonic-gate #include <inet/ip.h> 440Sstevel@tonic-gate #include <inet/ip6.h> 450Sstevel@tonic-gate #include <inet/ip_if.h> 460Sstevel@tonic-gate #include <inet/ipclassifier.h> 470Sstevel@tonic-gate #include <inet/sctp_ip.h> 480Sstevel@tonic-gate #include "sctp_impl.h" 490Sstevel@tonic-gate #include "sctp_addr.h" 500Sstevel@tonic-gate 510Sstevel@tonic-gate static void sctp_ipif_inactive(sctp_ipif_t *); 520Sstevel@tonic-gate static sctp_ipif_t *sctp_lookup_ipif_addr(in6_addr_t *, boolean_t, 53852Svi117747 zoneid_t zoneid, uint_t); 540Sstevel@tonic-gate static int sctp_get_all_ipifs(sctp_t *, int); 55852Svi117747 int sctp_valid_addr_list(sctp_t *, const void *, uint32_t, 56852Svi117747 uchar_t *, size_t); 570Sstevel@tonic-gate sctp_saddr_ipif_t *sctp_ipif_lookup(sctp_t *, uint_t); 58432Svi117747 static int sctp_ipif_hash_insert(sctp_t *, sctp_ipif_t *, int, 59432Svi117747 boolean_t dontsrc); 600Sstevel@tonic-gate static void sctp_ipif_hash_remove(sctp_t *, sctp_ipif_t *); 610Sstevel@tonic-gate static int sctp_compare_ipif_list(sctp_ipif_hash_t *, 620Sstevel@tonic-gate sctp_ipif_hash_t *); 630Sstevel@tonic-gate int sctp_compare_saddrs(sctp_t *, sctp_t *); 640Sstevel@tonic-gate static int sctp_copy_ipifs(sctp_ipif_hash_t *, sctp_t *, int); 650Sstevel@tonic-gate int sctp_dup_saddrs(sctp_t *, sctp_t *, int); 660Sstevel@tonic-gate void sctp_free_saddrs(sctp_t *); 670Sstevel@tonic-gate void sctp_update_ill(ill_t *, int); 680Sstevel@tonic-gate void sctp_update_ipif(ipif_t *, int); 690Sstevel@tonic-gate void sctp_move_ipif(ipif_t *, ill_t *, ill_t *); 700Sstevel@tonic-gate void sctp_del_saddr(sctp_t *, sctp_saddr_ipif_t *); 710Sstevel@tonic-gate void sctp_del_saddr_list(sctp_t *, const void *, int, 720Sstevel@tonic-gate boolean_t); 73852Svi117747 sctp_saddr_ipif_t *sctp_saddr_lookup(sctp_t *, in6_addr_t *, uint_t); 740Sstevel@tonic-gate in6_addr_t sctp_get_valid_addr(sctp_t *, boolean_t); 750Sstevel@tonic-gate int sctp_getmyaddrs(void *, void *, int *); 760Sstevel@tonic-gate void sctp_saddr_init(); 770Sstevel@tonic-gate void sctp_saddr_fini(); 78432Svi117747 790Sstevel@tonic-gate #define SCTP_IPIF_USABLE(sctp_ipif_state) \ 800Sstevel@tonic-gate ((sctp_ipif_state) == SCTP_IPIFS_UP || \ 81432Svi117747 (sctp_ipif_state) == SCTP_IPIFS_DOWN) 82432Svi117747 83432Svi117747 #define SCTP_IPIF_DISCARD(sctp_ipif_flags) \ 84432Svi117747 ((sctp_ipif_flags) & (IPIF_PRIVATE | IPIF_DEPRECATED)) 85432Svi117747 86852Svi117747 #define SCTP_IS_IPIF_LOOPBACK(ipif) \ 87852Svi117747 ((ipif)->sctp_ipif_ill->sctp_ill_flags & PHYI_LOOPBACK) 88852Svi117747 89852Svi117747 #define SCTP_IS_IPIF_LINKLOCAL(ipif) \ 90852Svi117747 ((ipif)->sctp_ipif_isv6 && \ 91852Svi117747 IN6_IS_ADDR_LINKLOCAL(&(ipif)->sctp_ipif_saddr)) 92432Svi117747 93432Svi117747 #define SCTP_UNSUPP_AF(ipif, supp_af) \ 94432Svi117747 ((!(ipif)->sctp_ipif_isv6 && !((supp_af) & PARM_SUPP_V4)) || \ 95432Svi117747 ((ipif)->sctp_ipif_isv6 && !((supp_af) & PARM_SUPP_V6))) 960Sstevel@tonic-gate 970Sstevel@tonic-gate #define SCTP_ILL_HASH_FN(index) ((index) % SCTP_ILL_HASH) 980Sstevel@tonic-gate #define SCTP_IPIF_HASH_FN(seqid) ((seqid) % SCTP_IPIF_HASH) 990Sstevel@tonic-gate #define SCTP_ILL_TO_PHYINDEX(ill) ((ill)->ill_phyint->phyint_ifindex) 1000Sstevel@tonic-gate 1010Sstevel@tonic-gate /* Global list of SCTP ILLs */ 1020Sstevel@tonic-gate sctp_ill_hash_t sctp_g_ills[SCTP_ILL_HASH]; 1030Sstevel@tonic-gate uint32_t sctp_ills_count = 0; 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate /* Global list of SCTP IPIFs */ 1060Sstevel@tonic-gate sctp_ipif_hash_t sctp_g_ipifs[SCTP_IPIF_HASH]; 107852Svi117747 uint32_t sctp_g_ipifs_count = 0; 1080Sstevel@tonic-gate /* 1090Sstevel@tonic-gate * 1100Sstevel@tonic-gate * 1110Sstevel@tonic-gate * SCTP Interface list manipulation functions, locking used. 1120Sstevel@tonic-gate * 1130Sstevel@tonic-gate * 1140Sstevel@tonic-gate */ 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate /* 1170Sstevel@tonic-gate * Delete an SCTP IPIF from the list if the refcount goes to 0 and it is 1180Sstevel@tonic-gate * marked as condemned. Also, check if the ILL needs to go away. 1190Sstevel@tonic-gate * Called with no locks held. 1200Sstevel@tonic-gate */ 1210Sstevel@tonic-gate static void 1220Sstevel@tonic-gate sctp_ipif_inactive(sctp_ipif_t *sctp_ipif) 1230Sstevel@tonic-gate { 1240Sstevel@tonic-gate sctp_ill_t *sctp_ill; 1250Sstevel@tonic-gate uint_t ipif_index; 1260Sstevel@tonic-gate uint_t ill_index; 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate rw_enter(&sctp_g_ills_lock, RW_READER); 1290Sstevel@tonic-gate rw_enter(&sctp_g_ipifs_lock, RW_WRITER); 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate ipif_index = SCTP_IPIF_HASH_FN(sctp_ipif->sctp_ipif_id); 1320Sstevel@tonic-gate sctp_ill = sctp_ipif->sctp_ipif_ill; 1330Sstevel@tonic-gate ASSERT(sctp_ill != NULL); 1340Sstevel@tonic-gate ill_index = SCTP_ILL_HASH_FN(sctp_ill->sctp_ill_index); 1350Sstevel@tonic-gate if (sctp_ipif->sctp_ipif_state != SCTP_IPIFS_CONDEMNED || 1360Sstevel@tonic-gate sctp_ipif->sctp_ipif_refcnt != 0) { 1370Sstevel@tonic-gate rw_exit(&sctp_g_ipifs_lock); 1380Sstevel@tonic-gate rw_exit(&sctp_g_ills_lock); 1390Sstevel@tonic-gate return; 1400Sstevel@tonic-gate } 1410Sstevel@tonic-gate list_remove(&sctp_g_ipifs[ipif_index].sctp_ipif_list, sctp_ipif); 1420Sstevel@tonic-gate sctp_g_ipifs[ipif_index].ipif_count--; 1430Sstevel@tonic-gate sctp_g_ipifs_count--; 1440Sstevel@tonic-gate rw_destroy(&sctp_ipif->sctp_ipif_lock); 1450Sstevel@tonic-gate kmem_free(sctp_ipif, sizeof (sctp_ipif_t)); 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate (void) atomic_add_32_nv(&sctp_ill->sctp_ill_ipifcnt, -1); 1480Sstevel@tonic-gate if (rw_tryupgrade(&sctp_g_ills_lock) != 0) { 1490Sstevel@tonic-gate rw_downgrade(&sctp_g_ipifs_lock); 1500Sstevel@tonic-gate if (sctp_ill->sctp_ill_ipifcnt == 0 && 1510Sstevel@tonic-gate sctp_ill->sctp_ill_state == SCTP_ILLS_CONDEMNED) { 1520Sstevel@tonic-gate list_remove(&sctp_g_ills[ill_index].sctp_ill_list, 1530Sstevel@tonic-gate (void *)sctp_ill); 1540Sstevel@tonic-gate sctp_g_ills[ill_index].ill_count--; 1550Sstevel@tonic-gate sctp_ills_count--; 1560Sstevel@tonic-gate kmem_free(sctp_ill->sctp_ill_name, 1570Sstevel@tonic-gate sctp_ill->sctp_ill_name_length); 1580Sstevel@tonic-gate kmem_free(sctp_ill, sizeof (sctp_ill_t)); 1590Sstevel@tonic-gate } 1600Sstevel@tonic-gate } 1610Sstevel@tonic-gate rw_exit(&sctp_g_ipifs_lock); 1620Sstevel@tonic-gate rw_exit(&sctp_g_ills_lock); 1630Sstevel@tonic-gate } 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate /* 1660Sstevel@tonic-gate * Lookup an SCTP IPIF given an IP address. Increments sctp_ipif refcnt. 1670Sstevel@tonic-gate * Called with no locks held. 1680Sstevel@tonic-gate */ 1690Sstevel@tonic-gate static sctp_ipif_t * 170852Svi117747 sctp_lookup_ipif_addr(in6_addr_t *addr, boolean_t refhold, zoneid_t zoneid, 171852Svi117747 uint_t ifindex) 1720Sstevel@tonic-gate { 1730Sstevel@tonic-gate int i; 1740Sstevel@tonic-gate int j; 1750Sstevel@tonic-gate sctp_ipif_t *sctp_ipif; 1760Sstevel@tonic-gate 177*1676Sjpk ASSERT(zoneid != ALL_ZONES); 1780Sstevel@tonic-gate rw_enter(&sctp_g_ipifs_lock, RW_READER); 1790Sstevel@tonic-gate for (i = 0; i < SCTP_IPIF_HASH; i++) { 1800Sstevel@tonic-gate if (sctp_g_ipifs[i].ipif_count == 0) 1810Sstevel@tonic-gate continue; 1820Sstevel@tonic-gate sctp_ipif = list_head(&sctp_g_ipifs[i].sctp_ipif_list); 1830Sstevel@tonic-gate for (j = 0; j < sctp_g_ipifs[i].ipif_count; j++) { 1840Sstevel@tonic-gate rw_enter(&sctp_ipif->sctp_ipif_lock, RW_READER); 185*1676Sjpk if ((zoneid == sctp_ipif->sctp_ipif_zoneid || 186*1676Sjpk sctp_ipif->sctp_ipif_zoneid == ALL_ZONES) && 1870Sstevel@tonic-gate SCTP_IPIF_USABLE(sctp_ipif->sctp_ipif_state) && 188852Svi117747 (ifindex == 0 || ifindex == 189852Svi117747 sctp_ipif->sctp_ipif_ill->sctp_ill_index) && 1900Sstevel@tonic-gate IN6_ARE_ADDR_EQUAL(&sctp_ipif->sctp_ipif_saddr, 1910Sstevel@tonic-gate addr)) { 1920Sstevel@tonic-gate rw_exit(&sctp_ipif->sctp_ipif_lock); 1930Sstevel@tonic-gate if (refhold) 1940Sstevel@tonic-gate SCTP_IPIF_REFHOLD(sctp_ipif); 1950Sstevel@tonic-gate rw_exit(&sctp_g_ipifs_lock); 1960Sstevel@tonic-gate return (sctp_ipif); 1970Sstevel@tonic-gate } 1980Sstevel@tonic-gate rw_exit(&sctp_ipif->sctp_ipif_lock); 1990Sstevel@tonic-gate sctp_ipif = list_next(&sctp_g_ipifs[i].sctp_ipif_list, 2000Sstevel@tonic-gate sctp_ipif); 2010Sstevel@tonic-gate } 2020Sstevel@tonic-gate } 2030Sstevel@tonic-gate rw_exit(&sctp_g_ipifs_lock); 2040Sstevel@tonic-gate return (NULL); 2050Sstevel@tonic-gate } 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate /* 2080Sstevel@tonic-gate * Populate the list with all the SCTP ipifs for a given ipversion. 2090Sstevel@tonic-gate * Increments sctp_ipif refcnt. 2100Sstevel@tonic-gate * Called with no locks held. 2110Sstevel@tonic-gate */ 2120Sstevel@tonic-gate static int 2130Sstevel@tonic-gate sctp_get_all_ipifs(sctp_t *sctp, int sleep) 2140Sstevel@tonic-gate { 2150Sstevel@tonic-gate sctp_ipif_t *sctp_ipif; 2160Sstevel@tonic-gate int i; 2170Sstevel@tonic-gate int j; 2180Sstevel@tonic-gate int error = 0; 2190Sstevel@tonic-gate 2200Sstevel@tonic-gate rw_enter(&sctp_g_ipifs_lock, RW_READER); 2210Sstevel@tonic-gate for (i = 0; i < SCTP_IPIF_HASH; i++) { 2220Sstevel@tonic-gate if (sctp_g_ipifs[i].ipif_count == 0) 2230Sstevel@tonic-gate continue; 2240Sstevel@tonic-gate sctp_ipif = list_head(&sctp_g_ipifs[i].sctp_ipif_list); 2250Sstevel@tonic-gate for (j = 0; j < sctp_g_ipifs[i].ipif_count; j++) { 2260Sstevel@tonic-gate rw_enter(&sctp_ipif->sctp_ipif_lock, RW_READER); 227432Svi117747 if (SCTP_IPIF_DISCARD(sctp_ipif->sctp_ipif_flags) || 2280Sstevel@tonic-gate !SCTP_IPIF_USABLE(sctp_ipif->sctp_ipif_state) || 229*1676Sjpk (sctp_ipif->sctp_ipif_zoneid != ALL_ZONES && 230*1676Sjpk sctp_ipif->sctp_ipif_zoneid != sctp->sctp_zoneid) || 2310Sstevel@tonic-gate (sctp->sctp_ipversion == IPV4_VERSION && 232432Svi117747 sctp_ipif->sctp_ipif_isv6) || 2330Sstevel@tonic-gate (sctp->sctp_connp->conn_ipv6_v6only && 234432Svi117747 !sctp_ipif->sctp_ipif_isv6)) { 2350Sstevel@tonic-gate rw_exit(&sctp_ipif->sctp_ipif_lock); 2360Sstevel@tonic-gate sctp_ipif = list_next( 2370Sstevel@tonic-gate &sctp_g_ipifs[i].sctp_ipif_list, sctp_ipif); 2380Sstevel@tonic-gate continue; 2390Sstevel@tonic-gate } 2400Sstevel@tonic-gate rw_exit(&sctp_ipif->sctp_ipif_lock); 2410Sstevel@tonic-gate SCTP_IPIF_REFHOLD(sctp_ipif); 242432Svi117747 error = sctp_ipif_hash_insert(sctp, sctp_ipif, sleep, 243432Svi117747 B_FALSE); 2440Sstevel@tonic-gate if (error != 0) 2450Sstevel@tonic-gate goto free_stuff; 2460Sstevel@tonic-gate sctp_ipif = list_next(&sctp_g_ipifs[i].sctp_ipif_list, 2470Sstevel@tonic-gate sctp_ipif); 2480Sstevel@tonic-gate } 2490Sstevel@tonic-gate } 2500Sstevel@tonic-gate rw_exit(&sctp_g_ipifs_lock); 2510Sstevel@tonic-gate return (0); 2520Sstevel@tonic-gate free_stuff: 2530Sstevel@tonic-gate rw_exit(&sctp_g_ipifs_lock); 2540Sstevel@tonic-gate sctp_free_saddrs(sctp); 2550Sstevel@tonic-gate return (ENOMEM); 2560Sstevel@tonic-gate } 2570Sstevel@tonic-gate 2580Sstevel@tonic-gate /* 2590Sstevel@tonic-gate * Given a list of address, fills in the list of SCTP ipifs if all the addresses 2600Sstevel@tonic-gate * are present in the SCTP interface list, return number of addresses filled 261852Svi117747 * or error. If the caller wants the list of addresses, it sends a pre-allocated 262852Svi117747 * buffer - list. Currently, this list is only used on a clustered node when 263852Svi117747 * the SCTP is in the listen state (from sctp_bind_add()). When called on a 264852Svi117747 * clustered node, the input is always a list of addresses (even if the 265852Svi117747 * original bind() was to INADDR_ANY). 2660Sstevel@tonic-gate * Called with no locks held. 2670Sstevel@tonic-gate */ 2680Sstevel@tonic-gate int 269852Svi117747 sctp_valid_addr_list(sctp_t *sctp, const void *addrs, uint32_t addrcnt, 270852Svi117747 uchar_t *list, size_t lsize) 2710Sstevel@tonic-gate { 2720Sstevel@tonic-gate struct sockaddr_in *sin4; 2730Sstevel@tonic-gate struct sockaddr_in6 *sin6; 2740Sstevel@tonic-gate struct in_addr *addr4; 2750Sstevel@tonic-gate in6_addr_t addr; 2760Sstevel@tonic-gate int cnt; 2770Sstevel@tonic-gate int err = 0; 2780Sstevel@tonic-gate int saddr_cnt = 0; 2790Sstevel@tonic-gate sctp_ipif_t *ipif; 2800Sstevel@tonic-gate boolean_t bind_to_all = B_FALSE; 2810Sstevel@tonic-gate boolean_t check_addrs = B_FALSE; 2820Sstevel@tonic-gate boolean_t check_lport = B_FALSE; 283852Svi117747 uchar_t *p = list; 2840Sstevel@tonic-gate 2850Sstevel@tonic-gate /* 2860Sstevel@tonic-gate * Need to check for port and address depending on the state. 2870Sstevel@tonic-gate * After a socket is bound, we need to make sure that subsequent 2880Sstevel@tonic-gate * bindx() has correct port. After an association is established, 2890Sstevel@tonic-gate * we need to check for changing the bound address to invalid 2900Sstevel@tonic-gate * addresses. 2910Sstevel@tonic-gate */ 2920Sstevel@tonic-gate if (sctp->sctp_state >= SCTPS_BOUND) { 2930Sstevel@tonic-gate check_lport = B_TRUE; 2940Sstevel@tonic-gate if (sctp->sctp_state > SCTPS_LISTEN) 2950Sstevel@tonic-gate check_addrs = B_TRUE; 2960Sstevel@tonic-gate } 297852Svi117747 2980Sstevel@tonic-gate if (sctp->sctp_conn_tfp != NULL) 2990Sstevel@tonic-gate mutex_enter(&sctp->sctp_conn_tfp->tf_lock); 3000Sstevel@tonic-gate if (sctp->sctp_listen_tfp != NULL) 3010Sstevel@tonic-gate mutex_enter(&sctp->sctp_listen_tfp->tf_lock); 3020Sstevel@tonic-gate for (cnt = 0; cnt < addrcnt; cnt++) { 3030Sstevel@tonic-gate boolean_t lookup_saddr = B_TRUE; 304852Svi117747 uint_t ifindex = 0; 3050Sstevel@tonic-gate 3060Sstevel@tonic-gate switch (sctp->sctp_family) { 3070Sstevel@tonic-gate case AF_INET: 3080Sstevel@tonic-gate sin4 = (struct sockaddr_in *)addrs + cnt; 3090Sstevel@tonic-gate if (sin4->sin_family != AF_INET || (check_lport && 3100Sstevel@tonic-gate sin4->sin_port != sctp->sctp_lport)) { 3110Sstevel@tonic-gate err = EINVAL; 3120Sstevel@tonic-gate goto free_ret; 3130Sstevel@tonic-gate } 3140Sstevel@tonic-gate addr4 = &sin4->sin_addr; 3150Sstevel@tonic-gate if (check_addrs && 3160Sstevel@tonic-gate (addr4->s_addr == INADDR_ANY || 3170Sstevel@tonic-gate addr4->s_addr == INADDR_BROADCAST || 3180Sstevel@tonic-gate IN_MULTICAST(addr4->s_addr))) { 3190Sstevel@tonic-gate err = EINVAL; 3200Sstevel@tonic-gate goto free_ret; 3210Sstevel@tonic-gate } 3220Sstevel@tonic-gate IN6_INADDR_TO_V4MAPPED(addr4, &addr); 3230Sstevel@tonic-gate if (!check_addrs && addr4->s_addr == INADDR_ANY) { 3240Sstevel@tonic-gate lookup_saddr = B_FALSE; 3250Sstevel@tonic-gate bind_to_all = B_TRUE; 3260Sstevel@tonic-gate } 3270Sstevel@tonic-gate 3280Sstevel@tonic-gate break; 3290Sstevel@tonic-gate case AF_INET6: 3300Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)addrs + cnt; 3310Sstevel@tonic-gate if (sin6->sin6_family != AF_INET6 || (check_lport && 3320Sstevel@tonic-gate sin6->sin6_port != sctp->sctp_lport)) { 3330Sstevel@tonic-gate err = EINVAL; 3340Sstevel@tonic-gate goto free_ret; 3350Sstevel@tonic-gate } 3360Sstevel@tonic-gate addr = sin6->sin6_addr; 337852Svi117747 /* Contains the interface index */ 338852Svi117747 ifindex = sin6->sin6_scope_id; 3390Sstevel@tonic-gate if (sctp->sctp_connp->conn_ipv6_v6only && 3400Sstevel@tonic-gate IN6_IS_ADDR_V4MAPPED(&addr)) { 3410Sstevel@tonic-gate err = EAFNOSUPPORT; 3420Sstevel@tonic-gate goto free_ret; 3430Sstevel@tonic-gate } 3440Sstevel@tonic-gate if (check_addrs && 3450Sstevel@tonic-gate (IN6_IS_ADDR_LINKLOCAL(&addr) || 3460Sstevel@tonic-gate IN6_IS_ADDR_MULTICAST(&addr) || 3470Sstevel@tonic-gate IN6_IS_ADDR_UNSPECIFIED(&addr))) { 3480Sstevel@tonic-gate err = EINVAL; 3490Sstevel@tonic-gate goto free_ret; 3500Sstevel@tonic-gate } 3510Sstevel@tonic-gate if (!check_addrs && IN6_IS_ADDR_UNSPECIFIED(&addr)) { 3520Sstevel@tonic-gate lookup_saddr = B_FALSE; 3530Sstevel@tonic-gate bind_to_all = B_TRUE; 3540Sstevel@tonic-gate } 3550Sstevel@tonic-gate 3560Sstevel@tonic-gate break; 3570Sstevel@tonic-gate default: 3580Sstevel@tonic-gate err = EAFNOSUPPORT; 3590Sstevel@tonic-gate goto free_ret; 3600Sstevel@tonic-gate } 3610Sstevel@tonic-gate if (lookup_saddr) { 3620Sstevel@tonic-gate ipif = sctp_lookup_ipif_addr(&addr, B_TRUE, 363852Svi117747 sctp->sctp_zoneid, ifindex); 3640Sstevel@tonic-gate if (ipif == NULL) { 3650Sstevel@tonic-gate /* Address not in the list */ 3660Sstevel@tonic-gate err = EINVAL; 3670Sstevel@tonic-gate goto free_ret; 368852Svi117747 } else if (check_addrs && SCTP_IS_IPIF_LOOPBACK(ipif) && 369852Svi117747 cl_sctp_check_addrs == NULL) { 3700Sstevel@tonic-gate SCTP_IPIF_REFRELE(ipif); 3710Sstevel@tonic-gate err = EINVAL; 3720Sstevel@tonic-gate goto free_ret; 3730Sstevel@tonic-gate } 3740Sstevel@tonic-gate } 3750Sstevel@tonic-gate if (!bind_to_all) { 376432Svi117747 /* 377432Svi117747 * If an address is added after association setup, 378432Svi117747 * we need to wait for the peer to send us an ASCONF 379432Svi117747 * ACK before we can start using it. 380432Svi117747 * saddr_ipif_dontsrc will be reset (to 0) when we 381432Svi117747 * get the ASCONF ACK for this address. 382432Svi117747 */ 383432Svi117747 err = sctp_ipif_hash_insert(sctp, ipif, KM_SLEEP, 384432Svi117747 check_addrs ? B_TRUE : B_FALSE); 3850Sstevel@tonic-gate if (err != 0) { 3860Sstevel@tonic-gate SCTP_IPIF_REFRELE(ipif); 3870Sstevel@tonic-gate if (check_addrs && err == EALREADY) 3880Sstevel@tonic-gate err = EADDRINUSE; 3890Sstevel@tonic-gate goto free_ret; 3900Sstevel@tonic-gate } 3910Sstevel@tonic-gate saddr_cnt++; 392852Svi117747 if (lsize >= sizeof (addr)) { 393852Svi117747 bcopy(&addr, p, sizeof (addr)); 394852Svi117747 p += sizeof (addr); 395852Svi117747 lsize -= sizeof (addr); 396852Svi117747 } 3970Sstevel@tonic-gate } 3980Sstevel@tonic-gate } 3990Sstevel@tonic-gate if (bind_to_all) { 4000Sstevel@tonic-gate /* 4010Sstevel@tonic-gate * Free whatever we might have added before encountering 4020Sstevel@tonic-gate * inaddr_any. 4030Sstevel@tonic-gate */ 4040Sstevel@tonic-gate if (sctp->sctp_nsaddrs > 0) { 4050Sstevel@tonic-gate sctp_free_saddrs(sctp); 4060Sstevel@tonic-gate ASSERT(sctp->sctp_nsaddrs == 0); 4070Sstevel@tonic-gate } 4080Sstevel@tonic-gate err = sctp_get_all_ipifs(sctp, KM_SLEEP); 4090Sstevel@tonic-gate if (err != 0) 4100Sstevel@tonic-gate return (err); 4110Sstevel@tonic-gate sctp->sctp_bound_to_all = 1; 4120Sstevel@tonic-gate } 4130Sstevel@tonic-gate if (sctp->sctp_listen_tfp != NULL) 4140Sstevel@tonic-gate mutex_exit(&sctp->sctp_listen_tfp->tf_lock); 4150Sstevel@tonic-gate if (sctp->sctp_conn_tfp != NULL) 4160Sstevel@tonic-gate mutex_exit(&sctp->sctp_conn_tfp->tf_lock); 4170Sstevel@tonic-gate return (0); 4180Sstevel@tonic-gate free_ret: 4190Sstevel@tonic-gate if (saddr_cnt != 0) 4200Sstevel@tonic-gate sctp_del_saddr_list(sctp, addrs, saddr_cnt, B_TRUE); 4210Sstevel@tonic-gate if (sctp->sctp_listen_tfp != NULL) 4220Sstevel@tonic-gate mutex_exit(&sctp->sctp_listen_tfp->tf_lock); 4230Sstevel@tonic-gate if (sctp->sctp_conn_tfp != NULL) 4240Sstevel@tonic-gate mutex_exit(&sctp->sctp_conn_tfp->tf_lock); 4250Sstevel@tonic-gate return (err); 4260Sstevel@tonic-gate } 4270Sstevel@tonic-gate 4280Sstevel@tonic-gate sctp_saddr_ipif_t * 4290Sstevel@tonic-gate sctp_ipif_lookup(sctp_t *sctp, uint_t ipif_index) 4300Sstevel@tonic-gate { 4310Sstevel@tonic-gate int cnt; 4320Sstevel@tonic-gate int seqid = SCTP_IPIF_HASH_FN(ipif_index); 4330Sstevel@tonic-gate sctp_saddr_ipif_t *ipif_obj; 4340Sstevel@tonic-gate 4350Sstevel@tonic-gate if (sctp->sctp_saddrs[seqid].ipif_count == 0) 4360Sstevel@tonic-gate return (NULL); 4370Sstevel@tonic-gate 4380Sstevel@tonic-gate ipif_obj = list_head(&sctp->sctp_saddrs[seqid].sctp_ipif_list); 4390Sstevel@tonic-gate for (cnt = 0; cnt < sctp->sctp_saddrs[seqid].ipif_count; cnt++) { 4400Sstevel@tonic-gate if (ipif_obj->saddr_ipifp->sctp_ipif_id == ipif_index) 4410Sstevel@tonic-gate return (ipif_obj); 4420Sstevel@tonic-gate ipif_obj = list_next(&sctp->sctp_saddrs[seqid].sctp_ipif_list, 4430Sstevel@tonic-gate ipif_obj); 4440Sstevel@tonic-gate } 4450Sstevel@tonic-gate return (NULL); 4460Sstevel@tonic-gate } 4470Sstevel@tonic-gate 4480Sstevel@tonic-gate static int 449432Svi117747 sctp_ipif_hash_insert(sctp_t *sctp, sctp_ipif_t *ipif, int sleep, 450432Svi117747 boolean_t dontsrc) 4510Sstevel@tonic-gate { 4520Sstevel@tonic-gate int cnt; 4530Sstevel@tonic-gate sctp_saddr_ipif_t *ipif_obj; 4540Sstevel@tonic-gate int seqid = SCTP_IPIF_HASH_FN(ipif->sctp_ipif_id); 4550Sstevel@tonic-gate 4560Sstevel@tonic-gate ipif_obj = list_head(&sctp->sctp_saddrs[seqid].sctp_ipif_list); 4570Sstevel@tonic-gate for (cnt = 0; cnt < sctp->sctp_saddrs[seqid].ipif_count; cnt++) { 4580Sstevel@tonic-gate if (ipif_obj->saddr_ipifp->sctp_ipif_id == ipif->sctp_ipif_id) 4590Sstevel@tonic-gate return (EALREADY); 4600Sstevel@tonic-gate ipif_obj = list_next(&sctp->sctp_saddrs[seqid].sctp_ipif_list, 4610Sstevel@tonic-gate ipif_obj); 4620Sstevel@tonic-gate } 4630Sstevel@tonic-gate ipif_obj = kmem_zalloc(sizeof (sctp_saddr_ipif_t), sleep); 4640Sstevel@tonic-gate if (ipif_obj == NULL) { 4650Sstevel@tonic-gate /* Need to do something */ 4660Sstevel@tonic-gate return (ENOMEM); 4670Sstevel@tonic-gate } 4680Sstevel@tonic-gate ipif_obj->saddr_ipifp = ipif; 469432Svi117747 ipif_obj->saddr_ipif_dontsrc = dontsrc ? 1 : 0; 4700Sstevel@tonic-gate list_insert_tail(&sctp->sctp_saddrs[seqid].sctp_ipif_list, ipif_obj); 4710Sstevel@tonic-gate sctp->sctp_saddrs[seqid].ipif_count++; 4720Sstevel@tonic-gate sctp->sctp_nsaddrs++; 4730Sstevel@tonic-gate return (0); 4740Sstevel@tonic-gate } 4750Sstevel@tonic-gate 4760Sstevel@tonic-gate static void 4770Sstevel@tonic-gate sctp_ipif_hash_remove(sctp_t *sctp, sctp_ipif_t *ipif) 4780Sstevel@tonic-gate { 4790Sstevel@tonic-gate int cnt; 4800Sstevel@tonic-gate sctp_saddr_ipif_t *ipif_obj; 4810Sstevel@tonic-gate int seqid = SCTP_IPIF_HASH_FN(ipif->sctp_ipif_id); 4820Sstevel@tonic-gate 4830Sstevel@tonic-gate ipif_obj = list_head(&sctp->sctp_saddrs[seqid].sctp_ipif_list); 4840Sstevel@tonic-gate for (cnt = 0; cnt < sctp->sctp_saddrs[seqid].ipif_count; cnt++) { 4850Sstevel@tonic-gate if (ipif_obj->saddr_ipifp->sctp_ipif_id == ipif->sctp_ipif_id) { 4860Sstevel@tonic-gate list_remove(&sctp->sctp_saddrs[seqid].sctp_ipif_list, 4870Sstevel@tonic-gate ipif_obj); 4880Sstevel@tonic-gate sctp->sctp_nsaddrs--; 4890Sstevel@tonic-gate sctp->sctp_saddrs[seqid].ipif_count--; 4900Sstevel@tonic-gate SCTP_IPIF_REFRELE(ipif_obj->saddr_ipifp); 4910Sstevel@tonic-gate kmem_free(ipif_obj, sizeof (sctp_saddr_ipif_t)); 4920Sstevel@tonic-gate break; 4930Sstevel@tonic-gate } 4940Sstevel@tonic-gate ipif_obj = list_next(&sctp->sctp_saddrs[seqid].sctp_ipif_list, 4950Sstevel@tonic-gate ipif_obj); 4960Sstevel@tonic-gate } 4970Sstevel@tonic-gate } 4980Sstevel@tonic-gate 4990Sstevel@tonic-gate static int 5000Sstevel@tonic-gate sctp_compare_ipif_list(sctp_ipif_hash_t *list1, sctp_ipif_hash_t *list2) 5010Sstevel@tonic-gate { 5020Sstevel@tonic-gate int i; 5030Sstevel@tonic-gate int j; 5040Sstevel@tonic-gate sctp_saddr_ipif_t *obj1; 5050Sstevel@tonic-gate sctp_saddr_ipif_t *obj2; 5060Sstevel@tonic-gate int overlap = 0; 5070Sstevel@tonic-gate 5080Sstevel@tonic-gate obj1 = list_head(&list1->sctp_ipif_list); 5090Sstevel@tonic-gate for (i = 0; i < list1->ipif_count; i++) { 5100Sstevel@tonic-gate obj2 = list_head(&list2->sctp_ipif_list); 5110Sstevel@tonic-gate for (j = 0; j < list2->ipif_count; j++) { 5120Sstevel@tonic-gate if (obj1->saddr_ipifp->sctp_ipif_id == 5130Sstevel@tonic-gate obj2->saddr_ipifp->sctp_ipif_id) { 5140Sstevel@tonic-gate overlap++; 5150Sstevel@tonic-gate break; 5160Sstevel@tonic-gate } 5170Sstevel@tonic-gate obj2 = list_next(&list2->sctp_ipif_list, 5180Sstevel@tonic-gate obj2); 5190Sstevel@tonic-gate } 5200Sstevel@tonic-gate obj1 = list_next(&list1->sctp_ipif_list, obj1); 5210Sstevel@tonic-gate } 5220Sstevel@tonic-gate return (overlap); 5230Sstevel@tonic-gate } 5240Sstevel@tonic-gate 5250Sstevel@tonic-gate int 5260Sstevel@tonic-gate sctp_compare_saddrs(sctp_t *sctp1, sctp_t *sctp2) 5270Sstevel@tonic-gate { 5280Sstevel@tonic-gate int i; 5290Sstevel@tonic-gate int overlap = 0; 5300Sstevel@tonic-gate 5310Sstevel@tonic-gate for (i = 0; i < SCTP_IPIF_HASH; i++) { 5320Sstevel@tonic-gate overlap += sctp_compare_ipif_list(&sctp1->sctp_saddrs[i], 5330Sstevel@tonic-gate &sctp2->sctp_saddrs[i]); 5340Sstevel@tonic-gate } 5350Sstevel@tonic-gate 5360Sstevel@tonic-gate if (sctp1->sctp_nsaddrs == sctp2->sctp_nsaddrs && 5370Sstevel@tonic-gate overlap == sctp1->sctp_nsaddrs) { 5380Sstevel@tonic-gate return (SCTP_ADDR_EQUAL); 5390Sstevel@tonic-gate } 5400Sstevel@tonic-gate 5410Sstevel@tonic-gate if (overlap == sctp1->sctp_nsaddrs) 5420Sstevel@tonic-gate return (SCTP_ADDR_SUBSET); 5430Sstevel@tonic-gate 5440Sstevel@tonic-gate if (overlap > 0) 5450Sstevel@tonic-gate return (SCTP_ADDR_OVERLAP); 5460Sstevel@tonic-gate 5470Sstevel@tonic-gate return (SCTP_ADDR_DISJOINT); 5480Sstevel@tonic-gate } 5490Sstevel@tonic-gate 5500Sstevel@tonic-gate static int 5510Sstevel@tonic-gate sctp_copy_ipifs(sctp_ipif_hash_t *list1, sctp_t *sctp2, int sleep) 5520Sstevel@tonic-gate { 5530Sstevel@tonic-gate int i; 5540Sstevel@tonic-gate sctp_saddr_ipif_t *obj; 5550Sstevel@tonic-gate int error = 0; 5560Sstevel@tonic-gate 5570Sstevel@tonic-gate obj = list_head(&list1->sctp_ipif_list); 5580Sstevel@tonic-gate for (i = 0; i < list1->ipif_count; i++) { 5590Sstevel@tonic-gate SCTP_IPIF_REFHOLD(obj->saddr_ipifp); 560432Svi117747 error = sctp_ipif_hash_insert(sctp2, obj->saddr_ipifp, sleep, 561432Svi117747 B_FALSE); 5620Sstevel@tonic-gate if (error != 0) 5630Sstevel@tonic-gate return (error); 5640Sstevel@tonic-gate obj = list_next(&list1->sctp_ipif_list, obj); 5650Sstevel@tonic-gate } 5660Sstevel@tonic-gate return (error); 5670Sstevel@tonic-gate } 5680Sstevel@tonic-gate 5690Sstevel@tonic-gate int 5700Sstevel@tonic-gate sctp_dup_saddrs(sctp_t *sctp1, sctp_t *sctp2, int sleep) 5710Sstevel@tonic-gate { 5720Sstevel@tonic-gate int error = 0; 5730Sstevel@tonic-gate int i; 5740Sstevel@tonic-gate 575432Svi117747 if (sctp1 == NULL || sctp1->sctp_bound_to_all == 1) 5760Sstevel@tonic-gate return (sctp_get_all_ipifs(sctp2, sleep)); 5770Sstevel@tonic-gate 5780Sstevel@tonic-gate for (i = 0; i < SCTP_IPIF_HASH; i++) { 5790Sstevel@tonic-gate if (sctp1->sctp_saddrs[i].ipif_count == 0) 5800Sstevel@tonic-gate continue; 5810Sstevel@tonic-gate error = sctp_copy_ipifs(&sctp1->sctp_saddrs[i], sctp2, sleep); 5820Sstevel@tonic-gate if (error != 0) { 5830Sstevel@tonic-gate sctp_free_saddrs(sctp2); 5840Sstevel@tonic-gate return (error); 5850Sstevel@tonic-gate } 5860Sstevel@tonic-gate } 5870Sstevel@tonic-gate return (0); 5880Sstevel@tonic-gate } 5890Sstevel@tonic-gate 5900Sstevel@tonic-gate void 5910Sstevel@tonic-gate sctp_free_saddrs(sctp_t *sctp) 5920Sstevel@tonic-gate { 5930Sstevel@tonic-gate int i; 5940Sstevel@tonic-gate int l; 5950Sstevel@tonic-gate sctp_saddr_ipif_t *obj; 5960Sstevel@tonic-gate 5970Sstevel@tonic-gate if (sctp->sctp_nsaddrs == 0) 5980Sstevel@tonic-gate return; 5990Sstevel@tonic-gate for (i = 0; i < SCTP_IPIF_HASH; i++) { 6000Sstevel@tonic-gate if (sctp->sctp_saddrs[i].ipif_count == 0) 6010Sstevel@tonic-gate continue; 6020Sstevel@tonic-gate obj = list_tail(&sctp->sctp_saddrs[i].sctp_ipif_list); 6030Sstevel@tonic-gate for (l = 0; l < sctp->sctp_saddrs[i].ipif_count; l++) { 6040Sstevel@tonic-gate list_remove(&sctp->sctp_saddrs[i].sctp_ipif_list, obj); 6050Sstevel@tonic-gate SCTP_IPIF_REFRELE(obj->saddr_ipifp); 6060Sstevel@tonic-gate sctp->sctp_nsaddrs--; 6070Sstevel@tonic-gate kmem_free(obj, sizeof (sctp_saddr_ipif_t)); 6080Sstevel@tonic-gate obj = list_tail(&sctp->sctp_saddrs[i].sctp_ipif_list); 6090Sstevel@tonic-gate } 6100Sstevel@tonic-gate sctp->sctp_saddrs[i].ipif_count = 0; 6110Sstevel@tonic-gate } 612432Svi117747 if (sctp->sctp_bound_to_all == 1) 613432Svi117747 sctp->sctp_bound_to_all = 0; 6140Sstevel@tonic-gate ASSERT(sctp->sctp_nsaddrs == 0); 6150Sstevel@tonic-gate } 6160Sstevel@tonic-gate 6170Sstevel@tonic-gate /* 6180Sstevel@tonic-gate * Add/Delete the given ILL from the SCTP ILL list. Called with no locks 6190Sstevel@tonic-gate * held. 6200Sstevel@tonic-gate */ 6210Sstevel@tonic-gate void 6220Sstevel@tonic-gate sctp_update_ill(ill_t *ill, int op) 6230Sstevel@tonic-gate { 6240Sstevel@tonic-gate int i; 6250Sstevel@tonic-gate sctp_ill_t *sctp_ill = NULL; 6260Sstevel@tonic-gate uint_t index; 6270Sstevel@tonic-gate 6280Sstevel@tonic-gate ip2dbg(("sctp_update_ill: %s\n", ill->ill_name)); 6290Sstevel@tonic-gate 6300Sstevel@tonic-gate rw_enter(&sctp_g_ills_lock, RW_WRITER); 6310Sstevel@tonic-gate 6320Sstevel@tonic-gate index = SCTP_ILL_HASH_FN(SCTP_ILL_TO_PHYINDEX(ill)); 6330Sstevel@tonic-gate sctp_ill = list_head(&sctp_g_ills[index].sctp_ill_list); 6340Sstevel@tonic-gate for (i = 0; i < sctp_g_ills[index].ill_count; i++) { 6350Sstevel@tonic-gate if (sctp_ill->sctp_ill_index == SCTP_ILL_TO_PHYINDEX(ill)) 6360Sstevel@tonic-gate break; 6370Sstevel@tonic-gate sctp_ill = list_next(&sctp_g_ills[index].sctp_ill_list, 6380Sstevel@tonic-gate sctp_ill); 6390Sstevel@tonic-gate } 6400Sstevel@tonic-gate 6410Sstevel@tonic-gate switch (op) { 6420Sstevel@tonic-gate case SCTP_ILL_INSERT: 6430Sstevel@tonic-gate if (sctp_ill != NULL) { 6440Sstevel@tonic-gate /* Unmark it if it is condemned */ 6450Sstevel@tonic-gate if (sctp_ill->sctp_ill_state == SCTP_ILLS_CONDEMNED) 6460Sstevel@tonic-gate sctp_ill->sctp_ill_state = 0; 6470Sstevel@tonic-gate rw_exit(&sctp_g_ills_lock); 6480Sstevel@tonic-gate return; 6490Sstevel@tonic-gate } 6500Sstevel@tonic-gate sctp_ill = kmem_zalloc(sizeof (sctp_ill_t), KM_NOSLEEP); 6510Sstevel@tonic-gate /* Need to re-try? */ 6520Sstevel@tonic-gate if (sctp_ill == NULL) { 6530Sstevel@tonic-gate ip1dbg(("sctp_ill_insert: mem error..\n")); 6540Sstevel@tonic-gate rw_exit(&sctp_g_ills_lock); 6550Sstevel@tonic-gate return; 6560Sstevel@tonic-gate } 6570Sstevel@tonic-gate sctp_ill->sctp_ill_name = 6580Sstevel@tonic-gate kmem_zalloc(ill->ill_name_length, KM_NOSLEEP); 6590Sstevel@tonic-gate if (sctp_ill->sctp_ill_name == NULL) { 6600Sstevel@tonic-gate ip1dbg(("sctp_ill_insert: mem error..\n")); 6610Sstevel@tonic-gate kmem_free(sctp_ill, sizeof (sctp_ill_t)); 6620Sstevel@tonic-gate rw_exit(&sctp_g_ills_lock); 6630Sstevel@tonic-gate return; 6640Sstevel@tonic-gate } 6650Sstevel@tonic-gate bcopy(ill->ill_name, sctp_ill->sctp_ill_name, 6660Sstevel@tonic-gate ill->ill_name_length); 6670Sstevel@tonic-gate sctp_ill->sctp_ill_name_length = ill->ill_name_length; 6680Sstevel@tonic-gate sctp_ill->sctp_ill_index = SCTP_ILL_TO_PHYINDEX(ill); 6690Sstevel@tonic-gate sctp_ill->sctp_ill_flags = ill->ill_phyint->phyint_flags; 6700Sstevel@tonic-gate list_insert_tail(&sctp_g_ills[index].sctp_ill_list, 6710Sstevel@tonic-gate (void *)sctp_ill); 6720Sstevel@tonic-gate sctp_g_ills[index].ill_count++; 6730Sstevel@tonic-gate sctp_ills_count++; 6740Sstevel@tonic-gate 6750Sstevel@tonic-gate break; 6760Sstevel@tonic-gate 6770Sstevel@tonic-gate case SCTP_ILL_REMOVE: 6780Sstevel@tonic-gate 6790Sstevel@tonic-gate if (sctp_ill == NULL) { 6800Sstevel@tonic-gate rw_exit(&sctp_g_ills_lock); 6810Sstevel@tonic-gate return; 6820Sstevel@tonic-gate } 6830Sstevel@tonic-gate if (sctp_ill->sctp_ill_ipifcnt == 0) { 6840Sstevel@tonic-gate list_remove(&sctp_g_ills[index].sctp_ill_list, 6850Sstevel@tonic-gate (void *)sctp_ill); 6860Sstevel@tonic-gate sctp_g_ills[index].ill_count--; 6870Sstevel@tonic-gate sctp_ills_count--; 6880Sstevel@tonic-gate kmem_free(sctp_ill->sctp_ill_name, 6890Sstevel@tonic-gate ill->ill_name_length); 6900Sstevel@tonic-gate kmem_free(sctp_ill, sizeof (sctp_ill_t)); 6910Sstevel@tonic-gate } else { 6920Sstevel@tonic-gate sctp_ill->sctp_ill_state = SCTP_ILLS_CONDEMNED; 6930Sstevel@tonic-gate } 6940Sstevel@tonic-gate 6950Sstevel@tonic-gate break; 6960Sstevel@tonic-gate } 6970Sstevel@tonic-gate rw_exit(&sctp_g_ills_lock); 6980Sstevel@tonic-gate } 6990Sstevel@tonic-gate 7000Sstevel@tonic-gate /* move ipif from f_ill to t_ill */ 7010Sstevel@tonic-gate void 7020Sstevel@tonic-gate sctp_move_ipif(ipif_t *ipif, ill_t *f_ill, ill_t *t_ill) 7030Sstevel@tonic-gate { 7040Sstevel@tonic-gate sctp_ill_t *fsctp_ill = NULL; 7050Sstevel@tonic-gate sctp_ill_t *tsctp_ill = NULL; 7060Sstevel@tonic-gate sctp_ipif_t *sctp_ipif; 7070Sstevel@tonic-gate uint_t index; 7080Sstevel@tonic-gate int i; 7090Sstevel@tonic-gate 7100Sstevel@tonic-gate rw_enter(&sctp_g_ills_lock, RW_READER); 7110Sstevel@tonic-gate rw_enter(&sctp_g_ipifs_lock, RW_READER); 7120Sstevel@tonic-gate 7130Sstevel@tonic-gate index = SCTP_ILL_HASH_FN(SCTP_ILL_TO_PHYINDEX(f_ill)); 7140Sstevel@tonic-gate fsctp_ill = list_head(&sctp_g_ills[index].sctp_ill_list); 7150Sstevel@tonic-gate for (i = 0; i < sctp_g_ills[index].ill_count; i++) { 7160Sstevel@tonic-gate if (fsctp_ill->sctp_ill_index == SCTP_ILL_TO_PHYINDEX(f_ill)) 7170Sstevel@tonic-gate break; 7180Sstevel@tonic-gate fsctp_ill = list_next(&sctp_g_ills[index].sctp_ill_list, 7190Sstevel@tonic-gate fsctp_ill); 7200Sstevel@tonic-gate } 7210Sstevel@tonic-gate 7220Sstevel@tonic-gate index = SCTP_ILL_HASH_FN(SCTP_ILL_TO_PHYINDEX(t_ill)); 7230Sstevel@tonic-gate tsctp_ill = list_head(&sctp_g_ills[index].sctp_ill_list); 7240Sstevel@tonic-gate for (i = 0; i < sctp_g_ills[index].ill_count; i++) { 7250Sstevel@tonic-gate if (tsctp_ill->sctp_ill_index == SCTP_ILL_TO_PHYINDEX(t_ill)) 7260Sstevel@tonic-gate break; 7270Sstevel@tonic-gate tsctp_ill = list_next(&sctp_g_ills[index].sctp_ill_list, 7280Sstevel@tonic-gate tsctp_ill); 7290Sstevel@tonic-gate } 7300Sstevel@tonic-gate 7310Sstevel@tonic-gate index = SCTP_IPIF_HASH_FN(ipif->ipif_seqid); 7320Sstevel@tonic-gate sctp_ipif = list_head(&sctp_g_ipifs[index].sctp_ipif_list); 7330Sstevel@tonic-gate for (i = 0; i < sctp_g_ipifs[index].ipif_count; i++) { 7340Sstevel@tonic-gate if (sctp_ipif->sctp_ipif_id == ipif->ipif_seqid) 7350Sstevel@tonic-gate break; 7360Sstevel@tonic-gate sctp_ipif = list_next(&sctp_g_ipifs[index].sctp_ipif_list, 7370Sstevel@tonic-gate sctp_ipif); 7380Sstevel@tonic-gate } 7390Sstevel@tonic-gate /* Should be an ASSERT? */ 7400Sstevel@tonic-gate if (fsctp_ill == NULL || tsctp_ill == NULL || sctp_ipif == NULL) { 7410Sstevel@tonic-gate ip1dbg(("sctp_move_ipif: error moving ipif %p from %p to %p\n", 7420Sstevel@tonic-gate (void *)ipif, (void *)f_ill, (void *)t_ill)); 7430Sstevel@tonic-gate rw_exit(&sctp_g_ipifs_lock); 7440Sstevel@tonic-gate rw_exit(&sctp_g_ills_lock); 7450Sstevel@tonic-gate return; 7460Sstevel@tonic-gate } 7470Sstevel@tonic-gate rw_enter(&sctp_ipif->sctp_ipif_lock, RW_WRITER); 7480Sstevel@tonic-gate ASSERT(sctp_ipif->sctp_ipif_ill == fsctp_ill); 7490Sstevel@tonic-gate sctp_ipif->sctp_ipif_ill = tsctp_ill; 7500Sstevel@tonic-gate rw_exit(&sctp_ipif->sctp_ipif_lock); 7510Sstevel@tonic-gate (void) atomic_add_32_nv(&fsctp_ill->sctp_ill_ipifcnt, -1); 7520Sstevel@tonic-gate atomic_add_32(&tsctp_ill->sctp_ill_ipifcnt, 1); 7530Sstevel@tonic-gate rw_exit(&sctp_g_ipifs_lock); 7540Sstevel@tonic-gate rw_exit(&sctp_g_ills_lock); 7550Sstevel@tonic-gate } 7560Sstevel@tonic-gate 7570Sstevel@tonic-gate /* Insert, Remove, Mark up or Mark down the ipif */ 7580Sstevel@tonic-gate void 7590Sstevel@tonic-gate sctp_update_ipif(ipif_t *ipif, int op) 7600Sstevel@tonic-gate { 7610Sstevel@tonic-gate ill_t *ill = ipif->ipif_ill; 7620Sstevel@tonic-gate int i; 7630Sstevel@tonic-gate sctp_ill_t *sctp_ill; 7640Sstevel@tonic-gate sctp_ipif_t *sctp_ipif; 7650Sstevel@tonic-gate uint_t ill_index; 7660Sstevel@tonic-gate uint_t ipif_index; 7670Sstevel@tonic-gate 7680Sstevel@tonic-gate ip2dbg(("sctp_update_ipif: %s %d\n", ill->ill_name, ipif->ipif_seqid)); 7690Sstevel@tonic-gate 7700Sstevel@tonic-gate rw_enter(&sctp_g_ills_lock, RW_READER); 7710Sstevel@tonic-gate rw_enter(&sctp_g_ipifs_lock, RW_WRITER); 7720Sstevel@tonic-gate 7730Sstevel@tonic-gate ill_index = SCTP_ILL_HASH_FN(SCTP_ILL_TO_PHYINDEX(ill)); 7740Sstevel@tonic-gate sctp_ill = list_head(&sctp_g_ills[ill_index].sctp_ill_list); 7750Sstevel@tonic-gate for (i = 0; i < sctp_g_ills[ill_index].ill_count; i++) { 7760Sstevel@tonic-gate if (sctp_ill->sctp_ill_index == SCTP_ILL_TO_PHYINDEX(ill)) 7770Sstevel@tonic-gate break; 7780Sstevel@tonic-gate sctp_ill = list_next(&sctp_g_ills[ill_index].sctp_ill_list, 7790Sstevel@tonic-gate sctp_ill); 7800Sstevel@tonic-gate } 7810Sstevel@tonic-gate if (sctp_ill == NULL) { 7820Sstevel@tonic-gate rw_exit(&sctp_g_ipifs_lock); 7830Sstevel@tonic-gate rw_exit(&sctp_g_ills_lock); 7840Sstevel@tonic-gate return; 7850Sstevel@tonic-gate } 7860Sstevel@tonic-gate 7870Sstevel@tonic-gate ipif_index = SCTP_IPIF_HASH_FN(ipif->ipif_seqid); 7880Sstevel@tonic-gate sctp_ipif = list_head(&sctp_g_ipifs[ipif_index].sctp_ipif_list); 7890Sstevel@tonic-gate for (i = 0; i < sctp_g_ipifs[ipif_index].ipif_count; i++) { 7900Sstevel@tonic-gate if (sctp_ipif->sctp_ipif_id == ipif->ipif_seqid) 7910Sstevel@tonic-gate break; 7920Sstevel@tonic-gate sctp_ipif = list_next(&sctp_g_ipifs[ipif_index].sctp_ipif_list, 7930Sstevel@tonic-gate sctp_ipif); 7940Sstevel@tonic-gate } 7950Sstevel@tonic-gate if (op != SCTP_IPIF_INSERT && sctp_ipif == NULL) { 7960Sstevel@tonic-gate ip1dbg(("sctp_update_ipif: null sctp_ipif for %d\n", op)); 7970Sstevel@tonic-gate rw_exit(&sctp_g_ipifs_lock); 7980Sstevel@tonic-gate rw_exit(&sctp_g_ills_lock); 7990Sstevel@tonic-gate return; 8000Sstevel@tonic-gate } 8010Sstevel@tonic-gate #ifdef DEBUG 8020Sstevel@tonic-gate if (sctp_ipif != NULL) 8030Sstevel@tonic-gate ASSERT(sctp_ill == sctp_ipif->sctp_ipif_ill); 8040Sstevel@tonic-gate #endif 8050Sstevel@tonic-gate switch (op) { 8060Sstevel@tonic-gate case SCTP_IPIF_INSERT: 8070Sstevel@tonic-gate if (sctp_ipif != NULL) { 8080Sstevel@tonic-gate if (sctp_ipif->sctp_ipif_state == SCTP_IPIFS_CONDEMNED) 809252Svi117747 sctp_ipif->sctp_ipif_state = SCTP_IPIFS_INVALID; 8100Sstevel@tonic-gate rw_exit(&sctp_g_ipifs_lock); 8110Sstevel@tonic-gate rw_exit(&sctp_g_ills_lock); 8120Sstevel@tonic-gate return; 8130Sstevel@tonic-gate } 8140Sstevel@tonic-gate sctp_ipif = kmem_zalloc(sizeof (sctp_ipif_t), KM_NOSLEEP); 8150Sstevel@tonic-gate /* Try again? */ 8160Sstevel@tonic-gate if (sctp_ipif == NULL) { 8170Sstevel@tonic-gate ip1dbg(("sctp_ipif_insert: mem failure..\n")); 8180Sstevel@tonic-gate rw_exit(&sctp_g_ipifs_lock); 8190Sstevel@tonic-gate rw_exit(&sctp_g_ills_lock); 8200Sstevel@tonic-gate return; 8210Sstevel@tonic-gate } 8220Sstevel@tonic-gate sctp_ipif->sctp_ipif_id = ipif->ipif_seqid; 8230Sstevel@tonic-gate sctp_ipif->sctp_ipif_ill = sctp_ill; 824252Svi117747 sctp_ipif->sctp_ipif_state = SCTP_IPIFS_INVALID; 8250Sstevel@tonic-gate sctp_ipif->sctp_ipif_mtu = ipif->ipif_mtu; 8260Sstevel@tonic-gate sctp_ipif->sctp_ipif_zoneid = ipif->ipif_zoneid; 8270Sstevel@tonic-gate sctp_ipif->sctp_ipif_isv6 = ill->ill_isv6; 828432Svi117747 sctp_ipif->sctp_ipif_flags = ipif->ipif_flags; 8290Sstevel@tonic-gate rw_init(&sctp_ipif->sctp_ipif_lock, NULL, RW_DEFAULT, NULL); 8300Sstevel@tonic-gate list_insert_tail(&sctp_g_ipifs[ipif_index].sctp_ipif_list, 8310Sstevel@tonic-gate (void *)sctp_ipif); 8320Sstevel@tonic-gate sctp_g_ipifs[ipif_index].ipif_count++; 8330Sstevel@tonic-gate sctp_g_ipifs_count++; 8340Sstevel@tonic-gate atomic_add_32(&sctp_ill->sctp_ill_ipifcnt, 1); 8350Sstevel@tonic-gate 8360Sstevel@tonic-gate break; 8370Sstevel@tonic-gate 8380Sstevel@tonic-gate case SCTP_IPIF_REMOVE: 8390Sstevel@tonic-gate { 8400Sstevel@tonic-gate list_t *ipif_list; 8410Sstevel@tonic-gate list_t *ill_list; 8420Sstevel@tonic-gate 8430Sstevel@tonic-gate ill_list = &sctp_g_ills[ill_index].sctp_ill_list; 8440Sstevel@tonic-gate ipif_list = &sctp_g_ipifs[ipif_index].sctp_ipif_list; 8450Sstevel@tonic-gate if (sctp_ipif->sctp_ipif_refcnt != 0) { 8460Sstevel@tonic-gate sctp_ipif->sctp_ipif_state = SCTP_IPIFS_CONDEMNED; 8470Sstevel@tonic-gate rw_exit(&sctp_g_ipifs_lock); 8480Sstevel@tonic-gate rw_exit(&sctp_g_ills_lock); 8490Sstevel@tonic-gate return; 8500Sstevel@tonic-gate } 8510Sstevel@tonic-gate list_remove(ipif_list, (void *)sctp_ipif); 8520Sstevel@tonic-gate sctp_g_ipifs[ipif_index].ipif_count--; 8530Sstevel@tonic-gate sctp_g_ipifs_count--; 8540Sstevel@tonic-gate rw_destroy(&sctp_ipif->sctp_ipif_lock); 8550Sstevel@tonic-gate kmem_free(sctp_ipif, sizeof (sctp_ipif_t)); 8560Sstevel@tonic-gate (void) atomic_add_32_nv(&sctp_ill->sctp_ill_ipifcnt, -1); 8570Sstevel@tonic-gate if (rw_tryupgrade(&sctp_g_ills_lock) != 0) { 8580Sstevel@tonic-gate rw_downgrade(&sctp_g_ipifs_lock); 8590Sstevel@tonic-gate if (sctp_ill->sctp_ill_ipifcnt == 0 && 8600Sstevel@tonic-gate sctp_ill->sctp_ill_state == SCTP_ILLS_CONDEMNED) { 8610Sstevel@tonic-gate list_remove(ill_list, (void *)sctp_ill); 8620Sstevel@tonic-gate sctp_ills_count--; 8630Sstevel@tonic-gate sctp_g_ills[ill_index].ill_count--; 8640Sstevel@tonic-gate kmem_free(sctp_ill->sctp_ill_name, 8650Sstevel@tonic-gate sctp_ill->sctp_ill_name_length); 8660Sstevel@tonic-gate kmem_free(sctp_ill, sizeof (sctp_ill_t)); 8670Sstevel@tonic-gate } 8680Sstevel@tonic-gate } 8690Sstevel@tonic-gate break; 8700Sstevel@tonic-gate } 8710Sstevel@tonic-gate 8720Sstevel@tonic-gate case SCTP_IPIF_UP: 8730Sstevel@tonic-gate 8740Sstevel@tonic-gate rw_downgrade(&sctp_g_ipifs_lock); 8750Sstevel@tonic-gate rw_enter(&sctp_ipif->sctp_ipif_lock, RW_WRITER); 8760Sstevel@tonic-gate sctp_ipif->sctp_ipif_state = SCTP_IPIFS_UP; 8770Sstevel@tonic-gate sctp_ipif->sctp_ipif_saddr = ipif->ipif_v6lcl_addr; 878432Svi117747 sctp_ipif->sctp_ipif_flags = ipif->ipif_flags; 879432Svi117747 sctp_ipif->sctp_ipif_mtu = ipif->ipif_mtu; 8800Sstevel@tonic-gate rw_exit(&sctp_ipif->sctp_ipif_lock); 8810Sstevel@tonic-gate 8820Sstevel@tonic-gate break; 8830Sstevel@tonic-gate 8840Sstevel@tonic-gate case SCTP_IPIF_UPDATE: 8850Sstevel@tonic-gate 8860Sstevel@tonic-gate rw_downgrade(&sctp_g_ipifs_lock); 8870Sstevel@tonic-gate rw_enter(&sctp_ipif->sctp_ipif_lock, RW_WRITER); 8880Sstevel@tonic-gate sctp_ipif->sctp_ipif_mtu = ipif->ipif_mtu; 8890Sstevel@tonic-gate sctp_ipif->sctp_ipif_saddr = ipif->ipif_v6lcl_addr; 8900Sstevel@tonic-gate sctp_ipif->sctp_ipif_zoneid = ipif->ipif_zoneid; 891432Svi117747 sctp_ipif->sctp_ipif_flags = ipif->ipif_flags; 8920Sstevel@tonic-gate rw_exit(&sctp_ipif->sctp_ipif_lock); 8930Sstevel@tonic-gate 8940Sstevel@tonic-gate break; 8950Sstevel@tonic-gate 8960Sstevel@tonic-gate case SCTP_IPIF_DOWN: 8970Sstevel@tonic-gate 8980Sstevel@tonic-gate rw_downgrade(&sctp_g_ipifs_lock); 8990Sstevel@tonic-gate rw_enter(&sctp_ipif->sctp_ipif_lock, RW_WRITER); 9000Sstevel@tonic-gate sctp_ipif->sctp_ipif_state = SCTP_IPIFS_DOWN; 9010Sstevel@tonic-gate rw_exit(&sctp_ipif->sctp_ipif_lock); 9020Sstevel@tonic-gate 9030Sstevel@tonic-gate break; 9040Sstevel@tonic-gate } 9050Sstevel@tonic-gate rw_exit(&sctp_g_ipifs_lock); 9060Sstevel@tonic-gate rw_exit(&sctp_g_ills_lock); 9070Sstevel@tonic-gate } 9080Sstevel@tonic-gate 9090Sstevel@tonic-gate /* 9100Sstevel@tonic-gate * 9110Sstevel@tonic-gate * 9120Sstevel@tonic-gate * SCTP source address list manipulaton, locking not used (except for 9130Sstevel@tonic-gate * sctp locking by the caller. 9140Sstevel@tonic-gate * 9150Sstevel@tonic-gate * 9160Sstevel@tonic-gate */ 9170Sstevel@tonic-gate 9180Sstevel@tonic-gate /* Remove a specific saddr from the list */ 9190Sstevel@tonic-gate void 9200Sstevel@tonic-gate sctp_del_saddr(sctp_t *sctp, sctp_saddr_ipif_t *sp) 9210Sstevel@tonic-gate { 9220Sstevel@tonic-gate if (sctp->sctp_conn_tfp != NULL) 9230Sstevel@tonic-gate mutex_enter(&sctp->sctp_conn_tfp->tf_lock); 9240Sstevel@tonic-gate 9250Sstevel@tonic-gate if (sctp->sctp_listen_tfp != NULL) 9260Sstevel@tonic-gate mutex_enter(&sctp->sctp_listen_tfp->tf_lock); 9270Sstevel@tonic-gate 9280Sstevel@tonic-gate sctp_ipif_hash_remove(sctp, sp->saddr_ipifp); 9290Sstevel@tonic-gate 930432Svi117747 if (sctp->sctp_bound_to_all == 1) 9310Sstevel@tonic-gate sctp->sctp_bound_to_all = 0; 9320Sstevel@tonic-gate 9330Sstevel@tonic-gate if (sctp->sctp_conn_tfp != NULL) 9340Sstevel@tonic-gate mutex_exit(&sctp->sctp_conn_tfp->tf_lock); 9350Sstevel@tonic-gate 9360Sstevel@tonic-gate if (sctp->sctp_listen_tfp != NULL) 9370Sstevel@tonic-gate mutex_exit(&sctp->sctp_listen_tfp->tf_lock); 9380Sstevel@tonic-gate } 9390Sstevel@tonic-gate 9400Sstevel@tonic-gate /* 9410Sstevel@tonic-gate * Delete source address from the existing list. No error checking done here 9420Sstevel@tonic-gate * Called with no locks held. 9430Sstevel@tonic-gate */ 9440Sstevel@tonic-gate void 9450Sstevel@tonic-gate sctp_del_saddr_list(sctp_t *sctp, const void *addrs, int addcnt, 9460Sstevel@tonic-gate boolean_t fanout_locked) 9470Sstevel@tonic-gate { 9480Sstevel@tonic-gate struct sockaddr_in *sin4; 9490Sstevel@tonic-gate struct sockaddr_in6 *sin6; 9500Sstevel@tonic-gate int cnt; 9510Sstevel@tonic-gate in6_addr_t addr; 9520Sstevel@tonic-gate sctp_ipif_t *sctp_ipif; 953852Svi117747 int ifindex = 0; 9540Sstevel@tonic-gate 955852Svi117747 ASSERT(sctp->sctp_nsaddrs >= addcnt); 9560Sstevel@tonic-gate 9570Sstevel@tonic-gate if (!fanout_locked) { 9580Sstevel@tonic-gate if (sctp->sctp_conn_tfp != NULL) 9590Sstevel@tonic-gate mutex_enter(&sctp->sctp_conn_tfp->tf_lock); 9600Sstevel@tonic-gate if (sctp->sctp_listen_tfp != NULL) 9610Sstevel@tonic-gate mutex_enter(&sctp->sctp_listen_tfp->tf_lock); 9620Sstevel@tonic-gate } 9630Sstevel@tonic-gate 9640Sstevel@tonic-gate for (cnt = 0; cnt < addcnt; cnt++) { 9650Sstevel@tonic-gate switch (sctp->sctp_family) { 9660Sstevel@tonic-gate case AF_INET: 9670Sstevel@tonic-gate sin4 = (struct sockaddr_in *)addrs + cnt; 9680Sstevel@tonic-gate IN6_INADDR_TO_V4MAPPED(&sin4->sin_addr, &addr); 9690Sstevel@tonic-gate break; 9700Sstevel@tonic-gate 9710Sstevel@tonic-gate case AF_INET6: 9720Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)addrs + cnt; 9730Sstevel@tonic-gate addr = sin6->sin6_addr; 974852Svi117747 ifindex = sin6->sin6_scope_id; 9750Sstevel@tonic-gate break; 9760Sstevel@tonic-gate } 9770Sstevel@tonic-gate sctp_ipif = sctp_lookup_ipif_addr(&addr, B_FALSE, 978852Svi117747 sctp->sctp_zoneid, ifindex); 9790Sstevel@tonic-gate ASSERT(sctp_ipif != NULL); 9800Sstevel@tonic-gate sctp_ipif_hash_remove(sctp, sctp_ipif); 9810Sstevel@tonic-gate } 982432Svi117747 if (sctp->sctp_bound_to_all == 1) 9830Sstevel@tonic-gate sctp->sctp_bound_to_all = 0; 9840Sstevel@tonic-gate 9850Sstevel@tonic-gate if (!fanout_locked) { 9860Sstevel@tonic-gate if (sctp->sctp_conn_tfp != NULL) 9870Sstevel@tonic-gate mutex_exit(&sctp->sctp_conn_tfp->tf_lock); 9880Sstevel@tonic-gate if (sctp->sctp_listen_tfp != NULL) 9890Sstevel@tonic-gate mutex_exit(&sctp->sctp_listen_tfp->tf_lock); 9900Sstevel@tonic-gate } 9910Sstevel@tonic-gate } 9920Sstevel@tonic-gate 9930Sstevel@tonic-gate /* 9940Sstevel@tonic-gate * Given an address get the corresponding entry from the list 9950Sstevel@tonic-gate * Called with no locks held. 9960Sstevel@tonic-gate */ 9970Sstevel@tonic-gate sctp_saddr_ipif_t * 998852Svi117747 sctp_saddr_lookup(sctp_t *sctp, in6_addr_t *addr, uint_t ifindex) 9990Sstevel@tonic-gate { 10000Sstevel@tonic-gate sctp_saddr_ipif_t *saddr_ipifs; 10010Sstevel@tonic-gate sctp_ipif_t *sctp_ipif; 10020Sstevel@tonic-gate 1003852Svi117747 sctp_ipif = sctp_lookup_ipif_addr(addr, B_FALSE, sctp->sctp_zoneid, 1004852Svi117747 ifindex); 10050Sstevel@tonic-gate if (sctp_ipif == NULL) 10060Sstevel@tonic-gate return (NULL); 10070Sstevel@tonic-gate 10080Sstevel@tonic-gate saddr_ipifs = sctp_ipif_lookup(sctp, sctp_ipif->sctp_ipif_id); 10090Sstevel@tonic-gate return (saddr_ipifs); 10100Sstevel@tonic-gate } 10110Sstevel@tonic-gate 1012432Svi117747 /* Given an address, add it to the source address list */ 1013432Svi117747 int 1014852Svi117747 sctp_saddr_add_addr(sctp_t *sctp, in6_addr_t *addr, uint_t ifindex) 1015432Svi117747 { 1016432Svi117747 sctp_ipif_t *sctp_ipif; 1017432Svi117747 1018852Svi117747 sctp_ipif = sctp_lookup_ipif_addr(addr, B_TRUE, sctp->sctp_zoneid, 1019852Svi117747 ifindex); 1020432Svi117747 if (sctp_ipif == NULL) 1021432Svi117747 return (EINVAL); 1022432Svi117747 1023432Svi117747 if (sctp_ipif_hash_insert(sctp, sctp_ipif, KM_NOSLEEP, B_FALSE) != 0) { 1024432Svi117747 SCTP_IPIF_REFRELE(sctp_ipif); 1025432Svi117747 return (EINVAL); 1026432Svi117747 } 1027432Svi117747 return (0); 1028432Svi117747 } 1029432Svi117747 1030432Svi117747 /* 1031432Svi117747 * Remove or mark as dontsrc addresses that are currently not part of the 1032432Svi117747 * association. One would delete addresses when processing an INIT and 1033432Svi117747 * mark as dontsrc when processing an INIT-ACK. 1034432Svi117747 */ 1035432Svi117747 void 1036432Svi117747 sctp_check_saddr(sctp_t *sctp, int supp_af, boolean_t delete) 1037432Svi117747 { 1038432Svi117747 int i; 1039432Svi117747 int l; 1040432Svi117747 sctp_saddr_ipif_t *obj; 1041432Svi117747 int scanned = 0; 1042432Svi117747 int naddr; 1043432Svi117747 int nsaddr; 1044432Svi117747 1045432Svi117747 ASSERT(!sctp->sctp_loopback && !sctp->sctp_linklocal && supp_af != 0); 1046432Svi117747 1047432Svi117747 /* 1048432Svi117747 * Irregardless of the supported address in the INIT, v4 1049432Svi117747 * must be supported. 1050432Svi117747 */ 1051432Svi117747 if (sctp->sctp_family == AF_INET) 1052432Svi117747 supp_af = PARM_SUPP_V4; 1053432Svi117747 1054432Svi117747 nsaddr = sctp->sctp_nsaddrs; 1055432Svi117747 for (i = 0; i < SCTP_IPIF_HASH; i++) { 1056432Svi117747 if (sctp->sctp_saddrs[i].ipif_count == 0) 1057432Svi117747 continue; 1058432Svi117747 obj = list_head(&sctp->sctp_saddrs[i].sctp_ipif_list); 1059432Svi117747 naddr = sctp->sctp_saddrs[i].ipif_count; 1060432Svi117747 for (l = 0; l < naddr; l++) { 1061432Svi117747 sctp_ipif_t *ipif; 1062432Svi117747 1063432Svi117747 ipif = obj->saddr_ipifp; 1064432Svi117747 scanned++; 1065432Svi117747 1066432Svi117747 /* 1067432Svi117747 * Delete/mark dontsrc loopback/linklocal addresses and 1068432Svi117747 * unsupported address. 1069852Svi117747 * On a clustered node, we trust the clustering module 1070852Svi117747 * to do the right thing w.r.t loopback addresses, so 1071852Svi117747 * we ignore loopback addresses in this check. 1072432Svi117747 */ 1073852Svi117747 if ((SCTP_IS_IPIF_LOOPBACK(ipif) && 1074852Svi117747 cl_sctp_check_addrs == NULL) || 1075852Svi117747 SCTP_IS_IPIF_LINKLOCAL(ipif) || 1076432Svi117747 SCTP_UNSUPP_AF(ipif, supp_af)) { 1077432Svi117747 if (!delete) { 1078432Svi117747 obj->saddr_ipif_unconfirmed = 1; 1079432Svi117747 goto next_obj; 1080432Svi117747 } 1081432Svi117747 if (sctp->sctp_bound_to_all == 1) 1082432Svi117747 sctp->sctp_bound_to_all = 0; 1083432Svi117747 if (scanned < nsaddr) { 1084432Svi117747 obj = list_next(&sctp->sctp_saddrs[i]. 1085432Svi117747 sctp_ipif_list, obj); 1086432Svi117747 sctp_ipif_hash_remove(sctp, ipif); 1087432Svi117747 continue; 1088432Svi117747 } 1089432Svi117747 sctp_ipif_hash_remove(sctp, ipif); 1090432Svi117747 } 1091432Svi117747 next_obj: 1092432Svi117747 if (scanned >= nsaddr) 1093432Svi117747 return; 1094432Svi117747 obj = list_next(&sctp->sctp_saddrs[i].sctp_ipif_list, 1095432Svi117747 obj); 1096432Svi117747 } 1097432Svi117747 } 1098432Svi117747 } 1099432Svi117747 1100432Svi117747 11010Sstevel@tonic-gate /* Get the first valid address from the list. Called with no locks held */ 11020Sstevel@tonic-gate in6_addr_t 11030Sstevel@tonic-gate sctp_get_valid_addr(sctp_t *sctp, boolean_t isv6) 11040Sstevel@tonic-gate { 11050Sstevel@tonic-gate int i; 11060Sstevel@tonic-gate int l; 11070Sstevel@tonic-gate sctp_saddr_ipif_t *obj; 11080Sstevel@tonic-gate int scanned = 0; 11090Sstevel@tonic-gate in6_addr_t addr; 11100Sstevel@tonic-gate 11110Sstevel@tonic-gate for (i = 0; i < SCTP_IPIF_HASH; i++) { 11120Sstevel@tonic-gate if (sctp->sctp_saddrs[i].ipif_count == 0) 11130Sstevel@tonic-gate continue; 11140Sstevel@tonic-gate obj = list_head(&sctp->sctp_saddrs[i].sctp_ipif_list); 11150Sstevel@tonic-gate for (l = 0; l < sctp->sctp_saddrs[i].ipif_count; l++) { 11160Sstevel@tonic-gate sctp_ipif_t *ipif; 11170Sstevel@tonic-gate 11180Sstevel@tonic-gate ipif = obj->saddr_ipifp; 1119432Svi117747 if (!SCTP_DONT_SRC(obj) && 11200Sstevel@tonic-gate ipif->sctp_ipif_isv6 == isv6 && 1121432Svi117747 ipif->sctp_ipif_state == SCTP_IPIFS_UP) { 11220Sstevel@tonic-gate return (ipif->sctp_ipif_saddr); 11230Sstevel@tonic-gate } 11240Sstevel@tonic-gate scanned++; 11250Sstevel@tonic-gate if (scanned >= sctp->sctp_nsaddrs) 11260Sstevel@tonic-gate goto got_none; 11270Sstevel@tonic-gate obj = list_next(&sctp->sctp_saddrs[i].sctp_ipif_list, 11280Sstevel@tonic-gate obj); 11290Sstevel@tonic-gate } 11300Sstevel@tonic-gate } 11310Sstevel@tonic-gate got_none: 11320Sstevel@tonic-gate /* Need to double check this */ 11330Sstevel@tonic-gate if (isv6 == B_TRUE) 11340Sstevel@tonic-gate addr = ipv6_all_zeros; 11350Sstevel@tonic-gate else 11360Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(0, &addr); 11370Sstevel@tonic-gate 11380Sstevel@tonic-gate return (addr); 11390Sstevel@tonic-gate } 11400Sstevel@tonic-gate 11410Sstevel@tonic-gate /* 11420Sstevel@tonic-gate * Return the list of local addresses of an association. The parameter 11430Sstevel@tonic-gate * myaddrs is supposed to be either (struct sockaddr_in *) or (struct 11440Sstevel@tonic-gate * sockaddr_in6 *) depending on the address family. 11450Sstevel@tonic-gate */ 11460Sstevel@tonic-gate int 11470Sstevel@tonic-gate sctp_getmyaddrs(void *conn, void *myaddrs, int *addrcnt) 11480Sstevel@tonic-gate { 11490Sstevel@tonic-gate int i; 11500Sstevel@tonic-gate int l; 11510Sstevel@tonic-gate sctp_saddr_ipif_t *obj; 11520Sstevel@tonic-gate sctp_t *sctp = (sctp_t *)conn; 11530Sstevel@tonic-gate int family = sctp->sctp_family; 11540Sstevel@tonic-gate int max = *addrcnt; 11550Sstevel@tonic-gate size_t added = 0; 11560Sstevel@tonic-gate struct sockaddr_in6 *sin6; 11570Sstevel@tonic-gate struct sockaddr_in *sin4; 11580Sstevel@tonic-gate int scanned = 0; 11590Sstevel@tonic-gate boolean_t skip_lback = B_FALSE; 11600Sstevel@tonic-gate 11610Sstevel@tonic-gate if (sctp->sctp_nsaddrs == 0) 11620Sstevel@tonic-gate return (EINVAL); 11630Sstevel@tonic-gate 1164852Svi117747 /* 1165852Svi117747 * Skip loopback addresses for non-loopback assoc., ignore 1166852Svi117747 * this on a clustered node. 1167852Svi117747 */ 1168852Svi117747 if (sctp->sctp_state >= SCTPS_ESTABLISHED && !sctp->sctp_loopback && 1169852Svi117747 (cl_sctp_check_addrs == NULL)) { 11700Sstevel@tonic-gate skip_lback = B_TRUE; 1171852Svi117747 } 1172852Svi117747 11730Sstevel@tonic-gate for (i = 0; i < SCTP_IPIF_HASH; i++) { 11740Sstevel@tonic-gate if (sctp->sctp_saddrs[i].ipif_count == 0) 11750Sstevel@tonic-gate continue; 11760Sstevel@tonic-gate obj = list_head(&sctp->sctp_saddrs[i].sctp_ipif_list); 11770Sstevel@tonic-gate for (l = 0; l < sctp->sctp_saddrs[i].ipif_count; l++) { 11780Sstevel@tonic-gate sctp_ipif_t *ipif = obj->saddr_ipifp; 11790Sstevel@tonic-gate in6_addr_t addr = ipif->sctp_ipif_saddr; 11800Sstevel@tonic-gate 11810Sstevel@tonic-gate scanned++; 11820Sstevel@tonic-gate if ((ipif->sctp_ipif_state == SCTP_IPIFS_CONDEMNED) || 1183432Svi117747 SCTP_DONT_SRC(obj) || 1184852Svi117747 (SCTP_IS_IPIF_LOOPBACK(ipif) && skip_lback)) { 11850Sstevel@tonic-gate if (scanned >= sctp->sctp_nsaddrs) 11860Sstevel@tonic-gate goto done; 11870Sstevel@tonic-gate obj = list_next(&sctp->sctp_saddrs[i]. 11880Sstevel@tonic-gate sctp_ipif_list, obj); 11890Sstevel@tonic-gate continue; 11900Sstevel@tonic-gate } 11910Sstevel@tonic-gate switch (family) { 11920Sstevel@tonic-gate case AF_INET: 11930Sstevel@tonic-gate sin4 = (struct sockaddr_in *)myaddrs + added; 11940Sstevel@tonic-gate sin4->sin_family = AF_INET; 11950Sstevel@tonic-gate sin4->sin_port = sctp->sctp_lport; 11960Sstevel@tonic-gate IN6_V4MAPPED_TO_INADDR(&addr, &sin4->sin_addr); 11970Sstevel@tonic-gate break; 11980Sstevel@tonic-gate 11990Sstevel@tonic-gate case AF_INET6: 12000Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)myaddrs + added; 12010Sstevel@tonic-gate sin6->sin6_family = AF_INET6; 12020Sstevel@tonic-gate sin6->sin6_port = sctp->sctp_lport; 12030Sstevel@tonic-gate sin6->sin6_addr = addr; 12040Sstevel@tonic-gate break; 12050Sstevel@tonic-gate } 12060Sstevel@tonic-gate added++; 12070Sstevel@tonic-gate if (added >= max || scanned >= sctp->sctp_nsaddrs) 12080Sstevel@tonic-gate goto done; 12090Sstevel@tonic-gate obj = list_next(&sctp->sctp_saddrs[i].sctp_ipif_list, 12100Sstevel@tonic-gate obj); 12110Sstevel@tonic-gate } 12120Sstevel@tonic-gate } 12130Sstevel@tonic-gate done: 12140Sstevel@tonic-gate *addrcnt = added; 12150Sstevel@tonic-gate return (0); 12160Sstevel@tonic-gate } 12170Sstevel@tonic-gate 12180Sstevel@tonic-gate /* 1219252Svi117747 * Given the supported address family, walk through the source address list 1220252Svi117747 * and return the total length of the available addresses. If 'p' is not 1221252Svi117747 * null, construct the parameter list for the addresses in 'p'. 1222432Svi117747 * 'modify' will only be set when we want the source address list to 1223432Svi117747 * be modified. The source address list will be modified only when 1224432Svi117747 * generating an INIT chunk. For generating an INIT-ACK 'modify' will 1225432Svi117747 * be false since the 'sctp' will be that of the listener. 12260Sstevel@tonic-gate */ 12270Sstevel@tonic-gate size_t 1228432Svi117747 sctp_saddr_info(sctp_t *sctp, int supp_af, uchar_t *p, boolean_t modify) 12290Sstevel@tonic-gate { 12300Sstevel@tonic-gate int i; 12310Sstevel@tonic-gate int l; 12320Sstevel@tonic-gate sctp_saddr_ipif_t *obj; 1233252Svi117747 size_t paramlen = 0; 12340Sstevel@tonic-gate sctp_parm_hdr_t *hdr; 12350Sstevel@tonic-gate int scanned = 0; 1236432Svi117747 int naddr; 1237432Svi117747 int nsaddr; 1238852Svi117747 boolean_t del_ll = B_FALSE; 1239852Svi117747 boolean_t del_lb = B_FALSE; 1240852Svi117747 12410Sstevel@tonic-gate 1242852Svi117747 /* 1243852Svi117747 * On a clustered node don't bother changing anything 1244852Svi117747 * on the loopback interface. 1245852Svi117747 */ 1246852Svi117747 if (modify && !sctp->sctp_loopback && (cl_sctp_check_addrs == NULL)) 1247852Svi117747 del_lb = B_TRUE; 1248852Svi117747 1249852Svi117747 if (modify && !sctp->sctp_linklocal) 1250852Svi117747 del_ll = B_TRUE; 1251432Svi117747 1252432Svi117747 nsaddr = sctp->sctp_nsaddrs; 12530Sstevel@tonic-gate for (i = 0; i < SCTP_IPIF_HASH; i++) { 12540Sstevel@tonic-gate if (sctp->sctp_saddrs[i].ipif_count == 0) 12550Sstevel@tonic-gate continue; 12560Sstevel@tonic-gate obj = list_head(&sctp->sctp_saddrs[i].sctp_ipif_list); 1257432Svi117747 naddr = sctp->sctp_saddrs[i].ipif_count; 1258432Svi117747 for (l = 0; l < naddr; l++) { 12590Sstevel@tonic-gate in6_addr_t addr; 12600Sstevel@tonic-gate sctp_ipif_t *ipif; 1261852Svi117747 boolean_t ipif_lb; 1262852Svi117747 boolean_t ipif_ll; 1263432Svi117747 boolean_t unsupp_af; 12640Sstevel@tonic-gate 12650Sstevel@tonic-gate ipif = obj->saddr_ipifp; 12660Sstevel@tonic-gate scanned++; 1267432Svi117747 1268852Svi117747 ipif_lb = SCTP_IS_IPIF_LOOPBACK(ipif); 1269852Svi117747 ipif_ll = SCTP_IS_IPIF_LINKLOCAL(ipif); 1270432Svi117747 unsupp_af = SCTP_UNSUPP_AF(ipif, supp_af); 1271432Svi117747 /* 1272432Svi117747 * We need to either delete or skip loopback/linklocal 1273852Svi117747 * or unsupported addresses, if required. 1274432Svi117747 */ 1275852Svi117747 if ((ipif_ll && del_ll) || (ipif_lb && del_lb) || 1276852Svi117747 (unsupp_af && modify)) { 1277432Svi117747 if (sctp->sctp_bound_to_all == 1) 1278432Svi117747 sctp->sctp_bound_to_all = 0; 1279432Svi117747 if (scanned < nsaddr) { 1280432Svi117747 obj = list_next(&sctp->sctp_saddrs[i]. 1281432Svi117747 sctp_ipif_list, obj); 1282432Svi117747 sctp_ipif_hash_remove(sctp, ipif); 1283432Svi117747 continue; 1284432Svi117747 } 1285432Svi117747 sctp_ipif_hash_remove(sctp, ipif); 1286432Svi117747 goto next_addr; 1287852Svi117747 } else if (ipif_ll || unsupp_af || 1288852Svi117747 (ipif_lb && (cl_sctp_check_addrs == NULL))) { 1289252Svi117747 goto next_addr; 12900Sstevel@tonic-gate } 1291432Svi117747 1292432Svi117747 if (!SCTP_IPIF_USABLE(ipif->sctp_ipif_state)) 1293432Svi117747 goto next_addr; 1294252Svi117747 if (p != NULL) 1295252Svi117747 hdr = (sctp_parm_hdr_t *)(p + paramlen); 12960Sstevel@tonic-gate addr = ipif->sctp_ipif_saddr; 1297432Svi117747 if (!ipif->sctp_ipif_isv6) { 12980Sstevel@tonic-gate struct in_addr *v4; 12990Sstevel@tonic-gate 1300252Svi117747 if (p != NULL) { 1301252Svi117747 hdr->sph_type = htons(PARM_ADDR4); 1302252Svi117747 hdr->sph_len = htons(PARM_ADDR4_LEN); 1303252Svi117747 v4 = (struct in_addr *)(hdr + 1); 1304252Svi117747 IN6_V4MAPPED_TO_INADDR(&addr, v4); 1305252Svi117747 } 1306252Svi117747 paramlen += PARM_ADDR4_LEN; 1307432Svi117747 } else { 1308252Svi117747 if (p != NULL) { 1309252Svi117747 hdr->sph_type = htons(PARM_ADDR6); 1310252Svi117747 hdr->sph_len = htons(PARM_ADDR6_LEN); 1311252Svi117747 bcopy(&addr, hdr + 1, sizeof (addr)); 1312252Svi117747 } 1313252Svi117747 paramlen += PARM_ADDR6_LEN; 13140Sstevel@tonic-gate } 1315252Svi117747 next_addr: 1316432Svi117747 if (scanned >= nsaddr) 1317252Svi117747 return (paramlen); 13180Sstevel@tonic-gate obj = list_next(&sctp->sctp_saddrs[i].sctp_ipif_list, 13190Sstevel@tonic-gate obj); 13200Sstevel@tonic-gate } 13210Sstevel@tonic-gate } 1322252Svi117747 return (paramlen); 13230Sstevel@tonic-gate } 13240Sstevel@tonic-gate 1325852Svi117747 /* 1326852Svi117747 * This is used on a clustered node to obtain a list of addresses, the list 1327852Svi117747 * consists of sockaddr_in structs for v4 and sockaddr_in6 for v6. The list 1328852Svi117747 * is then passed onto the clustering module which sends back the correct 1329852Svi117747 * list based on the port info. Regardless of the input, i.e INADDR_ANY 1330852Svi117747 * or specific address(es), we create the list since it could be modified by 1331852Svi117747 * the clustering module. When given a list of addresses, we simply 1332852Svi117747 * create the list of sockaddr_in or sockaddr_in6 structs using those 1333852Svi117747 * addresses. If there is an INADDR_ANY in the input list, or if the 1334852Svi117747 * input is INADDR_ANY, we create a list of sockaddr_in or sockaddr_in6 1335852Svi117747 * structs consisting all the addresses in the global interface list 1336852Svi117747 * except those that are hosted on the loopback interface. We create 1337852Svi117747 * a list of sockaddr_in[6] structs just so that it can be directly input 1338852Svi117747 * to sctp_valid_addr_list() once the clustering module has processed it. 1339852Svi117747 */ 1340852Svi117747 int 1341852Svi117747 sctp_get_addrlist(sctp_t *sctp, const void *addrs, uint32_t *addrcnt, 1342852Svi117747 uchar_t **addrlist, int *uspec, size_t *size) 1343852Svi117747 { 1344852Svi117747 int cnt; 1345852Svi117747 int icnt; 1346852Svi117747 sctp_ipif_t *sctp_ipif; 1347852Svi117747 struct sockaddr_in *s4; 1348852Svi117747 struct sockaddr_in6 *s6; 1349852Svi117747 uchar_t *p; 1350852Svi117747 int err = 0; 1351852Svi117747 1352852Svi117747 *addrlist = NULL; 1353852Svi117747 *size = 0; 1354852Svi117747 1355852Svi117747 /* 1356852Svi117747 * Create a list of sockaddr_in[6] structs using the input list. 1357852Svi117747 */ 1358852Svi117747 if (sctp->sctp_family == AF_INET) { 1359852Svi117747 *size = sizeof (struct sockaddr_in) * *addrcnt; 1360852Svi117747 *addrlist = kmem_zalloc(*size, KM_SLEEP); 1361852Svi117747 p = *addrlist; 1362852Svi117747 for (cnt = 0; cnt < *addrcnt; cnt++) { 1363852Svi117747 s4 = (struct sockaddr_in *)addrs + cnt; 1364852Svi117747 /* 1365852Svi117747 * We need to create a list of all the available 1366852Svi117747 * addresses if there is an INADDR_ANY. However, 1367852Svi117747 * if we are beyond LISTEN, then this is invalid 1368852Svi117747 * (see sctp_valid_addr_list(). So, we just fail 1369852Svi117747 * it here rather than wait till it fails in 1370852Svi117747 * sctp_valid_addr_list(). 1371852Svi117747 */ 1372852Svi117747 if (s4->sin_addr.s_addr == INADDR_ANY) { 1373852Svi117747 kmem_free(*addrlist, *size); 1374852Svi117747 *addrlist = NULL; 1375852Svi117747 *size = 0; 1376852Svi117747 if (sctp->sctp_state > SCTPS_LISTEN) { 1377852Svi117747 *addrcnt = 0; 1378852Svi117747 return (EINVAL); 1379852Svi117747 } 1380852Svi117747 if (uspec != NULL) 1381852Svi117747 *uspec = 1; 1382852Svi117747 goto get_all_addrs; 1383852Svi117747 } else { 1384852Svi117747 bcopy(s4, p, sizeof (*s4)); 1385852Svi117747 p += sizeof (*s4); 1386852Svi117747 } 1387852Svi117747 } 1388852Svi117747 } else { 1389852Svi117747 *size = sizeof (struct sockaddr_in6) * *addrcnt; 1390852Svi117747 *addrlist = kmem_zalloc(*size, KM_SLEEP); 1391852Svi117747 p = *addrlist; 1392852Svi117747 for (cnt = 0; cnt < *addrcnt; cnt++) { 1393852Svi117747 s6 = (struct sockaddr_in6 *)addrs + cnt; 1394852Svi117747 /* 1395852Svi117747 * Comments for INADDR_ANY, above, apply here too. 1396852Svi117747 */ 1397852Svi117747 if (IN6_IS_ADDR_UNSPECIFIED(&s6->sin6_addr)) { 1398852Svi117747 kmem_free(*addrlist, *size); 1399852Svi117747 *size = 0; 1400852Svi117747 *addrlist = NULL; 1401852Svi117747 if (sctp->sctp_state > SCTPS_LISTEN) { 1402852Svi117747 *addrcnt = 0; 1403852Svi117747 return (EINVAL); 1404852Svi117747 } 1405852Svi117747 if (uspec != NULL) 1406852Svi117747 *uspec = 1; 1407852Svi117747 goto get_all_addrs; 1408852Svi117747 } else { 1409852Svi117747 bcopy(addrs, p, sizeof (*s6)); 1410852Svi117747 p += sizeof (*s6); 1411852Svi117747 } 1412852Svi117747 } 1413852Svi117747 } 1414852Svi117747 return (err); 1415852Svi117747 get_all_addrs: 1416852Svi117747 1417852Svi117747 /* 1418852Svi117747 * Allocate max possible size. We allocate the max. size here because 1419852Svi117747 * the clustering module could end up adding addresses to the list. 1420852Svi117747 * We allocate upfront so that the clustering module need to bother 1421852Svi117747 * re-sizing the list. 1422852Svi117747 */ 1423852Svi117747 if (sctp->sctp_family == AF_INET) 1424852Svi117747 *size = sizeof (struct sockaddr_in) * sctp_g_ipifs_count; 1425852Svi117747 else 1426852Svi117747 *size = sizeof (struct sockaddr_in6) * sctp_g_ipifs_count; 1427852Svi117747 1428852Svi117747 *addrlist = kmem_zalloc(*size, KM_SLEEP); 1429852Svi117747 *addrcnt = 0; 1430852Svi117747 p = *addrlist; 1431852Svi117747 rw_enter(&sctp_g_ipifs_lock, RW_READER); 1432852Svi117747 1433852Svi117747 /* 1434852Svi117747 * Walk through the global interface list and add all addresses, 1435852Svi117747 * except those that are hosted on loopback interfaces. 1436852Svi117747 */ 1437852Svi117747 for (cnt = 0; cnt < SCTP_IPIF_HASH; cnt++) { 1438852Svi117747 if (sctp_g_ipifs[cnt].ipif_count == 0) 1439852Svi117747 continue; 1440852Svi117747 sctp_ipif = list_head(&sctp_g_ipifs[cnt].sctp_ipif_list); 1441852Svi117747 for (icnt = 0; icnt < sctp_g_ipifs[cnt].ipif_count; icnt++) { 1442852Svi117747 in6_addr_t addr; 1443852Svi117747 1444852Svi117747 rw_enter(&sctp_ipif->sctp_ipif_lock, RW_READER); 1445852Svi117747 addr = sctp_ipif->sctp_ipif_saddr; 1446852Svi117747 if (SCTP_IPIF_DISCARD(sctp_ipif->sctp_ipif_flags) || 1447852Svi117747 !SCTP_IPIF_USABLE(sctp_ipif->sctp_ipif_state) || 1448852Svi117747 SCTP_IS_IPIF_LOOPBACK(sctp_ipif) || 1449852Svi117747 SCTP_IS_IPIF_LINKLOCAL(sctp_ipif) || 1450852Svi117747 sctp_ipif->sctp_ipif_zoneid != sctp->sctp_zoneid || 1451852Svi117747 (sctp->sctp_ipversion == IPV4_VERSION && 1452852Svi117747 sctp_ipif->sctp_ipif_isv6) || 1453852Svi117747 (sctp->sctp_connp->conn_ipv6_v6only && 1454852Svi117747 !sctp_ipif->sctp_ipif_isv6)) { 1455852Svi117747 rw_exit(&sctp_ipif->sctp_ipif_lock); 1456852Svi117747 sctp_ipif = list_next( 1457852Svi117747 &sctp_g_ipifs[cnt].sctp_ipif_list, 1458852Svi117747 sctp_ipif); 1459852Svi117747 continue; 1460852Svi117747 } 1461852Svi117747 rw_exit(&sctp_ipif->sctp_ipif_lock); 1462852Svi117747 if (sctp->sctp_family == AF_INET) { 1463852Svi117747 s4 = (struct sockaddr_in *)p; 1464852Svi117747 IN6_V4MAPPED_TO_INADDR(&addr, &s4->sin_addr); 1465852Svi117747 s4->sin_family = AF_INET; 1466852Svi117747 p += sizeof (*s4); 1467852Svi117747 } else { 1468852Svi117747 s6 = (struct sockaddr_in6 *)p; 1469852Svi117747 s6->sin6_addr = addr; 1470852Svi117747 s6->sin6_family = AF_INET6; 1471852Svi117747 s6->sin6_scope_id = 1472852Svi117747 sctp_ipif->sctp_ipif_ill->sctp_ill_index; 1473852Svi117747 p += sizeof (*s6); 1474852Svi117747 } 1475852Svi117747 (*addrcnt)++; 1476852Svi117747 sctp_ipif = list_next(&sctp_g_ipifs[cnt].sctp_ipif_list, 1477852Svi117747 sctp_ipif); 1478852Svi117747 } 1479852Svi117747 } 1480852Svi117747 rw_exit(&sctp_g_ipifs_lock); 1481852Svi117747 return (err); 1482852Svi117747 } 1483852Svi117747 1484852Svi117747 /* 1485852Svi117747 * Get a list of addresses from the source address list. The caller is 1486852Svi117747 * responsible for allocating sufficient buffer for this. 1487852Svi117747 */ 1488852Svi117747 void 1489852Svi117747 sctp_get_saddr_list(sctp_t *sctp, uchar_t *p, size_t psize) 1490852Svi117747 { 1491852Svi117747 int cnt; 1492852Svi117747 int icnt; 1493852Svi117747 sctp_saddr_ipif_t *obj; 1494852Svi117747 int naddr; 1495852Svi117747 int scanned = 0; 1496852Svi117747 1497852Svi117747 for (cnt = 0; cnt < SCTP_IPIF_HASH; cnt++) { 1498852Svi117747 if (sctp->sctp_saddrs[cnt].ipif_count == 0) 1499852Svi117747 continue; 1500852Svi117747 obj = list_head(&sctp->sctp_saddrs[cnt].sctp_ipif_list); 1501852Svi117747 naddr = sctp->sctp_saddrs[cnt].ipif_count; 1502852Svi117747 for (icnt = 0; icnt < naddr; icnt++) { 1503852Svi117747 sctp_ipif_t *ipif; 1504852Svi117747 1505852Svi117747 if (psize < sizeof (ipif->sctp_ipif_saddr)) 1506852Svi117747 return; 1507852Svi117747 1508852Svi117747 scanned++; 1509852Svi117747 ipif = obj->saddr_ipifp; 1510852Svi117747 bcopy(&ipif->sctp_ipif_saddr, p, 1511852Svi117747 sizeof (ipif->sctp_ipif_saddr)); 1512852Svi117747 p += sizeof (ipif->sctp_ipif_saddr); 1513852Svi117747 psize -= sizeof (ipif->sctp_ipif_saddr); 1514852Svi117747 if (scanned >= sctp->sctp_nsaddrs) 1515852Svi117747 return; 1516852Svi117747 obj = list_next(&sctp->sctp_saddrs[icnt].sctp_ipif_list, 1517852Svi117747 obj); 1518852Svi117747 } 1519852Svi117747 } 1520852Svi117747 } 1521852Svi117747 1522852Svi117747 /* 1523852Svi117747 * Get a list of addresses from the remote address list. The caller is 1524852Svi117747 * responsible for allocating sufficient buffer for this. 1525852Svi117747 */ 1526852Svi117747 void 1527852Svi117747 sctp_get_faddr_list(sctp_t *sctp, uchar_t *p, size_t psize) 1528852Svi117747 { 1529852Svi117747 sctp_faddr_t *fp; 1530852Svi117747 1531852Svi117747 for (fp = sctp->sctp_faddrs; fp != NULL; fp = fp->next) { 1532852Svi117747 if (psize < sizeof (fp->faddr)) 1533852Svi117747 return; 1534852Svi117747 bcopy(&fp->faddr, p, sizeof (fp->faddr)); 1535852Svi117747 p += sizeof (fp->faddr); 1536852Svi117747 psize -= sizeof (fp->faddr); 1537852Svi117747 } 1538852Svi117747 } 15390Sstevel@tonic-gate 15400Sstevel@tonic-gate /* Initialize the SCTP ILL list and lock */ 15410Sstevel@tonic-gate void 15420Sstevel@tonic-gate sctp_saddr_init() 15430Sstevel@tonic-gate { 15440Sstevel@tonic-gate int i; 15450Sstevel@tonic-gate 15460Sstevel@tonic-gate rw_init(&sctp_g_ills_lock, NULL, RW_DEFAULT, NULL); 15470Sstevel@tonic-gate rw_init(&sctp_g_ipifs_lock, NULL, RW_DEFAULT, NULL); 15480Sstevel@tonic-gate 15490Sstevel@tonic-gate for (i = 0; i < SCTP_ILL_HASH; i++) { 15500Sstevel@tonic-gate sctp_g_ills[i].ill_count = 0; 15510Sstevel@tonic-gate list_create(&sctp_g_ills[i].sctp_ill_list, sizeof (sctp_ill_t), 15520Sstevel@tonic-gate offsetof(sctp_ill_t, sctp_ills)); 15530Sstevel@tonic-gate } 15540Sstevel@tonic-gate for (i = 0; i < SCTP_IPIF_HASH; i++) { 15550Sstevel@tonic-gate sctp_g_ipifs[i].ipif_count = 0; 15560Sstevel@tonic-gate list_create(&sctp_g_ipifs[i].sctp_ipif_list, 15570Sstevel@tonic-gate sizeof (sctp_ipif_t), offsetof(sctp_ipif_t, sctp_ipifs)); 15580Sstevel@tonic-gate } 15590Sstevel@tonic-gate } 15600Sstevel@tonic-gate 15610Sstevel@tonic-gate void 15620Sstevel@tonic-gate sctp_saddr_fini() 15630Sstevel@tonic-gate { 15640Sstevel@tonic-gate int i; 15650Sstevel@tonic-gate 15660Sstevel@tonic-gate rw_destroy(&sctp_g_ills_lock); 15670Sstevel@tonic-gate rw_destroy(&sctp_g_ipifs_lock); 15680Sstevel@tonic-gate ASSERT(sctp_ills_count == 0 && sctp_g_ipifs_count == 0); 15690Sstevel@tonic-gate for (i = 0; i < SCTP_ILL_HASH; i++) 15700Sstevel@tonic-gate list_destroy(&sctp_g_ills[i].sctp_ill_list); 15710Sstevel@tonic-gate for (i = 0; i < SCTP_IPIF_HASH; i++) 15720Sstevel@tonic-gate list_destroy(&sctp_g_ipifs[i].sctp_ipif_list); 15730Sstevel@tonic-gate } 1574