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 269858 2014-08-12 11:30:16Z 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 uint8_t local_strreset_support; 482 uint32_t sctp_cmt_on_off; 483 uint8_t ecn_supported; 484 uint8_t prsctp_supported; 485 uint8_t auth_supported; 486 uint8_t asconf_supported; 487 uint8_t reconfig_supported; 488 uint8_t nrsack_supported; 489 uint8_t pktdrop_supported; 490 struct sctp_nonpad_sndrcvinfo def_send; 491 /*- 492 * These three are here for the sosend_dgram 493 * (pkt, pkt_last and control). 494 * routine. However, I don't think anyone in 495 * the current FreeBSD kernel calls this. So 496 * they are candidates with sctp_sendm for 497 * de-supporting. 498 */ 499 #ifdef __Panda__ 500 pakhandle_type pak_to_read; 501 pakhandle_type pak_to_read_sendq; 502 #endif 503 struct mbuf *pkt, *pkt_last; 504 struct mbuf *control; 505 #if !(defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__)) 506 #ifndef INP_IPV6 507 #define INP_IPV6 0x1 508 #endif 509 #ifndef INP_IPV4 510 #define INP_IPV4 0x2 511 #endif 512 uint8_t inp_vflag; 513 /* TODO __Userspace__ where is our inp_vlag going to be? */ 514 uint8_t inp_ip_ttl; 515 uint8_t inp_ip_tos; /* defined as macro in user_inpcb.h */ 516 uint8_t inp_ip_resv; 517 #endif 518 #if defined(__FreeBSD__) && __FreeBSD_version >= 503000 519 struct mtx inp_mtx; 520 struct mtx inp_create_mtx; 521 struct mtx inp_rdata_mtx; 522 int32_t refcount; 523 #elif defined(SCTP_PROCESS_LEVEL_LOCKS) 524 userland_mutex_t inp_mtx; 525 userland_mutex_t inp_create_mtx; 526 userland_mutex_t inp_rdata_mtx; 527 int32_t refcount; 528 #elif defined(__APPLE__) 529 #if defined(SCTP_APPLE_RWLOCK) 530 lck_rw_t *inp_mtx; 531 #else 532 lck_mtx_t *inp_mtx; 533 #endif 534 lck_mtx_t *inp_create_mtx; 535 lck_mtx_t *inp_rdata_mtx; 536 #elif defined(__Windows__) 537 struct rwlock inp_lock; 538 struct spinlock inp_create_lock; 539 struct spinlock inp_rdata_lock; 540 int32_t refcount; 541 #elif defined(__Userspace__) 542 /* TODO decide on __Userspace__ locks */ 543 int32_t refcount; 544 #endif 545 #if defined(__APPLE__) 546 int32_t refcount; 547 548 uint32_t lock_caller1; 549 uint32_t lock_caller2; 550 uint32_t lock_caller3; 551 uint32_t unlock_caller1; 552 uint32_t unlock_caller2; 553 uint32_t unlock_caller3; 554 uint32_t getlock_caller1; 555 uint32_t getlock_caller2; 556 uint32_t getlock_caller3; 557 uint32_t gen_count; 558 uint32_t lock_gen_count; 559 uint32_t unlock_gen_count; 560 uint32_t getlock_gen_count; 561 562 uint32_t i_am_here_file; 563 uint32_t i_am_here_line; 564 #endif 565 uint32_t def_vrf_id; 566 #ifdef SCTP_MVRF 567 uint32_t *m_vrf_ids; 568 uint32_t num_vrfs; 569 uint32_t vrf_size; 570 #endif 571 uint32_t total_sends; 572 uint32_t total_recvs; 573 uint32_t last_abort_code; 574 uint32_t total_nospaces; 575 struct sctpasochead *sctp_asocidhash; 576 u_long hashasocidmark; 577 uint32_t sctp_associd_counter; 578 579 #ifdef SCTP_ASOCLOG_OF_TSNS 580 struct sctp_pcbtsn_rlog readlog[SCTP_READ_LOG_SIZE]; 581 uint32_t readlog_index; 582 #endif 583 #if defined(__Userspace__) 584 void *ulp_info; 585 int (*recv_callback)(struct socket *, union sctp_sockstore, void *, size_t, 586 struct sctp_rcvinfo, int, void *); 587 uint32_t send_sb_threshold; 588 int (*send_callback)(struct socket *, uint32_t); 589 #endif 590 }; 591 592 #if defined(__Userspace__) 593 int register_recv_cb (struct socket *, 594 int (*)(struct socket *, union sctp_sockstore, void *, size_t, 595 struct sctp_rcvinfo, int, void *)); 596 int register_send_cb (struct socket *, uint32_t, int (*)(struct socket *, uint32_t)); 597 int register_ulp_info (struct socket *, void *); 598 599 #endif 600 struct sctp_tcb { 601 struct socket *sctp_socket; /* back pointer to socket */ 602 struct sctp_inpcb *sctp_ep; /* back pointer to ep */ 603 LIST_ENTRY(sctp_tcb) sctp_tcbhash; /* next link in hash 604 * table */ 605 LIST_ENTRY(sctp_tcb) sctp_tcblist; /* list of all of the 606 * TCB's */ 607 LIST_ENTRY(sctp_tcb) sctp_tcbasocidhash; /* next link in asocid 608 * hash table 609 */ 610 LIST_ENTRY(sctp_tcb) sctp_asocs; /* vtag hash list */ 611 struct sctp_block_entry *block_entry; /* pointer locked by socket 612 * send buffer */ 613 struct sctp_association asoc; 614 /*- 615 * freed_by_sorcv_sincelast is protected by the sockbuf_lock NOT the 616 * tcb_lock. Its special in this way to help avoid extra mutex calls 617 * in the reading of data. 618 */ 619 uint32_t freed_by_sorcv_sincelast; 620 uint32_t total_sends; 621 uint32_t total_recvs; 622 int freed_from_where; 623 uint16_t rport; /* remote port in network format */ 624 uint16_t resv; 625 #if defined(__FreeBSD__) && __FreeBSD_version >= 503000 626 struct mtx tcb_mtx; 627 struct mtx tcb_send_mtx; 628 #elif defined(SCTP_PROCESS_LEVEL_LOCKS) 629 userland_mutex_t tcb_mtx; 630 userland_mutex_t tcb_send_mtx; 631 #elif defined(__APPLE__) 632 lck_mtx_t* tcb_mtx; 633 lck_mtx_t* tcb_send_mtx; 634 #elif defined(__Windows__) 635 struct spinlock tcb_lock; 636 struct spinlock tcb_send_lock; 637 #elif defined(__Userspace__) 638 /* TODO decide on __Userspace__ locks */ 639 #endif 640 #if defined(__APPLE__) 641 uint32_t caller1; 642 uint32_t caller2; 643 uint32_t caller3; 644 #endif 645 }; 646 647 648 #if defined(__FreeBSD__) && __FreeBSD_version >= 503000 649 650 #include <netinet/sctp_lock_bsd.h> 651 652 #elif defined(__APPLE__) 653 /* 654 * Apple MacOS X 10.4 "Tiger" 655 */ 656 657 #include <netinet/sctp_lock_apple_fg.h> 658 659 #elif defined(SCTP_PROCESS_LEVEL_LOCKS) 660 661 #include <netinet/sctp_process_lock.h> 662 663 #elif defined(__Windows__) 664 665 #include <netinet/sctp_lock_windows.h> 666 667 #elif defined(__Userspace__) 668 669 #include <netinet/sctp_lock_userspace.h> 670 671 #else 672 /* 673 * Pre-5.x FreeBSD, and others. 674 */ 675 #include <netinet/sctp_lock_empty.h> 676 #endif 677 678 /* TODO where to put non-_KERNEL things for __Userspace__? */ 679 #if defined(_KERNEL) || defined(__Userspace__) 680 681 /* Attention Julian, this is the extern that 682 * goes with the base info. sctp_pcb.c has 683 * the real definition. 684 */ 685 #if defined(__FreeBSD__) && __FreeBSD_version >= 801000 686 VNET_DECLARE(struct sctp_base_info, system_base_info) ; 687 #else 688 extern struct sctp_base_info system_base_info; 689 #endif 690 691 #ifdef INET6 692 int SCTP6_ARE_ADDR_EQUAL(struct sockaddr_in6 *a, struct sockaddr_in6 *b); 693 #endif 694 695 void sctp_fill_pcbinfo(struct sctp_pcbinfo *); 696 697 struct sctp_ifn * 698 sctp_find_ifn(void *ifn, uint32_t ifn_index); 699 700 struct sctp_vrf *sctp_allocate_vrf(int vrfid); 701 struct sctp_vrf *sctp_find_vrf(uint32_t vrfid); 702 void sctp_free_vrf(struct sctp_vrf *vrf); 703 704 /*- 705 * Change address state, can be used if 706 * O/S supports telling transports about 707 * changes to IFA/IFN's (link layer triggers). 708 * If a ifn goes down, we will do src-addr-selection 709 * and NOT use that, as a source address. This does 710 * not stop the routing system from routing out 711 * that interface, but we won't put it as a source. 712 */ 713 void sctp_mark_ifa_addr_down(uint32_t vrf_id, struct sockaddr *addr, const char *if_name, uint32_t ifn_index); 714 void sctp_mark_ifa_addr_up(uint32_t vrf_id, struct sockaddr *addr, const char *if_name, uint32_t ifn_index); 715 716 struct sctp_ifa * 717 sctp_add_addr_to_vrf(uint32_t vrfid, 718 void *ifn, uint32_t ifn_index, uint32_t ifn_type, 719 const char *if_name, 720 void *ifa, struct sockaddr *addr, uint32_t ifa_flags, 721 int dynamic_add); 722 723 void sctp_update_ifn_mtu(uint32_t ifn_index, uint32_t mtu); 724 725 void sctp_free_ifn(struct sctp_ifn *sctp_ifnp); 726 void sctp_free_ifa(struct sctp_ifa *sctp_ifap); 727 728 729 void sctp_del_addr_from_vrf(uint32_t vrfid, struct sockaddr *addr, 730 uint32_t ifn_index, const char *if_name); 731 732 733 734 struct sctp_nets *sctp_findnet(struct sctp_tcb *, struct sockaddr *); 735 736 struct sctp_inpcb *sctp_pcb_findep(struct sockaddr *, int, int, uint32_t); 737 738 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000 739 int sctp_inpcb_bind(struct socket *, struct sockaddr *, 740 struct sctp_ifa *,struct thread *); 741 #elif defined(__Windows__) 742 int sctp_inpcb_bind(struct socket *, struct sockaddr *, 743 struct sctp_ifa *,PKTHREAD); 744 #else 745 /* struct proc is a dummy for __Userspace__ */ 746 int sctp_inpcb_bind(struct socket *, struct sockaddr *, 747 struct sctp_ifa *, struct proc *); 748 #endif 749 750 struct sctp_tcb * 751 sctp_findassociation_addr(struct mbuf *, int, 752 struct sockaddr *, struct sockaddr *, 753 struct sctphdr *, struct sctp_chunkhdr *, struct sctp_inpcb **, 754 struct sctp_nets **, uint32_t vrf_id); 755 756 struct sctp_tcb * 757 sctp_findassociation_addr_sa(struct sockaddr *, 758 struct sockaddr *, struct sctp_inpcb **, struct sctp_nets **, int, uint32_t); 759 760 void 761 sctp_move_pcb_and_assoc(struct sctp_inpcb *, struct sctp_inpcb *, 762 struct sctp_tcb *); 763 764 /*- 765 * For this call ep_addr, the to is the destination endpoint address of the 766 * peer (relative to outbound). The from field is only used if the TCP model 767 * is enabled and helps distingush amongst the subset bound (non-boundall). 768 * The TCP model MAY change the actual ep field, this is why it is passed. 769 */ 770 struct sctp_tcb * 771 sctp_findassociation_ep_addr(struct sctp_inpcb **, 772 struct sockaddr *, struct sctp_nets **, struct sockaddr *, 773 struct sctp_tcb *); 774 775 struct sctp_tcb * 776 sctp_findasoc_ep_asocid_locked(struct sctp_inpcb *inp, sctp_assoc_t asoc_id, int want_lock); 777 778 struct sctp_tcb * 779 sctp_findassociation_ep_asocid(struct sctp_inpcb *, 780 sctp_assoc_t, int); 781 782 struct sctp_tcb * 783 sctp_findassociation_ep_asconf(struct mbuf *, int, struct sockaddr *, 784 struct sctphdr *, struct sctp_inpcb **, struct sctp_nets **, uint32_t vrf_id); 785 786 int sctp_inpcb_alloc(struct socket *so, uint32_t vrf_id); 787 788 int sctp_is_address_on_local_host(struct sockaddr *addr, uint32_t vrf_id); 789 790 void sctp_inpcb_free(struct sctp_inpcb *, int, int); 791 792 #if defined(__FreeBSD__) && __FreeBSD_version >= 500000 793 struct sctp_tcb * 794 sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *, 795 int *, uint32_t, uint32_t, struct thread *); 796 #elif defined(__Windows__) 797 struct sctp_tcb * 798 sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *, 799 int *, uint32_t, uint32_t, PKTHREAD); 800 #else 801 /* proc will be NULL for __Userspace__ */ 802 struct sctp_tcb * 803 sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *, 804 int *, uint32_t, uint32_t, struct proc *); 805 #endif 806 807 int sctp_free_assoc(struct sctp_inpcb *, struct sctp_tcb *, int, int); 808 809 810 void sctp_delete_from_timewait(uint32_t, uint16_t, uint16_t); 811 812 int sctp_is_in_timewait(uint32_t tag, uint16_t lport, uint16_t rport); 813 814 void 815 sctp_add_vtag_to_timewait(uint32_t tag, uint32_t time, uint16_t lport, uint16_t rport); 816 817 void sctp_add_local_addr_ep(struct sctp_inpcb *, struct sctp_ifa *, uint32_t); 818 819 int sctp_insert_laddr(struct sctpladdr *, struct sctp_ifa *, uint32_t); 820 821 void sctp_remove_laddr(struct sctp_laddr *); 822 823 void sctp_del_local_addr_ep(struct sctp_inpcb *, struct sctp_ifa *); 824 825 int sctp_add_remote_addr(struct sctp_tcb *, struct sockaddr *, struct sctp_nets **, int, int); 826 827 void sctp_remove_net(struct sctp_tcb *, struct sctp_nets *); 828 829 int sctp_del_remote_addr(struct sctp_tcb *, struct sockaddr *); 830 831 void sctp_pcb_init(void); 832 833 void sctp_pcb_finish(void); 834 835 void sctp_add_local_addr_restricted(struct sctp_tcb *, struct sctp_ifa *); 836 void sctp_del_local_addr_restricted(struct sctp_tcb *, struct sctp_ifa *); 837 838 int 839 sctp_load_addresses_from_init(struct sctp_tcb *, struct mbuf *, int, int, 840 struct sockaddr *, struct sockaddr *, struct sockaddr *); 841 842 int 843 sctp_set_primary_addr(struct sctp_tcb *, struct sockaddr *, 844 struct sctp_nets *); 845 846 int sctp_is_vtag_good(uint32_t, uint16_t lport, uint16_t rport, struct timeval *); 847 848 /* void sctp_drain(void); */ 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