1f4b3ec61Sdh /*
2f4b3ec61Sdh  * CDDL HEADER START
3f4b3ec61Sdh  *
4f4b3ec61Sdh  * The contents of this file are subject to the terms of the
5f4b3ec61Sdh  * Common Development and Distribution License (the "License").
6f4b3ec61Sdh  * You may not use this file except in compliance with the License.
7f4b3ec61Sdh  *
8f4b3ec61Sdh  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9f4b3ec61Sdh  * or http://www.opensolaris.org/os/licensing.
10f4b3ec61Sdh  * See the License for the specific language governing permissions
11f4b3ec61Sdh  * and limitations under the License.
12f4b3ec61Sdh  *
13f4b3ec61Sdh  * When distributing Covered Code, include this CDDL HEADER in each
14f4b3ec61Sdh  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15f4b3ec61Sdh  * If applicable, add the following below this CDDL HEADER, with the
16f4b3ec61Sdh  * fields enclosed by brackets "[]" replaced with your own identifying
17f4b3ec61Sdh  * information: Portions Copyright [yyyy] [name of copyright owner]
18f4b3ec61Sdh  *
19f4b3ec61Sdh  * CDDL HEADER END
20f4b3ec61Sdh  */
21f4b3ec61Sdh 
22f4b3ec61Sdh /*
23*5dd46ab5SKacheong Poon  * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24f4b3ec61Sdh  */
25f4b3ec61Sdh 
26f4b3ec61Sdh #ifndef	_INET_SCTP_SCTP_STACK_H
27f4b3ec61Sdh #define	_INET_SCTP_SCTP_STACK_H
28f4b3ec61Sdh 
29f4b3ec61Sdh #include <sys/netstack.h>
302ea701aaSyz #include <sys/taskq.h>
31f4b3ec61Sdh 
32f4b3ec61Sdh #ifdef	__cplusplus
33f4b3ec61Sdh extern "C" {
34f4b3ec61Sdh #endif
35f4b3ec61Sdh 
36f4b3ec61Sdh /* SCTP kstat */
37f4b3ec61Sdh typedef struct sctp_kstat_s {
38f4b3ec61Sdh 	kstat_named_t	sctp_add_faddr;
39f4b3ec61Sdh 	kstat_named_t	sctp_add_timer;
40f4b3ec61Sdh 	kstat_named_t	sctp_conn_create;
41f4b3ec61Sdh 	kstat_named_t	sctp_find_next_tq;
42f4b3ec61Sdh 	kstat_named_t	sctp_fr_add_hdr;
43f4b3ec61Sdh 	kstat_named_t	sctp_fr_not_found;
44f4b3ec61Sdh 	kstat_named_t	sctp_output_failed;
45f4b3ec61Sdh 	kstat_named_t	sctp_rexmit_failed;
46f4b3ec61Sdh 	kstat_named_t	sctp_send_init_failed;
47f4b3ec61Sdh 	kstat_named_t	sctp_send_cookie_failed;
48f4b3ec61Sdh 	kstat_named_t	sctp_send_cookie_ack_failed;
49f4b3ec61Sdh 	kstat_named_t	sctp_send_err_failed;
50f4b3ec61Sdh 	kstat_named_t	sctp_send_sack_failed;
51f4b3ec61Sdh 	kstat_named_t	sctp_send_shutdown_failed;
52f4b3ec61Sdh 	kstat_named_t	sctp_send_shutdown_ack_failed;
53f4b3ec61Sdh 	kstat_named_t	sctp_send_shutdown_comp_failed;
54f4b3ec61Sdh 	kstat_named_t	sctp_send_user_abort_failed;
55f4b3ec61Sdh 	kstat_named_t	sctp_send_asconf_failed;
56f4b3ec61Sdh 	kstat_named_t	sctp_send_asconf_ack_failed;
57f4b3ec61Sdh 	kstat_named_t	sctp_send_ftsn_failed;
58f4b3ec61Sdh 	kstat_named_t	sctp_send_hb_failed;
59f4b3ec61Sdh 	kstat_named_t	sctp_return_hb_failed;
60f4b3ec61Sdh 	kstat_named_t	sctp_ss_rexmit_failed;
61f4b3ec61Sdh 	kstat_named_t	sctp_cl_connect;
62f4b3ec61Sdh 	kstat_named_t	sctp_cl_assoc_change;
63f4b3ec61Sdh 	kstat_named_t	sctp_cl_check_addrs;
64*5dd46ab5SKacheong Poon 	kstat_named_t	sctp_reclaim_cnt;
65*5dd46ab5SKacheong Poon 	kstat_named_t	sctp_listen_cnt_drop;
66f4b3ec61Sdh } sctp_kstat_t;
67f4b3ec61Sdh 
68*5dd46ab5SKacheong Poon /*
69*5dd46ab5SKacheong Poon  * This struct contains only the counter part of sctp_kstat_t.  It is used
70*5dd46ab5SKacheong Poon  * in sctp_stats_cpu_t instead of sctp_kstat_t to save memory space.
71*5dd46ab5SKacheong Poon  */
72*5dd46ab5SKacheong Poon typedef struct sctp_kstat_counter_s {
73*5dd46ab5SKacheong Poon 	uint64_t	sctp_add_faddr;
74*5dd46ab5SKacheong Poon 	uint64_t	sctp_add_timer;
75*5dd46ab5SKacheong Poon 	uint64_t	sctp_conn_create;
76*5dd46ab5SKacheong Poon 	uint64_t	sctp_find_next_tq;
77*5dd46ab5SKacheong Poon 	uint64_t	sctp_fr_add_hdr;
78*5dd46ab5SKacheong Poon 	uint64_t	sctp_fr_not_found;
79*5dd46ab5SKacheong Poon 	uint64_t	sctp_output_failed;
80*5dd46ab5SKacheong Poon 	uint64_t	sctp_rexmit_failed;
81*5dd46ab5SKacheong Poon 	uint64_t	sctp_send_init_failed;
82*5dd46ab5SKacheong Poon 	uint64_t	sctp_send_cookie_failed;
83*5dd46ab5SKacheong Poon 	uint64_t	sctp_send_cookie_ack_failed;
84*5dd46ab5SKacheong Poon 	uint64_t	sctp_send_err_failed;
85*5dd46ab5SKacheong Poon 	uint64_t	sctp_send_sack_failed;
86*5dd46ab5SKacheong Poon 	uint64_t	sctp_send_shutdown_failed;
87*5dd46ab5SKacheong Poon 	uint64_t	sctp_send_shutdown_ack_failed;
88*5dd46ab5SKacheong Poon 	uint64_t	sctp_send_shutdown_comp_failed;
89*5dd46ab5SKacheong Poon 	uint64_t	sctp_send_user_abort_failed;
90*5dd46ab5SKacheong Poon 	uint64_t	sctp_send_asconf_failed;
91*5dd46ab5SKacheong Poon 	uint64_t	sctp_send_asconf_ack_failed;
92*5dd46ab5SKacheong Poon 	uint64_t	sctp_send_ftsn_failed;
93*5dd46ab5SKacheong Poon 	uint64_t	sctp_send_hb_failed;
94*5dd46ab5SKacheong Poon 	uint64_t	sctp_return_hb_failed;
95*5dd46ab5SKacheong Poon 	uint64_t	sctp_ss_rexmit_failed;
96*5dd46ab5SKacheong Poon 	uint64_t	sctp_cl_connect;
97*5dd46ab5SKacheong Poon 	uint64_t	sctp_cl_assoc_change;
98*5dd46ab5SKacheong Poon 	uint64_t	sctp_cl_check_addrs;
99*5dd46ab5SKacheong Poon 	uint64_t	sctp_reclaim_cnt;
100*5dd46ab5SKacheong Poon 	uint64_t	sctp_listen_cnt_drop;
101*5dd46ab5SKacheong Poon } sctp_kstat_counter_t;
102*5dd46ab5SKacheong Poon 
103*5dd46ab5SKacheong Poon /* Per CPU SCTP statistics counters. */
104*5dd46ab5SKacheong Poon typedef struct {
105*5dd46ab5SKacheong Poon 	int64_t			sctp_sc_assoc_cnt;
106*5dd46ab5SKacheong Poon 	mib2_sctp_t		sctp_sc_mib;
107*5dd46ab5SKacheong Poon 	sctp_kstat_counter_t	sctp_sc_stats;
108*5dd46ab5SKacheong Poon } sctp_stats_cpu_t;
109*5dd46ab5SKacheong Poon 
110*5dd46ab5SKacheong Poon #define	SCTP_KSTAT(sctps, x)		\
111*5dd46ab5SKacheong Poon 	((sctps)->sctps_sc[CPU->cpu_seqid]->sctp_sc_stats.x++)
112*5dd46ab5SKacheong Poon 
113*5dd46ab5SKacheong Poon #define	SCTPS_BUMP_MIB(sctps, x)	\
114*5dd46ab5SKacheong Poon 	BUMP_MIB(&(sctps)->sctps_sc[CPU->cpu_seqid]->sctp_sc_mib, x)
115*5dd46ab5SKacheong Poon 
116*5dd46ab5SKacheong Poon #define	SCTPS_UPDATE_MIB(sctps, x, y)	\
117*5dd46ab5SKacheong Poon 	UPDATE_MIB(&(sctps)->sctps_sc[CPU->cpu_seqid]->sctp_sc_mib, x, y)
118f4b3ec61Sdh 
119f4b3ec61Sdh /*
120f4b3ec61Sdh  * SCTP stack instances
121f4b3ec61Sdh  */
122f4b3ec61Sdh struct sctp_stack {
123f4b3ec61Sdh 	netstack_t	*sctps_netstack;	/* Common netstack */
124f4b3ec61Sdh 
125f4b3ec61Sdh 	/* Protected by sctps_g_lock */
126f4b3ec61Sdh 	struct list	sctps_g_list;	/* SCTP instance data chain */
127f4b3ec61Sdh 	kmutex_t	sctps_g_lock;
128f4b3ec61Sdh 
129f4b3ec61Sdh #define	SCTP_NUM_EPRIV_PORTS	64
130f4b3ec61Sdh 	int		sctps_g_num_epriv_ports;
1316e91bba0SGirish Moodalbail 	in_port_t	sctps_g_epriv_ports[SCTP_NUM_EPRIV_PORTS];
132f4b3ec61Sdh 	kmutex_t	sctps_epriv_port_lock;
133f4b3ec61Sdh 	uint_t		sctps_next_port_to_try;
134f4b3ec61Sdh 
135f4b3ec61Sdh 	/* SCTP bind hash list - all sctp_t with state >= BOUND. */
136f4b3ec61Sdh 	struct sctp_tf_s	*sctps_bind_fanout;
137f4b3ec61Sdh 	/* SCTP listen hash list - all sctp_t with state == LISTEN. */
138f4b3ec61Sdh 	struct sctp_tf_s	*sctps_listen_fanout;
139f4b3ec61Sdh 	struct sctp_tf_s	*sctps_conn_fanout;
140f4b3ec61Sdh 	uint_t			sctps_conn_hash_size;
141f4b3ec61Sdh 
1426e91bba0SGirish Moodalbail 	/* holds sctp tunables */
1436e91bba0SGirish Moodalbail 	struct mod_prop_info_s	*sctps_propinfo_tbl;
144f4b3ec61Sdh 
145*5dd46ab5SKacheong Poon 	/*
146*5dd46ab5SKacheong Poon 	 * This lock protects the SCTP recvq_tq_list array and
147*5dd46ab5SKacheong Poon 	 * recvq_tq_list_cur_sz.
148*5dd46ab5SKacheong Poon 	 */
149f4b3ec61Sdh 	kmutex_t		sctps_rq_tq_lock;
150f4b3ec61Sdh 	int			sctps_recvq_tq_list_max_sz;
151f4b3ec61Sdh 	taskq_t			**sctps_recvq_tq_list;
152f4b3ec61Sdh 
153f4b3ec61Sdh 	/* Current number of recvq taskq.  At least 1 for the default taskq. */
154f4b3ec61Sdh 	uint32_t		sctps_recvq_tq_list_cur_sz;
155f4b3ec61Sdh 	uint32_t		sctps_recvq_tq_list_cur;
156f4b3ec61Sdh 
157f4b3ec61Sdh 	/* Global list of SCTP ILLs */
158f4b3ec61Sdh 	struct sctp_ill_hash_s	*sctps_g_ills;
159f4b3ec61Sdh 	uint32_t		sctps_ills_count;
160f4b3ec61Sdh 	krwlock_t		sctps_g_ills_lock;
161f4b3ec61Sdh 
162f4b3ec61Sdh 	/* Global list of SCTP IPIFs */
163f4b3ec61Sdh 	struct sctp_ipif_hash_s	*sctps_g_ipifs;
164f4b3ec61Sdh 	uint32_t		sctps_g_ipifs_count;
165f4b3ec61Sdh 	krwlock_t		sctps_g_ipifs_lock;
166f4b3ec61Sdh 
167*5dd46ab5SKacheong Poon 	/* kstat exporting mib2_sctp_t and sctp_kstat_t data */
168f4b3ec61Sdh 	kstat_t			*sctps_mibkp;
169f4b3ec61Sdh 	kstat_t			*sctps_kstat;
170*5dd46ab5SKacheong Poon 
171*5dd46ab5SKacheong Poon 	/* Variables for handling kmem reclaim call back. */
172*5dd46ab5SKacheong Poon 	kmutex_t	sctps_reclaim_lock;
173*5dd46ab5SKacheong Poon 	boolean_t	sctps_reclaim;
174*5dd46ab5SKacheong Poon 	timeout_id_t	sctps_reclaim_tid;
175*5dd46ab5SKacheong Poon 	uint32_t	sctps_reclaim_period;
176*5dd46ab5SKacheong Poon 
177*5dd46ab5SKacheong Poon 	/* Listener association limit configuration. */
178*5dd46ab5SKacheong Poon 	kmutex_t	sctps_listener_conf_lock;
179*5dd46ab5SKacheong Poon 	list_t		sctps_listener_conf;
180*5dd46ab5SKacheong Poon 
181*5dd46ab5SKacheong Poon 	/*
182*5dd46ab5SKacheong Poon 	 * Per CPU stats
183*5dd46ab5SKacheong Poon 	 *
184*5dd46ab5SKacheong Poon 	 * sctps_sc: array of pointer to per CPU stats.  The i-th element in
185*5dd46ab5SKacheong Poon 	 *   the array represents the stats of the CPU with cpu_seqid.
186*5dd46ab5SKacheong Poon 	 * sctps_sc_cnt: number of CPU stats in the sctps_sc array.
187*5dd46ab5SKacheong Poon 	 */
188*5dd46ab5SKacheong Poon 	sctp_stats_cpu_t	**sctps_sc;
189*5dd46ab5SKacheong Poon 	int			sctps_sc_cnt;
190f4b3ec61Sdh };
191*5dd46ab5SKacheong Poon 
192f4b3ec61Sdh typedef struct sctp_stack sctp_stack_t;
193f4b3ec61Sdh 
194f4b3ec61Sdh #ifdef	__cplusplus
195f4b3ec61Sdh }
196f4b3ec61Sdh #endif
197f4b3ec61Sdh 
198f4b3ec61Sdh #endif	/* _INET_SCTP_SCTP_STACK_H */
199