1f8829a4aSRandall Stewart /*- 2b1006367SRandall Stewart * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved. 3f8829a4aSRandall Stewart * 4f8829a4aSRandall Stewart * Redistribution and use in source and binary forms, with or without 5f8829a4aSRandall Stewart * modification, are permitted provided that the following conditions are met: 6f8829a4aSRandall Stewart * 7f8829a4aSRandall Stewart * a) Redistributions of source code must retain the above copyright notice, 8f8829a4aSRandall Stewart * this list of conditions and the following disclaimer. 9f8829a4aSRandall Stewart * 10f8829a4aSRandall Stewart * b) Redistributions in binary form must reproduce the above copyright 11f8829a4aSRandall Stewart * notice, this list of conditions and the following disclaimer in 12f8829a4aSRandall Stewart * the documentation and/or other materials provided with the distribution. 13f8829a4aSRandall Stewart * 14f8829a4aSRandall Stewart * c) Neither the name of Cisco Systems, Inc. nor the names of its 15f8829a4aSRandall Stewart * contributors may be used to endorse or promote products derived 16f8829a4aSRandall Stewart * from this software without specific prior written permission. 17f8829a4aSRandall Stewart * 18f8829a4aSRandall Stewart * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19f8829a4aSRandall Stewart * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20f8829a4aSRandall Stewart * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21f8829a4aSRandall Stewart * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22f8829a4aSRandall Stewart * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23f8829a4aSRandall Stewart * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24f8829a4aSRandall Stewart * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25f8829a4aSRandall Stewart * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26f8829a4aSRandall Stewart * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27f8829a4aSRandall Stewart * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28f8829a4aSRandall Stewart * THE POSSIBILITY OF SUCH DAMAGE. 29f8829a4aSRandall Stewart */ 30f8829a4aSRandall Stewart 31f8829a4aSRandall Stewart /* $KAME: sctp_asconf.c,v 1.24 2005/03/06 16:04:16 itojun Exp $ */ 32f8829a4aSRandall Stewart 33f8829a4aSRandall Stewart #include <sys/cdefs.h> 34cef8ad06SRandall Stewart __FBSDID("$FreeBSD$"); 35f8829a4aSRandall Stewart #include <netinet/sctp_os.h> 36f8829a4aSRandall Stewart #include <netinet/sctp_var.h> 3742551e99SRandall Stewart #include <netinet/sctp_sysctl.h> 38f8829a4aSRandall Stewart #include <netinet/sctp_pcb.h> 39f8829a4aSRandall Stewart #include <netinet/sctp_header.h> 40f8829a4aSRandall Stewart #include <netinet/sctputil.h> 41f8829a4aSRandall Stewart #include <netinet/sctp_output.h> 42f8829a4aSRandall Stewart #include <netinet/sctp_asconf.h> 43851b7298SRandall Stewart #include <netinet/sctp_timer.h> 44f8829a4aSRandall Stewart 45f8829a4aSRandall Stewart /* 46f8829a4aSRandall Stewart * debug flags: 47f8829a4aSRandall Stewart * SCTP_DEBUG_ASCONF1: protocol info, general info and errors 48f8829a4aSRandall Stewart * SCTP_DEBUG_ASCONF2: detailed info 49f8829a4aSRandall Stewart */ 50f8829a4aSRandall Stewart #ifdef SCTP_DEBUG 51f8829a4aSRandall Stewart #endif /* SCTP_DEBUG */ 52f8829a4aSRandall Stewart 53f8829a4aSRandall Stewart 54ad81507eSRandall Stewart static void 55f8829a4aSRandall Stewart sctp_asconf_get_source_ip(struct mbuf *m, struct sockaddr *sa) 56f8829a4aSRandall Stewart { 57f8829a4aSRandall Stewart struct ip *iph; 58f8829a4aSRandall Stewart struct sockaddr_in *sin; 59f8829a4aSRandall Stewart 60f8829a4aSRandall Stewart #ifdef INET6 61f8829a4aSRandall Stewart struct sockaddr_in6 *sin6; 62f8829a4aSRandall Stewart 63f8829a4aSRandall Stewart #endif 64f8829a4aSRandall Stewart 65f8829a4aSRandall Stewart iph = mtod(m, struct ip *); 66f8829a4aSRandall Stewart if (iph->ip_v == IPVERSION) { 67f8829a4aSRandall Stewart /* IPv4 source */ 68f8829a4aSRandall Stewart sin = (struct sockaddr_in *)sa; 69f8829a4aSRandall Stewart bzero(sin, sizeof(*sin)); 70f8829a4aSRandall Stewart sin->sin_family = AF_INET; 71f8829a4aSRandall Stewart sin->sin_len = sizeof(struct sockaddr_in); 72f8829a4aSRandall Stewart sin->sin_port = 0; 73f8829a4aSRandall Stewart sin->sin_addr.s_addr = iph->ip_src.s_addr; 74ad81507eSRandall Stewart return; 75f8829a4aSRandall Stewart } 76f8829a4aSRandall Stewart #ifdef INET6 77f8829a4aSRandall Stewart else if (iph->ip_v == (IPV6_VERSION >> 4)) { 78f8829a4aSRandall Stewart /* IPv6 source */ 79f8829a4aSRandall Stewart struct ip6_hdr *ip6; 80f8829a4aSRandall Stewart 81f8829a4aSRandall Stewart sin6 = (struct sockaddr_in6 *)sa; 82f8829a4aSRandall Stewart bzero(sin6, sizeof(*sin6)); 83f8829a4aSRandall Stewart sin6->sin6_family = AF_INET6; 84f8829a4aSRandall Stewart sin6->sin6_len = sizeof(struct sockaddr_in6); 85f8829a4aSRandall Stewart sin6->sin6_port = 0; 86f8829a4aSRandall Stewart ip6 = mtod(m, struct ip6_hdr *); 87f8829a4aSRandall Stewart sin6->sin6_addr = ip6->ip6_src; 88ad81507eSRandall Stewart return; 89f8829a4aSRandall Stewart } 90f8829a4aSRandall Stewart #endif /* INET6 */ 91f8829a4aSRandall Stewart else 92ad81507eSRandall Stewart return; 93f8829a4aSRandall Stewart } 94f8829a4aSRandall Stewart 95f8829a4aSRandall Stewart /* 96f8829a4aSRandall Stewart * draft-ietf-tsvwg-addip-sctp 97f8829a4aSRandall Stewart * 98f8829a4aSRandall Stewart * An ASCONF parameter queue exists per asoc which holds the pending address 99f8829a4aSRandall Stewart * operations. Lists are updated upon receipt of ASCONF-ACK. 100f8829a4aSRandall Stewart * 10118e198d3SRandall Stewart * A restricted_addrs list exists per assoc to hold local addresses that are 10218e198d3SRandall Stewart * not (yet) usable by the assoc as a source address. These addresses are 10318e198d3SRandall Stewart * either pending an ASCONF operation (and exist on the ASCONF parameter 10418e198d3SRandall Stewart * queue), or they are permanently restricted (the peer has returned an 10518e198d3SRandall Stewart * ERROR indication to an ASCONF(ADD), or the peer does not support ASCONF). 10618e198d3SRandall Stewart * 107f8829a4aSRandall Stewart * Deleted addresses are always immediately removed from the lists as they will 108f8829a4aSRandall Stewart * (shortly) no longer exist in the kernel. We send ASCONFs as a courtesy, 109f8829a4aSRandall Stewart * only if allowed. 110f8829a4aSRandall Stewart */ 111f8829a4aSRandall Stewart 112f8829a4aSRandall Stewart /* 11318e198d3SRandall Stewart * ASCONF parameter processing. 11418e198d3SRandall Stewart * response_required: set if a reply is required (eg. SUCCESS_REPORT). 11518e198d3SRandall Stewart * returns a mbuf to an "error" response parameter or NULL/"success" if ok. 11618e198d3SRandall Stewart * FIX: allocating this many mbufs on the fly is pretty inefficient... 117f8829a4aSRandall Stewart */ 118f8829a4aSRandall Stewart static struct mbuf * 119f8829a4aSRandall Stewart sctp_asconf_success_response(uint32_t id) 120f8829a4aSRandall Stewart { 121f8829a4aSRandall Stewart struct mbuf *m_reply = NULL; 122f8829a4aSRandall Stewart struct sctp_asconf_paramhdr *aph; 123f8829a4aSRandall Stewart 124f8829a4aSRandall Stewart m_reply = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_paramhdr), 125f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 126f8829a4aSRandall Stewart if (m_reply == NULL) { 127ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 128ad81507eSRandall Stewart "asconf_success_response: couldn't get mbuf!\n"); 129f8829a4aSRandall Stewart return NULL; 130f8829a4aSRandall Stewart } 131f8829a4aSRandall Stewart aph = mtod(m_reply, struct sctp_asconf_paramhdr *); 132f8829a4aSRandall Stewart aph->correlation_id = id; 133f8829a4aSRandall Stewart aph->ph.param_type = htons(SCTP_SUCCESS_REPORT); 134f8829a4aSRandall Stewart aph->ph.param_length = sizeof(struct sctp_asconf_paramhdr); 135139bc87fSRandall Stewart SCTP_BUF_LEN(m_reply) = aph->ph.param_length; 136f8829a4aSRandall Stewart aph->ph.param_length = htons(aph->ph.param_length); 137f8829a4aSRandall Stewart 138f8829a4aSRandall Stewart return m_reply; 139f8829a4aSRandall Stewart } 140f8829a4aSRandall Stewart 141f8829a4aSRandall Stewart static struct mbuf * 142f8829a4aSRandall Stewart sctp_asconf_error_response(uint32_t id, uint16_t cause, uint8_t * error_tlv, 143f8829a4aSRandall Stewart uint16_t tlv_length) 144f8829a4aSRandall Stewart { 145f8829a4aSRandall Stewart struct mbuf *m_reply = NULL; 146f8829a4aSRandall Stewart struct sctp_asconf_paramhdr *aph; 147f8829a4aSRandall Stewart struct sctp_error_cause *error; 148f8829a4aSRandall Stewart uint8_t *tlv; 149f8829a4aSRandall Stewart 150f8829a4aSRandall Stewart m_reply = sctp_get_mbuf_for_msg((sizeof(struct sctp_asconf_paramhdr) + 151f8829a4aSRandall Stewart tlv_length + 152f8829a4aSRandall Stewart sizeof(struct sctp_error_cause)), 153f8829a4aSRandall Stewart 0, M_DONTWAIT, 1, MT_DATA); 154f8829a4aSRandall Stewart if (m_reply == NULL) { 155ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 156ad81507eSRandall Stewart "asconf_error_response: couldn't get mbuf!\n"); 157f8829a4aSRandall Stewart return NULL; 158f8829a4aSRandall Stewart } 159f8829a4aSRandall Stewart aph = mtod(m_reply, struct sctp_asconf_paramhdr *); 160f8829a4aSRandall Stewart error = (struct sctp_error_cause *)(aph + 1); 161f8829a4aSRandall Stewart 162f8829a4aSRandall Stewart aph->correlation_id = id; 163f8829a4aSRandall Stewart aph->ph.param_type = htons(SCTP_ERROR_CAUSE_IND); 164f8829a4aSRandall Stewart error->code = htons(cause); 165f8829a4aSRandall Stewart error->length = tlv_length + sizeof(struct sctp_error_cause); 166f8829a4aSRandall Stewart aph->ph.param_length = error->length + 167f8829a4aSRandall Stewart sizeof(struct sctp_asconf_paramhdr); 168f8829a4aSRandall Stewart 169f8829a4aSRandall Stewart if (aph->ph.param_length > MLEN) { 170ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 171ad81507eSRandall Stewart "asconf_error_response: tlv_length (%xh) too big\n", 172f8829a4aSRandall Stewart tlv_length); 173f8829a4aSRandall Stewart sctp_m_freem(m_reply); /* discard */ 174f8829a4aSRandall Stewart return NULL; 175f8829a4aSRandall Stewart } 176f8829a4aSRandall Stewart if (error_tlv != NULL) { 177f8829a4aSRandall Stewart tlv = (uint8_t *) (error + 1); 178f8829a4aSRandall Stewart memcpy(tlv, error_tlv, tlv_length); 179f8829a4aSRandall Stewart } 180139bc87fSRandall Stewart SCTP_BUF_LEN(m_reply) = aph->ph.param_length; 181f8829a4aSRandall Stewart error->length = htons(error->length); 182f8829a4aSRandall Stewart aph->ph.param_length = htons(aph->ph.param_length); 183f8829a4aSRandall Stewart 184f8829a4aSRandall Stewart return m_reply; 185f8829a4aSRandall Stewart } 186f8829a4aSRandall Stewart 187f8829a4aSRandall Stewart static struct mbuf * 188f8829a4aSRandall Stewart sctp_process_asconf_add_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph, 189f8829a4aSRandall Stewart struct sctp_tcb *stcb, int response_required) 190f8829a4aSRandall Stewart { 191f8829a4aSRandall Stewart struct mbuf *m_reply = NULL; 192f8829a4aSRandall Stewart struct sockaddr_storage sa_source, sa_store; 193f8829a4aSRandall Stewart struct sctp_ipv4addr_param *v4addr; 194f8829a4aSRandall Stewart uint16_t param_type, param_length, aparam_length; 195f8829a4aSRandall Stewart struct sockaddr *sa; 196f8829a4aSRandall Stewart struct sockaddr_in *sin; 197f8829a4aSRandall Stewart int zero_address = 0; 198f8829a4aSRandall Stewart 199f8829a4aSRandall Stewart #ifdef INET6 200f8829a4aSRandall Stewart struct sockaddr_in6 *sin6; 201f8829a4aSRandall Stewart struct sctp_ipv6addr_param *v6addr; 202f8829a4aSRandall Stewart 203f8829a4aSRandall Stewart #endif /* INET6 */ 204f8829a4aSRandall Stewart 205f8829a4aSRandall Stewart aparam_length = ntohs(aph->ph.param_length); 206f8829a4aSRandall Stewart v4addr = (struct sctp_ipv4addr_param *)(aph + 1); 207f8829a4aSRandall Stewart #ifdef INET6 208f8829a4aSRandall Stewart v6addr = (struct sctp_ipv6addr_param *)(aph + 1); 209f8829a4aSRandall Stewart #endif /* INET6 */ 210f8829a4aSRandall Stewart param_type = ntohs(v4addr->ph.param_type); 211f8829a4aSRandall Stewart param_length = ntohs(v4addr->ph.param_length); 212f8829a4aSRandall Stewart 213f8829a4aSRandall Stewart sa = (struct sockaddr *)&sa_store; 214f8829a4aSRandall Stewart switch (param_type) { 215f8829a4aSRandall Stewart case SCTP_IPV4_ADDRESS: 216f8829a4aSRandall Stewart if (param_length != sizeof(struct sctp_ipv4addr_param)) { 217f8829a4aSRandall Stewart /* invalid param size */ 218f8829a4aSRandall Stewart return NULL; 219f8829a4aSRandall Stewart } 220f8829a4aSRandall Stewart sin = (struct sockaddr_in *)&sa_store; 221f8829a4aSRandall Stewart bzero(sin, sizeof(*sin)); 222f8829a4aSRandall Stewart sin->sin_family = AF_INET; 223f8829a4aSRandall Stewart sin->sin_len = sizeof(struct sockaddr_in); 224f8829a4aSRandall Stewart sin->sin_port = stcb->rport; 225f8829a4aSRandall Stewart sin->sin_addr.s_addr = v4addr->addr; 226f8829a4aSRandall Stewart if (sin->sin_addr.s_addr == INADDR_ANY) 227f8829a4aSRandall Stewart zero_address = 1; 228ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_add_ip: adding "); 229ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 230f8829a4aSRandall Stewart break; 231f8829a4aSRandall Stewart case SCTP_IPV6_ADDRESS: 232f8829a4aSRandall Stewart #ifdef INET6 233f8829a4aSRandall Stewart if (param_length != sizeof(struct sctp_ipv6addr_param)) { 234f8829a4aSRandall Stewart /* invalid param size */ 235f8829a4aSRandall Stewart return NULL; 236f8829a4aSRandall Stewart } 237f8829a4aSRandall Stewart sin6 = (struct sockaddr_in6 *)&sa_store; 238f8829a4aSRandall Stewart bzero(sin6, sizeof(*sin6)); 239f8829a4aSRandall Stewart sin6->sin6_family = AF_INET6; 240f8829a4aSRandall Stewart sin6->sin6_len = sizeof(struct sockaddr_in6); 241f8829a4aSRandall Stewart sin6->sin6_port = stcb->rport; 242f8829a4aSRandall Stewart memcpy((caddr_t)&sin6->sin6_addr, v6addr->addr, 243f8829a4aSRandall Stewart sizeof(struct in6_addr)); 244f8829a4aSRandall Stewart if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) 245f8829a4aSRandall Stewart zero_address = 1; 246ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_add_ip: adding "); 247ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 248f8829a4aSRandall Stewart #else 249f8829a4aSRandall Stewart /* IPv6 not enabled! */ 250f8829a4aSRandall Stewart /* FIX ME: currently sends back an invalid param error */ 251f8829a4aSRandall Stewart m_reply = sctp_asconf_error_response(aph->correlation_id, 252f8829a4aSRandall Stewart SCTP_CAUSE_INVALID_PARAM, (uint8_t *) aph, aparam_length); 253ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 254ad81507eSRandall Stewart "process_asconf_add_ip: v6 disabled- skipping "); 255ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 256f8829a4aSRandall Stewart return m_reply; 257ad81507eSRandall Stewart #endif 258f8829a4aSRandall Stewart break; 259f8829a4aSRandall Stewart default: 260f8829a4aSRandall Stewart m_reply = sctp_asconf_error_response(aph->correlation_id, 261f8829a4aSRandall Stewart SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph, 262f8829a4aSRandall Stewart aparam_length); 263f8829a4aSRandall Stewart return m_reply; 264f8829a4aSRandall Stewart } /* end switch */ 265f8829a4aSRandall Stewart 266f8829a4aSRandall Stewart /* if 0.0.0.0/::0, add the source address instead */ 267b3f1ea41SRandall Stewart if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) { 268f8829a4aSRandall Stewart sa = (struct sockaddr *)&sa_source; 269f8829a4aSRandall Stewart sctp_asconf_get_source_ip(m, sa); 270ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 271ad81507eSRandall Stewart "process_asconf_add_ip: using source addr "); 272ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 273f8829a4aSRandall Stewart } 274f8829a4aSRandall Stewart /* add the address */ 275a5d547adSRandall Stewart if (sctp_add_remote_addr(stcb, sa, SCTP_DONOT_SETSCOPE, 276a5d547adSRandall Stewart SCTP_ADDR_DYNAMIC_ADDED) != 0) { 277ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 278ad81507eSRandall Stewart "process_asconf_add_ip: error adding address\n"); 279f8829a4aSRandall Stewart m_reply = sctp_asconf_error_response(aph->correlation_id, 280f8829a4aSRandall Stewart SCTP_CAUSE_RESOURCE_SHORTAGE, (uint8_t *) aph, 281f8829a4aSRandall Stewart aparam_length); 282f8829a4aSRandall Stewart } else { 283f8829a4aSRandall Stewart /* notify upper layer */ 284ceaad40aSRandall Stewart sctp_ulp_notify(SCTP_NOTIFY_ASCONF_ADD_IP, stcb, 0, sa, SCTP_SO_NOT_LOCKED); 285f8829a4aSRandall Stewart if (response_required) { 286f8829a4aSRandall Stewart m_reply = 287f8829a4aSRandall Stewart sctp_asconf_success_response(aph->correlation_id); 288f8829a4aSRandall Stewart } 2893c503c28SRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, 2903c503c28SRandall Stewart NULL, SCTP_FROM_SCTP_ASCONF + SCTP_LOC_1); 2913c503c28SRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, 2923c503c28SRandall Stewart stcb, NULL); 293f8829a4aSRandall Stewart } 294f8829a4aSRandall Stewart 295f8829a4aSRandall Stewart return m_reply; 296f8829a4aSRandall Stewart } 297f8829a4aSRandall Stewart 298f8829a4aSRandall Stewart static int 2991b649582SRandall Stewart sctp_asconf_del_remote_addrs_except(struct sctp_tcb *stcb, struct sockaddr *src) 300f8829a4aSRandall Stewart { 301f8829a4aSRandall Stewart struct sctp_nets *src_net, *net; 302f8829a4aSRandall Stewart 303f8829a4aSRandall Stewart /* make sure the source address exists as a destination net */ 304f8829a4aSRandall Stewart src_net = sctp_findnet(stcb, src); 305f8829a4aSRandall Stewart if (src_net == NULL) { 306f8829a4aSRandall Stewart /* not found */ 307f8829a4aSRandall Stewart return -1; 308f8829a4aSRandall Stewart } 309f8829a4aSRandall Stewart /* delete all destination addresses except the source */ 310f8829a4aSRandall Stewart TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 311f8829a4aSRandall Stewart if (net != src_net) { 312f8829a4aSRandall Stewart /* delete this address */ 313f8829a4aSRandall Stewart sctp_remove_net(stcb, net); 314ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 315ad81507eSRandall Stewart "asconf_del_remote_addrs_except: deleting "); 316ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, 317ad81507eSRandall Stewart (struct sockaddr *)&net->ro._l_addr); 318f8829a4aSRandall Stewart /* notify upper layer */ 319f8829a4aSRandall Stewart sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0, 320ceaad40aSRandall Stewart (struct sockaddr *)&net->ro._l_addr, SCTP_SO_NOT_LOCKED); 321f8829a4aSRandall Stewart } 322f8829a4aSRandall Stewart } 323f8829a4aSRandall Stewart return 0; 324f8829a4aSRandall Stewart } 325f8829a4aSRandall Stewart 326f8829a4aSRandall Stewart static struct mbuf * 327f8829a4aSRandall Stewart sctp_process_asconf_delete_ip(struct mbuf *m, struct sctp_asconf_paramhdr *aph, 328f8829a4aSRandall Stewart struct sctp_tcb *stcb, int response_required) 329f8829a4aSRandall Stewart { 330f8829a4aSRandall Stewart struct mbuf *m_reply = NULL; 331f8829a4aSRandall Stewart struct sockaddr_storage sa_source, sa_store; 332f8829a4aSRandall Stewart struct sctp_ipv4addr_param *v4addr; 333f8829a4aSRandall Stewart uint16_t param_type, param_length, aparam_length; 334f8829a4aSRandall Stewart struct sockaddr *sa; 335f8829a4aSRandall Stewart struct sockaddr_in *sin; 336f8829a4aSRandall Stewart int zero_address = 0; 337f8829a4aSRandall Stewart int result; 338f8829a4aSRandall Stewart 339f8829a4aSRandall Stewart #ifdef INET6 340f8829a4aSRandall Stewart struct sockaddr_in6 *sin6; 341f8829a4aSRandall Stewart struct sctp_ipv6addr_param *v6addr; 342f8829a4aSRandall Stewart 343f8829a4aSRandall Stewart #endif /* INET6 */ 344f8829a4aSRandall Stewart 345f8829a4aSRandall Stewart /* get the source IP address for src and 0.0.0.0/::0 delete checks */ 346f8829a4aSRandall Stewart sctp_asconf_get_source_ip(m, (struct sockaddr *)&sa_source); 347f8829a4aSRandall Stewart 348f8829a4aSRandall Stewart aparam_length = ntohs(aph->ph.param_length); 349f8829a4aSRandall Stewart v4addr = (struct sctp_ipv4addr_param *)(aph + 1); 350f8829a4aSRandall Stewart #ifdef INET6 351f8829a4aSRandall Stewart v6addr = (struct sctp_ipv6addr_param *)(aph + 1); 352f8829a4aSRandall Stewart #endif /* INET6 */ 353f8829a4aSRandall Stewart param_type = ntohs(v4addr->ph.param_type); 354f8829a4aSRandall Stewart param_length = ntohs(v4addr->ph.param_length); 355f8829a4aSRandall Stewart 356f8829a4aSRandall Stewart sa = (struct sockaddr *)&sa_store; 357f8829a4aSRandall Stewart switch (param_type) { 358f8829a4aSRandall Stewart case SCTP_IPV4_ADDRESS: 359f8829a4aSRandall Stewart if (param_length != sizeof(struct sctp_ipv4addr_param)) { 360f8829a4aSRandall Stewart /* invalid param size */ 361f8829a4aSRandall Stewart return NULL; 362f8829a4aSRandall Stewart } 363f8829a4aSRandall Stewart sin = (struct sockaddr_in *)&sa_store; 364f8829a4aSRandall Stewart bzero(sin, sizeof(*sin)); 365f8829a4aSRandall Stewart sin->sin_family = AF_INET; 366f8829a4aSRandall Stewart sin->sin_len = sizeof(struct sockaddr_in); 367f8829a4aSRandall Stewart sin->sin_port = stcb->rport; 368f8829a4aSRandall Stewart sin->sin_addr.s_addr = v4addr->addr; 369f8829a4aSRandall Stewart if (sin->sin_addr.s_addr == INADDR_ANY) 370f8829a4aSRandall Stewart zero_address = 1; 371ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 372ad81507eSRandall Stewart "process_asconf_delete_ip: deleting "); 373ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 374f8829a4aSRandall Stewart break; 375f8829a4aSRandall Stewart case SCTP_IPV6_ADDRESS: 376f8829a4aSRandall Stewart if (param_length != sizeof(struct sctp_ipv6addr_param)) { 377f8829a4aSRandall Stewart /* invalid param size */ 378f8829a4aSRandall Stewart return NULL; 379f8829a4aSRandall Stewart } 380f8829a4aSRandall Stewart #ifdef INET6 381f8829a4aSRandall Stewart sin6 = (struct sockaddr_in6 *)&sa_store; 382f8829a4aSRandall Stewart bzero(sin6, sizeof(*sin6)); 383f8829a4aSRandall Stewart sin6->sin6_family = AF_INET6; 384f8829a4aSRandall Stewart sin6->sin6_len = sizeof(struct sockaddr_in6); 385f8829a4aSRandall Stewart sin6->sin6_port = stcb->rport; 386f8829a4aSRandall Stewart memcpy(&sin6->sin6_addr, v6addr->addr, 387f8829a4aSRandall Stewart sizeof(struct in6_addr)); 388f8829a4aSRandall Stewart if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) 389f8829a4aSRandall Stewart zero_address = 1; 390ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 391ad81507eSRandall Stewart "process_asconf_delete_ip: deleting "); 392ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 393f8829a4aSRandall Stewart #else 394f8829a4aSRandall Stewart /* IPv6 not enabled! No "action" needed; just ack it */ 395ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 396ad81507eSRandall Stewart "process_asconf_delete_ip: v6 disabled- ignoring: "); 397ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 398f8829a4aSRandall Stewart /* just respond with a "success" ASCONF-ACK */ 399f8829a4aSRandall Stewart return NULL; 400ad81507eSRandall Stewart #endif 401f8829a4aSRandall Stewart break; 402f8829a4aSRandall Stewart default: 403f8829a4aSRandall Stewart m_reply = sctp_asconf_error_response(aph->correlation_id, 404f8829a4aSRandall Stewart SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph, 405f8829a4aSRandall Stewart aparam_length); 406f8829a4aSRandall Stewart return m_reply; 407f8829a4aSRandall Stewart } 408f8829a4aSRandall Stewart 409f8829a4aSRandall Stewart /* make sure the source address is not being deleted */ 410f8829a4aSRandall Stewart if (sctp_cmpaddr(sa, (struct sockaddr *)&sa_source)) { 411f8829a4aSRandall Stewart /* trying to delete the source address! */ 412ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: tried to delete source addr\n"); 413f8829a4aSRandall Stewart m_reply = sctp_asconf_error_response(aph->correlation_id, 414f8829a4aSRandall Stewart SCTP_CAUSE_DELETING_SRC_ADDR, (uint8_t *) aph, 415f8829a4aSRandall Stewart aparam_length); 416f8829a4aSRandall Stewart return m_reply; 417f8829a4aSRandall Stewart } 418f8829a4aSRandall Stewart /* if deleting 0.0.0.0/::0, delete all addresses except src addr */ 419b3f1ea41SRandall Stewart if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) { 420f8829a4aSRandall Stewart result = sctp_asconf_del_remote_addrs_except(stcb, 421f8829a4aSRandall Stewart (struct sockaddr *)&sa_source); 422f8829a4aSRandall Stewart 423f8829a4aSRandall Stewart if (result) { 424f8829a4aSRandall Stewart /* src address did not exist? */ 425ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: src addr does not exist?\n"); 426f8829a4aSRandall Stewart /* what error to reply with?? */ 427f8829a4aSRandall Stewart m_reply = 428f8829a4aSRandall Stewart sctp_asconf_error_response(aph->correlation_id, 429f8829a4aSRandall Stewart SCTP_CAUSE_REQUEST_REFUSED, (uint8_t *) aph, 430f8829a4aSRandall Stewart aparam_length); 431f8829a4aSRandall Stewart } else if (response_required) { 432f8829a4aSRandall Stewart m_reply = 433f8829a4aSRandall Stewart sctp_asconf_success_response(aph->correlation_id); 434f8829a4aSRandall Stewart } 435f8829a4aSRandall Stewart return m_reply; 436f8829a4aSRandall Stewart } 437f8829a4aSRandall Stewart /* delete the address */ 438f8829a4aSRandall Stewart result = sctp_del_remote_addr(stcb, sa); 439f8829a4aSRandall Stewart /* 440f8829a4aSRandall Stewart * note if result == -2, the address doesn't exist in the asoc but 441f8829a4aSRandall Stewart * since it's being deleted anyways, we just ack the delete -- but 442f8829a4aSRandall Stewart * this probably means something has already gone awry 443f8829a4aSRandall Stewart */ 444f8829a4aSRandall Stewart if (result == -1) { 445f8829a4aSRandall Stewart /* only one address in the asoc */ 446ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: tried to delete last IP addr!\n"); 447f8829a4aSRandall Stewart m_reply = sctp_asconf_error_response(aph->correlation_id, 448f8829a4aSRandall Stewart SCTP_CAUSE_DELETING_LAST_ADDR, (uint8_t *) aph, 449f8829a4aSRandall Stewart aparam_length); 450f8829a4aSRandall Stewart } else { 451f8829a4aSRandall Stewart if (response_required) { 452f8829a4aSRandall Stewart m_reply = sctp_asconf_success_response(aph->correlation_id); 453f8829a4aSRandall Stewart } 454f8829a4aSRandall Stewart /* notify upper layer */ 455ceaad40aSRandall Stewart sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0, sa, SCTP_SO_NOT_LOCKED); 456f8829a4aSRandall Stewart } 457f8829a4aSRandall Stewart return m_reply; 458f8829a4aSRandall Stewart } 459f8829a4aSRandall Stewart 460f8829a4aSRandall Stewart static struct mbuf * 461f8829a4aSRandall Stewart sctp_process_asconf_set_primary(struct mbuf *m, 4621b649582SRandall Stewart struct sctp_asconf_paramhdr *aph, 4631b649582SRandall Stewart struct sctp_tcb *stcb, int response_required) 464f8829a4aSRandall Stewart { 465f8829a4aSRandall Stewart struct mbuf *m_reply = NULL; 466f8829a4aSRandall Stewart struct sockaddr_storage sa_source, sa_store; 467f8829a4aSRandall Stewart struct sctp_ipv4addr_param *v4addr; 468f8829a4aSRandall Stewart uint16_t param_type, param_length, aparam_length; 469f8829a4aSRandall Stewart struct sockaddr *sa; 470f8829a4aSRandall Stewart struct sockaddr_in *sin; 471f8829a4aSRandall Stewart int zero_address = 0; 472f8829a4aSRandall Stewart 473f8829a4aSRandall Stewart #ifdef INET6 474f8829a4aSRandall Stewart struct sockaddr_in6 *sin6; 475f8829a4aSRandall Stewart struct sctp_ipv6addr_param *v6addr; 476f8829a4aSRandall Stewart 477f8829a4aSRandall Stewart #endif /* INET6 */ 478f8829a4aSRandall Stewart 479f8829a4aSRandall Stewart aparam_length = ntohs(aph->ph.param_length); 480f8829a4aSRandall Stewart v4addr = (struct sctp_ipv4addr_param *)(aph + 1); 481f8829a4aSRandall Stewart #ifdef INET6 482f8829a4aSRandall Stewart v6addr = (struct sctp_ipv6addr_param *)(aph + 1); 483f8829a4aSRandall Stewart #endif /* INET6 */ 484f8829a4aSRandall Stewart param_type = ntohs(v4addr->ph.param_type); 485f8829a4aSRandall Stewart param_length = ntohs(v4addr->ph.param_length); 486f8829a4aSRandall Stewart 487f8829a4aSRandall Stewart sa = (struct sockaddr *)&sa_store; 488f8829a4aSRandall Stewart switch (param_type) { 489f8829a4aSRandall Stewart case SCTP_IPV4_ADDRESS: 490f8829a4aSRandall Stewart if (param_length != sizeof(struct sctp_ipv4addr_param)) { 491f8829a4aSRandall Stewart /* invalid param size */ 492f8829a4aSRandall Stewart return NULL; 493f8829a4aSRandall Stewart } 494f8829a4aSRandall Stewart sin = (struct sockaddr_in *)&sa_store; 495f8829a4aSRandall Stewart bzero(sin, sizeof(*sin)); 496f8829a4aSRandall Stewart sin->sin_family = AF_INET; 497f8829a4aSRandall Stewart sin->sin_len = sizeof(struct sockaddr_in); 498f8829a4aSRandall Stewart sin->sin_addr.s_addr = v4addr->addr; 499f8829a4aSRandall Stewart if (sin->sin_addr.s_addr == INADDR_ANY) 500f8829a4aSRandall Stewart zero_address = 1; 501ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_set_primary: "); 502ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 503f8829a4aSRandall Stewart break; 504f8829a4aSRandall Stewart case SCTP_IPV6_ADDRESS: 505f8829a4aSRandall Stewart if (param_length != sizeof(struct sctp_ipv6addr_param)) { 506f8829a4aSRandall Stewart /* invalid param size */ 507f8829a4aSRandall Stewart return NULL; 508f8829a4aSRandall Stewart } 509f8829a4aSRandall Stewart #ifdef INET6 510f8829a4aSRandall Stewart sin6 = (struct sockaddr_in6 *)&sa_store; 511f8829a4aSRandall Stewart bzero(sin6, sizeof(*sin6)); 512f8829a4aSRandall Stewart sin6->sin6_family = AF_INET6; 513f8829a4aSRandall Stewart sin6->sin6_len = sizeof(struct sockaddr_in6); 514f8829a4aSRandall Stewart memcpy((caddr_t)&sin6->sin6_addr, v6addr->addr, 515f8829a4aSRandall Stewart sizeof(struct in6_addr)); 516f8829a4aSRandall Stewart if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) 517f8829a4aSRandall Stewart zero_address = 1; 518ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_set_primary: "); 519ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 520f8829a4aSRandall Stewart #else 521f8829a4aSRandall Stewart /* IPv6 not enabled! No "action" needed; just ack it */ 522ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 523ad81507eSRandall Stewart "process_asconf_set_primary: v6 disabled- ignoring: "); 524ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 525f8829a4aSRandall Stewart /* just respond with a "success" ASCONF-ACK */ 526f8829a4aSRandall Stewart return NULL; 527ad81507eSRandall Stewart #endif 528f8829a4aSRandall Stewart break; 529f8829a4aSRandall Stewart default: 530f8829a4aSRandall Stewart m_reply = sctp_asconf_error_response(aph->correlation_id, 531f8829a4aSRandall Stewart SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph, 532f8829a4aSRandall Stewart aparam_length); 533f8829a4aSRandall Stewart return m_reply; 534f8829a4aSRandall Stewart } 535f8829a4aSRandall Stewart 536f8829a4aSRandall Stewart /* if 0.0.0.0/::0, use the source address instead */ 537b3f1ea41SRandall Stewart if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) { 538f8829a4aSRandall Stewart sa = (struct sockaddr *)&sa_source; 539f8829a4aSRandall Stewart sctp_asconf_get_source_ip(m, sa); 540ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 541ad81507eSRandall Stewart "process_asconf_set_primary: using source addr "); 542ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 543f8829a4aSRandall Stewart } 544f8829a4aSRandall Stewart /* set the primary address */ 545f8829a4aSRandall Stewart if (sctp_set_primary_addr(stcb, sa, NULL) == 0) { 546ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 547ad81507eSRandall Stewart "process_asconf_set_primary: primary address set\n"); 548f8829a4aSRandall Stewart /* notify upper layer */ 549ceaad40aSRandall Stewart sctp_ulp_notify(SCTP_NOTIFY_ASCONF_SET_PRIMARY, stcb, 0, sa, SCTP_SO_NOT_LOCKED); 550f8829a4aSRandall Stewart 551f8829a4aSRandall Stewart if (response_required) { 552f8829a4aSRandall Stewart m_reply = sctp_asconf_success_response(aph->correlation_id); 553f8829a4aSRandall Stewart } 554851b7298SRandall Stewart /* 555851b7298SRandall Stewart * Mobility adaptation. Ideally, when the reception of SET 556851b7298SRandall Stewart * PRIMARY with DELETE IP ADDRESS of the previous primary 557851b7298SRandall Stewart * destination, unacknowledged DATA are retransmitted 558851b7298SRandall Stewart * immediately to the new primary destination for seamless 559b5c16493SMichael Tuexen * handover. If the destination is UNCONFIRMED and marked to 560b5c16493SMichael Tuexen * REQ_PRIM, The retransmission occur when reception of the 561b5c16493SMichael Tuexen * HEARTBEAT-ACK. (See sctp_handle_heartbeat_ack in 562851b7298SRandall Stewart * sctp_input.c) Also, when change of the primary 563851b7298SRandall Stewart * destination, it is better that all subsequent new DATA 564851b7298SRandall Stewart * containing already queued DATA are transmitted to the new 565851b7298SRandall Stewart * primary destination. (by micchie) 566851b7298SRandall Stewart */ 567851b7298SRandall Stewart if ((sctp_is_mobility_feature_on(stcb->sctp_ep, 568851b7298SRandall Stewart SCTP_MOBILITY_BASE) || 569851b7298SRandall Stewart sctp_is_mobility_feature_on(stcb->sctp_ep, 570851b7298SRandall Stewart SCTP_MOBILITY_FASTHANDOFF)) && 571851b7298SRandall Stewart sctp_is_mobility_feature_on(stcb->sctp_ep, 572851b7298SRandall Stewart SCTP_MOBILITY_PRIM_DELETED) && 573851b7298SRandall Stewart (stcb->asoc.primary_destination->dest_state & 574851b7298SRandall Stewart SCTP_ADDR_UNCONFIRMED) == 0) { 575851b7298SRandall Stewart 576851b7298SRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_PRIM_DELETED, stcb->sctp_ep, stcb, NULL, SCTP_FROM_SCTP_TIMER + SCTP_LOC_7); 577851b7298SRandall Stewart if (sctp_is_mobility_feature_on(stcb->sctp_ep, 578851b7298SRandall Stewart SCTP_MOBILITY_FASTHANDOFF)) { 579851b7298SRandall Stewart sctp_assoc_immediate_retrans(stcb, 580851b7298SRandall Stewart stcb->asoc.primary_destination); 581851b7298SRandall Stewart } 582851b7298SRandall Stewart if (sctp_is_mobility_feature_on(stcb->sctp_ep, 583851b7298SRandall Stewart SCTP_MOBILITY_BASE)) { 584851b7298SRandall Stewart sctp_move_chunks_from_deleted_prim(stcb, 585851b7298SRandall Stewart stcb->asoc.primary_destination); 586851b7298SRandall Stewart } 587851b7298SRandall Stewart sctp_delete_prim_timer(stcb->sctp_ep, stcb, 588851b7298SRandall Stewart stcb->asoc.deleted_primary); 589851b7298SRandall Stewart } 590f8829a4aSRandall Stewart } else { 591f8829a4aSRandall Stewart /* couldn't set the requested primary address! */ 592ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 593ad81507eSRandall Stewart "process_asconf_set_primary: set primary failed!\n"); 594f8829a4aSRandall Stewart /* must have been an invalid address, so report */ 595f8829a4aSRandall Stewart m_reply = sctp_asconf_error_response(aph->correlation_id, 596f8829a4aSRandall Stewart SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph, 597f8829a4aSRandall Stewart aparam_length); 598f8829a4aSRandall Stewart } 599f8829a4aSRandall Stewart 600f8829a4aSRandall Stewart return m_reply; 601f8829a4aSRandall Stewart } 602f8829a4aSRandall Stewart 603f8829a4aSRandall Stewart /* 604f8829a4aSRandall Stewart * handles an ASCONF chunk. 605f8829a4aSRandall Stewart * if all parameters are processed ok, send a plain (empty) ASCONF-ACK 606f8829a4aSRandall Stewart */ 607f8829a4aSRandall Stewart void 608f8829a4aSRandall Stewart sctp_handle_asconf(struct mbuf *m, unsigned int offset, 6092afb3e84SRandall Stewart struct sctp_asconf_chunk *cp, struct sctp_tcb *stcb, 6102afb3e84SRandall Stewart int first) 611f8829a4aSRandall Stewart { 612f8829a4aSRandall Stewart struct sctp_association *asoc; 613f8829a4aSRandall Stewart uint32_t serial_num; 6142afb3e84SRandall Stewart struct mbuf *n, *m_ack, *m_result, *m_tail; 615f8829a4aSRandall Stewart struct sctp_asconf_ack_chunk *ack_cp; 616f8829a4aSRandall Stewart struct sctp_asconf_paramhdr *aph, *ack_aph; 617f8829a4aSRandall Stewart struct sctp_ipv6addr_param *p_addr; 618f8829a4aSRandall Stewart unsigned int asconf_limit; 619f8829a4aSRandall Stewart int error = 0; /* did an error occur? */ 620f8829a4aSRandall Stewart 621f8829a4aSRandall Stewart /* asconf param buffer */ 622f42a358aSRandall Stewart uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE]; 6232afb3e84SRandall Stewart struct sctp_asconf_ack *ack, *ack_next; 624f8829a4aSRandall Stewart 625f8829a4aSRandall Stewart /* verify minimum length */ 626f8829a4aSRandall Stewart if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_chunk)) { 627ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 628ad81507eSRandall Stewart "handle_asconf: chunk too small = %xh\n", 629f8829a4aSRandall Stewart ntohs(cp->ch.chunk_length)); 630f8829a4aSRandall Stewart return; 631f8829a4aSRandall Stewart } 632f8829a4aSRandall Stewart asoc = &stcb->asoc; 633f8829a4aSRandall Stewart serial_num = ntohl(cp->serial_number); 634f8829a4aSRandall Stewart 6352afb3e84SRandall Stewart if (compare_with_wrap(asoc->asconf_seq_in, serial_num, MAX_SEQ) || 6362afb3e84SRandall Stewart serial_num == asoc->asconf_seq_in) { 637f8829a4aSRandall Stewart /* got a duplicate ASCONF */ 638ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 639ad81507eSRandall Stewart "handle_asconf: got duplicate serial number = %xh\n", 640f8829a4aSRandall Stewart serial_num); 641f8829a4aSRandall Stewart return; 642f8829a4aSRandall Stewart } else if (serial_num != (asoc->asconf_seq_in + 1)) { 643ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: incorrect serial number = %xh (expected next = %xh)\n", 644f8829a4aSRandall Stewart serial_num, asoc->asconf_seq_in + 1); 645f8829a4aSRandall Stewart return; 646f8829a4aSRandall Stewart } 647f8829a4aSRandall Stewart /* it's the expected "next" sequence number, so process it */ 648f8829a4aSRandall Stewart asoc->asconf_seq_in = serial_num; /* update sequence */ 649f8829a4aSRandall Stewart /* get length of all the param's in the ASCONF */ 650f8829a4aSRandall Stewart asconf_limit = offset + ntohs(cp->ch.chunk_length); 651ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 652ad81507eSRandall Stewart "handle_asconf: asconf_limit=%u, sequence=%xh\n", 653f8829a4aSRandall Stewart asconf_limit, serial_num); 6542afb3e84SRandall Stewart 6552afb3e84SRandall Stewart if (first) { 6562afb3e84SRandall Stewart /* delete old cache */ 6572afb3e84SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: Now processing firstASCONF. Try to delte old cache\n"); 6582afb3e84SRandall Stewart 6592afb3e84SRandall Stewart ack = TAILQ_FIRST(&stcb->asoc.asconf_ack_sent); 6602afb3e84SRandall Stewart while (ack != NULL) { 6612afb3e84SRandall Stewart ack_next = TAILQ_NEXT(ack, next); 6622afb3e84SRandall Stewart if (ack->serial_number == serial_num) 6632afb3e84SRandall Stewart break; 6642afb3e84SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: delete old(%u) < first(%u)\n", 6652afb3e84SRandall Stewart ack->serial_number, serial_num); 6662afb3e84SRandall Stewart TAILQ_REMOVE(&stcb->asoc.asconf_ack_sent, ack, next); 6672afb3e84SRandall Stewart if (ack->data != NULL) { 6682afb3e84SRandall Stewart sctp_m_freem(ack->data); 6692afb3e84SRandall Stewart } 670b3f1ea41SRandall Stewart SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_asconf_ack), ack); 6712afb3e84SRandall Stewart ack = ack_next; 6722afb3e84SRandall Stewart } 673f8829a4aSRandall Stewart } 674139bc87fSRandall Stewart m_ack = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_ack_chunk), 0, 675f8829a4aSRandall Stewart M_DONTWAIT, 1, MT_DATA); 676f8829a4aSRandall Stewart if (m_ack == NULL) { 677ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 678ad81507eSRandall Stewart "handle_asconf: couldn't get mbuf!\n"); 679f8829a4aSRandall Stewart return; 680f8829a4aSRandall Stewart } 681f8829a4aSRandall Stewart m_tail = m_ack; /* current reply chain's tail */ 682f8829a4aSRandall Stewart 683f8829a4aSRandall Stewart /* fill in ASCONF-ACK header */ 684f8829a4aSRandall Stewart ack_cp = mtod(m_ack, struct sctp_asconf_ack_chunk *); 685f8829a4aSRandall Stewart ack_cp->ch.chunk_type = SCTP_ASCONF_ACK; 686f8829a4aSRandall Stewart ack_cp->ch.chunk_flags = 0; 687f8829a4aSRandall Stewart ack_cp->serial_number = htonl(serial_num); 688f8829a4aSRandall Stewart /* set initial lengths (eg. just an ASCONF-ACK), ntohx at the end! */ 689139bc87fSRandall Stewart SCTP_BUF_LEN(m_ack) = sizeof(struct sctp_asconf_ack_chunk); 690f8829a4aSRandall Stewart ack_cp->ch.chunk_length = sizeof(struct sctp_asconf_ack_chunk); 691f8829a4aSRandall Stewart 692f8829a4aSRandall Stewart /* skip the lookup address parameter */ 693f8829a4aSRandall Stewart offset += sizeof(struct sctp_asconf_chunk); 694f8829a4aSRandall Stewart p_addr = (struct sctp_ipv6addr_param *)sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), (uint8_t *) & aparam_buf); 695f8829a4aSRandall Stewart if (p_addr == NULL) { 696ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 697ad81507eSRandall Stewart "handle_asconf: couldn't get lookup addr!\n"); 698f8829a4aSRandall Stewart /* respond with a missing/invalid mandatory parameter error */ 699f8829a4aSRandall Stewart return; 700f8829a4aSRandall Stewart } 701f8829a4aSRandall Stewart /* param_length is already validated in process_control... */ 702f8829a4aSRandall Stewart offset += ntohs(p_addr->ph.param_length); /* skip lookup addr */ 703f8829a4aSRandall Stewart 704f8829a4aSRandall Stewart /* get pointer to first asconf param in ASCONF-ACK */ 705f8829a4aSRandall Stewart ack_aph = (struct sctp_asconf_paramhdr *)(mtod(m_ack, caddr_t)+sizeof(struct sctp_asconf_ack_chunk)); 706f8829a4aSRandall Stewart if (ack_aph == NULL) { 707ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "Gak in asconf2\n"); 708f8829a4aSRandall Stewart return; 709f8829a4aSRandall Stewart } 710f8829a4aSRandall Stewart /* get pointer to first asconf param in ASCONF */ 711f8829a4aSRandall Stewart aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, sizeof(struct sctp_asconf_paramhdr), (uint8_t *) & aparam_buf); 712f8829a4aSRandall Stewart if (aph == NULL) { 713ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "Empty ASCONF received?\n"); 714f8829a4aSRandall Stewart goto send_reply; 715f8829a4aSRandall Stewart } 716f8829a4aSRandall Stewart /* process through all parameters */ 717f8829a4aSRandall Stewart while (aph != NULL) { 718f8829a4aSRandall Stewart unsigned int param_length, param_type; 719f8829a4aSRandall Stewart 720f8829a4aSRandall Stewart param_type = ntohs(aph->ph.param_type); 721f8829a4aSRandall Stewart param_length = ntohs(aph->ph.param_length); 722f8829a4aSRandall Stewart if (offset + param_length > asconf_limit) { 723f8829a4aSRandall Stewart /* parameter goes beyond end of chunk! */ 724f8829a4aSRandall Stewart sctp_m_freem(m_ack); 725f8829a4aSRandall Stewart return; 726f8829a4aSRandall Stewart } 727f8829a4aSRandall Stewart m_result = NULL; 728f8829a4aSRandall Stewart 729f8829a4aSRandall Stewart if (param_length > sizeof(aparam_buf)) { 730ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) larger than buffer size!\n", param_length); 731f8829a4aSRandall Stewart sctp_m_freem(m_ack); 732f8829a4aSRandall Stewart return; 733f8829a4aSRandall Stewart } 734f8829a4aSRandall Stewart if (param_length <= sizeof(struct sctp_paramhdr)) { 735ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) too short\n", param_length); 736f8829a4aSRandall Stewart sctp_m_freem(m_ack); 737f8829a4aSRandall Stewart } 738f8829a4aSRandall Stewart /* get the entire parameter */ 739f8829a4aSRandall Stewart aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf); 740f8829a4aSRandall Stewart if (aph == NULL) { 741ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: couldn't get entire param\n"); 742f8829a4aSRandall Stewart sctp_m_freem(m_ack); 743f8829a4aSRandall Stewart return; 744f8829a4aSRandall Stewart } 745f8829a4aSRandall Stewart switch (param_type) { 746f8829a4aSRandall Stewart case SCTP_ADD_IP_ADDRESS: 747f8829a4aSRandall Stewart asoc->peer_supports_asconf = 1; 748f8829a4aSRandall Stewart m_result = sctp_process_asconf_add_ip(m, aph, stcb, 749f8829a4aSRandall Stewart error); 750f8829a4aSRandall Stewart break; 751f8829a4aSRandall Stewart case SCTP_DEL_IP_ADDRESS: 752f8829a4aSRandall Stewart asoc->peer_supports_asconf = 1; 753f8829a4aSRandall Stewart m_result = sctp_process_asconf_delete_ip(m, aph, stcb, 754f8829a4aSRandall Stewart error); 755f8829a4aSRandall Stewart break; 756f8829a4aSRandall Stewart case SCTP_ERROR_CAUSE_IND: 757f8829a4aSRandall Stewart /* not valid in an ASCONF chunk */ 758f8829a4aSRandall Stewart break; 759f8829a4aSRandall Stewart case SCTP_SET_PRIM_ADDR: 760f8829a4aSRandall Stewart asoc->peer_supports_asconf = 1; 761f8829a4aSRandall Stewart m_result = sctp_process_asconf_set_primary(m, aph, 762f8829a4aSRandall Stewart stcb, error); 763f8829a4aSRandall Stewart break; 764830d754dSRandall Stewart case SCTP_NAT_VTAGS: 765830d754dSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: sees a NAT VTAG state parameter\n"); 766830d754dSRandall Stewart break; 767f8829a4aSRandall Stewart case SCTP_SUCCESS_REPORT: 768f8829a4aSRandall Stewart /* not valid in an ASCONF chunk */ 769f8829a4aSRandall Stewart break; 770f8829a4aSRandall Stewart case SCTP_ULP_ADAPTATION: 771f8829a4aSRandall Stewart /* FIX */ 772f8829a4aSRandall Stewart break; 773f8829a4aSRandall Stewart default: 774f8829a4aSRandall Stewart if ((param_type & 0x8000) == 0) { 775f8829a4aSRandall Stewart /* Been told to STOP at this param */ 776f8829a4aSRandall Stewart asconf_limit = offset; 777f8829a4aSRandall Stewart /* 778f8829a4aSRandall Stewart * FIX FIX - We need to call 779f8829a4aSRandall Stewart * sctp_arethere_unrecognized_parameters() 780f8829a4aSRandall Stewart * to get a operr and send it for any 781f8829a4aSRandall Stewart * param's with the 0x4000 bit set OR do it 782f8829a4aSRandall Stewart * here ourselves... note we still must STOP 783f8829a4aSRandall Stewart * if the 0x8000 bit is clear. 784f8829a4aSRandall Stewart */ 785f8829a4aSRandall Stewart } 786f8829a4aSRandall Stewart /* unknown/invalid param type */ 787f8829a4aSRandall Stewart break; 788f8829a4aSRandall Stewart } /* switch */ 789f8829a4aSRandall Stewart 790f8829a4aSRandall Stewart /* add any (error) result to the reply mbuf chain */ 791f8829a4aSRandall Stewart if (m_result != NULL) { 792139bc87fSRandall Stewart SCTP_BUF_NEXT(m_tail) = m_result; 793f8829a4aSRandall Stewart m_tail = m_result; 794f8829a4aSRandall Stewart /* update lengths, make sure it's aligned too */ 795139bc87fSRandall Stewart SCTP_BUF_LEN(m_result) = SCTP_SIZE32(SCTP_BUF_LEN(m_result)); 796139bc87fSRandall Stewart ack_cp->ch.chunk_length += SCTP_BUF_LEN(m_result); 797f8829a4aSRandall Stewart /* set flag to force success reports */ 798f8829a4aSRandall Stewart error = 1; 799f8829a4aSRandall Stewart } 800f8829a4aSRandall Stewart offset += SCTP_SIZE32(param_length); 801f8829a4aSRandall Stewart /* update remaining ASCONF message length to process */ 802f8829a4aSRandall Stewart if (offset >= asconf_limit) { 803f8829a4aSRandall Stewart /* no more data in the mbuf chain */ 804f8829a4aSRandall Stewart break; 805f8829a4aSRandall Stewart } 806f8829a4aSRandall Stewart /* get pointer to next asconf param */ 807f8829a4aSRandall Stewart aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, 808f8829a4aSRandall Stewart sizeof(struct sctp_asconf_paramhdr), 809f8829a4aSRandall Stewart (uint8_t *) & aparam_buf); 810f8829a4aSRandall Stewart if (aph == NULL) { 811f8829a4aSRandall Stewart /* can't get an asconf paramhdr */ 812ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: can't get asconf param hdr!\n"); 813f8829a4aSRandall Stewart /* FIX ME - add error here... */ 814f8829a4aSRandall Stewart } 815ad81507eSRandall Stewart } 816f8829a4aSRandall Stewart 817f8829a4aSRandall Stewart send_reply: 818f8829a4aSRandall Stewart ack_cp->ch.chunk_length = htons(ack_cp->ch.chunk_length); 819f8829a4aSRandall Stewart /* save the ASCONF-ACK reply */ 820b3f1ea41SRandall Stewart ack = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_asconf_ack), 8212afb3e84SRandall Stewart struct sctp_asconf_ack); 8222afb3e84SRandall Stewart if (ack == NULL) { 8232afb3e84SRandall Stewart sctp_m_freem(m_ack); 8242afb3e84SRandall Stewart return; 8252afb3e84SRandall Stewart } 8262afb3e84SRandall Stewart ack->serial_number = serial_num; 8272afb3e84SRandall Stewart ack->last_sent_to = NULL; 8282afb3e84SRandall Stewart ack->data = m_ack; 829*fc066a61SMichael Tuexen ack->len = 0; 8302afb3e84SRandall Stewart n = m_ack; 8312afb3e84SRandall Stewart while (n) { 8322afb3e84SRandall Stewart ack->len += SCTP_BUF_LEN(n); 8332afb3e84SRandall Stewart n = SCTP_BUF_NEXT(n); 8342afb3e84SRandall Stewart } 8352afb3e84SRandall Stewart TAILQ_INSERT_TAIL(&stcb->asoc.asconf_ack_sent, ack, next); 836f8829a4aSRandall Stewart 837f8829a4aSRandall Stewart /* see if last_control_chunk_from is set properly (use IP src addr) */ 838f8829a4aSRandall Stewart if (stcb->asoc.last_control_chunk_from == NULL) { 839f8829a4aSRandall Stewart /* 840f8829a4aSRandall Stewart * this could happen if the source address was just newly 841f8829a4aSRandall Stewart * added 842f8829a4aSRandall Stewart */ 843f8829a4aSRandall Stewart struct ip *iph; 844f8829a4aSRandall Stewart struct sctphdr *sh; 845f8829a4aSRandall Stewart struct sockaddr_storage from_store; 846f8829a4aSRandall Stewart struct sockaddr *from = (struct sockaddr *)&from_store; 847f8829a4aSRandall Stewart 848ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: looking up net for IP source address\n"); 849f8829a4aSRandall Stewart /* pullup already done, IP options already stripped */ 850f8829a4aSRandall Stewart iph = mtod(m, struct ip *); 851f8829a4aSRandall Stewart sh = (struct sctphdr *)((caddr_t)iph + sizeof(*iph)); 8525e2c2d87SRandall Stewart switch (iph->ip_v) { 8535e2c2d87SRandall Stewart case IPVERSION: 8545e2c2d87SRandall Stewart { 855f8829a4aSRandall Stewart struct sockaddr_in *from4; 856f8829a4aSRandall Stewart 857f8829a4aSRandall Stewart from4 = (struct sockaddr_in *)&from_store; 858f8829a4aSRandall Stewart bzero(from4, sizeof(*from4)); 859f8829a4aSRandall Stewart from4->sin_family = AF_INET; 860f8829a4aSRandall Stewart from4->sin_len = sizeof(struct sockaddr_in); 861f8829a4aSRandall Stewart from4->sin_addr.s_addr = iph->ip_src.s_addr; 862f8829a4aSRandall Stewart from4->sin_port = sh->src_port; 8635e2c2d87SRandall Stewart break; 8645e2c2d87SRandall Stewart } 8655e2c2d87SRandall Stewart #ifdef INET6 8665e2c2d87SRandall Stewart case IPV6_VERSION >> 4: 8675e2c2d87SRandall Stewart { 868f8829a4aSRandall Stewart struct ip6_hdr *ip6; 869f8829a4aSRandall Stewart struct sockaddr_in6 *from6; 870f8829a4aSRandall Stewart 871f8829a4aSRandall Stewart ip6 = mtod(m, struct ip6_hdr *); 872f8829a4aSRandall Stewart from6 = (struct sockaddr_in6 *)&from_store; 873f8829a4aSRandall Stewart bzero(from6, sizeof(*from6)); 874f8829a4aSRandall Stewart from6->sin6_family = AF_INET6; 875f8829a4aSRandall Stewart from6->sin6_len = sizeof(struct sockaddr_in6); 876f8829a4aSRandall Stewart from6->sin6_addr = ip6->ip6_src; 877f8829a4aSRandall Stewart from6->sin6_port = sh->src_port; 8785e2c2d87SRandall Stewart /* 8795e2c2d87SRandall Stewart * Get the scopes in properly to the sin6 8805e2c2d87SRandall Stewart * addr's 8815e2c2d87SRandall Stewart */ 882f8829a4aSRandall Stewart /* we probably don't need these operations */ 883f8829a4aSRandall Stewart (void)sa6_recoverscope(from6); 884fc14de76SRandall Stewart sa6_embedscope(from6, 885482444b4SRandall Stewart MODULE_GLOBAL(ip6_use_defzone)); 886fc14de76SRandall Stewart 8875e2c2d87SRandall Stewart break; 8885e2c2d87SRandall Stewart } 8895e2c2d87SRandall Stewart #endif 8905e2c2d87SRandall Stewart default: 891f8829a4aSRandall Stewart /* unknown address type */ 892f8829a4aSRandall Stewart from = NULL; 893f8829a4aSRandall Stewart } 894f8829a4aSRandall Stewart if (from != NULL) { 895ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "Looking for IP source: "); 896ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, from); 897f8829a4aSRandall Stewart /* look up the from address */ 898f8829a4aSRandall Stewart stcb->asoc.last_control_chunk_from = sctp_findnet(stcb, from); 899f8829a4aSRandall Stewart #ifdef SCTP_DEBUG 900ad81507eSRandall Stewart if (stcb->asoc.last_control_chunk_from == NULL) 901ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: IP source address not found?!\n"); 902ad81507eSRandall Stewart #endif 903f8829a4aSRandall Stewart } 904f8829a4aSRandall Stewart } 905f8829a4aSRandall Stewart } 906f8829a4aSRandall Stewart 907f8829a4aSRandall Stewart /* 908f8829a4aSRandall Stewart * does the address match? returns 0 if not, 1 if so 909f8829a4aSRandall Stewart */ 910f8829a4aSRandall Stewart static uint32_t 911f8829a4aSRandall Stewart sctp_asconf_addr_match(struct sctp_asconf_addr *aa, struct sockaddr *sa) 912f8829a4aSRandall Stewart { 913f8829a4aSRandall Stewart #ifdef INET6 914f8829a4aSRandall Stewart if (sa->sa_family == AF_INET6) { 915f8829a4aSRandall Stewart /* IPv6 sa address */ 916f8829a4aSRandall Stewart /* XXX scopeid */ 917f8829a4aSRandall Stewart struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa; 918f8829a4aSRandall Stewart 919f8829a4aSRandall Stewart if ((aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) && 920f8829a4aSRandall Stewart (memcmp(&aa->ap.addrp.addr, &sin6->sin6_addr, 921f8829a4aSRandall Stewart sizeof(struct in6_addr)) == 0)) { 922f8829a4aSRandall Stewart return (1); 923f8829a4aSRandall Stewart } 924f8829a4aSRandall Stewart } else 925f8829a4aSRandall Stewart #endif /* INET6 */ 926f8829a4aSRandall Stewart if (sa->sa_family == AF_INET) { 927f8829a4aSRandall Stewart /* IPv4 sa address */ 928f8829a4aSRandall Stewart struct sockaddr_in *sin = (struct sockaddr_in *)sa; 929f8829a4aSRandall Stewart 930f8829a4aSRandall Stewart if ((aa->ap.addrp.ph.param_type == SCTP_IPV4_ADDRESS) && 931f8829a4aSRandall Stewart (memcmp(&aa->ap.addrp.addr, &sin->sin_addr, 932f8829a4aSRandall Stewart sizeof(struct in_addr)) == 0)) { 933f8829a4aSRandall Stewart return (1); 934f8829a4aSRandall Stewart } 935f8829a4aSRandall Stewart } 936f8829a4aSRandall Stewart return (0); 937f8829a4aSRandall Stewart } 938f8829a4aSRandall Stewart 939f8829a4aSRandall Stewart /* 940c54a18d2SRandall Stewart * does the address match? returns 0 if not, 1 if so 941c54a18d2SRandall Stewart */ 942c54a18d2SRandall Stewart static uint32_t 943c54a18d2SRandall Stewart sctp_addr_match( 944c54a18d2SRandall Stewart struct sctp_ipv6addr_param *v6addr, 945c54a18d2SRandall Stewart struct sockaddr *sa) 946c54a18d2SRandall Stewart { 947c54a18d2SRandall Stewart uint16_t param_type, param_length; 948c54a18d2SRandall Stewart struct sctp_ipv4addr_param *v4addr = (struct sctp_ipv4addr_param *)v6addr; 949c54a18d2SRandall Stewart 950d6af161aSRandall Stewart #ifdef INET6 951c54a18d2SRandall Stewart if (sa->sa_family == AF_INET6) { 952c54a18d2SRandall Stewart /* IPv6 sa address */ 953c54a18d2SRandall Stewart /* XXX scopeid */ 954c54a18d2SRandall Stewart struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa; 955c54a18d2SRandall Stewart 956c54a18d2SRandall Stewart param_type = ntohs(v6addr->ph.param_type); 957c54a18d2SRandall Stewart param_length = ntohs(v6addr->ph.param_length); 958c54a18d2SRandall Stewart 959c54a18d2SRandall Stewart if ((param_type == SCTP_IPV6_ADDRESS) && 960c54a18d2SRandall Stewart param_length == sizeof(struct sctp_ipv6addr_param) && 961c54a18d2SRandall Stewart (memcmp(&v6addr->addr, &sin6->sin6_addr, 962c54a18d2SRandall Stewart sizeof(struct in6_addr)) == 0)) { 963c54a18d2SRandall Stewart return (1); 964c54a18d2SRandall Stewart } 965d6af161aSRandall Stewart } 966d6af161aSRandall Stewart #endif 967c54a18d2SRandall Stewart if (sa->sa_family == AF_INET) { 968c54a18d2SRandall Stewart /* IPv4 sa address */ 969c54a18d2SRandall Stewart struct sockaddr_in *sin = (struct sockaddr_in *)sa; 970c54a18d2SRandall Stewart 971c54a18d2SRandall Stewart param_type = ntohs(v4addr->ph.param_type); 972c54a18d2SRandall Stewart param_length = ntohs(v4addr->ph.param_length); 973c54a18d2SRandall Stewart 974c54a18d2SRandall Stewart if ((param_type == SCTP_IPV4_ADDRESS) && 975c54a18d2SRandall Stewart param_length == sizeof(struct sctp_ipv4addr_param) && 976c54a18d2SRandall Stewart (memcmp(&v4addr->addr, &sin->sin_addr, 977c54a18d2SRandall Stewart sizeof(struct in_addr)) == 0)) { 978c54a18d2SRandall Stewart return (1); 979c54a18d2SRandall Stewart } 980c54a18d2SRandall Stewart } 981c54a18d2SRandall Stewart return (0); 982c54a18d2SRandall Stewart } 983c54a18d2SRandall Stewart 984c54a18d2SRandall Stewart /* 985f8829a4aSRandall Stewart * Cleanup for non-responded/OP ERR'd ASCONF 986f8829a4aSRandall Stewart */ 987f8829a4aSRandall Stewart void 988f8829a4aSRandall Stewart sctp_asconf_cleanup(struct sctp_tcb *stcb, struct sctp_nets *net) 989f8829a4aSRandall Stewart { 990f8829a4aSRandall Stewart /* mark peer as ASCONF incapable */ 991f8829a4aSRandall Stewart stcb->asoc.peer_supports_asconf = 0; 992f8829a4aSRandall Stewart /* 993f8829a4aSRandall Stewart * clear out any existing asconfs going out 994f8829a4aSRandall Stewart */ 9953c503c28SRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, net, 9963c503c28SRandall Stewart SCTP_FROM_SCTP_ASCONF + SCTP_LOC_2); 997c54a18d2SRandall Stewart stcb->asoc.asconf_seq_out_acked = stcb->asoc.asconf_seq_out; 998f8829a4aSRandall Stewart /* remove the old ASCONF on our outbound queue */ 999f8829a4aSRandall Stewart sctp_toss_old_asconf(stcb); 1000f8829a4aSRandall Stewart } 1001f8829a4aSRandall Stewart 1002f8829a4aSRandall Stewart /* 10032dad8a55SRandall Stewart * cleanup any cached source addresses that may be topologically 10042dad8a55SRandall Stewart * incorrect after a new address has been added to this interface. 10052dad8a55SRandall Stewart */ 10062dad8a55SRandall Stewart static void 10072dad8a55SRandall Stewart sctp_asconf_nets_cleanup(struct sctp_tcb *stcb, struct sctp_ifn *ifn) 10082dad8a55SRandall Stewart { 10092dad8a55SRandall Stewart struct sctp_nets *net; 10102dad8a55SRandall Stewart 10112dad8a55SRandall Stewart /* 10122dad8a55SRandall Stewart * Ideally, we want to only clear cached routes and source addresses 10132dad8a55SRandall Stewart * that are topologically incorrect. But since there is no easy way 10142dad8a55SRandall Stewart * to know whether the newly added address on the ifn would cause a 10152dad8a55SRandall Stewart * routing change (i.e. a new egress interface would be chosen) 10162dad8a55SRandall Stewart * without doing a new routing lookup and source address selection, 10172dad8a55SRandall Stewart * we will (for now) just flush any cached route using a different 10182dad8a55SRandall Stewart * ifn (and cached source addrs) and let output re-choose them 10192dad8a55SRandall Stewart * during the next send on that net. 10202dad8a55SRandall Stewart */ 10212dad8a55SRandall Stewart TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 10222dad8a55SRandall Stewart /* 10232dad8a55SRandall Stewart * clear any cached route (and cached source address) if the 10242dad8a55SRandall Stewart * route's interface is NOT the same as the address change. 10252dad8a55SRandall Stewart * If it's the same interface, just clear the cached source 10262dad8a55SRandall Stewart * address. 10272dad8a55SRandall Stewart */ 10282dad8a55SRandall Stewart if (SCTP_ROUTE_HAS_VALID_IFN(&net->ro) && 1029*fc066a61SMichael Tuexen ((ifn == NULL) || 1030*fc066a61SMichael Tuexen (SCTP_GET_IF_INDEX_FROM_ROUTE(&net->ro) != ifn->ifn_index))) { 10312dad8a55SRandall Stewart /* clear any cached route */ 10322dad8a55SRandall Stewart RTFREE(net->ro.ro_rt); 10332dad8a55SRandall Stewart net->ro.ro_rt = NULL; 10342dad8a55SRandall Stewart } 10352dad8a55SRandall Stewart /* clear any cached source address */ 10362dad8a55SRandall Stewart if (net->src_addr_selected) { 10372dad8a55SRandall Stewart sctp_free_ifa(net->ro._s_addr); 10382dad8a55SRandall Stewart net->ro._s_addr = NULL; 10392dad8a55SRandall Stewart net->src_addr_selected = 0; 10402dad8a55SRandall Stewart } 10412dad8a55SRandall Stewart } 10422dad8a55SRandall Stewart } 10432dad8a55SRandall Stewart 1044851b7298SRandall Stewart void 1045851b7298SRandall Stewart sctp_move_chunks_from_deleted_prim(struct sctp_tcb *stcb, struct sctp_nets *dst) 1046851b7298SRandall Stewart { 1047851b7298SRandall Stewart struct sctp_association *asoc; 1048851b7298SRandall Stewart struct sctp_stream_out *outs; 1049851b7298SRandall Stewart struct sctp_tmit_chunk *chk; 1050851b7298SRandall Stewart struct sctp_stream_queue_pending *sp; 1051851b7298SRandall Stewart 1052851b7298SRandall Stewart if (dst->dest_state & SCTP_ADDR_UNCONFIRMED) { 1053851b7298SRandall Stewart return; 1054851b7298SRandall Stewart } 1055851b7298SRandall Stewart if (stcb->asoc.deleted_primary == NULL) { 1056851b7298SRandall Stewart return; 1057851b7298SRandall Stewart } 1058851b7298SRandall Stewart asoc = &stcb->asoc; 1059851b7298SRandall Stewart 1060851b7298SRandall Stewart /* 1061851b7298SRandall Stewart * now through all the streams checking for chunks sent to our bad 1062851b7298SRandall Stewart * network. 1063851b7298SRandall Stewart */ 1064851b7298SRandall Stewart TAILQ_FOREACH(outs, &asoc->out_wheel, next_spoke) { 1065851b7298SRandall Stewart /* now clean up any chunks here */ 1066851b7298SRandall Stewart TAILQ_FOREACH(sp, &outs->outqueue, next) { 1067851b7298SRandall Stewart if (sp->net == asoc->deleted_primary) { 1068851b7298SRandall Stewart sctp_free_remote_addr(sp->net); 1069851b7298SRandall Stewart sp->net = dst; 1070851b7298SRandall Stewart atomic_add_int(&dst->ref_count, 1); 1071851b7298SRandall Stewart } 1072851b7298SRandall Stewart } 1073851b7298SRandall Stewart } 1074851b7298SRandall Stewart /* Now check the pending queue */ 1075851b7298SRandall Stewart TAILQ_FOREACH(chk, &asoc->send_queue, sctp_next) { 1076851b7298SRandall Stewart if (chk->whoTo == asoc->deleted_primary) { 1077851b7298SRandall Stewart sctp_free_remote_addr(chk->whoTo); 1078851b7298SRandall Stewart chk->whoTo = dst; 1079851b7298SRandall Stewart atomic_add_int(&dst->ref_count, 1); 1080851b7298SRandall Stewart } 1081851b7298SRandall Stewart } 1082851b7298SRandall Stewart 1083851b7298SRandall Stewart } 1084851b7298SRandall Stewart 1085851b7298SRandall Stewart 1086851b7298SRandall Stewart void 1087851b7298SRandall Stewart sctp_assoc_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *dstnet) 1088851b7298SRandall Stewart { 1089851b7298SRandall Stewart int error; 1090851b7298SRandall Stewart 1091851b7298SRandall Stewart if (dstnet->dest_state & SCTP_ADDR_UNCONFIRMED) { 1092851b7298SRandall Stewart return; 1093851b7298SRandall Stewart } 1094851b7298SRandall Stewart if (stcb->asoc.deleted_primary == NULL) { 1095851b7298SRandall Stewart return; 1096851b7298SRandall Stewart } 1097851b7298SRandall Stewart if (!TAILQ_EMPTY(&stcb->asoc.sent_queue)) { 1098b27a6b7dSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "assoc_immediate_retrans: Deleted primary is "); 1099851b7298SRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &stcb->asoc.deleted_primary->ro._l_addr.sa); 1100851b7298SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "Current Primary is "); 1101851b7298SRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &stcb->asoc.primary_destination->ro._l_addr.sa); 1102851b7298SRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, 1103851b7298SRandall Stewart stcb->asoc.deleted_primary, 1104851b7298SRandall Stewart SCTP_FROM_SCTP_TIMER + SCTP_LOC_8); 1105851b7298SRandall Stewart stcb->asoc.num_send_timers_up--; 1106851b7298SRandall Stewart if (stcb->asoc.num_send_timers_up < 0) { 1107851b7298SRandall Stewart stcb->asoc.num_send_timers_up = 0; 1108851b7298SRandall Stewart } 1109851b7298SRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 1110851b7298SRandall Stewart error = sctp_t3rxt_timer(stcb->sctp_ep, stcb, 1111851b7298SRandall Stewart stcb->asoc.deleted_primary); 1112851b7298SRandall Stewart if (error) { 1113851b7298SRandall Stewart SCTP_INP_DECR_REF(stcb->sctp_ep); 1114851b7298SRandall Stewart return; 1115851b7298SRandall Stewart } 1116851b7298SRandall Stewart SCTP_TCB_LOCK_ASSERT(stcb); 1117851b7298SRandall Stewart #ifdef SCTP_AUDITING_ENABLED 1118f31e6c7fSMichael Tuexen sctp_auditing(4, stcb->sctp_ep, stcb, stcb->asoc.deleted_primary); 1119851b7298SRandall Stewart #endif 1120851b7298SRandall Stewart sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED); 1121851b7298SRandall Stewart if ((stcb->asoc.num_send_timers_up == 0) && 1122851b7298SRandall Stewart (stcb->asoc.sent_queue_cnt > 0)) { 1123851b7298SRandall Stewart struct sctp_tmit_chunk *chk; 1124851b7298SRandall Stewart 1125851b7298SRandall Stewart chk = TAILQ_FIRST(&stcb->asoc.sent_queue); 1126851b7298SRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, 1127851b7298SRandall Stewart stcb, chk->whoTo); 1128851b7298SRandall Stewart } 1129851b7298SRandall Stewart } 1130851b7298SRandall Stewart return; 1131851b7298SRandall Stewart } 1132851b7298SRandall Stewart 11332afb3e84SRandall Stewart static int 11342afb3e84SRandall Stewart sctp_asconf_queue_mgmt(struct sctp_tcb *, struct sctp_ifa *, uint16_t); 11352afb3e84SRandall Stewart 1136851b7298SRandall Stewart void 11372afb3e84SRandall Stewart sctp_net_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *net) 11382afb3e84SRandall Stewart { 11392afb3e84SRandall Stewart struct sctp_tmit_chunk *chk; 11402afb3e84SRandall Stewart 1141b27a6b7dSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "net_immediate_retrans: RTO is %d\n", net->RTO); 11422afb3e84SRandall Stewart sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, net, 11432afb3e84SRandall Stewart SCTP_FROM_SCTP_TIMER + SCTP_LOC_5); 11442afb3e84SRandall Stewart stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net); 11452afb3e84SRandall Stewart net->error_count = 0; 11462afb3e84SRandall Stewart TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) { 11472afb3e84SRandall Stewart if (chk->whoTo == net) { 1148851b7298SRandall Stewart if (chk->sent < SCTP_DATAGRAM_RESEND) { 11492afb3e84SRandall Stewart chk->sent = SCTP_DATAGRAM_RESEND; 11502afb3e84SRandall Stewart sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt); 1151d55b0b1bSRandall Stewart sctp_flight_size_decrease(chk); 1152d55b0b1bSRandall Stewart sctp_total_flight_decrease(stcb, chk); 1153d55b0b1bSRandall Stewart net->marked_retrans++; 1154d55b0b1bSRandall Stewart stcb->asoc.marked_retrans++; 11552afb3e84SRandall Stewart } 11562afb3e84SRandall Stewart } 11572afb3e84SRandall Stewart } 1158d55b0b1bSRandall Stewart if (net->marked_retrans) { 1159d55b0b1bSRandall Stewart sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED); 1160d55b0b1bSRandall Stewart } 1161851b7298SRandall Stewart } 11622afb3e84SRandall Stewart 11632afb3e84SRandall Stewart static void 11642afb3e84SRandall Stewart sctp_path_check_and_react(struct sctp_tcb *stcb, struct sctp_ifa *newifa) 11652afb3e84SRandall Stewart { 11662afb3e84SRandall Stewart struct sctp_nets *net; 11672afb3e84SRandall Stewart int addrnum, changed; 11682afb3e84SRandall Stewart 11692afb3e84SRandall Stewart /* 11702afb3e84SRandall Stewart * If number of local valid addresses is 1, the valid address is 11712afb3e84SRandall Stewart * probably newly added address. Several valid addresses in this 11722afb3e84SRandall Stewart * association. A source address may not be changed. Additionally, 11732afb3e84SRandall Stewart * they can be configured on a same interface as "alias" addresses. 11742afb3e84SRandall Stewart * (by micchie) 11752afb3e84SRandall Stewart */ 11762afb3e84SRandall Stewart addrnum = sctp_local_addr_count(stcb); 11772afb3e84SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "p_check_react(): %d local addresses\n", 11782afb3e84SRandall Stewart addrnum); 11792afb3e84SRandall Stewart if (addrnum == 1) { 11802afb3e84SRandall Stewart TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 11812afb3e84SRandall Stewart /* clear any cached route and source address */ 11822afb3e84SRandall Stewart if (net->ro.ro_rt) { 11832afb3e84SRandall Stewart RTFREE(net->ro.ro_rt); 11842afb3e84SRandall Stewart net->ro.ro_rt = NULL; 11852afb3e84SRandall Stewart } 11862afb3e84SRandall Stewart if (net->src_addr_selected) { 11872afb3e84SRandall Stewart sctp_free_ifa(net->ro._s_addr); 11882afb3e84SRandall Stewart net->ro._s_addr = NULL; 11892afb3e84SRandall Stewart net->src_addr_selected = 0; 11902afb3e84SRandall Stewart } 11912afb3e84SRandall Stewart /* Retransmit unacknowledged DATA chunks immediately */ 11922afb3e84SRandall Stewart if (sctp_is_mobility_feature_on(stcb->sctp_ep, 11932afb3e84SRandall Stewart SCTP_MOBILITY_FASTHANDOFF)) { 11942afb3e84SRandall Stewart sctp_net_immediate_retrans(stcb, net); 11952afb3e84SRandall Stewart } 11962afb3e84SRandall Stewart /* also, SET PRIMARY is maybe already sent */ 11972afb3e84SRandall Stewart } 11982afb3e84SRandall Stewart return; 11992afb3e84SRandall Stewart } 12002afb3e84SRandall Stewart /* Multiple local addresses exsist in the association. */ 12012afb3e84SRandall Stewart TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 12022afb3e84SRandall Stewart /* clear any cached route and source address */ 12032afb3e84SRandall Stewart if (net->ro.ro_rt) { 12042afb3e84SRandall Stewart RTFREE(net->ro.ro_rt); 12052afb3e84SRandall Stewart net->ro.ro_rt = NULL; 12062afb3e84SRandall Stewart } 12072afb3e84SRandall Stewart if (net->src_addr_selected) { 12082afb3e84SRandall Stewart sctp_free_ifa(net->ro._s_addr); 12092afb3e84SRandall Stewart net->ro._s_addr = NULL; 12102afb3e84SRandall Stewart net->src_addr_selected = 0; 12112afb3e84SRandall Stewart } 12122afb3e84SRandall Stewart /* 12132afb3e84SRandall Stewart * Check if the nexthop is corresponding to the new address. 12142afb3e84SRandall Stewart * If the new address is corresponding to the current 12152afb3e84SRandall Stewart * nexthop, the path will be changed. If the new address is 12162afb3e84SRandall Stewart * NOT corresponding to the current nexthop, the path will 12172afb3e84SRandall Stewart * not be changed. 12182afb3e84SRandall Stewart */ 12192afb3e84SRandall Stewart SCTP_RTALLOC((sctp_route_t *) & net->ro, 12202afb3e84SRandall Stewart stcb->sctp_ep->def_vrf_id); 12212afb3e84SRandall Stewart if (net->ro.ro_rt == NULL) 12222afb3e84SRandall Stewart continue; 12232afb3e84SRandall Stewart 12242afb3e84SRandall Stewart changed = 0; 12252afb3e84SRandall Stewart if (net->ro._l_addr.sa.sa_family == AF_INET) { 12262afb3e84SRandall Stewart if (sctp_v4src_match_nexthop(newifa, (sctp_route_t *) & net->ro)) 12272afb3e84SRandall Stewart changed = 1; 12282afb3e84SRandall Stewart } 12295e2c2d87SRandall Stewart #ifdef INET6 12302afb3e84SRandall Stewart if (net->ro._l_addr.sa.sa_family == AF_INET6) { 12312afb3e84SRandall Stewart if (sctp_v6src_match_nexthop( 12322afb3e84SRandall Stewart &newifa->address.sin6, (sctp_route_t *) & net->ro)) 12332afb3e84SRandall Stewart changed = 1; 12342afb3e84SRandall Stewart } 12355e2c2d87SRandall Stewart #endif 12362afb3e84SRandall Stewart /* 12372afb3e84SRandall Stewart * if the newly added address does not relate routing 12382afb3e84SRandall Stewart * information, we skip. 12392afb3e84SRandall Stewart */ 12402afb3e84SRandall Stewart if (changed == 0) 12412afb3e84SRandall Stewart continue; 12422afb3e84SRandall Stewart /* Retransmit unacknowledged DATA chunks immediately */ 12432afb3e84SRandall Stewart if (sctp_is_mobility_feature_on(stcb->sctp_ep, 12442afb3e84SRandall Stewart SCTP_MOBILITY_FASTHANDOFF)) { 12452afb3e84SRandall Stewart sctp_net_immediate_retrans(stcb, net); 12462afb3e84SRandall Stewart } 12472afb3e84SRandall Stewart /* Send SET PRIMARY for this new address */ 12482afb3e84SRandall Stewart if (net == stcb->asoc.primary_destination) { 12492afb3e84SRandall Stewart (void)sctp_asconf_queue_mgmt(stcb, newifa, 12502afb3e84SRandall Stewart SCTP_SET_PRIM_ADDR); 12512afb3e84SRandall Stewart } 12522afb3e84SRandall Stewart } 12532afb3e84SRandall Stewart } 12542afb3e84SRandall Stewart 12552dad8a55SRandall Stewart /* 1256f8829a4aSRandall Stewart * process an ADD/DELETE IP ack from peer. 12571b649582SRandall Stewart * addr: corresponding sctp_ifa to the address being added/deleted. 1258f8829a4aSRandall Stewart * type: SCTP_ADD_IP_ADDRESS or SCTP_DEL_IP_ADDRESS. 1259f8829a4aSRandall Stewart * flag: 1=success, 0=failure. 1260f8829a4aSRandall Stewart */ 1261f8829a4aSRandall Stewart static void 126242551e99SRandall Stewart sctp_asconf_addr_mgmt_ack(struct sctp_tcb *stcb, struct sctp_ifa *addr, 1263f8829a4aSRandall Stewart uint16_t type, uint32_t flag) 1264f8829a4aSRandall Stewart { 1265f8829a4aSRandall Stewart /* 1266f8829a4aSRandall Stewart * do the necessary asoc list work- if we get a failure indication, 12672dad8a55SRandall Stewart * leave the address on the assoc's restricted list. If we get a 12682dad8a55SRandall Stewart * success indication, remove the address from the restricted list. 1269f8829a4aSRandall Stewart */ 1270f8829a4aSRandall Stewart /* 1271f8829a4aSRandall Stewart * Note: this will only occur for ADD_IP_ADDRESS, since 1272f8829a4aSRandall Stewart * DEL_IP_ADDRESS is never actually added to the list... 1273f8829a4aSRandall Stewart */ 1274f8829a4aSRandall Stewart if (flag) { 12751b649582SRandall Stewart /* success case, so remove from the restricted list */ 12761b649582SRandall Stewart sctp_del_local_addr_restricted(stcb, addr); 12772dad8a55SRandall Stewart 12783232788eSRandall Stewart if (sctp_is_mobility_feature_on(stcb->sctp_ep, 1279d55b0b1bSRandall Stewart SCTP_MOBILITY_BASE) || 1280d55b0b1bSRandall Stewart sctp_is_mobility_feature_on(stcb->sctp_ep, 1281d55b0b1bSRandall Stewart SCTP_MOBILITY_FASTHANDOFF)) { 12822afb3e84SRandall Stewart sctp_path_check_and_react(stcb, addr); 12832afb3e84SRandall Stewart return; 12842afb3e84SRandall Stewart } 12853232788eSRandall Stewart /* clear any cached/topologically incorrect source addresses */ 12862dad8a55SRandall Stewart sctp_asconf_nets_cleanup(stcb, addr->ifn_p); 1287f8829a4aSRandall Stewart } 1288f8829a4aSRandall Stewart /* else, leave it on the list */ 1289f8829a4aSRandall Stewart } 1290f8829a4aSRandall Stewart 1291f8829a4aSRandall Stewart /* 12921b649582SRandall Stewart * add an asconf add/delete/set primary IP address parameter to the queue. 1293f8829a4aSRandall Stewart * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR. 12941b649582SRandall Stewart * returns 0 if queued, -1 if not queued/removed. 12951b649582SRandall Stewart * NOTE: if adding, but a delete for the same address is already scheduled 12961b649582SRandall Stewart * (and not yet sent out), simply remove it from queue. Same for deleting 12971b649582SRandall Stewart * an address already scheduled for add. If a duplicate operation is found, 12981b649582SRandall Stewart * ignore the new one. 1299f8829a4aSRandall Stewart */ 13001b649582SRandall Stewart static int 13011b649582SRandall Stewart sctp_asconf_queue_mgmt(struct sctp_tcb *stcb, struct sctp_ifa *ifa, 130218e198d3SRandall Stewart uint16_t type) 1303f8829a4aSRandall Stewart { 1304f8829a4aSRandall Stewart struct sctp_asconf_addr *aa, *aa_next; 1305f8829a4aSRandall Stewart struct sockaddr *sa; 1306f8829a4aSRandall Stewart 1307f8829a4aSRandall Stewart /* make sure the request isn't already in the queue */ 1308f8829a4aSRandall Stewart for (aa = TAILQ_FIRST(&stcb->asoc.asconf_queue); aa != NULL; 1309f8829a4aSRandall Stewart aa = aa_next) { 1310f8829a4aSRandall Stewart aa_next = TAILQ_NEXT(aa, next); 1311f8829a4aSRandall Stewart /* address match? */ 131242551e99SRandall Stewart if (sctp_asconf_addr_match(aa, &ifa->address.sa) == 0) 1313f8829a4aSRandall Stewart continue; 1314c54a18d2SRandall Stewart /* 1315c54a18d2SRandall Stewart * is the request already in queue but not sent? pass the 1316c54a18d2SRandall Stewart * request already sent in order to resolve the following 1317c54a18d2SRandall Stewart * case: 1. arrival of ADD, then sent 2. arrival of DEL. we 1318c54a18d2SRandall Stewart * can't remove the ADD request already sent 3. arrival of 1319c54a18d2SRandall Stewart * ADD 1320c54a18d2SRandall Stewart */ 1321c54a18d2SRandall Stewart if (aa->ap.aph.ph.param_type == type && aa->sent == 0) { 1322f8829a4aSRandall Stewart return (-1); 1323f8829a4aSRandall Stewart } 1324f8829a4aSRandall Stewart /* is the negative request already in queue, and not sent */ 13251b649582SRandall Stewart if ((aa->sent == 0) && (type == SCTP_ADD_IP_ADDRESS) && 13261b649582SRandall Stewart (aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS)) { 1327f8829a4aSRandall Stewart /* add requested, delete already queued */ 1328f8829a4aSRandall Stewart TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next); 13291b649582SRandall Stewart /* remove the ifa from the restricted list */ 13301b649582SRandall Stewart sctp_del_local_addr_restricted(stcb, ifa); 13311b649582SRandall Stewart /* free the asconf param */ 1332207304d4SRandall Stewart SCTP_FREE(aa, SCTP_M_ASC_ADDR); 13331b649582SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_mgmt: add removes queued entry\n"); 13341b649582SRandall Stewart return (-1); 13351b649582SRandall Stewart } 13361b649582SRandall Stewart if ((aa->sent == 0) && (type == SCTP_DEL_IP_ADDRESS) && 13371b649582SRandall Stewart (aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS)) { 13381b649582SRandall Stewart /* delete requested, add already queued */ 13391b649582SRandall Stewart TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next); 13401b649582SRandall Stewart /* remove the aa->ifa from the restricted list */ 13411b649582SRandall Stewart sctp_del_local_addr_restricted(stcb, aa->ifa); 13421b649582SRandall Stewart /* free the asconf param */ 13431b649582SRandall Stewart SCTP_FREE(aa, SCTP_M_ASC_ADDR); 13441b649582SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_mgmt: delete removes queued entry\n"); 1345f8829a4aSRandall Stewart return (-1); 1346f8829a4aSRandall Stewart } 1347f8829a4aSRandall Stewart } /* for each aa */ 1348f8829a4aSRandall Stewart 1349f8829a4aSRandall Stewart /* adding new request to the queue */ 13501b649582SRandall Stewart SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), 13511b649582SRandall Stewart SCTP_M_ASC_ADDR); 1352f8829a4aSRandall Stewart if (aa == NULL) { 1353f8829a4aSRandall Stewart /* didn't get memory */ 13541b649582SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "asconf_queue_mgmt: failed to get memory!\n"); 1355f8829a4aSRandall Stewart return (-1); 1356f8829a4aSRandall Stewart } 1357830d754dSRandall Stewart aa->special_del = 0; 1358f8829a4aSRandall Stewart /* fill in asconf address parameter fields */ 1359f8829a4aSRandall Stewart /* top level elements are "networked" during send */ 1360f8829a4aSRandall Stewart aa->ap.aph.ph.param_type = type; 1361f8829a4aSRandall Stewart aa->ifa = ifa; 1362bff64a4dSRandall Stewart atomic_add_int(&ifa->refcount, 1); 1363f8829a4aSRandall Stewart /* correlation_id filled in during send routine later... */ 136442551e99SRandall Stewart if (ifa->address.sa.sa_family == AF_INET6) { 1365f8829a4aSRandall Stewart /* IPv6 address */ 1366f8829a4aSRandall Stewart struct sockaddr_in6 *sin6; 1367f8829a4aSRandall Stewart 136842551e99SRandall Stewart sin6 = (struct sockaddr_in6 *)&ifa->address.sa; 1369f8829a4aSRandall Stewart sa = (struct sockaddr *)sin6; 1370f8829a4aSRandall Stewart aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS; 1371f8829a4aSRandall Stewart aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param)); 13721b649582SRandall Stewart aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + 1373f8829a4aSRandall Stewart sizeof(struct sctp_ipv6addr_param); 1374f8829a4aSRandall Stewart memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr, 1375f8829a4aSRandall Stewart sizeof(struct in6_addr)); 137642551e99SRandall Stewart } else if (ifa->address.sa.sa_family == AF_INET) { 1377f8829a4aSRandall Stewart /* IPv4 address */ 13781b649582SRandall Stewart struct sockaddr_in *sin; 1379f8829a4aSRandall Stewart 13801b649582SRandall Stewart sin = (struct sockaddr_in *)&ifa->address.sa; 1381f8829a4aSRandall Stewart sa = (struct sockaddr *)sin; 1382f8829a4aSRandall Stewart aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS; 1383f8829a4aSRandall Stewart aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param)); 13841b649582SRandall Stewart aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + 1385f8829a4aSRandall Stewart sizeof(struct sctp_ipv4addr_param); 1386f8829a4aSRandall Stewart memcpy(&aa->ap.addrp.addr, &sin->sin_addr, 1387f8829a4aSRandall Stewart sizeof(struct in_addr)); 1388f8829a4aSRandall Stewart } else { 1389f8829a4aSRandall Stewart /* invalid family! */ 1390207304d4SRandall Stewart SCTP_FREE(aa, SCTP_M_ASC_ADDR); 13913232788eSRandall Stewart sctp_free_ifa(ifa); 1392f8829a4aSRandall Stewart return (-1); 1393f8829a4aSRandall Stewart } 1394f8829a4aSRandall Stewart aa->sent = 0; /* clear sent flag */ 1395f8829a4aSRandall Stewart 1396f8829a4aSRandall Stewart TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); 1397f8829a4aSRandall Stewart #ifdef SCTP_DEBUG 1398b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_debug_on) && SCTP_DEBUG_ASCONF2) { 1399c54a18d2SRandall Stewart if (type == SCTP_ADD_IP_ADDRESS) { 1400c54a18d2SRandall Stewart SCTP_PRINTF("asconf_queue_mgmt: inserted asconf ADD_IP_ADDRESS: "); 1401c54a18d2SRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, sa); 1402c54a18d2SRandall Stewart } else if (type == SCTP_DEL_IP_ADDRESS) { 14031b649582SRandall Stewart SCTP_PRINTF("asconf_queue_mgmt: appended asconf DEL_IP_ADDRESS: "); 1404ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, sa); 1405f8829a4aSRandall Stewart } else { 14061b649582SRandall Stewart SCTP_PRINTF("asconf_queue_mgmt: appended asconf SET_PRIM_ADDR: "); 1407ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, sa); 1408f8829a4aSRandall Stewart } 1409f8829a4aSRandall Stewart } 1410ad81507eSRandall Stewart #endif 1411f8829a4aSRandall Stewart 1412f8829a4aSRandall Stewart return (0); 1413f8829a4aSRandall Stewart } 1414f8829a4aSRandall Stewart 14151b649582SRandall Stewart 14161b649582SRandall Stewart /* 14171b649582SRandall Stewart * add an asconf operation for the given ifa and type. 14181b649582SRandall Stewart * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR. 14191b649582SRandall Stewart * returns 0 if completed, -1 if not completed, 1 if immediate send is 14201b649582SRandall Stewart * advisable. 14211b649582SRandall Stewart */ 14221b649582SRandall Stewart static int 14231b649582SRandall Stewart sctp_asconf_queue_add(struct sctp_tcb *stcb, struct sctp_ifa *ifa, 14241b649582SRandall Stewart uint16_t type) 14251b649582SRandall Stewart { 14261b649582SRandall Stewart uint32_t status; 14271b649582SRandall Stewart int pending_delete_queued = 0; 14281b649582SRandall Stewart 14291b649582SRandall Stewart /* see if peer supports ASCONF */ 14301b649582SRandall Stewart if (stcb->asoc.peer_supports_asconf == 0) { 14311b649582SRandall Stewart return (-1); 14321b649582SRandall Stewart } 14331b649582SRandall Stewart /* 14341b649582SRandall Stewart * if this is deleting the last address from the assoc, mark it as 14351b649582SRandall Stewart * pending. 14361b649582SRandall Stewart */ 14371b649582SRandall Stewart if ((type == SCTP_DEL_IP_ADDRESS) && !stcb->asoc.asconf_del_pending && 14381b649582SRandall Stewart (sctp_local_addr_count(stcb) < 2)) { 14391b649582SRandall Stewart /* set the pending delete info only */ 14401b649582SRandall Stewart stcb->asoc.asconf_del_pending = 1; 14411b649582SRandall Stewart stcb->asoc.asconf_addr_del_pending = ifa; 14421b649582SRandall Stewart atomic_add_int(&ifa->refcount, 1); 14431b649582SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF2, 14441b649582SRandall Stewart "asconf_queue_add: mark delete last address pending\n"); 14451b649582SRandall Stewart return (-1); 14461b649582SRandall Stewart } 1447c54a18d2SRandall Stewart /* queue an asconf parameter */ 1448c54a18d2SRandall Stewart status = sctp_asconf_queue_mgmt(stcb, ifa, type); 1449c54a18d2SRandall Stewart 14501b649582SRandall Stewart /* 14511b649582SRandall Stewart * if this is an add, and there is a delete also pending (i.e. the 14521b649582SRandall Stewart * last local address is being changed), queue the pending delete 14531b649582SRandall Stewart * too. 14541b649582SRandall Stewart */ 1455c54a18d2SRandall Stewart if ((type == SCTP_ADD_IP_ADDRESS) && stcb->asoc.asconf_del_pending && (status == 0)) { 14561b649582SRandall Stewart /* queue in the pending delete */ 14571b649582SRandall Stewart if (sctp_asconf_queue_mgmt(stcb, 14581b649582SRandall Stewart stcb->asoc.asconf_addr_del_pending, 14591b649582SRandall Stewart SCTP_DEL_IP_ADDRESS) == 0) { 14601b649582SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_add: queing pending delete\n"); 14611b649582SRandall Stewart pending_delete_queued = 1; 14621b649582SRandall Stewart /* clear out the pending delete info */ 14631b649582SRandall Stewart stcb->asoc.asconf_del_pending = 0; 14641b649582SRandall Stewart sctp_free_ifa(stcb->asoc.asconf_addr_del_pending); 14651b649582SRandall Stewart stcb->asoc.asconf_addr_del_pending = NULL; 14661b649582SRandall Stewart } 14671b649582SRandall Stewart } 1468c54a18d2SRandall Stewart if (pending_delete_queued) { 14691b649582SRandall Stewart struct sctp_nets *net; 14701b649582SRandall Stewart 14711b649582SRandall Stewart /* 14721b649582SRandall Stewart * since we know that the only/last address is now being 14731b649582SRandall Stewart * changed in this case, reset the cwnd/rto on all nets to 14741b649582SRandall Stewart * start as a new address and path. Also clear the error 14751b649582SRandall Stewart * counts to give the assoc the best chance to complete the 14761b649582SRandall Stewart * address change. 14771b649582SRandall Stewart */ 14781b649582SRandall Stewart TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 14791b649582SRandall Stewart stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, 14801b649582SRandall Stewart net); 14811b649582SRandall Stewart net->RTO = 0; 14821b649582SRandall Stewart net->error_count = 0; 14831b649582SRandall Stewart } 14841b649582SRandall Stewart stcb->asoc.overall_error_count = 0; 1485b3f1ea41SRandall Stewart if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { 1486c4739e2fSRandall Stewart sctp_misc_ints(SCTP_THRESHOLD_CLEAR, 1487c4739e2fSRandall Stewart stcb->asoc.overall_error_count, 1488c4739e2fSRandall Stewart 0, 1489c4739e2fSRandall Stewart SCTP_FROM_SCTP_ASCONF, 1490c4739e2fSRandall Stewart __LINE__); 1491c4739e2fSRandall Stewart } 14921b649582SRandall Stewart /* queue in an advisory set primary too */ 14931b649582SRandall Stewart (void)sctp_asconf_queue_mgmt(stcb, ifa, SCTP_SET_PRIM_ADDR); 14941b649582SRandall Stewart /* let caller know we should send this out immediately */ 14951b649582SRandall Stewart status = 1; 14961b649582SRandall Stewart } 14971b649582SRandall Stewart return (status); 14981b649582SRandall Stewart } 14991b649582SRandall Stewart 15003232788eSRandall Stewart /*- 15013232788eSRandall Stewart * add an asconf delete IP address parameter to the queue by sockaddr and 15023232788eSRandall Stewart * possibly with no sctp_ifa available. This is only called by the routine 15033232788eSRandall Stewart * that checks the addresses in an INIT-ACK against the current address list. 1504f8829a4aSRandall Stewart * returns 0 if completed, non-zero if not completed. 15053232788eSRandall Stewart * NOTE: if an add is already scheduled (and not yet sent out), simply 15063232788eSRandall Stewart * remove it from queue. If a duplicate operation is found, ignore the 15073232788eSRandall Stewart * new one. 1508f8829a4aSRandall Stewart */ 15091b649582SRandall Stewart static int 15103232788eSRandall Stewart sctp_asconf_queue_sa_delete(struct sctp_tcb *stcb, struct sockaddr *sa) 1511f8829a4aSRandall Stewart { 1512bff64a4dSRandall Stewart struct sctp_ifa *ifa; 1513f8829a4aSRandall Stewart struct sctp_asconf_addr *aa, *aa_next; 151442551e99SRandall Stewart uint32_t vrf_id; 1515f8829a4aSRandall Stewart 1516ad81507eSRandall Stewart if (stcb == NULL) { 1517ad81507eSRandall Stewart return (-1); 1518ad81507eSRandall Stewart } 1519f8829a4aSRandall Stewart /* see if peer supports ASCONF */ 1520f8829a4aSRandall Stewart if (stcb->asoc.peer_supports_asconf == 0) { 1521f8829a4aSRandall Stewart return (-1); 1522f8829a4aSRandall Stewart } 1523f8829a4aSRandall Stewart /* make sure the request isn't already in the queue */ 1524f8829a4aSRandall Stewart for (aa = TAILQ_FIRST(&stcb->asoc.asconf_queue); aa != NULL; 1525f8829a4aSRandall Stewart aa = aa_next) { 1526f8829a4aSRandall Stewart aa_next = TAILQ_NEXT(aa, next); 1527f8829a4aSRandall Stewart /* address match? */ 1528f8829a4aSRandall Stewart if (sctp_asconf_addr_match(aa, sa) == 0) 1529f8829a4aSRandall Stewart continue; 1530f8829a4aSRandall Stewart /* is the request already in queue (sent or not) */ 15313232788eSRandall Stewart if (aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) { 1532f8829a4aSRandall Stewart return (-1); 1533f8829a4aSRandall Stewart } 1534f8829a4aSRandall Stewart /* is the negative request already in queue, and not sent */ 1535f8829a4aSRandall Stewart if (aa->sent == 1) 1536f8829a4aSRandall Stewart continue; 15373232788eSRandall Stewart if (aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS) { 15383232788eSRandall Stewart /* add already queued, so remove existing entry */ 1539f8829a4aSRandall Stewart TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next); 15401b649582SRandall Stewart sctp_del_local_addr_restricted(stcb, aa->ifa); 1541f8829a4aSRandall Stewart /* free the entry */ 1542207304d4SRandall Stewart SCTP_FREE(aa, SCTP_M_ASC_ADDR); 1543f8829a4aSRandall Stewart return (-1); 1544f8829a4aSRandall Stewart } 1545f8829a4aSRandall Stewart } /* for each aa */ 15463232788eSRandall Stewart 15473232788eSRandall Stewart /* find any existing ifa-- NOTE ifa CAN be allowed to be NULL */ 1548bff64a4dSRandall Stewart if (stcb) { 1549bff64a4dSRandall Stewart vrf_id = stcb->asoc.vrf_id; 1550bff64a4dSRandall Stewart } else { 1551bff64a4dSRandall Stewart vrf_id = SCTP_DEFAULT_VRFID; 1552bff64a4dSRandall Stewart } 1553851b7298SRandall Stewart ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED); 15543232788eSRandall Stewart 1555f8829a4aSRandall Stewart /* adding new request to the queue */ 15561b649582SRandall Stewart SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), 15571b649582SRandall Stewart SCTP_M_ASC_ADDR); 1558f8829a4aSRandall Stewart if (aa == NULL) { 1559f8829a4aSRandall Stewart /* didn't get memory */ 1560ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 15613232788eSRandall Stewart "sctp_asconf_queue_sa_delete: failed to get memory!\n"); 1562f8829a4aSRandall Stewart return (-1); 1563f8829a4aSRandall Stewart } 1564830d754dSRandall Stewart aa->special_del = 0; 1565f8829a4aSRandall Stewart /* fill in asconf address parameter fields */ 1566f8829a4aSRandall Stewart /* top level elements are "networked" during send */ 15673232788eSRandall Stewart aa->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS; 1568bff64a4dSRandall Stewart aa->ifa = ifa; 15693232788eSRandall Stewart if (ifa) 1570bff64a4dSRandall Stewart atomic_add_int(&ifa->refcount, 1); 1571f8829a4aSRandall Stewart /* correlation_id filled in during send routine later... */ 1572f8829a4aSRandall Stewart if (sa->sa_family == AF_INET6) { 1573f8829a4aSRandall Stewart /* IPv6 address */ 1574f8829a4aSRandall Stewart struct sockaddr_in6 *sin6; 1575f8829a4aSRandall Stewart 1576f8829a4aSRandall Stewart sin6 = (struct sockaddr_in6 *)sa; 1577f8829a4aSRandall Stewart aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS; 1578f8829a4aSRandall Stewart aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param)); 1579f8829a4aSRandall Stewart aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv6addr_param); 1580f8829a4aSRandall Stewart memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr, 1581f8829a4aSRandall Stewart sizeof(struct in6_addr)); 1582f8829a4aSRandall Stewart } else if (sa->sa_family == AF_INET) { 1583f8829a4aSRandall Stewart /* IPv4 address */ 1584f8829a4aSRandall Stewart struct sockaddr_in *sin = (struct sockaddr_in *)sa; 1585f8829a4aSRandall Stewart 1586f8829a4aSRandall Stewart aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS; 1587f8829a4aSRandall Stewart aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param)); 1588f8829a4aSRandall Stewart aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv4addr_param); 1589f8829a4aSRandall Stewart memcpy(&aa->ap.addrp.addr, &sin->sin_addr, 1590f8829a4aSRandall Stewart sizeof(struct in_addr)); 1591f8829a4aSRandall Stewart } else { 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 */ 1880f8829a4aSRandall Stewart for (aa = TAILQ_FIRST(&stcb->asoc.asconf_queue); aa != NULL; 1881f8829a4aSRandall Stewart aa = aa_next) { 1882f8829a4aSRandall Stewart aa_next = TAILQ_NEXT(aa, next); 1883f8829a4aSRandall Stewart if (aa->sent == 1) { 1884f8829a4aSRandall Stewart /* 1885f8829a4aSRandall Stewart * implicitly successful or failed if correlation_id 1886f8829a4aSRandall Stewart * < last_error_id, then success else, failure 1887f8829a4aSRandall Stewart */ 1888f8829a4aSRandall Stewart if (aa->ap.aph.correlation_id < last_error_id) 188918e198d3SRandall Stewart sctp_asconf_process_param_ack(stcb, aa, 1); 1890f8829a4aSRandall Stewart else 189118e198d3SRandall Stewart sctp_asconf_process_param_ack(stcb, aa, 0); 1892f8829a4aSRandall Stewart } else { 1893f8829a4aSRandall Stewart /* 1894f8829a4aSRandall Stewart * since we always process in order (FIFO queue) if 1895f8829a4aSRandall Stewart * we reach one that hasn't been sent, the rest 1896f8829a4aSRandall Stewart * should not have been sent either. so, we're 1897f8829a4aSRandall Stewart * done... 1898f8829a4aSRandall Stewart */ 1899f8829a4aSRandall Stewart break; 1900f8829a4aSRandall Stewart } 1901f8829a4aSRandall Stewart } 1902f8829a4aSRandall Stewart 1903f8829a4aSRandall Stewart /* update the next sequence number to use */ 1904c54a18d2SRandall Stewart asoc->asconf_seq_out_acked++; 1905f8829a4aSRandall Stewart /* remove the old ASCONF on our outbound queue */ 1906f8829a4aSRandall Stewart sctp_toss_old_asconf(stcb); 1907f8829a4aSRandall Stewart if (!TAILQ_EMPTY(&stcb->asoc.asconf_queue)) { 19081b649582SRandall Stewart #ifdef SCTP_TIMER_BASED_ASCONF 1909f8829a4aSRandall Stewart /* we have more params, so restart our timer */ 1910f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, 1911f8829a4aSRandall Stewart stcb, net); 19121b649582SRandall Stewart #else 19131b649582SRandall Stewart /* we have more params, so send out more */ 19143232788eSRandall Stewart sctp_send_asconf(stcb, net, SCTP_ADDR_NOT_LOCKED); 19151b649582SRandall Stewart #endif 1916f8829a4aSRandall Stewart } 1917f8829a4aSRandall Stewart } 1918f8829a4aSRandall Stewart 19195e2c2d87SRandall Stewart #ifdef INET6 1920f8829a4aSRandall Stewart static uint32_t 1921f8829a4aSRandall Stewart sctp_is_scopeid_in_nets(struct sctp_tcb *stcb, struct sockaddr *sa) 1922f8829a4aSRandall Stewart { 1923f8829a4aSRandall Stewart struct sockaddr_in6 *sin6, *net6; 1924f8829a4aSRandall Stewart struct sctp_nets *net; 1925f8829a4aSRandall Stewart 1926f8829a4aSRandall Stewart if (sa->sa_family != AF_INET6) { 1927f8829a4aSRandall Stewart /* wrong family */ 1928f8829a4aSRandall Stewart return (0); 1929f8829a4aSRandall Stewart } 1930f8829a4aSRandall Stewart sin6 = (struct sockaddr_in6 *)sa; 1931f8829a4aSRandall Stewart if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) == 0) { 1932f8829a4aSRandall Stewart /* not link local address */ 1933f8829a4aSRandall Stewart return (0); 1934f8829a4aSRandall Stewart } 1935f8829a4aSRandall Stewart /* hunt through our destination nets list for this scope_id */ 1936f8829a4aSRandall Stewart TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 1937f8829a4aSRandall Stewart if (((struct sockaddr *)(&net->ro._l_addr))->sa_family != 1938f8829a4aSRandall Stewart AF_INET6) 1939f8829a4aSRandall Stewart continue; 1940f8829a4aSRandall Stewart net6 = (struct sockaddr_in6 *)&net->ro._l_addr; 1941f8829a4aSRandall Stewart if (IN6_IS_ADDR_LINKLOCAL(&net6->sin6_addr) == 0) 1942f8829a4aSRandall Stewart continue; 1943f8829a4aSRandall Stewart if (sctp_is_same_scope(sin6, net6)) { 1944f8829a4aSRandall Stewart /* found one */ 1945f8829a4aSRandall Stewart return (1); 1946f8829a4aSRandall Stewart } 1947f8829a4aSRandall Stewart } 1948f8829a4aSRandall Stewart /* didn't find one */ 1949f8829a4aSRandall Stewart return (0); 1950f8829a4aSRandall Stewart } 1951f8829a4aSRandall Stewart 19525e2c2d87SRandall Stewart #endif 19535e2c2d87SRandall Stewart 1954f8829a4aSRandall Stewart /* 1955f8829a4aSRandall Stewart * address management functions 1956f8829a4aSRandall Stewart */ 1957f8829a4aSRandall Stewart static void 1958f8829a4aSRandall Stewart sctp_addr_mgmt_assoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb, 19593232788eSRandall Stewart struct sctp_ifa *ifa, uint16_t type, int addr_locked) 1960f8829a4aSRandall Stewart { 1961f8829a4aSRandall Stewart int status; 1962f8829a4aSRandall Stewart 1963f8829a4aSRandall Stewart 1964f8829a4aSRandall Stewart if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0 && 1965f8829a4aSRandall Stewart sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_ASCONF)) { 1966f8829a4aSRandall Stewart /* subset bound, no ASCONF allowed case, so ignore */ 1967f8829a4aSRandall Stewart return; 1968f8829a4aSRandall Stewart } 1969f8829a4aSRandall Stewart /* 1970f8829a4aSRandall Stewart * note: we know this is not the subset bound, no ASCONF case eg. 1971f8829a4aSRandall Stewart * this is boundall or subset bound w/ASCONF allowed 1972f8829a4aSRandall Stewart */ 1973f8829a4aSRandall Stewart 1974f8829a4aSRandall Stewart /* first, make sure it's a good address family */ 197542551e99SRandall Stewart if (ifa->address.sa.sa_family != AF_INET6 && 197642551e99SRandall Stewart ifa->address.sa.sa_family != AF_INET) { 1977f8829a4aSRandall Stewart return; 1978f8829a4aSRandall Stewart } 1979f8829a4aSRandall Stewart /* make sure we're "allowed" to add this type of addr */ 198042551e99SRandall Stewart if (ifa->address.sa.sa_family == AF_INET6) { 1981f8829a4aSRandall Stewart /* invalid if we're not a v6 endpoint */ 1982f8829a4aSRandall Stewart if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) 1983f8829a4aSRandall Stewart return; 1984f8829a4aSRandall Stewart /* is the v6 addr really valid ? */ 198542551e99SRandall Stewart if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) { 1986f8829a4aSRandall Stewart return; 1987f8829a4aSRandall Stewart } 1988f8829a4aSRandall Stewart } 1989f8829a4aSRandall Stewart /* put this address on the "pending/do not use yet" list */ 19901b649582SRandall Stewart sctp_add_local_addr_restricted(stcb, ifa); 1991f8829a4aSRandall Stewart /* 1992f8829a4aSRandall Stewart * check address scope if address is out of scope, don't queue 1993f8829a4aSRandall Stewart * anything... note: this would leave the address on both inp and 1994f8829a4aSRandall Stewart * asoc lists 1995f8829a4aSRandall Stewart */ 19965e2c2d87SRandall Stewart switch (ifa->address.sa.sa_family) { 19975e2c2d87SRandall Stewart #ifdef INET6 19985e2c2d87SRandall Stewart case AF_INET6: 19995e2c2d87SRandall Stewart { 2000f8829a4aSRandall Stewart struct sockaddr_in6 *sin6; 2001f8829a4aSRandall Stewart 200242551e99SRandall Stewart sin6 = (struct sockaddr_in6 *)&ifa->address.sin6; 2003f8829a4aSRandall Stewart if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { 2004f8829a4aSRandall Stewart /* we skip unspecifed addresses */ 2005f8829a4aSRandall Stewart return; 2006f8829a4aSRandall Stewart } 2007f8829a4aSRandall Stewart if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { 2008f8829a4aSRandall Stewart if (stcb->asoc.local_scope == 0) { 2009f8829a4aSRandall Stewart return; 2010f8829a4aSRandall Stewart } 2011f8829a4aSRandall Stewart /* is it the right link local scope? */ 201242551e99SRandall Stewart if (sctp_is_scopeid_in_nets(stcb, &ifa->address.sa) == 0) { 2013f8829a4aSRandall Stewart return; 2014f8829a4aSRandall Stewart } 2015f8829a4aSRandall Stewart } 2016f8829a4aSRandall Stewart if (stcb->asoc.site_scope == 0 && 2017f8829a4aSRandall Stewart IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)) { 2018f8829a4aSRandall Stewart return; 2019f8829a4aSRandall Stewart } 20205e2c2d87SRandall Stewart break; 20215e2c2d87SRandall Stewart } 20225e2c2d87SRandall Stewart #endif 20235e2c2d87SRandall Stewart case AF_INET: 20245e2c2d87SRandall Stewart { 2025f8829a4aSRandall Stewart struct sockaddr_in *sin; 2026f8829a4aSRandall Stewart struct in6pcb *inp6; 2027f8829a4aSRandall Stewart 2028f8829a4aSRandall Stewart inp6 = (struct in6pcb *)&inp->ip_inp.inp; 2029f8829a4aSRandall Stewart /* invalid if we are a v6 only endpoint */ 2030f8829a4aSRandall Stewart if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) && 203144b7479bSRandall Stewart SCTP_IPV6_V6ONLY(inp6)) 2032f8829a4aSRandall Stewart return; 2033f8829a4aSRandall Stewart 203442551e99SRandall Stewart sin = (struct sockaddr_in *)&ifa->address.sa; 2035f8829a4aSRandall Stewart if (sin->sin_addr.s_addr == 0) { 2036f8829a4aSRandall Stewart /* we skip unspecifed addresses */ 2037f8829a4aSRandall Stewart return; 2038f8829a4aSRandall Stewart } 2039f8829a4aSRandall Stewart if (stcb->asoc.ipv4_local_scope == 0 && 2040f8829a4aSRandall Stewart IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) { 2041f8829a4aSRandall Stewart return; 2042f8829a4aSRandall Stewart } 20435e2c2d87SRandall Stewart break; 20445e2c2d87SRandall Stewart } 20455e2c2d87SRandall Stewart default: 2046f8829a4aSRandall Stewart /* else, not AF_INET or AF_INET6, so skip */ 2047f8829a4aSRandall Stewart return; 2048f8829a4aSRandall Stewart } 2049f8829a4aSRandall Stewart 2050f8829a4aSRandall Stewart /* queue an asconf for this address add/delete */ 2051f8829a4aSRandall Stewart if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF)) { 2052f8829a4aSRandall Stewart /* does the peer do asconf? */ 2053f8829a4aSRandall Stewart if (stcb->asoc.peer_supports_asconf) { 2054f8829a4aSRandall Stewart /* queue an asconf for this addr */ 2055f8829a4aSRandall Stewart status = sctp_asconf_queue_add(stcb, ifa, type); 20561b649582SRandall Stewart 2057f8829a4aSRandall Stewart /* 20581b649582SRandall Stewart * if queued ok, and in the open state, send out the 20591b649582SRandall Stewart * ASCONF. If in the non-open state, these will be 20601b649582SRandall Stewart * sent when the state goes open. 2061f8829a4aSRandall Stewart */ 2062f8829a4aSRandall Stewart if (status == 0 && 2063f8829a4aSRandall Stewart SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) { 20641b649582SRandall Stewart #ifdef SCTP_TIMER_BASED_ASCONF 2065f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, inp, 2066f8829a4aSRandall Stewart stcb, stcb->asoc.primary_destination); 20671b649582SRandall Stewart #else 20683232788eSRandall Stewart sctp_send_asconf(stcb, stcb->asoc.primary_destination, 20693232788eSRandall Stewart addr_locked); 20701b649582SRandall Stewart #endif 2071f8829a4aSRandall Stewart } 2072f8829a4aSRandall Stewart } 2073f8829a4aSRandall Stewart } 2074f8829a4aSRandall Stewart } 2075f8829a4aSRandall Stewart 207642551e99SRandall Stewart 207742551e99SRandall Stewart int 20781b649582SRandall Stewart sctp_asconf_iterator_ep(struct sctp_inpcb *inp, void *ptr, uint32_t val) 2079f8829a4aSRandall Stewart { 208042551e99SRandall Stewart struct sctp_asconf_iterator *asc; 208142551e99SRandall Stewart struct sctp_ifa *ifa; 208242551e99SRandall Stewart struct sctp_laddr *l; 208342551e99SRandall Stewart int type; 208442551e99SRandall Stewart int cnt_invalid = 0; 2085f8829a4aSRandall Stewart 208642551e99SRandall Stewart asc = (struct sctp_asconf_iterator *)ptr; 208742551e99SRandall Stewart LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) { 208842551e99SRandall Stewart ifa = l->ifa; 208942551e99SRandall Stewart type = l->action; 209042551e99SRandall Stewart if (ifa->address.sa.sa_family == AF_INET6) { 2091f8829a4aSRandall Stewart /* invalid if we're not a v6 endpoint */ 2092f8829a4aSRandall Stewart if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) { 209342551e99SRandall Stewart cnt_invalid++; 209442551e99SRandall Stewart if (asc->cnt == cnt_invalid) 209542551e99SRandall Stewart return (1); 209642551e99SRandall Stewart else 209742551e99SRandall Stewart continue; 2098f8829a4aSRandall Stewart } 209942551e99SRandall Stewart } else if (ifa->address.sa.sa_family == AF_INET) { 2100f8829a4aSRandall Stewart /* invalid if we are a v6 only endpoint */ 2101f8829a4aSRandall Stewart struct in6pcb *inp6; 2102f8829a4aSRandall Stewart 2103f8829a4aSRandall Stewart inp6 = (struct in6pcb *)&inp->ip_inp.inp; 2104f8829a4aSRandall Stewart if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) && 210544b7479bSRandall Stewart SCTP_IPV6_V6ONLY(inp6)) { 210642551e99SRandall Stewart cnt_invalid++; 210742551e99SRandall Stewart if (asc->cnt == cnt_invalid) 210842551e99SRandall Stewart return (1); 210942551e99SRandall Stewart else 211042551e99SRandall Stewart continue; 2111f8829a4aSRandall Stewart } 2112f8829a4aSRandall Stewart } else { 2113f8829a4aSRandall Stewart /* invalid address family */ 211442551e99SRandall Stewart cnt_invalid++; 211542551e99SRandall Stewart if (asc->cnt == cnt_invalid) 211642551e99SRandall Stewart return (1); 2117f8829a4aSRandall Stewart else 211842551e99SRandall Stewart continue; 2119f8829a4aSRandall Stewart } 212042551e99SRandall Stewart } 212142551e99SRandall Stewart return (0); 212242551e99SRandall Stewart } 2123f8829a4aSRandall Stewart 21241b649582SRandall Stewart static int 21251b649582SRandall Stewart sctp_asconf_iterator_ep_end(struct sctp_inpcb *inp, void *ptr, uint32_t val) 212642551e99SRandall Stewart { 212742551e99SRandall Stewart struct sctp_ifa *ifa; 212842551e99SRandall Stewart struct sctp_asconf_iterator *asc; 212942551e99SRandall Stewart struct sctp_laddr *laddr, *nladdr, *l; 213042551e99SRandall Stewart 213142551e99SRandall Stewart /* Only for specific case not bound all */ 213242551e99SRandall Stewart asc = (struct sctp_asconf_iterator *)ptr; 213342551e99SRandall Stewart LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) { 213442551e99SRandall Stewart ifa = l->ifa; 213542551e99SRandall Stewart if (l->action == SCTP_ADD_IP_ADDRESS) { 21363c503c28SRandall Stewart LIST_FOREACH(laddr, &inp->sctp_addr_list, 21373c503c28SRandall Stewart sctp_nxt_addr) { 213842551e99SRandall Stewart if (laddr->ifa == ifa) { 213942551e99SRandall Stewart laddr->action = 0; 214042551e99SRandall Stewart break; 214142551e99SRandall Stewart } 214242551e99SRandall Stewart } 214342551e99SRandall Stewart } else if (l->action == SCTP_DEL_IP_ADDRESS) { 214442551e99SRandall Stewart laddr = LIST_FIRST(&inp->sctp_addr_list); 214542551e99SRandall Stewart while (laddr) { 214642551e99SRandall Stewart nladdr = LIST_NEXT(laddr, sctp_nxt_addr); 214742551e99SRandall Stewart /* remove only after all guys are done */ 214842551e99SRandall Stewart if (laddr->ifa == ifa) { 214942551e99SRandall Stewart sctp_del_local_addr_ep(inp, ifa); 215042551e99SRandall Stewart } 215142551e99SRandall Stewart laddr = nladdr; 215242551e99SRandall Stewart } 215342551e99SRandall Stewart } 215442551e99SRandall Stewart } 215542551e99SRandall Stewart return (0); 215642551e99SRandall Stewart } 215742551e99SRandall Stewart 215842551e99SRandall Stewart void 21591b649582SRandall Stewart sctp_asconf_iterator_stcb(struct sctp_inpcb *inp, struct sctp_tcb *stcb, 21601b649582SRandall Stewart void *ptr, uint32_t val) 216142551e99SRandall Stewart { 216242551e99SRandall Stewart struct sctp_asconf_iterator *asc; 216342551e99SRandall Stewart struct sctp_ifa *ifa; 216442551e99SRandall Stewart struct sctp_laddr *l; 216542551e99SRandall Stewart int cnt_invalid = 0; 216642551e99SRandall Stewart int type, status; 21671b649582SRandall Stewart int num_queued = 0; 216842551e99SRandall Stewart 216942551e99SRandall Stewart asc = (struct sctp_asconf_iterator *)ptr; 217042551e99SRandall Stewart LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) { 217142551e99SRandall Stewart ifa = l->ifa; 217242551e99SRandall Stewart type = l->action; 217322a67197SRandall Stewart 217422a67197SRandall Stewart /* address's vrf_id must be the vrf_id of the assoc */ 217522a67197SRandall Stewart if (ifa->vrf_id != stcb->asoc.vrf_id) { 217622a67197SRandall Stewart continue; 217722a67197SRandall Stewart } 217842551e99SRandall Stewart /* Same checks again for assoc */ 21795e2c2d87SRandall Stewart switch (ifa->address.sa.sa_family) { 21805e2c2d87SRandall Stewart #ifdef INET6 21815e2c2d87SRandall Stewart case AF_INET6: 21825e2c2d87SRandall Stewart { 218342551e99SRandall Stewart /* invalid if we're not a v6 endpoint */ 218442551e99SRandall Stewart struct sockaddr_in6 *sin6; 218542551e99SRandall Stewart 218642551e99SRandall Stewart if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) { 218742551e99SRandall Stewart cnt_invalid++; 218842551e99SRandall Stewart if (asc->cnt == cnt_invalid) 218942551e99SRandall Stewart return; 219042551e99SRandall Stewart else 219142551e99SRandall Stewart continue; 219242551e99SRandall Stewart } 219342551e99SRandall Stewart sin6 = (struct sockaddr_in6 *)&ifa->address.sin6; 219442551e99SRandall Stewart if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { 219542551e99SRandall Stewart /* we skip unspecifed addresses */ 219642551e99SRandall Stewart continue; 219742551e99SRandall Stewart } 219842551e99SRandall Stewart if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { 219942551e99SRandall Stewart if (stcb->asoc.local_scope == 0) { 220042551e99SRandall Stewart continue; 220142551e99SRandall Stewart } 220242551e99SRandall Stewart /* is it the right link local scope? */ 220342551e99SRandall Stewart if (sctp_is_scopeid_in_nets(stcb, &ifa->address.sa) == 0) { 220442551e99SRandall Stewart continue; 220542551e99SRandall Stewart } 220642551e99SRandall Stewart } 22075e2c2d87SRandall Stewart break; 22085e2c2d87SRandall Stewart } 22095e2c2d87SRandall Stewart #endif 22105e2c2d87SRandall Stewart case AF_INET: 22115e2c2d87SRandall Stewart { 221242551e99SRandall Stewart /* invalid if we are a v6 only endpoint */ 221342551e99SRandall Stewart struct in6pcb *inp6; 221442551e99SRandall Stewart struct sockaddr_in *sin; 221542551e99SRandall Stewart 221642551e99SRandall Stewart inp6 = (struct in6pcb *)&inp->ip_inp.inp; 221742551e99SRandall Stewart /* invalid if we are a v6 only endpoint */ 221842551e99SRandall Stewart if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) && 221942551e99SRandall Stewart SCTP_IPV6_V6ONLY(inp6)) 222042551e99SRandall Stewart continue; 222142551e99SRandall Stewart 222242551e99SRandall Stewart sin = (struct sockaddr_in *)&ifa->address.sa; 222342551e99SRandall Stewart if (sin->sin_addr.s_addr == 0) { 222442551e99SRandall Stewart /* we skip unspecifed addresses */ 222542551e99SRandall Stewart continue; 222642551e99SRandall Stewart } 222742551e99SRandall Stewart if (stcb->asoc.ipv4_local_scope == 0 && 222842551e99SRandall Stewart IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) { 2229c2ede4b3SMartin Blapp continue; 223042551e99SRandall Stewart } 223142551e99SRandall Stewart if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) && 223242551e99SRandall Stewart SCTP_IPV6_V6ONLY(inp6)) { 223342551e99SRandall Stewart cnt_invalid++; 223442551e99SRandall Stewart if (asc->cnt == cnt_invalid) 223542551e99SRandall Stewart return; 223642551e99SRandall Stewart else 223742551e99SRandall Stewart continue; 223842551e99SRandall Stewart } 22395e2c2d87SRandall Stewart break; 22405e2c2d87SRandall Stewart } 22415e2c2d87SRandall Stewart default: 224242551e99SRandall Stewart /* invalid address family */ 224342551e99SRandall Stewart cnt_invalid++; 224442551e99SRandall Stewart if (asc->cnt == cnt_invalid) 2245f8829a4aSRandall Stewart return; 224642551e99SRandall Stewart else 224742551e99SRandall Stewart continue; 22485e2c2d87SRandall Stewart break; 2249f8829a4aSRandall Stewart } 2250f8829a4aSRandall Stewart 225142551e99SRandall Stewart if (type == SCTP_ADD_IP_ADDRESS) { 22521b649582SRandall Stewart /* prevent this address from being used as a source */ 22531b649582SRandall Stewart sctp_add_local_addr_restricted(stcb, ifa); 225442551e99SRandall Stewart } else if (type == SCTP_DEL_IP_ADDRESS) { 2255f8829a4aSRandall Stewart struct sctp_nets *net; 2256f8829a4aSRandall Stewart 2257f8829a4aSRandall Stewart TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { 225817205eccSRandall Stewart sctp_rtentry_t *rt; 2259f8829a4aSRandall Stewart 2260f8829a4aSRandall Stewart /* delete this address if cached */ 2261851b7298SRandall Stewart if (net->ro._s_addr == ifa) { 226242551e99SRandall Stewart sctp_free_ifa(net->ro._s_addr); 226342551e99SRandall Stewart net->ro._s_addr = NULL; 226442551e99SRandall Stewart net->src_addr_selected = 0; 2265f8829a4aSRandall Stewart rt = net->ro.ro_rt; 226642551e99SRandall Stewart if (rt) { 226742551e99SRandall Stewart RTFREE(rt); 2268f8829a4aSRandall Stewart net->ro.ro_rt = NULL; 2269f8829a4aSRandall Stewart } 227042551e99SRandall Stewart /* 227142551e99SRandall Stewart * Now we deleted our src address, 227242551e99SRandall Stewart * should we not also now reset the 227342551e99SRandall Stewart * cwnd/rto to start as if its a new 227442551e99SRandall Stewart * address? 227542551e99SRandall Stewart */ 2276b54d3a6cSRandall Stewart stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net); 2277108df27cSRandall Stewart net->RTO = 0; 227842551e99SRandall Stewart 2279f8829a4aSRandall Stewart } 2280f8829a4aSRandall Stewart } 228142551e99SRandall Stewart } else if (type == SCTP_SET_PRIM_ADDR) { 228242551e99SRandall Stewart if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) { 22831b649582SRandall Stewart /* must validate the ifa is in the ep */ 228442551e99SRandall Stewart if (sctp_is_addr_in_ep(stcb->sctp_ep, ifa) == 0) { 228542551e99SRandall Stewart continue; 2286f8829a4aSRandall Stewart } 228742551e99SRandall Stewart } else { 228842551e99SRandall Stewart /* Need to check scopes for this guy */ 228942551e99SRandall Stewart if (sctp_is_address_in_scope(ifa, 229042551e99SRandall Stewart stcb->asoc.ipv4_addr_legal, 229142551e99SRandall Stewart stcb->asoc.ipv6_addr_legal, 229242551e99SRandall Stewart stcb->asoc.loopback_scope, 229342551e99SRandall Stewart stcb->asoc.ipv4_local_scope, 229442551e99SRandall Stewart stcb->asoc.local_scope, 229542551e99SRandall Stewart stcb->asoc.site_scope, 0) == 0) { 229642551e99SRandall Stewart continue; 2297f8829a4aSRandall Stewart } 229842551e99SRandall Stewart } 229942551e99SRandall Stewart } 230042551e99SRandall Stewart /* queue an asconf for this address add/delete */ 23011b649582SRandall Stewart if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF) && 23021b649582SRandall Stewart stcb->asoc.peer_supports_asconf) { 230342551e99SRandall Stewart /* queue an asconf for this addr */ 230442551e99SRandall Stewart status = sctp_asconf_queue_add(stcb, ifa, type); 230542551e99SRandall Stewart /* 23061b649582SRandall Stewart * if queued ok, and in the open state, update the 23071b649582SRandall Stewart * count of queued params. If in the non-open 23081b649582SRandall Stewart * state, these get sent when the assoc goes open. 230942551e99SRandall Stewart */ 23101b649582SRandall Stewart if (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) { 23111b649582SRandall Stewart if (status >= 0) { 23121b649582SRandall Stewart num_queued++; 231342551e99SRandall Stewart } 231442551e99SRandall Stewart } 231542551e99SRandall Stewart } 231642551e99SRandall Stewart } 23171b649582SRandall Stewart /* 23181b649582SRandall Stewart * If we have queued params in the open state, send out an ASCONF. 23191b649582SRandall Stewart */ 23201b649582SRandall Stewart if (num_queued > 0) { 23213232788eSRandall Stewart sctp_send_asconf(stcb, stcb->asoc.primary_destination, 23223232788eSRandall Stewart SCTP_ADDR_NOT_LOCKED); 23231b649582SRandall Stewart } 232442551e99SRandall Stewart } 232542551e99SRandall Stewart 232642551e99SRandall Stewart void 23271b649582SRandall Stewart sctp_asconf_iterator_end(void *ptr, uint32_t val) 232842551e99SRandall Stewart { 232942551e99SRandall Stewart struct sctp_asconf_iterator *asc; 233042551e99SRandall Stewart struct sctp_ifa *ifa; 233142551e99SRandall Stewart struct sctp_laddr *l, *l_next; 233242551e99SRandall Stewart 233342551e99SRandall Stewart asc = (struct sctp_asconf_iterator *)ptr; 233442551e99SRandall Stewart l = LIST_FIRST(&asc->list_of_work); 233542551e99SRandall Stewart while (l != NULL) { 233642551e99SRandall Stewart l_next = LIST_NEXT(l, sctp_nxt_addr); 233742551e99SRandall Stewart ifa = l->ifa; 233842551e99SRandall Stewart if (l->action == SCTP_ADD_IP_ADDRESS) { 233942551e99SRandall Stewart /* Clear the defer use flag */ 234042551e99SRandall Stewart ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE; 234142551e99SRandall Stewart } 234242551e99SRandall Stewart sctp_free_ifa(ifa); 2343b3f1ea41SRandall Stewart SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_laddr), l); 234442551e99SRandall Stewart SCTP_DECR_LADDR_COUNT(); 234542551e99SRandall Stewart l = l_next; 234642551e99SRandall Stewart } 2347207304d4SRandall Stewart SCTP_FREE(asc, SCTP_M_ASC_IT); 2348f8829a4aSRandall Stewart } 2349f8829a4aSRandall Stewart 2350f8829a4aSRandall Stewart /* 23511b649582SRandall Stewart * sa is the sockaddr to ask the peer to set primary to. 23521b649582SRandall Stewart * returns: 0 = completed, -1 = error 2353f8829a4aSRandall Stewart */ 2354c4739e2fSRandall Stewart int32_t 2355f8829a4aSRandall Stewart sctp_set_primary_ip_address_sa(struct sctp_tcb *stcb, struct sockaddr *sa) 2356f8829a4aSRandall Stewart { 23573232788eSRandall Stewart uint32_t vrf_id; 23583232788eSRandall Stewart struct sctp_ifa *ifa; 2359f8829a4aSRandall Stewart 23603232788eSRandall Stewart /* find the ifa for the desired set primary */ 23613232788eSRandall Stewart vrf_id = stcb->asoc.vrf_id; 23623232788eSRandall Stewart ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED); 23633232788eSRandall Stewart if (ifa == NULL) { 23643232788eSRandall Stewart /* Invalid address */ 23653232788eSRandall Stewart return (-1); 23663232788eSRandall Stewart } 2367f8829a4aSRandall Stewart /* queue an ASCONF:SET_PRIM_ADDR to be sent */ 23683232788eSRandall Stewart if (!sctp_asconf_queue_add(stcb, ifa, SCTP_SET_PRIM_ADDR)) { 2369f8829a4aSRandall Stewart /* set primary queuing succeeded */ 2370ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 2371ad81507eSRandall Stewart "set_primary_ip_address_sa: queued on tcb=%p, ", 2372f8829a4aSRandall Stewart stcb); 2373ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 23741b649582SRandall Stewart if (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) { 23751b649582SRandall Stewart #ifdef SCTP_TIMER_BASED_ASCONF 23761b649582SRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, 23771b649582SRandall Stewart stcb->sctp_ep, stcb, 23781b649582SRandall Stewart stcb->asoc.primary_destination); 23791b649582SRandall Stewart #else 23803232788eSRandall Stewart sctp_send_asconf(stcb, stcb->asoc.primary_destination, 23813232788eSRandall Stewart SCTP_ADDR_NOT_LOCKED); 23821b649582SRandall Stewart #endif 23831b649582SRandall Stewart } 2384f8829a4aSRandall Stewart } else { 2385ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "set_primary_ip_address_sa: failed to add to queue on tcb=%p, ", 2386f8829a4aSRandall Stewart stcb); 2387ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); 2388f8829a4aSRandall Stewart return (-1); 2389f8829a4aSRandall Stewart } 2390f8829a4aSRandall Stewart return (0); 2391f8829a4aSRandall Stewart } 2392f8829a4aSRandall Stewart 2393f8829a4aSRandall Stewart void 239442551e99SRandall Stewart sctp_set_primary_ip_address(struct sctp_ifa *ifa) 2395f8829a4aSRandall Stewart { 2396f8829a4aSRandall Stewart struct sctp_inpcb *inp; 2397f8829a4aSRandall Stewart 2398f8829a4aSRandall Stewart /* go through all our PCB's */ 2399b3f1ea41SRandall Stewart LIST_FOREACH(inp, &SCTP_BASE_INFO(listhead), sctp_list) { 2400f8829a4aSRandall Stewart struct sctp_tcb *stcb; 2401f8829a4aSRandall Stewart 2402f8829a4aSRandall Stewart /* process for all associations for this endpoint */ 2403f8829a4aSRandall Stewart LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { 2404f8829a4aSRandall Stewart /* queue an ASCONF:SET_PRIM_ADDR to be sent */ 2405f8829a4aSRandall Stewart if (!sctp_asconf_queue_add(stcb, ifa, 2406f8829a4aSRandall Stewart SCTP_SET_PRIM_ADDR)) { 2407f8829a4aSRandall Stewart /* set primary queuing succeeded */ 2408ceaad40aSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "set_primary_ip_address: queued on stcb=%p, ", 2409f8829a4aSRandall Stewart stcb); 2410ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &ifa->address.sa); 24111b649582SRandall Stewart if (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) { 24121b649582SRandall Stewart #ifdef SCTP_TIMER_BASED_ASCONF 24131b649582SRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, 24141b649582SRandall Stewart stcb->sctp_ep, stcb, 24151b649582SRandall Stewart stcb->asoc.primary_destination); 24161b649582SRandall Stewart #else 24173232788eSRandall Stewart sctp_send_asconf(stcb, stcb->asoc.primary_destination, 24183232788eSRandall Stewart SCTP_ADDR_NOT_LOCKED); 24191b649582SRandall Stewart #endif 24201b649582SRandall Stewart } 2421f8829a4aSRandall Stewart } 2422f8829a4aSRandall Stewart } /* for each stcb */ 2423f8829a4aSRandall Stewart } /* for each inp */ 2424f8829a4aSRandall Stewart } 2425f8829a4aSRandall Stewart 2426c54a18d2SRandall Stewart int 2427c54a18d2SRandall Stewart sctp_is_addr_pending(struct sctp_tcb *stcb, struct sctp_ifa *sctp_ifa) 2428c54a18d2SRandall Stewart { 2429c54a18d2SRandall Stewart struct sctp_tmit_chunk *chk, *nchk; 2430c54a18d2SRandall Stewart unsigned int offset, asconf_limit; 2431c54a18d2SRandall Stewart struct sctp_asconf_chunk *acp; 2432c54a18d2SRandall Stewart struct sctp_asconf_paramhdr *aph; 2433c54a18d2SRandall Stewart uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE]; 2434c54a18d2SRandall Stewart struct sctp_ipv6addr_param *p_addr; 2435c54a18d2SRandall Stewart int add_cnt, del_cnt; 2436c54a18d2SRandall Stewart uint16_t last_param_type; 2437c54a18d2SRandall Stewart 2438c54a18d2SRandall Stewart add_cnt = del_cnt = 0; 2439c54a18d2SRandall Stewart last_param_type = 0; 2440c54a18d2SRandall Stewart for (chk = TAILQ_FIRST(&stcb->asoc.asconf_send_queue); chk != NULL; 2441c54a18d2SRandall Stewart chk = nchk) { 2442c54a18d2SRandall Stewart /* get next chk */ 2443c54a18d2SRandall Stewart nchk = TAILQ_NEXT(chk, sctp_next); 2444c54a18d2SRandall Stewart 2445c54a18d2SRandall Stewart if (chk->data == NULL) { 2446c54a18d2SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: No mbuf data?\n"); 2447c54a18d2SRandall Stewart continue; 2448c54a18d2SRandall Stewart } 2449c54a18d2SRandall Stewart offset = 0; 2450c54a18d2SRandall Stewart acp = mtod(chk->data, struct sctp_asconf_chunk *); 2451c54a18d2SRandall Stewart offset += sizeof(struct sctp_asconf_chunk); 2452c54a18d2SRandall Stewart asconf_limit = ntohs(acp->ch.chunk_length); 2453c54a18d2SRandall Stewart p_addr = (struct sctp_ipv6addr_param *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_paramhdr), aparam_buf); 2454c54a18d2SRandall Stewart if (p_addr == NULL) { 2455c54a18d2SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: couldn't get lookup addr!\n"); 2456c54a18d2SRandall Stewart continue; 2457c54a18d2SRandall Stewart } 2458c54a18d2SRandall Stewart offset += ntohs(p_addr->ph.param_length); 2459c54a18d2SRandall Stewart 2460c54a18d2SRandall Stewart aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_asconf_paramhdr), aparam_buf); 2461c54a18d2SRandall Stewart if (aph == NULL) { 2462c54a18d2SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: Empty ASCONF will be sent?\n"); 2463c54a18d2SRandall Stewart continue; 2464c54a18d2SRandall Stewart } 2465c54a18d2SRandall Stewart while (aph != NULL) { 2466c54a18d2SRandall Stewart unsigned int param_length, param_type; 2467c54a18d2SRandall Stewart 2468c54a18d2SRandall Stewart param_type = ntohs(aph->ph.param_type); 2469c54a18d2SRandall Stewart param_length = ntohs(aph->ph.param_length); 2470c54a18d2SRandall Stewart if (offset + param_length > asconf_limit) { 2471c54a18d2SRandall Stewart /* parameter goes beyond end of chunk! */ 2472c54a18d2SRandall Stewart break; 2473c54a18d2SRandall Stewart } 2474c54a18d2SRandall Stewart if (param_length > sizeof(aparam_buf)) { 2475c54a18d2SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: param length (%u) larger than buffer size!\n", param_length); 2476c54a18d2SRandall Stewart break; 2477c54a18d2SRandall Stewart } 2478c54a18d2SRandall Stewart if (param_length <= sizeof(struct sctp_paramhdr)) { 2479c54a18d2SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: param length(%u) too short\n", param_length); 2480c54a18d2SRandall Stewart break; 2481c54a18d2SRandall Stewart } 2482c54a18d2SRandall Stewart aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, param_length, aparam_buf); 2483c54a18d2SRandall Stewart if (aph == NULL) { 2484c54a18d2SRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: couldn't get entire param\n"); 2485c54a18d2SRandall Stewart break; 2486c54a18d2SRandall Stewart } 2487c54a18d2SRandall Stewart p_addr = (struct sctp_ipv6addr_param *)(aph + 1); 2488c54a18d2SRandall Stewart if (sctp_addr_match(p_addr, &sctp_ifa->address.sa) != 0) { 2489c54a18d2SRandall Stewart switch (param_type) { 2490c54a18d2SRandall Stewart case SCTP_ADD_IP_ADDRESS: 2491c54a18d2SRandall Stewart add_cnt++; 2492c54a18d2SRandall Stewart break; 2493c54a18d2SRandall Stewart case SCTP_DEL_IP_ADDRESS: 2494c54a18d2SRandall Stewart del_cnt++; 2495c54a18d2SRandall Stewart break; 2496c54a18d2SRandall Stewart default: 2497c54a18d2SRandall Stewart break; 2498c54a18d2SRandall Stewart } 2499c54a18d2SRandall Stewart last_param_type = param_type; 2500c54a18d2SRandall Stewart } 2501c54a18d2SRandall Stewart offset += SCTP_SIZE32(param_length); 2502c54a18d2SRandall Stewart if (offset >= asconf_limit) { 2503c54a18d2SRandall Stewart /* no more data in the mbuf chain */ 2504c54a18d2SRandall Stewart break; 2505c54a18d2SRandall Stewart } 2506c54a18d2SRandall Stewart /* get pointer to next asconf param */ 2507c54a18d2SRandall Stewart aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_asconf_paramhdr), aparam_buf); 2508c54a18d2SRandall Stewart } 2509c54a18d2SRandall Stewart } 2510c54a18d2SRandall Stewart 2511c54a18d2SRandall Stewart /* 2512c54a18d2SRandall Stewart * we want to find the sequences which consist of ADD -> DEL -> ADD 2513c54a18d2SRandall Stewart * or DEL -> ADD 2514c54a18d2SRandall Stewart */ 2515c54a18d2SRandall Stewart if (add_cnt > del_cnt || 2516c54a18d2SRandall Stewart (add_cnt == del_cnt && last_param_type == SCTP_ADD_IP_ADDRESS)) { 2517c54a18d2SRandall Stewart return 1; 2518c54a18d2SRandall Stewart } 2519c54a18d2SRandall Stewart return 0; 2520c54a18d2SRandall Stewart } 2521c54a18d2SRandall Stewart 2522f8829a4aSRandall Stewart static struct sockaddr * 25233232788eSRandall Stewart sctp_find_valid_localaddr(struct sctp_tcb *stcb, int addr_locked) 2524f8829a4aSRandall Stewart { 252542551e99SRandall Stewart struct sctp_vrf *vrf = NULL; 252642551e99SRandall Stewart struct sctp_ifn *sctp_ifn; 252742551e99SRandall Stewart struct sctp_ifa *sctp_ifa; 2528f8829a4aSRandall Stewart 25293232788eSRandall Stewart if (addr_locked == SCTP_ADDR_NOT_LOCKED) 2530c99efcf6SRandall Stewart SCTP_IPI_ADDR_RLOCK(); 253142551e99SRandall Stewart vrf = sctp_find_vrf(stcb->asoc.vrf_id); 2532ad81507eSRandall Stewart if (vrf == NULL) { 25333232788eSRandall Stewart if (addr_locked == SCTP_ADDR_NOT_LOCKED) 2534c99efcf6SRandall Stewart SCTP_IPI_ADDR_RUNLOCK(); 2535ad81507eSRandall Stewart return (NULL); 2536ad81507eSRandall Stewart } 253742551e99SRandall Stewart LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) { 253842551e99SRandall Stewart if (stcb->asoc.loopback_scope == 0 && 253942551e99SRandall Stewart SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) { 2540f8829a4aSRandall Stewart /* Skip if loopback_scope not set */ 2541f8829a4aSRandall Stewart continue; 2542f8829a4aSRandall Stewart } 254342551e99SRandall Stewart LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) { 254442551e99SRandall Stewart if (sctp_ifa->address.sa.sa_family == AF_INET && 2545f8829a4aSRandall Stewart stcb->asoc.ipv4_addr_legal) { 2546f8829a4aSRandall Stewart struct sockaddr_in *sin; 2547f8829a4aSRandall Stewart 254842551e99SRandall Stewart sin = (struct sockaddr_in *)&sctp_ifa->address.sa; 2549f8829a4aSRandall Stewart if (sin->sin_addr.s_addr == 0) { 2550f8829a4aSRandall Stewart /* skip unspecifed addresses */ 2551f8829a4aSRandall Stewart continue; 2552f8829a4aSRandall Stewart } 2553f8829a4aSRandall Stewart if (stcb->asoc.ipv4_local_scope == 0 && 2554f8829a4aSRandall Stewart IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) 2555f8829a4aSRandall Stewart continue; 2556f8829a4aSRandall Stewart 2557c54a18d2SRandall Stewart if (sctp_is_addr_restricted(stcb, sctp_ifa) && 2558c54a18d2SRandall Stewart (!sctp_is_addr_pending(stcb, sctp_ifa))) 2559f8829a4aSRandall Stewart continue; 2560f8829a4aSRandall Stewart /* found a valid local v4 address to use */ 25613232788eSRandall Stewart if (addr_locked == SCTP_ADDR_NOT_LOCKED) 2562c99efcf6SRandall Stewart SCTP_IPI_ADDR_RUNLOCK(); 256342551e99SRandall Stewart return (&sctp_ifa->address.sa); 256442551e99SRandall Stewart } else if (sctp_ifa->address.sa.sa_family == AF_INET6 && 2565f8829a4aSRandall Stewart stcb->asoc.ipv6_addr_legal) { 2566f8829a4aSRandall Stewart struct sockaddr_in6 *sin6; 2567f8829a4aSRandall Stewart 256842551e99SRandall Stewart if (sctp_ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) { 2569f8829a4aSRandall Stewart continue; 257042551e99SRandall Stewart } 257142551e99SRandall Stewart sin6 = (struct sockaddr_in6 *)&sctp_ifa->address.sa; 2572f8829a4aSRandall Stewart if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { 2573f8829a4aSRandall Stewart /* we skip unspecifed addresses */ 2574f8829a4aSRandall Stewart continue; 2575f8829a4aSRandall Stewart } 2576f8829a4aSRandall Stewart if (stcb->asoc.local_scope == 0 && 2577f8829a4aSRandall Stewart IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) 2578f8829a4aSRandall Stewart continue; 2579f8829a4aSRandall Stewart if (stcb->asoc.site_scope == 0 && 2580f8829a4aSRandall Stewart IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)) 2581f8829a4aSRandall Stewart continue; 2582f8829a4aSRandall Stewart 2583c54a18d2SRandall Stewart if (sctp_is_addr_restricted(stcb, sctp_ifa) && 2584c54a18d2SRandall Stewart (!sctp_is_addr_pending(stcb, sctp_ifa))) 2585c54a18d2SRandall Stewart continue; 2586f8829a4aSRandall Stewart /* found a valid local v6 address to use */ 25873232788eSRandall Stewart if (addr_locked == SCTP_ADDR_NOT_LOCKED) 2588c99efcf6SRandall Stewart SCTP_IPI_ADDR_RUNLOCK(); 258942551e99SRandall Stewart return (&sctp_ifa->address.sa); 2590f8829a4aSRandall Stewart } 2591f8829a4aSRandall Stewart } 2592f8829a4aSRandall Stewart } 2593f8829a4aSRandall Stewart /* no valid addresses found */ 25943232788eSRandall Stewart if (addr_locked == SCTP_ADDR_NOT_LOCKED) 2595c99efcf6SRandall Stewart SCTP_IPI_ADDR_RUNLOCK(); 2596f8829a4aSRandall Stewart return (NULL); 2597f8829a4aSRandall Stewart } 2598f8829a4aSRandall Stewart 2599f8829a4aSRandall Stewart static struct sockaddr * 2600f8829a4aSRandall Stewart sctp_find_valid_localaddr_ep(struct sctp_tcb *stcb) 2601f8829a4aSRandall Stewart { 2602f8829a4aSRandall Stewart struct sctp_laddr *laddr; 2603f8829a4aSRandall Stewart 2604f8829a4aSRandall Stewart LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) { 2605f8829a4aSRandall Stewart if (laddr->ifa == NULL) { 2606f8829a4aSRandall Stewart continue; 2607f8829a4aSRandall Stewart } 2608f8829a4aSRandall Stewart /* is the address restricted ? */ 2609c54a18d2SRandall Stewart if (sctp_is_addr_restricted(stcb, laddr->ifa) && 2610c54a18d2SRandall Stewart (!sctp_is_addr_pending(stcb, laddr->ifa))) 2611f8829a4aSRandall Stewart continue; 2612f8829a4aSRandall Stewart 2613f8829a4aSRandall Stewart /* found a valid local address to use */ 261442551e99SRandall Stewart return (&laddr->ifa->address.sa); 2615f8829a4aSRandall Stewart } 2616f8829a4aSRandall Stewart /* no valid addresses found */ 2617f8829a4aSRandall Stewart return (NULL); 2618f8829a4aSRandall Stewart } 2619f8829a4aSRandall Stewart 2620f8829a4aSRandall Stewart /* 262118e198d3SRandall Stewart * builds an ASCONF chunk from queued ASCONF params. 262218e198d3SRandall Stewart * returns NULL on error (no mbuf, no ASCONF params queued, etc). 2623f8829a4aSRandall Stewart */ 2624f8829a4aSRandall Stewart struct mbuf * 26253232788eSRandall Stewart sctp_compose_asconf(struct sctp_tcb *stcb, int *retlen, int addr_locked) 2626f8829a4aSRandall Stewart { 2627f8829a4aSRandall Stewart struct mbuf *m_asconf, *m_asconf_chk; 2628f8829a4aSRandall Stewart struct sctp_asconf_addr *aa; 2629f8829a4aSRandall Stewart struct sctp_asconf_chunk *acp; 2630f8829a4aSRandall Stewart struct sctp_asconf_paramhdr *aph; 2631f8829a4aSRandall Stewart struct sctp_asconf_addr_param *aap; 2632f8829a4aSRandall Stewart uint32_t p_length; 2633f8829a4aSRandall Stewart uint32_t correlation_id = 1; /* 0 is reserved... */ 2634f8829a4aSRandall Stewart caddr_t ptr, lookup_ptr; 2635f8829a4aSRandall Stewart uint8_t lookup_used = 0; 2636f8829a4aSRandall Stewart 2637f8829a4aSRandall Stewart /* are there any asconf params to send? */ 2638c54a18d2SRandall Stewart TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) { 2639c54a18d2SRandall Stewart if (aa->sent == 0) 2640c54a18d2SRandall Stewart break; 2641f8829a4aSRandall Stewart } 2642c54a18d2SRandall Stewart if (aa == NULL) 26431b649582SRandall Stewart return (NULL); 2644c54a18d2SRandall Stewart 2645f8829a4aSRandall Stewart /* 2646f8829a4aSRandall Stewart * get a chunk header mbuf and a cluster for the asconf params since 2647f8829a4aSRandall Stewart * it's simpler to fill in the asconf chunk header lookup address on 2648f8829a4aSRandall Stewart * the fly 2649f8829a4aSRandall Stewart */ 2650139bc87fSRandall Stewart m_asconf_chk = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_chunk), 0, M_DONTWAIT, 1, MT_DATA); 2651f8829a4aSRandall Stewart if (m_asconf_chk == NULL) { 2652f8829a4aSRandall Stewart /* no mbuf's */ 2653ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 2654ad81507eSRandall Stewart "compose_asconf: couldn't get chunk mbuf!\n"); 2655f8829a4aSRandall Stewart return (NULL); 2656f8829a4aSRandall Stewart } 2657139bc87fSRandall Stewart m_asconf = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_DONTWAIT, 1, MT_DATA); 2658f8829a4aSRandall Stewart if (m_asconf == NULL) { 2659f8829a4aSRandall Stewart /* no mbuf's */ 2660ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 2661ad81507eSRandall Stewart "compose_asconf: couldn't get mbuf!\n"); 2662f8829a4aSRandall Stewart sctp_m_freem(m_asconf_chk); 2663f8829a4aSRandall Stewart return (NULL); 2664f8829a4aSRandall Stewart } 2665139bc87fSRandall Stewart SCTP_BUF_LEN(m_asconf_chk) = sizeof(struct sctp_asconf_chunk); 2666139bc87fSRandall Stewart SCTP_BUF_LEN(m_asconf) = 0; 2667f8829a4aSRandall Stewart acp = mtod(m_asconf_chk, struct sctp_asconf_chunk *); 2668f8829a4aSRandall Stewart bzero(acp, sizeof(struct sctp_asconf_chunk)); 2669f8829a4aSRandall Stewart /* save pointers to lookup address and asconf params */ 2670f8829a4aSRandall Stewart lookup_ptr = (caddr_t)(acp + 1); /* after the header */ 2671f8829a4aSRandall Stewart ptr = mtod(m_asconf, caddr_t); /* beginning of cluster */ 2672f8829a4aSRandall Stewart 2673f8829a4aSRandall Stewart /* fill in chunk header info */ 2674f8829a4aSRandall Stewart acp->ch.chunk_type = SCTP_ASCONF; 2675f8829a4aSRandall Stewart acp->ch.chunk_flags = 0; 2676f8829a4aSRandall Stewart acp->serial_number = htonl(stcb->asoc.asconf_seq_out); 2677c54a18d2SRandall Stewart stcb->asoc.asconf_seq_out++; 2678f8829a4aSRandall Stewart 2679f8829a4aSRandall Stewart /* add parameters... up to smallest MTU allowed */ 2680f8829a4aSRandall Stewart TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) { 2681c54a18d2SRandall Stewart if (aa->sent) 2682c54a18d2SRandall Stewart continue; 2683f8829a4aSRandall Stewart /* get the parameter length */ 2684f8829a4aSRandall Stewart p_length = SCTP_SIZE32(aa->ap.aph.ph.param_length); 2685f8829a4aSRandall Stewart /* will it fit in current chunk? */ 2686139bc87fSRandall Stewart if (SCTP_BUF_LEN(m_asconf) + p_length > stcb->asoc.smallest_mtu) { 2687f8829a4aSRandall Stewart /* won't fit, so we're done with this chunk */ 2688f8829a4aSRandall Stewart break; 2689f8829a4aSRandall Stewart } 2690f8829a4aSRandall Stewart /* assign (and store) a correlation id */ 2691f8829a4aSRandall Stewart aa->ap.aph.correlation_id = correlation_id++; 2692f8829a4aSRandall Stewart 2693f8829a4aSRandall Stewart /* 2694f8829a4aSRandall Stewart * fill in address if we're doing a delete this is a simple 2695f8829a4aSRandall Stewart * way for us to fill in the correlation address, which 2696f8829a4aSRandall Stewart * should only be used by the peer if we're deleting our 2697f8829a4aSRandall Stewart * source address and adding a new address (e.g. renumbering 2698f8829a4aSRandall Stewart * case) 2699f8829a4aSRandall Stewart */ 2700f8829a4aSRandall Stewart if (lookup_used == 0 && 2701830d754dSRandall Stewart (aa->special_del == 0) && 2702f8829a4aSRandall Stewart aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) { 2703f8829a4aSRandall Stewart struct sctp_ipv6addr_param *lookup; 2704f8829a4aSRandall Stewart uint16_t p_size, addr_size; 2705f8829a4aSRandall Stewart 2706f8829a4aSRandall Stewart lookup = (struct sctp_ipv6addr_param *)lookup_ptr; 2707f8829a4aSRandall Stewart lookup->ph.param_type = 2708f8829a4aSRandall Stewart htons(aa->ap.addrp.ph.param_type); 2709f8829a4aSRandall Stewart if (aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) { 2710f8829a4aSRandall Stewart /* copy IPv6 address */ 2711f8829a4aSRandall Stewart p_size = sizeof(struct sctp_ipv6addr_param); 2712f8829a4aSRandall Stewart addr_size = sizeof(struct in6_addr); 2713f8829a4aSRandall Stewart } else { 2714f8829a4aSRandall Stewart /* copy IPv4 address */ 2715f8829a4aSRandall Stewart p_size = sizeof(struct sctp_ipv4addr_param); 2716f8829a4aSRandall Stewart addr_size = sizeof(struct in_addr); 2717f8829a4aSRandall Stewart } 2718f8829a4aSRandall Stewart lookup->ph.param_length = htons(SCTP_SIZE32(p_size)); 2719f8829a4aSRandall Stewart memcpy(lookup->addr, &aa->ap.addrp.addr, addr_size); 2720139bc87fSRandall Stewart SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size); 2721f8829a4aSRandall Stewart lookup_used = 1; 2722f8829a4aSRandall Stewart } 2723f8829a4aSRandall Stewart /* copy into current space */ 2724f8829a4aSRandall Stewart memcpy(ptr, &aa->ap, p_length); 2725f8829a4aSRandall Stewart 2726f8829a4aSRandall Stewart /* network elements and update lengths */ 2727f8829a4aSRandall Stewart aph = (struct sctp_asconf_paramhdr *)ptr; 2728f8829a4aSRandall Stewart aap = (struct sctp_asconf_addr_param *)ptr; 2729f8829a4aSRandall Stewart /* correlation_id is transparent to peer, no htonl needed */ 2730f8829a4aSRandall Stewart aph->ph.param_type = htons(aph->ph.param_type); 2731f8829a4aSRandall Stewart aph->ph.param_length = htons(aph->ph.param_length); 2732f8829a4aSRandall Stewart aap->addrp.ph.param_type = htons(aap->addrp.ph.param_type); 2733f8829a4aSRandall Stewart aap->addrp.ph.param_length = htons(aap->addrp.ph.param_length); 2734f8829a4aSRandall Stewart 2735139bc87fSRandall Stewart SCTP_BUF_LEN(m_asconf) += SCTP_SIZE32(p_length); 2736f8829a4aSRandall Stewart ptr += SCTP_SIZE32(p_length); 2737f8829a4aSRandall Stewart 2738f8829a4aSRandall Stewart /* 2739f8829a4aSRandall Stewart * these params are removed off the pending list upon 2740f8829a4aSRandall Stewart * getting an ASCONF-ACK back from the peer, just set flag 2741f8829a4aSRandall Stewart */ 2742f8829a4aSRandall Stewart aa->sent = 1; 2743f8829a4aSRandall Stewart } 2744f8829a4aSRandall Stewart /* check to see if the lookup addr has been populated yet */ 2745f8829a4aSRandall Stewart if (lookup_used == 0) { 2746f8829a4aSRandall Stewart /* NOTE: if the address param is optional, can skip this... */ 2747f8829a4aSRandall Stewart /* add any valid (existing) address... */ 2748f8829a4aSRandall Stewart struct sctp_ipv6addr_param *lookup; 2749f8829a4aSRandall Stewart uint16_t p_size, addr_size; 2750f8829a4aSRandall Stewart struct sockaddr *found_addr; 2751f8829a4aSRandall Stewart caddr_t addr_ptr; 2752f8829a4aSRandall Stewart 2753f8829a4aSRandall Stewart if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) 27543232788eSRandall Stewart found_addr = sctp_find_valid_localaddr(stcb, 27553232788eSRandall Stewart addr_locked); 2756f8829a4aSRandall Stewart else 2757f8829a4aSRandall Stewart found_addr = sctp_find_valid_localaddr_ep(stcb); 2758f8829a4aSRandall Stewart 2759f8829a4aSRandall Stewart lookup = (struct sctp_ipv6addr_param *)lookup_ptr; 2760f8829a4aSRandall Stewart if (found_addr != NULL) { 2761f8829a4aSRandall Stewart if (found_addr->sa_family == AF_INET6) { 2762f8829a4aSRandall Stewart /* copy IPv6 address */ 2763f8829a4aSRandall Stewart lookup->ph.param_type = 2764f8829a4aSRandall Stewart htons(SCTP_IPV6_ADDRESS); 2765f8829a4aSRandall Stewart p_size = sizeof(struct sctp_ipv6addr_param); 2766f8829a4aSRandall Stewart addr_size = sizeof(struct in6_addr); 2767f8829a4aSRandall Stewart addr_ptr = (caddr_t)&((struct sockaddr_in6 *) 2768f8829a4aSRandall Stewart found_addr)->sin6_addr; 2769f8829a4aSRandall Stewart } else { 2770f8829a4aSRandall Stewart /* copy IPv4 address */ 2771f8829a4aSRandall Stewart lookup->ph.param_type = 2772f8829a4aSRandall Stewart htons(SCTP_IPV4_ADDRESS); 2773f8829a4aSRandall Stewart p_size = sizeof(struct sctp_ipv4addr_param); 2774f8829a4aSRandall Stewart addr_size = sizeof(struct in_addr); 2775f8829a4aSRandall Stewart addr_ptr = (caddr_t)&((struct sockaddr_in *) 2776f8829a4aSRandall Stewart found_addr)->sin_addr; 2777f8829a4aSRandall Stewart } 2778f8829a4aSRandall Stewart lookup->ph.param_length = htons(SCTP_SIZE32(p_size)); 2779f8829a4aSRandall Stewart memcpy(lookup->addr, addr_ptr, addr_size); 2780139bc87fSRandall Stewart SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size); 2781f8829a4aSRandall Stewart lookup_used = 1; 2782f8829a4aSRandall Stewart } else { 2783f8829a4aSRandall Stewart /* uh oh... don't have any address?? */ 2784ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 2785ad81507eSRandall Stewart "compose_asconf: no lookup addr!\n"); 2786f8829a4aSRandall Stewart /* for now, we send a IPv4 address of 0.0.0.0 */ 2787f8829a4aSRandall Stewart lookup->ph.param_type = htons(SCTP_IPV4_ADDRESS); 2788f8829a4aSRandall Stewart lookup->ph.param_length = htons(SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param))); 2789f8829a4aSRandall Stewart bzero(lookup->addr, sizeof(struct in_addr)); 2790139bc87fSRandall Stewart SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param)); 2791f8829a4aSRandall Stewart lookup_used = 1; 2792f8829a4aSRandall Stewart } 2793f8829a4aSRandall Stewart } 2794f8829a4aSRandall Stewart /* chain it all together */ 2795139bc87fSRandall Stewart SCTP_BUF_NEXT(m_asconf_chk) = m_asconf; 27963c503c28SRandall Stewart *retlen = SCTP_BUF_LEN(m_asconf_chk) + SCTP_BUF_LEN(m_asconf); 27973c503c28SRandall Stewart acp->ch.chunk_length = ntohs(*retlen); 2798f8829a4aSRandall Stewart 2799f8829a4aSRandall Stewart return (m_asconf_chk); 2800f8829a4aSRandall Stewart } 2801f8829a4aSRandall Stewart 2802f8829a4aSRandall Stewart /* 2803f8829a4aSRandall Stewart * section to handle address changes before an association is up eg. changes 2804f8829a4aSRandall Stewart * during INIT/INIT-ACK/COOKIE-ECHO handshake 2805f8829a4aSRandall Stewart */ 2806f8829a4aSRandall Stewart 2807f8829a4aSRandall Stewart /* 2808f8829a4aSRandall Stewart * processes the (local) addresses in the INIT-ACK chunk 2809f8829a4aSRandall Stewart */ 2810f8829a4aSRandall Stewart static void 2811f8829a4aSRandall Stewart sctp_process_initack_addresses(struct sctp_tcb *stcb, struct mbuf *m, 2812f8829a4aSRandall Stewart unsigned int offset, unsigned int length) 2813f8829a4aSRandall Stewart { 2814f8829a4aSRandall Stewart struct sctp_paramhdr tmp_param, *ph; 2815f8829a4aSRandall Stewart uint16_t plen, ptype; 281642551e99SRandall Stewart struct sctp_ifa *sctp_ifa; 2817f8829a4aSRandall Stewart struct sctp_ipv6addr_param addr_store; 2818f8829a4aSRandall Stewart struct sockaddr_in6 sin6; 2819f8829a4aSRandall Stewart struct sockaddr_in sin; 2820f8829a4aSRandall Stewart struct sockaddr *sa; 282142551e99SRandall Stewart uint32_t vrf_id; 2822f8829a4aSRandall Stewart 2823ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF2, "processing init-ack addresses\n"); 2824ad81507eSRandall Stewart if (stcb == NULL) /* Un-needed check for SA */ 2825ad81507eSRandall Stewart return; 2826f8829a4aSRandall Stewart 2827f8829a4aSRandall Stewart /* convert to upper bound */ 2828f8829a4aSRandall Stewart length += offset; 2829f8829a4aSRandall Stewart 2830f8829a4aSRandall Stewart if ((offset + sizeof(struct sctp_paramhdr)) > length) { 2831f8829a4aSRandall Stewart return; 2832f8829a4aSRandall Stewart } 2833f8829a4aSRandall Stewart /* init the addresses */ 2834f8829a4aSRandall Stewart bzero(&sin6, sizeof(sin6)); 2835f8829a4aSRandall Stewart sin6.sin6_family = AF_INET6; 2836f8829a4aSRandall Stewart sin6.sin6_len = sizeof(sin6); 2837f8829a4aSRandall Stewart sin6.sin6_port = stcb->rport; 2838f8829a4aSRandall Stewart 2839f8829a4aSRandall Stewart bzero(&sin, sizeof(sin)); 2840f8829a4aSRandall Stewart sin.sin_len = sizeof(sin); 2841f8829a4aSRandall Stewart sin.sin_family = AF_INET; 2842f8829a4aSRandall Stewart sin.sin_port = stcb->rport; 2843f8829a4aSRandall Stewart 2844f8829a4aSRandall Stewart /* go through the addresses in the init-ack */ 2845f8829a4aSRandall Stewart ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset, 2846f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr), (uint8_t *) & tmp_param); 2847f8829a4aSRandall Stewart while (ph != NULL) { 2848f8829a4aSRandall Stewart ptype = ntohs(ph->param_type); 2849f8829a4aSRandall Stewart plen = ntohs(ph->param_length); 2850f8829a4aSRandall Stewart if (ptype == SCTP_IPV6_ADDRESS) { 2851f8829a4aSRandall Stewart struct sctp_ipv6addr_param *a6p; 2852f8829a4aSRandall Stewart 2853f8829a4aSRandall Stewart /* get the entire IPv6 address param */ 2854f8829a4aSRandall Stewart a6p = (struct sctp_ipv6addr_param *) 2855f8829a4aSRandall Stewart sctp_m_getptr(m, offset, 2856f8829a4aSRandall Stewart sizeof(struct sctp_ipv6addr_param), 2857f8829a4aSRandall Stewart (uint8_t *) & addr_store); 2858f8829a4aSRandall Stewart if (plen != sizeof(struct sctp_ipv6addr_param) || 2859f8829a4aSRandall Stewart a6p == NULL) { 2860f8829a4aSRandall Stewart return; 2861f8829a4aSRandall Stewart } 2862f8829a4aSRandall Stewart memcpy(&sin6.sin6_addr, a6p->addr, 2863f8829a4aSRandall Stewart sizeof(struct in6_addr)); 2864f8829a4aSRandall Stewart sa = (struct sockaddr *)&sin6; 2865f8829a4aSRandall Stewart } else if (ptype == SCTP_IPV4_ADDRESS) { 2866f8829a4aSRandall Stewart struct sctp_ipv4addr_param *a4p; 2867f8829a4aSRandall Stewart 2868f8829a4aSRandall Stewart /* get the entire IPv4 address param */ 286942551e99SRandall Stewart a4p = (struct sctp_ipv4addr_param *)sctp_m_getptr(m, offset, 287042551e99SRandall Stewart sizeof(struct sctp_ipv4addr_param), 287142551e99SRandall Stewart (uint8_t *) & addr_store); 2872f8829a4aSRandall Stewart if (plen != sizeof(struct sctp_ipv4addr_param) || 2873f8829a4aSRandall Stewart a4p == NULL) { 2874f8829a4aSRandall Stewart return; 2875f8829a4aSRandall Stewart } 2876f8829a4aSRandall Stewart sin.sin_addr.s_addr = a4p->addr; 2877f8829a4aSRandall Stewart sa = (struct sockaddr *)&sin; 2878f8829a4aSRandall Stewart } else { 2879f8829a4aSRandall Stewart goto next_addr; 2880f8829a4aSRandall Stewart } 2881f8829a4aSRandall Stewart 2882f8829a4aSRandall Stewart /* see if this address really (still) exists */ 2883bff64a4dSRandall Stewart if (stcb) { 2884bff64a4dSRandall Stewart vrf_id = stcb->asoc.vrf_id; 2885bff64a4dSRandall Stewart } else { 288642551e99SRandall Stewart vrf_id = SCTP_DEFAULT_VRFID; 2887bff64a4dSRandall Stewart } 28883232788eSRandall Stewart sctp_ifa = sctp_find_ifa_by_addr(sa, vrf_id, 28893232788eSRandall Stewart SCTP_ADDR_NOT_LOCKED); 289042551e99SRandall Stewart if (sctp_ifa == NULL) { 2891f8829a4aSRandall Stewart /* address doesn't exist anymore */ 2892f8829a4aSRandall Stewart int status; 2893f8829a4aSRandall Stewart 2894f8829a4aSRandall Stewart /* are ASCONFs allowed ? */ 2895f8829a4aSRandall Stewart if ((sctp_is_feature_on(stcb->sctp_ep, 2896f8829a4aSRandall Stewart SCTP_PCB_FLAGS_DO_ASCONF)) && 2897f8829a4aSRandall Stewart stcb->asoc.peer_supports_asconf) { 2898f8829a4aSRandall Stewart /* queue an ASCONF DEL_IP_ADDRESS */ 28993232788eSRandall Stewart status = sctp_asconf_queue_sa_delete(stcb, sa); 2900f8829a4aSRandall Stewart /* 29011b649582SRandall Stewart * if queued ok, and in correct state, send 29021b649582SRandall Stewart * out the ASCONF. 2903f8829a4aSRandall Stewart */ 2904f8829a4aSRandall Stewart if (status == 0 && 2905f8829a4aSRandall Stewart SCTP_GET_STATE(&stcb->asoc) == 2906f8829a4aSRandall Stewart SCTP_STATE_OPEN) { 29071b649582SRandall Stewart #ifdef SCTP_TIMER_BASED_ASCONF 2908f8829a4aSRandall Stewart sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, 2909f8829a4aSRandall Stewart stcb->sctp_ep, stcb, 2910f8829a4aSRandall Stewart stcb->asoc.primary_destination); 29111b649582SRandall Stewart #else 29123232788eSRandall Stewart sctp_send_asconf(stcb, stcb->asoc.primary_destination, 29133232788eSRandall Stewart SCTP_ADDR_NOT_LOCKED); 29141b649582SRandall Stewart #endif 2915f8829a4aSRandall Stewart } 2916f8829a4aSRandall Stewart } 2917f8829a4aSRandall Stewart } 2918f8829a4aSRandall Stewart next_addr: 2919f8829a4aSRandall Stewart /* 2920f8829a4aSRandall Stewart * Sanity check: Make sure the length isn't 0, otherwise 2921f8829a4aSRandall Stewart * we'll be stuck in this loop for a long time... 2922f8829a4aSRandall Stewart */ 2923f8829a4aSRandall Stewart if (SCTP_SIZE32(plen) == 0) { 2924ad81507eSRandall Stewart SCTP_PRINTF("process_initack_addrs: bad len (%d) type=%xh\n", 2925f8829a4aSRandall Stewart plen, ptype); 2926f8829a4aSRandall Stewart return; 2927f8829a4aSRandall Stewart } 2928f8829a4aSRandall Stewart /* get next parameter */ 2929f8829a4aSRandall Stewart offset += SCTP_SIZE32(plen); 2930f8829a4aSRandall Stewart if ((offset + sizeof(struct sctp_paramhdr)) > length) 2931f8829a4aSRandall Stewart return; 2932f8829a4aSRandall Stewart ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset, 2933f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr), (uint8_t *) & tmp_param); 2934f8829a4aSRandall Stewart } /* while */ 2935f8829a4aSRandall Stewart } 2936f8829a4aSRandall Stewart 2937f8829a4aSRandall Stewart /* FIX ME: need to verify return result for v6 address type if v6 disabled */ 2938f8829a4aSRandall Stewart /* 2939f8829a4aSRandall Stewart * checks to see if a specific address is in the initack address list returns 2940f8829a4aSRandall Stewart * 1 if found, 0 if not 2941f8829a4aSRandall Stewart */ 2942f8829a4aSRandall Stewart static uint32_t 2943f8829a4aSRandall Stewart sctp_addr_in_initack(struct sctp_tcb *stcb, struct mbuf *m, uint32_t offset, 2944f8829a4aSRandall Stewart uint32_t length, struct sockaddr *sa) 2945f8829a4aSRandall Stewart { 2946f8829a4aSRandall Stewart struct sctp_paramhdr tmp_param, *ph; 2947f8829a4aSRandall Stewart uint16_t plen, ptype; 2948f8829a4aSRandall Stewart struct sctp_ipv6addr_param addr_store; 2949f8829a4aSRandall Stewart struct sockaddr_in *sin; 2950f8829a4aSRandall Stewart struct sctp_ipv4addr_param *a4p; 2951f8829a4aSRandall Stewart 2952f8829a4aSRandall Stewart #ifdef INET6 295342551e99SRandall Stewart struct sockaddr_in6 *sin6; 2954f8829a4aSRandall Stewart struct sctp_ipv6addr_param *a6p; 295542551e99SRandall Stewart struct sockaddr_in6 sin6_tmp; 2956f8829a4aSRandall Stewart 2957f8829a4aSRandall Stewart #endif /* INET6 */ 2958f8829a4aSRandall Stewart 2959f8829a4aSRandall Stewart if ( 2960f8829a4aSRandall Stewart #ifdef INET6 2961f8829a4aSRandall Stewart (sa->sa_family != AF_INET6) && 2962f8829a4aSRandall Stewart #endif /* INET6 */ 2963f8829a4aSRandall Stewart (sa->sa_family != AF_INET)) 2964f8829a4aSRandall Stewart return (0); 2965f8829a4aSRandall Stewart 2966ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF2, "find_initack_addr: starting search for "); 2967ad81507eSRandall Stewart SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, sa); 2968f8829a4aSRandall Stewart /* convert to upper bound */ 2969f8829a4aSRandall Stewart length += offset; 2970f8829a4aSRandall Stewart 2971f8829a4aSRandall Stewart if ((offset + sizeof(struct sctp_paramhdr)) > length) { 2972ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 2973ad81507eSRandall Stewart "find_initack_addr: invalid offset?\n"); 2974f8829a4aSRandall Stewart return (0); 2975f8829a4aSRandall Stewart } 2976f8829a4aSRandall Stewart /* go through the addresses in the init-ack */ 2977f8829a4aSRandall Stewart ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset, 2978f8829a4aSRandall Stewart sizeof(struct sctp_paramhdr), (uint8_t *) & tmp_param); 2979f8829a4aSRandall Stewart while (ph != NULL) { 2980f8829a4aSRandall Stewart ptype = ntohs(ph->param_type); 2981f8829a4aSRandall Stewart plen = ntohs(ph->param_length); 2982f8829a4aSRandall Stewart #ifdef INET6 2983f8829a4aSRandall Stewart if (ptype == SCTP_IPV6_ADDRESS && sa->sa_family == AF_INET6) { 2984f8829a4aSRandall Stewart /* get the entire IPv6 address param */ 2985f8829a4aSRandall Stewart a6p = (struct sctp_ipv6addr_param *) 2986f8829a4aSRandall Stewart sctp_m_getptr(m, offset, 2987f8829a4aSRandall Stewart sizeof(struct sctp_ipv6addr_param), 2988f8829a4aSRandall Stewart (uint8_t *) & addr_store); 2989f8829a4aSRandall Stewart if (plen != sizeof(struct sctp_ipv6addr_param) || 2990ad81507eSRandall Stewart (ph == NULL) || 2991ad81507eSRandall Stewart (a6p == NULL)) { 2992f8829a4aSRandall Stewart return (0); 2993f8829a4aSRandall Stewart } 2994f8829a4aSRandall Stewart sin6 = (struct sockaddr_in6 *)sa; 2995f8829a4aSRandall Stewart if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr)) { 2996f8829a4aSRandall Stewart /* create a copy and clear scope */ 2997f8829a4aSRandall Stewart memcpy(&sin6_tmp, sin6, 2998f8829a4aSRandall Stewart sizeof(struct sockaddr_in6)); 2999f8829a4aSRandall Stewart sin6 = &sin6_tmp; 3000f8829a4aSRandall Stewart in6_clearscope(&sin6->sin6_addr); 3001f8829a4aSRandall Stewart } 3002f8829a4aSRandall Stewart if (memcmp(&sin6->sin6_addr, a6p->addr, 3003f8829a4aSRandall Stewart sizeof(struct in6_addr)) == 0) { 3004f8829a4aSRandall Stewart /* found it */ 3005f8829a4aSRandall Stewart return (1); 3006f8829a4aSRandall Stewart } 3007f8829a4aSRandall Stewart } else 3008f8829a4aSRandall Stewart #endif /* INET6 */ 3009f8829a4aSRandall Stewart 3010f8829a4aSRandall Stewart if (ptype == SCTP_IPV4_ADDRESS && 3011f8829a4aSRandall Stewart sa->sa_family == AF_INET) { 3012f8829a4aSRandall Stewart /* get the entire IPv4 address param */ 3013f8829a4aSRandall Stewart a4p = (struct sctp_ipv4addr_param *)sctp_m_getptr(m, 3014f8829a4aSRandall Stewart offset, sizeof(struct sctp_ipv4addr_param), 3015f8829a4aSRandall Stewart (uint8_t *) & addr_store); 3016f8829a4aSRandall Stewart if (plen != sizeof(struct sctp_ipv4addr_param) || 3017ad81507eSRandall Stewart (ph == NULL) || 3018ad81507eSRandall Stewart (a4p == NULL)) { 3019f8829a4aSRandall Stewart return (0); 3020f8829a4aSRandall Stewart } 3021f8829a4aSRandall Stewart sin = (struct sockaddr_in *)sa; 3022f8829a4aSRandall Stewart if (sin->sin_addr.s_addr == a4p->addr) { 3023f8829a4aSRandall Stewart /* found it */ 3024f8829a4aSRandall Stewart return (1); 3025f8829a4aSRandall Stewart } 3026f8829a4aSRandall Stewart } 3027f8829a4aSRandall Stewart /* get next parameter */ 3028f8829a4aSRandall Stewart offset += SCTP_SIZE32(plen); 3029f8829a4aSRandall Stewart if (offset + sizeof(struct sctp_paramhdr) > length) 3030f8829a4aSRandall Stewart return (0); 3031f8829a4aSRandall Stewart ph = (struct sctp_paramhdr *) 3032f8829a4aSRandall Stewart sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), 3033f8829a4aSRandall Stewart (uint8_t *) & tmp_param); 3034f8829a4aSRandall Stewart } /* while */ 3035f8829a4aSRandall Stewart /* not found! */ 3036f8829a4aSRandall Stewart return (0); 3037f8829a4aSRandall Stewart } 3038f8829a4aSRandall Stewart 3039f8829a4aSRandall Stewart /* 3040f8829a4aSRandall Stewart * makes sure that the current endpoint local addr list is consistent with 3041f8829a4aSRandall Stewart * the new association (eg. subset bound, asconf allowed) adds addresses as 3042f8829a4aSRandall Stewart * necessary 3043f8829a4aSRandall Stewart */ 3044f8829a4aSRandall Stewart static void 3045f8829a4aSRandall Stewart sctp_check_address_list_ep(struct sctp_tcb *stcb, struct mbuf *m, int offset, 3046f8829a4aSRandall Stewart int length, struct sockaddr *init_addr) 3047f8829a4aSRandall Stewart { 3048f8829a4aSRandall Stewart struct sctp_laddr *laddr; 3049f8829a4aSRandall Stewart 3050f8829a4aSRandall Stewart /* go through the endpoint list */ 3051f8829a4aSRandall Stewart LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) { 3052f8829a4aSRandall Stewart /* be paranoid and validate the laddr */ 3053f8829a4aSRandall Stewart if (laddr->ifa == NULL) { 3054ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 3055ad81507eSRandall Stewart "check_addr_list_ep: laddr->ifa is NULL"); 3056f8829a4aSRandall Stewart continue; 3057f8829a4aSRandall Stewart } 305842551e99SRandall Stewart if (laddr->ifa == NULL) { 3059ad81507eSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "check_addr_list_ep: laddr->ifa->ifa_addr is NULL"); 3060f8829a4aSRandall Stewart continue; 3061f8829a4aSRandall Stewart } 3062f8829a4aSRandall Stewart /* do i have it implicitly? */ 306342551e99SRandall Stewart if (sctp_cmpaddr(&laddr->ifa->address.sa, init_addr)) { 3064f8829a4aSRandall Stewart continue; 3065f8829a4aSRandall Stewart } 3066f8829a4aSRandall Stewart /* check to see if in the init-ack */ 3067f8829a4aSRandall Stewart if (!sctp_addr_in_initack(stcb, m, offset, length, 306842551e99SRandall Stewart &laddr->ifa->address.sa)) { 3069f8829a4aSRandall Stewart /* try to add it */ 3070f8829a4aSRandall Stewart sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb, laddr->ifa, 30713232788eSRandall Stewart SCTP_ADD_IP_ADDRESS, SCTP_ADDR_NOT_LOCKED); 3072f8829a4aSRandall Stewart } 3073f8829a4aSRandall Stewart } 3074f8829a4aSRandall Stewart } 3075f8829a4aSRandall Stewart 3076f8829a4aSRandall Stewart /* 3077f8829a4aSRandall Stewart * makes sure that the current kernel address list is consistent with the new 3078f8829a4aSRandall Stewart * association (with all addrs bound) adds addresses as necessary 3079f8829a4aSRandall Stewart */ 3080f8829a4aSRandall Stewart static void 3081f8829a4aSRandall Stewart sctp_check_address_list_all(struct sctp_tcb *stcb, struct mbuf *m, int offset, 3082f8829a4aSRandall Stewart int length, struct sockaddr *init_addr, 3083f8829a4aSRandall Stewart uint16_t local_scope, uint16_t site_scope, 3084f8829a4aSRandall Stewart uint16_t ipv4_scope, uint16_t loopback_scope) 3085f8829a4aSRandall Stewart { 308642551e99SRandall Stewart struct sctp_vrf *vrf = NULL; 308742551e99SRandall Stewart struct sctp_ifn *sctp_ifn; 308842551e99SRandall Stewart struct sctp_ifa *sctp_ifa; 308942551e99SRandall Stewart uint32_t vrf_id; 3090f8829a4aSRandall Stewart 3091bff64a4dSRandall Stewart if (stcb) { 3092bff64a4dSRandall Stewart vrf_id = stcb->asoc.vrf_id; 3093bff64a4dSRandall Stewart } else { 3094ad81507eSRandall Stewart return; 3095bff64a4dSRandall Stewart } 3096c99efcf6SRandall Stewart SCTP_IPI_ADDR_RLOCK(); 309742551e99SRandall Stewart vrf = sctp_find_vrf(vrf_id); 309842551e99SRandall Stewart if (vrf == NULL) { 3099c99efcf6SRandall Stewart SCTP_IPI_ADDR_RUNLOCK(); 310042551e99SRandall Stewart return; 310142551e99SRandall Stewart } 3102f8829a4aSRandall Stewart /* go through all our known interfaces */ 310342551e99SRandall Stewart LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) { 310442551e99SRandall Stewart if (loopback_scope == 0 && SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) { 3105f8829a4aSRandall Stewart /* skip loopback interface */ 3106f8829a4aSRandall Stewart continue; 3107f8829a4aSRandall Stewart } 3108f8829a4aSRandall Stewart /* go through each interface address */ 310942551e99SRandall Stewart LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) { 3110f8829a4aSRandall Stewart /* do i have it implicitly? */ 311142551e99SRandall Stewart if (sctp_cmpaddr(&sctp_ifa->address.sa, init_addr)) { 3112f8829a4aSRandall Stewart continue; 3113f8829a4aSRandall Stewart } 3114f8829a4aSRandall Stewart /* check to see if in the init-ack */ 3115f8829a4aSRandall Stewart if (!sctp_addr_in_initack(stcb, m, offset, length, 311642551e99SRandall Stewart &sctp_ifa->address.sa)) { 3117f8829a4aSRandall Stewart /* try to add it */ 3118f8829a4aSRandall Stewart sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb, 31193232788eSRandall Stewart sctp_ifa, SCTP_ADD_IP_ADDRESS, 31203232788eSRandall Stewart SCTP_ADDR_LOCKED); 3121f8829a4aSRandall Stewart } 3122f8829a4aSRandall Stewart } /* end foreach ifa */ 3123f8829a4aSRandall Stewart } /* end foreach ifn */ 3124c99efcf6SRandall Stewart SCTP_IPI_ADDR_RUNLOCK(); 3125f8829a4aSRandall Stewart } 3126f8829a4aSRandall Stewart 3127f8829a4aSRandall Stewart /* 3128f8829a4aSRandall Stewart * validates an init-ack chunk (from a cookie-echo) with current addresses 3129f8829a4aSRandall Stewart * adds addresses from the init-ack into our local address list, if needed 3130f8829a4aSRandall Stewart * queues asconf adds/deletes addresses as needed and makes appropriate list 3131f8829a4aSRandall Stewart * changes for source address selection m, offset: points to the start of the 3132f8829a4aSRandall Stewart * address list in an init-ack chunk length: total length of the address 3133f8829a4aSRandall Stewart * params only init_addr: address where my INIT-ACK was sent from 3134f8829a4aSRandall Stewart */ 3135f8829a4aSRandall Stewart void 3136f8829a4aSRandall Stewart sctp_check_address_list(struct sctp_tcb *stcb, struct mbuf *m, int offset, 3137f8829a4aSRandall Stewart int length, struct sockaddr *init_addr, 3138f8829a4aSRandall Stewart uint16_t local_scope, uint16_t site_scope, 3139f8829a4aSRandall Stewart uint16_t ipv4_scope, uint16_t loopback_scope) 3140f8829a4aSRandall Stewart { 3141f8829a4aSRandall Stewart /* process the local addresses in the initack */ 3142f8829a4aSRandall Stewart sctp_process_initack_addresses(stcb, m, offset, length); 3143f8829a4aSRandall Stewart 3144f8829a4aSRandall Stewart if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { 3145f8829a4aSRandall Stewart /* bound all case */ 3146f8829a4aSRandall Stewart sctp_check_address_list_all(stcb, m, offset, length, init_addr, 3147f8829a4aSRandall Stewart local_scope, site_scope, ipv4_scope, loopback_scope); 3148f8829a4aSRandall Stewart } else { 3149f8829a4aSRandall Stewart /* subset bound case */ 3150f8829a4aSRandall Stewart if (sctp_is_feature_on(stcb->sctp_ep, 3151f8829a4aSRandall Stewart SCTP_PCB_FLAGS_DO_ASCONF)) { 3152f8829a4aSRandall Stewart /* asconf's allowed */ 3153f8829a4aSRandall Stewart sctp_check_address_list_ep(stcb, m, offset, length, 3154f8829a4aSRandall Stewart init_addr); 3155f8829a4aSRandall Stewart } 3156f8829a4aSRandall Stewart /* else, no asconfs allowed, so what we sent is what we get */ 3157f8829a4aSRandall Stewart } 3158f8829a4aSRandall Stewart } 3159f8829a4aSRandall Stewart 3160f8829a4aSRandall Stewart /* 3161f8829a4aSRandall Stewart * sctp_bindx() support 3162f8829a4aSRandall Stewart */ 3163f8829a4aSRandall Stewart uint32_t 31643c503c28SRandall Stewart sctp_addr_mgmt_ep_sa(struct sctp_inpcb *inp, struct sockaddr *sa, 316580fefe0aSRandall Stewart uint32_t type, uint32_t vrf_id, struct sctp_ifa *sctp_ifap) 3166f8829a4aSRandall Stewart { 316742551e99SRandall Stewart struct sctp_ifa *ifa; 3168f8829a4aSRandall Stewart 316942551e99SRandall Stewart if (sa->sa_len == 0) { 3170c4739e2fSRandall Stewart SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EINVAL); 3171f8829a4aSRandall Stewart return (EINVAL); 317242551e99SRandall Stewart } 317380fefe0aSRandall Stewart if (sctp_ifap) { 317480fefe0aSRandall Stewart ifa = sctp_ifap; 317580fefe0aSRandall Stewart } else if (type == SCTP_ADD_IP_ADDRESS) { 317642551e99SRandall Stewart /* For an add the address MUST be on the system */ 3177851b7298SRandall Stewart ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED); 317842551e99SRandall Stewart } else if (type == SCTP_DEL_IP_ADDRESS) { 317942551e99SRandall Stewart /* For a delete we need to find it in the inp */ 3180851b7298SRandall Stewart ifa = sctp_find_ifa_in_ep(inp, sa, SCTP_ADDR_NOT_LOCKED); 318142551e99SRandall Stewart } else { 318242551e99SRandall Stewart ifa = NULL; 318342551e99SRandall Stewart } 3184f8829a4aSRandall Stewart if (ifa != NULL) { 318542551e99SRandall Stewart if (type == SCTP_ADD_IP_ADDRESS) { 318642551e99SRandall Stewart sctp_add_local_addr_ep(inp, ifa, type); 318742551e99SRandall Stewart } else if (type == SCTP_DEL_IP_ADDRESS) { 318842551e99SRandall Stewart struct sctp_laddr *laddr; 318942551e99SRandall Stewart 31903c503c28SRandall Stewart if (inp->laddr_count < 2) { 31913c503c28SRandall Stewart /* can't delete the last local address */ 3192c4739e2fSRandall Stewart SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EINVAL); 31933c503c28SRandall Stewart return (EINVAL); 31943c503c28SRandall Stewart } 31953c503c28SRandall Stewart LIST_FOREACH(laddr, &inp->sctp_addr_list, 31963c503c28SRandall Stewart sctp_nxt_addr) { 319742551e99SRandall Stewart if (ifa == laddr->ifa) { 319842551e99SRandall Stewart /* Mark in the delete */ 319942551e99SRandall Stewart laddr->action = type; 320042551e99SRandall Stewart } 320142551e99SRandall Stewart } 320242551e99SRandall Stewart } 320387b4fcd3SMichael Tuexen if (!LIST_EMPTY(&inp->sctp_asoc_list)) { 320487b4fcd3SMichael Tuexen /* 320587b4fcd3SMichael Tuexen * There is no need to start the iterator if the inp 320687b4fcd3SMichael Tuexen * has no associations. 320787b4fcd3SMichael Tuexen */ 320887b4fcd3SMichael Tuexen struct sctp_asconf_iterator *asc; 320987b4fcd3SMichael Tuexen struct sctp_laddr *wi; 321087b4fcd3SMichael Tuexen 321187b4fcd3SMichael Tuexen SCTP_MALLOC(asc, struct sctp_asconf_iterator *, 321287b4fcd3SMichael Tuexen sizeof(struct sctp_asconf_iterator), 321387b4fcd3SMichael Tuexen SCTP_M_ASC_IT); 321487b4fcd3SMichael Tuexen if (asc == NULL) { 321587b4fcd3SMichael Tuexen SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, ENOMEM); 321687b4fcd3SMichael Tuexen return (ENOMEM); 321787b4fcd3SMichael Tuexen } 321887b4fcd3SMichael Tuexen wi = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_laddr), struct sctp_laddr); 321987b4fcd3SMichael Tuexen if (wi == NULL) { 322087b4fcd3SMichael Tuexen SCTP_FREE(asc, SCTP_M_ASC_IT); 322187b4fcd3SMichael Tuexen SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, ENOMEM); 322287b4fcd3SMichael Tuexen return (ENOMEM); 322387b4fcd3SMichael Tuexen } 322442551e99SRandall Stewart LIST_INIT(&asc->list_of_work); 322542551e99SRandall Stewart asc->cnt = 1; 322642551e99SRandall Stewart SCTP_INCR_LADDR_COUNT(); 322742551e99SRandall Stewart wi->ifa = ifa; 322842551e99SRandall Stewart wi->action = type; 322942551e99SRandall Stewart atomic_add_int(&ifa->refcount, 1); 323042551e99SRandall Stewart LIST_INSERT_HEAD(&asc->list_of_work, wi, sctp_nxt_addr); 32311b649582SRandall Stewart (void)sctp_initiate_iterator(sctp_asconf_iterator_ep, 32321b649582SRandall Stewart sctp_asconf_iterator_stcb, 32331b649582SRandall Stewart sctp_asconf_iterator_ep_end, 323442551e99SRandall Stewart SCTP_PCB_ANY_FLAGS, 32353c503c28SRandall Stewart SCTP_PCB_ANY_FEATURES, 32361b649582SRandall Stewart SCTP_ASOC_ANY_STATE, 32371b649582SRandall Stewart (void *)asc, 0, 32381b649582SRandall Stewart sctp_asconf_iterator_end, inp, 0); 323987b4fcd3SMichael Tuexen } 324087b4fcd3SMichael Tuexen return (0); 3241f8829a4aSRandall Stewart } else { 3242f8829a4aSRandall Stewart /* invalid address! */ 3243c4739e2fSRandall Stewart SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EADDRNOTAVAIL); 3244f8829a4aSRandall Stewart return (EADDRNOTAVAIL); 3245f8829a4aSRandall Stewart } 3246f8829a4aSRandall Stewart } 3247830d754dSRandall Stewart 3248830d754dSRandall Stewart void 3249830d754dSRandall Stewart sctp_asconf_send_nat_state_update(struct sctp_tcb *stcb, 3250830d754dSRandall Stewart struct sctp_nets *net) 3251830d754dSRandall Stewart { 3252830d754dSRandall Stewart struct sctp_asconf_addr *aa; 3253830d754dSRandall Stewart struct sctp_ifa *sctp_ifap; 3254830d754dSRandall Stewart struct sctp_asconf_tag_param *vtag; 3255830d754dSRandall Stewart struct sockaddr_in *to; 3256830d754dSRandall Stewart 3257830d754dSRandall Stewart #ifdef INET6 3258830d754dSRandall Stewart struct sockaddr_in6 *to6; 3259830d754dSRandall Stewart 3260830d754dSRandall Stewart #endif 3261830d754dSRandall Stewart if (net == NULL) { 3262830d754dSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing net\n"); 3263830d754dSRandall Stewart return; 3264830d754dSRandall Stewart } 3265830d754dSRandall Stewart if (stcb == NULL) { 3266830d754dSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing stcb\n"); 3267830d754dSRandall Stewart return; 3268830d754dSRandall Stewart } 3269830d754dSRandall Stewart /* 3270830d754dSRandall Stewart * Need to have in the asconf: - vtagparam(my_vtag/peer_vtag) - 3271830d754dSRandall Stewart * add(0.0.0.0) - del(0.0.0.0) - Any global addresses add(addr) 3272830d754dSRandall Stewart */ 3273830d754dSRandall Stewart SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), 3274830d754dSRandall Stewart SCTP_M_ASC_ADDR); 3275830d754dSRandall Stewart if (aa == NULL) { 3276830d754dSRandall Stewart /* didn't get memory */ 3277830d754dSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 3278830d754dSRandall Stewart "sctp_asconf_send_nat_state_update: failed to get memory!\n"); 3279830d754dSRandall Stewart return; 3280830d754dSRandall Stewart } 3281830d754dSRandall Stewart aa->special_del = 0; 3282830d754dSRandall Stewart /* fill in asconf address parameter fields */ 3283830d754dSRandall Stewart /* top level elements are "networked" during send */ 3284830d754dSRandall Stewart aa->ifa = NULL; 3285830d754dSRandall Stewart aa->sent = 0; /* clear sent flag */ 3286830d754dSRandall Stewart vtag = (struct sctp_asconf_tag_param *)&aa->ap.aph; 3287830d754dSRandall Stewart vtag->aph.ph.param_type = SCTP_NAT_VTAGS; 3288830d754dSRandall Stewart vtag->aph.ph.param_length = sizeof(struct sctp_asconf_tag_param); 3289830d754dSRandall Stewart vtag->local_vtag = htonl(stcb->asoc.my_vtag); 3290830d754dSRandall Stewart vtag->remote_vtag = htonl(stcb->asoc.peer_vtag); 3291830d754dSRandall Stewart TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); 3292830d754dSRandall Stewart 3293830d754dSRandall Stewart SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), 3294830d754dSRandall Stewart SCTP_M_ASC_ADDR); 3295830d754dSRandall Stewart if (aa == NULL) { 3296830d754dSRandall Stewart /* didn't get memory */ 3297830d754dSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 3298830d754dSRandall Stewart "sctp_asconf_send_nat_state_update: failed to get memory!\n"); 3299830d754dSRandall Stewart return; 3300830d754dSRandall Stewart } 3301830d754dSRandall Stewart memset(aa, 0, sizeof(struct sctp_asconf_addr)); 3302830d754dSRandall Stewart /* fill in asconf address parameter fields */ 3303830d754dSRandall Stewart /* ADD(0.0.0.0) */ 3304830d754dSRandall Stewart if (net->ro._l_addr.sa.sa_family == AF_INET) { 3305830d754dSRandall Stewart aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS; 3306830d754dSRandall Stewart aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param); 3307830d754dSRandall Stewart aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS; 3308830d754dSRandall Stewart aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv4addr_param); 3309830d754dSRandall Stewart /* No need to add an address, we are using 0.0.0.0 */ 3310830d754dSRandall Stewart TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); 3311830d754dSRandall Stewart } 3312830d754dSRandall Stewart #ifdef INET6 3313830d754dSRandall Stewart else if (net->ro._l_addr.sa.sa_family == AF_INET6) { 3314830d754dSRandall Stewart aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS; 3315830d754dSRandall Stewart aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param); 3316830d754dSRandall Stewart aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS; 3317830d754dSRandall Stewart aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv6addr_param); 3318830d754dSRandall Stewart /* No need to add an address, we are using 0.0.0.0 */ 3319830d754dSRandall Stewart TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); 3320830d754dSRandall Stewart } 3321830d754dSRandall Stewart #endif /* INET6 */ 3322830d754dSRandall Stewart SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), 3323830d754dSRandall Stewart SCTP_M_ASC_ADDR); 3324830d754dSRandall Stewart if (aa == NULL) { 3325830d754dSRandall Stewart /* didn't get memory */ 3326830d754dSRandall Stewart SCTPDBG(SCTP_DEBUG_ASCONF1, 3327830d754dSRandall Stewart "sctp_asconf_send_nat_state_update: failed to get memory!\n"); 3328830d754dSRandall Stewart return; 3329830d754dSRandall Stewart } 3330830d754dSRandall Stewart memset(aa, 0, sizeof(struct sctp_asconf_addr)); 3331830d754dSRandall Stewart /* fill in asconf address parameter fields */ 3332830d754dSRandall Stewart /* ADD(0.0.0.0) */ 3333830d754dSRandall Stewart if (net->ro._l_addr.sa.sa_family == AF_INET) { 3334830d754dSRandall Stewart aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS; 3335830d754dSRandall Stewart aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param); 3336830d754dSRandall Stewart aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS; 3337830d754dSRandall Stewart aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv4addr_param); 3338830d754dSRandall Stewart /* No need to add an address, we are using 0.0.0.0 */ 3339830d754dSRandall Stewart TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); 3340830d754dSRandall Stewart } 3341830d754dSRandall Stewart #ifdef INET6 3342830d754dSRandall Stewart else if (net->ro._l_addr.sa.sa_family == AF_INET6) { 3343830d754dSRandall Stewart aa->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS; 3344830d754dSRandall Stewart aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param); 3345830d754dSRandall Stewart aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS; 3346830d754dSRandall Stewart aa->ap.addrp.ph.param_length = sizeof(struct sctp_ipv6addr_param); 3347830d754dSRandall Stewart /* No need to add an address, we are using 0.0.0.0 */ 3348830d754dSRandall Stewart TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); 3349830d754dSRandall Stewart } 3350830d754dSRandall Stewart #endif /* INET6 */ 3351830d754dSRandall Stewart /* Now we must hunt the addresses and add all global addresses */ 3352830d754dSRandall Stewart if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { 3353830d754dSRandall Stewart struct sctp_vrf *vrf = NULL; 3354830d754dSRandall Stewart struct sctp_ifn *sctp_ifnp; 3355830d754dSRandall Stewart uint32_t vrf_id; 3356830d754dSRandall Stewart 3357830d754dSRandall Stewart vrf_id = stcb->sctp_ep->def_vrf_id; 3358830d754dSRandall Stewart vrf = sctp_find_vrf(vrf_id); 3359830d754dSRandall Stewart if (vrf == NULL) { 3360830d754dSRandall Stewart goto skip_rest; 3361830d754dSRandall Stewart } 3362830d754dSRandall Stewart SCTP_IPI_ADDR_RLOCK(); 3363830d754dSRandall Stewart LIST_FOREACH(sctp_ifnp, &vrf->ifnlist, next_ifn) { 3364830d754dSRandall Stewart LIST_FOREACH(sctp_ifap, &sctp_ifnp->ifalist, next_ifa) { 3365830d754dSRandall Stewart if (sctp_ifap->address.sa.sa_family == AF_INET) { 3366830d754dSRandall Stewart to = &sctp_ifap->address.sin; 3367830d754dSRandall Stewart 3368830d754dSRandall Stewart if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) { 3369830d754dSRandall Stewart continue; 3370830d754dSRandall Stewart } 3371830d754dSRandall Stewart if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) { 3372830d754dSRandall Stewart continue; 3373830d754dSRandall Stewart } 3374830d754dSRandall Stewart } 3375830d754dSRandall Stewart #ifdef INET6 3376830d754dSRandall Stewart else if (sctp_ifap->address.sa.sa_family == AF_INET6) { 3377830d754dSRandall Stewart to6 = &sctp_ifap->address.sin6; 3378830d754dSRandall Stewart if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) { 3379830d754dSRandall Stewart continue; 3380830d754dSRandall Stewart } 3381830d754dSRandall Stewart if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) { 3382830d754dSRandall Stewart continue; 3383830d754dSRandall Stewart } 3384830d754dSRandall Stewart } 3385830d754dSRandall Stewart #endif 3386830d754dSRandall Stewart sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS); 3387830d754dSRandall Stewart } 3388830d754dSRandall Stewart } 3389830d754dSRandall Stewart SCTP_IPI_ADDR_RUNLOCK(); 3390830d754dSRandall Stewart } else { 3391830d754dSRandall Stewart struct sctp_laddr *laddr; 3392830d754dSRandall Stewart 3393830d754dSRandall Stewart LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) { 3394830d754dSRandall Stewart if (laddr->ifa == NULL) { 3395830d754dSRandall Stewart continue; 3396830d754dSRandall Stewart } 3397830d754dSRandall Stewart if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED) 3398830d754dSRandall Stewart /* 3399830d754dSRandall Stewart * Address being deleted by the system, dont 3400830d754dSRandall Stewart * list. 3401830d754dSRandall Stewart */ 3402830d754dSRandall Stewart continue; 3403830d754dSRandall Stewart if (laddr->action == SCTP_DEL_IP_ADDRESS) { 3404830d754dSRandall Stewart /* 3405830d754dSRandall Stewart * Address being deleted on this ep don't 3406830d754dSRandall Stewart * list. 3407830d754dSRandall Stewart */ 3408830d754dSRandall Stewart continue; 3409830d754dSRandall Stewart } 3410830d754dSRandall Stewart sctp_ifap = laddr->ifa; 3411830d754dSRandall Stewart if (sctp_ifap->address.sa.sa_family == AF_INET) { 3412830d754dSRandall Stewart to = &sctp_ifap->address.sin; 3413830d754dSRandall Stewart 3414830d754dSRandall Stewart if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) { 3415830d754dSRandall Stewart continue; 3416830d754dSRandall Stewart } 3417830d754dSRandall Stewart if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) { 3418830d754dSRandall Stewart continue; 3419830d754dSRandall Stewart } 3420830d754dSRandall Stewart } 3421830d754dSRandall Stewart #ifdef INET6 3422830d754dSRandall Stewart else if (sctp_ifap->address.sa.sa_family == AF_INET6) { 3423830d754dSRandall Stewart to6 = &sctp_ifap->address.sin6; 3424830d754dSRandall Stewart if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) { 3425830d754dSRandall Stewart continue; 3426830d754dSRandall Stewart } 3427830d754dSRandall Stewart if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) { 3428830d754dSRandall Stewart continue; 3429830d754dSRandall Stewart } 3430830d754dSRandall Stewart } 3431830d754dSRandall Stewart #endif 3432830d754dSRandall Stewart sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS); 3433830d754dSRandall Stewart } 3434830d754dSRandall Stewart } 3435830d754dSRandall Stewart skip_rest: 3436830d754dSRandall Stewart /* Now we must send the asconf into the queue */ 3437830d754dSRandall Stewart sctp_send_asconf(stcb, net, 0); 3438830d754dSRandall Stewart } 3439