netwerk/sctp/src/netinet/sctputil.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rwxr-xr-x

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-2007, 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/sctputil.h 243186 2012-11-17 20:04:04Z tuexen $");
michael@0 36 #endif
michael@0 37
michael@0 38 #ifndef _NETINET_SCTP_UTIL_H_
michael@0 39 #define _NETINET_SCTP_UTIL_H_
michael@0 40
michael@0 41 #if defined(_KERNEL) || defined(__Userspace__)
michael@0 42
michael@0 43 #define SCTP_READ_LOCK_HELD 1
michael@0 44 #define SCTP_READ_LOCK_NOT_HELD 0
michael@0 45
michael@0 46 #ifdef SCTP_ASOCLOG_OF_TSNS
michael@0 47 void sctp_print_out_track_log(struct sctp_tcb *stcb);
michael@0 48 #endif
michael@0 49
michael@0 50 #ifdef SCTP_MBUF_LOGGING
michael@0 51 struct mbuf *sctp_m_free(struct mbuf *m);
michael@0 52 void sctp_m_freem(struct mbuf *m);
michael@0 53 #else
michael@0 54 #define sctp_m_free m_free
michael@0 55 #define sctp_m_freem m_freem
michael@0 56 #endif
michael@0 57
michael@0 58 #if defined(SCTP_LOCAL_TRACE_BUF) || defined(__APPLE__)
michael@0 59 void
michael@0 60 sctp_log_trace(uint32_t fr, const char *str SCTP_UNUSED, uint32_t a, uint32_t b, uint32_t c, uint32_t d, uint32_t e, uint32_t f);
michael@0 61 #endif
michael@0 62
michael@0 63 #define sctp_get_associd(stcb) ((sctp_assoc_t)stcb->asoc.assoc_id)
michael@0 64
michael@0 65
michael@0 66 /*
michael@0 67 * Function prototypes
michael@0 68 */
michael@0 69 uint32_t
michael@0 70 sctp_get_ifa_hash_val(struct sockaddr *addr);
michael@0 71
michael@0 72 struct sctp_ifa *
michael@0 73 sctp_find_ifa_in_ep(struct sctp_inpcb *inp, struct sockaddr *addr, int hold_lock);
michael@0 74
michael@0 75 struct sctp_ifa *
michael@0 76 sctp_find_ifa_by_addr(struct sockaddr *addr, uint32_t vrf_id, int holds_lock);
michael@0 77
michael@0 78 uint32_t sctp_select_initial_TSN(struct sctp_pcb *);
michael@0 79
michael@0 80 uint32_t sctp_select_a_tag(struct sctp_inpcb *, uint16_t lport, uint16_t rport, int);
michael@0 81
michael@0 82 int sctp_init_asoc(struct sctp_inpcb *, struct sctp_tcb *, uint32_t, uint32_t);
michael@0 83
michael@0 84 void sctp_fill_random_store(struct sctp_pcb *);
michael@0 85
michael@0 86 void
michael@0 87 sctp_notify_stream_reset_add(struct sctp_tcb *stcb, uint16_t numberin,
michael@0 88 uint16_t numberout, int flag);
michael@0 89 void
michael@0 90 sctp_notify_stream_reset_tsn(struct sctp_tcb *stcb, uint32_t sending_tsn, uint32_t recv_tsn, int flag);
michael@0 91
michael@0 92 void
michael@0 93 sctp_timer_start(int, struct sctp_inpcb *, struct sctp_tcb *,
michael@0 94 struct sctp_nets *);
michael@0 95
michael@0 96 void
michael@0 97 sctp_timer_stop(int, struct sctp_inpcb *, struct sctp_tcb *,
michael@0 98 struct sctp_nets *, uint32_t);
michael@0 99
michael@0 100 int
michael@0 101 sctp_dynamic_set_primary(struct sockaddr *sa, uint32_t vrf_id);
michael@0 102
michael@0 103 void
michael@0 104 sctp_mtu_size_reset(struct sctp_inpcb *, struct sctp_association *, uint32_t);
michael@0 105
michael@0 106 void
michael@0 107 sctp_add_to_readq(struct sctp_inpcb *inp,
michael@0 108 struct sctp_tcb *stcb,
michael@0 109 struct sctp_queued_to_read *control,
michael@0 110 struct sockbuf *sb,
michael@0 111 int end,
michael@0 112 int inpread_locked,
michael@0 113 int so_locked
michael@0 114 #if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
michael@0 115 SCTP_UNUSED
michael@0 116 #endif
michael@0 117 );
michael@0 118
michael@0 119 int
michael@0 120 sctp_append_to_readq(struct sctp_inpcb *inp,
michael@0 121 struct sctp_tcb *stcb,
michael@0 122 struct sctp_queued_to_read *control,
michael@0 123 struct mbuf *m,
michael@0 124 int end,
michael@0 125 int new_cumack,
michael@0 126 struct sockbuf *sb);
michael@0 127
michael@0 128
michael@0 129 void sctp_iterator_worker(void);
michael@0 130
michael@0 131 uint32_t sctp_get_prev_mtu(uint32_t);
michael@0 132 uint32_t sctp_get_next_mtu(uint32_t);
michael@0 133
michael@0 134 void
michael@0 135 sctp_timeout_handler(void *);
michael@0 136
michael@0 137 uint32_t
michael@0 138 sctp_calculate_rto(struct sctp_tcb *, struct sctp_association *,
michael@0 139 struct sctp_nets *, struct timeval *, int, int);
michael@0 140
michael@0 141 uint32_t sctp_calculate_len(struct mbuf *);
michael@0 142
michael@0 143 caddr_t sctp_m_getptr(struct mbuf *, int, int, uint8_t *);
michael@0 144
michael@0 145 struct sctp_paramhdr *
michael@0 146 sctp_get_next_param(struct mbuf *, int,
michael@0 147 struct sctp_paramhdr *, int);
michael@0 148
michael@0 149 int sctp_add_pad_tombuf(struct mbuf *, int);
michael@0 150
michael@0 151 int sctp_pad_lastmbuf(struct mbuf *, int, struct mbuf *);
michael@0 152
michael@0 153 void sctp_ulp_notify(uint32_t, struct sctp_tcb *, uint32_t, void *, int
michael@0 154 #if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
michael@0 155 SCTP_UNUSED
michael@0 156 #endif
michael@0 157 );
michael@0 158
michael@0 159 void
michael@0 160 sctp_pull_off_control_to_new_inp(struct sctp_inpcb *old_inp,
michael@0 161 struct sctp_inpcb *new_inp,
michael@0 162 struct sctp_tcb *stcb, int waitflags);
michael@0 163
michael@0 164
michael@0 165 void sctp_stop_timers_for_shutdown(struct sctp_tcb *);
michael@0 166
michael@0 167 void sctp_report_all_outbound(struct sctp_tcb *, uint16_t, int, int
michael@0 168 #if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
michael@0 169 SCTP_UNUSED
michael@0 170 #endif
michael@0 171 );
michael@0 172
michael@0 173 int sctp_expand_mapping_array(struct sctp_association *, uint32_t);
michael@0 174
michael@0 175 void sctp_abort_notification(struct sctp_tcb *, uint8_t, uint16_t,
michael@0 176 struct sctp_abort_chunk *, int
michael@0 177 #if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
michael@0 178 SCTP_UNUSED
michael@0 179 #endif
michael@0 180 );
michael@0 181
michael@0 182 /* We abort responding to an IP packet for some reason */
michael@0 183 void
michael@0 184 sctp_abort_association(struct sctp_inpcb *, struct sctp_tcb *, struct mbuf *,
michael@0 185 int, struct sockaddr *, struct sockaddr *,
michael@0 186 struct sctphdr *, struct mbuf *,
michael@0 187 #if defined(__FreeBSD__)
michael@0 188 uint8_t, uint32_t,
michael@0 189 #endif
michael@0 190 uint32_t, uint16_t);
michael@0 191
michael@0 192
michael@0 193 /* We choose to abort via user input */
michael@0 194 void
michael@0 195 sctp_abort_an_association(struct sctp_inpcb *, struct sctp_tcb *,
michael@0 196 struct mbuf *, int
michael@0 197 #if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
michael@0 198 SCTP_UNUSED
michael@0 199 #endif
michael@0 200 );
michael@0 201
michael@0 202 void sctp_handle_ootb(struct mbuf *, int, int,
michael@0 203 struct sockaddr *, struct sockaddr *,
michael@0 204 struct sctphdr *, struct sctp_inpcb *,
michael@0 205 #if defined(__FreeBSD__)
michael@0 206 uint8_t, uint32_t,
michael@0 207 #endif
michael@0 208 uint32_t, uint16_t);
michael@0 209
michael@0 210 int sctp_connectx_helper_add(struct sctp_tcb *stcb, struct sockaddr *addr,
michael@0 211 int totaddr, int *error);
michael@0 212
michael@0 213 struct sctp_tcb *
michael@0 214 sctp_connectx_helper_find(struct sctp_inpcb *inp, struct sockaddr *addr,
michael@0 215 int *totaddr, int *num_v4, int *num_v6, int *error, int limit, int *bad_addr);
michael@0 216
michael@0 217 int sctp_is_there_an_abort_here(struct mbuf *, int, uint32_t *);
michael@0 218 #ifdef INET6
michael@0 219 uint32_t sctp_is_same_scope(struct sockaddr_in6 *, struct sockaddr_in6 *);
michael@0 220
michael@0 221 #if defined(SCTP_EMBEDDED_V6_SCOPE)
michael@0 222 struct sockaddr_in6 *
michael@0 223 sctp_recover_scope(struct sockaddr_in6 *, struct sockaddr_in6 *);
michael@0 224
michael@0 225 #ifdef SCTP_KAME
michael@0 226 #define sctp_recover_scope_mac(addr, store) do { \
michael@0 227 if ((addr->sin6_family == AF_INET6) && \
michael@0 228 (IN6_IS_SCOPE_LINKLOCAL(&addr->sin6_addr))) { \
michael@0 229 *store = *addr; \
michael@0 230 if (addr->sin6_scope_id == 0) { \
michael@0 231 if (!sa6_recoverscope(store)) { \
michael@0 232 addr = store; \
michael@0 233 } \
michael@0 234 } else { \
michael@0 235 in6_clearscope(&addr->sin6_addr); \
michael@0 236 addr = store; \
michael@0 237 } \
michael@0 238 } \
michael@0 239 } while (0)
michael@0 240 #else
michael@0 241 #define sctp_recover_scope_mac(addr, store) do { \
michael@0 242 if ((addr->sin6_family == AF_INET6) && \
michael@0 243 (IN6_IS_SCOPE_LINKLOCAL(&addr->sin6_addr))) { \
michael@0 244 *store = *addr; \
michael@0 245 if (addr->sin6_scope_id == 0) { \
michael@0 246 if (!in6_recoverscope(store, &store->sin6_addr, \
michael@0 247 NULL)) { \
michael@0 248 addr = store; \
michael@0 249 } \
michael@0 250 } else { \
michael@0 251 in6_clearscope(&addr->sin6_addr); \
michael@0 252 addr = store; \
michael@0 253 } \
michael@0 254 } \
michael@0 255 } while (0)
michael@0 256 #endif
michael@0 257 #endif
michael@0 258 #endif
michael@0 259
michael@0 260 int sctp_cmpaddr(struct sockaddr *, struct sockaddr *);
michael@0 261
michael@0 262 void sctp_print_address(struct sockaddr *);
michael@0 263
michael@0 264 int
michael@0 265 sctp_release_pr_sctp_chunk(struct sctp_tcb *, struct sctp_tmit_chunk *,
michael@0 266 uint8_t, int
michael@0 267 #if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
michael@0 268 SCTP_UNUSED
michael@0 269 #endif
michael@0 270 );
michael@0 271
michael@0 272 struct mbuf *sctp_generate_invmanparam(int);
michael@0 273
michael@0 274 void sctp_bindx_add_address(struct socket *so, struct sctp_inpcb *inp,
michael@0 275 struct sockaddr *sa, sctp_assoc_t assoc_id,
michael@0 276 uint32_t vrf_id, int *error, void *p);
michael@0 277 void sctp_bindx_delete_address(struct sctp_inpcb *inp,
michael@0 278 struct sockaddr *sa, sctp_assoc_t assoc_id,
michael@0 279 uint32_t vrf_id, int *error);
michael@0 280
michael@0 281 int sctp_local_addr_count(struct sctp_tcb *stcb);
michael@0 282
michael@0 283 #ifdef SCTP_MBCNT_LOGGING
michael@0 284 void
michael@0 285 sctp_free_bufspace(struct sctp_tcb *, struct sctp_association *,
michael@0 286 struct sctp_tmit_chunk *, int);
michael@0 287
michael@0 288 #else
michael@0 289 #define sctp_free_bufspace(stcb, asoc, tp1, chk_cnt) \
michael@0 290 do { \
michael@0 291 if (tp1->data != NULL) { \
michael@0 292 atomic_subtract_int(&((asoc)->chunks_on_out_queue), chk_cnt); \
michael@0 293 if ((asoc)->total_output_queue_size >= tp1->book_size) { \
michael@0 294 atomic_subtract_int(&((asoc)->total_output_queue_size), tp1->book_size); \
michael@0 295 } else { \
michael@0 296 (asoc)->total_output_queue_size = 0; \
michael@0 297 } \
michael@0 298 if (stcb->sctp_socket && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \
michael@0 299 (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \
michael@0 300 if (stcb->sctp_socket->so_snd.sb_cc >= tp1->book_size) { \
michael@0 301 atomic_subtract_int(&((stcb)->sctp_socket->so_snd.sb_cc), tp1->book_size); \
michael@0 302 } else { \
michael@0 303 stcb->sctp_socket->so_snd.sb_cc = 0; \
michael@0 304 } \
michael@0 305 } \
michael@0 306 } \
michael@0 307 } while (0)
michael@0 308
michael@0 309 #endif
michael@0 310
michael@0 311 #define sctp_free_spbufspace(stcb, asoc, sp) \
michael@0 312 do { \
michael@0 313 if (sp->data != NULL) { \
michael@0 314 if ((asoc)->total_output_queue_size >= sp->length) { \
michael@0 315 atomic_subtract_int(&(asoc)->total_output_queue_size, sp->length); \
michael@0 316 } else { \
michael@0 317 (asoc)->total_output_queue_size = 0; \
michael@0 318 } \
michael@0 319 if (stcb->sctp_socket && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \
michael@0 320 (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \
michael@0 321 if (stcb->sctp_socket->so_snd.sb_cc >= sp->length) { \
michael@0 322 atomic_subtract_int(&stcb->sctp_socket->so_snd.sb_cc,sp->length); \
michael@0 323 } else { \
michael@0 324 stcb->sctp_socket->so_snd.sb_cc = 0; \
michael@0 325 } \
michael@0 326 } \
michael@0 327 } \
michael@0 328 } while (0)
michael@0 329
michael@0 330 #define sctp_snd_sb_alloc(stcb, sz) \
michael@0 331 do { \
michael@0 332 atomic_add_int(&stcb->asoc.total_output_queue_size,sz); \
michael@0 333 if ((stcb->sctp_socket != NULL) && \
michael@0 334 ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) || \
michael@0 335 (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) { \
michael@0 336 atomic_add_int(&stcb->sctp_socket->so_snd.sb_cc,sz); \
michael@0 337 } \
michael@0 338 } while (0)
michael@0 339
michael@0 340 /* functions to start/stop udp tunneling */
michael@0 341 #if defined(__APPLE__) || defined(__FreeBSD__)
michael@0 342 void sctp_over_udp_stop(void);
michael@0 343 int sctp_over_udp_start(void);
michael@0 344 #endif
michael@0 345 #if defined(__Windows__)
michael@0 346 void sctp_over_udp_restart(void);
michael@0 347 #endif
michael@0 348
michael@0 349 int
michael@0 350 sctp_soreceive(struct socket *so, struct sockaddr **psa,
michael@0 351 struct uio *uio,
michael@0 352 struct mbuf **mp0,
michael@0 353 struct mbuf **controlp,
michael@0 354 int *flagsp);
michael@0 355
michael@0 356 void
michael@0 357 sctp_misc_ints(uint8_t from, uint32_t a, uint32_t b, uint32_t c, uint32_t d);
michael@0 358
michael@0 359 void
michael@0 360 sctp_wakeup_log(struct sctp_tcb *stcb,
michael@0 361 uint32_t wake_cnt, int from);
michael@0 362
michael@0 363 void sctp_log_strm_del_alt(struct sctp_tcb *stcb, uint32_t, uint16_t, uint16_t, int);
michael@0 364
michael@0 365 void sctp_log_nagle_event(struct sctp_tcb *stcb, int action);
michael@0 366
michael@0 367
michael@0 368 void
michael@0 369 sctp_log_mb(struct mbuf *m, int from);
michael@0 370
michael@0 371 void
michael@0 372 sctp_sblog(struct sockbuf *sb,
michael@0 373 struct sctp_tcb *stcb, int from, int incr);
michael@0 374
michael@0 375 void
michael@0 376 sctp_log_strm_del(struct sctp_queued_to_read *control,
michael@0 377 struct sctp_queued_to_read *poschk,
michael@0 378 int from);
michael@0 379 void sctp_log_cwnd(struct sctp_tcb *stcb, struct sctp_nets *, int, uint8_t);
michael@0 380 void rto_logging(struct sctp_nets *net, int from);
michael@0 381
michael@0 382 void sctp_log_closing(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int16_t loc);
michael@0 383
michael@0 384 void sctp_log_lock(struct sctp_inpcb *inp, struct sctp_tcb *stcb, uint8_t from);
michael@0 385 void sctp_log_maxburst(struct sctp_tcb *stcb, struct sctp_nets *, int, int, uint8_t);
michael@0 386 void sctp_log_block(uint8_t, struct sctp_association *, int);
michael@0 387 void sctp_log_rwnd(uint8_t, uint32_t, uint32_t, uint32_t);
michael@0 388 void sctp_log_mbcnt(uint8_t, uint32_t, uint32_t, uint32_t, uint32_t);
michael@0 389 void sctp_log_rwnd_set(uint8_t, uint32_t, uint32_t, uint32_t, uint32_t);
michael@0 390 int sctp_fill_stat_log(void *, size_t *);
michael@0 391 void sctp_log_fr(uint32_t, uint32_t, uint32_t, int);
michael@0 392 void sctp_log_sack(uint32_t, uint32_t, uint32_t, uint16_t, uint16_t, int);
michael@0 393 void sctp_log_map(uint32_t, uint32_t, uint32_t, int);
michael@0 394 void sctp_print_mapping_array(struct sctp_association *asoc);
michael@0 395 void sctp_clr_stat_log(void);
michael@0 396
michael@0 397
michael@0 398 #ifdef SCTP_AUDITING_ENABLED
michael@0 399 void
michael@0 400 sctp_auditing(int, struct sctp_inpcb *, struct sctp_tcb *,
michael@0 401 struct sctp_nets *);
michael@0 402 void sctp_audit_log(uint8_t, uint8_t);
michael@0 403
michael@0 404 #endif
michael@0 405 #endif /* _KERNEL */
michael@0 406 #endif

mercurial