2 * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * a) Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
12 * b) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the distribution.
16 * c) Neither the name of Cisco Systems, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
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
56 * An ASCONF parameter queue exists per asoc which holds the pending address
57 * operations. Lists are updated upon receipt of ASCONF-ACK.
59 * A restricted_addrs list exists per assoc to hold local addresses that are
60 * not (yet) usable by the assoc as a source address. These addresses are
61 * either pending an ASCONF operation (and exist on the ASCONF parameter
62 * queue), or they are permanently restricted (the peer has returned an
63 * ERROR indication to an ASCONF(ADD), or the peer does not support ASCONF).
65 * Deleted addresses are always immediately removed from the lists as they will
66 * (shortly) no longer exist in the kernel. We send ASCONFs as a courtesy,
71 * ASCONF parameter processing.
72 * response_required: set if a reply is required (eg. SUCCESS_REPORT).
73 * returns a mbuf to an "error" response parameter or NULL/"success" if ok.
74 * FIX: allocating this many mbufs on the fly is pretty inefficient...
77 sctp_asconf_success_response(uint32_t id)
79 struct mbuf *m_reply = NULL;
80 struct sctp_asconf_paramhdr *aph;
82 m_reply = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_paramhdr),
83 0, M_NOWAIT, 1, MT_DATA);
84 if (m_reply == NULL) {
85 SCTPDBG(SCTP_DEBUG_ASCONF1,
86 "asconf_success_response: couldn't get mbuf!\n");
89 aph = mtod(m_reply, struct sctp_asconf_paramhdr *);
90 aph->correlation_id = id;
91 aph->ph.param_type = htons(SCTP_SUCCESS_REPORT);
92 aph->ph.param_length = sizeof(struct sctp_asconf_paramhdr);
93 SCTP_BUF_LEN(m_reply) = aph->ph.param_length;
94 aph->ph.param_length = htons(aph->ph.param_length);
100 sctp_asconf_error_response(uint32_t id, uint16_t cause, uint8_t *error_tlv,
103 struct mbuf *m_reply = NULL;
104 struct sctp_asconf_paramhdr *aph;
105 struct sctp_error_cause *error;
108 m_reply = sctp_get_mbuf_for_msg((sizeof(struct sctp_asconf_paramhdr) +
110 sizeof(struct sctp_error_cause)),
111 0, M_NOWAIT, 1, MT_DATA);
112 if (m_reply == NULL) {
113 SCTPDBG(SCTP_DEBUG_ASCONF1,
114 "asconf_error_response: couldn't get mbuf!\n");
117 aph = mtod(m_reply, struct sctp_asconf_paramhdr *);
118 error = (struct sctp_error_cause *)(aph + 1);
120 aph->correlation_id = id;
121 aph->ph.param_type = htons(SCTP_ERROR_CAUSE_IND);
122 error->code = htons(cause);
123 error->length = tlv_length + sizeof(struct sctp_error_cause);
124 aph->ph.param_length = error->length +
125 sizeof(struct sctp_asconf_paramhdr);
127 if (aph->ph.param_length > MLEN) {
128 SCTPDBG(SCTP_DEBUG_ASCONF1,
129 "asconf_error_response: tlv_length (%xh) too big\n",
131 sctp_m_freem(m_reply); /* discard */
134 if (error_tlv != NULL) {
135 tlv = (uint8_t *)(error + 1);
136 memcpy(tlv, error_tlv, tlv_length);
138 SCTP_BUF_LEN(m_reply) = aph->ph.param_length;
139 error->length = htons(error->length);
140 aph->ph.param_length = htons(aph->ph.param_length);
146 sctp_process_asconf_add_ip(struct sockaddr *src, struct sctp_asconf_paramhdr *aph,
147 struct sctp_tcb *stcb, int send_hb, int response_required)
149 struct sctp_nets *net;
150 struct mbuf *m_reply = NULL;
151 union sctp_sockstore store;
152 struct sctp_paramhdr *ph;
153 uint16_t param_type, aparam_length;
154 #if defined(INET) || defined(INET6)
155 uint16_t param_length;
158 int zero_address = 0;
161 struct sockaddr_in *sin;
162 struct sctp_ipv4addr_param *v4addr;
165 struct sockaddr_in6 *sin6;
166 struct sctp_ipv6addr_param *v6addr;
169 aparam_length = ntohs(aph->ph.param_length);
170 ph = (struct sctp_paramhdr *)(aph + 1);
171 param_type = ntohs(ph->param_type);
172 #if defined(INET) || defined(INET6)
173 param_length = ntohs(ph->param_length);
176 switch (param_type) {
178 case SCTP_IPV4_ADDRESS:
179 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
180 /* invalid param size */
183 v4addr = (struct sctp_ipv4addr_param *)ph;
185 memset(sin, 0, sizeof(*sin));
186 sin->sin_family = AF_INET;
187 sin->sin_len = sizeof(struct sockaddr_in);
188 sin->sin_port = stcb->rport;
189 sin->sin_addr.s_addr = v4addr->addr;
190 if ((sin->sin_addr.s_addr == INADDR_BROADCAST) ||
191 IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) {
194 if (sin->sin_addr.s_addr == INADDR_ANY)
196 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_add_ip: adding ");
197 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
201 case SCTP_IPV6_ADDRESS:
202 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
203 /* invalid param size */
206 v6addr = (struct sctp_ipv6addr_param *)ph;
208 memset(sin6, 0, sizeof(*sin6));
209 sin6->sin6_family = AF_INET6;
210 sin6->sin6_len = sizeof(struct sockaddr_in6);
211 sin6->sin6_port = stcb->rport;
212 memcpy((caddr_t)&sin6->sin6_addr, v6addr->addr,
213 sizeof(struct in6_addr));
214 if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
217 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
219 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_add_ip: adding ");
220 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
224 m_reply = sctp_asconf_error_response(aph->correlation_id,
225 SCTP_CAUSE_INVALID_PARAM, (uint8_t *)aph,
230 /* if 0.0.0.0/::0, add the source address instead */
231 if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) {
233 SCTPDBG(SCTP_DEBUG_ASCONF1,
234 "process_asconf_add_ip: using source addr ");
235 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, src);
237 /* add the address */
239 m_reply = sctp_asconf_error_response(aph->correlation_id,
240 SCTP_CAUSE_INVALID_PARAM, (uint8_t *)aph,
242 } else if (sctp_add_remote_addr(stcb, sa, &net, stcb->asoc.port,
244 SCTP_ADDR_DYNAMIC_ADDED) != 0) {
245 SCTPDBG(SCTP_DEBUG_ASCONF1,
246 "process_asconf_add_ip: error adding address\n");
247 m_reply = sctp_asconf_error_response(aph->correlation_id,
248 SCTP_CAUSE_RESOURCE_SHORTAGE, (uint8_t *)aph,
251 /* notify upper layer */
252 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_ADD_IP, stcb, 0, sa, SCTP_SO_NOT_LOCKED);
253 if (response_required) {
255 sctp_asconf_success_response(aph->correlation_id);
257 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, stcb->sctp_ep, stcb, net);
258 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep,
261 sctp_send_hb(stcb, net, SCTP_SO_NOT_LOCKED);
268 sctp_asconf_del_remote_addrs_except(struct sctp_tcb *stcb, struct sockaddr *src)
270 struct sctp_nets *src_net, *net;
272 /* make sure the source address exists as a destination net */
273 src_net = sctp_findnet(stcb, src);
274 if (src_net == NULL) {
279 /* delete all destination addresses except the source */
280 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
281 if (net != src_net) {
282 /* delete this address */
283 sctp_remove_net(stcb, net);
284 SCTPDBG(SCTP_DEBUG_ASCONF1,
285 "asconf_del_remote_addrs_except: deleting ");
286 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1,
287 (struct sockaddr *)&net->ro._l_addr);
288 /* notify upper layer */
289 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0,
290 (struct sockaddr *)&net->ro._l_addr, SCTP_SO_NOT_LOCKED);
297 sctp_process_asconf_delete_ip(struct sockaddr *src,
298 struct sctp_asconf_paramhdr *aph,
299 struct sctp_tcb *stcb, int response_required)
301 struct mbuf *m_reply = NULL;
302 union sctp_sockstore store;
303 struct sctp_paramhdr *ph;
304 uint16_t param_type, aparam_length;
305 #if defined(INET) || defined(INET6)
306 uint16_t param_length;
309 int zero_address = 0;
312 struct sockaddr_in *sin;
313 struct sctp_ipv4addr_param *v4addr;
316 struct sockaddr_in6 *sin6;
317 struct sctp_ipv6addr_param *v6addr;
320 aparam_length = ntohs(aph->ph.param_length);
321 ph = (struct sctp_paramhdr *)(aph + 1);
322 param_type = ntohs(ph->param_type);
323 #if defined(INET) || defined(INET6)
324 param_length = ntohs(ph->param_length);
327 switch (param_type) {
329 case SCTP_IPV4_ADDRESS:
330 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
331 /* invalid param size */
334 v4addr = (struct sctp_ipv4addr_param *)ph;
336 memset(sin, 0, sizeof(*sin));
337 sin->sin_family = AF_INET;
338 sin->sin_len = sizeof(struct sockaddr_in);
339 sin->sin_port = stcb->rport;
340 sin->sin_addr.s_addr = v4addr->addr;
341 if (sin->sin_addr.s_addr == INADDR_ANY)
343 SCTPDBG(SCTP_DEBUG_ASCONF1,
344 "process_asconf_delete_ip: deleting ");
345 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
349 case SCTP_IPV6_ADDRESS:
350 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
351 /* invalid param size */
354 v6addr = (struct sctp_ipv6addr_param *)ph;
356 memset(sin6, 0, sizeof(*sin6));
357 sin6->sin6_family = AF_INET6;
358 sin6->sin6_len = sizeof(struct sockaddr_in6);
359 sin6->sin6_port = stcb->rport;
360 memcpy(&sin6->sin6_addr, v6addr->addr,
361 sizeof(struct in6_addr));
362 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
364 SCTPDBG(SCTP_DEBUG_ASCONF1,
365 "process_asconf_delete_ip: deleting ");
366 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
370 m_reply = sctp_asconf_error_response(aph->correlation_id,
371 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *)aph,
376 /* make sure the source address is not being deleted */
377 if (sctp_cmpaddr(sa, src)) {
378 /* trying to delete the source address! */
379 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: tried to delete source addr\n");
380 m_reply = sctp_asconf_error_response(aph->correlation_id,
381 SCTP_CAUSE_DELETING_SRC_ADDR, (uint8_t *)aph,
386 /* if deleting 0.0.0.0/::0, delete all addresses except src addr */
387 if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) {
388 result = sctp_asconf_del_remote_addrs_except(stcb, src);
391 /* src address did not exist? */
392 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: src addr does not exist?\n");
393 /* what error to reply with?? */
395 sctp_asconf_error_response(aph->correlation_id,
396 SCTP_CAUSE_REQUEST_REFUSED, (uint8_t *)aph,
398 } else if (response_required) {
400 sctp_asconf_success_response(aph->correlation_id);
405 /* delete the address */
406 result = sctp_del_remote_addr(stcb, sa);
408 * note if result == -2, the address doesn't exist in the asoc but
409 * since it's being deleted anyways, we just ack the delete -- but
410 * this probably means something has already gone awry
413 /* only one address in the asoc */
414 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: tried to delete last IP addr!\n");
415 m_reply = sctp_asconf_error_response(aph->correlation_id,
416 SCTP_CAUSE_DELETING_LAST_ADDR, (uint8_t *)aph,
419 if (response_required) {
420 m_reply = sctp_asconf_success_response(aph->correlation_id);
422 /* notify upper layer */
423 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0, sa, SCTP_SO_NOT_LOCKED);
429 sctp_process_asconf_set_primary(struct sockaddr *src,
430 struct sctp_asconf_paramhdr *aph,
431 struct sctp_tcb *stcb, int response_required)
433 struct mbuf *m_reply = NULL;
434 union sctp_sockstore store;
435 struct sctp_paramhdr *ph;
436 uint16_t param_type, aparam_length;
437 #if defined(INET) || defined(INET6)
438 uint16_t param_length;
441 int zero_address = 0;
443 struct sockaddr_in *sin;
444 struct sctp_ipv4addr_param *v4addr;
447 struct sockaddr_in6 *sin6;
448 struct sctp_ipv6addr_param *v6addr;
451 aparam_length = ntohs(aph->ph.param_length);
452 ph = (struct sctp_paramhdr *)(aph + 1);
453 param_type = ntohs(ph->param_type);
454 #if defined(INET) || defined(INET6)
455 param_length = ntohs(ph->param_length);
458 switch (param_type) {
460 case SCTP_IPV4_ADDRESS:
461 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
462 /* invalid param size */
465 v4addr = (struct sctp_ipv4addr_param *)ph;
467 memset(sin, 0, sizeof(*sin));
468 sin->sin_family = AF_INET;
469 sin->sin_len = sizeof(struct sockaddr_in);
470 sin->sin_addr.s_addr = v4addr->addr;
471 if (sin->sin_addr.s_addr == INADDR_ANY)
473 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_set_primary: ");
474 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
478 case SCTP_IPV6_ADDRESS:
479 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
480 /* invalid param size */
483 v6addr = (struct sctp_ipv6addr_param *)ph;
485 memset(sin6, 0, sizeof(*sin6));
486 sin6->sin6_family = AF_INET6;
487 sin6->sin6_len = sizeof(struct sockaddr_in6);
488 memcpy((caddr_t)&sin6->sin6_addr, v6addr->addr,
489 sizeof(struct in6_addr));
490 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
492 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_set_primary: ");
493 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
497 m_reply = sctp_asconf_error_response(aph->correlation_id,
498 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *)aph,
503 /* if 0.0.0.0/::0, use the source address instead */
504 if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) {
506 SCTPDBG(SCTP_DEBUG_ASCONF1,
507 "process_asconf_set_primary: using source addr ");
508 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, src);
510 /* set the primary address */
511 if (sctp_set_primary_addr(stcb, sa, NULL) == 0) {
512 SCTPDBG(SCTP_DEBUG_ASCONF1,
513 "process_asconf_set_primary: primary address set\n");
514 /* notify upper layer */
515 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_SET_PRIMARY, stcb, 0, sa, SCTP_SO_NOT_LOCKED);
516 if ((stcb->asoc.primary_destination->dest_state & SCTP_ADDR_REACHABLE) &&
517 (!(stcb->asoc.primary_destination->dest_state & SCTP_ADDR_PF)) &&
518 (stcb->asoc.alternate)) {
519 sctp_free_remote_addr(stcb->asoc.alternate);
520 stcb->asoc.alternate = NULL;
522 if (response_required) {
523 m_reply = sctp_asconf_success_response(aph->correlation_id);
526 * Mobility adaptation. Ideally, when the reception of SET
527 * PRIMARY with DELETE IP ADDRESS of the previous primary
528 * destination, unacknowledged DATA are retransmitted
529 * immediately to the new primary destination for seamless
530 * handover. If the destination is UNCONFIRMED and marked to
531 * REQ_PRIM, The retransmission occur when reception of the
532 * HEARTBEAT-ACK. (See sctp_handle_heartbeat_ack in
533 * sctp_input.c) Also, when change of the primary
534 * destination, it is better that all subsequent new DATA
535 * containing already queued DATA are transmitted to the new
536 * primary destination. (by micchie)
538 if ((sctp_is_mobility_feature_on(stcb->sctp_ep,
539 SCTP_MOBILITY_BASE) ||
540 sctp_is_mobility_feature_on(stcb->sctp_ep,
541 SCTP_MOBILITY_FASTHANDOFF)) &&
542 sctp_is_mobility_feature_on(stcb->sctp_ep,
543 SCTP_MOBILITY_PRIM_DELETED) &&
544 (stcb->asoc.primary_destination->dest_state &
545 SCTP_ADDR_UNCONFIRMED) == 0) {
547 sctp_timer_stop(SCTP_TIMER_TYPE_PRIM_DELETED,
548 stcb->sctp_ep, stcb, NULL,
549 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_1);
550 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
551 SCTP_MOBILITY_FASTHANDOFF)) {
552 sctp_assoc_immediate_retrans(stcb,
553 stcb->asoc.primary_destination);
555 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
556 SCTP_MOBILITY_BASE)) {
557 sctp_move_chunks_from_net(stcb,
558 stcb->asoc.deleted_primary);
560 sctp_delete_prim_timer(stcb->sctp_ep, stcb,
561 stcb->asoc.deleted_primary);
564 /* couldn't set the requested primary address! */
565 SCTPDBG(SCTP_DEBUG_ASCONF1,
566 "process_asconf_set_primary: set primary failed!\n");
567 /* must have been an invalid address, so report */
568 m_reply = sctp_asconf_error_response(aph->correlation_id,
569 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *)aph,
577 * handles an ASCONF chunk.
578 * if all parameters are processed ok, send a plain (empty) ASCONF-ACK
581 sctp_handle_asconf(struct mbuf *m, unsigned int offset,
582 struct sockaddr *src,
583 struct sctp_asconf_chunk *cp, struct sctp_tcb *stcb,
586 struct sctp_association *asoc;
588 struct mbuf *n, *m_ack, *m_result, *m_tail;
589 struct sctp_asconf_ack_chunk *ack_cp;
590 struct sctp_asconf_paramhdr *aph;
591 struct sctp_ipv6addr_param *p_addr;
592 unsigned int asconf_limit, cnt;
593 int error = 0; /* did an error occur? */
595 /* asconf param buffer */
596 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE];
597 struct sctp_asconf_ack *ack, *ack_next;
599 /* verify minimum length */
600 if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_chunk)) {
601 SCTPDBG(SCTP_DEBUG_ASCONF1,
602 "handle_asconf: chunk too small = %xh\n",
603 ntohs(cp->ch.chunk_length));
607 serial_num = ntohl(cp->serial_number);
609 if (SCTP_TSN_GE(asoc->asconf_seq_in, serial_num)) {
610 /* got a duplicate ASCONF */
611 SCTPDBG(SCTP_DEBUG_ASCONF1,
612 "handle_asconf: got duplicate serial number = %xh\n",
615 } else if (serial_num != (asoc->asconf_seq_in + 1)) {
616 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: incorrect serial number = %xh (expected next = %xh)\n",
617 serial_num, asoc->asconf_seq_in + 1);
621 /* it's the expected "next" sequence number, so process it */
622 asoc->asconf_seq_in = serial_num; /* update sequence */
623 /* get length of all the param's in the ASCONF */
624 asconf_limit = offset + ntohs(cp->ch.chunk_length);
625 SCTPDBG(SCTP_DEBUG_ASCONF1,
626 "handle_asconf: asconf_limit=%u, sequence=%xh\n",
627 asconf_limit, serial_num);
630 /* delete old cache */
631 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: Now processing first ASCONF. Try to delete old cache\n");
633 TAILQ_FOREACH_SAFE(ack, &asoc->asconf_ack_sent, next, ack_next) {
634 if (ack->serial_number == serial_num)
636 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: delete old(%u) < first(%u)\n",
637 ack->serial_number, serial_num);
638 TAILQ_REMOVE(&asoc->asconf_ack_sent, ack, next);
639 if (ack->data != NULL) {
640 sctp_m_freem(ack->data);
642 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_asconf_ack), ack);
646 m_ack = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_ack_chunk), 0,
647 M_NOWAIT, 1, MT_DATA);
649 SCTPDBG(SCTP_DEBUG_ASCONF1,
650 "handle_asconf: couldn't get mbuf!\n");
653 m_tail = m_ack; /* current reply chain's tail */
655 /* fill in ASCONF-ACK header */
656 ack_cp = mtod(m_ack, struct sctp_asconf_ack_chunk *);
657 ack_cp->ch.chunk_type = SCTP_ASCONF_ACK;
658 ack_cp->ch.chunk_flags = 0;
659 ack_cp->serial_number = htonl(serial_num);
660 /* set initial lengths (eg. just an ASCONF-ACK), ntohx at the end! */
661 SCTP_BUF_LEN(m_ack) = sizeof(struct sctp_asconf_ack_chunk);
662 ack_cp->ch.chunk_length = sizeof(struct sctp_asconf_ack_chunk);
664 /* skip the lookup address parameter */
665 offset += sizeof(struct sctp_asconf_chunk);
666 p_addr = (struct sctp_ipv6addr_param *)sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), (uint8_t *)&aparam_buf);
667 if (p_addr == NULL) {
668 SCTPDBG(SCTP_DEBUG_ASCONF1,
669 "handle_asconf: couldn't get lookup addr!\n");
670 /* respond with a missing/invalid mandatory parameter error */
673 /* param_length is already validated in process_control... */
674 offset += ntohs(p_addr->ph.param_length); /* skip lookup addr */
675 /* get pointer to first asconf param in ASCONF */
676 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, sizeof(struct sctp_asconf_paramhdr), (uint8_t *)&aparam_buf);
678 SCTPDBG(SCTP_DEBUG_ASCONF1, "Empty ASCONF received?\n");
681 /* process through all parameters */
683 while (aph != NULL) {
684 unsigned int param_length, param_type;
686 param_type = ntohs(aph->ph.param_type);
687 param_length = ntohs(aph->ph.param_length);
688 if (offset + param_length > asconf_limit) {
689 /* parameter goes beyond end of chunk! */
695 if (param_length > sizeof(aparam_buf)) {
696 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) larger than buffer size!\n", param_length);
700 if (param_length <= sizeof(struct sctp_paramhdr)) {
701 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) too short\n", param_length);
704 /* get the entire parameter */
705 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf);
707 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: couldn't get entire param\n");
711 switch (param_type) {
712 case SCTP_ADD_IP_ADDRESS:
713 m_result = sctp_process_asconf_add_ip(src, aph, stcb,
714 (cnt < SCTP_BASE_SYSCTL(sctp_hb_maxburst)), error);
717 case SCTP_DEL_IP_ADDRESS:
718 m_result = sctp_process_asconf_delete_ip(src, aph, stcb,
721 case SCTP_ERROR_CAUSE_IND:
722 /* not valid in an ASCONF chunk */
724 case SCTP_SET_PRIM_ADDR:
725 m_result = sctp_process_asconf_set_primary(src, aph,
729 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: sees a NAT VTAG state parameter\n");
731 case SCTP_SUCCESS_REPORT:
732 /* not valid in an ASCONF chunk */
734 case SCTP_ULP_ADAPTATION:
738 if ((param_type & 0x8000) == 0) {
739 /* Been told to STOP at this param */
740 asconf_limit = offset;
742 * FIX FIX - We need to call
743 * sctp_arethere_unrecognized_parameters()
744 * to get a operr and send it for any
745 * param's with the 0x4000 bit set OR do it
746 * here ourselves... note we still must STOP
747 * if the 0x8000 bit is clear.
750 /* unknown/invalid param type */
754 /* add any (error) result to the reply mbuf chain */
755 if (m_result != NULL) {
756 SCTP_BUF_NEXT(m_tail) = m_result;
758 /* update lengths, make sure it's aligned too */
759 SCTP_BUF_LEN(m_result) = SCTP_SIZE32(SCTP_BUF_LEN(m_result));
760 ack_cp->ch.chunk_length += SCTP_BUF_LEN(m_result);
761 /* set flag to force success reports */
764 offset += SCTP_SIZE32(param_length);
765 /* update remaining ASCONF message length to process */
766 if (offset >= asconf_limit) {
767 /* no more data in the mbuf chain */
770 /* get pointer to next asconf param */
771 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset,
772 sizeof(struct sctp_asconf_paramhdr),
773 (uint8_t *)&aparam_buf);
775 /* can't get an asconf paramhdr */
776 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: can't get asconf param hdr!\n");
777 /* FIX ME - add error here... */
782 ack_cp->ch.chunk_length = htons(ack_cp->ch.chunk_length);
783 /* save the ASCONF-ACK reply */
784 ack = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_asconf_ack),
785 struct sctp_asconf_ack);
790 ack->serial_number = serial_num;
791 ack->last_sent_to = NULL;
794 for (n = m_ack; n != NULL; n = SCTP_BUF_NEXT(n)) {
795 ack->len += SCTP_BUF_LEN(n);
797 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_ack_sent, ack, next);
799 /* see if last_control_chunk_from is set properly (use IP src addr) */
800 if (stcb->asoc.last_control_chunk_from == NULL) {
802 * this could happen if the source address was just newly
805 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: looking up net for IP source address\n");
806 SCTPDBG(SCTP_DEBUG_ASCONF1, "Looking for IP source: ");
807 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, src);
808 /* look up the from address */
809 stcb->asoc.last_control_chunk_from = sctp_findnet(stcb, src);
811 if (stcb->asoc.last_control_chunk_from == NULL) {
812 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: IP source address not found?!\n");
819 * does the address match? returns 0 if not, 1 if so
822 sctp_asconf_addr_match(struct sctp_asconf_addr *aa, struct sockaddr *sa)
824 switch (sa->sa_family) {
829 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
831 if ((aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) &&
832 (memcmp(&aa->ap.addrp.addr, &sin6->sin6_addr,
833 sizeof(struct in6_addr)) == 0)) {
842 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
844 if ((aa->ap.addrp.ph.param_type == SCTP_IPV4_ADDRESS) &&
845 (memcmp(&aa->ap.addrp.addr, &sin->sin_addr,
846 sizeof(struct in_addr)) == 0)) {
859 * does the address match? returns 0 if not, 1 if so
862 sctp_addr_match(struct sctp_paramhdr *ph, struct sockaddr *sa)
864 #if defined(INET) || defined(INET6)
865 uint16_t param_type, param_length;
867 param_type = ntohs(ph->param_type);
868 param_length = ntohs(ph->param_length);
870 switch (sa->sa_family) {
875 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
876 struct sctp_ipv6addr_param *v6addr;
878 v6addr = (struct sctp_ipv6addr_param *)ph;
879 if ((param_type == SCTP_IPV6_ADDRESS) &&
880 (param_length == sizeof(struct sctp_ipv6addr_param)) &&
881 (memcmp(&v6addr->addr, &sin6->sin6_addr,
882 sizeof(struct in6_addr)) == 0)) {
891 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
892 struct sctp_ipv4addr_param *v4addr;
894 v4addr = (struct sctp_ipv4addr_param *)ph;
895 if ((param_type == SCTP_IPV4_ADDRESS) &&
896 (param_length == sizeof(struct sctp_ipv4addr_param)) &&
897 (memcmp(&v4addr->addr, &sin->sin_addr,
898 sizeof(struct in_addr)) == 0)) {
911 * Cleanup for non-responded/OP ERR'd ASCONF
914 sctp_asconf_cleanup(struct sctp_tcb *stcb, struct sctp_nets *net)
917 * clear out any existing asconfs going out
919 sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, net,
920 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_2);
921 stcb->asoc.asconf_seq_out_acked = stcb->asoc.asconf_seq_out;
922 /* remove the old ASCONF on our outbound queue */
923 sctp_toss_old_asconf(stcb);
927 * cleanup any cached source addresses that may be topologically
928 * incorrect after a new address has been added to this interface.
931 sctp_asconf_nets_cleanup(struct sctp_tcb *stcb, struct sctp_ifn *ifn)
933 struct sctp_nets *net;
936 * Ideally, we want to only clear cached routes and source addresses
937 * that are topologically incorrect. But since there is no easy way
938 * to know whether the newly added address on the ifn would cause a
939 * routing change (i.e. a new egress interface would be chosen)
940 * without doing a new routing lookup and source address selection,
941 * we will (for now) just flush any cached route using a different
942 * ifn (and cached source addrs) and let output re-choose them
943 * during the next send on that net.
945 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
947 * clear any cached route (and cached source address) if the
948 * route's interface is NOT the same as the address change.
949 * If it's the same interface, just clear the cached source
952 if (SCTP_ROUTE_HAS_VALID_IFN(&net->ro) &&
954 (SCTP_GET_IF_INDEX_FROM_ROUTE(&net->ro) != ifn->ifn_index))) {
955 /* clear any cached route */
956 RTFREE(net->ro.ro_rt);
957 net->ro.ro_rt = NULL;
959 /* clear any cached source address */
960 if (net->src_addr_selected) {
961 sctp_free_ifa(net->ro._s_addr);
962 net->ro._s_addr = NULL;
963 net->src_addr_selected = 0;
970 sctp_assoc_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *dstnet)
974 if (dstnet->dest_state & SCTP_ADDR_UNCONFIRMED) {
977 if (stcb->asoc.deleted_primary == NULL) {
981 if (!TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
982 SCTPDBG(SCTP_DEBUG_ASCONF1, "assoc_immediate_retrans: Deleted primary is ");
983 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &stcb->asoc.deleted_primary->ro._l_addr.sa);
984 SCTPDBG(SCTP_DEBUG_ASCONF1, "Current Primary is ");
985 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &stcb->asoc.primary_destination->ro._l_addr.sa);
986 sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb,
987 stcb->asoc.deleted_primary,
988 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_3);
989 stcb->asoc.num_send_timers_up--;
990 if (stcb->asoc.num_send_timers_up < 0) {
991 stcb->asoc.num_send_timers_up = 0;
993 SCTP_TCB_LOCK_ASSERT(stcb);
994 error = sctp_t3rxt_timer(stcb->sctp_ep, stcb,
995 stcb->asoc.deleted_primary);
997 SCTP_INP_DECR_REF(stcb->sctp_ep);
1000 SCTP_TCB_LOCK_ASSERT(stcb);
1001 #ifdef SCTP_AUDITING_ENABLED
1002 sctp_auditing(4, stcb->sctp_ep, stcb, stcb->asoc.deleted_primary);
1004 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED);
1005 if ((stcb->asoc.num_send_timers_up == 0) &&
1006 (stcb->asoc.sent_queue_cnt > 0)) {
1007 struct sctp_tmit_chunk *chk;
1009 chk = TAILQ_FIRST(&stcb->asoc.sent_queue);
1010 sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep,
1018 sctp_asconf_queue_mgmt(struct sctp_tcb *, struct sctp_ifa *, uint16_t);
1021 sctp_net_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *net)
1023 struct sctp_tmit_chunk *chk;
1025 SCTPDBG(SCTP_DEBUG_ASCONF1, "net_immediate_retrans: RTO is %d\n", net->RTO);
1026 sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, net,
1027 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_4);
1028 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
1029 net->error_count = 0;
1030 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
1031 if (chk->whoTo == net) {
1032 if (chk->sent < SCTP_DATAGRAM_RESEND) {
1033 chk->sent = SCTP_DATAGRAM_RESEND;
1034 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
1035 sctp_flight_size_decrease(chk);
1036 sctp_total_flight_decrease(stcb, chk);
1037 net->marked_retrans++;
1038 stcb->asoc.marked_retrans++;
1042 if (net->marked_retrans) {
1043 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED);
1048 sctp_path_check_and_react(struct sctp_tcb *stcb, struct sctp_ifa *newifa)
1050 struct sctp_nets *net;
1051 int addrnum, changed;
1054 * If number of local valid addresses is 1, the valid address is
1055 * probably newly added address. Several valid addresses in this
1056 * association. A source address may not be changed. Additionally,
1057 * they can be configured on a same interface as "alias" addresses.
1060 addrnum = sctp_local_addr_count(stcb);
1061 SCTPDBG(SCTP_DEBUG_ASCONF1, "p_check_react(): %d local addresses\n",
1064 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1065 /* clear any cached route and source address */
1066 if (net->ro.ro_rt) {
1067 RTFREE(net->ro.ro_rt);
1068 net->ro.ro_rt = NULL;
1070 if (net->src_addr_selected) {
1071 sctp_free_ifa(net->ro._s_addr);
1072 net->ro._s_addr = NULL;
1073 net->src_addr_selected = 0;
1075 /* Retransmit unacknowledged DATA chunks immediately */
1076 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
1077 SCTP_MOBILITY_FASTHANDOFF)) {
1078 sctp_net_immediate_retrans(stcb, net);
1080 /* also, SET PRIMARY is maybe already sent */
1085 /* Multiple local addresses exsist in the association. */
1086 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1087 /* clear any cached route and source address */
1088 if (net->ro.ro_rt) {
1089 RTFREE(net->ro.ro_rt);
1090 net->ro.ro_rt = NULL;
1092 if (net->src_addr_selected) {
1093 sctp_free_ifa(net->ro._s_addr);
1094 net->ro._s_addr = NULL;
1095 net->src_addr_selected = 0;
1098 * Check if the nexthop is corresponding to the new address.
1099 * If the new address is corresponding to the current
1100 * nexthop, the path will be changed. If the new address is
1101 * NOT corresponding to the current nexthop, the path will
1104 SCTP_RTALLOC((sctp_route_t *)&net->ro,
1105 stcb->sctp_ep->def_vrf_id,
1106 stcb->sctp_ep->fibnum);
1107 if (net->ro.ro_rt == NULL)
1111 switch (net->ro._l_addr.sa.sa_family) {
1114 if (sctp_v4src_match_nexthop(newifa, (sctp_route_t *)&net->ro)) {
1121 if (sctp_v6src_match_nexthop(
1122 &newifa->address.sin6, (sctp_route_t *)&net->ro)) {
1131 * if the newly added address does not relate routing
1132 * information, we skip.
1136 /* Retransmit unacknowledged DATA chunks immediately */
1137 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
1138 SCTP_MOBILITY_FASTHANDOFF)) {
1139 sctp_net_immediate_retrans(stcb, net);
1141 /* Send SET PRIMARY for this new address */
1142 if (net == stcb->asoc.primary_destination) {
1143 (void)sctp_asconf_queue_mgmt(stcb, newifa,
1144 SCTP_SET_PRIM_ADDR);
1150 * process an ADD/DELETE IP ack from peer.
1151 * addr: corresponding sctp_ifa to the address being added/deleted.
1152 * type: SCTP_ADD_IP_ADDRESS or SCTP_DEL_IP_ADDRESS.
1153 * flag: 1=success, 0=failure.
1156 sctp_asconf_addr_mgmt_ack(struct sctp_tcb *stcb, struct sctp_ifa *addr, uint32_t flag)
1159 * do the necessary asoc list work- if we get a failure indication,
1160 * leave the address on the assoc's restricted list. If we get a
1161 * success indication, remove the address from the restricted list.
1164 * Note: this will only occur for ADD_IP_ADDRESS, since
1165 * DEL_IP_ADDRESS is never actually added to the list...
1168 /* success case, so remove from the restricted list */
1169 sctp_del_local_addr_restricted(stcb, addr);
1171 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
1172 SCTP_MOBILITY_BASE) ||
1173 sctp_is_mobility_feature_on(stcb->sctp_ep,
1174 SCTP_MOBILITY_FASTHANDOFF)) {
1175 sctp_path_check_and_react(stcb, addr);
1178 /* clear any cached/topologically incorrect source addresses */
1179 sctp_asconf_nets_cleanup(stcb, addr->ifn_p);
1181 /* else, leave it on the list */
1185 * add an asconf add/delete/set primary IP address parameter to the queue.
1186 * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR.
1187 * returns 0 if queued, -1 if not queued/removed.
1188 * NOTE: if adding, but a delete for the same address is already scheduled
1189 * (and not yet sent out), simply remove it from queue. Same for deleting
1190 * an address already scheduled for add. If a duplicate operation is found,
1191 * ignore the new one.
1194 sctp_asconf_queue_mgmt(struct sctp_tcb *stcb, struct sctp_ifa *ifa,
1197 struct sctp_asconf_addr *aa, *aa_next;
1199 /* make sure the request isn't already in the queue */
1200 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) {
1201 /* address match? */
1202 if (sctp_asconf_addr_match(aa, &ifa->address.sa) == 0)
1205 * is the request already in queue but not sent? pass the
1206 * request already sent in order to resolve the following
1207 * case: 1. arrival of ADD, then sent 2. arrival of DEL. we
1208 * can't remove the ADD request already sent 3. arrival of
1211 if (aa->ap.aph.ph.param_type == type && aa->sent == 0) {
1214 /* is the negative request already in queue, and not sent */
1215 if ((aa->sent == 0) && (type == SCTP_ADD_IP_ADDRESS) &&
1216 (aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS)) {
1217 /* add requested, delete already queued */
1218 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1219 /* remove the ifa from the restricted list */
1220 sctp_del_local_addr_restricted(stcb, ifa);
1221 /* free the asconf param */
1222 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1223 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_mgmt: add removes queued entry\n");
1226 if ((aa->sent == 0) && (type == SCTP_DEL_IP_ADDRESS) &&
1227 (aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS)) {
1228 /* delete requested, add already queued */
1229 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1230 /* remove the aa->ifa from the restricted list */
1231 sctp_del_local_addr_restricted(stcb, aa->ifa);
1232 /* free the asconf param */
1233 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1234 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_mgmt: delete removes queued entry\n");
1239 /* adding new request to the queue */
1240 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
1243 /* didn't get memory */
1244 SCTPDBG(SCTP_DEBUG_ASCONF1, "asconf_queue_mgmt: failed to get memory!\n");
1247 aa->special_del = 0;
1248 /* fill in asconf address parameter fields */
1249 /* top level elements are "networked" during send */
1250 aa->ap.aph.ph.param_type = type;
1252 atomic_add_int(&ifa->refcount, 1);
1253 /* correlation_id filled in during send routine later... */
1254 switch (ifa->address.sa.sa_family) {
1258 struct sockaddr_in6 *sin6;
1260 sin6 = &ifa->address.sin6;
1261 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
1262 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param));
1263 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) +
1264 sizeof(struct sctp_ipv6addr_param);
1265 memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr,
1266 sizeof(struct in6_addr));
1273 struct sockaddr_in *sin;
1275 sin = &ifa->address.sin;
1276 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
1277 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param));
1278 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) +
1279 sizeof(struct sctp_ipv4addr_param);
1280 memcpy(&aa->ap.addrp.addr, &sin->sin_addr,
1281 sizeof(struct in_addr));
1286 /* invalid family! */
1287 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1291 aa->sent = 0; /* clear sent flag */
1293 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
1295 if (SCTP_BASE_SYSCTL(sctp_debug_on) & SCTP_DEBUG_ASCONF2) {
1296 if (type == SCTP_ADD_IP_ADDRESS) {
1297 SCTP_PRINTF("asconf_queue_mgmt: inserted asconf ADD_IP_ADDRESS: ");
1298 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa);
1299 } else if (type == SCTP_DEL_IP_ADDRESS) {
1300 SCTP_PRINTF("asconf_queue_mgmt: appended asconf DEL_IP_ADDRESS: ");
1301 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa);
1303 SCTP_PRINTF("asconf_queue_mgmt: appended asconf SET_PRIM_ADDR: ");
1304 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa);
1314 * add an asconf operation for the given ifa and type.
1315 * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR.
1316 * returns 0 if completed, -1 if not completed, 1 if immediate send is
1320 sctp_asconf_queue_add(struct sctp_tcb *stcb, struct sctp_ifa *ifa,
1324 int pending_delete_queued = 0;
1327 /* see if peer supports ASCONF */
1328 if (stcb->asoc.asconf_supported == 0) {
1333 * if this is deleting the last address from the assoc, mark it as
1336 if ((type == SCTP_DEL_IP_ADDRESS) && !stcb->asoc.asconf_del_pending) {
1337 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1338 last = (sctp_local_addr_count(stcb) == 0);
1340 last = (sctp_local_addr_count(stcb) == 1);
1343 /* set the pending delete info only */
1344 stcb->asoc.asconf_del_pending = 1;
1345 stcb->asoc.asconf_addr_del_pending = ifa;
1346 atomic_add_int(&ifa->refcount, 1);
1347 SCTPDBG(SCTP_DEBUG_ASCONF2,
1348 "asconf_queue_add: mark delete last address pending\n");
1353 /* queue an asconf parameter */
1354 status = sctp_asconf_queue_mgmt(stcb, ifa, type);
1357 * if this is an add, and there is a delete also pending (i.e. the
1358 * last local address is being changed), queue the pending delete
1361 if ((type == SCTP_ADD_IP_ADDRESS) && stcb->asoc.asconf_del_pending && (status == 0)) {
1362 /* queue in the pending delete */
1363 if (sctp_asconf_queue_mgmt(stcb,
1364 stcb->asoc.asconf_addr_del_pending,
1365 SCTP_DEL_IP_ADDRESS) == 0) {
1366 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_add: queing pending delete\n");
1367 pending_delete_queued = 1;
1368 /* clear out the pending delete info */
1369 stcb->asoc.asconf_del_pending = 0;
1370 sctp_free_ifa(stcb->asoc.asconf_addr_del_pending);
1371 stcb->asoc.asconf_addr_del_pending = NULL;
1375 if (pending_delete_queued) {
1376 struct sctp_nets *net;
1379 * since we know that the only/last address is now being
1380 * changed in this case, reset the cwnd/rto on all nets to
1381 * start as a new address and path. Also clear the error
1382 * counts to give the assoc the best chance to complete the
1385 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1386 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb,
1389 net->error_count = 0;
1391 stcb->asoc.overall_error_count = 0;
1392 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) {
1393 sctp_misc_ints(SCTP_THRESHOLD_CLEAR,
1394 stcb->asoc.overall_error_count,
1396 SCTP_FROM_SCTP_ASCONF,
1400 /* queue in an advisory set primary too */
1401 (void)sctp_asconf_queue_mgmt(stcb, ifa, SCTP_SET_PRIM_ADDR);
1402 /* let caller know we should send this out immediately */
1409 * add an asconf delete IP address parameter to the queue by sockaddr and
1410 * possibly with no sctp_ifa available. This is only called by the routine
1411 * that checks the addresses in an INIT-ACK against the current address list.
1412 * returns 0 if completed, non-zero if not completed.
1413 * NOTE: if an add is already scheduled (and not yet sent out), simply
1414 * remove it from queue. If a duplicate operation is found, ignore the
1418 sctp_asconf_queue_sa_delete(struct sctp_tcb *stcb, struct sockaddr *sa)
1420 struct sctp_ifa *ifa;
1421 struct sctp_asconf_addr *aa, *aa_next;
1426 /* see if peer supports ASCONF */
1427 if (stcb->asoc.asconf_supported == 0) {
1430 /* make sure the request isn't already in the queue */
1431 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) {
1432 /* address match? */
1433 if (sctp_asconf_addr_match(aa, sa) == 0)
1435 /* is the request already in queue (sent or not) */
1436 if (aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) {
1439 /* is the negative request already in queue, and not sent */
1442 if (aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS) {
1443 /* add already queued, so remove existing entry */
1444 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1445 sctp_del_local_addr_restricted(stcb, aa->ifa);
1446 /* free the entry */
1447 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1452 /* find any existing ifa-- NOTE ifa CAN be allowed to be NULL */
1453 ifa = sctp_find_ifa_by_addr(sa, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
1455 /* adding new request to the queue */
1456 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
1459 /* didn't get memory */
1460 SCTPDBG(SCTP_DEBUG_ASCONF1,
1461 "sctp_asconf_queue_sa_delete: failed to get memory!\n");
1464 aa->special_del = 0;
1465 /* fill in asconf address parameter fields */
1466 /* top level elements are "networked" during send */
1467 aa->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS;
1470 atomic_add_int(&ifa->refcount, 1);
1471 /* correlation_id filled in during send routine later... */
1472 switch (sa->sa_family) {
1477 struct sockaddr_in6 *sin6;
1479 sin6 = (struct sockaddr_in6 *)sa;
1480 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
1481 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param));
1482 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv6addr_param);
1483 memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr,
1484 sizeof(struct in6_addr));
1492 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
1494 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
1495 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param));
1496 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv4addr_param);
1497 memcpy(&aa->ap.addrp.addr, &sin->sin_addr,
1498 sizeof(struct in_addr));
1503 /* invalid family! */
1504 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1509 aa->sent = 0; /* clear sent flag */
1511 /* delete goes to the back of the queue */
1512 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
1514 /* sa_ignore MEMLEAK {memory is put on the tailq} */
1519 * find a specific asconf param on our "sent" queue
1521 static struct sctp_asconf_addr *
1522 sctp_asconf_find_param(struct sctp_tcb *stcb, uint32_t correlation_id)
1524 struct sctp_asconf_addr *aa;
1526 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
1527 if (aa->ap.aph.correlation_id == correlation_id &&
1533 /* didn't find it */
1538 * process an SCTP_ERROR_CAUSE_IND for a ASCONF-ACK parameter and do
1539 * notifications based on the error response
1542 sctp_asconf_process_error(struct sctp_tcb *stcb SCTP_UNUSED,
1543 struct sctp_asconf_paramhdr *aph)
1545 struct sctp_error_cause *eh;
1546 struct sctp_paramhdr *ph;
1547 uint16_t param_type;
1548 uint16_t error_code;
1550 eh = (struct sctp_error_cause *)(aph + 1);
1551 ph = (struct sctp_paramhdr *)(eh + 1);
1552 /* validate lengths */
1553 if (htons(eh->length) + sizeof(struct sctp_error_cause) >
1554 htons(aph->ph.param_length)) {
1555 /* invalid error cause length */
1556 SCTPDBG(SCTP_DEBUG_ASCONF1,
1557 "asconf_process_error: cause element too long\n");
1560 if (htons(ph->param_length) + sizeof(struct sctp_paramhdr) >
1561 htons(eh->length)) {
1562 /* invalid included TLV length */
1563 SCTPDBG(SCTP_DEBUG_ASCONF1,
1564 "asconf_process_error: included TLV too long\n");
1567 /* which error code ? */
1568 error_code = ntohs(eh->code);
1569 param_type = ntohs(aph->ph.param_type);
1570 /* FIX: this should go back up the REMOTE_ERROR ULP notify */
1571 switch (error_code) {
1572 case SCTP_CAUSE_RESOURCE_SHORTAGE:
1573 /* we allow ourselves to "try again" for this error */
1576 /* peer can't handle it... */
1577 switch (param_type) {
1578 case SCTP_ADD_IP_ADDRESS:
1579 case SCTP_DEL_IP_ADDRESS:
1580 case SCTP_SET_PRIM_ADDR:
1589 * process an asconf queue param.
1590 * aparam: parameter to process, will be removed from the queue.
1591 * flag: 1=success case, 0=failure case
1594 sctp_asconf_process_param_ack(struct sctp_tcb *stcb,
1595 struct sctp_asconf_addr *aparam, uint32_t flag)
1597 uint16_t param_type;
1599 /* process this param */
1600 param_type = aparam->ap.aph.ph.param_type;
1601 switch (param_type) {
1602 case SCTP_ADD_IP_ADDRESS:
1603 SCTPDBG(SCTP_DEBUG_ASCONF1,
1604 "process_param_ack: added IP address\n");
1605 sctp_asconf_addr_mgmt_ack(stcb, aparam->ifa, flag);
1607 case SCTP_DEL_IP_ADDRESS:
1608 SCTPDBG(SCTP_DEBUG_ASCONF1,
1609 "process_param_ack: deleted IP address\n");
1610 /* nothing really to do... lists already updated */
1612 case SCTP_SET_PRIM_ADDR:
1613 SCTPDBG(SCTP_DEBUG_ASCONF1,
1614 "process_param_ack: set primary IP address\n");
1615 /* nothing to do... peer may start using this addr */
1618 /* should NEVER happen */
1622 /* remove the param and free it */
1623 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aparam, next);
1625 sctp_free_ifa(aparam->ifa);
1626 SCTP_FREE(aparam, SCTP_M_ASC_ADDR);
1630 * cleanup from a bad asconf ack parameter
1633 sctp_asconf_ack_clear(struct sctp_tcb *stcb SCTP_UNUSED)
1635 /* assume peer doesn't really know how to do asconfs */
1636 /* XXX we could free the pending queue here */
1641 sctp_handle_asconf_ack(struct mbuf *m, int offset,
1642 struct sctp_asconf_ack_chunk *cp, struct sctp_tcb *stcb,
1643 struct sctp_nets *net, int *abort_no_unlock)
1645 struct sctp_association *asoc;
1646 uint32_t serial_num;
1647 uint16_t ack_length;
1648 struct sctp_asconf_paramhdr *aph;
1649 struct sctp_asconf_addr *aa, *aa_next;
1650 uint32_t last_error_id = 0; /* last error correlation id */
1652 struct sctp_asconf_addr *ap;
1654 /* asconf param buffer */
1655 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE];
1657 /* verify minimum length */
1658 if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_ack_chunk)) {
1659 SCTPDBG(SCTP_DEBUG_ASCONF1,
1660 "handle_asconf_ack: chunk too small = %xh\n",
1661 ntohs(cp->ch.chunk_length));
1665 serial_num = ntohl(cp->serial_number);
1668 * NOTE: we may want to handle this differently- currently, we will
1669 * abort when we get an ack for the expected serial number + 1 (eg.
1670 * we didn't send it), process an ack normally if it is the expected
1671 * serial number, and re-send the previous ack for *ALL* other
1676 * if the serial number is the next expected, but I didn't send it,
1677 * abort the asoc, since someone probably just hijacked us...
1679 if (serial_num == (asoc->asconf_seq_out + 1)) {
1680 struct mbuf *op_err;
1681 char msg[SCTP_DIAG_INFO_LEN];
1683 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got unexpected next serial number! Aborting asoc!\n");
1684 snprintf(msg, sizeof(msg), "Never sent serial number %8.8x",
1686 op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
1687 sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
1688 *abort_no_unlock = 1;
1691 if (serial_num != asoc->asconf_seq_out_acked + 1) {
1692 /* got a duplicate/unexpected ASCONF-ACK */
1693 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got duplicate/unexpected serial number = %xh (expected = %xh)\n",
1694 serial_num, asoc->asconf_seq_out_acked + 1);
1698 if (serial_num == asoc->asconf_seq_out - 1) {
1699 /* stop our timer */
1700 sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, net,
1701 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_5);
1704 /* process the ASCONF-ACK contents */
1705 ack_length = ntohs(cp->ch.chunk_length) -
1706 sizeof(struct sctp_asconf_ack_chunk);
1707 offset += sizeof(struct sctp_asconf_ack_chunk);
1708 /* process through all parameters */
1709 while (ack_length >= sizeof(struct sctp_asconf_paramhdr)) {
1710 unsigned int param_length, param_type;
1712 /* get pointer to next asconf parameter */
1713 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset,
1714 sizeof(struct sctp_asconf_paramhdr), aparam_buf);
1716 /* can't get an asconf paramhdr */
1717 sctp_asconf_ack_clear(stcb);
1720 param_type = ntohs(aph->ph.param_type);
1721 param_length = ntohs(aph->ph.param_length);
1722 if (param_length > ack_length) {
1723 sctp_asconf_ack_clear(stcb);
1726 if (param_length < sizeof(struct sctp_paramhdr)) {
1727 sctp_asconf_ack_clear(stcb);
1730 /* get the complete parameter... */
1731 if (param_length > sizeof(aparam_buf)) {
1732 SCTPDBG(SCTP_DEBUG_ASCONF1,
1733 "param length (%u) larger than buffer size!\n", param_length);
1734 sctp_asconf_ack_clear(stcb);
1737 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf);
1739 sctp_asconf_ack_clear(stcb);
1742 /* correlation_id is transparent to peer, no ntohl needed */
1743 id = aph->correlation_id;
1745 switch (param_type) {
1746 case SCTP_ERROR_CAUSE_IND:
1748 /* find the corresponding asconf param in our queue */
1749 ap = sctp_asconf_find_param(stcb, id);
1751 /* hmm... can't find this in our queue! */
1754 /* process the parameter, failed flag */
1755 sctp_asconf_process_param_ack(stcb, ap, 0);
1756 /* process the error response */
1757 sctp_asconf_process_error(stcb, aph);
1759 case SCTP_SUCCESS_REPORT:
1760 /* find the corresponding asconf param in our queue */
1761 ap = sctp_asconf_find_param(stcb, id);
1763 /* hmm... can't find this in our queue! */
1766 /* process the parameter, success flag */
1767 sctp_asconf_process_param_ack(stcb, ap, 1);
1773 /* update remaining ASCONF-ACK message length to process */
1774 ack_length -= SCTP_SIZE32(param_length);
1775 if (ack_length <= 0) {
1776 /* no more data in the mbuf chain */
1779 offset += SCTP_SIZE32(param_length);
1783 * if there are any "sent" params still on the queue, these are
1784 * implicitly "success", or "failed" (if we got an error back) ...
1785 * so process these appropriately
1787 * we assume that the correlation_id's are monotonically increasing
1788 * beginning from 1 and that we don't have *that* many outstanding
1791 if (last_error_id == 0)
1792 last_error_id--; /* set to "max" value */
1793 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) {
1794 if (aa->sent == 1) {
1796 * implicitly successful or failed if correlation_id
1797 * < last_error_id, then success else, failure
1799 if (aa->ap.aph.correlation_id < last_error_id)
1800 sctp_asconf_process_param_ack(stcb, aa, 1);
1802 sctp_asconf_process_param_ack(stcb, aa, 0);
1805 * since we always process in order (FIFO queue) if
1806 * we reach one that hasn't been sent, the rest
1807 * should not have been sent either. so, we're
1814 /* update the next sequence number to use */
1815 asoc->asconf_seq_out_acked++;
1816 /* remove the old ASCONF on our outbound queue */
1817 sctp_toss_old_asconf(stcb);
1818 if (!TAILQ_EMPTY(&stcb->asoc.asconf_queue)) {
1819 #ifdef SCTP_TIMER_BASED_ASCONF
1820 /* we have more params, so restart our timer */
1821 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep,
1824 /* we have more params, so send out more */
1825 sctp_send_asconf(stcb, net, SCTP_ADDR_NOT_LOCKED);
1832 sctp_is_scopeid_in_nets(struct sctp_tcb *stcb, struct sockaddr *sa)
1834 struct sockaddr_in6 *sin6, *net6;
1835 struct sctp_nets *net;
1837 if (sa->sa_family != AF_INET6) {
1841 sin6 = (struct sockaddr_in6 *)sa;
1842 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) == 0) {
1843 /* not link local address */
1846 /* hunt through our destination nets list for this scope_id */
1847 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1848 if (((struct sockaddr *)(&net->ro._l_addr))->sa_family !=
1851 net6 = (struct sockaddr_in6 *)&net->ro._l_addr;
1852 if (IN6_IS_ADDR_LINKLOCAL(&net6->sin6_addr) == 0)
1854 if (sctp_is_same_scope(sin6, net6)) {
1859 /* didn't find one */
1865 * address management functions
1868 sctp_addr_mgmt_assoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
1869 struct sctp_ifa *ifa, uint16_t type, int addr_locked)
1873 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0 ||
1874 sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_ASCONF)) {
1875 /* subset bound, no ASCONF allowed case, so ignore */
1879 * note: we know this is not the subset bound, no ASCONF case eg.
1880 * this is boundall or subset bound w/ASCONF allowed
1883 /* first, make sure that the address is IPv4 or IPv6 and not jailed */
1884 switch (ifa->address.sa.sa_family) {
1887 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1888 &ifa->address.sin6.sin6_addr) != 0) {
1895 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1896 &ifa->address.sin.sin_addr) != 0) {
1905 /* make sure we're "allowed" to add this type of addr */
1906 if (ifa->address.sa.sa_family == AF_INET6) {
1907 /* invalid if we're not a v6 endpoint */
1908 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0)
1910 /* is the v6 addr really valid ? */
1911 if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) {
1916 /* put this address on the "pending/do not use yet" list */
1917 sctp_add_local_addr_restricted(stcb, ifa);
1919 * check address scope if address is out of scope, don't queue
1920 * anything... note: this would leave the address on both inp and
1923 switch (ifa->address.sa.sa_family) {
1927 struct sockaddr_in6 *sin6;
1929 sin6 = &ifa->address.sin6;
1930 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1931 /* we skip unspecifed addresses */
1934 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1935 if (stcb->asoc.scope.local_scope == 0) {
1938 /* is it the right link local scope? */
1939 if (sctp_is_scopeid_in_nets(stcb, &ifa->address.sa) == 0) {
1943 if (stcb->asoc.scope.site_scope == 0 &&
1944 IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)) {
1953 struct sockaddr_in *sin;
1954 struct in6pcb *inp6;
1956 inp6 = (struct in6pcb *)&inp->ip_inp.inp;
1957 /* invalid if we are a v6 only endpoint */
1958 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1959 SCTP_IPV6_V6ONLY(inp6))
1962 sin = &ifa->address.sin;
1963 if (sin->sin_addr.s_addr == 0) {
1964 /* we skip unspecifed addresses */
1967 if (stcb->asoc.scope.ipv4_local_scope == 0 &&
1968 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) {
1975 /* else, not AF_INET or AF_INET6, so skip */
1979 /* queue an asconf for this address add/delete */
1980 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF)) {
1981 /* does the peer do asconf? */
1982 if (stcb->asoc.asconf_supported) {
1983 /* queue an asconf for this addr */
1984 status = sctp_asconf_queue_add(stcb, ifa, type);
1987 * if queued ok, and in the open state, send out the
1988 * ASCONF. If in the non-open state, these will be
1989 * sent when the state goes open.
1992 ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
1993 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED))) {
1994 #ifdef SCTP_TIMER_BASED_ASCONF
1995 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, inp,
1996 stcb, stcb->asoc.primary_destination);
1998 sctp_send_asconf(stcb, NULL, addr_locked);
2007 sctp_asconf_iterator_ep(struct sctp_inpcb *inp, void *ptr, uint32_t val SCTP_UNUSED)
2009 struct sctp_asconf_iterator *asc;
2010 struct sctp_ifa *ifa;
2011 struct sctp_laddr *l;
2012 int cnt_invalid = 0;
2014 asc = (struct sctp_asconf_iterator *)ptr;
2015 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) {
2017 switch (ifa->address.sa.sa_family) {
2020 /* invalid if we're not a v6 endpoint */
2021 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
2023 if (asc->cnt == cnt_invalid)
2031 /* invalid if we are a v6 only endpoint */
2032 struct in6pcb *inp6;
2034 inp6 = (struct in6pcb *)&inp->ip_inp.inp;
2035 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2036 SCTP_IPV6_V6ONLY(inp6)) {
2038 if (asc->cnt == cnt_invalid)
2045 /* invalid address family */
2047 if (asc->cnt == cnt_invalid)
2055 sctp_asconf_iterator_ep_end(struct sctp_inpcb *inp, void *ptr, uint32_t val SCTP_UNUSED)
2057 struct sctp_ifa *ifa;
2058 struct sctp_asconf_iterator *asc;
2059 struct sctp_laddr *laddr, *nladdr, *l;
2061 /* Only for specific case not bound all */
2062 asc = (struct sctp_asconf_iterator *)ptr;
2063 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) {
2065 if (l->action == SCTP_ADD_IP_ADDRESS) {
2066 LIST_FOREACH(laddr, &inp->sctp_addr_list,
2068 if (laddr->ifa == ifa) {
2074 } else if (l->action == SCTP_DEL_IP_ADDRESS) {
2075 LIST_FOREACH_SAFE(laddr, &inp->sctp_addr_list, sctp_nxt_addr, nladdr) {
2076 /* remove only after all guys are done */
2077 if (laddr->ifa == ifa) {
2078 sctp_del_local_addr_ep(inp, ifa);
2087 sctp_asconf_iterator_stcb(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
2088 void *ptr, uint32_t val SCTP_UNUSED)
2090 struct sctp_asconf_iterator *asc;
2091 struct sctp_ifa *ifa;
2092 struct sctp_laddr *l;
2093 int cnt_invalid = 0;
2097 asc = (struct sctp_asconf_iterator *)ptr;
2098 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) {
2102 /* address's vrf_id must be the vrf_id of the assoc */
2103 if (ifa->vrf_id != stcb->asoc.vrf_id) {
2107 /* Same checks again for assoc */
2108 switch (ifa->address.sa.sa_family) {
2112 /* invalid if we're not a v6 endpoint */
2113 struct sockaddr_in6 *sin6;
2115 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
2117 if (asc->cnt == cnt_invalid)
2122 sin6 = &ifa->address.sin6;
2123 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2124 /* we skip unspecifed addresses */
2127 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
2128 &sin6->sin6_addr) != 0) {
2131 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
2132 if (stcb->asoc.scope.local_scope == 0) {
2135 /* is it the right link local scope? */
2136 if (sctp_is_scopeid_in_nets(stcb, &ifa->address.sa) == 0) {
2146 /* invalid if we are a v6 only endpoint */
2147 struct in6pcb *inp6;
2148 struct sockaddr_in *sin;
2150 inp6 = (struct in6pcb *)&inp->ip_inp.inp;
2151 /* invalid if we are a v6 only endpoint */
2152 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2153 SCTP_IPV6_V6ONLY(inp6))
2156 sin = &ifa->address.sin;
2157 if (sin->sin_addr.s_addr == 0) {
2158 /* we skip unspecifed addresses */
2161 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
2162 &sin->sin_addr) != 0) {
2165 if (stcb->asoc.scope.ipv4_local_scope == 0 &&
2166 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) {
2169 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2170 SCTP_IPV6_V6ONLY(inp6)) {
2172 if (asc->cnt == cnt_invalid)
2181 /* invalid address family */
2183 if (asc->cnt == cnt_invalid)
2190 if (type == SCTP_ADD_IP_ADDRESS) {
2191 /* prevent this address from being used as a source */
2192 sctp_add_local_addr_restricted(stcb, ifa);
2193 } else if (type == SCTP_DEL_IP_ADDRESS) {
2194 struct sctp_nets *net;
2196 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2199 /* delete this address if cached */
2200 if (net->ro._s_addr == ifa) {
2201 sctp_free_ifa(net->ro._s_addr);
2202 net->ro._s_addr = NULL;
2203 net->src_addr_selected = 0;
2207 net->ro.ro_rt = NULL;
2210 * Now we deleted our src address,
2211 * should we not also now reset the
2212 * cwnd/rto to start as if its a new
2215 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
2220 } else if (type == SCTP_SET_PRIM_ADDR) {
2221 if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
2222 /* must validate the ifa is in the ep */
2223 if (sctp_is_addr_in_ep(stcb->sctp_ep, ifa) == 0) {
2227 /* Need to check scopes for this guy */
2228 if (sctp_is_address_in_scope(ifa, &stcb->asoc.scope, 0) == 0) {
2233 /* queue an asconf for this address add/delete */
2234 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF) &&
2235 stcb->asoc.asconf_supported == 1) {
2236 /* queue an asconf for this addr */
2237 status = sctp_asconf_queue_add(stcb, ifa, type);
2239 * if queued ok, and in the open state, update the
2240 * count of queued params. If in the non-open
2241 * state, these get sent when the assoc goes open.
2243 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
2244 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
2252 * If we have queued params in the open state, send out an ASCONF.
2254 if (num_queued > 0) {
2255 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2260 sctp_asconf_iterator_end(void *ptr, uint32_t val SCTP_UNUSED)
2262 struct sctp_asconf_iterator *asc;
2263 struct sctp_ifa *ifa;
2264 struct sctp_laddr *l, *nl;
2266 asc = (struct sctp_asconf_iterator *)ptr;
2267 LIST_FOREACH_SAFE(l, &asc->list_of_work, sctp_nxt_addr, nl) {
2269 if (l->action == SCTP_ADD_IP_ADDRESS) {
2270 /* Clear the defer use flag */
2271 ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE;
2274 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_laddr), l);
2275 SCTP_DECR_LADDR_COUNT();
2277 SCTP_FREE(asc, SCTP_M_ASC_IT);
2281 * sa is the sockaddr to ask the peer to set primary to.
2282 * returns: 0 = completed, -1 = error
2285 sctp_set_primary_ip_address_sa(struct sctp_tcb *stcb, struct sockaddr *sa)
2288 struct sctp_ifa *ifa;
2290 /* find the ifa for the desired set primary */
2291 vrf_id = stcb->asoc.vrf_id;
2292 ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED);
2294 /* Invalid address */
2298 /* queue an ASCONF:SET_PRIM_ADDR to be sent */
2299 if (!sctp_asconf_queue_add(stcb, ifa, SCTP_SET_PRIM_ADDR)) {
2300 /* set primary queuing succeeded */
2301 SCTPDBG(SCTP_DEBUG_ASCONF1,
2302 "set_primary_ip_address_sa: queued on tcb=%p, ",
2304 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
2305 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
2306 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
2307 #ifdef SCTP_TIMER_BASED_ASCONF
2308 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
2309 stcb->sctp_ep, stcb,
2310 stcb->asoc.primary_destination);
2312 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2316 SCTPDBG(SCTP_DEBUG_ASCONF1, "set_primary_ip_address_sa: failed to add to queue on tcb=%p, ",
2318 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
2325 sctp_is_addr_pending(struct sctp_tcb *stcb, struct sctp_ifa *sctp_ifa)
2327 struct sctp_tmit_chunk *chk, *nchk;
2328 unsigned int offset, asconf_limit;
2329 struct sctp_asconf_chunk *acp;
2330 struct sctp_asconf_paramhdr *aph;
2331 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE];
2332 struct sctp_paramhdr *ph;
2333 int add_cnt, del_cnt;
2334 uint16_t last_param_type;
2336 add_cnt = del_cnt = 0;
2337 last_param_type = 0;
2338 TAILQ_FOREACH_SAFE(chk, &stcb->asoc.asconf_send_queue, sctp_next, nchk) {
2339 if (chk->data == NULL) {
2340 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: No mbuf data?\n");
2344 acp = mtod(chk->data, struct sctp_asconf_chunk *);
2345 offset += sizeof(struct sctp_asconf_chunk);
2346 asconf_limit = ntohs(acp->ch.chunk_length);
2347 ph = (struct sctp_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_paramhdr), aparam_buf);
2349 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: couldn't get lookup addr!\n");
2352 offset += ntohs(ph->param_length);
2354 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_asconf_paramhdr), aparam_buf);
2356 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: Empty ASCONF will be sent?\n");
2359 while (aph != NULL) {
2360 unsigned int param_length, param_type;
2362 param_type = ntohs(aph->ph.param_type);
2363 param_length = ntohs(aph->ph.param_length);
2364 if (offset + param_length > asconf_limit) {
2365 /* parameter goes beyond end of chunk! */
2368 if (param_length > sizeof(aparam_buf)) {
2369 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: param length (%u) larger than buffer size!\n", param_length);
2372 if (param_length <= sizeof(struct sctp_paramhdr)) {
2373 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: param length(%u) too short\n", param_length);
2377 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, param_length, aparam_buf);
2379 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: couldn't get entire param\n");
2383 ph = (struct sctp_paramhdr *)(aph + 1);
2384 if (sctp_addr_match(ph, &sctp_ifa->address.sa) != 0) {
2385 switch (param_type) {
2386 case SCTP_ADD_IP_ADDRESS:
2389 case SCTP_DEL_IP_ADDRESS:
2395 last_param_type = param_type;
2398 offset += SCTP_SIZE32(param_length);
2399 if (offset >= asconf_limit) {
2400 /* no more data in the mbuf chain */
2403 /* get pointer to next asconf param */
2404 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_asconf_paramhdr), aparam_buf);
2409 * we want to find the sequences which consist of ADD -> DEL -> ADD
2412 if (add_cnt > del_cnt ||
2413 (add_cnt == del_cnt && last_param_type == SCTP_ADD_IP_ADDRESS)) {
2419 static struct sockaddr *
2420 sctp_find_valid_localaddr(struct sctp_tcb *stcb, int addr_locked)
2422 struct sctp_vrf *vrf = NULL;
2423 struct sctp_ifn *sctp_ifn;
2424 struct sctp_ifa *sctp_ifa;
2426 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2427 SCTP_IPI_ADDR_RLOCK();
2428 vrf = sctp_find_vrf(stcb->asoc.vrf_id);
2430 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2431 SCTP_IPI_ADDR_RUNLOCK();
2434 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
2435 if (stcb->asoc.scope.loopback_scope == 0 &&
2436 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
2437 /* Skip if loopback_scope not set */
2440 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
2441 switch (sctp_ifa->address.sa.sa_family) {
2444 if (stcb->asoc.scope.ipv4_addr_legal) {
2445 struct sockaddr_in *sin;
2447 sin = &sctp_ifa->address.sin;
2448 if (sin->sin_addr.s_addr == 0) {
2449 /* skip unspecifed addresses */
2452 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
2453 &sin->sin_addr) != 0) {
2456 if (stcb->asoc.scope.ipv4_local_scope == 0 &&
2457 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))
2460 if (sctp_is_addr_restricted(stcb, sctp_ifa) &&
2461 (!sctp_is_addr_pending(stcb, sctp_ifa)))
2464 * found a valid local v4 address to
2467 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2468 SCTP_IPI_ADDR_RUNLOCK();
2469 return (&sctp_ifa->address.sa);
2475 if (stcb->asoc.scope.ipv6_addr_legal) {
2476 struct sockaddr_in6 *sin6;
2478 if (sctp_ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) {
2482 sin6 = &sctp_ifa->address.sin6;
2483 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2485 * we skip unspecifed
2490 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
2491 &sin6->sin6_addr) != 0) {
2494 if (stcb->asoc.scope.local_scope == 0 &&
2495 IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))
2497 if (stcb->asoc.scope.site_scope == 0 &&
2498 IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))
2501 if (sctp_is_addr_restricted(stcb, sctp_ifa) &&
2502 (!sctp_is_addr_pending(stcb, sctp_ifa)))
2505 * found a valid local v6 address to
2508 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2509 SCTP_IPI_ADDR_RUNLOCK();
2510 return (&sctp_ifa->address.sa);
2519 /* no valid addresses found */
2520 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2521 SCTP_IPI_ADDR_RUNLOCK();
2525 static struct sockaddr *
2526 sctp_find_valid_localaddr_ep(struct sctp_tcb *stcb)
2528 struct sctp_laddr *laddr;
2530 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
2531 if (laddr->ifa == NULL) {
2534 /* is the address restricted ? */
2535 if (sctp_is_addr_restricted(stcb, laddr->ifa) &&
2536 (!sctp_is_addr_pending(stcb, laddr->ifa)))
2539 /* found a valid local address to use */
2540 return (&laddr->ifa->address.sa);
2542 /* no valid addresses found */
2547 * builds an ASCONF chunk from queued ASCONF params.
2548 * returns NULL on error (no mbuf, no ASCONF params queued, etc).
2551 sctp_compose_asconf(struct sctp_tcb *stcb, int *retlen, int addr_locked)
2553 struct mbuf *m_asconf, *m_asconf_chk;
2554 struct sctp_asconf_addr *aa;
2555 struct sctp_asconf_chunk *acp;
2556 struct sctp_asconf_paramhdr *aph;
2557 struct sctp_asconf_addr_param *aap;
2559 uint32_t correlation_id = 1; /* 0 is reserved... */
2560 caddr_t ptr, lookup_ptr;
2561 uint8_t lookup_used = 0;
2563 /* are there any asconf params to send? */
2564 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
2572 * get a chunk header mbuf and a cluster for the asconf params since
2573 * it's simpler to fill in the asconf chunk header lookup address on
2576 m_asconf_chk = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_chunk), 0, M_NOWAIT, 1, MT_DATA);
2577 if (m_asconf_chk == NULL) {
2579 SCTPDBG(SCTP_DEBUG_ASCONF1,
2580 "compose_asconf: couldn't get chunk mbuf!\n");
2583 m_asconf = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA);
2584 if (m_asconf == NULL) {
2586 SCTPDBG(SCTP_DEBUG_ASCONF1,
2587 "compose_asconf: couldn't get mbuf!\n");
2588 sctp_m_freem(m_asconf_chk);
2591 SCTP_BUF_LEN(m_asconf_chk) = sizeof(struct sctp_asconf_chunk);
2592 SCTP_BUF_LEN(m_asconf) = 0;
2593 acp = mtod(m_asconf_chk, struct sctp_asconf_chunk *);
2594 memset(acp, 0, sizeof(struct sctp_asconf_chunk));
2595 /* save pointers to lookup address and asconf params */
2596 lookup_ptr = (caddr_t)(acp + 1); /* after the header */
2597 ptr = mtod(m_asconf, caddr_t); /* beginning of cluster */
2599 /* fill in chunk header info */
2600 acp->ch.chunk_type = SCTP_ASCONF;
2601 acp->ch.chunk_flags = 0;
2602 acp->serial_number = htonl(stcb->asoc.asconf_seq_out);
2603 stcb->asoc.asconf_seq_out++;
2605 /* add parameters... up to smallest MTU allowed */
2606 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
2609 /* get the parameter length */
2610 p_length = SCTP_SIZE32(aa->ap.aph.ph.param_length);
2611 /* will it fit in current chunk? */
2612 if ((SCTP_BUF_LEN(m_asconf) + p_length > stcb->asoc.smallest_mtu) ||
2613 (SCTP_BUF_LEN(m_asconf) + p_length > MCLBYTES)) {
2614 /* won't fit, so we're done with this chunk */
2617 /* assign (and store) a correlation id */
2618 aa->ap.aph.correlation_id = correlation_id++;
2621 * fill in address if we're doing a delete this is a simple
2622 * way for us to fill in the correlation address, which
2623 * should only be used by the peer if we're deleting our
2624 * source address and adding a new address (e.g. renumbering
2627 if (lookup_used == 0 &&
2628 (aa->special_del == 0) &&
2629 aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) {
2630 struct sctp_ipv6addr_param *lookup;
2631 uint16_t p_size, addr_size;
2633 lookup = (struct sctp_ipv6addr_param *)lookup_ptr;
2634 lookup->ph.param_type =
2635 htons(aa->ap.addrp.ph.param_type);
2636 if (aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) {
2637 /* copy IPv6 address */
2638 p_size = sizeof(struct sctp_ipv6addr_param);
2639 addr_size = sizeof(struct in6_addr);
2641 /* copy IPv4 address */
2642 p_size = sizeof(struct sctp_ipv4addr_param);
2643 addr_size = sizeof(struct in_addr);
2645 lookup->ph.param_length = htons(SCTP_SIZE32(p_size));
2646 memcpy(lookup->addr, &aa->ap.addrp.addr, addr_size);
2647 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size);
2650 /* copy into current space */
2651 memcpy(ptr, &aa->ap, p_length);
2653 /* network elements and update lengths */
2654 aph = (struct sctp_asconf_paramhdr *)ptr;
2655 aap = (struct sctp_asconf_addr_param *)ptr;
2656 /* correlation_id is transparent to peer, no htonl needed */
2657 aph->ph.param_type = htons(aph->ph.param_type);
2658 aph->ph.param_length = htons(aph->ph.param_length);
2659 aap->addrp.ph.param_type = htons(aap->addrp.ph.param_type);
2660 aap->addrp.ph.param_length = htons(aap->addrp.ph.param_length);
2662 SCTP_BUF_LEN(m_asconf) += SCTP_SIZE32(p_length);
2663 ptr += SCTP_SIZE32(p_length);
2666 * these params are removed off the pending list upon
2667 * getting an ASCONF-ACK back from the peer, just set flag
2671 /* check to see if the lookup addr has been populated yet */
2672 if (lookup_used == 0) {
2673 /* NOTE: if the address param is optional, can skip this... */
2674 /* add any valid (existing) address... */
2675 struct sctp_ipv6addr_param *lookup;
2676 uint16_t p_size, addr_size;
2677 struct sockaddr *found_addr;
2680 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL)
2681 found_addr = sctp_find_valid_localaddr(stcb,
2684 found_addr = sctp_find_valid_localaddr_ep(stcb);
2686 lookup = (struct sctp_ipv6addr_param *)lookup_ptr;
2687 if (found_addr != NULL) {
2688 switch (found_addr->sa_family) {
2691 /* copy IPv6 address */
2692 lookup->ph.param_type =
2693 htons(SCTP_IPV6_ADDRESS);
2694 p_size = sizeof(struct sctp_ipv6addr_param);
2695 addr_size = sizeof(struct in6_addr);
2696 addr_ptr = (caddr_t)&((struct sockaddr_in6 *)
2697 found_addr)->sin6_addr;
2702 /* copy IPv4 address */
2703 lookup->ph.param_type =
2704 htons(SCTP_IPV4_ADDRESS);
2705 p_size = sizeof(struct sctp_ipv4addr_param);
2706 addr_size = sizeof(struct in_addr);
2707 addr_ptr = (caddr_t)&((struct sockaddr_in *)
2708 found_addr)->sin_addr;
2717 lookup->ph.param_length = htons(SCTP_SIZE32(p_size));
2718 memcpy(lookup->addr, addr_ptr, addr_size);
2719 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size);
2721 /* uh oh... don't have any address?? */
2722 SCTPDBG(SCTP_DEBUG_ASCONF1,
2723 "compose_asconf: no lookup addr!\n");
2724 /* XXX for now, we send a IPv4 address of 0.0.0.0 */
2725 lookup->ph.param_type = htons(SCTP_IPV4_ADDRESS);
2726 lookup->ph.param_length = htons(SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param)));
2727 memset(lookup->addr, 0, sizeof(struct in_addr));
2728 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param));
2731 /* chain it all together */
2732 SCTP_BUF_NEXT(m_asconf_chk) = m_asconf;
2733 *retlen = SCTP_BUF_LEN(m_asconf_chk) + SCTP_BUF_LEN(m_asconf);
2734 acp->ch.chunk_length = htons(*retlen);
2736 return (m_asconf_chk);
2740 * section to handle address changes before an association is up eg. changes
2741 * during INIT/INIT-ACK/COOKIE-ECHO handshake
2745 * processes the (local) addresses in the INIT-ACK chunk
2748 sctp_process_initack_addresses(struct sctp_tcb *stcb, struct mbuf *m,
2749 unsigned int offset, unsigned int length)
2751 struct sctp_paramhdr tmp_param, *ph;
2752 uint16_t plen, ptype;
2753 struct sctp_ifa *sctp_ifa;
2754 union sctp_sockstore store;
2756 struct sctp_ipv6addr_param addr6_store;
2759 struct sctp_ipv4addr_param addr4_store;
2762 SCTPDBG(SCTP_DEBUG_ASCONF2, "processing init-ack addresses\n");
2763 if (stcb == NULL) /* Un-needed check for SA */
2766 /* convert to upper bound */
2769 if ((offset + sizeof(struct sctp_paramhdr)) > length) {
2772 /* go through the addresses in the init-ack */
2773 ph = (struct sctp_paramhdr *)
2774 sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr),
2775 (uint8_t *)&tmp_param);
2776 while (ph != NULL) {
2777 ptype = ntohs(ph->param_type);
2778 plen = ntohs(ph->param_length);
2781 case SCTP_IPV6_ADDRESS:
2783 struct sctp_ipv6addr_param *a6p;
2785 /* get the entire IPv6 address param */
2786 a6p = (struct sctp_ipv6addr_param *)
2787 sctp_m_getptr(m, offset,
2788 sizeof(struct sctp_ipv6addr_param),
2789 (uint8_t *)&addr6_store);
2790 if (plen != sizeof(struct sctp_ipv6addr_param) ||
2794 memset(&store, 0, sizeof(union sctp_sockstore));
2795 store.sin6.sin6_family = AF_INET6;
2796 store.sin6.sin6_len = sizeof(struct sockaddr_in6);
2797 store.sin6.sin6_port = stcb->rport;
2798 memcpy(&store.sin6.sin6_addr, a6p->addr, sizeof(struct in6_addr));
2803 case SCTP_IPV4_ADDRESS:
2805 struct sctp_ipv4addr_param *a4p;
2807 /* get the entire IPv4 address param */
2808 a4p = (struct sctp_ipv4addr_param *)sctp_m_getptr(m, offset,
2809 sizeof(struct sctp_ipv4addr_param),
2810 (uint8_t *)&addr4_store);
2811 if (plen != sizeof(struct sctp_ipv4addr_param) ||
2815 memset(&store, 0, sizeof(union sctp_sockstore));
2816 store.sin.sin_family = AF_INET;
2817 store.sin.sin_len = sizeof(struct sockaddr_in);
2818 store.sin.sin_port = stcb->rport;
2819 store.sin.sin_addr.s_addr = a4p->addr;
2827 /* see if this address really (still) exists */
2828 sctp_ifa = sctp_find_ifa_by_addr(&store.sa, stcb->asoc.vrf_id,
2829 SCTP_ADDR_NOT_LOCKED);
2830 if (sctp_ifa == NULL) {
2831 /* address doesn't exist anymore */
2834 /* are ASCONFs allowed ? */
2835 if ((sctp_is_feature_on(stcb->sctp_ep,
2836 SCTP_PCB_FLAGS_DO_ASCONF)) &&
2837 stcb->asoc.asconf_supported) {
2838 /* queue an ASCONF DEL_IP_ADDRESS */
2839 status = sctp_asconf_queue_sa_delete(stcb, &store.sa);
2841 * if queued ok, and in correct state, send
2845 SCTP_GET_STATE(&stcb->asoc) ==
2847 #ifdef SCTP_TIMER_BASED_ASCONF
2848 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
2849 stcb->sctp_ep, stcb,
2850 stcb->asoc.primary_destination);
2852 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2860 * Sanity check: Make sure the length isn't 0, otherwise
2861 * we'll be stuck in this loop for a long time...
2863 if (SCTP_SIZE32(plen) == 0) {
2864 SCTP_PRINTF("process_initack_addrs: bad len (%d) type=%xh\n",
2868 /* get next parameter */
2869 offset += SCTP_SIZE32(plen);
2870 if ((offset + sizeof(struct sctp_paramhdr)) > length)
2872 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset,
2873 sizeof(struct sctp_paramhdr), (uint8_t *)&tmp_param);
2877 /* FIX ME: need to verify return result for v6 address type if v6 disabled */
2879 * checks to see if a specific address is in the initack address list returns
2880 * 1 if found, 0 if not
2883 sctp_addr_in_initack(struct mbuf *m, uint32_t offset, uint32_t length, struct sockaddr *sa)
2885 struct sctp_paramhdr tmp_param, *ph;
2886 uint16_t plen, ptype;
2888 struct sockaddr_in *sin;
2889 struct sctp_ipv4addr_param *a4p;
2890 struct sctp_ipv6addr_param addr4_store;
2893 struct sockaddr_in6 *sin6;
2894 struct sctp_ipv6addr_param *a6p;
2895 struct sctp_ipv6addr_param addr6_store;
2896 struct sockaddr_in6 sin6_tmp;
2899 switch (sa->sa_family) {
2912 SCTPDBG(SCTP_DEBUG_ASCONF2, "find_initack_addr: starting search for ");
2913 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, sa);
2914 /* convert to upper bound */
2917 if ((offset + sizeof(struct sctp_paramhdr)) > length) {
2918 SCTPDBG(SCTP_DEBUG_ASCONF1,
2919 "find_initack_addr: invalid offset?\n");
2922 /* go through the addresses in the init-ack */
2923 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset,
2924 sizeof(struct sctp_paramhdr), (uint8_t *)&tmp_param);
2925 while (ph != NULL) {
2926 ptype = ntohs(ph->param_type);
2927 plen = ntohs(ph->param_length);
2930 case SCTP_IPV6_ADDRESS:
2931 if (sa->sa_family == AF_INET6) {
2932 /* get the entire IPv6 address param */
2933 if (plen != sizeof(struct sctp_ipv6addr_param)) {
2936 /* get the entire IPv6 address param */
2937 a6p = (struct sctp_ipv6addr_param *)
2938 sctp_m_getptr(m, offset,
2939 sizeof(struct sctp_ipv6addr_param),
2940 (uint8_t *)&addr6_store);
2944 sin6 = (struct sockaddr_in6 *)sa;
2945 if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr)) {
2946 /* create a copy and clear scope */
2947 memcpy(&sin6_tmp, sin6,
2948 sizeof(struct sockaddr_in6));
2950 in6_clearscope(&sin6->sin6_addr);
2952 if (memcmp(&sin6->sin6_addr, a6p->addr,
2953 sizeof(struct in6_addr)) == 0) {
2961 case SCTP_IPV4_ADDRESS:
2962 if (sa->sa_family == AF_INET) {
2963 if (plen != sizeof(struct sctp_ipv4addr_param)) {
2966 /* get the entire IPv4 address param */
2967 a4p = (struct sctp_ipv4addr_param *)
2968 sctp_m_getptr(m, offset,
2969 sizeof(struct sctp_ipv4addr_param),
2970 (uint8_t *)&addr4_store);
2974 sin = (struct sockaddr_in *)sa;
2975 if (sin->sin_addr.s_addr == a4p->addr) {
2985 /* get next parameter */
2986 offset += SCTP_SIZE32(plen);
2987 if (offset + sizeof(struct sctp_paramhdr) > length) {
2990 ph = (struct sctp_paramhdr *)
2991 sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr),
2992 (uint8_t *)&tmp_param);
2999 * makes sure that the current endpoint local addr list is consistent with
3000 * the new association (eg. subset bound, asconf allowed) adds addresses as
3004 sctp_check_address_list_ep(struct sctp_tcb *stcb, struct mbuf *m, int offset,
3005 int length, struct sockaddr *init_addr)
3007 struct sctp_laddr *laddr;
3009 /* go through the endpoint list */
3010 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
3011 /* be paranoid and validate the laddr */
3012 if (laddr->ifa == NULL) {
3013 SCTPDBG(SCTP_DEBUG_ASCONF1,
3014 "check_addr_list_ep: laddr->ifa is NULL");
3017 if (laddr->ifa == NULL) {
3018 SCTPDBG(SCTP_DEBUG_ASCONF1, "check_addr_list_ep: laddr->ifa->ifa_addr is NULL");
3021 /* do i have it implicitly? */
3022 if (sctp_cmpaddr(&laddr->ifa->address.sa, init_addr)) {
3025 /* check to see if in the init-ack */
3026 if (!sctp_addr_in_initack(m, offset, length, &laddr->ifa->address.sa)) {
3028 sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb, laddr->ifa,
3029 SCTP_ADD_IP_ADDRESS, SCTP_ADDR_NOT_LOCKED);
3035 * makes sure that the current kernel address list is consistent with the new
3036 * association (with all addrs bound) adds addresses as necessary
3039 sctp_check_address_list_all(struct sctp_tcb *stcb, struct mbuf *m, int offset,
3040 int length, struct sockaddr *init_addr,
3041 uint16_t local_scope, uint16_t site_scope,
3042 uint16_t ipv4_scope, uint16_t loopback_scope)
3044 struct sctp_vrf *vrf = NULL;
3045 struct sctp_ifn *sctp_ifn;
3046 struct sctp_ifa *sctp_ifa;
3049 struct sockaddr_in *sin;
3052 struct sockaddr_in6 *sin6;
3056 vrf_id = stcb->asoc.vrf_id;
3060 SCTP_IPI_ADDR_RLOCK();
3061 vrf = sctp_find_vrf(vrf_id);
3063 SCTP_IPI_ADDR_RUNLOCK();
3066 /* go through all our known interfaces */
3067 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
3068 if (loopback_scope == 0 && SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
3069 /* skip loopback interface */
3072 /* go through each interface address */
3073 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
3074 /* do i have it implicitly? */
3075 if (sctp_cmpaddr(&sctp_ifa->address.sa, init_addr)) {
3078 switch (sctp_ifa->address.sa.sa_family) {
3081 sin = &sctp_ifa->address.sin;
3082 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
3083 &sin->sin_addr) != 0) {
3086 if ((ipv4_scope == 0) &&
3087 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
3088 /* private address not in scope */
3095 sin6 = &sctp_ifa->address.sin6;
3096 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
3097 &sin6->sin6_addr) != 0) {
3100 if ((local_scope == 0) &&
3101 (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))) {
3104 if ((site_scope == 0) &&
3105 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
3113 /* check to see if in the init-ack */
3114 if (!sctp_addr_in_initack(m, offset, length, &sctp_ifa->address.sa)) {
3116 sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb,
3117 sctp_ifa, SCTP_ADD_IP_ADDRESS,
3120 } /* end foreach ifa */
3121 } /* end foreach ifn */
3122 SCTP_IPI_ADDR_RUNLOCK();
3126 * validates an init-ack chunk (from a cookie-echo) with current addresses
3127 * adds addresses from the init-ack into our local address list, if needed
3128 * queues asconf adds/deletes addresses as needed and makes appropriate list
3129 * changes for source address selection m, offset: points to the start of the
3130 * address list in an init-ack chunk length: total length of the address
3131 * params only init_addr: address where my INIT-ACK was sent from
3134 sctp_check_address_list(struct sctp_tcb *stcb, struct mbuf *m, int offset,
3135 int length, struct sockaddr *init_addr,
3136 uint16_t local_scope, uint16_t site_scope,
3137 uint16_t ipv4_scope, uint16_t loopback_scope)
3139 /* process the local addresses in the initack */
3140 sctp_process_initack_addresses(stcb, m, offset, length);
3142 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3143 /* bound all case */
3144 sctp_check_address_list_all(stcb, m, offset, length, init_addr,
3145 local_scope, site_scope, ipv4_scope, loopback_scope);
3147 /* subset bound case */
3148 if (sctp_is_feature_on(stcb->sctp_ep,
3149 SCTP_PCB_FLAGS_DO_ASCONF)) {
3150 /* asconf's allowed */
3151 sctp_check_address_list_ep(stcb, m, offset, length,
3154 /* else, no asconfs allowed, so what we sent is what we get */
3159 * sctp_bindx() support
3162 sctp_addr_mgmt_ep_sa(struct sctp_inpcb *inp, struct sockaddr *sa,
3163 uint32_t type, uint32_t vrf_id, struct sctp_ifa *sctp_ifap)
3165 struct sctp_ifa *ifa;
3166 struct sctp_laddr *laddr, *nladdr;
3168 if (sa->sa_len == 0) {
3169 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EINVAL);
3174 } else if (type == SCTP_ADD_IP_ADDRESS) {
3175 /* For an add the address MUST be on the system */
3176 ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED);
3177 } else if (type == SCTP_DEL_IP_ADDRESS) {
3178 /* For a delete we need to find it in the inp */
3179 ifa = sctp_find_ifa_in_ep(inp, sa, SCTP_ADDR_NOT_LOCKED);
3184 if (type == SCTP_ADD_IP_ADDRESS) {
3185 sctp_add_local_addr_ep(inp, ifa, type);
3186 } else if (type == SCTP_DEL_IP_ADDRESS) {
3187 if (inp->laddr_count < 2) {
3188 /* can't delete the last local address */
3189 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EINVAL);
3192 LIST_FOREACH(laddr, &inp->sctp_addr_list,
3194 if (ifa == laddr->ifa) {
3195 /* Mark in the delete */
3196 laddr->action = type;
3200 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
3202 * There is no need to start the iterator if the inp
3203 * has no associations.
3205 if (type == SCTP_DEL_IP_ADDRESS) {
3206 LIST_FOREACH_SAFE(laddr, &inp->sctp_addr_list, sctp_nxt_addr, nladdr) {
3207 if (laddr->ifa == ifa) {
3208 sctp_del_local_addr_ep(inp, ifa);
3213 struct sctp_asconf_iterator *asc;
3214 struct sctp_laddr *wi;
3217 SCTP_MALLOC(asc, struct sctp_asconf_iterator *,
3218 sizeof(struct sctp_asconf_iterator),
3221 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, ENOMEM);
3224 wi = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_laddr), struct sctp_laddr);
3226 SCTP_FREE(asc, SCTP_M_ASC_IT);
3227 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, ENOMEM);
3230 LIST_INIT(&asc->list_of_work);
3232 SCTP_INCR_LADDR_COUNT();
3235 atomic_add_int(&ifa->refcount, 1);
3236 LIST_INSERT_HEAD(&asc->list_of_work, wi, sctp_nxt_addr);
3237 ret = sctp_initiate_iterator(sctp_asconf_iterator_ep,
3238 sctp_asconf_iterator_stcb,
3239 sctp_asconf_iterator_ep_end,
3241 SCTP_PCB_ANY_FEATURES,
3242 SCTP_ASOC_ANY_STATE,
3244 sctp_asconf_iterator_end, inp, 0);
3246 SCTP_PRINTF("Failed to initiate iterator for addr_mgmt_ep_sa\n");
3247 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EFAULT);
3248 sctp_asconf_iterator_end(asc, 0);
3254 /* invalid address! */
3255 SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EADDRNOTAVAIL);
3256 return (EADDRNOTAVAIL);
3261 sctp_asconf_send_nat_state_update(struct sctp_tcb *stcb,
3262 struct sctp_nets *net)
3264 struct sctp_asconf_addr *aa;
3265 struct sctp_ifa *sctp_ifap;
3266 struct sctp_asconf_tag_param *vtag;
3268 struct sockaddr_in *to;
3271 struct sockaddr_in6 *to6;
3274 SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing net\n");
3278 SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing stcb\n");
3282 * Need to have in the asconf: - vtagparam(my_vtag/peer_vtag) -
3283 * add(0.0.0.0) - del(0.0.0.0) - Any global addresses add(addr)
3285 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
3288 /* didn't get memory */
3289 SCTPDBG(SCTP_DEBUG_ASCONF1,
3290 "sctp_asconf_send_nat_state_update: failed to get memory!\n");
3293 aa->special_del = 0;
3294 /* fill in asconf address parameter fields */
3295 /* top level elements are "networked" during send */
3297 aa->sent = 0; /* clear sent flag */
3298 vtag = (struct sctp_asconf_tag_param *)&aa->ap.aph;
3299 vtag->aph.ph.param_type = SCTP_NAT_VTAGS;
3300 vtag->aph.ph.param_length = sizeof(struct sctp_asconf_tag_param);
3301 vtag->local_vtag = htonl(stcb->asoc.my_vtag);
3302 vtag->remote_vtag = htonl(stcb->asoc.peer_vtag);
3303 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
3305 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
3308 /* didn't get memory */
3309 SCTPDBG(SCTP_DEBUG_ASCONF1,
3310 "sctp_asconf_send_nat_state_update: failed to get memory!\n");
3313 memset(aa, 0, sizeof(struct sctp_asconf_addr));
3314 /* fill in asconf address parameter fields */
3316 switch (net->ro._l_addr.sa.sa_family) {
3319 aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
3320 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param);
3321 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
3322 aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv4addr_param);
3323 /* No need to add an address, we are using 0.0.0.0 */
3324 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
3329 aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
3330 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param);
3331 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
3332 aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv6addr_param);
3333 /* No need to add an address, we are using 0.0.0.0 */
3334 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
3338 SCTPDBG(SCTP_DEBUG_ASCONF1,
3339 "sctp_asconf_send_nat_state_update: unknown address family\n");
3340 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
3343 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
3346 /* didn't get memory */
3347 SCTPDBG(SCTP_DEBUG_ASCONF1,
3348 "sctp_asconf_send_nat_state_update: failed to get memory!\n");
3351 memset(aa, 0, sizeof(struct sctp_asconf_addr));
3352 /* fill in asconf address parameter fields */
3354 switch (net->ro._l_addr.sa.sa_family) {
3357 aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
3358 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param);
3359 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
3360 aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv4addr_param);
3361 /* No need to add an address, we are using 0.0.0.0 */
3362 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
3367 aa->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS;
3368 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param);
3369 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
3370 aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv6addr_param);
3371 /* No need to add an address, we are using 0.0.0.0 */
3372 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
3376 SCTPDBG(SCTP_DEBUG_ASCONF1,
3377 "sctp_asconf_send_nat_state_update: unknown address family\n");
3378 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
3381 /* Now we must hunt the addresses and add all global addresses */
3382 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3383 struct sctp_vrf *vrf = NULL;
3384 struct sctp_ifn *sctp_ifnp;
3387 vrf_id = stcb->sctp_ep->def_vrf_id;
3388 vrf = sctp_find_vrf(vrf_id);
3393 SCTP_IPI_ADDR_RLOCK();
3394 LIST_FOREACH(sctp_ifnp, &vrf->ifnlist, next_ifn) {
3395 LIST_FOREACH(sctp_ifap, &sctp_ifnp->ifalist, next_ifa) {
3396 switch (sctp_ifap->address.sa.sa_family) {
3399 to = &sctp_ifap->address.sin;
3400 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
3401 &to->sin_addr) != 0) {
3404 if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) {
3407 if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) {
3414 to6 = &sctp_ifap->address.sin6;
3415 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
3416 &to6->sin6_addr) != 0) {
3419 if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) {
3422 if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) {
3430 sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS);
3433 SCTP_IPI_ADDR_RUNLOCK();
3435 struct sctp_laddr *laddr;
3437 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
3438 if (laddr->ifa == NULL) {
3441 if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED)
3443 * Address being deleted by the system, dont
3447 if (laddr->action == SCTP_DEL_IP_ADDRESS) {
3449 * Address being deleted on this ep don't
3454 sctp_ifap = laddr->ifa;
3455 switch (sctp_ifap->address.sa.sa_family) {
3458 to = &sctp_ifap->address.sin;
3459 if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) {
3462 if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) {
3469 to6 = &sctp_ifap->address.sin6;
3470 if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) {
3473 if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) {
3481 sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS);
3485 /* Now we must send the asconf into the queue */
3486 sctp_send_asconf(stcb, net, SCTP_ADDR_NOT_LOCKED);