1dfc5c98a4
This particular implementation is designed to be fully backwards compatible and to be MFC-able to 7.x (and 6.x) Currently the only protocol that can make use of the multiple tables is IPv4 Similar functionality exists in OpenBSD and Linux. From my notes: ----- One thing where FreeBSD has been falling behind, and which by chance I have some time to work on is "policy based routing", which allows different packet streams to be routed by more than just the destination address. Constraints: ------------ I want to make some form of this available in the 6.x tree (and by extension 7.x) , but FreeBSD in general needs it so I might as well do it in -current and back port the portions I need. One of the ways that this can be done is to have the ability to instantiate multiple kernel routing tables (which I will now refer to as "Forwarding Information Bases" or "FIBs" for political correctness reasons). Which FIB a particular packet uses to make the next hop decision can be decided by a number of mechanisms. The policies these mechanisms implement are the "Policies" referred to in "Policy based routing". One of the constraints I have if I try to back port this work to 6.x is that it must be implemented as a EXTENSION to the existing ABIs in 6.x so that third party applications do not need to be recompiled in timespan of the branch. This first version will not have some of the bells and whistles that will come with later versions. It will, for example, be limited to 16 tables in the first commit. Implementation method, Compatible version. (part 1) ------------------------------- For this reason I have implemented a "sufficient subset" of a multiple routing table solution in Perforce, and back-ported it to 6.x. (also in Perforce though not always caught up with what I have done in -current/P4). The subset allows a number of FIBs to be defined at compile time (8 is sufficient for my purposes in 6.x) and implements the changes needed to allow IPV4 to use them. I have not done the changes for ipv6 simply because I do not need it, and I do not have enough knowledge of ipv6 (e.g. neighbor discovery) needed to do it. Other protocol families are left untouched and should there be users with proprietary protocol families, they should continue to work and be oblivious to the existence of the extra FIBs. To understand how this is done, one must know that the current FIB code starts everything off with a single dimensional array of pointers to FIB head structures (One per protocol family), each of which in turn points to the trie of routes available to that family. The basic change in the ABI compatible version of the change is to extent that array to be a 2 dimensional array, so that instead of protocol family X looking at rt_tables[X] for the table it needs, it looks at rt_tables[Y][X] when for all protocol families except ipv4 Y is always 0. Code that is unaware of the change always just sees the first row of the table, which of course looks just like the one dimensional array that existed before. The entry points rtrequest(), rtalloc(), rtalloc1(), rtalloc_ign() are all maintained, but refer only to the first row of the array, so that existing callers in proprietary protocols can continue to do the "right thing". Some new entry points are added, for the exclusive use of ipv4 code called in_rtrequest(), in_rtalloc(), in_rtalloc1() and in_rtalloc_ign(), which have an extra argument which refers the code to the correct row. In addition, there are some new entry points (currently called rtalloc_fib() and friends) that check the Address family being looked up and call either rtalloc() (and friends) if the protocol is not IPv4 forcing the action to row 0 or to the appropriate row if it IS IPv4 (and that info is available). These are for calling from code that is not specific to any particular protocol. The way these are implemented would change in the non ABI preserving code to be added later. One feature of the first version of the code is that for ipv4, the interface routes show up automatically on all the FIBs, so that no matter what FIB you select you always have the basic direct attached hosts available to you. (rtinit() does this automatically). You CAN delete an interface route from one FIB should you want to but by default it's there. ARP information is also available in each FIB. It's assumed that the same machine would have the same MAC address, regardless of which FIB you are using to get to it. This brings us as to how the correct FIB is selected for an outgoing IPV4 packet. Firstly, all packets have a FIB associated with them. if nothing has been done to change it, it will be FIB 0. The FIB is changed in the following ways. Packets fall into one of a number of classes. 1/ locally generated packets, coming from a socket/PCB. Such packets select a FIB from a number associated with the socket/PCB. This in turn is inherited from the process, but can be changed by a socket option. The process in turn inherits it on fork. I have written a utility call setfib that acts a bit like nice.. setfib -3 ping target.example.com # will use fib 3 for ping. It is an obvious extension to make it a property of a jail but I have not done so. It can be achieved by combining the setfib and jail commands. 2/ packets received on an interface for forwarding. By default these packets would use table 0, (or possibly a number settable in a sysctl(not yet)). but prior to routing the firewall can inspect them (see below). (possibly in the future you may be able to associate a FIB with packets received on an interface.. An ifconfig arg, but not yet.) 3/ packets inspected by a packet classifier, which can arbitrarily associate a fib with it on a packet by packet basis. A fib assigned to a packet by a packet classifier (such as ipfw) would over-ride a fib associated by a more default source. (such as cases 1 or 2). 4/ a tcp listen socket associated with a fib will generate accept sockets that are associated with that same fib. 5/ Packets generated in response to some other packet (e.g. reset or icmp packets). These should use the FIB associated with the packet being reponded to. 6/ Packets generated during encapsulation. gif, tun and other tunnel interfaces will encapsulate using the FIB that was in effect withthe proces that set up the tunnel. thus setfib 1 ifconfig gif0 [tunnel instructions] will set the fib for the tunnel to use to be fib 1. Routing messages would be associated with their process, and thus select one FIB or another. messages from the kernel would be associated with the fib they refer to and would only be received by a routing socket associated with that fib. (not yet implemented) In addition Netstat has been edited to be able to cope with the fact that the array is now 2 dimensional. (It looks in system memory using libkvm (!)). Old versions of netstat see only the first FIB. In addition two sysctls are added to give: a) the number of FIBs compiled in (active) b) the default FIB of the calling process. Early testing experience: ------------------------- Basically our (IronPort's) appliance does this functionality already using ipfw fwd but that method has some drawbacks. For example, It can't fully simulate a routing table because it can't influence the socket's choice of local address when a connect() is done. Testing during the generating of these changes has been remarkably smooth so far. Multiple tables have co-existed with no notable side effects, and packets have been routes accordingly. ipfw has grown 2 new keywords: setfib N ip from anay to any count ip from any to any fib N In pf there seems to be a requirement to be able to give symbolic names to the fibs but I do not have that capacity. I am not sure if it is required. SCTP has interestingly enough built in support for this, called VRFs in Cisco parlance. it will be interesting to see how that handles it when it suddenly actually does something. Where to next: -------------------- After committing the ABI compatible version and MFCing it, I'd like to proceed in a forward direction in -current. this will result in some roto-tilling in the routing code. Firstly: the current code's idea of having a separate tree per protocol family, all of the same format, and pointed to by the 1 dimensional array is a bit silly. Especially when one considers that there is code that makes assumptions about every protocol having the same internal structures there. Some protocols don't WANT that sort of structure. (for example the whole idea of a netmask is foreign to appletalk). This needs to be made opaque to the external code. My suggested first change is to add routing method pointers to the 'domain' structure, along with information pointing the data. instead of having an array of pointers to uniform structures, there would be an array pointing to the 'domain' structures for each protocol address domain (protocol family), and the methods this reached would be called. The methods would have an argument that gives FIB number, but the protocol would be free to ignore it. When the ABI can be changed it raises the possibilty of the addition of a fib entry into the "struct route". Currently, the structure contains the sockaddr of the desination, and the resulting fib entry. To make this work fully, one could add a fib number so that given an address and a fib, one can find the third element, the fib entry. Interaction with the ARP layer/ LL layer would need to be revisited as well. Qing Li has been working on this already. This work was sponsored by Ironport Systems/Cisco Reviewed by: several including rwatson, bz and mlair (parts each) Obtained from: Ironport systems/Cisco
466 lines
14 KiB
C
466 lines
14 KiB
C
/*-
|
|
* Copyright (c) 2006-2007, by Cisco Systems, Inc. All rights reserved.
|
|
*
|
|
* 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.
|
|
*/
|
|
#include <sys/cdefs.h>
|
|
__FBSDID("$FreeBSD$");
|
|
#ifndef __sctp_os_bsd_h__
|
|
#define __sctp_os_bsd_h__
|
|
/*
|
|
* includes
|
|
*/
|
|
#include "opt_ipsec.h"
|
|
#include "opt_compat.h"
|
|
#include "opt_inet6.h"
|
|
#include "opt_inet.h"
|
|
#include "opt_sctp.h"
|
|
#include <sys/param.h>
|
|
#include <sys/ktr.h>
|
|
#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>
|
|
#include <sys/jail.h>
|
|
#include <sys/sysctl.h>
|
|
#include <sys/resourcevar.h>
|
|
#include <sys/uio.h>
|
|
#include <sys/lock.h>
|
|
#include <sys/rwlock.h>
|
|
#include <sys/kthread.h>
|
|
#include <sys/priv.h>
|
|
#include <sys/random.h>
|
|
#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>
|
|
|
|
#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 IPSEC
|
|
#include <netipsec/ipsec.h>
|
|
#include <netipsec/key.h>
|
|
#endif /* IPSEC */
|
|
|
|
#ifdef INET6
|
|
#include <sys/domain.h>
|
|
#ifdef IPSEC
|
|
#include <netipsec/ipsec6.h>
|
|
#endif
|
|
#include <netinet/ip6.h>
|
|
#include <netinet6/ip6_var.h>
|
|
#include <netinet6/in6_pcb.h>
|
|
#include <netinet/icmp6.h>
|
|
#include <netinet6/ip6protosw.h>
|
|
#include <netinet6/nd6.h>
|
|
#include <netinet6/scope6_var.h>
|
|
#endif /* INET6 */
|
|
|
|
|
|
#include <netinet/ip_options.h>
|
|
|
|
#ifndef in6pcb
|
|
#define in6pcb inpcb
|
|
#endif
|
|
/* 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);
|
|
|
|
#if defined(SCTP_LOCAL_TRACE_BUF)
|
|
|
|
#define SCTP_GET_CYCLECOUNT get_cyclecount()
|
|
#define SCTP_CTR6 sctp_log_trace
|
|
|
|
#else
|
|
#define SCTP_CTR6 CTR6
|
|
#endif
|
|
|
|
|
|
/*
|
|
*
|
|
*/
|
|
#define USER_ADDR_NULL (NULL) /* FIX ME: temp */
|
|
#define SCTP_LIST_EMPTY(list) LIST_EMPTY(list)
|
|
|
|
#if defined(SCTP_DEBUG)
|
|
#define SCTPDBG(level, params...) \
|
|
{ \
|
|
do { \
|
|
if (sctp_debug_on & level ) { \
|
|
printf(params); \
|
|
} \
|
|
} while (0); \
|
|
}
|
|
#define SCTPDBG_ADDR(level, addr) \
|
|
{ \
|
|
do { \
|
|
if (sctp_debug_on & level ) { \
|
|
sctp_print_address(addr); \
|
|
} \
|
|
} while (0); \
|
|
}
|
|
#define SCTPDBG_PKT(level, iph, sh) \
|
|
{ \
|
|
do { \
|
|
if (sctp_debug_on & level) { \
|
|
sctp_print_address_pkt(iph, sh); \
|
|
} \
|
|
} while (0); \
|
|
}
|
|
#else
|
|
#define SCTPDBG(level, params...)
|
|
#define SCTPDBG_ADDR(level, addr)
|
|
#define SCTPDBG_PKT(level, iph, sh)
|
|
#endif
|
|
#define SCTP_PRINTF(params...) printf(params)
|
|
|
|
#ifdef SCTP_LTRACE_CHUNKS
|
|
#define SCTP_LTRACE_CHK(a, b, c, d) if(sctp_logging_level & SCTP_LTRACE_CHUNK_ENABLE) CTR6(KTR_SUBSYS, "SCTP:%d[%d]:%x-%x-%x-%x", SCTP_LOG_CHUNK_PROC, 0, a, b, c, d)
|
|
#else
|
|
#define SCTP_LTRACE_CHK(a, b, c, d)
|
|
#endif
|
|
|
|
#ifdef SCTP_LTRACE_ERRORS
|
|
#define SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, net, file, err) if(sctp_logging_level & SCTP_LTRACE_ERROR_ENABLE) \
|
|
printf("mbuf:%p inp:%p stcb:%p net:%p file:%x line:%d error:%d\n", \
|
|
m, inp, stcb, net, file, __LINE__, err);
|
|
#define SCTP_LTRACE_ERR_RET(inp, stcb, net, file, err) if(sctp_logging_level & SCTP_LTRACE_ERROR_ENABLE) \
|
|
printf("inp:%p stcb:%p net:%p file:%x line:%d error:%d\n", \
|
|
inp, stcb, net, file, __LINE__, err);
|
|
#else
|
|
#define SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, net, file, err)
|
|
#define SCTP_LTRACE_ERR_RET(inp, stcb, net, file, err)
|
|
#endif
|
|
|
|
|
|
/*
|
|
* Local address and interface list handling
|
|
*/
|
|
#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
|
|
#define SCTP_INIT_VRF_TABLEID(vrf)
|
|
|
|
#define SCTP_IFN_IS_IFT_LOOP(ifn) ((ifn)->ifn_type == IFT_LOOP)
|
|
|
|
/*
|
|
* 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
|
|
#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)
|
|
|
|
/*
|
|
* general memory allocation
|
|
*/
|
|
#define SCTP_MALLOC(var, type, size, name) \
|
|
do { \
|
|
MALLOC(var, type, size, name, M_NOWAIT); \
|
|
} while (0)
|
|
|
|
#define SCTP_FREE(var, type) FREE(var, type)
|
|
|
|
#define SCTP_MALLOC_SONAME(var, type, size) \
|
|
do { \
|
|
MALLOC(var, type, size, M_SONAME, M_WAITOK | M_ZERO); \
|
|
} while (0)
|
|
|
|
#define SCTP_FREE_SONAME(var) FREE(var, M_SONAME)
|
|
|
|
#define SCTP_PROCESS_STRUCT struct proc *
|
|
|
|
/*
|
|
* zone allocation functions
|
|
*/
|
|
#include <vm/uma.h>
|
|
/* SCTP_ZONE_INIT: initialize the zone */
|
|
typedef struct uma_zone *sctp_zone_t;
|
|
|
|
#define UMA_ZFLAG_FULL 0x0020
|
|
#define SCTP_ZONE_INIT(zone, name, size, number) { \
|
|
zone = uma_zcreate(name, size, NULL, NULL, NULL, NULL, UMA_ALIGN_PTR,\
|
|
UMA_ZFLAG_FULL); \
|
|
uma_zone_set_max(zone, number); \
|
|
}
|
|
|
|
/* SCTP_ZONE_GET: allocate element from the zone */
|
|
#define SCTP_ZONE_GET(zone, type) \
|
|
(type *)uma_zalloc(zone, M_NOWAIT);
|
|
|
|
/* SCTP_ZONE_FREE: free element from the zone */
|
|
#define SCTP_ZONE_FREE(zone, element) \
|
|
uma_zfree(zone, element);
|
|
#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
|
|
|
|
/*
|
|
* timers
|
|
*/
|
|
#include <sys/callout.h>
|
|
typedef struct callout sctp_os_timer_t;
|
|
|
|
#define SCTP_OS_TIMER_INIT(tmr) callout_init(tmr, 1)
|
|
#define SCTP_OS_TIMER_START callout_reset
|
|
#define SCTP_OS_TIMER_STOP callout_stop
|
|
#define SCTP_OS_TIMER_STOP_DRAIN callout_drain
|
|
#define SCTP_OS_TIMER_PENDING callout_pending
|
|
#define SCTP_OS_TIMER_ACTIVE callout_active
|
|
#define SCTP_OS_TIMER_DEACTIVATE callout_deactivate
|
|
|
|
#define sctp_get_tick_count() (ticks)
|
|
|
|
/* The packed define for 64 bit platforms */
|
|
#define SCTP_PACKED __attribute__((packed))
|
|
#define SCTP_UNUSED __attribute__((unused))
|
|
|
|
/*
|
|
* Functions
|
|
*/
|
|
/* 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)
|
|
#define SCTP_BUF_EXTEND_SIZE(m) (m->m_ext.ext_size)
|
|
#define SCTP_BUF_TYPE(m) (m->m_type)
|
|
#define SCTP_BUF_RECVIF(m) (m->m_pkthdr.rcvif)
|
|
#define SCTP_BUF_PREPEND M_PREPEND
|
|
|
|
#define SCTP_ALIGN_TO_END(m, len) if(m->m_flags & M_PKTHDR) { \
|
|
MH_ALIGN(m, len); \
|
|
} else if ((m->m_flags & M_EXT) == 0) { \
|
|
M_ALIGN(m, len); \
|
|
}
|
|
|
|
/* We make it so if you have up to 4 threads
|
|
* writting based on the default size of
|
|
* the packet log 65 k, that would be
|
|
* 4 16k packets before we would hit
|
|
* a problem.
|
|
*/
|
|
#define SCTP_PKTLOG_WRITERS_NEED_LOCK 3
|
|
|
|
/*************************/
|
|
/* MTU */
|
|
/*************************/
|
|
#define SCTP_GATHER_MTU_FROM_IFN_INFO(ifn, ifn_index, af) ((struct ifnet *)ifn)->if_mtu
|
|
#define SCTP_GATHER_MTU_FROM_ROUTE(sctp_ifa, sa, rt) ((rt != NULL) ? rt->rt_rmx.rmx_mtu : 0)
|
|
#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) \
|
|
rt->rt_rmx.rmx_mtu = mtu; \
|
|
} while(0)
|
|
|
|
/* (de-)register interface event notifications */
|
|
#define SCTP_REGISTER_INTERFACE(ifhandle, af)
|
|
#define SCTP_DEREGISTER_INTERFACE(ifhandle, af)
|
|
|
|
|
|
/*************************/
|
|
/* 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 */
|
|
#define SCTP_BUF_EXTEND_REFCNT(m) (*m->m_ext.ref_cnt)
|
|
/* 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
|
|
* O/S's may have seperate packet header and mbuf
|
|
* chain pointers.. thus the macro.
|
|
*/
|
|
#define SCTP_HEADER_TO_CHAIN(m) (m)
|
|
#define SCTP_DETACH_HEADER_FROM_CHAIN(m)
|
|
#define SCTP_HEADER_LEN(m) (m->m_pkthdr.len)
|
|
#define SCTP_GET_HEADER_FOR_OUTPUT(o_pak) 0
|
|
#define SCTP_RELEASE_HEADER(m)
|
|
#define SCTP_RELEASE_PKT(m) sctp_m_freem(m)
|
|
|
|
#define SCTP_GET_PKT_VRFID(m, vrf_id) ((vrf_id = SCTP_DEFAULT_VRFID) != SCTP_DEFAULT_VRFID)
|
|
|
|
|
|
|
|
/* Attach the chain of data into the sendable packet. */
|
|
#define SCTP_ATTACH_CHAIN(pak, m, packet_length) do { \
|
|
pak = m; \
|
|
pak->m_pkthdr.len = packet_length; \
|
|
} while(0)
|
|
|
|
/* Other m_pkthdr type things */
|
|
#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)))
|
|
|
|
|
|
/* This converts any input packet header
|
|
* into the chain of data holders, for BSD
|
|
* its a NOP.
|
|
*/
|
|
|
|
/* Macro's for getting length from V6/V4 header */
|
|
#define SCTP_GET_IPV4_LENGTH(iph) (iph->ip_len)
|
|
#define SCTP_GET_IPV6_LENGTH(ip6) (ntohs(ip6->ip6_plen))
|
|
|
|
/* 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)));
|
|
|
|
/* is the endpoint v6only? */
|
|
#define SCTP_IPV6_V6ONLY(inp) (((struct inpcb *)inp)->inp_flags & IN6P_IPV6_V6ONLY)
|
|
/* 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)
|
|
/* reserve sb space for a socket */
|
|
#define SCTP_SORESERVE(so, send, recv) soreserve(so, send, recv)
|
|
/* wakeup a socket */
|
|
#define SCTP_SOWAKEUP(so) wakeup(&(so)->so_timeo)
|
|
/* clear the socket buffer state */
|
|
#define SCTP_SB_CLEAR(sb) \
|
|
(sb).sb_cc = 0; \
|
|
(sb).sb_mb = NULL; \
|
|
(sb).sb_mbcnt = 0;
|
|
|
|
#define SCTP_SB_LIMIT_RCV(so) so->so_rcv.sb_hiwat
|
|
#define SCTP_SB_LIMIT_SND(so) so->so_snd.sb_hiwat
|
|
|
|
/*
|
|
* routes, output, etc.
|
|
*/
|
|
typedef struct route sctp_route_t;
|
|
typedef struct rtentry sctp_rtentry_t;
|
|
|
|
#define SCTP_RTALLOC(ro, vrf_id) in_rtalloc_ign((struct route *)ro, 0UL, vrf_id)
|
|
|
|
/* Future zero copy wakeup/send function */
|
|
#define SCTP_ZERO_COPY_EVENT(inp, so)
|
|
/* This is re-pulse ourselves for sendbuf */
|
|
#define SCTP_ZERO_COPY_SENDQ_EVENT(inp, so)
|
|
|
|
/*
|
|
* IP output routines
|
|
*/
|
|
#define SCTP_IP_OUTPUT(result, o_pak, ro, stcb, vrf_id) \
|
|
{ \
|
|
int o_flgs = 0; \
|
|
if (stcb && stcb->sctp_ep && stcb->sctp_ep->sctp_socket) { \
|
|
o_flgs = IP_RAWOUTPUT | (stcb->sctp_ep->sctp_socket->so_options & SO_DONTROUTE); \
|
|
} else { \
|
|
o_flgs = IP_RAWOUTPUT; \
|
|
} \
|
|
result = ip_output(o_pak, NULL, ro, o_flgs, 0, NULL); \
|
|
}
|
|
|
|
#define SCTP_IP6_OUTPUT(result, o_pak, ro, ifp, stcb, vrf_id) \
|
|
{ \
|
|
if (stcb && stcb->sctp_ep) \
|
|
result = ip6_output(o_pak, \
|
|
((struct in6pcb *)(stcb->sctp_ep))->in6p_outputopts, \
|
|
(ro), 0, 0, ifp, NULL); \
|
|
else \
|
|
result = ip6_output(o_pak, NULL, (ro), 0, 0, ifp, NULL); \
|
|
}
|
|
|
|
struct mbuf *
|
|
sctp_get_mbuf_for_msg(unsigned int space_needed,
|
|
int want_header, int how, int allonebuf, int type);
|
|
|
|
|
|
/*
|
|
* SCTP AUTH
|
|
*/
|
|
#define HAVE_SHA2
|
|
|
|
#define SCTP_READ_RANDOM(buf, len) read_random(buf, len)
|
|
|
|
#ifdef USE_SCTP_SHA1
|
|
#include <netinet/sctp_sha1.h>
|
|
#else
|
|
#include <crypto/sha1.h>
|
|
/* map standard crypto API names */
|
|
#define SHA1_Init SHA1Init
|
|
#define SHA1_Update SHA1Update
|
|
#define SHA1_Final(x,y) SHA1Final((caddr_t)x, y)
|
|
#endif
|
|
|
|
#if defined(HAVE_SHA2)
|
|
#include <crypto/sha2/sha2.h>
|
|
#endif
|
|
|
|
#include <sys/md5.h>
|
|
/* map standard crypto API names */
|
|
#define MD5_Init MD5Init
|
|
#define MD5_Update MD5Update
|
|
#define MD5_Final MD5Final
|
|
|
|
#endif
|