1163953Srrs/*- 2169382Srrs * Copyright (c) 2006-2007, by Cisco Systems, Inc. All rights reserved. 3235828Stuexen * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved. 4235828Stuexen * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved. 5163953Srrs * 6163953Srrs * Redistribution and use in source and binary forms, with or without 7163953Srrs * modification, are permitted provided that the following conditions are met: 8163953Srrs * 9163953Srrs * a) Redistributions of source code must retain the above copyright notice, 10163953Srrs * this list of conditions and the following disclaimer. 11163953Srrs * 12163953Srrs * b) Redistributions in binary form must reproduce the above copyright 13163953Srrs * notice, this list of conditions and the following disclaimer in 14163953Srrs * the documentation and/or other materials provided with the distribution. 15163953Srrs * 16163953Srrs * c) Neither the name of Cisco Systems, Inc. nor the names of its 17163953Srrs * contributors may be used to endorse or promote products derived 18163953Srrs * from this software without specific prior written permission. 19163953Srrs * 20163953Srrs * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21163953Srrs * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 22163953Srrs * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23163953Srrs * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24163953Srrs * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25163953Srrs * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26163953Srrs * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27163953Srrs * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28163953Srrs * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29163953Srrs * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30163953Srrs * THE POSSIBILITY OF SUCH DAMAGE. 31163953Srrs */ 32235828Stuexen 33163954Srrs#include <sys/cdefs.h> 34163953Srrs__FBSDID("$FreeBSD: stable/10/sys/netinet/sctp_os_bsd.h 314327 2017-02-27 08:27:38Z avg $"); 35235828Stuexen 36235828Stuexen#ifndef _NETINET_SCTP_OS_BSD_H_ 37235828Stuexen#define _NETINET_SCTP_OS_BSD_H_ 38163953Srrs/* 39163953Srrs * includes 40163953Srrs */ 41166086Srrs#include "opt_ipsec.h" 42166086Srrs#include "opt_compat.h" 43166086Srrs#include "opt_inet6.h" 44166086Srrs#include "opt_inet.h" 45166086Srrs#include "opt_sctp.h" 46181803Sbz 47166086Srrs#include <sys/param.h> 48170744Srrs#include <sys/ktr.h> 49166086Srrs#include <sys/systm.h> 50166086Srrs#include <sys/malloc.h> 51166086Srrs#include <sys/kernel.h> 52166086Srrs#include <sys/sysctl.h> 53166086Srrs#include <sys/mbuf.h> 54166086Srrs#include <sys/protosw.h> 55166086Srrs#include <sys/socket.h> 56166086Srrs#include <sys/socketvar.h> 57171477Srrs#include <sys/jail.h> 58166086Srrs#include <sys/sysctl.h> 59166086Srrs#include <sys/resourcevar.h> 60166086Srrs#include <sys/uio.h> 61172218Srrs#include <sys/lock.h> 62172218Srrs#include <sys/rwlock.h> 63167598Srrs#include <sys/kthread.h> 64166086Srrs#include <sys/priv.h> 65163953Srrs#include <sys/random.h> 66166086Srrs#include <sys/limits.h> 67166086Srrs#include <sys/queue.h> 68166086Srrs#include <machine/cpu.h> 69163953Srrs 70166086Srrs#include <net/if.h> 71166086Srrs#include <net/if_types.h> 72166086Srrs#include <net/if_var.h> 73166086Srrs#include <net/route.h> 74197929Stuexen#include <net/vnet.h> 75166086Srrs 76166086Srrs#include <netinet/in.h> 77166086Srrs#include <netinet/in_systm.h> 78166086Srrs#include <netinet/ip.h> 79166086Srrs#include <netinet/in_pcb.h> 80166086Srrs#include <netinet/in_var.h> 81166086Srrs#include <netinet/ip_var.h> 82166086Srrs#include <netinet/ip_icmp.h> 83166086Srrs#include <netinet/icmp_var.h> 84166086Srrs 85171167Sgnn#ifdef IPSEC 86171133Sgnn#include <netipsec/ipsec.h> 87171133Sgnn#include <netipsec/key.h> 88166086Srrs#endif /* IPSEC */ 89166086Srrs 90166086Srrs#ifdef INET6 91166086Srrs#include <sys/domain.h> 92171167Sgnn#ifdef IPSEC 93171139Sgnn#include <netipsec/ipsec6.h> 94166086Srrs#endif 95166086Srrs#include <netinet/ip6.h> 96166086Srrs#include <netinet6/ip6_var.h> 97166086Srrs#include <netinet6/in6_pcb.h> 98166086Srrs#include <netinet6/ip6protosw.h> 99166086Srrs#include <netinet6/nd6.h> 100166086Srrs#include <netinet6/scope6_var.h> 101166086Srrs#endif /* INET6 */ 102166086Srrs 103166675Srrs 104166086Srrs#include <netinet/ip_options.h> 105166086Srrs 106255160Stuexen#include <crypto/sha1.h> 107314327Savg#include <crypto/sha2/sha256.h> 108255160Stuexen 109166086Srrs#ifndef in6pcb 110166086Srrs#define in6pcb inpcb 111166086Srrs#endif 112170091Srrs/* Declare all the malloc names for all the various mallocs */ 113170091SrrsMALLOC_DECLARE(SCTP_M_MAP); 114170091SrrsMALLOC_DECLARE(SCTP_M_STRMI); 115170091SrrsMALLOC_DECLARE(SCTP_M_STRMO); 116170091SrrsMALLOC_DECLARE(SCTP_M_ASC_ADDR); 117170091SrrsMALLOC_DECLARE(SCTP_M_ASC_IT); 118170091SrrsMALLOC_DECLARE(SCTP_M_AUTH_CL); 119170091SrrsMALLOC_DECLARE(SCTP_M_AUTH_KY); 120170091SrrsMALLOC_DECLARE(SCTP_M_AUTH_HL); 121170091SrrsMALLOC_DECLARE(SCTP_M_AUTH_IF); 122170091SrrsMALLOC_DECLARE(SCTP_M_STRESET); 123170091SrrsMALLOC_DECLARE(SCTP_M_CMSG); 124170091SrrsMALLOC_DECLARE(SCTP_M_COPYAL); 125170091SrrsMALLOC_DECLARE(SCTP_M_VRF); 126170091SrrsMALLOC_DECLARE(SCTP_M_IFA); 127170091SrrsMALLOC_DECLARE(SCTP_M_IFN); 128170091SrrsMALLOC_DECLARE(SCTP_M_TIMW); 129170091SrrsMALLOC_DECLARE(SCTP_M_MVRF); 130170091SrrsMALLOC_DECLARE(SCTP_M_ITER); 131170091SrrsMALLOC_DECLARE(SCTP_M_SOCKOPT); 132218211SrrsMALLOC_DECLARE(SCTP_M_MCORE); 133166086Srrs 134171943Srrs#if defined(SCTP_LOCAL_TRACE_BUF) 135171943Srrs 136171943Srrs#define SCTP_GET_CYCLECOUNT get_cyclecount() 137171943Srrs#define SCTP_CTR6 sctp_log_trace 138171943Srrs 139171943Srrs#else 140171943Srrs#define SCTP_CTR6 CTR6 141171943Srrs#endif 142171943Srrs 143163953Srrs/* 144180387Srrs * Macros to expand out globals defined by various modules 145180387Srrs * to either a real global or a virtualized instance of one, 146181803Sbz * depending on whether VIMAGE is defined. 147180387Srrs */ 148180387Srrs/* then define the macro(s) that hook into the vimage macros */ 149197326Stuexen#define MODULE_GLOBAL(__SYMBOL) V_##__SYMBOL 150188067Srrs 151197326Stuexen#define V_system_base_info VNET(system_base_info) 152197288Srrs#define SCTP_BASE_INFO(__m) V_system_base_info.sctppcbinfo.__m 153197288Srrs#define SCTP_BASE_STATS V_system_base_info.sctpstat 154271746Stuexen#define SCTP_BASE_STAT(__m) V_system_base_info.sctpstat.__m 155271746Stuexen#define SCTP_BASE_SYSCTL(__m) V_system_base_info.sctpsysctl.__m 156197288Srrs#define SCTP_BASE_VAR(__m) V_system_base_info.__m 157197288Srrs 158234995Stuexen#define SCTP_PRINTF(params...) printf(params) 159169352Srrs#if defined(SCTP_DEBUG) 160169352Srrs#define SCTPDBG(level, params...) \ 161169352Srrs{ \ 162270352Stuexen do { \ 163270352Stuexen if (SCTP_BASE_SYSCTL(sctp_debug_on) & level ) { \ 164270352Stuexen SCTP_PRINTF(params); \ 165270352Stuexen } \ 166270352Stuexen } while (0); \ 167169352Srrs} 168169352Srrs#define SCTPDBG_ADDR(level, addr) \ 169169352Srrs{ \ 170270352Stuexen do { \ 171271746Stuexen if (SCTP_BASE_SYSCTL(sctp_debug_on) & level ) { \ 172271746Stuexen sctp_print_address(addr); \ 173271746Stuexen } \ 174270352Stuexen } while (0); \ 175169352Srrs} 176169352Srrs#else 177169352Srrs#define SCTPDBG(level, params...) 178169352Srrs#define SCTPDBG_ADDR(level, addr) 179169352Srrs#endif 180169352Srrs 181170744Srrs#ifdef SCTP_LTRACE_CHUNKS 182189371Srrs#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) 183170744Srrs#else 184170744Srrs#define SCTP_LTRACE_CHK(a, b, c, d) 185170744Srrs#endif 186170744Srrs 187170744Srrs#ifdef SCTP_LTRACE_ERRORS 188234995Stuexen#define SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, net, file, err) \ 189234995Stuexen if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LTRACE_ERROR_ENABLE) \ 190270352Stuexen SCTP_PRINTF("mbuf:%p inp:%p stcb:%p net:%p file:%x line:%d error:%d\n", \ 191234995Stuexen m, inp, stcb, net, file, __LINE__, err); 192234995Stuexen#define SCTP_LTRACE_ERR_RET(inp, stcb, net, file, err) \ 193234995Stuexen if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LTRACE_ERROR_ENABLE) \ 194270352Stuexen SCTP_PRINTF("inp:%p stcb:%p net:%p file:%x line:%d error:%d\n", \ 195234995Stuexen inp, stcb, net, file, __LINE__, err); 196170744Srrs#else 197171943Srrs#define SCTP_LTRACE_ERR_RET_PKT(m, inp, stcb, net, file, err) 198171943Srrs#define SCTP_LTRACE_ERR_RET(inp, stcb, net, file, err) 199170744Srrs#endif 200170744Srrs 201171943Srrs 202163953Srrs/* 203167598Srrs * Local address and interface list handling 204167598Srrs */ 205169352Srrs#define SCTP_MAX_VRF_ID 0 206169352Srrs#define SCTP_SIZE_OF_VRF_HASH 3 207169352Srrs#define SCTP_IFNAMSIZ IFNAMSIZ 208169352Srrs#define SCTP_DEFAULT_VRFID 0 209169352Srrs#define SCTP_VRF_ADDR_HASH_SIZE 16 210169352Srrs#define SCTP_VRF_IFN_HASH_SIZE 3 211170205Srrs#define SCTP_INIT_VRF_TABLEID(vrf) 212167598Srrs 213167598Srrs#define SCTP_IFN_IS_IFT_LOOP(ifn) ((ifn)->ifn_type == IFT_LOOP) 214179157Srrs#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) 215167598Srrs 216167598Srrs/* 217167598Srrs * Access to IFN's to help with src-addr-selection 218167598Srrs */ 219167598Srrs/* This could return VOID if the index works but for BSD we provide both. */ 220167598Srrs#define SCTP_GET_IFN_VOID_FROM_ROUTE(ro) (void *)ro->ro_rt->rt_ifp 221169352Srrs#define SCTP_GET_IF_INDEX_FROM_ROUTE(ro) (ro)->ro_rt->rt_ifp->if_index 222169352Srrs#define SCTP_ROUTE_HAS_VALID_IFN(ro) ((ro)->ro_rt && (ro)->ro_rt->rt_ifp) 223167598Srrs 224167598Srrs/* 225163953Srrs * general memory allocation 226163953Srrs */ 227163953Srrs#define SCTP_MALLOC(var, type, size, name) \ 228270352Stuexen do { \ 229270352Stuexen var = (type)malloc(size, name, M_NOWAIT); \ 230270352Stuexen } while (0) 231163953Srrs 232184205Sdes#define SCTP_FREE(var, type) free(var, type) 233163953Srrs 234163953Srrs#define SCTP_MALLOC_SONAME(var, type, size) \ 235270352Stuexen do { \ 236270352Stuexen var = (type)malloc(size, M_SONAME, M_WAITOK | M_ZERO); \ 237270352Stuexen } while (0) 238163953Srrs 239184205Sdes#define SCTP_FREE_SONAME(var) free(var, M_SONAME) 240163953Srrs 241167598Srrs#define SCTP_PROCESS_STRUCT struct proc * 242167598Srrs 243163953Srrs/* 244163953Srrs * zone allocation functions 245163953Srrs */ 246163953Srrs#include <vm/uma.h> 247179157Srrs 248163953Srrs/* SCTP_ZONE_INIT: initialize the zone */ 249163953Srrstypedef struct uma_zone *sctp_zone_t; 250163953Srrs 251163953Srrs#define SCTP_ZONE_INIT(zone, name, size, number) { \ 252163953Srrs zone = uma_zcreate(name, size, NULL, NULL, NULL, NULL, UMA_ALIGN_PTR,\ 253199370Stuexen 0); \ 254163953Srrs uma_zone_set_max(zone, number); \ 255163953Srrs} 256163953Srrs 257179157Srrs#define SCTP_ZONE_DESTROY(zone) uma_zdestroy(zone) 258179157Srrs 259163953Srrs/* SCTP_ZONE_GET: allocate element from the zone */ 260166675Srrs#define SCTP_ZONE_GET(zone, type) \ 261166675Srrs (type *)uma_zalloc(zone, M_NOWAIT); 262163953Srrs 263163953Srrs/* SCTP_ZONE_FREE: free element from the zone */ 264163953Srrs#define SCTP_ZONE_FREE(zone, element) \ 265163953Srrs uma_zfree(zone, element); 266179157Srrs 267166023Srrs#define SCTP_HASH_INIT(size, hashmark) hashinit_flags(size, M_PCB, hashmark, HASH_NOWAIT) 268166023Srrs#define SCTP_HASH_FREE(table, hashmark) hashdestroy(table, M_PCB, hashmark) 269163953Srrs 270166023Srrs#define SCTP_M_COPYM m_copym 271166023Srrs 272163953Srrs/* 273165647Srrs * timers 274165647Srrs */ 275165647Srrs#include <sys/callout.h> 276165647Srrstypedef struct callout sctp_os_timer_t; 277165647Srrs 278179157Srrs 279165647Srrs#define SCTP_OS_TIMER_INIT(tmr) callout_init(tmr, 1) 280165647Srrs#define SCTP_OS_TIMER_START callout_reset 281165647Srrs#define SCTP_OS_TIMER_STOP callout_stop 282166023Srrs#define SCTP_OS_TIMER_STOP_DRAIN callout_drain 283165647Srrs#define SCTP_OS_TIMER_PENDING callout_pending 284165647Srrs#define SCTP_OS_TIMER_ACTIVE callout_active 285165647Srrs#define SCTP_OS_TIMER_DEACTIVATE callout_deactivate 286165647Srrs 287170091Srrs#define sctp_get_tick_count() (ticks) 288170091Srrs 289172090Srrs#define SCTP_UNUSED __attribute__((unused)) 290170606Srrs 291165647Srrs/* 292163953Srrs * Functions 293163953Srrs */ 294165647Srrs/* Mbuf manipulation and access macros */ 295165647Srrs#define SCTP_BUF_LEN(m) (m->m_len) 296165647Srrs#define SCTP_BUF_NEXT(m) (m->m_next) 297165647Srrs#define SCTP_BUF_NEXT_PKT(m) (m->m_nextpkt) 298165647Srrs#define SCTP_BUF_RESV_UF(m, size) m->m_data += size 299165647Srrs#define SCTP_BUF_AT(m, size) m->m_data + size 300165647Srrs#define SCTP_BUF_IS_EXTENDED(m) (m->m_flags & M_EXT) 301165647Srrs#define SCTP_BUF_EXTEND_SIZE(m) (m->m_ext.ext_size) 302165647Srrs#define SCTP_BUF_TYPE(m) (m->m_type) 303165647Srrs#define SCTP_BUF_RECVIF(m) (m->m_pkthdr.rcvif) 304165647Srrs#define SCTP_BUF_PREPEND M_PREPEND 305168124Srrs 306168124Srrs#define SCTP_ALIGN_TO_END(m, len) if(m->m_flags & M_PKTHDR) { \ 307168124Srrs MH_ALIGN(m, len); \ 308168124Srrs } else if ((m->m_flags & M_EXT) == 0) { \ 309168124Srrs M_ALIGN(m, len); \ 310168124Srrs } 311170138Srrs 312170138Srrs/* We make it so if you have up to 4 threads 313215034Sbrucec * writing based on the default size of 314170138Srrs * the packet log 65 k, that would be 315170138Srrs * 4 16k packets before we would hit 316170138Srrs * a problem. 317170138Srrs */ 318170138Srrs#define SCTP_PKTLOG_WRITERS_NEED_LOCK 3 319170138Srrs 320169352Srrs/*************************/ 321169352Srrs/* MTU */ 322169352Srrs/*************************/ 323170181Srrs#define SCTP_GATHER_MTU_FROM_IFN_INFO(ifn, ifn_index, af) ((struct ifnet *)ifn)->if_mtu 324271750Stuexen#define SCTP_GATHER_MTU_FROM_ROUTE(sctp_ifa, sa, rt) ((uint32_t)((rt != NULL) ? rt->rt_mtu : 0)) 325169352Srrs#define SCTP_GATHER_MTU_FROM_INTFC(sctp_ifn) ((sctp_ifn->ifn_p != NULL) ? ((struct ifnet *)(sctp_ifn->ifn_p))->if_mtu : 0) 326169352Srrs#define SCTP_SET_MTU_OF_ROUTE(sa, rt, mtu) do { \ 327169352Srrs if (rt != NULL) \ 328263478Sglebius rt->rt_mtu = mtu; \ 329169352Srrs } while(0) 330168124Srrs 331169352Srrs/* (de-)register interface event notifications */ 332170181Srrs#define SCTP_REGISTER_INTERFACE(ifhandle, af) 333170181Srrs#define SCTP_DEREGISTER_INTERFACE(ifhandle, af) 334169352Srrs 335171477Srrs 336165647Srrs/*************************/ 337165647Srrs/* These are for logging */ 338165647Srrs/*************************/ 339165647Srrs/* return the base ext data pointer */ 340165647Srrs#define SCTP_BUF_EXTEND_BASE(m) (m->m_ext.ext_buf) 341165647Srrs /* return the refcnt of the data pointer */ 342165647Srrs#define SCTP_BUF_EXTEND_REFCNT(m) (*m->m_ext.ref_cnt) 343165647Srrs/* return any buffer related flags, this is 344165647Srrs * used beyond logging for apple only. 345165647Srrs */ 346165647Srrs#define SCTP_BUF_GET_FLAGS(m) (m->m_flags) 347165647Srrs 348165647Srrs/* For BSD this just accesses the M_PKTHDR length 349165647Srrs * so it operates on an mbuf with hdr flag. Other 350215034Sbrucec * O/S's may have separate packet header and mbuf 351165647Srrs * chain pointers.. thus the macro. 352165647Srrs */ 353165647Srrs#define SCTP_HEADER_TO_CHAIN(m) (m) 354169352Srrs#define SCTP_DETACH_HEADER_FROM_CHAIN(m) 355237540Stuexen#define SCTP_HEADER_LEN(m) ((m)->m_pkthdr.len) 356169352Srrs#define SCTP_GET_HEADER_FOR_OUTPUT(o_pak) 0 357169352Srrs#define SCTP_RELEASE_HEADER(m) 358169352Srrs#define SCTP_RELEASE_PKT(m) sctp_m_freem(m) 359179783Srrs#define SCTP_ENABLE_UDP_CSUM(m) do { \ 360179783Srrs m->m_pkthdr.csum_flags = CSUM_UDP; \ 361179783Srrs m->m_pkthdr.csum_data = offsetof(struct udphdr, uh_sum); \ 362179783Srrs } while (0) 363165647Srrs 364170806Srrs#define SCTP_GET_PKT_VRFID(m, vrf_id) ((vrf_id = SCTP_DEFAULT_VRFID) != SCTP_DEFAULT_VRFID) 365169352Srrs 366170806Srrs 367170806Srrs 368165647Srrs/* Attach the chain of data into the sendable packet. */ 369165647Srrs#define SCTP_ATTACH_CHAIN(pak, m, packet_length) do { \ 370169352Srrs pak = m; \ 371165647Srrs pak->m_pkthdr.len = packet_length; \ 372165647Srrs } while(0) 373165647Srrs 374165647Srrs/* Other m_pkthdr type things */ 375170091Srrs#define SCTP_IS_IT_BROADCAST(dst, m) ((m->m_flags & M_PKTHDR) ? in_broadcast(dst, m->m_pkthdr.rcvif) : 0) 376170091Srrs#define SCTP_IS_IT_LOOPBACK(m) ((m->m_flags & M_PKTHDR) && ((m->m_pkthdr.rcvif == NULL) || (m->m_pkthdr.rcvif->if_type == IFT_LOOP))) 377165647Srrs 378165647Srrs 379165647Srrs/* This converts any input packet header 380165647Srrs * into the chain of data holders, for BSD 381165647Srrs * its a NOP. 382165647Srrs */ 383165647Srrs 384169352Srrs/* get the v6 hop limit */ 385169352Srrs#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))); 386169352Srrs 387166023Srrs/* is the endpoint v6only? */ 388166023Srrs#define SCTP_IPV6_V6ONLY(inp) (((struct inpcb *)inp)->inp_flags & IN6P_IPV6_V6ONLY) 389167598Srrs/* is the socket non-blocking? */ 390167598Srrs#define SCTP_SO_IS_NBIO(so) ((so)->so_state & SS_NBIO) 391167598Srrs#define SCTP_SET_SO_NBIO(so) ((so)->so_state |= SS_NBIO) 392167598Srrs#define SCTP_CLEAR_SO_NBIO(so) ((so)->so_state &= ~SS_NBIO) 393167598Srrs/* get the socket type */ 394167598Srrs#define SCTP_SO_TYPE(so) ((so)->so_type) 395167695Srrs/* reserve sb space for a socket */ 396167695Srrs#define SCTP_SORESERVE(so, send, recv) soreserve(so, send, recv) 397169352Srrs/* wakeup a socket */ 398169352Srrs#define SCTP_SOWAKEUP(so) wakeup(&(so)->so_timeo) 399167695Srrs/* clear the socket buffer state */ 400167695Srrs#define SCTP_SB_CLEAR(sb) \ 401167695Srrs (sb).sb_cc = 0; \ 402167695Srrs (sb).sb_mb = NULL; \ 403167695Srrs (sb).sb_mbcnt = 0; 404166023Srrs 405167736Srrs#define SCTP_SB_LIMIT_RCV(so) so->so_rcv.sb_hiwat 406167736Srrs#define SCTP_SB_LIMIT_SND(so) so->so_snd.sb_hiwat 407167736Srrs 408166675Srrs/* 409168299Srrs * routes, output, etc. 410168299Srrs */ 411168299Srrstypedef struct route sctp_route_t; 412169352Srrstypedef struct rtentry sctp_rtentry_t; 413168299Srrs 414284633Stuexen#define SCTP_RTALLOC(ro, vrf_id, fibnum) \ 415284633Stuexen rtalloc_ign_fib((struct route *)ro, 0UL, fibnum) 416168299Srrs 417169352Srrs/* Future zero copy wakeup/send function */ 418169352Srrs#define SCTP_ZERO_COPY_EVENT(inp, so) 419170181Srrs/* This is re-pulse ourselves for sendbuf */ 420170181Srrs#define SCTP_ZERO_COPY_SENDQ_EVENT(inp, so) 421169352Srrs 422169352Srrs/* 423254521Sandre * SCTP protocol specific mbuf flags. 424254521Sandre */ 425254527Sandre#define M_NOTIFICATION M_PROTO1 /* SCTP notification */ 426254521Sandre 427254521Sandre/* 428169352Srrs * IP output routines 429169352Srrs */ 430170181Srrs#define SCTP_IP_OUTPUT(result, o_pak, ro, stcb, vrf_id) \ 431169352Srrs{ \ 432211969Stuexen int o_flgs = IP_RAWOUTPUT; \ 433211969Stuexen struct sctp_tcb *local_stcb = stcb; \ 434211969Stuexen if (local_stcb && \ 435211969Stuexen local_stcb->sctp_ep && \ 436211969Stuexen local_stcb->sctp_ep->sctp_socket) \ 437211969Stuexen o_flgs |= local_stcb->sctp_ep->sctp_socket->so_options & SO_DONTROUTE; \ 438254523Sandre m_clrprotoflags(o_pak); \ 439169352Srrs result = ip_output(o_pak, NULL, ro, o_flgs, 0, NULL); \ 440169352Srrs} 441169352Srrs 442170181Srrs#define SCTP_IP6_OUTPUT(result, o_pak, ro, ifp, stcb, vrf_id) \ 443169352Srrs{ \ 444211969Stuexen struct sctp_tcb *local_stcb = stcb; \ 445254523Sandre m_clrprotoflags(o_pak); \ 446211969Stuexen if (local_stcb && local_stcb->sctp_ep) \ 447169352Srrs result = ip6_output(o_pak, \ 448211969Stuexen ((struct in6pcb *)(local_stcb->sctp_ep))->in6p_outputopts, \ 449169352Srrs (ro), 0, 0, ifp, NULL); \ 450169352Srrs else \ 451169352Srrs result = ip6_output(o_pak, NULL, (ro), 0, 0, ifp, NULL); \ 452169352Srrs} 453169352Srrs 454169208Srrsstruct mbuf * 455169208Srrssctp_get_mbuf_for_msg(unsigned int space_needed, 456169208Srrs int want_header, int how, int allonebuf, int type); 457169208Srrs 458169208Srrs 459168299Srrs/* 460166675Srrs * SCTP AUTH 461166675Srrs */ 462166675Srrs#define SCTP_READ_RANDOM(buf, len) read_random(buf, len) 463166675Srrs 464166675Srrs/* map standard crypto API names */ 465255160Stuexen#define SCTP_SHA1_CTX SHA1_CTX 466255160Stuexen#define SCTP_SHA1_INIT SHA1Init 467255160Stuexen#define SCTP_SHA1_UPDATE SHA1Update 468255160Stuexen#define SCTP_SHA1_FINAL(x,y) SHA1Final((caddr_t)x, y) 469166675Srrs 470255160Stuexen#define SCTP_SHA256_CTX SHA256_CTX 471255160Stuexen#define SCTP_SHA256_INIT SHA256_Init 472255160Stuexen#define SCTP_SHA256_UPDATE SHA256_Update 473255160Stuexen#define SCTP_SHA256_FINAL(x,y) SHA256_Final((caddr_t)x, y) 474166675Srrs 475166675Srrs#endif 476185694Srrs 477185694Srrs#define SCTP_DECREMENT_AND_CHECK_REFCOUNT(addr) (atomic_fetchadd_int(addr, -1) == 1) 478185694Srrs#if defined(INVARIANTS) 479185694Srrs#define SCTP_SAVE_ATOMIC_DECREMENT(addr, val) \ 480185694Srrs{ \ 481185694Srrs int32_t oldval; \ 482185694Srrs oldval = atomic_fetchadd_int(addr, -val); \ 483185694Srrs if (oldval < val) { \ 484185694Srrs panic("Counter goes negative"); \ 485185694Srrs } \ 486185694Srrs} 487185694Srrs#else 488185694Srrs#define SCTP_SAVE_ATOMIC_DECREMENT(addr, val) \ 489185694Srrs{ \ 490185694Srrs int32_t oldval; \ 491185694Srrs oldval = atomic_fetchadd_int(addr, -val); \ 492185694Srrs if (oldval < val) { \ 493185694Srrs *addr = 0; \ 494185694Srrs } \ 495185694Srrs} 496185694Srrs#endif 497