xref: /freebsd-src/sys/netinet/sctp_pcb.h (revision 523913c94371ab50a8129cbab820394d25f7a269)
1f8829a4aSRandall Stewart /*-
251369649SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
351369649SPedro F. Giffuni  *
4b1006367SRandall Stewart  * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
5807aad63SMichael Tuexen  * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
6807aad63SMichael Tuexen  * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
7807aad63SMichael Tuexen  *
8f8829a4aSRandall Stewart  * Redistribution and use in source and binary forms, with or without
9f8829a4aSRandall Stewart  * modification, are permitted provided that the following conditions are met:
10f8829a4aSRandall Stewart  *
11f8829a4aSRandall Stewart  * a) Redistributions of source code must retain the above copyright notice,
12f8829a4aSRandall Stewart  *    this list of conditions and the following disclaimer.
13f8829a4aSRandall Stewart  *
14f8829a4aSRandall Stewart  * b) Redistributions in binary form must reproduce the above copyright
15f8829a4aSRandall Stewart  *    notice, this list of conditions and the following disclaimer in
16f8829a4aSRandall Stewart  *    the documentation and/or other materials provided with the distribution.
17f8829a4aSRandall Stewart  *
18f8829a4aSRandall Stewart  * c) Neither the name of Cisco Systems, Inc. nor the names of its
19f8829a4aSRandall Stewart  *    contributors may be used to endorse or promote products derived
20f8829a4aSRandall Stewart  *    from this software without specific prior written permission.
21f8829a4aSRandall Stewart  *
22f8829a4aSRandall Stewart  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23f8829a4aSRandall Stewart  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24f8829a4aSRandall Stewart  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25f8829a4aSRandall Stewart  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26f8829a4aSRandall Stewart  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27f8829a4aSRandall Stewart  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28f8829a4aSRandall Stewart  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29f8829a4aSRandall Stewart  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30f8829a4aSRandall Stewart  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31f8829a4aSRandall Stewart  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32f8829a4aSRandall Stewart  * THE POSSIBILITY OF SUCH DAMAGE.
33f8829a4aSRandall Stewart  */
34f8829a4aSRandall Stewart 
35807aad63SMichael Tuexen #ifndef _NETINET_SCTP_PCB_H_
36807aad63SMichael Tuexen #define _NETINET_SCTP_PCB_H_
37f8829a4aSRandall Stewart 
38f8829a4aSRandall Stewart #include <netinet/sctp_os.h>
3993164cf9SRandall Stewart #include <netinet/sctp.h>
40f8829a4aSRandall Stewart #include <netinet/sctp_constants.h>
41b3f1ea41SRandall Stewart #include <netinet/sctp_sysctl.h>
42f8829a4aSRandall Stewart 
43f8829a4aSRandall Stewart LIST_HEAD(sctppcbhead, sctp_inpcb);
44f8829a4aSRandall Stewart LIST_HEAD(sctpasochead, sctp_tcb);
45f8829a4aSRandall Stewart LIST_HEAD(sctpladdr, sctp_laddr);
46f8829a4aSRandall Stewart LIST_HEAD(sctpvtaghead, sctp_tagblock);
4742551e99SRandall Stewart LIST_HEAD(sctp_vrflist, sctp_vrf);
4842551e99SRandall Stewart LIST_HEAD(sctp_ifnlist, sctp_ifn);
4942551e99SRandall Stewart LIST_HEAD(sctp_ifalist, sctp_ifa);
50f8829a4aSRandall Stewart TAILQ_HEAD(sctp_readhead, sctp_queued_to_read);
51f8829a4aSRandall Stewart TAILQ_HEAD(sctp_streamhead, sctp_stream_queue_pending);
52f8829a4aSRandall Stewart 
53f8829a4aSRandall Stewart #include <netinet/sctp_structs.h>
54f8829a4aSRandall Stewart #include <netinet/sctp_auth.h>
55f8829a4aSRandall Stewart 
56f8829a4aSRandall Stewart #define SCTP_PCBHASH_ALLADDR(port, mask) (port & mask)
57f8829a4aSRandall Stewart #define SCTP_PCBHASH_ASOC(tag, mask) (tag & mask)
58f8829a4aSRandall Stewart 
5942551e99SRandall Stewart struct sctp_vrf {
6042551e99SRandall Stewart 	LIST_ENTRY(sctp_vrf) next_vrf;
616a27c376SRandall Stewart 	struct sctp_ifalist *vrf_addr_hash;
6242551e99SRandall Stewart 	struct sctp_ifnlist ifnlist;
6342551e99SRandall Stewart 	uint32_t vrf_id;
64f4c93d24SRandall Stewart 	uint32_t tbl_id_v4;	/* default v4 table id */
65f4c93d24SRandall Stewart 	uint32_t tbl_id_v6;	/* default v6 table id */
6642551e99SRandall Stewart 	uint32_t total_ifa_count;
6717205eccSRandall Stewart 	u_long vrf_addr_hashmark;
6880fefe0aSRandall Stewart 	uint32_t refcount;
6942551e99SRandall Stewart };
7042551e99SRandall Stewart 
7142551e99SRandall Stewart struct sctp_ifn {
7242551e99SRandall Stewart 	struct sctp_ifalist ifalist;
7342551e99SRandall Stewart 	struct sctp_vrf *vrf;
7442551e99SRandall Stewart 	         LIST_ENTRY(sctp_ifn) next_ifn;
7517205eccSRandall Stewart 	         LIST_ENTRY(sctp_ifn) next_bucket;
7642551e99SRandall Stewart 	void *ifn_p;		/* never access without appropriate lock */
7717205eccSRandall Stewart 	uint32_t ifn_mtu;
7842551e99SRandall Stewart 	uint32_t ifn_type;
7942551e99SRandall Stewart 	uint32_t ifn_index;	/* shorthand way to look at ifn for reference */
8042551e99SRandall Stewart 	uint32_t refcount;	/* number of reference held should be >=
8142551e99SRandall Stewart 				 * ifa_count */
8242551e99SRandall Stewart 	uint32_t ifa_count;	/* IFA's we hold (in our list - ifalist) */
83ad21a364SRandall Stewart 	uint32_t num_v6;	/* number of v6 addresses */
84ad21a364SRandall Stewart 	uint32_t num_v4;	/* number of v4 addresses */
85ad21a364SRandall Stewart 	uint32_t registered_af;	/* registered address family for i/f events */
8642551e99SRandall Stewart 	char ifn_name[SCTP_IFNAMSIZ];
8742551e99SRandall Stewart };
8842551e99SRandall Stewart 
8942551e99SRandall Stewart /* SCTP local IFA flags */
9042551e99SRandall Stewart #define SCTP_ADDR_VALID         0x00000001	/* its up and active */
9142551e99SRandall Stewart #define SCTP_BEING_DELETED      0x00000002	/* being deleted, when
9242551e99SRandall Stewart 						 * refcount = 0. Note that it
9342551e99SRandall Stewart 						 * is pulled from the ifn list
9442551e99SRandall Stewart 						 * and ifa_p is nulled right
9542551e99SRandall Stewart 						 * away but it cannot be freed
9642551e99SRandall Stewart 						 * until the last *net
9742551e99SRandall Stewart 						 * pointing to it is deleted. */
9842551e99SRandall Stewart #define SCTP_ADDR_DEFER_USE     0x00000004	/* Hold off using this one */
9942551e99SRandall Stewart #define SCTP_ADDR_IFA_UNUSEABLE 0x00000008
10042551e99SRandall Stewart 
10142551e99SRandall Stewart struct sctp_ifa {
10242551e99SRandall Stewart 	LIST_ENTRY(sctp_ifa) next_ifa;
1036a27c376SRandall Stewart 	LIST_ENTRY(sctp_ifa) next_bucket;
10442551e99SRandall Stewart 	struct sctp_ifn *ifn_p;	/* back pointer to parent ifn */
10542551e99SRandall Stewart 	void *ifa;		/* pointer to ifa, needed for flag update for
10642551e99SRandall Stewart 				 * that we MUST lock appropriate locks. This
10742551e99SRandall Stewart 				 * is for V6. */
10842551e99SRandall Stewart 	union sctp_sockstore address;
109cd0a4ff6SPedro F. Giffuni 	uint32_t refcount;	/* number of folks referring to this */
11042551e99SRandall Stewart 	uint32_t flags;
11142551e99SRandall Stewart 	uint32_t localifa_flags;
11222a67197SRandall Stewart 	uint32_t vrf_id;	/* vrf_id of this addr (for deleting) */
11342551e99SRandall Stewart 	uint8_t src_is_loop;
11442551e99SRandall Stewart 	uint8_t src_is_priv;
11542551e99SRandall Stewart 	uint8_t src_is_glob;
11617205eccSRandall Stewart 	uint8_t resv;
11742551e99SRandall Stewart };
11842551e99SRandall Stewart 
119f8829a4aSRandall Stewart struct sctp_laddr {
120f8829a4aSRandall Stewart 	LIST_ENTRY(sctp_laddr) sctp_nxt_addr;	/* next in list */
12142551e99SRandall Stewart 	struct sctp_ifa *ifa;
12242551e99SRandall Stewart 	uint32_t action;	/* Used during asconf and adding if no-zero
12342551e99SRandall Stewart 				 * src-addr selection will not consider this
12442551e99SRandall Stewart 				 * address. */
125d61a0ae0SRandall Stewart 	struct timeval start_time;	/* time when this address was created */
126f8829a4aSRandall Stewart };
127f8829a4aSRandall Stewart 
128f8829a4aSRandall Stewart struct sctp_block_entry {
129f8829a4aSRandall Stewart 	int error;
130f8829a4aSRandall Stewart };
131f8829a4aSRandall Stewart 
132f8829a4aSRandall Stewart struct sctp_timewait {
13342aeb8d4SMichael Tuexen 	time_t tv_sec_at_expire;	/* the seconds from boot to expire */
134f8829a4aSRandall Stewart 	uint32_t v_tag;		/* the vtag that can not be reused */
135830d754dSRandall Stewart 	uint16_t lport;		/* the local port used in vtag */
136830d754dSRandall Stewart 	uint16_t rport;		/* the remote port used in vtag */
137f8829a4aSRandall Stewart };
138f8829a4aSRandall Stewart 
139f8829a4aSRandall Stewart struct sctp_tagblock {
140f8829a4aSRandall Stewart 	LIST_ENTRY(sctp_tagblock) sctp_nxt_tagblock;
141f8829a4aSRandall Stewart 	struct sctp_timewait vtag_block[SCTP_NUMBER_IN_VTAG_BLOCK];
142f8829a4aSRandall Stewart };
143f8829a4aSRandall Stewart 
144f8829a4aSRandall Stewart struct sctp_epinfo {
1453a51a264SMichael Tuexen #ifdef INET
1463a51a264SMichael Tuexen 	struct socket *udp4_tun_socket;
1473a51a264SMichael Tuexen #endif
1483a51a264SMichael Tuexen #ifdef INET6
1493a51a264SMichael Tuexen 	struct socket *udp6_tun_socket;
1503a51a264SMichael Tuexen #endif
151f8829a4aSRandall Stewart 	struct sctpasochead *sctp_asochash;
152f8829a4aSRandall Stewart 	u_long hashasocmark;
153f8829a4aSRandall Stewart 
154f8829a4aSRandall Stewart 	struct sctppcbhead *sctp_ephash;
155f8829a4aSRandall Stewart 	u_long hashmark;
156f8829a4aSRandall Stewart 
1575e54f665SRandall Stewart 	/*-
158f8829a4aSRandall Stewart 	 * The TCP model represents a substantial overhead in that we get an
159f8829a4aSRandall Stewart 	 * additional hash table to keep explicit connections in. The
160f8829a4aSRandall Stewart 	 * listening TCP endpoint will exist in the usual ephash above and
161f8829a4aSRandall Stewart 	 * accept only INIT's. It will be incapable of sending off an INIT.
162f8829a4aSRandall Stewart 	 * When a dg arrives we must look in the normal ephash. If we find a
163f8829a4aSRandall Stewart 	 * TCP endpoint that will tell us to go to the specific endpoint
164f8829a4aSRandall Stewart 	 * hash and re-hash to find the right assoc/socket. If we find a UDP
165f8829a4aSRandall Stewart 	 * model socket we then must complete the lookup. If this fails,
166f8829a4aSRandall Stewart 	 * i.e. no association can be found then we must continue to see if
167f8829a4aSRandall Stewart 	 * a sctp_peeloff()'d socket is in the tcpephash (a spun off socket
168f8829a4aSRandall Stewart 	 * acts like a TCP model connected socket).
169f8829a4aSRandall Stewart 	 */
170f8829a4aSRandall Stewart 	struct sctppcbhead *sctp_tcpephash;
171f8829a4aSRandall Stewart 	u_long hashtcpmark;
172f8829a4aSRandall Stewart 	uint32_t hashtblsize;
173f8829a4aSRandall Stewart 
17442551e99SRandall Stewart 	struct sctp_vrflist *sctp_vrfhash;
17542551e99SRandall Stewart 	u_long hashvrfmark;
17642551e99SRandall Stewart 
177f4c93d24SRandall Stewart 	struct sctp_ifnlist *vrf_ifn_hash;
178f4c93d24SRandall Stewart 	u_long vrf_ifn_hashmark;
179f4c93d24SRandall Stewart 
180f8829a4aSRandall Stewart 	struct sctppcbhead listhead;
181f8829a4aSRandall Stewart 	struct sctpladdr addr_wq;
182f8829a4aSRandall Stewart 
183f8829a4aSRandall Stewart 	/* ep zone info */
184f8829a4aSRandall Stewart 	sctp_zone_t ipi_zone_ep;
185f8829a4aSRandall Stewart 	sctp_zone_t ipi_zone_asoc;
186f8829a4aSRandall Stewart 	sctp_zone_t ipi_zone_laddr;
187f8829a4aSRandall Stewart 	sctp_zone_t ipi_zone_net;
188f8829a4aSRandall Stewart 	sctp_zone_t ipi_zone_chunk;
189f8829a4aSRandall Stewart 	sctp_zone_t ipi_zone_readq;
190f8829a4aSRandall Stewart 	sctp_zone_t ipi_zone_strmoq;
191c54a18d2SRandall Stewart 	sctp_zone_t ipi_zone_asconf;
1922afb3e84SRandall Stewart 	sctp_zone_t ipi_zone_asconf_ack;
193f8829a4aSRandall Stewart 
194c99efcf6SRandall Stewart 	struct rwlock ipi_ep_mtx;
19542551e99SRandall Stewart 	struct mtx ipi_iterator_wq_mtx;
196c99efcf6SRandall Stewart 	struct rwlock ipi_addr_mtx;
197207304d4SRandall Stewart 	struct mtx ipi_pktlog_mtx;
198f7517433SRandall Stewart 	struct mtx wq_addr_mtx;
199f8829a4aSRandall Stewart 	uint32_t ipi_count_ep;
200f8829a4aSRandall Stewart 
201f8829a4aSRandall Stewart 	/* assoc/tcb zone info */
202f8829a4aSRandall Stewart 	uint32_t ipi_count_asoc;
203f8829a4aSRandall Stewart 
204f8829a4aSRandall Stewart 	/* local addrlist zone info */
205f8829a4aSRandall Stewart 	uint32_t ipi_count_laddr;
206f8829a4aSRandall Stewart 
207f8829a4aSRandall Stewart 	/* remote addrlist zone info */
208f8829a4aSRandall Stewart 	uint32_t ipi_count_raddr;
209f8829a4aSRandall Stewart 
210f8829a4aSRandall Stewart 	/* chunk structure list for output */
211f8829a4aSRandall Stewart 	uint32_t ipi_count_chunk;
212f8829a4aSRandall Stewart 
213f8829a4aSRandall Stewart 	/* socket queue zone info */
214f8829a4aSRandall Stewart 	uint32_t ipi_count_readq;
215f8829a4aSRandall Stewart 
216f8829a4aSRandall Stewart 	/* socket queue zone info */
217f8829a4aSRandall Stewart 	uint32_t ipi_count_strmoq;
218f8829a4aSRandall Stewart 
21917205eccSRandall Stewart 	/* Number of vrfs */
22017205eccSRandall Stewart 	uint32_t ipi_count_vrfs;
22117205eccSRandall Stewart 
22217205eccSRandall Stewart 	/* Number of ifns */
22317205eccSRandall Stewart 	uint32_t ipi_count_ifns;
22417205eccSRandall Stewart 
22517205eccSRandall Stewart 	/* Number of ifas */
22617205eccSRandall Stewart 	uint32_t ipi_count_ifas;
22717205eccSRandall Stewart 
228f8829a4aSRandall Stewart 	/* system wide number of free chunks hanging around */
229f8829a4aSRandall Stewart 	uint32_t ipi_free_chunks;
230f8829a4aSRandall Stewart 	uint32_t ipi_free_strmoq;
231f8829a4aSRandall Stewart 
232a1e13272SRandall Stewart 	struct sctpvtaghead vtag_timewait[SCTP_STACK_VTAG_HASH_SIZE];
233f8829a4aSRandall Stewart 
23442551e99SRandall Stewart 	/* address work queue handling */
235f8829a4aSRandall Stewart 	struct sctp_timer addr_wq_timer;
236f8829a4aSRandall Stewart 
237f8829a4aSRandall Stewart };
238f8829a4aSRandall Stewart 
239b3f1ea41SRandall Stewart struct sctp_base_info {
240b3f1ea41SRandall Stewart 	/*
241b3f1ea41SRandall Stewart 	 * All static structures that anchor the system must be here.
242b3f1ea41SRandall Stewart 	 */
243b3f1ea41SRandall Stewart 	struct sctp_epinfo sctppcbinfo;
2442f9e6db0SMichael Tuexen #if defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
245ae26e0a4SRandall Stewart 	struct sctpstat *sctpstat;
246ff014514SRandall Stewart #else
247b3f1ea41SRandall Stewart 	struct sctpstat sctpstat;
248ff014514SRandall Stewart #endif
249b3f1ea41SRandall Stewart 	struct sctp_sysctl sctpsysctl;
250b3f1ea41SRandall Stewart 	uint8_t first_time;
251b3f1ea41SRandall Stewart 	char sctp_pcb_initialized;
252b3f1ea41SRandall Stewart #if defined(SCTP_PACKET_LOGGING)
253b3f1ea41SRandall Stewart 	int packet_log_writers;
254b3f1ea41SRandall Stewart 	int packet_log_end;
255b3f1ea41SRandall Stewart 	uint8_t packet_log_buffer[SCTP_PACKET_LOG_SIZE];
256b3f1ea41SRandall Stewart #endif
2579f36ec8bSMichael Tuexen 	eventhandler_tag eh_tag;
258b3f1ea41SRandall Stewart };
259b3f1ea41SRandall Stewart 
2605e54f665SRandall Stewart /*-
261f8829a4aSRandall Stewart  * Here we have all the relevant information for each SCTP entity created. We
262f8829a4aSRandall Stewart  * will need to modify this as approprate. We also need to figure out how to
263f8829a4aSRandall Stewart  * access /dev/random.
264f8829a4aSRandall Stewart  */
265f8829a4aSRandall Stewart struct sctp_pcb {
2669d8a3718SMichael Tuexen 	time_t time_of_secret_change;	/* number of seconds from
267f8829a4aSRandall Stewart 					 * timeval.tv_sec */
268f8829a4aSRandall Stewart 	uint32_t secret_key[SCTP_HOW_MANY_SECRETS][SCTP_NUMBER_OF_SECRETS];
269f8829a4aSRandall Stewart 	unsigned int size_of_a_cookie;
270f8829a4aSRandall Stewart 
271d5d190f2SMichael Tuexen 	uint32_t sctp_timeoutticks[SCTP_NUM_TMRS];
272d5d190f2SMichael Tuexen 	uint32_t sctp_minrto;
273d5d190f2SMichael Tuexen 	uint32_t sctp_maxrto;
274d5d190f2SMichael Tuexen 	uint32_t initial_rto;
275d5d190f2SMichael Tuexen 	uint32_t initial_init_rto_max;
276f8829a4aSRandall Stewart 
27742551e99SRandall Stewart 	unsigned int sctp_sack_freq;
278f8829a4aSRandall Stewart 	uint32_t sctp_sws_sender;
279f8829a4aSRandall Stewart 	uint32_t sctp_sws_receiver;
280f8829a4aSRandall Stewart 
281b54d3a6cSRandall Stewart 	uint32_t sctp_default_cc_module;
282f7a77f6fSMichael Tuexen 	uint32_t sctp_default_ss_module;
283f8829a4aSRandall Stewart 	/* authentication related fields */
284f8829a4aSRandall Stewart 	struct sctp_keyhead shared_keys;
285f8829a4aSRandall Stewart 	sctp_auth_chklist_t *local_auth_chunks;
286f8829a4aSRandall Stewart 	sctp_hmaclist_t *local_hmacs;
287f8829a4aSRandall Stewart 	uint16_t default_keyid;
28828a6addeSMichael Tuexen 	uint32_t default_mtu;
289f8829a4aSRandall Stewart 
290f8829a4aSRandall Stewart 	/* various thresholds */
291f8829a4aSRandall Stewart 	/* Max times I will init at a guy */
292f8829a4aSRandall Stewart 	uint16_t max_init_times;
293f8829a4aSRandall Stewart 
294f8829a4aSRandall Stewart 	/* Max times I will send before we consider someone dead */
295f8829a4aSRandall Stewart 	uint16_t max_send_times;
296f8829a4aSRandall Stewart 
297f8829a4aSRandall Stewart 	uint16_t def_net_failure;
298f8829a4aSRandall Stewart 
299ca85e948SMichael Tuexen 	uint16_t def_net_pf_threshold;
300ca85e948SMichael Tuexen 
301f8829a4aSRandall Stewart 	/* number of streams to pre-open on a association */
302f8829a4aSRandall Stewart 	uint16_t pre_open_stream_count;
303f8829a4aSRandall Stewart 	uint16_t max_open_streams_intome;
304f8829a4aSRandall Stewart 
305f8829a4aSRandall Stewart 	/* random number generator */
306f8829a4aSRandall Stewart 	uint32_t random_counter;
307f8829a4aSRandall Stewart 	uint8_t random_numbers[SCTP_SIGNATURE_ALOC_SIZE];
308f8829a4aSRandall Stewart 	uint8_t random_store[SCTP_SIGNATURE_ALOC_SIZE];
309f8829a4aSRandall Stewart 
310f8829a4aSRandall Stewart 	/*
311f8829a4aSRandall Stewart 	 * This timer is kept running per endpoint.  When it fires it will
312f8829a4aSRandall Stewart 	 * change the secret key.  The default is once a hour
313f8829a4aSRandall Stewart 	 */
314f8829a4aSRandall Stewart 	struct sctp_timer signature_change;
315d61a0ae0SRandall Stewart 
31618e198d3SRandall Stewart 	uint32_t def_cookie_life;
317f8829a4aSRandall Stewart 	/* defaults to 0 */
318239e5865SMichael Tuexen 	uint32_t auto_close_time;
319f8829a4aSRandall Stewart 	uint32_t initial_sequence_debug;
320f8829a4aSRandall Stewart 	uint32_t adaptation_layer_indicator;
3212416af26SMichael Tuexen 	uint8_t adaptation_layer_indicator_provided;
322851b7298SRandall Stewart 	uint32_t store_at;
32390fed1d8SMichael Tuexen 	uint32_t max_burst;
324899288aeSRandall Stewart 	uint32_t fr_max_burst;
32558bdb691SMichael Tuexen #ifdef INET6
32658bdb691SMichael Tuexen 	uint32_t default_flowlabel;
32758bdb691SMichael Tuexen #endif
32858bdb691SMichael Tuexen 	uint8_t default_dscp;
329f8829a4aSRandall Stewart 	char current_secret_number;
330f8829a4aSRandall Stewart 	char last_secret_number;
331c9c58059SMichael Tuexen 	uint16_t port;		/* remote UDP encapsulation port */
332f8829a4aSRandall Stewart };
333f8829a4aSRandall Stewart 
334f8829a4aSRandall Stewart #ifndef SCTP_ALIGNMENT
335f8829a4aSRandall Stewart #define SCTP_ALIGNMENT 32
336f8829a4aSRandall Stewart #endif
337f8829a4aSRandall Stewart 
338f8829a4aSRandall Stewart #ifndef SCTP_ALIGNM1
339f8829a4aSRandall Stewart #define SCTP_ALIGNM1 (SCTP_ALIGNMENT-1)
340f8829a4aSRandall Stewart #endif
341f8829a4aSRandall Stewart 
342f8829a4aSRandall Stewart #define sctp_lport ip_inp.inp.inp_lport
343f8829a4aSRandall Stewart 
34418e198d3SRandall Stewart struct sctp_pcbtsn_rlog {
34518e198d3SRandall Stewart 	uint32_t vtag;
34618e198d3SRandall Stewart 	uint16_t strm;
34718e198d3SRandall Stewart 	uint16_t seq;
34818e198d3SRandall Stewart 	uint16_t sz;
34918e198d3SRandall Stewart 	uint16_t flgs;
35018e198d3SRandall Stewart };
35118e198d3SRandall Stewart #define SCTP_READ_LOG_SIZE 135	/* we choose the number to make a pcb a page */
35218e198d3SRandall Stewart 
353f8829a4aSRandall Stewart struct sctp_inpcb {
3545e54f665SRandall Stewart 	/*-
355f8829a4aSRandall Stewart 	 * put an inpcb in front of it all, kind of a waste but we need to
356cd0a4ff6SPedro F. Giffuni 	 * for compatibility with all the other stuff.
357f8829a4aSRandall Stewart 	 */
358f8829a4aSRandall Stewart 	union {
359f8829a4aSRandall Stewart 		struct inpcb inp;
3600ecd976eSBjoern A. Zeeb 		char align[(sizeof(struct inpcb) + SCTP_ALIGNM1) &
361f8829a4aSRandall Stewart 		    ~SCTP_ALIGNM1];
362f8829a4aSRandall Stewart 	}     ip_inp;
363f8829a4aSRandall Stewart 
3644e88d37aSMichael Tuexen 	/* Socket buffer lock protects read_queue and of course sb_cc */
365f8829a4aSRandall Stewart 	struct sctp_readhead read_queue;
366f8829a4aSRandall Stewart 
367f8829a4aSRandall Stewart 	              LIST_ENTRY(sctp_inpcb) sctp_list;	/* lists all endpoints */
368f8829a4aSRandall Stewart 	/* hash of all endpoints for model */
369f8829a4aSRandall Stewart 	              LIST_ENTRY(sctp_inpcb) sctp_hash;
370f8829a4aSRandall Stewart 	/* count of local addresses bound, 0 if bound all */
371f8829a4aSRandall Stewart 	int laddr_count;
37242551e99SRandall Stewart 
37342551e99SRandall Stewart 	/* list of addrs in use by the EP, NULL if bound-all */
374f8829a4aSRandall Stewart 	struct sctpladdr sctp_addr_list;
375b7b84c0eSMichael Tuexen 	/*
376b7b84c0eSMichael Tuexen 	 * used for source address selection rotation when we are subset
377b7b84c0eSMichael Tuexen 	 * bound
378b7b84c0eSMichael Tuexen 	 */
379f8829a4aSRandall Stewart 	struct sctp_laddr *next_addr_touse;
38042551e99SRandall Stewart 
381f8829a4aSRandall Stewart 	/* back pointer to our socket */
382f8829a4aSRandall Stewart 	struct socket *sctp_socket;
3832c9c61deSMichael Tuexen 	uint64_t sctp_features;	/* Feature flags */
384f8829a4aSRandall Stewart 	uint32_t sctp_flags;	/* INP state flag set */
3852afb3e84SRandall Stewart 	uint32_t sctp_mobility_features;	/* Mobility  Feature flags */
386f8829a4aSRandall Stewart 	struct sctp_pcb sctp_ep;	/* SCTP ep data */
387f8829a4aSRandall Stewart 	/* head of the hash of all associations */
388f8829a4aSRandall Stewart 	struct sctpasochead *sctp_tcbhash;
389f8829a4aSRandall Stewart 	u_long sctp_hashmark;
390f8829a4aSRandall Stewart 	/* head of the list of all associations */
391f8829a4aSRandall Stewart 	struct sctpasochead sctp_asoc_list;
392a5d547adSRandall Stewart #ifdef SCTP_TRACK_FREED_ASOCS
393a5d547adSRandall Stewart 	struct sctpasochead sctp_asoc_free_list;
394a5d547adSRandall Stewart #endif
395f8829a4aSRandall Stewart 	uint32_t sctp_frag_point;
396f8829a4aSRandall Stewart 	uint32_t partial_delivery_point;
397f8829a4aSRandall Stewart 	uint32_t sctp_context;
39859b6d5beSMichael Tuexen 	uint32_t max_cwnd;
399c4e848b7SRandall Stewart 	uint8_t local_strreset_support;
40020083c2eSMichael Tuexen 	uint32_t sctp_cmt_on_off;
401f342355aSMichael Tuexen 	uint8_t ecn_supported;
402dd973b0eSMichael Tuexen 	uint8_t prsctp_supported;
403c79bec9cSMichael Tuexen 	uint8_t auth_supported;
40444249214SRandall Stewart 	uint8_t idata_supported;
405c79bec9cSMichael Tuexen 	uint8_t asconf_supported;
406317e00efSMichael Tuexen 	uint8_t reconfig_supported;
407caea9879SMichael Tuexen 	uint8_t nrsack_supported;
408cb9b8e6fSMichael Tuexen 	uint8_t pktdrop_supported;
40952640d61SMichael Tuexen 	uint8_t rcv_edmid;
410d61a0ae0SRandall Stewart 	struct sctp_nonpad_sndrcvinfo def_send;
4115e54f665SRandall Stewart 	/*-
4125e54f665SRandall Stewart 	 * These three are here for the sosend_dgram
4135e54f665SRandall Stewart 	 * (pkt, pkt_last and control).
4145e54f665SRandall Stewart 	 * routine. However, I don't think anyone in
4155e54f665SRandall Stewart 	 * the current FreeBSD kernel calls this. So
4165e54f665SRandall Stewart 	 * they are candidates with sctp_sendm for
4175e54f665SRandall Stewart 	 * de-supporting.
418f8829a4aSRandall Stewart 	 */
419f8829a4aSRandall Stewart 	struct mbuf *pkt, *pkt_last;
420f8829a4aSRandall Stewart 	struct mbuf *control;
421f8829a4aSRandall Stewart 	struct mtx inp_mtx;
422f8829a4aSRandall Stewart 	struct mtx inp_create_mtx;
423f8829a4aSRandall Stewart 	struct mtx inp_rdata_mtx;
424f8829a4aSRandall Stewart 	int32_t refcount;
42542551e99SRandall Stewart 	uint32_t def_vrf_id;
426d089f9b9SMichael Tuexen 	uint16_t fibnum;
427a5d547adSRandall Stewart 	uint32_t total_sends;
428a5d547adSRandall Stewart 	uint32_t total_recvs;
429a5d547adSRandall Stewart 	uint32_t last_abort_code;
430a5d547adSRandall Stewart 	uint32_t total_nospaces;
431830d754dSRandall Stewart 	struct sctpasochead *sctp_asocidhash;
432830d754dSRandall Stewart 	u_long hashasocidmark;
433830d754dSRandall Stewart 	uint32_t sctp_associd_counter;
434830d754dSRandall Stewart 
43518e198d3SRandall Stewart #ifdef SCTP_ASOCLOG_OF_TSNS
43618e198d3SRandall Stewart 	struct sctp_pcbtsn_rlog readlog[SCTP_READ_LOG_SIZE];
43718e198d3SRandall Stewart 	uint32_t readlog_index;
43818e198d3SRandall Stewart #endif
439f8829a4aSRandall Stewart };
440f8829a4aSRandall Stewart 
441f8829a4aSRandall Stewart struct sctp_tcb {
442f8829a4aSRandall Stewart 	struct socket *sctp_socket;	/* back pointer to socket */
443f8829a4aSRandall Stewart 	struct sctp_inpcb *sctp_ep;	/* back pointer to ep */
444f8829a4aSRandall Stewart 	           LIST_ENTRY(sctp_tcb) sctp_tcbhash;	/* next link in hash
445f8829a4aSRandall Stewart 							 * table */
446f8829a4aSRandall Stewart 	           LIST_ENTRY(sctp_tcb) sctp_tcblist;	/* list of all of the
447f8829a4aSRandall Stewart 							 * TCB's */
448830d754dSRandall Stewart 	           LIST_ENTRY(sctp_tcb) sctp_tcbasocidhash;	/* next link in asocid
449f8829a4aSRandall Stewart 								 * hash table */
450f8829a4aSRandall Stewart 	           LIST_ENTRY(sctp_tcb) sctp_asocs;	/* vtag hash list */
451f8829a4aSRandall Stewart 	struct sctp_block_entry *block_entry;	/* pointer locked by  socket
452f8829a4aSRandall Stewart 						 * send buffer */
453f8829a4aSRandall Stewart 	struct sctp_association asoc;
4545e54f665SRandall Stewart 	/*-
455f8829a4aSRandall Stewart 	 * freed_by_sorcv_sincelast is protected by the sockbuf_lock NOT the
456f8829a4aSRandall Stewart 	 * tcb_lock. Its special in this way to help avoid extra mutex calls
457f8829a4aSRandall Stewart 	 * in the reading of data.
458f8829a4aSRandall Stewart 	 */
459f8829a4aSRandall Stewart 	uint32_t freed_by_sorcv_sincelast;
460a5d547adSRandall Stewart 	uint32_t total_sends;
461a5d547adSRandall Stewart 	uint32_t total_recvs;
462a5d547adSRandall Stewart 	int freed_from_where;
463f8829a4aSRandall Stewart 	uint16_t rport;		/* remote port in network format */
464f8829a4aSRandall Stewart 	uint16_t resv;
465f8829a4aSRandall Stewart 	struct mtx tcb_mtx;
466f8829a4aSRandall Stewart };
467f8829a4aSRandall Stewart 
468f8829a4aSRandall Stewart #include <netinet/sctp_lock_bsd.h>
469f8829a4aSRandall Stewart 
470fc14de76SRandall Stewart #if defined(_KERNEL) || defined(__Userspace__)
471f8829a4aSRandall Stewart 
472b3f1ea41SRandall Stewart /* Attention Julian, this is the extern that
473b3f1ea41SRandall Stewart  * goes with the base info. sctp_pcb.c has
474b3f1ea41SRandall Stewart  * the real definition.
475b3f1ea41SRandall Stewart  */
476482444b4SRandall Stewart VNET_DECLARE(struct sctp_base_info, system_base_info);
477f8829a4aSRandall Stewart 
4785e2c2d87SRandall Stewart #ifdef INET6
479c54a18d2SRandall Stewart int SCTP6_ARE_ADDR_EQUAL(struct sockaddr_in6 *a, struct sockaddr_in6 *b);
4805e2c2d87SRandall Stewart #endif
4815e2c2d87SRandall Stewart 
482f8829a4aSRandall Stewart void sctp_fill_pcbinfo(struct sctp_pcbinfo *);
483f8829a4aSRandall Stewart 
4840053ed28SMichael Tuexen struct sctp_ifn *sctp_find_ifn(void *ifn, uint32_t ifn_index);
48542551e99SRandall Stewart 
48642551e99SRandall Stewart struct sctp_vrf *sctp_allocate_vrf(int vrfid);
48742551e99SRandall Stewart struct sctp_vrf *sctp_find_vrf(uint32_t vrfid);
48880fefe0aSRandall Stewart void sctp_free_vrf(struct sctp_vrf *vrf);
48942551e99SRandall Stewart 
49042551e99SRandall Stewart struct sctp_ifa *
49142551e99SRandall Stewart sctp_add_addr_to_vrf(uint32_t vrfid,
49242551e99SRandall Stewart     void *ifn, uint32_t ifn_index, uint32_t ifn_type,
49342551e99SRandall Stewart     const char *if_name,
494f4c93d24SRandall Stewart     void *ifa, struct sockaddr *addr, uint32_t ifa_flags,
495f4c93d24SRandall Stewart     int dynamic_add);
49642551e99SRandall Stewart 
49742551e99SRandall Stewart void sctp_free_ifa(struct sctp_ifa *sctp_ifap);
49842551e99SRandall Stewart 
499d06c82f1SRandall Stewart void
50042551e99SRandall Stewart sctp_del_addr_from_vrf(uint32_t vrfid, struct sockaddr *addr,
501*523913c9SMichael Tuexen     void *ifn, uint32_t ifn_index);
50242551e99SRandall Stewart 
503f8829a4aSRandall Stewart struct sctp_nets *sctp_findnet(struct sctp_tcb *, struct sockaddr *);
504f8829a4aSRandall Stewart 
50542551e99SRandall Stewart struct sctp_inpcb *sctp_pcb_findep(struct sockaddr *, int, int, uint32_t);
506f8829a4aSRandall Stewart 
50780fefe0aSRandall Stewart int
50818e198d3SRandall Stewart sctp_inpcb_bind(struct socket *, struct sockaddr *,
5091b649582SRandall Stewart     struct sctp_ifa *, struct thread *);
510457abbb8SMark Johnston int
511457abbb8SMark Johnston sctp_inpcb_bind_locked(struct sctp_inpcb *, struct sockaddr *,
512457abbb8SMark Johnston     struct sctp_ifa *, struct thread *);
513f8829a4aSRandall Stewart 
514f8829a4aSRandall Stewart struct sctp_tcb *
5157215cc1bSMichael Tuexen sctp_findassociation_addr(struct mbuf *, int,
516b1754ad1SMichael Tuexen     struct sockaddr *, struct sockaddr *,
517f8829a4aSRandall Stewart     struct sctphdr *, struct sctp_chunkhdr *, struct sctp_inpcb **,
518bff64a4dSRandall Stewart     struct sctp_nets **, uint32_t vrf_id);
519f8829a4aSRandall Stewart 
520f8829a4aSRandall Stewart struct sctp_tcb *
521f8829a4aSRandall Stewart sctp_findassociation_addr_sa(struct sockaddr *,
52242551e99SRandall Stewart     struct sockaddr *, struct sctp_inpcb **, struct sctp_nets **, int, uint32_t);
523f8829a4aSRandall Stewart 
524f8829a4aSRandall Stewart void
525f8829a4aSRandall Stewart sctp_move_pcb_and_assoc(struct sctp_inpcb *, struct sctp_inpcb *,
526f8829a4aSRandall Stewart     struct sctp_tcb *);
527f8829a4aSRandall Stewart 
5285e54f665SRandall Stewart /*-
529f8829a4aSRandall Stewart  * For this call ep_addr, the to is the destination endpoint address of the
530f8829a4aSRandall Stewart  * peer (relative to outbound). The from field is only used if the TCP model
531f8829a4aSRandall Stewart  * is enabled and helps distingush amongst the subset bound (non-boundall).
532f8829a4aSRandall Stewart  * The TCP model MAY change the actual ep field, this is why it is passed.
533f8829a4aSRandall Stewart  */
534f8829a4aSRandall Stewart struct sctp_tcb *
535f8829a4aSRandall Stewart sctp_findassociation_ep_addr(struct sctp_inpcb **,
536f8829a4aSRandall Stewart     struct sockaddr *, struct sctp_nets **, struct sockaddr *,
537f8829a4aSRandall Stewart     struct sctp_tcb *);
538f8829a4aSRandall Stewart 
5390053ed28SMichael Tuexen struct sctp_tcb *sctp_findasoc_ep_asocid_locked(struct sctp_inpcb *inp, sctp_assoc_t asoc_id, int want_lock);
540830d754dSRandall Stewart 
541830d754dSRandall Stewart struct sctp_tcb *
542f8829a4aSRandall Stewart sctp_findassociation_ep_asocid(struct sctp_inpcb *,
543f8829a4aSRandall Stewart     sctp_assoc_t, int);
544f8829a4aSRandall Stewart 
545f8829a4aSRandall Stewart struct sctp_tcb *
546b1754ad1SMichael Tuexen sctp_findassociation_ep_asconf(struct mbuf *, int, struct sockaddr *,
547830d754dSRandall Stewart     struct sctphdr *, struct sctp_inpcb **, struct sctp_nets **, uint32_t vrf_id);
548f8829a4aSRandall Stewart 
549f4c93d24SRandall Stewart int sctp_inpcb_alloc(struct socket *so, uint32_t vrf_id);
550f8829a4aSRandall Stewart 
55142551e99SRandall Stewart int sctp_is_address_on_local_host(struct sockaddr *addr, uint32_t vrf_id);
552f8829a4aSRandall Stewart 
553f8829a4aSRandall Stewart void sctp_inpcb_free(struct sctp_inpcb *, int, int);
554f8829a4aSRandall Stewart 
5558a956abeSMichael Tuexen #define SCTP_DONT_INITIALIZE_AUTH_PARAMS	0
5568a956abeSMichael Tuexen #define SCTP_INITIALIZE_AUTH_PARAMS		1
5578a956abeSMichael Tuexen 
558f8829a4aSRandall Stewart struct sctp_tcb *
559f8829a4aSRandall Stewart sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *,
560c7f048abSMichael Tuexen     int *, uint32_t, uint32_t, uint32_t, uint16_t, uint16_t,
561c7f048abSMichael Tuexen     struct thread *, int);
5622d5c48ecSMark Johnston struct sctp_tcb *
5632d5c48ecSMark Johnston sctp_aloc_assoc_connected(struct sctp_inpcb *, struct sockaddr *,
5642d5c48ecSMark Johnston     int *, uint32_t, uint32_t, uint32_t, uint16_t, uint16_t,
5652d5c48ecSMark Johnston     struct thread *, int);
566f8829a4aSRandall Stewart 
567a5d547adSRandall Stewart int sctp_free_assoc(struct sctp_inpcb *, struct sctp_tcb *, int, int);
568f8829a4aSRandall Stewart 
569ad81507eSRandall Stewart void sctp_add_local_addr_ep(struct sctp_inpcb *, struct sctp_ifa *, uint32_t);
570f8829a4aSRandall Stewart 
571ad81507eSRandall Stewart void sctp_del_local_addr_ep(struct sctp_inpcb *, struct sctp_ifa *);
572f8829a4aSRandall Stewart 
5737154bf4aSMichael Tuexen int sctp_add_remote_addr(struct sctp_tcb *, struct sockaddr *, struct sctp_nets **, uint16_t, int, int);
574f8829a4aSRandall Stewart 
575f8829a4aSRandall Stewart void sctp_remove_net(struct sctp_tcb *, struct sctp_nets *);
576f8829a4aSRandall Stewart 
577f8829a4aSRandall Stewart int sctp_del_remote_addr(struct sctp_tcb *, struct sockaddr *);
578f8829a4aSRandall Stewart 
579f8829a4aSRandall Stewart void sctp_pcb_init(void);
580f8829a4aSRandall Stewart 
581b3f1ea41SRandall Stewart void sctp_pcb_finish(void);
582c4739e2fSRandall Stewart 
5831b649582SRandall Stewart void sctp_add_local_addr_restricted(struct sctp_tcb *, struct sctp_ifa *);
5841b649582SRandall Stewart void sctp_del_local_addr_restricted(struct sctp_tcb *, struct sctp_ifa *);
585f8829a4aSRandall Stewart 
586f8829a4aSRandall Stewart int
587b1754ad1SMichael Tuexen sctp_load_addresses_from_init(struct sctp_tcb *, struct mbuf *, int, int,
588ec70917fSMichael Tuexen     struct sockaddr *, struct sockaddr *, struct sockaddr *, uint16_t);
589f8829a4aSRandall Stewart 
590f8829a4aSRandall Stewart int
591f8829a4aSRandall Stewart sctp_set_primary_addr(struct sctp_tcb *, struct sockaddr *,
592f8829a4aSRandall Stewart     struct sctp_nets *);
593f8829a4aSRandall Stewart 
59458a7bf12SMichael Tuexen bool
59558a7bf12SMichael Tuexen      sctp_is_vtag_good(uint32_t, uint16_t lport, uint16_t rport, struct timeval *);
596f8829a4aSRandall Stewart 
597f8829a4aSRandall Stewart int sctp_destination_is_reachable(struct sctp_tcb *, struct sockaddr *);
598f8829a4aSRandall Stewart 
5996d9e8f2bSRandall Stewart int sctp_swap_inpcb_for_listen(struct sctp_inpcb *inp);
6006d9e8f2bSRandall Stewart 
60144249214SRandall Stewart void sctp_clean_up_stream(struct sctp_tcb *stcb, struct sctp_readhead *rh);
60244249214SRandall Stewart 
603a5c2009dSMichael Tuexen void
604a5c2009dSMichael Tuexen      sctp_pcb_add_flags(struct sctp_inpcb *, uint32_t);
605a5c2009dSMichael Tuexen 
6065e54f665SRandall Stewart /*-
607f8829a4aSRandall Stewart  * Null in last arg inpcb indicate run on ALL ep's. Specific inp in last arg
608f8829a4aSRandall Stewart  * indicates run on ONLY assoc's of the specified endpoint.
609f8829a4aSRandall Stewart  */
610f8829a4aSRandall Stewart int
61142551e99SRandall Stewart sctp_initiate_iterator(inp_func inpf,
61242551e99SRandall Stewart     asoc_func af,
61342551e99SRandall Stewart     inp_func inpe,
61442551e99SRandall Stewart     uint32_t, uint32_t,
61542551e99SRandall Stewart     uint32_t, void *,
61642551e99SRandall Stewart     uint32_t,
61742551e99SRandall Stewart     end_func ef,
61842551e99SRandall Stewart     struct sctp_inpcb *,
61942551e99SRandall Stewart     uint8_t co_off);
6202f9e6db0SMichael Tuexen #if defined(SCTP_MCORE_INPUT) && defined(SMP)
621bfc46083SRandall Stewart void
622bfc46083SRandall Stewart      sctp_queue_to_mcore(struct mbuf *m, int off, int cpu_to_use);
623bfc46083SRandall Stewart 
624bfc46083SRandall Stewart #endif
625bfc46083SRandall Stewart 
626f8829a4aSRandall Stewart #endif				/* _KERNEL */
627f8829a4aSRandall Stewart #endif				/* !__sctp_pcb_h__ */
628