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;
155 #if defined(INET) || defined(INET6)
156 uint16_t param_length;
160 int zero_address = 0;
164 struct sockaddr_in *sin;
165 struct sctp_ipv4addr_param *v4addr;
169 struct sockaddr_in6 *sin6;
170 struct sctp_ipv6addr_param *v6addr;
174 aparam_length = ntohs(aph->ph.param_length);
175 ph = (struct sctp_paramhdr *)(aph + 1);
176 param_type = ntohs(ph->param_type);
177 #if defined(INET) || defined(INET6)
178 param_length = ntohs(ph->param_length);
181 switch (param_type) {
183 case SCTP_IPV4_ADDRESS:
184 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
185 /* invalid param size */
188 v4addr = (struct sctp_ipv4addr_param *)ph;
190 bzero(sin, sizeof(*sin));
191 sin->sin_family = AF_INET;
192 sin->sin_len = sizeof(struct sockaddr_in);
193 sin->sin_port = stcb->rport;
194 sin->sin_addr.s_addr = v4addr->addr;
195 if ((sin->sin_addr.s_addr == INADDR_BROADCAST) ||
196 IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) {
199 if (sin->sin_addr.s_addr == INADDR_ANY)
201 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_add_ip: adding ");
202 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
206 case SCTP_IPV6_ADDRESS:
207 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
208 /* invalid param size */
211 v6addr = (struct sctp_ipv6addr_param *)ph;
213 bzero(sin6, sizeof(*sin6));
214 sin6->sin6_family = AF_INET6;
215 sin6->sin6_len = sizeof(struct sockaddr_in6);
216 sin6->sin6_port = stcb->rport;
217 memcpy((caddr_t)&sin6->sin6_addr, v6addr->addr,
218 sizeof(struct in6_addr));
219 if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
222 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
224 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_add_ip: adding ");
225 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
229 m_reply = sctp_asconf_error_response(aph->correlation_id,
230 SCTP_CAUSE_INVALID_PARAM, (uint8_t *) aph,
235 /* if 0.0.0.0/::0, add the source address instead */
236 if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) {
238 SCTPDBG(SCTP_DEBUG_ASCONF1,
239 "process_asconf_add_ip: using source addr ");
240 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, src);
242 /* add the address */
244 m_reply = sctp_asconf_error_response(aph->correlation_id,
245 SCTP_CAUSE_INVALID_PARAM, (uint8_t *) aph,
247 } else if (sctp_add_remote_addr(stcb, sa, &net, stcb->asoc.port,
249 SCTP_ADDR_DYNAMIC_ADDED) != 0) {
250 SCTPDBG(SCTP_DEBUG_ASCONF1,
251 "process_asconf_add_ip: error adding address\n");
252 m_reply = sctp_asconf_error_response(aph->correlation_id,
253 SCTP_CAUSE_RESOURCE_SHORTAGE, (uint8_t *) aph,
256 /* notify upper layer */
257 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_ADD_IP, stcb, 0, sa, SCTP_SO_NOT_LOCKED);
258 if (response_required) {
260 sctp_asconf_success_response(aph->correlation_id);
262 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, stcb->sctp_ep, stcb, net);
263 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep,
266 sctp_send_hb(stcb, net, SCTP_SO_NOT_LOCKED);
273 sctp_asconf_del_remote_addrs_except(struct sctp_tcb *stcb, struct sockaddr *src)
275 struct sctp_nets *src_net, *net;
277 /* make sure the source address exists as a destination net */
278 src_net = sctp_findnet(stcb, src);
279 if (src_net == NULL) {
283 /* delete all destination addresses except the source */
284 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
285 if (net != src_net) {
286 /* delete this address */
287 sctp_remove_net(stcb, net);
288 SCTPDBG(SCTP_DEBUG_ASCONF1,
289 "asconf_del_remote_addrs_except: deleting ");
290 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1,
291 (struct sockaddr *)&net->ro._l_addr);
292 /* notify upper layer */
293 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0,
294 (struct sockaddr *)&net->ro._l_addr, SCTP_SO_NOT_LOCKED);
301 sctp_process_asconf_delete_ip(struct sockaddr *src,
302 struct sctp_asconf_paramhdr *aph,
303 struct sctp_tcb *stcb, int response_required)
305 struct mbuf *m_reply = NULL;
306 union sctp_sockstore store;
307 struct sctp_paramhdr *ph;
308 uint16_t param_type, aparam_length;
310 #if defined(INET) || defined(INET6)
311 uint16_t param_length;
315 int zero_address = 0;
319 struct sockaddr_in *sin;
320 struct sctp_ipv4addr_param *v4addr;
324 struct sockaddr_in6 *sin6;
325 struct sctp_ipv6addr_param *v6addr;
329 aparam_length = ntohs(aph->ph.param_length);
330 ph = (struct sctp_paramhdr *)(aph + 1);
331 param_type = ntohs(ph->param_type);
332 #if defined(INET) || defined(INET6)
333 param_length = ntohs(ph->param_length);
336 switch (param_type) {
338 case SCTP_IPV4_ADDRESS:
339 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
340 /* invalid param size */
343 v4addr = (struct sctp_ipv4addr_param *)ph;
345 bzero(sin, sizeof(*sin));
346 sin->sin_family = AF_INET;
347 sin->sin_len = sizeof(struct sockaddr_in);
348 sin->sin_port = stcb->rport;
349 sin->sin_addr.s_addr = v4addr->addr;
350 if (sin->sin_addr.s_addr == INADDR_ANY)
352 SCTPDBG(SCTP_DEBUG_ASCONF1,
353 "process_asconf_delete_ip: deleting ");
354 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
358 case SCTP_IPV6_ADDRESS:
359 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
360 /* invalid param size */
363 v6addr = (struct sctp_ipv6addr_param *)ph;
365 bzero(sin6, sizeof(*sin6));
366 sin6->sin6_family = AF_INET6;
367 sin6->sin6_len = sizeof(struct sockaddr_in6);
368 sin6->sin6_port = stcb->rport;
369 memcpy(&sin6->sin6_addr, v6addr->addr,
370 sizeof(struct in6_addr));
371 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
373 SCTPDBG(SCTP_DEBUG_ASCONF1,
374 "process_asconf_delete_ip: deleting ");
375 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
379 m_reply = sctp_asconf_error_response(aph->correlation_id,
380 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph,
385 /* make sure the source address is not being deleted */
386 if (sctp_cmpaddr(sa, src)) {
387 /* trying to delete the source address! */
388 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: tried to delete source addr\n");
389 m_reply = sctp_asconf_error_response(aph->correlation_id,
390 SCTP_CAUSE_DELETING_SRC_ADDR, (uint8_t *) aph,
394 /* if deleting 0.0.0.0/::0, delete all addresses except src addr */
395 if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) {
396 result = sctp_asconf_del_remote_addrs_except(stcb, src);
399 /* src address did not exist? */
400 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: src addr does not exist?\n");
401 /* what error to reply with?? */
403 sctp_asconf_error_response(aph->correlation_id,
404 SCTP_CAUSE_REQUEST_REFUSED, (uint8_t *) aph,
406 } else if (response_required) {
408 sctp_asconf_success_response(aph->correlation_id);
412 /* delete the address */
413 result = sctp_del_remote_addr(stcb, sa);
415 * note if result == -2, the address doesn't exist in the asoc but
416 * since it's being deleted anyways, we just ack the delete -- but
417 * this probably means something has already gone awry
420 /* only one address in the asoc */
421 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: tried to delete last IP addr!\n");
422 m_reply = sctp_asconf_error_response(aph->correlation_id,
423 SCTP_CAUSE_DELETING_LAST_ADDR, (uint8_t *) aph,
426 if (response_required) {
427 m_reply = sctp_asconf_success_response(aph->correlation_id);
429 /* notify upper layer */
430 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0, sa, SCTP_SO_NOT_LOCKED);
436 sctp_process_asconf_set_primary(struct sockaddr *src,
437 struct sctp_asconf_paramhdr *aph,
438 struct sctp_tcb *stcb, int response_required)
440 struct mbuf *m_reply = NULL;
441 union sctp_sockstore store;
442 struct sctp_paramhdr *ph;
443 uint16_t param_type, aparam_length;
445 #if defined(INET) || defined(INET6)
446 uint16_t param_length;
450 int zero_address = 0;
453 struct sockaddr_in *sin;
454 struct sctp_ipv4addr_param *v4addr;
458 struct sockaddr_in6 *sin6;
459 struct sctp_ipv6addr_param *v6addr;
463 aparam_length = ntohs(aph->ph.param_length);
464 ph = (struct sctp_paramhdr *)(aph + 1);
465 param_type = ntohs(ph->param_type);
466 #if defined(INET) || defined(INET6)
467 param_length = ntohs(ph->param_length);
470 switch (param_type) {
472 case SCTP_IPV4_ADDRESS:
473 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
474 /* invalid param size */
477 v4addr = (struct sctp_ipv4addr_param *)ph;
479 bzero(sin, sizeof(*sin));
480 sin->sin_family = AF_INET;
481 sin->sin_len = sizeof(struct sockaddr_in);
482 sin->sin_addr.s_addr = v4addr->addr;
483 if (sin->sin_addr.s_addr == INADDR_ANY)
485 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_set_primary: ");
486 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
490 case SCTP_IPV6_ADDRESS:
491 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
492 /* invalid param size */
495 v6addr = (struct sctp_ipv6addr_param *)ph;
497 bzero(sin6, sizeof(*sin6));
498 sin6->sin6_family = AF_INET6;
499 sin6->sin6_len = sizeof(struct sockaddr_in6);
500 memcpy((caddr_t)&sin6->sin6_addr, v6addr->addr,
501 sizeof(struct in6_addr));
502 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
504 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_set_primary: ");
505 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
509 m_reply = sctp_asconf_error_response(aph->correlation_id,
510 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph,
515 /* if 0.0.0.0/::0, use the source address instead */
516 if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) {
518 SCTPDBG(SCTP_DEBUG_ASCONF1,
519 "process_asconf_set_primary: using source addr ");
520 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, src);
522 /* set the primary address */
523 if (sctp_set_primary_addr(stcb, sa, NULL) == 0) {
524 SCTPDBG(SCTP_DEBUG_ASCONF1,
525 "process_asconf_set_primary: primary address set\n");
526 /* notify upper layer */
527 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_SET_PRIMARY, stcb, 0, sa, SCTP_SO_NOT_LOCKED);
528 if ((stcb->asoc.primary_destination->dest_state & SCTP_ADDR_REACHABLE) &&
529 (!(stcb->asoc.primary_destination->dest_state & SCTP_ADDR_PF)) &&
530 (stcb->asoc.alternate)) {
531 sctp_free_remote_addr(stcb->asoc.alternate);
532 stcb->asoc.alternate = NULL;
534 if (response_required) {
535 m_reply = sctp_asconf_success_response(aph->correlation_id);
538 * Mobility adaptation. Ideally, when the reception of SET
539 * PRIMARY with DELETE IP ADDRESS of the previous primary
540 * destination, unacknowledged DATA are retransmitted
541 * immediately to the new primary destination for seamless
542 * handover. If the destination is UNCONFIRMED and marked to
543 * REQ_PRIM, The retransmission occur when reception of the
544 * HEARTBEAT-ACK. (See sctp_handle_heartbeat_ack in
545 * sctp_input.c) Also, when change of the primary
546 * destination, it is better that all subsequent new DATA
547 * containing already queued DATA are transmitted to the new
548 * primary destination. (by micchie)
550 if ((sctp_is_mobility_feature_on(stcb->sctp_ep,
551 SCTP_MOBILITY_BASE) ||
552 sctp_is_mobility_feature_on(stcb->sctp_ep,
553 SCTP_MOBILITY_FASTHANDOFF)) &&
554 sctp_is_mobility_feature_on(stcb->sctp_ep,
555 SCTP_MOBILITY_PRIM_DELETED) &&
556 (stcb->asoc.primary_destination->dest_state &
557 SCTP_ADDR_UNCONFIRMED) == 0) {
559 sctp_timer_stop(SCTP_TIMER_TYPE_PRIM_DELETED,
560 stcb->sctp_ep, stcb, NULL,
561 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_1);
562 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
563 SCTP_MOBILITY_FASTHANDOFF)) {
564 sctp_assoc_immediate_retrans(stcb,
565 stcb->asoc.primary_destination);
567 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
568 SCTP_MOBILITY_BASE)) {
569 sctp_move_chunks_from_net(stcb,
570 stcb->asoc.deleted_primary);
572 sctp_delete_prim_timer(stcb->sctp_ep, stcb,
573 stcb->asoc.deleted_primary);
576 /* couldn't set the requested primary address! */
577 SCTPDBG(SCTP_DEBUG_ASCONF1,
578 "process_asconf_set_primary: set primary failed!\n");
579 /* must have been an invalid address, so report */
580 m_reply = sctp_asconf_error_response(aph->correlation_id,
581 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph,
589 * handles an ASCONF chunk.
590 * if all parameters are processed ok, send a plain (empty) ASCONF-ACK
593 sctp_handle_asconf(struct mbuf *m, unsigned int offset,
594 struct sockaddr *src,
595 struct sctp_asconf_chunk *cp, struct sctp_tcb *stcb,
598 struct sctp_association *asoc;
600 struct mbuf *n, *m_ack, *m_result, *m_tail;
601 struct sctp_asconf_ack_chunk *ack_cp;
602 struct sctp_asconf_paramhdr *aph;
603 struct sctp_ipv6addr_param *p_addr;
604 unsigned int asconf_limit, cnt;
605 int error = 0; /* did an error occur? */
607 /* asconf param buffer */
608 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE];
609 struct sctp_asconf_ack *ack, *ack_next;
611 /* verify minimum length */
612 if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_chunk)) {
613 SCTPDBG(SCTP_DEBUG_ASCONF1,
614 "handle_asconf: chunk too small = %xh\n",
615 ntohs(cp->ch.chunk_length));
619 serial_num = ntohl(cp->serial_number);
621 if (SCTP_TSN_GE(asoc->asconf_seq_in, serial_num)) {
622 /* got a duplicate ASCONF */
623 SCTPDBG(SCTP_DEBUG_ASCONF1,
624 "handle_asconf: got duplicate serial number = %xh\n",
627 } else if (serial_num != (asoc->asconf_seq_in + 1)) {
628 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: incorrect serial number = %xh (expected next = %xh)\n",
629 serial_num, asoc->asconf_seq_in + 1);
632 /* it's the expected "next" sequence number, so process it */
633 asoc->asconf_seq_in = serial_num; /* update sequence */
634 /* get length of all the param's in the ASCONF */
635 asconf_limit = offset + ntohs(cp->ch.chunk_length);
636 SCTPDBG(SCTP_DEBUG_ASCONF1,
637 "handle_asconf: asconf_limit=%u, sequence=%xh\n",
638 asconf_limit, serial_num);
641 /* delete old cache */
642 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: Now processing first ASCONF. Try to delete old cache\n");
644 TAILQ_FOREACH_SAFE(ack, &asoc->asconf_ack_sent, next, ack_next) {
645 if (ack->serial_number == serial_num)
647 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: delete old(%u) < first(%u)\n",
648 ack->serial_number, serial_num);
649 TAILQ_REMOVE(&asoc->asconf_ack_sent, ack, next);
650 if (ack->data != NULL) {
651 sctp_m_freem(ack->data);
653 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_asconf_ack), ack);
656 m_ack = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_ack_chunk), 0,
657 M_NOWAIT, 1, MT_DATA);
659 SCTPDBG(SCTP_DEBUG_ASCONF1,
660 "handle_asconf: couldn't get mbuf!\n");
663 m_tail = m_ack; /* current reply chain's tail */
665 /* fill in ASCONF-ACK header */
666 ack_cp = mtod(m_ack, struct sctp_asconf_ack_chunk *);
667 ack_cp->ch.chunk_type = SCTP_ASCONF_ACK;
668 ack_cp->ch.chunk_flags = 0;
669 ack_cp->serial_number = htonl(serial_num);
670 /* set initial lengths (eg. just an ASCONF-ACK), ntohx at the end! */
671 SCTP_BUF_LEN(m_ack) = sizeof(struct sctp_asconf_ack_chunk);
672 ack_cp->ch.chunk_length = sizeof(struct sctp_asconf_ack_chunk);
674 /* skip the lookup address parameter */
675 offset += sizeof(struct sctp_asconf_chunk);
676 p_addr = (struct sctp_ipv6addr_param *)sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), (uint8_t *) & aparam_buf);
677 if (p_addr == NULL) {
678 SCTPDBG(SCTP_DEBUG_ASCONF1,
679 "handle_asconf: couldn't get lookup addr!\n");
680 /* respond with a missing/invalid mandatory parameter error */
683 /* param_length is already validated in process_control... */
684 offset += ntohs(p_addr->ph.param_length); /* skip lookup addr */
685 /* get pointer to first asconf param in ASCONF */
686 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, sizeof(struct sctp_asconf_paramhdr), (uint8_t *) & aparam_buf);
688 SCTPDBG(SCTP_DEBUG_ASCONF1, "Empty ASCONF received?\n");
691 /* process through all parameters */
693 while (aph != NULL) {
694 unsigned int param_length, param_type;
696 param_type = ntohs(aph->ph.param_type);
697 param_length = ntohs(aph->ph.param_length);
698 if (offset + param_length > asconf_limit) {
699 /* parameter goes beyond end of chunk! */
705 if (param_length > sizeof(aparam_buf)) {
706 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) larger than buffer size!\n", param_length);
710 if (param_length <= sizeof(struct sctp_paramhdr)) {
711 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) too short\n", param_length);
714 /* get the entire parameter */
715 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf);
717 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: couldn't get entire param\n");
721 switch (param_type) {
722 case SCTP_ADD_IP_ADDRESS:
723 m_result = sctp_process_asconf_add_ip(src, aph, stcb,
724 (cnt < SCTP_BASE_SYSCTL(sctp_hb_maxburst)), error);
727 case SCTP_DEL_IP_ADDRESS:
728 m_result = sctp_process_asconf_delete_ip(src, aph, stcb,
731 case SCTP_ERROR_CAUSE_IND:
732 /* not valid in an ASCONF chunk */
734 case SCTP_SET_PRIM_ADDR:
735 m_result = sctp_process_asconf_set_primary(src, aph,
739 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: sees a NAT VTAG state parameter\n");
741 case SCTP_SUCCESS_REPORT:
742 /* not valid in an ASCONF chunk */
744 case SCTP_ULP_ADAPTATION:
748 if ((param_type & 0x8000) == 0) {
749 /* Been told to STOP at this param */
750 asconf_limit = offset;
752 * FIX FIX - We need to call
753 * sctp_arethere_unrecognized_parameters()
754 * to get a operr and send it for any
755 * param's with the 0x4000 bit set OR do it
756 * here ourselves... note we still must STOP
757 * if the 0x8000 bit is clear.
760 /* unknown/invalid param type */
764 /* add any (error) result to the reply mbuf chain */
765 if (m_result != NULL) {
766 SCTP_BUF_NEXT(m_tail) = m_result;
768 /* update lengths, make sure it's aligned too */
769 SCTP_BUF_LEN(m_result) = SCTP_SIZE32(SCTP_BUF_LEN(m_result));
770 ack_cp->ch.chunk_length += SCTP_BUF_LEN(m_result);
771 /* set flag to force success reports */
774 offset += SCTP_SIZE32(param_length);
775 /* update remaining ASCONF message length to process */
776 if (offset >= asconf_limit) {
777 /* no more data in the mbuf chain */
780 /* get pointer to next asconf param */
781 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset,
782 sizeof(struct sctp_asconf_paramhdr),
783 (uint8_t *) & aparam_buf);
785 /* can't get an asconf paramhdr */
786 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: can't get asconf param hdr!\n");
787 /* FIX ME - add error here... */
792 ack_cp->ch.chunk_length = htons(ack_cp->ch.chunk_length);
793 /* save the ASCONF-ACK reply */
794 ack = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_asconf_ack),
795 struct sctp_asconf_ack);
800 ack->serial_number = serial_num;
801 ack->last_sent_to = NULL;
804 for (n = m_ack; n != NULL; n = SCTP_BUF_NEXT(n)) {
805 ack->len += SCTP_BUF_LEN(n);
807 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_ack_sent, ack, next);
809 /* see if last_control_chunk_from is set properly (use IP src addr) */
810 if (stcb->asoc.last_control_chunk_from == NULL) {
812 * this could happen if the source address was just newly
815 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: looking up net for IP source address\n");
816 SCTPDBG(SCTP_DEBUG_ASCONF1, "Looking for IP source: ");
817 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, src);
818 /* look up the from address */
819 stcb->asoc.last_control_chunk_from = sctp_findnet(stcb, src);
821 if (stcb->asoc.last_control_chunk_from == NULL) {
822 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: IP source address not found?!\n");
829 * does the address match? returns 0 if not, 1 if so
832 sctp_asconf_addr_match(struct sctp_asconf_addr *aa, struct sockaddr *sa)
834 switch (sa->sa_family) {
839 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
841 if ((aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) &&
842 (memcmp(&aa->ap.addrp.addr, &sin6->sin6_addr,
843 sizeof(struct in6_addr)) == 0)) {
852 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
854 if ((aa->ap.addrp.ph.param_type == SCTP_IPV4_ADDRESS) &&
855 (memcmp(&aa->ap.addrp.addr, &sin->sin_addr,
856 sizeof(struct in_addr)) == 0)) {
869 * does the address match? returns 0 if not, 1 if so
872 sctp_addr_match(struct sctp_paramhdr *ph, struct sockaddr *sa)
874 #if defined(INET) || defined(INET6)
875 uint16_t param_type, param_length;
877 param_type = ntohs(ph->param_type);
878 param_length = ntohs(ph->param_length);
880 switch (sa->sa_family) {
885 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
886 struct sctp_ipv6addr_param *v6addr;
888 v6addr = (struct sctp_ipv6addr_param *)ph;
889 if ((param_type == SCTP_IPV6_ADDRESS) &&
890 (param_length == sizeof(struct sctp_ipv6addr_param)) &&
891 (memcmp(&v6addr->addr, &sin6->sin6_addr,
892 sizeof(struct in6_addr)) == 0)) {
901 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
902 struct sctp_ipv4addr_param *v4addr;
904 v4addr = (struct sctp_ipv4addr_param *)ph;
905 if ((param_type == SCTP_IPV4_ADDRESS) &&
906 (param_length == sizeof(struct sctp_ipv4addr_param)) &&
907 (memcmp(&v4addr->addr, &sin->sin_addr,
908 sizeof(struct in_addr)) == 0)) {
921 * Cleanup for non-responded/OP ERR'd ASCONF
924 sctp_asconf_cleanup(struct sctp_tcb *stcb, struct sctp_nets *net)
927 * clear out any existing asconfs going out
929 sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, net,
930 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_2);
931 stcb->asoc.asconf_seq_out_acked = stcb->asoc.asconf_seq_out;
932 /* remove the old ASCONF on our outbound queue */
933 sctp_toss_old_asconf(stcb);
937 * cleanup any cached source addresses that may be topologically
938 * incorrect after a new address has been added to this interface.
941 sctp_asconf_nets_cleanup(struct sctp_tcb *stcb, struct sctp_ifn *ifn)
943 struct sctp_nets *net;
946 * Ideally, we want to only clear cached routes and source addresses
947 * that are topologically incorrect. But since there is no easy way
948 * to know whether the newly added address on the ifn would cause a
949 * routing change (i.e. a new egress interface would be chosen)
950 * without doing a new routing lookup and source address selection,
951 * we will (for now) just flush any cached route using a different
952 * ifn (and cached source addrs) and let output re-choose them
953 * during the next send on that net.
955 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
957 * clear any cached route (and cached source address) if the
958 * route's interface is NOT the same as the address change.
959 * If it's the same interface, just clear the cached source
962 if (SCTP_ROUTE_HAS_VALID_IFN(&net->ro) &&
964 (SCTP_GET_IF_INDEX_FROM_ROUTE(&net->ro) != ifn->ifn_index))) {
965 /* clear any cached route */
966 RTFREE(net->ro.ro_rt);
967 net->ro.ro_rt = NULL;
969 /* clear any cached source address */
970 if (net->src_addr_selected) {
971 sctp_free_ifa(net->ro._s_addr);
972 net->ro._s_addr = NULL;
973 net->src_addr_selected = 0;
980 sctp_assoc_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *dstnet)
984 if (dstnet->dest_state & SCTP_ADDR_UNCONFIRMED) {
987 if (stcb->asoc.deleted_primary == NULL) {
990 if (!TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
991 SCTPDBG(SCTP_DEBUG_ASCONF1, "assoc_immediate_retrans: Deleted primary is ");
992 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &stcb->asoc.deleted_primary->ro._l_addr.sa);
993 SCTPDBG(SCTP_DEBUG_ASCONF1, "Current Primary is ");
994 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &stcb->asoc.primary_destination->ro._l_addr.sa);
995 sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb,
996 stcb->asoc.deleted_primary,
997 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_3);
998 stcb->asoc.num_send_timers_up--;
999 if (stcb->asoc.num_send_timers_up < 0) {
1000 stcb->asoc.num_send_timers_up = 0;
1002 SCTP_TCB_LOCK_ASSERT(stcb);
1003 error = sctp_t3rxt_timer(stcb->sctp_ep, stcb,
1004 stcb->asoc.deleted_primary);
1006 SCTP_INP_DECR_REF(stcb->sctp_ep);
1009 SCTP_TCB_LOCK_ASSERT(stcb);
1010 #ifdef SCTP_AUDITING_ENABLED
1011 sctp_auditing(4, stcb->sctp_ep, stcb, stcb->asoc.deleted_primary);
1013 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED);
1014 if ((stcb->asoc.num_send_timers_up == 0) &&
1015 (stcb->asoc.sent_queue_cnt > 0)) {
1016 struct sctp_tmit_chunk *chk;
1018 chk = TAILQ_FIRST(&stcb->asoc.sent_queue);
1019 sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep,
1027 sctp_asconf_queue_mgmt(struct sctp_tcb *, struct sctp_ifa *, uint16_t);
1030 sctp_net_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *net)
1032 struct sctp_tmit_chunk *chk;
1034 SCTPDBG(SCTP_DEBUG_ASCONF1, "net_immediate_retrans: RTO is %d\n", net->RTO);
1035 sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, net,
1036 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_4);
1037 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
1038 net->error_count = 0;
1039 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
1040 if (chk->whoTo == net) {
1041 if (chk->sent < SCTP_DATAGRAM_RESEND) {
1042 chk->sent = SCTP_DATAGRAM_RESEND;
1043 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
1044 sctp_flight_size_decrease(chk);
1045 sctp_total_flight_decrease(stcb, chk);
1046 net->marked_retrans++;
1047 stcb->asoc.marked_retrans++;
1051 if (net->marked_retrans) {
1052 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED);
1057 sctp_path_check_and_react(struct sctp_tcb *stcb, struct sctp_ifa *newifa)
1059 struct sctp_nets *net;
1060 int addrnum, changed;
1063 * If number of local valid addresses is 1, the valid address is
1064 * probably newly added address. Several valid addresses in this
1065 * association. A source address may not be changed. Additionally,
1066 * they can be configured on a same interface as "alias" addresses.
1069 addrnum = sctp_local_addr_count(stcb);
1070 SCTPDBG(SCTP_DEBUG_ASCONF1, "p_check_react(): %d local addresses\n",
1073 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1074 /* clear any cached route and source address */
1075 if (net->ro.ro_rt) {
1076 RTFREE(net->ro.ro_rt);
1077 net->ro.ro_rt = NULL;
1079 if (net->src_addr_selected) {
1080 sctp_free_ifa(net->ro._s_addr);
1081 net->ro._s_addr = NULL;
1082 net->src_addr_selected = 0;
1084 /* Retransmit unacknowledged DATA chunks immediately */
1085 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
1086 SCTP_MOBILITY_FASTHANDOFF)) {
1087 sctp_net_immediate_retrans(stcb, net);
1089 /* also, SET PRIMARY is maybe already sent */
1093 /* Multiple local addresses exsist in the association. */
1094 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1095 /* clear any cached route and source address */
1096 if (net->ro.ro_rt) {
1097 RTFREE(net->ro.ro_rt);
1098 net->ro.ro_rt = NULL;
1100 if (net->src_addr_selected) {
1101 sctp_free_ifa(net->ro._s_addr);
1102 net->ro._s_addr = NULL;
1103 net->src_addr_selected = 0;
1106 * Check if the nexthop is corresponding to the new address.
1107 * If the new address is corresponding to the current
1108 * nexthop, the path will be changed. If the new address is
1109 * NOT corresponding to the current nexthop, the path will
1112 SCTP_RTALLOC((sctp_route_t *) & net->ro,
1113 stcb->sctp_ep->def_vrf_id,
1114 stcb->sctp_ep->fibnum);
1115 if (net->ro.ro_rt == NULL)
1119 switch (net->ro._l_addr.sa.sa_family) {
1122 if (sctp_v4src_match_nexthop(newifa, (sctp_route_t *) & net->ro)) {
1129 if (sctp_v6src_match_nexthop(
1130 &newifa->address.sin6, (sctp_route_t *) & net->ro)) {
1139 * if the newly added address does not relate routing
1140 * information, we skip.
1144 /* Retransmit unacknowledged DATA chunks immediately */
1145 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
1146 SCTP_MOBILITY_FASTHANDOFF)) {
1147 sctp_net_immediate_retrans(stcb, net);
1149 /* Send SET PRIMARY for this new address */
1150 if (net == stcb->asoc.primary_destination) {
1151 (void)sctp_asconf_queue_mgmt(stcb, newifa,
1152 SCTP_SET_PRIM_ADDR);
1158 * process an ADD/DELETE IP ack from peer.
1159 * addr: corresponding sctp_ifa to the address being added/deleted.
1160 * type: SCTP_ADD_IP_ADDRESS or SCTP_DEL_IP_ADDRESS.
1161 * flag: 1=success, 0=failure.
1164 sctp_asconf_addr_mgmt_ack(struct sctp_tcb *stcb, struct sctp_ifa *addr, uint32_t flag)
1167 * do the necessary asoc list work- if we get a failure indication,
1168 * leave the address on the assoc's restricted list. If we get a
1169 * success indication, remove the address from the restricted list.
1172 * Note: this will only occur for ADD_IP_ADDRESS, since
1173 * DEL_IP_ADDRESS is never actually added to the list...
1176 /* success case, so remove from the restricted list */
1177 sctp_del_local_addr_restricted(stcb, addr);
1179 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
1180 SCTP_MOBILITY_BASE) ||
1181 sctp_is_mobility_feature_on(stcb->sctp_ep,
1182 SCTP_MOBILITY_FASTHANDOFF)) {
1183 sctp_path_check_and_react(stcb, addr);
1186 /* clear any cached/topologically incorrect source addresses */
1187 sctp_asconf_nets_cleanup(stcb, addr->ifn_p);
1189 /* else, leave it on the list */
1193 * add an asconf add/delete/set primary IP address parameter to the queue.
1194 * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR.
1195 * returns 0 if queued, -1 if not queued/removed.
1196 * NOTE: if adding, but a delete for the same address is already scheduled
1197 * (and not yet sent out), simply remove it from queue. Same for deleting
1198 * an address already scheduled for add. If a duplicate operation is found,
1199 * ignore the new one.
1202 sctp_asconf_queue_mgmt(struct sctp_tcb *stcb, struct sctp_ifa *ifa,
1205 struct sctp_asconf_addr *aa, *aa_next;
1207 /* make sure the request isn't already in the queue */
1208 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) {
1209 /* address match? */
1210 if (sctp_asconf_addr_match(aa, &ifa->address.sa) == 0)
1213 * is the request already in queue but not sent? pass the
1214 * request already sent in order to resolve the following
1215 * case: 1. arrival of ADD, then sent 2. arrival of DEL. we
1216 * can't remove the ADD request already sent 3. arrival of
1219 if (aa->ap.aph.ph.param_type == type && aa->sent == 0) {
1222 /* is the negative request already in queue, and not sent */
1223 if ((aa->sent == 0) && (type == SCTP_ADD_IP_ADDRESS) &&
1224 (aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS)) {
1225 /* add requested, delete already queued */
1226 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1227 /* remove the ifa from the restricted list */
1228 sctp_del_local_addr_restricted(stcb, ifa);
1229 /* free the asconf param */
1230 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1231 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_mgmt: add removes queued entry\n");
1234 if ((aa->sent == 0) && (type == SCTP_DEL_IP_ADDRESS) &&
1235 (aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS)) {
1236 /* delete requested, add already queued */
1237 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1238 /* remove the aa->ifa from the restricted list */
1239 sctp_del_local_addr_restricted(stcb, aa->ifa);
1240 /* free the asconf param */
1241 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1242 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_mgmt: delete removes queued entry\n");
1247 /* adding new request to the queue */
1248 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
1251 /* didn't get memory */
1252 SCTPDBG(SCTP_DEBUG_ASCONF1, "asconf_queue_mgmt: failed to get memory!\n");
1255 aa->special_del = 0;
1256 /* fill in asconf address parameter fields */
1257 /* top level elements are "networked" during send */
1258 aa->ap.aph.ph.param_type = type;
1260 atomic_add_int(&ifa->refcount, 1);
1261 /* correlation_id filled in during send routine later... */
1262 switch (ifa->address.sa.sa_family) {
1266 struct sockaddr_in6 *sin6;
1268 sin6 = &ifa->address.sin6;
1269 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
1270 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param));
1271 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) +
1272 sizeof(struct sctp_ipv6addr_param);
1273 memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr,
1274 sizeof(struct in6_addr));
1281 struct sockaddr_in *sin;
1283 sin = &ifa->address.sin;
1284 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
1285 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param));
1286 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) +
1287 sizeof(struct sctp_ipv4addr_param);
1288 memcpy(&aa->ap.addrp.addr, &sin->sin_addr,
1289 sizeof(struct in_addr));
1294 /* invalid family! */
1295 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1299 aa->sent = 0; /* clear sent flag */
1301 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
1303 if (SCTP_BASE_SYSCTL(sctp_debug_on) & SCTP_DEBUG_ASCONF2) {
1304 if (type == SCTP_ADD_IP_ADDRESS) {
1305 SCTP_PRINTF("asconf_queue_mgmt: inserted asconf ADD_IP_ADDRESS: ");
1306 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa);
1307 } else if (type == SCTP_DEL_IP_ADDRESS) {
1308 SCTP_PRINTF("asconf_queue_mgmt: appended asconf DEL_IP_ADDRESS: ");
1309 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa);
1311 SCTP_PRINTF("asconf_queue_mgmt: appended asconf SET_PRIM_ADDR: ");
1312 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa);
1322 * add an asconf operation for the given ifa and type.
1323 * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR.
1324 * returns 0 if completed, -1 if not completed, 1 if immediate send is
1328 sctp_asconf_queue_add(struct sctp_tcb *stcb, struct sctp_ifa *ifa,
1332 int pending_delete_queued = 0;
1335 /* see if peer supports ASCONF */
1336 if (stcb->asoc.asconf_supported == 0) {
1340 * if this is deleting the last address from the assoc, mark it as
1343 if ((type == SCTP_DEL_IP_ADDRESS) && !stcb->asoc.asconf_del_pending) {
1344 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
1345 last = (sctp_local_addr_count(stcb) == 0);
1347 last = (sctp_local_addr_count(stcb) == 1);
1350 /* set the pending delete info only */
1351 stcb->asoc.asconf_del_pending = 1;
1352 stcb->asoc.asconf_addr_del_pending = ifa;
1353 atomic_add_int(&ifa->refcount, 1);
1354 SCTPDBG(SCTP_DEBUG_ASCONF2,
1355 "asconf_queue_add: mark delete last address pending\n");
1359 /* queue an asconf parameter */
1360 status = sctp_asconf_queue_mgmt(stcb, ifa, type);
1363 * if this is an add, and there is a delete also pending (i.e. the
1364 * last local address is being changed), queue the pending delete
1367 if ((type == SCTP_ADD_IP_ADDRESS) && stcb->asoc.asconf_del_pending && (status == 0)) {
1368 /* queue in the pending delete */
1369 if (sctp_asconf_queue_mgmt(stcb,
1370 stcb->asoc.asconf_addr_del_pending,
1371 SCTP_DEL_IP_ADDRESS) == 0) {
1372 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_add: queing pending delete\n");
1373 pending_delete_queued = 1;
1374 /* clear out the pending delete info */
1375 stcb->asoc.asconf_del_pending = 0;
1376 sctp_free_ifa(stcb->asoc.asconf_addr_del_pending);
1377 stcb->asoc.asconf_addr_del_pending = NULL;
1380 if (pending_delete_queued) {
1381 struct sctp_nets *net;
1384 * since we know that the only/last address is now being
1385 * changed in this case, reset the cwnd/rto on all nets to
1386 * start as a new address and path. Also clear the error
1387 * counts to give the assoc the best chance to complete the
1390 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1391 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb,
1394 net->error_count = 0;
1396 stcb->asoc.overall_error_count = 0;
1397 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) {
1398 sctp_misc_ints(SCTP_THRESHOLD_CLEAR,
1399 stcb->asoc.overall_error_count,
1401 SCTP_FROM_SCTP_ASCONF,
1404 /* queue in an advisory set primary too */
1405 (void)sctp_asconf_queue_mgmt(stcb, ifa, SCTP_SET_PRIM_ADDR);
1406 /* let caller know we should send this out immediately */
1413 * add an asconf delete IP address parameter to the queue by sockaddr and
1414 * possibly with no sctp_ifa available. This is only called by the routine
1415 * that checks the addresses in an INIT-ACK against the current address list.
1416 * returns 0 if completed, non-zero if not completed.
1417 * NOTE: if an add is already scheduled (and not yet sent out), simply
1418 * remove it from queue. If a duplicate operation is found, ignore the
1422 sctp_asconf_queue_sa_delete(struct sctp_tcb *stcb, struct sockaddr *sa)
1424 struct sctp_ifa *ifa;
1425 struct sctp_asconf_addr *aa, *aa_next;
1430 /* see if peer supports ASCONF */
1431 if (stcb->asoc.asconf_supported == 0) {
1434 /* make sure the request isn't already in the queue */
1435 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) {
1436 /* address match? */
1437 if (sctp_asconf_addr_match(aa, sa) == 0)
1439 /* is the request already in queue (sent or not) */
1440 if (aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) {
1443 /* is the negative request already in queue, and not sent */
1446 if (aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS) {
1447 /* add already queued, so remove existing entry */
1448 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1449 sctp_del_local_addr_restricted(stcb, aa->ifa);
1450 /* free the entry */
1451 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1456 /* find any existing ifa-- NOTE ifa CAN be allowed to be NULL */
1457 ifa = sctp_find_ifa_by_addr(sa, stcb->asoc.vrf_id, SCTP_ADDR_NOT_LOCKED);
1459 /* adding new request to the queue */
1460 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
1463 /* didn't get memory */
1464 SCTPDBG(SCTP_DEBUG_ASCONF1,
1465 "sctp_asconf_queue_sa_delete: failed to get memory!\n");
1468 aa->special_del = 0;
1469 /* fill in asconf address parameter fields */
1470 /* top level elements are "networked" during send */
1471 aa->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS;
1474 atomic_add_int(&ifa->refcount, 1);
1475 /* correlation_id filled in during send routine later... */
1476 switch (sa->sa_family) {
1481 struct sockaddr_in6 *sin6;
1483 sin6 = (struct sockaddr_in6 *)sa;
1484 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
1485 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param));
1486 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv6addr_param);
1487 memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr,
1488 sizeof(struct in6_addr));
1496 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
1498 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
1499 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param));
1500 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv4addr_param);
1501 memcpy(&aa->ap.addrp.addr, &sin->sin_addr,
1502 sizeof(struct in_addr));
1507 /* invalid family! */
1508 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1513 aa->sent = 0; /* clear sent flag */
1515 /* delete goes to the back of the queue */
1516 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
1518 /* sa_ignore MEMLEAK {memory is put on the tailq} */
1523 * find a specific asconf param on our "sent" queue
1525 static struct sctp_asconf_addr *
1526 sctp_asconf_find_param(struct sctp_tcb *stcb, uint32_t correlation_id)
1528 struct sctp_asconf_addr *aa;
1530 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
1531 if (aa->ap.aph.correlation_id == correlation_id &&
1537 /* didn't find it */
1542 * process an SCTP_ERROR_CAUSE_IND for a ASCONF-ACK parameter and do
1543 * notifications based on the error response
1546 sctp_asconf_process_error(struct sctp_tcb *stcb SCTP_UNUSED,
1547 struct sctp_asconf_paramhdr *aph)
1549 struct sctp_error_cause *eh;
1550 struct sctp_paramhdr *ph;
1551 uint16_t param_type;
1552 uint16_t error_code;
1554 eh = (struct sctp_error_cause *)(aph + 1);
1555 ph = (struct sctp_paramhdr *)(eh + 1);
1556 /* validate lengths */
1557 if (htons(eh->length) + sizeof(struct sctp_error_cause) >
1558 htons(aph->ph.param_length)) {
1559 /* invalid error cause length */
1560 SCTPDBG(SCTP_DEBUG_ASCONF1,
1561 "asconf_process_error: cause element too long\n");
1564 if (htons(ph->param_length) + sizeof(struct sctp_paramhdr) >
1565 htons(eh->length)) {
1566 /* invalid included TLV length */
1567 SCTPDBG(SCTP_DEBUG_ASCONF1,
1568 "asconf_process_error: included TLV too long\n");
1571 /* which error code ? */
1572 error_code = ntohs(eh->code);
1573 param_type = ntohs(aph->ph.param_type);
1574 /* FIX: this should go back up the REMOTE_ERROR ULP notify */
1575 switch (error_code) {
1576 case SCTP_CAUSE_RESOURCE_SHORTAGE:
1577 /* we allow ourselves to "try again" for this error */
1580 /* peer can't handle it... */
1581 switch (param_type) {
1582 case SCTP_ADD_IP_ADDRESS:
1583 case SCTP_DEL_IP_ADDRESS:
1584 case SCTP_SET_PRIM_ADDR:
1593 * process an asconf queue param.
1594 * aparam: parameter to process, will be removed from the queue.
1595 * flag: 1=success case, 0=failure case
1598 sctp_asconf_process_param_ack(struct sctp_tcb *stcb,
1599 struct sctp_asconf_addr *aparam, uint32_t flag)
1601 uint16_t param_type;
1603 /* process this param */
1604 param_type = aparam->ap.aph.ph.param_type;
1605 switch (param_type) {
1606 case SCTP_ADD_IP_ADDRESS:
1607 SCTPDBG(SCTP_DEBUG_ASCONF1,
1608 "process_param_ack: added IP address\n");
1609 sctp_asconf_addr_mgmt_ack(stcb, aparam->ifa, flag);
1611 case SCTP_DEL_IP_ADDRESS:
1612 SCTPDBG(SCTP_DEBUG_ASCONF1,
1613 "process_param_ack: deleted IP address\n");
1614 /* nothing really to do... lists already updated */
1616 case SCTP_SET_PRIM_ADDR:
1617 SCTPDBG(SCTP_DEBUG_ASCONF1,
1618 "process_param_ack: set primary IP address\n");
1619 /* nothing to do... peer may start using this addr */
1622 /* should NEVER happen */
1626 /* remove the param and free it */
1627 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aparam, next);
1629 sctp_free_ifa(aparam->ifa);
1630 SCTP_FREE(aparam, SCTP_M_ASC_ADDR);
1634 * cleanup from a bad asconf ack parameter
1637 sctp_asconf_ack_clear(struct sctp_tcb *stcb SCTP_UNUSED)
1639 /* assume peer doesn't really know how to do asconfs */
1640 /* XXX we could free the pending queue here */
1645 sctp_handle_asconf_ack(struct mbuf *m, int offset,
1646 struct sctp_asconf_ack_chunk *cp, struct sctp_tcb *stcb,
1647 struct sctp_nets *net, int *abort_no_unlock)
1649 struct sctp_association *asoc;
1650 uint32_t serial_num;
1651 uint16_t ack_length;
1652 struct sctp_asconf_paramhdr *aph;
1653 struct sctp_asconf_addr *aa, *aa_next;
1654 uint32_t last_error_id = 0; /* last error correlation id */
1656 struct sctp_asconf_addr *ap;
1658 /* asconf param buffer */
1659 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE];
1661 /* verify minimum length */
1662 if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_ack_chunk)) {
1663 SCTPDBG(SCTP_DEBUG_ASCONF1,
1664 "handle_asconf_ack: chunk too small = %xh\n",
1665 ntohs(cp->ch.chunk_length));
1669 serial_num = ntohl(cp->serial_number);
1672 * NOTE: we may want to handle this differently- currently, we will
1673 * abort when we get an ack for the expected serial number + 1 (eg.
1674 * we didn't send it), process an ack normally if it is the expected
1675 * serial number, and re-send the previous ack for *ALL* other
1680 * if the serial number is the next expected, but I didn't send it,
1681 * abort the asoc, since someone probably just hijacked us...
1683 if (serial_num == (asoc->asconf_seq_out + 1)) {
1684 struct mbuf *op_err;
1685 char msg[SCTP_DIAG_INFO_LEN];
1687 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got unexpected next serial number! Aborting asoc!\n");
1688 snprintf(msg, sizeof(msg), "Never sent serial number %8.8x",
1690 op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
1691 sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
1692 *abort_no_unlock = 1;
1695 if (serial_num != asoc->asconf_seq_out_acked + 1) {
1696 /* got a duplicate/unexpected ASCONF-ACK */
1697 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got duplicate/unexpected serial number = %xh (expected = %xh)\n",
1698 serial_num, asoc->asconf_seq_out_acked + 1);
1701 if (serial_num == asoc->asconf_seq_out - 1) {
1702 /* stop our timer */
1703 sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, net,
1704 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_5);
1706 /* process the ASCONF-ACK contents */
1707 ack_length = ntohs(cp->ch.chunk_length) -
1708 sizeof(struct sctp_asconf_ack_chunk);
1709 offset += sizeof(struct sctp_asconf_ack_chunk);
1710 /* process through all parameters */
1711 while (ack_length >= sizeof(struct sctp_asconf_paramhdr)) {
1712 unsigned int param_length, param_type;
1714 /* get pointer to next asconf parameter */
1715 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset,
1716 sizeof(struct sctp_asconf_paramhdr), aparam_buf);
1718 /* can't get an asconf paramhdr */
1719 sctp_asconf_ack_clear(stcb);
1722 param_type = ntohs(aph->ph.param_type);
1723 param_length = ntohs(aph->ph.param_length);
1724 if (param_length > ack_length) {
1725 sctp_asconf_ack_clear(stcb);
1728 if (param_length < sizeof(struct sctp_paramhdr)) {
1729 sctp_asconf_ack_clear(stcb);
1732 /* get the complete parameter... */
1733 if (param_length > sizeof(aparam_buf)) {
1734 SCTPDBG(SCTP_DEBUG_ASCONF1,
1735 "param length (%u) larger than buffer size!\n", param_length);
1736 sctp_asconf_ack_clear(stcb);
1739 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf);
1741 sctp_asconf_ack_clear(stcb);
1744 /* correlation_id is transparent to peer, no ntohl needed */
1745 id = aph->correlation_id;
1747 switch (param_type) {
1748 case SCTP_ERROR_CAUSE_IND:
1750 /* find the corresponding asconf param in our queue */
1751 ap = sctp_asconf_find_param(stcb, id);
1753 /* hmm... can't find this in our queue! */
1756 /* process the parameter, failed flag */
1757 sctp_asconf_process_param_ack(stcb, ap, 0);
1758 /* process the error response */
1759 sctp_asconf_process_error(stcb, aph);
1761 case SCTP_SUCCESS_REPORT:
1762 /* find the corresponding asconf param in our queue */
1763 ap = sctp_asconf_find_param(stcb, id);
1765 /* hmm... can't find this in our queue! */
1768 /* process the parameter, success flag */
1769 sctp_asconf_process_param_ack(stcb, ap, 1);
1775 /* update remaining ASCONF-ACK message length to process */
1776 ack_length -= SCTP_SIZE32(param_length);
1777 if (ack_length <= 0) {
1778 /* no more data in the mbuf chain */
1781 offset += SCTP_SIZE32(param_length);
1785 * if there are any "sent" params still on the queue, these are
1786 * implicitly "success", or "failed" (if we got an error back) ...
1787 * so process these appropriately
1789 * we assume that the correlation_id's are monotonically increasing
1790 * beginning from 1 and that we don't have *that* many outstanding
1793 if (last_error_id == 0)
1794 last_error_id--;/* set to "max" value */
1795 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) {
1796 if (aa->sent == 1) {
1798 * implicitly successful or failed if correlation_id
1799 * < last_error_id, then success else, failure
1801 if (aa->ap.aph.correlation_id < last_error_id)
1802 sctp_asconf_process_param_ack(stcb, aa, 1);
1804 sctp_asconf_process_param_ack(stcb, aa, 0);
1807 * since we always process in order (FIFO queue) if
1808 * we reach one that hasn't been sent, the rest
1809 * should not have been sent either. so, we're
1816 /* update the next sequence number to use */
1817 asoc->asconf_seq_out_acked++;
1818 /* remove the old ASCONF on our outbound queue */
1819 sctp_toss_old_asconf(stcb);
1820 if (!TAILQ_EMPTY(&stcb->asoc.asconf_queue)) {
1821 #ifdef SCTP_TIMER_BASED_ASCONF
1822 /* we have more params, so restart our timer */
1823 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep,
1826 /* we have more params, so send out more */
1827 sctp_send_asconf(stcb, net, SCTP_ADDR_NOT_LOCKED);
1834 sctp_is_scopeid_in_nets(struct sctp_tcb *stcb, struct sockaddr *sa)
1836 struct sockaddr_in6 *sin6, *net6;
1837 struct sctp_nets *net;
1839 if (sa->sa_family != AF_INET6) {
1843 sin6 = (struct sockaddr_in6 *)sa;
1844 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) == 0) {
1845 /* not link local address */
1848 /* hunt through our destination nets list for this scope_id */
1849 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1850 if (((struct sockaddr *)(&net->ro._l_addr))->sa_family !=
1853 net6 = (struct sockaddr_in6 *)&net->ro._l_addr;
1854 if (IN6_IS_ADDR_LINKLOCAL(&net6->sin6_addr) == 0)
1856 if (sctp_is_same_scope(sin6, net6)) {
1861 /* didn't find one */
1868 * address management functions
1871 sctp_addr_mgmt_assoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
1872 struct sctp_ifa *ifa, uint16_t type, int addr_locked)
1876 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0 ||
1877 sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_ASCONF)) {
1878 /* subset bound, no ASCONF allowed case, so ignore */
1882 * note: we know this is not the subset bound, no ASCONF case eg.
1883 * this is boundall or subset bound w/ASCONF allowed
1886 /* first, make sure that the address is IPv4 or IPv6 and not jailed */
1887 switch (ifa->address.sa.sa_family) {
1890 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
1891 &ifa->address.sin6.sin6_addr) != 0) {
1898 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
1899 &ifa->address.sin.sin_addr) != 0) {
1908 /* make sure we're "allowed" to add this type of addr */
1909 if (ifa->address.sa.sa_family == AF_INET6) {
1910 /* invalid if we're not a v6 endpoint */
1911 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0)
1913 /* is the v6 addr really valid ? */
1914 if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) {
1919 /* put this address on the "pending/do not use yet" list */
1920 sctp_add_local_addr_restricted(stcb, ifa);
1922 * check address scope if address is out of scope, don't queue
1923 * anything... note: this would leave the address on both inp and
1926 switch (ifa->address.sa.sa_family) {
1930 struct sockaddr_in6 *sin6;
1932 sin6 = &ifa->address.sin6;
1933 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1934 /* we skip unspecifed addresses */
1937 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1938 if (stcb->asoc.scope.local_scope == 0) {
1941 /* is it the right link local scope? */
1942 if (sctp_is_scopeid_in_nets(stcb, &ifa->address.sa) == 0) {
1946 if (stcb->asoc.scope.site_scope == 0 &&
1947 IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)) {
1956 struct sockaddr_in *sin;
1957 struct in6pcb *inp6;
1959 inp6 = (struct in6pcb *)&inp->ip_inp.inp;
1960 /* invalid if we are a v6 only endpoint */
1961 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1962 SCTP_IPV6_V6ONLY(inp6))
1965 sin = &ifa->address.sin;
1966 if (sin->sin_addr.s_addr == 0) {
1967 /* we skip unspecifed addresses */
1970 if (stcb->asoc.scope.ipv4_local_scope == 0 &&
1971 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) {
1978 /* else, not AF_INET or AF_INET6, so skip */
1982 /* queue an asconf for this address add/delete */
1983 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF)) {
1984 /* does the peer do asconf? */
1985 if (stcb->asoc.asconf_supported) {
1986 /* queue an asconf for this addr */
1987 status = sctp_asconf_queue_add(stcb, ifa, type);
1990 * if queued ok, and in the open state, send out the
1991 * ASCONF. If in the non-open state, these will be
1992 * sent when the state goes open.
1995 ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
1996 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED))) {
1997 #ifdef SCTP_TIMER_BASED_ASCONF
1998 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, inp,
1999 stcb, stcb->asoc.primary_destination);
2001 sctp_send_asconf(stcb, NULL, addr_locked);
2010 sctp_asconf_iterator_ep(struct sctp_inpcb *inp, void *ptr, uint32_t val SCTP_UNUSED)
2012 struct sctp_asconf_iterator *asc;
2013 struct sctp_ifa *ifa;
2014 struct sctp_laddr *l;
2015 int cnt_invalid = 0;
2017 asc = (struct sctp_asconf_iterator *)ptr;
2018 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) {
2020 switch (ifa->address.sa.sa_family) {
2023 /* invalid if we're not a v6 endpoint */
2024 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
2026 if (asc->cnt == cnt_invalid)
2034 /* invalid if we are a v6 only endpoint */
2035 struct in6pcb *inp6;
2037 inp6 = (struct in6pcb *)&inp->ip_inp.inp;
2038 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2039 SCTP_IPV6_V6ONLY(inp6)) {
2041 if (asc->cnt == cnt_invalid)
2048 /* invalid address family */
2050 if (asc->cnt == cnt_invalid)
2058 sctp_asconf_iterator_ep_end(struct sctp_inpcb *inp, void *ptr, uint32_t val SCTP_UNUSED)
2060 struct sctp_ifa *ifa;
2061 struct sctp_asconf_iterator *asc;
2062 struct sctp_laddr *laddr, *nladdr, *l;
2064 /* Only for specific case not bound all */
2065 asc = (struct sctp_asconf_iterator *)ptr;
2066 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) {
2068 if (l->action == SCTP_ADD_IP_ADDRESS) {
2069 LIST_FOREACH(laddr, &inp->sctp_addr_list,
2071 if (laddr->ifa == ifa) {
2076 } else if (l->action == SCTP_DEL_IP_ADDRESS) {
2077 LIST_FOREACH_SAFE(laddr, &inp->sctp_addr_list, sctp_nxt_addr, nladdr) {
2078 /* remove only after all guys are done */
2079 if (laddr->ifa == ifa) {
2080 sctp_del_local_addr_ep(inp, ifa);
2089 sctp_asconf_iterator_stcb(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
2090 void *ptr, uint32_t val SCTP_UNUSED)
2092 struct sctp_asconf_iterator *asc;
2093 struct sctp_ifa *ifa;
2094 struct sctp_laddr *l;
2095 int cnt_invalid = 0;
2099 asc = (struct sctp_asconf_iterator *)ptr;
2100 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) {
2104 /* address's vrf_id must be the vrf_id of the assoc */
2105 if (ifa->vrf_id != stcb->asoc.vrf_id) {
2108 /* Same checks again for assoc */
2109 switch (ifa->address.sa.sa_family) {
2113 /* invalid if we're not a v6 endpoint */
2114 struct sockaddr_in6 *sin6;
2116 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
2118 if (asc->cnt == cnt_invalid)
2123 sin6 = &ifa->address.sin6;
2124 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2125 /* we skip unspecifed addresses */
2128 if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
2129 &sin6->sin6_addr) != 0) {
2132 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
2133 if (stcb->asoc.scope.local_scope == 0) {
2136 /* is it the right link local scope? */
2137 if (sctp_is_scopeid_in_nets(stcb, &ifa->address.sa) == 0) {
2147 /* invalid if we are a v6 only endpoint */
2148 struct in6pcb *inp6;
2149 struct sockaddr_in *sin;
2151 inp6 = (struct in6pcb *)&inp->ip_inp.inp;
2152 /* invalid if we are a v6 only endpoint */
2153 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2154 SCTP_IPV6_V6ONLY(inp6))
2157 sin = &ifa->address.sin;
2158 if (sin->sin_addr.s_addr == 0) {
2159 /* we skip unspecifed addresses */
2162 if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
2163 &sin->sin_addr) != 0) {
2166 if (stcb->asoc.scope.ipv4_local_scope == 0 &&
2167 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) {
2170 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2171 SCTP_IPV6_V6ONLY(inp6)) {
2173 if (asc->cnt == cnt_invalid)
2182 /* invalid address family */
2184 if (asc->cnt == cnt_invalid)
2191 if (type == SCTP_ADD_IP_ADDRESS) {
2192 /* prevent this address from being used as a source */
2193 sctp_add_local_addr_restricted(stcb, ifa);
2194 } else if (type == SCTP_DEL_IP_ADDRESS) {
2195 struct sctp_nets *net;
2197 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2200 /* delete this address if cached */
2201 if (net->ro._s_addr == ifa) {
2202 sctp_free_ifa(net->ro._s_addr);
2203 net->ro._s_addr = NULL;
2204 net->src_addr_selected = 0;
2208 net->ro.ro_rt = NULL;
2211 * Now we deleted our src address,
2212 * should we not also now reset the
2213 * cwnd/rto to start as if its a new
2216 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
2221 } else if (type == SCTP_SET_PRIM_ADDR) {
2222 if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
2223 /* must validate the ifa is in the ep */
2224 if (sctp_is_addr_in_ep(stcb->sctp_ep, ifa) == 0) {
2228 /* Need to check scopes for this guy */
2229 if (sctp_is_address_in_scope(ifa, &stcb->asoc.scope, 0) == 0) {
2234 /* queue an asconf for this address add/delete */
2235 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF) &&
2236 stcb->asoc.asconf_supported == 1) {
2237 /* queue an asconf for this addr */
2238 status = sctp_asconf_queue_add(stcb, ifa, type);
2240 * if queued ok, and in the open state, update the
2241 * count of queued params. If in the non-open
2242 * state, these get sent when the assoc goes open.
2244 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
2245 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
2253 * If we have queued params in the open state, send out an ASCONF.
2255 if (num_queued > 0) {
2256 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2261 sctp_asconf_iterator_end(void *ptr, uint32_t val SCTP_UNUSED)
2263 struct sctp_asconf_iterator *asc;
2264 struct sctp_ifa *ifa;
2265 struct sctp_laddr *l, *nl;
2267 asc = (struct sctp_asconf_iterator *)ptr;
2268 LIST_FOREACH_SAFE(l, &asc->list_of_work, sctp_nxt_addr, nl) {
2270 if (l->action == SCTP_ADD_IP_ADDRESS) {
2271 /* Clear the defer use flag */
2272 ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE;
2275 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_laddr), l);
2276 SCTP_DECR_LADDR_COUNT();
2278 SCTP_FREE(asc, SCTP_M_ASC_IT);
2282 * sa is the sockaddr to ask the peer to set primary to.
2283 * returns: 0 = completed, -1 = error
2286 sctp_set_primary_ip_address_sa(struct sctp_tcb *stcb, struct sockaddr *sa)
2289 struct sctp_ifa *ifa;
2291 /* find the ifa for the desired set primary */
2292 vrf_id = stcb->asoc.vrf_id;
2293 ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED);
2295 /* Invalid address */
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_set_primary_ip_address(struct sctp_ifa *ifa)
2327 struct sctp_inpcb *inp;
2329 /* go through all our PCB's */
2330 LIST_FOREACH(inp, &SCTP_BASE_INFO(listhead), sctp_list) {
2331 struct sctp_tcb *stcb;
2333 /* process for all associations for this endpoint */
2334 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
2335 /* queue an ASCONF:SET_PRIM_ADDR to be sent */
2336 if (!sctp_asconf_queue_add(stcb, ifa,
2337 SCTP_SET_PRIM_ADDR)) {
2338 /* set primary queuing succeeded */
2339 SCTPDBG(SCTP_DEBUG_ASCONF1, "set_primary_ip_address: queued on stcb=%p, ",
2341 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &ifa->address.sa);
2342 if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
2343 (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
2344 #ifdef SCTP_TIMER_BASED_ASCONF
2345 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
2346 stcb->sctp_ep, stcb,
2347 stcb->asoc.primary_destination);
2349 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2353 } /* for each stcb */
2354 } /* for each inp */
2358 sctp_is_addr_pending(struct sctp_tcb *stcb, struct sctp_ifa *sctp_ifa)
2360 struct sctp_tmit_chunk *chk, *nchk;
2361 unsigned int offset, asconf_limit;
2362 struct sctp_asconf_chunk *acp;
2363 struct sctp_asconf_paramhdr *aph;
2364 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE];
2365 struct sctp_paramhdr *ph;
2366 int add_cnt, del_cnt;
2367 uint16_t last_param_type;
2369 add_cnt = del_cnt = 0;
2370 last_param_type = 0;
2371 TAILQ_FOREACH_SAFE(chk, &stcb->asoc.asconf_send_queue, sctp_next, nchk) {
2372 if (chk->data == NULL) {
2373 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: No mbuf data?\n");
2377 acp = mtod(chk->data, struct sctp_asconf_chunk *);
2378 offset += sizeof(struct sctp_asconf_chunk);
2379 asconf_limit = ntohs(acp->ch.chunk_length);
2380 ph = (struct sctp_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_paramhdr), aparam_buf);
2382 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: couldn't get lookup addr!\n");
2385 offset += ntohs(ph->param_length);
2387 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_asconf_paramhdr), aparam_buf);
2389 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: Empty ASCONF will be sent?\n");
2392 while (aph != NULL) {
2393 unsigned int param_length, param_type;
2395 param_type = ntohs(aph->ph.param_type);
2396 param_length = ntohs(aph->ph.param_length);
2397 if (offset + param_length > asconf_limit) {
2398 /* parameter goes beyond end of chunk! */
2401 if (param_length > sizeof(aparam_buf)) {
2402 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: param length (%u) larger than buffer size!\n", param_length);
2405 if (param_length <= sizeof(struct sctp_paramhdr)) {
2406 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: param length(%u) too short\n", param_length);
2409 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, param_length, aparam_buf);
2411 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: couldn't get entire param\n");
2414 ph = (struct sctp_paramhdr *)(aph + 1);
2415 if (sctp_addr_match(ph, &sctp_ifa->address.sa) != 0) {
2416 switch (param_type) {
2417 case SCTP_ADD_IP_ADDRESS:
2420 case SCTP_DEL_IP_ADDRESS:
2426 last_param_type = param_type;
2428 offset += SCTP_SIZE32(param_length);
2429 if (offset >= asconf_limit) {
2430 /* no more data in the mbuf chain */
2433 /* get pointer to next asconf param */
2434 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_asconf_paramhdr), aparam_buf);
2439 * we want to find the sequences which consist of ADD -> DEL -> ADD
2442 if (add_cnt > del_cnt ||
2443 (add_cnt == del_cnt && last_param_type == SCTP_ADD_IP_ADDRESS)) {
2449 static struct sockaddr *
2450 sctp_find_valid_localaddr(struct sctp_tcb *stcb, int addr_locked)
2452 struct sctp_vrf *vrf = NULL;
2453 struct sctp_ifn *sctp_ifn;
2454 struct sctp_ifa *sctp_ifa;
2456 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2457 SCTP_IPI_ADDR_RLOCK();
2458 vrf = sctp_find_vrf(stcb->asoc.vrf_id);
2460 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2461 SCTP_IPI_ADDR_RUNLOCK();
2464 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
2465 if (stcb->asoc.scope.loopback_scope == 0 &&
2466 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
2467 /* Skip if loopback_scope not set */
2470 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
2471 switch (sctp_ifa->address.sa.sa_family) {
2474 if (stcb->asoc.scope.ipv4_addr_legal) {
2475 struct sockaddr_in *sin;
2477 sin = &sctp_ifa->address.sin;
2478 if (sin->sin_addr.s_addr == 0) {
2479 /* skip unspecifed addresses */
2482 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
2483 &sin->sin_addr) != 0) {
2486 if (stcb->asoc.scope.ipv4_local_scope == 0 &&
2487 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))
2490 if (sctp_is_addr_restricted(stcb, sctp_ifa) &&
2491 (!sctp_is_addr_pending(stcb, sctp_ifa)))
2494 * found a valid local v4 address to
2497 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2498 SCTP_IPI_ADDR_RUNLOCK();
2499 return (&sctp_ifa->address.sa);
2505 if (stcb->asoc.scope.ipv6_addr_legal) {
2506 struct sockaddr_in6 *sin6;
2508 if (sctp_ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) {
2511 sin6 = &sctp_ifa->address.sin6;
2512 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2514 * we skip unspecifed
2519 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
2520 &sin6->sin6_addr) != 0) {
2523 if (stcb->asoc.scope.local_scope == 0 &&
2524 IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))
2526 if (stcb->asoc.scope.site_scope == 0 &&
2527 IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))
2530 if (sctp_is_addr_restricted(stcb, sctp_ifa) &&
2531 (!sctp_is_addr_pending(stcb, sctp_ifa)))
2534 * found a valid local v6 address to
2537 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2538 SCTP_IPI_ADDR_RUNLOCK();
2539 return (&sctp_ifa->address.sa);
2548 /* no valid addresses found */
2549 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2550 SCTP_IPI_ADDR_RUNLOCK();
2554 static struct sockaddr *
2555 sctp_find_valid_localaddr_ep(struct sctp_tcb *stcb)
2557 struct sctp_laddr *laddr;
2559 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
2560 if (laddr->ifa == NULL) {
2563 /* is the address restricted ? */
2564 if (sctp_is_addr_restricted(stcb, laddr->ifa) &&
2565 (!sctp_is_addr_pending(stcb, laddr->ifa)))
2568 /* found a valid local address to use */
2569 return (&laddr->ifa->address.sa);
2571 /* no valid addresses found */
2576 * builds an ASCONF chunk from queued ASCONF params.
2577 * returns NULL on error (no mbuf, no ASCONF params queued, etc).
2580 sctp_compose_asconf(struct sctp_tcb *stcb, int *retlen, int addr_locked)
2582 struct mbuf *m_asconf, *m_asconf_chk;
2583 struct sctp_asconf_addr *aa;
2584 struct sctp_asconf_chunk *acp;
2585 struct sctp_asconf_paramhdr *aph;
2586 struct sctp_asconf_addr_param *aap;
2588 uint32_t correlation_id = 1; /* 0 is reserved... */
2589 caddr_t ptr, lookup_ptr;
2590 uint8_t lookup_used = 0;
2592 /* are there any asconf params to send? */
2593 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
2601 * get a chunk header mbuf and a cluster for the asconf params since
2602 * it's simpler to fill in the asconf chunk header lookup address on
2605 m_asconf_chk = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_chunk), 0, M_NOWAIT, 1, MT_DATA);
2606 if (m_asconf_chk == NULL) {
2608 SCTPDBG(SCTP_DEBUG_ASCONF1,
2609 "compose_asconf: couldn't get chunk mbuf!\n");
2612 m_asconf = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA);
2613 if (m_asconf == NULL) {
2615 SCTPDBG(SCTP_DEBUG_ASCONF1,
2616 "compose_asconf: couldn't get mbuf!\n");
2617 sctp_m_freem(m_asconf_chk);
2620 SCTP_BUF_LEN(m_asconf_chk) = sizeof(struct sctp_asconf_chunk);
2621 SCTP_BUF_LEN(m_asconf) = 0;
2622 acp = mtod(m_asconf_chk, struct sctp_asconf_chunk *);
2623 bzero(acp, sizeof(struct sctp_asconf_chunk));
2624 /* save pointers to lookup address and asconf params */
2625 lookup_ptr = (caddr_t)(acp + 1); /* after the header */
2626 ptr = mtod(m_asconf, caddr_t); /* beginning of cluster */
2628 /* fill in chunk header info */
2629 acp->ch.chunk_type = SCTP_ASCONF;
2630 acp->ch.chunk_flags = 0;
2631 acp->serial_number = htonl(stcb->asoc.asconf_seq_out);
2632 stcb->asoc.asconf_seq_out++;
2634 /* add parameters... up to smallest MTU allowed */
2635 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
2638 /* get the parameter length */
2639 p_length = SCTP_SIZE32(aa->ap.aph.ph.param_length);
2640 /* will it fit in current chunk? */
2641 if ((SCTP_BUF_LEN(m_asconf) + p_length > stcb->asoc.smallest_mtu) ||
2642 (SCTP_BUF_LEN(m_asconf) + p_length > MCLBYTES)) {
2643 /* won't fit, so we're done with this chunk */
2646 /* assign (and store) a correlation id */
2647 aa->ap.aph.correlation_id = correlation_id++;
2650 * fill in address if we're doing a delete this is a simple
2651 * way for us to fill in the correlation address, which
2652 * should only be used by the peer if we're deleting our
2653 * source address and adding a new address (e.g. renumbering
2656 if (lookup_used == 0 &&
2657 (aa->special_del == 0) &&
2658 aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) {
2659 struct sctp_ipv6addr_param *lookup;
2660 uint16_t p_size, addr_size;
2662 lookup = (struct sctp_ipv6addr_param *)lookup_ptr;
2663 lookup->ph.param_type =
2664 htons(aa->ap.addrp.ph.param_type);
2665 if (aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) {
2666 /* copy IPv6 address */
2667 p_size = sizeof(struct sctp_ipv6addr_param);
2668 addr_size = sizeof(struct in6_addr);
2670 /* copy IPv4 address */
2671 p_size = sizeof(struct sctp_ipv4addr_param);
2672 addr_size = sizeof(struct in_addr);
2674 lookup->ph.param_length = htons(SCTP_SIZE32(p_size));
2675 memcpy(lookup->addr, &aa->ap.addrp.addr, addr_size);
2676 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size);
2679 /* copy into current space */
2680 memcpy(ptr, &aa->ap, p_length);
2682 /* network elements and update lengths */
2683 aph = (struct sctp_asconf_paramhdr *)ptr;
2684 aap = (struct sctp_asconf_addr_param *)ptr;
2685 /* correlation_id is transparent to peer, no htonl needed */
2686 aph->ph.param_type = htons(aph->ph.param_type);
2687 aph->ph.param_length = htons(aph->ph.param_length);
2688 aap->addrp.ph.param_type = htons(aap->addrp.ph.param_type);
2689 aap->addrp.ph.param_length = htons(aap->addrp.ph.param_length);
2691 SCTP_BUF_LEN(m_asconf) += SCTP_SIZE32(p_length);
2692 ptr += SCTP_SIZE32(p_length);
2695 * these params are removed off the pending list upon
2696 * getting an ASCONF-ACK back from the peer, just set flag
2700 /* check to see if the lookup addr has been populated yet */
2701 if (lookup_used == 0) {
2702 /* NOTE: if the address param is optional, can skip this... */
2703 /* add any valid (existing) address... */
2704 struct sctp_ipv6addr_param *lookup;
2705 uint16_t p_size, addr_size;
2706 struct sockaddr *found_addr;
2709 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL)
2710 found_addr = sctp_find_valid_localaddr(stcb,
2713 found_addr = sctp_find_valid_localaddr_ep(stcb);
2715 lookup = (struct sctp_ipv6addr_param *)lookup_ptr;
2716 if (found_addr != NULL) {
2717 switch (found_addr->sa_family) {
2720 /* copy IPv6 address */
2721 lookup->ph.param_type =
2722 htons(SCTP_IPV6_ADDRESS);
2723 p_size = sizeof(struct sctp_ipv6addr_param);
2724 addr_size = sizeof(struct in6_addr);
2725 addr_ptr = (caddr_t)&((struct sockaddr_in6 *)
2726 found_addr)->sin6_addr;
2731 /* copy IPv4 address */
2732 lookup->ph.param_type =
2733 htons(SCTP_IPV4_ADDRESS);
2734 p_size = sizeof(struct sctp_ipv4addr_param);
2735 addr_size = sizeof(struct in_addr);
2736 addr_ptr = (caddr_t)&((struct sockaddr_in *)
2737 found_addr)->sin_addr;
2746 lookup->ph.param_length = htons(SCTP_SIZE32(p_size));
2747 memcpy(lookup->addr, addr_ptr, addr_size);
2748 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size);
2750 /* uh oh... don't have any address?? */
2751 SCTPDBG(SCTP_DEBUG_ASCONF1,
2752 "compose_asconf: no lookup addr!\n");
2753 /* XXX for now, we send a IPv4 address of 0.0.0.0 */
2754 lookup->ph.param_type = htons(SCTP_IPV4_ADDRESS);
2755 lookup->ph.param_length = htons(SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param)));
2756 bzero(lookup->addr, sizeof(struct in_addr));
2757 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param));
2760 /* chain it all together */
2761 SCTP_BUF_NEXT(m_asconf_chk) = m_asconf;
2762 *retlen = SCTP_BUF_LEN(m_asconf_chk) + SCTP_BUF_LEN(m_asconf);
2763 acp->ch.chunk_length = htons(*retlen);
2765 return (m_asconf_chk);
2769 * section to handle address changes before an association is up eg. changes
2770 * during INIT/INIT-ACK/COOKIE-ECHO handshake
2774 * processes the (local) addresses in the INIT-ACK chunk
2777 sctp_process_initack_addresses(struct sctp_tcb *stcb, struct mbuf *m,
2778 unsigned int offset, unsigned int length)
2780 struct sctp_paramhdr tmp_param, *ph;
2781 uint16_t plen, ptype;
2782 struct sctp_ifa *sctp_ifa;
2783 union sctp_sockstore store;
2786 struct sctp_ipv6addr_param addr6_store;
2790 struct sctp_ipv4addr_param addr4_store;
2794 SCTPDBG(SCTP_DEBUG_ASCONF2, "processing init-ack addresses\n");
2795 if (stcb == NULL) /* Un-needed check for SA */
2798 /* convert to upper bound */
2801 if ((offset + sizeof(struct sctp_paramhdr)) > length) {
2804 /* go through the addresses in the init-ack */
2805 ph = (struct sctp_paramhdr *)
2806 sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr),
2807 (uint8_t *) & tmp_param);
2808 while (ph != NULL) {
2809 ptype = ntohs(ph->param_type);
2810 plen = ntohs(ph->param_length);
2813 case SCTP_IPV6_ADDRESS:
2815 struct sctp_ipv6addr_param *a6p;
2817 /* get the entire IPv6 address param */
2818 a6p = (struct sctp_ipv6addr_param *)
2819 sctp_m_getptr(m, offset,
2820 sizeof(struct sctp_ipv6addr_param),
2821 (uint8_t *) & addr6_store);
2822 if (plen != sizeof(struct sctp_ipv6addr_param) ||
2826 memset(&store, 0, sizeof(union sctp_sockstore));
2827 store.sin6.sin6_family = AF_INET6;
2828 store.sin6.sin6_len = sizeof(struct sockaddr_in6);
2829 store.sin6.sin6_port = stcb->rport;
2830 memcpy(&store.sin6.sin6_addr, a6p->addr, sizeof(struct in6_addr));
2835 case SCTP_IPV4_ADDRESS:
2837 struct sctp_ipv4addr_param *a4p;
2839 /* get the entire IPv4 address param */
2840 a4p = (struct sctp_ipv4addr_param *)sctp_m_getptr(m, offset,
2841 sizeof(struct sctp_ipv4addr_param),
2842 (uint8_t *) & addr4_store);
2843 if (plen != sizeof(struct sctp_ipv4addr_param) ||
2847 memset(&store, 0, sizeof(union sctp_sockstore));
2848 store.sin.sin_family = AF_INET;
2849 store.sin.sin_len = sizeof(struct sockaddr_in);
2850 store.sin.sin_port = stcb->rport;
2851 store.sin.sin_addr.s_addr = a4p->addr;
2859 /* see if this address really (still) exists */
2860 sctp_ifa = sctp_find_ifa_by_addr(&store.sa, stcb->asoc.vrf_id,
2861 SCTP_ADDR_NOT_LOCKED);
2862 if (sctp_ifa == NULL) {
2863 /* address doesn't exist anymore */
2866 /* are ASCONFs allowed ? */
2867 if ((sctp_is_feature_on(stcb->sctp_ep,
2868 SCTP_PCB_FLAGS_DO_ASCONF)) &&
2869 stcb->asoc.asconf_supported) {
2870 /* queue an ASCONF DEL_IP_ADDRESS */
2871 status = sctp_asconf_queue_sa_delete(stcb, &store.sa);
2873 * if queued ok, and in correct state, send
2877 SCTP_GET_STATE(&stcb->asoc) ==
2879 #ifdef SCTP_TIMER_BASED_ASCONF
2880 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
2881 stcb->sctp_ep, stcb,
2882 stcb->asoc.primary_destination);
2884 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2891 * Sanity check: Make sure the length isn't 0, otherwise
2892 * we'll be stuck in this loop for a long time...
2894 if (SCTP_SIZE32(plen) == 0) {
2895 SCTP_PRINTF("process_initack_addrs: bad len (%d) type=%xh\n",
2899 /* get next parameter */
2900 offset += SCTP_SIZE32(plen);
2901 if ((offset + sizeof(struct sctp_paramhdr)) > length)
2903 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset,
2904 sizeof(struct sctp_paramhdr), (uint8_t *) & tmp_param);
2908 /* FIX ME: need to verify return result for v6 address type if v6 disabled */
2910 * checks to see if a specific address is in the initack address list returns
2911 * 1 if found, 0 if not
2914 sctp_addr_in_initack(struct mbuf *m, uint32_t offset, uint32_t length, struct sockaddr *sa)
2916 struct sctp_paramhdr tmp_param, *ph;
2917 uint16_t plen, ptype;
2920 struct sockaddr_in *sin;
2921 struct sctp_ipv4addr_param *a4p;
2922 struct sctp_ipv6addr_param addr4_store;
2926 struct sockaddr_in6 *sin6;
2927 struct sctp_ipv6addr_param *a6p;
2928 struct sctp_ipv6addr_param addr6_store;
2929 struct sockaddr_in6 sin6_tmp;
2933 switch (sa->sa_family) {
2946 SCTPDBG(SCTP_DEBUG_ASCONF2, "find_initack_addr: starting search for ");
2947 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, sa);
2948 /* convert to upper bound */
2951 if ((offset + sizeof(struct sctp_paramhdr)) > length) {
2952 SCTPDBG(SCTP_DEBUG_ASCONF1,
2953 "find_initack_addr: invalid offset?\n");
2956 /* go through the addresses in the init-ack */
2957 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset,
2958 sizeof(struct sctp_paramhdr), (uint8_t *) & tmp_param);
2959 while (ph != NULL) {
2960 ptype = ntohs(ph->param_type);
2961 plen = ntohs(ph->param_length);
2964 case SCTP_IPV6_ADDRESS:
2965 if (sa->sa_family == AF_INET6) {
2966 /* get the entire IPv6 address param */
2967 if (plen != sizeof(struct sctp_ipv6addr_param)) {
2970 /* get the entire IPv6 address param */
2971 a6p = (struct sctp_ipv6addr_param *)
2972 sctp_m_getptr(m, offset,
2973 sizeof(struct sctp_ipv6addr_param),
2974 (uint8_t *) & addr6_store);
2978 sin6 = (struct sockaddr_in6 *)sa;
2979 if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr)) {
2980 /* create a copy and clear scope */
2981 memcpy(&sin6_tmp, sin6,
2982 sizeof(struct sockaddr_in6));
2984 in6_clearscope(&sin6->sin6_addr);
2986 if (memcmp(&sin6->sin6_addr, a6p->addr,
2987 sizeof(struct in6_addr)) == 0) {
2995 case SCTP_IPV4_ADDRESS:
2996 if (sa->sa_family == AF_INET) {
2997 if (plen != sizeof(struct sctp_ipv4addr_param)) {
3000 /* get the entire IPv4 address param */
3001 a4p = (struct sctp_ipv4addr_param *)
3002 sctp_m_getptr(m, offset,
3003 sizeof(struct sctp_ipv4addr_param),
3004 (uint8_t *) & addr4_store);
3008 sin = (struct sockaddr_in *)sa;
3009 if (sin->sin_addr.s_addr == a4p->addr) {
3019 /* get next parameter */
3020 offset += SCTP_SIZE32(plen);
3021 if (offset + sizeof(struct sctp_paramhdr) > length) {
3024 ph = (struct sctp_paramhdr *)
3025 sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr),
3026 (uint8_t *) & tmp_param);
3033 * makes sure that the current endpoint local addr list is consistent with
3034 * the new association (eg. subset bound, asconf allowed) adds addresses as
3038 sctp_check_address_list_ep(struct sctp_tcb *stcb, struct mbuf *m, int offset,
3039 int length, struct sockaddr *init_addr)
3041 struct sctp_laddr *laddr;
3043 /* go through the endpoint list */
3044 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
3045 /* be paranoid and validate the laddr */
3046 if (laddr->ifa == NULL) {
3047 SCTPDBG(SCTP_DEBUG_ASCONF1,
3048 "check_addr_list_ep: laddr->ifa is NULL");
3051 if (laddr->ifa == NULL) {
3052 SCTPDBG(SCTP_DEBUG_ASCONF1, "check_addr_list_ep: laddr->ifa->ifa_addr is NULL");
3055 /* do i have it implicitly? */
3056 if (sctp_cmpaddr(&laddr->ifa->address.sa, init_addr)) {
3059 /* check to see if in the init-ack */
3060 if (!sctp_addr_in_initack(m, offset, length, &laddr->ifa->address.sa)) {
3062 sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb, laddr->ifa,
3063 SCTP_ADD_IP_ADDRESS, SCTP_ADDR_NOT_LOCKED);
3069 * makes sure that the current kernel address list is consistent with the new
3070 * association (with all addrs bound) adds addresses as necessary
3073 sctp_check_address_list_all(struct sctp_tcb *stcb, struct mbuf *m, int offset,
3074 int length, struct sockaddr *init_addr,
3075 uint16_t local_scope, uint16_t site_scope,
3076 uint16_t ipv4_scope, uint16_t loopback_scope)
3078 struct sctp_vrf *vrf = NULL;
3079 struct sctp_ifn *sctp_ifn;
3080 struct sctp_ifa *sctp_ifa;
3084 struct sockaddr_in *sin;
3088 struct sockaddr_in6 *sin6;
3093 vrf_id = stcb->asoc.vrf_id;
3097 SCTP_IPI_ADDR_RLOCK();
3098 vrf = sctp_find_vrf(vrf_id);
3100 SCTP_IPI_ADDR_RUNLOCK();
3103 /* go through all our known interfaces */
3104 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
3105 if (loopback_scope == 0 && SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
3106 /* skip loopback interface */
3109 /* go through each interface address */
3110 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
3111 /* do i have it implicitly? */
3112 if (sctp_cmpaddr(&sctp_ifa->address.sa, init_addr)) {
3115 switch (sctp_ifa->address.sa.sa_family) {
3118 sin = &sctp_ifa->address.sin;
3119 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
3120 &sin->sin_addr) != 0) {
3123 if ((ipv4_scope == 0) &&
3124 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
3125 /* private address not in scope */
3132 sin6 = &sctp_ifa->address.sin6;
3133 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
3134 &sin6->sin6_addr) != 0) {
3137 if ((local_scope == 0) &&
3138 (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))) {
3141 if ((site_scope == 0) &&
3142 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
3150 /* check to see if in the init-ack */
3151 if (!sctp_addr_in_initack(m, offset, length, &sctp_ifa->address.sa)) {
3153 sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb,
3154 sctp_ifa, SCTP_ADD_IP_ADDRESS,
3157 } /* end foreach ifa */
3158 } /* end foreach ifn */
3159 SCTP_IPI_ADDR_RUNLOCK();
3163 * validates an init-ack chunk (from a cookie-echo) with current addresses
3164 * adds addresses from the init-ack into our local address list, if needed
3165 * queues asconf adds/deletes addresses as needed and makes appropriate list
3166 * changes for source address selection m, offset: points to the start of the
3167 * address list in an init-ack chunk length: total length of the address
3168 * params only init_addr: address where my INIT-ACK was sent from
3171 sctp_check_address_list(struct sctp_tcb *stcb, struct mbuf *m, int offset,
3172 int length, struct sockaddr *init_addr,
3173 uint16_t local_scope, uint16_t site_scope,
3174 uint16_t ipv4_scope, uint16_t loopback_scope)
3176 /* process the local addresses in the initack */
3177 sctp_process_initack_addresses(stcb, m, offset, length);
3179 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3180 /* bound all case */
3181 sctp_check_address_list_all(stcb, m, offset, length, init_addr,
3182 local_scope, site_scope, ipv4_scope, loopback_scope);
3184 /* subset bound case */
3185 if (sctp_is_feature_on(stcb->sctp_ep,
3186 SCTP_PCB_FLAGS_DO_ASCONF)) {
3187 /* asconf's allowed */
3188 sctp_check_address_list_ep(stcb, m, offset, length,
3191 /* else, no asconfs allowed, so what we sent is what we get */
3196 * sctp_bindx() support
3199 sctp_addr_mgmt_ep_sa(struct sctp_inpcb *inp, struct sockaddr *sa,
3200 uint32_t type, uint32_t vrf_id, struct sctp_ifa *sctp_ifap)
3202 struct sctp_ifa *ifa;
3203 struct sctp_laddr *laddr, *nladdr;
3205 if (sa->sa_len == 0) {
3206 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EINVAL);
3211 } else if (type == SCTP_ADD_IP_ADDRESS) {
3212 /* For an add the address MUST be on the system */
3213 ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED);
3214 } else if (type == SCTP_DEL_IP_ADDRESS) {
3215 /* For a delete we need to find it in the inp */
3216 ifa = sctp_find_ifa_in_ep(inp, sa, SCTP_ADDR_NOT_LOCKED);
3221 if (type == SCTP_ADD_IP_ADDRESS) {
3222 sctp_add_local_addr_ep(inp, ifa, type);
3223 } else if (type == SCTP_DEL_IP_ADDRESS) {
3224 if (inp->laddr_count < 2) {
3225 /* can't delete the last local address */
3226 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EINVAL);
3229 LIST_FOREACH(laddr, &inp->sctp_addr_list,
3231 if (ifa == laddr->ifa) {
3232 /* Mark in the delete */
3233 laddr->action = type;
3237 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
3239 * There is no need to start the iterator if the inp
3240 * has no associations.
3242 if (type == SCTP_DEL_IP_ADDRESS) {
3243 LIST_FOREACH_SAFE(laddr, &inp->sctp_addr_list, sctp_nxt_addr, nladdr) {
3244 if (laddr->ifa == ifa) {
3245 sctp_del_local_addr_ep(inp, ifa);
3250 struct sctp_asconf_iterator *asc;
3251 struct sctp_laddr *wi;
3254 SCTP_MALLOC(asc, struct sctp_asconf_iterator *,
3255 sizeof(struct sctp_asconf_iterator),
3258 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, ENOMEM);
3261 wi = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_laddr), struct sctp_laddr);
3263 SCTP_FREE(asc, SCTP_M_ASC_IT);
3264 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, ENOMEM);
3267 LIST_INIT(&asc->list_of_work);
3269 SCTP_INCR_LADDR_COUNT();
3272 atomic_add_int(&ifa->refcount, 1);
3273 LIST_INSERT_HEAD(&asc->list_of_work, wi, sctp_nxt_addr);
3274 ret = sctp_initiate_iterator(sctp_asconf_iterator_ep,
3275 sctp_asconf_iterator_stcb,
3276 sctp_asconf_iterator_ep_end,
3278 SCTP_PCB_ANY_FEATURES,
3279 SCTP_ASOC_ANY_STATE,
3281 sctp_asconf_iterator_end, inp, 0);
3283 SCTP_PRINTF("Failed to initiate iterator for addr_mgmt_ep_sa\n");
3284 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EFAULT);
3285 sctp_asconf_iterator_end(asc, 0);
3291 /* invalid address! */
3292 SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EADDRNOTAVAIL);
3293 return (EADDRNOTAVAIL);
3298 sctp_asconf_send_nat_state_update(struct sctp_tcb *stcb,
3299 struct sctp_nets *net)
3301 struct sctp_asconf_addr *aa;
3302 struct sctp_ifa *sctp_ifap;
3303 struct sctp_asconf_tag_param *vtag;
3306 struct sockaddr_in *to;
3310 struct sockaddr_in6 *to6;
3314 SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing net\n");
3318 SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing stcb\n");
3322 * Need to have in the asconf: - vtagparam(my_vtag/peer_vtag) -
3323 * add(0.0.0.0) - del(0.0.0.0) - Any global addresses add(addr)
3325 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
3328 /* didn't get memory */
3329 SCTPDBG(SCTP_DEBUG_ASCONF1,
3330 "sctp_asconf_send_nat_state_update: failed to get memory!\n");
3333 aa->special_del = 0;
3334 /* fill in asconf address parameter fields */
3335 /* top level elements are "networked" during send */
3337 aa->sent = 0; /* clear sent flag */
3338 vtag = (struct sctp_asconf_tag_param *)&aa->ap.aph;
3339 vtag->aph.ph.param_type = SCTP_NAT_VTAGS;
3340 vtag->aph.ph.param_length = sizeof(struct sctp_asconf_tag_param);
3341 vtag->local_vtag = htonl(stcb->asoc.my_vtag);
3342 vtag->remote_vtag = htonl(stcb->asoc.peer_vtag);
3343 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
3345 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
3348 /* didn't get memory */
3349 SCTPDBG(SCTP_DEBUG_ASCONF1,
3350 "sctp_asconf_send_nat_state_update: failed to get memory!\n");
3353 memset(aa, 0, sizeof(struct sctp_asconf_addr));
3354 /* fill in asconf address parameter fields */
3356 switch (net->ro._l_addr.sa.sa_family) {
3359 aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
3360 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param);
3361 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
3362 aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv4addr_param);
3363 /* No need to add an address, we are using 0.0.0.0 */
3364 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
3369 aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
3370 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param);
3371 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
3372 aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv6addr_param);
3373 /* No need to add an address, we are using 0.0.0.0 */
3374 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
3378 SCTPDBG(SCTP_DEBUG_ASCONF1,
3379 "sctp_asconf_send_nat_state_update: unknown address family\n");
3380 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
3383 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
3386 /* didn't get memory */
3387 SCTPDBG(SCTP_DEBUG_ASCONF1,
3388 "sctp_asconf_send_nat_state_update: failed to get memory!\n");
3391 memset(aa, 0, sizeof(struct sctp_asconf_addr));
3392 /* fill in asconf address parameter fields */
3394 switch (net->ro._l_addr.sa.sa_family) {
3397 aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
3398 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param);
3399 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
3400 aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv4addr_param);
3401 /* No need to add an address, we are using 0.0.0.0 */
3402 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
3407 aa->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS;
3408 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param);
3409 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
3410 aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv6addr_param);
3411 /* No need to add an address, we are using 0.0.0.0 */
3412 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
3416 SCTPDBG(SCTP_DEBUG_ASCONF1,
3417 "sctp_asconf_send_nat_state_update: unknown address family\n");
3418 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
3421 /* Now we must hunt the addresses and add all global addresses */
3422 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3423 struct sctp_vrf *vrf = NULL;
3424 struct sctp_ifn *sctp_ifnp;
3427 vrf_id = stcb->sctp_ep->def_vrf_id;
3428 vrf = sctp_find_vrf(vrf_id);
3432 SCTP_IPI_ADDR_RLOCK();
3433 LIST_FOREACH(sctp_ifnp, &vrf->ifnlist, next_ifn) {
3434 LIST_FOREACH(sctp_ifap, &sctp_ifnp->ifalist, next_ifa) {
3435 switch (sctp_ifap->address.sa.sa_family) {
3438 to = &sctp_ifap->address.sin;
3439 if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
3440 &to->sin_addr) != 0) {
3443 if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) {
3446 if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) {
3453 to6 = &sctp_ifap->address.sin6;
3454 if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
3455 &to6->sin6_addr) != 0) {
3458 if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) {
3461 if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) {
3469 sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS);
3472 SCTP_IPI_ADDR_RUNLOCK();
3474 struct sctp_laddr *laddr;
3476 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
3477 if (laddr->ifa == NULL) {
3480 if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED)
3482 * Address being deleted by the system, dont
3486 if (laddr->action == SCTP_DEL_IP_ADDRESS) {
3488 * Address being deleted on this ep don't
3493 sctp_ifap = laddr->ifa;
3494 switch (sctp_ifap->address.sa.sa_family) {
3497 to = &sctp_ifap->address.sin;
3498 if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) {
3501 if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) {
3508 to6 = &sctp_ifap->address.sin6;
3509 if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) {
3512 if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) {
3520 sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS);
3524 /* Now we must send the asconf into the queue */
3525 sctp_send_asconf(stcb, net, SCTP_ADDR_NOT_LOCKED);