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_asconf_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, false, 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_asconf_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)
2200 if (type == SCTP_ADD_IP_ADDRESS) {
2201 /* prevent this address from being used as a source */
2202 sctp_add_local_addr_restricted(stcb, ifa);
2203 } else if (type == SCTP_DEL_IP_ADDRESS) {
2204 struct sctp_nets *net;
2206 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2207 /* delete this address if cached */
2208 if (net->ro._s_addr == ifa) {
2209 sctp_free_ifa(net->ro._s_addr);
2210 net->ro._s_addr = NULL;
2211 net->src_addr_selected = 0;
2212 RO_NHFREE(&net->ro);
2214 * Now we deleted our src address,
2215 * should we not also now reset the
2216 * cwnd/rto to start as if its a new
2219 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
2223 } else if (type == SCTP_SET_PRIM_ADDR) {
2224 if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
2225 /* must validate the ifa is in the ep */
2226 if (sctp_is_addr_in_ep(stcb->sctp_ep, ifa) == 0) {
2230 /* Need to check scopes for this guy */
2231 if (sctp_is_address_in_scope(ifa, &stcb->asoc.scope, 0) == 0) {
2236 /* queue an asconf for this address add/delete */
2237 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF) &&
2238 stcb->asoc.asconf_supported == 1) {
2239 /* queue an asconf for this addr */
2240 status = sctp_asconf_queue_add(stcb, ifa, type);
2242 * if queued ok, and in the open state, update the
2243 * count of queued params. If in the non-open
2244 * state, these get sent when the assoc goes open.
2246 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
2247 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
2255 * If we have queued params in the open state, send out an ASCONF.
2257 if (num_queued > 0) {
2258 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2263 sctp_asconf_iterator_end(void *ptr, uint32_t val SCTP_UNUSED)
2265 struct sctp_asconf_iterator *asc;
2266 struct sctp_ifa *ifa;
2267 struct sctp_laddr *l, *nl;
2269 asc = (struct sctp_asconf_iterator *)ptr;
2270 LIST_FOREACH_SAFE(l, &asc->list_of_work, sctp_nxt_addr, nl) {
2272 if (l->action == SCTP_ADD_IP_ADDRESS) {
2273 /* Clear the defer use flag */
2274 ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE;
2277 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_laddr), l);
2278 SCTP_DECR_LADDR_COUNT();
2280 SCTP_FREE(asc, SCTP_M_ASC_IT);
2284 * sa is the sockaddr to ask the peer to set primary to.
2285 * returns: 0 = completed, -1 = error
2288 sctp_set_primary_ip_address_sa(struct sctp_tcb *stcb, struct sockaddr *sa)
2291 struct sctp_ifa *ifa;
2293 /* find the ifa for the desired set primary */
2294 vrf_id = stcb->asoc.vrf_id;
2295 ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED);
2297 /* Invalid address */
2301 /* queue an ASCONF:SET_PRIM_ADDR to be sent */
2302 if (!sctp_asconf_queue_add(stcb, ifa, SCTP_SET_PRIM_ADDR)) {
2303 /* set primary queuing succeeded */
2304 SCTPDBG(SCTP_DEBUG_ASCONF1,
2305 "set_primary_ip_address_sa: queued on tcb=%p, ",
2307 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
2308 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
2309 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
2310 #ifdef SCTP_TIMER_BASED_ASCONF
2311 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
2312 stcb->sctp_ep, stcb,
2313 stcb->asoc.primary_destination);
2315 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2319 SCTPDBG(SCTP_DEBUG_ASCONF1, "set_primary_ip_address_sa: failed to add to queue on tcb=%p, ",
2321 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
2328 sctp_is_addr_pending(struct sctp_tcb *stcb, struct sctp_ifa *sctp_ifa)
2330 struct sctp_tmit_chunk *chk, *nchk;
2331 unsigned int offset, asconf_limit;
2332 struct sctp_asconf_chunk *acp;
2333 struct sctp_asconf_paramhdr *aph;
2334 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE];
2335 struct sctp_paramhdr *ph;
2336 int add_cnt, del_cnt;
2337 uint16_t last_param_type;
2339 add_cnt = del_cnt = 0;
2340 last_param_type = 0;
2341 TAILQ_FOREACH_SAFE(chk, &stcb->asoc.asconf_send_queue, sctp_next, nchk) {
2342 if (chk->data == NULL) {
2343 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: No mbuf data?\n");
2347 acp = mtod(chk->data, struct sctp_asconf_chunk *);
2348 offset += sizeof(struct sctp_asconf_chunk);
2349 asconf_limit = ntohs(acp->ch.chunk_length);
2350 ph = (struct sctp_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_paramhdr), aparam_buf);
2352 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: couldn't get lookup addr!\n");
2355 offset += ntohs(ph->param_length);
2357 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_asconf_paramhdr), aparam_buf);
2359 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: Empty ASCONF will be sent?\n");
2362 while (aph != NULL) {
2363 unsigned int param_length, param_type;
2365 param_type = ntohs(aph->ph.param_type);
2366 param_length = ntohs(aph->ph.param_length);
2367 if (offset + param_length > asconf_limit) {
2368 /* parameter goes beyond end of chunk! */
2371 if (param_length > sizeof(aparam_buf)) {
2372 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: param length (%u) larger than buffer size!\n", param_length);
2375 if (param_length <= sizeof(struct sctp_paramhdr)) {
2376 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: param length(%u) too short\n", param_length);
2380 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, param_length, aparam_buf);
2382 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: couldn't get entire param\n");
2386 ph = (struct sctp_paramhdr *)(aph + 1);
2387 if (sctp_addr_match(ph, &sctp_ifa->address.sa) != 0) {
2388 switch (param_type) {
2389 case SCTP_ADD_IP_ADDRESS:
2392 case SCTP_DEL_IP_ADDRESS:
2398 last_param_type = param_type;
2401 offset += SCTP_SIZE32(param_length);
2402 if (offset >= asconf_limit) {
2403 /* no more data in the mbuf chain */
2406 /* get pointer to next asconf param */
2407 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_asconf_paramhdr), aparam_buf);
2412 * we want to find the sequences which consist of ADD -> DEL -> ADD
2415 if (add_cnt > del_cnt ||
2416 (add_cnt == del_cnt && last_param_type == SCTP_ADD_IP_ADDRESS)) {
2422 static struct sockaddr *
2423 sctp_find_valid_localaddr(struct sctp_tcb *stcb, int addr_locked)
2425 struct sctp_vrf *vrf = NULL;
2426 struct sctp_ifn *sctp_ifn;
2427 struct sctp_ifa *sctp_ifa;
2429 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2430 SCTP_IPI_ADDR_RLOCK();
2431 vrf = sctp_find_vrf(stcb->asoc.vrf_id);
2433 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2434 SCTP_IPI_ADDR_RUNLOCK();
2437 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
2438 if (stcb->asoc.scope.loopback_scope == 0 &&
2439 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
2440 /* Skip if loopback_scope not set */
2443 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
2444 switch (sctp_ifa->address.sa.sa_family) {
2447 if (stcb->asoc.scope.ipv4_addr_legal) {
2448 struct sockaddr_in *sin;
2450 sin = &sctp_ifa->address.sin;
2451 if (sin->sin_addr.s_addr == 0) {
2452 /* skip unspecifed addresses */
2455 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
2456 &sin->sin_addr) != 0) {
2459 if (stcb->asoc.scope.ipv4_local_scope == 0 &&
2460 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))
2463 if (sctp_is_addr_restricted(stcb, sctp_ifa) &&
2464 (!sctp_is_addr_pending(stcb, sctp_ifa)))
2467 * found a valid local v4 address to
2470 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2471 SCTP_IPI_ADDR_RUNLOCK();
2472 return (&sctp_ifa->address.sa);
2478 if (stcb->asoc.scope.ipv6_addr_legal) {
2479 struct sockaddr_in6 *sin6;
2481 if (sctp_ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) {
2485 sin6 = &sctp_ifa->address.sin6;
2486 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2488 * we skip unspecifed
2493 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
2494 &sin6->sin6_addr) != 0) {
2497 if (stcb->asoc.scope.local_scope == 0 &&
2498 IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))
2500 if (stcb->asoc.scope.site_scope == 0 &&
2501 IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))
2504 if (sctp_is_addr_restricted(stcb, sctp_ifa) &&
2505 (!sctp_is_addr_pending(stcb, sctp_ifa)))
2508 * found a valid local v6 address to
2511 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2512 SCTP_IPI_ADDR_RUNLOCK();
2513 return (&sctp_ifa->address.sa);
2522 /* no valid addresses found */
2523 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2524 SCTP_IPI_ADDR_RUNLOCK();
2528 static struct sockaddr *
2529 sctp_find_valid_localaddr_ep(struct sctp_tcb *stcb)
2531 struct sctp_laddr *laddr;
2533 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
2534 if (laddr->ifa == NULL) {
2537 /* is the address restricted ? */
2538 if (sctp_is_addr_restricted(stcb, laddr->ifa) &&
2539 (!sctp_is_addr_pending(stcb, laddr->ifa)))
2542 /* found a valid local address to use */
2543 return (&laddr->ifa->address.sa);
2545 /* no valid addresses found */
2550 * builds an ASCONF chunk from queued ASCONF params.
2551 * returns NULL on error (no mbuf, no ASCONF params queued, etc).
2554 sctp_compose_asconf(struct sctp_tcb *stcb, int *retlen, int addr_locked)
2556 struct mbuf *m_asconf, *m_asconf_chk;
2557 struct sctp_asconf_addr *aa;
2558 struct sctp_asconf_chunk *acp;
2559 struct sctp_asconf_paramhdr *aph;
2560 struct sctp_asconf_addr_param *aap;
2562 uint32_t correlation_id = 1; /* 0 is reserved... */
2563 caddr_t ptr, lookup_ptr;
2564 uint8_t lookup_used = 0;
2566 /* are there any asconf params to send? */
2567 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
2575 * get a chunk header mbuf and a cluster for the asconf params since
2576 * it's simpler to fill in the asconf chunk header lookup address on
2579 m_asconf_chk = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_chunk), 0, M_NOWAIT, 1, MT_DATA);
2580 if (m_asconf_chk == NULL) {
2582 SCTPDBG(SCTP_DEBUG_ASCONF1,
2583 "sctp_compose_asconf: couldn't get chunk mbuf!\n");
2586 m_asconf = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA);
2587 if (m_asconf == NULL) {
2589 SCTPDBG(SCTP_DEBUG_ASCONF1,
2590 "sctp_compose_asconf: couldn't get mbuf!\n");
2591 sctp_m_freem(m_asconf_chk);
2594 SCTP_BUF_LEN(m_asconf_chk) = sizeof(struct sctp_asconf_chunk);
2595 SCTP_BUF_LEN(m_asconf) = 0;
2596 acp = mtod(m_asconf_chk, struct sctp_asconf_chunk *);
2597 memset(acp, 0, sizeof(struct sctp_asconf_chunk));
2598 /* save pointers to lookup address and asconf params */
2599 lookup_ptr = (caddr_t)(acp + 1); /* after the header */
2600 ptr = mtod(m_asconf, caddr_t); /* beginning of cluster */
2602 /* fill in chunk header info */
2603 acp->ch.chunk_type = SCTP_ASCONF;
2604 acp->ch.chunk_flags = 0;
2605 acp->serial_number = htonl(stcb->asoc.asconf_seq_out);
2606 stcb->asoc.asconf_seq_out++;
2608 /* add parameters... up to smallest MTU allowed */
2609 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
2612 /* get the parameter length */
2613 p_length = SCTP_SIZE32(aa->ap.aph.ph.param_length);
2614 /* will it fit in current chunk? */
2615 if ((SCTP_BUF_LEN(m_asconf) + p_length > stcb->asoc.smallest_mtu) ||
2616 (SCTP_BUF_LEN(m_asconf) + p_length > MCLBYTES)) {
2617 /* won't fit, so we're done with this chunk */
2620 /* assign (and store) a correlation id */
2621 aa->ap.aph.correlation_id = correlation_id++;
2624 * fill in address if we're doing a delete this is a simple
2625 * way for us to fill in the correlation address, which
2626 * should only be used by the peer if we're deleting our
2627 * source address and adding a new address (e.g. renumbering
2630 if (lookup_used == 0 &&
2631 (aa->special_del == 0) &&
2632 aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) {
2633 struct sctp_ipv6addr_param *lookup;
2634 uint16_t p_size, addr_size;
2636 lookup = (struct sctp_ipv6addr_param *)lookup_ptr;
2637 lookup->ph.param_type =
2638 htons(aa->ap.addrp.ph.param_type);
2639 if (aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) {
2640 /* copy IPv6 address */
2641 p_size = sizeof(struct sctp_ipv6addr_param);
2642 addr_size = sizeof(struct in6_addr);
2644 /* copy IPv4 address */
2645 p_size = sizeof(struct sctp_ipv4addr_param);
2646 addr_size = sizeof(struct in_addr);
2648 lookup->ph.param_length = htons(SCTP_SIZE32(p_size));
2649 memcpy(lookup->addr, &aa->ap.addrp.addr, addr_size);
2650 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size);
2653 /* copy into current space */
2654 memcpy(ptr, &aa->ap, p_length);
2656 /* network elements and update lengths */
2657 aph = (struct sctp_asconf_paramhdr *)ptr;
2658 aap = (struct sctp_asconf_addr_param *)ptr;
2659 /* correlation_id is transparent to peer, no htonl needed */
2660 aph->ph.param_type = htons(aph->ph.param_type);
2661 aph->ph.param_length = htons(aph->ph.param_length);
2662 aap->addrp.ph.param_type = htons(aap->addrp.ph.param_type);
2663 aap->addrp.ph.param_length = htons(aap->addrp.ph.param_length);
2665 SCTP_BUF_LEN(m_asconf) += SCTP_SIZE32(p_length);
2666 ptr += SCTP_SIZE32(p_length);
2669 * these params are removed off the pending list upon
2670 * getting an ASCONF-ACK back from the peer, just set flag
2674 /* check to see if the lookup addr has been populated yet */
2675 if (lookup_used == 0) {
2676 /* NOTE: if the address param is optional, can skip this... */
2677 /* add any valid (existing) address... */
2678 struct sctp_ipv6addr_param *lookup;
2679 uint16_t p_size, addr_size;
2680 struct sockaddr *found_addr;
2683 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL)
2684 found_addr = sctp_find_valid_localaddr(stcb,
2687 found_addr = sctp_find_valid_localaddr_ep(stcb);
2689 lookup = (struct sctp_ipv6addr_param *)lookup_ptr;
2690 if (found_addr != NULL) {
2691 switch (found_addr->sa_family) {
2694 /* copy IPv6 address */
2695 lookup->ph.param_type =
2696 htons(SCTP_IPV6_ADDRESS);
2697 p_size = sizeof(struct sctp_ipv6addr_param);
2698 addr_size = sizeof(struct in6_addr);
2699 addr_ptr = (caddr_t)&((struct sockaddr_in6 *)
2700 found_addr)->sin6_addr;
2705 /* copy IPv4 address */
2706 lookup->ph.param_type =
2707 htons(SCTP_IPV4_ADDRESS);
2708 p_size = sizeof(struct sctp_ipv4addr_param);
2709 addr_size = sizeof(struct in_addr);
2710 addr_ptr = (caddr_t)&((struct sockaddr_in *)
2711 found_addr)->sin_addr;
2715 SCTPDBG(SCTP_DEBUG_ASCONF1,
2716 "sctp_compose_asconf: no usable lookup addr (family = %d)!\n",
2717 found_addr->sa_family);
2718 sctp_m_freem(m_asconf_chk);
2719 sctp_m_freem(m_asconf);
2722 lookup->ph.param_length = htons(SCTP_SIZE32(p_size));
2723 memcpy(lookup->addr, addr_ptr, addr_size);
2724 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size);
2726 /* uh oh... don't have any address?? */
2727 SCTPDBG(SCTP_DEBUG_ASCONF1,
2728 "sctp_compose_asconf: no lookup addr!\n");
2729 sctp_m_freem(m_asconf_chk);
2730 sctp_m_freem(m_asconf);
2734 /* chain it all together */
2735 SCTP_BUF_NEXT(m_asconf_chk) = m_asconf;
2736 *retlen = SCTP_BUF_LEN(m_asconf_chk) + SCTP_BUF_LEN(m_asconf);
2737 acp->ch.chunk_length = htons(*retlen);
2739 return (m_asconf_chk);
2743 * section to handle address changes before an association is up eg. changes
2744 * during INIT/INIT-ACK/COOKIE-ECHO handshake
2748 * processes the (local) addresses in the INIT-ACK chunk
2751 sctp_process_initack_addresses(struct sctp_tcb *stcb, struct mbuf *m,
2752 unsigned int offset, unsigned int length)
2754 struct sctp_paramhdr tmp_param, *ph;
2755 uint16_t plen, ptype;
2756 struct sctp_ifa *sctp_ifa;
2757 union sctp_sockstore store;
2759 struct sctp_ipv6addr_param addr6_store;
2762 struct sctp_ipv4addr_param addr4_store;
2765 SCTPDBG(SCTP_DEBUG_ASCONF2, "processing init-ack addresses\n");
2766 if (stcb == NULL) /* Un-needed check for SA */
2769 /* convert to upper bound */
2772 if ((offset + sizeof(struct sctp_paramhdr)) > length) {
2775 /* go through the addresses in the init-ack */
2776 ph = (struct sctp_paramhdr *)
2777 sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr),
2778 (uint8_t *)&tmp_param);
2779 while (ph != NULL) {
2780 ptype = ntohs(ph->param_type);
2781 plen = ntohs(ph->param_length);
2784 case SCTP_IPV6_ADDRESS:
2786 struct sctp_ipv6addr_param *a6p;
2788 /* get the entire IPv6 address param */
2789 a6p = (struct sctp_ipv6addr_param *)
2790 sctp_m_getptr(m, offset,
2791 sizeof(struct sctp_ipv6addr_param),
2792 (uint8_t *)&addr6_store);
2793 if (plen != sizeof(struct sctp_ipv6addr_param) ||
2797 memset(&store, 0, sizeof(union sctp_sockstore));
2798 store.sin6.sin6_family = AF_INET6;
2799 store.sin6.sin6_len = sizeof(struct sockaddr_in6);
2800 store.sin6.sin6_port = stcb->rport;
2801 memcpy(&store.sin6.sin6_addr, a6p->addr, sizeof(struct in6_addr));
2806 case SCTP_IPV4_ADDRESS:
2808 struct sctp_ipv4addr_param *a4p;
2810 /* get the entire IPv4 address param */
2811 a4p = (struct sctp_ipv4addr_param *)sctp_m_getptr(m, offset,
2812 sizeof(struct sctp_ipv4addr_param),
2813 (uint8_t *)&addr4_store);
2814 if (plen != sizeof(struct sctp_ipv4addr_param) ||
2818 memset(&store, 0, sizeof(union sctp_sockstore));
2819 store.sin.sin_family = AF_INET;
2820 store.sin.sin_len = sizeof(struct sockaddr_in);
2821 store.sin.sin_port = stcb->rport;
2822 store.sin.sin_addr.s_addr = a4p->addr;
2830 /* see if this address really (still) exists */
2831 sctp_ifa = sctp_find_ifa_by_addr(&store.sa, stcb->asoc.vrf_id,
2832 SCTP_ADDR_NOT_LOCKED);
2833 if (sctp_ifa == NULL) {
2834 /* address doesn't exist anymore */
2837 /* are ASCONFs allowed ? */
2838 if ((sctp_is_feature_on(stcb->sctp_ep,
2839 SCTP_PCB_FLAGS_DO_ASCONF)) &&
2840 stcb->asoc.asconf_supported) {
2841 /* queue an ASCONF DEL_IP_ADDRESS */
2842 status = sctp_asconf_queue_sa_delete(stcb, &store.sa);
2844 * if queued ok, and in correct state, send
2848 SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) {
2849 #ifdef SCTP_TIMER_BASED_ASCONF
2850 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
2851 stcb->sctp_ep, stcb,
2852 stcb->asoc.primary_destination);
2854 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2862 * Sanity check: Make sure the length isn't 0, otherwise
2863 * we'll be stuck in this loop for a long time...
2865 if (SCTP_SIZE32(plen) == 0) {
2866 SCTP_PRINTF("process_initack_addrs: bad len (%d) type=%xh\n",
2870 /* get next parameter */
2871 offset += SCTP_SIZE32(plen);
2872 if ((offset + sizeof(struct sctp_paramhdr)) > length)
2874 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset,
2875 sizeof(struct sctp_paramhdr), (uint8_t *)&tmp_param);
2879 /* FIX ME: need to verify return result for v6 address type if v6 disabled */
2881 * checks to see if a specific address is in the initack address list returns
2882 * 1 if found, 0 if not
2885 sctp_addr_in_initack(struct mbuf *m, uint32_t offset, uint32_t length, struct sockaddr *sa)
2887 struct sctp_paramhdr tmp_param, *ph;
2888 uint16_t plen, ptype;
2890 struct sockaddr_in *sin;
2891 struct sctp_ipv4addr_param *a4p;
2892 struct sctp_ipv6addr_param addr4_store;
2895 struct sockaddr_in6 *sin6;
2896 struct sctp_ipv6addr_param *a6p;
2897 struct sctp_ipv6addr_param addr6_store;
2898 struct sockaddr_in6 sin6_tmp;
2901 switch (sa->sa_family) {
2914 SCTPDBG(SCTP_DEBUG_ASCONF2, "find_initack_addr: starting search for ");
2915 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, sa);
2916 /* convert to upper bound */
2919 if ((offset + sizeof(struct sctp_paramhdr)) > length) {
2920 SCTPDBG(SCTP_DEBUG_ASCONF1,
2921 "find_initack_addr: invalid offset?\n");
2924 /* go through the addresses in the init-ack */
2925 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset,
2926 sizeof(struct sctp_paramhdr), (uint8_t *)&tmp_param);
2927 while (ph != NULL) {
2928 ptype = ntohs(ph->param_type);
2929 plen = ntohs(ph->param_length);
2932 case SCTP_IPV6_ADDRESS:
2933 if (sa->sa_family == AF_INET6) {
2934 /* get the entire IPv6 address param */
2935 if (plen != sizeof(struct sctp_ipv6addr_param)) {
2938 /* get the entire IPv6 address param */
2939 a6p = (struct sctp_ipv6addr_param *)
2940 sctp_m_getptr(m, offset,
2941 sizeof(struct sctp_ipv6addr_param),
2942 (uint8_t *)&addr6_store);
2946 sin6 = (struct sockaddr_in6 *)sa;
2947 if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr)) {
2948 /* create a copy and clear scope */
2949 memcpy(&sin6_tmp, sin6,
2950 sizeof(struct sockaddr_in6));
2952 in6_clearscope(&sin6->sin6_addr);
2954 if (memcmp(&sin6->sin6_addr, a6p->addr,
2955 sizeof(struct in6_addr)) == 0) {
2963 case SCTP_IPV4_ADDRESS:
2964 if (sa->sa_family == AF_INET) {
2965 if (plen != sizeof(struct sctp_ipv4addr_param)) {
2968 /* get the entire IPv4 address param */
2969 a4p = (struct sctp_ipv4addr_param *)
2970 sctp_m_getptr(m, offset,
2971 sizeof(struct sctp_ipv4addr_param),
2972 (uint8_t *)&addr4_store);
2976 sin = (struct sockaddr_in *)sa;
2977 if (sin->sin_addr.s_addr == a4p->addr) {
2987 /* get next parameter */
2988 offset += SCTP_SIZE32(plen);
2989 if (offset + sizeof(struct sctp_paramhdr) > length) {
2992 ph = (struct sctp_paramhdr *)
2993 sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr),
2994 (uint8_t *)&tmp_param);
3001 * makes sure that the current endpoint local addr list is consistent with
3002 * the new association (eg. subset bound, asconf allowed) adds addresses as
3006 sctp_check_address_list_ep(struct sctp_tcb *stcb, struct mbuf *m, int offset,
3007 int length, struct sockaddr *init_addr)
3009 struct sctp_laddr *laddr;
3011 /* go through the endpoint list */
3012 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
3013 /* be paranoid and validate the laddr */
3014 if (laddr->ifa == NULL) {
3015 SCTPDBG(SCTP_DEBUG_ASCONF1,
3016 "check_addr_list_ep: laddr->ifa is NULL");
3019 /* do i have it implicitly? */
3020 if (sctp_cmpaddr(&laddr->ifa->address.sa, init_addr)) {
3023 /* check to see if in the init-ack */
3024 if (!sctp_addr_in_initack(m, offset, length, &laddr->ifa->address.sa)) {
3026 sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb, laddr->ifa,
3027 SCTP_ADD_IP_ADDRESS, SCTP_ADDR_NOT_LOCKED);
3033 * makes sure that the current kernel address list is consistent with the new
3034 * association (with all addrs bound) adds addresses as necessary
3037 sctp_check_address_list_all(struct sctp_tcb *stcb, struct mbuf *m, int offset,
3038 int length, struct sockaddr *init_addr,
3039 uint16_t local_scope, uint16_t site_scope,
3040 uint16_t ipv4_scope, uint16_t loopback_scope)
3042 struct sctp_vrf *vrf = NULL;
3043 struct sctp_ifn *sctp_ifn;
3044 struct sctp_ifa *sctp_ifa;
3047 struct sockaddr_in *sin;
3050 struct sockaddr_in6 *sin6;
3054 vrf_id = stcb->asoc.vrf_id;
3058 SCTP_IPI_ADDR_RLOCK();
3059 vrf = sctp_find_vrf(vrf_id);
3061 SCTP_IPI_ADDR_RUNLOCK();
3064 /* go through all our known interfaces */
3065 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
3066 if (loopback_scope == 0 && SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
3067 /* skip loopback interface */
3070 /* go through each interface address */
3071 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
3072 /* do i have it implicitly? */
3073 if (sctp_cmpaddr(&sctp_ifa->address.sa, init_addr)) {
3076 switch (sctp_ifa->address.sa.sa_family) {
3079 sin = &sctp_ifa->address.sin;
3080 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
3081 &sin->sin_addr) != 0) {
3084 if ((ipv4_scope == 0) &&
3085 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
3086 /* private address not in scope */
3093 sin6 = &sctp_ifa->address.sin6;
3094 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
3095 &sin6->sin6_addr) != 0) {
3098 if ((local_scope == 0) &&
3099 (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))) {
3102 if ((site_scope == 0) &&
3103 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
3111 /* check to see if in the init-ack */
3112 if (!sctp_addr_in_initack(m, offset, length, &sctp_ifa->address.sa)) {
3114 sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb,
3115 sctp_ifa, SCTP_ADD_IP_ADDRESS,
3118 } /* end foreach ifa */
3119 } /* end foreach ifn */
3120 SCTP_IPI_ADDR_RUNLOCK();
3124 * validates an init-ack chunk (from a cookie-echo) with current addresses
3125 * adds addresses from the init-ack into our local address list, if needed
3126 * queues asconf adds/deletes addresses as needed and makes appropriate list
3127 * changes for source address selection m, offset: points to the start of the
3128 * address list in an init-ack chunk length: total length of the address
3129 * params only init_addr: address where my INIT-ACK was sent from
3132 sctp_check_address_list(struct sctp_tcb *stcb, struct mbuf *m, int offset,
3133 int length, struct sockaddr *init_addr,
3134 uint16_t local_scope, uint16_t site_scope,
3135 uint16_t ipv4_scope, uint16_t loopback_scope)
3137 /* process the local addresses in the initack */
3138 sctp_process_initack_addresses(stcb, m, offset, length);
3140 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3141 /* bound all case */
3142 sctp_check_address_list_all(stcb, m, offset, length, init_addr,
3143 local_scope, site_scope, ipv4_scope, loopback_scope);
3145 /* subset bound case */
3146 if (sctp_is_feature_on(stcb->sctp_ep,
3147 SCTP_PCB_FLAGS_DO_ASCONF)) {
3148 /* asconf's allowed */
3149 sctp_check_address_list_ep(stcb, m, offset, length,
3152 /* else, no asconfs allowed, so what we sent is what we get */
3157 * sctp_bindx() support
3160 sctp_addr_mgmt_ep_sa(struct sctp_inpcb *inp, struct sockaddr *sa,
3161 uint32_t type, uint32_t vrf_id)
3163 struct sctp_ifa *ifa;
3164 struct sctp_laddr *laddr, *nladdr;
3166 if (sa->sa_len == 0) {
3167 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EINVAL);
3170 if (type == SCTP_ADD_IP_ADDRESS) {
3171 /* For an add the address MUST be on the system */
3172 ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED);
3173 } else if (type == SCTP_DEL_IP_ADDRESS) {
3174 /* For a delete we need to find it in the inp */
3175 ifa = sctp_find_ifa_in_ep(inp, sa, SCTP_ADDR_NOT_LOCKED);
3180 if (type == SCTP_ADD_IP_ADDRESS) {
3181 sctp_add_local_addr_ep(inp, ifa, type);
3182 } else if (type == SCTP_DEL_IP_ADDRESS) {
3183 if (inp->laddr_count < 2) {
3184 /* can't delete the last local address */
3185 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EINVAL);
3188 LIST_FOREACH(laddr, &inp->sctp_addr_list,
3190 if (ifa == laddr->ifa) {
3191 /* Mark in the delete */
3192 laddr->action = type;
3196 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
3198 * There is no need to start the iterator if the inp
3199 * has no associations.
3201 if (type == SCTP_DEL_IP_ADDRESS) {
3202 LIST_FOREACH_SAFE(laddr, &inp->sctp_addr_list, sctp_nxt_addr, nladdr) {
3203 if (laddr->ifa == ifa) {
3204 sctp_del_local_addr_ep(inp, ifa);
3209 struct sctp_asconf_iterator *asc;
3210 struct sctp_laddr *wi;
3213 SCTP_MALLOC(asc, struct sctp_asconf_iterator *,
3214 sizeof(struct sctp_asconf_iterator),
3217 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, ENOMEM);
3220 wi = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_laddr), struct sctp_laddr);
3222 SCTP_FREE(asc, SCTP_M_ASC_IT);
3223 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, ENOMEM);
3226 LIST_INIT(&asc->list_of_work);
3228 SCTP_INCR_LADDR_COUNT();
3231 atomic_add_int(&ifa->refcount, 1);
3232 LIST_INSERT_HEAD(&asc->list_of_work, wi, sctp_nxt_addr);
3233 ret = sctp_initiate_iterator(sctp_asconf_iterator_ep,
3234 sctp_asconf_iterator_stcb,
3235 sctp_asconf_iterator_ep_end,
3237 SCTP_PCB_ANY_FEATURES,
3238 SCTP_ASOC_ANY_STATE,
3240 sctp_asconf_iterator_end, inp, 0);
3242 SCTP_PRINTF("Failed to initiate iterator for addr_mgmt_ep_sa\n");
3243 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EFAULT);
3244 sctp_asconf_iterator_end(asc, 0);
3250 /* invalid address! */
3251 SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EADDRNOTAVAIL);
3252 return (EADDRNOTAVAIL);
3257 sctp_asconf_send_nat_state_update(struct sctp_tcb *stcb, struct sctp_nets *net)
3259 struct sctp_asconf_addr *aa_vtag, *aa_add, *aa_del;
3260 struct sctp_ifa *sctp_ifap;
3261 struct sctp_asconf_tag_param *vtag;
3263 struct sockaddr_in *to;
3266 struct sockaddr_in6 *to6;
3270 SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing net\n");
3274 SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing stcb\n");
3278 * Need to have in the ASCONF: - VTAG(my_vtag/peer_vtag) -
3279 * ADD(wildcard) - DEL(wildcard) - ADD(Any global addresses)
3281 SCTP_MALLOC(aa_vtag, struct sctp_asconf_addr *, sizeof(struct sctp_asconf_addr), SCTP_M_ASC_ADDR);
3282 SCTP_MALLOC(aa_add, struct sctp_asconf_addr *, sizeof(struct sctp_asconf_addr), SCTP_M_ASC_ADDR);
3283 SCTP_MALLOC(aa_del, struct sctp_asconf_addr *, sizeof(struct sctp_asconf_addr), SCTP_M_ASC_ADDR);
3285 if ((aa_vtag == NULL) || (aa_add == NULL) || (aa_del == NULL)) {
3286 /* Didn't get memory */
3287 SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: failed to get memory!\n");
3289 if (aa_vtag != NULL) {
3290 SCTP_FREE(aa_vtag, SCTP_M_ASC_ADDR);
3292 if (aa_add != NULL) {
3293 SCTP_FREE(aa_add, SCTP_M_ASC_ADDR);
3295 if (aa_del != NULL) {
3296 SCTP_FREE(aa_del, SCTP_M_ASC_ADDR);
3300 memset(aa_vtag, 0, sizeof(struct sctp_asconf_addr));
3301 aa_vtag->special_del = 0;
3302 /* Fill in ASCONF address parameter fields. */
3303 /* Top level elements are "networked" during send. */
3304 aa_vtag->ifa = NULL;
3305 aa_vtag->sent = 0; /* clear sent flag */
3306 vtag = (struct sctp_asconf_tag_param *)&aa_vtag->ap.aph;
3307 vtag->aph.ph.param_type = SCTP_NAT_VTAGS;
3308 vtag->aph.ph.param_length = sizeof(struct sctp_asconf_tag_param);
3309 vtag->local_vtag = htonl(stcb->asoc.my_vtag);
3310 vtag->remote_vtag = htonl(stcb->asoc.peer_vtag);
3312 memset(aa_add, 0, sizeof(struct sctp_asconf_addr));
3313 memset(aa_del, 0, sizeof(struct sctp_asconf_addr));
3314 switch (net->ro._l_addr.sa.sa_family) {
3317 aa_add->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
3318 aa_add->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param);
3319 aa_add->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
3320 aa_add->ap.addrp.ph.param_length = sizeof(struct sctp_ipv4addr_param);
3321 /* No need to fill the address, we are using 0.0.0.0 */
3322 aa_del->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
3323 aa_del->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param);
3324 aa_del->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
3325 aa_del->ap.addrp.ph.param_length = sizeof(struct sctp_ipv4addr_param);
3326 /* No need to fill the address, we are using 0.0.0.0 */
3331 aa_add->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
3332 aa_add->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param);
3333 aa_add->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
3334 aa_add->ap.addrp.ph.param_length = sizeof(struct sctp_ipv6addr_param);
3335 /* No need to fill the address, we are using ::0 */
3336 aa_del->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS;
3337 aa_del->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param);
3338 aa_del->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
3339 aa_del->ap.addrp.ph.param_length = sizeof(struct sctp_ipv6addr_param);
3340 /* No need to fill the address, we are using ::0 */
3344 SCTPDBG(SCTP_DEBUG_ASCONF1,
3345 "sctp_asconf_send_nat_state_update: unknown address family %d\n",
3346 net->ro._l_addr.sa.sa_family);
3349 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa_vtag, next);
3350 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa_add, next);
3351 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa_del, next);
3353 /* Now we must hunt the addresses and add all global addresses */
3354 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3355 struct sctp_vrf *vrf = NULL;
3356 struct sctp_ifn *sctp_ifnp;
3359 vrf_id = stcb->sctp_ep->def_vrf_id;
3360 vrf = sctp_find_vrf(vrf_id);
3365 SCTP_IPI_ADDR_RLOCK();
3366 LIST_FOREACH(sctp_ifnp, &vrf->ifnlist, next_ifn) {
3367 LIST_FOREACH(sctp_ifap, &sctp_ifnp->ifalist, next_ifa) {
3368 switch (sctp_ifap->address.sa.sa_family) {
3371 to = &sctp_ifap->address.sin;
3372 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
3373 &to->sin_addr) != 0) {
3376 if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) {
3379 if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) {
3386 to6 = &sctp_ifap->address.sin6;
3387 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
3388 &to6->sin6_addr) != 0) {
3391 if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) {
3394 if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) {
3402 sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS);
3405 SCTP_IPI_ADDR_RUNLOCK();
3407 struct sctp_laddr *laddr;
3409 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
3410 if (laddr->ifa == NULL) {
3413 if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED)
3415 * Address being deleted by the system, dont
3419 if (laddr->action == SCTP_DEL_IP_ADDRESS) {
3421 * Address being deleted on this ep don't
3426 sctp_ifap = laddr->ifa;
3427 switch (sctp_ifap->address.sa.sa_family) {
3430 to = &sctp_ifap->address.sin;
3431 if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) {
3434 if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) {
3441 to6 = &sctp_ifap->address.sin6;
3442 if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) {
3445 if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) {
3453 sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS);
3457 /* Now we must send the asconf into the queue */
3458 sctp_send_asconf(stcb, net, SCTP_ADDR_NOT_LOCKED);