Deleted Added
full compact
sctp_var.h (228653) sctp_var.h (228907)
1/*-
2 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2011, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2011, by Michael Tuexen. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * a) Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * b) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the distribution.
15 *
16 * c) Neither the name of Cisco Systems, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33/* $KAME: sctp_var.h,v 1.24 2005/03/06 16:04:19 itojun Exp $ */
34
35#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2011, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2011, by Michael Tuexen. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * a) Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * b) Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the distribution.
15 *
16 * c) Neither the name of Cisco Systems, Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33/* $KAME: sctp_var.h,v 1.24 2005/03/06 16:04:19 itojun Exp $ */
34
35#include <sys/cdefs.h>
36__FBSDID("$FreeBSD: head/sys/netinet/sctp_var.h 228653 2011-12-17 19:21:40Z tuexen $");
36__FBSDID("$FreeBSD: head/sys/netinet/sctp_var.h 228907 2011-12-27 10:16:24Z tuexen $");
37
38#ifndef _NETINET_SCTP_VAR_H_
39#define _NETINET_SCTP_VAR_H_
40
41#include <netinet/sctp_uio.h>
42
43#if defined(_KERNEL) || defined(__Userspace__)
44
45extern struct pr_usrreqs sctp_usrreqs;
46
47
48#define sctp_feature_on(inp, feature) (inp->sctp_features |= feature)
49#define sctp_feature_off(inp, feature) (inp->sctp_features &= ~feature)
50#define sctp_is_feature_on(inp, feature) ((inp->sctp_features & feature) == feature)
51#define sctp_is_feature_off(inp, feature) ((inp->sctp_features & feature) == 0)
52
53#define sctp_stcb_feature_on(inp, stcb, feature) {\
54 if (stcb) { \
55 stcb->asoc.sctp_features |= feature; \
37
38#ifndef _NETINET_SCTP_VAR_H_
39#define _NETINET_SCTP_VAR_H_
40
41#include <netinet/sctp_uio.h>
42
43#if defined(_KERNEL) || defined(__Userspace__)
44
45extern struct pr_usrreqs sctp_usrreqs;
46
47
48#define sctp_feature_on(inp, feature) (inp->sctp_features |= feature)
49#define sctp_feature_off(inp, feature) (inp->sctp_features &= ~feature)
50#define sctp_is_feature_on(inp, feature) ((inp->sctp_features & feature) == feature)
51#define sctp_is_feature_off(inp, feature) ((inp->sctp_features & feature) == 0)
52
53#define sctp_stcb_feature_on(inp, stcb, feature) {\
54 if (stcb) { \
55 stcb->asoc.sctp_features |= feature; \
56 } else { \
56 } else if (inp) { \
57 inp->sctp_features |= feature; \
58 } \
59}
60#define sctp_stcb_feature_off(inp, stcb, feature) {\
61 if (stcb) { \
62 stcb->asoc.sctp_features &= ~feature; \
57 inp->sctp_features |= feature; \
58 } \
59}
60#define sctp_stcb_feature_off(inp, stcb, feature) {\
61 if (stcb) { \
62 stcb->asoc.sctp_features &= ~feature; \
63 } else { \
63 } else if (inp) { \
64 inp->sctp_features &= ~feature; \
65 } \
66}
67#define sctp_stcb_is_feature_on(inp, stcb, feature) \
68 (((stcb != NULL) && \
69 ((stcb->asoc.sctp_features & feature) == feature)) || \
64 inp->sctp_features &= ~feature; \
65 } \
66}
67#define sctp_stcb_is_feature_on(inp, stcb, feature) \
68 (((stcb != NULL) && \
69 ((stcb->asoc.sctp_features & feature) == feature)) || \
70 ((stcb == NULL) && \
70 ((stcb == NULL) && (inp != NULL) && \
71 ((inp->sctp_features & feature) == feature)))
72#define sctp_stcb_is_feature_off(inp, stcb, feature) \
73 (((stcb != NULL) && \
74 ((stcb->asoc.sctp_features & feature) == 0)) || \
71 ((inp->sctp_features & feature) == feature)))
72#define sctp_stcb_is_feature_off(inp, stcb, feature) \
73 (((stcb != NULL) && \
74 ((stcb->asoc.sctp_features & feature) == 0)) || \
75 ((stcb == NULL) && \
76 ((inp->sctp_features & feature) == 0)))
75 ((stcb == NULL) && (inp != NULL) && \
76 ((inp->sctp_features & feature) == 0)) || \
77 ((stcb == NULL) && (inp == NULL)))
77
78/* managing mobility_feature in inpcb (by micchie) */
79#define sctp_mobility_feature_on(inp, feature) (inp->sctp_mobility_features |= feature)
80#define sctp_mobility_feature_off(inp, feature) (inp->sctp_mobility_features &= ~feature)
81#define sctp_is_mobility_feature_on(inp, feature) (inp->sctp_mobility_features & feature)
82#define sctp_is_mobility_feature_off(inp, feature) ((inp->sctp_mobility_features & feature) == 0)
83
84#define sctp_maxspace(sb) (max((sb)->sb_hiwat,SCTP_MINIMAL_RWND))
85
86#define sctp_sbspace(asoc, sb) ((long) ((sctp_maxspace(sb) > (asoc)->sb_cc) ? (sctp_maxspace(sb) - (asoc)->sb_cc) : 0))
87
88#define sctp_sbspace_failedmsgs(sb) ((long) ((sctp_maxspace(sb) > (sb)->sb_cc) ? (sctp_maxspace(sb) - (sb)->sb_cc) : 0))
89
90#define sctp_sbspace_sub(a,b) ((a > b) ? (a - b) : 0)
91
92/*
93 * I tried to cache the readq entries at one point. But the reality
94 * is that it did not add any performance since this meant we had to
95 * lock the STCB on read. And at that point once you have to do an
96 * extra lock, it really does not matter if the lock is in the ZONE
97 * stuff or in our code. Note that this same problem would occur with
98 * an mbuf cache as well so it is not really worth doing, at least
99 * right now :-D
100 */
101
102#define sctp_free_a_readq(_stcb, _readq) { \
103 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_readq), (_readq)); \
104 SCTP_DECR_READQ_COUNT(); \
105}
106
107#define sctp_alloc_a_readq(_stcb, _readq) { \
108 (_readq) = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_readq), struct sctp_queued_to_read); \
109 if ((_readq)) { \
110 SCTP_INCR_READQ_COUNT(); \
111 } \
112}
113
114#define sctp_free_a_strmoq(_stcb, _strmoq, _so_locked) { \
115 if ((_strmoq)->holds_key_ref) { \
116 sctp_auth_key_release(stcb, sp->auth_keyid, _so_locked); \
117 (_strmoq)->holds_key_ref = 0; \
118 } \
119 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_strmoq), (_strmoq)); \
120 SCTP_DECR_STRMOQ_COUNT(); \
121}
122
123#define sctp_alloc_a_strmoq(_stcb, _strmoq) { \
124 (_strmoq) = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_strmoq), struct sctp_stream_queue_pending); \
125 if ((_strmoq)) { \
126 memset(_strmoq, 0, sizeof(struct sctp_stream_queue_pending)); \
127 SCTP_INCR_STRMOQ_COUNT(); \
128 (_strmoq)->holds_key_ref = 0; \
129 } \
130}
131
132#define sctp_free_a_chunk(_stcb, _chk, _so_locked) { \
133 if ((_chk)->holds_key_ref) {\
134 sctp_auth_key_release((_stcb), (_chk)->auth_keyid, _so_locked); \
135 (_chk)->holds_key_ref = 0; \
136 } \
137 if (_stcb) { \
138 SCTP_TCB_LOCK_ASSERT((_stcb)); \
139 if ((_chk)->whoTo) { \
140 sctp_free_remote_addr((_chk)->whoTo); \
141 (_chk)->whoTo = NULL; \
142 } \
143 if (((_stcb)->asoc.free_chunk_cnt > SCTP_BASE_SYSCTL(sctp_asoc_free_resc_limit)) || \
144 (SCTP_BASE_INFO(ipi_free_chunks) > SCTP_BASE_SYSCTL(sctp_system_free_resc_limit))) { \
145 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_chunk), (_chk)); \
146 SCTP_DECR_CHK_COUNT(); \
147 } else { \
148 TAILQ_INSERT_TAIL(&(_stcb)->asoc.free_chunks, (_chk), sctp_next); \
149 (_stcb)->asoc.free_chunk_cnt++; \
150 atomic_add_int(&SCTP_BASE_INFO(ipi_free_chunks), 1); \
151 } \
152 } else { \
153 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_chunk), (_chk)); \
154 SCTP_DECR_CHK_COUNT(); \
155 } \
156}
157
158#define sctp_alloc_a_chunk(_stcb, _chk) { \
159 if (TAILQ_EMPTY(&(_stcb)->asoc.free_chunks)) { \
160 (_chk) = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_chunk), struct sctp_tmit_chunk); \
161 if ((_chk)) { \
162 SCTP_INCR_CHK_COUNT(); \
163 (_chk)->whoTo = NULL; \
164 (_chk)->holds_key_ref = 0; \
165 } \
166 } else { \
167 (_chk) = TAILQ_FIRST(&(_stcb)->asoc.free_chunks); \
168 TAILQ_REMOVE(&(_stcb)->asoc.free_chunks, (_chk), sctp_next); \
169 atomic_subtract_int(&SCTP_BASE_INFO(ipi_free_chunks), 1); \
170 (_chk)->holds_key_ref = 0; \
171 SCTP_STAT_INCR(sctps_cached_chk); \
172 (_stcb)->asoc.free_chunk_cnt--; \
173 } \
174}
175
176
177#define sctp_free_remote_addr(__net) { \
178 if ((__net)) { \
179 if (SCTP_DECREMENT_AND_CHECK_REFCOUNT(&(__net)->ref_count)) { \
180 (void)SCTP_OS_TIMER_STOP(&(__net)->rxt_timer.timer); \
181 (void)SCTP_OS_TIMER_STOP(&(__net)->pmtu_timer.timer); \
182 if ((__net)->ro.ro_rt) { \
183 RTFREE((__net)->ro.ro_rt); \
184 (__net)->ro.ro_rt = NULL; \
185 } \
186 if ((__net)->src_addr_selected) { \
187 sctp_free_ifa((__net)->ro._s_addr); \
188 (__net)->ro._s_addr = NULL; \
189 } \
190 (__net)->src_addr_selected = 0; \
191 (__net)->dest_state &= ~SCTP_ADDR_REACHABLE; \
192 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_net), (__net)); \
193 SCTP_DECR_RADDR_COUNT(); \
194 } \
195 } \
196}
197
198#define sctp_sbfree(ctl, stcb, sb, m) { \
199 SCTP_SAVE_ATOMIC_DECREMENT(&(sb)->sb_cc, SCTP_BUF_LEN((m))); \
200 SCTP_SAVE_ATOMIC_DECREMENT(&(sb)->sb_mbcnt, MSIZE); \
201 if (((ctl)->do_not_ref_stcb == 0) && stcb) {\
202 SCTP_SAVE_ATOMIC_DECREMENT(&(stcb)->asoc.sb_cc, SCTP_BUF_LEN((m))); \
203 SCTP_SAVE_ATOMIC_DECREMENT(&(stcb)->asoc.my_rwnd_control_len, MSIZE); \
204 } \
205 if (SCTP_BUF_TYPE(m) != MT_DATA && SCTP_BUF_TYPE(m) != MT_HEADER && \
206 SCTP_BUF_TYPE(m) != MT_OOBDATA) \
207 atomic_subtract_int(&(sb)->sb_ctl,SCTP_BUF_LEN((m))); \
208}
209
210#define sctp_sballoc(stcb, sb, m) { \
211 atomic_add_int(&(sb)->sb_cc,SCTP_BUF_LEN((m))); \
212 atomic_add_int(&(sb)->sb_mbcnt, MSIZE); \
213 if (stcb) { \
214 atomic_add_int(&(stcb)->asoc.sb_cc,SCTP_BUF_LEN((m))); \
215 atomic_add_int(&(stcb)->asoc.my_rwnd_control_len, MSIZE); \
216 } \
217 if (SCTP_BUF_TYPE(m) != MT_DATA && SCTP_BUF_TYPE(m) != MT_HEADER && \
218 SCTP_BUF_TYPE(m) != MT_OOBDATA) \
219 atomic_add_int(&(sb)->sb_ctl,SCTP_BUF_LEN((m))); \
220}
221
222
223#define sctp_ucount_incr(val) { \
224 val++; \
225}
226
227#define sctp_ucount_decr(val) { \
228 if (val > 0) { \
229 val--; \
230 } else { \
231 val = 0; \
232 } \
233}
234
235#define sctp_mbuf_crush(data) do { \
236 struct mbuf *_m; \
237 _m = (data); \
78
79/* managing mobility_feature in inpcb (by micchie) */
80#define sctp_mobility_feature_on(inp, feature) (inp->sctp_mobility_features |= feature)
81#define sctp_mobility_feature_off(inp, feature) (inp->sctp_mobility_features &= ~feature)
82#define sctp_is_mobility_feature_on(inp, feature) (inp->sctp_mobility_features & feature)
83#define sctp_is_mobility_feature_off(inp, feature) ((inp->sctp_mobility_features & feature) == 0)
84
85#define sctp_maxspace(sb) (max((sb)->sb_hiwat,SCTP_MINIMAL_RWND))
86
87#define sctp_sbspace(asoc, sb) ((long) ((sctp_maxspace(sb) > (asoc)->sb_cc) ? (sctp_maxspace(sb) - (asoc)->sb_cc) : 0))
88
89#define sctp_sbspace_failedmsgs(sb) ((long) ((sctp_maxspace(sb) > (sb)->sb_cc) ? (sctp_maxspace(sb) - (sb)->sb_cc) : 0))
90
91#define sctp_sbspace_sub(a,b) ((a > b) ? (a - b) : 0)
92
93/*
94 * I tried to cache the readq entries at one point. But the reality
95 * is that it did not add any performance since this meant we had to
96 * lock the STCB on read. And at that point once you have to do an
97 * extra lock, it really does not matter if the lock is in the ZONE
98 * stuff or in our code. Note that this same problem would occur with
99 * an mbuf cache as well so it is not really worth doing, at least
100 * right now :-D
101 */
102
103#define sctp_free_a_readq(_stcb, _readq) { \
104 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_readq), (_readq)); \
105 SCTP_DECR_READQ_COUNT(); \
106}
107
108#define sctp_alloc_a_readq(_stcb, _readq) { \
109 (_readq) = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_readq), struct sctp_queued_to_read); \
110 if ((_readq)) { \
111 SCTP_INCR_READQ_COUNT(); \
112 } \
113}
114
115#define sctp_free_a_strmoq(_stcb, _strmoq, _so_locked) { \
116 if ((_strmoq)->holds_key_ref) { \
117 sctp_auth_key_release(stcb, sp->auth_keyid, _so_locked); \
118 (_strmoq)->holds_key_ref = 0; \
119 } \
120 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_strmoq), (_strmoq)); \
121 SCTP_DECR_STRMOQ_COUNT(); \
122}
123
124#define sctp_alloc_a_strmoq(_stcb, _strmoq) { \
125 (_strmoq) = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_strmoq), struct sctp_stream_queue_pending); \
126 if ((_strmoq)) { \
127 memset(_strmoq, 0, sizeof(struct sctp_stream_queue_pending)); \
128 SCTP_INCR_STRMOQ_COUNT(); \
129 (_strmoq)->holds_key_ref = 0; \
130 } \
131}
132
133#define sctp_free_a_chunk(_stcb, _chk, _so_locked) { \
134 if ((_chk)->holds_key_ref) {\
135 sctp_auth_key_release((_stcb), (_chk)->auth_keyid, _so_locked); \
136 (_chk)->holds_key_ref = 0; \
137 } \
138 if (_stcb) { \
139 SCTP_TCB_LOCK_ASSERT((_stcb)); \
140 if ((_chk)->whoTo) { \
141 sctp_free_remote_addr((_chk)->whoTo); \
142 (_chk)->whoTo = NULL; \
143 } \
144 if (((_stcb)->asoc.free_chunk_cnt > SCTP_BASE_SYSCTL(sctp_asoc_free_resc_limit)) || \
145 (SCTP_BASE_INFO(ipi_free_chunks) > SCTP_BASE_SYSCTL(sctp_system_free_resc_limit))) { \
146 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_chunk), (_chk)); \
147 SCTP_DECR_CHK_COUNT(); \
148 } else { \
149 TAILQ_INSERT_TAIL(&(_stcb)->asoc.free_chunks, (_chk), sctp_next); \
150 (_stcb)->asoc.free_chunk_cnt++; \
151 atomic_add_int(&SCTP_BASE_INFO(ipi_free_chunks), 1); \
152 } \
153 } else { \
154 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_chunk), (_chk)); \
155 SCTP_DECR_CHK_COUNT(); \
156 } \
157}
158
159#define sctp_alloc_a_chunk(_stcb, _chk) { \
160 if (TAILQ_EMPTY(&(_stcb)->asoc.free_chunks)) { \
161 (_chk) = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_chunk), struct sctp_tmit_chunk); \
162 if ((_chk)) { \
163 SCTP_INCR_CHK_COUNT(); \
164 (_chk)->whoTo = NULL; \
165 (_chk)->holds_key_ref = 0; \
166 } \
167 } else { \
168 (_chk) = TAILQ_FIRST(&(_stcb)->asoc.free_chunks); \
169 TAILQ_REMOVE(&(_stcb)->asoc.free_chunks, (_chk), sctp_next); \
170 atomic_subtract_int(&SCTP_BASE_INFO(ipi_free_chunks), 1); \
171 (_chk)->holds_key_ref = 0; \
172 SCTP_STAT_INCR(sctps_cached_chk); \
173 (_stcb)->asoc.free_chunk_cnt--; \
174 } \
175}
176
177
178#define sctp_free_remote_addr(__net) { \
179 if ((__net)) { \
180 if (SCTP_DECREMENT_AND_CHECK_REFCOUNT(&(__net)->ref_count)) { \
181 (void)SCTP_OS_TIMER_STOP(&(__net)->rxt_timer.timer); \
182 (void)SCTP_OS_TIMER_STOP(&(__net)->pmtu_timer.timer); \
183 if ((__net)->ro.ro_rt) { \
184 RTFREE((__net)->ro.ro_rt); \
185 (__net)->ro.ro_rt = NULL; \
186 } \
187 if ((__net)->src_addr_selected) { \
188 sctp_free_ifa((__net)->ro._s_addr); \
189 (__net)->ro._s_addr = NULL; \
190 } \
191 (__net)->src_addr_selected = 0; \
192 (__net)->dest_state &= ~SCTP_ADDR_REACHABLE; \
193 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_net), (__net)); \
194 SCTP_DECR_RADDR_COUNT(); \
195 } \
196 } \
197}
198
199#define sctp_sbfree(ctl, stcb, sb, m) { \
200 SCTP_SAVE_ATOMIC_DECREMENT(&(sb)->sb_cc, SCTP_BUF_LEN((m))); \
201 SCTP_SAVE_ATOMIC_DECREMENT(&(sb)->sb_mbcnt, MSIZE); \
202 if (((ctl)->do_not_ref_stcb == 0) && stcb) {\
203 SCTP_SAVE_ATOMIC_DECREMENT(&(stcb)->asoc.sb_cc, SCTP_BUF_LEN((m))); \
204 SCTP_SAVE_ATOMIC_DECREMENT(&(stcb)->asoc.my_rwnd_control_len, MSIZE); \
205 } \
206 if (SCTP_BUF_TYPE(m) != MT_DATA && SCTP_BUF_TYPE(m) != MT_HEADER && \
207 SCTP_BUF_TYPE(m) != MT_OOBDATA) \
208 atomic_subtract_int(&(sb)->sb_ctl,SCTP_BUF_LEN((m))); \
209}
210
211#define sctp_sballoc(stcb, sb, m) { \
212 atomic_add_int(&(sb)->sb_cc,SCTP_BUF_LEN((m))); \
213 atomic_add_int(&(sb)->sb_mbcnt, MSIZE); \
214 if (stcb) { \
215 atomic_add_int(&(stcb)->asoc.sb_cc,SCTP_BUF_LEN((m))); \
216 atomic_add_int(&(stcb)->asoc.my_rwnd_control_len, MSIZE); \
217 } \
218 if (SCTP_BUF_TYPE(m) != MT_DATA && SCTP_BUF_TYPE(m) != MT_HEADER && \
219 SCTP_BUF_TYPE(m) != MT_OOBDATA) \
220 atomic_add_int(&(sb)->sb_ctl,SCTP_BUF_LEN((m))); \
221}
222
223
224#define sctp_ucount_incr(val) { \
225 val++; \
226}
227
228#define sctp_ucount_decr(val) { \
229 if (val > 0) { \
230 val--; \
231 } else { \
232 val = 0; \
233 } \
234}
235
236#define sctp_mbuf_crush(data) do { \
237 struct mbuf *_m; \
238 _m = (data); \
238 while(_m && (SCTP_BUF_LEN(_m) == 0)) { \
239 while (_m && (SCTP_BUF_LEN(_m) == 0)) { \
239 (data) = SCTP_BUF_NEXT(_m); \
240 SCTP_BUF_NEXT(_m) = NULL; \
241 sctp_m_free(_m); \
242 _m = (data); \
243 } \
244} while (0)
245
246#define sctp_flight_size_decrease(tp1) do { \
247 if (tp1->whoTo->flight_size >= tp1->book_size) \
248 tp1->whoTo->flight_size -= tp1->book_size; \
249 else \
250 tp1->whoTo->flight_size = 0; \
251} while (0)
252
253#define sctp_flight_size_increase(tp1) do { \
254 (tp1)->whoTo->flight_size += (tp1)->book_size; \
255} while (0)
256
257#ifdef SCTP_FS_SPEC_LOG
258#define sctp_total_flight_decrease(stcb, tp1) do { \
259 if (stcb->asoc.fs_index > SCTP_FS_SPEC_LOG_SIZE) \
260 stcb->asoc.fs_index = 0;\
261 stcb->asoc.fslog[stcb->asoc.fs_index].total_flight = stcb->asoc.total_flight; \
262 stcb->asoc.fslog[stcb->asoc.fs_index].tsn = tp1->rec.data.TSN_seq; \
263 stcb->asoc.fslog[stcb->asoc.fs_index].book = tp1->book_size; \
264 stcb->asoc.fslog[stcb->asoc.fs_index].sent = tp1->sent; \
265 stcb->asoc.fslog[stcb->asoc.fs_index].incr = 0; \
266 stcb->asoc.fslog[stcb->asoc.fs_index].decr = 1; \
267 stcb->asoc.fs_index++; \
268 tp1->window_probe = 0; \
269 if (stcb->asoc.total_flight >= tp1->book_size) { \
270 stcb->asoc.total_flight -= tp1->book_size; \
271 if (stcb->asoc.total_flight_count > 0) \
272 stcb->asoc.total_flight_count--; \
273 } else { \
274 stcb->asoc.total_flight = 0; \
275 stcb->asoc.total_flight_count = 0; \
276 } \
277} while (0)
278
279#define sctp_total_flight_increase(stcb, tp1) do { \
280 if (stcb->asoc.fs_index > SCTP_FS_SPEC_LOG_SIZE) \
281 stcb->asoc.fs_index = 0;\
282 stcb->asoc.fslog[stcb->asoc.fs_index].total_flight = stcb->asoc.total_flight; \
283 stcb->asoc.fslog[stcb->asoc.fs_index].tsn = tp1->rec.data.TSN_seq; \
284 stcb->asoc.fslog[stcb->asoc.fs_index].book = tp1->book_size; \
285 stcb->asoc.fslog[stcb->asoc.fs_index].sent = tp1->sent; \
286 stcb->asoc.fslog[stcb->asoc.fs_index].incr = 1; \
287 stcb->asoc.fslog[stcb->asoc.fs_index].decr = 0; \
288 stcb->asoc.fs_index++; \
289 (stcb)->asoc.total_flight_count++; \
290 (stcb)->asoc.total_flight += (tp1)->book_size; \
291} while (0)
292
293#else
294
295#define sctp_total_flight_decrease(stcb, tp1) do { \
296 tp1->window_probe = 0; \
297 if (stcb->asoc.total_flight >= tp1->book_size) { \
298 stcb->asoc.total_flight -= tp1->book_size; \
299 if (stcb->asoc.total_flight_count > 0) \
300 stcb->asoc.total_flight_count--; \
301 } else { \
302 stcb->asoc.total_flight = 0; \
303 stcb->asoc.total_flight_count = 0; \
304 } \
305} while (0)
306
307#define sctp_total_flight_increase(stcb, tp1) do { \
308 (stcb)->asoc.total_flight_count++; \
309 (stcb)->asoc.total_flight += (tp1)->book_size; \
310} while (0)
311
312#endif
313
314#define SCTP_PF_ENABLED(_net) (_net->pf_threshold < _net->failure_threshold)
315#define SCTP_NET_IS_PF(_net) (_net->pf_threshold < _net->error_count)
316
317struct sctp_nets;
318struct sctp_inpcb;
319struct sctp_tcb;
320struct sctphdr;
321
322
323void sctp_close(struct socket *so);
324int sctp_disconnect(struct socket *so);
325
326void sctp_ctlinput __P((int, struct sockaddr *, void *));
327int sctp_ctloutput __P((struct socket *, struct sockopt *));
328
329#ifdef INET
330void sctp_input_with_port __P((struct mbuf *, int, uint16_t));
331
332#endif
333#ifdef INET
334void sctp_input __P((struct mbuf *, int));
335
336#endif
337void sctp_pathmtu_adjustment __P((struct sctp_tcb *, uint16_t));
338void sctp_drain __P((void));
339void sctp_init __P((void));
340
341void sctp_finish(void);
342
343int sctp_flush(struct socket *, int);
344int sctp_shutdown __P((struct socket *));
345void sctp_notify
346__P((struct sctp_inpcb *, struct ip *ip, struct sctphdr *,
347 struct sockaddr *, struct sctp_tcb *,
348 struct sctp_nets *));
349
350 int sctp_bindx(struct socket *, int, struct sockaddr_storage *,
351 int, int, struct proc *);
352
353/* can't use sctp_assoc_t here */
354 int sctp_peeloff(struct socket *, struct socket *, int, caddr_t, int *);
355
356 int sctp_ingetaddr(struct socket *,
357 struct sockaddr **
358);
359
360 int sctp_peeraddr(struct socket *,
361 struct sockaddr **
362);
363
364 int sctp_listen(struct socket *, int, struct thread *);
365
366 int sctp_accept(struct socket *, struct sockaddr **);
367
368#endif /* _KERNEL */
369
370#endif /* !_NETINET_SCTP_VAR_H_ */
240 (data) = SCTP_BUF_NEXT(_m); \
241 SCTP_BUF_NEXT(_m) = NULL; \
242 sctp_m_free(_m); \
243 _m = (data); \
244 } \
245} while (0)
246
247#define sctp_flight_size_decrease(tp1) do { \
248 if (tp1->whoTo->flight_size >= tp1->book_size) \
249 tp1->whoTo->flight_size -= tp1->book_size; \
250 else \
251 tp1->whoTo->flight_size = 0; \
252} while (0)
253
254#define sctp_flight_size_increase(tp1) do { \
255 (tp1)->whoTo->flight_size += (tp1)->book_size; \
256} while (0)
257
258#ifdef SCTP_FS_SPEC_LOG
259#define sctp_total_flight_decrease(stcb, tp1) do { \
260 if (stcb->asoc.fs_index > SCTP_FS_SPEC_LOG_SIZE) \
261 stcb->asoc.fs_index = 0;\
262 stcb->asoc.fslog[stcb->asoc.fs_index].total_flight = stcb->asoc.total_flight; \
263 stcb->asoc.fslog[stcb->asoc.fs_index].tsn = tp1->rec.data.TSN_seq; \
264 stcb->asoc.fslog[stcb->asoc.fs_index].book = tp1->book_size; \
265 stcb->asoc.fslog[stcb->asoc.fs_index].sent = tp1->sent; \
266 stcb->asoc.fslog[stcb->asoc.fs_index].incr = 0; \
267 stcb->asoc.fslog[stcb->asoc.fs_index].decr = 1; \
268 stcb->asoc.fs_index++; \
269 tp1->window_probe = 0; \
270 if (stcb->asoc.total_flight >= tp1->book_size) { \
271 stcb->asoc.total_flight -= tp1->book_size; \
272 if (stcb->asoc.total_flight_count > 0) \
273 stcb->asoc.total_flight_count--; \
274 } else { \
275 stcb->asoc.total_flight = 0; \
276 stcb->asoc.total_flight_count = 0; \
277 } \
278} while (0)
279
280#define sctp_total_flight_increase(stcb, tp1) do { \
281 if (stcb->asoc.fs_index > SCTP_FS_SPEC_LOG_SIZE) \
282 stcb->asoc.fs_index = 0;\
283 stcb->asoc.fslog[stcb->asoc.fs_index].total_flight = stcb->asoc.total_flight; \
284 stcb->asoc.fslog[stcb->asoc.fs_index].tsn = tp1->rec.data.TSN_seq; \
285 stcb->asoc.fslog[stcb->asoc.fs_index].book = tp1->book_size; \
286 stcb->asoc.fslog[stcb->asoc.fs_index].sent = tp1->sent; \
287 stcb->asoc.fslog[stcb->asoc.fs_index].incr = 1; \
288 stcb->asoc.fslog[stcb->asoc.fs_index].decr = 0; \
289 stcb->asoc.fs_index++; \
290 (stcb)->asoc.total_flight_count++; \
291 (stcb)->asoc.total_flight += (tp1)->book_size; \
292} while (0)
293
294#else
295
296#define sctp_total_flight_decrease(stcb, tp1) do { \
297 tp1->window_probe = 0; \
298 if (stcb->asoc.total_flight >= tp1->book_size) { \
299 stcb->asoc.total_flight -= tp1->book_size; \
300 if (stcb->asoc.total_flight_count > 0) \
301 stcb->asoc.total_flight_count--; \
302 } else { \
303 stcb->asoc.total_flight = 0; \
304 stcb->asoc.total_flight_count = 0; \
305 } \
306} while (0)
307
308#define sctp_total_flight_increase(stcb, tp1) do { \
309 (stcb)->asoc.total_flight_count++; \
310 (stcb)->asoc.total_flight += (tp1)->book_size; \
311} while (0)
312
313#endif
314
315#define SCTP_PF_ENABLED(_net) (_net->pf_threshold < _net->failure_threshold)
316#define SCTP_NET_IS_PF(_net) (_net->pf_threshold < _net->error_count)
317
318struct sctp_nets;
319struct sctp_inpcb;
320struct sctp_tcb;
321struct sctphdr;
322
323
324void sctp_close(struct socket *so);
325int sctp_disconnect(struct socket *so);
326
327void sctp_ctlinput __P((int, struct sockaddr *, void *));
328int sctp_ctloutput __P((struct socket *, struct sockopt *));
329
330#ifdef INET
331void sctp_input_with_port __P((struct mbuf *, int, uint16_t));
332
333#endif
334#ifdef INET
335void sctp_input __P((struct mbuf *, int));
336
337#endif
338void sctp_pathmtu_adjustment __P((struct sctp_tcb *, uint16_t));
339void sctp_drain __P((void));
340void sctp_init __P((void));
341
342void sctp_finish(void);
343
344int sctp_flush(struct socket *, int);
345int sctp_shutdown __P((struct socket *));
346void sctp_notify
347__P((struct sctp_inpcb *, struct ip *ip, struct sctphdr *,
348 struct sockaddr *, struct sctp_tcb *,
349 struct sctp_nets *));
350
351 int sctp_bindx(struct socket *, int, struct sockaddr_storage *,
352 int, int, struct proc *);
353
354/* can't use sctp_assoc_t here */
355 int sctp_peeloff(struct socket *, struct socket *, int, caddr_t, int *);
356
357 int sctp_ingetaddr(struct socket *,
358 struct sockaddr **
359);
360
361 int sctp_peeraddr(struct socket *,
362 struct sockaddr **
363);
364
365 int sctp_listen(struct socket *, int, struct thread *);
366
367 int sctp_accept(struct socket *, struct sockaddr **);
368
369#endif /* _KERNEL */
370
371#endif /* !_NETINET_SCTP_VAR_H_ */