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 */ 32 33 #ifdef __FreeBSD__ 34 #include <sys/cdefs.h> 35 __FBSDID("$FreeBSD: head/sys/netinet/sctp_pcb.h 279859 2015-03-10 19:49:25Z tuexen $"); 36 #endif 37 38 #ifndef _NETINET_SCTP_PCB_H_ 39 #define _NETINET_SCTP_PCB_H_ 40 41 #include <netinet/sctp_os.h> 42 #include <netinet/sctp.h> 43 #include <netinet/sctp_constants.h> 44 #include <netinet/sctp_sysctl.h> 45 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); 55 56 #include <netinet/sctp_structs.h> 57 #include <netinet/sctp_auth.h> 58 59 #define SCTP_PCBHASH_ALLADDR(port, mask) (port & mask) 60 #define SCTP_PCBHASH_ASOC(tag, mask) (tag & mask) 61 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 }; 73 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 }; 90 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 102 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 }; 121 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 }; 131 132 struct sctp_block_entry { 133 int error; 134 }; 135 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 }; 142 143 struct sctp_tagblock { 144 LIST_ENTRY(sctp_tagblock) sctp_nxt_tagblock; 145 struct sctp_timewait vtag_block[SCTP_NUMBER_IN_VTAG_BLOCK]; 146 }; 147 148 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; 160 161 struct sctppcbhead *sctp_ephash; 162 u_long hashmark; 163 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; 180 181 struct sctp_vrflist *sctp_vrfhash; 182 u_long hashvrfmark; 183 184 struct sctp_ifnlist *vrf_ifn_hash; 185 u_long vrf_ifn_hashmark; 186 187 struct sctppcbhead listhead; 188 struct sctpladdr addr_wq; 189 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; 204 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; 245 246 /* assoc/tcb zone info */ 247 uint32_t ipi_count_asoc; 248 249 /* local addrlist zone info */ 250 uint32_t ipi_count_laddr; 251 252 /* remote addrlist zone info */ 253 uint32_t ipi_count_raddr; 254 255 /* chunk structure list for output */ 256 uint32_t ipi_count_chunk; 257 258 /* socket queue zone info */ 259 uint32_t ipi_count_readq; 260 261 /* socket queue zone info */ 262 uint32_t ipi_count_strmoq; 263 264 /* Number of vrfs */ 265 uint32_t ipi_count_vrfs; 266 267 /* Number of ifns */ 268 uint32_t ipi_count_ifns; 269 270 /* Number of ifas */ 271 uint32_t ipi_count_ifas; 272 273 /* system wide number of free chunks hanging around */ 274 uint32_t ipi_free_chunks; 275 uint32_t ipi_free_strmoq; 276 277 struct sctpvtaghead vtag_timewait[SCTP_STACK_VTAG_HASH_SIZE]; 278 279 /* address work queue handling */ 280 struct sctp_timer addr_wq_timer; 281 282 #if defined(_SCTP_NEEDS_CALLOUT_) || defined(_USER_SCTP_NEEDS_CALLOUT_) 283 struct calloutlist callqueue; 284 #endif 285 }; 286 287 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 }; 335 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; 346 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; 352 353 unsigned int sctp_sack_freq; 354 uint32_t sctp_sws_sender; 355 uint32_t sctp_sws_receiver; 356 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; 364 365 /* various thresholds */ 366 /* Max times I will init at a guy */ 367 uint16_t max_init_times; 368 369 /* Max times I will send before we consider someone dead */ 370 uint16_t max_send_times; 371 372 uint16_t def_net_failure; 373 374 uint16_t def_net_pf_threshold; 375 376 /* number of streams to pre-open on a association */ 377 uint16_t pre_open_stream_count; 378 uint16_t max_open_streams_intome; 379 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]; 384 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; 390 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 }; 412 413 #ifndef SCTP_ALIGNMENT 414 #define SCTP_ALIGNMENT 32 415 #endif 416 417 #ifndef SCTP_ALIGNM1 418 #define SCTP_ALIGNM1 (SCTP_ALIGNMENT-1) 419 #endif 420 421 #define sctp_lport ip_inp.inp.inp_lport 422 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 */ 431 432 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; 443 444 #if defined(__APPLE__) 445 /* leave some space in case i386 inpcb is bigger than ppc */ 446 uint8_t padding[128]; 447 #endif 448 449 /* Socket buffer lock protects read_queue and of course sb_cc */ 450 struct sctp_readhead read_queue; 451 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; 457 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; 462 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 uint32_t max_cwnd; 482 uint8_t local_strreset_support; 483 uint32_t sctp_cmt_on_off; 484 uint8_t ecn_supported; 485 uint8_t prsctp_supported; 486 uint8_t auth_supported; 487 uint8_t asconf_supported; 488 uint8_t reconfig_supported; 489 uint8_t nrsack_supported; 490 uint8_t pktdrop_supported; 491 struct sctp_nonpad_sndrcvinfo def_send; 492 /*- 493 * These three are here for the sosend_dgram 494 * (pkt, pkt_last and control). 495 * routine. However, I don't think anyone in 496 * the current FreeBSD kernel calls this. So 497 * they are candidates with sctp_sendm for 498 * de-supporting. 499 */ 500 #ifdef __Panda__ 501 pakhandle_type pak_to_read; 502 pakhandle_type pak_to_read_sendq; 503 #endif 504 struct mbuf *pkt, *pkt_last; 505 struct mbuf *control; 506 #if !(defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__)) 507 #ifndef INP_IPV6 508 #define INP_IPV6 0x1 509 #endif 510 #ifndef INP_IPV4 511 #define INP_IPV4 0x2 512 #endif 513 uint8_t inp_vflag; 514 /* TODO __Userspace__ where is our inp_vlag going to be? */ 515 uint8_t inp_ip_ttl; 516 uint8_t inp_ip_tos; /* defined as macro in user_inpcb.h */ 517 uint8_t inp_ip_resv; 518 #endif 519 #if defined(__FreeBSD__) && __FreeBSD_version >= 503000 520 struct mtx inp_mtx; 521 struct mtx inp_create_mtx; 522 struct mtx inp_rdata_mtx; 523 int32_t refcount; 524 #elif defined(SCTP_PROCESS_LEVEL_LOCKS) 525 userland_mutex_t inp_mtx; 526 userland_mutex_t inp_create_mtx; 527 userland_mutex_t inp_rdata_mtx; 528 int32_t refcount; 529 #elif defined(__APPLE__) 530 #if defined(SCTP_APPLE_RWLOCK) 531 lck_rw_t *inp_mtx; 532 #else 533 lck_mtx_t *inp_mtx; 534 #endif 535 lck_mtx_t *inp_create_mtx; 536 lck_mtx_t *inp_rdata_mtx; 537 #elif defined(__Windows__) 538 struct rwlock inp_lock; 539 struct spinlock inp_create_lock; 540 struct spinlock inp_rdata_lock; 541 int32_t refcount; 542 #elif defined(__Userspace__) 543 /* TODO decide on __Userspace__ locks */ 544 int32_t refcount; 545 #endif 546 #if defined(__APPLE__) 547 int32_t refcount; 548 549 uint32_t lock_caller1; 550 uint32_t lock_caller2; 551 uint32_t lock_caller3; 552 uint32_t unlock_caller1; 553 uint32_t unlock_caller2; 554 uint32_t unlock_caller3; 555 uint32_t getlock_caller1; 556 uint32_t getlock_caller2; 557 uint32_t getlock_caller3; 558 uint32_t gen_count; 559 uint32_t lock_gen_count; 560 uint32_t unlock_gen_count; 561 uint32_t getlock_gen_count; 562 563 uint32_t i_am_here_file; 564 uint32_t i_am_here_line; 565 #endif 566 uint32_t def_vrf_id; 567 #ifdef SCTP_MVRF 568 uint32_t *m_vrf_ids; 569 uint32_t num_vrfs; 570 uint32_t vrf_size; 571 #endif 572 uint32_t total_sends; 573 uint32_t total_recvs; 574 uint32_t last_abort_code; 575 uint32_t total_nospaces; 576 struct sctpasochead *sctp_asocidhash; 577 u_long hashasocidmark; 578 uint32_t sctp_associd_counter; 579 580 #ifdef SCTP_ASOCLOG_OF_TSNS 581 struct sctp_pcbtsn_rlog readlog[SCTP_READ_LOG_SIZE]; 582 uint32_t readlog_index; 583 #endif 584 #if defined(__Userspace__) 585 void *ulp_info; 586 int (*recv_callback)(struct socket *, union sctp_sockstore, void *, size_t, 587 struct sctp_rcvinfo, int, void *); 588 uint32_t send_sb_threshold; 589 int (*send_callback)(struct socket *, uint32_t); 590 #endif 591 }; 592 593 #if defined(__Userspace__) 594 int register_recv_cb (struct socket *, 595 int (*)(struct socket *, union sctp_sockstore, void *, size_t, 596 struct sctp_rcvinfo, int, void *)); 597 int register_send_cb (struct socket *, uint32_t, int (*)(struct socket *, uint32_t)); 598 int register_ulp_info (struct socket *, void *); 599 600 #endif 601 struct sctp_tcb { 602 struct socket *sctp_socket; /* back pointer to socket */ 603 struct sctp_inpcb *sctp_ep; /* back pointer to ep */ 604 LIST_ENTRY(sctp_tcb) sctp_tcbhash; /* next link in hash 605 * table */ 606 LIST_ENTRY(sctp_tcb) sctp_tcblist; /* list of all of the 607 * TCB's */ 608 LIST_ENTRY(sctp_tcb) sctp_tcbasocidhash; /* next link in asocid 609 * hash table 610 */ 611 LIST_ENTRY(sctp_tcb) sctp_asocs; /* vtag hash list */ 612 struct sctp_block_entry *block_entry; /* pointer locked by socket 613 * send buffer */ 614 struct sctp_association asoc; 615 /*- 616 * freed_by_sorcv_sincelast is protected by the sockbuf_lock NOT the 617 * tcb_lock. Its special in this way to help avoid extra mutex calls 618 * in the reading of data. 619 */ 620 uint32_t freed_by_sorcv_sincelast; 621 uint32_t total_sends; 622 uint32_t total_recvs; 623 int freed_from_where; 624 uint16_t rport; /* remote port in network format */ 625 uint16_t resv; 626 #if defined(__FreeBSD__) && __FreeBSD_version >= 503000 627 struct mtx tcb_mtx; 628 struct mtx tcb_send_mtx; 629 #elif defined(SCTP_PROCESS_LEVEL_LOCKS) 630 userland_mutex_t tcb_mtx; 631 userland_mutex_t tcb_send_mtx; 632 #elif defined(__APPLE__) 633 lck_mtx_t* tcb_mtx; 634 lck_mtx_t* tcb_send_mtx; 635 #elif defined(__Windows__) 636 struct spinlock tcb_lock; 637 struct spinlock tcb_send_lock; 638 #elif defined(__Userspace__) 639 /* TODO decide on __Userspace__ locks */ 640 #endif 641 #if defined(__APPLE__) 642 uint32_t caller1; 643 uint32_t caller2; 644 uint32_t caller3; 645 #endif 646 }; 647 648 649 #if defined(__FreeBSD__) && __FreeBSD_version >= 503000 650 651 #include <netinet/sctp_lock_bsd.h> 652 653 #elif defined(__APPLE__) 654 /* 655 * Apple MacOS X 10.4 "Tiger" 656 */ 657 658 #include <netinet/sctp_lock_apple_fg.h> 659 660 #elif defined(SCTP_PROCESS_LEVEL_LOCKS) 661 662 #include <netinet/sctp_process_lock.h> 663 664 #elif defined(__Windows__) 665 666 #include <netinet/sctp_lock_windows.h> 667 668 #elif defined(__Userspace__) 669 670 #include <netinet/sctp_lock_userspace.h> 671 672 #else 673 /* 674 * Pre-5.x FreeBSD, and others. 675 */ 676 #include <netinet/sctp_lock_empty.h> 677 #endif 678 679 /* TODO where to put non-_KERNEL things for __Userspace__? */ 680 #if defined(_KERNEL) || defined(__Userspace__) 681 682 /* Attention Julian, this is the extern that 683 * goes with the base info. sctp_pcb.c has 684 * the real definition. 685 */ 686 #if defined(__FreeBSD__) && __FreeBSD_version >= 801000 687 VNET_DECLARE(struct sctp_base_info, system_base_info) ; 688 #else 689 extern struct sctp_base_info system_base_info; 690 #endif 691 692 #ifdef INET6 693 int SCTP6_ARE_ADDR_EQUAL(struct sockaddr_in6 *a, struct sockaddr_in6 *b); 694 #endif 695 696 void sctp_fill_pcbinfo(struct sctp_pcbinfo *); 697 698 struct sctp_ifn * 699 sctp_find_ifn(void *ifn, uint32_t ifn_index); 700 701 struct sctp_vrf *sctp_allocate_vrf(int vrfid); 702 struct sctp_vrf *sctp_find_vrf(uint32_t vrfid); 703 void sctp_free_vrf(struct sctp_vrf *vrf); 704 705 /*- 706 * Change address state, can be used if 707 * O/S supports telling transports about 708 * changes to IFA/IFN's (link layer triggers). 709 * If a ifn goes down, we will do src-addr-selection 710 * and NOT use that, as a source address. This does 711 * not stop the routing system from routing out 712 * that interface, but we won't put it as a source. 713 */ 714 void sctp_mark_ifa_addr_down(uint32_t vrf_id, struct sockaddr *addr, const char *if_name, uint32_t ifn_index); 715 void sctp_mark_ifa_addr_up(uint32_t vrf_id, struct sockaddr *addr, const char *if_name, uint32_t ifn_index); 716 717 struct sctp_ifa * 718 sctp_add_addr_to_vrf(uint32_t vrfid, 719 void *ifn, uint32_t ifn_index, uint32_t ifn_type, 720 const char *if_name, 721 void *ifa, struct sockaddr *addr, uint32_t ifa_flags, 722 int dynamic_add); 723 724 void sctp_update_ifn_mtu(uint32_t ifn_index, uint32_t mtu); 725 726 void sctp_free_ifn(struct sctp_ifn *sctp_ifnp); 727 void sctp_free_ifa(struct sctp_ifa *sctp_ifap); 728 729 730 void sctp_del_addr_from_vrf(uint32_t vrfid, struct sockaddr *addr, 731 uint32_t ifn_index, const char *if_name); 732 733 734 735 struct sctp_nets *sctp_findnet(struct sctp_tcb *, struct sockaddr *); 736 737 struct sctp_inpcb *sctp_pcb_findep(struct sockaddr *, int, int, uint32_t); 738 739 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000 740 int sctp_inpcb_bind(struct socket *, struct sockaddr *, 741 struct sctp_ifa *,struct thread *); 742 #elif defined(__Windows__) 743 int sctp_inpcb_bind(struct socket *, struct sockaddr *, 744 struct sctp_ifa *,PKTHREAD); 745 #else 746 /* struct proc is a dummy for __Userspace__ */ 747 int sctp_inpcb_bind(struct socket *, struct sockaddr *, 748 struct sctp_ifa *, struct proc *); 749 #endif 750 751 struct sctp_tcb * 752 sctp_findassociation_addr(struct mbuf *, int, 753 struct sockaddr *, struct sockaddr *, 754 struct sctphdr *, struct sctp_chunkhdr *, struct sctp_inpcb **, 755 struct sctp_nets **, uint32_t vrf_id); 756 757 struct sctp_tcb * 758 sctp_findassociation_addr_sa(struct sockaddr *, 759 struct sockaddr *, struct sctp_inpcb **, struct sctp_nets **, int, uint32_t); 760 761 void 762 sctp_move_pcb_and_assoc(struct sctp_inpcb *, struct sctp_inpcb *, 763 struct sctp_tcb *); 764 765 /*- 766 * For this call ep_addr, the to is the destination endpoint address of the 767 * peer (relative to outbound). The from field is only used if the TCP model 768 * is enabled and helps distingush amongst the subset bound (non-boundall). 769 * The TCP model MAY change the actual ep field, this is why it is passed. 770 */ 771 struct sctp_tcb * 772 sctp_findassociation_ep_addr(struct sctp_inpcb **, 773 struct sockaddr *, struct sctp_nets **, struct sockaddr *, 774 struct sctp_tcb *); 775 776 struct sctp_tcb * 777 sctp_findasoc_ep_asocid_locked(struct sctp_inpcb *inp, sctp_assoc_t asoc_id, int want_lock); 778 779 struct sctp_tcb * 780 sctp_findassociation_ep_asocid(struct sctp_inpcb *, 781 sctp_assoc_t, int); 782 783 struct sctp_tcb * 784 sctp_findassociation_ep_asconf(struct mbuf *, int, struct sockaddr *, 785 struct sctphdr *, struct sctp_inpcb **, struct sctp_nets **, uint32_t vrf_id); 786 787 int sctp_inpcb_alloc(struct socket *so, uint32_t vrf_id); 788 789 int sctp_is_address_on_local_host(struct sockaddr *addr, uint32_t vrf_id); 790 791 void sctp_inpcb_free(struct sctp_inpcb *, int, int); 792 793 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000 794 struct sctp_tcb * 795 sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *, 796 int *, uint32_t, uint32_t, struct thread *); 797 #elif defined(__Windows__) 798 struct sctp_tcb * 799 sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *, 800 int *, uint32_t, uint32_t, PKTHREAD); 801 #else 802 /* proc will be NULL for __Userspace__ */ 803 struct sctp_tcb * 804 sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *, 805 int *, uint32_t, uint32_t, struct proc *); 806 #endif 807 808 int sctp_free_assoc(struct sctp_inpcb *, struct sctp_tcb *, int, int); 809 810 811 void sctp_delete_from_timewait(uint32_t, uint16_t, uint16_t); 812 813 int sctp_is_in_timewait(uint32_t tag, uint16_t lport, uint16_t rport); 814 815 void 816 sctp_add_vtag_to_timewait(uint32_t tag, uint32_t time, uint16_t lport, uint16_t rport); 817 818 void sctp_add_local_addr_ep(struct sctp_inpcb *, struct sctp_ifa *, uint32_t); 819 820 int sctp_insert_laddr(struct sctpladdr *, struct sctp_ifa *, uint32_t); 821 822 void sctp_remove_laddr(struct sctp_laddr *); 823 824 void sctp_del_local_addr_ep(struct sctp_inpcb *, struct sctp_ifa *); 825 826 int sctp_add_remote_addr(struct sctp_tcb *, struct sockaddr *, struct sctp_nets **, int, int); 827 828 void sctp_remove_net(struct sctp_tcb *, struct sctp_nets *); 829 830 int sctp_del_remote_addr(struct sctp_tcb *, struct sockaddr *); 831 832 void sctp_pcb_init(void); 833 834 void sctp_pcb_finish(void); 835 836 void sctp_add_local_addr_restricted(struct sctp_tcb *, struct sctp_ifa *); 837 void sctp_del_local_addr_restricted(struct sctp_tcb *, struct sctp_ifa *); 838 839 int 840 sctp_load_addresses_from_init(struct sctp_tcb *, struct mbuf *, int, int, 841 struct sockaddr *, struct sockaddr *, struct sockaddr *); 842 843 int 844 sctp_set_primary_addr(struct sctp_tcb *, struct sockaddr *, 845 struct sctp_nets *); 846 847 int sctp_is_vtag_good(uint32_t, uint16_t lport, uint16_t rport, struct timeval *); 848 849 850 int sctp_destination_is_reachable(struct sctp_tcb *, struct sockaddr *); 851 852 int sctp_swap_inpcb_for_listen(struct sctp_inpcb *inp); 853 854 /*- 855 * Null in last arg inpcb indicate run on ALL ep's. Specific inp in last arg 856 * indicates run on ONLY assoc's of the specified endpoint. 857 */ 858 int 859 sctp_initiate_iterator(inp_func inpf, 860 asoc_func af, 861 inp_func inpe, 862 uint32_t, uint32_t, 863 uint32_t, void *, 864 uint32_t, 865 end_func ef, 866 struct sctp_inpcb *, 867 uint8_t co_off); 868 #if defined(__FreeBSD__) && 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 874 #ifdef INVARIANTS 875 void 876 sctp_validate_no_locks(struct sctp_inpcb *inp); 877 #endif 878 879 #endif /* _KERNEL */ 880 #endif /* !__sctp_pcb_h__ */ 881