1 /* $KAME: sctp_asconf.c,v 1.23 2004/08/17 06:28:01 t-momose Exp $ */
4 * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY CISCO SYSTEMS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL CISCO SYSTEMS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #if !(defined(__OpenBSD__) || defined(__APPLE__))
32 #include "opt_ipsec.h"
34 #if defined(__FreeBSD__)
35 #include "opt_compat.h"
36 #include "opt_inet6.h"
39 #if defined(__NetBSD__)
45 #elif !defined(__OpenBSD__)
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/malloc.h>
53 #include <sys/socket.h>
54 #include <sys/socketvar.h>
55 #include <sys/kernel.h>
56 #include <sys/sysctl.h>
57 #include <sys/thread2.h>
60 #include <net/if_types.h>
61 #include <net/route.h>
63 #include <netinet/in.h>
64 #include <netinet/in_systm.h>
65 #include <netinet/ip.h>
66 #include <netinet/in_pcb.h>
67 #include <netinet/in_var.h>
68 #include <netinet/ip_var.h>
71 #include <netinet/ip6.h>
72 #include <netinet6/ip6_var.h>
73 #if defined(__FreeBSD__) || (__NetBSD__)
74 #include <netinet6/in6_pcb.h>
75 #elif defined(__OpenBSD__)
76 #include <netinet/in_pcb.h>
78 #include <netinet/icmp6.h>
79 #include <netinet6/nd6.h>
82 #include <netinet/in_pcb.h>
84 #include <netinet/sctp_var.h>
85 #include <netinet/sctp_pcb.h>
86 #include <netinet/sctp_header.h>
87 #include <netinet/sctputil.h>
88 #include <netinet/sctp_output.h>
89 #include <netinet/sctp_asconf.h>
93 * SCTP_DEBUG_ASCONF1: protocol info, general info and errors
94 * SCTP_DEBUG_ASCONF2: detailed info
97 extern u_int32_t sctp_debug_on;
99 #if defined(SCTP_BASE_FREEBSD) || defined(__APPLE__)
100 #define strlcpy strncpy
102 #endif /* SCTP_DEBUG */
105 * draft-ietf-tsvwg-addip-sctp
107 * Address management only currently supported
108 * For the bound all case:
109 * the asoc local addr list is always a "DO NOT USE" list
110 * For the subset bound case:
111 * If ASCONFs are allowed:
112 * the endpoint local addr list is the usable address list
113 * the asoc local addr list is the "DO NOT USE" list
114 * If ASCONFs are not allowed:
115 * the endpoint local addr list is the default usable list
116 * the asoc local addr list is the usable address list
118 * An ASCONF parameter queue exists per asoc which holds the pending
119 * address operations. Lists are updated upon receipt of ASCONF-ACK.
121 * Deleted addresses are always immediately removed from the lists as
122 * they will (shortly) no longer exist in the kernel. We send ASCONFs
123 * as a courtesy, only if allowed.
127 * ASCONF parameter processing
128 * response_required: set if a reply is required (eg. SUCCESS_REPORT)
129 * returns a mbuf to an "error" response parameter or NULL/"success" if ok
130 * FIX: allocating this many mbufs on the fly is pretty inefficient...
134 sctp_asconf_success_response(uint32_t id)
136 struct mbuf *m_reply = NULL;
137 struct sctp_asconf_paramhdr *aph;
139 MGET(m_reply, MB_DONTWAIT, MT_DATA);
140 if (m_reply == NULL) {
142 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
143 kprintf("asconf_success_response: couldn't get mbuf!\n");
145 #endif /* SCTP_DEBUG */
148 aph = mtod(m_reply, struct sctp_asconf_paramhdr *);
149 aph->correlation_id = id;
150 aph->ph.param_type = htons(SCTP_SUCCESS_REPORT);
151 aph->ph.param_length = sizeof(struct sctp_asconf_paramhdr);
152 m_reply->m_len = aph->ph.param_length;
153 aph->ph.param_length = htons(aph->ph.param_length);
159 sctp_asconf_error_response(uint32_t id, uint16_t cause, uint8_t *error_tlv,
162 struct mbuf *m_reply = NULL;
163 struct sctp_asconf_paramhdr *aph;
164 struct sctp_error_cause *error;
167 MGET(m_reply, MB_DONTWAIT, MT_DATA);
168 if (m_reply == NULL) {
170 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
171 kprintf("asconf_error_response: couldn't get mbuf!\n");
173 #endif /* SCTP_DEBUG */
176 aph = mtod(m_reply, struct sctp_asconf_paramhdr *);
177 error = (struct sctp_error_cause *)(aph + 1);
179 aph->correlation_id = id;
180 aph->ph.param_type = htons(SCTP_ERROR_CAUSE_IND);
181 error->code = htons(cause);
182 error->length = tlv_length + sizeof(struct sctp_error_cause);
183 aph->ph.param_length = error->length +
184 sizeof(struct sctp_asconf_paramhdr);
186 if (aph->ph.param_length > MLEN) {
188 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
189 kprintf("asconf_error_response: tlv_length (%xh) too big\n",
192 #endif /* SCTP_DEBUG */
193 sctp_m_freem(m_reply); /* discard */
197 if (error_tlv != NULL) {
198 tlv = (uint8_t *)(error + 1);
199 memcpy(tlv, error_tlv, tlv_length);
202 m_reply->m_len = aph->ph.param_length;
203 error->length = htons(error->length);
204 aph->ph.param_length = htons(aph->ph.param_length);
210 sctp_process_asconf_add_ip(struct sctp_asconf_paramhdr *aph,
211 struct sctp_tcb *stcb, int response_required)
213 struct mbuf *m_reply = NULL;
214 struct sockaddr_storage sa_store;
215 struct sctp_ipv4addr_param *v4addr;
216 uint16_t param_type, param_length, aparam_length;
218 struct sockaddr_in *sin;
220 struct sockaddr_in6 *sin6;
221 struct sctp_ipv6addr_param *v6addr;
224 aparam_length = ntohs(aph->ph.param_length);
225 v4addr = (struct sctp_ipv4addr_param *)(aph + 1);
227 v6addr = (struct sctp_ipv6addr_param *)(aph + 1);
229 param_type = ntohs(v4addr->ph.param_type);
230 param_length = ntohs(v4addr->ph.param_length);
232 sa = (struct sockaddr *)&sa_store;
233 switch (param_type) {
234 case SCTP_IPV4_ADDRESS:
235 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
236 /* invalid param size */
239 sin = (struct sockaddr_in *)&sa_store;
240 bzero(sin, sizeof(*sin));
241 sin->sin_family = AF_INET;
242 sin->sin_len = sizeof(struct sockaddr_in);
243 sin->sin_port = stcb->rport;
244 sin->sin_addr.s_addr = v4addr->addr;
246 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
247 kprintf("process_asconf_add_ip: adding ");
248 sctp_print_address(sa);
250 #endif /* SCTP_DEBUG */
252 case SCTP_IPV6_ADDRESS:
254 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
255 /* invalid param size */
258 sin6 = (struct sockaddr_in6 *)&sa_store;
259 bzero(sin6, sizeof(*sin6));
260 sin6->sin6_family = AF_INET6;
261 sin6->sin6_len = sizeof(struct sockaddr_in6);
262 sin6->sin6_port = stcb->rport;
263 memcpy((caddr_t)&sin6->sin6_addr, v6addr->addr,
264 sizeof(struct in6_addr));
266 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
267 kprintf("process_asconf_add_ip: adding ");
268 sctp_print_address(sa);
270 #endif /* SCTP_DEBUG */
272 /* IPv6 not enabled! */
273 /* FIX ME: currently sends back an invalid param error */
274 m_reply = sctp_asconf_error_response(aph->correlation_id,
275 SCTP_ERROR_INVALID_PARAM, (uint8_t *)aph, aparam_length);
277 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
278 kprintf("process_asconf_add_ip: v6 disabled- skipping ");
279 sctp_print_address(sa);
281 #endif /* SCTP_DEBUG */
286 m_reply = sctp_asconf_error_response(aph->correlation_id,
287 SCTP_ERROR_UNRESOLVABLE_ADDR, (uint8_t *)aph,
292 /* add the address */
293 if (sctp_add_remote_addr(stcb, sa, 0, 6) != 0) {
295 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
296 kprintf("process_asconf_add_ip: error adding address\n");
298 #endif /* SCTP_DEBUG */
299 m_reply = sctp_asconf_error_response(aph->correlation_id,
300 SCTP_ERROR_RESOURCE_SHORTAGE, (uint8_t *)aph,
303 /* notify upper layer */
304 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_ADD_IP, stcb, 0, sa);
305 if (response_required) {
307 sctp_asconf_success_response(aph->correlation_id);
315 sctp_process_asconf_delete_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph,
316 struct sctp_tcb *stcb, int response_required)
318 struct mbuf *m_reply = NULL;
319 struct sockaddr_storage sa_store, sa_source;
320 struct sctp_ipv4addr_param *v4addr;
321 uint16_t param_type, param_length, aparam_length;
323 struct sockaddr_in *sin;
327 struct sockaddr_in6 *sin6;
328 struct sctp_ipv6addr_param *v6addr;
331 aparam_length = ntohs(aph->ph.param_length);
332 v4addr = (struct sctp_ipv4addr_param *)(aph + 1);
334 v6addr = (struct sctp_ipv6addr_param *)(aph + 1);
336 param_type = ntohs(v4addr->ph.param_type);
337 param_length = ntohs(v4addr->ph.param_length);
339 /* get the source IP address for deletion check */
340 iph = mtod(m, struct ip *);
341 if (iph->ip_v == IPVERSION) {
343 sin = (struct sockaddr_in *)&sa_source;
344 bzero(sin, sizeof(*sin));
345 sin->sin_family = AF_INET;
346 sin->sin_len = sizeof(struct sockaddr_in);
347 sin->sin_port = stcb->rport;
348 sin->sin_addr.s_addr = iph->ip_src.s_addr;
351 else if (iph->ip_v == (IPV6_VERSION >> 4)) {
355 sin6 = (struct sockaddr_in6 *)&sa_source;
356 bzero(sin6, sizeof(*sin6));
357 sin6->sin6_family = AF_INET6;
358 sin6->sin6_len = sizeof(struct sockaddr_in6);
359 sin6->sin6_port = stcb->rport;
360 ip6 = mtod(m, struct ip6_hdr *);
361 sin6->sin6_addr = ip6->ip6_src;
367 sa = (struct sockaddr *)&sa_store;
368 switch (param_type) {
369 case SCTP_IPV4_ADDRESS:
370 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
371 /* invalid param size */
374 sin = (struct sockaddr_in *)&sa_store;
375 bzero(sin, sizeof(*sin));
376 sin->sin_family = AF_INET;
377 sin->sin_len = sizeof(struct sockaddr_in);
378 sin->sin_port = stcb->rport;
379 sin->sin_addr.s_addr = v4addr->addr;
381 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
382 kprintf("process_asconf_delete_ip: deleting ");
383 sctp_print_address(sa);
385 #endif /* SCTP_DEBUG */
387 case SCTP_IPV6_ADDRESS:
388 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
389 /* invalid param size */
393 sin6 = (struct sockaddr_in6 *)&sa_store;
394 bzero(sin6, sizeof(*sin6));
395 sin6->sin6_family = AF_INET6;
396 sin6->sin6_len = sizeof(struct sockaddr_in6);
397 sin6->sin6_port = stcb->rport;
398 memcpy(&sin6->sin6_addr, v6addr->addr,
399 sizeof(struct in6_addr));
401 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
402 kprintf("process_asconf_delete_ip: deleting ");
403 sctp_print_address(sa);
405 #endif /* SCTP_DEBUG */
407 /* IPv6 not enabled! No "action" needed; just ack it */
409 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
410 kprintf("process_asconf_delete_ip: v6 disabled- ignoring: ");
411 sctp_print_address(sa);
413 #endif /* SCTP_DEBUG */
414 /* just respond with a "success" ASCONF-ACK */
419 m_reply = sctp_asconf_error_response(aph->correlation_id,
420 SCTP_ERROR_UNRESOLVABLE_ADDR, (uint8_t *)aph,
425 /* make sure the source address is not being deleted */
426 if ((memcmp(sa, &sa_source, sizeof(struct sockaddr_in)) == 0)
428 || (memcmp(sa, &sa_source, sizeof(struct sockaddr_in6)) == 0)
431 /* trying to delete the source address! */
433 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
434 kprintf("process_asconf_delete_ip: tried to delete source addr\n");
436 #endif /* SCTP_DEBUG */
437 m_reply = sctp_asconf_error_response(aph->correlation_id,
438 SCTP_ERROR_DELETE_SOURCE_ADDR, (uint8_t *)aph,
443 /* delete the address */
444 result = sctp_del_remote_addr(stcb, sa);
446 * note if result == -2, the address doesn't exist in the asoc
447 * but since it's being deleted anyways, we just ack the delete
448 * -- but this probably means something has already gone awry
451 /* only one address in the asoc */
453 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
454 kprintf("process_asconf_delete_ip: tried to delete last IP addr!\n");
456 #endif /* SCTP_DEBUG */
457 m_reply = sctp_asconf_error_response(aph->correlation_id,
458 SCTP_ERROR_DELETE_LAST_ADDR, (uint8_t *)aph,
461 /* notify upper layer */
462 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0, sa);
465 if (response_required) {
466 m_reply = sctp_asconf_success_response(aph->correlation_id);
472 sctp_process_asconf_set_primary(struct sctp_asconf_paramhdr *aph,
473 struct sctp_tcb *stcb, int response_required)
475 struct mbuf *m_reply = NULL;
476 struct sockaddr_storage sa_store;
477 struct sctp_ipv4addr_param *v4addr;
478 uint16_t param_type, param_length, aparam_length;
480 struct sockaddr_in *sin;
482 struct sockaddr_in6 *sin6;
483 struct sctp_ipv6addr_param *v6addr;
486 aparam_length = ntohs(aph->ph.param_length);
487 v4addr = (struct sctp_ipv4addr_param *)(aph + 1);
489 v6addr = (struct sctp_ipv6addr_param *)(aph + 1);
491 param_type = ntohs(v4addr->ph.param_type);
492 param_length = ntohs(v4addr->ph.param_length);
494 sa = (struct sockaddr *)&sa_store;
495 switch (param_type) {
496 case SCTP_IPV4_ADDRESS:
497 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
498 /* invalid param size */
501 sin = (struct sockaddr_in *)&sa_store;
502 bzero(sin, sizeof(*sin));
503 sin->sin_family = AF_INET;
504 sin->sin_len = sizeof(struct sockaddr_in);
505 sin->sin_addr.s_addr = v4addr->addr;
507 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
508 kprintf("process_asconf_set_primary: ");
509 sctp_print_address(sa);
511 #endif /* SCTP_DEBUG */
513 case SCTP_IPV6_ADDRESS:
514 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
515 /* invalid param size */
519 sin6 = (struct sockaddr_in6 *)&sa_store;
520 bzero(sin6, sizeof(*sin6));
521 sin6->sin6_family = AF_INET6;
522 sin6->sin6_len = sizeof(struct sockaddr_in6);
523 memcpy((caddr_t)&sin6->sin6_addr, v6addr->addr,
524 sizeof(struct in6_addr));
526 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
527 kprintf("process_asconf_set_primary: ");
528 sctp_print_address(sa);
530 #endif /* SCTP_DEBUG */
532 /* IPv6 not enabled! No "action" needed; just ack it */
534 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
535 kprintf("process_asconf_set_primary: v6 disabled- ignoring: ");
536 sctp_print_address(sa);
538 #endif /* SCTP_DEBUG */
539 /* just respond with a "success" ASCONF-ACK */
544 m_reply = sctp_asconf_error_response(aph->correlation_id,
545 SCTP_ERROR_UNRESOLVABLE_ADDR, (uint8_t *)aph,
550 /* set the primary address */
551 if (sctp_set_primary_addr(stcb, sa, NULL) == 0) {
553 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
554 kprintf("process_asconf_set_primary: primary address set\n");
556 #endif /* SCTP_DEBUG */
557 /* notify upper layer */
558 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_SET_PRIMARY, stcb, 0, sa);
560 if (response_required) {
561 m_reply = sctp_asconf_success_response(aph->correlation_id);
564 /* couldn't set the requested primary address! */
566 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
567 kprintf("process_asconf_set_primary: set primary failed!\n");
569 #endif /* SCTP_DEBUG */
570 /* must have been an invalid address, so report */
571 m_reply = sctp_asconf_error_response(aph->correlation_id,
572 SCTP_ERROR_UNRESOLVABLE_ADDR, (uint8_t *)aph,
580 * handles an ASCONF chunk
581 * if all parameters are processed ok, send a plain (empty) ASCONF-ACK
584 sctp_handle_asconf(struct mbuf *m, unsigned int offset, struct sctp_asconf_chunk *cp,
585 struct sctp_tcb *stcb, struct sctp_nets *net)
587 struct sctp_association *asoc;
589 struct mbuf *m_ack, *m_result, *m_tail;
590 struct sctp_asconf_ack_chunk *ack_cp;
591 struct sctp_asconf_paramhdr *aph, *ack_aph;
592 struct sctp_ipv6addr_param *p_addr;
593 unsigned int asconf_limit;
594 int error = 0; /* did an error occur? */
595 /* asconf param buffer */
596 static u_int8_t aparam_buf[DEFAULT_PARAM_BUFFER];
598 /* verify minimum length */
599 if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_chunk)) {
601 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
602 kprintf("handle_asconf: chunk too small = %xh\n",
603 ntohs(cp->ch.chunk_length));
605 #endif /* SCTP_DEBUG */
610 serial_num = ntohl(cp->serial_number);
612 if (serial_num == asoc->asconf_seq_in) {
613 /* got a duplicate ASCONF */
615 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
616 kprintf("handle_asconf: got duplicate serial number = %xh\n",
619 #endif /* SCTP_DEBUG */
620 /* resend last ASCONF-ACK... */
621 sctp_send_asconf_ack(stcb, 1);
623 } else if (serial_num != (asoc->asconf_seq_in + 1)) {
625 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
626 kprintf("handle_asconf: incorrect serial number = %xh (expected next = %xh)\n",
627 serial_num, asoc->asconf_seq_in+1);
629 #endif /* SCTP_DEBUG */
633 /* it's the expected "next" sequence number, so process it */
634 asoc->asconf_seq_in = serial_num; /* update sequence */
635 /* get length of all the param's in the ASCONF */
636 asconf_limit = offset + ntohs(cp->ch.chunk_length);
638 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
639 kprintf("handle_asconf: asconf_limit=%u, sequence=%xh\n",
640 asconf_limit, serial_num);
642 #endif /* SCTP_DEBUG */
643 if (asoc->last_asconf_ack_sent != NULL) {
644 /* free last ASCONF-ACK message sent */
645 sctp_m_freem(asoc->last_asconf_ack_sent);
646 asoc->last_asconf_ack_sent = NULL;
648 MGETHDR(m_ack, MB_DONTWAIT, MT_DATA);
651 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
652 kprintf("handle_asconf: couldn't get mbuf!\n");
654 #endif /* SCTP_DEBUG */
657 m_tail = m_ack; /* current reply chain's tail */
659 /* fill in ASCONF-ACK header */
660 ack_cp = mtod(m_ack, struct sctp_asconf_ack_chunk *);
661 ack_cp->ch.chunk_type = SCTP_ASCONF_ACK;
662 ack_cp->ch.chunk_flags = 0;
663 ack_cp->serial_number = htonl(serial_num);
664 /* set initial lengths (eg. just an ASCONF-ACK), ntohx at the end! */
665 m_ack->m_len = sizeof(struct sctp_asconf_ack_chunk);
666 ack_cp->ch.chunk_length = sizeof(struct sctp_asconf_ack_chunk);
667 m_ack->m_pkthdr.len = sizeof(struct sctp_asconf_ack_chunk);
669 /* skip the lookup address parameter */
670 offset += sizeof(struct sctp_asconf_chunk);
671 p_addr = (struct sctp_ipv6addr_param *)sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), (uint8_t *)&aparam_buf);
672 if (p_addr == NULL) {
674 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
675 kprintf("handle_asconf: couldn't get lookup addr!\n");
677 #endif /* SCTP_DEBUG */
679 /* respond with a missing/invalid mandatory parameter error */
682 /* param_length is already validated in process_control... */
683 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);
687 /* get pointer to first asconf param in ASCONF-ACK */
689 kprintf("Gak in asconf\n");
692 ack_aph = (struct sctp_asconf_paramhdr *)(mtod(m_ack, caddr_t) + sizeof(struct sctp_asconf_ack_chunk));
693 if (ack_aph == NULL) {
694 kprintf("Gak in asconf2\n");
698 /* process through all parameters */
699 while (aph != NULL) {
700 unsigned int param_length, param_type;
702 param_type = ntohs(aph->ph.param_type);
703 param_length = ntohs(aph->ph.param_length);
704 if (offset + param_length > asconf_limit) {
705 /* parameter goes beyond end of chunk! */
711 if (param_length > sizeof(aparam_buf)) {
713 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
714 kprintf("handle_asconf: param length (%u) larger than buffer size!\n", param_length);
716 #endif /* SCTP_DEBUG */
720 if (param_length <= sizeof(struct sctp_paramhdr)) {
722 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
723 kprintf("handle_asconf: param length (%u) too short\n", param_length);
725 #endif /* SCTP_DEBUG */
729 /* get the entire parameter */
730 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf);
736 switch (param_type) {
737 case SCTP_ADD_IP_ADDRESS:
738 asoc->peer_supports_asconf = 1;
739 m_result = sctp_process_asconf_add_ip(aph, stcb, error);
741 case SCTP_DEL_IP_ADDRESS:
742 asoc->peer_supports_asconf = 1;
743 m_result = sctp_process_asconf_delete_ip(m, aph, stcb,
746 case SCTP_ERROR_CAUSE_IND:
747 /* not valid in an ASCONF chunk */
749 case SCTP_SET_PRIM_ADDR:
750 asoc->peer_supports_asconf_setprim = 1;
751 m_result = sctp_process_asconf_set_primary(aph, stcb,
754 case SCTP_SUCCESS_REPORT:
755 /* not valid in an ASCONF chunk */
757 case SCTP_ULP_ADAPTION:
761 if ((param_type & 0x8000) == 0) {
762 /* Been told to STOP at this param */
763 asconf_limit = offset;
764 /* FIX FIX - We need to call sctp_arethere_unrecognized_parameters()
765 * to get a operr and send it for any param's with the
766 * 0x4000 bit set OR do it here ourselves... note we still
767 * must STOP if the 0x8000 bit is clear.
770 /* unknown/invalid param type */
774 /* add any (error) result to the reply mbuf chain */
775 if (m_result != NULL) {
777 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
778 kprintf("handle_asconf: adding reply...\n");
780 #endif /* SCTP_DEBUG */
781 m_tail->m_next = m_result;
783 /* update lengths, make sure it's aligned too */
784 m_result->m_len = SCTP_SIZE32(m_result->m_len);
785 m_ack->m_pkthdr.len += m_result->m_len;
786 ack_cp->ch.chunk_length += m_result->m_len;
787 /* set flag to force success reports */
791 offset += SCTP_SIZE32(param_length);
792 /* update remaining ASCONF message length to process */
793 if (offset >= asconf_limit) {
794 /* no more data in the mbuf chain */
797 /* get pointer to next asconf param */
798 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset,
799 sizeof(struct sctp_asconf_paramhdr),
800 (uint8_t *)&aparam_buf);
802 /* can't get an asconf paramhdr */
804 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
805 kprintf("handle_asconf: can't get asconf param hdr!\n");
807 #endif /* SCTP_DEBUG */
808 /* FIX ME - add error here... */
812 ack_cp->ch.chunk_length = htons(ack_cp->ch.chunk_length);
813 /* save the ASCONF-ACK reply */
814 asoc->last_asconf_ack_sent = m_ack;
815 /* and send (a new one) it out... */
816 sctp_send_asconf_ack(stcb, 0);
820 * does the address match?
821 * returns 0 if not, 1 if so
824 sctp_asconf_addr_match(struct sctp_asconf_addr *aa, struct sockaddr *sa)
827 if (sa->sa_family == AF_INET6) {
828 /* IPv6 sa address */
830 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
831 if ((aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) &&
832 (memcmp(&aa->ap.addrp.addr, &sin6->sin6_addr,
833 sizeof(struct in6_addr)) == 0)) {
838 if (sa->sa_family == AF_INET) {
839 /* IPv4 sa address */
840 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
841 if ((aa->ap.addrp.ph.param_type == SCTP_IPV4_ADDRESS) &&
842 (memcmp(&aa->ap.addrp.addr, &sin->sin_addr,
843 sizeof(struct in_addr)) == 0)) {
851 * Cleanup for non-responded/OP ERR'd ASCONF
854 sctp_asconf_cleanup(struct sctp_tcb *stcb, struct sctp_nets *net)
857 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
858 kprintf("asconf_cleanup: marking peer ASCONF incapable and cleaning up\n");
860 #endif /* SCTP_DEBUG */
861 /* mark peer as ASCONF incapable */
862 stcb->asoc.peer_supports_asconf = 0;
863 stcb->asoc.peer_supports_asconf_setprim = 0;
865 * clear out any existing asconfs going out
867 sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, net);
868 stcb->asoc.asconf_seq_out++;
869 /* remove the old ASCONF on our outbound queue */
870 sctp_toss_old_asconf(stcb);
874 * process an ADD/DELETE IP ack from peer
875 * ifa: corresponding ifaddr to the address being added/deleted
876 * type: SCTP_ADD_IP_ADDRESS or SCTP_DEL_IP_ADDRESS
877 * flag: 1=success, 0=failure
880 sctp_asconf_addr_mgmt_ack(struct sctp_tcb *stcb, struct ifaddr *addr,
881 uint16_t type, uint32_t flag)
885 * do the necessary asoc list work-
886 * if we get a failure indication, leave the address on the
887 * "do not use" asoc list
888 * if we get a success indication, remove the address from
892 * Note: this will only occur for ADD_IP_ADDRESS, since
893 * DEL_IP_ADDRESS is never actually added to the list...
896 /* success case, so remove from the list */
897 sctp_del_local_addr_assoc(stcb, addr);
899 /* else, leave it on the list */
903 * add an asconf add/delete IP address parameter to the queue
904 * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR
905 * returns 0 if completed, non-zero if not completed
906 * NOTE: if adding, but delete already scheduled (and not yet
907 * sent out), simply remove from queue. Same for deleting
908 * an address already scheduled for add. If a duplicate
909 * operation is found, ignore the new one.
912 sctp_asconf_queue_add(struct sctp_tcb *stcb, struct ifaddr *ifa, uint16_t type)
914 struct sctp_asconf_addr *aa, *aa_next;
916 char buf[128]; /* for address in string format */
917 #endif /* SCTP_DEBUG */
919 /* see if peer supports ASCONF */
920 if (stcb->asoc.peer_supports_asconf == 0) {
922 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
923 kprintf("asconf_queue_add: peer doesn't support ASCONF\n");
925 #endif /* SCTP_DEBUG */
929 /* make sure the request isn't already in the queue */
930 for (aa=TAILQ_FIRST(&stcb->asoc.asconf_queue); aa!=NULL; aa=aa_next) {
931 aa_next = TAILQ_NEXT(aa, next);
933 if (sctp_asconf_addr_match(aa, ifa->ifa_addr) == 0)
935 /* is the request already in queue (sent or not) */
936 if (aa->ap.aph.ph.param_type == type) {
938 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
939 kprintf("asconf_queue_add: request already exists\n");
941 #endif /* SCTP_DEBUG */
944 /* is the negative request already in queue, and not sent */
946 /* add requested, delete already queued */
947 ((type == SCTP_ADD_IP_ADDRESS &&
948 aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) ||
949 /* delete requested, add already queued */
950 (type == SCTP_DEL_IP_ADDRESS &&
951 aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS))) {
952 /* delete the existing entry in the queue */
953 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
954 /* take the entry off the appropriate list */
955 sctp_asconf_addr_mgmt_ack(stcb, aa->ifa, type, 1);
960 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
961 kprintf("asconf_queue_add: removing 'opposite' queued request\n");
963 #endif /* SCTP_DEBUG */
968 /* adding new request to the queue */
969 aa = kmalloc(sizeof(*aa), M_PCB, M_NOWAIT);
971 /* didn't get memory */
973 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
974 kprintf("asconf_queue_add: failed to get memory!\n");
976 #endif /* SCTP_DEBUG */
979 /* fill in asconf address parameter fields */
980 /* top level elements are "networked" during send */
981 aa->ap.aph.ph.param_type = type;
983 /* correlation_id filled in during send routine later... */
984 if (ifa->ifa_addr->sa_family == AF_INET6) {
986 struct sockaddr_in6 *sin6;
988 sin6 = (struct sockaddr_in6 *)ifa->ifa_addr;
989 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
990 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param));
991 aa->ap.aph.ph.param_length =
992 sizeof(struct sctp_asconf_paramhdr) +
993 sizeof(struct sctp_ipv6addr_param);
994 memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr,
995 sizeof(struct in6_addr));
997 strlcpy(buf, ip6_sprintf(&sin6->sin6_addr), sizeof(buf));
998 #endif /* SCTP_DEBUG */
1000 } else if (ifa->ifa_addr->sa_family == AF_INET) {
1002 struct sockaddr_in *sin = (struct sockaddr_in *)ifa->ifa_addr;
1003 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
1004 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param));
1005 aa->ap.aph.ph.param_length =
1006 sizeof(struct sctp_asconf_paramhdr) +
1007 sizeof(struct sctp_ipv4addr_param);
1008 memcpy(&aa->ap.addrp.addr, &sin->sin_addr,
1009 sizeof(struct in_addr));
1011 strlcpy(buf, inet_ntoa(sin->sin_addr), sizeof(buf));
1012 #endif /* SCTP_DEBUG */
1014 /* invalid family! */
1017 aa->sent = 0; /* clear sent flag */
1020 * if we are deleting an address it should go out last
1021 * otherwise, add it to front of the pending queue
1023 if (type == SCTP_ADD_IP_ADDRESS) {
1024 /* add goes to the front of the queue */
1025 TAILQ_INSERT_HEAD(&stcb->asoc.asconf_queue, aa, next);
1027 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1028 kprintf("asconf_queue_add: appended asconf ADD_IP_ADDRESS: %s\n", buf);
1030 #endif /* SCTP_DEBUG */
1032 /* delete and set primary goes to the back of the queue */
1033 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
1035 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1036 if (type == SCTP_DEL_IP_ADDRESS) {
1037 kprintf("asconf_queue_add: inserted asconf DEL_IP_ADDRESS: %s\n", buf);
1039 kprintf("asconf_queue_add: inserted asconf SET_PRIM_ADDR: %s\n", buf);
1042 #endif /* SCTP_DEBUG */
1049 * add an asconf add/delete IP address parameter to the queue by addr
1050 * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR
1051 * returns 0 if completed, non-zero if not completed
1052 * NOTE: if adding, but delete already scheduled (and not yet
1053 * sent out), simply remove from queue. Same for deleting
1054 * an address already scheduled for add. If a duplicate
1055 * operation is found, ignore the new one.
1058 sctp_asconf_queue_add_sa(struct sctp_tcb *stcb, struct sockaddr *sa,
1061 struct sctp_asconf_addr *aa, *aa_next;
1063 /* see if peer supports ASCONF */
1064 if (stcb->asoc.peer_supports_asconf == 0) {
1066 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1067 kprintf("asconf_queue_add_sa: peer doesn't support ASCONF\n");
1069 #endif /* SCTP_DEBUG */
1073 /* make sure the request isn't already in the queue */
1074 for (aa = TAILQ_FIRST(&stcb->asoc.asconf_queue); aa != NULL;
1076 aa_next = TAILQ_NEXT(aa, next);
1077 /* address match? */
1078 if (sctp_asconf_addr_match(aa, sa) == 0)
1080 /* is the request already in queue (sent or not) */
1081 if (aa->ap.aph.ph.param_type == type) {
1083 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1084 kprintf("asconf_queue_add_sa: request already exists\n");
1086 #endif /* SCTP_DEBUG */
1090 /* is the negative request already in queue, and not sent */
1093 if (type == SCTP_ADD_IP_ADDRESS &&
1094 aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) {
1095 /* add requested, delete already queued */
1097 /* delete the existing entry in the queue */
1098 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1099 /* free the entry */
1102 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1103 kprintf("asconf_queue_add_sa: removing queued delete request\n");
1105 #endif /* SCTP_DEBUG */
1107 } else if (type == SCTP_DEL_IP_ADDRESS &&
1108 aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS) {
1109 /* delete requested, add already queued */
1111 /* delete the existing entry in the queue */
1112 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1113 /* take the entry off the appropriate list */
1114 sctp_asconf_addr_mgmt_ack(stcb, aa->ifa, type, 1);
1115 /* free the entry */
1118 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1119 kprintf("asconf_queue_add_sa: removing queued add request\n");
1121 #endif /* SCTP_DEBUG */
1126 /* adding new request to the queue */
1127 aa = kmalloc(sizeof(*aa), M_PCB, M_NOWAIT);
1129 /* didn't get memory */
1131 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1132 kprintf("asconf_queue_add_sa: failed to get memory!\n");
1134 #endif /* SCTP_DEBUG */
1137 /* fill in asconf address parameter fields */
1138 /* top level elements are "networked" during send */
1139 aa->ap.aph.ph.param_type = type;
1140 aa->ifa = sctp_find_ifa_by_addr(sa);
1141 /* correlation_id filled in during send routine later... */
1142 if (sa->sa_family == AF_INET6) {
1144 struct sockaddr_in6 *sin6;
1146 sin6 = (struct sockaddr_in6 *)sa;
1147 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
1148 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param));
1149 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv6addr_param);
1150 memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr,
1151 sizeof(struct in6_addr));
1152 } else if (sa->sa_family == AF_INET) {
1154 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
1155 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
1156 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param));
1157 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv4addr_param);
1158 memcpy(&aa->ap.addrp.addr, &sin->sin_addr,
1159 sizeof(struct in_addr));
1161 /* invalid family! */
1164 aa->sent = 0; /* clear sent flag */
1167 * if we are deleting an address it should go out last
1168 * otherwise, add it to front of the pending queue
1170 if (type == SCTP_ADD_IP_ADDRESS) {
1171 /* add goes to the front of the queue */
1172 TAILQ_INSERT_HEAD(&stcb->asoc.asconf_queue, aa, next);
1174 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1175 kprintf("asconf_queue_add_sa: appended asconf ADD_IP_ADDRESS\n");
1177 #endif /* SCTP_DEBUG */
1179 /* delete and set primary goes to the back of the queue */
1180 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
1182 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1183 if (type == SCTP_DEL_IP_ADDRESS) {
1184 kprintf("asconf_queue_add_sa: inserted asconf DEL_IP_ADDRESS\n");
1186 kprintf("asconf_queue_add_sa: inserted asconf SET_PRIM_ADDR\n");
1189 #endif /* SCTP_DEBUG */
1196 * find a specific asconf param on our "sent" queue
1198 static struct sctp_asconf_addr *
1199 sctp_asconf_find_param(struct sctp_tcb *stcb, uint32_t correlation_id)
1201 struct sctp_asconf_addr *aa;
1203 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
1204 if (aa->ap.aph.correlation_id == correlation_id &&
1210 /* didn't find it */
1215 * process an SCTP_ERROR_CAUSE_IND for a ASCONF-ACK parameter
1216 * and do notifications based on the error response
1219 sctp_asconf_process_error(struct sctp_tcb *stcb,
1220 struct sctp_asconf_paramhdr *aph)
1222 struct sctp_error_cause *eh;
1223 struct sctp_paramhdr *ph;
1224 uint16_t param_type;
1225 uint16_t error_code;
1227 eh = (struct sctp_error_cause *)(aph + 1);
1228 ph = (struct sctp_paramhdr *)(eh + 1);
1229 /* validate lengths */
1230 if (htons(eh->length) + sizeof(struct sctp_error_cause) >
1231 htons(aph->ph.param_length)) {
1232 /* invalid error cause length */
1234 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1235 kprintf("asconf_process_error: cause element too long\n");
1237 #endif /* SCTP_DEBUG */
1240 if (htons(ph->param_length) + sizeof(struct sctp_paramhdr) >
1241 htons(eh->length)) {
1242 /* invalid included TLV length */
1244 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1245 kprintf("asconf_process_error: included TLV too long\n");
1247 #endif /* SCTP_DEBUG */
1251 /* which error code ? */
1252 error_code = ntohs(eh->code);
1253 param_type = ntohs(aph->ph.param_type);
1254 /* FIX: this should go back up the REMOTE_ERROR ULP notify */
1255 switch (error_code) {
1256 case SCTP_ERROR_RESOURCE_SHORTAGE:
1257 /* we allow ourselves to "try again" for this error */
1260 /* peer can't handle it... */
1261 switch (param_type) {
1262 case SCTP_ADD_IP_ADDRESS:
1263 case SCTP_DEL_IP_ADDRESS:
1264 stcb->asoc.peer_supports_asconf = 0;
1266 case SCTP_SET_PRIM_ADDR:
1267 stcb->asoc.peer_supports_asconf_setprim = 0;
1276 * process an asconf queue param
1277 * aparam: parameter to process, will be removed from the queue
1278 * flag: 1=success, 0=failure
1281 sctp_asconf_process_param_ack(struct sctp_tcb *stcb,
1282 struct sctp_asconf_addr *aparam, uint32_t flag)
1284 uint16_t param_type;
1286 /* process this param */
1287 param_type = aparam->ap.aph.ph.param_type;
1289 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1290 kprintf("process_param_ack: handling asconf parameter type=%xh\n", param_type);
1292 #endif /* SCTP_DEBUG */
1293 switch (param_type) {
1294 case SCTP_ADD_IP_ADDRESS:
1296 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1297 kprintf("process_param_ack: added IP address\n");
1299 #endif /* SCTP_DEBUG */
1300 sctp_asconf_addr_mgmt_ack(stcb, aparam->ifa, param_type, flag);
1302 case SCTP_DEL_IP_ADDRESS:
1304 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1305 kprintf("process_param_ack: deleted IP address\n");
1307 #endif /* SCTP_DEBUG */
1308 /* nothing really to do... lists already updated */
1310 case SCTP_SET_PRIM_ADDR:
1311 /* nothing to do... peer may start using this addr */
1313 stcb->asoc.peer_supports_asconf_setprim = 0;
1316 /* should NEVER happen */
1320 /* remove the param and free it */
1321 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aparam, next);
1322 kfree(aparam, M_PCB);
1326 * cleanup from a bad asconf ack parameter
1329 sctp_asconf_ack_clear(struct sctp_tcb *stcb)
1331 /* assume peer doesn't really know how to do asconfs */
1332 stcb->asoc.peer_supports_asconf = 0;
1333 stcb->asoc.peer_supports_asconf_setprim = 0;
1334 /* XXX we could free the pending queue here */
1338 sctp_handle_asconf_ack(struct mbuf *m, int offset,
1339 struct sctp_asconf_ack_chunk *cp, struct sctp_tcb *stcb,
1340 struct sctp_nets *net)
1342 struct sctp_association *asoc;
1343 uint32_t serial_num;
1344 uint16_t ack_length;
1345 struct sctp_asconf_paramhdr *aph;
1346 struct sctp_asconf_addr *aa, *aa_next;
1347 uint32_t last_error_id = 0; /* last error correlation id */
1349 struct sctp_asconf_addr *ap;
1350 /* asconf param buffer */
1351 static u_int8_t aparam_buf[DEFAULT_PARAM_BUFFER];
1353 /* verify minimum length */
1354 if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_ack_chunk)) {
1356 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1357 kprintf("handle_asconf_ack: chunk too small = %xh\n",
1358 ntohs(cp->ch.chunk_length));
1360 #endif /* SCTP_DEBUG */
1365 serial_num = ntohl(cp->serial_number);
1368 * NOTE: we may want to handle this differently- currently, we
1369 * will abort when we get an ack for the expected serial number + 1
1370 * (eg. we didn't send it), process an ack normally if it is the
1371 * expected serial number, and re-send the previous ack for *ALL*
1372 * other serial numbers
1376 * if the serial number is the next expected, but I didn't send it,
1377 * abort the asoc, since someone probably just hijacked us...
1379 if (serial_num == (asoc->asconf_seq_out + 1)) {
1380 sctp_abort_an_association(stcb->sctp_ep, stcb,
1381 SCTP_ERROR_ILLEGAL_ASCONF_ACK, NULL);
1383 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1384 kprintf("handle_asconf_ack: got unexpected next serial number! Aborting asoc!\n");
1386 #endif /* SCTP_DEBUG */
1390 if (serial_num != asoc->asconf_seq_out) {
1391 /* got a duplicate/unexpected ASCONF-ACK */
1393 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1394 kprintf("handle_asconf_ack: got duplicate/unexpected serial number = %xh (expected = %xh)\n", serial_num, asoc->asconf_seq_out);
1396 #endif /* SCTP_DEBUG */
1399 /* stop our timer */
1400 sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, net);
1402 /* process the ASCONF-ACK contents */
1403 ack_length = ntohs(cp->ch.chunk_length) -
1404 sizeof(struct sctp_asconf_ack_chunk);
1405 offset += sizeof(struct sctp_asconf_ack_chunk);
1406 /* process through all parameters */
1407 while (ack_length >= sizeof(struct sctp_asconf_paramhdr)) {
1408 unsigned int param_length, param_type;
1410 /* get pointer to next asconf parameter */
1411 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset,
1412 sizeof(struct sctp_asconf_paramhdr), aparam_buf);
1414 /* can't get an asconf paramhdr */
1415 sctp_asconf_ack_clear(stcb);
1418 param_type = ntohs(aph->ph.param_type);
1419 param_length = ntohs(aph->ph.param_length);
1420 if (param_length > ack_length) {
1421 sctp_asconf_ack_clear(stcb);
1424 if (param_length < sizeof(struct sctp_paramhdr)) {
1425 sctp_asconf_ack_clear(stcb);
1429 /* get the complete parameter... */
1430 if (param_length > sizeof(aparam_buf)) {
1432 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1433 kprintf("param length (%u) larger than buffer size!\n", param_length);
1435 #endif /* SCTP_DEBUG */
1436 sctp_asconf_ack_clear(stcb);
1439 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf);
1441 sctp_asconf_ack_clear(stcb);
1444 /* correlation_id is transparent to peer, no ntohl needed */
1445 id = aph->correlation_id;
1447 switch (param_type) {
1448 case SCTP_ERROR_CAUSE_IND:
1450 /* find the corresponding asconf param in our queue */
1451 ap = sctp_asconf_find_param(stcb, id);
1453 /* hmm... can't find this in our queue! */
1456 /* process the parameter, failed flag */
1457 sctp_asconf_process_param_ack(stcb, ap, 0);
1458 /* process the error response */
1459 sctp_asconf_process_error(stcb, aph);
1461 case SCTP_SUCCESS_REPORT:
1462 /* find the corresponding asconf param in our queue */
1463 ap = sctp_asconf_find_param(stcb, id);
1465 /* hmm... can't find this in our queue! */
1468 /* process the parameter, success flag */
1469 sctp_asconf_process_param_ack(stcb, ap, 1);
1475 /* update remaining ASCONF-ACK message length to process */
1476 ack_length -= SCTP_SIZE32(param_length);
1477 if (ack_length <= 0) {
1478 /* no more data in the mbuf chain */
1481 offset += SCTP_SIZE32(param_length);
1485 * if there are any "sent" params still on the queue, these are
1486 * implicitly "success", or "failed" (if we got an error back)
1487 * ... so process these appropriately
1489 * we assume that the correlation_id's are monotonically increasing
1490 * beginning from 1 and that we don't have *that* many outstanding
1493 if (last_error_id == 0)
1494 last_error_id--; /* set to "max" value */
1495 for (aa = TAILQ_FIRST(&stcb->asoc.asconf_queue); aa != NULL;
1497 aa_next = TAILQ_NEXT(aa, next);
1498 if (aa->sent == 1) {
1500 * implicitly successful or failed
1501 * if correlation_id < last_error_id, then success
1504 if (aa->ap.aph.correlation_id < last_error_id)
1505 sctp_asconf_process_param_ack(stcb, aa,
1506 SCTP_SUCCESS_REPORT);
1508 sctp_asconf_process_param_ack(stcb, aa,
1509 SCTP_ERROR_CAUSE_IND);
1512 * since we always process in order (FIFO queue)
1513 * if we reach one that hasn't been sent, the
1514 * rest should not have been sent either.
1521 /* update the next sequence number to use */
1522 asoc->asconf_seq_out++;
1523 /* remove the old ASCONF on our outbound queue */
1524 sctp_toss_old_asconf(stcb);
1525 /* clear the sent flag to allow new ASCONFs */
1526 asoc->asconf_sent = 0;
1527 if (!TAILQ_EMPTY(&stcb->asoc.asconf_queue)) {
1528 /* we have more params, so restart our timer */
1529 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep,
1534 /* is this an interface that we care about at all? */
1536 sctp_is_desired_interface_type(struct ifaddr *ifa)
1540 /* check the interface type to see if it's one we care about */
1541 switch (ifa->ifa_ifp->if_type) {
1556 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1557 kprintf("ignoring interface type = %u\n",
1558 ifa->ifa_ifp->if_type);
1560 #endif /* SCTP_DEBUG */
1568 sctp_is_scopeid_in_nets(struct sctp_tcb *stcb, struct sockaddr *sa)
1570 struct sockaddr_in6 *sin6, *net6;
1571 struct sctp_nets *net;
1573 if (sa->sa_family != AF_INET6) {
1578 sin6 = (struct sockaddr_in6 *)sa;
1579 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) == 0) {
1580 /* not link local address */
1584 /* hunt through our destination nets list for this scope_id */
1585 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1586 if (((struct sockaddr *)(&net->ro._l_addr))->sa_family !=
1589 net6 = (struct sockaddr_in6 *)&net->ro._l_addr;
1590 if (IN6_IS_ADDR_LINKLOCAL(&net6->sin6_addr) == 0)
1592 if (sctp_is_same_scope(sin6, net6)) {
1597 /* didn't find one */
1602 * address management functions
1605 sctp_addr_mgmt_assoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
1606 struct ifaddr *ifa, uint16_t type)
1610 char buf[128]; /* for address in string format */
1611 #endif /* SCTP_DEBUG */
1613 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0 &&
1614 (inp->sctp_flags & SCTP_PCB_FLAGS_DO_ASCONF) == 0) {
1615 /* subset bound, no ASCONF allowed case, so ignore */
1620 * note: we know this is not the subset bound, no ASCONF case
1621 * eg. this is boundall or subset bound w/ASCONF allowed
1624 /* first, make sure it's a good address family */
1625 if (ifa->ifa_addr->sa_family != AF_INET6 &&
1626 ifa->ifa_addr->sa_family != AF_INET) {
1630 /* make sure we're "allowed" to add this type of addr */
1631 if (ifa->ifa_addr->sa_family == AF_INET6) {
1632 struct in6_ifaddr *ifa6;
1634 /* invalid if we're not a v6 endpoint */
1635 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0)
1637 /* is the v6 addr really valid ? */
1638 ifa6 = (struct in6_ifaddr *)ifa;
1639 if (IFA6_IS_DEPRECATED(ifa6) ||
1641 (IN6_IFF_DETACHED | IN6_IFF_ANYCAST | IN6_IFF_NOTREADY))) {
1642 /* can't use an invalid address */
1647 /* put this address on the "pending/do not use yet" list */
1649 * Note: we do this primarily for the subset bind case
1650 * We don't have scoping flags at the EP level, so we must
1651 * add link local/site local addresses to the EP, then need
1652 * to "negate" them here. Recall that this routine is only
1653 * called for the subset bound w/ASCONF allowed case.
1657 * do a scope_id check against any link local addresses
1658 * in the destination nets list to see if we should put
1659 * this local address on the pending list or not
1660 * eg. don't put on the list if we have a link local
1661 * destination with the same scope_id
1663 if (type == SCTP_ADD_IP_ADDRESS) {
1664 if (sctp_is_scopeid_in_nets(stcb, ifa->ifa_addr) == 0) {
1665 sctp_add_local_addr_assoc(stcb, ifa);
1667 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1668 kprintf("addr_mgmt_assoc: added to pending list ");
1669 sctp_print_address(ifa->ifa_addr);
1671 #endif /* SCTP_DEBUG */
1675 * check address scope
1676 * if address is out of scope, don't queue anything...
1677 * note: this would leave the address on both inp and asoc lists
1679 if (ifa->ifa_addr->sa_family == AF_INET6) {
1680 struct sockaddr_in6 *sin6;
1682 sin6 = (struct sockaddr_in6 *)ifa->ifa_addr;
1684 strlcpy(buf, ip6_sprintf(&sin6->sin6_addr), sizeof(buf));
1685 #endif /* SCTP_DEBUG */
1686 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1687 /* we skip unspecifed addresses */
1689 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1690 kprintf("addr_mgmt_assoc: unspecified IPv6 addr\n");
1692 #endif /* SCTP_DEBUG */
1695 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1696 if (stcb->asoc.local_scope == 0) {
1698 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1699 kprintf("addr_mgmt_assoc: skipping link local IPv6 addr: %s\n", buf);
1701 #endif /* SCTP_DEBUG */
1704 /* is it the right link local scope? */
1705 if (sctp_is_scopeid_in_nets(stcb, ifa->ifa_addr) == 0) {
1707 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1708 kprintf("addr_mgmt_assoc: skipping link local IPv6 addr: %s, wrong scope_id\n", buf);
1710 #endif /* SCTP_DEBUG */
1714 if (stcb->asoc.site_scope == 0 &&
1715 IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)) {
1717 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1718 kprintf("addr_mgmt_assoc: skipping site local IPv6 addr: %s\n", buf);
1720 #endif /* SCTP_DEBUG */
1723 } else if (ifa->ifa_addr->sa_family == AF_INET) {
1724 struct sockaddr_in *sin;
1725 struct in6pcb *inp6;
1727 inp6 = (struct in6pcb *)&inp->ip_inp.inp;
1728 /* invalid if we are a v6 only endpoint */
1729 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1730 #if defined(__OpenBSD__)
1731 (0) /* we always do dual bind */
1732 #elif defined (__NetBSD__)
1733 (inp6->in6p_flags & IN6P_IPV6_V6ONLY)
1735 (inp6->inp_flags & IN6P_IPV6_V6ONLY)
1740 sin = (struct sockaddr_in *)ifa->ifa_addr;
1742 strlcpy(buf, inet_ntoa(sin->sin_addr), sizeof(buf));
1743 #endif /* SCTP_DEBUG */
1744 if (sin->sin_addr.s_addr == 0) {
1745 /* we skip unspecifed addresses */
1747 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1748 kprintf("addr_mgmt_assoc: unspecified IPv4 addr\n");
1750 #endif /* SCTP_DEBUG */
1753 if (stcb->asoc.ipv4_local_scope == 0 &&
1754 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) {
1756 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1757 kprintf("addr_mgmt_assoc: skipping private IPv4 addr: %s\n", buf);
1759 #endif /* SCTP_DEBUG */
1763 /* else, not AF_INET or AF_INET6, so skip */
1765 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1766 kprintf("addr_mgmt_assoc: not AF_INET or AF_INET6\n");
1768 #endif /* SCTP_DEBUG */
1772 /* queue an asconf for this address add/delete */
1773 if (inp->sctp_flags & SCTP_PCB_FLAGS_DO_ASCONF) {
1774 /* does the peer do asconf? */
1775 if (stcb->asoc.peer_supports_asconf) {
1776 /* queue an asconf for this addr */
1777 status = sctp_asconf_queue_add(stcb, ifa, type);
1779 * if queued ok, and in correct state, set the
1781 * if in non-open state, we will set this timer
1782 * when the state does go open and do all the
1786 SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) {
1787 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, inp,
1788 stcb, stcb->asoc.primary_destination);
1792 /* this is the boundall, no ASCONF case */
1793 #if 0 /* assume kernel will delete this very shortly; add done above */
1794 if (type == SCTP_DEL_IP_ADDRESS) {
1795 /* if deleting, add this addr to the do not use list */
1796 sctp_add_local_addr_assoc(stcb, ifa);
1803 sctp_addr_mgmt_ep(struct sctp_inpcb *inp, struct ifaddr *ifa, uint16_t type)
1805 struct sctp_tcb *stcb;
1807 SCTP_INP_WLOCK(inp);
1808 /* make sure we're "allowed" to add this type of addr */
1809 if (ifa->ifa_addr->sa_family == AF_INET6) {
1810 struct in6_ifaddr *ifa6;
1812 /* invalid if we're not a v6 endpoint */
1813 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
1814 SCTP_INP_WUNLOCK(inp);
1817 /* is the v6 addr really valid ? */
1818 ifa6 = (struct in6_ifaddr *)ifa;
1819 if (IFA6_IS_DEPRECATED(ifa6) ||
1821 (IN6_IFF_DETACHED | IN6_IFF_ANYCAST | IN6_IFF_NOTREADY))) {
1822 /* can't use an invalid address */
1823 SCTP_INP_WUNLOCK(inp);
1826 } else if (ifa->ifa_addr->sa_family == AF_INET) {
1827 /* invalid if we are a v6 only endpoint */
1828 struct in6pcb *inp6;
1829 inp6 = (struct in6pcb *)&inp->ip_inp.inp;
1831 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1832 #if defined(__OpenBSD__)
1833 (0) /* we always do dual bind */
1834 #elif defined (__NetBSD__)
1835 (inp6->in6p_flags & IN6P_IPV6_V6ONLY)
1837 (inp6->inp_flags & IN6P_IPV6_V6ONLY)
1840 SCTP_INP_WUNLOCK(inp);
1844 /* invalid address family */
1845 SCTP_INP_WUNLOCK(inp);
1848 /* is this endpoint subset bound ? */
1849 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
1850 /* subset bound endpoint */
1851 if ((inp->sctp_flags & SCTP_PCB_FLAGS_DO_ASCONF) == 0) {
1853 * subset bound, but ASCONFs not allowed...
1854 * if adding, nothing to do, since not allowed
1855 * if deleting, remove address from endpoint
1856 * peer will have to "timeout" this addr
1858 if (type == SCTP_DEL_IP_ADDRESS) {
1859 sctp_del_local_addr_ep(inp, ifa);
1861 /* no asconfs to queue for this inp... */
1862 SCTP_INP_WUNLOCK(inp);
1866 * subset bound, ASCONFs allowed...
1867 * if adding, add address to endpoint list
1868 * if deleting, remove address from endpoint
1870 if (type == SCTP_ADD_IP_ADDRESS) {
1871 sctp_add_local_addr_ep(inp, ifa);
1873 sctp_del_local_addr_ep(inp, ifa);
1875 /* drop through and notify all asocs */
1880 /* process for all associations for this endpoint */
1881 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1882 SCTP_TCB_LOCK(stcb);
1883 sctp_addr_mgmt_assoc(inp, stcb, ifa, type);
1884 SCTP_TCB_UNLOCK(stcb);
1885 } /* for each stcb */
1887 SCTP_INP_WUNLOCK(inp);
1891 * restrict the use of this address
1894 sctp_addr_mgmt_restrict_ep(struct sctp_inpcb *inp, struct ifaddr *ifa)
1896 struct sctp_tcb *stcb;
1898 /* is this endpoint bound to all? */
1899 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
1901 * Nothing to do for subset bound case.
1902 * Allow sctp_bindx() to manage the address lists
1908 SCTP_INP_RLOCK(inp);
1909 /* process for all associations for this endpoint */
1910 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1911 /* put this address on the "pending/do not use yet" list */
1912 SCTP_TCB_LOCK(stcb);
1913 sctp_add_local_addr_assoc(stcb, ifa);
1914 SCTP_TCB_UNLOCK(stcb);
1916 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1917 kprintf("restrict_ep: added addr to unusable list\n");
1919 #endif /* SCTP_DEBUG */
1920 } /* for each stcb */
1922 SCTP_INP_RUNLOCK(inp);
1926 * this is only called for kernel initiated address changes
1927 * eg. it will check the PCB_FLAGS_AUTO_ASCONF flag
1930 sctp_addr_mgmt(struct ifaddr *ifa, uint16_t type) {
1931 struct sockaddr *sa;
1932 struct sctp_inpcb *inp;
1934 /* make sure we care about this interface... */
1935 if (!sctp_is_desired_interface_type(ifa)) {
1937 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1938 kprintf("sctp_addr_mgmt: ignoring this interface\n");
1940 #endif /* SCTP_DEBUG */
1945 if (sa->sa_family != AF_INET && sa->sa_family != AF_INET6)
1949 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1950 if (type == SCTP_ADD_IP_ADDRESS)
1951 kprintf("sctp_addr_mgmt: kernel adds ");
1953 kprintf("sctp_addr_mgmt: kernel deletes ");
1954 sctp_print_address(sa);
1956 #endif /* SCTP_DEBUG */
1958 /* go through all our PCB's */
1959 LIST_FOREACH(inp, &sctppcbinfo.listhead, sctp_list) {
1960 if (inp->sctp_flags & SCTP_PCB_FLAGS_AUTO_ASCONF) {
1961 sctp_addr_mgmt_ep(inp, ifa, type);
1963 /* this address is going away anyways... */
1964 if (type == SCTP_DEL_IP_ADDRESS)
1966 /* (temporarily) restrict this address */
1967 sctp_addr_mgmt_restrict_ep(inp, ifa);
1969 /* else, not allowing automatic asconf's, so ignore */
1970 } /* for each inp */
1974 * add/delete IP address requests from kernel (via routing change)
1975 * assumed that the address is non-broadcast, non-multicast
1976 * all addresses are passed from any type of interface-- need to filter
1977 * duplicate addresses may get requested
1981 sctp_add_ip_address(struct ifaddr *ifa)
1983 sctp_addr_mgmt(ifa, SCTP_ADD_IP_ADDRESS);
1987 sctp_delete_ip_address(struct ifaddr *ifa)
1989 struct sctp_inpcb *inp;
1991 /* process the delete */
1992 sctp_addr_mgmt(ifa, SCTP_DEL_IP_ADDRESS);
1995 * need to remove this ifaddr from any cached routes
1996 * and also any from any assoc "restricted/pending" lists
1998 /* make sure we care about this interface... */
1999 if (!sctp_is_desired_interface_type(ifa)) {
2001 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
2002 kprintf("sctp_delete_ip_address: ignoring this interface\n");
2004 #endif /* SCTP_DEBUG */
2008 /* go through all our PCB's */
2009 SCTP_INP_INFO_RLOCK();
2010 LIST_FOREACH(inp, &sctppcbinfo.listhead, sctp_list) {
2011 struct sctp_tcb *stcb;
2012 struct sctp_laddr *laddr, *laddr_next;
2014 /* process for all associations for this endpoint */
2015 SCTP_INP_RLOCK(inp);
2016 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
2017 struct sctp_nets *net;
2019 /* process through the nets list */
2020 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2022 /* delete this address if cached */
2024 if (rt != NULL && rt->rt_ifa == ifa) {
2026 net->ro.ro_rt = NULL;
2028 } /* for each net */
2029 /* process through the asoc "pending" list */
2030 laddr = LIST_FIRST(&stcb->asoc.sctp_local_addr_list);
2031 while (laddr != NULL) {
2032 laddr_next = LIST_NEXT(laddr, sctp_nxt_addr);
2033 /* remove if in use */
2034 if (laddr->ifa == ifa) {
2035 sctp_remove_laddr(laddr);
2039 } /* for each stcb */
2040 /* process through the inp bound addr list */
2041 laddr = LIST_FIRST(&inp->sctp_addr_list);
2042 while (laddr != NULL) {
2043 laddr_next = LIST_NEXT(laddr, sctp_nxt_addr);
2044 /* remove if in use */
2045 if (laddr->ifa == ifa) {
2046 sctp_remove_laddr(laddr);
2050 SCTP_INP_RUNLOCK(inp);
2051 } /* for each inp */
2052 SCTP_INP_INFO_RUNLOCK();
2056 * sa is the sockaddr to ask the peer to set primary to
2057 * returns: 0 = completed, -1 = error
2060 sctp_set_primary_ip_address_sa(struct sctp_tcb *stcb, struct sockaddr *sa)
2062 /* NOTE: we currently don't check the validity of the address! */
2064 /* queue an ASCONF:SET_PRIM_ADDR to be sent */
2065 if (!sctp_asconf_queue_add_sa(stcb, sa, SCTP_SET_PRIM_ADDR)) {
2066 /* set primary queuing succeeded */
2067 if (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) {
2068 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
2069 stcb->sctp_ep, stcb,
2070 stcb->asoc.primary_destination);
2073 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
2074 kprintf("set_primary_ip_address_sa: queued on tcb=%p, ",
2076 sctp_print_address(sa);
2078 #endif /* SCTP_DEBUG */
2081 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
2082 kprintf("set_primary_ip_address_sa: failed to add to queue on tcb=%p, ",
2084 sctp_print_address(sa);
2086 #endif /* SCTP_DEBUG */
2093 sctp_set_primary_ip_address(struct ifaddr *ifa)
2095 struct sctp_inpcb *inp;
2097 /* make sure we care about this interface... */
2098 if (!sctp_is_desired_interface_type(ifa)) {
2100 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
2101 kprintf("set_primary_ip_address: ignoring this interface\n");
2103 #endif /* SCTP_DEBUG */
2107 /* go through all our PCB's */
2108 LIST_FOREACH(inp, &sctppcbinfo.listhead, sctp_list) {
2109 struct sctp_tcb *stcb;
2111 /* process for all associations for this endpoint */
2112 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
2113 /* queue an ASCONF:SET_PRIM_ADDR to be sent */
2114 if (!sctp_asconf_queue_add(stcb, ifa,
2115 SCTP_SET_PRIM_ADDR)) {
2116 /* set primary queuing succeeded */
2117 if (SCTP_GET_STATE(&stcb->asoc) ==
2119 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
2120 stcb->sctp_ep, stcb,
2121 stcb->asoc.primary_destination);
2124 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
2125 kprintf("set_primary_ip_address: queued on stcb=%p, ",
2127 sctp_print_address(ifa->ifa_addr);
2129 #endif /* SCTP_DEBUG */
2132 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
2133 kprintf("set_primary_ip_address: failed to add to queue, ");
2134 sctp_print_address(ifa->ifa_addr);
2136 #endif /* SCTP_DEBUG */
2138 } /* for each stcb */
2139 } /* for each inp */
2142 static struct sockaddr *
2143 sctp_find_valid_localaddr(struct sctp_tcb *stcb)
2147 TAILQ_FOREACH(ifn, &ifnet, if_list) {
2148 struct ifaddr_container *ifac;
2150 if (stcb->asoc.loopback_scope == 0 && ifn->if_type == IFT_LOOP) {
2151 /* Skip if loopback_scope not set */
2154 TAILQ_FOREACH(ifac, &ifn->if_addrheads[mycpuid], ifa_link) {
2155 struct ifaddr *ifa = ifac->ifa;
2157 if (ifa->ifa_addr->sa_family == AF_INET &&
2158 stcb->asoc.ipv4_addr_legal) {
2159 struct sockaddr_in *sin;
2161 sin = (struct sockaddr_in *)ifa->ifa_addr;
2162 if (sin->sin_addr.s_addr == 0) {
2163 /* skip unspecifed addresses */
2166 if (stcb->asoc.ipv4_local_scope == 0 &&
2167 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))
2170 if (sctp_is_addr_restricted(stcb,
2173 /* found a valid local v4 address to use */
2174 return (ifa->ifa_addr);
2175 } else if (ifa->ifa_addr->sa_family == AF_INET6 &&
2176 stcb->asoc.ipv6_addr_legal) {
2177 struct sockaddr_in6 *sin6;
2178 struct in6_ifaddr *ifa6;
2180 ifa6 = (struct in6_ifaddr *)ifa;
2181 if (IFA6_IS_DEPRECATED(ifa6) ||
2182 (ifa6->ia6_flags & (IN6_IFF_DETACHED |
2183 IN6_IFF_ANYCAST | IN6_IFF_NOTREADY)))
2186 sin6 = (struct sockaddr_in6 *)ifa->ifa_addr;
2187 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2188 /* we skip unspecifed addresses */
2191 if (stcb->asoc.local_scope == 0 &&
2192 IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))
2194 if (stcb->asoc.site_scope == 0 &&
2195 IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))
2198 /* found a valid local v6 address to use */
2199 return (ifa->ifa_addr);
2203 /* no valid addresses found */
2207 static struct sockaddr *
2208 sctp_find_valid_localaddr_ep(struct sctp_tcb *stcb)
2210 struct sctp_laddr *laddr;
2212 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
2213 if (laddr->ifa == NULL) {
2215 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
2216 kprintf("find_valid_localaddr_ep: laddr error\n");
2218 #endif /* SCTP_DEBUG */
2221 if (laddr->ifa->ifa_addr == NULL) {
2223 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
2224 kprintf("find_valid_localaddr_ep: laddr->ifa error\n");
2226 #endif /* SCTP_DEBUG */
2229 /* is the address restricted ? */
2230 if (sctp_is_addr_restricted(stcb, laddr->ifa->ifa_addr))
2233 /* found a valid local address to use */
2234 return (laddr->ifa->ifa_addr);
2236 /* no valid addresses found */
2241 * builds an ASCONF chunk from queued ASCONF params
2242 * returns NULL on error (no mbuf, no ASCONF params queued, etc)
2245 sctp_compose_asconf(struct sctp_tcb *stcb)
2247 struct mbuf *m_asconf, *m_asconf_chk;
2248 struct sctp_asconf_addr *aa;
2249 struct sctp_asconf_chunk *acp;
2250 struct sctp_asconf_paramhdr *aph;
2251 struct sctp_asconf_addr_param *aap;
2253 uint32_t correlation_id = 1; /* 0 is reserved... */
2254 caddr_t ptr, lookup_ptr;
2255 uint8_t lookup_used = 0;
2257 /* are there any asconf params to send? */
2258 if (TAILQ_EMPTY(&stcb->asoc.asconf_queue)) {
2263 * get a chunk header mbuf and a cluster for the asconf params
2264 * since it's simpler to fill in the asconf chunk header lookup
2265 * address on the fly
2267 m_asconf_chk = NULL;
2268 MGETHDR(m_asconf_chk, MB_DONTWAIT, MT_DATA);
2269 if (m_asconf_chk == NULL) {
2272 if (sctp_debug_on & SCTP_DEBUG_ASCONF1)
2273 kprintf("compose_asconf: couldn't get chunk mbuf!\n");
2274 #endif /* SCTP_DEBUG */
2278 MGETHDR(m_asconf, MB_DONTWAIT, MT_HEADER);
2279 if (m_asconf == NULL) {
2282 if (sctp_debug_on & SCTP_DEBUG_ASCONF1)
2283 kprintf("compose_asconf: couldn't get mbuf!\n");
2284 #endif /* SCTP_DEBUG */
2285 sctp_m_freem(m_asconf_chk);
2288 MCLGET(m_asconf, MB_DONTWAIT);
2289 if ((m_asconf->m_flags & M_EXT) != M_EXT) {
2290 /* failed to get cluster buffer */
2292 if (sctp_debug_on & SCTP_DEBUG_ASCONF1)
2293 kprintf("compose_asconf: couldn't get cluster!\n");
2294 #endif /* SCTP_DEBUG */
2295 sctp_m_freem(m_asconf_chk);
2296 sctp_m_freem(m_asconf);
2300 m_asconf_chk->m_len = sizeof(struct sctp_asconf_chunk);
2301 m_asconf->m_len = 0;
2302 acp = mtod(m_asconf_chk, struct sctp_asconf_chunk *);
2303 bzero(acp, sizeof(struct sctp_asconf_chunk));
2304 /* save pointers to lookup address and asconf params */
2305 lookup_ptr = (caddr_t)(acp + 1); /* after the header */
2306 ptr = mtod(m_asconf, caddr_t); /* beginning of cluster */
2308 /* fill in chunk header info */
2309 acp->ch.chunk_type = SCTP_ASCONF;
2310 acp->ch.chunk_flags = 0;
2311 acp->serial_number = htonl(stcb->asoc.asconf_seq_out);
2313 /* add parameters... up to smallest MTU allowed */
2314 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
2315 /* get the parameter length */
2316 p_length = SCTP_SIZE32(aa->ap.aph.ph.param_length);
2317 /* will it fit in current chunk? */
2318 if (m_asconf->m_len + p_length > stcb->asoc.smallest_mtu) {
2319 /* won't fit, so we're done with this chunk */
2322 /* assign (and store) a correlation id */
2323 aa->ap.aph.correlation_id = correlation_id++;
2326 * fill in address if we're doing a delete
2327 * this is a simple way for us to fill in the correlation
2328 * address, which should only be used by the peer if we're
2329 * deleting our source address and adding a new address
2330 * (e.g. renumbering case)
2332 if (lookup_used == 0 &&
2333 aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) {
2334 struct sctp_ipv6addr_param *lookup;
2335 uint16_t p_size, addr_size;
2337 lookup = (struct sctp_ipv6addr_param *)lookup_ptr;
2338 lookup->ph.param_type =
2339 htons(aa->ap.addrp.ph.param_type);
2340 if (aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) {
2341 /* copy IPv6 address */
2342 p_size = sizeof(struct sctp_ipv6addr_param);
2343 addr_size = sizeof(struct in6_addr);
2345 /* copy IPv4 address */
2346 p_size = sizeof(struct sctp_ipv4addr_param);
2347 addr_size = sizeof(struct in_addr);
2349 lookup->ph.param_length = htons(SCTP_SIZE32(p_size));
2350 memcpy(lookup->addr, &aa->ap.addrp.addr, addr_size);
2351 m_asconf_chk->m_len += SCTP_SIZE32(p_size);
2355 /* copy into current space */
2356 memcpy(ptr, &aa->ap, p_length);
2358 /* network elements and update lengths */
2359 aph = (struct sctp_asconf_paramhdr *) ptr;
2360 aap = (struct sctp_asconf_addr_param *) ptr;
2361 /* correlation_id is transparent to peer, no htonl needed */
2362 aph->ph.param_type = htons(aph->ph.param_type);
2363 aph->ph.param_length = htons(aph->ph.param_length);
2364 aap->addrp.ph.param_type = htons(aap->addrp.ph.param_type);
2365 aap->addrp.ph.param_length = htons(aap->addrp.ph.param_length);
2367 m_asconf->m_len += SCTP_SIZE32(p_length);
2368 ptr += SCTP_SIZE32(p_length);
2371 * these params are removed off the pending list upon
2372 * getting an ASCONF-ACK back from the peer, just set flag
2376 /* check to see if the lookup addr has been populated yet */
2377 if (lookup_used == 0) {
2378 /* NOTE: if the address param is optional, can skip this... */
2379 /* add any valid (existing) address... */
2380 struct sctp_ipv6addr_param *lookup;
2381 uint16_t p_size, addr_size;
2382 struct sockaddr *found_addr;
2385 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL)
2386 found_addr = sctp_find_valid_localaddr(stcb);
2388 found_addr = sctp_find_valid_localaddr_ep(stcb);
2390 lookup = (struct sctp_ipv6addr_param *)lookup_ptr;
2391 if (found_addr != NULL) {
2392 if (found_addr->sa_family == AF_INET6) {
2393 /* copy IPv6 address */
2394 lookup->ph.param_type =
2395 htons(SCTP_IPV6_ADDRESS);
2396 p_size = sizeof(struct sctp_ipv6addr_param);
2397 addr_size = sizeof(struct in6_addr);
2398 addr_ptr = (caddr_t)&((struct sockaddr_in6 *)
2399 found_addr)->sin6_addr;
2401 /* copy IPv4 address */
2402 lookup->ph.param_type =
2403 htons(SCTP_IPV4_ADDRESS);
2404 p_size = sizeof(struct sctp_ipv4addr_param);
2405 addr_size = sizeof(struct in_addr);
2406 addr_ptr = (caddr_t)&((struct sockaddr_in *)
2407 found_addr)->sin_addr;
2409 lookup->ph.param_length = htons(SCTP_SIZE32(p_size));
2410 memcpy(lookup->addr, addr_ptr, addr_size);
2411 m_asconf_chk->m_len += SCTP_SIZE32(p_size);
2414 /* uh oh... don't have any address?? */
2416 if (sctp_debug_on & SCTP_DEBUG_ASCONF1)
2417 kprintf("compose_asconf: no lookup addr!\n");
2418 #endif /* SCTP_DEBUG */
2419 /* for now, we send a IPv4 address of 0.0.0.0 */
2420 lookup->ph.param_type = htons(SCTP_IPV4_ADDRESS);
2421 lookup->ph.param_length = htons(SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param)));
2422 bzero(lookup->addr, sizeof(struct in_addr));
2423 m_asconf_chk->m_len += SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param));
2428 /* chain it all together */
2429 m_asconf_chk->m_next = m_asconf;
2430 m_asconf_chk->m_pkthdr.len = m_asconf_chk->m_len + m_asconf->m_len;
2431 acp->ch.chunk_length = ntohs(m_asconf_chk->m_pkthdr.len);
2433 /* update "sent" flag */
2434 stcb->asoc.asconf_sent++;
2436 return (m_asconf_chk);
2440 * section to handle address changes before an association is up
2441 * eg. changes during INIT/INIT-ACK/COOKIE-ECHO handshake
2445 * processes the (local) addresses in the INIT-ACK chunk
2448 sctp_process_initack_addresses(struct sctp_tcb *stcb, struct mbuf *m,
2449 unsigned int offset, unsigned int length)
2451 struct sctp_paramhdr tmp_param, *ph;
2452 uint16_t plen, ptype;
2453 struct sctp_ipv6addr_param addr_store;
2454 struct sockaddr_in6 sin6;
2455 struct sockaddr_in sin;
2456 struct sockaddr *sa;
2460 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) {
2461 kprintf("processing init-ack addresses\n");
2463 #endif /* SCTP_DEBUG */
2465 /* convert to upper bound */
2468 if ((offset + sizeof(struct sctp_paramhdr)) > length) {
2470 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
2471 kprintf("process_initack_addrs: invalid offset?\n");
2473 #endif /* SCTP_DEBUG */
2477 /* init the addresses */
2478 bzero(&sin6, sizeof(sin6));
2479 sin6.sin6_family = AF_INET6;
2480 sin6.sin6_len = sizeof(sin6);
2481 sin6.sin6_port = stcb->rport;
2483 bzero(&sin, sizeof(sin));
2484 sin.sin_len = sizeof(sin);
2485 sin.sin_family = AF_INET;
2486 sin.sin_port = stcb->rport;
2488 /* go through the addresses in the init-ack */
2489 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset,
2490 sizeof(struct sctp_paramhdr), (uint8_t *)&tmp_param);
2491 while (ph != NULL) {
2492 ptype = ntohs(ph->param_type);
2493 plen = ntohs(ph->param_length);
2494 if (ptype == SCTP_IPV6_ADDRESS) {
2495 struct sctp_ipv6addr_param *a6p;
2496 /* get the entire IPv6 address param */
2498 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) {
2499 kprintf("process_initack_addrs: checking IPv6 param\n");
2501 #endif /* SCTP_DEBUG */
2502 a6p = (struct sctp_ipv6addr_param *)
2503 sctp_m_getptr(m, offset,
2504 sizeof(struct sctp_ipv6addr_param),
2505 (uint8_t *)&addr_store);
2506 if (plen != sizeof(struct sctp_ipv6addr_param) ||
2509 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
2510 kprintf("process_initack_addrs: invalid IPv6 param length\n");
2512 #endif /* SCTP_DEBUG */
2515 memcpy(&sin6.sin6_addr, a6p->addr,
2516 sizeof(struct in6_addr));
2517 sa = (struct sockaddr *)&sin6;
2518 } else if (ptype == SCTP_IPV4_ADDRESS) {
2519 struct sctp_ipv4addr_param *a4p;
2520 /* get the entire IPv4 address param */
2522 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) {
2523 kprintf("process_initack_addrs: checking IPv4 param\n");
2525 #endif /* SCTP_DEBUG */
2526 a4p = (struct sctp_ipv4addr_param *)sctp_m_getptr(m, offset, sizeof(struct sctp_ipv4addr_param), (uint8_t *)&addr_store);
2527 if (plen != sizeof(struct sctp_ipv4addr_param) ||
2530 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
2531 kprintf("process_initack_addrs: invalid IPv4 param length\n");
2533 #endif /* SCTP_DEBUG */
2536 sin.sin_addr.s_addr = a4p->addr;
2537 sa = (struct sockaddr *)&sin;
2540 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) {
2541 kprintf("process_initack_addrs: skipping param type=%xh\n", ptype);
2543 #endif /* SCTP_DEBUG */
2547 /* see if this address really (still) exists */
2548 ifa = sctp_find_ifa_by_addr(sa);
2550 /* address doesn't exist anymore */
2552 /* are ASCONFs allowed ? */
2553 if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_DO_ASCONF) &&
2554 stcb->asoc.peer_supports_asconf) {
2555 /* queue an ASCONF DEL_IP_ADDRESS */
2556 status = sctp_asconf_queue_add_sa(stcb, sa,
2557 SCTP_DEL_IP_ADDRESS);
2559 * if queued ok, and in correct state,
2560 * set the ASCONF timer
2563 SCTP_GET_STATE(&stcb->asoc) ==
2565 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
2566 stcb->sctp_ep, stcb,
2567 stcb->asoc.primary_destination);
2571 /* address still exists */
2573 * if subset bound, ep addr's managed by default
2574 * if not doing ASCONF, add the address to the assoc
2576 if ((stcb->sctp_ep->sctp_flags &
2577 SCTP_PCB_FLAGS_BOUNDALL) == 0 &&
2578 (stcb->sctp_ep->sctp_flags &
2579 SCTP_PCB_FLAGS_DO_ASCONF) == 0) {
2581 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) {
2582 kprintf("process_initack_addrs: adding local addr to asoc\n");
2584 #endif /* SCTP_DEBUG */
2585 sctp_add_local_addr_assoc(stcb, ifa);
2590 /* get next parameter */
2591 offset += SCTP_SIZE32(plen);
2592 if ((offset + sizeof(struct sctp_paramhdr)) > length)
2594 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset,
2595 sizeof(struct sctp_paramhdr), (uint8_t *)&tmp_param);
2599 /* FIX ME: need to verify return result for v6 address type if v6 disabled */
2601 * checks to see if a specific address is in the initack address list
2602 * returns 1 if found, 0 if not
2605 sctp_addr_in_initack(struct sctp_tcb *stcb, struct mbuf *m, unsigned int offset,
2606 unsigned int length, struct sockaddr *sa)
2608 struct sctp_paramhdr tmp_param, *ph;
2609 uint16_t plen, ptype;
2610 struct sctp_ipv6addr_param addr_store;
2611 struct sockaddr_in *sin;
2612 struct sctp_ipv4addr_param *a4p;
2614 struct sockaddr_in6 *sin6, sin6_tmp;
2615 struct sctp_ipv6addr_param *a6p;
2620 (sa->sa_family != AF_INET6) &&
2622 (sa->sa_family != AF_INET))
2626 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) {
2627 kprintf("find_initack_addr: starting search for ");
2628 sctp_print_address(sa);
2630 #endif /* SCTP_DEBUG */
2631 /* convert to upper bound */
2634 if ((offset + sizeof(struct sctp_paramhdr)) > length) {
2636 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
2637 kprintf("find_initack_addr: invalid offset?\n");
2639 #endif /* SCTP_DEBUG */
2643 /* go through the addresses in the init-ack */
2644 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset,
2645 sizeof(struct sctp_paramhdr), (uint8_t *)&tmp_param);
2646 while (ph != NULL) {
2647 ptype = ntohs(ph->param_type);
2648 plen = ntohs(ph->param_length);
2650 if (ptype == SCTP_IPV6_ADDRESS && sa->sa_family == AF_INET6) {
2651 /* get the entire IPv6 address param */
2653 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) {
2654 kprintf("addr_in_initack: checking IPv6 param\n");
2656 #endif /* SCTP_DEBUG */
2657 a6p = (struct sctp_ipv6addr_param *)
2658 sctp_m_getptr(m, offset,
2659 sizeof(struct sctp_ipv6addr_param),
2660 (uint8_t *)&addr_store);
2661 if (plen != sizeof(struct sctp_ipv6addr_param) ||
2664 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) {
2665 kprintf("addr_in_initack: invalid IPv6 param length\n");
2667 #endif /* SCTP_DEBUG */
2670 sin6 = (struct sockaddr_in6 *)sa;
2671 if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr)) {
2672 /* create a copy and clear scope */
2673 memcpy(&sin6_tmp, sin6,
2674 sizeof(struct sockaddr_in6));
2676 in6_clearscope(&sin6->sin6_addr);
2678 if (memcmp(&sin6->sin6_addr, a6p->addr,
2679 sizeof(struct in6_addr)) == 0) {
2682 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) {
2683 kprintf("addr_in_initack: found IPv6 addr\n");
2685 #endif /* SCTP_DEBUG */
2691 if (ptype == SCTP_IPV4_ADDRESS &&
2692 sa->sa_family == AF_INET) {
2693 /* get the entire IPv4 address param */
2695 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) {
2696 kprintf("addr_in_initack: checking IPv4 param\n");
2698 #endif /* SCTP_DEBUG */
2699 a4p = (struct sctp_ipv4addr_param *)sctp_m_getptr(m,
2700 offset, sizeof(struct sctp_ipv4addr_param),
2701 (uint8_t *)&addr_store);
2702 if (plen != sizeof(struct sctp_ipv4addr_param) ||
2705 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) {
2706 kprintf("addr_in_initack: invalid IPv4 param length\n");
2708 #endif /* SCTP_DEBUG */
2711 sin = (struct sockaddr_in *)sa;
2712 if (sin->sin_addr.s_addr == a4p->addr) {
2715 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) {
2716 kprintf("addr_in_initack: found IPv4 addr\n");
2718 #endif /* SCTP_DEBUG */
2723 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) {
2724 kprintf("addr_in_initack: skipping param type=%xh\n", ptype);
2726 #endif /* SCTP_DEBUG */
2728 /* get next parameter */
2729 offset += SCTP_SIZE32(plen);
2730 if (offset + sizeof(struct sctp_paramhdr) > length)
2732 ph = (struct sctp_paramhdr *)
2733 sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr),
2734 (uint8_t *)&tmp_param);
2738 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
2739 kprintf("addr_in_initack: not found!\n");
2741 #endif /* SCTP_DEBUG */
2746 * makes sure that the current endpoint local addr list is consistent
2747 * with the new association (eg. subset bound, asconf allowed)
2748 * adds addresses as necessary
2751 sctp_check_address_list_ep(struct sctp_tcb *stcb, struct mbuf *m, int offset,
2752 int length, struct sockaddr *init_addr)
2754 struct sctp_laddr *laddr;
2756 /* go through the endpoint list */
2757 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
2758 /* be paranoid and validate the laddr */
2759 if (laddr->ifa == NULL) {
2761 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
2762 kprintf("check_addr_list_ep: laddr->ifa is NULL");
2767 if (laddr->ifa->ifa_addr == NULL) {
2769 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
2770 kprintf("check_addr_list_ep: laddr->ifa->ifa_addr is NULL");
2775 /* do i have it implicitly? */
2776 if (sctp_cmpaddr(laddr->ifa->ifa_addr, init_addr)) {
2778 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) {
2779 kprintf("check_address_list_all: skipping ");
2780 sctp_print_address(laddr->ifa->ifa_addr);
2782 #endif /* SCTP_DEBUG */
2785 /* check to see if in the init-ack */
2786 if (!sctp_addr_in_initack(stcb, m, offset, length,
2787 laddr->ifa->ifa_addr)) {
2789 sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb, laddr->ifa,
2790 SCTP_ADD_IP_ADDRESS);
2796 * makes sure that the current kernel address list is consistent
2797 * with the new association (with all addrs bound)
2798 * adds addresses as necessary
2801 sctp_check_address_list_all(struct sctp_tcb *stcb, struct mbuf *m, int offset,
2802 int length, struct sockaddr *init_addr, uint16_t local_scope,
2803 uint16_t site_scope, uint16_t ipv4_scope, uint16_t loopback_scope)
2807 /* go through all our known interfaces */
2808 TAILQ_FOREACH(ifn, &ifnet, if_list) {
2809 struct ifaddr_container *ifac;
2811 if (loopback_scope == 0 && ifn->if_type == IFT_LOOP) {
2812 /* skip loopback interface */
2816 /* go through each interface address */
2817 TAILQ_FOREACH(ifac, &ifn->if_addrheads[mycpuid], ifa_link) {
2818 struct ifaddr *ifa = ifac->ifa;
2820 /* do i have it implicitly? */
2821 if (sctp_cmpaddr(ifa->ifa_addr, init_addr)) {
2823 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) {
2824 kprintf("check_address_list_all: "
2826 sctp_print_address(ifa->ifa_addr);
2828 #endif /* SCTP_DEBUG */
2831 /* check to see if in the init-ack */
2832 if (!sctp_addr_in_initack(stcb, m, offset, length,
2835 sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb,
2836 ifa, SCTP_ADD_IP_ADDRESS);
2838 } /* end foreach ifa */
2839 } /* end foreach ifn */
2843 * validates an init-ack chunk (from a cookie-echo) with current addresses
2844 * adds addresses from the init-ack into our local address list, if needed
2845 * queues asconf adds/deletes addresses as needed and makes appropriate
2846 * list changes for source address selection
2847 * m, offset: points to the start of the address list in an init-ack chunk
2848 * length: total length of the address params only
2849 * init_addr: address where my INIT-ACK was sent from
2852 sctp_check_address_list(struct sctp_tcb *stcb, struct mbuf *m, int offset,
2853 int length, struct sockaddr *init_addr, uint16_t local_scope,
2854 uint16_t site_scope, uint16_t ipv4_scope, uint16_t loopback_scope)
2857 /* process the local addresses in the initack */
2858 sctp_process_initack_addresses(stcb, m, offset, length);
2860 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
2861 /* bound all case */
2862 sctp_check_address_list_all(stcb, m, offset, length, init_addr,
2863 local_scope, site_scope, ipv4_scope, loopback_scope);
2865 /* subset bound case */
2866 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_DO_ASCONF) {
2867 /* asconf's allowed */
2868 sctp_check_address_list_ep(stcb, m, offset, length,
2871 /* else, no asconfs allowed, so what we sent is what we get */
2876 * sctp_bindx() support
2879 sctp_addr_mgmt_ep_sa(struct sctp_inpcb *inp, struct sockaddr *sa, uint16_t type)
2883 if (sa->sa_len == 0)
2886 ifa = sctp_find_ifa_by_addr(sa);
2889 if (ifa->ifa_addr->sa_family == AF_INET6) {
2890 struct in6_ifaddr *ifa6;
2891 ifa6 = (struct in6_ifaddr *)ifa;
2892 if (IFA6_IS_DEPRECATED(ifa6) ||
2893 (ifa6->ia6_flags & (IN6_IFF_DETACHED |
2894 IN6_IFF_ANYCAST | IN6_IFF_NOTREADY))) {
2895 /* Can't bind a non-existent addr. */
2900 /* add this address */
2901 sctp_addr_mgmt_ep(inp, ifa, type);
2903 /* invalid address! */
2905 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
2906 kprintf("addr_mgmt_ep_sa: got invalid address!\n");
2908 #endif /* SCTP_DEBUG */
2909 return (EADDRNOTAVAIL);