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 #include <netinet/sctp_os.h>
37 #include <netinet/sctp_var.h>
38 #include <netinet/sctp_sysctl.h>
39 #include <netinet/sctp_pcb.h>
40 #include <netinet/sctp_header.h>
41 #include <netinet/sctputil.h>
42 #include <netinet/sctp_output.h>
43 #include <netinet/sctp_asconf.h>
44 #include <netinet/sctp_timer.h>
48 * SCTP_DEBUG_ASCONF1: protocol info, general info and errors
49 * SCTP_DEBUG_ASCONF2: detailed info
55 * An ASCONF parameter queue exists per asoc which holds the pending address
56 * operations. Lists are updated upon receipt of ASCONF-ACK.
58 * A restricted_addrs list exists per assoc to hold local addresses that are
59 * not (yet) usable by the assoc as a source address. These addresses are
60 * either pending an ASCONF operation (and exist on the ASCONF parameter
61 * queue), or they are permanently restricted (the peer has returned an
62 * ERROR indication to an ASCONF(ADD), or the peer does not support ASCONF).
64 * Deleted addresses are always immediately removed from the lists as they will
65 * (shortly) no longer exist in the kernel. We send ASCONFs as a courtesy,
70 * ASCONF parameter processing.
71 * response_required: set if a reply is required (eg. SUCCESS_REPORT).
72 * returns a mbuf to an "error" response parameter or NULL/"success" if ok.
73 * FIX: allocating this many mbufs on the fly is pretty inefficient...
76 sctp_asconf_success_response(uint32_t id)
78 struct mbuf *m_reply = NULL;
79 struct sctp_asconf_paramhdr *aph;
81 m_reply = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_paramhdr),
82 0, M_NOWAIT, 1, MT_DATA);
83 if (m_reply == NULL) {
84 SCTPDBG(SCTP_DEBUG_ASCONF1,
85 "asconf_success_response: couldn't get mbuf!\n");
88 aph = mtod(m_reply, struct sctp_asconf_paramhdr *);
89 aph->correlation_id = id;
90 aph->ph.param_type = htons(SCTP_SUCCESS_REPORT);
91 aph->ph.param_length = sizeof(struct sctp_asconf_paramhdr);
92 SCTP_BUF_LEN(m_reply) = aph->ph.param_length;
93 aph->ph.param_length = htons(aph->ph.param_length);
99 sctp_asconf_error_response(uint32_t id, uint16_t cause, uint8_t *error_tlv,
102 struct mbuf *m_reply = NULL;
103 struct sctp_asconf_paramhdr *aph;
104 struct sctp_error_cause *error;
106 uint16_t i, param_length, cause_length, padding_length;
109 if (error_tlv == NULL) {
112 cause_length = sizeof(struct sctp_error_cause) + tlv_length;
113 param_length = sizeof(struct sctp_asconf_paramhdr) + cause_length;
114 padding_length = tlv_length % 4;
115 if (padding_length != 0) {
116 padding_length = 4 - padding_length;
118 buf_len = param_length + padding_length;
119 if (buf_len > MLEN) {
120 SCTPDBG(SCTP_DEBUG_ASCONF1,
121 "asconf_error_response: tlv_length (%xh) too big\n",
125 m_reply = sctp_get_mbuf_for_msg(buf_len, 0, M_NOWAIT, 1, MT_DATA);
126 if (m_reply == NULL) {
127 SCTPDBG(SCTP_DEBUG_ASCONF1,
128 "asconf_error_response: couldn't get mbuf!\n");
131 aph = mtod(m_reply, struct sctp_asconf_paramhdr *);
132 aph->ph.param_type = htons(SCTP_ERROR_CAUSE_IND);
133 aph->ph.param_length = htons(param_length);
134 aph->correlation_id = id;
135 error = (struct sctp_error_cause *)(aph + 1);
136 error->code = htons(cause);
137 error->length = htons(cause_length);
138 if (error_tlv != NULL) {
139 tlv = (uint8_t *)(error + 1);
140 memcpy(tlv, error_tlv, tlv_length);
141 for (i = 0; i < padding_length; i++) {
142 tlv[tlv_length + i] = 0;
145 SCTP_BUF_LEN(m_reply) = buf_len;
150 sctp_process_asconf_add_ip(struct sockaddr *src, struct sctp_asconf_paramhdr *aph,
151 struct sctp_tcb *stcb, int send_hb, int response_required)
153 struct sctp_nets *net;
154 struct mbuf *m_reply = NULL;
155 union sctp_sockstore store;
156 struct sctp_paramhdr *ph;
157 uint16_t param_type, aparam_length;
158 #if defined(INET) || defined(INET6)
159 uint16_t param_length;
162 int zero_address = 0;
165 struct sockaddr_in *sin;
166 struct sctp_ipv4addr_param *v4addr;
169 struct sockaddr_in6 *sin6;
170 struct sctp_ipv6addr_param *v6addr;
173 aparam_length = ntohs(aph->ph.param_length);
174 if (aparam_length < sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_paramhdr)) {
177 ph = (struct sctp_paramhdr *)(aph + 1);
178 param_type = ntohs(ph->param_type);
179 #if defined(INET) || defined(INET6)
180 param_length = ntohs(ph->param_length);
181 if (param_length + sizeof(struct sctp_asconf_paramhdr) != aparam_length) {
186 switch (param_type) {
188 case SCTP_IPV4_ADDRESS:
189 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
190 /* invalid param size */
193 v4addr = (struct sctp_ipv4addr_param *)ph;
195 memset(sin, 0, sizeof(*sin));
196 sin->sin_family = AF_INET;
197 sin->sin_len = sizeof(struct sockaddr_in);
198 sin->sin_port = stcb->rport;
199 sin->sin_addr.s_addr = v4addr->addr;
200 if ((sin->sin_addr.s_addr == INADDR_BROADCAST) ||
201 IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) {
204 if (sin->sin_addr.s_addr == INADDR_ANY)
206 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_add_ip: adding ");
207 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
211 case SCTP_IPV6_ADDRESS:
212 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
213 /* invalid param size */
216 v6addr = (struct sctp_ipv6addr_param *)ph;
218 memset(sin6, 0, sizeof(*sin6));
219 sin6->sin6_family = AF_INET6;
220 sin6->sin6_len = sizeof(struct sockaddr_in6);
221 sin6->sin6_port = stcb->rport;
222 memcpy((caddr_t)&sin6->sin6_addr, v6addr->addr,
223 sizeof(struct in6_addr));
224 if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
227 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
229 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_add_ip: adding ");
230 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
234 m_reply = sctp_asconf_error_response(aph->correlation_id,
235 SCTP_CAUSE_INVALID_PARAM, (uint8_t *)aph,
240 /* if 0.0.0.0/::0, add the source address instead */
241 if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) {
243 SCTPDBG(SCTP_DEBUG_ASCONF1,
244 "process_asconf_add_ip: using source addr ");
245 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, src);
248 /* add the address */
250 m_reply = sctp_asconf_error_response(aph->correlation_id,
251 SCTP_CAUSE_INVALID_PARAM, (uint8_t *)aph,
253 } else if (sctp_add_remote_addr(stcb, sa, &net, stcb->asoc.port,
255 SCTP_ADDR_DYNAMIC_ADDED) != 0) {
256 SCTPDBG(SCTP_DEBUG_ASCONF1,
257 "process_asconf_add_ip: error adding address\n");
258 m_reply = sctp_asconf_error_response(aph->correlation_id,
259 SCTP_CAUSE_RESOURCE_SHORTAGE, (uint8_t *)aph,
262 if (response_required) {
264 sctp_asconf_success_response(aph->correlation_id);
267 /* notify upper layer */
268 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_ADD_IP, stcb, 0, sa, SCTP_SO_NOT_LOCKED);
269 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, stcb->sctp_ep, stcb, net);
270 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep,
273 sctp_send_hb(stcb, net, SCTP_SO_NOT_LOCKED);
281 sctp_asconf_del_remote_addrs_except(struct sctp_tcb *stcb, struct sockaddr *src)
283 struct sctp_nets *src_net, *net, *nnet;
285 /* make sure the source address exists as a destination net */
286 src_net = sctp_findnet(stcb, src);
287 if (src_net == NULL) {
292 /* delete all destination addresses except the source */
293 TAILQ_FOREACH_SAFE(net, &stcb->asoc.nets, sctp_next, nnet) {
294 if (net != src_net) {
295 /* delete this address */
296 SCTPDBG(SCTP_DEBUG_ASCONF1,
297 "asconf_del_remote_addrs_except: deleting ");
298 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1,
299 (struct sockaddr *)&net->ro._l_addr);
300 /* notify upper layer */
301 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0,
302 (struct sockaddr *)&net->ro._l_addr, SCTP_SO_NOT_LOCKED);
303 sctp_remove_net(stcb, net);
310 sctp_process_asconf_delete_ip(struct sockaddr *src,
311 struct sctp_asconf_paramhdr *aph,
312 struct sctp_tcb *stcb, int response_required)
314 struct mbuf *m_reply = NULL;
315 union sctp_sockstore store;
316 struct sctp_paramhdr *ph;
317 uint16_t param_type, aparam_length;
318 #if defined(INET) || defined(INET6)
319 uint16_t param_length;
322 int zero_address = 0;
325 struct sockaddr_in *sin;
326 struct sctp_ipv4addr_param *v4addr;
329 struct sockaddr_in6 *sin6;
330 struct sctp_ipv6addr_param *v6addr;
333 aparam_length = ntohs(aph->ph.param_length);
334 if (aparam_length < sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_paramhdr)) {
337 ph = (struct sctp_paramhdr *)(aph + 1);
338 param_type = ntohs(ph->param_type);
339 #if defined(INET) || defined(INET6)
340 param_length = ntohs(ph->param_length);
341 if (param_length + sizeof(struct sctp_asconf_paramhdr) != aparam_length) {
346 switch (param_type) {
348 case SCTP_IPV4_ADDRESS:
349 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
350 /* invalid param size */
353 v4addr = (struct sctp_ipv4addr_param *)ph;
355 memset(sin, 0, sizeof(*sin));
356 sin->sin_family = AF_INET;
357 sin->sin_len = sizeof(struct sockaddr_in);
358 sin->sin_port = stcb->rport;
359 sin->sin_addr.s_addr = v4addr->addr;
360 if (sin->sin_addr.s_addr == INADDR_ANY)
362 SCTPDBG(SCTP_DEBUG_ASCONF1,
363 "process_asconf_delete_ip: deleting ");
364 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
368 case SCTP_IPV6_ADDRESS:
369 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
370 /* invalid param size */
373 v6addr = (struct sctp_ipv6addr_param *)ph;
375 memset(sin6, 0, sizeof(*sin6));
376 sin6->sin6_family = AF_INET6;
377 sin6->sin6_len = sizeof(struct sockaddr_in6);
378 sin6->sin6_port = stcb->rport;
379 memcpy(&sin6->sin6_addr, v6addr->addr,
380 sizeof(struct in6_addr));
381 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
383 SCTPDBG(SCTP_DEBUG_ASCONF1,
384 "process_asconf_delete_ip: deleting ");
385 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
389 m_reply = sctp_asconf_error_response(aph->correlation_id,
390 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *)aph,
395 /* make sure the source address is not being deleted */
396 if (sctp_cmpaddr(sa, src)) {
397 /* trying to delete the source address! */
398 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: tried to delete source addr\n");
399 m_reply = sctp_asconf_error_response(aph->correlation_id,
400 SCTP_CAUSE_DELETING_SRC_ADDR, (uint8_t *)aph,
405 /* if deleting 0.0.0.0/::0, delete all addresses except src addr */
406 if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) {
407 result = sctp_asconf_del_remote_addrs_except(stcb, src);
410 /* src address did not exist? */
411 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: src addr does not exist?\n");
412 /* what error to reply with?? */
414 sctp_asconf_error_response(aph->correlation_id,
415 SCTP_CAUSE_REQUEST_REFUSED, (uint8_t *)aph,
417 } else if (response_required) {
419 sctp_asconf_success_response(aph->correlation_id);
424 /* delete the address */
425 result = sctp_del_remote_addr(stcb, sa);
427 * note if result == -2, the address doesn't exist in the asoc but
428 * since it's being deleted anyways, we just ack the delete -- but
429 * this probably means something has already gone awry
432 /* only one address in the asoc */
433 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: tried to delete last IP addr!\n");
434 m_reply = sctp_asconf_error_response(aph->correlation_id,
435 SCTP_CAUSE_DELETING_LAST_ADDR, (uint8_t *)aph,
438 if (response_required) {
439 m_reply = sctp_asconf_success_response(aph->correlation_id);
441 /* notify upper layer */
442 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0, sa, SCTP_SO_NOT_LOCKED);
448 sctp_process_asconf_set_primary(struct sockaddr *src,
449 struct sctp_asconf_paramhdr *aph,
450 struct sctp_tcb *stcb, int response_required)
452 struct mbuf *m_reply = NULL;
453 union sctp_sockstore store;
454 struct sctp_paramhdr *ph;
455 uint16_t param_type, aparam_length;
456 #if defined(INET) || defined(INET6)
457 uint16_t param_length;
460 int zero_address = 0;
462 struct sockaddr_in *sin;
463 struct sctp_ipv4addr_param *v4addr;
466 struct sockaddr_in6 *sin6;
467 struct sctp_ipv6addr_param *v6addr;
470 aparam_length = ntohs(aph->ph.param_length);
471 if (aparam_length < sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_paramhdr)) {
474 ph = (struct sctp_paramhdr *)(aph + 1);
475 param_type = ntohs(ph->param_type);
476 #if defined(INET) || defined(INET6)
477 param_length = ntohs(ph->param_length);
478 if (param_length + sizeof(struct sctp_asconf_paramhdr) != aparam_length) {
483 switch (param_type) {
485 case SCTP_IPV4_ADDRESS:
486 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
487 /* invalid param size */
490 v4addr = (struct sctp_ipv4addr_param *)ph;
492 memset(sin, 0, sizeof(*sin));
493 sin->sin_family = AF_INET;
494 sin->sin_len = sizeof(struct sockaddr_in);
495 sin->sin_addr.s_addr = v4addr->addr;
496 if (sin->sin_addr.s_addr == INADDR_ANY)
498 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_set_primary: ");
499 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
503 case SCTP_IPV6_ADDRESS:
504 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
505 /* invalid param size */
508 v6addr = (struct sctp_ipv6addr_param *)ph;
510 memset(sin6, 0, sizeof(*sin6));
511 sin6->sin6_family = AF_INET6;
512 sin6->sin6_len = sizeof(struct sockaddr_in6);
513 memcpy((caddr_t)&sin6->sin6_addr, v6addr->addr,
514 sizeof(struct in6_addr));
515 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
517 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_set_primary: ");
518 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
522 m_reply = sctp_asconf_error_response(aph->correlation_id,
523 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *)aph,
528 /* if 0.0.0.0/::0, use the source address instead */
529 if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) {
531 SCTPDBG(SCTP_DEBUG_ASCONF1,
532 "process_asconf_set_primary: using source addr ");
533 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, src);
535 /* set the primary address */
536 if (sctp_set_primary_addr(stcb, sa, NULL) == 0) {
537 SCTPDBG(SCTP_DEBUG_ASCONF1,
538 "process_asconf_set_primary: primary address set\n");
539 /* notify upper layer */
540 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_SET_PRIMARY, stcb, 0, sa, SCTP_SO_NOT_LOCKED);
541 if ((stcb->asoc.primary_destination->dest_state & SCTP_ADDR_REACHABLE) &&
542 ((stcb->asoc.primary_destination->dest_state & SCTP_ADDR_PF) == 0) &&
543 (stcb->asoc.alternate != NULL)) {
544 sctp_free_remote_addr(stcb->asoc.alternate);
545 stcb->asoc.alternate = NULL;
547 if (response_required) {
548 m_reply = sctp_asconf_success_response(aph->correlation_id);
551 * Mobility adaptation. Ideally, when the reception of SET
552 * PRIMARY with DELETE IP ADDRESS of the previous primary
553 * destination, unacknowledged DATA are retransmitted
554 * immediately to the new primary destination for seamless
555 * handover. If the destination is UNCONFIRMED and marked to
556 * REQ_PRIM, The retransmission occur when reception of the
557 * HEARTBEAT-ACK. (See sctp_handle_heartbeat_ack in
558 * sctp_input.c) Also, when change of the primary
559 * destination, it is better that all subsequent new DATA
560 * containing already queued DATA are transmitted to the new
561 * primary destination. (by micchie)
563 if ((sctp_is_mobility_feature_on(stcb->sctp_ep,
564 SCTP_MOBILITY_BASE) ||
565 sctp_is_mobility_feature_on(stcb->sctp_ep,
566 SCTP_MOBILITY_FASTHANDOFF)) &&
567 sctp_is_mobility_feature_on(stcb->sctp_ep,
568 SCTP_MOBILITY_PRIM_DELETED) &&
569 (stcb->asoc.primary_destination->dest_state &
570 SCTP_ADDR_UNCONFIRMED) == 0) {
571 sctp_timer_stop(SCTP_TIMER_TYPE_PRIM_DELETED,
572 stcb->sctp_ep, stcb, NULL,
573 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_1);
574 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
575 SCTP_MOBILITY_FASTHANDOFF)) {
576 sctp_assoc_immediate_retrans(stcb,
577 stcb->asoc.primary_destination);
579 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
580 SCTP_MOBILITY_BASE)) {
581 sctp_move_chunks_from_net(stcb,
582 stcb->asoc.deleted_primary);
584 sctp_delete_prim_timer(stcb->sctp_ep, stcb);
587 /* couldn't set the requested primary address! */
588 SCTPDBG(SCTP_DEBUG_ASCONF1,
589 "process_asconf_set_primary: set primary failed!\n");
590 /* must have been an invalid address, so report */
591 m_reply = sctp_asconf_error_response(aph->correlation_id,
592 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *)aph,
600 * handles an ASCONF chunk.
601 * if all parameters are processed ok, send a plain (empty) ASCONF-ACK
604 sctp_handle_asconf(struct mbuf *m, unsigned int offset,
605 struct sockaddr *src,
606 struct sctp_asconf_chunk *cp, struct sctp_tcb *stcb,
609 struct sctp_association *asoc;
611 struct mbuf *n, *m_ack, *m_result, *m_tail;
612 struct sctp_asconf_ack_chunk *ack_cp;
613 struct sctp_asconf_paramhdr *aph;
614 struct sctp_ipv6addr_param *p_addr;
615 unsigned int asconf_limit, cnt;
616 int error = 0; /* did an error occur? */
618 /* asconf param buffer */
619 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE];
620 struct sctp_asconf_ack *ack, *ack_next;
622 /* verify minimum length */
623 if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_chunk)) {
624 SCTPDBG(SCTP_DEBUG_ASCONF1,
625 "handle_asconf: chunk too small = %xh\n",
626 ntohs(cp->ch.chunk_length));
630 serial_num = ntohl(cp->serial_number);
632 if (SCTP_TSN_GE(asoc->asconf_seq_in, serial_num)) {
633 /* got a duplicate ASCONF */
634 SCTPDBG(SCTP_DEBUG_ASCONF1,
635 "handle_asconf: got duplicate serial number = %xh\n",
638 } else if (serial_num != (asoc->asconf_seq_in + 1)) {
639 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: incorrect serial number = %xh (expected next = %xh)\n",
640 serial_num, asoc->asconf_seq_in + 1);
644 /* it's the expected "next" sequence number, so process it */
645 asoc->asconf_seq_in = serial_num; /* update sequence */
646 /* get length of all the param's in the ASCONF */
647 asconf_limit = offset + ntohs(cp->ch.chunk_length);
648 SCTPDBG(SCTP_DEBUG_ASCONF1,
649 "handle_asconf: asconf_limit=%u, sequence=%xh\n",
650 asconf_limit, serial_num);
653 /* delete old cache */
654 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: Now processing first ASCONF. Try to delete old cache\n");
656 TAILQ_FOREACH_SAFE(ack, &asoc->asconf_ack_sent, next, ack_next) {
657 if (ack->serial_number == serial_num)
659 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: delete old(%u) < first(%u)\n",
660 ack->serial_number, serial_num);
661 TAILQ_REMOVE(&asoc->asconf_ack_sent, ack, next);
662 if (ack->data != NULL) {
663 sctp_m_freem(ack->data);
665 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_asconf_ack), ack);
669 m_ack = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_ack_chunk), 0,
670 M_NOWAIT, 1, MT_DATA);
672 SCTPDBG(SCTP_DEBUG_ASCONF1,
673 "handle_asconf: couldn't get mbuf!\n");
676 m_tail = m_ack; /* current reply chain's tail */
678 /* fill in ASCONF-ACK header */
679 ack_cp = mtod(m_ack, struct sctp_asconf_ack_chunk *);
680 ack_cp->ch.chunk_type = SCTP_ASCONF_ACK;
681 ack_cp->ch.chunk_flags = 0;
682 ack_cp->serial_number = htonl(serial_num);
683 /* set initial lengths (eg. just an ASCONF-ACK), ntohx at the end! */
684 SCTP_BUF_LEN(m_ack) = sizeof(struct sctp_asconf_ack_chunk);
685 ack_cp->ch.chunk_length = sizeof(struct sctp_asconf_ack_chunk);
687 /* skip the lookup address parameter */
688 offset += sizeof(struct sctp_asconf_chunk);
689 p_addr = (struct sctp_ipv6addr_param *)sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), (uint8_t *)&aparam_buf);
690 if (p_addr == NULL) {
691 SCTPDBG(SCTP_DEBUG_ASCONF1,
692 "handle_asconf: couldn't get lookup addr!\n");
693 /* respond with a missing/invalid mandatory parameter error */
697 /* skip lookup addr */
698 offset += SCTP_SIZE32(ntohs(p_addr->ph.param_length));
699 /* get pointer to first asconf param in ASCONF */
700 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, sizeof(struct sctp_asconf_paramhdr), (uint8_t *)&aparam_buf);
702 SCTPDBG(SCTP_DEBUG_ASCONF1, "Empty ASCONF received?\n");
705 /* process through all parameters */
707 while (aph != NULL) {
708 unsigned int param_length, param_type;
710 param_type = ntohs(aph->ph.param_type);
711 param_length = ntohs(aph->ph.param_length);
712 if (offset + param_length > asconf_limit) {
713 /* parameter goes beyond end of chunk! */
719 if (param_length > sizeof(aparam_buf)) {
720 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) larger than buffer size!\n", param_length);
724 if (param_length < sizeof(struct sctp_asconf_paramhdr)) {
725 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) too short\n", param_length);
729 /* get the entire parameter */
730 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf);
732 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: couldn't get entire param\n");
736 switch (param_type) {
737 case SCTP_ADD_IP_ADDRESS:
738 m_result = sctp_process_asconf_add_ip(src, aph, stcb,
739 (cnt < SCTP_BASE_SYSCTL(sctp_hb_maxburst)), error);
742 case SCTP_DEL_IP_ADDRESS:
743 m_result = sctp_process_asconf_delete_ip(src, aph, stcb,
746 case SCTP_ERROR_CAUSE_IND:
747 /* not valid in an ASCONF chunk */
749 case SCTP_SET_PRIM_ADDR:
750 m_result = sctp_process_asconf_set_primary(src, aph,
754 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: sees a NAT VTAG state parameter\n");
756 case SCTP_SUCCESS_REPORT:
757 /* not valid in an ASCONF chunk */
759 case SCTP_ULP_ADAPTATION:
763 if ((param_type & 0x8000) == 0) {
764 /* Been told to STOP at this param */
765 asconf_limit = offset;
767 * FIX FIX - We need to call
768 * sctp_arethere_unrecognized_parameters()
769 * to get a operr and send it for any
770 * param's with the 0x4000 bit set OR do it
771 * here ourselves... note we still must STOP
772 * if the 0x8000 bit is clear.
775 /* unknown/invalid param type */
779 /* add any (error) result to the reply mbuf chain */
780 if (m_result != NULL) {
781 SCTP_BUF_NEXT(m_tail) = m_result;
783 ack_cp->ch.chunk_length += SCTP_BUF_LEN(m_result);
784 /* set flag to force success reports */
787 offset += SCTP_SIZE32(param_length);
788 /* update remaining ASCONF message length to process */
789 if (offset >= asconf_limit) {
790 /* no more data in the mbuf chain */
793 /* get pointer to next asconf param */
794 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset,
795 sizeof(struct sctp_asconf_paramhdr),
796 (uint8_t *)&aparam_buf);
798 /* can't get an asconf paramhdr */
799 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: can't get asconf param hdr!\n");
800 /* FIX ME - add error here... */
805 ack_cp->ch.chunk_length = htons(ack_cp->ch.chunk_length);
806 /* save the ASCONF-ACK reply */
807 ack = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_asconf_ack),
808 struct sctp_asconf_ack);
813 ack->serial_number = serial_num;
814 ack->last_sent_to = NULL;
817 for (n = m_ack; n != NULL; n = SCTP_BUF_NEXT(n)) {
818 ack->len += SCTP_BUF_LEN(n);
820 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_ack_sent, ack, next);
822 /* see if last_control_chunk_from is set properly (use IP src addr) */
823 if (stcb->asoc.last_control_chunk_from == NULL) {
825 * this could happen if the source address was just newly
828 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: looking up net for IP source address\n");
829 SCTPDBG(SCTP_DEBUG_ASCONF1, "Looking for IP source: ");
830 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, src);
831 /* look up the from address */
832 stcb->asoc.last_control_chunk_from = sctp_findnet(stcb, src);
834 if (stcb->asoc.last_control_chunk_from == NULL) {
835 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: IP source address not found?!\n");
842 * does the address match? returns 0 if not, 1 if so
845 sctp_asconf_addr_match(struct sctp_asconf_addr *aa, struct sockaddr *sa)
847 switch (sa->sa_family) {
852 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
854 if ((aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) &&
855 (memcmp(&aa->ap.addrp.addr, &sin6->sin6_addr,
856 sizeof(struct in6_addr)) == 0)) {
865 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
867 if ((aa->ap.addrp.ph.param_type == SCTP_IPV4_ADDRESS) &&
868 (memcmp(&aa->ap.addrp.addr, &sin->sin_addr,
869 sizeof(struct in_addr)) == 0)) {
882 * does the address match? returns 0 if not, 1 if so
885 sctp_addr_match(struct sctp_paramhdr *ph, struct sockaddr *sa)
887 #if defined(INET) || defined(INET6)
888 uint16_t param_type, param_length;
890 param_type = ntohs(ph->param_type);
891 param_length = ntohs(ph->param_length);
893 switch (sa->sa_family) {
898 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
899 struct sctp_ipv6addr_param *v6addr;
901 v6addr = (struct sctp_ipv6addr_param *)ph;
902 if ((param_type == SCTP_IPV6_ADDRESS) &&
903 (param_length == sizeof(struct sctp_ipv6addr_param)) &&
904 (memcmp(&v6addr->addr, &sin6->sin6_addr,
905 sizeof(struct in6_addr)) == 0)) {
914 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
915 struct sctp_ipv4addr_param *v4addr;
917 v4addr = (struct sctp_ipv4addr_param *)ph;
918 if ((param_type == SCTP_IPV4_ADDRESS) &&
919 (param_length == sizeof(struct sctp_ipv4addr_param)) &&
920 (memcmp(&v4addr->addr, &sin->sin_addr,
921 sizeof(struct in_addr)) == 0)) {
934 * Cleanup for non-responded/OP ERR'd ASCONF
937 sctp_asconf_cleanup(struct sctp_tcb *stcb)
940 * clear out any existing asconfs going out
942 sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, NULL,
943 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_2);
944 stcb->asoc.asconf_seq_out_acked = stcb->asoc.asconf_seq_out;
945 /* remove the old ASCONF on our outbound queue */
946 sctp_toss_old_asconf(stcb);
950 * cleanup any cached source addresses that may be topologically
951 * incorrect after a new address has been added to this interface.
954 sctp_asconf_nets_cleanup(struct sctp_tcb *stcb, struct sctp_ifn *ifn)
956 struct sctp_nets *net;
959 * Ideally, we want to only clear cached routes and source addresses
960 * that are topologically incorrect. But since there is no easy way
961 * to know whether the newly added address on the ifn would cause a
962 * routing change (i.e. a new egress interface would be chosen)
963 * without doing a new routing lookup and source address selection,
964 * we will (for now) just flush any cached route using a different
965 * ifn (and cached source addrs) and let output re-choose them
966 * during the next send on that net.
968 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
970 * clear any cached route (and cached source address) if the
971 * route's interface is NOT the same as the address change.
972 * If it's the same interface, just clear the cached source
975 if (SCTP_ROUTE_HAS_VALID_IFN(&net->ro) &&
977 (SCTP_GET_IF_INDEX_FROM_ROUTE(&net->ro) != ifn->ifn_index))) {
978 /* clear any cached route */
981 /* clear any cached source address */
982 if (net->src_addr_selected) {
983 sctp_free_ifa(net->ro._s_addr);
984 net->ro._s_addr = NULL;
985 net->src_addr_selected = 0;
991 sctp_assoc_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *dstnet)
995 if (dstnet->dest_state & SCTP_ADDR_UNCONFIRMED) {
998 if (stcb->asoc.deleted_primary == NULL) {
1002 if (!TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
1003 SCTPDBG(SCTP_DEBUG_ASCONF1, "assoc_immediate_retrans: Deleted primary is ");
1004 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &stcb->asoc.deleted_primary->ro._l_addr.sa);
1005 SCTPDBG(SCTP_DEBUG_ASCONF1, "Current Primary is ");
1006 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &stcb->asoc.primary_destination->ro._l_addr.sa);
1007 sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb,
1008 stcb->asoc.deleted_primary,
1009 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_3);
1010 stcb->asoc.num_send_timers_up--;
1011 if (stcb->asoc.num_send_timers_up < 0) {
1012 stcb->asoc.num_send_timers_up = 0;
1014 SCTP_TCB_LOCK_ASSERT(stcb);
1015 error = sctp_t3rxt_timer(stcb->sctp_ep, stcb,
1016 stcb->asoc.deleted_primary);
1018 SCTP_INP_DECR_REF(stcb->sctp_ep);
1021 SCTP_TCB_LOCK_ASSERT(stcb);
1022 #ifdef SCTP_AUDITING_ENABLED
1023 sctp_auditing(4, stcb->sctp_ep, stcb, stcb->asoc.deleted_primary);
1025 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED);
1026 if ((stcb->asoc.num_send_timers_up == 0) &&
1027 (stcb->asoc.sent_queue_cnt > 0)) {
1028 struct sctp_tmit_chunk *chk;
1030 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
1031 if (chk->whoTo != NULL) {
1036 sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, chk->whoTo);
1044 sctp_asconf_queue_mgmt(struct sctp_tcb *, struct sctp_ifa *, uint16_t);
1047 sctp_net_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *net)
1049 struct sctp_tmit_chunk *chk;
1051 SCTPDBG(SCTP_DEBUG_ASCONF1, "net_immediate_retrans: RTO is %d\n", net->RTO);
1052 sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, net,
1053 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_4);
1054 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
1055 net->error_count = 0;
1056 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
1057 if (chk->whoTo == net) {
1058 if (chk->sent < SCTP_DATAGRAM_RESEND) {
1059 chk->sent = SCTP_DATAGRAM_RESEND;
1060 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
1061 sctp_flight_size_decrease(chk);
1062 sctp_total_flight_decrease(stcb, chk);
1063 net->marked_retrans++;
1064 stcb->asoc.marked_retrans++;
1068 if (net->marked_retrans) {
1069 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED);
1074 sctp_path_check_and_react(struct sctp_tcb *stcb, struct sctp_ifa *newifa)
1076 struct sctp_nets *net;
1077 int addrnum, changed;
1080 * If number of local valid addresses is 1, the valid address is
1081 * probably newly added address. Several valid addresses in this
1082 * association. A source address may not be changed. Additionally,
1083 * they can be configured on a same interface as "alias" addresses.
1086 addrnum = sctp_local_addr_count(stcb);
1087 SCTPDBG(SCTP_DEBUG_ASCONF1, "p_check_react(): %d local addresses\n",
1090 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1091 /* clear any cached route and source address */
1092 RO_NHFREE(&net->ro);
1093 if (net->src_addr_selected) {
1094 sctp_free_ifa(net->ro._s_addr);
1095 net->ro._s_addr = NULL;
1096 net->src_addr_selected = 0;
1098 /* Retransmit unacknowledged DATA chunks immediately */
1099 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
1100 SCTP_MOBILITY_FASTHANDOFF)) {
1101 sctp_net_immediate_retrans(stcb, net);
1103 /* also, SET PRIMARY is maybe already sent */
1108 /* Multiple local addresses exist in the association. */
1109 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1110 /* clear any cached route and source address */
1111 RO_NHFREE(&net->ro);
1112 if (net->src_addr_selected) {
1113 sctp_free_ifa(net->ro._s_addr);
1114 net->ro._s_addr = NULL;
1115 net->src_addr_selected = 0;
1118 * Check if the nexthop is corresponding to the new address.
1119 * If the new address is corresponding to the current
1120 * nexthop, the path will be changed. If the new address is
1121 * NOT corresponding to the current nexthop, the path will
1124 SCTP_RTALLOC((sctp_route_t *)&net->ro,
1125 stcb->sctp_ep->def_vrf_id,
1126 stcb->sctp_ep->fibnum);
1127 if (net->ro.ro_nh == NULL)
1131 switch (net->ro._l_addr.sa.sa_family) {
1134 if (sctp_v4src_match_nexthop(newifa, (sctp_route_t *)&net->ro)) {
1141 if (sctp_v6src_match_nexthop(
1142 &newifa->address.sin6, (sctp_route_t *)&net->ro)) {
1151 * if the newly added address does not relate routing
1152 * information, we skip.
1156 /* Retransmit unacknowledged DATA chunks immediately */
1157 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
1158 SCTP_MOBILITY_FASTHANDOFF)) {
1159 sctp_net_immediate_retrans(stcb, net);
1161 /* Send SET PRIMARY for this new address */
1162 if (net == stcb->asoc.primary_destination) {
1163 (void)sctp_asconf_queue_mgmt(stcb, newifa,
1164 SCTP_SET_PRIM_ADDR);
1170 * process an ADD/DELETE IP ack from peer.
1171 * addr: corresponding sctp_ifa to the address being added/deleted.
1172 * type: SCTP_ADD_IP_ADDRESS or SCTP_DEL_IP_ADDRESS.
1173 * flag: 1=success, 0=failure.
1176 sctp_asconf_addr_mgmt_ack(struct sctp_tcb *stcb, struct sctp_ifa *addr, uint32_t flag)
1179 * do the necessary asoc list work- if we get a failure indication,
1180 * leave the address on the assoc's restricted list. If we get a
1181 * success indication, remove the address from the restricted list.
1184 * Note: this will only occur for ADD_IP_ADDRESS, since
1185 * DEL_IP_ADDRESS is never actually added to the list...
1188 /* success case, so remove from the restricted list */
1189 sctp_del_local_addr_restricted(stcb, addr);
1191 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
1192 SCTP_MOBILITY_BASE) ||
1193 sctp_is_mobility_feature_on(stcb->sctp_ep,
1194 SCTP_MOBILITY_FASTHANDOFF)) {
1195 sctp_path_check_and_react(stcb, addr);
1198 /* clear any cached/topologically incorrect source addresses */
1199 sctp_asconf_nets_cleanup(stcb, addr->ifn_p);
1201 /* else, leave it on the list */
1205 * add an asconf add/delete/set primary IP address parameter to the queue.
1206 * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR.
1207 * returns 0 if queued, -1 if not queued/removed.
1208 * NOTE: if adding, but a delete for the same address is already scheduled
1209 * (and not yet sent out), simply remove it from queue. Same for deleting
1210 * an address already scheduled for add. If a duplicate operation is found,
1211 * ignore the new one.
1214 sctp_asconf_queue_mgmt(struct sctp_tcb *stcb, struct sctp_ifa *ifa,
1217 struct sctp_asconf_addr *aa, *aa_next;
1219 /* make sure the request isn't already in the queue */
1220 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) {
1221 /* address match? */
1222 if (sctp_asconf_addr_match(aa, &ifa->address.sa) == 0)
1225 * is the request already in queue but not sent? pass the
1226 * request already sent in order to resolve the following
1227 * case: 1. arrival of ADD, then sent 2. arrival of DEL. we
1228 * can't remove the ADD request already sent 3. arrival of
1231 if (aa->ap.aph.ph.param_type == type && aa->sent == 0) {
1234 /* is the negative request already in queue, and not sent */
1235 if ((aa->sent == 0) && (type == SCTP_ADD_IP_ADDRESS) &&
1236 (aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS)) {
1237 /* add requested, delete already queued */
1238 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1239 /* remove the ifa from the restricted list */
1240 sctp_del_local_addr_restricted(stcb, ifa);
1241 /* free the asconf param */
1242 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1243 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_mgmt: add removes queued entry\n");
1246 if ((aa->sent == 0) && (type == SCTP_DEL_IP_ADDRESS) &&
1247 (aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS)) {
1248 /* delete requested, add already queued */
1249 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1250 /* remove the aa->ifa from the restricted list */
1251 sctp_del_local_addr_restricted(stcb, aa->ifa);
1252 /* free the asconf param */
1253 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1254 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_mgmt: delete removes queued entry\n");
1259 /* adding new request to the queue */
1260 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
1263 /* didn't get memory */
1264 SCTPDBG(SCTP_DEBUG_ASCONF1, "asconf_queue_mgmt: failed to get memory!\n");
1267 aa->special_del = 0;
1268 /* fill in asconf address parameter fields */
1269 /* top level elements are "networked" during send */
1270 aa->ap.aph.ph.param_type = type;
1272 atomic_add_int(&ifa->refcount, 1);
1273 /* correlation_id filled in during send routine later... */
1274 switch (ifa->address.sa.sa_family) {
1278 struct sockaddr_in6 *sin6;
1280 sin6 = &ifa->address.sin6;
1281 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
1282 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param));
1283 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) +
1284 sizeof(struct sctp_ipv6addr_param);
1285 memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr,
1286 sizeof(struct in6_addr));
1293 struct sockaddr_in *sin;
1295 sin = &ifa->address.sin;
1296 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
1297 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param));
1298 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) +
1299 sizeof(struct sctp_ipv4addr_param);
1300 memcpy(&aa->ap.addrp.addr, &sin->sin_addr,
1301 sizeof(struct in_addr));
1306 /* invalid family! */
1307 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1311 aa->sent = 0; /* clear sent flag */
1313 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
1315 if (SCTP_BASE_SYSCTL(sctp_debug_on) & SCTP_DEBUG_ASCONF2) {
1316 if (type == SCTP_ADD_IP_ADDRESS) {
1317 SCTP_PRINTF("asconf_queue_mgmt: inserted asconf ADD_IP_ADDRESS: ");
1318 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa);
1319 } else if (type == SCTP_DEL_IP_ADDRESS) {
1320 SCTP_PRINTF("asconf_queue_mgmt: appended asconf DEL_IP_ADDRESS: ");
1321 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa);
1323 SCTP_PRINTF("asconf_queue_mgmt: appended asconf SET_PRIM_ADDR: ");
1324 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa);
1333 * add an asconf operation for the given ifa and type.
1334 * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR.
1335 * returns 0 if completed, -1 if not completed, 1 if immediate send is
1339 sctp_asconf_queue_add(struct sctp_tcb *stcb, struct sctp_ifa *ifa,
1343 int pending_delete_queued = 0;
1346 /* see if peer supports ASCONF */
1347 if (stcb->asoc.asconf_supported == 0) {
1352 * if this is deleting the last address from the assoc, mark it as
1355 if ((type == SCTP_DEL_IP_ADDRESS) && !stcb->asoc.asconf_del_pending) {
1356 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1357 last = (sctp_local_addr_count(stcb) == 0);
1359 last = (sctp_local_addr_count(stcb) == 1);
1362 /* set the pending delete info only */
1363 stcb->asoc.asconf_del_pending = 1;
1364 stcb->asoc.asconf_addr_del_pending = ifa;
1365 atomic_add_int(&ifa->refcount, 1);
1366 SCTPDBG(SCTP_DEBUG_ASCONF2,
1367 "asconf_queue_add: mark delete last address pending\n");
1372 /* queue an asconf parameter */
1373 status = sctp_asconf_queue_mgmt(stcb, ifa, type);
1376 * if this is an add, and there is a delete also pending (i.e. the
1377 * last local address is being changed), queue the pending delete
1380 if ((type == SCTP_ADD_IP_ADDRESS) && stcb->asoc.asconf_del_pending && (status == 0)) {
1381 /* queue in the pending delete */
1382 if (sctp_asconf_queue_mgmt(stcb,
1383 stcb->asoc.asconf_addr_del_pending,
1384 SCTP_DEL_IP_ADDRESS) == 0) {
1385 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_add: queuing pending delete\n");
1386 pending_delete_queued = 1;
1387 /* clear out the pending delete info */
1388 stcb->asoc.asconf_del_pending = 0;
1389 sctp_free_ifa(stcb->asoc.asconf_addr_del_pending);
1390 stcb->asoc.asconf_addr_del_pending = NULL;
1394 if (pending_delete_queued) {
1395 struct sctp_nets *net;
1398 * since we know that the only/last address is now being
1399 * changed in this case, reset the cwnd/rto on all nets to
1400 * start as a new address and path. Also clear the error
1401 * counts to give the assoc the best chance to complete the
1404 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1405 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb,
1408 net->error_count = 0;
1410 stcb->asoc.overall_error_count = 0;
1411 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) {
1412 sctp_misc_ints(SCTP_THRESHOLD_CLEAR,
1413 stcb->asoc.overall_error_count,
1415 SCTP_FROM_SCTP_ASCONF,
1419 /* queue in an advisory set primary too */
1420 (void)sctp_asconf_queue_mgmt(stcb, ifa, SCTP_SET_PRIM_ADDR);
1421 /* let caller know we should send this out immediately */
1428 * add an asconf delete IP address parameter to the queue by sockaddr and
1429 * possibly with no sctp_ifa available. This is only called by the routine
1430 * that checks the addresses in an INIT-ACK against the current address list.
1431 * returns 0 if completed, non-zero if not completed.
1432 * NOTE: if an add is already scheduled (and not yet sent out), simply
1433 * remove it from queue. If a duplicate operation is found, ignore the
1437 sctp_asconf_queue_sa_delete(struct sctp_tcb *stcb, struct sockaddr *sa)
1439 struct sctp_ifa *ifa;
1440 struct sctp_asconf_addr *aa, *aa_next;
1445 /* see if peer supports ASCONF */
1446 if (stcb->asoc.asconf_supported == 0) {
1449 /* make sure the request isn't already in the queue */
1450 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) {
1451 /* address match? */
1452 if (sctp_asconf_addr_match(aa, sa) == 0)
1454 /* is the request already in queue (sent or not) */
1455 if (aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) {
1458 /* is the negative request already in queue, and not sent */
1461 if (aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS) {
1462 /* add already queued, so remove existing entry */
1463 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1464 sctp_del_local_addr_restricted(stcb, aa->ifa);
1465 /* free the entry */
1466 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1471 /* find any existing ifa-- NOTE ifa CAN be allowed to be NULL */
1472 ifa = sctp_find_ifa_by_addr(sa, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
1474 /* adding new request to the queue */
1475 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
1478 /* didn't get memory */
1479 SCTPDBG(SCTP_DEBUG_ASCONF1,
1480 "sctp_asconf_queue_sa_delete: failed to get memory!\n");
1483 aa->special_del = 0;
1484 /* fill in asconf address parameter fields */
1485 /* top level elements are "networked" during send */
1486 aa->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS;
1489 atomic_add_int(&ifa->refcount, 1);
1490 /* correlation_id filled in during send routine later... */
1491 switch (sa->sa_family) {
1496 struct sockaddr_in6 *sin6;
1498 sin6 = (struct sockaddr_in6 *)sa;
1499 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
1500 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param));
1501 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv6addr_param);
1502 memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr,
1503 sizeof(struct in6_addr));
1511 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
1513 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
1514 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param));
1515 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv4addr_param);
1516 memcpy(&aa->ap.addrp.addr, &sin->sin_addr,
1517 sizeof(struct in_addr));
1522 /* invalid family! */
1523 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1528 aa->sent = 0; /* clear sent flag */
1530 /* delete goes to the back of the queue */
1531 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
1533 /* sa_ignore MEMLEAK {memory is put on the tailq} */
1538 * find a specific asconf param on our "sent" queue
1540 static struct sctp_asconf_addr *
1541 sctp_asconf_find_param(struct sctp_tcb *stcb, uint32_t correlation_id)
1543 struct sctp_asconf_addr *aa;
1545 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
1546 if (aa->ap.aph.correlation_id == correlation_id &&
1552 /* didn't find it */
1557 * process an SCTP_ERROR_CAUSE_IND for a ASCONF-ACK parameter and do
1558 * notifications based on the error response
1561 sctp_asconf_process_error(struct sctp_tcb *stcb SCTP_UNUSED,
1562 struct sctp_asconf_paramhdr *aph)
1564 struct sctp_error_cause *eh;
1565 struct sctp_paramhdr *ph;
1566 uint16_t param_type;
1567 uint16_t error_code;
1569 eh = (struct sctp_error_cause *)(aph + 1);
1570 ph = (struct sctp_paramhdr *)(eh + 1);
1571 /* validate lengths */
1572 if (htons(eh->length) + sizeof(struct sctp_error_cause) >
1573 htons(aph->ph.param_length)) {
1574 /* invalid error cause length */
1575 SCTPDBG(SCTP_DEBUG_ASCONF1,
1576 "asconf_process_error: cause element too long\n");
1579 if (htons(ph->param_length) + sizeof(struct sctp_paramhdr) >
1580 htons(eh->length)) {
1581 /* invalid included TLV length */
1582 SCTPDBG(SCTP_DEBUG_ASCONF1,
1583 "asconf_process_error: included TLV too long\n");
1586 /* which error code ? */
1587 error_code = ntohs(eh->code);
1588 param_type = ntohs(aph->ph.param_type);
1589 /* FIX: this should go back up the REMOTE_ERROR ULP notify */
1590 switch (error_code) {
1591 case SCTP_CAUSE_RESOURCE_SHORTAGE:
1592 /* we allow ourselves to "try again" for this error */
1595 /* peer can't handle it... */
1596 switch (param_type) {
1597 case SCTP_ADD_IP_ADDRESS:
1598 case SCTP_DEL_IP_ADDRESS:
1599 case SCTP_SET_PRIM_ADDR:
1608 * process an asconf queue param.
1609 * aparam: parameter to process, will be removed from the queue.
1610 * flag: 1=success case, 0=failure case
1613 sctp_asconf_process_param_ack(struct sctp_tcb *stcb,
1614 struct sctp_asconf_addr *aparam, uint32_t flag)
1616 uint16_t param_type;
1618 /* process this param */
1619 param_type = aparam->ap.aph.ph.param_type;
1620 switch (param_type) {
1621 case SCTP_ADD_IP_ADDRESS:
1622 SCTPDBG(SCTP_DEBUG_ASCONF1,
1623 "process_param_ack: added IP address\n");
1624 sctp_asconf_addr_mgmt_ack(stcb, aparam->ifa, flag);
1626 case SCTP_DEL_IP_ADDRESS:
1627 SCTPDBG(SCTP_DEBUG_ASCONF1,
1628 "process_param_ack: deleted IP address\n");
1629 /* nothing really to do... lists already updated */
1631 case SCTP_SET_PRIM_ADDR:
1632 SCTPDBG(SCTP_DEBUG_ASCONF1,
1633 "process_param_ack: set primary IP address\n");
1634 /* nothing to do... peer may start using this addr */
1637 /* should NEVER happen */
1641 /* remove the param and free it */
1642 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aparam, next);
1644 sctp_free_ifa(aparam->ifa);
1645 SCTP_FREE(aparam, SCTP_M_ASC_ADDR);
1649 * cleanup from a bad asconf ack parameter
1652 sctp_asconf_ack_clear(struct sctp_tcb *stcb SCTP_UNUSED)
1654 /* assume peer doesn't really know how to do asconfs */
1655 /* XXX we could free the pending queue here */
1660 sctp_handle_asconf_ack(struct mbuf *m, int offset,
1661 struct sctp_asconf_ack_chunk *cp, struct sctp_tcb *stcb,
1662 struct sctp_nets *net, int *abort_no_unlock)
1664 struct sctp_association *asoc;
1665 uint32_t serial_num;
1666 uint16_t ack_length;
1667 struct sctp_asconf_paramhdr *aph;
1668 struct sctp_asconf_addr *aa, *aa_next;
1669 uint32_t last_error_id = 0; /* last error correlation id */
1671 struct sctp_asconf_addr *ap;
1673 /* asconf param buffer */
1674 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE];
1676 /* verify minimum length */
1677 if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_ack_chunk)) {
1678 SCTPDBG(SCTP_DEBUG_ASCONF1,
1679 "handle_asconf_ack: chunk too small = %xh\n",
1680 ntohs(cp->ch.chunk_length));
1684 serial_num = ntohl(cp->serial_number);
1687 * NOTE: we may want to handle this differently- currently, we will
1688 * abort when we get an ack for the expected serial number + 1 (eg.
1689 * we didn't send it), process an ack normally if it is the expected
1690 * serial number, and re-send the previous ack for *ALL* other
1695 * if the serial number is the next expected, but I didn't send it,
1696 * abort the asoc, since someone probably just hijacked us...
1698 if (serial_num == (asoc->asconf_seq_out + 1)) {
1699 struct mbuf *op_err;
1700 char msg[SCTP_DIAG_INFO_LEN];
1702 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got unexpected next serial number! Aborting asoc!\n");
1703 SCTP_SNPRINTF(msg, sizeof(msg), "Never sent serial number %8.8x", serial_num);
1704 op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
1705 sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, false, SCTP_SO_NOT_LOCKED);
1706 *abort_no_unlock = 1;
1709 if (serial_num != asoc->asconf_seq_out_acked + 1) {
1710 /* got a duplicate/unexpected ASCONF-ACK */
1711 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got duplicate/unexpected serial number = %xh (expected = %xh)\n",
1712 serial_num, asoc->asconf_seq_out_acked + 1);
1716 if (serial_num == asoc->asconf_seq_out - 1) {
1717 /* stop our timer */
1718 sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, NULL,
1719 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_5);
1722 /* process the ASCONF-ACK contents */
1723 ack_length = ntohs(cp->ch.chunk_length) -
1724 sizeof(struct sctp_asconf_ack_chunk);
1725 offset += sizeof(struct sctp_asconf_ack_chunk);
1726 /* process through all parameters */
1727 while (ack_length >= sizeof(struct sctp_asconf_paramhdr)) {
1728 unsigned int param_length, param_type;
1730 /* get pointer to next asconf parameter */
1731 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset,
1732 sizeof(struct sctp_asconf_paramhdr), aparam_buf);
1734 /* can't get an asconf paramhdr */
1735 sctp_asconf_ack_clear(stcb);
1738 param_type = ntohs(aph->ph.param_type);
1739 param_length = ntohs(aph->ph.param_length);
1740 if (param_length > ack_length) {
1741 sctp_asconf_ack_clear(stcb);
1744 if (param_length < sizeof(struct sctp_asconf_paramhdr)) {
1745 sctp_asconf_ack_clear(stcb);
1748 /* get the complete parameter... */
1749 if (param_length > sizeof(aparam_buf)) {
1750 SCTPDBG(SCTP_DEBUG_ASCONF1,
1751 "param length (%u) larger than buffer size!\n", param_length);
1752 sctp_asconf_ack_clear(stcb);
1755 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf);
1757 sctp_asconf_ack_clear(stcb);
1760 /* correlation_id is transparent to peer, no ntohl needed */
1761 id = aph->correlation_id;
1763 switch (param_type) {
1764 case SCTP_ERROR_CAUSE_IND:
1766 /* find the corresponding asconf param in our queue */
1767 ap = sctp_asconf_find_param(stcb, id);
1769 /* hmm... can't find this in our queue! */
1772 /* process the parameter, failed flag */
1773 sctp_asconf_process_param_ack(stcb, ap, 0);
1774 /* process the error response */
1775 sctp_asconf_process_error(stcb, aph);
1777 case SCTP_SUCCESS_REPORT:
1778 /* find the corresponding asconf param in our queue */
1779 ap = sctp_asconf_find_param(stcb, id);
1781 /* hmm... can't find this in our queue! */
1784 /* process the parameter, success flag */
1785 sctp_asconf_process_param_ack(stcb, ap, 1);
1791 /* update remaining ASCONF-ACK message length to process */
1792 if (ack_length > SCTP_SIZE32(param_length)) {
1793 ack_length -= SCTP_SIZE32(param_length);
1797 offset += SCTP_SIZE32(param_length);
1801 * if there are any "sent" params still on the queue, these are
1802 * implicitly "success", or "failed" (if we got an error back) ...
1803 * so process these appropriately
1805 * we assume that the correlation_id's are monotonically increasing
1806 * beginning from 1 and that we don't have *that* many outstanding
1809 if (last_error_id == 0)
1810 last_error_id--; /* set to "max" value */
1811 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) {
1812 if (aa->sent == 1) {
1814 * implicitly successful or failed if correlation_id
1815 * < last_error_id, then success else, failure
1817 if (aa->ap.aph.correlation_id < last_error_id)
1818 sctp_asconf_process_param_ack(stcb, aa, 1);
1820 sctp_asconf_process_param_ack(stcb, aa, 0);
1823 * since we always process in order (FIFO queue) if
1824 * we reach one that hasn't been sent, the rest
1825 * should not have been sent either. so, we're
1832 /* update the next sequence number to use */
1833 asoc->asconf_seq_out_acked++;
1834 /* remove the old ASCONF on our outbound queue */
1835 sctp_toss_old_asconf(stcb);
1836 if (!TAILQ_EMPTY(&stcb->asoc.asconf_queue)) {
1837 #ifdef SCTP_TIMER_BASED_ASCONF
1838 /* we have more params, so restart our timer */
1839 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep,
1842 /* we have more params, so send out more */
1843 sctp_send_asconf(stcb, net, SCTP_ADDR_NOT_LOCKED);
1850 sctp_is_scopeid_in_nets(struct sctp_tcb *stcb, struct sockaddr *sa)
1852 struct sockaddr_in6 *sin6, *net6;
1853 struct sctp_nets *net;
1855 if (sa->sa_family != AF_INET6) {
1859 sin6 = (struct sockaddr_in6 *)sa;
1860 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) == 0) {
1861 /* not link local address */
1864 /* hunt through our destination nets list for this scope_id */
1865 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1866 if (((struct sockaddr *)(&net->ro._l_addr))->sa_family !=
1869 net6 = (struct sockaddr_in6 *)&net->ro._l_addr;
1870 if (IN6_IS_ADDR_LINKLOCAL(&net6->sin6_addr) == 0)
1872 if (sctp_is_same_scope(sin6, net6)) {
1877 /* didn't find one */
1883 * address management functions
1886 sctp_addr_mgmt_assoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
1887 struct sctp_ifa *ifa, uint16_t type, int addr_locked)
1891 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0 ||
1892 sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_ASCONF)) {
1893 /* subset bound, no ASCONF allowed case, so ignore */
1897 * note: we know this is not the subset bound, no ASCONF case eg.
1898 * this is boundall or subset bound w/ASCONF allowed
1901 /* first, make sure that the address is IPv4 or IPv6 and not jailed */
1902 switch (ifa->address.sa.sa_family) {
1905 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1906 &ifa->address.sin6.sin6_addr) != 0) {
1913 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1914 &ifa->address.sin.sin_addr) != 0) {
1923 /* make sure we're "allowed" to add this type of addr */
1924 if (ifa->address.sa.sa_family == AF_INET6) {
1925 /* invalid if we're not a v6 endpoint */
1926 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0)
1928 /* is the v6 addr really valid ? */
1929 if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) {
1934 /* put this address on the "pending/do not use yet" list */
1935 sctp_add_local_addr_restricted(stcb, ifa);
1937 * check address scope if address is out of scope, don't queue
1938 * anything... note: this would leave the address on both inp and
1941 switch (ifa->address.sa.sa_family) {
1945 struct sockaddr_in6 *sin6;
1947 sin6 = &ifa->address.sin6;
1948 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1949 /* we skip unspecified addresses */
1952 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1953 if (stcb->asoc.scope.local_scope == 0) {
1956 /* is it the right link local scope? */
1957 if (sctp_is_scopeid_in_nets(stcb, &ifa->address.sa) == 0) {
1961 if (stcb->asoc.scope.site_scope == 0 &&
1962 IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)) {
1971 struct sockaddr_in *sin;
1973 /* invalid if we are a v6 only endpoint */
1974 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1975 SCTP_IPV6_V6ONLY(inp))
1978 sin = &ifa->address.sin;
1979 if (sin->sin_addr.s_addr == 0) {
1980 /* we skip unspecified addresses */
1983 if (stcb->asoc.scope.ipv4_local_scope == 0 &&
1984 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) {
1991 /* else, not AF_INET or AF_INET6, so skip */
1995 /* queue an asconf for this address add/delete */
1996 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF)) {
1997 /* does the peer do asconf? */
1998 if (stcb->asoc.asconf_supported) {
1999 /* queue an asconf for this addr */
2000 status = sctp_asconf_queue_add(stcb, ifa, type);
2003 * if queued ok, and in the open state, send out the
2004 * ASCONF. If in the non-open state, these will be
2005 * sent when the state goes open.
2008 ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
2009 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED))) {
2010 #ifdef SCTP_TIMER_BASED_ASCONF
2011 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, inp,
2012 stcb, stcb->asoc.primary_destination);
2014 sctp_send_asconf(stcb, NULL, addr_locked);
2022 sctp_asconf_iterator_ep(struct sctp_inpcb *inp, void *ptr, uint32_t val SCTP_UNUSED)
2024 struct sctp_asconf_iterator *asc;
2025 struct sctp_ifa *ifa;
2026 struct sctp_laddr *l;
2027 int cnt_invalid = 0;
2029 asc = (struct sctp_asconf_iterator *)ptr;
2030 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) {
2032 switch (ifa->address.sa.sa_family) {
2035 /* invalid if we're not a v6 endpoint */
2036 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
2038 if (asc->cnt == cnt_invalid)
2046 /* invalid if we are a v6 only endpoint */
2047 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2048 SCTP_IPV6_V6ONLY(inp)) {
2050 if (asc->cnt == cnt_invalid)
2057 /* invalid address family */
2059 if (asc->cnt == cnt_invalid)
2067 sctp_asconf_iterator_ep_end(struct sctp_inpcb *inp, void *ptr, uint32_t val SCTP_UNUSED)
2069 struct sctp_ifa *ifa;
2070 struct sctp_asconf_iterator *asc;
2071 struct sctp_laddr *laddr, *nladdr, *l;
2073 /* Only for specific case not bound all */
2074 asc = (struct sctp_asconf_iterator *)ptr;
2075 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) {
2077 if (l->action == SCTP_ADD_IP_ADDRESS) {
2078 LIST_FOREACH(laddr, &inp->sctp_addr_list,
2080 if (laddr->ifa == ifa) {
2085 } else if (l->action == SCTP_DEL_IP_ADDRESS) {
2086 LIST_FOREACH_SAFE(laddr, &inp->sctp_addr_list, sctp_nxt_addr, nladdr) {
2087 /* remove only after all guys are done */
2088 if (laddr->ifa == ifa) {
2089 sctp_del_local_addr_ep(inp, ifa);
2098 sctp_asconf_iterator_stcb(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
2099 void *ptr, uint32_t val SCTP_UNUSED)
2101 struct sctp_asconf_iterator *asc;
2102 struct sctp_ifa *ifa;
2103 struct sctp_laddr *l;
2104 int cnt_invalid = 0;
2108 asc = (struct sctp_asconf_iterator *)ptr;
2109 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) {
2113 /* address's vrf_id must be the vrf_id of the assoc */
2114 if (ifa->vrf_id != stcb->asoc.vrf_id) {
2118 /* Same checks again for assoc */
2119 switch (ifa->address.sa.sa_family) {
2123 /* invalid if we're not a v6 endpoint */
2124 struct sockaddr_in6 *sin6;
2126 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
2128 if (asc->cnt == cnt_invalid)
2133 sin6 = &ifa->address.sin6;
2134 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2135 /* we skip unspecified addresses */
2138 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
2139 &sin6->sin6_addr) != 0) {
2142 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
2143 if (stcb->asoc.scope.local_scope == 0) {
2146 /* is it the right link local scope? */
2147 if (sctp_is_scopeid_in_nets(stcb, &ifa->address.sa) == 0) {
2157 /* invalid if we are a v6 only endpoint */
2158 struct sockaddr_in *sin;
2160 /* invalid if we are a v6 only endpoint */
2161 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2162 SCTP_IPV6_V6ONLY(inp))
2165 sin = &ifa->address.sin;
2166 if (sin->sin_addr.s_addr == 0) {
2167 /* we skip unspecified addresses */
2170 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
2171 &sin->sin_addr) != 0) {
2174 if (stcb->asoc.scope.ipv4_local_scope == 0 &&
2175 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) {
2178 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2179 SCTP_IPV6_V6ONLY(inp)) {
2181 if (asc->cnt == cnt_invalid)
2190 /* invalid address family */
2192 if (asc->cnt == cnt_invalid)
2198 if (type == SCTP_ADD_IP_ADDRESS) {
2199 /* prevent this address from being used as a source */
2200 sctp_add_local_addr_restricted(stcb, ifa);
2201 } else if (type == SCTP_DEL_IP_ADDRESS) {
2202 struct sctp_nets *net;
2204 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2205 /* delete this address if cached */
2206 if (net->ro._s_addr == ifa) {
2207 sctp_free_ifa(net->ro._s_addr);
2208 net->ro._s_addr = NULL;
2209 net->src_addr_selected = 0;
2210 RO_NHFREE(&net->ro);
2212 * Now we deleted our src address,
2213 * should we not also now reset the
2214 * cwnd/rto to start as if its a new
2217 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
2221 } else if (type == SCTP_SET_PRIM_ADDR) {
2222 if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
2223 /* must validate the ifa is in the ep */
2224 if (sctp_is_addr_in_ep(stcb->sctp_ep, ifa) == 0) {
2228 /* Need to check scopes for this guy */
2229 if (sctp_is_address_in_scope(ifa, &stcb->asoc.scope, 0) == 0) {
2234 /* queue an asconf for this address add/delete */
2235 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF) &&
2236 stcb->asoc.asconf_supported == 1) {
2237 /* queue an asconf for this addr */
2238 status = sctp_asconf_queue_add(stcb, ifa, type);
2240 * if queued ok, and in the open state, update the
2241 * count of queued params. If in the non-open
2242 * state, these get sent when the assoc goes open.
2244 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
2245 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
2253 * If we have queued params in the open state, send out an ASCONF.
2255 if (num_queued > 0) {
2256 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2261 sctp_asconf_iterator_end(void *ptr, uint32_t val SCTP_UNUSED)
2263 struct sctp_asconf_iterator *asc;
2264 struct sctp_ifa *ifa;
2265 struct sctp_laddr *l, *nl;
2267 asc = (struct sctp_asconf_iterator *)ptr;
2268 LIST_FOREACH_SAFE(l, &asc->list_of_work, sctp_nxt_addr, nl) {
2270 if (l->action == SCTP_ADD_IP_ADDRESS) {
2271 /* Clear the defer use flag */
2272 ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE;
2275 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_laddr), l);
2276 SCTP_DECR_LADDR_COUNT();
2278 SCTP_FREE(asc, SCTP_M_ASC_IT);
2282 * sa is the sockaddr to ask the peer to set primary to.
2283 * returns: 0 = completed, -1 = error
2286 sctp_set_primary_ip_address_sa(struct sctp_tcb *stcb, struct sockaddr *sa)
2289 struct sctp_ifa *ifa;
2291 /* find the ifa for the desired set primary */
2292 vrf_id = stcb->asoc.vrf_id;
2293 ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED);
2295 /* Invalid address */
2299 /* queue an ASCONF:SET_PRIM_ADDR to be sent */
2300 if (!sctp_asconf_queue_add(stcb, ifa, SCTP_SET_PRIM_ADDR)) {
2301 /* set primary queuing succeeded */
2302 SCTPDBG(SCTP_DEBUG_ASCONF1,
2303 "set_primary_ip_address_sa: queued on tcb=%p, ",
2305 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
2306 if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
2307 (SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
2308 #ifdef SCTP_TIMER_BASED_ASCONF
2309 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
2310 stcb->sctp_ep, stcb,
2311 stcb->asoc.primary_destination);
2313 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2317 SCTPDBG(SCTP_DEBUG_ASCONF1, "set_primary_ip_address_sa: failed to add to queue on tcb=%p, ",
2319 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
2326 sctp_is_addr_pending(struct sctp_tcb *stcb, struct sctp_ifa *sctp_ifa)
2328 struct sctp_tmit_chunk *chk, *nchk;
2329 unsigned int offset, asconf_limit;
2330 struct sctp_asconf_chunk *acp;
2331 struct sctp_asconf_paramhdr *aph;
2332 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE];
2333 struct sctp_paramhdr *ph;
2334 int add_cnt, del_cnt;
2335 uint16_t last_param_type;
2337 add_cnt = del_cnt = 0;
2338 last_param_type = 0;
2339 TAILQ_FOREACH_SAFE(chk, &stcb->asoc.asconf_send_queue, sctp_next, nchk) {
2340 if (chk->data == NULL) {
2341 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: No mbuf data?\n");
2345 acp = mtod(chk->data, struct sctp_asconf_chunk *);
2346 offset += sizeof(struct sctp_asconf_chunk);
2347 asconf_limit = ntohs(acp->ch.chunk_length);
2348 ph = (struct sctp_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_paramhdr), aparam_buf);
2350 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: couldn't get lookup addr!\n");
2353 offset += ntohs(ph->param_length);
2355 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_asconf_paramhdr), aparam_buf);
2357 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: Empty ASCONF will be sent?\n");
2360 while (aph != NULL) {
2361 unsigned int param_length, param_type;
2363 param_type = ntohs(aph->ph.param_type);
2364 param_length = ntohs(aph->ph.param_length);
2365 if (offset + param_length > asconf_limit) {
2366 /* parameter goes beyond end of chunk! */
2369 if (param_length > sizeof(aparam_buf)) {
2370 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: param length (%u) larger than buffer size!\n", param_length);
2373 if (param_length <= sizeof(struct sctp_paramhdr)) {
2374 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: param length(%u) too short\n", param_length);
2378 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, param_length, aparam_buf);
2380 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: couldn't get entire param\n");
2384 ph = (struct sctp_paramhdr *)(aph + 1);
2385 if (sctp_addr_match(ph, &sctp_ifa->address.sa) != 0) {
2386 switch (param_type) {
2387 case SCTP_ADD_IP_ADDRESS:
2390 case SCTP_DEL_IP_ADDRESS:
2396 last_param_type = param_type;
2399 offset += SCTP_SIZE32(param_length);
2400 if (offset >= asconf_limit) {
2401 /* no more data in the mbuf chain */
2404 /* get pointer to next asconf param */
2405 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_asconf_paramhdr), aparam_buf);
2410 * we want to find the sequences which consist of ADD -> DEL -> ADD
2413 if (add_cnt > del_cnt ||
2414 (add_cnt == del_cnt && last_param_type == SCTP_ADD_IP_ADDRESS)) {
2420 static struct sockaddr *
2421 sctp_find_valid_localaddr(struct sctp_tcb *stcb, int addr_locked)
2423 struct sctp_vrf *vrf = NULL;
2424 struct sctp_ifn *sctp_ifn;
2425 struct sctp_ifa *sctp_ifa;
2427 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2428 SCTP_IPI_ADDR_RLOCK();
2429 vrf = sctp_find_vrf(stcb->asoc.vrf_id);
2431 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2432 SCTP_IPI_ADDR_RUNLOCK();
2435 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
2436 if (stcb->asoc.scope.loopback_scope == 0 &&
2437 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
2438 /* Skip if loopback_scope not set */
2441 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
2442 switch (sctp_ifa->address.sa.sa_family) {
2445 if (stcb->asoc.scope.ipv4_addr_legal) {
2446 struct sockaddr_in *sin;
2448 sin = &sctp_ifa->address.sin;
2449 if (sin->sin_addr.s_addr == 0) {
2456 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
2457 &sin->sin_addr) != 0) {
2460 if (stcb->asoc.scope.ipv4_local_scope == 0 &&
2461 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))
2464 if (sctp_is_addr_restricted(stcb, sctp_ifa) &&
2465 (!sctp_is_addr_pending(stcb, sctp_ifa)))
2468 * found a valid local v4 address to
2471 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2472 SCTP_IPI_ADDR_RUNLOCK();
2473 return (&sctp_ifa->address.sa);
2479 if (stcb->asoc.scope.ipv6_addr_legal) {
2480 struct sockaddr_in6 *sin6;
2482 if (sctp_ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) {
2486 sin6 = &sctp_ifa->address.sin6;
2487 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2489 * we skip unspecified
2494 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
2495 &sin6->sin6_addr) != 0) {
2498 if (stcb->asoc.scope.local_scope == 0 &&
2499 IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))
2501 if (stcb->asoc.scope.site_scope == 0 &&
2502 IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))
2505 if (sctp_is_addr_restricted(stcb, sctp_ifa) &&
2506 (!sctp_is_addr_pending(stcb, sctp_ifa)))
2509 * found a valid local v6 address to
2512 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2513 SCTP_IPI_ADDR_RUNLOCK();
2514 return (&sctp_ifa->address.sa);
2523 /* no valid addresses found */
2524 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2525 SCTP_IPI_ADDR_RUNLOCK();
2529 static struct sockaddr *
2530 sctp_find_valid_localaddr_ep(struct sctp_tcb *stcb)
2532 struct sctp_laddr *laddr;
2534 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
2535 if (laddr->ifa == NULL) {
2538 /* is the address restricted ? */
2539 if (sctp_is_addr_restricted(stcb, laddr->ifa) &&
2540 (!sctp_is_addr_pending(stcb, laddr->ifa)))
2543 /* found a valid local address to use */
2544 return (&laddr->ifa->address.sa);
2546 /* no valid addresses found */
2551 * builds an ASCONF chunk from queued ASCONF params.
2552 * returns NULL on error (no mbuf, no ASCONF params queued, etc).
2555 sctp_compose_asconf(struct sctp_tcb *stcb, int *retlen, int addr_locked)
2557 struct mbuf *m_asconf, *m_asconf_chk;
2558 struct sctp_asconf_addr *aa;
2559 struct sctp_asconf_chunk *acp;
2560 struct sctp_asconf_paramhdr *aph;
2561 struct sctp_asconf_addr_param *aap;
2562 uint32_t p_length, overhead;
2563 uint32_t correlation_id = 1; /* 0 is reserved... */
2564 caddr_t ptr, lookup_ptr;
2565 uint8_t lookup_used = 0;
2567 /* are there any asconf params to send? */
2568 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
2575 /* Consider IP header and SCTP common header. */
2576 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
2577 overhead = SCTP_MIN_OVERHEAD;
2579 overhead = SCTP_MIN_V4_OVERHEAD;
2581 /* Consider ASONF chunk. */
2582 overhead += sizeof(struct sctp_asconf_chunk);
2583 /* Consider AUTH chunk. */
2584 overhead += sctp_get_auth_chunk_len(stcb->asoc.peer_hmac_id);
2585 if (stcb->asoc.smallest_mtu <= overhead) {
2586 /* MTU too small. */
2590 * get a chunk header mbuf and a cluster for the asconf params since
2591 * it's simpler to fill in the asconf chunk header lookup address on
2594 m_asconf_chk = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_chunk), 0, M_NOWAIT, 1, MT_DATA);
2595 if (m_asconf_chk == NULL) {
2597 SCTPDBG(SCTP_DEBUG_ASCONF1,
2598 "sctp_compose_asconf: couldn't get chunk mbuf!\n");
2601 m_asconf = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA);
2602 if (m_asconf == NULL) {
2604 SCTPDBG(SCTP_DEBUG_ASCONF1,
2605 "sctp_compose_asconf: couldn't get mbuf!\n");
2606 sctp_m_freem(m_asconf_chk);
2609 SCTP_BUF_LEN(m_asconf_chk) = sizeof(struct sctp_asconf_chunk);
2610 SCTP_BUF_LEN(m_asconf) = 0;
2611 acp = mtod(m_asconf_chk, struct sctp_asconf_chunk *);
2612 memset(acp, 0, sizeof(struct sctp_asconf_chunk));
2613 /* save pointers to lookup address and asconf params */
2614 lookup_ptr = (caddr_t)(acp + 1); /* after the header */
2615 ptr = mtod(m_asconf, caddr_t); /* beginning of cluster */
2617 /* fill in chunk header info */
2618 acp->ch.chunk_type = SCTP_ASCONF;
2619 acp->ch.chunk_flags = 0;
2620 acp->serial_number = htonl(stcb->asoc.asconf_seq_out);
2621 stcb->asoc.asconf_seq_out++;
2623 /* add parameters... up to smallest MTU allowed */
2624 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
2627 /* get the parameter length */
2628 p_length = SCTP_SIZE32(aa->ap.aph.ph.param_length);
2629 /* will it fit in current chunk? */
2630 if ((SCTP_BUF_LEN(m_asconf) + p_length > stcb->asoc.smallest_mtu - overhead) ||
2631 (SCTP_BUF_LEN(m_asconf) + p_length > MCLBYTES)) {
2632 /* won't fit, so we're done with this chunk */
2635 /* assign (and store) a correlation id */
2636 aa->ap.aph.correlation_id = correlation_id++;
2639 * fill in address if we're doing a delete this is a simple
2640 * way for us to fill in the correlation address, which
2641 * should only be used by the peer if we're deleting our
2642 * source address and adding a new address (e.g. renumbering
2645 if (lookup_used == 0 &&
2646 (aa->special_del == 0) &&
2647 aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) {
2648 struct sctp_ipv6addr_param *lookup;
2649 uint16_t p_size, addr_size;
2651 lookup = (struct sctp_ipv6addr_param *)lookup_ptr;
2652 lookup->ph.param_type =
2653 htons(aa->ap.addrp.ph.param_type);
2654 if (aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) {
2655 /* copy IPv6 address */
2656 p_size = sizeof(struct sctp_ipv6addr_param);
2657 addr_size = sizeof(struct in6_addr);
2659 /* copy IPv4 address */
2660 p_size = sizeof(struct sctp_ipv4addr_param);
2661 addr_size = sizeof(struct in_addr);
2663 lookup->ph.param_length = htons(SCTP_SIZE32(p_size));
2664 memcpy(lookup->addr, &aa->ap.addrp.addr, addr_size);
2665 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size);
2668 /* copy into current space */
2669 memcpy(ptr, &aa->ap, p_length);
2671 /* network elements and update lengths */
2672 aph = (struct sctp_asconf_paramhdr *)ptr;
2673 aap = (struct sctp_asconf_addr_param *)ptr;
2674 /* correlation_id is transparent to peer, no htonl needed */
2675 aph->ph.param_type = htons(aph->ph.param_type);
2676 aph->ph.param_length = htons(aph->ph.param_length);
2677 aap->addrp.ph.param_type = htons(aap->addrp.ph.param_type);
2678 aap->addrp.ph.param_length = htons(aap->addrp.ph.param_length);
2680 SCTP_BUF_LEN(m_asconf) += SCTP_SIZE32(p_length);
2681 ptr += SCTP_SIZE32(p_length);
2684 * these params are removed off the pending list upon
2685 * getting an ASCONF-ACK back from the peer, just set flag
2689 /* check to see if the lookup addr has been populated yet */
2690 if (lookup_used == 0) {
2691 /* NOTE: if the address param is optional, can skip this... */
2692 /* add any valid (existing) address... */
2693 struct sctp_ipv6addr_param *lookup;
2694 uint16_t p_size, addr_size;
2695 struct sockaddr *found_addr;
2698 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL)
2699 found_addr = sctp_find_valid_localaddr(stcb,
2702 found_addr = sctp_find_valid_localaddr_ep(stcb);
2704 lookup = (struct sctp_ipv6addr_param *)lookup_ptr;
2705 if (found_addr != NULL) {
2706 switch (found_addr->sa_family) {
2709 /* copy IPv6 address */
2710 lookup->ph.param_type =
2711 htons(SCTP_IPV6_ADDRESS);
2712 p_size = sizeof(struct sctp_ipv6addr_param);
2713 addr_size = sizeof(struct in6_addr);
2714 addr_ptr = (caddr_t)&((struct sockaddr_in6 *)
2715 found_addr)->sin6_addr;
2720 /* copy IPv4 address */
2721 lookup->ph.param_type =
2722 htons(SCTP_IPV4_ADDRESS);
2723 p_size = sizeof(struct sctp_ipv4addr_param);
2724 addr_size = sizeof(struct in_addr);
2725 addr_ptr = (caddr_t)&((struct sockaddr_in *)
2726 found_addr)->sin_addr;
2730 SCTPDBG(SCTP_DEBUG_ASCONF1,
2731 "sctp_compose_asconf: no usable lookup addr (family = %d)!\n",
2732 found_addr->sa_family);
2733 sctp_m_freem(m_asconf_chk);
2734 sctp_m_freem(m_asconf);
2737 lookup->ph.param_length = htons(SCTP_SIZE32(p_size));
2738 memcpy(lookup->addr, addr_ptr, addr_size);
2739 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size);
2741 /* uh oh... don't have any address?? */
2742 SCTPDBG(SCTP_DEBUG_ASCONF1,
2743 "sctp_compose_asconf: no lookup addr!\n");
2744 sctp_m_freem(m_asconf_chk);
2745 sctp_m_freem(m_asconf);
2749 /* chain it all together */
2750 SCTP_BUF_NEXT(m_asconf_chk) = m_asconf;
2751 *retlen = SCTP_BUF_LEN(m_asconf_chk) + SCTP_BUF_LEN(m_asconf);
2752 acp->ch.chunk_length = htons(*retlen);
2754 return (m_asconf_chk);
2758 * section to handle address changes before an association is up eg. changes
2759 * during INIT/INIT-ACK/COOKIE-ECHO handshake
2763 * processes the (local) addresses in the INIT-ACK chunk
2766 sctp_process_initack_addresses(struct sctp_tcb *stcb, struct mbuf *m,
2767 unsigned int offset, unsigned int length)
2769 struct sctp_paramhdr tmp_param, *ph;
2770 uint16_t plen, ptype;
2771 struct sctp_ifa *sctp_ifa;
2772 union sctp_sockstore store;
2774 struct sctp_ipv6addr_param addr6_store;
2777 struct sctp_ipv4addr_param addr4_store;
2780 SCTPDBG(SCTP_DEBUG_ASCONF2, "processing init-ack addresses\n");
2781 if (stcb == NULL) /* Un-needed check for SA */
2784 /* convert to upper bound */
2787 if ((offset + sizeof(struct sctp_paramhdr)) > length) {
2790 /* go through the addresses in the init-ack */
2791 ph = (struct sctp_paramhdr *)
2792 sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr),
2793 (uint8_t *)&tmp_param);
2794 while (ph != NULL) {
2795 ptype = ntohs(ph->param_type);
2796 plen = ntohs(ph->param_length);
2799 case SCTP_IPV6_ADDRESS:
2801 struct sctp_ipv6addr_param *a6p;
2803 /* get the entire IPv6 address param */
2804 a6p = (struct sctp_ipv6addr_param *)
2805 sctp_m_getptr(m, offset,
2806 sizeof(struct sctp_ipv6addr_param),
2807 (uint8_t *)&addr6_store);
2808 if (plen != sizeof(struct sctp_ipv6addr_param) ||
2812 memset(&store, 0, sizeof(union sctp_sockstore));
2813 store.sin6.sin6_family = AF_INET6;
2814 store.sin6.sin6_len = sizeof(struct sockaddr_in6);
2815 store.sin6.sin6_port = stcb->rport;
2816 memcpy(&store.sin6.sin6_addr, a6p->addr, sizeof(struct in6_addr));
2821 case SCTP_IPV4_ADDRESS:
2823 struct sctp_ipv4addr_param *a4p;
2825 /* get the entire IPv4 address param */
2826 a4p = (struct sctp_ipv4addr_param *)sctp_m_getptr(m, offset,
2827 sizeof(struct sctp_ipv4addr_param),
2828 (uint8_t *)&addr4_store);
2829 if (plen != sizeof(struct sctp_ipv4addr_param) ||
2833 memset(&store, 0, sizeof(union sctp_sockstore));
2834 store.sin.sin_family = AF_INET;
2835 store.sin.sin_len = sizeof(struct sockaddr_in);
2836 store.sin.sin_port = stcb->rport;
2837 store.sin.sin_addr.s_addr = a4p->addr;
2845 /* see if this address really (still) exists */
2846 sctp_ifa = sctp_find_ifa_by_addr(&store.sa, stcb->asoc.vrf_id,
2847 SCTP_ADDR_NOT_LOCKED);
2848 if (sctp_ifa == NULL) {
2849 /* address doesn't exist anymore */
2852 /* are ASCONFs allowed ? */
2853 if ((sctp_is_feature_on(stcb->sctp_ep,
2854 SCTP_PCB_FLAGS_DO_ASCONF)) &&
2855 stcb->asoc.asconf_supported) {
2856 /* queue an ASCONF DEL_IP_ADDRESS */
2857 status = sctp_asconf_queue_sa_delete(stcb, &store.sa);
2859 * if queued ok, and in correct state, send
2863 SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) {
2864 #ifdef SCTP_TIMER_BASED_ASCONF
2865 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
2866 stcb->sctp_ep, stcb,
2867 stcb->asoc.primary_destination);
2869 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2877 * Sanity check: Make sure the length isn't 0, otherwise
2878 * we'll be stuck in this loop for a long time...
2880 if (SCTP_SIZE32(plen) == 0) {
2881 SCTP_PRINTF("process_initack_addrs: bad len (%d) type=%xh\n",
2885 /* get next parameter */
2886 offset += SCTP_SIZE32(plen);
2887 if ((offset + sizeof(struct sctp_paramhdr)) > length)
2889 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset,
2890 sizeof(struct sctp_paramhdr), (uint8_t *)&tmp_param);
2894 /* FIX ME: need to verify return result for v6 address type if v6 disabled */
2896 * checks to see if a specific address is in the initack address list returns
2897 * 1 if found, 0 if not
2900 sctp_addr_in_initack(struct mbuf *m, uint32_t offset, uint32_t length, struct sockaddr *sa)
2902 struct sctp_paramhdr tmp_param, *ph;
2903 uint16_t plen, ptype;
2905 struct sockaddr_in *sin;
2906 struct sctp_ipv4addr_param *a4p;
2907 struct sctp_ipv6addr_param addr4_store;
2910 struct sockaddr_in6 *sin6;
2911 struct sctp_ipv6addr_param *a6p;
2912 struct sctp_ipv6addr_param addr6_store;
2913 struct sockaddr_in6 sin6_tmp;
2916 switch (sa->sa_family) {
2929 SCTPDBG(SCTP_DEBUG_ASCONF2, "find_initack_addr: starting search for ");
2930 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, sa);
2931 /* convert to upper bound */
2934 if ((offset + sizeof(struct sctp_paramhdr)) > length) {
2935 SCTPDBG(SCTP_DEBUG_ASCONF1,
2936 "find_initack_addr: invalid offset?\n");
2939 /* go through the addresses in the init-ack */
2940 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset,
2941 sizeof(struct sctp_paramhdr), (uint8_t *)&tmp_param);
2942 while (ph != NULL) {
2943 ptype = ntohs(ph->param_type);
2944 plen = ntohs(ph->param_length);
2947 case SCTP_IPV6_ADDRESS:
2948 if (sa->sa_family == AF_INET6) {
2949 /* get the entire IPv6 address param */
2950 if (plen != sizeof(struct sctp_ipv6addr_param)) {
2953 /* get the entire IPv6 address param */
2954 a6p = (struct sctp_ipv6addr_param *)
2955 sctp_m_getptr(m, offset,
2956 sizeof(struct sctp_ipv6addr_param),
2957 (uint8_t *)&addr6_store);
2961 sin6 = (struct sockaddr_in6 *)sa;
2962 if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr)) {
2963 /* create a copy and clear scope */
2964 memcpy(&sin6_tmp, sin6,
2965 sizeof(struct sockaddr_in6));
2967 in6_clearscope(&sin6->sin6_addr);
2969 if (memcmp(&sin6->sin6_addr, a6p->addr,
2970 sizeof(struct in6_addr)) == 0) {
2978 case SCTP_IPV4_ADDRESS:
2979 if (sa->sa_family == AF_INET) {
2980 if (plen != sizeof(struct sctp_ipv4addr_param)) {
2983 /* get the entire IPv4 address param */
2984 a4p = (struct sctp_ipv4addr_param *)
2985 sctp_m_getptr(m, offset,
2986 sizeof(struct sctp_ipv4addr_param),
2987 (uint8_t *)&addr4_store);
2991 sin = (struct sockaddr_in *)sa;
2992 if (sin->sin_addr.s_addr == a4p->addr) {
3002 /* get next parameter */
3003 offset += SCTP_SIZE32(plen);
3004 if (offset + sizeof(struct sctp_paramhdr) > length) {
3007 ph = (struct sctp_paramhdr *)
3008 sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr),
3009 (uint8_t *)&tmp_param);
3016 * makes sure that the current endpoint local addr list is consistent with
3017 * the new association (eg. subset bound, asconf allowed) adds addresses as
3021 sctp_check_address_list_ep(struct sctp_tcb *stcb, struct mbuf *m, int offset,
3022 int length, struct sockaddr *init_addr)
3024 struct sctp_laddr *laddr;
3026 /* go through the endpoint list */
3027 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
3028 /* be paranoid and validate the laddr */
3029 if (laddr->ifa == NULL) {
3030 SCTPDBG(SCTP_DEBUG_ASCONF1,
3031 "check_addr_list_ep: laddr->ifa is NULL");
3034 /* do i have it implicitly? */
3035 if (sctp_cmpaddr(&laddr->ifa->address.sa, init_addr)) {
3038 /* check to see if in the init-ack */
3039 if (!sctp_addr_in_initack(m, offset, length, &laddr->ifa->address.sa)) {
3041 sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb, laddr->ifa,
3042 SCTP_ADD_IP_ADDRESS, SCTP_ADDR_NOT_LOCKED);
3048 * makes sure that the current kernel address list is consistent with the new
3049 * association (with all addrs bound) adds addresses as necessary
3052 sctp_check_address_list_all(struct sctp_tcb *stcb, struct mbuf *m, int offset,
3053 int length, struct sockaddr *init_addr,
3054 uint16_t local_scope, uint16_t site_scope,
3055 uint16_t ipv4_scope, uint16_t loopback_scope)
3057 struct sctp_vrf *vrf = NULL;
3058 struct sctp_ifn *sctp_ifn;
3059 struct sctp_ifa *sctp_ifa;
3062 struct sockaddr_in *sin;
3065 struct sockaddr_in6 *sin6;
3069 vrf_id = stcb->asoc.vrf_id;
3073 SCTP_IPI_ADDR_RLOCK();
3074 vrf = sctp_find_vrf(vrf_id);
3076 SCTP_IPI_ADDR_RUNLOCK();
3079 /* go through all our known interfaces */
3080 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
3081 if (loopback_scope == 0 && SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
3082 /* skip loopback interface */
3085 /* go through each interface address */
3086 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
3087 /* do i have it implicitly? */
3088 if (sctp_cmpaddr(&sctp_ifa->address.sa, init_addr)) {
3091 switch (sctp_ifa->address.sa.sa_family) {
3094 sin = &sctp_ifa->address.sin;
3095 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
3096 &sin->sin_addr) != 0) {
3099 if ((ipv4_scope == 0) &&
3100 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
3101 /* private address not in scope */
3108 sin6 = &sctp_ifa->address.sin6;
3109 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
3110 &sin6->sin6_addr) != 0) {
3113 if ((local_scope == 0) &&
3114 (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))) {
3117 if ((site_scope == 0) &&
3118 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
3126 /* check to see if in the init-ack */
3127 if (!sctp_addr_in_initack(m, offset, length, &sctp_ifa->address.sa)) {
3129 sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb,
3130 sctp_ifa, SCTP_ADD_IP_ADDRESS,
3133 } /* end foreach ifa */
3134 } /* end foreach ifn */
3135 SCTP_IPI_ADDR_RUNLOCK();
3139 * validates an init-ack chunk (from a cookie-echo) with current addresses
3140 * adds addresses from the init-ack into our local address list, if needed
3141 * queues asconf adds/deletes addresses as needed and makes appropriate list
3142 * changes for source address selection m, offset: points to the start of the
3143 * address list in an init-ack chunk length: total length of the address
3144 * params only init_addr: address where my INIT-ACK was sent from
3147 sctp_check_address_list(struct sctp_tcb *stcb, struct mbuf *m, int offset,
3148 int length, struct sockaddr *init_addr,
3149 uint16_t local_scope, uint16_t site_scope,
3150 uint16_t ipv4_scope, uint16_t loopback_scope)
3152 /* process the local addresses in the initack */
3153 sctp_process_initack_addresses(stcb, m, offset, length);
3155 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3156 /* bound all case */
3157 sctp_check_address_list_all(stcb, m, offset, length, init_addr,
3158 local_scope, site_scope, ipv4_scope, loopback_scope);
3160 /* subset bound case */
3161 if (sctp_is_feature_on(stcb->sctp_ep,
3162 SCTP_PCB_FLAGS_DO_ASCONF)) {
3163 /* asconf's allowed */
3164 sctp_check_address_list_ep(stcb, m, offset, length,
3167 /* else, no asconfs allowed, so what we sent is what we get */
3172 * sctp_bindx() support
3175 sctp_addr_mgmt_ep_sa(struct sctp_inpcb *inp, struct sockaddr *sa,
3176 uint32_t type, uint32_t vrf_id)
3178 struct sctp_ifa *ifa;
3179 struct sctp_laddr *laddr, *nladdr;
3181 if (sa->sa_len == 0) {
3182 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EINVAL);
3185 if (type == SCTP_ADD_IP_ADDRESS) {
3186 /* For an add the address MUST be on the system */
3187 ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED);
3188 } else if (type == SCTP_DEL_IP_ADDRESS) {
3189 /* For a delete we need to find it in the inp */
3190 ifa = sctp_find_ifa_in_ep(inp, sa, SCTP_ADDR_NOT_LOCKED);
3195 if (type == SCTP_ADD_IP_ADDRESS) {
3196 sctp_add_local_addr_ep(inp, ifa, type);
3197 } else if (type == SCTP_DEL_IP_ADDRESS) {
3198 if (inp->laddr_count < 2) {
3199 /* can't delete the last local address */
3200 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EINVAL);
3203 LIST_FOREACH(laddr, &inp->sctp_addr_list,
3205 if (ifa == laddr->ifa) {
3206 /* Mark in the delete */
3207 laddr->action = type;
3211 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
3213 * There is no need to start the iterator if the inp
3214 * has no associations.
3216 if (type == SCTP_DEL_IP_ADDRESS) {
3217 LIST_FOREACH_SAFE(laddr, &inp->sctp_addr_list, sctp_nxt_addr, nladdr) {
3218 if (laddr->ifa == ifa) {
3219 sctp_del_local_addr_ep(inp, ifa);
3224 struct sctp_asconf_iterator *asc;
3225 struct sctp_laddr *wi;
3228 SCTP_MALLOC(asc, struct sctp_asconf_iterator *,
3229 sizeof(struct sctp_asconf_iterator),
3232 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, ENOMEM);
3235 wi = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_laddr), struct sctp_laddr);
3237 SCTP_FREE(asc, SCTP_M_ASC_IT);
3238 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, ENOMEM);
3241 LIST_INIT(&asc->list_of_work);
3243 SCTP_INCR_LADDR_COUNT();
3246 atomic_add_int(&ifa->refcount, 1);
3247 LIST_INSERT_HEAD(&asc->list_of_work, wi, sctp_nxt_addr);
3248 ret = sctp_initiate_iterator(sctp_asconf_iterator_ep,
3249 sctp_asconf_iterator_stcb,
3250 sctp_asconf_iterator_ep_end,
3252 SCTP_PCB_ANY_FEATURES,
3253 SCTP_ASOC_ANY_STATE,
3255 sctp_asconf_iterator_end, inp, 0);
3257 SCTP_PRINTF("Failed to initiate iterator for addr_mgmt_ep_sa\n");
3258 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EFAULT);
3259 sctp_asconf_iterator_end(asc, 0);
3265 /* invalid address! */
3266 SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EADDRNOTAVAIL);
3267 return (EADDRNOTAVAIL);
3272 sctp_asconf_send_nat_state_update(struct sctp_tcb *stcb, struct sctp_nets *net)
3274 struct sctp_asconf_addr *aa_vtag, *aa_add, *aa_del;
3275 struct sctp_ifa *sctp_ifap;
3276 struct sctp_asconf_tag_param *vtag;
3278 struct sockaddr_in *to;
3281 struct sockaddr_in6 *to6;
3285 SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing net\n");
3289 SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing stcb\n");
3293 * Need to have in the ASCONF: - VTAG(my_vtag/peer_vtag) -
3294 * ADD(wildcard) - DEL(wildcard) - ADD(Any global addresses)
3296 SCTP_MALLOC(aa_vtag, struct sctp_asconf_addr *, sizeof(struct sctp_asconf_addr), SCTP_M_ASC_ADDR);
3297 SCTP_MALLOC(aa_add, struct sctp_asconf_addr *, sizeof(struct sctp_asconf_addr), SCTP_M_ASC_ADDR);
3298 SCTP_MALLOC(aa_del, struct sctp_asconf_addr *, sizeof(struct sctp_asconf_addr), SCTP_M_ASC_ADDR);
3300 if ((aa_vtag == NULL) || (aa_add == NULL) || (aa_del == NULL)) {
3301 /* Didn't get memory */
3302 SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: failed to get memory!\n");
3304 if (aa_vtag != NULL) {
3305 SCTP_FREE(aa_vtag, SCTP_M_ASC_ADDR);
3307 if (aa_add != NULL) {
3308 SCTP_FREE(aa_add, SCTP_M_ASC_ADDR);
3310 if (aa_del != NULL) {
3311 SCTP_FREE(aa_del, SCTP_M_ASC_ADDR);
3315 memset(aa_vtag, 0, sizeof(struct sctp_asconf_addr));
3316 aa_vtag->special_del = 0;
3317 /* Fill in ASCONF address parameter fields. */
3318 /* Top level elements are "networked" during send. */
3319 aa_vtag->ifa = NULL;
3320 aa_vtag->sent = 0; /* clear sent flag */
3321 vtag = (struct sctp_asconf_tag_param *)&aa_vtag->ap.aph;
3322 vtag->aph.ph.param_type = SCTP_NAT_VTAGS;
3323 vtag->aph.ph.param_length = sizeof(struct sctp_asconf_tag_param);
3324 vtag->local_vtag = htonl(stcb->asoc.my_vtag);
3325 vtag->remote_vtag = htonl(stcb->asoc.peer_vtag);
3327 memset(aa_add, 0, sizeof(struct sctp_asconf_addr));
3328 memset(aa_del, 0, sizeof(struct sctp_asconf_addr));
3329 switch (net->ro._l_addr.sa.sa_family) {
3332 aa_add->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
3333 aa_add->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param);
3334 aa_add->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
3335 aa_add->ap.addrp.ph.param_length = sizeof(struct sctp_ipv4addr_param);
3336 /* No need to fill the address, we are using 0.0.0.0 */
3337 aa_del->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS;
3338 aa_del->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param);
3339 aa_del->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
3340 aa_del->ap.addrp.ph.param_length = sizeof(struct sctp_ipv4addr_param);
3341 /* No need to fill the address, we are using 0.0.0.0 */
3346 aa_add->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
3347 aa_add->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param);
3348 aa_add->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
3349 aa_add->ap.addrp.ph.param_length = sizeof(struct sctp_ipv6addr_param);
3350 /* No need to fill the address, we are using ::0 */
3351 aa_del->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS;
3352 aa_del->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param);
3353 aa_del->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
3354 aa_del->ap.addrp.ph.param_length = sizeof(struct sctp_ipv6addr_param);
3355 /* No need to fill the address, we are using ::0 */
3359 SCTPDBG(SCTP_DEBUG_ASCONF1,
3360 "sctp_asconf_send_nat_state_update: unknown address family %d\n",
3361 net->ro._l_addr.sa.sa_family);
3364 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa_vtag, next);
3365 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa_add, next);
3366 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa_del, next);
3368 /* Now we must hunt the addresses and add all global addresses */
3369 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3370 struct sctp_vrf *vrf = NULL;
3371 struct sctp_ifn *sctp_ifnp;
3374 vrf_id = stcb->sctp_ep->def_vrf_id;
3375 vrf = sctp_find_vrf(vrf_id);
3380 SCTP_IPI_ADDR_RLOCK();
3381 LIST_FOREACH(sctp_ifnp, &vrf->ifnlist, next_ifn) {
3382 LIST_FOREACH(sctp_ifap, &sctp_ifnp->ifalist, next_ifa) {
3383 switch (sctp_ifap->address.sa.sa_family) {
3386 to = &sctp_ifap->address.sin;
3387 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
3388 &to->sin_addr) != 0) {
3391 if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) {
3394 if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) {
3401 to6 = &sctp_ifap->address.sin6;
3402 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
3403 &to6->sin6_addr) != 0) {
3406 if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) {
3409 if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) {
3417 sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS);
3420 SCTP_IPI_ADDR_RUNLOCK();
3422 struct sctp_laddr *laddr;
3424 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
3425 if (laddr->ifa == NULL) {
3428 if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED)
3430 * Address being deleted by the system, dont
3434 if (laddr->action == SCTP_DEL_IP_ADDRESS) {
3436 * Address being deleted on this ep don't
3441 sctp_ifap = laddr->ifa;
3442 switch (sctp_ifap->address.sa.sa_family) {
3445 to = &sctp_ifap->address.sin;
3446 if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) {
3449 if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) {
3456 to6 = &sctp_ifap->address.sin6;
3457 if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) {
3460 if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) {
3468 sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS);
3472 /* Now we must send the asconf into the queue */
3473 sctp_send_asconf(stcb, net, SCTP_ADDR_NOT_LOCKED);