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) 2006-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,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* b) Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-05-23 11:26:28 +00:00
|
|
|
|
2006-11-03 17:21:53 +00:00
|
|
|
#include <sys/cdefs.h>
|
2006-11-03 15:23:16 +00:00
|
|
|
__FBSDID("$FreeBSD$");
|
2012-05-23 11:26:28 +00:00
|
|
|
|
|
|
|
#ifndef _NETINET_SCTP_OS_BSD_H_
|
|
|
|
#define _NETINET_SCTP_OS_BSD_H_
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* includes
|
|
|
|
*/
|
2007-01-18 09:58:43 +00:00
|
|
|
#include "opt_compat.h"
|
|
|
|
#include "opt_inet6.h"
|
|
|
|
#include "opt_inet.h"
|
|
|
|
#include "opt_sctp.h"
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
|
2007-01-18 09:58:43 +00:00
|
|
|
#include <sys/param.h>
|
2007-06-14 22:59:04 +00:00
|
|
|
#include <sys/ktr.h>
|
2007-01-18 09:58:43 +00:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
2007-07-17 20:58:26 +00:00
|
|
|
#include <sys/jail.h>
|
2007-01-18 09:58:43 +00:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/resourcevar.h>
|
|
|
|
#include <sys/uio.h>
|
2007-09-18 15:16:39 +00:00
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/rwlock.h>
|
2007-03-15 11:27:14 +00:00
|
|
|
#include <sys/kthread.h>
|
2007-01-18 09:58:43 +00:00
|
|
|
#include <sys/priv.h>
|
2006-11-03 15:23:16 +00:00
|
|
|
#include <sys/random.h>
|
2007-01-18 09:58:43 +00:00
|
|
|
#include <sys/limits.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <machine/cpu.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/if_var.h>
|
|
|
|
#include <net/route.h>
|
2009-10-10 13:59:18 +00:00
|
|
|
#include <net/vnet.h>
|
2007-01-18 09:58:43 +00:00
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/in_pcb.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/ip_var.h>
|
|
|
|
#include <netinet/ip_icmp.h>
|
|
|
|
#include <netinet/icmp_var.h>
|
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
#include <sys/domain.h>
|
|
|
|
#include <netinet/ip6.h>
|
|
|
|
#include <netinet6/ip6_var.h>
|
|
|
|
#include <netinet6/in6_pcb.h>
|
|
|
|
#include <netinet6/ip6protosw.h>
|
|
|
|
#include <netinet6/nd6.h>
|
|
|
|
#include <netinet6/scope6_var.h>
|
|
|
|
#endif /* INET6 */
|
|
|
|
|
|
|
|
#include <netinet/ip_options.h>
|
|
|
|
|
2013-09-02 22:48:41 +00:00
|
|
|
#include <crypto/sha1.h>
|
2015-12-27 17:33:59 +00:00
|
|
|
#include <crypto/sha2/sha256.h>
|
2013-09-02 22:48:41 +00:00
|
|
|
|
2007-01-18 09:58:43 +00:00
|
|
|
#ifndef in6pcb
|
|
|
|
#define in6pcb inpcb
|
|
|
|
#endif
|
2007-05-29 09:29:03 +00:00
|
|
|
/* Declare all the malloc names for all the various mallocs */
|
|
|
|
MALLOC_DECLARE(SCTP_M_MAP);
|
|
|
|
MALLOC_DECLARE(SCTP_M_STRMI);
|
|
|
|
MALLOC_DECLARE(SCTP_M_STRMO);
|
|
|
|
MALLOC_DECLARE(SCTP_M_ASC_ADDR);
|
|
|
|
MALLOC_DECLARE(SCTP_M_ASC_IT);
|
|
|
|
MALLOC_DECLARE(SCTP_M_AUTH_CL);
|
|
|
|
MALLOC_DECLARE(SCTP_M_AUTH_KY);
|
|
|
|
MALLOC_DECLARE(SCTP_M_AUTH_HL);
|
|
|
|
MALLOC_DECLARE(SCTP_M_AUTH_IF);
|
|
|
|
MALLOC_DECLARE(SCTP_M_STRESET);
|
|
|
|
MALLOC_DECLARE(SCTP_M_CMSG);
|
|
|
|
MALLOC_DECLARE(SCTP_M_COPYAL);
|
|
|
|
MALLOC_DECLARE(SCTP_M_VRF);
|
|
|
|
MALLOC_DECLARE(SCTP_M_IFA);
|
|
|
|
MALLOC_DECLARE(SCTP_M_IFN);
|
|
|
|
MALLOC_DECLARE(SCTP_M_TIMW);
|
|
|
|
MALLOC_DECLARE(SCTP_M_MVRF);
|
|
|
|
MALLOC_DECLARE(SCTP_M_ITER);
|
|
|
|
MALLOC_DECLARE(SCTP_M_SOCKOPT);
|
2011-02-03 10:05:30 +00:00
|
|
|
MALLOC_DECLARE(SCTP_M_MCORE);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-08-24 00:53:53 +00:00
|
|
|
#if defined(SCTP_LOCAL_TRACE_BUF)
|
|
|
|
|
|
|
|
#define SCTP_GET_CYCLECOUNT get_cyclecount()
|
|
|
|
#define SCTP_CTR6 sctp_log_trace
|
|
|
|
|
|
|
|
#else
|
|
|
|
#define SCTP_CTR6 CTR6
|
|
|
|
#endif
|
|
|
|
|
2008-07-09 16:45:30 +00:00
|
|
|
/*
|
|
|
|
* Macros to expand out globals defined by various modules
|
|
|
|
* to either a real global or a virtualized instance of one,
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
* depending on whether VIMAGE is defined.
|
2008-07-09 16:45:30 +00:00
|
|
|
*/
|
|
|
|
/* then define the macro(s) that hook into the vimage macros */
|
2009-09-19 14:02:16 +00:00
|
|
|
#define MODULE_GLOBAL(__SYMBOL) V_##__SYMBOL
|
2009-09-17 15:11:12 +00:00
|
|
|
|
2009-09-19 14:02:16 +00:00
|
|
|
#define V_system_base_info VNET(system_base_info)
|
2009-09-17 15:11:12 +00:00
|
|
|
#define SCTP_BASE_INFO(__m) V_system_base_info.sctppcbinfo.__m
|
|
|
|
#define SCTP_BASE_STATS V_system_base_info.sctpstat
|
2014-09-06 19:12:14 +00:00
|
|
|
#define SCTP_BASE_STAT(__m) V_system_base_info.sctpstat.__m
|
|
|
|
#define SCTP_BASE_SYSCTL(__m) V_system_base_info.sctpsysctl.__m
|
2009-09-17 15:11:12 +00:00
|
|
|
#define SCTP_BASE_VAR(__m) V_system_base_info.__m
|
2009-02-03 11:04:03 +00:00
|
|
|
|
2012-05-04 09:27:00 +00:00
|
|
|
#define SCTP_PRINTF(params...) printf(params)
|
2007-05-08 00:21:05 +00:00
|
|
|
#if defined(SCTP_DEBUG)
|
|
|
|
#define SCTPDBG(level, params...) \
|
|
|
|
{ \
|
2014-07-11 21:15:40 +00:00
|
|
|
do { \
|
|
|
|
if (SCTP_BASE_SYSCTL(sctp_debug_on) & level ) { \
|
|
|
|
SCTP_PRINTF(params); \
|
|
|
|
} \
|
|
|
|
} while (0); \
|
2007-05-08 00:21:05 +00:00
|
|
|
}
|
|
|
|
#define SCTPDBG_ADDR(level, addr) \
|
|
|
|
{ \
|
2014-07-11 21:15:40 +00:00
|
|
|
do { \
|
2014-09-06 19:12:14 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_debug_on) & level ) { \
|
|
|
|
sctp_print_address(addr); \
|
|
|
|
} \
|
2014-07-11 21:15:40 +00:00
|
|
|
} while (0); \
|
2007-05-08 00:21:05 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define SCTPDBG(level, params...)
|
|
|
|
#define SCTPDBG_ADDR(level, addr)
|
|
|
|
#endif
|
|
|
|
|
2007-06-14 22:59:04 +00:00
|
|
|
#ifdef SCTP_LTRACE_CHUNKS
|
2009-03-04 20:54:42 +00:00
|
|
|
#define SCTP_LTRACE_CHK(a, b, c, d) if(SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LTRACE_CHUNK_ENABLE) SCTP_CTR6(KTR_SUBSYS, "SCTP:%d[%d]:%x-%x-%x-%x", SCTP_LOG_CHUNK_PROC, 0, a, b, c, d)
|
2007-06-14 22:59:04 +00:00
|
|
|
#else
|
|
|
|
#define SCTP_LTRACE_CHK(a, b, c, d)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SCTP_LTRACE_ERRORS
|
2012-05-04 09:27:00 +00:00
|
|
|
#define SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, net, file, err) \
|
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LTRACE_ERROR_ENABLE) \
|
2014-07-11 21:15:40 +00:00
|
|
|
SCTP_PRINTF("mbuf:%p inp:%p stcb:%p net:%p file:%x line:%d error:%d\n", \
|
2012-05-04 09:27:00 +00:00
|
|
|
m, inp, stcb, net, file, __LINE__, err);
|
|
|
|
#define SCTP_LTRACE_ERR_RET(inp, stcb, net, file, err) \
|
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LTRACE_ERROR_ENABLE) \
|
2014-07-11 21:15:40 +00:00
|
|
|
SCTP_PRINTF("inp:%p stcb:%p net:%p file:%x line:%d error:%d\n", \
|
2012-05-04 09:27:00 +00:00
|
|
|
inp, stcb, net, file, __LINE__, err);
|
2007-06-14 22:59:04 +00:00
|
|
|
#else
|
2007-08-24 00:53:53 +00:00
|
|
|
#define SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, net, file, err)
|
|
|
|
#define SCTP_LTRACE_ERR_RET(inp, stcb, net, file, err)
|
2007-06-14 22:59:04 +00:00
|
|
|
#endif
|
|
|
|
|
2007-08-24 00:53:53 +00:00
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
/*
|
|
|
|
* Local address and interface list handling
|
|
|
|
*/
|
2007-05-08 00:21:05 +00:00
|
|
|
#define SCTP_MAX_VRF_ID 0
|
|
|
|
#define SCTP_SIZE_OF_VRF_HASH 3
|
|
|
|
#define SCTP_IFNAMSIZ IFNAMSIZ
|
|
|
|
#define SCTP_DEFAULT_VRFID 0
|
|
|
|
#define SCTP_VRF_ADDR_HASH_SIZE 16
|
|
|
|
#define SCTP_VRF_IFN_HASH_SIZE 3
|
2007-06-02 11:05:08 +00:00
|
|
|
#define SCTP_INIT_VRF_TABLEID(vrf)
|
2007-03-15 11:27:14 +00:00
|
|
|
|
|
|
|
#define SCTP_IFN_IS_IFT_LOOP(ifn) ((ifn)->ifn_type == IFT_LOOP)
|
2008-05-20 13:47:46 +00:00
|
|
|
#define SCTP_ROUTE_IS_REAL_LOOP(ro) ((ro)->ro_rt && (ro)->ro_rt->rt_ifa && (ro)->ro_rt->rt_ifa->ifa_ifp && (ro)->ro_rt->rt_ifa->ifa_ifp->if_type == IFT_LOOP)
|
2007-03-15 11:27:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Access to IFN's to help with src-addr-selection
|
|
|
|
*/
|
|
|
|
/* This could return VOID if the index works but for BSD we provide both. */
|
|
|
|
#define SCTP_GET_IFN_VOID_FROM_ROUTE(ro) (void *)ro->ro_rt->rt_ifp
|
2007-05-08 00:21:05 +00:00
|
|
|
#define SCTP_GET_IF_INDEX_FROM_ROUTE(ro) (ro)->ro_rt->rt_ifp->if_index
|
|
|
|
#define SCTP_ROUTE_HAS_VALID_IFN(ro) ((ro)->ro_rt && (ro)->ro_rt->rt_ifp)
|
2007-03-15 11:27:14 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* general memory allocation
|
|
|
|
*/
|
|
|
|
#define SCTP_MALLOC(var, type, size, name) \
|
2014-07-11 21:15:40 +00:00
|
|
|
do { \
|
|
|
|
var = (type)malloc(size, name, M_NOWAIT); \
|
|
|
|
} while (0)
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2008-10-23 15:53:51 +00:00
|
|
|
#define SCTP_FREE(var, type) free(var, type)
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
#define SCTP_MALLOC_SONAME(var, type, size) \
|
2014-07-11 21:15:40 +00:00
|
|
|
do { \
|
|
|
|
var = (type)malloc(size, M_SONAME, M_WAITOK | M_ZERO); \
|
|
|
|
} while (0)
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2008-10-23 15:53:51 +00:00
|
|
|
#define SCTP_FREE_SONAME(var) free(var, M_SONAME)
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
#define SCTP_PROCESS_STRUCT struct proc *
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* zone allocation functions
|
|
|
|
*/
|
|
|
|
#include <vm/uma.h>
|
2008-05-20 13:47:46 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/* SCTP_ZONE_INIT: initialize the zone */
|
|
|
|
typedef struct uma_zone *sctp_zone_t;
|
|
|
|
#define SCTP_ZONE_INIT(zone, name, size, number) { \
|
|
|
|
zone = uma_zcreate(name, size, NULL, NULL, NULL, NULL, UMA_ALIGN_PTR,\
|
2009-11-17 13:08:15 +00:00
|
|
|
0); \
|
2006-11-03 15:23:16 +00:00
|
|
|
uma_zone_set_max(zone, number); \
|
|
|
|
}
|
|
|
|
|
2008-05-20 13:47:46 +00:00
|
|
|
#define SCTP_ZONE_DESTROY(zone) uma_zdestroy(zone)
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/* SCTP_ZONE_GET: allocate element from the zone */
|
2007-02-12 23:24:31 +00:00
|
|
|
#define SCTP_ZONE_GET(zone, type) \
|
|
|
|
(type *)uma_zalloc(zone, M_NOWAIT);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/* SCTP_ZONE_FREE: free element from the zone */
|
|
|
|
#define SCTP_ZONE_FREE(zone, element) \
|
|
|
|
uma_zfree(zone, element);
|
2008-05-20 13:47:46 +00:00
|
|
|
|
2007-01-15 15:12:10 +00:00
|
|
|
#define SCTP_HASH_INIT(size, hashmark) hashinit_flags(size, M_PCB, hashmark, HASH_NOWAIT)
|
|
|
|
#define SCTP_HASH_FREE(table, hashmark) hashdestroy(table, M_PCB, hashmark)
|
|
|
|
|
|
|
|
#define SCTP_M_COPYM m_copym
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2006-12-29 20:21:42 +00:00
|
|
|
/*
|
|
|
|
* timers
|
|
|
|
*/
|
|
|
|
#include <sys/callout.h>
|
|
|
|
typedef struct callout sctp_os_timer_t;
|
|
|
|
|
2008-05-20 13:47:46 +00:00
|
|
|
|
2006-12-29 20:21:42 +00:00
|
|
|
#define SCTP_OS_TIMER_INIT(tmr) callout_init(tmr, 1)
|
|
|
|
#define SCTP_OS_TIMER_START callout_reset
|
|
|
|
#define SCTP_OS_TIMER_STOP callout_stop
|
2007-01-15 15:12:10 +00:00
|
|
|
#define SCTP_OS_TIMER_STOP_DRAIN callout_drain
|
2006-12-29 20:21:42 +00:00
|
|
|
#define SCTP_OS_TIMER_PENDING callout_pending
|
|
|
|
#define SCTP_OS_TIMER_ACTIVE callout_active
|
|
|
|
#define SCTP_OS_TIMER_DEACTIVATE callout_deactivate
|
|
|
|
|
2007-05-29 09:29:03 +00:00
|
|
|
#define sctp_get_tick_count() (ticks)
|
|
|
|
|
2007-09-08 11:35:11 +00:00
|
|
|
#define SCTP_UNUSED __attribute__((unused))
|
2007-06-12 11:21:00 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* Functions
|
|
|
|
*/
|
2006-12-29 20:21:42 +00:00
|
|
|
/* Mbuf manipulation and access macros */
|
|
|
|
#define SCTP_BUF_LEN(m) (m->m_len)
|
|
|
|
#define SCTP_BUF_NEXT(m) (m->m_next)
|
|
|
|
#define SCTP_BUF_NEXT_PKT(m) (m->m_nextpkt)
|
|
|
|
#define SCTP_BUF_RESV_UF(m, size) m->m_data += size
|
|
|
|
#define SCTP_BUF_AT(m, size) m->m_data + size
|
|
|
|
#define SCTP_BUF_IS_EXTENDED(m) (m->m_flags & M_EXT)
|
2015-01-10 13:56:26 +00:00
|
|
|
#define SCTP_BUF_SIZE M_SIZE
|
2006-12-29 20:21:42 +00:00
|
|
|
#define SCTP_BUF_TYPE(m) (m->m_type)
|
|
|
|
#define SCTP_BUF_RECVIF(m) (m->m_pkthdr.rcvif)
|
|
|
|
#define SCTP_BUF_PREPEND M_PREPEND
|
2007-03-31 11:47:30 +00:00
|
|
|
|
To ease changes to underlying mbuf structure and the mbuf allocator, reduce
the knowledge of mbuf layout, and in particular constants such as M_EXT,
MLEN, MHLEN, and so on, in mbuf consumers by unifying various alignment
utility functions (M_ALIGN(), MH_ALIGN(), MEXT_ALIGN() in a single
M_ALIGN() macro, implemented by a now-inlined m_align() function:
- Move m_align() from uipc_mbuf.c to mbuf.h; mark as __inline.
- Reimplement M_ALIGN(), MH_ALIGN(), and MEXT_ALIGN() using m_align().
- Update consumers around the tree to simply use M_ALIGN().
This change eliminates a number of cases where mbuf consumers must be aware
of whether or not mbufs returned by the allocator use external storage, but
also assumptions about the size of the returned mbuf. This will make it
easier to introduce changes in how we use external storage, as well as
features such as variable-size mbufs.
Differential Revision: https://reviews.freebsd.org/D1436
Reviewed by: glebius, trasz, gnn, bz
Sponsored by: EMC / Isilon Storage Division
2015-01-05 09:58:32 +00:00
|
|
|
#define SCTP_ALIGN_TO_END(m, len) M_ALIGN(m, len)
|
2007-05-30 17:39:45 +00:00
|
|
|
|
|
|
|
/* We make it so if you have up to 4 threads
|
2010-11-09 10:59:09 +00:00
|
|
|
* writing based on the default size of
|
2007-05-30 17:39:45 +00:00
|
|
|
* the packet log 65 k, that would be
|
|
|
|
* 4 16k packets before we would hit
|
|
|
|
* a problem.
|
|
|
|
*/
|
|
|
|
#define SCTP_PKTLOG_WRITERS_NEED_LOCK 3
|
|
|
|
|
2007-05-08 00:21:05 +00:00
|
|
|
/*************************/
|
|
|
|
/* MTU */
|
|
|
|
/*************************/
|
2007-06-01 11:19:54 +00:00
|
|
|
#define SCTP_GATHER_MTU_FROM_IFN_INFO(ifn, ifn_index, af) ((struct ifnet *)ifn)->if_mtu
|
2014-09-16 09:22:43 +00:00
|
|
|
#define SCTP_GATHER_MTU_FROM_ROUTE(sctp_ifa, sa, rt) ((uint32_t)((rt != NULL) ? rt->rt_mtu : 0))
|
2007-05-08 00:21:05 +00:00
|
|
|
#define SCTP_GATHER_MTU_FROM_INTFC(sctp_ifn) ((sctp_ifn->ifn_p != NULL) ? ((struct ifnet *)(sctp_ifn->ifn_p))->if_mtu : 0)
|
|
|
|
#define SCTP_SET_MTU_OF_ROUTE(sa, rt, mtu) do { \
|
|
|
|
if (rt != NULL) \
|
2014-03-05 01:17:47 +00:00
|
|
|
rt->rt_mtu = mtu; \
|
2007-05-08 00:21:05 +00:00
|
|
|
} while(0)
|
|
|
|
|
|
|
|
/* (de-)register interface event notifications */
|
2007-06-01 11:19:54 +00:00
|
|
|
#define SCTP_REGISTER_INTERFACE(ifhandle, af)
|
|
|
|
#define SCTP_DEREGISTER_INTERFACE(ifhandle, af)
|
2007-03-31 11:47:30 +00:00
|
|
|
|
2007-07-17 20:58:26 +00:00
|
|
|
|
2006-12-29 20:21:42 +00:00
|
|
|
/*************************/
|
|
|
|
/* These are for logging */
|
|
|
|
/*************************/
|
|
|
|
/* return the base ext data pointer */
|
|
|
|
#define SCTP_BUF_EXTEND_BASE(m) (m->m_ext.ext_buf)
|
|
|
|
/* return the refcnt of the data pointer */
|
2014-07-11 14:34:29 +00:00
|
|
|
#define SCTP_BUF_EXTEND_REFCNT(m) (*m->m_ext.ext_cnt)
|
2006-12-29 20:21:42 +00:00
|
|
|
/* return any buffer related flags, this is
|
|
|
|
* used beyond logging for apple only.
|
|
|
|
*/
|
|
|
|
#define SCTP_BUF_GET_FLAGS(m) (m->m_flags)
|
|
|
|
|
|
|
|
/* For BSD this just accesses the M_PKTHDR length
|
|
|
|
* so it operates on an mbuf with hdr flag. Other
|
2010-11-09 10:59:09 +00:00
|
|
|
* O/S's may have separate packet header and mbuf
|
2006-12-29 20:21:42 +00:00
|
|
|
* chain pointers.. thus the macro.
|
|
|
|
*/
|
|
|
|
#define SCTP_HEADER_TO_CHAIN(m) (m)
|
2007-05-08 00:21:05 +00:00
|
|
|
#define SCTP_DETACH_HEADER_FROM_CHAIN(m)
|
2012-06-24 21:25:54 +00:00
|
|
|
#define SCTP_HEADER_LEN(m) ((m)->m_pkthdr.len)
|
2007-05-08 00:21:05 +00:00
|
|
|
#define SCTP_GET_HEADER_FOR_OUTPUT(o_pak) 0
|
|
|
|
#define SCTP_RELEASE_HEADER(m)
|
|
|
|
#define SCTP_RELEASE_PKT(m) sctp_m_freem(m)
|
2008-06-14 07:58:05 +00:00
|
|
|
#define SCTP_ENABLE_UDP_CSUM(m) do { \
|
|
|
|
m->m_pkthdr.csum_flags = CSUM_UDP; \
|
|
|
|
m->m_pkthdr.csum_data = offsetof(struct udphdr, uh_sum); \
|
|
|
|
} while (0)
|
2007-05-08 00:21:05 +00:00
|
|
|
|
2007-06-16 00:33:47 +00:00
|
|
|
#define SCTP_GET_PKT_VRFID(m, vrf_id) ((vrf_id = SCTP_DEFAULT_VRFID) != SCTP_DEFAULT_VRFID)
|
|
|
|
|
|
|
|
|
2006-12-29 20:21:42 +00:00
|
|
|
|
|
|
|
/* Attach the chain of data into the sendable packet. */
|
|
|
|
#define SCTP_ATTACH_CHAIN(pak, m, packet_length) do { \
|
2007-05-08 00:21:05 +00:00
|
|
|
pak = m; \
|
2006-12-29 20:21:42 +00:00
|
|
|
pak->m_pkthdr.len = packet_length; \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
/* Other m_pkthdr type things */
|
2007-05-29 09:29:03 +00:00
|
|
|
#define SCTP_IS_IT_BROADCAST(dst, m) ((m->m_flags & M_PKTHDR) ? in_broadcast(dst, m->m_pkthdr.rcvif) : 0)
|
|
|
|
#define SCTP_IS_IT_LOOPBACK(m) ((m->m_flags & M_PKTHDR) && ((m->m_pkthdr.rcvif == NULL) || (m->m_pkthdr.rcvif->if_type == IFT_LOOP)))
|
2006-12-29 20:21:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* This converts any input packet header
|
|
|
|
* into the chain of data holders, for BSD
|
|
|
|
* its a NOP.
|
|
|
|
*/
|
|
|
|
|
2007-05-08 00:21:05 +00:00
|
|
|
/* get the v6 hop limit */
|
|
|
|
#define SCTP_GET_HLIM(inp, ro) in6_selecthlim((struct in6pcb *)&inp->ip_inp.inp, (ro ? (ro->ro_rt ? (ro->ro_rt->rt_ifp) : (NULL)) : (NULL)));
|
|
|
|
|
2007-01-15 15:12:10 +00:00
|
|
|
/* is the endpoint v6only? */
|
|
|
|
#define SCTP_IPV6_V6ONLY(inp) (((struct inpcb *)inp)->inp_flags & IN6P_IPV6_V6ONLY)
|
2007-03-15 11:27:14 +00:00
|
|
|
/* is the socket non-blocking? */
|
|
|
|
#define SCTP_SO_IS_NBIO(so) ((so)->so_state & SS_NBIO)
|
|
|
|
#define SCTP_SET_SO_NBIO(so) ((so)->so_state |= SS_NBIO)
|
|
|
|
#define SCTP_CLEAR_SO_NBIO(so) ((so)->so_state &= ~SS_NBIO)
|
|
|
|
/* get the socket type */
|
|
|
|
#define SCTP_SO_TYPE(so) ((so)->so_type)
|
2015-03-11 15:40:29 +00:00
|
|
|
/* Use a macro for renaming sb_cc to sb_acc.
|
|
|
|
* Initially sb_ccc was used, but this broke select() when used
|
|
|
|
* with SCTP sockets.
|
|
|
|
*/
|
2015-03-11 15:21:39 +00:00
|
|
|
#define sb_cc sb_acc
|
2007-03-19 06:53:02 +00:00
|
|
|
/* reserve sb space for a socket */
|
|
|
|
#define SCTP_SORESERVE(so, send, recv) soreserve(so, send, recv)
|
2007-05-08 00:21:05 +00:00
|
|
|
/* wakeup a socket */
|
|
|
|
#define SCTP_SOWAKEUP(so) wakeup(&(so)->so_timeo)
|
2007-03-19 06:53:02 +00:00
|
|
|
/* clear the socket buffer state */
|
|
|
|
#define SCTP_SB_CLEAR(sb) \
|
2014-12-02 20:29:29 +00:00
|
|
|
(sb).sb_cc = 0; \
|
2007-03-19 06:53:02 +00:00
|
|
|
(sb).sb_mb = NULL; \
|
|
|
|
(sb).sb_mbcnt = 0;
|
2007-01-15 15:12:10 +00:00
|
|
|
|
2017-07-20 14:50:13 +00:00
|
|
|
#define SCTP_SB_LIMIT_RCV(so) (SOLISTENING(so) ? so->sol_sbrcv_hiwat : so->so_rcv.sb_hiwat)
|
|
|
|
#define SCTP_SB_LIMIT_SND(so) (SOLISTENING(so) ? so->sol_sbsnd_hiwat : so->so_snd.sb_hiwat)
|
2007-03-20 10:23:11 +00:00
|
|
|
|
2007-04-03 11:15:32 +00:00
|
|
|
/*
|
|
|
|
* routes, output, etc.
|
|
|
|
*/
|
|
|
|
typedef struct route sctp_route_t;
|
2007-05-08 00:21:05 +00:00
|
|
|
typedef struct rtentry sctp_rtentry_t;
|
|
|
|
|
2015-06-17 15:20:14 +00:00
|
|
|
#define SCTP_RTALLOC(ro, vrf_id, fibnum) \
|
|
|
|
rtalloc_ign_fib((struct route *)ro, 0UL, fibnum)
|
2007-04-03 11:15:32 +00:00
|
|
|
|
2013-08-19 12:30:18 +00:00
|
|
|
/*
|
|
|
|
* SCTP protocol specific mbuf flags.
|
|
|
|
*/
|
2013-08-19 14:25:11 +00:00
|
|
|
#define M_NOTIFICATION M_PROTO1 /* SCTP notification */
|
2013-08-19 12:30:18 +00:00
|
|
|
|
2007-05-08 00:21:05 +00:00
|
|
|
/*
|
|
|
|
* IP output routines
|
|
|
|
*/
|
2007-06-01 11:19:54 +00:00
|
|
|
#define SCTP_IP_OUTPUT(result, o_pak, ro, stcb, vrf_id) \
|
2007-05-08 00:21:05 +00:00
|
|
|
{ \
|
2010-08-29 18:50:30 +00:00
|
|
|
int o_flgs = IP_RAWOUTPUT; \
|
|
|
|
struct sctp_tcb *local_stcb = stcb; \
|
|
|
|
if (local_stcb && \
|
|
|
|
local_stcb->sctp_ep && \
|
|
|
|
local_stcb->sctp_ep->sctp_socket) \
|
|
|
|
o_flgs |= local_stcb->sctp_ep->sctp_socket->so_options & SO_DONTROUTE; \
|
2013-08-19 13:27:32 +00:00
|
|
|
m_clrprotoflags(o_pak); \
|
2007-05-08 00:21:05 +00:00
|
|
|
result = ip_output(o_pak, NULL, ro, o_flgs, 0, NULL); \
|
|
|
|
}
|
|
|
|
|
2007-06-01 11:19:54 +00:00
|
|
|
#define SCTP_IP6_OUTPUT(result, o_pak, ro, ifp, stcb, vrf_id) \
|
2007-05-08 00:21:05 +00:00
|
|
|
{ \
|
2010-08-29 18:50:30 +00:00
|
|
|
struct sctp_tcb *local_stcb = stcb; \
|
2013-08-19 13:27:32 +00:00
|
|
|
m_clrprotoflags(o_pak); \
|
2010-08-29 18:50:30 +00:00
|
|
|
if (local_stcb && local_stcb->sctp_ep) \
|
2007-05-08 00:21:05 +00:00
|
|
|
result = ip6_output(o_pak, \
|
2010-08-29 18:50:30 +00:00
|
|
|
((struct in6pcb *)(local_stcb->sctp_ep))->in6p_outputopts, \
|
2007-05-08 00:21:05 +00:00
|
|
|
(ro), 0, 0, ifp, NULL); \
|
|
|
|
else \
|
|
|
|
result = ip6_output(o_pak, NULL, (ro), 0, 0, ifp, NULL); \
|
|
|
|
}
|
2007-04-03 11:15:32 +00:00
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
2007-02-12 23:24:31 +00:00
|
|
|
/*
|
|
|
|
* SCTP AUTH
|
|
|
|
*/
|
|
|
|
#define SCTP_READ_RANDOM(buf, len) read_random(buf, len)
|
|
|
|
|
|
|
|
/* map standard crypto API names */
|
2013-09-02 22:48:41 +00:00
|
|
|
#define SCTP_SHA1_CTX SHA1_CTX
|
|
|
|
#define SCTP_SHA1_INIT SHA1Init
|
|
|
|
#define SCTP_SHA1_UPDATE SHA1Update
|
|
|
|
#define SCTP_SHA1_FINAL(x,y) SHA1Final((caddr_t)x, y)
|
|
|
|
|
|
|
|
#define SCTP_SHA256_CTX SHA256_CTX
|
|
|
|
#define SCTP_SHA256_INIT SHA256_Init
|
|
|
|
#define SCTP_SHA256_UPDATE SHA256_Update
|
|
|
|
#define SCTP_SHA256_FINAL(x,y) SHA256_Final((caddr_t)x, y)
|
2007-02-12 23:24:31 +00:00
|
|
|
|
2008-12-06 13:19:54 +00:00
|
|
|
#define SCTP_DECREMENT_AND_CHECK_REFCOUNT(addr) (atomic_fetchadd_int(addr, -1) == 1)
|
|
|
|
#if defined(INVARIANTS)
|
|
|
|
#define SCTP_SAVE_ATOMIC_DECREMENT(addr, val) \
|
|
|
|
{ \
|
|
|
|
int32_t oldval; \
|
2016-04-07 09:34:41 +00:00
|
|
|
oldval = atomic_fetchadd_int(addr, -val); \
|
2008-12-06 13:19:54 +00:00
|
|
|
if (oldval < val) { \
|
2016-04-07 09:34:41 +00:00
|
|
|
panic("Counter goes negative"); \
|
2008-12-06 13:19:54 +00:00
|
|
|
} \
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define SCTP_SAVE_ATOMIC_DECREMENT(addr, val) \
|
|
|
|
{ \
|
|
|
|
int32_t oldval; \
|
|
|
|
oldval = atomic_fetchadd_int(addr, -val); \
|
|
|
|
if (oldval < val) { \
|
|
|
|
*addr = 0; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
#endif
|
2017-05-26 16:29:00 +00:00
|
|
|
|
|
|
|
#define SCTP_IS_LISTENING(inp) ((inp->sctp_flags & SCTP_PCB_FLAGS_ACCEPTING) != 0)
|
|
|
|
|
|
|
|
#endif
|