]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/netinet/sctp_var.h
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / netinet / sctp_var.h
1 /*-
2  * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * a) Redistributions of source code must retain the above copyright notice,
8  *   this list of conditions and the following disclaimer.
9  *
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.
13  *
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.
17  *
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.
29  */
30
31 /* $KAME: sctp_var.h,v 1.24 2005/03/06 16:04:19 itojun Exp $     */
32
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
35
36 #ifndef _NETINET_SCTP_VAR_H_
37 #define _NETINET_SCTP_VAR_H_
38
39 #include <netinet/sctp_uio.h>
40
41 #if defined(_KERNEL) || defined(__Userspace__)
42
43 extern struct pr_usrreqs sctp_usrreqs;
44
45
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) == feature)
49 #define sctp_is_feature_off(inp, feature) ((inp->sctp_features & feature) == 0)
50
51
52 /* managing mobility_feature in inpcb (by micchie) */
53 #define sctp_mobility_feature_on(inp, feature)  (inp->sctp_mobility_features |= feature)
54 #define sctp_mobility_feature_off(inp, feature) (inp->sctp_mobility_features &= ~feature)
55 #define sctp_is_mobility_feature_on(inp, feature) (inp->sctp_mobility_features & feature)
56 #define sctp_is_mobility_feature_off(inp, feature) ((inp->sctp_mobility_features & feature) == 0)
57
58 #define sctp_maxspace(sb) (max((sb)->sb_hiwat,SCTP_MINIMAL_RWND))
59
60 #define sctp_sbspace(asoc, sb) ((long) ((sctp_maxspace(sb) > (asoc)->sb_cc) ? (sctp_maxspace(sb) - (asoc)->sb_cc) : 0))
61
62 #define sctp_sbspace_failedmsgs(sb) ((long) ((sctp_maxspace(sb) > (sb)->sb_cc) ? (sctp_maxspace(sb) - (sb)->sb_cc) : 0))
63
64 #define sctp_sbspace_sub(a,b) ((a > b) ? (a - b) : 0)
65
66 /*
67  * I tried to cache the readq entries at one point. But the reality
68  * is that it did not add any performance since this meant we had to
69  * lock the STCB on read. And at that point once you have to do an
70  * extra lock, it really does not matter if the lock is in the ZONE
71  * stuff or in our code. Note that this same problem would occur with
72  * an mbuf cache as well so it is not really worth doing, at least
73  * right now :-D
74  */
75
76 #define sctp_free_a_readq(_stcb, _readq) { \
77         SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_readq), (_readq)); \
78         SCTP_DECR_READQ_COUNT(); \
79 }
80
81 #define sctp_alloc_a_readq(_stcb, _readq) { \
82         (_readq) = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_readq), struct sctp_queued_to_read); \
83         if ((_readq)) { \
84              SCTP_INCR_READQ_COUNT(); \
85         } \
86 }
87
88 #define sctp_free_a_strmoq(_stcb, _strmoq) { \
89         if ((_strmoq)->holds_key_ref) { \
90                 sctp_auth_key_release(stcb, sp->auth_keyid); \
91                 (_strmoq)->holds_key_ref = 0; \
92         } \
93         SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_strmoq), (_strmoq)); \
94         SCTP_DECR_STRMOQ_COUNT(); \
95 }
96
97 #define sctp_alloc_a_strmoq(_stcb, _strmoq) { \
98         (_strmoq) = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_strmoq), struct sctp_stream_queue_pending); \
99         if ((_strmoq)) { \
100                 SCTP_INCR_STRMOQ_COUNT(); \
101                 (_strmoq)->holds_key_ref = 0; \
102         } \
103 }
104
105 #define sctp_free_a_chunk(_stcb, _chk) { \
106         if ((_chk)->holds_key_ref) {\
107                 sctp_auth_key_release((_stcb), (_chk)->auth_keyid); \
108                 (_chk)->holds_key_ref = 0; \
109         } \
110         if(_stcb) { \
111           SCTP_TCB_LOCK_ASSERT((_stcb)); \
112           if ((_chk)->whoTo) { \
113                   sctp_free_remote_addr((_chk)->whoTo); \
114                   (_chk)->whoTo = NULL; \
115           } \
116           if (((_stcb)->asoc.free_chunk_cnt > SCTP_BASE_SYSCTL(sctp_asoc_free_resc_limit)) || \
117                (SCTP_BASE_INFO(ipi_free_chunks) > SCTP_BASE_SYSCTL(sctp_system_free_resc_limit))) { \
118                 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_chunk), (_chk)); \
119                 SCTP_DECR_CHK_COUNT(); \
120           } else { \
121                 TAILQ_INSERT_TAIL(&(_stcb)->asoc.free_chunks, (_chk), sctp_next); \
122                 (_stcb)->asoc.free_chunk_cnt++; \
123                 atomic_add_int(&SCTP_BASE_INFO(ipi_free_chunks), 1); \
124           } \
125         } else { \
126                 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_chunk), (_chk)); \
127                 SCTP_DECR_CHK_COUNT(); \
128         } \
129 }
130
131 #define sctp_alloc_a_chunk(_stcb, _chk) { \
132         if (TAILQ_EMPTY(&(_stcb)->asoc.free_chunks))  { \
133                 (_chk) = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_chunk), struct sctp_tmit_chunk); \
134                 if ((_chk)) { \
135                         SCTP_INCR_CHK_COUNT(); \
136                         (_chk)->whoTo = NULL; \
137                         (_chk)->holds_key_ref = 0; \
138                 } \
139         } else { \
140                 (_chk) = TAILQ_FIRST(&(_stcb)->asoc.free_chunks); \
141                 TAILQ_REMOVE(&(_stcb)->asoc.free_chunks, (_chk), sctp_next); \
142                 atomic_subtract_int(&SCTP_BASE_INFO(ipi_free_chunks), 1); \
143                 (_chk)->holds_key_ref = 0; \
144                 SCTP_STAT_INCR(sctps_cached_chk); \
145                 (_stcb)->asoc.free_chunk_cnt--; \
146         } \
147 }
148
149
150 #define sctp_free_remote_addr(__net) { \
151         if ((__net)) {  \
152                 if (SCTP_DECREMENT_AND_CHECK_REFCOUNT(&(__net)->ref_count)) { \
153                         (void)SCTP_OS_TIMER_STOP(&(__net)->rxt_timer.timer); \
154                         (void)SCTP_OS_TIMER_STOP(&(__net)->pmtu_timer.timer); \
155                         (void)SCTP_OS_TIMER_STOP(&(__net)->fr_timer.timer); \
156                         if ((__net)->ro.ro_rt) { \
157                                 RTFREE((__net)->ro.ro_rt); \
158                                 (__net)->ro.ro_rt = NULL; \
159                         } \
160                         if ((__net)->src_addr_selected) { \
161                                 sctp_free_ifa((__net)->ro._s_addr); \
162                                 (__net)->ro._s_addr = NULL; \
163                         } \
164                         (__net)->src_addr_selected = 0; \
165                         (__net)->dest_state = SCTP_ADDR_NOT_REACHABLE; \
166                         SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_net), (__net)); \
167                         SCTP_DECR_RADDR_COUNT(); \
168                 } \
169         } \
170 }
171
172 #define sctp_sbfree(ctl, stcb, sb, m) { \
173         SCTP_SAVE_ATOMIC_DECREMENT(&(sb)->sb_cc, SCTP_BUF_LEN((m))); \
174         SCTP_SAVE_ATOMIC_DECREMENT(&(sb)->sb_mbcnt, MSIZE); \
175         if (((ctl)->do_not_ref_stcb == 0) && stcb) {\
176                 SCTP_SAVE_ATOMIC_DECREMENT(&(stcb)->asoc.sb_cc, SCTP_BUF_LEN((m))); \
177                 SCTP_SAVE_ATOMIC_DECREMENT(&(stcb)->asoc.my_rwnd_control_len, MSIZE); \
178         } \
179         if (SCTP_BUF_TYPE(m) != MT_DATA && SCTP_BUF_TYPE(m) != MT_HEADER && \
180             SCTP_BUF_TYPE(m) != MT_OOBDATA) \
181                 atomic_subtract_int(&(sb)->sb_ctl,SCTP_BUF_LEN((m))); \
182 }
183
184 #define sctp_sballoc(stcb, sb, m) { \
185         atomic_add_int(&(sb)->sb_cc,SCTP_BUF_LEN((m))); \
186         atomic_add_int(&(sb)->sb_mbcnt, MSIZE); \
187         if (stcb) { \
188                 atomic_add_int(&(stcb)->asoc.sb_cc,SCTP_BUF_LEN((m))); \
189                 atomic_add_int(&(stcb)->asoc.my_rwnd_control_len, MSIZE); \
190         } \
191         if (SCTP_BUF_TYPE(m) != MT_DATA && SCTP_BUF_TYPE(m) != MT_HEADER && \
192             SCTP_BUF_TYPE(m) != MT_OOBDATA) \
193                 atomic_add_int(&(sb)->sb_ctl,SCTP_BUF_LEN((m))); \
194 }
195
196
197 #define sctp_ucount_incr(val) { \
198         val++; \
199 }
200
201 #define sctp_ucount_decr(val) { \
202         if (val > 0) { \
203                 val--; \
204         } else { \
205                 val = 0; \
206         } \
207 }
208
209 #define sctp_mbuf_crush(data) do { \
210         struct mbuf *_m; \
211         _m = (data); \
212         while(_m && (SCTP_BUF_LEN(_m) == 0)) { \
213                 (data)  = SCTP_BUF_NEXT(_m); \
214                 SCTP_BUF_NEXT(_m) = NULL; \
215                 sctp_m_free(_m); \
216                 _m = (data); \
217         } \
218 } while (0)
219
220 #define sctp_flight_size_decrease(tp1) do { \
221         if (tp1->whoTo->flight_size >= tp1->book_size) \
222                 tp1->whoTo->flight_size -= tp1->book_size; \
223         else \
224                 tp1->whoTo->flight_size = 0; \
225 } while (0)
226
227 #define sctp_flight_size_increase(tp1) do { \
228        (tp1)->whoTo->flight_size += (tp1)->book_size; \
229 } while (0)
230
231 #ifdef SCTP_FS_SPEC_LOG
232 #define sctp_total_flight_decrease(stcb, tp1) do { \
233         if(stcb->asoc.fs_index > SCTP_FS_SPEC_LOG_SIZE) \
234                 stcb->asoc.fs_index = 0;\
235         stcb->asoc.fslog[stcb->asoc.fs_index].total_flight = stcb->asoc.total_flight; \
236         stcb->asoc.fslog[stcb->asoc.fs_index].tsn = tp1->rec.data.TSN_seq; \
237         stcb->asoc.fslog[stcb->asoc.fs_index].book = tp1->book_size; \
238         stcb->asoc.fslog[stcb->asoc.fs_index].sent = tp1->sent; \
239         stcb->asoc.fslog[stcb->asoc.fs_index].incr = 0; \
240         stcb->asoc.fslog[stcb->asoc.fs_index].decr = 1; \
241         stcb->asoc.fs_index++; \
242         tp1->window_probe = 0; \
243         if (stcb->asoc.total_flight >= tp1->book_size) { \
244                 stcb->asoc.total_flight -= tp1->book_size; \
245                 if (stcb->asoc.total_flight_count > 0) \
246                         stcb->asoc.total_flight_count--; \
247         } else { \
248                 stcb->asoc.total_flight = 0; \
249                 stcb->asoc.total_flight_count = 0; \
250         } \
251 } while (0)
252
253 #define sctp_total_flight_increase(stcb, tp1) do { \
254         if(stcb->asoc.fs_index > SCTP_FS_SPEC_LOG_SIZE) \
255                 stcb->asoc.fs_index = 0;\
256         stcb->asoc.fslog[stcb->asoc.fs_index].total_flight = stcb->asoc.total_flight; \
257         stcb->asoc.fslog[stcb->asoc.fs_index].tsn = tp1->rec.data.TSN_seq; \
258         stcb->asoc.fslog[stcb->asoc.fs_index].book = tp1->book_size; \
259         stcb->asoc.fslog[stcb->asoc.fs_index].sent = tp1->sent; \
260         stcb->asoc.fslog[stcb->asoc.fs_index].incr = 1; \
261         stcb->asoc.fslog[stcb->asoc.fs_index].decr = 0; \
262         stcb->asoc.fs_index++; \
263        (stcb)->asoc.total_flight_count++; \
264        (stcb)->asoc.total_flight += (tp1)->book_size; \
265 } while (0)
266
267 #else
268
269 #define sctp_total_flight_decrease(stcb, tp1) do { \
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        (stcb)->asoc.total_flight_count++; \
282        (stcb)->asoc.total_flight += (tp1)->book_size; \
283 } while (0)
284
285 #endif
286
287
288 struct sctp_nets;
289 struct sctp_inpcb;
290 struct sctp_tcb;
291 struct sctphdr;
292
293
294 void sctp_close(struct socket *so);
295 int sctp_disconnect(struct socket *so);
296
297 void sctp_ctlinput __P((int, struct sockaddr *, void *));
298 int sctp_ctloutput __P((struct socket *, struct sockopt *));
299 void sctp_input_with_port __P((struct mbuf *, int, uint16_t));
300 void sctp_input __P((struct mbuf *, int));
301 void sctp_pathmtu_adjustment __P((struct sctp_inpcb *, struct sctp_tcb *, struct sctp_nets *, uint16_t));
302 void sctp_drain __P((void));
303 void sctp_init __P((void));
304
305 void sctp_finish(void);
306
307 int sctp_flush(struct socket *, int);
308 int sctp_shutdown __P((struct socket *));
309 void sctp_notify 
310 __P((struct sctp_inpcb *, struct ip *ip, struct sctphdr *,
311     struct sockaddr *, struct sctp_tcb *,
312     struct sctp_nets *));
313
314         int sctp_bindx(struct socket *, int, struct sockaddr_storage *,
315         int, int, struct proc *);
316
317 /* can't use sctp_assoc_t here */
318         int sctp_peeloff(struct socket *, struct socket *, int, caddr_t, int *);
319
320         int sctp_ingetaddr(struct socket *,
321         struct sockaddr **
322 );
323
324         int sctp_peeraddr(struct socket *,
325         struct sockaddr **
326 );
327
328         int sctp_listen(struct socket *, int, struct thread *);
329
330         int sctp_accept(struct socket *, struct sockaddr **);
331
332 #endif                          /* _KERNEL */
333
334 #endif                          /* !_NETINET_SCTP_VAR_H_ */