1f8829a4aSRandall Stewart /*- 2b1006367SRandall Stewart * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved. 35d40cf5dSRandall Stewart * Copyright (c) 2008-2011, by Randall Stewart. All rights reserved. 45d40cf5dSRandall Stewart * Copyright (c) 2008-2011, by Michael Tuexen. All rights reserved. 5f8829a4aSRandall Stewart * 6f8829a4aSRandall Stewart * Redistribution and use in source and binary forms, with or without 7f8829a4aSRandall Stewart * modification, are permitted provided that the following conditions are met: 8f8829a4aSRandall Stewart * 9f8829a4aSRandall Stewart * a) Redistributions of source code must retain the above copyright notice, 10f8829a4aSRandall Stewart * this list of conditions and the following disclaimer. 11f8829a4aSRandall Stewart * 12f8829a4aSRandall Stewart * b) Redistributions in binary form must reproduce the above copyright 13f8829a4aSRandall Stewart * notice, this list of conditions and the following disclaimer in 14f8829a4aSRandall Stewart * the documentation and/or other materials provided with the distribution. 15f8829a4aSRandall Stewart * 16f8829a4aSRandall Stewart * c) Neither the name of Cisco Systems, Inc. nor the names of its 17f8829a4aSRandall Stewart * contributors may be used to endorse or promote products derived 18f8829a4aSRandall Stewart * from this software without specific prior written permission. 19f8829a4aSRandall Stewart * 20f8829a4aSRandall Stewart * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21f8829a4aSRandall Stewart * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 22f8829a4aSRandall Stewart * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23f8829a4aSRandall Stewart * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24f8829a4aSRandall Stewart * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25f8829a4aSRandall Stewart * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26f8829a4aSRandall Stewart * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27f8829a4aSRandall Stewart * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28f8829a4aSRandall Stewart * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29f8829a4aSRandall Stewart * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30f8829a4aSRandall Stewart * THE POSSIBILITY OF SUCH DAMAGE. 31f8829a4aSRandall Stewart */ 32f8829a4aSRandall Stewart 33f8829a4aSRandall Stewart /* $KAME: sctp_asconf.c,v 1.24 2005/03/06 16:04:16 itojun Exp $ */ 34f8829a4aSRandall Stewart 35f8829a4aSRandall Stewart #include <sys/cdefs.h> 36cef8ad06SRandall Stewart __FBSDID("$FreeBSD$"); 37f8829a4aSRandall Stewart #include <netinet/sctp_os.h> 38f8829a4aSRandall Stewart #include <netinet/sctp_var.h> 3942551e99SRandall Stewart #include <netinet/sctp_sysctl.h> 40f8829a4aSRandall Stewart #include <netinet/sctp_pcb.h> 41f8829a4aSRandall Stewart #include <netinet/sctp_header.h> 42f8829a4aSRandall Stewart #include <netinet/sctputil.h> 43f8829a4aSRandall Stewart #include <netinet/sctp_output.h> 44f8829a4aSRandall Stewart #include <netinet/sctp_asconf.h> 45851b7298SRandall Stewart #include <netinet/sctp_timer.h> 46f8829a4aSRandall Stewart 47f8829a4aSRandall Stewart /* 48f8829a4aSRandall Stewart * debug flags: 49f8829a4aSRandall Stewart * SCTP_DEBUG_ASCONF1: protocol info, general info and errors 50f8829a4aSRandall Stewart * SCTP_DEBUG_ASCONF2: detailed info 51f8829a4aSRandall Stewart */ 52f8829a4aSRandall Stewart #ifdef SCTP_DEBUG 53f8829a4aSRandall Stewart #endif /* SCTP_DEBUG */ 54f8829a4aSRandall Stewart 55f8829a4aSRandall Stewart 56ad81507eSRandall Stewart static void 57f8829a4aSRandall Stewart sctp_asconf_get_source_ip(struct mbuf *m, struct sockaddr *sa) 58f8829a4aSRandall Stewart { 59f8829a4aSRandall Stewart struct ip *iph; 60*e6194c2eSMichael Tuexen 61*e6194c2eSMichael Tuexen #ifdef INET 62f8829a4aSRandall Stewart struct sockaddr_in *sin; 63f8829a4aSRandall Stewart 64*e6194c2eSMichael Tuexen #endif 65f8829a4aSRandall Stewart #ifdef INET6 66f8829a4aSRandall Stewart struct sockaddr_in6 *sin6; 67f8829a4aSRandall Stewart 68f8829a4aSRandall Stewart #endif 69f8829a4aSRandall Stewart 70f8829a4aSRandall Stewart iph = mtod(m, struct ip *); 71*e6194c2eSMichael Tuexen switch (iph->ip_v) { 72*e6194c2eSMichael Tuexen #ifdef INET 73*e6194c2eSMichael Tuexen case IPVERSION: 74*e6194c2eSMichael Tuexen { 75f8829a4aSRandall Stewart /* IPv4 source */ 76f8829a4aSRandall Stewart sin = (struct sockaddr_in *)sa; 77f8829a4aSRandall Stewart bzero(sin, sizeof(*sin)); 78f8829a4aSRandall Stewart sin->sin_family = AF_INET; 79f8829a4aSRandall Stewart sin->sin_len = sizeof(struct sockaddr_in); 80f8829a4aSRandall Stewart sin->sin_port = 0; 81f8829a4aSRandall Stewart sin->sin_addr.s_addr = iph->ip_src.s_addr; 82*e6194c2eSMichael Tuexen break; 83f8829a4aSRandall Stewart } 84*e6194c2eSMichael Tuexen #endif 85f8829a4aSRandall Stewart #ifdef INET6 86*e6194c2eSMichael Tuexen case (IPV6_VERSION >> 4): 87*e6194c2eSMichael Tuexen { 88f8829a4aSRandall Stewart /* IPv6 source */ 89f8829a4aSRandall Stewart struct ip6_hdr *ip6; 90f8829a4aSRandall Stewart 91f8829a4aSRandall Stewart sin6 = (struct sockaddr_in6 *)sa; 92f8829a4aSRandall Stewart bzero(sin6, sizeof(*sin6)); 93f8829a4aSRandall Stewart sin6->sin6_family = AF_INET6; 94f8829a4aSRandall Stewart sin6->sin6_len = sizeof(struct sockaddr_in6); 95f8829a4aSRandall Stewart sin6->sin6_port = 0; 96f8829a4aSRandall Stewart ip6 = mtod(m, struct ip6_hdr *); 97f8829a4aSRandall Stewart sin6->sin6_addr = ip6->ip6_src; 98*e6194c2eSMichael Tuexen break; 99f8829a4aSRandall Stewart } 100f8829a4aSRandall Stewart #endif /* INET6 */ 101*e6194c2eSMichael Tuexen default: 102*e6194c2eSMichael Tuexen break; 103*e6194c2eSMichael Tuexen } 104ad81507eSRandall Stewart return; 105f8829a4aSRandall Stewart } 106f8829a4aSRandall Stewart 107f8829a4aSRandall Stewart /* 108f8829a4aSRandall Stewart * draft-ietf-tsvwg-addip-sctp 109f8829a4aSRandall Stewart * 110f8829a4aSRandall Stewart * An ASCONF parameter queue exists per asoc which holds the pending address 111f8829a4aSRandall Stewart * operations. Lists are updated upon receipt of ASCONF-ACK. 112f8829a4aSRandall Stewart * 11318e198d3SRandall Stewart * A restricted_addrs list exists per assoc to hold local addresses that are 11418e198d3SRandall Stewart * not (yet) usable by the assoc as a source address. These addresses are 11518e198d3SRandall Stewart * either pending an ASCONF operation (and exist on the ASCONF parameter 11618e198d3SRandall Stewart * queue), or they are permanently restricted (the peer has returned an 11718e198d3SRandall Stewart * ERROR indication to an ASCONF(ADD), or the peer does not support ASCONF). 11818e198d3SRandall Stewart * 119f8829a4aSRandall Stewart * Deleted addresses are always immediately removed from the lists as they will 120f8829a4aSRandall Stewart * (shortly) no longer exist in the kernel. We send ASCONFs as a courtesy, 121f8829a4aSRandall Stewart * only if allowed. 122f8829a4aSRandall Stewart */ 123f8829a4aSRandall Stewart 124f8829a4aSRandall Stewart /* 12518e198d3SRandall Stewart * ASCONF parameter processing. 12618e198d3SRandall Stewart * response_required: set if a reply is required (eg. SUCCESS_REPORT). 12718e198d3SRandall Stewart * returns a mbuf to an "error" response parameter or NULL/"success" if ok. 12818e198d3SRandall Stewart * FIX: allocating this many mbufs on the fly is pretty inefficient... 129f8829a4aSRandall Stewart */ 130f8829a4aSRandall Stewart static struct mbuf * 131f8829a4aSRandall Stewart sctp_asconf_success_response(uint32_t id) 132f8829a4aSRandall Stewart { 133f8829a4aSRandall Stewart struct mbuf *m_reply = NULL; 134f8829a4aSRandall Stewart struct sctp_asconf_paramhdr *aph; 135f8829a4aSRandall Stewart 136f8829a4aSRandall Stewart m_reply = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_paramhdr), 137f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 138f8829a4aSRandall Stewart if (m_reply == NULL) { 139ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 140ad81507eSRandall Stewart "asconf_success_response: couldn't get mbuf!\n"); 141f8829a4aSRandall Stewart return NULL; 142f8829a4aSRandall Stewart } 143f8829a4aSRandall Stewart aph = mtod(m_reply, struct sctp_asconf_paramhdr *); 144f8829a4aSRandall Stewart aph->correlation_id = id; 145f8829a4aSRandall Stewart aph->ph.param_type = htons(SCTP_SUCCESS_REPORT); 146f8829a4aSRandall Stewart aph->ph.param_length = sizeof(struct sctp_asconf_paramhdr); 147139bc87fSRandall Stewart SCTP_BUF_LEN(m_reply) = aph->ph.param_length; 148f8829a4aSRandall Stewart aph->ph.param_length = htons(aph->ph.param_length); 149f8829a4aSRandall Stewart 150f8829a4aSRandall Stewart return m_reply; 151f8829a4aSRandall Stewart } 152f8829a4aSRandall Stewart 153f8829a4aSRandall Stewart static struct mbuf * 154f8829a4aSRandall Stewart sctp_asconf_error_response(uint32_t id, uint16_t cause, uint8_t * error_tlv, 155f8829a4aSRandall Stewart uint16_t tlv_length) 156f8829a4aSRandall Stewart { 157f8829a4aSRandall Stewart struct mbuf *m_reply = NULL; 158f8829a4aSRandall Stewart struct sctp_asconf_paramhdr *aph; 159f8829a4aSRandall Stewart struct sctp_error_cause *error; 160f8829a4aSRandall Stewart uint8_t *tlv; 161f8829a4aSRandall Stewart 162f8829a4aSRandall Stewart m_reply = sctp_get_mbuf_for_msg((sizeof(struct sctp_asconf_paramhdr) + 163f8829a4aSRandall Stewart tlv_length + 164f8829a4aSRandall Stewart sizeof(struct sctp_error_cause)), 165f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 166f8829a4aSRandall Stewart if (m_reply == NULL) { 167ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 168ad81507eSRandall Stewart "asconf_error_response: couldn't get mbuf!\n"); 169f8829a4aSRandall Stewart return NULL; 170f8829a4aSRandall Stewart } 171f8829a4aSRandall Stewart aph = mtod(m_reply, struct sctp_asconf_paramhdr *); 172f8829a4aSRandall Stewart error = (struct sctp_error_cause *)(aph + 1); 173f8829a4aSRandall Stewart 174f8829a4aSRandall Stewart aph->correlation_id = id; 175f8829a4aSRandall Stewart aph->ph.param_type = htons(SCTP_ERROR_CAUSE_IND); 176f8829a4aSRandall Stewart error->code = htons(cause); 177f8829a4aSRandall Stewart error->length = tlv_length + sizeof(struct sctp_error_cause); 178f8829a4aSRandall Stewart aph->ph.param_length = error->length + 179f8829a4aSRandall Stewart sizeof(struct sctp_asconf_paramhdr); 180f8829a4aSRandall Stewart 181f8829a4aSRandall Stewart if (aph->ph.param_length > MLEN) { 182ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 183ad81507eSRandall Stewart "asconf_error_response: tlv_length (%xh) too big\n", 184f8829a4aSRandall Stewart tlv_length); 185f8829a4aSRandall Stewart sctp_m_freem(m_reply); /* discard */ 186f8829a4aSRandall Stewart return NULL; 187f8829a4aSRandall Stewart } 188f8829a4aSRandall Stewart if (error_tlv != NULL) { 189f8829a4aSRandall Stewart tlv = (uint8_t *) (error + 1); 190f8829a4aSRandall Stewart memcpy(tlv, error_tlv, tlv_length); 191f8829a4aSRandall Stewart } 192139bc87fSRandall Stewart SCTP_BUF_LEN(m_reply) = aph->ph.param_length; 193f8829a4aSRandall Stewart error->length = htons(error->length); 194f8829a4aSRandall Stewart aph->ph.param_length = htons(aph->ph.param_length); 195f8829a4aSRandall Stewart 196f8829a4aSRandall Stewart return m_reply; 197f8829a4aSRandall Stewart } 198f8829a4aSRandall Stewart 199f8829a4aSRandall Stewart static struct mbuf * 200f8829a4aSRandall Stewart sctp_process_asconf_add_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph, 201f8829a4aSRandall Stewart struct sctp_tcb *stcb, int response_required) 202f8829a4aSRandall Stewart { 203f8829a4aSRandall Stewart struct mbuf *m_reply = NULL; 204f8829a4aSRandall Stewart struct sockaddr_storage sa_source, sa_store; 205*e6194c2eSMichael Tuexen struct sctp_paramhdr *ph; 206f8829a4aSRandall Stewart uint16_t param_type, param_length, aparam_length; 207f8829a4aSRandall Stewart struct sockaddr *sa; 208f8829a4aSRandall Stewart int zero_address = 0; 209f8829a4aSRandall Stewart 210*e6194c2eSMichael Tuexen #ifdef INET 211*e6194c2eSMichael Tuexen struct sockaddr_in *sin; 212*e6194c2eSMichael Tuexen struct sctp_ipv4addr_param *v4addr; 213*e6194c2eSMichael Tuexen 214*e6194c2eSMichael Tuexen #endif 215f8829a4aSRandall Stewart #ifdef INET6 216f8829a4aSRandall Stewart struct sockaddr_in6 *sin6; 217f8829a4aSRandall Stewart struct sctp_ipv6addr_param *v6addr; 218f8829a4aSRandall Stewart 219*e6194c2eSMichael Tuexen #endif 220f8829a4aSRandall Stewart 221f8829a4aSRandall Stewart aparam_length = ntohs(aph->ph.param_length); 222*e6194c2eSMichael Tuexen ph = (struct sctp_paramhdr *)(aph + 1); 223*e6194c2eSMichael Tuexen param_type = ntohs(ph->param_type); 224*e6194c2eSMichael Tuexen param_length = ntohs(ph->param_length); 225f8829a4aSRandall Stewart 226f8829a4aSRandall Stewart sa = (struct sockaddr *)&sa_store; 227f8829a4aSRandall Stewart switch (param_type) { 228*e6194c2eSMichael Tuexen #ifdef INET 229f8829a4aSRandall Stewart case SCTP_IPV4_ADDRESS: 230f8829a4aSRandall Stewart if (param_length != sizeof(struct sctp_ipv4addr_param)) { 231f8829a4aSRandall Stewart /* invalid param size */ 232f8829a4aSRandall Stewart return NULL; 233f8829a4aSRandall Stewart } 234*e6194c2eSMichael Tuexen v4addr = (struct sctp_ipv4addr_param *)ph; 235f8829a4aSRandall Stewart sin = (struct sockaddr_in *)&sa_store; 236f8829a4aSRandall Stewart bzero(sin, sizeof(*sin)); 237f8829a4aSRandall Stewart sin->sin_family = AF_INET; 238f8829a4aSRandall Stewart sin->sin_len = sizeof(struct sockaddr_in); 239f8829a4aSRandall Stewart sin->sin_port = stcb->rport; 240f8829a4aSRandall Stewart sin->sin_addr.s_addr = v4addr->addr; 241f8829a4aSRandall Stewart if (sin->sin_addr.s_addr == INADDR_ANY) 242f8829a4aSRandall Stewart zero_address = 1; 243ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_add_ip: adding "); 244ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 245f8829a4aSRandall Stewart break; 246*e6194c2eSMichael Tuexen #endif 247f8829a4aSRandall Stewart #ifdef INET6 248*e6194c2eSMichael Tuexen case SCTP_IPV6_ADDRESS: 249f8829a4aSRandall Stewart if (param_length != sizeof(struct sctp_ipv6addr_param)) { 250f8829a4aSRandall Stewart /* invalid param size */ 251f8829a4aSRandall Stewart return NULL; 252f8829a4aSRandall Stewart } 253*e6194c2eSMichael Tuexen v6addr = (struct sctp_ipv6addr_param *)ph; 254f8829a4aSRandall Stewart sin6 = (struct sockaddr_in6 *)&sa_store; 255f8829a4aSRandall Stewart bzero(sin6, sizeof(*sin6)); 256f8829a4aSRandall Stewart sin6->sin6_family = AF_INET6; 257f8829a4aSRandall Stewart sin6->sin6_len = sizeof(struct sockaddr_in6); 258f8829a4aSRandall Stewart sin6->sin6_port = stcb->rport; 259f8829a4aSRandall Stewart memcpy((caddr_t)&sin6->sin6_addr, v6addr->addr, 260f8829a4aSRandall Stewart sizeof(struct in6_addr)); 261f8829a4aSRandall Stewart if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) 262f8829a4aSRandall Stewart zero_address = 1; 263ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_add_ip: adding "); 264ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 265f8829a4aSRandall Stewart break; 266*e6194c2eSMichael Tuexen #endif 267f8829a4aSRandall Stewart default: 268*e6194c2eSMichael Tuexen /* 269*e6194c2eSMichael Tuexen * XXX: Is this the correct error cause? Maybe 270*e6194c2eSMichael Tuexen * SCTP_CAUSE_INVALID_PARAM is a better choice. 271*e6194c2eSMichael Tuexen */ 272f8829a4aSRandall Stewart m_reply = sctp_asconf_error_response(aph->correlation_id, 273f8829a4aSRandall Stewart SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph, 274f8829a4aSRandall Stewart aparam_length); 275f8829a4aSRandall Stewart return m_reply; 276f8829a4aSRandall Stewart } /* end switch */ 277f8829a4aSRandall Stewart 278f8829a4aSRandall Stewart /* if 0.0.0.0/::0, add the source address instead */ 279b3f1ea41SRandall Stewart if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) { 280f8829a4aSRandall Stewart sa = (struct sockaddr *)&sa_source; 281f8829a4aSRandall Stewart sctp_asconf_get_source_ip(m, sa); 282ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 283ad81507eSRandall Stewart "process_asconf_add_ip: using source addr "); 284ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 285f8829a4aSRandall Stewart } 286f8829a4aSRandall Stewart /* add the address */ 287a5d547adSRandall Stewart if (sctp_add_remote_addr(stcb, sa, SCTP_DONOT_SETSCOPE, 288a5d547adSRandall Stewart SCTP_ADDR_DYNAMIC_ADDED) != 0) { 289ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 290ad81507eSRandall Stewart "process_asconf_add_ip: error adding address\n"); 291f8829a4aSRandall Stewart m_reply = sctp_asconf_error_response(aph->correlation_id, 292f8829a4aSRandall Stewart SCTP_CAUSE_RESOURCE_SHORTAGE, (uint8_t *) aph, 293f8829a4aSRandall Stewart aparam_length); 294f8829a4aSRandall Stewart } else { 295f8829a4aSRandall Stewart /* notify upper layer */ 296ceaad40aSRandall Stewart sctp_ulp_notify(SCTP_NOTIFY_ASCONF_ADD_IP, stcb, 0, sa, SCTP_SO_NOT_LOCKED); 297f8829a4aSRandall Stewart if (response_required) { 298f8829a4aSRandall Stewart m_reply = 299f8829a4aSRandall Stewart sctp_asconf_success_response(aph->correlation_id); 300f8829a4aSRandall Stewart } 3013c503c28SRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, 3023c503c28SRandall Stewart NULL, SCTP_FROM_SCTP_ASCONF + SCTP_LOC_1); 3033c503c28SRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, 3043c503c28SRandall Stewart stcb, NULL); 305f8829a4aSRandall Stewart } 306f8829a4aSRandall Stewart return m_reply; 307f8829a4aSRandall Stewart } 308f8829a4aSRandall Stewart 309f8829a4aSRandall Stewart static int 3101b649582SRandall Stewart sctp_asconf_del_remote_addrs_except(struct sctp_tcb *stcb, struct sockaddr *src) 311f8829a4aSRandall Stewart { 312f8829a4aSRandall Stewart struct sctp_nets *src_net, *net; 313f8829a4aSRandall Stewart 314f8829a4aSRandall Stewart /* make sure the source address exists as a destination net */ 315f8829a4aSRandall Stewart src_net = sctp_findnet(stcb, src); 316f8829a4aSRandall Stewart if (src_net == NULL) { 317f8829a4aSRandall Stewart /* not found */ 318f8829a4aSRandall Stewart return -1; 319f8829a4aSRandall Stewart } 320f8829a4aSRandall Stewart /* delete all destination addresses except the source */ 321f8829a4aSRandall Stewart TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 322f8829a4aSRandall Stewart if (net != src_net) { 323f8829a4aSRandall Stewart /* delete this address */ 324f8829a4aSRandall Stewart sctp_remove_net(stcb, net); 325ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 326ad81507eSRandall Stewart "asconf_del_remote_addrs_except: deleting "); 327ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, 328ad81507eSRandall Stewart (struct sockaddr *)&net->ro._l_addr); 329f8829a4aSRandall Stewart /* notify upper layer */ 330f8829a4aSRandall Stewart sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0, 331ceaad40aSRandall Stewart (struct sockaddr *)&net->ro._l_addr, SCTP_SO_NOT_LOCKED); 332f8829a4aSRandall Stewart } 333f8829a4aSRandall Stewart } 334f8829a4aSRandall Stewart return 0; 335f8829a4aSRandall Stewart } 336f8829a4aSRandall Stewart 337f8829a4aSRandall Stewart static struct mbuf * 338f8829a4aSRandall Stewart sctp_process_asconf_delete_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph, 339f8829a4aSRandall Stewart struct sctp_tcb *stcb, int response_required) 340f8829a4aSRandall Stewart { 341f8829a4aSRandall Stewart struct mbuf *m_reply = NULL; 342f8829a4aSRandall Stewart struct sockaddr_storage sa_source, sa_store; 343*e6194c2eSMichael Tuexen struct sctp_paramhdr *ph; 344f8829a4aSRandall Stewart uint16_t param_type, param_length, aparam_length; 345f8829a4aSRandall Stewart struct sockaddr *sa; 346f8829a4aSRandall Stewart int zero_address = 0; 347f8829a4aSRandall Stewart int result; 348f8829a4aSRandall Stewart 349*e6194c2eSMichael Tuexen #ifdef INET 350*e6194c2eSMichael Tuexen struct sockaddr_in *sin; 351*e6194c2eSMichael Tuexen struct sctp_ipv4addr_param *v4addr; 352*e6194c2eSMichael Tuexen 353*e6194c2eSMichael Tuexen #endif 354f8829a4aSRandall Stewart #ifdef INET6 355f8829a4aSRandall Stewart struct sockaddr_in6 *sin6; 356f8829a4aSRandall Stewart struct sctp_ipv6addr_param *v6addr; 357f8829a4aSRandall Stewart 358*e6194c2eSMichael Tuexen #endif 359f8829a4aSRandall Stewart 360f8829a4aSRandall Stewart /* get the source IP address for src and 0.0.0.0/::0 delete checks */ 361f8829a4aSRandall Stewart sctp_asconf_get_source_ip(m, (struct sockaddr *)&sa_source); 362f8829a4aSRandall Stewart 363f8829a4aSRandall Stewart aparam_length = ntohs(aph->ph.param_length); 364*e6194c2eSMichael Tuexen ph = (struct sctp_paramhdr *)(aph + 1); 365*e6194c2eSMichael Tuexen param_type = ntohs(ph->param_type); 366*e6194c2eSMichael Tuexen param_length = ntohs(ph->param_length); 367f8829a4aSRandall Stewart 368f8829a4aSRandall Stewart sa = (struct sockaddr *)&sa_store; 369f8829a4aSRandall Stewart switch (param_type) { 370*e6194c2eSMichael Tuexen #ifdef INET 371f8829a4aSRandall Stewart case SCTP_IPV4_ADDRESS: 372f8829a4aSRandall Stewart if (param_length != sizeof(struct sctp_ipv4addr_param)) { 373f8829a4aSRandall Stewart /* invalid param size */ 374f8829a4aSRandall Stewart return NULL; 375f8829a4aSRandall Stewart } 376*e6194c2eSMichael Tuexen v4addr = (struct sctp_ipv4addr_param *)ph; 377f8829a4aSRandall Stewart sin = (struct sockaddr_in *)&sa_store; 378f8829a4aSRandall Stewart bzero(sin, sizeof(*sin)); 379f8829a4aSRandall Stewart sin->sin_family = AF_INET; 380f8829a4aSRandall Stewart sin->sin_len = sizeof(struct sockaddr_in); 381f8829a4aSRandall Stewart sin->sin_port = stcb->rport; 382f8829a4aSRandall Stewart sin->sin_addr.s_addr = v4addr->addr; 383f8829a4aSRandall Stewart if (sin->sin_addr.s_addr == INADDR_ANY) 384f8829a4aSRandall Stewart zero_address = 1; 385ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 386ad81507eSRandall Stewart "process_asconf_delete_ip: deleting "); 387ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 388f8829a4aSRandall Stewart break; 389*e6194c2eSMichael Tuexen #endif 390*e6194c2eSMichael Tuexen #ifdef INET6 391f8829a4aSRandall Stewart case SCTP_IPV6_ADDRESS: 392f8829a4aSRandall Stewart if (param_length != sizeof(struct sctp_ipv6addr_param)) { 393f8829a4aSRandall Stewart /* invalid param size */ 394f8829a4aSRandall Stewart return NULL; 395f8829a4aSRandall Stewart } 396*e6194c2eSMichael Tuexen v6addr = (struct sctp_ipv6addr_param *)ph; 397f8829a4aSRandall Stewart sin6 = (struct sockaddr_in6 *)&sa_store; 398f8829a4aSRandall Stewart bzero(sin6, sizeof(*sin6)); 399f8829a4aSRandall Stewart sin6->sin6_family = AF_INET6; 400f8829a4aSRandall Stewart sin6->sin6_len = sizeof(struct sockaddr_in6); 401f8829a4aSRandall Stewart sin6->sin6_port = stcb->rport; 402f8829a4aSRandall Stewart memcpy(&sin6->sin6_addr, v6addr->addr, 403f8829a4aSRandall Stewart sizeof(struct in6_addr)); 404f8829a4aSRandall Stewart if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) 405f8829a4aSRandall Stewart zero_address = 1; 406ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 407ad81507eSRandall Stewart "process_asconf_delete_ip: deleting "); 408ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 409f8829a4aSRandall Stewart break; 410*e6194c2eSMichael Tuexen #endif 411f8829a4aSRandall Stewart default: 412f8829a4aSRandall Stewart m_reply = sctp_asconf_error_response(aph->correlation_id, 413f8829a4aSRandall Stewart SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph, 414f8829a4aSRandall Stewart aparam_length); 415f8829a4aSRandall Stewart return m_reply; 416f8829a4aSRandall Stewart } 417f8829a4aSRandall Stewart 418f8829a4aSRandall Stewart /* make sure the source address is not being deleted */ 419f8829a4aSRandall Stewart if (sctp_cmpaddr(sa, (struct sockaddr *)&sa_source)) { 420f8829a4aSRandall Stewart /* trying to delete the source address! */ 421ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: tried to delete source addr\n"); 422f8829a4aSRandall Stewart m_reply = sctp_asconf_error_response(aph->correlation_id, 423f8829a4aSRandall Stewart SCTP_CAUSE_DELETING_SRC_ADDR, (uint8_t *) aph, 424f8829a4aSRandall Stewart aparam_length); 425f8829a4aSRandall Stewart return m_reply; 426f8829a4aSRandall Stewart } 427f8829a4aSRandall Stewart /* if deleting 0.0.0.0/::0, delete all addresses except src addr */ 428b3f1ea41SRandall Stewart if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) { 429f8829a4aSRandall Stewart result = sctp_asconf_del_remote_addrs_except(stcb, 430f8829a4aSRandall Stewart (struct sockaddr *)&sa_source); 431f8829a4aSRandall Stewart 432f8829a4aSRandall Stewart if (result) { 433f8829a4aSRandall Stewart /* src address did not exist? */ 434ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: src addr does not exist?\n"); 435f8829a4aSRandall Stewart /* what error to reply with?? */ 436f8829a4aSRandall Stewart m_reply = 437f8829a4aSRandall Stewart sctp_asconf_error_response(aph->correlation_id, 438f8829a4aSRandall Stewart SCTP_CAUSE_REQUEST_REFUSED, (uint8_t *) aph, 439f8829a4aSRandall Stewart aparam_length); 440f8829a4aSRandall Stewart } else if (response_required) { 441f8829a4aSRandall Stewart m_reply = 442f8829a4aSRandall Stewart sctp_asconf_success_response(aph->correlation_id); 443f8829a4aSRandall Stewart } 444f8829a4aSRandall Stewart return m_reply; 445f8829a4aSRandall Stewart } 446f8829a4aSRandall Stewart /* delete the address */ 447f8829a4aSRandall Stewart result = sctp_del_remote_addr(stcb, sa); 448f8829a4aSRandall Stewart /* 449f8829a4aSRandall Stewart * note if result == -2, the address doesn't exist in the asoc but 450f8829a4aSRandall Stewart * since it's being deleted anyways, we just ack the delete -- but 451f8829a4aSRandall Stewart * this probably means something has already gone awry 452f8829a4aSRandall Stewart */ 453f8829a4aSRandall Stewart if (result == -1) { 454f8829a4aSRandall Stewart /* only one address in the asoc */ 455ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: tried to delete last IP addr!\n"); 456f8829a4aSRandall Stewart m_reply = sctp_asconf_error_response(aph->correlation_id, 457f8829a4aSRandall Stewart SCTP_CAUSE_DELETING_LAST_ADDR, (uint8_t *) aph, 458f8829a4aSRandall Stewart aparam_length); 459f8829a4aSRandall Stewart } else { 460f8829a4aSRandall Stewart if (response_required) { 461f8829a4aSRandall Stewart m_reply = sctp_asconf_success_response(aph->correlation_id); 462f8829a4aSRandall Stewart } 463f8829a4aSRandall Stewart /* notify upper layer */ 464ceaad40aSRandall Stewart sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0, sa, SCTP_SO_NOT_LOCKED); 465f8829a4aSRandall Stewart } 466f8829a4aSRandall Stewart return m_reply; 467f8829a4aSRandall Stewart } 468f8829a4aSRandall Stewart 469f8829a4aSRandall Stewart static struct mbuf * 470f8829a4aSRandall Stewart sctp_process_asconf_set_primary(struct mbuf *m, 4711b649582SRandall Stewart struct sctp_asconf_paramhdr *aph, 4721b649582SRandall Stewart struct sctp_tcb *stcb, int response_required) 473f8829a4aSRandall Stewart { 474f8829a4aSRandall Stewart struct mbuf *m_reply = NULL; 475f8829a4aSRandall Stewart struct sockaddr_storage sa_source, sa_store; 476*e6194c2eSMichael Tuexen struct sctp_paramhdr *ph; 477f8829a4aSRandall Stewart uint16_t param_type, param_length, aparam_length; 478f8829a4aSRandall Stewart struct sockaddr *sa; 479f8829a4aSRandall Stewart int zero_address = 0; 480f8829a4aSRandall Stewart 481*e6194c2eSMichael Tuexen #ifdef INET 482*e6194c2eSMichael Tuexen struct sockaddr_in *sin; 483*e6194c2eSMichael Tuexen struct sctp_ipv4addr_param *v4addr; 484*e6194c2eSMichael Tuexen 485*e6194c2eSMichael Tuexen #endif 486f8829a4aSRandall Stewart #ifdef INET6 487f8829a4aSRandall Stewart struct sockaddr_in6 *sin6; 488f8829a4aSRandall Stewart struct sctp_ipv6addr_param *v6addr; 489f8829a4aSRandall Stewart 490*e6194c2eSMichael Tuexen #endif 491f8829a4aSRandall Stewart 492f8829a4aSRandall Stewart aparam_length = ntohs(aph->ph.param_length); 493*e6194c2eSMichael Tuexen ph = (struct sctp_paramhdr *)(aph + 1); 494*e6194c2eSMichael Tuexen param_type = ntohs(ph->param_type); 495*e6194c2eSMichael Tuexen param_length = ntohs(ph->param_length); 496f8829a4aSRandall Stewart 497f8829a4aSRandall Stewart sa = (struct sockaddr *)&sa_store; 498f8829a4aSRandall Stewart switch (param_type) { 499*e6194c2eSMichael Tuexen #ifdef INET 500f8829a4aSRandall Stewart case SCTP_IPV4_ADDRESS: 501f8829a4aSRandall Stewart if (param_length != sizeof(struct sctp_ipv4addr_param)) { 502f8829a4aSRandall Stewart /* invalid param size */ 503f8829a4aSRandall Stewart return NULL; 504f8829a4aSRandall Stewart } 505*e6194c2eSMichael Tuexen v4addr = (struct sctp_ipv4addr_param *)ph; 506f8829a4aSRandall Stewart sin = (struct sockaddr_in *)&sa_store; 507f8829a4aSRandall Stewart bzero(sin, sizeof(*sin)); 508f8829a4aSRandall Stewart sin->sin_family = AF_INET; 509f8829a4aSRandall Stewart sin->sin_len = sizeof(struct sockaddr_in); 510f8829a4aSRandall Stewart sin->sin_addr.s_addr = v4addr->addr; 511f8829a4aSRandall Stewart if (sin->sin_addr.s_addr == INADDR_ANY) 512f8829a4aSRandall Stewart zero_address = 1; 513ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_set_primary: "); 514ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 515f8829a4aSRandall Stewart break; 516*e6194c2eSMichael Tuexen #endif 517*e6194c2eSMichael Tuexen #ifdef INET6 518f8829a4aSRandall Stewart case SCTP_IPV6_ADDRESS: 519f8829a4aSRandall Stewart if (param_length != sizeof(struct sctp_ipv6addr_param)) { 520f8829a4aSRandall Stewart /* invalid param size */ 521f8829a4aSRandall Stewart return NULL; 522f8829a4aSRandall Stewart } 523*e6194c2eSMichael Tuexen v6addr = (struct sctp_ipv6addr_param *)ph; 524f8829a4aSRandall Stewart sin6 = (struct sockaddr_in6 *)&sa_store; 525f8829a4aSRandall Stewart bzero(sin6, sizeof(*sin6)); 526f8829a4aSRandall Stewart sin6->sin6_family = AF_INET6; 527f8829a4aSRandall Stewart sin6->sin6_len = sizeof(struct sockaddr_in6); 528f8829a4aSRandall Stewart memcpy((caddr_t)&sin6->sin6_addr, v6addr->addr, 529f8829a4aSRandall Stewart sizeof(struct in6_addr)); 530f8829a4aSRandall Stewart if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) 531f8829a4aSRandall Stewart zero_address = 1; 532ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_set_primary: "); 533ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 534f8829a4aSRandall Stewart break; 535*e6194c2eSMichael Tuexen #endif 536f8829a4aSRandall Stewart default: 537f8829a4aSRandall Stewart m_reply = sctp_asconf_error_response(aph->correlation_id, 538f8829a4aSRandall Stewart SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph, 539f8829a4aSRandall Stewart aparam_length); 540f8829a4aSRandall Stewart return m_reply; 541f8829a4aSRandall Stewart } 542f8829a4aSRandall Stewart 543f8829a4aSRandall Stewart /* if 0.0.0.0/::0, use the source address instead */ 544b3f1ea41SRandall Stewart if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) { 545f8829a4aSRandall Stewart sa = (struct sockaddr *)&sa_source; 546f8829a4aSRandall Stewart sctp_asconf_get_source_ip(m, sa); 547ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 548ad81507eSRandall Stewart "process_asconf_set_primary: using source addr "); 549ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 550f8829a4aSRandall Stewart } 551f8829a4aSRandall Stewart /* set the primary address */ 552f8829a4aSRandall Stewart if (sctp_set_primary_addr(stcb, sa, NULL) == 0) { 553ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 554ad81507eSRandall Stewart "process_asconf_set_primary: primary address set\n"); 555f8829a4aSRandall Stewart /* notify upper layer */ 556ceaad40aSRandall Stewart sctp_ulp_notify(SCTP_NOTIFY_ASCONF_SET_PRIMARY, stcb, 0, sa, SCTP_SO_NOT_LOCKED); 557f8829a4aSRandall Stewart 558f8829a4aSRandall Stewart if (response_required) { 559f8829a4aSRandall Stewart m_reply = sctp_asconf_success_response(aph->correlation_id); 560f8829a4aSRandall Stewart } 561851b7298SRandall Stewart /* 562851b7298SRandall Stewart * Mobility adaptation. Ideally, when the reception of SET 563851b7298SRandall Stewart * PRIMARY with DELETE IP ADDRESS of the previous primary 564851b7298SRandall Stewart * destination, unacknowledged DATA are retransmitted 565851b7298SRandall Stewart * immediately to the new primary destination for seamless 566b5c16493SMichael Tuexen * handover. If the destination is UNCONFIRMED and marked to 567b5c16493SMichael Tuexen * REQ_PRIM, The retransmission occur when reception of the 568b5c16493SMichael Tuexen * HEARTBEAT-ACK. (See sctp_handle_heartbeat_ack in 569851b7298SRandall Stewart * sctp_input.c) Also, when change of the primary 570851b7298SRandall Stewart * destination, it is better that all subsequent new DATA 571851b7298SRandall Stewart * containing already queued DATA are transmitted to the new 572851b7298SRandall Stewart * primary destination. (by micchie) 573851b7298SRandall Stewart */ 574851b7298SRandall Stewart if ((sctp_is_mobility_feature_on(stcb->sctp_ep, 575851b7298SRandall Stewart SCTP_MOBILITY_BASE) || 576851b7298SRandall Stewart sctp_is_mobility_feature_on(stcb->sctp_ep, 577851b7298SRandall Stewart SCTP_MOBILITY_FASTHANDOFF)) && 578851b7298SRandall Stewart sctp_is_mobility_feature_on(stcb->sctp_ep, 579851b7298SRandall Stewart SCTP_MOBILITY_PRIM_DELETED) && 580851b7298SRandall Stewart (stcb->asoc.primary_destination->dest_state & 581851b7298SRandall Stewart SCTP_ADDR_UNCONFIRMED) == 0) { 582851b7298SRandall Stewart 583851b7298SRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_PRIM_DELETED, stcb->sctp_ep, stcb, NULL, SCTP_FROM_SCTP_TIMER + SCTP_LOC_7); 584851b7298SRandall Stewart if (sctp_is_mobility_feature_on(stcb->sctp_ep, 585851b7298SRandall Stewart SCTP_MOBILITY_FASTHANDOFF)) { 586851b7298SRandall Stewart sctp_assoc_immediate_retrans(stcb, 587851b7298SRandall Stewart stcb->asoc.primary_destination); 588851b7298SRandall Stewart } 589851b7298SRandall Stewart if (sctp_is_mobility_feature_on(stcb->sctp_ep, 590851b7298SRandall Stewart SCTP_MOBILITY_BASE)) { 5919eea4a2dSMichael Tuexen sctp_move_chunks_from_net(stcb, 5929eea4a2dSMichael Tuexen stcb->asoc.deleted_primary); 593851b7298SRandall Stewart } 594851b7298SRandall Stewart sctp_delete_prim_timer(stcb->sctp_ep, stcb, 595851b7298SRandall Stewart stcb->asoc.deleted_primary); 596851b7298SRandall Stewart } 597f8829a4aSRandall Stewart } else { 598f8829a4aSRandall Stewart /* couldn't set the requested primary address! */ 599ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 600ad81507eSRandall Stewart "process_asconf_set_primary: set primary failed!\n"); 601f8829a4aSRandall Stewart /* must have been an invalid address, so report */ 602f8829a4aSRandall Stewart m_reply = sctp_asconf_error_response(aph->correlation_id, 603f8829a4aSRandall Stewart SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph, 604f8829a4aSRandall Stewart aparam_length); 605f8829a4aSRandall Stewart } 606f8829a4aSRandall Stewart 607f8829a4aSRandall Stewart return m_reply; 608f8829a4aSRandall Stewart } 609f8829a4aSRandall Stewart 610f8829a4aSRandall Stewart /* 611f8829a4aSRandall Stewart * handles an ASCONF chunk. 612f8829a4aSRandall Stewart * if all parameters are processed ok, send a plain (empty) ASCONF-ACK 613f8829a4aSRandall Stewart */ 614f8829a4aSRandall Stewart void 615f8829a4aSRandall Stewart sctp_handle_asconf(struct mbuf *m, unsigned int offset, 6162afb3e84SRandall Stewart struct sctp_asconf_chunk *cp, struct sctp_tcb *stcb, 6172afb3e84SRandall Stewart int first) 618f8829a4aSRandall Stewart { 619f8829a4aSRandall Stewart struct sctp_association *asoc; 620f8829a4aSRandall Stewart uint32_t serial_num; 6212afb3e84SRandall Stewart struct mbuf *n, *m_ack, *m_result, *m_tail; 622f8829a4aSRandall Stewart struct sctp_asconf_ack_chunk *ack_cp; 623f8829a4aSRandall Stewart struct sctp_asconf_paramhdr *aph, *ack_aph; 624f8829a4aSRandall Stewart struct sctp_ipv6addr_param *p_addr; 625f8829a4aSRandall Stewart unsigned int asconf_limit; 626f8829a4aSRandall Stewart int error = 0; /* did an error occur? */ 627f8829a4aSRandall Stewart 628f8829a4aSRandall Stewart /* asconf param buffer */ 629f42a358aSRandall Stewart uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE]; 6302afb3e84SRandall Stewart struct sctp_asconf_ack *ack, *ack_next; 631f8829a4aSRandall Stewart 632f8829a4aSRandall Stewart /* verify minimum length */ 633f8829a4aSRandall Stewart if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_chunk)) { 634ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 635ad81507eSRandall Stewart "handle_asconf: chunk too small = %xh\n", 636f8829a4aSRandall Stewart ntohs(cp->ch.chunk_length)); 637f8829a4aSRandall Stewart return; 638f8829a4aSRandall Stewart } 639f8829a4aSRandall Stewart asoc = &stcb->asoc; 640f8829a4aSRandall Stewart serial_num = ntohl(cp->serial_number); 641f8829a4aSRandall Stewart 64220b07a4dSMichael Tuexen if (SCTP_TSN_GE(asoc->asconf_seq_in, serial_num)) { 643f8829a4aSRandall Stewart /* got a duplicate ASCONF */ 644ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 645ad81507eSRandall Stewart "handle_asconf: got duplicate serial number = %xh\n", 646f8829a4aSRandall Stewart serial_num); 647f8829a4aSRandall Stewart return; 648f8829a4aSRandall Stewart } else if (serial_num != (asoc->asconf_seq_in + 1)) { 649ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: incorrect serial number = %xh (expected next = %xh)\n", 650f8829a4aSRandall Stewart serial_num, asoc->asconf_seq_in + 1); 651f8829a4aSRandall Stewart return; 652f8829a4aSRandall Stewart } 653f8829a4aSRandall Stewart /* it's the expected "next" sequence number, so process it */ 654f8829a4aSRandall Stewart asoc->asconf_seq_in = serial_num; /* update sequence */ 655f8829a4aSRandall Stewart /* get length of all the param's in the ASCONF */ 656f8829a4aSRandall Stewart asconf_limit = offset + ntohs(cp->ch.chunk_length); 657ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 658ad81507eSRandall Stewart "handle_asconf: asconf_limit=%u, sequence=%xh\n", 659f8829a4aSRandall Stewart asconf_limit, serial_num); 6602afb3e84SRandall Stewart 6612afb3e84SRandall Stewart if (first) { 6622afb3e84SRandall Stewart /* delete old cache */ 663*e6194c2eSMichael Tuexen SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: Now processing first ASCONF. Try to delete old cache\n"); 6642afb3e84SRandall Stewart 6654a9ef3f8SMichael Tuexen TAILQ_FOREACH_SAFE(ack, &asoc->asconf_ack_sent, next, ack_next) { 6662afb3e84SRandall Stewart if (ack->serial_number == serial_num) 6672afb3e84SRandall Stewart break; 6682afb3e84SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: delete old(%u) < first(%u)\n", 6692afb3e84SRandall Stewart ack->serial_number, serial_num); 6704a9ef3f8SMichael Tuexen TAILQ_REMOVE(&asoc->asconf_ack_sent, ack, next); 6712afb3e84SRandall Stewart if (ack->data != NULL) { 6722afb3e84SRandall Stewart sctp_m_freem(ack->data); 6732afb3e84SRandall Stewart } 674b3f1ea41SRandall Stewart SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_asconf_ack), ack); 6752afb3e84SRandall Stewart } 676f8829a4aSRandall Stewart } 677139bc87fSRandall Stewart m_ack = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_ack_chunk), 0, 678f8829a4aSRandall Stewart M_DONTWAIT, 1, MT_DATA); 679f8829a4aSRandall Stewart if (m_ack == NULL) { 680ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 681ad81507eSRandall Stewart "handle_asconf: couldn't get mbuf!\n"); 682f8829a4aSRandall Stewart return; 683f8829a4aSRandall Stewart } 684f8829a4aSRandall Stewart m_tail = m_ack; /* current reply chain's tail */ 685f8829a4aSRandall Stewart 686f8829a4aSRandall Stewart /* fill in ASCONF-ACK header */ 687f8829a4aSRandall Stewart ack_cp = mtod(m_ack, struct sctp_asconf_ack_chunk *); 688f8829a4aSRandall Stewart ack_cp->ch.chunk_type = SCTP_ASCONF_ACK; 689f8829a4aSRandall Stewart ack_cp->ch.chunk_flags = 0; 690f8829a4aSRandall Stewart ack_cp->serial_number = htonl(serial_num); 691f8829a4aSRandall Stewart /* set initial lengths (eg. just an ASCONF-ACK), ntohx at the end! */ 692139bc87fSRandall Stewart SCTP_BUF_LEN(m_ack) = sizeof(struct sctp_asconf_ack_chunk); 693f8829a4aSRandall Stewart ack_cp->ch.chunk_length = sizeof(struct sctp_asconf_ack_chunk); 694f8829a4aSRandall Stewart 695f8829a4aSRandall Stewart /* skip the lookup address parameter */ 696f8829a4aSRandall Stewart offset += sizeof(struct sctp_asconf_chunk); 697f8829a4aSRandall Stewart p_addr = (struct sctp_ipv6addr_param *)sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), (uint8_t *) & aparam_buf); 698f8829a4aSRandall Stewart if (p_addr == NULL) { 699ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 700ad81507eSRandall Stewart "handle_asconf: couldn't get lookup addr!\n"); 701f8829a4aSRandall Stewart /* respond with a missing/invalid mandatory parameter error */ 702f8829a4aSRandall Stewart return; 703f8829a4aSRandall Stewart } 704f8829a4aSRandall Stewart /* param_length is already validated in process_control... */ 705f8829a4aSRandall Stewart offset += ntohs(p_addr->ph.param_length); /* skip lookup addr */ 706f8829a4aSRandall Stewart 707f8829a4aSRandall Stewart /* get pointer to first asconf param in ASCONF-ACK */ 708f8829a4aSRandall Stewart ack_aph = (struct sctp_asconf_paramhdr *)(mtod(m_ack, caddr_t)+sizeof(struct sctp_asconf_ack_chunk)); 709f8829a4aSRandall Stewart if (ack_aph == NULL) { 710ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "Gak in asconf2\n"); 711f8829a4aSRandall Stewart return; 712f8829a4aSRandall Stewart } 713f8829a4aSRandall Stewart /* get pointer to first asconf param in ASCONF */ 714f8829a4aSRandall Stewart aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, sizeof(struct sctp_asconf_paramhdr), (uint8_t *) & aparam_buf); 715f8829a4aSRandall Stewart if (aph == NULL) { 716ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "Empty ASCONF received?\n"); 717f8829a4aSRandall Stewart goto send_reply; 718f8829a4aSRandall Stewart } 719f8829a4aSRandall Stewart /* process through all parameters */ 720f8829a4aSRandall Stewart while (aph != NULL) { 721f8829a4aSRandall Stewart unsigned int param_length, param_type; 722f8829a4aSRandall Stewart 723f8829a4aSRandall Stewart param_type = ntohs(aph->ph.param_type); 724f8829a4aSRandall Stewart param_length = ntohs(aph->ph.param_length); 725f8829a4aSRandall Stewart if (offset + param_length > asconf_limit) { 726f8829a4aSRandall Stewart /* parameter goes beyond end of chunk! */ 727f8829a4aSRandall Stewart sctp_m_freem(m_ack); 728f8829a4aSRandall Stewart return; 729f8829a4aSRandall Stewart } 730f8829a4aSRandall Stewart m_result = NULL; 731f8829a4aSRandall Stewart 732f8829a4aSRandall Stewart if (param_length > sizeof(aparam_buf)) { 733ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) larger than buffer size!\n", param_length); 734f8829a4aSRandall Stewart sctp_m_freem(m_ack); 735f8829a4aSRandall Stewart return; 736f8829a4aSRandall Stewart } 737f8829a4aSRandall Stewart if (param_length <= sizeof(struct sctp_paramhdr)) { 738ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) too short\n", param_length); 739f8829a4aSRandall Stewart sctp_m_freem(m_ack); 740f8829a4aSRandall Stewart } 741f8829a4aSRandall Stewart /* get the entire parameter */ 742f8829a4aSRandall Stewart aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf); 743f8829a4aSRandall Stewart if (aph == NULL) { 744ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: couldn't get entire param\n"); 745f8829a4aSRandall Stewart sctp_m_freem(m_ack); 746f8829a4aSRandall Stewart return; 747f8829a4aSRandall Stewart } 748f8829a4aSRandall Stewart switch (param_type) { 749f8829a4aSRandall Stewart case SCTP_ADD_IP_ADDRESS: 750f8829a4aSRandall Stewart asoc->peer_supports_asconf = 1; 751f8829a4aSRandall Stewart m_result = sctp_process_asconf_add_ip(m, aph, stcb, 752f8829a4aSRandall Stewart error); 753f8829a4aSRandall Stewart break; 754f8829a4aSRandall Stewart case SCTP_DEL_IP_ADDRESS: 755f8829a4aSRandall Stewart asoc->peer_supports_asconf = 1; 756f8829a4aSRandall Stewart m_result = sctp_process_asconf_delete_ip(m, aph, stcb, 757f8829a4aSRandall Stewart error); 758f8829a4aSRandall Stewart break; 759f8829a4aSRandall Stewart case SCTP_ERROR_CAUSE_IND: 760f8829a4aSRandall Stewart /* not valid in an ASCONF chunk */ 761f8829a4aSRandall Stewart break; 762f8829a4aSRandall Stewart case SCTP_SET_PRIM_ADDR: 763f8829a4aSRandall Stewart asoc->peer_supports_asconf = 1; 764f8829a4aSRandall Stewart m_result = sctp_process_asconf_set_primary(m, aph, 765f8829a4aSRandall Stewart stcb, error); 766f8829a4aSRandall Stewart break; 767830d754dSRandall Stewart case SCTP_NAT_VTAGS: 768830d754dSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: sees a NAT VTAG state parameter\n"); 769830d754dSRandall Stewart break; 770f8829a4aSRandall Stewart case SCTP_SUCCESS_REPORT: 771f8829a4aSRandall Stewart /* not valid in an ASCONF chunk */ 772f8829a4aSRandall Stewart break; 773f8829a4aSRandall Stewart case SCTP_ULP_ADAPTATION: 774f8829a4aSRandall Stewart /* FIX */ 775f8829a4aSRandall Stewart break; 776f8829a4aSRandall Stewart default: 777f8829a4aSRandall Stewart if ((param_type & 0x8000) == 0) { 778f8829a4aSRandall Stewart /* Been told to STOP at this param */ 779f8829a4aSRandall Stewart asconf_limit = offset; 780f8829a4aSRandall Stewart /* 781f8829a4aSRandall Stewart * FIX FIX - We need to call 782f8829a4aSRandall Stewart * sctp_arethere_unrecognized_parameters() 783f8829a4aSRandall Stewart * to get a operr and send it for any 784f8829a4aSRandall Stewart * param's with the 0x4000 bit set OR do it 785f8829a4aSRandall Stewart * here ourselves... note we still must STOP 786f8829a4aSRandall Stewart * if the 0x8000 bit is clear. 787f8829a4aSRandall Stewart */ 788f8829a4aSRandall Stewart } 789f8829a4aSRandall Stewart /* unknown/invalid param type */ 790f8829a4aSRandall Stewart break; 791f8829a4aSRandall Stewart } /* switch */ 792f8829a4aSRandall Stewart 793f8829a4aSRandall Stewart /* add any (error) result to the reply mbuf chain */ 794f8829a4aSRandall Stewart if (m_result != NULL) { 795139bc87fSRandall Stewart SCTP_BUF_NEXT(m_tail) = m_result; 796f8829a4aSRandall Stewart m_tail = m_result; 797f8829a4aSRandall Stewart /* update lengths, make sure it's aligned too */ 798139bc87fSRandall Stewart SCTP_BUF_LEN(m_result) = SCTP_SIZE32(SCTP_BUF_LEN(m_result)); 799139bc87fSRandall Stewart ack_cp->ch.chunk_length += SCTP_BUF_LEN(m_result); 800f8829a4aSRandall Stewart /* set flag to force success reports */ 801f8829a4aSRandall Stewart error = 1; 802f8829a4aSRandall Stewart } 803f8829a4aSRandall Stewart offset += SCTP_SIZE32(param_length); 804f8829a4aSRandall Stewart /* update remaining ASCONF message length to process */ 805f8829a4aSRandall Stewart if (offset >= asconf_limit) { 806f8829a4aSRandall Stewart /* no more data in the mbuf chain */ 807f8829a4aSRandall Stewart break; 808f8829a4aSRandall Stewart } 809f8829a4aSRandall Stewart /* get pointer to next asconf param */ 810f8829a4aSRandall Stewart aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, 811f8829a4aSRandall Stewart sizeof(struct sctp_asconf_paramhdr), 812f8829a4aSRandall Stewart (uint8_t *) & aparam_buf); 813f8829a4aSRandall Stewart if (aph == NULL) { 814f8829a4aSRandall Stewart /* can't get an asconf paramhdr */ 815ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: can't get asconf param hdr!\n"); 816f8829a4aSRandall Stewart /* FIX ME - add error here... */ 817f8829a4aSRandall Stewart } 818ad81507eSRandall Stewart } 819f8829a4aSRandall Stewart 820f8829a4aSRandall Stewart send_reply: 821f8829a4aSRandall Stewart ack_cp->ch.chunk_length = htons(ack_cp->ch.chunk_length); 822f8829a4aSRandall Stewart /* save the ASCONF-ACK reply */ 823b3f1ea41SRandall Stewart ack = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_asconf_ack), 8242afb3e84SRandall Stewart struct sctp_asconf_ack); 8252afb3e84SRandall Stewart if (ack == NULL) { 8262afb3e84SRandall Stewart sctp_m_freem(m_ack); 8272afb3e84SRandall Stewart return; 8282afb3e84SRandall Stewart } 8292afb3e84SRandall Stewart ack->serial_number = serial_num; 8302afb3e84SRandall Stewart ack->last_sent_to = NULL; 8312afb3e84SRandall Stewart ack->data = m_ack; 832fc066a61SMichael Tuexen ack->len = 0; 833*e6194c2eSMichael Tuexen for (n = m_ack; n != NULL; n = SCTP_BUF_NEXT(n)) { 8342afb3e84SRandall Stewart ack->len += SCTP_BUF_LEN(n); 8352afb3e84SRandall Stewart } 8362afb3e84SRandall Stewart TAILQ_INSERT_TAIL(&stcb->asoc.asconf_ack_sent, ack, next); 837f8829a4aSRandall Stewart 838f8829a4aSRandall Stewart /* see if last_control_chunk_from is set properly (use IP src addr) */ 839f8829a4aSRandall Stewart if (stcb->asoc.last_control_chunk_from == NULL) { 840f8829a4aSRandall Stewart /* 841f8829a4aSRandall Stewart * this could happen if the source address was just newly 842f8829a4aSRandall Stewart * added 843f8829a4aSRandall Stewart */ 844f8829a4aSRandall Stewart struct ip *iph; 845f8829a4aSRandall Stewart struct sctphdr *sh; 846f8829a4aSRandall Stewart struct sockaddr_storage from_store; 847f8829a4aSRandall Stewart struct sockaddr *from = (struct sockaddr *)&from_store; 848f8829a4aSRandall Stewart 849ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: looking up net for IP source address\n"); 850f8829a4aSRandall Stewart /* pullup already done, IP options already stripped */ 851f8829a4aSRandall Stewart iph = mtod(m, struct ip *); 8525e2c2d87SRandall Stewart switch (iph->ip_v) { 853*e6194c2eSMichael Tuexen #ifdef INET 8545e2c2d87SRandall Stewart case IPVERSION: 8555e2c2d87SRandall Stewart { 856f8829a4aSRandall Stewart struct sockaddr_in *from4; 857f8829a4aSRandall Stewart 858*e6194c2eSMichael Tuexen sh = (struct sctphdr *)((caddr_t)iph + sizeof(*iph)); 859f8829a4aSRandall Stewart from4 = (struct sockaddr_in *)&from_store; 860f8829a4aSRandall Stewart bzero(from4, sizeof(*from4)); 861f8829a4aSRandall Stewart from4->sin_family = AF_INET; 862f8829a4aSRandall Stewart from4->sin_len = sizeof(struct sockaddr_in); 863f8829a4aSRandall Stewart from4->sin_addr.s_addr = iph->ip_src.s_addr; 864f8829a4aSRandall Stewart from4->sin_port = sh->src_port; 8655e2c2d87SRandall Stewart break; 8665e2c2d87SRandall Stewart } 867*e6194c2eSMichael Tuexen #endif 8685e2c2d87SRandall Stewart #ifdef INET6 8695e2c2d87SRandall Stewart case IPV6_VERSION >> 4: 8705e2c2d87SRandall Stewart { 871f8829a4aSRandall Stewart struct ip6_hdr *ip6; 872f8829a4aSRandall Stewart struct sockaddr_in6 *from6; 873f8829a4aSRandall Stewart 874f8829a4aSRandall Stewart ip6 = mtod(m, struct ip6_hdr *); 875*e6194c2eSMichael Tuexen sh = (struct sctphdr *)((caddr_t)ip6 + sizeof(*ip6)); 876f8829a4aSRandall Stewart from6 = (struct sockaddr_in6 *)&from_store; 877f8829a4aSRandall Stewart bzero(from6, sizeof(*from6)); 878f8829a4aSRandall Stewart from6->sin6_family = AF_INET6; 879f8829a4aSRandall Stewart from6->sin6_len = sizeof(struct sockaddr_in6); 880f8829a4aSRandall Stewart from6->sin6_addr = ip6->ip6_src; 881f8829a4aSRandall Stewart from6->sin6_port = sh->src_port; 8825e2c2d87SRandall Stewart /* 8835e2c2d87SRandall Stewart * Get the scopes in properly to the sin6 8845e2c2d87SRandall Stewart * addr's 8855e2c2d87SRandall Stewart */ 886f8829a4aSRandall Stewart /* we probably don't need these operations */ 887f8829a4aSRandall Stewart (void)sa6_recoverscope(from6); 888fc14de76SRandall Stewart sa6_embedscope(from6, 889482444b4SRandall Stewart MODULE_GLOBAL(ip6_use_defzone)); 890fc14de76SRandall Stewart 8915e2c2d87SRandall Stewart break; 8925e2c2d87SRandall Stewart } 8935e2c2d87SRandall Stewart #endif 8945e2c2d87SRandall Stewart default: 895f8829a4aSRandall Stewart /* unknown address type */ 896f8829a4aSRandall Stewart from = NULL; 897f8829a4aSRandall Stewart } 898f8829a4aSRandall Stewart if (from != NULL) { 899ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "Looking for IP source: "); 900ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, from); 901f8829a4aSRandall Stewart /* look up the from address */ 902f8829a4aSRandall Stewart stcb->asoc.last_control_chunk_from = sctp_findnet(stcb, from); 903f8829a4aSRandall Stewart #ifdef SCTP_DEBUG 904ad81507eSRandall Stewart if (stcb->asoc.last_control_chunk_from == NULL) 905ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: IP source address not found?!\n"); 906ad81507eSRandall Stewart #endif 907f8829a4aSRandall Stewart } 908f8829a4aSRandall Stewart } 909f8829a4aSRandall Stewart } 910f8829a4aSRandall Stewart 911f8829a4aSRandall Stewart /* 912f8829a4aSRandall Stewart * does the address match? returns 0 if not, 1 if so 913f8829a4aSRandall Stewart */ 914f8829a4aSRandall Stewart static uint32_t 915f8829a4aSRandall Stewart sctp_asconf_addr_match(struct sctp_asconf_addr *aa, struct sockaddr *sa) 916f8829a4aSRandall Stewart { 917*e6194c2eSMichael Tuexen switch (sa->sa_family) { 918f8829a4aSRandall Stewart #ifdef INET6 919*e6194c2eSMichael Tuexen case AF_INET6: 920*e6194c2eSMichael Tuexen { 921f8829a4aSRandall Stewart /* XXX scopeid */ 922f8829a4aSRandall Stewart struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa; 923f8829a4aSRandall Stewart 924f8829a4aSRandall Stewart if ((aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) && 925f8829a4aSRandall Stewart (memcmp(&aa->ap.addrp.addr, &sin6->sin6_addr, 926f8829a4aSRandall Stewart sizeof(struct in6_addr)) == 0)) { 927f8829a4aSRandall Stewart return (1); 928f8829a4aSRandall Stewart } 929*e6194c2eSMichael Tuexen break; 930*e6194c2eSMichael Tuexen } 931*e6194c2eSMichael Tuexen #endif 932*e6194c2eSMichael Tuexen #ifdef INET 933*e6194c2eSMichael Tuexen case AF_INET: 934*e6194c2eSMichael Tuexen { 935f8829a4aSRandall Stewart struct sockaddr_in *sin = (struct sockaddr_in *)sa; 936f8829a4aSRandall Stewart 937f8829a4aSRandall Stewart if ((aa->ap.addrp.ph.param_type == SCTP_IPV4_ADDRESS) && 938f8829a4aSRandall Stewart (memcmp(&aa->ap.addrp.addr, &sin->sin_addr, 939f8829a4aSRandall Stewart sizeof(struct in_addr)) == 0)) { 940f8829a4aSRandall Stewart return (1); 941f8829a4aSRandall Stewart } 942*e6194c2eSMichael Tuexen break; 943*e6194c2eSMichael Tuexen } 944*e6194c2eSMichael Tuexen #endif 945*e6194c2eSMichael Tuexen default: 946*e6194c2eSMichael Tuexen break; 947f8829a4aSRandall Stewart } 948f8829a4aSRandall Stewart return (0); 949f8829a4aSRandall Stewart } 950f8829a4aSRandall Stewart 951f8829a4aSRandall Stewart /* 952c54a18d2SRandall Stewart * does the address match? returns 0 if not, 1 if so 953c54a18d2SRandall Stewart */ 954c54a18d2SRandall Stewart static uint32_t 955*e6194c2eSMichael Tuexen sctp_addr_match(struct sctp_paramhdr *ph, struct sockaddr *sa) 956c54a18d2SRandall Stewart { 957c54a18d2SRandall Stewart uint16_t param_type, param_length; 958c54a18d2SRandall Stewart 959*e6194c2eSMichael Tuexen param_type = ntohs(ph->param_type); 960*e6194c2eSMichael Tuexen param_length = ntohs(ph->param_length); 961*e6194c2eSMichael Tuexen switch (sa->sa_family) { 962d6af161aSRandall Stewart #ifdef INET6 963*e6194c2eSMichael Tuexen case AF_INET6: 964*e6194c2eSMichael Tuexen { 965c54a18d2SRandall Stewart /* XXX scopeid */ 966c54a18d2SRandall Stewart struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa; 967*e6194c2eSMichael Tuexen struct sctp_ipv6addr_param *v6addr; 968c54a18d2SRandall Stewart 969*e6194c2eSMichael Tuexen v6addr = (struct sctp_ipv6addr_param *)ph; 970c54a18d2SRandall Stewart if ((param_type == SCTP_IPV6_ADDRESS) && 971c54a18d2SRandall Stewart param_length == sizeof(struct sctp_ipv6addr_param) && 972c54a18d2SRandall Stewart (memcmp(&v6addr->addr, &sin6->sin6_addr, 973c54a18d2SRandall Stewart sizeof(struct in6_addr)) == 0)) { 974c54a18d2SRandall Stewart return (1); 975c54a18d2SRandall Stewart } 976*e6194c2eSMichael Tuexen break; 977d6af161aSRandall Stewart } 978d6af161aSRandall Stewart #endif 979*e6194c2eSMichael Tuexen #ifdef INET 980*e6194c2eSMichael Tuexen case AF_INET: 981*e6194c2eSMichael Tuexen { 982c54a18d2SRandall Stewart struct sockaddr_in *sin = (struct sockaddr_in *)sa; 983*e6194c2eSMichael Tuexen struct sctp_ipv4addr_param *v4addr; 984c54a18d2SRandall Stewart 985*e6194c2eSMichael Tuexen v4addr = (struct sctp_ipv4addr_param *)ph; 986c54a18d2SRandall Stewart if ((param_type == SCTP_IPV4_ADDRESS) && 987c54a18d2SRandall Stewart param_length == sizeof(struct sctp_ipv4addr_param) && 988c54a18d2SRandall Stewart (memcmp(&v4addr->addr, &sin->sin_addr, 989c54a18d2SRandall Stewart sizeof(struct in_addr)) == 0)) { 990c54a18d2SRandall Stewart return (1); 991c54a18d2SRandall Stewart } 992*e6194c2eSMichael Tuexen break; 993*e6194c2eSMichael Tuexen } 994*e6194c2eSMichael Tuexen #endif 995*e6194c2eSMichael Tuexen default: 996*e6194c2eSMichael Tuexen break; 997c54a18d2SRandall Stewart } 998c54a18d2SRandall Stewart return (0); 999c54a18d2SRandall Stewart } 1000c54a18d2SRandall Stewart 1001c54a18d2SRandall Stewart /* 1002f8829a4aSRandall Stewart * Cleanup for non-responded/OP ERR'd ASCONF 1003f8829a4aSRandall Stewart */ 1004f8829a4aSRandall Stewart void 1005f8829a4aSRandall Stewart sctp_asconf_cleanup(struct sctp_tcb *stcb, struct sctp_nets *net) 1006f8829a4aSRandall Stewart { 1007f8829a4aSRandall Stewart /* mark peer as ASCONF incapable */ 1008f8829a4aSRandall Stewart stcb->asoc.peer_supports_asconf = 0; 1009f8829a4aSRandall Stewart /* 1010f8829a4aSRandall Stewart * clear out any existing asconfs going out 1011f8829a4aSRandall Stewart */ 10123c503c28SRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, net, 10133c503c28SRandall Stewart SCTP_FROM_SCTP_ASCONF + SCTP_LOC_2); 1014c54a18d2SRandall Stewart stcb->asoc.asconf_seq_out_acked = stcb->asoc.asconf_seq_out; 1015f8829a4aSRandall Stewart /* remove the old ASCONF on our outbound queue */ 1016f8829a4aSRandall Stewart sctp_toss_old_asconf(stcb); 1017f8829a4aSRandall Stewart } 1018f8829a4aSRandall Stewart 1019f8829a4aSRandall Stewart /* 10202dad8a55SRandall Stewart * cleanup any cached source addresses that may be topologically 10212dad8a55SRandall Stewart * incorrect after a new address has been added to this interface. 10222dad8a55SRandall Stewart */ 10232dad8a55SRandall Stewart static void 10242dad8a55SRandall Stewart sctp_asconf_nets_cleanup(struct sctp_tcb *stcb, struct sctp_ifn *ifn) 10252dad8a55SRandall Stewart { 10262dad8a55SRandall Stewart struct sctp_nets *net; 10272dad8a55SRandall Stewart 10282dad8a55SRandall Stewart /* 10292dad8a55SRandall Stewart * Ideally, we want to only clear cached routes and source addresses 10302dad8a55SRandall Stewart * that are topologically incorrect. But since there is no easy way 10312dad8a55SRandall Stewart * to know whether the newly added address on the ifn would cause a 10322dad8a55SRandall Stewart * routing change (i.e. a new egress interface would be chosen) 10332dad8a55SRandall Stewart * without doing a new routing lookup and source address selection, 10342dad8a55SRandall Stewart * we will (for now) just flush any cached route using a different 10352dad8a55SRandall Stewart * ifn (and cached source addrs) and let output re-choose them 10362dad8a55SRandall Stewart * during the next send on that net. 10372dad8a55SRandall Stewart */ 10382dad8a55SRandall Stewart TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 10392dad8a55SRandall Stewart /* 10402dad8a55SRandall Stewart * clear any cached route (and cached source address) if the 10412dad8a55SRandall Stewart * route's interface is NOT the same as the address change. 10422dad8a55SRandall Stewart * If it's the same interface, just clear the cached source 10432dad8a55SRandall Stewart * address. 10442dad8a55SRandall Stewart */ 10452dad8a55SRandall Stewart if (SCTP_ROUTE_HAS_VALID_IFN(&net->ro) && 1046fc066a61SMichael Tuexen ((ifn == NULL) || 1047fc066a61SMichael Tuexen (SCTP_GET_IF_INDEX_FROM_ROUTE(&net->ro) != ifn->ifn_index))) { 10482dad8a55SRandall Stewart /* clear any cached route */ 10492dad8a55SRandall Stewart RTFREE(net->ro.ro_rt); 10502dad8a55SRandall Stewart net->ro.ro_rt = NULL; 10512dad8a55SRandall Stewart } 10522dad8a55SRandall Stewart /* clear any cached source address */ 10532dad8a55SRandall Stewart if (net->src_addr_selected) { 10542dad8a55SRandall Stewart sctp_free_ifa(net->ro._s_addr); 10552dad8a55SRandall Stewart net->ro._s_addr = NULL; 10562dad8a55SRandall Stewart net->src_addr_selected = 0; 10572dad8a55SRandall Stewart } 10582dad8a55SRandall Stewart } 10592dad8a55SRandall Stewart } 10602dad8a55SRandall Stewart 1061851b7298SRandall Stewart 1062851b7298SRandall Stewart void 1063851b7298SRandall Stewart sctp_assoc_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *dstnet) 1064851b7298SRandall Stewart { 1065851b7298SRandall Stewart int error; 1066851b7298SRandall Stewart 1067851b7298SRandall Stewart if (dstnet->dest_state & SCTP_ADDR_UNCONFIRMED) { 1068851b7298SRandall Stewart return; 1069851b7298SRandall Stewart } 1070851b7298SRandall Stewart if (stcb->asoc.deleted_primary == NULL) { 1071851b7298SRandall Stewart return; 1072851b7298SRandall Stewart } 1073851b7298SRandall Stewart if (!TAILQ_EMPTY(&stcb->asoc.sent_queue)) { 1074b27a6b7dSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "assoc_immediate_retrans: Deleted primary is "); 1075851b7298SRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &stcb->asoc.deleted_primary->ro._l_addr.sa); 1076851b7298SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "Current Primary is "); 1077851b7298SRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &stcb->asoc.primary_destination->ro._l_addr.sa); 1078851b7298SRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, 1079851b7298SRandall Stewart stcb->asoc.deleted_primary, 1080851b7298SRandall Stewart SCTP_FROM_SCTP_TIMER + SCTP_LOC_8); 1081851b7298SRandall Stewart stcb->asoc.num_send_timers_up--; 1082851b7298SRandall Stewart if (stcb->asoc.num_send_timers_up < 0) { 1083851b7298SRandall Stewart stcb->asoc.num_send_timers_up = 0; 1084851b7298SRandall Stewart } 1085851b7298SRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 1086851b7298SRandall Stewart error = sctp_t3rxt_timer(stcb->sctp_ep, stcb, 1087851b7298SRandall Stewart stcb->asoc.deleted_primary); 1088851b7298SRandall Stewart if (error) { 1089851b7298SRandall Stewart SCTP_INP_DECR_REF(stcb->sctp_ep); 1090851b7298SRandall Stewart return; 1091851b7298SRandall Stewart } 1092851b7298SRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 1093851b7298SRandall Stewart #ifdef SCTP_AUDITING_ENABLED 1094f31e6c7fSMichael Tuexen sctp_auditing(4, stcb->sctp_ep, stcb, stcb->asoc.deleted_primary); 1095851b7298SRandall Stewart #endif 1096851b7298SRandall Stewart sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED); 1097851b7298SRandall Stewart if ((stcb->asoc.num_send_timers_up == 0) && 1098851b7298SRandall Stewart (stcb->asoc.sent_queue_cnt > 0)) { 1099851b7298SRandall Stewart struct sctp_tmit_chunk *chk; 1100851b7298SRandall Stewart 1101851b7298SRandall Stewart chk = TAILQ_FIRST(&stcb->asoc.sent_queue); 1102851b7298SRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 1103851b7298SRandall Stewart stcb, chk->whoTo); 1104851b7298SRandall Stewart } 1105851b7298SRandall Stewart } 1106851b7298SRandall Stewart return; 1107851b7298SRandall Stewart } 1108851b7298SRandall Stewart 11092afb3e84SRandall Stewart static int 11102afb3e84SRandall Stewart sctp_asconf_queue_mgmt(struct sctp_tcb *, struct sctp_ifa *, uint16_t); 11112afb3e84SRandall Stewart 1112851b7298SRandall Stewart void 11132afb3e84SRandall Stewart sctp_net_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *net) 11142afb3e84SRandall Stewart { 11152afb3e84SRandall Stewart struct sctp_tmit_chunk *chk; 11162afb3e84SRandall Stewart 1117b27a6b7dSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "net_immediate_retrans: RTO is %d\n", net->RTO); 11182afb3e84SRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, net, 11192afb3e84SRandall Stewart SCTP_FROM_SCTP_TIMER + SCTP_LOC_5); 11202afb3e84SRandall Stewart stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net); 11212afb3e84SRandall Stewart net->error_count = 0; 11222afb3e84SRandall Stewart TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) { 11232afb3e84SRandall Stewart if (chk->whoTo == net) { 1124851b7298SRandall Stewart if (chk->sent < SCTP_DATAGRAM_RESEND) { 11252afb3e84SRandall Stewart chk->sent = SCTP_DATAGRAM_RESEND; 11262afb3e84SRandall Stewart sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt); 1127d55b0b1bSRandall Stewart sctp_flight_size_decrease(chk); 1128d55b0b1bSRandall Stewart sctp_total_flight_decrease(stcb, chk); 1129d55b0b1bSRandall Stewart net->marked_retrans++; 1130d55b0b1bSRandall Stewart stcb->asoc.marked_retrans++; 11312afb3e84SRandall Stewart } 11322afb3e84SRandall Stewart } 11332afb3e84SRandall Stewart } 1134d55b0b1bSRandall Stewart if (net->marked_retrans) { 1135d55b0b1bSRandall Stewart sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED); 1136d55b0b1bSRandall Stewart } 1137851b7298SRandall Stewart } 11382afb3e84SRandall Stewart 11392afb3e84SRandall Stewart static void 11402afb3e84SRandall Stewart sctp_path_check_and_react(struct sctp_tcb *stcb, struct sctp_ifa *newifa) 11412afb3e84SRandall Stewart { 11422afb3e84SRandall Stewart struct sctp_nets *net; 11432afb3e84SRandall Stewart int addrnum, changed; 11442afb3e84SRandall Stewart 11452afb3e84SRandall Stewart /* 11462afb3e84SRandall Stewart * If number of local valid addresses is 1, the valid address is 11472afb3e84SRandall Stewart * probably newly added address. Several valid addresses in this 11482afb3e84SRandall Stewart * association. A source address may not be changed. Additionally, 11492afb3e84SRandall Stewart * they can be configured on a same interface as "alias" addresses. 11502afb3e84SRandall Stewart * (by micchie) 11512afb3e84SRandall Stewart */ 11522afb3e84SRandall Stewart addrnum = sctp_local_addr_count(stcb); 11532afb3e84SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "p_check_react(): %d local addresses\n", 11542afb3e84SRandall Stewart addrnum); 11552afb3e84SRandall Stewart if (addrnum == 1) { 11562afb3e84SRandall Stewart TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 11572afb3e84SRandall Stewart /* clear any cached route and source address */ 11582afb3e84SRandall Stewart if (net->ro.ro_rt) { 11592afb3e84SRandall Stewart RTFREE(net->ro.ro_rt); 11602afb3e84SRandall Stewart net->ro.ro_rt = NULL; 11612afb3e84SRandall Stewart } 11622afb3e84SRandall Stewart if (net->src_addr_selected) { 11632afb3e84SRandall Stewart sctp_free_ifa(net->ro._s_addr); 11642afb3e84SRandall Stewart net->ro._s_addr = NULL; 11652afb3e84SRandall Stewart net->src_addr_selected = 0; 11662afb3e84SRandall Stewart } 11672afb3e84SRandall Stewart /* Retransmit unacknowledged DATA chunks immediately */ 11682afb3e84SRandall Stewart if (sctp_is_mobility_feature_on(stcb->sctp_ep, 11692afb3e84SRandall Stewart SCTP_MOBILITY_FASTHANDOFF)) { 11702afb3e84SRandall Stewart sctp_net_immediate_retrans(stcb, net); 11712afb3e84SRandall Stewart } 11722afb3e84SRandall Stewart /* also, SET PRIMARY is maybe already sent */ 11732afb3e84SRandall Stewart } 11742afb3e84SRandall Stewart return; 11752afb3e84SRandall Stewart } 11762afb3e84SRandall Stewart /* Multiple local addresses exsist in the association. */ 11772afb3e84SRandall Stewart TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 11782afb3e84SRandall Stewart /* clear any cached route and source address */ 11792afb3e84SRandall Stewart if (net->ro.ro_rt) { 11802afb3e84SRandall Stewart RTFREE(net->ro.ro_rt); 11812afb3e84SRandall Stewart net->ro.ro_rt = NULL; 11822afb3e84SRandall Stewart } 11832afb3e84SRandall Stewart if (net->src_addr_selected) { 11842afb3e84SRandall Stewart sctp_free_ifa(net->ro._s_addr); 11852afb3e84SRandall Stewart net->ro._s_addr = NULL; 11862afb3e84SRandall Stewart net->src_addr_selected = 0; 11872afb3e84SRandall Stewart } 11882afb3e84SRandall Stewart /* 11892afb3e84SRandall Stewart * Check if the nexthop is corresponding to the new address. 11902afb3e84SRandall Stewart * If the new address is corresponding to the current 11912afb3e84SRandall Stewart * nexthop, the path will be changed. If the new address is 11922afb3e84SRandall Stewart * NOT corresponding to the current nexthop, the path will 11932afb3e84SRandall Stewart * not be changed. 11942afb3e84SRandall Stewart */ 11952afb3e84SRandall Stewart SCTP_RTALLOC((sctp_route_t *) & net->ro, 11962afb3e84SRandall Stewart stcb->sctp_ep->def_vrf_id); 11972afb3e84SRandall Stewart if (net->ro.ro_rt == NULL) 11982afb3e84SRandall Stewart continue; 11992afb3e84SRandall Stewart 12002afb3e84SRandall Stewart changed = 0; 1201*e6194c2eSMichael Tuexen switch (net->ro._l_addr.sa.sa_family) { 1202*e6194c2eSMichael Tuexen #ifdef INET 1203*e6194c2eSMichael Tuexen case AF_INET: 1204*e6194c2eSMichael Tuexen if (sctp_v4src_match_nexthop(newifa, (sctp_route_t *) & net->ro)) { 12052afb3e84SRandall Stewart changed = 1; 12062afb3e84SRandall Stewart } 1207*e6194c2eSMichael Tuexen break; 12085e2c2d87SRandall Stewart #endif 1209*e6194c2eSMichael Tuexen #ifdef INET6 1210*e6194c2eSMichael Tuexen case AF_INET6: 1211*e6194c2eSMichael Tuexen if (sctp_v6src_match_nexthop( 1212*e6194c2eSMichael Tuexen &newifa->address.sin6, (sctp_route_t *) & net->ro)) { 1213*e6194c2eSMichael Tuexen changed = 1; 1214*e6194c2eSMichael Tuexen } 1215*e6194c2eSMichael Tuexen break; 1216*e6194c2eSMichael Tuexen #endif 1217*e6194c2eSMichael Tuexen default: 1218*e6194c2eSMichael Tuexen break; 1219*e6194c2eSMichael Tuexen } 12202afb3e84SRandall Stewart /* 12212afb3e84SRandall Stewart * if the newly added address does not relate routing 12222afb3e84SRandall Stewart * information, we skip. 12232afb3e84SRandall Stewart */ 12242afb3e84SRandall Stewart if (changed == 0) 12252afb3e84SRandall Stewart continue; 12262afb3e84SRandall Stewart /* Retransmit unacknowledged DATA chunks immediately */ 12272afb3e84SRandall Stewart if (sctp_is_mobility_feature_on(stcb->sctp_ep, 12282afb3e84SRandall Stewart SCTP_MOBILITY_FASTHANDOFF)) { 12292afb3e84SRandall Stewart sctp_net_immediate_retrans(stcb, net); 12302afb3e84SRandall Stewart } 12312afb3e84SRandall Stewart /* Send SET PRIMARY for this new address */ 12322afb3e84SRandall Stewart if (net == stcb->asoc.primary_destination) { 12332afb3e84SRandall Stewart (void)sctp_asconf_queue_mgmt(stcb, newifa, 12342afb3e84SRandall Stewart SCTP_SET_PRIM_ADDR); 12352afb3e84SRandall Stewart } 12362afb3e84SRandall Stewart } 12372afb3e84SRandall Stewart } 12382afb3e84SRandall Stewart 12392dad8a55SRandall Stewart /* 1240f8829a4aSRandall Stewart * process an ADD/DELETE IP ack from peer. 12411b649582SRandall Stewart * addr: corresponding sctp_ifa to the address being added/deleted. 1242f8829a4aSRandall Stewart * type: SCTP_ADD_IP_ADDRESS or SCTP_DEL_IP_ADDRESS. 1243f8829a4aSRandall Stewart * flag: 1=success, 0=failure. 1244f8829a4aSRandall Stewart */ 1245f8829a4aSRandall Stewart static void 124642551e99SRandall Stewart sctp_asconf_addr_mgmt_ack(struct sctp_tcb *stcb, struct sctp_ifa *addr, 1247f8829a4aSRandall Stewart uint16_t type, uint32_t flag) 1248f8829a4aSRandall Stewart { 1249f8829a4aSRandall Stewart /* 1250f8829a4aSRandall Stewart * do the necessary asoc list work- if we get a failure indication, 12512dad8a55SRandall Stewart * leave the address on the assoc's restricted list. If we get a 12522dad8a55SRandall Stewart * success indication, remove the address from the restricted list. 1253f8829a4aSRandall Stewart */ 1254f8829a4aSRandall Stewart /* 1255f8829a4aSRandall Stewart * Note: this will only occur for ADD_IP_ADDRESS, since 1256f8829a4aSRandall Stewart * DEL_IP_ADDRESS is never actually added to the list... 1257f8829a4aSRandall Stewart */ 1258f8829a4aSRandall Stewart if (flag) { 12591b649582SRandall Stewart /* success case, so remove from the restricted list */ 12601b649582SRandall Stewart sctp_del_local_addr_restricted(stcb, addr); 12612dad8a55SRandall Stewart 12623232788eSRandall Stewart if (sctp_is_mobility_feature_on(stcb->sctp_ep, 1263d55b0b1bSRandall Stewart SCTP_MOBILITY_BASE) || 1264d55b0b1bSRandall Stewart sctp_is_mobility_feature_on(stcb->sctp_ep, 1265d55b0b1bSRandall Stewart SCTP_MOBILITY_FASTHANDOFF)) { 12662afb3e84SRandall Stewart sctp_path_check_and_react(stcb, addr); 12672afb3e84SRandall Stewart return; 12682afb3e84SRandall Stewart } 12693232788eSRandall Stewart /* clear any cached/topologically incorrect source addresses */ 12702dad8a55SRandall Stewart sctp_asconf_nets_cleanup(stcb, addr->ifn_p); 1271f8829a4aSRandall Stewart } 1272f8829a4aSRandall Stewart /* else, leave it on the list */ 1273f8829a4aSRandall Stewart } 1274f8829a4aSRandall Stewart 1275f8829a4aSRandall Stewart /* 12761b649582SRandall Stewart * add an asconf add/delete/set primary IP address parameter to the queue. 1277f8829a4aSRandall Stewart * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR. 12781b649582SRandall Stewart * returns 0 if queued, -1 if not queued/removed. 12791b649582SRandall Stewart * NOTE: if adding, but a delete for the same address is already scheduled 12801b649582SRandall Stewart * (and not yet sent out), simply remove it from queue. Same for deleting 12811b649582SRandall Stewart * an address already scheduled for add. If a duplicate operation is found, 12821b649582SRandall Stewart * ignore the new one. 1283f8829a4aSRandall Stewart */ 12841b649582SRandall Stewart static int 12851b649582SRandall Stewart sctp_asconf_queue_mgmt(struct sctp_tcb *stcb, struct sctp_ifa *ifa, 128618e198d3SRandall Stewart uint16_t type) 1287f8829a4aSRandall Stewart { 1288f8829a4aSRandall Stewart struct sctp_asconf_addr *aa, *aa_next; 1289f8829a4aSRandall Stewart struct sockaddr *sa; 1290f8829a4aSRandall Stewart 1291f8829a4aSRandall Stewart /* make sure the request isn't already in the queue */ 12924a9ef3f8SMichael Tuexen TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) { 1293f8829a4aSRandall Stewart /* address match? */ 129442551e99SRandall Stewart if (sctp_asconf_addr_match(aa, &ifa->address.sa) == 0) 1295f8829a4aSRandall Stewart continue; 1296c54a18d2SRandall Stewart /* 1297c54a18d2SRandall Stewart * is the request already in queue but not sent? pass the 1298c54a18d2SRandall Stewart * request already sent in order to resolve the following 1299c54a18d2SRandall Stewart * case: 1. arrival of ADD, then sent 2. arrival of DEL. we 1300c54a18d2SRandall Stewart * can't remove the ADD request already sent 3. arrival of 1301c54a18d2SRandall Stewart * ADD 1302c54a18d2SRandall Stewart */ 1303c54a18d2SRandall Stewart if (aa->ap.aph.ph.param_type == type && aa->sent == 0) { 1304f8829a4aSRandall Stewart return (-1); 1305f8829a4aSRandall Stewart } 1306f8829a4aSRandall Stewart /* is the negative request already in queue, and not sent */ 13071b649582SRandall Stewart if ((aa->sent == 0) && (type == SCTP_ADD_IP_ADDRESS) && 13081b649582SRandall Stewart (aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS)) { 1309f8829a4aSRandall Stewart /* add requested, delete already queued */ 1310f8829a4aSRandall Stewart TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next); 13111b649582SRandall Stewart /* remove the ifa from the restricted list */ 13121b649582SRandall Stewart sctp_del_local_addr_restricted(stcb, ifa); 13131b649582SRandall Stewart /* free the asconf param */ 1314207304d4SRandall Stewart SCTP_FREE(aa, SCTP_M_ASC_ADDR); 13151b649582SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_mgmt: add removes queued entry\n"); 13161b649582SRandall Stewart return (-1); 13171b649582SRandall Stewart } 13181b649582SRandall Stewart if ((aa->sent == 0) && (type == SCTP_DEL_IP_ADDRESS) && 13191b649582SRandall Stewart (aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS)) { 13201b649582SRandall Stewart /* delete requested, add already queued */ 13211b649582SRandall Stewart TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next); 13221b649582SRandall Stewart /* remove the aa->ifa from the restricted list */ 13231b649582SRandall Stewart sctp_del_local_addr_restricted(stcb, aa->ifa); 13241b649582SRandall Stewart /* free the asconf param */ 13251b649582SRandall Stewart SCTP_FREE(aa, SCTP_M_ASC_ADDR); 13261b649582SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_mgmt: delete removes queued entry\n"); 1327f8829a4aSRandall Stewart return (-1); 1328f8829a4aSRandall Stewart } 1329f8829a4aSRandall Stewart } /* for each aa */ 1330f8829a4aSRandall Stewart 1331f8829a4aSRandall Stewart /* adding new request to the queue */ 13321b649582SRandall Stewart SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), 13331b649582SRandall Stewart SCTP_M_ASC_ADDR); 1334f8829a4aSRandall Stewart if (aa == NULL) { 1335f8829a4aSRandall Stewart /* didn't get memory */ 13361b649582SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "asconf_queue_mgmt: failed to get memory!\n"); 1337f8829a4aSRandall Stewart return (-1); 1338f8829a4aSRandall Stewart } 1339830d754dSRandall Stewart aa->special_del = 0; 1340f8829a4aSRandall Stewart /* fill in asconf address parameter fields */ 1341f8829a4aSRandall Stewart /* top level elements are "networked" during send */ 1342f8829a4aSRandall Stewart aa->ap.aph.ph.param_type = type; 1343f8829a4aSRandall Stewart aa->ifa = ifa; 1344bff64a4dSRandall Stewart atomic_add_int(&ifa->refcount, 1); 1345f8829a4aSRandall Stewart /* correlation_id filled in during send routine later... */ 1346*e6194c2eSMichael Tuexen switch (ifa->address.sa.sa_family) { 1347*e6194c2eSMichael Tuexen #ifdef INET6 1348*e6194c2eSMichael Tuexen case AF_INET6: 1349*e6194c2eSMichael Tuexen { 1350f8829a4aSRandall Stewart struct sockaddr_in6 *sin6; 1351f8829a4aSRandall Stewart 135242551e99SRandall Stewart sin6 = (struct sockaddr_in6 *)&ifa->address.sa; 1353f8829a4aSRandall Stewart sa = (struct sockaddr *)sin6; 1354f8829a4aSRandall Stewart aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS; 1355f8829a4aSRandall Stewart aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param)); 13561b649582SRandall Stewart aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + 1357f8829a4aSRandall Stewart sizeof(struct sctp_ipv6addr_param); 1358f8829a4aSRandall Stewart memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr, 1359f8829a4aSRandall Stewart sizeof(struct in6_addr)); 1360*e6194c2eSMichael Tuexen break; 1361*e6194c2eSMichael Tuexen } 1362*e6194c2eSMichael Tuexen #endif 1363*e6194c2eSMichael Tuexen #ifdef INET 1364*e6194c2eSMichael Tuexen case AF_INET: 1365*e6194c2eSMichael Tuexen { 13661b649582SRandall Stewart struct sockaddr_in *sin; 1367f8829a4aSRandall Stewart 13681b649582SRandall Stewart sin = (struct sockaddr_in *)&ifa->address.sa; 1369f8829a4aSRandall Stewart sa = (struct sockaddr *)sin; 1370f8829a4aSRandall Stewart aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS; 1371f8829a4aSRandall Stewart aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param)); 13721b649582SRandall Stewart aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + 1373f8829a4aSRandall Stewart sizeof(struct sctp_ipv4addr_param); 1374f8829a4aSRandall Stewart memcpy(&aa->ap.addrp.addr, &sin->sin_addr, 1375f8829a4aSRandall Stewart sizeof(struct in_addr)); 1376*e6194c2eSMichael Tuexen break; 1377*e6194c2eSMichael Tuexen } 1378*e6194c2eSMichael Tuexen #endif 1379*e6194c2eSMichael Tuexen default: 1380f8829a4aSRandall Stewart /* invalid family! */ 1381207304d4SRandall Stewart SCTP_FREE(aa, SCTP_M_ASC_ADDR); 13823232788eSRandall Stewart sctp_free_ifa(ifa); 1383f8829a4aSRandall Stewart return (-1); 1384f8829a4aSRandall Stewart } 1385f8829a4aSRandall Stewart aa->sent = 0; /* clear sent flag */ 1386f8829a4aSRandall Stewart 1387f8829a4aSRandall Stewart TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); 1388f8829a4aSRandall Stewart #ifdef SCTP_DEBUG 1389dec0177dSRandall Stewart if (SCTP_BASE_SYSCTL(sctp_debug_on) & SCTP_DEBUG_ASCONF2) { 1390c54a18d2SRandall Stewart if (type == SCTP_ADD_IP_ADDRESS) { 1391c54a18d2SRandall Stewart SCTP_PRINTF("asconf_queue_mgmt: inserted asconf ADD_IP_ADDRESS: "); 1392c54a18d2SRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, sa); 1393c54a18d2SRandall Stewart } else if (type == SCTP_DEL_IP_ADDRESS) { 13941b649582SRandall Stewart SCTP_PRINTF("asconf_queue_mgmt: appended asconf DEL_IP_ADDRESS: "); 1395ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, sa); 1396f8829a4aSRandall Stewart } else { 13971b649582SRandall Stewart SCTP_PRINTF("asconf_queue_mgmt: appended asconf SET_PRIM_ADDR: "); 1398ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, sa); 1399f8829a4aSRandall Stewart } 1400f8829a4aSRandall Stewart } 1401ad81507eSRandall Stewart #endif 1402f8829a4aSRandall Stewart 1403f8829a4aSRandall Stewart return (0); 1404f8829a4aSRandall Stewart } 1405f8829a4aSRandall Stewart 14061b649582SRandall Stewart 14071b649582SRandall Stewart /* 14081b649582SRandall Stewart * add an asconf operation for the given ifa and type. 14091b649582SRandall Stewart * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR. 14101b649582SRandall Stewart * returns 0 if completed, -1 if not completed, 1 if immediate send is 14111b649582SRandall Stewart * advisable. 14121b649582SRandall Stewart */ 14131b649582SRandall Stewart static int 14141b649582SRandall Stewart sctp_asconf_queue_add(struct sctp_tcb *stcb, struct sctp_ifa *ifa, 14151b649582SRandall Stewart uint16_t type) 14161b649582SRandall Stewart { 14171b649582SRandall Stewart uint32_t status; 14181b649582SRandall Stewart int pending_delete_queued = 0; 14191b649582SRandall Stewart 14201b649582SRandall Stewart /* see if peer supports ASCONF */ 14211b649582SRandall Stewart if (stcb->asoc.peer_supports_asconf == 0) { 14221b649582SRandall Stewart return (-1); 14231b649582SRandall Stewart } 14241b649582SRandall Stewart /* 14251b649582SRandall Stewart * if this is deleting the last address from the assoc, mark it as 14261b649582SRandall Stewart * pending. 14271b649582SRandall Stewart */ 14281b649582SRandall Stewart if ((type == SCTP_DEL_IP_ADDRESS) && !stcb->asoc.asconf_del_pending && 14291b649582SRandall Stewart (sctp_local_addr_count(stcb) < 2)) { 14301b649582SRandall Stewart /* set the pending delete info only */ 14311b649582SRandall Stewart stcb->asoc.asconf_del_pending = 1; 14321b649582SRandall Stewart stcb->asoc.asconf_addr_del_pending = ifa; 14331b649582SRandall Stewart atomic_add_int(&ifa->refcount, 1); 14341b649582SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF2, 14351b649582SRandall Stewart "asconf_queue_add: mark delete last address pending\n"); 14361b649582SRandall Stewart return (-1); 14371b649582SRandall Stewart } 1438c54a18d2SRandall Stewart /* queue an asconf parameter */ 1439c54a18d2SRandall Stewart status = sctp_asconf_queue_mgmt(stcb, ifa, type); 1440c54a18d2SRandall Stewart 14411b649582SRandall Stewart /* 14421b649582SRandall Stewart * if this is an add, and there is a delete also pending (i.e. the 14431b649582SRandall Stewart * last local address is being changed), queue the pending delete 14441b649582SRandall Stewart * too. 14451b649582SRandall Stewart */ 1446c54a18d2SRandall Stewart if ((type == SCTP_ADD_IP_ADDRESS) && stcb->asoc.asconf_del_pending && (status == 0)) { 14471b649582SRandall Stewart /* queue in the pending delete */ 14481b649582SRandall Stewart if (sctp_asconf_queue_mgmt(stcb, 14491b649582SRandall Stewart stcb->asoc.asconf_addr_del_pending, 14501b649582SRandall Stewart SCTP_DEL_IP_ADDRESS) == 0) { 14511b649582SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_add: queing pending delete\n"); 14521b649582SRandall Stewart pending_delete_queued = 1; 14531b649582SRandall Stewart /* clear out the pending delete info */ 14541b649582SRandall Stewart stcb->asoc.asconf_del_pending = 0; 14551b649582SRandall Stewart sctp_free_ifa(stcb->asoc.asconf_addr_del_pending); 14561b649582SRandall Stewart stcb->asoc.asconf_addr_del_pending = NULL; 14571b649582SRandall Stewart } 14581b649582SRandall Stewart } 1459c54a18d2SRandall Stewart if (pending_delete_queued) { 14601b649582SRandall Stewart struct sctp_nets *net; 14611b649582SRandall Stewart 14621b649582SRandall Stewart /* 14631b649582SRandall Stewart * since we know that the only/last address is now being 14641b649582SRandall Stewart * changed in this case, reset the cwnd/rto on all nets to 14651b649582SRandall Stewart * start as a new address and path. Also clear the error 14661b649582SRandall Stewart * counts to give the assoc the best chance to complete the 14671b649582SRandall Stewart * address change. 14681b649582SRandall Stewart */ 14691b649582SRandall Stewart TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 14701b649582SRandall Stewart stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, 14711b649582SRandall Stewart net); 14721b649582SRandall Stewart net->RTO = 0; 14731b649582SRandall Stewart net->error_count = 0; 14741b649582SRandall Stewart } 14751b649582SRandall Stewart stcb->asoc.overall_error_count = 0; 1476b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { 1477c4739e2fSRandall Stewart sctp_misc_ints(SCTP_THRESHOLD_CLEAR, 1478c4739e2fSRandall Stewart stcb->asoc.overall_error_count, 1479c4739e2fSRandall Stewart 0, 1480c4739e2fSRandall Stewart SCTP_FROM_SCTP_ASCONF, 1481c4739e2fSRandall Stewart __LINE__); 1482c4739e2fSRandall Stewart } 14831b649582SRandall Stewart /* queue in an advisory set primary too */ 14841b649582SRandall Stewart (void)sctp_asconf_queue_mgmt(stcb, ifa, SCTP_SET_PRIM_ADDR); 14851b649582SRandall Stewart /* let caller know we should send this out immediately */ 14861b649582SRandall Stewart status = 1; 14871b649582SRandall Stewart } 14881b649582SRandall Stewart return (status); 14891b649582SRandall Stewart } 14901b649582SRandall Stewart 14913232788eSRandall Stewart /*- 14923232788eSRandall Stewart * add an asconf delete IP address parameter to the queue by sockaddr and 14933232788eSRandall Stewart * possibly with no sctp_ifa available. This is only called by the routine 14943232788eSRandall Stewart * that checks the addresses in an INIT-ACK against the current address list. 1495f8829a4aSRandall Stewart * returns 0 if completed, non-zero if not completed. 14963232788eSRandall Stewart * NOTE: if an add is already scheduled (and not yet sent out), simply 14973232788eSRandall Stewart * remove it from queue. If a duplicate operation is found, ignore the 14983232788eSRandall Stewart * new one. 1499f8829a4aSRandall Stewart */ 15001b649582SRandall Stewart static int 15013232788eSRandall Stewart sctp_asconf_queue_sa_delete(struct sctp_tcb *stcb, struct sockaddr *sa) 1502f8829a4aSRandall Stewart { 1503bff64a4dSRandall Stewart struct sctp_ifa *ifa; 1504f8829a4aSRandall Stewart struct sctp_asconf_addr *aa, *aa_next; 150542551e99SRandall Stewart uint32_t vrf_id; 1506f8829a4aSRandall Stewart 1507ad81507eSRandall Stewart if (stcb == NULL) { 1508ad81507eSRandall Stewart return (-1); 1509ad81507eSRandall Stewart } 1510f8829a4aSRandall Stewart /* see if peer supports ASCONF */ 1511f8829a4aSRandall Stewart if (stcb->asoc.peer_supports_asconf == 0) { 1512f8829a4aSRandall Stewart return (-1); 1513f8829a4aSRandall Stewart } 1514f8829a4aSRandall Stewart /* make sure the request isn't already in the queue */ 15154a9ef3f8SMichael Tuexen TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) { 1516f8829a4aSRandall Stewart /* address match? */ 1517f8829a4aSRandall Stewart if (sctp_asconf_addr_match(aa, sa) == 0) 1518f8829a4aSRandall Stewart continue; 1519f8829a4aSRandall Stewart /* is the request already in queue (sent or not) */ 15203232788eSRandall Stewart if (aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) { 1521f8829a4aSRandall Stewart return (-1); 1522f8829a4aSRandall Stewart } 1523f8829a4aSRandall Stewart /* is the negative request already in queue, and not sent */ 1524f8829a4aSRandall Stewart if (aa->sent == 1) 1525f8829a4aSRandall Stewart continue; 15263232788eSRandall Stewart if (aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS) { 15273232788eSRandall Stewart /* add already queued, so remove existing entry */ 1528f8829a4aSRandall Stewart TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next); 15291b649582SRandall Stewart sctp_del_local_addr_restricted(stcb, aa->ifa); 1530f8829a4aSRandall Stewart /* free the entry */ 1531207304d4SRandall Stewart SCTP_FREE(aa, SCTP_M_ASC_ADDR); 1532f8829a4aSRandall Stewart return (-1); 1533f8829a4aSRandall Stewart } 1534f8829a4aSRandall Stewart } /* for each aa */ 15353232788eSRandall Stewart 15363232788eSRandall Stewart /* find any existing ifa-- NOTE ifa CAN be allowed to be NULL */ 1537bff64a4dSRandall Stewart if (stcb) { 1538bff64a4dSRandall Stewart vrf_id = stcb->asoc.vrf_id; 1539bff64a4dSRandall Stewart } else { 1540bff64a4dSRandall Stewart vrf_id = SCTP_DEFAULT_VRFID; 1541bff64a4dSRandall Stewart } 1542851b7298SRandall Stewart ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED); 15433232788eSRandall Stewart 1544f8829a4aSRandall Stewart /* adding new request to the queue */ 15451b649582SRandall Stewart SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), 15461b649582SRandall Stewart SCTP_M_ASC_ADDR); 1547f8829a4aSRandall Stewart if (aa == NULL) { 1548f8829a4aSRandall Stewart /* didn't get memory */ 1549ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 15503232788eSRandall Stewart "sctp_asconf_queue_sa_delete: failed to get memory!\n"); 1551f8829a4aSRandall Stewart return (-1); 1552f8829a4aSRandall Stewart } 1553830d754dSRandall Stewart aa->special_del = 0; 1554f8829a4aSRandall Stewart /* fill in asconf address parameter fields */ 1555f8829a4aSRandall Stewart /* top level elements are "networked" during send */ 15563232788eSRandall Stewart aa->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS; 1557bff64a4dSRandall Stewart aa->ifa = ifa; 15583232788eSRandall Stewart if (ifa) 1559bff64a4dSRandall Stewart atomic_add_int(&ifa->refcount, 1); 1560f8829a4aSRandall Stewart /* correlation_id filled in during send routine later... */ 1561*e6194c2eSMichael Tuexen switch (sa->sa_family) { 1562*e6194c2eSMichael Tuexen #ifdef INET6 1563*e6194c2eSMichael Tuexen case AF_INET6: 1564*e6194c2eSMichael Tuexen { 1565f8829a4aSRandall Stewart /* IPv6 address */ 1566f8829a4aSRandall Stewart struct sockaddr_in6 *sin6; 1567f8829a4aSRandall Stewart 1568f8829a4aSRandall Stewart sin6 = (struct sockaddr_in6 *)sa; 1569f8829a4aSRandall Stewart aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS; 1570f8829a4aSRandall Stewart aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param)); 1571f8829a4aSRandall Stewart aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv6addr_param); 1572f8829a4aSRandall Stewart memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr, 1573f8829a4aSRandall Stewart sizeof(struct in6_addr)); 1574*e6194c2eSMichael Tuexen break; 1575*e6194c2eSMichael Tuexen } 1576*e6194c2eSMichael Tuexen #endif 1577*e6194c2eSMichael Tuexen #ifdef INET 1578*e6194c2eSMichael Tuexen case AF_INET: 1579*e6194c2eSMichael Tuexen { 1580f8829a4aSRandall Stewart /* IPv4 address */ 1581f8829a4aSRandall Stewart struct sockaddr_in *sin = (struct sockaddr_in *)sa; 1582f8829a4aSRandall Stewart 1583f8829a4aSRandall Stewart aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS; 1584f8829a4aSRandall Stewart aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param)); 1585f8829a4aSRandall Stewart aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv4addr_param); 1586f8829a4aSRandall Stewart memcpy(&aa->ap.addrp.addr, &sin->sin_addr, 1587f8829a4aSRandall Stewart sizeof(struct in_addr)); 1588*e6194c2eSMichael Tuexen break; 1589*e6194c2eSMichael Tuexen } 1590*e6194c2eSMichael Tuexen #endif 1591*e6194c2eSMichael Tuexen default: 1592f8829a4aSRandall Stewart /* invalid family! */ 1593207304d4SRandall Stewart SCTP_FREE(aa, SCTP_M_ASC_ADDR); 15943232788eSRandall Stewart if (ifa) 15953232788eSRandall Stewart sctp_free_ifa(ifa); 1596f8829a4aSRandall Stewart return (-1); 1597f8829a4aSRandall Stewart } 1598f8829a4aSRandall Stewart aa->sent = 0; /* clear sent flag */ 1599f8829a4aSRandall Stewart 16003232788eSRandall Stewart /* delete goes to the back of the queue */ 1601f8829a4aSRandall Stewart TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); 1602f8829a4aSRandall Stewart 1603c99efcf6SRandall Stewart /* sa_ignore MEMLEAK {memory is put on the tailq} */ 1604f8829a4aSRandall Stewart return (0); 1605f8829a4aSRandall Stewart } 1606f8829a4aSRandall Stewart 1607f8829a4aSRandall Stewart /* 1608f8829a4aSRandall Stewart * find a specific asconf param on our "sent" queue 1609f8829a4aSRandall Stewart */ 1610f8829a4aSRandall Stewart static struct sctp_asconf_addr * 1611f8829a4aSRandall Stewart sctp_asconf_find_param(struct sctp_tcb *stcb, uint32_t correlation_id) 1612f8829a4aSRandall Stewart { 1613f8829a4aSRandall Stewart struct sctp_asconf_addr *aa; 1614f8829a4aSRandall Stewart 1615f8829a4aSRandall Stewart TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) { 1616f8829a4aSRandall Stewart if (aa->ap.aph.correlation_id == correlation_id && 1617f8829a4aSRandall Stewart aa->sent == 1) { 1618f8829a4aSRandall Stewart /* found it */ 1619f8829a4aSRandall Stewart return (aa); 1620f8829a4aSRandall Stewart } 1621f8829a4aSRandall Stewart } 1622f8829a4aSRandall Stewart /* didn't find it */ 1623f8829a4aSRandall Stewart return (NULL); 1624f8829a4aSRandall Stewart } 1625f8829a4aSRandall Stewart 1626f8829a4aSRandall Stewart /* 1627f8829a4aSRandall Stewart * process an SCTP_ERROR_CAUSE_IND for a ASCONF-ACK parameter and do 1628f8829a4aSRandall Stewart * notifications based on the error response 1629f8829a4aSRandall Stewart */ 1630f8829a4aSRandall Stewart static void 1631f8829a4aSRandall Stewart sctp_asconf_process_error(struct sctp_tcb *stcb, 1632f8829a4aSRandall Stewart struct sctp_asconf_paramhdr *aph) 1633f8829a4aSRandall Stewart { 1634f8829a4aSRandall Stewart struct sctp_error_cause *eh; 1635f8829a4aSRandall Stewart struct sctp_paramhdr *ph; 1636f8829a4aSRandall Stewart uint16_t param_type; 1637f8829a4aSRandall Stewart uint16_t error_code; 1638f8829a4aSRandall Stewart 1639f8829a4aSRandall Stewart eh = (struct sctp_error_cause *)(aph + 1); 1640f8829a4aSRandall Stewart ph = (struct sctp_paramhdr *)(eh + 1); 1641f8829a4aSRandall Stewart /* validate lengths */ 1642f8829a4aSRandall Stewart if (htons(eh->length) + sizeof(struct sctp_error_cause) > 1643f8829a4aSRandall Stewart htons(aph->ph.param_length)) { 1644f8829a4aSRandall Stewart /* invalid error cause length */ 1645ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 1646ad81507eSRandall Stewart "asconf_process_error: cause element too long\n"); 1647f8829a4aSRandall Stewart return; 1648f8829a4aSRandall Stewart } 1649f8829a4aSRandall Stewart if (htons(ph->param_length) + sizeof(struct sctp_paramhdr) > 1650f8829a4aSRandall Stewart htons(eh->length)) { 1651f8829a4aSRandall Stewart /* invalid included TLV length */ 1652ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 1653ad81507eSRandall Stewart "asconf_process_error: included TLV too long\n"); 1654f8829a4aSRandall Stewart return; 1655f8829a4aSRandall Stewart } 1656f8829a4aSRandall Stewart /* which error code ? */ 1657f8829a4aSRandall Stewart error_code = ntohs(eh->code); 1658f8829a4aSRandall Stewart param_type = ntohs(aph->ph.param_type); 1659f8829a4aSRandall Stewart /* FIX: this should go back up the REMOTE_ERROR ULP notify */ 1660f8829a4aSRandall Stewart switch (error_code) { 1661f8829a4aSRandall Stewart case SCTP_CAUSE_RESOURCE_SHORTAGE: 1662f8829a4aSRandall Stewart /* we allow ourselves to "try again" for this error */ 1663f8829a4aSRandall Stewart break; 1664f8829a4aSRandall Stewart default: 1665f8829a4aSRandall Stewart /* peer can't handle it... */ 1666f8829a4aSRandall Stewart switch (param_type) { 1667f8829a4aSRandall Stewart case SCTP_ADD_IP_ADDRESS: 1668f8829a4aSRandall Stewart case SCTP_DEL_IP_ADDRESS: 1669f8829a4aSRandall Stewart stcb->asoc.peer_supports_asconf = 0; 1670f8829a4aSRandall Stewart break; 1671f8829a4aSRandall Stewart case SCTP_SET_PRIM_ADDR: 1672f8829a4aSRandall Stewart stcb->asoc.peer_supports_asconf = 0; 1673f8829a4aSRandall Stewart break; 1674f8829a4aSRandall Stewart default: 1675f8829a4aSRandall Stewart break; 1676f8829a4aSRandall Stewart } 1677f8829a4aSRandall Stewart } 1678f8829a4aSRandall Stewart } 1679f8829a4aSRandall Stewart 1680f8829a4aSRandall Stewart /* 168118e198d3SRandall Stewart * process an asconf queue param. 168218e198d3SRandall Stewart * aparam: parameter to process, will be removed from the queue. 168318e198d3SRandall Stewart * flag: 1=success case, 0=failure case 1684f8829a4aSRandall Stewart */ 1685f8829a4aSRandall Stewart static void 1686f8829a4aSRandall Stewart sctp_asconf_process_param_ack(struct sctp_tcb *stcb, 1687f8829a4aSRandall Stewart struct sctp_asconf_addr *aparam, uint32_t flag) 1688f8829a4aSRandall Stewart { 1689f8829a4aSRandall Stewart uint16_t param_type; 1690f8829a4aSRandall Stewart 1691f8829a4aSRandall Stewart /* process this param */ 1692f8829a4aSRandall Stewart param_type = aparam->ap.aph.ph.param_type; 1693f8829a4aSRandall Stewart switch (param_type) { 1694f8829a4aSRandall Stewart case SCTP_ADD_IP_ADDRESS: 1695ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 1696ad81507eSRandall Stewart "process_param_ack: added IP address\n"); 1697f8829a4aSRandall Stewart sctp_asconf_addr_mgmt_ack(stcb, aparam->ifa, param_type, flag); 1698f8829a4aSRandall Stewart break; 1699f8829a4aSRandall Stewart case SCTP_DEL_IP_ADDRESS: 1700ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 1701ad81507eSRandall Stewart "process_param_ack: deleted IP address\n"); 1702f8829a4aSRandall Stewart /* nothing really to do... lists already updated */ 1703f8829a4aSRandall Stewart break; 1704f8829a4aSRandall Stewart case SCTP_SET_PRIM_ADDR: 1705c54a18d2SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 1706c54a18d2SRandall Stewart "process_param_ack: set primary IP address\n"); 1707f8829a4aSRandall Stewart /* nothing to do... peer may start using this addr */ 1708f8829a4aSRandall Stewart if (flag == 0) 1709f8829a4aSRandall Stewart stcb->asoc.peer_supports_asconf = 0; 1710f8829a4aSRandall Stewart break; 1711f8829a4aSRandall Stewart default: 1712f8829a4aSRandall Stewart /* should NEVER happen */ 1713f8829a4aSRandall Stewart break; 1714f8829a4aSRandall Stewart } 1715f8829a4aSRandall Stewart 1716f8829a4aSRandall Stewart /* remove the param and free it */ 1717f8829a4aSRandall Stewart TAILQ_REMOVE(&stcb->asoc.asconf_queue, aparam, next); 17183232788eSRandall Stewart if (aparam->ifa) 1719bff64a4dSRandall Stewart sctp_free_ifa(aparam->ifa); 1720207304d4SRandall Stewart SCTP_FREE(aparam, SCTP_M_ASC_ADDR); 1721f8829a4aSRandall Stewart } 1722f8829a4aSRandall Stewart 1723f8829a4aSRandall Stewart /* 1724f8829a4aSRandall Stewart * cleanup from a bad asconf ack parameter 1725f8829a4aSRandall Stewart */ 1726f8829a4aSRandall Stewart static void 1727f8829a4aSRandall Stewart sctp_asconf_ack_clear(struct sctp_tcb *stcb) 1728f8829a4aSRandall Stewart { 1729f8829a4aSRandall Stewart /* assume peer doesn't really know how to do asconfs */ 1730f8829a4aSRandall Stewart stcb->asoc.peer_supports_asconf = 0; 1731f8829a4aSRandall Stewart /* XXX we could free the pending queue here */ 1732f8829a4aSRandall Stewart } 1733f8829a4aSRandall Stewart 1734f8829a4aSRandall Stewart void 1735f8829a4aSRandall Stewart sctp_handle_asconf_ack(struct mbuf *m, int offset, 1736f8829a4aSRandall Stewart struct sctp_asconf_ack_chunk *cp, struct sctp_tcb *stcb, 17373232788eSRandall Stewart struct sctp_nets *net, int *abort_no_unlock) 1738f8829a4aSRandall Stewart { 1739f8829a4aSRandall Stewart struct sctp_association *asoc; 1740f8829a4aSRandall Stewart uint32_t serial_num; 1741f8829a4aSRandall Stewart uint16_t ack_length; 1742f8829a4aSRandall Stewart struct sctp_asconf_paramhdr *aph; 1743f8829a4aSRandall Stewart struct sctp_asconf_addr *aa, *aa_next; 1744f8829a4aSRandall Stewart uint32_t last_error_id = 0; /* last error correlation id */ 1745f8829a4aSRandall Stewart uint32_t id; 1746f8829a4aSRandall Stewart struct sctp_asconf_addr *ap; 1747f8829a4aSRandall Stewart 1748f8829a4aSRandall Stewart /* asconf param buffer */ 1749f42a358aSRandall Stewart uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE]; 1750f8829a4aSRandall Stewart 1751f8829a4aSRandall Stewart /* verify minimum length */ 1752f8829a4aSRandall Stewart if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_ack_chunk)) { 1753ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 1754ad81507eSRandall Stewart "handle_asconf_ack: chunk too small = %xh\n", 1755f8829a4aSRandall Stewart ntohs(cp->ch.chunk_length)); 1756f8829a4aSRandall Stewart return; 1757f8829a4aSRandall Stewart } 1758f8829a4aSRandall Stewart asoc = &stcb->asoc; 1759f8829a4aSRandall Stewart serial_num = ntohl(cp->serial_number); 1760f8829a4aSRandall Stewart 1761f8829a4aSRandall Stewart /* 1762f8829a4aSRandall Stewart * NOTE: we may want to handle this differently- currently, we will 1763f8829a4aSRandall Stewart * abort when we get an ack for the expected serial number + 1 (eg. 1764f8829a4aSRandall Stewart * we didn't send it), process an ack normally if it is the expected 1765f8829a4aSRandall Stewart * serial number, and re-send the previous ack for *ALL* other 1766f8829a4aSRandall Stewart * serial numbers 1767f8829a4aSRandall Stewart */ 1768f8829a4aSRandall Stewart 1769f8829a4aSRandall Stewart /* 1770f8829a4aSRandall Stewart * if the serial number is the next expected, but I didn't send it, 1771f8829a4aSRandall Stewart * abort the asoc, since someone probably just hijacked us... 1772f8829a4aSRandall Stewart */ 1773f8829a4aSRandall Stewart if (serial_num == (asoc->asconf_seq_out + 1)) { 1774ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got unexpected next serial number! Aborting asoc!\n"); 1775f8829a4aSRandall Stewart sctp_abort_an_association(stcb->sctp_ep, stcb, 1776ceaad40aSRandall Stewart SCTP_CAUSE_ILLEGAL_ASCONF_ACK, NULL, SCTP_SO_NOT_LOCKED); 17773232788eSRandall Stewart *abort_no_unlock = 1; 1778f8829a4aSRandall Stewart return; 1779f8829a4aSRandall Stewart } 1780c54a18d2SRandall Stewart if (serial_num != asoc->asconf_seq_out_acked + 1) { 1781f8829a4aSRandall Stewart /* got a duplicate/unexpected ASCONF-ACK */ 1782ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got duplicate/unexpected serial number = %xh (expected = %xh)\n", 1783c54a18d2SRandall Stewart serial_num, asoc->asconf_seq_out_acked + 1); 1784f8829a4aSRandall Stewart return; 1785f8829a4aSRandall Stewart } 1786c54a18d2SRandall Stewart if (serial_num == asoc->asconf_seq_out - 1) { 1787f8829a4aSRandall Stewart /* stop our timer */ 17883c503c28SRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, net, 17893c503c28SRandall Stewart SCTP_FROM_SCTP_ASCONF + SCTP_LOC_3); 1790c54a18d2SRandall Stewart } 1791f8829a4aSRandall Stewart /* process the ASCONF-ACK contents */ 1792f8829a4aSRandall Stewart ack_length = ntohs(cp->ch.chunk_length) - 1793f8829a4aSRandall Stewart sizeof(struct sctp_asconf_ack_chunk); 1794f8829a4aSRandall Stewart offset += sizeof(struct sctp_asconf_ack_chunk); 1795f8829a4aSRandall Stewart /* process through all parameters */ 1796f8829a4aSRandall Stewart while (ack_length >= sizeof(struct sctp_asconf_paramhdr)) { 1797f8829a4aSRandall Stewart unsigned int param_length, param_type; 1798f8829a4aSRandall Stewart 1799f8829a4aSRandall Stewart /* get pointer to next asconf parameter */ 1800f8829a4aSRandall Stewart aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, 1801f8829a4aSRandall Stewart sizeof(struct sctp_asconf_paramhdr), aparam_buf); 1802f8829a4aSRandall Stewart if (aph == NULL) { 1803f8829a4aSRandall Stewart /* can't get an asconf paramhdr */ 1804f8829a4aSRandall Stewart sctp_asconf_ack_clear(stcb); 1805f8829a4aSRandall Stewart return; 1806f8829a4aSRandall Stewart } 1807f8829a4aSRandall Stewart param_type = ntohs(aph->ph.param_type); 1808f8829a4aSRandall Stewart param_length = ntohs(aph->ph.param_length); 1809f8829a4aSRandall Stewart if (param_length > ack_length) { 1810f8829a4aSRandall Stewart sctp_asconf_ack_clear(stcb); 1811f8829a4aSRandall Stewart return; 1812f8829a4aSRandall Stewart } 1813f8829a4aSRandall Stewart if (param_length < sizeof(struct sctp_paramhdr)) { 1814f8829a4aSRandall Stewart sctp_asconf_ack_clear(stcb); 1815f8829a4aSRandall Stewart return; 1816f8829a4aSRandall Stewart } 1817f8829a4aSRandall Stewart /* get the complete parameter... */ 1818f8829a4aSRandall Stewart if (param_length > sizeof(aparam_buf)) { 1819ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 1820ad81507eSRandall Stewart "param length (%u) larger than buffer size!\n", param_length); 1821f8829a4aSRandall Stewart sctp_asconf_ack_clear(stcb); 1822f8829a4aSRandall Stewart return; 1823f8829a4aSRandall Stewart } 1824f8829a4aSRandall Stewart aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf); 1825f8829a4aSRandall Stewart if (aph == NULL) { 1826f8829a4aSRandall Stewart sctp_asconf_ack_clear(stcb); 1827f8829a4aSRandall Stewart return; 1828f8829a4aSRandall Stewart } 1829f8829a4aSRandall Stewart /* correlation_id is transparent to peer, no ntohl needed */ 1830f8829a4aSRandall Stewart id = aph->correlation_id; 1831f8829a4aSRandall Stewart 1832f8829a4aSRandall Stewart switch (param_type) { 1833f8829a4aSRandall Stewart case SCTP_ERROR_CAUSE_IND: 1834f8829a4aSRandall Stewart last_error_id = id; 1835f8829a4aSRandall Stewart /* find the corresponding asconf param in our queue */ 1836f8829a4aSRandall Stewart ap = sctp_asconf_find_param(stcb, id); 1837f8829a4aSRandall Stewart if (ap == NULL) { 1838f8829a4aSRandall Stewart /* hmm... can't find this in our queue! */ 1839f8829a4aSRandall Stewart break; 1840f8829a4aSRandall Stewart } 1841f8829a4aSRandall Stewart /* process the parameter, failed flag */ 1842f8829a4aSRandall Stewart sctp_asconf_process_param_ack(stcb, ap, 0); 1843f8829a4aSRandall Stewart /* process the error response */ 1844f8829a4aSRandall Stewart sctp_asconf_process_error(stcb, aph); 1845f8829a4aSRandall Stewart break; 1846f8829a4aSRandall Stewart case SCTP_SUCCESS_REPORT: 1847f8829a4aSRandall Stewart /* find the corresponding asconf param in our queue */ 1848f8829a4aSRandall Stewart ap = sctp_asconf_find_param(stcb, id); 1849f8829a4aSRandall Stewart if (ap == NULL) { 1850f8829a4aSRandall Stewart /* hmm... can't find this in our queue! */ 1851f8829a4aSRandall Stewart break; 1852f8829a4aSRandall Stewart } 1853f8829a4aSRandall Stewart /* process the parameter, success flag */ 1854f8829a4aSRandall Stewart sctp_asconf_process_param_ack(stcb, ap, 1); 1855f8829a4aSRandall Stewart break; 1856f8829a4aSRandall Stewart default: 1857f8829a4aSRandall Stewart break; 1858f8829a4aSRandall Stewart } /* switch */ 1859f8829a4aSRandall Stewart 1860f8829a4aSRandall Stewart /* update remaining ASCONF-ACK message length to process */ 1861f8829a4aSRandall Stewart ack_length -= SCTP_SIZE32(param_length); 1862f8829a4aSRandall Stewart if (ack_length <= 0) { 1863f8829a4aSRandall Stewart /* no more data in the mbuf chain */ 1864f8829a4aSRandall Stewart break; 1865f8829a4aSRandall Stewart } 1866f8829a4aSRandall Stewart offset += SCTP_SIZE32(param_length); 1867f8829a4aSRandall Stewart } /* while */ 1868f8829a4aSRandall Stewart 1869f8829a4aSRandall Stewart /* 1870f8829a4aSRandall Stewart * if there are any "sent" params still on the queue, these are 1871f8829a4aSRandall Stewart * implicitly "success", or "failed" (if we got an error back) ... 1872f8829a4aSRandall Stewart * so process these appropriately 1873f8829a4aSRandall Stewart * 1874f8829a4aSRandall Stewart * we assume that the correlation_id's are monotonically increasing 1875f8829a4aSRandall Stewart * beginning from 1 and that we don't have *that* many outstanding 1876f8829a4aSRandall Stewart * at any given time 1877f8829a4aSRandall Stewart */ 1878f8829a4aSRandall Stewart if (last_error_id == 0) 1879f8829a4aSRandall Stewart last_error_id--;/* set to "max" value */ 18804a9ef3f8SMichael Tuexen TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) { 1881f8829a4aSRandall Stewart if (aa->sent == 1) { 1882f8829a4aSRandall Stewart /* 1883f8829a4aSRandall Stewart * implicitly successful or failed if correlation_id 1884f8829a4aSRandall Stewart * < last_error_id, then success else, failure 1885f8829a4aSRandall Stewart */ 1886f8829a4aSRandall Stewart if (aa->ap.aph.correlation_id < last_error_id) 188718e198d3SRandall Stewart sctp_asconf_process_param_ack(stcb, aa, 1); 1888f8829a4aSRandall Stewart else 188918e198d3SRandall Stewart sctp_asconf_process_param_ack(stcb, aa, 0); 1890f8829a4aSRandall Stewart } else { 1891f8829a4aSRandall Stewart /* 1892f8829a4aSRandall Stewart * since we always process in order (FIFO queue) if 1893f8829a4aSRandall Stewart * we reach one that hasn't been sent, the rest 1894f8829a4aSRandall Stewart * should not have been sent either. so, we're 1895f8829a4aSRandall Stewart * done... 1896f8829a4aSRandall Stewart */ 1897f8829a4aSRandall Stewart break; 1898f8829a4aSRandall Stewart } 1899f8829a4aSRandall Stewart } 1900f8829a4aSRandall Stewart 1901f8829a4aSRandall Stewart /* update the next sequence number to use */ 1902c54a18d2SRandall Stewart asoc->asconf_seq_out_acked++; 1903f8829a4aSRandall Stewart /* remove the old ASCONF on our outbound queue */ 1904f8829a4aSRandall Stewart sctp_toss_old_asconf(stcb); 1905f8829a4aSRandall Stewart if (!TAILQ_EMPTY(&stcb->asoc.asconf_queue)) { 19061b649582SRandall Stewart #ifdef SCTP_TIMER_BASED_ASCONF 1907f8829a4aSRandall Stewart /* we have more params, so restart our timer */ 1908f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, 1909f8829a4aSRandall Stewart stcb, net); 19101b649582SRandall Stewart #else 19111b649582SRandall Stewart /* we have more params, so send out more */ 19123232788eSRandall Stewart sctp_send_asconf(stcb, net, SCTP_ADDR_NOT_LOCKED); 19131b649582SRandall Stewart #endif 1914f8829a4aSRandall Stewart } 1915f8829a4aSRandall Stewart } 1916f8829a4aSRandall Stewart 19175e2c2d87SRandall Stewart #ifdef INET6 1918f8829a4aSRandall Stewart static uint32_t 1919f8829a4aSRandall Stewart sctp_is_scopeid_in_nets(struct sctp_tcb *stcb, struct sockaddr *sa) 1920f8829a4aSRandall Stewart { 1921f8829a4aSRandall Stewart struct sockaddr_in6 *sin6, *net6; 1922f8829a4aSRandall Stewart struct sctp_nets *net; 1923f8829a4aSRandall Stewart 1924f8829a4aSRandall Stewart if (sa->sa_family != AF_INET6) { 1925f8829a4aSRandall Stewart /* wrong family */ 1926f8829a4aSRandall Stewart return (0); 1927f8829a4aSRandall Stewart } 1928f8829a4aSRandall Stewart sin6 = (struct sockaddr_in6 *)sa; 1929f8829a4aSRandall Stewart if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) == 0) { 1930f8829a4aSRandall Stewart /* not link local address */ 1931f8829a4aSRandall Stewart return (0); 1932f8829a4aSRandall Stewart } 1933f8829a4aSRandall Stewart /* hunt through our destination nets list for this scope_id */ 1934f8829a4aSRandall Stewart TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 1935f8829a4aSRandall Stewart if (((struct sockaddr *)(&net->ro._l_addr))->sa_family != 1936f8829a4aSRandall Stewart AF_INET6) 1937f8829a4aSRandall Stewart continue; 1938f8829a4aSRandall Stewart net6 = (struct sockaddr_in6 *)&net->ro._l_addr; 1939f8829a4aSRandall Stewart if (IN6_IS_ADDR_LINKLOCAL(&net6->sin6_addr) == 0) 1940f8829a4aSRandall Stewart continue; 1941f8829a4aSRandall Stewart if (sctp_is_same_scope(sin6, net6)) { 1942f8829a4aSRandall Stewart /* found one */ 1943f8829a4aSRandall Stewart return (1); 1944f8829a4aSRandall Stewart } 1945f8829a4aSRandall Stewart } 1946f8829a4aSRandall Stewart /* didn't find one */ 1947f8829a4aSRandall Stewart return (0); 1948f8829a4aSRandall Stewart } 1949f8829a4aSRandall Stewart 19505e2c2d87SRandall Stewart #endif 19515e2c2d87SRandall Stewart 1952f8829a4aSRandall Stewart /* 1953f8829a4aSRandall Stewart * address management functions 1954f8829a4aSRandall Stewart */ 1955f8829a4aSRandall Stewart static void 1956f8829a4aSRandall Stewart sctp_addr_mgmt_assoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb, 19573232788eSRandall Stewart struct sctp_ifa *ifa, uint16_t type, int addr_locked) 1958f8829a4aSRandall Stewart { 1959f8829a4aSRandall Stewart int status; 1960f8829a4aSRandall Stewart 1961f8829a4aSRandall Stewart 1962f8829a4aSRandall Stewart if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0 && 1963f8829a4aSRandall Stewart sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_ASCONF)) { 1964f8829a4aSRandall Stewart /* subset bound, no ASCONF allowed case, so ignore */ 1965f8829a4aSRandall Stewart return; 1966f8829a4aSRandall Stewart } 1967f8829a4aSRandall Stewart /* 1968f8829a4aSRandall Stewart * note: we know this is not the subset bound, no ASCONF case eg. 1969f8829a4aSRandall Stewart * this is boundall or subset bound w/ASCONF allowed 1970f8829a4aSRandall Stewart */ 1971f8829a4aSRandall Stewart 1972f8829a4aSRandall Stewart /* first, make sure it's a good address family */ 1973*e6194c2eSMichael Tuexen switch (ifa->address.sa.sa_family) { 1974*e6194c2eSMichael Tuexen #ifdef INET6 1975*e6194c2eSMichael Tuexen case AF_INET6: 1976*e6194c2eSMichael Tuexen break; 1977*e6194c2eSMichael Tuexen #endif 1978*e6194c2eSMichael Tuexen #ifdef INET 1979*e6194c2eSMichael Tuexen case AF_INET: 1980*e6194c2eSMichael Tuexen break; 1981*e6194c2eSMichael Tuexen #endif 1982*e6194c2eSMichael Tuexen default: 1983f8829a4aSRandall Stewart return; 1984f8829a4aSRandall Stewart } 1985*e6194c2eSMichael Tuexen #ifdef INET6 1986f8829a4aSRandall Stewart /* make sure we're "allowed" to add this type of addr */ 198742551e99SRandall Stewart if (ifa->address.sa.sa_family == AF_INET6) { 1988f8829a4aSRandall Stewart /* invalid if we're not a v6 endpoint */ 1989f8829a4aSRandall Stewart if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) 1990f8829a4aSRandall Stewart return; 1991f8829a4aSRandall Stewart /* is the v6 addr really valid ? */ 199242551e99SRandall Stewart if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) { 1993f8829a4aSRandall Stewart return; 1994f8829a4aSRandall Stewart } 1995f8829a4aSRandall Stewart } 1996*e6194c2eSMichael Tuexen #endif 1997f8829a4aSRandall Stewart /* put this address on the "pending/do not use yet" list */ 19981b649582SRandall Stewart sctp_add_local_addr_restricted(stcb, ifa); 1999f8829a4aSRandall Stewart /* 2000f8829a4aSRandall Stewart * check address scope if address is out of scope, don't queue 2001f8829a4aSRandall Stewart * anything... note: this would leave the address on both inp and 2002f8829a4aSRandall Stewart * asoc lists 2003f8829a4aSRandall Stewart */ 20045e2c2d87SRandall Stewart switch (ifa->address.sa.sa_family) { 20055e2c2d87SRandall Stewart #ifdef INET6 20065e2c2d87SRandall Stewart case AF_INET6: 20075e2c2d87SRandall Stewart { 2008f8829a4aSRandall Stewart struct sockaddr_in6 *sin6; 2009f8829a4aSRandall Stewart 201042551e99SRandall Stewart sin6 = (struct sockaddr_in6 *)&ifa->address.sin6; 2011f8829a4aSRandall Stewart if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { 2012f8829a4aSRandall Stewart /* we skip unspecifed addresses */ 2013f8829a4aSRandall Stewart return; 2014f8829a4aSRandall Stewart } 2015f8829a4aSRandall Stewart if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { 2016f8829a4aSRandall Stewart if (stcb->asoc.local_scope == 0) { 2017f8829a4aSRandall Stewart return; 2018f8829a4aSRandall Stewart } 2019f8829a4aSRandall Stewart /* is it the right link local scope? */ 202042551e99SRandall Stewart if (sctp_is_scopeid_in_nets(stcb, &ifa->address.sa) == 0) { 2021f8829a4aSRandall Stewart return; 2022f8829a4aSRandall Stewart } 2023f8829a4aSRandall Stewart } 2024f8829a4aSRandall Stewart if (stcb->asoc.site_scope == 0 && 2025f8829a4aSRandall Stewart IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)) { 2026f8829a4aSRandall Stewart return; 2027f8829a4aSRandall Stewart } 20285e2c2d87SRandall Stewart break; 20295e2c2d87SRandall Stewart } 20305e2c2d87SRandall Stewart #endif 2031*e6194c2eSMichael Tuexen #ifdef INET 20325e2c2d87SRandall Stewart case AF_INET: 20335e2c2d87SRandall Stewart { 2034f8829a4aSRandall Stewart struct sockaddr_in *sin; 2035f8829a4aSRandall Stewart struct in6pcb *inp6; 2036f8829a4aSRandall Stewart 2037f8829a4aSRandall Stewart inp6 = (struct in6pcb *)&inp->ip_inp.inp; 2038f8829a4aSRandall Stewart /* invalid if we are a v6 only endpoint */ 2039f8829a4aSRandall Stewart if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) && 204044b7479bSRandall Stewart SCTP_IPV6_V6ONLY(inp6)) 2041f8829a4aSRandall Stewart return; 2042f8829a4aSRandall Stewart 204342551e99SRandall Stewart sin = (struct sockaddr_in *)&ifa->address.sa; 2044f8829a4aSRandall Stewart if (sin->sin_addr.s_addr == 0) { 2045f8829a4aSRandall Stewart /* we skip unspecifed addresses */ 2046f8829a4aSRandall Stewart return; 2047f8829a4aSRandall Stewart } 2048f8829a4aSRandall Stewart if (stcb->asoc.ipv4_local_scope == 0 && 2049f8829a4aSRandall Stewart IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) { 2050f8829a4aSRandall Stewart return; 2051f8829a4aSRandall Stewart } 20525e2c2d87SRandall Stewart break; 20535e2c2d87SRandall Stewart } 2054*e6194c2eSMichael Tuexen #endif 20555e2c2d87SRandall Stewart default: 2056f8829a4aSRandall Stewart /* else, not AF_INET or AF_INET6, so skip */ 2057f8829a4aSRandall Stewart return; 2058f8829a4aSRandall Stewart } 2059f8829a4aSRandall Stewart 2060f8829a4aSRandall Stewart /* queue an asconf for this address add/delete */ 2061f8829a4aSRandall Stewart if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF)) { 2062f8829a4aSRandall Stewart /* does the peer do asconf? */ 2063f8829a4aSRandall Stewart if (stcb->asoc.peer_supports_asconf) { 2064f8829a4aSRandall Stewart /* queue an asconf for this addr */ 2065f8829a4aSRandall Stewart status = sctp_asconf_queue_add(stcb, ifa, type); 20661b649582SRandall Stewart 2067f8829a4aSRandall Stewart /* 20681b649582SRandall Stewart * if queued ok, and in the open state, send out the 20691b649582SRandall Stewart * ASCONF. If in the non-open state, these will be 20701b649582SRandall Stewart * sent when the state goes open. 2071f8829a4aSRandall Stewart */ 2072f8829a4aSRandall Stewart if (status == 0 && 2073f8829a4aSRandall Stewart SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) { 20741b649582SRandall Stewart #ifdef SCTP_TIMER_BASED_ASCONF 2075f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, inp, 2076f8829a4aSRandall Stewart stcb, stcb->asoc.primary_destination); 20771b649582SRandall Stewart #else 20783232788eSRandall Stewart sctp_send_asconf(stcb, stcb->asoc.primary_destination, 20793232788eSRandall Stewart addr_locked); 20801b649582SRandall Stewart #endif 2081f8829a4aSRandall Stewart } 2082f8829a4aSRandall Stewart } 2083f8829a4aSRandall Stewart } 2084f8829a4aSRandall Stewart } 2085f8829a4aSRandall Stewart 208642551e99SRandall Stewart 208742551e99SRandall Stewart int 20881b649582SRandall Stewart sctp_asconf_iterator_ep(struct sctp_inpcb *inp, void *ptr, uint32_t val) 2089f8829a4aSRandall Stewart { 209042551e99SRandall Stewart struct sctp_asconf_iterator *asc; 209142551e99SRandall Stewart struct sctp_ifa *ifa; 209242551e99SRandall Stewart struct sctp_laddr *l; 209342551e99SRandall Stewart int cnt_invalid = 0; 2094f8829a4aSRandall Stewart 209542551e99SRandall Stewart asc = (struct sctp_asconf_iterator *)ptr; 209642551e99SRandall Stewart LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) { 209742551e99SRandall Stewart ifa = l->ifa; 2098*e6194c2eSMichael Tuexen switch (ifa->address.sa.sa_family) { 2099*e6194c2eSMichael Tuexen #ifdef INET6 2100*e6194c2eSMichael Tuexen case AF_INET6: 2101f8829a4aSRandall Stewart /* invalid if we're not a v6 endpoint */ 2102f8829a4aSRandall Stewart if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) { 210342551e99SRandall Stewart cnt_invalid++; 210442551e99SRandall Stewart if (asc->cnt == cnt_invalid) 210542551e99SRandall Stewart return (1); 2106f8829a4aSRandall Stewart } 2107*e6194c2eSMichael Tuexen break; 2108*e6194c2eSMichael Tuexen #endif 2109*e6194c2eSMichael Tuexen #ifdef INET 2110*e6194c2eSMichael Tuexen case AF_INET: 2111*e6194c2eSMichael Tuexen { 2112f8829a4aSRandall Stewart /* invalid if we are a v6 only endpoint */ 2113f8829a4aSRandall Stewart struct in6pcb *inp6; 2114f8829a4aSRandall Stewart 2115f8829a4aSRandall Stewart inp6 = (struct in6pcb *)&inp->ip_inp.inp; 2116f8829a4aSRandall Stewart if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) && 211744b7479bSRandall Stewart SCTP_IPV6_V6ONLY(inp6)) { 211842551e99SRandall Stewart cnt_invalid++; 211942551e99SRandall Stewart if (asc->cnt == cnt_invalid) 212042551e99SRandall Stewart return (1); 2121f8829a4aSRandall Stewart } 2122*e6194c2eSMichael Tuexen break; 2123*e6194c2eSMichael Tuexen } 2124*e6194c2eSMichael Tuexen #endif 2125*e6194c2eSMichael Tuexen default: 2126f8829a4aSRandall Stewart /* invalid address family */ 212742551e99SRandall Stewart cnt_invalid++; 212842551e99SRandall Stewart if (asc->cnt == cnt_invalid) 212942551e99SRandall Stewart return (1); 2130f8829a4aSRandall Stewart } 213142551e99SRandall Stewart } 213242551e99SRandall Stewart return (0); 213342551e99SRandall Stewart } 2134f8829a4aSRandall Stewart 21351b649582SRandall Stewart static int 21361b649582SRandall Stewart sctp_asconf_iterator_ep_end(struct sctp_inpcb *inp, void *ptr, uint32_t val) 213742551e99SRandall Stewart { 213842551e99SRandall Stewart struct sctp_ifa *ifa; 213942551e99SRandall Stewart struct sctp_asconf_iterator *asc; 214042551e99SRandall Stewart struct sctp_laddr *laddr, *nladdr, *l; 214142551e99SRandall Stewart 214242551e99SRandall Stewart /* Only for specific case not bound all */ 214342551e99SRandall Stewart asc = (struct sctp_asconf_iterator *)ptr; 214442551e99SRandall Stewart LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) { 214542551e99SRandall Stewart ifa = l->ifa; 214642551e99SRandall Stewart if (l->action == SCTP_ADD_IP_ADDRESS) { 21473c503c28SRandall Stewart LIST_FOREACH(laddr, &inp->sctp_addr_list, 21483c503c28SRandall Stewart sctp_nxt_addr) { 214942551e99SRandall Stewart if (laddr->ifa == ifa) { 215042551e99SRandall Stewart laddr->action = 0; 215142551e99SRandall Stewart break; 215242551e99SRandall Stewart } 215342551e99SRandall Stewart } 215442551e99SRandall Stewart } else if (l->action == SCTP_DEL_IP_ADDRESS) { 21554a9ef3f8SMichael Tuexen LIST_FOREACH_SAFE(laddr, &inp->sctp_addr_list, sctp_nxt_addr, nladdr) { 215642551e99SRandall Stewart /* remove only after all guys are done */ 215742551e99SRandall Stewart if (laddr->ifa == ifa) { 215842551e99SRandall Stewart sctp_del_local_addr_ep(inp, ifa); 215942551e99SRandall Stewart } 216042551e99SRandall Stewart } 216142551e99SRandall Stewart } 216242551e99SRandall Stewart } 216342551e99SRandall Stewart return (0); 216442551e99SRandall Stewart } 216542551e99SRandall Stewart 216642551e99SRandall Stewart void 21671b649582SRandall Stewart sctp_asconf_iterator_stcb(struct sctp_inpcb *inp, struct sctp_tcb *stcb, 21681b649582SRandall Stewart void *ptr, uint32_t val) 216942551e99SRandall Stewart { 217042551e99SRandall Stewart struct sctp_asconf_iterator *asc; 217142551e99SRandall Stewart struct sctp_ifa *ifa; 217242551e99SRandall Stewart struct sctp_laddr *l; 217342551e99SRandall Stewart int cnt_invalid = 0; 217442551e99SRandall Stewart int type, status; 21751b649582SRandall Stewart int num_queued = 0; 217642551e99SRandall Stewart 217742551e99SRandall Stewart asc = (struct sctp_asconf_iterator *)ptr; 217842551e99SRandall Stewart LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) { 217942551e99SRandall Stewart ifa = l->ifa; 218042551e99SRandall Stewart type = l->action; 218122a67197SRandall Stewart 218222a67197SRandall Stewart /* address's vrf_id must be the vrf_id of the assoc */ 218322a67197SRandall Stewart if (ifa->vrf_id != stcb->asoc.vrf_id) { 218422a67197SRandall Stewart continue; 218522a67197SRandall Stewart } 218642551e99SRandall Stewart /* Same checks again for assoc */ 21875e2c2d87SRandall Stewart switch (ifa->address.sa.sa_family) { 21885e2c2d87SRandall Stewart #ifdef INET6 21895e2c2d87SRandall Stewart case AF_INET6: 21905e2c2d87SRandall Stewart { 219142551e99SRandall Stewart /* invalid if we're not a v6 endpoint */ 219242551e99SRandall Stewart struct sockaddr_in6 *sin6; 219342551e99SRandall Stewart 219442551e99SRandall Stewart if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) { 219542551e99SRandall Stewart cnt_invalid++; 219642551e99SRandall Stewart if (asc->cnt == cnt_invalid) 219742551e99SRandall Stewart return; 219842551e99SRandall Stewart else 219942551e99SRandall Stewart continue; 220042551e99SRandall Stewart } 220142551e99SRandall Stewart sin6 = (struct sockaddr_in6 *)&ifa->address.sin6; 220242551e99SRandall Stewart if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { 220342551e99SRandall Stewart /* we skip unspecifed addresses */ 220442551e99SRandall Stewart continue; 220542551e99SRandall Stewart } 220642551e99SRandall Stewart if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { 220742551e99SRandall Stewart if (stcb->asoc.local_scope == 0) { 220842551e99SRandall Stewart continue; 220942551e99SRandall Stewart } 221042551e99SRandall Stewart /* is it the right link local scope? */ 221142551e99SRandall Stewart if (sctp_is_scopeid_in_nets(stcb, &ifa->address.sa) == 0) { 221242551e99SRandall Stewart continue; 221342551e99SRandall Stewart } 221442551e99SRandall Stewart } 22155e2c2d87SRandall Stewart break; 22165e2c2d87SRandall Stewart } 22175e2c2d87SRandall Stewart #endif 2218*e6194c2eSMichael Tuexen #ifdef INET 22195e2c2d87SRandall Stewart case AF_INET: 22205e2c2d87SRandall Stewart { 222142551e99SRandall Stewart /* invalid if we are a v6 only endpoint */ 222242551e99SRandall Stewart struct in6pcb *inp6; 222342551e99SRandall Stewart struct sockaddr_in *sin; 222442551e99SRandall Stewart 222542551e99SRandall Stewart inp6 = (struct in6pcb *)&inp->ip_inp.inp; 222642551e99SRandall Stewart /* invalid if we are a v6 only endpoint */ 222742551e99SRandall Stewart if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) && 222842551e99SRandall Stewart SCTP_IPV6_V6ONLY(inp6)) 222942551e99SRandall Stewart continue; 223042551e99SRandall Stewart 223142551e99SRandall Stewart sin = (struct sockaddr_in *)&ifa->address.sa; 223242551e99SRandall Stewart if (sin->sin_addr.s_addr == 0) { 223342551e99SRandall Stewart /* we skip unspecifed addresses */ 223442551e99SRandall Stewart continue; 223542551e99SRandall Stewart } 223642551e99SRandall Stewart if (stcb->asoc.ipv4_local_scope == 0 && 223742551e99SRandall Stewart IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) { 2238c2ede4b3SMartin Blapp continue; 223942551e99SRandall Stewart } 224042551e99SRandall Stewart if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) && 224142551e99SRandall Stewart SCTP_IPV6_V6ONLY(inp6)) { 224242551e99SRandall Stewart cnt_invalid++; 224342551e99SRandall Stewart if (asc->cnt == cnt_invalid) 224442551e99SRandall Stewart return; 224542551e99SRandall Stewart else 224642551e99SRandall Stewart continue; 224742551e99SRandall Stewart } 22485e2c2d87SRandall Stewart break; 22495e2c2d87SRandall Stewart } 2250*e6194c2eSMichael Tuexen #endif 22515e2c2d87SRandall Stewart default: 225242551e99SRandall Stewart /* invalid address family */ 225342551e99SRandall Stewart cnt_invalid++; 225442551e99SRandall Stewart if (asc->cnt == cnt_invalid) 2255f8829a4aSRandall Stewart return; 225642551e99SRandall Stewart else 225742551e99SRandall Stewart continue; 22585e2c2d87SRandall Stewart break; 2259f8829a4aSRandall Stewart } 2260f8829a4aSRandall Stewart 226142551e99SRandall Stewart if (type == SCTP_ADD_IP_ADDRESS) { 22621b649582SRandall Stewart /* prevent this address from being used as a source */ 22631b649582SRandall Stewart sctp_add_local_addr_restricted(stcb, ifa); 226442551e99SRandall Stewart } else if (type == SCTP_DEL_IP_ADDRESS) { 2265f8829a4aSRandall Stewart struct sctp_nets *net; 2266f8829a4aSRandall Stewart 2267f8829a4aSRandall Stewart TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 226817205eccSRandall Stewart sctp_rtentry_t *rt; 2269f8829a4aSRandall Stewart 2270f8829a4aSRandall Stewart /* delete this address if cached */ 2271851b7298SRandall Stewart if (net->ro._s_addr == ifa) { 227242551e99SRandall Stewart sctp_free_ifa(net->ro._s_addr); 227342551e99SRandall Stewart net->ro._s_addr = NULL; 227442551e99SRandall Stewart net->src_addr_selected = 0; 2275f8829a4aSRandall Stewart rt = net->ro.ro_rt; 227642551e99SRandall Stewart if (rt) { 227742551e99SRandall Stewart RTFREE(rt); 2278f8829a4aSRandall Stewart net->ro.ro_rt = NULL; 2279f8829a4aSRandall Stewart } 228042551e99SRandall Stewart /* 228142551e99SRandall Stewart * Now we deleted our src address, 228242551e99SRandall Stewart * should we not also now reset the 228342551e99SRandall Stewart * cwnd/rto to start as if its a new 228442551e99SRandall Stewart * address? 228542551e99SRandall Stewart */ 2286b54d3a6cSRandall Stewart stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net); 2287108df27cSRandall Stewart net->RTO = 0; 228842551e99SRandall Stewart 2289f8829a4aSRandall Stewart } 2290f8829a4aSRandall Stewart } 229142551e99SRandall Stewart } else if (type == SCTP_SET_PRIM_ADDR) { 229242551e99SRandall Stewart if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) { 22931b649582SRandall Stewart /* must validate the ifa is in the ep */ 229442551e99SRandall Stewart if (sctp_is_addr_in_ep(stcb->sctp_ep, ifa) == 0) { 229542551e99SRandall Stewart continue; 2296f8829a4aSRandall Stewart } 229742551e99SRandall Stewart } else { 229842551e99SRandall Stewart /* Need to check scopes for this guy */ 229942551e99SRandall Stewart if (sctp_is_address_in_scope(ifa, 230042551e99SRandall Stewart stcb->asoc.ipv4_addr_legal, 230142551e99SRandall Stewart stcb->asoc.ipv6_addr_legal, 230242551e99SRandall Stewart stcb->asoc.loopback_scope, 230342551e99SRandall Stewart stcb->asoc.ipv4_local_scope, 230442551e99SRandall Stewart stcb->asoc.local_scope, 230542551e99SRandall Stewart stcb->asoc.site_scope, 0) == 0) { 230642551e99SRandall Stewart continue; 2307f8829a4aSRandall Stewart } 230842551e99SRandall Stewart } 230942551e99SRandall Stewart } 231042551e99SRandall Stewart /* queue an asconf for this address add/delete */ 23111b649582SRandall Stewart if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF) && 23121b649582SRandall Stewart stcb->asoc.peer_supports_asconf) { 231342551e99SRandall Stewart /* queue an asconf for this addr */ 231442551e99SRandall Stewart status = sctp_asconf_queue_add(stcb, ifa, type); 231542551e99SRandall Stewart /* 23161b649582SRandall Stewart * if queued ok, and in the open state, update the 23171b649582SRandall Stewart * count of queued params. If in the non-open 23181b649582SRandall Stewart * state, these get sent when the assoc goes open. 231942551e99SRandall Stewart */ 23201b649582SRandall Stewart if (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) { 23211b649582SRandall Stewart if (status >= 0) { 23221b649582SRandall Stewart num_queued++; 232342551e99SRandall Stewart } 232442551e99SRandall Stewart } 232542551e99SRandall Stewart } 232642551e99SRandall Stewart } 23271b649582SRandall Stewart /* 23281b649582SRandall Stewart * If we have queued params in the open state, send out an ASCONF. 23291b649582SRandall Stewart */ 23301b649582SRandall Stewart if (num_queued > 0) { 23313232788eSRandall Stewart sctp_send_asconf(stcb, stcb->asoc.primary_destination, 23323232788eSRandall Stewart SCTP_ADDR_NOT_LOCKED); 23331b649582SRandall Stewart } 233442551e99SRandall Stewart } 233542551e99SRandall Stewart 233642551e99SRandall Stewart void 23371b649582SRandall Stewart sctp_asconf_iterator_end(void *ptr, uint32_t val) 233842551e99SRandall Stewart { 233942551e99SRandall Stewart struct sctp_asconf_iterator *asc; 234042551e99SRandall Stewart struct sctp_ifa *ifa; 23414a9ef3f8SMichael Tuexen struct sctp_laddr *l, *nl; 234242551e99SRandall Stewart 234342551e99SRandall Stewart asc = (struct sctp_asconf_iterator *)ptr; 23444a9ef3f8SMichael Tuexen LIST_FOREACH_SAFE(l, &asc->list_of_work, sctp_nxt_addr, nl) { 234542551e99SRandall Stewart ifa = l->ifa; 234642551e99SRandall Stewart if (l->action == SCTP_ADD_IP_ADDRESS) { 234742551e99SRandall Stewart /* Clear the defer use flag */ 234842551e99SRandall Stewart ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE; 234942551e99SRandall Stewart } 235042551e99SRandall Stewart sctp_free_ifa(ifa); 2351b3f1ea41SRandall Stewart SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_laddr), l); 235242551e99SRandall Stewart SCTP_DECR_LADDR_COUNT(); 235342551e99SRandall Stewart } 2354207304d4SRandall Stewart SCTP_FREE(asc, SCTP_M_ASC_IT); 2355f8829a4aSRandall Stewart } 2356f8829a4aSRandall Stewart 2357f8829a4aSRandall Stewart /* 23581b649582SRandall Stewart * sa is the sockaddr to ask the peer to set primary to. 23591b649582SRandall Stewart * returns: 0 = completed, -1 = error 2360f8829a4aSRandall Stewart */ 2361c4739e2fSRandall Stewart int32_t 2362f8829a4aSRandall Stewart sctp_set_primary_ip_address_sa(struct sctp_tcb *stcb, struct sockaddr *sa) 2363f8829a4aSRandall Stewart { 23643232788eSRandall Stewart uint32_t vrf_id; 23653232788eSRandall Stewart struct sctp_ifa *ifa; 2366f8829a4aSRandall Stewart 23673232788eSRandall Stewart /* find the ifa for the desired set primary */ 23683232788eSRandall Stewart vrf_id = stcb->asoc.vrf_id; 23693232788eSRandall Stewart ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED); 23703232788eSRandall Stewart if (ifa == NULL) { 23713232788eSRandall Stewart /* Invalid address */ 23723232788eSRandall Stewart return (-1); 23733232788eSRandall Stewart } 2374f8829a4aSRandall Stewart /* queue an ASCONF:SET_PRIM_ADDR to be sent */ 23753232788eSRandall Stewart if (!sctp_asconf_queue_add(stcb, ifa, SCTP_SET_PRIM_ADDR)) { 2376f8829a4aSRandall Stewart /* set primary queuing succeeded */ 2377ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 2378ad81507eSRandall Stewart "set_primary_ip_address_sa: queued on tcb=%p, ", 2379f8829a4aSRandall Stewart stcb); 2380ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 23811b649582SRandall Stewart if (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) { 23821b649582SRandall Stewart #ifdef SCTP_TIMER_BASED_ASCONF 23831b649582SRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, 23841b649582SRandall Stewart stcb->sctp_ep, stcb, 23851b649582SRandall Stewart stcb->asoc.primary_destination); 23861b649582SRandall Stewart #else 23873232788eSRandall Stewart sctp_send_asconf(stcb, stcb->asoc.primary_destination, 23883232788eSRandall Stewart SCTP_ADDR_NOT_LOCKED); 23891b649582SRandall Stewart #endif 23901b649582SRandall Stewart } 2391f8829a4aSRandall Stewart } else { 2392ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "set_primary_ip_address_sa: failed to add to queue on tcb=%p, ", 2393f8829a4aSRandall Stewart stcb); 2394ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 2395f8829a4aSRandall Stewart return (-1); 2396f8829a4aSRandall Stewart } 2397f8829a4aSRandall Stewart return (0); 2398f8829a4aSRandall Stewart } 2399f8829a4aSRandall Stewart 2400f8829a4aSRandall Stewart void 240142551e99SRandall Stewart sctp_set_primary_ip_address(struct sctp_ifa *ifa) 2402f8829a4aSRandall Stewart { 2403f8829a4aSRandall Stewart struct sctp_inpcb *inp; 2404f8829a4aSRandall Stewart 2405f8829a4aSRandall Stewart /* go through all our PCB's */ 2406b3f1ea41SRandall Stewart LIST_FOREACH(inp, &SCTP_BASE_INFO(listhead), sctp_list) { 2407f8829a4aSRandall Stewart struct sctp_tcb *stcb; 2408f8829a4aSRandall Stewart 2409f8829a4aSRandall Stewart /* process for all associations for this endpoint */ 2410f8829a4aSRandall Stewart LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { 2411f8829a4aSRandall Stewart /* queue an ASCONF:SET_PRIM_ADDR to be sent */ 2412f8829a4aSRandall Stewart if (!sctp_asconf_queue_add(stcb, ifa, 2413f8829a4aSRandall Stewart SCTP_SET_PRIM_ADDR)) { 2414f8829a4aSRandall Stewart /* set primary queuing succeeded */ 2415ceaad40aSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "set_primary_ip_address: queued on stcb=%p, ", 2416f8829a4aSRandall Stewart stcb); 2417ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &ifa->address.sa); 24181b649582SRandall Stewart if (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) { 24191b649582SRandall Stewart #ifdef SCTP_TIMER_BASED_ASCONF 24201b649582SRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, 24211b649582SRandall Stewart stcb->sctp_ep, stcb, 24221b649582SRandall Stewart stcb->asoc.primary_destination); 24231b649582SRandall Stewart #else 24243232788eSRandall Stewart sctp_send_asconf(stcb, stcb->asoc.primary_destination, 24253232788eSRandall Stewart SCTP_ADDR_NOT_LOCKED); 24261b649582SRandall Stewart #endif 24271b649582SRandall Stewart } 2428f8829a4aSRandall Stewart } 2429f8829a4aSRandall Stewart } /* for each stcb */ 2430f8829a4aSRandall Stewart } /* for each inp */ 2431f8829a4aSRandall Stewart } 2432f8829a4aSRandall Stewart 2433c54a18d2SRandall Stewart int 2434c54a18d2SRandall Stewart sctp_is_addr_pending(struct sctp_tcb *stcb, struct sctp_ifa *sctp_ifa) 2435c54a18d2SRandall Stewart { 2436c54a18d2SRandall Stewart struct sctp_tmit_chunk *chk, *nchk; 2437c54a18d2SRandall Stewart unsigned int offset, asconf_limit; 2438c54a18d2SRandall Stewart struct sctp_asconf_chunk *acp; 2439c54a18d2SRandall Stewart struct sctp_asconf_paramhdr *aph; 2440c54a18d2SRandall Stewart uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE]; 2441*e6194c2eSMichael Tuexen struct sctp_paramhdr *ph; 2442c54a18d2SRandall Stewart int add_cnt, del_cnt; 2443c54a18d2SRandall Stewart uint16_t last_param_type; 2444c54a18d2SRandall Stewart 2445c54a18d2SRandall Stewart add_cnt = del_cnt = 0; 2446c54a18d2SRandall Stewart last_param_type = 0; 24474a9ef3f8SMichael Tuexen TAILQ_FOREACH_SAFE(chk, &stcb->asoc.asconf_send_queue, sctp_next, nchk) { 2448c54a18d2SRandall Stewart if (chk->data == NULL) { 2449c54a18d2SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: No mbuf data?\n"); 2450c54a18d2SRandall Stewart continue; 2451c54a18d2SRandall Stewart } 2452c54a18d2SRandall Stewart offset = 0; 2453c54a18d2SRandall Stewart acp = mtod(chk->data, struct sctp_asconf_chunk *); 2454c54a18d2SRandall Stewart offset += sizeof(struct sctp_asconf_chunk); 2455c54a18d2SRandall Stewart asconf_limit = ntohs(acp->ch.chunk_length); 2456*e6194c2eSMichael Tuexen ph = (struct sctp_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_paramhdr), aparam_buf); 2457*e6194c2eSMichael Tuexen if (ph == NULL) { 2458c54a18d2SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: couldn't get lookup addr!\n"); 2459c54a18d2SRandall Stewart continue; 2460c54a18d2SRandall Stewart } 2461*e6194c2eSMichael Tuexen offset += ntohs(ph->param_length); 2462c54a18d2SRandall Stewart 2463c54a18d2SRandall Stewart aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_asconf_paramhdr), aparam_buf); 2464c54a18d2SRandall Stewart if (aph == NULL) { 2465c54a18d2SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: Empty ASCONF will be sent?\n"); 2466c54a18d2SRandall Stewart continue; 2467c54a18d2SRandall Stewart } 2468c54a18d2SRandall Stewart while (aph != NULL) { 2469c54a18d2SRandall Stewart unsigned int param_length, param_type; 2470c54a18d2SRandall Stewart 2471c54a18d2SRandall Stewart param_type = ntohs(aph->ph.param_type); 2472c54a18d2SRandall Stewart param_length = ntohs(aph->ph.param_length); 2473c54a18d2SRandall Stewart if (offset + param_length > asconf_limit) { 2474c54a18d2SRandall Stewart /* parameter goes beyond end of chunk! */ 2475c54a18d2SRandall Stewart break; 2476c54a18d2SRandall Stewart } 2477c54a18d2SRandall Stewart if (param_length > sizeof(aparam_buf)) { 2478c54a18d2SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: param length (%u) larger than buffer size!\n", param_length); 2479c54a18d2SRandall Stewart break; 2480c54a18d2SRandall Stewart } 2481c54a18d2SRandall Stewart if (param_length <= sizeof(struct sctp_paramhdr)) { 2482c54a18d2SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: param length(%u) too short\n", param_length); 2483c54a18d2SRandall Stewart break; 2484c54a18d2SRandall Stewart } 2485c54a18d2SRandall Stewart aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, param_length, aparam_buf); 2486c54a18d2SRandall Stewart if (aph == NULL) { 2487c54a18d2SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: couldn't get entire param\n"); 2488c54a18d2SRandall Stewart break; 2489c54a18d2SRandall Stewart } 2490*e6194c2eSMichael Tuexen ph = (struct sctp_paramhdr *)(aph + 1); 2491*e6194c2eSMichael Tuexen if (sctp_addr_match(ph, &sctp_ifa->address.sa) != 0) { 2492c54a18d2SRandall Stewart switch (param_type) { 2493c54a18d2SRandall Stewart case SCTP_ADD_IP_ADDRESS: 2494c54a18d2SRandall Stewart add_cnt++; 2495c54a18d2SRandall Stewart break; 2496c54a18d2SRandall Stewart case SCTP_DEL_IP_ADDRESS: 2497c54a18d2SRandall Stewart del_cnt++; 2498c54a18d2SRandall Stewart break; 2499c54a18d2SRandall Stewart default: 2500c54a18d2SRandall Stewart break; 2501c54a18d2SRandall Stewart } 2502c54a18d2SRandall Stewart last_param_type = param_type; 2503c54a18d2SRandall Stewart } 2504c54a18d2SRandall Stewart offset += SCTP_SIZE32(param_length); 2505c54a18d2SRandall Stewart if (offset >= asconf_limit) { 2506c54a18d2SRandall Stewart /* no more data in the mbuf chain */ 2507c54a18d2SRandall Stewart break; 2508c54a18d2SRandall Stewart } 2509c54a18d2SRandall Stewart /* get pointer to next asconf param */ 2510c54a18d2SRandall Stewart aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_asconf_paramhdr), aparam_buf); 2511c54a18d2SRandall Stewart } 2512c54a18d2SRandall Stewart } 2513c54a18d2SRandall Stewart 2514c54a18d2SRandall Stewart /* 2515c54a18d2SRandall Stewart * we want to find the sequences which consist of ADD -> DEL -> ADD 2516c54a18d2SRandall Stewart * or DEL -> ADD 2517c54a18d2SRandall Stewart */ 2518c54a18d2SRandall Stewart if (add_cnt > del_cnt || 2519c54a18d2SRandall Stewart (add_cnt == del_cnt && last_param_type == SCTP_ADD_IP_ADDRESS)) { 2520c54a18d2SRandall Stewart return 1; 2521c54a18d2SRandall Stewart } 2522c54a18d2SRandall Stewart return 0; 2523c54a18d2SRandall Stewart } 2524c54a18d2SRandall Stewart 2525f8829a4aSRandall Stewart static struct sockaddr * 25263232788eSRandall Stewart sctp_find_valid_localaddr(struct sctp_tcb *stcb, int addr_locked) 2527f8829a4aSRandall Stewart { 252842551e99SRandall Stewart struct sctp_vrf *vrf = NULL; 252942551e99SRandall Stewart struct sctp_ifn *sctp_ifn; 253042551e99SRandall Stewart struct sctp_ifa *sctp_ifa; 2531f8829a4aSRandall Stewart 25323232788eSRandall Stewart if (addr_locked == SCTP_ADDR_NOT_LOCKED) 2533c99efcf6SRandall Stewart SCTP_IPI_ADDR_RLOCK(); 253442551e99SRandall Stewart vrf = sctp_find_vrf(stcb->asoc.vrf_id); 2535ad81507eSRandall Stewart if (vrf == NULL) { 25363232788eSRandall Stewart if (addr_locked == SCTP_ADDR_NOT_LOCKED) 2537c99efcf6SRandall Stewart SCTP_IPI_ADDR_RUNLOCK(); 2538ad81507eSRandall Stewart return (NULL); 2539ad81507eSRandall Stewart } 254042551e99SRandall Stewart LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) { 254142551e99SRandall Stewart if (stcb->asoc.loopback_scope == 0 && 254242551e99SRandall Stewart SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) { 2543f8829a4aSRandall Stewart /* Skip if loopback_scope not set */ 2544f8829a4aSRandall Stewart continue; 2545f8829a4aSRandall Stewart } 254642551e99SRandall Stewart LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) { 2547*e6194c2eSMichael Tuexen switch (sctp_ifa->address.sa.sa_family) { 2548*e6194c2eSMichael Tuexen #ifdef INET 2549*e6194c2eSMichael Tuexen case AF_INET: 2550*e6194c2eSMichael Tuexen if (stcb->asoc.ipv4_addr_legal) { 2551f8829a4aSRandall Stewart struct sockaddr_in *sin; 2552f8829a4aSRandall Stewart 255342551e99SRandall Stewart sin = (struct sockaddr_in *)&sctp_ifa->address.sa; 2554f8829a4aSRandall Stewart if (sin->sin_addr.s_addr == 0) { 2555f8829a4aSRandall Stewart /* skip unspecifed addresses */ 2556f8829a4aSRandall Stewart continue; 2557f8829a4aSRandall Stewart } 2558f8829a4aSRandall Stewart if (stcb->asoc.ipv4_local_scope == 0 && 2559f8829a4aSRandall Stewart IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) 2560f8829a4aSRandall Stewart continue; 2561f8829a4aSRandall Stewart 2562c54a18d2SRandall Stewart if (sctp_is_addr_restricted(stcb, sctp_ifa) && 2563c54a18d2SRandall Stewart (!sctp_is_addr_pending(stcb, sctp_ifa))) 2564f8829a4aSRandall Stewart continue; 2565*e6194c2eSMichael Tuexen /* 2566*e6194c2eSMichael Tuexen * found a valid local v4 address to 2567*e6194c2eSMichael Tuexen * use 2568*e6194c2eSMichael Tuexen */ 25693232788eSRandall Stewart if (addr_locked == SCTP_ADDR_NOT_LOCKED) 2570c99efcf6SRandall Stewart SCTP_IPI_ADDR_RUNLOCK(); 257142551e99SRandall Stewart return (&sctp_ifa->address.sa); 2572*e6194c2eSMichael Tuexen } 2573*e6194c2eSMichael Tuexen break; 2574*e6194c2eSMichael Tuexen #endif 2575*e6194c2eSMichael Tuexen #ifdef INET6 2576*e6194c2eSMichael Tuexen case AF_INET6: 2577*e6194c2eSMichael Tuexen if (stcb->asoc.ipv6_addr_legal) { 2578f8829a4aSRandall Stewart struct sockaddr_in6 *sin6; 2579f8829a4aSRandall Stewart 258042551e99SRandall Stewart if (sctp_ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) { 2581f8829a4aSRandall Stewart continue; 258242551e99SRandall Stewart } 258342551e99SRandall Stewart sin6 = (struct sockaddr_in6 *)&sctp_ifa->address.sa; 2584f8829a4aSRandall Stewart if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { 2585*e6194c2eSMichael Tuexen /* 2586*e6194c2eSMichael Tuexen * we skip unspecifed 2587*e6194c2eSMichael Tuexen * addresses 2588*e6194c2eSMichael Tuexen */ 2589f8829a4aSRandall Stewart continue; 2590f8829a4aSRandall Stewart } 2591f8829a4aSRandall Stewart if (stcb->asoc.local_scope == 0 && 2592f8829a4aSRandall Stewart IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) 2593f8829a4aSRandall Stewart continue; 2594f8829a4aSRandall Stewart if (stcb->asoc.site_scope == 0 && 2595f8829a4aSRandall Stewart IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)) 2596f8829a4aSRandall Stewart continue; 2597f8829a4aSRandall Stewart 2598c54a18d2SRandall Stewart if (sctp_is_addr_restricted(stcb, sctp_ifa) && 2599c54a18d2SRandall Stewart (!sctp_is_addr_pending(stcb, sctp_ifa))) 2600c54a18d2SRandall Stewart continue; 2601*e6194c2eSMichael Tuexen /* 2602*e6194c2eSMichael Tuexen * found a valid local v6 address to 2603*e6194c2eSMichael Tuexen * use 2604*e6194c2eSMichael Tuexen */ 26053232788eSRandall Stewart if (addr_locked == SCTP_ADDR_NOT_LOCKED) 2606c99efcf6SRandall Stewart SCTP_IPI_ADDR_RUNLOCK(); 260742551e99SRandall Stewart return (&sctp_ifa->address.sa); 2608f8829a4aSRandall Stewart } 2609*e6194c2eSMichael Tuexen break; 2610*e6194c2eSMichael Tuexen #endif 2611*e6194c2eSMichael Tuexen default: 2612*e6194c2eSMichael Tuexen break; 2613*e6194c2eSMichael Tuexen } 2614f8829a4aSRandall Stewart } 2615f8829a4aSRandall Stewart } 2616f8829a4aSRandall Stewart /* no valid addresses found */ 26173232788eSRandall Stewart if (addr_locked == SCTP_ADDR_NOT_LOCKED) 2618c99efcf6SRandall Stewart SCTP_IPI_ADDR_RUNLOCK(); 2619f8829a4aSRandall Stewart return (NULL); 2620f8829a4aSRandall Stewart } 2621f8829a4aSRandall Stewart 2622f8829a4aSRandall Stewart static struct sockaddr * 2623f8829a4aSRandall Stewart sctp_find_valid_localaddr_ep(struct sctp_tcb *stcb) 2624f8829a4aSRandall Stewart { 2625f8829a4aSRandall Stewart struct sctp_laddr *laddr; 2626f8829a4aSRandall Stewart 2627f8829a4aSRandall Stewart LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) { 2628f8829a4aSRandall Stewart if (laddr->ifa == NULL) { 2629f8829a4aSRandall Stewart continue; 2630f8829a4aSRandall Stewart } 2631f8829a4aSRandall Stewart /* is the address restricted ? */ 2632c54a18d2SRandall Stewart if (sctp_is_addr_restricted(stcb, laddr->ifa) && 2633c54a18d2SRandall Stewart (!sctp_is_addr_pending(stcb, laddr->ifa))) 2634f8829a4aSRandall Stewart continue; 2635f8829a4aSRandall Stewart 2636f8829a4aSRandall Stewart /* found a valid local address to use */ 263742551e99SRandall Stewart return (&laddr->ifa->address.sa); 2638f8829a4aSRandall Stewart } 2639f8829a4aSRandall Stewart /* no valid addresses found */ 2640f8829a4aSRandall Stewart return (NULL); 2641f8829a4aSRandall Stewart } 2642f8829a4aSRandall Stewart 2643f8829a4aSRandall Stewart /* 264418e198d3SRandall Stewart * builds an ASCONF chunk from queued ASCONF params. 264518e198d3SRandall Stewart * returns NULL on error (no mbuf, no ASCONF params queued, etc). 2646f8829a4aSRandall Stewart */ 2647f8829a4aSRandall Stewart struct mbuf * 26483232788eSRandall Stewart sctp_compose_asconf(struct sctp_tcb *stcb, int *retlen, int addr_locked) 2649f8829a4aSRandall Stewart { 2650f8829a4aSRandall Stewart struct mbuf *m_asconf, *m_asconf_chk; 2651f8829a4aSRandall Stewart struct sctp_asconf_addr *aa; 2652f8829a4aSRandall Stewart struct sctp_asconf_chunk *acp; 2653f8829a4aSRandall Stewart struct sctp_asconf_paramhdr *aph; 2654f8829a4aSRandall Stewart struct sctp_asconf_addr_param *aap; 2655f8829a4aSRandall Stewart uint32_t p_length; 2656f8829a4aSRandall Stewart uint32_t correlation_id = 1; /* 0 is reserved... */ 2657f8829a4aSRandall Stewart caddr_t ptr, lookup_ptr; 2658f8829a4aSRandall Stewart uint8_t lookup_used = 0; 2659f8829a4aSRandall Stewart 2660f8829a4aSRandall Stewart /* are there any asconf params to send? */ 2661c54a18d2SRandall Stewart TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) { 2662c54a18d2SRandall Stewart if (aa->sent == 0) 2663c54a18d2SRandall Stewart break; 2664f8829a4aSRandall Stewart } 2665c54a18d2SRandall Stewart if (aa == NULL) 26661b649582SRandall Stewart return (NULL); 2667c54a18d2SRandall Stewart 2668f8829a4aSRandall Stewart /* 2669f8829a4aSRandall Stewart * get a chunk header mbuf and a cluster for the asconf params since 2670f8829a4aSRandall Stewart * it's simpler to fill in the asconf chunk header lookup address on 2671f8829a4aSRandall Stewart * the fly 2672f8829a4aSRandall Stewart */ 2673139bc87fSRandall Stewart m_asconf_chk = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_chunk), 0, M_DONTWAIT, 1, MT_DATA); 2674f8829a4aSRandall Stewart if (m_asconf_chk == NULL) { 2675f8829a4aSRandall Stewart /* no mbuf's */ 2676ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 2677ad81507eSRandall Stewart "compose_asconf: couldn't get chunk mbuf!\n"); 2678f8829a4aSRandall Stewart return (NULL); 2679f8829a4aSRandall Stewart } 2680139bc87fSRandall Stewart m_asconf = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_DONTWAIT, 1, MT_DATA); 2681f8829a4aSRandall Stewart if (m_asconf == NULL) { 2682f8829a4aSRandall Stewart /* no mbuf's */ 2683ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 2684ad81507eSRandall Stewart "compose_asconf: couldn't get mbuf!\n"); 2685f8829a4aSRandall Stewart sctp_m_freem(m_asconf_chk); 2686f8829a4aSRandall Stewart return (NULL); 2687f8829a4aSRandall Stewart } 2688139bc87fSRandall Stewart SCTP_BUF_LEN(m_asconf_chk) = sizeof(struct sctp_asconf_chunk); 2689139bc87fSRandall Stewart SCTP_BUF_LEN(m_asconf) = 0; 2690f8829a4aSRandall Stewart acp = mtod(m_asconf_chk, struct sctp_asconf_chunk *); 2691f8829a4aSRandall Stewart bzero(acp, sizeof(struct sctp_asconf_chunk)); 2692f8829a4aSRandall Stewart /* save pointers to lookup address and asconf params */ 2693f8829a4aSRandall Stewart lookup_ptr = (caddr_t)(acp + 1); /* after the header */ 2694f8829a4aSRandall Stewart ptr = mtod(m_asconf, caddr_t); /* beginning of cluster */ 2695f8829a4aSRandall Stewart 2696f8829a4aSRandall Stewart /* fill in chunk header info */ 2697f8829a4aSRandall Stewart acp->ch.chunk_type = SCTP_ASCONF; 2698f8829a4aSRandall Stewart acp->ch.chunk_flags = 0; 2699f8829a4aSRandall Stewart acp->serial_number = htonl(stcb->asoc.asconf_seq_out); 2700c54a18d2SRandall Stewart stcb->asoc.asconf_seq_out++; 2701f8829a4aSRandall Stewart 2702f8829a4aSRandall Stewart /* add parameters... up to smallest MTU allowed */ 2703f8829a4aSRandall Stewart TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) { 2704c54a18d2SRandall Stewart if (aa->sent) 2705c54a18d2SRandall Stewart continue; 2706f8829a4aSRandall Stewart /* get the parameter length */ 2707f8829a4aSRandall Stewart p_length = SCTP_SIZE32(aa->ap.aph.ph.param_length); 2708f8829a4aSRandall Stewart /* will it fit in current chunk? */ 2709139bc87fSRandall Stewart if (SCTP_BUF_LEN(m_asconf) + p_length > stcb->asoc.smallest_mtu) { 2710f8829a4aSRandall Stewart /* won't fit, so we're done with this chunk */ 2711f8829a4aSRandall Stewart break; 2712f8829a4aSRandall Stewart } 2713f8829a4aSRandall Stewart /* assign (and store) a correlation id */ 2714f8829a4aSRandall Stewart aa->ap.aph.correlation_id = correlation_id++; 2715f8829a4aSRandall Stewart 2716f8829a4aSRandall Stewart /* 2717f8829a4aSRandall Stewart * fill in address if we're doing a delete this is a simple 2718f8829a4aSRandall Stewart * way for us to fill in the correlation address, which 2719f8829a4aSRandall Stewart * should only be used by the peer if we're deleting our 2720f8829a4aSRandall Stewart * source address and adding a new address (e.g. renumbering 2721f8829a4aSRandall Stewart * case) 2722f8829a4aSRandall Stewart */ 2723f8829a4aSRandall Stewart if (lookup_used == 0 && 2724830d754dSRandall Stewart (aa->special_del == 0) && 2725f8829a4aSRandall Stewart aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) { 2726f8829a4aSRandall Stewart struct sctp_ipv6addr_param *lookup; 2727f8829a4aSRandall Stewart uint16_t p_size, addr_size; 2728f8829a4aSRandall Stewart 2729f8829a4aSRandall Stewart lookup = (struct sctp_ipv6addr_param *)lookup_ptr; 2730f8829a4aSRandall Stewart lookup->ph.param_type = 2731f8829a4aSRandall Stewart htons(aa->ap.addrp.ph.param_type); 2732f8829a4aSRandall Stewart if (aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) { 2733f8829a4aSRandall Stewart /* copy IPv6 address */ 2734f8829a4aSRandall Stewart p_size = sizeof(struct sctp_ipv6addr_param); 2735f8829a4aSRandall Stewart addr_size = sizeof(struct in6_addr); 2736f8829a4aSRandall Stewart } else { 2737f8829a4aSRandall Stewart /* copy IPv4 address */ 2738f8829a4aSRandall Stewart p_size = sizeof(struct sctp_ipv4addr_param); 2739f8829a4aSRandall Stewart addr_size = sizeof(struct in_addr); 2740f8829a4aSRandall Stewart } 2741f8829a4aSRandall Stewart lookup->ph.param_length = htons(SCTP_SIZE32(p_size)); 2742f8829a4aSRandall Stewart memcpy(lookup->addr, &aa->ap.addrp.addr, addr_size); 2743139bc87fSRandall Stewart SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size); 2744f8829a4aSRandall Stewart lookup_used = 1; 2745f8829a4aSRandall Stewart } 2746f8829a4aSRandall Stewart /* copy into current space */ 2747f8829a4aSRandall Stewart memcpy(ptr, &aa->ap, p_length); 2748f8829a4aSRandall Stewart 2749f8829a4aSRandall Stewart /* network elements and update lengths */ 2750f8829a4aSRandall Stewart aph = (struct sctp_asconf_paramhdr *)ptr; 2751f8829a4aSRandall Stewart aap = (struct sctp_asconf_addr_param *)ptr; 2752f8829a4aSRandall Stewart /* correlation_id is transparent to peer, no htonl needed */ 2753f8829a4aSRandall Stewart aph->ph.param_type = htons(aph->ph.param_type); 2754f8829a4aSRandall Stewart aph->ph.param_length = htons(aph->ph.param_length); 2755f8829a4aSRandall Stewart aap->addrp.ph.param_type = htons(aap->addrp.ph.param_type); 2756f8829a4aSRandall Stewart aap->addrp.ph.param_length = htons(aap->addrp.ph.param_length); 2757f8829a4aSRandall Stewart 2758139bc87fSRandall Stewart SCTP_BUF_LEN(m_asconf) += SCTP_SIZE32(p_length); 2759f8829a4aSRandall Stewart ptr += SCTP_SIZE32(p_length); 2760f8829a4aSRandall Stewart 2761f8829a4aSRandall Stewart /* 2762f8829a4aSRandall Stewart * these params are removed off the pending list upon 2763f8829a4aSRandall Stewart * getting an ASCONF-ACK back from the peer, just set flag 2764f8829a4aSRandall Stewart */ 2765f8829a4aSRandall Stewart aa->sent = 1; 2766f8829a4aSRandall Stewart } 2767f8829a4aSRandall Stewart /* check to see if the lookup addr has been populated yet */ 2768f8829a4aSRandall Stewart if (lookup_used == 0) { 2769f8829a4aSRandall Stewart /* NOTE: if the address param is optional, can skip this... */ 2770f8829a4aSRandall Stewart /* add any valid (existing) address... */ 2771f8829a4aSRandall Stewart struct sctp_ipv6addr_param *lookup; 2772f8829a4aSRandall Stewart uint16_t p_size, addr_size; 2773f8829a4aSRandall Stewart struct sockaddr *found_addr; 2774f8829a4aSRandall Stewart caddr_t addr_ptr; 2775f8829a4aSRandall Stewart 2776f8829a4aSRandall Stewart if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) 27773232788eSRandall Stewart found_addr = sctp_find_valid_localaddr(stcb, 27783232788eSRandall Stewart addr_locked); 2779f8829a4aSRandall Stewart else 2780f8829a4aSRandall Stewart found_addr = sctp_find_valid_localaddr_ep(stcb); 2781f8829a4aSRandall Stewart 2782f8829a4aSRandall Stewart lookup = (struct sctp_ipv6addr_param *)lookup_ptr; 2783f8829a4aSRandall Stewart if (found_addr != NULL) { 2784*e6194c2eSMichael Tuexen switch (found_addr->sa_family) { 2785*e6194c2eSMichael Tuexen #ifdef INET6 2786*e6194c2eSMichael Tuexen case AF_INET6: 2787f8829a4aSRandall Stewart /* copy IPv6 address */ 2788f8829a4aSRandall Stewart lookup->ph.param_type = 2789f8829a4aSRandall Stewart htons(SCTP_IPV6_ADDRESS); 2790f8829a4aSRandall Stewart p_size = sizeof(struct sctp_ipv6addr_param); 2791f8829a4aSRandall Stewart addr_size = sizeof(struct in6_addr); 2792f8829a4aSRandall Stewart addr_ptr = (caddr_t)&((struct sockaddr_in6 *) 2793f8829a4aSRandall Stewart found_addr)->sin6_addr; 2794*e6194c2eSMichael Tuexen break; 2795*e6194c2eSMichael Tuexen #endif 2796*e6194c2eSMichael Tuexen #ifdef INET 2797*e6194c2eSMichael Tuexen case AF_INET: 2798f8829a4aSRandall Stewart /* copy IPv4 address */ 2799f8829a4aSRandall Stewart lookup->ph.param_type = 2800f8829a4aSRandall Stewart htons(SCTP_IPV4_ADDRESS); 2801f8829a4aSRandall Stewart p_size = sizeof(struct sctp_ipv4addr_param); 2802f8829a4aSRandall Stewart addr_size = sizeof(struct in_addr); 2803f8829a4aSRandall Stewart addr_ptr = (caddr_t)&((struct sockaddr_in *) 2804f8829a4aSRandall Stewart found_addr)->sin_addr; 2805*e6194c2eSMichael Tuexen break; 2806*e6194c2eSMichael Tuexen #endif 2807*e6194c2eSMichael Tuexen default: 2808*e6194c2eSMichael Tuexen p_size = 0; 2809*e6194c2eSMichael Tuexen addr_size = 0; 2810*e6194c2eSMichael Tuexen addr_ptr = NULL; 2811*e6194c2eSMichael Tuexen break; 2812f8829a4aSRandall Stewart } 2813f8829a4aSRandall Stewart lookup->ph.param_length = htons(SCTP_SIZE32(p_size)); 2814f8829a4aSRandall Stewart memcpy(lookup->addr, addr_ptr, addr_size); 2815139bc87fSRandall Stewart SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size); 2816f8829a4aSRandall Stewart lookup_used = 1; 2817f8829a4aSRandall Stewart } else { 2818f8829a4aSRandall Stewart /* uh oh... don't have any address?? */ 2819ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 2820ad81507eSRandall Stewart "compose_asconf: no lookup addr!\n"); 2821*e6194c2eSMichael Tuexen /* XXX for now, we send a IPv4 address of 0.0.0.0 */ 2822f8829a4aSRandall Stewart lookup->ph.param_type = htons(SCTP_IPV4_ADDRESS); 2823f8829a4aSRandall Stewart lookup->ph.param_length = htons(SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param))); 2824f8829a4aSRandall Stewart bzero(lookup->addr, sizeof(struct in_addr)); 2825139bc87fSRandall Stewart SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param)); 2826f8829a4aSRandall Stewart lookup_used = 1; 2827f8829a4aSRandall Stewart } 2828f8829a4aSRandall Stewart } 2829f8829a4aSRandall Stewart /* chain it all together */ 2830139bc87fSRandall Stewart SCTP_BUF_NEXT(m_asconf_chk) = m_asconf; 28313c503c28SRandall Stewart *retlen = SCTP_BUF_LEN(m_asconf_chk) + SCTP_BUF_LEN(m_asconf); 28323c503c28SRandall Stewart acp->ch.chunk_length = ntohs(*retlen); 2833f8829a4aSRandall Stewart 2834f8829a4aSRandall Stewart return (m_asconf_chk); 2835f8829a4aSRandall Stewart } 2836f8829a4aSRandall Stewart 2837f8829a4aSRandall Stewart /* 2838f8829a4aSRandall Stewart * section to handle address changes before an association is up eg. changes 2839f8829a4aSRandall Stewart * during INIT/INIT-ACK/COOKIE-ECHO handshake 2840f8829a4aSRandall Stewart */ 2841f8829a4aSRandall Stewart 2842f8829a4aSRandall Stewart /* 2843f8829a4aSRandall Stewart * processes the (local) addresses in the INIT-ACK chunk 2844f8829a4aSRandall Stewart */ 2845f8829a4aSRandall Stewart static void 2846f8829a4aSRandall Stewart sctp_process_initack_addresses(struct sctp_tcb *stcb, struct mbuf *m, 2847f8829a4aSRandall Stewart unsigned int offset, unsigned int length) 2848f8829a4aSRandall Stewart { 2849f8829a4aSRandall Stewart struct sctp_paramhdr tmp_param, *ph; 2850f8829a4aSRandall Stewart uint16_t plen, ptype; 285142551e99SRandall Stewart struct sctp_ifa *sctp_ifa; 2852f8829a4aSRandall Stewart struct sctp_ipv6addr_param addr_store; 2853*e6194c2eSMichael Tuexen 2854*e6194c2eSMichael Tuexen #ifdef INET6 2855f8829a4aSRandall Stewart struct sockaddr_in6 sin6; 2856*e6194c2eSMichael Tuexen 2857*e6194c2eSMichael Tuexen #endif 2858*e6194c2eSMichael Tuexen #ifdef INET 2859f8829a4aSRandall Stewart struct sockaddr_in sin; 2860*e6194c2eSMichael Tuexen 2861*e6194c2eSMichael Tuexen #endif 2862f8829a4aSRandall Stewart struct sockaddr *sa; 286342551e99SRandall Stewart uint32_t vrf_id; 2864f8829a4aSRandall Stewart 2865ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF2, "processing init-ack addresses\n"); 2866ad81507eSRandall Stewart if (stcb == NULL) /* Un-needed check for SA */ 2867ad81507eSRandall Stewart return; 2868f8829a4aSRandall Stewart 2869f8829a4aSRandall Stewart /* convert to upper bound */ 2870f8829a4aSRandall Stewart length += offset; 2871f8829a4aSRandall Stewart 2872f8829a4aSRandall Stewart if ((offset + sizeof(struct sctp_paramhdr)) > length) { 2873f8829a4aSRandall Stewart return; 2874f8829a4aSRandall Stewart } 2875f8829a4aSRandall Stewart /* init the addresses */ 2876*e6194c2eSMichael Tuexen #ifdef INET6 2877f8829a4aSRandall Stewart bzero(&sin6, sizeof(sin6)); 2878f8829a4aSRandall Stewart sin6.sin6_family = AF_INET6; 2879f8829a4aSRandall Stewart sin6.sin6_len = sizeof(sin6); 2880f8829a4aSRandall Stewart sin6.sin6_port = stcb->rport; 2881*e6194c2eSMichael Tuexen #endif 2882f8829a4aSRandall Stewart 2883*e6194c2eSMichael Tuexen #ifdef INET 2884f8829a4aSRandall Stewart bzero(&sin, sizeof(sin)); 2885f8829a4aSRandall Stewart sin.sin_family = AF_INET; 2886*e6194c2eSMichael Tuexen sin.sin_len = sizeof(sin); 2887f8829a4aSRandall Stewart sin.sin_port = stcb->rport; 2888*e6194c2eSMichael Tuexen #endif 2889f8829a4aSRandall Stewart 2890f8829a4aSRandall Stewart /* go through the addresses in the init-ack */ 2891*e6194c2eSMichael Tuexen ph = (struct sctp_paramhdr *) 2892*e6194c2eSMichael Tuexen sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), 2893*e6194c2eSMichael Tuexen (uint8_t *) & tmp_param); 2894f8829a4aSRandall Stewart while (ph != NULL) { 2895f8829a4aSRandall Stewart ptype = ntohs(ph->param_type); 2896f8829a4aSRandall Stewart plen = ntohs(ph->param_length); 2897*e6194c2eSMichael Tuexen switch (ptype) { 2898*e6194c2eSMichael Tuexen #ifdef INET6 2899*e6194c2eSMichael Tuexen case SCTP_IPV6_ADDRESS: 2900*e6194c2eSMichael Tuexen { 2901f8829a4aSRandall Stewart struct sctp_ipv6addr_param *a6p; 2902f8829a4aSRandall Stewart 2903f8829a4aSRandall Stewart /* get the entire IPv6 address param */ 2904f8829a4aSRandall Stewart a6p = (struct sctp_ipv6addr_param *) 2905f8829a4aSRandall Stewart sctp_m_getptr(m, offset, 2906f8829a4aSRandall Stewart sizeof(struct sctp_ipv6addr_param), 2907f8829a4aSRandall Stewart (uint8_t *) & addr_store); 2908f8829a4aSRandall Stewart if (plen != sizeof(struct sctp_ipv6addr_param) || 2909f8829a4aSRandall Stewart a6p == NULL) { 2910f8829a4aSRandall Stewart return; 2911f8829a4aSRandall Stewart } 2912f8829a4aSRandall Stewart memcpy(&sin6.sin6_addr, a6p->addr, 2913f8829a4aSRandall Stewart sizeof(struct in6_addr)); 2914f8829a4aSRandall Stewart sa = (struct sockaddr *)&sin6; 2915*e6194c2eSMichael Tuexen break; 2916*e6194c2eSMichael Tuexen } 2917*e6194c2eSMichael Tuexen #endif 2918*e6194c2eSMichael Tuexen #ifdef INET 2919*e6194c2eSMichael Tuexen case SCTP_IPV4_ADDRESS: 2920*e6194c2eSMichael Tuexen { 2921f8829a4aSRandall Stewart struct sctp_ipv4addr_param *a4p; 2922f8829a4aSRandall Stewart 2923f8829a4aSRandall Stewart /* get the entire IPv4 address param */ 292442551e99SRandall Stewart a4p = (struct sctp_ipv4addr_param *)sctp_m_getptr(m, offset, 292542551e99SRandall Stewart sizeof(struct sctp_ipv4addr_param), 292642551e99SRandall Stewart (uint8_t *) & addr_store); 2927f8829a4aSRandall Stewart if (plen != sizeof(struct sctp_ipv4addr_param) || 2928f8829a4aSRandall Stewart a4p == NULL) { 2929f8829a4aSRandall Stewart return; 2930f8829a4aSRandall Stewart } 2931f8829a4aSRandall Stewart sin.sin_addr.s_addr = a4p->addr; 2932f8829a4aSRandall Stewart sa = (struct sockaddr *)&sin; 2933*e6194c2eSMichael Tuexen } 2934*e6194c2eSMichael Tuexen #endif 2935*e6194c2eSMichael Tuexen default: 2936f8829a4aSRandall Stewart goto next_addr; 2937f8829a4aSRandall Stewart } 2938f8829a4aSRandall Stewart 2939f8829a4aSRandall Stewart /* see if this address really (still) exists */ 2940bff64a4dSRandall Stewart if (stcb) { 2941bff64a4dSRandall Stewart vrf_id = stcb->asoc.vrf_id; 2942bff64a4dSRandall Stewart } else { 294342551e99SRandall Stewart vrf_id = SCTP_DEFAULT_VRFID; 2944bff64a4dSRandall Stewart } 29453232788eSRandall Stewart sctp_ifa = sctp_find_ifa_by_addr(sa, vrf_id, 29463232788eSRandall Stewart SCTP_ADDR_NOT_LOCKED); 294742551e99SRandall Stewart if (sctp_ifa == NULL) { 2948f8829a4aSRandall Stewart /* address doesn't exist anymore */ 2949f8829a4aSRandall Stewart int status; 2950f8829a4aSRandall Stewart 2951f8829a4aSRandall Stewart /* are ASCONFs allowed ? */ 2952f8829a4aSRandall Stewart if ((sctp_is_feature_on(stcb->sctp_ep, 2953f8829a4aSRandall Stewart SCTP_PCB_FLAGS_DO_ASCONF)) && 2954f8829a4aSRandall Stewart stcb->asoc.peer_supports_asconf) { 2955f8829a4aSRandall Stewart /* queue an ASCONF DEL_IP_ADDRESS */ 29563232788eSRandall Stewart status = sctp_asconf_queue_sa_delete(stcb, sa); 2957f8829a4aSRandall Stewart /* 29581b649582SRandall Stewart * if queued ok, and in correct state, send 29591b649582SRandall Stewart * out the ASCONF. 2960f8829a4aSRandall Stewart */ 2961f8829a4aSRandall Stewart if (status == 0 && 2962f8829a4aSRandall Stewart SCTP_GET_STATE(&stcb->asoc) == 2963f8829a4aSRandall Stewart SCTP_STATE_OPEN) { 29641b649582SRandall Stewart #ifdef SCTP_TIMER_BASED_ASCONF 2965f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, 2966f8829a4aSRandall Stewart stcb->sctp_ep, stcb, 2967f8829a4aSRandall Stewart stcb->asoc.primary_destination); 29681b649582SRandall Stewart #else 29693232788eSRandall Stewart sctp_send_asconf(stcb, stcb->asoc.primary_destination, 29703232788eSRandall Stewart SCTP_ADDR_NOT_LOCKED); 29711b649582SRandall Stewart #endif 2972f8829a4aSRandall Stewart } 2973f8829a4aSRandall Stewart } 2974f8829a4aSRandall Stewart } 2975f8829a4aSRandall Stewart next_addr: 2976f8829a4aSRandall Stewart /* 2977f8829a4aSRandall Stewart * Sanity check: Make sure the length isn't 0, otherwise 2978f8829a4aSRandall Stewart * we'll be stuck in this loop for a long time... 2979f8829a4aSRandall Stewart */ 2980f8829a4aSRandall Stewart if (SCTP_SIZE32(plen) == 0) { 2981ad81507eSRandall Stewart SCTP_PRINTF("process_initack_addrs: bad len (%d) type=%xh\n", 2982f8829a4aSRandall Stewart plen, ptype); 2983f8829a4aSRandall Stewart return; 2984f8829a4aSRandall Stewart } 2985f8829a4aSRandall Stewart /* get next parameter */ 2986f8829a4aSRandall Stewart offset += SCTP_SIZE32(plen); 2987f8829a4aSRandall Stewart if ((offset + sizeof(struct sctp_paramhdr)) > length) 2988f8829a4aSRandall Stewart return; 2989f8829a4aSRandall Stewart ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset, 2990f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr), (uint8_t *) & tmp_param); 2991f8829a4aSRandall Stewart } /* while */ 2992f8829a4aSRandall Stewart } 2993f8829a4aSRandall Stewart 2994f8829a4aSRandall Stewart /* FIX ME: need to verify return result for v6 address type if v6 disabled */ 2995f8829a4aSRandall Stewart /* 2996f8829a4aSRandall Stewart * checks to see if a specific address is in the initack address list returns 2997f8829a4aSRandall Stewart * 1 if found, 0 if not 2998f8829a4aSRandall Stewart */ 2999f8829a4aSRandall Stewart static uint32_t 3000f8829a4aSRandall Stewart sctp_addr_in_initack(struct sctp_tcb *stcb, struct mbuf *m, uint32_t offset, 3001f8829a4aSRandall Stewart uint32_t length, struct sockaddr *sa) 3002f8829a4aSRandall Stewart { 3003f8829a4aSRandall Stewart struct sctp_paramhdr tmp_param, *ph; 3004f8829a4aSRandall Stewart uint16_t plen, ptype; 3005f8829a4aSRandall Stewart struct sctp_ipv6addr_param addr_store; 3006*e6194c2eSMichael Tuexen 3007*e6194c2eSMichael Tuexen #ifdef INET 3008f8829a4aSRandall Stewart struct sockaddr_in *sin; 3009f8829a4aSRandall Stewart struct sctp_ipv4addr_param *a4p; 3010f8829a4aSRandall Stewart 3011*e6194c2eSMichael Tuexen #endif 3012f8829a4aSRandall Stewart #ifdef INET6 301342551e99SRandall Stewart struct sockaddr_in6 *sin6; 3014f8829a4aSRandall Stewart struct sctp_ipv6addr_param *a6p; 301542551e99SRandall Stewart struct sockaddr_in6 sin6_tmp; 3016f8829a4aSRandall Stewart 3017*e6194c2eSMichael Tuexen #endif 3018f8829a4aSRandall Stewart 3019*e6194c2eSMichael Tuexen switch (sa->sa_family) { 3020*e6194c2eSMichael Tuexen #ifdef INET 3021*e6194c2eSMichael Tuexen case AF_INET: 3022*e6194c2eSMichael Tuexen break; 3023*e6194c2eSMichael Tuexen #endif 3024f8829a4aSRandall Stewart #ifdef INET6 3025*e6194c2eSMichael Tuexen case AF_INET6: 3026*e6194c2eSMichael Tuexen break; 3027*e6194c2eSMichael Tuexen #endif 3028*e6194c2eSMichael Tuexen default: 3029f8829a4aSRandall Stewart return (0); 3030*e6194c2eSMichael Tuexen } 3031f8829a4aSRandall Stewart 3032ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF2, "find_initack_addr: starting search for "); 3033ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, sa); 3034f8829a4aSRandall Stewart /* convert to upper bound */ 3035f8829a4aSRandall Stewart length += offset; 3036f8829a4aSRandall Stewart 3037f8829a4aSRandall Stewart if ((offset + sizeof(struct sctp_paramhdr)) > length) { 3038ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 3039ad81507eSRandall Stewart "find_initack_addr: invalid offset?\n"); 3040f8829a4aSRandall Stewart return (0); 3041f8829a4aSRandall Stewart } 3042f8829a4aSRandall Stewart /* go through the addresses in the init-ack */ 3043f8829a4aSRandall Stewart ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset, 3044f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr), (uint8_t *) & tmp_param); 3045f8829a4aSRandall Stewart while (ph != NULL) { 3046f8829a4aSRandall Stewart ptype = ntohs(ph->param_type); 3047f8829a4aSRandall Stewart plen = ntohs(ph->param_length); 3048*e6194c2eSMichael Tuexen switch (ptype) { 3049f8829a4aSRandall Stewart #ifdef INET6 3050*e6194c2eSMichael Tuexen case SCTP_IPV6_ADDRESS: 3051*e6194c2eSMichael Tuexen if (sa->sa_family == AF_INET6) { 3052*e6194c2eSMichael Tuexen /* get the entire IPv6 address param */ 3053*e6194c2eSMichael Tuexen if (plen != sizeof(struct sctp_ipv6addr_param)) { 3054*e6194c2eSMichael Tuexen break; 3055*e6194c2eSMichael Tuexen } 3056f8829a4aSRandall Stewart /* get the entire IPv6 address param */ 3057f8829a4aSRandall Stewart a6p = (struct sctp_ipv6addr_param *) 3058f8829a4aSRandall Stewart sctp_m_getptr(m, offset, 3059f8829a4aSRandall Stewart sizeof(struct sctp_ipv6addr_param), 3060f8829a4aSRandall Stewart (uint8_t *) & addr_store); 3061*e6194c2eSMichael Tuexen if (a6p == NULL) { 3062f8829a4aSRandall Stewart return (0); 3063f8829a4aSRandall Stewart } 3064f8829a4aSRandall Stewart sin6 = (struct sockaddr_in6 *)sa; 3065f8829a4aSRandall Stewart if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr)) { 3066f8829a4aSRandall Stewart /* create a copy and clear scope */ 3067f8829a4aSRandall Stewart memcpy(&sin6_tmp, sin6, 3068f8829a4aSRandall Stewart sizeof(struct sockaddr_in6)); 3069f8829a4aSRandall Stewart sin6 = &sin6_tmp; 3070f8829a4aSRandall Stewart in6_clearscope(&sin6->sin6_addr); 3071f8829a4aSRandall Stewart } 3072f8829a4aSRandall Stewart if (memcmp(&sin6->sin6_addr, a6p->addr, 3073f8829a4aSRandall Stewart sizeof(struct in6_addr)) == 0) { 3074f8829a4aSRandall Stewart /* found it */ 3075f8829a4aSRandall Stewart return (1); 3076f8829a4aSRandall Stewart } 3077*e6194c2eSMichael Tuexen } 3078*e6194c2eSMichael Tuexen break; 3079f8829a4aSRandall Stewart #endif /* INET6 */ 3080*e6194c2eSMichael Tuexen #ifdef INET 3081*e6194c2eSMichael Tuexen case SCTP_IPV4_ADDRESS: 3082*e6194c2eSMichael Tuexen if (sa->sa_family == AF_INET) { 3083*e6194c2eSMichael Tuexen if (plen != sizeof(struct sctp_ipv4addr_param)) { 3084*e6194c2eSMichael Tuexen break; 3085*e6194c2eSMichael Tuexen } 3086f8829a4aSRandall Stewart /* get the entire IPv4 address param */ 3087*e6194c2eSMichael Tuexen a4p = (struct sctp_ipv4addr_param *) 3088*e6194c2eSMichael Tuexen sctp_m_getptr(m, offset, 3089*e6194c2eSMichael Tuexen sizeof(struct sctp_ipv4addr_param), 3090f8829a4aSRandall Stewart (uint8_t *) & addr_store); 3091*e6194c2eSMichael Tuexen if (a4p == NULL) { 3092f8829a4aSRandall Stewart return (0); 3093f8829a4aSRandall Stewart } 3094f8829a4aSRandall Stewart sin = (struct sockaddr_in *)sa; 3095f8829a4aSRandall Stewart if (sin->sin_addr.s_addr == a4p->addr) { 3096f8829a4aSRandall Stewart /* found it */ 3097f8829a4aSRandall Stewart return (1); 3098f8829a4aSRandall Stewart } 3099f8829a4aSRandall Stewart } 3100*e6194c2eSMichael Tuexen break; 3101*e6194c2eSMichael Tuexen #endif 3102*e6194c2eSMichael Tuexen default: 3103*e6194c2eSMichael Tuexen break; 3104*e6194c2eSMichael Tuexen } 3105f8829a4aSRandall Stewart /* get next parameter */ 3106f8829a4aSRandall Stewart offset += SCTP_SIZE32(plen); 3107*e6194c2eSMichael Tuexen if (offset + sizeof(struct sctp_paramhdr) > length) { 3108f8829a4aSRandall Stewart return (0); 3109*e6194c2eSMichael Tuexen } 3110f8829a4aSRandall Stewart ph = (struct sctp_paramhdr *) 3111f8829a4aSRandall Stewart sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), 3112f8829a4aSRandall Stewart (uint8_t *) & tmp_param); 3113f8829a4aSRandall Stewart } /* while */ 3114f8829a4aSRandall Stewart /* not found! */ 3115f8829a4aSRandall Stewart return (0); 3116f8829a4aSRandall Stewart } 3117f8829a4aSRandall Stewart 3118f8829a4aSRandall Stewart /* 3119f8829a4aSRandall Stewart * makes sure that the current endpoint local addr list is consistent with 3120f8829a4aSRandall Stewart * the new association (eg. subset bound, asconf allowed) adds addresses as 3121f8829a4aSRandall Stewart * necessary 3122f8829a4aSRandall Stewart */ 3123f8829a4aSRandall Stewart static void 3124f8829a4aSRandall Stewart sctp_check_address_list_ep(struct sctp_tcb *stcb, struct mbuf *m, int offset, 3125f8829a4aSRandall Stewart int length, struct sockaddr *init_addr) 3126f8829a4aSRandall Stewart { 3127f8829a4aSRandall Stewart struct sctp_laddr *laddr; 3128f8829a4aSRandall Stewart 3129f8829a4aSRandall Stewart /* go through the endpoint list */ 3130f8829a4aSRandall Stewart LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) { 3131f8829a4aSRandall Stewart /* be paranoid and validate the laddr */ 3132f8829a4aSRandall Stewart if (laddr->ifa == NULL) { 3133ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 3134ad81507eSRandall Stewart "check_addr_list_ep: laddr->ifa is NULL"); 3135f8829a4aSRandall Stewart continue; 3136f8829a4aSRandall Stewart } 313742551e99SRandall Stewart if (laddr->ifa == NULL) { 3138ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "check_addr_list_ep: laddr->ifa->ifa_addr is NULL"); 3139f8829a4aSRandall Stewart continue; 3140f8829a4aSRandall Stewart } 3141f8829a4aSRandall Stewart /* do i have it implicitly? */ 314242551e99SRandall Stewart if (sctp_cmpaddr(&laddr->ifa->address.sa, init_addr)) { 3143f8829a4aSRandall Stewart continue; 3144f8829a4aSRandall Stewart } 3145f8829a4aSRandall Stewart /* check to see if in the init-ack */ 3146f8829a4aSRandall Stewart if (!sctp_addr_in_initack(stcb, m, offset, length, 314742551e99SRandall Stewart &laddr->ifa->address.sa)) { 3148f8829a4aSRandall Stewart /* try to add it */ 3149f8829a4aSRandall Stewart sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb, laddr->ifa, 31503232788eSRandall Stewart SCTP_ADD_IP_ADDRESS, SCTP_ADDR_NOT_LOCKED); 3151f8829a4aSRandall Stewart } 3152f8829a4aSRandall Stewart } 3153f8829a4aSRandall Stewart } 3154f8829a4aSRandall Stewart 3155f8829a4aSRandall Stewart /* 3156f8829a4aSRandall Stewart * makes sure that the current kernel address list is consistent with the new 3157f8829a4aSRandall Stewart * association (with all addrs bound) adds addresses as necessary 3158f8829a4aSRandall Stewart */ 3159f8829a4aSRandall Stewart static void 3160f8829a4aSRandall Stewart sctp_check_address_list_all(struct sctp_tcb *stcb, struct mbuf *m, int offset, 3161f8829a4aSRandall Stewart int length, struct sockaddr *init_addr, 3162f8829a4aSRandall Stewart uint16_t local_scope, uint16_t site_scope, 3163f8829a4aSRandall Stewart uint16_t ipv4_scope, uint16_t loopback_scope) 3164f8829a4aSRandall Stewart { 316542551e99SRandall Stewart struct sctp_vrf *vrf = NULL; 316642551e99SRandall Stewart struct sctp_ifn *sctp_ifn; 316742551e99SRandall Stewart struct sctp_ifa *sctp_ifa; 316842551e99SRandall Stewart uint32_t vrf_id; 3169f8829a4aSRandall Stewart 3170bff64a4dSRandall Stewart if (stcb) { 3171bff64a4dSRandall Stewart vrf_id = stcb->asoc.vrf_id; 3172bff64a4dSRandall Stewart } else { 3173ad81507eSRandall Stewart return; 3174bff64a4dSRandall Stewart } 3175c99efcf6SRandall Stewart SCTP_IPI_ADDR_RLOCK(); 317642551e99SRandall Stewart vrf = sctp_find_vrf(vrf_id); 317742551e99SRandall Stewart if (vrf == NULL) { 3178c99efcf6SRandall Stewart SCTP_IPI_ADDR_RUNLOCK(); 317942551e99SRandall Stewart return; 318042551e99SRandall Stewart } 3181f8829a4aSRandall Stewart /* go through all our known interfaces */ 318242551e99SRandall Stewart LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) { 318342551e99SRandall Stewart if (loopback_scope == 0 && SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) { 3184f8829a4aSRandall Stewart /* skip loopback interface */ 3185f8829a4aSRandall Stewart continue; 3186f8829a4aSRandall Stewart } 3187f8829a4aSRandall Stewart /* go through each interface address */ 318842551e99SRandall Stewart LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) { 3189f8829a4aSRandall Stewart /* do i have it implicitly? */ 319042551e99SRandall Stewart if (sctp_cmpaddr(&sctp_ifa->address.sa, init_addr)) { 3191f8829a4aSRandall Stewart continue; 3192f8829a4aSRandall Stewart } 3193f8829a4aSRandall Stewart /* check to see if in the init-ack */ 3194f8829a4aSRandall Stewart if (!sctp_addr_in_initack(stcb, m, offset, length, 319542551e99SRandall Stewart &sctp_ifa->address.sa)) { 3196f8829a4aSRandall Stewart /* try to add it */ 3197f8829a4aSRandall Stewart sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb, 31983232788eSRandall Stewart sctp_ifa, SCTP_ADD_IP_ADDRESS, 31993232788eSRandall Stewart SCTP_ADDR_LOCKED); 3200f8829a4aSRandall Stewart } 3201f8829a4aSRandall Stewart } /* end foreach ifa */ 3202f8829a4aSRandall Stewart } /* end foreach ifn */ 3203c99efcf6SRandall Stewart SCTP_IPI_ADDR_RUNLOCK(); 3204f8829a4aSRandall Stewart } 3205f8829a4aSRandall Stewart 3206f8829a4aSRandall Stewart /* 3207f8829a4aSRandall Stewart * validates an init-ack chunk (from a cookie-echo) with current addresses 3208f8829a4aSRandall Stewart * adds addresses from the init-ack into our local address list, if needed 3209f8829a4aSRandall Stewart * queues asconf adds/deletes addresses as needed and makes appropriate list 3210f8829a4aSRandall Stewart * changes for source address selection m, offset: points to the start of the 3211f8829a4aSRandall Stewart * address list in an init-ack chunk length: total length of the address 3212f8829a4aSRandall Stewart * params only init_addr: address where my INIT-ACK was sent from 3213f8829a4aSRandall Stewart */ 3214f8829a4aSRandall Stewart void 3215f8829a4aSRandall Stewart sctp_check_address_list(struct sctp_tcb *stcb, struct mbuf *m, int offset, 3216f8829a4aSRandall Stewart int length, struct sockaddr *init_addr, 3217f8829a4aSRandall Stewart uint16_t local_scope, uint16_t site_scope, 3218f8829a4aSRandall Stewart uint16_t ipv4_scope, uint16_t loopback_scope) 3219f8829a4aSRandall Stewart { 3220f8829a4aSRandall Stewart /* process the local addresses in the initack */ 3221f8829a4aSRandall Stewart sctp_process_initack_addresses(stcb, m, offset, length); 3222f8829a4aSRandall Stewart 3223f8829a4aSRandall Stewart if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { 3224f8829a4aSRandall Stewart /* bound all case */ 3225f8829a4aSRandall Stewart sctp_check_address_list_all(stcb, m, offset, length, init_addr, 3226f8829a4aSRandall Stewart local_scope, site_scope, ipv4_scope, loopback_scope); 3227f8829a4aSRandall Stewart } else { 3228f8829a4aSRandall Stewart /* subset bound case */ 3229f8829a4aSRandall Stewart if (sctp_is_feature_on(stcb->sctp_ep, 3230f8829a4aSRandall Stewart SCTP_PCB_FLAGS_DO_ASCONF)) { 3231f8829a4aSRandall Stewart /* asconf's allowed */ 3232f8829a4aSRandall Stewart sctp_check_address_list_ep(stcb, m, offset, length, 3233f8829a4aSRandall Stewart init_addr); 3234f8829a4aSRandall Stewart } 3235f8829a4aSRandall Stewart /* else, no asconfs allowed, so what we sent is what we get */ 3236f8829a4aSRandall Stewart } 3237f8829a4aSRandall Stewart } 3238f8829a4aSRandall Stewart 3239f8829a4aSRandall Stewart /* 3240f8829a4aSRandall Stewart * sctp_bindx() support 3241f8829a4aSRandall Stewart */ 3242f8829a4aSRandall Stewart uint32_t 32433c503c28SRandall Stewart sctp_addr_mgmt_ep_sa(struct sctp_inpcb *inp, struct sockaddr *sa, 324480fefe0aSRandall Stewart uint32_t type, uint32_t vrf_id, struct sctp_ifa *sctp_ifap) 3245f8829a4aSRandall Stewart { 324642551e99SRandall Stewart struct sctp_ifa *ifa; 32472678fe1eSMichael Tuexen struct sctp_laddr *laddr, *nladdr; 3248f8829a4aSRandall Stewart 324942551e99SRandall Stewart if (sa->sa_len == 0) { 3250c4739e2fSRandall Stewart SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EINVAL); 3251f8829a4aSRandall Stewart return (EINVAL); 325242551e99SRandall Stewart } 325380fefe0aSRandall Stewart if (sctp_ifap) { 325480fefe0aSRandall Stewart ifa = sctp_ifap; 325580fefe0aSRandall Stewart } else if (type == SCTP_ADD_IP_ADDRESS) { 325642551e99SRandall Stewart /* For an add the address MUST be on the system */ 3257851b7298SRandall Stewart ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED); 325842551e99SRandall Stewart } else if (type == SCTP_DEL_IP_ADDRESS) { 325942551e99SRandall Stewart /* For a delete we need to find it in the inp */ 3260851b7298SRandall Stewart ifa = sctp_find_ifa_in_ep(inp, sa, SCTP_ADDR_NOT_LOCKED); 326142551e99SRandall Stewart } else { 326242551e99SRandall Stewart ifa = NULL; 326342551e99SRandall Stewart } 3264f8829a4aSRandall Stewart if (ifa != NULL) { 326542551e99SRandall Stewart if (type == SCTP_ADD_IP_ADDRESS) { 326642551e99SRandall Stewart sctp_add_local_addr_ep(inp, ifa, type); 326742551e99SRandall Stewart } else if (type == SCTP_DEL_IP_ADDRESS) { 32683c503c28SRandall Stewart if (inp->laddr_count < 2) { 32693c503c28SRandall Stewart /* can't delete the last local address */ 3270c4739e2fSRandall Stewart SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EINVAL); 32713c503c28SRandall Stewart return (EINVAL); 32723c503c28SRandall Stewart } 32733c503c28SRandall Stewart LIST_FOREACH(laddr, &inp->sctp_addr_list, 32743c503c28SRandall Stewart sctp_nxt_addr) { 327542551e99SRandall Stewart if (ifa == laddr->ifa) { 327642551e99SRandall Stewart /* Mark in the delete */ 327742551e99SRandall Stewart laddr->action = type; 327842551e99SRandall Stewart } 327942551e99SRandall Stewart } 328042551e99SRandall Stewart } 32812678fe1eSMichael Tuexen if (LIST_EMPTY(&inp->sctp_asoc_list)) { 328287b4fcd3SMichael Tuexen /* 328387b4fcd3SMichael Tuexen * There is no need to start the iterator if the inp 328487b4fcd3SMichael Tuexen * has no associations. 328587b4fcd3SMichael Tuexen */ 32862678fe1eSMichael Tuexen if (type == SCTP_DEL_IP_ADDRESS) { 32872678fe1eSMichael Tuexen LIST_FOREACH_SAFE(laddr, &inp->sctp_addr_list, sctp_nxt_addr, nladdr) { 32882678fe1eSMichael Tuexen if (laddr->ifa == ifa) { 32892678fe1eSMichael Tuexen sctp_del_local_addr_ep(inp, ifa); 32902678fe1eSMichael Tuexen } 32912678fe1eSMichael Tuexen } 32922678fe1eSMichael Tuexen } 32932678fe1eSMichael Tuexen } else { 329487b4fcd3SMichael Tuexen struct sctp_asconf_iterator *asc; 329587b4fcd3SMichael Tuexen struct sctp_laddr *wi; 329687b4fcd3SMichael Tuexen 329787b4fcd3SMichael Tuexen SCTP_MALLOC(asc, struct sctp_asconf_iterator *, 329887b4fcd3SMichael Tuexen sizeof(struct sctp_asconf_iterator), 329987b4fcd3SMichael Tuexen SCTP_M_ASC_IT); 330087b4fcd3SMichael Tuexen if (asc == NULL) { 330187b4fcd3SMichael Tuexen SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, ENOMEM); 330287b4fcd3SMichael Tuexen return (ENOMEM); 330387b4fcd3SMichael Tuexen } 330487b4fcd3SMichael Tuexen wi = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_laddr), struct sctp_laddr); 330587b4fcd3SMichael Tuexen if (wi == NULL) { 330687b4fcd3SMichael Tuexen SCTP_FREE(asc, SCTP_M_ASC_IT); 330787b4fcd3SMichael Tuexen SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, ENOMEM); 330887b4fcd3SMichael Tuexen return (ENOMEM); 330987b4fcd3SMichael Tuexen } 331042551e99SRandall Stewart LIST_INIT(&asc->list_of_work); 331142551e99SRandall Stewart asc->cnt = 1; 331242551e99SRandall Stewart SCTP_INCR_LADDR_COUNT(); 331342551e99SRandall Stewart wi->ifa = ifa; 331442551e99SRandall Stewart wi->action = type; 331542551e99SRandall Stewart atomic_add_int(&ifa->refcount, 1); 331642551e99SRandall Stewart LIST_INSERT_HEAD(&asc->list_of_work, wi, sctp_nxt_addr); 33171b649582SRandall Stewart (void)sctp_initiate_iterator(sctp_asconf_iterator_ep, 33181b649582SRandall Stewart sctp_asconf_iterator_stcb, 33191b649582SRandall Stewart sctp_asconf_iterator_ep_end, 332042551e99SRandall Stewart SCTP_PCB_ANY_FLAGS, 33213c503c28SRandall Stewart SCTP_PCB_ANY_FEATURES, 33221b649582SRandall Stewart SCTP_ASOC_ANY_STATE, 33231b649582SRandall Stewart (void *)asc, 0, 33241b649582SRandall Stewart sctp_asconf_iterator_end, inp, 0); 332587b4fcd3SMichael Tuexen } 332687b4fcd3SMichael Tuexen return (0); 3327f8829a4aSRandall Stewart } else { 3328f8829a4aSRandall Stewart /* invalid address! */ 3329c4739e2fSRandall Stewart SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EADDRNOTAVAIL); 3330f8829a4aSRandall Stewart return (EADDRNOTAVAIL); 3331f8829a4aSRandall Stewart } 3332f8829a4aSRandall Stewart } 3333830d754dSRandall Stewart 3334830d754dSRandall Stewart void 3335830d754dSRandall Stewart sctp_asconf_send_nat_state_update(struct sctp_tcb *stcb, 3336830d754dSRandall Stewart struct sctp_nets *net) 3337830d754dSRandall Stewart { 3338830d754dSRandall Stewart struct sctp_asconf_addr *aa; 3339830d754dSRandall Stewart struct sctp_ifa *sctp_ifap; 3340830d754dSRandall Stewart struct sctp_asconf_tag_param *vtag; 3341*e6194c2eSMichael Tuexen 3342*e6194c2eSMichael Tuexen #ifdef INET 3343830d754dSRandall Stewart struct sockaddr_in *to; 3344830d754dSRandall Stewart 3345*e6194c2eSMichael Tuexen #endif 3346830d754dSRandall Stewart #ifdef INET6 3347830d754dSRandall Stewart struct sockaddr_in6 *to6; 3348830d754dSRandall Stewart 3349830d754dSRandall Stewart #endif 3350830d754dSRandall Stewart if (net == NULL) { 3351830d754dSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing net\n"); 3352830d754dSRandall Stewart return; 3353830d754dSRandall Stewart } 3354830d754dSRandall Stewart if (stcb == NULL) { 3355830d754dSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing stcb\n"); 3356830d754dSRandall Stewart return; 3357830d754dSRandall Stewart } 3358830d754dSRandall Stewart /* 3359830d754dSRandall Stewart * Need to have in the asconf: - vtagparam(my_vtag/peer_vtag) - 3360830d754dSRandall Stewart * add(0.0.0.0) - del(0.0.0.0) - Any global addresses add(addr) 3361830d754dSRandall Stewart */ 3362830d754dSRandall Stewart SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), 3363830d754dSRandall Stewart SCTP_M_ASC_ADDR); 3364830d754dSRandall Stewart if (aa == NULL) { 3365830d754dSRandall Stewart /* didn't get memory */ 3366830d754dSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 3367830d754dSRandall Stewart "sctp_asconf_send_nat_state_update: failed to get memory!\n"); 3368830d754dSRandall Stewart return; 3369830d754dSRandall Stewart } 3370830d754dSRandall Stewart aa->special_del = 0; 3371830d754dSRandall Stewart /* fill in asconf address parameter fields */ 3372830d754dSRandall Stewart /* top level elements are "networked" during send */ 3373830d754dSRandall Stewart aa->ifa = NULL; 3374830d754dSRandall Stewart aa->sent = 0; /* clear sent flag */ 3375830d754dSRandall Stewart vtag = (struct sctp_asconf_tag_param *)&aa->ap.aph; 3376830d754dSRandall Stewart vtag->aph.ph.param_type = SCTP_NAT_VTAGS; 3377830d754dSRandall Stewart vtag->aph.ph.param_length = sizeof(struct sctp_asconf_tag_param); 3378830d754dSRandall Stewart vtag->local_vtag = htonl(stcb->asoc.my_vtag); 3379830d754dSRandall Stewart vtag->remote_vtag = htonl(stcb->asoc.peer_vtag); 3380830d754dSRandall Stewart TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); 3381830d754dSRandall Stewart 3382830d754dSRandall Stewart SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), 3383830d754dSRandall Stewart SCTP_M_ASC_ADDR); 3384830d754dSRandall Stewart if (aa == NULL) { 3385830d754dSRandall Stewart /* didn't get memory */ 3386830d754dSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 3387830d754dSRandall Stewart "sctp_asconf_send_nat_state_update: failed to get memory!\n"); 3388830d754dSRandall Stewart return; 3389830d754dSRandall Stewart } 3390830d754dSRandall Stewart memset(aa, 0, sizeof(struct sctp_asconf_addr)); 3391830d754dSRandall Stewart /* fill in asconf address parameter fields */ 3392830d754dSRandall Stewart /* ADD(0.0.0.0) */ 3393*e6194c2eSMichael Tuexen switch (net->ro._l_addr.sa.sa_family) { 3394*e6194c2eSMichael Tuexen #ifdef INET 3395*e6194c2eSMichael Tuexen case AF_INET: 3396830d754dSRandall Stewart aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS; 3397830d754dSRandall Stewart aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param); 3398830d754dSRandall Stewart aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS; 3399830d754dSRandall Stewart aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv4addr_param); 3400830d754dSRandall Stewart /* No need to add an address, we are using 0.0.0.0 */ 3401830d754dSRandall Stewart TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); 3402*e6194c2eSMichael Tuexen break; 3403*e6194c2eSMichael Tuexen #endif 3404830d754dSRandall Stewart #ifdef INET6 3405*e6194c2eSMichael Tuexen case AF_INET6: 3406830d754dSRandall Stewart aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS; 3407830d754dSRandall Stewart aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param); 3408830d754dSRandall Stewart aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS; 3409830d754dSRandall Stewart aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv6addr_param); 3410830d754dSRandall Stewart /* No need to add an address, we are using 0.0.0.0 */ 3411830d754dSRandall Stewart TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); 3412*e6194c2eSMichael Tuexen break; 3413*e6194c2eSMichael Tuexen #endif 3414830d754dSRandall Stewart } 3415830d754dSRandall Stewart SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), 3416830d754dSRandall Stewart SCTP_M_ASC_ADDR); 3417830d754dSRandall Stewart if (aa == NULL) { 3418830d754dSRandall Stewart /* didn't get memory */ 3419830d754dSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 3420830d754dSRandall Stewart "sctp_asconf_send_nat_state_update: failed to get memory!\n"); 3421830d754dSRandall Stewart return; 3422830d754dSRandall Stewart } 3423830d754dSRandall Stewart memset(aa, 0, sizeof(struct sctp_asconf_addr)); 3424830d754dSRandall Stewart /* fill in asconf address parameter fields */ 3425830d754dSRandall Stewart /* ADD(0.0.0.0) */ 3426*e6194c2eSMichael Tuexen switch (net->ro._l_addr.sa.sa_family) { 3427*e6194c2eSMichael Tuexen #ifdef INET 3428*e6194c2eSMichael Tuexen case AF_INET: 3429830d754dSRandall Stewart aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS; 3430830d754dSRandall Stewart aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param); 3431830d754dSRandall Stewart aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS; 3432830d754dSRandall Stewart aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv4addr_param); 3433830d754dSRandall Stewart /* No need to add an address, we are using 0.0.0.0 */ 3434830d754dSRandall Stewart TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); 3435*e6194c2eSMichael Tuexen break; 3436*e6194c2eSMichael Tuexen #endif 3437830d754dSRandall Stewart #ifdef INET6 3438*e6194c2eSMichael Tuexen case AF_INET6: 3439830d754dSRandall Stewart aa->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS; 3440830d754dSRandall Stewart aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param); 3441830d754dSRandall Stewart aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS; 3442830d754dSRandall Stewart aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv6addr_param); 3443830d754dSRandall Stewart /* No need to add an address, we are using 0.0.0.0 */ 3444830d754dSRandall Stewart TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); 3445*e6194c2eSMichael Tuexen break; 3446*e6194c2eSMichael Tuexen #endif 3447830d754dSRandall Stewart } 3448830d754dSRandall Stewart /* Now we must hunt the addresses and add all global addresses */ 3449830d754dSRandall Stewart if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { 3450830d754dSRandall Stewart struct sctp_vrf *vrf = NULL; 3451830d754dSRandall Stewart struct sctp_ifn *sctp_ifnp; 3452830d754dSRandall Stewart uint32_t vrf_id; 3453830d754dSRandall Stewart 3454830d754dSRandall Stewart vrf_id = stcb->sctp_ep->def_vrf_id; 3455830d754dSRandall Stewart vrf = sctp_find_vrf(vrf_id); 3456830d754dSRandall Stewart if (vrf == NULL) { 3457830d754dSRandall Stewart goto skip_rest; 3458830d754dSRandall Stewart } 3459830d754dSRandall Stewart SCTP_IPI_ADDR_RLOCK(); 3460830d754dSRandall Stewart LIST_FOREACH(sctp_ifnp, &vrf->ifnlist, next_ifn) { 3461830d754dSRandall Stewart LIST_FOREACH(sctp_ifap, &sctp_ifnp->ifalist, next_ifa) { 3462*e6194c2eSMichael Tuexen switch (sctp_ifap->address.sa.sa_family) { 3463*e6194c2eSMichael Tuexen #ifdef INET 3464*e6194c2eSMichael Tuexen case AF_INET: 3465830d754dSRandall Stewart to = &sctp_ifap->address.sin; 3466830d754dSRandall Stewart if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) { 3467830d754dSRandall Stewart continue; 3468830d754dSRandall Stewart } 3469830d754dSRandall Stewart if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) { 3470830d754dSRandall Stewart continue; 3471830d754dSRandall Stewart } 3472*e6194c2eSMichael Tuexen break; 3473*e6194c2eSMichael Tuexen #endif 3474830d754dSRandall Stewart #ifdef INET6 3475*e6194c2eSMichael Tuexen case AF_INET6: 3476830d754dSRandall Stewart to6 = &sctp_ifap->address.sin6; 3477830d754dSRandall Stewart if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) { 3478830d754dSRandall Stewart continue; 3479830d754dSRandall Stewart } 3480830d754dSRandall Stewart if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) { 3481830d754dSRandall Stewart continue; 3482830d754dSRandall Stewart } 3483*e6194c2eSMichael Tuexen break; 3484830d754dSRandall Stewart #endif 3485*e6194c2eSMichael Tuexen default: 3486*e6194c2eSMichael Tuexen continue; 3487*e6194c2eSMichael Tuexen } 3488830d754dSRandall Stewart sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS); 3489830d754dSRandall Stewart } 3490830d754dSRandall Stewart } 3491830d754dSRandall Stewart SCTP_IPI_ADDR_RUNLOCK(); 3492830d754dSRandall Stewart } else { 3493830d754dSRandall Stewart struct sctp_laddr *laddr; 3494830d754dSRandall Stewart 3495830d754dSRandall Stewart LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) { 3496830d754dSRandall Stewart if (laddr->ifa == NULL) { 3497830d754dSRandall Stewart continue; 3498830d754dSRandall Stewart } 3499830d754dSRandall Stewart if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED) 3500830d754dSRandall Stewart /* 3501830d754dSRandall Stewart * Address being deleted by the system, dont 3502830d754dSRandall Stewart * list. 3503830d754dSRandall Stewart */ 3504830d754dSRandall Stewart continue; 3505830d754dSRandall Stewart if (laddr->action == SCTP_DEL_IP_ADDRESS) { 3506830d754dSRandall Stewart /* 3507830d754dSRandall Stewart * Address being deleted on this ep don't 3508830d754dSRandall Stewart * list. 3509830d754dSRandall Stewart */ 3510830d754dSRandall Stewart continue; 3511830d754dSRandall Stewart } 3512830d754dSRandall Stewart sctp_ifap = laddr->ifa; 3513*e6194c2eSMichael Tuexen switch (sctp_ifap->address.sa.sa_family) { 3514*e6194c2eSMichael Tuexen #ifdef INET 3515*e6194c2eSMichael Tuexen case AF_INET: 3516830d754dSRandall Stewart to = &sctp_ifap->address.sin; 3517830d754dSRandall Stewart if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) { 3518830d754dSRandall Stewart continue; 3519830d754dSRandall Stewart } 3520830d754dSRandall Stewart if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) { 3521830d754dSRandall Stewart continue; 3522830d754dSRandall Stewart } 3523*e6194c2eSMichael Tuexen break; 3524*e6194c2eSMichael Tuexen #endif 3525830d754dSRandall Stewart #ifdef INET6 3526*e6194c2eSMichael Tuexen case AF_INET6: 3527830d754dSRandall Stewart to6 = &sctp_ifap->address.sin6; 3528830d754dSRandall Stewart if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) { 3529830d754dSRandall Stewart continue; 3530830d754dSRandall Stewart } 3531830d754dSRandall Stewart if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) { 3532830d754dSRandall Stewart continue; 3533830d754dSRandall Stewart } 3534*e6194c2eSMichael Tuexen break; 3535830d754dSRandall Stewart #endif 3536*e6194c2eSMichael Tuexen default: 3537*e6194c2eSMichael Tuexen continue; 3538*e6194c2eSMichael Tuexen } 3539830d754dSRandall Stewart sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS); 3540830d754dSRandall Stewart } 3541830d754dSRandall Stewart } 3542830d754dSRandall Stewart skip_rest: 3543830d754dSRandall Stewart /* Now we must send the asconf into the queue */ 3544830d754dSRandall Stewart sctp_send_asconf(stcb, net, 0); 3545830d754dSRandall Stewart } 3546