2006-11-03 15:23:16 +00:00
|
|
|
/*-
|
2008-12-06 13:19:54 +00:00
|
|
|
* Copyright (c) 2001-2008, 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>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include <netinet/sctp_os.h>
|
2007-01-18 09:58:43 +00:00
|
|
|
#include <sys/proc.h>
|
2006-11-03 15:23:16 +00:00
|
|
|
#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/sctputil.h>
|
|
|
|
#include <netinet/sctp.h>
|
|
|
|
#include <netinet/sctp_header.h>
|
|
|
|
#include <netinet/sctp_asconf.h>
|
|
|
|
#include <netinet/sctp_output.h>
|
|
|
|
#include <netinet/sctp_timer.h>
|
2007-03-15 11:27:14 +00:00
|
|
|
#include <netinet/sctp_bsd_addr.h>
|
2010-11-25 13:39:55 +00:00
|
|
|
#include <netinet/sctp_dtrace_define.h>
|
2014-07-11 06:52:48 +00:00
|
|
|
#if defined(INET) || defined(INET6)
|
2008-05-20 13:47:46 +00:00
|
|
|
#include <netinet/udp.h>
|
2014-07-11 06:52:48 +00:00
|
|
|
#endif
|
2011-09-14 08:15:21 +00:00
|
|
|
#ifdef INET6
|
|
|
|
#include <netinet6/ip6_var.h>
|
|
|
|
#endif
|
2011-02-03 10:05:30 +00:00
|
|
|
#include <sys/sched.h>
|
|
|
|
#include <sys/smp.h>
|
|
|
|
#include <sys/unistd.h>
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
|
2009-09-17 15:11:12 +00:00
|
|
|
VNET_DEFINE(struct sctp_base_info, system_base_info);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/* FIX: we don't handle multiple link local scopes */
|
|
|
|
/* "scopeless" replacement IN6_ARE_ADDR_EQUAL */
|
2008-04-16 17:24:18 +00:00
|
|
|
#ifdef INET6
|
2006-11-03 15:23:16 +00:00
|
|
|
int
|
2008-05-20 13:47:46 +00:00
|
|
|
SCTP6_ARE_ADDR_EQUAL(struct sockaddr_in6 *a, struct sockaddr_in6 *b)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2008-05-20 13:47:46 +00:00
|
|
|
struct sockaddr_in6 tmp_a, tmp_b;
|
|
|
|
|
|
|
|
memcpy(&tmp_a, a, sizeof(struct sockaddr_in6));
|
2009-09-17 15:11:12 +00:00
|
|
|
if (sa6_embedscope(&tmp_a, MODULE_GLOBAL(ip6_use_defzone)) != 0) {
|
2011-12-27 10:16:24 +00:00
|
|
|
return (0);
|
2008-05-20 13:47:46 +00:00
|
|
|
}
|
|
|
|
memcpy(&tmp_b, b, sizeof(struct sockaddr_in6));
|
2009-09-17 15:11:12 +00:00
|
|
|
if (sa6_embedscope(&tmp_b, MODULE_GLOBAL(ip6_use_defzone)) != 0) {
|
2011-12-27 10:16:24 +00:00
|
|
|
return (0);
|
2008-05-20 13:47:46 +00:00
|
|
|
}
|
|
|
|
return (IN6_ARE_ADDR_EQUAL(&tmp_a.sin6_addr, &tmp_b.sin6_addr));
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
2008-04-16 17:24:18 +00:00
|
|
|
#endif
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
void
|
|
|
|
sctp_fill_pcbinfo(struct sctp_pcbinfo *spcb)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We really don't need to lock this, but I will just because it
|
|
|
|
* does not hurt.
|
|
|
|
*/
|
|
|
|
SCTP_INP_INFO_RLOCK();
|
2008-06-14 07:58:05 +00:00
|
|
|
spcb->ep_count = SCTP_BASE_INFO(ipi_count_ep);
|
|
|
|
spcb->asoc_count = SCTP_BASE_INFO(ipi_count_asoc);
|
|
|
|
spcb->laddr_count = SCTP_BASE_INFO(ipi_count_laddr);
|
|
|
|
spcb->raddr_count = SCTP_BASE_INFO(ipi_count_raddr);
|
|
|
|
spcb->chk_count = SCTP_BASE_INFO(ipi_count_chunk);
|
|
|
|
spcb->readq_count = SCTP_BASE_INFO(ipi_count_readq);
|
|
|
|
spcb->stream_oque = SCTP_BASE_INFO(ipi_count_strmoq);
|
|
|
|
spcb->free_chunks = SCTP_BASE_INFO(ipi_free_chunks);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_INFO_RUNLOCK();
|
|
|
|
}
|
|
|
|
|
2013-02-09 17:26:14 +00:00
|
|
|
/*-
|
2007-03-15 11:27:14 +00:00
|
|
|
* Addresses are added to VRF's (Virtual Router's). For BSD we
|
|
|
|
* have only the default VRF 0. We maintain a hash list of
|
|
|
|
* VRF's. Each VRF has its own list of sctp_ifn's. Each of
|
|
|
|
* these has a list of addresses. When we add a new address
|
|
|
|
* to a VRF we lookup the ifn/ifn_index, if the ifn does
|
|
|
|
* not exist we create it and add it to the list of IFN's
|
|
|
|
* within the VRF. Once we have the sctp_ifn, we add the
|
|
|
|
* address to the list. So we look something like:
|
|
|
|
*
|
|
|
|
* hash-vrf-table
|
|
|
|
* vrf-> ifn-> ifn -> ifn
|
|
|
|
* vrf |
|
|
|
|
* ... +--ifa-> ifa -> ifa
|
|
|
|
* vrf
|
|
|
|
*
|
2010-11-09 10:59:09 +00:00
|
|
|
* We keep these separate lists since the SCTP subsystem will
|
2007-03-15 11:27:14 +00:00
|
|
|
* point to these from its source address selection nets structure.
|
|
|
|
* When an address is deleted it does not happen right away on
|
|
|
|
* the SCTP side, it gets scheduled. What we do when a
|
|
|
|
* delete happens is immediately remove the address from
|
|
|
|
* the master list and decrement the refcount. As our
|
|
|
|
* addip iterator works through and frees the src address
|
|
|
|
* selection pointing to the sctp_ifa, eventually the refcount
|
|
|
|
* will reach 0 and we will delete it. Note that it is assumed
|
|
|
|
* that any locking on system level ifn/ifa is done at the
|
|
|
|
* caller of these functions and these routines will only
|
|
|
|
* lock the SCTP structures as they add or delete things.
|
|
|
|
*
|
|
|
|
* Other notes on VRF concepts.
|
|
|
|
* - An endpoint can be in multiple VRF's
|
|
|
|
* - An association lives within a VRF and only one VRF.
|
|
|
|
* - Any incoming packet we can deduce the VRF for by
|
|
|
|
* looking at the mbuf/pak inbound (for BSD its VRF=0 :D)
|
|
|
|
* - Any downward send call or connect call must supply the
|
|
|
|
* VRF via ancillary data or via some sort of set default
|
|
|
|
* VRF socket option call (again for BSD no brainer since
|
|
|
|
* the VRF is always 0).
|
|
|
|
* - An endpoint may add multiple VRF's to it.
|
|
|
|
* - Listening sockets can accept associations in any
|
|
|
|
* of the VRF's they are in but the assoc will end up
|
|
|
|
* in only one VRF (gotten from the packet or connect/send).
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct sctp_vrf *
|
2007-05-08 00:21:05 +00:00
|
|
|
sctp_allocate_vrf(int vrf_id)
|
2007-03-15 11:27:14 +00:00
|
|
|
{
|
|
|
|
struct sctp_vrf *vrf = NULL;
|
|
|
|
struct sctp_vrflist *bucket;
|
|
|
|
|
|
|
|
/* First allocate the VRF structure */
|
2007-05-08 00:21:05 +00:00
|
|
|
vrf = sctp_find_vrf(vrf_id);
|
2007-03-15 11:27:14 +00:00
|
|
|
if (vrf) {
|
|
|
|
/* Already allocated */
|
|
|
|
return (vrf);
|
|
|
|
}
|
|
|
|
SCTP_MALLOC(vrf, struct sctp_vrf *, sizeof(struct sctp_vrf),
|
2007-05-29 09:29:03 +00:00
|
|
|
SCTP_M_VRF);
|
2007-03-15 11:27:14 +00:00
|
|
|
if (vrf == NULL) {
|
|
|
|
/* No memory */
|
|
|
|
#ifdef INVARIANTS
|
2007-05-08 00:21:05 +00:00
|
|
|
panic("No memory for VRF:%d", vrf_id);
|
2007-03-15 11:27:14 +00:00
|
|
|
#endif
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
/* setup the VRF */
|
|
|
|
memset(vrf, 0, sizeof(struct sctp_vrf));
|
2007-05-08 00:21:05 +00:00
|
|
|
vrf->vrf_id = vrf_id;
|
2007-03-15 11:27:14 +00:00
|
|
|
LIST_INIT(&vrf->ifnlist);
|
|
|
|
vrf->total_ifa_count = 0;
|
2007-06-14 22:59:04 +00:00
|
|
|
vrf->refcount = 0;
|
2007-06-02 11:05:08 +00:00
|
|
|
/* now also setup table ids */
|
|
|
|
SCTP_INIT_VRF_TABLEID(vrf);
|
2007-03-19 11:11:16 +00:00
|
|
|
/* Init the HASH of addresses */
|
2007-05-08 00:21:05 +00:00
|
|
|
vrf->vrf_addr_hash = SCTP_HASH_INIT(SCTP_VRF_ADDR_HASH_SIZE,
|
|
|
|
&vrf->vrf_addr_hashmark);
|
2007-03-19 11:11:16 +00:00
|
|
|
if (vrf->vrf_addr_hash == NULL) {
|
|
|
|
/* No memory */
|
|
|
|
#ifdef INVARIANTS
|
2007-05-08 00:21:05 +00:00
|
|
|
panic("No memory for VRF:%d", vrf_id);
|
|
|
|
#endif
|
2007-05-29 09:29:03 +00:00
|
|
|
SCTP_FREE(vrf, SCTP_M_VRF);
|
2007-05-08 00:21:05 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
/* Add it to the hash table */
|
2008-06-14 07:58:05 +00:00
|
|
|
bucket = &SCTP_BASE_INFO(sctp_vrfhash)[(vrf_id & SCTP_BASE_INFO(hashvrfmark))];
|
2007-03-15 11:27:14 +00:00
|
|
|
LIST_INSERT_HEAD(bucket, vrf, next_vrf);
|
2008-06-14 07:58:05 +00:00
|
|
|
atomic_add_int(&SCTP_BASE_INFO(ipi_count_vrfs), 1);
|
2007-03-15 11:27:14 +00:00
|
|
|
return (vrf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct sctp_ifn *
|
2007-06-02 11:05:08 +00:00
|
|
|
sctp_find_ifn(void *ifn, uint32_t ifn_index)
|
2007-03-15 11:27:14 +00:00
|
|
|
{
|
|
|
|
struct sctp_ifn *sctp_ifnp;
|
2007-05-08 00:21:05 +00:00
|
|
|
struct sctp_ifnlist *hash_ifn_head;
|
2007-03-15 11:27:14 +00:00
|
|
|
|
|
|
|
/*
|
2010-11-09 10:59:09 +00:00
|
|
|
* We assume the lock is held for the addresses if that's wrong
|
2007-03-15 11:27:14 +00:00
|
|
|
* problems could occur :-)
|
|
|
|
*/
|
2008-06-14 07:58:05 +00:00
|
|
|
hash_ifn_head = &SCTP_BASE_INFO(vrf_ifn_hash)[(ifn_index & SCTP_BASE_INFO(vrf_ifn_hashmark))];
|
2007-05-08 00:21:05 +00:00
|
|
|
LIST_FOREACH(sctp_ifnp, hash_ifn_head, next_bucket) {
|
2007-03-15 11:27:14 +00:00
|
|
|
if (sctp_ifnp->ifn_index == ifn_index) {
|
|
|
|
return (sctp_ifnp);
|
|
|
|
}
|
|
|
|
if (sctp_ifnp->ifn_p && ifn && (sctp_ifnp->ifn_p == ifn)) {
|
|
|
|
return (sctp_ifnp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2007-05-08 00:21:05 +00:00
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
struct sctp_vrf *
|
2007-05-08 00:21:05 +00:00
|
|
|
sctp_find_vrf(uint32_t vrf_id)
|
2007-03-15 11:27:14 +00:00
|
|
|
{
|
|
|
|
struct sctp_vrflist *bucket;
|
|
|
|
struct sctp_vrf *liste;
|
|
|
|
|
2008-06-14 07:58:05 +00:00
|
|
|
bucket = &SCTP_BASE_INFO(sctp_vrfhash)[(vrf_id & SCTP_BASE_INFO(hashvrfmark))];
|
2007-03-15 11:27:14 +00:00
|
|
|
LIST_FOREACH(liste, bucket, next_vrf) {
|
2007-05-08 00:21:05 +00:00
|
|
|
if (vrf_id == liste->vrf_id) {
|
2007-03-15 11:27:14 +00:00
|
|
|
return (liste);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2013-02-09 17:26:14 +00:00
|
|
|
|
2007-06-14 22:59:04 +00:00
|
|
|
void
|
|
|
|
sctp_free_vrf(struct sctp_vrf *vrf)
|
|
|
|
{
|
2008-12-06 13:19:54 +00:00
|
|
|
if (SCTP_DECREMENT_AND_CHECK_REFCOUNT(&vrf->refcount)) {
|
2008-02-22 15:08:10 +00:00
|
|
|
if (vrf->vrf_addr_hash) {
|
|
|
|
SCTP_HASH_FREE(vrf->vrf_addr_hash, vrf->vrf_addr_hashmark);
|
|
|
|
vrf->vrf_addr_hash = NULL;
|
|
|
|
}
|
2007-06-14 22:59:04 +00:00
|
|
|
/* We zero'd the count */
|
|
|
|
LIST_REMOVE(vrf, next_vrf);
|
|
|
|
SCTP_FREE(vrf, SCTP_M_VRF);
|
2008-06-14 07:58:05 +00:00
|
|
|
atomic_subtract_int(&SCTP_BASE_INFO(ipi_count_vrfs), 1);
|
2007-06-14 22:59:04 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-03 11:15:32 +00:00
|
|
|
|
2013-02-09 17:26:14 +00:00
|
|
|
|
2007-05-08 00:21:05 +00:00
|
|
|
void
|
|
|
|
sctp_free_ifn(struct sctp_ifn *sctp_ifnp)
|
|
|
|
{
|
2008-12-06 13:19:54 +00:00
|
|
|
if (SCTP_DECREMENT_AND_CHECK_REFCOUNT(&sctp_ifnp->refcount)) {
|
2007-05-08 00:21:05 +00:00
|
|
|
/* We zero'd the count */
|
2007-06-14 22:59:04 +00:00
|
|
|
if (sctp_ifnp->vrf) {
|
|
|
|
sctp_free_vrf(sctp_ifnp->vrf);
|
|
|
|
}
|
2007-05-29 09:29:03 +00:00
|
|
|
SCTP_FREE(sctp_ifnp, SCTP_M_IFN);
|
2008-06-14 07:58:05 +00:00
|
|
|
atomic_subtract_int(&SCTP_BASE_INFO(ipi_count_ifns), 1);
|
2007-05-08 00:21:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-09 17:26:14 +00:00
|
|
|
|
2007-05-08 00:21:05 +00:00
|
|
|
void
|
2007-06-02 11:05:08 +00:00
|
|
|
sctp_update_ifn_mtu(uint32_t ifn_index, uint32_t mtu)
|
2007-05-08 00:21:05 +00:00
|
|
|
{
|
|
|
|
struct sctp_ifn *sctp_ifnp;
|
|
|
|
|
2007-06-02 11:05:08 +00:00
|
|
|
sctp_ifnp = sctp_find_ifn((void *)NULL, ifn_index);
|
2007-05-08 00:21:05 +00:00
|
|
|
if (sctp_ifnp != NULL) {
|
|
|
|
sctp_ifnp->ifn_mtu = mtu;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
void
|
|
|
|
sctp_free_ifa(struct sctp_ifa *sctp_ifap)
|
|
|
|
{
|
2008-12-06 13:19:54 +00:00
|
|
|
if (SCTP_DECREMENT_AND_CHECK_REFCOUNT(&sctp_ifap->refcount)) {
|
2007-03-15 11:27:14 +00:00
|
|
|
/* We zero'd the count */
|
2007-06-14 22:59:04 +00:00
|
|
|
if (sctp_ifap->ifn_p) {
|
|
|
|
sctp_free_ifn(sctp_ifap->ifn_p);
|
|
|
|
}
|
2007-05-29 09:29:03 +00:00
|
|
|
SCTP_FREE(sctp_ifap, SCTP_M_IFA);
|
2008-06-14 07:58:05 +00:00
|
|
|
atomic_subtract_int(&SCTP_BASE_INFO(ipi_count_ifas), 1);
|
2007-05-08 00:21:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-09 17:26:14 +00:00
|
|
|
|
2007-05-08 00:21:05 +00:00
|
|
|
static void
|
|
|
|
sctp_delete_ifn(struct sctp_ifn *sctp_ifnp, int hold_addr_lock)
|
|
|
|
{
|
|
|
|
struct sctp_ifn *found;
|
|
|
|
|
2007-06-02 11:05:08 +00:00
|
|
|
found = sctp_find_ifn(sctp_ifnp->ifn_p, sctp_ifnp->ifn_index);
|
2007-05-08 00:21:05 +00:00
|
|
|
if (found == NULL) {
|
|
|
|
/* Not in the list.. sorry */
|
|
|
|
return;
|
2007-03-15 11:27:14 +00:00
|
|
|
}
|
2007-05-08 00:21:05 +00:00
|
|
|
if (hold_addr_lock == 0)
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_WLOCK();
|
2007-05-08 00:21:05 +00:00
|
|
|
LIST_REMOVE(sctp_ifnp, next_bucket);
|
|
|
|
LIST_REMOVE(sctp_ifnp, next_ifn);
|
2007-06-01 11:19:54 +00:00
|
|
|
SCTP_DEREGISTER_INTERFACE(sctp_ifnp->ifn_index,
|
|
|
|
sctp_ifnp->registered_af);
|
2007-05-08 00:21:05 +00:00
|
|
|
if (hold_addr_lock == 0)
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_WUNLOCK();
|
2007-05-08 00:21:05 +00:00
|
|
|
/* Take away the reference, and possibly free it */
|
|
|
|
sctp_free_ifn(sctp_ifnp);
|
2007-03-15 11:27:14 +00:00
|
|
|
}
|
|
|
|
|
2013-02-09 17:26:14 +00:00
|
|
|
|
2007-09-08 17:48:46 +00:00
|
|
|
void
|
2007-09-21 04:19:33 +00:00
|
|
|
sctp_mark_ifa_addr_down(uint32_t vrf_id, struct sockaddr *addr,
|
|
|
|
const char *if_name, uint32_t ifn_index)
|
2007-09-08 17:48:46 +00:00
|
|
|
{
|
|
|
|
struct sctp_vrf *vrf;
|
2013-02-09 17:26:14 +00:00
|
|
|
struct sctp_ifa *sctp_ifap;
|
2007-09-08 17:48:46 +00:00
|
|
|
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_RLOCK();
|
2007-09-08 17:48:46 +00:00
|
|
|
vrf = sctp_find_vrf(vrf_id);
|
|
|
|
if (vrf == NULL) {
|
2007-09-21 04:19:33 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB4, "Can't find vrf_id 0x%x\n", vrf_id);
|
2007-09-08 17:48:46 +00:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
}
|
|
|
|
sctp_ifap = sctp_find_ifa_by_addr(addr, vrf->vrf_id, SCTP_ADDR_LOCKED);
|
|
|
|
if (sctp_ifap == NULL) {
|
2007-09-21 04:19:33 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB4, "Can't find sctp_ifap for address\n");
|
2007-09-08 17:48:46 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (sctp_ifap->ifn_p == NULL) {
|
2007-09-21 04:19:33 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB4, "IFA has no IFN - can't mark unuseable\n");
|
2007-09-08 17:48:46 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (if_name) {
|
2011-11-18 09:01:08 +00:00
|
|
|
if (strncmp(if_name, sctp_ifap->ifn_p->ifn_name, SCTP_IFNAMSIZ) != 0) {
|
2007-09-21 04:19:33 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB4, "IFN %s of IFA not the same as %s\n",
|
2011-11-18 09:01:08 +00:00
|
|
|
sctp_ifap->ifn_p->ifn_name, if_name);
|
2007-09-08 17:48:46 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (sctp_ifap->ifn_p->ifn_index != ifn_index) {
|
2007-09-21 04:19:33 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB4, "IFA owned by ifn_index:%d down command for ifn_index:%d - ignored\n",
|
2007-09-08 17:48:46 +00:00
|
|
|
sctp_ifap->ifn_p->ifn_index, ifn_index);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sctp_ifap->localifa_flags &= (~SCTP_ADDR_VALID);
|
|
|
|
sctp_ifap->localifa_flags |= SCTP_ADDR_IFA_UNUSEABLE;
|
|
|
|
out:
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_RUNLOCK();
|
2007-09-08 17:48:46 +00:00
|
|
|
}
|
|
|
|
|
2013-02-09 17:26:14 +00:00
|
|
|
|
2007-09-08 17:48:46 +00:00
|
|
|
void
|
2007-09-21 04:19:33 +00:00
|
|
|
sctp_mark_ifa_addr_up(uint32_t vrf_id, struct sockaddr *addr,
|
|
|
|
const char *if_name, uint32_t ifn_index)
|
2007-09-08 17:48:46 +00:00
|
|
|
{
|
|
|
|
struct sctp_vrf *vrf;
|
2013-02-09 17:26:14 +00:00
|
|
|
struct sctp_ifa *sctp_ifap;
|
2007-09-08 17:48:46 +00:00
|
|
|
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_RLOCK();
|
2007-09-08 17:48:46 +00:00
|
|
|
vrf = sctp_find_vrf(vrf_id);
|
|
|
|
if (vrf == NULL) {
|
2007-09-21 04:19:33 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB4, "Can't find vrf_id 0x%x\n", vrf_id);
|
2007-09-08 17:48:46 +00:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
}
|
|
|
|
sctp_ifap = sctp_find_ifa_by_addr(addr, vrf->vrf_id, SCTP_ADDR_LOCKED);
|
|
|
|
if (sctp_ifap == NULL) {
|
2007-09-21 04:19:33 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB4, "Can't find sctp_ifap for address\n");
|
2007-09-08 17:48:46 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (sctp_ifap->ifn_p == NULL) {
|
2007-09-21 04:19:33 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB4, "IFA has no IFN - can't mark unuseable\n");
|
2007-09-08 17:48:46 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (if_name) {
|
2011-11-18 09:01:08 +00:00
|
|
|
if (strncmp(if_name, sctp_ifap->ifn_p->ifn_name, SCTP_IFNAMSIZ) != 0) {
|
2007-09-21 04:19:33 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB4, "IFN %s of IFA not the same as %s\n",
|
2011-11-18 09:01:08 +00:00
|
|
|
sctp_ifap->ifn_p->ifn_name, if_name);
|
2007-09-08 17:48:46 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (sctp_ifap->ifn_p->ifn_index != ifn_index) {
|
2007-09-21 04:19:33 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB4, "IFA owned by ifn_index:%d down command for ifn_index:%d - ignored\n",
|
2007-09-08 17:48:46 +00:00
|
|
|
sctp_ifap->ifn_p->ifn_index, ifn_index);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sctp_ifap->localifa_flags &= (~SCTP_ADDR_IFA_UNUSEABLE);
|
|
|
|
sctp_ifap->localifa_flags |= SCTP_ADDR_VALID;
|
|
|
|
out:
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_RUNLOCK();
|
2007-09-08 17:48:46 +00:00
|
|
|
}
|
|
|
|
|
2013-02-09 17:26:14 +00:00
|
|
|
|
2007-09-21 04:19:33 +00:00
|
|
|
/*-
|
|
|
|
* Add an ifa to an ifn.
|
|
|
|
* Register the interface as necessary.
|
|
|
|
* NOTE: ADDR write lock MUST be held.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
sctp_add_ifa_to_ifn(struct sctp_ifn *sctp_ifnp, struct sctp_ifa *sctp_ifap)
|
|
|
|
{
|
|
|
|
int ifa_af;
|
|
|
|
|
|
|
|
LIST_INSERT_HEAD(&sctp_ifnp->ifalist, sctp_ifap, next_ifa);
|
|
|
|
sctp_ifap->ifn_p = sctp_ifnp;
|
|
|
|
atomic_add_int(&sctp_ifap->ifn_p->refcount, 1);
|
|
|
|
/* update address counts */
|
|
|
|
sctp_ifnp->ifa_count++;
|
|
|
|
ifa_af = sctp_ifap->address.sa.sa_family;
|
2011-04-30 11:18:16 +00:00
|
|
|
switch (ifa_af) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
2007-09-21 04:19:33 +00:00
|
|
|
sctp_ifnp->num_v4++;
|
2011-04-30 11:18:16 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
2007-09-21 04:19:33 +00:00
|
|
|
sctp_ifnp->num_v6++;
|
2011-04-30 11:18:16 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2007-09-21 04:19:33 +00:00
|
|
|
if (sctp_ifnp->ifa_count == 1) {
|
|
|
|
/* register the new interface */
|
|
|
|
SCTP_REGISTER_INTERFACE(sctp_ifnp->ifn_index, ifa_af);
|
|
|
|
sctp_ifnp->registered_af = ifa_af;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-09 17:26:14 +00:00
|
|
|
|
2007-09-21 04:19:33 +00:00
|
|
|
/*-
|
|
|
|
* Remove an ifa from its ifn.
|
|
|
|
* If no more addresses exist, remove the ifn too. Otherwise, re-register
|
|
|
|
* the interface based on the remaining address families left.
|
|
|
|
* NOTE: ADDR write lock MUST be held.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
sctp_remove_ifa_from_ifn(struct sctp_ifa *sctp_ifap)
|
|
|
|
{
|
|
|
|
LIST_REMOVE(sctp_ifap, next_ifa);
|
|
|
|
if (sctp_ifap->ifn_p) {
|
|
|
|
/* update address counts */
|
|
|
|
sctp_ifap->ifn_p->ifa_count--;
|
2011-04-30 11:18:16 +00:00
|
|
|
switch (sctp_ifap->address.sa.sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
2007-09-21 04:19:33 +00:00
|
|
|
sctp_ifap->ifn_p->num_v4--;
|
2011-04-30 11:18:16 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
sctp_ifap->ifn_p->num_v6--;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2007-09-21 04:19:33 +00:00
|
|
|
|
2009-11-17 20:56:14 +00:00
|
|
|
if (LIST_EMPTY(&sctp_ifap->ifn_p->ifalist)) {
|
2007-09-21 04:19:33 +00:00
|
|
|
/* remove the ifn, possibly freeing it */
|
|
|
|
sctp_delete_ifn(sctp_ifap->ifn_p, SCTP_ADDR_LOCKED);
|
|
|
|
} else {
|
|
|
|
/* re-register address family type, if needed */
|
|
|
|
if ((sctp_ifap->ifn_p->num_v6 == 0) &&
|
|
|
|
(sctp_ifap->ifn_p->registered_af == AF_INET6)) {
|
2011-12-27 10:16:24 +00:00
|
|
|
SCTP_DEREGISTER_INTERFACE(sctp_ifap->ifn_p->ifn_index, AF_INET6);
|
|
|
|
SCTP_REGISTER_INTERFACE(sctp_ifap->ifn_p->ifn_index, AF_INET);
|
2007-09-21 04:19:33 +00:00
|
|
|
sctp_ifap->ifn_p->registered_af = AF_INET;
|
|
|
|
} else if ((sctp_ifap->ifn_p->num_v4 == 0) &&
|
|
|
|
(sctp_ifap->ifn_p->registered_af == AF_INET)) {
|
2011-12-27 10:16:24 +00:00
|
|
|
SCTP_DEREGISTER_INTERFACE(sctp_ifap->ifn_p->ifn_index, AF_INET);
|
|
|
|
SCTP_REGISTER_INTERFACE(sctp_ifap->ifn_p->ifn_index, AF_INET6);
|
2007-09-21 04:19:33 +00:00
|
|
|
sctp_ifap->ifn_p->registered_af = AF_INET6;
|
|
|
|
}
|
|
|
|
/* free the ifn refcount */
|
|
|
|
sctp_free_ifn(sctp_ifap->ifn_p);
|
|
|
|
}
|
|
|
|
sctp_ifap->ifn_p = NULL;
|
|
|
|
}
|
|
|
|
}
|
2007-05-08 00:21:05 +00:00
|
|
|
|
2013-02-09 17:26:14 +00:00
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
struct sctp_ifa *
|
2007-05-08 00:21:05 +00:00
|
|
|
sctp_add_addr_to_vrf(uint32_t vrf_id, void *ifn, uint32_t ifn_index,
|
2007-09-21 04:19:33 +00:00
|
|
|
uint32_t ifn_type, const char *if_name, void *ifa,
|
|
|
|
struct sockaddr *addr, uint32_t ifa_flags,
|
2007-05-08 00:21:05 +00:00
|
|
|
int dynamic_add)
|
2007-03-15 11:27:14 +00:00
|
|
|
{
|
|
|
|
struct sctp_vrf *vrf;
|
|
|
|
struct sctp_ifn *sctp_ifnp = NULL;
|
|
|
|
struct sctp_ifa *sctp_ifap = NULL;
|
2007-05-08 00:21:05 +00:00
|
|
|
struct sctp_ifalist *hash_addr_head;
|
|
|
|
struct sctp_ifnlist *hash_ifn_head;
|
2007-03-19 11:11:16 +00:00
|
|
|
uint32_t hash_of_addr;
|
2007-06-01 11:19:54 +00:00
|
|
|
int new_ifn_af = 0;
|
2007-03-15 11:27:14 +00:00
|
|
|
|
2007-09-21 04:19:33 +00:00
|
|
|
#ifdef SCTP_DEBUG
|
|
|
|
SCTPDBG(SCTP_DEBUG_PCB4, "vrf_id 0x%x: adding address: ", vrf_id);
|
|
|
|
SCTPDBG_ADDR(SCTP_DEBUG_PCB4, addr);
|
|
|
|
#endif
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_WLOCK();
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_ifnp = sctp_find_ifn(ifn, ifn_index);
|
|
|
|
if (sctp_ifnp) {
|
|
|
|
vrf = sctp_ifnp->vrf;
|
|
|
|
} else {
|
|
|
|
vrf = sctp_find_vrf(vrf_id);
|
2007-03-15 11:27:14 +00:00
|
|
|
if (vrf == NULL) {
|
2007-06-14 22:59:04 +00:00
|
|
|
vrf = sctp_allocate_vrf(vrf_id);
|
|
|
|
if (vrf == NULL) {
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_WUNLOCK();
|
2007-06-14 22:59:04 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sctp_ifnp == NULL) {
|
|
|
|
/*
|
|
|
|
* build one and add it, can't hold lock until after malloc
|
|
|
|
* done though.
|
|
|
|
*/
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_WUNLOCK();
|
2007-09-21 04:19:33 +00:00
|
|
|
SCTP_MALLOC(sctp_ifnp, struct sctp_ifn *,
|
|
|
|
sizeof(struct sctp_ifn), SCTP_M_IFN);
|
2007-03-15 11:27:14 +00:00
|
|
|
if (sctp_ifnp == NULL) {
|
|
|
|
#ifdef INVARIANTS
|
2010-09-05 13:41:45 +00:00
|
|
|
panic("No memory for IFN");
|
2007-03-15 11:27:14 +00:00
|
|
|
#endif
|
|
|
|
return (NULL);
|
|
|
|
}
|
2007-06-18 21:59:15 +00:00
|
|
|
memset(sctp_ifnp, 0, sizeof(struct sctp_ifn));
|
2007-03-15 11:27:14 +00:00
|
|
|
sctp_ifnp->ifn_index = ifn_index;
|
|
|
|
sctp_ifnp->ifn_p = ifn;
|
|
|
|
sctp_ifnp->ifn_type = ifn_type;
|
2007-10-16 14:05:51 +00:00
|
|
|
sctp_ifnp->refcount = 0;
|
2007-03-15 11:27:14 +00:00
|
|
|
sctp_ifnp->vrf = vrf;
|
2007-06-14 22:59:04 +00:00
|
|
|
atomic_add_int(&vrf->refcount, 1);
|
2007-06-01 11:19:54 +00:00
|
|
|
sctp_ifnp->ifn_mtu = SCTP_GATHER_MTU_FROM_IFN_INFO(ifn, ifn_index, addr->sa_family);
|
2007-05-08 00:21:05 +00:00
|
|
|
if (if_name != NULL) {
|
2011-11-13 11:53:18 +00:00
|
|
|
snprintf(sctp_ifnp->ifn_name, SCTP_IFNAMSIZ, "%s", if_name);
|
2007-05-08 00:21:05 +00:00
|
|
|
} else {
|
2011-11-13 11:53:18 +00:00
|
|
|
snprintf(sctp_ifnp->ifn_name, SCTP_IFNAMSIZ, "%s", "unknown");
|
2007-05-08 00:21:05 +00:00
|
|
|
}
|
2008-06-14 07:58:05 +00:00
|
|
|
hash_ifn_head = &SCTP_BASE_INFO(vrf_ifn_hash)[(ifn_index & SCTP_BASE_INFO(vrf_ifn_hashmark))];
|
2007-03-15 11:27:14 +00:00
|
|
|
LIST_INIT(&sctp_ifnp->ifalist);
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_WLOCK();
|
2007-05-08 00:21:05 +00:00
|
|
|
LIST_INSERT_HEAD(hash_ifn_head, sctp_ifnp, next_bucket);
|
2007-03-15 11:27:14 +00:00
|
|
|
LIST_INSERT_HEAD(&vrf->ifnlist, sctp_ifnp, next_ifn);
|
2008-06-14 07:58:05 +00:00
|
|
|
atomic_add_int(&SCTP_BASE_INFO(ipi_count_ifns), 1);
|
2007-06-01 11:19:54 +00:00
|
|
|
new_ifn_af = 1;
|
2007-03-15 11:27:14 +00:00
|
|
|
}
|
2007-09-08 17:48:46 +00:00
|
|
|
sctp_ifap = sctp_find_ifa_by_addr(addr, vrf->vrf_id, SCTP_ADDR_LOCKED);
|
2007-03-15 11:27:14 +00:00
|
|
|
if (sctp_ifap) {
|
|
|
|
/* Hmm, it already exists? */
|
|
|
|
if ((sctp_ifap->ifn_p) &&
|
|
|
|
(sctp_ifap->ifn_p->ifn_index == ifn_index)) {
|
2007-09-21 04:19:33 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB4, "Using existing ifn %s (0x%x) for ifa %p\n",
|
|
|
|
sctp_ifap->ifn_p->ifn_name, ifn_index,
|
2012-09-05 18:52:01 +00:00
|
|
|
(void *)sctp_ifap);
|
2007-06-14 22:59:04 +00:00
|
|
|
if (new_ifn_af) {
|
|
|
|
/* Remove the created one that we don't want */
|
2007-09-21 04:19:33 +00:00
|
|
|
sctp_delete_ifn(sctp_ifnp, SCTP_ADDR_LOCKED);
|
2007-06-14 22:59:04 +00:00
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
if (sctp_ifap->localifa_flags & SCTP_BEING_DELETED) {
|
|
|
|
/* easy to solve, just switch back to active */
|
2007-09-21 04:19:33 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB4, "Clearing deleted ifa flag\n");
|
2007-03-15 11:27:14 +00:00
|
|
|
sctp_ifap->localifa_flags = SCTP_ADDR_VALID;
|
|
|
|
sctp_ifap->ifn_p = sctp_ifnp;
|
2007-06-14 22:59:04 +00:00
|
|
|
atomic_add_int(&sctp_ifap->ifn_p->refcount, 1);
|
2007-03-15 11:27:14 +00:00
|
|
|
}
|
2007-09-21 04:19:33 +00:00
|
|
|
exit_stage_left:
|
|
|
|
SCTP_IPI_ADDR_WUNLOCK();
|
|
|
|
return (sctp_ifap);
|
2007-03-15 11:27:14 +00:00
|
|
|
} else {
|
|
|
|
if (sctp_ifap->ifn_p) {
|
|
|
|
/*
|
2010-11-09 16:18:32 +00:00
|
|
|
* The last IFN gets the address, remove the
|
|
|
|
* old one
|
2007-03-15 11:27:14 +00:00
|
|
|
*/
|
2007-09-21 04:19:33 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB4, "Moving ifa %p from %s (0x%x) to %s (0x%x)\n",
|
2012-09-05 18:52:01 +00:00
|
|
|
(void *)sctp_ifap, sctp_ifap->ifn_p->ifn_name,
|
2007-09-21 04:19:33 +00:00
|
|
|
sctp_ifap->ifn_p->ifn_index, if_name,
|
|
|
|
ifn_index);
|
|
|
|
/* remove the address from the old ifn */
|
|
|
|
sctp_remove_ifa_from_ifn(sctp_ifap);
|
|
|
|
/* move the address over to the new ifn */
|
|
|
|
sctp_add_ifa_to_ifn(sctp_ifnp, sctp_ifap);
|
2007-03-15 11:27:14 +00:00
|
|
|
goto exit_stage_left;
|
|
|
|
} else {
|
|
|
|
/* repair ifnp which was NULL ? */
|
|
|
|
sctp_ifap->localifa_flags = SCTP_ADDR_VALID;
|
2007-09-21 04:19:33 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB4, "Repairing ifn %p for ifa %p\n",
|
2012-09-05 18:52:01 +00:00
|
|
|
(void *)sctp_ifnp, (void *)sctp_ifap);
|
2007-09-21 04:19:33 +00:00
|
|
|
sctp_add_ifa_to_ifn(sctp_ifnp, sctp_ifap);
|
2007-03-15 11:27:14 +00:00
|
|
|
}
|
|
|
|
goto exit_stage_left;
|
|
|
|
}
|
|
|
|
}
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_WUNLOCK();
|
2007-05-29 09:29:03 +00:00
|
|
|
SCTP_MALLOC(sctp_ifap, struct sctp_ifa *, sizeof(struct sctp_ifa), SCTP_M_IFA);
|
2007-03-15 11:27:14 +00:00
|
|
|
if (sctp_ifap == NULL) {
|
|
|
|
#ifdef INVARIANTS
|
|
|
|
panic("No memory for IFA");
|
|
|
|
#endif
|
|
|
|
return (NULL);
|
|
|
|
}
|
2007-03-19 06:53:02 +00:00
|
|
|
memset(sctp_ifap, 0, sizeof(struct sctp_ifa));
|
2007-03-15 11:27:14 +00:00
|
|
|
sctp_ifap->ifn_p = sctp_ifnp;
|
|
|
|
atomic_add_int(&sctp_ifnp->refcount, 1);
|
2007-06-15 03:16:48 +00:00
|
|
|
sctp_ifap->vrf_id = vrf_id;
|
2007-03-15 11:27:14 +00:00
|
|
|
sctp_ifap->ifa = ifa;
|
|
|
|
memcpy(&sctp_ifap->address, addr, addr->sa_len);
|
|
|
|
sctp_ifap->localifa_flags = SCTP_ADDR_VALID | SCTP_ADDR_DEFER_USE;
|
|
|
|
sctp_ifap->flags = ifa_flags;
|
|
|
|
/* Set scope */
|
2008-04-16 17:24:18 +00:00
|
|
|
switch (sctp_ifap->address.sa.sa_family) {
|
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;
|
2007-03-15 11:27:14 +00:00
|
|
|
|
2014-09-07 09:06:26 +00:00
|
|
|
sin = &sctp_ifap->address.sin;
|
2008-04-16 17:24:18 +00:00
|
|
|
if (SCTP_IFN_IS_IFT_LOOP(sctp_ifap->ifn_p) ||
|
|
|
|
(IN4_ISLOOPBACK_ADDRESS(&sin->sin_addr))) {
|
|
|
|
sctp_ifap->src_is_loop = 1;
|
|
|
|
}
|
|
|
|
if ((IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
|
|
|
|
sctp_ifap->src_is_priv = 1;
|
|
|
|
}
|
|
|
|
sctp_ifnp->num_v4++;
|
|
|
|
if (new_ifn_af)
|
|
|
|
new_ifn_af = AF_INET;
|
|
|
|
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
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
{
|
|
|
|
/* ok to use deprecated addresses? */
|
|
|
|
struct sockaddr_in6 *sin6;
|
2007-03-15 11:27:14 +00:00
|
|
|
|
2014-09-07 09:06:26 +00:00
|
|
|
sin6 = &sctp_ifap->address.sin6;
|
2008-04-16 17:24:18 +00:00
|
|
|
if (SCTP_IFN_IS_IFT_LOOP(sctp_ifap->ifn_p) ||
|
|
|
|
(IN6_IS_ADDR_LOOPBACK(&sin6->sin6_addr))) {
|
|
|
|
sctp_ifap->src_is_loop = 1;
|
|
|
|
}
|
|
|
|
if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
|
|
|
|
sctp_ifap->src_is_priv = 1;
|
|
|
|
}
|
|
|
|
sctp_ifnp->num_v6++;
|
|
|
|
if (new_ifn_af)
|
|
|
|
new_ifn_af = AF_INET6;
|
|
|
|
break;
|
2007-03-15 11:27:14 +00:00
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
#endif
|
|
|
|
default:
|
2007-06-01 11:19:54 +00:00
|
|
|
new_ifn_af = 0;
|
2008-04-16 17:24:18 +00:00
|
|
|
break;
|
2007-03-15 11:27:14 +00:00
|
|
|
}
|
2007-03-19 11:11:16 +00:00
|
|
|
hash_of_addr = sctp_get_ifa_hash_val(&sctp_ifap->address.sa);
|
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
if ((sctp_ifap->src_is_priv == 0) &&
|
|
|
|
(sctp_ifap->src_is_loop == 0)) {
|
|
|
|
sctp_ifap->src_is_glob = 1;
|
|
|
|
}
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_WLOCK();
|
2007-05-08 00:21:05 +00:00
|
|
|
hash_addr_head = &vrf->vrf_addr_hash[(hash_of_addr & vrf->vrf_addr_hashmark)];
|
|
|
|
LIST_INSERT_HEAD(hash_addr_head, sctp_ifap, next_bucket);
|
2007-03-15 11:27:14 +00:00
|
|
|
sctp_ifap->refcount = 1;
|
|
|
|
LIST_INSERT_HEAD(&sctp_ifnp->ifalist, sctp_ifap, next_ifa);
|
|
|
|
sctp_ifnp->ifa_count++;
|
|
|
|
vrf->total_ifa_count++;
|
2008-06-14 07:58:05 +00:00
|
|
|
atomic_add_int(&SCTP_BASE_INFO(ipi_count_ifas), 1);
|
2007-06-01 11:19:54 +00:00
|
|
|
if (new_ifn_af) {
|
|
|
|
SCTP_REGISTER_INTERFACE(ifn_index, new_ifn_af);
|
|
|
|
sctp_ifnp->registered_af = new_ifn_af;
|
|
|
|
}
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_WUNLOCK();
|
2007-05-02 12:50:13 +00:00
|
|
|
if (dynamic_add) {
|
|
|
|
/*
|
|
|
|
* Bump up the refcount so that when the timer completes it
|
|
|
|
* will drop back down.
|
|
|
|
*/
|
|
|
|
struct sctp_laddr *wi;
|
|
|
|
|
|
|
|
atomic_add_int(&sctp_ifap->refcount, 1);
|
2008-06-14 07:58:05 +00:00
|
|
|
wi = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_laddr), struct sctp_laddr);
|
2007-05-02 12:50:13 +00:00
|
|
|
if (wi == NULL) {
|
|
|
|
/*
|
|
|
|
* Gak, what can we do? We have lost an address
|
|
|
|
* change can you say HOSED?
|
|
|
|
*/
|
2007-09-21 04:19:33 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB4, "Lost an address change?\n");
|
2007-05-02 12:50:13 +00:00
|
|
|
/* Opps, must decrement the count */
|
2007-09-21 04:19:33 +00:00
|
|
|
sctp_del_addr_from_vrf(vrf_id, addr, ifn_index,
|
|
|
|
if_name);
|
2007-05-02 12:50:13 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
SCTP_INCR_LADDR_COUNT();
|
|
|
|
bzero(wi, sizeof(*wi));
|
2007-05-28 11:17:24 +00:00
|
|
|
(void)SCTP_GETTIME_TIMEVAL(&wi->start_time);
|
2007-05-02 12:50:13 +00:00
|
|
|
wi->ifa = sctp_ifap;
|
|
|
|
wi->action = SCTP_ADD_IP_ADDRESS;
|
2010-05-16 17:03:56 +00:00
|
|
|
|
|
|
|
SCTP_WQ_ADDR_LOCK();
|
2008-06-14 07:58:05 +00:00
|
|
|
LIST_INSERT_HEAD(&SCTP_BASE_INFO(addr_wq), wi, sctp_nxt_addr);
|
2010-05-16 17:03:56 +00:00
|
|
|
SCTP_WQ_ADDR_UNLOCK();
|
|
|
|
|
2007-05-02 12:50:13 +00:00
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_ADDR_WQ,
|
|
|
|
(struct sctp_inpcb *)NULL,
|
|
|
|
(struct sctp_tcb *)NULL,
|
|
|
|
(struct sctp_nets *)NULL);
|
2007-05-08 00:21:05 +00:00
|
|
|
} else {
|
|
|
|
/* it's ready for use */
|
|
|
|
sctp_ifap->localifa_flags &= ~SCTP_ADDR_DEFER_USE;
|
2007-05-02 12:50:13 +00:00
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
return (sctp_ifap);
|
|
|
|
}
|
|
|
|
|
2007-05-02 12:50:13 +00:00
|
|
|
void
|
2007-05-08 00:21:05 +00:00
|
|
|
sctp_del_addr_from_vrf(uint32_t vrf_id, struct sockaddr *addr,
|
2007-09-08 17:48:46 +00:00
|
|
|
uint32_t ifn_index, const char *if_name)
|
2007-03-15 11:27:14 +00:00
|
|
|
{
|
|
|
|
struct sctp_vrf *vrf;
|
|
|
|
struct sctp_ifa *sctp_ifap = NULL;
|
|
|
|
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_WLOCK();
|
2007-05-08 00:21:05 +00:00
|
|
|
vrf = sctp_find_vrf(vrf_id);
|
2007-03-15 11:27:14 +00:00
|
|
|
if (vrf == NULL) {
|
2007-09-21 04:19:33 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB4, "Can't find vrf_id 0x%x\n", vrf_id);
|
2007-03-15 11:27:14 +00:00
|
|
|
goto out_now;
|
|
|
|
}
|
2007-09-21 04:19:33 +00:00
|
|
|
#ifdef SCTP_DEBUG
|
|
|
|
SCTPDBG(SCTP_DEBUG_PCB4, "vrf_id 0x%x: deleting address:", vrf_id);
|
|
|
|
SCTPDBG_ADDR(SCTP_DEBUG_PCB4, addr);
|
|
|
|
#endif
|
2007-09-08 17:48:46 +00:00
|
|
|
sctp_ifap = sctp_find_ifa_by_addr(addr, vrf->vrf_id, SCTP_ADDR_LOCKED);
|
2007-03-15 11:27:14 +00:00
|
|
|
if (sctp_ifap) {
|
2007-09-08 17:48:46 +00:00
|
|
|
/* Validate the delete */
|
|
|
|
if (sctp_ifap->ifn_p) {
|
|
|
|
int valid = 0;
|
|
|
|
|
|
|
|
/*-
|
|
|
|
* The name has priority over the ifn_index
|
|
|
|
* if its given. We do this especially for
|
|
|
|
* panda who might recycle indexes fast.
|
|
|
|
*/
|
|
|
|
if (if_name) {
|
2011-11-13 11:53:18 +00:00
|
|
|
if (strncmp(if_name, sctp_ifap->ifn_p->ifn_name, SCTP_IFNAMSIZ) == 0) {
|
|
|
|
/* They match its a correct delete */
|
|
|
|
valid = 1;
|
2007-09-08 17:48:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!valid) {
|
|
|
|
/* last ditch check ifn_index */
|
|
|
|
if (ifn_index == sctp_ifap->ifn_p->ifn_index) {
|
|
|
|
valid = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!valid) {
|
2007-09-21 04:19:33 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB4, "ifn:%d ifname:%s does not match addresses\n",
|
2007-09-08 17:48:46 +00:00
|
|
|
ifn_index, ((if_name == NULL) ? "NULL" : if_name));
|
2007-09-21 04:19:33 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB4, "ifn:%d ifname:%s - ignoring delete\n",
|
2007-09-08 17:48:46 +00:00
|
|
|
sctp_ifap->ifn_p->ifn_index, sctp_ifap->ifn_p->ifn_name);
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_WUNLOCK();
|
2007-09-08 17:48:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-09-05 18:52:01 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB4, "Deleting ifa %p\n", (void *)sctp_ifap);
|
2007-03-15 11:27:14 +00:00
|
|
|
sctp_ifap->localifa_flags &= SCTP_ADDR_VALID;
|
2014-03-29 21:26:45 +00:00
|
|
|
/*
|
|
|
|
* We don't set the flag. This means that the structure will
|
|
|
|
* hang around in EP's that have bound specific to it until
|
|
|
|
* they close. This gives us TCP like behavior if someone
|
|
|
|
* removes an address (or for that matter adds it right
|
|
|
|
* back).
|
|
|
|
*/
|
|
|
|
/* sctp_ifap->localifa_flags |= SCTP_BEING_DELETED; */
|
2007-03-15 11:27:14 +00:00
|
|
|
vrf->total_ifa_count--;
|
2007-03-19 11:11:16 +00:00
|
|
|
LIST_REMOVE(sctp_ifap, next_bucket);
|
2007-09-21 04:19:33 +00:00
|
|
|
sctp_remove_ifa_from_ifn(sctp_ifap);
|
2007-05-08 00:21:05 +00:00
|
|
|
}
|
|
|
|
#ifdef SCTP_DEBUG
|
|
|
|
else {
|
2007-09-21 04:19:33 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB4, "Del Addr-ifn:%d Could not find address:",
|
2007-03-15 11:27:14 +00:00
|
|
|
ifn_index);
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTPDBG_ADDR(SCTP_DEBUG_PCB1, addr);
|
2007-03-15 11:27:14 +00:00
|
|
|
}
|
2007-05-08 00:21:05 +00:00
|
|
|
#endif
|
2007-05-09 13:30:06 +00:00
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
out_now:
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_WUNLOCK();
|
2007-05-02 12:50:13 +00:00
|
|
|
if (sctp_ifap) {
|
|
|
|
struct sctp_laddr *wi;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2008-06-14 07:58:05 +00:00
|
|
|
wi = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_laddr), struct sctp_laddr);
|
2007-05-02 12:50:13 +00:00
|
|
|
if (wi == NULL) {
|
|
|
|
/*
|
|
|
|
* Gak, what can we do? We have lost an address
|
|
|
|
* change can you say HOSED?
|
|
|
|
*/
|
2007-09-21 04:19:33 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB4, "Lost an address change?\n");
|
2007-05-02 12:50:13 +00:00
|
|
|
|
2007-09-18 15:16:39 +00:00
|
|
|
/* Oops, must decrement the count */
|
2007-05-02 12:50:13 +00:00
|
|
|
sctp_free_ifa(sctp_ifap);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SCTP_INCR_LADDR_COUNT();
|
|
|
|
bzero(wi, sizeof(*wi));
|
2007-05-28 11:17:24 +00:00
|
|
|
(void)SCTP_GETTIME_TIMEVAL(&wi->start_time);
|
2007-05-02 12:50:13 +00:00
|
|
|
wi->ifa = sctp_ifap;
|
|
|
|
wi->action = SCTP_DEL_IP_ADDRESS;
|
2010-05-16 17:03:56 +00:00
|
|
|
SCTP_WQ_ADDR_LOCK();
|
2007-05-02 12:50:13 +00:00
|
|
|
/*
|
|
|
|
* Should this really be a tailq? As it is we will process
|
|
|
|
* the newest first :-0
|
|
|
|
*/
|
2008-06-14 07:58:05 +00:00
|
|
|
LIST_INSERT_HEAD(&SCTP_BASE_INFO(addr_wq), wi, sctp_nxt_addr);
|
2010-05-16 17:03:56 +00:00
|
|
|
SCTP_WQ_ADDR_UNLOCK();
|
2007-05-29 09:29:03 +00:00
|
|
|
|
2007-05-02 12:50:13 +00:00
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_ADDR_WQ,
|
|
|
|
(struct sctp_inpcb *)NULL,
|
|
|
|
(struct sctp_tcb *)NULL,
|
|
|
|
(struct sctp_nets *)NULL);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
|
2013-02-10 19:57:19 +00:00
|
|
|
static int
|
|
|
|
sctp_does_stcb_own_this_addr(struct sctp_tcb *stcb, struct sockaddr *to)
|
|
|
|
{
|
2013-11-02 20:12:19 +00:00
|
|
|
int loopback_scope;
|
|
|
|
|
|
|
|
#if defined(INET)
|
|
|
|
int ipv4_local_scope, ipv4_addr_legal;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#if defined(INET6)
|
|
|
|
int local_scope, site_scope, ipv6_addr_legal;
|
|
|
|
|
|
|
|
#endif
|
2013-02-10 19:57:19 +00:00
|
|
|
struct sctp_vrf *vrf;
|
|
|
|
struct sctp_ifn *sctp_ifn;
|
|
|
|
struct sctp_ifa *sctp_ifa;
|
|
|
|
|
|
|
|
loopback_scope = stcb->asoc.scope.loopback_scope;
|
2013-11-02 20:12:19 +00:00
|
|
|
#if defined(INET)
|
2013-02-10 19:57:19 +00:00
|
|
|
ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
|
2013-11-02 20:12:19 +00:00
|
|
|
ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
|
|
|
|
#endif
|
|
|
|
#if defined(INET6)
|
2013-02-10 19:57:19 +00:00
|
|
|
local_scope = stcb->asoc.scope.local_scope;
|
|
|
|
site_scope = stcb->asoc.scope.site_scope;
|
|
|
|
ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
|
2013-11-02 20:12:19 +00:00
|
|
|
#endif
|
2013-02-10 19:57:19 +00:00
|
|
|
|
|
|
|
SCTP_IPI_ADDR_RLOCK();
|
|
|
|
vrf = sctp_find_vrf(stcb->asoc.vrf_id);
|
|
|
|
if (vrf == NULL) {
|
|
|
|
/* no vrf, no addresses */
|
|
|
|
SCTP_IPI_ADDR_RUNLOCK();
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
|
|
|
|
LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
|
|
|
|
if ((loopback_scope == 0) &&
|
|
|
|
SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
|
|
|
|
if (sctp_is_addr_restricted(stcb, sctp_ifa) &&
|
|
|
|
(!sctp_is_addr_pending(stcb, sctp_ifa))) {
|
|
|
|
/*
|
|
|
|
* We allow pending addresses, where
|
|
|
|
* we have sent an asconf-add to be
|
|
|
|
* considered valid.
|
|
|
|
*/
|
|
|
|
continue;
|
|
|
|
}
|
2013-11-16 15:34:14 +00:00
|
|
|
if (sctp_ifa->address.sa.sa_family != to->sa_family) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-02-10 19:57:19 +00:00
|
|
|
switch (sctp_ifa->address.sa.sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
if (ipv4_addr_legal) {
|
|
|
|
struct sockaddr_in *sin,
|
|
|
|
*rsin;
|
|
|
|
|
|
|
|
sin = &sctp_ifa->address.sin;
|
|
|
|
rsin = (struct sockaddr_in *)to;
|
|
|
|
if ((ipv4_local_scope == 0) &&
|
|
|
|
IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) {
|
|
|
|
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-10 19:57:19 +00:00
|
|
|
if (sin->sin_addr.s_addr == rsin->sin_addr.s_addr) {
|
|
|
|
SCTP_IPI_ADDR_RUNLOCK();
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
if (ipv6_addr_legal) {
|
|
|
|
struct sockaddr_in6 *sin6,
|
|
|
|
*rsin6;
|
|
|
|
|
|
|
|
sin6 = &sctp_ifa->address.sin6;
|
|
|
|
rsin6 = (struct sockaddr_in6 *)to;
|
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-10 19:57:19 +00:00
|
|
|
if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
|
|
|
|
if (local_scope == 0)
|
|
|
|
continue;
|
|
|
|
if (sin6->sin6_scope_id == 0) {
|
|
|
|
if (sa6_recoverscope(sin6) != 0)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((site_scope == 0) &&
|
|
|
|
(IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (SCTP6_ARE_ADDR_EQUAL(sin6, rsin6)) {
|
|
|
|
SCTP_IPI_ADDR_RUNLOCK();
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
/* TSNH */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
struct sctp_laddr *laddr;
|
|
|
|
|
|
|
|
LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list, sctp_nxt_addr) {
|
|
|
|
if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED) {
|
|
|
|
SCTPDBG(SCTP_DEBUG_PCB1, "ifa being deleted\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (sctp_is_addr_restricted(stcb, laddr->ifa) &&
|
|
|
|
(!sctp_is_addr_pending(stcb, laddr->ifa))) {
|
|
|
|
/*
|
|
|
|
* We allow pending addresses, where we have
|
|
|
|
* sent an asconf-add to be considered
|
|
|
|
* valid.
|
|
|
|
*/
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (laddr->ifa->address.sa.sa_family != to->sa_family) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch (to->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
{
|
|
|
|
struct sockaddr_in *sin, *rsin;
|
|
|
|
|
2014-09-07 09:06:26 +00:00
|
|
|
sin = &laddr->ifa->address.sin;
|
2013-02-10 19:57:19 +00:00
|
|
|
rsin = (struct sockaddr_in *)to;
|
|
|
|
if (sin->sin_addr.s_addr == rsin->sin_addr.s_addr) {
|
|
|
|
SCTP_IPI_ADDR_RUNLOCK();
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
{
|
|
|
|
struct sockaddr_in6 *sin6, *rsin6;
|
|
|
|
|
2014-09-07 09:06:26 +00:00
|
|
|
sin6 = &laddr->ifa->address.sin6;
|
2013-02-10 19:57:19 +00:00
|
|
|
rsin6 = (struct sockaddr_in6 *)to;
|
|
|
|
if (SCTP6_ARE_ADDR_EQUAL(sin6, rsin6)) {
|
|
|
|
SCTP_IPI_ADDR_RUNLOCK();
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
/* TSNH */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SCTP_IPI_ADDR_RUNLOCK();
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
static struct sctp_tcb *
|
|
|
|
sctp_tcb_special_locate(struct sctp_inpcb **inp_p, struct sockaddr *from,
|
2007-04-03 11:15:32 +00:00
|
|
|
struct sockaddr *to, struct sctp_nets **netp, uint32_t vrf_id)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2007-09-21 04:19:33 +00:00
|
|
|
/**** ASSUMES THE CALLER holds the INP_INFO_RLOCK */
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* If we support the TCP model, then we must now dig through to see
|
|
|
|
* if we can find our endpoint in the list of tcp ep's.
|
|
|
|
*/
|
|
|
|
uint16_t lport, rport;
|
|
|
|
struct sctppcbhead *ephead;
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
struct sctp_laddr *laddr;
|
|
|
|
struct sctp_tcb *stcb;
|
|
|
|
struct sctp_nets *net;
|
|
|
|
|
|
|
|
if ((to == NULL) || (from == NULL)) {
|
|
|
|
return (NULL);
|
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
switch (to->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
if (from->sa_family == AF_INET) {
|
|
|
|
lport = ((struct sockaddr_in *)to)->sin_port;
|
|
|
|
rport = ((struct sockaddr_in *)from)->sin_port;
|
|
|
|
} else {
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
if (from->sa_family == AF_INET6) {
|
|
|
|
lport = ((struct sockaddr_in6 *)to)->sin6_port;
|
|
|
|
rport = ((struct sockaddr_in6 *)from)->sin6_port;
|
|
|
|
} else {
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
return (NULL);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2010-11-09 16:18:32 +00:00
|
|
|
ephead = &SCTP_BASE_INFO(sctp_tcpephash)[SCTP_PCBHASH_ALLADDR((lport | rport), SCTP_BASE_INFO(hashtcpmark))];
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* Ok now for each of the guys in this bucket we must look and see:
|
|
|
|
* - Does the remote port match. - Does there single association's
|
|
|
|
* addresses match this address (to). If so we update p_ep to point
|
|
|
|
* to this ep and return the tcb from it.
|
|
|
|
*/
|
|
|
|
LIST_FOREACH(inp, ephead, sctp_hash) {
|
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) {
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
continue;
|
|
|
|
}
|
2007-05-02 12:50:13 +00:00
|
|
|
if (lport != inp->sctp_lport) {
|
2007-05-08 00:21:05 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2007-05-02 12:50:13 +00:00
|
|
|
continue;
|
|
|
|
}
|
2014-06-20 13:26:49 +00:00
|
|
|
switch (to->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
{
|
|
|
|
struct sockaddr_in *sin;
|
|
|
|
|
|
|
|
sin = (struct sockaddr_in *)to;
|
|
|
|
if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
|
|
|
|
&sin->sin_addr) != 0) {
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
{
|
|
|
|
struct sockaddr_in6 *sin6;
|
|
|
|
|
|
|
|
sin6 = (struct sockaddr_in6 *)to;
|
|
|
|
if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
|
|
|
|
&sin6->sin6_addr) != 0) {
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
continue;
|
|
|
|
}
|
2007-04-14 09:44:09 +00:00
|
|
|
if (inp->def_vrf_id != vrf_id) {
|
2007-04-03 11:15:32 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
continue;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
/* check to see if the ep has one of the addresses */
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
|
|
|
|
/* We are NOT bound all, so look further */
|
|
|
|
int match = 0;
|
|
|
|
|
|
|
|
LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
|
|
|
|
|
|
|
|
if (laddr->ifa == NULL) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB1, "%s: NULL ifa\n", __FUNCTION__);
|
2006-11-03 15:23:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB1, "ifa being deleted\n");
|
2006-11-03 15:23:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
if (laddr->ifa->address.sa.sa_family ==
|
2006-11-03 15:23:16 +00:00
|
|
|
to->sa_family) {
|
|
|
|
/* see if it matches */
|
2011-04-30 11:18:16 +00:00
|
|
|
#ifdef INET
|
2006-11-03 15:23:16 +00:00
|
|
|
if (from->sa_family == AF_INET) {
|
2011-04-30 11:18:16 +00:00
|
|
|
struct sockaddr_in *intf_addr,
|
|
|
|
*sin;
|
|
|
|
|
|
|
|
intf_addr = &laddr->ifa->address.sin;
|
|
|
|
sin = (struct sockaddr_in *)to;
|
2006-11-03 15:23:16 +00:00
|
|
|
if (sin->sin_addr.s_addr ==
|
|
|
|
intf_addr->sin_addr.s_addr) {
|
|
|
|
match = 1;
|
|
|
|
break;
|
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
#endif
|
2008-04-16 17:24:18 +00:00
|
|
|
#ifdef INET6
|
|
|
|
if (from->sa_family == AF_INET6) {
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sockaddr_in6 *intf_addr6;
|
|
|
|
struct sockaddr_in6 *sin6;
|
|
|
|
|
|
|
|
sin6 = (struct sockaddr_in6 *)
|
|
|
|
to;
|
2007-03-15 11:27:14 +00:00
|
|
|
intf_addr6 = &laddr->ifa->address.sin6;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2008-05-20 13:47:46 +00:00
|
|
|
if (SCTP6_ARE_ADDR_EQUAL(sin6,
|
|
|
|
intf_addr6)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
match = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (match == 0) {
|
|
|
|
/* This endpoint does not have this address */
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Ok if we hit here the ep has the address, does it hold
|
|
|
|
* the tcb?
|
|
|
|
*/
|
2013-02-10 19:57:19 +00:00
|
|
|
/* XXX: Why don't we TAILQ_FOREACH through sctp_asoc_list? */
|
2006-11-03 15:23:16 +00:00
|
|
|
stcb = LIST_FIRST(&inp->sctp_asoc_list);
|
|
|
|
if (stcb == NULL) {
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
SCTP_TCB_LOCK(stcb);
|
2013-02-10 19:57:19 +00:00
|
|
|
if (!sctp_does_stcb_own_this_addr(stcb, to)) {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
continue;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb->rport != rport) {
|
|
|
|
/* remote port does not match. */
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
continue;
|
|
|
|
}
|
2007-10-30 14:09:24 +00:00
|
|
|
if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
continue;
|
|
|
|
}
|
2013-02-10 19:57:19 +00:00
|
|
|
if (!sctp_does_stcb_own_this_addr(stcb, to)) {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
continue;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Does this TCB have a matching address? */
|
|
|
|
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
|
|
|
|
|
|
|
|
if (net->ro._l_addr.sa.sa_family != from->sa_family) {
|
|
|
|
/* not the same family, can't be a match */
|
|
|
|
continue;
|
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
switch (from->sa_family) {
|
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, *rsin;
|
|
|
|
|
|
|
|
sin = (struct sockaddr_in *)&net->ro._l_addr;
|
|
|
|
rsin = (struct sockaddr_in *)from;
|
|
|
|
if (sin->sin_addr.s_addr ==
|
|
|
|
rsin->sin_addr.s_addr) {
|
|
|
|
/* found it */
|
|
|
|
if (netp != NULL) {
|
|
|
|
*netp = net;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Update the endpoint
|
|
|
|
* pointer
|
|
|
|
*/
|
|
|
|
*inp_p = inp;
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
return (stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
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
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
{
|
|
|
|
struct sockaddr_in6 *sin6, *rsin6;
|
|
|
|
|
|
|
|
sin6 = (struct sockaddr_in6 *)&net->ro._l_addr;
|
|
|
|
rsin6 = (struct sockaddr_in6 *)from;
|
2008-05-20 13:47:46 +00:00
|
|
|
if (SCTP6_ARE_ADDR_EQUAL(sin6,
|
|
|
|
rsin6)) {
|
2008-04-16 17:24:18 +00:00
|
|
|
/* found it */
|
|
|
|
if (netp != NULL) {
|
|
|
|
*netp = net;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Update the endpoint
|
|
|
|
* pointer
|
|
|
|
*/
|
|
|
|
*inp_p = inp;
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
return (stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
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
|
|
|
|
default:
|
|
|
|
/* TSNH */
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2013-02-09 17:26:14 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* rules for use
|
|
|
|
*
|
|
|
|
* 1) If I return a NULL you must decrement any INP ref cnt. 2) If I find an
|
|
|
|
* stcb, both will be locked (locked_tcb and stcb) but decrement will be done
|
|
|
|
* (if locked == NULL). 3) Decrement happens on return ONLY if locked ==
|
|
|
|
* NULL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct sctp_tcb *
|
|
|
|
sctp_findassociation_ep_addr(struct sctp_inpcb **inp_p, struct sockaddr *remote,
|
|
|
|
struct sctp_nets **netp, struct sockaddr *local, struct sctp_tcb *locked_tcb)
|
|
|
|
{
|
|
|
|
struct sctpasochead *head;
|
|
|
|
struct sctp_inpcb *inp;
|
2007-04-03 11:15:32 +00:00
|
|
|
struct sctp_tcb *stcb = NULL;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_nets *net;
|
|
|
|
uint16_t rport;
|
|
|
|
|
|
|
|
inp = *inp_p;
|
2012-07-14 20:08:03 +00:00
|
|
|
switch (remote->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
2006-11-03 15:23:16 +00:00
|
|
|
rport = (((struct sockaddr_in *)remote)->sin_port);
|
2012-07-14 20:08:03 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
2006-11-03 15:23:16 +00:00
|
|
|
rport = (((struct sockaddr_in6 *)remote)->sin6_port);
|
2012-07-14 20:08:03 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2006-11-03 15:23:16 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (locked_tcb) {
|
|
|
|
/*
|
|
|
|
* UN-lock so we can do proper locking here this occurs when
|
|
|
|
* called from load_addresses_from_init.
|
|
|
|
*/
|
2007-08-24 00:53:53 +00:00
|
|
|
atomic_add_int(&locked_tcb->asoc.refcnt, 1);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_TCB_UNLOCK(locked_tcb);
|
|
|
|
}
|
|
|
|
SCTP_INP_INFO_RLOCK();
|
2012-11-26 16:43:32 +00:00
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
|
|
|
|
(inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
|
2007-04-03 11:15:32 +00:00
|
|
|
/*-
|
2006-11-03 15:23:16 +00:00
|
|
|
* Now either this guy is our listener or it's the
|
|
|
|
* connector. If it is the one that issued the connect, then
|
|
|
|
* it's only chance is to be the first TCB in the list. If
|
|
|
|
* it is the acceptor, then do the special_lookup to hash
|
|
|
|
* and find the real inp.
|
|
|
|
*/
|
|
|
|
if ((inp->sctp_socket) && (inp->sctp_socket->so_qlimit)) {
|
|
|
|
/* to is peer addr, from is my addr */
|
|
|
|
stcb = sctp_tcb_special_locate(inp_p, remote, local,
|
2007-04-03 11:15:32 +00:00
|
|
|
netp, inp->def_vrf_id);
|
2006-11-03 15:23:16 +00:00
|
|
|
if ((stcb != NULL) && (locked_tcb == NULL)) {
|
|
|
|
/* we have a locked tcb, lower refcount */
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
|
|
|
}
|
|
|
|
if ((locked_tcb != NULL) && (locked_tcb != stcb)) {
|
|
|
|
SCTP_INP_RLOCK(locked_tcb->sctp_ep);
|
|
|
|
SCTP_TCB_LOCK(locked_tcb);
|
2007-08-24 00:53:53 +00:00
|
|
|
atomic_subtract_int(&locked_tcb->asoc.refcnt, 1);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_RUNLOCK(locked_tcb->sctp_ep);
|
|
|
|
}
|
|
|
|
SCTP_INP_INFO_RUNLOCK();
|
|
|
|
return (stcb);
|
|
|
|
} else {
|
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) {
|
|
|
|
goto null_return;
|
|
|
|
}
|
|
|
|
stcb = LIST_FIRST(&inp->sctp_asoc_list);
|
|
|
|
if (stcb == NULL) {
|
|
|
|
goto null_return;
|
|
|
|
}
|
|
|
|
SCTP_TCB_LOCK(stcb);
|
2007-10-30 14:09:24 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb->rport != rport) {
|
|
|
|
/* remote port does not match. */
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
goto null_return;
|
|
|
|
}
|
2007-10-30 14:09:24 +00:00
|
|
|
if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
goto null_return;
|
|
|
|
}
|
2010-06-24 07:43:25 +00:00
|
|
|
if (local && !sctp_does_stcb_own_this_addr(stcb, local)) {
|
2010-06-23 15:19:07 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
goto null_return;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
/* now look at the list of remote addresses */
|
|
|
|
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
|
2006-12-14 17:02:55 +00:00
|
|
|
#ifdef INVARIANTS
|
2006-11-03 15:23:16 +00:00
|
|
|
if (net == (TAILQ_NEXT(net, sctp_next))) {
|
|
|
|
panic("Corrupt net list");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (net->ro._l_addr.sa.sa_family !=
|
|
|
|
remote->sa_family) {
|
|
|
|
/* not the same family */
|
|
|
|
continue;
|
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
switch (remote->sa_family) {
|
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,
|
|
|
|
*rsin;
|
|
|
|
|
|
|
|
sin = (struct sockaddr_in *)
|
|
|
|
&net->ro._l_addr;
|
|
|
|
rsin = (struct sockaddr_in *)remote;
|
|
|
|
if (sin->sin_addr.s_addr ==
|
|
|
|
rsin->sin_addr.s_addr) {
|
|
|
|
/* found it */
|
|
|
|
if (netp != NULL) {
|
|
|
|
*netp = net;
|
|
|
|
}
|
|
|
|
if (locked_tcb == NULL) {
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
|
|
|
} else if (locked_tcb != stcb) {
|
|
|
|
SCTP_TCB_LOCK(locked_tcb);
|
|
|
|
}
|
|
|
|
if (locked_tcb) {
|
|
|
|
atomic_subtract_int(&locked_tcb->asoc.refcnt, 1);
|
|
|
|
}
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
SCTP_INP_INFO_RUNLOCK();
|
|
|
|
return (stcb);
|
2007-08-24 00:53:53 +00:00
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
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
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
{
|
|
|
|
struct sockaddr_in6 *sin6,
|
|
|
|
*rsin6;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2008-04-16 17:24:18 +00:00
|
|
|
sin6 = (struct sockaddr_in6 *)&net->ro._l_addr;
|
|
|
|
rsin6 = (struct sockaddr_in6 *)remote;
|
2008-05-20 13:47:46 +00:00
|
|
|
if (SCTP6_ARE_ADDR_EQUAL(sin6,
|
|
|
|
rsin6)) {
|
2008-04-16 17:24:18 +00:00
|
|
|
/* found it */
|
|
|
|
if (netp != NULL) {
|
|
|
|
*netp = net;
|
|
|
|
}
|
|
|
|
if (locked_tcb == NULL) {
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
|
|
|
} else if (locked_tcb != stcb) {
|
|
|
|
SCTP_TCB_LOCK(locked_tcb);
|
|
|
|
}
|
|
|
|
if (locked_tcb) {
|
|
|
|
atomic_subtract_int(&locked_tcb->asoc.refcnt, 1);
|
|
|
|
}
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
SCTP_INP_INFO_RUNLOCK();
|
|
|
|
return (stcb);
|
2007-08-24 00:53:53 +00:00
|
|
|
}
|
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
|
|
|
|
default:
|
|
|
|
/* TSNH */
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) {
|
|
|
|
goto null_return;
|
|
|
|
}
|
|
|
|
head = &inp->sctp_tcbhash[SCTP_PCBHASH_ALLADDR(rport,
|
|
|
|
inp->sctp_hashmark)];
|
|
|
|
LIST_FOREACH(stcb, head, sctp_tcbhash) {
|
|
|
|
if (stcb->rport != rport) {
|
|
|
|
/* remote port does not match */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
SCTP_TCB_LOCK(stcb);
|
2007-10-30 14:09:24 +00:00
|
|
|
if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
continue;
|
|
|
|
}
|
2010-06-24 07:43:25 +00:00
|
|
|
if (local && !sctp_does_stcb_own_this_addr(stcb, local)) {
|
2010-06-23 15:19:07 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
continue;
|
|
|
|
}
|
2007-10-30 14:09:24 +00:00
|
|
|
/* now look at the list of remote addresses */
|
2006-11-03 15:23:16 +00:00
|
|
|
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
|
2006-12-14 17:02:55 +00:00
|
|
|
#ifdef INVARIANTS
|
2006-11-03 15:23:16 +00:00
|
|
|
if (net == (TAILQ_NEXT(net, sctp_next))) {
|
|
|
|
panic("Corrupt net list");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (net->ro._l_addr.sa.sa_family !=
|
|
|
|
remote->sa_family) {
|
|
|
|
/* not the same family */
|
|
|
|
continue;
|
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
switch (remote->sa_family) {
|
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,
|
|
|
|
*rsin;
|
|
|
|
|
|
|
|
sin = (struct sockaddr_in *)
|
|
|
|
&net->ro._l_addr;
|
|
|
|
rsin = (struct sockaddr_in *)remote;
|
|
|
|
if (sin->sin_addr.s_addr ==
|
|
|
|
rsin->sin_addr.s_addr) {
|
|
|
|
/* found it */
|
|
|
|
if (netp != NULL) {
|
|
|
|
*netp = net;
|
|
|
|
}
|
|
|
|
if (locked_tcb == NULL) {
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
|
|
|
} else if (locked_tcb != stcb) {
|
|
|
|
SCTP_TCB_LOCK(locked_tcb);
|
|
|
|
}
|
|
|
|
if (locked_tcb) {
|
|
|
|
atomic_subtract_int(&locked_tcb->asoc.refcnt, 1);
|
|
|
|
}
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
SCTP_INP_INFO_RUNLOCK();
|
|
|
|
return (stcb);
|
2007-08-24 00:53:53 +00:00
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
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
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
{
|
|
|
|
struct sockaddr_in6 *sin6,
|
|
|
|
*rsin6;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2008-04-16 17:24:18 +00:00
|
|
|
sin6 = (struct sockaddr_in6 *)
|
|
|
|
&net->ro._l_addr;
|
|
|
|
rsin6 = (struct sockaddr_in6 *)remote;
|
2008-05-20 13:47:46 +00:00
|
|
|
if (SCTP6_ARE_ADDR_EQUAL(sin6,
|
|
|
|
rsin6)) {
|
2008-04-16 17:24:18 +00:00
|
|
|
/* found it */
|
|
|
|
if (netp != NULL) {
|
|
|
|
*netp = net;
|
|
|
|
}
|
|
|
|
if (locked_tcb == NULL) {
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
|
|
|
} else if (locked_tcb != stcb) {
|
|
|
|
SCTP_TCB_LOCK(locked_tcb);
|
|
|
|
}
|
|
|
|
if (locked_tcb) {
|
|
|
|
atomic_subtract_int(&locked_tcb->asoc.refcnt, 1);
|
|
|
|
}
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
SCTP_INP_INFO_RUNLOCK();
|
|
|
|
return (stcb);
|
2007-08-24 00:53:53 +00:00
|
|
|
}
|
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
|
|
|
|
default:
|
|
|
|
/* TSNH */
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
null_return:
|
|
|
|
/* clean up for returning null */
|
|
|
|
if (locked_tcb) {
|
|
|
|
SCTP_TCB_LOCK(locked_tcb);
|
2007-08-24 00:53:53 +00:00
|
|
|
atomic_subtract_int(&locked_tcb->asoc.refcnt, 1);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
SCTP_INP_INFO_RUNLOCK();
|
|
|
|
/* not found */
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2013-02-09 17:26:14 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* Find an association for a specific endpoint using the association id given
|
|
|
|
* out in the COMM_UP notification
|
|
|
|
*/
|
|
|
|
struct sctp_tcb *
|
2008-12-06 13:19:54 +00:00
|
|
|
sctp_findasoc_ep_asocid_locked(struct sctp_inpcb *inp, sctp_assoc_t asoc_id, int want_lock)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Use my the assoc_id to find a endpoint
|
|
|
|
*/
|
|
|
|
struct sctpasochead *head;
|
|
|
|
struct sctp_tcb *stcb;
|
|
|
|
uint32_t id;
|
|
|
|
|
2008-12-06 13:19:54 +00:00
|
|
|
if (inp == NULL) {
|
|
|
|
SCTP_PRINTF("TSNH ep_associd\n");
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) {
|
|
|
|
SCTP_PRINTF("TSNH ep_associd0\n");
|
2006-11-03 15:23:16 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
id = (uint32_t) asoc_id;
|
2008-12-06 13:19:54 +00:00
|
|
|
head = &inp->sctp_asocidhash[SCTP_PCBHASH_ASOC(id, inp->hashasocidmark)];
|
2006-11-03 15:23:16 +00:00
|
|
|
if (head == NULL) {
|
|
|
|
/* invalid id TSNH */
|
2008-12-06 13:19:54 +00:00
|
|
|
SCTP_PRINTF("TSNH ep_associd1\n");
|
2006-11-03 15:23:16 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
2008-12-06 13:19:54 +00:00
|
|
|
LIST_FOREACH(stcb, head, sctp_tcbasocidhash) {
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb->asoc.assoc_id == id) {
|
|
|
|
if (inp != stcb->sctp_ep) {
|
|
|
|
/*
|
|
|
|
* some other guy has the same id active (id
|
|
|
|
* collision ??).
|
|
|
|
*/
|
2008-12-06 13:19:54 +00:00
|
|
|
SCTP_PRINTF("TSNH ep_associd2\n");
|
2006-11-03 15:23:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
2007-10-30 14:09:24 +00:00
|
|
|
if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
|
|
|
|
continue;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if (want_lock) {
|
|
|
|
SCTP_TCB_LOCK(stcb);
|
|
|
|
}
|
|
|
|
return (stcb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-06 13:19:54 +00:00
|
|
|
struct sctp_tcb *
|
|
|
|
sctp_findassociation_ep_asocid(struct sctp_inpcb *inp, sctp_assoc_t asoc_id, int want_lock)
|
|
|
|
{
|
|
|
|
struct sctp_tcb *stcb;
|
|
|
|
|
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
stcb = sctp_findasoc_ep_asocid_locked(inp, asoc_id, want_lock);
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
return (stcb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-09 17:26:14 +00:00
|
|
|
/*
|
|
|
|
* Endpoint probe expects that the INP_INFO is locked.
|
|
|
|
*/
|
2006-11-03 15:23:16 +00:00
|
|
|
static struct sctp_inpcb *
|
|
|
|
sctp_endpoint_probe(struct sockaddr *nam, struct sctppcbhead *head,
|
2007-03-15 11:27:14 +00:00
|
|
|
uint16_t lport, uint32_t vrf_id)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
struct sctp_inpcb *inp;
|
2011-04-30 11:18:16 +00:00
|
|
|
struct sctp_laddr *laddr;
|
2008-04-16 17:24:18 +00:00
|
|
|
|
2011-04-30 11:18:16 +00:00
|
|
|
#ifdef INET
|
|
|
|
struct sockaddr_in *sin;
|
2008-04-16 17:24:18 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
2011-04-30 11:18:16 +00:00
|
|
|
struct sockaddr_in6 *sin6;
|
2008-04-16 17:24:18 +00:00
|
|
|
struct sockaddr_in6 *intf_addr6;
|
|
|
|
|
|
|
|
#endif
|
2007-03-15 11:27:14 +00:00
|
|
|
int fnd;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2011-04-30 11:18:16 +00:00
|
|
|
#ifdef INET
|
2008-04-16 17:24:18 +00:00
|
|
|
sin = NULL;
|
2011-04-30 11:18:16 +00:00
|
|
|
#endif
|
2008-04-16 17:24:18 +00:00
|
|
|
#ifdef INET6
|
|
|
|
sin6 = NULL;
|
|
|
|
#endif
|
|
|
|
switch (nam->sa_family) {
|
2011-04-30 11:18:16 +00:00
|
|
|
#ifdef INET
|
2008-04-16 17:24:18 +00:00
|
|
|
case AF_INET:
|
2006-11-03 15:23:16 +00:00
|
|
|
sin = (struct sockaddr_in *)nam;
|
2008-04-16 17:24:18 +00:00
|
|
|
break;
|
2011-04-30 11:18:16 +00:00
|
|
|
#endif
|
2008-04-16 17:24:18 +00:00
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
2006-11-03 15:23:16 +00:00
|
|
|
sin6 = (struct sockaddr_in6 *)nam;
|
2008-04-16 17:24:18 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2006-11-03 15:23:16 +00:00
|
|
|
/* unsupported family */
|
|
|
|
return (NULL);
|
|
|
|
}
|
2008-07-31 11:08:30 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
if (head == NULL)
|
|
|
|
return (NULL);
|
2008-12-06 13:19:54 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
LIST_FOREACH(inp, head, sctp_hash) {
|
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) {
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) &&
|
|
|
|
(inp->sctp_lport == lport)) {
|
|
|
|
/* got it */
|
2014-06-20 13:26:49 +00:00
|
|
|
switch (nam->sa_family) {
|
2011-04-30 11:18:16 +00:00
|
|
|
#ifdef INET
|
2014-06-20 13:26:49 +00:00
|
|
|
case AF_INET:
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
|
|
|
|
SCTP_IPV6_V6ONLY(inp)) {
|
|
|
|
/*
|
|
|
|
* IPv4 on a IPv6 socket with ONLY
|
|
|
|
* IPv6 set
|
|
|
|
*/
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
|
|
|
|
&sin->sin_addr) != 0) {
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
2011-04-30 11:18:16 +00:00
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
2014-06-20 13:26:49 +00:00
|
|
|
case AF_INET6:
|
|
|
|
/*
|
|
|
|
* A V6 address and the endpoint is NOT
|
|
|
|
* bound V6
|
|
|
|
*/
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
|
|
|
|
&sin6->sin6_addr) != 0) {
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
2011-04-30 11:18:16 +00:00
|
|
|
#endif
|
2014-06-20 13:26:49 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
/* does a VRF id match? */
|
|
|
|
fnd = 0;
|
|
|
|
if (inp->def_vrf_id == vrf_id)
|
|
|
|
fnd = 1;
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2007-03-15 11:27:14 +00:00
|
|
|
if (!fnd)
|
|
|
|
continue;
|
2006-11-03 15:23:16 +00:00
|
|
|
return (inp);
|
|
|
|
}
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
switch (nam->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
if (sin->sin_addr.s_addr == INADDR_ANY) {
|
|
|
|
/* Can't hunt for one that has no address specified */
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
2008-04-16 17:24:18 +00:00
|
|
|
#ifdef INET6
|
2011-04-30 11:18:16 +00:00
|
|
|
case AF_INET6:
|
|
|
|
if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
|
|
|
|
/* Can't hunt for one that has no address specified */
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
break;
|
2008-04-16 17:24:18 +00:00
|
|
|
#endif
|
2011-04-30 11:18:16 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* ok, not bound to all so see if we can find a EP bound to this
|
|
|
|
* address.
|
|
|
|
*/
|
|
|
|
LIST_FOREACH(inp, head, sctp_hash) {
|
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) {
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL)) {
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Ok this could be a likely candidate, look at all of its
|
|
|
|
* addresses
|
|
|
|
*/
|
|
|
|
if (inp->sctp_lport != lport) {
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
continue;
|
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
/* does a VRF id match? */
|
|
|
|
fnd = 0;
|
|
|
|
if (inp->def_vrf_id == vrf_id)
|
|
|
|
fnd = 1;
|
|
|
|
|
|
|
|
if (!fnd) {
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
continue;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
|
|
|
|
if (laddr->ifa == NULL) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB1, "%s: NULL ifa\n",
|
|
|
|
__FUNCTION__);
|
2006-11-03 15:23:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB1, "Ok laddr->ifa:%p is possible, ",
|
2012-09-05 18:52:01 +00:00
|
|
|
(void *)laddr->ifa);
|
2007-03-15 11:27:14 +00:00
|
|
|
if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB1, "Huh IFA being deleted\n");
|
2006-11-03 15:23:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
if (laddr->ifa->address.sa.sa_family == nam->sa_family) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* possible, see if it matches */
|
2008-04-16 17:24:18 +00:00
|
|
|
switch (nam->sa_family) {
|
2011-04-30 11:18:16 +00:00
|
|
|
#ifdef INET
|
2008-04-16 17:24:18 +00:00
|
|
|
case AF_INET:
|
2006-11-03 15:23:16 +00:00
|
|
|
if (sin->sin_addr.s_addr ==
|
2011-04-30 11:18:16 +00:00
|
|
|
laddr->ifa->address.sin.sin_addr.s_addr) {
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
return (inp);
|
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
break;
|
2011-04-30 11:18:16 +00:00
|
|
|
#endif
|
2008-04-16 17:24:18 +00:00
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
2007-03-15 11:27:14 +00:00
|
|
|
intf_addr6 = &laddr->ifa->address.sin6;
|
2008-05-20 13:47:46 +00:00
|
|
|
if (SCTP6_ARE_ADDR_EQUAL(sin6,
|
|
|
|
intf_addr6)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
return (inp);
|
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2008-07-31 11:08:30 +00:00
|
|
|
|
|
|
|
static struct sctp_inpcb *
|
|
|
|
sctp_isport_inuse(struct sctp_inpcb *inp, uint16_t lport, uint32_t vrf_id)
|
|
|
|
{
|
|
|
|
struct sctppcbhead *head;
|
|
|
|
struct sctp_inpcb *t_inp;
|
|
|
|
int fnd;
|
|
|
|
|
|
|
|
head = &SCTP_BASE_INFO(sctp_ephash)[SCTP_PCBHASH_ALLADDR(lport,
|
|
|
|
SCTP_BASE_INFO(hashmark))];
|
|
|
|
LIST_FOREACH(t_inp, head, sctp_hash) {
|
|
|
|
if (t_inp->sctp_lport != lport) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* is it in the VRF in question */
|
|
|
|
fnd = 0;
|
|
|
|
if (t_inp->def_vrf_id == vrf_id)
|
|
|
|
fnd = 1;
|
|
|
|
if (!fnd)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* This one is in use. */
|
|
|
|
/* check the v6/v4 binding issue */
|
|
|
|
if ((t_inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
|
|
|
|
SCTP_IPV6_V6ONLY(t_inp)) {
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
|
|
|
|
/* collision in V6 space */
|
|
|
|
return (t_inp);
|
|
|
|
} else {
|
|
|
|
/* inp is BOUND_V4 no conflict */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else if (t_inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
|
|
|
|
/* t_inp is bound v4 and v6, conflict always */
|
|
|
|
return (t_inp);
|
|
|
|
} else {
|
|
|
|
/* t_inp is bound only V4 */
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
|
|
|
|
SCTP_IPV6_V6ONLY(inp)) {
|
|
|
|
/* no conflict */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* else fall through to conflict */
|
|
|
|
}
|
|
|
|
return (t_inp);
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
sctp_swap_inpcb_for_listen(struct sctp_inpcb *inp)
|
|
|
|
{
|
|
|
|
/* For 1-2-1 with port reuse */
|
|
|
|
struct sctppcbhead *head;
|
2015-03-24 21:12:45 +00:00
|
|
|
struct sctp_inpcb *tinp, *ninp;
|
2008-07-31 11:08:30 +00:00
|
|
|
|
|
|
|
if (sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE)) {
|
|
|
|
/* only works with port reuse on */
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) == 0) {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2015-03-24 21:12:45 +00:00
|
|
|
SCTP_INP_INFO_WLOCK();
|
2008-07-31 11:08:30 +00:00
|
|
|
head = &SCTP_BASE_INFO(sctp_ephash)[SCTP_PCBHASH_ALLADDR(inp->sctp_lport,
|
|
|
|
SCTP_BASE_INFO(hashmark))];
|
|
|
|
/* Kick out all non-listeners to the TCP hash */
|
2015-03-24 21:12:45 +00:00
|
|
|
LIST_FOREACH_SAFE(tinp, head, sctp_hash, ninp) {
|
2008-07-31 11:08:30 +00:00
|
|
|
if (tinp->sctp_lport != inp->sctp_lport) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (tinp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (tinp->sctp_socket->so_qlimit) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
SCTP_INP_WLOCK(tinp);
|
|
|
|
LIST_REMOVE(tinp, sctp_hash);
|
|
|
|
head = &SCTP_BASE_INFO(sctp_tcpephash)[SCTP_PCBHASH_ALLADDR(tinp->sctp_lport, SCTP_BASE_INFO(hashtcpmark))];
|
|
|
|
tinp->sctp_flags |= SCTP_PCB_FLAGS_IN_TCPPOOL;
|
|
|
|
LIST_INSERT_HEAD(head, tinp, sctp_hash);
|
|
|
|
SCTP_INP_WUNLOCK(tinp);
|
|
|
|
}
|
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
/* Pull from where he was */
|
|
|
|
LIST_REMOVE(inp, sctp_hash);
|
|
|
|
inp->sctp_flags &= ~SCTP_PCB_FLAGS_IN_TCPPOOL;
|
|
|
|
head = &SCTP_BASE_INFO(sctp_ephash)[SCTP_PCBHASH_ALLADDR(inp->sctp_lport, SCTP_BASE_INFO(hashmark))];
|
|
|
|
LIST_INSERT_HEAD(head, inp, sctp_hash);
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
SCTP_INP_RLOCK(inp);
|
2015-03-24 21:12:45 +00:00
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
2008-07-31 11:08:30 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_inpcb *
|
2007-05-09 13:30:06 +00:00
|
|
|
sctp_pcb_findep(struct sockaddr *nam, int find_tcp_pool, int have_lock,
|
|
|
|
uint32_t vrf_id)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* First we check the hash table to see if someone has this port
|
|
|
|
* bound with just the port.
|
|
|
|
*/
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
struct sctppcbhead *head;
|
|
|
|
int lport;
|
2010-11-09 16:18:32 +00:00
|
|
|
unsigned int i;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2011-04-30 11:18:16 +00:00
|
|
|
#ifdef INET
|
|
|
|
struct sockaddr_in *sin;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
struct sockaddr_in6 *sin6;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
switch (nam->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
2006-11-03 15:23:16 +00:00
|
|
|
sin = (struct sockaddr_in *)nam;
|
2011-12-27 10:16:24 +00:00
|
|
|
lport = sin->sin_port;
|
2011-04-30 11:18:16 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
2006-11-03 15:23:16 +00:00
|
|
|
sin6 = (struct sockaddr_in6 *)nam;
|
2011-12-27 10:16:24 +00:00
|
|
|
lport = sin6->sin6_port;
|
2011-04-30 11:18:16 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2006-11-03 15:23:16 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* I could cheat here and just cast to one of the types but we will
|
|
|
|
* do it right. It also provides the check against an Unsupported
|
|
|
|
* type too.
|
|
|
|
*/
|
|
|
|
/* Find the head of the ALLADDR chain */
|
|
|
|
if (have_lock == 0) {
|
|
|
|
SCTP_INP_INFO_RLOCK();
|
|
|
|
}
|
2008-06-14 07:58:05 +00:00
|
|
|
head = &SCTP_BASE_INFO(sctp_ephash)[SCTP_PCBHASH_ALLADDR(lport,
|
|
|
|
SCTP_BASE_INFO(hashmark))];
|
2007-03-15 11:27:14 +00:00
|
|
|
inp = sctp_endpoint_probe(nam, head, lport, vrf_id);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the TCP model exists it could be that the main listening
|
2010-11-09 16:18:32 +00:00
|
|
|
* endpoint is gone but there still exists a connected socket for
|
|
|
|
* this guy. If so we can return the first one that we find. This
|
|
|
|
* may NOT be the correct one so the caller should be wary on the
|
|
|
|
* returned INP. Currently the only caller that sets find_tcp_pool
|
|
|
|
* is in bindx where we are verifying that a user CAN bind the
|
|
|
|
* address. He either has bound it already, or someone else has, or
|
|
|
|
* its open to bind, so this is good enough.
|
2006-11-03 15:23:16 +00:00
|
|
|
*/
|
|
|
|
if (inp == NULL && find_tcp_pool) {
|
2010-11-09 16:18:32 +00:00
|
|
|
for (i = 0; i < SCTP_BASE_INFO(hashtcpmark) + 1; i++) {
|
|
|
|
head = &SCTP_BASE_INFO(sctp_tcpephash)[i];
|
|
|
|
inp = sctp_endpoint_probe(nam, head, lport, vrf_id);
|
|
|
|
if (inp) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
if (inp) {
|
|
|
|
SCTP_INP_INCR_REF(inp);
|
|
|
|
}
|
|
|
|
if (have_lock == 0) {
|
|
|
|
SCTP_INP_INFO_RUNLOCK();
|
|
|
|
}
|
|
|
|
return (inp);
|
|
|
|
}
|
|
|
|
|
2013-02-09 17:26:14 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* Find an association for an endpoint with the pointer to whom you want to
|
|
|
|
* send to and the endpoint pointer. The address can be IPv4 or IPv6. We may
|
|
|
|
* need to change the *to to some other struct like a mbuf...
|
|
|
|
*/
|
|
|
|
struct sctp_tcb *
|
2012-06-28 16:01:08 +00:00
|
|
|
sctp_findassociation_addr_sa(struct sockaddr *from, struct sockaddr *to,
|
2007-06-13 01:31:53 +00:00
|
|
|
struct sctp_inpcb **inp_p, struct sctp_nets **netp, int find_tcp_pool,
|
|
|
|
uint32_t vrf_id)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2007-04-14 09:44:09 +00:00
|
|
|
struct sctp_inpcb *inp = NULL;
|
2013-02-10 19:57:19 +00:00
|
|
|
struct sctp_tcb *stcb;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
SCTP_INP_INFO_RLOCK();
|
|
|
|
if (find_tcp_pool) {
|
|
|
|
if (inp_p != NULL) {
|
2013-02-10 19:57:19 +00:00
|
|
|
stcb = sctp_tcb_special_locate(inp_p, from, to, netp,
|
2007-06-13 01:31:53 +00:00
|
|
|
vrf_id);
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2013-02-10 19:57:19 +00:00
|
|
|
stcb = sctp_tcb_special_locate(&inp, from, to, netp,
|
2007-06-13 01:31:53 +00:00
|
|
|
vrf_id);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2013-02-10 19:57:19 +00:00
|
|
|
if (stcb != NULL) {
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_INFO_RUNLOCK();
|
2013-02-10 19:57:19 +00:00
|
|
|
return (stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
inp = sctp_pcb_findep(to, 0, 1, vrf_id);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (inp_p != NULL) {
|
|
|
|
*inp_p = inp;
|
|
|
|
}
|
|
|
|
SCTP_INP_INFO_RUNLOCK();
|
|
|
|
if (inp == NULL) {
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* ok, we have an endpoint, now lets find the assoc for it (if any)
|
|
|
|
* we now place the source address or from in the to of the find
|
|
|
|
* endpoint call. Since in reality this chain is used from the
|
|
|
|
* inbound packet side.
|
|
|
|
*/
|
|
|
|
if (inp_p != NULL) {
|
2013-02-10 19:57:19 +00:00
|
|
|
stcb = sctp_findassociation_ep_addr(inp_p, from, netp, to,
|
2007-06-13 01:31:53 +00:00
|
|
|
NULL);
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2013-02-10 19:57:19 +00:00
|
|
|
stcb = sctp_findassociation_ep_addr(&inp, from, netp, to,
|
2007-06-13 01:31:53 +00:00
|
|
|
NULL);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2013-02-10 19:57:19 +00:00
|
|
|
return (stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This routine will grub through the mbuf that is a INIT or INIT-ACK and
|
|
|
|
* find all addresses that the sender has specified in any address list. Each
|
|
|
|
* address will be used to lookup the TCB and see if one exits.
|
|
|
|
*/
|
|
|
|
static struct sctp_tcb *
|
2011-12-17 19:21:40 +00:00
|
|
|
sctp_findassociation_special_addr(struct mbuf *m, int offset,
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctphdr *sh, struct sctp_inpcb **inp_p, struct sctp_nets **netp,
|
2012-06-28 16:01:08 +00:00
|
|
|
struct sockaddr *dst)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
struct sctp_paramhdr *phdr, parm_buf;
|
2013-11-02 20:12:19 +00:00
|
|
|
|
|
|
|
#if defined(INET) || defined(INET6)
|
2013-02-10 19:57:19 +00:00
|
|
|
struct sctp_tcb *stcb;
|
2013-11-02 20:12:19 +00:00
|
|
|
uint16_t ptype;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
uint16_t plen;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2011-04-30 11:18:16 +00:00
|
|
|
#ifdef INET
|
|
|
|
struct sockaddr_in sin4;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
struct sockaddr_in6 sin6;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef INET
|
2006-11-03 15:23:16 +00:00
|
|
|
memset(&sin4, 0, sizeof(sin4));
|
|
|
|
sin4.sin_len = sizeof(sin4);
|
|
|
|
sin4.sin_family = AF_INET;
|
|
|
|
sin4.sin_port = sh->src_port;
|
2011-04-30 11:18:16 +00:00
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
memset(&sin6, 0, sizeof(sin6));
|
2006-11-03 15:23:16 +00:00
|
|
|
sin6.sin6_len = sizeof(sin6);
|
|
|
|
sin6.sin6_family = AF_INET6;
|
|
|
|
sin6.sin6_port = sh->src_port;
|
2011-04-30 11:18:16 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
offset += sizeof(struct sctp_init_chunk);
|
|
|
|
|
|
|
|
phdr = sctp_get_next_param(m, offset, &parm_buf, sizeof(parm_buf));
|
|
|
|
while (phdr != NULL) {
|
|
|
|
/* now we must see if we want the parameter */
|
2013-11-02 20:12:19 +00:00
|
|
|
#if defined(INET) || defined(INET6)
|
2006-11-03 15:23:16 +00:00
|
|
|
ptype = ntohs(phdr->param_type);
|
2013-11-02 20:12:19 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
plen = ntohs(phdr->param_length);
|
|
|
|
if (plen == 0) {
|
|
|
|
break;
|
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
#ifdef INET
|
2006-11-03 15:23:16 +00:00
|
|
|
if (ptype == SCTP_IPV4_ADDRESS &&
|
|
|
|
plen == sizeof(struct sctp_ipv4addr_param)) {
|
|
|
|
/* Get the rest of the address */
|
|
|
|
struct sctp_ipv4addr_param ip4_parm, *p4;
|
|
|
|
|
|
|
|
phdr = sctp_get_next_param(m, offset,
|
2007-05-02 12:50:13 +00:00
|
|
|
(struct sctp_paramhdr *)&ip4_parm, min(plen, sizeof(ip4_parm)));
|
2006-11-03 15:23:16 +00:00
|
|
|
if (phdr == NULL) {
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
p4 = (struct sctp_ipv4addr_param *)phdr;
|
|
|
|
memcpy(&sin4.sin_addr, &p4->addr, sizeof(p4->addr));
|
|
|
|
/* look it up */
|
2013-02-10 19:57:19 +00:00
|
|
|
stcb = sctp_findassociation_ep_addr(inp_p,
|
2012-06-28 16:01:08 +00:00
|
|
|
(struct sockaddr *)&sin4, netp, dst, NULL);
|
2013-02-10 19:57:19 +00:00
|
|
|
if (stcb != NULL) {
|
|
|
|
return (stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
if (ptype == SCTP_IPV6_ADDRESS &&
|
2006-11-03 15:23:16 +00:00
|
|
|
plen == sizeof(struct sctp_ipv6addr_param)) {
|
|
|
|
/* Get the rest of the address */
|
|
|
|
struct sctp_ipv6addr_param ip6_parm, *p6;
|
|
|
|
|
|
|
|
phdr = sctp_get_next_param(m, offset,
|
2007-05-02 12:50:13 +00:00
|
|
|
(struct sctp_paramhdr *)&ip6_parm, min(plen, sizeof(ip6_parm)));
|
2006-11-03 15:23:16 +00:00
|
|
|
if (phdr == NULL) {
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
p6 = (struct sctp_ipv6addr_param *)phdr;
|
|
|
|
memcpy(&sin6.sin6_addr, &p6->addr, sizeof(p6->addr));
|
|
|
|
/* look it up */
|
2013-02-10 19:57:19 +00:00
|
|
|
stcb = sctp_findassociation_ep_addr(inp_p,
|
2012-06-28 16:01:08 +00:00
|
|
|
(struct sockaddr *)&sin6, netp, dst, NULL);
|
2013-02-10 19:57:19 +00:00
|
|
|
if (stcb != NULL) {
|
|
|
|
return (stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
offset += SCTP_SIZE32(plen);
|
|
|
|
phdr = sctp_get_next_param(m, offset, &parm_buf,
|
|
|
|
sizeof(parm_buf));
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct sctp_tcb *
|
2008-12-06 13:19:54 +00:00
|
|
|
sctp_findassoc_by_vtag(struct sockaddr *from, struct sockaddr *to, uint32_t vtag,
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_inpcb **inp_p, struct sctp_nets **netp, uint16_t rport,
|
2008-12-06 13:19:54 +00:00
|
|
|
uint16_t lport, int skip_src_check, uint32_t vrf_id, uint32_t remote_tag)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Use my vtag to hash. If we find it we then verify the source addr
|
|
|
|
* is in the assoc. If all goes well we save a bit on rec of a
|
|
|
|
* packet.
|
|
|
|
*/
|
|
|
|
struct sctpasochead *head;
|
|
|
|
struct sctp_nets *net;
|
|
|
|
struct sctp_tcb *stcb;
|
|
|
|
|
|
|
|
SCTP_INP_INFO_RLOCK();
|
2008-06-14 07:58:05 +00:00
|
|
|
head = &SCTP_BASE_INFO(sctp_asochash)[SCTP_PCBHASH_ASOC(vtag,
|
|
|
|
SCTP_BASE_INFO(hashasocmark))];
|
2006-11-03 15:23:16 +00:00
|
|
|
LIST_FOREACH(stcb, head, sctp_asocs) {
|
|
|
|
SCTP_INP_RLOCK(stcb->sctp_ep);
|
|
|
|
if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) {
|
|
|
|
SCTP_INP_RUNLOCK(stcb->sctp_ep);
|
2007-05-02 12:50:13 +00:00
|
|
|
continue;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2011-12-17 19:21:40 +00:00
|
|
|
if (stcb->sctp_ep->def_vrf_id != vrf_id) {
|
|
|
|
SCTP_INP_RUNLOCK(stcb->sctp_ep);
|
|
|
|
continue;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_TCB_LOCK(stcb);
|
|
|
|
SCTP_INP_RUNLOCK(stcb->sctp_ep);
|
|
|
|
if (stcb->asoc.my_vtag == vtag) {
|
|
|
|
/* candidate */
|
|
|
|
if (stcb->rport != rport) {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (stcb->sctp_ep->sctp_lport != lport) {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
continue;
|
|
|
|
}
|
2007-10-30 14:09:24 +00:00
|
|
|
if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
continue;
|
|
|
|
}
|
2008-12-06 13:19:54 +00:00
|
|
|
/* RRS:Need toaddr check here */
|
|
|
|
if (sctp_does_stcb_own_this_addr(stcb, to) == 0) {
|
|
|
|
/* Endpoint does not own this address */
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (remote_tag) {
|
|
|
|
/*
|
2010-11-09 10:59:09 +00:00
|
|
|
* If we have both vtags that's all we match
|
2008-12-06 13:19:54 +00:00
|
|
|
* on
|
|
|
|
*/
|
|
|
|
if (stcb->asoc.peer_vtag == remote_tag) {
|
|
|
|
/*
|
|
|
|
* If both tags match we consider it
|
|
|
|
* conclusive and check NO
|
|
|
|
* source/destination addresses
|
|
|
|
*/
|
|
|
|
goto conclusive;
|
|
|
|
}
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if (skip_src_check) {
|
2008-12-06 13:19:54 +00:00
|
|
|
conclusive:
|
|
|
|
if (from) {
|
2011-12-27 10:16:24 +00:00
|
|
|
*netp = sctp_findnet(stcb, from);
|
2008-12-06 13:19:54 +00:00
|
|
|
} else {
|
|
|
|
*netp = NULL; /* unknown */
|
|
|
|
}
|
2007-05-09 13:30:06 +00:00
|
|
|
if (inp_p)
|
|
|
|
*inp_p = stcb->sctp_ep;
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_INFO_RUNLOCK();
|
|
|
|
return (stcb);
|
|
|
|
}
|
|
|
|
net = sctp_findnet(stcb, from);
|
|
|
|
if (net) {
|
|
|
|
/* yep its him. */
|
|
|
|
*netp = net;
|
|
|
|
SCTP_STAT_INCR(sctps_vtagexpress);
|
|
|
|
*inp_p = stcb->sctp_ep;
|
|
|
|
SCTP_INP_INFO_RUNLOCK();
|
|
|
|
return (stcb);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* not him, this should only happen in rare
|
|
|
|
* cases so I peg it.
|
|
|
|
*/
|
|
|
|
SCTP_STAT_INCR(sctps_vtagbogus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
}
|
|
|
|
SCTP_INP_INFO_RUNLOCK();
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2013-02-09 17:26:14 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* Find an association with the pointer to the inbound IP packet. This can be
|
|
|
|
* a IPv4 or IPv6 packet.
|
|
|
|
*/
|
|
|
|
struct sctp_tcb *
|
2011-12-17 19:21:40 +00:00
|
|
|
sctp_findassociation_addr(struct mbuf *m, int offset,
|
2012-06-28 16:01:08 +00:00
|
|
|
struct sockaddr *src, struct sockaddr *dst,
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctphdr *sh, struct sctp_chunkhdr *ch,
|
2007-04-03 11:15:32 +00:00
|
|
|
struct sctp_inpcb **inp_p, struct sctp_nets **netp, uint32_t vrf_id)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
int find_tcp_pool;
|
2013-02-10 19:57:19 +00:00
|
|
|
struct sctp_tcb *stcb;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
|
2008-12-06 13:19:54 +00:00
|
|
|
if (sh->v_tag) {
|
|
|
|
/* we only go down this path if vtag is non-zero */
|
2013-02-10 19:57:19 +00:00
|
|
|
stcb = sctp_findassoc_by_vtag(src, dst, ntohl(sh->v_tag),
|
2008-12-06 13:19:54 +00:00
|
|
|
inp_p, netp, sh->src_port, sh->dest_port, 0, vrf_id, 0);
|
2013-02-10 19:57:19 +00:00
|
|
|
if (stcb) {
|
|
|
|
return (stcb);
|
2008-12-06 13:19:54 +00:00
|
|
|
}
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
find_tcp_pool = 0;
|
|
|
|
if ((ch->chunk_type != SCTP_INITIATION) &&
|
|
|
|
(ch->chunk_type != SCTP_INITIATION_ACK) &&
|
|
|
|
(ch->chunk_type != SCTP_COOKIE_ACK) &&
|
|
|
|
(ch->chunk_type != SCTP_COOKIE_ECHO)) {
|
|
|
|
/* Other chunk types go to the tcp pool. */
|
|
|
|
find_tcp_pool = 1;
|
|
|
|
}
|
|
|
|
if (inp_p) {
|
2013-02-10 19:57:19 +00:00
|
|
|
stcb = sctp_findassociation_addr_sa(src, dst, inp_p, netp,
|
2007-03-15 11:27:14 +00:00
|
|
|
find_tcp_pool, vrf_id);
|
2006-11-03 15:23:16 +00:00
|
|
|
inp = *inp_p;
|
|
|
|
} else {
|
2013-02-10 19:57:19 +00:00
|
|
|
stcb = sctp_findassociation_addr_sa(src, dst, &inp, netp,
|
2007-03-15 11:27:14 +00:00
|
|
|
find_tcp_pool, vrf_id);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2013-02-10 19:57:19 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB1, "stcb:%p inp:%p\n", (void *)stcb, (void *)inp);
|
|
|
|
if (stcb == NULL && inp) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Found a EP but not this address */
|
|
|
|
if ((ch->chunk_type == SCTP_INITIATION) ||
|
|
|
|
(ch->chunk_type == SCTP_INITIATION_ACK)) {
|
2007-05-02 12:50:13 +00:00
|
|
|
/*-
|
2006-11-03 15:23:16 +00:00
|
|
|
* special hook, we do NOT return linp or an
|
|
|
|
* association that is linked to an existing
|
|
|
|
* association that is under the TCP pool (i.e. no
|
|
|
|
* listener exists). The endpoint finding routine
|
2010-11-09 10:59:09 +00:00
|
|
|
* will always find a listener before examining the
|
2006-11-03 15:23:16 +00:00
|
|
|
* TCP pool.
|
|
|
|
*/
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) {
|
|
|
|
if (inp_p) {
|
|
|
|
*inp_p = NULL;
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
2013-02-10 19:57:19 +00:00
|
|
|
stcb = sctp_findassociation_special_addr(m,
|
2012-06-28 16:01:08 +00:00
|
|
|
offset, sh, &inp, netp, dst);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (inp_p != NULL) {
|
|
|
|
*inp_p = inp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-02-10 19:57:19 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB1, "stcb is %p\n", (void *)stcb);
|
|
|
|
return (stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* lookup an association by an ASCONF lookup address.
|
|
|
|
* if the lookup address is 0.0.0.0 or ::0, use the vtag to do the lookup
|
|
|
|
*/
|
|
|
|
struct sctp_tcb *
|
2011-12-17 19:21:40 +00:00
|
|
|
sctp_findassociation_ep_asconf(struct mbuf *m, int offset,
|
2012-06-28 16:01:08 +00:00
|
|
|
struct sockaddr *dst, struct sctphdr *sh,
|
|
|
|
struct sctp_inpcb **inp_p, struct sctp_nets **netp, uint32_t vrf_id)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
struct sctp_tcb *stcb;
|
2014-09-07 09:06:26 +00:00
|
|
|
union sctp_sockstore remote_store;
|
2011-04-30 11:18:16 +00:00
|
|
|
struct sctp_paramhdr parm_buf, *phdr;
|
|
|
|
int ptype;
|
|
|
|
int zero_address = 0;
|
2008-04-16 17:24:18 +00:00
|
|
|
|
2011-04-30 11:18:16 +00:00
|
|
|
#ifdef INET
|
|
|
|
struct sockaddr_in *sin;
|
|
|
|
|
|
|
|
#endif
|
2008-04-16 17:24:18 +00:00
|
|
|
#ifdef INET6
|
2011-04-30 11:18:16 +00:00
|
|
|
struct sockaddr_in6 *sin6;
|
2008-04-16 17:24:18 +00:00
|
|
|
|
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
memset(&remote_store, 0, sizeof(remote_store));
|
|
|
|
phdr = sctp_get_next_param(m, offset + sizeof(struct sctp_asconf_chunk),
|
|
|
|
&parm_buf, sizeof(struct sctp_paramhdr));
|
|
|
|
if (phdr == NULL) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_INPUT3, "%s: failed to get asconf lookup addr\n",
|
|
|
|
__FUNCTION__);
|
2006-11-03 15:23:16 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ptype = (int)((uint32_t) ntohs(phdr->param_type));
|
|
|
|
/* get the correlation address */
|
2008-04-16 17:24:18 +00:00
|
|
|
switch (ptype) {
|
|
|
|
#ifdef INET6
|
|
|
|
case SCTP_IPV6_ADDRESS:
|
|
|
|
{
|
|
|
|
/* ipv6 address param */
|
|
|
|
struct sctp_ipv6addr_param *p6, p6_buf;
|
|
|
|
|
|
|
|
if (ntohs(phdr->param_length) != sizeof(struct sctp_ipv6addr_param)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
p6 = (struct sctp_ipv6addr_param *)sctp_get_next_param(m,
|
|
|
|
offset + sizeof(struct sctp_asconf_chunk),
|
|
|
|
&p6_buf.ph, sizeof(*p6));
|
|
|
|
if (p6 == NULL) {
|
|
|
|
SCTPDBG(SCTP_DEBUG_INPUT3, "%s: failed to get asconf v6 lookup addr\n",
|
|
|
|
__FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
2014-09-07 09:06:26 +00:00
|
|
|
sin6 = &remote_store.sin6;
|
2008-04-16 17:24:18 +00:00
|
|
|
sin6->sin6_family = AF_INET6;
|
|
|
|
sin6->sin6_len = sizeof(*sin6);
|
|
|
|
sin6->sin6_port = sh->src_port;
|
|
|
|
memcpy(&sin6->sin6_addr, &p6->addr, sizeof(struct in6_addr));
|
|
|
|
if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
|
|
|
|
zero_address = 1;
|
|
|
|
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 SCTP_IPV4_ADDRESS:
|
|
|
|
{
|
|
|
|
/* ipv4 address param */
|
|
|
|
struct sctp_ipv4addr_param *p4, p4_buf;
|
|
|
|
|
|
|
|
if (ntohs(phdr->param_length) != sizeof(struct sctp_ipv4addr_param)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
p4 = (struct sctp_ipv4addr_param *)sctp_get_next_param(m,
|
|
|
|
offset + sizeof(struct sctp_asconf_chunk),
|
|
|
|
&p4_buf.ph, sizeof(*p4));
|
|
|
|
if (p4 == NULL) {
|
|
|
|
SCTPDBG(SCTP_DEBUG_INPUT3, "%s: failed to get asconf v4 lookup addr\n",
|
|
|
|
__FUNCTION__);
|
|
|
|
return (NULL);
|
|
|
|
}
|
2014-09-07 09:06:26 +00:00
|
|
|
sin = &remote_store.sin;
|
2008-04-16 17:24:18 +00:00
|
|
|
sin->sin_family = AF_INET;
|
|
|
|
sin->sin_len = sizeof(*sin);
|
|
|
|
sin->sin_port = sh->src_port;
|
|
|
|
memcpy(&sin->sin_addr, &p4->addr, sizeof(struct in_addr));
|
|
|
|
if (sin->sin_addr.s_addr == INADDR_ANY)
|
|
|
|
zero_address = 1;
|
|
|
|
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
|
|
|
/* invalid address param type */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (zero_address) {
|
2012-06-28 16:01:08 +00:00
|
|
|
stcb = sctp_findassoc_by_vtag(NULL, dst, ntohl(sh->v_tag), inp_p,
|
2008-12-06 13:19:54 +00:00
|
|
|
netp, sh->src_port, sh->dest_port, 1, vrf_id, 0);
|
2012-08-05 10:47:18 +00:00
|
|
|
if (stcb != NULL) {
|
|
|
|
SCTP_INP_DECR_REF(*inp_p);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
|
|
|
stcb = sctp_findassociation_ep_addr(inp_p,
|
2014-09-07 09:06:26 +00:00
|
|
|
&remote_store.sa, netp,
|
2012-06-28 16:01:08 +00:00
|
|
|
dst, NULL);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
return (stcb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* allocate a sctp_inpcb and setup a temporary binding to a port/all
|
|
|
|
* addresses. This way if we don't get a bind we by default pick a ephemeral
|
|
|
|
* port with all addresses bound.
|
|
|
|
*/
|
|
|
|
int
|
2007-06-02 11:05:08 +00:00
|
|
|
sctp_inpcb_alloc(struct socket *so, uint32_t vrf_id)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* we get called when a new endpoint starts up. We need to allocate
|
|
|
|
* the sctp_inpcb structure from the zone and init it. Mark it as
|
|
|
|
* unbound and find a port that we can use as an ephemeral with
|
|
|
|
* INADDR_ANY. If the user binds later no problem we can then add in
|
|
|
|
* the specific addresses. And setup the default parameters for the
|
|
|
|
* EP.
|
|
|
|
*/
|
|
|
|
int i, error;
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
struct sctp_pcb *m;
|
|
|
|
struct timeval time;
|
|
|
|
sctp_sharedkey_t *null_key;
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
SCTP_INP_INFO_WLOCK();
|
2008-06-14 07:58:05 +00:00
|
|
|
inp = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_ep), struct sctp_inpcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (inp == NULL) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("Out of SCTP-INPCB structures - no resources\n");
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, ENOBUFS);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
|
|
|
/* zap it */
|
|
|
|
bzero(inp, sizeof(*inp));
|
|
|
|
|
|
|
|
/* bump generations */
|
|
|
|
/* setup socket pointers */
|
|
|
|
inp->sctp_socket = so;
|
|
|
|
inp->ip_inp.inp.inp_socket = so;
|
2014-06-20 13:26:49 +00:00
|
|
|
inp->ip_inp.inp.inp_cred = crhold(so->so_cred);
|
2011-09-14 08:15:21 +00:00
|
|
|
#ifdef INET6
|
2013-05-10 18:09:38 +00:00
|
|
|
if (INP_SOCKAF(so) == AF_INET6) {
|
|
|
|
if (MODULE_GLOBAL(ip6_auto_flowlabel)) {
|
|
|
|
inp->ip_inp.inp.inp_flags |= IN6P_AUTOFLOWLABEL;
|
|
|
|
}
|
|
|
|
if (MODULE_GLOBAL(ip6_v6only)) {
|
|
|
|
inp->ip_inp.inp.inp_flags |= IN6P_IPV6_V6ONLY;
|
|
|
|
}
|
2011-09-14 08:15:21 +00:00
|
|
|
}
|
|
|
|
#endif
|
2008-12-06 13:19:54 +00:00
|
|
|
inp->sctp_associd_counter = 1;
|
2007-03-20 10:23:11 +00:00
|
|
|
inp->partial_delivery_point = SCTP_SB_LIMIT_RCV(so) >> SCTP_PARTIAL_DELIVERY_SHIFT;
|
2006-11-03 15:23:16 +00:00
|
|
|
inp->sctp_frag_point = SCTP_DEFAULT_MAXSEGMENT;
|
2015-03-10 19:49:25 +00:00
|
|
|
inp->max_cwnd = 0;
|
2010-08-28 17:59:51 +00:00
|
|
|
inp->sctp_cmt_on_off = SCTP_BASE_SYSCTL(sctp_cmt_on_off);
|
2014-08-02 17:35:13 +00:00
|
|
|
inp->ecn_supported = (uint8_t) SCTP_BASE_SYSCTL(sctp_ecn_enable);
|
2014-08-02 21:36:40 +00:00
|
|
|
inp->prsctp_supported = (uint8_t) SCTP_BASE_SYSCTL(sctp_pr_enable);
|
2014-08-12 13:13:11 +00:00
|
|
|
inp->auth_supported = (uint8_t) SCTP_BASE_SYSCTL(sctp_auth_enable);
|
2014-08-12 11:30:16 +00:00
|
|
|
inp->asconf_supported = (uint8_t) SCTP_BASE_SYSCTL(sctp_asconf_enable);
|
2014-08-04 20:07:35 +00:00
|
|
|
inp->reconfig_supported = (uint8_t) SCTP_BASE_SYSCTL(sctp_reconfig_enable);
|
2014-08-03 14:10:10 +00:00
|
|
|
inp->nrsack_supported = (uint8_t) SCTP_BASE_SYSCTL(sctp_nrsack_enable);
|
2014-08-03 18:12:55 +00:00
|
|
|
inp->pktdrop_supported = (uint8_t) SCTP_BASE_SYSCTL(sctp_pktdrop_enable);
|
2008-12-06 13:19:54 +00:00
|
|
|
/* init the small hash table we use to track asocid <-> tcb */
|
|
|
|
inp->sctp_asocidhash = SCTP_HASH_INIT(SCTP_STACK_VTAG_HASH_SIZE, &inp->hashasocidmark);
|
|
|
|
if (inp->sctp_asocidhash == NULL) {
|
2014-06-20 13:26:49 +00:00
|
|
|
crfree(inp->ip_inp.inp.inp_cred);
|
2008-12-06 13:19:54 +00:00
|
|
|
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_ep), inp);
|
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
2010-06-06 02:33:46 +00:00
|
|
|
return (ENOBUFS);
|
2008-12-06 13:19:54 +00:00
|
|
|
}
|
2007-07-03 12:13:45 +00:00
|
|
|
#ifdef IPSEC
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
struct inpcbpolicy *pcb_sp = NULL;
|
|
|
|
|
2007-07-01 11:41:27 +00:00
|
|
|
error = ipsec_init_policy(so, &pcb_sp);
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Arrange to share the policy */
|
|
|
|
inp->ip_inp.inp.inp_sp = pcb_sp;
|
|
|
|
((struct in6pcb *)(&inp->ip_inp.inp))->in6p_sp = pcb_sp;
|
|
|
|
}
|
|
|
|
if (error != 0) {
|
2014-06-20 13:26:49 +00:00
|
|
|
crfree(inp->ip_inp.inp.inp_cred);
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_ep), inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
|
|
|
return error;
|
|
|
|
}
|
2007-07-03 12:13:45 +00:00
|
|
|
#endif /* IPSEC */
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INCR_EP_COUNT();
|
2009-09-17 15:11:12 +00:00
|
|
|
inp->ip_inp.inp.inp_ip_ttl = MODULE_GLOBAL(ip_defttl);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
|
|
|
|
|
|
|
so->so_pcb = (caddr_t)inp;
|
|
|
|
|
2011-07-12 20:14:03 +00:00
|
|
|
if (SCTP_SO_TYPE(so) == SOCK_SEQPACKET) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* UDP style socket */
|
|
|
|
inp->sctp_flags = (SCTP_PCB_FLAGS_UDPTYPE |
|
|
|
|
SCTP_PCB_FLAGS_UNBOUND);
|
|
|
|
/* Be sure it is NON-BLOCKING IO for UDP */
|
2007-03-15 11:27:14 +00:00
|
|
|
/* SCTP_SET_SO_NBIO(so); */
|
|
|
|
} else if (SCTP_SO_TYPE(so) == SOCK_STREAM) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* TCP style socket */
|
|
|
|
inp->sctp_flags = (SCTP_PCB_FLAGS_TCPTYPE |
|
|
|
|
SCTP_PCB_FLAGS_UNBOUND);
|
|
|
|
/* Be sure we have blocking IO by default */
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_CLEAR_SO_NBIO(so);
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* unsupported socket type (RAW, etc)- in case we missed it
|
|
|
|
* in protosw
|
|
|
|
*/
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, EOPNOTSUPP);
|
2010-06-09 22:05:29 +00:00
|
|
|
so->so_pcb = NULL;
|
2014-06-20 13:26:49 +00:00
|
|
|
crfree(inp->ip_inp.inp.inp_cred);
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_ep), inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_default_frag_interleave) == SCTP_FRAG_LEVEL_1) {
|
2007-08-24 00:53:53 +00:00
|
|
|
sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
|
|
|
|
sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
|
2008-06-14 07:58:05 +00:00
|
|
|
} else if (SCTP_BASE_SYSCTL(sctp_default_frag_interleave) == SCTP_FRAG_LEVEL_2) {
|
2007-08-24 00:53:53 +00:00
|
|
|
sctp_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
|
|
|
|
sctp_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
|
2008-06-14 07:58:05 +00:00
|
|
|
} else if (SCTP_BASE_SYSCTL(sctp_default_frag_interleave) == SCTP_FRAG_LEVEL_0) {
|
2007-08-24 00:53:53 +00:00
|
|
|
sctp_feature_off(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE);
|
|
|
|
sctp_feature_off(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS);
|
|
|
|
}
|
2008-06-14 07:58:05 +00:00
|
|
|
inp->sctp_tcbhash = SCTP_HASH_INIT(SCTP_BASE_SYSCTL(sctp_pcbtblsize),
|
2006-11-03 15:23:16 +00:00
|
|
|
&inp->sctp_hashmark);
|
|
|
|
if (inp->sctp_tcbhash == NULL) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("Out of SCTP-INPCB->hashinit - no resources\n");
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, ENOBUFS);
|
2010-06-09 22:05:29 +00:00
|
|
|
so->so_pcb = NULL;
|
2014-06-20 13:26:49 +00:00
|
|
|
crfree(inp->ip_inp.inp.inp_cred);
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_ep), inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
2007-06-02 11:05:08 +00:00
|
|
|
inp->def_vrf_id = vrf_id;
|
2007-03-15 11:27:14 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_INFO_WLOCK();
|
|
|
|
SCTP_INP_LOCK_INIT(inp);
|
2007-06-15 19:28:58 +00:00
|
|
|
INP_LOCK_INIT(&inp->ip_inp.inp, "inp", "sctpinp");
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_READ_INIT(inp);
|
|
|
|
SCTP_ASOC_CREATE_LOCK_INIT(inp);
|
|
|
|
/* lock the new ep */
|
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
|
|
|
|
/* add it to the info area */
|
2008-06-14 07:58:05 +00:00
|
|
|
LIST_INSERT_HEAD(&SCTP_BASE_INFO(listhead), inp, sctp_list);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
|
|
|
|
|
|
|
TAILQ_INIT(&inp->read_queue);
|
|
|
|
LIST_INIT(&inp->sctp_addr_list);
|
2007-03-15 11:27:14 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
LIST_INIT(&inp->sctp_asoc_list);
|
|
|
|
|
2006-12-14 17:02:55 +00:00
|
|
|
#ifdef SCTP_TRACK_FREED_ASOCS
|
|
|
|
/* TEMP CODE */
|
|
|
|
LIST_INIT(&inp->sctp_asoc_free_list);
|
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Init the timer structure for signature change */
|
2006-12-29 20:21:42 +00:00
|
|
|
SCTP_OS_TIMER_INIT(&inp->sctp_ep.signature_change.timer);
|
2006-11-03 15:23:16 +00:00
|
|
|
inp->sctp_ep.signature_change.type = SCTP_TIMER_TYPE_NEWCOOKIE;
|
|
|
|
|
|
|
|
/* now init the actual endpoint default data */
|
|
|
|
m = &inp->sctp_ep;
|
|
|
|
|
|
|
|
/* setup the base timeout information */
|
|
|
|
m->sctp_timeoutticks[SCTP_TIMER_SEND] = SEC_TO_TICKS(SCTP_SEND_SEC); /* needed ? */
|
|
|
|
m->sctp_timeoutticks[SCTP_TIMER_INIT] = SEC_TO_TICKS(SCTP_INIT_SEC); /* needed ? */
|
2008-06-14 07:58:05 +00:00
|
|
|
m->sctp_timeoutticks[SCTP_TIMER_RECV] = MSEC_TO_TICKS(SCTP_BASE_SYSCTL(sctp_delayed_sack_time_default));
|
|
|
|
m->sctp_timeoutticks[SCTP_TIMER_HEARTBEAT] = MSEC_TO_TICKS(SCTP_BASE_SYSCTL(sctp_heartbeat_interval_default));
|
|
|
|
m->sctp_timeoutticks[SCTP_TIMER_PMTU] = SEC_TO_TICKS(SCTP_BASE_SYSCTL(sctp_pmtu_raise_time_default));
|
|
|
|
m->sctp_timeoutticks[SCTP_TIMER_MAXSHUTDOWN] = SEC_TO_TICKS(SCTP_BASE_SYSCTL(sctp_shutdown_guard_time_default));
|
|
|
|
m->sctp_timeoutticks[SCTP_TIMER_SIGNATURE] = SEC_TO_TICKS(SCTP_BASE_SYSCTL(sctp_secret_lifetime_default));
|
2006-11-03 15:23:16 +00:00
|
|
|
/* all max/min max are in ms */
|
2008-06-14 07:58:05 +00:00
|
|
|
m->sctp_maxrto = SCTP_BASE_SYSCTL(sctp_rto_max_default);
|
|
|
|
m->sctp_minrto = SCTP_BASE_SYSCTL(sctp_rto_min_default);
|
|
|
|
m->initial_rto = SCTP_BASE_SYSCTL(sctp_rto_initial_default);
|
|
|
|
m->initial_init_rto_max = SCTP_BASE_SYSCTL(sctp_init_rto_max_default);
|
|
|
|
m->sctp_sack_freq = SCTP_BASE_SYSCTL(sctp_sack_freq_default);
|
|
|
|
m->max_init_times = SCTP_BASE_SYSCTL(sctp_init_rtx_max_default);
|
|
|
|
m->max_send_times = SCTP_BASE_SYSCTL(sctp_assoc_rtx_max_default);
|
|
|
|
m->def_net_failure = SCTP_BASE_SYSCTL(sctp_path_rtx_max_default);
|
2011-08-03 20:21:00 +00:00
|
|
|
m->def_net_pf_threshold = SCTP_BASE_SYSCTL(sctp_path_pf_threshold);
|
2006-11-03 15:23:16 +00:00
|
|
|
m->sctp_sws_sender = SCTP_SWS_SENDER_DEF;
|
|
|
|
m->sctp_sws_receiver = SCTP_SWS_RECEIVER_DEF;
|
2008-06-14 07:58:05 +00:00
|
|
|
m->max_burst = SCTP_BASE_SYSCTL(sctp_max_burst_default);
|
2011-02-02 11:13:23 +00:00
|
|
|
m->fr_max_burst = SCTP_BASE_SYSCTL(sctp_fr_max_burst_default);
|
|
|
|
|
2011-01-19 22:10:35 +00:00
|
|
|
m->sctp_default_cc_module = SCTP_BASE_SYSCTL(sctp_default_cc_module);
|
2011-01-23 19:36:28 +00:00
|
|
|
m->sctp_default_ss_module = SCTP_BASE_SYSCTL(sctp_default_ss_module);
|
2013-07-05 10:08:49 +00:00
|
|
|
m->max_open_streams_intome = SCTP_BASE_SYSCTL(sctp_nr_incoming_streams_default);
|
2006-11-03 15:23:16 +00:00
|
|
|
/* number of streams to pre-open on a association */
|
2008-06-14 07:58:05 +00:00
|
|
|
m->pre_open_stream_count = SCTP_BASE_SYSCTL(sctp_nr_outgoing_streams_default);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/* Add adaptation cookie */
|
2013-02-11 21:02:49 +00:00
|
|
|
m->adaptation_layer_indicator = 0;
|
|
|
|
m->adaptation_layer_indicator_provided = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/* seed random number generator */
|
|
|
|
m->random_counter = 1;
|
|
|
|
m->store_at = SCTP_SIGNATURE_SIZE;
|
2006-12-29 20:21:42 +00:00
|
|
|
SCTP_READ_RANDOM(m->random_numbers, sizeof(m->random_numbers));
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_fill_random_store(m);
|
|
|
|
|
|
|
|
/* Minimum cookie size */
|
|
|
|
m->size_of_a_cookie = (sizeof(struct sctp_init_msg) * 2) +
|
|
|
|
sizeof(struct sctp_state_cookie);
|
|
|
|
m->size_of_a_cookie += SCTP_SIGNATURE_SIZE;
|
|
|
|
|
|
|
|
/* Setup the initial secret */
|
2007-05-08 14:32:53 +00:00
|
|
|
(void)SCTP_GETTIME_TIMEVAL(&time);
|
2006-11-03 15:23:16 +00:00
|
|
|
m->time_of_secret_change = time.tv_sec;
|
|
|
|
|
|
|
|
for (i = 0; i < SCTP_NUMBER_OF_SECRETS; i++) {
|
|
|
|
m->secret_key[0][i] = sctp_select_initial_TSN(m);
|
|
|
|
}
|
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_NEWCOOKIE, inp, NULL, NULL);
|
|
|
|
|
|
|
|
/* How long is a cookie good for ? */
|
2008-06-14 07:58:05 +00:00
|
|
|
m->def_cookie_life = MSEC_TO_TICKS(SCTP_BASE_SYSCTL(sctp_valid_cookie_life_default));
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* Initialize authentication parameters
|
|
|
|
*/
|
|
|
|
m->local_hmacs = sctp_default_supported_hmaclist();
|
|
|
|
m->local_auth_chunks = sctp_alloc_chunklist();
|
2014-08-12 11:30:16 +00:00
|
|
|
if (inp->asconf_supported) {
|
|
|
|
sctp_auth_add_chunk(SCTP_ASCONF, m->local_auth_chunks);
|
|
|
|
sctp_auth_add_chunk(SCTP_ASCONF_ACK, m->local_auth_chunks);
|
|
|
|
}
|
2011-09-14 08:15:21 +00:00
|
|
|
m->default_dscp = 0;
|
|
|
|
#ifdef INET6
|
|
|
|
m->default_flowlabel = 0;
|
|
|
|
#endif
|
2011-11-20 15:00:45 +00:00
|
|
|
m->port = 0; /* encapsulation disabled by default */
|
2006-11-03 15:23:16 +00:00
|
|
|
LIST_INIT(&m->shared_keys);
|
|
|
|
/* add default NULL key as key id 0 */
|
|
|
|
null_key = sctp_alloc_sharedkey();
|
|
|
|
sctp_insert_sharedkey(&m->shared_keys, null_key);
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
#ifdef SCTP_LOG_CLOSING
|
|
|
|
sctp_log_closing(inp, NULL, 12);
|
|
|
|
#endif
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_move_pcb_and_assoc(struct sctp_inpcb *old_inp, struct sctp_inpcb *new_inp,
|
|
|
|
struct sctp_tcb *stcb)
|
|
|
|
{
|
|
|
|
struct sctp_nets *net;
|
|
|
|
uint16_t lport, rport;
|
|
|
|
struct sctppcbhead *head;
|
|
|
|
struct sctp_laddr *laddr, *oladdr;
|
|
|
|
|
2007-08-27 05:19:48 +00:00
|
|
|
atomic_add_int(&stcb->asoc.refcnt, 1);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
SCTP_INP_INFO_WLOCK();
|
|
|
|
SCTP_INP_WLOCK(old_inp);
|
|
|
|
SCTP_INP_WLOCK(new_inp);
|
|
|
|
SCTP_TCB_LOCK(stcb);
|
2007-08-27 05:19:48 +00:00
|
|
|
atomic_subtract_int(&stcb->asoc.refcnt, 1);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
new_inp->sctp_ep.time_of_secret_change =
|
|
|
|
old_inp->sctp_ep.time_of_secret_change;
|
|
|
|
memcpy(new_inp->sctp_ep.secret_key, old_inp->sctp_ep.secret_key,
|
|
|
|
sizeof(old_inp->sctp_ep.secret_key));
|
|
|
|
new_inp->sctp_ep.current_secret_number =
|
|
|
|
old_inp->sctp_ep.current_secret_number;
|
|
|
|
new_inp->sctp_ep.last_secret_number =
|
|
|
|
old_inp->sctp_ep.last_secret_number;
|
|
|
|
new_inp->sctp_ep.size_of_a_cookie = old_inp->sctp_ep.size_of_a_cookie;
|
|
|
|
|
|
|
|
/* make it so new data pours into the new socket */
|
|
|
|
stcb->sctp_socket = new_inp->sctp_socket;
|
|
|
|
stcb->sctp_ep = new_inp;
|
|
|
|
|
|
|
|
/* Copy the port across */
|
|
|
|
lport = new_inp->sctp_lport = old_inp->sctp_lport;
|
|
|
|
rport = stcb->rport;
|
|
|
|
/* Pull the tcb from the old association */
|
|
|
|
LIST_REMOVE(stcb, sctp_tcbhash);
|
|
|
|
LIST_REMOVE(stcb, sctp_tcblist);
|
2009-02-03 11:04:03 +00:00
|
|
|
if (stcb->asoc.in_asocid_hash) {
|
|
|
|
LIST_REMOVE(stcb, sctp_tcbasocidhash);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Now insert the new_inp into the TCP connected hash */
|
2010-11-09 16:18:32 +00:00
|
|
|
head = &SCTP_BASE_INFO(sctp_tcpephash)[SCTP_PCBHASH_ALLADDR((lport | rport), SCTP_BASE_INFO(hashtcpmark))];
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
LIST_INSERT_HEAD(head, new_inp, sctp_hash);
|
2007-01-18 09:58:43 +00:00
|
|
|
/* Its safe to access */
|
|
|
|
new_inp->sctp_flags &= ~SCTP_PCB_FLAGS_UNBOUND;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/* Now move the tcb into the endpoint list */
|
|
|
|
LIST_INSERT_HEAD(&new_inp->sctp_asoc_list, stcb, sctp_tcblist);
|
|
|
|
/*
|
|
|
|
* Question, do we even need to worry about the ep-hash since we
|
|
|
|
* only have one connection? Probably not :> so lets get rid of it
|
|
|
|
* and not suck up any kernel memory in that.
|
|
|
|
*/
|
2009-02-03 11:04:03 +00:00
|
|
|
if (stcb->asoc.in_asocid_hash) {
|
|
|
|
struct sctpasochead *lhd;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2009-02-03 11:04:03 +00:00
|
|
|
lhd = &new_inp->sctp_asocidhash[SCTP_PCBHASH_ASOC(stcb->asoc.assoc_id,
|
|
|
|
new_inp->hashasocidmark)];
|
|
|
|
LIST_INSERT_HEAD(lhd, stcb, sctp_tcbasocidhash);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Ok. Let's restart timer. */
|
|
|
|
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
|
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, new_inp,
|
|
|
|
stcb, net);
|
|
|
|
}
|
|
|
|
|
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
|
|
|
if (new_inp->sctp_tcbhash != NULL) {
|
2007-01-15 15:12:10 +00:00
|
|
|
SCTP_HASH_FREE(new_inp->sctp_tcbhash, new_inp->sctp_hashmark);
|
2006-11-03 15:23:16 +00:00
|
|
|
new_inp->sctp_tcbhash = NULL;
|
|
|
|
}
|
|
|
|
if ((new_inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) {
|
|
|
|
/* Subset bound, so copy in the laddr list from the old_inp */
|
|
|
|
LIST_FOREACH(oladdr, &old_inp->sctp_addr_list, sctp_nxt_addr) {
|
2008-06-14 07:58:05 +00:00
|
|
|
laddr = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_laddr), struct sctp_laddr);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (laddr == NULL) {
|
|
|
|
/*
|
|
|
|
* Gak, what can we do? This assoc is really
|
|
|
|
* HOSED. We probably should send an abort
|
|
|
|
* here.
|
|
|
|
*/
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB1, "Association hosed in TCP model, out of laddr memory\n");
|
2006-11-03 15:23:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
SCTP_INCR_LADDR_COUNT();
|
|
|
|
bzero(laddr, sizeof(*laddr));
|
2007-05-28 11:17:24 +00:00
|
|
|
(void)SCTP_GETTIME_TIMEVAL(&laddr->start_time);
|
2006-11-03 15:23:16 +00:00
|
|
|
laddr->ifa = oladdr->ifa;
|
2007-04-03 11:15:32 +00:00
|
|
|
atomic_add_int(&laddr->ifa->refcount, 1);
|
2006-11-03 15:23:16 +00:00
|
|
|
LIST_INSERT_HEAD(&new_inp->sctp_addr_list, laddr,
|
|
|
|
sctp_nxt_addr);
|
|
|
|
new_inp->laddr_count++;
|
2011-10-10 12:28:47 +00:00
|
|
|
if (oladdr == stcb->asoc.last_used_address) {
|
|
|
|
stcb->asoc.last_used_address = laddr;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Now any running timers need to be adjusted since we really don't
|
|
|
|
* care if they are running or not just blast in the new_inp into
|
|
|
|
* all of them.
|
|
|
|
*/
|
|
|
|
|
|
|
|
stcb->asoc.dack_timer.ep = (void *)new_inp;
|
|
|
|
stcb->asoc.asconf_timer.ep = (void *)new_inp;
|
|
|
|
stcb->asoc.strreset_timer.ep = (void *)new_inp;
|
|
|
|
stcb->asoc.shut_guard_timer.ep = (void *)new_inp;
|
|
|
|
stcb->asoc.autoclose_timer.ep = (void *)new_inp;
|
|
|
|
stcb->asoc.delayed_event_timer.ep = (void *)new_inp;
|
2007-09-08 17:48:46 +00:00
|
|
|
stcb->asoc.delete_prim_timer.ep = (void *)new_inp;
|
2006-11-03 15:23:16 +00:00
|
|
|
/* now what about the nets? */
|
|
|
|
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
|
|
|
|
net->pmtu_timer.ep = (void *)new_inp;
|
2011-10-09 14:12:17 +00:00
|
|
|
net->hb_timer.ep = (void *)new_inp;
|
2006-11-03 15:23:16 +00:00
|
|
|
net->rxt_timer.ep = (void *)new_inp;
|
|
|
|
}
|
|
|
|
SCTP_INP_WUNLOCK(new_inp);
|
|
|
|
SCTP_INP_WUNLOCK(old_inp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-07-24 20:06:02 +00:00
|
|
|
/* sctp_ifap is used to bypass normal local address validation checks */
|
2006-11-03 15:23:16 +00:00
|
|
|
int
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_inpcb_bind(struct socket *so, struct sockaddr *addr,
|
2007-07-24 20:06:02 +00:00
|
|
|
struct sctp_ifa *sctp_ifap, struct thread *p)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
/* bind a ep to a socket address */
|
|
|
|
struct sctppcbhead *head;
|
|
|
|
struct sctp_inpcb *inp, *inp_tmp;
|
|
|
|
struct inpcb *ip_inp;
|
2008-07-31 11:08:30 +00:00
|
|
|
int port_reuse_active = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
int bindall;
|
|
|
|
uint16_t lport;
|
|
|
|
int error;
|
2007-03-15 11:27:14 +00:00
|
|
|
uint32_t vrf_id;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
lport = 0;
|
|
|
|
bindall = 1;
|
|
|
|
inp = (struct sctp_inpcb *)so->so_pcb;
|
|
|
|
ip_inp = (struct inpcb *)so->so_pcb;
|
|
|
|
#ifdef SCTP_DEBUG
|
2007-05-09 13:30:06 +00:00
|
|
|
if (addr) {
|
2012-12-27 08:06:58 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB1, "Bind called port: %d\n",
|
2007-05-09 13:30:06 +00:00
|
|
|
ntohs(((struct sockaddr_in *)addr)->sin_port));
|
2012-12-27 08:06:58 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB1, "Addr: ");
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTPDBG_ADDR(SCTP_DEBUG_PCB1, addr);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-05-09 13:30:06 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) == 0) {
|
|
|
|
/* already did a bind, subsequent binds NOT allowed ! */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
2007-07-21 21:41:32 +00:00
|
|
|
#ifdef INVARIANTS
|
|
|
|
if (p == NULL)
|
|
|
|
panic("null proc/thread");
|
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
if (addr != NULL) {
|
2008-04-16 17:24:18 +00:00
|
|
|
switch (addr->sa_family) {
|
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;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2008-04-16 17:24:18 +00:00
|
|
|
/* IPV6_V6ONLY socket? */
|
|
|
|
if (SCTP_IPV6_V6ONLY(ip_inp)) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, EINVAL);
|
2007-07-17 20:58:26 +00:00
|
|
|
return (EINVAL);
|
2007-08-24 00:53:53 +00:00
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
if (addr->sa_len != sizeof(*sin)) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, EINVAL);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
sin = (struct sockaddr_in *)addr;
|
|
|
|
lport = sin->sin_port;
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
/*
|
2008-12-06 13:19:54 +00:00
|
|
|
* For LOOPBACK the prison_local_ip4() call
|
|
|
|
* will transmute the ip address to the
|
|
|
|
* proper value.
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
*/
|
2009-02-13 18:44:30 +00:00
|
|
|
if (p && (error = prison_local_ip4(p->td_ucred, &sin->sin_addr)) != 0) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, error);
|
|
|
|
return (error);
|
2008-04-16 17:24:18 +00:00
|
|
|
}
|
|
|
|
if (sin->sin_addr.s_addr != INADDR_ANY) {
|
|
|
|
bindall = 0;
|
|
|
|
}
|
|
|
|
break;
|
2007-07-17 20:58:26 +00:00
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
#endif
|
2008-04-16 17:24:18 +00:00
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Only for pure IPv6 Address. (No IPv4
|
|
|
|
* Mapped!)
|
|
|
|
*/
|
|
|
|
struct sockaddr_in6 *sin6;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2008-04-16 17:24:18 +00:00
|
|
|
sin6 = (struct sockaddr_in6 *)addr;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2008-04-16 17:24:18 +00:00
|
|
|
if (addr->sa_len != sizeof(*sin6)) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (EINVAL);
|
2007-08-24 00:53:53 +00:00
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
lport = sin6->sin6_port;
|
|
|
|
/*
|
2008-12-06 13:19:54 +00:00
|
|
|
* For LOOPBACK the prison_local_ip6() call
|
|
|
|
* will transmute the ipv6 address to the
|
|
|
|
* proper value.
|
2008-04-16 17:24:18 +00:00
|
|
|
*/
|
2009-02-13 18:44:30 +00:00
|
|
|
if (p && (error = prison_local_ip6(p->td_ucred, &sin6->sin6_addr,
|
|
|
|
(SCTP_IPV6_V6ONLY(inp) != 0))) != 0) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, error);
|
|
|
|
return (error);
|
MFp4:
Bring in updated jail support from bz_jail branch.
This enhances the current jail implementation to permit multiple
addresses per jail. In addtion to IPv4, IPv6 is supported as well.
Due to updated checks it is even possible to have jails without
an IP address at all, which basically gives one a chroot with
restricted process view, no networking,..
SCTP support was updated and supports IPv6 in jails as well.
Cpuset support permits jails to be bound to specific processor
sets after creation.
Jails can have an unrestricted (no duplicate protection, etc.) name
in addition to the hostname. The jail name cannot be changed from
within a jail and is considered to be used for management purposes
or as audit-token in the future.
DDB 'show jails' command was added to aid debugging.
Proper compat support permits 32bit jail binaries to be used on 64bit
systems to manage jails. Also backward compatibility was preserved where
possible: for jail v1 syscalls, as well as with user space management
utilities.
Both jail as well as prison version were updated for the new features.
A gap was intentionally left as the intermediate versions had been
used by various patches floating around the last years.
Bump __FreeBSD_version for the afore mentioned and in kernel changes.
Special thanks to:
- Pawel Jakub Dawidek (pjd) for his multi-IPv4 patches
and Olivier Houchard (cognet) for initial single-IPv6 patches.
- Jeff Roberson (jeff) and Randall Stewart (rrs) for their
help, ideas and review on cpuset and SCTP support.
- Robert Watson (rwatson) for lots and lots of help, discussions,
suggestions and review of most of the patch at various stages.
- John Baldwin (jhb) for his help.
- Simon L. Nielsen (simon) as early adopter testing changes
on cluster machines as well as all the testers and people
who provided feedback the last months on freebsd-jail and
other channels.
- My employer, CK Software GmbH, for the support so I could work on this.
Reviewed by: (see above)
MFC after: 3 months (this is just so that I get the mail)
X-MFC Before: 7.2-RELEASE if possible
2008-11-29 14:32:14 +00:00
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
if (!IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
|
|
|
|
bindall = 0;
|
|
|
|
/* KAME hack: embed scopeid */
|
2009-09-17 15:11:12 +00:00
|
|
|
if (sa6_embedscope(sin6, MODULE_GLOBAL(ip6_use_defzone)) != 0) {
|
2008-04-16 17:24:18 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, EINVAL);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* this must be cleared for ifa_ifwithaddr() */
|
|
|
|
sin6->sin6_scope_id = 0;
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
#endif
|
|
|
|
default:
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, EAFNOSUPPORT);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (EAFNOSUPPORT);
|
|
|
|
}
|
|
|
|
}
|
2008-01-28 10:34:38 +00:00
|
|
|
SCTP_INP_INFO_WLOCK();
|
|
|
|
SCTP_INP_WLOCK(inp);
|
2007-05-17 12:16:24 +00:00
|
|
|
/* Setup a vrf_id to be the default for the non-bind-all case. */
|
2007-03-15 11:27:14 +00:00
|
|
|
vrf_id = inp->def_vrf_id;
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/* increase our count due to the unlock we do */
|
|
|
|
SCTP_INP_INCR_REF(inp);
|
|
|
|
if (lport) {
|
|
|
|
/*
|
2012-09-09 08:14:04 +00:00
|
|
|
* Did the caller specify a port? if so we must see if an ep
|
2006-11-03 15:23:16 +00:00
|
|
|
* already has this one bound.
|
|
|
|
*/
|
|
|
|
/* got to be root to get at low ports */
|
|
|
|
if (ntohs(lport) < IPPORT_RESERVED) {
|
2006-11-08 00:21:13 +00:00
|
|
|
if (p && (error =
|
2007-06-12 00:12:01 +00:00
|
|
|
priv_check(p, PRIV_NETINET_RESERVEDPORT)
|
2006-11-08 00:21:13 +00:00
|
|
|
)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_DECR_REF(inp);
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
2007-03-15 11:27:14 +00:00
|
|
|
if (bindall) {
|
|
|
|
vrf_id = inp->def_vrf_id;
|
|
|
|
inp_tmp = sctp_pcb_findep(addr, 0, 1, vrf_id);
|
|
|
|
if (inp_tmp != NULL) {
|
|
|
|
/*
|
|
|
|
* lock guy returned and lower count note
|
|
|
|
* that we are not bound so inp_tmp should
|
|
|
|
* NEVER be inp. And it is this inp
|
|
|
|
* (inp_tmp) that gets the reference bump,
|
|
|
|
* so we must lower it.
|
|
|
|
*/
|
|
|
|
SCTP_INP_DECR_REF(inp_tmp);
|
|
|
|
/* unlock info */
|
2008-07-31 11:08:30 +00:00
|
|
|
if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
|
|
|
|
(sctp_is_feature_on(inp_tmp, SCTP_PCB_FLAGS_PORTREUSE))) {
|
|
|
|
/*
|
|
|
|
* Ok, must be one-2-one and
|
|
|
|
* allowing port re-use
|
|
|
|
*/
|
|
|
|
port_reuse_active = 1;
|
|
|
|
goto continue_anyway;
|
|
|
|
}
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, EADDRINUSE);
|
2007-05-29 09:29:03 +00:00
|
|
|
return (EADDRINUSE);
|
2007-03-15 11:27:14 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
inp_tmp = sctp_pcb_findep(addr, 0, 1, vrf_id);
|
|
|
|
if (inp_tmp != NULL) {
|
|
|
|
/*
|
|
|
|
* lock guy returned and lower count note
|
|
|
|
* that we are not bound so inp_tmp should
|
|
|
|
* NEVER be inp. And it is this inp
|
|
|
|
* (inp_tmp) that gets the reference bump,
|
|
|
|
* so we must lower it.
|
|
|
|
*/
|
|
|
|
SCTP_INP_DECR_REF(inp_tmp);
|
|
|
|
/* unlock info */
|
2008-07-31 11:08:30 +00:00
|
|
|
if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
|
|
|
|
(sctp_is_feature_on(inp_tmp, SCTP_PCB_FLAGS_PORTREUSE))) {
|
|
|
|
/*
|
|
|
|
* Ok, must be one-2-one and
|
|
|
|
* allowing port re-use
|
|
|
|
*/
|
|
|
|
port_reuse_active = 1;
|
|
|
|
goto continue_anyway;
|
|
|
|
}
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, EADDRINUSE);
|
2007-05-29 09:29:03 +00:00
|
|
|
return (EADDRINUSE);
|
2007-03-15 11:27:14 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2008-07-31 11:08:30 +00:00
|
|
|
continue_anyway:
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
if (bindall) {
|
|
|
|
/* verify that no lport is not used by a singleton */
|
2008-07-31 11:08:30 +00:00
|
|
|
if ((port_reuse_active == 0) &&
|
2012-09-09 08:14:04 +00:00
|
|
|
(inp_tmp = sctp_isport_inuse(inp, lport, vrf_id))) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Sorry someone already has this one bound */
|
2008-07-31 11:08:30 +00:00
|
|
|
if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_PORTREUSE)) &&
|
|
|
|
(sctp_is_feature_on(inp_tmp, SCTP_PCB_FLAGS_PORTREUSE))) {
|
|
|
|
port_reuse_active = 1;
|
|
|
|
} else {
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, EADDRINUSE);
|
|
|
|
return (EADDRINUSE);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2007-06-13 01:31:53 +00:00
|
|
|
uint16_t first, last, candidate;
|
2007-05-28 11:17:24 +00:00
|
|
|
uint16_t count;
|
|
|
|
int done;
|
|
|
|
|
|
|
|
if (ip_inp->inp_flags & INP_HIGHPORT) {
|
2009-09-17 15:11:12 +00:00
|
|
|
first = MODULE_GLOBAL(ipport_hifirstauto);
|
|
|
|
last = MODULE_GLOBAL(ipport_hilastauto);
|
2007-05-28 11:17:24 +00:00
|
|
|
} else if (ip_inp->inp_flags & INP_LOWPORT) {
|
|
|
|
if (p && (error =
|
2007-06-12 00:12:01 +00:00
|
|
|
priv_check(p, PRIV_NETINET_RESERVEDPORT)
|
2007-05-28 11:17:24 +00:00
|
|
|
)) {
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, error);
|
2007-05-28 11:17:24 +00:00
|
|
|
return (error);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2009-09-17 15:11:12 +00:00
|
|
|
first = MODULE_GLOBAL(ipport_lowfirstauto);
|
|
|
|
last = MODULE_GLOBAL(ipport_lowlastauto);
|
2007-05-28 11:17:24 +00:00
|
|
|
} else {
|
2009-09-17 15:11:12 +00:00
|
|
|
first = MODULE_GLOBAL(ipport_firstauto);
|
|
|
|
last = MODULE_GLOBAL(ipport_lastauto);
|
2007-05-28 11:17:24 +00:00
|
|
|
}
|
|
|
|
if (first > last) {
|
|
|
|
uint16_t temp;
|
2007-05-17 12:16:24 +00:00
|
|
|
|
2007-05-28 11:17:24 +00:00
|
|
|
temp = first;
|
|
|
|
first = last;
|
|
|
|
last = temp;
|
|
|
|
}
|
|
|
|
count = last - first + 1; /* number of candidates */
|
2007-06-13 01:31:53 +00:00
|
|
|
candidate = first + sctp_select_initial_TSN(&inp->sctp_ep) % (count);
|
2007-05-28 11:17:24 +00:00
|
|
|
|
|
|
|
done = 0;
|
|
|
|
while (!done) {
|
2008-07-31 11:08:30 +00:00
|
|
|
if (sctp_isport_inuse(inp, htons(candidate), inp->def_vrf_id) == NULL) {
|
2007-05-28 11:17:24 +00:00
|
|
|
done = 1;
|
2007-03-15 11:27:14 +00:00
|
|
|
}
|
2007-05-28 11:17:24 +00:00
|
|
|
if (!done) {
|
|
|
|
if (--count == 0) {
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, EADDRINUSE);
|
2007-05-29 09:29:03 +00:00
|
|
|
return (EADDRINUSE);
|
2007-05-28 11:17:24 +00:00
|
|
|
}
|
2007-06-13 01:31:53 +00:00
|
|
|
if (candidate == last)
|
|
|
|
candidate = first;
|
2007-05-28 11:17:24 +00:00
|
|
|
else
|
2007-06-13 01:31:53 +00:00
|
|
|
candidate = candidate + 1;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-13 01:31:53 +00:00
|
|
|
lport = htons(candidate);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
|
|
|
if (inp->sctp_flags & (SCTP_PCB_FLAGS_SOCKET_GONE |
|
|
|
|
SCTP_PCB_FLAGS_SOCKET_ALLGONE)) {
|
|
|
|
/*
|
|
|
|
* this really should not happen. The guy did a non-blocking
|
|
|
|
* bind and then did a close at the same time.
|
|
|
|
*/
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
/* ok we look clear to give out this port, so lets setup the binding */
|
|
|
|
if (bindall) {
|
|
|
|
/* binding to all addresses, so just set in the proper flags */
|
|
|
|
inp->sctp_flags |= SCTP_PCB_FLAGS_BOUNDALL;
|
|
|
|
/* set the automatic addr changes from kernel flag */
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_auto_asconf) == 0) {
|
2007-08-24 00:53:53 +00:00
|
|
|
sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_ASCONF);
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
|
|
|
|
} else {
|
2007-08-24 00:53:53 +00:00
|
|
|
sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF);
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_feature_on(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
|
|
|
|
}
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_multiple_asconfs) == 0) {
|
2008-05-20 13:47:46 +00:00
|
|
|
sctp_feature_off(inp, SCTP_PCB_FLAGS_MULTIPLE_ASCONFS);
|
|
|
|
} else {
|
|
|
|
sctp_feature_on(inp, SCTP_PCB_FLAGS_MULTIPLE_ASCONFS);
|
|
|
|
}
|
2007-08-27 05:19:48 +00:00
|
|
|
/*
|
|
|
|
* set the automatic mobility_base from kernel flag (by
|
|
|
|
* micchie)
|
|
|
|
*/
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_mobility_base) == 0) {
|
2007-08-27 05:19:48 +00:00
|
|
|
sctp_mobility_feature_off(inp, SCTP_MOBILITY_BASE);
|
2007-09-08 17:48:46 +00:00
|
|
|
sctp_mobility_feature_off(inp, SCTP_MOBILITY_PRIM_DELETED);
|
2007-08-27 05:19:48 +00:00
|
|
|
} else {
|
|
|
|
sctp_mobility_feature_on(inp, SCTP_MOBILITY_BASE);
|
2007-09-08 17:48:46 +00:00
|
|
|
sctp_mobility_feature_off(inp, SCTP_MOBILITY_PRIM_DELETED);
|
2007-08-27 05:19:48 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* set the automatic mobility_fasthandoff from kernel flag
|
|
|
|
* (by micchie)
|
|
|
|
*/
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_mobility_fasthandoff) == 0) {
|
2007-08-27 05:19:48 +00:00
|
|
|
sctp_mobility_feature_off(inp, SCTP_MOBILITY_FASTHANDOFF);
|
2007-09-08 17:48:46 +00:00
|
|
|
sctp_mobility_feature_off(inp, SCTP_MOBILITY_PRIM_DELETED);
|
2007-08-27 05:19:48 +00:00
|
|
|
} else {
|
|
|
|
sctp_mobility_feature_on(inp, SCTP_MOBILITY_FASTHANDOFF);
|
2007-09-08 17:48:46 +00:00
|
|
|
sctp_mobility_feature_off(inp, SCTP_MOBILITY_PRIM_DELETED);
|
2007-08-27 05:19:48 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* bind specific, make sure flags is off and add a new
|
|
|
|
* address structure to the sctp_addr_list inside the ep
|
|
|
|
* structure.
|
|
|
|
*
|
|
|
|
* We will need to allocate one and insert it at the head. The
|
|
|
|
* socketopt call can just insert new addresses in there as
|
|
|
|
* well. It will also have to do the embed scope kame hack
|
|
|
|
* too (before adding).
|
|
|
|
*/
|
2007-03-15 11:27:14 +00:00
|
|
|
struct sctp_ifa *ifa;
|
2014-09-07 09:06:26 +00:00
|
|
|
union sctp_sockstore store;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2014-09-07 09:06:26 +00:00
|
|
|
memset(&store, 0, sizeof(store));
|
2011-04-30 11:18:16 +00:00
|
|
|
switch (addr->sa_family) {
|
2012-07-15 11:04:49 +00:00
|
|
|
#ifdef INET
|
2011-04-30 11:18:16 +00:00
|
|
|
case AF_INET:
|
2014-09-07 09:06:26 +00:00
|
|
|
memcpy(&store.sin, addr, sizeof(struct sockaddr_in));
|
|
|
|
store.sin.sin_port = 0;
|
|
|
|
break;
|
2012-07-15 11:04:49 +00:00
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
2011-04-30 11:18:16 +00:00
|
|
|
case AF_INET6:
|
2014-09-07 09:06:26 +00:00
|
|
|
memcpy(&store.sin6, addr, sizeof(struct sockaddr_in6));
|
|
|
|
store.sin6.sin6_port = 0;
|
|
|
|
break;
|
2012-07-15 11:04:49 +00:00
|
|
|
#endif
|
2011-04-30 11:18:16 +00:00
|
|
|
default:
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* first find the interface with the bound address need to
|
|
|
|
* zero out the port to find the address! yuck! can't do
|
|
|
|
* this earlier since need port for sctp_pcb_findep()
|
|
|
|
*/
|
2012-09-09 08:14:04 +00:00
|
|
|
if (sctp_ifap != NULL) {
|
2007-07-24 20:06:02 +00:00
|
|
|
ifa = sctp_ifap;
|
2012-09-09 08:14:04 +00:00
|
|
|
} else {
|
2007-07-24 20:06:02 +00:00
|
|
|
/*
|
|
|
|
* Note for BSD we hit here always other O/S's will
|
|
|
|
* pass things in via the sctp_ifap argument
|
|
|
|
* (Panda).
|
|
|
|
*/
|
2014-09-07 09:06:26 +00:00
|
|
|
ifa = sctp_find_ifa_by_addr(&store.sa,
|
2007-09-08 17:48:46 +00:00
|
|
|
vrf_id, SCTP_ADDR_NOT_LOCKED);
|
2007-07-24 20:06:02 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if (ifa == NULL) {
|
|
|
|
/* Can't find an interface with that address */
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, EADDRNOTAVAIL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (EADDRNOTAVAIL);
|
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
#ifdef INET6
|
2006-11-03 15:23:16 +00:00
|
|
|
if (addr->sa_family == AF_INET6) {
|
2007-03-15 11:27:14 +00:00
|
|
|
/* GAK, more FIXME IFA lock? */
|
|
|
|
if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Can't bind a non-existent addr. */
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
/* we're not bound all */
|
|
|
|
inp->sctp_flags &= ~SCTP_PCB_FLAGS_BOUNDALL;
|
2007-05-17 12:16:24 +00:00
|
|
|
/* allow bindx() to send ASCONF's for binding changes */
|
2007-03-15 11:27:14 +00:00
|
|
|
sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_ASCONF);
|
2007-06-14 22:59:04 +00:00
|
|
|
/* clear automatic addr changes from kernel flag */
|
|
|
|
sctp_feature_off(inp, SCTP_PCB_FLAGS_AUTO_ASCONF);
|
2007-03-15 11:27:14 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/* add this address to the endpoint list */
|
2007-03-15 11:27:14 +00:00
|
|
|
error = sctp_insert_laddr(&inp->sctp_addr_list, ifa, 0);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (error != 0) {
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
inp->laddr_count++;
|
|
|
|
}
|
|
|
|
/* find the bucket */
|
2008-07-31 11:08:30 +00:00
|
|
|
if (port_reuse_active) {
|
|
|
|
/* Put it into tcp 1-2-1 hash */
|
2010-11-09 16:18:32 +00:00
|
|
|
head = &SCTP_BASE_INFO(sctp_tcpephash)[SCTP_PCBHASH_ALLADDR(lport, SCTP_BASE_INFO(hashtcpmark))];
|
2008-07-31 11:08:30 +00:00
|
|
|
inp->sctp_flags |= SCTP_PCB_FLAGS_IN_TCPPOOL;
|
|
|
|
} else {
|
2010-11-09 16:18:32 +00:00
|
|
|
head = &SCTP_BASE_INFO(sctp_ephash)[SCTP_PCBHASH_ALLADDR(lport, SCTP_BASE_INFO(hashmark))];
|
2008-07-31 11:08:30 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
/* put it in the bucket */
|
|
|
|
LIST_INSERT_HEAD(head, inp, sctp_hash);
|
2008-07-31 11:08:30 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB1, "Main hash to bind at head:%p, bound port:%d - in tcp_pool=%d\n",
|
2012-09-05 18:52:01 +00:00
|
|
|
(void *)head, ntohs(lport), port_reuse_active);
|
2006-11-03 15:23:16 +00:00
|
|
|
/* set in the port */
|
|
|
|
inp->sctp_lport = lport;
|
|
|
|
|
|
|
|
/* turn off just the unbound flag */
|
|
|
|
inp->sctp_flags &= ~SCTP_PCB_FLAGS_UNBOUND;
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2010-05-16 17:03:56 +00:00
|
|
|
sctp_iterator_inp_being_freed(struct sctp_inpcb *inp)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2010-05-16 17:03:56 +00:00
|
|
|
struct sctp_iterator *it, *nit;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We enter with the only the ITERATOR_LOCK in place and a write
|
|
|
|
* lock on the inp_info stuff.
|
|
|
|
*/
|
2010-05-16 17:03:56 +00:00
|
|
|
it = sctp_it_ctl.cur_it;
|
|
|
|
if (it && (it->vn != curvnet)) {
|
|
|
|
/* Its not looking at our VNET */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (it && (it->inp == inp)) {
|
|
|
|
/*
|
|
|
|
* This is tricky and we hold the iterator lock, but when it
|
|
|
|
* returns and gets the lock (when we release it) the
|
|
|
|
* iterator will try to operate on inp. We need to stop that
|
|
|
|
* from happening. But of course the iterator has a
|
|
|
|
* reference on the stcb and inp. We can mark it and it will
|
|
|
|
* stop.
|
|
|
|
*
|
|
|
|
* If its a single iterator situation, we set the end iterator
|
|
|
|
* flag. Otherwise we set the iterator to go to the next
|
|
|
|
* inp.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
if (it->iterator_flags & SCTP_ITERATOR_DO_SINGLE_INP) {
|
|
|
|
sctp_it_ctl.iterator_flags |= SCTP_ITERATOR_STOP_CUR_IT;
|
|
|
|
} else {
|
|
|
|
sctp_it_ctl.iterator_flags |= SCTP_ITERATOR_STOP_CUR_INP;
|
|
|
|
}
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
2010-05-16 17:03:56 +00:00
|
|
|
* Now go through and remove any single reference to our inp that
|
|
|
|
* may be still pending on the list
|
2006-11-03 15:23:16 +00:00
|
|
|
*/
|
2010-05-16 17:03:56 +00:00
|
|
|
SCTP_IPI_ITERATOR_WQ_LOCK();
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_FOREACH_SAFE(it, &sctp_it_ctl.iteratorhead, sctp_nxt_itr, nit) {
|
2010-05-16 17:03:56 +00:00
|
|
|
if (it->vn != curvnet) {
|
2006-11-03 15:23:16 +00:00
|
|
|
continue;
|
2010-05-16 17:03:56 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if (it->inp == inp) {
|
2010-05-16 17:03:56 +00:00
|
|
|
/* This one points to me is it inp specific? */
|
2006-11-03 15:23:16 +00:00
|
|
|
if (it->iterator_flags & SCTP_ITERATOR_DO_SINGLE_INP) {
|
2010-05-16 17:03:56 +00:00
|
|
|
/* Remove and free this one */
|
|
|
|
TAILQ_REMOVE(&sctp_it_ctl.iteratorhead,
|
|
|
|
it, sctp_nxt_itr);
|
|
|
|
if (it->function_atend != NULL) {
|
|
|
|
(*it->function_atend) (it->pointer, it->val);
|
|
|
|
}
|
|
|
|
SCTP_FREE(it, SCTP_M_ITER);
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2010-05-16 17:03:56 +00:00
|
|
|
it->inp = LIST_NEXT(it->inp, sctp_list);
|
2010-06-14 21:25:07 +00:00
|
|
|
if (it->inp) {
|
|
|
|
SCTP_INP_INCR_REF(it->inp);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2010-06-11 03:54:00 +00:00
|
|
|
/*
|
|
|
|
* When its put in the refcnt is incremented so decr
|
|
|
|
* it
|
|
|
|
*/
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-16 17:03:56 +00:00
|
|
|
SCTP_IPI_ITERATOR_WQ_UNLOCK();
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* release sctp_inpcb unbind the port */
|
|
|
|
void
|
|
|
|
sctp_inpcb_free(struct sctp_inpcb *inp, int immediate, int from)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Here we free a endpoint. We must find it (if it is in the Hash
|
|
|
|
* table) and remove it from there. Then we must also find it in the
|
|
|
|
* overall list and remove it from there. After all removals are
|
|
|
|
* complete then any timer has to be stopped. Then start the actual
|
|
|
|
* freeing. a) Any local lists. b) Any associations. c) The hash of
|
|
|
|
* all associations. d) finally the ep itself.
|
|
|
|
*/
|
|
|
|
struct sctp_tcb *asoc, *nasoc;
|
|
|
|
struct sctp_laddr *laddr, *nladdr;
|
|
|
|
struct inpcb *ip_pcb;
|
|
|
|
struct socket *so;
|
2010-06-06 20:34:17 +00:00
|
|
|
int being_refed = 0;
|
2010-12-30 16:56:20 +00:00
|
|
|
struct sctp_queued_to_read *sq, *nsq;
|
2007-01-18 09:58:43 +00:00
|
|
|
int cnt;
|
2010-12-30 16:56:20 +00:00
|
|
|
sctp_sharedkey_t *shared_key, *nshared_key;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef SCTP_LOG_CLOSING
|
|
|
|
sctp_log_closing(inp, NULL, 0);
|
|
|
|
#endif
|
2010-06-14 21:25:07 +00:00
|
|
|
SCTP_ITERATOR_LOCK();
|
|
|
|
/* mark any iterators on the list or being processed */
|
|
|
|
sctp_iterator_inp_being_freed(inp);
|
|
|
|
SCTP_ITERATOR_UNLOCK();
|
2010-06-06 02:33:46 +00:00
|
|
|
so = inp->sctp_socket;
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) {
|
|
|
|
/* been here before.. eeks.. get out of here */
|
|
|
|
SCTP_PRINTF("This conflict in free SHOULD not be happening! from %d, imm %d\n", from, immediate);
|
|
|
|
#ifdef SCTP_LOG_CLOSING
|
|
|
|
sctp_log_closing(inp, NULL, 1);
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SCTP_ASOC_CREATE_LOCK(inp);
|
|
|
|
SCTP_INP_INFO_WLOCK();
|
|
|
|
|
|
|
|
SCTP_INP_WLOCK(inp);
|
2010-06-09 16:42:42 +00:00
|
|
|
if (from == SCTP_CALLED_AFTER_CMPSET_OFCLOSE) {
|
|
|
|
inp->sctp_flags &= ~SCTP_PCB_FLAGS_CLOSE_IP;
|
|
|
|
/* socket is gone, so no more wakeups allowed */
|
|
|
|
inp->sctp_flags |= SCTP_PCB_FLAGS_DONT_WAKE;
|
|
|
|
inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEINPUT;
|
|
|
|
inp->sctp_flags &= ~SCTP_PCB_FLAGS_WAKEOUTPUT;
|
|
|
|
|
|
|
|
}
|
2010-06-06 02:33:46 +00:00
|
|
|
/* First time through we have the socket lock, after that no more. */
|
2006-12-14 17:02:55 +00:00
|
|
|
sctp_timer_stop(SCTP_TIMER_TYPE_NEWCOOKIE, inp, NULL, NULL,
|
|
|
|
SCTP_FROM_SCTP_PCB + SCTP_LOC_1);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
if (inp->control) {
|
|
|
|
sctp_m_freem(inp->control);
|
|
|
|
inp->control = NULL;
|
|
|
|
}
|
|
|
|
if (inp->pkt) {
|
|
|
|
sctp_m_freem(inp->pkt);
|
|
|
|
inp->pkt = NULL;
|
|
|
|
}
|
|
|
|
ip_pcb = &inp->ip_inp.inp; /* we could just cast the main pointer
|
|
|
|
* here but I will be nice :> (i.e.
|
|
|
|
* ip_pcb = ep;) */
|
2007-05-08 15:53:03 +00:00
|
|
|
if (immediate == SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE) {
|
2006-11-03 15:23:16 +00:00
|
|
|
int cnt_in_sd;
|
|
|
|
|
|
|
|
cnt_in_sd = 0;
|
2010-12-30 16:56:20 +00:00
|
|
|
LIST_FOREACH_SAFE(asoc, &inp->sctp_asoc_list, sctp_tcblist, nasoc) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_TCB_LOCK(asoc);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (asoc->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
|
|
|
|
/* Skip guys being freed */
|
|
|
|
cnt_in_sd++;
|
2010-06-05 21:17:23 +00:00
|
|
|
if (asoc->asoc.state & SCTP_STATE_IN_ACCEPT_QUEUE) {
|
|
|
|
/*
|
|
|
|
* Special case - we did not start a
|
|
|
|
* kill timer on the asoc due to it
|
|
|
|
* was not closed. So go ahead and
|
|
|
|
* start it now.
|
|
|
|
*/
|
|
|
|
asoc->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
|
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_ASOCKILL, inp, asoc, NULL);
|
|
|
|
}
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_TCB_UNLOCK(asoc);
|
2006-11-03 15:23:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
2009-04-04 11:43:32 +00:00
|
|
|
if (((SCTP_GET_STATE(&asoc->asoc) == SCTP_STATE_COOKIE_WAIT) ||
|
|
|
|
(SCTP_GET_STATE(&asoc->asoc) == SCTP_STATE_COOKIE_ECHOED)) &&
|
|
|
|
(asoc->asoc.total_output_queue_size == 0)) {
|
2007-06-17 19:27:46 +00:00
|
|
|
/*
|
|
|
|
* If we have data in queue, we don't want
|
|
|
|
* to just free since the app may have done,
|
|
|
|
* send()/close or connect/send/close. And
|
|
|
|
* it wants the data to get across first.
|
|
|
|
*/
|
2007-08-27 05:19:48 +00:00
|
|
|
/* Just abandon things in the front states */
|
|
|
|
if (sctp_free_assoc(inp, asoc, SCTP_PCBFREE_NOFORCE,
|
|
|
|
SCTP_FROM_SCTP_PCB + SCTP_LOC_2) == 0) {
|
|
|
|
cnt_in_sd++;
|
2007-06-17 19:27:46 +00:00
|
|
|
}
|
2007-08-27 05:19:48 +00:00
|
|
|
continue;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
/* Disconnect the socket please */
|
|
|
|
asoc->sctp_socket = NULL;
|
|
|
|
asoc->asoc.state |= SCTP_STATE_CLOSED_SOCKET;
|
|
|
|
if ((asoc->asoc.size_on_reasm_queue > 0) ||
|
|
|
|
(asoc->asoc.control_pdapi) ||
|
|
|
|
(asoc->asoc.size_on_all_streams > 0) ||
|
2014-12-02 20:29:29 +00:00
|
|
|
(so && (so->so_rcv.sb_cc > 0))) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Left with Data unread */
|
|
|
|
struct mbuf *op_err;
|
|
|
|
|
2014-03-16 12:32:16 +00:00
|
|
|
op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
|
2006-12-14 17:02:55 +00:00
|
|
|
asoc->sctp_ep->last_abort_code = SCTP_FROM_SCTP_PCB + SCTP_LOC_3;
|
2007-09-08 11:35:11 +00:00
|
|
|
sctp_send_abort_tcb(asoc, op_err, SCTP_SO_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_STAT_INCR_COUNTER32(sctps_aborted);
|
|
|
|
if ((SCTP_GET_STATE(&asoc->asoc) == SCTP_STATE_OPEN) ||
|
|
|
|
(SCTP_GET_STATE(&asoc->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
|
|
|
|
SCTP_STAT_DECR_GAUGE32(sctps_currestab);
|
|
|
|
}
|
2007-08-24 00:53:53 +00:00
|
|
|
if (sctp_free_assoc(inp, asoc,
|
|
|
|
SCTP_PCBFREE_NOFORCE, SCTP_FROM_SCTP_PCB + SCTP_LOC_4) == 0) {
|
|
|
|
cnt_in_sd++;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
continue;
|
|
|
|
} else if (TAILQ_EMPTY(&asoc->asoc.send_queue) &&
|
|
|
|
TAILQ_EMPTY(&asoc->asoc.sent_queue) &&
|
2012-09-23 07:43:10 +00:00
|
|
|
(asoc->asoc.stream_queue_cnt == 0)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
if (asoc->asoc.locked_on_sending) {
|
|
|
|
goto abort_anyway;
|
|
|
|
}
|
|
|
|
if ((SCTP_GET_STATE(&asoc->asoc) != SCTP_STATE_SHUTDOWN_SENT) &&
|
|
|
|
(SCTP_GET_STATE(&asoc->asoc) != SCTP_STATE_SHUTDOWN_ACK_SENT)) {
|
2011-08-03 20:21:00 +00:00
|
|
|
struct sctp_nets *netp;
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* there is nothing queued to send,
|
|
|
|
* so I send shutdown
|
|
|
|
*/
|
2007-02-12 23:24:31 +00:00
|
|
|
if ((SCTP_GET_STATE(&asoc->asoc) == SCTP_STATE_OPEN) ||
|
|
|
|
(SCTP_GET_STATE(&asoc->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
|
|
|
|
SCTP_STAT_DECR_GAUGE32(sctps_currestab);
|
|
|
|
}
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_SET_STATE(&asoc->asoc, SCTP_STATE_SHUTDOWN_SENT);
|
2007-10-16 14:05:51 +00:00
|
|
|
SCTP_CLEAR_SUBSTATE(&asoc->asoc, SCTP_STATE_SHUTDOWN_PENDING);
|
2013-02-09 08:27:08 +00:00
|
|
|
sctp_stop_timers_for_shutdown(asoc);
|
|
|
|
if (asoc->asoc.alternate) {
|
|
|
|
netp = asoc->asoc.alternate;
|
|
|
|
} else {
|
|
|
|
netp = asoc->asoc.primary_destination;
|
|
|
|
}
|
|
|
|
sctp_send_shutdown(asoc, netp);
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN, asoc->sctp_ep, asoc,
|
2011-08-03 20:21:00 +00:00
|
|
|
netp);
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, asoc->sctp_ep, asoc,
|
|
|
|
asoc->asoc.primary_destination);
|
2007-09-08 11:35:11 +00:00
|
|
|
sctp_chunk_output(inp, asoc, SCTP_OUTPUT_FROM_SHUT_TMR, SCTP_SO_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* mark into shutdown pending */
|
|
|
|
struct sctp_stream_queue_pending *sp;
|
|
|
|
|
|
|
|
asoc->asoc.state |= SCTP_STATE_SHUTDOWN_PENDING;
|
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD, asoc->sctp_ep, asoc,
|
|
|
|
asoc->asoc.primary_destination);
|
|
|
|
if (asoc->asoc.locked_on_sending) {
|
|
|
|
sp = TAILQ_LAST(&((asoc->asoc.locked_on_sending)->outqueue),
|
|
|
|
sctp_streamhead);
|
|
|
|
if (sp == NULL) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("Error, sp is NULL, locked on sending is %p strm:%d\n",
|
2012-09-05 18:52:01 +00:00
|
|
|
(void *)asoc->asoc.locked_on_sending,
|
2006-11-03 15:23:16 +00:00
|
|
|
asoc->asoc.locked_on_sending->stream_no);
|
|
|
|
} else {
|
|
|
|
if ((sp->length == 0) && (sp->msg_is_complete == 0))
|
|
|
|
asoc->asoc.state |= SCTP_STATE_PARTIAL_MSG_LEFT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (TAILQ_EMPTY(&asoc->asoc.send_queue) &&
|
|
|
|
TAILQ_EMPTY(&asoc->asoc.sent_queue) &&
|
|
|
|
(asoc->asoc.state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
|
|
|
|
struct mbuf *op_err;
|
|
|
|
|
|
|
|
abort_anyway:
|
2014-03-16 12:32:16 +00:00
|
|
|
op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
|
2006-12-14 17:02:55 +00:00
|
|
|
asoc->sctp_ep->last_abort_code = SCTP_FROM_SCTP_PCB + SCTP_LOC_5;
|
2007-09-08 11:35:11 +00:00
|
|
|
sctp_send_abort_tcb(asoc, op_err, SCTP_SO_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_STAT_INCR_COUNTER32(sctps_aborted);
|
|
|
|
if ((SCTP_GET_STATE(&asoc->asoc) == SCTP_STATE_OPEN) ||
|
|
|
|
(SCTP_GET_STATE(&asoc->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
|
|
|
|
SCTP_STAT_DECR_GAUGE32(sctps_currestab);
|
|
|
|
}
|
2007-08-24 00:53:53 +00:00
|
|
|
if (sctp_free_assoc(inp, asoc,
|
|
|
|
SCTP_PCBFREE_NOFORCE,
|
|
|
|
SCTP_FROM_SCTP_PCB + SCTP_LOC_6) == 0) {
|
|
|
|
cnt_in_sd++;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
continue;
|
2007-08-27 05:19:48 +00:00
|
|
|
} else {
|
2007-09-08 11:35:11 +00:00
|
|
|
sctp_chunk_output(inp, asoc, SCTP_OUTPUT_FROM_CLOSING, SCTP_SO_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
cnt_in_sd++;
|
|
|
|
SCTP_TCB_UNLOCK(asoc);
|
|
|
|
}
|
|
|
|
/* now is there some left in our SHUTDOWN state? */
|
|
|
|
if (cnt_in_sd) {
|
|
|
|
#ifdef SCTP_LOG_CLOSING
|
|
|
|
sctp_log_closing(inp, NULL, 2);
|
|
|
|
#endif
|
2008-08-27 13:13:35 +00:00
|
|
|
inp->sctp_socket = NULL;
|
2010-06-09 16:42:42 +00:00
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
SCTP_ASOC_CREATE_UNLOCK(inp);
|
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
2006-11-03 15:23:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inp->sctp_socket = NULL;
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) !=
|
|
|
|
SCTP_PCB_FLAGS_UNBOUND) {
|
|
|
|
/*
|
|
|
|
* ok, this guy has been bound. It's port is somewhere in
|
2008-06-14 07:58:05 +00:00
|
|
|
* the SCTP_BASE_INFO(hash table). Remove it!
|
2006-11-03 15:23:16 +00:00
|
|
|
*/
|
|
|
|
LIST_REMOVE(inp, sctp_hash);
|
|
|
|
inp->sctp_flags |= SCTP_PCB_FLAGS_UNBOUND;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If there is a timer running to kill us, forget it, since it may
|
|
|
|
* have a contest on the INP lock.. which would cause us to die ...
|
|
|
|
*/
|
|
|
|
cnt = 0;
|
2010-12-30 16:56:20 +00:00
|
|
|
LIST_FOREACH_SAFE(asoc, &inp->sctp_asoc_list, sctp_tcblist, nasoc) {
|
2010-11-13 12:52:44 +00:00
|
|
|
SCTP_TCB_LOCK(asoc);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (asoc->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
|
2010-06-06 16:09:12 +00:00
|
|
|
if (asoc->asoc.state & SCTP_STATE_IN_ACCEPT_QUEUE) {
|
|
|
|
asoc->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
|
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_ASOCKILL, inp, asoc, NULL);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
cnt++;
|
2010-11-13 12:52:44 +00:00
|
|
|
SCTP_TCB_UNLOCK(asoc);
|
2006-11-03 15:23:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Free associations that are NOT killing us */
|
|
|
|
if ((SCTP_GET_STATE(&asoc->asoc) != SCTP_STATE_COOKIE_WAIT) &&
|
|
|
|
((asoc->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) == 0)) {
|
|
|
|
struct mbuf *op_err;
|
|
|
|
|
2014-03-16 12:32:16 +00:00
|
|
|
op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
|
2006-12-14 17:02:55 +00:00
|
|
|
asoc->sctp_ep->last_abort_code = SCTP_FROM_SCTP_PCB + SCTP_LOC_7;
|
2007-09-08 11:35:11 +00:00
|
|
|
sctp_send_abort_tcb(asoc, op_err, SCTP_SO_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_STAT_INCR_COUNTER32(sctps_aborted);
|
|
|
|
} else if (asoc->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
|
|
|
|
cnt++;
|
|
|
|
SCTP_TCB_UNLOCK(asoc);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((SCTP_GET_STATE(&asoc->asoc) == SCTP_STATE_OPEN) ||
|
|
|
|
(SCTP_GET_STATE(&asoc->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
|
|
|
|
SCTP_STAT_DECR_GAUGE32(sctps_currestab);
|
|
|
|
}
|
2007-08-24 00:53:53 +00:00
|
|
|
if (sctp_free_assoc(inp, asoc, SCTP_PCBFREE_FORCE, SCTP_FROM_SCTP_PCB + SCTP_LOC_8) == 0) {
|
|
|
|
cnt++;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
if (cnt) {
|
|
|
|
/* Ok we have someone out there that will kill us */
|
2007-05-08 14:32:53 +00:00
|
|
|
(void)SCTP_OS_TIMER_STOP(&inp->sctp_ep.signature_change.timer);
|
2006-11-03 15:23:16 +00:00
|
|
|
#ifdef SCTP_LOG_CLOSING
|
|
|
|
sctp_log_closing(inp, NULL, 3);
|
|
|
|
#endif
|
2010-06-09 16:42:42 +00:00
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
SCTP_ASOC_CREATE_UNLOCK(inp);
|
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
2006-11-03 15:23:16 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-06 20:34:17 +00:00
|
|
|
if (SCTP_INP_LOCK_CONTENDED(inp))
|
|
|
|
being_refed++;
|
|
|
|
if (SCTP_INP_READ_CONTENDED(inp))
|
|
|
|
being_refed++;
|
|
|
|
if (SCTP_ASOC_CREATE_LOCK_CONTENDED(inp))
|
|
|
|
being_refed++;
|
|
|
|
|
2010-06-06 19:24:32 +00:00
|
|
|
if ((inp->refcount) ||
|
2010-06-06 20:34:17 +00:00
|
|
|
(being_refed) ||
|
|
|
|
(inp->sctp_flags & SCTP_PCB_FLAGS_CLOSE_IP)) {
|
2007-05-08 14:32:53 +00:00
|
|
|
(void)SCTP_OS_TIMER_STOP(&inp->sctp_ep.signature_change.timer);
|
2010-06-09 16:42:42 +00:00
|
|
|
#ifdef SCTP_LOG_CLOSING
|
|
|
|
sctp_log_closing(inp, NULL, 4);
|
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_INPKILL, inp, NULL, NULL);
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
SCTP_ASOC_CREATE_UNLOCK(inp);
|
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
inp->sctp_ep.signature_change.type = 0;
|
|
|
|
inp->sctp_flags |= SCTP_PCB_FLAGS_SOCKET_ALLGONE;
|
2010-06-09 16:42:42 +00:00
|
|
|
/*
|
|
|
|
* Remove it from the list .. last thing we need a lock for.
|
|
|
|
*/
|
|
|
|
LIST_REMOVE(inp, sctp_list);
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
SCTP_ASOC_CREATE_UNLOCK(inp);
|
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
|
|
|
/*
|
|
|
|
* Now we release all locks. Since this INP cannot be found anymore
|
2010-11-09 10:59:09 +00:00
|
|
|
* except possibly by the kill timer that might be running. We call
|
2010-06-09 16:42:42 +00:00
|
|
|
* the drain function here. It should hit the case were it sees the
|
|
|
|
* ACTIVE flag cleared and exit out freeing us to proceed and
|
|
|
|
* destroy everything.
|
|
|
|
*/
|
|
|
|
if (from != SCTP_CALLED_FROM_INPKILL_TIMER) {
|
|
|
|
(void)SCTP_OS_TIMER_STOP_DRAIN(&inp->sctp_ep.signature_change.timer);
|
|
|
|
} else {
|
|
|
|
/* Probably un-needed */
|
|
|
|
(void)SCTP_OS_TIMER_STOP(&inp->sctp_ep.signature_change.timer);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
#ifdef SCTP_LOG_CLOSING
|
|
|
|
sctp_log_closing(inp, NULL, 5);
|
|
|
|
#endif
|
|
|
|
|
2010-06-09 16:42:42 +00:00
|
|
|
|
2008-12-06 13:19:54 +00:00
|
|
|
if ((inp->sctp_asocidhash) != NULL) {
|
|
|
|
SCTP_HASH_FREE(inp->sctp_asocidhash, inp->hashasocidmark);
|
|
|
|
inp->sctp_asocidhash = NULL;
|
|
|
|
}
|
2007-05-17 12:16:24 +00:00
|
|
|
/* sa_ignore FREED_MEMORY */
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_FOREACH_SAFE(sq, &inp->read_queue, next, nsq) {
|
2007-04-19 11:28:43 +00:00
|
|
|
/* Its only abandoned if it had data left */
|
|
|
|
if (sq->length)
|
|
|
|
SCTP_STAT_INCR(sctps_left_abandon);
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
TAILQ_REMOVE(&inp->read_queue, sq, next);
|
|
|
|
sctp_free_remote_addr(sq->whoFrom);
|
|
|
|
if (so)
|
2014-12-02 20:29:29 +00:00
|
|
|
so->so_rcv.sb_cc -= sq->length;
|
2006-11-03 15:23:16 +00:00
|
|
|
if (sq->data) {
|
|
|
|
sctp_m_freem(sq->data);
|
|
|
|
sq->data = NULL;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* no need to free the net count, since at this point all
|
|
|
|
* assoc's are gone.
|
|
|
|
*/
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_readq), sq);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_DECR_READQ_COUNT();
|
|
|
|
}
|
|
|
|
/* Now the sctp_pcb things */
|
|
|
|
/*
|
|
|
|
* free each asoc if it is not already closed/free. we can't use the
|
|
|
|
* macro here since le_next will get freed as part of the
|
|
|
|
* sctp_free_assoc() call.
|
|
|
|
*/
|
|
|
|
if (so) {
|
2007-07-03 12:13:45 +00:00
|
|
|
#ifdef IPSEC
|
2008-11-27 10:43:08 +00:00
|
|
|
ipsec_delete_pcbpolicy(ip_pcb);
|
2007-07-03 12:13:45 +00:00
|
|
|
#endif /* IPSEC */
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/* Unlocks not needed since the socket is gone now */
|
|
|
|
}
|
|
|
|
if (ip_pcb->inp_options) {
|
|
|
|
(void)sctp_m_free(ip_pcb->inp_options);
|
|
|
|
ip_pcb->inp_options = 0;
|
|
|
|
}
|
|
|
|
#ifdef INET6
|
|
|
|
if (ip_pcb->inp_vflag & INP_IPV6) {
|
|
|
|
struct in6pcb *in6p;
|
|
|
|
|
|
|
|
in6p = (struct in6pcb *)inp;
|
|
|
|
ip6_freepcbopts(in6p->in6p_outputopts);
|
|
|
|
}
|
|
|
|
#endif /* INET6 */
|
|
|
|
ip_pcb->inp_vflag = 0;
|
|
|
|
/* free up authentication fields */
|
|
|
|
if (inp->sctp_ep.local_auth_chunks != NULL)
|
|
|
|
sctp_free_chunklist(inp->sctp_ep.local_auth_chunks);
|
|
|
|
if (inp->sctp_ep.local_hmacs != NULL)
|
|
|
|
sctp_free_hmaclist(inp->sctp_ep.local_hmacs);
|
|
|
|
|
2010-12-30 16:56:20 +00:00
|
|
|
LIST_FOREACH_SAFE(shared_key, &inp->sctp_ep.shared_keys, next, nshared_key) {
|
2006-11-03 15:23:16 +00:00
|
|
|
LIST_REMOVE(shared_key, next);
|
|
|
|
sctp_free_sharedkey(shared_key);
|
2007-05-17 12:16:24 +00:00
|
|
|
/* sa_ignore FREED_MEMORY */
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if we have an address list the following will free the list of
|
|
|
|
* ifaddr's that are set into this ep. Again macro limitations here,
|
|
|
|
* since the LIST_FOREACH could be a bad idea.
|
|
|
|
*/
|
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
|
|
|
sctp_remove_laddr(laddr);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2006-12-14 17:02:55 +00:00
|
|
|
|
|
|
|
#ifdef SCTP_TRACK_FREED_ASOCS
|
|
|
|
/* TEMP CODE */
|
2010-12-30 16:56:20 +00:00
|
|
|
LIST_FOREACH_SAFE(asoc, &inp->sctp_asoc_free_list, sctp_tcblist, nasoc) {
|
2006-12-14 17:02:55 +00:00
|
|
|
LIST_REMOVE(asoc, sctp_tcblist);
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_asoc), asoc);
|
2006-12-14 17:02:55 +00:00
|
|
|
SCTP_DECR_ASOC_COUNT();
|
|
|
|
}
|
|
|
|
/* *** END TEMP CODE *** */
|
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Now lets see about freeing the EP hash table. */
|
|
|
|
if (inp->sctp_tcbhash != NULL) {
|
2007-01-15 15:12:10 +00:00
|
|
|
SCTP_HASH_FREE(inp->sctp_tcbhash, inp->sctp_hashmark);
|
|
|
|
inp->sctp_tcbhash = NULL;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
/* Now we must put the ep memory back into the zone pool */
|
2014-06-20 13:26:49 +00:00
|
|
|
crfree(inp->ip_inp.inp.inp_cred);
|
2007-06-15 19:28:58 +00:00
|
|
|
INP_LOCK_DESTROY(&inp->ip_inp.inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_LOCK_DESTROY(inp);
|
|
|
|
SCTP_INP_READ_DESTROY(inp);
|
|
|
|
SCTP_ASOC_CREATE_LOCK_DESTROY(inp);
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_ep), inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_DECR_EP_COUNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct sctp_nets *
|
|
|
|
sctp_findnet(struct sctp_tcb *stcb, struct sockaddr *addr)
|
|
|
|
{
|
|
|
|
struct sctp_nets *net;
|
|
|
|
|
|
|
|
/* locate the address */
|
|
|
|
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
|
|
|
|
if (sctp_cmpaddr(addr, (struct sockaddr *)&net->ro._l_addr))
|
|
|
|
return (net);
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2007-03-15 11:27:14 +00:00
|
|
|
sctp_is_address_on_local_host(struct sockaddr *addr, uint32_t vrf_id)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2007-03-15 11:27:14 +00:00
|
|
|
struct sctp_ifa *sctp_ifa;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-09-08 17:48:46 +00:00
|
|
|
sctp_ifa = sctp_find_ifa_by_addr(addr, vrf_id, SCTP_ADDR_NOT_LOCKED);
|
2007-03-15 11:27:14 +00:00
|
|
|
if (sctp_ifa) {
|
|
|
|
return (1);
|
|
|
|
} else {
|
|
|
|
return (0);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
}
|
|
|
|
|
2007-05-09 13:30:06 +00:00
|
|
|
/*
|
|
|
|
* add's a remote endpoint address, done with the INIT/INIT-ACK as well as
|
|
|
|
* when a ASCONF arrives that adds it. It will also initialize all the cwnd
|
|
|
|
* stats of stuff.
|
|
|
|
*/
|
2006-11-03 15:23:16 +00:00
|
|
|
int
|
|
|
|
sctp_add_remote_addr(struct sctp_tcb *stcb, struct sockaddr *newaddr,
|
2011-08-03 20:21:00 +00:00
|
|
|
struct sctp_nets **netp, int set_scope, int from)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The following is redundant to the same lines in the
|
2010-11-09 16:18:32 +00:00
|
|
|
* sctp_aloc_assoc() but is needed since others call the add address
|
|
|
|
* function
|
2006-11-03 15:23:16 +00:00
|
|
|
*/
|
|
|
|
struct sctp_nets *net, *netfirst;
|
|
|
|
int addr_inscope;
|
|
|
|
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB1, "Adding an address (from:%d) to the peer: ",
|
|
|
|
from);
|
|
|
|
SCTPDBG_ADDR(SCTP_DEBUG_PCB1, newaddr);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
netfirst = sctp_findnet(stcb, newaddr);
|
|
|
|
if (netfirst) {
|
|
|
|
/*
|
|
|
|
* Lie and return ok, we don't want to make the association
|
|
|
|
* go away for this behavior. It will happen in the TCP
|
|
|
|
* model in a connected socket. It does not reach the hash
|
|
|
|
* table until after the association is built so it can't be
|
|
|
|
* found. Mark as reachable, since the initial creation will
|
|
|
|
* have been cleared and the NOT_IN_ASSOC flag will have
|
|
|
|
* been added... and we don't want to end up removing it
|
|
|
|
* back out.
|
|
|
|
*/
|
|
|
|
if (netfirst->dest_state & SCTP_ADDR_UNCONFIRMED) {
|
|
|
|
netfirst->dest_state = (SCTP_ADDR_REACHABLE |
|
|
|
|
SCTP_ADDR_UNCONFIRMED);
|
|
|
|
} else {
|
|
|
|
netfirst->dest_state = SCTP_ADDR_REACHABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
addr_inscope = 1;
|
2011-04-30 11:18:16 +00:00
|
|
|
switch (newaddr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
{
|
|
|
|
struct sockaddr_in *sin;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2011-04-30 11:18:16 +00:00
|
|
|
sin = (struct sockaddr_in *)newaddr;
|
|
|
|
if (sin->sin_addr.s_addr == 0) {
|
|
|
|
/* Invalid address */
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
/* zero out the bzero area */
|
|
|
|
memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2011-04-30 11:18:16 +00:00
|
|
|
/* assure len is set */
|
|
|
|
sin->sin_len = sizeof(struct sockaddr_in);
|
|
|
|
if (set_scope) {
|
2006-11-03 15:23:16 +00:00
|
|
|
#ifdef SCTP_DONT_DO_PRIVADDR_SCOPE
|
2013-10-28 20:32:37 +00:00
|
|
|
stcb->asoc.scope.ipv4_local_scope = 1;
|
2006-11-03 15:23:16 +00:00
|
|
|
#else
|
2011-04-30 11:18:16 +00:00
|
|
|
if (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) {
|
2013-02-09 17:26:14 +00:00
|
|
|
stcb->asoc.scope.ipv4_local_scope = 1;
|
2011-04-30 11:18:16 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
#endif /* SCTP_DONT_DO_PRIVADDR_SCOPE */
|
2011-04-30 11:18:16 +00:00
|
|
|
} else {
|
|
|
|
/* Validate the address is in scope */
|
|
|
|
if ((IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)) &&
|
2013-02-09 17:26:14 +00:00
|
|
|
(stcb->asoc.scope.ipv4_local_scope == 0)) {
|
2011-04-30 11:18:16 +00:00
|
|
|
addr_inscope = 0;
|
|
|
|
}
|
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
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
#endif
|
2008-05-20 13:47:46 +00:00
|
|
|
#ifdef INET6
|
2011-04-30 11:18:16 +00:00
|
|
|
case AF_INET6:
|
|
|
|
{
|
|
|
|
struct sockaddr_in6 *sin6;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2011-04-30 11:18:16 +00:00
|
|
|
sin6 = (struct sockaddr_in6 *)newaddr;
|
|
|
|
if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
|
|
|
|
/* Invalid address */
|
|
|
|
return (-1);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
/* assure len is set */
|
|
|
|
sin6->sin6_len = sizeof(struct sockaddr_in6);
|
|
|
|
if (set_scope) {
|
|
|
|
if (sctp_is_address_on_local_host(newaddr, stcb->asoc.vrf_id)) {
|
2013-02-09 17:26:14 +00:00
|
|
|
stcb->asoc.scope.loopback_scope = 1;
|
|
|
|
stcb->asoc.scope.local_scope = 0;
|
|
|
|
stcb->asoc.scope.ipv4_local_scope = 1;
|
|
|
|
stcb->asoc.scope.site_scope = 1;
|
2011-04-30 11:18:16 +00:00
|
|
|
} else if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
|
|
|
|
/*
|
|
|
|
* If the new destination is a
|
|
|
|
* LINK_LOCAL we must have common
|
|
|
|
* site scope. Don't set the local
|
|
|
|
* scope since we may not share all
|
|
|
|
* links, only loopback can do this.
|
|
|
|
* Links on the local network would
|
|
|
|
* also be on our private network
|
|
|
|
* for v4 too.
|
|
|
|
*/
|
2013-02-09 17:26:14 +00:00
|
|
|
stcb->asoc.scope.ipv4_local_scope = 1;
|
|
|
|
stcb->asoc.scope.site_scope = 1;
|
2011-04-30 11:18:16 +00:00
|
|
|
} else if (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)) {
|
|
|
|
/*
|
|
|
|
* If the new destination is
|
|
|
|
* SITE_LOCAL then we must have site
|
|
|
|
* scope in common.
|
|
|
|
*/
|
2013-02-09 17:26:14 +00:00
|
|
|
stcb->asoc.scope.site_scope = 1;
|
2011-04-30 11:18:16 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Validate the address is in scope */
|
|
|
|
if (IN6_IS_ADDR_LOOPBACK(&sin6->sin6_addr) &&
|
2013-02-09 17:26:14 +00:00
|
|
|
(stcb->asoc.scope.loopback_scope == 0)) {
|
2011-04-30 11:18:16 +00:00
|
|
|
addr_inscope = 0;
|
|
|
|
} else if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) &&
|
2013-02-09 17:26:14 +00:00
|
|
|
(stcb->asoc.scope.local_scope == 0)) {
|
2011-04-30 11:18:16 +00:00
|
|
|
addr_inscope = 0;
|
|
|
|
} else if (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr) &&
|
2013-02-09 17:26:14 +00:00
|
|
|
(stcb->asoc.scope.site_scope == 0)) {
|
2011-04-30 11:18:16 +00:00
|
|
|
addr_inscope = 0;
|
|
|
|
}
|
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
|
|
|
}
|
2008-05-20 13:47:46 +00:00
|
|
|
#endif
|
2011-04-30 11:18:16 +00:00
|
|
|
default:
|
2006-11-03 15:23:16 +00:00
|
|
|
/* not supported family type */
|
|
|
|
return (-1);
|
|
|
|
}
|
2008-06-14 07:58:05 +00:00
|
|
|
net = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_net), struct sctp_nets);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (net == NULL) {
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
SCTP_INCR_RADDR_COUNT();
|
2011-08-03 20:21:00 +00:00
|
|
|
bzero(net, sizeof(struct sctp_nets));
|
2007-05-08 14:32:53 +00:00
|
|
|
(void)SCTP_GETTIME_TIMEVAL(&net->start_time);
|
2006-11-03 15:23:16 +00:00
|
|
|
memcpy(&net->ro._l_addr, newaddr, newaddr->sa_len);
|
2011-04-30 11:18:16 +00:00
|
|
|
switch (newaddr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
2006-11-03 15:23:16 +00:00
|
|
|
((struct sockaddr_in *)&net->ro._l_addr)->sin_port = stcb->rport;
|
2011-04-30 11:18:16 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
2006-11-03 15:23:16 +00:00
|
|
|
((struct sockaddr_in6 *)&net->ro._l_addr)->sin6_port = stcb->rport;
|
2011-04-30 11:18:16 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
net->addr_is_local = sctp_is_address_on_local_host(newaddr, stcb->asoc.vrf_id);
|
|
|
|
if (net->addr_is_local && ((set_scope || (from == SCTP_ADDR_IS_CONFIRMED)))) {
|
2013-02-09 17:26:14 +00:00
|
|
|
stcb->asoc.scope.loopback_scope = 1;
|
|
|
|
stcb->asoc.scope.ipv4_local_scope = 1;
|
|
|
|
stcb->asoc.scope.local_scope = 0;
|
|
|
|
stcb->asoc.scope.site_scope = 1;
|
2007-03-15 11:27:14 +00:00
|
|
|
addr_inscope = 1;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
net->failure_threshold = stcb->asoc.def_net_failure;
|
2011-08-03 20:21:00 +00:00
|
|
|
net->pf_threshold = stcb->asoc.def_net_pf_threshold;
|
2006-11-03 15:23:16 +00:00
|
|
|
if (addr_inscope == 0) {
|
|
|
|
net->dest_state = (SCTP_ADDR_REACHABLE |
|
|
|
|
SCTP_ADDR_OUT_OF_SCOPE);
|
|
|
|
} else {
|
2006-12-14 17:02:55 +00:00
|
|
|
if (from == SCTP_ADDR_IS_CONFIRMED)
|
|
|
|
/* SCTP_ADDR_IS_CONFIRMED is passed by connect_x */
|
2006-11-03 15:23:16 +00:00
|
|
|
net->dest_state = SCTP_ADDR_REACHABLE;
|
|
|
|
else
|
|
|
|
net->dest_state = SCTP_ADDR_REACHABLE |
|
|
|
|
SCTP_ADDR_UNCONFIRMED;
|
|
|
|
}
|
2007-06-08 10:57:11 +00:00
|
|
|
/*
|
|
|
|
* We set this to 0, the timer code knows that this means its an
|
|
|
|
* initial value
|
|
|
|
*/
|
2011-03-08 11:58:25 +00:00
|
|
|
net->rto_needed = 1;
|
2007-06-08 10:57:11 +00:00
|
|
|
net->RTO = 0;
|
2007-06-13 01:31:53 +00:00
|
|
|
net->RTO_measured = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
stcb->asoc.numnets++;
|
2011-11-20 15:00:45 +00:00
|
|
|
net->ref_count = 1;
|
2011-01-29 19:55:29 +00:00
|
|
|
net->cwr_window_tsn = net->last_cwr_tsn = stcb->asoc.sending_seq - 1;
|
2011-11-20 15:00:45 +00:00
|
|
|
net->port = stcb->asoc.port;
|
2011-08-14 20:55:32 +00:00
|
|
|
net->dscp = stcb->asoc.default_dscp;
|
2011-09-14 08:15:21 +00:00
|
|
|
#ifdef INET6
|
2011-08-14 20:55:32 +00:00
|
|
|
net->flowlabel = stcb->asoc.default_flowlabel;
|
2011-09-14 08:15:21 +00:00
|
|
|
#endif
|
2011-09-17 08:50:29 +00:00
|
|
|
if (sctp_stcb_is_feature_on(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_DONOT_HEARTBEAT)) {
|
2011-08-03 20:21:00 +00:00
|
|
|
net->dest_state |= SCTP_ADDR_NOHB;
|
|
|
|
} else {
|
|
|
|
net->dest_state &= ~SCTP_ADDR_NOHB;
|
|
|
|
}
|
2011-09-17 08:50:29 +00:00
|
|
|
if (sctp_stcb_is_feature_on(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD)) {
|
|
|
|
net->dest_state |= SCTP_ADDR_NO_PMTUD;
|
|
|
|
} else {
|
|
|
|
net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
|
|
|
|
}
|
2011-08-03 20:21:00 +00:00
|
|
|
net->heart_beat_delay = stcb->asoc.heart_beat_delay;
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Init the timer structure */
|
2006-12-29 20:21:42 +00:00
|
|
|
SCTP_OS_TIMER_INIT(&net->rxt_timer.timer);
|
|
|
|
SCTP_OS_TIMER_INIT(&net->pmtu_timer.timer);
|
2011-08-03 20:21:00 +00:00
|
|
|
SCTP_OS_TIMER_INIT(&net->hb_timer.timer);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/* Now generate a route for this guy */
|
2008-04-16 17:24:18 +00:00
|
|
|
#ifdef INET6
|
2006-11-03 15:23:16 +00:00
|
|
|
/* KAME hack: embed scopeid */
|
|
|
|
if (newaddr->sa_family == AF_INET6) {
|
|
|
|
struct sockaddr_in6 *sin6;
|
|
|
|
|
|
|
|
sin6 = (struct sockaddr_in6 *)&net->ro._l_addr;
|
2009-09-17 15:11:12 +00:00
|
|
|
(void)sa6_embedscope(sin6, MODULE_GLOBAL(ip6_use_defzone));
|
2006-11-03 15:23:16 +00:00
|
|
|
sin6->sin6_scope_id = 0;
|
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
#endif
|
2007-06-01 11:19:54 +00:00
|
|
|
SCTP_RTALLOC((sctp_route_t *) & net->ro, stcb->asoc.vrf_id);
|
2007-04-03 11:15:32 +00:00
|
|
|
|
2007-05-08 00:21:05 +00:00
|
|
|
if (SCTP_ROUTE_HAS_VALID_IFN(&net->ro)) {
|
|
|
|
/* Get source address */
|
|
|
|
net->ro._s_addr = sctp_source_address_selection(stcb->sctp_ep,
|
|
|
|
stcb,
|
|
|
|
(sctp_route_t *) & net->ro,
|
|
|
|
net,
|
|
|
|
0,
|
|
|
|
stcb->asoc.vrf_id);
|
2014-07-11 17:31:40 +00:00
|
|
|
if (net->ro._s_addr != NULL) {
|
|
|
|
net->src_addr_selected = 1;
|
|
|
|
/* Now get the interface MTU */
|
|
|
|
if (net->ro._s_addr->ifn_p != NULL) {
|
|
|
|
net->mtu = SCTP_GATHER_MTU_FROM_INTFC(net->ro._s_addr->ifn_p);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
net->src_addr_selected = 0;
|
2007-05-08 00:21:05 +00:00
|
|
|
}
|
2011-11-15 20:41:50 +00:00
|
|
|
if (net->mtu > 0) {
|
2007-05-08 00:21:05 +00:00
|
|
|
uint32_t rmtu;
|
|
|
|
|
|
|
|
rmtu = SCTP_GATHER_MTU_FROM_ROUTE(net->ro._s_addr, &net->ro._l_addr.sa, net->ro.ro_rt);
|
|
|
|
if (rmtu == 0) {
|
|
|
|
/*
|
|
|
|
* Start things off to match mtu of
|
|
|
|
* interface please.
|
|
|
|
*/
|
|
|
|
SCTP_SET_MTU_OF_ROUTE(&net->ro._l_addr.sa,
|
|
|
|
net->ro.ro_rt, net->mtu);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* we take the route mtu over the interface,
|
|
|
|
* since the route may be leading out the
|
|
|
|
* loopback, or a different interface.
|
|
|
|
*/
|
|
|
|
net->mtu = rmtu;
|
|
|
|
}
|
|
|
|
}
|
2014-07-11 17:31:40 +00:00
|
|
|
} else {
|
|
|
|
net->src_addr_selected = 0;
|
2011-11-15 20:41:50 +00:00
|
|
|
}
|
|
|
|
if (net->mtu == 0) {
|
|
|
|
switch (newaddr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
net->mtu = SCTP_DEFAULT_MTU;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
net->mtu = 1280;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2011-11-15 20:41:50 +00:00
|
|
|
}
|
2014-07-11 06:52:48 +00:00
|
|
|
#if defined(INET) || defined(INET6)
|
2011-11-15 20:41:50 +00:00
|
|
|
if (net->port) {
|
|
|
|
net->mtu -= (uint32_t) sizeof(struct udphdr);
|
|
|
|
}
|
2014-07-11 06:52:48 +00:00
|
|
|
#endif
|
2011-11-15 20:41:50 +00:00
|
|
|
if (from == SCTP_ALLOC_ASOC) {
|
|
|
|
stcb->asoc.smallest_mtu = net->mtu;
|
|
|
|
}
|
|
|
|
if (stcb->asoc.smallest_mtu > net->mtu) {
|
|
|
|
stcb->asoc.smallest_mtu = net->mtu;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2008-05-20 13:47:46 +00:00
|
|
|
#ifdef INET6
|
|
|
|
if (newaddr->sa_family == AF_INET6) {
|
|
|
|
struct sockaddr_in6 *sin6;
|
|
|
|
|
|
|
|
sin6 = (struct sockaddr_in6 *)&net->ro._l_addr;
|
|
|
|
(void)sa6_recoverscope(sin6);
|
|
|
|
}
|
|
|
|
#endif
|
2011-11-15 20:41:50 +00:00
|
|
|
|
2007-07-14 09:36:28 +00:00
|
|
|
/* JRS - Use the congestion control given in the CC module */
|
2011-02-26 15:23:46 +00:00
|
|
|
if (stcb->asoc.cc_functions.sctp_set_initial_cc_param != NULL)
|
|
|
|
(*stcb->asoc.cc_functions.sctp_set_initial_cc_param) (stcb, net);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* CMT: CUC algo - set find_pseudo_cumack to TRUE (1) at beginning
|
|
|
|
* of assoc (2005/06/27, iyengar@cis.udel.edu)
|
|
|
|
*/
|
|
|
|
net->find_pseudo_cumack = 1;
|
|
|
|
net->find_rtx_pseudo_cumack = 1;
|
2011-02-07 15:04:23 +00:00
|
|
|
/* Choose an initial flowid. */
|
|
|
|
net->flowid = stcb->asoc.my_vtag ^
|
|
|
|
ntohs(stcb->rport) ^
|
|
|
|
ntohs(stcb->sctp_ep->sctp_lport);
|
2014-12-04 21:17:50 +00:00
|
|
|
net->flowtype = M_HASHTYPE_OPAQUE;
|
2011-10-27 22:38:48 +00:00
|
|
|
if (netp) {
|
|
|
|
*netp = net;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
netfirst = TAILQ_FIRST(&stcb->asoc.nets);
|
|
|
|
if (net->ro.ro_rt == NULL) {
|
|
|
|
/* Since we have no route put it at the back */
|
|
|
|
TAILQ_INSERT_TAIL(&stcb->asoc.nets, net, sctp_next);
|
|
|
|
} else if (netfirst == NULL) {
|
|
|
|
/* We are the first one in the pool. */
|
|
|
|
TAILQ_INSERT_HEAD(&stcb->asoc.nets, net, sctp_next);
|
|
|
|
} else if (netfirst->ro.ro_rt == NULL) {
|
|
|
|
/*
|
|
|
|
* First one has NO route. Place this one ahead of the first
|
|
|
|
* one.
|
|
|
|
*/
|
|
|
|
TAILQ_INSERT_HEAD(&stcb->asoc.nets, net, sctp_next);
|
|
|
|
} else if (net->ro.ro_rt->rt_ifp != netfirst->ro.ro_rt->rt_ifp) {
|
|
|
|
/*
|
|
|
|
* This one has a different interface than the one at the
|
|
|
|
* top of the list. Place it ahead.
|
|
|
|
*/
|
|
|
|
TAILQ_INSERT_HEAD(&stcb->asoc.nets, net, sctp_next);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Ok we have the same interface as the first one. Move
|
|
|
|
* forward until we find either a) one with a NULL route...
|
|
|
|
* insert ahead of that b) one with a different ifp.. insert
|
|
|
|
* after that. c) end of the list.. insert at the tail.
|
|
|
|
*/
|
|
|
|
struct sctp_nets *netlook;
|
|
|
|
|
|
|
|
do {
|
|
|
|
netlook = TAILQ_NEXT(netfirst, sctp_next);
|
|
|
|
if (netlook == NULL) {
|
|
|
|
/* End of the list */
|
2007-04-03 11:15:32 +00:00
|
|
|
TAILQ_INSERT_TAIL(&stcb->asoc.nets, net, sctp_next);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
} else if (netlook->ro.ro_rt == NULL) {
|
|
|
|
/* next one has NO route */
|
|
|
|
TAILQ_INSERT_BEFORE(netfirst, net, sctp_next);
|
|
|
|
break;
|
2007-04-03 11:15:32 +00:00
|
|
|
} else if (netlook->ro.ro_rt->rt_ifp != net->ro.ro_rt->rt_ifp) {
|
2006-11-03 15:23:16 +00:00
|
|
|
TAILQ_INSERT_AFTER(&stcb->asoc.nets, netlook,
|
|
|
|
net, sctp_next);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Shift forward */
|
|
|
|
netfirst = netlook;
|
|
|
|
} while (netlook != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* got to have a primary set */
|
|
|
|
if (stcb->asoc.primary_destination == 0) {
|
|
|
|
stcb->asoc.primary_destination = net;
|
|
|
|
} else if ((stcb->asoc.primary_destination->ro.ro_rt == NULL) &&
|
|
|
|
(net->ro.ro_rt) &&
|
|
|
|
((net->dest_state & SCTP_ADDR_UNCONFIRMED) == 0)) {
|
|
|
|
/* No route to current primary adopt new primary */
|
|
|
|
stcb->asoc.primary_destination = net;
|
|
|
|
}
|
|
|
|
/* Validate primary is first */
|
|
|
|
net = TAILQ_FIRST(&stcb->asoc.nets);
|
|
|
|
if ((net != stcb->asoc.primary_destination) &&
|
|
|
|
(stcb->asoc.primary_destination)) {
|
|
|
|
/*
|
|
|
|
* first one on the list is NOT the primary sctp_cmpaddr()
|
2010-11-09 10:59:09 +00:00
|
|
|
* is much more efficient if the primary is the first on the
|
2006-11-03 15:23:16 +00:00
|
|
|
* list, make it so.
|
|
|
|
*/
|
|
|
|
TAILQ_REMOVE(&stcb->asoc.nets,
|
|
|
|
stcb->asoc.primary_destination, sctp_next);
|
|
|
|
TAILQ_INSERT_HEAD(&stcb->asoc.nets,
|
|
|
|
stcb->asoc.primary_destination, sctp_next);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-06 13:19:54 +00:00
|
|
|
static uint32_t
|
|
|
|
sctp_aloc_a_assoc_id(struct sctp_inpcb *inp, struct sctp_tcb *stcb)
|
|
|
|
{
|
|
|
|
uint32_t id;
|
|
|
|
struct sctpasochead *head;
|
|
|
|
struct sctp_tcb *lstcb;
|
|
|
|
|
2009-09-13 17:45:31 +00:00
|
|
|
SCTP_INP_WLOCK(inp);
|
2008-12-06 13:19:54 +00:00
|
|
|
try_again:
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) {
|
|
|
|
/* TSNH */
|
2009-09-13 17:45:31 +00:00
|
|
|
SCTP_INP_WUNLOCK(inp);
|
2008-12-06 13:19:54 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2009-09-13 17:45:31 +00:00
|
|
|
/*
|
2011-06-15 23:50:27 +00:00
|
|
|
* We don't allow assoc id to be one of SCTP_FUTURE_ASSOC,
|
|
|
|
* SCTP_CURRENT_ASSOC and SCTP_ALL_ASSOC.
|
2009-09-13 17:45:31 +00:00
|
|
|
*/
|
2011-06-15 23:50:27 +00:00
|
|
|
if (inp->sctp_associd_counter <= SCTP_ALL_ASSOC) {
|
|
|
|
inp->sctp_associd_counter = SCTP_ALL_ASSOC + 1;
|
2009-09-13 17:45:31 +00:00
|
|
|
}
|
2008-12-06 13:19:54 +00:00
|
|
|
id = inp->sctp_associd_counter;
|
|
|
|
inp->sctp_associd_counter++;
|
|
|
|
lstcb = sctp_findasoc_ep_asocid_locked(inp, (sctp_assoc_t) id, 0);
|
|
|
|
if (lstcb) {
|
|
|
|
goto try_again;
|
|
|
|
}
|
|
|
|
head = &inp->sctp_asocidhash[SCTP_PCBHASH_ASOC(id, inp->hashasocidmark)];
|
|
|
|
LIST_INSERT_HEAD(head, stcb, sctp_tcbasocidhash);
|
|
|
|
stcb->asoc.in_asocid_hash = 1;
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* allocate an association and add it to the endpoint. The caller must be
|
|
|
|
* careful to add all additional addresses once they are know right away or
|
|
|
|
* else the assoc will be may experience a blackout scenario.
|
|
|
|
*/
|
|
|
|
struct sctp_tcb *
|
|
|
|
sctp_aloc_assoc(struct sctp_inpcb *inp, struct sockaddr *firstaddr,
|
2010-04-03 15:40:14 +00:00
|
|
|
int *error, uint32_t override_tag, uint32_t vrf_id,
|
2007-07-21 21:41:32 +00:00
|
|
|
struct thread *p
|
|
|
|
)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2007-07-21 21:41:32 +00:00
|
|
|
/* note the p argument is only valid in unbound sockets */
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_tcb *stcb;
|
|
|
|
struct sctp_association *asoc;
|
|
|
|
struct sctpasochead *head;
|
|
|
|
uint16_t rport;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Assumption made here: Caller has done a
|
|
|
|
* sctp_findassociation_ep_addr(ep, addr's); to make sure the
|
|
|
|
* address does not exist already.
|
|
|
|
*/
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_INFO(ipi_count_asoc) >= SCTP_MAX_NUM_OF_ASOC) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Hit max assoc, sorry no more */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, ENOBUFS);
|
2006-11-03 15:23:16 +00:00
|
|
|
*error = ENOBUFS;
|
|
|
|
return (NULL);
|
|
|
|
}
|
2007-05-09 13:30:06 +00:00
|
|
|
if (firstaddr == NULL) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, EINVAL);
|
2007-05-09 13:30:06 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
return (NULL);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_RLOCK(inp);
|
2008-07-31 11:08:30 +00:00
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) &&
|
|
|
|
((sctp_is_feature_off(inp, SCTP_PCB_FLAGS_PORTREUSE)) ||
|
|
|
|
(inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED))) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* If its in the TCP pool, its NOT allowed to create an
|
|
|
|
* association. The parent listener needs to call
|
|
|
|
* sctp_aloc_assoc.. or the one-2-many socket. If a peeled
|
|
|
|
* off, or connected one does this.. its an error.
|
|
|
|
*/
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
return (NULL);
|
|
|
|
}
|
2011-09-14 19:10:13 +00:00
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
|
|
|
|
(inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE)) {
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_WAS_CONNECTED) ||
|
|
|
|
(inp->sctp_flags & SCTP_PCB_FLAGS_WAS_ABORTED)) {
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, EINVAL);
|
|
|
|
*error = EINVAL;
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
}
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB3, "Allocate an association for peer:");
|
2006-11-03 15:23:16 +00:00
|
|
|
#ifdef SCTP_DEBUG
|
2007-05-09 13:30:06 +00:00
|
|
|
if (firstaddr) {
|
|
|
|
SCTPDBG_ADDR(SCTP_DEBUG_PCB3, firstaddr);
|
2011-04-30 11:18:16 +00:00
|
|
|
switch (firstaddr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
SCTPDBG(SCTP_DEBUG_PCB3, "Port:%d\n",
|
|
|
|
ntohs(((struct sockaddr_in *)firstaddr)->sin_port));
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
SCTPDBG(SCTP_DEBUG_PCB3, "Port:%d\n",
|
|
|
|
ntohs(((struct sockaddr_in6 *)firstaddr)->sin6_port));
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2007-05-09 13:30:06 +00:00
|
|
|
} else {
|
|
|
|
SCTPDBG(SCTP_DEBUG_PCB3, "None\n");
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
#endif /* SCTP_DEBUG */
|
2011-04-30 11:18:16 +00:00
|
|
|
switch (firstaddr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
{
|
|
|
|
struct sockaddr_in *sin;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2011-04-30 11:18:16 +00:00
|
|
|
sin = (struct sockaddr_in *)firstaddr;
|
2011-09-15 08:49:54 +00:00
|
|
|
if ((ntohs(sin->sin_port) == 0) ||
|
|
|
|
(sin->sin_addr.s_addr == INADDR_ANY) ||
|
|
|
|
(sin->sin_addr.s_addr == INADDR_BROADCAST) ||
|
|
|
|
IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) {
|
2011-04-30 11:18:16 +00:00
|
|
|
/* Invalid address */
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, EINVAL);
|
|
|
|
*error = EINVAL;
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
rport = sin->sin_port;
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
{
|
|
|
|
struct sockaddr_in6 *sin6;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2011-04-30 11:18:16 +00:00
|
|
|
sin6 = (struct sockaddr_in6 *)firstaddr;
|
2011-09-15 08:49:54 +00:00
|
|
|
if ((ntohs(sin6->sin6_port) == 0) ||
|
|
|
|
IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr) ||
|
|
|
|
IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
|
2011-04-30 11:18:16 +00:00
|
|
|
/* Invalid address */
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, EINVAL);
|
|
|
|
*error = EINVAL;
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
rport = sin6->sin6_port;
|
|
|
|
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
|
|
|
/* not supported family type */
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
|
|
|
|
/*
|
|
|
|
* If you have not performed a bind, then we need to do the
|
2010-11-09 10:59:09 +00:00
|
|
|
* ephemeral bind for you.
|
2006-11-03 15:23:16 +00:00
|
|
|
*/
|
|
|
|
if ((err = sctp_inpcb_bind(inp->sctp_socket,
|
2007-07-17 20:58:26 +00:00
|
|
|
(struct sockaddr *)NULL,
|
2007-07-24 20:06:02 +00:00
|
|
|
(struct sctp_ifa *)NULL,
|
2007-07-21 21:41:32 +00:00
|
|
|
p
|
2006-11-03 15:23:16 +00:00
|
|
|
))) {
|
|
|
|
/* bind error, probably perm */
|
|
|
|
*error = err;
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
}
|
2008-06-14 07:58:05 +00:00
|
|
|
stcb = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_asoc), struct sctp_tcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb == NULL) {
|
|
|
|
/* out of memory? */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, ENOMEM);
|
2006-11-03 15:23:16 +00:00
|
|
|
*error = ENOMEM;
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
SCTP_INCR_ASOC_COUNT();
|
|
|
|
|
|
|
|
bzero(stcb, sizeof(*stcb));
|
|
|
|
asoc = &stcb->asoc;
|
2008-12-06 13:19:54 +00:00
|
|
|
|
|
|
|
asoc->assoc_id = sctp_aloc_a_assoc_id(inp, stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_TCB_LOCK_INIT(stcb);
|
|
|
|
SCTP_TCB_SEND_LOCK_INIT(stcb);
|
2008-12-06 13:19:54 +00:00
|
|
|
stcb->rport = rport;
|
2006-11-03 15:23:16 +00:00
|
|
|
/* setup back pointer's */
|
|
|
|
stcb->sctp_ep = inp;
|
|
|
|
stcb->sctp_socket = inp->sctp_socket;
|
2010-04-03 15:40:14 +00:00
|
|
|
if ((err = sctp_init_asoc(inp, stcb, override_tag, vrf_id))) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* failed */
|
|
|
|
SCTP_TCB_LOCK_DESTROY(stcb);
|
|
|
|
SCTP_TCB_SEND_LOCK_DESTROY(stcb);
|
2008-12-06 13:19:54 +00:00
|
|
|
LIST_REMOVE(stcb, sctp_tcbasocidhash);
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_asoc), stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_DECR_ASOC_COUNT();
|
|
|
|
*error = err;
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
/* and the port */
|
|
|
|
SCTP_INP_INFO_WLOCK();
|
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
if (inp->sctp_flags & (SCTP_PCB_FLAGS_SOCKET_GONE | SCTP_PCB_FLAGS_SOCKET_ALLGONE)) {
|
|
|
|
/* inpcb freed while alloc going on */
|
|
|
|
SCTP_TCB_LOCK_DESTROY(stcb);
|
|
|
|
SCTP_TCB_SEND_LOCK_DESTROY(stcb);
|
2008-12-06 13:19:54 +00:00
|
|
|
LIST_REMOVE(stcb, sctp_tcbasocidhash);
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_asoc), stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
|
|
|
SCTP_DECR_ASOC_COUNT();
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
SCTP_TCB_LOCK(stcb);
|
|
|
|
|
|
|
|
/* now that my_vtag is set, add it to the hash */
|
2008-12-06 13:19:54 +00:00
|
|
|
head = &SCTP_BASE_INFO(sctp_asochash)[SCTP_PCBHASH_ASOC(stcb->asoc.my_vtag, SCTP_BASE_INFO(hashasocmark))];
|
2006-11-03 15:23:16 +00:00
|
|
|
/* put it in the bucket in the vtag hash of assoc's for the system */
|
|
|
|
LIST_INSERT_HEAD(head, stcb, sctp_asocs);
|
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
|
|
|
|
2011-08-03 20:21:00 +00:00
|
|
|
if ((err = sctp_add_remote_addr(stcb, firstaddr, NULL, SCTP_DO_SETSCOPE, SCTP_ALLOC_ASOC))) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* failure.. memory error? */
|
2007-05-29 09:29:03 +00:00
|
|
|
if (asoc->strmout) {
|
|
|
|
SCTP_FREE(asoc->strmout, SCTP_M_STRMO);
|
|
|
|
asoc->strmout = NULL;
|
|
|
|
}
|
|
|
|
if (asoc->mapping_array) {
|
|
|
|
SCTP_FREE(asoc->mapping_array, SCTP_M_MAP);
|
|
|
|
asoc->mapping_array = NULL;
|
|
|
|
}
|
2009-05-30 10:56:27 +00:00
|
|
|
if (asoc->nr_mapping_array) {
|
|
|
|
SCTP_FREE(asoc->nr_mapping_array, SCTP_M_MAP);
|
|
|
|
asoc->nr_mapping_array = NULL;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_DECR_ASOC_COUNT();
|
2013-11-03 14:00:17 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_TCB_LOCK_DESTROY(stcb);
|
|
|
|
SCTP_TCB_SEND_LOCK_DESTROY(stcb);
|
2008-12-06 13:19:54 +00:00
|
|
|
LIST_REMOVE(stcb, sctp_tcbasocidhash);
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_asoc), stcb);
|
2007-04-03 11:15:32 +00:00
|
|
|
SCTP_INP_WUNLOCK(inp);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PCB, ENOBUFS);
|
2006-11-03 15:23:16 +00:00
|
|
|
*error = ENOBUFS;
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
/* Init all the timers */
|
2006-12-29 20:21:42 +00:00
|
|
|
SCTP_OS_TIMER_INIT(&asoc->dack_timer.timer);
|
|
|
|
SCTP_OS_TIMER_INIT(&asoc->strreset_timer.timer);
|
|
|
|
SCTP_OS_TIMER_INIT(&asoc->asconf_timer.timer);
|
|
|
|
SCTP_OS_TIMER_INIT(&asoc->shut_guard_timer.timer);
|
|
|
|
SCTP_OS_TIMER_INIT(&asoc->autoclose_timer.timer);
|
|
|
|
SCTP_OS_TIMER_INIT(&asoc->delayed_event_timer.timer);
|
2007-09-08 17:48:46 +00:00
|
|
|
SCTP_OS_TIMER_INIT(&asoc->delete_prim_timer.timer);
|
2006-12-29 20:21:42 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
LIST_INSERT_HEAD(&inp->sctp_asoc_list, stcb, sctp_tcblist);
|
|
|
|
/* now file the port under the hash as well */
|
|
|
|
if (inp->sctp_tcbhash != NULL) {
|
|
|
|
head = &inp->sctp_tcbhash[SCTP_PCBHASH_ALLADDR(stcb->rport,
|
|
|
|
inp->sctp_hashmark)];
|
|
|
|
LIST_INSERT_HEAD(head, stcb, sctp_tcbhash);
|
|
|
|
}
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
2012-09-05 18:52:01 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB1, "Association %p now allocated\n", (void *)stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (stcb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_remove_net(struct sctp_tcb *stcb, struct sctp_nets *net)
|
|
|
|
{
|
|
|
|
struct sctp_association *asoc;
|
|
|
|
|
|
|
|
asoc = &stcb->asoc;
|
|
|
|
asoc->numnets--;
|
|
|
|
TAILQ_REMOVE(&asoc->nets, net, sctp_next);
|
|
|
|
if (net == asoc->primary_destination) {
|
|
|
|
/* Reset primary */
|
|
|
|
struct sctp_nets *lnet;
|
|
|
|
|
|
|
|
lnet = TAILQ_FIRST(&asoc->nets);
|
2007-09-08 17:48:46 +00:00
|
|
|
/*
|
|
|
|
* Mobility adaptation Ideally, if deleted destination is
|
|
|
|
* the primary, it becomes a fast retransmission trigger by
|
|
|
|
* the subsequent SET PRIMARY. (by micchie)
|
|
|
|
*/
|
|
|
|
if (sctp_is_mobility_feature_on(stcb->sctp_ep,
|
2007-10-16 14:05:51 +00:00
|
|
|
SCTP_MOBILITY_BASE) ||
|
|
|
|
sctp_is_mobility_feature_on(stcb->sctp_ep,
|
2007-09-08 17:48:46 +00:00
|
|
|
SCTP_MOBILITY_FASTHANDOFF)) {
|
|
|
|
SCTPDBG(SCTP_DEBUG_ASCONF1, "remove_net: primary dst is deleting\n");
|
|
|
|
if (asoc->deleted_primary != NULL) {
|
|
|
|
SCTPDBG(SCTP_DEBUG_ASCONF1, "remove_net: deleted primary may be already stored\n");
|
2008-05-20 13:47:46 +00:00
|
|
|
goto out;
|
2007-09-08 17:48:46 +00:00
|
|
|
}
|
|
|
|
asoc->deleted_primary = net;
|
|
|
|
atomic_add_int(&net->ref_count, 1);
|
2007-10-01 03:22:29 +00:00
|
|
|
memset(&net->lastsa, 0, sizeof(net->lastsa));
|
|
|
|
memset(&net->lastsv, 0, sizeof(net->lastsv));
|
2007-09-08 17:48:46 +00:00
|
|
|
sctp_mobility_feature_on(stcb->sctp_ep,
|
|
|
|
SCTP_MOBILITY_PRIM_DELETED);
|
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_PRIM_DELETED,
|
|
|
|
stcb->sctp_ep, stcb, NULL);
|
|
|
|
}
|
2008-05-20 13:47:46 +00:00
|
|
|
out:
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Try to find a confirmed primary */
|
2007-03-15 11:27:14 +00:00
|
|
|
asoc->primary_destination = sctp_find_alternate_net(stcb, lnet, 0);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
if (net == asoc->last_data_chunk_from) {
|
|
|
|
/* Reset primary */
|
|
|
|
asoc->last_data_chunk_from = TAILQ_FIRST(&asoc->nets);
|
|
|
|
}
|
|
|
|
if (net == asoc->last_control_chunk_from) {
|
|
|
|
/* Clear net */
|
|
|
|
asoc->last_control_chunk_from = NULL;
|
|
|
|
}
|
2011-08-03 20:21:00 +00:00
|
|
|
if (net == stcb->asoc.alternate) {
|
|
|
|
sctp_free_remote_addr(stcb->asoc.alternate);
|
|
|
|
stcb->asoc.alternate = NULL;
|
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
sctp_free_remote_addr(net);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* remove a remote endpoint address from an association, it will fail if the
|
|
|
|
* address does not exist.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
sctp_del_remote_addr(struct sctp_tcb *stcb, struct sockaddr *remaddr)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Here we need to remove a remote address. This is quite simple, we
|
|
|
|
* first find it in the list of address for the association
|
|
|
|
* (tasoc->asoc.nets) and then if it is there, we do a LIST_REMOVE
|
|
|
|
* on that item. Note we do not allow it to be removed if there are
|
|
|
|
* no other addresses.
|
|
|
|
*/
|
|
|
|
struct sctp_association *asoc;
|
2010-12-30 16:56:20 +00:00
|
|
|
struct sctp_nets *net, *nnet;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
asoc = &stcb->asoc;
|
|
|
|
|
|
|
|
/* locate the address */
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_FOREACH_SAFE(net, &asoc->nets, sctp_next, nnet) {
|
2006-11-03 15:23:16 +00:00
|
|
|
if (net->ro._l_addr.sa.sa_family != remaddr->sa_family) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (sctp_cmpaddr((struct sockaddr *)&net->ro._l_addr,
|
|
|
|
remaddr)) {
|
|
|
|
/* we found the guy */
|
|
|
|
if (asoc->numnets < 2) {
|
|
|
|
/* Must have at LEAST two remote addresses */
|
|
|
|
return (-1);
|
|
|
|
} else {
|
|
|
|
sctp_remove_net(stcb, net);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* not found. */
|
|
|
|
return (-2);
|
|
|
|
}
|
|
|
|
|
2007-09-08 17:48:46 +00:00
|
|
|
void
|
2008-12-06 13:19:54 +00:00
|
|
|
sctp_delete_from_timewait(uint32_t tag, uint16_t lport, uint16_t rport)
|
2007-09-08 17:48:46 +00:00
|
|
|
{
|
|
|
|
struct sctpvtaghead *chain;
|
|
|
|
struct sctp_tagblock *twait_block;
|
|
|
|
int found = 0;
|
|
|
|
int i;
|
|
|
|
|
2008-06-14 07:58:05 +00:00
|
|
|
chain = &SCTP_BASE_INFO(vtag_timewait)[(tag % SCTP_STACK_VTAG_HASH_SIZE)];
|
2013-07-03 18:48:43 +00:00
|
|
|
LIST_FOREACH(twait_block, chain, sctp_nxt_tagblock) {
|
|
|
|
for (i = 0; i < SCTP_NUMBER_IN_VTAG_BLOCK; i++) {
|
|
|
|
if ((twait_block->vtag_block[i].v_tag == tag) &&
|
|
|
|
(twait_block->vtag_block[i].lport == lport) &&
|
|
|
|
(twait_block->vtag_block[i].rport == rport)) {
|
|
|
|
twait_block->vtag_block[i].tv_sec_at_expire = 0;
|
|
|
|
twait_block->vtag_block[i].v_tag = 0;
|
|
|
|
twait_block->vtag_block[i].lport = 0;
|
|
|
|
twait_block->vtag_block[i].rport = 0;
|
|
|
|
found = 1;
|
2007-09-08 17:48:46 +00:00
|
|
|
break;
|
2013-07-03 18:48:43 +00:00
|
|
|
}
|
2007-09-08 17:48:46 +00:00
|
|
|
}
|
2013-07-03 18:48:43 +00:00
|
|
|
if (found)
|
|
|
|
break;
|
2007-09-08 17:48:46 +00:00
|
|
|
}
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-10-30 14:09:24 +00:00
|
|
|
int
|
2008-12-06 13:19:54 +00:00
|
|
|
sctp_is_in_timewait(uint32_t tag, uint16_t lport, uint16_t rport)
|
2007-10-30 14:09:24 +00:00
|
|
|
{
|
|
|
|
struct sctpvtaghead *chain;
|
|
|
|
struct sctp_tagblock *twait_block;
|
|
|
|
int found = 0;
|
|
|
|
int i;
|
|
|
|
|
2008-11-12 14:16:39 +00:00
|
|
|
SCTP_INP_INFO_WLOCK();
|
2008-06-14 07:58:05 +00:00
|
|
|
chain = &SCTP_BASE_INFO(vtag_timewait)[(tag % SCTP_STACK_VTAG_HASH_SIZE)];
|
2013-07-03 18:48:43 +00:00
|
|
|
LIST_FOREACH(twait_block, chain, sctp_nxt_tagblock) {
|
|
|
|
for (i = 0; i < SCTP_NUMBER_IN_VTAG_BLOCK; i++) {
|
|
|
|
if ((twait_block->vtag_block[i].v_tag == tag) &&
|
|
|
|
(twait_block->vtag_block[i].lport == lport) &&
|
|
|
|
(twait_block->vtag_block[i].rport == rport)) {
|
|
|
|
found = 1;
|
2007-10-30 14:09:24 +00:00
|
|
|
break;
|
2013-07-03 18:48:43 +00:00
|
|
|
}
|
2007-10-30 14:09:24 +00:00
|
|
|
}
|
2013-07-03 18:48:43 +00:00
|
|
|
if (found)
|
|
|
|
break;
|
2007-10-30 14:09:24 +00:00
|
|
|
}
|
2008-11-12 14:16:39 +00:00
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
2007-10-30 14:09:24 +00:00
|
|
|
return (found);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-15 15:12:10 +00:00
|
|
|
void
|
2008-12-06 13:19:54 +00:00
|
|
|
sctp_add_vtag_to_timewait(uint32_t tag, uint32_t time, uint16_t lport, uint16_t rport)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
struct sctpvtaghead *chain;
|
|
|
|
struct sctp_tagblock *twait_block;
|
|
|
|
struct timeval now;
|
|
|
|
int set, i;
|
|
|
|
|
2009-05-30 11:14:41 +00:00
|
|
|
if (time == 0) {
|
|
|
|
/* Its disabled */
|
|
|
|
return;
|
|
|
|
}
|
2007-05-08 14:32:53 +00:00
|
|
|
(void)SCTP_GETTIME_TIMEVAL(&now);
|
2008-06-14 07:58:05 +00:00
|
|
|
chain = &SCTP_BASE_INFO(vtag_timewait)[(tag % SCTP_STACK_VTAG_HASH_SIZE)];
|
2006-11-03 15:23:16 +00:00
|
|
|
set = 0;
|
2013-07-03 18:48:43 +00:00
|
|
|
LIST_FOREACH(twait_block, chain, sctp_nxt_tagblock) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Block(s) present, lets find space, and expire on the fly */
|
2013-07-03 18:48:43 +00:00
|
|
|
for (i = 0; i < SCTP_NUMBER_IN_VTAG_BLOCK; i++) {
|
|
|
|
if ((twait_block->vtag_block[i].v_tag == 0) &&
|
|
|
|
!set) {
|
|
|
|
twait_block->vtag_block[i].tv_sec_at_expire =
|
|
|
|
now.tv_sec + time;
|
|
|
|
twait_block->vtag_block[i].v_tag = tag;
|
|
|
|
twait_block->vtag_block[i].lport = lport;
|
|
|
|
twait_block->vtag_block[i].rport = rport;
|
|
|
|
set = 1;
|
|
|
|
} else if ((twait_block->vtag_block[i].v_tag) &&
|
|
|
|
((long)twait_block->vtag_block[i].tv_sec_at_expire < now.tv_sec)) {
|
|
|
|
/* Audit expires this guy */
|
|
|
|
twait_block->vtag_block[i].tv_sec_at_expire = 0;
|
|
|
|
twait_block->vtag_block[i].v_tag = 0;
|
|
|
|
twait_block->vtag_block[i].lport = 0;
|
|
|
|
twait_block->vtag_block[i].rport = 0;
|
|
|
|
if (set == 0) {
|
|
|
|
/* Reuse it for my new tag */
|
|
|
|
twait_block->vtag_block[i].tv_sec_at_expire = now.tv_sec + time;
|
2006-11-03 15:23:16 +00:00
|
|
|
twait_block->vtag_block[i].v_tag = tag;
|
2008-12-06 13:19:54 +00:00
|
|
|
twait_block->vtag_block[i].lport = lport;
|
|
|
|
twait_block->vtag_block[i].rport = rport;
|
2006-11-03 15:23:16 +00:00
|
|
|
set = 1;
|
|
|
|
}
|
|
|
|
}
|
2013-07-03 18:48:43 +00:00
|
|
|
}
|
|
|
|
if (set) {
|
|
|
|
/*
|
|
|
|
* We only do up to the block where we can place our
|
|
|
|
* tag for audits
|
|
|
|
*/
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Need to add a new block to chain */
|
|
|
|
if (!set) {
|
|
|
|
SCTP_MALLOC(twait_block, struct sctp_tagblock *,
|
2007-05-29 09:29:03 +00:00
|
|
|
sizeof(struct sctp_tagblock), SCTP_M_TIMW);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (twait_block == NULL) {
|
2008-11-12 14:16:39 +00:00
|
|
|
#ifdef INVARIANTS
|
|
|
|
panic("Can not alloc tagblock");
|
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-01-15 15:12:10 +00:00
|
|
|
memset(twait_block, 0, sizeof(struct sctp_tagblock));
|
2006-11-03 15:23:16 +00:00
|
|
|
LIST_INSERT_HEAD(chain, twait_block, sctp_nxt_tagblock);
|
2007-10-30 14:09:24 +00:00
|
|
|
twait_block->vtag_block[0].tv_sec_at_expire = now.tv_sec + time;
|
2006-11-03 15:23:16 +00:00
|
|
|
twait_block->vtag_block[0].v_tag = tag;
|
2008-12-06 13:19:54 +00:00
|
|
|
twait_block->vtag_block[0].lport = lport;
|
|
|
|
twait_block->vtag_block[0].rport = rport;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-03 11:15:32 +00:00
|
|
|
|
2007-08-24 00:53:53 +00:00
|
|
|
/*-
|
|
|
|
* Free the association after un-hashing the remote port. This
|
|
|
|
* function ALWAYS returns holding NO LOCK on the stcb. It DOES
|
|
|
|
* expect that the input to this function IS a locked TCB.
|
|
|
|
* It will return 0, if it did NOT destroy the association (instead
|
|
|
|
* it unlocks it. It will return NON-zero if it either destroyed the
|
|
|
|
* association OR the association is already destroyed.
|
2006-11-03 15:23:16 +00:00
|
|
|
*/
|
|
|
|
int
|
2006-12-14 17:02:55 +00:00
|
|
|
sctp_free_assoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int from_inpcbfree, int from_location)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct sctp_association *asoc;
|
2010-12-30 16:56:20 +00:00
|
|
|
struct sctp_nets *net, *nnet;
|
|
|
|
struct sctp_laddr *laddr, *naddr;
|
|
|
|
struct sctp_tmit_chunk *chk, *nchk;
|
|
|
|
struct sctp_asconf_addr *aparam, *naparam;
|
|
|
|
struct sctp_asconf_ack *aack, *naack;
|
|
|
|
struct sctp_stream_reset_list *strrst, *nstrrst;
|
|
|
|
struct sctp_queued_to_read *sq, *nsq;
|
|
|
|
struct sctp_stream_queue_pending *sp, *nsp;
|
|
|
|
sctp_sharedkey_t *shared_key, *nshared_key;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct socket *so;
|
|
|
|
|
|
|
|
/* first, lets purge the entry from the hash table. */
|
|
|
|
|
|
|
|
#ifdef SCTP_LOG_CLOSING
|
|
|
|
sctp_log_closing(inp, stcb, 6);
|
|
|
|
#endif
|
|
|
|
if (stcb->asoc.state == 0) {
|
|
|
|
#ifdef SCTP_LOG_CLOSING
|
|
|
|
sctp_log_closing(inp, NULL, 7);
|
|
|
|
#endif
|
|
|
|
/* there is no asoc, really TSNH :-0 */
|
|
|
|
return (1);
|
|
|
|
}
|
2011-08-03 20:21:00 +00:00
|
|
|
if (stcb->asoc.alternate) {
|
|
|
|
sctp_free_remote_addr(stcb->asoc.alternate);
|
|
|
|
stcb->asoc.alternate = NULL;
|
|
|
|
}
|
2006-12-14 17:02:55 +00:00
|
|
|
/* TEMP CODE */
|
|
|
|
if (stcb->freed_from_where == 0) {
|
|
|
|
/* Only record the first place free happened from */
|
|
|
|
stcb->freed_from_where = from_location;
|
|
|
|
}
|
|
|
|
/* TEMP CODE */
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
asoc = &stcb->asoc;
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
|
|
|
|
(inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE))
|
|
|
|
/* nothing around */
|
|
|
|
so = NULL;
|
|
|
|
else
|
|
|
|
so = inp->sctp_socket;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We used timer based freeing if a reader or writer is in the way.
|
|
|
|
* So we first check if we are actually being called from a timer,
|
|
|
|
* if so we abort early if a reader or writer is still in the way.
|
|
|
|
*/
|
|
|
|
if ((stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) &&
|
2006-12-14 17:02:55 +00:00
|
|
|
(from_inpcbfree == SCTP_NORMAL_PROC)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* is it the timer driving us? if so are the reader/writers
|
|
|
|
* gone?
|
|
|
|
*/
|
|
|
|
if (stcb->asoc.refcnt) {
|
|
|
|
/* nope, reader or writer in the way */
|
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_ASOCKILL, inp, stcb, NULL);
|
|
|
|
/* no asoc destroyed */
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
#ifdef SCTP_LOG_CLOSING
|
|
|
|
sctp_log_closing(inp, stcb, 8);
|
|
|
|
#endif
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* now clean up any other timers */
|
2007-05-08 14:32:53 +00:00
|
|
|
(void)SCTP_OS_TIMER_STOP(&asoc->dack_timer.timer);
|
2007-04-14 09:44:09 +00:00
|
|
|
asoc->dack_timer.self = NULL;
|
2007-05-08 14:32:53 +00:00
|
|
|
(void)SCTP_OS_TIMER_STOP(&asoc->strreset_timer.timer);
|
2007-04-14 09:44:09 +00:00
|
|
|
/*-
|
|
|
|
* For stream reset we don't blast this unless
|
|
|
|
* it is a str-reset timer, it might be the
|
|
|
|
* free-asoc timer which we DON'T want to
|
|
|
|
* disturb.
|
|
|
|
*/
|
|
|
|
if (asoc->strreset_timer.type == SCTP_TIMER_TYPE_STRRESET)
|
|
|
|
asoc->strreset_timer.self = NULL;
|
2007-05-08 14:32:53 +00:00
|
|
|
(void)SCTP_OS_TIMER_STOP(&asoc->asconf_timer.timer);
|
2007-04-14 09:44:09 +00:00
|
|
|
asoc->asconf_timer.self = NULL;
|
2007-05-08 14:32:53 +00:00
|
|
|
(void)SCTP_OS_TIMER_STOP(&asoc->autoclose_timer.timer);
|
2007-04-14 09:44:09 +00:00
|
|
|
asoc->autoclose_timer.self = NULL;
|
2007-05-08 14:32:53 +00:00
|
|
|
(void)SCTP_OS_TIMER_STOP(&asoc->shut_guard_timer.timer);
|
2007-04-14 09:44:09 +00:00
|
|
|
asoc->shut_guard_timer.self = NULL;
|
2007-05-08 14:32:53 +00:00
|
|
|
(void)SCTP_OS_TIMER_STOP(&asoc->delayed_event_timer.timer);
|
2007-04-14 09:44:09 +00:00
|
|
|
asoc->delayed_event_timer.self = NULL;
|
2007-09-08 17:48:46 +00:00
|
|
|
/* Mobility adaptation */
|
|
|
|
(void)SCTP_OS_TIMER_STOP(&asoc->delete_prim_timer.timer);
|
|
|
|
asoc->delete_prim_timer.self = NULL;
|
2006-11-03 15:23:16 +00:00
|
|
|
TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
|
2007-05-08 14:32:53 +00:00
|
|
|
(void)SCTP_OS_TIMER_STOP(&net->rxt_timer.timer);
|
2007-04-14 09:44:09 +00:00
|
|
|
net->rxt_timer.self = NULL;
|
2007-05-08 14:32:53 +00:00
|
|
|
(void)SCTP_OS_TIMER_STOP(&net->pmtu_timer.timer);
|
2007-04-14 09:44:09 +00:00
|
|
|
net->pmtu_timer.self = NULL;
|
2011-08-03 20:21:00 +00:00
|
|
|
(void)SCTP_OS_TIMER_STOP(&net->hb_timer.timer);
|
|
|
|
net->hb_timer.self = NULL;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2006-11-06 14:34:21 +00:00
|
|
|
/* Now the read queue needs to be cleaned up (only once) */
|
|
|
|
if ((stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) == 0) {
|
2007-05-02 12:50:13 +00:00
|
|
|
stcb->asoc.state |= SCTP_STATE_ABOUT_TO_BE_FREED;
|
2006-11-06 14:34:21 +00:00
|
|
|
SCTP_INP_READ_LOCK(inp);
|
|
|
|
TAILQ_FOREACH(sq, &inp->read_queue, next) {
|
|
|
|
if (sq->stcb == stcb) {
|
|
|
|
sq->do_not_ref_stcb = 1;
|
|
|
|
sq->sinfo_cumtsn = stcb->asoc.cumulative_tsn;
|
2006-11-08 00:21:13 +00:00
|
|
|
/*
|
|
|
|
* If there is no end, there never will be
|
|
|
|
* now.
|
|
|
|
*/
|
|
|
|
if (sq->end_added == 0) {
|
|
|
|
/* Held for PD-API clear that. */
|
|
|
|
sq->pdapi_aborted = 1;
|
|
|
|
sq->held_length = 0;
|
2011-06-15 23:50:27 +00:00
|
|
|
if (sctp_stcb_is_feature_on(inp, stcb, SCTP_PCB_FLAGS_PDAPIEVNT) && (so != NULL)) {
|
2006-11-08 00:21:13 +00:00
|
|
|
/*
|
|
|
|
* Need to add a PD-API
|
|
|
|
* aborted indication.
|
|
|
|
* Setting the control_pdapi
|
|
|
|
* assures that it will be
|
|
|
|
* added right after this
|
|
|
|
* msg.
|
|
|
|
*/
|
2007-04-22 11:06:27 +00:00
|
|
|
uint32_t strseq;
|
|
|
|
|
2006-11-08 00:21:13 +00:00
|
|
|
stcb->asoc.control_pdapi = sq;
|
2007-04-22 11:06:27 +00:00
|
|
|
strseq = (sq->sinfo_stream << 16) | sq->sinfo_ssn;
|
2009-08-15 21:10:52 +00:00
|
|
|
sctp_ulp_notify(SCTP_NOTIFY_PARTIAL_DELVIERY_INDICATION,
|
|
|
|
stcb,
|
|
|
|
SCTP_PARTIAL_DELIVERY_ABORTED,
|
|
|
|
(void *)&strseq,
|
|
|
|
SCTP_SO_LOCKED);
|
2006-11-08 00:21:13 +00:00
|
|
|
stcb->asoc.control_pdapi = NULL;
|
2006-11-06 14:34:21 +00:00
|
|
|
}
|
|
|
|
}
|
2006-11-08 00:21:13 +00:00
|
|
|
/* Add an end to wake them */
|
2006-11-06 14:34:21 +00:00
|
|
|
sq->end_added = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SCTP_INP_READ_UNLOCK(inp);
|
|
|
|
if (stcb->block_entry) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_PCB, ECONNRESET);
|
2006-11-06 14:34:21 +00:00
|
|
|
stcb->block_entry->error = ECONNRESET;
|
|
|
|
stcb->block_entry = NULL;
|
|
|
|
}
|
|
|
|
}
|
2010-05-11 17:02:29 +00:00
|
|
|
if ((stcb->asoc.refcnt) || (stcb->asoc.state & SCTP_STATE_IN_ACCEPT_QUEUE)) {
|
2006-11-06 14:34:21 +00:00
|
|
|
/*
|
2010-05-11 17:02:29 +00:00
|
|
|
* Someone holds a reference OR the socket is unaccepted
|
|
|
|
* yet.
|
2006-11-06 14:34:21 +00:00
|
|
|
*/
|
2010-06-05 21:17:23 +00:00
|
|
|
if ((stcb->asoc.refcnt) ||
|
|
|
|
(inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
|
|
|
|
(inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
|
|
|
|
stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
|
2010-05-11 17:02:29 +00:00
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_ASOCKILL, inp, stcb, NULL);
|
2010-06-05 21:17:23 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2007-07-14 09:36:28 +00:00
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
|
|
|
|
(inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE))
|
|
|
|
/* nothing around */
|
|
|
|
so = NULL;
|
2006-12-14 17:02:55 +00:00
|
|
|
if (so) {
|
2007-07-14 09:36:28 +00:00
|
|
|
/* Wake any reader/writers */
|
|
|
|
sctp_sorwakeup(inp, so);
|
|
|
|
sctp_sowwakeup(inp, so);
|
2006-12-14 17:02:55 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
#ifdef SCTP_LOG_CLOSING
|
|
|
|
sctp_log_closing(inp, stcb, 9);
|
|
|
|
#endif
|
|
|
|
/* no asoc destroyed */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
#ifdef SCTP_LOG_CLOSING
|
|
|
|
sctp_log_closing(inp, stcb, 10);
|
|
|
|
#endif
|
2006-12-14 17:02:55 +00:00
|
|
|
/*
|
|
|
|
* When I reach here, no others want to kill the assoc yet.. and I
|
|
|
|
* own the lock. Now its possible an abort comes in when I do the
|
|
|
|
* lock exchange below to grab all the locks to do the final take
|
|
|
|
* out. to prevent this we increment the count, which will start a
|
|
|
|
* timer and blow out above thus assuring us that we hold exclusive
|
|
|
|
* killing of the asoc. Note that after getting back the TCB lock we
|
|
|
|
* will go ahead and increment the counter back up and stop any
|
|
|
|
* timer a passing stranger may have started :-S
|
|
|
|
*/
|
|
|
|
if (from_inpcbfree == SCTP_NORMAL_PROC) {
|
|
|
|
atomic_add_int(&stcb->asoc.refcnt, 1);
|
|
|
|
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
SCTP_INP_INFO_WLOCK();
|
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
SCTP_TCB_LOCK(stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2006-12-14 17:02:55 +00:00
|
|
|
/* Double check the GONE flag */
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
|
|
|
|
(inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE))
|
|
|
|
/* nothing around */
|
|
|
|
so = NULL;
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
|
|
|
|
(inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
|
|
|
|
/*
|
|
|
|
* For TCP type we need special handling when we are
|
|
|
|
* connected. We also include the peel'ed off ones to.
|
|
|
|
*/
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) {
|
|
|
|
inp->sctp_flags &= ~SCTP_PCB_FLAGS_CONNECTED;
|
|
|
|
inp->sctp_flags |= SCTP_PCB_FLAGS_WAS_CONNECTED;
|
|
|
|
if (so) {
|
|
|
|
SOCK_LOCK(so);
|
2014-12-02 20:29:29 +00:00
|
|
|
if (so->so_rcv.sb_cc == 0) {
|
2006-11-03 15:23:16 +00:00
|
|
|
so->so_state &= ~(SS_ISCONNECTING |
|
|
|
|
SS_ISDISCONNECTING |
|
|
|
|
SS_ISCONFIRMING |
|
|
|
|
SS_ISCONNECTED);
|
|
|
|
}
|
2010-06-07 04:01:38 +00:00
|
|
|
socantrcvmore_locked(so);
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_sowwakeup(inp, so);
|
|
|
|
sctp_sorwakeup(inp, so);
|
2007-05-08 00:21:05 +00:00
|
|
|
SCTP_SOWAKEUP(so);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Make it invalid too, that way if its about to run it will abort
|
|
|
|
* and return.
|
|
|
|
*/
|
|
|
|
/* re-increment the lock */
|
2006-12-14 17:02:55 +00:00
|
|
|
if (from_inpcbfree == SCTP_NORMAL_PROC) {
|
2006-11-05 13:25:18 +00:00
|
|
|
atomic_add_int(&stcb->asoc.refcnt, -1);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2010-06-14 21:25:07 +00:00
|
|
|
if (stcb->asoc.refcnt) {
|
|
|
|
stcb->asoc.state &= ~SCTP_STATE_IN_ACCEPT_QUEUE;
|
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_ASOCKILL, inp, stcb, NULL);
|
|
|
|
if (from_inpcbfree == SCTP_NORMAL_PROC) {
|
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
}
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
return (0);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
asoc->state = 0;
|
|
|
|
if (inp->sctp_tcbhash) {
|
|
|
|
LIST_REMOVE(stcb, sctp_tcbhash);
|
|
|
|
}
|
2008-12-06 13:19:54 +00:00
|
|
|
if (stcb->asoc.in_asocid_hash) {
|
|
|
|
LIST_REMOVE(stcb, sctp_tcbasocidhash);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
/* Now lets remove it from the list of ALL associations in the EP */
|
|
|
|
LIST_REMOVE(stcb, sctp_tcblist);
|
2006-12-14 17:02:55 +00:00
|
|
|
if (from_inpcbfree == SCTP_NORMAL_PROC) {
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_INCR_REF(inp);
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
}
|
|
|
|
/* pull from vtag hash */
|
|
|
|
LIST_REMOVE(stcb, sctp_asocs);
|
2009-05-30 11:14:41 +00:00
|
|
|
sctp_add_vtag_to_timewait(asoc->my_vtag, SCTP_BASE_SYSCTL(sctp_vtag_time_wait),
|
|
|
|
inp->sctp_lport, stcb->rport);
|
2007-01-15 15:12:10 +00:00
|
|
|
|
|
|
|
/*
|
2010-04-03 15:40:14 +00:00
|
|
|
* Now restop the timers to be sure this is paranoia at is finest!
|
2007-01-15 15:12:10 +00:00
|
|
|
*/
|
2007-05-08 14:32:53 +00:00
|
|
|
(void)SCTP_OS_TIMER_STOP(&asoc->strreset_timer.timer);
|
|
|
|
(void)SCTP_OS_TIMER_STOP(&asoc->dack_timer.timer);
|
|
|
|
(void)SCTP_OS_TIMER_STOP(&asoc->strreset_timer.timer);
|
|
|
|
(void)SCTP_OS_TIMER_STOP(&asoc->asconf_timer.timer);
|
|
|
|
(void)SCTP_OS_TIMER_STOP(&asoc->shut_guard_timer.timer);
|
|
|
|
(void)SCTP_OS_TIMER_STOP(&asoc->autoclose_timer.timer);
|
|
|
|
(void)SCTP_OS_TIMER_STOP(&asoc->delayed_event_timer.timer);
|
2007-01-15 15:12:10 +00:00
|
|
|
TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
|
2007-05-08 14:32:53 +00:00
|
|
|
(void)SCTP_OS_TIMER_STOP(&net->rxt_timer.timer);
|
|
|
|
(void)SCTP_OS_TIMER_STOP(&net->pmtu_timer.timer);
|
2011-08-03 20:21:00 +00:00
|
|
|
(void)SCTP_OS_TIMER_STOP(&net->hb_timer.timer);
|
2007-01-15 15:12:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
asoc->strreset_timer.type = SCTP_TIMER_TYPE_NONE;
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* The chunk lists and such SHOULD be empty but we check them just
|
|
|
|
* in case.
|
|
|
|
*/
|
|
|
|
/* anything on the wheel needs to be removed */
|
|
|
|
for (i = 0; i < asoc->streamoutcnt; i++) {
|
|
|
|
struct sctp_stream_out *outs;
|
|
|
|
|
|
|
|
outs = &asoc->strmout[i];
|
|
|
|
/* now clean up any chunks here */
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_FOREACH_SAFE(sp, &outs->outqueue, next, nsp) {
|
2006-11-03 15:23:16 +00:00
|
|
|
TAILQ_REMOVE(&outs->outqueue, sp, next);
|
2012-07-17 13:03:47 +00:00
|
|
|
sctp_free_spbufspace(stcb, asoc, sp);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (sp->data) {
|
2010-07-26 09:22:52 +00:00
|
|
|
if (so) {
|
|
|
|
/* Still an open socket - report */
|
|
|
|
sctp_ulp_notify(SCTP_NOTIFY_SPECIAL_SP_FAIL, stcb,
|
2012-05-13 19:32:49 +00:00
|
|
|
0, (void *)sp, SCTP_SO_LOCKED);
|
2010-07-26 09:22:52 +00:00
|
|
|
}
|
|
|
|
if (sp->data) {
|
|
|
|
sctp_m_freem(sp->data);
|
|
|
|
sp->data = NULL;
|
|
|
|
sp->tail_mbuf = NULL;
|
2012-07-17 13:03:47 +00:00
|
|
|
sp->length = 0;
|
2010-07-26 09:22:52 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2010-09-15 23:10:45 +00:00
|
|
|
if (sp->net) {
|
|
|
|
sctp_free_remote_addr(sp->net);
|
|
|
|
sp->net = NULL;
|
|
|
|
}
|
2012-07-17 13:03:47 +00:00
|
|
|
sctp_free_a_strmoq(stcb, sp, SCTP_SO_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-17 12:16:24 +00:00
|
|
|
/* sa_ignore FREED_MEMORY */
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_FOREACH_SAFE(strrst, &asoc->resetHead, next_resp, nstrrst) {
|
|
|
|
TAILQ_REMOVE(&asoc->resetHead, strrst, next_resp);
|
|
|
|
SCTP_FREE(strrst, SCTP_M_STRESET);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_FOREACH_SAFE(sq, &asoc->pending_reply_queue, next, nsq) {
|
2006-11-03 15:23:16 +00:00
|
|
|
TAILQ_REMOVE(&asoc->pending_reply_queue, sq, next);
|
|
|
|
if (sq->data) {
|
|
|
|
sctp_m_freem(sq->data);
|
|
|
|
sq->data = NULL;
|
|
|
|
}
|
|
|
|
sctp_free_remote_addr(sq->whoFrom);
|
|
|
|
sq->whoFrom = NULL;
|
|
|
|
sq->stcb = NULL;
|
|
|
|
/* Free the ctl entry */
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_readq), sq);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_DECR_READQ_COUNT();
|
2007-05-17 12:16:24 +00:00
|
|
|
/* sa_ignore FREED_MEMORY */
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_FOREACH_SAFE(chk, &asoc->free_chunks, sctp_next, nchk) {
|
2006-11-03 15:23:16 +00:00
|
|
|
TAILQ_REMOVE(&asoc->free_chunks, chk, sctp_next);
|
|
|
|
if (chk->data) {
|
|
|
|
sctp_m_freem(chk->data);
|
|
|
|
chk->data = NULL;
|
|
|
|
}
|
2008-12-06 13:19:54 +00:00
|
|
|
if (chk->holds_key_ref)
|
2011-05-08 09:11:59 +00:00
|
|
|
sctp_auth_key_release(stcb, chk->auth_keyid, SCTP_SO_LOCKED);
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_chunk), chk);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_DECR_CHK_COUNT();
|
2008-06-14 07:58:05 +00:00
|
|
|
atomic_subtract_int(&SCTP_BASE_INFO(ipi_free_chunks), 1);
|
2006-11-03 15:23:16 +00:00
|
|
|
asoc->free_chunk_cnt--;
|
2007-05-17 12:16:24 +00:00
|
|
|
/* sa_ignore FREED_MEMORY */
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
/* pending send queue SHOULD be empty */
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_FOREACH_SAFE(chk, &asoc->send_queue, sctp_next, nchk) {
|
2012-11-16 19:39:10 +00:00
|
|
|
if (asoc->strmout[chk->rec.data.stream_number].chunks_on_queues > 0) {
|
|
|
|
asoc->strmout[chk->rec.data.stream_number].chunks_on_queues--;
|
|
|
|
#ifdef INVARIANTS
|
|
|
|
} else {
|
|
|
|
panic("No chunks on the queues for sid %u.", chk->rec.data.stream_number);
|
|
|
|
#endif
|
|
|
|
}
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_REMOVE(&asoc->send_queue, chk, sctp_next);
|
|
|
|
if (chk->data) {
|
|
|
|
if (so) {
|
|
|
|
/* Still a socket? */
|
2012-05-13 19:32:49 +00:00
|
|
|
sctp_ulp_notify(SCTP_NOTIFY_UNSENT_DG_FAIL, stcb,
|
|
|
|
0, chk, SCTP_SO_LOCKED);
|
2010-09-15 23:10:45 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if (chk->data) {
|
2010-12-30 16:56:20 +00:00
|
|
|
sctp_m_freem(chk->data);
|
|
|
|
chk->data = NULL;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2010-12-30 16:56:20 +00:00
|
|
|
}
|
|
|
|
if (chk->holds_key_ref)
|
2011-05-08 09:11:59 +00:00
|
|
|
sctp_auth_key_release(stcb, chk->auth_keyid, SCTP_SO_LOCKED);
|
2010-12-30 16:56:20 +00:00
|
|
|
if (chk->whoTo) {
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_free_remote_addr(chk->whoTo);
|
2010-12-30 16:56:20 +00:00
|
|
|
chk->whoTo = NULL;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2010-12-30 16:56:20 +00:00
|
|
|
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_chunk), chk);
|
|
|
|
SCTP_DECR_CHK_COUNT();
|
|
|
|
/* sa_ignore FREED_MEMORY */
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2010-12-30 16:56:20 +00:00
|
|
|
/* sent queue SHOULD be empty */
|
|
|
|
TAILQ_FOREACH_SAFE(chk, &asoc->sent_queue, sctp_next, nchk) {
|
2012-11-16 19:39:10 +00:00
|
|
|
if (chk->sent != SCTP_DATAGRAM_NR_ACKED) {
|
2012-11-07 22:11:38 +00:00
|
|
|
if (asoc->strmout[chk->rec.data.stream_number].chunks_on_queues > 0) {
|
|
|
|
asoc->strmout[chk->rec.data.stream_number].chunks_on_queues--;
|
|
|
|
#ifdef INVARIANTS
|
|
|
|
} else {
|
|
|
|
panic("No chunks on the queues for sid %u.", chk->rec.data.stream_number);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_REMOVE(&asoc->sent_queue, chk, sctp_next);
|
|
|
|
if (chk->data) {
|
|
|
|
if (so) {
|
|
|
|
/* Still a socket? */
|
2012-05-13 19:32:49 +00:00
|
|
|
sctp_ulp_notify(SCTP_NOTIFY_SENT_DG_FAIL, stcb,
|
|
|
|
0, chk, SCTP_SO_LOCKED);
|
2010-12-30 16:56:20 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if (chk->data) {
|
|
|
|
sctp_m_freem(chk->data);
|
|
|
|
chk->data = NULL;
|
|
|
|
}
|
|
|
|
}
|
2010-12-30 16:56:20 +00:00
|
|
|
if (chk->holds_key_ref)
|
2011-05-08 09:11:59 +00:00
|
|
|
sctp_auth_key_release(stcb, chk->auth_keyid, SCTP_SO_LOCKED);
|
2010-12-30 16:56:20 +00:00
|
|
|
sctp_free_remote_addr(chk->whoTo);
|
|
|
|
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_chunk), chk);
|
|
|
|
SCTP_DECR_CHK_COUNT();
|
|
|
|
/* sa_ignore FREED_MEMORY */
|
|
|
|
}
|
2012-11-16 19:39:10 +00:00
|
|
|
#ifdef INVARIANTS
|
|
|
|
for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
|
|
|
|
if (stcb->asoc.strmout[i].chunks_on_queues > 0) {
|
|
|
|
panic("%u chunks left for stream %u.", stcb->asoc.strmout[i].chunks_on_queues, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2010-12-30 16:56:20 +00:00
|
|
|
/* control queue MAY not be empty */
|
|
|
|
TAILQ_FOREACH_SAFE(chk, &asoc->control_send_queue, sctp_next, nchk) {
|
|
|
|
TAILQ_REMOVE(&asoc->control_send_queue, chk, sctp_next);
|
|
|
|
if (chk->data) {
|
|
|
|
sctp_m_freem(chk->data);
|
|
|
|
chk->data = NULL;
|
|
|
|
}
|
|
|
|
if (chk->holds_key_ref)
|
2011-05-08 09:11:59 +00:00
|
|
|
sctp_auth_key_release(stcb, chk->auth_keyid, SCTP_SO_LOCKED);
|
2010-12-30 16:56:20 +00:00
|
|
|
sctp_free_remote_addr(chk->whoTo);
|
|
|
|
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_chunk), chk);
|
|
|
|
SCTP_DECR_CHK_COUNT();
|
|
|
|
/* sa_ignore FREED_MEMORY */
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2008-05-20 13:47:46 +00:00
|
|
|
/* ASCONF queue MAY not be empty */
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_FOREACH_SAFE(chk, &asoc->asconf_send_queue, sctp_next, nchk) {
|
|
|
|
TAILQ_REMOVE(&asoc->asconf_send_queue, chk, sctp_next);
|
|
|
|
if (chk->data) {
|
|
|
|
sctp_m_freem(chk->data);
|
|
|
|
chk->data = NULL;
|
2008-05-20 13:47:46 +00:00
|
|
|
}
|
2010-12-30 16:56:20 +00:00
|
|
|
if (chk->holds_key_ref)
|
2011-05-08 09:11:59 +00:00
|
|
|
sctp_auth_key_release(stcb, chk->auth_keyid, SCTP_SO_LOCKED);
|
2010-12-30 16:56:20 +00:00
|
|
|
sctp_free_remote_addr(chk->whoTo);
|
|
|
|
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_chunk), chk);
|
|
|
|
SCTP_DECR_CHK_COUNT();
|
|
|
|
/* sa_ignore FREED_MEMORY */
|
2008-05-20 13:47:46 +00:00
|
|
|
}
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_FOREACH_SAFE(chk, &asoc->reasmqueue, sctp_next, nchk) {
|
|
|
|
TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next);
|
|
|
|
if (chk->data) {
|
|
|
|
sctp_m_freem(chk->data);
|
|
|
|
chk->data = NULL;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2010-12-30 16:56:20 +00:00
|
|
|
if (chk->holds_key_ref)
|
2011-05-08 09:11:59 +00:00
|
|
|
sctp_auth_key_release(stcb, chk->auth_keyid, SCTP_SO_LOCKED);
|
2010-12-30 16:56:20 +00:00
|
|
|
sctp_free_remote_addr(chk->whoTo);
|
|
|
|
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_chunk), chk);
|
|
|
|
SCTP_DECR_CHK_COUNT();
|
|
|
|
/* sa_ignore FREED_MEMORY */
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2010-12-30 16:56:20 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
if (asoc->mapping_array) {
|
2007-05-29 09:29:03 +00:00
|
|
|
SCTP_FREE(asoc->mapping_array, SCTP_M_MAP);
|
2006-11-03 15:23:16 +00:00
|
|
|
asoc->mapping_array = NULL;
|
|
|
|
}
|
2009-05-30 10:56:27 +00:00
|
|
|
if (asoc->nr_mapping_array) {
|
|
|
|
SCTP_FREE(asoc->nr_mapping_array, SCTP_M_MAP);
|
|
|
|
asoc->nr_mapping_array = NULL;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
/* the stream outs */
|
|
|
|
if (asoc->strmout) {
|
2007-05-29 09:29:03 +00:00
|
|
|
SCTP_FREE(asoc->strmout, SCTP_M_STRMO);
|
2006-11-03 15:23:16 +00:00
|
|
|
asoc->strmout = NULL;
|
|
|
|
}
|
2009-02-20 15:03:54 +00:00
|
|
|
asoc->strm_realoutsize = asoc->streamoutcnt = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
if (asoc->strmin) {
|
2010-12-30 16:56:20 +00:00
|
|
|
struct sctp_queued_to_read *ctl, *nctl;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
for (i = 0; i < asoc->streamincnt; i++) {
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_FOREACH_SAFE(ctl, &asoc->strmin[i].inqueue, next, nctl) {
|
|
|
|
TAILQ_REMOVE(&asoc->strmin[i].inqueue, ctl, next);
|
|
|
|
sctp_free_remote_addr(ctl->whoFrom);
|
|
|
|
if (ctl->data) {
|
|
|
|
sctp_m_freem(ctl->data);
|
|
|
|
ctl->data = NULL;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2010-12-30 16:56:20 +00:00
|
|
|
/*
|
|
|
|
* We don't free the address here since all
|
|
|
|
* the net's were freed above.
|
|
|
|
*/
|
|
|
|
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_readq), ctl);
|
|
|
|
SCTP_DECR_READQ_COUNT();
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-29 09:29:03 +00:00
|
|
|
SCTP_FREE(asoc->strmin, SCTP_M_STRMI);
|
2006-11-03 15:23:16 +00:00
|
|
|
asoc->strmin = NULL;
|
|
|
|
}
|
|
|
|
asoc->streamincnt = 0;
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_FOREACH_SAFE(net, &asoc->nets, sctp_next, nnet) {
|
2006-12-14 17:02:55 +00:00
|
|
|
#ifdef INVARIANTS
|
2010-12-30 16:56:20 +00:00
|
|
|
if (SCTP_BASE_INFO(ipi_count_raddr) == 0) {
|
2006-11-03 15:23:16 +00:00
|
|
|
panic("no net's left alloc'ed, or list points to itself");
|
|
|
|
}
|
2010-12-30 16:56:20 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
TAILQ_REMOVE(&asoc->nets, net, sctp_next);
|
|
|
|
sctp_free_remote_addr(net);
|
|
|
|
}
|
2010-12-30 16:56:20 +00:00
|
|
|
LIST_FOREACH_SAFE(laddr, &asoc->sctp_restricted_addrs, sctp_nxt_addr, naddr) {
|
2007-05-17 12:16:24 +00:00
|
|
|
/* sa_ignore FREED_MEMORY */
|
2007-03-15 11:27:14 +00:00
|
|
|
sctp_remove_laddr(laddr);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/* pending asconf (address) parameters */
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_FOREACH_SAFE(aparam, &asoc->asconf_queue, next, naparam) {
|
2007-05-17 12:16:24 +00:00
|
|
|
/* sa_ignore FREED_MEMORY */
|
2006-11-03 15:23:16 +00:00
|
|
|
TAILQ_REMOVE(&asoc->asconf_queue, aparam, next);
|
2007-05-29 09:29:03 +00:00
|
|
|
SCTP_FREE(aparam, SCTP_M_ASC_ADDR);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_FOREACH_SAFE(aack, &asoc->asconf_ack_sent, next, naack) {
|
2007-09-08 17:48:46 +00:00
|
|
|
/* sa_ignore FREED_MEMORY */
|
2007-08-27 05:19:48 +00:00
|
|
|
TAILQ_REMOVE(&asoc->asconf_ack_sent, aack, next);
|
|
|
|
if (aack->data != NULL) {
|
|
|
|
sctp_m_freem(aack->data);
|
|
|
|
}
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_asconf_ack), aack);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
/* clean up auth stuff */
|
|
|
|
if (asoc->local_hmacs)
|
|
|
|
sctp_free_hmaclist(asoc->local_hmacs);
|
|
|
|
if (asoc->peer_hmacs)
|
|
|
|
sctp_free_hmaclist(asoc->peer_hmacs);
|
|
|
|
|
|
|
|
if (asoc->local_auth_chunks)
|
|
|
|
sctp_free_chunklist(asoc->local_auth_chunks);
|
|
|
|
if (asoc->peer_auth_chunks)
|
|
|
|
sctp_free_chunklist(asoc->peer_auth_chunks);
|
|
|
|
|
|
|
|
sctp_free_authinfo(&asoc->authinfo);
|
|
|
|
|
2010-12-30 16:56:20 +00:00
|
|
|
LIST_FOREACH_SAFE(shared_key, &asoc->shared_keys, next, nshared_key) {
|
2006-11-03 15:23:16 +00:00
|
|
|
LIST_REMOVE(shared_key, next);
|
|
|
|
sctp_free_sharedkey(shared_key);
|
2007-05-17 12:16:24 +00:00
|
|
|
/* sa_ignore FREED_MEMORY */
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Insert new items here :> */
|
|
|
|
|
|
|
|
/* Get rid of LOCK */
|
2013-11-03 14:00:17 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_TCB_LOCK_DESTROY(stcb);
|
|
|
|
SCTP_TCB_SEND_LOCK_DESTROY(stcb);
|
2006-12-14 17:02:55 +00:00
|
|
|
if (from_inpcbfree == SCTP_NORMAL_PROC) {
|
|
|
|
SCTP_INP_INFO_WUNLOCK();
|
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
}
|
|
|
|
#ifdef SCTP_TRACK_FREED_ASOCS
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) {
|
|
|
|
/* now clean up the tasoc itself */
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_asoc), stcb);
|
2006-12-14 17:02:55 +00:00
|
|
|
SCTP_DECR_ASOC_COUNT();
|
|
|
|
} else {
|
|
|
|
LIST_INSERT_HEAD(&inp->sctp_asoc_free_list, stcb, sctp_tcblist);
|
|
|
|
}
|
|
|
|
#else
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_asoc), stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_DECR_ASOC_COUNT();
|
2006-12-14 17:02:55 +00:00
|
|
|
#endif
|
|
|
|
if (from_inpcbfree == SCTP_NORMAL_PROC) {
|
2006-11-03 15:23:16 +00:00
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) {
|
|
|
|
/*
|
|
|
|
* If its NOT the inp_free calling us AND sctp_close
|
|
|
|
* as been called, we call back...
|
|
|
|
*/
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
/*
|
|
|
|
* This will start the kill timer (if we are the
|
2010-11-09 16:18:32 +00:00
|
|
|
* last one) since we hold an increment yet. But
|
|
|
|
* this is the only safe way to do this since
|
|
|
|
* otherwise if the socket closes at the same time
|
|
|
|
* we are here we might collide in the cleanup.
|
2006-11-03 15:23:16 +00:00
|
|
|
*/
|
2007-05-08 15:53:03 +00:00
|
|
|
sctp_inpcb_free(inp,
|
|
|
|
SCTP_FREE_SHOULD_USE_GRACEFUL_CLOSE,
|
|
|
|
SCTP_CALLED_DIRECTLY_NOCMPSET);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_DECR_REF(inp);
|
2006-12-14 17:02:55 +00:00
|
|
|
goto out_of;
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
|
|
|
/* The socket is still open. */
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
|
|
|
}
|
|
|
|
}
|
2006-12-14 17:02:55 +00:00
|
|
|
if (from_inpcbfree == SCTP_NORMAL_PROC) {
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
|
|
|
}
|
|
|
|
out_of:
|
2006-11-03 15:23:16 +00:00
|
|
|
/* destroyed the asoc */
|
|
|
|
#ifdef SCTP_LOG_CLOSING
|
|
|
|
sctp_log_closing(inp, NULL, 11);
|
|
|
|
#endif
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* determine if a destination is "reachable" based upon the addresses bound
|
|
|
|
* to the current endpoint (e.g. only v4 or v6 currently bound)
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* FIX: if we allow assoc-level bindx(), then this needs to be fixed to use
|
|
|
|
* assoc level v4/v6 flags, as the assoc *may* not have the same address
|
|
|
|
* types bound as its endpoint
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
sctp_destination_is_reachable(struct sctp_tcb *stcb, struct sockaddr *destaddr)
|
|
|
|
{
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
int answer;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* No locks here, the TCB, in all cases is already locked and an
|
|
|
|
* assoc is up. There is either a INP lock by the caller applied (in
|
|
|
|
* asconf case when deleting an address) or NOT in the HB case,
|
|
|
|
* however if HB then the INP increment is up and the INP will not
|
|
|
|
* be removed (on top of the fact that we have a TCB lock). So we
|
|
|
|
* only want to read the sctp_flags, which is either bound-all or
|
|
|
|
* not.. no protection needed since once an assoc is up you can't be
|
|
|
|
* changing your binding.
|
|
|
|
*/
|
|
|
|
inp = stcb->sctp_ep;
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
|
|
|
|
/* if bound all, destination is not restricted */
|
|
|
|
/*
|
|
|
|
* RRS: Question during lock work: Is this correct? If you
|
|
|
|
* are bound-all you still might need to obey the V4--V6
|
|
|
|
* flags??? IMO this bound-all stuff needs to be removed!
|
|
|
|
*/
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
/* NOTE: all "scope" checks are done when local addresses are added */
|
2011-04-30 11:18:16 +00:00
|
|
|
switch (destaddr->sa_family) {
|
2012-07-15 11:04:49 +00:00
|
|
|
#ifdef INET6
|
2011-04-30 11:18:16 +00:00
|
|
|
case AF_INET6:
|
2006-11-03 15:23:16 +00:00
|
|
|
answer = inp->ip_inp.inp.inp_vflag & INP_IPV6;
|
2011-04-30 11:18:16 +00:00
|
|
|
break;
|
2012-07-15 11:04:49 +00:00
|
|
|
#endif
|
|
|
|
#ifdef INET
|
2011-04-30 11:18:16 +00:00
|
|
|
case AF_INET:
|
2006-11-03 15:23:16 +00:00
|
|
|
answer = inp->ip_inp.inp.inp_vflag & INP_IPV4;
|
2011-04-30 11:18:16 +00:00
|
|
|
break;
|
2012-07-15 11:04:49 +00:00
|
|
|
#endif
|
2011-04-30 11:18:16 +00:00
|
|
|
default:
|
2006-11-03 15:23:16 +00:00
|
|
|
/* invalid family, so it's unreachable */
|
|
|
|
answer = 0;
|
2011-04-30 11:18:16 +00:00
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
return (answer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* update the inp_vflags on an endpoint
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
sctp_update_ep_vflag(struct sctp_inpcb *inp)
|
|
|
|
{
|
|
|
|
struct sctp_laddr *laddr;
|
|
|
|
|
|
|
|
/* first clear the flag */
|
|
|
|
inp->ip_inp.inp.inp_vflag = 0;
|
|
|
|
/* set the flag based on addresses on the ep list */
|
|
|
|
LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
|
|
|
|
if (laddr->ifa == NULL) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB1, "%s: NULL ifa\n",
|
|
|
|
__FUNCTION__);
|
2006-11-03 15:23:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
if (laddr->ifa->localifa_flags & SCTP_BEING_DELETED) {
|
2006-11-03 15:23:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
switch (laddr->ifa->address.sa.sa_family) {
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
2006-11-03 15:23:16 +00:00
|
|
|
inp->ip_inp.inp.inp_vflag |= INP_IPV6;
|
2011-04-30 11:18:16 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
2006-11-03 15:23:16 +00:00
|
|
|
inp->ip_inp.inp.inp_vflag |= INP_IPV4;
|
2011-04-30 11:18:16 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add the address to the endpoint local address list There is nothing to be
|
|
|
|
* done if we are bound to all addresses
|
|
|
|
*/
|
2007-05-09 13:30:06 +00:00
|
|
|
void
|
2007-03-15 11:27:14 +00:00
|
|
|
sctp_add_local_addr_ep(struct sctp_inpcb *inp, struct sctp_ifa *ifa, uint32_t action)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
struct sctp_laddr *laddr;
|
2007-05-09 13:30:06 +00:00
|
|
|
int fnd, error = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
fnd = 0;
|
|
|
|
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
|
|
|
|
/* You are already bound to all. You have it already */
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
#ifdef INET6
|
2007-03-15 11:27:14 +00:00
|
|
|
if (ifa->address.sa.sa_family == AF_INET6) {
|
|
|
|
if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) {
|
|
|
|
/* Can't bind a non-useable addr. */
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2007-03-15 11:27:14 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
/* first, is it already present? */
|
|
|
|
LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
|
|
|
|
if (laddr->ifa == ifa) {
|
|
|
|
fnd = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
if (fnd == 0) {
|
|
|
|
/* Not in the ep list */
|
|
|
|
error = sctp_insert_laddr(&inp->sctp_addr_list, ifa, action);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (error != 0)
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
inp->laddr_count++;
|
|
|
|
/* update inp_vflag flags */
|
2011-04-30 11:18:16 +00:00
|
|
|
switch (ifa->address.sa.sa_family) {
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
2006-11-03 15:23:16 +00:00
|
|
|
inp->ip_inp.inp.inp_vflag |= INP_IPV6;
|
2011-04-30 11:18:16 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2012-07-15 11:04:49 +00:00
|
|
|
#ifdef INET
|
2011-04-30 11:18:16 +00:00
|
|
|
case AF_INET:
|
2006-11-03 15:23:16 +00:00
|
|
|
inp->ip_inp.inp.inp_vflag |= INP_IPV4;
|
2011-04-30 11:18:16 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* select a new (hopefully reachable) destination net (should only be used
|
|
|
|
* when we deleted an ep addr that is the only usable source address to reach
|
|
|
|
* the destination net)
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
sctp_select_primary_destination(struct sctp_tcb *stcb)
|
|
|
|
{
|
|
|
|
struct sctp_nets *net;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
|
|
|
|
/* for now, we'll just pick the first reachable one we find */
|
|
|
|
if (net->dest_state & SCTP_ADDR_UNCONFIRMED)
|
|
|
|
continue;
|
|
|
|
if (sctp_destination_is_reachable(stcb,
|
|
|
|
(struct sockaddr *)&net->ro._l_addr)) {
|
|
|
|
/* found a reachable destination */
|
|
|
|
stcb->asoc.primary_destination = net;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* I can't there from here! ...we're gonna die shortly... */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delete the address from the endpoint local address list There is nothing
|
|
|
|
* to be done if we are bound to all addresses
|
|
|
|
*/
|
2007-05-09 13:30:06 +00:00
|
|
|
void
|
2007-03-15 11:27:14 +00:00
|
|
|
sctp_del_local_addr_ep(struct sctp_inpcb *inp, struct sctp_ifa *ifa)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
struct sctp_laddr *laddr;
|
|
|
|
int fnd;
|
|
|
|
|
|
|
|
fnd = 0;
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
|
|
|
|
/* You are already bound to all. You have it already */
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
|
|
|
|
if (laddr->ifa == ifa) {
|
|
|
|
fnd = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fnd && (inp->laddr_count < 2)) {
|
|
|
|
/* can't delete unless there are at LEAST 2 addresses */
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
if (fnd) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* clean up any use of this address go through our
|
|
|
|
* associations and clear any last_used_address that match
|
|
|
|
* this one for each assoc, see if a new primary_destination
|
|
|
|
* is needed
|
|
|
|
*/
|
|
|
|
struct sctp_tcb *stcb;
|
|
|
|
|
|
|
|
/* clean up "next_addr_touse" */
|
|
|
|
if (inp->next_addr_touse == laddr)
|
|
|
|
/* delete this address */
|
|
|
|
inp->next_addr_touse = NULL;
|
|
|
|
|
|
|
|
/* clean up "last_used_address" */
|
|
|
|
LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
|
2007-03-15 11:27:14 +00:00
|
|
|
struct sctp_nets *net;
|
|
|
|
|
|
|
|
SCTP_TCB_LOCK(stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb->asoc.last_used_address == laddr)
|
|
|
|
/* delete this address */
|
|
|
|
stcb->asoc.last_used_address = NULL;
|
2007-03-15 11:27:14 +00:00
|
|
|
/*
|
|
|
|
* Now spin through all the nets and purge any ref
|
|
|
|
* to laddr
|
|
|
|
*/
|
|
|
|
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
|
|
|
|
if (net->ro._s_addr &&
|
|
|
|
(net->ro._s_addr->ifa == laddr->ifa)) {
|
|
|
|
/* Yep, purge src address selected */
|
2007-05-08 00:21:05 +00:00
|
|
|
sctp_rtentry_t *rt;
|
2007-03-15 11:27:14 +00:00
|
|
|
|
|
|
|
/* delete this address if cached */
|
|
|
|
rt = net->ro.ro_rt;
|
|
|
|
if (rt != NULL) {
|
|
|
|
RTFREE(rt);
|
|
|
|
net->ro.ro_rt = NULL;
|
|
|
|
}
|
|
|
|
sctp_free_ifa(net->ro._s_addr);
|
|
|
|
net->ro._s_addr = NULL;
|
|
|
|
net->src_addr_selected = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
} /* for each tcb */
|
|
|
|
/* remove it from the ep list */
|
|
|
|
sctp_remove_laddr(laddr);
|
|
|
|
inp->laddr_count--;
|
|
|
|
/* update inp_vflag flags */
|
|
|
|
sctp_update_ep_vflag(inp);
|
|
|
|
}
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-07-24 20:06:02 +00:00
|
|
|
* Add the address to the TCB local address restricted list.
|
|
|
|
* This is a "pending" address list (eg. addresses waiting for an
|
|
|
|
* ASCONF-ACK response) and cannot be used as a valid source address.
|
2006-11-03 15:23:16 +00:00
|
|
|
*/
|
2007-05-09 13:30:06 +00:00
|
|
|
void
|
2007-07-24 20:06:02 +00:00
|
|
|
sctp_add_local_addr_restricted(struct sctp_tcb *stcb, struct sctp_ifa *ifa)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
struct sctp_laddr *laddr;
|
2007-03-15 11:27:14 +00:00
|
|
|
struct sctpladdr *list;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/*
|
2007-03-15 11:27:14 +00:00
|
|
|
* Assumes TCB is locked.. and possibly the INP. May need to
|
2006-11-03 15:23:16 +00:00
|
|
|
* confirm/fix that if we need it and is not the case.
|
|
|
|
*/
|
2007-03-15 11:27:14 +00:00
|
|
|
list = &stcb->asoc.sctp_restricted_addrs;
|
|
|
|
|
2011-04-30 11:18:16 +00:00
|
|
|
#ifdef INET6
|
2007-03-15 11:27:14 +00:00
|
|
|
if (ifa->address.sa.sa_family == AF_INET6) {
|
|
|
|
if (ifa->localifa_flags & SCTP_ADDR_IFA_UNUSEABLE) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Can't bind a non-existent addr. */
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2007-03-15 11:27:14 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
/* does the address already exist? */
|
2007-03-15 11:27:14 +00:00
|
|
|
LIST_FOREACH(laddr, list, sctp_nxt_addr) {
|
2006-11-03 15:23:16 +00:00
|
|
|
if (laddr->ifa == ifa) {
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add to the list */
|
2007-05-09 13:30:06 +00:00
|
|
|
(void)sctp_insert_laddr(list, ifa, 0);
|
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* insert an laddr entry with the given ifa for the desired list
|
|
|
|
*/
|
|
|
|
int
|
2007-03-15 11:27:14 +00:00
|
|
|
sctp_insert_laddr(struct sctpladdr *list, struct sctp_ifa *ifa, uint32_t act)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
struct sctp_laddr *laddr;
|
|
|
|
|
2008-06-14 07:58:05 +00:00
|
|
|
laddr = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_laddr), struct sctp_laddr);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (laddr == NULL) {
|
|
|
|
/* out of memory? */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_PCB, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
SCTP_INCR_LADDR_COUNT();
|
|
|
|
bzero(laddr, sizeof(*laddr));
|
2007-05-28 11:17:24 +00:00
|
|
|
(void)SCTP_GETTIME_TIMEVAL(&laddr->start_time);
|
2006-11-03 15:23:16 +00:00
|
|
|
laddr->ifa = ifa;
|
2007-03-15 11:27:14 +00:00
|
|
|
laddr->action = act;
|
|
|
|
atomic_add_int(&ifa->refcount, 1);
|
2006-11-03 15:23:16 +00:00
|
|
|
/* insert it */
|
|
|
|
LIST_INSERT_HEAD(list, laddr, sctp_nxt_addr);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove an laddr entry from the local address list (on an assoc)
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sctp_remove_laddr(struct sctp_laddr *laddr)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* remove from the list */
|
|
|
|
LIST_REMOVE(laddr, sctp_nxt_addr);
|
2007-03-15 11:27:14 +00:00
|
|
|
sctp_free_ifa(laddr->ifa);
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_laddr), laddr);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_DECR_LADDR_COUNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-07-24 20:06:02 +00:00
|
|
|
* Remove a local address from the TCB local address restricted list
|
2006-11-03 15:23:16 +00:00
|
|
|
*/
|
2007-05-09 13:30:06 +00:00
|
|
|
void
|
2007-07-24 20:06:02 +00:00
|
|
|
sctp_del_local_addr_restricted(struct sctp_tcb *stcb, struct sctp_ifa *ifa)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
struct sctp_laddr *laddr;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is called by asconf work. It is assumed that a) The TCB is
|
|
|
|
* locked and b) The INP is locked. This is true in as much as I can
|
|
|
|
* trace through the entry asconf code where I did these locks.
|
|
|
|
* Again, the ASCONF code is a bit different in that it does lock
|
|
|
|
* the INP during its work often times. This must be since we don't
|
|
|
|
* want other proc's looking up things while what they are looking
|
|
|
|
* up is changing :-D
|
|
|
|
*/
|
|
|
|
|
|
|
|
inp = stcb->sctp_ep;
|
|
|
|
/* if subset bound and don't allow ASCONF's, can't delete last */
|
|
|
|
if (((inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) == 0) &&
|
2007-07-17 20:58:26 +00:00
|
|
|
sctp_is_feature_off(inp, SCTP_PCB_FLAGS_DO_ASCONF)) {
|
|
|
|
if (stcb->sctp_ep->laddr_count < 2) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* can't delete last address */
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
LIST_FOREACH(laddr, &stcb->asoc.sctp_restricted_addrs, sctp_nxt_addr) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* remove the address if it exists */
|
|
|
|
if (laddr->ifa == NULL)
|
|
|
|
continue;
|
|
|
|
if (laddr->ifa == ifa) {
|
|
|
|
sctp_remove_laddr(laddr);
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* address not found! */
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Temporarily remove for __APPLE__ until we use the Tiger equivalents
|
|
|
|
*/
|
|
|
|
/* sysctl */
|
|
|
|
static int sctp_max_number_of_assoc = SCTP_MAX_NUM_OF_ASOC;
|
|
|
|
static int sctp_scale_up_for_address = SCTP_SCALE_FOR_ADDR;
|
|
|
|
|
2011-02-03 10:05:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
#if defined(__FreeBSD__) && defined(SCTP_MCORE_INPUT) && defined(SMP)
|
|
|
|
struct sctp_mcore_ctrl *sctp_mcore_workers = NULL;
|
2011-02-04 13:50:30 +00:00
|
|
|
int *sctp_cpuarry = NULL;
|
2011-02-03 10:05:30 +00:00
|
|
|
void
|
|
|
|
sctp_queue_to_mcore(struct mbuf *m, int off, int cpu_to_use)
|
|
|
|
{
|
|
|
|
/* Queue a packet to a processor for the specified core */
|
|
|
|
struct sctp_mcore_queue *qent;
|
|
|
|
struct sctp_mcore_ctrl *wkq;
|
|
|
|
int need_wake = 0;
|
|
|
|
|
|
|
|
if (sctp_mcore_workers == NULL) {
|
|
|
|
/* Something went way bad during setup */
|
|
|
|
sctp_input_with_port(m, off, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SCTP_MALLOC(qent, struct sctp_mcore_queue *,
|
|
|
|
(sizeof(struct sctp_mcore_queue)),
|
|
|
|
SCTP_M_MCORE);
|
|
|
|
if (qent == NULL) {
|
|
|
|
/* This is trouble */
|
|
|
|
sctp_input_with_port(m, off, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
qent->vn = curvnet;
|
|
|
|
qent->m = m;
|
|
|
|
qent->off = off;
|
|
|
|
qent->v6 = 0;
|
|
|
|
wkq = &sctp_mcore_workers[cpu_to_use];
|
|
|
|
SCTP_MCORE_QLOCK(wkq);
|
|
|
|
|
|
|
|
TAILQ_INSERT_TAIL(&wkq->que, qent, next);
|
|
|
|
if (wkq->running == 0) {
|
|
|
|
need_wake = 1;
|
|
|
|
}
|
|
|
|
SCTP_MCORE_QUNLOCK(wkq);
|
|
|
|
if (need_wake) {
|
|
|
|
wakeup(&wkq->running);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sctp_mcore_thread(void *arg)
|
|
|
|
{
|
|
|
|
|
|
|
|
struct sctp_mcore_ctrl *wkq;
|
|
|
|
struct sctp_mcore_queue *qent;
|
|
|
|
|
|
|
|
wkq = (struct sctp_mcore_ctrl *)arg;
|
|
|
|
struct mbuf *m;
|
|
|
|
int off, v6;
|
|
|
|
|
|
|
|
/* Wait for first tickle */
|
|
|
|
SCTP_MCORE_LOCK(wkq);
|
|
|
|
wkq->running = 0;
|
|
|
|
msleep(&wkq->running,
|
|
|
|
&wkq->core_mtx,
|
|
|
|
0, "wait for pkt", 0);
|
|
|
|
SCTP_MCORE_UNLOCK(wkq);
|
|
|
|
|
|
|
|
/* Bind to our cpu */
|
|
|
|
thread_lock(curthread);
|
|
|
|
sched_bind(curthread, wkq->cpuid);
|
|
|
|
thread_unlock(curthread);
|
|
|
|
|
|
|
|
/* Now lets start working */
|
|
|
|
SCTP_MCORE_LOCK(wkq);
|
|
|
|
/* Now grab lock and go */
|
2011-12-17 19:21:40 +00:00
|
|
|
for (;;) {
|
2011-02-03 10:05:30 +00:00
|
|
|
SCTP_MCORE_QLOCK(wkq);
|
|
|
|
skip_sleep:
|
|
|
|
wkq->running = 1;
|
|
|
|
qent = TAILQ_FIRST(&wkq->que);
|
|
|
|
if (qent) {
|
|
|
|
TAILQ_REMOVE(&wkq->que, qent, next);
|
|
|
|
SCTP_MCORE_QUNLOCK(wkq);
|
|
|
|
CURVNET_SET(qent->vn);
|
|
|
|
m = qent->m;
|
|
|
|
off = qent->off;
|
|
|
|
v6 = qent->v6;
|
|
|
|
SCTP_FREE(qent, SCTP_M_MCORE);
|
|
|
|
if (v6 == 0) {
|
|
|
|
sctp_input_with_port(m, off, 0);
|
|
|
|
} else {
|
2012-05-04 09:27:00 +00:00
|
|
|
SCTP_PRINTF("V6 not yet supported\n");
|
2011-02-03 10:05:30 +00:00
|
|
|
sctp_m_freem(m);
|
|
|
|
}
|
|
|
|
CURVNET_RESTORE();
|
|
|
|
SCTP_MCORE_QLOCK(wkq);
|
|
|
|
}
|
|
|
|
wkq->running = 0;
|
|
|
|
if (!TAILQ_EMPTY(&wkq->que)) {
|
|
|
|
goto skip_sleep;
|
|
|
|
}
|
|
|
|
SCTP_MCORE_QUNLOCK(wkq);
|
|
|
|
msleep(&wkq->running,
|
|
|
|
&wkq->core_mtx,
|
|
|
|
0, "wait for pkt", 0);
|
2011-12-27 10:16:24 +00:00
|
|
|
}
|
2011-02-03 10:05:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sctp_startup_mcore_threads(void)
|
|
|
|
{
|
2011-02-04 13:50:30 +00:00
|
|
|
int i, cpu;
|
2011-02-03 10:05:30 +00:00
|
|
|
|
2011-02-04 13:50:30 +00:00
|
|
|
if (mp_ncpus == 1)
|
2011-02-03 10:05:30 +00:00
|
|
|
return;
|
|
|
|
|
2011-02-04 13:50:30 +00:00
|
|
|
if (sctp_mcore_workers != NULL) {
|
|
|
|
/*
|
|
|
|
* Already been here in some previous vnet?
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
2011-02-03 10:05:30 +00:00
|
|
|
SCTP_MALLOC(sctp_mcore_workers, struct sctp_mcore_ctrl *,
|
2011-02-04 13:50:30 +00:00
|
|
|
((mp_maxid + 1) * sizeof(struct sctp_mcore_ctrl)),
|
2011-02-03 10:05:30 +00:00
|
|
|
SCTP_M_MCORE);
|
|
|
|
if (sctp_mcore_workers == NULL) {
|
|
|
|
/* TSNH I hope */
|
|
|
|
return;
|
|
|
|
}
|
2011-02-04 13:50:30 +00:00
|
|
|
memset(sctp_mcore_workers, 0, ((mp_maxid + 1) *
|
2011-02-03 10:05:30 +00:00
|
|
|
sizeof(struct sctp_mcore_ctrl)));
|
|
|
|
/* Init the structures */
|
2011-02-04 13:50:30 +00:00
|
|
|
for (i = 0; i <= mp_maxid; i++) {
|
2011-02-03 10:05:30 +00:00
|
|
|
TAILQ_INIT(&sctp_mcore_workers[i].que);
|
|
|
|
SCTP_MCORE_LOCK_INIT(&sctp_mcore_workers[i]);
|
|
|
|
SCTP_MCORE_QLOCK_INIT(&sctp_mcore_workers[i]);
|
|
|
|
sctp_mcore_workers[i].cpuid = i;
|
|
|
|
}
|
2011-02-04 13:50:30 +00:00
|
|
|
if (sctp_cpuarry == NULL) {
|
|
|
|
SCTP_MALLOC(sctp_cpuarry, int *,
|
|
|
|
(mp_ncpus * sizeof(int)),
|
|
|
|
SCTP_M_MCORE);
|
|
|
|
i = 0;
|
|
|
|
CPU_FOREACH(cpu) {
|
|
|
|
sctp_cpuarry[i] = cpu;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2011-02-03 10:05:30 +00:00
|
|
|
/* Now start them all */
|
2011-02-04 13:50:30 +00:00
|
|
|
CPU_FOREACH(cpu) {
|
2011-02-03 10:05:30 +00:00
|
|
|
(void)kproc_create(sctp_mcore_thread,
|
2011-02-04 13:50:30 +00:00
|
|
|
(void *)&sctp_mcore_workers[cpu],
|
|
|
|
&sctp_mcore_workers[cpu].thread_proc,
|
2011-02-03 10:05:30 +00:00
|
|
|
RFPROC,
|
|
|
|
SCTP_KTHREAD_PAGES,
|
|
|
|
SCTP_MCORE_NAME);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
void
|
|
|
|
sctp_pcb_init()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* SCTP initialization for the PCB structures should be called by
|
|
|
|
* the sctp_init() funciton.
|
|
|
|
*/
|
|
|
|
int i;
|
2007-09-08 17:48:46 +00:00
|
|
|
struct timeval tv;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_VAR(sctp_pcb_initialized) != 0) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* error I was called twice */
|
|
|
|
return;
|
|
|
|
}
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_BASE_VAR(sctp_pcb_initialized) = 1;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-09-13 14:43:54 +00:00
|
|
|
#if defined(SCTP_LOCAL_TRACE_BUF)
|
2008-06-14 07:58:05 +00:00
|
|
|
bzero(&SCTP_BASE_SYSCTL(sctp_log), sizeof(struct sctp_log));
|
2011-02-03 11:52:22 +00:00
|
|
|
#endif
|
|
|
|
#if defined(__FreeBSD__) && defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
|
|
|
|
SCTP_MALLOC(SCTP_BASE_STATS, struct sctpstat *,
|
2011-02-04 13:50:30 +00:00
|
|
|
((mp_maxid + 1) * sizeof(struct sctpstat)),
|
2011-02-03 11:52:22 +00:00
|
|
|
SCTP_M_MCORE);
|
2007-09-13 14:43:54 +00:00
|
|
|
#endif
|
2007-09-08 17:48:46 +00:00
|
|
|
(void)SCTP_GETTIME_TIMEVAL(&tv);
|
2010-03-24 20:02:40 +00:00
|
|
|
#if defined(__FreeBSD__) && defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
|
2011-02-04 13:50:30 +00:00
|
|
|
bzero(SCTP_BASE_STATS, (sizeof(struct sctpstat) * (mp_maxid + 1)));
|
2010-03-24 20:02:40 +00:00
|
|
|
SCTP_BASE_STATS[PCPU_GET(cpuid)].sctps_discontinuitytime.tv_sec = (uint32_t) tv.tv_sec;
|
|
|
|
SCTP_BASE_STATS[PCPU_GET(cpuid)].sctps_discontinuitytime.tv_usec = (uint32_t) tv.tv_usec;
|
|
|
|
#else
|
2011-02-03 11:52:22 +00:00
|
|
|
bzero(&SCTP_BASE_STATS, sizeof(struct sctpstat));
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_BASE_STAT(sctps_discontinuitytime).tv_sec = (uint32_t) tv.tv_sec;
|
|
|
|
SCTP_BASE_STAT(sctps_discontinuitytime).tv_usec = (uint32_t) tv.tv_usec;
|
2010-03-24 20:02:40 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
/* init the empty list of (All) Endpoints */
|
2008-06-14 07:58:05 +00:00
|
|
|
LIST_INIT(&SCTP_BASE_INFO(listhead));
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* init the hash table of endpoints */
|
2008-06-14 07:58:05 +00:00
|
|
|
TUNABLE_INT_FETCH("net.inet.sctp.tcbhashsize", &SCTP_BASE_SYSCTL(sctp_hashtblsize));
|
|
|
|
TUNABLE_INT_FETCH("net.inet.sctp.pcbhashsize", &SCTP_BASE_SYSCTL(sctp_pcbtblsize));
|
|
|
|
TUNABLE_INT_FETCH("net.inet.sctp.chunkscale", &SCTP_BASE_SYSCTL(sctp_chunkscale));
|
|
|
|
SCTP_BASE_INFO(sctp_asochash) = SCTP_HASH_INIT((SCTP_BASE_SYSCTL(sctp_hashtblsize) * 31),
|
|
|
|
&SCTP_BASE_INFO(hashasocmark));
|
|
|
|
SCTP_BASE_INFO(sctp_ephash) = SCTP_HASH_INIT(SCTP_BASE_SYSCTL(sctp_hashtblsize),
|
|
|
|
&SCTP_BASE_INFO(hashmark));
|
|
|
|
SCTP_BASE_INFO(sctp_tcpephash) = SCTP_HASH_INIT(SCTP_BASE_SYSCTL(sctp_hashtblsize),
|
|
|
|
&SCTP_BASE_INFO(hashtcpmark));
|
|
|
|
SCTP_BASE_INFO(hashtblsize) = SCTP_BASE_SYSCTL(sctp_hashtblsize);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_BASE_INFO(sctp_vrfhash) = SCTP_HASH_INIT(SCTP_SIZE_OF_VRF_HASH,
|
|
|
|
&SCTP_BASE_INFO(hashvrfmark));
|
2007-03-15 11:27:14 +00:00
|
|
|
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_BASE_INFO(vrf_ifn_hash) = SCTP_HASH_INIT(SCTP_VRF_IFN_HASH_SIZE,
|
|
|
|
&SCTP_BASE_INFO(vrf_ifn_hashmark));
|
2006-11-03 15:23:16 +00:00
|
|
|
/* init the zones */
|
|
|
|
/*
|
|
|
|
* FIX ME: Should check for NULL returns, but if it does fail we are
|
|
|
|
* doomed to panic anyways... add later maybe.
|
|
|
|
*/
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_ZONE_INIT(SCTP_BASE_INFO(ipi_zone_ep), "sctp_ep",
|
2006-11-03 15:23:16 +00:00
|
|
|
sizeof(struct sctp_inpcb), maxsockets);
|
|
|
|
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_ZONE_INIT(SCTP_BASE_INFO(ipi_zone_asoc), "sctp_asoc",
|
2006-11-03 15:23:16 +00:00
|
|
|
sizeof(struct sctp_tcb), sctp_max_number_of_assoc);
|
|
|
|
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_ZONE_INIT(SCTP_BASE_INFO(ipi_zone_laddr), "sctp_laddr",
|
2006-11-03 15:23:16 +00:00
|
|
|
sizeof(struct sctp_laddr),
|
|
|
|
(sctp_max_number_of_assoc * sctp_scale_up_for_address));
|
|
|
|
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_ZONE_INIT(SCTP_BASE_INFO(ipi_zone_net), "sctp_raddr",
|
2006-11-03 15:23:16 +00:00
|
|
|
sizeof(struct sctp_nets),
|
|
|
|
(sctp_max_number_of_assoc * sctp_scale_up_for_address));
|
|
|
|
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_ZONE_INIT(SCTP_BASE_INFO(ipi_zone_chunk), "sctp_chunk",
|
2006-11-03 15:23:16 +00:00
|
|
|
sizeof(struct sctp_tmit_chunk),
|
2008-06-14 07:58:05 +00:00
|
|
|
(sctp_max_number_of_assoc * SCTP_BASE_SYSCTL(sctp_chunkscale)));
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_ZONE_INIT(SCTP_BASE_INFO(ipi_zone_readq), "sctp_readq",
|
2006-11-03 15:23:16 +00:00
|
|
|
sizeof(struct sctp_queued_to_read),
|
2008-06-14 07:58:05 +00:00
|
|
|
(sctp_max_number_of_assoc * SCTP_BASE_SYSCTL(sctp_chunkscale)));
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_ZONE_INIT(SCTP_BASE_INFO(ipi_zone_strmoq), "sctp_stream_msg_out",
|
2006-11-03 15:23:16 +00:00
|
|
|
sizeof(struct sctp_stream_queue_pending),
|
2008-06-14 07:58:05 +00:00
|
|
|
(sctp_max_number_of_assoc * SCTP_BASE_SYSCTL(sctp_chunkscale)));
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_ZONE_INIT(SCTP_BASE_INFO(ipi_zone_asconf), "sctp_asconf",
|
2008-05-20 13:47:46 +00:00
|
|
|
sizeof(struct sctp_asconf),
|
2008-06-14 07:58:05 +00:00
|
|
|
(sctp_max_number_of_assoc * SCTP_BASE_SYSCTL(sctp_chunkscale)));
|
2008-05-20 13:47:46 +00:00
|
|
|
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_ZONE_INIT(SCTP_BASE_INFO(ipi_zone_asconf_ack), "sctp_asconf_ack",
|
2007-08-27 05:19:48 +00:00
|
|
|
sizeof(struct sctp_asconf_ack),
|
2008-06-14 07:58:05 +00:00
|
|
|
(sctp_max_number_of_assoc * SCTP_BASE_SYSCTL(sctp_chunkscale)));
|
2007-08-27 05:19:48 +00:00
|
|
|
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Master Lock INIT for info structure */
|
|
|
|
SCTP_INP_INFO_LOCK_INIT();
|
|
|
|
SCTP_STATLOG_INIT_LOCK();
|
2006-12-14 17:02:55 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_IPI_COUNT_INIT();
|
|
|
|
SCTP_IPI_ADDR_INIT();
|
2007-05-29 09:29:03 +00:00
|
|
|
#ifdef SCTP_PACKET_LOGGING
|
|
|
|
SCTP_IP_PKTLOG_INIT();
|
|
|
|
#endif
|
2008-06-14 07:58:05 +00:00
|
|
|
LIST_INIT(&SCTP_BASE_INFO(addr_wq));
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2010-05-16 17:03:56 +00:00
|
|
|
SCTP_WQ_ADDR_INIT();
|
2006-11-03 15:23:16 +00:00
|
|
|
/* not sure if we need all the counts */
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_BASE_INFO(ipi_count_ep) = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
/* assoc/tcb zone info */
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_BASE_INFO(ipi_count_asoc) = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
/* local addrlist zone info */
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_BASE_INFO(ipi_count_laddr) = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
/* remote addrlist zone info */
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_BASE_INFO(ipi_count_raddr) = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
/* chunk info */
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_BASE_INFO(ipi_count_chunk) = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/* socket queue zone info */
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_BASE_INFO(ipi_count_readq) = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/* stream out queue cont */
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_BASE_INFO(ipi_count_strmoq) = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_BASE_INFO(ipi_free_strmoq) = 0;
|
|
|
|
SCTP_BASE_INFO(ipi_free_chunks) = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_OS_TIMER_INIT(&SCTP_BASE_INFO(addr_wq_timer.timer));
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/* Init the TIMEWAIT list */
|
2008-11-12 14:16:39 +00:00
|
|
|
for (i = 0; i < SCTP_STACK_VTAG_HASH_SIZE; i++) {
|
2010-01-04 18:25:38 +00:00
|
|
|
LIST_INIT(&SCTP_BASE_INFO(vtag_timewait)[i]);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
sctp_startup_iterator();
|
|
|
|
|
2011-02-03 10:05:30 +00:00
|
|
|
#if defined(__FreeBSD__) && defined(SCTP_MCORE_INPUT) && defined(SMP)
|
|
|
|
sctp_startup_mcore_threads();
|
|
|
|
#endif
|
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
/*
|
|
|
|
* INIT the default VRF which for BSD is the only one, other O/S's
|
|
|
|
* may have more. But initially they must start with one and then
|
|
|
|
* add the VRF's as addresses are added.
|
|
|
|
*/
|
|
|
|
sctp_init_vrf_list(SCTP_DEFAULT_VRF);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
2008-05-20 13:47:46 +00:00
|
|
|
/*
|
2008-06-14 07:58:05 +00:00
|
|
|
* Assumes that the SCTP_BASE_INFO() lock is NOT held.
|
2008-05-20 13:47:46 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
sctp_pcb_finish(void)
|
|
|
|
{
|
|
|
|
struct sctp_vrflist *vrf_bucket;
|
2010-12-30 16:56:20 +00:00
|
|
|
struct sctp_vrf *vrf, *nvrf;
|
|
|
|
struct sctp_ifn *ifn, *nifn;
|
|
|
|
struct sctp_ifa *ifa, *nifa;
|
2008-06-14 07:58:05 +00:00
|
|
|
struct sctpvtaghead *chain;
|
|
|
|
struct sctp_tagblock *twait_block, *prev_twait_block;
|
2010-12-30 16:56:20 +00:00
|
|
|
struct sctp_laddr *wi, *nwi;
|
2008-06-14 07:58:05 +00:00
|
|
|
int i;
|
2013-11-16 15:04:49 +00:00
|
|
|
struct sctp_iterator *it, *nit;
|
2008-05-20 13:47:46 +00:00
|
|
|
|
2010-05-16 17:03:56 +00:00
|
|
|
/*
|
2013-11-16 15:04:49 +00:00
|
|
|
* In FreeBSD the iterator thread never exits but we do clean up.
|
|
|
|
* The only way FreeBSD reaches here is if we have VRF's but we
|
|
|
|
* still add the ifdef to make it compile on old versions.
|
2010-05-16 17:03:56 +00:00
|
|
|
*/
|
2013-11-16 15:04:49 +00:00
|
|
|
SCTP_IPI_ITERATOR_WQ_LOCK();
|
|
|
|
TAILQ_FOREACH_SAFE(it, &sctp_it_ctl.iteratorhead, sctp_nxt_itr, nit) {
|
|
|
|
if (it->vn != curvnet) {
|
|
|
|
continue;
|
2010-05-16 17:03:56 +00:00
|
|
|
}
|
2013-11-16 15:04:49 +00:00
|
|
|
TAILQ_REMOVE(&sctp_it_ctl.iteratorhead, it, sctp_nxt_itr);
|
|
|
|
if (it->function_atend != NULL) {
|
|
|
|
(*it->function_atend) (it->pointer, it->val);
|
2010-05-16 17:03:56 +00:00
|
|
|
}
|
2013-11-16 15:04:49 +00:00
|
|
|
SCTP_FREE(it, SCTP_M_ITER);
|
2010-05-16 17:03:56 +00:00
|
|
|
}
|
2013-11-16 15:04:49 +00:00
|
|
|
SCTP_IPI_ITERATOR_WQ_UNLOCK();
|
|
|
|
SCTP_ITERATOR_LOCK();
|
|
|
|
if ((sctp_it_ctl.cur_it) &&
|
|
|
|
(sctp_it_ctl.cur_it->vn == curvnet)) {
|
|
|
|
sctp_it_ctl.iterator_flags |= SCTP_ITERATOR_STOP_CUR_IT;
|
|
|
|
}
|
|
|
|
SCTP_ITERATOR_UNLOCK();
|
2009-11-17 13:13:58 +00:00
|
|
|
SCTP_OS_TIMER_STOP(&SCTP_BASE_INFO(addr_wq_timer.timer));
|
2010-05-16 17:03:56 +00:00
|
|
|
SCTP_WQ_ADDR_LOCK();
|
2010-12-30 16:56:20 +00:00
|
|
|
LIST_FOREACH_SAFE(wi, &SCTP_BASE_INFO(addr_wq), sctp_nxt_addr, nwi) {
|
2009-11-17 13:13:58 +00:00
|
|
|
LIST_REMOVE(wi, sctp_nxt_addr);
|
|
|
|
SCTP_DECR_LADDR_COUNT();
|
2014-09-06 20:03:24 +00:00
|
|
|
if (wi->action == SCTP_DEL_IP_ADDRESS) {
|
|
|
|
SCTP_FREE(wi->ifa, SCTP_M_IFA);
|
|
|
|
}
|
2009-11-17 13:13:58 +00:00
|
|
|
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_laddr), wi);
|
|
|
|
}
|
2010-05-16 17:03:56 +00:00
|
|
|
SCTP_WQ_ADDR_UNLOCK();
|
2009-11-17 13:13:58 +00:00
|
|
|
|
2008-05-20 13:47:46 +00:00
|
|
|
/*
|
|
|
|
* free the vrf/ifn/ifa lists and hashes (be sure address monitor is
|
|
|
|
* destroyed first).
|
|
|
|
*/
|
2008-06-14 07:58:05 +00:00
|
|
|
vrf_bucket = &SCTP_BASE_INFO(sctp_vrfhash)[(SCTP_DEFAULT_VRFID & SCTP_BASE_INFO(hashvrfmark))];
|
2010-12-30 16:56:20 +00:00
|
|
|
LIST_FOREACH_SAFE(vrf, vrf_bucket, next_vrf, nvrf) {
|
|
|
|
LIST_FOREACH_SAFE(ifn, &vrf->ifnlist, next_ifn, nifn) {
|
|
|
|
LIST_FOREACH_SAFE(ifa, &ifn->ifalist, next_ifa, nifa) {
|
2008-05-20 13:47:46 +00:00
|
|
|
/* free the ifa */
|
|
|
|
LIST_REMOVE(ifa, next_bucket);
|
|
|
|
LIST_REMOVE(ifa, next_ifa);
|
|
|
|
SCTP_FREE(ifa, SCTP_M_IFA);
|
|
|
|
}
|
|
|
|
/* free the ifn */
|
|
|
|
LIST_REMOVE(ifn, next_bucket);
|
|
|
|
LIST_REMOVE(ifn, next_ifn);
|
|
|
|
SCTP_FREE(ifn, SCTP_M_IFN);
|
|
|
|
}
|
|
|
|
SCTP_HASH_FREE(vrf->vrf_addr_hash, vrf->vrf_addr_hashmark);
|
|
|
|
/* free the vrf */
|
|
|
|
LIST_REMOVE(vrf, next_vrf);
|
|
|
|
SCTP_FREE(vrf, SCTP_M_VRF);
|
|
|
|
}
|
|
|
|
/* free the vrf hashes */
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_HASH_FREE(SCTP_BASE_INFO(sctp_vrfhash), SCTP_BASE_INFO(hashvrfmark));
|
|
|
|
SCTP_HASH_FREE(SCTP_BASE_INFO(vrf_ifn_hash), SCTP_BASE_INFO(vrf_ifn_hashmark));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* free the TIMEWAIT list elements malloc'd in the function
|
|
|
|
* sctp_add_vtag_to_timewait()...
|
|
|
|
*/
|
2008-11-12 14:16:39 +00:00
|
|
|
for (i = 0; i < SCTP_STACK_VTAG_HASH_SIZE; i++) {
|
2008-06-14 07:58:05 +00:00
|
|
|
chain = &SCTP_BASE_INFO(vtag_timewait)[i];
|
2009-11-17 20:56:14 +00:00
|
|
|
if (!LIST_EMPTY(chain)) {
|
2008-06-14 07:58:05 +00:00
|
|
|
prev_twait_block = NULL;
|
|
|
|
LIST_FOREACH(twait_block, chain, sctp_nxt_tagblock) {
|
|
|
|
if (prev_twait_block) {
|
|
|
|
SCTP_FREE(prev_twait_block, SCTP_M_TIMW);
|
|
|
|
}
|
|
|
|
prev_twait_block = twait_block;
|
|
|
|
}
|
|
|
|
SCTP_FREE(prev_twait_block, SCTP_M_TIMW);
|
|
|
|
}
|
|
|
|
}
|
2008-05-20 13:47:46 +00:00
|
|
|
|
|
|
|
/* free the locks and mutexes */
|
|
|
|
#ifdef SCTP_PACKET_LOGGING
|
|
|
|
SCTP_IP_PKTLOG_DESTROY();
|
|
|
|
#endif
|
|
|
|
SCTP_IPI_ADDR_DESTROY();
|
|
|
|
SCTP_STATLOG_DESTROY();
|
|
|
|
SCTP_INP_INFO_LOCK_DESTROY();
|
|
|
|
|
2010-05-16 17:03:56 +00:00
|
|
|
SCTP_WQ_ADDR_DESTROY();
|
|
|
|
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_ZONE_DESTROY(SCTP_BASE_INFO(ipi_zone_ep));
|
|
|
|
SCTP_ZONE_DESTROY(SCTP_BASE_INFO(ipi_zone_asoc));
|
|
|
|
SCTP_ZONE_DESTROY(SCTP_BASE_INFO(ipi_zone_laddr));
|
|
|
|
SCTP_ZONE_DESTROY(SCTP_BASE_INFO(ipi_zone_net));
|
|
|
|
SCTP_ZONE_DESTROY(SCTP_BASE_INFO(ipi_zone_chunk));
|
|
|
|
SCTP_ZONE_DESTROY(SCTP_BASE_INFO(ipi_zone_readq));
|
|
|
|
SCTP_ZONE_DESTROY(SCTP_BASE_INFO(ipi_zone_strmoq));
|
|
|
|
SCTP_ZONE_DESTROY(SCTP_BASE_INFO(ipi_zone_asconf));
|
|
|
|
SCTP_ZONE_DESTROY(SCTP_BASE_INFO(ipi_zone_asconf_ack));
|
2008-06-15 12:31:23 +00:00
|
|
|
/* Get rid of other stuff to */
|
|
|
|
if (SCTP_BASE_INFO(sctp_asochash) != NULL)
|
|
|
|
SCTP_HASH_FREE(SCTP_BASE_INFO(sctp_asochash), SCTP_BASE_INFO(hashasocmark));
|
|
|
|
if (SCTP_BASE_INFO(sctp_ephash) != NULL)
|
|
|
|
SCTP_HASH_FREE(SCTP_BASE_INFO(sctp_ephash), SCTP_BASE_INFO(hashmark));
|
|
|
|
if (SCTP_BASE_INFO(sctp_tcpephash) != NULL)
|
|
|
|
SCTP_HASH_FREE(SCTP_BASE_INFO(sctp_tcpephash), SCTP_BASE_INFO(hashtcpmark));
|
2011-02-03 11:52:22 +00:00
|
|
|
#if defined(__FreeBSD__) && defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
|
|
|
|
SCTP_FREE(SCTP_BASE_STATS, SCTP_M_MCORE);
|
|
|
|
#endif
|
2008-05-20 13:47:46 +00:00
|
|
|
}
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
sctp_load_addresses_from_init(struct sctp_tcb *stcb, struct mbuf *m,
|
2012-06-28 16:01:08 +00:00
|
|
|
int offset, int limit,
|
|
|
|
struct sockaddr *src, struct sockaddr *dst,
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sockaddr *altsa)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* grub through the INIT pulling addresses and loading them to the
|
|
|
|
* nets structure in the asoc. The from address in the mbuf should
|
|
|
|
* also be loaded (if it is not already). This routine can be called
|
|
|
|
* with either INIT or INIT-ACK's as long as the m points to the IP
|
|
|
|
* packet and the offset points to the beginning of the parameters.
|
|
|
|
*/
|
2011-12-27 10:16:24 +00:00
|
|
|
struct sctp_inpcb *inp;
|
2010-12-30 16:56:20 +00:00
|
|
|
struct sctp_nets *net, *nnet, *net_tmp;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_paramhdr *phdr, parm_buf;
|
|
|
|
struct sctp_tcb *stcb_tmp;
|
|
|
|
uint16_t ptype, plen;
|
|
|
|
struct sockaddr *sa;
|
2007-02-12 23:24:31 +00:00
|
|
|
uint8_t random_store[SCTP_PARAM_BUFFER_SIZE];
|
2007-03-31 11:47:30 +00:00
|
|
|
struct sctp_auth_random *p_random = NULL;
|
2006-11-03 15:23:16 +00:00
|
|
|
uint16_t random_len = 0;
|
2007-02-12 23:24:31 +00:00
|
|
|
uint8_t hmacs_store[SCTP_PARAM_BUFFER_SIZE];
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_auth_hmac_algo *hmacs = NULL;
|
|
|
|
uint16_t hmacs_len = 0;
|
2007-08-27 05:19:48 +00:00
|
|
|
uint8_t saw_asconf = 0;
|
|
|
|
uint8_t saw_asconf_ack = 0;
|
2007-02-12 23:24:31 +00:00
|
|
|
uint8_t chunks_store[SCTP_PARAM_BUFFER_SIZE];
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_auth_chunk_list *chunks = NULL;
|
|
|
|
uint16_t num_chunks = 0;
|
|
|
|
sctp_key_t *new_key;
|
|
|
|
uint32_t keylen;
|
|
|
|
int got_random = 0, got_hmacs = 0, got_chklist = 0;
|
2014-08-12 11:30:16 +00:00
|
|
|
uint8_t peer_supports_ecn;
|
|
|
|
uint8_t peer_supports_prsctp;
|
|
|
|
uint8_t peer_supports_auth;
|
|
|
|
uint8_t peer_supports_asconf;
|
|
|
|
uint8_t peer_supports_asconf_ack;
|
|
|
|
uint8_t peer_supports_reconfig;
|
|
|
|
uint8_t peer_supports_nrsack;
|
|
|
|
uint8_t peer_supports_pktdrop;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2011-04-30 11:18:16 +00:00
|
|
|
#ifdef INET
|
|
|
|
struct sockaddr_in sin;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
struct sockaddr_in6 sin6;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/* First get the destination address setup too. */
|
2011-04-30 11:18:16 +00:00
|
|
|
#ifdef INET
|
2006-11-03 15:23:16 +00:00
|
|
|
memset(&sin, 0, sizeof(sin));
|
|
|
|
sin.sin_family = AF_INET;
|
|
|
|
sin.sin_len = sizeof(sin);
|
|
|
|
sin.sin_port = stcb->rport;
|
2011-04-30 11:18:16 +00:00
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
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;
|
2011-04-30 11:18:16 +00:00
|
|
|
#endif
|
2012-06-28 16:01:08 +00:00
|
|
|
if (altsa) {
|
|
|
|
sa = altsa;
|
|
|
|
} else {
|
|
|
|
sa = src;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2014-08-12 11:30:16 +00:00
|
|
|
peer_supports_ecn = 0;
|
|
|
|
peer_supports_prsctp = 0;
|
|
|
|
peer_supports_auth = 0;
|
|
|
|
peer_supports_asconf = 0;
|
|
|
|
peer_supports_reconfig = 0;
|
|
|
|
peer_supports_nrsack = 0;
|
|
|
|
peer_supports_pktdrop = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
|
|
|
|
/* mark all addresses that we have currently on the list */
|
|
|
|
net->dest_state |= SCTP_ADDR_NOT_IN_ASSOC;
|
|
|
|
}
|
|
|
|
/* does the source address already exist? if so skip it */
|
2011-12-27 10:16:24 +00:00
|
|
|
inp = stcb->sctp_ep;
|
2006-11-05 13:25:18 +00:00
|
|
|
atomic_add_int(&stcb->asoc.refcnt, 1);
|
2012-06-28 16:01:08 +00:00
|
|
|
stcb_tmp = sctp_findassociation_ep_addr(&inp, sa, &net_tmp, dst, stcb);
|
2006-11-05 13:25:18 +00:00
|
|
|
atomic_add_int(&stcb->asoc.refcnt, -1);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
if ((stcb_tmp == NULL && inp == stcb->sctp_ep) || inp == NULL) {
|
|
|
|
/* we must add the source address */
|
|
|
|
/* no scope set here since we have a tcb already. */
|
2011-04-30 11:18:16 +00:00
|
|
|
switch (sa->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
2013-02-09 17:26:14 +00:00
|
|
|
if (stcb->asoc.scope.ipv4_addr_legal) {
|
2011-08-03 20:21:00 +00:00
|
|
|
if (sctp_add_remote_addr(stcb, sa, NULL, SCTP_DONOT_SETSCOPE, SCTP_LOAD_ADDR_2)) {
|
2011-04-30 11:18:16 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
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-08-03 20:21:00 +00:00
|
|
|
if (sctp_add_remote_addr(stcb, sa, NULL, SCTP_DONOT_SETSCOPE, SCTP_LOAD_ADDR_3)) {
|
2011-04-30 11:18:16 +00:00
|
|
|
return (-2);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (net_tmp != NULL && stcb_tmp == stcb) {
|
|
|
|
net_tmp->dest_state &= ~SCTP_ADDR_NOT_IN_ASSOC;
|
|
|
|
} else if (stcb_tmp != stcb) {
|
|
|
|
/* It belongs to another association? */
|
2007-06-18 21:59:15 +00:00
|
|
|
if (stcb_tmp)
|
|
|
|
SCTP_TCB_UNLOCK(stcb_tmp);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (-3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (stcb->asoc.state == 0) {
|
|
|
|
/* the assoc was freed? */
|
|
|
|
return (-4);
|
|
|
|
}
|
|
|
|
/* now we must go through each of the params. */
|
|
|
|
phdr = sctp_get_next_param(m, offset, &parm_buf, sizeof(parm_buf));
|
|
|
|
while (phdr) {
|
|
|
|
ptype = ntohs(phdr->param_type);
|
|
|
|
plen = ntohs(phdr->param_length);
|
|
|
|
/*
|
2012-05-04 09:27:00 +00:00
|
|
|
* SCTP_PRINTF("ptype => %0x, plen => %d\n",
|
|
|
|
* (uint32_t)ptype, (int)plen);
|
2006-11-03 15:23:16 +00:00
|
|
|
*/
|
|
|
|
if (offset + plen > limit) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (plen == 0) {
|
|
|
|
break;
|
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
#ifdef INET
|
2006-11-03 15:23:16 +00:00
|
|
|
if (ptype == SCTP_IPV4_ADDRESS) {
|
2013-02-09 17:26:14 +00:00
|
|
|
if (stcb->asoc.scope.ipv4_addr_legal) {
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_ipv4addr_param *p4, p4_buf;
|
|
|
|
|
|
|
|
/* ok get the v4 address and check/add */
|
|
|
|
phdr = sctp_get_next_param(m, offset,
|
2009-02-03 11:04:03 +00:00
|
|
|
(struct sctp_paramhdr *)&p4_buf,
|
|
|
|
sizeof(p4_buf));
|
2006-11-03 15:23:16 +00:00
|
|
|
if (plen != sizeof(struct sctp_ipv4addr_param) ||
|
|
|
|
phdr == NULL) {
|
|
|
|
return (-5);
|
|
|
|
}
|
|
|
|
p4 = (struct sctp_ipv4addr_param *)phdr;
|
|
|
|
sin.sin_addr.s_addr = p4->addr;
|
2010-09-01 16:11:26 +00:00
|
|
|
if (IN_MULTICAST(ntohl(sin.sin_addr.s_addr))) {
|
2007-05-02 12:50:13 +00:00
|
|
|
/* Skip multi-cast addresses */
|
|
|
|
goto next_param;
|
|
|
|
}
|
2007-05-08 00:21:05 +00:00
|
|
|
if ((sin.sin_addr.s_addr == INADDR_BROADCAST) ||
|
|
|
|
(sin.sin_addr.s_addr == INADDR_ANY)) {
|
|
|
|
goto next_param;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
sa = (struct sockaddr *)&sin;
|
|
|
|
inp = stcb->sctp_ep;
|
2006-11-05 13:25:18 +00:00
|
|
|
atomic_add_int(&stcb->asoc.refcnt, 1);
|
2006-11-03 15:23:16 +00:00
|
|
|
stcb_tmp = sctp_findassociation_ep_addr(&inp, sa, &net,
|
2012-06-28 16:01:08 +00:00
|
|
|
dst, stcb);
|
2006-11-05 13:25:18 +00:00
|
|
|
atomic_add_int(&stcb->asoc.refcnt, -1);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
if ((stcb_tmp == NULL && inp == stcb->sctp_ep) ||
|
|
|
|
inp == NULL) {
|
|
|
|
/* we must add the source address */
|
|
|
|
/*
|
|
|
|
* no scope set since we have a tcb
|
|
|
|
* already
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we must validate the state again
|
|
|
|
* here
|
|
|
|
*/
|
2008-07-31 11:08:30 +00:00
|
|
|
add_it_now:
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb->asoc.state == 0) {
|
|
|
|
/* the assoc was freed? */
|
|
|
|
return (-7);
|
|
|
|
}
|
2011-08-03 20:21:00 +00:00
|
|
|
if (sctp_add_remote_addr(stcb, sa, NULL, SCTP_DONOT_SETSCOPE, SCTP_LOAD_ADDR_4)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
return (-8);
|
|
|
|
}
|
|
|
|
} else if (stcb_tmp == stcb) {
|
|
|
|
if (stcb->asoc.state == 0) {
|
|
|
|
/* the assoc was freed? */
|
|
|
|
return (-10);
|
|
|
|
}
|
|
|
|
if (net != NULL) {
|
|
|
|
/* clear flag */
|
|
|
|
net->dest_state &=
|
|
|
|
~SCTP_ADDR_NOT_IN_ASSOC;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* strange, address is in another
|
|
|
|
* assoc? straighten out locks.
|
|
|
|
*/
|
2008-07-31 11:08:30 +00:00
|
|
|
if (stcb_tmp) {
|
|
|
|
if (SCTP_GET_STATE(&stcb_tmp->asoc) & SCTP_STATE_COOKIE_WAIT) {
|
|
|
|
/*
|
|
|
|
* in setup state we
|
|
|
|
* abort this guy
|
|
|
|
*/
|
|
|
|
sctp_abort_an_association(stcb_tmp->sctp_ep,
|
2012-05-12 20:11:35 +00:00
|
|
|
stcb_tmp, NULL, SCTP_SO_NOT_LOCKED);
|
2008-07-31 11:08:30 +00:00
|
|
|
goto add_it_now;
|
|
|
|
}
|
2007-07-21 21:41:32 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb_tmp);
|
2008-07-31 11:08:30 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb->asoc.state == 0) {
|
|
|
|
/* the assoc was freed? */
|
|
|
|
return (-12);
|
|
|
|
}
|
|
|
|
return (-13);
|
|
|
|
}
|
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
if (ptype == SCTP_IPV6_ADDRESS) {
|
2013-02-09 17:26:14 +00:00
|
|
|
if (stcb->asoc.scope.ipv6_addr_legal) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* ok get the v6 address and check/add */
|
|
|
|
struct sctp_ipv6addr_param *p6, p6_buf;
|
|
|
|
|
|
|
|
phdr = sctp_get_next_param(m, offset,
|
2009-02-03 11:04:03 +00:00
|
|
|
(struct sctp_paramhdr *)&p6_buf,
|
|
|
|
sizeof(p6_buf));
|
2006-11-03 15:23:16 +00:00
|
|
|
if (plen != sizeof(struct sctp_ipv6addr_param) ||
|
|
|
|
phdr == NULL) {
|
|
|
|
return (-14);
|
|
|
|
}
|
|
|
|
p6 = (struct sctp_ipv6addr_param *)phdr;
|
|
|
|
memcpy((caddr_t)&sin6.sin6_addr, p6->addr,
|
|
|
|
sizeof(p6->addr));
|
2007-05-02 12:50:13 +00:00
|
|
|
if (IN6_IS_ADDR_MULTICAST(&sin6.sin6_addr)) {
|
|
|
|
/* Skip multi-cast addresses */
|
|
|
|
goto next_param;
|
|
|
|
}
|
|
|
|
if (IN6_IS_ADDR_LINKLOCAL(&sin6.sin6_addr)) {
|
|
|
|
/*
|
|
|
|
* Link local make no sense without
|
|
|
|
* scope
|
|
|
|
*/
|
|
|
|
goto next_param;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
sa = (struct sockaddr *)&sin6;
|
|
|
|
inp = stcb->sctp_ep;
|
2006-11-05 13:25:18 +00:00
|
|
|
atomic_add_int(&stcb->asoc.refcnt, 1);
|
2006-11-03 15:23:16 +00:00
|
|
|
stcb_tmp = sctp_findassociation_ep_addr(&inp, sa, &net,
|
2012-06-28 16:01:08 +00:00
|
|
|
dst, stcb);
|
2006-11-05 13:25:18 +00:00
|
|
|
atomic_add_int(&stcb->asoc.refcnt, -1);
|
2009-02-03 11:04:03 +00:00
|
|
|
if (stcb_tmp == NULL &&
|
|
|
|
(inp == stcb->sctp_ep || inp == NULL)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* we must validate the state again
|
|
|
|
* here
|
|
|
|
*/
|
2008-07-31 11:08:30 +00:00
|
|
|
add_it_now6:
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb->asoc.state == 0) {
|
|
|
|
/* the assoc was freed? */
|
|
|
|
return (-16);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* we must add the address, no scope
|
|
|
|
* set
|
|
|
|
*/
|
2011-08-03 20:21:00 +00:00
|
|
|
if (sctp_add_remote_addr(stcb, sa, NULL, SCTP_DONOT_SETSCOPE, SCTP_LOAD_ADDR_5)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
return (-17);
|
|
|
|
}
|
|
|
|
} else if (stcb_tmp == stcb) {
|
|
|
|
/*
|
|
|
|
* we must validate the state again
|
|
|
|
* here
|
|
|
|
*/
|
|
|
|
if (stcb->asoc.state == 0) {
|
|
|
|
/* the assoc was freed? */
|
|
|
|
return (-19);
|
|
|
|
}
|
|
|
|
if (net != NULL) {
|
|
|
|
/* clear flag */
|
|
|
|
net->dest_state &=
|
|
|
|
~SCTP_ADDR_NOT_IN_ASSOC;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* strange, address is in another
|
|
|
|
* assoc? straighten out locks.
|
|
|
|
*/
|
2007-07-21 21:41:32 +00:00
|
|
|
if (stcb_tmp)
|
2008-07-31 11:08:30 +00:00
|
|
|
if (SCTP_GET_STATE(&stcb_tmp->asoc) & SCTP_STATE_COOKIE_WAIT) {
|
|
|
|
/*
|
|
|
|
* in setup state we
|
|
|
|
* abort this guy
|
|
|
|
*/
|
|
|
|
sctp_abort_an_association(stcb_tmp->sctp_ep,
|
2012-05-12 20:11:35 +00:00
|
|
|
stcb_tmp, NULL, SCTP_SO_NOT_LOCKED);
|
2008-07-31 11:08:30 +00:00
|
|
|
goto add_it_now6;
|
|
|
|
}
|
|
|
|
SCTP_TCB_UNLOCK(stcb_tmp);
|
2007-07-21 21:41:32 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb->asoc.state == 0) {
|
|
|
|
/* the assoc was freed? */
|
|
|
|
return (-21);
|
|
|
|
}
|
|
|
|
return (-22);
|
|
|
|
}
|
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
if (ptype == SCTP_ECN_CAPABLE) {
|
2014-08-12 11:30:16 +00:00
|
|
|
peer_supports_ecn = 1;
|
2006-11-03 15:23:16 +00:00
|
|
|
} else if (ptype == SCTP_ULP_ADAPTATION) {
|
|
|
|
if (stcb->asoc.state != SCTP_STATE_OPEN) {
|
|
|
|
struct sctp_adaptation_layer_indication ai,
|
|
|
|
*aip;
|
|
|
|
|
|
|
|
phdr = sctp_get_next_param(m, offset,
|
|
|
|
(struct sctp_paramhdr *)&ai, sizeof(ai));
|
|
|
|
aip = (struct sctp_adaptation_layer_indication *)phdr;
|
2007-05-08 14:32:53 +00:00
|
|
|
if (aip) {
|
2007-08-27 05:19:48 +00:00
|
|
|
stcb->asoc.peers_adaptation = ntohl(aip->indication);
|
|
|
|
stcb->asoc.adaptation_needed = 1;
|
2007-05-08 14:32:53 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
} else if (ptype == SCTP_SET_PRIM_ADDR) {
|
|
|
|
struct sctp_asconf_addr_param lstore, *fee;
|
|
|
|
int lptype;
|
|
|
|
struct sockaddr *lsa = NULL;
|
|
|
|
|
2011-04-30 11:18:16 +00:00
|
|
|
#ifdef INET
|
|
|
|
struct sctp_asconf_addrv4_param *fii;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2014-08-12 11:30:16 +00:00
|
|
|
if (stcb->asoc.asconf_supported == 0) {
|
|
|
|
return (-100);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if (plen > sizeof(lstore)) {
|
|
|
|
return (-23);
|
|
|
|
}
|
|
|
|
phdr = sctp_get_next_param(m, offset,
|
2009-02-03 11:04:03 +00:00
|
|
|
(struct sctp_paramhdr *)&lstore,
|
|
|
|
min(plen, sizeof(lstore)));
|
2006-11-03 15:23:16 +00:00
|
|
|
if (phdr == NULL) {
|
|
|
|
return (-24);
|
|
|
|
}
|
|
|
|
fee = (struct sctp_asconf_addr_param *)phdr;
|
|
|
|
lptype = ntohs(fee->addrp.ph.param_type);
|
2011-04-30 11:18:16 +00:00
|
|
|
switch (lptype) {
|
|
|
|
#ifdef INET
|
|
|
|
case SCTP_IPV4_ADDRESS:
|
2006-11-03 15:23:16 +00:00
|
|
|
if (plen !=
|
|
|
|
sizeof(struct sctp_asconf_addrv4_param)) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("Sizeof setprim in init/init ack not %d but %d - ignored\n",
|
2006-11-03 15:23:16 +00:00
|
|
|
(int)sizeof(struct sctp_asconf_addrv4_param),
|
|
|
|
plen);
|
|
|
|
} else {
|
|
|
|
fii = (struct sctp_asconf_addrv4_param *)fee;
|
|
|
|
sin.sin_addr.s_addr = fii->addrp.addr;
|
|
|
|
lsa = (struct sockaddr *)&sin;
|
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case SCTP_IPV6_ADDRESS:
|
2006-11-03 15:23:16 +00:00
|
|
|
if (plen !=
|
|
|
|
sizeof(struct sctp_asconf_addr_param)) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("Sizeof setprim (v6) in init/init ack not %d but %d - ignored\n",
|
2006-11-03 15:23:16 +00:00
|
|
|
(int)sizeof(struct sctp_asconf_addr_param),
|
|
|
|
plen);
|
|
|
|
} else {
|
|
|
|
memcpy(sin6.sin6_addr.s6_addr,
|
|
|
|
fee->addrp.addr,
|
|
|
|
sizeof(fee->addrp.addr));
|
|
|
|
lsa = (struct sockaddr *)&sin6;
|
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
if (lsa) {
|
2007-05-09 13:30:06 +00:00
|
|
|
(void)sctp_set_primary_addr(stcb, sa, NULL);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2008-12-06 13:19:54 +00:00
|
|
|
} else if (ptype == SCTP_HAS_NAT_SUPPORT) {
|
|
|
|
stcb->asoc.peer_supports_nat = 1;
|
2006-11-03 15:23:16 +00:00
|
|
|
} else if (ptype == SCTP_PRSCTP_SUPPORTED) {
|
|
|
|
/* Peer supports pr-sctp */
|
2014-08-12 11:30:16 +00:00
|
|
|
peer_supports_prsctp = 1;
|
2006-11-03 15:23:16 +00:00
|
|
|
} else if (ptype == SCTP_SUPPORTED_CHUNK_EXT) {
|
|
|
|
/* A supported extension chunk */
|
|
|
|
struct sctp_supported_chunk_types_param *pr_supported;
|
2007-02-12 23:24:31 +00:00
|
|
|
uint8_t local_store[SCTP_PARAM_BUFFER_SIZE];
|
2006-11-03 15:23:16 +00:00
|
|
|
int num_ent, i;
|
|
|
|
|
|
|
|
phdr = sctp_get_next_param(m, offset,
|
2007-05-02 12:50:13 +00:00
|
|
|
(struct sctp_paramhdr *)&local_store, min(sizeof(local_store), plen));
|
2006-11-03 15:23:16 +00:00
|
|
|
if (phdr == NULL) {
|
|
|
|
return (-25);
|
|
|
|
}
|
|
|
|
pr_supported = (struct sctp_supported_chunk_types_param *)phdr;
|
|
|
|
num_ent = plen - sizeof(struct sctp_paramhdr);
|
|
|
|
for (i = 0; i < num_ent; i++) {
|
|
|
|
switch (pr_supported->chunk_types[i]) {
|
|
|
|
case SCTP_ASCONF:
|
2014-08-12 11:30:16 +00:00
|
|
|
peer_supports_asconf = 1;
|
2014-12-17 20:34:38 +00:00
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
case SCTP_ASCONF_ACK:
|
2014-08-12 11:30:16 +00:00
|
|
|
peer_supports_asconf_ack = 1;
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_FORWARD_CUM_TSN:
|
2014-08-12 11:30:16 +00:00
|
|
|
peer_supports_prsctp = 1;
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_PACKET_DROPPED:
|
2014-08-12 11:30:16 +00:00
|
|
|
peer_supports_pktdrop = 1;
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
2009-04-04 11:43:32 +00:00
|
|
|
case SCTP_NR_SELECTIVE_ACK:
|
2014-08-12 11:30:16 +00:00
|
|
|
peer_supports_nrsack = 1;
|
2009-04-04 11:43:32 +00:00
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
case SCTP_STREAM_RESET:
|
2014-08-12 11:30:16 +00:00
|
|
|
peer_supports_reconfig = 1;
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_AUTHENTICATION:
|
2014-08-12 11:30:16 +00:00
|
|
|
peer_supports_auth = 1;
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* one I have not learned yet */
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (ptype == SCTP_RANDOM) {
|
2007-02-12 23:24:31 +00:00
|
|
|
if (plen > sizeof(random_store))
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
if (got_random) {
|
|
|
|
/* already processed a RANDOM */
|
|
|
|
goto next_param;
|
|
|
|
}
|
|
|
|
phdr = sctp_get_next_param(m, offset,
|
2007-02-12 23:24:31 +00:00
|
|
|
(struct sctp_paramhdr *)random_store,
|
2007-05-02 12:50:13 +00:00
|
|
|
min(sizeof(random_store), plen));
|
2006-11-03 15:23:16 +00:00
|
|
|
if (phdr == NULL)
|
|
|
|
return (-26);
|
2007-03-31 11:47:30 +00:00
|
|
|
p_random = (struct sctp_auth_random *)phdr;
|
|
|
|
random_len = plen - sizeof(*p_random);
|
2006-11-03 15:23:16 +00:00
|
|
|
/* enforce the random length */
|
|
|
|
if (random_len != SCTP_AUTH_RANDOM_SIZE_REQUIRED) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_AUTH1, "SCTP: invalid RANDOM len\n");
|
2006-11-03 15:23:16 +00:00
|
|
|
return (-27);
|
|
|
|
}
|
|
|
|
got_random = 1;
|
|
|
|
} else if (ptype == SCTP_HMAC_LIST) {
|
2014-09-16 14:20:33 +00:00
|
|
|
uint16_t num_hmacs;
|
|
|
|
uint16_t i;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
if (plen > sizeof(hmacs_store))
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
if (got_hmacs) {
|
|
|
|
/* already processed a HMAC list */
|
|
|
|
goto next_param;
|
|
|
|
}
|
|
|
|
phdr = sctp_get_next_param(m, offset,
|
2007-02-12 23:24:31 +00:00
|
|
|
(struct sctp_paramhdr *)hmacs_store,
|
2007-05-02 12:50:13 +00:00
|
|
|
min(plen, sizeof(hmacs_store)));
|
2006-11-03 15:23:16 +00:00
|
|
|
if (phdr == NULL)
|
|
|
|
return (-28);
|
|
|
|
hmacs = (struct sctp_auth_hmac_algo *)phdr;
|
|
|
|
hmacs_len = plen - sizeof(*hmacs);
|
|
|
|
num_hmacs = hmacs_len / sizeof(hmacs->hmac_ids[0]);
|
|
|
|
/* validate the hmac list */
|
|
|
|
if (sctp_verify_hmac_param(hmacs, num_hmacs)) {
|
|
|
|
return (-29);
|
|
|
|
}
|
|
|
|
if (stcb->asoc.peer_hmacs != NULL)
|
|
|
|
sctp_free_hmaclist(stcb->asoc.peer_hmacs);
|
|
|
|
stcb->asoc.peer_hmacs = sctp_alloc_hmaclist(num_hmacs);
|
|
|
|
if (stcb->asoc.peer_hmacs != NULL) {
|
|
|
|
for (i = 0; i < num_hmacs; i++) {
|
2007-05-08 14:32:53 +00:00
|
|
|
(void)sctp_auth_add_hmacid(stcb->asoc.peer_hmacs,
|
2006-11-03 15:23:16 +00:00
|
|
|
ntohs(hmacs->hmac_ids[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
got_hmacs = 1;
|
|
|
|
} else if (ptype == SCTP_CHUNK_LIST) {
|
|
|
|
int i;
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
if (plen > sizeof(chunks_store))
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
if (got_chklist) {
|
|
|
|
/* already processed a Chunks list */
|
|
|
|
goto next_param;
|
|
|
|
}
|
|
|
|
phdr = sctp_get_next_param(m, offset,
|
2007-02-12 23:24:31 +00:00
|
|
|
(struct sctp_paramhdr *)chunks_store,
|
2007-05-02 12:50:13 +00:00
|
|
|
min(plen, sizeof(chunks_store)));
|
2006-11-03 15:23:16 +00:00
|
|
|
if (phdr == NULL)
|
|
|
|
return (-30);
|
|
|
|
chunks = (struct sctp_auth_chunk_list *)phdr;
|
|
|
|
num_chunks = plen - sizeof(*chunks);
|
|
|
|
if (stcb->asoc.peer_auth_chunks != NULL)
|
|
|
|
sctp_clear_chunklist(stcb->asoc.peer_auth_chunks);
|
|
|
|
else
|
|
|
|
stcb->asoc.peer_auth_chunks = sctp_alloc_chunklist();
|
|
|
|
for (i = 0; i < num_chunks; i++) {
|
2007-05-08 14:32:53 +00:00
|
|
|
(void)sctp_auth_add_chunk(chunks->chunk_types[i],
|
2006-11-03 15:23:16 +00:00
|
|
|
stcb->asoc.peer_auth_chunks);
|
2007-08-27 05:19:48 +00:00
|
|
|
/* record asconf/asconf-ack if listed */
|
|
|
|
if (chunks->chunk_types[i] == SCTP_ASCONF)
|
|
|
|
saw_asconf = 1;
|
|
|
|
if (chunks->chunk_types[i] == SCTP_ASCONF_ACK)
|
|
|
|
saw_asconf_ack = 1;
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
got_chklist = 1;
|
|
|
|
} else if ((ptype == SCTP_HEARTBEAT_INFO) ||
|
|
|
|
(ptype == SCTP_STATE_COOKIE) ||
|
|
|
|
(ptype == SCTP_UNRECOG_PARAM) ||
|
|
|
|
(ptype == SCTP_COOKIE_PRESERVE) ||
|
|
|
|
(ptype == SCTP_SUPPORTED_ADDRTYPE) ||
|
|
|
|
(ptype == SCTP_ADD_IP_ADDRESS) ||
|
|
|
|
(ptype == SCTP_DEL_IP_ADDRESS) ||
|
|
|
|
(ptype == SCTP_ERROR_CAUSE_IND) ||
|
|
|
|
(ptype == SCTP_SUCCESS_REPORT)) {
|
|
|
|
/* don't care */ ;
|
|
|
|
} else {
|
|
|
|
if ((ptype & 0x8000) == 0x0000) {
|
|
|
|
/*
|
|
|
|
* must stop processing the rest of the
|
|
|
|
* param's. Any report bits were handled
|
|
|
|
* with the call to
|
|
|
|
* sctp_arethere_unrecognized_parameters()
|
|
|
|
* when the INIT or INIT-ACK was first seen.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-02-03 11:04:03 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
next_param:
|
|
|
|
offset += SCTP_SIZE32(plen);
|
|
|
|
if (offset >= limit) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
phdr = sctp_get_next_param(m, offset, &parm_buf,
|
|
|
|
sizeof(parm_buf));
|
|
|
|
}
|
|
|
|
/* Now check to see if we need to purge any addresses */
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_FOREACH_SAFE(net, &stcb->asoc.nets, sctp_next, nnet) {
|
2006-11-03 15:23:16 +00:00
|
|
|
if ((net->dest_state & SCTP_ADDR_NOT_IN_ASSOC) ==
|
|
|
|
SCTP_ADDR_NOT_IN_ASSOC) {
|
|
|
|
/* This address has been removed from the asoc */
|
|
|
|
/* remove and free it */
|
|
|
|
stcb->asoc.numnets--;
|
|
|
|
TAILQ_REMOVE(&stcb->asoc.nets, net, sctp_next);
|
|
|
|
sctp_free_remote_addr(net);
|
|
|
|
if (net == stcb->asoc.primary_destination) {
|
|
|
|
stcb->asoc.primary_destination = NULL;
|
|
|
|
sctp_select_primary_destination(stcb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-12 11:30:16 +00:00
|
|
|
if ((stcb->asoc.ecn_supported == 1) &&
|
|
|
|
(peer_supports_ecn == 0)) {
|
|
|
|
stcb->asoc.ecn_supported = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2014-08-12 11:30:16 +00:00
|
|
|
if ((stcb->asoc.prsctp_supported == 1) &&
|
|
|
|
(peer_supports_prsctp == 0)) {
|
|
|
|
stcb->asoc.prsctp_supported = 0;
|
|
|
|
}
|
|
|
|
if ((stcb->asoc.auth_supported == 1) &&
|
|
|
|
((peer_supports_auth == 0) ||
|
|
|
|
(got_random == 0) || (got_hmacs == 0))) {
|
|
|
|
stcb->asoc.auth_supported = 0;
|
|
|
|
}
|
|
|
|
if ((stcb->asoc.asconf_supported == 1) &&
|
|
|
|
((peer_supports_asconf == 0) || (peer_supports_asconf_ack == 0) ||
|
|
|
|
(stcb->asoc.auth_supported == 0) ||
|
|
|
|
(saw_asconf == 0) || (saw_asconf_ack == 0))) {
|
|
|
|
stcb->asoc.asconf_supported = 0;
|
|
|
|
}
|
|
|
|
if ((stcb->asoc.reconfig_supported == 1) &&
|
|
|
|
(peer_supports_reconfig == 0)) {
|
|
|
|
stcb->asoc.reconfig_supported = 0;
|
|
|
|
}
|
|
|
|
if ((stcb->asoc.nrsack_supported == 1) &&
|
|
|
|
(peer_supports_nrsack == 0)) {
|
|
|
|
stcb->asoc.nrsack_supported = 0;
|
|
|
|
}
|
|
|
|
if ((stcb->asoc.pktdrop_supported == 1) &&
|
|
|
|
(peer_supports_pktdrop == 0)) {
|
|
|
|
stcb->asoc.pktdrop_supported = 0;
|
|
|
|
}
|
|
|
|
/* validate authentication required parameters */
|
|
|
|
if ((peer_supports_auth == 0) && (got_chklist == 1)) {
|
2007-03-31 11:47:30 +00:00
|
|
|
/* peer does not support auth but sent a chunks list? */
|
|
|
|
return (-31);
|
|
|
|
}
|
2014-08-12 11:30:16 +00:00
|
|
|
if ((peer_supports_asconf == 1) && (peer_supports_auth == 0)) {
|
2007-03-31 11:47:30 +00:00
|
|
|
/* peer supports asconf but not auth? */
|
|
|
|
return (-32);
|
2014-08-12 11:30:16 +00:00
|
|
|
} else if ((peer_supports_asconf == 1) &&
|
|
|
|
(peer_supports_auth == 1) &&
|
2007-08-27 05:19:48 +00:00
|
|
|
((saw_asconf == 0) || (saw_asconf_ack == 0))) {
|
|
|
|
return (-33);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
/* concatenate the full random key */
|
2009-02-03 11:04:03 +00:00
|
|
|
keylen = sizeof(*p_random) + random_len + sizeof(*hmacs) + hmacs_len;
|
|
|
|
if (chunks != NULL) {
|
|
|
|
keylen += sizeof(*chunks) + num_chunks;
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
new_key = sctp_alloc_key(keylen);
|
|
|
|
if (new_key != NULL) {
|
|
|
|
/* copy in the RANDOM */
|
2007-03-31 11:47:30 +00:00
|
|
|
if (p_random != NULL) {
|
|
|
|
keylen = sizeof(*p_random) + random_len;
|
|
|
|
bcopy(p_random, new_key->key, keylen);
|
2007-02-12 23:24:31 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
/* append in the AUTH chunks */
|
2007-02-12 23:24:31 +00:00
|
|
|
if (chunks != NULL) {
|
|
|
|
bcopy(chunks, new_key->key + keylen,
|
|
|
|
sizeof(*chunks) + num_chunks);
|
|
|
|
keylen += sizeof(*chunks) + num_chunks;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
/* append in the HMACs */
|
2007-02-12 23:24:31 +00:00
|
|
|
if (hmacs != NULL) {
|
|
|
|
bcopy(hmacs, new_key->key + keylen,
|
|
|
|
sizeof(*hmacs) + hmacs_len);
|
|
|
|
}
|
2010-01-16 20:04:17 +00:00
|
|
|
} else {
|
2007-03-31 11:47:30 +00:00
|
|
|
/* failed to get memory for the key */
|
2007-08-27 05:19:48 +00:00
|
|
|
return (-34);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
if (stcb->asoc.authinfo.peer_random != NULL)
|
|
|
|
sctp_free_key(stcb->asoc.authinfo.peer_random);
|
|
|
|
stcb->asoc.authinfo.peer_random = new_key;
|
|
|
|
sctp_clear_cachedkeys(stcb, stcb->asoc.authinfo.assoc_keyid);
|
|
|
|
sctp_clear_cachedkeys(stcb, stcb->asoc.authinfo.recv_keyid);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sctp_set_primary_addr(struct sctp_tcb *stcb, struct sockaddr *sa,
|
|
|
|
struct sctp_nets *net)
|
|
|
|
{
|
|
|
|
/* make sure the requested primary address exists in the assoc */
|
|
|
|
if (net == NULL && sa)
|
|
|
|
net = sctp_findnet(stcb, sa);
|
|
|
|
|
|
|
|
if (net == NULL) {
|
|
|
|
/* didn't find the requested primary address! */
|
|
|
|
return (-1);
|
|
|
|
} else {
|
|
|
|
/* set the primary address */
|
|
|
|
if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
|
2007-03-15 11:27:14 +00:00
|
|
|
/* Must be confirmed, so queue to set */
|
|
|
|
net->dest_state |= SCTP_ADDR_REQ_PRIMARY;
|
|
|
|
return (0);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
stcb->asoc.primary_destination = net;
|
2011-08-03 20:21:00 +00:00
|
|
|
if (!(net->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
|
|
|
net = TAILQ_FIRST(&stcb->asoc.nets);
|
|
|
|
if (net != stcb->asoc.primary_destination) {
|
|
|
|
/*
|
|
|
|
* first one on the list is NOT the primary
|
2010-11-09 10:59:09 +00:00
|
|
|
* sctp_cmpaddr() is much more efficient if the
|
2006-11-03 15:23:16 +00:00
|
|
|
* primary is the first on the list, make it so.
|
|
|
|
*/
|
|
|
|
TAILQ_REMOVE(&stcb->asoc.nets, stcb->asoc.primary_destination, sctp_next);
|
|
|
|
TAILQ_INSERT_HEAD(&stcb->asoc.nets, stcb->asoc.primary_destination, sctp_next);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-12-17 19:21:40 +00:00
|
|
|
sctp_is_vtag_good(uint32_t tag, uint16_t lport, uint16_t rport, struct timeval *now)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This function serves two purposes. It will see if a TAG can be
|
|
|
|
* re-used and return 1 for yes it is ok and 0 for don't use that
|
|
|
|
* tag. A secondary function it will do is purge out old tags that
|
|
|
|
* can be removed.
|
|
|
|
*/
|
|
|
|
struct sctpvtaghead *chain;
|
|
|
|
struct sctp_tagblock *twait_block;
|
2008-12-06 13:19:54 +00:00
|
|
|
struct sctpasochead *head;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_tcb *stcb;
|
|
|
|
int i;
|
|
|
|
|
2008-12-06 13:19:54 +00:00
|
|
|
SCTP_INP_INFO_RLOCK();
|
2008-06-14 07:58:05 +00:00
|
|
|
head = &SCTP_BASE_INFO(sctp_asochash)[SCTP_PCBHASH_ASOC(tag,
|
|
|
|
SCTP_BASE_INFO(hashasocmark))];
|
2006-11-03 15:23:16 +00:00
|
|
|
LIST_FOREACH(stcb, head, sctp_asocs) {
|
2008-12-06 13:19:54 +00:00
|
|
|
/*
|
|
|
|
* We choose not to lock anything here. TCB's can't be
|
|
|
|
* removed since we have the read lock, so they can't be
|
|
|
|
* freed on us, same thing for the INP. I may be wrong with
|
|
|
|
* this assumption, but we will go with it for now :-)
|
|
|
|
*/
|
|
|
|
if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) {
|
|
|
|
continue;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2008-12-06 13:19:54 +00:00
|
|
|
if (stcb->asoc.my_vtag == tag) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* candidate */
|
2008-12-06 13:19:54 +00:00
|
|
|
if (stcb->rport != rport) {
|
|
|
|
continue;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2008-12-06 13:19:54 +00:00
|
|
|
if (stcb->sctp_ep->sctp_lport != lport) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* Its a used tag set */
|
2010-07-02 09:53:26 +00:00
|
|
|
SCTP_INP_INFO_RUNLOCK();
|
2008-12-06 13:19:54 +00:00
|
|
|
return (0);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-04 18:25:38 +00:00
|
|
|
chain = &SCTP_BASE_INFO(vtag_timewait)[(tag % SCTP_STACK_VTAG_HASH_SIZE)];
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Now what about timed wait ? */
|
2013-07-03 18:48:43 +00:00
|
|
|
LIST_FOREACH(twait_block, chain, sctp_nxt_tagblock) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* Block(s) are present, lets see if we have this tag in the
|
|
|
|
* list
|
|
|
|
*/
|
2013-07-03 18:48:43 +00:00
|
|
|
for (i = 0; i < SCTP_NUMBER_IN_VTAG_BLOCK; i++) {
|
|
|
|
if (twait_block->vtag_block[i].v_tag == 0) {
|
|
|
|
/* not used */
|
|
|
|
continue;
|
|
|
|
} else if ((long)twait_block->vtag_block[i].tv_sec_at_expire <
|
|
|
|
now->tv_sec) {
|
|
|
|
/* Audit expires this guy */
|
|
|
|
twait_block->vtag_block[i].tv_sec_at_expire = 0;
|
|
|
|
twait_block->vtag_block[i].v_tag = 0;
|
|
|
|
twait_block->vtag_block[i].lport = 0;
|
|
|
|
twait_block->vtag_block[i].rport = 0;
|
|
|
|
} else if ((twait_block->vtag_block[i].v_tag == tag) &&
|
|
|
|
(twait_block->vtag_block[i].lport == lport) &&
|
|
|
|
(twait_block->vtag_block[i].rport == rport)) {
|
|
|
|
/* Bad tag, sorry :< */
|
|
|
|
SCTP_INP_INFO_RUNLOCK();
|
|
|
|
return (0);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-12-06 13:19:54 +00:00
|
|
|
SCTP_INP_INFO_RUNLOCK();
|
2006-11-03 15:23:16 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-12-17 19:21:40 +00:00
|
|
|
sctp_drain_mbufs(struct sctp_tcb *stcb)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We must hunt this association for MBUF's past the cumack (i.e.
|
|
|
|
* out of order data that we can renege on).
|
|
|
|
*/
|
|
|
|
struct sctp_association *asoc;
|
|
|
|
struct sctp_tmit_chunk *chk, *nchk;
|
2010-04-03 15:40:14 +00:00
|
|
|
uint32_t cumulative_tsn_p1;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_queued_to_read *ctl, *nctl;
|
2010-04-03 15:40:14 +00:00
|
|
|
int cnt, strmat;
|
|
|
|
uint32_t gap, i;
|
|
|
|
int fnd = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/* We look for anything larger than the cum-ack + 1 */
|
|
|
|
|
|
|
|
asoc = &stcb->asoc;
|
|
|
|
if (asoc->cumulative_tsn == asoc->highest_tsn_inside_map) {
|
|
|
|
/* none we can reneg on. */
|
|
|
|
return;
|
|
|
|
}
|
2006-12-14 17:02:55 +00:00
|
|
|
SCTP_STAT_INCR(sctps_protocol_drains_done);
|
2006-11-03 15:23:16 +00:00
|
|
|
cumulative_tsn_p1 = asoc->cumulative_tsn + 1;
|
|
|
|
cnt = 0;
|
|
|
|
/* First look in the re-assembly queue */
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_FOREACH_SAFE(chk, &asoc->reasmqueue, sctp_next, nchk) {
|
2010-12-30 21:32:35 +00:00
|
|
|
if (SCTP_TSN_GT(chk->rec.data.TSN_seq, cumulative_tsn_p1)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Yep it is above cum-ack */
|
|
|
|
cnt++;
|
2010-04-03 15:40:14 +00:00
|
|
|
SCTP_CALC_TSN_TO_GAP(gap, chk->rec.data.TSN_seq, asoc->mapping_array_base_tsn);
|
2006-11-03 15:23:16 +00:00
|
|
|
asoc->size_on_reasm_queue = sctp_sbspace_sub(asoc->size_on_reasm_queue, chk->send_size);
|
|
|
|
sctp_ucount_decr(asoc->cnt_on_reasm_queue);
|
|
|
|
SCTP_UNSET_TSN_PRESENT(asoc->mapping_array, gap);
|
|
|
|
TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next);
|
|
|
|
if (chk->data) {
|
|
|
|
sctp_m_freem(chk->data);
|
|
|
|
chk->data = NULL;
|
|
|
|
}
|
2011-05-08 09:11:59 +00:00
|
|
|
sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Ok that was fun, now we will drain all the inbound streams? */
|
|
|
|
for (strmat = 0; strmat < asoc->streamincnt; strmat++) {
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_FOREACH_SAFE(ctl, &asoc->strmin[strmat].inqueue, next, nctl) {
|
2010-12-30 21:32:35 +00:00
|
|
|
if (SCTP_TSN_GT(ctl->sinfo_tsn, cumulative_tsn_p1)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Yep it is above cum-ack */
|
|
|
|
cnt++;
|
2010-04-03 15:40:14 +00:00
|
|
|
SCTP_CALC_TSN_TO_GAP(gap, ctl->sinfo_tsn, asoc->mapping_array_base_tsn);
|
2006-11-03 15:23:16 +00:00
|
|
|
asoc->size_on_all_streams = sctp_sbspace_sub(asoc->size_on_all_streams, ctl->length);
|
|
|
|
sctp_ucount_decr(asoc->cnt_on_all_streams);
|
2010-04-03 15:40:14 +00:00
|
|
|
SCTP_UNSET_TSN_PRESENT(asoc->mapping_array, gap);
|
|
|
|
TAILQ_REMOVE(&asoc->strmin[strmat].inqueue, ctl, next);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (ctl->data) {
|
|
|
|
sctp_m_freem(ctl->data);
|
|
|
|
ctl->data = NULL;
|
|
|
|
}
|
|
|
|
sctp_free_remote_addr(ctl->whoFrom);
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_readq), ctl);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_DECR_READQ_COUNT();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-05-09 13:30:06 +00:00
|
|
|
if (cnt) {
|
2010-04-03 15:40:14 +00:00
|
|
|
/* We must back down to see what the new highest is */
|
2010-12-30 21:32:35 +00:00
|
|
|
for (i = asoc->highest_tsn_inside_map; SCTP_TSN_GE(i, asoc->mapping_array_base_tsn); i--) {
|
2010-04-03 15:40:14 +00:00
|
|
|
SCTP_CALC_TSN_TO_GAP(gap, i, asoc->mapping_array_base_tsn);
|
|
|
|
if (SCTP_IS_TSN_PRESENT(asoc->mapping_array, gap)) {
|
|
|
|
asoc->highest_tsn_inside_map = i;
|
|
|
|
fnd = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!fnd) {
|
|
|
|
asoc->highest_tsn_inside_map = asoc->mapping_array_base_tsn - 1;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Question, should we go through the delivery queue? The
|
|
|
|
* only reason things are on here is the app not reading OR
|
|
|
|
* a p-d-api up. An attacker COULD send enough in to
|
|
|
|
* initiate the PD-API and then send a bunch of stuff to
|
|
|
|
* other streams... these would wind up on the delivery
|
|
|
|
* queue.. and then we would not get to them. But in order
|
|
|
|
* to do this I then have to back-track and un-deliver
|
|
|
|
* sequence numbers in streams.. el-yucko. I think for now
|
|
|
|
* we will NOT look at the delivery queue and leave it to be
|
|
|
|
* something to consider later. An alternative would be to
|
|
|
|
* abort the P-D-API with a notification and then deliver
|
|
|
|
* the data.... Or another method might be to keep track of
|
|
|
|
* how many times the situation occurs and if we see a
|
|
|
|
* possible attack underway just abort the association.
|
|
|
|
*/
|
|
|
|
#ifdef SCTP_DEBUG
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_PCB1, "Freed %d chunks from reneg harvest\n", cnt);
|
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* Now do we need to find a new
|
|
|
|
* asoc->highest_tsn_inside_map?
|
|
|
|
*/
|
|
|
|
asoc->last_revoke_count = cnt;
|
2007-05-08 14:32:53 +00:00
|
|
|
(void)SCTP_OS_TIMER_STOP(&stcb->asoc.dack_timer.timer);
|
2007-09-13 10:36:43 +00:00
|
|
|
/* sa_ignore NO_NULL_CHK */
|
2011-05-08 09:11:59 +00:00
|
|
|
sctp_send_sack(stcb, SCTP_SO_NOT_LOCKED);
|
2007-09-08 11:35:11 +00:00
|
|
|
sctp_chunk_output(stcb->sctp_ep, stcb, SCTP_OUTPUT_FROM_DRAIN, SCTP_SO_NOT_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Another issue, in un-setting the TSN's in the mapping array we
|
2010-11-09 16:18:32 +00:00
|
|
|
* DID NOT adjust the highest_tsn marker. This will cause one of
|
|
|
|
* two things to occur. It may cause us to do extra work in checking
|
|
|
|
* for our mapping array movement. More importantly it may cause us
|
|
|
|
* to SACK every datagram. This may not be a bad thing though since
|
|
|
|
* we will recover once we get our cum-ack above and all this stuff
|
|
|
|
* we dumped recovered.
|
2006-11-03 15:23:16 +00:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_drain()
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We must walk the PCB lists for ALL associations here. The system
|
|
|
|
* is LOW on MBUF's and needs help. This is where reneging will
|
|
|
|
* occur. We really hope this does NOT happen!
|
|
|
|
*/
|
2009-09-19 14:02:16 +00:00
|
|
|
VNET_ITERATOR_DECL(vnet_iter);
|
|
|
|
VNET_LIST_RLOCK_NOSLEEP();
|
|
|
|
VNET_FOREACH(vnet_iter) {
|
|
|
|
CURVNET_SET(vnet_iter);
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
struct sctp_tcb *stcb;
|
|
|
|
|
2009-09-20 11:33:39 +00:00
|
|
|
SCTP_STAT_INCR(sctps_protocol_drain_calls);
|
|
|
|
if (SCTP_BASE_SYSCTL(sctp_do_drain) == 0) {
|
|
|
|
#ifdef VIMAGE
|
|
|
|
continue;
|
|
|
|
#else
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
}
|
2009-09-19 14:02:16 +00:00
|
|
|
SCTP_INP_INFO_RLOCK();
|
|
|
|
LIST_FOREACH(inp, &SCTP_BASE_INFO(listhead), sctp_list) {
|
|
|
|
/* For each endpoint */
|
|
|
|
SCTP_INP_RLOCK(inp);
|
|
|
|
LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
|
|
|
|
/* For each association */
|
|
|
|
SCTP_TCB_LOCK(stcb);
|
2011-12-17 19:21:40 +00:00
|
|
|
sctp_drain_mbufs(stcb);
|
2009-09-19 14:02:16 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
}
|
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2009-09-19 14:02:16 +00:00
|
|
|
SCTP_INP_INFO_RUNLOCK();
|
|
|
|
CURVNET_RESTORE();
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2009-09-19 14:02:16 +00:00
|
|
|
VNET_LIST_RUNLOCK_NOSLEEP();
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* start a new iterator
|
|
|
|
* iterates through all endpoints and associations based on the pcb_state
|
|
|
|
* flags and asoc_state. "af" (mandatory) is executed for all matching
|
|
|
|
* assocs and "ef" (optional) is executed when the iterator completes.
|
|
|
|
* "inpf" (optional) is executed for each new endpoint as it is being
|
2007-04-03 11:15:32 +00:00
|
|
|
* iterated through. inpe (optional) is called when the inp completes
|
|
|
|
* its way through all the stcbs.
|
2006-11-03 15:23:16 +00:00
|
|
|
*/
|
|
|
|
int
|
2007-03-15 11:27:14 +00:00
|
|
|
sctp_initiate_iterator(inp_func inpf,
|
|
|
|
asoc_func af,
|
|
|
|
inp_func inpe,
|
|
|
|
uint32_t pcb_state,
|
|
|
|
uint32_t pcb_features,
|
|
|
|
uint32_t asoc_state,
|
|
|
|
void *argp,
|
|
|
|
uint32_t argi,
|
|
|
|
end_func ef,
|
|
|
|
struct sctp_inpcb *s_inp,
|
|
|
|
uint8_t chunk_output_off)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
struct sctp_iterator *it = NULL;
|
|
|
|
|
|
|
|
if (af == NULL) {
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
SCTP_MALLOC(it, struct sctp_iterator *, sizeof(struct sctp_iterator),
|
2007-05-29 09:29:03 +00:00
|
|
|
SCTP_M_ITER);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (it == NULL) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_PCB, ENOMEM);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
memset(it, 0, sizeof(*it));
|
|
|
|
it->function_assoc = af;
|
|
|
|
it->function_inp = inpf;
|
2007-03-15 11:27:14 +00:00
|
|
|
if (inpf)
|
|
|
|
it->done_current_ep = 0;
|
|
|
|
else
|
|
|
|
it->done_current_ep = 1;
|
2006-11-03 15:23:16 +00:00
|
|
|
it->function_atend = ef;
|
|
|
|
it->pointer = argp;
|
|
|
|
it->val = argi;
|
|
|
|
it->pcb_flags = pcb_state;
|
|
|
|
it->pcb_features = pcb_features;
|
|
|
|
it->asoc_state = asoc_state;
|
2007-03-15 11:27:14 +00:00
|
|
|
it->function_inp_end = inpe;
|
2006-11-03 15:23:16 +00:00
|
|
|
it->no_chunk_output = chunk_output_off;
|
2010-05-16 17:03:56 +00:00
|
|
|
it->vn = curvnet;
|
2006-11-03 15:23:16 +00:00
|
|
|
if (s_inp) {
|
2010-06-11 03:54:00 +00:00
|
|
|
/* Assume lock is held here */
|
2006-11-03 15:23:16 +00:00
|
|
|
it->inp = s_inp;
|
2010-06-11 03:54:00 +00:00
|
|
|
SCTP_INP_INCR_REF(it->inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
it->iterator_flags = SCTP_ITERATOR_DO_SINGLE_INP;
|
|
|
|
} else {
|
|
|
|
SCTP_INP_INFO_RLOCK();
|
2008-06-14 07:58:05 +00:00
|
|
|
it->inp = LIST_FIRST(&SCTP_BASE_INFO(listhead));
|
2010-06-11 03:54:00 +00:00
|
|
|
if (it->inp) {
|
|
|
|
SCTP_INP_INCR_REF(it->inp);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_INFO_RUNLOCK();
|
|
|
|
it->iterator_flags = SCTP_ITERATOR_DO_ALL_INP;
|
|
|
|
|
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_IPI_ITERATOR_WQ_LOCK();
|
2010-06-11 03:54:00 +00:00
|
|
|
|
2010-05-16 17:03:56 +00:00
|
|
|
TAILQ_INSERT_TAIL(&sctp_it_ctl.iteratorhead, it, sctp_nxt_itr);
|
|
|
|
if (sctp_it_ctl.iterator_running == 0) {
|
2007-03-15 11:27:14 +00:00
|
|
|
sctp_wakeup_iterator();
|
|
|
|
}
|
|
|
|
SCTP_IPI_ITERATOR_WQ_UNLOCK();
|
2007-05-17 12:16:24 +00:00
|
|
|
/* sa_ignore MEMLEAK {memory is put on the tailq for the iterator} */
|
2006-11-03 15:23:16 +00:00
|
|
|
return (0);
|
|
|
|
}
|