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
57 * An ASCONF parameter queue exists per asoc which holds the pending address
58 * operations. Lists are updated upon receipt of ASCONF-ACK.
60 * A restricted_addrs list exists per assoc to hold local addresses that are
61 * not (yet) usable by the assoc as a source address. These addresses are
62 * either pending an ASCONF operation (and exist on the ASCONF parameter
63 * queue), or they are permanently restricted (the peer has returned an
64 * ERROR indication to an ASCONF(ADD), or the peer does not support ASCONF).
66 * Deleted addresses are always immediately removed from the lists as they will
67 * (shortly) no longer exist in the kernel. We send ASCONFs as a courtesy,
72 * ASCONF parameter processing.
73 * response_required: set if a reply is required (eg. SUCCESS_REPORT).
74 * returns a mbuf to an "error" response parameter or NULL/"success" if ok.
75 * FIX: allocating this many mbufs on the fly is pretty inefficient...
78 sctp_asconf_success_response(uint32_t id)
80 struct mbuf *m_reply = NULL;
81 struct sctp_asconf_paramhdr *aph;
83 m_reply = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_paramhdr),
84 0, M_NOWAIT, 1, MT_DATA);
85 if (m_reply == NULL) {
86 SCTPDBG(SCTP_DEBUG_ASCONF1,
87 "asconf_success_response: couldn't get mbuf!\n");
90 aph = mtod(m_reply, struct sctp_asconf_paramhdr *);
91 aph->correlation_id = id;
92 aph->ph.param_type = htons(SCTP_SUCCESS_REPORT);
93 aph->ph.param_length = sizeof(struct sctp_asconf_paramhdr);
94 SCTP_BUF_LEN(m_reply) = aph->ph.param_length;
95 aph->ph.param_length = htons(aph->ph.param_length);
101 sctp_asconf_error_response(uint32_t id, uint16_t cause, uint8_t *error_tlv,
104 struct mbuf *m_reply = NULL;
105 struct sctp_asconf_paramhdr *aph;
106 struct sctp_error_cause *error;
108 uint16_t i, param_length, cause_length, padding_length;
111 if (error_tlv == NULL) {
114 cause_length = sizeof(struct sctp_error_cause) + tlv_length;
115 param_length = sizeof(struct sctp_asconf_paramhdr) + cause_length;
116 padding_length = tlv_length % 4;
117 if (padding_length != 0) {
118 padding_length = 4 - padding_length;
120 buf_len = param_length + padding_length;
121 if (buf_len > MLEN) {
122 SCTPDBG(SCTP_DEBUG_ASCONF1,
123 "asconf_error_response: tlv_length (%xh) too big\n",
127 m_reply = sctp_get_mbuf_for_msg(buf_len, 0, M_NOWAIT, 1, MT_DATA);
128 if (m_reply == NULL) {
129 SCTPDBG(SCTP_DEBUG_ASCONF1,
130 "asconf_error_response: couldn't get mbuf!\n");
133 aph = mtod(m_reply, struct sctp_asconf_paramhdr *);
134 aph->ph.param_type = htons(SCTP_ERROR_CAUSE_IND);
135 aph->ph.param_length = htons(param_length);
136 aph->correlation_id = id;
137 error = (struct sctp_error_cause *)(aph + 1);
138 error->code = htons(cause);
139 error->length = htons(cause_length);
140 if (error_tlv != NULL) {
141 tlv = (uint8_t *)(error + 1);
142 memcpy(tlv, error_tlv, tlv_length);
143 for (i = 0; i < padding_length; i++) {
144 tlv[tlv_length + i] = 0;
147 SCTP_BUF_LEN(m_reply) = buf_len;
152 sctp_process_asconf_add_ip(struct sockaddr *src, struct sctp_asconf_paramhdr *aph,
153 struct sctp_tcb *stcb, int send_hb, int response_required)
155 struct sctp_nets *net;
156 struct mbuf *m_reply = NULL;
157 union sctp_sockstore store;
158 struct sctp_paramhdr *ph;
159 uint16_t param_type, aparam_length;
160 #if defined(INET) || defined(INET6)
161 uint16_t param_length;
164 int zero_address = 0;
167 struct sockaddr_in *sin;
168 struct sctp_ipv4addr_param *v4addr;
171 struct sockaddr_in6 *sin6;
172 struct sctp_ipv6addr_param *v6addr;
175 aparam_length = ntohs(aph->ph.param_length);
176 if (aparam_length < sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_paramhdr)) {
179 ph = (struct sctp_paramhdr *)(aph + 1);
180 param_type = ntohs(ph->param_type);
181 #if defined(INET) || defined(INET6)
182 param_length = ntohs(ph->param_length);
183 if (param_length + sizeof(struct sctp_asconf_paramhdr) != aparam_length) {
188 switch (param_type) {
190 case SCTP_IPV4_ADDRESS:
191 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
192 /* invalid param size */
195 v4addr = (struct sctp_ipv4addr_param *)ph;
197 memset(sin, 0, sizeof(*sin));
198 sin->sin_family = AF_INET;
199 sin->sin_len = sizeof(struct sockaddr_in);
200 sin->sin_port = stcb->rport;
201 sin->sin_addr.s_addr = v4addr->addr;
202 if ((sin->sin_addr.s_addr == INADDR_BROADCAST) ||
203 IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) {
206 if (sin->sin_addr.s_addr == INADDR_ANY)
208 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_add_ip: adding ");
209 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
213 case SCTP_IPV6_ADDRESS:
214 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
215 /* invalid param size */
218 v6addr = (struct sctp_ipv6addr_param *)ph;
220 memset(sin6, 0, sizeof(*sin6));
221 sin6->sin6_family = AF_INET6;
222 sin6->sin6_len = sizeof(struct sockaddr_in6);
223 sin6->sin6_port = stcb->rport;
224 memcpy((caddr_t)&sin6->sin6_addr, v6addr->addr,
225 sizeof(struct in6_addr));
226 if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
229 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
231 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_add_ip: adding ");
232 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
236 m_reply = sctp_asconf_error_response(aph->correlation_id,
237 SCTP_CAUSE_INVALID_PARAM, (uint8_t *)aph,
242 /* if 0.0.0.0/::0, add the source address instead */
243 if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) {
245 SCTPDBG(SCTP_DEBUG_ASCONF1,
246 "process_asconf_add_ip: using source addr ");
247 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, src);
250 /* add the address */
252 m_reply = sctp_asconf_error_response(aph->correlation_id,
253 SCTP_CAUSE_INVALID_PARAM, (uint8_t *)aph,
255 } else if (sctp_add_remote_addr(stcb, sa, &net, stcb->asoc.port,
257 SCTP_ADDR_DYNAMIC_ADDED) != 0) {
258 SCTPDBG(SCTP_DEBUG_ASCONF1,
259 "process_asconf_add_ip: error adding address\n");
260 m_reply = sctp_asconf_error_response(aph->correlation_id,
261 SCTP_CAUSE_RESOURCE_SHORTAGE, (uint8_t *)aph,
264 if (response_required) {
266 sctp_asconf_success_response(aph->correlation_id);
269 /* notify upper layer */
270 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_ADD_IP, stcb, 0, sa, SCTP_SO_NOT_LOCKED);
271 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, stcb->sctp_ep, stcb, net);
272 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep,
275 sctp_send_hb(stcb, net, SCTP_SO_NOT_LOCKED);
283 sctp_asconf_del_remote_addrs_except(struct sctp_tcb *stcb, struct sockaddr *src)
285 struct sctp_nets *src_net, *net, *nnet;
287 /* make sure the source address exists as a destination net */
288 src_net = sctp_findnet(stcb, src);
289 if (src_net == NULL) {
294 /* delete all destination addresses except the source */
295 TAILQ_FOREACH_SAFE(net, &stcb->asoc.nets, sctp_next, nnet) {
296 if (net != src_net) {
297 /* delete this address */
298 SCTPDBG(SCTP_DEBUG_ASCONF1,
299 "asconf_del_remote_addrs_except: deleting ");
300 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1,
301 (struct sockaddr *)&net->ro._l_addr);
302 /* notify upper layer */
303 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0,
304 (struct sockaddr *)&net->ro._l_addr, SCTP_SO_NOT_LOCKED);
305 sctp_remove_net(stcb, net);
312 sctp_process_asconf_delete_ip(struct sockaddr *src,
313 struct sctp_asconf_paramhdr *aph,
314 struct sctp_tcb *stcb, int response_required)
316 struct mbuf *m_reply = NULL;
317 union sctp_sockstore store;
318 struct sctp_paramhdr *ph;
319 uint16_t param_type, aparam_length;
320 #if defined(INET) || defined(INET6)
321 uint16_t param_length;
324 int zero_address = 0;
327 struct sockaddr_in *sin;
328 struct sctp_ipv4addr_param *v4addr;
331 struct sockaddr_in6 *sin6;
332 struct sctp_ipv6addr_param *v6addr;
335 aparam_length = ntohs(aph->ph.param_length);
336 if (aparam_length < sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_paramhdr)) {
339 ph = (struct sctp_paramhdr *)(aph + 1);
340 param_type = ntohs(ph->param_type);
341 #if defined(INET) || defined(INET6)
342 param_length = ntohs(ph->param_length);
343 if (param_length + sizeof(struct sctp_asconf_paramhdr) != aparam_length) {
348 switch (param_type) {
350 case SCTP_IPV4_ADDRESS:
351 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
352 /* invalid param size */
355 v4addr = (struct sctp_ipv4addr_param *)ph;
357 memset(sin, 0, sizeof(*sin));
358 sin->sin_family = AF_INET;
359 sin->sin_len = sizeof(struct sockaddr_in);
360 sin->sin_port = stcb->rport;
361 sin->sin_addr.s_addr = v4addr->addr;
362 if (sin->sin_addr.s_addr == INADDR_ANY)
364 SCTPDBG(SCTP_DEBUG_ASCONF1,
365 "process_asconf_delete_ip: deleting ");
366 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
370 case SCTP_IPV6_ADDRESS:
371 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
372 /* invalid param size */
375 v6addr = (struct sctp_ipv6addr_param *)ph;
377 memset(sin6, 0, sizeof(*sin6));
378 sin6->sin6_family = AF_INET6;
379 sin6->sin6_len = sizeof(struct sockaddr_in6);
380 sin6->sin6_port = stcb->rport;
381 memcpy(&sin6->sin6_addr, v6addr->addr,
382 sizeof(struct in6_addr));
383 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
385 SCTPDBG(SCTP_DEBUG_ASCONF1,
386 "process_asconf_delete_ip: deleting ");
387 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
391 m_reply = sctp_asconf_error_response(aph->correlation_id,
392 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *)aph,
397 /* make sure the source address is not being deleted */
398 if (sctp_cmpaddr(sa, src)) {
399 /* trying to delete the source address! */
400 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: tried to delete source addr\n");
401 m_reply = sctp_asconf_error_response(aph->correlation_id,
402 SCTP_CAUSE_DELETING_SRC_ADDR, (uint8_t *)aph,
407 /* if deleting 0.0.0.0/::0, delete all addresses except src addr */
408 if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) {
409 result = sctp_asconf_del_remote_addrs_except(stcb, src);
412 /* src address did not exist? */
413 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: src addr does not exist?\n");
414 /* what error to reply with?? */
416 sctp_asconf_error_response(aph->correlation_id,
417 SCTP_CAUSE_REQUEST_REFUSED, (uint8_t *)aph,
419 } else if (response_required) {
421 sctp_asconf_success_response(aph->correlation_id);
426 /* delete the address */
427 result = sctp_del_remote_addr(stcb, sa);
429 * note if result == -2, the address doesn't exist in the asoc but
430 * since it's being deleted anyways, we just ack the delete -- but
431 * this probably means something has already gone awry
434 /* only one address in the asoc */
435 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: tried to delete last IP addr!\n");
436 m_reply = sctp_asconf_error_response(aph->correlation_id,
437 SCTP_CAUSE_DELETING_LAST_ADDR, (uint8_t *)aph,
440 if (response_required) {
441 m_reply = sctp_asconf_success_response(aph->correlation_id);
443 /* notify upper layer */
444 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0, sa, SCTP_SO_NOT_LOCKED);
450 sctp_process_asconf_set_primary(struct sockaddr *src,
451 struct sctp_asconf_paramhdr *aph,
452 struct sctp_tcb *stcb, int response_required)
454 struct mbuf *m_reply = NULL;
455 union sctp_sockstore store;
456 struct sctp_paramhdr *ph;
457 uint16_t param_type, aparam_length;
458 #if defined(INET) || defined(INET6)
459 uint16_t param_length;
462 int zero_address = 0;
464 struct sockaddr_in *sin;
465 struct sctp_ipv4addr_param *v4addr;
468 struct sockaddr_in6 *sin6;
469 struct sctp_ipv6addr_param *v6addr;
472 aparam_length = ntohs(aph->ph.param_length);
473 if (aparam_length < sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_paramhdr)) {
476 ph = (struct sctp_paramhdr *)(aph + 1);
477 param_type = ntohs(ph->param_type);
478 #if defined(INET) || defined(INET6)
479 param_length = ntohs(ph->param_length);
480 if (param_length + sizeof(struct sctp_asconf_paramhdr) != aparam_length) {
485 switch (param_type) {
487 case SCTP_IPV4_ADDRESS:
488 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
489 /* invalid param size */
492 v4addr = (struct sctp_ipv4addr_param *)ph;
494 memset(sin, 0, sizeof(*sin));
495 sin->sin_family = AF_INET;
496 sin->sin_len = sizeof(struct sockaddr_in);
497 sin->sin_addr.s_addr = v4addr->addr;
498 if (sin->sin_addr.s_addr == INADDR_ANY)
500 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_set_primary: ");
501 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
505 case SCTP_IPV6_ADDRESS:
506 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
507 /* invalid param size */
510 v6addr = (struct sctp_ipv6addr_param *)ph;
512 memset(sin6, 0, sizeof(*sin6));
513 sin6->sin6_family = AF_INET6;
514 sin6->sin6_len = sizeof(struct sockaddr_in6);
515 memcpy((caddr_t)&sin6->sin6_addr, v6addr->addr,
516 sizeof(struct in6_addr));
517 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
519 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_set_primary: ");
520 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
524 m_reply = sctp_asconf_error_response(aph->correlation_id,
525 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *)aph,
530 /* if 0.0.0.0/::0, use the source address instead */
531 if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) {
533 SCTPDBG(SCTP_DEBUG_ASCONF1,
534 "process_asconf_set_primary: using source addr ");
535 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, src);
537 /* set the primary address */
538 if (sctp_set_primary_addr(stcb, sa, NULL) == 0) {
539 SCTPDBG(SCTP_DEBUG_ASCONF1,
540 "process_asconf_set_primary: primary address set\n");
541 /* notify upper layer */
542 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_SET_PRIMARY, stcb, 0, sa, SCTP_SO_NOT_LOCKED);
543 if ((stcb->asoc.primary_destination->dest_state & SCTP_ADDR_REACHABLE) &&
544 (!(stcb->asoc.primary_destination->dest_state & SCTP_ADDR_PF)) &&
545 (stcb->asoc.alternate)) {
546 sctp_free_remote_addr(stcb->asoc.alternate);
547 stcb->asoc.alternate = NULL;
549 if (response_required) {
550 m_reply = sctp_asconf_success_response(aph->correlation_id);
553 * Mobility adaptation. Ideally, when the reception of SET
554 * PRIMARY with DELETE IP ADDRESS of the previous primary
555 * destination, unacknowledged DATA are retransmitted
556 * immediately to the new primary destination for seamless
557 * handover. If the destination is UNCONFIRMED and marked to
558 * REQ_PRIM, The retransmission occur when reception of the
559 * HEARTBEAT-ACK. (See sctp_handle_heartbeat_ack in
560 * sctp_input.c) Also, when change of the primary
561 * destination, it is better that all subsequent new DATA
562 * containing already queued DATA are transmitted to the new
563 * primary destination. (by micchie)
565 if ((sctp_is_mobility_feature_on(stcb->sctp_ep,
566 SCTP_MOBILITY_BASE) ||
567 sctp_is_mobility_feature_on(stcb->sctp_ep,
568 SCTP_MOBILITY_FASTHANDOFF)) &&
569 sctp_is_mobility_feature_on(stcb->sctp_ep,
570 SCTP_MOBILITY_PRIM_DELETED) &&
571 (stcb->asoc.primary_destination->dest_state &
572 SCTP_ADDR_UNCONFIRMED) == 0) {
573 sctp_timer_stop(SCTP_TIMER_TYPE_PRIM_DELETED,
574 stcb->sctp_ep, stcb, NULL,
575 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_1);
576 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
577 SCTP_MOBILITY_FASTHANDOFF)) {
578 sctp_assoc_immediate_retrans(stcb,
579 stcb->asoc.primary_destination);
581 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
582 SCTP_MOBILITY_BASE)) {
583 sctp_move_chunks_from_net(stcb,
584 stcb->asoc.deleted_primary);
586 sctp_delete_prim_timer(stcb->sctp_ep, stcb);
589 /* couldn't set the requested primary address! */
590 SCTPDBG(SCTP_DEBUG_ASCONF1,
591 "process_asconf_set_primary: set primary failed!\n");
592 /* must have been an invalid address, so report */
593 m_reply = sctp_asconf_error_response(aph->correlation_id,
594 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *)aph,
602 * handles an ASCONF chunk.
603 * if all parameters are processed ok, send a plain (empty) ASCONF-ACK
606 sctp_handle_asconf(struct mbuf *m, unsigned int offset,
607 struct sockaddr *src,
608 struct sctp_asconf_chunk *cp, struct sctp_tcb *stcb,
611 struct sctp_association *asoc;
613 struct mbuf *n, *m_ack, *m_result, *m_tail;
614 struct sctp_asconf_ack_chunk *ack_cp;
615 struct sctp_asconf_paramhdr *aph;
616 struct sctp_ipv6addr_param *p_addr;
617 unsigned int asconf_limit, cnt;
618 int error = 0; /* did an error occur? */
620 /* asconf param buffer */
621 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE];
622 struct sctp_asconf_ack *ack, *ack_next;
624 /* verify minimum length */
625 if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_chunk)) {
626 SCTPDBG(SCTP_DEBUG_ASCONF1,
627 "handle_asconf: chunk too small = %xh\n",
628 ntohs(cp->ch.chunk_length));
632 serial_num = ntohl(cp->serial_number);
634 if (SCTP_TSN_GE(asoc->asconf_seq_in, serial_num)) {
635 /* got a duplicate ASCONF */
636 SCTPDBG(SCTP_DEBUG_ASCONF1,
637 "handle_asconf: got duplicate serial number = %xh\n",
640 } else if (serial_num != (asoc->asconf_seq_in + 1)) {
641 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: incorrect serial number = %xh (expected next = %xh)\n",
642 serial_num, asoc->asconf_seq_in + 1);
646 /* it's the expected "next" sequence number, so process it */
647 asoc->asconf_seq_in = serial_num; /* update sequence */
648 /* get length of all the param's in the ASCONF */
649 asconf_limit = offset + ntohs(cp->ch.chunk_length);
650 SCTPDBG(SCTP_DEBUG_ASCONF1,
651 "handle_asconf: asconf_limit=%u, sequence=%xh\n",
652 asconf_limit, serial_num);
655 /* delete old cache */
656 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: Now processing first ASCONF. Try to delete old cache\n");
658 TAILQ_FOREACH_SAFE(ack, &asoc->asconf_ack_sent, next, ack_next) {
659 if (ack->serial_number == serial_num)
661 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: delete old(%u) < first(%u)\n",
662 ack->serial_number, serial_num);
663 TAILQ_REMOVE(&asoc->asconf_ack_sent, ack, next);
664 if (ack->data != NULL) {
665 sctp_m_freem(ack->data);
667 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_asconf_ack), ack);
671 m_ack = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_ack_chunk), 0,
672 M_NOWAIT, 1, MT_DATA);
674 SCTPDBG(SCTP_DEBUG_ASCONF1,
675 "handle_asconf: couldn't get mbuf!\n");
678 m_tail = m_ack; /* current reply chain's tail */
680 /* fill in ASCONF-ACK header */
681 ack_cp = mtod(m_ack, struct sctp_asconf_ack_chunk *);
682 ack_cp->ch.chunk_type = SCTP_ASCONF_ACK;
683 ack_cp->ch.chunk_flags = 0;
684 ack_cp->serial_number = htonl(serial_num);
685 /* set initial lengths (eg. just an ASCONF-ACK), ntohx at the end! */
686 SCTP_BUF_LEN(m_ack) = sizeof(struct sctp_asconf_ack_chunk);
687 ack_cp->ch.chunk_length = sizeof(struct sctp_asconf_ack_chunk);
689 /* skip the lookup address parameter */
690 offset += sizeof(struct sctp_asconf_chunk);
691 p_addr = (struct sctp_ipv6addr_param *)sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), (uint8_t *)&aparam_buf);
692 if (p_addr == NULL) {
693 SCTPDBG(SCTP_DEBUG_ASCONF1,
694 "handle_asconf: couldn't get lookup addr!\n");
695 /* respond with a missing/invalid mandatory parameter error */
699 /* skip lookup addr */
700 offset += SCTP_SIZE32(ntohs(p_addr->ph.param_length));
701 /* get pointer to first asconf param in ASCONF */
702 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, sizeof(struct sctp_asconf_paramhdr), (uint8_t *)&aparam_buf);
704 SCTPDBG(SCTP_DEBUG_ASCONF1, "Empty ASCONF received?\n");
707 /* process through all parameters */
709 while (aph != NULL) {
710 unsigned int param_length, param_type;
712 param_type = ntohs(aph->ph.param_type);
713 param_length = ntohs(aph->ph.param_length);
714 if (offset + param_length > asconf_limit) {
715 /* parameter goes beyond end of chunk! */
721 if (param_length > sizeof(aparam_buf)) {
722 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) larger than buffer size!\n", param_length);
726 if (param_length <= sizeof(struct sctp_paramhdr)) {
727 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) too short\n", param_length);
731 /* get the entire parameter */
732 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf);
734 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: couldn't get entire param\n");
738 switch (param_type) {
739 case SCTP_ADD_IP_ADDRESS:
740 m_result = sctp_process_asconf_add_ip(src, aph, stcb,
741 (cnt < SCTP_BASE_SYSCTL(sctp_hb_maxburst)), error);
744 case SCTP_DEL_IP_ADDRESS:
745 m_result = sctp_process_asconf_delete_ip(src, aph, stcb,
748 case SCTP_ERROR_CAUSE_IND:
749 /* not valid in an ASCONF chunk */
751 case SCTP_SET_PRIM_ADDR:
752 m_result = sctp_process_asconf_set_primary(src, aph,
756 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: sees a NAT VTAG state parameter\n");
758 case SCTP_SUCCESS_REPORT:
759 /* not valid in an ASCONF chunk */
761 case SCTP_ULP_ADAPTATION:
765 if ((param_type & 0x8000) == 0) {
766 /* Been told to STOP at this param */
767 asconf_limit = offset;
769 * FIX FIX - We need to call
770 * sctp_arethere_unrecognized_parameters()
771 * to get a operr and send it for any
772 * param's with the 0x4000 bit set OR do it
773 * here ourselves... note we still must STOP
774 * if the 0x8000 bit is clear.
777 /* unknown/invalid param type */
781 /* add any (error) result to the reply mbuf chain */
782 if (m_result != NULL) {
783 SCTP_BUF_NEXT(m_tail) = m_result;
785 ack_cp->ch.chunk_length += SCTP_BUF_LEN(m_result);
786 /* set flag to force success reports */
789 offset += SCTP_SIZE32(param_length);
790 /* update remaining ASCONF message length to process */
791 if (offset >= asconf_limit) {
792 /* no more data in the mbuf chain */
795 /* get pointer to next asconf param */
796 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset,
797 sizeof(struct sctp_asconf_paramhdr),
798 (uint8_t *)&aparam_buf);
800 /* can't get an asconf paramhdr */
801 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: can't get asconf param hdr!\n");
802 /* FIX ME - add error here... */
807 ack_cp->ch.chunk_length = htons(ack_cp->ch.chunk_length);
808 /* save the ASCONF-ACK reply */
809 ack = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_asconf_ack),
810 struct sctp_asconf_ack);
815 ack->serial_number = serial_num;
816 ack->last_sent_to = NULL;
819 for (n = m_ack; n != NULL; n = SCTP_BUF_NEXT(n)) {
820 ack->len += SCTP_BUF_LEN(n);
822 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_ack_sent, ack, next);
824 /* see if last_control_chunk_from is set properly (use IP src addr) */
825 if (stcb->asoc.last_control_chunk_from == NULL) {
827 * this could happen if the source address was just newly
830 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: looking up net for IP source address\n");
831 SCTPDBG(SCTP_DEBUG_ASCONF1, "Looking for IP source: ");
832 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, src);
833 /* look up the from address */
834 stcb->asoc.last_control_chunk_from = sctp_findnet(stcb, src);
836 if (stcb->asoc.last_control_chunk_from == NULL) {
837 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: IP source address not found?!\n");
844 * does the address match? returns 0 if not, 1 if so
847 sctp_asconf_addr_match(struct sctp_asconf_addr *aa, struct sockaddr *sa)
849 switch (sa->sa_family) {
854 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
856 if ((aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) &&
857 (memcmp(&aa->ap.addrp.addr, &sin6->sin6_addr,
858 sizeof(struct in6_addr)) == 0)) {
867 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
869 if ((aa->ap.addrp.ph.param_type == SCTP_IPV4_ADDRESS) &&
870 (memcmp(&aa->ap.addrp.addr, &sin->sin_addr,
871 sizeof(struct in_addr)) == 0)) {
884 * does the address match? returns 0 if not, 1 if so
887 sctp_addr_match(struct sctp_paramhdr *ph, struct sockaddr *sa)
889 #if defined(INET) || defined(INET6)
890 uint16_t param_type, param_length;
892 param_type = ntohs(ph->param_type);
893 param_length = ntohs(ph->param_length);
895 switch (sa->sa_family) {
900 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
901 struct sctp_ipv6addr_param *v6addr;
903 v6addr = (struct sctp_ipv6addr_param *)ph;
904 if ((param_type == SCTP_IPV6_ADDRESS) &&
905 (param_length == sizeof(struct sctp_ipv6addr_param)) &&
906 (memcmp(&v6addr->addr, &sin6->sin6_addr,
907 sizeof(struct in6_addr)) == 0)) {
916 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
917 struct sctp_ipv4addr_param *v4addr;
919 v4addr = (struct sctp_ipv4addr_param *)ph;
920 if ((param_type == SCTP_IPV4_ADDRESS) &&
921 (param_length == sizeof(struct sctp_ipv4addr_param)) &&
922 (memcmp(&v4addr->addr, &sin->sin_addr,
923 sizeof(struct in_addr)) == 0)) {
936 * Cleanup for non-responded/OP ERR'd ASCONF
939 sctp_asconf_cleanup(struct sctp_tcb *stcb)
942 * clear out any existing asconfs going out
944 sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, NULL,
945 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_2);
946 stcb->asoc.asconf_seq_out_acked = stcb->asoc.asconf_seq_out;
947 /* remove the old ASCONF on our outbound queue */
948 sctp_toss_old_asconf(stcb);
952 * cleanup any cached source addresses that may be topologically
953 * incorrect after a new address has been added to this interface.
956 sctp_asconf_nets_cleanup(struct sctp_tcb *stcb, struct sctp_ifn *ifn)
958 struct sctp_nets *net;
961 * Ideally, we want to only clear cached routes and source addresses
962 * that are topologically incorrect. But since there is no easy way
963 * to know whether the newly added address on the ifn would cause a
964 * routing change (i.e. a new egress interface would be chosen)
965 * without doing a new routing lookup and source address selection,
966 * we will (for now) just flush any cached route using a different
967 * ifn (and cached source addrs) and let output re-choose them
968 * during the next send on that net.
970 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
972 * clear any cached route (and cached source address) if the
973 * route's interface is NOT the same as the address change.
974 * If it's the same interface, just clear the cached source
977 if (SCTP_ROUTE_HAS_VALID_IFN(&net->ro) &&
979 (SCTP_GET_IF_INDEX_FROM_ROUTE(&net->ro) != ifn->ifn_index))) {
980 /* clear any cached route */
983 /* clear any cached source address */
984 if (net->src_addr_selected) {
985 sctp_free_ifa(net->ro._s_addr);
986 net->ro._s_addr = NULL;
987 net->src_addr_selected = 0;
993 sctp_assoc_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *dstnet)
997 if (dstnet->dest_state & SCTP_ADDR_UNCONFIRMED) {
1000 if (stcb->asoc.deleted_primary == NULL) {
1004 if (!TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
1005 SCTPDBG(SCTP_DEBUG_ASCONF1, "assoc_immediate_retrans: Deleted primary is ");
1006 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &stcb->asoc.deleted_primary->ro._l_addr.sa);
1007 SCTPDBG(SCTP_DEBUG_ASCONF1, "Current Primary is ");
1008 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &stcb->asoc.primary_destination->ro._l_addr.sa);
1009 sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb,
1010 stcb->asoc.deleted_primary,
1011 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_3);
1012 stcb->asoc.num_send_timers_up--;
1013 if (stcb->asoc.num_send_timers_up < 0) {
1014 stcb->asoc.num_send_timers_up = 0;
1016 SCTP_TCB_LOCK_ASSERT(stcb);
1017 error = sctp_t3rxt_timer(stcb->sctp_ep, stcb,
1018 stcb->asoc.deleted_primary);
1020 SCTP_INP_DECR_REF(stcb->sctp_ep);
1023 SCTP_TCB_LOCK_ASSERT(stcb);
1024 #ifdef SCTP_AUDITING_ENABLED
1025 sctp_auditing(4, stcb->sctp_ep, stcb, stcb->asoc.deleted_primary);
1027 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED);
1028 if ((stcb->asoc.num_send_timers_up == 0) &&
1029 (stcb->asoc.sent_queue_cnt > 0)) {
1030 struct sctp_tmit_chunk *chk;
1032 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
1033 if (chk->whoTo != NULL) {
1038 sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, chk->whoTo);
1046 sctp_asconf_queue_mgmt(struct sctp_tcb *, struct sctp_ifa *, uint16_t);
1049 sctp_net_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *net)
1051 struct sctp_tmit_chunk *chk;
1053 SCTPDBG(SCTP_DEBUG_ASCONF1, "net_immediate_retrans: RTO is %d\n", net->RTO);
1054 sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, net,
1055 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_4);
1056 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
1057 net->error_count = 0;
1058 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
1059 if (chk->whoTo == net) {
1060 if (chk->sent < SCTP_DATAGRAM_RESEND) {
1061 chk->sent = SCTP_DATAGRAM_RESEND;
1062 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
1063 sctp_flight_size_decrease(chk);
1064 sctp_total_flight_decrease(stcb, chk);
1065 net->marked_retrans++;
1066 stcb->asoc.marked_retrans++;
1070 if (net->marked_retrans) {
1071 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED);
1076 sctp_path_check_and_react(struct sctp_tcb *stcb, struct sctp_ifa *newifa)
1078 struct sctp_nets *net;
1079 int addrnum, changed;
1082 * If number of local valid addresses is 1, the valid address is
1083 * probably newly added address. Several valid addresses in this
1084 * association. A source address may not be changed. Additionally,
1085 * they can be configured on a same interface as "alias" addresses.
1088 addrnum = sctp_local_addr_count(stcb);
1089 SCTPDBG(SCTP_DEBUG_ASCONF1, "p_check_react(): %d local addresses\n",
1092 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1093 /* clear any cached route and source address */
1094 RO_NHFREE(&net->ro);
1095 if (net->src_addr_selected) {
1096 sctp_free_ifa(net->ro._s_addr);
1097 net->ro._s_addr = NULL;
1098 net->src_addr_selected = 0;
1100 /* Retransmit unacknowledged DATA chunks immediately */
1101 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
1102 SCTP_MOBILITY_FASTHANDOFF)) {
1103 sctp_net_immediate_retrans(stcb, net);
1105 /* also, SET PRIMARY is maybe already sent */
1110 /* Multiple local addresses exsist in the association. */
1111 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1112 /* clear any cached route and source address */
1113 RO_NHFREE(&net->ro);
1114 if (net->src_addr_selected) {
1115 sctp_free_ifa(net->ro._s_addr);
1116 net->ro._s_addr = NULL;
1117 net->src_addr_selected = 0;
1120 * Check if the nexthop is corresponding to the new address.
1121 * If the new address is corresponding to the current
1122 * nexthop, the path will be changed. If the new address is
1123 * NOT corresponding to the current nexthop, the path will
1126 SCTP_RTALLOC((sctp_route_t *)&net->ro,
1127 stcb->sctp_ep->def_vrf_id,
1128 stcb->sctp_ep->fibnum);
1129 if (net->ro.ro_nh == NULL)
1133 switch (net->ro._l_addr.sa.sa_family) {
1136 if (sctp_v4src_match_nexthop(newifa, (sctp_route_t *)&net->ro)) {
1143 if (sctp_v6src_match_nexthop(
1144 &newifa->address.sin6, (sctp_route_t *)&net->ro)) {
1153 * if the newly added address does not relate routing
1154 * information, we skip.
1158 /* Retransmit unacknowledged DATA chunks immediately */
1159 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
1160 SCTP_MOBILITY_FASTHANDOFF)) {
1161 sctp_net_immediate_retrans(stcb, net);
1163 /* Send SET PRIMARY for this new address */
1164 if (net == stcb->asoc.primary_destination) {
1165 (void)sctp_asconf_queue_mgmt(stcb, newifa,
1166 SCTP_SET_PRIM_ADDR);
1172 * process an ADD/DELETE IP ack from peer.
1173 * addr: corresponding sctp_ifa to the address being added/deleted.
1174 * type: SCTP_ADD_IP_ADDRESS or SCTP_DEL_IP_ADDRESS.
1175 * flag: 1=success, 0=failure.
1178 sctp_asconf_addr_mgmt_ack(struct sctp_tcb *stcb, struct sctp_ifa *addr, uint32_t flag)
1181 * do the necessary asoc list work- if we get a failure indication,
1182 * leave the address on the assoc's restricted list. If we get a
1183 * success indication, remove the address from the restricted list.
1186 * Note: this will only occur for ADD_IP_ADDRESS, since
1187 * DEL_IP_ADDRESS is never actually added to the list...
1190 /* success case, so remove from the restricted list */
1191 sctp_del_local_addr_restricted(stcb, addr);
1193 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
1194 SCTP_MOBILITY_BASE) ||
1195 sctp_is_mobility_feature_on(stcb->sctp_ep,
1196 SCTP_MOBILITY_FASTHANDOFF)) {
1197 sctp_path_check_and_react(stcb, addr);
1200 /* clear any cached/topologically incorrect source addresses */
1201 sctp_asconf_nets_cleanup(stcb, addr->ifn_p);
1203 /* else, leave it on the list */
1207 * add an asconf add/delete/set primary IP address parameter to the queue.
1208 * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR.
1209 * returns 0 if queued, -1 if not queued/removed.
1210 * NOTE: if adding, but a delete for the same address is already scheduled
1211 * (and not yet sent out), simply remove it from queue. Same for deleting
1212 * an address already scheduled for add. If a duplicate operation is found,
1213 * ignore the new one.
1216 sctp_asconf_queue_mgmt(struct sctp_tcb *stcb, struct sctp_ifa *ifa,
1219 struct sctp_asconf_addr *aa, *aa_next;
1221 /* make sure the request isn't already in the queue */
1222 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) {
1223 /* address match? */
1224 if (sctp_asconf_addr_match(aa, &ifa->address.sa) == 0)
1227 * is the request already in queue but not sent? pass the
1228 * request already sent in order to resolve the following
1229 * case: 1. arrival of ADD, then sent 2. arrival of DEL. we
1230 * can't remove the ADD request already sent 3. arrival of
1233 if (aa->ap.aph.ph.param_type == type && aa->sent == 0) {
1236 /* is the negative request already in queue, and not sent */
1237 if ((aa->sent == 0) && (type == SCTP_ADD_IP_ADDRESS) &&
1238 (aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS)) {
1239 /* add requested, delete already queued */
1240 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1241 /* remove the ifa from the restricted list */
1242 sctp_del_local_addr_restricted(stcb, ifa);
1243 /* free the asconf param */
1244 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1245 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_mgmt: add removes queued entry\n");
1248 if ((aa->sent == 0) && (type == SCTP_DEL_IP_ADDRESS) &&
1249 (aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS)) {
1250 /* delete requested, add already queued */
1251 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1252 /* remove the aa->ifa from the restricted list */
1253 sctp_del_local_addr_restricted(stcb, aa->ifa);
1254 /* free the asconf param */
1255 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1256 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_mgmt: delete removes queued entry\n");
1261 /* adding new request to the queue */
1262 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
1265 /* didn't get memory */
1266 SCTPDBG(SCTP_DEBUG_ASCONF1, "asconf_queue_mgmt: failed to get memory!\n");
1269 aa->special_del = 0;
1270 /* fill in asconf address parameter fields */
1271 /* top level elements are "networked" during send */
1272 aa->ap.aph.ph.param_type = type;
1274 atomic_add_int(&ifa->refcount, 1);
1275 /* correlation_id filled in during send routine later... */
1276 switch (ifa->address.sa.sa_family) {
1280 struct sockaddr_in6 *sin6;
1282 sin6 = &ifa->address.sin6;
1283 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
1284 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param));
1285 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) +
1286 sizeof(struct sctp_ipv6addr_param);
1287 memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr,
1288 sizeof(struct in6_addr));
1295 struct sockaddr_in *sin;
1297 sin = &ifa->address.sin;
1298 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
1299 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param));
1300 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) +
1301 sizeof(struct sctp_ipv4addr_param);
1302 memcpy(&aa->ap.addrp.addr, &sin->sin_addr,
1303 sizeof(struct in_addr));
1308 /* invalid family! */
1309 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1313 aa->sent = 0; /* clear sent flag */
1315 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
1317 if (SCTP_BASE_SYSCTL(sctp_debug_on) & SCTP_DEBUG_ASCONF2) {
1318 if (type == SCTP_ADD_IP_ADDRESS) {
1319 SCTP_PRINTF("asconf_queue_mgmt: inserted asconf ADD_IP_ADDRESS: ");
1320 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa);
1321 } else if (type == SCTP_DEL_IP_ADDRESS) {
1322 SCTP_PRINTF("asconf_queue_mgmt: appended asconf DEL_IP_ADDRESS: ");
1323 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa);
1325 SCTP_PRINTF("asconf_queue_mgmt: appended asconf SET_PRIM_ADDR: ");
1326 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa);
1335 * add an asconf operation for the given ifa and type.
1336 * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR.
1337 * returns 0 if completed, -1 if not completed, 1 if immediate send is
1341 sctp_asconf_queue_add(struct sctp_tcb *stcb, struct sctp_ifa *ifa,
1345 int pending_delete_queued = 0;
1348 /* see if peer supports ASCONF */
1349 if (stcb->asoc.asconf_supported == 0) {
1354 * if this is deleting the last address from the assoc, mark it as
1357 if ((type == SCTP_DEL_IP_ADDRESS) && !stcb->asoc.asconf_del_pending) {
1358 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1359 last = (sctp_local_addr_count(stcb) == 0);
1361 last = (sctp_local_addr_count(stcb) == 1);
1364 /* set the pending delete info only */
1365 stcb->asoc.asconf_del_pending = 1;
1366 stcb->asoc.asconf_addr_del_pending = ifa;
1367 atomic_add_int(&ifa->refcount, 1);
1368 SCTPDBG(SCTP_DEBUG_ASCONF2,
1369 "asconf_queue_add: mark delete last address pending\n");
1374 /* queue an asconf parameter */
1375 status = sctp_asconf_queue_mgmt(stcb, ifa, type);
1378 * if this is an add, and there is a delete also pending (i.e. the
1379 * last local address is being changed), queue the pending delete
1382 if ((type == SCTP_ADD_IP_ADDRESS) && stcb->asoc.asconf_del_pending && (status == 0)) {
1383 /* queue in the pending delete */
1384 if (sctp_asconf_queue_mgmt(stcb,
1385 stcb->asoc.asconf_addr_del_pending,
1386 SCTP_DEL_IP_ADDRESS) == 0) {
1387 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_add: queuing pending delete\n");
1388 pending_delete_queued = 1;
1389 /* clear out the pending delete info */
1390 stcb->asoc.asconf_del_pending = 0;
1391 sctp_free_ifa(stcb->asoc.asconf_addr_del_pending);
1392 stcb->asoc.asconf_addr_del_pending = NULL;
1396 if (pending_delete_queued) {
1397 struct sctp_nets *net;
1400 * since we know that the only/last address is now being
1401 * changed in this case, reset the cwnd/rto on all nets to
1402 * start as a new address and path. Also clear the error
1403 * counts to give the assoc the best chance to complete the
1406 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1407 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb,
1410 net->error_count = 0;
1412 stcb->asoc.overall_error_count = 0;
1413 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) {
1414 sctp_misc_ints(SCTP_THRESHOLD_CLEAR,
1415 stcb->asoc.overall_error_count,
1417 SCTP_FROM_SCTP_ASCONF,
1421 /* queue in an advisory set primary too */
1422 (void)sctp_asconf_queue_mgmt(stcb, ifa, SCTP_SET_PRIM_ADDR);
1423 /* let caller know we should send this out immediately */
1430 * add an asconf delete IP address parameter to the queue by sockaddr and
1431 * possibly with no sctp_ifa available. This is only called by the routine
1432 * that checks the addresses in an INIT-ACK against the current address list.
1433 * returns 0 if completed, non-zero if not completed.
1434 * NOTE: if an add is already scheduled (and not yet sent out), simply
1435 * remove it from queue. If a duplicate operation is found, ignore the
1439 sctp_asconf_queue_sa_delete(struct sctp_tcb *stcb, struct sockaddr *sa)
1441 struct sctp_ifa *ifa;
1442 struct sctp_asconf_addr *aa, *aa_next;
1447 /* see if peer supports ASCONF */
1448 if (stcb->asoc.asconf_supported == 0) {
1451 /* make sure the request isn't already in the queue */
1452 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) {
1453 /* address match? */
1454 if (sctp_asconf_addr_match(aa, sa) == 0)
1456 /* is the request already in queue (sent or not) */
1457 if (aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) {
1460 /* is the negative request already in queue, and not sent */
1463 if (aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS) {
1464 /* add already queued, so remove existing entry */
1465 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1466 sctp_del_local_addr_restricted(stcb, aa->ifa);
1467 /* free the entry */
1468 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1473 /* find any existing ifa-- NOTE ifa CAN be allowed to be NULL */
1474 ifa = sctp_find_ifa_by_addr(sa, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
1476 /* adding new request to the queue */
1477 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
1480 /* didn't get memory */
1481 SCTPDBG(SCTP_DEBUG_ASCONF1,
1482 "sctp_asconf_queue_sa_delete: failed to get memory!\n");
1485 aa->special_del = 0;
1486 /* fill in asconf address parameter fields */
1487 /* top level elements are "networked" during send */
1488 aa->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS;
1491 atomic_add_int(&ifa->refcount, 1);
1492 /* correlation_id filled in during send routine later... */
1493 switch (sa->sa_family) {
1498 struct sockaddr_in6 *sin6;
1500 sin6 = (struct sockaddr_in6 *)sa;
1501 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
1502 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param));
1503 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv6addr_param);
1504 memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr,
1505 sizeof(struct in6_addr));
1513 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
1515 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
1516 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param));
1517 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv4addr_param);
1518 memcpy(&aa->ap.addrp.addr, &sin->sin_addr,
1519 sizeof(struct in_addr));
1524 /* invalid family! */
1525 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1530 aa->sent = 0; /* clear sent flag */
1532 /* delete goes to the back of the queue */
1533 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
1535 /* sa_ignore MEMLEAK {memory is put on the tailq} */
1540 * find a specific asconf param on our "sent" queue
1542 static struct sctp_asconf_addr *
1543 sctp_asconf_find_param(struct sctp_tcb *stcb, uint32_t correlation_id)
1545 struct sctp_asconf_addr *aa;
1547 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
1548 if (aa->ap.aph.correlation_id == correlation_id &&
1554 /* didn't find it */
1559 * process an SCTP_ERROR_CAUSE_IND for a ASCONF-ACK parameter and do
1560 * notifications based on the error response
1563 sctp_asconf_process_error(struct sctp_tcb *stcb SCTP_UNUSED,
1564 struct sctp_asconf_paramhdr *aph)
1566 struct sctp_error_cause *eh;
1567 struct sctp_paramhdr *ph;
1568 uint16_t param_type;
1569 uint16_t error_code;
1571 eh = (struct sctp_error_cause *)(aph + 1);
1572 ph = (struct sctp_paramhdr *)(eh + 1);
1573 /* validate lengths */
1574 if (htons(eh->length) + sizeof(struct sctp_error_cause) >
1575 htons(aph->ph.param_length)) {
1576 /* invalid error cause length */
1577 SCTPDBG(SCTP_DEBUG_ASCONF1,
1578 "asconf_process_error: cause element too long\n");
1581 if (htons(ph->param_length) + sizeof(struct sctp_paramhdr) >
1582 htons(eh->length)) {
1583 /* invalid included TLV length */
1584 SCTPDBG(SCTP_DEBUG_ASCONF1,
1585 "asconf_process_error: included TLV too long\n");
1588 /* which error code ? */
1589 error_code = ntohs(eh->code);
1590 param_type = ntohs(aph->ph.param_type);
1591 /* FIX: this should go back up the REMOTE_ERROR ULP notify */
1592 switch (error_code) {
1593 case SCTP_CAUSE_RESOURCE_SHORTAGE:
1594 /* we allow ourselves to "try again" for this error */
1597 /* peer can't handle it... */
1598 switch (param_type) {
1599 case SCTP_ADD_IP_ADDRESS:
1600 case SCTP_DEL_IP_ADDRESS:
1601 case SCTP_SET_PRIM_ADDR:
1610 * process an asconf queue param.
1611 * aparam: parameter to process, will be removed from the queue.
1612 * flag: 1=success case, 0=failure case
1615 sctp_asconf_process_param_ack(struct sctp_tcb *stcb,
1616 struct sctp_asconf_addr *aparam, uint32_t flag)
1618 uint16_t param_type;
1620 /* process this param */
1621 param_type = aparam->ap.aph.ph.param_type;
1622 switch (param_type) {
1623 case SCTP_ADD_IP_ADDRESS:
1624 SCTPDBG(SCTP_DEBUG_ASCONF1,
1625 "process_param_ack: added IP address\n");
1626 sctp_asconf_addr_mgmt_ack(stcb, aparam->ifa, flag);
1628 case SCTP_DEL_IP_ADDRESS:
1629 SCTPDBG(SCTP_DEBUG_ASCONF1,
1630 "process_param_ack: deleted IP address\n");
1631 /* nothing really to do... lists already updated */
1633 case SCTP_SET_PRIM_ADDR:
1634 SCTPDBG(SCTP_DEBUG_ASCONF1,
1635 "process_param_ack: set primary IP address\n");
1636 /* nothing to do... peer may start using this addr */
1639 /* should NEVER happen */
1643 /* remove the param and free it */
1644 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aparam, next);
1646 sctp_free_ifa(aparam->ifa);
1647 SCTP_FREE(aparam, SCTP_M_ASC_ADDR);
1651 * cleanup from a bad asconf ack parameter
1654 sctp_asconf_ack_clear(struct sctp_tcb *stcb SCTP_UNUSED)
1656 /* assume peer doesn't really know how to do asconfs */
1657 /* XXX we could free the pending queue here */
1662 sctp_handle_asconf_ack(struct mbuf *m, int offset,
1663 struct sctp_asconf_ack_chunk *cp, struct sctp_tcb *stcb,
1664 struct sctp_nets *net, int *abort_no_unlock)
1666 struct sctp_association *asoc;
1667 uint32_t serial_num;
1668 uint16_t ack_length;
1669 struct sctp_asconf_paramhdr *aph;
1670 struct sctp_asconf_addr *aa, *aa_next;
1671 uint32_t last_error_id = 0; /* last error correlation id */
1673 struct sctp_asconf_addr *ap;
1675 /* asconf param buffer */
1676 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE];
1678 /* verify minimum length */
1679 if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_ack_chunk)) {
1680 SCTPDBG(SCTP_DEBUG_ASCONF1,
1681 "handle_asconf_ack: chunk too small = %xh\n",
1682 ntohs(cp->ch.chunk_length));
1686 serial_num = ntohl(cp->serial_number);
1689 * NOTE: we may want to handle this differently- currently, we will
1690 * abort when we get an ack for the expected serial number + 1 (eg.
1691 * we didn't send it), process an ack normally if it is the expected
1692 * serial number, and re-send the previous ack for *ALL* other
1697 * if the serial number is the next expected, but I didn't send it,
1698 * abort the asoc, since someone probably just hijacked us...
1700 if (serial_num == (asoc->asconf_seq_out + 1)) {
1701 struct mbuf *op_err;
1702 char msg[SCTP_DIAG_INFO_LEN];
1704 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got unexpected next serial number! Aborting asoc!\n");
1705 SCTP_SNPRINTF(msg, sizeof(msg), "Never sent serial number %8.8x", serial_num);
1706 op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
1707 sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
1708 *abort_no_unlock = 1;
1711 if (serial_num != asoc->asconf_seq_out_acked + 1) {
1712 /* got a duplicate/unexpected ASCONF-ACK */
1713 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got duplicate/unexpected serial number = %xh (expected = %xh)\n",
1714 serial_num, asoc->asconf_seq_out_acked + 1);
1718 if (serial_num == asoc->asconf_seq_out - 1) {
1719 /* stop our timer */
1720 sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, NULL,
1721 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_5);
1724 /* process the ASCONF-ACK contents */
1725 ack_length = ntohs(cp->ch.chunk_length) -
1726 sizeof(struct sctp_asconf_ack_chunk);
1727 offset += sizeof(struct sctp_asconf_ack_chunk);
1728 /* process through all parameters */
1729 while (ack_length >= sizeof(struct sctp_asconf_paramhdr)) {
1730 unsigned int param_length, param_type;
1732 /* get pointer to next asconf parameter */
1733 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset,
1734 sizeof(struct sctp_asconf_paramhdr), aparam_buf);
1736 /* can't get an asconf paramhdr */
1737 sctp_asconf_ack_clear(stcb);
1740 param_type = ntohs(aph->ph.param_type);
1741 param_length = ntohs(aph->ph.param_length);
1742 if (param_length > ack_length) {
1743 sctp_asconf_ack_clear(stcb);
1746 if (param_length < sizeof(struct sctp_paramhdr)) {
1747 sctp_asconf_ack_clear(stcb);
1750 /* get the complete parameter... */
1751 if (param_length > sizeof(aparam_buf)) {
1752 SCTPDBG(SCTP_DEBUG_ASCONF1,
1753 "param length (%u) larger than buffer size!\n", param_length);
1754 sctp_asconf_ack_clear(stcb);
1757 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf);
1759 sctp_asconf_ack_clear(stcb);
1762 /* correlation_id is transparent to peer, no ntohl needed */
1763 id = aph->correlation_id;
1765 switch (param_type) {
1766 case SCTP_ERROR_CAUSE_IND:
1768 /* find the corresponding asconf param in our queue */
1769 ap = sctp_asconf_find_param(stcb, id);
1771 /* hmm... can't find this in our queue! */
1774 /* process the parameter, failed flag */
1775 sctp_asconf_process_param_ack(stcb, ap, 0);
1776 /* process the error response */
1777 sctp_asconf_process_error(stcb, aph);
1779 case SCTP_SUCCESS_REPORT:
1780 /* find the corresponding asconf param in our queue */
1781 ap = sctp_asconf_find_param(stcb, id);
1783 /* hmm... can't find this in our queue! */
1786 /* process the parameter, success flag */
1787 sctp_asconf_process_param_ack(stcb, ap, 1);
1793 /* update remaining ASCONF-ACK message length to process */
1794 if (ack_length > SCTP_SIZE32(param_length)) {
1795 ack_length -= SCTP_SIZE32(param_length);
1799 offset += SCTP_SIZE32(param_length);
1803 * if there are any "sent" params still on the queue, these are
1804 * implicitly "success", or "failed" (if we got an error back) ...
1805 * so process these appropriately
1807 * we assume that the correlation_id's are monotonically increasing
1808 * beginning from 1 and that we don't have *that* many outstanding
1811 if (last_error_id == 0)
1812 last_error_id--; /* set to "max" value */
1813 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) {
1814 if (aa->sent == 1) {
1816 * implicitly successful or failed if correlation_id
1817 * < last_error_id, then success else, failure
1819 if (aa->ap.aph.correlation_id < last_error_id)
1820 sctp_asconf_process_param_ack(stcb, aa, 1);
1822 sctp_asconf_process_param_ack(stcb, aa, 0);
1825 * since we always process in order (FIFO queue) if
1826 * we reach one that hasn't been sent, the rest
1827 * should not have been sent either. so, we're
1834 /* update the next sequence number to use */
1835 asoc->asconf_seq_out_acked++;
1836 /* remove the old ASCONF on our outbound queue */
1837 sctp_toss_old_asconf(stcb);
1838 if (!TAILQ_EMPTY(&stcb->asoc.asconf_queue)) {
1839 #ifdef SCTP_TIMER_BASED_ASCONF
1840 /* we have more params, so restart our timer */
1841 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep,
1844 /* we have more params, so send out more */
1845 sctp_send_asconf(stcb, net, SCTP_ADDR_NOT_LOCKED);
1852 sctp_is_scopeid_in_nets(struct sctp_tcb *stcb, struct sockaddr *sa)
1854 struct sockaddr_in6 *sin6, *net6;
1855 struct sctp_nets *net;
1857 if (sa->sa_family != AF_INET6) {
1861 sin6 = (struct sockaddr_in6 *)sa;
1862 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) == 0) {
1863 /* not link local address */
1866 /* hunt through our destination nets list for this scope_id */
1867 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1868 if (((struct sockaddr *)(&net->ro._l_addr))->sa_family !=
1871 net6 = (struct sockaddr_in6 *)&net->ro._l_addr;
1872 if (IN6_IS_ADDR_LINKLOCAL(&net6->sin6_addr) == 0)
1874 if (sctp_is_same_scope(sin6, net6)) {
1879 /* didn't find one */
1885 * address management functions
1888 sctp_addr_mgmt_assoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
1889 struct sctp_ifa *ifa, uint16_t type, int addr_locked)
1893 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0 ||
1894 sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_ASCONF)) {
1895 /* subset bound, no ASCONF allowed case, so ignore */
1899 * note: we know this is not the subset bound, no ASCONF case eg.
1900 * this is boundall or subset bound w/ASCONF allowed
1903 /* first, make sure that the address is IPv4 or IPv6 and not jailed */
1904 switch (ifa->address.sa.sa_family) {
1907 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1908 &ifa->address.sin6.sin6_addr) != 0) {
1915 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1916 &ifa->address.sin.sin_addr) != 0) {
1925 /* make sure we're "allowed" to add this type of addr */
1926 if (ifa->address.sa.sa_family == AF_INET6) {
1927 /* invalid if we're not a v6 endpoint */
1928 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0)
1930 /* is the v6 addr really valid ? */
1931 if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) {
1936 /* put this address on the "pending/do not use yet" list */
1937 sctp_add_local_addr_restricted(stcb, ifa);
1939 * check address scope if address is out of scope, don't queue
1940 * anything... note: this would leave the address on both inp and
1943 switch (ifa->address.sa.sa_family) {
1947 struct sockaddr_in6 *sin6;
1949 sin6 = &ifa->address.sin6;
1950 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1951 /* we skip unspecifed addresses */
1954 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1955 if (stcb->asoc.scope.local_scope == 0) {
1958 /* is it the right link local scope? */
1959 if (sctp_is_scopeid_in_nets(stcb, &ifa->address.sa) == 0) {
1963 if (stcb->asoc.scope.site_scope == 0 &&
1964 IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)) {
1973 struct sockaddr_in *sin;
1975 /* invalid if we are a v6 only endpoint */
1976 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1977 SCTP_IPV6_V6ONLY(inp))
1980 sin = &ifa->address.sin;
1981 if (sin->sin_addr.s_addr == 0) {
1982 /* we skip unspecifed addresses */
1985 if (stcb->asoc.scope.ipv4_local_scope == 0 &&
1986 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) {
1993 /* else, not AF_INET or AF_INET6, so skip */
1997 /* queue an asconf for this address add/delete */
1998 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF)) {
1999 /* does the peer do asconf? */
2000 if (stcb->asoc.asconf_supported) {
2001 /* queue an asconf for this addr */
2002 status = sctp_asconf_queue_add(stcb, ifa, type);
2005 * if queued ok, and in the open state, send out the
2006 * ASCONF. If in the non-open state, these will be
2007 * sent when the state goes open.
2010 ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
2011 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED))) {
2012 #ifdef SCTP_TIMER_BASED_ASCONF
2013 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, inp,
2014 stcb, stcb->asoc.primary_destination);
2016 sctp_send_asconf(stcb, NULL, addr_locked);
2024 sctp_asconf_iterator_ep(struct sctp_inpcb *inp, void *ptr, uint32_t val SCTP_UNUSED)
2026 struct sctp_asconf_iterator *asc;
2027 struct sctp_ifa *ifa;
2028 struct sctp_laddr *l;
2029 int cnt_invalid = 0;
2031 asc = (struct sctp_asconf_iterator *)ptr;
2032 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) {
2034 switch (ifa->address.sa.sa_family) {
2037 /* invalid if we're not a v6 endpoint */
2038 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
2040 if (asc->cnt == cnt_invalid)
2048 /* invalid if we are a v6 only endpoint */
2049 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2050 SCTP_IPV6_V6ONLY(inp)) {
2052 if (asc->cnt == cnt_invalid)
2059 /* invalid address family */
2061 if (asc->cnt == cnt_invalid)
2069 sctp_asconf_iterator_ep_end(struct sctp_inpcb *inp, void *ptr, uint32_t val SCTP_UNUSED)
2071 struct sctp_ifa *ifa;
2072 struct sctp_asconf_iterator *asc;
2073 struct sctp_laddr *laddr, *nladdr, *l;
2075 /* Only for specific case not bound all */
2076 asc = (struct sctp_asconf_iterator *)ptr;
2077 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) {
2079 if (l->action == SCTP_ADD_IP_ADDRESS) {
2080 LIST_FOREACH(laddr, &inp->sctp_addr_list,
2082 if (laddr->ifa == ifa) {
2087 } else if (l->action == SCTP_DEL_IP_ADDRESS) {
2088 LIST_FOREACH_SAFE(laddr, &inp->sctp_addr_list, sctp_nxt_addr, nladdr) {
2089 /* remove only after all guys are done */
2090 if (laddr->ifa == ifa) {
2091 sctp_del_local_addr_ep(inp, ifa);
2100 sctp_asconf_iterator_stcb(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
2101 void *ptr, uint32_t val SCTP_UNUSED)
2103 struct sctp_asconf_iterator *asc;
2104 struct sctp_ifa *ifa;
2105 struct sctp_laddr *l;
2106 int cnt_invalid = 0;
2110 asc = (struct sctp_asconf_iterator *)ptr;
2111 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) {
2115 /* address's vrf_id must be the vrf_id of the assoc */
2116 if (ifa->vrf_id != stcb->asoc.vrf_id) {
2120 /* Same checks again for assoc */
2121 switch (ifa->address.sa.sa_family) {
2125 /* invalid if we're not a v6 endpoint */
2126 struct sockaddr_in6 *sin6;
2128 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
2130 if (asc->cnt == cnt_invalid)
2135 sin6 = &ifa->address.sin6;
2136 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2137 /* we skip unspecifed addresses */
2140 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
2141 &sin6->sin6_addr) != 0) {
2144 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
2145 if (stcb->asoc.scope.local_scope == 0) {
2148 /* is it the right link local scope? */
2149 if (sctp_is_scopeid_in_nets(stcb, &ifa->address.sa) == 0) {
2159 /* invalid if we are a v6 only endpoint */
2160 struct sockaddr_in *sin;
2162 /* invalid if we are a v6 only endpoint */
2163 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2164 SCTP_IPV6_V6ONLY(inp))
2167 sin = &ifa->address.sin;
2168 if (sin->sin_addr.s_addr == 0) {
2169 /* we skip unspecifed addresses */
2172 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
2173 &sin->sin_addr) != 0) {
2176 if (stcb->asoc.scope.ipv4_local_scope == 0 &&
2177 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) {
2180 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2181 SCTP_IPV6_V6ONLY(inp)) {
2183 if (asc->cnt == cnt_invalid)
2192 /* invalid address family */
2194 if (asc->cnt == cnt_invalid)
2201 if (type == SCTP_ADD_IP_ADDRESS) {
2202 /* prevent this address from being used as a source */
2203 sctp_add_local_addr_restricted(stcb, ifa);
2204 } else if (type == SCTP_DEL_IP_ADDRESS) {
2205 struct sctp_nets *net;
2207 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2208 /* delete this address if cached */
2209 if (net->ro._s_addr == ifa) {
2210 sctp_free_ifa(net->ro._s_addr);
2211 net->ro._s_addr = NULL;
2212 net->src_addr_selected = 0;
2213 RO_NHFREE(&net->ro);
2215 * Now we deleted our src address,
2216 * should we not also now reset the
2217 * cwnd/rto to start as if its a new
2220 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
2224 } else if (type == SCTP_SET_PRIM_ADDR) {
2225 if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
2226 /* must validate the ifa is in the ep */
2227 if (sctp_is_addr_in_ep(stcb->sctp_ep, ifa) == 0) {
2231 /* Need to check scopes for this guy */
2232 if (sctp_is_address_in_scope(ifa, &stcb->asoc.scope, 0) == 0) {
2237 /* queue an asconf for this address add/delete */
2238 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF) &&
2239 stcb->asoc.asconf_supported == 1) {
2240 /* queue an asconf for this addr */
2241 status = sctp_asconf_queue_add(stcb, ifa, type);
2243 * if queued ok, and in the open state, update the
2244 * count of queued params. If in the non-open
2245 * state, these get sent when the assoc goes open.
2247 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
2248 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
2256 * If we have queued params in the open state, send out an ASCONF.
2258 if (num_queued > 0) {
2259 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2264 sctp_asconf_iterator_end(void *ptr, uint32_t val SCTP_UNUSED)
2266 struct sctp_asconf_iterator *asc;
2267 struct sctp_ifa *ifa;
2268 struct sctp_laddr *l, *nl;
2270 asc = (struct sctp_asconf_iterator *)ptr;
2271 LIST_FOREACH_SAFE(l, &asc->list_of_work, sctp_nxt_addr, nl) {
2273 if (l->action == SCTP_ADD_IP_ADDRESS) {
2274 /* Clear the defer use flag */
2275 ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE;
2278 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_laddr), l);
2279 SCTP_DECR_LADDR_COUNT();
2281 SCTP_FREE(asc, SCTP_M_ASC_IT);
2285 * sa is the sockaddr to ask the peer to set primary to.
2286 * returns: 0 = completed, -1 = error
2289 sctp_set_primary_ip_address_sa(struct sctp_tcb *stcb, struct sockaddr *sa)
2292 struct sctp_ifa *ifa;
2294 /* find the ifa for the desired set primary */
2295 vrf_id = stcb->asoc.vrf_id;
2296 ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED);
2298 /* Invalid address */
2302 /* queue an ASCONF:SET_PRIM_ADDR to be sent */
2303 if (!sctp_asconf_queue_add(stcb, ifa, SCTP_SET_PRIM_ADDR)) {
2304 /* set primary queuing succeeded */
2305 SCTPDBG(SCTP_DEBUG_ASCONF1,
2306 "set_primary_ip_address_sa: queued on tcb=%p, ",
2308 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
2309 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
2310 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
2311 #ifdef SCTP_TIMER_BASED_ASCONF
2312 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
2313 stcb->sctp_ep, stcb,
2314 stcb->asoc.primary_destination);
2316 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2320 SCTPDBG(SCTP_DEBUG_ASCONF1, "set_primary_ip_address_sa: failed to add to queue on tcb=%p, ",
2322 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
2329 sctp_is_addr_pending(struct sctp_tcb *stcb, struct sctp_ifa *sctp_ifa)
2331 struct sctp_tmit_chunk *chk, *nchk;
2332 unsigned int offset, asconf_limit;
2333 struct sctp_asconf_chunk *acp;
2334 struct sctp_asconf_paramhdr *aph;
2335 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE];
2336 struct sctp_paramhdr *ph;
2337 int add_cnt, del_cnt;
2338 uint16_t last_param_type;
2340 add_cnt = del_cnt = 0;
2341 last_param_type = 0;
2342 TAILQ_FOREACH_SAFE(chk, &stcb->asoc.asconf_send_queue, sctp_next, nchk) {
2343 if (chk->data == NULL) {
2344 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: No mbuf data?\n");
2348 acp = mtod(chk->data, struct sctp_asconf_chunk *);
2349 offset += sizeof(struct sctp_asconf_chunk);
2350 asconf_limit = ntohs(acp->ch.chunk_length);
2351 ph = (struct sctp_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_paramhdr), aparam_buf);
2353 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: couldn't get lookup addr!\n");
2356 offset += ntohs(ph->param_length);
2358 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_asconf_paramhdr), aparam_buf);
2360 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: Empty ASCONF will be sent?\n");
2363 while (aph != NULL) {
2364 unsigned int param_length, param_type;
2366 param_type = ntohs(aph->ph.param_type);
2367 param_length = ntohs(aph->ph.param_length);
2368 if (offset + param_length > asconf_limit) {
2369 /* parameter goes beyond end of chunk! */
2372 if (param_length > sizeof(aparam_buf)) {
2373 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: param length (%u) larger than buffer size!\n", param_length);
2376 if (param_length <= sizeof(struct sctp_paramhdr)) {
2377 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: param length(%u) too short\n", param_length);
2381 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, param_length, aparam_buf);
2383 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: couldn't get entire param\n");
2387 ph = (struct sctp_paramhdr *)(aph + 1);
2388 if (sctp_addr_match(ph, &sctp_ifa->address.sa) != 0) {
2389 switch (param_type) {
2390 case SCTP_ADD_IP_ADDRESS:
2393 case SCTP_DEL_IP_ADDRESS:
2399 last_param_type = param_type;
2402 offset += SCTP_SIZE32(param_length);
2403 if (offset >= asconf_limit) {
2404 /* no more data in the mbuf chain */
2407 /* get pointer to next asconf param */
2408 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_asconf_paramhdr), aparam_buf);
2413 * we want to find the sequences which consist of ADD -> DEL -> ADD
2416 if (add_cnt > del_cnt ||
2417 (add_cnt == del_cnt && last_param_type == SCTP_ADD_IP_ADDRESS)) {
2423 static struct sockaddr *
2424 sctp_find_valid_localaddr(struct sctp_tcb *stcb, int addr_locked)
2426 struct sctp_vrf *vrf = NULL;
2427 struct sctp_ifn *sctp_ifn;
2428 struct sctp_ifa *sctp_ifa;
2430 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2431 SCTP_IPI_ADDR_RLOCK();
2432 vrf = sctp_find_vrf(stcb->asoc.vrf_id);
2434 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2435 SCTP_IPI_ADDR_RUNLOCK();
2438 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
2439 if (stcb->asoc.scope.loopback_scope == 0 &&
2440 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
2441 /* Skip if loopback_scope not set */
2444 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
2445 switch (sctp_ifa->address.sa.sa_family) {
2448 if (stcb->asoc.scope.ipv4_addr_legal) {
2449 struct sockaddr_in *sin;
2451 sin = &sctp_ifa->address.sin;
2452 if (sin->sin_addr.s_addr == 0) {
2453 /* skip unspecifed addresses */
2456 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
2457 &sin->sin_addr) != 0) {
2460 if (stcb->asoc.scope.ipv4_local_scope == 0 &&
2461 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))
2464 if (sctp_is_addr_restricted(stcb, sctp_ifa) &&
2465 (!sctp_is_addr_pending(stcb, sctp_ifa)))
2468 * found a valid local v4 address to
2471 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2472 SCTP_IPI_ADDR_RUNLOCK();
2473 return (&sctp_ifa->address.sa);
2479 if (stcb->asoc.scope.ipv6_addr_legal) {
2480 struct sockaddr_in6 *sin6;
2482 if (sctp_ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) {
2486 sin6 = &sctp_ifa->address.sin6;
2487 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2489 * we skip unspecifed
2494 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
2495 &sin6->sin6_addr) != 0) {
2498 if (stcb->asoc.scope.local_scope == 0 &&
2499 IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))
2501 if (stcb->asoc.scope.site_scope == 0 &&
2502 IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))
2505 if (sctp_is_addr_restricted(stcb, sctp_ifa) &&
2506 (!sctp_is_addr_pending(stcb, sctp_ifa)))
2509 * found a valid local v6 address to
2512 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2513 SCTP_IPI_ADDR_RUNLOCK();
2514 return (&sctp_ifa->address.sa);
2523 /* no valid addresses found */
2524 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2525 SCTP_IPI_ADDR_RUNLOCK();
2529 static struct sockaddr *
2530 sctp_find_valid_localaddr_ep(struct sctp_tcb *stcb)
2532 struct sctp_laddr *laddr;
2534 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
2535 if (laddr->ifa == NULL) {
2538 /* is the address restricted ? */
2539 if (sctp_is_addr_restricted(stcb, laddr->ifa) &&
2540 (!sctp_is_addr_pending(stcb, laddr->ifa)))
2543 /* found a valid local address to use */
2544 return (&laddr->ifa->address.sa);
2546 /* no valid addresses found */
2551 * builds an ASCONF chunk from queued ASCONF params.
2552 * returns NULL on error (no mbuf, no ASCONF params queued, etc).
2555 sctp_compose_asconf(struct sctp_tcb *stcb, int *retlen, int addr_locked)
2557 struct mbuf *m_asconf, *m_asconf_chk;
2558 struct sctp_asconf_addr *aa;
2559 struct sctp_asconf_chunk *acp;
2560 struct sctp_asconf_paramhdr *aph;
2561 struct sctp_asconf_addr_param *aap;
2563 uint32_t correlation_id = 1; /* 0 is reserved... */
2564 caddr_t ptr, lookup_ptr;
2565 uint8_t lookup_used = 0;
2567 /* are there any asconf params to send? */
2568 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
2576 * get a chunk header mbuf and a cluster for the asconf params since
2577 * it's simpler to fill in the asconf chunk header lookup address on
2580 m_asconf_chk = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_chunk), 0, M_NOWAIT, 1, MT_DATA);
2581 if (m_asconf_chk == NULL) {
2583 SCTPDBG(SCTP_DEBUG_ASCONF1,
2584 "sctp_compose_asconf: couldn't get chunk mbuf!\n");
2587 m_asconf = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA);
2588 if (m_asconf == NULL) {
2590 SCTPDBG(SCTP_DEBUG_ASCONF1,
2591 "sctp_compose_asconf: couldn't get mbuf!\n");
2592 sctp_m_freem(m_asconf_chk);
2595 SCTP_BUF_LEN(m_asconf_chk) = sizeof(struct sctp_asconf_chunk);
2596 SCTP_BUF_LEN(m_asconf) = 0;
2597 acp = mtod(m_asconf_chk, struct sctp_asconf_chunk *);
2598 memset(acp, 0, sizeof(struct sctp_asconf_chunk));
2599 /* save pointers to lookup address and asconf params */
2600 lookup_ptr = (caddr_t)(acp + 1); /* after the header */
2601 ptr = mtod(m_asconf, caddr_t); /* beginning of cluster */
2603 /* fill in chunk header info */
2604 acp->ch.chunk_type = SCTP_ASCONF;
2605 acp->ch.chunk_flags = 0;
2606 acp->serial_number = htonl(stcb->asoc.asconf_seq_out);
2607 stcb->asoc.asconf_seq_out++;
2609 /* add parameters... up to smallest MTU allowed */
2610 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
2613 /* get the parameter length */
2614 p_length = SCTP_SIZE32(aa->ap.aph.ph.param_length);
2615 /* will it fit in current chunk? */
2616 if ((SCTP_BUF_LEN(m_asconf) + p_length > stcb->asoc.smallest_mtu) ||
2617 (SCTP_BUF_LEN(m_asconf) + p_length > MCLBYTES)) {
2618 /* won't fit, so we're done with this chunk */
2621 /* assign (and store) a correlation id */
2622 aa->ap.aph.correlation_id = correlation_id++;
2625 * fill in address if we're doing a delete this is a simple
2626 * way for us to fill in the correlation address, which
2627 * should only be used by the peer if we're deleting our
2628 * source address and adding a new address (e.g. renumbering
2631 if (lookup_used == 0 &&
2632 (aa->special_del == 0) &&
2633 aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) {
2634 struct sctp_ipv6addr_param *lookup;
2635 uint16_t p_size, addr_size;
2637 lookup = (struct sctp_ipv6addr_param *)lookup_ptr;
2638 lookup->ph.param_type =
2639 htons(aa->ap.addrp.ph.param_type);
2640 if (aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) {
2641 /* copy IPv6 address */
2642 p_size = sizeof(struct sctp_ipv6addr_param);
2643 addr_size = sizeof(struct in6_addr);
2645 /* copy IPv4 address */
2646 p_size = sizeof(struct sctp_ipv4addr_param);
2647 addr_size = sizeof(struct in_addr);
2649 lookup->ph.param_length = htons(SCTP_SIZE32(p_size));
2650 memcpy(lookup->addr, &aa->ap.addrp.addr, addr_size);
2651 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size);
2654 /* copy into current space */
2655 memcpy(ptr, &aa->ap, p_length);
2657 /* network elements and update lengths */
2658 aph = (struct sctp_asconf_paramhdr *)ptr;
2659 aap = (struct sctp_asconf_addr_param *)ptr;
2660 /* correlation_id is transparent to peer, no htonl needed */
2661 aph->ph.param_type = htons(aph->ph.param_type);
2662 aph->ph.param_length = htons(aph->ph.param_length);
2663 aap->addrp.ph.param_type = htons(aap->addrp.ph.param_type);
2664 aap->addrp.ph.param_length = htons(aap->addrp.ph.param_length);
2666 SCTP_BUF_LEN(m_asconf) += SCTP_SIZE32(p_length);
2667 ptr += SCTP_SIZE32(p_length);
2670 * these params are removed off the pending list upon
2671 * getting an ASCONF-ACK back from the peer, just set flag
2675 /* check to see if the lookup addr has been populated yet */
2676 if (lookup_used == 0) {
2677 /* NOTE: if the address param is optional, can skip this... */
2678 /* add any valid (existing) address... */
2679 struct sctp_ipv6addr_param *lookup;
2680 uint16_t p_size, addr_size;
2681 struct sockaddr *found_addr;
2684 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL)
2685 found_addr = sctp_find_valid_localaddr(stcb,
2688 found_addr = sctp_find_valid_localaddr_ep(stcb);
2690 lookup = (struct sctp_ipv6addr_param *)lookup_ptr;
2691 if (found_addr != NULL) {
2692 switch (found_addr->sa_family) {
2695 /* copy IPv6 address */
2696 lookup->ph.param_type =
2697 htons(SCTP_IPV6_ADDRESS);
2698 p_size = sizeof(struct sctp_ipv6addr_param);
2699 addr_size = sizeof(struct in6_addr);
2700 addr_ptr = (caddr_t)&((struct sockaddr_in6 *)
2701 found_addr)->sin6_addr;
2706 /* copy IPv4 address */
2707 lookup->ph.param_type =
2708 htons(SCTP_IPV4_ADDRESS);
2709 p_size = sizeof(struct sctp_ipv4addr_param);
2710 addr_size = sizeof(struct in_addr);
2711 addr_ptr = (caddr_t)&((struct sockaddr_in *)
2712 found_addr)->sin_addr;
2716 SCTPDBG(SCTP_DEBUG_ASCONF1,
2717 "sctp_compose_asconf: no usable lookup addr (family = %d)!\n",
2718 found_addr->sa_family);
2719 sctp_m_freem(m_asconf_chk);
2720 sctp_m_freem(m_asconf);
2723 lookup->ph.param_length = htons(SCTP_SIZE32(p_size));
2724 memcpy(lookup->addr, addr_ptr, addr_size);
2725 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size);
2727 /* uh oh... don't have any address?? */
2728 SCTPDBG(SCTP_DEBUG_ASCONF1,
2729 "sctp_compose_asconf: no lookup addr!\n");
2730 sctp_m_freem(m_asconf_chk);
2731 sctp_m_freem(m_asconf);
2735 /* chain it all together */
2736 SCTP_BUF_NEXT(m_asconf_chk) = m_asconf;
2737 *retlen = SCTP_BUF_LEN(m_asconf_chk) + SCTP_BUF_LEN(m_asconf);
2738 acp->ch.chunk_length = htons(*retlen);
2740 return (m_asconf_chk);
2744 * section to handle address changes before an association is up eg. changes
2745 * during INIT/INIT-ACK/COOKIE-ECHO handshake
2749 * processes the (local) addresses in the INIT-ACK chunk
2752 sctp_process_initack_addresses(struct sctp_tcb *stcb, struct mbuf *m,
2753 unsigned int offset, unsigned int length)
2755 struct sctp_paramhdr tmp_param, *ph;
2756 uint16_t plen, ptype;
2757 struct sctp_ifa *sctp_ifa;
2758 union sctp_sockstore store;
2760 struct sctp_ipv6addr_param addr6_store;
2763 struct sctp_ipv4addr_param addr4_store;
2766 SCTPDBG(SCTP_DEBUG_ASCONF2, "processing init-ack addresses\n");
2767 if (stcb == NULL) /* Un-needed check for SA */
2770 /* convert to upper bound */
2773 if ((offset + sizeof(struct sctp_paramhdr)) > length) {
2776 /* go through the addresses in the init-ack */
2777 ph = (struct sctp_paramhdr *)
2778 sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr),
2779 (uint8_t *)&tmp_param);
2780 while (ph != NULL) {
2781 ptype = ntohs(ph->param_type);
2782 plen = ntohs(ph->param_length);
2785 case SCTP_IPV6_ADDRESS:
2787 struct sctp_ipv6addr_param *a6p;
2789 /* get the entire IPv6 address param */
2790 a6p = (struct sctp_ipv6addr_param *)
2791 sctp_m_getptr(m, offset,
2792 sizeof(struct sctp_ipv6addr_param),
2793 (uint8_t *)&addr6_store);
2794 if (plen != sizeof(struct sctp_ipv6addr_param) ||
2798 memset(&store, 0, sizeof(union sctp_sockstore));
2799 store.sin6.sin6_family = AF_INET6;
2800 store.sin6.sin6_len = sizeof(struct sockaddr_in6);
2801 store.sin6.sin6_port = stcb->rport;
2802 memcpy(&store.sin6.sin6_addr, a6p->addr, sizeof(struct in6_addr));
2807 case SCTP_IPV4_ADDRESS:
2809 struct sctp_ipv4addr_param *a4p;
2811 /* get the entire IPv4 address param */
2812 a4p = (struct sctp_ipv4addr_param *)sctp_m_getptr(m, offset,
2813 sizeof(struct sctp_ipv4addr_param),
2814 (uint8_t *)&addr4_store);
2815 if (plen != sizeof(struct sctp_ipv4addr_param) ||
2819 memset(&store, 0, sizeof(union sctp_sockstore));
2820 store.sin.sin_family = AF_INET;
2821 store.sin.sin_len = sizeof(struct sockaddr_in);
2822 store.sin.sin_port = stcb->rport;
2823 store.sin.sin_addr.s_addr = a4p->addr;
2831 /* see if this address really (still) exists */
2832 sctp_ifa = sctp_find_ifa_by_addr(&store.sa, stcb->asoc.vrf_id,
2833 SCTP_ADDR_NOT_LOCKED);
2834 if (sctp_ifa == NULL) {
2835 /* address doesn't exist anymore */
2838 /* are ASCONFs allowed ? */
2839 if ((sctp_is_feature_on(stcb->sctp_ep,
2840 SCTP_PCB_FLAGS_DO_ASCONF)) &&
2841 stcb->asoc.asconf_supported) {
2842 /* queue an ASCONF DEL_IP_ADDRESS */
2843 status = sctp_asconf_queue_sa_delete(stcb, &store.sa);
2845 * if queued ok, and in correct state, send
2849 SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) {
2850 #ifdef SCTP_TIMER_BASED_ASCONF
2851 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
2852 stcb->sctp_ep, stcb,
2853 stcb->asoc.primary_destination);
2855 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2863 * Sanity check: Make sure the length isn't 0, otherwise
2864 * we'll be stuck in this loop for a long time...
2866 if (SCTP_SIZE32(plen) == 0) {
2867 SCTP_PRINTF("process_initack_addrs: bad len (%d) type=%xh\n",
2871 /* get next parameter */
2872 offset += SCTP_SIZE32(plen);
2873 if ((offset + sizeof(struct sctp_paramhdr)) > length)
2875 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset,
2876 sizeof(struct sctp_paramhdr), (uint8_t *)&tmp_param);
2880 /* FIX ME: need to verify return result for v6 address type if v6 disabled */
2882 * checks to see if a specific address is in the initack address list returns
2883 * 1 if found, 0 if not
2886 sctp_addr_in_initack(struct mbuf *m, uint32_t offset, uint32_t length, struct sockaddr *sa)
2888 struct sctp_paramhdr tmp_param, *ph;
2889 uint16_t plen, ptype;
2891 struct sockaddr_in *sin;
2892 struct sctp_ipv4addr_param *a4p;
2893 struct sctp_ipv6addr_param addr4_store;
2896 struct sockaddr_in6 *sin6;
2897 struct sctp_ipv6addr_param *a6p;
2898 struct sctp_ipv6addr_param addr6_store;
2899 struct sockaddr_in6 sin6_tmp;
2902 switch (sa->sa_family) {
2915 SCTPDBG(SCTP_DEBUG_ASCONF2, "find_initack_addr: starting search for ");
2916 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, sa);
2917 /* convert to upper bound */
2920 if ((offset + sizeof(struct sctp_paramhdr)) > length) {
2921 SCTPDBG(SCTP_DEBUG_ASCONF1,
2922 "find_initack_addr: invalid offset?\n");
2925 /* go through the addresses in the init-ack */
2926 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset,
2927 sizeof(struct sctp_paramhdr), (uint8_t *)&tmp_param);
2928 while (ph != NULL) {
2929 ptype = ntohs(ph->param_type);
2930 plen = ntohs(ph->param_length);
2933 case SCTP_IPV6_ADDRESS:
2934 if (sa->sa_family == AF_INET6) {
2935 /* get the entire IPv6 address param */
2936 if (plen != sizeof(struct sctp_ipv6addr_param)) {
2939 /* get the entire IPv6 address param */
2940 a6p = (struct sctp_ipv6addr_param *)
2941 sctp_m_getptr(m, offset,
2942 sizeof(struct sctp_ipv6addr_param),
2943 (uint8_t *)&addr6_store);
2947 sin6 = (struct sockaddr_in6 *)sa;
2948 if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr)) {
2949 /* create a copy and clear scope */
2950 memcpy(&sin6_tmp, sin6,
2951 sizeof(struct sockaddr_in6));
2953 in6_clearscope(&sin6->sin6_addr);
2955 if (memcmp(&sin6->sin6_addr, a6p->addr,
2956 sizeof(struct in6_addr)) == 0) {
2964 case SCTP_IPV4_ADDRESS:
2965 if (sa->sa_family == AF_INET) {
2966 if (plen != sizeof(struct sctp_ipv4addr_param)) {
2969 /* get the entire IPv4 address param */
2970 a4p = (struct sctp_ipv4addr_param *)
2971 sctp_m_getptr(m, offset,
2972 sizeof(struct sctp_ipv4addr_param),
2973 (uint8_t *)&addr4_store);
2977 sin = (struct sockaddr_in *)sa;
2978 if (sin->sin_addr.s_addr == a4p->addr) {
2988 /* get next parameter */
2989 offset += SCTP_SIZE32(plen);
2990 if (offset + sizeof(struct sctp_paramhdr) > length) {
2993 ph = (struct sctp_paramhdr *)
2994 sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr),
2995 (uint8_t *)&tmp_param);
3002 * makes sure that the current endpoint local addr list is consistent with
3003 * the new association (eg. subset bound, asconf allowed) adds addresses as
3007 sctp_check_address_list_ep(struct sctp_tcb *stcb, struct mbuf *m, int offset,
3008 int length, struct sockaddr *init_addr)
3010 struct sctp_laddr *laddr;
3012 /* go through the endpoint list */
3013 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
3014 /* be paranoid and validate the laddr */
3015 if (laddr->ifa == NULL) {
3016 SCTPDBG(SCTP_DEBUG_ASCONF1,
3017 "check_addr_list_ep: laddr->ifa is NULL");
3020 /* do i have it implicitly? */
3021 if (sctp_cmpaddr(&laddr->ifa->address.sa, init_addr)) {
3024 /* check to see if in the init-ack */
3025 if (!sctp_addr_in_initack(m, offset, length, &laddr->ifa->address.sa)) {
3027 sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb, laddr->ifa,
3028 SCTP_ADD_IP_ADDRESS, SCTP_ADDR_NOT_LOCKED);
3034 * makes sure that the current kernel address list is consistent with the new
3035 * association (with all addrs bound) adds addresses as necessary
3038 sctp_check_address_list_all(struct sctp_tcb *stcb, struct mbuf *m, int offset,
3039 int length, struct sockaddr *init_addr,
3040 uint16_t local_scope, uint16_t site_scope,
3041 uint16_t ipv4_scope, uint16_t loopback_scope)
3043 struct sctp_vrf *vrf = NULL;
3044 struct sctp_ifn *sctp_ifn;
3045 struct sctp_ifa *sctp_ifa;
3048 struct sockaddr_in *sin;
3051 struct sockaddr_in6 *sin6;
3055 vrf_id = stcb->asoc.vrf_id;
3059 SCTP_IPI_ADDR_RLOCK();
3060 vrf = sctp_find_vrf(vrf_id);
3062 SCTP_IPI_ADDR_RUNLOCK();
3065 /* go through all our known interfaces */
3066 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
3067 if (loopback_scope == 0 && SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
3068 /* skip loopback interface */
3071 /* go through each interface address */
3072 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
3073 /* do i have it implicitly? */
3074 if (sctp_cmpaddr(&sctp_ifa->address.sa, init_addr)) {
3077 switch (sctp_ifa->address.sa.sa_family) {
3080 sin = &sctp_ifa->address.sin;
3081 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
3082 &sin->sin_addr) != 0) {
3085 if ((ipv4_scope == 0) &&
3086 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
3087 /* private address not in scope */
3094 sin6 = &sctp_ifa->address.sin6;
3095 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
3096 &sin6->sin6_addr) != 0) {
3099 if ((local_scope == 0) &&
3100 (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))) {
3103 if ((site_scope == 0) &&
3104 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
3112 /* check to see if in the init-ack */
3113 if (!sctp_addr_in_initack(m, offset, length, &sctp_ifa->address.sa)) {
3115 sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb,
3116 sctp_ifa, SCTP_ADD_IP_ADDRESS,
3119 } /* end foreach ifa */
3120 } /* end foreach ifn */
3121 SCTP_IPI_ADDR_RUNLOCK();
3125 * validates an init-ack chunk (from a cookie-echo) with current addresses
3126 * adds addresses from the init-ack into our local address list, if needed
3127 * queues asconf adds/deletes addresses as needed and makes appropriate list
3128 * changes for source address selection m, offset: points to the start of the
3129 * address list in an init-ack chunk length: total length of the address
3130 * params only init_addr: address where my INIT-ACK was sent from
3133 sctp_check_address_list(struct sctp_tcb *stcb, struct mbuf *m, int offset,
3134 int length, struct sockaddr *init_addr,
3135 uint16_t local_scope, uint16_t site_scope,
3136 uint16_t ipv4_scope, uint16_t loopback_scope)
3138 /* process the local addresses in the initack */
3139 sctp_process_initack_addresses(stcb, m, offset, length);
3141 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3142 /* bound all case */
3143 sctp_check_address_list_all(stcb, m, offset, length, init_addr,
3144 local_scope, site_scope, ipv4_scope, loopback_scope);
3146 /* subset bound case */
3147 if (sctp_is_feature_on(stcb->sctp_ep,
3148 SCTP_PCB_FLAGS_DO_ASCONF)) {
3149 /* asconf's allowed */
3150 sctp_check_address_list_ep(stcb, m, offset, length,
3153 /* else, no asconfs allowed, so what we sent is what we get */
3158 * sctp_bindx() support
3161 sctp_addr_mgmt_ep_sa(struct sctp_inpcb *inp, struct sockaddr *sa,
3162 uint32_t type, uint32_t vrf_id)
3164 struct sctp_ifa *ifa;
3165 struct sctp_laddr *laddr, *nladdr;
3167 if (sa->sa_len == 0) {
3168 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EINVAL);
3171 if (type == SCTP_ADD_IP_ADDRESS) {
3172 /* For an add the address MUST be on the system */
3173 ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED);
3174 } else if (type == SCTP_DEL_IP_ADDRESS) {
3175 /* For a delete we need to find it in the inp */
3176 ifa = sctp_find_ifa_in_ep(inp, sa, SCTP_ADDR_NOT_LOCKED);
3181 if (type == SCTP_ADD_IP_ADDRESS) {
3182 sctp_add_local_addr_ep(inp, ifa, type);
3183 } else if (type == SCTP_DEL_IP_ADDRESS) {
3184 if (inp->laddr_count < 2) {
3185 /* can't delete the last local address */
3186 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EINVAL);
3189 LIST_FOREACH(laddr, &inp->sctp_addr_list,
3191 if (ifa == laddr->ifa) {
3192 /* Mark in the delete */
3193 laddr->action = type;
3197 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
3199 * There is no need to start the iterator if the inp
3200 * has no associations.
3202 if (type == SCTP_DEL_IP_ADDRESS) {
3203 LIST_FOREACH_SAFE(laddr, &inp->sctp_addr_list, sctp_nxt_addr, nladdr) {
3204 if (laddr->ifa == ifa) {
3205 sctp_del_local_addr_ep(inp, ifa);
3210 struct sctp_asconf_iterator *asc;
3211 struct sctp_laddr *wi;
3214 SCTP_MALLOC(asc, struct sctp_asconf_iterator *,
3215 sizeof(struct sctp_asconf_iterator),
3218 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, ENOMEM);
3221 wi = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_laddr), struct sctp_laddr);
3223 SCTP_FREE(asc, SCTP_M_ASC_IT);
3224 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, ENOMEM);
3227 LIST_INIT(&asc->list_of_work);
3229 SCTP_INCR_LADDR_COUNT();
3232 atomic_add_int(&ifa->refcount, 1);
3233 LIST_INSERT_HEAD(&asc->list_of_work, wi, sctp_nxt_addr);
3234 ret = sctp_initiate_iterator(sctp_asconf_iterator_ep,
3235 sctp_asconf_iterator_stcb,
3236 sctp_asconf_iterator_ep_end,
3238 SCTP_PCB_ANY_FEATURES,
3239 SCTP_ASOC_ANY_STATE,
3241 sctp_asconf_iterator_end, inp, 0);
3243 SCTP_PRINTF("Failed to initiate iterator for addr_mgmt_ep_sa\n");
3244 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EFAULT);
3245 sctp_asconf_iterator_end(asc, 0);
3251 /* invalid address! */
3252 SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EADDRNOTAVAIL);
3253 return (EADDRNOTAVAIL);
3258 sctp_asconf_send_nat_state_update(struct sctp_tcb *stcb, struct sctp_nets *net)
3260 struct sctp_asconf_addr *aa_vtag, *aa_add, *aa_del;
3261 struct sctp_ifa *sctp_ifap;
3262 struct sctp_asconf_tag_param *vtag;
3264 struct sockaddr_in *to;
3267 struct sockaddr_in6 *to6;
3271 SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing net\n");
3275 SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing stcb\n");
3279 * Need to have in the ASCONF: - VTAG(my_vtag/peer_vtag) -
3280 * ADD(wildcard) - DEL(wildcard) - ADD(Any global addresses)
3282 SCTP_MALLOC(aa_vtag, struct sctp_asconf_addr *, sizeof(struct sctp_asconf_addr), SCTP_M_ASC_ADDR);
3283 SCTP_MALLOC(aa_add, struct sctp_asconf_addr *, sizeof(struct sctp_asconf_addr), SCTP_M_ASC_ADDR);
3284 SCTP_MALLOC(aa_del, struct sctp_asconf_addr *, sizeof(struct sctp_asconf_addr), SCTP_M_ASC_ADDR);
3286 if ((aa_vtag == NULL) || (aa_add == NULL) || (aa_del == NULL)) {
3287 /* Didn't get memory */
3288 SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: failed to get memory!\n");
3290 if (aa_vtag != NULL) {
3291 SCTP_FREE(aa_vtag, SCTP_M_ASC_ADDR);
3293 if (aa_add != NULL) {
3294 SCTP_FREE(aa_add, SCTP_M_ASC_ADDR);
3296 if (aa_del != NULL) {
3297 SCTP_FREE(aa_del, SCTP_M_ASC_ADDR);
3301 memset(aa_vtag, 0, sizeof(struct sctp_asconf_addr));
3302 aa_vtag->special_del = 0;
3303 /* Fill in ASCONF address parameter fields. */
3304 /* Top level elements are "networked" during send. */
3305 aa_vtag->ifa = NULL;
3306 aa_vtag->sent = 0; /* clear sent flag */
3307 vtag = (struct sctp_asconf_tag_param *)&aa_vtag->ap.aph;
3308 vtag->aph.ph.param_type = SCTP_NAT_VTAGS;
3309 vtag->aph.ph.param_length = sizeof(struct sctp_asconf_tag_param);
3310 vtag->local_vtag = htonl(stcb->asoc.my_vtag);
3311 vtag->remote_vtag = htonl(stcb->asoc.peer_vtag);
3313 memset(aa_add, 0, sizeof(struct sctp_asconf_addr));
3314 memset(aa_del, 0, sizeof(struct sctp_asconf_addr));
3315 switch (net->ro._l_addr.sa.sa_family) {
3318 aa_add->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
3319 aa_add->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param);
3320 aa_add->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
3321 aa_add->ap.addrp.ph.param_length = sizeof(struct sctp_ipv4addr_param);
3322 /* No need to fill the address, we are using 0.0.0.0 */
3323 aa_del->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
3324 aa_del->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param);
3325 aa_del->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
3326 aa_del->ap.addrp.ph.param_length = sizeof(struct sctp_ipv4addr_param);
3327 /* No need to fill the address, we are using 0.0.0.0 */
3332 aa_add->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
3333 aa_add->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param);
3334 aa_add->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
3335 aa_add->ap.addrp.ph.param_length = sizeof(struct sctp_ipv6addr_param);
3336 /* No need to fill the address, we are using ::0 */
3337 aa_del->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS;
3338 aa_del->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param);
3339 aa_del->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
3340 aa_del->ap.addrp.ph.param_length = sizeof(struct sctp_ipv6addr_param);
3341 /* No need to fill the address, we are using ::0 */
3345 SCTPDBG(SCTP_DEBUG_ASCONF1,
3346 "sctp_asconf_send_nat_state_update: unknown address family %d\n",
3347 net->ro._l_addr.sa.sa_family);
3350 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa_vtag, next);
3351 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa_add, next);
3352 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa_del, next);
3354 /* Now we must hunt the addresses and add all global addresses */
3355 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3356 struct sctp_vrf *vrf = NULL;
3357 struct sctp_ifn *sctp_ifnp;
3360 vrf_id = stcb->sctp_ep->def_vrf_id;
3361 vrf = sctp_find_vrf(vrf_id);
3366 SCTP_IPI_ADDR_RLOCK();
3367 LIST_FOREACH(sctp_ifnp, &vrf->ifnlist, next_ifn) {
3368 LIST_FOREACH(sctp_ifap, &sctp_ifnp->ifalist, next_ifa) {
3369 switch (sctp_ifap->address.sa.sa_family) {
3372 to = &sctp_ifap->address.sin;
3373 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
3374 &to->sin_addr) != 0) {
3377 if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) {
3380 if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) {
3387 to6 = &sctp_ifap->address.sin6;
3388 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
3389 &to6->sin6_addr) != 0) {
3392 if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) {
3395 if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) {
3403 sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS);
3406 SCTP_IPI_ADDR_RUNLOCK();
3408 struct sctp_laddr *laddr;
3410 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
3411 if (laddr->ifa == NULL) {
3414 if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED)
3416 * Address being deleted by the system, dont
3420 if (laddr->action == SCTP_DEL_IP_ADDRESS) {
3422 * Address being deleted on this ep don't
3427 sctp_ifap = laddr->ifa;
3428 switch (sctp_ifap->address.sa.sa_family) {
3431 to = &sctp_ifap->address.sin;
3432 if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) {
3435 if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) {
3442 to6 = &sctp_ifap->address.sin6;
3443 if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) {
3446 if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) {
3454 sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS);
3458 /* Now we must send the asconf into the queue */
3459 sctp_send_asconf(stcb, net, SCTP_ADDR_NOT_LOCKED);