tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

sctp_pcb.h (26870B)


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