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