2 * Copyright (c) 2001-2006, Cisco Systems, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * a) Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
10 * b) Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the distribution.
14 * c) Neither the name of Cisco Systems, Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE.
31 /* $KAME: sctp_asconf.c,v 1.24 2005/03/06 16:04:16 itojun Exp $ */
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
38 #include "opt_ipsec.h"
39 #include "opt_compat.h"
40 #include "opt_inet6.h"
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/malloc.h>
49 #include <sys/socket.h>
50 #include <sys/socketvar.h>
51 #include <sys/kernel.h>
52 #include <sys/sysctl.h>
55 #include <net/if_types.h>
56 #include <net/route.h>
58 #include <netinet/in.h>
59 #include <netinet/in_systm.h>
60 #include <netinet/ip.h>
61 #include <netinet/in_pcb.h>
62 #include <netinet/in_var.h>
63 #include <netinet/ip_var.h>
66 #include <netinet/ip6.h>
67 #include <netinet6/ip6_var.h>
68 #include <netinet6/in6_pcb.h>
69 #include <netinet/icmp6.h>
70 #include <netinet6/nd6.h>
71 #include <netinet6/scope6_var.h>
74 #include <netinet/in_pcb.h>
76 #include <netinet/sctp_os.h>
77 #include <netinet/sctp_var.h>
78 #include <netinet/sctp_pcb.h>
79 #include <netinet/sctp_header.h>
80 #include <netinet/sctputil.h>
81 #include <netinet/sctp_output.h>
82 #include <netinet/sctp_bsd_addr.h>
83 #include <netinet/sctp_asconf.h>
87 * SCTP_DEBUG_ASCONF1: protocol info, general info and errors
88 * SCTP_DEBUG_ASCONF2: detailed info
91 extern uint32_t sctp_debug_on;
93 #endif /* SCTP_DEBUG */
97 sctp_asconf_get_source_ip(struct mbuf *m, struct sockaddr *sa)
100 struct sockaddr_in *sin;
103 struct sockaddr_in6 *sin6;
107 iph = mtod(m, struct ip *);
108 if (iph->ip_v == IPVERSION) {
110 sin = (struct sockaddr_in *)sa;
111 bzero(sin, sizeof(*sin));
112 sin->sin_family = AF_INET;
113 sin->sin_len = sizeof(struct sockaddr_in);
115 sin->sin_addr.s_addr = iph->ip_src.s_addr;
119 else if (iph->ip_v == (IPV6_VERSION >> 4)) {
123 sin6 = (struct sockaddr_in6 *)sa;
124 bzero(sin6, sizeof(*sin6));
125 sin6->sin6_family = AF_INET6;
126 sin6->sin6_len = sizeof(struct sockaddr_in6);
128 ip6 = mtod(m, struct ip6_hdr *);
129 sin6->sin6_addr = ip6->ip6_src;
138 * draft-ietf-tsvwg-addip-sctp
140 * Address management only currently supported For the bound all case: the asoc
141 * local addr list is always a "DO NOT USE" list For the subset bound case:
142 * If ASCONFs are allowed: the endpoint local addr list is the usable address
143 * list the asoc local addr list is the "DO NOT USE" list If ASCONFs are not
144 * allowed: the endpoint local addr list is the default usable list the asoc
145 * local addr list is the usable address list
147 * An ASCONF parameter queue exists per asoc which holds the pending address
148 * operations. Lists are updated upon receipt of ASCONF-ACK.
150 * Deleted addresses are always immediately removed from the lists as they will
151 * (shortly) no longer exist in the kernel. We send ASCONFs as a courtesy,
156 * ASCONF parameter processing response_required: set if a reply is required
157 * (eg. SUCCESS_REPORT) returns a mbuf to an "error" response parameter or
158 * NULL/"success" if ok FIX: allocating this many mbufs on the fly is pretty
162 sctp_asconf_success_response(uint32_t id)
164 struct mbuf *m_reply = NULL;
165 struct sctp_asconf_paramhdr *aph;
167 m_reply = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_paramhdr),
168 0, M_DONTWAIT, 1, MT_DATA);
169 if (m_reply == NULL) {
171 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
172 printf("asconf_success_response: couldn't get mbuf!\n");
174 #endif /* SCTP_DEBUG */
177 aph = mtod(m_reply, struct sctp_asconf_paramhdr *);
178 aph->correlation_id = id;
179 aph->ph.param_type = htons(SCTP_SUCCESS_REPORT);
180 aph->ph.param_length = sizeof(struct sctp_asconf_paramhdr);
181 SCTP_BUF_LEN(m_reply) = aph->ph.param_length;
182 aph->ph.param_length = htons(aph->ph.param_length);
188 sctp_asconf_error_response(uint32_t id, uint16_t cause, uint8_t * error_tlv,
191 struct mbuf *m_reply = NULL;
192 struct sctp_asconf_paramhdr *aph;
193 struct sctp_error_cause *error;
196 m_reply = sctp_get_mbuf_for_msg((sizeof(struct sctp_asconf_paramhdr) +
198 sizeof(struct sctp_error_cause)),
199 0, M_DONTWAIT, 1, MT_DATA);
200 if (m_reply == NULL) {
202 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
203 printf("asconf_error_response: couldn't get mbuf!\n");
205 #endif /* SCTP_DEBUG */
208 aph = mtod(m_reply, struct sctp_asconf_paramhdr *);
209 error = (struct sctp_error_cause *)(aph + 1);
211 aph->correlation_id = id;
212 aph->ph.param_type = htons(SCTP_ERROR_CAUSE_IND);
213 error->code = htons(cause);
214 error->length = tlv_length + sizeof(struct sctp_error_cause);
215 aph->ph.param_length = error->length +
216 sizeof(struct sctp_asconf_paramhdr);
218 if (aph->ph.param_length > MLEN) {
220 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
221 printf("asconf_error_response: tlv_length (%xh) too big\n",
224 #endif /* SCTP_DEBUG */
225 sctp_m_freem(m_reply); /* discard */
228 if (error_tlv != NULL) {
229 tlv = (uint8_t *) (error + 1);
230 memcpy(tlv, error_tlv, tlv_length);
232 SCTP_BUF_LEN(m_reply) = aph->ph.param_length;
233 error->length = htons(error->length);
234 aph->ph.param_length = htons(aph->ph.param_length);
240 sctp_process_asconf_add_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph,
241 struct sctp_tcb *stcb, int response_required)
243 struct mbuf *m_reply = NULL;
244 struct sockaddr_storage sa_source, sa_store;
245 struct sctp_ipv4addr_param *v4addr;
246 uint16_t param_type, param_length, aparam_length;
248 struct sockaddr_in *sin;
249 int zero_address = 0;
252 struct sockaddr_in6 *sin6;
253 struct sctp_ipv6addr_param *v6addr;
257 aparam_length = ntohs(aph->ph.param_length);
258 v4addr = (struct sctp_ipv4addr_param *)(aph + 1);
260 v6addr = (struct sctp_ipv6addr_param *)(aph + 1);
262 param_type = ntohs(v4addr->ph.param_type);
263 param_length = ntohs(v4addr->ph.param_length);
265 sa = (struct sockaddr *)&sa_store;
266 switch (param_type) {
267 case SCTP_IPV4_ADDRESS:
268 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
269 /* invalid param size */
272 sin = (struct sockaddr_in *)&sa_store;
273 bzero(sin, sizeof(*sin));
274 sin->sin_family = AF_INET;
275 sin->sin_len = sizeof(struct sockaddr_in);
276 sin->sin_port = stcb->rport;
277 sin->sin_addr.s_addr = v4addr->addr;
278 if (sin->sin_addr.s_addr == INADDR_ANY)
281 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
282 printf("process_asconf_add_ip: adding ");
283 sctp_print_address(sa);
285 #endif /* SCTP_DEBUG */
287 case SCTP_IPV6_ADDRESS:
289 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
290 /* invalid param size */
293 sin6 = (struct sockaddr_in6 *)&sa_store;
294 bzero(sin6, sizeof(*sin6));
295 sin6->sin6_family = AF_INET6;
296 sin6->sin6_len = sizeof(struct sockaddr_in6);
297 sin6->sin6_port = stcb->rport;
298 memcpy((caddr_t)&sin6->sin6_addr, v6addr->addr,
299 sizeof(struct in6_addr));
300 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
303 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
304 printf("process_asconf_add_ip: adding ");
305 sctp_print_address(sa);
307 #endif /* SCTP_DEBUG */
309 /* IPv6 not enabled! */
310 /* FIX ME: currently sends back an invalid param error */
311 m_reply = sctp_asconf_error_response(aph->correlation_id,
312 SCTP_CAUSE_INVALID_PARAM, (uint8_t *) aph, aparam_length);
314 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
315 printf("process_asconf_add_ip: v6 disabled- skipping ");
316 sctp_print_address(sa);
318 #endif /* SCTP_DEBUG */
323 m_reply = sctp_asconf_error_response(aph->correlation_id,
324 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph,
329 /* if 0.0.0.0/::0, add the source address instead */
330 if (zero_address && sctp_nat_friendly) {
331 sa = (struct sockaddr *)&sa_source;
332 sctp_asconf_get_source_ip(m, sa);
334 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
335 printf("process_asconf_add_ip: using source addr ");
336 sctp_print_address(sa);
338 #endif /* SCTP_DEBUG */
340 /* add the address */
341 if (sctp_add_remote_addr(stcb, sa, SCTP_DONOT_SETSCOPE,
342 SCTP_ADDR_DYNAMIC_ADDED) != 0) {
344 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
345 printf("process_asconf_add_ip: error adding address\n");
347 #endif /* SCTP_DEBUG */
348 m_reply = sctp_asconf_error_response(aph->correlation_id,
349 SCTP_CAUSE_RESOURCE_SHORTAGE, (uint8_t *) aph,
352 /* notify upper layer */
353 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_ADD_IP, stcb, 0, sa);
354 if (response_required) {
356 sctp_asconf_success_response(aph->correlation_id);
358 sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, NULL, SCTP_FROM_SCTP_ASCONF + SCTP_LOC_1);
359 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, NULL);
367 sctp_asconf_del_remote_addrs_except(struct sctp_tcb *stcb,
368 struct sockaddr *src)
370 struct sctp_nets *src_net, *net;
372 /* make sure the source address exists as a destination net */
373 src_net = sctp_findnet(stcb, src);
374 if (src_net == NULL) {
378 /* delete all destination addresses except the source */
379 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
380 if (net != src_net) {
381 /* delete this address */
382 sctp_remove_net(stcb, net);
384 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
385 printf("asconf_del_remote_addrs_except: deleting ");
386 sctp_print_address((struct sockaddr *)&net->ro._l_addr);
389 /* notify upper layer */
390 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0,
391 (struct sockaddr *)&net->ro._l_addr);
398 sctp_process_asconf_delete_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph,
399 struct sctp_tcb *stcb, int response_required)
401 struct mbuf *m_reply = NULL;
402 struct sockaddr_storage sa_source, sa_store;
403 struct sctp_ipv4addr_param *v4addr;
404 uint16_t param_type, param_length, aparam_length;
406 struct sockaddr_in *sin;
407 int zero_address = 0;
411 struct sockaddr_in6 *sin6;
412 struct sctp_ipv6addr_param *v6addr;
416 /* get the source IP address for src and 0.0.0.0/::0 delete checks */
417 sctp_asconf_get_source_ip(m, (struct sockaddr *)&sa_source);
419 aparam_length = ntohs(aph->ph.param_length);
420 v4addr = (struct sctp_ipv4addr_param *)(aph + 1);
422 v6addr = (struct sctp_ipv6addr_param *)(aph + 1);
424 param_type = ntohs(v4addr->ph.param_type);
425 param_length = ntohs(v4addr->ph.param_length);
427 sa = (struct sockaddr *)&sa_store;
428 switch (param_type) {
429 case SCTP_IPV4_ADDRESS:
430 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
431 /* invalid param size */
434 sin = (struct sockaddr_in *)&sa_store;
435 bzero(sin, sizeof(*sin));
436 sin->sin_family = AF_INET;
437 sin->sin_len = sizeof(struct sockaddr_in);
438 sin->sin_port = stcb->rport;
439 sin->sin_addr.s_addr = v4addr->addr;
440 if (sin->sin_addr.s_addr == INADDR_ANY)
443 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
444 printf("process_asconf_delete_ip: deleting ");
445 sctp_print_address(sa);
447 #endif /* SCTP_DEBUG */
449 case SCTP_IPV6_ADDRESS:
450 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
451 /* invalid param size */
455 sin6 = (struct sockaddr_in6 *)&sa_store;
456 bzero(sin6, sizeof(*sin6));
457 sin6->sin6_family = AF_INET6;
458 sin6->sin6_len = sizeof(struct sockaddr_in6);
459 sin6->sin6_port = stcb->rport;
460 memcpy(&sin6->sin6_addr, v6addr->addr,
461 sizeof(struct in6_addr));
462 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
465 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
466 printf("process_asconf_delete_ip: deleting ");
467 sctp_print_address(sa);
469 #endif /* SCTP_DEBUG */
471 /* IPv6 not enabled! No "action" needed; just ack it */
473 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
474 printf("process_asconf_delete_ip: v6 disabled- ignoring: ");
475 sctp_print_address(sa);
477 #endif /* SCTP_DEBUG */
478 /* just respond with a "success" ASCONF-ACK */
483 m_reply = sctp_asconf_error_response(aph->correlation_id,
484 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph,
489 /* make sure the source address is not being deleted */
490 if (sctp_cmpaddr(sa, (struct sockaddr *)&sa_source)) {
491 /* trying to delete the source address! */
493 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
494 printf("process_asconf_delete_ip: tried to delete source addr\n");
496 #endif /* SCTP_DEBUG */
497 m_reply = sctp_asconf_error_response(aph->correlation_id,
498 SCTP_CAUSE_DELETING_SRC_ADDR, (uint8_t *) aph,
502 /* if deleting 0.0.0.0/::0, delete all addresses except src addr */
503 if (zero_address && sctp_nat_friendly) {
504 result = sctp_asconf_del_remote_addrs_except(stcb,
505 (struct sockaddr *)&sa_source);
508 /* src address did not exist? */
510 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
511 printf("process_asconf_delete_ip: src addr does not exist?\n");
513 #endif /* SCTP_DEBUG */
514 /* what error to reply with?? */
516 sctp_asconf_error_response(aph->correlation_id,
517 SCTP_CAUSE_REQUEST_REFUSED, (uint8_t *) aph,
519 } else if (response_required) {
521 sctp_asconf_success_response(aph->correlation_id);
525 /* delete the address */
526 result = sctp_del_remote_addr(stcb, sa);
528 * note if result == -2, the address doesn't exist in the asoc but
529 * since it's being deleted anyways, we just ack the delete -- but
530 * this probably means something has already gone awry
533 /* only one address in the asoc */
535 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
536 printf("process_asconf_delete_ip: tried to delete last IP addr!\n");
538 #endif /* SCTP_DEBUG */
539 m_reply = sctp_asconf_error_response(aph->correlation_id,
540 SCTP_CAUSE_DELETING_LAST_ADDR, (uint8_t *) aph,
543 if (response_required) {
544 m_reply = sctp_asconf_success_response(aph->correlation_id);
546 /* notify upper layer */
547 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0, sa);
553 sctp_process_asconf_set_primary(struct mbuf *m,
554 struct sctp_asconf_paramhdr *aph, struct sctp_tcb *stcb,
555 int response_required)
557 struct mbuf *m_reply = NULL;
558 struct sockaddr_storage sa_source, sa_store;
559 struct sctp_ipv4addr_param *v4addr;
560 uint16_t param_type, param_length, aparam_length;
562 struct sockaddr_in *sin;
563 int zero_address = 0;
566 struct sockaddr_in6 *sin6;
567 struct sctp_ipv6addr_param *v6addr;
571 aparam_length = ntohs(aph->ph.param_length);
572 v4addr = (struct sctp_ipv4addr_param *)(aph + 1);
574 v6addr = (struct sctp_ipv6addr_param *)(aph + 1);
576 param_type = ntohs(v4addr->ph.param_type);
577 param_length = ntohs(v4addr->ph.param_length);
579 sa = (struct sockaddr *)&sa_store;
580 switch (param_type) {
581 case SCTP_IPV4_ADDRESS:
582 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
583 /* invalid param size */
586 sin = (struct sockaddr_in *)&sa_store;
587 bzero(sin, sizeof(*sin));
588 sin->sin_family = AF_INET;
589 sin->sin_len = sizeof(struct sockaddr_in);
590 sin->sin_addr.s_addr = v4addr->addr;
591 if (sin->sin_addr.s_addr == INADDR_ANY)
594 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
595 printf("process_asconf_set_primary: ");
596 sctp_print_address(sa);
598 #endif /* SCTP_DEBUG */
600 case SCTP_IPV6_ADDRESS:
601 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
602 /* invalid param size */
606 sin6 = (struct sockaddr_in6 *)&sa_store;
607 bzero(sin6, sizeof(*sin6));
608 sin6->sin6_family = AF_INET6;
609 sin6->sin6_len = sizeof(struct sockaddr_in6);
610 memcpy((caddr_t)&sin6->sin6_addr, v6addr->addr,
611 sizeof(struct in6_addr));
612 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
615 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
616 printf("process_asconf_set_primary: ");
617 sctp_print_address(sa);
619 #endif /* SCTP_DEBUG */
621 /* IPv6 not enabled! No "action" needed; just ack it */
623 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
624 printf("process_asconf_set_primary: v6 disabled- ignoring: ");
625 sctp_print_address(sa);
627 #endif /* SCTP_DEBUG */
628 /* just respond with a "success" ASCONF-ACK */
633 m_reply = sctp_asconf_error_response(aph->correlation_id,
634 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph,
639 /* if 0.0.0.0/::0, use the source address instead */
640 if (zero_address && sctp_nat_friendly) {
641 sa = (struct sockaddr *)&sa_source;
642 sctp_asconf_get_source_ip(m, sa);
644 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
645 printf("process_asconf_set_primary: using source addr ");
646 sctp_print_address(sa);
648 #endif /* SCTP_DEBUG */
650 /* set the primary address */
651 if (sctp_set_primary_addr(stcb, sa, NULL) == 0) {
653 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
654 printf("process_asconf_set_primary: primary address set\n");
656 #endif /* SCTP_DEBUG */
657 /* notify upper layer */
658 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_SET_PRIMARY, stcb, 0, sa);
660 if (response_required) {
661 m_reply = sctp_asconf_success_response(aph->correlation_id);
664 /* couldn't set the requested primary address! */
666 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
667 printf("process_asconf_set_primary: set primary failed!\n");
669 #endif /* SCTP_DEBUG */
670 /* must have been an invalid address, so report */
671 m_reply = sctp_asconf_error_response(aph->correlation_id,
672 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph,
680 * handles an ASCONF chunk.
681 * if all parameters are processed ok, send a plain (empty) ASCONF-ACK
684 sctp_handle_asconf(struct mbuf *m, unsigned int offset,
685 struct sctp_asconf_chunk *cp, struct sctp_tcb *stcb)
687 struct sctp_association *asoc;
689 struct mbuf *m_ack, *m_result, *m_tail;
690 struct sctp_asconf_ack_chunk *ack_cp;
691 struct sctp_asconf_paramhdr *aph, *ack_aph;
692 struct sctp_ipv6addr_param *p_addr;
693 unsigned int asconf_limit;
694 int error = 0; /* did an error occur? */
696 /* asconf param buffer */
697 static uint8_t aparam_buf[DEFAULT_PARAM_BUFFER];
699 /* verify minimum length */
700 if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_chunk)) {
702 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
703 printf("handle_asconf: chunk too small = %xh\n",
704 ntohs(cp->ch.chunk_length));
706 #endif /* SCTP_DEBUG */
710 serial_num = ntohl(cp->serial_number);
712 if (serial_num == asoc->asconf_seq_in) {
713 /* got a duplicate ASCONF */
715 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
716 printf("handle_asconf: got duplicate serial number = %xh\n",
719 #endif /* SCTP_DEBUG */
720 /* resend last ASCONF-ACK... */
721 sctp_send_asconf_ack(stcb, 1);
723 } else if (serial_num != (asoc->asconf_seq_in + 1)) {
725 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
726 printf("handle_asconf: incorrect serial number = %xh (expected next = %xh)\n",
727 serial_num, asoc->asconf_seq_in + 1);
729 #endif /* SCTP_DEBUG */
732 /* it's the expected "next" sequence number, so process it */
733 asoc->asconf_seq_in = serial_num; /* update sequence */
734 /* get length of all the param's in the ASCONF */
735 asconf_limit = offset + ntohs(cp->ch.chunk_length);
737 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
738 printf("handle_asconf: asconf_limit=%u, sequence=%xh\n",
739 asconf_limit, serial_num);
741 #endif /* SCTP_DEBUG */
742 if (asoc->last_asconf_ack_sent != NULL) {
743 /* free last ASCONF-ACK message sent */
744 sctp_m_freem(asoc->last_asconf_ack_sent);
745 asoc->last_asconf_ack_sent = NULL;
747 m_ack = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_ack_chunk), 0,
748 M_DONTWAIT, 1, MT_DATA);
751 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
752 printf("handle_asconf: couldn't get mbuf!\n");
754 #endif /* SCTP_DEBUG */
757 m_tail = m_ack; /* current reply chain's tail */
759 /* fill in ASCONF-ACK header */
760 ack_cp = mtod(m_ack, struct sctp_asconf_ack_chunk *);
761 ack_cp->ch.chunk_type = SCTP_ASCONF_ACK;
762 ack_cp->ch.chunk_flags = 0;
763 ack_cp->serial_number = htonl(serial_num);
764 /* set initial lengths (eg. just an ASCONF-ACK), ntohx at the end! */
765 SCTP_BUF_LEN(m_ack) = sizeof(struct sctp_asconf_ack_chunk);
766 ack_cp->ch.chunk_length = sizeof(struct sctp_asconf_ack_chunk);
768 /* skip the lookup address parameter */
769 offset += sizeof(struct sctp_asconf_chunk);
770 p_addr = (struct sctp_ipv6addr_param *)sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), (uint8_t *) & aparam_buf);
771 if (p_addr == NULL) {
773 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
774 printf("handle_asconf: couldn't get lookup addr!\n");
776 #endif /* SCTP_DEBUG */
778 /* respond with a missing/invalid mandatory parameter error */
781 /* param_length is already validated in process_control... */
782 offset += ntohs(p_addr->ph.param_length); /* skip lookup addr */
784 /* get pointer to first asconf param in ASCONF-ACK */
785 ack_aph = (struct sctp_asconf_paramhdr *)(mtod(m_ack, caddr_t)+sizeof(struct sctp_asconf_ack_chunk));
786 if (ack_aph == NULL) {
788 printf("Gak in asconf2\n");
792 /* get pointer to first asconf param in ASCONF */
793 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, sizeof(struct sctp_asconf_paramhdr), (uint8_t *) & aparam_buf);
796 printf("Empty ASCONF received?\n");
800 /* process through all parameters */
801 while (aph != NULL) {
802 unsigned int param_length, param_type;
804 param_type = ntohs(aph->ph.param_type);
805 param_length = ntohs(aph->ph.param_length);
806 if (offset + param_length > asconf_limit) {
807 /* parameter goes beyond end of chunk! */
813 if (param_length > sizeof(aparam_buf)) {
815 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
816 printf("handle_asconf: param length (%u) larger than buffer size!\n", param_length);
818 #endif /* SCTP_DEBUG */
822 if (param_length <= sizeof(struct sctp_paramhdr)) {
824 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
825 printf("handle_asconf: param length (%u) too short\n", param_length);
827 #endif /* SCTP_DEBUG */
830 /* get the entire parameter */
831 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf);
839 switch (param_type) {
840 case SCTP_ADD_IP_ADDRESS:
841 asoc->peer_supports_asconf = 1;
842 m_result = sctp_process_asconf_add_ip(m, aph, stcb,
845 case SCTP_DEL_IP_ADDRESS:
846 asoc->peer_supports_asconf = 1;
847 m_result = sctp_process_asconf_delete_ip(m, aph, stcb,
850 case SCTP_ERROR_CAUSE_IND:
851 /* not valid in an ASCONF chunk */
853 case SCTP_SET_PRIM_ADDR:
854 asoc->peer_supports_asconf = 1;
855 m_result = sctp_process_asconf_set_primary(m, aph,
858 case SCTP_SUCCESS_REPORT:
859 /* not valid in an ASCONF chunk */
861 case SCTP_ULP_ADAPTATION:
865 if ((param_type & 0x8000) == 0) {
866 /* Been told to STOP at this param */
867 asconf_limit = offset;
869 * FIX FIX - We need to call
870 * sctp_arethere_unrecognized_parameters()
871 * to get a operr and send it for any
872 * param's with the 0x4000 bit set OR do it
873 * here ourselves... note we still must STOP
874 * if the 0x8000 bit is clear.
877 /* unknown/invalid param type */
881 /* add any (error) result to the reply mbuf chain */
882 if (m_result != NULL) {
883 SCTP_BUF_NEXT(m_tail) = m_result;
885 /* update lengths, make sure it's aligned too */
886 SCTP_BUF_LEN(m_result) = SCTP_SIZE32(SCTP_BUF_LEN(m_result));
887 ack_cp->ch.chunk_length += SCTP_BUF_LEN(m_result);
888 /* set flag to force success reports */
891 offset += SCTP_SIZE32(param_length);
892 /* update remaining ASCONF message length to process */
893 if (offset >= asconf_limit) {
894 /* no more data in the mbuf chain */
897 /* get pointer to next asconf param */
898 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset,
899 sizeof(struct sctp_asconf_paramhdr),
900 (uint8_t *) & aparam_buf);
902 /* can't get an asconf paramhdr */
904 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
905 printf("handle_asconf: can't get asconf param hdr!\n");
907 #endif /* SCTP_DEBUG */
908 /* FIX ME - add error here... */
913 ack_cp->ch.chunk_length = htons(ack_cp->ch.chunk_length);
914 /* save the ASCONF-ACK reply */
915 asoc->last_asconf_ack_sent = m_ack;
917 /* see if last_control_chunk_from is set properly (use IP src addr) */
918 if (stcb->asoc.last_control_chunk_from == NULL) {
920 * this could happen if the source address was just newly
925 struct sockaddr_storage from_store;
926 struct sockaddr *from = (struct sockaddr *)&from_store;
929 if (sctp_debug_on & SCTP_DEBUG_ASCONF1)
930 printf("handle_asconf: looking up net for IP source address\n");
931 #endif /* SCTP_DEBUG */
932 /* pullup already done, IP options already stripped */
933 iph = mtod(m, struct ip *);
934 sh = (struct sctphdr *)((caddr_t)iph + sizeof(*iph));
935 if (iph->ip_v == IPVERSION) {
936 struct sockaddr_in *from4;
938 from4 = (struct sockaddr_in *)&from_store;
939 bzero(from4, sizeof(*from4));
940 from4->sin_family = AF_INET;
941 from4->sin_len = sizeof(struct sockaddr_in);
942 from4->sin_addr.s_addr = iph->ip_src.s_addr;
943 from4->sin_port = sh->src_port;
944 } else if (iph->ip_v == (IPV6_VERSION >> 4)) {
946 struct sockaddr_in6 *from6;
948 ip6 = mtod(m, struct ip6_hdr *);
949 from6 = (struct sockaddr_in6 *)&from_store;
950 bzero(from6, sizeof(*from6));
951 from6->sin6_family = AF_INET6;
952 from6->sin6_len = sizeof(struct sockaddr_in6);
953 from6->sin6_addr = ip6->ip6_src;
954 from6->sin6_port = sh->src_port;
955 /* Get the scopes in properly to the sin6 addr's */
956 /* we probably don't need these operations */
957 (void)sa6_recoverscope(from6);
958 sa6_embedscope(from6, ip6_use_defzone);
960 /* unknown address type */
965 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
966 printf("Looking for IP source: ");
967 sctp_print_address(from);
969 #endif /* SCTP_DEBUG */
970 /* look up the from address */
971 stcb->asoc.last_control_chunk_from = sctp_findnet(stcb, from);
973 if ((stcb->asoc.last_control_chunk_from == NULL) &&
974 (sctp_debug_on & SCTP_DEBUG_ASCONF1))
975 printf("handle_asconf: IP source address not found?!\n");
976 #endif /* SCTP_DEBUG */
979 /* and send it (a new one) out... */
980 sctp_send_asconf_ack(stcb, 0);
984 * does the address match? returns 0 if not, 1 if so
987 sctp_asconf_addr_match(struct sctp_asconf_addr *aa, struct sockaddr *sa)
990 if (sa->sa_family == AF_INET6) {
991 /* IPv6 sa address */
993 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
995 if ((aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) &&
996 (memcmp(&aa->ap.addrp.addr, &sin6->sin6_addr,
997 sizeof(struct in6_addr)) == 0)) {
1002 if (sa->sa_family == AF_INET) {
1003 /* IPv4 sa address */
1004 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
1006 if ((aa->ap.addrp.ph.param_type == SCTP_IPV4_ADDRESS) &&
1007 (memcmp(&aa->ap.addrp.addr, &sin->sin_addr,
1008 sizeof(struct in_addr)) == 0)) {
1016 * Cleanup for non-responded/OP ERR'd ASCONF
1019 sctp_asconf_cleanup(struct sctp_tcb *stcb, struct sctp_nets *net)
1021 /* mark peer as ASCONF incapable */
1022 stcb->asoc.peer_supports_asconf = 0;
1024 * clear out any existing asconfs going out
1026 sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_ASCONF + SCTP_LOC_2);
1027 stcb->asoc.asconf_seq_out++;
1028 /* remove the old ASCONF on our outbound queue */
1029 sctp_toss_old_asconf(stcb);
1033 * process an ADD/DELETE IP ack from peer.
1034 * addr corresponding ifaddr to the address being added/deleted.
1035 * type: SCTP_ADD_IP_ADDRESS or SCTP_DEL_IP_ADDRESS.
1036 * flag: 1=success, 0=failure.
1039 sctp_asconf_addr_mgmt_ack(struct sctp_tcb *stcb, struct ifaddr *addr,
1040 uint16_t type, uint32_t flag)
1043 * do the necessary asoc list work- if we get a failure indication,
1044 * leave the address on the "do not use" asoc list if we get a
1045 * success indication, remove the address from the list
1048 * Note: this will only occur for ADD_IP_ADDRESS, since
1049 * DEL_IP_ADDRESS is never actually added to the list...
1052 /* success case, so remove from the list */
1053 sctp_del_local_addr_assoc(stcb, addr);
1055 /* else, leave it on the list */
1059 * add an asconf add/delete IP address parameter to the queue.
1060 * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR.
1061 * returns 0 if completed, non-zero if not completed.
1062 * NOTE: if adding, but delete already scheduled (and not yet sent out),
1063 * simply remove from queue. Same for deleting an address already scheduled
1064 * for add. If a duplicate operation is found, ignore the new one.
1067 sctp_asconf_queue_add(struct sctp_tcb *stcb, struct ifaddr *ifa, uint16_t type)
1069 struct sctp_asconf_addr *aa, *aa_next;
1070 struct sockaddr *sa;
1072 /* see if peer supports ASCONF */
1073 if (stcb->asoc.peer_supports_asconf == 0) {
1076 /* make sure the request isn't already in the queue */
1077 for (aa = TAILQ_FIRST(&stcb->asoc.asconf_queue); aa != NULL;
1079 aa_next = TAILQ_NEXT(aa, next);
1080 /* address match? */
1081 if (sctp_asconf_addr_match(aa, ifa->ifa_addr) == 0)
1083 /* is the request already in queue (sent or not) */
1084 if (aa->ap.aph.ph.param_type == type) {
1087 /* is the negative request already in queue, and not sent */
1088 if (aa->sent == 0 &&
1089 /* add requested, delete already queued */
1090 ((type == SCTP_ADD_IP_ADDRESS &&
1091 aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) ||
1092 /* delete requested, add already queued */
1093 (type == SCTP_DEL_IP_ADDRESS &&
1094 aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS))) {
1095 /* delete the existing entry in the queue */
1096 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1097 /* take the entry off the appropriate list */
1098 sctp_asconf_addr_mgmt_ack(stcb, aa->ifa, type, 1);
1099 /* free the entry */
1105 /* adding new request to the queue */
1106 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), "AsconfAddr");
1108 /* didn't get memory */
1110 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1111 printf("asconf_queue_add: failed to get memory!\n");
1113 #endif /* SCTP_DEBUG */
1116 /* fill in asconf address parameter fields */
1117 /* top level elements are "networked" during send */
1118 aa->ap.aph.ph.param_type = type;
1120 /* correlation_id filled in during send routine later... */
1121 if (ifa->ifa_addr->sa_family == AF_INET6) {
1123 struct sockaddr_in6 *sin6;
1125 sin6 = (struct sockaddr_in6 *)ifa->ifa_addr;
1126 sa = (struct sockaddr *)sin6;
1127 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
1128 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param));
1129 aa->ap.aph.ph.param_length =
1130 sizeof(struct sctp_asconf_paramhdr) +
1131 sizeof(struct sctp_ipv6addr_param);
1132 memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr,
1133 sizeof(struct in6_addr));
1134 } else if (ifa->ifa_addr->sa_family == AF_INET) {
1136 struct sockaddr_in *sin = (struct sockaddr_in *)ifa->ifa_addr;
1138 sa = (struct sockaddr *)sin;
1139 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
1140 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param));
1141 aa->ap.aph.ph.param_length =
1142 sizeof(struct sctp_asconf_paramhdr) +
1143 sizeof(struct sctp_ipv4addr_param);
1144 memcpy(&aa->ap.addrp.addr, &sin->sin_addr,
1145 sizeof(struct in_addr));
1147 /* invalid family! */
1150 aa->sent = 0; /* clear sent flag */
1153 * if we are deleting an address it should go out last otherwise,
1154 * add it to front of the pending queue
1156 if (type == SCTP_ADD_IP_ADDRESS) {
1157 /* add goes to the front of the queue */
1158 TAILQ_INSERT_HEAD(&stcb->asoc.asconf_queue, aa, next);
1160 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) {
1161 printf("asconf_queue_add: appended asconf ADD_IP_ADDRESS: ");
1162 sctp_print_address(sa);
1164 #endif /* SCTP_DEBUG */
1166 /* delete and set primary goes to the back of the queue */
1167 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
1169 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) {
1170 if (type == SCTP_DEL_IP_ADDRESS) {
1171 printf("asconf_queue_add: inserted asconf DEL_IP_ADDRESS: ");
1172 sctp_print_address(sa);
1174 printf("asconf_queue_add: inserted asconf SET_PRIM_ADDR: ");
1175 sctp_print_address(sa);
1178 #endif /* SCTP_DEBUG */
1185 * add an asconf add/delete IP address parameter to the queue by addr.
1186 * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR.
1187 * returns 0 if completed, non-zero if not completed.
1188 * NOTE: if adding, but delete already scheduled (and not yet sent out),
1189 * simply remove from queue. Same for deleting an address already scheduled
1190 * for add. If a duplicate operation is found, ignore the new one.
1193 sctp_asconf_queue_add_sa(struct sctp_tcb *stcb, struct sockaddr *sa,
1196 struct sctp_asconf_addr *aa, *aa_next;
1198 /* see if peer supports ASCONF */
1199 if (stcb->asoc.peer_supports_asconf == 0) {
1202 /* make sure the request isn't already in the queue */
1203 for (aa = TAILQ_FIRST(&stcb->asoc.asconf_queue); aa != NULL;
1205 aa_next = TAILQ_NEXT(aa, next);
1206 /* address match? */
1207 if (sctp_asconf_addr_match(aa, sa) == 0)
1209 /* is the request already in queue (sent or not) */
1210 if (aa->ap.aph.ph.param_type == type) {
1213 /* is the negative request already in queue, and not sent */
1216 if (type == SCTP_ADD_IP_ADDRESS &&
1217 aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) {
1218 /* add requested, delete already queued */
1220 /* delete the existing entry in the queue */
1221 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1222 /* free the entry */
1225 } else if (type == SCTP_DEL_IP_ADDRESS &&
1226 aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS) {
1227 /* delete requested, add already queued */
1229 /* delete the existing entry in the queue */
1230 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1231 /* take the entry off the appropriate list */
1232 sctp_asconf_addr_mgmt_ack(stcb, aa->ifa, type, 1);
1233 /* free the entry */
1239 /* adding new request to the queue */
1240 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), "AsconfAddr");
1242 /* didn't get memory */
1244 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1245 printf("asconf_queue_add_sa: failed to get memory!\n");
1247 #endif /* SCTP_DEBUG */
1250 /* fill in asconf address parameter fields */
1251 /* top level elements are "networked" during send */
1252 aa->ap.aph.ph.param_type = type;
1253 aa->ifa = sctp_find_ifa_by_addr(sa);
1254 /* correlation_id filled in during send routine later... */
1255 if (sa->sa_family == AF_INET6) {
1257 struct sockaddr_in6 *sin6;
1259 sin6 = (struct sockaddr_in6 *)sa;
1260 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
1261 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param));
1262 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv6addr_param);
1263 memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr,
1264 sizeof(struct in6_addr));
1265 } else if (sa->sa_family == AF_INET) {
1267 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
1269 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
1270 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param));
1271 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv4addr_param);
1272 memcpy(&aa->ap.addrp.addr, &sin->sin_addr,
1273 sizeof(struct in_addr));
1275 /* invalid family! */
1279 aa->sent = 0; /* clear sent flag */
1282 * if we are deleting an address it should go out last otherwise,
1283 * add it to front of the pending queue
1285 if (type == SCTP_ADD_IP_ADDRESS) {
1286 /* add goes to the front of the queue */
1287 TAILQ_INSERT_HEAD(&stcb->asoc.asconf_queue, aa, next);
1289 /* delete and set primary goes to the back of the queue */
1290 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
1297 * find a specific asconf param on our "sent" queue
1299 static struct sctp_asconf_addr *
1300 sctp_asconf_find_param(struct sctp_tcb *stcb, uint32_t correlation_id)
1302 struct sctp_asconf_addr *aa;
1304 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
1305 if (aa->ap.aph.correlation_id == correlation_id &&
1311 /* didn't find it */
1316 * process an SCTP_ERROR_CAUSE_IND for a ASCONF-ACK parameter and do
1317 * notifications based on the error response
1320 sctp_asconf_process_error(struct sctp_tcb *stcb,
1321 struct sctp_asconf_paramhdr *aph)
1323 struct sctp_error_cause *eh;
1324 struct sctp_paramhdr *ph;
1325 uint16_t param_type;
1326 uint16_t error_code;
1328 eh = (struct sctp_error_cause *)(aph + 1);
1329 ph = (struct sctp_paramhdr *)(eh + 1);
1330 /* validate lengths */
1331 if (htons(eh->length) + sizeof(struct sctp_error_cause) >
1332 htons(aph->ph.param_length)) {
1333 /* invalid error cause length */
1335 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1336 printf("asconf_process_error: cause element too long\n");
1338 #endif /* SCTP_DEBUG */
1341 if (htons(ph->param_length) + sizeof(struct sctp_paramhdr) >
1342 htons(eh->length)) {
1343 /* invalid included TLV length */
1345 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1346 printf("asconf_process_error: included TLV too long\n");
1348 #endif /* SCTP_DEBUG */
1351 /* which error code ? */
1352 error_code = ntohs(eh->code);
1353 param_type = ntohs(aph->ph.param_type);
1354 /* FIX: this should go back up the REMOTE_ERROR ULP notify */
1355 switch (error_code) {
1356 case SCTP_CAUSE_RESOURCE_SHORTAGE:
1357 /* we allow ourselves to "try again" for this error */
1360 /* peer can't handle it... */
1361 switch (param_type) {
1362 case SCTP_ADD_IP_ADDRESS:
1363 case SCTP_DEL_IP_ADDRESS:
1364 stcb->asoc.peer_supports_asconf = 0;
1366 case SCTP_SET_PRIM_ADDR:
1367 stcb->asoc.peer_supports_asconf = 0;
1376 * process an asconf queue param aparam: parameter to process, will be
1377 * removed from the queue flag: 1=success, 0=failure
1380 sctp_asconf_process_param_ack(struct sctp_tcb *stcb,
1381 struct sctp_asconf_addr *aparam, uint32_t flag)
1383 uint16_t param_type;
1385 /* process this param */
1386 param_type = aparam->ap.aph.ph.param_type;
1387 switch (param_type) {
1388 case SCTP_ADD_IP_ADDRESS:
1390 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1391 printf("process_param_ack: added IP address\n");
1393 #endif /* SCTP_DEBUG */
1394 sctp_asconf_addr_mgmt_ack(stcb, aparam->ifa, param_type, flag);
1396 case SCTP_DEL_IP_ADDRESS:
1398 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1399 printf("process_param_ack: deleted IP address\n");
1401 #endif /* SCTP_DEBUG */
1402 /* nothing really to do... lists already updated */
1404 case SCTP_SET_PRIM_ADDR:
1405 /* nothing to do... peer may start using this addr */
1407 stcb->asoc.peer_supports_asconf = 0;
1410 /* should NEVER happen */
1414 /* remove the param and free it */
1415 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aparam, next);
1420 * cleanup from a bad asconf ack parameter
1423 sctp_asconf_ack_clear(struct sctp_tcb *stcb)
1425 /* assume peer doesn't really know how to do asconfs */
1426 stcb->asoc.peer_supports_asconf = 0;
1427 /* XXX we could free the pending queue here */
1431 sctp_handle_asconf_ack(struct mbuf *m, int offset,
1432 struct sctp_asconf_ack_chunk *cp, struct sctp_tcb *stcb,
1433 struct sctp_nets *net)
1435 struct sctp_association *asoc;
1436 uint32_t serial_num;
1437 uint16_t ack_length;
1438 struct sctp_asconf_paramhdr *aph;
1439 struct sctp_asconf_addr *aa, *aa_next;
1440 uint32_t last_error_id = 0; /* last error correlation id */
1442 struct sctp_asconf_addr *ap;
1444 /* asconf param buffer */
1445 static uint8_t aparam_buf[DEFAULT_PARAM_BUFFER];
1447 /* verify minimum length */
1448 if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_ack_chunk)) {
1450 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1451 printf("handle_asconf_ack: chunk too small = %xh\n",
1452 ntohs(cp->ch.chunk_length));
1454 #endif /* SCTP_DEBUG */
1458 serial_num = ntohl(cp->serial_number);
1461 * NOTE: we may want to handle this differently- currently, we will
1462 * abort when we get an ack for the expected serial number + 1 (eg.
1463 * we didn't send it), process an ack normally if it is the expected
1464 * serial number, and re-send the previous ack for *ALL* other
1469 * if the serial number is the next expected, but I didn't send it,
1470 * abort the asoc, since someone probably just hijacked us...
1472 if (serial_num == (asoc->asconf_seq_out + 1)) {
1474 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1475 printf("handle_asconf_ack: got unexpected next serial number! Aborting asoc!\n");
1477 #endif /* SCTP_DEBUG */
1478 sctp_abort_an_association(stcb->sctp_ep, stcb,
1479 SCTP_CAUSE_ILLEGAL_ASCONF_ACK, NULL);
1482 if (serial_num != asoc->asconf_seq_out) {
1483 /* got a duplicate/unexpected ASCONF-ACK */
1485 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1486 printf("handle_asconf_ack: got duplicate/unexpected serial number = %xh (expected = %xh)\n", serial_num, asoc->asconf_seq_out);
1488 #endif /* SCTP_DEBUG */
1491 if (stcb->asoc.asconf_sent == 0) {
1492 /* got a unexpected ASCONF-ACK for serial not in flight */
1494 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1495 printf("handle_asconf_ack: got serial number = %xh but not in flight\n", serial_num);
1497 #endif /* SCTP_DEBUG */
1498 /* nothing to do... duplicate ACK received */
1501 /* stop our timer */
1502 sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_ASCONF + SCTP_LOC_3);
1504 /* process the ASCONF-ACK contents */
1505 ack_length = ntohs(cp->ch.chunk_length) -
1506 sizeof(struct sctp_asconf_ack_chunk);
1507 offset += sizeof(struct sctp_asconf_ack_chunk);
1508 /* process through all parameters */
1509 while (ack_length >= sizeof(struct sctp_asconf_paramhdr)) {
1510 unsigned int param_length, param_type;
1512 /* get pointer to next asconf parameter */
1513 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset,
1514 sizeof(struct sctp_asconf_paramhdr), aparam_buf);
1516 /* can't get an asconf paramhdr */
1517 sctp_asconf_ack_clear(stcb);
1520 param_type = ntohs(aph->ph.param_type);
1521 param_length = ntohs(aph->ph.param_length);
1522 if (param_length > ack_length) {
1523 sctp_asconf_ack_clear(stcb);
1526 if (param_length < sizeof(struct sctp_paramhdr)) {
1527 sctp_asconf_ack_clear(stcb);
1530 /* get the complete parameter... */
1531 if (param_length > sizeof(aparam_buf)) {
1533 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1534 printf("param length (%u) larger than buffer size!\n", param_length);
1536 #endif /* SCTP_DEBUG */
1537 sctp_asconf_ack_clear(stcb);
1540 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf);
1542 sctp_asconf_ack_clear(stcb);
1545 /* correlation_id is transparent to peer, no ntohl needed */
1546 id = aph->correlation_id;
1548 switch (param_type) {
1549 case SCTP_ERROR_CAUSE_IND:
1551 /* find the corresponding asconf param in our queue */
1552 ap = sctp_asconf_find_param(stcb, id);
1554 /* hmm... can't find this in our queue! */
1557 /* process the parameter, failed flag */
1558 sctp_asconf_process_param_ack(stcb, ap, 0);
1559 /* process the error response */
1560 sctp_asconf_process_error(stcb, aph);
1562 case SCTP_SUCCESS_REPORT:
1563 /* find the corresponding asconf param in our queue */
1564 ap = sctp_asconf_find_param(stcb, id);
1566 /* hmm... can't find this in our queue! */
1569 /* process the parameter, success flag */
1570 sctp_asconf_process_param_ack(stcb, ap, 1);
1576 /* update remaining ASCONF-ACK message length to process */
1577 ack_length -= SCTP_SIZE32(param_length);
1578 if (ack_length <= 0) {
1579 /* no more data in the mbuf chain */
1582 offset += SCTP_SIZE32(param_length);
1586 * if there are any "sent" params still on the queue, these are
1587 * implicitly "success", or "failed" (if we got an error back) ...
1588 * so process these appropriately
1590 * we assume that the correlation_id's are monotonically increasing
1591 * beginning from 1 and that we don't have *that* many outstanding
1594 if (last_error_id == 0)
1595 last_error_id--;/* set to "max" value */
1596 for (aa = TAILQ_FIRST(&stcb->asoc.asconf_queue); aa != NULL;
1598 aa_next = TAILQ_NEXT(aa, next);
1599 if (aa->sent == 1) {
1601 * implicitly successful or failed if correlation_id
1602 * < last_error_id, then success else, failure
1604 if (aa->ap.aph.correlation_id < last_error_id)
1605 sctp_asconf_process_param_ack(stcb, aa,
1606 SCTP_SUCCESS_REPORT);
1608 sctp_asconf_process_param_ack(stcb, aa,
1609 SCTP_ERROR_CAUSE_IND);
1612 * since we always process in order (FIFO queue) if
1613 * we reach one that hasn't been sent, the rest
1614 * should not have been sent either. so, we're
1621 /* update the next sequence number to use */
1622 asoc->asconf_seq_out++;
1623 /* remove the old ASCONF on our outbound queue */
1624 sctp_toss_old_asconf(stcb);
1625 /* clear the sent flag to allow new ASCONFs */
1626 asoc->asconf_sent = 0;
1627 if (!TAILQ_EMPTY(&stcb->asoc.asconf_queue)) {
1628 /* we have more params, so restart our timer */
1629 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep,
1634 /* is this an interface that we care about at all? */
1636 sctp_is_desired_interface_type(struct ifaddr *ifa)
1640 /* check the interface type to see if it's one we care about */
1641 switch (ifa->ifa_ifp->if_type) {
1664 sctp_is_scopeid_in_nets(struct sctp_tcb *stcb, struct sockaddr *sa)
1666 struct sockaddr_in6 *sin6, *net6;
1667 struct sctp_nets *net;
1669 if (sa->sa_family != AF_INET6) {
1673 sin6 = (struct sockaddr_in6 *)sa;
1674 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) == 0) {
1675 /* not link local address */
1678 /* hunt through our destination nets list for this scope_id */
1679 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1680 if (((struct sockaddr *)(&net->ro._l_addr))->sa_family !=
1683 net6 = (struct sockaddr_in6 *)&net->ro._l_addr;
1684 if (IN6_IS_ADDR_LINKLOCAL(&net6->sin6_addr) == 0)
1686 if (sctp_is_same_scope(sin6, net6)) {
1691 /* didn't find one */
1696 * address management functions
1699 sctp_addr_mgmt_assoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
1700 struct ifaddr *ifa, uint16_t type)
1705 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0 &&
1706 sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_ASCONF)) {
1707 /* subset bound, no ASCONF allowed case, so ignore */
1711 * note: we know this is not the subset bound, no ASCONF case eg.
1712 * this is boundall or subset bound w/ASCONF allowed
1715 /* first, make sure it's a good address family */
1716 if (ifa->ifa_addr->sa_family != AF_INET6 &&
1717 ifa->ifa_addr->sa_family != AF_INET) {
1720 /* make sure we're "allowed" to add this type of addr */
1721 if (ifa->ifa_addr->sa_family == AF_INET6) {
1722 struct in6_ifaddr *ifa6;
1724 /* invalid if we're not a v6 endpoint */
1725 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0)
1727 /* is the v6 addr really valid ? */
1728 ifa6 = (struct in6_ifaddr *)ifa;
1729 if (IFA6_IS_DEPRECATED(ifa6) ||
1731 (IN6_IFF_DETACHED | IN6_IFF_ANYCAST | IN6_IFF_NOTREADY))) {
1732 /* can't use an invalid address */
1736 /* put this address on the "pending/do not use yet" list */
1738 * Note: we do this primarily for the subset bind case We don't have
1739 * scoping flags at the EP level, so we must add link local/site
1740 * local addresses to the EP, then need to "negate" them here.
1741 * Recall that this routine is only called for the subset bound
1742 * w/ASCONF allowed case.
1746 * do a scope_id check against any link local addresses in the
1747 * destination nets list to see if we should put this local address
1748 * on the pending list or not eg. don't put on the list if we have a
1749 * link local destination with the same scope_id
1751 if (type == SCTP_ADD_IP_ADDRESS) {
1752 if (sctp_is_scopeid_in_nets(stcb, ifa->ifa_addr) == 0) {
1753 sctp_add_local_addr_assoc(stcb, ifa);
1757 * check address scope if address is out of scope, don't queue
1758 * anything... note: this would leave the address on both inp and
1761 if (ifa->ifa_addr->sa_family == AF_INET6) {
1762 struct sockaddr_in6 *sin6;
1764 sin6 = (struct sockaddr_in6 *)ifa->ifa_addr;
1765 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
1766 /* we skip unspecifed addresses */
1769 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
1770 if (stcb->asoc.local_scope == 0) {
1773 /* is it the right link local scope? */
1774 if (sctp_is_scopeid_in_nets(stcb, ifa->ifa_addr) == 0) {
1778 if (stcb->asoc.site_scope == 0 &&
1779 IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)) {
1782 } else if (ifa->ifa_addr->sa_family == AF_INET) {
1783 struct sockaddr_in *sin;
1784 struct in6pcb *inp6;
1786 inp6 = (struct in6pcb *)&inp->ip_inp.inp;
1787 /* invalid if we are a v6 only endpoint */
1788 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1789 (inp6->inp_flags & IN6P_IPV6_V6ONLY)
1793 sin = (struct sockaddr_in *)ifa->ifa_addr;
1794 if (sin->sin_addr.s_addr == 0) {
1795 /* we skip unspecifed addresses */
1798 if (stcb->asoc.ipv4_local_scope == 0 &&
1799 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) {
1803 /* else, not AF_INET or AF_INET6, so skip */
1805 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1806 printf("addr_mgmt_assoc: not AF_INET or AF_INET6\n");
1808 #endif /* SCTP_DEBUG */
1812 /* queue an asconf for this address add/delete */
1814 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF)) {
1815 /* does the peer do asconf? */
1816 if (stcb->asoc.peer_supports_asconf) {
1817 /* queue an asconf for this addr */
1818 status = sctp_asconf_queue_add(stcb, ifa, type);
1820 * if queued ok, and in correct state, set the
1821 * ASCONF timer if in non-open state, we will set
1822 * this timer when the state does go open and do all
1826 SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) {
1827 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, inp,
1828 stcb, stcb->asoc.primary_destination);
1832 /* this is the boundall, no ASCONF case */
1834 /* Peter: Fixe me? why the if 0? */
1836 * assume kernel will delete this very shortly; add done
1839 if (type == SCTP_DEL_IP_ADDRESS) {
1840 /* if deleting, add this addr to the do not use list */
1841 sctp_add_local_addr_assoc(stcb, ifa);
1848 sctp_addr_mgmt_ep(struct sctp_inpcb *inp, struct ifaddr *ifa, uint16_t type)
1850 struct sctp_tcb *stcb;
1854 SCTP_INP_WLOCK(inp);
1855 /* make sure we're "allowed" to add this type of addr */
1856 if (ifa->ifa_addr->sa_family == AF_INET6) {
1857 struct in6_ifaddr *ifa6;
1859 /* invalid if we're not a v6 endpoint */
1860 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
1861 SCTP_INP_WUNLOCK(inp);
1864 /* is the v6 addr really valid ? */
1865 ifa6 = (struct in6_ifaddr *)ifa;
1866 if (IFA6_IS_DEPRECATED(ifa6) ||
1868 (IN6_IFF_DETACHED | IN6_IFF_ANYCAST | IN6_IFF_NOTREADY))) {
1869 /* can't use an invalid address */
1870 SCTP_INP_WUNLOCK(inp);
1873 } else if (ifa->ifa_addr->sa_family == AF_INET) {
1874 /* invalid if we are a v6 only endpoint */
1875 struct in6pcb *inp6;
1877 inp6 = (struct in6pcb *)&inp->ip_inp.inp;
1879 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
1880 (inp6->inp_flags & IN6P_IPV6_V6ONLY)
1882 SCTP_INP_WUNLOCK(inp);
1886 /* invalid address family */
1887 SCTP_INP_WUNLOCK(inp);
1890 /* is this endpoint subset bound ? */
1891 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
1892 /* subset bound endpoint */
1893 if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_ASCONF)) {
1895 * subset bound, but ASCONFs not allowed... if
1896 * adding, nothing to do, since not allowed if
1897 * deleting, remove address from endpoint peer will
1898 * have to "timeout" this addr
1900 if (type == SCTP_DEL_IP_ADDRESS) {
1901 sctp_del_local_addr_ep(inp, ifa);
1903 /* no asconfs to queue for this inp... */
1904 SCTP_INP_WUNLOCK(inp);
1908 * subset bound, ASCONFs allowed... if adding, add
1909 * address to endpoint list if deleting, remove
1910 * address from endpoint
1912 if (type == SCTP_ADD_IP_ADDRESS) {
1913 sctp_add_local_addr_ep(inp, ifa);
1915 sctp_del_local_addr_ep(inp, ifa);
1917 /* drop through and notify all asocs */
1921 /* process for all associations for this endpoint */
1922 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1923 SCTP_TCB_LOCK(stcb);
1924 sctp_addr_mgmt_assoc(inp, stcb, ifa, type);
1925 SCTP_TCB_UNLOCK(stcb);
1928 SCTP_INP_WUNLOCK(inp);
1932 * restrict the use of this address
1935 sctp_addr_mgmt_restrict_ep(struct sctp_inpcb *inp, struct ifaddr *ifa)
1937 struct sctp_tcb *stcb;
1940 /* is this endpoint bound to all? */
1941 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
1943 * Nothing to do for subset bound case. Allow sctp_bindx()
1944 * to manage the address lists
1949 SCTP_INP_RLOCK(inp);
1950 /* process for all associations for this endpoint */
1951 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
1952 /* put this address on the "pending/do not use yet" list */
1953 SCTP_TCB_LOCK(stcb);
1954 sctp_add_local_addr_assoc(stcb, ifa);
1955 SCTP_TCB_UNLOCK(stcb);
1958 SCTP_INP_RUNLOCK(inp);
1962 * this is only called for kernel initiated address changes eg. it will check
1963 * the PCB_FLAGS_AUTO_ASCONF flag
1966 sctp_addr_mgmt(struct ifaddr *ifa, uint16_t type)
1968 struct sockaddr *sa;
1969 struct sctp_inpcb *inp;
1971 /* make sure we care about this interface... */
1972 if (!sctp_is_desired_interface_type(ifa)) {
1976 if (sa->sa_family != AF_INET && sa->sa_family != AF_INET6)
1980 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
1981 if (type == SCTP_ADD_IP_ADDRESS)
1982 printf("sctp_addr_mgmt: kernel adds ");
1984 printf("sctp_addr_mgmt: kernel deletes ");
1985 sctp_print_address(sa);
1987 #endif /* SCTP_DEBUG */
1989 /* go through all our PCB's */
1990 LIST_FOREACH(inp, &sctppcbinfo.listhead, sctp_list) {
1991 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF)) {
1992 sctp_addr_mgmt_ep(inp, ifa, type);
1994 /* this address is going away anyways... */
1995 if (type == SCTP_DEL_IP_ADDRESS)
1997 /* (temporarily) restrict this address */
1998 sctp_addr_mgmt_restrict_ep(inp, ifa);
2000 /* else, not allowing automatic asconf's, so ignore */
2005 * add/delete IP address requests from kernel (via routing change) assumed
2006 * that the address is non-broadcast, non-multicast all addresses are passed
2007 * from any type of interface-- need to filter duplicate addresses may get
2012 sctp_add_ip_address(struct ifaddr *ifa)
2014 sctp_addr_mgmt(ifa, SCTP_ADD_IP_ADDRESS);
2018 sctp_delete_ip_address(struct ifaddr *ifa)
2020 struct sctp_inpcb *inp;
2022 /* process the delete */
2023 sctp_addr_mgmt(ifa, SCTP_DEL_IP_ADDRESS);
2026 * need to remove this ifaddr from any cached routes and also any
2027 * from any assoc "restricted/pending" lists
2029 /* make sure we care about this interface... */
2030 if (!sctp_is_desired_interface_type(ifa)) {
2033 /* go through all our PCB's */
2034 SCTP_INP_INFO_RLOCK();
2035 LIST_FOREACH(inp, &sctppcbinfo.listhead, sctp_list) {
2036 struct sctp_tcb *stcb;
2037 struct sctp_laddr *laddr, *laddr_next;
2039 /* process for all associations for this endpoint */
2040 SCTP_INP_RLOCK(inp);
2041 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
2042 struct sctp_nets *net;
2044 /* process through the nets list */
2045 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2048 /* delete this address if cached */
2050 if (rt != NULL && rt->rt_ifa == ifa) {
2052 net->ro.ro_rt = NULL;
2054 } /* for each net */
2055 /* process through the asoc "pending" list */
2056 laddr = LIST_FIRST(&stcb->asoc.sctp_local_addr_list);
2057 while (laddr != NULL) {
2058 laddr_next = LIST_NEXT(laddr, sctp_nxt_addr);
2059 /* remove if in use */
2060 if (laddr->ifa == ifa) {
2061 sctp_remove_laddr(laddr);
2065 } /* for each stcb */
2066 /* process through the inp bound addr list */
2067 laddr = LIST_FIRST(&inp->sctp_addr_list);
2068 while (laddr != NULL) {
2069 laddr_next = LIST_NEXT(laddr, sctp_nxt_addr);
2070 /* remove if in use */
2071 if (laddr->ifa == ifa) {
2072 sctp_remove_laddr(laddr);
2076 SCTP_INP_RUNLOCK(inp);
2078 SCTP_INP_INFO_RUNLOCK();
2082 * sa is the sockaddr to ask the peer to set primary to returns: 0 =
2083 * completed, -1 = error
2086 sctp_set_primary_ip_address_sa(struct sctp_tcb *stcb, struct sockaddr *sa)
2088 /* NOTE: we currently don't check the validity of the address! */
2090 /* queue an ASCONF:SET_PRIM_ADDR to be sent */
2091 if (!sctp_asconf_queue_add_sa(stcb, sa, SCTP_SET_PRIM_ADDR)) {
2092 /* set primary queuing succeeded */
2093 if (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) {
2094 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
2095 stcb->sctp_ep, stcb,
2096 stcb->asoc.primary_destination);
2099 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
2100 printf("set_primary_ip_address_sa: queued on tcb=%p, ",
2102 sctp_print_address(sa);
2104 #endif /* SCTP_DEBUG */
2107 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
2108 printf("set_primary_ip_address_sa: failed to add to queue on tcb=%p, ",
2110 sctp_print_address(sa);
2112 #endif /* SCTP_DEBUG */
2119 sctp_set_primary_ip_address(struct ifaddr *ifa)
2121 struct sctp_inpcb *inp;
2123 /* make sure we care about this interface... */
2124 if (!sctp_is_desired_interface_type(ifa)) {
2127 /* go through all our PCB's */
2128 LIST_FOREACH(inp, &sctppcbinfo.listhead, sctp_list) {
2129 struct sctp_tcb *stcb;
2131 /* process for all associations for this endpoint */
2132 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
2133 /* queue an ASCONF:SET_PRIM_ADDR to be sent */
2134 if (!sctp_asconf_queue_add(stcb, ifa,
2135 SCTP_SET_PRIM_ADDR)) {
2136 /* set primary queuing succeeded */
2137 if (SCTP_GET_STATE(&stcb->asoc) ==
2139 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
2140 stcb->sctp_ep, stcb,
2141 stcb->asoc.primary_destination);
2144 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
2145 printf("set_primary_ip_address: queued on stcb=%p, ",
2147 sctp_print_address(ifa->ifa_addr);
2149 #endif /* SCTP_DEBUG */
2151 } /* for each stcb */
2152 } /* for each inp */
2155 static struct sockaddr *
2156 sctp_find_valid_localaddr(struct sctp_tcb *stcb)
2162 TAILQ_FOREACH(ifn, &ifnet, if_list) {
2163 if (stcb->asoc.loopback_scope == 0 && ifn->if_type == IFT_LOOP) {
2164 /* Skip if loopback_scope not set */
2167 TAILQ_FOREACH(ifa, &ifn->if_addrlist, ifa_list) {
2168 if (ifa->ifa_addr->sa_family == AF_INET &&
2169 stcb->asoc.ipv4_addr_legal) {
2170 struct sockaddr_in *sin;
2172 sin = (struct sockaddr_in *)ifa->ifa_addr;
2173 if (sin->sin_addr.s_addr == 0) {
2174 /* skip unspecifed addresses */
2177 if (stcb->asoc.ipv4_local_scope == 0 &&
2178 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))
2181 if (sctp_is_addr_restricted(stcb,
2184 /* found a valid local v4 address to use */
2185 return (ifa->ifa_addr);
2186 } else if (ifa->ifa_addr->sa_family == AF_INET6 &&
2187 stcb->asoc.ipv6_addr_legal) {
2188 struct sockaddr_in6 *sin6;
2189 struct in6_ifaddr *ifa6;
2191 ifa6 = (struct in6_ifaddr *)ifa;
2192 if (IFA6_IS_DEPRECATED(ifa6) ||
2193 (ifa6->ia6_flags & (IN6_IFF_DETACHED |
2194 IN6_IFF_ANYCAST | IN6_IFF_NOTREADY)))
2197 sin6 = (struct sockaddr_in6 *)ifa->ifa_addr;
2198 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2199 /* we skip unspecifed addresses */
2202 if (stcb->asoc.local_scope == 0 &&
2203 IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))
2205 if (stcb->asoc.site_scope == 0 &&
2206 IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))
2209 /* found a valid local v6 address to use */
2210 return (ifa->ifa_addr);
2214 /* no valid addresses found */
2218 static struct sockaddr *
2219 sctp_find_valid_localaddr_ep(struct sctp_tcb *stcb)
2221 struct sctp_laddr *laddr;
2223 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
2224 if (laddr->ifa == NULL) {
2227 if (laddr->ifa->ifa_addr == NULL) {
2230 /* is the address restricted ? */
2231 if (sctp_is_addr_restricted(stcb, laddr->ifa->ifa_addr))
2234 /* found a valid local address to use */
2235 return (laddr->ifa->ifa_addr);
2237 /* no valid addresses found */
2242 * builds an ASCONF chunk from queued ASCONF params returns NULL on error (no
2243 * mbuf, no ASCONF params queued, etc)
2246 sctp_compose_asconf(struct sctp_tcb *stcb, int *retlen)
2248 struct mbuf *m_asconf, *m_asconf_chk;
2249 struct sctp_asconf_addr *aa;
2250 struct sctp_asconf_chunk *acp;
2251 struct sctp_asconf_paramhdr *aph;
2252 struct sctp_asconf_addr_param *aap;
2254 uint32_t correlation_id = 1; /* 0 is reserved... */
2255 caddr_t ptr, lookup_ptr;
2256 uint8_t lookup_used = 0;
2258 /* are there any asconf params to send? */
2259 if (TAILQ_EMPTY(&stcb->asoc.asconf_queue)) {
2263 * get a chunk header mbuf and a cluster for the asconf params since
2264 * it's simpler to fill in the asconf chunk header lookup address on
2267 m_asconf_chk = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_chunk), 0, M_DONTWAIT, 1, MT_DATA);
2268 if (m_asconf_chk == NULL) {
2271 if (sctp_debug_on & SCTP_DEBUG_ASCONF1)
2272 printf("compose_asconf: couldn't get chunk mbuf!\n");
2273 #endif /* SCTP_DEBUG */
2276 m_asconf = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_DONTWAIT, 1, MT_DATA);
2277 if (m_asconf == NULL) {
2280 if (sctp_debug_on & SCTP_DEBUG_ASCONF1)
2281 printf("compose_asconf: couldn't get mbuf!\n");
2282 #endif /* SCTP_DEBUG */
2283 sctp_m_freem(m_asconf_chk);
2286 SCTP_BUF_LEN(m_asconf_chk) = sizeof(struct sctp_asconf_chunk);
2287 SCTP_BUF_LEN(m_asconf) = 0;
2288 acp = mtod(m_asconf_chk, struct sctp_asconf_chunk *);
2289 bzero(acp, sizeof(struct sctp_asconf_chunk));
2290 /* save pointers to lookup address and asconf params */
2291 lookup_ptr = (caddr_t)(acp + 1); /* after the header */
2292 ptr = mtod(m_asconf, caddr_t); /* beginning of cluster */
2294 /* fill in chunk header info */
2295 acp->ch.chunk_type = SCTP_ASCONF;
2296 acp->ch.chunk_flags = 0;
2297 acp->serial_number = htonl(stcb->asoc.asconf_seq_out);
2299 /* add parameters... up to smallest MTU allowed */
2300 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
2301 /* get the parameter length */
2302 p_length = SCTP_SIZE32(aa->ap.aph.ph.param_length);
2303 /* will it fit in current chunk? */
2304 if (SCTP_BUF_LEN(m_asconf) + p_length > stcb->asoc.smallest_mtu) {
2305 /* won't fit, so we're done with this chunk */
2308 /* assign (and store) a correlation id */
2309 aa->ap.aph.correlation_id = correlation_id++;
2312 * fill in address if we're doing a delete this is a simple
2313 * way for us to fill in the correlation address, which
2314 * should only be used by the peer if we're deleting our
2315 * source address and adding a new address (e.g. renumbering
2318 if (lookup_used == 0 &&
2319 aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) {
2320 struct sctp_ipv6addr_param *lookup;
2321 uint16_t p_size, addr_size;
2323 lookup = (struct sctp_ipv6addr_param *)lookup_ptr;
2324 lookup->ph.param_type =
2325 htons(aa->ap.addrp.ph.param_type);
2326 if (aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) {
2327 /* copy IPv6 address */
2328 p_size = sizeof(struct sctp_ipv6addr_param);
2329 addr_size = sizeof(struct in6_addr);
2331 /* copy IPv4 address */
2332 p_size = sizeof(struct sctp_ipv4addr_param);
2333 addr_size = sizeof(struct in_addr);
2335 lookup->ph.param_length = htons(SCTP_SIZE32(p_size));
2336 memcpy(lookup->addr, &aa->ap.addrp.addr, addr_size);
2337 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size);
2340 /* copy into current space */
2341 memcpy(ptr, &aa->ap, p_length);
2343 /* network elements and update lengths */
2344 aph = (struct sctp_asconf_paramhdr *)ptr;
2345 aap = (struct sctp_asconf_addr_param *)ptr;
2346 /* correlation_id is transparent to peer, no htonl needed */
2347 aph->ph.param_type = htons(aph->ph.param_type);
2348 aph->ph.param_length = htons(aph->ph.param_length);
2349 aap->addrp.ph.param_type = htons(aap->addrp.ph.param_type);
2350 aap->addrp.ph.param_length = htons(aap->addrp.ph.param_length);
2352 SCTP_BUF_LEN(m_asconf) += SCTP_SIZE32(p_length);
2353 ptr += SCTP_SIZE32(p_length);
2356 * these params are removed off the pending list upon
2357 * getting an ASCONF-ACK back from the peer, just set flag
2361 /* check to see if the lookup addr has been populated yet */
2362 if (lookup_used == 0) {
2363 /* NOTE: if the address param is optional, can skip this... */
2364 /* add any valid (existing) address... */
2365 struct sctp_ipv6addr_param *lookup;
2366 uint16_t p_size, addr_size;
2367 struct sockaddr *found_addr;
2370 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL)
2371 found_addr = sctp_find_valid_localaddr(stcb);
2373 found_addr = sctp_find_valid_localaddr_ep(stcb);
2375 lookup = (struct sctp_ipv6addr_param *)lookup_ptr;
2376 if (found_addr != NULL) {
2377 if (found_addr->sa_family == AF_INET6) {
2378 /* copy IPv6 address */
2379 lookup->ph.param_type =
2380 htons(SCTP_IPV6_ADDRESS);
2381 p_size = sizeof(struct sctp_ipv6addr_param);
2382 addr_size = sizeof(struct in6_addr);
2383 addr_ptr = (caddr_t)&((struct sockaddr_in6 *)
2384 found_addr)->sin6_addr;
2386 /* copy IPv4 address */
2387 lookup->ph.param_type =
2388 htons(SCTP_IPV4_ADDRESS);
2389 p_size = sizeof(struct sctp_ipv4addr_param);
2390 addr_size = sizeof(struct in_addr);
2391 addr_ptr = (caddr_t)&((struct sockaddr_in *)
2392 found_addr)->sin_addr;
2394 lookup->ph.param_length = htons(SCTP_SIZE32(p_size));
2395 memcpy(lookup->addr, addr_ptr, addr_size);
2396 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size);
2399 /* uh oh... don't have any address?? */
2401 if (sctp_debug_on & SCTP_DEBUG_ASCONF1)
2402 printf("compose_asconf: no lookup addr!\n");
2403 #endif /* SCTP_DEBUG */
2404 /* for now, we send a IPv4 address of 0.0.0.0 */
2405 lookup->ph.param_type = htons(SCTP_IPV4_ADDRESS);
2406 lookup->ph.param_length = htons(SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param)));
2407 bzero(lookup->addr, sizeof(struct in_addr));
2408 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param));
2412 /* chain it all together */
2413 SCTP_BUF_NEXT(m_asconf_chk) = m_asconf;
2414 *retlen = acp->ch.chunk_length = ntohs(SCTP_BUF_LEN(m_asconf_chk) + SCTP_BUF_LEN(m_asconf));
2416 /* update "sent" flag */
2417 stcb->asoc.asconf_sent++;
2419 return (m_asconf_chk);
2423 * section to handle address changes before an association is up eg. changes
2424 * during INIT/INIT-ACK/COOKIE-ECHO handshake
2428 * processes the (local) addresses in the INIT-ACK chunk
2431 sctp_process_initack_addresses(struct sctp_tcb *stcb, struct mbuf *m,
2432 unsigned int offset, unsigned int length)
2434 struct sctp_paramhdr tmp_param, *ph;
2435 uint16_t plen, ptype;
2436 struct sctp_ipv6addr_param addr_store;
2437 struct sockaddr_in6 sin6;
2438 struct sockaddr_in sin;
2439 struct sockaddr *sa;
2443 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) {
2444 printf("processing init-ack addresses\n");
2446 #endif /* SCTP_DEBUG */
2448 /* convert to upper bound */
2451 if ((offset + sizeof(struct sctp_paramhdr)) > length) {
2454 /* init the addresses */
2455 bzero(&sin6, sizeof(sin6));
2456 sin6.sin6_family = AF_INET6;
2457 sin6.sin6_len = sizeof(sin6);
2458 sin6.sin6_port = stcb->rport;
2460 bzero(&sin, sizeof(sin));
2461 sin.sin_len = sizeof(sin);
2462 sin.sin_family = AF_INET;
2463 sin.sin_port = stcb->rport;
2465 /* go through the addresses in the init-ack */
2466 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset,
2467 sizeof(struct sctp_paramhdr), (uint8_t *) & tmp_param);
2468 while (ph != NULL) {
2469 ptype = ntohs(ph->param_type);
2470 plen = ntohs(ph->param_length);
2471 if (ptype == SCTP_IPV6_ADDRESS) {
2472 struct sctp_ipv6addr_param *a6p;
2474 /* get the entire IPv6 address param */
2475 a6p = (struct sctp_ipv6addr_param *)
2476 sctp_m_getptr(m, offset,
2477 sizeof(struct sctp_ipv6addr_param),
2478 (uint8_t *) & addr_store);
2479 if (plen != sizeof(struct sctp_ipv6addr_param) ||
2483 memcpy(&sin6.sin6_addr, a6p->addr,
2484 sizeof(struct in6_addr));
2485 sa = (struct sockaddr *)&sin6;
2486 } else if (ptype == SCTP_IPV4_ADDRESS) {
2487 struct sctp_ipv4addr_param *a4p;
2489 /* get the entire IPv4 address param */
2490 a4p = (struct sctp_ipv4addr_param *)sctp_m_getptr(m, offset, sizeof(struct sctp_ipv4addr_param), (uint8_t *) & addr_store);
2491 if (plen != sizeof(struct sctp_ipv4addr_param) ||
2495 sin.sin_addr.s_addr = a4p->addr;
2496 sa = (struct sockaddr *)&sin;
2501 /* see if this address really (still) exists */
2502 ifa = sctp_find_ifa_by_addr(sa);
2504 /* address doesn't exist anymore */
2507 /* are ASCONFs allowed ? */
2508 if ((sctp_is_feature_on(stcb->sctp_ep,
2509 SCTP_PCB_FLAGS_DO_ASCONF)) &&
2510 stcb->asoc.peer_supports_asconf) {
2511 /* queue an ASCONF DEL_IP_ADDRESS */
2512 status = sctp_asconf_queue_add_sa(stcb, sa,
2513 SCTP_DEL_IP_ADDRESS);
2515 * if queued ok, and in correct state, set
2519 SCTP_GET_STATE(&stcb->asoc) ==
2521 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
2522 stcb->sctp_ep, stcb,
2523 stcb->asoc.primary_destination);
2527 /* address still exists */
2529 * if subset bound, ep addr's managed by default if
2530 * not doing ASCONF, add the address to the assoc
2532 if ((stcb->sctp_ep->sctp_flags &
2533 SCTP_PCB_FLAGS_BOUNDALL) == 0 &&
2534 (sctp_is_feature_off(stcb->sctp_ep,
2535 SCTP_PCB_FLAGS_DO_ASCONF))) {
2537 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) {
2538 printf("process_initack_addrs: adding local addr to asoc\n");
2540 #endif /* SCTP_DEBUG */
2541 sctp_add_local_addr_assoc(stcb, ifa);
2547 * Sanity check: Make sure the length isn't 0, otherwise
2548 * we'll be stuck in this loop for a long time...
2550 if (SCTP_SIZE32(plen) == 0) {
2552 printf("process_initack_addrs: bad len (%d) type=%xh\n",
2557 /* get next parameter */
2558 offset += SCTP_SIZE32(plen);
2559 if ((offset + sizeof(struct sctp_paramhdr)) > length)
2561 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset,
2562 sizeof(struct sctp_paramhdr), (uint8_t *) & tmp_param);
2566 /* FIX ME: need to verify return result for v6 address type if v6 disabled */
2568 * checks to see if a specific address is in the initack address list returns
2569 * 1 if found, 0 if not
2572 sctp_addr_in_initack(struct sctp_tcb *stcb, struct mbuf *m, uint32_t offset,
2573 uint32_t length, struct sockaddr *sa)
2575 struct sctp_paramhdr tmp_param, *ph;
2576 uint16_t plen, ptype;
2577 struct sctp_ipv6addr_param addr_store;
2578 struct sockaddr_in *sin;
2579 struct sctp_ipv4addr_param *a4p;
2582 struct sockaddr_in6 *sin6, sin6_tmp;
2583 struct sctp_ipv6addr_param *a6p;
2589 (sa->sa_family != AF_INET6) &&
2591 (sa->sa_family != AF_INET))
2595 if (sctp_debug_on & SCTP_DEBUG_ASCONF2) {
2596 printf("find_initack_addr: starting search for ");
2597 sctp_print_address(sa);
2599 #endif /* SCTP_DEBUG */
2600 /* convert to upper bound */
2603 if ((offset + sizeof(struct sctp_paramhdr)) > length) {
2605 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
2606 printf("find_initack_addr: invalid offset?\n");
2608 #endif /* SCTP_DEBUG */
2611 /* go through the addresses in the init-ack */
2612 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset,
2613 sizeof(struct sctp_paramhdr), (uint8_t *) & tmp_param);
2614 while (ph != NULL) {
2615 ptype = ntohs(ph->param_type);
2616 plen = ntohs(ph->param_length);
2618 if (ptype == SCTP_IPV6_ADDRESS && sa->sa_family == AF_INET6) {
2619 /* get the entire IPv6 address param */
2620 a6p = (struct sctp_ipv6addr_param *)
2621 sctp_m_getptr(m, offset,
2622 sizeof(struct sctp_ipv6addr_param),
2623 (uint8_t *) & addr_store);
2624 if (plen != sizeof(struct sctp_ipv6addr_param) ||
2628 sin6 = (struct sockaddr_in6 *)sa;
2629 if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr)) {
2630 /* create a copy and clear scope */
2631 memcpy(&sin6_tmp, sin6,
2632 sizeof(struct sockaddr_in6));
2634 in6_clearscope(&sin6->sin6_addr);
2636 if (memcmp(&sin6->sin6_addr, a6p->addr,
2637 sizeof(struct in6_addr)) == 0) {
2644 if (ptype == SCTP_IPV4_ADDRESS &&
2645 sa->sa_family == AF_INET) {
2646 /* get the entire IPv4 address param */
2647 a4p = (struct sctp_ipv4addr_param *)sctp_m_getptr(m,
2648 offset, sizeof(struct sctp_ipv4addr_param),
2649 (uint8_t *) & addr_store);
2650 if (plen != sizeof(struct sctp_ipv4addr_param) ||
2654 sin = (struct sockaddr_in *)sa;
2655 if (sin->sin_addr.s_addr == a4p->addr) {
2660 /* get next parameter */
2661 offset += SCTP_SIZE32(plen);
2662 if (offset + sizeof(struct sctp_paramhdr) > length)
2664 ph = (struct sctp_paramhdr *)
2665 sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr),
2666 (uint8_t *) & tmp_param);
2673 * makes sure that the current endpoint local addr list is consistent with
2674 * the new association (eg. subset bound, asconf allowed) adds addresses as
2678 sctp_check_address_list_ep(struct sctp_tcb *stcb, struct mbuf *m, int offset,
2679 int length, struct sockaddr *init_addr)
2681 struct sctp_laddr *laddr;
2683 /* go through the endpoint list */
2684 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
2685 /* be paranoid and validate the laddr */
2686 if (laddr->ifa == NULL) {
2688 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
2689 printf("check_addr_list_ep: laddr->ifa is NULL");
2691 #endif /* SCTP_DEBUG */
2694 if (laddr->ifa->ifa_addr == NULL) {
2696 if (sctp_debug_on & SCTP_DEBUG_ASCONF1) {
2697 printf("check_addr_list_ep: laddr->ifa->ifa_addr is NULL");
2699 #endif /* SCTP_DEBUG */
2702 /* do i have it implicitly? */
2703 if (sctp_cmpaddr(laddr->ifa->ifa_addr, init_addr)) {
2706 /* check to see if in the init-ack */
2707 if (!sctp_addr_in_initack(stcb, m, offset, length,
2708 laddr->ifa->ifa_addr)) {
2710 sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb, laddr->ifa,
2711 SCTP_ADD_IP_ADDRESS);
2717 * makes sure that the current kernel address list is consistent with the new
2718 * association (with all addrs bound) adds addresses as necessary
2721 sctp_check_address_list_all(struct sctp_tcb *stcb, struct mbuf *m, int offset,
2722 int length, struct sockaddr *init_addr,
2723 uint16_t local_scope, uint16_t site_scope,
2724 uint16_t ipv4_scope, uint16_t loopback_scope)
2729 /* go through all our known interfaces */
2730 TAILQ_FOREACH(ifn, &ifnet, if_list) {
2731 if (loopback_scope == 0 && ifn->if_type == IFT_LOOP) {
2732 /* skip loopback interface */
2735 /* go through each interface address */
2736 TAILQ_FOREACH(ifa, &ifn->if_addrlist, ifa_list) {
2737 /* do i have it implicitly? */
2738 if (sctp_cmpaddr(ifa->ifa_addr, init_addr)) {
2741 /* check to see if in the init-ack */
2742 if (!sctp_addr_in_initack(stcb, m, offset, length,
2745 sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb,
2746 ifa, SCTP_ADD_IP_ADDRESS);
2748 } /* end foreach ifa */
2749 } /* end foreach ifn */
2753 * validates an init-ack chunk (from a cookie-echo) with current addresses
2754 * adds addresses from the init-ack into our local address list, if needed
2755 * queues asconf adds/deletes addresses as needed and makes appropriate list
2756 * changes for source address selection m, offset: points to the start of the
2757 * address list in an init-ack chunk length: total length of the address
2758 * params only init_addr: address where my INIT-ACK was sent from
2761 sctp_check_address_list(struct sctp_tcb *stcb, struct mbuf *m, int offset,
2762 int length, struct sockaddr *init_addr,
2763 uint16_t local_scope, uint16_t site_scope,
2764 uint16_t ipv4_scope, uint16_t loopback_scope)
2766 /* process the local addresses in the initack */
2767 sctp_process_initack_addresses(stcb, m, offset, length);
2769 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
2770 /* bound all case */
2771 sctp_check_address_list_all(stcb, m, offset, length, init_addr,
2772 local_scope, site_scope, ipv4_scope, loopback_scope);
2774 /* subset bound case */
2775 if (sctp_is_feature_on(stcb->sctp_ep,
2776 SCTP_PCB_FLAGS_DO_ASCONF)) {
2777 /* asconf's allowed */
2778 sctp_check_address_list_ep(stcb, m, offset, length,
2781 /* else, no asconfs allowed, so what we sent is what we get */
2786 * sctp_bindx() support
2789 sctp_addr_mgmt_ep_sa(struct sctp_inpcb *inp, struct sockaddr *sa, uint16_t type)
2794 if (sa->sa_len == 0)
2797 ifa = sctp_find_ifa_by_addr(sa);
2800 if (ifa->ifa_addr->sa_family == AF_INET6) {
2801 struct in6_ifaddr *ifa6;
2803 ifa6 = (struct in6_ifaddr *)ifa;
2804 if (IFA6_IS_DEPRECATED(ifa6) ||
2805 (ifa6->ia6_flags & (IN6_IFF_DETACHED |
2806 IN6_IFF_ANYCAST | IN6_IFF_NOTREADY))) {
2807 /* Can't bind a non-existent addr. */
2812 /* add this address */
2813 sctp_addr_mgmt_ep(inp, ifa, type);
2815 /* invalid address! */
2816 return (EADDRNOTAVAIL);
2822 sctp_addr_change(struct ifaddr *ifa, int cmd)
2824 struct sctp_laddr *wi;
2826 wi = (struct sctp_laddr *)SCTP_ZONE_GET(sctppcbinfo.ipi_zone_laddr);
2829 * Gak, what can we do? We have lost an address change can
2833 if (sctp_debug_on & SCTP_DEBUG_PCB1) {
2834 printf("Lost and address change ???\n");
2836 #endif /* SCTP_DEBUG */
2839 SCTP_INCR_LADDR_COUNT();
2840 bzero(wi, sizeof(*wi));
2845 SCTP_IPI_ADDR_LOCK();
2847 * Should this really be a tailq? As it is we will process the
2850 LIST_INSERT_HEAD(&sctppcbinfo.addr_wq, wi, sctp_nxt_addr);
2851 sctp_timer_start(SCTP_TIMER_TYPE_ADDR_WQ,
2852 (struct sctp_inpcb *)NULL,
2853 (struct sctp_tcb *)NULL,
2854 (struct sctp_nets *)NULL);
2855 SCTP_IPI_ADDR_UNLOCK();