xref: /freebsd/sys/netinet/sctp_os_bsd.h (revision b1006367704bb48f19bf9ae63fef539028cff085)
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>
4393164cf9SRandall Stewart #include <sys/systm.h>
4493164cf9SRandall Stewart #include <sys/malloc.h>
4593164cf9SRandall Stewart #include <sys/kernel.h>
4693164cf9SRandall Stewart #include <sys/sysctl.h>
4793164cf9SRandall Stewart #include <sys/mbuf.h>
4893164cf9SRandall Stewart #include <sys/protosw.h>
4993164cf9SRandall Stewart #include <sys/socket.h>
5093164cf9SRandall Stewart #include <sys/socketvar.h>
5193164cf9SRandall Stewart #include <sys/sysctl.h>
5293164cf9SRandall Stewart #include <sys/resourcevar.h>
5393164cf9SRandall Stewart #include <sys/uio.h>
5442551e99SRandall Stewart #include <sys/kthread.h>
5593164cf9SRandall Stewart #include <sys/priv.h>
56f8829a4aSRandall Stewart #include <sys/random.h>
5793164cf9SRandall Stewart #include <sys/limits.h>
5893164cf9SRandall Stewart #include <sys/queue.h>
5993164cf9SRandall Stewart #include <machine/cpu.h>
6093164cf9SRandall Stewart 
6193164cf9SRandall Stewart #include <net/if.h>
6293164cf9SRandall Stewart #include <net/if_types.h>
6393164cf9SRandall Stewart #include <net/if_var.h>
6493164cf9SRandall Stewart #include <net/route.h>
6593164cf9SRandall Stewart 
6693164cf9SRandall Stewart #include <netinet/in.h>
6793164cf9SRandall Stewart #include <netinet/in_systm.h>
6893164cf9SRandall Stewart #include <netinet/ip.h>
6993164cf9SRandall Stewart #include <netinet/in_pcb.h>
7093164cf9SRandall Stewart #include <netinet/in_var.h>
7193164cf9SRandall Stewart #include <netinet/ip_var.h>
7293164cf9SRandall Stewart #include <netinet/ip_icmp.h>
7393164cf9SRandall Stewart #include <netinet/icmp_var.h>
7493164cf9SRandall Stewart 
7593164cf9SRandall Stewart 
7693164cf9SRandall Stewart #ifdef IPSEC
7793164cf9SRandall Stewart #include <netinet6/ipsec.h>
7893164cf9SRandall Stewart #include <netkey/key.h>
7993164cf9SRandall Stewart #endif				/* IPSEC */
8093164cf9SRandall Stewart 
8193164cf9SRandall Stewart #ifdef INET6
8293164cf9SRandall Stewart #include <sys/domain.h>
8393164cf9SRandall Stewart #ifdef IPSEC
8493164cf9SRandall Stewart #include <netinet6/ipsec6.h>
8593164cf9SRandall Stewart #endif
8693164cf9SRandall Stewart #include <netinet/ip6.h>
8793164cf9SRandall Stewart #include <netinet6/ip6_var.h>
8893164cf9SRandall Stewart #include <netinet6/in6_pcb.h>
8993164cf9SRandall Stewart #include <netinet/icmp6.h>
9093164cf9SRandall Stewart #include <netinet6/ip6protosw.h>
9193164cf9SRandall Stewart #include <netinet6/nd6.h>
9293164cf9SRandall Stewart #include <netinet6/scope6_var.h>
9393164cf9SRandall Stewart #endif				/* INET6 */
9493164cf9SRandall Stewart 
95f42a358aSRandall Stewart 
9693164cf9SRandall Stewart #include <netinet/ip_options.h>
9793164cf9SRandall Stewart 
9893164cf9SRandall Stewart #ifndef in6pcb
9993164cf9SRandall Stewart #define in6pcb		inpcb
10093164cf9SRandall Stewart #endif
10193164cf9SRandall Stewart 
10293164cf9SRandall Stewart 
103f8829a4aSRandall Stewart 
104f8829a4aSRandall Stewart /*
105f8829a4aSRandall Stewart  *
106f8829a4aSRandall Stewart  */
107a5d547adSRandall Stewart #define USER_ADDR_NULL	(NULL)	/* FIX ME: temp */
108f42a358aSRandall Stewart #define SCTP_LIST_EMPTY(list)	LIST_EMPTY(list)
109a5d547adSRandall Stewart 
11017205eccSRandall Stewart #if defined(SCTP_DEBUG)
11117205eccSRandall Stewart #define SCTPDBG(level, params...)					\
11217205eccSRandall Stewart {									\
11317205eccSRandall Stewart     do {								\
11417205eccSRandall Stewart 	if (sctp_debug_on & level ) {					\
11517205eccSRandall Stewart 	    printf(params);						\
11617205eccSRandall Stewart 	}								\
11717205eccSRandall Stewart     } while (0);							\
11817205eccSRandall Stewart }
11917205eccSRandall Stewart #define SCTPDBG_ADDR(level, addr)					\
12017205eccSRandall Stewart {									\
12117205eccSRandall Stewart     do {								\
12217205eccSRandall Stewart 	if (sctp_debug_on & level ) {					\
12317205eccSRandall Stewart 	    sctp_print_address(addr);					\
12417205eccSRandall Stewart 	}								\
12517205eccSRandall Stewart     } while (0);							\
12617205eccSRandall Stewart }
12717205eccSRandall Stewart #define SCTP_PRINTF(params...)	printf(params)
12817205eccSRandall Stewart #else
12917205eccSRandall Stewart #define SCTPDBG(level, params...)
13017205eccSRandall Stewart #define SCTPDBG_ADDR(level, addr)
13117205eccSRandall Stewart #define SCTP_PRINTF(params...)
13217205eccSRandall Stewart #endif
13317205eccSRandall Stewart 
134f8829a4aSRandall Stewart /*
13542551e99SRandall Stewart  * Local address and interface list handling
13642551e99SRandall Stewart  */
13742551e99SRandall Stewart #define SCTP_MAX_VRF_ID		0
13842551e99SRandall Stewart #define SCTP_SIZE_OF_VRF_HASH	3
13942551e99SRandall Stewart #define SCTP_IFNAMSIZ		IFNAMSIZ
14042551e99SRandall Stewart #define SCTP_DEFAULT_VRFID	0
14117205eccSRandall Stewart #define SCTP_DEFAULT_TABLEID	0
14217205eccSRandall Stewart #define SCTP_VRF_ADDR_HASH_SIZE	16
14317205eccSRandall Stewart #define SCTP_VRF_IFN_HASH_SIZE	3
14417205eccSRandall Stewart #define SCTP_VRF_DEFAULT_TABLEID(vrf_id)	0
14542551e99SRandall Stewart 
14642551e99SRandall Stewart #define SCTP_IFN_IS_IFT_LOOP(ifn) ((ifn)->ifn_type == IFT_LOOP)
14742551e99SRandall Stewart 
14842551e99SRandall Stewart /*
14942551e99SRandall Stewart  * Access to IFN's to help with src-addr-selection
15042551e99SRandall Stewart  */
15142551e99SRandall Stewart /* This could return VOID if the index works but for BSD we provide both. */
15242551e99SRandall Stewart #define SCTP_GET_IFN_VOID_FROM_ROUTE(ro) (void *)ro->ro_rt->rt_ifp
15317205eccSRandall Stewart #define SCTP_GET_IF_INDEX_FROM_ROUTE(ro) (ro)->ro_rt->rt_ifp->if_index
15417205eccSRandall Stewart #define SCTP_ROUTE_HAS_VALID_IFN(ro) ((ro)->ro_rt && (ro)->ro_rt->rt_ifp)
15542551e99SRandall Stewart 
15642551e99SRandall Stewart /*
157f8829a4aSRandall Stewart  * general memory allocation
158f8829a4aSRandall Stewart  */
159f8829a4aSRandall Stewart #define SCTP_MALLOC(var, type, size, name) \
160f8829a4aSRandall Stewart     do { \
161f8829a4aSRandall Stewart 	MALLOC(var, type, size, M_PCB, M_NOWAIT); \
162f8829a4aSRandall Stewart     } while (0)
163f8829a4aSRandall Stewart 
164f8829a4aSRandall Stewart #define SCTP_FREE(var)	FREE(var, M_PCB)
165f8829a4aSRandall Stewart 
166f8829a4aSRandall Stewart #define SCTP_MALLOC_SONAME(var, type, size) \
167f8829a4aSRandall Stewart     do { \
168f8829a4aSRandall Stewart 	MALLOC(var, type, size, M_SONAME, M_WAITOK | M_ZERO); \
169f8829a4aSRandall Stewart     } while (0)
170f8829a4aSRandall Stewart 
171f8829a4aSRandall Stewart #define SCTP_FREE_SONAME(var)	FREE(var, M_SONAME)
172f8829a4aSRandall Stewart 
17342551e99SRandall Stewart #define SCTP_PROCESS_STRUCT struct proc *
17442551e99SRandall Stewart 
175f8829a4aSRandall Stewart /*
176f8829a4aSRandall Stewart  * zone allocation functions
177f8829a4aSRandall Stewart  */
178f8829a4aSRandall Stewart #include <vm/uma.h>
179f8829a4aSRandall Stewart /* SCTP_ZONE_INIT: initialize the zone */
180f8829a4aSRandall Stewart typedef struct uma_zone *sctp_zone_t;
181f8829a4aSRandall Stewart 
182f8829a4aSRandall Stewart #define UMA_ZFLAG_FULL	0x0020
183f8829a4aSRandall Stewart #define SCTP_ZONE_INIT(zone, name, size, number) { \
184f8829a4aSRandall Stewart 	zone = uma_zcreate(name, size, NULL, NULL, NULL, NULL, UMA_ALIGN_PTR,\
185f8829a4aSRandall Stewart 		UMA_ZFLAG_FULL); \
186f8829a4aSRandall Stewart 	uma_zone_set_max(zone, number); \
187f8829a4aSRandall Stewart }
188f8829a4aSRandall Stewart 
189f8829a4aSRandall Stewart /* SCTP_ZONE_GET: allocate element from the zone */
190f42a358aSRandall Stewart #define SCTP_ZONE_GET(zone, type) \
191f42a358aSRandall Stewart 	(type *)uma_zalloc(zone, M_NOWAIT);
192f8829a4aSRandall Stewart 
193f8829a4aSRandall Stewart /* SCTP_ZONE_FREE: free element from the zone */
194f8829a4aSRandall Stewart #define SCTP_ZONE_FREE(zone, element) \
195f8829a4aSRandall Stewart 	uma_zfree(zone, element);
19644b7479bSRandall Stewart #define SCTP_HASH_INIT(size, hashmark) hashinit_flags(size, M_PCB, hashmark, HASH_NOWAIT)
19744b7479bSRandall Stewart #define SCTP_HASH_FREE(table, hashmark) hashdestroy(table, M_PCB, hashmark)
19844b7479bSRandall Stewart 
19944b7479bSRandall Stewart #define SCTP_M_COPYM	m_copym
200f8829a4aSRandall Stewart 
201f8829a4aSRandall Stewart /*
202139bc87fSRandall Stewart  * timers
203139bc87fSRandall Stewart  */
204139bc87fSRandall Stewart #include <sys/callout.h>
205139bc87fSRandall Stewart typedef struct callout sctp_os_timer_t;
206139bc87fSRandall Stewart 
207139bc87fSRandall Stewart #define SCTP_OS_TIMER_INIT(tmr)	callout_init(tmr, 1)
208139bc87fSRandall Stewart #define SCTP_OS_TIMER_START	callout_reset
209139bc87fSRandall Stewart #define SCTP_OS_TIMER_STOP	callout_stop
21044b7479bSRandall Stewart #define SCTP_OS_TIMER_STOP_DRAIN callout_drain
211139bc87fSRandall Stewart #define SCTP_OS_TIMER_PENDING	callout_pending
212139bc87fSRandall Stewart #define SCTP_OS_TIMER_ACTIVE	callout_active
213139bc87fSRandall Stewart #define SCTP_OS_TIMER_DEACTIVATE callout_deactivate
214139bc87fSRandall Stewart 
215139bc87fSRandall Stewart /*
216f8829a4aSRandall Stewart  * Functions
217f8829a4aSRandall Stewart  */
218139bc87fSRandall Stewart /* Mbuf manipulation and access macros  */
219139bc87fSRandall Stewart #define SCTP_BUF_LEN(m) (m->m_len)
220139bc87fSRandall Stewart #define SCTP_BUF_NEXT(m) (m->m_next)
221139bc87fSRandall Stewart #define SCTP_BUF_NEXT_PKT(m) (m->m_nextpkt)
222139bc87fSRandall Stewart #define SCTP_BUF_RESV_UF(m, size) m->m_data += size
223139bc87fSRandall Stewart #define SCTP_BUF_AT(m, size) m->m_data + size
224139bc87fSRandall Stewart #define SCTP_BUF_IS_EXTENDED(m) (m->m_flags & M_EXT)
225139bc87fSRandall Stewart #define SCTP_BUF_EXTEND_SIZE(m) (m->m_ext.ext_size)
226139bc87fSRandall Stewart #define SCTP_BUF_TYPE(m) (m->m_type)
227139bc87fSRandall Stewart #define SCTP_BUF_RECVIF(m) (m->m_pkthdr.rcvif)
228139bc87fSRandall Stewart #define SCTP_BUF_PREPEND	M_PREPEND
2295e54f665SRandall Stewart 
2305e54f665SRandall Stewart #define SCTP_ALIGN_TO_END(m, len) if(m->m_flags & M_PKTHDR) { \
2315e54f665SRandall Stewart                                      MH_ALIGN(m, len); \
2325e54f665SRandall Stewart                                   } else if ((m->m_flags & M_EXT) == 0) { \
2335e54f665SRandall Stewart                                      M_ALIGN(m, len); \
2345e54f665SRandall Stewart                                   }
23517205eccSRandall Stewart /*************************/
23617205eccSRandall Stewart /*      MTU              */
23717205eccSRandall Stewart /*************************/
23817205eccSRandall Stewart #define SCTP_GATHER_MTU_FROM_IFN_INFO(ifn, ifn_index) ((struct ifnet *)ifn)->if_mtu
23917205eccSRandall Stewart #define SCTP_GATHER_MTU_FROM_ROUTE(sctp_ifa, sa, rt) ((rt != NULL) ? rt->rt_rmx.rmx_mtu : 0)
24017205eccSRandall Stewart #define SCTP_GATHER_MTU_FROM_INTFC(sctp_ifn) ((sctp_ifn->ifn_p != NULL) ? ((struct ifnet *)(sctp_ifn->ifn_p))->if_mtu : 0)
24117205eccSRandall Stewart #define SCTP_SET_MTU_OF_ROUTE(sa, rt, mtu) do { \
24217205eccSRandall Stewart                                               if (rt != NULL) \
24317205eccSRandall Stewart                                                  rt->rt_rmx.rmx_mtu = mtu; \
24417205eccSRandall Stewart                                            } while(0)
24517205eccSRandall Stewart 
24617205eccSRandall Stewart /* (de-)register interface event notifications */
24717205eccSRandall Stewart #define SCTP_REGISTER_INTERFACE(ifhandle, ifname)
24817205eccSRandall Stewart #define SCTP_DEREGISTER_INTERFACE(ifhandle, ifname)
2495e54f665SRandall Stewart 
250139bc87fSRandall Stewart /*************************/
251139bc87fSRandall Stewart /* These are for logging */
252139bc87fSRandall Stewart /*************************/
253139bc87fSRandall Stewart /* return the base ext data pointer */
254139bc87fSRandall Stewart #define SCTP_BUF_EXTEND_BASE(m) (m->m_ext.ext_buf)
255139bc87fSRandall Stewart  /* return the refcnt of the data pointer */
256139bc87fSRandall Stewart #define SCTP_BUF_EXTEND_REFCNT(m) (*m->m_ext.ref_cnt)
257139bc87fSRandall Stewart /* return any buffer related flags, this is
258139bc87fSRandall Stewart  * used beyond logging for apple only.
259139bc87fSRandall Stewart  */
260139bc87fSRandall Stewart #define SCTP_BUF_GET_FLAGS(m) (m->m_flags)
261139bc87fSRandall Stewart 
262139bc87fSRandall Stewart /* For BSD this just accesses the M_PKTHDR length
263139bc87fSRandall Stewart  * so it operates on an mbuf with hdr flag. Other
264139bc87fSRandall Stewart  * O/S's may have seperate packet header and mbuf
265139bc87fSRandall Stewart  * chain pointers.. thus the macro.
266139bc87fSRandall Stewart  */
267139bc87fSRandall Stewart #define SCTP_HEADER_TO_CHAIN(m) (m)
26817205eccSRandall Stewart #define SCTP_DETACH_HEADER_FROM_CHAIN(m)
269139bc87fSRandall Stewart #define SCTP_HEADER_LEN(m) (m->m_pkthdr.len)
27017205eccSRandall Stewart #define SCTP_GET_HEADER_FOR_OUTPUT(o_pak) 0
27117205eccSRandall Stewart #define SCTP_RELEASE_HEADER(m)
27217205eccSRandall Stewart #define SCTP_RELEASE_PKT(m)	sctp_m_freem(m)
27317205eccSRandall Stewart 
27417205eccSRandall Stewart static inline int
27517205eccSRandall Stewart SCTP_GET_PKT_VRFID(void *m, uint32_t vrf_id)
27617205eccSRandall Stewart {
27717205eccSRandall Stewart 	vrf_id = SCTP_DEFAULT_VRFID;
27817205eccSRandall Stewart 	return (0);
27917205eccSRandall Stewart }
28017205eccSRandall Stewart static inline int
28117205eccSRandall Stewart SCTP_GET_PKT_TABLEID(void *m, uint32_t table_id)
28217205eccSRandall Stewart {
28317205eccSRandall Stewart 	table_id = SCTP_DEFAULT_TABLEID;
28417205eccSRandall Stewart 	return (0);
28517205eccSRandall Stewart }
286139bc87fSRandall Stewart 
287139bc87fSRandall Stewart /* Attach the chain of data into the sendable packet. */
288139bc87fSRandall Stewart #define SCTP_ATTACH_CHAIN(pak, m, packet_length) do { \
28917205eccSRandall Stewart                                                  pak = m; \
290139bc87fSRandall Stewart                                                  pak->m_pkthdr.len = packet_length; \
291139bc87fSRandall Stewart                          } while(0)
292139bc87fSRandall Stewart 
293139bc87fSRandall Stewart /* Other m_pkthdr type things */
294139bc87fSRandall Stewart #define SCTP_IS_IT_BROADCAST(dst, m) in_broadcast(dst, m->m_pkthdr.rcvif)
295139bc87fSRandall Stewart #define SCTP_IS_IT_LOOPBACK(m) ((m->m_pkthdr.rcvif == NULL) ||(m->m_pkthdr.rcvif->if_type == IFT_LOOP))
296139bc87fSRandall Stewart 
297139bc87fSRandall Stewart 
298139bc87fSRandall Stewart /* This converts any input packet header
299139bc87fSRandall Stewart  * into the chain of data holders, for BSD
300139bc87fSRandall Stewart  * its a NOP.
301139bc87fSRandall Stewart  */
302139bc87fSRandall Stewart 
303139bc87fSRandall Stewart /* Macro's for getting length from V6/V4 header */
304139bc87fSRandall Stewart #define SCTP_GET_IPV4_LENGTH(iph) (iph->ip_len)
305139bc87fSRandall Stewart #define SCTP_GET_IPV6_LENGTH(ip6) (ntohs(ip6->ip6_plen))
306f8829a4aSRandall Stewart 
30717205eccSRandall Stewart /* get the v6 hop limit */
30817205eccSRandall 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)));
30917205eccSRandall Stewart 
31044b7479bSRandall Stewart /* is the endpoint v6only? */
31144b7479bSRandall Stewart #define SCTP_IPV6_V6ONLY(inp)	(((struct inpcb *)inp)->inp_flags & IN6P_IPV6_V6ONLY)
31242551e99SRandall Stewart /* is the socket non-blocking? */
31342551e99SRandall Stewart #define SCTP_SO_IS_NBIO(so)	((so)->so_state & SS_NBIO)
31442551e99SRandall Stewart #define SCTP_SET_SO_NBIO(so)	((so)->so_state |= SS_NBIO)
31542551e99SRandall Stewart #define SCTP_CLEAR_SO_NBIO(so)	((so)->so_state &= ~SS_NBIO)
31642551e99SRandall Stewart /* get the socket type */
31742551e99SRandall Stewart #define SCTP_SO_TYPE(so)	((so)->so_type)
318132dea7dSRandall Stewart /* reserve sb space for a socket */
319132dea7dSRandall Stewart #define SCTP_SORESERVE(so, send, recv)	soreserve(so, send, recv)
32017205eccSRandall Stewart /* wakeup a socket */
32117205eccSRandall Stewart #define SCTP_SOWAKEUP(so)	wakeup(&(so)->so_timeo)
322132dea7dSRandall Stewart /* clear the socket buffer state */
323132dea7dSRandall Stewart #define SCTP_SB_CLEAR(sb)	\
324132dea7dSRandall Stewart 	(sb).sb_cc = 0;		\
325132dea7dSRandall Stewart 	(sb).sb_mb = NULL;	\
326132dea7dSRandall Stewart 	(sb).sb_mbcnt = 0;
32744b7479bSRandall Stewart 
32862c1ff9cSRandall Stewart #define SCTP_SB_LIMIT_RCV(so) so->so_rcv.sb_hiwat
32962c1ff9cSRandall Stewart #define SCTP_SB_LIMIT_SND(so) so->so_snd.sb_hiwat
33062c1ff9cSRandall Stewart 
331f42a358aSRandall Stewart /*
332bff64a4dSRandall Stewart  * routes, output, etc.
333bff64a4dSRandall Stewart  */
334bff64a4dSRandall Stewart typedef struct route sctp_route_t;
33517205eccSRandall Stewart typedef struct rtentry sctp_rtentry_t;
336bff64a4dSRandall Stewart 
33717205eccSRandall Stewart #define SCTP_RTALLOC(ro, vrf_id, table_id) rtalloc_ign((struct route *)ro, 0UL)
33817205eccSRandall Stewart 
33917205eccSRandall Stewart /* Future zero copy wakeup/send  function */
34017205eccSRandall Stewart #define SCTP_ZERO_COPY_EVENT(inp, so)
34117205eccSRandall Stewart 
34217205eccSRandall Stewart /*
34317205eccSRandall Stewart  * IP output routines
34417205eccSRandall Stewart  */
34517205eccSRandall Stewart #define SCTP_IP_OUTPUT(result, o_pak, ro, stcb, vrf_id, table_id) \
34617205eccSRandall Stewart { \
34717205eccSRandall Stewart 	int o_flgs = 0; \
34817205eccSRandall Stewart 	if (stcb && stcb->sctp_ep && stcb->sctp_ep->sctp_socket) { \
34917205eccSRandall Stewart 		o_flgs = IP_RAWOUTPUT | (stcb->sctp_ep->sctp_socket->so_options & SO_DONTROUTE); \
35017205eccSRandall Stewart 	} else { \
35117205eccSRandall Stewart 		o_flgs = IP_RAWOUTPUT; \
35217205eccSRandall Stewart 	} \
35317205eccSRandall Stewart 	result = ip_output(o_pak, NULL, ro, o_flgs, 0, NULL); \
35417205eccSRandall Stewart }
35517205eccSRandall Stewart 
35617205eccSRandall Stewart #define SCTP_IP6_OUTPUT(result, o_pak, ro, ifp, stcb, vrf_id, table_id) \
35717205eccSRandall Stewart { \
35817205eccSRandall Stewart  	if (stcb && stcb->sctp_ep) \
35917205eccSRandall Stewart 		result = ip6_output(o_pak, \
36017205eccSRandall Stewart 				    ((struct in6pcb *)(stcb->sctp_ep))->in6p_outputopts, \
36117205eccSRandall Stewart 				    (ro), 0, 0, ifp, NULL); \
36217205eccSRandall Stewart 	else \
36317205eccSRandall Stewart 		result = ip6_output(o_pak, NULL, (ro), 0, 0, ifp, NULL); \
36417205eccSRandall Stewart }
365bff64a4dSRandall Stewart 
366d06c82f1SRandall Stewart struct mbuf *
367d06c82f1SRandall Stewart sctp_get_mbuf_for_msg(unsigned int space_needed,
368d06c82f1SRandall Stewart     int want_header, int how, int allonebuf, int type);
369d06c82f1SRandall Stewart 
370d06c82f1SRandall Stewart 
371bff64a4dSRandall Stewart /*
372f42a358aSRandall Stewart  * SCTP AUTH
373f42a358aSRandall Stewart  */
374f42a358aSRandall Stewart #define HAVE_SHA2
375f42a358aSRandall Stewart 
376f42a358aSRandall Stewart #define SCTP_READ_RANDOM(buf, len)	read_random(buf, len)
377f42a358aSRandall Stewart 
378f42a358aSRandall Stewart #ifdef USE_SCTP_SHA1
379f42a358aSRandall Stewart #include <netinet/sctp_sha1.h>
380f42a358aSRandall Stewart #else
381f42a358aSRandall Stewart #include <crypto/sha1.h>
382f42a358aSRandall Stewart /* map standard crypto API names */
383f42a358aSRandall Stewart #define SHA1_Init	SHA1Init
384f42a358aSRandall Stewart #define SHA1_Update	SHA1Update
385f42a358aSRandall Stewart #define SHA1_Final(x,y)	SHA1Final((caddr_t)x, y)
386f42a358aSRandall Stewart #endif
387f42a358aSRandall Stewart 
388f42a358aSRandall Stewart #if defined(HAVE_SHA2)
389f42a358aSRandall Stewart #include <crypto/sha2/sha2.h>
390f42a358aSRandall Stewart #endif
391f42a358aSRandall Stewart 
392f42a358aSRandall Stewart #include <sys/md5.h>
393f42a358aSRandall Stewart /* map standard crypto API names */
394f42a358aSRandall Stewart #define MD5_Init	MD5Init
395f42a358aSRandall Stewart #define MD5_Update	MD5Update
396f42a358aSRandall Stewart #define MD5_Final	MD5Final
397f42a358aSRandall Stewart 
398f8829a4aSRandall Stewart #endif
399