17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
545916cd2Sjpk  * Common Development and Distribution License (the "License").
645916cd2Sjpk  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
2177c67f2fSkcpoon 
227c478bd9Sstevel@tonic-gate /*
23fd7b5aedSGeorge Shepherd  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #include <sys/types.h>
277c478bd9Sstevel@tonic-gate #include <sys/systm.h>
287c478bd9Sstevel@tonic-gate #include <sys/stream.h>
297c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
307c478bd9Sstevel@tonic-gate #include <sys/socket.h>
317c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
327c478bd9Sstevel@tonic-gate #include <sys/strsubr.h>
337c478bd9Sstevel@tonic-gate #include <sys/strsun.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include <netinet/in.h>
367c478bd9Sstevel@tonic-gate #include <netinet/ip6.h>
377c478bd9Sstevel@tonic-gate #include <netinet/sctp.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #include <inet/common.h>
407c478bd9Sstevel@tonic-gate #include <inet/ip.h>
417c478bd9Sstevel@tonic-gate #include <inet/ip6.h>
427c478bd9Sstevel@tonic-gate #include <inet/mib2.h>
43f4b3ec61Sdh #include <inet/ipclassifier.h>
447c478bd9Sstevel@tonic-gate #include "sctp_impl.h"
457c478bd9Sstevel@tonic-gate #include "sctp_asconf.h"
467c478bd9Sstevel@tonic-gate #include "sctp_addr.h"
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate typedef struct sctp_asconf_s {
491d8c4025Svi 	mblk_t		*head;
50*ab82c29bSToomas Soome 	uint32_t	cid;
517c478bd9Sstevel@tonic-gate } sctp_asconf_t;
527c478bd9Sstevel@tonic-gate 
531d8c4025Svi /*
541d8c4025Svi  * This is only used on a clustered node to maintain pre-allocated buffer info.
551d8c4025Svi  * before sending an ASCONF chunk. The reason for pre-allocation is we don't
561d8c4025Svi  * want to fail allocating memory when we get then ASCONF-ACK in order to
571d8c4025Svi  * update the clustering subsystem's state for this assoc.
581d8c4025Svi  */
591d8c4025Svi typedef struct sctp_cl_ainfo_s {
601d8c4025Svi 	uchar_t	*sctp_cl_alist;
611d8c4025Svi 	size_t	sctp_cl_asize;
621d8c4025Svi 	uchar_t	*sctp_cl_dlist;
631d8c4025Svi 	size_t	sctp_cl_dsize;
641d8c4025Svi } sctp_cl_ainfo_t;
651d8c4025Svi 
667c478bd9Sstevel@tonic-gate /*
677c478bd9Sstevel@tonic-gate  * The ASCONF chunk per-parameter request interface. ph is the
687c478bd9Sstevel@tonic-gate  * parameter header for the parameter in the request, and cid
697c478bd9Sstevel@tonic-gate  * is the parameters correlation ID. cont should be set to 1
707c478bd9Sstevel@tonic-gate  * if the ASCONF framework should continue processing request
717c478bd9Sstevel@tonic-gate  * parameters following this one, or 0 if it should stop. If
727c478bd9Sstevel@tonic-gate  * cont is -1, this indicates complete memory depletion, which
737c478bd9Sstevel@tonic-gate  * will cause the ASCONF framework to abort building a reply. If
747c478bd9Sstevel@tonic-gate  * act is 1, the callback should take whatever action it needs
757c478bd9Sstevel@tonic-gate  * to fulfil this request. If act is 0, this request has already
767c478bd9Sstevel@tonic-gate  * been processed, so the callback should only verify and pass
777c478bd9Sstevel@tonic-gate  * back error parameters, and not take any action.
787c478bd9Sstevel@tonic-gate  *
797c478bd9Sstevel@tonic-gate  * The callback should return an mblk with any reply enclosed,
807c478bd9Sstevel@tonic-gate  * with the correlation ID in the first four bytes of the
817c478bd9Sstevel@tonic-gate  * message. A NULL return implies implicit success to the
827c478bd9Sstevel@tonic-gate  * requestor.
837c478bd9Sstevel@tonic-gate  */
847c478bd9Sstevel@tonic-gate typedef mblk_t *sctp_asconf_func_t(sctp_t *, sctp_parm_hdr_t *ph, uint32_t cid,
851d8c4025Svi     sctp_faddr_t *, int *cont, int act, in6_addr_t *addr);
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate /*
887c478bd9Sstevel@tonic-gate  * The ASCONF chunk per-parameter ACK interface. ph is the parameter
897c478bd9Sstevel@tonic-gate  * header for the parameter returned in the ACK, and oph is the
907c478bd9Sstevel@tonic-gate  * original parameter sent out in the ASCONF request.
917c478bd9Sstevel@tonic-gate  * If the peer implicitly responded OK (by not including an
927c478bd9Sstevel@tonic-gate  * explicit OK for the request), ph will be NULL.
937c478bd9Sstevel@tonic-gate  * ph can also point to an Unrecognized Parameter parameter,
947c478bd9Sstevel@tonic-gate  * in which case the peer did not understand the request
957c478bd9Sstevel@tonic-gate  * parameter.
967c478bd9Sstevel@tonic-gate  *
977c478bd9Sstevel@tonic-gate  * ph and oph parameter headers are in host byte order. Encapsulated
987c478bd9Sstevel@tonic-gate  * parameters will still be in network byte order.
997c478bd9Sstevel@tonic-gate  */
1007c478bd9Sstevel@tonic-gate typedef void sctp_asconf_ack_func_t(sctp_t *, sctp_parm_hdr_t *ph,
1011d8c4025Svi     sctp_parm_hdr_t *oph, sctp_faddr_t *, in6_addr_t *addr);
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate typedef struct {
1047c478bd9Sstevel@tonic-gate 	uint16_t id;
1057c478bd9Sstevel@tonic-gate 	sctp_asconf_func_t *asconf;
1067c478bd9Sstevel@tonic-gate 	sctp_asconf_ack_func_t *asconf_ack;
1077c478bd9Sstevel@tonic-gate } dispatch_t;
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate static sctp_asconf_func_t sctp_addip_req, sctp_setprim_req,
1107c478bd9Sstevel@tonic-gate     sctp_asconf_unrec_parm;
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate static sctp_asconf_ack_func_t sctp_addip_ack, sctp_setprim_ack,
1137c478bd9Sstevel@tonic-gate     sctp_asconf_ack_unrec_parm;
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate static const dispatch_t sctp_asconf_dispatch_tbl[] = {
1167c478bd9Sstevel@tonic-gate /*	ID			ASCONF			ASCONF_ACK */
1177c478bd9Sstevel@tonic-gate 	{ PARM_ADD_IP,		sctp_addip_req,		sctp_addip_ack },
1187c478bd9Sstevel@tonic-gate 	{ PARM_DEL_IP,		sctp_addip_req,		sctp_addip_ack },
1197c478bd9Sstevel@tonic-gate 	{ PARM_SET_PRIMARY,	sctp_setprim_req,	sctp_setprim_ack }
1207c478bd9Sstevel@tonic-gate };
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate static const dispatch_t sctp_asconf_default_dispatch = {
1237c478bd9Sstevel@tonic-gate 	0, sctp_asconf_unrec_parm, sctp_asconf_ack_unrec_parm
1247c478bd9Sstevel@tonic-gate };
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate /*
1277c478bd9Sstevel@tonic-gate  * ASCONF framework
1287c478bd9Sstevel@tonic-gate  */
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate static const dispatch_t *
sctp_lookup_asconf_dispatch(int id)1317c478bd9Sstevel@tonic-gate sctp_lookup_asconf_dispatch(int id)
1327c478bd9Sstevel@tonic-gate {
1337c478bd9Sstevel@tonic-gate 	int i;
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate 	for (i = 0; i < A_CNT(sctp_asconf_dispatch_tbl); i++) {
1367c478bd9Sstevel@tonic-gate 		if (sctp_asconf_dispatch_tbl[i].id == id) {
1377c478bd9Sstevel@tonic-gate 			return (sctp_asconf_dispatch_tbl + i);
1387c478bd9Sstevel@tonic-gate 		}
1397c478bd9Sstevel@tonic-gate 	}
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate 	return (&sctp_asconf_default_dispatch);
1427c478bd9Sstevel@tonic-gate }
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate /*
1457c478bd9Sstevel@tonic-gate  * Frees mp on failure
1467c478bd9Sstevel@tonic-gate  */
1477c478bd9Sstevel@tonic-gate static mblk_t *
sctp_asconf_prepend_errwrap(mblk_t * mp,uint32_t cid)1487c478bd9Sstevel@tonic-gate sctp_asconf_prepend_errwrap(mblk_t *mp, uint32_t cid)
1497c478bd9Sstevel@tonic-gate {
1507c478bd9Sstevel@tonic-gate 	mblk_t		*wmp;
1517c478bd9Sstevel@tonic-gate 	sctp_parm_hdr_t	*wph;
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate 	/* Prepend a wrapper err cause ind param */
1547c478bd9Sstevel@tonic-gate 	wmp = allocb(sizeof (*wph) + sizeof (cid), BPRI_MED);
1557c478bd9Sstevel@tonic-gate 	if (wmp == NULL) {
1567c478bd9Sstevel@tonic-gate 		freemsg(mp);
1577c478bd9Sstevel@tonic-gate 		return (NULL);
1587c478bd9Sstevel@tonic-gate 	}
1597c478bd9Sstevel@tonic-gate 	wmp->b_wptr += sizeof (*wph) + sizeof (cid);
1607c478bd9Sstevel@tonic-gate 	wph = (sctp_parm_hdr_t *)wmp->b_rptr;
1617c478bd9Sstevel@tonic-gate 	wph->sph_type = htons(PARM_ERROR_IND);
1627c478bd9Sstevel@tonic-gate 	wph->sph_len = htons(msgdsize(mp) + sizeof (*wph) + sizeof (cid));
1637c478bd9Sstevel@tonic-gate 	bcopy(&cid, wph + 1, sizeof (uint32_t));
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate 	wmp->b_cont = mp;
1667c478bd9Sstevel@tonic-gate 	return (wmp);
1677c478bd9Sstevel@tonic-gate }
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1707c478bd9Sstevel@tonic-gate static mblk_t *
sctp_asconf_unrec_parm(sctp_t * sctp,sctp_parm_hdr_t * ph,uint32_t cid,sctp_faddr_t * fp,int * cont,int act,in6_addr_t * addr)1717c478bd9Sstevel@tonic-gate sctp_asconf_unrec_parm(sctp_t *sctp, sctp_parm_hdr_t *ph, uint32_t cid,
1721d8c4025Svi     sctp_faddr_t *fp, int *cont, int act, in6_addr_t *addr)
1737c478bd9Sstevel@tonic-gate {
1747c478bd9Sstevel@tonic-gate 	mblk_t *mp = NULL;
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate 	/* Unrecognized param; check the high order bits */
17777ebe684SGeorge Shepherd 	if ((ph->sph_type & SCTP_UNREC_PARAM_MASK) ==
17877ebe684SGeorge Shepherd 	    (SCTP_CONT_PROC_PARAMS | SCTP_REPORT_THIS_PARAM)) {
1797c478bd9Sstevel@tonic-gate 		/* report unrecognized param, and keep processing */
180c513743fSGeorge Shepherd 		sctp_add_unrec_parm(ph, &mp, B_FALSE);
1817c478bd9Sstevel@tonic-gate 		if (mp == NULL) {
1827c478bd9Sstevel@tonic-gate 			*cont = -1;
1837c478bd9Sstevel@tonic-gate 			return (NULL);
1847c478bd9Sstevel@tonic-gate 		}
1857c478bd9Sstevel@tonic-gate 		/* Prepend a the CID and a wrapper err cause ind param */
1867c478bd9Sstevel@tonic-gate 		mp = sctp_asconf_prepend_errwrap(mp, cid);
1877c478bd9Sstevel@tonic-gate 		if (mp == NULL) {
1887c478bd9Sstevel@tonic-gate 			*cont = -1;
1897c478bd9Sstevel@tonic-gate 			return (NULL);
1907c478bd9Sstevel@tonic-gate 		}
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate 		*cont = 1;
1937c478bd9Sstevel@tonic-gate 		return (mp);
1947c478bd9Sstevel@tonic-gate 	}
19577ebe684SGeorge Shepherd 	if (ph->sph_type & SCTP_REPORT_THIS_PARAM) {
1967c478bd9Sstevel@tonic-gate 		/* Stop processing and drop; report unrecognized param */
197c513743fSGeorge Shepherd 		sctp_add_unrec_parm(ph, &mp, B_FALSE);
1987c478bd9Sstevel@tonic-gate 		if (mp == NULL) {
1997c478bd9Sstevel@tonic-gate 			*cont = -1;
2007c478bd9Sstevel@tonic-gate 			return (NULL);
2017c478bd9Sstevel@tonic-gate 		}
2027c478bd9Sstevel@tonic-gate 		/* Prepend a the CID and a wrapper err cause ind param */
2037c478bd9Sstevel@tonic-gate 		mp = sctp_asconf_prepend_errwrap(mp, cid);
2047c478bd9Sstevel@tonic-gate 		if (mp == NULL) {
2057c478bd9Sstevel@tonic-gate 			*cont = -1;
2067c478bd9Sstevel@tonic-gate 			return (NULL);
2077c478bd9Sstevel@tonic-gate 		}
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate 		*cont = 0;
2107c478bd9Sstevel@tonic-gate 		return (mp);
2117c478bd9Sstevel@tonic-gate 	}
21277ebe684SGeorge Shepherd 	if (ph->sph_type & SCTP_CONT_PROC_PARAMS) {
2137c478bd9Sstevel@tonic-gate 		/* skip and continue processing */
2147c478bd9Sstevel@tonic-gate 		*cont = 1;
2157c478bd9Sstevel@tonic-gate 		return (NULL);
2167c478bd9Sstevel@tonic-gate 	}
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 	/* 2 high bits are clear; stop processing and drop packet */
2197c478bd9Sstevel@tonic-gate 	*cont = 0;
2207c478bd9Sstevel@tonic-gate 	return (NULL);
2217c478bd9Sstevel@tonic-gate }
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate /*ARGSUSED*/
2247c478bd9Sstevel@tonic-gate static void
sctp_asconf_ack_unrec_parm(sctp_t * sctp,sctp_parm_hdr_t * ph,sctp_parm_hdr_t * oph,sctp_faddr_t * fp,in6_addr_t * laddr)2257c478bd9Sstevel@tonic-gate sctp_asconf_ack_unrec_parm(sctp_t *sctp, sctp_parm_hdr_t *ph,
2261d8c4025Svi     sctp_parm_hdr_t *oph, sctp_faddr_t *fp, in6_addr_t *laddr)
2277c478bd9Sstevel@tonic-gate {
2287c478bd9Sstevel@tonic-gate 	ASSERT(ph);
2298dfac042SAnil udupa 	sctp_error_event(sctp, (sctp_chunk_hdr_t *)ph, B_TRUE);
2307c478bd9Sstevel@tonic-gate }
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate static void
sctp_asconf_init(sctp_asconf_t * asc)2337c478bd9Sstevel@tonic-gate sctp_asconf_init(sctp_asconf_t *asc)
2347c478bd9Sstevel@tonic-gate {
2357c478bd9Sstevel@tonic-gate 	ASSERT(asc != NULL);
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate 	asc->head = NULL;
2387c478bd9Sstevel@tonic-gate 	asc->cid = 0;
2397c478bd9Sstevel@tonic-gate }
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate static int
sctp_asconf_add(sctp_asconf_t * asc,mblk_t * mp)2427c478bd9Sstevel@tonic-gate sctp_asconf_add(sctp_asconf_t *asc, mblk_t *mp)
2437c478bd9Sstevel@tonic-gate {
2447c478bd9Sstevel@tonic-gate 	uint32_t *cp;
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate 	/* XXX can't exceed MTU */
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 	cp = (uint32_t *)(mp->b_rptr + sizeof (sctp_parm_hdr_t));
2497c478bd9Sstevel@tonic-gate 	*cp = asc->cid++;
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 	if (asc->head == NULL)
2527c478bd9Sstevel@tonic-gate 		asc->head = mp;
2537c478bd9Sstevel@tonic-gate 	else
2547c478bd9Sstevel@tonic-gate 		linkb(asc->head, mp);
2557c478bd9Sstevel@tonic-gate 
2567c478bd9Sstevel@tonic-gate 	return (0);
2577c478bd9Sstevel@tonic-gate }
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate static void
sctp_asconf_destroy(sctp_asconf_t * asc)2607c478bd9Sstevel@tonic-gate sctp_asconf_destroy(sctp_asconf_t *asc)
2617c478bd9Sstevel@tonic-gate {
2627c478bd9Sstevel@tonic-gate 	if (asc->head != NULL) {
2637c478bd9Sstevel@tonic-gate 		freemsg(asc->head);
2647c478bd9Sstevel@tonic-gate 		asc->head = NULL;
2657c478bd9Sstevel@tonic-gate 	}
2667c478bd9Sstevel@tonic-gate 	asc->cid = 0;
2677c478bd9Sstevel@tonic-gate }
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate static int
sctp_asconf_send(sctp_t * sctp,sctp_asconf_t * asc,sctp_faddr_t * fp,sctp_cl_ainfo_t * ainfo)2701d8c4025Svi sctp_asconf_send(sctp_t *sctp, sctp_asconf_t *asc, sctp_faddr_t *fp,
2711d8c4025Svi     sctp_cl_ainfo_t *ainfo)
2727c478bd9Sstevel@tonic-gate {
2737c478bd9Sstevel@tonic-gate 	mblk_t			*mp, *nmp;
2747c478bd9Sstevel@tonic-gate 	sctp_chunk_hdr_t	*ch;
2757c478bd9Sstevel@tonic-gate 	boolean_t		isv4;
2767c478bd9Sstevel@tonic-gate 	size_t			msgsize;
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 	ASSERT(asc != NULL && asc->head != NULL);
2797c478bd9Sstevel@tonic-gate 
2806be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	isv4 = (fp != NULL) ? fp->sf_isv4 : sctp->sctp_current->sf_isv4;
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 	/* SCTP chunk header + Serial Number + Address Param TLV */
2837c478bd9Sstevel@tonic-gate 	msgsize = sizeof (*ch) + sizeof (uint32_t) +
2847c478bd9Sstevel@tonic-gate 	    (isv4 ? PARM_ADDR4_LEN : PARM_ADDR6_LEN);
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate 	mp = allocb(msgsize, BPRI_MED);
2877c478bd9Sstevel@tonic-gate 	if (mp == NULL)
2887c478bd9Sstevel@tonic-gate 		return (ENOMEM);
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 	mp->b_wptr += msgsize;
2917c478bd9Sstevel@tonic-gate 	mp->b_cont = asc->head;
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate 	ch = (sctp_chunk_hdr_t *)mp->b_rptr;
2947c478bd9Sstevel@tonic-gate 	ch->sch_id = CHUNK_ASCONF;
2957c478bd9Sstevel@tonic-gate 	ch->sch_flags = 0;
2967c478bd9Sstevel@tonic-gate 	ch->sch_len = htons(msgdsize(mp));
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate 	nmp = msgpullup(mp, -1);
2997c478bd9Sstevel@tonic-gate 	if (nmp == NULL) {
3007c478bd9Sstevel@tonic-gate 		freeb(mp);
3017c478bd9Sstevel@tonic-gate 		return (ENOMEM);
3027c478bd9Sstevel@tonic-gate 	}
3037c478bd9Sstevel@tonic-gate 
3041d8c4025Svi 	/*
3051d8c4025Svi 	 * Stash the address list and the count so that when the operation
3061d8c4025Svi 	 * completes, i.e. when as get an ACK, we can update the clustering's
3071d8c4025Svi 	 * state for this association.
3081d8c4025Svi 	 */
3091d8c4025Svi 	if (ainfo != NULL) {
3101d8c4025Svi 		ASSERT(cl_sctp_assoc_change != NULL);
3111d8c4025Svi 		ASSERT(nmp->b_prev == NULL);
3121d8c4025Svi 		nmp->b_prev = (mblk_t *)ainfo;
3131d8c4025Svi 	}
3147c478bd9Sstevel@tonic-gate 	/* Clean up the temporary mblk chain */
3157c478bd9Sstevel@tonic-gate 	freemsg(mp);
3167c478bd9Sstevel@tonic-gate 	asc->head = NULL;
3177c478bd9Sstevel@tonic-gate 	asc->cid = 0;
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate 	/* Queue it ... */
3207c478bd9Sstevel@tonic-gate 	if (sctp->sctp_cxmit_list == NULL) {
3217c478bd9Sstevel@tonic-gate 		sctp->sctp_cxmit_list = nmp;
3227c478bd9Sstevel@tonic-gate 	} else {
3237c478bd9Sstevel@tonic-gate 		linkb(sctp->sctp_cxmit_list, nmp);
3247c478bd9Sstevel@tonic-gate 	}
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate 	BUMP_LOCAL(sctp->sctp_obchunks);
3277c478bd9Sstevel@tonic-gate 
3287c478bd9Sstevel@tonic-gate 	/* And try to send it. */
3297c478bd9Sstevel@tonic-gate 	sctp_wput_asconf(sctp, fp);
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate 	return (0);
3327c478bd9Sstevel@tonic-gate }
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate /*
3357c478bd9Sstevel@tonic-gate  * If the peer does not understand an ASCONF chunk, we simply
3367c478bd9Sstevel@tonic-gate  * clear out the cxmit_list, since we can send nothing further
3377c478bd9Sstevel@tonic-gate  * that the peer will understand.
3387c478bd9Sstevel@tonic-gate  *
3397c478bd9Sstevel@tonic-gate  * Assumes chunk length has already been checked.
3407c478bd9Sstevel@tonic-gate  */
3417c478bd9Sstevel@tonic-gate /*ARGSUSED*/
3427c478bd9Sstevel@tonic-gate void
sctp_asconf_free_cxmit(sctp_t * sctp,sctp_chunk_hdr_t * ch)3431d8c4025Svi sctp_asconf_free_cxmit(sctp_t *sctp, sctp_chunk_hdr_t *ch)
3447c478bd9Sstevel@tonic-gate {
3451d8c4025Svi 	mblk_t		*mp;
3461d8c4025Svi 	mblk_t		*mp1;
3471d8c4025Svi 	sctp_cl_ainfo_t	*ainfo;
3481d8c4025Svi 
3497c478bd9Sstevel@tonic-gate 	if (sctp->sctp_cxmit_list == NULL) {
3507c478bd9Sstevel@tonic-gate 		/* Nothing pending */
3517c478bd9Sstevel@tonic-gate 		return;
3527c478bd9Sstevel@tonic-gate 	}
3537c478bd9Sstevel@tonic-gate 
3541d8c4025Svi 	mp = sctp->sctp_cxmit_list;
3551d8c4025Svi 	while (mp != NULL) {
3561d8c4025Svi 		mp1 = mp->b_cont;
3571d8c4025Svi 		mp->b_cont = NULL;
3581d8c4025Svi 		if (mp->b_prev != NULL) {
3591d8c4025Svi 			ainfo = (sctp_cl_ainfo_t *)mp->b_prev;
3601d8c4025Svi 			mp->b_prev = NULL;
3611d8c4025Svi 			kmem_free(ainfo->sctp_cl_alist, ainfo->sctp_cl_asize);
3621d8c4025Svi 			kmem_free(ainfo->sctp_cl_dlist, ainfo->sctp_cl_dsize);
3631d8c4025Svi 			kmem_free(ainfo, sizeof (*ainfo));
3641d8c4025Svi 		}
3651d8c4025Svi 		freeb(mp);
3661d8c4025Svi 		mp = mp1;
3671d8c4025Svi 	}
3687c478bd9Sstevel@tonic-gate 	sctp->sctp_cxmit_list = NULL;
3697c478bd9Sstevel@tonic-gate }
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate void
sctp_input_asconf(sctp_t * sctp,sctp_chunk_hdr_t * ch,sctp_faddr_t * fp)3727c478bd9Sstevel@tonic-gate sctp_input_asconf(sctp_t *sctp, sctp_chunk_hdr_t *ch, sctp_faddr_t *fp)
3737c478bd9Sstevel@tonic-gate {
3747c478bd9Sstevel@tonic-gate 	const dispatch_t	*dp;
3757c478bd9Sstevel@tonic-gate 	mblk_t			*hmp;
3767c478bd9Sstevel@tonic-gate 	mblk_t			*mp;
3777c478bd9Sstevel@tonic-gate 	uint32_t		*idp;
3787c478bd9Sstevel@tonic-gate 	uint32_t		*hidp;
3797c478bd9Sstevel@tonic-gate 	ssize_t			rlen;
3807c478bd9Sstevel@tonic-gate 	sctp_parm_hdr_t		*ph;
3817c478bd9Sstevel@tonic-gate 	sctp_chunk_hdr_t	*ach;
3827c478bd9Sstevel@tonic-gate 	int			cont;
3837c478bd9Sstevel@tonic-gate 	int			act;
3847c478bd9Sstevel@tonic-gate 	uint16_t		plen;
3851d8c4025Svi 	uchar_t			*alist = NULL;
3861d8c4025Svi 	size_t			asize = 0;
3871d8c4025Svi 	uchar_t			*dlist = NULL;
3881d8c4025Svi 	size_t			dsize = 0;
3891d8c4025Svi 	uchar_t			*aptr = NULL;
3901d8c4025Svi 	uchar_t			*dptr = NULL;
3911d8c4025Svi 	int			acount = 0;
3921d8c4025Svi 	int			dcount = 0;
393f4b3ec61Sdh 	sctp_stack_t		*sctps = sctp->sctp_sctps;
3947c478bd9Sstevel@tonic-gate 
3957c478bd9Sstevel@tonic-gate 	ASSERT(ch->sch_id == CHUNK_ASCONF);
3967c478bd9Sstevel@tonic-gate 
3977c478bd9Sstevel@tonic-gate 	idp = (uint32_t *)(ch + 1);
3987c478bd9Sstevel@tonic-gate 	rlen = ntohs(ch->sch_len) - sizeof (*ch) - sizeof (*idp);
3997c478bd9Sstevel@tonic-gate 
4007c478bd9Sstevel@tonic-gate 	if (rlen < 0 || rlen < sizeof (*idp)) {
4017c478bd9Sstevel@tonic-gate 		/* nothing there; bail out */
4027c478bd9Sstevel@tonic-gate 		return;
4037c478bd9Sstevel@tonic-gate 	}
4047c478bd9Sstevel@tonic-gate 
4057c478bd9Sstevel@tonic-gate 	/* Check for duplicates */
4067c478bd9Sstevel@tonic-gate 	*idp = ntohl(*idp);
4077c478bd9Sstevel@tonic-gate 	if (*idp == (sctp->sctp_fcsn + 1)) {
4087c478bd9Sstevel@tonic-gate 		act = 1;
4097c478bd9Sstevel@tonic-gate 	} else if (*idp == sctp->sctp_fcsn) {
4107c478bd9Sstevel@tonic-gate 		act = 0;
4117c478bd9Sstevel@tonic-gate 	} else {
4127c478bd9Sstevel@tonic-gate 		/* stale or malicious packet; drop */
4137c478bd9Sstevel@tonic-gate 		return;
4147c478bd9Sstevel@tonic-gate 	}
4157c478bd9Sstevel@tonic-gate 
4167c478bd9Sstevel@tonic-gate 	/* Create the ASCONF_ACK header */
4177c478bd9Sstevel@tonic-gate 	hmp = sctp_make_mp(sctp, fp, sizeof (*ach) + sizeof (*idp));
4187c478bd9Sstevel@tonic-gate 	if (hmp == NULL) {
4197c478bd9Sstevel@tonic-gate 		/* Let the peer retransmit */
420f4b3ec61Sdh 		SCTP_KSTAT(sctps, sctp_send_asconf_ack_failed);
4217c478bd9Sstevel@tonic-gate 		return;
4227c478bd9Sstevel@tonic-gate 	}
4237c478bd9Sstevel@tonic-gate 	ach = (sctp_chunk_hdr_t *)hmp->b_wptr;
4247c478bd9Sstevel@tonic-gate 	ach->sch_id = CHUNK_ASCONF_ACK;
4257c478bd9Sstevel@tonic-gate 	ach->sch_flags = 0;
4267c478bd9Sstevel@tonic-gate 	/* Set the length later */
4277c478bd9Sstevel@tonic-gate 	hidp = (uint32_t *)(ach + 1);
4287c478bd9Sstevel@tonic-gate 	*hidp = htonl(*idp);
4297c478bd9Sstevel@tonic-gate 	hmp->b_wptr = (uchar_t *)(hidp + 1);
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate 	/* Move to the Address Parameter */
4327c478bd9Sstevel@tonic-gate 	ph = (sctp_parm_hdr_t *)(idp + 1);
4337c478bd9Sstevel@tonic-gate 	if (rlen <= ntohs(ph->sph_len)) {
4347c478bd9Sstevel@tonic-gate 		freeb(hmp);
4357c478bd9Sstevel@tonic-gate 		return;
4367c478bd9Sstevel@tonic-gate 	}
4377c478bd9Sstevel@tonic-gate 
4387c478bd9Sstevel@tonic-gate 	/*
4397c478bd9Sstevel@tonic-gate 	 * We already have the association here, so this address parameter
4407c478bd9Sstevel@tonic-gate 	 * doesn't seem to be very useful, should we make sure this is part
4417c478bd9Sstevel@tonic-gate 	 * of the association and send an error, if not?
4427c478bd9Sstevel@tonic-gate 	 * Ignore it for now.
4437c478bd9Sstevel@tonic-gate 	 */
4447c478bd9Sstevel@tonic-gate 	rlen -= ntohs(ph->sph_len);
4457c478bd9Sstevel@tonic-gate 	ph = (sctp_parm_hdr_t *)((char *)ph + ntohs(ph->sph_len));
4461d8c4025Svi 
4471d8c4025Svi 	/*
4481d8c4025Svi 	 * We need to pre-allocate buffer before processing the ASCONF
4491d8c4025Svi 	 * chunk. We don't want to fail allocating buffers after processing
4501d8c4025Svi 	 * the ASCONF chunk. So, we walk the list and get the number of
4511d8c4025Svi 	 * addresses added and/or deleted.
4521d8c4025Svi 	 */
4531d8c4025Svi 	if (cl_sctp_assoc_change != NULL) {
4541d8c4025Svi 		sctp_parm_hdr_t	*oph = ph;
4551d8c4025Svi 		ssize_t		orlen = rlen;
4561d8c4025Svi 
4571d8c4025Svi 		/*
4581d8c4025Svi 		 * This not very efficient, but there is no better way of
4591d8c4025Svi 		 * doing it.  It should be fine since normally the param list
4601d8c4025Svi 		 * will not be very long.
4611d8c4025Svi 		 */
4621d8c4025Svi 		while (orlen > 0) {
4631d8c4025Svi 			/* Sanity checks */
4641d8c4025Svi 			if (orlen < sizeof (*oph))
4651d8c4025Svi 				break;
4661d8c4025Svi 			plen = ntohs(oph->sph_len);
4671d8c4025Svi 			if (plen < sizeof (*oph) || plen > orlen)
4681d8c4025Svi 				break;
4691d8c4025Svi 			if (oph->sph_type == htons(PARM_ADD_IP))
4701d8c4025Svi 				acount++;
4711d8c4025Svi 			if (oph->sph_type == htons(PARM_DEL_IP))
4721d8c4025Svi 				dcount++;
4731d8c4025Svi 			oph = sctp_next_parm(oph, &orlen);
4741d8c4025Svi 			if (oph == NULL)
4751d8c4025Svi 				break;
4761d8c4025Svi 		}
4771d8c4025Svi 		if (acount > 0 || dcount > 0) {
4781d8c4025Svi 			if (acount > 0) {
4791d8c4025Svi 				asize = sizeof (in6_addr_t) * acount;
4801d8c4025Svi 				alist = kmem_alloc(asize, KM_NOSLEEP);
4811d8c4025Svi 				if (alist == NULL) {
4821d8c4025Svi 					freeb(hmp);
483f4b3ec61Sdh 					SCTP_KSTAT(sctps, sctp_cl_assoc_change);
4841d8c4025Svi 					return;
4851d8c4025Svi 				}
4861d8c4025Svi 			}
4871d8c4025Svi 			if (dcount > 0) {
4881d8c4025Svi 				dsize = sizeof (in6_addr_t) * dcount;
4891d8c4025Svi 				dlist = kmem_alloc(dsize, KM_NOSLEEP);
4901d8c4025Svi 				if (dlist == NULL) {
4911d8c4025Svi 					if (acount > 0)
4921d8c4025Svi 						kmem_free(alist, asize);
4931d8c4025Svi 					freeb(hmp);
494f4b3ec61Sdh 					SCTP_KSTAT(sctps, sctp_cl_assoc_change);
4951d8c4025Svi 					return;
4961d8c4025Svi 				}
4971d8c4025Svi 			}
4981d8c4025Svi 			aptr = alist;
4991d8c4025Svi 			dptr = dlist;
5001d8c4025Svi 			/*
5011d8c4025Svi 			 * We will get the actual count when we process
5021d8c4025Svi 			 * the chunk.
5031d8c4025Svi 			 */
5041d8c4025Svi 			acount = 0;
5051d8c4025Svi 			dcount = 0;
5061d8c4025Svi 		}
5071d8c4025Svi 	}
5087c478bd9Sstevel@tonic-gate 	cont = 1;
5097c478bd9Sstevel@tonic-gate 	while (rlen > 0 && cont) {
5101d8c4025Svi 		in6_addr_t	addr;
5111d8c4025Svi 
5127c478bd9Sstevel@tonic-gate 		/* Sanity checks */
5137c478bd9Sstevel@tonic-gate 		if (rlen < sizeof (*ph))
5147c478bd9Sstevel@tonic-gate 			break;
5157c478bd9Sstevel@tonic-gate 		plen = ntohs(ph->sph_len);
5167c478bd9Sstevel@tonic-gate 		if (plen < sizeof (*ph) || plen > rlen) {
5177c478bd9Sstevel@tonic-gate 			break;
5187c478bd9Sstevel@tonic-gate 		}
5197c478bd9Sstevel@tonic-gate 		idp = (uint32_t *)(ph + 1);
5207c478bd9Sstevel@tonic-gate 		dp = sctp_lookup_asconf_dispatch(ntohs(ph->sph_type));
5217c478bd9Sstevel@tonic-gate 		ASSERT(dp);
5227c478bd9Sstevel@tonic-gate 		if (dp->asconf) {
5231d8c4025Svi 			mp = dp->asconf(sctp, ph, *idp, fp, &cont, act, &addr);
5247c478bd9Sstevel@tonic-gate 			if (cont == -1) {
5257c478bd9Sstevel@tonic-gate 				/*
5267c478bd9Sstevel@tonic-gate 				 * Not even enough memory to create
5277c478bd9Sstevel@tonic-gate 				 * an out-of-resources error. Free
5287c478bd9Sstevel@tonic-gate 				 * everything and return; the peer
5297c478bd9Sstevel@tonic-gate 				 * should retransmit.
5307c478bd9Sstevel@tonic-gate 				 */
5317c478bd9Sstevel@tonic-gate 				freemsg(hmp);
5321d8c4025Svi 				if (alist != NULL)
5331d8c4025Svi 					kmem_free(alist, asize);
5341d8c4025Svi 				if (dlist != NULL)
5351d8c4025Svi 					kmem_free(dlist, dsize);
5367c478bd9Sstevel@tonic-gate 				return;
5377c478bd9Sstevel@tonic-gate 			}
5387c478bd9Sstevel@tonic-gate 			if (mp != NULL) {
5397c478bd9Sstevel@tonic-gate 				linkb(hmp, mp);
5401d8c4025Svi 			} else if (act != 0) {
5411d8c4025Svi 				/* update the add/delete list */
5421d8c4025Svi 				if (cl_sctp_assoc_change != NULL) {
5431d8c4025Svi 					if (ph->sph_type ==
5441d8c4025Svi 					    htons(PARM_ADD_IP)) {
5451d8c4025Svi 						ASSERT(alist != NULL);
5461d8c4025Svi 						bcopy(&addr, aptr,
5471d8c4025Svi 						    sizeof (addr));
5481d8c4025Svi 						aptr += sizeof (addr);
5491d8c4025Svi 						acount++;
5501d8c4025Svi 					} else if (ph->sph_type ==
5511d8c4025Svi 					    htons(PARM_DEL_IP)) {
5521d8c4025Svi 						ASSERT(dlist != NULL);
5531d8c4025Svi 						bcopy(&addr, dptr,
5541d8c4025Svi 						    sizeof (addr));
5551d8c4025Svi 						dptr += sizeof (addr);
5561d8c4025Svi 						dcount++;
5571d8c4025Svi 					}
5581d8c4025Svi 				}
5597c478bd9Sstevel@tonic-gate 			}
5607c478bd9Sstevel@tonic-gate 		}
5617c478bd9Sstevel@tonic-gate 		ph = sctp_next_parm(ph, &rlen);
5627c478bd9Sstevel@tonic-gate 		if (ph == NULL)
5637c478bd9Sstevel@tonic-gate 			break;
5647c478bd9Sstevel@tonic-gate 	}
5657c478bd9Sstevel@tonic-gate 
5661d8c4025Svi 	/*
5671d8c4025Svi 	 * Update clustering's state for this assoc. Note acount/dcount
5681d8c4025Svi 	 * could be zero (i.e. if the add/delete address(es) were not
5691d8c4025Svi 	 * processed successfully). Regardless, if the ?size is > 0,
5701d8c4025Svi 	 * it is the clustering module's responsibility to free the lists.
5711d8c4025Svi 	 */
5721d8c4025Svi 	if (cl_sctp_assoc_change != NULL) {
573bd670b35SErik Nordmark 		(*cl_sctp_assoc_change)(sctp->sctp_connp->conn_family,
574bd670b35SErik Nordmark 		    alist, asize,
5751d8c4025Svi 		    acount, dlist, dsize, dcount, SCTP_CL_PADDR,
5761d8c4025Svi 		    (cl_sctp_handle_t)sctp);
5771d8c4025Svi 		/* alist and dlist will be freed by the clustering module */
5781d8c4025Svi 	}
5797c478bd9Sstevel@tonic-gate 	/* Now that the params have been processed, increment the fcsn */
5807c478bd9Sstevel@tonic-gate 	if (act) {
5817c478bd9Sstevel@tonic-gate 		sctp->sctp_fcsn++;
5827c478bd9Sstevel@tonic-gate 	}
5837c478bd9Sstevel@tonic-gate 	BUMP_LOCAL(sctp->sctp_obchunks);
5847c478bd9Sstevel@tonic-gate 
5856be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	if (fp->sf_isv4)
5867c478bd9Sstevel@tonic-gate 		ach->sch_len = htons(msgdsize(hmp) - sctp->sctp_hdr_len);
5877c478bd9Sstevel@tonic-gate 	else
5887c478bd9Sstevel@tonic-gate 		ach->sch_len = htons(msgdsize(hmp) - sctp->sctp_hdr6_len);
5897c478bd9Sstevel@tonic-gate 
5906be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	sctp_set_iplen(sctp, hmp, fp->sf_ixa);
5916be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	(void) conn_ip_output(hmp, fp->sf_ixa);
592bd670b35SErik Nordmark 	BUMP_LOCAL(sctp->sctp_opkts);
5937c478bd9Sstevel@tonic-gate 	sctp_validate_peer(sctp);
5947c478bd9Sstevel@tonic-gate }
5957c478bd9Sstevel@tonic-gate 
5967c478bd9Sstevel@tonic-gate static sctp_parm_hdr_t *
sctp_lookup_asconf_param(sctp_parm_hdr_t * ph,uint32_t cid,ssize_t rlen)5977c478bd9Sstevel@tonic-gate sctp_lookup_asconf_param(sctp_parm_hdr_t *ph, uint32_t cid, ssize_t rlen)
5987c478bd9Sstevel@tonic-gate {
5997c478bd9Sstevel@tonic-gate 	uint32_t *idp;
6007c478bd9Sstevel@tonic-gate 
6017c478bd9Sstevel@tonic-gate 	while (rlen > 0) {
6027c478bd9Sstevel@tonic-gate 		idp = (uint32_t *)(ph + 1);
6037c478bd9Sstevel@tonic-gate 		if (*idp == cid) {
6047c478bd9Sstevel@tonic-gate 			return (ph);
6057c478bd9Sstevel@tonic-gate 		}
6067c478bd9Sstevel@tonic-gate 		ph = sctp_next_parm(ph, &rlen);
6077c478bd9Sstevel@tonic-gate 		if (ph == NULL)
6087c478bd9Sstevel@tonic-gate 			break;
6097c478bd9Sstevel@tonic-gate 	}
6107c478bd9Sstevel@tonic-gate 	return (NULL);
6117c478bd9Sstevel@tonic-gate }
6127c478bd9Sstevel@tonic-gate 
6137c478bd9Sstevel@tonic-gate void
sctp_input_asconf_ack(sctp_t * sctp,sctp_chunk_hdr_t * ch,sctp_faddr_t * fp)6147c478bd9Sstevel@tonic-gate sctp_input_asconf_ack(sctp_t *sctp, sctp_chunk_hdr_t *ch, sctp_faddr_t *fp)
6157c478bd9Sstevel@tonic-gate {
6167c478bd9Sstevel@tonic-gate 	const dispatch_t	*dp;
6177c478bd9Sstevel@tonic-gate 	uint32_t		*idp;
6187c478bd9Sstevel@tonic-gate 	uint32_t		*snp;
6197c478bd9Sstevel@tonic-gate 	ssize_t			rlen;
6207c478bd9Sstevel@tonic-gate 	ssize_t			plen;
6217c478bd9Sstevel@tonic-gate 	sctp_parm_hdr_t		*ph;
6227c478bd9Sstevel@tonic-gate 	sctp_parm_hdr_t		*oph;
6237c478bd9Sstevel@tonic-gate 	sctp_parm_hdr_t		*fph;
6247c478bd9Sstevel@tonic-gate 	mblk_t			*mp;
6257c478bd9Sstevel@tonic-gate 	sctp_chunk_hdr_t	*och;
6267c478bd9Sstevel@tonic-gate 	int			redosrcs = 0;
6277c478bd9Sstevel@tonic-gate 	uint16_t		param_len;
6281d8c4025Svi 	uchar_t			*alist;
6291d8c4025Svi 	uchar_t			*dlist;
6301d8c4025Svi 	uint_t			acount = 0;
6311d8c4025Svi 	uint_t			dcount = 0;
6321d8c4025Svi 	uchar_t			*aptr;
6331d8c4025Svi 	uchar_t			*dptr;
6341d8c4025Svi 	sctp_cl_ainfo_t		*ainfo;
6351d8c4025Svi 	in6_addr_t		addr;
6367c478bd9Sstevel@tonic-gate 
6377c478bd9Sstevel@tonic-gate 	ASSERT(ch->sch_id == CHUNK_ASCONF_ACK);
6387c478bd9Sstevel@tonic-gate 
639*ab82c29bSToomas Soome 	ainfo = NULL;
640*ab82c29bSToomas Soome 	alist = NULL;
641*ab82c29bSToomas Soome 	dlist = NULL;
642*ab82c29bSToomas Soome 	aptr = NULL;
643*ab82c29bSToomas Soome 	dptr = NULL;
644*ab82c29bSToomas Soome 
6457c478bd9Sstevel@tonic-gate 	snp = (uint32_t *)(ch + 1);
6467c478bd9Sstevel@tonic-gate 	rlen = ntohs(ch->sch_len) - sizeof (*ch) - sizeof (*snp);
6477c478bd9Sstevel@tonic-gate 	if (rlen < 0) {
6487c478bd9Sstevel@tonic-gate 		return;
6497c478bd9Sstevel@tonic-gate 	}
6507c478bd9Sstevel@tonic-gate 
6517c478bd9Sstevel@tonic-gate 	/* Accept only an ACK for the current serial number */
6527c478bd9Sstevel@tonic-gate 	*snp = ntohl(*snp);
6537c478bd9Sstevel@tonic-gate 	if (sctp->sctp_cxmit_list == NULL || *snp != (sctp->sctp_lcsn - 1)) {
6547c478bd9Sstevel@tonic-gate 		/* Need to send an abort */
6557c478bd9Sstevel@tonic-gate 		return;
6567c478bd9Sstevel@tonic-gate 	}
6577c478bd9Sstevel@tonic-gate 	sctp->sctp_cchunk_pend = 0;
6587c478bd9Sstevel@tonic-gate 	SCTP_FADDR_RC_TIMER_STOP(fp);
6597c478bd9Sstevel@tonic-gate 
6601d8c4025Svi 	mp = sctp->sctp_cxmit_list;
6611d8c4025Svi 	/*
6621d8c4025Svi 	 * We fill in the addresses here to update the clustering's state for
6631d8c4025Svi 	 * this assoc.
6641d8c4025Svi 	 */
6651d8c4025Svi 	if (mp != NULL && cl_sctp_assoc_change != NULL) {
6661d8c4025Svi 		ASSERT(mp->b_prev != NULL);
6671d8c4025Svi 		ainfo = (sctp_cl_ainfo_t *)mp->b_prev;
6681d8c4025Svi 		alist = ainfo->sctp_cl_alist;
6691d8c4025Svi 		dlist = ainfo->sctp_cl_dlist;
6701d8c4025Svi 		aptr = alist;
6711d8c4025Svi 		dptr = dlist;
6721d8c4025Svi 	}
6731d8c4025Svi 
6747c478bd9Sstevel@tonic-gate 	/*
6757c478bd9Sstevel@tonic-gate 	 * Pass explicit replies to callbacks:
6767c478bd9Sstevel@tonic-gate 	 * For each reply in the ACK, look up the corresponding
6777c478bd9Sstevel@tonic-gate 	 * original parameter in the request using the correlation
6787c478bd9Sstevel@tonic-gate 	 * ID, and pass it to the right callback.
6797c478bd9Sstevel@tonic-gate 	 */
6807c478bd9Sstevel@tonic-gate 	och = (sctp_chunk_hdr_t *)sctp->sctp_cxmit_list->b_rptr;
6817c478bd9Sstevel@tonic-gate 
6827c478bd9Sstevel@tonic-gate 	plen = ntohs(och->sch_len) - sizeof (*och) - sizeof (*idp);
6837c478bd9Sstevel@tonic-gate 	idp = (uint32_t *)(och + 1);
6847c478bd9Sstevel@tonic-gate 
6857c478bd9Sstevel@tonic-gate 	/* Get to the 1st ASCONF param, need to skip Address TLV parm */
6867c478bd9Sstevel@tonic-gate 	fph = (sctp_parm_hdr_t *)(idp + 1);
6877c478bd9Sstevel@tonic-gate 	plen -= ntohs(fph->sph_len);
6887c478bd9Sstevel@tonic-gate 	fph = (sctp_parm_hdr_t *)((char *)fph + ntohs(fph->sph_len));
6897c478bd9Sstevel@tonic-gate 	ph = (sctp_parm_hdr_t *)(snp + 1);
6907c478bd9Sstevel@tonic-gate 	while (rlen > 0) {
6917c478bd9Sstevel@tonic-gate 		/* Sanity checks */
6927c478bd9Sstevel@tonic-gate 		if (rlen < sizeof (*ph)) {
6937c478bd9Sstevel@tonic-gate 			break;
6947c478bd9Sstevel@tonic-gate 		}
6957c478bd9Sstevel@tonic-gate 		param_len = ntohs(ph->sph_len);
6967c478bd9Sstevel@tonic-gate 		if (param_len < sizeof (*ph) || param_len > rlen) {
6977c478bd9Sstevel@tonic-gate 			break;
6987c478bd9Sstevel@tonic-gate 		}
6997c478bd9Sstevel@tonic-gate 		idp = (uint32_t *)(ph + 1);
7007c478bd9Sstevel@tonic-gate 		oph = sctp_lookup_asconf_param(fph, *idp, plen);
7017c478bd9Sstevel@tonic-gate 		if (oph != NULL) {
7027c478bd9Sstevel@tonic-gate 			dp = sctp_lookup_asconf_dispatch(ntohs(oph->sph_type));
7037c478bd9Sstevel@tonic-gate 			ASSERT(dp);
7047c478bd9Sstevel@tonic-gate 			if (dp->asconf_ack) {
7051d8c4025Svi 				dp->asconf_ack(sctp, ph, oph, fp, &addr);
7067c478bd9Sstevel@tonic-gate 
7077c478bd9Sstevel@tonic-gate 				/* hack. see below */
7087c478bd9Sstevel@tonic-gate 				if (oph->sph_type == htons(PARM_ADD_IP) ||
7097c478bd9Sstevel@tonic-gate 				    oph->sph_type == htons(PARM_DEL_IP)) {
7107c478bd9Sstevel@tonic-gate 					redosrcs = 1;
7111d8c4025Svi 					/*
7121d8c4025Svi 					 * If the address was sucessfully
7131d8c4025Svi 					 * processed, add it to the add/delete
7141d8c4025Svi 					 * list to send to the clustering
7151d8c4025Svi 					 * module.
7161d8c4025Svi 					 */
7171d8c4025Svi 					if (cl_sctp_assoc_change != NULL &&
718a22dfb13SVenugopal Iyer 					    !SCTP_IS_ADDR_UNSPEC(
719a22dfb13SVenugopal Iyer 					    IN6_IS_ADDR_V4MAPPED(&addr),
720a22dfb13SVenugopal Iyer 					    addr)) {
7211d8c4025Svi 						if (oph->sph_type ==
7221d8c4025Svi 						    htons(PARM_ADD_IP)) {
7231d8c4025Svi 							bcopy(&addr, aptr,
7241d8c4025Svi 							    sizeof (addr));
7251d8c4025Svi 							aptr += sizeof (addr);
7261d8c4025Svi 							acount++;
7271d8c4025Svi 						} else {
7281d8c4025Svi 							bcopy(&addr, dptr,
7291d8c4025Svi 							    sizeof (addr));
7301d8c4025Svi 							dptr += sizeof (addr);
7311d8c4025Svi 							dcount++;
7321d8c4025Svi 						}
7331d8c4025Svi 					}
7347c478bd9Sstevel@tonic-gate 				}
7357c478bd9Sstevel@tonic-gate 			}
7367c478bd9Sstevel@tonic-gate 		}
7377c478bd9Sstevel@tonic-gate 
7387c478bd9Sstevel@tonic-gate 		ph = sctp_next_parm(ph, &rlen);
7397c478bd9Sstevel@tonic-gate 		if (ph == NULL)
7407c478bd9Sstevel@tonic-gate 			break;
7417c478bd9Sstevel@tonic-gate 	}
7427c478bd9Sstevel@tonic-gate 
7437c478bd9Sstevel@tonic-gate 	/*
7447c478bd9Sstevel@tonic-gate 	 * Pass implicit replies to callbacks:
7457c478bd9Sstevel@tonic-gate 	 * For each original request, look up its parameter
7467c478bd9Sstevel@tonic-gate 	 * in the ACK. If there is no corresponding reply,
7477c478bd9Sstevel@tonic-gate 	 * call the callback with a NULL parameter, indicating
7487c478bd9Sstevel@tonic-gate 	 * success.
7497c478bd9Sstevel@tonic-gate 	 */
7507c478bd9Sstevel@tonic-gate 	rlen = plen;
7517c478bd9Sstevel@tonic-gate 	plen = ntohs(ch->sch_len) - sizeof (*ch) - sizeof (*idp);
7527c478bd9Sstevel@tonic-gate 	oph = fph;
7537c478bd9Sstevel@tonic-gate 	fph = (sctp_parm_hdr_t *)((char *)ch + sizeof (sctp_chunk_hdr_t) +
7547c478bd9Sstevel@tonic-gate 	    sizeof (uint32_t));
7557c478bd9Sstevel@tonic-gate 	while (rlen > 0) {
7567c478bd9Sstevel@tonic-gate 		idp = (uint32_t *)(oph + 1);
7577c478bd9Sstevel@tonic-gate 		ph = sctp_lookup_asconf_param(fph, *idp, plen);
7587c478bd9Sstevel@tonic-gate 		if (ph == NULL) {
7597c478bd9Sstevel@tonic-gate 			dp = sctp_lookup_asconf_dispatch(ntohs(oph->sph_type));
7607c478bd9Sstevel@tonic-gate 			ASSERT(dp);
7617c478bd9Sstevel@tonic-gate 			if (dp->asconf_ack) {
7621d8c4025Svi 				dp->asconf_ack(sctp, NULL, oph, fp, &addr);
7637c478bd9Sstevel@tonic-gate 
7647c478bd9Sstevel@tonic-gate 				/* hack. see below */
7657c478bd9Sstevel@tonic-gate 				if (oph->sph_type == htons(PARM_ADD_IP) ||
7667c478bd9Sstevel@tonic-gate 				    oph->sph_type == htons(PARM_DEL_IP)) {
7677c478bd9Sstevel@tonic-gate 					redosrcs = 1;
7681d8c4025Svi 					/*
7691d8c4025Svi 					 * If the address was sucessfully
7701d8c4025Svi 					 * processed, add it to the add/delete
7711d8c4025Svi 					 * list to send to the clustering
7721d8c4025Svi 					 * module.
7731d8c4025Svi 					 */
7741d8c4025Svi 					if (cl_sctp_assoc_change != NULL &&
775a22dfb13SVenugopal Iyer 					    !SCTP_IS_ADDR_UNSPEC(
776a22dfb13SVenugopal Iyer 					    IN6_IS_ADDR_V4MAPPED(&addr),
777a22dfb13SVenugopal Iyer 					    addr)) {
7781d8c4025Svi 						if (oph->sph_type ==
7791d8c4025Svi 						    htons(PARM_ADD_IP)) {
7801d8c4025Svi 							bcopy(&addr, aptr,
7811d8c4025Svi 							    sizeof (addr));
7821d8c4025Svi 							aptr += sizeof (addr);
7831d8c4025Svi 							acount++;
7841d8c4025Svi 						} else {
7851d8c4025Svi 							bcopy(&addr, dptr,
7861d8c4025Svi 							    sizeof (addr));
7871d8c4025Svi 							dptr += sizeof (addr);
7881d8c4025Svi 							dcount++;
7891d8c4025Svi 						}
7901d8c4025Svi 					}
7917c478bd9Sstevel@tonic-gate 				}
7927c478bd9Sstevel@tonic-gate 			}
7937c478bd9Sstevel@tonic-gate 		}
7947c478bd9Sstevel@tonic-gate 		oph = sctp_next_parm(oph, &rlen);
7957c478bd9Sstevel@tonic-gate 		if (oph == NULL) {
7967c478bd9Sstevel@tonic-gate 			break;
7977c478bd9Sstevel@tonic-gate 		}
7987c478bd9Sstevel@tonic-gate 	}
7997c478bd9Sstevel@tonic-gate 
8007c478bd9Sstevel@tonic-gate 	/* We can now free up the first chunk in the cxmit list */
8017c478bd9Sstevel@tonic-gate 	sctp->sctp_cxmit_list = mp->b_cont;
8027c478bd9Sstevel@tonic-gate 	mp->b_cont = NULL;
8037c478bd9Sstevel@tonic-gate 
8047c478bd9Sstevel@tonic-gate 	fp = SCTP_CHUNK_DEST(mp);
8056be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	ASSERT(fp != NULL && fp->sf_suna >= MBLKL(mp));
8066be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	fp->sf_suna -= MBLKL(mp);
8071d8c4025Svi 
8081d8c4025Svi 	/*
8091d8c4025Svi 	 * Update clustering's state for this assoc. Note acount/dcount
8101d8c4025Svi 	 * could be zero (i.e. if the add/delete address(es) did not
8111d8c4025Svi 	 * succeed). Regardless, if the ?size is > 0, it is the clustering
8121d8c4025Svi 	 * module's responsibility to free the lists.
8131d8c4025Svi 	 */
8141d8c4025Svi 	if (cl_sctp_assoc_change != NULL) {
8151d8c4025Svi 		ASSERT(mp->b_prev != NULL);
8161d8c4025Svi 		mp->b_prev = NULL;
8171d8c4025Svi 		ainfo->sctp_cl_alist = NULL;
8181d8c4025Svi 		ainfo->sctp_cl_dlist = NULL;
819bd670b35SErik Nordmark 		(*cl_sctp_assoc_change)(sctp->sctp_connp->conn_family, alist,
8201d8c4025Svi 		    ainfo->sctp_cl_asize, acount, dlist, ainfo->sctp_cl_dsize,
8211d8c4025Svi 		    dcount, SCTP_CL_LADDR, (cl_sctp_handle_t)sctp);
8221d8c4025Svi 		/* alist and dlist will be freed by the clustering module */
8231d8c4025Svi 		ainfo->sctp_cl_asize = 0;
8241d8c4025Svi 		ainfo->sctp_cl_dsize = 0;
8251d8c4025Svi 		kmem_free(ainfo, sizeof (*ainfo));
8261d8c4025Svi 	}
8277c478bd9Sstevel@tonic-gate 	freeb(mp);
8287c478bd9Sstevel@tonic-gate 
8297c478bd9Sstevel@tonic-gate 	/* can now send the next control chunk */
8307c478bd9Sstevel@tonic-gate 	if (sctp->sctp_cxmit_list != NULL)
8317c478bd9Sstevel@tonic-gate 		sctp_wput_asconf(sctp, NULL);
8327c478bd9Sstevel@tonic-gate 
8337c478bd9Sstevel@tonic-gate 	/*
8347c478bd9Sstevel@tonic-gate 	 * If an add-ip or del-ip has completed (successfully or
8357c478bd9Sstevel@tonic-gate 	 * unsuccessfully), the pool of available source addresses
8367c478bd9Sstevel@tonic-gate 	 * may have changed, so we need to redo faddr source
8377c478bd9Sstevel@tonic-gate 	 * address selections. This is a bit of a hack since
8387c478bd9Sstevel@tonic-gate 	 * this really belongs in the add/del-ip code. However,
8397c478bd9Sstevel@tonic-gate 	 * that code consists of callbacks called for *each*
8407c478bd9Sstevel@tonic-gate 	 * add/del-ip parameter, and sctp_redo_faddr_srcs() is
8417c478bd9Sstevel@tonic-gate 	 * expensive enough that we really don't want to be
8427c478bd9Sstevel@tonic-gate 	 * doing it for each one. So we do it once here.
8437c478bd9Sstevel@tonic-gate 	 */
8447c478bd9Sstevel@tonic-gate 	if (redosrcs)
8457c478bd9Sstevel@tonic-gate 		sctp_redo_faddr_srcs(sctp);
8467c478bd9Sstevel@tonic-gate }
8477c478bd9Sstevel@tonic-gate 
8487c478bd9Sstevel@tonic-gate static void
sctp_rc_timer(sctp_t * sctp,sctp_faddr_t * fp)8497c478bd9Sstevel@tonic-gate sctp_rc_timer(sctp_t *sctp, sctp_faddr_t *fp)
8507c478bd9Sstevel@tonic-gate {
8517c478bd9Sstevel@tonic-gate #define	SCTP_CLR_SENT_FLAG(mp)	((mp)->b_flag &= ~SCTP_CHUNK_FLAG_SENT)
8527c478bd9Sstevel@tonic-gate 	sctp_faddr_t	*nfp;
8537c478bd9Sstevel@tonic-gate 	sctp_faddr_t	*ofp;
854f4b3ec61Sdh 	sctp_stack_t	*sctps = sctp->sctp_sctps;
8557c478bd9Sstevel@tonic-gate 
8567c478bd9Sstevel@tonic-gate 	ASSERT(fp != NULL);
8577c478bd9Sstevel@tonic-gate 
8586be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	fp->sf_rc_timer_running = 0;
8597c478bd9Sstevel@tonic-gate 
8607c478bd9Sstevel@tonic-gate 	if (sctp->sctp_state != SCTPS_ESTABLISHED ||
8617c478bd9Sstevel@tonic-gate 	    sctp->sctp_cxmit_list == NULL) {
8627c478bd9Sstevel@tonic-gate 		return;
8637c478bd9Sstevel@tonic-gate 	}
8647c478bd9Sstevel@tonic-gate 	/*
8657c478bd9Sstevel@tonic-gate 	 * Not a retransmission, this was deferred due to some error
8667c478bd9Sstevel@tonic-gate 	 * condition
8677c478bd9Sstevel@tonic-gate 	 */
8687c478bd9Sstevel@tonic-gate 	if (!SCTP_CHUNK_ISSENT(sctp->sctp_cxmit_list)) {
8697c478bd9Sstevel@tonic-gate 		sctp_wput_asconf(sctp, fp);
8707c478bd9Sstevel@tonic-gate 		return;
8717c478bd9Sstevel@tonic-gate 	}
8727c478bd9Sstevel@tonic-gate 	/*
8737c478bd9Sstevel@tonic-gate 	 * The sent flag indicates if the msg has been sent on this fp.
8747c478bd9Sstevel@tonic-gate 	 */
8757c478bd9Sstevel@tonic-gate 	SCTP_CLR_SENT_FLAG(sctp->sctp_cxmit_list);
8767c478bd9Sstevel@tonic-gate 	/* Retransmission */
8777c478bd9Sstevel@tonic-gate 	if (sctp->sctp_strikes >= sctp->sctp_pa_max_rxt) {
8787c478bd9Sstevel@tonic-gate 		/* time to give up */
8795dd46ab5SKacheong Poon 		SCTPS_BUMP_MIB(sctps, sctpAborted);
8807c478bd9Sstevel@tonic-gate 		sctp_assoc_event(sctp, SCTP_COMM_LOST, 0, NULL);
8817c478bd9Sstevel@tonic-gate 		sctp_clean_death(sctp, ETIMEDOUT);
8827c478bd9Sstevel@tonic-gate 		return;
8837c478bd9Sstevel@tonic-gate 	}
8846be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	if (fp->sf_strikes >= fp->sf_max_retr) {
8857c478bd9Sstevel@tonic-gate 		if (sctp_faddr_dead(sctp, fp, SCTP_FADDRS_DOWN) == -1)
8867c478bd9Sstevel@tonic-gate 			return;
8877c478bd9Sstevel@tonic-gate 	}
8887c478bd9Sstevel@tonic-gate 
8896be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	fp->sf_strikes++;
8907c478bd9Sstevel@tonic-gate 	sctp->sctp_strikes++;
891fd7b5aedSGeorge Shepherd 	SCTP_CALC_RXT(sctp, fp, sctp->sctp_rto_max);
8927c478bd9Sstevel@tonic-gate 
8937c478bd9Sstevel@tonic-gate 	nfp = sctp_rotate_faddr(sctp, fp);
8947c478bd9Sstevel@tonic-gate 	sctp->sctp_cchunk_pend = 0;
8957c478bd9Sstevel@tonic-gate 	ofp = SCTP_CHUNK_DEST(sctp->sctp_cxmit_list);
8967c478bd9Sstevel@tonic-gate 	SCTP_SET_CHUNK_DEST(sctp->sctp_cxmit_list, NULL);
8977c478bd9Sstevel@tonic-gate 	ASSERT(ofp != NULL && ofp == fp);
8986be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India 	ASSERT(ofp->sf_suna >= MBLKL(sctp->sctp_cxmit_list));
8997c478bd9Sstevel@tonic-gate 	/*
9007c478bd9Sstevel@tonic-gate 	 * Enter slow start for this destination.
9017c478bd9Sstevel@tonic-gate 	 * XXX anything in the data path that needs to be considered?
9027c478bd9Sstevel@tonic-gate 	 */
9036be61d4eSchandrasekar marimuthu - Sun Microsystems - Bangalore India