1f8829a4aSRandall Stewart /*- 2b1006367SRandall Stewart * Copyright (c) 2006-2007, by Cisco Systems, Inc. All rights reserved. 3f8829a4aSRandall Stewart * 4f8829a4aSRandall Stewart * Redistribution and use in source and binary forms, with or without 5f8829a4aSRandall Stewart * modification, are permitted provided that the following conditions are met: 6f8829a4aSRandall Stewart * 7f8829a4aSRandall Stewart * a) Redistributions of source code must retain the above copyright notice, 8f8829a4aSRandall Stewart * this list of conditions and the following disclaimer. 9f8829a4aSRandall Stewart * 10f8829a4aSRandall Stewart * b) Redistributions in binary form must reproduce the above copyright 11f8829a4aSRandall Stewart * notice, this list of conditions and the following disclaimer in 12f8829a4aSRandall Stewart * the documentation and/or other materials provided with the distribution. 13f8829a4aSRandall Stewart * 14f8829a4aSRandall Stewart * c) Neither the name of Cisco Systems, Inc. nor the names of its 15f8829a4aSRandall Stewart * contributors may be used to endorse or promote products derived 16f8829a4aSRandall Stewart * from this software without specific prior written permission. 17f8829a4aSRandall Stewart * 18f8829a4aSRandall Stewart * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19f8829a4aSRandall Stewart * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20f8829a4aSRandall Stewart * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21f8829a4aSRandall Stewart * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22f8829a4aSRandall Stewart * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23f8829a4aSRandall Stewart * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24f8829a4aSRandall Stewart * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25f8829a4aSRandall Stewart * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26f8829a4aSRandall Stewart * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27f8829a4aSRandall Stewart * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28f8829a4aSRandall Stewart * THE POSSIBILITY OF SUCH DAMAGE. 29f8829a4aSRandall Stewart */ 3073932c69SRandall Stewart #include <sys/cdefs.h> 31f8829a4aSRandall Stewart __FBSDID("$FreeBSD$"); 32f8829a4aSRandall Stewart #ifndef __sctp_os_bsd_h__ 33f8829a4aSRandall Stewart #define __sctp_os_bsd_h__ 34f8829a4aSRandall Stewart /* 35f8829a4aSRandall Stewart * includes 36f8829a4aSRandall Stewart */ 3793164cf9SRandall Stewart #include "opt_ipsec.h" 3893164cf9SRandall Stewart #include "opt_compat.h" 3993164cf9SRandall Stewart #include "opt_inet6.h" 4093164cf9SRandall Stewart #include "opt_inet.h" 4193164cf9SRandall Stewart #include "opt_sctp.h" 4293164cf9SRandall Stewart #include <sys/param.h> 4380fefe0aSRandall Stewart #include <sys/ktr.h> 4493164cf9SRandall Stewart #include <sys/systm.h> 4593164cf9SRandall Stewart #include <sys/malloc.h> 4693164cf9SRandall Stewart #include <sys/kernel.h> 4793164cf9SRandall Stewart #include <sys/sysctl.h> 4893164cf9SRandall Stewart #include <sys/mbuf.h> 4993164cf9SRandall Stewart #include <sys/protosw.h> 5093164cf9SRandall Stewart #include <sys/socket.h> 5193164cf9SRandall Stewart #include <sys/socketvar.h> 5293164cf9SRandall Stewart #include <sys/sysctl.h> 5393164cf9SRandall Stewart #include <sys/resourcevar.h> 5493164cf9SRandall Stewart #include <sys/uio.h> 5542551e99SRandall Stewart #include <sys/kthread.h> 5693164cf9SRandall Stewart #include <sys/priv.h> 57f8829a4aSRandall Stewart #include <sys/random.h> 5893164cf9SRandall Stewart #include <sys/limits.h> 5993164cf9SRandall Stewart #include <sys/queue.h> 6093164cf9SRandall Stewart #include <machine/cpu.h> 6193164cf9SRandall Stewart 6293164cf9SRandall Stewart #include <net/if.h> 6393164cf9SRandall Stewart #include <net/if_types.h> 6493164cf9SRandall Stewart #include <net/if_var.h> 6593164cf9SRandall Stewart #include <net/route.h> 6693164cf9SRandall Stewart 6793164cf9SRandall Stewart #include <netinet/in.h> 6893164cf9SRandall Stewart #include <netinet/in_systm.h> 6993164cf9SRandall Stewart #include <netinet/ip.h> 7093164cf9SRandall Stewart #include <netinet/in_pcb.h> 7193164cf9SRandall Stewart #include <netinet/in_var.h> 7293164cf9SRandall Stewart #include <netinet/ip_var.h> 7393164cf9SRandall Stewart #include <netinet/ip_icmp.h> 7493164cf9SRandall Stewart #include <netinet/icmp_var.h> 7593164cf9SRandall Stewart 7693164cf9SRandall Stewart 7793164cf9SRandall Stewart #ifdef IPSEC 7893164cf9SRandall Stewart #include <netinet6/ipsec.h> 7993164cf9SRandall Stewart #include <netkey/key.h> 8093164cf9SRandall Stewart #endif /* IPSEC */ 8193164cf9SRandall Stewart 8293164cf9SRandall Stewart #ifdef INET6 8393164cf9SRandall Stewart #include <sys/domain.h> 8493164cf9SRandall Stewart #ifdef IPSEC 8593164cf9SRandall Stewart #include <netinet6/ipsec6.h> 8693164cf9SRandall Stewart #endif 8793164cf9SRandall Stewart #include <netinet/ip6.h> 8893164cf9SRandall Stewart #include <netinet6/ip6_var.h> 8993164cf9SRandall Stewart #include <netinet6/in6_pcb.h> 9093164cf9SRandall Stewart #include <netinet/icmp6.h> 9193164cf9SRandall Stewart #include <netinet6/ip6protosw.h> 9293164cf9SRandall Stewart #include <netinet6/nd6.h> 9393164cf9SRandall Stewart #include <netinet6/scope6_var.h> 9493164cf9SRandall Stewart #endif /* INET6 */ 9593164cf9SRandall Stewart 96f42a358aSRandall Stewart 9793164cf9SRandall Stewart #include <netinet/ip_options.h> 9893164cf9SRandall Stewart 9993164cf9SRandall Stewart #ifndef in6pcb 10093164cf9SRandall Stewart #define in6pcb inpcb 10193164cf9SRandall Stewart #endif 102207304d4SRandall Stewart /* Declare all the malloc names for all the various mallocs */ 103207304d4SRandall Stewart MALLOC_DECLARE(SCTP_M_MAP); 104207304d4SRandall Stewart MALLOC_DECLARE(SCTP_M_STRMI); 105207304d4SRandall Stewart MALLOC_DECLARE(SCTP_M_STRMO); 106207304d4SRandall Stewart MALLOC_DECLARE(SCTP_M_ASC_ADDR); 107207304d4SRandall Stewart MALLOC_DECLARE(SCTP_M_ASC_IT); 108207304d4SRandall Stewart MALLOC_DECLARE(SCTP_M_AUTH_CL); 109207304d4SRandall Stewart MALLOC_DECLARE(SCTP_M_AUTH_KY); 110207304d4SRandall Stewart MALLOC_DECLARE(SCTP_M_AUTH_HL); 111207304d4SRandall Stewart MALLOC_DECLARE(SCTP_M_AUTH_IF); 112207304d4SRandall Stewart MALLOC_DECLARE(SCTP_M_STRESET); 113207304d4SRandall Stewart MALLOC_DECLARE(SCTP_M_CMSG); 114207304d4SRandall Stewart MALLOC_DECLARE(SCTP_M_COPYAL); 115207304d4SRandall Stewart MALLOC_DECLARE(SCTP_M_VRF); 116207304d4SRandall Stewart MALLOC_DECLARE(SCTP_M_IFA); 117207304d4SRandall Stewart MALLOC_DECLARE(SCTP_M_IFN); 118207304d4SRandall Stewart MALLOC_DECLARE(SCTP_M_TIMW); 119207304d4SRandall Stewart MALLOC_DECLARE(SCTP_M_MVRF); 120207304d4SRandall Stewart MALLOC_DECLARE(SCTP_M_ITER); 121207304d4SRandall Stewart MALLOC_DECLARE(SCTP_M_SOCKOPT); 122f8829a4aSRandall Stewart 123f8829a4aSRandall Stewart /* 124f8829a4aSRandall Stewart * 125f8829a4aSRandall Stewart */ 126a5d547adSRandall Stewart #define USER_ADDR_NULL (NULL) /* FIX ME: temp */ 127f42a358aSRandall Stewart #define SCTP_LIST_EMPTY(list) LIST_EMPTY(list) 128a5d547adSRandall Stewart 12917205eccSRandall Stewart #if defined(SCTP_DEBUG) 13017205eccSRandall Stewart #define SCTPDBG(level, params...) \ 13117205eccSRandall Stewart { \ 13217205eccSRandall Stewart do { \ 13317205eccSRandall Stewart if (sctp_debug_on & level ) { \ 13417205eccSRandall Stewart printf(params); \ 13517205eccSRandall Stewart } \ 13617205eccSRandall Stewart } while (0); \ 13717205eccSRandall Stewart } 13817205eccSRandall Stewart #define SCTPDBG_ADDR(level, addr) \ 13917205eccSRandall Stewart { \ 14017205eccSRandall Stewart do { \ 14117205eccSRandall Stewart if (sctp_debug_on & level ) { \ 14217205eccSRandall Stewart sctp_print_address(addr); \ 14317205eccSRandall Stewart } \ 14417205eccSRandall Stewart } while (0); \ 14517205eccSRandall Stewart } 146ad81507eSRandall Stewart #define SCTPDBG_PKT(level, iph, sh) \ 147ad81507eSRandall Stewart { \ 148ad81507eSRandall Stewart do { \ 149ad81507eSRandall Stewart if (sctp_debug_on & level) { \ 150ad81507eSRandall Stewart sctp_print_address_pkt(iph, sh); \ 151ad81507eSRandall Stewart } \ 152ad81507eSRandall Stewart } while (0); \ 153ad81507eSRandall Stewart } 15417205eccSRandall Stewart #else 15517205eccSRandall Stewart #define SCTPDBG(level, params...) 15617205eccSRandall Stewart #define SCTPDBG_ADDR(level, addr) 157ad81507eSRandall Stewart #define SCTPDBG_PKT(level, iph, sh) 15817205eccSRandall Stewart #endif 159ad81507eSRandall Stewart #define SCTP_PRINTF(params...) printf(params) 16017205eccSRandall Stewart 16180fefe0aSRandall Stewart #ifdef SCTP_LTRACE_CHUNKS 16280fefe0aSRandall Stewart #define SCTP_LTRACE_CHK(a, b, c, d) if(sctp_logging_level & SCTP_LTRACE_CHUNK_ENABLE) CTR6(KTR_NET, "SCTP:%d[%d]:%x-%x-%x-%x", SCTP_LOG_CHUNK_PROC, 0, a, b, c, d) 16380fefe0aSRandall Stewart #else 16480fefe0aSRandall Stewart #define SCTP_LTRACE_CHK(a, b, c, d) 16580fefe0aSRandall Stewart #endif 16680fefe0aSRandall Stewart 16780fefe0aSRandall Stewart #ifdef SCTP_LTRACE_ERRORS 16880fefe0aSRandall Stewart #define SCTP_LTRACE_ERR(a, b, c, d) if(sctp_logging_level & SCTP_LTRACE_ERROR_ENABLE) CTR6(KTR_NET, "SCTP:%d[%d]:%x-%x-%x-%x", SCTP_LOG_ERROR_RET, 0, a, b, c, d) 16980fefe0aSRandall Stewart #else 17080fefe0aSRandall Stewart #define SCTP_LTRACE_ERR(a, b, c, d) 17180fefe0aSRandall Stewart #endif 17280fefe0aSRandall Stewart 173f8829a4aSRandall Stewart /* 17442551e99SRandall Stewart * Local address and interface list handling 17542551e99SRandall Stewart */ 17642551e99SRandall Stewart #define SCTP_MAX_VRF_ID 0 17742551e99SRandall Stewart #define SCTP_SIZE_OF_VRF_HASH 3 17842551e99SRandall Stewart #define SCTP_IFNAMSIZ IFNAMSIZ 17942551e99SRandall Stewart #define SCTP_DEFAULT_VRFID 0 18017205eccSRandall Stewart #define SCTP_VRF_ADDR_HASH_SIZE 16 18117205eccSRandall Stewart #define SCTP_VRF_IFN_HASH_SIZE 3 182f4c93d24SRandall Stewart #define SCTP_INIT_VRF_TABLEID(vrf) 18342551e99SRandall Stewart 18442551e99SRandall Stewart #define SCTP_IFN_IS_IFT_LOOP(ifn) ((ifn)->ifn_type == IFT_LOOP) 18542551e99SRandall Stewart 18642551e99SRandall Stewart /* 18742551e99SRandall Stewart * Access to IFN's to help with src-addr-selection 18842551e99SRandall Stewart */ 18942551e99SRandall Stewart /* This could return VOID if the index works but for BSD we provide both. */ 19042551e99SRandall Stewart #define SCTP_GET_IFN_VOID_FROM_ROUTE(ro) (void *)ro->ro_rt->rt_ifp 19117205eccSRandall Stewart #define SCTP_GET_IF_INDEX_FROM_ROUTE(ro) (ro)->ro_rt->rt_ifp->if_index 19217205eccSRandall Stewart #define SCTP_ROUTE_HAS_VALID_IFN(ro) ((ro)->ro_rt && (ro)->ro_rt->rt_ifp) 19342551e99SRandall Stewart 19442551e99SRandall Stewart /* 195f8829a4aSRandall Stewart * general memory allocation 196f8829a4aSRandall Stewart */ 197f8829a4aSRandall Stewart #define SCTP_MALLOC(var, type, size, name) \ 198f8829a4aSRandall Stewart do { \ 199207304d4SRandall Stewart MALLOC(var, type, size, name, M_NOWAIT); \ 200f8829a4aSRandall Stewart } while (0) 201f8829a4aSRandall Stewart 202207304d4SRandall Stewart #define SCTP_FREE(var, type) FREE(var, type) 203f8829a4aSRandall Stewart 204f8829a4aSRandall Stewart #define SCTP_MALLOC_SONAME(var, type, size) \ 205f8829a4aSRandall Stewart do { \ 206f8829a4aSRandall Stewart MALLOC(var, type, size, M_SONAME, M_WAITOK | M_ZERO); \ 207f8829a4aSRandall Stewart } while (0) 208f8829a4aSRandall Stewart 209f8829a4aSRandall Stewart #define SCTP_FREE_SONAME(var) FREE(var, M_SONAME) 210f8829a4aSRandall Stewart 21142551e99SRandall Stewart #define SCTP_PROCESS_STRUCT struct proc * 21242551e99SRandall Stewart 213f8829a4aSRandall Stewart /* 214f8829a4aSRandall Stewart * zone allocation functions 215f8829a4aSRandall Stewart */ 216f8829a4aSRandall Stewart #include <vm/uma.h> 217f8829a4aSRandall Stewart /* SCTP_ZONE_INIT: initialize the zone */ 218f8829a4aSRandall Stewart typedef struct uma_zone *sctp_zone_t; 219f8829a4aSRandall Stewart 220f8829a4aSRandall Stewart #define UMA_ZFLAG_FULL 0x0020 221f8829a4aSRandall Stewart #define SCTP_ZONE_INIT(zone, name, size, number) { \ 222f8829a4aSRandall Stewart zone = uma_zcreate(name, size, NULL, NULL, NULL, NULL, UMA_ALIGN_PTR,\ 223f8829a4aSRandall Stewart UMA_ZFLAG_FULL); \ 224f8829a4aSRandall Stewart uma_zone_set_max(zone, number); \ 225f8829a4aSRandall Stewart } 226f8829a4aSRandall Stewart 227f8829a4aSRandall Stewart /* SCTP_ZONE_GET: allocate element from the zone */ 228f42a358aSRandall Stewart #define SCTP_ZONE_GET(zone, type) \ 229f42a358aSRandall Stewart (type *)uma_zalloc(zone, M_NOWAIT); 230f8829a4aSRandall Stewart 231f8829a4aSRandall Stewart /* SCTP_ZONE_FREE: free element from the zone */ 232f8829a4aSRandall Stewart #define SCTP_ZONE_FREE(zone, element) \ 233f8829a4aSRandall Stewart uma_zfree(zone, element); 23444b7479bSRandall Stewart #define SCTP_HASH_INIT(size, hashmark) hashinit_flags(size, M_PCB, hashmark, HASH_NOWAIT) 23544b7479bSRandall Stewart #define SCTP_HASH_FREE(table, hashmark) hashdestroy(table, M_PCB, hashmark) 23644b7479bSRandall Stewart 23744b7479bSRandall Stewart #define SCTP_M_COPYM m_copym 238f8829a4aSRandall Stewart 239f8829a4aSRandall Stewart /* 240139bc87fSRandall Stewart * timers 241139bc87fSRandall Stewart */ 242139bc87fSRandall Stewart #include <sys/callout.h> 243139bc87fSRandall Stewart typedef struct callout sctp_os_timer_t; 244139bc87fSRandall Stewart 245139bc87fSRandall Stewart #define SCTP_OS_TIMER_INIT(tmr) callout_init(tmr, 1) 246139bc87fSRandall Stewart #define SCTP_OS_TIMER_START callout_reset 247139bc87fSRandall Stewart #define SCTP_OS_TIMER_STOP callout_stop 24844b7479bSRandall Stewart #define SCTP_OS_TIMER_STOP_DRAIN callout_drain 249139bc87fSRandall Stewart #define SCTP_OS_TIMER_PENDING callout_pending 250139bc87fSRandall Stewart #define SCTP_OS_TIMER_ACTIVE callout_active 251139bc87fSRandall Stewart #define SCTP_OS_TIMER_DEACTIVATE callout_deactivate 252139bc87fSRandall Stewart 253207304d4SRandall Stewart #define sctp_get_tick_count() (ticks) 254207304d4SRandall Stewart 25535918f85SRandall Stewart /* The packed define for 64 bit platforms */ 25635918f85SRandall Stewart #define SCTP_PACKED __attribute__((packed)) 25735918f85SRandall Stewart 258139bc87fSRandall Stewart /* 259f8829a4aSRandall Stewart * Functions 260f8829a4aSRandall Stewart */ 261139bc87fSRandall Stewart /* Mbuf manipulation and access macros */ 262139bc87fSRandall Stewart #define SCTP_BUF_LEN(m) (m->m_len) 263139bc87fSRandall Stewart #define SCTP_BUF_NEXT(m) (m->m_next) 264139bc87fSRandall Stewart #define SCTP_BUF_NEXT_PKT(m) (m->m_nextpkt) 265139bc87fSRandall Stewart #define SCTP_BUF_RESV_UF(m, size) m->m_data += size 266139bc87fSRandall Stewart #define SCTP_BUF_AT(m, size) m->m_data + size 267139bc87fSRandall Stewart #define SCTP_BUF_IS_EXTENDED(m) (m->m_flags & M_EXT) 268139bc87fSRandall Stewart #define SCTP_BUF_EXTEND_SIZE(m) (m->m_ext.ext_size) 269139bc87fSRandall Stewart #define SCTP_BUF_TYPE(m) (m->m_type) 270139bc87fSRandall Stewart #define SCTP_BUF_RECVIF(m) (m->m_pkthdr.rcvif) 271139bc87fSRandall Stewart #define SCTP_BUF_PREPEND M_PREPEND 2725e54f665SRandall Stewart 2735e54f665SRandall Stewart #define SCTP_ALIGN_TO_END(m, len) if(m->m_flags & M_PKTHDR) { \ 2745e54f665SRandall Stewart MH_ALIGN(m, len); \ 2755e54f665SRandall Stewart } else if ((m->m_flags & M_EXT) == 0) { \ 2765e54f665SRandall Stewart M_ALIGN(m, len); \ 2775e54f665SRandall Stewart } 2780696e120SRandall Stewart 2790696e120SRandall Stewart /* We make it so if you have up to 4 threads 2800696e120SRandall Stewart * writting based on the default size of 2810696e120SRandall Stewart * the packet log 65 k, that would be 2820696e120SRandall Stewart * 4 16k packets before we would hit 2830696e120SRandall Stewart * a problem. 2840696e120SRandall Stewart */ 2850696e120SRandall Stewart #define SCTP_PKTLOG_WRITERS_NEED_LOCK 3 2860696e120SRandall Stewart 28717205eccSRandall Stewart /*************************/ 28817205eccSRandall Stewart /* MTU */ 28917205eccSRandall Stewart /*************************/ 290ad21a364SRandall Stewart #define SCTP_GATHER_MTU_FROM_IFN_INFO(ifn, ifn_index, af) ((struct ifnet *)ifn)->if_mtu 29117205eccSRandall Stewart #define SCTP_GATHER_MTU_FROM_ROUTE(sctp_ifa, sa, rt) ((rt != NULL) ? rt->rt_rmx.rmx_mtu : 0) 29217205eccSRandall Stewart #define SCTP_GATHER_MTU_FROM_INTFC(sctp_ifn) ((sctp_ifn->ifn_p != NULL) ? ((struct ifnet *)(sctp_ifn->ifn_p))->if_mtu : 0) 29317205eccSRandall Stewart #define SCTP_SET_MTU_OF_ROUTE(sa, rt, mtu) do { \ 29417205eccSRandall Stewart if (rt != NULL) \ 29517205eccSRandall Stewart rt->rt_rmx.rmx_mtu = mtu; \ 29617205eccSRandall Stewart } while(0) 29717205eccSRandall Stewart 29817205eccSRandall Stewart /* (de-)register interface event notifications */ 299ad21a364SRandall Stewart #define SCTP_REGISTER_INTERFACE(ifhandle, af) 300ad21a364SRandall Stewart #define SCTP_DEREGISTER_INTERFACE(ifhandle, af) 3015e54f665SRandall Stewart 302139bc87fSRandall Stewart /*************************/ 303139bc87fSRandall Stewart /* These are for logging */ 304139bc87fSRandall Stewart /*************************/ 305139bc87fSRandall Stewart /* return the base ext data pointer */ 306139bc87fSRandall Stewart #define SCTP_BUF_EXTEND_BASE(m) (m->m_ext.ext_buf) 307139bc87fSRandall Stewart /* return the refcnt of the data pointer */ 308139bc87fSRandall Stewart #define SCTP_BUF_EXTEND_REFCNT(m) (*m->m_ext.ref_cnt) 309139bc87fSRandall Stewart /* return any buffer related flags, this is 310139bc87fSRandall Stewart * used beyond logging for apple only. 311139bc87fSRandall Stewart */ 312139bc87fSRandall Stewart #define SCTP_BUF_GET_FLAGS(m) (m->m_flags) 313139bc87fSRandall Stewart 314139bc87fSRandall Stewart /* For BSD this just accesses the M_PKTHDR length 315139bc87fSRandall Stewart * so it operates on an mbuf with hdr flag. Other 316139bc87fSRandall Stewart * O/S's may have seperate packet header and mbuf 317139bc87fSRandall Stewart * chain pointers.. thus the macro. 318139bc87fSRandall Stewart */ 319139bc87fSRandall Stewart #define SCTP_HEADER_TO_CHAIN(m) (m) 32017205eccSRandall Stewart #define SCTP_DETACH_HEADER_FROM_CHAIN(m) 321139bc87fSRandall Stewart #define SCTP_HEADER_LEN(m) (m->m_pkthdr.len) 32217205eccSRandall Stewart #define SCTP_GET_HEADER_FOR_OUTPUT(o_pak) 0 32317205eccSRandall Stewart #define SCTP_RELEASE_HEADER(m) 32417205eccSRandall Stewart #define SCTP_RELEASE_PKT(m) sctp_m_freem(m) 32517205eccSRandall Stewart 32617205eccSRandall Stewart static inline int 32717205eccSRandall Stewart SCTP_GET_PKT_VRFID(void *m, uint32_t vrf_id) 32817205eccSRandall Stewart { 32917205eccSRandall Stewart vrf_id = SCTP_DEFAULT_VRFID; 33017205eccSRandall Stewart return (0); 33117205eccSRandall Stewart } 332139bc87fSRandall Stewart 333139bc87fSRandall Stewart /* Attach the chain of data into the sendable packet. */ 334139bc87fSRandall Stewart #define SCTP_ATTACH_CHAIN(pak, m, packet_length) do { \ 33517205eccSRandall Stewart pak = m; \ 336139bc87fSRandall Stewart pak->m_pkthdr.len = packet_length; \ 337139bc87fSRandall Stewart } while(0) 338139bc87fSRandall Stewart 339139bc87fSRandall Stewart /* Other m_pkthdr type things */ 340207304d4SRandall Stewart #define SCTP_IS_IT_BROADCAST(dst, m) ((m->m_flags & M_PKTHDR) ? in_broadcast(dst, m->m_pkthdr.rcvif) : 0) 341207304d4SRandall Stewart #define SCTP_IS_IT_LOOPBACK(m) ((m->m_flags & M_PKTHDR) && ((m->m_pkthdr.rcvif == NULL) || (m->m_pkthdr.rcvif->if_type == IFT_LOOP))) 342139bc87fSRandall Stewart 343139bc87fSRandall Stewart 344139bc87fSRandall Stewart /* This converts any input packet header 345139bc87fSRandall Stewart * into the chain of data holders, for BSD 346139bc87fSRandall Stewart * its a NOP. 347139bc87fSRandall Stewart */ 348139bc87fSRandall Stewart 349139bc87fSRandall Stewart /* Macro's for getting length from V6/V4 header */ 350139bc87fSRandall Stewart #define SCTP_GET_IPV4_LENGTH(iph) (iph->ip_len) 351139bc87fSRandall Stewart #define SCTP_GET_IPV6_LENGTH(ip6) (ntohs(ip6->ip6_plen)) 352f8829a4aSRandall Stewart 35317205eccSRandall Stewart /* get the v6 hop limit */ 35417205eccSRandall Stewart #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))); 35517205eccSRandall Stewart 35644b7479bSRandall Stewart /* is the endpoint v6only? */ 35744b7479bSRandall Stewart #define SCTP_IPV6_V6ONLY(inp) (((struct inpcb *)inp)->inp_flags & IN6P_IPV6_V6ONLY) 35842551e99SRandall Stewart /* is the socket non-blocking? */ 35942551e99SRandall Stewart #define SCTP_SO_IS_NBIO(so) ((so)->so_state & SS_NBIO) 36042551e99SRandall Stewart #define SCTP_SET_SO_NBIO(so) ((so)->so_state |= SS_NBIO) 36142551e99SRandall Stewart #define SCTP_CLEAR_SO_NBIO(so) ((so)->so_state &= ~SS_NBIO) 36242551e99SRandall Stewart /* get the socket type */ 36342551e99SRandall Stewart #define SCTP_SO_TYPE(so) ((so)->so_type) 364132dea7dSRandall Stewart /* reserve sb space for a socket */ 365132dea7dSRandall Stewart #define SCTP_SORESERVE(so, send, recv) soreserve(so, send, recv) 36617205eccSRandall Stewart /* wakeup a socket */ 36717205eccSRandall Stewart #define SCTP_SOWAKEUP(so) wakeup(&(so)->so_timeo) 368132dea7dSRandall Stewart /* clear the socket buffer state */ 369132dea7dSRandall Stewart #define SCTP_SB_CLEAR(sb) \ 370132dea7dSRandall Stewart (sb).sb_cc = 0; \ 371132dea7dSRandall Stewart (sb).sb_mb = NULL; \ 372132dea7dSRandall Stewart (sb).sb_mbcnt = 0; 37344b7479bSRandall Stewart 37462c1ff9cSRandall Stewart #define SCTP_SB_LIMIT_RCV(so) so->so_rcv.sb_hiwat 37562c1ff9cSRandall Stewart #define SCTP_SB_LIMIT_SND(so) so->so_snd.sb_hiwat 37662c1ff9cSRandall Stewart 377f42a358aSRandall Stewart /* 378bff64a4dSRandall Stewart * routes, output, etc. 379bff64a4dSRandall Stewart */ 380bff64a4dSRandall Stewart typedef struct route sctp_route_t; 38117205eccSRandall Stewart typedef struct rtentry sctp_rtentry_t; 382bff64a4dSRandall Stewart 383ad21a364SRandall Stewart #define SCTP_RTALLOC(ro, vrf_id) rtalloc_ign((struct route *)ro, 0UL) 38417205eccSRandall Stewart 38517205eccSRandall Stewart /* Future zero copy wakeup/send function */ 38617205eccSRandall Stewart #define SCTP_ZERO_COPY_EVENT(inp, so) 387ad21a364SRandall Stewart /* This is re-pulse ourselves for sendbuf */ 388ad21a364SRandall Stewart #define SCTP_ZERO_COPY_SENDQ_EVENT(inp, so) 38917205eccSRandall Stewart 39017205eccSRandall Stewart /* 39117205eccSRandall Stewart * IP output routines 39217205eccSRandall Stewart */ 393ad21a364SRandall Stewart #define SCTP_IP_OUTPUT(result, o_pak, ro, stcb, vrf_id) \ 39417205eccSRandall Stewart { \ 39517205eccSRandall Stewart int o_flgs = 0; \ 39617205eccSRandall Stewart if (stcb && stcb->sctp_ep && stcb->sctp_ep->sctp_socket) { \ 39717205eccSRandall Stewart o_flgs = IP_RAWOUTPUT | (stcb->sctp_ep->sctp_socket->so_options & SO_DONTROUTE); \ 39817205eccSRandall Stewart } else { \ 39917205eccSRandall Stewart o_flgs = IP_RAWOUTPUT; \ 40017205eccSRandall Stewart } \ 40117205eccSRandall Stewart result = ip_output(o_pak, NULL, ro, o_flgs, 0, NULL); \ 40217205eccSRandall Stewart } 40317205eccSRandall Stewart 404ad21a364SRandall Stewart #define SCTP_IP6_OUTPUT(result, o_pak, ro, ifp, stcb, vrf_id) \ 40517205eccSRandall Stewart { \ 40617205eccSRandall Stewart if (stcb && stcb->sctp_ep) \ 40717205eccSRandall Stewart result = ip6_output(o_pak, \ 40817205eccSRandall Stewart ((struct in6pcb *)(stcb->sctp_ep))->in6p_outputopts, \ 40917205eccSRandall Stewart (ro), 0, 0, ifp, NULL); \ 41017205eccSRandall Stewart else \ 41117205eccSRandall Stewart result = ip6_output(o_pak, NULL, (ro), 0, 0, ifp, NULL); \ 41217205eccSRandall Stewart } 413bff64a4dSRandall Stewart 414d06c82f1SRandall Stewart struct mbuf * 415d06c82f1SRandall Stewart sctp_get_mbuf_for_msg(unsigned int space_needed, 416d06c82f1SRandall Stewart int want_header, int how, int allonebuf, int type); 417d06c82f1SRandall Stewart 418d06c82f1SRandall Stewart 419bff64a4dSRandall Stewart /* 420f42a358aSRandall Stewart * SCTP AUTH 421f42a358aSRandall Stewart */ 422f42a358aSRandall Stewart #define HAVE_SHA2 423f42a358aSRandall Stewart 424f42a358aSRandall Stewart #define SCTP_READ_RANDOM(buf, len) read_random(buf, len) 425f42a358aSRandall Stewart 426f42a358aSRandall Stewart #ifdef USE_SCTP_SHA1 427f42a358aSRandall Stewart #include <netinet/sctp_sha1.h> 428f42a358aSRandall Stewart #else 429f42a358aSRandall Stewart #include <crypto/sha1.h> 430f42a358aSRandall Stewart /* map standard crypto API names */ 431f42a358aSRandall Stewart #define SHA1_Init SHA1Init 432f42a358aSRandall Stewart #define SHA1_Update SHA1Update 433f42a358aSRandall Stewart #define SHA1_Final(x,y) SHA1Final((caddr_t)x, y) 434f42a358aSRandall Stewart #endif 435f42a358aSRandall Stewart 436f42a358aSRandall Stewart #if defined(HAVE_SHA2) 437f42a358aSRandall Stewart #include <crypto/sha2/sha2.h> 438f42a358aSRandall Stewart #endif 439f42a358aSRandall Stewart 440f42a358aSRandall Stewart #include <sys/md5.h> 441f42a358aSRandall Stewart /* map standard crypto API names */ 442f42a358aSRandall Stewart #define MD5_Init MD5Init 443f42a358aSRandall Stewart #define MD5_Update MD5Update 444f42a358aSRandall Stewart #define MD5_Final MD5Final 445f42a358aSRandall Stewart 446f8829a4aSRandall Stewart #endif 447