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 */ 211735Skcpoon 220Sstevel@tonic-gate /* 233448Sdh155122 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <sys/types.h> 300Sstevel@tonic-gate #include <sys/systm.h> 310Sstevel@tonic-gate #include <sys/stream.h> 320Sstevel@tonic-gate #include <sys/cmn_err.h> 330Sstevel@tonic-gate #include <sys/socket.h> 340Sstevel@tonic-gate #include <sys/kmem.h> 350Sstevel@tonic-gate #include <sys/strsubr.h> 360Sstevel@tonic-gate #include <sys/strsun.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/mib2.h> 463448Sdh155122 #include <inet/ipclassifier.h> 470Sstevel@tonic-gate #include "sctp_impl.h" 480Sstevel@tonic-gate #include "sctp_asconf.h" 490Sstevel@tonic-gate #include "sctp_addr.h" 500Sstevel@tonic-gate 510Sstevel@tonic-gate typedef struct sctp_asconf_s { 52852Svi117747 mblk_t *head; 53852Svi117747 uint32_t cid; 540Sstevel@tonic-gate } sctp_asconf_t; 550Sstevel@tonic-gate 560Sstevel@tonic-gate /* 57852Svi117747 * This is only used on a clustered node to maintain pre-allocated buffer info. 58852Svi117747 * before sending an ASCONF chunk. The reason for pre-allocation is we don't 59852Svi117747 * want to fail allocating memory when we get then ASCONF-ACK in order to 60852Svi117747 * update the clustering subsystem's state for this assoc. 61852Svi117747 */ 62852Svi117747 typedef struct sctp_cl_ainfo_s { 63852Svi117747 uchar_t *sctp_cl_alist; 64852Svi117747 size_t sctp_cl_asize; 65852Svi117747 uchar_t *sctp_cl_dlist; 66852Svi117747 size_t sctp_cl_dsize; 67852Svi117747 } sctp_cl_ainfo_t; 68852Svi117747 69852Svi117747 /* 700Sstevel@tonic-gate * The ASCONF chunk per-parameter request interface. ph is the 710Sstevel@tonic-gate * parameter header for the parameter in the request, and cid 720Sstevel@tonic-gate * is the parameters correlation ID. cont should be set to 1 730Sstevel@tonic-gate * if the ASCONF framework should continue processing request 740Sstevel@tonic-gate * parameters following this one, or 0 if it should stop. If 750Sstevel@tonic-gate * cont is -1, this indicates complete memory depletion, which 760Sstevel@tonic-gate * will cause the ASCONF framework to abort building a reply. If 770Sstevel@tonic-gate * act is 1, the callback should take whatever action it needs 780Sstevel@tonic-gate * to fulfil this request. If act is 0, this request has already 790Sstevel@tonic-gate * been processed, so the callback should only verify and pass 800Sstevel@tonic-gate * back error parameters, and not take any action. 810Sstevel@tonic-gate * 820Sstevel@tonic-gate * The callback should return an mblk with any reply enclosed, 830Sstevel@tonic-gate * with the correlation ID in the first four bytes of the 840Sstevel@tonic-gate * message. A NULL return implies implicit success to the 850Sstevel@tonic-gate * requestor. 860Sstevel@tonic-gate */ 870Sstevel@tonic-gate typedef mblk_t *sctp_asconf_func_t(sctp_t *, sctp_parm_hdr_t *ph, uint32_t cid, 88852Svi117747 sctp_faddr_t *, int *cont, int act, in6_addr_t *addr); 890Sstevel@tonic-gate 900Sstevel@tonic-gate /* 910Sstevel@tonic-gate * The ASCONF chunk per-parameter ACK interface. ph is the parameter 920Sstevel@tonic-gate * header for the parameter returned in the ACK, and oph is the 930Sstevel@tonic-gate * original parameter sent out in the ASCONF request. 940Sstevel@tonic-gate * If the peer implicitly responded OK (by not including an 950Sstevel@tonic-gate * explicit OK for the request), ph will be NULL. 960Sstevel@tonic-gate * ph can also point to an Unrecognized Parameter parameter, 970Sstevel@tonic-gate * in which case the peer did not understand the request 980Sstevel@tonic-gate * parameter. 990Sstevel@tonic-gate * 1000Sstevel@tonic-gate * ph and oph parameter headers are in host byte order. Encapsulated 1010Sstevel@tonic-gate * parameters will still be in network byte order. 1020Sstevel@tonic-gate */ 1030Sstevel@tonic-gate typedef void sctp_asconf_ack_func_t(sctp_t *, sctp_parm_hdr_t *ph, 104852Svi117747 sctp_parm_hdr_t *oph, sctp_faddr_t *, in6_addr_t *addr); 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate typedef struct { 1070Sstevel@tonic-gate uint16_t id; 1080Sstevel@tonic-gate sctp_asconf_func_t *asconf; 1090Sstevel@tonic-gate sctp_asconf_ack_func_t *asconf_ack; 1100Sstevel@tonic-gate } dispatch_t; 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate static sctp_asconf_func_t sctp_addip_req, sctp_setprim_req, 1130Sstevel@tonic-gate sctp_asconf_unrec_parm; 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate static sctp_asconf_ack_func_t sctp_addip_ack, sctp_setprim_ack, 1160Sstevel@tonic-gate sctp_asconf_ack_unrec_parm; 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate static const dispatch_t sctp_asconf_dispatch_tbl[] = { 1190Sstevel@tonic-gate /* ID ASCONF ASCONF_ACK */ 1200Sstevel@tonic-gate { PARM_ADD_IP, sctp_addip_req, sctp_addip_ack }, 1210Sstevel@tonic-gate { PARM_DEL_IP, sctp_addip_req, sctp_addip_ack }, 1220Sstevel@tonic-gate { PARM_SET_PRIMARY, sctp_setprim_req, sctp_setprim_ack } 1230Sstevel@tonic-gate }; 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate static const dispatch_t sctp_asconf_default_dispatch = { 1260Sstevel@tonic-gate 0, sctp_asconf_unrec_parm, sctp_asconf_ack_unrec_parm 1270Sstevel@tonic-gate }; 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate /* 1300Sstevel@tonic-gate * ASCONF framework 1310Sstevel@tonic-gate */ 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate static const dispatch_t * 1340Sstevel@tonic-gate sctp_lookup_asconf_dispatch(int id) 1350Sstevel@tonic-gate { 1360Sstevel@tonic-gate int i; 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate for (i = 0; i < A_CNT(sctp_asconf_dispatch_tbl); i++) { 1390Sstevel@tonic-gate if (sctp_asconf_dispatch_tbl[i].id == id) { 1400Sstevel@tonic-gate return (sctp_asconf_dispatch_tbl + i); 1410Sstevel@tonic-gate } 1420Sstevel@tonic-gate } 1430Sstevel@tonic-gate 1440Sstevel@tonic-gate return (&sctp_asconf_default_dispatch); 1450Sstevel@tonic-gate } 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate /* 1480Sstevel@tonic-gate * Frees mp on failure 1490Sstevel@tonic-gate */ 1500Sstevel@tonic-gate static mblk_t * 1510Sstevel@tonic-gate sctp_asconf_prepend_errwrap(mblk_t *mp, uint32_t cid) 1520Sstevel@tonic-gate { 1530Sstevel@tonic-gate mblk_t *wmp; 1540Sstevel@tonic-gate sctp_parm_hdr_t *wph; 1550Sstevel@tonic-gate 1560Sstevel@tonic-gate /* Prepend a wrapper err cause ind param */ 1570Sstevel@tonic-gate wmp = allocb(sizeof (*wph) + sizeof (cid), BPRI_MED); 1580Sstevel@tonic-gate if (wmp == NULL) { 1590Sstevel@tonic-gate freemsg(mp); 1600Sstevel@tonic-gate return (NULL); 1610Sstevel@tonic-gate } 1620Sstevel@tonic-gate wmp->b_wptr += sizeof (*wph) + sizeof (cid); 1630Sstevel@tonic-gate wph = (sctp_parm_hdr_t *)wmp->b_rptr; 1640Sstevel@tonic-gate wph->sph_type = htons(PARM_ERROR_IND); 1650Sstevel@tonic-gate wph->sph_len = htons(msgdsize(mp) + sizeof (*wph) + sizeof (cid)); 1660Sstevel@tonic-gate bcopy(&cid, wph + 1, sizeof (uint32_t)); 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate wmp->b_cont = mp; 1690Sstevel@tonic-gate return (wmp); 1700Sstevel@tonic-gate } 1710Sstevel@tonic-gate 1720Sstevel@tonic-gate /*ARGSUSED*/ 1730Sstevel@tonic-gate static mblk_t * 1740Sstevel@tonic-gate sctp_asconf_unrec_parm(sctp_t *sctp, sctp_parm_hdr_t *ph, uint32_t cid, 175852Svi117747 sctp_faddr_t *fp, int *cont, int act, in6_addr_t *addr) 1760Sstevel@tonic-gate { 1770Sstevel@tonic-gate mblk_t *mp = NULL; 1780Sstevel@tonic-gate 1790Sstevel@tonic-gate /* Unrecognized param; check the high order bits */ 1800Sstevel@tonic-gate if ((ph->sph_type & 0xc000) == 0xc000) { 1810Sstevel@tonic-gate /* report unrecognized param, and keep processing */ 1820Sstevel@tonic-gate sctp_add_unrec_parm(ph, &mp); 1830Sstevel@tonic-gate if (mp == NULL) { 1840Sstevel@tonic-gate *cont = -1; 1850Sstevel@tonic-gate return (NULL); 1860Sstevel@tonic-gate } 1870Sstevel@tonic-gate /* Prepend a the CID and a wrapper err cause ind param */ 1880Sstevel@tonic-gate mp = sctp_asconf_prepend_errwrap(mp, cid); 1890Sstevel@tonic-gate if (mp == NULL) { 1900Sstevel@tonic-gate *cont = -1; 1910Sstevel@tonic-gate return (NULL); 1920Sstevel@tonic-gate } 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate *cont = 1; 1950Sstevel@tonic-gate return (mp); 1960Sstevel@tonic-gate } 1970Sstevel@tonic-gate if (ph->sph_type & 0x4000) { 1980Sstevel@tonic-gate /* Stop processing and drop; report unrecognized param */ 1990Sstevel@tonic-gate sctp_add_unrec_parm(ph, &mp); 2000Sstevel@tonic-gate if (mp == NULL) { 2010Sstevel@tonic-gate *cont = -1; 2020Sstevel@tonic-gate return (NULL); 2030Sstevel@tonic-gate } 2040Sstevel@tonic-gate /* Prepend a the CID and a wrapper err cause ind param */ 2050Sstevel@tonic-gate mp = sctp_asconf_prepend_errwrap(mp, cid); 2060Sstevel@tonic-gate if (mp == NULL) { 2070Sstevel@tonic-gate *cont = -1; 2080Sstevel@tonic-gate return (NULL); 2090Sstevel@tonic-gate } 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate *cont = 0; 2120Sstevel@tonic-gate return (mp); 2130Sstevel@tonic-gate } 2140Sstevel@tonic-gate if (ph->sph_type & 0x8000) { 2150Sstevel@tonic-gate /* skip and continue processing */ 2160Sstevel@tonic-gate *cont = 1; 2170Sstevel@tonic-gate return (NULL); 2180Sstevel@tonic-gate } 2190Sstevel@tonic-gate 2200Sstevel@tonic-gate /* 2 high bits are clear; stop processing and drop packet */ 2210Sstevel@tonic-gate *cont = 0; 2220Sstevel@tonic-gate return (NULL); 2230Sstevel@tonic-gate } 2240Sstevel@tonic-gate 2250Sstevel@tonic-gate /*ARGSUSED*/ 2260Sstevel@tonic-gate static void 2270Sstevel@tonic-gate sctp_asconf_ack_unrec_parm(sctp_t *sctp, sctp_parm_hdr_t *ph, 228852Svi117747 sctp_parm_hdr_t *oph, sctp_faddr_t *fp, in6_addr_t *laddr) 2290Sstevel@tonic-gate { 2300Sstevel@tonic-gate ASSERT(ph); 2310Sstevel@tonic-gate sctp_error_event(sctp, (sctp_chunk_hdr_t *)ph); 2320Sstevel@tonic-gate } 2330Sstevel@tonic-gate 2340Sstevel@tonic-gate static void 2350Sstevel@tonic-gate sctp_asconf_init(sctp_asconf_t *asc) 2360Sstevel@tonic-gate { 2370Sstevel@tonic-gate ASSERT(asc != NULL); 2380Sstevel@tonic-gate 2390Sstevel@tonic-gate asc->head = NULL; 2400Sstevel@tonic-gate asc->cid = 0; 2410Sstevel@tonic-gate } 2420Sstevel@tonic-gate 2430Sstevel@tonic-gate static int 2440Sstevel@tonic-gate sctp_asconf_add(sctp_asconf_t *asc, mblk_t *mp) 2450Sstevel@tonic-gate { 2460Sstevel@tonic-gate uint32_t *cp; 2470Sstevel@tonic-gate 2480Sstevel@tonic-gate /* XXX can't exceed MTU */ 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate cp = (uint32_t *)(mp->b_rptr + sizeof (sctp_parm_hdr_t)); 2510Sstevel@tonic-gate *cp = asc->cid++; 2520Sstevel@tonic-gate 2530Sstevel@tonic-gate if (asc->head == NULL) 2540Sstevel@tonic-gate asc->head = mp; 2550Sstevel@tonic-gate else 2560Sstevel@tonic-gate linkb(asc->head, mp); 2570Sstevel@tonic-gate 2580Sstevel@tonic-gate return (0); 2590Sstevel@tonic-gate } 2600Sstevel@tonic-gate 2610Sstevel@tonic-gate static void 2620Sstevel@tonic-gate sctp_asconf_destroy(sctp_asconf_t *asc) 2630Sstevel@tonic-gate { 2640Sstevel@tonic-gate if (asc->head != NULL) { 2650Sstevel@tonic-gate freemsg(asc->head); 2660Sstevel@tonic-gate asc->head = NULL; 2670Sstevel@tonic-gate } 2680Sstevel@tonic-gate asc->cid = 0; 2690Sstevel@tonic-gate } 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate static int 272852Svi117747 sctp_asconf_send(sctp_t *sctp, sctp_asconf_t *asc, sctp_faddr_t *fp, 273852Svi117747 sctp_cl_ainfo_t *ainfo) 2740Sstevel@tonic-gate { 2750Sstevel@tonic-gate mblk_t *mp, *nmp; 2760Sstevel@tonic-gate sctp_chunk_hdr_t *ch; 2770Sstevel@tonic-gate boolean_t isv4; 2780Sstevel@tonic-gate size_t msgsize; 2790Sstevel@tonic-gate 2800Sstevel@tonic-gate ASSERT(asc != NULL && asc->head != NULL); 2810Sstevel@tonic-gate 2820Sstevel@tonic-gate isv4 = (fp != NULL) ? fp->isv4 : sctp->sctp_current->isv4; 2830Sstevel@tonic-gate 2840Sstevel@tonic-gate /* SCTP chunk header + Serial Number + Address Param TLV */ 2850Sstevel@tonic-gate msgsize = sizeof (*ch) + sizeof (uint32_t) + 2860Sstevel@tonic-gate (isv4 ? PARM_ADDR4_LEN : PARM_ADDR6_LEN); 2870Sstevel@tonic-gate 2880Sstevel@tonic-gate mp = allocb(msgsize, BPRI_MED); 2890Sstevel@tonic-gate if (mp == NULL) 2900Sstevel@tonic-gate return (ENOMEM); 2910Sstevel@tonic-gate 2920Sstevel@tonic-gate mp->b_wptr += msgsize; 2930Sstevel@tonic-gate mp->b_cont = asc->head; 2940Sstevel@tonic-gate 2950Sstevel@tonic-gate ch = (sctp_chunk_hdr_t *)mp->b_rptr; 2960Sstevel@tonic-gate ch->sch_id = CHUNK_ASCONF; 2970Sstevel@tonic-gate ch->sch_flags = 0; 2980Sstevel@tonic-gate ch->sch_len = htons(msgdsize(mp)); 2990Sstevel@tonic-gate 3000Sstevel@tonic-gate nmp = msgpullup(mp, -1); 3010Sstevel@tonic-gate if (nmp == NULL) { 3020Sstevel@tonic-gate freeb(mp); 3030Sstevel@tonic-gate return (ENOMEM); 3040Sstevel@tonic-gate } 3050Sstevel@tonic-gate 306852Svi117747 /* 307852Svi117747 * Stash the address list and the count so that when the operation 308852Svi117747 * completes, i.e. when as get an ACK, we can update the clustering's 309852Svi117747 * state for this association. 310852Svi117747 */ 311852Svi117747 if (ainfo != NULL) { 312852Svi117747 ASSERT(cl_sctp_assoc_change != NULL); 313852Svi117747 ASSERT(nmp->b_prev == NULL); 314852Svi117747 nmp->b_prev = (mblk_t *)ainfo; 315852Svi117747 } 3160Sstevel@tonic-gate /* Clean up the temporary mblk chain */ 3170Sstevel@tonic-gate freemsg(mp); 3180Sstevel@tonic-gate asc->head = NULL; 3190Sstevel@tonic-gate asc->cid = 0; 3200Sstevel@tonic-gate 3210Sstevel@tonic-gate /* Queue it ... */ 3220Sstevel@tonic-gate if (sctp->sctp_cxmit_list == NULL) { 3230Sstevel@tonic-gate sctp->sctp_cxmit_list = nmp; 3240Sstevel@tonic-gate } else { 3250Sstevel@tonic-gate linkb(sctp->sctp_cxmit_list, nmp); 3260Sstevel@tonic-gate } 3270Sstevel@tonic-gate 3280Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_obchunks); 3290Sstevel@tonic-gate 3300Sstevel@tonic-gate /* And try to send it. */ 3310Sstevel@tonic-gate sctp_wput_asconf(sctp, fp); 3320Sstevel@tonic-gate 3330Sstevel@tonic-gate return (0); 3340Sstevel@tonic-gate } 3350Sstevel@tonic-gate 3360Sstevel@tonic-gate /* 3370Sstevel@tonic-gate * If the peer does not understand an ASCONF chunk, we simply 3380Sstevel@tonic-gate * clear out the cxmit_list, since we can send nothing further 3390Sstevel@tonic-gate * that the peer will understand. 3400Sstevel@tonic-gate * 3410Sstevel@tonic-gate * Assumes chunk length has already been checked. 3420Sstevel@tonic-gate */ 3430Sstevel@tonic-gate /*ARGSUSED*/ 3440Sstevel@tonic-gate void 345852Svi117747 sctp_asconf_free_cxmit(sctp_t *sctp, sctp_chunk_hdr_t *ch) 3460Sstevel@tonic-gate { 347852Svi117747 mblk_t *mp; 348852Svi117747 mblk_t *mp1; 349852Svi117747 sctp_cl_ainfo_t *ainfo; 350852Svi117747 3510Sstevel@tonic-gate if (sctp->sctp_cxmit_list == NULL) { 3520Sstevel@tonic-gate /* Nothing pending */ 3530Sstevel@tonic-gate return; 3540Sstevel@tonic-gate } 3550Sstevel@tonic-gate 356852Svi117747 mp = sctp->sctp_cxmit_list; 357852Svi117747 while (mp != NULL) { 358852Svi117747 mp1 = mp->b_cont; 359852Svi117747 mp->b_cont = NULL; 360852Svi117747 if (mp->b_prev != NULL) { 361852Svi117747 ainfo = (sctp_cl_ainfo_t *)mp->b_prev; 362852Svi117747 mp->b_prev = NULL; 363852Svi117747 kmem_free(ainfo->sctp_cl_alist, ainfo->sctp_cl_asize); 364852Svi117747 kmem_free(ainfo->sctp_cl_dlist, ainfo->sctp_cl_dsize); 365852Svi117747 kmem_free(ainfo, sizeof (*ainfo)); 366852Svi117747 } 367852Svi117747 freeb(mp); 368852Svi117747 mp = mp1; 369852Svi117747 } 3700Sstevel@tonic-gate sctp->sctp_cxmit_list = NULL; 3710Sstevel@tonic-gate } 3720Sstevel@tonic-gate 3730Sstevel@tonic-gate void 3740Sstevel@tonic-gate sctp_input_asconf(sctp_t *sctp, sctp_chunk_hdr_t *ch, sctp_faddr_t *fp) 3750Sstevel@tonic-gate { 3760Sstevel@tonic-gate const dispatch_t *dp; 3770Sstevel@tonic-gate mblk_t *hmp; 3780Sstevel@tonic-gate mblk_t *mp; 3790Sstevel@tonic-gate uint32_t *idp; 3800Sstevel@tonic-gate uint32_t *hidp; 3810Sstevel@tonic-gate ssize_t rlen; 3820Sstevel@tonic-gate sctp_parm_hdr_t *ph; 3830Sstevel@tonic-gate sctp_chunk_hdr_t *ach; 3840Sstevel@tonic-gate int cont; 3850Sstevel@tonic-gate int act; 3860Sstevel@tonic-gate uint16_t plen; 387852Svi117747 uchar_t *alist = NULL; 388852Svi117747 size_t asize = 0; 389852Svi117747 uchar_t *dlist = NULL; 390852Svi117747 size_t dsize = 0; 391852Svi117747 uchar_t *aptr = NULL; 392852Svi117747 uchar_t *dptr = NULL; 393852Svi117747 int acount = 0; 394852Svi117747 int dcount = 0; 3953448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 3960Sstevel@tonic-gate 3970Sstevel@tonic-gate ASSERT(ch->sch_id == CHUNK_ASCONF); 3980Sstevel@tonic-gate 3990Sstevel@tonic-gate idp = (uint32_t *)(ch + 1); 4000Sstevel@tonic-gate rlen = ntohs(ch->sch_len) - sizeof (*ch) - sizeof (*idp); 4010Sstevel@tonic-gate 4020Sstevel@tonic-gate if (rlen < 0 || rlen < sizeof (*idp)) { 4030Sstevel@tonic-gate /* nothing there; bail out */ 4040Sstevel@tonic-gate return; 4050Sstevel@tonic-gate } 4060Sstevel@tonic-gate 4070Sstevel@tonic-gate /* Check for duplicates */ 4080Sstevel@tonic-gate *idp = ntohl(*idp); 4090Sstevel@tonic-gate if (*idp == (sctp->sctp_fcsn + 1)) { 4100Sstevel@tonic-gate act = 1; 4110Sstevel@tonic-gate } else if (*idp == sctp->sctp_fcsn) { 4120Sstevel@tonic-gate act = 0; 4130Sstevel@tonic-gate } else { 4140Sstevel@tonic-gate /* stale or malicious packet; drop */ 4150Sstevel@tonic-gate return; 4160Sstevel@tonic-gate } 4170Sstevel@tonic-gate 4180Sstevel@tonic-gate /* Create the ASCONF_ACK header */ 4190Sstevel@tonic-gate hmp = sctp_make_mp(sctp, fp, sizeof (*ach) + sizeof (*idp)); 4200Sstevel@tonic-gate if (hmp == NULL) { 4210Sstevel@tonic-gate /* Let the peer retransmit */ 4223448Sdh155122 SCTP_KSTAT(sctps, sctp_send_asconf_ack_failed); 4230Sstevel@tonic-gate return; 4240Sstevel@tonic-gate } 4250Sstevel@tonic-gate ach = (sctp_chunk_hdr_t *)hmp->b_wptr; 4260Sstevel@tonic-gate ach->sch_id = CHUNK_ASCONF_ACK; 4270Sstevel@tonic-gate ach->sch_flags = 0; 4280Sstevel@tonic-gate /* Set the length later */ 4290Sstevel@tonic-gate hidp = (uint32_t *)(ach + 1); 4300Sstevel@tonic-gate *hidp = htonl(*idp); 4310Sstevel@tonic-gate hmp->b_wptr = (uchar_t *)(hidp + 1); 4320Sstevel@tonic-gate 4330Sstevel@tonic-gate /* Move to the Address Parameter */ 4340Sstevel@tonic-gate ph = (sctp_parm_hdr_t *)(idp + 1); 4350Sstevel@tonic-gate if (rlen <= ntohs(ph->sph_len)) { 4360Sstevel@tonic-gate freeb(hmp); 4370Sstevel@tonic-gate return; 4380Sstevel@tonic-gate } 4390Sstevel@tonic-gate 4400Sstevel@tonic-gate /* 4410Sstevel@tonic-gate * We already have the association here, so this address parameter 4420Sstevel@tonic-gate * doesn't seem to be very useful, should we make sure this is part 4430Sstevel@tonic-gate * of the association and send an error, if not? 4440Sstevel@tonic-gate * Ignore it for now. 4450Sstevel@tonic-gate */ 4460Sstevel@tonic-gate rlen -= ntohs(ph->sph_len); 4470Sstevel@tonic-gate ph = (sctp_parm_hdr_t *)((char *)ph + ntohs(ph->sph_len)); 448852Svi117747 449852Svi117747 /* 450852Svi117747 * We need to pre-allocate buffer before processing the ASCONF 451852Svi117747 * chunk. We don't want to fail allocating buffers after processing 452852Svi117747 * the ASCONF chunk. So, we walk the list and get the number of 453852Svi117747 * addresses added and/or deleted. 454852Svi117747 */ 455852Svi117747 if (cl_sctp_assoc_change != NULL) { 456852Svi117747 sctp_parm_hdr_t *oph = ph; 457852Svi117747 ssize_t orlen = rlen; 458852Svi117747 459852Svi117747 /* 460852Svi117747 * This not very efficient, but there is no better way of 461852Svi117747 * doing it. It should be fine since normally the param list 462852Svi117747 * will not be very long. 463852Svi117747 */ 464852Svi117747 while (orlen > 0) { 465852Svi117747 /* Sanity checks */ 466852Svi117747 if (orlen < sizeof (*oph)) 467852Svi117747 break; 468852Svi117747 plen = ntohs(oph->sph_len); 469852Svi117747 if (plen < sizeof (*oph) || plen > orlen) 470852Svi117747 break; 471852Svi117747 if (oph->sph_type == htons(PARM_ADD_IP)) 472852Svi117747 acount++; 473852Svi117747 if (oph->sph_type == htons(PARM_DEL_IP)) 474852Svi117747 dcount++; 475852Svi117747 oph = sctp_next_parm(oph, &orlen); 476852Svi117747 if (oph == NULL) 477852Svi117747 break; 478852Svi117747 } 479852Svi117747 if (acount > 0 || dcount > 0) { 480852Svi117747 if (acount > 0) { 481852Svi117747 asize = sizeof (in6_addr_t) * acount; 482852Svi117747 alist = kmem_alloc(asize, KM_NOSLEEP); 483852Svi117747 if (alist == NULL) { 484852Svi117747 freeb(hmp); 4853448Sdh155122 SCTP_KSTAT(sctps, sctp_cl_assoc_change); 486852Svi117747 return; 487852Svi117747 } 488852Svi117747 } 489852Svi117747 if (dcount > 0) { 490852Svi117747 dsize = sizeof (in6_addr_t) * dcount; 491852Svi117747 dlist = kmem_alloc(dsize, KM_NOSLEEP); 492852Svi117747 if (dlist == NULL) { 493852Svi117747 if (acount > 0) 494852Svi117747 kmem_free(alist, asize); 495852Svi117747 freeb(hmp); 4963448Sdh155122 SCTP_KSTAT(sctps, sctp_cl_assoc_change); 497852Svi117747 return; 498852Svi117747 } 499852Svi117747 } 500852Svi117747 aptr = alist; 501852Svi117747 dptr = dlist; 502852Svi117747 /* 503852Svi117747 * We will get the actual count when we process 504852Svi117747 * the chunk. 505852Svi117747 */ 506852Svi117747 acount = 0; 507852Svi117747 dcount = 0; 508852Svi117747 } 509852Svi117747 } 5100Sstevel@tonic-gate cont = 1; 5110Sstevel@tonic-gate while (rlen > 0 && cont) { 512852Svi117747 in6_addr_t addr; 513852Svi117747 5140Sstevel@tonic-gate /* Sanity checks */ 5150Sstevel@tonic-gate if (rlen < sizeof (*ph)) 5160Sstevel@tonic-gate break; 5170Sstevel@tonic-gate plen = ntohs(ph->sph_len); 5180Sstevel@tonic-gate if (plen < sizeof (*ph) || plen > rlen) { 5190Sstevel@tonic-gate break; 5200Sstevel@tonic-gate } 5210Sstevel@tonic-gate idp = (uint32_t *)(ph + 1); 5220Sstevel@tonic-gate dp = sctp_lookup_asconf_dispatch(ntohs(ph->sph_type)); 5230Sstevel@tonic-gate ASSERT(dp); 5240Sstevel@tonic-gate if (dp->asconf) { 525852Svi117747 mp = dp->asconf(sctp, ph, *idp, fp, &cont, act, &addr); 5260Sstevel@tonic-gate if (cont == -1) { 5270Sstevel@tonic-gate /* 5280Sstevel@tonic-gate * Not even enough memory to create 5290Sstevel@tonic-gate * an out-of-resources error. Free 5300Sstevel@tonic-gate * everything and return; the peer 5310Sstevel@tonic-gate * should retransmit. 5320Sstevel@tonic-gate */ 5330Sstevel@tonic-gate freemsg(hmp); 534852Svi117747 if (alist != NULL) 535852Svi117747 kmem_free(alist, asize); 536852Svi117747 if (dlist != NULL) 537852Svi117747 kmem_free(dlist, dsize); 5380Sstevel@tonic-gate return; 5390Sstevel@tonic-gate } 5400Sstevel@tonic-gate if (mp != NULL) { 5410Sstevel@tonic-gate linkb(hmp, mp); 542852Svi117747 } else if (act != 0) { 543852Svi117747 /* update the add/delete list */ 544852Svi117747 if (cl_sctp_assoc_change != NULL) { 545852Svi117747 if (ph->sph_type == 546852Svi117747 htons(PARM_ADD_IP)) { 547852Svi117747 ASSERT(alist != NULL); 548852Svi117747 bcopy(&addr, aptr, 549852Svi117747 sizeof (addr)); 550852Svi117747 aptr += sizeof (addr); 551852Svi117747 acount++; 552852Svi117747 } else if (ph->sph_type == 553852Svi117747 htons(PARM_DEL_IP)) { 554852Svi117747 ASSERT(dlist != NULL); 555852Svi117747 bcopy(&addr, dptr, 556852Svi117747 sizeof (addr)); 557852Svi117747 dptr += sizeof (addr); 558852Svi117747 dcount++; 559852Svi117747 } 560852Svi117747 } 5610Sstevel@tonic-gate } 5620Sstevel@tonic-gate } 5630Sstevel@tonic-gate ph = sctp_next_parm(ph, &rlen); 5640Sstevel@tonic-gate if (ph == NULL) 5650Sstevel@tonic-gate break; 5660Sstevel@tonic-gate } 5670Sstevel@tonic-gate 568852Svi117747 /* 569852Svi117747 * Update clustering's state for this assoc. Note acount/dcount 570852Svi117747 * could be zero (i.e. if the add/delete address(es) were not 571852Svi117747 * processed successfully). Regardless, if the ?size is > 0, 572852Svi117747 * it is the clustering module's responsibility to free the lists. 573852Svi117747 */ 574852Svi117747 if (cl_sctp_assoc_change != NULL) { 575852Svi117747 (*cl_sctp_assoc_change)(sctp->sctp_family, alist, asize, 576852Svi117747 acount, dlist, dsize, dcount, SCTP_CL_PADDR, 577852Svi117747 (cl_sctp_handle_t)sctp); 578852Svi117747 /* alist and dlist will be freed by the clustering module */ 579852Svi117747 } 5800Sstevel@tonic-gate /* Now that the params have been processed, increment the fcsn */ 5810Sstevel@tonic-gate if (act) { 5820Sstevel@tonic-gate sctp->sctp_fcsn++; 5830Sstevel@tonic-gate } 5840Sstevel@tonic-gate BUMP_LOCAL(sctp->sctp_obchunks); 5850Sstevel@tonic-gate 5860Sstevel@tonic-gate if (fp->isv4) 5870Sstevel@tonic-gate ach->sch_len = htons(msgdsize(hmp) - sctp->sctp_hdr_len); 5880Sstevel@tonic-gate else 5890Sstevel@tonic-gate ach->sch_len = htons(msgdsize(hmp) - sctp->sctp_hdr6_len); 5900Sstevel@tonic-gate sctp_set_iplen(sctp, hmp); 5910Sstevel@tonic-gate 5920Sstevel@tonic-gate sctp_add_sendq(sctp, hmp); 5930Sstevel@tonic-gate sctp_validate_peer(sctp); 5940Sstevel@tonic-gate } 5950Sstevel@tonic-gate 5960Sstevel@tonic-gate static sctp_parm_hdr_t * 5970Sstevel@tonic-gate sctp_lookup_asconf_param(sctp_parm_hdr_t *ph, uint32_t cid, ssize_t rlen) 5980Sstevel@tonic-gate { 5990Sstevel@tonic-gate uint32_t *idp; 6000Sstevel@tonic-gate 6010Sstevel@tonic-gate while (rlen > 0) { 6020Sstevel@tonic-gate idp = (uint32_t *)(ph + 1); 6030Sstevel@tonic-gate if (*idp == cid) { 6040Sstevel@tonic-gate return (ph); 6050Sstevel@tonic-gate } 6060Sstevel@tonic-gate ph = sctp_next_parm(ph, &rlen); 6070Sstevel@tonic-gate if (ph == NULL) 6080Sstevel@tonic-gate break; 6090Sstevel@tonic-gate } 6100Sstevel@tonic-gate return (NULL); 6110Sstevel@tonic-gate } 6120Sstevel@tonic-gate 6130Sstevel@tonic-gate void 6140Sstevel@tonic-gate sctp_input_asconf_ack(sctp_t *sctp, sctp_chunk_hdr_t *ch, sctp_faddr_t *fp) 6150Sstevel@tonic-gate { 6160Sstevel@tonic-gate const dispatch_t *dp; 6170Sstevel@tonic-gate uint32_t *idp; 6180Sstevel@tonic-gate uint32_t *snp; 6190Sstevel@tonic-gate ssize_t rlen; 6200Sstevel@tonic-gate ssize_t plen; 6210Sstevel@tonic-gate sctp_parm_hdr_t *ph; 6220Sstevel@tonic-gate sctp_parm_hdr_t *oph; 6230Sstevel@tonic-gate sctp_parm_hdr_t *fph; 6240Sstevel@tonic-gate mblk_t *mp; 6250Sstevel@tonic-gate sctp_chunk_hdr_t *och; 6260Sstevel@tonic-gate int redosrcs = 0; 6270Sstevel@tonic-gate uint16_t param_len; 628852Svi117747 uchar_t *alist; 629852Svi117747 uchar_t *dlist; 630852Svi117747 uint_t acount = 0; 631852Svi117747 uint_t dcount = 0; 632852Svi117747 uchar_t *aptr; 633852Svi117747 uchar_t *dptr; 634852Svi117747 sctp_cl_ainfo_t *ainfo; 635852Svi117747 in6_addr_t addr; 6360Sstevel@tonic-gate 6370Sstevel@tonic-gate ASSERT(ch->sch_id == CHUNK_ASCONF_ACK); 6380Sstevel@tonic-gate 6390Sstevel@tonic-gate snp = (uint32_t *)(ch + 1); 6400Sstevel@tonic-gate rlen = ntohs(ch->sch_len) - sizeof (*ch) - sizeof (*snp); 6410Sstevel@tonic-gate if (rlen < 0) { 6420Sstevel@tonic-gate return; 6430Sstevel@tonic-gate } 6440Sstevel@tonic-gate 6450Sstevel@tonic-gate /* Accept only an ACK for the current serial number */ 6460Sstevel@tonic-gate *snp = ntohl(*snp); 6470Sstevel@tonic-gate if (sctp->sctp_cxmit_list == NULL || *snp != (sctp->sctp_lcsn - 1)) { 6480Sstevel@tonic-gate /* Need to send an abort */ 6490Sstevel@tonic-gate return; 6500Sstevel@tonic-gate } 6510Sstevel@tonic-gate sctp->sctp_cchunk_pend = 0; 6520Sstevel@tonic-gate SCTP_FADDR_RC_TIMER_STOP(fp); 6530Sstevel@tonic-gate 654852Svi117747 mp = sctp->sctp_cxmit_list; 655852Svi117747 /* 656852Svi117747 * We fill in the addresses here to update the clustering's state for 657852Svi117747 * this assoc. 658852Svi117747 */ 659852Svi117747 if (mp != NULL && cl_sctp_assoc_change != NULL) { 660852Svi117747 ASSERT(mp->b_prev != NULL); 661852Svi117747 ainfo = (sctp_cl_ainfo_t *)mp->b_prev; 662852Svi117747 alist = ainfo->sctp_cl_alist; 663852Svi117747 dlist = ainfo->sctp_cl_dlist; 664852Svi117747 aptr = alist; 665852Svi117747 dptr = dlist; 666852Svi117747 } 667852Svi117747 6680Sstevel@tonic-gate /* 6690Sstevel@tonic-gate * Pass explicit replies to callbacks: 6700Sstevel@tonic-gate * For each reply in the ACK, look up the corresponding 6710Sstevel@tonic-gate * original parameter in the request using the correlation 6720Sstevel@tonic-gate * ID, and pass it to the right callback. 6730Sstevel@tonic-gate */ 6740Sstevel@tonic-gate och = (sctp_chunk_hdr_t *)sctp->sctp_cxmit_list->b_rptr; 6750Sstevel@tonic-gate 6760Sstevel@tonic-gate plen = ntohs(och->sch_len) - sizeof (*och) - sizeof (*idp); 6770Sstevel@tonic-gate idp = (uint32_t *)(och + 1); 6780Sstevel@tonic-gate 6790Sstevel@tonic-gate /* Get to the 1st ASCONF param, need to skip Address TLV parm */ 6800Sstevel@tonic-gate fph = (sctp_parm_hdr_t *)(idp + 1); 6810Sstevel@tonic-gate plen -= ntohs(fph->sph_len); 6820Sstevel@tonic-gate fph = (sctp_parm_hdr_t *)((char *)fph + ntohs(fph->sph_len)); 6830Sstevel@tonic-gate ph = (sctp_parm_hdr_t *)(snp + 1); 6840Sstevel@tonic-gate while (rlen > 0) { 6850Sstevel@tonic-gate /* Sanity checks */ 6860Sstevel@tonic-gate if (rlen < sizeof (*ph)) { 6870Sstevel@tonic-gate break; 6880Sstevel@tonic-gate } 6890Sstevel@tonic-gate param_len = ntohs(ph->sph_len); 6900Sstevel@tonic-gate if (param_len < sizeof (*ph) || param_len > rlen) { 6910Sstevel@tonic-gate break; 6920Sstevel@tonic-gate } 6930Sstevel@tonic-gate idp = (uint32_t *)(ph + 1); 6940Sstevel@tonic-gate oph = sctp_lookup_asconf_param(fph, *idp, plen); 6950Sstevel@tonic-gate if (oph != NULL) { 6960Sstevel@tonic-gate dp = sctp_lookup_asconf_dispatch(ntohs(oph->sph_type)); 6970Sstevel@tonic-gate ASSERT(dp); 6980Sstevel@tonic-gate if (dp->asconf_ack) { 699852Svi117747 dp->asconf_ack(sctp, ph, oph, fp, &addr); 7000Sstevel@tonic-gate 7010Sstevel@tonic-gate /* hack. see below */ 7020Sstevel@tonic-gate if (oph->sph_type == htons(PARM_ADD_IP) || 7030Sstevel@tonic-gate oph->sph_type == htons(PARM_DEL_IP)) { 7040Sstevel@tonic-gate redosrcs = 1; 705852Svi117747 /* 706852Svi117747 * If the address was sucessfully 707852Svi117747 * processed, add it to the add/delete 708852Svi117747 * list to send to the clustering 709852Svi117747 * module. 710852Svi117747 */ 711852Svi117747 if (cl_sctp_assoc_change != NULL && 712852Svi117747 !IN6_IS_ADDR_UNSPECIFIED(&addr)) { 713852Svi117747 if (oph->sph_type == 714852Svi117747 htons(PARM_ADD_IP)) { 715852Svi117747 bcopy(&addr, aptr, 716852Svi117747 sizeof (addr)); 717852Svi117747 aptr += sizeof (addr); 718852Svi117747 acount++; 719852Svi117747 } else { 720852Svi117747 bcopy(&addr, dptr, 721852Svi117747 sizeof (addr)); 722852Svi117747 dptr += sizeof (addr); 723852Svi117747 dcount++; 724852Svi117747 } 725852Svi117747 } 7260Sstevel@tonic-gate } 7270Sstevel@tonic-gate } 7280Sstevel@tonic-gate } 7290Sstevel@tonic-gate 7300Sstevel@tonic-gate ph = sctp_next_parm(ph, &rlen); 7310Sstevel@tonic-gate if (ph == NULL) 7320Sstevel@tonic-gate break; 7330Sstevel@tonic-gate } 7340Sstevel@tonic-gate 7350Sstevel@tonic-gate /* 7360Sstevel@tonic-gate * Pass implicit replies to callbacks: 7370Sstevel@tonic-gate * For each original request, look up its parameter 7380Sstevel@tonic-gate * in the ACK. If there is no corresponding reply, 7390Sstevel@tonic-gate * call the callback with a NULL parameter, indicating 7400Sstevel@tonic-gate * success. 7410Sstevel@tonic-gate */ 7420Sstevel@tonic-gate rlen = plen; 7430Sstevel@tonic-gate plen = ntohs(ch->sch_len) - sizeof (*ch) - sizeof (*idp); 7440Sstevel@tonic-gate oph = fph; 7450Sstevel@tonic-gate fph = (sctp_parm_hdr_t *)((char *)ch + sizeof (sctp_chunk_hdr_t) + 7460Sstevel@tonic-gate sizeof (uint32_t)); 7470Sstevel@tonic-gate while (rlen > 0) { 7480Sstevel@tonic-gate idp = (uint32_t *)(oph + 1); 7490Sstevel@tonic-gate ph = sctp_lookup_asconf_param(fph, *idp, plen); 7500Sstevel@tonic-gate if (ph == NULL) { 7510Sstevel@tonic-gate dp = sctp_lookup_asconf_dispatch(ntohs(oph->sph_type)); 7520Sstevel@tonic-gate ASSERT(dp); 7530Sstevel@tonic-gate if (dp->asconf_ack) { 754852Svi117747 dp->asconf_ack(sctp, NULL, oph, fp, &addr); 7550Sstevel@tonic-gate 7560Sstevel@tonic-gate /* hack. see below */ 7570Sstevel@tonic-gate if (oph->sph_type == htons(PARM_ADD_IP) || 7580Sstevel@tonic-gate oph->sph_type == htons(PARM_DEL_IP)) { 7590Sstevel@tonic-gate redosrcs = 1; 760852Svi117747 /* 761852Svi117747 * If the address was sucessfully 762852Svi117747 * processed, add it to the add/delete 763852Svi117747 * list to send to the clustering 764852Svi117747 * module. 765852Svi117747 */ 766852Svi117747 if (cl_sctp_assoc_change != NULL && 767852Svi117747 !IN6_IS_ADDR_UNSPECIFIED(&addr)) { 768852Svi117747 if (oph->sph_type == 769852Svi117747 htons(PARM_ADD_IP)) { 770852Svi117747 bcopy(&addr, aptr, 771852Svi117747 sizeof (addr)); 772852Svi117747 aptr += sizeof (addr); 773852Svi117747 acount++; 774852Svi117747 } else { 775852Svi117747 bcopy(&addr, dptr, 776852Svi117747 sizeof (addr)); 777852Svi117747 dptr += sizeof (addr); 778852Svi117747 dcount++; 779852Svi117747 } 780852Svi117747 } 7810Sstevel@tonic-gate } 7820Sstevel@tonic-gate } 7830Sstevel@tonic-gate } 7840Sstevel@tonic-gate oph = sctp_next_parm(oph, &rlen); 7850Sstevel@tonic-gate if (oph == NULL) { 7860Sstevel@tonic-gate break; 7870Sstevel@tonic-gate } 7880Sstevel@tonic-gate } 7890Sstevel@tonic-gate 7900Sstevel@tonic-gate /* We can now free up the first chunk in the cxmit list */ 7910Sstevel@tonic-gate sctp->sctp_cxmit_list = mp->b_cont; 7920Sstevel@tonic-gate mp->b_cont = NULL; 7930Sstevel@tonic-gate 7940Sstevel@tonic-gate fp = SCTP_CHUNK_DEST(mp); 7950Sstevel@tonic-gate ASSERT(fp != NULL && fp->suna >= MBLKL(mp)); 7960Sstevel@tonic-gate fp->suna -= MBLKL(mp); 797852Svi117747 798852Svi117747 /* 799852Svi117747 * Update clustering's state for this assoc. Note acount/dcount 800852Svi117747 * could be zero (i.e. if the add/delete address(es) did not 801852Svi117747 * succeed). Regardless, if the ?size is > 0, it is the clustering 802852Svi117747 * module's responsibility to free the lists. 803852Svi117747 */ 804852Svi117747 if (cl_sctp_assoc_change != NULL) { 805852Svi117747 ASSERT(mp->b_prev != NULL); 806852Svi117747 mp->b_prev = NULL; 807852Svi117747 ainfo->sctp_cl_alist = NULL; 808852Svi117747 ainfo->sctp_cl_dlist = NULL; 809852Svi117747 (*cl_sctp_assoc_change)(sctp->sctp_family, alist, 810852Svi117747 ainfo->sctp_cl_asize, acount, dlist, ainfo->sctp_cl_dsize, 811852Svi117747 dcount, SCTP_CL_LADDR, (cl_sctp_handle_t)sctp); 812852Svi117747 /* alist and dlist will be freed by the clustering module */ 813852Svi117747 ainfo->sctp_cl_asize = 0; 814852Svi117747 ainfo->sctp_cl_dsize = 0; 815852Svi117747 kmem_free(ainfo, sizeof (*ainfo)); 816852Svi117747 } 8170Sstevel@tonic-gate freeb(mp); 8180Sstevel@tonic-gate 8190Sstevel@tonic-gate /* can now send the next control chunk */ 8200Sstevel@tonic-gate if (sctp->sctp_cxmit_list != NULL) 8210Sstevel@tonic-gate sctp_wput_asconf(sctp, NULL); 8220Sstevel@tonic-gate 8230Sstevel@tonic-gate /* 8240Sstevel@tonic-gate * If an add-ip or del-ip has completed (successfully or 8250Sstevel@tonic-gate * unsuccessfully), the pool of available source addresses 8260Sstevel@tonic-gate * may have changed, so we need to redo faddr source 8270Sstevel@tonic-gate * address selections. This is a bit of a hack since 8280Sstevel@tonic-gate * this really belongs in the add/del-ip code. However, 8290Sstevel@tonic-gate * that code consists of callbacks called for *each* 8300Sstevel@tonic-gate * add/del-ip parameter, and sctp_redo_faddr_srcs() is 8310Sstevel@tonic-gate * expensive enough that we really don't want to be 8320Sstevel@tonic-gate * doing it for each one. So we do it once here. 8330Sstevel@tonic-gate */ 8340Sstevel@tonic-gate if (redosrcs) 8350Sstevel@tonic-gate sctp_redo_faddr_srcs(sctp); 8360Sstevel@tonic-gate } 8370Sstevel@tonic-gate 8380Sstevel@tonic-gate static void 8390Sstevel@tonic-gate sctp_rc_timer(sctp_t *sctp, sctp_faddr_t *fp) 8400Sstevel@tonic-gate { 8410Sstevel@tonic-gate #define SCTP_CLR_SENT_FLAG(mp) ((mp)->b_flag &= ~SCTP_CHUNK_FLAG_SENT) 8420Sstevel@tonic-gate sctp_faddr_t *nfp; 8430Sstevel@tonic-gate sctp_faddr_t *ofp; 8443448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 8450Sstevel@tonic-gate 8460Sstevel@tonic-gate ASSERT(fp != NULL); 8470Sstevel@tonic-gate 8480Sstevel@tonic-gate fp->rc_timer_running = 0; 8490Sstevel@tonic-gate 8500Sstevel@tonic-gate if (sctp->sctp_state != SCTPS_ESTABLISHED || 8510Sstevel@tonic-gate sctp->sctp_cxmit_list == NULL) { 8520Sstevel@tonic-gate return; 8530Sstevel@tonic-gate } 8540Sstevel@tonic-gate /* 8550Sstevel@tonic-gate * Not a retransmission, this was deferred due to some error 8560Sstevel@tonic-gate * condition 8570Sstevel@tonic-gate */ 8580Sstevel@tonic-gate if (!SCTP_CHUNK_ISSENT(sctp->sctp_cxmit_list)) { 8590Sstevel@tonic-gate sctp_wput_asconf(sctp, fp); 8600Sstevel@tonic-gate return; 8610Sstevel@tonic-gate } 8620Sstevel@tonic-gate /* 8630Sstevel@tonic-gate * The sent flag indicates if the msg has been sent on this fp. 8640Sstevel@tonic-gate */ 8650Sstevel@tonic-gate SCTP_CLR_SENT_FLAG(sctp->sctp_cxmit_list); 8660Sstevel@tonic-gate /* Retransmission */ 8670Sstevel@tonic-gate if (sctp->sctp_strikes >= sctp->sctp_pa_max_rxt) { 8680Sstevel@tonic-gate /* time to give up */ 8693448Sdh155122 BUMP_MIB(&sctps->sctps_mib, sctpAborted); 8700Sstevel@tonic-gate sctp_assoc_event(sctp, SCTP_COMM_LOST, 0, NULL); 8710Sstevel@tonic-gate sctp_clean_death(sctp, ETIMEDOUT); 8720Sstevel@tonic-gate return; 8730Sstevel@tonic-gate } 8740Sstevel@tonic-gate if (fp->strikes >= fp->max_retr) { 8750Sstevel@tonic-gate if (sctp_faddr_dead(sctp, fp, SCTP_FADDRS_DOWN) == -1) 8760Sstevel@tonic-gate return; 8770Sstevel@tonic-gate } 8780Sstevel@tonic-gate 8790Sstevel@tonic-gate fp->strikes++; 8800Sstevel@tonic-gate sctp->sctp_strikes++; 8810Sstevel@tonic-gate SCTP_CALC_RXT(fp, sctp->sctp_rto_max); 8820Sstevel@tonic-gate 8830Sstevel@tonic-gate nfp = sctp_rotate_faddr(sctp, fp); 8840Sstevel@tonic-gate sctp->sctp_cchunk_pend = 0; 8850Sstevel@tonic-gate ofp = SCTP_CHUNK_DEST(sctp->sctp_cxmit_list); 8860Sstevel@tonic-gate SCTP_SET_CHUNK_DEST(sctp->sctp_cxmit_list, NULL); 8870Sstevel@tonic-gate ASSERT(ofp != NULL && ofp == fp); 8880Sstevel@tonic-gate ASSERT(ofp->suna >= MBLKL(sctp->sctp_cxmit_list)); 8890Sstevel@tonic-gate /* 8900Sstevel@tonic-gate * Enter slow start for this destination. 8910Sstevel@tonic-gate * XXX anything in the data path that needs to be considered? 8920Sstevel@tonic-gate */ 8930Sstevel@tonic-gate ofp->ssthresh = ofp->cwnd / 2; 8940Sstevel@tonic-gate if (ofp->ssthresh < 2 * ofp->sfa_pmss) 8950Sstevel@tonic-gate ofp->ssthresh = 2 * ofp->sfa_pmss; 8960Sstevel@tonic-gate ofp->cwnd = ofp->sfa_pmss; 8970Sstevel@tonic-gate ofp->pba = 0; 8980Sstevel@tonic-gate ofp->suna -= MBLKL(sctp->sctp_cxmit_list); 8990Sstevel@tonic-gate /* 9000Sstevel@tonic-gate * The rexmit flags is used to determine if a serial number needs to 9010Sstevel@tonic-gate * be assigned or not, so once set we leave it there. 9020Sstevel@tonic-gate */ 9030Sstevel@tonic-gate if (!SCTP_CHUNK_WANT_REXMIT(sctp->sctp_cxmit_list)) 9040Sstevel@tonic-gate SCTP_CHUNK_REXMIT(sctp->sctp_cxmit_list); 9050Sstevel@tonic-gate sctp_wput_asconf(sctp, nfp); 9060Sstevel@tonic-gate #undef SCTP_CLR_SENT_FLAG 9070Sstevel@tonic-gate } 9080Sstevel@tonic-gate 9090Sstevel@tonic-gate void 9100Sstevel@tonic-gate sctp_wput_asconf(sctp_t *sctp, sctp_faddr_t *fp) 9110Sstevel@tonic-gate { 9120Sstevel@tonic-gate #define SCTP_SET_SENT_FLAG(mp) ((mp)->b_flag = SCTP_CHUNK_FLAG_SENT) 9130Sstevel@tonic-gate 9140Sstevel@tonic-gate mblk_t *mp; 9150Sstevel@tonic-gate mblk_t *ipmp; 9160Sstevel@tonic-gate uint32_t *snp; 9170Sstevel@tonic-gate sctp_parm_hdr_t *ph; 9180Sstevel@tonic-gate boolean_t isv4; 9193448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 920*4818Skcpoon boolean_t saddr_set; 9210Sstevel@tonic-gate 9220Sstevel@tonic-gate if (sctp->sctp_cchunk_pend || sctp->sctp_cxmit_list == NULL || 9230Sstevel@tonic-gate /* Queue it for later transmission if not yet established */ 9240Sstevel@tonic-gate sctp->sctp_state < SCTPS_ESTABLISHED) { 9250Sstevel@tonic-gate ip2dbg(("sctp_wput_asconf: cchunk pending? (%d) or null "\ 9260Sstevel@tonic-gate "sctp_cxmit_list? (%s) or incorrect state? (%x)\n", 9270Sstevel@tonic-gate sctp->sctp_cchunk_pend, sctp->sctp_cxmit_list == NULL ? 9280Sstevel@tonic-gate "yes" : "no", sctp->sctp_state)); 9290Sstevel@tonic-gate return; 9300Sstevel@tonic-gate } 9310Sstevel@tonic-gate 9320Sstevel@tonic-gate if (fp == NULL) 9330Sstevel@tonic-gate fp = sctp->sctp_current; 9340Sstevel@tonic-gate 9350Sstevel@tonic-gate /* OK to send */ 9360Sstevel@tonic-gate ipmp = sctp_make_mp(sctp, fp, 0); 9370Sstevel@tonic-gate if (ipmp == NULL) { 9380Sstevel@tonic-gate SCTP_FADDR_RC_TIMER_RESTART(sctp, fp, fp->rto); 9393448Sdh155122 SCTP_KSTAT(sctps, sctp_send_asconf_failed); 9400Sstevel@tonic-gate return; 9410Sstevel@tonic-gate } 9420Sstevel@tonic-gate mp = sctp->sctp_cxmit_list; 9430Sstevel@tonic-gate /* Fill in the mandatory Address Parameter TLV */ 9440Sstevel@tonic-gate isv4 = (fp != NULL) ? fp->isv4 : sctp->sctp_current->isv4; 9450Sstevel@tonic-gate ph = (sctp_parm_hdr_t *)(mp->b_rptr + sizeof (sctp_chunk_hdr_t) + 9460Sstevel@tonic-gate sizeof (uint32_t)); 9470Sstevel@tonic-gate if (isv4) { 9480Sstevel@tonic-gate ipha_t *ipha = (ipha_t *)ipmp->b_rptr; 9490Sstevel@tonic-gate in6_addr_t ipaddr; 9500Sstevel@tonic-gate ipaddr_t addr4; 9510Sstevel@tonic-gate 9520Sstevel@tonic-gate ph->sph_type = htons(PARM_ADDR4); 9530Sstevel@tonic-gate ph->sph_len = htons(PARM_ADDR4_LEN); 9540Sstevel@tonic-gate if (ipha->ipha_src != INADDR_ANY) { 9550Sstevel@tonic-gate bcopy(&ipha->ipha_src, ph + 1, IP_ADDR_LEN); 9560Sstevel@tonic-gate } else { 957*4818Skcpoon ipaddr = sctp_get_valid_addr(sctp, B_FALSE, &saddr_set); 958252Svi117747 /* 959252Svi117747 * All the addresses are down. 960252Svi117747 * Maybe we might have better luck next time. 961252Svi117747 */ 962*4818Skcpoon if (!saddr_set) { 963252Svi117747 SCTP_FADDR_RC_TIMER_RESTART(sctp, fp, fp->rto); 964252Svi117747 freeb(ipmp); 965252Svi117747 return; 966252Svi117747 } 9670Sstevel@tonic-gate IN6_V4MAPPED_TO_IPADDR(&ipaddr, addr4); 9680Sstevel@tonic-gate bcopy(&addr4, ph + 1, IP_ADDR_LEN); 9690Sstevel@tonic-gate } 9700Sstevel@tonic-gate } else { 9710Sstevel@tonic-gate ip6_t *ip6 = (ip6_t *)ipmp->b_rptr; 9720Sstevel@tonic-gate in6_addr_t ipaddr; 9730Sstevel@tonic-gate 9740Sstevel@tonic-gate ph->sph_type = htons(PARM_ADDR6); 9750Sstevel@tonic-gate ph->sph_len = htons(PARM_ADDR6_LEN); 9760Sstevel@tonic-gate if (!IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_src)) { 9770Sstevel@tonic-gate bcopy(&ip6->ip6_src, ph + 1, IPV6_ADDR_LEN); 9780Sstevel@tonic-gate } else { 979*4818Skcpoon ipaddr = sctp_get_valid_addr(sctp, B_TRUE, &saddr_set); 980252Svi117747 /* 981252Svi117747 * All the addresses are down. 982252Svi117747 * Maybe we might have better luck next time. 983252Svi117747 */ 984*4818Skcpoon if (!saddr_set) { 985252Svi117747 SCTP_FADDR_RC_TIMER_RESTART(sctp, fp, fp->rto); 986252Svi117747 freeb(ipmp); 987252Svi117747 return; 988252Svi117747 } 9890Sstevel@tonic-gate bcopy(&ipaddr, ph + 1, IPV6_ADDR_LEN); 9900Sstevel@tonic-gate } 9910Sstevel@tonic-gate } 9920Sstevel@tonic-gate 9930Sstevel@tonic-gate /* Don't exceed CWND */ 9940Sstevel@tonic-gate if ((MBLKL(mp) > (fp->cwnd - fp->suna)) || 9950Sstevel@tonic-gate ((mp = dupb(sctp->sctp_cxmit_list)) == NULL)) { 9960Sstevel@tonic-gate SCTP_FADDR_RC_TIMER_RESTART(sctp, fp, fp->rto); 9970Sstevel@tonic-gate freeb(ipmp); 9980Sstevel@tonic-gate return; 9990Sstevel@tonic-gate } 10000Sstevel@tonic-gate 10010Sstevel@tonic-gate /* Set the serial number now, if sending for the first time */ 10020Sstevel@tonic-gate if (!SCTP_CHUNK_WANT_REXMIT(mp)) { 10030Sstevel@tonic-gate snp = (uint32_t *)(mp->b_rptr + sizeof (sctp_chunk_hdr_t)); 10040Sstevel@tonic-gate *snp = htonl(sctp->sctp_lcsn++); 10050Sstevel@tonic-gate } 10060Sstevel@tonic-gate SCTP_CHUNK_CLEAR_FLAGS(mp); 10070Sstevel@tonic-gate fp->suna += MBLKL(mp); 10080Sstevel@tonic-gate /* Attach the header and send the chunk */ 10090Sstevel@tonic-gate ipmp->b_cont = mp; 10100Sstevel@tonic-gate sctp_set_iplen(sctp, ipmp); 10110Sstevel@tonic-gate sctp->sctp_cchunk_pend = 1; 10120Sstevel@tonic-gate 10130Sstevel@tonic-gate SCTP_SET_SENT_FLAG(sctp->sctp_cxmit_list); 10140Sstevel@tonic-gate SCTP_SET_CHUNK_DEST(sctp->sctp_cxmit_list, fp); 10150Sstevel@tonic-gate sctp_add_sendq(sctp, ipmp); 10160Sstevel@tonic-gate SCTP_FADDR_RC_TIMER_RESTART(sctp, fp, fp->rto); 10170Sstevel@tonic-gate #undef SCTP_SET_SENT_FLAG 10180Sstevel@tonic-gate } 10190Sstevel@tonic-gate 10200Sstevel@tonic-gate /* 10210Sstevel@tonic-gate * Generate ASCONF error param, include errph, if present. 10220Sstevel@tonic-gate */ 10230Sstevel@tonic-gate static mblk_t * 10240Sstevel@tonic-gate sctp_asconf_adderr(int err, sctp_parm_hdr_t *errph, uint32_t cid) 10250Sstevel@tonic-gate { 10260Sstevel@tonic-gate mblk_t *mp; 10270Sstevel@tonic-gate sctp_parm_hdr_t *eph; 10280Sstevel@tonic-gate sctp_parm_hdr_t *wph; 10290Sstevel@tonic-gate size_t len; 10300Sstevel@tonic-gate size_t elen = 0; 10310Sstevel@tonic-gate 10320Sstevel@tonic-gate len = sizeof (*wph) + sizeof (*eph) + sizeof (cid); 10330Sstevel@tonic-gate if (errph != NULL) { 10340Sstevel@tonic-gate elen = ntohs(errph->sph_len); 10350Sstevel@tonic-gate len += elen; 10360Sstevel@tonic-gate } 10370Sstevel@tonic-gate mp = allocb(len, BPRI_MED); 10380Sstevel@tonic-gate if (mp == NULL) { 10390Sstevel@tonic-gate return (NULL); 10400Sstevel@tonic-gate } 10410Sstevel@tonic-gate wph = (sctp_parm_hdr_t *)mp->b_rptr; 10420Sstevel@tonic-gate /* error cause wrapper */ 10430Sstevel@tonic-gate wph->sph_type = htons(PARM_ERROR_IND); 10440Sstevel@tonic-gate wph->sph_len = htons(len); 10450Sstevel@tonic-gate bcopy(&cid, wph + 1, sizeof (uint32_t)); 10460Sstevel@tonic-gate 10470Sstevel@tonic-gate /* error cause */ 10480Sstevel@tonic-gate eph = (sctp_parm_hdr_t *)((char *)wph + sizeof (sctp_parm_hdr_t) + 10490Sstevel@tonic-gate sizeof (cid)); 10500Sstevel@tonic-gate eph->sph_type = htons(err); 10510Sstevel@tonic-gate eph->sph_len = htons(len - sizeof (*wph) - sizeof (cid)); 10520Sstevel@tonic-gate mp->b_wptr = (uchar_t *)(eph + 1); 10530Sstevel@tonic-gate 10540Sstevel@tonic-gate /* details */ 10550Sstevel@tonic-gate if (elen > 0) { 10560Sstevel@tonic-gate bcopy(errph, mp->b_wptr, elen); 10570Sstevel@tonic-gate mp->b_wptr += elen; 10580Sstevel@tonic-gate } 10590Sstevel@tonic-gate return (mp); 10600Sstevel@tonic-gate } 10610Sstevel@tonic-gate 10620Sstevel@tonic-gate static mblk_t * 10630Sstevel@tonic-gate sctp_check_addip_addr(sctp_parm_hdr_t *ph, sctp_parm_hdr_t *oph, int *cont, 10640Sstevel@tonic-gate uint32_t cid, in6_addr_t *raddr) 10650Sstevel@tonic-gate { 10660Sstevel@tonic-gate uint16_t atype; 10670Sstevel@tonic-gate uint16_t alen; 10680Sstevel@tonic-gate mblk_t *mp; 10690Sstevel@tonic-gate in6_addr_t addr; 10700Sstevel@tonic-gate ipaddr_t *addr4; 10710Sstevel@tonic-gate 10720Sstevel@tonic-gate atype = ntohs(ph->sph_type); 10730Sstevel@tonic-gate alen = ntohs(ph->sph_len); 10740Sstevel@tonic-gate 10750Sstevel@tonic-gate if (atype != PARM_ADDR4 && atype != PARM_ADDR6) { 10760Sstevel@tonic-gate mp = sctp_asconf_adderr(SCTP_ERR_BAD_MANDPARM, oph, cid); 10770Sstevel@tonic-gate if (mp == NULL) { 10780Sstevel@tonic-gate *cont = -1; 10790Sstevel@tonic-gate } 10800Sstevel@tonic-gate return (mp); 10810Sstevel@tonic-gate } 10820Sstevel@tonic-gate if ((atype == PARM_ADDR4 && alen < PARM_ADDR4_LEN) || 10830Sstevel@tonic-gate (atype == PARM_ADDR6 && alen < PARM_ADDR6_LEN)) { 10840Sstevel@tonic-gate mp = sctp_asconf_adderr(SCTP_ERR_BAD_MANDPARM, oph, cid); 10850Sstevel@tonic-gate if (mp == NULL) { 10860Sstevel@tonic-gate *cont = -1; 10870Sstevel@tonic-gate } 10880Sstevel@tonic-gate return (mp); 10890Sstevel@tonic-gate } 10900Sstevel@tonic-gate 10910Sstevel@tonic-gate /* Address parameter is present; extract and screen it */ 10920Sstevel@tonic-gate if (atype == PARM_ADDR4) { 10930Sstevel@tonic-gate addr4 = (ipaddr_t *)(ph + 1); 10940Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(*addr4, &addr); 10950Sstevel@tonic-gate 10960Sstevel@tonic-gate /* screen XXX loopback to scoping */ 10970Sstevel@tonic-gate if (*addr4 == 0 || *addr4 == INADDR_BROADCAST || 10980Sstevel@tonic-gate *addr4 == htonl(INADDR_LOOPBACK) || IN_MULTICAST(*addr4)) { 10990Sstevel@tonic-gate dprint(1, ("addip: addr not unicast: %x:%x:%x:%x\n", 11000Sstevel@tonic-gate SCTP_PRINTADDR(addr))); 11010Sstevel@tonic-gate mp = sctp_asconf_adderr(SCTP_ERR_BAD_MANDPARM, oph, 11020Sstevel@tonic-gate cid); 11030Sstevel@tonic-gate if (mp == NULL) { 11040Sstevel@tonic-gate *cont = -1; 11050Sstevel@tonic-gate } 11060Sstevel@tonic-gate return (mp); 11070Sstevel@tonic-gate } 11080Sstevel@tonic-gate /* 11090Sstevel@tonic-gate * XXX also need to check for subnet 11100Sstevel@tonic-gate * broadcasts. This should probably 11110Sstevel@tonic-gate * wait until we have full access 11120Sstevel@tonic-gate * to the ILL tables. 11130Sstevel@tonic-gate */ 11140Sstevel@tonic-gate 11150Sstevel@tonic-gate } else { 11160Sstevel@tonic-gate bcopy(ph + 1, &addr, sizeof (addr)); 11170Sstevel@tonic-gate 11180Sstevel@tonic-gate /* screen XXX loopback to scoping */ 11190Sstevel@tonic-gate if (IN6_IS_ADDR_LINKLOCAL(&addr) || 11200Sstevel@tonic-gate IN6_IS_ADDR_MULTICAST(&addr) || 11210Sstevel@tonic-gate IN6_IS_ADDR_LOOPBACK(&addr)) { 11220Sstevel@tonic-gate dprint(1, ("addip: addr not unicast: %x:%x:%x:%x\n", 11230Sstevel@tonic-gate SCTP_PRINTADDR(addr))); 11240Sstevel@tonic-gate mp = sctp_asconf_adderr(SCTP_ERR_BAD_MANDPARM, oph, 11250Sstevel@tonic-gate cid); 11260Sstevel@tonic-gate if (mp == NULL) { 11270Sstevel@tonic-gate *cont = -1; 11280Sstevel@tonic-gate } 11290Sstevel@tonic-gate return (mp); 11300Sstevel@tonic-gate } 11310Sstevel@tonic-gate 11320Sstevel@tonic-gate } 11330Sstevel@tonic-gate 11340Sstevel@tonic-gate /* OK */ 11350Sstevel@tonic-gate *raddr = addr; 11360Sstevel@tonic-gate return (NULL); 11370Sstevel@tonic-gate } 11380Sstevel@tonic-gate 11390Sstevel@tonic-gate /* 11400Sstevel@tonic-gate * Handles both add and delete address requests. 11410Sstevel@tonic-gate */ 11420Sstevel@tonic-gate static mblk_t * 11430Sstevel@tonic-gate sctp_addip_req(sctp_t *sctp, sctp_parm_hdr_t *ph, uint32_t cid, 1144852Svi117747 sctp_faddr_t *fp, int *cont, int act, in6_addr_t *raddr) 11450Sstevel@tonic-gate { 11460Sstevel@tonic-gate in6_addr_t addr; 11470Sstevel@tonic-gate uint16_t type; 11480Sstevel@tonic-gate mblk_t *mp; 11490Sstevel@tonic-gate sctp_faddr_t *nfp; 11501676Sjpk sctp_parm_hdr_t *oph = ph; 11511676Sjpk int err; 11523448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 11530Sstevel@tonic-gate 11540Sstevel@tonic-gate *cont = 1; 11550Sstevel@tonic-gate 11560Sstevel@tonic-gate /* Send back an authorization error if addip is disabled */ 11573448Sdh155122 if (!sctps->sctps_addip_enabled) { 11581676Sjpk err = SCTP_ERR_UNAUTHORIZED; 11591676Sjpk goto error_handler; 11600Sstevel@tonic-gate } 11610Sstevel@tonic-gate /* Check input */ 11620Sstevel@tonic-gate if (ntohs(ph->sph_len) < (sizeof (*ph) * 2)) { 11631676Sjpk err = SCTP_ERR_BAD_MANDPARM; 11641676Sjpk goto error_handler; 11650Sstevel@tonic-gate } 11660Sstevel@tonic-gate 11670Sstevel@tonic-gate type = ntohs(ph->sph_type); 11680Sstevel@tonic-gate ph = (sctp_parm_hdr_t *)((char *)ph + sizeof (sctp_parm_hdr_t) + 11690Sstevel@tonic-gate sizeof (cid)); 11700Sstevel@tonic-gate mp = sctp_check_addip_addr(ph, oph, cont, cid, &addr); 11710Sstevel@tonic-gate if (mp != NULL) 11720Sstevel@tonic-gate return (mp); 1173852Svi117747 if (raddr != NULL) 1174852Svi117747 *raddr = addr; 11750Sstevel@tonic-gate if (type == PARM_ADD_IP) { 11760Sstevel@tonic-gate if (sctp_lookup_faddr(sctp, &addr) != NULL) { 11770Sstevel@tonic-gate /* Address is already part of association */ 11780Sstevel@tonic-gate dprint(1, ("addip: addr already here: %x:%x:%x:%x\n", 11790Sstevel@tonic-gate SCTP_PRINTADDR(addr))); 11801676Sjpk err = SCTP_ERR_BAD_MANDPARM; 11811676Sjpk goto error_handler; 11820Sstevel@tonic-gate } 11830Sstevel@tonic-gate 11840Sstevel@tonic-gate if (!act) { 11850Sstevel@tonic-gate return (NULL); 11860Sstevel@tonic-gate } 11870Sstevel@tonic-gate /* Add the new address */ 11880Sstevel@tonic-gate mutex_enter(&sctp->sctp_conn_tfp->tf_lock); 11891735Skcpoon err = sctp_add_faddr(sctp, &addr, KM_NOSLEEP, B_FALSE); 11901676Sjpk mutex_exit(&sctp->sctp_conn_tfp->tf_lock); 11911676Sjpk if (err == ENOMEM) { 11920Sstevel@tonic-gate /* no memory */ 11930Sstevel@tonic-gate *cont = -1; 11940Sstevel@tonic-gate return (NULL); 11950Sstevel@tonic-gate } 11961676Sjpk if (err != 0) { 11971676Sjpk err = SCTP_ERR_BAD_MANDPARM; 11981676Sjpk goto error_handler; 11991676Sjpk } 12000Sstevel@tonic-gate sctp_intf_event(sctp, addr, SCTP_ADDR_ADDED, 0); 12010Sstevel@tonic-gate } else if (type == PARM_DEL_IP) { 12020Sstevel@tonic-gate nfp = sctp_lookup_faddr(sctp, &addr); 12030Sstevel@tonic-gate if (nfp == NULL) { 12040Sstevel@tonic-gate /* 12050Sstevel@tonic-gate * Peer is trying to delete an address that is not 12060Sstevel@tonic-gate * part of the association. 12070Sstevel@tonic-gate */ 12080Sstevel@tonic-gate dprint(1, ("delip: addr not here: %x:%x:%x:%x\n", 12090Sstevel@tonic-gate SCTP_PRINTADDR(addr))); 12101676Sjpk err = SCTP_ERR_BAD_MANDPARM; 12111676Sjpk goto error_handler; 12120Sstevel@tonic-gate } 12130Sstevel@tonic-gate if (sctp->sctp_faddrs == nfp && nfp->next == NULL) { 12140Sstevel@tonic-gate /* Peer is trying to delete last address */ 12150Sstevel@tonic-gate dprint(1, ("delip: del last addr: %x:%x:%x:%x\n", 12160Sstevel@tonic-gate SCTP_PRINTADDR(addr))); 12171676Sjpk err = SCTP_ERR_DEL_LAST_ADDR; 12181676Sjpk goto error_handler; 12190Sstevel@tonic-gate } 12200Sstevel@tonic-gate if (nfp == fp) { 12210Sstevel@tonic-gate /* Peer is trying to delete source address */ 12220Sstevel@tonic-gate dprint(1, ("delip: del src addr: %x:%x:%x:%x\n", 12230Sstevel@tonic-gate SCTP_PRINTADDR(addr))); 12241676Sjpk err = SCTP_ERR_DEL_SRC_ADDR; 12251676Sjpk goto error_handler; 12260Sstevel@tonic-gate } 12270Sstevel@tonic-gate if (!act) { 12280Sstevel@tonic-gate return (NULL); 12290Sstevel@tonic-gate } 12300Sstevel@tonic-gate 12310Sstevel@tonic-gate sctp_unlink_faddr(sctp, nfp); 12320Sstevel@tonic-gate /* Update all references to the deleted faddr */ 12330Sstevel@tonic-gate if (sctp->sctp_primary == nfp) { 12340Sstevel@tonic-gate sctp->sctp_primary = fp; 12350Sstevel@tonic-gate } 12360Sstevel@tonic-gate if (sctp->sctp_current == nfp) { 12371735Skcpoon sctp_set_faddr_current(sctp, fp); 12380Sstevel@tonic-gate } 12390Sstevel@tonic-gate if (sctp->sctp_lastdata == nfp) { 12400Sstevel@tonic-gate sctp->sctp_lastdata = fp; 12410Sstevel@tonic-gate } 12420Sstevel@tonic-gate if (sctp->sctp_shutdown_faddr == nfp) { 12430Sstevel@tonic-gate sctp->sctp_shutdown_faddr = nfp; 12440Sstevel@tonic-gate } 12450Sstevel@tonic-gate if (sctp->sctp_lastfaddr == nfp) { 12460Sstevel@tonic-gate for (fp = sctp->sctp_faddrs; fp->next; fp = fp->next) 12470Sstevel@tonic-gate ; 12480Sstevel@tonic-gate sctp->sctp_lastfaddr = fp; 12490Sstevel@tonic-gate } 12500Sstevel@tonic-gate sctp_intf_event(sctp, addr, SCTP_ADDR_REMOVED, 0); 12510Sstevel@tonic-gate } else { 12520Sstevel@tonic-gate ASSERT(0); 12530Sstevel@tonic-gate } 12540Sstevel@tonic-gate 12550Sstevel@tonic-gate /* Successful, don't need to return anything. */ 12560Sstevel@tonic-gate return (NULL); 12571676Sjpk 12581676Sjpk error_handler: 12591676Sjpk mp = sctp_asconf_adderr(err, oph, cid); 12601676Sjpk if (mp == NULL) 12611676Sjpk *cont = -1; 12621676Sjpk return (mp); 12630Sstevel@tonic-gate } 12640Sstevel@tonic-gate 12650Sstevel@tonic-gate /* 12660Sstevel@tonic-gate * Handles both add and delete IP ACKs. 12670Sstevel@tonic-gate */ 12680Sstevel@tonic-gate /*ARGSUSED*/ 12690Sstevel@tonic-gate static void 12700Sstevel@tonic-gate sctp_addip_ack(sctp_t *sctp, sctp_parm_hdr_t *ph, sctp_parm_hdr_t *oph, 1271852Svi117747 sctp_faddr_t *fp, in6_addr_t *laddr) 12720Sstevel@tonic-gate { 12730Sstevel@tonic-gate in6_addr_t addr; 12740Sstevel@tonic-gate sctp_saddr_ipif_t *sp; 12750Sstevel@tonic-gate ipaddr_t *addr4; 12760Sstevel@tonic-gate boolean_t backout = B_FALSE; 12770Sstevel@tonic-gate uint16_t type; 12780Sstevel@tonic-gate uint32_t *cid; 12790Sstevel@tonic-gate 1280852Svi117747 /* could be an ASSERT */ 1281852Svi117747 if (laddr != NULL) 1282852Svi117747 IN6_IPADDR_TO_V4MAPPED(0, laddr); 1283852Svi117747 12840Sstevel@tonic-gate /* If the peer doesn't understand Add-IP, remember it */ 12850Sstevel@tonic-gate if (ph != NULL && ph->sph_type == htons(PARM_UNRECOGNIZED)) { 12860Sstevel@tonic-gate sctp->sctp_understands_addip = B_FALSE; 12870Sstevel@tonic-gate backout = B_TRUE; 12880Sstevel@tonic-gate } 12890Sstevel@tonic-gate 12900Sstevel@tonic-gate /* 12910Sstevel@tonic-gate * If OK, continue with the add / delete action, otherwise 12920Sstevel@tonic-gate * back out the action. 12930Sstevel@tonic-gate */ 12940Sstevel@tonic-gate if (ph != NULL && ph->sph_type != htons(PARM_SUCCESS)) { 12950Sstevel@tonic-gate backout = B_TRUE; 12960Sstevel@tonic-gate sctp_error_event(sctp, (sctp_chunk_hdr_t *)ph); 12970Sstevel@tonic-gate } 12980Sstevel@tonic-gate 12990Sstevel@tonic-gate type = ntohs(oph->sph_type); 13000Sstevel@tonic-gate cid = (uint32_t *)(oph + 1); 13010Sstevel@tonic-gate oph = (sctp_parm_hdr_t *)(cid + 1); 13020Sstevel@tonic-gate if (oph->sph_type == htons(PARM_ADDR4)) { 13030Sstevel@tonic-gate addr4 = (ipaddr_t *)(oph + 1); 13040Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(*addr4, &addr); 13050Sstevel@tonic-gate } else { 13060Sstevel@tonic-gate bcopy(oph + 1, &addr, sizeof (addr)); 13070Sstevel@tonic-gate } 13080Sstevel@tonic-gate 1309852Svi117747 /* Signifies that the address was sucessfully processed */ 1310852Svi117747 if (!backout && laddr != NULL) 1311852Svi117747 *laddr = addr; 1312852Svi117747 1313852Svi117747 sp = sctp_saddr_lookup(sctp, &addr, 0); 13140Sstevel@tonic-gate ASSERT(sp != NULL); 13150Sstevel@tonic-gate 13160Sstevel@tonic-gate if (type == PARM_ADD_IP) { 13170Sstevel@tonic-gate if (backout) { 13180Sstevel@tonic-gate sctp_del_saddr(sctp, sp); 13190Sstevel@tonic-gate } else { 13200Sstevel@tonic-gate sp->saddr_ipif_dontsrc = 0; 13210Sstevel@tonic-gate } 13220Sstevel@tonic-gate } else if (type == PARM_DEL_IP) { 13230Sstevel@tonic-gate if (backout) { 13240Sstevel@tonic-gate sp->saddr_ipif_delete_pending = 0; 13250Sstevel@tonic-gate sp->saddr_ipif_dontsrc = 0; 13260Sstevel@tonic-gate } else { 13270Sstevel@tonic-gate sctp_del_saddr(sctp, sp); 13280Sstevel@tonic-gate } 13290Sstevel@tonic-gate } else { 13300Sstevel@tonic-gate /* Must be either PARM_ADD_IP or PARM_DEL_IP */ 13310Sstevel@tonic-gate ASSERT(0); 13320Sstevel@tonic-gate } 13330Sstevel@tonic-gate } 13340Sstevel@tonic-gate 13350Sstevel@tonic-gate /*ARGSUSED*/ 13360Sstevel@tonic-gate static mblk_t * 13370Sstevel@tonic-gate sctp_setprim_req(sctp_t *sctp, sctp_parm_hdr_t *ph, uint32_t cid, 1338852Svi117747 sctp_faddr_t *fp, int *cont, int act, in6_addr_t *raddr) 13390Sstevel@tonic-gate { 13400Sstevel@tonic-gate mblk_t *mp; 13410Sstevel@tonic-gate sctp_parm_hdr_t *oph; 13420Sstevel@tonic-gate sctp_faddr_t *nfp; 13430Sstevel@tonic-gate in6_addr_t addr; 13440Sstevel@tonic-gate 13450Sstevel@tonic-gate *cont = 1; 13460Sstevel@tonic-gate 13470Sstevel@tonic-gate /* Check input */ 13480Sstevel@tonic-gate if (ntohs(ph->sph_len) < (sizeof (*ph) * 2)) { 13490Sstevel@tonic-gate mp = sctp_asconf_adderr(SCTP_ERR_BAD_MANDPARM, ph, cid); 13500Sstevel@tonic-gate if (mp == NULL) { 13510Sstevel@tonic-gate *cont = -1; 13520Sstevel@tonic-gate } 13530Sstevel@tonic-gate return (mp); 13540Sstevel@tonic-gate } 13550Sstevel@tonic-gate 13560Sstevel@tonic-gate oph = ph; 13570Sstevel@tonic-gate ph = (sctp_parm_hdr_t *)((char *)ph + sizeof (sctp_parm_hdr_t) + 13580Sstevel@tonic-gate sizeof (cid)); 13590Sstevel@tonic-gate mp = sctp_check_addip_addr(ph, oph, cont, cid, &addr); 13600Sstevel@tonic-gate if (mp != NULL) { 13610Sstevel@tonic-gate return (mp); 13620Sstevel@tonic-gate } 13630Sstevel@tonic-gate 13640Sstevel@tonic-gate nfp = sctp_lookup_faddr(sctp, &addr); 13650Sstevel@tonic-gate if (nfp == NULL) { 13660Sstevel@tonic-gate /* 13670Sstevel@tonic-gate * Peer is trying to set an address that is not 13680Sstevel@tonic-gate * part of the association. 13690Sstevel@tonic-gate */ 13700Sstevel@tonic-gate dprint(1, ("setprim: addr not here: %x:%x:%x:%x\n", 13710Sstevel@tonic-gate SCTP_PRINTADDR(addr))); 13720Sstevel@tonic-gate mp = sctp_asconf_adderr(SCTP_ERR_BAD_MANDPARM, oph, cid); 13730Sstevel@tonic-gate if (mp == NULL) { 13740Sstevel@tonic-gate *cont = -1; 13750Sstevel@tonic-gate } 13760Sstevel@tonic-gate return (mp); 13770Sstevel@tonic-gate } 13780Sstevel@tonic-gate 13790Sstevel@tonic-gate sctp_intf_event(sctp, addr, SCTP_ADDR_MADE_PRIM, 0); 13800Sstevel@tonic-gate sctp->sctp_primary = nfp; 13810Sstevel@tonic-gate if (nfp->state != SCTP_FADDRS_ALIVE || nfp == sctp->sctp_current) { 13820Sstevel@tonic-gate return (NULL); 13830Sstevel@tonic-gate } 13841735Skcpoon sctp_set_faddr_current(sctp, nfp); 13850Sstevel@tonic-gate return (NULL); 13860Sstevel@tonic-gate } 13870Sstevel@tonic-gate 13880Sstevel@tonic-gate /*ARGSUSED*/ 13890Sstevel@tonic-gate static void 13900Sstevel@tonic-gate sctp_setprim_ack(sctp_t *sctp, sctp_parm_hdr_t *ph, sctp_parm_hdr_t *oph, 1391852Svi117747 sctp_faddr_t *fp, in6_addr_t *laddr) 13920Sstevel@tonic-gate { 13930Sstevel@tonic-gate if (ph != NULL && ph->sph_type != htons(PARM_SUCCESS)) { 13940Sstevel@tonic-gate /* If the peer doesn't understand Add-IP, remember it */ 13950Sstevel@tonic-gate if (ph->sph_type == htons(PARM_UNRECOGNIZED)) { 13960Sstevel@tonic-gate sctp->sctp_understands_addip = B_FALSE; 13970Sstevel@tonic-gate } 13980Sstevel@tonic-gate sctp_error_event(sctp, (sctp_chunk_hdr_t *)ph); 13990Sstevel@tonic-gate } 14000Sstevel@tonic-gate 14010Sstevel@tonic-gate /* On success we do nothing */ 14020Sstevel@tonic-gate } 14030Sstevel@tonic-gate 14040Sstevel@tonic-gate int 14050Sstevel@tonic-gate sctp_add_ip(sctp_t *sctp, const void *addrs, uint32_t cnt) 14060Sstevel@tonic-gate { 14070Sstevel@tonic-gate struct sockaddr_in *sin4; 14080Sstevel@tonic-gate struct sockaddr_in6 *sin6; 14090Sstevel@tonic-gate mblk_t *mp; 14100Sstevel@tonic-gate int error = 0; 14110Sstevel@tonic-gate int i; 14120Sstevel@tonic-gate sctp_addip4_t *ad4; 14130Sstevel@tonic-gate sctp_addip6_t *ad6; 14140Sstevel@tonic-gate sctp_asconf_t asc[1]; 14150Sstevel@tonic-gate uint16_t type = htons(PARM_ADD_IP); 14160Sstevel@tonic-gate boolean_t v4mapped = B_FALSE; 1417852Svi117747 sctp_cl_ainfo_t *ainfo = NULL; 14180Sstevel@tonic-gate 14190Sstevel@tonic-gate /* Does the peer understand ASCONF and Add-IP? */ 14200Sstevel@tonic-gate if (!sctp->sctp_understands_asconf || !sctp->sctp_understands_addip) 14210Sstevel@tonic-gate return (EOPNOTSUPP); 14220Sstevel@tonic-gate 1423852Svi117747 /* 1424852Svi117747 * On a clustered node, we need to pass this list when 1425852Svi117747 * we get an ASCONF-ACK. We only pre-allocate memory for the 1426852Svi117747 * list, but fill in the addresses when it is processed 1427852Svi117747 * successfully after we get an ASCONF-ACK. 1428852Svi117747 */ 1429852Svi117747 if (cl_sctp_assoc_change != NULL) { 1430852Svi117747 ainfo = kmem_zalloc(sizeof (*ainfo), KM_SLEEP); 1431852Svi117747 /* 1432852Svi117747 * Reserve space for the list of new addresses 1433852Svi117747 */ 1434852Svi117747 ainfo->sctp_cl_asize = sizeof (in6_addr_t) * cnt; 1435852Svi117747 ainfo->sctp_cl_alist = kmem_alloc(ainfo->sctp_cl_asize, 1436852Svi117747 KM_SLEEP); 1437852Svi117747 } 1438852Svi117747 14390Sstevel@tonic-gate sctp_asconf_init(asc); 14400Sstevel@tonic-gate 14410Sstevel@tonic-gate /* 14420Sstevel@tonic-gate * Screen addresses: 14430Sstevel@tonic-gate * If adding: 14440Sstevel@tonic-gate * o Must not already be a part of the association 14450Sstevel@tonic-gate * o Must be AF_INET or AF_INET6 14460Sstevel@tonic-gate * o XXX Must be valid source address for this node 14470Sstevel@tonic-gate * o Must be unicast 14480Sstevel@tonic-gate * o XXX Must fit scoping rules 14490Sstevel@tonic-gate * If deleting: 14500Sstevel@tonic-gate * o Must be part of the association 14510Sstevel@tonic-gate */ 14520Sstevel@tonic-gate for (i = 0; i < cnt; i++) { 14530Sstevel@tonic-gate switch (sctp->sctp_family) { 14540Sstevel@tonic-gate case AF_INET: 14550Sstevel@tonic-gate sin4 = (struct sockaddr_in *)addrs + i; 14560Sstevel@tonic-gate v4mapped = B_TRUE; 14570Sstevel@tonic-gate break; 14580Sstevel@tonic-gate 14590Sstevel@tonic-gate case AF_INET6: 14600Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)addrs + i; 14610Sstevel@tonic-gate break; 14620Sstevel@tonic-gate } 14630Sstevel@tonic-gate 14640Sstevel@tonic-gate if (v4mapped) { 14650Sstevel@tonic-gate mp = allocb(sizeof (*ad4), BPRI_MED); 14660Sstevel@tonic-gate if (mp == NULL) { 14670Sstevel@tonic-gate error = ENOMEM; 14680Sstevel@tonic-gate goto fail; 14690Sstevel@tonic-gate } 14700Sstevel@tonic-gate mp->b_wptr += sizeof (*ad4); 14710Sstevel@tonic-gate ad4 = (sctp_addip4_t *)mp->b_rptr; 14720Sstevel@tonic-gate ad4->sad4_addip_ph.sph_type = type; 14730Sstevel@tonic-gate ad4->sad4_addip_ph.sph_len = 14740Sstevel@tonic-gate htons(sizeof (sctp_parm_hdr_t) + 14750Sstevel@tonic-gate PARM_ADDR4_LEN + sizeof (ad4->asconf_req_cid)); 14760Sstevel@tonic-gate ad4->sad4_addr4_ph.sph_type = htons(PARM_ADDR4); 14770Sstevel@tonic-gate ad4->sad4_addr4_ph.sph_len = htons(PARM_ADDR4_LEN); 14780Sstevel@tonic-gate ad4->sad4_addr = sin4->sin_addr.s_addr; 14790Sstevel@tonic-gate } else { 14800Sstevel@tonic-gate mp = allocb(sizeof (*ad6), BPRI_MED); 14810Sstevel@tonic-gate if (mp == NULL) { 14820Sstevel@tonic-gate error = ENOMEM; 14830Sstevel@tonic-gate goto fail; 14840Sstevel@tonic-gate } 14850Sstevel@tonic-gate mp->b_wptr += sizeof (*ad6); 14860Sstevel@tonic-gate ad6 = (sctp_addip6_t *)mp->b_rptr; 14870Sstevel@tonic-gate ad6->sad6_addip_ph.sph_type = type; 14880Sstevel@tonic-gate ad6->sad6_addip_ph.sph_len = 14890Sstevel@tonic-gate htons(sizeof (sctp_parm_hdr_t) + 14900Sstevel@tonic-gate PARM_ADDR6_LEN + sizeof (ad6->asconf_req_cid)); 14910Sstevel@tonic-gate ad6->sad6_addr6_ph.sph_type = htons(PARM_ADDR6); 14920Sstevel@tonic-gate ad6->sad6_addr6_ph.sph_len = htons(PARM_ADDR6_LEN); 14930Sstevel@tonic-gate ad6->sad6_addr = sin6->sin6_addr; 14940Sstevel@tonic-gate } 14950Sstevel@tonic-gate error = sctp_asconf_add(asc, mp); 14960Sstevel@tonic-gate if (error != 0) 14970Sstevel@tonic-gate goto fail; 14980Sstevel@tonic-gate } 1499852Svi117747 error = sctp_asconf_send(sctp, asc, sctp->sctp_current, ainfo); 15000Sstevel@tonic-gate if (error != 0) 15010Sstevel@tonic-gate goto fail; 15020Sstevel@tonic-gate 15030Sstevel@tonic-gate return (0); 15040Sstevel@tonic-gate 15050Sstevel@tonic-gate fail: 1506852Svi117747 if (ainfo != NULL) { 1507852Svi117747 kmem_free(ainfo->sctp_cl_alist, ainfo->sctp_cl_asize); 1508852Svi117747 ainfo->sctp_cl_asize = 0; 1509852Svi117747 kmem_free(ainfo, sizeof (*ainfo)); 1510852Svi117747 } 15110Sstevel@tonic-gate sctp_asconf_destroy(asc); 15120Sstevel@tonic-gate return (error); 15130Sstevel@tonic-gate } 15140Sstevel@tonic-gate 15150Sstevel@tonic-gate int 1516852Svi117747 sctp_del_ip(sctp_t *sctp, const void *addrs, uint32_t cnt, uchar_t *ulist, 1517852Svi117747 size_t usize) 15180Sstevel@tonic-gate { 15190Sstevel@tonic-gate struct sockaddr_in *sin4; 15200Sstevel@tonic-gate struct sockaddr_in6 *sin6; 15210Sstevel@tonic-gate mblk_t *mp; 15220Sstevel@tonic-gate int error = 0; 15230Sstevel@tonic-gate int i; 15240Sstevel@tonic-gate int addrcnt = 0; 15250Sstevel@tonic-gate sctp_addip4_t *ad4; 15260Sstevel@tonic-gate sctp_addip6_t *ad6; 15270Sstevel@tonic-gate sctp_asconf_t asc[1]; 15280Sstevel@tonic-gate sctp_saddr_ipif_t *nsp; 15290Sstevel@tonic-gate uint16_t type = htons(PARM_DEL_IP); 15300Sstevel@tonic-gate boolean_t v4mapped = B_FALSE; 15310Sstevel@tonic-gate in6_addr_t addr; 15320Sstevel@tonic-gate boolean_t asconf = B_TRUE; 1533852Svi117747 uint_t ifindex; 1534852Svi117747 sctp_cl_ainfo_t *ainfo = NULL; 1535852Svi117747 uchar_t *p = ulist; 1536852Svi117747 boolean_t check_lport = B_FALSE; 15373448Sdh155122 sctp_stack_t *sctps = sctp->sctp_sctps; 15380Sstevel@tonic-gate 15390Sstevel@tonic-gate /* Does the peer understand ASCONF and Add-IP? */ 15403448Sdh155122 if (sctp->sctp_state <= SCTPS_LISTEN || !sctps->sctps_addip_enabled || 15410Sstevel@tonic-gate !sctp->sctp_understands_asconf || !sctp->sctp_understands_addip) { 15420Sstevel@tonic-gate asconf = B_FALSE; 15430Sstevel@tonic-gate } 15440Sstevel@tonic-gate 1545852Svi117747 if (sctp->sctp_state > SCTPS_BOUND) 1546852Svi117747 check_lport = B_TRUE; 1547852Svi117747 1548852Svi117747 if (asconf) { 1549852Svi117747 /* 1550852Svi117747 * On a clustered node, we need to pass this list when 1551852Svi117747 * we get an ASCONF-ACK. We only pre-allocate memory for the 1552852Svi117747 * list, but fill in the addresses when it is processed 1553852Svi117747 * successfully after we get an ASCONF-ACK. 1554852Svi117747 */ 1555852Svi117747 if (cl_sctp_assoc_change != NULL) { 1556852Svi117747 ainfo = kmem_alloc(sizeof (*ainfo), KM_SLEEP); 1557852Svi117747 ainfo->sctp_cl_dsize = sizeof (in6_addr_t) * cnt; 1558852Svi117747 ainfo->sctp_cl_dlist = kmem_alloc(ainfo->sctp_cl_dsize, 1559852Svi117747 KM_SLEEP); 1560852Svi117747 } 15610Sstevel@tonic-gate sctp_asconf_init(asc); 1562852Svi117747 } 15630Sstevel@tonic-gate /* 15640Sstevel@tonic-gate * Screen addresses: 15650Sstevel@tonic-gate * If adding: 15660Sstevel@tonic-gate * o Must not already be a part of the association 15670Sstevel@tonic-gate * o Must be AF_INET or AF_INET6 15680Sstevel@tonic-gate * o XXX Must be valid source address for this node 15690Sstevel@tonic-gate * o Must be unicast 15700Sstevel@tonic-gate * o XXX Must fit scoping rules 15710Sstevel@tonic-gate * If deleting: 15720Sstevel@tonic-gate * o Must be part of the association 15730Sstevel@tonic-gate */ 15740Sstevel@tonic-gate for (i = 0; i < cnt; i++) { 1575852Svi117747 ifindex = 0; 1576852Svi117747 15770Sstevel@tonic-gate switch (sctp->sctp_family) { 15780Sstevel@tonic-gate case AF_INET: 15790Sstevel@tonic-gate sin4 = (struct sockaddr_in *)addrs + i; 1580852Svi117747 if (check_lport && sin4->sin_port != sctp->sctp_lport) { 1581852Svi117747 error = EINVAL; 1582852Svi117747 goto fail; 1583852Svi117747 } 15840Sstevel@tonic-gate v4mapped = B_TRUE; 15850Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(sin4->sin_addr.s_addr, &addr); 15860Sstevel@tonic-gate break; 15870Sstevel@tonic-gate 15880Sstevel@tonic-gate case AF_INET6: 15890Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)addrs + i; 1590852Svi117747 if (check_lport && 1591852Svi117747 sin6->sin6_port != sctp->sctp_lport) { 1592852Svi117747 error = EINVAL; 1593852Svi117747 goto fail; 1594852Svi117747 } 15950Sstevel@tonic-gate addr = sin6->sin6_addr; 1596852Svi117747 ifindex = sin6->sin6_scope_id; 15970Sstevel@tonic-gate break; 15980Sstevel@tonic-gate } 1599852Svi117747 nsp = sctp_saddr_lookup(sctp, &addr, ifindex); 16000Sstevel@tonic-gate if (nsp == NULL) { 16010Sstevel@tonic-gate error = EADDRNOTAVAIL; 16020Sstevel@tonic-gate goto fail; 16030Sstevel@tonic-gate } 16040Sstevel@tonic-gate 1605852Svi117747 /* Collect the list of addresses, if required */ 1606852Svi117747 if (usize >= sizeof (addr)) { 1607852Svi117747 bcopy(&addr, p, sizeof (addr)); 1608852Svi117747 p += sizeof (addr); 1609852Svi117747 usize -= sizeof (addr); 1610852Svi117747 } 16110Sstevel@tonic-gate if (!asconf) 16120Sstevel@tonic-gate continue; 16130Sstevel@tonic-gate 16140Sstevel@tonic-gate nsp->saddr_ipif_delete_pending = 1; 16150Sstevel@tonic-gate nsp->saddr_ipif_dontsrc = 1; 16160Sstevel@tonic-gate addrcnt++; 16170Sstevel@tonic-gate if (v4mapped) { 16180Sstevel@tonic-gate mp = allocb(sizeof (*ad4), BPRI_MED); 16190Sstevel@tonic-gate if (mp == NULL) { 16200Sstevel@tonic-gate error = ENOMEM; 16210Sstevel@tonic-gate goto fail; 16220Sstevel@tonic-gate } 16230Sstevel@tonic-gate mp->b_wptr += sizeof (*ad4); 16240Sstevel@tonic-gate ad4 = (sctp_addip4_t *)mp->b_rptr; 16250Sstevel@tonic-gate ad4->sad4_addip_ph.sph_type = type; 16260Sstevel@tonic-gate ad4->sad4_addip_ph.sph_len = 16270Sstevel@tonic-gate htons(sizeof (sctp_parm_hdr_t) + 16280Sstevel@tonic-gate PARM_ADDR4_LEN + sizeof (ad4->asconf_req_cid)); 16290Sstevel@tonic-gate ad4->sad4_addr4_ph.sph_type = htons(PARM_ADDR4); 16300Sstevel@tonic-gate ad4->sad4_addr4_ph.sph_len = htons(PARM_ADDR4_LEN); 16310Sstevel@tonic-gate ad4->sad4_addr = sin4->sin_addr.s_addr; 16320Sstevel@tonic-gate } else { 16330Sstevel@tonic-gate mp = allocb(sizeof (*ad6), BPRI_MED); 16340Sstevel@tonic-gate if (mp == NULL) { 16350Sstevel@tonic-gate error = ENOMEM; 16360Sstevel@tonic-gate goto fail; 16370Sstevel@tonic-gate } 16380Sstevel@tonic-gate mp->b_wptr += sizeof (*ad6); 16390Sstevel@tonic-gate ad6 = (sctp_addip6_t *)mp->b_rptr; 16400Sstevel@tonic-gate ad6->sad6_addip_ph.sph_type = type; 16410Sstevel@tonic-gate ad6->sad6_addip_ph.sph_len = 16420Sstevel@tonic-gate htons(sizeof (sctp_parm_hdr_t) + PARM_ADDR6_LEN + 16430Sstevel@tonic-gate sizeof (ad6->asconf_req_cid)); 16440Sstevel@tonic-gate ad6->sad6_addr6_ph.sph_type = htons(PARM_ADDR6); 16450Sstevel@tonic-gate ad6->sad6_addr6_ph.sph_len = htons(PARM_ADDR6_LEN); 16460Sstevel@tonic-gate ad6->sad6_addr = addr; 16470Sstevel@tonic-gate } 16480Sstevel@tonic-gate 16490Sstevel@tonic-gate error = sctp_asconf_add(asc, mp); 16500Sstevel@tonic-gate if (error != 0) 16510Sstevel@tonic-gate goto fail; 16520Sstevel@tonic-gate } 16530Sstevel@tonic-gate 16540Sstevel@tonic-gate if (!asconf) { 16550Sstevel@tonic-gate sctp_del_saddr_list(sctp, addrs, cnt, B_FALSE); 16560Sstevel@tonic-gate return (0); 16570Sstevel@tonic-gate } 1658852Svi117747 error = sctp_asconf_send(sctp, asc, sctp->sctp_current, ainfo); 16590Sstevel@tonic-gate if (error != 0) 16600Sstevel@tonic-gate goto fail; 16610Sstevel@tonic-gate sctp_redo_faddr_srcs(sctp); 16620Sstevel@tonic-gate return (0); 16630Sstevel@tonic-gate 16640Sstevel@tonic-gate fail: 1665852Svi117747 if (ainfo != NULL) { 1666852Svi117747 kmem_free(ainfo->sctp_cl_dlist, ainfo->sctp_cl_dsize); 1667852Svi117747 ainfo->sctp_cl_dsize = 0; 1668852Svi117747 kmem_free(ainfo, sizeof (*ainfo)); 1669852Svi117747 } 16700Sstevel@tonic-gate if (!asconf) 16710Sstevel@tonic-gate return (error); 16720Sstevel@tonic-gate for (i = 0; i < addrcnt; i++) { 1673852Svi117747 ifindex = 0; 1674852Svi117747 16750Sstevel@tonic-gate switch (sctp->sctp_family) { 16760Sstevel@tonic-gate case AF_INET: 16770Sstevel@tonic-gate sin4 = (struct sockaddr_in *)addrs + i; 16780Sstevel@tonic-gate IN6_INADDR_TO_V4MAPPED(&(sin4->sin_addr), &addr); 16790Sstevel@tonic-gate break; 16800Sstevel@tonic-gate case AF_INET6: 16810Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)addrs + i; 16820Sstevel@tonic-gate addr = sin6->sin6_addr; 1683852Svi117747 ifindex = sin6->sin6_scope_id; 16840Sstevel@tonic-gate break; 16850Sstevel@tonic-gate } 1686852Svi117747 nsp = sctp_saddr_lookup(sctp, &addr, ifindex); 16870Sstevel@tonic-gate ASSERT(nsp != NULL); 16880Sstevel@tonic-gate nsp->saddr_ipif_delete_pending = 0; 16890Sstevel@tonic-gate nsp->saddr_ipif_dontsrc = 0; 16900Sstevel@tonic-gate } 16910Sstevel@tonic-gate sctp_asconf_destroy(asc); 16920Sstevel@tonic-gate 16930Sstevel@tonic-gate return (error); 16940Sstevel@tonic-gate } 16950Sstevel@tonic-gate 16960Sstevel@tonic-gate int 16970Sstevel@tonic-gate sctp_set_peerprim(sctp_t *sctp, const void *inp, uint_t inlen) 16980Sstevel@tonic-gate { 16990Sstevel@tonic-gate const struct sctp_setprim *prim = inp; 17000Sstevel@tonic-gate const struct sockaddr_storage *ss; 17010Sstevel@tonic-gate struct sockaddr_in *sin; 17020Sstevel@tonic-gate struct sockaddr_in6 *sin6; 17030Sstevel@tonic-gate in6_addr_t addr; 17040Sstevel@tonic-gate mblk_t *mp; 17050Sstevel@tonic-gate sctp_saddr_ipif_t *sp; 17060Sstevel@tonic-gate sctp_addip4_t *ad4; 17070Sstevel@tonic-gate sctp_addip6_t *ad6; 17080Sstevel@tonic-gate sctp_asconf_t asc[1]; 17090Sstevel@tonic-gate int error = 0; 1710852Svi117747 uint_t ifindex = 0; 17110Sstevel@tonic-gate 17120Sstevel@tonic-gate /* Does the peer understand ASCONF and Add-IP? */ 17130Sstevel@tonic-gate if (!sctp->sctp_understands_asconf || !sctp->sctp_understands_addip) { 17140Sstevel@tonic-gate return (EOPNOTSUPP); 17150Sstevel@tonic-gate } 17160Sstevel@tonic-gate 17170Sstevel@tonic-gate if (inlen < sizeof (*prim)) 17180Sstevel@tonic-gate return (EINVAL); 17190Sstevel@tonic-gate 17200Sstevel@tonic-gate /* Don't do anything if we are not connected */ 17210Sstevel@tonic-gate if (sctp->sctp_state != SCTPS_ESTABLISHED) 17220Sstevel@tonic-gate return (EINVAL); 17230Sstevel@tonic-gate 17240Sstevel@tonic-gate ss = &prim->ssp_addr; 17250Sstevel@tonic-gate sin = NULL; 17260Sstevel@tonic-gate sin6 = NULL; 17270Sstevel@tonic-gate if (ss->ss_family == AF_INET) { 17280Sstevel@tonic-gate sin = (struct sockaddr_in *)ss; 17290Sstevel@tonic-gate IN6_IPADDR_TO_V4MAPPED(sin->sin_addr.s_addr, &addr); 17300Sstevel@tonic-gate } else if (ss->ss_family == AF_INET6) { 17310Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)ss; 17320Sstevel@tonic-gate addr = sin6->sin6_addr; 1733852Svi117747 ifindex = sin6->sin6_scope_id; 17340Sstevel@tonic-gate } else { 17350Sstevel@tonic-gate return (EAFNOSUPPORT); 17360Sstevel@tonic-gate } 1737852Svi117747 sp = sctp_saddr_lookup(sctp, &addr, ifindex); 17380Sstevel@tonic-gate if (sp == NULL) 17390Sstevel@tonic-gate return (EADDRNOTAVAIL); 17400Sstevel@tonic-gate sctp_asconf_init(asc); 17410Sstevel@tonic-gate if (sin) { 17420Sstevel@tonic-gate mp = allocb(sizeof (*ad4), BPRI_MED); 17430Sstevel@tonic-gate if (mp == NULL) { 17440Sstevel@tonic-gate error = ENOMEM; 17450Sstevel@tonic-gate goto fail; 17460Sstevel@tonic-gate } 17470Sstevel@tonic-gate mp->b_wptr += sizeof (*ad4); 17480Sstevel@tonic-gate ad4 = (sctp_addip4_t *)mp->b_rptr; 17490Sstevel@tonic-gate ad4->sad4_addip_ph.sph_type = htons(PARM_SET_PRIMARY); 17500Sstevel@tonic-gate ad4->sad4_addip_ph.sph_len = htons(sizeof (sctp_parm_hdr_t) + 17510Sstevel@tonic-gate PARM_ADDR4_LEN + sizeof (ad4->asconf_req_cid)); 17520Sstevel@tonic-gate ad4->sad4_addr4_ph.sph_type = htons(PARM_ADDR4); 17530Sstevel@tonic-gate ad4->sad4_addr4_ph.sph_len = htons(PARM_ADDR4_LEN); 17540Sstevel@tonic-gate ad4->sad4_addr = sin->sin_addr.s_addr; 17550Sstevel@tonic-gate } else { 17560Sstevel@tonic-gate mp = allocb(sizeof (*ad6), BPRI_MED); 17570Sstevel@tonic-gate if (mp == NULL) { 17580Sstevel@tonic-gate error = ENOMEM; 17590Sstevel@tonic-gate goto fail; 17600Sstevel@tonic-gate } 17610Sstevel@tonic-gate mp->b_wptr += sizeof (*ad6); 17620Sstevel@tonic-gate ad6 = (sctp_addip6_t *)mp->b_rptr; 17630Sstevel@tonic-gate ad6->sad6_addip_ph.sph_type = htons(PARM_SET_PRIMARY); 17640Sstevel@tonic-gate ad6->sad6_addip_ph.sph_len = htons(sizeof (sctp_parm_hdr_t) + 17650Sstevel@tonic-gate PARM_ADDR6_LEN + sizeof (ad6->asconf_req_cid)); 17660Sstevel@tonic-gate ad6->sad6_addr6_ph.sph_type = htons(PARM_ADDR6); 17670Sstevel@tonic-gate ad6->sad6_addr6_ph.sph_len = htons(PARM_ADDR6_LEN); 17680Sstevel@tonic-gate ad6->sad6_addr = sin6->sin6_addr; 17690Sstevel@tonic-gate } 17700Sstevel@tonic-gate 17710Sstevel@tonic-gate error = sctp_asconf_add(asc, mp); 17720Sstevel@tonic-gate if (error != 0) { 17730Sstevel@tonic-gate goto fail; 17740Sstevel@tonic-gate } 17750Sstevel@tonic-gate 1776852Svi117747 error = sctp_asconf_send(sctp, asc, sctp->sctp_current, NULL); 17770Sstevel@tonic-gate if (error == 0) { 17780Sstevel@tonic-gate return (0); 17790Sstevel@tonic-gate } 17800Sstevel@tonic-gate 17810Sstevel@tonic-gate fail: 17820Sstevel@tonic-gate sctp_asconf_destroy(asc); 17830Sstevel@tonic-gate return (error); 17840Sstevel@tonic-gate } 1785