2006-11-03 15:23:16 +00:00
|
|
|
/*-
|
2017-11-20 19:43:44 +00:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
2007-05-08 17:01:12 +00:00
|
|
|
* Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
|
2012-05-23 11:26:28 +00:00
|
|
|
* Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
|
|
|
|
* Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
|
2006-11-03 15:23:16 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* a) Redistributions of source code must retain the above copyright notice,
|
2011-12-17 19:21:40 +00:00
|
|
|
* this list of conditions and the following disclaimer.
|
2006-11-03 15:23:16 +00:00
|
|
|
*
|
|
|
|
* b) Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
2011-12-17 19:21:40 +00:00
|
|
|
* the documentation and/or other materials provided with the distribution.
|
2006-11-03 15:23:16 +00:00
|
|
|
*
|
|
|
|
* c) Neither the name of Cisco Systems, Inc. nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include <netinet/sctp_os.h>
|
|
|
|
#include <netinet/sctp_var.h>
|
|
|
|
#include <netinet/sctp_pcb.h>
|
|
|
|
#include <netinet/sctp_header.h>
|
|
|
|
#include <netinet/sctputil.h>
|
|
|
|
#include <netinet/sctp_output.h>
|
|
|
|
#include <netinet/sctp_bsd_addr.h>
|
|
|
|
#include <netinet/sctp_uio.h>
|
|
|
|
#include <netinet/sctputil.h>
|
|
|
|
#include <netinet/sctp_timer.h>
|
|
|
|
#include <netinet/sctp_asconf.h>
|
2007-05-02 12:50:13 +00:00
|
|
|
#include <netinet/sctp_sysctl.h>
|
2006-11-03 15:23:16 +00:00
|
|
|
#include <netinet/sctp_indata.h>
|
2007-03-15 11:27:14 +00:00
|
|
|
#include <sys/unistd.h>
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-05-29 09:29:03 +00:00
|
|
|
/* Declare all of our malloc named types */
|
|
|
|
MALLOC_DEFINE(SCTP_M_MAP, "sctp_map", "sctp asoc map descriptor");
|
|
|
|
MALLOC_DEFINE(SCTP_M_STRMI, "sctp_stri", "sctp stream in array");
|
|
|
|
MALLOC_DEFINE(SCTP_M_STRMO, "sctp_stro", "sctp stream out array");
|
|
|
|
MALLOC_DEFINE(SCTP_M_ASC_ADDR, "sctp_aadr", "sctp asconf address");
|
|
|
|
MALLOC_DEFINE(SCTP_M_ASC_IT, "sctp_a_it", "sctp asconf iterator");
|
|
|
|
MALLOC_DEFINE(SCTP_M_AUTH_CL, "sctp_atcl", "sctp auth chunklist");
|
|
|
|
MALLOC_DEFINE(SCTP_M_AUTH_KY, "sctp_atky", "sctp auth key");
|
|
|
|
MALLOC_DEFINE(SCTP_M_AUTH_HL, "sctp_athm", "sctp auth hmac list");
|
|
|
|
MALLOC_DEFINE(SCTP_M_AUTH_IF, "sctp_athi", "sctp auth info");
|
|
|
|
MALLOC_DEFINE(SCTP_M_STRESET, "sctp_stre", "sctp stream reset");
|
|
|
|
MALLOC_DEFINE(SCTP_M_CMSG, "sctp_cmsg", "sctp CMSG buffer");
|
|
|
|
MALLOC_DEFINE(SCTP_M_COPYAL, "sctp_cpal", "sctp copy all");
|
|
|
|
MALLOC_DEFINE(SCTP_M_VRF, "sctp_vrf", "sctp vrf struct");
|
|
|
|
MALLOC_DEFINE(SCTP_M_IFA, "sctp_ifa", "sctp ifa struct");
|
|
|
|
MALLOC_DEFINE(SCTP_M_IFN, "sctp_ifn", "sctp ifn struct");
|
|
|
|
MALLOC_DEFINE(SCTP_M_TIMW, "sctp_timw", "sctp time block");
|
|
|
|
MALLOC_DEFINE(SCTP_M_MVRF, "sctp_mvrf", "sctp mvrf pcb list");
|
|
|
|
MALLOC_DEFINE(SCTP_M_ITER, "sctp_iter", "sctp iterator control");
|
|
|
|
MALLOC_DEFINE(SCTP_M_SOCKOPT, "sctp_socko", "sctp socket option");
|
2011-02-03 10:05:30 +00:00
|
|
|
MALLOC_DEFINE(SCTP_M_MCORE, "sctp_mcore", "sctp mcore queue");
|
2007-05-29 09:29:03 +00:00
|
|
|
|
2010-05-16 17:03:56 +00:00
|
|
|
/* Global NON-VNET structure that controls the iterator */
|
|
|
|
struct iterator_control sctp_it_ctl;
|
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
void
|
|
|
|
sctp_wakeup_iterator(void)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2010-05-16 17:03:56 +00:00
|
|
|
wakeup(&sctp_it_ctl.iterator_running);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
static void
|
2011-12-17 19:21:40 +00:00
|
|
|
sctp_iterator_thread(void *v SCTP_UNUSED)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_IPI_ITERATOR_WQ_LOCK();
|
2011-09-19 21:47:20 +00:00
|
|
|
/* In FreeBSD this thread never terminates. */
|
2011-12-17 19:21:40 +00:00
|
|
|
for (;;) {
|
2010-05-16 17:03:56 +00:00
|
|
|
msleep(&sctp_it_ctl.iterator_running,
|
|
|
|
&sctp_it_ctl.ipi_iterator_wq_mtx,
|
2008-01-28 10:33:41 +00:00
|
|
|
0, "waiting_for_work", 0);
|
2007-03-15 11:27:14 +00:00
|
|
|
sctp_iterator_worker();
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
void
|
|
|
|
sctp_startup_iterator(void)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2013-11-16 15:04:49 +00:00
|
|
|
if (sctp_it_ctl.thread_proc) {
|
2010-05-16 17:03:56 +00:00
|
|
|
/* You only get one */
|
|
|
|
return;
|
|
|
|
}
|
2013-11-30 12:51:19 +00:00
|
|
|
/* Initialize global locks here, thus only once. */
|
|
|
|
SCTP_ITERATOR_LOCK_INIT();
|
|
|
|
SCTP_IPI_ITERATOR_WQ_INIT();
|
2010-05-16 17:03:56 +00:00
|
|
|
TAILQ_INIT(&sctp_it_ctl.iteratorhead);
|
2013-11-16 15:04:49 +00:00
|
|
|
kproc_create(sctp_iterator_thread,
|
2010-05-16 17:03:56 +00:00
|
|
|
(void *)NULL,
|
|
|
|
&sctp_it_ctl.thread_proc,
|
2007-03-15 11:27:14 +00:00
|
|
|
RFPROC,
|
|
|
|
SCTP_KTHREAD_PAGES,
|
|
|
|
SCTP_KTRHEAD_NAME);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
2008-04-16 17:24:18 +00:00
|
|
|
#ifdef INET6
|
2008-07-09 16:45:30 +00:00
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
void
|
|
|
|
sctp_gather_internal_ifa_flags(struct sctp_ifa *ifa)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2007-03-15 11:27:14 +00:00
|
|
|
struct in6_ifaddr *ifa6;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
ifa6 = (struct in6_ifaddr *)ifa->ifa;
|
|
|
|
ifa->flags = ifa6->ia6_flags;
|
2009-09-17 15:11:12 +00:00
|
|
|
if (!MODULE_GLOBAL(ip6_use_deprecated)) {
|
2007-03-15 11:27:14 +00:00
|
|
|
if (ifa->flags &
|
|
|
|
IN6_IFF_DEPRECATED) {
|
|
|
|
ifa->localifa_flags |= SCTP_ADDR_IFA_UNUSEABLE;
|
|
|
|
} else {
|
|
|
|
ifa->localifa_flags &= ~SCTP_ADDR_IFA_UNUSEABLE;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
} else {
|
|
|
|
ifa->localifa_flags &= ~SCTP_ADDR_IFA_UNUSEABLE;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
if (ifa->flags &
|
|
|
|
(IN6_IFF_DETACHED |
|
|
|
|
IN6_IFF_ANYCAST |
|
|
|
|
IN6_IFF_NOTREADY)) {
|
|
|
|
ifa->localifa_flags |= SCTP_ADDR_IFA_UNUSEABLE;
|
|
|
|
} else {
|
|
|
|
ifa->localifa_flags &= ~SCTP_ADDR_IFA_UNUSEABLE;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-09 16:45:30 +00:00
|
|
|
#endif /* INET6 */
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
static uint32_t
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_is_desired_interface_type(struct ifnet *ifn)
|
|
|
|
{
|
2007-03-15 11:27:14 +00:00
|
|
|
int result;
|
|
|
|
|
|
|
|
/* check the interface type to see if it's one we care about */
|
2012-08-04 08:03:30 +00:00
|
|
|
switch (ifn->if_type) {
|
2007-03-15 11:27:14 +00:00
|
|
|
case IFT_ETHER:
|
|
|
|
case IFT_ISO88023:
|
|
|
|
case IFT_ISO88024:
|
|
|
|
case IFT_ISO88025:
|
|
|
|
case IFT_ISO88026:
|
|
|
|
case IFT_STARLAN:
|
|
|
|
case IFT_P10:
|
|
|
|
case IFT_P80:
|
|
|
|
case IFT_HY:
|
|
|
|
case IFT_FDDI:
|
|
|
|
case IFT_XETHER:
|
|
|
|
case IFT_ISDNBASIC:
|
|
|
|
case IFT_ISDNPRIMARY:
|
|
|
|
case IFT_PTPSERIAL:
|
2007-09-08 17:48:46 +00:00
|
|
|
case IFT_OTHER:
|
2007-03-15 11:27:14 +00:00
|
|
|
case IFT_PPP:
|
|
|
|
case IFT_LOOP:
|
|
|
|
case IFT_SLIP:
|
2008-06-14 07:58:05 +00:00
|
|
|
case IFT_GIF:
|
2009-08-28 08:41:59 +00:00
|
|
|
case IFT_L2VLAN:
|
2012-03-09 13:15:40 +00:00
|
|
|
case IFT_STF:
|
2007-03-15 11:27:14 +00:00
|
|
|
case IFT_IP:
|
|
|
|
case IFT_IPOVERCDLC:
|
|
|
|
case IFT_IPOVERCLAW:
|
2012-03-12 15:05:17 +00:00
|
|
|
case IFT_PROPVIRTUAL: /* NetGraph Virtual too */
|
2007-03-15 11:27:14 +00:00
|
|
|
case IFT_VIRTUALIPADDRESS:
|
|
|
|
result = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sctp_init_ifns_for_vrf(int vrfid)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
/*
|
2007-03-15 11:27:14 +00:00
|
|
|
* Here we must apply ANY locks needed by the IFN we access and also
|
|
|
|
* make sure we lock any IFA that exists as we float through the
|
|
|
|
* list of IFA's
|
2006-11-03 15:23:16 +00:00
|
|
|
*/
|
Widen NET_EPOCH coverage.
When epoch(9) was introduced to network stack, it was basically
dropped in place of existing locking, which was mutexes and
rwlocks. For the sake of performance mutex covered areas were
as small as possible, so became epoch covered areas.
However, epoch doesn't introduce any contention, it just delays
memory reclaim. So, there is no point to minimise epoch covered
areas in sense of performance. Meanwhile entering/exiting epoch
also has non-zero CPU usage, so doing this less often is a win.
Not the least is also code maintainability. In the new paradigm
we can assume that at any stage of processing a packet, we are
inside network epoch. This makes coding both input and output
path way easier.
On output path we already enter epoch quite early - in the
ip_output(), in the ip6_output().
This patch does the same for the input path. All ISR processing,
network related callouts, other ways of packet injection to the
network stack shall be performed in net_epoch. Any leaf function
that walks network configuration now asserts epoch.
Tricky part is configuration code paths - ioctls, sysctls. They
also call into leaf functions, so some need to be changed.
This patch would introduce more epoch recursions (see EPOCH_TRACE)
than we had before. They will be cleaned up separately, as several
of them aren't trivial. Note, that unlike a lock recursion the
epoch recursion is safe and just wastes a bit of resources.
Reviewed by: gallatin, hselasky, cy, adrian, kristof
Differential Revision: https://reviews.freebsd.org/D19111
2019-10-07 22:40:05 +00:00
|
|
|
struct epoch_tracker et;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct ifnet *ifn;
|
|
|
|
struct ifaddr *ifa;
|
2007-03-15 11:27:14 +00:00
|
|
|
struct sctp_ifa *sctp_ifa;
|
|
|
|
uint32_t ifa_flags;
|
2011-04-30 11:18:16 +00:00
|
|
|
#ifdef INET6
|
|
|
|
struct in6_ifaddr *ifa6;
|
|
|
|
#endif
|
|
|
|
|
2009-09-19 14:02:16 +00:00
|
|
|
IFNET_RLOCK();
|
Widen NET_EPOCH coverage.
When epoch(9) was introduced to network stack, it was basically
dropped in place of existing locking, which was mutexes and
rwlocks. For the sake of performance mutex covered areas were
as small as possible, so became epoch covered areas.
However, epoch doesn't introduce any contention, it just delays
memory reclaim. So, there is no point to minimise epoch covered
areas in sense of performance. Meanwhile entering/exiting epoch
also has non-zero CPU usage, so doing this less often is a win.
Not the least is also code maintainability. In the new paradigm
we can assume that at any stage of processing a packet, we are
inside network epoch. This makes coding both input and output
path way easier.
On output path we already enter epoch quite early - in the
ip_output(), in the ip6_output().
This patch does the same for the input path. All ISR processing,
network related callouts, other ways of packet injection to the
network stack shall be performed in net_epoch. Any leaf function
that walks network configuration now asserts epoch.
Tricky part is configuration code paths - ioctls, sysctls. They
also call into leaf functions, so some need to be changed.
This patch would introduce more epoch recursions (see EPOCH_TRACE)
than we had before. They will be cleaned up separately, as several
of them aren't trivial. Note, that unlike a lock recursion the
epoch recursion is safe and just wastes a bit of resources.
Reviewed by: gallatin, hselasky, cy, adrian, kristof
Differential Revision: https://reviews.freebsd.org/D19111
2019-10-07 22:40:05 +00:00
|
|
|
NET_EPOCH_ENTER(et);
|
2018-05-23 21:02:14 +00:00
|
|
|
CK_STAILQ_FOREACH(ifn, &MODULE_GLOBAL(ifnet), if_link) {
|
2012-08-04 08:03:30 +00:00
|
|
|
if (sctp_is_desired_interface_type(ifn) == 0) {
|
|
|
|
/* non desired type */
|
|
|
|
continue;
|
|
|
|
}
|
2018-05-18 20:13:34 +00:00
|
|
|
CK_STAILQ_FOREACH(ifa, &ifn->if_addrhead, ifa_link) {
|
2007-03-15 11:27:14 +00:00
|
|
|
if (ifa->ifa_addr == NULL) {
|
2006-11-03 15:23:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
switch (ifa->ifa_addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
if (((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr == 0) {
|
2007-03-15 11:27:14 +00:00
|
|
|
continue;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
if (IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr)) {
|
|
|
|
/* skip unspecifed addresses */
|
2007-03-15 11:27:14 +00:00
|
|
|
continue;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
continue;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
switch (ifa->ifa_addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
ifa_flags = 0;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
2008-06-14 07:58:05 +00:00
|
|
|
ifa6 = (struct in6_ifaddr *)ifa;
|
|
|
|
ifa_flags = ifa6->ia6_flags;
|
2011-04-30 11:18:16 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2008-06-14 07:58:05 +00:00
|
|
|
ifa_flags = 0;
|
2011-04-30 11:18:16 +00:00
|
|
|
break;
|
2008-06-14 07:58:05 +00:00
|
|
|
}
|
|
|
|
sctp_ifa = sctp_add_addr_to_vrf(vrfid,
|
|
|
|
(void *)ifn,
|
|
|
|
ifn->if_index,
|
|
|
|
ifn->if_type,
|
|
|
|
ifn->if_xname,
|
|
|
|
(void *)ifa,
|
|
|
|
ifa->ifa_addr,
|
|
|
|
ifa_flags,
|
|
|
|
0);
|
|
|
|
if (sctp_ifa) {
|
|
|
|
sctp_ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Widen NET_EPOCH coverage.
When epoch(9) was introduced to network stack, it was basically
dropped in place of existing locking, which was mutexes and
rwlocks. For the sake of performance mutex covered areas were
as small as possible, so became epoch covered areas.
However, epoch doesn't introduce any contention, it just delays
memory reclaim. So, there is no point to minimise epoch covered
areas in sense of performance. Meanwhile entering/exiting epoch
also has non-zero CPU usage, so doing this less often is a win.
Not the least is also code maintainability. In the new paradigm
we can assume that at any stage of processing a packet, we are
inside network epoch. This makes coding both input and output
path way easier.
On output path we already enter epoch quite early - in the
ip_output(), in the ip6_output().
This patch does the same for the input path. All ISR processing,
network related callouts, other ways of packet injection to the
network stack shall be performed in net_epoch. Any leaf function
that walks network configuration now asserts epoch.
Tricky part is configuration code paths - ioctls, sysctls. They
also call into leaf functions, so some need to be changed.
This patch would introduce more epoch recursions (see EPOCH_TRACE)
than we had before. They will be cleaned up separately, as several
of them aren't trivial. Note, that unlike a lock recursion the
epoch recursion is safe and just wastes a bit of resources.
Reviewed by: gallatin, hselasky, cy, adrian, kristof
Differential Revision: https://reviews.freebsd.org/D19111
2019-10-07 22:40:05 +00:00
|
|
|
NET_EPOCH_EXIT(et);
|
2009-09-19 14:02:16 +00:00
|
|
|
IFNET_RUNLOCK();
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
void
|
|
|
|
sctp_init_vrf_list(int vrfid)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2007-03-15 11:27:14 +00:00
|
|
|
if (vrfid > SCTP_MAX_VRF_ID)
|
|
|
|
/* can't do that */
|
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
/* Don't care about return here */
|
|
|
|
(void)sctp_allocate_vrf(vrfid);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
/*
|
|
|
|
* Now we need to build all the ifn's for this vrf and there
|
|
|
|
* addresses
|
|
|
|
*/
|
|
|
|
sctp_init_ifns_for_vrf(vrfid);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
void
|
|
|
|
sctp_addr_change(struct ifaddr *ifa, int cmd)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2007-03-15 11:27:14 +00:00
|
|
|
uint32_t ifa_flags = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2016-02-16 19:36:25 +00:00
|
|
|
if (SCTP_BASE_VAR(sctp_pcb_initialized) == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
2007-03-15 11:27:14 +00:00
|
|
|
* BSD only has one VRF, if this changes we will need to hook in the
|
2016-05-02 20:56:11 +00:00
|
|
|
* right things here to get the id to pass to the address management
|
2007-03-15 11:27:14 +00:00
|
|
|
* routine.
|
2006-11-03 15:23:16 +00:00
|
|
|
*/
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_VAR(first_time) == 0) {
|
2007-03-15 11:27:14 +00:00
|
|
|
/* Special test to see if my ::1 will showup with this */
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_BASE_VAR(first_time) = 1;
|
2007-03-15 11:27:14 +00:00
|
|
|
sctp_init_ifns_for_vrf(SCTP_DEFAULT_VRFID);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2018-07-19 20:16:33 +00:00
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
if ((cmd != RTM_ADD) && (cmd != RTM_DELETE)) {
|
|
|
|
/* don't know what to do with this */
|
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2018-07-19 20:16:33 +00:00
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
if (ifa->ifa_addr == NULL) {
|
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2012-08-04 08:03:30 +00:00
|
|
|
if (sctp_is_desired_interface_type(ifa->ifa_ifp) == 0) {
|
|
|
|
/* non desired type */
|
|
|
|
return;
|
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
switch (ifa->ifa_addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
if (((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
2008-06-14 07:58:05 +00:00
|
|
|
ifa_flags = ((struct in6_ifaddr *)ifa)->ia6_flags;
|
2007-03-15 11:27:14 +00:00
|
|
|
if (IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr)) {
|
|
|
|
/* skip unspecifed addresses */
|
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
/* non inet/inet6 skip */
|
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
if (cmd == RTM_ADD) {
|
2010-09-15 21:19:54 +00:00
|
|
|
(void)sctp_add_addr_to_vrf(SCTP_DEFAULT_VRFID, (void *)ifa->ifa_ifp,
|
2012-08-04 08:03:30 +00:00
|
|
|
ifa->ifa_ifp->if_index, ifa->ifa_ifp->if_type, ifa->ifa_ifp->if_xname,
|
2007-05-02 12:50:13 +00:00
|
|
|
(void *)ifa, ifa->ifa_addr, ifa_flags, 1);
|
2008-06-14 07:58:05 +00:00
|
|
|
} else {
|
2007-09-08 17:48:46 +00:00
|
|
|
sctp_del_addr_from_vrf(SCTP_DEFAULT_VRFID, ifa->ifa_addr,
|
|
|
|
ifa->ifa_ifp->if_index,
|
2012-08-04 08:03:30 +00:00
|
|
|
ifa->ifa_ifp->if_xname);
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
2007-03-15 11:27:14 +00:00
|
|
|
* We don't bump refcount here so when it completes the
|
|
|
|
* final delete will happen.
|
2006-11-03 15:23:16 +00:00
|
|
|
*/
|
|
|
|
}
|
2007-05-02 12:50:13 +00:00
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
|
2019-10-13 18:17:08 +00:00
|
|
|
void
|
|
|
|
sctp_addr_change_event_handler(void *arg __unused, struct ifaddr *ifa, int cmd)
|
|
|
|
{
|
|
|
|
sctp_addr_change(ifa, cmd);
|
|
|
|
}
|
|
|
|
|
2007-05-02 12:50:13 +00:00
|
|
|
struct mbuf *
|
|
|
|
sctp_get_mbuf_for_msg(unsigned int space_needed, int want_header,
|
|
|
|
int how, int allonebuf, int type)
|
|
|
|
{
|
|
|
|
struct mbuf *m = NULL;
|
2007-03-15 11:27:14 +00:00
|
|
|
|
2007-05-02 12:50:13 +00:00
|
|
|
m = m_getm2(NULL, space_needed, how, type, want_header ? M_PKTHDR : 0);
|
|
|
|
if (m == NULL) {
|
|
|
|
/* bad, no memory */
|
|
|
|
return (m);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-05-02 12:50:13 +00:00
|
|
|
if (allonebuf) {
|
2015-01-10 13:56:26 +00:00
|
|
|
if (SCTP_BUF_SIZE(m) < space_needed) {
|
2007-05-02 12:50:13 +00:00
|
|
|
m_freem(m);
|
|
|
|
return (NULL);
|
|
|
|
}
|
2020-10-04 15:37:34 +00:00
|
|
|
KASSERT(SCTP_BUF_NEXT(m) == NULL, ("%s: no chain allowed", __func__));
|
2007-05-02 12:50:13 +00:00
|
|
|
}
|
|
|
|
#ifdef SCTP_MBUF_LOGGING
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) {
|
2015-01-10 20:49:57 +00:00
|
|
|
sctp_log_mb(m, SCTP_MBUF_IALLOC);
|
2007-05-02 12:50:13 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return (m);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-05-29 09:29:03 +00:00
|
|
|
|
|
|
|
#ifdef SCTP_PACKET_LOGGING
|
|
|
|
void
|
2012-06-24 21:25:54 +00:00
|
|
|
sctp_packet_log(struct mbuf *m)
|
2007-05-29 09:29:03 +00:00
|
|
|
{
|
2007-05-30 17:39:45 +00:00
|
|
|
int *lenat, thisone;
|
2007-05-29 09:29:03 +00:00
|
|
|
void *copyto;
|
|
|
|
uint32_t *tick_tock;
|
2012-06-24 21:25:54 +00:00
|
|
|
int length;
|
2007-05-30 17:39:45 +00:00
|
|
|
int total_len;
|
|
|
|
int grabbed_lock = 0;
|
|
|
|
int value, newval, thisend, thisbegin;
|
2007-05-29 09:29:03 +00:00
|
|
|
|
2007-05-30 17:39:45 +00:00
|
|
|
/*
|
|
|
|
* Buffer layout. -sizeof this entry (total_len) -previous end
|
|
|
|
* (value) -ticks of log (ticks) o -ip packet o -as logged -
|
|
|
|
* where this started (thisbegin) x <--end points here
|
|
|
|
*/
|
2012-06-24 21:25:54 +00:00
|
|
|
length = SCTP_HEADER_LEN(m);
|
2007-05-30 17:39:45 +00:00
|
|
|
total_len = SCTP_SIZE32((length + (4 * sizeof(int))));
|
2007-05-29 09:29:03 +00:00
|
|
|
/* Log a packet to the buffer. */
|
|
|
|
if (total_len > SCTP_PACKET_LOG_SIZE) {
|
|
|
|
/* Can't log this packet I have not a buffer big enough */
|
|
|
|
return;
|
|
|
|
}
|
2008-06-14 07:58:05 +00:00
|
|
|
if (length < (int)(SCTP_MIN_V4_OVERHEAD + sizeof(struct sctp_cookie_ack_chunk))) {
|
2007-05-29 09:29:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-06-14 07:58:05 +00:00
|
|
|
atomic_add_int(&SCTP_BASE_VAR(packet_log_writers), 1);
|
2007-05-30 17:39:45 +00:00
|
|
|
try_again:
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_VAR(packet_log_writers) > SCTP_PKTLOG_WRITERS_NEED_LOCK) {
|
2007-05-30 17:39:45 +00:00
|
|
|
SCTP_IP_PKTLOG_LOCK();
|
|
|
|
grabbed_lock = 1;
|
|
|
|
again_locked:
|
2008-06-14 07:58:05 +00:00
|
|
|
value = SCTP_BASE_VAR(packet_log_end);
|
|
|
|
newval = SCTP_BASE_VAR(packet_log_end) + total_len;
|
2007-05-30 17:39:45 +00:00
|
|
|
if (newval >= SCTP_PACKET_LOG_SIZE) {
|
|
|
|
/* we wrapped */
|
|
|
|
thisbegin = 0;
|
|
|
|
thisend = total_len;
|
2007-05-29 09:29:03 +00:00
|
|
|
} else {
|
2008-06-14 07:58:05 +00:00
|
|
|
thisbegin = SCTP_BASE_VAR(packet_log_end);
|
2007-05-30 17:39:45 +00:00
|
|
|
thisend = newval;
|
2007-05-29 09:29:03 +00:00
|
|
|
}
|
2008-06-14 07:58:05 +00:00
|
|
|
if (!(atomic_cmpset_int(&SCTP_BASE_VAR(packet_log_end), value, thisend))) {
|
2007-05-30 17:39:45 +00:00
|
|
|
goto again_locked;
|
2007-05-29 09:29:03 +00:00
|
|
|
}
|
|
|
|
} else {
|
2008-06-14 07:58:05 +00:00
|
|
|
value = SCTP_BASE_VAR(packet_log_end);
|
|
|
|
newval = SCTP_BASE_VAR(packet_log_end) + total_len;
|
2007-05-30 17:39:45 +00:00
|
|
|
if (newval >= SCTP_PACKET_LOG_SIZE) {
|
|
|
|
/* we wrapped */
|
|
|
|
thisbegin = 0;
|
|
|
|
thisend = total_len;
|
|
|
|
} else {
|
2008-06-14 07:58:05 +00:00
|
|
|
thisbegin = SCTP_BASE_VAR(packet_log_end);
|
2007-05-30 17:39:45 +00:00
|
|
|
thisend = newval;
|
|
|
|
}
|
2008-06-14 07:58:05 +00:00
|
|
|
if (!(atomic_cmpset_int(&SCTP_BASE_VAR(packet_log_end), value, thisend))) {
|
2007-05-30 17:39:45 +00:00
|
|
|
goto try_again;
|
2007-05-29 09:29:03 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-30 17:39:45 +00:00
|
|
|
/* Sanity check */
|
|
|
|
if (thisend >= SCTP_PACKET_LOG_SIZE) {
|
2012-05-04 09:27:00 +00:00
|
|
|
SCTP_PRINTF("Insanity stops a log thisbegin:%d thisend:%d writers:%d lock:%d end:%d\n",
|
2007-05-30 17:39:45 +00:00
|
|
|
thisbegin,
|
|
|
|
thisend,
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_BASE_VAR(packet_log_writers),
|
2007-05-30 17:39:45 +00:00
|
|
|
grabbed_lock,
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_BASE_VAR(packet_log_end));
|
|
|
|
SCTP_BASE_VAR(packet_log_end) = 0;
|
2007-05-30 17:39:45 +00:00
|
|
|
goto no_log;
|
2007-05-29 09:29:03 +00:00
|
|
|
}
|
2008-06-14 07:58:05 +00:00
|
|
|
lenat = (int *)&SCTP_BASE_VAR(packet_log_buffer)[thisbegin];
|
2007-05-29 09:29:03 +00:00
|
|
|
*lenat = total_len;
|
|
|
|
lenat++;
|
2007-05-30 17:39:45 +00:00
|
|
|
*lenat = value;
|
|
|
|
lenat++;
|
2018-07-19 20:11:14 +00:00
|
|
|
tick_tock = (uint32_t *)lenat;
|
2007-05-29 09:29:03 +00:00
|
|
|
lenat++;
|
|
|
|
*tick_tock = sctp_get_tick_count();
|
|
|
|
copyto = (void *)lenat;
|
2007-05-30 17:39:45 +00:00
|
|
|
thisone = thisend - sizeof(int);
|
2008-06-14 07:58:05 +00:00
|
|
|
lenat = (int *)&SCTP_BASE_VAR(packet_log_buffer)[thisone];
|
2007-05-30 17:39:45 +00:00
|
|
|
*lenat = thisbegin;
|
|
|
|
if (grabbed_lock) {
|
|
|
|
SCTP_IP_PKTLOG_UNLOCK();
|
|
|
|
grabbed_lock = 0;
|
|
|
|
}
|
2007-05-29 09:29:03 +00:00
|
|
|
m_copydata(m, 0, length, (caddr_t)copyto);
|
2007-05-30 17:39:45 +00:00
|
|
|
no_log:
|
|
|
|
if (grabbed_lock) {
|
|
|
|
SCTP_IP_PKTLOG_UNLOCK();
|
|
|
|
}
|
2008-06-14 07:58:05 +00:00
|
|
|
atomic_subtract_int(&SCTP_BASE_VAR(packet_log_writers), 1);
|
2007-05-29 09:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_copy_out_packet_log(uint8_t *target, int length)
|
2007-05-29 09:29:03 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We wind through the packet log starting at start copying up to
|
|
|
|
* length bytes out. We return the number of bytes copied.
|
|
|
|
*/
|
2007-05-30 17:39:45 +00:00
|
|
|
int tocopy, this_copy;
|
|
|
|
int *lenat;
|
|
|
|
int did_delay = 0;
|
2007-05-29 09:29:03 +00:00
|
|
|
|
|
|
|
tocopy = length;
|
2008-06-14 07:58:05 +00:00
|
|
|
if (length < (int)(2 * sizeof(int))) {
|
2007-05-30 17:39:45 +00:00
|
|
|
/* not enough room */
|
2007-05-29 09:29:03 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2007-05-30 17:39:45 +00:00
|
|
|
if (SCTP_PKTLOG_WRITERS_NEED_LOCK) {
|
2008-06-14 07:58:05 +00:00
|
|
|
atomic_add_int(&SCTP_BASE_VAR(packet_log_writers), SCTP_PKTLOG_WRITERS_NEED_LOCK);
|
2007-05-30 17:39:45 +00:00
|
|
|
again:
|
2008-06-14 07:58:05 +00:00
|
|
|
if ((did_delay == 0) && (SCTP_BASE_VAR(packet_log_writers) != SCTP_PKTLOG_WRITERS_NEED_LOCK)) {
|
2007-05-30 17:39:45 +00:00
|
|
|
/*
|
|
|
|
* we delay here for just a moment hoping the
|
|
|
|
* writer(s) that were present when we entered will
|
|
|
|
* have left and we only have locking ones that will
|
|
|
|
* contend with us for the lock. This does not
|
|
|
|
* assure 100% access, but its good enough for a
|
|
|
|
* logging facility like this.
|
|
|
|
*/
|
|
|
|
did_delay = 1;
|
|
|
|
DELAY(10);
|
|
|
|
goto again;
|
2007-05-29 09:29:03 +00:00
|
|
|
}
|
|
|
|
}
|
2007-05-30 17:39:45 +00:00
|
|
|
SCTP_IP_PKTLOG_LOCK();
|
|
|
|
lenat = (int *)target;
|
2008-06-14 07:58:05 +00:00
|
|
|
*lenat = SCTP_BASE_VAR(packet_log_end);
|
2007-05-30 17:39:45 +00:00
|
|
|
lenat++;
|
2007-06-17 23:43:37 +00:00
|
|
|
this_copy = min((length - sizeof(int)), SCTP_PACKET_LOG_SIZE);
|
2008-06-14 07:58:05 +00:00
|
|
|
memcpy((void *)lenat, (void *)SCTP_BASE_VAR(packet_log_buffer), this_copy);
|
2007-05-30 17:39:45 +00:00
|
|
|
if (SCTP_PKTLOG_WRITERS_NEED_LOCK) {
|
2008-06-14 07:58:05 +00:00
|
|
|
atomic_subtract_int(&SCTP_BASE_VAR(packet_log_writers),
|
2007-06-17 23:43:37 +00:00
|
|
|
SCTP_PKTLOG_WRITERS_NEED_LOCK);
|
2007-05-30 17:39:45 +00:00
|
|
|
}
|
|
|
|
SCTP_IP_PKTLOG_UNLOCK();
|
|
|
|
return (this_copy + sizeof(int));
|
2007-05-29 09:29:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|