38#ifndef _NETINET_SCTP_VAR_H_
39#define _NETINET_SCTP_VAR_H_
43#if defined(_KERNEL) || defined(__Userspace__)
47#define sctp_feature_on(inp, feature) (inp->sctp_features |= feature)
48#define sctp_feature_off(inp, feature) (inp->sctp_features &= ~feature)
49#define sctp_is_feature_on(inp, feature) ((inp->sctp_features & feature) == feature)
50#define sctp_is_feature_off(inp, feature) ((inp->sctp_features & feature) == 0)
52#define sctp_stcb_feature_on(inp, stcb, feature) {\
54 stcb->asoc.sctp_features |= feature; \
56 inp->sctp_features |= feature; \
59#define sctp_stcb_feature_off(inp, stcb, feature) {\
61 stcb->asoc.sctp_features &= ~feature; \
63 inp->sctp_features &= ~feature; \
66#define sctp_stcb_is_feature_on(inp, stcb, feature) \
68 ((stcb->asoc.sctp_features & feature) == feature)) || \
69 ((stcb == NULL) && (inp != NULL) && \
70 ((inp->sctp_features & feature) == feature)))
71#define sctp_stcb_is_feature_off(inp, stcb, feature) \
73 ((stcb->asoc.sctp_features & feature) == 0)) || \
74 ((stcb == NULL) && (inp != NULL) && \
75 ((inp->sctp_features & feature) == 0)) || \
76 ((stcb == NULL) && (inp == NULL)))
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)
84#define sctp_maxspace(sb) (max((sb)->sb_hiwat,SCTP_MINIMAL_RWND))
86#define sctp_sbspace(asoc, sb) ((long) ((sctp_maxspace(sb) > (asoc)->sb_cc) ? (sctp_maxspace(sb) - (asoc)->sb_cc) : 0))
88#define sctp_sbspace_failedmsgs(sb) ((long) ((sctp_maxspace(sb) > (sb)->sb_cc) ? (sctp_maxspace(sb) - (sb)->sb_cc) : 0))
90#define sctp_sbspace_sub(a,b) (((a) > (b)) ? ((a) - (b)) : 0)
102#define sctp_free_a_readq(_stcb, _readq) { \
103 if ((_readq)->on_strm_q) \
104 panic("On strm q stcb:%p readq:%p", (_stcb), (_readq)); \
105 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_readq), (_readq)); \
106 SCTP_DECR_READQ_COUNT(); \
109#define sctp_free_a_readq(_stcb, _readq) { \
110 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_readq), (_readq)); \
111 SCTP_DECR_READQ_COUNT(); \
115#define sctp_alloc_a_readq(_stcb, _readq) { \
116 (_readq) = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_readq), struct sctp_queued_to_read); \
118 SCTP_INCR_READQ_COUNT(); \
122#define sctp_free_a_strmoq(_stcb, _strmoq, _so_locked) { \
123 if ((_strmoq)->holds_key_ref) { \
124 sctp_auth_key_release(stcb, sp->auth_keyid, _so_locked); \
125 (_strmoq)->holds_key_ref = 0; \
127 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_strmoq), (_strmoq)); \
128 SCTP_DECR_STRMOQ_COUNT(); \
131#define sctp_alloc_a_strmoq(_stcb, _strmoq) { \
132 (_strmoq) = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_strmoq), struct sctp_stream_queue_pending); \
134 memset(_strmoq, 0, sizeof(struct sctp_stream_queue_pending)); \
135 SCTP_INCR_STRMOQ_COUNT(); \
136 (_strmoq)->holds_key_ref = 0; \
140#define sctp_free_a_chunk(_stcb, _chk, _so_locked) { \
141 if ((_chk)->holds_key_ref) {\
142 sctp_auth_key_release((_stcb), (_chk)->auth_keyid, _so_locked); \
143 (_chk)->holds_key_ref = 0; \
146 SCTP_TCB_LOCK_ASSERT((_stcb)); \
147 if ((_chk)->whoTo) { \
148 sctp_free_remote_addr((_chk)->whoTo); \
149 (_chk)->whoTo = NULL; \
151 if (((_stcb)->asoc.free_chunk_cnt > SCTP_BASE_SYSCTL(sctp_asoc_free_resc_limit)) || \
152 (SCTP_BASE_INFO(ipi_free_chunks) > SCTP_BASE_SYSCTL(sctp_system_free_resc_limit))) { \
153 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_chunk), (_chk)); \
154 SCTP_DECR_CHK_COUNT(); \
156 TAILQ_INSERT_TAIL(&(_stcb)->asoc.free_chunks, (_chk), sctp_next); \
157 (_stcb)->asoc.free_chunk_cnt++; \
158 atomic_add_int(&SCTP_BASE_INFO(ipi_free_chunks), 1); \
161 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_chunk), (_chk)); \
162 SCTP_DECR_CHK_COUNT(); \
166#define sctp_alloc_a_chunk(_stcb, _chk) { \
167 if (TAILQ_EMPTY(&(_stcb)->asoc.free_chunks)) { \
168 (_chk) = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_chunk), struct sctp_tmit_chunk); \
170 SCTP_INCR_CHK_COUNT(); \
171 (_chk)->whoTo = NULL; \
172 (_chk)->holds_key_ref = 0; \
175 (_chk) = TAILQ_FIRST(&(_stcb)->asoc.free_chunks); \
176 TAILQ_REMOVE(&(_stcb)->asoc.free_chunks, (_chk), sctp_next); \
177 atomic_subtract_int(&SCTP_BASE_INFO(ipi_free_chunks), 1); \
178 (_chk)->holds_key_ref = 0; \
179 SCTP_STAT_INCR(sctps_cached_chk); \
180 (_stcb)->asoc.free_chunk_cnt--; \
184#define sctp_free_remote_addr(__net) { \
186 if (SCTP_DECREMENT_AND_CHECK_REFCOUNT(&(__net)->ref_count)) { \
187 RO_NHFREE(&(__net)->ro); \
188 if ((__net)->src_addr_selected) { \
189 sctp_free_ifa((__net)->ro._s_addr); \
190 (__net)->ro._s_addr = NULL; \
192 (__net)->src_addr_selected = 0; \
193 (__net)->dest_state &= ~SCTP_ADDR_REACHABLE; \
194 SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_net), (__net)); \
195 SCTP_DECR_RADDR_COUNT(); \
200#define sctp_sbfree(ctl, stcb, sb, m) { \
201 SCTP_SAVE_ATOMIC_DECREMENT(&(sb)->sb_cc, SCTP_BUF_LEN((m))); \
202 SCTP_SAVE_ATOMIC_DECREMENT(&(sb)->sb_mbcnt, MSIZE); \
203 if (((ctl)->do_not_ref_stcb == 0) && stcb) {\
204 SCTP_SAVE_ATOMIC_DECREMENT(&(stcb)->asoc.sb_cc, SCTP_BUF_LEN((m))); \
205 SCTP_SAVE_ATOMIC_DECREMENT(&(stcb)->asoc.my_rwnd_control_len, MSIZE); \
207 if (SCTP_BUF_TYPE(m) != MT_DATA && SCTP_BUF_TYPE(m) != MT_HEADER && \
208 SCTP_BUF_TYPE(m) != MT_OOBDATA) \
209 atomic_subtract_int(&(sb)->sb_ctl,SCTP_BUF_LEN((m))); \
212#define sctp_sballoc(stcb, sb, m) { \
213 atomic_add_int(&(sb)->sb_cc,SCTP_BUF_LEN((m))); \
214 atomic_add_int(&(sb)->sb_mbcnt, MSIZE); \
216 atomic_add_int(&(stcb)->asoc.sb_cc, SCTP_BUF_LEN((m))); \
217 atomic_add_int(&(stcb)->asoc.my_rwnd_control_len, MSIZE); \
219 if (SCTP_BUF_TYPE(m) != MT_DATA && SCTP_BUF_TYPE(m) != MT_HEADER && \
220 SCTP_BUF_TYPE(m) != MT_OOBDATA) \
221 atomic_add_int(&(sb)->sb_ctl,SCTP_BUF_LEN((m))); \
224#define sctp_ucount_incr(val) { \
228#define sctp_ucount_decr(val) { \
236#define sctp_mbuf_crush(data) do { \
239 while (_m && (SCTP_BUF_LEN(_m) == 0)) { \
240 (data) = SCTP_BUF_NEXT(_m); \
241 SCTP_BUF_NEXT(_m) = NULL; \
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; \
251 tp1->whoTo->flight_size = 0; \
254#define sctp_flight_size_increase(tp1) do { \
255 (tp1)->whoTo->flight_size += (tp1)->book_size; \
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; \
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--; \
275 stcb->asoc.total_flight = 0; \
276 stcb->asoc.total_flight_count = 0; \
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; \
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; \
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--; \
303 stcb->asoc.total_flight = 0; \
304 stcb->asoc.total_flight_count = 0; \
308#define sctp_total_flight_increase(stcb, tp1) do { \
309 (stcb)->asoc.total_flight_count++; \
310 (stcb)->asoc.total_flight += (tp1)->book_size; \
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)
328void sctp_input_with_port(
struct mbuf *,
int,
uint16_t);
329int sctp_input(
struct mbuf **,
int *,
int);
340 int,
int,
struct proc *);
343int sctp_peeloff(
struct socket *,
struct socket *,
int, caddr_t,
int *);
346int sctp_listen(
struct socket *,
int,
struct thread *);
347int sctp_accept(
struct socket *,
struct sockaddr **);
int sctp_shutdown(struct socket *)
int sctp_flush(struct socket *, int)
int sctp_listen(struct socket *, int, struct thread *)
int sctp_disconnect(struct socket *so)
void sctp_pathmtu_adjustment(struct sctp_tcb *, uint32_t, bool)
void sctp_notify(struct sctp_inpcb *, struct sctp_tcb *, struct sctp_nets *, uint8_t, uint8_t, uint16_t, uint32_t)
int sctp_ctloutput(struct socket *, struct sockopt *)
int sctp_peeloff(struct socket *, struct socket *, int, caddr_t, int *)
int sctp_bindx(struct socket *, int, struct sockaddr_storage *, int, int, struct proc *)
void sctp_close(struct socket *so)
int sctp_peeraddr(struct socket *, struct sockaddr **)
void sctp_ctlinput(int, struct sockaddr *, void *)
struct pr_usrreqs sctp_usrreqs
int sctp_accept(struct socket *, struct sockaddr **)
int sctp_ingetaddr(struct socket *, struct sockaddr **)