2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
5 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
6 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * a) Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
14 * b) Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the distribution.
18 * c) Neither the name of Cisco Systems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32 * THE POSSIBILITY OF SUCH DAMAGE.
35 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
38 #include <netinet/sctp_os.h>
39 #include <netinet/sctp_var.h>
40 #include <netinet/sctp_sysctl.h>
41 #include <netinet/sctp_pcb.h>
42 #include <netinet/sctp_header.h>
43 #include <netinet/sctputil.h>
44 #include <netinet/sctp_output.h>
45 #include <netinet/sctp_asconf.h>
46 #include <netinet/sctp_timer.h>
50 * SCTP_DEBUG_ASCONF1: protocol info, general info and errors
51 * SCTP_DEBUG_ASCONF2: detailed info
58 * An ASCONF parameter queue exists per asoc which holds the pending address
59 * operations. Lists are updated upon receipt of ASCONF-ACK.
61 * A restricted_addrs list exists per assoc to hold local addresses that are
62 * not (yet) usable by the assoc as a source address. These addresses are
63 * either pending an ASCONF operation (and exist on the ASCONF parameter
64 * queue), or they are permanently restricted (the peer has returned an
65 * ERROR indication to an ASCONF(ADD), or the peer does not support ASCONF).
67 * Deleted addresses are always immediately removed from the lists as they will
68 * (shortly) no longer exist in the kernel. We send ASCONFs as a courtesy,
73 * ASCONF parameter processing.
74 * response_required: set if a reply is required (eg. SUCCESS_REPORT).
75 * returns a mbuf to an "error" response parameter or NULL/"success" if ok.
76 * FIX: allocating this many mbufs on the fly is pretty inefficient...
79 sctp_asconf_success_response(uint32_t id)
81 struct mbuf *m_reply = NULL;
82 struct sctp_asconf_paramhdr *aph;
84 m_reply = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_paramhdr),
85 0, M_NOWAIT, 1, MT_DATA);
86 if (m_reply == NULL) {
87 SCTPDBG(SCTP_DEBUG_ASCONF1,
88 "asconf_success_response: couldn't get mbuf!\n");
91 aph = mtod(m_reply, struct sctp_asconf_paramhdr *);
92 aph->correlation_id = id;
93 aph->ph.param_type = htons(SCTP_SUCCESS_REPORT);
94 aph->ph.param_length = sizeof(struct sctp_asconf_paramhdr);
95 SCTP_BUF_LEN(m_reply) = aph->ph.param_length;
96 aph->ph.param_length = htons(aph->ph.param_length);
102 sctp_asconf_error_response(uint32_t id, uint16_t cause, uint8_t *error_tlv,
105 struct mbuf *m_reply = NULL;
106 struct sctp_asconf_paramhdr *aph;
107 struct sctp_error_cause *error;
109 uint16_t i, param_length, cause_length, padding_length;
112 if (error_tlv == NULL) {
115 cause_length = sizeof(struct sctp_error_cause) + tlv_length;
116 param_length = sizeof(struct sctp_asconf_paramhdr) + cause_length;
117 padding_length = tlv_length % 4;
118 if (padding_length != 0) {
119 padding_length = 4 - padding_length;
121 buf_len = param_length + padding_length;
122 if (buf_len > MLEN) {
123 SCTPDBG(SCTP_DEBUG_ASCONF1,
124 "asconf_error_response: tlv_length (%xh) too big\n",
128 m_reply = sctp_get_mbuf_for_msg(buf_len, 0, M_NOWAIT, 1, MT_DATA);
129 if (m_reply == NULL) {
130 SCTPDBG(SCTP_DEBUG_ASCONF1,
131 "asconf_error_response: couldn't get mbuf!\n");
134 aph = mtod(m_reply, struct sctp_asconf_paramhdr *);
135 aph->ph.param_type = htons(SCTP_ERROR_CAUSE_IND);
136 aph->ph.param_length = htons(param_length);
137 aph->correlation_id = id;
138 error = (struct sctp_error_cause *)(aph + 1);
139 error->code = htons(cause);
140 error->length = htons(cause_length);
141 if (error_tlv != NULL) {
142 tlv = (uint8_t *)(error + 1);
143 memcpy(tlv, error_tlv, tlv_length);
144 for (i = 0; i < padding_length; i++) {
145 tlv[tlv_length + i] = 0;
148 SCTP_BUF_LEN(m_reply) = buf_len;
153 sctp_process_asconf_add_ip(struct sockaddr *src, struct sctp_asconf_paramhdr *aph,
154 struct sctp_tcb *stcb, int send_hb, int response_required)
156 struct sctp_nets *net;
157 struct mbuf *m_reply = NULL;
158 union sctp_sockstore store;
159 struct sctp_paramhdr *ph;
160 uint16_t param_type, aparam_length;
161 #if defined(INET) || defined(INET6)
162 uint16_t param_length;
165 int zero_address = 0;
168 struct sockaddr_in *sin;
169 struct sctp_ipv4addr_param *v4addr;
172 struct sockaddr_in6 *sin6;
173 struct sctp_ipv6addr_param *v6addr;
176 aparam_length = ntohs(aph->ph.param_length);
177 if (aparam_length < sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_paramhdr)) {
180 ph = (struct sctp_paramhdr *)(aph + 1);
181 param_type = ntohs(ph->param_type);
182 #if defined(INET) || defined(INET6)
183 param_length = ntohs(ph->param_length);
184 if (param_length + sizeof(struct sctp_asconf_paramhdr) != aparam_length) {
189 switch (param_type) {
191 case SCTP_IPV4_ADDRESS:
192 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
193 /* invalid param size */
196 v4addr = (struct sctp_ipv4addr_param *)ph;
198 memset(sin, 0, sizeof(*sin));
199 sin->sin_family = AF_INET;
200 sin->sin_len = sizeof(struct sockaddr_in);
201 sin->sin_port = stcb->rport;
202 sin->sin_addr.s_addr = v4addr->addr;
203 if ((sin->sin_addr.s_addr == INADDR_BROADCAST) ||
204 IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) {
207 if (sin->sin_addr.s_addr == INADDR_ANY)
209 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_add_ip: adding ");
210 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
214 case SCTP_IPV6_ADDRESS:
215 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
216 /* invalid param size */
219 v6addr = (struct sctp_ipv6addr_param *)ph;
221 memset(sin6, 0, sizeof(*sin6));
222 sin6->sin6_family = AF_INET6;
223 sin6->sin6_len = sizeof(struct sockaddr_in6);
224 sin6->sin6_port = stcb->rport;
225 memcpy((caddr_t)&sin6->sin6_addr, v6addr->addr,
226 sizeof(struct in6_addr));
227 if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
230 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
232 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_add_ip: adding ");
233 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
237 m_reply = sctp_asconf_error_response(aph->correlation_id,
238 SCTP_CAUSE_INVALID_PARAM, (uint8_t *)aph,
243 /* if 0.0.0.0/::0, add the source address instead */
244 if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) {
246 SCTPDBG(SCTP_DEBUG_ASCONF1,
247 "process_asconf_add_ip: using source addr ");
248 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, src);
251 /* add the address */
253 m_reply = sctp_asconf_error_response(aph->correlation_id,
254 SCTP_CAUSE_INVALID_PARAM, (uint8_t *)aph,
256 } else if (sctp_add_remote_addr(stcb, sa, &net, stcb->asoc.port,
258 SCTP_ADDR_DYNAMIC_ADDED) != 0) {
259 SCTPDBG(SCTP_DEBUG_ASCONF1,
260 "process_asconf_add_ip: error adding address\n");
261 m_reply = sctp_asconf_error_response(aph->correlation_id,
262 SCTP_CAUSE_RESOURCE_SHORTAGE, (uint8_t *)aph,
265 if (response_required) {
267 sctp_asconf_success_response(aph->correlation_id);
270 /* notify upper layer */
271 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_ADD_IP, stcb, 0, sa, SCTP_SO_NOT_LOCKED);
272 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, stcb->sctp_ep, stcb, net);
273 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep,
276 sctp_send_hb(stcb, net, SCTP_SO_NOT_LOCKED);
284 sctp_asconf_del_remote_addrs_except(struct sctp_tcb *stcb, struct sockaddr *src)
286 struct sctp_nets *src_net, *net, *nnet;
288 /* make sure the source address exists as a destination net */
289 src_net = sctp_findnet(stcb, src);
290 if (src_net == NULL) {
295 /* delete all destination addresses except the source */
296 TAILQ_FOREACH_SAFE(net, &stcb->asoc.nets, sctp_next, nnet) {
297 if (net != src_net) {
298 /* delete this address */
299 SCTPDBG(SCTP_DEBUG_ASCONF1,
300 "asconf_del_remote_addrs_except: deleting ");
301 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1,
302 (struct sockaddr *)&net->ro._l_addr);
303 /* notify upper layer */
304 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0,
305 (struct sockaddr *)&net->ro._l_addr, SCTP_SO_NOT_LOCKED);
306 sctp_remove_net(stcb, net);
313 sctp_process_asconf_delete_ip(struct sockaddr *src,
314 struct sctp_asconf_paramhdr *aph,
315 struct sctp_tcb *stcb, int response_required)
317 struct mbuf *m_reply = NULL;
318 union sctp_sockstore store;
319 struct sctp_paramhdr *ph;
320 uint16_t param_type, aparam_length;
321 #if defined(INET) || defined(INET6)
322 uint16_t param_length;
325 int zero_address = 0;
328 struct sockaddr_in *sin;
329 struct sctp_ipv4addr_param *v4addr;
332 struct sockaddr_in6 *sin6;
333 struct sctp_ipv6addr_param *v6addr;
336 aparam_length = ntohs(aph->ph.param_length);
337 if (aparam_length < sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_paramhdr)) {
340 ph = (struct sctp_paramhdr *)(aph + 1);
341 param_type = ntohs(ph->param_type);
342 #if defined(INET) || defined(INET6)
343 param_length = ntohs(ph->param_length);
344 if (param_length + sizeof(struct sctp_asconf_paramhdr) != aparam_length) {
349 switch (param_type) {
351 case SCTP_IPV4_ADDRESS:
352 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
353 /* invalid param size */
356 v4addr = (struct sctp_ipv4addr_param *)ph;
358 memset(sin, 0, sizeof(*sin));
359 sin->sin_family = AF_INET;
360 sin->sin_len = sizeof(struct sockaddr_in);
361 sin->sin_port = stcb->rport;
362 sin->sin_addr.s_addr = v4addr->addr;
363 if (sin->sin_addr.s_addr == INADDR_ANY)
365 SCTPDBG(SCTP_DEBUG_ASCONF1,
366 "process_asconf_delete_ip: deleting ");
367 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
371 case SCTP_IPV6_ADDRESS:
372 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
373 /* invalid param size */
376 v6addr = (struct sctp_ipv6addr_param *)ph;
378 memset(sin6, 0, sizeof(*sin6));
379 sin6->sin6_family = AF_INET6;
380 sin6->sin6_len = sizeof(struct sockaddr_in6);
381 sin6->sin6_port = stcb->rport;
382 memcpy(&sin6->sin6_addr, v6addr->addr,
383 sizeof(struct in6_addr));
384 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
386 SCTPDBG(SCTP_DEBUG_ASCONF1,
387 "process_asconf_delete_ip: deleting ");
388 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
392 m_reply = sctp_asconf_error_response(aph->correlation_id,
393 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *)aph,
398 /* make sure the source address is not being deleted */
399 if (sctp_cmpaddr(sa, src)) {
400 /* trying to delete the source address! */
401 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: tried to delete source addr\n");
402 m_reply = sctp_asconf_error_response(aph->correlation_id,
403 SCTP_CAUSE_DELETING_SRC_ADDR, (uint8_t *)aph,
408 /* if deleting 0.0.0.0/::0, delete all addresses except src addr */
409 if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) {
410 result = sctp_asconf_del_remote_addrs_except(stcb, src);
413 /* src address did not exist? */
414 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: src addr does not exist?\n");
415 /* what error to reply with?? */
417 sctp_asconf_error_response(aph->correlation_id,
418 SCTP_CAUSE_REQUEST_REFUSED, (uint8_t *)aph,
420 } else if (response_required) {
422 sctp_asconf_success_response(aph->correlation_id);
427 /* delete the address */
428 result = sctp_del_remote_addr(stcb, sa);
430 * note if result == -2, the address doesn't exist in the asoc but
431 * since it's being deleted anyways, we just ack the delete -- but
432 * this probably means something has already gone awry
435 /* only one address in the asoc */
436 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: tried to delete last IP addr!\n");
437 m_reply = sctp_asconf_error_response(aph->correlation_id,
438 SCTP_CAUSE_DELETING_LAST_ADDR, (uint8_t *)aph,
441 if (response_required) {
442 m_reply = sctp_asconf_success_response(aph->correlation_id);
444 /* notify upper layer */
445 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0, sa, SCTP_SO_NOT_LOCKED);
451 sctp_process_asconf_set_primary(struct sockaddr *src,
452 struct sctp_asconf_paramhdr *aph,
453 struct sctp_tcb *stcb, int response_required)
455 struct mbuf *m_reply = NULL;
456 union sctp_sockstore store;
457 struct sctp_paramhdr *ph;
458 uint16_t param_type, aparam_length;
459 #if defined(INET) || defined(INET6)
460 uint16_t param_length;
463 int zero_address = 0;
465 struct sockaddr_in *sin;
466 struct sctp_ipv4addr_param *v4addr;
469 struct sockaddr_in6 *sin6;
470 struct sctp_ipv6addr_param *v6addr;
473 aparam_length = ntohs(aph->ph.param_length);
474 if (aparam_length < sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_paramhdr)) {
477 ph = (struct sctp_paramhdr *)(aph + 1);
478 param_type = ntohs(ph->param_type);
479 #if defined(INET) || defined(INET6)
480 param_length = ntohs(ph->param_length);
481 if (param_length + sizeof(struct sctp_asconf_paramhdr) != aparam_length) {
486 switch (param_type) {
488 case SCTP_IPV4_ADDRESS:
489 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
490 /* invalid param size */
493 v4addr = (struct sctp_ipv4addr_param *)ph;
495 memset(sin, 0, sizeof(*sin));
496 sin->sin_family = AF_INET;
497 sin->sin_len = sizeof(struct sockaddr_in);
498 sin->sin_addr.s_addr = v4addr->addr;
499 if (sin->sin_addr.s_addr == INADDR_ANY)
501 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_set_primary: ");
502 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
506 case SCTP_IPV6_ADDRESS:
507 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
508 /* invalid param size */
511 v6addr = (struct sctp_ipv6addr_param *)ph;
513 memset(sin6, 0, sizeof(*sin6));
514 sin6->sin6_family = AF_INET6;
515 sin6->sin6_len = sizeof(struct sockaddr_in6);
516 memcpy((caddr_t)&sin6->sin6_addr, v6addr->addr,
517 sizeof(struct in6_addr));
518 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
520 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_set_primary: ");
521 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
525 m_reply = sctp_asconf_error_response(aph->correlation_id,
526 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *)aph,
531 /* if 0.0.0.0/::0, use the source address instead */
532 if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) {
534 SCTPDBG(SCTP_DEBUG_ASCONF1,
535 "process_asconf_set_primary: using source addr ");
536 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, src);
538 /* set the primary address */
539 if (sctp_set_primary_addr(stcb, sa, NULL) == 0) {
540 SCTPDBG(SCTP_DEBUG_ASCONF1,
541 "process_asconf_set_primary: primary address set\n");
542 /* notify upper layer */
543 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_SET_PRIMARY, stcb, 0, sa, SCTP_SO_NOT_LOCKED);
544 if ((stcb->asoc.primary_destination->dest_state & SCTP_ADDR_REACHABLE) &&
545 (!(stcb->asoc.primary_destination->dest_state & SCTP_ADDR_PF)) &&
546 (stcb->asoc.alternate)) {
547 sctp_free_remote_addr(stcb->asoc.alternate);
548 stcb->asoc.alternate = NULL;
550 if (response_required) {
551 m_reply = sctp_asconf_success_response(aph->correlation_id);
554 * Mobility adaptation. Ideally, when the reception of SET
555 * PRIMARY with DELETE IP ADDRESS of the previous primary
556 * destination, unacknowledged DATA are retransmitted
557 * immediately to the new primary destination for seamless
558 * handover. If the destination is UNCONFIRMED and marked to
559 * REQ_PRIM, The retransmission occur when reception of the
560 * HEARTBEAT-ACK. (See sctp_handle_heartbeat_ack in
561 * sctp_input.c) Also, when change of the primary
562 * destination, it is better that all subsequent new DATA
563 * containing already queued DATA are transmitted to the new
564 * primary destination. (by micchie)
566 if ((sctp_is_mobility_feature_on(stcb->sctp_ep,
567 SCTP_MOBILITY_BASE) ||
568 sctp_is_mobility_feature_on(stcb->sctp_ep,
569 SCTP_MOBILITY_FASTHANDOFF)) &&
570 sctp_is_mobility_feature_on(stcb->sctp_ep,
571 SCTP_MOBILITY_PRIM_DELETED) &&
572 (stcb->asoc.primary_destination->dest_state &
573 SCTP_ADDR_UNCONFIRMED) == 0) {
575 sctp_timer_stop(SCTP_TIMER_TYPE_PRIM_DELETED,
576 stcb->sctp_ep, stcb, NULL,
577 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_1);
578 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
579 SCTP_MOBILITY_FASTHANDOFF)) {
580 sctp_assoc_immediate_retrans(stcb,
581 stcb->asoc.primary_destination);
583 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
584 SCTP_MOBILITY_BASE)) {
585 sctp_move_chunks_from_net(stcb,
586 stcb->asoc.deleted_primary);
588 sctp_delete_prim_timer(stcb->sctp_ep, stcb);
591 /* couldn't set the requested primary address! */
592 SCTPDBG(SCTP_DEBUG_ASCONF1,
593 "process_asconf_set_primary: set primary failed!\n");
594 /* must have been an invalid address, so report */
595 m_reply = sctp_asconf_error_response(aph->correlation_id,
596 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *)aph,
604 * handles an ASCONF chunk.
605 * if all parameters are processed ok, send a plain (empty) ASCONF-ACK
608 sctp_handle_asconf(struct mbuf *m, unsigned int offset,
609 struct sockaddr *src,
610 struct sctp_asconf_chunk *cp, struct sctp_tcb *stcb,
613 struct sctp_association *asoc;
615 struct mbuf *n, *m_ack, *m_result, *m_tail;
616 struct sctp_asconf_ack_chunk *ack_cp;
617 struct sctp_asconf_paramhdr *aph;
618 struct sctp_ipv6addr_param *p_addr;
619 unsigned int asconf_limit, cnt;
620 int error = 0; /* did an error occur? */
622 /* asconf param buffer */
623 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE];
624 struct sctp_asconf_ack *ack, *ack_next;
626 /* verify minimum length */
627 if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_chunk)) {
628 SCTPDBG(SCTP_DEBUG_ASCONF1,
629 "handle_asconf: chunk too small = %xh\n",
630 ntohs(cp->ch.chunk_length));
634 serial_num = ntohl(cp->serial_number);
636 if (SCTP_TSN_GE(asoc->asconf_seq_in, serial_num)) {
637 /* got a duplicate ASCONF */
638 SCTPDBG(SCTP_DEBUG_ASCONF1,
639 "handle_asconf: got duplicate serial number = %xh\n",
642 } else if (serial_num != (asoc->asconf_seq_in + 1)) {
643 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: incorrect serial number = %xh (expected next = %xh)\n",
644 serial_num, asoc->asconf_seq_in + 1);
648 /* it's the expected "next" sequence number, so process it */
649 asoc->asconf_seq_in = serial_num; /* update sequence */
650 /* get length of all the param's in the ASCONF */
651 asconf_limit = offset + ntohs(cp->ch.chunk_length);
652 SCTPDBG(SCTP_DEBUG_ASCONF1,
653 "handle_asconf: asconf_limit=%u, sequence=%xh\n",
654 asconf_limit, serial_num);
657 /* delete old cache */
658 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: Now processing first ASCONF. Try to delete old cache\n");
660 TAILQ_FOREACH_SAFE(ack, &asoc->asconf_ack_sent, next, ack_next) {
661 if (ack->serial_number == serial_num)
663 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: delete old(%u) < first(%u)\n",
664 ack->serial_number, serial_num);
665 TAILQ_REMOVE(&asoc->asconf_ack_sent, ack, next);
666 if (ack->data != NULL) {
667 sctp_m_freem(ack->data);
669 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_asconf_ack), ack);
673 m_ack = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_ack_chunk), 0,
674 M_NOWAIT, 1, MT_DATA);
676 SCTPDBG(SCTP_DEBUG_ASCONF1,
677 "handle_asconf: couldn't get mbuf!\n");
680 m_tail = m_ack; /* current reply chain's tail */
682 /* fill in ASCONF-ACK header */
683 ack_cp = mtod(m_ack, struct sctp_asconf_ack_chunk *);
684 ack_cp->ch.chunk_type = SCTP_ASCONF_ACK;
685 ack_cp->ch.chunk_flags = 0;
686 ack_cp->serial_number = htonl(serial_num);
687 /* set initial lengths (eg. just an ASCONF-ACK), ntohx at the end! */
688 SCTP_BUF_LEN(m_ack) = sizeof(struct sctp_asconf_ack_chunk);
689 ack_cp->ch.chunk_length = sizeof(struct sctp_asconf_ack_chunk);
691 /* skip the lookup address parameter */
692 offset += sizeof(struct sctp_asconf_chunk);
693 p_addr = (struct sctp_ipv6addr_param *)sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), (uint8_t *)&aparam_buf);
694 if (p_addr == NULL) {
695 SCTPDBG(SCTP_DEBUG_ASCONF1,
696 "handle_asconf: couldn't get lookup addr!\n");
697 /* respond with a missing/invalid mandatory parameter error */
701 /* skip lookup addr */
702 offset += SCTP_SIZE32(ntohs(p_addr->ph.param_length));
703 /* get pointer to first asconf param in ASCONF */
704 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, sizeof(struct sctp_asconf_paramhdr), (uint8_t *)&aparam_buf);
706 SCTPDBG(SCTP_DEBUG_ASCONF1, "Empty ASCONF received?\n");
709 /* process through all parameters */
711 while (aph != NULL) {
712 unsigned int param_length, param_type;
714 param_type = ntohs(aph->ph.param_type);
715 param_length = ntohs(aph->ph.param_length);
716 if (offset + param_length > asconf_limit) {
717 /* parameter goes beyond end of chunk! */
723 if (param_length > sizeof(aparam_buf)) {
724 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) larger than buffer size!\n", param_length);
728 if (param_length <= sizeof(struct sctp_paramhdr)) {
729 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) too short\n", param_length);
733 /* get the entire parameter */
734 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf);
736 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: couldn't get entire param\n");
740 switch (param_type) {
741 case SCTP_ADD_IP_ADDRESS:
742 m_result = sctp_process_asconf_add_ip(src, aph, stcb,
743 (cnt < SCTP_BASE_SYSCTL(sctp_hb_maxburst)), error);
746 case SCTP_DEL_IP_ADDRESS:
747 m_result = sctp_process_asconf_delete_ip(src, aph, stcb,
750 case SCTP_ERROR_CAUSE_IND:
751 /* not valid in an ASCONF chunk */
753 case SCTP_SET_PRIM_ADDR:
754 m_result = sctp_process_asconf_set_primary(src, aph,
758 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: sees a NAT VTAG state parameter\n");
760 case SCTP_SUCCESS_REPORT:
761 /* not valid in an ASCONF chunk */
763 case SCTP_ULP_ADAPTATION:
767 if ((param_type & 0x8000) == 0) {
768 /* Been told to STOP at this param */
769 asconf_limit = offset;
771 * FIX FIX - We need to call
772 * sctp_arethere_unrecognized_parameters()
773 * to get a operr and send it for any
774 * param's with the 0x4000 bit set OR do it
775 * here ourselves... note we still must STOP
776 * if the 0x8000 bit is clear.
779 /* unknown/invalid param type */
783 /* add any (error) result to the reply mbuf chain */
784 if (m_result != NULL) {
785 SCTP_BUF_NEXT(m_tail) = m_result;
787 ack_cp->ch.chunk_length += SCTP_BUF_LEN(m_result);
788 /* set flag to force success reports */
791 offset += SCTP_SIZE32(param_length);
792 /* update remaining ASCONF message length to process */
793 if (offset >= asconf_limit) {
794 /* no more data in the mbuf chain */
797 /* get pointer to next asconf param */
798 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset,
799 sizeof(struct sctp_asconf_paramhdr),
800 (uint8_t *)&aparam_buf);
802 /* can't get an asconf paramhdr */
803 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: can't get asconf param hdr!\n");
804 /* FIX ME - add error here... */
809 ack_cp->ch.chunk_length = htons(ack_cp->ch.chunk_length);
810 /* save the ASCONF-ACK reply */
811 ack = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_asconf_ack),
812 struct sctp_asconf_ack);
817 ack->serial_number = serial_num;
818 ack->last_sent_to = NULL;
821 for (n = m_ack; n != NULL; n = SCTP_BUF_NEXT(n)) {
822 ack->len += SCTP_BUF_LEN(n);
824 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_ack_sent, ack, next);
826 /* see if last_control_chunk_from is set properly (use IP src addr) */
827 if (stcb->asoc.last_control_chunk_from == NULL) {
829 * this could happen if the source address was just newly
832 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: looking up net for IP source address\n");
833 SCTPDBG(SCTP_DEBUG_ASCONF1, "Looking for IP source: ");
834 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, src);
835 /* look up the from address */
836 stcb->asoc.last_control_chunk_from = sctp_findnet(stcb, src);
838 if (stcb->asoc.last_control_chunk_from == NULL) {
839 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: IP source address not found?!\n");
846 * does the address match? returns 0 if not, 1 if so
849 sctp_asconf_addr_match(struct sctp_asconf_addr *aa, struct sockaddr *sa)
851 switch (sa->sa_family) {
856 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
858 if ((aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) &&
859 (memcmp(&aa->ap.addrp.addr, &sin6->sin6_addr,
860 sizeof(struct in6_addr)) == 0)) {
869 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
871 if ((aa->ap.addrp.ph.param_type == SCTP_IPV4_ADDRESS) &&
872 (memcmp(&aa->ap.addrp.addr, &sin->sin_addr,
873 sizeof(struct in_addr)) == 0)) {
886 * does the address match? returns 0 if not, 1 if so
889 sctp_addr_match(struct sctp_paramhdr *ph, struct sockaddr *sa)
891 #if defined(INET) || defined(INET6)
892 uint16_t param_type, param_length;
894 param_type = ntohs(ph->param_type);
895 param_length = ntohs(ph->param_length);
897 switch (sa->sa_family) {
902 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
903 struct sctp_ipv6addr_param *v6addr;
905 v6addr = (struct sctp_ipv6addr_param *)ph;
906 if ((param_type == SCTP_IPV6_ADDRESS) &&
907 (param_length == sizeof(struct sctp_ipv6addr_param)) &&
908 (memcmp(&v6addr->addr, &sin6->sin6_addr,
909 sizeof(struct in6_addr)) == 0)) {
918 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
919 struct sctp_ipv4addr_param *v4addr;
921 v4addr = (struct sctp_ipv4addr_param *)ph;
922 if ((param_type == SCTP_IPV4_ADDRESS) &&
923 (param_length == sizeof(struct sctp_ipv4addr_param)) &&
924 (memcmp(&v4addr->addr, &sin->sin_addr,
925 sizeof(struct in_addr)) == 0)) {
938 * Cleanup for non-responded/OP ERR'd ASCONF
941 sctp_asconf_cleanup(struct sctp_tcb *stcb)
944 * clear out any existing asconfs going out
946 sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, NULL,
947 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_2);
948 stcb->asoc.asconf_seq_out_acked = stcb->asoc.asconf_seq_out;
949 /* remove the old ASCONF on our outbound queue */
950 sctp_toss_old_asconf(stcb);
954 * cleanup any cached source addresses that may be topologically
955 * incorrect after a new address has been added to this interface.
958 sctp_asconf_nets_cleanup(struct sctp_tcb *stcb, struct sctp_ifn *ifn)
960 struct sctp_nets *net;
963 * Ideally, we want to only clear cached routes and source addresses
964 * that are topologically incorrect. But since there is no easy way
965 * to know whether the newly added address on the ifn would cause a
966 * routing change (i.e. a new egress interface would be chosen)
967 * without doing a new routing lookup and source address selection,
968 * we will (for now) just flush any cached route using a different
969 * ifn (and cached source addrs) and let output re-choose them
970 * during the next send on that net.
972 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
974 * clear any cached route (and cached source address) if the
975 * route's interface is NOT the same as the address change.
976 * If it's the same interface, just clear the cached source
979 if (SCTP_ROUTE_HAS_VALID_IFN(&net->ro) &&
981 (SCTP_GET_IF_INDEX_FROM_ROUTE(&net->ro) != ifn->ifn_index))) {
982 /* clear any cached route */
985 /* clear any cached source address */
986 if (net->src_addr_selected) {
987 sctp_free_ifa(net->ro._s_addr);
988 net->ro._s_addr = NULL;
989 net->src_addr_selected = 0;
996 sctp_assoc_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *dstnet)
1000 if (dstnet->dest_state & SCTP_ADDR_UNCONFIRMED) {
1003 if (stcb->asoc.deleted_primary == NULL) {
1007 if (!TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
1008 SCTPDBG(SCTP_DEBUG_ASCONF1, "assoc_immediate_retrans: Deleted primary is ");
1009 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &stcb->asoc.deleted_primary->ro._l_addr.sa);
1010 SCTPDBG(SCTP_DEBUG_ASCONF1, "Current Primary is ");
1011 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &stcb->asoc.primary_destination->ro._l_addr.sa);
1012 sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb,
1013 stcb->asoc.deleted_primary,
1014 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_3);
1015 stcb->asoc.num_send_timers_up--;
1016 if (stcb->asoc.num_send_timers_up < 0) {
1017 stcb->asoc.num_send_timers_up = 0;
1019 SCTP_TCB_LOCK_ASSERT(stcb);
1020 error = sctp_t3rxt_timer(stcb->sctp_ep, stcb,
1021 stcb->asoc.deleted_primary);
1023 SCTP_INP_DECR_REF(stcb->sctp_ep);
1026 SCTP_TCB_LOCK_ASSERT(stcb);
1027 #ifdef SCTP_AUDITING_ENABLED
1028 sctp_auditing(4, stcb->sctp_ep, stcb, stcb->asoc.deleted_primary);
1030 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED);
1031 if ((stcb->asoc.num_send_timers_up == 0) &&
1032 (stcb->asoc.sent_queue_cnt > 0)) {
1033 struct sctp_tmit_chunk *chk;
1035 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
1036 if (chk->whoTo != NULL) {
1041 sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, chk->whoTo);
1049 sctp_asconf_queue_mgmt(struct sctp_tcb *, struct sctp_ifa *, uint16_t);
1052 sctp_net_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *net)
1054 struct sctp_tmit_chunk *chk;
1056 SCTPDBG(SCTP_DEBUG_ASCONF1, "net_immediate_retrans: RTO is %d\n", net->RTO);
1057 sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, net,
1058 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_4);
1059 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
1060 net->error_count = 0;
1061 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
1062 if (chk->whoTo == net) {
1063 if (chk->sent < SCTP_DATAGRAM_RESEND) {
1064 chk->sent = SCTP_DATAGRAM_RESEND;
1065 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
1066 sctp_flight_size_decrease(chk);
1067 sctp_total_flight_decrease(stcb, chk);
1068 net->marked_retrans++;
1069 stcb->asoc.marked_retrans++;
1073 if (net->marked_retrans) {
1074 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED);
1079 sctp_path_check_and_react(struct sctp_tcb *stcb, struct sctp_ifa *newifa)
1081 struct sctp_nets *net;
1082 int addrnum, changed;
1085 * If number of local valid addresses is 1, the valid address is
1086 * probably newly added address. Several valid addresses in this
1087 * association. A source address may not be changed. Additionally,
1088 * they can be configured on a same interface as "alias" addresses.
1091 addrnum = sctp_local_addr_count(stcb);
1092 SCTPDBG(SCTP_DEBUG_ASCONF1, "p_check_react(): %d local addresses\n",
1095 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1096 /* clear any cached route and source address */
1097 RO_NHFREE(&net->ro);
1098 if (net->src_addr_selected) {
1099 sctp_free_ifa(net->ro._s_addr);
1100 net->ro._s_addr = NULL;
1101 net->src_addr_selected = 0;
1103 /* Retransmit unacknowledged DATA chunks immediately */
1104 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
1105 SCTP_MOBILITY_FASTHANDOFF)) {
1106 sctp_net_immediate_retrans(stcb, net);
1108 /* also, SET PRIMARY is maybe already sent */
1113 /* Multiple local addresses exsist in the association. */
1114 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1115 /* clear any cached route and source address */
1116 RO_NHFREE(&net->ro);
1117 if (net->src_addr_selected) {
1118 sctp_free_ifa(net->ro._s_addr);
1119 net->ro._s_addr = NULL;
1120 net->src_addr_selected = 0;
1123 * Check if the nexthop is corresponding to the new address.
1124 * If the new address is corresponding to the current
1125 * nexthop, the path will be changed. If the new address is
1126 * NOT corresponding to the current nexthop, the path will
1129 SCTP_RTALLOC((sctp_route_t *)&net->ro,
1130 stcb->sctp_ep->def_vrf_id,
1131 stcb->sctp_ep->fibnum);
1132 if (net->ro.ro_nh == NULL)
1136 switch (net->ro._l_addr.sa.sa_family) {
1139 if (sctp_v4src_match_nexthop(newifa, (sctp_route_t *)&net->ro)) {
1146 if (sctp_v6src_match_nexthop(
1147 &newifa->address.sin6, (sctp_route_t *)&net->ro)) {
1156 * if the newly added address does not relate routing
1157 * information, we skip.
1161 /* Retransmit unacknowledged DATA chunks immediately */
1162 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
1163 SCTP_MOBILITY_FASTHANDOFF)) {
1164 sctp_net_immediate_retrans(stcb, net);
1166 /* Send SET PRIMARY for this new address */
1167 if (net == stcb->asoc.primary_destination) {
1168 (void)sctp_asconf_queue_mgmt(stcb, newifa,
1169 SCTP_SET_PRIM_ADDR);
1175 * process an ADD/DELETE IP ack from peer.
1176 * addr: corresponding sctp_ifa to the address being added/deleted.
1177 * type: SCTP_ADD_IP_ADDRESS or SCTP_DEL_IP_ADDRESS.
1178 * flag: 1=success, 0=failure.
1181 sctp_asconf_addr_mgmt_ack(struct sctp_tcb *stcb, struct sctp_ifa *addr, uint32_t flag)
1184 * do the necessary asoc list work- if we get a failure indication,
1185 * leave the address on the assoc's restricted list. If we get a
1186 * success indication, remove the address from the restricted list.
1189 * Note: this will only occur for ADD_IP_ADDRESS, since
1190 * DEL_IP_ADDRESS is never actually added to the list...
1193 /* success case, so remove from the restricted list */
1194 sctp_del_local_addr_restricted(stcb, addr);
1196 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
1197 SCTP_MOBILITY_BASE) ||
1198 sctp_is_mobility_feature_on(stcb->sctp_ep,
1199 SCTP_MOBILITY_FASTHANDOFF)) {
1200 sctp_path_check_and_react(stcb, addr);
1203 /* clear any cached/topologically incorrect source addresses */
1204 sctp_asconf_nets_cleanup(stcb, addr->ifn_p);
1206 /* else, leave it on the list */
1210 * add an asconf add/delete/set primary IP address parameter to the queue.
1211 * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR.
1212 * returns 0 if queued, -1 if not queued/removed.
1213 * NOTE: if adding, but a delete for the same address is already scheduled
1214 * (and not yet sent out), simply remove it from queue. Same for deleting
1215 * an address already scheduled for add. If a duplicate operation is found,
1216 * ignore the new one.
1219 sctp_asconf_queue_mgmt(struct sctp_tcb *stcb, struct sctp_ifa *ifa,
1222 struct sctp_asconf_addr *aa, *aa_next;
1224 /* make sure the request isn't already in the queue */
1225 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) {
1226 /* address match? */
1227 if (sctp_asconf_addr_match(aa, &ifa->address.sa) == 0)
1230 * is the request already in queue but not sent? pass the
1231 * request already sent in order to resolve the following
1232 * case: 1. arrival of ADD, then sent 2. arrival of DEL. we
1233 * can't remove the ADD request already sent 3. arrival of
1236 if (aa->ap.aph.ph.param_type == type && aa->sent == 0) {
1239 /* is the negative request already in queue, and not sent */
1240 if ((aa->sent == 0) && (type == SCTP_ADD_IP_ADDRESS) &&
1241 (aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS)) {
1242 /* add requested, delete already queued */
1243 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1244 /* remove the ifa from the restricted list */
1245 sctp_del_local_addr_restricted(stcb, ifa);
1246 /* free the asconf param */
1247 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1248 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_mgmt: add removes queued entry\n");
1251 if ((aa->sent == 0) && (type == SCTP_DEL_IP_ADDRESS) &&
1252 (aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS)) {
1253 /* delete requested, add already queued */
1254 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1255 /* remove the aa->ifa from the restricted list */
1256 sctp_del_local_addr_restricted(stcb, aa->ifa);
1257 /* free the asconf param */
1258 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1259 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_mgmt: delete removes queued entry\n");
1264 /* adding new request to the queue */
1265 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
1268 /* didn't get memory */
1269 SCTPDBG(SCTP_DEBUG_ASCONF1, "asconf_queue_mgmt: failed to get memory!\n");
1272 aa->special_del = 0;
1273 /* fill in asconf address parameter fields */
1274 /* top level elements are "networked" during send */
1275 aa->ap.aph.ph.param_type = type;
1277 atomic_add_int(&ifa->refcount, 1);
1278 /* correlation_id filled in during send routine later... */
1279 switch (ifa->address.sa.sa_family) {
1283 struct sockaddr_in6 *sin6;
1285 sin6 = &ifa->address.sin6;
1286 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
1287 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param));
1288 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) +
1289 sizeof(struct sctp_ipv6addr_param);
1290 memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr,
1291 sizeof(struct in6_addr));
1298 struct sockaddr_in *sin;
1300 sin = &ifa->address.sin;
1301 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
1302 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param));
1303 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) +
1304 sizeof(struct sctp_ipv4addr_param);
1305 memcpy(&aa->ap.addrp.addr, &sin->sin_addr,
1306 sizeof(struct in_addr));
1311 /* invalid family! */
1312 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1316 aa->sent = 0; /* clear sent flag */
1318 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
1320 if (SCTP_BASE_SYSCTL(sctp_debug_on) & SCTP_DEBUG_ASCONF2) {
1321 if (type == SCTP_ADD_IP_ADDRESS) {
1322 SCTP_PRINTF("asconf_queue_mgmt: inserted asconf ADD_IP_ADDRESS: ");
1323 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa);
1324 } else if (type == SCTP_DEL_IP_ADDRESS) {
1325 SCTP_PRINTF("asconf_queue_mgmt: appended asconf DEL_IP_ADDRESS: ");
1326 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa);
1328 SCTP_PRINTF("asconf_queue_mgmt: appended asconf SET_PRIM_ADDR: ");
1329 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa);
1339 * add an asconf operation for the given ifa and type.
1340 * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR.
1341 * returns 0 if completed, -1 if not completed, 1 if immediate send is
1345 sctp_asconf_queue_add(struct sctp_tcb *stcb, struct sctp_ifa *ifa,
1349 int pending_delete_queued = 0;
1352 /* see if peer supports ASCONF */
1353 if (stcb->asoc.asconf_supported == 0) {
1358 * if this is deleting the last address from the assoc, mark it as
1361 if ((type == SCTP_DEL_IP_ADDRESS) && !stcb->asoc.asconf_del_pending) {
1362 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1363 last = (sctp_local_addr_count(stcb) == 0);
1365 last = (sctp_local_addr_count(stcb) == 1);
1368 /* set the pending delete info only */
1369 stcb->asoc.asconf_del_pending = 1;
1370 stcb->asoc.asconf_addr_del_pending = ifa;
1371 atomic_add_int(&ifa->refcount, 1);
1372 SCTPDBG(SCTP_DEBUG_ASCONF2,
1373 "asconf_queue_add: mark delete last address pending\n");
1378 /* queue an asconf parameter */
1379 status = sctp_asconf_queue_mgmt(stcb, ifa, type);
1382 * if this is an add, and there is a delete also pending (i.e. the
1383 * last local address is being changed), queue the pending delete
1386 if ((type == SCTP_ADD_IP_ADDRESS) && stcb->asoc.asconf_del_pending && (status == 0)) {
1387 /* queue in the pending delete */
1388 if (sctp_asconf_queue_mgmt(stcb,
1389 stcb->asoc.asconf_addr_del_pending,
1390 SCTP_DEL_IP_ADDRESS) == 0) {
1391 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_add: queuing pending delete\n");
1392 pending_delete_queued = 1;
1393 /* clear out the pending delete info */
1394 stcb->asoc.asconf_del_pending = 0;
1395 sctp_free_ifa(stcb->asoc.asconf_addr_del_pending);
1396 stcb->asoc.asconf_addr_del_pending = NULL;
1400 if (pending_delete_queued) {
1401 struct sctp_nets *net;
1404 * since we know that the only/last address is now being
1405 * changed in this case, reset the cwnd/rto on all nets to
1406 * start as a new address and path. Also clear the error
1407 * counts to give the assoc the best chance to complete the
1410 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1411 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb,
1414 net->error_count = 0;
1416 stcb->asoc.overall_error_count = 0;
1417 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) {
1418 sctp_misc_ints(SCTP_THRESHOLD_CLEAR,
1419 stcb->asoc.overall_error_count,
1421 SCTP_FROM_SCTP_ASCONF,
1425 /* queue in an advisory set primary too */
1426 (void)sctp_asconf_queue_mgmt(stcb, ifa, SCTP_SET_PRIM_ADDR);
1427 /* let caller know we should send this out immediately */
1434 * add an asconf delete IP address parameter to the queue by sockaddr and
1435 * possibly with no sctp_ifa available. This is only called by the routine
1436 * that checks the addresses in an INIT-ACK against the current address list.
1437 * returns 0 if completed, non-zero if not completed.
1438 * NOTE: if an add is already scheduled (and not yet sent out), simply
1439 * remove it from queue. If a duplicate operation is found, ignore the
1443 sctp_asconf_queue_sa_delete(struct sctp_tcb *stcb, struct sockaddr *sa)
1445 struct sctp_ifa *ifa;
1446 struct sctp_asconf_addr *aa, *aa_next;
1451 /* see if peer supports ASCONF */
1452 if (stcb->asoc.asconf_supported == 0) {
1455 /* make sure the request isn't already in the queue */
1456 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) {
1457 /* address match? */
1458 if (sctp_asconf_addr_match(aa, sa) == 0)
1460 /* is the request already in queue (sent or not) */
1461 if (aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) {
1464 /* is the negative request already in queue, and not sent */
1467 if (aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS) {
1468 /* add already queued, so remove existing entry */
1469 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1470 sctp_del_local_addr_restricted(stcb, aa->ifa);
1471 /* free the entry */
1472 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1477 /* find any existing ifa-- NOTE ifa CAN be allowed to be NULL */
1478 ifa = sctp_find_ifa_by_addr(sa, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
1480 /* adding new request to the queue */
1481 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
1484 /* didn't get memory */
1485 SCTPDBG(SCTP_DEBUG_ASCONF1,
1486 "sctp_asconf_queue_sa_delete: failed to get memory!\n");
1489 aa->special_del = 0;
1490 /* fill in asconf address parameter fields */
1491 /* top level elements are "networked" during send */
1492 aa->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS;
1495 atomic_add_int(&ifa->refcount, 1);
1496 /* correlation_id filled in during send routine later... */
1497 switch (sa->sa_family) {
1502 struct sockaddr_in6 *sin6;
1504 sin6 = (struct sockaddr_in6 *)sa;
1505 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
1506 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param));
1507 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv6addr_param);
1508 memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr,
1509 sizeof(struct in6_addr));
1517 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
1519 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
1520 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param));
1521 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv4addr_param);
1522 memcpy(&aa->ap.addrp.addr, &sin->sin_addr,
1523 sizeof(struct in_addr));
1528 /* invalid family! */
1529 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1534 aa->sent = 0; /* clear sent flag */
1536 /* delete goes to the back of the queue */
1537 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
1539 /* sa_ignore MEMLEAK {memory is put on the tailq} */
1544 * find a specific asconf param on our "sent" queue
1546 static struct sctp_asconf_addr *
1547 sctp_asconf_find_param(struct sctp_tcb *stcb, uint32_t correlation_id)
1549 struct sctp_asconf_addr *aa;
1551 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
1552 if (aa->ap.aph.correlation_id == correlation_id &&
1558 /* didn't find it */
1563 * process an SCTP_ERROR_CAUSE_IND for a ASCONF-ACK parameter and do
1564 * notifications based on the error response
1567 sctp_asconf_process_error(struct sctp_tcb *stcb SCTP_UNUSED,
1568 struct sctp_asconf_paramhdr *aph)
1570 struct sctp_error_cause *eh;
1571 struct sctp_paramhdr *ph;
1572 uint16_t param_type;
1573 uint16_t error_code;
1575 eh = (struct sctp_error_cause *)(aph + 1);
1576 ph = (struct sctp_paramhdr *)(eh + 1);
1577 /* validate lengths */
1578 if (htons(eh->length) + sizeof(struct sctp_error_cause) >
1579 htons(aph->ph.param_length)) {
1580 /* invalid error cause length */
1581 SCTPDBG(SCTP_DEBUG_ASCONF1,
1582 "asconf_process_error: cause element too long\n");
1585 if (htons(ph->param_length) + sizeof(struct sctp_paramhdr) >
1586 htons(eh->length)) {
1587 /* invalid included TLV length */
1588 SCTPDBG(SCTP_DEBUG_ASCONF1,
1589 "asconf_process_error: included TLV too long\n");
1592 /* which error code ? */
1593 error_code = ntohs(eh->code);
1594 param_type = ntohs(aph->ph.param_type);
1595 /* FIX: this should go back up the REMOTE_ERROR ULP notify */
1596 switch (error_code) {
1597 case SCTP_CAUSE_RESOURCE_SHORTAGE:
1598 /* we allow ourselves to "try again" for this error */
1601 /* peer can't handle it... */
1602 switch (param_type) {
1603 case SCTP_ADD_IP_ADDRESS:
1604 case SCTP_DEL_IP_ADDRESS:
1605 case SCTP_SET_PRIM_ADDR:
1614 * process an asconf queue param.
1615 * aparam: parameter to process, will be removed from the queue.
1616 * flag: 1=success case, 0=failure case
1619 sctp_asconf_process_param_ack(struct sctp_tcb *stcb,
1620 struct sctp_asconf_addr *aparam, uint32_t flag)
1622 uint16_t param_type;
1624 /* process this param */
1625 param_type = aparam->ap.aph.ph.param_type;
1626 switch (param_type) {
1627 case SCTP_ADD_IP_ADDRESS:
1628 SCTPDBG(SCTP_DEBUG_ASCONF1,
1629 "process_param_ack: added IP address\n");
1630 sctp_asconf_addr_mgmt_ack(stcb, aparam->ifa, flag);
1632 case SCTP_DEL_IP_ADDRESS:
1633 SCTPDBG(SCTP_DEBUG_ASCONF1,
1634 "process_param_ack: deleted IP address\n");
1635 /* nothing really to do... lists already updated */
1637 case SCTP_SET_PRIM_ADDR:
1638 SCTPDBG(SCTP_DEBUG_ASCONF1,
1639 "process_param_ack: set primary IP address\n");
1640 /* nothing to do... peer may start using this addr */
1643 /* should NEVER happen */
1647 /* remove the param and free it */
1648 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aparam, next);
1650 sctp_free_ifa(aparam->ifa);
1651 SCTP_FREE(aparam, SCTP_M_ASC_ADDR);
1655 * cleanup from a bad asconf ack parameter
1658 sctp_asconf_ack_clear(struct sctp_tcb *stcb SCTP_UNUSED)
1660 /* assume peer doesn't really know how to do asconfs */
1661 /* XXX we could free the pending queue here */
1666 sctp_handle_asconf_ack(struct mbuf *m, int offset,
1667 struct sctp_asconf_ack_chunk *cp, struct sctp_tcb *stcb,
1668 struct sctp_nets *net, int *abort_no_unlock)
1670 struct sctp_association *asoc;
1671 uint32_t serial_num;
1672 uint16_t ack_length;
1673 struct sctp_asconf_paramhdr *aph;
1674 struct sctp_asconf_addr *aa, *aa_next;
1675 uint32_t last_error_id = 0; /* last error correlation id */
1677 struct sctp_asconf_addr *ap;
1679 /* asconf param buffer */
1680 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE];
1682 /* verify minimum length */
1683 if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_ack_chunk)) {
1684 SCTPDBG(SCTP_DEBUG_ASCONF1,
1685 "handle_asconf_ack: chunk too small = %xh\n",
1686 ntohs(cp->ch.chunk_length));
1690 serial_num = ntohl(cp->serial_number);
1693 * NOTE: we may want to handle this differently- currently, we will
1694 * abort when we get an ack for the expected serial number + 1 (eg.
1695 * we didn't send it), process an ack normally if it is the expected
1696 * serial number, and re-send the previous ack for *ALL* other
1701 * if the serial number is the next expected, but I didn't send it,
1702 * abort the asoc, since someone probably just hijacked us...
1704 if (serial_num == (asoc->asconf_seq_out + 1)) {
1705 struct mbuf *op_err;
1706 char msg[SCTP_DIAG_INFO_LEN];
1708 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got unexpected next serial number! Aborting asoc!\n");
1709 snprintf(msg, sizeof(msg), "Never sent serial number %8.8x",
1711 op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
1712 sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
1713 *abort_no_unlock = 1;
1716 if (serial_num != asoc->asconf_seq_out_acked + 1) {
1717 /* got a duplicate/unexpected ASCONF-ACK */
1718 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got duplicate/unexpected serial number = %xh (expected = %xh)\n",
1719 serial_num, asoc->asconf_seq_out_acked + 1);
1723 if (serial_num == asoc->asconf_seq_out - 1) {
1724 /* stop our timer */
1725 sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, NULL,
1726 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_5);
1729 /* process the ASCONF-ACK contents */
1730 ack_length = ntohs(cp->ch.chunk_length) -
1731 sizeof(struct sctp_asconf_ack_chunk);
1732 offset += sizeof(struct sctp_asconf_ack_chunk);
1733 /* process through all parameters */
1734 while (ack_length >= sizeof(struct sctp_asconf_paramhdr)) {
1735 unsigned int param_length, param_type;
1737 /* get pointer to next asconf parameter */
1738 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset,
1739 sizeof(struct sctp_asconf_paramhdr), aparam_buf);
1741 /* can't get an asconf paramhdr */
1742 sctp_asconf_ack_clear(stcb);
1745 param_type = ntohs(aph->ph.param_type);
1746 param_length = ntohs(aph->ph.param_length);
1747 if (param_length > ack_length) {
1748 sctp_asconf_ack_clear(stcb);
1751 if (param_length < sizeof(struct sctp_paramhdr)) {
1752 sctp_asconf_ack_clear(stcb);
1755 /* get the complete parameter... */
1756 if (param_length > sizeof(aparam_buf)) {
1757 SCTPDBG(SCTP_DEBUG_ASCONF1,
1758 "param length (%u) larger than buffer size!\n", param_length);
1759 sctp_asconf_ack_clear(stcb);
1762 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf);
1764 sctp_asconf_ack_clear(stcb);
1767 /* correlation_id is transparent to peer, no ntohl needed */
1768 id = aph->correlation_id;
1770 switch (param_type) {
1771 case SCTP_ERROR_CAUSE_IND:
1773 /* find the corresponding asconf param in our queue */
1774 ap = sctp_asconf_find_param(stcb, id);
1776 /* hmm... can't find this in our queue! */
1779 /* process the parameter, failed flag */
1780 sctp_asconf_process_param_ack(stcb, ap, 0);
1781 /* process the error response */
1782 sctp_asconf_process_error(stcb, aph);
1784 case SCTP_SUCCESS_REPORT:
1785 /* find the corresponding asconf param in our queue */
1786 ap = sctp_asconf_find_param(stcb, id);
1788 /* hmm... can't find this in our queue! */
1791 /* process the parameter, success flag */
1792 sctp_asconf_process_param_ack(stcb, ap, 1);
1798 /* update remaining ASCONF-ACK message length to process */
1799 if (ack_length > SCTP_SIZE32(param_length)) {
1800 ack_length -= SCTP_SIZE32(param_length);
1804 offset += SCTP_SIZE32(param_length);
1808 * if there are any "sent" params still on the queue, these are
1809 * implicitly "success", or "failed" (if we got an error back) ...
1810 * so process these appropriately
1812 * we assume that the correlation_id's are monotonically increasing
1813 * beginning from 1 and that we don't have *that* many outstanding
1816 if (last_error_id == 0)
1817 last_error_id--; /* set to "max" value */
1818 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) {
1819 if (aa->sent == 1) {
1821 * implicitly successful or failed if correlation_id
1822 * < last_error_id, then success else, failure
1824 if (aa->ap.aph.correlation_id < last_error_id)
1825 sctp_asconf_process_param_ack(stcb, aa, 1);
1827 sctp_asconf_process_param_ack(stcb, aa, 0);
1830 * since we always process in order (FIFO queue) if
1831 * we reach one that hasn't been sent, the rest
1832 * should not have been sent either. so, we're
1839 /* update the next sequence number to use */
1840 asoc->asconf_seq_out_acked++;
1841 /* remove the old ASCONF on our outbound queue */
1842 sctp_toss_old_asconf(stcb);
1843 if (!TAILQ_EMPTY(&stcb->asoc.asconf_queue)) {
1844 #ifdef SCTP_TIMER_BASED_ASCONF
1845 /* we have more params, so restart our timer */
1846 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep,
1849 /* we have more params, so send out more */
1850 sctp_send_asconf(stcb, net, SCTP_ADDR_NOT_LOCKED);
1857 sctp_is_scopeid_in_nets(struct sctp_tcb *stcb, struct sockaddr *sa)
1859 struct sockaddr_in6 *sin6, *net6;
1860 struct sctp_nets *net;
1862 if (sa->sa_family != AF_INET6) {
1866 sin6 = (struct sockaddr_in6 *)sa;
1867 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) == 0) {
1868 /* not link local address */
1871 /* hunt through our destination nets list for this scope_id */
1872 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1873 if (((struct sockaddr *)(&net->ro._l_addr))->sa_family !=
1876 net6 = (struct sockaddr_in6 *)&net->ro._l_addr;
1877 if (IN6_IS_ADDR_LINKLOCAL(&net6->sin6_addr) == 0)
1879 if (sctp_is_same_scope(sin6, net6)) {
1884 /* didn't find one */
1890 * address management functions
1893 sctp_addr_mgmt_assoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
1894 struct sctp_ifa *ifa, uint16_t type, int addr_locked)
1898 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0 ||
1899 sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_ASCONF)) {
1900 /* subset bound, no ASCONF allowed case, so ignore */
1904 * note: we know this is not the subset bound, no ASCONF case eg.
1905 * this is boundall or subset bound w/ASCONF allowed
1908 /* first, make sure that the address is IPv4 or IPv6 and not jailed */
1909 switch (ifa->address.sa.sa_family) {
1912 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1913 &ifa->address.sin6.sin6_addr) != 0) {
1920 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1921 &ifa->address.sin.sin_addr) != 0) {
1930 /* make sure we're "allowed" to add this type of addr */
1931 if (ifa->address.sa.sa_family == AF_INET6) {
1932 /* invalid if we're not a v6 endpoint */
1933 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0)
1935 /* is the v6 addr really valid ? */
1936 if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) {
1941 /* put this address on the "pending/do not use yet" list */
1942 sctp_add_local_addr_restricted(stcb, ifa);
1944 * check address scope if address is out of scope, don't queue
1945 * anything... note: this would leave the address on both inp and
1948 switch (ifa->address.sa.sa_family) {
1952 struct sockaddr_in6 *sin6;
1954 sin6 = &ifa->address.sin6;
1955 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1956 /* we skip unspecifed addresses */
1959 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1960 if (stcb->asoc.scope.local_scope == 0) {
1963 /* is it the right link local scope? */
1964 if (sctp_is_scopeid_in_nets(stcb, &ifa->address.sa) == 0) {
1968 if (stcb->asoc.scope.site_scope == 0 &&
1969 IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)) {
1978 struct sockaddr_in *sin;
1980 /* invalid if we are a v6 only endpoint */
1981 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1982 SCTP_IPV6_V6ONLY(inp))
1985 sin = &ifa->address.sin;
1986 if (sin->sin_addr.s_addr == 0) {
1987 /* we skip unspecifed addresses */
1990 if (stcb->asoc.scope.ipv4_local_scope == 0 &&
1991 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) {
1998 /* else, not AF_INET or AF_INET6, so skip */
2002 /* queue an asconf for this address add/delete */
2003 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF)) {
2004 /* does the peer do asconf? */
2005 if (stcb->asoc.asconf_supported) {
2006 /* queue an asconf for this addr */
2007 status = sctp_asconf_queue_add(stcb, ifa, type);
2010 * if queued ok, and in the open state, send out the
2011 * ASCONF. If in the non-open state, these will be
2012 * sent when the state goes open.
2015 ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
2016 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED))) {
2017 #ifdef SCTP_TIMER_BASED_ASCONF
2018 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, inp,
2019 stcb, stcb->asoc.primary_destination);
2021 sctp_send_asconf(stcb, NULL, addr_locked);
2030 sctp_asconf_iterator_ep(struct sctp_inpcb *inp, void *ptr, uint32_t val SCTP_UNUSED)
2032 struct sctp_asconf_iterator *asc;
2033 struct sctp_ifa *ifa;
2034 struct sctp_laddr *l;
2035 int cnt_invalid = 0;
2037 asc = (struct sctp_asconf_iterator *)ptr;
2038 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) {
2040 switch (ifa->address.sa.sa_family) {
2043 /* invalid if we're not a v6 endpoint */
2044 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
2046 if (asc->cnt == cnt_invalid)
2054 /* invalid if we are a v6 only endpoint */
2055 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2056 SCTP_IPV6_V6ONLY(inp)) {
2058 if (asc->cnt == cnt_invalid)
2065 /* invalid address family */
2067 if (asc->cnt == cnt_invalid)
2075 sctp_asconf_iterator_ep_end(struct sctp_inpcb *inp, void *ptr, uint32_t val SCTP_UNUSED)
2077 struct sctp_ifa *ifa;
2078 struct sctp_asconf_iterator *asc;
2079 struct sctp_laddr *laddr, *nladdr, *l;
2081 /* Only for specific case not bound all */
2082 asc = (struct sctp_asconf_iterator *)ptr;
2083 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) {
2085 if (l->action == SCTP_ADD_IP_ADDRESS) {
2086 LIST_FOREACH(laddr, &inp->sctp_addr_list,
2088 if (laddr->ifa == ifa) {
2094 } else if (l->action == SCTP_DEL_IP_ADDRESS) {
2095 LIST_FOREACH_SAFE(laddr, &inp->sctp_addr_list, sctp_nxt_addr, nladdr) {
2096 /* remove only after all guys are done */
2097 if (laddr->ifa == ifa) {
2098 sctp_del_local_addr_ep(inp, ifa);
2107 sctp_asconf_iterator_stcb(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
2108 void *ptr, uint32_t val SCTP_UNUSED)
2110 struct sctp_asconf_iterator *asc;
2111 struct sctp_ifa *ifa;
2112 struct sctp_laddr *l;
2113 int cnt_invalid = 0;
2117 asc = (struct sctp_asconf_iterator *)ptr;
2118 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) {
2122 /* address's vrf_id must be the vrf_id of the assoc */
2123 if (ifa->vrf_id != stcb->asoc.vrf_id) {
2127 /* Same checks again for assoc */
2128 switch (ifa->address.sa.sa_family) {
2132 /* invalid if we're not a v6 endpoint */
2133 struct sockaddr_in6 *sin6;
2135 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
2137 if (asc->cnt == cnt_invalid)
2142 sin6 = &ifa->address.sin6;
2143 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2144 /* we skip unspecifed addresses */
2147 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
2148 &sin6->sin6_addr) != 0) {
2151 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
2152 if (stcb->asoc.scope.local_scope == 0) {
2155 /* is it the right link local scope? */
2156 if (sctp_is_scopeid_in_nets(stcb, &ifa->address.sa) == 0) {
2166 /* invalid if we are a v6 only endpoint */
2167 struct sockaddr_in *sin;
2169 /* invalid if we are a v6 only endpoint */
2170 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2171 SCTP_IPV6_V6ONLY(inp))
2174 sin = &ifa->address.sin;
2175 if (sin->sin_addr.s_addr == 0) {
2176 /* we skip unspecifed addresses */
2179 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
2180 &sin->sin_addr) != 0) {
2183 if (stcb->asoc.scope.ipv4_local_scope == 0 &&
2184 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) {
2187 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2188 SCTP_IPV6_V6ONLY(inp)) {
2190 if (asc->cnt == cnt_invalid)
2199 /* invalid address family */
2201 if (asc->cnt == cnt_invalid)
2208 if (type == SCTP_ADD_IP_ADDRESS) {
2209 /* prevent this address from being used as a source */
2210 sctp_add_local_addr_restricted(stcb, ifa);
2211 } else if (type == SCTP_DEL_IP_ADDRESS) {
2212 struct sctp_nets *net;
2214 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2215 /* delete this address if cached */
2216 if (net->ro._s_addr == ifa) {
2217 sctp_free_ifa(net->ro._s_addr);
2218 net->ro._s_addr = NULL;
2219 net->src_addr_selected = 0;
2220 RO_NHFREE(&net->ro);
2222 * Now we deleted our src address,
2223 * should we not also now reset the
2224 * cwnd/rto to start as if its a new
2227 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
2232 } else if (type == SCTP_SET_PRIM_ADDR) {
2233 if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
2234 /* must validate the ifa is in the ep */
2235 if (sctp_is_addr_in_ep(stcb->sctp_ep, ifa) == 0) {
2239 /* Need to check scopes for this guy */
2240 if (sctp_is_address_in_scope(ifa, &stcb->asoc.scope, 0) == 0) {
2245 /* queue an asconf for this address add/delete */
2246 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF) &&
2247 stcb->asoc.asconf_supported == 1) {
2248 /* queue an asconf for this addr */
2249 status = sctp_asconf_queue_add(stcb, ifa, type);
2251 * if queued ok, and in the open state, update the
2252 * count of queued params. If in the non-open
2253 * state, these get sent when the assoc goes open.
2255 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
2256 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
2264 * If we have queued params in the open state, send out an ASCONF.
2266 if (num_queued > 0) {
2267 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2272 sctp_asconf_iterator_end(void *ptr, uint32_t val SCTP_UNUSED)
2274 struct sctp_asconf_iterator *asc;
2275 struct sctp_ifa *ifa;
2276 struct sctp_laddr *l, *nl;
2278 asc = (struct sctp_asconf_iterator *)ptr;
2279 LIST_FOREACH_SAFE(l, &asc->list_of_work, sctp_nxt_addr, nl) {
2281 if (l->action == SCTP_ADD_IP_ADDRESS) {
2282 /* Clear the defer use flag */
2283 ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE;
2286 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_laddr), l);
2287 SCTP_DECR_LADDR_COUNT();
2289 SCTP_FREE(asc, SCTP_M_ASC_IT);
2293 * sa is the sockaddr to ask the peer to set primary to.
2294 * returns: 0 = completed, -1 = error
2297 sctp_set_primary_ip_address_sa(struct sctp_tcb *stcb, struct sockaddr *sa)
2300 struct sctp_ifa *ifa;
2302 /* find the ifa for the desired set primary */
2303 vrf_id = stcb->asoc.vrf_id;
2304 ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED);
2306 /* Invalid address */
2310 /* queue an ASCONF:SET_PRIM_ADDR to be sent */
2311 if (!sctp_asconf_queue_add(stcb, ifa, SCTP_SET_PRIM_ADDR)) {
2312 /* set primary queuing succeeded */
2313 SCTPDBG(SCTP_DEBUG_ASCONF1,
2314 "set_primary_ip_address_sa: queued on tcb=%p, ",
2316 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
2317 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
2318 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
2319 #ifdef SCTP_TIMER_BASED_ASCONF
2320 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
2321 stcb->sctp_ep, stcb,
2322 stcb->asoc.primary_destination);
2324 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2328 SCTPDBG(SCTP_DEBUG_ASCONF1, "set_primary_ip_address_sa: failed to add to queue on tcb=%p, ",
2330 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
2337 sctp_is_addr_pending(struct sctp_tcb *stcb, struct sctp_ifa *sctp_ifa)
2339 struct sctp_tmit_chunk *chk, *nchk;
2340 unsigned int offset, asconf_limit;
2341 struct sctp_asconf_chunk *acp;
2342 struct sctp_asconf_paramhdr *aph;
2343 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE];
2344 struct sctp_paramhdr *ph;
2345 int add_cnt, del_cnt;
2346 uint16_t last_param_type;
2348 add_cnt = del_cnt = 0;
2349 last_param_type = 0;
2350 TAILQ_FOREACH_SAFE(chk, &stcb->asoc.asconf_send_queue, sctp_next, nchk) {
2351 if (chk->data == NULL) {
2352 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: No mbuf data?\n");
2356 acp = mtod(chk->data, struct sctp_asconf_chunk *);
2357 offset += sizeof(struct sctp_asconf_chunk);
2358 asconf_limit = ntohs(acp->ch.chunk_length);
2359 ph = (struct sctp_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_paramhdr), aparam_buf);
2361 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: couldn't get lookup addr!\n");
2364 offset += ntohs(ph->param_length);
2366 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_asconf_paramhdr), aparam_buf);
2368 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: Empty ASCONF will be sent?\n");
2371 while (aph != NULL) {
2372 unsigned int param_length, param_type;
2374 param_type = ntohs(aph->ph.param_type);
2375 param_length = ntohs(aph->ph.param_length);
2376 if (offset + param_length > asconf_limit) {
2377 /* parameter goes beyond end of chunk! */
2380 if (param_length > sizeof(aparam_buf)) {
2381 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: param length (%u) larger than buffer size!\n", param_length);
2384 if (param_length <= sizeof(struct sctp_paramhdr)) {
2385 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: param length(%u) too short\n", param_length);
2389 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, param_length, aparam_buf);
2391 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: couldn't get entire param\n");
2395 ph = (struct sctp_paramhdr *)(aph + 1);
2396 if (sctp_addr_match(ph, &sctp_ifa->address.sa) != 0) {
2397 switch (param_type) {
2398 case SCTP_ADD_IP_ADDRESS:
2401 case SCTP_DEL_IP_ADDRESS:
2407 last_param_type = param_type;
2410 offset += SCTP_SIZE32(param_length);
2411 if (offset >= asconf_limit) {
2412 /* no more data in the mbuf chain */
2415 /* get pointer to next asconf param */
2416 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_asconf_paramhdr), aparam_buf);
2421 * we want to find the sequences which consist of ADD -> DEL -> ADD
2424 if (add_cnt > del_cnt ||
2425 (add_cnt == del_cnt && last_param_type == SCTP_ADD_IP_ADDRESS)) {
2431 static struct sockaddr *
2432 sctp_find_valid_localaddr(struct sctp_tcb *stcb, int addr_locked)
2434 struct sctp_vrf *vrf = NULL;
2435 struct sctp_ifn *sctp_ifn;
2436 struct sctp_ifa *sctp_ifa;
2438 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2439 SCTP_IPI_ADDR_RLOCK();
2440 vrf = sctp_find_vrf(stcb->asoc.vrf_id);
2442 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2443 SCTP_IPI_ADDR_RUNLOCK();
2446 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
2447 if (stcb->asoc.scope.loopback_scope == 0 &&
2448 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
2449 /* Skip if loopback_scope not set */
2452 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
2453 switch (sctp_ifa->address.sa.sa_family) {
2456 if (stcb->asoc.scope.ipv4_addr_legal) {
2457 struct sockaddr_in *sin;
2459 sin = &sctp_ifa->address.sin;
2460 if (sin->sin_addr.s_addr == 0) {
2461 /* skip unspecifed addresses */
2464 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
2465 &sin->sin_addr) != 0) {
2468 if (stcb->asoc.scope.ipv4_local_scope == 0 &&
2469 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))
2472 if (sctp_is_addr_restricted(stcb, sctp_ifa) &&
2473 (!sctp_is_addr_pending(stcb, sctp_ifa)))
2476 * found a valid local v4 address to
2479 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2480 SCTP_IPI_ADDR_RUNLOCK();
2481 return (&sctp_ifa->address.sa);
2487 if (stcb->asoc.scope.ipv6_addr_legal) {
2488 struct sockaddr_in6 *sin6;
2490 if (sctp_ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) {
2494 sin6 = &sctp_ifa->address.sin6;
2495 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2497 * we skip unspecifed
2502 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
2503 &sin6->sin6_addr) != 0) {
2506 if (stcb->asoc.scope.local_scope == 0 &&
2507 IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))
2509 if (stcb->asoc.scope.site_scope == 0 &&
2510 IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))
2513 if (sctp_is_addr_restricted(stcb, sctp_ifa) &&
2514 (!sctp_is_addr_pending(stcb, sctp_ifa)))
2517 * found a valid local v6 address to
2520 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2521 SCTP_IPI_ADDR_RUNLOCK();
2522 return (&sctp_ifa->address.sa);
2531 /* no valid addresses found */
2532 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2533 SCTP_IPI_ADDR_RUNLOCK();
2537 static struct sockaddr *
2538 sctp_find_valid_localaddr_ep(struct sctp_tcb *stcb)
2540 struct sctp_laddr *laddr;
2542 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
2543 if (laddr->ifa == NULL) {
2546 /* is the address restricted ? */
2547 if (sctp_is_addr_restricted(stcb, laddr->ifa) &&
2548 (!sctp_is_addr_pending(stcb, laddr->ifa)))
2551 /* found a valid local address to use */
2552 return (&laddr->ifa->address.sa);
2554 /* no valid addresses found */
2559 * builds an ASCONF chunk from queued ASCONF params.
2560 * returns NULL on error (no mbuf, no ASCONF params queued, etc).
2563 sctp_compose_asconf(struct sctp_tcb *stcb, int *retlen, int addr_locked)
2565 struct mbuf *m_asconf, *m_asconf_chk;
2566 struct sctp_asconf_addr *aa;
2567 struct sctp_asconf_chunk *acp;
2568 struct sctp_asconf_paramhdr *aph;
2569 struct sctp_asconf_addr_param *aap;
2571 uint32_t correlation_id = 1; /* 0 is reserved... */
2572 caddr_t ptr, lookup_ptr;
2573 uint8_t lookup_used = 0;
2575 /* are there any asconf params to send? */
2576 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
2584 * get a chunk header mbuf and a cluster for the asconf params since
2585 * it's simpler to fill in the asconf chunk header lookup address on
2588 m_asconf_chk = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_chunk), 0, M_NOWAIT, 1, MT_DATA);
2589 if (m_asconf_chk == NULL) {
2591 SCTPDBG(SCTP_DEBUG_ASCONF1,
2592 "compose_asconf: couldn't get chunk mbuf!\n");
2595 m_asconf = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA);
2596 if (m_asconf == NULL) {
2598 SCTPDBG(SCTP_DEBUG_ASCONF1,
2599 "compose_asconf: couldn't get mbuf!\n");
2600 sctp_m_freem(m_asconf_chk);
2603 SCTP_BUF_LEN(m_asconf_chk) = sizeof(struct sctp_asconf_chunk);
2604 SCTP_BUF_LEN(m_asconf) = 0;
2605 acp = mtod(m_asconf_chk, struct sctp_asconf_chunk *);
2606 memset(acp, 0, sizeof(struct sctp_asconf_chunk));
2607 /* save pointers to lookup address and asconf params */
2608 lookup_ptr = (caddr_t)(acp + 1); /* after the header */
2609 ptr = mtod(m_asconf, caddr_t); /* beginning of cluster */
2611 /* fill in chunk header info */
2612 acp->ch.chunk_type = SCTP_ASCONF;
2613 acp->ch.chunk_flags = 0;
2614 acp->serial_number = htonl(stcb->asoc.asconf_seq_out);
2615 stcb->asoc.asconf_seq_out++;
2617 /* add parameters... up to smallest MTU allowed */
2618 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
2621 /* get the parameter length */
2622 p_length = SCTP_SIZE32(aa->ap.aph.ph.param_length);
2623 /* will it fit in current chunk? */
2624 if ((SCTP_BUF_LEN(m_asconf) + p_length > stcb->asoc.smallest_mtu) ||
2625 (SCTP_BUF_LEN(m_asconf) + p_length > MCLBYTES)) {
2626 /* won't fit, so we're done with this chunk */
2629 /* assign (and store) a correlation id */
2630 aa->ap.aph.correlation_id = correlation_id++;
2633 * fill in address if we're doing a delete this is a simple
2634 * way for us to fill in the correlation address, which
2635 * should only be used by the peer if we're deleting our
2636 * source address and adding a new address (e.g. renumbering
2639 if (lookup_used == 0 &&
2640 (aa->special_del == 0) &&
2641 aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) {
2642 struct sctp_ipv6addr_param *lookup;
2643 uint16_t p_size, addr_size;
2645 lookup = (struct sctp_ipv6addr_param *)lookup_ptr;
2646 lookup->ph.param_type =
2647 htons(aa->ap.addrp.ph.param_type);
2648 if (aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) {
2649 /* copy IPv6 address */
2650 p_size = sizeof(struct sctp_ipv6addr_param);
2651 addr_size = sizeof(struct in6_addr);
2653 /* copy IPv4 address */
2654 p_size = sizeof(struct sctp_ipv4addr_param);
2655 addr_size = sizeof(struct in_addr);
2657 lookup->ph.param_length = htons(SCTP_SIZE32(p_size));
2658 memcpy(lookup->addr, &aa->ap.addrp.addr, addr_size);
2659 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size);
2662 /* copy into current space */
2663 memcpy(ptr, &aa->ap, p_length);
2665 /* network elements and update lengths */
2666 aph = (struct sctp_asconf_paramhdr *)ptr;
2667 aap = (struct sctp_asconf_addr_param *)ptr;
2668 /* correlation_id is transparent to peer, no htonl needed */
2669 aph->ph.param_type = htons(aph->ph.param_type);
2670 aph->ph.param_length = htons(aph->ph.param_length);
2671 aap->addrp.ph.param_type = htons(aap->addrp.ph.param_type);
2672 aap->addrp.ph.param_length = htons(aap->addrp.ph.param_length);
2674 SCTP_BUF_LEN(m_asconf) += SCTP_SIZE32(p_length);
2675 ptr += SCTP_SIZE32(p_length);
2678 * these params are removed off the pending list upon
2679 * getting an ASCONF-ACK back from the peer, just set flag
2683 /* check to see if the lookup addr has been populated yet */
2684 if (lookup_used == 0) {
2685 /* NOTE: if the address param is optional, can skip this... */
2686 /* add any valid (existing) address... */
2687 struct sctp_ipv6addr_param *lookup;
2688 uint16_t p_size, addr_size;
2689 struct sockaddr *found_addr;
2692 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL)
2693 found_addr = sctp_find_valid_localaddr(stcb,
2696 found_addr = sctp_find_valid_localaddr_ep(stcb);
2698 lookup = (struct sctp_ipv6addr_param *)lookup_ptr;
2699 if (found_addr != NULL) {
2700 switch (found_addr->sa_family) {
2703 /* copy IPv6 address */
2704 lookup->ph.param_type =
2705 htons(SCTP_IPV6_ADDRESS);
2706 p_size = sizeof(struct sctp_ipv6addr_param);
2707 addr_size = sizeof(struct in6_addr);
2708 addr_ptr = (caddr_t)&((struct sockaddr_in6 *)
2709 found_addr)->sin6_addr;
2714 /* copy IPv4 address */
2715 lookup->ph.param_type =
2716 htons(SCTP_IPV4_ADDRESS);
2717 p_size = sizeof(struct sctp_ipv4addr_param);
2718 addr_size = sizeof(struct in_addr);
2719 addr_ptr = (caddr_t)&((struct sockaddr_in *)
2720 found_addr)->sin_addr;
2729 lookup->ph.param_length = htons(SCTP_SIZE32(p_size));
2730 memcpy(lookup->addr, addr_ptr, addr_size);
2731 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size);
2733 /* uh oh... don't have any address?? */
2734 SCTPDBG(SCTP_DEBUG_ASCONF1,
2735 "compose_asconf: no lookup addr!\n");
2736 /* XXX for now, we send a IPv4 address of 0.0.0.0 */
2737 lookup->ph.param_type = htons(SCTP_IPV4_ADDRESS);
2738 lookup->ph.param_length = htons(SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param)));
2739 memset(lookup->addr, 0, sizeof(struct in_addr));
2740 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param));
2743 /* chain it all together */
2744 SCTP_BUF_NEXT(m_asconf_chk) = m_asconf;
2745 *retlen = SCTP_BUF_LEN(m_asconf_chk) + SCTP_BUF_LEN(m_asconf);
2746 acp->ch.chunk_length = htons(*retlen);
2748 return (m_asconf_chk);
2752 * section to handle address changes before an association is up eg. changes
2753 * during INIT/INIT-ACK/COOKIE-ECHO handshake
2757 * processes the (local) addresses in the INIT-ACK chunk
2760 sctp_process_initack_addresses(struct sctp_tcb *stcb, struct mbuf *m,
2761 unsigned int offset, unsigned int length)
2763 struct sctp_paramhdr tmp_param, *ph;
2764 uint16_t plen, ptype;
2765 struct sctp_ifa *sctp_ifa;
2766 union sctp_sockstore store;
2768 struct sctp_ipv6addr_param addr6_store;
2771 struct sctp_ipv4addr_param addr4_store;
2774 SCTPDBG(SCTP_DEBUG_ASCONF2, "processing init-ack addresses\n");
2775 if (stcb == NULL) /* Un-needed check for SA */
2778 /* convert to upper bound */
2781 if ((offset + sizeof(struct sctp_paramhdr)) > length) {
2784 /* go through the addresses in the init-ack */
2785 ph = (struct sctp_paramhdr *)
2786 sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr),
2787 (uint8_t *)&tmp_param);
2788 while (ph != NULL) {
2789 ptype = ntohs(ph->param_type);
2790 plen = ntohs(ph->param_length);
2793 case SCTP_IPV6_ADDRESS:
2795 struct sctp_ipv6addr_param *a6p;
2797 /* get the entire IPv6 address param */
2798 a6p = (struct sctp_ipv6addr_param *)
2799 sctp_m_getptr(m, offset,
2800 sizeof(struct sctp_ipv6addr_param),
2801 (uint8_t *)&addr6_store);
2802 if (plen != sizeof(struct sctp_ipv6addr_param) ||
2806 memset(&store, 0, sizeof(union sctp_sockstore));
2807 store.sin6.sin6_family = AF_INET6;
2808 store.sin6.sin6_len = sizeof(struct sockaddr_in6);
2809 store.sin6.sin6_port = stcb->rport;
2810 memcpy(&store.sin6.sin6_addr, a6p->addr, sizeof(struct in6_addr));
2815 case SCTP_IPV4_ADDRESS:
2817 struct sctp_ipv4addr_param *a4p;
2819 /* get the entire IPv4 address param */
2820 a4p = (struct sctp_ipv4addr_param *)sctp_m_getptr(m, offset,
2821 sizeof(struct sctp_ipv4addr_param),
2822 (uint8_t *)&addr4_store);
2823 if (plen != sizeof(struct sctp_ipv4addr_param) ||
2827 memset(&store, 0, sizeof(union sctp_sockstore));
2828 store.sin.sin_family = AF_INET;
2829 store.sin.sin_len = sizeof(struct sockaddr_in);
2830 store.sin.sin_port = stcb->rport;
2831 store.sin.sin_addr.s_addr = a4p->addr;
2839 /* see if this address really (still) exists */
2840 sctp_ifa = sctp_find_ifa_by_addr(&store.sa, stcb->asoc.vrf_id,
2841 SCTP_ADDR_NOT_LOCKED);
2842 if (sctp_ifa == NULL) {
2843 /* address doesn't exist anymore */
2846 /* are ASCONFs allowed ? */
2847 if ((sctp_is_feature_on(stcb->sctp_ep,
2848 SCTP_PCB_FLAGS_DO_ASCONF)) &&
2849 stcb->asoc.asconf_supported) {
2850 /* queue an ASCONF DEL_IP_ADDRESS */
2851 status = sctp_asconf_queue_sa_delete(stcb, &store.sa);
2853 * if queued ok, and in correct state, send
2857 SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) {
2858 #ifdef SCTP_TIMER_BASED_ASCONF
2859 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
2860 stcb->sctp_ep, stcb,
2861 stcb->asoc.primary_destination);
2863 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2871 * Sanity check: Make sure the length isn't 0, otherwise
2872 * we'll be stuck in this loop for a long time...
2874 if (SCTP_SIZE32(plen) == 0) {
2875 SCTP_PRINTF("process_initack_addrs: bad len (%d) type=%xh\n",
2879 /* get next parameter */
2880 offset += SCTP_SIZE32(plen);
2881 if ((offset + sizeof(struct sctp_paramhdr)) > length)
2883 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset,
2884 sizeof(struct sctp_paramhdr), (uint8_t *)&tmp_param);
2888 /* FIX ME: need to verify return result for v6 address type if v6 disabled */
2890 * checks to see if a specific address is in the initack address list returns
2891 * 1 if found, 0 if not
2894 sctp_addr_in_initack(struct mbuf *m, uint32_t offset, uint32_t length, struct sockaddr *sa)
2896 struct sctp_paramhdr tmp_param, *ph;
2897 uint16_t plen, ptype;
2899 struct sockaddr_in *sin;
2900 struct sctp_ipv4addr_param *a4p;
2901 struct sctp_ipv6addr_param addr4_store;
2904 struct sockaddr_in6 *sin6;
2905 struct sctp_ipv6addr_param *a6p;
2906 struct sctp_ipv6addr_param addr6_store;
2907 struct sockaddr_in6 sin6_tmp;
2910 switch (sa->sa_family) {
2923 SCTPDBG(SCTP_DEBUG_ASCONF2, "find_initack_addr: starting search for ");
2924 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, sa);
2925 /* convert to upper bound */
2928 if ((offset + sizeof(struct sctp_paramhdr)) > length) {
2929 SCTPDBG(SCTP_DEBUG_ASCONF1,
2930 "find_initack_addr: invalid offset?\n");
2933 /* go through the addresses in the init-ack */
2934 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset,
2935 sizeof(struct sctp_paramhdr), (uint8_t *)&tmp_param);
2936 while (ph != NULL) {
2937 ptype = ntohs(ph->param_type);
2938 plen = ntohs(ph->param_length);
2941 case SCTP_IPV6_ADDRESS:
2942 if (sa->sa_family == AF_INET6) {
2943 /* get the entire IPv6 address param */
2944 if (plen != sizeof(struct sctp_ipv6addr_param)) {
2947 /* get the entire IPv6 address param */
2948 a6p = (struct sctp_ipv6addr_param *)
2949 sctp_m_getptr(m, offset,
2950 sizeof(struct sctp_ipv6addr_param),
2951 (uint8_t *)&addr6_store);
2955 sin6 = (struct sockaddr_in6 *)sa;
2956 if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr)) {
2957 /* create a copy and clear scope */
2958 memcpy(&sin6_tmp, sin6,
2959 sizeof(struct sockaddr_in6));
2961 in6_clearscope(&sin6->sin6_addr);
2963 if (memcmp(&sin6->sin6_addr, a6p->addr,
2964 sizeof(struct in6_addr)) == 0) {
2972 case SCTP_IPV4_ADDRESS:
2973 if (sa->sa_family == AF_INET) {
2974 if (plen != sizeof(struct sctp_ipv4addr_param)) {
2977 /* get the entire IPv4 address param */
2978 a4p = (struct sctp_ipv4addr_param *)
2979 sctp_m_getptr(m, offset,
2980 sizeof(struct sctp_ipv4addr_param),
2981 (uint8_t *)&addr4_store);
2985 sin = (struct sockaddr_in *)sa;
2986 if (sin->sin_addr.s_addr == a4p->addr) {
2996 /* get next parameter */
2997 offset += SCTP_SIZE32(plen);
2998 if (offset + sizeof(struct sctp_paramhdr) > length) {
3001 ph = (struct sctp_paramhdr *)
3002 sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr),
3003 (uint8_t *)&tmp_param);
3010 * makes sure that the current endpoint local addr list is consistent with
3011 * the new association (eg. subset bound, asconf allowed) adds addresses as
3015 sctp_check_address_list_ep(struct sctp_tcb *stcb, struct mbuf *m, int offset,
3016 int length, struct sockaddr *init_addr)
3018 struct sctp_laddr *laddr;
3020 /* go through the endpoint list */
3021 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
3022 /* be paranoid and validate the laddr */
3023 if (laddr->ifa == NULL) {
3024 SCTPDBG(SCTP_DEBUG_ASCONF1,
3025 "check_addr_list_ep: laddr->ifa is NULL");
3028 /* do i have it implicitly? */
3029 if (sctp_cmpaddr(&laddr->ifa->address.sa, init_addr)) {
3032 /* check to see if in the init-ack */
3033 if (!sctp_addr_in_initack(m, offset, length, &laddr->ifa->address.sa)) {
3035 sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb, laddr->ifa,
3036 SCTP_ADD_IP_ADDRESS, SCTP_ADDR_NOT_LOCKED);
3042 * makes sure that the current kernel address list is consistent with the new
3043 * association (with all addrs bound) adds addresses as necessary
3046 sctp_check_address_list_all(struct sctp_tcb *stcb, struct mbuf *m, int offset,
3047 int length, struct sockaddr *init_addr,
3048 uint16_t local_scope, uint16_t site_scope,
3049 uint16_t ipv4_scope, uint16_t loopback_scope)
3051 struct sctp_vrf *vrf = NULL;
3052 struct sctp_ifn *sctp_ifn;
3053 struct sctp_ifa *sctp_ifa;
3056 struct sockaddr_in *sin;
3059 struct sockaddr_in6 *sin6;
3063 vrf_id = stcb->asoc.vrf_id;
3067 SCTP_IPI_ADDR_RLOCK();
3068 vrf = sctp_find_vrf(vrf_id);
3070 SCTP_IPI_ADDR_RUNLOCK();
3073 /* go through all our known interfaces */
3074 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
3075 if (loopback_scope == 0 && SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
3076 /* skip loopback interface */
3079 /* go through each interface address */
3080 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
3081 /* do i have it implicitly? */
3082 if (sctp_cmpaddr(&sctp_ifa->address.sa, init_addr)) {
3085 switch (sctp_ifa->address.sa.sa_family) {
3088 sin = &sctp_ifa->address.sin;
3089 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
3090 &sin->sin_addr) != 0) {
3093 if ((ipv4_scope == 0) &&
3094 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
3095 /* private address not in scope */
3102 sin6 = &sctp_ifa->address.sin6;
3103 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
3104 &sin6->sin6_addr) != 0) {
3107 if ((local_scope == 0) &&
3108 (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))) {
3111 if ((site_scope == 0) &&
3112 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
3120 /* check to see if in the init-ack */
3121 if (!sctp_addr_in_initack(m, offset, length, &sctp_ifa->address.sa)) {
3123 sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb,
3124 sctp_ifa, SCTP_ADD_IP_ADDRESS,
3127 } /* end foreach ifa */
3128 } /* end foreach ifn */
3129 SCTP_IPI_ADDR_RUNLOCK();
3133 * validates an init-ack chunk (from a cookie-echo) with current addresses
3134 * adds addresses from the init-ack into our local address list, if needed
3135 * queues asconf adds/deletes addresses as needed and makes appropriate list
3136 * changes for source address selection m, offset: points to the start of the
3137 * address list in an init-ack chunk length: total length of the address
3138 * params only init_addr: address where my INIT-ACK was sent from
3141 sctp_check_address_list(struct sctp_tcb *stcb, struct mbuf *m, int offset,
3142 int length, struct sockaddr *init_addr,
3143 uint16_t local_scope, uint16_t site_scope,
3144 uint16_t ipv4_scope, uint16_t loopback_scope)
3146 /* process the local addresses in the initack */
3147 sctp_process_initack_addresses(stcb, m, offset, length);
3149 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3150 /* bound all case */
3151 sctp_check_address_list_all(stcb, m, offset, length, init_addr,
3152 local_scope, site_scope, ipv4_scope, loopback_scope);
3154 /* subset bound case */
3155 if (sctp_is_feature_on(stcb->sctp_ep,
3156 SCTP_PCB_FLAGS_DO_ASCONF)) {
3157 /* asconf's allowed */
3158 sctp_check_address_list_ep(stcb, m, offset, length,
3161 /* else, no asconfs allowed, so what we sent is what we get */
3166 * sctp_bindx() support
3169 sctp_addr_mgmt_ep_sa(struct sctp_inpcb *inp, struct sockaddr *sa,
3170 uint32_t type, uint32_t vrf_id, struct sctp_ifa *sctp_ifap)
3172 struct sctp_ifa *ifa;
3173 struct sctp_laddr *laddr, *nladdr;
3175 if (sa->sa_len == 0) {
3176 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EINVAL);
3181 } else if (type == SCTP_ADD_IP_ADDRESS) {
3182 /* For an add the address MUST be on the system */
3183 ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED);
3184 } else if (type == SCTP_DEL_IP_ADDRESS) {
3185 /* For a delete we need to find it in the inp */
3186 ifa = sctp_find_ifa_in_ep(inp, sa, SCTP_ADDR_NOT_LOCKED);
3191 if (type == SCTP_ADD_IP_ADDRESS) {
3192 sctp_add_local_addr_ep(inp, ifa, type);
3193 } else if (type == SCTP_DEL_IP_ADDRESS) {
3194 if (inp->laddr_count < 2) {
3195 /* can't delete the last local address */
3196 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EINVAL);
3199 LIST_FOREACH(laddr, &inp->sctp_addr_list,
3201 if (ifa == laddr->ifa) {
3202 /* Mark in the delete */
3203 laddr->action = type;
3207 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
3209 * There is no need to start the iterator if the inp
3210 * has no associations.
3212 if (type == SCTP_DEL_IP_ADDRESS) {
3213 LIST_FOREACH_SAFE(laddr, &inp->sctp_addr_list, sctp_nxt_addr, nladdr) {
3214 if (laddr->ifa == ifa) {
3215 sctp_del_local_addr_ep(inp, ifa);
3220 struct sctp_asconf_iterator *asc;
3221 struct sctp_laddr *wi;
3224 SCTP_MALLOC(asc, struct sctp_asconf_iterator *,
3225 sizeof(struct sctp_asconf_iterator),
3228 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, ENOMEM);
3231 wi = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_laddr), struct sctp_laddr);
3233 SCTP_FREE(asc, SCTP_M_ASC_IT);
3234 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, ENOMEM);
3237 LIST_INIT(&asc->list_of_work);
3239 SCTP_INCR_LADDR_COUNT();
3242 atomic_add_int(&ifa->refcount, 1);
3243 LIST_INSERT_HEAD(&asc->list_of_work, wi, sctp_nxt_addr);
3244 ret = sctp_initiate_iterator(sctp_asconf_iterator_ep,
3245 sctp_asconf_iterator_stcb,
3246 sctp_asconf_iterator_ep_end,
3248 SCTP_PCB_ANY_FEATURES,
3249 SCTP_ASOC_ANY_STATE,
3251 sctp_asconf_iterator_end, inp, 0);
3253 SCTP_PRINTF("Failed to initiate iterator for addr_mgmt_ep_sa\n");
3254 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EFAULT);
3255 sctp_asconf_iterator_end(asc, 0);
3261 /* invalid address! */
3262 SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EADDRNOTAVAIL);
3263 return (EADDRNOTAVAIL);
3268 sctp_asconf_send_nat_state_update(struct sctp_tcb *stcb,
3269 struct sctp_nets *net)
3271 struct sctp_asconf_addr *aa;
3272 struct sctp_ifa *sctp_ifap;
3273 struct sctp_asconf_tag_param *vtag;
3275 struct sockaddr_in *to;
3278 struct sockaddr_in6 *to6;
3281 SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing net\n");
3285 SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing stcb\n");
3289 * Need to have in the asconf: - vtagparam(my_vtag/peer_vtag) -
3290 * add(0.0.0.0) - del(0.0.0.0) - Any global addresses add(addr)
3292 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
3295 /* didn't get memory */
3296 SCTPDBG(SCTP_DEBUG_ASCONF1,
3297 "sctp_asconf_send_nat_state_update: failed to get memory!\n");
3300 aa->special_del = 0;
3301 /* fill in asconf address parameter fields */
3302 /* top level elements are "networked" during send */
3304 aa->sent = 0; /* clear sent flag */
3305 vtag = (struct sctp_asconf_tag_param *)&aa->ap.aph;
3306 vtag->aph.ph.param_type = SCTP_NAT_VTAGS;
3307 vtag->aph.ph.param_length = sizeof(struct sctp_asconf_tag_param);
3308 vtag->local_vtag = htonl(stcb->asoc.my_vtag);
3309 vtag->remote_vtag = htonl(stcb->asoc.peer_vtag);
3310 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
3312 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
3315 /* didn't get memory */
3316 SCTPDBG(SCTP_DEBUG_ASCONF1,
3317 "sctp_asconf_send_nat_state_update: failed to get memory!\n");
3320 memset(aa, 0, sizeof(struct sctp_asconf_addr));
3321 /* fill in asconf address parameter fields */
3323 switch (net->ro._l_addr.sa.sa_family) {
3326 aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
3327 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param);
3328 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
3329 aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv4addr_param);
3330 /* No need to add an address, we are using 0.0.0.0 */
3331 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
3336 aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
3337 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param);
3338 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
3339 aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv6addr_param);
3340 /* No need to add an address, we are using 0.0.0.0 */
3341 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
3345 SCTPDBG(SCTP_DEBUG_ASCONF1,
3346 "sctp_asconf_send_nat_state_update: unknown address family\n");
3347 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
3350 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
3353 /* didn't get memory */
3354 SCTPDBG(SCTP_DEBUG_ASCONF1,
3355 "sctp_asconf_send_nat_state_update: failed to get memory!\n");
3358 memset(aa, 0, sizeof(struct sctp_asconf_addr));
3359 /* fill in asconf address parameter fields */
3361 switch (net->ro._l_addr.sa.sa_family) {
3364 aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
3365 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param);
3366 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
3367 aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv4addr_param);
3368 /* No need to add an address, we are using 0.0.0.0 */
3369 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
3374 aa->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS;
3375 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param);
3376 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
3377 aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv6addr_param);
3378 /* No need to add an address, we are using 0.0.0.0 */
3379 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
3383 SCTPDBG(SCTP_DEBUG_ASCONF1,
3384 "sctp_asconf_send_nat_state_update: unknown address family\n");
3385 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
3388 /* Now we must hunt the addresses and add all global addresses */
3389 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3390 struct sctp_vrf *vrf = NULL;
3391 struct sctp_ifn *sctp_ifnp;
3394 vrf_id = stcb->sctp_ep->def_vrf_id;
3395 vrf = sctp_find_vrf(vrf_id);
3400 SCTP_IPI_ADDR_RLOCK();
3401 LIST_FOREACH(sctp_ifnp, &vrf->ifnlist, next_ifn) {
3402 LIST_FOREACH(sctp_ifap, &sctp_ifnp->ifalist, next_ifa) {
3403 switch (sctp_ifap->address.sa.sa_family) {
3406 to = &sctp_ifap->address.sin;
3407 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
3408 &to->sin_addr) != 0) {
3411 if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) {
3414 if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) {
3421 to6 = &sctp_ifap->address.sin6;
3422 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
3423 &to6->sin6_addr) != 0) {
3426 if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) {
3429 if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) {
3437 sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS);
3440 SCTP_IPI_ADDR_RUNLOCK();
3442 struct sctp_laddr *laddr;
3444 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
3445 if (laddr->ifa == NULL) {
3448 if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED)
3450 * Address being deleted by the system, dont
3454 if (laddr->action == SCTP_DEL_IP_ADDRESS) {
3456 * Address being deleted on this ep don't
3461 sctp_ifap = laddr->ifa;
3462 switch (sctp_ifap->address.sa.sa_family) {
3465 to = &sctp_ifap->address.sin;
3466 if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) {
3469 if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) {
3476 to6 = &sctp_ifap->address.sin6;
3477 if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) {
3480 if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) {
3488 sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS);
3492 /* Now we must send the asconf into the queue */
3493 sctp_send_asconf(stcb, net, SCTP_ADDR_NOT_LOCKED);