netwerk/sctp/src/netinet/sctp_pcb.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/sctp/src/netinet/sctp_pcb.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,874 @@
     1.4 +/*-
     1.5 + * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
     1.6 + * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
     1.7 + * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
     1.8 + *
     1.9 + * Redistribution and use in source and binary forms, with or without
    1.10 + * modification, are permitted provided that the following conditions are met:
    1.11 + *
    1.12 + * a) Redistributions of source code must retain the above copyright notice,
    1.13 + *    this list of conditions and the following disclaimer.
    1.14 + *
    1.15 + * b) Redistributions in binary form must reproduce the above copyright
    1.16 + *    notice, this list of conditions and the following disclaimer in
    1.17 + *    the documentation and/or other materials provided with the distribution.
    1.18 + *
    1.19 + * c) Neither the name of Cisco Systems, Inc. nor the names of its
    1.20 + *    contributors may be used to endorse or promote products derived
    1.21 + *    from this software without specific prior written permission.
    1.22 + *
    1.23 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.24 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    1.25 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.26 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    1.27 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    1.28 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    1.29 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    1.30 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    1.31 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    1.32 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
    1.33 + * THE POSSIBILITY OF SUCH DAMAGE.
    1.34 + */
    1.35 +
    1.36 +#ifdef __FreeBSD__
    1.37 +#include <sys/cdefs.h>
    1.38 +__FBSDID("$FreeBSD: head/sys/netinet/sctp_pcb.h 254248 2013-08-12 13:52:15Z tuexen $");
    1.39 +#endif
    1.40 +
    1.41 +#ifndef _NETINET_SCTP_PCB_H_
    1.42 +#define _NETINET_SCTP_PCB_H_
    1.43 +
    1.44 +#include <netinet/sctp_os.h>
    1.45 +#include <netinet/sctp.h>
    1.46 +#include <netinet/sctp_constants.h>
    1.47 +#include <netinet/sctp_sysctl.h>
    1.48 +
    1.49 +LIST_HEAD(sctppcbhead, sctp_inpcb);
    1.50 +LIST_HEAD(sctpasochead, sctp_tcb);
    1.51 +LIST_HEAD(sctpladdr, sctp_laddr);
    1.52 +LIST_HEAD(sctpvtaghead, sctp_tagblock);
    1.53 +LIST_HEAD(sctp_vrflist, sctp_vrf);
    1.54 +LIST_HEAD(sctp_ifnlist, sctp_ifn);
    1.55 +LIST_HEAD(sctp_ifalist, sctp_ifa);
    1.56 +TAILQ_HEAD(sctp_readhead, sctp_queued_to_read);
    1.57 +TAILQ_HEAD(sctp_streamhead, sctp_stream_queue_pending);
    1.58 +
    1.59 +#include <netinet/sctp_structs.h>
    1.60 +#include <netinet/sctp_auth.h>
    1.61 +
    1.62 +#define SCTP_PCBHASH_ALLADDR(port, mask) (port & mask)
    1.63 +#define SCTP_PCBHASH_ASOC(tag, mask) (tag & mask)
    1.64 +
    1.65 +struct sctp_vrf {
    1.66 +	LIST_ENTRY (sctp_vrf) next_vrf;
    1.67 +	struct sctp_ifalist *vrf_addr_hash;
    1.68 +	struct sctp_ifnlist ifnlist;
    1.69 +	uint32_t vrf_id;
    1.70 +	uint32_t tbl_id_v4;		/* default v4 table id */
    1.71 +	uint32_t tbl_id_v6;		/* default v6 table id */
    1.72 +	uint32_t total_ifa_count;
    1.73 +	u_long   vrf_addr_hashmark;
    1.74 +	uint32_t refcount;
    1.75 +};
    1.76 +
    1.77 +struct sctp_ifn {
    1.78 +	struct sctp_ifalist ifalist;
    1.79 +	struct sctp_vrf *vrf;
    1.80 +	LIST_ENTRY(sctp_ifn) next_ifn;
    1.81 +	LIST_ENTRY(sctp_ifn) next_bucket;
    1.82 +	void     *ifn_p;	/* never access without appropriate lock */
    1.83 +	uint32_t ifn_mtu;
    1.84 +	uint32_t ifn_type;
    1.85 +	uint32_t ifn_index;	/* shorthand way to look at ifn for reference */
    1.86 +	uint32_t refcount;	/* number of reference held should be >= ifa_count */
    1.87 +	uint32_t ifa_count;	/* IFA's we hold (in our list - ifalist)*/
    1.88 +	uint32_t num_v6;	/* number of v6 addresses */
    1.89 +	uint32_t num_v4;	/* number of v4 addresses */
    1.90 +	uint32_t registered_af;	/* registered address family for i/f events */
    1.91 +	char     ifn_name[SCTP_IFNAMSIZ];
    1.92 +};
    1.93 +
    1.94 +/* SCTP local IFA flags */
    1.95 +#define SCTP_ADDR_VALID         0x00000001	/* its up and active */
    1.96 +#define SCTP_BEING_DELETED      0x00000002	/* being deleted,
    1.97 +						 * when refcount = 0. Note
    1.98 +						 * that it is pulled from the ifn list
    1.99 +						 * and ifa_p is nulled right away but
   1.100 +						 * it cannot be freed until the last *net
   1.101 +						 * pointing to it is deleted.
   1.102 +						 */
   1.103 +#define SCTP_ADDR_DEFER_USE     0x00000004	/* Hold off using this one */
   1.104 +#define SCTP_ADDR_IFA_UNUSEABLE 0x00000008
   1.105 +
   1.106 +struct sctp_ifa {
   1.107 +	LIST_ENTRY(sctp_ifa) next_ifa;
   1.108 +	LIST_ENTRY(sctp_ifa) next_bucket;
   1.109 +	struct sctp_ifn *ifn_p;	/* back pointer to parent ifn */
   1.110 +	void    *ifa;		/* pointer to ifa, needed for flag
   1.111 +				 * update for that we MUST lock
   1.112 +				 * appropriate locks. This is for V6.
   1.113 +				 */
   1.114 +	union sctp_sockstore address;
   1.115 +	uint32_t refcount;	/* number of folks refering to this */
   1.116 +     	uint32_t flags;
   1.117 +	uint32_t localifa_flags;
   1.118 +	uint32_t vrf_id;	/* vrf_id of this addr (for deleting) */
   1.119 +	uint8_t src_is_loop;
   1.120 +	uint8_t src_is_priv;
   1.121 +	uint8_t src_is_glob;
   1.122 +	uint8_t resv;
   1.123 +};
   1.124 +
   1.125 +struct sctp_laddr {
   1.126 +	LIST_ENTRY(sctp_laddr) sctp_nxt_addr;	/* next in list */
   1.127 +	struct sctp_ifa *ifa;
   1.128 +	uint32_t action;		/* Used during asconf and adding
   1.129 +					 * if no-zero src-addr selection will
   1.130 +					 * not consider this address.
   1.131 +					 */
   1.132 +	struct timeval start_time;      /* time when this address was created */
   1.133 +};
   1.134 +
   1.135 +struct sctp_block_entry {
   1.136 +	int error;
   1.137 +};
   1.138 +
   1.139 +struct sctp_timewait {
   1.140 +	uint32_t tv_sec_at_expire;	/* the seconds from boot to expire */
   1.141 +        uint32_t v_tag;		        /* the vtag that can not be reused */
   1.142 +        uint16_t lport;                 /* the local port used in vtag */
   1.143 +        uint16_t rport;                 /* the remote port used in vtag */
   1.144 +};
   1.145 +
   1.146 +struct sctp_tagblock {
   1.147 +	LIST_ENTRY(sctp_tagblock) sctp_nxt_tagblock;
   1.148 +	struct sctp_timewait vtag_block[SCTP_NUMBER_IN_VTAG_BLOCK];
   1.149 +};
   1.150 +
   1.151 +
   1.152 +struct sctp_epinfo {
   1.153 +#if defined(__FreeBSD__)
   1.154 +#ifdef INET
   1.155 +	struct socket *udp4_tun_socket;
   1.156 +#endif
   1.157 +#ifdef INET6
   1.158 +	struct socket *udp6_tun_socket;
   1.159 +#endif
   1.160 +#endif
   1.161 +	struct sctpasochead *sctp_asochash;
   1.162 +	u_long hashasocmark;
   1.163 +
   1.164 +	struct sctppcbhead *sctp_ephash;
   1.165 +	u_long hashmark;
   1.166 +
   1.167 +	/*-
   1.168 +	 * The TCP model represents a substantial overhead in that we get an
   1.169 +	 * additional hash table to keep explicit connections in. The
   1.170 +	 * listening TCP endpoint will exist in the usual ephash above and
   1.171 +	 * accept only INIT's. It will be incapable of sending off an INIT.
   1.172 +	 * When a dg arrives we must look in the normal ephash. If we find a
   1.173 +	 * TCP endpoint that will tell us to go to the specific endpoint
   1.174 +	 * hash and re-hash to find the right assoc/socket. If we find a UDP
   1.175 +	 * model socket we then must complete the lookup. If this fails,
   1.176 +	 * i.e. no association can be found then we must continue to see if
   1.177 +	 * a sctp_peeloff()'d socket is in the tcpephash (a spun off socket
   1.178 +	 * acts like a TCP model connected socket).
   1.179 +	 */
   1.180 +	struct sctppcbhead *sctp_tcpephash;
   1.181 +	u_long hashtcpmark;
   1.182 +	uint32_t hashtblsize;
   1.183 +
   1.184 +	struct sctp_vrflist *sctp_vrfhash;
   1.185 +	u_long hashvrfmark;
   1.186 +
   1.187 +	struct sctp_ifnlist *vrf_ifn_hash;
   1.188 +	u_long   vrf_ifn_hashmark;
   1.189 +
   1.190 +	struct sctppcbhead listhead;
   1.191 +	struct sctpladdr addr_wq;
   1.192 +
   1.193 +#if defined(__APPLE__)
   1.194 +	struct inpcbhead inplisthead;
   1.195 +	struct inpcbinfo sctbinfo;
   1.196 +#endif
   1.197 +	/* ep zone info */
   1.198 +	sctp_zone_t ipi_zone_ep;
   1.199 +	sctp_zone_t ipi_zone_asoc;
   1.200 +	sctp_zone_t ipi_zone_laddr;
   1.201 +	sctp_zone_t ipi_zone_net;
   1.202 +	sctp_zone_t ipi_zone_chunk;
   1.203 +	sctp_zone_t ipi_zone_readq;
   1.204 +	sctp_zone_t ipi_zone_strmoq;
   1.205 +	sctp_zone_t ipi_zone_asconf;
   1.206 +	sctp_zone_t ipi_zone_asconf_ack;
   1.207 +
   1.208 +#if defined(__FreeBSD__) && __FreeBSD_version >= 503000
   1.209 +#if __FreeBSD_version <= 602000
   1.210 +	struct mtx ipi_ep_mtx;
   1.211 +#else
   1.212 +	struct rwlock ipi_ep_mtx;
   1.213 +#endif
   1.214 +	struct mtx ipi_iterator_wq_mtx;
   1.215 +#if __FreeBSD_version <= 602000
   1.216 +	struct mtx ipi_addr_mtx;
   1.217 +#else
   1.218 +	struct rwlock ipi_addr_mtx;
   1.219 +#endif
   1.220 +	struct mtx ipi_pktlog_mtx;
   1.221 +	struct mtx wq_addr_mtx;
   1.222 +#elif defined(SCTP_PROCESS_LEVEL_LOCKS)
   1.223 +	userland_mutex_t ipi_ep_mtx;
   1.224 +	userland_mutex_t ipi_addr_mtx;
   1.225 +	userland_mutex_t ipi_count_mtx;
   1.226 +	userland_mutex_t ipi_pktlog_mtx;
   1.227 +	userland_mutex_t wq_addr_mtx;
   1.228 +#elif defined(__APPLE__)
   1.229 +#ifdef _KERN_LOCKS_H_
   1.230 +	lck_mtx_t *ipi_addr_mtx;
   1.231 +	lck_mtx_t *ipi_count_mtx;
   1.232 +	lck_mtx_t *ipi_pktlog_mtx;
   1.233 +	lck_mtx_t *logging_mtx;
   1.234 +	lck_mtx_t *wq_addr_mtx;
   1.235 +#else
   1.236 +	void *ipi_count_mtx;
   1.237 +	void *logging_mtx;
   1.238 +#endif /* _KERN_LOCKS_H_ */
   1.239 +#elif defined(__Windows__)
   1.240 +	struct rwlock ipi_ep_lock;
   1.241 +	struct rwlock ipi_addr_lock;
   1.242 +	struct spinlock ipi_pktlog_mtx;
   1.243 +	struct rwlock wq_addr_mtx;
   1.244 +#elif defined(__Userspace__)
   1.245 +    /* TODO decide on __Userspace__ locks */
   1.246 +#endif
   1.247 +	uint32_t ipi_count_ep;
   1.248 +
   1.249 +	/* assoc/tcb zone info */
   1.250 +	uint32_t ipi_count_asoc;
   1.251 +
   1.252 +	/* local addrlist zone info */
   1.253 +	uint32_t ipi_count_laddr;
   1.254 +
   1.255 +	/* remote addrlist zone info */
   1.256 +	uint32_t ipi_count_raddr;
   1.257 +
   1.258 +	/* chunk structure list for output */
   1.259 +	uint32_t ipi_count_chunk;
   1.260 +
   1.261 +	/* socket queue zone info */
   1.262 +	uint32_t ipi_count_readq;
   1.263 +
   1.264 +	/* socket queue zone info */
   1.265 +	uint32_t ipi_count_strmoq;
   1.266 +
   1.267 +	/* Number of vrfs */
   1.268 +	uint32_t ipi_count_vrfs;
   1.269 +
   1.270 +        /* Number of ifns */
   1.271 +	uint32_t ipi_count_ifns;
   1.272 +
   1.273 +        /* Number of ifas */
   1.274 +	uint32_t ipi_count_ifas;
   1.275 +
   1.276 +	/* system wide number of free chunks hanging around */
   1.277 +	uint32_t ipi_free_chunks;
   1.278 +	uint32_t ipi_free_strmoq;
   1.279 +
   1.280 +	struct sctpvtaghead vtag_timewait[SCTP_STACK_VTAG_HASH_SIZE];
   1.281 +
   1.282 +	/* address work queue handling */
   1.283 +	struct sctp_timer addr_wq_timer;
   1.284 +
   1.285 +#if defined(_SCTP_NEEDS_CALLOUT_) || defined(_USER_SCTP_NEEDS_CALLOUT_)
   1.286 +	struct calloutlist callqueue;
   1.287 +#endif
   1.288 +};
   1.289 +
   1.290 +
   1.291 +struct sctp_base_info {
   1.292 +	/* All static structures that
   1.293 +	 * anchor the system must be here.
   1.294 +	 */
   1.295 +	struct sctp_epinfo sctppcbinfo;
   1.296 +#if defined(__FreeBSD__) && defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
   1.297 +	struct sctpstat    *sctpstat;
   1.298 +#else
   1.299 +	struct sctpstat    sctpstat;
   1.300 +#endif
   1.301 +	struct sctp_sysctl sctpsysctl;
   1.302 +	uint8_t first_time;
   1.303 +	char sctp_pcb_initialized;
   1.304 +#if defined(SCTP_PACKET_LOGGING)
   1.305 +	int packet_log_writers;
   1.306 +	int packet_log_end;
   1.307 +	uint8_t packet_log_buffer[SCTP_PACKET_LOG_SIZE];
   1.308 +#endif
   1.309 +#if defined(__APPLE__)
   1.310 +	int sctp_main_timer_ticks;
   1.311 +#endif
   1.312 +#if defined(__Userspace__)
   1.313 +	userland_mutex_t timer_mtx;
   1.314 +	userland_thread_t timer_thread;
   1.315 +	uint8_t timer_thread_should_exit;
   1.316 +#if !defined(__Userspace_os_Windows)
   1.317 +#if defined(INET) || defined(INET6)
   1.318 +	int userspace_route;
   1.319 +	userland_thread_t recvthreadroute;
   1.320 +#endif
   1.321 +#endif
   1.322 +#ifdef INET
   1.323 +	int userspace_rawsctp;
   1.324 +	int userspace_udpsctp;
   1.325 +	userland_thread_t recvthreadraw;
   1.326 +	userland_thread_t recvthreadudp;
   1.327 +#endif
   1.328 +#ifdef INET6
   1.329 +	int userspace_rawsctp6;
   1.330 +	int userspace_udpsctp6;
   1.331 +	userland_thread_t recvthreadraw6;
   1.332 +	userland_thread_t recvthreadudp6;
   1.333 +#endif
   1.334 +	int (*conn_output)(void *addr, void *buffer, size_t length, uint8_t tos, uint8_t set_df);
   1.335 +	void (*debug_printf)(const char *format, ...);
   1.336 +#endif
   1.337 +};
   1.338 +
   1.339 +/*-
   1.340 + * Here we have all the relevant information for each SCTP entity created. We
   1.341 + * will need to modify this as approprate. We also need to figure out how to
   1.342 + * access /dev/random.
   1.343 + */
   1.344 +struct sctp_pcb {
   1.345 +	unsigned int time_of_secret_change;	/* number of seconds from
   1.346 +						 * timeval.tv_sec */
   1.347 +	uint32_t secret_key[SCTP_HOW_MANY_SECRETS][SCTP_NUMBER_OF_SECRETS];
   1.348 +	unsigned int size_of_a_cookie;
   1.349 +
   1.350 +	unsigned int sctp_timeoutticks[SCTP_NUM_TMRS];
   1.351 +	unsigned int sctp_minrto;
   1.352 +	unsigned int sctp_maxrto;
   1.353 +	unsigned int initial_rto;
   1.354 +	int initial_init_rto_max;
   1.355 +
   1.356 +	unsigned int sctp_sack_freq;
   1.357 +	uint32_t sctp_sws_sender;
   1.358 +	uint32_t sctp_sws_receiver;
   1.359 +
   1.360 +	uint32_t sctp_default_cc_module;
   1.361 +	uint32_t sctp_default_ss_module;
   1.362 +	/* authentication related fields */
   1.363 +	struct sctp_keyhead shared_keys;
   1.364 +	sctp_auth_chklist_t *local_auth_chunks;
   1.365 +	sctp_hmaclist_t *local_hmacs;
   1.366 +	uint16_t default_keyid;
   1.367 +
   1.368 +	/* various thresholds */
   1.369 +	/* Max times I will init at a guy */
   1.370 +	uint16_t max_init_times;
   1.371 +
   1.372 +	/* Max times I will send before we consider someone dead */
   1.373 +	uint16_t max_send_times;
   1.374 +
   1.375 +	uint16_t def_net_failure;
   1.376 +
   1.377 +	uint16_t def_net_pf_threshold;
   1.378 +
   1.379 +	/* number of streams to pre-open on a association */
   1.380 +	uint16_t pre_open_stream_count;
   1.381 +	uint16_t max_open_streams_intome;
   1.382 +
   1.383 +	/* random number generator */
   1.384 +	uint32_t random_counter;
   1.385 +	uint8_t random_numbers[SCTP_SIGNATURE_ALOC_SIZE];
   1.386 +	uint8_t random_store[SCTP_SIGNATURE_ALOC_SIZE];
   1.387 +
   1.388 +	/*
   1.389 +	 * This timer is kept running per endpoint.  When it fires it will
   1.390 +	 * change the secret key.  The default is once a hour
   1.391 +	 */
   1.392 +	struct sctp_timer signature_change;
   1.393 +
   1.394 +	/* Zero copy full buffer timer */
   1.395 +	struct sctp_timer zero_copy_timer;
   1.396 +        /* Zero copy app to transport (sendq) read repulse timer */
   1.397 +	struct sctp_timer zero_copy_sendq_timer;
   1.398 +	uint32_t def_cookie_life;
   1.399 +	/* defaults to 0 */
   1.400 +	int auto_close_time;
   1.401 +	uint32_t initial_sequence_debug;
   1.402 +	uint32_t adaptation_layer_indicator;
   1.403 +	uint8_t adaptation_layer_indicator_provided;
   1.404 +	uint32_t store_at;
   1.405 +	uint32_t max_burst;
   1.406 +	uint32_t fr_max_burst;
   1.407 +#ifdef INET6
   1.408 +	uint32_t default_flowlabel;
   1.409 +#endif
   1.410 +	uint8_t default_dscp;
   1.411 +	char current_secret_number;
   1.412 +	char last_secret_number;
   1.413 +	uint16_t port; /* remote UDP encapsulation port */
   1.414 +};
   1.415 +
   1.416 +#ifndef SCTP_ALIGNMENT
   1.417 +#define SCTP_ALIGNMENT 32
   1.418 +#endif
   1.419 +
   1.420 +#ifndef SCTP_ALIGNM1
   1.421 +#define SCTP_ALIGNM1 (SCTP_ALIGNMENT-1)
   1.422 +#endif
   1.423 +
   1.424 +#define sctp_lport ip_inp.inp.inp_lport
   1.425 +
   1.426 +struct sctp_pcbtsn_rlog {
   1.427 +	uint32_t vtag;
   1.428 +	uint16_t strm;
   1.429 +	uint16_t seq;
   1.430 +	uint16_t sz;
   1.431 +	uint16_t flgs;
   1.432 +};
   1.433 +#define SCTP_READ_LOG_SIZE 135	/* we choose the number to make a pcb a page */
   1.434 +
   1.435 +
   1.436 +struct sctp_inpcb {
   1.437 +	/*-
   1.438 +	 * put an inpcb in front of it all, kind of a waste but we need to
   1.439 +	 * for compatability with all the other stuff.
   1.440 +	 */
   1.441 +	union {
   1.442 +		struct inpcb inp;
   1.443 +		char align[(sizeof(struct in6pcb) + SCTP_ALIGNM1) &
   1.444 +		        ~SCTP_ALIGNM1];
   1.445 +	}     ip_inp;
   1.446 +
   1.447 +#if defined(__APPLE__)
   1.448 +	/* leave some space in case i386 inpcb is bigger than ppc */
   1.449 +	uint8_t		padding[128];
   1.450 +#endif
   1.451 +
   1.452 +	/* Socket buffer lock protects read_queue and of course sb_cc */
   1.453 +	struct sctp_readhead read_queue;
   1.454 +
   1.455 +	LIST_ENTRY(sctp_inpcb) sctp_list;	/* lists all endpoints */
   1.456 +        /* hash of all endpoints for model */
   1.457 +	LIST_ENTRY(sctp_inpcb) sctp_hash;
   1.458 +	/* count of local addresses bound, 0 if bound all */
   1.459 +	int laddr_count;
   1.460 +
   1.461 +	/* list of addrs in use by the EP, NULL if bound-all */
   1.462 +	struct sctpladdr sctp_addr_list;
   1.463 +	/* used for source address selection rotation when we are subset bound */
   1.464 +	struct sctp_laddr *next_addr_touse;
   1.465 +
   1.466 +	/* back pointer to our socket */
   1.467 +	struct socket *sctp_socket;
   1.468 +	uint64_t sctp_features;	/* Feature flags */
   1.469 +	uint32_t sctp_flags;	/* INP state flag set */
   1.470 +	uint32_t sctp_mobility_features; /* Mobility  Feature flags */
   1.471 +	struct sctp_pcb sctp_ep;/* SCTP ep data */
   1.472 +	/* head of the hash of all associations */
   1.473 +	struct sctpasochead *sctp_tcbhash;
   1.474 +	u_long sctp_hashmark;
   1.475 +	/* head of the list of all associations */
   1.476 +	struct sctpasochead sctp_asoc_list;
   1.477 +#ifdef SCTP_TRACK_FREED_ASOCS
   1.478 +	struct sctpasochead sctp_asoc_free_list;
   1.479 +#endif
   1.480 +	struct sctp_iterator *inp_starting_point_for_iterator;
   1.481 +	uint32_t sctp_frag_point;
   1.482 +	uint32_t partial_delivery_point;
   1.483 +	uint32_t sctp_context;
   1.484 +	uint8_t local_strreset_support;
   1.485 +	uint32_t sctp_cmt_on_off;
   1.486 +	uint32_t sctp_ecn_enable;
   1.487 +	struct sctp_nonpad_sndrcvinfo def_send;
   1.488 +	/*-
   1.489 +	 * These three are here for the sosend_dgram
   1.490 +	 * (pkt, pkt_last and control).
   1.491 +	 * routine. However, I don't think anyone in
   1.492 +	 * the current FreeBSD kernel calls this. So
   1.493 +	 * they are candidates with sctp_sendm for
   1.494 +	 * de-supporting.
   1.495 +	 */
   1.496 +#ifdef __Panda__
   1.497 +	pakhandle_type pak_to_read;
   1.498 +	pakhandle_type pak_to_read_sendq;
   1.499 +#endif
   1.500 +	struct mbuf *pkt, *pkt_last;
   1.501 +	struct mbuf *control;
   1.502 +#if !(defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__))
   1.503 +#ifndef INP_IPV6
   1.504 +#define INP_IPV6	0x1
   1.505 +#endif
   1.506 +#ifndef INP_IPV4
   1.507 +#define INP_IPV4	0x2
   1.508 +#endif
   1.509 +	uint8_t inp_vflag;
   1.510 +                               /* TODO __Userspace__ where is our inp_vlag going to be? */
   1.511 +	uint8_t inp_ip_ttl;
   1.512 +        uint8_t inp_ip_tos;    /* defined as macro in user_inpcb.h */
   1.513 +	uint8_t inp_ip_resv;
   1.514 +#endif
   1.515 +#if defined(__FreeBSD__) && __FreeBSD_version >= 503000
   1.516 +	struct mtx inp_mtx;
   1.517 +	struct mtx inp_create_mtx;
   1.518 +	struct mtx inp_rdata_mtx;
   1.519 +	int32_t refcount;
   1.520 +#elif defined(SCTP_PROCESS_LEVEL_LOCKS)
   1.521 +	userland_mutex_t inp_mtx;
   1.522 +	userland_mutex_t inp_create_mtx;
   1.523 +	userland_mutex_t inp_rdata_mtx;
   1.524 +	int32_t refcount;
   1.525 +#elif defined(__APPLE__)
   1.526 +#if defined(SCTP_APPLE_RWLOCK)
   1.527 +	lck_rw_t *inp_mtx;
   1.528 +#else
   1.529 +	lck_mtx_t *inp_mtx;
   1.530 +#endif
   1.531 +	lck_mtx_t *inp_create_mtx;
   1.532 +	lck_mtx_t *inp_rdata_mtx;
   1.533 +#elif defined(__Windows__)
   1.534 +	struct rwlock inp_lock;
   1.535 +	struct spinlock inp_create_lock;
   1.536 +	struct spinlock inp_rdata_lock;
   1.537 +	int32_t refcount;
   1.538 +#elif defined(__Userspace__)
   1.539 +    /* TODO decide on __Userspace__ locks */
   1.540 +	int32_t refcount;
   1.541 +#endif
   1.542 +#if defined(__APPLE__)
   1.543 +	int32_t refcount;
   1.544 +
   1.545 +	uint32_t lock_caller1;
   1.546 +	uint32_t lock_caller2;
   1.547 +	uint32_t lock_caller3;
   1.548 +	uint32_t unlock_caller1;
   1.549 +	uint32_t unlock_caller2;
   1.550 +	uint32_t unlock_caller3;
   1.551 +	uint32_t getlock_caller1;
   1.552 +	uint32_t getlock_caller2;
   1.553 +	uint32_t getlock_caller3;
   1.554 +	uint32_t gen_count;
   1.555 +	uint32_t lock_gen_count;
   1.556 +	uint32_t unlock_gen_count;
   1.557 +	uint32_t getlock_gen_count;
   1.558 +
   1.559 +	uint32_t i_am_here_file;
   1.560 +	uint32_t i_am_here_line;
   1.561 +#endif
   1.562 +	uint32_t def_vrf_id;
   1.563 +#ifdef SCTP_MVRF
   1.564 +	uint32_t *m_vrf_ids;
   1.565 +	uint32_t num_vrfs;
   1.566 +	uint32_t vrf_size;
   1.567 +#endif
   1.568 +	uint32_t total_sends;
   1.569 +	uint32_t total_recvs;
   1.570 +	uint32_t last_abort_code;
   1.571 +	uint32_t total_nospaces;
   1.572 +	struct sctpasochead *sctp_asocidhash;
   1.573 +	u_long hashasocidmark;
   1.574 +        uint32_t sctp_associd_counter;
   1.575 +
   1.576 +#ifdef SCTP_ASOCLOG_OF_TSNS
   1.577 +	struct sctp_pcbtsn_rlog readlog[SCTP_READ_LOG_SIZE];
   1.578 +	uint32_t readlog_index;
   1.579 +#endif
   1.580 +#if defined(__Userspace__)
   1.581 +	void *ulp_info;
   1.582 +	int (*recv_callback)(struct socket *, union sctp_sockstore, void *, size_t,
   1.583 +                             struct sctp_rcvinfo, int, void *);
   1.584 +	uint32_t send_sb_threshold;
   1.585 +	int (*send_callback)(struct socket *, uint32_t);
   1.586 +#endif
   1.587 +};
   1.588 +
   1.589 +#if defined(__Userspace__)
   1.590 +int register_recv_cb (struct socket *,
   1.591 +                      int (*)(struct socket *, union sctp_sockstore, void *, size_t,
   1.592 +                              struct sctp_rcvinfo, int, void *));
   1.593 +int register_send_cb (struct socket *, uint32_t, int (*)(struct socket *, uint32_t));
   1.594 +int register_ulp_info (struct socket *, void *);
   1.595 +
   1.596 +#endif
   1.597 +struct sctp_tcb {
   1.598 +	struct socket *sctp_socket;	/* back pointer to socket */
   1.599 +	struct sctp_inpcb *sctp_ep;	/* back pointer to ep */
   1.600 +	LIST_ENTRY(sctp_tcb) sctp_tcbhash;	/* next link in hash
   1.601 +						 * table */
   1.602 +        LIST_ENTRY(sctp_tcb) sctp_tcblist;	/* list of all of the
   1.603 +						 * TCB's */
   1.604 +        LIST_ENTRY(sctp_tcb) sctp_tcbasocidhash;	/* next link in asocid
   1.605 +							 * hash table
   1.606 +							 */
   1.607 +        LIST_ENTRY(sctp_tcb) sctp_asocs;	/* vtag hash list */
   1.608 +	struct sctp_block_entry *block_entry;	/* pointer locked by  socket
   1.609 +						 * send buffer */
   1.610 +	struct sctp_association asoc;
   1.611 +	/*-
   1.612 +	 * freed_by_sorcv_sincelast is protected by the sockbuf_lock NOT the
   1.613 +	 * tcb_lock. Its special in this way to help avoid extra mutex calls
   1.614 +	 * in the reading of data.
   1.615 +	 */
   1.616 +	uint32_t freed_by_sorcv_sincelast;
   1.617 +	uint32_t total_sends;
   1.618 +	uint32_t total_recvs;
   1.619 +	int freed_from_where;
   1.620 +	uint16_t rport;		/* remote port in network format */
   1.621 +	uint16_t resv;
   1.622 +#if defined(__FreeBSD__) && __FreeBSD_version >= 503000
   1.623 +	struct mtx tcb_mtx;
   1.624 +	struct mtx tcb_send_mtx;
   1.625 +#elif defined(SCTP_PROCESS_LEVEL_LOCKS)
   1.626 +	userland_mutex_t tcb_mtx;
   1.627 +	userland_mutex_t tcb_send_mtx;
   1.628 +#elif defined(__APPLE__)
   1.629 +	lck_mtx_t* tcb_mtx;
   1.630 +	lck_mtx_t* tcb_send_mtx;
   1.631 +#elif defined(__Windows__)
   1.632 +	struct spinlock tcb_lock;
   1.633 +	struct spinlock tcb_send_lock;
   1.634 +#elif defined(__Userspace__)
   1.635 +    /* TODO decide on __Userspace__ locks */
   1.636 +#endif
   1.637 +#if defined(__APPLE__)
   1.638 +	uint32_t caller1;
   1.639 +	uint32_t caller2;
   1.640 +	uint32_t caller3;
   1.641 +#endif
   1.642 +};
   1.643 +
   1.644 +
   1.645 +#if defined(__FreeBSD__) && __FreeBSD_version >= 503000
   1.646 +
   1.647 +#include <netinet/sctp_lock_bsd.h>
   1.648 +
   1.649 +#elif defined(__APPLE__)
   1.650 +/*
   1.651 + * Apple MacOS X 10.4 "Tiger"
   1.652 + */
   1.653 +
   1.654 +#include <netinet/sctp_lock_apple_fg.h>
   1.655 +
   1.656 +#elif defined(SCTP_PROCESS_LEVEL_LOCKS)
   1.657 +
   1.658 +#include <netinet/sctp_process_lock.h>
   1.659 +
   1.660 +#elif defined(__Windows__)
   1.661 +
   1.662 +#include <netinet/sctp_lock_windows.h>
   1.663 +
   1.664 +#elif defined(__Userspace__)
   1.665 +
   1.666 +#include <netinet/sctp_lock_userspace.h>
   1.667 +
   1.668 +#else
   1.669 +/*
   1.670 + * Pre-5.x FreeBSD, and others.
   1.671 + */
   1.672 +#include <netinet/sctp_lock_empty.h>
   1.673 +#endif
   1.674 +
   1.675 +/* TODO where to put non-_KERNEL things for __Userspace__? */
   1.676 +#if defined(_KERNEL) || defined(__Userspace__)
   1.677 +
   1.678 +/* Attention Julian, this is the extern that
   1.679 + * goes with the base info. sctp_pcb.c has
   1.680 + * the real definition.
   1.681 + */
   1.682 +#if defined(__FreeBSD__) && __FreeBSD_version >= 801000
   1.683 +VNET_DECLARE(struct sctp_base_info, system_base_info) ;
   1.684 +#else
   1.685 +extern struct sctp_base_info system_base_info;
   1.686 +#endif
   1.687 +
   1.688 +#ifdef INET6
   1.689 +int SCTP6_ARE_ADDR_EQUAL(struct sockaddr_in6 *a, struct sockaddr_in6 *b);
   1.690 +#endif
   1.691 +
   1.692 +void sctp_fill_pcbinfo(struct sctp_pcbinfo *);
   1.693 +
   1.694 +struct sctp_ifn *
   1.695 +sctp_find_ifn(void *ifn, uint32_t ifn_index);
   1.696 +
   1.697 +struct sctp_vrf *sctp_allocate_vrf(int vrfid);
   1.698 +struct sctp_vrf *sctp_find_vrf(uint32_t vrfid);
   1.699 +void sctp_free_vrf(struct sctp_vrf *vrf);
   1.700 +
   1.701 +/*-
   1.702 + * Change address state, can be used if
   1.703 + * O/S supports telling transports about
   1.704 + * changes to IFA/IFN's (link layer triggers).
   1.705 + * If a ifn goes down, we will do src-addr-selection
   1.706 + * and NOT use that, as a source address. This does
   1.707 + * not stop the routing system from routing out
   1.708 + * that interface, but we won't put it as a source.
   1.709 + */
   1.710 +void sctp_mark_ifa_addr_down(uint32_t vrf_id, struct sockaddr *addr, const char *if_name, uint32_t ifn_index);
   1.711 +void sctp_mark_ifa_addr_up(uint32_t vrf_id, struct sockaddr *addr, const char *if_name, uint32_t ifn_index);
   1.712 +
   1.713 +struct sctp_ifa *
   1.714 +sctp_add_addr_to_vrf(uint32_t vrfid,
   1.715 +		     void *ifn, uint32_t ifn_index, uint32_t ifn_type,
   1.716 +		     const char *if_name,
   1.717 +		     void *ifa, struct sockaddr *addr, uint32_t ifa_flags,
   1.718 +		     int dynamic_add);
   1.719 +
   1.720 +void sctp_update_ifn_mtu(uint32_t ifn_index, uint32_t mtu);
   1.721 +
   1.722 +void sctp_free_ifn(struct sctp_ifn *sctp_ifnp);
   1.723 +void sctp_free_ifa(struct sctp_ifa *sctp_ifap);
   1.724 +
   1.725 +
   1.726 +void sctp_del_addr_from_vrf(uint32_t vrfid, struct sockaddr *addr,
   1.727 +			    uint32_t ifn_index, const char *if_name);
   1.728 +
   1.729 +
   1.730 +
   1.731 +struct sctp_nets *sctp_findnet(struct sctp_tcb *, struct sockaddr *);
   1.732 +
   1.733 +struct sctp_inpcb *sctp_pcb_findep(struct sockaddr *, int, int, uint32_t);
   1.734 +
   1.735 +#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
   1.736 +int sctp_inpcb_bind(struct socket *, struct sockaddr *,
   1.737 +		    struct sctp_ifa *,struct thread *);
   1.738 +#elif defined(__Windows__)
   1.739 +int sctp_inpcb_bind(struct socket *, struct sockaddr *,
   1.740 +		    struct sctp_ifa *,PKTHREAD);
   1.741 +#else
   1.742 +/* struct proc is a dummy for __Userspace__ */
   1.743 +int sctp_inpcb_bind(struct socket *, struct sockaddr *,
   1.744 +		    struct sctp_ifa *, struct proc *);
   1.745 +#endif
   1.746 +
   1.747 +struct sctp_tcb *
   1.748 +sctp_findassociation_addr(struct mbuf *, int,
   1.749 +    struct sockaddr *, struct sockaddr *,
   1.750 +    struct sctphdr *, struct sctp_chunkhdr *, struct sctp_inpcb **,
   1.751 +    struct sctp_nets **, uint32_t vrf_id);
   1.752 +
   1.753 +struct sctp_tcb *
   1.754 +sctp_findassociation_addr_sa(struct sockaddr *,
   1.755 +    struct sockaddr *, struct sctp_inpcb **, struct sctp_nets **, int, uint32_t);
   1.756 +
   1.757 +void
   1.758 +sctp_move_pcb_and_assoc(struct sctp_inpcb *, struct sctp_inpcb *,
   1.759 +    struct sctp_tcb *);
   1.760 +
   1.761 +/*-
   1.762 + * For this call ep_addr, the to is the destination endpoint address of the
   1.763 + * peer (relative to outbound). The from field is only used if the TCP model
   1.764 + * is enabled and helps distingush amongst the subset bound (non-boundall).
   1.765 + * The TCP model MAY change the actual ep field, this is why it is passed.
   1.766 + */
   1.767 +struct sctp_tcb *
   1.768 +sctp_findassociation_ep_addr(struct sctp_inpcb **,
   1.769 +    struct sockaddr *, struct sctp_nets **, struct sockaddr *,
   1.770 +    struct sctp_tcb *);
   1.771 +
   1.772 +struct sctp_tcb *
   1.773 +sctp_findasoc_ep_asocid_locked(struct sctp_inpcb *inp, sctp_assoc_t asoc_id, int want_lock);
   1.774 +
   1.775 +struct sctp_tcb *
   1.776 +sctp_findassociation_ep_asocid(struct sctp_inpcb *,
   1.777 +    sctp_assoc_t, int);
   1.778 +
   1.779 +struct sctp_tcb *
   1.780 +sctp_findassociation_ep_asconf(struct mbuf *, int, struct sockaddr *,
   1.781 +			       struct sctphdr *, struct sctp_inpcb **, struct sctp_nets **, uint32_t vrf_id);
   1.782 +
   1.783 +int sctp_inpcb_alloc(struct socket *so, uint32_t vrf_id);
   1.784 +
   1.785 +int sctp_is_address_on_local_host(struct sockaddr *addr, uint32_t vrf_id);
   1.786 +
   1.787 +void sctp_inpcb_free(struct sctp_inpcb *, int, int);
   1.788 +
   1.789 +#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
   1.790 +struct sctp_tcb *
   1.791 +sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *,
   1.792 +                int *, uint32_t, uint32_t, struct thread *);
   1.793 +#elif defined(__Windows__)
   1.794 +struct sctp_tcb *
   1.795 +sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *,
   1.796 +                int *, uint32_t, uint32_t, PKTHREAD);
   1.797 +#else
   1.798 +/* proc will be NULL for __Userspace__ */
   1.799 +struct sctp_tcb *
   1.800 +sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *,
   1.801 +                int *, uint32_t, uint32_t, struct proc *);
   1.802 +#endif
   1.803 +
   1.804 +int sctp_free_assoc(struct sctp_inpcb *, struct sctp_tcb *, int, int);
   1.805 +
   1.806 +
   1.807 +void sctp_delete_from_timewait(uint32_t, uint16_t, uint16_t);
   1.808 +
   1.809 +int sctp_is_in_timewait(uint32_t tag, uint16_t lport, uint16_t rport);
   1.810 +
   1.811 +void
   1.812 +sctp_add_vtag_to_timewait(uint32_t tag, uint32_t time, uint16_t lport, uint16_t rport);
   1.813 +
   1.814 +void sctp_add_local_addr_ep(struct sctp_inpcb *, struct sctp_ifa *, uint32_t);
   1.815 +
   1.816 +int sctp_insert_laddr(struct sctpladdr *, struct sctp_ifa *, uint32_t);
   1.817 +
   1.818 +void sctp_remove_laddr(struct sctp_laddr *);
   1.819 +
   1.820 +void sctp_del_local_addr_ep(struct sctp_inpcb *, struct sctp_ifa *);
   1.821 +
   1.822 +int sctp_add_remote_addr(struct sctp_tcb *, struct sockaddr *, struct sctp_nets **, int, int);
   1.823 +
   1.824 +void sctp_remove_net(struct sctp_tcb *, struct sctp_nets *);
   1.825 +
   1.826 +int sctp_del_remote_addr(struct sctp_tcb *, struct sockaddr *);
   1.827 +
   1.828 +void sctp_pcb_init(void);
   1.829 +
   1.830 +void sctp_pcb_finish(void);
   1.831 +
   1.832 +void sctp_add_local_addr_restricted(struct sctp_tcb *, struct sctp_ifa *);
   1.833 +void sctp_del_local_addr_restricted(struct sctp_tcb *, struct sctp_ifa *);
   1.834 +
   1.835 +int
   1.836 +sctp_load_addresses_from_init(struct sctp_tcb *, struct mbuf *, int, int,
   1.837 +    struct sockaddr *, struct sockaddr *, struct sockaddr *);
   1.838 +
   1.839 +int
   1.840 +sctp_set_primary_addr(struct sctp_tcb *, struct sockaddr *,
   1.841 +    struct sctp_nets *);
   1.842 +
   1.843 +int sctp_is_vtag_good(uint32_t, uint16_t lport, uint16_t rport, struct timeval *);
   1.844 +
   1.845 +/* void sctp_drain(void); */
   1.846 +
   1.847 +int sctp_destination_is_reachable(struct sctp_tcb *, struct sockaddr *);
   1.848 +
   1.849 +int sctp_swap_inpcb_for_listen(struct sctp_inpcb *inp);
   1.850 +
   1.851 +/*-
   1.852 + * Null in last arg inpcb indicate run on ALL ep's. Specific inp in last arg
   1.853 + * indicates run on ONLY assoc's of the specified endpoint.
   1.854 + */
   1.855 +int
   1.856 +sctp_initiate_iterator(inp_func inpf,
   1.857 +		       asoc_func af,
   1.858 +		       inp_func inpe,
   1.859 +		       uint32_t, uint32_t,
   1.860 +		       uint32_t, void *,
   1.861 +		       uint32_t,
   1.862 +		       end_func ef,
   1.863 +		       struct sctp_inpcb *,
   1.864 +		       uint8_t co_off);
   1.865 +#if defined(__FreeBSD__) && defined(SCTP_MCORE_INPUT) && defined(SMP)
   1.866 +void
   1.867 +sctp_queue_to_mcore(struct mbuf *m, int off, int cpu_to_use);
   1.868 +
   1.869 +#endif
   1.870 +
   1.871 +#ifdef INVARIANTS
   1.872 +void
   1.873 +sctp_validate_no_locks(struct sctp_inpcb *inp);
   1.874 +#endif
   1.875 +
   1.876 +#endif				/* _KERNEL */
   1.877 +#endif				/* !__sctp_pcb_h__ */

mercurial