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;
110 m_reply = sctp_get_mbuf_for_msg((sizeof(struct sctp_asconf_paramhdr) +
112 sizeof(struct sctp_error_cause)),
113 0, M_NOWAIT, 1, MT_DATA);
114 if (m_reply == NULL) {
115 SCTPDBG(SCTP_DEBUG_ASCONF1,
116 "asconf_error_response: couldn't get mbuf!\n");
119 aph = mtod(m_reply, struct sctp_asconf_paramhdr *);
120 error = (struct sctp_error_cause *)(aph + 1);
122 aph->correlation_id = id;
123 aph->ph.param_type = htons(SCTP_ERROR_CAUSE_IND);
124 error->code = htons(cause);
125 error->length = tlv_length + sizeof(struct sctp_error_cause);
126 aph->ph.param_length = error->length +
127 sizeof(struct sctp_asconf_paramhdr);
129 if (aph->ph.param_length > MLEN) {
130 SCTPDBG(SCTP_DEBUG_ASCONF1,
131 "asconf_error_response: tlv_length (%xh) too big\n",
133 sctp_m_freem(m_reply); /* discard */
136 if (error_tlv != NULL) {
137 tlv = (uint8_t *)(error + 1);
138 memcpy(tlv, error_tlv, tlv_length);
140 SCTP_BUF_LEN(m_reply) = aph->ph.param_length;
141 error->length = htons(error->length);
142 aph->ph.param_length = htons(aph->ph.param_length);
148 sctp_process_asconf_add_ip(struct sockaddr *src, struct sctp_asconf_paramhdr *aph,
149 struct sctp_tcb *stcb, int send_hb, int response_required)
151 struct sctp_nets *net;
152 struct mbuf *m_reply = NULL;
153 union sctp_sockstore store;
154 struct sctp_paramhdr *ph;
155 uint16_t param_type, aparam_length;
156 #if defined(INET) || defined(INET6)
157 uint16_t param_length;
160 int zero_address = 0;
163 struct sockaddr_in *sin;
164 struct sctp_ipv4addr_param *v4addr;
167 struct sockaddr_in6 *sin6;
168 struct sctp_ipv6addr_param *v6addr;
171 aparam_length = ntohs(aph->ph.param_length);
172 ph = (struct sctp_paramhdr *)(aph + 1);
173 param_type = ntohs(ph->param_type);
174 #if defined(INET) || defined(INET6)
175 param_length = ntohs(ph->param_length);
178 switch (param_type) {
180 case SCTP_IPV4_ADDRESS:
181 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
182 /* invalid param size */
185 v4addr = (struct sctp_ipv4addr_param *)ph;
187 memset(sin, 0, sizeof(*sin));
188 sin->sin_family = AF_INET;
189 sin->sin_len = sizeof(struct sockaddr_in);
190 sin->sin_port = stcb->rport;
191 sin->sin_addr.s_addr = v4addr->addr;
192 if ((sin->sin_addr.s_addr == INADDR_BROADCAST) ||
193 IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) {
196 if (sin->sin_addr.s_addr == INADDR_ANY)
198 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_add_ip: adding ");
199 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
203 case SCTP_IPV6_ADDRESS:
204 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
205 /* invalid param size */
208 v6addr = (struct sctp_ipv6addr_param *)ph;
210 memset(sin6, 0, sizeof(*sin6));
211 sin6->sin6_family = AF_INET6;
212 sin6->sin6_len = sizeof(struct sockaddr_in6);
213 sin6->sin6_port = stcb->rport;
214 memcpy((caddr_t)&sin6->sin6_addr, v6addr->addr,
215 sizeof(struct in6_addr));
216 if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
219 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
221 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_add_ip: adding ");
222 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
226 m_reply = sctp_asconf_error_response(aph->correlation_id,
227 SCTP_CAUSE_INVALID_PARAM, (uint8_t *)aph,
232 /* if 0.0.0.0/::0, add the source address instead */
233 if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) {
235 SCTPDBG(SCTP_DEBUG_ASCONF1,
236 "process_asconf_add_ip: using source addr ");
237 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, src);
239 /* add the address */
241 m_reply = sctp_asconf_error_response(aph->correlation_id,
242 SCTP_CAUSE_INVALID_PARAM, (uint8_t *)aph,
244 } else if (sctp_add_remote_addr(stcb, sa, &net, stcb->asoc.port,
246 SCTP_ADDR_DYNAMIC_ADDED) != 0) {
247 SCTPDBG(SCTP_DEBUG_ASCONF1,
248 "process_asconf_add_ip: error adding address\n");
249 m_reply = sctp_asconf_error_response(aph->correlation_id,
250 SCTP_CAUSE_RESOURCE_SHORTAGE, (uint8_t *)aph,
253 /* notify upper layer */
254 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_ADD_IP, stcb, 0, sa, SCTP_SO_NOT_LOCKED);
255 if (response_required) {
257 sctp_asconf_success_response(aph->correlation_id);
259 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, stcb->sctp_ep, stcb, net);
260 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep,
263 sctp_send_hb(stcb, net, SCTP_SO_NOT_LOCKED);
270 sctp_asconf_del_remote_addrs_except(struct sctp_tcb *stcb, struct sockaddr *src)
272 struct sctp_nets *src_net, *net;
274 /* make sure the source address exists as a destination net */
275 src_net = sctp_findnet(stcb, src);
276 if (src_net == NULL) {
280 /* delete all destination addresses except the source */
281 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
282 if (net != src_net) {
283 /* delete this address */
284 sctp_remove_net(stcb, net);
285 SCTPDBG(SCTP_DEBUG_ASCONF1,
286 "asconf_del_remote_addrs_except: deleting ");
287 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1,
288 (struct sockaddr *)&net->ro._l_addr);
289 /* notify upper layer */
290 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0,
291 (struct sockaddr *)&net->ro._l_addr, SCTP_SO_NOT_LOCKED);
298 sctp_process_asconf_delete_ip(struct sockaddr *src,
299 struct sctp_asconf_paramhdr *aph,
300 struct sctp_tcb *stcb, int response_required)
302 struct mbuf *m_reply = NULL;
303 union sctp_sockstore store;
304 struct sctp_paramhdr *ph;
305 uint16_t param_type, aparam_length;
306 #if defined(INET) || defined(INET6)
307 uint16_t param_length;
310 int zero_address = 0;
313 struct sockaddr_in *sin;
314 struct sctp_ipv4addr_param *v4addr;
317 struct sockaddr_in6 *sin6;
318 struct sctp_ipv6addr_param *v6addr;
321 aparam_length = ntohs(aph->ph.param_length);
322 ph = (struct sctp_paramhdr *)(aph + 1);
323 param_type = ntohs(ph->param_type);
324 #if defined(INET) || defined(INET6)
325 param_length = ntohs(ph->param_length);
328 switch (param_type) {
330 case SCTP_IPV4_ADDRESS:
331 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
332 /* invalid param size */
335 v4addr = (struct sctp_ipv4addr_param *)ph;
337 memset(sin, 0, sizeof(*sin));
338 sin->sin_family = AF_INET;
339 sin->sin_len = sizeof(struct sockaddr_in);
340 sin->sin_port = stcb->rport;
341 sin->sin_addr.s_addr = v4addr->addr;
342 if (sin->sin_addr.s_addr == INADDR_ANY)
344 SCTPDBG(SCTP_DEBUG_ASCONF1,
345 "process_asconf_delete_ip: deleting ");
346 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
350 case SCTP_IPV6_ADDRESS:
351 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
352 /* invalid param size */
355 v6addr = (struct sctp_ipv6addr_param *)ph;
357 memset(sin6, 0, sizeof(*sin6));
358 sin6->sin6_family = AF_INET6;
359 sin6->sin6_len = sizeof(struct sockaddr_in6);
360 sin6->sin6_port = stcb->rport;
361 memcpy(&sin6->sin6_addr, v6addr->addr,
362 sizeof(struct in6_addr));
363 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
365 SCTPDBG(SCTP_DEBUG_ASCONF1,
366 "process_asconf_delete_ip: deleting ");
367 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
371 m_reply = sctp_asconf_error_response(aph->correlation_id,
372 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *)aph,
377 /* make sure the source address is not being deleted */
378 if (sctp_cmpaddr(sa, src)) {
379 /* trying to delete the source address! */
380 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: tried to delete source addr\n");
381 m_reply = sctp_asconf_error_response(aph->correlation_id,
382 SCTP_CAUSE_DELETING_SRC_ADDR, (uint8_t *)aph,
386 /* if deleting 0.0.0.0/::0, delete all addresses except src addr */
387 if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) {
388 result = sctp_asconf_del_remote_addrs_except(stcb, src);
391 /* src address did not exist? */
392 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: src addr does not exist?\n");
393 /* what error to reply with?? */
395 sctp_asconf_error_response(aph->correlation_id,
396 SCTP_CAUSE_REQUEST_REFUSED, (uint8_t *)aph,
398 } else if (response_required) {
400 sctp_asconf_success_response(aph->correlation_id);
404 /* delete the address */
405 result = sctp_del_remote_addr(stcb, sa);
407 * note if result == -2, the address doesn't exist in the asoc but
408 * since it's being deleted anyways, we just ack the delete -- but
409 * this probably means something has already gone awry
412 /* only one address in the asoc */
413 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: tried to delete last IP addr!\n");
414 m_reply = sctp_asconf_error_response(aph->correlation_id,
415 SCTP_CAUSE_DELETING_LAST_ADDR, (uint8_t *)aph,
418 if (response_required) {
419 m_reply = sctp_asconf_success_response(aph->correlation_id);
421 /* notify upper layer */
422 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0, sa, SCTP_SO_NOT_LOCKED);
428 sctp_process_asconf_set_primary(struct sockaddr *src,
429 struct sctp_asconf_paramhdr *aph,
430 struct sctp_tcb *stcb, int response_required)
432 struct mbuf *m_reply = NULL;
433 union sctp_sockstore store;
434 struct sctp_paramhdr *ph;
435 uint16_t param_type, aparam_length;
436 #if defined(INET) || defined(INET6)
437 uint16_t param_length;
440 int zero_address = 0;
442 struct sockaddr_in *sin;
443 struct sctp_ipv4addr_param *v4addr;
446 struct sockaddr_in6 *sin6;
447 struct sctp_ipv6addr_param *v6addr;
450 aparam_length = ntohs(aph->ph.param_length);
451 ph = (struct sctp_paramhdr *)(aph + 1);
452 param_type = ntohs(ph->param_type);
453 #if defined(INET) || defined(INET6)
454 param_length = ntohs(ph->param_length);
457 switch (param_type) {
459 case SCTP_IPV4_ADDRESS:
460 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
461 /* invalid param size */
464 v4addr = (struct sctp_ipv4addr_param *)ph;
466 memset(sin, 0, sizeof(*sin));
467 sin->sin_family = AF_INET;
468 sin->sin_len = sizeof(struct sockaddr_in);
469 sin->sin_addr.s_addr = v4addr->addr;
470 if (sin->sin_addr.s_addr == INADDR_ANY)
472 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_set_primary: ");
473 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
477 case SCTP_IPV6_ADDRESS:
478 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
479 /* invalid param size */
482 v6addr = (struct sctp_ipv6addr_param *)ph;
484 memset(sin6, 0, sizeof(*sin6));
485 sin6->sin6_family = AF_INET6;
486 sin6->sin6_len = sizeof(struct sockaddr_in6);
487 memcpy((caddr_t)&sin6->sin6_addr, v6addr->addr,
488 sizeof(struct in6_addr));
489 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
491 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_set_primary: ");
492 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
496 m_reply = sctp_asconf_error_response(aph->correlation_id,
497 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *)aph,
502 /* if 0.0.0.0/::0, use the source address instead */
503 if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) {
505 SCTPDBG(SCTP_DEBUG_ASCONF1,
506 "process_asconf_set_primary: using source addr ");
507 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, src);
509 /* set the primary address */
510 if (sctp_set_primary_addr(stcb, sa, NULL) == 0) {
511 SCTPDBG(SCTP_DEBUG_ASCONF1,
512 "process_asconf_set_primary: primary address set\n");
513 /* notify upper layer */
514 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_SET_PRIMARY, stcb, 0, sa, SCTP_SO_NOT_LOCKED);
515 if ((stcb->asoc.primary_destination->dest_state & SCTP_ADDR_REACHABLE) &&
516 (!(stcb->asoc.primary_destination->dest_state & SCTP_ADDR_PF)) &&
517 (stcb->asoc.alternate)) {
518 sctp_free_remote_addr(stcb->asoc.alternate);
519 stcb->asoc.alternate = NULL;
521 if (response_required) {
522 m_reply = sctp_asconf_success_response(aph->correlation_id);
525 * Mobility adaptation. Ideally, when the reception of SET
526 * PRIMARY with DELETE IP ADDRESS of the previous primary
527 * destination, unacknowledged DATA are retransmitted
528 * immediately to the new primary destination for seamless
529 * handover. If the destination is UNCONFIRMED and marked to
530 * REQ_PRIM, The retransmission occur when reception of the
531 * HEARTBEAT-ACK. (See sctp_handle_heartbeat_ack in
532 * sctp_input.c) Also, when change of the primary
533 * destination, it is better that all subsequent new DATA
534 * containing already queued DATA are transmitted to the new
535 * primary destination. (by micchie)
537 if ((sctp_is_mobility_feature_on(stcb->sctp_ep,
538 SCTP_MOBILITY_BASE) ||
539 sctp_is_mobility_feature_on(stcb->sctp_ep,
540 SCTP_MOBILITY_FASTHANDOFF)) &&
541 sctp_is_mobility_feature_on(stcb->sctp_ep,
542 SCTP_MOBILITY_PRIM_DELETED) &&
543 (stcb->asoc.primary_destination->dest_state &
544 SCTP_ADDR_UNCONFIRMED) == 0) {
546 sctp_timer_stop(SCTP_TIMER_TYPE_PRIM_DELETED,
547 stcb->sctp_ep, stcb, NULL,
548 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_1);
549 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
550 SCTP_MOBILITY_FASTHANDOFF)) {
551 sctp_assoc_immediate_retrans(stcb,
552 stcb->asoc.primary_destination);
554 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
555 SCTP_MOBILITY_BASE)) {
556 sctp_move_chunks_from_net(stcb,
557 stcb->asoc.deleted_primary);
559 sctp_delete_prim_timer(stcb->sctp_ep, stcb,
560 stcb->asoc.deleted_primary);
563 /* couldn't set the requested primary address! */
564 SCTPDBG(SCTP_DEBUG_ASCONF1,
565 "process_asconf_set_primary: set primary failed!\n");
566 /* must have been an invalid address, so report */
567 m_reply = sctp_asconf_error_response(aph->correlation_id,
568 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *)aph,
576 * handles an ASCONF chunk.
577 * if all parameters are processed ok, send a plain (empty) ASCONF-ACK
580 sctp_handle_asconf(struct mbuf *m, unsigned int offset,
581 struct sockaddr *src,
582 struct sctp_asconf_chunk *cp, struct sctp_tcb *stcb,
585 struct sctp_association *asoc;
587 struct mbuf *n, *m_ack, *m_result, *m_tail;
588 struct sctp_asconf_ack_chunk *ack_cp;
589 struct sctp_asconf_paramhdr *aph;
590 struct sctp_ipv6addr_param *p_addr;
591 unsigned int asconf_limit, cnt;
592 int error = 0; /* did an error occur? */
594 /* asconf param buffer */
595 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE];
596 struct sctp_asconf_ack *ack, *ack_next;
598 /* verify minimum length */
599 if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_chunk)) {
600 SCTPDBG(SCTP_DEBUG_ASCONF1,
601 "handle_asconf: chunk too small = %xh\n",
602 ntohs(cp->ch.chunk_length));
606 serial_num = ntohl(cp->serial_number);
608 if (SCTP_TSN_GE(asoc->asconf_seq_in, serial_num)) {
609 /* got a duplicate ASCONF */
610 SCTPDBG(SCTP_DEBUG_ASCONF1,
611 "handle_asconf: got duplicate serial number = %xh\n",
614 } else if (serial_num != (asoc->asconf_seq_in + 1)) {
615 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: incorrect serial number = %xh (expected next = %xh)\n",
616 serial_num, asoc->asconf_seq_in + 1);
619 /* it's the expected "next" sequence number, so process it */
620 asoc->asconf_seq_in = serial_num; /* update sequence */
621 /* get length of all the param's in the ASCONF */
622 asconf_limit = offset + ntohs(cp->ch.chunk_length);
623 SCTPDBG(SCTP_DEBUG_ASCONF1,
624 "handle_asconf: asconf_limit=%u, sequence=%xh\n",
625 asconf_limit, serial_num);
628 /* delete old cache */
629 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: Now processing first ASCONF. Try to delete old cache\n");
631 TAILQ_FOREACH_SAFE(ack, &asoc->asconf_ack_sent, next, ack_next) {
632 if (ack->serial_number == serial_num)
634 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: delete old(%u) < first(%u)\n",
635 ack->serial_number, serial_num);
636 TAILQ_REMOVE(&asoc->asconf_ack_sent, ack, next);
637 if (ack->data != NULL) {
638 sctp_m_freem(ack->data);
640 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_asconf_ack), ack);
643 m_ack = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_ack_chunk), 0,
644 M_NOWAIT, 1, MT_DATA);
646 SCTPDBG(SCTP_DEBUG_ASCONF1,
647 "handle_asconf: couldn't get mbuf!\n");
650 m_tail = m_ack; /* current reply chain's tail */
652 /* fill in ASCONF-ACK header */
653 ack_cp = mtod(m_ack, struct sctp_asconf_ack_chunk *);
654 ack_cp->ch.chunk_type = SCTP_ASCONF_ACK;
655 ack_cp->ch.chunk_flags = 0;
656 ack_cp->serial_number = htonl(serial_num);
657 /* set initial lengths (eg. just an ASCONF-ACK), ntohx at the end! */
658 SCTP_BUF_LEN(m_ack) = sizeof(struct sctp_asconf_ack_chunk);
659 ack_cp->ch.chunk_length = sizeof(struct sctp_asconf_ack_chunk);
661 /* skip the lookup address parameter */
662 offset += sizeof(struct sctp_asconf_chunk);
663 p_addr = (struct sctp_ipv6addr_param *)sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), (uint8_t *)&aparam_buf);
664 if (p_addr == NULL) {
665 SCTPDBG(SCTP_DEBUG_ASCONF1,
666 "handle_asconf: couldn't get lookup addr!\n");
667 /* respond with a missing/invalid mandatory parameter error */
670 /* param_length is already validated in process_control... */
671 offset += ntohs(p_addr->ph.param_length); /* skip lookup addr */
672 /* get pointer to first asconf param in ASCONF */
673 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, sizeof(struct sctp_asconf_paramhdr), (uint8_t *)&aparam_buf);
675 SCTPDBG(SCTP_DEBUG_ASCONF1, "Empty ASCONF received?\n");
678 /* process through all parameters */
680 while (aph != NULL) {
681 unsigned int param_length, param_type;
683 param_type = ntohs(aph->ph.param_type);
684 param_length = ntohs(aph->ph.param_length);
685 if (offset + param_length > asconf_limit) {
686 /* parameter goes beyond end of chunk! */
692 if (param_length > sizeof(aparam_buf)) {
693 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) larger than buffer size!\n", param_length);
697 if (param_length <= sizeof(struct sctp_paramhdr)) {
698 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) too short\n", param_length);
701 /* get the entire parameter */
702 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf);
704 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: couldn't get entire param\n");
708 switch (param_type) {
709 case SCTP_ADD_IP_ADDRESS:
710 m_result = sctp_process_asconf_add_ip(src, aph, stcb,
711 (cnt < SCTP_BASE_SYSCTL(sctp_hb_maxburst)), error);
714 case SCTP_DEL_IP_ADDRESS:
715 m_result = sctp_process_asconf_delete_ip(src, aph, stcb,
718 case SCTP_ERROR_CAUSE_IND:
719 /* not valid in an ASCONF chunk */
721 case SCTP_SET_PRIM_ADDR:
722 m_result = sctp_process_asconf_set_primary(src, aph,
726 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: sees a NAT VTAG state parameter\n");
728 case SCTP_SUCCESS_REPORT:
729 /* not valid in an ASCONF chunk */
731 case SCTP_ULP_ADAPTATION:
735 if ((param_type & 0x8000) == 0) {
736 /* Been told to STOP at this param */
737 asconf_limit = offset;
739 * FIX FIX - We need to call
740 * sctp_arethere_unrecognized_parameters()
741 * to get a operr and send it for any
742 * param's with the 0x4000 bit set OR do it
743 * here ourselves... note we still must STOP
744 * if the 0x8000 bit is clear.
747 /* unknown/invalid param type */
751 /* add any (error) result to the reply mbuf chain */
752 if (m_result != NULL) {
753 SCTP_BUF_NEXT(m_tail) = m_result;
755 /* update lengths, make sure it's aligned too */
756 SCTP_BUF_LEN(m_result) = SCTP_SIZE32(SCTP_BUF_LEN(m_result));
757 ack_cp->ch.chunk_length += SCTP_BUF_LEN(m_result);
758 /* set flag to force success reports */
761 offset += SCTP_SIZE32(param_length);
762 /* update remaining ASCONF message length to process */
763 if (offset >= asconf_limit) {
764 /* no more data in the mbuf chain */
767 /* get pointer to next asconf param */
768 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset,
769 sizeof(struct sctp_asconf_paramhdr),
770 (uint8_t *)&aparam_buf);
772 /* can't get an asconf paramhdr */
773 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: can't get asconf param hdr!\n");
774 /* FIX ME - add error here... */
779 ack_cp->ch.chunk_length = htons(ack_cp->ch.chunk_length);
780 /* save the ASCONF-ACK reply */
781 ack = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_asconf_ack),
782 struct sctp_asconf_ack);
787 ack->serial_number = serial_num;
788 ack->last_sent_to = NULL;
791 for (n = m_ack; n != NULL; n = SCTP_BUF_NEXT(n)) {
792 ack->len += SCTP_BUF_LEN(n);
794 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_ack_sent, ack, next);
796 /* see if last_control_chunk_from is set properly (use IP src addr) */
797 if (stcb->asoc.last_control_chunk_from == NULL) {
799 * this could happen if the source address was just newly
802 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: looking up net for IP source address\n");
803 SCTPDBG(SCTP_DEBUG_ASCONF1, "Looking for IP source: ");
804 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, src);
805 /* look up the from address */
806 stcb->asoc.last_control_chunk_from = sctp_findnet(stcb, src);
808 if (stcb->asoc.last_control_chunk_from == NULL) {
809 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: IP source address not found?!\n");
816 * does the address match? returns 0 if not, 1 if so
819 sctp_asconf_addr_match(struct sctp_asconf_addr *aa, struct sockaddr *sa)
821 switch (sa->sa_family) {
826 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
828 if ((aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) &&
829 (memcmp(&aa->ap.addrp.addr, &sin6->sin6_addr,
830 sizeof(struct in6_addr)) == 0)) {
839 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
841 if ((aa->ap.addrp.ph.param_type == SCTP_IPV4_ADDRESS) &&
842 (memcmp(&aa->ap.addrp.addr, &sin->sin_addr,
843 sizeof(struct in_addr)) == 0)) {
856 * does the address match? returns 0 if not, 1 if so
859 sctp_addr_match(struct sctp_paramhdr *ph, struct sockaddr *sa)
861 #if defined(INET) || defined(INET6)
862 uint16_t param_type, param_length;
864 param_type = ntohs(ph->param_type);
865 param_length = ntohs(ph->param_length);
867 switch (sa->sa_family) {
872 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
873 struct sctp_ipv6addr_param *v6addr;
875 v6addr = (struct sctp_ipv6addr_param *)ph;
876 if ((param_type == SCTP_IPV6_ADDRESS) &&
877 (param_length == sizeof(struct sctp_ipv6addr_param)) &&
878 (memcmp(&v6addr->addr, &sin6->sin6_addr,
879 sizeof(struct in6_addr)) == 0)) {
888 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
889 struct sctp_ipv4addr_param *v4addr;
891 v4addr = (struct sctp_ipv4addr_param *)ph;
892 if ((param_type == SCTP_IPV4_ADDRESS) &&
893 (param_length == sizeof(struct sctp_ipv4addr_param)) &&
894 (memcmp(&v4addr->addr, &sin->sin_addr,
895 sizeof(struct in_addr)) == 0)) {
908 * Cleanup for non-responded/OP ERR'd ASCONF
911 sctp_asconf_cleanup(struct sctp_tcb *stcb, struct sctp_nets *net)
914 * clear out any existing asconfs going out
916 sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, net,
917 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_2);
918 stcb->asoc.asconf_seq_out_acked = stcb->asoc.asconf_seq_out;
919 /* remove the old ASCONF on our outbound queue */
920 sctp_toss_old_asconf(stcb);
924 * cleanup any cached source addresses that may be topologically
925 * incorrect after a new address has been added to this interface.
928 sctp_asconf_nets_cleanup(struct sctp_tcb *stcb, struct sctp_ifn *ifn)
930 struct sctp_nets *net;
933 * Ideally, we want to only clear cached routes and source addresses
934 * that are topologically incorrect. But since there is no easy way
935 * to know whether the newly added address on the ifn would cause a
936 * routing change (i.e. a new egress interface would be chosen)
937 * without doing a new routing lookup and source address selection,
938 * we will (for now) just flush any cached route using a different
939 * ifn (and cached source addrs) and let output re-choose them
940 * during the next send on that net.
942 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
944 * clear any cached route (and cached source address) if the
945 * route's interface is NOT the same as the address change.
946 * If it's the same interface, just clear the cached source
949 if (SCTP_ROUTE_HAS_VALID_IFN(&net->ro) &&
951 (SCTP_GET_IF_INDEX_FROM_ROUTE(&net->ro) != ifn->ifn_index))) {
952 /* clear any cached route */
953 RTFREE(net->ro.ro_rt);
954 net->ro.ro_rt = NULL;
956 /* clear any cached source address */
957 if (net->src_addr_selected) {
958 sctp_free_ifa(net->ro._s_addr);
959 net->ro._s_addr = NULL;
960 net->src_addr_selected = 0;
967 sctp_assoc_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *dstnet)
971 if (dstnet->dest_state & SCTP_ADDR_UNCONFIRMED) {
974 if (stcb->asoc.deleted_primary == NULL) {
977 if (!TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
978 SCTPDBG(SCTP_DEBUG_ASCONF1, "assoc_immediate_retrans: Deleted primary is ");
979 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &stcb->asoc.deleted_primary->ro._l_addr.sa);
980 SCTPDBG(SCTP_DEBUG_ASCONF1, "Current Primary is ");
981 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &stcb->asoc.primary_destination->ro._l_addr.sa);
982 sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb,
983 stcb->asoc.deleted_primary,
984 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_3);
985 stcb->asoc.num_send_timers_up--;
986 if (stcb->asoc.num_send_timers_up < 0) {
987 stcb->asoc.num_send_timers_up = 0;
989 SCTP_TCB_LOCK_ASSERT(stcb);
990 error = sctp_t3rxt_timer(stcb->sctp_ep, stcb,
991 stcb->asoc.deleted_primary);
993 SCTP_INP_DECR_REF(stcb->sctp_ep);
996 SCTP_TCB_LOCK_ASSERT(stcb);
997 #ifdef SCTP_AUDITING_ENABLED
998 sctp_auditing(4, stcb->sctp_ep, stcb, stcb->asoc.deleted_primary);
1000 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED);
1001 if ((stcb->asoc.num_send_timers_up == 0) &&
1002 (stcb->asoc.sent_queue_cnt > 0)) {
1003 struct sctp_tmit_chunk *chk;
1005 chk = TAILQ_FIRST(&stcb->asoc.sent_queue);
1006 sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep,
1014 sctp_asconf_queue_mgmt(struct sctp_tcb *, struct sctp_ifa *, uint16_t);
1017 sctp_net_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *net)
1019 struct sctp_tmit_chunk *chk;
1021 SCTPDBG(SCTP_DEBUG_ASCONF1, "net_immediate_retrans: RTO is %d\n", net->RTO);
1022 sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, net,
1023 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_4);
1024 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
1025 net->error_count = 0;
1026 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
1027 if (chk->whoTo == net) {
1028 if (chk->sent < SCTP_DATAGRAM_RESEND) {
1029 chk->sent = SCTP_DATAGRAM_RESEND;
1030 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
1031 sctp_flight_size_decrease(chk);
1032 sctp_total_flight_decrease(stcb, chk);
1033 net->marked_retrans++;
1034 stcb->asoc.marked_retrans++;
1038 if (net->marked_retrans) {
1039 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED);
1044 sctp_path_check_and_react(struct sctp_tcb *stcb, struct sctp_ifa *newifa)
1046 struct sctp_nets *net;
1047 int addrnum, changed;
1050 * If number of local valid addresses is 1, the valid address is
1051 * probably newly added address. Several valid addresses in this
1052 * association. A source address may not be changed. Additionally,
1053 * they can be configured on a same interface as "alias" addresses.
1056 addrnum = sctp_local_addr_count(stcb);
1057 SCTPDBG(SCTP_DEBUG_ASCONF1, "p_check_react(): %d local addresses\n",
1060 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1061 /* clear any cached route and source address */
1062 if (net->ro.ro_rt) {
1063 RTFREE(net->ro.ro_rt);
1064 net->ro.ro_rt = NULL;
1066 if (net->src_addr_selected) {
1067 sctp_free_ifa(net->ro._s_addr);
1068 net->ro._s_addr = NULL;
1069 net->src_addr_selected = 0;
1071 /* Retransmit unacknowledged DATA chunks immediately */
1072 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
1073 SCTP_MOBILITY_FASTHANDOFF)) {
1074 sctp_net_immediate_retrans(stcb, net);
1076 /* also, SET PRIMARY is maybe already sent */
1080 /* Multiple local addresses exsist in the association. */
1081 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1082 /* clear any cached route and source address */
1083 if (net->ro.ro_rt) {
1084 RTFREE(net->ro.ro_rt);
1085 net->ro.ro_rt = NULL;
1087 if (net->src_addr_selected) {
1088 sctp_free_ifa(net->ro._s_addr);
1089 net->ro._s_addr = NULL;
1090 net->src_addr_selected = 0;
1093 * Check if the nexthop is corresponding to the new address.
1094 * If the new address is corresponding to the current
1095 * nexthop, the path will be changed. If the new address is
1096 * NOT corresponding to the current nexthop, the path will
1099 SCTP_RTALLOC((sctp_route_t *)&net->ro,
1100 stcb->sctp_ep->def_vrf_id,
1101 stcb->sctp_ep->fibnum);
1102 if (net->ro.ro_rt == NULL)
1106 switch (net->ro._l_addr.sa.sa_family) {
1109 if (sctp_v4src_match_nexthop(newifa, (sctp_route_t *)&net->ro)) {
1116 if (sctp_v6src_match_nexthop(
1117 &newifa->address.sin6, (sctp_route_t *)&net->ro)) {
1126 * if the newly added address does not relate routing
1127 * information, we skip.
1131 /* Retransmit unacknowledged DATA chunks immediately */
1132 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
1133 SCTP_MOBILITY_FASTHANDOFF)) {
1134 sctp_net_immediate_retrans(stcb, net);
1136 /* Send SET PRIMARY for this new address */
1137 if (net == stcb->asoc.primary_destination) {
1138 (void)sctp_asconf_queue_mgmt(stcb, newifa,
1139 SCTP_SET_PRIM_ADDR);
1145 * process an ADD/DELETE IP ack from peer.
1146 * addr: corresponding sctp_ifa to the address being added/deleted.
1147 * type: SCTP_ADD_IP_ADDRESS or SCTP_DEL_IP_ADDRESS.
1148 * flag: 1=success, 0=failure.
1151 sctp_asconf_addr_mgmt_ack(struct sctp_tcb *stcb, struct sctp_ifa *addr, uint32_t flag)
1154 * do the necessary asoc list work- if we get a failure indication,
1155 * leave the address on the assoc's restricted list. If we get a
1156 * success indication, remove the address from the restricted list.
1159 * Note: this will only occur for ADD_IP_ADDRESS, since
1160 * DEL_IP_ADDRESS is never actually added to the list...
1163 /* success case, so remove from the restricted list */
1164 sctp_del_local_addr_restricted(stcb, addr);
1166 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
1167 SCTP_MOBILITY_BASE) ||
1168 sctp_is_mobility_feature_on(stcb->sctp_ep,
1169 SCTP_MOBILITY_FASTHANDOFF)) {
1170 sctp_path_check_and_react(stcb, addr);
1173 /* clear any cached/topologically incorrect source addresses */
1174 sctp_asconf_nets_cleanup(stcb, addr->ifn_p);
1176 /* else, leave it on the list */
1180 * add an asconf add/delete/set primary IP address parameter to the queue.
1181 * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR.
1182 * returns 0 if queued, -1 if not queued/removed.
1183 * NOTE: if adding, but a delete for the same address is already scheduled
1184 * (and not yet sent out), simply remove it from queue. Same for deleting
1185 * an address already scheduled for add. If a duplicate operation is found,
1186 * ignore the new one.
1189 sctp_asconf_queue_mgmt(struct sctp_tcb *stcb, struct sctp_ifa *ifa,
1192 struct sctp_asconf_addr *aa, *aa_next;
1194 /* make sure the request isn't already in the queue */
1195 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) {
1196 /* address match? */
1197 if (sctp_asconf_addr_match(aa, &ifa->address.sa) == 0)
1200 * is the request already in queue but not sent? pass the
1201 * request already sent in order to resolve the following
1202 * case: 1. arrival of ADD, then sent 2. arrival of DEL. we
1203 * can't remove the ADD request already sent 3. arrival of
1206 if (aa->ap.aph.ph.param_type == type && aa->sent == 0) {
1209 /* is the negative request already in queue, and not sent */
1210 if ((aa->sent == 0) && (type == SCTP_ADD_IP_ADDRESS) &&
1211 (aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS)) {
1212 /* add requested, delete already queued */
1213 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1214 /* remove the ifa from the restricted list */
1215 sctp_del_local_addr_restricted(stcb, ifa);
1216 /* free the asconf param */
1217 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1218 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_mgmt: add removes queued entry\n");
1221 if ((aa->sent == 0) && (type == SCTP_DEL_IP_ADDRESS) &&
1222 (aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS)) {
1223 /* delete requested, add already queued */
1224 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1225 /* remove the aa->ifa from the restricted list */
1226 sctp_del_local_addr_restricted(stcb, aa->ifa);
1227 /* free the asconf param */
1228 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1229 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_mgmt: delete removes queued entry\n");
1234 /* adding new request to the queue */
1235 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
1238 /* didn't get memory */
1239 SCTPDBG(SCTP_DEBUG_ASCONF1, "asconf_queue_mgmt: failed to get memory!\n");
1242 aa->special_del = 0;
1243 /* fill in asconf address parameter fields */
1244 /* top level elements are "networked" during send */
1245 aa->ap.aph.ph.param_type = type;
1247 atomic_add_int(&ifa->refcount, 1);
1248 /* correlation_id filled in during send routine later... */
1249 switch (ifa->address.sa.sa_family) {
1253 struct sockaddr_in6 *sin6;
1255 sin6 = &ifa->address.sin6;
1256 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
1257 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param));
1258 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) +
1259 sizeof(struct sctp_ipv6addr_param);
1260 memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr,
1261 sizeof(struct in6_addr));
1268 struct sockaddr_in *sin;
1270 sin = &ifa->address.sin;
1271 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
1272 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param));
1273 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) +
1274 sizeof(struct sctp_ipv4addr_param);
1275 memcpy(&aa->ap.addrp.addr, &sin->sin_addr,
1276 sizeof(struct in_addr));
1281 /* invalid family! */
1282 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1286 aa->sent = 0; /* clear sent flag */
1288 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
1290 if (SCTP_BASE_SYSCTL(sctp_debug_on) & SCTP_DEBUG_ASCONF2) {
1291 if (type == SCTP_ADD_IP_ADDRESS) {
1292 SCTP_PRINTF("asconf_queue_mgmt: inserted asconf ADD_IP_ADDRESS: ");
1293 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa);
1294 } else if (type == SCTP_DEL_IP_ADDRESS) {
1295 SCTP_PRINTF("asconf_queue_mgmt: appended asconf DEL_IP_ADDRESS: ");
1296 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa);
1298 SCTP_PRINTF("asconf_queue_mgmt: appended asconf SET_PRIM_ADDR: ");
1299 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa);
1309 * add an asconf operation for the given ifa and type.
1310 * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR.
1311 * returns 0 if completed, -1 if not completed, 1 if immediate send is
1315 sctp_asconf_queue_add(struct sctp_tcb *stcb, struct sctp_ifa *ifa,
1319 int pending_delete_queued = 0;
1322 /* see if peer supports ASCONF */
1323 if (stcb->asoc.asconf_supported == 0) {
1327 * if this is deleting the last address from the assoc, mark it as
1330 if ((type == SCTP_DEL_IP_ADDRESS) && !stcb->asoc.asconf_del_pending) {
1331 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1332 last = (sctp_local_addr_count(stcb) == 0);
1334 last = (sctp_local_addr_count(stcb) == 1);
1337 /* set the pending delete info only */
1338 stcb->asoc.asconf_del_pending = 1;
1339 stcb->asoc.asconf_addr_del_pending = ifa;
1340 atomic_add_int(&ifa->refcount, 1);
1341 SCTPDBG(SCTP_DEBUG_ASCONF2,
1342 "asconf_queue_add: mark delete last address pending\n");
1346 /* queue an asconf parameter */
1347 status = sctp_asconf_queue_mgmt(stcb, ifa, type);
1350 * if this is an add, and there is a delete also pending (i.e. the
1351 * last local address is being changed), queue the pending delete
1354 if ((type == SCTP_ADD_IP_ADDRESS) && stcb->asoc.asconf_del_pending && (status == 0)) {
1355 /* queue in the pending delete */
1356 if (sctp_asconf_queue_mgmt(stcb,
1357 stcb->asoc.asconf_addr_del_pending,
1358 SCTP_DEL_IP_ADDRESS) == 0) {
1359 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_add: queing pending delete\n");
1360 pending_delete_queued = 1;
1361 /* clear out the pending delete info */
1362 stcb->asoc.asconf_del_pending = 0;
1363 sctp_free_ifa(stcb->asoc.asconf_addr_del_pending);
1364 stcb->asoc.asconf_addr_del_pending = NULL;
1367 if (pending_delete_queued) {
1368 struct sctp_nets *net;
1371 * since we know that the only/last address is now being
1372 * changed in this case, reset the cwnd/rto on all nets to
1373 * start as a new address and path. Also clear the error
1374 * counts to give the assoc the best chance to complete the
1377 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1378 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb,
1381 net->error_count = 0;
1383 stcb->asoc.overall_error_count = 0;
1384 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) {
1385 sctp_misc_ints(SCTP_THRESHOLD_CLEAR,
1386 stcb->asoc.overall_error_count,
1388 SCTP_FROM_SCTP_ASCONF,
1391 /* queue in an advisory set primary too */
1392 (void)sctp_asconf_queue_mgmt(stcb, ifa, SCTP_SET_PRIM_ADDR);
1393 /* let caller know we should send this out immediately */
1400 * add an asconf delete IP address parameter to the queue by sockaddr and
1401 * possibly with no sctp_ifa available. This is only called by the routine
1402 * that checks the addresses in an INIT-ACK against the current address list.
1403 * returns 0 if completed, non-zero if not completed.
1404 * NOTE: if an add is already scheduled (and not yet sent out), simply
1405 * remove it from queue. If a duplicate operation is found, ignore the
1409 sctp_asconf_queue_sa_delete(struct sctp_tcb *stcb, struct sockaddr *sa)
1411 struct sctp_ifa *ifa;
1412 struct sctp_asconf_addr *aa, *aa_next;
1417 /* see if peer supports ASCONF */
1418 if (stcb->asoc.asconf_supported == 0) {
1421 /* make sure the request isn't already in the queue */
1422 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) {
1423 /* address match? */
1424 if (sctp_asconf_addr_match(aa, sa) == 0)
1426 /* is the request already in queue (sent or not) */
1427 if (aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) {
1430 /* is the negative request already in queue, and not sent */
1433 if (aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS) {
1434 /* add already queued, so remove existing entry */
1435 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1436 sctp_del_local_addr_restricted(stcb, aa->ifa);
1437 /* free the entry */
1438 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1443 /* find any existing ifa-- NOTE ifa CAN be allowed to be NULL */
1444 ifa = sctp_find_ifa_by_addr(sa, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
1446 /* adding new request to the queue */
1447 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
1450 /* didn't get memory */
1451 SCTPDBG(SCTP_DEBUG_ASCONF1,
1452 "sctp_asconf_queue_sa_delete: failed to get memory!\n");
1455 aa->special_del = 0;
1456 /* fill in asconf address parameter fields */
1457 /* top level elements are "networked" during send */
1458 aa->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS;
1461 atomic_add_int(&ifa->refcount, 1);
1462 /* correlation_id filled in during send routine later... */
1463 switch (sa->sa_family) {
1468 struct sockaddr_in6 *sin6;
1470 sin6 = (struct sockaddr_in6 *)sa;
1471 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
1472 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param));
1473 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv6addr_param);
1474 memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr,
1475 sizeof(struct in6_addr));
1483 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
1485 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
1486 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param));
1487 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv4addr_param);
1488 memcpy(&aa->ap.addrp.addr, &sin->sin_addr,
1489 sizeof(struct in_addr));
1494 /* invalid family! */
1495 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1500 aa->sent = 0; /* clear sent flag */
1502 /* delete goes to the back of the queue */
1503 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
1505 /* sa_ignore MEMLEAK {memory is put on the tailq} */
1510 * find a specific asconf param on our "sent" queue
1512 static struct sctp_asconf_addr *
1513 sctp_asconf_find_param(struct sctp_tcb *stcb, uint32_t correlation_id)
1515 struct sctp_asconf_addr *aa;
1517 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
1518 if (aa->ap.aph.correlation_id == correlation_id &&
1524 /* didn't find it */
1529 * process an SCTP_ERROR_CAUSE_IND for a ASCONF-ACK parameter and do
1530 * notifications based on the error response
1533 sctp_asconf_process_error(struct sctp_tcb *stcb SCTP_UNUSED,
1534 struct sctp_asconf_paramhdr *aph)
1536 struct sctp_error_cause *eh;
1537 struct sctp_paramhdr *ph;
1538 uint16_t param_type;
1539 uint16_t error_code;
1541 eh = (struct sctp_error_cause *)(aph + 1);
1542 ph = (struct sctp_paramhdr *)(eh + 1);
1543 /* validate lengths */
1544 if (htons(eh->length) + sizeof(struct sctp_error_cause) >
1545 htons(aph->ph.param_length)) {
1546 /* invalid error cause length */
1547 SCTPDBG(SCTP_DEBUG_ASCONF1,
1548 "asconf_process_error: cause element too long\n");
1551 if (htons(ph->param_length) + sizeof(struct sctp_paramhdr) >
1552 htons(eh->length)) {
1553 /* invalid included TLV length */
1554 SCTPDBG(SCTP_DEBUG_ASCONF1,
1555 "asconf_process_error: included TLV too long\n");
1558 /* which error code ? */
1559 error_code = ntohs(eh->code);
1560 param_type = ntohs(aph->ph.param_type);
1561 /* FIX: this should go back up the REMOTE_ERROR ULP notify */
1562 switch (error_code) {
1563 case SCTP_CAUSE_RESOURCE_SHORTAGE:
1564 /* we allow ourselves to "try again" for this error */
1567 /* peer can't handle it... */
1568 switch (param_type) {
1569 case SCTP_ADD_IP_ADDRESS:
1570 case SCTP_DEL_IP_ADDRESS:
1571 case SCTP_SET_PRIM_ADDR:
1580 * process an asconf queue param.
1581 * aparam: parameter to process, will be removed from the queue.
1582 * flag: 1=success case, 0=failure case
1585 sctp_asconf_process_param_ack(struct sctp_tcb *stcb,
1586 struct sctp_asconf_addr *aparam, uint32_t flag)
1588 uint16_t param_type;
1590 /* process this param */
1591 param_type = aparam->ap.aph.ph.param_type;
1592 switch (param_type) {
1593 case SCTP_ADD_IP_ADDRESS:
1594 SCTPDBG(SCTP_DEBUG_ASCONF1,
1595 "process_param_ack: added IP address\n");
1596 sctp_asconf_addr_mgmt_ack(stcb, aparam->ifa, flag);
1598 case SCTP_DEL_IP_ADDRESS:
1599 SCTPDBG(SCTP_DEBUG_ASCONF1,
1600 "process_param_ack: deleted IP address\n");
1601 /* nothing really to do... lists already updated */
1603 case SCTP_SET_PRIM_ADDR:
1604 SCTPDBG(SCTP_DEBUG_ASCONF1,
1605 "process_param_ack: set primary IP address\n");
1606 /* nothing to do... peer may start using this addr */
1609 /* should NEVER happen */
1613 /* remove the param and free it */
1614 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aparam, next);
1616 sctp_free_ifa(aparam->ifa);
1617 SCTP_FREE(aparam, SCTP_M_ASC_ADDR);
1621 * cleanup from a bad asconf ack parameter
1624 sctp_asconf_ack_clear(struct sctp_tcb *stcb SCTP_UNUSED)
1626 /* assume peer doesn't really know how to do asconfs */
1627 /* XXX we could free the pending queue here */
1632 sctp_handle_asconf_ack(struct mbuf *m, int offset,
1633 struct sctp_asconf_ack_chunk *cp, struct sctp_tcb *stcb,
1634 struct sctp_nets *net, int *abort_no_unlock)
1636 struct sctp_association *asoc;
1637 uint32_t serial_num;
1638 uint16_t ack_length;
1639 struct sctp_asconf_paramhdr *aph;
1640 struct sctp_asconf_addr *aa, *aa_next;
1641 uint32_t last_error_id = 0; /* last error correlation id */
1643 struct sctp_asconf_addr *ap;
1645 /* asconf param buffer */
1646 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE];
1648 /* verify minimum length */
1649 if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_ack_chunk)) {
1650 SCTPDBG(SCTP_DEBUG_ASCONF1,
1651 "handle_asconf_ack: chunk too small = %xh\n",
1652 ntohs(cp->ch.chunk_length));
1656 serial_num = ntohl(cp->serial_number);
1659 * NOTE: we may want to handle this differently- currently, we will
1660 * abort when we get an ack for the expected serial number + 1 (eg.
1661 * we didn't send it), process an ack normally if it is the expected
1662 * serial number, and re-send the previous ack for *ALL* other
1667 * if the serial number is the next expected, but I didn't send it,
1668 * abort the asoc, since someone probably just hijacked us...
1670 if (serial_num == (asoc->asconf_seq_out + 1)) {
1671 struct mbuf *op_err;
1672 char msg[SCTP_DIAG_INFO_LEN];
1674 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got unexpected next serial number! Aborting asoc!\n");
1675 snprintf(msg, sizeof(msg), "Never sent serial number %8.8x",
1677 op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
1678 sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
1679 *abort_no_unlock = 1;
1682 if (serial_num != asoc->asconf_seq_out_acked + 1) {
1683 /* got a duplicate/unexpected ASCONF-ACK */
1684 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got duplicate/unexpected serial number = %xh (expected = %xh)\n",
1685 serial_num, asoc->asconf_seq_out_acked + 1);
1688 if (serial_num == asoc->asconf_seq_out - 1) {
1689 /* stop our timer */
1690 sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, net,
1691 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_5);
1693 /* process the ASCONF-ACK contents */
1694 ack_length = ntohs(cp->ch.chunk_length) -
1695 sizeof(struct sctp_asconf_ack_chunk);
1696 offset += sizeof(struct sctp_asconf_ack_chunk);
1697 /* process through all parameters */
1698 while (ack_length >= sizeof(struct sctp_asconf_paramhdr)) {
1699 unsigned int param_length, param_type;
1701 /* get pointer to next asconf parameter */
1702 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset,
1703 sizeof(struct sctp_asconf_paramhdr), aparam_buf);
1705 /* can't get an asconf paramhdr */
1706 sctp_asconf_ack_clear(stcb);
1709 param_type = ntohs(aph->ph.param_type);
1710 param_length = ntohs(aph->ph.param_length);
1711 if (param_length > ack_length) {
1712 sctp_asconf_ack_clear(stcb);
1715 if (param_length < sizeof(struct sctp_paramhdr)) {
1716 sctp_asconf_ack_clear(stcb);
1719 /* get the complete parameter... */
1720 if (param_length > sizeof(aparam_buf)) {
1721 SCTPDBG(SCTP_DEBUG_ASCONF1,
1722 "param length (%u) larger than buffer size!\n", param_length);
1723 sctp_asconf_ack_clear(stcb);
1726 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf);
1728 sctp_asconf_ack_clear(stcb);
1731 /* correlation_id is transparent to peer, no ntohl needed */
1732 id = aph->correlation_id;
1734 switch (param_type) {
1735 case SCTP_ERROR_CAUSE_IND:
1737 /* find the corresponding asconf param in our queue */
1738 ap = sctp_asconf_find_param(stcb, id);
1740 /* hmm... can't find this in our queue! */
1743 /* process the parameter, failed flag */
1744 sctp_asconf_process_param_ack(stcb, ap, 0);
1745 /* process the error response */
1746 sctp_asconf_process_error(stcb, aph);
1748 case SCTP_SUCCESS_REPORT:
1749 /* find the corresponding asconf param in our queue */
1750 ap = sctp_asconf_find_param(stcb, id);
1752 /* hmm... can't find this in our queue! */
1755 /* process the parameter, success flag */
1756 sctp_asconf_process_param_ack(stcb, ap, 1);
1762 /* update remaining ASCONF-ACK message length to process */
1763 ack_length -= SCTP_SIZE32(param_length);
1764 if (ack_length <= 0) {
1765 /* no more data in the mbuf chain */
1768 offset += SCTP_SIZE32(param_length);
1772 * if there are any "sent" params still on the queue, these are
1773 * implicitly "success", or "failed" (if we got an error back) ...
1774 * so process these appropriately
1776 * we assume that the correlation_id's are monotonically increasing
1777 * beginning from 1 and that we don't have *that* many outstanding
1780 if (last_error_id == 0)
1781 last_error_id--;/* set to "max" value */
1782 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) {
1783 if (aa->sent == 1) {
1785 * implicitly successful or failed if correlation_id
1786 * < last_error_id, then success else, failure
1788 if (aa->ap.aph.correlation_id < last_error_id)
1789 sctp_asconf_process_param_ack(stcb, aa, 1);
1791 sctp_asconf_process_param_ack(stcb, aa, 0);
1794 * since we always process in order (FIFO queue) if
1795 * we reach one that hasn't been sent, the rest
1796 * should not have been sent either. so, we're
1803 /* update the next sequence number to use */
1804 asoc->asconf_seq_out_acked++;
1805 /* remove the old ASCONF on our outbound queue */
1806 sctp_toss_old_asconf(stcb);
1807 if (!TAILQ_EMPTY(&stcb->asoc.asconf_queue)) {
1808 #ifdef SCTP_TIMER_BASED_ASCONF
1809 /* we have more params, so restart our timer */
1810 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep,
1813 /* we have more params, so send out more */
1814 sctp_send_asconf(stcb, net, SCTP_ADDR_NOT_LOCKED);
1821 sctp_is_scopeid_in_nets(struct sctp_tcb *stcb, struct sockaddr *sa)
1823 struct sockaddr_in6 *sin6, *net6;
1824 struct sctp_nets *net;
1826 if (sa->sa_family != AF_INET6) {
1830 sin6 = (struct sockaddr_in6 *)sa;
1831 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) == 0) {
1832 /* not link local address */
1835 /* hunt through our destination nets list for this scope_id */
1836 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1837 if (((struct sockaddr *)(&net->ro._l_addr))->sa_family !=
1840 net6 = (struct sockaddr_in6 *)&net->ro._l_addr;
1841 if (IN6_IS_ADDR_LINKLOCAL(&net6->sin6_addr) == 0)
1843 if (sctp_is_same_scope(sin6, net6)) {
1848 /* didn't find one */
1854 * address management functions
1857 sctp_addr_mgmt_assoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
1858 struct sctp_ifa *ifa, uint16_t type, int addr_locked)
1862 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0 ||
1863 sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_ASCONF)) {
1864 /* subset bound, no ASCONF allowed case, so ignore */
1868 * note: we know this is not the subset bound, no ASCONF case eg.
1869 * this is boundall or subset bound w/ASCONF allowed
1872 /* first, make sure that the address is IPv4 or IPv6 and not jailed */
1873 switch (ifa->address.sa.sa_family) {
1876 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1877 &ifa->address.sin6.sin6_addr) != 0) {
1884 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1885 &ifa->address.sin.sin_addr) != 0) {
1894 /* make sure we're "allowed" to add this type of addr */
1895 if (ifa->address.sa.sa_family == AF_INET6) {
1896 /* invalid if we're not a v6 endpoint */
1897 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0)
1899 /* is the v6 addr really valid ? */
1900 if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) {
1905 /* put this address on the "pending/do not use yet" list */
1906 sctp_add_local_addr_restricted(stcb, ifa);
1908 * check address scope if address is out of scope, don't queue
1909 * anything... note: this would leave the address on both inp and
1912 switch (ifa->address.sa.sa_family) {
1916 struct sockaddr_in6 *sin6;
1918 sin6 = &ifa->address.sin6;
1919 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1920 /* we skip unspecifed addresses */
1923 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1924 if (stcb->asoc.scope.local_scope == 0) {
1927 /* is it the right link local scope? */
1928 if (sctp_is_scopeid_in_nets(stcb, &ifa->address.sa) == 0) {
1932 if (stcb->asoc.scope.site_scope == 0 &&
1933 IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)) {
1942 struct sockaddr_in *sin;
1943 struct in6pcb *inp6;
1945 inp6 = (struct in6pcb *)&inp->ip_inp.inp;
1946 /* invalid if we are a v6 only endpoint */
1947 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1948 SCTP_IPV6_V6ONLY(inp6))
1951 sin = &ifa->address.sin;
1952 if (sin->sin_addr.s_addr == 0) {
1953 /* we skip unspecifed addresses */
1956 if (stcb->asoc.scope.ipv4_local_scope == 0 &&
1957 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) {
1964 /* else, not AF_INET or AF_INET6, so skip */
1968 /* queue an asconf for this address add/delete */
1969 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF)) {
1970 /* does the peer do asconf? */
1971 if (stcb->asoc.asconf_supported) {
1972 /* queue an asconf for this addr */
1973 status = sctp_asconf_queue_add(stcb, ifa, type);
1976 * if queued ok, and in the open state, send out the
1977 * ASCONF. If in the non-open state, these will be
1978 * sent when the state goes open.
1981 ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
1982 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED))) {
1983 #ifdef SCTP_TIMER_BASED_ASCONF
1984 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, inp,
1985 stcb, stcb->asoc.primary_destination);
1987 sctp_send_asconf(stcb, NULL, addr_locked);
1996 sctp_asconf_iterator_ep(struct sctp_inpcb *inp, void *ptr, uint32_t val SCTP_UNUSED)
1998 struct sctp_asconf_iterator *asc;
1999 struct sctp_ifa *ifa;
2000 struct sctp_laddr *l;
2001 int cnt_invalid = 0;
2003 asc = (struct sctp_asconf_iterator *)ptr;
2004 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) {
2006 switch (ifa->address.sa.sa_family) {
2009 /* invalid if we're not a v6 endpoint */
2010 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
2012 if (asc->cnt == cnt_invalid)
2020 /* invalid if we are a v6 only endpoint */
2021 struct in6pcb *inp6;
2023 inp6 = (struct in6pcb *)&inp->ip_inp.inp;
2024 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2025 SCTP_IPV6_V6ONLY(inp6)) {
2027 if (asc->cnt == cnt_invalid)
2034 /* invalid address family */
2036 if (asc->cnt == cnt_invalid)
2044 sctp_asconf_iterator_ep_end(struct sctp_inpcb *inp, void *ptr, uint32_t val SCTP_UNUSED)
2046 struct sctp_ifa *ifa;
2047 struct sctp_asconf_iterator *asc;
2048 struct sctp_laddr *laddr, *nladdr, *l;
2050 /* Only for specific case not bound all */
2051 asc = (struct sctp_asconf_iterator *)ptr;
2052 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) {
2054 if (l->action == SCTP_ADD_IP_ADDRESS) {
2055 LIST_FOREACH(laddr, &inp->sctp_addr_list,
2057 if (laddr->ifa == ifa) {
2062 } else if (l->action == SCTP_DEL_IP_ADDRESS) {
2063 LIST_FOREACH_SAFE(laddr, &inp->sctp_addr_list, sctp_nxt_addr, nladdr) {
2064 /* remove only after all guys are done */
2065 if (laddr->ifa == ifa) {
2066 sctp_del_local_addr_ep(inp, ifa);
2075 sctp_asconf_iterator_stcb(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
2076 void *ptr, uint32_t val SCTP_UNUSED)
2078 struct sctp_asconf_iterator *asc;
2079 struct sctp_ifa *ifa;
2080 struct sctp_laddr *l;
2081 int cnt_invalid = 0;
2085 asc = (struct sctp_asconf_iterator *)ptr;
2086 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) {
2090 /* address's vrf_id must be the vrf_id of the assoc */
2091 if (ifa->vrf_id != stcb->asoc.vrf_id) {
2094 /* Same checks again for assoc */
2095 switch (ifa->address.sa.sa_family) {
2099 /* invalid if we're not a v6 endpoint */
2100 struct sockaddr_in6 *sin6;
2102 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
2104 if (asc->cnt == cnt_invalid)
2109 sin6 = &ifa->address.sin6;
2110 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2111 /* we skip unspecifed addresses */
2114 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
2115 &sin6->sin6_addr) != 0) {
2118 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
2119 if (stcb->asoc.scope.local_scope == 0) {
2122 /* is it the right link local scope? */
2123 if (sctp_is_scopeid_in_nets(stcb, &ifa->address.sa) == 0) {
2133 /* invalid if we are a v6 only endpoint */
2134 struct in6pcb *inp6;
2135 struct sockaddr_in *sin;
2137 inp6 = (struct in6pcb *)&inp->ip_inp.inp;
2138 /* invalid if we are a v6 only endpoint */
2139 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2140 SCTP_IPV6_V6ONLY(inp6))
2143 sin = &ifa->address.sin;
2144 if (sin->sin_addr.s_addr == 0) {
2145 /* we skip unspecifed addresses */
2148 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
2149 &sin->sin_addr) != 0) {
2152 if (stcb->asoc.scope.ipv4_local_scope == 0 &&
2153 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) {
2156 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2157 SCTP_IPV6_V6ONLY(inp6)) {
2159 if (asc->cnt == cnt_invalid)
2168 /* invalid address family */
2170 if (asc->cnt == cnt_invalid)
2177 if (type == SCTP_ADD_IP_ADDRESS) {
2178 /* prevent this address from being used as a source */
2179 sctp_add_local_addr_restricted(stcb, ifa);
2180 } else if (type == SCTP_DEL_IP_ADDRESS) {
2181 struct sctp_nets *net;
2183 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2186 /* delete this address if cached */
2187 if (net->ro._s_addr == ifa) {
2188 sctp_free_ifa(net->ro._s_addr);
2189 net->ro._s_addr = NULL;
2190 net->src_addr_selected = 0;
2194 net->ro.ro_rt = NULL;
2197 * Now we deleted our src address,
2198 * should we not also now reset the
2199 * cwnd/rto to start as if its a new
2202 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
2207 } else if (type == SCTP_SET_PRIM_ADDR) {
2208 if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
2209 /* must validate the ifa is in the ep */
2210 if (sctp_is_addr_in_ep(stcb->sctp_ep, ifa) == 0) {
2214 /* Need to check scopes for this guy */
2215 if (sctp_is_address_in_scope(ifa, &stcb->asoc.scope, 0) == 0) {
2220 /* queue an asconf for this address add/delete */
2221 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF) &&
2222 stcb->asoc.asconf_supported == 1) {
2223 /* queue an asconf for this addr */
2224 status = sctp_asconf_queue_add(stcb, ifa, type);
2226 * if queued ok, and in the open state, update the
2227 * count of queued params. If in the non-open
2228 * state, these get sent when the assoc goes open.
2230 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
2231 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
2239 * If we have queued params in the open state, send out an ASCONF.
2241 if (num_queued > 0) {
2242 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2247 sctp_asconf_iterator_end(void *ptr, uint32_t val SCTP_UNUSED)
2249 struct sctp_asconf_iterator *asc;
2250 struct sctp_ifa *ifa;
2251 struct sctp_laddr *l, *nl;
2253 asc = (struct sctp_asconf_iterator *)ptr;
2254 LIST_FOREACH_SAFE(l, &asc->list_of_work, sctp_nxt_addr, nl) {
2256 if (l->action == SCTP_ADD_IP_ADDRESS) {
2257 /* Clear the defer use flag */
2258 ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE;
2261 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_laddr), l);
2262 SCTP_DECR_LADDR_COUNT();
2264 SCTP_FREE(asc, SCTP_M_ASC_IT);
2268 * sa is the sockaddr to ask the peer to set primary to.
2269 * returns: 0 = completed, -1 = error
2272 sctp_set_primary_ip_address_sa(struct sctp_tcb *stcb, struct sockaddr *sa)
2275 struct sctp_ifa *ifa;
2277 /* find the ifa for the desired set primary */
2278 vrf_id = stcb->asoc.vrf_id;
2279 ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED);
2281 /* Invalid address */
2284 /* queue an ASCONF:SET_PRIM_ADDR to be sent */
2285 if (!sctp_asconf_queue_add(stcb, ifa, SCTP_SET_PRIM_ADDR)) {
2286 /* set primary queuing succeeded */
2287 SCTPDBG(SCTP_DEBUG_ASCONF1,
2288 "set_primary_ip_address_sa: queued on tcb=%p, ",
2290 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
2291 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
2292 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
2293 #ifdef SCTP_TIMER_BASED_ASCONF
2294 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
2295 stcb->sctp_ep, stcb,
2296 stcb->asoc.primary_destination);
2298 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2302 SCTPDBG(SCTP_DEBUG_ASCONF1, "set_primary_ip_address_sa: failed to add to queue on tcb=%p, ",
2304 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
2311 sctp_is_addr_pending(struct sctp_tcb *stcb, struct sctp_ifa *sctp_ifa)
2313 struct sctp_tmit_chunk *chk, *nchk;
2314 unsigned int offset, asconf_limit;
2315 struct sctp_asconf_chunk *acp;
2316 struct sctp_asconf_paramhdr *aph;
2317 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE];
2318 struct sctp_paramhdr *ph;
2319 int add_cnt, del_cnt;
2320 uint16_t last_param_type;
2322 add_cnt = del_cnt = 0;
2323 last_param_type = 0;
2324 TAILQ_FOREACH_SAFE(chk, &stcb->asoc.asconf_send_queue, sctp_next, nchk) {
2325 if (chk->data == NULL) {
2326 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: No mbuf data?\n");
2330 acp = mtod(chk->data, struct sctp_asconf_chunk *);
2331 offset += sizeof(struct sctp_asconf_chunk);
2332 asconf_limit = ntohs(acp->ch.chunk_length);
2333 ph = (struct sctp_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_paramhdr), aparam_buf);
2335 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: couldn't get lookup addr!\n");
2338 offset += ntohs(ph->param_length);
2340 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_asconf_paramhdr), aparam_buf);
2342 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: Empty ASCONF will be sent?\n");
2345 while (aph != NULL) {
2346 unsigned int param_length, param_type;
2348 param_type = ntohs(aph->ph.param_type);
2349 param_length = ntohs(aph->ph.param_length);
2350 if (offset + param_length > asconf_limit) {
2351 /* parameter goes beyond end of chunk! */
2354 if (param_length > sizeof(aparam_buf)) {
2355 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: param length (%u) larger than buffer size!\n", param_length);
2358 if (param_length <= sizeof(struct sctp_paramhdr)) {
2359 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: param length(%u) too short\n", param_length);
2362 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, param_length, aparam_buf);
2364 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: couldn't get entire param\n");
2367 ph = (struct sctp_paramhdr *)(aph + 1);
2368 if (sctp_addr_match(ph, &sctp_ifa->address.sa) != 0) {
2369 switch (param_type) {
2370 case SCTP_ADD_IP_ADDRESS:
2373 case SCTP_DEL_IP_ADDRESS:
2379 last_param_type = param_type;
2381 offset += SCTP_SIZE32(param_length);
2382 if (offset >= asconf_limit) {
2383 /* no more data in the mbuf chain */
2386 /* get pointer to next asconf param */
2387 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_asconf_paramhdr), aparam_buf);
2392 * we want to find the sequences which consist of ADD -> DEL -> ADD
2395 if (add_cnt > del_cnt ||
2396 (add_cnt == del_cnt && last_param_type == SCTP_ADD_IP_ADDRESS)) {
2402 static struct sockaddr *
2403 sctp_find_valid_localaddr(struct sctp_tcb *stcb, int addr_locked)
2405 struct sctp_vrf *vrf = NULL;
2406 struct sctp_ifn *sctp_ifn;
2407 struct sctp_ifa *sctp_ifa;
2409 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2410 SCTP_IPI_ADDR_RLOCK();
2411 vrf = sctp_find_vrf(stcb->asoc.vrf_id);
2413 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2414 SCTP_IPI_ADDR_RUNLOCK();
2417 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
2418 if (stcb->asoc.scope.loopback_scope == 0 &&
2419 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
2420 /* Skip if loopback_scope not set */
2423 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
2424 switch (sctp_ifa->address.sa.sa_family) {
2427 if (stcb->asoc.scope.ipv4_addr_legal) {
2428 struct sockaddr_in *sin;
2430 sin = &sctp_ifa->address.sin;
2431 if (sin->sin_addr.s_addr == 0) {
2432 /* skip unspecifed addresses */
2435 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
2436 &sin->sin_addr) != 0) {
2439 if (stcb->asoc.scope.ipv4_local_scope == 0 &&
2440 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))
2443 if (sctp_is_addr_restricted(stcb, sctp_ifa) &&
2444 (!sctp_is_addr_pending(stcb, sctp_ifa)))
2447 * found a valid local v4 address to
2450 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2451 SCTP_IPI_ADDR_RUNLOCK();
2452 return (&sctp_ifa->address.sa);
2458 if (stcb->asoc.scope.ipv6_addr_legal) {
2459 struct sockaddr_in6 *sin6;
2461 if (sctp_ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) {
2464 sin6 = &sctp_ifa->address.sin6;
2465 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2467 * we skip unspecifed
2472 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
2473 &sin6->sin6_addr) != 0) {
2476 if (stcb->asoc.scope.local_scope == 0 &&
2477 IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))
2479 if (stcb->asoc.scope.site_scope == 0 &&
2480 IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))
2483 if (sctp_is_addr_restricted(stcb, sctp_ifa) &&
2484 (!sctp_is_addr_pending(stcb, sctp_ifa)))
2487 * found a valid local v6 address to
2490 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2491 SCTP_IPI_ADDR_RUNLOCK();
2492 return (&sctp_ifa->address.sa);
2501 /* no valid addresses found */
2502 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2503 SCTP_IPI_ADDR_RUNLOCK();
2507 static struct sockaddr *
2508 sctp_find_valid_localaddr_ep(struct sctp_tcb *stcb)
2510 struct sctp_laddr *laddr;
2512 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
2513 if (laddr->ifa == NULL) {
2516 /* is the address restricted ? */
2517 if (sctp_is_addr_restricted(stcb, laddr->ifa) &&
2518 (!sctp_is_addr_pending(stcb, laddr->ifa)))
2521 /* found a valid local address to use */
2522 return (&laddr->ifa->address.sa);
2524 /* no valid addresses found */
2529 * builds an ASCONF chunk from queued ASCONF params.
2530 * returns NULL on error (no mbuf, no ASCONF params queued, etc).
2533 sctp_compose_asconf(struct sctp_tcb *stcb, int *retlen, int addr_locked)
2535 struct mbuf *m_asconf, *m_asconf_chk;
2536 struct sctp_asconf_addr *aa;
2537 struct sctp_asconf_chunk *acp;
2538 struct sctp_asconf_paramhdr *aph;
2539 struct sctp_asconf_addr_param *aap;
2541 uint32_t correlation_id = 1; /* 0 is reserved... */
2542 caddr_t ptr, lookup_ptr;
2543 uint8_t lookup_used = 0;
2545 /* are there any asconf params to send? */
2546 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
2554 * get a chunk header mbuf and a cluster for the asconf params since
2555 * it's simpler to fill in the asconf chunk header lookup address on
2558 m_asconf_chk = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_chunk), 0, M_NOWAIT, 1, MT_DATA);
2559 if (m_asconf_chk == NULL) {
2561 SCTPDBG(SCTP_DEBUG_ASCONF1,
2562 "compose_asconf: couldn't get chunk mbuf!\n");
2565 m_asconf = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA);
2566 if (m_asconf == NULL) {
2568 SCTPDBG(SCTP_DEBUG_ASCONF1,
2569 "compose_asconf: couldn't get mbuf!\n");
2570 sctp_m_freem(m_asconf_chk);
2573 SCTP_BUF_LEN(m_asconf_chk) = sizeof(struct sctp_asconf_chunk);
2574 SCTP_BUF_LEN(m_asconf) = 0;
2575 acp = mtod(m_asconf_chk, struct sctp_asconf_chunk *);
2576 memset(acp, 0, sizeof(struct sctp_asconf_chunk));
2577 /* save pointers to lookup address and asconf params */
2578 lookup_ptr = (caddr_t)(acp + 1); /* after the header */
2579 ptr = mtod(m_asconf, caddr_t); /* beginning of cluster */
2581 /* fill in chunk header info */
2582 acp->ch.chunk_type = SCTP_ASCONF;
2583 acp->ch.chunk_flags = 0;
2584 acp->serial_number = htonl(stcb->asoc.asconf_seq_out);
2585 stcb->asoc.asconf_seq_out++;
2587 /* add parameters... up to smallest MTU allowed */
2588 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
2591 /* get the parameter length */
2592 p_length = SCTP_SIZE32(aa->ap.aph.ph.param_length);
2593 /* will it fit in current chunk? */
2594 if ((SCTP_BUF_LEN(m_asconf) + p_length > stcb->asoc.smallest_mtu) ||
2595 (SCTP_BUF_LEN(m_asconf) + p_length > MCLBYTES)) {
2596 /* won't fit, so we're done with this chunk */
2599 /* assign (and store) a correlation id */
2600 aa->ap.aph.correlation_id = correlation_id++;
2603 * fill in address if we're doing a delete this is a simple
2604 * way for us to fill in the correlation address, which
2605 * should only be used by the peer if we're deleting our
2606 * source address and adding a new address (e.g. renumbering
2609 if (lookup_used == 0 &&
2610 (aa->special_del == 0) &&
2611 aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) {
2612 struct sctp_ipv6addr_param *lookup;
2613 uint16_t p_size, addr_size;
2615 lookup = (struct sctp_ipv6addr_param *)lookup_ptr;
2616 lookup->ph.param_type =
2617 htons(aa->ap.addrp.ph.param_type);
2618 if (aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) {
2619 /* copy IPv6 address */
2620 p_size = sizeof(struct sctp_ipv6addr_param);
2621 addr_size = sizeof(struct in6_addr);
2623 /* copy IPv4 address */
2624 p_size = sizeof(struct sctp_ipv4addr_param);
2625 addr_size = sizeof(struct in_addr);
2627 lookup->ph.param_length = htons(SCTP_SIZE32(p_size));
2628 memcpy(lookup->addr, &aa->ap.addrp.addr, addr_size);
2629 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size);
2632 /* copy into current space */
2633 memcpy(ptr, &aa->ap, p_length);
2635 /* network elements and update lengths */
2636 aph = (struct sctp_asconf_paramhdr *)ptr;
2637 aap = (struct sctp_asconf_addr_param *)ptr;
2638 /* correlation_id is transparent to peer, no htonl needed */
2639 aph->ph.param_type = htons(aph->ph.param_type);
2640 aph->ph.param_length = htons(aph->ph.param_length);
2641 aap->addrp.ph.param_type = htons(aap->addrp.ph.param_type);
2642 aap->addrp.ph.param_length = htons(aap->addrp.ph.param_length);
2644 SCTP_BUF_LEN(m_asconf) += SCTP_SIZE32(p_length);
2645 ptr += SCTP_SIZE32(p_length);
2648 * these params are removed off the pending list upon
2649 * getting an ASCONF-ACK back from the peer, just set flag
2653 /* check to see if the lookup addr has been populated yet */
2654 if (lookup_used == 0) {
2655 /* NOTE: if the address param is optional, can skip this... */
2656 /* add any valid (existing) address... */
2657 struct sctp_ipv6addr_param *lookup;
2658 uint16_t p_size, addr_size;
2659 struct sockaddr *found_addr;
2662 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL)
2663 found_addr = sctp_find_valid_localaddr(stcb,
2666 found_addr = sctp_find_valid_localaddr_ep(stcb);
2668 lookup = (struct sctp_ipv6addr_param *)lookup_ptr;
2669 if (found_addr != NULL) {
2670 switch (found_addr->sa_family) {
2673 /* copy IPv6 address */
2674 lookup->ph.param_type =
2675 htons(SCTP_IPV6_ADDRESS);
2676 p_size = sizeof(struct sctp_ipv6addr_param);
2677 addr_size = sizeof(struct in6_addr);
2678 addr_ptr = (caddr_t)&((struct sockaddr_in6 *)
2679 found_addr)->sin6_addr;
2684 /* copy IPv4 address */
2685 lookup->ph.param_type =
2686 htons(SCTP_IPV4_ADDRESS);
2687 p_size = sizeof(struct sctp_ipv4addr_param);
2688 addr_size = sizeof(struct in_addr);
2689 addr_ptr = (caddr_t)&((struct sockaddr_in *)
2690 found_addr)->sin_addr;
2699 lookup->ph.param_length = htons(SCTP_SIZE32(p_size));
2700 memcpy(lookup->addr, addr_ptr, addr_size);
2701 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size);
2703 /* uh oh... don't have any address?? */
2704 SCTPDBG(SCTP_DEBUG_ASCONF1,
2705 "compose_asconf: no lookup addr!\n");
2706 /* XXX for now, we send a IPv4 address of 0.0.0.0 */
2707 lookup->ph.param_type = htons(SCTP_IPV4_ADDRESS);
2708 lookup->ph.param_length = htons(SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param)));
2709 memset(lookup->addr, 0, sizeof(struct in_addr));
2710 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param));
2713 /* chain it all together */
2714 SCTP_BUF_NEXT(m_asconf_chk) = m_asconf;
2715 *retlen = SCTP_BUF_LEN(m_asconf_chk) + SCTP_BUF_LEN(m_asconf);
2716 acp->ch.chunk_length = htons(*retlen);
2718 return (m_asconf_chk);
2722 * section to handle address changes before an association is up eg. changes
2723 * during INIT/INIT-ACK/COOKIE-ECHO handshake
2727 * processes the (local) addresses in the INIT-ACK chunk
2730 sctp_process_initack_addresses(struct sctp_tcb *stcb, struct mbuf *m,
2731 unsigned int offset, unsigned int length)
2733 struct sctp_paramhdr tmp_param, *ph;
2734 uint16_t plen, ptype;
2735 struct sctp_ifa *sctp_ifa;
2736 union sctp_sockstore store;
2738 struct sctp_ipv6addr_param addr6_store;
2741 struct sctp_ipv4addr_param addr4_store;
2744 SCTPDBG(SCTP_DEBUG_ASCONF2, "processing init-ack addresses\n");
2745 if (stcb == NULL) /* Un-needed check for SA */
2748 /* convert to upper bound */
2751 if ((offset + sizeof(struct sctp_paramhdr)) > length) {
2754 /* go through the addresses in the init-ack */
2755 ph = (struct sctp_paramhdr *)
2756 sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr),
2757 (uint8_t *)&tmp_param);
2758 while (ph != NULL) {
2759 ptype = ntohs(ph->param_type);
2760 plen = ntohs(ph->param_length);
2763 case SCTP_IPV6_ADDRESS:
2765 struct sctp_ipv6addr_param *a6p;
2767 /* get the entire IPv6 address param */
2768 a6p = (struct sctp_ipv6addr_param *)
2769 sctp_m_getptr(m, offset,
2770 sizeof(struct sctp_ipv6addr_param),
2771 (uint8_t *)&addr6_store);
2772 if (plen != sizeof(struct sctp_ipv6addr_param) ||
2776 memset(&store, 0, sizeof(union sctp_sockstore));
2777 store.sin6.sin6_family = AF_INET6;
2778 store.sin6.sin6_len = sizeof(struct sockaddr_in6);
2779 store.sin6.sin6_port = stcb->rport;
2780 memcpy(&store.sin6.sin6_addr, a6p->addr, sizeof(struct in6_addr));
2785 case SCTP_IPV4_ADDRESS:
2787 struct sctp_ipv4addr_param *a4p;
2789 /* get the entire IPv4 address param */
2790 a4p = (struct sctp_ipv4addr_param *)sctp_m_getptr(m, offset,
2791 sizeof(struct sctp_ipv4addr_param),
2792 (uint8_t *)&addr4_store);
2793 if (plen != sizeof(struct sctp_ipv4addr_param) ||
2797 memset(&store, 0, sizeof(union sctp_sockstore));
2798 store.sin.sin_family = AF_INET;
2799 store.sin.sin_len = sizeof(struct sockaddr_in);
2800 store.sin.sin_port = stcb->rport;
2801 store.sin.sin_addr.s_addr = a4p->addr;
2809 /* see if this address really (still) exists */
2810 sctp_ifa = sctp_find_ifa_by_addr(&store.sa, stcb->asoc.vrf_id,
2811 SCTP_ADDR_NOT_LOCKED);
2812 if (sctp_ifa == NULL) {
2813 /* address doesn't exist anymore */
2816 /* are ASCONFs allowed ? */
2817 if ((sctp_is_feature_on(stcb->sctp_ep,
2818 SCTP_PCB_FLAGS_DO_ASCONF)) &&
2819 stcb->asoc.asconf_supported) {
2820 /* queue an ASCONF DEL_IP_ADDRESS */
2821 status = sctp_asconf_queue_sa_delete(stcb, &store.sa);
2823 * if queued ok, and in correct state, send
2827 SCTP_GET_STATE(&stcb->asoc) ==
2829 #ifdef SCTP_TIMER_BASED_ASCONF
2830 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
2831 stcb->sctp_ep, stcb,
2832 stcb->asoc.primary_destination);
2834 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2841 * Sanity check: Make sure the length isn't 0, otherwise
2842 * we'll be stuck in this loop for a long time...
2844 if (SCTP_SIZE32(plen) == 0) {
2845 SCTP_PRINTF("process_initack_addrs: bad len (%d) type=%xh\n",
2849 /* get next parameter */
2850 offset += SCTP_SIZE32(plen);
2851 if ((offset + sizeof(struct sctp_paramhdr)) > length)
2853 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset,
2854 sizeof(struct sctp_paramhdr), (uint8_t *)&tmp_param);
2858 /* FIX ME: need to verify return result for v6 address type if v6 disabled */
2860 * checks to see if a specific address is in the initack address list returns
2861 * 1 if found, 0 if not
2864 sctp_addr_in_initack(struct mbuf *m, uint32_t offset, uint32_t length, struct sockaddr *sa)
2866 struct sctp_paramhdr tmp_param, *ph;
2867 uint16_t plen, ptype;
2869 struct sockaddr_in *sin;
2870 struct sctp_ipv4addr_param *a4p;
2871 struct sctp_ipv6addr_param addr4_store;
2874 struct sockaddr_in6 *sin6;
2875 struct sctp_ipv6addr_param *a6p;
2876 struct sctp_ipv6addr_param addr6_store;
2877 struct sockaddr_in6 sin6_tmp;
2880 switch (sa->sa_family) {
2893 SCTPDBG(SCTP_DEBUG_ASCONF2, "find_initack_addr: starting search for ");
2894 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, sa);
2895 /* convert to upper bound */
2898 if ((offset + sizeof(struct sctp_paramhdr)) > length) {
2899 SCTPDBG(SCTP_DEBUG_ASCONF1,
2900 "find_initack_addr: invalid offset?\n");
2903 /* go through the addresses in the init-ack */
2904 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset,
2905 sizeof(struct sctp_paramhdr), (uint8_t *)&tmp_param);
2906 while (ph != NULL) {
2907 ptype = ntohs(ph->param_type);
2908 plen = ntohs(ph->param_length);
2911 case SCTP_IPV6_ADDRESS:
2912 if (sa->sa_family == AF_INET6) {
2913 /* get the entire IPv6 address param */
2914 if (plen != sizeof(struct sctp_ipv6addr_param)) {
2917 /* get the entire IPv6 address param */
2918 a6p = (struct sctp_ipv6addr_param *)
2919 sctp_m_getptr(m, offset,
2920 sizeof(struct sctp_ipv6addr_param),
2921 (uint8_t *)&addr6_store);
2925 sin6 = (struct sockaddr_in6 *)sa;
2926 if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr)) {
2927 /* create a copy and clear scope */
2928 memcpy(&sin6_tmp, sin6,
2929 sizeof(struct sockaddr_in6));
2931 in6_clearscope(&sin6->sin6_addr);
2933 if (memcmp(&sin6->sin6_addr, a6p->addr,
2934 sizeof(struct in6_addr)) == 0) {
2942 case SCTP_IPV4_ADDRESS:
2943 if (sa->sa_family == AF_INET) {
2944 if (plen != sizeof(struct sctp_ipv4addr_param)) {
2947 /* get the entire IPv4 address param */
2948 a4p = (struct sctp_ipv4addr_param *)
2949 sctp_m_getptr(m, offset,
2950 sizeof(struct sctp_ipv4addr_param),
2951 (uint8_t *)&addr4_store);
2955 sin = (struct sockaddr_in *)sa;
2956 if (sin->sin_addr.s_addr == a4p->addr) {
2966 /* get next parameter */
2967 offset += SCTP_SIZE32(plen);
2968 if (offset + sizeof(struct sctp_paramhdr) > length) {
2971 ph = (struct sctp_paramhdr *)
2972 sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr),
2973 (uint8_t *)&tmp_param);
2980 * makes sure that the current endpoint local addr list is consistent with
2981 * the new association (eg. subset bound, asconf allowed) adds addresses as
2985 sctp_check_address_list_ep(struct sctp_tcb *stcb, struct mbuf *m, int offset,
2986 int length, struct sockaddr *init_addr)
2988 struct sctp_laddr *laddr;
2990 /* go through the endpoint list */
2991 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
2992 /* be paranoid and validate the laddr */
2993 if (laddr->ifa == NULL) {
2994 SCTPDBG(SCTP_DEBUG_ASCONF1,
2995 "check_addr_list_ep: laddr->ifa is NULL");
2998 if (laddr->ifa == NULL) {
2999 SCTPDBG(SCTP_DEBUG_ASCONF1, "check_addr_list_ep: laddr->ifa->ifa_addr is NULL");
3002 /* do i have it implicitly? */
3003 if (sctp_cmpaddr(&laddr->ifa->address.sa, init_addr)) {
3006 /* check to see if in the init-ack */
3007 if (!sctp_addr_in_initack(m, offset, length, &laddr->ifa->address.sa)) {
3009 sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb, laddr->ifa,
3010 SCTP_ADD_IP_ADDRESS, SCTP_ADDR_NOT_LOCKED);
3016 * makes sure that the current kernel address list is consistent with the new
3017 * association (with all addrs bound) adds addresses as necessary
3020 sctp_check_address_list_all(struct sctp_tcb *stcb, struct mbuf *m, int offset,
3021 int length, struct sockaddr *init_addr,
3022 uint16_t local_scope, uint16_t site_scope,
3023 uint16_t ipv4_scope, uint16_t loopback_scope)
3025 struct sctp_vrf *vrf = NULL;
3026 struct sctp_ifn *sctp_ifn;
3027 struct sctp_ifa *sctp_ifa;
3030 struct sockaddr_in *sin;
3033 struct sockaddr_in6 *sin6;
3037 vrf_id = stcb->asoc.vrf_id;
3041 SCTP_IPI_ADDR_RLOCK();
3042 vrf = sctp_find_vrf(vrf_id);
3044 SCTP_IPI_ADDR_RUNLOCK();
3047 /* go through all our known interfaces */
3048 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
3049 if (loopback_scope == 0 && SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
3050 /* skip loopback interface */
3053 /* go through each interface address */
3054 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
3055 /* do i have it implicitly? */
3056 if (sctp_cmpaddr(&sctp_ifa->address.sa, init_addr)) {
3059 switch (sctp_ifa->address.sa.sa_family) {
3062 sin = &sctp_ifa->address.sin;
3063 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
3064 &sin->sin_addr) != 0) {
3067 if ((ipv4_scope == 0) &&
3068 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
3069 /* private address not in scope */
3076 sin6 = &sctp_ifa->address.sin6;
3077 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
3078 &sin6->sin6_addr) != 0) {
3081 if ((local_scope == 0) &&
3082 (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))) {
3085 if ((site_scope == 0) &&
3086 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
3094 /* check to see if in the init-ack */
3095 if (!sctp_addr_in_initack(m, offset, length, &sctp_ifa->address.sa)) {
3097 sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb,
3098 sctp_ifa, SCTP_ADD_IP_ADDRESS,
3101 } /* end foreach ifa */
3102 } /* end foreach ifn */
3103 SCTP_IPI_ADDR_RUNLOCK();
3107 * validates an init-ack chunk (from a cookie-echo) with current addresses
3108 * adds addresses from the init-ack into our local address list, if needed
3109 * queues asconf adds/deletes addresses as needed and makes appropriate list
3110 * changes for source address selection m, offset: points to the start of the
3111 * address list in an init-ack chunk length: total length of the address
3112 * params only init_addr: address where my INIT-ACK was sent from
3115 sctp_check_address_list(struct sctp_tcb *stcb, struct mbuf *m, int offset,
3116 int length, struct sockaddr *init_addr,
3117 uint16_t local_scope, uint16_t site_scope,
3118 uint16_t ipv4_scope, uint16_t loopback_scope)
3120 /* process the local addresses in the initack */
3121 sctp_process_initack_addresses(stcb, m, offset, length);
3123 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3124 /* bound all case */
3125 sctp_check_address_list_all(stcb, m, offset, length, init_addr,
3126 local_scope, site_scope, ipv4_scope, loopback_scope);
3128 /* subset bound case */
3129 if (sctp_is_feature_on(stcb->sctp_ep,
3130 SCTP_PCB_FLAGS_DO_ASCONF)) {
3131 /* asconf's allowed */
3132 sctp_check_address_list_ep(stcb, m, offset, length,
3135 /* else, no asconfs allowed, so what we sent is what we get */
3140 * sctp_bindx() support
3143 sctp_addr_mgmt_ep_sa(struct sctp_inpcb *inp, struct sockaddr *sa,
3144 uint32_t type, uint32_t vrf_id, struct sctp_ifa *sctp_ifap)
3146 struct sctp_ifa *ifa;
3147 struct sctp_laddr *laddr, *nladdr;
3149 if (sa->sa_len == 0) {
3150 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EINVAL);
3155 } else if (type == SCTP_ADD_IP_ADDRESS) {
3156 /* For an add the address MUST be on the system */
3157 ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED);
3158 } else if (type == SCTP_DEL_IP_ADDRESS) {
3159 /* For a delete we need to find it in the inp */
3160 ifa = sctp_find_ifa_in_ep(inp, sa, SCTP_ADDR_NOT_LOCKED);
3165 if (type == SCTP_ADD_IP_ADDRESS) {
3166 sctp_add_local_addr_ep(inp, ifa, type);
3167 } else if (type == SCTP_DEL_IP_ADDRESS) {
3168 if (inp->laddr_count < 2) {
3169 /* can't delete the last local address */
3170 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EINVAL);
3173 LIST_FOREACH(laddr, &inp->sctp_addr_list,
3175 if (ifa == laddr->ifa) {
3176 /* Mark in the delete */
3177 laddr->action = type;
3181 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
3183 * There is no need to start the iterator if the inp
3184 * has no associations.
3186 if (type == SCTP_DEL_IP_ADDRESS) {
3187 LIST_FOREACH_SAFE(laddr, &inp->sctp_addr_list, sctp_nxt_addr, nladdr) {
3188 if (laddr->ifa == ifa) {
3189 sctp_del_local_addr_ep(inp, ifa);
3194 struct sctp_asconf_iterator *asc;
3195 struct sctp_laddr *wi;
3198 SCTP_MALLOC(asc, struct sctp_asconf_iterator *,
3199 sizeof(struct sctp_asconf_iterator),
3202 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, ENOMEM);
3205 wi = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_laddr), struct sctp_laddr);
3207 SCTP_FREE(asc, SCTP_M_ASC_IT);
3208 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, ENOMEM);
3211 LIST_INIT(&asc->list_of_work);
3213 SCTP_INCR_LADDR_COUNT();
3216 atomic_add_int(&ifa->refcount, 1);
3217 LIST_INSERT_HEAD(&asc->list_of_work, wi, sctp_nxt_addr);
3218 ret = sctp_initiate_iterator(sctp_asconf_iterator_ep,
3219 sctp_asconf_iterator_stcb,
3220 sctp_asconf_iterator_ep_end,
3222 SCTP_PCB_ANY_FEATURES,
3223 SCTP_ASOC_ANY_STATE,
3225 sctp_asconf_iterator_end, inp, 0);
3227 SCTP_PRINTF("Failed to initiate iterator for addr_mgmt_ep_sa\n");
3228 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EFAULT);
3229 sctp_asconf_iterator_end(asc, 0);
3235 /* invalid address! */
3236 SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EADDRNOTAVAIL);
3237 return (EADDRNOTAVAIL);
3242 sctp_asconf_send_nat_state_update(struct sctp_tcb *stcb,
3243 struct sctp_nets *net)
3245 struct sctp_asconf_addr *aa;
3246 struct sctp_ifa *sctp_ifap;
3247 struct sctp_asconf_tag_param *vtag;
3249 struct sockaddr_in *to;
3252 struct sockaddr_in6 *to6;
3255 SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing net\n");
3259 SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing stcb\n");
3263 * Need to have in the asconf: - vtagparam(my_vtag/peer_vtag) -
3264 * add(0.0.0.0) - del(0.0.0.0) - Any global addresses add(addr)
3266 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
3269 /* didn't get memory */
3270 SCTPDBG(SCTP_DEBUG_ASCONF1,
3271 "sctp_asconf_send_nat_state_update: failed to get memory!\n");
3274 aa->special_del = 0;
3275 /* fill in asconf address parameter fields */
3276 /* top level elements are "networked" during send */
3278 aa->sent = 0; /* clear sent flag */
3279 vtag = (struct sctp_asconf_tag_param *)&aa->ap.aph;
3280 vtag->aph.ph.param_type = SCTP_NAT_VTAGS;
3281 vtag->aph.ph.param_length = sizeof(struct sctp_asconf_tag_param);
3282 vtag->local_vtag = htonl(stcb->asoc.my_vtag);
3283 vtag->remote_vtag = htonl(stcb->asoc.peer_vtag);
3284 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
3286 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
3289 /* didn't get memory */
3290 SCTPDBG(SCTP_DEBUG_ASCONF1,
3291 "sctp_asconf_send_nat_state_update: failed to get memory!\n");
3294 memset(aa, 0, sizeof(struct sctp_asconf_addr));
3295 /* fill in asconf address parameter fields */
3297 switch (net->ro._l_addr.sa.sa_family) {
3300 aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
3301 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param);
3302 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
3303 aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv4addr_param);
3304 /* No need to add an address, we are using 0.0.0.0 */
3305 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
3310 aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
3311 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param);
3312 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
3313 aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv6addr_param);
3314 /* No need to add an address, we are using 0.0.0.0 */
3315 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
3319 SCTPDBG(SCTP_DEBUG_ASCONF1,
3320 "sctp_asconf_send_nat_state_update: unknown address family\n");
3321 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
3324 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
3327 /* didn't get memory */
3328 SCTPDBG(SCTP_DEBUG_ASCONF1,
3329 "sctp_asconf_send_nat_state_update: failed to get memory!\n");
3332 memset(aa, 0, sizeof(struct sctp_asconf_addr));
3333 /* fill in asconf address parameter fields */
3335 switch (net->ro._l_addr.sa.sa_family) {
3338 aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
3339 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param);
3340 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
3341 aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv4addr_param);
3342 /* No need to add an address, we are using 0.0.0.0 */
3343 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
3348 aa->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS;
3349 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param);
3350 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
3351 aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv6addr_param);
3352 /* No need to add an address, we are using 0.0.0.0 */
3353 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
3357 SCTPDBG(SCTP_DEBUG_ASCONF1,
3358 "sctp_asconf_send_nat_state_update: unknown address family\n");
3359 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
3362 /* Now we must hunt the addresses and add all global addresses */
3363 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3364 struct sctp_vrf *vrf = NULL;
3365 struct sctp_ifn *sctp_ifnp;
3368 vrf_id = stcb->sctp_ep->def_vrf_id;
3369 vrf = sctp_find_vrf(vrf_id);
3373 SCTP_IPI_ADDR_RLOCK();
3374 LIST_FOREACH(sctp_ifnp, &vrf->ifnlist, next_ifn) {
3375 LIST_FOREACH(sctp_ifap, &sctp_ifnp->ifalist, next_ifa) {
3376 switch (sctp_ifap->address.sa.sa_family) {
3379 to = &sctp_ifap->address.sin;
3380 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
3381 &to->sin_addr) != 0) {
3384 if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) {
3387 if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) {
3394 to6 = &sctp_ifap->address.sin6;
3395 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
3396 &to6->sin6_addr) != 0) {
3399 if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) {
3402 if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) {
3410 sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS);
3413 SCTP_IPI_ADDR_RUNLOCK();
3415 struct sctp_laddr *laddr;
3417 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
3418 if (laddr->ifa == NULL) {
3421 if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED)
3423 * Address being deleted by the system, dont
3427 if (laddr->action == SCTP_DEL_IP_ADDRESS) {
3429 * Address being deleted on this ep don't
3434 sctp_ifap = laddr->ifa;
3435 switch (sctp_ifap->address.sa.sa_family) {
3438 to = &sctp_ifap->address.sin;
3439 if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) {
3442 if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) {
3449 to6 = &sctp_ifap->address.sin6;
3450 if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) {
3453 if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) {
3461 sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS);
3465 /* Now we must send the asconf into the queue */
3466 sctp_send_asconf(stcb, net, SCTP_ADDR_NOT_LOCKED);