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