sctp_os_bsd.h revision 218211
1163953Srrs/*- 2169382Srrs * Copyright (c) 2006-2007, by Cisco Systems, Inc. All rights reserved. 3163953Srrs * 4163953Srrs * Redistribution and use in source and binary forms, with or without 5163953Srrs * modification, are permitted provided that the following conditions are met: 6163953Srrs * 7163953Srrs * a) Redistributions of source code must retain the above copyright notice, 8163953Srrs * this list of conditions and the following disclaimer. 9163953Srrs * 10163953Srrs * b) Redistributions in binary form must reproduce the above copyright 11163953Srrs * notice, this list of conditions and the following disclaimer in 12163953Srrs * the documentation and/or other materials provided with the distribution. 13163953Srrs * 14163953Srrs * c) Neither the name of Cisco Systems, Inc. nor the names of its 15163953Srrs * contributors may be used to endorse or promote products derived 16163953Srrs * from this software without specific prior written permission. 17163953Srrs * 18163953Srrs * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19163953Srrs * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20163953Srrs * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21163953Srrs * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22163953Srrs * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23163953Srrs * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24163953Srrs * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25163953Srrs * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26163953Srrs * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27163953Srrs * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 28163953Srrs * THE POSSIBILITY OF SUCH DAMAGE. 29163953Srrs */ 30163954Srrs#include <sys/cdefs.h> 31163953Srrs__FBSDID("$FreeBSD: head/sys/netinet/sctp_os_bsd.h 218211 2011-02-03 10:05:30Z rrs $"); 32163953Srrs#ifndef __sctp_os_bsd_h__ 33163953Srrs#define __sctp_os_bsd_h__ 34163953Srrs/* 35163953Srrs * includes 36163953Srrs */ 37166086Srrs#include "opt_ipsec.h" 38166086Srrs#include "opt_compat.h" 39166086Srrs#include "opt_inet6.h" 40166086Srrs#include "opt_inet.h" 41166086Srrs#include "opt_sctp.h" 42181803Sbz 43166086Srrs#include <sys/param.h> 44170744Srrs#include <sys/ktr.h> 45166086Srrs#include <sys/systm.h> 46166086Srrs#include <sys/malloc.h> 47166086Srrs#include <sys/kernel.h> 48166086Srrs#include <sys/sysctl.h> 49166086Srrs#include <sys/mbuf.h> 50166086Srrs#include <sys/protosw.h> 51166086Srrs#include <sys/socket.h> 52166086Srrs#include <sys/socketvar.h> 53171477Srrs#include <sys/jail.h> 54166086Srrs#include <sys/sysctl.h> 55166086Srrs#include <sys/resourcevar.h> 56166086Srrs#include <sys/uio.h> 57172218Srrs#include <sys/lock.h> 58172218Srrs#include <sys/rwlock.h> 59167598Srrs#include <sys/kthread.h> 60166086Srrs#include <sys/priv.h> 61163953Srrs#include <sys/random.h> 62166086Srrs#include <sys/limits.h> 63166086Srrs#include <sys/queue.h> 64166086Srrs#include <machine/cpu.h> 65163953Srrs 66166086Srrs#include <net/if.h> 67166086Srrs#include <net/if_types.h> 68166086Srrs#include <net/if_var.h> 69166086Srrs#include <net/route.h> 70197929Stuexen#include <net/vnet.h> 71166086Srrs 72166086Srrs#include <netinet/in.h> 73166086Srrs#include <netinet/in_systm.h> 74166086Srrs#include <netinet/ip.h> 75166086Srrs#include <netinet/in_pcb.h> 76166086Srrs#include <netinet/in_var.h> 77166086Srrs#include <netinet/ip_var.h> 78166086Srrs#include <netinet/ip_icmp.h> 79166086Srrs#include <netinet/icmp_var.h> 80166086Srrs 81171167Sgnn#ifdef IPSEC 82171133Sgnn#include <netipsec/ipsec.h> 83171133Sgnn#include <netipsec/key.h> 84166086Srrs#endif /* IPSEC */ 85166086Srrs 86166086Srrs#ifdef INET6 87166086Srrs#include <sys/domain.h> 88171167Sgnn#ifdef IPSEC 89171139Sgnn#include <netipsec/ipsec6.h> 90166086Srrs#endif 91166086Srrs#include <netinet/ip6.h> 92166086Srrs#include <netinet6/ip6_var.h> 93166086Srrs#include <netinet6/in6_pcb.h> 94166086Srrs#include <netinet/icmp6.h> 95166086Srrs#include <netinet6/ip6protosw.h> 96166086Srrs#include <netinet6/nd6.h> 97166086Srrs#include <netinet6/scope6_var.h> 98166086Srrs#endif /* INET6 */ 99166086Srrs 100166675Srrs 101166086Srrs#include <netinet/ip_options.h> 102166086Srrs 103166086Srrs#ifndef in6pcb 104166086Srrs#define in6pcb inpcb 105166086Srrs#endif 106170091Srrs/* Declare all the malloc names for all the various mallocs */ 107170091SrrsMALLOC_DECLARE(SCTP_M_MAP); 108170091SrrsMALLOC_DECLARE(SCTP_M_STRMI); 109170091SrrsMALLOC_DECLARE(SCTP_M_STRMO); 110170091SrrsMALLOC_DECLARE(SCTP_M_ASC_ADDR); 111170091SrrsMALLOC_DECLARE(SCTP_M_ASC_IT); 112170091SrrsMALLOC_DECLARE(SCTP_M_AUTH_CL); 113170091SrrsMALLOC_DECLARE(SCTP_M_AUTH_KY); 114170091SrrsMALLOC_DECLARE(SCTP_M_AUTH_HL); 115170091SrrsMALLOC_DECLARE(SCTP_M_AUTH_IF); 116170091SrrsMALLOC_DECLARE(SCTP_M_STRESET); 117170091SrrsMALLOC_DECLARE(SCTP_M_CMSG); 118170091SrrsMALLOC_DECLARE(SCTP_M_COPYAL); 119170091SrrsMALLOC_DECLARE(SCTP_M_VRF); 120170091SrrsMALLOC_DECLARE(SCTP_M_IFA); 121170091SrrsMALLOC_DECLARE(SCTP_M_IFN); 122170091SrrsMALLOC_DECLARE(SCTP_M_TIMW); 123170091SrrsMALLOC_DECLARE(SCTP_M_MVRF); 124170091SrrsMALLOC_DECLARE(SCTP_M_ITER); 125170091SrrsMALLOC_DECLARE(SCTP_M_SOCKOPT); 126218211SrrsMALLOC_DECLARE(SCTP_M_MCORE); 127166086Srrs 128171943Srrs#if defined(SCTP_LOCAL_TRACE_BUF) 129171943Srrs 130171943Srrs#define SCTP_GET_CYCLECOUNT get_cyclecount() 131171943Srrs#define SCTP_CTR6 sctp_log_trace 132171943Srrs 133171943Srrs#else 134171943Srrs#define SCTP_CTR6 CTR6 135171943Srrs#endif 136171943Srrs 137163953Srrs/* 138180387Srrs * Macros to expand out globals defined by various modules 139180387Srrs * to either a real global or a virtualized instance of one, 140181803Sbz * depending on whether VIMAGE is defined. 141180387Srrs */ 142180387Srrs/* then define the macro(s) that hook into the vimage macros */ 143197326Stuexen#define MODULE_GLOBAL(__SYMBOL) V_##__SYMBOL 144188067Srrs 145197326Stuexen#define V_system_base_info VNET(system_base_info) 146197288Srrs#define SCTP_BASE_INFO(__m) V_system_base_info.sctppcbinfo.__m 147197288Srrs#define SCTP_BASE_STATS V_system_base_info.sctpstat 148197326Stuexen#define SCTP_BASE_STATS_SYSCTL VNET_NAME(system_base_info.sctpstat) 149197288Srrs#define SCTP_BASE_STAT(__m) V_system_base_info.sctpstat.__m 150197326Stuexen#define SCTP_BASE_SYSCTL(__m) VNET_NAME(system_base_info.sctpsysctl.__m) 151197288Srrs#define SCTP_BASE_VAR(__m) V_system_base_info.__m 152197288Srrs 153180387Srrs/* 154163953Srrs * 155163953Srrs */ 156165220Srrs#define USER_ADDR_NULL (NULL) /* FIX ME: temp */ 157165220Srrs 158169352Srrs#if defined(SCTP_DEBUG) 159169352Srrs#define SCTPDBG(level, params...) \ 160169352Srrs{ \ 161169352Srrs do { \ 162179783Srrs if (SCTP_BASE_SYSCTL(sctp_debug_on) & level ) { \ 163169352Srrs printf(params); \ 164169352Srrs } \ 165169352Srrs } while (0); \ 166169352Srrs} 167169352Srrs#define SCTPDBG_ADDR(level, addr) \ 168169352Srrs{ \ 169169352Srrs do { \ 170179783Srrs if (SCTP_BASE_SYSCTL(sctp_debug_on) & level ) { \ 171169352Srrs sctp_print_address(addr); \ 172169352Srrs } \ 173169352Srrs } while (0); \ 174169352Srrs} 175169420Srrs#define SCTPDBG_PKT(level, iph, sh) \ 176169420Srrs{ \ 177169420Srrs do { \ 178179783Srrs if (SCTP_BASE_SYSCTL(sctp_debug_on) & level) { \ 179169420Srrs sctp_print_address_pkt(iph, sh); \ 180169420Srrs } \ 181169420Srrs } while (0); \ 182169420Srrs} 183169352Srrs#else 184169352Srrs#define SCTPDBG(level, params...) 185169352Srrs#define SCTPDBG_ADDR(level, addr) 186169420Srrs#define SCTPDBG_PKT(level, iph, sh) 187169352Srrs#endif 188169420Srrs#define SCTP_PRINTF(params...) printf(params) 189169352Srrs 190170744Srrs#ifdef SCTP_LTRACE_CHUNKS 191189371Srrs#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) 192170744Srrs#else 193170744Srrs#define SCTP_LTRACE_CHK(a, b, c, d) 194170744Srrs#endif 195170744Srrs 196170744Srrs#ifdef SCTP_LTRACE_ERRORS 197179786Srrs#define SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, net, file, err) if(SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LTRACE_ERROR_ENABLE) \ 198171943Srrs printf("mbuf:%p inp:%p stcb:%p net:%p file:%x line:%d error:%d\n", \ 199171943Srrs m, inp, stcb, net, file, __LINE__, err); 200179786Srrs#define SCTP_LTRACE_ERR_RET(inp, stcb, net, file, err) if(SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LTRACE_ERROR_ENABLE) \ 201171943Srrs printf("inp:%p stcb:%p net:%p file:%x line:%d error:%d\n", \ 202171943Srrs inp, stcb, net, file, __LINE__, err); 203170744Srrs#else 204171943Srrs#define SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, net, file, err) 205171943Srrs#define SCTP_LTRACE_ERR_RET(inp, stcb, net, file, err) 206170744Srrs#endif 207170744Srrs 208171943Srrs 209163953Srrs/* 210167598Srrs * Local address and interface list handling 211167598Srrs */ 212169352Srrs#define SCTP_MAX_VRF_ID 0 213169352Srrs#define SCTP_SIZE_OF_VRF_HASH 3 214169352Srrs#define SCTP_IFNAMSIZ IFNAMSIZ 215169352Srrs#define SCTP_DEFAULT_VRFID 0 216169352Srrs#define SCTP_VRF_ADDR_HASH_SIZE 16 217169352Srrs#define SCTP_VRF_IFN_HASH_SIZE 3 218170205Srrs#define SCTP_INIT_VRF_TABLEID(vrf) 219167598Srrs 220167598Srrs#define SCTP_IFN_IS_IFT_LOOP(ifn) ((ifn)->ifn_type == IFT_LOOP) 221179157Srrs#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) 222167598Srrs 223167598Srrs/* 224167598Srrs * Access to IFN's to help with src-addr-selection 225167598Srrs */ 226167598Srrs/* This could return VOID if the index works but for BSD we provide both. */ 227167598Srrs#define SCTP_GET_IFN_VOID_FROM_ROUTE(ro) (void *)ro->ro_rt->rt_ifp 228169352Srrs#define SCTP_GET_IF_INDEX_FROM_ROUTE(ro) (ro)->ro_rt->rt_ifp->if_index 229169352Srrs#define SCTP_ROUTE_HAS_VALID_IFN(ro) ((ro)->ro_rt && (ro)->ro_rt->rt_ifp) 230167598Srrs 231167598Srrs/* 232163953Srrs * general memory allocation 233163953Srrs */ 234163953Srrs#define SCTP_MALLOC(var, type, size, name) \ 235163953Srrs do { \ 236184205Sdes var = (type)malloc(size, name, M_NOWAIT); \ 237163953Srrs } while (0) 238163953Srrs 239184205Sdes#define SCTP_FREE(var, type) free(var, type) 240163953Srrs 241163953Srrs#define SCTP_MALLOC_SONAME(var, type, size) \ 242163953Srrs do { \ 243184205Sdes var = (type)malloc(size, M_SONAME, M_WAITOK | M_ZERO); \ 244163953Srrs } while (0) 245163953Srrs 246184205Sdes#define SCTP_FREE_SONAME(var) free(var, M_SONAME) 247163953Srrs 248167598Srrs#define SCTP_PROCESS_STRUCT struct proc * 249167598Srrs 250163953Srrs/* 251163953Srrs * zone allocation functions 252163953Srrs */ 253163953Srrs#include <vm/uma.h> 254179157Srrs 255163953Srrs/* SCTP_ZONE_INIT: initialize the zone */ 256163953Srrstypedef struct uma_zone *sctp_zone_t; 257163953Srrs 258163953Srrs#define SCTP_ZONE_INIT(zone, name, size, number) { \ 259163953Srrs zone = uma_zcreate(name, size, NULL, NULL, NULL, NULL, UMA_ALIGN_PTR,\ 260199370Stuexen 0); \ 261163953Srrs uma_zone_set_max(zone, number); \ 262163953Srrs} 263163953Srrs 264179157Srrs#define SCTP_ZONE_DESTROY(zone) uma_zdestroy(zone) 265179157Srrs 266163953Srrs/* SCTP_ZONE_GET: allocate element from the zone */ 267166675Srrs#define SCTP_ZONE_GET(zone, type) \ 268166675Srrs (type *)uma_zalloc(zone, M_NOWAIT); 269163953Srrs 270163953Srrs/* SCTP_ZONE_FREE: free element from the zone */ 271163953Srrs#define SCTP_ZONE_FREE(zone, element) \ 272163953Srrs uma_zfree(zone, element); 273179157Srrs 274166023Srrs#define SCTP_HASH_INIT(size, hashmark) hashinit_flags(size, M_PCB, hashmark, HASH_NOWAIT) 275166023Srrs#define SCTP_HASH_FREE(table, hashmark) hashdestroy(table, M_PCB, hashmark) 276163953Srrs 277166023Srrs#define SCTP_M_COPYM m_copym 278166023Srrs 279163953Srrs/* 280165647Srrs * timers 281165647Srrs */ 282165647Srrs#include <sys/callout.h> 283165647Srrstypedef struct callout sctp_os_timer_t; 284165647Srrs 285179157Srrs 286165647Srrs#define SCTP_OS_TIMER_INIT(tmr) callout_init(tmr, 1) 287165647Srrs#define SCTP_OS_TIMER_START callout_reset 288165647Srrs#define SCTP_OS_TIMER_STOP callout_stop 289166023Srrs#define SCTP_OS_TIMER_STOP_DRAIN callout_drain 290165647Srrs#define SCTP_OS_TIMER_PENDING callout_pending 291165647Srrs#define SCTP_OS_TIMER_ACTIVE callout_active 292165647Srrs#define SCTP_OS_TIMER_DEACTIVATE callout_deactivate 293165647Srrs 294170091Srrs#define sctp_get_tick_count() (ticks) 295170091Srrs 296172090Srrs#define SCTP_UNUSED __attribute__((unused)) 297170606Srrs 298165647Srrs/* 299163953Srrs * Functions 300163953Srrs */ 301165647Srrs/* Mbuf manipulation and access macros */ 302165647Srrs#define SCTP_BUF_LEN(m) (m->m_len) 303165647Srrs#define SCTP_BUF_NEXT(m) (m->m_next) 304165647Srrs#define SCTP_BUF_NEXT_PKT(m) (m->m_nextpkt) 305165647Srrs#define SCTP_BUF_RESV_UF(m, size) m->m_data += size 306165647Srrs#define SCTP_BUF_AT(m, size) m->m_data + size 307165647Srrs#define SCTP_BUF_IS_EXTENDED(m) (m->m_flags & M_EXT) 308165647Srrs#define SCTP_BUF_EXTEND_SIZE(m) (m->m_ext.ext_size) 309165647Srrs#define SCTP_BUF_TYPE(m) (m->m_type) 310165647Srrs#define SCTP_BUF_RECVIF(m) (m->m_pkthdr.rcvif) 311165647Srrs#define SCTP_BUF_PREPEND M_PREPEND 312168124Srrs 313168124Srrs#define SCTP_ALIGN_TO_END(m, len) if(m->m_flags & M_PKTHDR) { \ 314168124Srrs MH_ALIGN(m, len); \ 315168124Srrs } else if ((m->m_flags & M_EXT) == 0) { \ 316168124Srrs M_ALIGN(m, len); \ 317168124Srrs } 318170138Srrs 319170138Srrs/* We make it so if you have up to 4 threads 320215034Sbrucec * writing based on the default size of 321170138Srrs * the packet log 65 k, that would be 322170138Srrs * 4 16k packets before we would hit 323170138Srrs * a problem. 324170138Srrs */ 325170138Srrs#define SCTP_PKTLOG_WRITERS_NEED_LOCK 3 326170138Srrs 327169352Srrs/*************************/ 328169352Srrs/* MTU */ 329169352Srrs/*************************/ 330170181Srrs#define SCTP_GATHER_MTU_FROM_IFN_INFO(ifn, ifn_index, af) ((struct ifnet *)ifn)->if_mtu 331169352Srrs#define SCTP_GATHER_MTU_FROM_ROUTE(sctp_ifa, sa, rt) ((rt != NULL) ? rt->rt_rmx.rmx_mtu : 0) 332169352Srrs#define SCTP_GATHER_MTU_FROM_INTFC(sctp_ifn) ((sctp_ifn->ifn_p != NULL) ? ((struct ifnet *)(sctp_ifn->ifn_p))->if_mtu : 0) 333169352Srrs#define SCTP_SET_MTU_OF_ROUTE(sa, rt, mtu) do { \ 334169352Srrs if (rt != NULL) \ 335169352Srrs rt->rt_rmx.rmx_mtu = mtu; \ 336169352Srrs } while(0) 337168124Srrs 338169352Srrs/* (de-)register interface event notifications */ 339170181Srrs#define SCTP_REGISTER_INTERFACE(ifhandle, af) 340170181Srrs#define SCTP_DEREGISTER_INTERFACE(ifhandle, af) 341169352Srrs 342171477Srrs 343165647Srrs/*************************/ 344165647Srrs/* These are for logging */ 345165647Srrs/*************************/ 346165647Srrs/* return the base ext data pointer */ 347165647Srrs#define SCTP_BUF_EXTEND_BASE(m) (m->m_ext.ext_buf) 348165647Srrs /* return the refcnt of the data pointer */ 349165647Srrs#define SCTP_BUF_EXTEND_REFCNT(m) (*m->m_ext.ref_cnt) 350165647Srrs/* return any buffer related flags, this is 351165647Srrs * used beyond logging for apple only. 352165647Srrs */ 353165647Srrs#define SCTP_BUF_GET_FLAGS(m) (m->m_flags) 354165647Srrs 355165647Srrs/* For BSD this just accesses the M_PKTHDR length 356165647Srrs * so it operates on an mbuf with hdr flag. Other 357215034Sbrucec * O/S's may have separate packet header and mbuf 358165647Srrs * chain pointers.. thus the macro. 359165647Srrs */ 360165647Srrs#define SCTP_HEADER_TO_CHAIN(m) (m) 361169352Srrs#define SCTP_DETACH_HEADER_FROM_CHAIN(m) 362165647Srrs#define SCTP_HEADER_LEN(m) (m->m_pkthdr.len) 363169352Srrs#define SCTP_GET_HEADER_FOR_OUTPUT(o_pak) 0 364169352Srrs#define SCTP_RELEASE_HEADER(m) 365169352Srrs#define SCTP_RELEASE_PKT(m) sctp_m_freem(m) 366179783Srrs#define SCTP_ENABLE_UDP_CSUM(m) do { \ 367179783Srrs m->m_pkthdr.csum_flags = CSUM_UDP; \ 368179783Srrs m->m_pkthdr.csum_data = offsetof(struct udphdr, uh_sum); \ 369179783Srrs } while (0) 370165647Srrs 371170806Srrs#define SCTP_GET_PKT_VRFID(m, vrf_id) ((vrf_id = SCTP_DEFAULT_VRFID) != SCTP_DEFAULT_VRFID) 372169352Srrs 373170806Srrs 374170806Srrs 375165647Srrs/* Attach the chain of data into the sendable packet. */ 376165647Srrs#define SCTP_ATTACH_CHAIN(pak, m, packet_length) do { \ 377169352Srrs pak = m; \ 378165647Srrs pak->m_pkthdr.len = packet_length; \ 379165647Srrs } while(0) 380165647Srrs 381165647Srrs/* Other m_pkthdr type things */ 382170091Srrs#define SCTP_IS_IT_BROADCAST(dst, m) ((m->m_flags & M_PKTHDR) ? in_broadcast(dst, m->m_pkthdr.rcvif) : 0) 383170091Srrs#define SCTP_IS_IT_LOOPBACK(m) ((m->m_flags & M_PKTHDR) && ((m->m_pkthdr.rcvif == NULL) || (m->m_pkthdr.rcvif->if_type == IFT_LOOP))) 384165647Srrs 385165647Srrs 386165647Srrs/* This converts any input packet header 387165647Srrs * into the chain of data holders, for BSD 388165647Srrs * its a NOP. 389165647Srrs */ 390165647Srrs 391165647Srrs/* Macro's for getting length from V6/V4 header */ 392165647Srrs#define SCTP_GET_IPV4_LENGTH(iph) (iph->ip_len) 393165647Srrs#define SCTP_GET_IPV6_LENGTH(ip6) (ntohs(ip6->ip6_plen)) 394165647Srrs 395169352Srrs/* get the v6 hop limit */ 396169352Srrs#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))); 397169352Srrs 398166023Srrs/* is the endpoint v6only? */ 399166023Srrs#define SCTP_IPV6_V6ONLY(inp) (((struct inpcb *)inp)->inp_flags & IN6P_IPV6_V6ONLY) 400167598Srrs/* is the socket non-blocking? */ 401167598Srrs#define SCTP_SO_IS_NBIO(so) ((so)->so_state & SS_NBIO) 402167598Srrs#define SCTP_SET_SO_NBIO(so) ((so)->so_state |= SS_NBIO) 403167598Srrs#define SCTP_CLEAR_SO_NBIO(so) ((so)->so_state &= ~SS_NBIO) 404167598Srrs/* get the socket type */ 405167598Srrs#define SCTP_SO_TYPE(so) ((so)->so_type) 406167695Srrs/* reserve sb space for a socket */ 407167695Srrs#define SCTP_SORESERVE(so, send, recv) soreserve(so, send, recv) 408169352Srrs/* wakeup a socket */ 409169352Srrs#define SCTP_SOWAKEUP(so) wakeup(&(so)->so_timeo) 410167695Srrs/* clear the socket buffer state */ 411167695Srrs#define SCTP_SB_CLEAR(sb) \ 412167695Srrs (sb).sb_cc = 0; \ 413167695Srrs (sb).sb_mb = NULL; \ 414167695Srrs (sb).sb_mbcnt = 0; 415166023Srrs 416167736Srrs#define SCTP_SB_LIMIT_RCV(so) so->so_rcv.sb_hiwat 417167736Srrs#define SCTP_SB_LIMIT_SND(so) so->so_snd.sb_hiwat 418167736Srrs 419166675Srrs/* 420168299Srrs * routes, output, etc. 421168299Srrs */ 422168299Srrstypedef struct route sctp_route_t; 423169352Srrstypedef struct rtentry sctp_rtentry_t; 424168299Srrs 425179783Srrs#define SCTP_RTALLOC(ro, vrf_id) rtalloc_ign((struct route *)ro, 0UL) 426168299Srrs 427169352Srrs/* Future zero copy wakeup/send function */ 428169352Srrs#define SCTP_ZERO_COPY_EVENT(inp, so) 429170181Srrs/* This is re-pulse ourselves for sendbuf */ 430170181Srrs#define SCTP_ZERO_COPY_SENDQ_EVENT(inp, so) 431169352Srrs 432169352Srrs/* 433169352Srrs * IP output routines 434169352Srrs */ 435170181Srrs#define SCTP_IP_OUTPUT(result, o_pak, ro, stcb, vrf_id) \ 436169352Srrs{ \ 437211969Stuexen int o_flgs = IP_RAWOUTPUT; \ 438211969Stuexen struct sctp_tcb *local_stcb = stcb; \ 439211969Stuexen if (local_stcb && \ 440211969Stuexen local_stcb->sctp_ep && \ 441211969Stuexen local_stcb->sctp_ep->sctp_socket) \ 442211969Stuexen o_flgs |= local_stcb->sctp_ep->sctp_socket->so_options & SO_DONTROUTE; \ 443169352Srrs result = ip_output(o_pak, NULL, ro, o_flgs, 0, NULL); \ 444169352Srrs} 445169352Srrs 446170181Srrs#define SCTP_IP6_OUTPUT(result, o_pak, ro, ifp, stcb, vrf_id) \ 447169352Srrs{ \ 448211969Stuexen struct sctp_tcb *local_stcb = stcb; \ 449211969Stuexen if (local_stcb && local_stcb->sctp_ep) \ 450169352Srrs result = ip6_output(o_pak, \ 451211969Stuexen ((struct in6pcb *)(local_stcb->sctp_ep))->in6p_outputopts, \ 452169352Srrs (ro), 0, 0, ifp, NULL); \ 453169352Srrs else \ 454169352Srrs result = ip6_output(o_pak, NULL, (ro), 0, 0, ifp, NULL); \ 455169352Srrs} 456169352Srrs 457169208Srrsstruct mbuf * 458169208Srrssctp_get_mbuf_for_msg(unsigned int space_needed, 459169208Srrs int want_header, int how, int allonebuf, int type); 460169208Srrs 461169208Srrs 462168299Srrs/* 463166675Srrs * SCTP AUTH 464166675Srrs */ 465166675Srrs#define HAVE_SHA2 466166675Srrs 467166675Srrs#define SCTP_READ_RANDOM(buf, len) read_random(buf, len) 468166675Srrs 469166675Srrs#ifdef USE_SCTP_SHA1 470166675Srrs#include <netinet/sctp_sha1.h> 471166675Srrs#else 472166675Srrs#include <crypto/sha1.h> 473166675Srrs/* map standard crypto API names */ 474166675Srrs#define SHA1_Init SHA1Init 475166675Srrs#define SHA1_Update SHA1Update 476166675Srrs#define SHA1_Final(x,y) SHA1Final((caddr_t)x, y) 477163953Srrs#endif 478166675Srrs 479166675Srrs#if defined(HAVE_SHA2) 480166675Srrs#include <crypto/sha2/sha2.h> 481166675Srrs#endif 482166675Srrs 483166675Srrs#endif 484185694Srrs 485185694Srrs#define SCTP_DECREMENT_AND_CHECK_REFCOUNT(addr) (atomic_fetchadd_int(addr, -1) == 1) 486185694Srrs#if defined(INVARIANTS) 487185694Srrs#define SCTP_SAVE_ATOMIC_DECREMENT(addr, val) \ 488185694Srrs{ \ 489185694Srrs int32_t oldval; \ 490185694Srrs oldval = atomic_fetchadd_int(addr, -val); \ 491185694Srrs if (oldval < val) { \ 492185694Srrs panic("Counter goes negative"); \ 493185694Srrs } \ 494185694Srrs} 495185694Srrs#else 496185694Srrs#define SCTP_SAVE_ATOMIC_DECREMENT(addr, val) \ 497185694Srrs{ \ 498185694Srrs int32_t oldval; \ 499185694Srrs oldval = atomic_fetchadd_int(addr, -val); \ 500185694Srrs if (oldval < val) { \ 501185694Srrs *addr = 0; \ 502185694Srrs } \ 503185694Srrs} 504185694Srrs#endif 505