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) {
574 sctp_timer_stop(SCTP_TIMER_TYPE_PRIM_DELETED,
575 stcb->sctp_ep, stcb, NULL,
576 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_1);
577 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
578 SCTP_MOBILITY_FASTHANDOFF)) {
579 sctp_assoc_immediate_retrans(stcb,
580 stcb->asoc.primary_destination);
582 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
583 SCTP_MOBILITY_BASE)) {
584 sctp_move_chunks_from_net(stcb,
585 stcb->asoc.deleted_primary);
587 sctp_delete_prim_timer(stcb->sctp_ep, stcb);
590 /* couldn't set the requested primary address! */
591 SCTPDBG(SCTP_DEBUG_ASCONF1,
592 "process_asconf_set_primary: set primary failed!\n");
593 /* must have been an invalid address, so report */
594 m_reply = sctp_asconf_error_response(aph->correlation_id,
595 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *)aph,
603 * handles an ASCONF chunk.
604 * if all parameters are processed ok, send a plain (empty) ASCONF-ACK
607 sctp_handle_asconf(struct mbuf *m, unsigned int offset,
608 struct sockaddr *src,
609 struct sctp_asconf_chunk *cp, struct sctp_tcb *stcb,
612 struct sctp_association *asoc;
614 struct mbuf *n, *m_ack, *m_result, *m_tail;
615 struct sctp_asconf_ack_chunk *ack_cp;
616 struct sctp_asconf_paramhdr *aph;
617 struct sctp_ipv6addr_param *p_addr;
618 unsigned int asconf_limit, cnt;
619 int error = 0; /* did an error occur? */
621 /* asconf param buffer */
622 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE];
623 struct sctp_asconf_ack *ack, *ack_next;
625 /* verify minimum length */
626 if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_chunk)) {
627 SCTPDBG(SCTP_DEBUG_ASCONF1,
628 "handle_asconf: chunk too small = %xh\n",
629 ntohs(cp->ch.chunk_length));
633 serial_num = ntohl(cp->serial_number);
635 if (SCTP_TSN_GE(asoc->asconf_seq_in, serial_num)) {
636 /* got a duplicate ASCONF */
637 SCTPDBG(SCTP_DEBUG_ASCONF1,
638 "handle_asconf: got duplicate serial number = %xh\n",
641 } else if (serial_num != (asoc->asconf_seq_in + 1)) {
642 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: incorrect serial number = %xh (expected next = %xh)\n",
643 serial_num, asoc->asconf_seq_in + 1);
647 /* it's the expected "next" sequence number, so process it */
648 asoc->asconf_seq_in = serial_num; /* update sequence */
649 /* get length of all the param's in the ASCONF */
650 asconf_limit = offset + ntohs(cp->ch.chunk_length);
651 SCTPDBG(SCTP_DEBUG_ASCONF1,
652 "handle_asconf: asconf_limit=%u, sequence=%xh\n",
653 asconf_limit, serial_num);
656 /* delete old cache */
657 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: Now processing first ASCONF. Try to delete old cache\n");
659 TAILQ_FOREACH_SAFE(ack, &asoc->asconf_ack_sent, next, ack_next) {
660 if (ack->serial_number == serial_num)
662 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: delete old(%u) < first(%u)\n",
663 ack->serial_number, serial_num);
664 TAILQ_REMOVE(&asoc->asconf_ack_sent, ack, next);
665 if (ack->data != NULL) {
666 sctp_m_freem(ack->data);
668 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_asconf_ack), ack);
672 m_ack = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_ack_chunk), 0,
673 M_NOWAIT, 1, MT_DATA);
675 SCTPDBG(SCTP_DEBUG_ASCONF1,
676 "handle_asconf: couldn't get mbuf!\n");
679 m_tail = m_ack; /* current reply chain's tail */
681 /* fill in ASCONF-ACK header */
682 ack_cp = mtod(m_ack, struct sctp_asconf_ack_chunk *);
683 ack_cp->ch.chunk_type = SCTP_ASCONF_ACK;
684 ack_cp->ch.chunk_flags = 0;
685 ack_cp->serial_number = htonl(serial_num);
686 /* set initial lengths (eg. just an ASCONF-ACK), ntohx at the end! */
687 SCTP_BUF_LEN(m_ack) = sizeof(struct sctp_asconf_ack_chunk);
688 ack_cp->ch.chunk_length = sizeof(struct sctp_asconf_ack_chunk);
690 /* skip the lookup address parameter */
691 offset += sizeof(struct sctp_asconf_chunk);
692 p_addr = (struct sctp_ipv6addr_param *)sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), (uint8_t *)&aparam_buf);
693 if (p_addr == NULL) {
694 SCTPDBG(SCTP_DEBUG_ASCONF1,
695 "handle_asconf: couldn't get lookup addr!\n");
696 /* respond with a missing/invalid mandatory parameter error */
700 /* skip lookup addr */
701 offset += SCTP_SIZE32(ntohs(p_addr->ph.param_length));
702 /* get pointer to first asconf param in ASCONF */
703 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, sizeof(struct sctp_asconf_paramhdr), (uint8_t *)&aparam_buf);
705 SCTPDBG(SCTP_DEBUG_ASCONF1, "Empty ASCONF received?\n");
708 /* process through all parameters */
710 while (aph != NULL) {
711 unsigned int param_length, param_type;
713 param_type = ntohs(aph->ph.param_type);
714 param_length = ntohs(aph->ph.param_length);
715 if (offset + param_length > asconf_limit) {
716 /* parameter goes beyond end of chunk! */
722 if (param_length > sizeof(aparam_buf)) {
723 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) larger than buffer size!\n", param_length);
727 if (param_length <= sizeof(struct sctp_paramhdr)) {
728 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) too short\n", param_length);
732 /* get the entire parameter */
733 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf);
735 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: couldn't get entire param\n");
739 switch (param_type) {
740 case SCTP_ADD_IP_ADDRESS:
741 m_result = sctp_process_asconf_add_ip(src, aph, stcb,
742 (cnt < SCTP_BASE_SYSCTL(sctp_hb_maxburst)), error);
745 case SCTP_DEL_IP_ADDRESS:
746 m_result = sctp_process_asconf_delete_ip(src, aph, stcb,
749 case SCTP_ERROR_CAUSE_IND:
750 /* not valid in an ASCONF chunk */
752 case SCTP_SET_PRIM_ADDR:
753 m_result = sctp_process_asconf_set_primary(src, aph,
757 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: sees a NAT VTAG state parameter\n");
759 case SCTP_SUCCESS_REPORT:
760 /* not valid in an ASCONF chunk */
762 case SCTP_ULP_ADAPTATION:
766 if ((param_type & 0x8000) == 0) {
767 /* Been told to STOP at this param */
768 asconf_limit = offset;
770 * FIX FIX - We need to call
771 * sctp_arethere_unrecognized_parameters()
772 * to get a operr and send it for any
773 * param's with the 0x4000 bit set OR do it
774 * here ourselves... note we still must STOP
775 * if the 0x8000 bit is clear.
778 /* unknown/invalid param type */
782 /* add any (error) result to the reply mbuf chain */
783 if (m_result != NULL) {
784 SCTP_BUF_NEXT(m_tail) = m_result;
786 ack_cp->ch.chunk_length += SCTP_BUF_LEN(m_result);
787 /* set flag to force success reports */
790 offset += SCTP_SIZE32(param_length);
791 /* update remaining ASCONF message length to process */
792 if (offset >= asconf_limit) {
793 /* no more data in the mbuf chain */
796 /* get pointer to next asconf param */
797 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset,
798 sizeof(struct sctp_asconf_paramhdr),
799 (uint8_t *)&aparam_buf);
801 /* can't get an asconf paramhdr */
802 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: can't get asconf param hdr!\n");
803 /* FIX ME - add error here... */
808 ack_cp->ch.chunk_length = htons(ack_cp->ch.chunk_length);
809 /* save the ASCONF-ACK reply */
810 ack = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_asconf_ack),
811 struct sctp_asconf_ack);
816 ack->serial_number = serial_num;
817 ack->last_sent_to = NULL;
820 for (n = m_ack; n != NULL; n = SCTP_BUF_NEXT(n)) {
821 ack->len += SCTP_BUF_LEN(n);
823 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_ack_sent, ack, next);
825 /* see if last_control_chunk_from is set properly (use IP src addr) */
826 if (stcb->asoc.last_control_chunk_from == NULL) {
828 * this could happen if the source address was just newly
831 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: looking up net for IP source address\n");
832 SCTPDBG(SCTP_DEBUG_ASCONF1, "Looking for IP source: ");
833 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, src);
834 /* look up the from address */
835 stcb->asoc.last_control_chunk_from = sctp_findnet(stcb, src);
837 if (stcb->asoc.last_control_chunk_from == NULL) {
838 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: IP source address not found?!\n");
845 * does the address match? returns 0 if not, 1 if so
848 sctp_asconf_addr_match(struct sctp_asconf_addr *aa, struct sockaddr *sa)
850 switch (sa->sa_family) {
855 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
857 if ((aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) &&
858 (memcmp(&aa->ap.addrp.addr, &sin6->sin6_addr,
859 sizeof(struct in6_addr)) == 0)) {
868 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
870 if ((aa->ap.addrp.ph.param_type == SCTP_IPV4_ADDRESS) &&
871 (memcmp(&aa->ap.addrp.addr, &sin->sin_addr,
872 sizeof(struct in_addr)) == 0)) {
885 * does the address match? returns 0 if not, 1 if so
888 sctp_addr_match(struct sctp_paramhdr *ph, struct sockaddr *sa)
890 #if defined(INET) || defined(INET6)
891 uint16_t param_type, param_length;
893 param_type = ntohs(ph->param_type);
894 param_length = ntohs(ph->param_length);
896 switch (sa->sa_family) {
901 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
902 struct sctp_ipv6addr_param *v6addr;
904 v6addr = (struct sctp_ipv6addr_param *)ph;
905 if ((param_type == SCTP_IPV6_ADDRESS) &&
906 (param_length == sizeof(struct sctp_ipv6addr_param)) &&
907 (memcmp(&v6addr->addr, &sin6->sin6_addr,
908 sizeof(struct in6_addr)) == 0)) {
917 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
918 struct sctp_ipv4addr_param *v4addr;
920 v4addr = (struct sctp_ipv4addr_param *)ph;
921 if ((param_type == SCTP_IPV4_ADDRESS) &&
922 (param_length == sizeof(struct sctp_ipv4addr_param)) &&
923 (memcmp(&v4addr->addr, &sin->sin_addr,
924 sizeof(struct in_addr)) == 0)) {
937 * Cleanup for non-responded/OP ERR'd ASCONF
940 sctp_asconf_cleanup(struct sctp_tcb *stcb)
943 * clear out any existing asconfs going out
945 sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, NULL,
946 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_2);
947 stcb->asoc.asconf_seq_out_acked = stcb->asoc.asconf_seq_out;
948 /* remove the old ASCONF on our outbound queue */
949 sctp_toss_old_asconf(stcb);
953 * cleanup any cached source addresses that may be topologically
954 * incorrect after a new address has been added to this interface.
957 sctp_asconf_nets_cleanup(struct sctp_tcb *stcb, struct sctp_ifn *ifn)
959 struct sctp_nets *net;
962 * Ideally, we want to only clear cached routes and source addresses
963 * that are topologically incorrect. But since there is no easy way
964 * to know whether the newly added address on the ifn would cause a
965 * routing change (i.e. a new egress interface would be chosen)
966 * without doing a new routing lookup and source address selection,
967 * we will (for now) just flush any cached route using a different
968 * ifn (and cached source addrs) and let output re-choose them
969 * during the next send on that net.
971 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
973 * clear any cached route (and cached source address) if the
974 * route's interface is NOT the same as the address change.
975 * If it's the same interface, just clear the cached source
978 if (SCTP_ROUTE_HAS_VALID_IFN(&net->ro) &&
980 (SCTP_GET_IF_INDEX_FROM_ROUTE(&net->ro) != ifn->ifn_index))) {
981 /* clear any cached route */
984 /* clear any cached source address */
985 if (net->src_addr_selected) {
986 sctp_free_ifa(net->ro._s_addr);
987 net->ro._s_addr = NULL;
988 net->src_addr_selected = 0;
995 sctp_assoc_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *dstnet)
999 if (dstnet->dest_state & SCTP_ADDR_UNCONFIRMED) {
1002 if (stcb->asoc.deleted_primary == NULL) {
1006 if (!TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
1007 SCTPDBG(SCTP_DEBUG_ASCONF1, "assoc_immediate_retrans: Deleted primary is ");
1008 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &stcb->asoc.deleted_primary->ro._l_addr.sa);
1009 SCTPDBG(SCTP_DEBUG_ASCONF1, "Current Primary is ");
1010 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &stcb->asoc.primary_destination->ro._l_addr.sa);
1011 sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb,
1012 stcb->asoc.deleted_primary,
1013 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_3);
1014 stcb->asoc.num_send_timers_up--;
1015 if (stcb->asoc.num_send_timers_up < 0) {
1016 stcb->asoc.num_send_timers_up = 0;
1018 SCTP_TCB_LOCK_ASSERT(stcb);
1019 error = sctp_t3rxt_timer(stcb->sctp_ep, stcb,
1020 stcb->asoc.deleted_primary);
1022 SCTP_INP_DECR_REF(stcb->sctp_ep);
1025 SCTP_TCB_LOCK_ASSERT(stcb);
1026 #ifdef SCTP_AUDITING_ENABLED
1027 sctp_auditing(4, stcb->sctp_ep, stcb, stcb->asoc.deleted_primary);
1029 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED);
1030 if ((stcb->asoc.num_send_timers_up == 0) &&
1031 (stcb->asoc.sent_queue_cnt > 0)) {
1032 struct sctp_tmit_chunk *chk;
1034 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
1035 if (chk->whoTo != NULL) {
1040 sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, chk->whoTo);
1048 sctp_asconf_queue_mgmt(struct sctp_tcb *, struct sctp_ifa *, uint16_t);
1051 sctp_net_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *net)
1053 struct sctp_tmit_chunk *chk;
1055 SCTPDBG(SCTP_DEBUG_ASCONF1, "net_immediate_retrans: RTO is %d\n", net->RTO);
1056 sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, net,
1057 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_4);
1058 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
1059 net->error_count = 0;
1060 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
1061 if (chk->whoTo == net) {
1062 if (chk->sent < SCTP_DATAGRAM_RESEND) {
1063 chk->sent = SCTP_DATAGRAM_RESEND;
1064 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
1065 sctp_flight_size_decrease(chk);
1066 sctp_total_flight_decrease(stcb, chk);
1067 net->marked_retrans++;
1068 stcb->asoc.marked_retrans++;
1072 if (net->marked_retrans) {
1073 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED);
1078 sctp_path_check_and_react(struct sctp_tcb *stcb, struct sctp_ifa *newifa)
1080 struct sctp_nets *net;
1081 int addrnum, changed;
1084 * If number of local valid addresses is 1, the valid address is
1085 * probably newly added address. Several valid addresses in this
1086 * association. A source address may not be changed. Additionally,
1087 * they can be configured on a same interface as "alias" addresses.
1090 addrnum = sctp_local_addr_count(stcb);
1091 SCTPDBG(SCTP_DEBUG_ASCONF1, "p_check_react(): %d local addresses\n",
1094 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1095 /* clear any cached route and source address */
1096 RO_NHFREE(&net->ro);
1097 if (net->src_addr_selected) {
1098 sctp_free_ifa(net->ro._s_addr);
1099 net->ro._s_addr = NULL;
1100 net->src_addr_selected = 0;
1102 /* Retransmit unacknowledged DATA chunks immediately */
1103 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
1104 SCTP_MOBILITY_FASTHANDOFF)) {
1105 sctp_net_immediate_retrans(stcb, net);
1107 /* also, SET PRIMARY is maybe already sent */
1112 /* Multiple local addresses exsist in the association. */
1113 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1114 /* clear any cached route and source address */
1115 RO_NHFREE(&net->ro);
1116 if (net->src_addr_selected) {
1117 sctp_free_ifa(net->ro._s_addr);
1118 net->ro._s_addr = NULL;
1119 net->src_addr_selected = 0;
1122 * Check if the nexthop is corresponding to the new address.
1123 * If the new address is corresponding to the current
1124 * nexthop, the path will be changed. If the new address is
1125 * NOT corresponding to the current nexthop, the path will
1128 SCTP_RTALLOC((sctp_route_t *)&net->ro,
1129 stcb->sctp_ep->def_vrf_id,
1130 stcb->sctp_ep->fibnum);
1131 if (net->ro.ro_nh == NULL)
1135 switch (net->ro._l_addr.sa.sa_family) {
1138 if (sctp_v4src_match_nexthop(newifa, (sctp_route_t *)&net->ro)) {
1145 if (sctp_v6src_match_nexthop(
1146 &newifa->address.sin6, (sctp_route_t *)&net->ro)) {
1155 * if the newly added address does not relate routing
1156 * information, we skip.
1160 /* Retransmit unacknowledged DATA chunks immediately */
1161 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
1162 SCTP_MOBILITY_FASTHANDOFF)) {
1163 sctp_net_immediate_retrans(stcb, net);
1165 /* Send SET PRIMARY for this new address */
1166 if (net == stcb->asoc.primary_destination) {
1167 (void)sctp_asconf_queue_mgmt(stcb, newifa,
1168 SCTP_SET_PRIM_ADDR);
1174 * process an ADD/DELETE IP ack from peer.
1175 * addr: corresponding sctp_ifa to the address being added/deleted.
1176 * type: SCTP_ADD_IP_ADDRESS or SCTP_DEL_IP_ADDRESS.
1177 * flag: 1=success, 0=failure.
1180 sctp_asconf_addr_mgmt_ack(struct sctp_tcb *stcb, struct sctp_ifa *addr, uint32_t flag)
1183 * do the necessary asoc list work- if we get a failure indication,
1184 * leave the address on the assoc's restricted list. If we get a
1185 * success indication, remove the address from the restricted list.
1188 * Note: this will only occur for ADD_IP_ADDRESS, since
1189 * DEL_IP_ADDRESS is never actually added to the list...
1192 /* success case, so remove from the restricted list */
1193 sctp_del_local_addr_restricted(stcb, addr);
1195 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
1196 SCTP_MOBILITY_BASE) ||
1197 sctp_is_mobility_feature_on(stcb->sctp_ep,
1198 SCTP_MOBILITY_FASTHANDOFF)) {
1199 sctp_path_check_and_react(stcb, addr);
1202 /* clear any cached/topologically incorrect source addresses */
1203 sctp_asconf_nets_cleanup(stcb, addr->ifn_p);
1205 /* else, leave it on the list */
1209 * add an asconf add/delete/set primary IP address parameter to the queue.
1210 * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR.
1211 * returns 0 if queued, -1 if not queued/removed.
1212 * NOTE: if adding, but a delete for the same address is already scheduled
1213 * (and not yet sent out), simply remove it from queue. Same for deleting
1214 * an address already scheduled for add. If a duplicate operation is found,
1215 * ignore the new one.
1218 sctp_asconf_queue_mgmt(struct sctp_tcb *stcb, struct sctp_ifa *ifa,
1221 struct sctp_asconf_addr *aa, *aa_next;
1223 /* make sure the request isn't already in the queue */
1224 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) {
1225 /* address match? */
1226 if (sctp_asconf_addr_match(aa, &ifa->address.sa) == 0)
1229 * is the request already in queue but not sent? pass the
1230 * request already sent in order to resolve the following
1231 * case: 1. arrival of ADD, then sent 2. arrival of DEL. we
1232 * can't remove the ADD request already sent 3. arrival of
1235 if (aa->ap.aph.ph.param_type == type && aa->sent == 0) {
1238 /* is the negative request already in queue, and not sent */
1239 if ((aa->sent == 0) && (type == SCTP_ADD_IP_ADDRESS) &&
1240 (aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS)) {
1241 /* add requested, delete already queued */
1242 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1243 /* remove the ifa from the restricted list */
1244 sctp_del_local_addr_restricted(stcb, ifa);
1245 /* free the asconf param */
1246 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1247 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_mgmt: add removes queued entry\n");
1250 if ((aa->sent == 0) && (type == SCTP_DEL_IP_ADDRESS) &&
1251 (aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS)) {
1252 /* delete requested, add already queued */
1253 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1254 /* remove the aa->ifa from the restricted list */
1255 sctp_del_local_addr_restricted(stcb, aa->ifa);
1256 /* free the asconf param */
1257 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1258 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_mgmt: delete removes queued entry\n");
1263 /* adding new request to the queue */
1264 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
1267 /* didn't get memory */
1268 SCTPDBG(SCTP_DEBUG_ASCONF1, "asconf_queue_mgmt: failed to get memory!\n");
1271 aa->special_del = 0;
1272 /* fill in asconf address parameter fields */
1273 /* top level elements are "networked" during send */
1274 aa->ap.aph.ph.param_type = type;
1276 atomic_add_int(&ifa->refcount, 1);
1277 /* correlation_id filled in during send routine later... */
1278 switch (ifa->address.sa.sa_family) {
1282 struct sockaddr_in6 *sin6;
1284 sin6 = &ifa->address.sin6;
1285 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
1286 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param));
1287 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) +
1288 sizeof(struct sctp_ipv6addr_param);
1289 memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr,
1290 sizeof(struct in6_addr));
1297 struct sockaddr_in *sin;
1299 sin = &ifa->address.sin;
1300 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
1301 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param));
1302 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) +
1303 sizeof(struct sctp_ipv4addr_param);
1304 memcpy(&aa->ap.addrp.addr, &sin->sin_addr,
1305 sizeof(struct in_addr));
1310 /* invalid family! */
1311 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1315 aa->sent = 0; /* clear sent flag */
1317 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
1319 if (SCTP_BASE_SYSCTL(sctp_debug_on) & SCTP_DEBUG_ASCONF2) {
1320 if (type == SCTP_ADD_IP_ADDRESS) {
1321 SCTP_PRINTF("asconf_queue_mgmt: inserted asconf ADD_IP_ADDRESS: ");
1322 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa);
1323 } else if (type == SCTP_DEL_IP_ADDRESS) {
1324 SCTP_PRINTF("asconf_queue_mgmt: appended asconf DEL_IP_ADDRESS: ");
1325 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa);
1327 SCTP_PRINTF("asconf_queue_mgmt: appended asconf SET_PRIM_ADDR: ");
1328 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa);
1338 * add an asconf operation for the given ifa and type.
1339 * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR.
1340 * returns 0 if completed, -1 if not completed, 1 if immediate send is
1344 sctp_asconf_queue_add(struct sctp_tcb *stcb, struct sctp_ifa *ifa,
1348 int pending_delete_queued = 0;
1351 /* see if peer supports ASCONF */
1352 if (stcb->asoc.asconf_supported == 0) {
1357 * if this is deleting the last address from the assoc, mark it as
1360 if ((type == SCTP_DEL_IP_ADDRESS) && !stcb->asoc.asconf_del_pending) {
1361 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1362 last = (sctp_local_addr_count(stcb) == 0);
1364 last = (sctp_local_addr_count(stcb) == 1);
1367 /* set the pending delete info only */
1368 stcb->asoc.asconf_del_pending = 1;
1369 stcb->asoc.asconf_addr_del_pending = ifa;
1370 atomic_add_int(&ifa->refcount, 1);
1371 SCTPDBG(SCTP_DEBUG_ASCONF2,
1372 "asconf_queue_add: mark delete last address pending\n");
1377 /* queue an asconf parameter */
1378 status = sctp_asconf_queue_mgmt(stcb, ifa, type);
1381 * if this is an add, and there is a delete also pending (i.e. the
1382 * last local address is being changed), queue the pending delete
1385 if ((type == SCTP_ADD_IP_ADDRESS) && stcb->asoc.asconf_del_pending && (status == 0)) {
1386 /* queue in the pending delete */
1387 if (sctp_asconf_queue_mgmt(stcb,
1388 stcb->asoc.asconf_addr_del_pending,
1389 SCTP_DEL_IP_ADDRESS) == 0) {
1390 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_add: queuing pending delete\n");
1391 pending_delete_queued = 1;
1392 /* clear out the pending delete info */
1393 stcb->asoc.asconf_del_pending = 0;
1394 sctp_free_ifa(stcb->asoc.asconf_addr_del_pending);
1395 stcb->asoc.asconf_addr_del_pending = NULL;
1399 if (pending_delete_queued) {
1400 struct sctp_nets *net;
1403 * since we know that the only/last address is now being
1404 * changed in this case, reset the cwnd/rto on all nets to
1405 * start as a new address and path. Also clear the error
1406 * counts to give the assoc the best chance to complete the
1409 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1410 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb,
1413 net->error_count = 0;
1415 stcb->asoc.overall_error_count = 0;
1416 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) {
1417 sctp_misc_ints(SCTP_THRESHOLD_CLEAR,
1418 stcb->asoc.overall_error_count,
1420 SCTP_FROM_SCTP_ASCONF,
1424 /* queue in an advisory set primary too */
1425 (void)sctp_asconf_queue_mgmt(stcb, ifa, SCTP_SET_PRIM_ADDR);
1426 /* let caller know we should send this out immediately */
1433 * add an asconf delete IP address parameter to the queue by sockaddr and
1434 * possibly with no sctp_ifa available. This is only called by the routine
1435 * that checks the addresses in an INIT-ACK against the current address list.
1436 * returns 0 if completed, non-zero if not completed.
1437 * NOTE: if an add is already scheduled (and not yet sent out), simply
1438 * remove it from queue. If a duplicate operation is found, ignore the
1442 sctp_asconf_queue_sa_delete(struct sctp_tcb *stcb, struct sockaddr *sa)
1444 struct sctp_ifa *ifa;
1445 struct sctp_asconf_addr *aa, *aa_next;
1450 /* see if peer supports ASCONF */
1451 if (stcb->asoc.asconf_supported == 0) {
1454 /* make sure the request isn't already in the queue */
1455 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) {
1456 /* address match? */
1457 if (sctp_asconf_addr_match(aa, sa) == 0)
1459 /* is the request already in queue (sent or not) */
1460 if (aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) {
1463 /* is the negative request already in queue, and not sent */
1466 if (aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS) {
1467 /* add already queued, so remove existing entry */
1468 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1469 sctp_del_local_addr_restricted(stcb, aa->ifa);
1470 /* free the entry */
1471 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1476 /* find any existing ifa-- NOTE ifa CAN be allowed to be NULL */
1477 ifa = sctp_find_ifa_by_addr(sa, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
1479 /* adding new request to the queue */
1480 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
1483 /* didn't get memory */
1484 SCTPDBG(SCTP_DEBUG_ASCONF1,
1485 "sctp_asconf_queue_sa_delete: failed to get memory!\n");
1488 aa->special_del = 0;
1489 /* fill in asconf address parameter fields */
1490 /* top level elements are "networked" during send */
1491 aa->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS;
1494 atomic_add_int(&ifa->refcount, 1);
1495 /* correlation_id filled in during send routine later... */
1496 switch (sa->sa_family) {
1501 struct sockaddr_in6 *sin6;
1503 sin6 = (struct sockaddr_in6 *)sa;
1504 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
1505 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param));
1506 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv6addr_param);
1507 memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr,
1508 sizeof(struct in6_addr));
1516 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
1518 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
1519 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param));
1520 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv4addr_param);
1521 memcpy(&aa->ap.addrp.addr, &sin->sin_addr,
1522 sizeof(struct in_addr));
1527 /* invalid family! */
1528 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1533 aa->sent = 0; /* clear sent flag */
1535 /* delete goes to the back of the queue */
1536 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
1538 /* sa_ignore MEMLEAK {memory is put on the tailq} */
1543 * find a specific asconf param on our "sent" queue
1545 static struct sctp_asconf_addr *
1546 sctp_asconf_find_param(struct sctp_tcb *stcb, uint32_t correlation_id)
1548 struct sctp_asconf_addr *aa;
1550 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
1551 if (aa->ap.aph.correlation_id == correlation_id &&
1557 /* didn't find it */
1562 * process an SCTP_ERROR_CAUSE_IND for a ASCONF-ACK parameter and do
1563 * notifications based on the error response
1566 sctp_asconf_process_error(struct sctp_tcb *stcb SCTP_UNUSED,
1567 struct sctp_asconf_paramhdr *aph)
1569 struct sctp_error_cause *eh;
1570 struct sctp_paramhdr *ph;
1571 uint16_t param_type;
1572 uint16_t error_code;
1574 eh = (struct sctp_error_cause *)(aph + 1);
1575 ph = (struct sctp_paramhdr *)(eh + 1);
1576 /* validate lengths */
1577 if (htons(eh->length) + sizeof(struct sctp_error_cause) >
1578 htons(aph->ph.param_length)) {
1579 /* invalid error cause length */
1580 SCTPDBG(SCTP_DEBUG_ASCONF1,
1581 "asconf_process_error: cause element too long\n");
1584 if (htons(ph->param_length) + sizeof(struct sctp_paramhdr) >
1585 htons(eh->length)) {
1586 /* invalid included TLV length */
1587 SCTPDBG(SCTP_DEBUG_ASCONF1,
1588 "asconf_process_error: included TLV too long\n");
1591 /* which error code ? */
1592 error_code = ntohs(eh->code);
1593 param_type = ntohs(aph->ph.param_type);
1594 /* FIX: this should go back up the REMOTE_ERROR ULP notify */
1595 switch (error_code) {
1596 case SCTP_CAUSE_RESOURCE_SHORTAGE:
1597 /* we allow ourselves to "try again" for this error */
1600 /* peer can't handle it... */
1601 switch (param_type) {
1602 case SCTP_ADD_IP_ADDRESS:
1603 case SCTP_DEL_IP_ADDRESS:
1604 case SCTP_SET_PRIM_ADDR:
1613 * process an asconf queue param.
1614 * aparam: parameter to process, will be removed from the queue.
1615 * flag: 1=success case, 0=failure case
1618 sctp_asconf_process_param_ack(struct sctp_tcb *stcb,
1619 struct sctp_asconf_addr *aparam, uint32_t flag)
1621 uint16_t param_type;
1623 /* process this param */
1624 param_type = aparam->ap.aph.ph.param_type;
1625 switch (param_type) {
1626 case SCTP_ADD_IP_ADDRESS:
1627 SCTPDBG(SCTP_DEBUG_ASCONF1,
1628 "process_param_ack: added IP address\n");
1629 sctp_asconf_addr_mgmt_ack(stcb, aparam->ifa, flag);
1631 case SCTP_DEL_IP_ADDRESS:
1632 SCTPDBG(SCTP_DEBUG_ASCONF1,
1633 "process_param_ack: deleted IP address\n");
1634 /* nothing really to do... lists already updated */
1636 case SCTP_SET_PRIM_ADDR:
1637 SCTPDBG(SCTP_DEBUG_ASCONF1,
1638 "process_param_ack: set primary IP address\n");
1639 /* nothing to do... peer may start using this addr */
1642 /* should NEVER happen */
1646 /* remove the param and free it */
1647 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aparam, next);
1649 sctp_free_ifa(aparam->ifa);
1650 SCTP_FREE(aparam, SCTP_M_ASC_ADDR);
1654 * cleanup from a bad asconf ack parameter
1657 sctp_asconf_ack_clear(struct sctp_tcb *stcb SCTP_UNUSED)
1659 /* assume peer doesn't really know how to do asconfs */
1660 /* XXX we could free the pending queue here */
1665 sctp_handle_asconf_ack(struct mbuf *m, int offset,
1666 struct sctp_asconf_ack_chunk *cp, struct sctp_tcb *stcb,
1667 struct sctp_nets *net, int *abort_no_unlock)
1669 struct sctp_association *asoc;
1670 uint32_t serial_num;
1671 uint16_t ack_length;
1672 struct sctp_asconf_paramhdr *aph;
1673 struct sctp_asconf_addr *aa, *aa_next;
1674 uint32_t last_error_id = 0; /* last error correlation id */
1676 struct sctp_asconf_addr *ap;
1678 /* asconf param buffer */
1679 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE];
1681 /* verify minimum length */
1682 if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_ack_chunk)) {
1683 SCTPDBG(SCTP_DEBUG_ASCONF1,
1684 "handle_asconf_ack: chunk too small = %xh\n",
1685 ntohs(cp->ch.chunk_length));
1689 serial_num = ntohl(cp->serial_number);
1692 * NOTE: we may want to handle this differently- currently, we will
1693 * abort when we get an ack for the expected serial number + 1 (eg.
1694 * we didn't send it), process an ack normally if it is the expected
1695 * serial number, and re-send the previous ack for *ALL* other
1700 * if the serial number is the next expected, but I didn't send it,
1701 * abort the asoc, since someone probably just hijacked us...
1703 if (serial_num == (asoc->asconf_seq_out + 1)) {
1704 struct mbuf *op_err;
1705 char msg[SCTP_DIAG_INFO_LEN];
1707 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got unexpected next serial number! Aborting asoc!\n");
1708 SCTP_SNPRINTF(msg, sizeof(msg), "Never sent serial number %8.8x", serial_num);
1709 op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
1710 sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
1711 *abort_no_unlock = 1;
1714 if (serial_num != asoc->asconf_seq_out_acked + 1) {
1715 /* got a duplicate/unexpected ASCONF-ACK */
1716 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got duplicate/unexpected serial number = %xh (expected = %xh)\n",
1717 serial_num, asoc->asconf_seq_out_acked + 1);
1721 if (serial_num == asoc->asconf_seq_out - 1) {
1722 /* stop our timer */
1723 sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, NULL,
1724 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_5);
1727 /* process the ASCONF-ACK contents */
1728 ack_length = ntohs(cp->ch.chunk_length) -
1729 sizeof(struct sctp_asconf_ack_chunk);
1730 offset += sizeof(struct sctp_asconf_ack_chunk);
1731 /* process through all parameters */
1732 while (ack_length >= sizeof(struct sctp_asconf_paramhdr)) {
1733 unsigned int param_length, param_type;
1735 /* get pointer to next asconf parameter */
1736 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset,
1737 sizeof(struct sctp_asconf_paramhdr), aparam_buf);
1739 /* can't get an asconf paramhdr */
1740 sctp_asconf_ack_clear(stcb);
1743 param_type = ntohs(aph->ph.param_type);
1744 param_length = ntohs(aph->ph.param_length);
1745 if (param_length > ack_length) {
1746 sctp_asconf_ack_clear(stcb);
1749 if (param_length < sizeof(struct sctp_paramhdr)) {
1750 sctp_asconf_ack_clear(stcb);
1753 /* get the complete parameter... */
1754 if (param_length > sizeof(aparam_buf)) {
1755 SCTPDBG(SCTP_DEBUG_ASCONF1,
1756 "param length (%u) larger than buffer size!\n", param_length);
1757 sctp_asconf_ack_clear(stcb);
1760 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf);
1762 sctp_asconf_ack_clear(stcb);
1765 /* correlation_id is transparent to peer, no ntohl needed */
1766 id = aph->correlation_id;
1768 switch (param_type) {
1769 case SCTP_ERROR_CAUSE_IND:
1771 /* find the corresponding asconf param in our queue */
1772 ap = sctp_asconf_find_param(stcb, id);
1774 /* hmm... can't find this in our queue! */
1777 /* process the parameter, failed flag */
1778 sctp_asconf_process_param_ack(stcb, ap, 0);
1779 /* process the error response */
1780 sctp_asconf_process_error(stcb, aph);
1782 case SCTP_SUCCESS_REPORT:
1783 /* find the corresponding asconf param in our queue */
1784 ap = sctp_asconf_find_param(stcb, id);
1786 /* hmm... can't find this in our queue! */
1789 /* process the parameter, success flag */
1790 sctp_asconf_process_param_ack(stcb, ap, 1);
1796 /* update remaining ASCONF-ACK message length to process */
1797 if (ack_length > SCTP_SIZE32(param_length)) {
1798 ack_length -= SCTP_SIZE32(param_length);
1802 offset += SCTP_SIZE32(param_length);
1806 * if there are any "sent" params still on the queue, these are
1807 * implicitly "success", or "failed" (if we got an error back) ...
1808 * so process these appropriately
1810 * we assume that the correlation_id's are monotonically increasing
1811 * beginning from 1 and that we don't have *that* many outstanding
1814 if (last_error_id == 0)
1815 last_error_id--; /* set to "max" value */
1816 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) {
1817 if (aa->sent == 1) {
1819 * implicitly successful or failed if correlation_id
1820 * < last_error_id, then success else, failure
1822 if (aa->ap.aph.correlation_id < last_error_id)
1823 sctp_asconf_process_param_ack(stcb, aa, 1);
1825 sctp_asconf_process_param_ack(stcb, aa, 0);
1828 * since we always process in order (FIFO queue) if
1829 * we reach one that hasn't been sent, the rest
1830 * should not have been sent either. so, we're
1837 /* update the next sequence number to use */
1838 asoc->asconf_seq_out_acked++;
1839 /* remove the old ASCONF on our outbound queue */
1840 sctp_toss_old_asconf(stcb);
1841 if (!TAILQ_EMPTY(&stcb->asoc.asconf_queue)) {
1842 #ifdef SCTP_TIMER_BASED_ASCONF
1843 /* we have more params, so restart our timer */
1844 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep,
1847 /* we have more params, so send out more */
1848 sctp_send_asconf(stcb, net, SCTP_ADDR_NOT_LOCKED);
1855 sctp_is_scopeid_in_nets(struct sctp_tcb *stcb, struct sockaddr *sa)
1857 struct sockaddr_in6 *sin6, *net6;
1858 struct sctp_nets *net;
1860 if (sa->sa_family != AF_INET6) {
1864 sin6 = (struct sockaddr_in6 *)sa;
1865 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) == 0) {
1866 /* not link local address */
1869 /* hunt through our destination nets list for this scope_id */
1870 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1871 if (((struct sockaddr *)(&net->ro._l_addr))->sa_family !=
1874 net6 = (struct sockaddr_in6 *)&net->ro._l_addr;
1875 if (IN6_IS_ADDR_LINKLOCAL(&net6->sin6_addr) == 0)
1877 if (sctp_is_same_scope(sin6, net6)) {
1882 /* didn't find one */
1888 * address management functions
1891 sctp_addr_mgmt_assoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
1892 struct sctp_ifa *ifa, uint16_t type, int addr_locked)
1896 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0 ||
1897 sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_ASCONF)) {
1898 /* subset bound, no ASCONF allowed case, so ignore */
1902 * note: we know this is not the subset bound, no ASCONF case eg.
1903 * this is boundall or subset bound w/ASCONF allowed
1906 /* first, make sure that the address is IPv4 or IPv6 and not jailed */
1907 switch (ifa->address.sa.sa_family) {
1910 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1911 &ifa->address.sin6.sin6_addr) != 0) {
1918 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1919 &ifa->address.sin.sin_addr) != 0) {
1928 /* make sure we're "allowed" to add this type of addr */
1929 if (ifa->address.sa.sa_family == AF_INET6) {
1930 /* invalid if we're not a v6 endpoint */
1931 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0)
1933 /* is the v6 addr really valid ? */
1934 if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) {
1939 /* put this address on the "pending/do not use yet" list */
1940 sctp_add_local_addr_restricted(stcb, ifa);
1942 * check address scope if address is out of scope, don't queue
1943 * anything... note: this would leave the address on both inp and
1946 switch (ifa->address.sa.sa_family) {
1950 struct sockaddr_in6 *sin6;
1952 sin6 = &ifa->address.sin6;
1953 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1954 /* we skip unspecifed addresses */
1957 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1958 if (stcb->asoc.scope.local_scope == 0) {
1961 /* is it the right link local scope? */
1962 if (sctp_is_scopeid_in_nets(stcb, &ifa->address.sa) == 0) {
1966 if (stcb->asoc.scope.site_scope == 0 &&
1967 IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)) {
1976 struct sockaddr_in *sin;
1978 /* invalid if we are a v6 only endpoint */
1979 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1980 SCTP_IPV6_V6ONLY(inp))
1983 sin = &ifa->address.sin;
1984 if (sin->sin_addr.s_addr == 0) {
1985 /* we skip unspecifed addresses */
1988 if (stcb->asoc.scope.ipv4_local_scope == 0 &&
1989 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) {
1996 /* else, not AF_INET or AF_INET6, so skip */
2000 /* queue an asconf for this address add/delete */
2001 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF)) {
2002 /* does the peer do asconf? */
2003 if (stcb->asoc.asconf_supported) {
2004 /* queue an asconf for this addr */
2005 status = sctp_asconf_queue_add(stcb, ifa, type);
2008 * if queued ok, and in the open state, send out the
2009 * ASCONF. If in the non-open state, these will be
2010 * sent when the state goes open.
2013 ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
2014 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED))) {
2015 #ifdef SCTP_TIMER_BASED_ASCONF
2016 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, inp,
2017 stcb, stcb->asoc.primary_destination);
2019 sctp_send_asconf(stcb, NULL, addr_locked);
2028 sctp_asconf_iterator_ep(struct sctp_inpcb *inp, void *ptr, uint32_t val SCTP_UNUSED)
2030 struct sctp_asconf_iterator *asc;
2031 struct sctp_ifa *ifa;
2032 struct sctp_laddr *l;
2033 int cnt_invalid = 0;
2035 asc = (struct sctp_asconf_iterator *)ptr;
2036 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) {
2038 switch (ifa->address.sa.sa_family) {
2041 /* invalid if we're not a v6 endpoint */
2042 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
2044 if (asc->cnt == cnt_invalid)
2052 /* invalid if we are a v6 only endpoint */
2053 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2054 SCTP_IPV6_V6ONLY(inp)) {
2056 if (asc->cnt == cnt_invalid)
2063 /* invalid address family */
2065 if (asc->cnt == cnt_invalid)
2073 sctp_asconf_iterator_ep_end(struct sctp_inpcb *inp, void *ptr, uint32_t val SCTP_UNUSED)
2075 struct sctp_ifa *ifa;
2076 struct sctp_asconf_iterator *asc;
2077 struct sctp_laddr *laddr, *nladdr, *l;
2079 /* Only for specific case not bound all */
2080 asc = (struct sctp_asconf_iterator *)ptr;
2081 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) {
2083 if (l->action == SCTP_ADD_IP_ADDRESS) {
2084 LIST_FOREACH(laddr, &inp->sctp_addr_list,
2086 if (laddr->ifa == ifa) {
2092 } else if (l->action == SCTP_DEL_IP_ADDRESS) {
2093 LIST_FOREACH_SAFE(laddr, &inp->sctp_addr_list, sctp_nxt_addr, nladdr) {
2094 /* remove only after all guys are done */
2095 if (laddr->ifa == ifa) {
2096 sctp_del_local_addr_ep(inp, ifa);
2105 sctp_asconf_iterator_stcb(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
2106 void *ptr, uint32_t val SCTP_UNUSED)
2108 struct sctp_asconf_iterator *asc;
2109 struct sctp_ifa *ifa;
2110 struct sctp_laddr *l;
2111 int cnt_invalid = 0;
2115 asc = (struct sctp_asconf_iterator *)ptr;
2116 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) {
2120 /* address's vrf_id must be the vrf_id of the assoc */
2121 if (ifa->vrf_id != stcb->asoc.vrf_id) {
2125 /* Same checks again for assoc */
2126 switch (ifa->address.sa.sa_family) {
2130 /* invalid if we're not a v6 endpoint */
2131 struct sockaddr_in6 *sin6;
2133 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
2135 if (asc->cnt == cnt_invalid)
2140 sin6 = &ifa->address.sin6;
2141 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2142 /* we skip unspecifed addresses */
2145 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
2146 &sin6->sin6_addr) != 0) {
2149 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
2150 if (stcb->asoc.scope.local_scope == 0) {
2153 /* is it the right link local scope? */
2154 if (sctp_is_scopeid_in_nets(stcb, &ifa->address.sa) == 0) {
2164 /* invalid if we are a v6 only endpoint */
2165 struct sockaddr_in *sin;
2167 /* invalid if we are a v6 only endpoint */
2168 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2169 SCTP_IPV6_V6ONLY(inp))
2172 sin = &ifa->address.sin;
2173 if (sin->sin_addr.s_addr == 0) {
2174 /* we skip unspecifed addresses */
2177 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
2178 &sin->sin_addr) != 0) {
2181 if (stcb->asoc.scope.ipv4_local_scope == 0 &&
2182 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) {
2185 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2186 SCTP_IPV6_V6ONLY(inp)) {
2188 if (asc->cnt == cnt_invalid)
2197 /* invalid address family */
2199 if (asc->cnt == cnt_invalid)
2206 if (type == SCTP_ADD_IP_ADDRESS) {
2207 /* prevent this address from being used as a source */
2208 sctp_add_local_addr_restricted(stcb, ifa);
2209 } else if (type == SCTP_DEL_IP_ADDRESS) {
2210 struct sctp_nets *net;
2212 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2213 /* delete this address if cached */
2214 if (net->ro._s_addr == ifa) {
2215 sctp_free_ifa(net->ro._s_addr);
2216 net->ro._s_addr = NULL;
2217 net->src_addr_selected = 0;
2218 RO_NHFREE(&net->ro);
2220 * Now we deleted our src address,
2221 * should we not also now reset the
2222 * cwnd/rto to start as if its a new
2225 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
2230 } else if (type == SCTP_SET_PRIM_ADDR) {
2231 if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
2232 /* must validate the ifa is in the ep */
2233 if (sctp_is_addr_in_ep(stcb->sctp_ep, ifa) == 0) {
2237 /* Need to check scopes for this guy */
2238 if (sctp_is_address_in_scope(ifa, &stcb->asoc.scope, 0) == 0) {
2243 /* queue an asconf for this address add/delete */
2244 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF) &&
2245 stcb->asoc.asconf_supported == 1) {
2246 /* queue an asconf for this addr */
2247 status = sctp_asconf_queue_add(stcb, ifa, type);
2249 * if queued ok, and in the open state, update the
2250 * count of queued params. If in the non-open
2251 * state, these get sent when the assoc goes open.
2253 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
2254 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
2262 * If we have queued params in the open state, send out an ASCONF.
2264 if (num_queued > 0) {
2265 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2270 sctp_asconf_iterator_end(void *ptr, uint32_t val SCTP_UNUSED)
2272 struct sctp_asconf_iterator *asc;
2273 struct sctp_ifa *ifa;
2274 struct sctp_laddr *l, *nl;
2276 asc = (struct sctp_asconf_iterator *)ptr;
2277 LIST_FOREACH_SAFE(l, &asc->list_of_work, sctp_nxt_addr, nl) {
2279 if (l->action == SCTP_ADD_IP_ADDRESS) {
2280 /* Clear the defer use flag */
2281 ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE;
2284 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_laddr), l);
2285 SCTP_DECR_LADDR_COUNT();
2287 SCTP_FREE(asc, SCTP_M_ASC_IT);
2291 * sa is the sockaddr to ask the peer to set primary to.
2292 * returns: 0 = completed, -1 = error
2295 sctp_set_primary_ip_address_sa(struct sctp_tcb *stcb, struct sockaddr *sa)
2298 struct sctp_ifa *ifa;
2300 /* find the ifa for the desired set primary */
2301 vrf_id = stcb->asoc.vrf_id;
2302 ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED);
2304 /* Invalid address */
2308 /* queue an ASCONF:SET_PRIM_ADDR to be sent */
2309 if (!sctp_asconf_queue_add(stcb, ifa, SCTP_SET_PRIM_ADDR)) {
2310 /* set primary queuing succeeded */
2311 SCTPDBG(SCTP_DEBUG_ASCONF1,
2312 "set_primary_ip_address_sa: queued on tcb=%p, ",
2314 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
2315 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
2316 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
2317 #ifdef SCTP_TIMER_BASED_ASCONF
2318 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
2319 stcb->sctp_ep, stcb,
2320 stcb->asoc.primary_destination);
2322 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2326 SCTPDBG(SCTP_DEBUG_ASCONF1, "set_primary_ip_address_sa: failed to add to queue on tcb=%p, ",
2328 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
2335 sctp_is_addr_pending(struct sctp_tcb *stcb, struct sctp_ifa *sctp_ifa)
2337 struct sctp_tmit_chunk *chk, *nchk;
2338 unsigned int offset, asconf_limit;
2339 struct sctp_asconf_chunk *acp;
2340 struct sctp_asconf_paramhdr *aph;
2341 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE];
2342 struct sctp_paramhdr *ph;
2343 int add_cnt, del_cnt;
2344 uint16_t last_param_type;
2346 add_cnt = del_cnt = 0;
2347 last_param_type = 0;
2348 TAILQ_FOREACH_SAFE(chk, &stcb->asoc.asconf_send_queue, sctp_next, nchk) {
2349 if (chk->data == NULL) {
2350 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: No mbuf data?\n");
2354 acp = mtod(chk->data, struct sctp_asconf_chunk *);
2355 offset += sizeof(struct sctp_asconf_chunk);
2356 asconf_limit = ntohs(acp->ch.chunk_length);
2357 ph = (struct sctp_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_paramhdr), aparam_buf);
2359 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: couldn't get lookup addr!\n");
2362 offset += ntohs(ph->param_length);
2364 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_asconf_paramhdr), aparam_buf);
2366 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: Empty ASCONF will be sent?\n");
2369 while (aph != NULL) {
2370 unsigned int param_length, param_type;
2372 param_type = ntohs(aph->ph.param_type);
2373 param_length = ntohs(aph->ph.param_length);
2374 if (offset + param_length > asconf_limit) {
2375 /* parameter goes beyond end of chunk! */
2378 if (param_length > sizeof(aparam_buf)) {
2379 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: param length (%u) larger than buffer size!\n", param_length);
2382 if (param_length <= sizeof(struct sctp_paramhdr)) {
2383 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: param length(%u) too short\n", param_length);
2387 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, param_length, aparam_buf);
2389 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: couldn't get entire param\n");
2393 ph = (struct sctp_paramhdr *)(aph + 1);
2394 if (sctp_addr_match(ph, &sctp_ifa->address.sa) != 0) {
2395 switch (param_type) {
2396 case SCTP_ADD_IP_ADDRESS:
2399 case SCTP_DEL_IP_ADDRESS:
2405 last_param_type = param_type;
2408 offset += SCTP_SIZE32(param_length);
2409 if (offset >= asconf_limit) {
2410 /* no more data in the mbuf chain */
2413 /* get pointer to next asconf param */
2414 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_asconf_paramhdr), aparam_buf);
2419 * we want to find the sequences which consist of ADD -> DEL -> ADD
2422 if (add_cnt > del_cnt ||
2423 (add_cnt == del_cnt && last_param_type == SCTP_ADD_IP_ADDRESS)) {
2429 static struct sockaddr *
2430 sctp_find_valid_localaddr(struct sctp_tcb *stcb, int addr_locked)
2432 struct sctp_vrf *vrf = NULL;
2433 struct sctp_ifn *sctp_ifn;
2434 struct sctp_ifa *sctp_ifa;
2436 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2437 SCTP_IPI_ADDR_RLOCK();
2438 vrf = sctp_find_vrf(stcb->asoc.vrf_id);
2440 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2441 SCTP_IPI_ADDR_RUNLOCK();
2444 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
2445 if (stcb->asoc.scope.loopback_scope == 0 &&
2446 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
2447 /* Skip if loopback_scope not set */
2450 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
2451 switch (sctp_ifa->address.sa.sa_family) {
2454 if (stcb->asoc.scope.ipv4_addr_legal) {
2455 struct sockaddr_in *sin;
2457 sin = &sctp_ifa->address.sin;
2458 if (sin->sin_addr.s_addr == 0) {
2459 /* skip unspecifed addresses */
2462 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
2463 &sin->sin_addr) != 0) {
2466 if (stcb->asoc.scope.ipv4_local_scope == 0 &&
2467 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))
2470 if (sctp_is_addr_restricted(stcb, sctp_ifa) &&
2471 (!sctp_is_addr_pending(stcb, sctp_ifa)))
2474 * found a valid local v4 address to
2477 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2478 SCTP_IPI_ADDR_RUNLOCK();
2479 return (&sctp_ifa->address.sa);
2485 if (stcb->asoc.scope.ipv6_addr_legal) {
2486 struct sockaddr_in6 *sin6;
2488 if (sctp_ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) {
2492 sin6 = &sctp_ifa->address.sin6;
2493 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2495 * we skip unspecifed
2500 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
2501 &sin6->sin6_addr) != 0) {
2504 if (stcb->asoc.scope.local_scope == 0 &&
2505 IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))
2507 if (stcb->asoc.scope.site_scope == 0 &&
2508 IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))
2511 if (sctp_is_addr_restricted(stcb, sctp_ifa) &&
2512 (!sctp_is_addr_pending(stcb, sctp_ifa)))
2515 * found a valid local v6 address to
2518 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2519 SCTP_IPI_ADDR_RUNLOCK();
2520 return (&sctp_ifa->address.sa);
2529 /* no valid addresses found */
2530 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2531 SCTP_IPI_ADDR_RUNLOCK();
2535 static struct sockaddr *
2536 sctp_find_valid_localaddr_ep(struct sctp_tcb *stcb)
2538 struct sctp_laddr *laddr;
2540 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
2541 if (laddr->ifa == NULL) {
2544 /* is the address restricted ? */
2545 if (sctp_is_addr_restricted(stcb, laddr->ifa) &&
2546 (!sctp_is_addr_pending(stcb, laddr->ifa)))
2549 /* found a valid local address to use */
2550 return (&laddr->ifa->address.sa);
2552 /* no valid addresses found */
2557 * builds an ASCONF chunk from queued ASCONF params.
2558 * returns NULL on error (no mbuf, no ASCONF params queued, etc).
2561 sctp_compose_asconf(struct sctp_tcb *stcb, int *retlen, int addr_locked)
2563 struct mbuf *m_asconf, *m_asconf_chk;
2564 struct sctp_asconf_addr *aa;
2565 struct sctp_asconf_chunk *acp;
2566 struct sctp_asconf_paramhdr *aph;
2567 struct sctp_asconf_addr_param *aap;
2569 uint32_t correlation_id = 1; /* 0 is reserved... */
2570 caddr_t ptr, lookup_ptr;
2571 uint8_t lookup_used = 0;
2573 /* are there any asconf params to send? */
2574 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
2582 * get a chunk header mbuf and a cluster for the asconf params since
2583 * it's simpler to fill in the asconf chunk header lookup address on
2586 m_asconf_chk = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_chunk), 0, M_NOWAIT, 1, MT_DATA);
2587 if (m_asconf_chk == NULL) {
2589 SCTPDBG(SCTP_DEBUG_ASCONF1,
2590 "sctp_compose_asconf: couldn't get chunk mbuf!\n");
2593 m_asconf = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA);
2594 if (m_asconf == NULL) {
2596 SCTPDBG(SCTP_DEBUG_ASCONF1,
2597 "sctp_compose_asconf: couldn't get mbuf!\n");
2598 sctp_m_freem(m_asconf_chk);
2601 SCTP_BUF_LEN(m_asconf_chk) = sizeof(struct sctp_asconf_chunk);
2602 SCTP_BUF_LEN(m_asconf) = 0;
2603 acp = mtod(m_asconf_chk, struct sctp_asconf_chunk *);
2604 memset(acp, 0, sizeof(struct sctp_asconf_chunk));
2605 /* save pointers to lookup address and asconf params */
2606 lookup_ptr = (caddr_t)(acp + 1); /* after the header */
2607 ptr = mtod(m_asconf, caddr_t); /* beginning of cluster */
2609 /* fill in chunk header info */
2610 acp->ch.chunk_type = SCTP_ASCONF;
2611 acp->ch.chunk_flags = 0;
2612 acp->serial_number = htonl(stcb->asoc.asconf_seq_out);
2613 stcb->asoc.asconf_seq_out++;
2615 /* add parameters... up to smallest MTU allowed */
2616 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
2619 /* get the parameter length */
2620 p_length = SCTP_SIZE32(aa->ap.aph.ph.param_length);
2621 /* will it fit in current chunk? */
2622 if ((SCTP_BUF_LEN(m_asconf) + p_length > stcb->asoc.smallest_mtu) ||
2623 (SCTP_BUF_LEN(m_asconf) + p_length > MCLBYTES)) {
2624 /* won't fit, so we're done with this chunk */
2627 /* assign (and store) a correlation id */
2628 aa->ap.aph.correlation_id = correlation_id++;
2631 * fill in address if we're doing a delete this is a simple
2632 * way for us to fill in the correlation address, which
2633 * should only be used by the peer if we're deleting our
2634 * source address and adding a new address (e.g. renumbering
2637 if (lookup_used == 0 &&
2638 (aa->special_del == 0) &&
2639 aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) {
2640 struct sctp_ipv6addr_param *lookup;
2641 uint16_t p_size, addr_size;
2643 lookup = (struct sctp_ipv6addr_param *)lookup_ptr;
2644 lookup->ph.param_type =
2645 htons(aa->ap.addrp.ph.param_type);
2646 if (aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) {
2647 /* copy IPv6 address */
2648 p_size = sizeof(struct sctp_ipv6addr_param);
2649 addr_size = sizeof(struct in6_addr);
2651 /* copy IPv4 address */
2652 p_size = sizeof(struct sctp_ipv4addr_param);
2653 addr_size = sizeof(struct in_addr);
2655 lookup->ph.param_length = htons(SCTP_SIZE32(p_size));
2656 memcpy(lookup->addr, &aa->ap.addrp.addr, addr_size);
2657 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size);
2660 /* copy into current space */
2661 memcpy(ptr, &aa->ap, p_length);
2663 /* network elements and update lengths */
2664 aph = (struct sctp_asconf_paramhdr *)ptr;
2665 aap = (struct sctp_asconf_addr_param *)ptr;
2666 /* correlation_id is transparent to peer, no htonl needed */
2667 aph->ph.param_type = htons(aph->ph.param_type);
2668 aph->ph.param_length = htons(aph->ph.param_length);
2669 aap->addrp.ph.param_type = htons(aap->addrp.ph.param_type);
2670 aap->addrp.ph.param_length = htons(aap->addrp.ph.param_length);
2672 SCTP_BUF_LEN(m_asconf) += SCTP_SIZE32(p_length);
2673 ptr += SCTP_SIZE32(p_length);
2676 * these params are removed off the pending list upon
2677 * getting an ASCONF-ACK back from the peer, just set flag
2681 /* check to see if the lookup addr has been populated yet */
2682 if (lookup_used == 0) {
2683 /* NOTE: if the address param is optional, can skip this... */
2684 /* add any valid (existing) address... */
2685 struct sctp_ipv6addr_param *lookup;
2686 uint16_t p_size, addr_size;
2687 struct sockaddr *found_addr;
2690 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL)
2691 found_addr = sctp_find_valid_localaddr(stcb,
2694 found_addr = sctp_find_valid_localaddr_ep(stcb);
2696 lookup = (struct sctp_ipv6addr_param *)lookup_ptr;
2697 if (found_addr != NULL) {
2698 switch (found_addr->sa_family) {
2701 /* copy IPv6 address */
2702 lookup->ph.param_type =
2703 htons(SCTP_IPV6_ADDRESS);
2704 p_size = sizeof(struct sctp_ipv6addr_param);
2705 addr_size = sizeof(struct in6_addr);
2706 addr_ptr = (caddr_t)&((struct sockaddr_in6 *)
2707 found_addr)->sin6_addr;
2712 /* copy IPv4 address */
2713 lookup->ph.param_type =
2714 htons(SCTP_IPV4_ADDRESS);
2715 p_size = sizeof(struct sctp_ipv4addr_param);
2716 addr_size = sizeof(struct in_addr);
2717 addr_ptr = (caddr_t)&((struct sockaddr_in *)
2718 found_addr)->sin_addr;
2722 SCTPDBG(SCTP_DEBUG_ASCONF1,
2723 "sctp_compose_asconf: no usable lookup addr (family = %d)!\n",
2724 found_addr->sa_family);
2725 sctp_m_freem(m_asconf_chk);
2726 sctp_m_freem(m_asconf);
2729 lookup->ph.param_length = htons(SCTP_SIZE32(p_size));
2730 memcpy(lookup->addr, addr_ptr, addr_size);
2731 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size);
2733 /* uh oh... don't have any address?? */
2734 SCTPDBG(SCTP_DEBUG_ASCONF1,
2735 "sctp_compose_asconf: no lookup addr!\n");
2736 sctp_m_freem(m_asconf_chk);
2737 sctp_m_freem(m_asconf);
2741 /* chain it all together */
2742 SCTP_BUF_NEXT(m_asconf_chk) = m_asconf;
2743 *retlen = SCTP_BUF_LEN(m_asconf_chk) + SCTP_BUF_LEN(m_asconf);
2744 acp->ch.chunk_length = htons(*retlen);
2746 return (m_asconf_chk);
2750 * section to handle address changes before an association is up eg. changes
2751 * during INIT/INIT-ACK/COOKIE-ECHO handshake
2755 * processes the (local) addresses in the INIT-ACK chunk
2758 sctp_process_initack_addresses(struct sctp_tcb *stcb, struct mbuf *m,
2759 unsigned int offset, unsigned int length)
2761 struct sctp_paramhdr tmp_param, *ph;
2762 uint16_t plen, ptype;
2763 struct sctp_ifa *sctp_ifa;
2764 union sctp_sockstore store;
2766 struct sctp_ipv6addr_param addr6_store;
2769 struct sctp_ipv4addr_param addr4_store;
2772 SCTPDBG(SCTP_DEBUG_ASCONF2, "processing init-ack addresses\n");
2773 if (stcb == NULL) /* Un-needed check for SA */
2776 /* convert to upper bound */
2779 if ((offset + sizeof(struct sctp_paramhdr)) > length) {
2782 /* go through the addresses in the init-ack */
2783 ph = (struct sctp_paramhdr *)
2784 sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr),
2785 (uint8_t *)&tmp_param);
2786 while (ph != NULL) {
2787 ptype = ntohs(ph->param_type);
2788 plen = ntohs(ph->param_length);
2791 case SCTP_IPV6_ADDRESS:
2793 struct sctp_ipv6addr_param *a6p;
2795 /* get the entire IPv6 address param */
2796 a6p = (struct sctp_ipv6addr_param *)
2797 sctp_m_getptr(m, offset,
2798 sizeof(struct sctp_ipv6addr_param),
2799 (uint8_t *)&addr6_store);
2800 if (plen != sizeof(struct sctp_ipv6addr_param) ||
2804 memset(&store, 0, sizeof(union sctp_sockstore));
2805 store.sin6.sin6_family = AF_INET6;
2806 store.sin6.sin6_len = sizeof(struct sockaddr_in6);
2807 store.sin6.sin6_port = stcb->rport;
2808 memcpy(&store.sin6.sin6_addr, a6p->addr, sizeof(struct in6_addr));
2813 case SCTP_IPV4_ADDRESS:
2815 struct sctp_ipv4addr_param *a4p;
2817 /* get the entire IPv4 address param */
2818 a4p = (struct sctp_ipv4addr_param *)sctp_m_getptr(m, offset,
2819 sizeof(struct sctp_ipv4addr_param),
2820 (uint8_t *)&addr4_store);
2821 if (plen != sizeof(struct sctp_ipv4addr_param) ||
2825 memset(&store, 0, sizeof(union sctp_sockstore));
2826 store.sin.sin_family = AF_INET;
2827 store.sin.sin_len = sizeof(struct sockaddr_in);
2828 store.sin.sin_port = stcb->rport;
2829 store.sin.sin_addr.s_addr = a4p->addr;
2837 /* see if this address really (still) exists */
2838 sctp_ifa = sctp_find_ifa_by_addr(&store.sa, stcb->asoc.vrf_id,
2839 SCTP_ADDR_NOT_LOCKED);
2840 if (sctp_ifa == NULL) {
2841 /* address doesn't exist anymore */
2844 /* are ASCONFs allowed ? */
2845 if ((sctp_is_feature_on(stcb->sctp_ep,
2846 SCTP_PCB_FLAGS_DO_ASCONF)) &&
2847 stcb->asoc.asconf_supported) {
2848 /* queue an ASCONF DEL_IP_ADDRESS */
2849 status = sctp_asconf_queue_sa_delete(stcb, &store.sa);
2851 * if queued ok, and in correct state, send
2855 SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) {
2856 #ifdef SCTP_TIMER_BASED_ASCONF
2857 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
2858 stcb->sctp_ep, stcb,
2859 stcb->asoc.primary_destination);
2861 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2869 * Sanity check: Make sure the length isn't 0, otherwise
2870 * we'll be stuck in this loop for a long time...
2872 if (SCTP_SIZE32(plen) == 0) {
2873 SCTP_PRINTF("process_initack_addrs: bad len (%d) type=%xh\n",
2877 /* get next parameter */
2878 offset += SCTP_SIZE32(plen);
2879 if ((offset + sizeof(struct sctp_paramhdr)) > length)
2881 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset,
2882 sizeof(struct sctp_paramhdr), (uint8_t *)&tmp_param);
2886 /* FIX ME: need to verify return result for v6 address type if v6 disabled */
2888 * checks to see if a specific address is in the initack address list returns
2889 * 1 if found, 0 if not
2892 sctp_addr_in_initack(struct mbuf *m, uint32_t offset, uint32_t length, struct sockaddr *sa)
2894 struct sctp_paramhdr tmp_param, *ph;
2895 uint16_t plen, ptype;
2897 struct sockaddr_in *sin;
2898 struct sctp_ipv4addr_param *a4p;
2899 struct sctp_ipv6addr_param addr4_store;
2902 struct sockaddr_in6 *sin6;
2903 struct sctp_ipv6addr_param *a6p;
2904 struct sctp_ipv6addr_param addr6_store;
2905 struct sockaddr_in6 sin6_tmp;
2908 switch (sa->sa_family) {
2921 SCTPDBG(SCTP_DEBUG_ASCONF2, "find_initack_addr: starting search for ");
2922 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, sa);
2923 /* convert to upper bound */
2926 if ((offset + sizeof(struct sctp_paramhdr)) > length) {
2927 SCTPDBG(SCTP_DEBUG_ASCONF1,
2928 "find_initack_addr: invalid offset?\n");
2931 /* go through the addresses in the init-ack */
2932 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset,
2933 sizeof(struct sctp_paramhdr), (uint8_t *)&tmp_param);
2934 while (ph != NULL) {
2935 ptype = ntohs(ph->param_type);
2936 plen = ntohs(ph->param_length);
2939 case SCTP_IPV6_ADDRESS:
2940 if (sa->sa_family == AF_INET6) {
2941 /* get the entire IPv6 address param */
2942 if (plen != sizeof(struct sctp_ipv6addr_param)) {
2945 /* get the entire IPv6 address param */
2946 a6p = (struct sctp_ipv6addr_param *)
2947 sctp_m_getptr(m, offset,
2948 sizeof(struct sctp_ipv6addr_param),
2949 (uint8_t *)&addr6_store);
2953 sin6 = (struct sockaddr_in6 *)sa;
2954 if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr)) {
2955 /* create a copy and clear scope */
2956 memcpy(&sin6_tmp, sin6,
2957 sizeof(struct sockaddr_in6));
2959 in6_clearscope(&sin6->sin6_addr);
2961 if (memcmp(&sin6->sin6_addr, a6p->addr,
2962 sizeof(struct in6_addr)) == 0) {
2970 case SCTP_IPV4_ADDRESS:
2971 if (sa->sa_family == AF_INET) {
2972 if (plen != sizeof(struct sctp_ipv4addr_param)) {
2975 /* get the entire IPv4 address param */
2976 a4p = (struct sctp_ipv4addr_param *)
2977 sctp_m_getptr(m, offset,
2978 sizeof(struct sctp_ipv4addr_param),
2979 (uint8_t *)&addr4_store);
2983 sin = (struct sockaddr_in *)sa;
2984 if (sin->sin_addr.s_addr == a4p->addr) {
2994 /* get next parameter */
2995 offset += SCTP_SIZE32(plen);
2996 if (offset + sizeof(struct sctp_paramhdr) > length) {
2999 ph = (struct sctp_paramhdr *)
3000 sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr),
3001 (uint8_t *)&tmp_param);
3008 * makes sure that the current endpoint local addr list is consistent with
3009 * the new association (eg. subset bound, asconf allowed) adds addresses as
3013 sctp_check_address_list_ep(struct sctp_tcb *stcb, struct mbuf *m, int offset,
3014 int length, struct sockaddr *init_addr)
3016 struct sctp_laddr *laddr;
3018 /* go through the endpoint list */
3019 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
3020 /* be paranoid and validate the laddr */
3021 if (laddr->ifa == NULL) {
3022 SCTPDBG(SCTP_DEBUG_ASCONF1,
3023 "check_addr_list_ep: laddr->ifa is NULL");
3026 /* do i have it implicitly? */
3027 if (sctp_cmpaddr(&laddr->ifa->address.sa, init_addr)) {
3030 /* check to see if in the init-ack */
3031 if (!sctp_addr_in_initack(m, offset, length, &laddr->ifa->address.sa)) {
3033 sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb, laddr->ifa,
3034 SCTP_ADD_IP_ADDRESS, SCTP_ADDR_NOT_LOCKED);
3040 * makes sure that the current kernel address list is consistent with the new
3041 * association (with all addrs bound) adds addresses as necessary
3044 sctp_check_address_list_all(struct sctp_tcb *stcb, struct mbuf *m, int offset,
3045 int length, struct sockaddr *init_addr,
3046 uint16_t local_scope, uint16_t site_scope,
3047 uint16_t ipv4_scope, uint16_t loopback_scope)
3049 struct sctp_vrf *vrf = NULL;
3050 struct sctp_ifn *sctp_ifn;
3051 struct sctp_ifa *sctp_ifa;
3054 struct sockaddr_in *sin;
3057 struct sockaddr_in6 *sin6;
3061 vrf_id = stcb->asoc.vrf_id;
3065 SCTP_IPI_ADDR_RLOCK();
3066 vrf = sctp_find_vrf(vrf_id);
3068 SCTP_IPI_ADDR_RUNLOCK();
3071 /* go through all our known interfaces */
3072 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
3073 if (loopback_scope == 0 && SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
3074 /* skip loopback interface */
3077 /* go through each interface address */
3078 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
3079 /* do i have it implicitly? */
3080 if (sctp_cmpaddr(&sctp_ifa->address.sa, init_addr)) {
3083 switch (sctp_ifa->address.sa.sa_family) {
3086 sin = &sctp_ifa->address.sin;
3087 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
3088 &sin->sin_addr) != 0) {
3091 if ((ipv4_scope == 0) &&
3092 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
3093 /* private address not in scope */
3100 sin6 = &sctp_ifa->address.sin6;
3101 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
3102 &sin6->sin6_addr) != 0) {
3105 if ((local_scope == 0) &&
3106 (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))) {
3109 if ((site_scope == 0) &&
3110 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
3118 /* check to see if in the init-ack */
3119 if (!sctp_addr_in_initack(m, offset, length, &sctp_ifa->address.sa)) {
3121 sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb,
3122 sctp_ifa, SCTP_ADD_IP_ADDRESS,
3125 } /* end foreach ifa */
3126 } /* end foreach ifn */
3127 SCTP_IPI_ADDR_RUNLOCK();
3131 * validates an init-ack chunk (from a cookie-echo) with current addresses
3132 * adds addresses from the init-ack into our local address list, if needed
3133 * queues asconf adds/deletes addresses as needed and makes appropriate list
3134 * changes for source address selection m, offset: points to the start of the
3135 * address list in an init-ack chunk length: total length of the address
3136 * params only init_addr: address where my INIT-ACK was sent from
3139 sctp_check_address_list(struct sctp_tcb *stcb, struct mbuf *m, int offset,
3140 int length, struct sockaddr *init_addr,
3141 uint16_t local_scope, uint16_t site_scope,
3142 uint16_t ipv4_scope, uint16_t loopback_scope)
3144 /* process the local addresses in the initack */
3145 sctp_process_initack_addresses(stcb, m, offset, length);
3147 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3148 /* bound all case */
3149 sctp_check_address_list_all(stcb, m, offset, length, init_addr,
3150 local_scope, site_scope, ipv4_scope, loopback_scope);
3152 /* subset bound case */
3153 if (sctp_is_feature_on(stcb->sctp_ep,
3154 SCTP_PCB_FLAGS_DO_ASCONF)) {
3155 /* asconf's allowed */
3156 sctp_check_address_list_ep(stcb, m, offset, length,
3159 /* else, no asconfs allowed, so what we sent is what we get */
3164 * sctp_bindx() support
3167 sctp_addr_mgmt_ep_sa(struct sctp_inpcb *inp, struct sockaddr *sa,
3168 uint32_t type, uint32_t vrf_id)
3170 struct sctp_ifa *ifa;
3171 struct sctp_laddr *laddr, *nladdr;
3173 if (sa->sa_len == 0) {
3174 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EINVAL);
3177 if (type == SCTP_ADD_IP_ADDRESS) {
3178 /* For an add the address MUST be on the system */
3179 ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED);
3180 } else if (type == SCTP_DEL_IP_ADDRESS) {
3181 /* For a delete we need to find it in the inp */
3182 ifa = sctp_find_ifa_in_ep(inp, sa, SCTP_ADDR_NOT_LOCKED);
3187 if (type == SCTP_ADD_IP_ADDRESS) {
3188 sctp_add_local_addr_ep(inp, ifa, type);
3189 } else if (type == SCTP_DEL_IP_ADDRESS) {
3190 if (inp->laddr_count < 2) {
3191 /* can't delete the last local address */
3192 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EINVAL);
3195 LIST_FOREACH(laddr, &inp->sctp_addr_list,
3197 if (ifa == laddr->ifa) {
3198 /* Mark in the delete */
3199 laddr->action = type;
3203 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
3205 * There is no need to start the iterator if the inp
3206 * has no associations.
3208 if (type == SCTP_DEL_IP_ADDRESS) {
3209 LIST_FOREACH_SAFE(laddr, &inp->sctp_addr_list, sctp_nxt_addr, nladdr) {
3210 if (laddr->ifa == ifa) {
3211 sctp_del_local_addr_ep(inp, ifa);
3216 struct sctp_asconf_iterator *asc;
3217 struct sctp_laddr *wi;
3220 SCTP_MALLOC(asc, struct sctp_asconf_iterator *,
3221 sizeof(struct sctp_asconf_iterator),
3224 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, ENOMEM);
3227 wi = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_laddr), struct sctp_laddr);
3229 SCTP_FREE(asc, SCTP_M_ASC_IT);
3230 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, ENOMEM);
3233 LIST_INIT(&asc->list_of_work);
3235 SCTP_INCR_LADDR_COUNT();
3238 atomic_add_int(&ifa->refcount, 1);
3239 LIST_INSERT_HEAD(&asc->list_of_work, wi, sctp_nxt_addr);
3240 ret = sctp_initiate_iterator(sctp_asconf_iterator_ep,
3241 sctp_asconf_iterator_stcb,
3242 sctp_asconf_iterator_ep_end,
3244 SCTP_PCB_ANY_FEATURES,
3245 SCTP_ASOC_ANY_STATE,
3247 sctp_asconf_iterator_end, inp, 0);
3249 SCTP_PRINTF("Failed to initiate iterator for addr_mgmt_ep_sa\n");
3250 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EFAULT);
3251 sctp_asconf_iterator_end(asc, 0);
3257 /* invalid address! */
3258 SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EADDRNOTAVAIL);
3259 return (EADDRNOTAVAIL);
3264 sctp_asconf_send_nat_state_update(struct sctp_tcb *stcb, struct sctp_nets *net)
3266 struct sctp_asconf_addr *aa_vtag, *aa_add, *aa_del;
3267 struct sctp_ifa *sctp_ifap;
3268 struct sctp_asconf_tag_param *vtag;
3270 struct sockaddr_in *to;
3273 struct sockaddr_in6 *to6;
3277 SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing net\n");
3281 SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing stcb\n");
3285 * Need to have in the ASCONF: - VTAG(my_vtag/peer_vtag) -
3286 * ADD(wildcard) - DEL(wildcard) - ADD(Any global addresses)
3288 SCTP_MALLOC(aa_vtag, struct sctp_asconf_addr *, sizeof(struct sctp_asconf_addr), SCTP_M_ASC_ADDR);
3289 SCTP_MALLOC(aa_add, struct sctp_asconf_addr *, sizeof(struct sctp_asconf_addr), SCTP_M_ASC_ADDR);
3290 SCTP_MALLOC(aa_del, struct sctp_asconf_addr *, sizeof(struct sctp_asconf_addr), SCTP_M_ASC_ADDR);
3292 if ((aa_vtag == NULL) || (aa_add == NULL) || (aa_del == NULL)) {
3293 /* Didn't get memory */
3294 SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: failed to get memory!\n");
3296 if (aa_vtag != NULL) {
3297 SCTP_FREE(aa_vtag, SCTP_M_ASC_ADDR);
3299 if (aa_add != NULL) {
3300 SCTP_FREE(aa_add, SCTP_M_ASC_ADDR);
3302 if (aa_del != NULL) {
3303 SCTP_FREE(aa_del, SCTP_M_ASC_ADDR);
3307 memset(aa_vtag, 0, sizeof(struct sctp_asconf_addr));
3308 aa_vtag->special_del = 0;
3309 /* Fill in ASCONF address parameter fields. */
3310 /* Top level elements are "networked" during send. */
3311 aa_vtag->ifa = NULL;
3312 aa_vtag->sent = 0; /* clear sent flag */
3313 vtag = (struct sctp_asconf_tag_param *)&aa_vtag->ap.aph;
3314 vtag->aph.ph.param_type = SCTP_NAT_VTAGS;
3315 vtag->aph.ph.param_length = sizeof(struct sctp_asconf_tag_param);
3316 vtag->local_vtag = htonl(stcb->asoc.my_vtag);
3317 vtag->remote_vtag = htonl(stcb->asoc.peer_vtag);
3319 memset(aa_add, 0, sizeof(struct sctp_asconf_addr));
3320 memset(aa_del, 0, sizeof(struct sctp_asconf_addr));
3321 switch (net->ro._l_addr.sa.sa_family) {
3324 aa_add->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
3325 aa_add->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param);
3326 aa_add->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
3327 aa_add->ap.addrp.ph.param_length = sizeof(struct sctp_ipv4addr_param);
3328 /* No need to fill the address, we are using 0.0.0.0 */
3329 aa_del->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
3330 aa_del->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param);
3331 aa_del->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
3332 aa_del->ap.addrp.ph.param_length = sizeof(struct sctp_ipv4addr_param);
3333 /* No need to fill the address, we are using 0.0.0.0 */
3338 aa_add->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
3339 aa_add->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param);
3340 aa_add->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
3341 aa_add->ap.addrp.ph.param_length = sizeof(struct sctp_ipv6addr_param);
3342 /* No need to fill the address, we are using ::0 */
3343 aa_del->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS;
3344 aa_del->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param);
3345 aa_del->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
3346 aa_del->ap.addrp.ph.param_length = sizeof(struct sctp_ipv6addr_param);
3347 /* No need to fill the address, we are using ::0 */
3351 SCTPDBG(SCTP_DEBUG_ASCONF1,
3352 "sctp_asconf_send_nat_state_update: unknown address family %d\n",
3353 net->ro._l_addr.sa.sa_family);
3356 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa_vtag, next);
3357 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa_add, next);
3358 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa_del, next);
3360 /* Now we must hunt the addresses and add all global addresses */
3361 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3362 struct sctp_vrf *vrf = NULL;
3363 struct sctp_ifn *sctp_ifnp;
3366 vrf_id = stcb->sctp_ep->def_vrf_id;
3367 vrf = sctp_find_vrf(vrf_id);
3372 SCTP_IPI_ADDR_RLOCK();
3373 LIST_FOREACH(sctp_ifnp, &vrf->ifnlist, next_ifn) {
3374 LIST_FOREACH(sctp_ifap, &sctp_ifnp->ifalist, next_ifa) {
3375 switch (sctp_ifap->address.sa.sa_family) {
3378 to = &sctp_ifap->address.sin;
3379 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
3380 &to->sin_addr) != 0) {
3383 if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) {
3386 if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) {
3393 to6 = &sctp_ifap->address.sin6;
3394 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
3395 &to6->sin6_addr) != 0) {
3398 if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) {
3401 if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) {
3409 sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS);
3412 SCTP_IPI_ADDR_RUNLOCK();
3414 struct sctp_laddr *laddr;
3416 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
3417 if (laddr->ifa == NULL) {
3420 if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED)
3422 * Address being deleted by the system, dont
3426 if (laddr->action == SCTP_DEL_IP_ADDRESS) {
3428 * Address being deleted on this ep don't
3433 sctp_ifap = laddr->ifa;
3434 switch (sctp_ifap->address.sa.sa_family) {
3437 to = &sctp_ifap->address.sin;
3438 if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) {
3441 if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) {
3448 to6 = &sctp_ifap->address.sin6;
3449 if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) {
3452 if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) {
3460 sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS);
3464 /* Now we must send the asconf into the queue */
3465 sctp_send_asconf(stcb, net, SCTP_ADDR_NOT_LOCKED);