Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /*- |
michael@0 | 2 | * Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved. |
michael@0 | 3 | * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved. |
michael@0 | 4 | * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved. |
michael@0 | 5 | * |
michael@0 | 6 | * Redistribution and use in source and binary forms, with or without |
michael@0 | 7 | * modification, are permitted provided that the following conditions are met: |
michael@0 | 8 | * |
michael@0 | 9 | * a) Redistributions of source code must retain the above copyright notice, |
michael@0 | 10 | * this list of conditions and the following disclaimer. |
michael@0 | 11 | * |
michael@0 | 12 | * b) Redistributions in binary form must reproduce the above copyright |
michael@0 | 13 | * notice, this list of conditions and the following disclaimer in |
michael@0 | 14 | * the documentation and/or other materials provided with the distribution. |
michael@0 | 15 | * |
michael@0 | 16 | * c) Neither the name of Cisco Systems, Inc. nor the names of its |
michael@0 | 17 | * contributors may be used to endorse or promote products derived |
michael@0 | 18 | * from this software without specific prior written permission. |
michael@0 | 19 | * |
michael@0 | 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
michael@0 | 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
michael@0 | 22 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
michael@0 | 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
michael@0 | 24 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
michael@0 | 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
michael@0 | 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
michael@0 | 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
michael@0 | 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
michael@0 | 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
michael@0 | 30 | * THE POSSIBILITY OF SUCH DAMAGE. |
michael@0 | 31 | */ |
michael@0 | 32 | |
michael@0 | 33 | #ifdef __FreeBSD__ |
michael@0 | 34 | #include <sys/cdefs.h> |
michael@0 | 35 | __FBSDID("$FreeBSD: head/sys/netinet/sctp_var.h 242327 2012-10-29 20:47:32Z tuexen $"); |
michael@0 | 36 | #endif |
michael@0 | 37 | |
michael@0 | 38 | #ifndef _NETINET_SCTP_VAR_H_ |
michael@0 | 39 | #define _NETINET_SCTP_VAR_H_ |
michael@0 | 40 | |
michael@0 | 41 | #include <netinet/sctp_uio.h> |
michael@0 | 42 | |
michael@0 | 43 | #if defined(_KERNEL) || defined(__Userspace__) |
michael@0 | 44 | |
michael@0 | 45 | #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) |
michael@0 | 46 | extern struct pr_usrreqs sctp_usrreqs; |
michael@0 | 47 | #endif |
michael@0 | 48 | |
michael@0 | 49 | |
michael@0 | 50 | #define sctp_feature_on(inp, feature) (inp->sctp_features |= feature) |
michael@0 | 51 | #define sctp_feature_off(inp, feature) (inp->sctp_features &= ~feature) |
michael@0 | 52 | #define sctp_is_feature_on(inp, feature) ((inp->sctp_features & feature) == feature) |
michael@0 | 53 | #define sctp_is_feature_off(inp, feature) ((inp->sctp_features & feature) == 0) |
michael@0 | 54 | |
michael@0 | 55 | #define sctp_stcb_feature_on(inp, stcb, feature) {\ |
michael@0 | 56 | if (stcb) { \ |
michael@0 | 57 | stcb->asoc.sctp_features |= feature; \ |
michael@0 | 58 | } else if (inp) { \ |
michael@0 | 59 | inp->sctp_features |= feature; \ |
michael@0 | 60 | } \ |
michael@0 | 61 | } |
michael@0 | 62 | #define sctp_stcb_feature_off(inp, stcb, feature) {\ |
michael@0 | 63 | if (stcb) { \ |
michael@0 | 64 | stcb->asoc.sctp_features &= ~feature; \ |
michael@0 | 65 | } else if (inp) { \ |
michael@0 | 66 | inp->sctp_features &= ~feature; \ |
michael@0 | 67 | } \ |
michael@0 | 68 | } |
michael@0 | 69 | #define sctp_stcb_is_feature_on(inp, stcb, feature) \ |
michael@0 | 70 | (((stcb != NULL) && \ |
michael@0 | 71 | ((stcb->asoc.sctp_features & feature) == feature)) || \ |
michael@0 | 72 | ((stcb == NULL) && (inp != NULL) && \ |
michael@0 | 73 | ((inp->sctp_features & feature) == feature))) |
michael@0 | 74 | #define sctp_stcb_is_feature_off(inp, stcb, feature) \ |
michael@0 | 75 | (((stcb != NULL) && \ |
michael@0 | 76 | ((stcb->asoc.sctp_features & feature) == 0)) || \ |
michael@0 | 77 | ((stcb == NULL) && (inp != NULL) && \ |
michael@0 | 78 | ((inp->sctp_features & feature) == 0)) || \ |
michael@0 | 79 | ((stcb == NULL) && (inp == NULL))) |
michael@0 | 80 | |
michael@0 | 81 | /* managing mobility_feature in inpcb (by micchie) */ |
michael@0 | 82 | #define sctp_mobility_feature_on(inp, feature) (inp->sctp_mobility_features |= feature) |
michael@0 | 83 | #define sctp_mobility_feature_off(inp, feature) (inp->sctp_mobility_features &= ~feature) |
michael@0 | 84 | #define sctp_is_mobility_feature_on(inp, feature) (inp->sctp_mobility_features & feature) |
michael@0 | 85 | #define sctp_is_mobility_feature_off(inp, feature) ((inp->sctp_mobility_features & feature) == 0) |
michael@0 | 86 | |
michael@0 | 87 | #define sctp_maxspace(sb) (max((sb)->sb_hiwat,SCTP_MINIMAL_RWND)) |
michael@0 | 88 | |
michael@0 | 89 | #define sctp_sbspace(asoc, sb) ((long) ((sctp_maxspace(sb) > (asoc)->sb_cc) ? (sctp_maxspace(sb) - (asoc)->sb_cc) : 0)) |
michael@0 | 90 | |
michael@0 | 91 | #define sctp_sbspace_failedmsgs(sb) ((long) ((sctp_maxspace(sb) > (sb)->sb_cc) ? (sctp_maxspace(sb) - (sb)->sb_cc) : 0)) |
michael@0 | 92 | |
michael@0 | 93 | #define sctp_sbspace_sub(a,b) ((a > b) ? (a - b) : 0) |
michael@0 | 94 | |
michael@0 | 95 | /* |
michael@0 | 96 | * I tried to cache the readq entries at one point. But the reality |
michael@0 | 97 | * is that it did not add any performance since this meant we had to |
michael@0 | 98 | * lock the STCB on read. And at that point once you have to do an |
michael@0 | 99 | * extra lock, it really does not matter if the lock is in the ZONE |
michael@0 | 100 | * stuff or in our code. Note that this same problem would occur with |
michael@0 | 101 | * an mbuf cache as well so it is not really worth doing, at least |
michael@0 | 102 | * right now :-D |
michael@0 | 103 | */ |
michael@0 | 104 | |
michael@0 | 105 | #define sctp_free_a_readq(_stcb, _readq) { \ |
michael@0 | 106 | SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_readq), (_readq)); \ |
michael@0 | 107 | SCTP_DECR_READQ_COUNT(); \ |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | #define sctp_alloc_a_readq(_stcb, _readq) { \ |
michael@0 | 111 | (_readq) = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_readq), struct sctp_queued_to_read); \ |
michael@0 | 112 | if ((_readq)) { \ |
michael@0 | 113 | SCTP_INCR_READQ_COUNT(); \ |
michael@0 | 114 | } \ |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | #define sctp_free_a_strmoq(_stcb, _strmoq, _so_locked) { \ |
michael@0 | 118 | if ((_strmoq)->holds_key_ref) { \ |
michael@0 | 119 | sctp_auth_key_release(stcb, sp->auth_keyid, _so_locked); \ |
michael@0 | 120 | (_strmoq)->holds_key_ref = 0; \ |
michael@0 | 121 | } \ |
michael@0 | 122 | SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_strmoq), (_strmoq)); \ |
michael@0 | 123 | SCTP_DECR_STRMOQ_COUNT(); \ |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | #define sctp_alloc_a_strmoq(_stcb, _strmoq) { \ |
michael@0 | 127 | (_strmoq) = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_strmoq), struct sctp_stream_queue_pending); \ |
michael@0 | 128 | if ((_strmoq)) { \ |
michael@0 | 129 | memset(_strmoq, 0, sizeof(struct sctp_stream_queue_pending)); \ |
michael@0 | 130 | SCTP_INCR_STRMOQ_COUNT(); \ |
michael@0 | 131 | (_strmoq)->holds_key_ref = 0; \ |
michael@0 | 132 | } \ |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | #define sctp_free_a_chunk(_stcb, _chk, _so_locked) { \ |
michael@0 | 136 | if ((_chk)->holds_key_ref) {\ |
michael@0 | 137 | sctp_auth_key_release((_stcb), (_chk)->auth_keyid, _so_locked); \ |
michael@0 | 138 | (_chk)->holds_key_ref = 0; \ |
michael@0 | 139 | } \ |
michael@0 | 140 | if (_stcb) { \ |
michael@0 | 141 | SCTP_TCB_LOCK_ASSERT((_stcb)); \ |
michael@0 | 142 | if ((_chk)->whoTo) { \ |
michael@0 | 143 | sctp_free_remote_addr((_chk)->whoTo); \ |
michael@0 | 144 | (_chk)->whoTo = NULL; \ |
michael@0 | 145 | } \ |
michael@0 | 146 | if (((_stcb)->asoc.free_chunk_cnt > SCTP_BASE_SYSCTL(sctp_asoc_free_resc_limit)) || \ |
michael@0 | 147 | (SCTP_BASE_INFO(ipi_free_chunks) > SCTP_BASE_SYSCTL(sctp_system_free_resc_limit))) { \ |
michael@0 | 148 | SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_chunk), (_chk)); \ |
michael@0 | 149 | SCTP_DECR_CHK_COUNT(); \ |
michael@0 | 150 | } else { \ |
michael@0 | 151 | TAILQ_INSERT_TAIL(&(_stcb)->asoc.free_chunks, (_chk), sctp_next); \ |
michael@0 | 152 | (_stcb)->asoc.free_chunk_cnt++; \ |
michael@0 | 153 | atomic_add_int(&SCTP_BASE_INFO(ipi_free_chunks), 1); \ |
michael@0 | 154 | } \ |
michael@0 | 155 | } else { \ |
michael@0 | 156 | SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_chunk), (_chk)); \ |
michael@0 | 157 | SCTP_DECR_CHK_COUNT(); \ |
michael@0 | 158 | } \ |
michael@0 | 159 | } |
michael@0 | 160 | |
michael@0 | 161 | #define sctp_alloc_a_chunk(_stcb, _chk) { \ |
michael@0 | 162 | if (TAILQ_EMPTY(&(_stcb)->asoc.free_chunks)) { \ |
michael@0 | 163 | (_chk) = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_chunk), struct sctp_tmit_chunk); \ |
michael@0 | 164 | if ((_chk)) { \ |
michael@0 | 165 | SCTP_INCR_CHK_COUNT(); \ |
michael@0 | 166 | (_chk)->whoTo = NULL; \ |
michael@0 | 167 | (_chk)->holds_key_ref = 0; \ |
michael@0 | 168 | } \ |
michael@0 | 169 | } else { \ |
michael@0 | 170 | (_chk) = TAILQ_FIRST(&(_stcb)->asoc.free_chunks); \ |
michael@0 | 171 | TAILQ_REMOVE(&(_stcb)->asoc.free_chunks, (_chk), sctp_next); \ |
michael@0 | 172 | atomic_subtract_int(&SCTP_BASE_INFO(ipi_free_chunks), 1); \ |
michael@0 | 173 | (_chk)->holds_key_ref = 0; \ |
michael@0 | 174 | SCTP_STAT_INCR(sctps_cached_chk); \ |
michael@0 | 175 | (_stcb)->asoc.free_chunk_cnt--; \ |
michael@0 | 176 | } \ |
michael@0 | 177 | } |
michael@0 | 178 | |
michael@0 | 179 | #if defined(__FreeBSD__) && __FreeBSD_version > 500000 |
michael@0 | 180 | |
michael@0 | 181 | #define sctp_free_remote_addr(__net) { \ |
michael@0 | 182 | if ((__net)) { \ |
michael@0 | 183 | if (SCTP_DECREMENT_AND_CHECK_REFCOUNT(&(__net)->ref_count)) { \ |
michael@0 | 184 | (void)SCTP_OS_TIMER_STOP(&(__net)->rxt_timer.timer); \ |
michael@0 | 185 | (void)SCTP_OS_TIMER_STOP(&(__net)->pmtu_timer.timer); \ |
michael@0 | 186 | if ((__net)->ro.ro_rt) { \ |
michael@0 | 187 | RTFREE((__net)->ro.ro_rt); \ |
michael@0 | 188 | (__net)->ro.ro_rt = NULL; \ |
michael@0 | 189 | } \ |
michael@0 | 190 | if ((__net)->src_addr_selected) { \ |
michael@0 | 191 | sctp_free_ifa((__net)->ro._s_addr); \ |
michael@0 | 192 | (__net)->ro._s_addr = NULL; \ |
michael@0 | 193 | } \ |
michael@0 | 194 | (__net)->src_addr_selected = 0; \ |
michael@0 | 195 | (__net)->dest_state &= ~SCTP_ADDR_REACHABLE; \ |
michael@0 | 196 | SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_net), (__net)); \ |
michael@0 | 197 | SCTP_DECR_RADDR_COUNT(); \ |
michael@0 | 198 | } \ |
michael@0 | 199 | } \ |
michael@0 | 200 | } |
michael@0 | 201 | |
michael@0 | 202 | #define sctp_sbfree(ctl, stcb, sb, m) { \ |
michael@0 | 203 | SCTP_SAVE_ATOMIC_DECREMENT(&(sb)->sb_cc, SCTP_BUF_LEN((m))); \ |
michael@0 | 204 | SCTP_SAVE_ATOMIC_DECREMENT(&(sb)->sb_mbcnt, MSIZE); \ |
michael@0 | 205 | if (((ctl)->do_not_ref_stcb == 0) && stcb) {\ |
michael@0 | 206 | SCTP_SAVE_ATOMIC_DECREMENT(&(stcb)->asoc.sb_cc, SCTP_BUF_LEN((m))); \ |
michael@0 | 207 | SCTP_SAVE_ATOMIC_DECREMENT(&(stcb)->asoc.my_rwnd_control_len, MSIZE); \ |
michael@0 | 208 | } \ |
michael@0 | 209 | if (SCTP_BUF_TYPE(m) != MT_DATA && SCTP_BUF_TYPE(m) != MT_HEADER && \ |
michael@0 | 210 | SCTP_BUF_TYPE(m) != MT_OOBDATA) \ |
michael@0 | 211 | atomic_subtract_int(&(sb)->sb_ctl,SCTP_BUF_LEN((m))); \ |
michael@0 | 212 | } |
michael@0 | 213 | |
michael@0 | 214 | #define sctp_sballoc(stcb, sb, m) { \ |
michael@0 | 215 | atomic_add_int(&(sb)->sb_cc,SCTP_BUF_LEN((m))); \ |
michael@0 | 216 | atomic_add_int(&(sb)->sb_mbcnt, MSIZE); \ |
michael@0 | 217 | if (stcb) { \ |
michael@0 | 218 | atomic_add_int(&(stcb)->asoc.sb_cc,SCTP_BUF_LEN((m))); \ |
michael@0 | 219 | atomic_add_int(&(stcb)->asoc.my_rwnd_control_len, MSIZE); \ |
michael@0 | 220 | } \ |
michael@0 | 221 | if (SCTP_BUF_TYPE(m) != MT_DATA && SCTP_BUF_TYPE(m) != MT_HEADER && \ |
michael@0 | 222 | SCTP_BUF_TYPE(m) != MT_OOBDATA) \ |
michael@0 | 223 | atomic_add_int(&(sb)->sb_ctl,SCTP_BUF_LEN((m))); \ |
michael@0 | 224 | } |
michael@0 | 225 | |
michael@0 | 226 | #else /* FreeBSD Version <= 500000 or non-FreeBSD */ |
michael@0 | 227 | |
michael@0 | 228 | #define sctp_free_remote_addr(__net) { \ |
michael@0 | 229 | if ((__net)) { \ |
michael@0 | 230 | if (SCTP_DECREMENT_AND_CHECK_REFCOUNT(&(__net)->ref_count)) { \ |
michael@0 | 231 | (void)SCTP_OS_TIMER_STOP(&(__net)->rxt_timer.timer); \ |
michael@0 | 232 | (void)SCTP_OS_TIMER_STOP(&(__net)->pmtu_timer.timer); \ |
michael@0 | 233 | (void)SCTP_OS_TIMER_STOP(&(__net)->hb_timer.timer); \ |
michael@0 | 234 | if ((__net)->ro.ro_rt) { \ |
michael@0 | 235 | RTFREE((__net)->ro.ro_rt); \ |
michael@0 | 236 | (__net)->ro.ro_rt = NULL; \ |
michael@0 | 237 | } \ |
michael@0 | 238 | if ((__net)->src_addr_selected) { \ |
michael@0 | 239 | sctp_free_ifa((__net)->ro._s_addr); \ |
michael@0 | 240 | (__net)->ro._s_addr = NULL; \ |
michael@0 | 241 | } \ |
michael@0 | 242 | (__net)->src_addr_selected = 0; \ |
michael@0 | 243 | (__net)->dest_state &=~SCTP_ADDR_REACHABLE; \ |
michael@0 | 244 | SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_net), (__net)); \ |
michael@0 | 245 | SCTP_DECR_RADDR_COUNT(); \ |
michael@0 | 246 | } \ |
michael@0 | 247 | } \ |
michael@0 | 248 | } |
michael@0 | 249 | |
michael@0 | 250 | #if defined(__Panda__) |
michael@0 | 251 | #define sctp_sbfree(ctl, stcb, sb, m) { \ |
michael@0 | 252 | if ((sb)->sb_cc >= (uint32_t)SCTP_BUF_LEN((m))) { \ |
michael@0 | 253 | atomic_subtract_int(&(sb)->sb_cc, SCTP_BUF_LEN((m))); \ |
michael@0 | 254 | } else { \ |
michael@0 | 255 | (sb)->sb_cc = 0; \ |
michael@0 | 256 | } \ |
michael@0 | 257 | if (((ctl)->do_not_ref_stcb == 0) && stcb) { \ |
michael@0 | 258 | if ((stcb)->asoc.sb_cc >= (uint32_t)SCTP_BUF_LEN((m))) { \ |
michael@0 | 259 | atomic_subtract_int(&(stcb)->asoc.sb_cc, SCTP_BUF_LEN((m))); \ |
michael@0 | 260 | } else { \ |
michael@0 | 261 | (stcb)->asoc.sb_cc = 0; \ |
michael@0 | 262 | } \ |
michael@0 | 263 | } \ |
michael@0 | 264 | } |
michael@0 | 265 | |
michael@0 | 266 | #define sctp_sballoc(stcb, sb, m) { \ |
michael@0 | 267 | atomic_add_int(&(sb)->sb_cc, SCTP_BUF_LEN((m))); \ |
michael@0 | 268 | if (stcb) { \ |
michael@0 | 269 | atomic_add_int(&(stcb)->asoc.sb_cc, SCTP_BUF_LEN((m))); \ |
michael@0 | 270 | } \ |
michael@0 | 271 | } |
michael@0 | 272 | |
michael@0 | 273 | #else |
michael@0 | 274 | |
michael@0 | 275 | #define sctp_sbfree(ctl, stcb, sb, m) { \ |
michael@0 | 276 | SCTP_SAVE_ATOMIC_DECREMENT(&(sb)->sb_cc, SCTP_BUF_LEN((m))); \ |
michael@0 | 277 | SCTP_SAVE_ATOMIC_DECREMENT(&(sb)->sb_mbcnt, MSIZE); \ |
michael@0 | 278 | if (((ctl)->do_not_ref_stcb == 0) && stcb) { \ |
michael@0 | 279 | SCTP_SAVE_ATOMIC_DECREMENT(&(stcb)->asoc.sb_cc, SCTP_BUF_LEN((m))); \ |
michael@0 | 280 | SCTP_SAVE_ATOMIC_DECREMENT(&(stcb)->asoc.my_rwnd_control_len, MSIZE); \ |
michael@0 | 281 | } \ |
michael@0 | 282 | } |
michael@0 | 283 | |
michael@0 | 284 | #define sctp_sballoc(stcb, sb, m) { \ |
michael@0 | 285 | atomic_add_int(&(sb)->sb_cc, SCTP_BUF_LEN((m))); \ |
michael@0 | 286 | atomic_add_int(&(sb)->sb_mbcnt, MSIZE); \ |
michael@0 | 287 | if (stcb) { \ |
michael@0 | 288 | atomic_add_int(&(stcb)->asoc.sb_cc, SCTP_BUF_LEN((m))); \ |
michael@0 | 289 | atomic_add_int(&(stcb)->asoc.my_rwnd_control_len, MSIZE); \ |
michael@0 | 290 | } \ |
michael@0 | 291 | } |
michael@0 | 292 | #endif |
michael@0 | 293 | #endif |
michael@0 | 294 | |
michael@0 | 295 | #define sctp_ucount_incr(val) { \ |
michael@0 | 296 | val++; \ |
michael@0 | 297 | } |
michael@0 | 298 | |
michael@0 | 299 | #define sctp_ucount_decr(val) { \ |
michael@0 | 300 | if (val > 0) { \ |
michael@0 | 301 | val--; \ |
michael@0 | 302 | } else { \ |
michael@0 | 303 | val = 0; \ |
michael@0 | 304 | } \ |
michael@0 | 305 | } |
michael@0 | 306 | |
michael@0 | 307 | #define sctp_mbuf_crush(data) do { \ |
michael@0 | 308 | struct mbuf *_m; \ |
michael@0 | 309 | _m = (data); \ |
michael@0 | 310 | while (_m && (SCTP_BUF_LEN(_m) == 0)) { \ |
michael@0 | 311 | (data) = SCTP_BUF_NEXT(_m); \ |
michael@0 | 312 | SCTP_BUF_NEXT(_m) = NULL; \ |
michael@0 | 313 | sctp_m_free(_m); \ |
michael@0 | 314 | _m = (data); \ |
michael@0 | 315 | } \ |
michael@0 | 316 | } while (0) |
michael@0 | 317 | |
michael@0 | 318 | #define sctp_flight_size_decrease(tp1) do { \ |
michael@0 | 319 | if (tp1->whoTo->flight_size >= tp1->book_size) \ |
michael@0 | 320 | tp1->whoTo->flight_size -= tp1->book_size; \ |
michael@0 | 321 | else \ |
michael@0 | 322 | tp1->whoTo->flight_size = 0; \ |
michael@0 | 323 | } while (0) |
michael@0 | 324 | |
michael@0 | 325 | #define sctp_flight_size_increase(tp1) do { \ |
michael@0 | 326 | (tp1)->whoTo->flight_size += (tp1)->book_size; \ |
michael@0 | 327 | } while (0) |
michael@0 | 328 | |
michael@0 | 329 | #ifdef SCTP_FS_SPEC_LOG |
michael@0 | 330 | #define sctp_total_flight_decrease(stcb, tp1) do { \ |
michael@0 | 331 | if (stcb->asoc.fs_index > SCTP_FS_SPEC_LOG_SIZE) \ |
michael@0 | 332 | stcb->asoc.fs_index = 0;\ |
michael@0 | 333 | stcb->asoc.fslog[stcb->asoc.fs_index].total_flight = stcb->asoc.total_flight; \ |
michael@0 | 334 | stcb->asoc.fslog[stcb->asoc.fs_index].tsn = tp1->rec.data.TSN_seq; \ |
michael@0 | 335 | stcb->asoc.fslog[stcb->asoc.fs_index].book = tp1->book_size; \ |
michael@0 | 336 | stcb->asoc.fslog[stcb->asoc.fs_index].sent = tp1->sent; \ |
michael@0 | 337 | stcb->asoc.fslog[stcb->asoc.fs_index].incr = 0; \ |
michael@0 | 338 | stcb->asoc.fslog[stcb->asoc.fs_index].decr = 1; \ |
michael@0 | 339 | stcb->asoc.fs_index++; \ |
michael@0 | 340 | tp1->window_probe = 0; \ |
michael@0 | 341 | if (stcb->asoc.total_flight >= tp1->book_size) { \ |
michael@0 | 342 | stcb->asoc.total_flight -= tp1->book_size; \ |
michael@0 | 343 | if (stcb->asoc.total_flight_count > 0) \ |
michael@0 | 344 | stcb->asoc.total_flight_count--; \ |
michael@0 | 345 | } else { \ |
michael@0 | 346 | stcb->asoc.total_flight = 0; \ |
michael@0 | 347 | stcb->asoc.total_flight_count = 0; \ |
michael@0 | 348 | } \ |
michael@0 | 349 | } while (0) |
michael@0 | 350 | |
michael@0 | 351 | #define sctp_total_flight_increase(stcb, tp1) do { \ |
michael@0 | 352 | if (stcb->asoc.fs_index > SCTP_FS_SPEC_LOG_SIZE) \ |
michael@0 | 353 | stcb->asoc.fs_index = 0;\ |
michael@0 | 354 | stcb->asoc.fslog[stcb->asoc.fs_index].total_flight = stcb->asoc.total_flight; \ |
michael@0 | 355 | stcb->asoc.fslog[stcb->asoc.fs_index].tsn = tp1->rec.data.TSN_seq; \ |
michael@0 | 356 | stcb->asoc.fslog[stcb->asoc.fs_index].book = tp1->book_size; \ |
michael@0 | 357 | stcb->asoc.fslog[stcb->asoc.fs_index].sent = tp1->sent; \ |
michael@0 | 358 | stcb->asoc.fslog[stcb->asoc.fs_index].incr = 1; \ |
michael@0 | 359 | stcb->asoc.fslog[stcb->asoc.fs_index].decr = 0; \ |
michael@0 | 360 | stcb->asoc.fs_index++; \ |
michael@0 | 361 | (stcb)->asoc.total_flight_count++; \ |
michael@0 | 362 | (stcb)->asoc.total_flight += (tp1)->book_size; \ |
michael@0 | 363 | } while (0) |
michael@0 | 364 | |
michael@0 | 365 | #else |
michael@0 | 366 | |
michael@0 | 367 | #define sctp_total_flight_decrease(stcb, tp1) do { \ |
michael@0 | 368 | tp1->window_probe = 0; \ |
michael@0 | 369 | if (stcb->asoc.total_flight >= tp1->book_size) { \ |
michael@0 | 370 | stcb->asoc.total_flight -= tp1->book_size; \ |
michael@0 | 371 | if (stcb->asoc.total_flight_count > 0) \ |
michael@0 | 372 | stcb->asoc.total_flight_count--; \ |
michael@0 | 373 | } else { \ |
michael@0 | 374 | stcb->asoc.total_flight = 0; \ |
michael@0 | 375 | stcb->asoc.total_flight_count = 0; \ |
michael@0 | 376 | } \ |
michael@0 | 377 | } while (0) |
michael@0 | 378 | |
michael@0 | 379 | #define sctp_total_flight_increase(stcb, tp1) do { \ |
michael@0 | 380 | (stcb)->asoc.total_flight_count++; \ |
michael@0 | 381 | (stcb)->asoc.total_flight += (tp1)->book_size; \ |
michael@0 | 382 | } while (0) |
michael@0 | 383 | |
michael@0 | 384 | #endif |
michael@0 | 385 | |
michael@0 | 386 | #define SCTP_PF_ENABLED(_net) (_net->pf_threshold < _net->failure_threshold) |
michael@0 | 387 | #define SCTP_NET_IS_PF(_net) (_net->pf_threshold < _net->error_count) |
michael@0 | 388 | |
michael@0 | 389 | struct sctp_nets; |
michael@0 | 390 | struct sctp_inpcb; |
michael@0 | 391 | struct sctp_tcb; |
michael@0 | 392 | struct sctphdr; |
michael@0 | 393 | |
michael@0 | 394 | |
michael@0 | 395 | #if (defined(__FreeBSD__) && __FreeBSD_version > 690000) || defined(__Windows__) || defined(__Userspace__) |
michael@0 | 396 | void sctp_close(struct socket *so); |
michael@0 | 397 | #else |
michael@0 | 398 | int sctp_detach(struct socket *so); |
michael@0 | 399 | #endif |
michael@0 | 400 | int sctp_disconnect(struct socket *so); |
michael@0 | 401 | #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) |
michael@0 | 402 | #if defined(__FreeBSD__) && __FreeBSD_version < 902000 |
michael@0 | 403 | void sctp_ctlinput __P((int, struct sockaddr *, void *)); |
michael@0 | 404 | int sctp_ctloutput __P((struct socket *, struct sockopt *)); |
michael@0 | 405 | #ifdef INET |
michael@0 | 406 | void sctp_input_with_port __P((struct mbuf *, int, uint16_t)); |
michael@0 | 407 | void sctp_input __P((struct mbuf *, int)); |
michael@0 | 408 | #endif |
michael@0 | 409 | void sctp_pathmtu_adjustment __P((struct sctp_tcb *, uint16_t)); |
michael@0 | 410 | #else |
michael@0 | 411 | void sctp_ctlinput(int, struct sockaddr *, void *); |
michael@0 | 412 | int sctp_ctloutput(struct socket *, struct sockopt *); |
michael@0 | 413 | #ifdef INET |
michael@0 | 414 | void sctp_input_with_port(struct mbuf *, int, uint16_t); |
michael@0 | 415 | void sctp_input(struct mbuf *, int); |
michael@0 | 416 | #endif |
michael@0 | 417 | void sctp_pathmtu_adjustment(struct sctp_tcb *, uint16_t); |
michael@0 | 418 | #endif |
michael@0 | 419 | #else |
michael@0 | 420 | #if defined(__Panda__) |
michael@0 | 421 | void sctp_input(pakhandle_type i_pak); |
michael@0 | 422 | #elif defined(__Userspace__) |
michael@0 | 423 | void sctp_pathmtu_adjustment(struct sctp_tcb *, uint16_t); |
michael@0 | 424 | #else |
michael@0 | 425 | void sctp_input(struct mbuf *,...); |
michael@0 | 426 | #endif |
michael@0 | 427 | void *sctp_ctlinput(int, struct sockaddr *, void *); |
michael@0 | 428 | int sctp_ctloutput(int, struct socket *, int, int, struct mbuf **); |
michael@0 | 429 | #endif |
michael@0 | 430 | #if defined(__FreeBSD__) && __FreeBSD_version < 902000 |
michael@0 | 431 | void sctp_drain __P((void)); |
michael@0 | 432 | #else |
michael@0 | 433 | void sctp_drain(void); |
michael@0 | 434 | #endif |
michael@0 | 435 | #if defined(__Userspace__) |
michael@0 | 436 | void sctp_init(uint16_t, |
michael@0 | 437 | int (*)(void *addr, void *buffer, size_t length, uint8_t tos, uint8_t set_df), |
michael@0 | 438 | void (*)(const char *, ...)); |
michael@0 | 439 | #elif defined(__FreeBSD__) && __FreeBSD_version < 902000 |
michael@0 | 440 | void sctp_init __P((void)); |
michael@0 | 441 | #elif defined(__APPLE__) && (!defined(APPLE_LEOPARD) && !defined(APPLE_SNOWLEOPARD) &&!defined(APPLE_LION) && !defined(APPLE_MOUNTAINLION)) |
michael@0 | 442 | void sctp_init(struct protosw *pp, struct domain *dp); |
michael@0 | 443 | #else |
michael@0 | 444 | void sctp_init(void); |
michael@0 | 445 | #endif |
michael@0 | 446 | void sctp_finish(void); |
michael@0 | 447 | #if defined(__FreeBSD__) || defined(__Windows__) || defined(__Userspace__) |
michael@0 | 448 | int sctp_flush(struct socket *, int); |
michael@0 | 449 | #endif |
michael@0 | 450 | #if defined(__FreeBSD__) && __FreeBSD_version < 902000 |
michael@0 | 451 | int sctp_shutdown __P((struct socket *)); |
michael@0 | 452 | void sctp_notify __P((struct sctp_inpcb *, struct ip *ip, struct sctphdr *, |
michael@0 | 453 | struct sockaddr *, struct sctp_tcb *, |
michael@0 | 454 | struct sctp_nets *)); |
michael@0 | 455 | #else |
michael@0 | 456 | int sctp_shutdown(struct socket *); |
michael@0 | 457 | void sctp_notify(struct sctp_inpcb *, struct ip *ip, struct sctphdr *, |
michael@0 | 458 | struct sockaddr *, struct sctp_tcb *, |
michael@0 | 459 | struct sctp_nets *); |
michael@0 | 460 | #endif |
michael@0 | 461 | int sctp_bindx(struct socket *, int, struct sockaddr_storage *, |
michael@0 | 462 | int, int, struct proc *); |
michael@0 | 463 | /* can't use sctp_assoc_t here */ |
michael@0 | 464 | int sctp_peeloff(struct socket *, struct socket *, int, caddr_t, int *); |
michael@0 | 465 | #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) |
michael@0 | 466 | int sctp_ingetaddr(struct socket *, struct sockaddr **); |
michael@0 | 467 | #elif defined(__Panda__) |
michael@0 | 468 | int sctp_ingetaddr(struct socket *, struct sockaddr *); |
michael@0 | 469 | #else |
michael@0 | 470 | int sctp_ingetaddr(struct socket *, struct mbuf *); |
michael@0 | 471 | #endif |
michael@0 | 472 | #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) |
michael@0 | 473 | int sctp_peeraddr(struct socket *, struct sockaddr **); |
michael@0 | 474 | #elif defined(__Panda__) |
michael@0 | 475 | int sctp_peeraddr(struct socket *, struct sockaddr *); |
michael@0 | 476 | #else |
michael@0 | 477 | int sctp_peeraddr(struct socket *, struct mbuf *); |
michael@0 | 478 | #endif |
michael@0 | 479 | #if defined(__FreeBSD__) && __FreeBSD_version >= 500000 |
michael@0 | 480 | #if __FreeBSD_version >= 700000 |
michael@0 | 481 | int sctp_listen(struct socket *, int, struct thread *); |
michael@0 | 482 | #else |
michael@0 | 483 | int sctp_listen(struct socket *, struct thread *); |
michael@0 | 484 | #endif |
michael@0 | 485 | #elif defined(__Windows__) |
michael@0 | 486 | int sctp_listen(struct socket *, int, PKTHREAD); |
michael@0 | 487 | #elif defined(__Userspace__) |
michael@0 | 488 | int sctp_listen(struct socket *, int, struct proc *); |
michael@0 | 489 | #else |
michael@0 | 490 | int sctp_listen(struct socket *, struct proc *); |
michael@0 | 491 | #endif |
michael@0 | 492 | #if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__) |
michael@0 | 493 | int sctp_accept(struct socket *, struct sockaddr **); |
michael@0 | 494 | #elif defined(__Panda__) |
michael@0 | 495 | int sctp_accept(struct socket *, struct sockaddr *, int *, void *, int *); |
michael@0 | 496 | #else |
michael@0 | 497 | int sctp_accept(struct socket *, struct mbuf *); |
michael@0 | 498 | #endif |
michael@0 | 499 | |
michael@0 | 500 | #endif /* _KERNEL */ |
michael@0 | 501 | |
michael@0 | 502 | #endif /* !_NETINET_SCTP_VAR_H_ */ |