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.
1 /*-
2 * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
4 * Copyright (c) 2008-2012, 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 */
33 #ifdef __FreeBSD__
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD: head/sys/netinet/sctp_pcb.h 254248 2013-08-12 13:52:15Z tuexen $");
36 #endif
38 #ifndef _NETINET_SCTP_PCB_H_
39 #define _NETINET_SCTP_PCB_H_
41 #include <netinet/sctp_os.h>
42 #include <netinet/sctp.h>
43 #include <netinet/sctp_constants.h>
44 #include <netinet/sctp_sysctl.h>
46 LIST_HEAD(sctppcbhead, sctp_inpcb);
47 LIST_HEAD(sctpasochead, sctp_tcb);
48 LIST_HEAD(sctpladdr, sctp_laddr);
49 LIST_HEAD(sctpvtaghead, sctp_tagblock);
50 LIST_HEAD(sctp_vrflist, sctp_vrf);
51 LIST_HEAD(sctp_ifnlist, sctp_ifn);
52 LIST_HEAD(sctp_ifalist, sctp_ifa);
53 TAILQ_HEAD(sctp_readhead, sctp_queued_to_read);
54 TAILQ_HEAD(sctp_streamhead, sctp_stream_queue_pending);
56 #include <netinet/sctp_structs.h>
57 #include <netinet/sctp_auth.h>
59 #define SCTP_PCBHASH_ALLADDR(port, mask) (port & mask)
60 #define SCTP_PCBHASH_ASOC(tag, mask) (tag & mask)
62 struct sctp_vrf {
63 LIST_ENTRY (sctp_vrf) next_vrf;
64 struct sctp_ifalist *vrf_addr_hash;
65 struct sctp_ifnlist ifnlist;
66 uint32_t vrf_id;
67 uint32_t tbl_id_v4; /* default v4 table id */
68 uint32_t tbl_id_v6; /* default v6 table id */
69 uint32_t total_ifa_count;
70 u_long vrf_addr_hashmark;
71 uint32_t refcount;
72 };
74 struct sctp_ifn {
75 struct sctp_ifalist ifalist;
76 struct sctp_vrf *vrf;
77 LIST_ENTRY(sctp_ifn) next_ifn;
78 LIST_ENTRY(sctp_ifn) next_bucket;
79 void *ifn_p; /* never access without appropriate lock */
80 uint32_t ifn_mtu;
81 uint32_t ifn_type;
82 uint32_t ifn_index; /* shorthand way to look at ifn for reference */
83 uint32_t refcount; /* number of reference held should be >= ifa_count */
84 uint32_t ifa_count; /* IFA's we hold (in our list - ifalist)*/
85 uint32_t num_v6; /* number of v6 addresses */
86 uint32_t num_v4; /* number of v4 addresses */
87 uint32_t registered_af; /* registered address family for i/f events */
88 char ifn_name[SCTP_IFNAMSIZ];
89 };
91 /* SCTP local IFA flags */
92 #define SCTP_ADDR_VALID 0x00000001 /* its up and active */
93 #define SCTP_BEING_DELETED 0x00000002 /* being deleted,
94 * when refcount = 0. Note
95 * that it is pulled from the ifn list
96 * and ifa_p is nulled right away but
97 * it cannot be freed until the last *net
98 * pointing to it is deleted.
99 */
100 #define SCTP_ADDR_DEFER_USE 0x00000004 /* Hold off using this one */
101 #define SCTP_ADDR_IFA_UNUSEABLE 0x00000008
103 struct sctp_ifa {
104 LIST_ENTRY(sctp_ifa) next_ifa;
105 LIST_ENTRY(sctp_ifa) next_bucket;
106 struct sctp_ifn *ifn_p; /* back pointer to parent ifn */
107 void *ifa; /* pointer to ifa, needed for flag
108 * update for that we MUST lock
109 * appropriate locks. This is for V6.
110 */
111 union sctp_sockstore address;
112 uint32_t refcount; /* number of folks refering to this */
113 uint32_t flags;
114 uint32_t localifa_flags;
115 uint32_t vrf_id; /* vrf_id of this addr (for deleting) */
116 uint8_t src_is_loop;
117 uint8_t src_is_priv;
118 uint8_t src_is_glob;
119 uint8_t resv;
120 };
122 struct sctp_laddr {
123 LIST_ENTRY(sctp_laddr) sctp_nxt_addr; /* next in list */
124 struct sctp_ifa *ifa;
125 uint32_t action; /* Used during asconf and adding
126 * if no-zero src-addr selection will
127 * not consider this address.
128 */
129 struct timeval start_time; /* time when this address was created */
130 };
132 struct sctp_block_entry {
133 int error;
134 };
136 struct sctp_timewait {
137 uint32_t tv_sec_at_expire; /* the seconds from boot to expire */
138 uint32_t v_tag; /* the vtag that can not be reused */
139 uint16_t lport; /* the local port used in vtag */
140 uint16_t rport; /* the remote port used in vtag */
141 };
143 struct sctp_tagblock {
144 LIST_ENTRY(sctp_tagblock) sctp_nxt_tagblock;
145 struct sctp_timewait vtag_block[SCTP_NUMBER_IN_VTAG_BLOCK];
146 };
149 struct sctp_epinfo {
150 #if defined(__FreeBSD__)
151 #ifdef INET
152 struct socket *udp4_tun_socket;
153 #endif
154 #ifdef INET6
155 struct socket *udp6_tun_socket;
156 #endif
157 #endif
158 struct sctpasochead *sctp_asochash;
159 u_long hashasocmark;
161 struct sctppcbhead *sctp_ephash;
162 u_long hashmark;
164 /*-
165 * The TCP model represents a substantial overhead in that we get an
166 * additional hash table to keep explicit connections in. The
167 * listening TCP endpoint will exist in the usual ephash above and
168 * accept only INIT's. It will be incapable of sending off an INIT.
169 * When a dg arrives we must look in the normal ephash. If we find a
170 * TCP endpoint that will tell us to go to the specific endpoint
171 * hash and re-hash to find the right assoc/socket. If we find a UDP
172 * model socket we then must complete the lookup. If this fails,
173 * i.e. no association can be found then we must continue to see if
174 * a sctp_peeloff()'d socket is in the tcpephash (a spun off socket
175 * acts like a TCP model connected socket).
176 */
177 struct sctppcbhead *sctp_tcpephash;
178 u_long hashtcpmark;
179 uint32_t hashtblsize;
181 struct sctp_vrflist *sctp_vrfhash;
182 u_long hashvrfmark;
184 struct sctp_ifnlist *vrf_ifn_hash;
185 u_long vrf_ifn_hashmark;
187 struct sctppcbhead listhead;
188 struct sctpladdr addr_wq;
190 #if defined(__APPLE__)
191 struct inpcbhead inplisthead;
192 struct inpcbinfo sctbinfo;
193 #endif
194 /* ep zone info */
195 sctp_zone_t ipi_zone_ep;
196 sctp_zone_t ipi_zone_asoc;
197 sctp_zone_t ipi_zone_laddr;
198 sctp_zone_t ipi_zone_net;
199 sctp_zone_t ipi_zone_chunk;
200 sctp_zone_t ipi_zone_readq;
201 sctp_zone_t ipi_zone_strmoq;
202 sctp_zone_t ipi_zone_asconf;
203 sctp_zone_t ipi_zone_asconf_ack;
205 #if defined(__FreeBSD__) && __FreeBSD_version >= 503000
206 #if __FreeBSD_version <= 602000
207 struct mtx ipi_ep_mtx;
208 #else
209 struct rwlock ipi_ep_mtx;
210 #endif
211 struct mtx ipi_iterator_wq_mtx;
212 #if __FreeBSD_version <= 602000
213 struct mtx ipi_addr_mtx;
214 #else
215 struct rwlock ipi_addr_mtx;
216 #endif
217 struct mtx ipi_pktlog_mtx;
218 struct mtx wq_addr_mtx;
219 #elif defined(SCTP_PROCESS_LEVEL_LOCKS)
220 userland_mutex_t ipi_ep_mtx;
221 userland_mutex_t ipi_addr_mtx;
222 userland_mutex_t ipi_count_mtx;
223 userland_mutex_t ipi_pktlog_mtx;
224 userland_mutex_t wq_addr_mtx;
225 #elif defined(__APPLE__)
226 #ifdef _KERN_LOCKS_H_
227 lck_mtx_t *ipi_addr_mtx;
228 lck_mtx_t *ipi_count_mtx;
229 lck_mtx_t *ipi_pktlog_mtx;
230 lck_mtx_t *logging_mtx;
231 lck_mtx_t *wq_addr_mtx;
232 #else
233 void *ipi_count_mtx;
234 void *logging_mtx;
235 #endif /* _KERN_LOCKS_H_ */
236 #elif defined(__Windows__)
237 struct rwlock ipi_ep_lock;
238 struct rwlock ipi_addr_lock;
239 struct spinlock ipi_pktlog_mtx;
240 struct rwlock wq_addr_mtx;
241 #elif defined(__Userspace__)
242 /* TODO decide on __Userspace__ locks */
243 #endif
244 uint32_t ipi_count_ep;
246 /* assoc/tcb zone info */
247 uint32_t ipi_count_asoc;
249 /* local addrlist zone info */
250 uint32_t ipi_count_laddr;
252 /* remote addrlist zone info */
253 uint32_t ipi_count_raddr;
255 /* chunk structure list for output */
256 uint32_t ipi_count_chunk;
258 /* socket queue zone info */
259 uint32_t ipi_count_readq;
261 /* socket queue zone info */
262 uint32_t ipi_count_strmoq;
264 /* Number of vrfs */
265 uint32_t ipi_count_vrfs;
267 /* Number of ifns */
268 uint32_t ipi_count_ifns;
270 /* Number of ifas */
271 uint32_t ipi_count_ifas;
273 /* system wide number of free chunks hanging around */
274 uint32_t ipi_free_chunks;
275 uint32_t ipi_free_strmoq;
277 struct sctpvtaghead vtag_timewait[SCTP_STACK_VTAG_HASH_SIZE];
279 /* address work queue handling */
280 struct sctp_timer addr_wq_timer;
282 #if defined(_SCTP_NEEDS_CALLOUT_) || defined(_USER_SCTP_NEEDS_CALLOUT_)
283 struct calloutlist callqueue;
284 #endif
285 };
288 struct sctp_base_info {
289 /* All static structures that
290 * anchor the system must be here.
291 */
292 struct sctp_epinfo sctppcbinfo;
293 #if defined(__FreeBSD__) && defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
294 struct sctpstat *sctpstat;
295 #else
296 struct sctpstat sctpstat;
297 #endif
298 struct sctp_sysctl sctpsysctl;
299 uint8_t first_time;
300 char sctp_pcb_initialized;
301 #if defined(SCTP_PACKET_LOGGING)
302 int packet_log_writers;
303 int packet_log_end;
304 uint8_t packet_log_buffer[SCTP_PACKET_LOG_SIZE];
305 #endif
306 #if defined(__APPLE__)
307 int sctp_main_timer_ticks;
308 #endif
309 #if defined(__Userspace__)
310 userland_mutex_t timer_mtx;
311 userland_thread_t timer_thread;
312 uint8_t timer_thread_should_exit;
313 #if !defined(__Userspace_os_Windows)
314 #if defined(INET) || defined(INET6)
315 int userspace_route;
316 userland_thread_t recvthreadroute;
317 #endif
318 #endif
319 #ifdef INET
320 int userspace_rawsctp;
321 int userspace_udpsctp;
322 userland_thread_t recvthreadraw;
323 userland_thread_t recvthreadudp;
324 #endif
325 #ifdef INET6
326 int userspace_rawsctp6;
327 int userspace_udpsctp6;
328 userland_thread_t recvthreadraw6;
329 userland_thread_t recvthreadudp6;
330 #endif
331 int (*conn_output)(void *addr, void *buffer, size_t length, uint8_t tos, uint8_t set_df);
332 void (*debug_printf)(const char *format, ...);
333 #endif
334 };
336 /*-
337 * Here we have all the relevant information for each SCTP entity created. We
338 * will need to modify this as approprate. We also need to figure out how to
339 * access /dev/random.
340 */
341 struct sctp_pcb {
342 unsigned int time_of_secret_change; /* number of seconds from
343 * timeval.tv_sec */
344 uint32_t secret_key[SCTP_HOW_MANY_SECRETS][SCTP_NUMBER_OF_SECRETS];
345 unsigned int size_of_a_cookie;
347 unsigned int sctp_timeoutticks[SCTP_NUM_TMRS];
348 unsigned int sctp_minrto;
349 unsigned int sctp_maxrto;
350 unsigned int initial_rto;
351 int initial_init_rto_max;
353 unsigned int sctp_sack_freq;
354 uint32_t sctp_sws_sender;
355 uint32_t sctp_sws_receiver;
357 uint32_t sctp_default_cc_module;
358 uint32_t sctp_default_ss_module;
359 /* authentication related fields */
360 struct sctp_keyhead shared_keys;
361 sctp_auth_chklist_t *local_auth_chunks;
362 sctp_hmaclist_t *local_hmacs;
363 uint16_t default_keyid;
365 /* various thresholds */
366 /* Max times I will init at a guy */
367 uint16_t max_init_times;
369 /* Max times I will send before we consider someone dead */
370 uint16_t max_send_times;
372 uint16_t def_net_failure;
374 uint16_t def_net_pf_threshold;
376 /* number of streams to pre-open on a association */
377 uint16_t pre_open_stream_count;
378 uint16_t max_open_streams_intome;
380 /* random number generator */
381 uint32_t random_counter;
382 uint8_t random_numbers[SCTP_SIGNATURE_ALOC_SIZE];
383 uint8_t random_store[SCTP_SIGNATURE_ALOC_SIZE];
385 /*
386 * This timer is kept running per endpoint. When it fires it will
387 * change the secret key. The default is once a hour
388 */
389 struct sctp_timer signature_change;
391 /* Zero copy full buffer timer */
392 struct sctp_timer zero_copy_timer;
393 /* Zero copy app to transport (sendq) read repulse timer */
394 struct sctp_timer zero_copy_sendq_timer;
395 uint32_t def_cookie_life;
396 /* defaults to 0 */
397 int auto_close_time;
398 uint32_t initial_sequence_debug;
399 uint32_t adaptation_layer_indicator;
400 uint8_t adaptation_layer_indicator_provided;
401 uint32_t store_at;
402 uint32_t max_burst;
403 uint32_t fr_max_burst;
404 #ifdef INET6
405 uint32_t default_flowlabel;
406 #endif
407 uint8_t default_dscp;
408 char current_secret_number;
409 char last_secret_number;
410 uint16_t port; /* remote UDP encapsulation port */
411 };
413 #ifndef SCTP_ALIGNMENT
414 #define SCTP_ALIGNMENT 32
415 #endif
417 #ifndef SCTP_ALIGNM1
418 #define SCTP_ALIGNM1 (SCTP_ALIGNMENT-1)
419 #endif
421 #define sctp_lport ip_inp.inp.inp_lport
423 struct sctp_pcbtsn_rlog {
424 uint32_t vtag;
425 uint16_t strm;
426 uint16_t seq;
427 uint16_t sz;
428 uint16_t flgs;
429 };
430 #define SCTP_READ_LOG_SIZE 135 /* we choose the number to make a pcb a page */
433 struct sctp_inpcb {
434 /*-
435 * put an inpcb in front of it all, kind of a waste but we need to
436 * for compatability with all the other stuff.
437 */
438 union {
439 struct inpcb inp;
440 char align[(sizeof(struct in6pcb) + SCTP_ALIGNM1) &
441 ~SCTP_ALIGNM1];
442 } ip_inp;
444 #if defined(__APPLE__)
445 /* leave some space in case i386 inpcb is bigger than ppc */
446 uint8_t padding[128];
447 #endif
449 /* Socket buffer lock protects read_queue and of course sb_cc */
450 struct sctp_readhead read_queue;
452 LIST_ENTRY(sctp_inpcb) sctp_list; /* lists all endpoints */
453 /* hash of all endpoints for model */
454 LIST_ENTRY(sctp_inpcb) sctp_hash;
455 /* count of local addresses bound, 0 if bound all */
456 int laddr_count;
458 /* list of addrs in use by the EP, NULL if bound-all */
459 struct sctpladdr sctp_addr_list;
460 /* used for source address selection rotation when we are subset bound */
461 struct sctp_laddr *next_addr_touse;
463 /* back pointer to our socket */
464 struct socket *sctp_socket;
465 uint64_t sctp_features; /* Feature flags */
466 uint32_t sctp_flags; /* INP state flag set */
467 uint32_t sctp_mobility_features; /* Mobility Feature flags */
468 struct sctp_pcb sctp_ep;/* SCTP ep data */
469 /* head of the hash of all associations */
470 struct sctpasochead *sctp_tcbhash;
471 u_long sctp_hashmark;
472 /* head of the list of all associations */
473 struct sctpasochead sctp_asoc_list;
474 #ifdef SCTP_TRACK_FREED_ASOCS
475 struct sctpasochead sctp_asoc_free_list;
476 #endif
477 struct sctp_iterator *inp_starting_point_for_iterator;
478 uint32_t sctp_frag_point;
479 uint32_t partial_delivery_point;
480 uint32_t sctp_context;
481 uint8_t local_strreset_support;
482 uint32_t sctp_cmt_on_off;
483 uint32_t sctp_ecn_enable;
484 struct sctp_nonpad_sndrcvinfo def_send;
485 /*-
486 * These three are here for the sosend_dgram
487 * (pkt, pkt_last and control).
488 * routine. However, I don't think anyone in
489 * the current FreeBSD kernel calls this. So
490 * they are candidates with sctp_sendm for
491 * de-supporting.
492 */
493 #ifdef __Panda__
494 pakhandle_type pak_to_read;
495 pakhandle_type pak_to_read_sendq;
496 #endif
497 struct mbuf *pkt, *pkt_last;
498 struct mbuf *control;
499 #if !(defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__))
500 #ifndef INP_IPV6
501 #define INP_IPV6 0x1
502 #endif
503 #ifndef INP_IPV4
504 #define INP_IPV4 0x2
505 #endif
506 uint8_t inp_vflag;
507 /* TODO __Userspace__ where is our inp_vlag going to be? */
508 uint8_t inp_ip_ttl;
509 uint8_t inp_ip_tos; /* defined as macro in user_inpcb.h */
510 uint8_t inp_ip_resv;
511 #endif
512 #if defined(__FreeBSD__) && __FreeBSD_version >= 503000
513 struct mtx inp_mtx;
514 struct mtx inp_create_mtx;
515 struct mtx inp_rdata_mtx;
516 int32_t refcount;
517 #elif defined(SCTP_PROCESS_LEVEL_LOCKS)
518 userland_mutex_t inp_mtx;
519 userland_mutex_t inp_create_mtx;
520 userland_mutex_t inp_rdata_mtx;
521 int32_t refcount;
522 #elif defined(__APPLE__)
523 #if defined(SCTP_APPLE_RWLOCK)
524 lck_rw_t *inp_mtx;
525 #else
526 lck_mtx_t *inp_mtx;
527 #endif
528 lck_mtx_t *inp_create_mtx;
529 lck_mtx_t *inp_rdata_mtx;
530 #elif defined(__Windows__)
531 struct rwlock inp_lock;
532 struct spinlock inp_create_lock;
533 struct spinlock inp_rdata_lock;
534 int32_t refcount;
535 #elif defined(__Userspace__)
536 /* TODO decide on __Userspace__ locks */
537 int32_t refcount;
538 #endif
539 #if defined(__APPLE__)
540 int32_t refcount;
542 uint32_t lock_caller1;
543 uint32_t lock_caller2;
544 uint32_t lock_caller3;
545 uint32_t unlock_caller1;
546 uint32_t unlock_caller2;
547 uint32_t unlock_caller3;
548 uint32_t getlock_caller1;
549 uint32_t getlock_caller2;
550 uint32_t getlock_caller3;
551 uint32_t gen_count;
552 uint32_t lock_gen_count;
553 uint32_t unlock_gen_count;
554 uint32_t getlock_gen_count;
556 uint32_t i_am_here_file;
557 uint32_t i_am_here_line;
558 #endif
559 uint32_t def_vrf_id;
560 #ifdef SCTP_MVRF
561 uint32_t *m_vrf_ids;
562 uint32_t num_vrfs;
563 uint32_t vrf_size;
564 #endif
565 uint32_t total_sends;
566 uint32_t total_recvs;
567 uint32_t last_abort_code;
568 uint32_t total_nospaces;
569 struct sctpasochead *sctp_asocidhash;
570 u_long hashasocidmark;
571 uint32_t sctp_associd_counter;
573 #ifdef SCTP_ASOCLOG_OF_TSNS
574 struct sctp_pcbtsn_rlog readlog[SCTP_READ_LOG_SIZE];
575 uint32_t readlog_index;
576 #endif
577 #if defined(__Userspace__)
578 void *ulp_info;
579 int (*recv_callback)(struct socket *, union sctp_sockstore, void *, size_t,
580 struct sctp_rcvinfo, int, void *);
581 uint32_t send_sb_threshold;
582 int (*send_callback)(struct socket *, uint32_t);
583 #endif
584 };
586 #if defined(__Userspace__)
587 int register_recv_cb (struct socket *,
588 int (*)(struct socket *, union sctp_sockstore, void *, size_t,
589 struct sctp_rcvinfo, int, void *));
590 int register_send_cb (struct socket *, uint32_t, int (*)(struct socket *, uint32_t));
591 int register_ulp_info (struct socket *, void *);
593 #endif
594 struct sctp_tcb {
595 struct socket *sctp_socket; /* back pointer to socket */
596 struct sctp_inpcb *sctp_ep; /* back pointer to ep */
597 LIST_ENTRY(sctp_tcb) sctp_tcbhash; /* next link in hash
598 * table */
599 LIST_ENTRY(sctp_tcb) sctp_tcblist; /* list of all of the
600 * TCB's */
601 LIST_ENTRY(sctp_tcb) sctp_tcbasocidhash; /* next link in asocid
602 * hash table
603 */
604 LIST_ENTRY(sctp_tcb) sctp_asocs; /* vtag hash list */
605 struct sctp_block_entry *block_entry; /* pointer locked by socket
606 * send buffer */
607 struct sctp_association asoc;
608 /*-
609 * freed_by_sorcv_sincelast is protected by the sockbuf_lock NOT the
610 * tcb_lock. Its special in this way to help avoid extra mutex calls
611 * in the reading of data.
612 */
613 uint32_t freed_by_sorcv_sincelast;
614 uint32_t total_sends;
615 uint32_t total_recvs;
616 int freed_from_where;
617 uint16_t rport; /* remote port in network format */
618 uint16_t resv;
619 #if defined(__FreeBSD__) && __FreeBSD_version >= 503000
620 struct mtx tcb_mtx;
621 struct mtx tcb_send_mtx;
622 #elif defined(SCTP_PROCESS_LEVEL_LOCKS)
623 userland_mutex_t tcb_mtx;
624 userland_mutex_t tcb_send_mtx;
625 #elif defined(__APPLE__)
626 lck_mtx_t* tcb_mtx;
627 lck_mtx_t* tcb_send_mtx;
628 #elif defined(__Windows__)
629 struct spinlock tcb_lock;
630 struct spinlock tcb_send_lock;
631 #elif defined(__Userspace__)
632 /* TODO decide on __Userspace__ locks */
633 #endif
634 #if defined(__APPLE__)
635 uint32_t caller1;
636 uint32_t caller2;
637 uint32_t caller3;
638 #endif
639 };
642 #if defined(__FreeBSD__) && __FreeBSD_version >= 503000
644 #include <netinet/sctp_lock_bsd.h>
646 #elif defined(__APPLE__)
647 /*
648 * Apple MacOS X 10.4 "Tiger"
649 */
651 #include <netinet/sctp_lock_apple_fg.h>
653 #elif defined(SCTP_PROCESS_LEVEL_LOCKS)
655 #include <netinet/sctp_process_lock.h>
657 #elif defined(__Windows__)
659 #include <netinet/sctp_lock_windows.h>
661 #elif defined(__Userspace__)
663 #include <netinet/sctp_lock_userspace.h>
665 #else
666 /*
667 * Pre-5.x FreeBSD, and others.
668 */
669 #include <netinet/sctp_lock_empty.h>
670 #endif
672 /* TODO where to put non-_KERNEL things for __Userspace__? */
673 #if defined(_KERNEL) || defined(__Userspace__)
675 /* Attention Julian, this is the extern that
676 * goes with the base info. sctp_pcb.c has
677 * the real definition.
678 */
679 #if defined(__FreeBSD__) && __FreeBSD_version >= 801000
680 VNET_DECLARE(struct sctp_base_info, system_base_info) ;
681 #else
682 extern struct sctp_base_info system_base_info;
683 #endif
685 #ifdef INET6
686 int SCTP6_ARE_ADDR_EQUAL(struct sockaddr_in6 *a, struct sockaddr_in6 *b);
687 #endif
689 void sctp_fill_pcbinfo(struct sctp_pcbinfo *);
691 struct sctp_ifn *
692 sctp_find_ifn(void *ifn, uint32_t ifn_index);
694 struct sctp_vrf *sctp_allocate_vrf(int vrfid);
695 struct sctp_vrf *sctp_find_vrf(uint32_t vrfid);
696 void sctp_free_vrf(struct sctp_vrf *vrf);
698 /*-
699 * Change address state, can be used if
700 * O/S supports telling transports about
701 * changes to IFA/IFN's (link layer triggers).
702 * If a ifn goes down, we will do src-addr-selection
703 * and NOT use that, as a source address. This does
704 * not stop the routing system from routing out
705 * that interface, but we won't put it as a source.
706 */
707 void sctp_mark_ifa_addr_down(uint32_t vrf_id, struct sockaddr *addr, const char *if_name, uint32_t ifn_index);
708 void sctp_mark_ifa_addr_up(uint32_t vrf_id, struct sockaddr *addr, const char *if_name, uint32_t ifn_index);
710 struct sctp_ifa *
711 sctp_add_addr_to_vrf(uint32_t vrfid,
712 void *ifn, uint32_t ifn_index, uint32_t ifn_type,
713 const char *if_name,
714 void *ifa, struct sockaddr *addr, uint32_t ifa_flags,
715 int dynamic_add);
717 void sctp_update_ifn_mtu(uint32_t ifn_index, uint32_t mtu);
719 void sctp_free_ifn(struct sctp_ifn *sctp_ifnp);
720 void sctp_free_ifa(struct sctp_ifa *sctp_ifap);
723 void sctp_del_addr_from_vrf(uint32_t vrfid, struct sockaddr *addr,
724 uint32_t ifn_index, const char *if_name);
728 struct sctp_nets *sctp_findnet(struct sctp_tcb *, struct sockaddr *);
730 struct sctp_inpcb *sctp_pcb_findep(struct sockaddr *, int, int, uint32_t);
732 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
733 int sctp_inpcb_bind(struct socket *, struct sockaddr *,
734 struct sctp_ifa *,struct thread *);
735 #elif defined(__Windows__)
736 int sctp_inpcb_bind(struct socket *, struct sockaddr *,
737 struct sctp_ifa *,PKTHREAD);
738 #else
739 /* struct proc is a dummy for __Userspace__ */
740 int sctp_inpcb_bind(struct socket *, struct sockaddr *,
741 struct sctp_ifa *, struct proc *);
742 #endif
744 struct sctp_tcb *
745 sctp_findassociation_addr(struct mbuf *, int,
746 struct sockaddr *, struct sockaddr *,
747 struct sctphdr *, struct sctp_chunkhdr *, struct sctp_inpcb **,
748 struct sctp_nets **, uint32_t vrf_id);
750 struct sctp_tcb *
751 sctp_findassociation_addr_sa(struct sockaddr *,
752 struct sockaddr *, struct sctp_inpcb **, struct sctp_nets **, int, uint32_t);
754 void
755 sctp_move_pcb_and_assoc(struct sctp_inpcb *, struct sctp_inpcb *,
756 struct sctp_tcb *);
758 /*-
759 * For this call ep_addr, the to is the destination endpoint address of the
760 * peer (relative to outbound). The from field is only used if the TCP model
761 * is enabled and helps distingush amongst the subset bound (non-boundall).
762 * The TCP model MAY change the actual ep field, this is why it is passed.
763 */
764 struct sctp_tcb *
765 sctp_findassociation_ep_addr(struct sctp_inpcb **,
766 struct sockaddr *, struct sctp_nets **, struct sockaddr *,
767 struct sctp_tcb *);
769 struct sctp_tcb *
770 sctp_findasoc_ep_asocid_locked(struct sctp_inpcb *inp, sctp_assoc_t asoc_id, int want_lock);
772 struct sctp_tcb *
773 sctp_findassociation_ep_asocid(struct sctp_inpcb *,
774 sctp_assoc_t, int);
776 struct sctp_tcb *
777 sctp_findassociation_ep_asconf(struct mbuf *, int, struct sockaddr *,
778 struct sctphdr *, struct sctp_inpcb **, struct sctp_nets **, uint32_t vrf_id);
780 int sctp_inpcb_alloc(struct socket *so, uint32_t vrf_id);
782 int sctp_is_address_on_local_host(struct sockaddr *addr, uint32_t vrf_id);
784 void sctp_inpcb_free(struct sctp_inpcb *, int, int);
786 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000
787 struct sctp_tcb *
788 sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *,
789 int *, uint32_t, uint32_t, struct thread *);
790 #elif defined(__Windows__)
791 struct sctp_tcb *
792 sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *,
793 int *, uint32_t, uint32_t, PKTHREAD);
794 #else
795 /* proc will be NULL for __Userspace__ */
796 struct sctp_tcb *
797 sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *,
798 int *, uint32_t, uint32_t, struct proc *);
799 #endif
801 int sctp_free_assoc(struct sctp_inpcb *, struct sctp_tcb *, int, int);
804 void sctp_delete_from_timewait(uint32_t, uint16_t, uint16_t);
806 int sctp_is_in_timewait(uint32_t tag, uint16_t lport, uint16_t rport);
808 void
809 sctp_add_vtag_to_timewait(uint32_t tag, uint32_t time, uint16_t lport, uint16_t rport);
811 void sctp_add_local_addr_ep(struct sctp_inpcb *, struct sctp_ifa *, uint32_t);
813 int sctp_insert_laddr(struct sctpladdr *, struct sctp_ifa *, uint32_t);
815 void sctp_remove_laddr(struct sctp_laddr *);
817 void sctp_del_local_addr_ep(struct sctp_inpcb *, struct sctp_ifa *);
819 int sctp_add_remote_addr(struct sctp_tcb *, struct sockaddr *, struct sctp_nets **, int, int);
821 void sctp_remove_net(struct sctp_tcb *, struct sctp_nets *);
823 int sctp_del_remote_addr(struct sctp_tcb *, struct sockaddr *);
825 void sctp_pcb_init(void);
827 void sctp_pcb_finish(void);
829 void sctp_add_local_addr_restricted(struct sctp_tcb *, struct sctp_ifa *);
830 void sctp_del_local_addr_restricted(struct sctp_tcb *, struct sctp_ifa *);
832 int
833 sctp_load_addresses_from_init(struct sctp_tcb *, struct mbuf *, int, int,
834 struct sockaddr *, struct sockaddr *, struct sockaddr *);
836 int
837 sctp_set_primary_addr(struct sctp_tcb *, struct sockaddr *,
838 struct sctp_nets *);
840 int sctp_is_vtag_good(uint32_t, uint16_t lport, uint16_t rport, struct timeval *);
842 /* void sctp_drain(void); */
844 int sctp_destination_is_reachable(struct sctp_tcb *, struct sockaddr *);
846 int sctp_swap_inpcb_for_listen(struct sctp_inpcb *inp);
848 /*-
849 * Null in last arg inpcb indicate run on ALL ep's. Specific inp in last arg
850 * indicates run on ONLY assoc's of the specified endpoint.
851 */
852 int
853 sctp_initiate_iterator(inp_func inpf,
854 asoc_func af,
855 inp_func inpe,
856 uint32_t, uint32_t,
857 uint32_t, void *,
858 uint32_t,
859 end_func ef,
860 struct sctp_inpcb *,
861 uint8_t co_off);
862 #if defined(__FreeBSD__) && defined(SCTP_MCORE_INPUT) && defined(SMP)
863 void
864 sctp_queue_to_mcore(struct mbuf *m, int off, int cpu_to_use);
866 #endif
868 #ifdef INVARIANTS
869 void
870 sctp_validate_no_locks(struct sctp_inpcb *inp);
871 #endif
873 #endif /* _KERNEL */
874 #endif /* !__sctp_pcb_h__ */