2 * Copyright (c) 2006, Cisco Systems, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * a) Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
10 * b) Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the distribution.
14 * c) Neither the name of Cisco Systems, Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
32 #ifndef __sctp_os_bsd_h__
33 #define __sctp_os_bsd_h__
38 #include <sys/random.h>
43 typedef struct mbuf *sctp_mbuf_t;
45 #define USER_ADDR_NULL (NULL) /* FIX ME: temp */
48 * general memory allocation
50 #define SCTP_MALLOC(var, type, size, name) \
52 MALLOC(var, type, size, M_PCB, M_NOWAIT); \
55 #define SCTP_FREE(var) FREE(var, M_PCB)
57 #define SCTP_MALLOC_SONAME(var, type, size) \
59 MALLOC(var, type, size, M_SONAME, M_WAITOK | M_ZERO); \
62 #define SCTP_FREE_SONAME(var) FREE(var, M_SONAME)
65 * zone allocation functions
68 /* SCTP_ZONE_INIT: initialize the zone */
69 typedef struct uma_zone *sctp_zone_t;
71 #define UMA_ZFLAG_FULL 0x0020
72 #define SCTP_ZONE_INIT(zone, name, size, number) { \
73 zone = uma_zcreate(name, size, NULL, NULL, NULL, NULL, UMA_ALIGN_PTR,\
75 uma_zone_set_max(zone, number); \
78 /* SCTP_ZONE_GET: allocate element from the zone */
79 #define SCTP_ZONE_GET(zone) \
80 uma_zalloc(zone, M_NOWAIT);
82 /* SCTP_ZONE_FREE: free element from the zone */
83 #define SCTP_ZONE_FREE(zone, element) \
84 uma_zfree(zone, element);
85 #define SCTP_HASH_INIT(size, hashmark) hashinit_flags(size, M_PCB, hashmark, HASH_NOWAIT)
86 #define SCTP_HASH_FREE(table, hashmark) hashdestroy(table, M_PCB, hashmark)
88 #define SCTP_M_COPYM m_copym
93 #include <sys/callout.h>
94 typedef struct callout sctp_os_timer_t;
96 #define SCTP_OS_TIMER_INIT(tmr) callout_init(tmr, 1)
97 #define SCTP_OS_TIMER_START callout_reset
98 #define SCTP_OS_TIMER_STOP callout_stop
99 #define SCTP_OS_TIMER_STOP_DRAIN callout_drain
100 #define SCTP_OS_TIMER_PENDING callout_pending
101 #define SCTP_OS_TIMER_ACTIVE callout_active
102 #define SCTP_OS_TIMER_DEACTIVATE callout_deactivate
107 #define SCTP_READ_RANDOM(buf, len) read_random(buf, len)
109 /* Mbuf manipulation and access macros */
110 #define SCTP_BUF_LEN(m) (m->m_len)
111 #define SCTP_BUF_NEXT(m) (m->m_next)
112 #define SCTP_BUF_NEXT_PKT(m) (m->m_nextpkt)
113 #define SCTP_BUF_RESV_UF(m, size) m->m_data += size
114 #define SCTP_BUF_AT(m, size) m->m_data + size
115 #define SCTP_BUF_IS_EXTENDED(m) (m->m_flags & M_EXT)
116 #define SCTP_BUF_EXTEND_SIZE(m) (m->m_ext.ext_size)
117 #define SCTP_BUF_TYPE(m) (m->m_type)
118 #define SCTP_BUF_RECVIF(m) (m->m_pkthdr.rcvif)
119 #define SCTP_BUF_PREPEND M_PREPEND
120 /*************************/
121 /* These are for logging */
122 /*************************/
123 /* return the base ext data pointer */
124 #define SCTP_BUF_EXTEND_BASE(m) (m->m_ext.ext_buf)
125 /* return the refcnt of the data pointer */
126 #define SCTP_BUF_EXTEND_REFCNT(m) (*m->m_ext.ref_cnt)
127 /* return any buffer related flags, this is
128 * used beyond logging for apple only.
130 #define SCTP_BUF_GET_FLAGS(m) (m->m_flags)
132 /* For BSD this just accesses the M_PKTHDR length
133 * so it operates on an mbuf with hdr flag. Other
134 * O/S's may have seperate packet header and mbuf
135 * chain pointers.. thus the macro.
137 #define SCTP_HEADER_TO_CHAIN(m) (m)
138 #define SCTP_HEADER_LEN(m) (m->m_pkthdr.len)
139 #define SCTP_GET_HEADER_FOR_OUTPUT(len) sctp_get_mbuf_for_msg(len, 1, M_DONTWAIT, 1, MT_DATA)
141 /* Attach the chain of data into the sendable packet. */
142 #define SCTP_ATTACH_CHAIN(pak, m, packet_length) do { \
144 pak->m_pkthdr.len = packet_length; \
147 /* Other m_pkthdr type things */
148 #define SCTP_IS_IT_BROADCAST(dst, m) in_broadcast(dst, m->m_pkthdr.rcvif)
149 #define SCTP_IS_IT_LOOPBACK(m) ((m->m_pkthdr.rcvif == NULL) ||(m->m_pkthdr.rcvif->if_type == IFT_LOOP))
152 /* This converts any input packet header
153 * into the chain of data holders, for BSD
156 #define SCTP_PAK_TO_BUF(i_pak) (i_pak)
158 /* Macro's for getting length from V6/V4 header */
159 #define SCTP_GET_IPV4_LENGTH(iph) (iph->ip_len)
160 #define SCTP_GET_IPV6_LENGTH(ip6) (ntohs(ip6->ip6_plen))
162 /* is the endpoint v6only? */
163 #define SCTP_IPV6_V6ONLY(inp) (((struct inpcb *)inp)->inp_flags & IN6P_IPV6_V6ONLY)