2 * Copyright (c) 2001-2007, by 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.
31 /* $KAME: sctp_var.h,v 1.24 2005/03/06 16:04:19 itojun Exp $ */
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #ifndef _NETINET_SCTP_VAR_H_
37 #define _NETINET_SCTP_VAR_H_
39 #include <netinet/sctp_uio.h>
43 extern struct pr_usrreqs sctp_usrreqs;
46 #define sctp_feature_on(inp, feature) (inp->sctp_features |= feature)
47 #define sctp_feature_off(inp, feature) (inp->sctp_features &= ~feature)
48 #define sctp_is_feature_on(inp, feature) (inp->sctp_features & feature)
49 #define sctp_is_feature_off(inp, feature) ((inp->sctp_features & feature) == 0)
51 #define sctp_sbspace(asoc, sb) ((long) (((sb)->sb_hiwat > (asoc)->sb_cc) ? ((sb)->sb_hiwat - (asoc)->sb_cc) : 0))
53 #define sctp_sbspace_failedmsgs(sb) ((long) (((sb)->sb_hiwat > (sb)->sb_cc) ? ((sb)->sb_hiwat - (sb)->sb_cc) : 0))
55 #define sctp_sbspace_sub(a,b) ((a > b) ? (a - b) : 0)
58 * I tried to cache the readq entries at one point. But the reality
59 * is that it did not add any performance since this meant we had to
60 * lock the STCB on read. And at that point once you have to do an
61 * extra lock, it really does not matter if the lock is in the ZONE
62 * stuff or in our code. Note that this same problem would occur with
63 * an mbuf cache as well so it is not really worth doing, at least
67 #define sctp_free_a_readq(_stcb, _readq) { \
68 SCTP_ZONE_FREE(sctppcbinfo.ipi_zone_readq, (_readq)); \
69 SCTP_DECR_READQ_COUNT(); \
72 #define sctp_alloc_a_readq(_stcb, _readq) { \
73 (_readq) = SCTP_ZONE_GET(sctppcbinfo.ipi_zone_readq, struct sctp_queued_to_read); \
75 SCTP_INCR_READQ_COUNT(); \
79 #define sctp_free_a_strmoq(_stcb, _strmoq) { \
80 SCTP_ZONE_FREE(sctppcbinfo.ipi_zone_strmoq, (_strmoq)); \
81 SCTP_DECR_STRMOQ_COUNT(); \
84 #define sctp_alloc_a_strmoq(_stcb, _strmoq) { \
85 (_strmoq) = SCTP_ZONE_GET(sctppcbinfo.ipi_zone_strmoq, struct sctp_stream_queue_pending); \
87 SCTP_INCR_STRMOQ_COUNT(); \
92 #define sctp_free_a_chunk(_stcb, _chk) { \
93 SCTP_TCB_LOCK_ASSERT((_stcb)); \
94 if ((_chk)->whoTo) { \
95 sctp_free_remote_addr((_chk)->whoTo); \
96 (_chk)->whoTo = NULL; \
98 if (((_stcb)->asoc.free_chunk_cnt > sctp_asoc_free_resc_limit) || \
99 (sctppcbinfo.ipi_free_chunks > sctp_system_free_resc_limit)) { \
100 SCTP_ZONE_FREE(sctppcbinfo.ipi_zone_chunk, (_chk)); \
101 SCTP_DECR_CHK_COUNT(); \
103 TAILQ_INSERT_TAIL(&(_stcb)->asoc.free_chunks, (_chk), sctp_next); \
104 (_stcb)->asoc.free_chunk_cnt++; \
105 atomic_add_int(&sctppcbinfo.ipi_free_chunks, 1); \
109 #define sctp_alloc_a_chunk(_stcb, _chk) { \
110 if (TAILQ_EMPTY(&(_stcb)->asoc.free_chunks)) { \
111 (_chk) = SCTP_ZONE_GET(sctppcbinfo.ipi_zone_chunk, struct sctp_tmit_chunk); \
113 SCTP_INCR_CHK_COUNT(); \
114 (_chk)->whoTo = NULL; \
117 (_chk) = TAILQ_FIRST(&(_stcb)->asoc.free_chunks); \
118 TAILQ_REMOVE(&(_stcb)->asoc.free_chunks, (_chk), sctp_next); \
119 atomic_subtract_int(&sctppcbinfo.ipi_free_chunks, 1); \
120 SCTP_STAT_INCR(sctps_cached_chk); \
121 (_stcb)->asoc.free_chunk_cnt--; \
127 #define sctp_free_remote_addr(__net) { \
129 if (atomic_fetchadd_int(&(__net)->ref_count, -1) == 1) { \
130 (void)SCTP_OS_TIMER_STOP(&(__net)->rxt_timer.timer); \
131 (void)SCTP_OS_TIMER_STOP(&(__net)->pmtu_timer.timer); \
132 (void)SCTP_OS_TIMER_STOP(&(__net)->fr_timer.timer); \
133 if ((__net)->ro.ro_rt) { \
134 RTFREE((__net)->ro.ro_rt); \
135 (__net)->ro.ro_rt = NULL; \
137 if ((__net)->src_addr_selected) { \
138 sctp_free_ifa((__net)->ro._s_addr); \
139 (__net)->ro._s_addr = NULL; \
141 (__net)->src_addr_selected = 0; \
142 (__net)->dest_state = SCTP_ADDR_NOT_REACHABLE; \
143 SCTP_ZONE_FREE(sctppcbinfo.ipi_zone_net, (__net)); \
144 SCTP_DECR_RADDR_COUNT(); \
149 #define sctp_sbfree(ctl, stcb, sb, m) { \
151 val = atomic_fetchadd_int(&(sb)->sb_cc,-(SCTP_BUF_LEN((m)))); \
152 if (val < SCTP_BUF_LEN((m))) { \
153 panic("sb_cc goes negative"); \
155 val = atomic_fetchadd_int(&(sb)->sb_mbcnt,-(MSIZE)); \
157 panic("sb_mbcnt goes negative"); \
159 if (SCTP_BUF_IS_EXTENDED(m)) { \
160 val = atomic_fetchadd_int(&(sb)->sb_mbcnt,-(SCTP_BUF_EXTEND_SIZE(m))); \
161 if (val < SCTP_BUF_EXTEND_SIZE(m)) { \
162 panic("sb_mbcnt goes negative2"); \
165 if (((ctl)->do_not_ref_stcb == 0) && stcb) {\
166 val = atomic_fetchadd_int(&(stcb)->asoc.sb_cc,-(SCTP_BUF_LEN((m)))); \
167 if (val < SCTP_BUF_LEN((m))) {\
168 panic("stcb->sb_cc goes negative"); \
170 val = atomic_fetchadd_int(&(stcb)->asoc.sb_mbcnt,-(MSIZE)); \
172 panic("asoc->mbcnt goes negative"); \
174 if (SCTP_BUF_IS_EXTENDED(m)) { \
175 val = atomic_fetchadd_int(&(stcb)->asoc.sb_mbcnt,-(SCTP_BUF_EXTEND_SIZE(m))); \
176 if (val < SCTP_BUF_EXTEND_SIZE(m)) { \
177 panic("assoc stcb->mbcnt would go negative"); \
181 if (SCTP_BUF_TYPE(m) != MT_DATA && SCTP_BUF_TYPE(m) != MT_HEADER && \
182 SCTP_BUF_TYPE(m) != MT_OOBDATA) \
183 atomic_subtract_int(&(sb)->sb_ctl,SCTP_BUF_LEN((m))); \
187 #define sctp_sballoc(stcb, sb, m) { \
188 atomic_add_int(&(sb)->sb_cc,SCTP_BUF_LEN((m))); \
189 atomic_add_int(&(sb)->sb_mbcnt, MSIZE); \
190 if (SCTP_BUF_IS_EXTENDED(m)) \
191 atomic_add_int(&(sb)->sb_mbcnt,SCTP_BUF_EXTEND_SIZE(m)); \
193 atomic_add_int(&(stcb)->asoc.sb_cc,SCTP_BUF_LEN((m))); \
194 atomic_add_int(&(stcb)->asoc.sb_mbcnt, MSIZE); \
195 if (SCTP_BUF_IS_EXTENDED(m)) \
196 atomic_add_int(&(stcb)->asoc.sb_mbcnt,SCTP_BUF_EXTEND_SIZE(m)); \
198 if (SCTP_BUF_TYPE(m) != MT_DATA && SCTP_BUF_TYPE(m) != MT_HEADER && \
199 SCTP_BUF_TYPE(m) != MT_OOBDATA) \
200 atomic_add_int(&(sb)->sb_ctl,SCTP_BUF_LEN((m))); \
204 #define sctp_ucount_incr(val) { \
208 #define sctp_ucount_decr(val) { \
216 #define sctp_mbuf_crush(data) do { \
219 while(_m && (SCTP_BUF_LEN(_m) == 0)) { \
220 (data) = SCTP_BUF_NEXT(_m); \
221 SCTP_BUF_NEXT(_m) = NULL; \
227 #define sctp_flight_size_decrease(tp1) do { \
228 if (tp1->whoTo->flight_size >= tp1->book_size) \
229 tp1->whoTo->flight_size -= tp1->book_size; \
231 tp1->whoTo->flight_size = 0; \
234 #define sctp_flight_size_increase(tp1) do { \
235 (tp1)->whoTo->flight_size += (tp1)->book_size; \
238 #ifdef SCTP_FS_SPEC_LOG
239 #define sctp_total_flight_decrease(stcb, tp1) do { \
240 if(stcb->asoc.fs_index > SCTP_FS_SPEC_LOG_SIZE) \
241 stcb->asoc.fs_index = 0;\
242 stcb->asoc.fslog[stcb->asoc.fs_index].total_flight = stcb->asoc.total_flight; \
243 stcb->asoc.fslog[stcb->asoc.fs_index].tsn = tp1->rec.data.TSN_seq; \
244 stcb->asoc.fslog[stcb->asoc.fs_index].book = tp1->book_size; \
245 stcb->asoc.fslog[stcb->asoc.fs_index].sent = tp1->sent; \
246 stcb->asoc.fslog[stcb->asoc.fs_index].incr = 0; \
247 stcb->asoc.fslog[stcb->asoc.fs_index].decr = 1; \
248 stcb->asoc.fs_index++; \
249 tp1->window_probe = 0; \
250 if (stcb->asoc.total_flight >= tp1->book_size) { \
251 stcb->asoc.total_flight -= tp1->book_size; \
252 if (stcb->asoc.total_flight_count > 0) \
253 stcb->asoc.total_flight_count--; \
255 stcb->asoc.total_flight = 0; \
256 stcb->asoc.total_flight_count = 0; \
260 #define sctp_total_flight_increase(stcb, tp1) do { \
261 if(stcb->asoc.fs_index > SCTP_FS_SPEC_LOG_SIZE) \
262 stcb->asoc.fs_index = 0;\
263 stcb->asoc.fslog[stcb->asoc.fs_index].total_flight = stcb->asoc.total_flight; \
264 stcb->asoc.fslog[stcb->asoc.fs_index].tsn = tp1->rec.data.TSN_seq; \
265 stcb->asoc.fslog[stcb->asoc.fs_index].book = tp1->book_size; \
266 stcb->asoc.fslog[stcb->asoc.fs_index].sent = tp1->sent; \
267 stcb->asoc.fslog[stcb->asoc.fs_index].incr = 1; \
268 stcb->asoc.fslog[stcb->asoc.fs_index].decr = 0; \
269 stcb->asoc.fs_index++; \
270 (stcb)->asoc.total_flight_count++; \
271 (stcb)->asoc.total_flight += (tp1)->book_size; \
276 #define sctp_total_flight_decrease(stcb, tp1) do { \
277 if (stcb->asoc.total_flight >= tp1->book_size) { \
278 stcb->asoc.total_flight -= tp1->book_size; \
279 if (stcb->asoc.total_flight_count > 0) \
280 stcb->asoc.total_flight_count--; \
282 stcb->asoc.total_flight = 0; \
283 stcb->asoc.total_flight_count = 0; \
287 #define sctp_total_flight_increase(stcb, tp1) do { \
288 (stcb)->asoc.total_flight_count++; \
289 (stcb)->asoc.total_flight += (tp1)->book_size; \
299 void sctp_ctlinput __P((int, struct sockaddr *, void *));
300 int sctp_ctloutput __P((struct socket *, struct sockopt *));
301 void sctp_input __P((struct mbuf *, int));
302 void sctp_drain __P((void));
303 void sctp_init __P((void));
306 void sctp_pcbinfo_cleanup(void);
308 int sctp_shutdown __P((struct socket *));
310 __P((struct sctp_inpcb *, int, struct sctphdr *,
311 struct sockaddr *, struct sctp_tcb *,
312 struct sctp_nets *));
314 int sctp_bindx(struct socket *, int, struct sockaddr_storage *,
315 int, int, struct proc *);
317 /* can't use sctp_assoc_t here */
318 int sctp_peeloff(struct socket *, struct socket *, int, caddr_t, int *);
320 int sctp_ingetaddr(struct socket *,
324 int sctp_peeraddr(struct socket *,
328 int sctp_listen(struct socket *, int, struct thread *);
330 int sctp_accept(struct socket *, struct sockaddr **);
334 #endif /* !_NETINET_SCTP_VAR_H_ */