2 * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
9 * a) Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
12 * b) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the distribution.
16 * c) Neither the name of Cisco Systems, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <netinet/sctp_os.h>
37 #include <netinet/sctp_var.h>
38 #include <netinet/sctp_sysctl.h>
39 #include <netinet/sctp_pcb.h>
40 #include <netinet/sctp_header.h>
41 #include <netinet/sctputil.h>
42 #include <netinet/sctp_output.h>
43 #include <netinet/sctp_asconf.h>
44 #include <netinet/sctp_timer.h>
48 * SCTP_DEBUG_ASCONF1: protocol info, general info and errors
49 * SCTP_DEBUG_ASCONF2: detailed info
52 #endif /* SCTP_DEBUG */
56 sctp_asconf_get_source_ip(struct mbuf *m, struct sockaddr *sa)
61 struct sockaddr_in *sin;
65 struct sockaddr_in6 *sin6;
69 iph = mtod(m, struct ip *);
75 sin = (struct sockaddr_in *)sa;
76 bzero(sin, sizeof(*sin));
77 sin->sin_family = AF_INET;
78 sin->sin_len = sizeof(struct sockaddr_in);
80 sin->sin_addr.s_addr = iph->ip_src.s_addr;
85 case (IPV6_VERSION >> 4):
90 sin6 = (struct sockaddr_in6 *)sa;
91 bzero(sin6, sizeof(*sin6));
92 sin6->sin6_family = AF_INET6;
93 sin6->sin6_len = sizeof(struct sockaddr_in6);
95 ip6 = mtod(m, struct ip6_hdr *);
96 sin6->sin6_addr = ip6->ip6_src;
107 * draft-ietf-tsvwg-addip-sctp
109 * An ASCONF parameter queue exists per asoc which holds the pending address
110 * operations. Lists are updated upon receipt of ASCONF-ACK.
112 * A restricted_addrs list exists per assoc to hold local addresses that are
113 * not (yet) usable by the assoc as a source address. These addresses are
114 * either pending an ASCONF operation (and exist on the ASCONF parameter
115 * queue), or they are permanently restricted (the peer has returned an
116 * ERROR indication to an ASCONF(ADD), or the peer does not support ASCONF).
118 * Deleted addresses are always immediately removed from the lists as they will
119 * (shortly) no longer exist in the kernel. We send ASCONFs as a courtesy,
124 * ASCONF parameter processing.
125 * response_required: set if a reply is required (eg. SUCCESS_REPORT).
126 * returns a mbuf to an "error" response parameter or NULL/"success" if ok.
127 * FIX: allocating this many mbufs on the fly is pretty inefficient...
130 sctp_asconf_success_response(uint32_t id)
132 struct mbuf *m_reply = NULL;
133 struct sctp_asconf_paramhdr *aph;
135 m_reply = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_paramhdr),
136 0, M_DONTWAIT, 1, MT_DATA);
137 if (m_reply == NULL) {
138 SCTPDBG(SCTP_DEBUG_ASCONF1,
139 "asconf_success_response: couldn't get mbuf!\n");
142 aph = mtod(m_reply, struct sctp_asconf_paramhdr *);
143 aph->correlation_id = id;
144 aph->ph.param_type = htons(SCTP_SUCCESS_REPORT);
145 aph->ph.param_length = sizeof(struct sctp_asconf_paramhdr);
146 SCTP_BUF_LEN(m_reply) = aph->ph.param_length;
147 aph->ph.param_length = htons(aph->ph.param_length);
153 sctp_asconf_error_response(uint32_t id, uint16_t cause, uint8_t * error_tlv,
156 struct mbuf *m_reply = NULL;
157 struct sctp_asconf_paramhdr *aph;
158 struct sctp_error_cause *error;
161 m_reply = sctp_get_mbuf_for_msg((sizeof(struct sctp_asconf_paramhdr) +
163 sizeof(struct sctp_error_cause)),
164 0, M_DONTWAIT, 1, MT_DATA);
165 if (m_reply == NULL) {
166 SCTPDBG(SCTP_DEBUG_ASCONF1,
167 "asconf_error_response: couldn't get mbuf!\n");
170 aph = mtod(m_reply, struct sctp_asconf_paramhdr *);
171 error = (struct sctp_error_cause *)(aph + 1);
173 aph->correlation_id = id;
174 aph->ph.param_type = htons(SCTP_ERROR_CAUSE_IND);
175 error->code = htons(cause);
176 error->length = tlv_length + sizeof(struct sctp_error_cause);
177 aph->ph.param_length = error->length +
178 sizeof(struct sctp_asconf_paramhdr);
180 if (aph->ph.param_length > MLEN) {
181 SCTPDBG(SCTP_DEBUG_ASCONF1,
182 "asconf_error_response: tlv_length (%xh) too big\n",
184 sctp_m_freem(m_reply); /* discard */
187 if (error_tlv != NULL) {
188 tlv = (uint8_t *) (error + 1);
189 memcpy(tlv, error_tlv, tlv_length);
191 SCTP_BUF_LEN(m_reply) = aph->ph.param_length;
192 error->length = htons(error->length);
193 aph->ph.param_length = htons(aph->ph.param_length);
199 sctp_process_asconf_add_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph,
200 struct sctp_tcb *stcb, int send_hb, int response_required)
202 struct sctp_nets *net;
203 struct mbuf *m_reply = NULL;
204 struct sockaddr_storage sa_source, sa_store;
205 struct sctp_paramhdr *ph;
206 uint16_t param_type, param_length, aparam_length;
208 int zero_address = 0;
212 struct sockaddr_in *sin;
213 struct sctp_ipv4addr_param *v4addr;
217 struct sockaddr_in6 *sin6;
218 struct sctp_ipv6addr_param *v6addr;
222 aparam_length = ntohs(aph->ph.param_length);
223 ph = (struct sctp_paramhdr *)(aph + 1);
224 param_type = ntohs(ph->param_type);
225 param_length = ntohs(ph->param_length);
227 sa = (struct sockaddr *)&sa_store;
228 switch (param_type) {
230 case SCTP_IPV4_ADDRESS:
231 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
232 /* invalid param size */
235 v4addr = (struct sctp_ipv4addr_param *)ph;
236 sin = (struct sockaddr_in *)&sa_store;
237 bzero(sin, sizeof(*sin));
238 sin->sin_family = AF_INET;
239 sin->sin_len = sizeof(struct sockaddr_in);
240 sin->sin_port = stcb->rport;
241 sin->sin_addr.s_addr = v4addr->addr;
242 if ((sin->sin_addr.s_addr == INADDR_BROADCAST) ||
243 IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) {
246 if (sin->sin_addr.s_addr == INADDR_ANY)
248 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_add_ip: adding ");
249 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
253 case SCTP_IPV6_ADDRESS:
254 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
255 /* invalid param size */
258 v6addr = (struct sctp_ipv6addr_param *)ph;
259 sin6 = (struct sockaddr_in6 *)&sa_store;
260 bzero(sin6, sizeof(*sin6));
261 sin6->sin6_family = AF_INET6;
262 sin6->sin6_len = sizeof(struct sockaddr_in6);
263 sin6->sin6_port = stcb->rport;
264 memcpy((caddr_t)&sin6->sin6_addr, v6addr->addr,
265 sizeof(struct in6_addr));
266 if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
269 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
271 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_add_ip: adding ");
272 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
276 m_reply = sctp_asconf_error_response(aph->correlation_id,
277 SCTP_CAUSE_INVALID_PARAM, (uint8_t *) aph,
282 /* if 0.0.0.0/::0, add the source address instead */
283 if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) {
284 sa = (struct sockaddr *)&sa_source;
285 sctp_asconf_get_source_ip(m, sa);
286 SCTPDBG(SCTP_DEBUG_ASCONF1,
287 "process_asconf_add_ip: using source addr ");
288 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
290 /* add the address */
292 m_reply = sctp_asconf_error_response(aph->correlation_id,
293 SCTP_CAUSE_INVALID_PARAM, (uint8_t *) aph,
295 } else if (sctp_add_remote_addr(stcb, sa, &net, SCTP_DONOT_SETSCOPE,
296 SCTP_ADDR_DYNAMIC_ADDED) != 0) {
297 SCTPDBG(SCTP_DEBUG_ASCONF1,
298 "process_asconf_add_ip: error adding address\n");
299 m_reply = sctp_asconf_error_response(aph->correlation_id,
300 SCTP_CAUSE_RESOURCE_SHORTAGE, (uint8_t *) aph,
303 /* notify upper layer */
304 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_ADD_IP, stcb, 0, sa, SCTP_SO_NOT_LOCKED);
305 if (response_required) {
307 sctp_asconf_success_response(aph->correlation_id);
309 sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, stcb->sctp_ep, stcb, net);
310 sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep,
313 sctp_send_hb(stcb, net, SCTP_SO_NOT_LOCKED);
320 sctp_asconf_del_remote_addrs_except(struct sctp_tcb *stcb, struct sockaddr *src)
322 struct sctp_nets *src_net, *net;
324 /* make sure the source address exists as a destination net */
325 src_net = sctp_findnet(stcb, src);
326 if (src_net == NULL) {
330 /* delete all destination addresses except the source */
331 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
332 if (net != src_net) {
333 /* delete this address */
334 sctp_remove_net(stcb, net);
335 SCTPDBG(SCTP_DEBUG_ASCONF1,
336 "asconf_del_remote_addrs_except: deleting ");
337 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1,
338 (struct sockaddr *)&net->ro._l_addr);
339 /* notify upper layer */
340 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0,
341 (struct sockaddr *)&net->ro._l_addr, SCTP_SO_NOT_LOCKED);
348 sctp_process_asconf_delete_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph,
349 struct sctp_tcb *stcb, int response_required)
351 struct mbuf *m_reply = NULL;
352 struct sockaddr_storage sa_source, sa_store;
353 struct sctp_paramhdr *ph;
354 uint16_t param_type, param_length, aparam_length;
356 int zero_address = 0;
360 struct sockaddr_in *sin;
361 struct sctp_ipv4addr_param *v4addr;
365 struct sockaddr_in6 *sin6;
366 struct sctp_ipv6addr_param *v6addr;
370 /* get the source IP address for src and 0.0.0.0/::0 delete checks */
371 sctp_asconf_get_source_ip(m, (struct sockaddr *)&sa_source);
373 aparam_length = ntohs(aph->ph.param_length);
374 ph = (struct sctp_paramhdr *)(aph + 1);
375 param_type = ntohs(ph->param_type);
376 param_length = ntohs(ph->param_length);
378 sa = (struct sockaddr *)&sa_store;
379 switch (param_type) {
381 case SCTP_IPV4_ADDRESS:
382 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
383 /* invalid param size */
386 v4addr = (struct sctp_ipv4addr_param *)ph;
387 sin = (struct sockaddr_in *)&sa_store;
388 bzero(sin, sizeof(*sin));
389 sin->sin_family = AF_INET;
390 sin->sin_len = sizeof(struct sockaddr_in);
391 sin->sin_port = stcb->rport;
392 sin->sin_addr.s_addr = v4addr->addr;
393 if (sin->sin_addr.s_addr == INADDR_ANY)
395 SCTPDBG(SCTP_DEBUG_ASCONF1,
396 "process_asconf_delete_ip: deleting ");
397 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
401 case SCTP_IPV6_ADDRESS:
402 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
403 /* invalid param size */
406 v6addr = (struct sctp_ipv6addr_param *)ph;
407 sin6 = (struct sockaddr_in6 *)&sa_store;
408 bzero(sin6, sizeof(*sin6));
409 sin6->sin6_family = AF_INET6;
410 sin6->sin6_len = sizeof(struct sockaddr_in6);
411 sin6->sin6_port = stcb->rport;
412 memcpy(&sin6->sin6_addr, v6addr->addr,
413 sizeof(struct in6_addr));
414 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
416 SCTPDBG(SCTP_DEBUG_ASCONF1,
417 "process_asconf_delete_ip: deleting ");
418 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
422 m_reply = sctp_asconf_error_response(aph->correlation_id,
423 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph,
428 /* make sure the source address is not being deleted */
429 if (sctp_cmpaddr(sa, (struct sockaddr *)&sa_source)) {
430 /* trying to delete the source address! */
431 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: tried to delete source addr\n");
432 m_reply = sctp_asconf_error_response(aph->correlation_id,
433 SCTP_CAUSE_DELETING_SRC_ADDR, (uint8_t *) aph,
437 /* if deleting 0.0.0.0/::0, delete all addresses except src addr */
438 if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) {
439 result = sctp_asconf_del_remote_addrs_except(stcb,
440 (struct sockaddr *)&sa_source);
443 /* src address did not exist? */
444 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: src addr does not exist?\n");
445 /* what error to reply with?? */
447 sctp_asconf_error_response(aph->correlation_id,
448 SCTP_CAUSE_REQUEST_REFUSED, (uint8_t *) aph,
450 } else if (response_required) {
452 sctp_asconf_success_response(aph->correlation_id);
456 /* delete the address */
457 result = sctp_del_remote_addr(stcb, sa);
459 * note if result == -2, the address doesn't exist in the asoc but
460 * since it's being deleted anyways, we just ack the delete -- but
461 * this probably means something has already gone awry
464 /* only one address in the asoc */
465 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: tried to delete last IP addr!\n");
466 m_reply = sctp_asconf_error_response(aph->correlation_id,
467 SCTP_CAUSE_DELETING_LAST_ADDR, (uint8_t *) aph,
470 if (response_required) {
471 m_reply = sctp_asconf_success_response(aph->correlation_id);
473 /* notify upper layer */
474 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0, sa, SCTP_SO_NOT_LOCKED);
480 sctp_process_asconf_set_primary(struct mbuf *m,
481 struct sctp_asconf_paramhdr *aph,
482 struct sctp_tcb *stcb, int response_required)
484 struct mbuf *m_reply = NULL;
485 struct sockaddr_storage sa_source, sa_store;
486 struct sctp_paramhdr *ph;
487 uint16_t param_type, param_length, aparam_length;
489 int zero_address = 0;
492 struct sockaddr_in *sin;
493 struct sctp_ipv4addr_param *v4addr;
497 struct sockaddr_in6 *sin6;
498 struct sctp_ipv6addr_param *v6addr;
502 aparam_length = ntohs(aph->ph.param_length);
503 ph = (struct sctp_paramhdr *)(aph + 1);
504 param_type = ntohs(ph->param_type);
505 param_length = ntohs(ph->param_length);
507 sa = (struct sockaddr *)&sa_store;
508 switch (param_type) {
510 case SCTP_IPV4_ADDRESS:
511 if (param_length != sizeof(struct sctp_ipv4addr_param)) {
512 /* invalid param size */
515 v4addr = (struct sctp_ipv4addr_param *)ph;
516 sin = (struct sockaddr_in *)&sa_store;
517 bzero(sin, sizeof(*sin));
518 sin->sin_family = AF_INET;
519 sin->sin_len = sizeof(struct sockaddr_in);
520 sin->sin_addr.s_addr = v4addr->addr;
521 if (sin->sin_addr.s_addr == INADDR_ANY)
523 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_set_primary: ");
524 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
528 case SCTP_IPV6_ADDRESS:
529 if (param_length != sizeof(struct sctp_ipv6addr_param)) {
530 /* invalid param size */
533 v6addr = (struct sctp_ipv6addr_param *)ph;
534 sin6 = (struct sockaddr_in6 *)&sa_store;
535 bzero(sin6, sizeof(*sin6));
536 sin6->sin6_family = AF_INET6;
537 sin6->sin6_len = sizeof(struct sockaddr_in6);
538 memcpy((caddr_t)&sin6->sin6_addr, v6addr->addr,
539 sizeof(struct in6_addr));
540 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
542 SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_set_primary: ");
543 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
547 m_reply = sctp_asconf_error_response(aph->correlation_id,
548 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph,
553 /* if 0.0.0.0/::0, use the source address instead */
554 if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) {
555 sa = (struct sockaddr *)&sa_source;
556 sctp_asconf_get_source_ip(m, sa);
557 SCTPDBG(SCTP_DEBUG_ASCONF1,
558 "process_asconf_set_primary: using source addr ");
559 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
561 /* set the primary address */
562 if (sctp_set_primary_addr(stcb, sa, NULL) == 0) {
563 SCTPDBG(SCTP_DEBUG_ASCONF1,
564 "process_asconf_set_primary: primary address set\n");
565 /* notify upper layer */
566 sctp_ulp_notify(SCTP_NOTIFY_ASCONF_SET_PRIMARY, stcb, 0, sa, SCTP_SO_NOT_LOCKED);
567 if ((stcb->asoc.primary_destination->dest_state & SCTP_ADDR_REACHABLE) &&
568 (!(stcb->asoc.primary_destination->dest_state & SCTP_ADDR_PF)) &&
569 (stcb->asoc.alternate)) {
570 sctp_free_remote_addr(stcb->asoc.alternate);
571 stcb->asoc.alternate = NULL;
573 if (response_required) {
574 m_reply = sctp_asconf_success_response(aph->correlation_id);
577 * Mobility adaptation. Ideally, when the reception of SET
578 * PRIMARY with DELETE IP ADDRESS of the previous primary
579 * destination, unacknowledged DATA are retransmitted
580 * immediately to the new primary destination for seamless
581 * handover. If the destination is UNCONFIRMED and marked to
582 * REQ_PRIM, The retransmission occur when reception of the
583 * HEARTBEAT-ACK. (See sctp_handle_heartbeat_ack in
584 * sctp_input.c) Also, when change of the primary
585 * destination, it is better that all subsequent new DATA
586 * containing already queued DATA are transmitted to the new
587 * primary destination. (by micchie)
589 if ((sctp_is_mobility_feature_on(stcb->sctp_ep,
590 SCTP_MOBILITY_BASE) ||
591 sctp_is_mobility_feature_on(stcb->sctp_ep,
592 SCTP_MOBILITY_FASTHANDOFF)) &&
593 sctp_is_mobility_feature_on(stcb->sctp_ep,
594 SCTP_MOBILITY_PRIM_DELETED) &&
595 (stcb->asoc.primary_destination->dest_state &
596 SCTP_ADDR_UNCONFIRMED) == 0) {
598 sctp_timer_stop(SCTP_TIMER_TYPE_PRIM_DELETED, stcb->sctp_ep, stcb, NULL, SCTP_FROM_SCTP_TIMER + SCTP_LOC_7);
599 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
600 SCTP_MOBILITY_FASTHANDOFF)) {
601 sctp_assoc_immediate_retrans(stcb,
602 stcb->asoc.primary_destination);
604 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
605 SCTP_MOBILITY_BASE)) {
606 sctp_move_chunks_from_net(stcb,
607 stcb->asoc.deleted_primary);
609 sctp_delete_prim_timer(stcb->sctp_ep, stcb,
610 stcb->asoc.deleted_primary);
613 /* couldn't set the requested primary address! */
614 SCTPDBG(SCTP_DEBUG_ASCONF1,
615 "process_asconf_set_primary: set primary failed!\n");
616 /* must have been an invalid address, so report */
617 m_reply = sctp_asconf_error_response(aph->correlation_id,
618 SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph,
626 * handles an ASCONF chunk.
627 * if all parameters are processed ok, send a plain (empty) ASCONF-ACK
630 sctp_handle_asconf(struct mbuf *m, unsigned int offset,
631 struct sctp_asconf_chunk *cp, struct sctp_tcb *stcb,
634 struct sctp_association *asoc;
636 struct mbuf *n, *m_ack, *m_result, *m_tail;
637 struct sctp_asconf_ack_chunk *ack_cp;
638 struct sctp_asconf_paramhdr *aph, *ack_aph;
639 struct sctp_ipv6addr_param *p_addr;
640 unsigned int asconf_limit, cnt;
641 int error = 0; /* did an error occur? */
643 /* asconf param buffer */
644 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE];
645 struct sctp_asconf_ack *ack, *ack_next;
647 /* verify minimum length */
648 if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_chunk)) {
649 SCTPDBG(SCTP_DEBUG_ASCONF1,
650 "handle_asconf: chunk too small = %xh\n",
651 ntohs(cp->ch.chunk_length));
655 serial_num = ntohl(cp->serial_number);
657 if (SCTP_TSN_GE(asoc->asconf_seq_in, serial_num)) {
658 /* got a duplicate ASCONF */
659 SCTPDBG(SCTP_DEBUG_ASCONF1,
660 "handle_asconf: got duplicate serial number = %xh\n",
663 } else if (serial_num != (asoc->asconf_seq_in + 1)) {
664 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: incorrect serial number = %xh (expected next = %xh)\n",
665 serial_num, asoc->asconf_seq_in + 1);
668 /* it's the expected "next" sequence number, so process it */
669 asoc->asconf_seq_in = serial_num; /* update sequence */
670 /* get length of all the param's in the ASCONF */
671 asconf_limit = offset + ntohs(cp->ch.chunk_length);
672 SCTPDBG(SCTP_DEBUG_ASCONF1,
673 "handle_asconf: asconf_limit=%u, sequence=%xh\n",
674 asconf_limit, serial_num);
677 /* delete old cache */
678 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: Now processing first ASCONF. Try to delete old cache\n");
680 TAILQ_FOREACH_SAFE(ack, &asoc->asconf_ack_sent, next, ack_next) {
681 if (ack->serial_number == serial_num)
683 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: delete old(%u) < first(%u)\n",
684 ack->serial_number, serial_num);
685 TAILQ_REMOVE(&asoc->asconf_ack_sent, ack, next);
686 if (ack->data != NULL) {
687 sctp_m_freem(ack->data);
689 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_asconf_ack), ack);
692 m_ack = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_ack_chunk), 0,
693 M_DONTWAIT, 1, MT_DATA);
695 SCTPDBG(SCTP_DEBUG_ASCONF1,
696 "handle_asconf: couldn't get mbuf!\n");
699 m_tail = m_ack; /* current reply chain's tail */
701 /* fill in ASCONF-ACK header */
702 ack_cp = mtod(m_ack, struct sctp_asconf_ack_chunk *);
703 ack_cp->ch.chunk_type = SCTP_ASCONF_ACK;
704 ack_cp->ch.chunk_flags = 0;
705 ack_cp->serial_number = htonl(serial_num);
706 /* set initial lengths (eg. just an ASCONF-ACK), ntohx at the end! */
707 SCTP_BUF_LEN(m_ack) = sizeof(struct sctp_asconf_ack_chunk);
708 ack_cp->ch.chunk_length = sizeof(struct sctp_asconf_ack_chunk);
710 /* skip the lookup address parameter */
711 offset += sizeof(struct sctp_asconf_chunk);
712 p_addr = (struct sctp_ipv6addr_param *)sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), (uint8_t *) & aparam_buf);
713 if (p_addr == NULL) {
714 SCTPDBG(SCTP_DEBUG_ASCONF1,
715 "handle_asconf: couldn't get lookup addr!\n");
716 /* respond with a missing/invalid mandatory parameter error */
719 /* param_length is already validated in process_control... */
720 offset += ntohs(p_addr->ph.param_length); /* skip lookup addr */
722 /* get pointer to first asconf param in ASCONF-ACK */
723 ack_aph = (struct sctp_asconf_paramhdr *)(mtod(m_ack, caddr_t)+sizeof(struct sctp_asconf_ack_chunk));
724 if (ack_aph == NULL) {
725 SCTPDBG(SCTP_DEBUG_ASCONF1, "Gak in asconf2\n");
728 /* get pointer to first asconf param in ASCONF */
729 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, sizeof(struct sctp_asconf_paramhdr), (uint8_t *) & aparam_buf);
731 SCTPDBG(SCTP_DEBUG_ASCONF1, "Empty ASCONF received?\n");
734 /* process through all parameters */
736 while (aph != NULL) {
737 unsigned int param_length, param_type;
739 param_type = ntohs(aph->ph.param_type);
740 param_length = ntohs(aph->ph.param_length);
741 if (offset + param_length > asconf_limit) {
742 /* parameter goes beyond end of chunk! */
748 if (param_length > sizeof(aparam_buf)) {
749 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) larger than buffer size!\n", param_length);
753 if (param_length <= sizeof(struct sctp_paramhdr)) {
754 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) too short\n", param_length);
757 /* get the entire parameter */
758 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf);
760 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: couldn't get entire param\n");
764 switch (param_type) {
765 case SCTP_ADD_IP_ADDRESS:
766 asoc->peer_supports_asconf = 1;
767 m_result = sctp_process_asconf_add_ip(m, aph, stcb,
768 (cnt < SCTP_BASE_SYSCTL(sctp_hb_maxburst)), error);
771 case SCTP_DEL_IP_ADDRESS:
772 asoc->peer_supports_asconf = 1;
773 m_result = sctp_process_asconf_delete_ip(m, aph, stcb,
776 case SCTP_ERROR_CAUSE_IND:
777 /* not valid in an ASCONF chunk */
779 case SCTP_SET_PRIM_ADDR:
780 asoc->peer_supports_asconf = 1;
781 m_result = sctp_process_asconf_set_primary(m, aph,
785 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: sees a NAT VTAG state parameter\n");
787 case SCTP_SUCCESS_REPORT:
788 /* not valid in an ASCONF chunk */
790 case SCTP_ULP_ADAPTATION:
794 if ((param_type & 0x8000) == 0) {
795 /* Been told to STOP at this param */
796 asconf_limit = offset;
798 * FIX FIX - We need to call
799 * sctp_arethere_unrecognized_parameters()
800 * to get a operr and send it for any
801 * param's with the 0x4000 bit set OR do it
802 * here ourselves... note we still must STOP
803 * if the 0x8000 bit is clear.
806 /* unknown/invalid param type */
810 /* add any (error) result to the reply mbuf chain */
811 if (m_result != NULL) {
812 SCTP_BUF_NEXT(m_tail) = m_result;
814 /* update lengths, make sure it's aligned too */
815 SCTP_BUF_LEN(m_result) = SCTP_SIZE32(SCTP_BUF_LEN(m_result));
816 ack_cp->ch.chunk_length += SCTP_BUF_LEN(m_result);
817 /* set flag to force success reports */
820 offset += SCTP_SIZE32(param_length);
821 /* update remaining ASCONF message length to process */
822 if (offset >= asconf_limit) {
823 /* no more data in the mbuf chain */
826 /* get pointer to next asconf param */
827 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset,
828 sizeof(struct sctp_asconf_paramhdr),
829 (uint8_t *) & aparam_buf);
831 /* can't get an asconf paramhdr */
832 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: can't get asconf param hdr!\n");
833 /* FIX ME - add error here... */
838 ack_cp->ch.chunk_length = htons(ack_cp->ch.chunk_length);
839 /* save the ASCONF-ACK reply */
840 ack = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_asconf_ack),
841 struct sctp_asconf_ack);
846 ack->serial_number = serial_num;
847 ack->last_sent_to = NULL;
850 for (n = m_ack; n != NULL; n = SCTP_BUF_NEXT(n)) {
851 ack->len += SCTP_BUF_LEN(n);
853 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_ack_sent, ack, next);
855 /* see if last_control_chunk_from is set properly (use IP src addr) */
856 if (stcb->asoc.last_control_chunk_from == NULL) {
858 * this could happen if the source address was just newly
863 struct sockaddr_storage from_store;
864 struct sockaddr *from = (struct sockaddr *)&from_store;
866 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: looking up net for IP source address\n");
867 /* pullup already done, IP options already stripped */
868 iph = mtod(m, struct ip *);
873 struct sockaddr_in *from4;
875 sh = (struct sctphdr *)((caddr_t)iph + sizeof(*iph));
876 from4 = (struct sockaddr_in *)&from_store;
877 bzero(from4, sizeof(*from4));
878 from4->sin_family = AF_INET;
879 from4->sin_len = sizeof(struct sockaddr_in);
880 from4->sin_addr.s_addr = iph->ip_src.s_addr;
881 from4->sin_port = sh->src_port;
886 case IPV6_VERSION >> 4:
889 struct sockaddr_in6 *from6;
891 ip6 = mtod(m, struct ip6_hdr *);
892 sh = (struct sctphdr *)((caddr_t)ip6 + sizeof(*ip6));
893 from6 = (struct sockaddr_in6 *)&from_store;
894 bzero(from6, sizeof(*from6));
895 from6->sin6_family = AF_INET6;
896 from6->sin6_len = sizeof(struct sockaddr_in6);
897 from6->sin6_addr = ip6->ip6_src;
898 from6->sin6_port = sh->src_port;
900 * Get the scopes in properly to the sin6
903 /* we probably don't need these operations */
904 (void)sa6_recoverscope(from6);
905 sa6_embedscope(from6,
906 MODULE_GLOBAL(ip6_use_defzone));
912 /* unknown address type */
916 SCTPDBG(SCTP_DEBUG_ASCONF1, "Looking for IP source: ");
917 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, from);
918 /* look up the from address */
919 stcb->asoc.last_control_chunk_from = sctp_findnet(stcb, from);
921 if (stcb->asoc.last_control_chunk_from == NULL)
922 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: IP source address not found?!\n");
929 * does the address match? returns 0 if not, 1 if so
932 sctp_asconf_addr_match(struct sctp_asconf_addr *aa, struct sockaddr *sa)
934 switch (sa->sa_family) {
939 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
941 if ((aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) &&
942 (memcmp(&aa->ap.addrp.addr, &sin6->sin6_addr,
943 sizeof(struct in6_addr)) == 0)) {
952 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
954 if ((aa->ap.addrp.ph.param_type == SCTP_IPV4_ADDRESS) &&
955 (memcmp(&aa->ap.addrp.addr, &sin->sin_addr,
956 sizeof(struct in_addr)) == 0)) {
969 * does the address match? returns 0 if not, 1 if so
972 sctp_addr_match(struct sctp_paramhdr *ph, struct sockaddr *sa)
974 uint16_t param_type, param_length;
976 param_type = ntohs(ph->param_type);
977 param_length = ntohs(ph->param_length);
978 switch (sa->sa_family) {
983 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
984 struct sctp_ipv6addr_param *v6addr;
986 v6addr = (struct sctp_ipv6addr_param *)ph;
987 if ((param_type == SCTP_IPV6_ADDRESS) &&
988 param_length == sizeof(struct sctp_ipv6addr_param) &&
989 (memcmp(&v6addr->addr, &sin6->sin6_addr,
990 sizeof(struct in6_addr)) == 0)) {
999 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
1000 struct sctp_ipv4addr_param *v4addr;
1002 v4addr = (struct sctp_ipv4addr_param *)ph;
1003 if ((param_type == SCTP_IPV4_ADDRESS) &&
1004 param_length == sizeof(struct sctp_ipv4addr_param) &&
1005 (memcmp(&v4addr->addr, &sin->sin_addr,
1006 sizeof(struct in_addr)) == 0)) {
1019 * Cleanup for non-responded/OP ERR'd ASCONF
1022 sctp_asconf_cleanup(struct sctp_tcb *stcb, struct sctp_nets *net)
1024 /* mark peer as ASCONF incapable */
1025 stcb->asoc.peer_supports_asconf = 0;
1027 * clear out any existing asconfs going out
1029 sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, net,
1030 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_2);
1031 stcb->asoc.asconf_seq_out_acked = stcb->asoc.asconf_seq_out;
1032 /* remove the old ASCONF on our outbound queue */
1033 sctp_toss_old_asconf(stcb);
1037 * cleanup any cached source addresses that may be topologically
1038 * incorrect after a new address has been added to this interface.
1041 sctp_asconf_nets_cleanup(struct sctp_tcb *stcb, struct sctp_ifn *ifn)
1043 struct sctp_nets *net;
1046 * Ideally, we want to only clear cached routes and source addresses
1047 * that are topologically incorrect. But since there is no easy way
1048 * to know whether the newly added address on the ifn would cause a
1049 * routing change (i.e. a new egress interface would be chosen)
1050 * without doing a new routing lookup and source address selection,
1051 * we will (for now) just flush any cached route using a different
1052 * ifn (and cached source addrs) and let output re-choose them
1053 * during the next send on that net.
1055 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1057 * clear any cached route (and cached source address) if the
1058 * route's interface is NOT the same as the address change.
1059 * If it's the same interface, just clear the cached source
1062 if (SCTP_ROUTE_HAS_VALID_IFN(&net->ro) &&
1064 (SCTP_GET_IF_INDEX_FROM_ROUTE(&net->ro) != ifn->ifn_index))) {
1065 /* clear any cached route */
1066 RTFREE(net->ro.ro_rt);
1067 net->ro.ro_rt = NULL;
1069 /* clear any cached source address */
1070 if (net->src_addr_selected) {
1071 sctp_free_ifa(net->ro._s_addr);
1072 net->ro._s_addr = NULL;
1073 net->src_addr_selected = 0;
1080 sctp_assoc_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *dstnet)
1084 if (dstnet->dest_state & SCTP_ADDR_UNCONFIRMED) {
1087 if (stcb->asoc.deleted_primary == NULL) {
1090 if (!TAILQ_EMPTY(&stcb->asoc.sent_queue)) {
1091 SCTPDBG(SCTP_DEBUG_ASCONF1, "assoc_immediate_retrans: Deleted primary is ");
1092 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &stcb->asoc.deleted_primary->ro._l_addr.sa);
1093 SCTPDBG(SCTP_DEBUG_ASCONF1, "Current Primary is ");
1094 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &stcb->asoc.primary_destination->ro._l_addr.sa);
1095 sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb,
1096 stcb->asoc.deleted_primary,
1097 SCTP_FROM_SCTP_TIMER + SCTP_LOC_8);
1098 stcb->asoc.num_send_timers_up--;
1099 if (stcb->asoc.num_send_timers_up < 0) {
1100 stcb->asoc.num_send_timers_up = 0;
1102 SCTP_TCB_LOCK_ASSERT(stcb);
1103 error = sctp_t3rxt_timer(stcb->sctp_ep, stcb,
1104 stcb->asoc.deleted_primary);
1106 SCTP_INP_DECR_REF(stcb->sctp_ep);
1109 SCTP_TCB_LOCK_ASSERT(stcb);
1110 #ifdef SCTP_AUDITING_ENABLED
1111 sctp_auditing(4, stcb->sctp_ep, stcb, stcb->asoc.deleted_primary);
1113 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED);
1114 if ((stcb->asoc.num_send_timers_up == 0) &&
1115 (stcb->asoc.sent_queue_cnt > 0)) {
1116 struct sctp_tmit_chunk *chk;
1118 chk = TAILQ_FIRST(&stcb->asoc.sent_queue);
1119 sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep,
1127 sctp_asconf_queue_mgmt(struct sctp_tcb *, struct sctp_ifa *, uint16_t);
1130 sctp_net_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *net)
1132 struct sctp_tmit_chunk *chk;
1134 SCTPDBG(SCTP_DEBUG_ASCONF1, "net_immediate_retrans: RTO is %d\n", net->RTO);
1135 sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, net,
1136 SCTP_FROM_SCTP_TIMER + SCTP_LOC_5);
1137 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
1138 net->error_count = 0;
1139 TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
1140 if (chk->whoTo == net) {
1141 if (chk->sent < SCTP_DATAGRAM_RESEND) {
1142 chk->sent = SCTP_DATAGRAM_RESEND;
1143 sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
1144 sctp_flight_size_decrease(chk);
1145 sctp_total_flight_decrease(stcb, chk);
1146 net->marked_retrans++;
1147 stcb->asoc.marked_retrans++;
1151 if (net->marked_retrans) {
1152 sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED);
1157 sctp_path_check_and_react(struct sctp_tcb *stcb, struct sctp_ifa *newifa)
1159 struct sctp_nets *net;
1160 int addrnum, changed;
1163 * If number of local valid addresses is 1, the valid address is
1164 * probably newly added address. Several valid addresses in this
1165 * association. A source address may not be changed. Additionally,
1166 * they can be configured on a same interface as "alias" addresses.
1169 addrnum = sctp_local_addr_count(stcb);
1170 SCTPDBG(SCTP_DEBUG_ASCONF1, "p_check_react(): %d local addresses\n",
1173 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1174 /* clear any cached route and source address */
1175 if (net->ro.ro_rt) {
1176 RTFREE(net->ro.ro_rt);
1177 net->ro.ro_rt = NULL;
1179 if (net->src_addr_selected) {
1180 sctp_free_ifa(net->ro._s_addr);
1181 net->ro._s_addr = NULL;
1182 net->src_addr_selected = 0;
1184 /* Retransmit unacknowledged DATA chunks immediately */
1185 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
1186 SCTP_MOBILITY_FASTHANDOFF)) {
1187 sctp_net_immediate_retrans(stcb, net);
1189 /* also, SET PRIMARY is maybe already sent */
1193 /* Multiple local addresses exsist in the association. */
1194 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1195 /* clear any cached route and source address */
1196 if (net->ro.ro_rt) {
1197 RTFREE(net->ro.ro_rt);
1198 net->ro.ro_rt = NULL;
1200 if (net->src_addr_selected) {
1201 sctp_free_ifa(net->ro._s_addr);
1202 net->ro._s_addr = NULL;
1203 net->src_addr_selected = 0;
1206 * Check if the nexthop is corresponding to the new address.
1207 * If the new address is corresponding to the current
1208 * nexthop, the path will be changed. If the new address is
1209 * NOT corresponding to the current nexthop, the path will
1212 SCTP_RTALLOC((sctp_route_t *) & net->ro,
1213 stcb->sctp_ep->def_vrf_id);
1214 if (net->ro.ro_rt == NULL)
1218 switch (net->ro._l_addr.sa.sa_family) {
1221 if (sctp_v4src_match_nexthop(newifa, (sctp_route_t *) & net->ro)) {
1228 if (sctp_v6src_match_nexthop(
1229 &newifa->address.sin6, (sctp_route_t *) & net->ro)) {
1238 * if the newly added address does not relate routing
1239 * information, we skip.
1243 /* Retransmit unacknowledged DATA chunks immediately */
1244 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
1245 SCTP_MOBILITY_FASTHANDOFF)) {
1246 sctp_net_immediate_retrans(stcb, net);
1248 /* Send SET PRIMARY for this new address */
1249 if (net == stcb->asoc.primary_destination) {
1250 (void)sctp_asconf_queue_mgmt(stcb, newifa,
1251 SCTP_SET_PRIM_ADDR);
1257 * process an ADD/DELETE IP ack from peer.
1258 * addr: corresponding sctp_ifa to the address being added/deleted.
1259 * type: SCTP_ADD_IP_ADDRESS or SCTP_DEL_IP_ADDRESS.
1260 * flag: 1=success, 0=failure.
1263 sctp_asconf_addr_mgmt_ack(struct sctp_tcb *stcb, struct sctp_ifa *addr, uint32_t flag)
1266 * do the necessary asoc list work- if we get a failure indication,
1267 * leave the address on the assoc's restricted list. If we get a
1268 * success indication, remove the address from the restricted list.
1271 * Note: this will only occur for ADD_IP_ADDRESS, since
1272 * DEL_IP_ADDRESS is never actually added to the list...
1275 /* success case, so remove from the restricted list */
1276 sctp_del_local_addr_restricted(stcb, addr);
1278 if (sctp_is_mobility_feature_on(stcb->sctp_ep,
1279 SCTP_MOBILITY_BASE) ||
1280 sctp_is_mobility_feature_on(stcb->sctp_ep,
1281 SCTP_MOBILITY_FASTHANDOFF)) {
1282 sctp_path_check_and_react(stcb, addr);
1285 /* clear any cached/topologically incorrect source addresses */
1286 sctp_asconf_nets_cleanup(stcb, addr->ifn_p);
1288 /* else, leave it on the list */
1292 * add an asconf add/delete/set primary IP address parameter to the queue.
1293 * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR.
1294 * returns 0 if queued, -1 if not queued/removed.
1295 * NOTE: if adding, but a delete for the same address is already scheduled
1296 * (and not yet sent out), simply remove it from queue. Same for deleting
1297 * an address already scheduled for add. If a duplicate operation is found,
1298 * ignore the new one.
1301 sctp_asconf_queue_mgmt(struct sctp_tcb *stcb, struct sctp_ifa *ifa,
1304 struct sctp_asconf_addr *aa, *aa_next;
1305 struct sockaddr *sa;
1307 /* make sure the request isn't already in the queue */
1308 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) {
1309 /* address match? */
1310 if (sctp_asconf_addr_match(aa, &ifa->address.sa) == 0)
1313 * is the request already in queue but not sent? pass the
1314 * request already sent in order to resolve the following
1315 * case: 1. arrival of ADD, then sent 2. arrival of DEL. we
1316 * can't remove the ADD request already sent 3. arrival of
1319 if (aa->ap.aph.ph.param_type == type && aa->sent == 0) {
1322 /* is the negative request already in queue, and not sent */
1323 if ((aa->sent == 0) && (type == SCTP_ADD_IP_ADDRESS) &&
1324 (aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS)) {
1325 /* add requested, delete already queued */
1326 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1327 /* remove the ifa from the restricted list */
1328 sctp_del_local_addr_restricted(stcb, ifa);
1329 /* free the asconf param */
1330 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1331 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_mgmt: add removes queued entry\n");
1334 if ((aa->sent == 0) && (type == SCTP_DEL_IP_ADDRESS) &&
1335 (aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS)) {
1336 /* delete requested, add already queued */
1337 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1338 /* remove the aa->ifa from the restricted list */
1339 sctp_del_local_addr_restricted(stcb, aa->ifa);
1340 /* free the asconf param */
1341 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1342 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_mgmt: delete removes queued entry\n");
1347 /* adding new request to the queue */
1348 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
1351 /* didn't get memory */
1352 SCTPDBG(SCTP_DEBUG_ASCONF1, "asconf_queue_mgmt: failed to get memory!\n");
1355 aa->special_del = 0;
1356 /* fill in asconf address parameter fields */
1357 /* top level elements are "networked" during send */
1358 aa->ap.aph.ph.param_type = type;
1360 atomic_add_int(&ifa->refcount, 1);
1361 /* correlation_id filled in during send routine later... */
1362 switch (ifa->address.sa.sa_family) {
1366 struct sockaddr_in6 *sin6;
1368 sin6 = (struct sockaddr_in6 *)&ifa->address.sa;
1369 sa = (struct sockaddr *)sin6;
1370 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
1371 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param));
1372 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) +
1373 sizeof(struct sctp_ipv6addr_param);
1374 memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr,
1375 sizeof(struct in6_addr));
1382 struct sockaddr_in *sin;
1384 sin = (struct sockaddr_in *)&ifa->address.sa;
1385 sa = (struct sockaddr *)sin;
1386 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
1387 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param));
1388 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) +
1389 sizeof(struct sctp_ipv4addr_param);
1390 memcpy(&aa->ap.addrp.addr, &sin->sin_addr,
1391 sizeof(struct in_addr));
1396 /* invalid family! */
1397 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1401 aa->sent = 0; /* clear sent flag */
1403 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
1405 if (SCTP_BASE_SYSCTL(sctp_debug_on) & SCTP_DEBUG_ASCONF2) {
1406 if (type == SCTP_ADD_IP_ADDRESS) {
1407 SCTP_PRINTF("asconf_queue_mgmt: inserted asconf ADD_IP_ADDRESS: ");
1408 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, sa);
1409 } else if (type == SCTP_DEL_IP_ADDRESS) {
1410 SCTP_PRINTF("asconf_queue_mgmt: appended asconf DEL_IP_ADDRESS: ");
1411 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, sa);
1413 SCTP_PRINTF("asconf_queue_mgmt: appended asconf SET_PRIM_ADDR: ");
1414 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, sa);
1424 * add an asconf operation for the given ifa and type.
1425 * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR.
1426 * returns 0 if completed, -1 if not completed, 1 if immediate send is
1430 sctp_asconf_queue_add(struct sctp_tcb *stcb, struct sctp_ifa *ifa,
1434 int pending_delete_queued = 0;
1436 /* see if peer supports ASCONF */
1437 if (stcb->asoc.peer_supports_asconf == 0) {
1441 * if this is deleting the last address from the assoc, mark it as
1444 if ((type == SCTP_DEL_IP_ADDRESS) && !stcb->asoc.asconf_del_pending &&
1445 (sctp_local_addr_count(stcb) < 2)) {
1446 /* set the pending delete info only */
1447 stcb->asoc.asconf_del_pending = 1;
1448 stcb->asoc.asconf_addr_del_pending = ifa;
1449 atomic_add_int(&ifa->refcount, 1);
1450 SCTPDBG(SCTP_DEBUG_ASCONF2,
1451 "asconf_queue_add: mark delete last address pending\n");
1454 /* queue an asconf parameter */
1455 status = sctp_asconf_queue_mgmt(stcb, ifa, type);
1458 * if this is an add, and there is a delete also pending (i.e. the
1459 * last local address is being changed), queue the pending delete
1462 if ((type == SCTP_ADD_IP_ADDRESS) && stcb->asoc.asconf_del_pending && (status == 0)) {
1463 /* queue in the pending delete */
1464 if (sctp_asconf_queue_mgmt(stcb,
1465 stcb->asoc.asconf_addr_del_pending,
1466 SCTP_DEL_IP_ADDRESS) == 0) {
1467 SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_add: queing pending delete\n");
1468 pending_delete_queued = 1;
1469 /* clear out the pending delete info */
1470 stcb->asoc.asconf_del_pending = 0;
1471 sctp_free_ifa(stcb->asoc.asconf_addr_del_pending);
1472 stcb->asoc.asconf_addr_del_pending = NULL;
1475 if (pending_delete_queued) {
1476 struct sctp_nets *net;
1479 * since we know that the only/last address is now being
1480 * changed in this case, reset the cwnd/rto on all nets to
1481 * start as a new address and path. Also clear the error
1482 * counts to give the assoc the best chance to complete the
1485 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1486 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb,
1489 net->error_count = 0;
1491 stcb->asoc.overall_error_count = 0;
1492 if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) {
1493 sctp_misc_ints(SCTP_THRESHOLD_CLEAR,
1494 stcb->asoc.overall_error_count,
1496 SCTP_FROM_SCTP_ASCONF,
1499 /* queue in an advisory set primary too */
1500 (void)sctp_asconf_queue_mgmt(stcb, ifa, SCTP_SET_PRIM_ADDR);
1501 /* let caller know we should send this out immediately */
1508 * add an asconf delete IP address parameter to the queue by sockaddr and
1509 * possibly with no sctp_ifa available. This is only called by the routine
1510 * that checks the addresses in an INIT-ACK against the current address list.
1511 * returns 0 if completed, non-zero if not completed.
1512 * NOTE: if an add is already scheduled (and not yet sent out), simply
1513 * remove it from queue. If a duplicate operation is found, ignore the
1517 sctp_asconf_queue_sa_delete(struct sctp_tcb *stcb, struct sockaddr *sa)
1519 struct sctp_ifa *ifa;
1520 struct sctp_asconf_addr *aa, *aa_next;
1526 /* see if peer supports ASCONF */
1527 if (stcb->asoc.peer_supports_asconf == 0) {
1530 /* make sure the request isn't already in the queue */
1531 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) {
1532 /* address match? */
1533 if (sctp_asconf_addr_match(aa, sa) == 0)
1535 /* is the request already in queue (sent or not) */
1536 if (aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) {
1539 /* is the negative request already in queue, and not sent */
1542 if (aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS) {
1543 /* add already queued, so remove existing entry */
1544 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next);
1545 sctp_del_local_addr_restricted(stcb, aa->ifa);
1546 /* free the entry */
1547 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1552 /* find any existing ifa-- NOTE ifa CAN be allowed to be NULL */
1554 vrf_id = stcb->asoc.vrf_id;
1556 vrf_id = SCTP_DEFAULT_VRFID;
1558 ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED);
1560 /* adding new request to the queue */
1561 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
1564 /* didn't get memory */
1565 SCTPDBG(SCTP_DEBUG_ASCONF1,
1566 "sctp_asconf_queue_sa_delete: failed to get memory!\n");
1569 aa->special_del = 0;
1570 /* fill in asconf address parameter fields */
1571 /* top level elements are "networked" during send */
1572 aa->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS;
1575 atomic_add_int(&ifa->refcount, 1);
1576 /* correlation_id filled in during send routine later... */
1577 switch (sa->sa_family) {
1582 struct sockaddr_in6 *sin6;
1584 sin6 = (struct sockaddr_in6 *)sa;
1585 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
1586 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param));
1587 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv6addr_param);
1588 memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr,
1589 sizeof(struct in6_addr));
1597 struct sockaddr_in *sin = (struct sockaddr_in *)sa;
1599 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
1600 aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param));
1601 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv4addr_param);
1602 memcpy(&aa->ap.addrp.addr, &sin->sin_addr,
1603 sizeof(struct in_addr));
1608 /* invalid family! */
1609 SCTP_FREE(aa, SCTP_M_ASC_ADDR);
1614 aa->sent = 0; /* clear sent flag */
1616 /* delete goes to the back of the queue */
1617 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
1619 /* sa_ignore MEMLEAK {memory is put on the tailq} */
1624 * find a specific asconf param on our "sent" queue
1626 static struct sctp_asconf_addr *
1627 sctp_asconf_find_param(struct sctp_tcb *stcb, uint32_t correlation_id)
1629 struct sctp_asconf_addr *aa;
1631 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
1632 if (aa->ap.aph.correlation_id == correlation_id &&
1638 /* didn't find it */
1643 * process an SCTP_ERROR_CAUSE_IND for a ASCONF-ACK parameter and do
1644 * notifications based on the error response
1647 sctp_asconf_process_error(struct sctp_tcb *stcb,
1648 struct sctp_asconf_paramhdr *aph)
1650 struct sctp_error_cause *eh;
1651 struct sctp_paramhdr *ph;
1652 uint16_t param_type;
1653 uint16_t error_code;
1655 eh = (struct sctp_error_cause *)(aph + 1);
1656 ph = (struct sctp_paramhdr *)(eh + 1);
1657 /* validate lengths */
1658 if (htons(eh->length) + sizeof(struct sctp_error_cause) >
1659 htons(aph->ph.param_length)) {
1660 /* invalid error cause length */
1661 SCTPDBG(SCTP_DEBUG_ASCONF1,
1662 "asconf_process_error: cause element too long\n");
1665 if (htons(ph->param_length) + sizeof(struct sctp_paramhdr) >
1666 htons(eh->length)) {
1667 /* invalid included TLV length */
1668 SCTPDBG(SCTP_DEBUG_ASCONF1,
1669 "asconf_process_error: included TLV too long\n");
1672 /* which error code ? */
1673 error_code = ntohs(eh->code);
1674 param_type = ntohs(aph->ph.param_type);
1675 /* FIX: this should go back up the REMOTE_ERROR ULP notify */
1676 switch (error_code) {
1677 case SCTP_CAUSE_RESOURCE_SHORTAGE:
1678 /* we allow ourselves to "try again" for this error */
1681 /* peer can't handle it... */
1682 switch (param_type) {
1683 case SCTP_ADD_IP_ADDRESS:
1684 case SCTP_DEL_IP_ADDRESS:
1685 stcb->asoc.peer_supports_asconf = 0;
1687 case SCTP_SET_PRIM_ADDR:
1688 stcb->asoc.peer_supports_asconf = 0;
1697 * process an asconf queue param.
1698 * aparam: parameter to process, will be removed from the queue.
1699 * flag: 1=success case, 0=failure case
1702 sctp_asconf_process_param_ack(struct sctp_tcb *stcb,
1703 struct sctp_asconf_addr *aparam, uint32_t flag)
1705 uint16_t param_type;
1707 /* process this param */
1708 param_type = aparam->ap.aph.ph.param_type;
1709 switch (param_type) {
1710 case SCTP_ADD_IP_ADDRESS:
1711 SCTPDBG(SCTP_DEBUG_ASCONF1,
1712 "process_param_ack: added IP address\n");
1713 sctp_asconf_addr_mgmt_ack(stcb, aparam->ifa, flag);
1715 case SCTP_DEL_IP_ADDRESS:
1716 SCTPDBG(SCTP_DEBUG_ASCONF1,
1717 "process_param_ack: deleted IP address\n");
1718 /* nothing really to do... lists already updated */
1720 case SCTP_SET_PRIM_ADDR:
1721 SCTPDBG(SCTP_DEBUG_ASCONF1,
1722 "process_param_ack: set primary IP address\n");
1723 /* nothing to do... peer may start using this addr */
1725 stcb->asoc.peer_supports_asconf = 0;
1728 /* should NEVER happen */
1732 /* remove the param and free it */
1733 TAILQ_REMOVE(&stcb->asoc.asconf_queue, aparam, next);
1735 sctp_free_ifa(aparam->ifa);
1736 SCTP_FREE(aparam, SCTP_M_ASC_ADDR);
1740 * cleanup from a bad asconf ack parameter
1743 sctp_asconf_ack_clear(struct sctp_tcb *stcb)
1745 /* assume peer doesn't really know how to do asconfs */
1746 stcb->asoc.peer_supports_asconf = 0;
1747 /* XXX we could free the pending queue here */
1751 sctp_handle_asconf_ack(struct mbuf *m, int offset,
1752 struct sctp_asconf_ack_chunk *cp, struct sctp_tcb *stcb,
1753 struct sctp_nets *net, int *abort_no_unlock)
1755 struct sctp_association *asoc;
1756 uint32_t serial_num;
1757 uint16_t ack_length;
1758 struct sctp_asconf_paramhdr *aph;
1759 struct sctp_asconf_addr *aa, *aa_next;
1760 uint32_t last_error_id = 0; /* last error correlation id */
1762 struct sctp_asconf_addr *ap;
1764 /* asconf param buffer */
1765 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE];
1767 /* verify minimum length */
1768 if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_ack_chunk)) {
1769 SCTPDBG(SCTP_DEBUG_ASCONF1,
1770 "handle_asconf_ack: chunk too small = %xh\n",
1771 ntohs(cp->ch.chunk_length));
1775 serial_num = ntohl(cp->serial_number);
1778 * NOTE: we may want to handle this differently- currently, we will
1779 * abort when we get an ack for the expected serial number + 1 (eg.
1780 * we didn't send it), process an ack normally if it is the expected
1781 * serial number, and re-send the previous ack for *ALL* other
1786 * if the serial number is the next expected, but I didn't send it,
1787 * abort the asoc, since someone probably just hijacked us...
1789 if (serial_num == (asoc->asconf_seq_out + 1)) {
1790 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got unexpected next serial number! Aborting asoc!\n");
1791 sctp_abort_an_association(stcb->sctp_ep, stcb, NULL, SCTP_SO_NOT_LOCKED);
1792 *abort_no_unlock = 1;
1795 if (serial_num != asoc->asconf_seq_out_acked + 1) {
1796 /* got a duplicate/unexpected ASCONF-ACK */
1797 SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got duplicate/unexpected serial number = %xh (expected = %xh)\n",
1798 serial_num, asoc->asconf_seq_out_acked + 1);
1801 if (serial_num == asoc->asconf_seq_out - 1) {
1802 /* stop our timer */
1803 sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, net,
1804 SCTP_FROM_SCTP_ASCONF + SCTP_LOC_3);
1806 /* process the ASCONF-ACK contents */
1807 ack_length = ntohs(cp->ch.chunk_length) -
1808 sizeof(struct sctp_asconf_ack_chunk);
1809 offset += sizeof(struct sctp_asconf_ack_chunk);
1810 /* process through all parameters */
1811 while (ack_length >= sizeof(struct sctp_asconf_paramhdr)) {
1812 unsigned int param_length, param_type;
1814 /* get pointer to next asconf parameter */
1815 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset,
1816 sizeof(struct sctp_asconf_paramhdr), aparam_buf);
1818 /* can't get an asconf paramhdr */
1819 sctp_asconf_ack_clear(stcb);
1822 param_type = ntohs(aph->ph.param_type);
1823 param_length = ntohs(aph->ph.param_length);
1824 if (param_length > ack_length) {
1825 sctp_asconf_ack_clear(stcb);
1828 if (param_length < sizeof(struct sctp_paramhdr)) {
1829 sctp_asconf_ack_clear(stcb);
1832 /* get the complete parameter... */
1833 if (param_length > sizeof(aparam_buf)) {
1834 SCTPDBG(SCTP_DEBUG_ASCONF1,
1835 "param length (%u) larger than buffer size!\n", param_length);
1836 sctp_asconf_ack_clear(stcb);
1839 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf);
1841 sctp_asconf_ack_clear(stcb);
1844 /* correlation_id is transparent to peer, no ntohl needed */
1845 id = aph->correlation_id;
1847 switch (param_type) {
1848 case SCTP_ERROR_CAUSE_IND:
1850 /* find the corresponding asconf param in our queue */
1851 ap = sctp_asconf_find_param(stcb, id);
1853 /* hmm... can't find this in our queue! */
1856 /* process the parameter, failed flag */
1857 sctp_asconf_process_param_ack(stcb, ap, 0);
1858 /* process the error response */
1859 sctp_asconf_process_error(stcb, aph);
1861 case SCTP_SUCCESS_REPORT:
1862 /* find the corresponding asconf param in our queue */
1863 ap = sctp_asconf_find_param(stcb, id);
1865 /* hmm... can't find this in our queue! */
1868 /* process the parameter, success flag */
1869 sctp_asconf_process_param_ack(stcb, ap, 1);
1875 /* update remaining ASCONF-ACK message length to process */
1876 ack_length -= SCTP_SIZE32(param_length);
1877 if (ack_length <= 0) {
1878 /* no more data in the mbuf chain */
1881 offset += SCTP_SIZE32(param_length);
1885 * if there are any "sent" params still on the queue, these are
1886 * implicitly "success", or "failed" (if we got an error back) ...
1887 * so process these appropriately
1889 * we assume that the correlation_id's are monotonically increasing
1890 * beginning from 1 and that we don't have *that* many outstanding
1893 if (last_error_id == 0)
1894 last_error_id--;/* set to "max" value */
1895 TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) {
1896 if (aa->sent == 1) {
1898 * implicitly successful or failed if correlation_id
1899 * < last_error_id, then success else, failure
1901 if (aa->ap.aph.correlation_id < last_error_id)
1902 sctp_asconf_process_param_ack(stcb, aa, 1);
1904 sctp_asconf_process_param_ack(stcb, aa, 0);
1907 * since we always process in order (FIFO queue) if
1908 * we reach one that hasn't been sent, the rest
1909 * should not have been sent either. so, we're
1916 /* update the next sequence number to use */
1917 asoc->asconf_seq_out_acked++;
1918 /* remove the old ASCONF on our outbound queue */
1919 sctp_toss_old_asconf(stcb);
1920 if (!TAILQ_EMPTY(&stcb->asoc.asconf_queue)) {
1921 #ifdef SCTP_TIMER_BASED_ASCONF
1922 /* we have more params, so restart our timer */
1923 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep,
1926 /* we have more params, so send out more */
1927 sctp_send_asconf(stcb, net, SCTP_ADDR_NOT_LOCKED);
1934 sctp_is_scopeid_in_nets(struct sctp_tcb *stcb, struct sockaddr *sa)
1936 struct sockaddr_in6 *sin6, *net6;
1937 struct sctp_nets *net;
1939 if (sa->sa_family != AF_INET6) {
1943 sin6 = (struct sockaddr_in6 *)sa;
1944 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) == 0) {
1945 /* not link local address */
1948 /* hunt through our destination nets list for this scope_id */
1949 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
1950 if (((struct sockaddr *)(&net->ro._l_addr))->sa_family !=
1953 net6 = (struct sockaddr_in6 *)&net->ro._l_addr;
1954 if (IN6_IS_ADDR_LINKLOCAL(&net6->sin6_addr) == 0)
1956 if (sctp_is_same_scope(sin6, net6)) {
1961 /* didn't find one */
1968 * address management functions
1971 sctp_addr_mgmt_assoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
1972 struct sctp_ifa *ifa, uint16_t type, int addr_locked)
1977 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0 ||
1978 sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_ASCONF)) {
1979 /* subset bound, no ASCONF allowed case, so ignore */
1983 * note: we know this is not the subset bound, no ASCONF case eg.
1984 * this is boundall or subset bound w/ASCONF allowed
1987 /* first, make sure it's a good address family */
1988 switch (ifa->address.sa.sa_family) {
2001 /* make sure we're "allowed" to add this type of addr */
2002 if (ifa->address.sa.sa_family == AF_INET6) {
2003 /* invalid if we're not a v6 endpoint */
2004 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0)
2006 /* is the v6 addr really valid ? */
2007 if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) {
2012 /* put this address on the "pending/do not use yet" list */
2013 sctp_add_local_addr_restricted(stcb, ifa);
2015 * check address scope if address is out of scope, don't queue
2016 * anything... note: this would leave the address on both inp and
2019 switch (ifa->address.sa.sa_family) {
2023 struct sockaddr_in6 *sin6;
2025 sin6 = (struct sockaddr_in6 *)&ifa->address.sin6;
2026 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2027 /* we skip unspecifed addresses */
2030 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
2031 if (stcb->asoc.local_scope == 0) {
2034 /* is it the right link local scope? */
2035 if (sctp_is_scopeid_in_nets(stcb, &ifa->address.sa) == 0) {
2039 if (stcb->asoc.site_scope == 0 &&
2040 IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)) {
2049 struct sockaddr_in *sin;
2050 struct in6pcb *inp6;
2052 inp6 = (struct in6pcb *)&inp->ip_inp.inp;
2053 /* invalid if we are a v6 only endpoint */
2054 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2055 SCTP_IPV6_V6ONLY(inp6))
2058 sin = (struct sockaddr_in *)&ifa->address.sa;
2059 if (sin->sin_addr.s_addr == 0) {
2060 /* we skip unspecifed addresses */
2063 if (stcb->asoc.ipv4_local_scope == 0 &&
2064 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) {
2071 /* else, not AF_INET or AF_INET6, so skip */
2075 /* queue an asconf for this address add/delete */
2076 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF)) {
2077 /* does the peer do asconf? */
2078 if (stcb->asoc.peer_supports_asconf) {
2079 /* queue an asconf for this addr */
2080 status = sctp_asconf_queue_add(stcb, ifa, type);
2083 * if queued ok, and in the open state, send out the
2084 * ASCONF. If in the non-open state, these will be
2085 * sent when the state goes open.
2088 SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) {
2089 #ifdef SCTP_TIMER_BASED_ASCONF
2090 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, inp,
2091 stcb, stcb->asoc.primary_destination);
2093 sctp_send_asconf(stcb, NULL, addr_locked);
2102 sctp_asconf_iterator_ep(struct sctp_inpcb *inp, void *ptr, uint32_t val SCTP_UNUSED)
2104 struct sctp_asconf_iterator *asc;
2105 struct sctp_ifa *ifa;
2106 struct sctp_laddr *l;
2107 int cnt_invalid = 0;
2109 asc = (struct sctp_asconf_iterator *)ptr;
2110 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) {
2112 switch (ifa->address.sa.sa_family) {
2115 /* invalid if we're not a v6 endpoint */
2116 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
2118 if (asc->cnt == cnt_invalid)
2126 /* invalid if we are a v6 only endpoint */
2127 struct in6pcb *inp6;
2129 inp6 = (struct in6pcb *)&inp->ip_inp.inp;
2130 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2131 SCTP_IPV6_V6ONLY(inp6)) {
2133 if (asc->cnt == cnt_invalid)
2140 /* invalid address family */
2142 if (asc->cnt == cnt_invalid)
2150 sctp_asconf_iterator_ep_end(struct sctp_inpcb *inp, void *ptr, uint32_t val SCTP_UNUSED)
2152 struct sctp_ifa *ifa;
2153 struct sctp_asconf_iterator *asc;
2154 struct sctp_laddr *laddr, *nladdr, *l;
2156 /* Only for specific case not bound all */
2157 asc = (struct sctp_asconf_iterator *)ptr;
2158 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) {
2160 if (l->action == SCTP_ADD_IP_ADDRESS) {
2161 LIST_FOREACH(laddr, &inp->sctp_addr_list,
2163 if (laddr->ifa == ifa) {
2168 } else if (l->action == SCTP_DEL_IP_ADDRESS) {
2169 LIST_FOREACH_SAFE(laddr, &inp->sctp_addr_list, sctp_nxt_addr, nladdr) {
2170 /* remove only after all guys are done */
2171 if (laddr->ifa == ifa) {
2172 sctp_del_local_addr_ep(inp, ifa);
2181 sctp_asconf_iterator_stcb(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
2182 void *ptr, uint32_t val SCTP_UNUSED)
2184 struct sctp_asconf_iterator *asc;
2185 struct sctp_ifa *ifa;
2186 struct sctp_laddr *l;
2187 int cnt_invalid = 0;
2191 asc = (struct sctp_asconf_iterator *)ptr;
2192 LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) {
2196 /* address's vrf_id must be the vrf_id of the assoc */
2197 if (ifa->vrf_id != stcb->asoc.vrf_id) {
2200 /* Same checks again for assoc */
2201 switch (ifa->address.sa.sa_family) {
2205 /* invalid if we're not a v6 endpoint */
2206 struct sockaddr_in6 *sin6;
2208 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
2210 if (asc->cnt == cnt_invalid)
2215 sin6 = (struct sockaddr_in6 *)&ifa->address.sin6;
2216 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2217 /* we skip unspecifed addresses */
2220 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
2221 if (stcb->asoc.local_scope == 0) {
2224 /* is it the right link local scope? */
2225 if (sctp_is_scopeid_in_nets(stcb, &ifa->address.sa) == 0) {
2235 /* invalid if we are a v6 only endpoint */
2236 struct in6pcb *inp6;
2237 struct sockaddr_in *sin;
2239 inp6 = (struct in6pcb *)&inp->ip_inp.inp;
2240 /* invalid if we are a v6 only endpoint */
2241 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2242 SCTP_IPV6_V6ONLY(inp6))
2245 sin = (struct sockaddr_in *)&ifa->address.sa;
2246 if (sin->sin_addr.s_addr == 0) {
2247 /* we skip unspecifed addresses */
2250 if (stcb->asoc.ipv4_local_scope == 0 &&
2251 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) {
2254 if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
2255 SCTP_IPV6_V6ONLY(inp6)) {
2257 if (asc->cnt == cnt_invalid)
2266 /* invalid address family */
2268 if (asc->cnt == cnt_invalid)
2275 if (type == SCTP_ADD_IP_ADDRESS) {
2276 /* prevent this address from being used as a source */
2277 sctp_add_local_addr_restricted(stcb, ifa);
2278 } else if (type == SCTP_DEL_IP_ADDRESS) {
2279 struct sctp_nets *net;
2281 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
2284 /* delete this address if cached */
2285 if (net->ro._s_addr == ifa) {
2286 sctp_free_ifa(net->ro._s_addr);
2287 net->ro._s_addr = NULL;
2288 net->src_addr_selected = 0;
2292 net->ro.ro_rt = NULL;
2295 * Now we deleted our src address,
2296 * should we not also now reset the
2297 * cwnd/rto to start as if its a new
2300 stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net);
2305 } else if (type == SCTP_SET_PRIM_ADDR) {
2306 if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
2307 /* must validate the ifa is in the ep */
2308 if (sctp_is_addr_in_ep(stcb->sctp_ep, ifa) == 0) {
2312 /* Need to check scopes for this guy */
2313 if (sctp_is_address_in_scope(ifa,
2314 stcb->asoc.ipv4_addr_legal,
2315 stcb->asoc.ipv6_addr_legal,
2316 stcb->asoc.loopback_scope,
2317 stcb->asoc.ipv4_local_scope,
2318 stcb->asoc.local_scope,
2319 stcb->asoc.site_scope, 0) == 0) {
2324 /* queue an asconf for this address add/delete */
2325 if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF) &&
2326 stcb->asoc.peer_supports_asconf) {
2327 /* queue an asconf for this addr */
2328 status = sctp_asconf_queue_add(stcb, ifa, type);
2330 * if queued ok, and in the open state, update the
2331 * count of queued params. If in the non-open
2332 * state, these get sent when the assoc goes open.
2334 if (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) {
2342 * If we have queued params in the open state, send out an ASCONF.
2344 if (num_queued > 0) {
2345 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2350 sctp_asconf_iterator_end(void *ptr, uint32_t val SCTP_UNUSED)
2352 struct sctp_asconf_iterator *asc;
2353 struct sctp_ifa *ifa;
2354 struct sctp_laddr *l, *nl;
2356 asc = (struct sctp_asconf_iterator *)ptr;
2357 LIST_FOREACH_SAFE(l, &asc->list_of_work, sctp_nxt_addr, nl) {
2359 if (l->action == SCTP_ADD_IP_ADDRESS) {
2360 /* Clear the defer use flag */
2361 ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE;
2364 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_laddr), l);
2365 SCTP_DECR_LADDR_COUNT();
2367 SCTP_FREE(asc, SCTP_M_ASC_IT);
2371 * sa is the sockaddr to ask the peer to set primary to.
2372 * returns: 0 = completed, -1 = error
2375 sctp_set_primary_ip_address_sa(struct sctp_tcb *stcb, struct sockaddr *sa)
2378 struct sctp_ifa *ifa;
2380 /* find the ifa for the desired set primary */
2381 vrf_id = stcb->asoc.vrf_id;
2382 ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED);
2384 /* Invalid address */
2387 /* queue an ASCONF:SET_PRIM_ADDR to be sent */
2388 if (!sctp_asconf_queue_add(stcb, ifa, SCTP_SET_PRIM_ADDR)) {
2389 /* set primary queuing succeeded */
2390 SCTPDBG(SCTP_DEBUG_ASCONF1,
2391 "set_primary_ip_address_sa: queued on tcb=%p, ",
2393 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
2394 if (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) {
2395 #ifdef SCTP_TIMER_BASED_ASCONF
2396 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
2397 stcb->sctp_ep, stcb,
2398 stcb->asoc.primary_destination);
2400 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2404 SCTPDBG(SCTP_DEBUG_ASCONF1, "set_primary_ip_address_sa: failed to add to queue on tcb=%p, ",
2406 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
2413 sctp_set_primary_ip_address(struct sctp_ifa *ifa)
2415 struct sctp_inpcb *inp;
2417 /* go through all our PCB's */
2418 LIST_FOREACH(inp, &SCTP_BASE_INFO(listhead), sctp_list) {
2419 struct sctp_tcb *stcb;
2421 /* process for all associations for this endpoint */
2422 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
2423 /* queue an ASCONF:SET_PRIM_ADDR to be sent */
2424 if (!sctp_asconf_queue_add(stcb, ifa,
2425 SCTP_SET_PRIM_ADDR)) {
2426 /* set primary queuing succeeded */
2427 SCTPDBG(SCTP_DEBUG_ASCONF1, "set_primary_ip_address: queued on stcb=%p, ",
2429 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &ifa->address.sa);
2430 if (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) {
2431 #ifdef SCTP_TIMER_BASED_ASCONF
2432 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
2433 stcb->sctp_ep, stcb,
2434 stcb->asoc.primary_destination);
2436 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2440 } /* for each stcb */
2441 } /* for each inp */
2445 sctp_is_addr_pending(struct sctp_tcb *stcb, struct sctp_ifa *sctp_ifa)
2447 struct sctp_tmit_chunk *chk, *nchk;
2448 unsigned int offset, asconf_limit;
2449 struct sctp_asconf_chunk *acp;
2450 struct sctp_asconf_paramhdr *aph;
2451 uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE];
2452 struct sctp_paramhdr *ph;
2453 int add_cnt, del_cnt;
2454 uint16_t last_param_type;
2456 add_cnt = del_cnt = 0;
2457 last_param_type = 0;
2458 TAILQ_FOREACH_SAFE(chk, &stcb->asoc.asconf_send_queue, sctp_next, nchk) {
2459 if (chk->data == NULL) {
2460 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: No mbuf data?\n");
2464 acp = mtod(chk->data, struct sctp_asconf_chunk *);
2465 offset += sizeof(struct sctp_asconf_chunk);
2466 asconf_limit = ntohs(acp->ch.chunk_length);
2467 ph = (struct sctp_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_paramhdr), aparam_buf);
2469 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: couldn't get lookup addr!\n");
2472 offset += ntohs(ph->param_length);
2474 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_asconf_paramhdr), aparam_buf);
2476 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: Empty ASCONF will be sent?\n");
2479 while (aph != NULL) {
2480 unsigned int param_length, param_type;
2482 param_type = ntohs(aph->ph.param_type);
2483 param_length = ntohs(aph->ph.param_length);
2484 if (offset + param_length > asconf_limit) {
2485 /* parameter goes beyond end of chunk! */
2488 if (param_length > sizeof(aparam_buf)) {
2489 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: param length (%u) larger than buffer size!\n", param_length);
2492 if (param_length <= sizeof(struct sctp_paramhdr)) {
2493 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: param length(%u) too short\n", param_length);
2496 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, param_length, aparam_buf);
2498 SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: couldn't get entire param\n");
2501 ph = (struct sctp_paramhdr *)(aph + 1);
2502 if (sctp_addr_match(ph, &sctp_ifa->address.sa) != 0) {
2503 switch (param_type) {
2504 case SCTP_ADD_IP_ADDRESS:
2507 case SCTP_DEL_IP_ADDRESS:
2513 last_param_type = param_type;
2515 offset += SCTP_SIZE32(param_length);
2516 if (offset >= asconf_limit) {
2517 /* no more data in the mbuf chain */
2520 /* get pointer to next asconf param */
2521 aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_asconf_paramhdr), aparam_buf);
2526 * we want to find the sequences which consist of ADD -> DEL -> ADD
2529 if (add_cnt > del_cnt ||
2530 (add_cnt == del_cnt && last_param_type == SCTP_ADD_IP_ADDRESS)) {
2536 static struct sockaddr *
2537 sctp_find_valid_localaddr(struct sctp_tcb *stcb, int addr_locked)
2539 struct sctp_vrf *vrf = NULL;
2540 struct sctp_ifn *sctp_ifn;
2541 struct sctp_ifa *sctp_ifa;
2543 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2544 SCTP_IPI_ADDR_RLOCK();
2545 vrf = sctp_find_vrf(stcb->asoc.vrf_id);
2547 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2548 SCTP_IPI_ADDR_RUNLOCK();
2551 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
2552 if (stcb->asoc.loopback_scope == 0 &&
2553 SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
2554 /* Skip if loopback_scope not set */
2557 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
2558 switch (sctp_ifa->address.sa.sa_family) {
2561 if (stcb->asoc.ipv4_addr_legal) {
2562 struct sockaddr_in *sin;
2564 sin = (struct sockaddr_in *)&sctp_ifa->address.sa;
2565 if (sin->sin_addr.s_addr == 0) {
2566 /* skip unspecifed addresses */
2569 if (stcb->asoc.ipv4_local_scope == 0 &&
2570 IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))
2573 if (sctp_is_addr_restricted(stcb, sctp_ifa) &&
2574 (!sctp_is_addr_pending(stcb, sctp_ifa)))
2577 * found a valid local v4 address to
2580 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2581 SCTP_IPI_ADDR_RUNLOCK();
2582 return (&sctp_ifa->address.sa);
2588 if (stcb->asoc.ipv6_addr_legal) {
2589 struct sockaddr_in6 *sin6;
2591 if (sctp_ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) {
2594 sin6 = (struct sockaddr_in6 *)&sctp_ifa->address.sa;
2595 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
2597 * we skip unspecifed
2602 if (stcb->asoc.local_scope == 0 &&
2603 IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))
2605 if (stcb->asoc.site_scope == 0 &&
2606 IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))
2609 if (sctp_is_addr_restricted(stcb, sctp_ifa) &&
2610 (!sctp_is_addr_pending(stcb, sctp_ifa)))
2613 * found a valid local v6 address to
2616 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2617 SCTP_IPI_ADDR_RUNLOCK();
2618 return (&sctp_ifa->address.sa);
2627 /* no valid addresses found */
2628 if (addr_locked == SCTP_ADDR_NOT_LOCKED)
2629 SCTP_IPI_ADDR_RUNLOCK();
2633 static struct sockaddr *
2634 sctp_find_valid_localaddr_ep(struct sctp_tcb *stcb)
2636 struct sctp_laddr *laddr;
2638 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
2639 if (laddr->ifa == NULL) {
2642 /* is the address restricted ? */
2643 if (sctp_is_addr_restricted(stcb, laddr->ifa) &&
2644 (!sctp_is_addr_pending(stcb, laddr->ifa)))
2647 /* found a valid local address to use */
2648 return (&laddr->ifa->address.sa);
2650 /* no valid addresses found */
2655 * builds an ASCONF chunk from queued ASCONF params.
2656 * returns NULL on error (no mbuf, no ASCONF params queued, etc).
2659 sctp_compose_asconf(struct sctp_tcb *stcb, int *retlen, int addr_locked)
2661 struct mbuf *m_asconf, *m_asconf_chk;
2662 struct sctp_asconf_addr *aa;
2663 struct sctp_asconf_chunk *acp;
2664 struct sctp_asconf_paramhdr *aph;
2665 struct sctp_asconf_addr_param *aap;
2667 uint32_t correlation_id = 1; /* 0 is reserved... */
2668 caddr_t ptr, lookup_ptr;
2669 uint8_t lookup_used = 0;
2671 /* are there any asconf params to send? */
2672 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
2680 * get a chunk header mbuf and a cluster for the asconf params since
2681 * it's simpler to fill in the asconf chunk header lookup address on
2684 m_asconf_chk = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_chunk), 0, M_DONTWAIT, 1, MT_DATA);
2685 if (m_asconf_chk == NULL) {
2687 SCTPDBG(SCTP_DEBUG_ASCONF1,
2688 "compose_asconf: couldn't get chunk mbuf!\n");
2691 m_asconf = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_DONTWAIT, 1, MT_DATA);
2692 if (m_asconf == NULL) {
2694 SCTPDBG(SCTP_DEBUG_ASCONF1,
2695 "compose_asconf: couldn't get mbuf!\n");
2696 sctp_m_freem(m_asconf_chk);
2699 SCTP_BUF_LEN(m_asconf_chk) = sizeof(struct sctp_asconf_chunk);
2700 SCTP_BUF_LEN(m_asconf) = 0;
2701 acp = mtod(m_asconf_chk, struct sctp_asconf_chunk *);
2702 bzero(acp, sizeof(struct sctp_asconf_chunk));
2703 /* save pointers to lookup address and asconf params */
2704 lookup_ptr = (caddr_t)(acp + 1); /* after the header */
2705 ptr = mtod(m_asconf, caddr_t); /* beginning of cluster */
2707 /* fill in chunk header info */
2708 acp->ch.chunk_type = SCTP_ASCONF;
2709 acp->ch.chunk_flags = 0;
2710 acp->serial_number = htonl(stcb->asoc.asconf_seq_out);
2711 stcb->asoc.asconf_seq_out++;
2713 /* add parameters... up to smallest MTU allowed */
2714 TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) {
2717 /* get the parameter length */
2718 p_length = SCTP_SIZE32(aa->ap.aph.ph.param_length);
2719 /* will it fit in current chunk? */
2720 if (SCTP_BUF_LEN(m_asconf) + p_length > stcb->asoc.smallest_mtu) {
2721 /* won't fit, so we're done with this chunk */
2724 /* assign (and store) a correlation id */
2725 aa->ap.aph.correlation_id = correlation_id++;
2728 * fill in address if we're doing a delete this is a simple
2729 * way for us to fill in the correlation address, which
2730 * should only be used by the peer if we're deleting our
2731 * source address and adding a new address (e.g. renumbering
2734 if (lookup_used == 0 &&
2735 (aa->special_del == 0) &&
2736 aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) {
2737 struct sctp_ipv6addr_param *lookup;
2738 uint16_t p_size, addr_size;
2740 lookup = (struct sctp_ipv6addr_param *)lookup_ptr;
2741 lookup->ph.param_type =
2742 htons(aa->ap.addrp.ph.param_type);
2743 if (aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) {
2744 /* copy IPv6 address */
2745 p_size = sizeof(struct sctp_ipv6addr_param);
2746 addr_size = sizeof(struct in6_addr);
2748 /* copy IPv4 address */
2749 p_size = sizeof(struct sctp_ipv4addr_param);
2750 addr_size = sizeof(struct in_addr);
2752 lookup->ph.param_length = htons(SCTP_SIZE32(p_size));
2753 memcpy(lookup->addr, &aa->ap.addrp.addr, addr_size);
2754 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size);
2757 /* copy into current space */
2758 memcpy(ptr, &aa->ap, p_length);
2760 /* network elements and update lengths */
2761 aph = (struct sctp_asconf_paramhdr *)ptr;
2762 aap = (struct sctp_asconf_addr_param *)ptr;
2763 /* correlation_id is transparent to peer, no htonl needed */
2764 aph->ph.param_type = htons(aph->ph.param_type);
2765 aph->ph.param_length = htons(aph->ph.param_length);
2766 aap->addrp.ph.param_type = htons(aap->addrp.ph.param_type);
2767 aap->addrp.ph.param_length = htons(aap->addrp.ph.param_length);
2769 SCTP_BUF_LEN(m_asconf) += SCTP_SIZE32(p_length);
2770 ptr += SCTP_SIZE32(p_length);
2773 * these params are removed off the pending list upon
2774 * getting an ASCONF-ACK back from the peer, just set flag
2778 /* check to see if the lookup addr has been populated yet */
2779 if (lookup_used == 0) {
2780 /* NOTE: if the address param is optional, can skip this... */
2781 /* add any valid (existing) address... */
2782 struct sctp_ipv6addr_param *lookup;
2783 uint16_t p_size, addr_size;
2784 struct sockaddr *found_addr;
2787 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL)
2788 found_addr = sctp_find_valid_localaddr(stcb,
2791 found_addr = sctp_find_valid_localaddr_ep(stcb);
2793 lookup = (struct sctp_ipv6addr_param *)lookup_ptr;
2794 if (found_addr != NULL) {
2795 switch (found_addr->sa_family) {
2798 /* copy IPv6 address */
2799 lookup->ph.param_type =
2800 htons(SCTP_IPV6_ADDRESS);
2801 p_size = sizeof(struct sctp_ipv6addr_param);
2802 addr_size = sizeof(struct in6_addr);
2803 addr_ptr = (caddr_t)&((struct sockaddr_in6 *)
2804 found_addr)->sin6_addr;
2809 /* copy IPv4 address */
2810 lookup->ph.param_type =
2811 htons(SCTP_IPV4_ADDRESS);
2812 p_size = sizeof(struct sctp_ipv4addr_param);
2813 addr_size = sizeof(struct in_addr);
2814 addr_ptr = (caddr_t)&((struct sockaddr_in *)
2815 found_addr)->sin_addr;
2824 lookup->ph.param_length = htons(SCTP_SIZE32(p_size));
2825 memcpy(lookup->addr, addr_ptr, addr_size);
2826 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size);
2828 /* uh oh... don't have any address?? */
2829 SCTPDBG(SCTP_DEBUG_ASCONF1,
2830 "compose_asconf: no lookup addr!\n");
2831 /* XXX for now, we send a IPv4 address of 0.0.0.0 */
2832 lookup->ph.param_type = htons(SCTP_IPV4_ADDRESS);
2833 lookup->ph.param_length = htons(SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param)));
2834 bzero(lookup->addr, sizeof(struct in_addr));
2835 SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param));
2838 /* chain it all together */
2839 SCTP_BUF_NEXT(m_asconf_chk) = m_asconf;
2840 *retlen = SCTP_BUF_LEN(m_asconf_chk) + SCTP_BUF_LEN(m_asconf);
2841 acp->ch.chunk_length = ntohs(*retlen);
2843 return (m_asconf_chk);
2847 * section to handle address changes before an association is up eg. changes
2848 * during INIT/INIT-ACK/COOKIE-ECHO handshake
2852 * processes the (local) addresses in the INIT-ACK chunk
2855 sctp_process_initack_addresses(struct sctp_tcb *stcb, struct mbuf *m,
2856 unsigned int offset, unsigned int length)
2858 struct sctp_paramhdr tmp_param, *ph;
2859 uint16_t plen, ptype;
2860 struct sctp_ifa *sctp_ifa;
2861 struct sctp_ipv6addr_param addr_store;
2864 struct sockaddr_in6 sin6;
2868 struct sockaddr_in sin;
2871 struct sockaddr *sa;
2874 SCTPDBG(SCTP_DEBUG_ASCONF2, "processing init-ack addresses\n");
2875 if (stcb == NULL) /* Un-needed check for SA */
2878 /* convert to upper bound */
2881 if ((offset + sizeof(struct sctp_paramhdr)) > length) {
2884 /* init the addresses */
2886 bzero(&sin6, sizeof(sin6));
2887 sin6.sin6_family = AF_INET6;
2888 sin6.sin6_len = sizeof(sin6);
2889 sin6.sin6_port = stcb->rport;
2893 bzero(&sin, sizeof(sin));
2894 sin.sin_family = AF_INET;
2895 sin.sin_len = sizeof(sin);
2896 sin.sin_port = stcb->rport;
2899 /* go through the addresses in the init-ack */
2900 ph = (struct sctp_paramhdr *)
2901 sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr),
2902 (uint8_t *) & tmp_param);
2903 while (ph != NULL) {
2904 ptype = ntohs(ph->param_type);
2905 plen = ntohs(ph->param_length);
2908 case SCTP_IPV6_ADDRESS:
2910 struct sctp_ipv6addr_param *a6p;
2912 /* get the entire IPv6 address param */
2913 a6p = (struct sctp_ipv6addr_param *)
2914 sctp_m_getptr(m, offset,
2915 sizeof(struct sctp_ipv6addr_param),
2916 (uint8_t *) & addr_store);
2917 if (plen != sizeof(struct sctp_ipv6addr_param) ||
2921 memcpy(&sin6.sin6_addr, a6p->addr,
2922 sizeof(struct in6_addr));
2923 sa = (struct sockaddr *)&sin6;
2928 case SCTP_IPV4_ADDRESS:
2930 struct sctp_ipv4addr_param *a4p;
2932 /* get the entire IPv4 address param */
2933 a4p = (struct sctp_ipv4addr_param *)sctp_m_getptr(m, offset,
2934 sizeof(struct sctp_ipv4addr_param),
2935 (uint8_t *) & addr_store);
2936 if (plen != sizeof(struct sctp_ipv4addr_param) ||
2940 sin.sin_addr.s_addr = a4p->addr;
2941 sa = (struct sockaddr *)&sin;
2949 /* see if this address really (still) exists */
2951 vrf_id = stcb->asoc.vrf_id;
2953 vrf_id = SCTP_DEFAULT_VRFID;
2955 sctp_ifa = sctp_find_ifa_by_addr(sa, vrf_id,
2956 SCTP_ADDR_NOT_LOCKED);
2957 if (sctp_ifa == NULL) {
2958 /* address doesn't exist anymore */
2961 /* are ASCONFs allowed ? */
2962 if ((sctp_is_feature_on(stcb->sctp_ep,
2963 SCTP_PCB_FLAGS_DO_ASCONF)) &&
2964 stcb->asoc.peer_supports_asconf) {
2965 /* queue an ASCONF DEL_IP_ADDRESS */
2966 status = sctp_asconf_queue_sa_delete(stcb, sa);
2968 * if queued ok, and in correct state, send
2972 SCTP_GET_STATE(&stcb->asoc) ==
2974 #ifdef SCTP_TIMER_BASED_ASCONF
2975 sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
2976 stcb->sctp_ep, stcb,
2977 stcb->asoc.primary_destination);
2979 sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED);
2986 * Sanity check: Make sure the length isn't 0, otherwise
2987 * we'll be stuck in this loop for a long time...
2989 if (SCTP_SIZE32(plen) == 0) {
2990 SCTP_PRINTF("process_initack_addrs: bad len (%d) type=%xh\n",
2994 /* get next parameter */
2995 offset += SCTP_SIZE32(plen);
2996 if ((offset + sizeof(struct sctp_paramhdr)) > length)
2998 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset,
2999 sizeof(struct sctp_paramhdr), (uint8_t *) & tmp_param);
3003 /* FIX ME: need to verify return result for v6 address type if v6 disabled */
3005 * checks to see if a specific address is in the initack address list returns
3006 * 1 if found, 0 if not
3009 sctp_addr_in_initack(struct mbuf *m, uint32_t offset, uint32_t length, struct sockaddr *sa)
3011 struct sctp_paramhdr tmp_param, *ph;
3012 uint16_t plen, ptype;
3013 struct sctp_ipv6addr_param addr_store;
3016 struct sockaddr_in *sin;
3017 struct sctp_ipv4addr_param *a4p;
3021 struct sockaddr_in6 *sin6;
3022 struct sctp_ipv6addr_param *a6p;
3023 struct sockaddr_in6 sin6_tmp;
3027 switch (sa->sa_family) {
3040 SCTPDBG(SCTP_DEBUG_ASCONF2, "find_initack_addr: starting search for ");
3041 SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, sa);
3042 /* convert to upper bound */
3045 if ((offset + sizeof(struct sctp_paramhdr)) > length) {
3046 SCTPDBG(SCTP_DEBUG_ASCONF1,
3047 "find_initack_addr: invalid offset?\n");
3050 /* go through the addresses in the init-ack */
3051 ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset,
3052 sizeof(struct sctp_paramhdr), (uint8_t *) & tmp_param);
3053 while (ph != NULL) {
3054 ptype = ntohs(ph->param_type);
3055 plen = ntohs(ph->param_length);
3058 case SCTP_IPV6_ADDRESS:
3059 if (sa->sa_family == AF_INET6) {
3060 /* get the entire IPv6 address param */
3061 if (plen != sizeof(struct sctp_ipv6addr_param)) {
3064 /* get the entire IPv6 address param */
3065 a6p = (struct sctp_ipv6addr_param *)
3066 sctp_m_getptr(m, offset,
3067 sizeof(struct sctp_ipv6addr_param),
3068 (uint8_t *) & addr_store);
3072 sin6 = (struct sockaddr_in6 *)sa;
3073 if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr)) {
3074 /* create a copy and clear scope */
3075 memcpy(&sin6_tmp, sin6,
3076 sizeof(struct sockaddr_in6));
3078 in6_clearscope(&sin6->sin6_addr);
3080 if (memcmp(&sin6->sin6_addr, a6p->addr,
3081 sizeof(struct in6_addr)) == 0) {
3089 case SCTP_IPV4_ADDRESS:
3090 if (sa->sa_family == AF_INET) {
3091 if (plen != sizeof(struct sctp_ipv4addr_param)) {
3094 /* get the entire IPv4 address param */
3095 a4p = (struct sctp_ipv4addr_param *)
3096 sctp_m_getptr(m, offset,
3097 sizeof(struct sctp_ipv4addr_param),
3098 (uint8_t *) & addr_store);
3102 sin = (struct sockaddr_in *)sa;
3103 if (sin->sin_addr.s_addr == a4p->addr) {
3113 /* get next parameter */
3114 offset += SCTP_SIZE32(plen);
3115 if (offset + sizeof(struct sctp_paramhdr) > length) {
3118 ph = (struct sctp_paramhdr *)
3119 sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr),
3120 (uint8_t *) & tmp_param);
3127 * makes sure that the current endpoint local addr list is consistent with
3128 * the new association (eg. subset bound, asconf allowed) adds addresses as
3132 sctp_check_address_list_ep(struct sctp_tcb *stcb, struct mbuf *m, int offset,
3133 int length, struct sockaddr *init_addr)
3135 struct sctp_laddr *laddr;
3137 /* go through the endpoint list */
3138 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
3139 /* be paranoid and validate the laddr */
3140 if (laddr->ifa == NULL) {
3141 SCTPDBG(SCTP_DEBUG_ASCONF1,
3142 "check_addr_list_ep: laddr->ifa is NULL");
3145 if (laddr->ifa == NULL) {
3146 SCTPDBG(SCTP_DEBUG_ASCONF1, "check_addr_list_ep: laddr->ifa->ifa_addr is NULL");
3149 /* do i have it implicitly? */
3150 if (sctp_cmpaddr(&laddr->ifa->address.sa, init_addr)) {
3153 /* check to see if in the init-ack */
3154 if (!sctp_addr_in_initack(m, offset, length, &laddr->ifa->address.sa)) {
3156 sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb, laddr->ifa,
3157 SCTP_ADD_IP_ADDRESS, SCTP_ADDR_NOT_LOCKED);
3163 * makes sure that the current kernel address list is consistent with the new
3164 * association (with all addrs bound) adds addresses as necessary
3167 sctp_check_address_list_all(struct sctp_tcb *stcb, struct mbuf *m, int offset,
3168 int length, struct sockaddr *init_addr,
3169 uint16_t local_scope, uint16_t site_scope,
3170 uint16_t ipv4_scope, uint16_t loopback_scope)
3172 struct sctp_vrf *vrf = NULL;
3173 struct sctp_ifn *sctp_ifn;
3174 struct sctp_ifa *sctp_ifa;
3178 struct sockaddr_in *sin;
3182 struct sockaddr_in6 *sin6;
3187 vrf_id = stcb->asoc.vrf_id;
3191 SCTP_IPI_ADDR_RLOCK();
3192 vrf = sctp_find_vrf(vrf_id);
3194 SCTP_IPI_ADDR_RUNLOCK();
3197 /* go through all our known interfaces */
3198 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
3199 if (loopback_scope == 0 && SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
3200 /* skip loopback interface */
3203 /* go through each interface address */
3204 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
3205 /* do i have it implicitly? */
3206 if (sctp_cmpaddr(&sctp_ifa->address.sa, init_addr)) {
3209 switch (sctp_ifa->address.sa.sa_family) {
3212 sin = (struct sockaddr_in *)&sctp_ifa->address.sin;
3213 if ((ipv4_scope == 0) &&
3214 (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
3215 /* private address not in scope */
3222 sin6 = (struct sockaddr_in6 *)&sctp_ifa->address.sin6;
3223 if ((local_scope == 0) &&
3224 (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))) {
3227 if ((site_scope == 0) &&
3228 (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
3236 /* check to see if in the init-ack */
3237 if (!sctp_addr_in_initack(m, offset, length, &sctp_ifa->address.sa)) {
3239 sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb,
3240 sctp_ifa, SCTP_ADD_IP_ADDRESS,
3243 } /* end foreach ifa */
3244 } /* end foreach ifn */
3245 SCTP_IPI_ADDR_RUNLOCK();
3249 * validates an init-ack chunk (from a cookie-echo) with current addresses
3250 * adds addresses from the init-ack into our local address list, if needed
3251 * queues asconf adds/deletes addresses as needed and makes appropriate list
3252 * changes for source address selection m, offset: points to the start of the
3253 * address list in an init-ack chunk length: total length of the address
3254 * params only init_addr: address where my INIT-ACK was sent from
3257 sctp_check_address_list(struct sctp_tcb *stcb, struct mbuf *m, int offset,
3258 int length, struct sockaddr *init_addr,
3259 uint16_t local_scope, uint16_t site_scope,
3260 uint16_t ipv4_scope, uint16_t loopback_scope)
3262 /* process the local addresses in the initack */
3263 sctp_process_initack_addresses(stcb, m, offset, length);
3265 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3266 /* bound all case */
3267 sctp_check_address_list_all(stcb, m, offset, length, init_addr,
3268 local_scope, site_scope, ipv4_scope, loopback_scope);
3270 /* subset bound case */
3271 if (sctp_is_feature_on(stcb->sctp_ep,
3272 SCTP_PCB_FLAGS_DO_ASCONF)) {
3273 /* asconf's allowed */
3274 sctp_check_address_list_ep(stcb, m, offset, length,
3277 /* else, no asconfs allowed, so what we sent is what we get */
3282 * sctp_bindx() support
3285 sctp_addr_mgmt_ep_sa(struct sctp_inpcb *inp, struct sockaddr *sa,
3286 uint32_t type, uint32_t vrf_id, struct sctp_ifa *sctp_ifap)
3288 struct sctp_ifa *ifa;
3289 struct sctp_laddr *laddr, *nladdr;
3291 if (sa->sa_len == 0) {
3292 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EINVAL);
3297 } else if (type == SCTP_ADD_IP_ADDRESS) {
3298 /* For an add the address MUST be on the system */
3299 ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED);
3300 } else if (type == SCTP_DEL_IP_ADDRESS) {
3301 /* For a delete we need to find it in the inp */
3302 ifa = sctp_find_ifa_in_ep(inp, sa, SCTP_ADDR_NOT_LOCKED);
3307 if (type == SCTP_ADD_IP_ADDRESS) {
3308 sctp_add_local_addr_ep(inp, ifa, type);
3309 } else if (type == SCTP_DEL_IP_ADDRESS) {
3310 if (inp->laddr_count < 2) {
3311 /* can't delete the last local address */
3312 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EINVAL);
3315 LIST_FOREACH(laddr, &inp->sctp_addr_list,
3317 if (ifa == laddr->ifa) {
3318 /* Mark in the delete */
3319 laddr->action = type;
3323 if (LIST_EMPTY(&inp->sctp_asoc_list)) {
3325 * There is no need to start the iterator if the inp
3326 * has no associations.
3328 if (type == SCTP_DEL_IP_ADDRESS) {
3329 LIST_FOREACH_SAFE(laddr, &inp->sctp_addr_list, sctp_nxt_addr, nladdr) {
3330 if (laddr->ifa == ifa) {
3331 sctp_del_local_addr_ep(inp, ifa);
3336 struct sctp_asconf_iterator *asc;
3337 struct sctp_laddr *wi;
3339 SCTP_MALLOC(asc, struct sctp_asconf_iterator *,
3340 sizeof(struct sctp_asconf_iterator),
3343 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, ENOMEM);
3346 wi = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_laddr), struct sctp_laddr);
3348 SCTP_FREE(asc, SCTP_M_ASC_IT);
3349 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, ENOMEM);
3352 LIST_INIT(&asc->list_of_work);
3354 SCTP_INCR_LADDR_COUNT();
3357 atomic_add_int(&ifa->refcount, 1);
3358 LIST_INSERT_HEAD(&asc->list_of_work, wi, sctp_nxt_addr);
3359 (void)sctp_initiate_iterator(sctp_asconf_iterator_ep,
3360 sctp_asconf_iterator_stcb,
3361 sctp_asconf_iterator_ep_end,
3363 SCTP_PCB_ANY_FEATURES,
3364 SCTP_ASOC_ANY_STATE,
3366 sctp_asconf_iterator_end, inp, 0);
3370 /* invalid address! */
3371 SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EADDRNOTAVAIL);
3372 return (EADDRNOTAVAIL);
3377 sctp_asconf_send_nat_state_update(struct sctp_tcb *stcb,
3378 struct sctp_nets *net)
3380 struct sctp_asconf_addr *aa;
3381 struct sctp_ifa *sctp_ifap;
3382 struct sctp_asconf_tag_param *vtag;
3385 struct sockaddr_in *to;
3389 struct sockaddr_in6 *to6;
3393 SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing net\n");
3397 SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing stcb\n");
3401 * Need to have in the asconf: - vtagparam(my_vtag/peer_vtag) -
3402 * add(0.0.0.0) - del(0.0.0.0) - Any global addresses add(addr)
3404 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
3407 /* didn't get memory */
3408 SCTPDBG(SCTP_DEBUG_ASCONF1,
3409 "sctp_asconf_send_nat_state_update: failed to get memory!\n");
3412 aa->special_del = 0;
3413 /* fill in asconf address parameter fields */
3414 /* top level elements are "networked" during send */
3416 aa->sent = 0; /* clear sent flag */
3417 vtag = (struct sctp_asconf_tag_param *)&aa->ap.aph;
3418 vtag->aph.ph.param_type = SCTP_NAT_VTAGS;
3419 vtag->aph.ph.param_length = sizeof(struct sctp_asconf_tag_param);
3420 vtag->local_vtag = htonl(stcb->asoc.my_vtag);
3421 vtag->remote_vtag = htonl(stcb->asoc.peer_vtag);
3422 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
3424 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
3427 /* didn't get memory */
3428 SCTPDBG(SCTP_DEBUG_ASCONF1,
3429 "sctp_asconf_send_nat_state_update: failed to get memory!\n");
3432 memset(aa, 0, sizeof(struct sctp_asconf_addr));
3433 /* fill in asconf address parameter fields */
3435 switch (net->ro._l_addr.sa.sa_family) {
3438 aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
3439 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param);
3440 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
3441 aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv4addr_param);
3442 /* No need to add an address, we are using 0.0.0.0 */
3443 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
3448 aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
3449 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param);
3450 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
3451 aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv6addr_param);
3452 /* No need to add an address, we are using 0.0.0.0 */
3453 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
3457 SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa),
3460 /* didn't get memory */
3461 SCTPDBG(SCTP_DEBUG_ASCONF1,
3462 "sctp_asconf_send_nat_state_update: failed to get memory!\n");
3465 memset(aa, 0, sizeof(struct sctp_asconf_addr));
3466 /* fill in asconf address parameter fields */
3468 switch (net->ro._l_addr.sa.sa_family) {
3471 aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS;
3472 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param);
3473 aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS;
3474 aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv4addr_param);
3475 /* No need to add an address, we are using 0.0.0.0 */
3476 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
3481 aa->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS;
3482 aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param);
3483 aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS;
3484 aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv6addr_param);
3485 /* No need to add an address, we are using 0.0.0.0 */
3486 TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next);
3490 /* Now we must hunt the addresses and add all global addresses */
3491 if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
3492 struct sctp_vrf *vrf = NULL;
3493 struct sctp_ifn *sctp_ifnp;
3496 vrf_id = stcb->sctp_ep->def_vrf_id;
3497 vrf = sctp_find_vrf(vrf_id);
3501 SCTP_IPI_ADDR_RLOCK();
3502 LIST_FOREACH(sctp_ifnp, &vrf->ifnlist, next_ifn) {
3503 LIST_FOREACH(sctp_ifap, &sctp_ifnp->ifalist, next_ifa) {
3504 switch (sctp_ifap->address.sa.sa_family) {
3507 to = &sctp_ifap->address.sin;
3508 if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) {
3511 if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) {
3518 to6 = &sctp_ifap->address.sin6;
3519 if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) {
3522 if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) {
3530 sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS);
3533 SCTP_IPI_ADDR_RUNLOCK();
3535 struct sctp_laddr *laddr;
3537 LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
3538 if (laddr->ifa == NULL) {
3541 if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED)
3543 * Address being deleted by the system, dont
3547 if (laddr->action == SCTP_DEL_IP_ADDRESS) {
3549 * Address being deleted on this ep don't
3554 sctp_ifap = laddr->ifa;
3555 switch (sctp_ifap->address.sa.sa_family) {
3558 to = &sctp_ifap->address.sin;
3559 if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) {
3562 if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) {
3569 to6 = &sctp_ifap->address.sin6;
3570 if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) {
3573 if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) {
3581 sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS);
3585 /* Now we must send the asconf into the queue */
3586 sctp_send_asconf(stcb, net, SCTP_ADDR_NOT_LOCKED);