1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 
26 #include <sys/types.h>
27 #include <sys/systm.h>
28 #include <sys/stream.h>
29 #include <sys/cmn_err.h>
30 #include <sys/socket.h>
31 #include <sys/kmem.h>
32 #include <sys/strsubr.h>
33 #include <sys/strsun.h>
34 
35 #include <netinet/in.h>
36 #include <netinet/ip6.h>
37 #include <netinet/sctp.h>
38 
39 #include <inet/common.h>
40 #include <inet/ip.h>
41 #include <inet/ip6.h>
42 #include <inet/mib2.h>
43 #include <inet/ipclassifier.h>
44 #include "sctp_impl.h"
45 #include "sctp_asconf.h"
46 #include "sctp_addr.h"
47 
48 typedef struct sctp_asconf_s {
49 	mblk_t		*head;
50 	uint32_t 	cid;
51 } sctp_asconf_t;
52 
53 /*
54  * This is only used on a clustered node to maintain pre-allocated buffer info.
55  * before sending an ASCONF chunk. The reason for pre-allocation is we don't
56  * want to fail allocating memory when we get then ASCONF-ACK in order to
57  * update the clustering subsystem's state for this assoc.
58  */
59 typedef struct sctp_cl_ainfo_s {
60 	uchar_t	*sctp_cl_alist;
61 	size_t	sctp_cl_asize;
62 	uchar_t	*sctp_cl_dlist;
63 	size_t	sctp_cl_dsize;
64 } sctp_cl_ainfo_t;
65 
66 /*
67  * The ASCONF chunk per-parameter request interface. ph is the
68  * parameter header for the parameter in the request, and cid
69  * is the parameters correlation ID. cont should be set to 1
70  * if the ASCONF framework should continue processing request
71  * parameters following this one, or 0 if it should stop. If
72  * cont is -1, this indicates complete memory depletion, which
73  * will cause the ASCONF framework to abort building a reply. If
74  * act is 1, the callback should take whatever action it needs
75  * to fulfil this request. If act is 0, this request has already
76  * been processed, so the callback should only verify and pass
77  * back error parameters, and not take any action.
78  *
79  * The callback should return an mblk with any reply enclosed,
80  * with the correlation ID in the first four bytes of the
81  * message. A NULL return implies implicit success to the
82  * requestor.
83  */
84 typedef mblk_t *sctp_asconf_func_t(sctp_t *, sctp_parm_hdr_t *ph, uint32_t cid,
85     sctp_faddr_t *, int *cont, int act, in6_addr_t *addr);
86 
87 /*
88  * The ASCONF chunk per-parameter ACK interface. ph is the parameter
89  * header for the parameter returned in the ACK, and oph is the
90  * original parameter sent out in the ASCONF request.
91  * If the peer implicitly responded OK (by not including an
92  * explicit OK for the request), ph will be NULL.
93  * ph can also point to an Unrecognized Parameter parameter,
94  * in which case the peer did not understand the request
95  * parameter.
96  *
97  * ph and oph parameter headers are in host byte order. Encapsulated
98  * parameters will still be in network byte order.
99  */
100 typedef void sctp_asconf_ack_func_t(sctp_t *, sctp_parm_hdr_t *ph,
101     sctp_parm_hdr_t *oph, sctp_faddr_t *, in6_addr_t *addr);
102 
103 typedef struct {
104 	uint16_t id;
105 	sctp_asconf_func_t *asconf;
106 	sctp_asconf_ack_func_t *asconf_ack;
107 } dispatch_t;
108 
109 static sctp_asconf_func_t sctp_addip_req, sctp_setprim_req,
110     sctp_asconf_unrec_parm;
111 
112 static sctp_asconf_ack_func_t sctp_addip_ack, sctp_setprim_ack,
113     sctp_asconf_ack_unrec_parm;
114 
115 static const dispatch_t sctp_asconf_dispatch_tbl[] = {
116 /*	ID			ASCONF			ASCONF_ACK */
117 	{ PARM_ADD_IP,		sctp_addip_req,		sctp_addip_ack },
118 	{ PARM_DEL_IP,		sctp_addip_req,		sctp_addip_ack },
119 	{ PARM_SET_PRIMARY,	sctp_setprim_req,	sctp_setprim_ack }
120 };
121 
122 static const dispatch_t sctp_asconf_default_dispatch = {
123 	0, sctp_asconf_unrec_parm, sctp_asconf_ack_unrec_parm
124 };
125 
126 /*
127  * ASCONF framework
128  */
129 
130 static const dispatch_t *
131 sctp_lookup_asconf_dispatch(int id)
132 {
133 	int i;
134 
135 	for (i = 0; i < A_CNT(sctp_asconf_dispatch_tbl); i++) {
136 		if (sctp_asconf_dispatch_tbl[i].id == id) {
137 			return (sctp_asconf_dispatch_tbl + i);
138 		}
139 	}
140 
141 	return (&sctp_asconf_default_dispatch);
142 }
143 
144 /*
145  * Frees mp on failure
146  */
147 static mblk_t *
148 sctp_asconf_prepend_errwrap(mblk_t *mp, uint32_t cid)
149 {
150 	mblk_t		*wmp;
151 	sctp_parm_hdr_t	*wph;
152 
153 	/* Prepend a wrapper err cause ind param */
154 	wmp = allocb(sizeof (*wph) + sizeof (cid), BPRI_MED);
155 	if (wmp == NULL) {
156 		freemsg(mp);
157 		return (NULL);
158 	}
159 	wmp->b_wptr += sizeof (*wph) + sizeof (cid);
160 	wph = (sctp_parm_hdr_t *)wmp->b_rptr;
161 	wph->sph_type = htons(PARM_ERROR_IND);
162 	wph->sph_len = htons(msgdsize(mp) + sizeof (*wph) + sizeof (cid));
163 	bcopy(&cid, wph + 1, sizeof (uint32_t));
164 
165 	wmp->b_cont = mp;
166 	return (wmp);
167 }
168 
169 /*ARGSUSED*/
170 static mblk_t *
171 sctp_asconf_unrec_parm(sctp_t *sctp, sctp_parm_hdr_t *ph, uint32_t cid,
172     sctp_faddr_t *fp, int *cont, int act, in6_addr_t *addr)
173 {
174 	mblk_t *mp = NULL;
175 
176 	/* Unrecognized param; check the high order bits */
177 	if ((ph->sph_type & SCTP_UNREC_PARAM_MASK) ==
178 	    (SCTP_CONT_PROC_PARAMS | SCTP_REPORT_THIS_PARAM)) {
179 		/* report unrecognized param, and keep processing */
180 		sctp_add_unrec_parm(ph, &mp, B_FALSE);
181 		if (mp == NULL) {
182 			*cont = -1;
183 			return (NULL);
184 		}
185 		/* Prepend a the CID and a wrapper err cause ind param */
186 		mp = sctp_asconf_prepend_errwrap(mp, cid);
187 		if (mp == NULL) {
188 			*cont = -1;
189 			return (NULL);
190 		}
191 
192 		*cont = 1;
193 		return (mp);
194 	}
195 	if (ph->sph_type & SCTP_REPORT_THIS_PARAM) {
196 		/* Stop processing and drop; report unrecognized param */
197 		sctp_add_unrec_parm(ph, &mp, B_FALSE);
198 		if (mp == NULL) {
199 			*cont = -1;
200 			return (NULL);
201 		}
202 		/* Prepend a the CID and a wrapper err cause ind param */
203 		mp = sctp_asconf_prepend_errwrap(mp, cid);
204 		if (mp == NULL) {
205 			*cont = -1;
206 			return (NULL);
207 		}
208 
209 		*cont = 0;
210 		return (mp);
211 	}
212 	if (ph->sph_type & SCTP_CONT_PROC_PARAMS) {
213 		/* skip and continue processing */
214 		*cont = 1;
215 		return (NULL);
216 	}
217 
218 	/* 2 high bits are clear; stop processing and drop packet */
219 	*cont = 0;
220 	return (NULL);
221 }
222 
223 /*ARGSUSED*/
224 static void
225 sctp_asconf_ack_unrec_parm(sctp_t *sctp, sctp_parm_hdr_t *ph,
226     sctp_parm_hdr_t *oph, sctp_faddr_t *fp, in6_addr_t *laddr)
227 {
228 	ASSERT(ph);
229 	sctp_error_event(sctp, (sctp_chunk_hdr_t *)ph, B_TRUE);
230 }
231 
232 static void
233 sctp_asconf_init(sctp_asconf_t *asc)
234 {
235 	ASSERT(asc != NULL);
236 
237 	asc->head = NULL;
238 	asc->cid = 0;
239 }
240 
241 static int
242 sctp_asconf_add(sctp_asconf_t *asc, mblk_t *mp)
243 {
244 	uint32_t *cp;
245 
246 	/* XXX can't exceed MTU */
247 
248 	cp = (uint32_t *)(mp->b_rptr + sizeof (sctp_parm_hdr_t));
249 	*cp = asc->cid++;
250 
251 	if (asc->head == NULL)
252 		asc->head = mp;
253 	else
254 		linkb(asc->head, mp);
255 
256 	return (0);
257 }
258 
259 static void
260 sctp_asconf_destroy(sctp_asconf_t *asc)
261 {
262 	if (asc->head != NULL) {
263 		freemsg(asc->head);
264 		asc->head = NULL;
265 	}
266 	asc->cid = 0;
267 }
268 
269 static int
270 sctp_asconf_send(sctp_t *sctp, sctp_asconf_t *asc, sctp_faddr_t *fp,
271     sctp_cl_ainfo_t *ainfo)
272 {
273 	mblk_t			*mp, *nmp;
274 	sctp_chunk_hdr_t	*ch;
275 	boolean_t		isv4;
276 	size_t			msgsize;
277 
278 	ASSERT(asc != NULL && asc->head != NULL);
279 
280 	isv4 = (fp != NULL) ? fp->isv4 : sctp->sctp_current->isv4;
281 
282 	/* SCTP chunk header + Serial Number + Address Param TLV */
283 	msgsize = sizeof (*ch) + sizeof (uint32_t) +
284 	    (isv4 ? PARM_ADDR4_LEN : PARM_ADDR6_LEN);
285 
286 	mp = allocb(msgsize, BPRI_MED);
287 	if (mp == NULL)
288 		return (ENOMEM);
289 
290 	mp->b_wptr += msgsize;
291 	mp->b_cont = asc->head;
292 
293 	ch = (sctp_chunk_hdr_t *)mp->b_rptr;
294 	ch->sch_id = CHUNK_ASCONF;
295 	ch->sch_flags = 0;
296 	ch->sch_len = htons(msgdsize(mp));
297 
298 	nmp = msgpullup(mp, -1);
299 	if (nmp == NULL) {
300 		freeb(mp);
301 		return (ENOMEM);
302 	}
303 
304 	/*
305 	 * Stash the address list and the count so that when the operation
306 	 * completes, i.e. when as get an ACK, we can update the clustering's
307 	 * state for this association.
308 	 */
309 	if (ainfo != NULL) {
310 		ASSERT(cl_sctp_assoc_change != NULL);
311 		ASSERT(nmp->b_prev == NULL);
312 		nmp->b_prev = (mblk_t *)ainfo;
313 	}
314 	/* Clean up the temporary mblk chain */
315 	freemsg(mp);
316 	asc->head = NULL;
317 	asc->cid = 0;
318 
319 	/* Queue it ... */
320 	if (sctp->sctp_cxmit_list == NULL) {
321 		sctp->sctp_cxmit_list = nmp;
322 	} else {
323 		linkb(sctp->sctp_cxmit_list, nmp);
324 	}
325 
326 	BUMP_LOCAL(sctp->sctp_obchunks);
327 
328 	/* And try to send it. */
329 	sctp_wput_asconf(sctp, fp);
330 
331 	return (0);
332 }
333 
334 /*
335  * If the peer does not understand an ASCONF chunk, we simply
336  * clear out the cxmit_list, since we can send nothing further
337  * that the peer will understand.
338  *
339  * Assumes chunk length has already been checked.
340  */
341 /*ARGSUSED*/
342 void
343 sctp_asconf_free_cxmit(sctp_t *sctp, sctp_chunk_hdr_t *ch)
344 {
345 	mblk_t		*mp;
346 	mblk_t		*mp1;
347 	sctp_cl_ainfo_t	*ainfo;
348 
349 	if (sctp->sctp_cxmit_list == NULL) {
350 		/* Nothing pending */
351 		return;
352 	}
353 
354 	mp = sctp->sctp_cxmit_list;
355 	while (mp != NULL) {
356 		mp1 = mp->b_cont;
357 		mp->b_cont = NULL;
358 		if (mp->b_prev != NULL) {
359 			ainfo = (sctp_cl_ainfo_t *)mp->b_prev;
360 			mp->b_prev = NULL;
361 			kmem_free(ainfo->sctp_cl_alist, ainfo->sctp_cl_asize);
362 			kmem_free(ainfo->sctp_cl_dlist, ainfo->sctp_cl_dsize);
363 			kmem_free(ainfo, sizeof (*ainfo));
364 		}
365 		freeb(mp);
366 		mp = mp1;
367 	}
368 	sctp->sctp_cxmit_list = NULL;
369 }
370 
371 void
372 sctp_input_asconf(sctp_t *sctp, sctp_chunk_hdr_t *ch, sctp_faddr_t *fp)
373 {
374 	const dispatch_t	*dp;
375 	mblk_t			*hmp;
376 	mblk_t			*mp;
377 	uint32_t		*idp;
378 	uint32_t		*hidp;
379 	ssize_t			rlen;
380 	sctp_parm_hdr_t		*ph;
381 	sctp_chunk_hdr_t	*ach;
382 	int			cont;
383 	int			act;
384 	uint16_t		plen;
385 	uchar_t			*alist = NULL;
386 	size_t			asize = 0;
387 	uchar_t			*dlist = NULL;
388 	size_t			dsize = 0;
389 	uchar_t			*aptr = NULL;
390 	uchar_t			*dptr = NULL;
391 	int			acount = 0;
392 	int			dcount = 0;
393 	sctp_stack_t		*sctps = sctp->sctp_sctps;
394 
395 	ASSERT(ch->sch_id == CHUNK_ASCONF);
396 
397 	idp = (uint32_t *)(ch + 1);
398 	rlen = ntohs(ch->sch_len) - sizeof (*ch) - sizeof (*idp);
399 
400 	if (rlen < 0 || rlen < sizeof (*idp)) {
401 		/* nothing there; bail out */
402 		return;
403 	}
404 
405 	/* Check for duplicates */
406 	*idp = ntohl(*idp);
407 	if (*idp == (sctp->sctp_fcsn + 1)) {
408 		act = 1;
409 	} else if (*idp == sctp->sctp_fcsn) {
410 		act = 0;
411 	} else {
412 		/* stale or malicious packet; drop */
413 		return;
414 	}
415 
416 	/* Create the ASCONF_ACK header */
417 	hmp = sctp_make_mp(sctp, fp, sizeof (*ach) + sizeof (*idp));
418 	if (hmp == NULL) {
419 		/* Let the peer retransmit */
420 		SCTP_KSTAT(sctps, sctp_send_asconf_ack_failed);
421 		return;
422 	}
423 	ach = (sctp_chunk_hdr_t *)hmp->b_wptr;
424 	ach->sch_id = CHUNK_ASCONF_ACK;
425 	ach->sch_flags = 0;
426 	/* Set the length later */
427 	hidp = (uint32_t *)(ach + 1);
428 	*hidp = htonl(*idp);
429 	hmp->b_wptr = (uchar_t *)(hidp + 1);
430 
431 	/* Move to the Address Parameter */
432 	ph = (sctp_parm_hdr_t *)(idp + 1);
433 	if (rlen <= ntohs(ph->sph_len)) {
434 		freeb(hmp);
435 		return;
436 	}
437 
438 	/*
439 	 * We already have the association here, so this address parameter
440 	 * doesn't seem to be very useful, should we make sure this is part
441 	 * of the association and send an error, if not?
442 	 * Ignore it for now.
443 	 */
444 	rlen -= ntohs(ph->sph_len);
445 	ph = (sctp_parm_hdr_t *)((char *)ph + ntohs(ph->sph_len));
446 
447 	/*
448 	 * We need to pre-allocate buffer before processing the ASCONF
449 	 * chunk. We don't want to fail allocating buffers after processing
450 	 * the ASCONF chunk. So, we walk the list and get the number of
451 	 * addresses added and/or deleted.
452 	 */
453 	if (cl_sctp_assoc_change != NULL) {
454 		sctp_parm_hdr_t	*oph = ph;
455 		ssize_t		orlen = rlen;
456 
457 		/*
458 		 * This not very efficient, but there is no better way of
459 		 * doing it.  It should be fine since normally the param list
460 		 * will not be very long.
461 		 */
462 		while (orlen > 0) {
463 			/* Sanity checks */
464 			if (orlen < sizeof (*oph))
465 				break;
466 			plen = ntohs(oph->sph_len);
467 			if (plen < sizeof (*oph) || plen > orlen)
468 				break;
469 			if (oph->sph_type == htons(PARM_ADD_IP))
470 				acount++;
471 			if (oph->sph_type == htons(PARM_DEL_IP))
472 				dcount++;
473 			oph = sctp_next_parm(oph, &orlen);
474 			if (oph == NULL)
475 				break;
476 		}
477 		if (acount > 0 || dcount > 0) {
478 			if (acount > 0) {
479 				asize = sizeof (in6_addr_t) * acount;
480 				alist = kmem_alloc(asize, KM_NOSLEEP);
481 				if (alist == NULL) {
482 					freeb(hmp);
483 					SCTP_KSTAT(sctps, sctp_cl_assoc_change);
484 					return;
485 				}
486 			}
487 			if (dcount > 0) {
488 				dsize = sizeof (in6_addr_t) * dcount;
489 				dlist = kmem_alloc(dsize, KM_NOSLEEP);
490 				if (dlist == NULL) {
491 					if (acount > 0)
492 						kmem_free(alist, asize);
493 					freeb(hmp);
494 					SCTP_KSTAT(sctps, sctp_cl_assoc_change);
495 					return;
496 				}
497 			}
498 			aptr = alist;
499 			dptr = dlist;
500 			/*
501 			 * We will get the actual count when we process
502 			 * the chunk.
503 			 */
504 			acount = 0;
505 			dcount = 0;
506 		}
507 	}
508 	cont = 1;
509 	while (rlen > 0 && cont) {
510 		in6_addr_t	addr;
511 
512 		/* Sanity checks */
513 		if (rlen < sizeof (*ph))
514 			break;
515 		plen = ntohs(ph->sph_len);
516 		if (plen < sizeof (*ph) || plen > rlen) {
517 			break;
518 		}
519 		idp = (uint32_t *)(ph + 1);
520 		dp = sctp_lookup_asconf_dispatch(ntohs(ph->sph_type));
521 		ASSERT(dp);
522 		if (dp->asconf) {
523 			mp = dp->asconf(sctp, ph, *idp, fp, &cont, act, &addr);
524 			if (cont == -1) {
525 				/*
526 				 * Not even enough memory to create
527 				 * an out-of-resources error. Free
528 				 * everything and return; the peer
529 				 * should retransmit.
530 				 */
531 				freemsg(hmp);
532 				if (alist != NULL)
533 					kmem_free(alist, asize);
534 				if (dlist != NULL)
535 					kmem_free(dlist, dsize);
536 				return;
537 			}
538 			if (mp != NULL) {
539 				linkb(hmp, mp);
540 			} else if (act != 0) {
541 				/* update the add/delete list */
542 				if (cl_sctp_assoc_change != NULL) {
543 					if (ph->sph_type ==
544 					    htons(PARM_ADD_IP)) {
545 						ASSERT(alist != NULL);
546 						bcopy(&addr, aptr,
547 						    sizeof (addr));
548 						aptr += sizeof (addr);
549 						acount++;
550 					} else if (ph->sph_type ==
551 					    htons(PARM_DEL_IP)) {
552 						ASSERT(dlist != NULL);
553 						bcopy(&addr, dptr,
554 						    sizeof (addr));
555 						dptr += sizeof (addr);
556 						dcount++;
557 					}
558 				}
559 			}
560 		}
561 		ph = sctp_next_parm(ph, &rlen);
562 		if (ph == NULL)
563 			break;
564 	}
565 
566 	/*
567 	 * Update clustering's state for this assoc. Note acount/dcount
568 	 * could be zero (i.e. if the add/delete address(es) were not
569 	 * processed successfully). Regardless, if the ?size is > 0,
570 	 * it is the clustering module's responsibility to free the lists.
571 	 */
572 	if (cl_sctp_assoc_change != NULL) {
573 		(*cl_sctp_assoc_change)(sctp->sctp_connp->conn_family,
574 		    alist, asize,
575 		    acount, dlist, dsize, dcount, SCTP_CL_PADDR,
576 		    (cl_sctp_handle_t)sctp);
577 		/* alist and dlist will be freed by the clustering module */
578 	}
579 	/* Now that the params have been processed, increment the fcsn */
580 	if (act) {
581 		sctp->sctp_fcsn++;
582 	}
583 	BUMP_LOCAL(sctp->sctp_obchunks);
584 
585 	if (fp->isv4)
586 		ach->sch_len = htons(msgdsize(hmp) - sctp->sctp_hdr_len);
587 	else
588 		ach->sch_len = htons(msgdsize(hmp) - sctp->sctp_hdr6_len);
589 
590 	sctp_set_iplen(sctp, hmp, fp->ixa);
591 	(void) conn_ip_output(hmp, fp->ixa);
592 	BUMP_LOCAL(sctp->sctp_opkts);
593 	sctp_validate_peer(sctp);
594 }
595 
596 static sctp_parm_hdr_t *
597 sctp_lookup_asconf_param(sctp_parm_hdr_t *ph, uint32_t cid, ssize_t rlen)
598 {
599 	uint32_t *idp;
600 
601 	while (rlen > 0) {
602 		idp = (uint32_t *)(ph + 1);
603 		if (*idp == cid) {
604 			return (ph);
605 		}
606 		ph = sctp_next_parm(ph, &rlen);
607 		if (ph == NULL)
608 			break;
609 	}
610 	return (NULL);
611 }
612 
613 void
614 sctp_input_asconf_ack(sctp_t *sctp, sctp_chunk_hdr_t *ch, sctp_faddr_t *fp)
615 {
616 	const dispatch_t	*dp;
617 	uint32_t		*idp;
618 	uint32_t		*snp;
619 	ssize_t			rlen;
620 	ssize_t			plen;
621 	sctp_parm_hdr_t		*ph;
622 	sctp_parm_hdr_t		*oph;
623 	sctp_parm_hdr_t		*fph;
624 	mblk_t			*mp;
625 	sctp_chunk_hdr_t	*och;
626 	int			redosrcs = 0;
627 	uint16_t		param_len;
628 	uchar_t			*alist;
629 	uchar_t			*dlist;
630 	uint_t			acount = 0;
631 	uint_t			dcount = 0;
632 	uchar_t			*aptr;
633 	uchar_t			*dptr;
634 	sctp_cl_ainfo_t		*ainfo;
635 	in6_addr_t		addr;
636 
637 	ASSERT(ch->sch_id == CHUNK_ASCONF_ACK);
638 
639 	snp = (uint32_t *)(ch + 1);
640 	rlen = ntohs(ch->sch_len) - sizeof (*ch) - sizeof (*snp);
641 	if (rlen < 0) {
642 		return;
643 	}
644 
645 	/* Accept only an ACK for the current serial number */
646 	*snp = ntohl(*snp);
647 	if (sctp->sctp_cxmit_list == NULL || *snp != (sctp->sctp_lcsn - 1)) {
648 		/* Need to send an abort */
649 		return;
650 	}
651 	sctp->sctp_cchunk_pend = 0;
652 	SCTP_FADDR_RC_TIMER_STOP(fp);
653 
654 	mp = sctp->sctp_cxmit_list;
655 	/*
656 	 * We fill in the addresses here to update the clustering's state for
657 	 * this assoc.
658 	 */
659 	if (mp != NULL && cl_sctp_assoc_change != NULL) {
660 		ASSERT(mp->b_prev != NULL);
661 		ainfo = (sctp_cl_ainfo_t *)mp->b_prev;
662 		alist = ainfo->sctp_cl_alist;
663 		dlist = ainfo->sctp_cl_dlist;
664 		aptr = alist;
665 		dptr = dlist;
666 	}
667 
668 	/*
669 	 * Pass explicit replies to callbacks:
670 	 * For each reply in the ACK, look up the corresponding
671 	 * original parameter in the request using the correlation
672 	 * ID, and pass it to the right callback.
673 	 */
674 	och = (sctp_chunk_hdr_t *)sctp->sctp_cxmit_list->b_rptr;
675 
676 	plen = ntohs(och->sch_len) - sizeof (*och) - sizeof (*idp);
677 	idp = (uint32_t *)(och + 1);
678 
679 	/* Get to the 1st ASCONF param, need to skip Address TLV parm */
680 	fph = (sctp_parm_hdr_t *)(idp + 1);
681 	plen -= ntohs(fph->sph_len);
682 	fph = (sctp_parm_hdr_t *)((char *)fph + ntohs(fph->sph_len));
683 	ph = (sctp_parm_hdr_t *)(snp + 1);
684 	while (rlen > 0) {
685 		/* Sanity checks */
686 		if (rlen < sizeof (*ph)) {
687 			break;
688 		}
689 		param_len = ntohs(ph->sph_len);
690 		if (param_len < sizeof (*ph) || param_len > rlen) {
691 			break;
692 		}
693 		idp = (uint32_t *)(ph + 1);
694 		oph = sctp_lookup_asconf_param(fph, *idp, plen);
695 		if (oph != NULL) {
696 			dp = sctp_lookup_asconf_dispatch(ntohs(oph->sph_type));
697 			ASSERT(dp);
698 			if (dp->asconf_ack) {
699 				dp->asconf_ack(sctp, ph, oph, fp, &addr);
700 
701 				/* hack. see below */
702 				if (oph->sph_type == htons(PARM_ADD_IP) ||
703 				    oph->sph_type == htons(PARM_DEL_IP)) {
704 					redosrcs = 1;
705 					/*
706 					 * If the address was sucessfully
707 					 * processed, add it to the add/delete
708 					 * list to send to the clustering
709 					 * module.
710 					 */
711 					if (cl_sctp_assoc_change != NULL &&
712 					    !SCTP_IS_ADDR_UNSPEC(
713 					    IN6_IS_ADDR_V4MAPPED(&addr),
714 					    addr)) {
715 						if (oph->sph_type ==
716 						    htons(PARM_ADD_IP)) {
717 							bcopy(&addr, aptr,
718 							    sizeof (addr));
719 							aptr += sizeof (addr);
720 							acount++;
721 						} else {
722 							bcopy(&addr, dptr,
723 							    sizeof (addr));
724 							dptr += sizeof (addr);
725 							dcount++;
726 						}
727 					}
728 				}
729 			}
730 		}
731 
732 		ph = sctp_next_parm(ph, &rlen);
733 		if (ph == NULL)
734 			break;
735 	}
736 
737 	/*
738 	 * Pass implicit replies to callbacks:
739 	 * For each original request, look up its parameter
740 	 * in the ACK. If there is no corresponding reply,
741 	 * call the callback with a NULL parameter, indicating
742 	 * success.
743 	 */
744 	rlen = plen;
745 	plen = ntohs(ch->sch_len) - sizeof (*ch) - sizeof (*idp);
746 	oph = fph;
747 	fph = (sctp_parm_hdr_t *)((char *)ch + sizeof (sctp_chunk_hdr_t) +
748 	    sizeof (uint32_t));
749 	while (rlen > 0) {
750 		idp = (uint32_t *)(oph + 1);
751 		ph = sctp_lookup_asconf_param(fph, *idp, plen);
752 		if (ph == NULL) {
753 			dp = sctp_lookup_asconf_dispatch(ntohs(oph->sph_type));
754 			ASSERT(dp);
755 			if (dp->asconf_ack) {
756 				dp->asconf_ack(sctp, NULL, oph, fp, &addr);
757 
758 				/* hack. see below */
759 				if (oph->sph_type == htons(PARM_ADD_IP) ||
760 				    oph->sph_type == htons(PARM_DEL_IP)) {
761 					redosrcs = 1;
762 					/*
763 					 * If the address was sucessfully
764 					 * processed, add it to the add/delete
765 					 * list to send to the clustering
766 					 * module.
767 					 */
768 					if (cl_sctp_assoc_change != NULL &&
769 					    !SCTP_IS_ADDR_UNSPEC(
770 					    IN6_IS_ADDR_V4MAPPED(&addr),
771 					    addr)) {
772 						if (oph->sph_type ==
773 						    htons(PARM_ADD_IP)) {
774 							bcopy(&addr, aptr,
775 							    sizeof (addr));
776 							aptr += sizeof (addr);
777 							acount++;
778 						} else {
779 							bcopy(&addr, dptr,
780 							    sizeof (addr));
781 							dptr += sizeof (addr);
782 							dcount++;
783 						}
784 					}
785 				}
786 			}
787 		}
788 		oph = sctp_next_parm(oph, &rlen);
789 		if (oph == NULL) {
790 			break;
791 		}
792 	}
793 
794 	/* We can now free up the first chunk in the cxmit list */
795 	sctp->sctp_cxmit_list = mp->b_cont;
796 	mp->b_cont = NULL;
797 
798 	fp = SCTP_CHUNK_DEST(mp);
799 	ASSERT(fp != NULL && fp->suna >= MBLKL(mp));
800 	fp->suna -= MBLKL(mp);
801 
802 	/*
803 	 * Update clustering's state for this assoc. Note acount/dcount
804 	 * could be zero (i.e. if the add/delete address(es) did not
805 	 * succeed). Regardless, if the ?size is > 0, it is the clustering
806 	 * module's responsibility to free the lists.
807 	 */
808 	if (cl_sctp_assoc_change != NULL) {
809 		ASSERT(mp->b_prev != NULL);
810 		mp->b_prev = NULL;
811 		ainfo->sctp_cl_alist = NULL;
812 		ainfo->sctp_cl_dlist = NULL;
813 		(*cl_sctp_assoc_change)(sctp->sctp_connp->conn_family, alist,
814 		    ainfo->sctp_cl_asize, acount, dlist, ainfo->sctp_cl_dsize,
815 		    dcount, SCTP_CL_LADDR, (cl_sctp_handle_t)sctp);
816 		/* alist and dlist will be freed by the clustering module */
817 		ainfo->sctp_cl_asize = 0;
818 		ainfo->sctp_cl_dsize = 0;
819 		kmem_free(ainfo, sizeof (*ainfo));
820 	}
821 	freeb(mp);
822 
823 	/* can now send the next control chunk */
824 	if (sctp->sctp_cxmit_list != NULL)
825 		sctp_wput_asconf(sctp, NULL);
826 
827 	/*
828 	 * If an add-ip or del-ip has completed (successfully or
829 	 * unsuccessfully), the pool of available source addresses
830 	 * may have changed, so we need to redo faddr source
831 	 * address selections. This is a bit of a hack since
832 	 * this really belongs in the add/del-ip code. However,
833 	 * that code consists of callbacks called for *each*
834 	 * add/del-ip parameter, and sctp_redo_faddr_srcs() is
835 	 * expensive enough that we really don't want to be
836 	 * doing it for each one. So we do it once here.
837 	 */
838 	if (redosrcs)
839 		sctp_redo_faddr_srcs(sctp);
840 }
841 
842 static void
843 sctp_rc_timer(sctp_t *sctp, sctp_faddr_t *fp)
844 {
845 #define	SCTP_CLR_SENT_FLAG(mp)	((mp)->b_flag &= ~SCTP_CHUNK_FLAG_SENT)
846 	sctp_faddr_t	*nfp;
847 	sctp_faddr_t	*ofp;
848 	sctp_stack_t	*sctps = sctp->sctp_sctps;
849 
850 	ASSERT(fp != NULL);
851 
852 	fp->rc_timer_running = 0;
853 
854 	if (sctp->sctp_state != SCTPS_ESTABLISHED ||
855 	    sctp->sctp_cxmit_list == NULL) {
856 		return;
857 	}
858 	/*
859 	 * Not a retransmission, this was deferred due to some error
860 	 * condition
861 	 */
862 	if (!SCTP_CHUNK_ISSENT(sctp->sctp_cxmit_list)) {
863 		sctp_wput_asconf(sctp, fp);
864 		return;
865 	}
866 	/*
867 	 * The sent flag indicates if the msg has been sent on this fp.
868 	 */
869 	SCTP_CLR_SENT_FLAG(sctp->sctp_cxmit_list);
870 	/* Retransmission */
871 	if (sctp->sctp_strikes >= sctp->sctp_pa_max_rxt) {
872 		/* time to give up */
873 		SCTPS_BUMP_MIB(sctps, sctpAborted);
874 		sctp_assoc_event(sctp, SCTP_COMM_LOST, 0, NULL);
875 		sctp_clean_death(sctp, ETIMEDOUT);
876 		return;
877 	}
878 	if (fp->strikes >= fp->max_retr) {
879 		if (sctp_faddr_dead(sctp, fp, SCTP_FADDRS_DOWN) == -1)
880 			return;
881 	}
882 
883 	fp->strikes++;
884 	sctp->sctp_strikes++;
885 	SCTP_CALC_RXT(sctp, fp, sctp->sctp_rto_max);
886 
887 	nfp = sctp_rotate_faddr(sctp, fp);
888 	sctp->sctp_cchunk_pend = 0;
889 	ofp = SCTP_CHUNK_DEST(sctp->sctp_cxmit_list);
890 	SCTP_SET_CHUNK_DEST(sctp->sctp_cxmit_list, NULL);
891 	ASSERT(ofp != NULL && ofp == fp);
892 	ASSERT(ofp->suna >= MBLKL(sctp->sctp_cxmit_list));
893 	/*
894 	 * Enter slow start for this destination.
895 	 * XXX anything in the data path that needs to be considered?
896 	 */
897 	ofp->ssthresh = ofp->cwnd / 2;
898 	if (ofp->ssthresh < 2 * ofp->sfa_pmss)
899 		ofp->ssthresh = 2 * ofp->sfa_pmss;
900 	ofp->cwnd = ofp->sfa_pmss;
901 	ofp->pba = 0;
902 	ofp->suna -= MBLKL(sctp->sctp_cxmit_list);
903 	/*
904 	 * The rexmit flags is used to determine if a serial number needs to
905 	 * be assigned or not, so once set we leave it there.
906 	 */
907 	if (!SCTP_CHUNK_WANT_REXMIT(sctp->sctp_cxmit_list))
908 		SCTP_CHUNK_REXMIT(sctp, sctp->sctp_cxmit_list);
909 	sctp_wput_asconf(sctp, nfp);
910 #undef	SCTP_CLR_SENT_FLAG
911 }
912 
913 void
914 sctp_wput_asconf(sctp_t *sctp, sctp_faddr_t *fp)
915 {
916 #define	SCTP_SET_SENT_FLAG(mp)	((mp)->b_flag = SCTP_CHUNK_FLAG_SENT)
917 
918 	mblk_t 			*mp;
919 	mblk_t			*ipmp;
920 	uint32_t 		*snp;
921 	sctp_parm_hdr_t		*ph;
922 	boolean_t		isv4;
923 	sctp_stack_t		*sctps = sctp->sctp_sctps;
924 	boolean_t		saddr_set;
925 
926 	if (sctp->sctp_cchunk_pend || sctp->sctp_cxmit_list == NULL ||
927 	    /* Queue it for later transmission if not yet established */
928 	    sctp->sctp_state < SCTPS_ESTABLISHED) {
929 		ip2dbg(("sctp_wput_asconf: cchunk pending? (%d) or null "\
930 		    "sctp_cxmit_list? (%s) or incorrect state? (%x)\n",
931 		    sctp->sctp_cchunk_pend, sctp->sctp_cxmit_list == NULL ?
932 		    "yes" : "no", sctp->sctp_state));
933 		return;
934 	}
935 
936 	if (fp == NULL)
937 		fp = sctp->sctp_current;
938 
939 	/* OK to send */
940 	ipmp = sctp_make_mp(sctp, fp, 0);
941 	if (ipmp == NULL) {
942 		SCTP_FADDR_RC_TIMER_RESTART(sctp, fp, fp->rto);
943 		SCTP_KSTAT(sctps, sctp_send_asconf_failed);
944 		return;
945 	}
946 	mp = sctp->sctp_cxmit_list;
947 	/* Fill in the mandatory  Address Parameter TLV */
948 	isv4 = (fp != NULL) ? fp->isv4 : sctp->sctp_current->isv4;
949 	ph = (sctp_parm_hdr_t *)(mp->b_rptr + sizeof (sctp_chunk_hdr_t) +
950 	    sizeof (uint32_t));
951 	if (isv4) {
952 		ipha_t		*ipha = (ipha_t *)ipmp->b_rptr;
953 		in6_addr_t	ipaddr;
954 		ipaddr_t	addr4;
955 
956 		ph->sph_type = htons(PARM_ADDR4);
957 		ph->sph_len = htons(PARM_ADDR4_LEN);
958 		if (ipha->ipha_src != INADDR_ANY) {
959 			bcopy(&ipha->ipha_src, ph + 1, IP_ADDR_LEN);
960 		} else {
961 			ipaddr = sctp_get_valid_addr(sctp, B_FALSE, &saddr_set);
962 			/*
963 			 * All the addresses are down.
964 			 * Maybe we might have better luck next time.
965 			 */
966 			if (!saddr_set) {
967 				SCTP_FADDR_RC_TIMER_RESTART(sctp, fp, fp->rto);
968 				freeb(ipmp);
969 				return;
970 			}
971 			IN6_V4MAPPED_TO_IPADDR(&ipaddr, addr4);
972 			bcopy(&addr4, ph + 1, IP_ADDR_LEN);
973 		}
974 	} else {
975 		ip6_t		*ip6 = (ip6_t *)ipmp->b_rptr;
976 		in6_addr_t	ipaddr;
977 
978 		ph->sph_type = htons(PARM_ADDR6);
979 		ph->sph_len = htons(PARM_ADDR6_LEN);
980 		if (!IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_src)) {
981 			bcopy(&ip6->ip6_src, ph + 1, IPV6_ADDR_LEN);
982 		} else {
983 			ipaddr = sctp_get_valid_addr(sctp, B_TRUE, &saddr_set);
984 			/*
985 			 * All the addresses are down.
986 			 * Maybe we might have better luck next time.
987 			 */
988 			if (!saddr_set) {
989 				SCTP_FADDR_RC_TIMER_RESTART(sctp, fp, fp->rto);
990 				freeb(ipmp);
991 				return;
992 			}
993 			bcopy(&ipaddr, ph + 1, IPV6_ADDR_LEN);
994 		}
995 	}
996 
997 	/* Don't exceed CWND */
998 	if ((MBLKL(mp) > (fp->cwnd - fp->suna)) ||
999 	    ((mp = dupb(sctp->sctp_cxmit_list)) == NULL)) {
1000 		SCTP_FADDR_RC_TIMER_RESTART(sctp, fp, fp->rto);
1001 		freeb(ipmp);
1002 		return;
1003 	}
1004 
1005 	/* Set the serial number now, if sending for the first time */
1006 	if (!SCTP_CHUNK_WANT_REXMIT(mp)) {
1007 		snp = (uint32_t *)(mp->b_rptr + sizeof (sctp_chunk_hdr_t));
1008 		*snp = htonl(sctp->sctp_lcsn++);
1009 	}
1010 	SCTP_CHUNK_CLEAR_FLAGS(mp);
1011 	fp->suna += MBLKL(mp);
1012 	/* Attach the header and send the chunk */
1013 	ipmp->b_cont = mp;
1014 	sctp->sctp_cchunk_pend = 1;
1015 
1016 	SCTP_SET_SENT_FLAG(sctp->sctp_cxmit_list);
1017 	SCTP_SET_CHUNK_DEST(sctp->sctp_cxmit_list, fp);
1018 	sctp_set_iplen(sctp, ipmp, fp->ixa);
1019 	(void) conn_ip_output(ipmp, fp->ixa);
1020 	BUMP_LOCAL(sctp->sctp_opkts);
1021 	SCTP_FADDR_RC_TIMER_RESTART(sctp, fp, fp->rto);
1022 #undef	SCTP_SET_SENT_FLAG
1023 }
1024 
1025 /*
1026  * Generate ASCONF error param, include errph, if present.
1027  */
1028 static mblk_t *
1029 sctp_asconf_adderr(int err, sctp_parm_hdr_t *errph, uint32_t cid)
1030 {
1031 	mblk_t		*mp;
1032 	sctp_parm_hdr_t	*eph;
1033 	sctp_parm_hdr_t	*wph;
1034 	size_t		len;
1035 	size_t		elen = 0;
1036 
1037 	len = sizeof (*wph) + sizeof (*eph) + sizeof (cid);
1038 	if (errph != NULL) {
1039 		elen = ntohs(errph->sph_len);
1040 		len += elen;
1041 	}
1042 	mp = allocb(len, BPRI_MED);
1043 	if (mp == NULL) {
1044 		return (NULL);
1045 	}
1046 	wph = (sctp_parm_hdr_t *)mp->b_rptr;
1047 	/* error cause wrapper */
1048 	wph->sph_type = htons(PARM_ERROR_IND);
1049 	wph->sph_len = htons(len);
1050 	bcopy(&cid, wph + 1, sizeof (uint32_t));
1051 
1052 	/* error cause */
1053 	eph = (sctp_parm_hdr_t *)((char *)wph + sizeof (sctp_parm_hdr_t) +
1054 	    sizeof (cid));
1055 	eph->sph_type = htons(err);
1056 	eph->sph_len = htons(len - sizeof (*wph) - sizeof (cid));
1057 	mp->b_wptr = (uchar_t *)(eph + 1);
1058 
1059 	/* details */
1060 	if (elen > 0) {
1061 		bcopy(errph, mp->b_wptr, elen);
1062 		mp->b_wptr += elen;
1063 	}
1064 	return (mp);
1065 }
1066 
1067 static mblk_t *
1068 sctp_check_addip_addr(sctp_parm_hdr_t *ph, sctp_parm_hdr_t *oph, int *cont,
1069     uint32_t cid, in6_addr_t *raddr)
1070 {
1071 	uint16_t	atype;
1072 	uint16_t	alen;
1073 	mblk_t		*mp;
1074 	in6_addr_t	addr;
1075 	ipaddr_t	*addr4;
1076 
1077 	atype = ntohs(ph->sph_type);
1078 	alen = ntohs(ph->sph_len);
1079 
1080 	if (atype != PARM_ADDR4 && atype != PARM_ADDR6) {
1081 		mp = sctp_asconf_adderr(SCTP_ERR_BAD_MANDPARM, oph, cid);
1082 		if (mp == NULL) {
1083 			*cont = -1;
1084 		}
1085 		return (mp);
1086 	}
1087 	if ((atype == PARM_ADDR4 && alen < PARM_ADDR4_LEN) ||
1088 	    (atype == PARM_ADDR6 && alen < PARM_ADDR6_LEN)) {
1089 		mp = sctp_asconf_adderr(SCTP_ERR_BAD_MANDPARM, oph, cid);
1090 		if (mp == NULL) {
1091 			*cont = -1;
1092 		}
1093 		return (mp);
1094 	}
1095 
1096 	/* Address parameter is present; extract and screen it */
1097 	if (atype == PARM_ADDR4) {
1098 		addr4 = (ipaddr_t *)(ph + 1);
1099 		IN6_IPADDR_TO_V4MAPPED(*addr4, &addr);
1100 
1101 		/* screen XXX loopback to scoping */
1102 		if (*addr4 == 0 || *addr4 == INADDR_BROADCAST ||
1103 		    *addr4 == htonl(INADDR_LOOPBACK) || CLASSD(*addr4)) {
1104 			dprint(1, ("addip: addr not unicast: %x:%x:%x:%x\n",
1105 			    SCTP_PRINTADDR(addr)));
1106 			mp = sctp_asconf_adderr(SCTP_ERR_BAD_MANDPARM, oph,
1107 			    cid);
1108 			if (mp == NULL) {
1109 				*cont = -1;
1110 			}
1111 			return (mp);
1112 		}
1113 		/*
1114 		 * XXX also need to check for subnet
1115 		 * broadcasts. This should probably
1116 		 * wait until we have full access
1117 		 * to the ILL tables.
1118 		 */
1119 
1120 	} else {
1121 		bcopy(ph + 1, &addr, sizeof (addr));
1122 
1123 		/* screen XXX loopback to scoping */
1124 		if (IN6_IS_ADDR_LINKLOCAL(&addr) ||
1125 		    IN6_IS_ADDR_MULTICAST(&addr) ||
1126 		    IN6_IS_ADDR_LOOPBACK(&addr)) {
1127 			dprint(1, ("addip: addr not unicast: %x:%x:%x:%x\n",
1128 			    SCTP_PRINTADDR(addr)));
1129 			mp = sctp_asconf_adderr(SCTP_ERR_BAD_MANDPARM, oph,
1130 			    cid);
1131 			if (mp == NULL) {
1132 				*cont = -1;
1133 			}
1134 			return (mp);
1135 		}
1136 
1137 	}
1138 
1139 	/* OK */
1140 	*raddr = addr;
1141 	return (NULL);
1142 }
1143 
1144 /*
1145  * Handles both add and delete address requests.
1146  */
1147 static mblk_t *
1148 sctp_addip_req(sctp_t *sctp, sctp_parm_hdr_t *ph, uint32_t cid,
1149     sctp_faddr_t *fp, int *cont, int act, in6_addr_t *raddr)
1150 {
1151 	in6_addr_t	addr;
1152 	uint16_t	type;
1153 	mblk_t		*mp;
1154 	sctp_faddr_t	*nfp;
1155 	sctp_parm_hdr_t	*oph = ph;
1156 	int		err;
1157 	sctp_stack_t	*sctps = sctp->sctp_sctps;
1158 
1159 	*cont = 1;
1160 
1161 	/* Send back an authorization error if addip is disabled */
1162 	if (!sctps->sctps_addip_enabled) {
1163 		err = SCTP_ERR_UNAUTHORIZED;
1164 		goto error_handler;
1165 	}
1166 	/* Check input */
1167 	if (ntohs(ph->sph_len) < (sizeof (*ph) * 2)) {
1168 		err = SCTP_ERR_BAD_MANDPARM;
1169 		goto error_handler;
1170 	}
1171 
1172 	type = ntohs(ph->sph_type);
1173 	ph = (sctp_parm_hdr_t *)((char *)ph + sizeof (sctp_parm_hdr_t) +
1174 	    sizeof (cid));
1175 	mp = sctp_check_addip_addr(ph, oph, cont, cid, &addr);
1176 	if (mp != NULL)
1177 		return (mp);
1178 	if (raddr != NULL)
1179 		*raddr = addr;
1180 	if (type == PARM_ADD_IP) {
1181 		if (sctp_lookup_faddr(sctp, &addr) != NULL) {
1182 			/* Address is already part of association */
1183 			dprint(1, ("addip: addr already here: %x:%x:%x:%x\n",
1184 			    SCTP_PRINTADDR(addr)));
1185 			err = SCTP_ERR_BAD_MANDPARM;
1186 			goto error_handler;
1187 		}
1188 
1189 		if (!act) {
1190 			return (NULL);
1191 		}
1192 		/* Add the new address */
1193 		mutex_enter(&sctp->sctp_conn_tfp->tf_lock);
1194 		err = sctp_add_faddr(sctp, &addr, KM_NOSLEEP, B_FALSE);
1195 		mutex_exit(&sctp->sctp_conn_tfp->tf_lock);
1196 		if (err == ENOMEM) {
1197 			/* no memory */
1198 			*cont = -1;
1199 			return (NULL);
1200 		}
1201 		if (err != 0) {
1202 			err = SCTP_ERR_BAD_MANDPARM;
1203 			goto error_handler;
1204 		}
1205 		sctp_intf_event(sctp, addr, SCTP_ADDR_ADDED, 0);
1206 	} else if (type == PARM_DEL_IP) {
1207 		nfp = sctp_lookup_faddr(sctp, &addr);
1208 		if (nfp == NULL) {
1209 			/*
1210 			 * Peer is trying to delete an address that is not
1211 			 * part of the association.
1212 			 */
1213 			dprint(1, ("delip: addr not here: %x:%x:%x:%x\n",
1214 			    SCTP_PRINTADDR(addr)));
1215 			err = SCTP_ERR_BAD_MANDPARM;
1216 			goto error_handler;
1217 		}
1218 		if (sctp->sctp_faddrs == nfp && nfp->next == NULL) {
1219 			/* Peer is trying to delete last address */
1220 			dprint(1, ("delip: del last addr: %x:%x:%x:%x\n",
1221 			    SCTP_PRINTADDR(addr)));
1222 			err = SCTP_ERR_DEL_LAST_ADDR;
1223 			goto error_handler;
1224 		}
1225 		if (nfp == fp) {
1226 			/* Peer is trying to delete source address */
1227 			dprint(1, ("delip: del src addr: %x:%x:%x:%x\n",
1228 			    SCTP_PRINTADDR(addr)));
1229 			err = SCTP_ERR_DEL_SRC_ADDR;
1230 			goto error_handler;
1231 		}
1232 		if (!act) {
1233 			return (NULL);
1234 		}
1235 
1236 		sctp_unlink_faddr(sctp, nfp);
1237 		/* Update all references to the deleted faddr */
1238 		if (sctp->sctp_primary == nfp) {
1239 			sctp->sctp_primary = fp;
1240 		}
1241 		if (sctp->sctp_current == nfp) {
1242 			sctp_set_faddr_current(sctp, fp);
1243 		}
1244 		if (sctp->sctp_lastdata == nfp) {
1245 			sctp->sctp_lastdata = fp;
1246 		}
1247 		if (sctp->sctp_shutdown_faddr == nfp) {
1248 			sctp->sctp_shutdown_faddr = nfp;
1249 		}
1250 		if (sctp->sctp_lastfaddr == nfp) {
1251 			for (fp = sctp->sctp_faddrs; fp->next; fp = fp->next)
1252 				;
1253 			sctp->sctp_lastfaddr = fp;
1254 		}
1255 		sctp_intf_event(sctp, addr, SCTP_ADDR_REMOVED, 0);
1256 	} else {
1257 		ASSERT(0);
1258 	}
1259 
1260 	/* Successful, don't need to return anything. */
1261 	return (NULL);
1262 
1263 error_handler:
1264 	mp = sctp_asconf_adderr(err, oph, cid);
1265 	if (mp == NULL)
1266 		*cont = -1;
1267 	return (mp);
1268 }
1269 
1270 /*
1271  * Handles both add and delete IP ACKs.
1272  */
1273 /*ARGSUSED*/
1274 static void
1275 sctp_addip_ack(sctp_t *sctp, sctp_parm_hdr_t *ph, sctp_parm_hdr_t *oph,
1276     sctp_faddr_t *fp, in6_addr_t *laddr)
1277 {
1278 	in6_addr_t		addr;
1279 	sctp_saddr_ipif_t	*sp;
1280 	ipaddr_t		*addr4;
1281 	boolean_t		backout = B_FALSE;
1282 	uint16_t		type;
1283 	uint32_t		*cid;
1284 
1285 	/* could be an ASSERT */
1286 	if (laddr != NULL)
1287 		IN6_IPADDR_TO_V4MAPPED(0, laddr);
1288 
1289 	/* If the peer doesn't understand Add-IP, remember it */
1290 	if (ph != NULL && ph->sph_type == htons(PARM_UNRECOGNIZED)) {
1291 		sctp->sctp_understands_addip = B_FALSE;
1292 		backout = B_TRUE;
1293 	}
1294 
1295 	/*
1296 	 * If OK, continue with the add / delete action, otherwise
1297 	 * back out the action.
1298 	 */
1299 	if (ph != NULL && ph->sph_type != htons(PARM_SUCCESS)) {
1300 		backout = B_TRUE;
1301 		sctp_error_event(sctp, (sctp_chunk_hdr_t *)ph, B_TRUE);
1302 	}
1303 
1304 	type = ntohs(oph->sph_type);
1305 	cid = (uint32_t *)(oph + 1);
1306 	oph = (sctp_parm_hdr_t *)(cid + 1);
1307 	if (oph->sph_type == htons(PARM_ADDR4)) {
1308 		addr4 = (ipaddr_t *)(oph + 1);
1309 		IN6_IPADDR_TO_V4MAPPED(*addr4, &addr);
1310 	} else {
1311 		bcopy(oph + 1, &addr, sizeof (addr));
1312 	}
1313 
1314 	/* Signifies that the address was sucessfully processed */
1315 	if (!backout && laddr != NULL)
1316 		*laddr = addr;
1317 
1318 	sp = sctp_saddr_lookup(sctp, &addr, 0);
1319 	ASSERT(sp != NULL);
1320 
1321 	if (type == PARM_ADD_IP) {
1322 		if (backout) {
1323 			sctp_del_saddr(sctp, sp);
1324 		} else {
1325 			sp->saddr_ipif_dontsrc = 0;
1326 		}
1327 	} else if (type == PARM_DEL_IP) {
1328 		if (backout) {
1329 			sp->saddr_ipif_delete_pending = 0;
1330 			sp->saddr_ipif_dontsrc = 0;
1331 		} else {
1332 			sctp_del_saddr(sctp, sp);
1333 		}
1334 	} else {
1335 		/* Must be either PARM_ADD_IP or PARM_DEL_IP */
1336 		ASSERT(0);
1337 	}
1338 }
1339 
1340 /*ARGSUSED*/
1341 static mblk_t *
1342 sctp_setprim_req(sctp_t *sctp, sctp_parm_hdr_t *ph, uint32_t cid,
1343     sctp_faddr_t *fp, int *cont, int act, in6_addr_t *raddr)
1344 {
1345 	mblk_t *mp;
1346 	sctp_parm_hdr_t *oph;
1347 	sctp_faddr_t *nfp;
1348 	in6_addr_t addr;
1349 
1350 	*cont = 1;
1351 
1352 	/* Does the peer understand ASCONF and Add-IP? */
1353 	if (!sctp->sctp_understands_asconf || !sctp->sctp_understands_addip) {
1354 		mp = sctp_asconf_adderr(SCTP_ERR_UNAUTHORIZED, ph, cid);
1355 		if (mp == NULL) {
1356 			*cont = -1;
1357 		}
1358 		return (mp);
1359 	}
1360 
1361 	/* Check input */
1362 	if (ntohs(ph->sph_len) < (sizeof (*ph) * 2)) {
1363 		mp = sctp_asconf_adderr(SCTP_ERR_BAD_MANDPARM, ph, cid);
1364 		if (mp == NULL) {
1365 			*cont = -1;
1366 		}
1367 		return (mp);
1368 	}
1369 
1370 	oph = ph;
1371 	ph = (sctp_parm_hdr_t *)((char *)ph + sizeof (sctp_parm_hdr_t) +
1372 	    sizeof (cid));
1373 	mp = sctp_check_addip_addr(ph, oph, cont, cid, &addr);
1374 	if (mp != NULL) {
1375 		return (mp);
1376 	}
1377 
1378 	nfp = sctp_lookup_faddr(sctp, &addr);
1379 	if (nfp == NULL) {
1380 		/*
1381 		 * Peer is trying to set an address that is not
1382 		 * part of the association.
1383 		 */
1384 		dprint(1, ("setprim: addr not here: %x:%x:%x:%x\n",
1385 		    SCTP_PRINTADDR(addr)));
1386 		mp = sctp_asconf_adderr(SCTP_ERR_BAD_MANDPARM, oph, cid);
1387 		if (mp == NULL) {
1388 			*cont = -1;
1389 		}
1390 		return (mp);
1391 	}
1392 
1393 	sctp_intf_event(sctp, addr, SCTP_ADDR_MADE_PRIM, 0);
1394 	sctp->sctp_primary = nfp;
1395 	if (nfp->state != SCTP_FADDRS_ALIVE || nfp == sctp->sctp_current) {
1396 		return (NULL);
1397 	}
1398 	sctp_set_faddr_current(sctp, nfp);
1399 	return (NULL);
1400 }
1401 
1402 /*ARGSUSED*/
1403 static void
1404 sctp_setprim_ack(sctp_t *sctp, sctp_parm_hdr_t *ph, sctp_parm_hdr_t *oph,
1405     sctp_faddr_t *fp, in6_addr_t *laddr)
1406 {
1407 	if (ph != NULL && ph->sph_type != htons(PARM_SUCCESS)) {
1408 		/* If the peer doesn't understand Add-IP, remember it */
1409 		if (ph->sph_type == htons(PARM_UNRECOGNIZED)) {
1410 			sctp->sctp_understands_addip = B_FALSE;
1411 		}
1412 		sctp_error_event(sctp, (sctp_chunk_hdr_t *)ph, B_TRUE);
1413 	}
1414 
1415 	/* On success we do nothing */
1416 }
1417 
1418 int
1419 sctp_add_ip(sctp_t *sctp, const void *addrs, uint32_t cnt)
1420 {
1421 	struct sockaddr_in	*sin4;
1422 	struct sockaddr_in6	*sin6;
1423 	mblk_t			*mp;
1424 	int			error = 0;
1425 	int			i;
1426 	sctp_addip4_t		*ad4;
1427 	sctp_addip6_t		*ad6;
1428 	sctp_asconf_t		asc[1];
1429 	uint16_t		type = htons(PARM_ADD_IP);
1430 	boolean_t		v4mapped = B_FALSE;
1431 	sctp_cl_ainfo_t		*ainfo = NULL;
1432 	conn_t			*connp = sctp->sctp_connp;
1433 
1434 	/* Does the peer understand ASCONF and Add-IP? */
1435 	if (!sctp->sctp_understands_asconf || !sctp->sctp_understands_addip)
1436 		return (EOPNOTSUPP);
1437 
1438 	/*
1439 	 * On a clustered node, we need to pass this list when
1440 	 * we get an ASCONF-ACK. We only pre-allocate memory for the
1441 	 * list, but fill in the addresses when it is processed
1442 	 * successfully after we get an ASCONF-ACK.
1443 	 */
1444 	if (cl_sctp_assoc_change != NULL) {
1445 		ainfo = kmem_zalloc(sizeof (*ainfo), KM_SLEEP);
1446 		/*
1447 		 * Reserve space for the list of new addresses
1448 		 */
1449 		ainfo->sctp_cl_asize = sizeof (in6_addr_t) * cnt;
1450 		ainfo->sctp_cl_alist = kmem_alloc(ainfo->sctp_cl_asize,
1451 		    KM_SLEEP);
1452 	}
1453 
1454 	sctp_asconf_init(asc);
1455 
1456 	/*
1457 	 * Screen addresses:
1458 	 * If adding:
1459 	 *   o Must not already be a part of the association
1460 	 *   o Must be AF_INET or AF_INET6
1461 	 *   o XXX Must be valid source address for this node
1462 	 *   o Must be unicast
1463 	 *   o XXX Must fit scoping rules
1464 	 * If deleting:
1465 	 *   o Must be part of the association
1466 	 */
1467 	for (i = 0; i < cnt; i++) {
1468 		switch (connp->conn_family) {
1469 		case AF_INET:
1470 			sin4 = (struct sockaddr_in *)addrs + i;
1471 			v4mapped = B_TRUE;
1472 			break;
1473 
1474 		case AF_INET6:
1475 			sin6 = (struct sockaddr_in6 *)addrs + i;
1476 			break;
1477 		}
1478 
1479 		if (v4mapped) {
1480 			mp = allocb(sizeof (*ad4), BPRI_MED);
1481 			if (mp == NULL) {
1482 				error = ENOMEM;
1483 				goto fail;
1484 			}
1485 			mp->b_wptr += sizeof (*ad4);
1486 			ad4 = (sctp_addip4_t *)mp->b_rptr;
1487 			ad4->sad4_addip_ph.sph_type = type;
1488 			ad4->sad4_addip_ph.sph_len =
1489 			    htons(sizeof (sctp_parm_hdr_t) +
1490 			    PARM_ADDR4_LEN + sizeof (ad4->asconf_req_cid));
1491 			ad4->sad4_addr4_ph.sph_type = htons(PARM_ADDR4);
1492 			ad4->sad4_addr4_ph.sph_len = htons(PARM_ADDR4_LEN);
1493 			ad4->sad4_addr = sin4->sin_addr.s_addr;
1494 		} else {
1495 			mp = allocb(sizeof (*ad6), BPRI_MED);
1496 			if (mp == NULL) {
1497 				error = ENOMEM;
1498 				goto fail;
1499 			}
1500 			mp->b_wptr += sizeof (*ad6);
1501 			ad6 = (sctp_addip6_t *)mp->b_rptr;
1502 			ad6->sad6_addip_ph.sph_type = type;
1503 			ad6->sad6_addip_ph.sph_len =
1504 			    htons(sizeof (sctp_parm_hdr_t) +
1505 			    PARM_ADDR6_LEN + sizeof (ad6->asconf_req_cid));
1506 			ad6->sad6_addr6_ph.sph_type = htons(PARM_ADDR6);
1507 			ad6->sad6_addr6_ph.sph_len = htons(PARM_ADDR6_LEN);
1508 			ad6->sad6_addr = sin6->sin6_addr;
1509 		}
1510 		error = sctp_asconf_add(asc, mp);
1511 		if (error != 0)
1512 			goto fail;
1513 	}
1514 	error = sctp_asconf_send(sctp, asc, sctp->sctp_current, ainfo);
1515 	if (error != 0)
1516 		goto fail;
1517 
1518 	return (0);
1519 
1520 fail:
1521 	if (ainfo != NULL) {
1522 		kmem_free(ainfo->sctp_cl_alist, ainfo->sctp_cl_asize);
1523 		ainfo->sctp_cl_asize = 0;
1524 		kmem_free(ainfo, sizeof (*ainfo));
1525 	}
1526 	sctp_asconf_destroy(asc);
1527 	return (error);
1528 }
1529 
1530 int
1531 sctp_del_ip(sctp_t *sctp, const void *addrs, uint32_t cnt, uchar_t *ulist,
1532     size_t usize)
1533 {
1534 	struct sockaddr_in	*sin4;
1535 	struct sockaddr_in6	*sin6;
1536 	mblk_t			*mp;
1537 	int			error = 0;
1538 	int			i;
1539 	int			addrcnt = 0;
1540 	sctp_addip4_t		*ad4;
1541 	sctp_addip6_t		*ad6;
1542 	sctp_asconf_t		asc[1];
1543 	sctp_saddr_ipif_t	*nsp;
1544 	uint16_t		type = htons(PARM_DEL_IP);
1545 	boolean_t		v4mapped = B_FALSE;
1546 	in6_addr_t		addr;
1547 	boolean_t		asconf = B_TRUE;
1548 	uint_t			ifindex;
1549 	sctp_cl_ainfo_t		*ainfo = NULL;
1550 	uchar_t			*p = ulist;
1551 	boolean_t		check_lport = B_FALSE;
1552 	sctp_stack_t		*sctps = sctp->sctp_sctps;
1553 	conn_t			*connp = sctp->sctp_connp;
1554 
1555 	/* Does the peer understand ASCONF and Add-IP? */
1556 	if (sctp->sctp_state <= SCTPS_LISTEN || !sctps->sctps_addip_enabled ||
1557 	    !sctp->sctp_understands_asconf || !sctp->sctp_understands_addip) {
1558 		asconf = B_FALSE;
1559 	}
1560 
1561 	if (sctp->sctp_state > SCTPS_BOUND)
1562 		check_lport = B_TRUE;
1563 
1564 	if (asconf) {
1565 		/*
1566 		 * On a clustered node, we need to pass this list when
1567 		 * we get an ASCONF-ACK. We only pre-allocate memory for the
1568 		 * list, but fill in the addresses when it is processed
1569 		 * successfully after we get an ASCONF-ACK.
1570 		 */
1571 		if (cl_sctp_assoc_change != NULL) {
1572 			ainfo = kmem_alloc(sizeof (*ainfo), KM_SLEEP);
1573 			ainfo->sctp_cl_dsize = sizeof (in6_addr_t) * cnt;
1574 			ainfo->sctp_cl_dlist = kmem_alloc(ainfo->sctp_cl_dsize,
1575 			    KM_SLEEP);
1576 		}
1577 		sctp_asconf_init(asc);
1578 	}
1579 	/*
1580 	 * Screen addresses:
1581 	 * If adding:
1582 	 *   o Must not already be a part of the association
1583 	 *   o Must be AF_INET or AF_INET6
1584 	 *   o XXX Must be valid source address for this node
1585 	 *   o Must be unicast
1586 	 *   o XXX Must fit scoping rules
1587 	 * If deleting:
1588 	 *   o Must be part of the association
1589 	 */
1590 	for (i = 0; i < cnt; i++) {
1591 		ifindex = 0;
1592 
1593 		switch (connp->conn_family) {
1594 		case AF_INET:
1595 			sin4 = (struct sockaddr_in *)addrs + i;
1596 			if (check_lport &&
1597 			    sin4->sin_port != connp->conn_lport) {
1598 				error = EINVAL;
1599 				goto fail;
1600 			}
1601 			v4mapped = B_TRUE;
1602 			IN6_IPADDR_TO_V4MAPPED(sin4->sin_addr.s_addr, &addr);
1603 			break;
1604 
1605 		case AF_INET6:
1606 			sin6 = (struct sockaddr_in6 *)addrs + i;
1607 			if (check_lport &&
1608 			    sin6->sin6_port != connp->conn_lport) {
1609 				error = EINVAL;
1610 				goto fail;
1611 			}
1612 			addr = sin6->sin6_addr;
1613 			ifindex = sin6->sin6_scope_id;
1614 			break;
1615 		}
1616 		nsp = sctp_saddr_lookup(sctp, &addr, ifindex);
1617 		if (nsp == NULL) {
1618 			error = EADDRNOTAVAIL;
1619 			goto fail;
1620 		}
1621 
1622 		/* Collect the list of addresses, if required */
1623 		if (usize >= sizeof (addr)) {
1624 			bcopy(&addr, p, sizeof (addr));
1625 			p += sizeof (addr);
1626 			usize -= sizeof (addr);
1627 		}
1628 		if (!asconf)
1629 			continue;
1630 
1631 		nsp->saddr_ipif_delete_pending = 1;
1632 		nsp->saddr_ipif_dontsrc = 1;
1633 		addrcnt++;
1634 		if (v4mapped) {
1635 			mp = allocb(sizeof (*ad4), BPRI_MED);
1636 			if (mp == NULL) {
1637 				error = ENOMEM;
1638 				goto fail;
1639 			}
1640 			mp->b_wptr += sizeof (*ad4);
1641 			ad4 = (sctp_addip4_t *)mp->b_rptr;
1642 			ad4->sad4_addip_ph.sph_type = type;
1643 			ad4->sad4_addip_ph.sph_len =
1644 			    htons(sizeof (sctp_parm_hdr_t) +
1645 			    PARM_ADDR4_LEN + sizeof (ad4->asconf_req_cid));
1646 			ad4->sad4_addr4_ph.sph_type = htons(PARM_ADDR4);
1647 			ad4->sad4_addr4_ph.sph_len = htons(PARM_ADDR4_LEN);
1648 			ad4->sad4_addr = sin4->sin_addr.s_addr;
1649 		} else {
1650 			mp = allocb(sizeof (*ad6), BPRI_MED);
1651 			if (mp == NULL) {
1652 				error = ENOMEM;
1653 				goto fail;
1654 			}
1655 			mp->b_wptr += sizeof (*ad6);
1656 			ad6 = (sctp_addip6_t *)mp->b_rptr;
1657 			ad6->sad6_addip_ph.sph_type = type;
1658 			ad6->sad6_addip_ph.sph_len =
1659 			    htons(sizeof (sctp_parm_hdr_t) + PARM_ADDR6_LEN +
1660 			    sizeof (ad6->asconf_req_cid));
1661 			ad6->sad6_addr6_ph.sph_type = htons(PARM_ADDR6);
1662 			ad6->sad6_addr6_ph.sph_len = htons(PARM_ADDR6_LEN);
1663 			ad6->sad6_addr = addr;
1664 		}
1665 
1666 		error = sctp_asconf_add(asc, mp);
1667 		if (error != 0)
1668 			goto fail;
1669 	}
1670 
1671 	if (!asconf) {
1672 		sctp_del_saddr_list(sctp, addrs, cnt, B_FALSE);
1673 		return (0);
1674 	}
1675 	error = sctp_asconf_send(sctp, asc, sctp->sctp_current, ainfo);
1676 	if (error != 0)
1677 		goto fail;
1678 	sctp_redo_faddr_srcs(sctp);
1679 	return (0);
1680 
1681 fail:
1682 	if (ainfo != NULL) {
1683 		kmem_free(ainfo->sctp_cl_dlist, ainfo->sctp_cl_dsize);
1684 		ainfo->sctp_cl_dsize = 0;
1685 		kmem_free(ainfo, sizeof (*ainfo));
1686 	}
1687 	if (!asconf)
1688 		return (error);
1689 	for (i = 0; i < addrcnt; i++) {
1690 		ifindex = 0;
1691 
1692 		switch (connp->conn_family) {
1693 		case AF_INET:
1694 			sin4 = (struct sockaddr_in *)addrs + i;
1695 			IN6_INADDR_TO_V4MAPPED(&(sin4->sin_addr), &addr);
1696 			break;
1697 		case AF_INET6:
1698 			sin6 = (struct sockaddr_in6 *)addrs + i;
1699 			addr = sin6->sin6_addr;
1700 			ifindex = sin6->sin6_scope_id;
1701 			break;
1702 		}
1703 		nsp = sctp_saddr_lookup(sctp, &addr, ifindex);
1704 		ASSERT(nsp != NULL);
1705 		nsp->saddr_ipif_delete_pending = 0;
1706 		nsp->saddr_ipif_dontsrc = 0;
1707 	}
1708 	sctp_asconf_destroy(asc);
1709 
1710 	return (error);
1711 }
1712 
1713 int
1714 sctp_set_peerprim(sctp_t *sctp, const void *inp)
1715 {
1716 	const struct sctp_setprim	*prim = inp;
1717 	const struct sockaddr_storage	*ss;
1718 	struct sockaddr_in *sin;
1719 	struct sockaddr_in6 *sin6;
1720 	in6_addr_t addr;
1721 	mblk_t *mp;
1722 	sctp_saddr_ipif_t *sp;
1723 	sctp_addip4_t *ad4;
1724 	sctp_addip6_t *ad6;
1725 	sctp_asconf_t asc[1];
1726 	int error = 0;
1727 	uint_t	ifindex = 0;
1728 
1729 	/* Does the peer understand ASCONF and Add-IP? */
1730 	if (!sctp->sctp_understands_asconf || !sctp->sctp_understands_addip) {
1731 		return (EOPNOTSUPP);
1732 	}
1733 
1734 	/* Don't do anything if we are not connected */
1735 	if (sctp->sctp_state != SCTPS_ESTABLISHED)
1736 		return (EINVAL);
1737 
1738 	ss = &prim->ssp_addr;
1739 	sin = NULL;
1740 	sin6 = NULL;
1741 	if (ss->ss_family == AF_INET) {
1742 		sin = (struct sockaddr_in *)ss;
1743 		IN6_IPADDR_TO_V4MAPPED(sin->sin_addr.s_addr, &addr);
1744 	} else if (ss->ss_family == AF_INET6) {
1745 		sin6 = (struct sockaddr_in6 *)ss;
1746 		addr = sin6->sin6_addr;
1747 		ifindex = sin6->sin6_scope_id;
1748 	} else {
1749 		return (EAFNOSUPPORT);
1750 	}
1751 	sp = sctp_saddr_lookup(sctp, &addr, ifindex);
1752 	if (sp == NULL)
1753 		return (EADDRNOTAVAIL);
1754 	sctp_asconf_init(asc);
1755 	if (sin) {
1756 		mp = allocb(sizeof (*ad4), BPRI_MED);
1757 		if (mp == NULL) {
1758 			error = ENOMEM;
1759 			goto fail;
1760 		}
1761 		mp->b_wptr += sizeof (*ad4);
1762 		ad4 = (sctp_addip4_t *)mp->b_rptr;
1763 		ad4->sad4_addip_ph.sph_type = htons(PARM_SET_PRIMARY);
1764 		ad4->sad4_addip_ph.sph_len = htons(sizeof (sctp_parm_hdr_t) +
1765 		    PARM_ADDR4_LEN + sizeof (ad4->asconf_req_cid));
1766 		ad4->sad4_addr4_ph.sph_type = htons(PARM_ADDR4);
1767 		ad4->sad4_addr4_ph.sph_len = htons(PARM_ADDR4_LEN);
1768 		ad4->sad4_addr = sin->sin_addr.s_addr;
1769 	} else {
1770 		mp = allocb(sizeof (*ad6), BPRI_MED);
1771 		if (mp == NULL) {
1772 			error = ENOMEM;
1773 			goto fail;
1774 		}
1775 		mp->b_wptr += sizeof (*ad6);
1776 		ad6 = (sctp_addip6_t *)mp->b_rptr;
1777 		ad6->sad6_addip_ph.sph_type = htons(PARM_SET_PRIMARY);
1778 		ad6->sad6_addip_ph.sph_len = htons(sizeof (sctp_parm_hdr_t) +
1779 		    PARM_ADDR6_LEN + sizeof (ad6->asconf_req_cid));
1780 		ad6->sad6_addr6_ph.sph_type = htons(PARM_ADDR6);
1781 		ad6->sad6_addr6_ph.sph_len = htons(PARM_ADDR6_LEN);
1782 		ad6->sad6_addr = sin6->sin6_addr;
1783 	}
1784 
1785 	error = sctp_asconf_add(asc, mp);
1786 	if (error != 0) {
1787 		goto fail;
1788 	}
1789 
1790 	error = sctp_asconf_send(sctp, asc, sctp->sctp_current, NULL);
1791 	if (error == 0) {
1792 		return (0);
1793 	}
1794 
1795 fail:
1796 	sctp_asconf_destroy(asc);
1797 	return (error);
1798 }
1799