michael@0: /*- michael@0: * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved. michael@0: * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved. michael@0: * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved. michael@0: * michael@0: * Redistribution and use in source and binary forms, with or without michael@0: * modification, are permitted provided that the following conditions are met: michael@0: * michael@0: * a) Redistributions of source code must retain the above copyright notice, michael@0: * this list of conditions and the following disclaimer. michael@0: * michael@0: * b) Redistributions in binary form must reproduce the above copyright michael@0: * notice, this list of conditions and the following disclaimer in michael@0: * the documentation and/or other materials provided with the distribution. michael@0: * michael@0: * c) Neither the name of Cisco Systems, Inc. nor the names of its michael@0: * contributors may be used to endorse or promote products derived michael@0: * from this software without specific prior written permission. michael@0: * michael@0: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, michael@0: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE michael@0: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE michael@0: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR michael@0: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF michael@0: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS michael@0: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN michael@0: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) michael@0: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF michael@0: * THE POSSIBILITY OF SUCH DAMAGE. michael@0: */ michael@0: michael@0: #ifdef __FreeBSD__ michael@0: #include michael@0: __FBSDID("$FreeBSD: head/sys/netinet/sctp_asconf.c 257803 2013-11-07 17:08:09Z tuexen $"); michael@0: #endif michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: /* michael@0: * debug flags: michael@0: * SCTP_DEBUG_ASCONF1: protocol info, general info and errors michael@0: * SCTP_DEBUG_ASCONF2: detailed info michael@0: */ michael@0: michael@0: #if defined(__APPLE__) michael@0: #define APPLE_FILE_NO 1 michael@0: #endif michael@0: michael@0: /* michael@0: * RFC 5061 michael@0: * michael@0: * An ASCONF parameter queue exists per asoc which holds the pending address michael@0: * operations. Lists are updated upon receipt of ASCONF-ACK. michael@0: * michael@0: * A restricted_addrs list exists per assoc to hold local addresses that are michael@0: * not (yet) usable by the assoc as a source address. These addresses are michael@0: * either pending an ASCONF operation (and exist on the ASCONF parameter michael@0: * queue), or they are permanently restricted (the peer has returned an michael@0: * ERROR indication to an ASCONF(ADD), or the peer does not support ASCONF). michael@0: * michael@0: * Deleted addresses are always immediately removed from the lists as they will michael@0: * (shortly) no longer exist in the kernel. We send ASCONFs as a courtesy, michael@0: * only if allowed. michael@0: */ michael@0: michael@0: /* michael@0: * ASCONF parameter processing. michael@0: * response_required: set if a reply is required (eg. SUCCESS_REPORT). michael@0: * returns a mbuf to an "error" response parameter or NULL/"success" if ok. michael@0: * FIX: allocating this many mbufs on the fly is pretty inefficient... michael@0: */ michael@0: static struct mbuf * michael@0: sctp_asconf_success_response(uint32_t id) michael@0: { michael@0: struct mbuf *m_reply = NULL; michael@0: struct sctp_asconf_paramhdr *aph; michael@0: michael@0: m_reply = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_paramhdr), michael@0: 0, M_NOWAIT, 1, MT_DATA); michael@0: if (m_reply == NULL) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "asconf_success_response: couldn't get mbuf!\n"); michael@0: return (NULL); michael@0: } michael@0: aph = mtod(m_reply, struct sctp_asconf_paramhdr *); michael@0: aph->correlation_id = id; michael@0: aph->ph.param_type = htons(SCTP_SUCCESS_REPORT); michael@0: aph->ph.param_length = sizeof(struct sctp_asconf_paramhdr); michael@0: SCTP_BUF_LEN(m_reply) = aph->ph.param_length; michael@0: aph->ph.param_length = htons(aph->ph.param_length); michael@0: michael@0: return (m_reply); michael@0: } michael@0: michael@0: static struct mbuf * michael@0: sctp_asconf_error_response(uint32_t id, uint16_t cause, uint8_t *error_tlv, michael@0: uint16_t tlv_length) michael@0: { michael@0: struct mbuf *m_reply = NULL; michael@0: struct sctp_asconf_paramhdr *aph; michael@0: struct sctp_error_cause *error; michael@0: uint8_t *tlv; michael@0: michael@0: m_reply = sctp_get_mbuf_for_msg((sizeof(struct sctp_asconf_paramhdr) + michael@0: tlv_length + michael@0: sizeof(struct sctp_error_cause)), michael@0: 0, M_NOWAIT, 1, MT_DATA); michael@0: if (m_reply == NULL) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "asconf_error_response: couldn't get mbuf!\n"); michael@0: return (NULL); michael@0: } michael@0: aph = mtod(m_reply, struct sctp_asconf_paramhdr *); michael@0: error = (struct sctp_error_cause *)(aph + 1); michael@0: michael@0: aph->correlation_id = id; michael@0: aph->ph.param_type = htons(SCTP_ERROR_CAUSE_IND); michael@0: error->code = htons(cause); michael@0: error->length = tlv_length + sizeof(struct sctp_error_cause); michael@0: aph->ph.param_length = error->length + michael@0: sizeof(struct sctp_asconf_paramhdr); michael@0: michael@0: if (aph->ph.param_length > MLEN) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "asconf_error_response: tlv_length (%xh) too big\n", michael@0: tlv_length); michael@0: sctp_m_freem(m_reply); /* discard */ michael@0: return (NULL); michael@0: } michael@0: if (error_tlv != NULL) { michael@0: tlv = (uint8_t *) (error + 1); michael@0: memcpy(tlv, error_tlv, tlv_length); michael@0: } michael@0: SCTP_BUF_LEN(m_reply) = aph->ph.param_length; michael@0: error->length = htons(error->length); michael@0: aph->ph.param_length = htons(aph->ph.param_length); michael@0: michael@0: return (m_reply); michael@0: } michael@0: michael@0: static struct mbuf * michael@0: sctp_process_asconf_add_ip(struct sockaddr *src, struct sctp_asconf_paramhdr *aph, michael@0: struct sctp_tcb *stcb, int send_hb, int response_required) michael@0: { michael@0: struct sctp_nets *net; michael@0: struct mbuf *m_reply = NULL; michael@0: struct sockaddr_storage sa_store; michael@0: struct sctp_paramhdr *ph; michael@0: uint16_t param_type, aparam_length; michael@0: #if defined(INET) || defined(INET6) michael@0: uint16_t param_length; michael@0: #endif michael@0: struct sockaddr *sa; michael@0: int zero_address = 0; michael@0: int bad_address = 0; michael@0: #ifdef INET michael@0: struct sockaddr_in *sin; michael@0: struct sctp_ipv4addr_param *v4addr; michael@0: #endif michael@0: #ifdef INET6 michael@0: struct sockaddr_in6 *sin6; michael@0: struct sctp_ipv6addr_param *v6addr; michael@0: #endif michael@0: michael@0: aparam_length = ntohs(aph->ph.param_length); michael@0: ph = (struct sctp_paramhdr *)(aph + 1); michael@0: param_type = ntohs(ph->param_type); michael@0: #if defined(INET) || defined(INET6) michael@0: param_length = ntohs(ph->param_length); michael@0: #endif michael@0: sa = (struct sockaddr *)&sa_store; michael@0: switch (param_type) { michael@0: #ifdef INET michael@0: case SCTP_IPV4_ADDRESS: michael@0: if (param_length != sizeof(struct sctp_ipv4addr_param)) { michael@0: /* invalid param size */ michael@0: return (NULL); michael@0: } michael@0: v4addr = (struct sctp_ipv4addr_param *)ph; michael@0: sin = (struct sockaddr_in *)&sa_store; michael@0: bzero(sin, sizeof(*sin)); michael@0: sin->sin_family = AF_INET; michael@0: #ifdef HAVE_SIN_LEN michael@0: sin->sin_len = sizeof(struct sockaddr_in); michael@0: #endif michael@0: sin->sin_port = stcb->rport; michael@0: sin->sin_addr.s_addr = v4addr->addr; michael@0: if ((sin->sin_addr.s_addr == INADDR_BROADCAST) || michael@0: IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) { michael@0: bad_address = 1; michael@0: } michael@0: if (sin->sin_addr.s_addr == INADDR_ANY) michael@0: zero_address = 1; michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_add_ip: adding "); michael@0: SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); michael@0: break; michael@0: #endif michael@0: #ifdef INET6 michael@0: case SCTP_IPV6_ADDRESS: michael@0: if (param_length != sizeof(struct sctp_ipv6addr_param)) { michael@0: /* invalid param size */ michael@0: return (NULL); michael@0: } michael@0: v6addr = (struct sctp_ipv6addr_param *)ph; michael@0: sin6 = (struct sockaddr_in6 *)&sa_store; michael@0: bzero(sin6, sizeof(*sin6)); michael@0: sin6->sin6_family = AF_INET6; michael@0: #ifdef HAVE_SIN6_LEN michael@0: sin6->sin6_len = sizeof(struct sockaddr_in6); michael@0: #endif michael@0: sin6->sin6_port = stcb->rport; michael@0: memcpy((caddr_t)&sin6->sin6_addr, v6addr->addr, michael@0: sizeof(struct in6_addr)); michael@0: if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) { michael@0: bad_address = 1; michael@0: } michael@0: if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) michael@0: zero_address = 1; michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_add_ip: adding "); michael@0: SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); michael@0: break; michael@0: #endif michael@0: default: michael@0: m_reply = sctp_asconf_error_response(aph->correlation_id, michael@0: SCTP_CAUSE_INVALID_PARAM, (uint8_t *) aph, michael@0: aparam_length); michael@0: return (m_reply); michael@0: } /* end switch */ michael@0: michael@0: /* if 0.0.0.0/::0, add the source address instead */ michael@0: if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) { michael@0: sa = src; michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "process_asconf_add_ip: using source addr "); michael@0: SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, src); michael@0: } michael@0: /* add the address */ michael@0: if (bad_address) { michael@0: m_reply = sctp_asconf_error_response(aph->correlation_id, michael@0: SCTP_CAUSE_INVALID_PARAM, (uint8_t *) aph, michael@0: aparam_length); michael@0: } else if (sctp_add_remote_addr(stcb, sa, &net, SCTP_DONOT_SETSCOPE, michael@0: SCTP_ADDR_DYNAMIC_ADDED) != 0) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "process_asconf_add_ip: error adding address\n"); michael@0: m_reply = sctp_asconf_error_response(aph->correlation_id, michael@0: SCTP_CAUSE_RESOURCE_SHORTAGE, (uint8_t *) aph, michael@0: aparam_length); michael@0: } else { michael@0: /* notify upper layer */ michael@0: sctp_ulp_notify(SCTP_NOTIFY_ASCONF_ADD_IP, stcb, 0, sa, SCTP_SO_NOT_LOCKED); michael@0: if (response_required) { michael@0: m_reply = michael@0: sctp_asconf_success_response(aph->correlation_id); michael@0: } michael@0: sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, stcb->sctp_ep, stcb, net); michael@0: sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, michael@0: stcb, net); michael@0: if (send_hb) { michael@0: sctp_send_hb(stcb, net, SCTP_SO_NOT_LOCKED); michael@0: } michael@0: } michael@0: return (m_reply); michael@0: } michael@0: michael@0: static int michael@0: sctp_asconf_del_remote_addrs_except(struct sctp_tcb *stcb, struct sockaddr *src) michael@0: { michael@0: struct sctp_nets *src_net, *net; michael@0: michael@0: /* make sure the source address exists as a destination net */ michael@0: src_net = sctp_findnet(stcb, src); michael@0: if (src_net == NULL) { michael@0: /* not found */ michael@0: return (-1); michael@0: } michael@0: michael@0: /* delete all destination addresses except the source */ michael@0: TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { michael@0: if (net != src_net) { michael@0: /* delete this address */ michael@0: sctp_remove_net(stcb, net); michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "asconf_del_remote_addrs_except: deleting "); michael@0: SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, michael@0: (struct sockaddr *)&net->ro._l_addr); michael@0: /* notify upper layer */ michael@0: sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0, michael@0: (struct sockaddr *)&net->ro._l_addr, SCTP_SO_NOT_LOCKED); michael@0: } michael@0: } michael@0: return (0); michael@0: } michael@0: michael@0: static struct mbuf * michael@0: sctp_process_asconf_delete_ip(struct sockaddr *src, michael@0: struct sctp_asconf_paramhdr *aph, michael@0: struct sctp_tcb *stcb, int response_required) michael@0: { michael@0: struct mbuf *m_reply = NULL; michael@0: struct sockaddr_storage sa_store; michael@0: struct sctp_paramhdr *ph; michael@0: uint16_t param_type, aparam_length; michael@0: #if defined(INET) || defined(INET6) michael@0: uint16_t param_length; michael@0: #endif michael@0: struct sockaddr *sa; michael@0: int zero_address = 0; michael@0: int result; michael@0: #ifdef INET michael@0: struct sockaddr_in *sin; michael@0: struct sctp_ipv4addr_param *v4addr; michael@0: #endif michael@0: #ifdef INET6 michael@0: struct sockaddr_in6 *sin6; michael@0: struct sctp_ipv6addr_param *v6addr; michael@0: #endif michael@0: michael@0: aparam_length = ntohs(aph->ph.param_length); michael@0: ph = (struct sctp_paramhdr *)(aph + 1); michael@0: param_type = ntohs(ph->param_type); michael@0: #if defined(INET) || defined(INET6) michael@0: param_length = ntohs(ph->param_length); michael@0: #endif michael@0: sa = (struct sockaddr *)&sa_store; michael@0: switch (param_type) { michael@0: #ifdef INET michael@0: case SCTP_IPV4_ADDRESS: michael@0: if (param_length != sizeof(struct sctp_ipv4addr_param)) { michael@0: /* invalid param size */ michael@0: return (NULL); michael@0: } michael@0: v4addr = (struct sctp_ipv4addr_param *)ph; michael@0: sin = (struct sockaddr_in *)&sa_store; michael@0: bzero(sin, sizeof(*sin)); michael@0: sin->sin_family = AF_INET; michael@0: #ifdef HAVE_SIN_LEN michael@0: sin->sin_len = sizeof(struct sockaddr_in); michael@0: #endif michael@0: sin->sin_port = stcb->rport; michael@0: sin->sin_addr.s_addr = v4addr->addr; michael@0: if (sin->sin_addr.s_addr == INADDR_ANY) michael@0: zero_address = 1; michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "process_asconf_delete_ip: deleting "); michael@0: SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); michael@0: break; michael@0: #endif michael@0: #ifdef INET6 michael@0: case SCTP_IPV6_ADDRESS: michael@0: if (param_length != sizeof(struct sctp_ipv6addr_param)) { michael@0: /* invalid param size */ michael@0: return (NULL); michael@0: } michael@0: v6addr = (struct sctp_ipv6addr_param *)ph; michael@0: sin6 = (struct sockaddr_in6 *)&sa_store; michael@0: bzero(sin6, sizeof(*sin6)); michael@0: sin6->sin6_family = AF_INET6; michael@0: #ifdef HAVE_SIN6_LEN michael@0: sin6->sin6_len = sizeof(struct sockaddr_in6); michael@0: #endif michael@0: sin6->sin6_port = stcb->rport; michael@0: memcpy(&sin6->sin6_addr, v6addr->addr, michael@0: sizeof(struct in6_addr)); michael@0: if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) michael@0: zero_address = 1; michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "process_asconf_delete_ip: deleting "); michael@0: SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); michael@0: break; michael@0: #endif michael@0: default: michael@0: m_reply = sctp_asconf_error_response(aph->correlation_id, michael@0: SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph, michael@0: aparam_length); michael@0: return (m_reply); michael@0: } michael@0: michael@0: /* make sure the source address is not being deleted */ michael@0: if (sctp_cmpaddr(sa, src)) { michael@0: /* trying to delete the source address! */ michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: tried to delete source addr\n"); michael@0: m_reply = sctp_asconf_error_response(aph->correlation_id, michael@0: SCTP_CAUSE_DELETING_SRC_ADDR, (uint8_t *) aph, michael@0: aparam_length); michael@0: return (m_reply); michael@0: } michael@0: michael@0: /* if deleting 0.0.0.0/::0, delete all addresses except src addr */ michael@0: if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) { michael@0: result = sctp_asconf_del_remote_addrs_except(stcb, src); michael@0: michael@0: if (result) { michael@0: /* src address did not exist? */ michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: src addr does not exist?\n"); michael@0: /* what error to reply with?? */ michael@0: m_reply = michael@0: sctp_asconf_error_response(aph->correlation_id, michael@0: SCTP_CAUSE_REQUEST_REFUSED, (uint8_t *) aph, michael@0: aparam_length); michael@0: } else if (response_required) { michael@0: m_reply = michael@0: sctp_asconf_success_response(aph->correlation_id); michael@0: } michael@0: return (m_reply); michael@0: } michael@0: michael@0: /* delete the address */ michael@0: result = sctp_del_remote_addr(stcb, sa); michael@0: /* michael@0: * note if result == -2, the address doesn't exist in the asoc but michael@0: * since it's being deleted anyways, we just ack the delete -- but michael@0: * this probably means something has already gone awry michael@0: */ michael@0: if (result == -1) { michael@0: /* only one address in the asoc */ michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_delete_ip: tried to delete last IP addr!\n"); michael@0: m_reply = sctp_asconf_error_response(aph->correlation_id, michael@0: SCTP_CAUSE_DELETING_LAST_ADDR, (uint8_t *) aph, michael@0: aparam_length); michael@0: } else { michael@0: if (response_required) { michael@0: m_reply = sctp_asconf_success_response(aph->correlation_id); michael@0: } michael@0: /* notify upper layer */ michael@0: sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0, sa, SCTP_SO_NOT_LOCKED); michael@0: } michael@0: return (m_reply); michael@0: } michael@0: michael@0: static struct mbuf * michael@0: sctp_process_asconf_set_primary(struct sockaddr *src, michael@0: struct sctp_asconf_paramhdr *aph, michael@0: struct sctp_tcb *stcb, int response_required) michael@0: { michael@0: struct mbuf *m_reply = NULL; michael@0: struct sockaddr_storage sa_store; michael@0: struct sctp_paramhdr *ph; michael@0: uint16_t param_type, aparam_length; michael@0: #if defined(INET) || defined(INET6) michael@0: uint16_t param_length; michael@0: #endif michael@0: struct sockaddr *sa; michael@0: int zero_address = 0; michael@0: #ifdef INET michael@0: struct sockaddr_in *sin; michael@0: struct sctp_ipv4addr_param *v4addr; michael@0: #endif michael@0: #ifdef INET6 michael@0: struct sockaddr_in6 *sin6; michael@0: struct sctp_ipv6addr_param *v6addr; michael@0: #endif michael@0: michael@0: aparam_length = ntohs(aph->ph.param_length); michael@0: ph = (struct sctp_paramhdr *)(aph + 1); michael@0: param_type = ntohs(ph->param_type); michael@0: #if defined(INET) || defined(INET6) michael@0: param_length = ntohs(ph->param_length); michael@0: #endif michael@0: sa = (struct sockaddr *)&sa_store; michael@0: switch (param_type) { michael@0: #ifdef INET michael@0: case SCTP_IPV4_ADDRESS: michael@0: if (param_length != sizeof(struct sctp_ipv4addr_param)) { michael@0: /* invalid param size */ michael@0: return (NULL); michael@0: } michael@0: v4addr = (struct sctp_ipv4addr_param *)ph; michael@0: sin = (struct sockaddr_in *)&sa_store; michael@0: bzero(sin, sizeof(*sin)); michael@0: sin->sin_family = AF_INET; michael@0: #ifdef HAVE_SIN_LEN michael@0: sin->sin_len = sizeof(struct sockaddr_in); michael@0: #endif michael@0: sin->sin_addr.s_addr = v4addr->addr; michael@0: if (sin->sin_addr.s_addr == INADDR_ANY) michael@0: zero_address = 1; michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_set_primary: "); michael@0: SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); michael@0: break; michael@0: #endif michael@0: #ifdef INET6 michael@0: case SCTP_IPV6_ADDRESS: michael@0: if (param_length != sizeof(struct sctp_ipv6addr_param)) { michael@0: /* invalid param size */ michael@0: return (NULL); michael@0: } michael@0: v6addr = (struct sctp_ipv6addr_param *)ph; michael@0: sin6 = (struct sockaddr_in6 *)&sa_store; michael@0: bzero(sin6, sizeof(*sin6)); michael@0: sin6->sin6_family = AF_INET6; michael@0: #ifdef HAVE_SIN6_LEN michael@0: sin6->sin6_len = sizeof(struct sockaddr_in6); michael@0: #endif michael@0: memcpy((caddr_t)&sin6->sin6_addr, v6addr->addr, michael@0: sizeof(struct in6_addr)); michael@0: if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) michael@0: zero_address = 1; michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "process_asconf_set_primary: "); michael@0: SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); michael@0: break; michael@0: #endif michael@0: default: michael@0: m_reply = sctp_asconf_error_response(aph->correlation_id, michael@0: SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph, michael@0: aparam_length); michael@0: return (m_reply); michael@0: } michael@0: michael@0: /* if 0.0.0.0/::0, use the source address instead */ michael@0: if (zero_address && SCTP_BASE_SYSCTL(sctp_nat_friendly)) { michael@0: sa = src; michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "process_asconf_set_primary: using source addr "); michael@0: SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, src); michael@0: } michael@0: /* set the primary address */ michael@0: if (sctp_set_primary_addr(stcb, sa, NULL) == 0) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "process_asconf_set_primary: primary address set\n"); michael@0: /* notify upper layer */ michael@0: sctp_ulp_notify(SCTP_NOTIFY_ASCONF_SET_PRIMARY, stcb, 0, sa, SCTP_SO_NOT_LOCKED); michael@0: if ((stcb->asoc.primary_destination->dest_state & SCTP_ADDR_REACHABLE) && michael@0: (!(stcb->asoc.primary_destination->dest_state & SCTP_ADDR_PF)) && michael@0: (stcb->asoc.alternate)) { michael@0: sctp_free_remote_addr(stcb->asoc.alternate); michael@0: stcb->asoc.alternate = NULL; michael@0: } michael@0: if (response_required) { michael@0: m_reply = sctp_asconf_success_response(aph->correlation_id); michael@0: } michael@0: /* Mobility adaptation. michael@0: Ideally, when the reception of SET PRIMARY with DELETE IP michael@0: ADDRESS of the previous primary destination, unacknowledged michael@0: DATA are retransmitted immediately to the new primary michael@0: destination for seamless handover. michael@0: If the destination is UNCONFIRMED and marked to REQ_PRIM, michael@0: The retransmission occur when reception of the michael@0: HEARTBEAT-ACK. (See sctp_handle_heartbeat_ack in michael@0: sctp_input.c) michael@0: Also, when change of the primary destination, it is better michael@0: that all subsequent new DATA containing already queued DATA michael@0: are transmitted to the new primary destination. (by micchie) michael@0: */ michael@0: if ((sctp_is_mobility_feature_on(stcb->sctp_ep, michael@0: SCTP_MOBILITY_BASE) || michael@0: sctp_is_mobility_feature_on(stcb->sctp_ep, michael@0: SCTP_MOBILITY_FASTHANDOFF)) && michael@0: sctp_is_mobility_feature_on(stcb->sctp_ep, michael@0: SCTP_MOBILITY_PRIM_DELETED) && michael@0: (stcb->asoc.primary_destination->dest_state & michael@0: SCTP_ADDR_UNCONFIRMED) == 0) { michael@0: michael@0: sctp_timer_stop(SCTP_TIMER_TYPE_PRIM_DELETED, stcb->sctp_ep, stcb, NULL, SCTP_FROM_SCTP_TIMER+SCTP_LOC_7); michael@0: if (sctp_is_mobility_feature_on(stcb->sctp_ep, michael@0: SCTP_MOBILITY_FASTHANDOFF)) { michael@0: sctp_assoc_immediate_retrans(stcb, michael@0: stcb->asoc.primary_destination); michael@0: } michael@0: if (sctp_is_mobility_feature_on(stcb->sctp_ep, michael@0: SCTP_MOBILITY_BASE)) { michael@0: sctp_move_chunks_from_net(stcb, michael@0: stcb->asoc.deleted_primary); michael@0: } michael@0: sctp_delete_prim_timer(stcb->sctp_ep, stcb, michael@0: stcb->asoc.deleted_primary); michael@0: } michael@0: } else { michael@0: /* couldn't set the requested primary address! */ michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "process_asconf_set_primary: set primary failed!\n"); michael@0: /* must have been an invalid address, so report */ michael@0: m_reply = sctp_asconf_error_response(aph->correlation_id, michael@0: SCTP_CAUSE_UNRESOLVABLE_ADDR, (uint8_t *) aph, michael@0: aparam_length); michael@0: } michael@0: michael@0: return (m_reply); michael@0: } michael@0: michael@0: /* michael@0: * handles an ASCONF chunk. michael@0: * if all parameters are processed ok, send a plain (empty) ASCONF-ACK michael@0: */ michael@0: void michael@0: sctp_handle_asconf(struct mbuf *m, unsigned int offset, michael@0: struct sockaddr *src, michael@0: struct sctp_asconf_chunk *cp, struct sctp_tcb *stcb, michael@0: int first) michael@0: { michael@0: struct sctp_association *asoc; michael@0: uint32_t serial_num; michael@0: struct mbuf *n, *m_ack, *m_result, *m_tail; michael@0: struct sctp_asconf_ack_chunk *ack_cp; michael@0: struct sctp_asconf_paramhdr *aph, *ack_aph; michael@0: struct sctp_ipv6addr_param *p_addr; michael@0: unsigned int asconf_limit, cnt; michael@0: int error = 0; /* did an error occur? */ michael@0: michael@0: /* asconf param buffer */ michael@0: uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE]; michael@0: struct sctp_asconf_ack *ack, *ack_next; michael@0: michael@0: /* verify minimum length */ michael@0: if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_chunk)) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "handle_asconf: chunk too small = %xh\n", michael@0: ntohs(cp->ch.chunk_length)); michael@0: return; michael@0: } michael@0: asoc = &stcb->asoc; michael@0: serial_num = ntohl(cp->serial_number); michael@0: michael@0: if (SCTP_TSN_GE(asoc->asconf_seq_in, serial_num)) { michael@0: /* got a duplicate ASCONF */ michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "handle_asconf: got duplicate serial number = %xh\n", michael@0: serial_num); michael@0: return; michael@0: } else if (serial_num != (asoc->asconf_seq_in + 1)) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: incorrect serial number = %xh (expected next = %xh)\n", michael@0: serial_num, asoc->asconf_seq_in + 1); michael@0: return; michael@0: } michael@0: michael@0: /* it's the expected "next" sequence number, so process it */ michael@0: asoc->asconf_seq_in = serial_num; /* update sequence */ michael@0: /* get length of all the param's in the ASCONF */ michael@0: asconf_limit = offset + ntohs(cp->ch.chunk_length); michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "handle_asconf: asconf_limit=%u, sequence=%xh\n", michael@0: asconf_limit, serial_num); michael@0: michael@0: if (first) { michael@0: /* delete old cache */ michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1,"handle_asconf: Now processing first ASCONF. Try to delete old cache\n"); michael@0: michael@0: TAILQ_FOREACH_SAFE(ack, &asoc->asconf_ack_sent, next, ack_next) { michael@0: if (ack->serial_number == serial_num) michael@0: break; michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1,"handle_asconf: delete old(%u) < first(%u)\n", michael@0: ack->serial_number, serial_num); michael@0: TAILQ_REMOVE(&asoc->asconf_ack_sent, ack, next); michael@0: if (ack->data != NULL) { michael@0: sctp_m_freem(ack->data); michael@0: } michael@0: SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_asconf_ack), ack); michael@0: } michael@0: } michael@0: michael@0: m_ack = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_ack_chunk), 0, michael@0: M_NOWAIT, 1, MT_DATA); michael@0: if (m_ack == NULL) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "handle_asconf: couldn't get mbuf!\n"); michael@0: return; michael@0: } michael@0: m_tail = m_ack; /* current reply chain's tail */ michael@0: michael@0: /* fill in ASCONF-ACK header */ michael@0: ack_cp = mtod(m_ack, struct sctp_asconf_ack_chunk *); michael@0: ack_cp->ch.chunk_type = SCTP_ASCONF_ACK; michael@0: ack_cp->ch.chunk_flags = 0; michael@0: ack_cp->serial_number = htonl(serial_num); michael@0: /* set initial lengths (eg. just an ASCONF-ACK), ntohx at the end! */ michael@0: SCTP_BUF_LEN(m_ack) = sizeof(struct sctp_asconf_ack_chunk); michael@0: ack_cp->ch.chunk_length = sizeof(struct sctp_asconf_ack_chunk); michael@0: michael@0: /* skip the lookup address parameter */ michael@0: offset += sizeof(struct sctp_asconf_chunk); michael@0: p_addr = (struct sctp_ipv6addr_param *)sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), (uint8_t *)&aparam_buf); michael@0: if (p_addr == NULL) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "handle_asconf: couldn't get lookup addr!\n"); michael@0: /* respond with a missing/invalid mandatory parameter error */ michael@0: return; michael@0: } michael@0: /* param_length is already validated in process_control... */ michael@0: offset += ntohs(p_addr->ph.param_length); /* skip lookup addr */ michael@0: michael@0: /* get pointer to first asconf param in ASCONF-ACK */ michael@0: ack_aph = (struct sctp_asconf_paramhdr *)(mtod(m_ack, caddr_t) + sizeof(struct sctp_asconf_ack_chunk)); michael@0: if (ack_aph == NULL) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "Gak in asconf2\n"); michael@0: return; michael@0: } michael@0: /* get pointer to first asconf param in ASCONF */ michael@0: aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, sizeof(struct sctp_asconf_paramhdr), (uint8_t *)&aparam_buf); michael@0: if (aph == NULL) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "Empty ASCONF received?\n"); michael@0: goto send_reply; michael@0: } michael@0: /* process through all parameters */ michael@0: cnt = 0; michael@0: while (aph != NULL) { michael@0: unsigned int param_length, param_type; michael@0: michael@0: param_type = ntohs(aph->ph.param_type); michael@0: param_length = ntohs(aph->ph.param_length); michael@0: if (offset + param_length > asconf_limit) { michael@0: /* parameter goes beyond end of chunk! */ michael@0: sctp_m_freem(m_ack); michael@0: return; michael@0: } michael@0: m_result = NULL; michael@0: michael@0: if (param_length > sizeof(aparam_buf)) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) larger than buffer size!\n", param_length); michael@0: sctp_m_freem(m_ack); michael@0: return; michael@0: } michael@0: if (param_length <= sizeof(struct sctp_paramhdr)) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) too short\n", param_length); michael@0: sctp_m_freem(m_ack); michael@0: } michael@0: /* get the entire parameter */ michael@0: aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf); michael@0: if (aph == NULL) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: couldn't get entire param\n"); michael@0: sctp_m_freem(m_ack); michael@0: return; michael@0: } michael@0: switch (param_type) { michael@0: case SCTP_ADD_IP_ADDRESS: michael@0: asoc->peer_supports_asconf = 1; michael@0: m_result = sctp_process_asconf_add_ip(src, aph, stcb, michael@0: (cnt < SCTP_BASE_SYSCTL(sctp_hb_maxburst)), error); michael@0: cnt++; michael@0: break; michael@0: case SCTP_DEL_IP_ADDRESS: michael@0: asoc->peer_supports_asconf = 1; michael@0: m_result = sctp_process_asconf_delete_ip(src, aph, stcb, michael@0: error); michael@0: break; michael@0: case SCTP_ERROR_CAUSE_IND: michael@0: /* not valid in an ASCONF chunk */ michael@0: break; michael@0: case SCTP_SET_PRIM_ADDR: michael@0: asoc->peer_supports_asconf = 1; michael@0: m_result = sctp_process_asconf_set_primary(src, aph, michael@0: stcb, error); michael@0: break; michael@0: case SCTP_NAT_VTAGS: michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: sees a NAT VTAG state parameter\n"); michael@0: break; michael@0: case SCTP_SUCCESS_REPORT: michael@0: /* not valid in an ASCONF chunk */ michael@0: break; michael@0: case SCTP_ULP_ADAPTATION: michael@0: /* FIX */ michael@0: break; michael@0: default: michael@0: if ((param_type & 0x8000) == 0) { michael@0: /* Been told to STOP at this param */ michael@0: asconf_limit = offset; michael@0: /* michael@0: * FIX FIX - We need to call michael@0: * sctp_arethere_unrecognized_parameters() michael@0: * to get a operr and send it for any michael@0: * param's with the 0x4000 bit set OR do it michael@0: * here ourselves... note we still must STOP michael@0: * if the 0x8000 bit is clear. michael@0: */ michael@0: } michael@0: /* unknown/invalid param type */ michael@0: break; michael@0: } /* switch */ michael@0: michael@0: /* add any (error) result to the reply mbuf chain */ michael@0: if (m_result != NULL) { michael@0: SCTP_BUF_NEXT(m_tail) = m_result; michael@0: m_tail = m_result; michael@0: /* update lengths, make sure it's aligned too */ michael@0: SCTP_BUF_LEN(m_result) = SCTP_SIZE32(SCTP_BUF_LEN(m_result)); michael@0: ack_cp->ch.chunk_length += SCTP_BUF_LEN(m_result); michael@0: /* set flag to force success reports */ michael@0: error = 1; michael@0: } michael@0: offset += SCTP_SIZE32(param_length); michael@0: /* update remaining ASCONF message length to process */ michael@0: if (offset >= asconf_limit) { michael@0: /* no more data in the mbuf chain */ michael@0: break; michael@0: } michael@0: /* get pointer to next asconf param */ michael@0: aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, michael@0: sizeof(struct sctp_asconf_paramhdr), michael@0: (uint8_t *)&aparam_buf); michael@0: if (aph == NULL) { michael@0: /* can't get an asconf paramhdr */ michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: can't get asconf param hdr!\n"); michael@0: /* FIX ME - add error here... */ michael@0: } michael@0: } michael@0: michael@0: send_reply: michael@0: ack_cp->ch.chunk_length = htons(ack_cp->ch.chunk_length); michael@0: /* save the ASCONF-ACK reply */ michael@0: ack = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_asconf_ack), michael@0: struct sctp_asconf_ack); michael@0: if (ack == NULL) { michael@0: sctp_m_freem(m_ack); michael@0: return; michael@0: } michael@0: ack->serial_number = serial_num; michael@0: ack->last_sent_to = NULL; michael@0: ack->data = m_ack; michael@0: ack->len = 0; michael@0: for (n = m_ack; n != NULL; n = SCTP_BUF_NEXT(n)) { michael@0: ack->len += SCTP_BUF_LEN(n); michael@0: } michael@0: TAILQ_INSERT_TAIL(&stcb->asoc.asconf_ack_sent, ack, next); michael@0: michael@0: /* see if last_control_chunk_from is set properly (use IP src addr) */ michael@0: if (stcb->asoc.last_control_chunk_from == NULL) { michael@0: /* michael@0: * this could happen if the source address was just newly michael@0: * added michael@0: */ michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: looking up net for IP source address\n"); michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "Looking for IP source: "); michael@0: SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, src); michael@0: /* look up the from address */ michael@0: stcb->asoc.last_control_chunk_from = sctp_findnet(stcb, src); michael@0: #ifdef SCTP_DEBUG michael@0: if (stcb->asoc.last_control_chunk_from == NULL) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: IP source address not found?!\n"); michael@0: } michael@0: #endif michael@0: } michael@0: } michael@0: michael@0: /* michael@0: * does the address match? returns 0 if not, 1 if so michael@0: */ michael@0: static uint32_t michael@0: sctp_asconf_addr_match(struct sctp_asconf_addr *aa, struct sockaddr *sa) michael@0: { michael@0: switch (sa->sa_family) { michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: { michael@0: /* XXX scopeid */ michael@0: struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa; michael@0: michael@0: if ((aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) && michael@0: (memcmp(&aa->ap.addrp.addr, &sin6->sin6_addr, michael@0: sizeof(struct in6_addr)) == 0)) { michael@0: return (1); michael@0: } michael@0: break; michael@0: } michael@0: #endif michael@0: #ifdef INET michael@0: case AF_INET: michael@0: { michael@0: struct sockaddr_in *sin = (struct sockaddr_in *)sa; michael@0: michael@0: if ((aa->ap.addrp.ph.param_type == SCTP_IPV4_ADDRESS) && michael@0: (memcmp(&aa->ap.addrp.addr, &sin->sin_addr, michael@0: sizeof(struct in_addr)) == 0)) { michael@0: return (1); michael@0: } michael@0: break; michael@0: } michael@0: #endif michael@0: default: michael@0: break; michael@0: } michael@0: return (0); michael@0: } michael@0: michael@0: /* michael@0: * does the address match? returns 0 if not, 1 if so michael@0: */ michael@0: static uint32_t michael@0: sctp_addr_match(struct sctp_paramhdr *ph, struct sockaddr *sa) michael@0: { michael@0: #if defined(INET) || defined(INET6) michael@0: uint16_t param_type, param_length; michael@0: michael@0: param_type = ntohs(ph->param_type); michael@0: param_length = ntohs(ph->param_length); michael@0: #endif michael@0: switch (sa->sa_family) { michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: { michael@0: /* XXX scopeid */ michael@0: struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa; michael@0: struct sctp_ipv6addr_param *v6addr; michael@0: michael@0: v6addr = (struct sctp_ipv6addr_param *)ph; michael@0: if ((param_type == SCTP_IPV6_ADDRESS) && michael@0: (param_length == sizeof(struct sctp_ipv6addr_param)) && michael@0: (memcmp(&v6addr->addr, &sin6->sin6_addr, michael@0: sizeof(struct in6_addr)) == 0)) { michael@0: return (1); michael@0: } michael@0: break; michael@0: } michael@0: #endif michael@0: #ifdef INET michael@0: case AF_INET: michael@0: { michael@0: struct sockaddr_in *sin = (struct sockaddr_in *)sa; michael@0: struct sctp_ipv4addr_param *v4addr; michael@0: michael@0: v4addr = (struct sctp_ipv4addr_param *)ph; michael@0: if ((param_type == SCTP_IPV4_ADDRESS) && michael@0: (param_length == sizeof(struct sctp_ipv4addr_param)) && michael@0: (memcmp(&v4addr->addr, &sin->sin_addr, michael@0: sizeof(struct in_addr)) == 0)) { michael@0: return (1); michael@0: } michael@0: break; michael@0: } michael@0: #endif michael@0: default: michael@0: break; michael@0: } michael@0: return (0); michael@0: } michael@0: /* michael@0: * Cleanup for non-responded/OP ERR'd ASCONF michael@0: */ michael@0: void michael@0: sctp_asconf_cleanup(struct sctp_tcb *stcb, struct sctp_nets *net) michael@0: { michael@0: /* mark peer as ASCONF incapable */ michael@0: stcb->asoc.peer_supports_asconf = 0; michael@0: /* michael@0: * clear out any existing asconfs going out michael@0: */ michael@0: sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, net, michael@0: SCTP_FROM_SCTP_ASCONF+SCTP_LOC_2); michael@0: stcb->asoc.asconf_seq_out_acked = stcb->asoc.asconf_seq_out; michael@0: /* remove the old ASCONF on our outbound queue */ michael@0: sctp_toss_old_asconf(stcb); michael@0: } michael@0: michael@0: /* michael@0: * cleanup any cached source addresses that may be topologically michael@0: * incorrect after a new address has been added to this interface. michael@0: */ michael@0: static void michael@0: sctp_asconf_nets_cleanup(struct sctp_tcb *stcb, struct sctp_ifn *ifn) michael@0: { michael@0: struct sctp_nets *net; michael@0: michael@0: /* michael@0: * Ideally, we want to only clear cached routes and source addresses michael@0: * that are topologically incorrect. But since there is no easy way michael@0: * to know whether the newly added address on the ifn would cause a michael@0: * routing change (i.e. a new egress interface would be chosen) michael@0: * without doing a new routing lookup and source address selection, michael@0: * we will (for now) just flush any cached route using a different michael@0: * ifn (and cached source addrs) and let output re-choose them during michael@0: * the next send on that net. michael@0: */ michael@0: TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { michael@0: /* michael@0: * clear any cached route (and cached source address) if the michael@0: * route's interface is NOT the same as the address change. michael@0: * If it's the same interface, just clear the cached source michael@0: * address. michael@0: */ michael@0: if (SCTP_ROUTE_HAS_VALID_IFN(&net->ro) && michael@0: ((ifn == NULL) || michael@0: (SCTP_GET_IF_INDEX_FROM_ROUTE(&net->ro) != ifn->ifn_index))) { michael@0: /* clear any cached route */ michael@0: RTFREE(net->ro.ro_rt); michael@0: net->ro.ro_rt = NULL; michael@0: } michael@0: /* clear any cached source address */ michael@0: if (net->src_addr_selected) { michael@0: sctp_free_ifa(net->ro._s_addr); michael@0: net->ro._s_addr = NULL; michael@0: net->src_addr_selected = 0; michael@0: } michael@0: } michael@0: } michael@0: michael@0: michael@0: void michael@0: sctp_assoc_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *dstnet) michael@0: { michael@0: int error; michael@0: michael@0: if (dstnet->dest_state & SCTP_ADDR_UNCONFIRMED) { michael@0: return; michael@0: } michael@0: if (stcb->asoc.deleted_primary == NULL) { michael@0: return; michael@0: } michael@0: michael@0: if (!TAILQ_EMPTY(&stcb->asoc.sent_queue)) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "assoc_immediate_retrans: Deleted primary is "); michael@0: SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &stcb->asoc.deleted_primary->ro._l_addr.sa); michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "Current Primary is "); michael@0: SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &stcb->asoc.primary_destination->ro._l_addr.sa); michael@0: sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, michael@0: stcb->asoc.deleted_primary, michael@0: SCTP_FROM_SCTP_TIMER+SCTP_LOC_8); michael@0: stcb->asoc.num_send_timers_up--; michael@0: if (stcb->asoc.num_send_timers_up < 0) { michael@0: stcb->asoc.num_send_timers_up = 0; michael@0: } michael@0: SCTP_TCB_LOCK_ASSERT(stcb); michael@0: error = sctp_t3rxt_timer(stcb->sctp_ep, stcb, michael@0: stcb->asoc.deleted_primary); michael@0: if (error) { michael@0: SCTP_INP_DECR_REF(stcb->sctp_ep); michael@0: return; michael@0: } michael@0: SCTP_TCB_LOCK_ASSERT(stcb); michael@0: #ifdef SCTP_AUDITING_ENABLED michael@0: sctp_auditing(4, stcb->sctp_ep, stcb, stcb->asoc.deleted_primary); michael@0: #endif michael@0: sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED); michael@0: if ((stcb->asoc.num_send_timers_up == 0) && michael@0: (stcb->asoc.sent_queue_cnt > 0)) { michael@0: struct sctp_tmit_chunk *chk; michael@0: michael@0: chk = TAILQ_FIRST(&stcb->asoc.sent_queue); michael@0: sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, michael@0: stcb, chk->whoTo); michael@0: } michael@0: } michael@0: return; michael@0: } michael@0: michael@0: #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Userspace__) michael@0: static int michael@0: sctp_asconf_queue_mgmt(struct sctp_tcb *, struct sctp_ifa *, uint16_t); michael@0: michael@0: void michael@0: sctp_net_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *net) michael@0: { michael@0: struct sctp_tmit_chunk *chk; michael@0: michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "net_immediate_retrans: RTO is %d\n", net->RTO); michael@0: sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, net, michael@0: SCTP_FROM_SCTP_TIMER+SCTP_LOC_5); michael@0: stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net); michael@0: net->error_count = 0; michael@0: TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) { michael@0: if (chk->whoTo == net) { michael@0: if (chk->sent < SCTP_DATAGRAM_RESEND) { michael@0: chk->sent = SCTP_DATAGRAM_RESEND; michael@0: sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt); michael@0: sctp_flight_size_decrease(chk); michael@0: sctp_total_flight_decrease(stcb, chk); michael@0: net->marked_retrans++; michael@0: stcb->asoc.marked_retrans++; michael@0: } michael@0: } michael@0: } michael@0: if (net->marked_retrans) { michael@0: sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED); michael@0: } michael@0: } michael@0: michael@0: static void michael@0: sctp_path_check_and_react(struct sctp_tcb *stcb, struct sctp_ifa *newifa) michael@0: { michael@0: struct sctp_nets *net; michael@0: int addrnum, changed; michael@0: michael@0: /* If number of local valid addresses is 1, the valid address is michael@0: probably newly added address. michael@0: Several valid addresses in this association. A source address michael@0: may not be changed. Additionally, they can be configured on a michael@0: same interface as "alias" addresses. (by micchie) michael@0: */ michael@0: addrnum = sctp_local_addr_count(stcb); michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "p_check_react(): %d local addresses\n", michael@0: addrnum); michael@0: if (addrnum == 1) { michael@0: TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { michael@0: /* clear any cached route and source address */ michael@0: if (net->ro.ro_rt) { michael@0: RTFREE(net->ro.ro_rt); michael@0: net->ro.ro_rt = NULL; michael@0: } michael@0: if (net->src_addr_selected) { michael@0: sctp_free_ifa(net->ro._s_addr); michael@0: net->ro._s_addr = NULL; michael@0: net->src_addr_selected = 0; michael@0: } michael@0: /* Retransmit unacknowledged DATA chunks immediately */ michael@0: if (sctp_is_mobility_feature_on(stcb->sctp_ep, michael@0: SCTP_MOBILITY_FASTHANDOFF)) { michael@0: sctp_net_immediate_retrans(stcb, net); michael@0: } michael@0: /* also, SET PRIMARY is maybe already sent */ michael@0: } michael@0: return; michael@0: } michael@0: michael@0: /* Multiple local addresses exsist in the association. */ michael@0: TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { michael@0: /* clear any cached route and source address */ michael@0: if (net->ro.ro_rt) { michael@0: RTFREE(net->ro.ro_rt); michael@0: net->ro.ro_rt = NULL; michael@0: } michael@0: if (net->src_addr_selected) { michael@0: sctp_free_ifa(net->ro._s_addr); michael@0: net->ro._s_addr = NULL; michael@0: net->src_addr_selected = 0; michael@0: } michael@0: /* Check if the nexthop is corresponding to the new address. michael@0: If the new address is corresponding to the current nexthop, michael@0: the path will be changed. michael@0: If the new address is NOT corresponding to the current michael@0: nexthop, the path will not be changed. michael@0: */ michael@0: SCTP_RTALLOC((sctp_route_t *)&net->ro, michael@0: stcb->sctp_ep->def_vrf_id); michael@0: if (net->ro.ro_rt == NULL) michael@0: continue; michael@0: michael@0: changed = 0; michael@0: switch (net->ro._l_addr.sa.sa_family) { michael@0: #ifdef INET michael@0: case AF_INET: michael@0: if (sctp_v4src_match_nexthop(newifa, (sctp_route_t *)&net->ro)) { michael@0: changed = 1; michael@0: } michael@0: break; michael@0: #endif michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: if (sctp_v6src_match_nexthop( michael@0: &newifa->address.sin6, (sctp_route_t *)&net->ro)) { michael@0: changed = 1; michael@0: } michael@0: break; michael@0: #endif michael@0: default: michael@0: break; michael@0: } michael@0: /* if the newly added address does not relate routing michael@0: information, we skip. michael@0: */ michael@0: if (changed == 0) michael@0: continue; michael@0: /* Retransmit unacknowledged DATA chunks immediately */ michael@0: if (sctp_is_mobility_feature_on(stcb->sctp_ep, michael@0: SCTP_MOBILITY_FASTHANDOFF)) { michael@0: sctp_net_immediate_retrans(stcb, net); michael@0: } michael@0: /* Send SET PRIMARY for this new address */ michael@0: if (net == stcb->asoc.primary_destination) { michael@0: (void)sctp_asconf_queue_mgmt(stcb, newifa, michael@0: SCTP_SET_PRIM_ADDR); michael@0: } michael@0: } michael@0: } michael@0: #endif /* __FreeBSD__ __APPLE__ __Userspace__ */ michael@0: michael@0: /* michael@0: * process an ADD/DELETE IP ack from peer. michael@0: * addr: corresponding sctp_ifa to the address being added/deleted. michael@0: * type: SCTP_ADD_IP_ADDRESS or SCTP_DEL_IP_ADDRESS. michael@0: * flag: 1=success, 0=failure. michael@0: */ michael@0: static void michael@0: sctp_asconf_addr_mgmt_ack(struct sctp_tcb *stcb, struct sctp_ifa *addr, uint32_t flag) michael@0: { michael@0: /* michael@0: * do the necessary asoc list work- if we get a failure indication, michael@0: * leave the address on the assoc's restricted list. If we get a michael@0: * success indication, remove the address from the restricted list. michael@0: */ michael@0: /* michael@0: * Note: this will only occur for ADD_IP_ADDRESS, since michael@0: * DEL_IP_ADDRESS is never actually added to the list... michael@0: */ michael@0: if (flag) { michael@0: /* success case, so remove from the restricted list */ michael@0: sctp_del_local_addr_restricted(stcb, addr); michael@0: michael@0: #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Userspace__) michael@0: if (sctp_is_mobility_feature_on(stcb->sctp_ep, michael@0: SCTP_MOBILITY_BASE) || michael@0: sctp_is_mobility_feature_on(stcb->sctp_ep, michael@0: SCTP_MOBILITY_FASTHANDOFF)) { michael@0: sctp_path_check_and_react(stcb, addr); michael@0: return; michael@0: } michael@0: #endif /* __FreeBSD__ __APPLE__ __Userspace__ */ michael@0: /* clear any cached/topologically incorrect source addresses */ michael@0: sctp_asconf_nets_cleanup(stcb, addr->ifn_p); michael@0: } michael@0: /* else, leave it on the list */ michael@0: } michael@0: michael@0: /* michael@0: * add an asconf add/delete/set primary IP address parameter to the queue. michael@0: * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR. michael@0: * returns 0 if queued, -1 if not queued/removed. michael@0: * NOTE: if adding, but a delete for the same address is already scheduled michael@0: * (and not yet sent out), simply remove it from queue. Same for deleting michael@0: * an address already scheduled for add. If a duplicate operation is found, michael@0: * ignore the new one. michael@0: */ michael@0: static int michael@0: sctp_asconf_queue_mgmt(struct sctp_tcb *stcb, struct sctp_ifa *ifa, michael@0: uint16_t type) michael@0: { michael@0: struct sctp_asconf_addr *aa, *aa_next; michael@0: michael@0: /* make sure the request isn't already in the queue */ michael@0: TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) { michael@0: /* address match? */ michael@0: if (sctp_asconf_addr_match(aa, &ifa->address.sa) == 0) michael@0: continue; michael@0: /* is the request already in queue but not sent? michael@0: * pass the request already sent in order to resolve the following case: michael@0: * 1. arrival of ADD, then sent michael@0: * 2. arrival of DEL. we can't remove the ADD request already sent michael@0: * 3. arrival of ADD michael@0: */ michael@0: if (aa->ap.aph.ph.param_type == type && aa->sent == 0) { michael@0: return (-1); michael@0: } michael@0: /* is the negative request already in queue, and not sent */ michael@0: if ((aa->sent == 0) && (type == SCTP_ADD_IP_ADDRESS) && michael@0: (aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS)) { michael@0: /* add requested, delete already queued */ michael@0: TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next); michael@0: /* remove the ifa from the restricted list */ michael@0: sctp_del_local_addr_restricted(stcb, ifa); michael@0: /* free the asconf param */ michael@0: SCTP_FREE(aa, SCTP_M_ASC_ADDR); michael@0: SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_mgmt: add removes queued entry\n"); michael@0: return (-1); michael@0: } michael@0: if ((aa->sent == 0) && (type == SCTP_DEL_IP_ADDRESS) && michael@0: (aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS)) { michael@0: /* delete requested, add already queued */ michael@0: TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next); michael@0: /* remove the aa->ifa from the restricted list */ michael@0: sctp_del_local_addr_restricted(stcb, aa->ifa); michael@0: /* free the asconf param */ michael@0: SCTP_FREE(aa, SCTP_M_ASC_ADDR); michael@0: SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_mgmt: delete removes queued entry\n"); michael@0: return (-1); michael@0: } michael@0: } /* for each aa */ michael@0: michael@0: /* adding new request to the queue */ michael@0: SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), michael@0: SCTP_M_ASC_ADDR); michael@0: if (aa == NULL) { michael@0: /* didn't get memory */ michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "asconf_queue_mgmt: failed to get memory!\n"); michael@0: return (-1); michael@0: } michael@0: aa->special_del = 0; michael@0: /* fill in asconf address parameter fields */ michael@0: /* top level elements are "networked" during send */ michael@0: aa->ap.aph.ph.param_type = type; michael@0: aa->ifa = ifa; michael@0: atomic_add_int(&ifa->refcount, 1); michael@0: /* correlation_id filled in during send routine later... */ michael@0: switch (ifa->address.sa.sa_family) { michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: { michael@0: struct sockaddr_in6 *sin6; michael@0: michael@0: sin6 = (struct sockaddr_in6 *)&ifa->address.sa; michael@0: aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS; michael@0: aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param)); michael@0: aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + michael@0: sizeof(struct sctp_ipv6addr_param); michael@0: memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr, michael@0: sizeof(struct in6_addr)); michael@0: break; michael@0: } michael@0: #endif michael@0: #ifdef INET michael@0: case AF_INET: michael@0: { michael@0: struct sockaddr_in *sin; michael@0: michael@0: sin= (struct sockaddr_in *)&ifa->address.sa; michael@0: aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS; michael@0: aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param)); michael@0: aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + michael@0: sizeof(struct sctp_ipv4addr_param); michael@0: memcpy(&aa->ap.addrp.addr, &sin->sin_addr, michael@0: sizeof(struct in_addr)); michael@0: break; michael@0: } michael@0: #endif michael@0: default: michael@0: /* invalid family! */ michael@0: SCTP_FREE(aa, SCTP_M_ASC_ADDR); michael@0: sctp_free_ifa(ifa); michael@0: return (-1); michael@0: } michael@0: aa->sent = 0; /* clear sent flag */ michael@0: michael@0: TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); michael@0: #ifdef SCTP_DEBUG michael@0: if (SCTP_BASE_SYSCTL(sctp_debug_on) & SCTP_DEBUG_ASCONF2) { michael@0: if (type == SCTP_ADD_IP_ADDRESS) { michael@0: SCTP_PRINTF("asconf_queue_mgmt: inserted asconf ADD_IP_ADDRESS: "); michael@0: SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa); michael@0: } else if (type == SCTP_DEL_IP_ADDRESS) { michael@0: SCTP_PRINTF("asconf_queue_mgmt: appended asconf DEL_IP_ADDRESS: "); michael@0: SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa); michael@0: } else { michael@0: SCTP_PRINTF("asconf_queue_mgmt: appended asconf SET_PRIM_ADDR: "); michael@0: SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, &ifa->address.sa); michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: return (0); michael@0: } michael@0: michael@0: michael@0: /* michael@0: * add an asconf operation for the given ifa and type. michael@0: * type = SCTP_ADD_IP_ADDRESS, SCTP_DEL_IP_ADDRESS, SCTP_SET_PRIM_ADDR. michael@0: * returns 0 if completed, -1 if not completed, 1 if immediate send is michael@0: * advisable. michael@0: */ michael@0: static int michael@0: sctp_asconf_queue_add(struct sctp_tcb *stcb, struct sctp_ifa *ifa, michael@0: uint16_t type) michael@0: { michael@0: uint32_t status; michael@0: int pending_delete_queued = 0; michael@0: michael@0: /* see if peer supports ASCONF */ michael@0: if (stcb->asoc.peer_supports_asconf == 0) { michael@0: return (-1); michael@0: } michael@0: michael@0: /* michael@0: * if this is deleting the last address from the assoc, mark it as michael@0: * pending. michael@0: */ michael@0: if ((type == SCTP_DEL_IP_ADDRESS) && !stcb->asoc.asconf_del_pending && michael@0: (sctp_local_addr_count(stcb) < 2)) { michael@0: /* set the pending delete info only */ michael@0: stcb->asoc.asconf_del_pending = 1; michael@0: stcb->asoc.asconf_addr_del_pending = ifa; michael@0: atomic_add_int(&ifa->refcount, 1); michael@0: SCTPDBG(SCTP_DEBUG_ASCONF2, michael@0: "asconf_queue_add: mark delete last address pending\n"); michael@0: return (-1); michael@0: } michael@0: michael@0: /* queue an asconf parameter */ michael@0: status = sctp_asconf_queue_mgmt(stcb, ifa, type); michael@0: michael@0: /* michael@0: * if this is an add, and there is a delete also pending (i.e. the michael@0: * last local address is being changed), queue the pending delete too. michael@0: */ michael@0: if ((type == SCTP_ADD_IP_ADDRESS) && stcb->asoc.asconf_del_pending && (status == 0)) { michael@0: /* queue in the pending delete */ michael@0: if (sctp_asconf_queue_mgmt(stcb, michael@0: stcb->asoc.asconf_addr_del_pending, michael@0: SCTP_DEL_IP_ADDRESS) == 0) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_add: queing pending delete\n"); michael@0: pending_delete_queued = 1; michael@0: /* clear out the pending delete info */ michael@0: stcb->asoc.asconf_del_pending = 0; michael@0: sctp_free_ifa(stcb->asoc.asconf_addr_del_pending); michael@0: stcb->asoc.asconf_addr_del_pending = NULL; michael@0: } michael@0: } michael@0: michael@0: if (pending_delete_queued) { michael@0: struct sctp_nets *net; michael@0: /* michael@0: * since we know that the only/last address is now being michael@0: * changed in this case, reset the cwnd/rto on all nets to michael@0: * start as a new address and path. Also clear the error michael@0: * counts to give the assoc the best chance to complete the michael@0: * address change. michael@0: */ michael@0: TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { michael@0: stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, michael@0: net); michael@0: net->RTO = 0; michael@0: net->error_count = 0; michael@0: } michael@0: stcb->asoc.overall_error_count = 0; michael@0: if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { michael@0: sctp_misc_ints(SCTP_THRESHOLD_CLEAR, michael@0: stcb->asoc.overall_error_count, michael@0: 0, michael@0: SCTP_FROM_SCTP_ASCONF, michael@0: __LINE__); michael@0: } michael@0: michael@0: /* queue in an advisory set primary too */ michael@0: (void)sctp_asconf_queue_mgmt(stcb, ifa, SCTP_SET_PRIM_ADDR); michael@0: /* let caller know we should send this out immediately */ michael@0: status = 1; michael@0: } michael@0: return (status); michael@0: } michael@0: michael@0: /*- michael@0: * add an asconf delete IP address parameter to the queue by sockaddr and michael@0: * possibly with no sctp_ifa available. This is only called by the routine michael@0: * that checks the addresses in an INIT-ACK against the current address list. michael@0: * returns 0 if completed, non-zero if not completed. michael@0: * NOTE: if an add is already scheduled (and not yet sent out), simply michael@0: * remove it from queue. If a duplicate operation is found, ignore the michael@0: * new one. michael@0: */ michael@0: static int michael@0: sctp_asconf_queue_sa_delete(struct sctp_tcb *stcb, struct sockaddr *sa) michael@0: { michael@0: struct sctp_ifa *ifa; michael@0: struct sctp_asconf_addr *aa, *aa_next; michael@0: uint32_t vrf_id; michael@0: michael@0: if (stcb == NULL) { michael@0: return (-1); michael@0: } michael@0: /* see if peer supports ASCONF */ michael@0: if (stcb->asoc.peer_supports_asconf == 0) { michael@0: return (-1); michael@0: } michael@0: /* make sure the request isn't already in the queue */ michael@0: TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) { michael@0: /* address match? */ michael@0: if (sctp_asconf_addr_match(aa, sa) == 0) michael@0: continue; michael@0: /* is the request already in queue (sent or not) */ michael@0: if (aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) { michael@0: return (-1); michael@0: } michael@0: /* is the negative request already in queue, and not sent */ michael@0: if (aa->sent == 1) michael@0: continue; michael@0: if (aa->ap.aph.ph.param_type == SCTP_ADD_IP_ADDRESS) { michael@0: /* add already queued, so remove existing entry */ michael@0: TAILQ_REMOVE(&stcb->asoc.asconf_queue, aa, next); michael@0: sctp_del_local_addr_restricted(stcb, aa->ifa); michael@0: /* free the entry */ michael@0: SCTP_FREE(aa, SCTP_M_ASC_ADDR); michael@0: return (-1); michael@0: } michael@0: } /* for each aa */ michael@0: michael@0: /* find any existing ifa-- NOTE ifa CAN be allowed to be NULL */ michael@0: if (stcb) { michael@0: vrf_id = stcb->asoc.vrf_id; michael@0: } else { michael@0: vrf_id = SCTP_DEFAULT_VRFID; michael@0: } michael@0: ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED); michael@0: michael@0: /* adding new request to the queue */ michael@0: SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), michael@0: SCTP_M_ASC_ADDR); michael@0: if (aa == NULL) { michael@0: /* didn't get memory */ michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "sctp_asconf_queue_sa_delete: failed to get memory!\n"); michael@0: return (-1); michael@0: } michael@0: aa->special_del = 0; michael@0: /* fill in asconf address parameter fields */ michael@0: /* top level elements are "networked" during send */ michael@0: aa->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS; michael@0: aa->ifa = ifa; michael@0: if (ifa) michael@0: atomic_add_int(&ifa->refcount, 1); michael@0: /* correlation_id filled in during send routine later... */ michael@0: switch (sa->sa_family) { michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: { michael@0: /* IPv6 address */ michael@0: struct sockaddr_in6 *sin6; michael@0: michael@0: sin6 = (struct sockaddr_in6 *)sa; michael@0: aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS; michael@0: aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv6addr_param)); michael@0: aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv6addr_param); michael@0: memcpy(&aa->ap.addrp.addr, &sin6->sin6_addr, michael@0: sizeof(struct in6_addr)); michael@0: break; michael@0: } michael@0: #endif michael@0: #ifdef INET michael@0: case AF_INET: michael@0: { michael@0: /* IPv4 address */ michael@0: struct sockaddr_in *sin = (struct sockaddr_in *)sa; michael@0: michael@0: aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS; michael@0: aa->ap.addrp.ph.param_length = (sizeof(struct sctp_ipv4addr_param)); michael@0: aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_ipv4addr_param); michael@0: memcpy(&aa->ap.addrp.addr, &sin->sin_addr, michael@0: sizeof(struct in_addr)); michael@0: break; michael@0: } michael@0: #endif michael@0: default: michael@0: /* invalid family! */ michael@0: SCTP_FREE(aa, SCTP_M_ASC_ADDR); michael@0: if (ifa) michael@0: sctp_free_ifa(ifa); michael@0: return (-1); michael@0: } michael@0: aa->sent = 0; /* clear sent flag */ michael@0: michael@0: /* delete goes to the back of the queue */ michael@0: TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); michael@0: michael@0: /* sa_ignore MEMLEAK {memory is put on the tailq} */ michael@0: return (0); michael@0: } michael@0: michael@0: /* michael@0: * find a specific asconf param on our "sent" queue michael@0: */ michael@0: static struct sctp_asconf_addr * michael@0: sctp_asconf_find_param(struct sctp_tcb *stcb, uint32_t correlation_id) michael@0: { michael@0: struct sctp_asconf_addr *aa; michael@0: michael@0: TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) { michael@0: if (aa->ap.aph.correlation_id == correlation_id && michael@0: aa->sent == 1) { michael@0: /* found it */ michael@0: return (aa); michael@0: } michael@0: } michael@0: /* didn't find it */ michael@0: return (NULL); michael@0: } michael@0: michael@0: /* michael@0: * process an SCTP_ERROR_CAUSE_IND for a ASCONF-ACK parameter and do michael@0: * notifications based on the error response michael@0: */ michael@0: static void michael@0: sctp_asconf_process_error(struct sctp_tcb *stcb, michael@0: struct sctp_asconf_paramhdr *aph) michael@0: { michael@0: struct sctp_error_cause *eh; michael@0: struct sctp_paramhdr *ph; michael@0: uint16_t param_type; michael@0: uint16_t error_code; michael@0: michael@0: eh = (struct sctp_error_cause *)(aph + 1); michael@0: ph = (struct sctp_paramhdr *)(eh + 1); michael@0: /* validate lengths */ michael@0: if (htons(eh->length) + sizeof(struct sctp_error_cause) > michael@0: htons(aph->ph.param_length)) { michael@0: /* invalid error cause length */ michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "asconf_process_error: cause element too long\n"); michael@0: return; michael@0: } michael@0: if (htons(ph->param_length) + sizeof(struct sctp_paramhdr) > michael@0: htons(eh->length)) { michael@0: /* invalid included TLV length */ michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "asconf_process_error: included TLV too long\n"); michael@0: return; michael@0: } michael@0: /* which error code ? */ michael@0: error_code = ntohs(eh->code); michael@0: param_type = ntohs(aph->ph.param_type); michael@0: /* FIX: this should go back up the REMOTE_ERROR ULP notify */ michael@0: switch (error_code) { michael@0: case SCTP_CAUSE_RESOURCE_SHORTAGE: michael@0: /* we allow ourselves to "try again" for this error */ michael@0: break; michael@0: default: michael@0: /* peer can't handle it... */ michael@0: switch (param_type) { michael@0: case SCTP_ADD_IP_ADDRESS: michael@0: case SCTP_DEL_IP_ADDRESS: michael@0: stcb->asoc.peer_supports_asconf = 0; michael@0: break; michael@0: case SCTP_SET_PRIM_ADDR: michael@0: stcb->asoc.peer_supports_asconf = 0; michael@0: break; michael@0: default: michael@0: break; michael@0: } michael@0: } michael@0: } michael@0: michael@0: /* michael@0: * process an asconf queue param. michael@0: * aparam: parameter to process, will be removed from the queue. michael@0: * flag: 1=success case, 0=failure case michael@0: */ michael@0: static void michael@0: sctp_asconf_process_param_ack(struct sctp_tcb *stcb, michael@0: struct sctp_asconf_addr *aparam, uint32_t flag) michael@0: { michael@0: uint16_t param_type; michael@0: michael@0: /* process this param */ michael@0: param_type = aparam->ap.aph.ph.param_type; michael@0: switch (param_type) { michael@0: case SCTP_ADD_IP_ADDRESS: michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "process_param_ack: added IP address\n"); michael@0: sctp_asconf_addr_mgmt_ack(stcb, aparam->ifa, flag); michael@0: break; michael@0: case SCTP_DEL_IP_ADDRESS: michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "process_param_ack: deleted IP address\n"); michael@0: /* nothing really to do... lists already updated */ michael@0: break; michael@0: case SCTP_SET_PRIM_ADDR: michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "process_param_ack: set primary IP address\n"); michael@0: /* nothing to do... peer may start using this addr */ michael@0: if (flag == 0) michael@0: stcb->asoc.peer_supports_asconf = 0; michael@0: break; michael@0: default: michael@0: /* should NEVER happen */ michael@0: break; michael@0: } michael@0: michael@0: /* remove the param and free it */ michael@0: TAILQ_REMOVE(&stcb->asoc.asconf_queue, aparam, next); michael@0: if (aparam->ifa) michael@0: sctp_free_ifa(aparam->ifa); michael@0: SCTP_FREE(aparam, SCTP_M_ASC_ADDR); michael@0: } michael@0: michael@0: /* michael@0: * cleanup from a bad asconf ack parameter michael@0: */ michael@0: static void michael@0: sctp_asconf_ack_clear(struct sctp_tcb *stcb) michael@0: { michael@0: /* assume peer doesn't really know how to do asconfs */ michael@0: stcb->asoc.peer_supports_asconf = 0; michael@0: /* XXX we could free the pending queue here */ michael@0: } michael@0: michael@0: void michael@0: sctp_handle_asconf_ack(struct mbuf *m, int offset, michael@0: struct sctp_asconf_ack_chunk *cp, struct sctp_tcb *stcb, michael@0: struct sctp_nets *net, int *abort_no_unlock) michael@0: { michael@0: struct sctp_association *asoc; michael@0: uint32_t serial_num; michael@0: uint16_t ack_length; michael@0: struct sctp_asconf_paramhdr *aph; michael@0: struct sctp_asconf_addr *aa, *aa_next; michael@0: uint32_t last_error_id = 0; /* last error correlation id */ michael@0: uint32_t id; michael@0: struct sctp_asconf_addr *ap; michael@0: michael@0: /* asconf param buffer */ michael@0: uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE]; michael@0: michael@0: /* verify minimum length */ michael@0: if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_asconf_ack_chunk)) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "handle_asconf_ack: chunk too small = %xh\n", michael@0: ntohs(cp->ch.chunk_length)); michael@0: return; michael@0: } michael@0: asoc = &stcb->asoc; michael@0: serial_num = ntohl(cp->serial_number); michael@0: michael@0: /* michael@0: * NOTE: we may want to handle this differently- currently, we will michael@0: * abort when we get an ack for the expected serial number + 1 (eg. michael@0: * we didn't send it), process an ack normally if it is the expected michael@0: * serial number, and re-send the previous ack for *ALL* other michael@0: * serial numbers michael@0: */ michael@0: michael@0: /* michael@0: * if the serial number is the next expected, but I didn't send it, michael@0: * abort the asoc, since someone probably just hijacked us... michael@0: */ michael@0: if (serial_num == (asoc->asconf_seq_out + 1)) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got unexpected next serial number! Aborting asoc!\n"); michael@0: sctp_abort_an_association(stcb->sctp_ep, stcb, NULL, SCTP_SO_NOT_LOCKED); michael@0: *abort_no_unlock = 1; michael@0: return; michael@0: } michael@0: if (serial_num != asoc->asconf_seq_out_acked + 1) { michael@0: /* got a duplicate/unexpected ASCONF-ACK */ michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got duplicate/unexpected serial number = %xh (expected = %xh)\n", michael@0: serial_num, asoc->asconf_seq_out_acked + 1); michael@0: return; michael@0: } michael@0: michael@0: if (serial_num == asoc->asconf_seq_out - 1) { michael@0: /* stop our timer */ michael@0: sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, net, michael@0: SCTP_FROM_SCTP_ASCONF+SCTP_LOC_3); michael@0: } michael@0: michael@0: /* process the ASCONF-ACK contents */ michael@0: ack_length = ntohs(cp->ch.chunk_length) - michael@0: sizeof(struct sctp_asconf_ack_chunk); michael@0: offset += sizeof(struct sctp_asconf_ack_chunk); michael@0: /* process through all parameters */ michael@0: while (ack_length >= sizeof(struct sctp_asconf_paramhdr)) { michael@0: unsigned int param_length, param_type; michael@0: michael@0: /* get pointer to next asconf parameter */ michael@0: aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, michael@0: sizeof(struct sctp_asconf_paramhdr), aparam_buf); michael@0: if (aph == NULL) { michael@0: /* can't get an asconf paramhdr */ michael@0: sctp_asconf_ack_clear(stcb); michael@0: return; michael@0: } michael@0: param_type = ntohs(aph->ph.param_type); michael@0: param_length = ntohs(aph->ph.param_length); michael@0: if (param_length > ack_length) { michael@0: sctp_asconf_ack_clear(stcb); michael@0: return; michael@0: } michael@0: if (param_length < sizeof(struct sctp_paramhdr)) { michael@0: sctp_asconf_ack_clear(stcb); michael@0: return; michael@0: } michael@0: /* get the complete parameter... */ michael@0: if (param_length > sizeof(aparam_buf)) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "param length (%u) larger than buffer size!\n", param_length); michael@0: sctp_asconf_ack_clear(stcb); michael@0: return; michael@0: } michael@0: aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf); michael@0: if (aph == NULL) { michael@0: sctp_asconf_ack_clear(stcb); michael@0: return; michael@0: } michael@0: /* correlation_id is transparent to peer, no ntohl needed */ michael@0: id = aph->correlation_id; michael@0: michael@0: switch (param_type) { michael@0: case SCTP_ERROR_CAUSE_IND: michael@0: last_error_id = id; michael@0: /* find the corresponding asconf param in our queue */ michael@0: ap = sctp_asconf_find_param(stcb, id); michael@0: if (ap == NULL) { michael@0: /* hmm... can't find this in our queue! */ michael@0: break; michael@0: } michael@0: /* process the parameter, failed flag */ michael@0: sctp_asconf_process_param_ack(stcb, ap, 0); michael@0: /* process the error response */ michael@0: sctp_asconf_process_error(stcb, aph); michael@0: break; michael@0: case SCTP_SUCCESS_REPORT: michael@0: /* find the corresponding asconf param in our queue */ michael@0: ap = sctp_asconf_find_param(stcb, id); michael@0: if (ap == NULL) { michael@0: /* hmm... can't find this in our queue! */ michael@0: break; michael@0: } michael@0: /* process the parameter, success flag */ michael@0: sctp_asconf_process_param_ack(stcb, ap, 1); michael@0: break; michael@0: default: michael@0: break; michael@0: } /* switch */ michael@0: michael@0: /* update remaining ASCONF-ACK message length to process */ michael@0: ack_length -= SCTP_SIZE32(param_length); michael@0: if (ack_length <= 0) { michael@0: /* no more data in the mbuf chain */ michael@0: break; michael@0: } michael@0: offset += SCTP_SIZE32(param_length); michael@0: } /* while */ michael@0: michael@0: /* michael@0: * if there are any "sent" params still on the queue, these are michael@0: * implicitly "success", or "failed" (if we got an error back) ... michael@0: * so process these appropriately michael@0: * michael@0: * we assume that the correlation_id's are monotonically increasing michael@0: * beginning from 1 and that we don't have *that* many outstanding michael@0: * at any given time michael@0: */ michael@0: if (last_error_id == 0) michael@0: last_error_id--; /* set to "max" value */ michael@0: TAILQ_FOREACH_SAFE(aa, &stcb->asoc.asconf_queue, next, aa_next) { michael@0: if (aa->sent == 1) { michael@0: /* michael@0: * implicitly successful or failed if correlation_id michael@0: * < last_error_id, then success else, failure michael@0: */ michael@0: if (aa->ap.aph.correlation_id < last_error_id) michael@0: sctp_asconf_process_param_ack(stcb, aa, 1); michael@0: else michael@0: sctp_asconf_process_param_ack(stcb, aa, 0); michael@0: } else { michael@0: /* michael@0: * since we always process in order (FIFO queue) if michael@0: * we reach one that hasn't been sent, the rest michael@0: * should not have been sent either. so, we're michael@0: * done... michael@0: */ michael@0: break; michael@0: } michael@0: } michael@0: michael@0: /* update the next sequence number to use */ michael@0: asoc->asconf_seq_out_acked++; michael@0: /* remove the old ASCONF on our outbound queue */ michael@0: sctp_toss_old_asconf(stcb); michael@0: if (!TAILQ_EMPTY(&stcb->asoc.asconf_queue)) { michael@0: #ifdef SCTP_TIMER_BASED_ASCONF michael@0: /* we have more params, so restart our timer */ michael@0: sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, michael@0: stcb, net); michael@0: #else michael@0: /* we have more params, so send out more */ michael@0: sctp_send_asconf(stcb, net, SCTP_ADDR_NOT_LOCKED); michael@0: #endif michael@0: } michael@0: } michael@0: michael@0: #ifdef INET6 michael@0: static uint32_t michael@0: sctp_is_scopeid_in_nets(struct sctp_tcb *stcb, struct sockaddr *sa) michael@0: { michael@0: struct sockaddr_in6 *sin6, *net6; michael@0: struct sctp_nets *net; michael@0: michael@0: if (sa->sa_family != AF_INET6) { michael@0: /* wrong family */ michael@0: return (0); michael@0: } michael@0: sin6 = (struct sockaddr_in6 *)sa; michael@0: if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) == 0) { michael@0: /* not link local address */ michael@0: return (0); michael@0: } michael@0: /* hunt through our destination nets list for this scope_id */ michael@0: TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { michael@0: if (((struct sockaddr *)(&net->ro._l_addr))->sa_family != michael@0: AF_INET6) michael@0: continue; michael@0: net6 = (struct sockaddr_in6 *)&net->ro._l_addr; michael@0: if (IN6_IS_ADDR_LINKLOCAL(&net6->sin6_addr) == 0) michael@0: continue; michael@0: if (sctp_is_same_scope(sin6, net6)) { michael@0: /* found one */ michael@0: return (1); michael@0: } michael@0: } michael@0: /* didn't find one */ michael@0: return (0); michael@0: } michael@0: #endif michael@0: michael@0: /* michael@0: * address management functions michael@0: */ michael@0: static void michael@0: sctp_addr_mgmt_assoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb, michael@0: struct sctp_ifa *ifa, uint16_t type, int addr_locked) michael@0: { michael@0: int status; michael@0: michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0 || michael@0: sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_ASCONF)) { michael@0: /* subset bound, no ASCONF allowed case, so ignore */ michael@0: return; michael@0: } michael@0: /* michael@0: * note: we know this is not the subset bound, no ASCONF case eg. michael@0: * this is boundall or subset bound w/ASCONF allowed michael@0: */ michael@0: michael@0: /* first, make sure it's a good address family */ michael@0: switch (ifa->address.sa.sa_family) { michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: break; michael@0: #endif michael@0: #ifdef INET michael@0: case AF_INET: michael@0: break; michael@0: #endif michael@0: default: michael@0: return; michael@0: } michael@0: #ifdef INET6 michael@0: /* make sure we're "allowed" to add this type of addr */ michael@0: if (ifa->address.sa.sa_family == AF_INET6) { michael@0: /* invalid if we're not a v6 endpoint */ michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) michael@0: return; michael@0: /* is the v6 addr really valid ? */ michael@0: if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) { michael@0: return; michael@0: } michael@0: } michael@0: #endif michael@0: /* put this address on the "pending/do not use yet" list */ michael@0: sctp_add_local_addr_restricted(stcb, ifa); michael@0: /* michael@0: * check address scope if address is out of scope, don't queue michael@0: * anything... note: this would leave the address on both inp and michael@0: * asoc lists michael@0: */ michael@0: switch (ifa->address.sa.sa_family) { michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: { michael@0: struct sockaddr_in6 *sin6; michael@0: michael@0: sin6 = (struct sockaddr_in6 *)&ifa->address.sin6; michael@0: if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { michael@0: /* we skip unspecifed addresses */ michael@0: return; michael@0: } michael@0: if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { michael@0: if (stcb->asoc.scope.local_scope == 0) { michael@0: return; michael@0: } michael@0: /* is it the right link local scope? */ michael@0: if (sctp_is_scopeid_in_nets(stcb, &ifa->address.sa) == 0) { michael@0: return; michael@0: } michael@0: } michael@0: if (stcb->asoc.scope.site_scope == 0 && michael@0: IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)) { michael@0: return; michael@0: } michael@0: break; michael@0: } michael@0: #endif michael@0: #ifdef INET michael@0: case AF_INET: michael@0: { michael@0: struct sockaddr_in *sin; michael@0: struct in6pcb *inp6; michael@0: michael@0: inp6 = (struct in6pcb *)&inp->ip_inp.inp; michael@0: /* invalid if we are a v6 only endpoint */ michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) && michael@0: SCTP_IPV6_V6ONLY(inp6)) michael@0: return; michael@0: michael@0: sin = (struct sockaddr_in *)&ifa->address.sa; michael@0: if (sin->sin_addr.s_addr == 0) { michael@0: /* we skip unspecifed addresses */ michael@0: return; michael@0: } michael@0: if (stcb->asoc.scope.ipv4_local_scope == 0 && michael@0: IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) { michael@0: return; michael@0: } michael@0: break; michael@0: } michael@0: #endif michael@0: default: michael@0: /* else, not AF_INET or AF_INET6, so skip */ michael@0: return; michael@0: } michael@0: michael@0: /* queue an asconf for this address add/delete */ michael@0: if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF)) { michael@0: /* does the peer do asconf? */ michael@0: if (stcb->asoc.peer_supports_asconf) { michael@0: /* queue an asconf for this addr */ michael@0: status = sctp_asconf_queue_add(stcb, ifa, type); michael@0: michael@0: /* michael@0: * if queued ok, and in the open state, send out the michael@0: * ASCONF. If in the non-open state, these will be michael@0: * sent when the state goes open. michael@0: */ michael@0: if (status == 0 && michael@0: SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) { michael@0: #ifdef SCTP_TIMER_BASED_ASCONF michael@0: sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, inp, michael@0: stcb, stcb->asoc.primary_destination); michael@0: #else michael@0: sctp_send_asconf(stcb, NULL, addr_locked); michael@0: #endif michael@0: } michael@0: } michael@0: } michael@0: } michael@0: michael@0: michael@0: int michael@0: sctp_asconf_iterator_ep(struct sctp_inpcb *inp, void *ptr, uint32_t val SCTP_UNUSED) michael@0: { michael@0: struct sctp_asconf_iterator *asc; michael@0: struct sctp_ifa *ifa; michael@0: struct sctp_laddr *l; michael@0: int cnt_invalid = 0; michael@0: michael@0: asc = (struct sctp_asconf_iterator *)ptr; michael@0: LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) { michael@0: ifa = l->ifa; michael@0: switch (ifa->address.sa.sa_family) { michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: /* invalid if we're not a v6 endpoint */ michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) { michael@0: cnt_invalid++; michael@0: if (asc->cnt == cnt_invalid) michael@0: return (1); michael@0: } michael@0: break; michael@0: #endif michael@0: #ifdef INET michael@0: case AF_INET: michael@0: { michael@0: /* invalid if we are a v6 only endpoint */ michael@0: struct in6pcb *inp6; michael@0: inp6 = (struct in6pcb *)&inp->ip_inp.inp; michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) && michael@0: SCTP_IPV6_V6ONLY(inp6)) { michael@0: cnt_invalid++; michael@0: if (asc->cnt == cnt_invalid) michael@0: return (1); michael@0: } michael@0: break; michael@0: } michael@0: #endif michael@0: default: michael@0: /* invalid address family */ michael@0: cnt_invalid++; michael@0: if (asc->cnt == cnt_invalid) michael@0: return (1); michael@0: } michael@0: } michael@0: return (0); michael@0: } michael@0: michael@0: static int michael@0: sctp_asconf_iterator_ep_end(struct sctp_inpcb *inp, void *ptr, uint32_t val SCTP_UNUSED) michael@0: { michael@0: struct sctp_ifa *ifa; michael@0: struct sctp_asconf_iterator *asc; michael@0: struct sctp_laddr *laddr, *nladdr, *l; michael@0: michael@0: /* Only for specific case not bound all */ michael@0: asc = (struct sctp_asconf_iterator *)ptr; michael@0: LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) { michael@0: ifa = l->ifa; michael@0: if (l->action == SCTP_ADD_IP_ADDRESS) { michael@0: LIST_FOREACH(laddr, &inp->sctp_addr_list, michael@0: sctp_nxt_addr) { michael@0: if (laddr->ifa == ifa) { michael@0: laddr->action = 0; michael@0: break; michael@0: } michael@0: michael@0: } michael@0: } else if (l->action == SCTP_DEL_IP_ADDRESS) { michael@0: LIST_FOREACH_SAFE(laddr, &inp->sctp_addr_list, sctp_nxt_addr, nladdr) { michael@0: /* remove only after all guys are done */ michael@0: if (laddr->ifa == ifa) { michael@0: sctp_del_local_addr_ep(inp, ifa); michael@0: } michael@0: } michael@0: } michael@0: } michael@0: return (0); michael@0: } michael@0: michael@0: void michael@0: sctp_asconf_iterator_stcb(struct sctp_inpcb *inp, struct sctp_tcb *stcb, michael@0: void *ptr, uint32_t val SCTP_UNUSED) michael@0: { michael@0: struct sctp_asconf_iterator *asc; michael@0: struct sctp_ifa *ifa; michael@0: struct sctp_laddr *l; michael@0: int cnt_invalid = 0; michael@0: int type, status; michael@0: int num_queued = 0; michael@0: michael@0: asc = (struct sctp_asconf_iterator *)ptr; michael@0: LIST_FOREACH(l, &asc->list_of_work, sctp_nxt_addr) { michael@0: ifa = l->ifa; michael@0: type = l->action; michael@0: michael@0: /* address's vrf_id must be the vrf_id of the assoc */ michael@0: if (ifa->vrf_id != stcb->asoc.vrf_id) { michael@0: continue; michael@0: } michael@0: michael@0: /* Same checks again for assoc */ michael@0: switch (ifa->address.sa.sa_family) { michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: { michael@0: /* invalid if we're not a v6 endpoint */ michael@0: struct sockaddr_in6 *sin6; michael@0: michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) { michael@0: cnt_invalid++; michael@0: if (asc->cnt == cnt_invalid) michael@0: return; michael@0: else michael@0: continue; michael@0: } michael@0: sin6 = (struct sockaddr_in6 *)&ifa->address.sin6; michael@0: if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { michael@0: /* we skip unspecifed addresses */ michael@0: continue; michael@0: } michael@0: if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) { michael@0: if (stcb->asoc.scope.local_scope == 0) { michael@0: continue; michael@0: } michael@0: /* is it the right link local scope? */ michael@0: if (sctp_is_scopeid_in_nets(stcb, &ifa->address.sa) == 0) { michael@0: continue; michael@0: } michael@0: } michael@0: break; michael@0: } michael@0: #endif michael@0: #ifdef INET michael@0: case AF_INET: michael@0: { michael@0: /* invalid if we are a v6 only endpoint */ michael@0: struct in6pcb *inp6; michael@0: struct sockaddr_in *sin; michael@0: michael@0: inp6 = (struct in6pcb *)&inp->ip_inp.inp; michael@0: /* invalid if we are a v6 only endpoint */ michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) && michael@0: SCTP_IPV6_V6ONLY(inp6)) michael@0: continue; michael@0: michael@0: sin = (struct sockaddr_in *)&ifa->address.sa; michael@0: if (sin->sin_addr.s_addr == 0) { michael@0: /* we skip unspecifed addresses */ michael@0: continue; michael@0: } michael@0: if (stcb->asoc.scope.ipv4_local_scope == 0 && michael@0: IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) { michael@0: continue; michael@0: } michael@0: if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) && michael@0: SCTP_IPV6_V6ONLY(inp6)) { michael@0: cnt_invalid++; michael@0: if (asc->cnt == cnt_invalid) michael@0: return; michael@0: else michael@0: continue; michael@0: } michael@0: break; michael@0: } michael@0: #endif michael@0: default: michael@0: /* invalid address family */ michael@0: cnt_invalid++; michael@0: if (asc->cnt == cnt_invalid) michael@0: return; michael@0: else michael@0: continue; michael@0: break; michael@0: } michael@0: michael@0: if (type == SCTP_ADD_IP_ADDRESS) { michael@0: /* prevent this address from being used as a source */ michael@0: sctp_add_local_addr_restricted(stcb, ifa); michael@0: } else if (type == SCTP_DEL_IP_ADDRESS) { michael@0: struct sctp_nets *net; michael@0: TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { michael@0: sctp_rtentry_t *rt; michael@0: michael@0: /* delete this address if cached */ michael@0: if (net->ro._s_addr == ifa) { michael@0: sctp_free_ifa(net->ro._s_addr); michael@0: net->ro._s_addr = NULL; michael@0: net->src_addr_selected = 0; michael@0: rt = net->ro.ro_rt; michael@0: if (rt) { michael@0: RTFREE(rt); michael@0: net->ro.ro_rt = NULL; michael@0: } michael@0: /* michael@0: * Now we deleted our src address, michael@0: * should we not also now reset the michael@0: * cwnd/rto to start as if its a new michael@0: * address? michael@0: */ michael@0: stcb->asoc.cc_functions.sctp_set_initial_cc_param(stcb, net); michael@0: net->RTO = 0; michael@0: michael@0: } michael@0: } michael@0: } else if (type == SCTP_SET_PRIM_ADDR) { michael@0: if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) { michael@0: /* must validate the ifa is in the ep */ michael@0: if (sctp_is_addr_in_ep(stcb->sctp_ep,ifa) == 0) { michael@0: continue; michael@0: } michael@0: } else { michael@0: /* Need to check scopes for this guy */ michael@0: if (sctp_is_address_in_scope(ifa, &stcb->asoc.scope, 0) == 0) { michael@0: continue; michael@0: } michael@0: } michael@0: } michael@0: /* queue an asconf for this address add/delete */ michael@0: if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF) && michael@0: stcb->asoc.peer_supports_asconf) { michael@0: /* queue an asconf for this addr */ michael@0: status = sctp_asconf_queue_add(stcb, ifa, type); michael@0: /* michael@0: * if queued ok, and in the open state, update the michael@0: * count of queued params. If in the non-open state, michael@0: * these get sent when the assoc goes open. michael@0: */ michael@0: if (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) { michael@0: if (status >= 0) { michael@0: num_queued++; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: /* michael@0: * If we have queued params in the open state, send out an ASCONF. michael@0: */ michael@0: if (num_queued > 0) { michael@0: sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED); michael@0: } michael@0: } michael@0: michael@0: void michael@0: sctp_asconf_iterator_end(void *ptr, uint32_t val SCTP_UNUSED) michael@0: { michael@0: struct sctp_asconf_iterator *asc; michael@0: struct sctp_ifa *ifa; michael@0: struct sctp_laddr *l, *nl; michael@0: michael@0: asc = (struct sctp_asconf_iterator *)ptr; michael@0: LIST_FOREACH_SAFE(l, &asc->list_of_work, sctp_nxt_addr, nl) { michael@0: ifa = l->ifa; michael@0: if (l->action == SCTP_ADD_IP_ADDRESS) { michael@0: /* Clear the defer use flag */ michael@0: ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE; michael@0: } michael@0: sctp_free_ifa(ifa); michael@0: SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_laddr), l); michael@0: SCTP_DECR_LADDR_COUNT(); michael@0: } michael@0: SCTP_FREE(asc, SCTP_M_ASC_IT); michael@0: } michael@0: michael@0: /* michael@0: * sa is the sockaddr to ask the peer to set primary to. michael@0: * returns: 0 = completed, -1 = error michael@0: */ michael@0: int32_t michael@0: sctp_set_primary_ip_address_sa(struct sctp_tcb *stcb, struct sockaddr *sa) michael@0: { michael@0: uint32_t vrf_id; michael@0: struct sctp_ifa *ifa; michael@0: michael@0: /* find the ifa for the desired set primary */ michael@0: vrf_id = stcb->asoc.vrf_id; michael@0: ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED); michael@0: if (ifa == NULL) { michael@0: /* Invalid address */ michael@0: return (-1); michael@0: } michael@0: michael@0: /* queue an ASCONF:SET_PRIM_ADDR to be sent */ michael@0: if (!sctp_asconf_queue_add(stcb, ifa, SCTP_SET_PRIM_ADDR)) { michael@0: /* set primary queuing succeeded */ michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "set_primary_ip_address_sa: queued on tcb=%p, ", michael@0: (void *)stcb); michael@0: SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); michael@0: if (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) { michael@0: #ifdef SCTP_TIMER_BASED_ASCONF michael@0: sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, michael@0: stcb->sctp_ep, stcb, michael@0: stcb->asoc.primary_destination); michael@0: #else michael@0: sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED); michael@0: #endif michael@0: } michael@0: } else { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "set_primary_ip_address_sa: failed to add to queue on tcb=%p, ", michael@0: (void *)stcb); michael@0: SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa); michael@0: return (-1); michael@0: } michael@0: return (0); michael@0: } michael@0: michael@0: void michael@0: sctp_set_primary_ip_address(struct sctp_ifa *ifa) michael@0: { michael@0: struct sctp_inpcb *inp; michael@0: michael@0: /* go through all our PCB's */ michael@0: LIST_FOREACH(inp, &SCTP_BASE_INFO(listhead), sctp_list) { michael@0: struct sctp_tcb *stcb; michael@0: michael@0: /* process for all associations for this endpoint */ michael@0: LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { michael@0: /* queue an ASCONF:SET_PRIM_ADDR to be sent */ michael@0: if (!sctp_asconf_queue_add(stcb, ifa, michael@0: SCTP_SET_PRIM_ADDR)) { michael@0: /* set primary queuing succeeded */ michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "set_primary_ip_address: queued on stcb=%p, ", michael@0: (void *)stcb); michael@0: SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, &ifa->address.sa); michael@0: if (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) { michael@0: #ifdef SCTP_TIMER_BASED_ASCONF michael@0: sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, michael@0: stcb->sctp_ep, stcb, michael@0: stcb->asoc.primary_destination); michael@0: #else michael@0: sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED); michael@0: #endif michael@0: } michael@0: } michael@0: } /* for each stcb */ michael@0: } /* for each inp */ michael@0: } michael@0: michael@0: int michael@0: sctp_is_addr_pending(struct sctp_tcb *stcb, struct sctp_ifa *sctp_ifa) michael@0: { michael@0: struct sctp_tmit_chunk *chk, *nchk; michael@0: unsigned int offset, asconf_limit; michael@0: struct sctp_asconf_chunk *acp; michael@0: struct sctp_asconf_paramhdr *aph; michael@0: uint8_t aparam_buf[SCTP_PARAM_BUFFER_SIZE]; michael@0: struct sctp_paramhdr *ph; michael@0: int add_cnt, del_cnt; michael@0: uint16_t last_param_type; michael@0: michael@0: add_cnt = del_cnt = 0; michael@0: last_param_type = 0; michael@0: TAILQ_FOREACH_SAFE(chk, &stcb->asoc.asconf_send_queue, sctp_next, nchk) { michael@0: if (chk->data == NULL) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: No mbuf data?\n"); michael@0: continue; michael@0: } michael@0: offset = 0; michael@0: acp = mtod(chk->data, struct sctp_asconf_chunk *); michael@0: offset += sizeof(struct sctp_asconf_chunk); michael@0: asconf_limit = ntohs(acp->ch.chunk_length); michael@0: ph = (struct sctp_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_paramhdr), aparam_buf); michael@0: if (ph == NULL) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: couldn't get lookup addr!\n"); michael@0: continue; michael@0: } michael@0: offset += ntohs(ph->param_length); michael@0: michael@0: aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_asconf_paramhdr), aparam_buf); michael@0: if (aph == NULL) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: Empty ASCONF will be sent?\n"); michael@0: continue; michael@0: } michael@0: while (aph != NULL) { michael@0: unsigned int param_length, param_type; michael@0: michael@0: param_type = ntohs(aph->ph.param_type); michael@0: param_length = ntohs(aph->ph.param_length); michael@0: if (offset + param_length > asconf_limit) { michael@0: /* parameter goes beyond end of chunk! */ michael@0: break; michael@0: } michael@0: if (param_length > sizeof(aparam_buf)) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: param length (%u) larger than buffer size!\n", param_length); michael@0: break; michael@0: } michael@0: if (param_length <= sizeof(struct sctp_paramhdr)) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: param length(%u) too short\n", param_length); michael@0: break; michael@0: } michael@0: michael@0: aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, param_length, aparam_buf); michael@0: if (aph == NULL) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "is_addr_pending: couldn't get entire param\n"); michael@0: break; michael@0: } michael@0: michael@0: ph = (struct sctp_paramhdr *)(aph + 1); michael@0: if (sctp_addr_match(ph, &sctp_ifa->address.sa) != 0) { michael@0: switch (param_type) { michael@0: case SCTP_ADD_IP_ADDRESS: michael@0: add_cnt++; michael@0: break; michael@0: case SCTP_DEL_IP_ADDRESS: michael@0: del_cnt++; michael@0: break; michael@0: default: michael@0: break; michael@0: } michael@0: last_param_type = param_type; michael@0: } michael@0: michael@0: offset += SCTP_SIZE32(param_length); michael@0: if (offset >= asconf_limit) { michael@0: /* no more data in the mbuf chain */ michael@0: break; michael@0: } michael@0: /* get pointer to next asconf param */ michael@0: aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(chk->data, offset, sizeof(struct sctp_asconf_paramhdr), aparam_buf); michael@0: } michael@0: } michael@0: michael@0: /* we want to find the sequences which consist of ADD -> DEL -> ADD or DEL -> ADD */ michael@0: if (add_cnt > del_cnt || michael@0: (add_cnt == del_cnt && last_param_type == SCTP_ADD_IP_ADDRESS)) { michael@0: return (1); michael@0: } michael@0: return (0); michael@0: } michael@0: michael@0: static struct sockaddr * michael@0: sctp_find_valid_localaddr(struct sctp_tcb *stcb, int addr_locked) michael@0: { michael@0: struct sctp_vrf *vrf = NULL; michael@0: struct sctp_ifn *sctp_ifn; michael@0: struct sctp_ifa *sctp_ifa; michael@0: michael@0: if (addr_locked == SCTP_ADDR_NOT_LOCKED) michael@0: SCTP_IPI_ADDR_RLOCK(); michael@0: vrf = sctp_find_vrf(stcb->asoc.vrf_id); michael@0: if (vrf == NULL) { michael@0: if (addr_locked == SCTP_ADDR_NOT_LOCKED) michael@0: SCTP_IPI_ADDR_RUNLOCK(); michael@0: return (NULL); michael@0: } michael@0: LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) { michael@0: if (stcb->asoc.scope.loopback_scope == 0 && michael@0: SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) { michael@0: /* Skip if loopback_scope not set */ michael@0: continue; michael@0: } michael@0: LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) { michael@0: switch (sctp_ifa->address.sa.sa_family) { michael@0: #ifdef INET michael@0: case AF_INET: michael@0: if (stcb->asoc.scope.ipv4_addr_legal) { michael@0: struct sockaddr_in *sin; michael@0: michael@0: sin = (struct sockaddr_in *)&sctp_ifa->address.sa; michael@0: if (sin->sin_addr.s_addr == 0) { michael@0: /* skip unspecifed addresses */ michael@0: continue; michael@0: } michael@0: if (stcb->asoc.scope.ipv4_local_scope == 0 && michael@0: IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) michael@0: continue; michael@0: michael@0: if (sctp_is_addr_restricted(stcb, sctp_ifa) && michael@0: (!sctp_is_addr_pending(stcb, sctp_ifa))) michael@0: continue; michael@0: /* found a valid local v4 address to use */ michael@0: if (addr_locked == SCTP_ADDR_NOT_LOCKED) michael@0: SCTP_IPI_ADDR_RUNLOCK(); michael@0: return (&sctp_ifa->address.sa); michael@0: } michael@0: break; michael@0: #endif michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: if (stcb->asoc.scope.ipv6_addr_legal) { michael@0: struct sockaddr_in6 *sin6; michael@0: michael@0: if (sctp_ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) { michael@0: continue; michael@0: } michael@0: michael@0: sin6 = (struct sockaddr_in6 *)&sctp_ifa->address.sa; michael@0: if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) { michael@0: /* we skip unspecifed addresses */ michael@0: continue; michael@0: } michael@0: if (stcb->asoc.scope.local_scope == 0 && michael@0: IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) michael@0: continue; michael@0: if (stcb->asoc.scope.site_scope == 0 && michael@0: IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)) michael@0: continue; michael@0: michael@0: if (sctp_is_addr_restricted(stcb, sctp_ifa) && michael@0: (!sctp_is_addr_pending(stcb, sctp_ifa))) michael@0: continue; michael@0: /* found a valid local v6 address to use */ michael@0: if (addr_locked == SCTP_ADDR_NOT_LOCKED) michael@0: SCTP_IPI_ADDR_RUNLOCK(); michael@0: return (&sctp_ifa->address.sa); michael@0: } michael@0: break; michael@0: #endif michael@0: default: michael@0: break; michael@0: } michael@0: } michael@0: } michael@0: /* no valid addresses found */ michael@0: if (addr_locked == SCTP_ADDR_NOT_LOCKED) michael@0: SCTP_IPI_ADDR_RUNLOCK(); michael@0: return (NULL); michael@0: } michael@0: michael@0: static struct sockaddr * michael@0: sctp_find_valid_localaddr_ep(struct sctp_tcb *stcb) michael@0: { michael@0: struct sctp_laddr *laddr; michael@0: michael@0: LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) { michael@0: if (laddr->ifa == NULL) { michael@0: continue; michael@0: } michael@0: /* is the address restricted ? */ michael@0: if (sctp_is_addr_restricted(stcb, laddr->ifa) && michael@0: (!sctp_is_addr_pending(stcb, laddr->ifa))) michael@0: continue; michael@0: michael@0: /* found a valid local address to use */ michael@0: return (&laddr->ifa->address.sa); michael@0: } michael@0: /* no valid addresses found */ michael@0: return (NULL); michael@0: } michael@0: michael@0: /* michael@0: * builds an ASCONF chunk from queued ASCONF params. michael@0: * returns NULL on error (no mbuf, no ASCONF params queued, etc). michael@0: */ michael@0: struct mbuf * michael@0: sctp_compose_asconf(struct sctp_tcb *stcb, int *retlen, int addr_locked) michael@0: { michael@0: struct mbuf *m_asconf, *m_asconf_chk; michael@0: struct sctp_asconf_addr *aa; michael@0: struct sctp_asconf_chunk *acp; michael@0: struct sctp_asconf_paramhdr *aph; michael@0: struct sctp_asconf_addr_param *aap; michael@0: uint32_t p_length; michael@0: uint32_t correlation_id = 1; /* 0 is reserved... */ michael@0: caddr_t ptr, lookup_ptr; michael@0: uint8_t lookup_used = 0; michael@0: michael@0: /* are there any asconf params to send? */ michael@0: TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) { michael@0: if (aa->sent == 0) michael@0: break; michael@0: } michael@0: if (aa == NULL) michael@0: return (NULL); michael@0: michael@0: /* michael@0: * get a chunk header mbuf and a cluster for the asconf params since michael@0: * it's simpler to fill in the asconf chunk header lookup address on michael@0: * the fly michael@0: */ michael@0: m_asconf_chk = sctp_get_mbuf_for_msg(sizeof(struct sctp_asconf_chunk), 0, M_NOWAIT, 1, MT_DATA); michael@0: if (m_asconf_chk == NULL) { michael@0: /* no mbuf's */ michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "compose_asconf: couldn't get chunk mbuf!\n"); michael@0: return (NULL); michael@0: } michael@0: m_asconf = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA); michael@0: if (m_asconf == NULL) { michael@0: /* no mbuf's */ michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "compose_asconf: couldn't get mbuf!\n"); michael@0: sctp_m_freem(m_asconf_chk); michael@0: return (NULL); michael@0: } michael@0: SCTP_BUF_LEN(m_asconf_chk) = sizeof(struct sctp_asconf_chunk); michael@0: SCTP_BUF_LEN(m_asconf) = 0; michael@0: acp = mtod(m_asconf_chk, struct sctp_asconf_chunk *); michael@0: bzero(acp, sizeof(struct sctp_asconf_chunk)); michael@0: /* save pointers to lookup address and asconf params */ michael@0: lookup_ptr = (caddr_t)(acp + 1); /* after the header */ michael@0: ptr = mtod(m_asconf, caddr_t); /* beginning of cluster */ michael@0: michael@0: /* fill in chunk header info */ michael@0: acp->ch.chunk_type = SCTP_ASCONF; michael@0: acp->ch.chunk_flags = 0; michael@0: acp->serial_number = htonl(stcb->asoc.asconf_seq_out); michael@0: stcb->asoc.asconf_seq_out++; michael@0: michael@0: /* add parameters... up to smallest MTU allowed */ michael@0: TAILQ_FOREACH(aa, &stcb->asoc.asconf_queue, next) { michael@0: if (aa->sent) michael@0: continue; michael@0: /* get the parameter length */ michael@0: p_length = SCTP_SIZE32(aa->ap.aph.ph.param_length); michael@0: /* will it fit in current chunk? */ michael@0: if ((SCTP_BUF_LEN(m_asconf) + p_length > stcb->asoc.smallest_mtu) || michael@0: (SCTP_BUF_LEN(m_asconf) + p_length > MCLBYTES)) { michael@0: /* won't fit, so we're done with this chunk */ michael@0: break; michael@0: } michael@0: /* assign (and store) a correlation id */ michael@0: aa->ap.aph.correlation_id = correlation_id++; michael@0: michael@0: /* michael@0: * fill in address if we're doing a delete this is a simple michael@0: * way for us to fill in the correlation address, which michael@0: * should only be used by the peer if we're deleting our michael@0: * source address and adding a new address (e.g. renumbering michael@0: * case) michael@0: */ michael@0: if (lookup_used == 0 && michael@0: (aa->special_del == 0) && michael@0: aa->ap.aph.ph.param_type == SCTP_DEL_IP_ADDRESS) { michael@0: struct sctp_ipv6addr_param *lookup; michael@0: uint16_t p_size, addr_size; michael@0: michael@0: lookup = (struct sctp_ipv6addr_param *)lookup_ptr; michael@0: lookup->ph.param_type = michael@0: htons(aa->ap.addrp.ph.param_type); michael@0: if (aa->ap.addrp.ph.param_type == SCTP_IPV6_ADDRESS) { michael@0: /* copy IPv6 address */ michael@0: p_size = sizeof(struct sctp_ipv6addr_param); michael@0: addr_size = sizeof(struct in6_addr); michael@0: } else { michael@0: /* copy IPv4 address */ michael@0: p_size = sizeof(struct sctp_ipv4addr_param); michael@0: addr_size = sizeof(struct in_addr); michael@0: } michael@0: lookup->ph.param_length = htons(SCTP_SIZE32(p_size)); michael@0: memcpy(lookup->addr, &aa->ap.addrp.addr, addr_size); michael@0: SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size); michael@0: lookup_used = 1; michael@0: } michael@0: /* copy into current space */ michael@0: memcpy(ptr, &aa->ap, p_length); michael@0: michael@0: /* network elements and update lengths */ michael@0: aph = (struct sctp_asconf_paramhdr *)ptr; michael@0: aap = (struct sctp_asconf_addr_param *)ptr; michael@0: /* correlation_id is transparent to peer, no htonl needed */ michael@0: aph->ph.param_type = htons(aph->ph.param_type); michael@0: aph->ph.param_length = htons(aph->ph.param_length); michael@0: aap->addrp.ph.param_type = htons(aap->addrp.ph.param_type); michael@0: aap->addrp.ph.param_length = htons(aap->addrp.ph.param_length); michael@0: michael@0: SCTP_BUF_LEN(m_asconf) += SCTP_SIZE32(p_length); michael@0: ptr += SCTP_SIZE32(p_length); michael@0: michael@0: /* michael@0: * these params are removed off the pending list upon michael@0: * getting an ASCONF-ACK back from the peer, just set flag michael@0: */ michael@0: aa->sent = 1; michael@0: } michael@0: /* check to see if the lookup addr has been populated yet */ michael@0: if (lookup_used == 0) { michael@0: /* NOTE: if the address param is optional, can skip this... */ michael@0: /* add any valid (existing) address... */ michael@0: struct sctp_ipv6addr_param *lookup; michael@0: uint16_t p_size, addr_size; michael@0: struct sockaddr *found_addr; michael@0: caddr_t addr_ptr; michael@0: michael@0: if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) michael@0: found_addr = sctp_find_valid_localaddr(stcb, michael@0: addr_locked); michael@0: else michael@0: found_addr = sctp_find_valid_localaddr_ep(stcb); michael@0: michael@0: lookup = (struct sctp_ipv6addr_param *)lookup_ptr; michael@0: if (found_addr != NULL) { michael@0: switch (found_addr->sa_family) { michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: /* copy IPv6 address */ michael@0: lookup->ph.param_type = michael@0: htons(SCTP_IPV6_ADDRESS); michael@0: p_size = sizeof(struct sctp_ipv6addr_param); michael@0: addr_size = sizeof(struct in6_addr); michael@0: addr_ptr = (caddr_t)&((struct sockaddr_in6 *) michael@0: found_addr)->sin6_addr; michael@0: break; michael@0: #endif michael@0: #ifdef INET michael@0: case AF_INET: michael@0: /* copy IPv4 address */ michael@0: lookup->ph.param_type = michael@0: htons(SCTP_IPV4_ADDRESS); michael@0: p_size = sizeof(struct sctp_ipv4addr_param); michael@0: addr_size = sizeof(struct in_addr); michael@0: addr_ptr = (caddr_t)&((struct sockaddr_in *) michael@0: found_addr)->sin_addr; michael@0: break; michael@0: #endif michael@0: default: michael@0: p_size = 0; michael@0: addr_size = 0; michael@0: addr_ptr = NULL; michael@0: break; michael@0: } michael@0: lookup->ph.param_length = htons(SCTP_SIZE32(p_size)); michael@0: memcpy(lookup->addr, addr_ptr, addr_size); michael@0: SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(p_size); michael@0: } else { michael@0: /* uh oh... don't have any address?? */ michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "compose_asconf: no lookup addr!\n"); michael@0: /* XXX for now, we send a IPv4 address of 0.0.0.0 */ michael@0: lookup->ph.param_type = htons(SCTP_IPV4_ADDRESS); michael@0: lookup->ph.param_length = htons(SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param))); michael@0: bzero(lookup->addr, sizeof(struct in_addr)); michael@0: SCTP_BUF_LEN(m_asconf_chk) += SCTP_SIZE32(sizeof(struct sctp_ipv4addr_param)); michael@0: } michael@0: } michael@0: /* chain it all together */ michael@0: SCTP_BUF_NEXT(m_asconf_chk) = m_asconf; michael@0: *retlen = SCTP_BUF_LEN(m_asconf_chk) + SCTP_BUF_LEN(m_asconf); michael@0: acp->ch.chunk_length = htons(*retlen); michael@0: michael@0: return (m_asconf_chk); michael@0: } michael@0: michael@0: /* michael@0: * section to handle address changes before an association is up eg. changes michael@0: * during INIT/INIT-ACK/COOKIE-ECHO handshake michael@0: */ michael@0: michael@0: /* michael@0: * processes the (local) addresses in the INIT-ACK chunk michael@0: */ michael@0: static void michael@0: sctp_process_initack_addresses(struct sctp_tcb *stcb, struct mbuf *m, michael@0: unsigned int offset, unsigned int length) michael@0: { michael@0: struct sctp_paramhdr tmp_param, *ph; michael@0: uint16_t plen, ptype; michael@0: struct sctp_ifa *sctp_ifa; michael@0: #ifdef INET6 michael@0: struct sctp_ipv6addr_param addr6_store; michael@0: struct sockaddr_in6 sin6; michael@0: #endif michael@0: #ifdef INET michael@0: struct sctp_ipv4addr_param addr4_store; michael@0: struct sockaddr_in sin; michael@0: #endif michael@0: struct sockaddr *sa; michael@0: uint32_t vrf_id; michael@0: michael@0: SCTPDBG(SCTP_DEBUG_ASCONF2, "processing init-ack addresses\n"); michael@0: if (stcb == NULL) /* Un-needed check for SA */ michael@0: return; michael@0: michael@0: /* convert to upper bound */ michael@0: length += offset; michael@0: michael@0: if ((offset + sizeof(struct sctp_paramhdr)) > length) { michael@0: return; michael@0: } michael@0: /* init the addresses */ michael@0: #ifdef INET6 michael@0: bzero(&sin6, sizeof(sin6)); michael@0: sin6.sin6_family = AF_INET6; michael@0: #ifdef HAVE_SIN6_LEN michael@0: sin6.sin6_len = sizeof(sin6); michael@0: #endif michael@0: sin6.sin6_port = stcb->rport; michael@0: #endif michael@0: michael@0: #ifdef INET michael@0: bzero(&sin, sizeof(sin)); michael@0: sin.sin_family = AF_INET; michael@0: #ifdef HAVE_SIN_LEN michael@0: sin.sin_len = sizeof(sin); michael@0: #endif michael@0: sin.sin_port = stcb->rport; michael@0: #endif michael@0: michael@0: /* go through the addresses in the init-ack */ michael@0: ph = (struct sctp_paramhdr *) michael@0: sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), michael@0: (uint8_t *)&tmp_param); michael@0: while (ph != NULL) { michael@0: ptype = ntohs(ph->param_type); michael@0: plen = ntohs(ph->param_length); michael@0: switch (ptype) { michael@0: #ifdef INET6 michael@0: case SCTP_IPV6_ADDRESS: michael@0: { michael@0: struct sctp_ipv6addr_param *a6p; michael@0: michael@0: /* get the entire IPv6 address param */ michael@0: a6p = (struct sctp_ipv6addr_param *) michael@0: sctp_m_getptr(m, offset, michael@0: sizeof(struct sctp_ipv6addr_param), michael@0: (uint8_t *)&addr6_store); michael@0: if (plen != sizeof(struct sctp_ipv6addr_param) || michael@0: a6p == NULL) { michael@0: return; michael@0: } michael@0: memcpy(&sin6.sin6_addr, a6p->addr, michael@0: sizeof(struct in6_addr)); michael@0: sa = (struct sockaddr *)&sin6; michael@0: break; michael@0: } michael@0: #endif michael@0: #ifdef INET michael@0: case SCTP_IPV4_ADDRESS: michael@0: { michael@0: struct sctp_ipv4addr_param *a4p; michael@0: michael@0: /* get the entire IPv4 address param */ michael@0: a4p = (struct sctp_ipv4addr_param *)sctp_m_getptr(m, offset, michael@0: sizeof(struct sctp_ipv4addr_param), michael@0: (uint8_t *)&addr4_store); michael@0: if (plen != sizeof(struct sctp_ipv4addr_param) || michael@0: a4p == NULL) { michael@0: return; michael@0: } michael@0: sin.sin_addr.s_addr = a4p->addr; michael@0: sa = (struct sockaddr *)&sin; michael@0: break; michael@0: } michael@0: #endif michael@0: default: michael@0: goto next_addr; michael@0: } michael@0: michael@0: /* see if this address really (still) exists */ michael@0: if (stcb) { michael@0: vrf_id = stcb->asoc.vrf_id; michael@0: } else { michael@0: vrf_id = SCTP_DEFAULT_VRFID; michael@0: } michael@0: sctp_ifa = sctp_find_ifa_by_addr(sa, vrf_id, michael@0: SCTP_ADDR_NOT_LOCKED); michael@0: if (sctp_ifa == NULL) { michael@0: /* address doesn't exist anymore */ michael@0: int status; michael@0: michael@0: /* are ASCONFs allowed ? */ michael@0: if ((sctp_is_feature_on(stcb->sctp_ep, michael@0: SCTP_PCB_FLAGS_DO_ASCONF)) && michael@0: stcb->asoc.peer_supports_asconf) { michael@0: /* queue an ASCONF DEL_IP_ADDRESS */ michael@0: status = sctp_asconf_queue_sa_delete(stcb, sa); michael@0: /* michael@0: * if queued ok, and in correct state, send michael@0: * out the ASCONF. michael@0: */ michael@0: if (status == 0 && michael@0: SCTP_GET_STATE(&stcb->asoc) == michael@0: SCTP_STATE_OPEN) { michael@0: #ifdef SCTP_TIMER_BASED_ASCONF michael@0: sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, michael@0: stcb->sctp_ep, stcb, michael@0: stcb->asoc.primary_destination); michael@0: #else michael@0: sctp_send_asconf(stcb, NULL, SCTP_ADDR_NOT_LOCKED); michael@0: #endif michael@0: } michael@0: } michael@0: } michael@0: michael@0: next_addr: michael@0: /* michael@0: * Sanity check: Make sure the length isn't 0, otherwise michael@0: * we'll be stuck in this loop for a long time... michael@0: */ michael@0: if (SCTP_SIZE32(plen) == 0) { michael@0: SCTP_PRINTF("process_initack_addrs: bad len (%d) type=%xh\n", michael@0: plen, ptype); michael@0: return; michael@0: } michael@0: /* get next parameter */ michael@0: offset += SCTP_SIZE32(plen); michael@0: if ((offset + sizeof(struct sctp_paramhdr)) > length) michael@0: return; michael@0: ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset, michael@0: sizeof(struct sctp_paramhdr), (uint8_t *) & tmp_param); michael@0: } /* while */ michael@0: } michael@0: michael@0: /* FIX ME: need to verify return result for v6 address type if v6 disabled */ michael@0: /* michael@0: * checks to see if a specific address is in the initack address list returns michael@0: * 1 if found, 0 if not michael@0: */ michael@0: static uint32_t michael@0: sctp_addr_in_initack(struct mbuf *m, uint32_t offset, uint32_t length, struct sockaddr *sa) michael@0: { michael@0: struct sctp_paramhdr tmp_param, *ph; michael@0: uint16_t plen, ptype; michael@0: #ifdef INET michael@0: struct sockaddr_in *sin; michael@0: struct sctp_ipv4addr_param *a4p; michael@0: struct sctp_ipv6addr_param addr4_store; michael@0: #endif michael@0: #ifdef INET6 michael@0: struct sockaddr_in6 *sin6; michael@0: struct sctp_ipv6addr_param *a6p; michael@0: struct sctp_ipv6addr_param addr6_store; michael@0: #ifdef SCTP_EMBEDDED_V6_SCOPE michael@0: struct sockaddr_in6 sin6_tmp; michael@0: #endif michael@0: #endif michael@0: michael@0: switch (sa->sa_family) { michael@0: #ifdef INET michael@0: case AF_INET: michael@0: break; michael@0: #endif michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: break; michael@0: #endif michael@0: default: michael@0: return (0); michael@0: } michael@0: michael@0: SCTPDBG(SCTP_DEBUG_ASCONF2, "find_initack_addr: starting search for "); michael@0: SCTPDBG_ADDR(SCTP_DEBUG_ASCONF2, sa); michael@0: /* convert to upper bound */ michael@0: length += offset; michael@0: michael@0: if ((offset + sizeof(struct sctp_paramhdr)) > length) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "find_initack_addr: invalid offset?\n"); michael@0: return (0); michael@0: } michael@0: /* go through the addresses in the init-ack */ michael@0: ph = (struct sctp_paramhdr *)sctp_m_getptr(m, offset, michael@0: sizeof(struct sctp_paramhdr), (uint8_t *) & tmp_param); michael@0: while (ph != NULL) { michael@0: ptype = ntohs(ph->param_type); michael@0: plen = ntohs(ph->param_length); michael@0: switch (ptype) { michael@0: #ifdef INET6 michael@0: case SCTP_IPV6_ADDRESS: michael@0: if (sa->sa_family == AF_INET6) { michael@0: /* get the entire IPv6 address param */ michael@0: if (plen != sizeof(struct sctp_ipv6addr_param)) { michael@0: break; michael@0: } michael@0: /* get the entire IPv6 address param */ michael@0: a6p = (struct sctp_ipv6addr_param *) michael@0: sctp_m_getptr(m, offset, michael@0: sizeof(struct sctp_ipv6addr_param), michael@0: (uint8_t *)&addr6_store); michael@0: if (a6p == NULL) { michael@0: return (0); michael@0: } michael@0: sin6 = (struct sockaddr_in6 *)sa; michael@0: #ifdef SCTP_EMBEDDED_V6_SCOPE michael@0: if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr)) { michael@0: /* create a copy and clear scope */ michael@0: memcpy(&sin6_tmp, sin6, michael@0: sizeof(struct sockaddr_in6)); michael@0: sin6 = &sin6_tmp; michael@0: in6_clearscope(&sin6->sin6_addr); michael@0: } michael@0: #endif /* SCTP_EMBEDDED_V6_SCOPE */ michael@0: if (memcmp(&sin6->sin6_addr, a6p->addr, michael@0: sizeof(struct in6_addr)) == 0) { michael@0: /* found it */ michael@0: return (1); michael@0: } michael@0: } michael@0: break; michael@0: #endif /* INET6 */ michael@0: #ifdef INET michael@0: case SCTP_IPV4_ADDRESS: michael@0: if (sa->sa_family == AF_INET) { michael@0: if (plen != sizeof(struct sctp_ipv4addr_param)) { michael@0: break; michael@0: } michael@0: /* get the entire IPv4 address param */ michael@0: a4p = (struct sctp_ipv4addr_param *) michael@0: sctp_m_getptr(m, offset, michael@0: sizeof(struct sctp_ipv4addr_param), michael@0: (uint8_t *)&addr4_store); michael@0: if (a4p == NULL) { michael@0: return (0); michael@0: } michael@0: sin = (struct sockaddr_in *)sa; michael@0: if (sin->sin_addr.s_addr == a4p->addr) { michael@0: /* found it */ michael@0: return (1); michael@0: } michael@0: } michael@0: break; michael@0: #endif michael@0: default: michael@0: break; michael@0: } michael@0: /* get next parameter */ michael@0: offset += SCTP_SIZE32(plen); michael@0: if (offset + sizeof(struct sctp_paramhdr) > length) { michael@0: return (0); michael@0: } michael@0: ph = (struct sctp_paramhdr *) michael@0: sctp_m_getptr(m, offset, sizeof(struct sctp_paramhdr), michael@0: (uint8_t *) & tmp_param); michael@0: } /* while */ michael@0: /* not found! */ michael@0: return (0); michael@0: } michael@0: michael@0: /* michael@0: * makes sure that the current endpoint local addr list is consistent with michael@0: * the new association (eg. subset bound, asconf allowed) adds addresses as michael@0: * necessary michael@0: */ michael@0: static void michael@0: sctp_check_address_list_ep(struct sctp_tcb *stcb, struct mbuf *m, int offset, michael@0: int length, struct sockaddr *init_addr) michael@0: { michael@0: struct sctp_laddr *laddr; michael@0: michael@0: /* go through the endpoint list */ michael@0: LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) { michael@0: /* be paranoid and validate the laddr */ michael@0: if (laddr->ifa == NULL) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "check_addr_list_ep: laddr->ifa is NULL"); michael@0: continue; michael@0: } michael@0: if (laddr->ifa == NULL) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "check_addr_list_ep: laddr->ifa->ifa_addr is NULL"); michael@0: continue; michael@0: } michael@0: /* do i have it implicitly? */ michael@0: if (sctp_cmpaddr(&laddr->ifa->address.sa, init_addr)) { michael@0: continue; michael@0: } michael@0: /* check to see if in the init-ack */ michael@0: if (!sctp_addr_in_initack(m, offset, length, &laddr->ifa->address.sa)) { michael@0: /* try to add it */ michael@0: sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb, laddr->ifa, michael@0: SCTP_ADD_IP_ADDRESS, SCTP_ADDR_NOT_LOCKED); michael@0: } michael@0: } michael@0: } michael@0: michael@0: /* michael@0: * makes sure that the current kernel address list is consistent with the new michael@0: * association (with all addrs bound) adds addresses as necessary michael@0: */ michael@0: static void michael@0: sctp_check_address_list_all(struct sctp_tcb *stcb, struct mbuf *m, int offset, michael@0: int length, struct sockaddr *init_addr, michael@0: uint16_t local_scope, uint16_t site_scope, michael@0: uint16_t ipv4_scope, uint16_t loopback_scope) michael@0: { michael@0: struct sctp_vrf *vrf = NULL; michael@0: struct sctp_ifn *sctp_ifn; michael@0: struct sctp_ifa *sctp_ifa; michael@0: uint32_t vrf_id; michael@0: #ifdef INET michael@0: struct sockaddr_in *sin; michael@0: #endif michael@0: #ifdef INET6 michael@0: struct sockaddr_in6 *sin6; michael@0: #endif michael@0: michael@0: if (stcb) { michael@0: vrf_id = stcb->asoc.vrf_id; michael@0: } else { michael@0: return; michael@0: } michael@0: SCTP_IPI_ADDR_RLOCK(); michael@0: vrf = sctp_find_vrf(vrf_id); michael@0: if (vrf == NULL) { michael@0: SCTP_IPI_ADDR_RUNLOCK(); michael@0: return; michael@0: } michael@0: /* go through all our known interfaces */ michael@0: LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) { michael@0: if (loopback_scope == 0 && SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) { michael@0: /* skip loopback interface */ michael@0: continue; michael@0: } michael@0: /* go through each interface address */ michael@0: LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) { michael@0: /* do i have it implicitly? */ michael@0: if (sctp_cmpaddr(&sctp_ifa->address.sa, init_addr)) { michael@0: continue; michael@0: } michael@0: switch (sctp_ifa->address.sa.sa_family) { michael@0: #ifdef INET michael@0: case AF_INET: michael@0: sin = (struct sockaddr_in *)&sctp_ifa->address.sin; michael@0: if ((ipv4_scope == 0) && michael@0: (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) { michael@0: /* private address not in scope */ michael@0: continue; michael@0: } michael@0: break; michael@0: #endif michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: sin6 = (struct sockaddr_in6 *)&sctp_ifa->address.sin6; michael@0: if ((local_scope == 0) && michael@0: (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr))) { michael@0: continue; michael@0: } michael@0: if ((site_scope == 0) && michael@0: (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) { michael@0: continue; michael@0: } michael@0: break; michael@0: #endif michael@0: default: michael@0: break; michael@0: } michael@0: /* check to see if in the init-ack */ michael@0: if (!sctp_addr_in_initack(m, offset, length, &sctp_ifa->address.sa)) { michael@0: /* try to add it */ michael@0: sctp_addr_mgmt_assoc(stcb->sctp_ep, stcb, michael@0: sctp_ifa, SCTP_ADD_IP_ADDRESS, michael@0: SCTP_ADDR_LOCKED); michael@0: } michael@0: } /* end foreach ifa */ michael@0: } /* end foreach ifn */ michael@0: SCTP_IPI_ADDR_RUNLOCK(); michael@0: } michael@0: michael@0: /* michael@0: * validates an init-ack chunk (from a cookie-echo) with current addresses michael@0: * adds addresses from the init-ack into our local address list, if needed michael@0: * queues asconf adds/deletes addresses as needed and makes appropriate list michael@0: * changes for source address selection m, offset: points to the start of the michael@0: * address list in an init-ack chunk length: total length of the address michael@0: * params only init_addr: address where my INIT-ACK was sent from michael@0: */ michael@0: void michael@0: sctp_check_address_list(struct sctp_tcb *stcb, struct mbuf *m, int offset, michael@0: int length, struct sockaddr *init_addr, michael@0: uint16_t local_scope, uint16_t site_scope, michael@0: uint16_t ipv4_scope, uint16_t loopback_scope) michael@0: { michael@0: /* process the local addresses in the initack */ michael@0: sctp_process_initack_addresses(stcb, m, offset, length); michael@0: michael@0: if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { michael@0: /* bound all case */ michael@0: sctp_check_address_list_all(stcb, m, offset, length, init_addr, michael@0: local_scope, site_scope, ipv4_scope, loopback_scope); michael@0: } else { michael@0: /* subset bound case */ michael@0: if (sctp_is_feature_on(stcb->sctp_ep, michael@0: SCTP_PCB_FLAGS_DO_ASCONF)) { michael@0: /* asconf's allowed */ michael@0: sctp_check_address_list_ep(stcb, m, offset, length, michael@0: init_addr); michael@0: } michael@0: /* else, no asconfs allowed, so what we sent is what we get */ michael@0: } michael@0: } michael@0: michael@0: /* michael@0: * sctp_bindx() support michael@0: */ michael@0: uint32_t michael@0: sctp_addr_mgmt_ep_sa(struct sctp_inpcb *inp, struct sockaddr *sa, michael@0: uint32_t type, uint32_t vrf_id, struct sctp_ifa *sctp_ifap) michael@0: { michael@0: struct sctp_ifa *ifa; michael@0: struct sctp_laddr *laddr, *nladdr; michael@0: michael@0: #ifdef HAVE_SA_LEN michael@0: if (sa->sa_len == 0) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: #endif michael@0: if (sctp_ifap) { michael@0: ifa = sctp_ifap; michael@0: } else if (type == SCTP_ADD_IP_ADDRESS) { michael@0: /* For an add the address MUST be on the system */ michael@0: ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED); michael@0: } else if (type == SCTP_DEL_IP_ADDRESS) { michael@0: /* For a delete we need to find it in the inp */ michael@0: ifa = sctp_find_ifa_in_ep(inp, sa, SCTP_ADDR_NOT_LOCKED); michael@0: } else { michael@0: ifa = NULL; michael@0: } michael@0: if (ifa != NULL) { michael@0: if (type == SCTP_ADD_IP_ADDRESS) { michael@0: sctp_add_local_addr_ep(inp, ifa, type); michael@0: } else if (type == SCTP_DEL_IP_ADDRESS) { michael@0: if (inp->laddr_count < 2) { michael@0: /* can't delete the last local address */ michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EINVAL); michael@0: return (EINVAL); michael@0: } michael@0: LIST_FOREACH(laddr, &inp->sctp_addr_list, michael@0: sctp_nxt_addr) { michael@0: if (ifa == laddr->ifa) { michael@0: /* Mark in the delete */ michael@0: laddr->action = type; michael@0: } michael@0: } michael@0: } michael@0: if (LIST_EMPTY(&inp->sctp_asoc_list)) { michael@0: /* michael@0: * There is no need to start the iterator if michael@0: * the inp has no associations. michael@0: */ michael@0: if (type == SCTP_DEL_IP_ADDRESS) { michael@0: LIST_FOREACH_SAFE(laddr, &inp->sctp_addr_list, sctp_nxt_addr, nladdr) { michael@0: if (laddr->ifa == ifa) { michael@0: sctp_del_local_addr_ep(inp, ifa); michael@0: } michael@0: } michael@0: } michael@0: } else { michael@0: struct sctp_asconf_iterator *asc; michael@0: struct sctp_laddr *wi; michael@0: michael@0: SCTP_MALLOC(asc, struct sctp_asconf_iterator *, michael@0: sizeof(struct sctp_asconf_iterator), michael@0: SCTP_M_ASC_IT); michael@0: if (asc == NULL) { michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, ENOMEM); michael@0: return (ENOMEM); michael@0: } michael@0: wi = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_laddr), struct sctp_laddr); michael@0: if (wi == NULL) { michael@0: SCTP_FREE(asc, SCTP_M_ASC_IT); michael@0: SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_ASCONF, ENOMEM); michael@0: return (ENOMEM); michael@0: } michael@0: LIST_INIT(&asc->list_of_work); michael@0: asc->cnt = 1; michael@0: SCTP_INCR_LADDR_COUNT(); michael@0: wi->ifa = ifa; michael@0: wi->action = type; michael@0: atomic_add_int(&ifa->refcount, 1); michael@0: LIST_INSERT_HEAD(&asc->list_of_work, wi, sctp_nxt_addr); michael@0: (void)sctp_initiate_iterator(sctp_asconf_iterator_ep, michael@0: sctp_asconf_iterator_stcb, michael@0: sctp_asconf_iterator_ep_end, michael@0: SCTP_PCB_ANY_FLAGS, michael@0: SCTP_PCB_ANY_FEATURES, michael@0: SCTP_ASOC_ANY_STATE, michael@0: (void *)asc, 0, michael@0: sctp_asconf_iterator_end, inp, 0); michael@0: } michael@0: return (0); michael@0: } else { michael@0: /* invalid address! */ michael@0: SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_ASCONF, EADDRNOTAVAIL); michael@0: return (EADDRNOTAVAIL); michael@0: } michael@0: } michael@0: michael@0: void michael@0: sctp_asconf_send_nat_state_update(struct sctp_tcb *stcb, michael@0: struct sctp_nets *net) michael@0: { michael@0: struct sctp_asconf_addr *aa; michael@0: struct sctp_ifa *sctp_ifap; michael@0: struct sctp_asconf_tag_param *vtag; michael@0: #ifdef INET michael@0: struct sockaddr_in *to; michael@0: #endif michael@0: #ifdef INET6 michael@0: struct sockaddr_in6 *to6; michael@0: #endif michael@0: if (net == NULL) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing net\n"); michael@0: return; michael@0: } michael@0: if (stcb == NULL) { michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, "sctp_asconf_send_nat_state_update: Missing stcb\n"); michael@0: return; michael@0: } michael@0: /* Need to have in the asconf: michael@0: * - vtagparam(my_vtag/peer_vtag) michael@0: * - add(0.0.0.0) michael@0: * - del(0.0.0.0) michael@0: * - Any global addresses add(addr) michael@0: */ michael@0: SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), michael@0: SCTP_M_ASC_ADDR); michael@0: if (aa == NULL) { michael@0: /* didn't get memory */ michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "sctp_asconf_send_nat_state_update: failed to get memory!\n"); michael@0: return; michael@0: } michael@0: aa->special_del = 0; michael@0: /* fill in asconf address parameter fields */ michael@0: /* top level elements are "networked" during send */ michael@0: aa->ifa = NULL; michael@0: aa->sent = 0; /* clear sent flag */ michael@0: vtag = (struct sctp_asconf_tag_param *)&aa->ap.aph; michael@0: vtag->aph.ph.param_type = SCTP_NAT_VTAGS; michael@0: vtag->aph.ph.param_length = sizeof(struct sctp_asconf_tag_param); michael@0: vtag->local_vtag = htonl(stcb->asoc.my_vtag); michael@0: vtag->remote_vtag = htonl(stcb->asoc.peer_vtag); michael@0: TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); michael@0: michael@0: SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), michael@0: SCTP_M_ASC_ADDR); michael@0: if (aa == NULL) { michael@0: /* didn't get memory */ michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "sctp_asconf_send_nat_state_update: failed to get memory!\n"); michael@0: return; michael@0: } michael@0: memset(aa, 0, sizeof(struct sctp_asconf_addr)); michael@0: /* fill in asconf address parameter fields */ michael@0: /* ADD(0.0.0.0) */ michael@0: switch (net->ro._l_addr.sa.sa_family) { michael@0: #ifdef INET michael@0: case AF_INET: michael@0: aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS; michael@0: aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param); michael@0: aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS; michael@0: aa->ap.addrp.ph.param_length = sizeof (struct sctp_ipv4addr_param); michael@0: /* No need to add an address, we are using 0.0.0.0 */ michael@0: TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); michael@0: break; michael@0: #endif michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS; michael@0: aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param); michael@0: aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS; michael@0: aa->ap.addrp.ph.param_length = sizeof (struct sctp_ipv6addr_param); michael@0: /* No need to add an address, we are using 0.0.0.0 */ michael@0: TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); michael@0: break; michael@0: #endif michael@0: } michael@0: SCTP_MALLOC(aa, struct sctp_asconf_addr *, sizeof(*aa), michael@0: SCTP_M_ASC_ADDR); michael@0: if (aa == NULL) { michael@0: /* didn't get memory */ michael@0: SCTPDBG(SCTP_DEBUG_ASCONF1, michael@0: "sctp_asconf_send_nat_state_update: failed to get memory!\n"); michael@0: return; michael@0: } michael@0: memset(aa, 0, sizeof(struct sctp_asconf_addr)); michael@0: /* fill in asconf address parameter fields */ michael@0: /* ADD(0.0.0.0) */ michael@0: switch (net->ro._l_addr.sa.sa_family) { michael@0: #ifdef INET michael@0: case AF_INET: michael@0: aa->ap.aph.ph.param_type = SCTP_ADD_IP_ADDRESS; michael@0: aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addrv4_param); michael@0: aa->ap.addrp.ph.param_type = SCTP_IPV4_ADDRESS; michael@0: aa->ap.addrp.ph.param_length = sizeof (struct sctp_ipv4addr_param); michael@0: /* No need to add an address, we are using 0.0.0.0 */ michael@0: TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); michael@0: break; michael@0: #endif michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: aa->ap.aph.ph.param_type = SCTP_DEL_IP_ADDRESS; michael@0: aa->ap.aph.ph.param_length = sizeof(struct sctp_asconf_addr_param); michael@0: aa->ap.addrp.ph.param_type = SCTP_IPV6_ADDRESS; michael@0: aa->ap.addrp.ph.param_length = sizeof (struct sctp_ipv6addr_param); michael@0: /* No need to add an address, we are using 0.0.0.0 */ michael@0: TAILQ_INSERT_TAIL(&stcb->asoc.asconf_queue, aa, next); michael@0: break; michael@0: #endif michael@0: } michael@0: /* Now we must hunt the addresses and add all global addresses */ michael@0: if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) { michael@0: struct sctp_vrf *vrf = NULL; michael@0: struct sctp_ifn *sctp_ifnp; michael@0: uint32_t vrf_id; michael@0: michael@0: vrf_id = stcb->sctp_ep->def_vrf_id; michael@0: vrf = sctp_find_vrf(vrf_id); michael@0: if (vrf == NULL) { michael@0: goto skip_rest; michael@0: } michael@0: michael@0: SCTP_IPI_ADDR_RLOCK(); michael@0: LIST_FOREACH(sctp_ifnp, &vrf->ifnlist, next_ifn) { michael@0: LIST_FOREACH(sctp_ifap, &sctp_ifnp->ifalist, next_ifa) { michael@0: switch (sctp_ifap->address.sa.sa_family) { michael@0: #ifdef INET michael@0: case AF_INET: michael@0: to = &sctp_ifap->address.sin; michael@0: if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) { michael@0: continue; michael@0: } michael@0: if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) { michael@0: continue; michael@0: } michael@0: break; michael@0: #endif michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: to6 = &sctp_ifap->address.sin6; michael@0: if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) { michael@0: continue; michael@0: } michael@0: if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) { michael@0: continue; michael@0: } michael@0: break; michael@0: #endif michael@0: default: michael@0: continue; michael@0: } michael@0: sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS); michael@0: } michael@0: } michael@0: SCTP_IPI_ADDR_RUNLOCK(); michael@0: } else { michael@0: struct sctp_laddr *laddr; michael@0: michael@0: LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) { michael@0: if (laddr->ifa == NULL) { michael@0: continue; michael@0: } michael@0: if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED) michael@0: /* Address being deleted by the system, dont michael@0: * list. michael@0: */ michael@0: continue; michael@0: if (laddr->action == SCTP_DEL_IP_ADDRESS) { michael@0: /* Address being deleted on this ep michael@0: * don't list. michael@0: */ michael@0: continue; michael@0: } michael@0: sctp_ifap = laddr->ifa; michael@0: switch (sctp_ifap->address.sa.sa_family) { michael@0: #ifdef INET michael@0: case AF_INET: michael@0: to = &sctp_ifap->address.sin; michael@0: if (IN4_ISPRIVATE_ADDRESS(&to->sin_addr)) { michael@0: continue; michael@0: } michael@0: if (IN4_ISLOOPBACK_ADDRESS(&to->sin_addr)) { michael@0: continue; michael@0: } michael@0: break; michael@0: #endif michael@0: #ifdef INET6 michael@0: case AF_INET6: michael@0: to6 = &sctp_ifap->address.sin6; michael@0: if (IN6_IS_ADDR_LOOPBACK(&to6->sin6_addr)) { michael@0: continue; michael@0: } michael@0: if (IN6_IS_ADDR_LINKLOCAL(&to6->sin6_addr)) { michael@0: continue; michael@0: } michael@0: break; michael@0: #endif michael@0: default: michael@0: continue; michael@0: } michael@0: sctp_asconf_queue_mgmt(stcb, sctp_ifap, SCTP_ADD_IP_ADDRESS); michael@0: } michael@0: } michael@0: skip_rest: michael@0: /* Now we must send the asconf into the queue */ michael@0: sctp_send_asconf(stcb, net, SCTP_ADDR_NOT_LOCKED); michael@0: }