1163953Srrs/*- 2169382Srrs * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved. 3235828Stuexen * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved. 4235828Stuexen * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved. 5235828Stuexen * 6163953Srrs * Redistribution and use in source and binary forms, with or without 7163953Srrs * modification, are permitted provided that the following conditions are met: 8163953Srrs * 9163953Srrs * a) Redistributions of source code must retain the above copyright notice, 10228653Stuexen * this list of conditions and the following disclaimer. 11163953Srrs * 12163953Srrs * b) Redistributions in binary form must reproduce the above copyright 13163953Srrs * notice, this list of conditions and the following disclaimer in 14228653Stuexen * the documentation and/or other materials provided with the distribution. 15163953Srrs * 16163953Srrs * c) Neither the name of Cisco Systems, Inc. nor the names of its 17163953Srrs * contributors may be used to endorse or promote products derived 18163953Srrs * from this software without specific prior written permission. 19163953Srrs * 20163953Srrs * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21163953Srrs * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 22163953Srrs * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23163953Srrs * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24163953Srrs * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25163953Srrs * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26163953Srrs * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27163953Srrs * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28163953Srrs * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29163953Srrs * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30163953Srrs * THE POSSIBILITY OF SUCH DAMAGE. 31163953Srrs */ 32163953Srrs 33163953Srrs#include <sys/cdefs.h> 34163953Srrs__FBSDID("$FreeBSD$"); 35163953Srrs 36235828Stuexen#ifndef _NETINET_SCTP_PCB_H_ 37235828Stuexen#define _NETINET_SCTP_PCB_H_ 38163953Srrs 39166086Srrs#include <netinet/sctp_os.h> 40163953Srrs#include <netinet/sctp.h> 41163953Srrs#include <netinet/sctp_constants.h> 42179783Srrs#include <netinet/sctp_sysctl.h> 43163953Srrs 44163953SrrsLIST_HEAD(sctppcbhead, sctp_inpcb); 45163953SrrsLIST_HEAD(sctpasochead, sctp_tcb); 46163953SrrsLIST_HEAD(sctpladdr, sctp_laddr); 47163953SrrsLIST_HEAD(sctpvtaghead, sctp_tagblock); 48167598SrrsLIST_HEAD(sctp_vrflist, sctp_vrf); 49167598SrrsLIST_HEAD(sctp_ifnlist, sctp_ifn); 50167598SrrsLIST_HEAD(sctp_ifalist, sctp_ifa); 51163953SrrsTAILQ_HEAD(sctp_readhead, sctp_queued_to_read); 52163953SrrsTAILQ_HEAD(sctp_streamhead, sctp_stream_queue_pending); 53163953Srrs 54163953Srrs#include <netinet/sctp_structs.h> 55163953Srrs#include <netinet/sctp_auth.h> 56163953Srrs 57163953Srrs#define SCTP_PCBHASH_ALLADDR(port, mask) (port & mask) 58163953Srrs#define SCTP_PCBHASH_ASOC(tag, mask) (tag & mask) 59163953Srrs 60167598Srrsstruct sctp_vrf { 61167598Srrs LIST_ENTRY(sctp_vrf) next_vrf; 62167698Srrs struct sctp_ifalist *vrf_addr_hash; 63167598Srrs struct sctp_ifnlist ifnlist; 64167598Srrs uint32_t vrf_id; 65170205Srrs uint32_t tbl_id_v4; /* default v4 table id */ 66170205Srrs uint32_t tbl_id_v6; /* default v6 table id */ 67167598Srrs uint32_t total_ifa_count; 68169352Srrs u_long vrf_addr_hashmark; 69170744Srrs uint32_t refcount; 70167598Srrs}; 71167598Srrs 72167598Srrsstruct sctp_ifn { 73167598Srrs struct sctp_ifalist ifalist; 74167598Srrs struct sctp_vrf *vrf; 75167598Srrs LIST_ENTRY(sctp_ifn) next_ifn; 76169352Srrs LIST_ENTRY(sctp_ifn) next_bucket; 77167598Srrs void *ifn_p; /* never access without appropriate lock */ 78169352Srrs uint32_t ifn_mtu; 79167598Srrs uint32_t ifn_type; 80167598Srrs uint32_t ifn_index; /* shorthand way to look at ifn for reference */ 81167598Srrs uint32_t refcount; /* number of reference held should be >= 82167598Srrs * ifa_count */ 83167598Srrs uint32_t ifa_count; /* IFA's we hold (in our list - ifalist) */ 84170181Srrs uint32_t num_v6; /* number of v6 addresses */ 85170181Srrs uint32_t num_v4; /* number of v4 addresses */ 86170181Srrs uint32_t registered_af; /* registered address family for i/f events */ 87167598Srrs char ifn_name[SCTP_IFNAMSIZ]; 88167598Srrs}; 89167598Srrs 90167598Srrs/* SCTP local IFA flags */ 91167598Srrs#define SCTP_ADDR_VALID 0x00000001 /* its up and active */ 92167598Srrs#define SCTP_BEING_DELETED 0x00000002 /* being deleted, when 93167598Srrs * refcount = 0. Note that it 94167598Srrs * is pulled from the ifn list 95167598Srrs * and ifa_p is nulled right 96167598Srrs * away but it cannot be freed 97167598Srrs * until the last *net 98167598Srrs * pointing to it is deleted. */ 99167598Srrs#define SCTP_ADDR_DEFER_USE 0x00000004 /* Hold off using this one */ 100167598Srrs#define SCTP_ADDR_IFA_UNUSEABLE 0x00000008 101167598Srrs 102167598Srrsstruct sctp_ifa { 103167598Srrs LIST_ENTRY(sctp_ifa) next_ifa; 104167698Srrs LIST_ENTRY(sctp_ifa) next_bucket; 105167598Srrs struct sctp_ifn *ifn_p; /* back pointer to parent ifn */ 106167598Srrs void *ifa; /* pointer to ifa, needed for flag update for 107167598Srrs * that we MUST lock appropriate locks. This 108167598Srrs * is for V6. */ 109167598Srrs union sctp_sockstore address; 110167598Srrs uint32_t refcount; /* number of folks refering to this */ 111167598Srrs uint32_t flags; 112167598Srrs uint32_t localifa_flags; 113170751Srrs uint32_t vrf_id; /* vrf_id of this addr (for deleting) */ 114167598Srrs uint8_t src_is_loop; 115167598Srrs uint8_t src_is_priv; 116167598Srrs uint8_t src_is_glob; 117169352Srrs uint8_t resv; 118167598Srrs}; 119167598Srrs 120163953Srrsstruct sctp_laddr { 121163953Srrs LIST_ENTRY(sctp_laddr) sctp_nxt_addr; /* next in list */ 122167598Srrs struct sctp_ifa *ifa; 123167598Srrs uint32_t action; /* Used during asconf and adding if no-zero 124167598Srrs * src-addr selection will not consider this 125167598Srrs * address. */ 126170056Srrs struct timeval start_time; /* time when this address was created */ 127163953Srrs}; 128163953Srrs 129163953Srrsstruct sctp_block_entry { 130163953Srrs int error; 131163953Srrs}; 132163953Srrs 133163953Srrsstruct sctp_timewait { 134163953Srrs uint32_t tv_sec_at_expire; /* the seconds from boot to expire */ 135163953Srrs uint32_t v_tag; /* the vtag that can not be reused */ 136185694Srrs uint16_t lport; /* the local port used in vtag */ 137185694Srrs uint16_t rport; /* the remote port used in vtag */ 138163953Srrs}; 139163953Srrs 140163953Srrsstruct sctp_tagblock { 141163953Srrs LIST_ENTRY(sctp_tagblock) sctp_nxt_tagblock; 142163953Srrs struct sctp_timewait vtag_block[SCTP_NUMBER_IN_VTAG_BLOCK]; 143163953Srrs}; 144163953Srrs 145179783Srrs 146163953Srrsstruct sctp_epinfo { 147243186Stuexen#ifdef INET 148243186Stuexen struct socket *udp4_tun_socket; 149243186Stuexen#endif 150243186Stuexen#ifdef INET6 151243186Stuexen struct socket *udp6_tun_socket; 152243186Stuexen#endif 153163953Srrs struct sctpasochead *sctp_asochash; 154163953Srrs u_long hashasocmark; 155163953Srrs 156163953Srrs struct sctppcbhead *sctp_ephash; 157163953Srrs u_long hashmark; 158163953Srrs 159168124Srrs /*- 160163953Srrs * The TCP model represents a substantial overhead in that we get an 161163953Srrs * additional hash table to keep explicit connections in. The 162163953Srrs * listening TCP endpoint will exist in the usual ephash above and 163163953Srrs * accept only INIT's. It will be incapable of sending off an INIT. 164163953Srrs * When a dg arrives we must look in the normal ephash. If we find a 165163953Srrs * TCP endpoint that will tell us to go to the specific endpoint 166163953Srrs * hash and re-hash to find the right assoc/socket. If we find a UDP 167163953Srrs * model socket we then must complete the lookup. If this fails, 168163953Srrs * i.e. no association can be found then we must continue to see if 169163953Srrs * a sctp_peeloff()'d socket is in the tcpephash (a spun off socket 170163953Srrs * acts like a TCP model connected socket). 171163953Srrs */ 172163953Srrs struct sctppcbhead *sctp_tcpephash; 173163953Srrs u_long hashtcpmark; 174163953Srrs uint32_t hashtblsize; 175163953Srrs 176167598Srrs struct sctp_vrflist *sctp_vrfhash; 177167598Srrs u_long hashvrfmark; 178167598Srrs 179170205Srrs struct sctp_ifnlist *vrf_ifn_hash; 180170205Srrs u_long vrf_ifn_hashmark; 181170205Srrs 182163953Srrs struct sctppcbhead listhead; 183163953Srrs struct sctpladdr addr_wq; 184163953Srrs 185163953Srrs /* ep zone info */ 186163953Srrs sctp_zone_t ipi_zone_ep; 187163953Srrs sctp_zone_t ipi_zone_asoc; 188163953Srrs sctp_zone_t ipi_zone_laddr; 189163953Srrs sctp_zone_t ipi_zone_net; 190163953Srrs sctp_zone_t ipi_zone_chunk; 191163953Srrs sctp_zone_t ipi_zone_readq; 192163953Srrs sctp_zone_t ipi_zone_strmoq; 193179157Srrs sctp_zone_t ipi_zone_asconf; 194171990Srrs sctp_zone_t ipi_zone_asconf_ack; 195163953Srrs 196172218Srrs struct rwlock ipi_ep_mtx; 197167598Srrs struct mtx ipi_iterator_wq_mtx; 198172218Srrs struct rwlock ipi_addr_mtx; 199170091Srrs struct mtx ipi_pktlog_mtx; 200208160Srrs struct mtx wq_addr_mtx; 201163953Srrs uint32_t ipi_count_ep; 202163953Srrs 203163953Srrs /* assoc/tcb zone info */ 204163953Srrs uint32_t ipi_count_asoc; 205163953Srrs 206163953Srrs /* local addrlist zone info */ 207163953Srrs uint32_t ipi_count_laddr; 208163953Srrs 209163953Srrs /* remote addrlist zone info */ 210163953Srrs uint32_t ipi_count_raddr; 211163953Srrs 212163953Srrs /* chunk structure list for output */ 213163953Srrs uint32_t ipi_count_chunk; 214163953Srrs 215163953Srrs /* socket queue zone info */ 216163953Srrs uint32_t ipi_count_readq; 217163953Srrs 218163953Srrs /* socket queue zone info */ 219163953Srrs uint32_t ipi_count_strmoq; 220163953Srrs 221169352Srrs /* Number of vrfs */ 222169352Srrs uint32_t ipi_count_vrfs; 223169352Srrs 224169352Srrs /* Number of ifns */ 225169352Srrs uint32_t ipi_count_ifns; 226169352Srrs 227169352Srrs /* Number of ifas */ 228169352Srrs uint32_t ipi_count_ifas; 229169352Srrs 230163953Srrs /* system wide number of free chunks hanging around */ 231163953Srrs uint32_t ipi_free_chunks; 232163953Srrs uint32_t ipi_free_strmoq; 233163953Srrs 234184883Srrs struct sctpvtaghead vtag_timewait[SCTP_STACK_VTAG_HASH_SIZE]; 235163953Srrs 236167598Srrs /* address work queue handling */ 237163953Srrs struct sctp_timer addr_wq_timer; 238163953Srrs 239163953Srrs}; 240163953Srrs 241179783Srrs 242179783Srrsstruct sctp_base_info { 243179783Srrs /* 244179783Srrs * All static structures that anchor the system must be here. 245179783Srrs */ 246179783Srrs struct sctp_epinfo sctppcbinfo; 247205629Srrs#if defined(__FreeBSD__) && defined(SMP) && defined(SCTP_USE_PERCPU_STAT) 248218219Srrs struct sctpstat *sctpstat; 249205629Srrs#else 250179783Srrs struct sctpstat sctpstat; 251205629Srrs#endif 252179783Srrs struct sctp_sysctl sctpsysctl; 253179783Srrs uint8_t first_time; 254179783Srrs char sctp_pcb_initialized; 255179783Srrs#if defined(SCTP_PACKET_LOGGING) 256179783Srrs int packet_log_writers; 257179783Srrs int packet_log_end; 258179783Srrs uint8_t packet_log_buffer[SCTP_PACKET_LOG_SIZE]; 259179783Srrs#endif 260179783Srrs}; 261179783Srrs 262168124Srrs/*- 263163953Srrs * Here we have all the relevant information for each SCTP entity created. We 264163953Srrs * will need to modify this as approprate. We also need to figure out how to 265163953Srrs * access /dev/random. 266163953Srrs */ 267163953Srrsstruct sctp_pcb { 268163953Srrs unsigned int time_of_secret_change; /* number of seconds from 269163953Srrs * timeval.tv_sec */ 270163953Srrs uint32_t secret_key[SCTP_HOW_MANY_SECRETS][SCTP_NUMBER_OF_SECRETS]; 271163953Srrs unsigned int size_of_a_cookie; 272163953Srrs 273163953Srrs unsigned int sctp_timeoutticks[SCTP_NUM_TMRS]; 274163953Srrs unsigned int sctp_minrto; 275163953Srrs unsigned int sctp_maxrto; 276163953Srrs unsigned int initial_rto; 277163953Srrs int initial_init_rto_max; 278163953Srrs 279167598Srrs unsigned int sctp_sack_freq; 280163953Srrs uint32_t sctp_sws_sender; 281163953Srrs uint32_t sctp_sws_receiver; 282163953Srrs 283171440Srrs uint32_t sctp_default_cc_module; 284217760Stuexen uint32_t sctp_default_ss_module; 285163953Srrs /* authentication related fields */ 286163953Srrs struct sctp_keyhead shared_keys; 287163953Srrs sctp_auth_chklist_t *local_auth_chunks; 288163953Srrs sctp_hmaclist_t *local_hmacs; 289163953Srrs uint16_t default_keyid; 290163953Srrs 291163953Srrs /* various thresholds */ 292163953Srrs /* Max times I will init at a guy */ 293163953Srrs uint16_t max_init_times; 294163953Srrs 295163953Srrs /* Max times I will send before we consider someone dead */ 296163953Srrs uint16_t max_send_times; 297163953Srrs 298163953Srrs uint16_t def_net_failure; 299163953Srrs 300224641Stuexen uint16_t def_net_pf_threshold; 301224641Stuexen 302163953Srrs /* number of streams to pre-open on a association */ 303163953Srrs uint16_t pre_open_stream_count; 304163953Srrs uint16_t max_open_streams_intome; 305163953Srrs 306163953Srrs /* random number generator */ 307163953Srrs uint32_t random_counter; 308163953Srrs uint8_t random_numbers[SCTP_SIGNATURE_ALOC_SIZE]; 309163953Srrs uint8_t random_store[SCTP_SIGNATURE_ALOC_SIZE]; 310163953Srrs 311163953Srrs /* 312163953Srrs * This timer is kept running per endpoint. When it fires it will 313163953Srrs * change the secret key. The default is once a hour 314163953Srrs */ 315163953Srrs struct sctp_timer signature_change; 316170056Srrs 317170056Srrs /* Zero copy full buffer timer */ 318170056Srrs struct sctp_timer zero_copy_timer; 319170181Srrs /* Zero copy app to transport (sendq) read repulse timer */ 320170181Srrs struct sctp_timer zero_copy_sendq_timer; 321171477Srrs uint32_t def_cookie_life; 322163953Srrs /* defaults to 0 */ 323163953Srrs int auto_close_time; 324163953Srrs uint32_t initial_sequence_debug; 325163953Srrs uint32_t adaptation_layer_indicator; 326246687Stuexen uint8_t adaptation_layer_indicator_provided; 327172091Srrs uint32_t store_at; 328217894Stuexen uint32_t max_burst; 329218186Srrs uint32_t fr_max_burst; 330225549Stuexen#ifdef INET6 331225549Stuexen uint32_t default_flowlabel; 332225549Stuexen#endif 333225549Stuexen uint8_t default_dscp; 334163953Srrs char current_secret_number; 335163953Srrs char last_secret_number; 336227755Stuexen uint16_t port; /* remote UDP encapsulation port */ 337163953Srrs}; 338163953Srrs 339163953Srrs#ifndef SCTP_ALIGNMENT 340163953Srrs#define SCTP_ALIGNMENT 32 341163953Srrs#endif 342163953Srrs 343163953Srrs#ifndef SCTP_ALIGNM1 344163953Srrs#define SCTP_ALIGNM1 (SCTP_ALIGNMENT-1) 345163953Srrs#endif 346163953Srrs 347163953Srrs#define sctp_lport ip_inp.inp.inp_lport 348163953Srrs 349171477Srrsstruct sctp_pcbtsn_rlog { 350171477Srrs uint32_t vtag; 351171477Srrs uint16_t strm; 352171477Srrs uint16_t seq; 353171477Srrs uint16_t sz; 354171477Srrs uint16_t flgs; 355171477Srrs}; 356171477Srrs 357171477Srrs#define SCTP_READ_LOG_SIZE 135 /* we choose the number to make a pcb a page */ 358171477Srrs 359171477Srrs 360163953Srrsstruct sctp_inpcb { 361168124Srrs /*- 362163953Srrs * put an inpcb in front of it all, kind of a waste but we need to 363163953Srrs * for compatability with all the other stuff. 364163953Srrs */ 365163953Srrs union { 366163953Srrs struct inpcb inp; 367163953Srrs char align[(sizeof(struct in6pcb) + SCTP_ALIGNM1) & 368163953Srrs ~SCTP_ALIGNM1]; 369163953Srrs } ip_inp; 370163953Srrs 371163953Srrs 372163953Srrs /* Socket buffer lock protects read_queue and of course sb_cc */ 373163953Srrs struct sctp_readhead read_queue; 374163953Srrs 375163953Srrs LIST_ENTRY(sctp_inpcb) sctp_list; /* lists all endpoints */ 376163953Srrs /* hash of all endpoints for model */ 377163953Srrs LIST_ENTRY(sctp_inpcb) sctp_hash; 378163953Srrs /* count of local addresses bound, 0 if bound all */ 379163953Srrs int laddr_count; 380167598Srrs 381167598Srrs /* list of addrs in use by the EP, NULL if bound-all */ 382163953Srrs struct sctpladdr sctp_addr_list; 383167598Srrs /* 384167598Srrs * used for source address selection rotation when we are subset 385167598Srrs * bound 386167598Srrs */ 387163953Srrs struct sctp_laddr *next_addr_touse; 388167598Srrs 389163953Srrs /* back pointer to our socket */ 390163953Srrs struct socket *sctp_socket; 391254248Stuexen uint64_t sctp_features; /* Feature flags */ 392163953Srrs uint32_t sctp_flags; /* INP state flag set */ 393171990Srrs uint32_t sctp_mobility_features; /* Mobility Feature flags */ 394163953Srrs struct sctp_pcb sctp_ep;/* SCTP ep data */ 395163953Srrs /* head of the hash of all associations */ 396163953Srrs struct sctpasochead *sctp_tcbhash; 397163953Srrs u_long sctp_hashmark; 398163953Srrs /* head of the list of all associations */ 399163953Srrs struct sctpasochead sctp_asoc_list; 400165220Srrs#ifdef SCTP_TRACK_FREED_ASOCS 401165220Srrs struct sctpasochead sctp_asoc_free_list; 402165220Srrs#endif 403163953Srrs struct sctp_iterator *inp_starting_point_for_iterator; 404163953Srrs uint32_t sctp_frag_point; 405163953Srrs uint32_t partial_delivery_point; 406163953Srrs uint32_t sctp_context; 407283724Stuexen uint32_t max_cwnd; 408233660Srrs uint8_t local_strreset_support; 409211944Stuexen uint32_t sctp_cmt_on_off; 410270356Stuexen uint8_t ecn_supported; 411270357Stuexen uint8_t prsctp_supported; 412270362Stuexen uint8_t auth_supported; 413270362Stuexen uint8_t asconf_supported; 414270361Stuexen uint8_t reconfig_supported; 415270359Stuexen uint8_t nrsack_supported; 416270360Stuexen uint8_t pktdrop_supported; 417170056Srrs struct sctp_nonpad_sndrcvinfo def_send; 418168124Srrs /*- 419168124Srrs * These three are here for the sosend_dgram 420168124Srrs * (pkt, pkt_last and control). 421168124Srrs * routine. However, I don't think anyone in 422168124Srrs * the current FreeBSD kernel calls this. So 423168124Srrs * they are candidates with sctp_sendm for 424168124Srrs * de-supporting. 425163953Srrs */ 426163953Srrs struct mbuf *pkt, *pkt_last; 427163953Srrs struct mbuf *control; 428163953Srrs struct mtx inp_mtx; 429163953Srrs struct mtx inp_create_mtx; 430163953Srrs struct mtx inp_rdata_mtx; 431163953Srrs int32_t refcount; 432167598Srrs uint32_t def_vrf_id; 433284633Stuexen uint16_t fibnum; 434165220Srrs uint32_t total_sends; 435165220Srrs uint32_t total_recvs; 436165220Srrs uint32_t last_abort_code; 437165220Srrs uint32_t total_nospaces; 438185694Srrs struct sctpasochead *sctp_asocidhash; 439185694Srrs u_long hashasocidmark; 440185694Srrs uint32_t sctp_associd_counter; 441185694Srrs 442171477Srrs#ifdef SCTP_ASOCLOG_OF_TSNS 443171477Srrs struct sctp_pcbtsn_rlog readlog[SCTP_READ_LOG_SIZE]; 444171477Srrs uint32_t readlog_index; 445171477Srrs#endif 446163953Srrs}; 447163953Srrs 448163953Srrsstruct sctp_tcb { 449163953Srrs struct socket *sctp_socket; /* back pointer to socket */ 450163953Srrs struct sctp_inpcb *sctp_ep; /* back pointer to ep */ 451163953Srrs LIST_ENTRY(sctp_tcb) sctp_tcbhash; /* next link in hash 452163953Srrs * table */ 453163953Srrs LIST_ENTRY(sctp_tcb) sctp_tcblist; /* list of all of the 454163953Srrs * TCB's */ 455185694Srrs LIST_ENTRY(sctp_tcb) sctp_tcbasocidhash; /* next link in asocid 456163953Srrs * hash table */ 457163953Srrs LIST_ENTRY(sctp_tcb) sctp_asocs; /* vtag hash list */ 458163953Srrs struct sctp_block_entry *block_entry; /* pointer locked by socket 459163953Srrs * send buffer */ 460163953Srrs struct sctp_association asoc; 461168124Srrs /*- 462163953Srrs * freed_by_sorcv_sincelast is protected by the sockbuf_lock NOT the 463163953Srrs * tcb_lock. Its special in this way to help avoid extra mutex calls 464163953Srrs * in the reading of data. 465163953Srrs */ 466163953Srrs uint32_t freed_by_sorcv_sincelast; 467165220Srrs uint32_t total_sends; 468165220Srrs uint32_t total_recvs; 469165220Srrs int freed_from_where; 470163953Srrs uint16_t rport; /* remote port in network format */ 471163953Srrs uint16_t resv; 472163953Srrs struct mtx tcb_mtx; 473163953Srrs struct mtx tcb_send_mtx; 474163953Srrs}; 475163953Srrs 476163953Srrs 477163953Srrs 478163953Srrs#include <netinet/sctp_lock_bsd.h> 479163953Srrs 480163953Srrs 481180387Srrs/* TODO where to put non-_KERNEL things for __Userspace__? */ 482180387Srrs#if defined(_KERNEL) || defined(__Userspace__) 483163953Srrs 484179783Srrs/* Attention Julian, this is the extern that 485179783Srrs * goes with the base info. sctp_pcb.c has 486179783Srrs * the real definition. 487179783Srrs */ 488197288SrrsVNET_DECLARE(struct sctp_base_info, system_base_info); 489163953Srrs 490178251Srrs#ifdef INET6 491179157Srrsint SCTP6_ARE_ADDR_EQUAL(struct sockaddr_in6 *a, struct sockaddr_in6 *b); 492163953Srrs 493178251Srrs#endif 494178251Srrs 495163953Srrsvoid sctp_fill_pcbinfo(struct sctp_pcbinfo *); 496163953Srrs 497167598Srrsstruct sctp_ifn * 498170205Srrs sctp_find_ifn(void *ifn, uint32_t ifn_index); 499167598Srrs 500167598Srrsstruct sctp_vrf *sctp_allocate_vrf(int vrfid); 501167598Srrsstruct sctp_vrf *sctp_find_vrf(uint32_t vrfid); 502170744Srrsvoid sctp_free_vrf(struct sctp_vrf *vrf); 503167598Srrs 504172091Srrs/*- 505172091Srrs * Change address state, can be used if 506172091Srrs * O/S supports telling transports about 507172091Srrs * changes to IFA/IFN's (link layer triggers). 508172091Srrs * If a ifn goes down, we will do src-addr-selection 509172091Srrs * and NOT use that, as a source address. This does 510172091Srrs * not stop the routing system from routing out 511172091Srrs * that interface, but we won't put it as a source. 512172091Srrs */ 513172091Srrsvoid sctp_mark_ifa_addr_down(uint32_t vrf_id, struct sockaddr *addr, const char *if_name, uint32_t ifn_index); 514172091Srrsvoid sctp_mark_ifa_addr_up(uint32_t vrf_id, struct sockaddr *addr, const char *if_name, uint32_t ifn_index); 515172091Srrs 516167598Srrsstruct sctp_ifa * 517167598Srrssctp_add_addr_to_vrf(uint32_t vrfid, 518167598Srrs void *ifn, uint32_t ifn_index, uint32_t ifn_type, 519167598Srrs const char *if_name, 520170205Srrs void *ifa, struct sockaddr *addr, uint32_t ifa_flags, 521170205Srrs int dynamic_add); 522167598Srrs 523170205Srrsvoid sctp_update_ifn_mtu(uint32_t ifn_index, uint32_t mtu); 524169352Srrs 525169352Srrsvoid sctp_free_ifn(struct sctp_ifn *sctp_ifnp); 526167598Srrsvoid sctp_free_ifa(struct sctp_ifa *sctp_ifap); 527167598Srrs 528169352Srrs 529169352Srrsvoid 530167598Srrssctp_del_addr_from_vrf(uint32_t vrfid, struct sockaddr *addr, 531172091Srrs uint32_t ifn_index, const char *if_name); 532167598Srrs 533167598Srrs 534167598Srrs 535163953Srrsstruct sctp_nets *sctp_findnet(struct sctp_tcb *, struct sockaddr *); 536163953Srrs 537167598Srrsstruct sctp_inpcb *sctp_pcb_findep(struct sockaddr *, int, int, uint32_t); 538163953Srrs 539170744Srrsint 540171477Srrssctp_inpcb_bind(struct socket *, struct sockaddr *, 541171572Srrs struct sctp_ifa *, struct thread *); 542163953Srrs 543163953Srrsstruct sctp_tcb * 544228653Stuexensctp_findassociation_addr(struct mbuf *, int, 545237715Stuexen struct sockaddr *, struct sockaddr *, 546163953Srrs struct sctphdr *, struct sctp_chunkhdr *, struct sctp_inpcb **, 547168299Srrs struct sctp_nets **, uint32_t vrf_id); 548163953Srrs 549163953Srrsstruct sctp_tcb * 550163953Srrssctp_findassociation_addr_sa(struct sockaddr *, 551167598Srrs struct sockaddr *, struct sctp_inpcb **, struct sctp_nets **, int, uint32_t); 552163953Srrs 553163953Srrsvoid 554163953Srrssctp_move_pcb_and_assoc(struct sctp_inpcb *, struct sctp_inpcb *, 555163953Srrs struct sctp_tcb *); 556163953Srrs 557168124Srrs/*- 558163953Srrs * For this call ep_addr, the to is the destination endpoint address of the 559163953Srrs * peer (relative to outbound). The from field is only used if the TCP model 560163953Srrs * is enabled and helps distingush amongst the subset bound (non-boundall). 561163953Srrs * The TCP model MAY change the actual ep field, this is why it is passed. 562163953Srrs */ 563163953Srrsstruct sctp_tcb * 564163953Srrssctp_findassociation_ep_addr(struct sctp_inpcb **, 565163953Srrs struct sockaddr *, struct sctp_nets **, struct sockaddr *, 566163953Srrs struct sctp_tcb *); 567163953Srrs 568163953Srrsstruct sctp_tcb * 569185694Srrs sctp_findasoc_ep_asocid_locked(struct sctp_inpcb *inp, sctp_assoc_t asoc_id, int want_lock); 570185694Srrs 571185694Srrsstruct sctp_tcb * 572163953Srrssctp_findassociation_ep_asocid(struct sctp_inpcb *, 573163953Srrs sctp_assoc_t, int); 574163953Srrs 575163953Srrsstruct sctp_tcb * 576237715Stuexensctp_findassociation_ep_asconf(struct mbuf *, int, struct sockaddr *, 577185694Srrs struct sctphdr *, struct sctp_inpcb **, struct sctp_nets **, uint32_t vrf_id); 578163953Srrs 579170205Srrsint sctp_inpcb_alloc(struct socket *so, uint32_t vrf_id); 580163953Srrs 581167598Srrsint sctp_is_address_on_local_host(struct sockaddr *addr, uint32_t vrf_id); 582163953Srrs 583163953Srrsvoid sctp_inpcb_free(struct sctp_inpcb *, int, int); 584163953Srrs 585163953Srrsstruct sctp_tcb * 586163953Srrssctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *, 587294215Stuexen int *, uint32_t, uint32_t, uint16_t, struct thread *); 588163953Srrs 589165220Srrsint sctp_free_assoc(struct sctp_inpcb *, struct sctp_tcb *, int, int); 590163953Srrs 591172091Srrs 592185694Srrsvoid sctp_delete_from_timewait(uint32_t, uint16_t, uint16_t); 593172091Srrs 594185694Srrsint sctp_is_in_timewait(uint32_t tag, uint16_t lport, uint16_t rport); 595173179Srrs 596166023Srrsvoid 597185694Srrs sctp_add_vtag_to_timewait(uint32_t tag, uint32_t time, uint16_t lport, uint16_t rport); 598166023Srrs 599169420Srrsvoid sctp_add_local_addr_ep(struct sctp_inpcb *, struct sctp_ifa *, uint32_t); 600163953Srrs 601169420Srrsvoid sctp_del_local_addr_ep(struct sctp_inpcb *, struct sctp_ifa *); 602163953Srrs 603224641Stuexenint sctp_add_remote_addr(struct sctp_tcb *, struct sockaddr *, struct sctp_nets **, int, int); 604163953Srrs 605163953Srrsvoid sctp_remove_net(struct sctp_tcb *, struct sctp_nets *); 606163953Srrs 607163953Srrsint sctp_del_remote_addr(struct sctp_tcb *, struct sockaddr *); 608163953Srrs 609163953Srrsvoid sctp_pcb_init(void); 610163953Srrs 611179783Srrsvoid sctp_pcb_finish(void); 612171943Srrs 613171572Srrsvoid sctp_add_local_addr_restricted(struct sctp_tcb *, struct sctp_ifa *); 614171572Srrsvoid sctp_del_local_addr_restricted(struct sctp_tcb *, struct sctp_ifa *); 615163953Srrs 616163953Srrsint 617237715Stuexensctp_load_addresses_from_init(struct sctp_tcb *, struct mbuf *, int, int, 618237715Stuexen struct sockaddr *, struct sockaddr *, struct sockaddr *); 619163953Srrs 620163953Srrsint 621163953Srrssctp_set_primary_addr(struct sctp_tcb *, struct sockaddr *, 622163953Srrs struct sctp_nets *); 623163953Srrs 624228653Stuexenint sctp_is_vtag_good(uint32_t, uint16_t lport, uint16_t rport, struct timeval *); 625163953Srrs 626163953Srrs/* void sctp_drain(void); */ 627163953Srrs 628163953Srrsint sctp_destination_is_reachable(struct sctp_tcb *, struct sockaddr *); 629163953Srrs 630181054Srrsint sctp_swap_inpcb_for_listen(struct sctp_inpcb *inp); 631181054Srrs 632168124Srrs/*- 633163953Srrs * Null in last arg inpcb indicate run on ALL ep's. Specific inp in last arg 634163953Srrs * indicates run on ONLY assoc's of the specified endpoint. 635163953Srrs */ 636163953Srrsint 637167598Srrssctp_initiate_iterator(inp_func inpf, 638167598Srrs asoc_func af, 639167598Srrs inp_func inpe, 640167598Srrs uint32_t, uint32_t, 641167598Srrs uint32_t, void *, 642167598Srrs uint32_t, 643167598Srrs end_func ef, 644167598Srrs struct sctp_inpcb *, 645167598Srrs uint8_t co_off); 646163953Srrs 647218211Srrs#if defined(__FreeBSD__) && defined(SCTP_MCORE_INPUT) && defined(SMP) 648218211Srrsvoid 649218211Srrs sctp_queue_to_mcore(struct mbuf *m, int off, int cpu_to_use); 650218211Srrs 651218211Srrs#endif 652218211Srrs 653163953Srrs#endif /* _KERNEL */ 654163953Srrs#endif /* !__sctp_pcb_h__ */ 655