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