xref: /freebsd/sys/netinet/sctp_sysctl.c (revision 5d08768a2b4ca4e283e6ee487d619584ca3bae1d)
142551e99SRandall Stewart /*-
2b1006367SRandall Stewart  * Copyright (c) 2007, by Cisco Systems, Inc. All rights reserved.
3807aad63SMichael Tuexen  * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
4807aad63SMichael Tuexen  * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
542551e99SRandall Stewart  *
642551e99SRandall Stewart  * Redistribution and use in source and binary forms, with or without
742551e99SRandall Stewart  * modification, are permitted provided that the following conditions are met:
842551e99SRandall Stewart  *
942551e99SRandall Stewart  * a) Redistributions of source code must retain the above copyright notice,
1042551e99SRandall Stewart  *    this list of conditions and the following disclaimer.
1142551e99SRandall Stewart  *
1242551e99SRandall Stewart  * b) Redistributions in binary form must reproduce the above copyright
1342551e99SRandall Stewart  *    notice, this list of conditions and the following disclaimer in
1442551e99SRandall Stewart  *    the documentation and/or other materials provided with the distribution.
1542551e99SRandall Stewart  *
1642551e99SRandall Stewart  * c) Neither the name of Cisco Systems, Inc. nor the names of its
1742551e99SRandall Stewart  *    contributors may be used to endorse or promote products derived
1842551e99SRandall Stewart  *    from this software without specific prior written permission.
1942551e99SRandall Stewart  *
2042551e99SRandall Stewart  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2142551e99SRandall Stewart  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
2242551e99SRandall Stewart  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2342551e99SRandall Stewart  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
2442551e99SRandall Stewart  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2542551e99SRandall Stewart  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2642551e99SRandall Stewart  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2742551e99SRandall Stewart  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2842551e99SRandall Stewart  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2942551e99SRandall Stewart  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3042551e99SRandall Stewart  * THE POSSIBILITY OF SUCH DAMAGE.
3142551e99SRandall Stewart  */
3242551e99SRandall Stewart 
3342551e99SRandall Stewart #include <sys/cdefs.h>
3442551e99SRandall Stewart __FBSDID("$FreeBSD$");
3542551e99SRandall Stewart 
3642551e99SRandall Stewart #include <netinet/sctp_os.h>
37b3f1ea41SRandall Stewart #include <netinet/sctp.h>
3842551e99SRandall Stewart #include <netinet/sctp_constants.h>
3942551e99SRandall Stewart #include <netinet/sctp_sysctl.h>
4042551e99SRandall Stewart #include <netinet/sctp_pcb.h>
4142551e99SRandall Stewart #include <netinet/sctputil.h>
42d61a0ae0SRandall Stewart #include <netinet/sctp_output.h>
43ff014514SRandall Stewart #include <sys/smp.h>
4476031b19SMichael Tuexen #include <sys/sysctl.h>
4576031b19SMichael Tuexen 
4676031b19SMichael Tuexen FEATURE(sctp, "Stream Control Transmission Protocol");
47b3f1ea41SRandall Stewart 
4842551e99SRandall Stewart /*
4942551e99SRandall Stewart  * sysctl tunable variables
5042551e99SRandall Stewart  */
515e54f665SRandall Stewart 
52b3f1ea41SRandall Stewart void
53b3f1ea41SRandall Stewart sctp_init_sysctls()
54b3f1ea41SRandall Stewart {
55b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_sendspace) = SCTPCTL_MAXDGRAM_DEFAULT;
56b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_recvspace) = SCTPCTL_RECVSPACE_DEFAULT;
57b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_auto_asconf) = SCTPCTL_AUTOASCONF_DEFAULT;
58b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_multiple_asconfs) = SCTPCTL_MULTIPLEASCONFS_DEFAULT;
59b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_ecn_enable) = SCTPCTL_ECN_ENABLE_DEFAULT;
60dd973b0eSMichael Tuexen 	SCTP_BASE_SYSCTL(sctp_pr_enable) = SCTPCTL_PR_ENABLE_DEFAULT;
6197a0ca5bSMichael Tuexen 	SCTP_BASE_SYSCTL(sctp_auth_enable) = SCTPCTL_AUTH_ENABLE_DEFAULT;
62c79bec9cSMichael Tuexen 	SCTP_BASE_SYSCTL(sctp_asconf_enable) = SCTPCTL_ASCONF_ENABLE_DEFAULT;
63317e00efSMichael Tuexen 	SCTP_BASE_SYSCTL(sctp_reconfig_enable) = SCTPCTL_RECONFIG_ENABLE_DEFAULT;
64caea9879SMichael Tuexen 	SCTP_BASE_SYSCTL(sctp_nrsack_enable) = SCTPCTL_NRSACK_ENABLE_DEFAULT;
65cb9b8e6fSMichael Tuexen 	SCTP_BASE_SYSCTL(sctp_pktdrop_enable) = SCTPCTL_PKTDROP_ENABLE_DEFAULT;
66b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_peer_chunk_oh) = SCTPCTL_PEER_CHKOH_DEFAULT;
67b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_max_burst_default) = SCTPCTL_MAXBURST_DEFAULT;
68899288aeSRandall Stewart 	SCTP_BASE_SYSCTL(sctp_fr_max_burst_default) = SCTPCTL_FRMAXBURST_DEFAULT;
69b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = SCTPCTL_MAXCHUNKS_DEFAULT;
70b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_hashtblsize) = SCTPCTL_TCBHASHSIZE_DEFAULT;
71b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_pcbtblsize) = SCTPCTL_PCBHASHSIZE_DEFAULT;
72b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_min_split_point) = SCTPCTL_MIN_SPLIT_POINT_DEFAULT;
73b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_chunkscale) = SCTPCTL_CHUNKSCALE_DEFAULT;
74b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_delayed_sack_time_default) = SCTPCTL_DELAYED_SACK_TIME_DEFAULT;
75b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_sack_freq_default) = SCTPCTL_SACK_FREQ_DEFAULT;
76b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_system_free_resc_limit) = SCTPCTL_SYS_RESOURCE_DEFAULT;
77b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_asoc_free_resc_limit) = SCTPCTL_ASOC_RESOURCE_DEFAULT;
78b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_heartbeat_interval_default) = SCTPCTL_HEARTBEAT_INTERVAL_DEFAULT;
79b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_pmtu_raise_time_default) = SCTPCTL_PMTU_RAISE_TIME_DEFAULT;
80b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_shutdown_guard_time_default) = SCTPCTL_SHUTDOWN_GUARD_TIME_DEFAULT;
81b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_secret_lifetime_default) = SCTPCTL_SECRET_LIFETIME_DEFAULT;
82b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_rto_max_default) = SCTPCTL_RTO_MAX_DEFAULT;
83b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_rto_min_default) = SCTPCTL_RTO_MIN_DEFAULT;
84b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_rto_initial_default) = SCTPCTL_RTO_INITIAL_DEFAULT;
85b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_init_rto_max_default) = SCTPCTL_INIT_RTO_MAX_DEFAULT;
86b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_valid_cookie_life_default) = SCTPCTL_VALID_COOKIE_LIFE_DEFAULT;
87b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_init_rtx_max_default) = SCTPCTL_INIT_RTX_MAX_DEFAULT;
88b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_assoc_rtx_max_default) = SCTPCTL_ASSOC_RTX_MAX_DEFAULT;
89b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_path_rtx_max_default) = SCTPCTL_PATH_RTX_MAX_DEFAULT;
90ca85e948SMichael Tuexen 	SCTP_BASE_SYSCTL(sctp_path_pf_threshold) = SCTPCTL_PATH_PF_THRESHOLD_DEFAULT;
91b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_add_more_threshold) = SCTPCTL_ADD_MORE_ON_OUTPUT_DEFAULT;
92ee1ccd92SMichael Tuexen 	SCTP_BASE_SYSCTL(sctp_nr_incoming_streams_default) = SCTPCTL_INCOMING_STREAMS_DEFAULT;
93b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_nr_outgoing_streams_default) = SCTPCTL_OUTGOING_STREAMS_DEFAULT;
94b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_cmt_on_off) = SCTPCTL_CMT_ON_OFF_DEFAULT;
95b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_cmt_use_dac) = SCTPCTL_CMT_USE_DAC_DEFAULT;
96b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_use_cwnd_based_maxburst) = SCTPCTL_CWND_MAXBURST_DEFAULT;
97b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_nat_friendly) = SCTPCTL_NAT_FRIENDLY_DEFAULT;
98b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_L2_abc_variable) = SCTPCTL_ABC_L_VAR_DEFAULT;
99b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_mbuf_threshold_count) = SCTPCTL_MAX_CHAINED_MBUFS_DEFAULT;
100b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_do_drain) = SCTPCTL_DO_SCTP_DRAIN_DEFAULT;
101b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_hb_maxburst) = SCTPCTL_HB_MAX_BURST_DEFAULT;
102b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_abort_if_one_2_one_hits_limit) = SCTPCTL_ABORT_AT_LIMIT_DEFAULT;
103b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_min_residual) = SCTPCTL_MIN_RESIDUAL_DEFAULT;
104b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_max_retran_chunk) = SCTPCTL_MAX_RETRAN_CHUNK_DEFAULT;
105b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_logging_level) = SCTPCTL_LOGGING_LEVEL_DEFAULT;
106b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_default_cc_module) = SCTPCTL_DEFAULT_CC_MODULE_DEFAULT;
107f7a77f6fSMichael Tuexen 	SCTP_BASE_SYSCTL(sctp_default_ss_module) = SCTPCTL_DEFAULT_SS_MODULE_DEFAULT;
108b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_default_frag_interleave) = SCTPCTL_DEFAULT_FRAG_INTERLEAVE_DEFAULT;
109b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_mobility_base) = SCTPCTL_MOBILITY_BASE_DEFAULT;
110b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_mobility_fasthandoff) = SCTPCTL_MOBILITY_FASTHANDOFF_DEFAULT;
111a16ccdceSRandall Stewart 	SCTP_BASE_SYSCTL(sctp_vtag_time_wait) = SCTPCTL_TIME_WAIT_DEFAULT;
11225a2a187SMichael Tuexen 	SCTP_BASE_SYSCTL(sctp_buffer_splitting) = SCTPCTL_BUFFER_SPLITTING_DEFAULT;
113dcfc0625SMichael Tuexen 	SCTP_BASE_SYSCTL(sctp_initial_cwnd) = SCTPCTL_INITIAL_CWND_DEFAULT;
114299108c5SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_rttvar_bw) = SCTPCTL_RTTVAR_BW_DEFAULT;
115299108c5SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_rttvar_rtt) = SCTPCTL_RTTVAR_RTT_DEFAULT;
116299108c5SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_rttvar_eqret) = SCTPCTL_RTTVAR_EQRET_DEFAULT;
117f79aab18SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_steady_step) = SCTPCTL_RTTVAR_STEADYS_DEFAULT;
118f79aab18SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_use_dccc_ecn) = SCTPCTL_RTTVAR_DCCCECN_DEFAULT;
119c58e60beSMichael Tuexen 	SCTP_BASE_SYSCTL(sctp_blackhole) = SCTPCTL_BLACKHOLE_DEFAULT;
120ff1ffd74SMichael Tuexen 	SCTP_BASE_SYSCTL(sctp_diag_info_code) = SCTPCTL_DIAG_INFO_CODE_DEFAULT;
121b27a6b7dSRandall Stewart #if defined(SCTP_LOCAL_TRACE_BUF)
122b3f1ea41SRandall Stewart 	memset(&SCTP_BASE_SYSCTL(sctp_log), 0, sizeof(struct sctp_log));
123b27a6b7dSRandall Stewart #endif
124b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_udp_tunneling_port) = SCTPCTL_UDP_TUNNELING_PORT_DEFAULT;
125b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_enable_sack_immediately) = SCTPCTL_SACK_IMMEDIATELY_ENABLE_DEFAULT;
126bf3d5177SMichael Tuexen 	SCTP_BASE_SYSCTL(sctp_inits_include_nat_friendly) = SCTPCTL_NAT_FRIENDLY_INITS_DEFAULT;
127b3f1ea41SRandall Stewart #if defined(SCTP_DEBUG)
128b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_debug_on) = SCTPCTL_DEBUG_DEFAULT;
12942551e99SRandall Stewart #endif
130b3f1ea41SRandall Stewart #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
131b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_output_unlocked) = SCTPCTL_OUTPUT_UNLOCKED_DEFAULT;
132b3f1ea41SRandall Stewart #endif
133b3f1ea41SRandall Stewart }
134d61a0ae0SRandall Stewart 
135a99b6783SRandall Stewart 
136d61a0ae0SRandall Stewart /* It returns an upper limit. No filtering is done here */
137d61a0ae0SRandall Stewart static unsigned int
138f47f328dSMichael Tuexen sctp_sysctl_number_of_addresses(struct sctp_inpcb *inp)
139d61a0ae0SRandall Stewart {
1407215cc1bSMichael Tuexen 	unsigned int cnt;
141d61a0ae0SRandall Stewart 	struct sctp_vrf *vrf;
142d61a0ae0SRandall Stewart 	struct sctp_ifn *sctp_ifn;
143d61a0ae0SRandall Stewart 	struct sctp_ifa *sctp_ifa;
144d61a0ae0SRandall Stewart 	struct sctp_laddr *laddr;
145d61a0ae0SRandall Stewart 
146d61a0ae0SRandall Stewart 	cnt = 0;
147d61a0ae0SRandall Stewart 	/* neither Mac OS X nor FreeBSD support mulitple routing functions */
148d61a0ae0SRandall Stewart 	if ((vrf = sctp_find_vrf(inp->def_vrf_id)) == NULL) {
149d61a0ae0SRandall Stewart 		return (0);
150d61a0ae0SRandall Stewart 	}
151d61a0ae0SRandall Stewart 	if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
152d61a0ae0SRandall Stewart 		LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
153d61a0ae0SRandall Stewart 			LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
154e6194c2eSMichael Tuexen 				switch (sctp_ifa->address.sa.sa_family) {
155e6194c2eSMichael Tuexen #ifdef INET
156e6194c2eSMichael Tuexen 				case AF_INET:
157e6194c2eSMichael Tuexen #endif
158e6194c2eSMichael Tuexen #ifdef INET6
159e6194c2eSMichael Tuexen 				case AF_INET6:
160e6194c2eSMichael Tuexen #endif
161d61a0ae0SRandall Stewart 					cnt++;
162e6194c2eSMichael Tuexen 					break;
163e6194c2eSMichael Tuexen 				default:
164e6194c2eSMichael Tuexen 					break;
165d61a0ae0SRandall Stewart 				}
166d61a0ae0SRandall Stewart 			}
167d61a0ae0SRandall Stewart 		}
168d61a0ae0SRandall Stewart 	} else {
169d61a0ae0SRandall Stewart 		LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
170e6194c2eSMichael Tuexen 			switch (laddr->ifa->address.sa.sa_family) {
171e6194c2eSMichael Tuexen #ifdef INET
172e6194c2eSMichael Tuexen 			case AF_INET:
173e6194c2eSMichael Tuexen #endif
174e6194c2eSMichael Tuexen #ifdef INET6
175e6194c2eSMichael Tuexen 			case AF_INET6:
176e6194c2eSMichael Tuexen #endif
177d61a0ae0SRandall Stewart 				cnt++;
178e6194c2eSMichael Tuexen 				break;
179e6194c2eSMichael Tuexen 			default:
180e6194c2eSMichael Tuexen 				break;
181d61a0ae0SRandall Stewart 			}
182d61a0ae0SRandall Stewart 		}
183d61a0ae0SRandall Stewart 	}
184d61a0ae0SRandall Stewart 	return (cnt);
185d61a0ae0SRandall Stewart }
186d61a0ae0SRandall Stewart 
187d61a0ae0SRandall Stewart static int
188f47f328dSMichael Tuexen sctp_sysctl_copy_out_local_addresses(struct sctp_inpcb *inp, struct sctp_tcb *stcb, struct sysctl_req *req)
189d61a0ae0SRandall Stewart {
190d61a0ae0SRandall Stewart 	struct sctp_ifn *sctp_ifn;
191d61a0ae0SRandall Stewart 	struct sctp_ifa *sctp_ifa;
192d61a0ae0SRandall Stewart 	int loopback_scope, ipv4_local_scope, local_scope, site_scope;
193d61a0ae0SRandall Stewart 	int ipv4_addr_legal, ipv6_addr_legal;
194d61a0ae0SRandall Stewart 	struct sctp_vrf *vrf;
195d61a0ae0SRandall Stewart 	struct xsctp_laddr xladdr;
196d61a0ae0SRandall Stewart 	struct sctp_laddr *laddr;
197d61a0ae0SRandall Stewart 	int error;
198d61a0ae0SRandall Stewart 
199d61a0ae0SRandall Stewart 	/* Turn on all the appropriate scope */
200d61a0ae0SRandall Stewart 	if (stcb) {
201d61a0ae0SRandall Stewart 		/* use association specific values */
202a1cb341bSMichael Tuexen 		loopback_scope = stcb->asoc.scope.loopback_scope;
203a1cb341bSMichael Tuexen 		ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
204a1cb341bSMichael Tuexen 		local_scope = stcb->asoc.scope.local_scope;
205a1cb341bSMichael Tuexen 		site_scope = stcb->asoc.scope.site_scope;
206a1cb341bSMichael Tuexen 		ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
207a1cb341bSMichael Tuexen 		ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
208d61a0ae0SRandall Stewart 	} else {
209a1cb341bSMichael Tuexen 		/* Use generic values for endpoints. */
210d61a0ae0SRandall Stewart 		loopback_scope = 1;
211d61a0ae0SRandall Stewart 		ipv4_local_scope = 1;
212d61a0ae0SRandall Stewart 		local_scope = 1;
213d61a0ae0SRandall Stewart 		site_scope = 1;
214d61a0ae0SRandall Stewart 		if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
215d61a0ae0SRandall Stewart 			ipv6_addr_legal = 1;
216d61a0ae0SRandall Stewart 			if (SCTP_IPV6_V6ONLY(inp)) {
217d61a0ae0SRandall Stewart 				ipv4_addr_legal = 0;
218d61a0ae0SRandall Stewart 			} else {
219d61a0ae0SRandall Stewart 				ipv4_addr_legal = 1;
220d61a0ae0SRandall Stewart 			}
221d61a0ae0SRandall Stewart 		} else {
222d61a0ae0SRandall Stewart 			ipv6_addr_legal = 0;
223a1cb341bSMichael Tuexen 			ipv4_addr_legal = 1;
224a1cb341bSMichael Tuexen 		}
225d61a0ae0SRandall Stewart 	}
226d61a0ae0SRandall Stewart 
227d61a0ae0SRandall Stewart 	/* neither Mac OS X nor FreeBSD support mulitple routing functions */
228d61a0ae0SRandall Stewart 	if ((vrf = sctp_find_vrf(inp->def_vrf_id)) == NULL) {
2295f26a41dSRandall Stewart 		SCTP_INP_RUNLOCK(inp);
2305f26a41dSRandall Stewart 		SCTP_INP_INFO_RUNLOCK();
231d61a0ae0SRandall Stewart 		return (-1);
232d61a0ae0SRandall Stewart 	}
233d61a0ae0SRandall Stewart 	if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
234d61a0ae0SRandall Stewart 		LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
235d61a0ae0SRandall Stewart 			if ((loopback_scope == 0) && SCTP_IFN_IS_IFT_LOOP(sctp_ifn))
236d61a0ae0SRandall Stewart 				/* Skip loopback if loopback_scope not set */
237d61a0ae0SRandall Stewart 				continue;
238d61a0ae0SRandall Stewart 			LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
239d61a0ae0SRandall Stewart 				if (stcb) {
240d61a0ae0SRandall Stewart 					/*
241d61a0ae0SRandall Stewart 					 * ignore if blacklisted at
242d61a0ae0SRandall Stewart 					 * association level
243d61a0ae0SRandall Stewart 					 */
244d61a0ae0SRandall Stewart 					if (sctp_is_addr_restricted(stcb, sctp_ifa))
245d61a0ae0SRandall Stewart 						continue;
246d61a0ae0SRandall Stewart 				}
2475e2c2d87SRandall Stewart 				switch (sctp_ifa->address.sa.sa_family) {
248e6194c2eSMichael Tuexen #ifdef INET
2495e2c2d87SRandall Stewart 				case AF_INET:
2505e2c2d87SRandall Stewart 					if (ipv4_addr_legal) {
251d61a0ae0SRandall Stewart 						struct sockaddr_in *sin;
252d61a0ae0SRandall Stewart 
25324aaac8dSMichael Tuexen 						sin = &sctp_ifa->address.sin;
254d61a0ae0SRandall Stewart 						if (sin->sin_addr.s_addr == 0)
255d61a0ae0SRandall Stewart 							continue;
2566ba22f19SMichael Tuexen 						if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
2576ba22f19SMichael Tuexen 						    &sin->sin_addr) != 0) {
2586ba22f19SMichael Tuexen 							continue;
2596ba22f19SMichael Tuexen 						}
260d61a0ae0SRandall Stewart 						if ((ipv4_local_scope == 0) && (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)))
261d61a0ae0SRandall Stewart 							continue;
2625e2c2d87SRandall Stewart 					} else {
2635e2c2d87SRandall Stewart 						continue;
2645e2c2d87SRandall Stewart 					}
2655e2c2d87SRandall Stewart 					break;
266e6194c2eSMichael Tuexen #endif
2675e2c2d87SRandall Stewart #ifdef INET6
2685e2c2d87SRandall Stewart 				case AF_INET6:
2695e2c2d87SRandall Stewart 					if (ipv6_addr_legal) {
270d61a0ae0SRandall Stewart 						struct sockaddr_in6 *sin6;
271d61a0ae0SRandall Stewart 
27224aaac8dSMichael Tuexen 						sin6 = &sctp_ifa->address.sin6;
273d61a0ae0SRandall Stewart 						if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
274d61a0ae0SRandall Stewart 							continue;
2756ba22f19SMichael Tuexen 						if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
2766ba22f19SMichael Tuexen 						    &sin6->sin6_addr) != 0) {
2776ba22f19SMichael Tuexen 							continue;
2786ba22f19SMichael Tuexen 						}
279d61a0ae0SRandall Stewart 						if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
280d61a0ae0SRandall Stewart 							if (local_scope == 0)
281d61a0ae0SRandall Stewart 								continue;
282d61a0ae0SRandall Stewart 						}
283d61a0ae0SRandall Stewart 						if ((site_scope == 0) && (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)))
284d61a0ae0SRandall Stewart 							continue;
2855e2c2d87SRandall Stewart 					} else {
286d61a0ae0SRandall Stewart 						continue;
2875e2c2d87SRandall Stewart 					}
2885e2c2d87SRandall Stewart 					break;
2895e2c2d87SRandall Stewart #endif
2905e2c2d87SRandall Stewart 				default:
2915e2c2d87SRandall Stewart 					continue;
2925e2c2d87SRandall Stewart 				}
293851b7298SRandall Stewart 				memset((void *)&xladdr, 0, sizeof(struct xsctp_laddr));
294d61a0ae0SRandall Stewart 				memcpy((void *)&xladdr.address, (const void *)&sctp_ifa->address, sizeof(union sctp_sockstore));
295d61a0ae0SRandall Stewart 				SCTP_INP_RUNLOCK(inp);
296d61a0ae0SRandall Stewart 				SCTP_INP_INFO_RUNLOCK();
297d61a0ae0SRandall Stewart 				error = SYSCTL_OUT(req, &xladdr, sizeof(struct xsctp_laddr));
298851b7298SRandall Stewart 				if (error) {
299d61a0ae0SRandall Stewart 					return (error);
300851b7298SRandall Stewart 				} else {
301d61a0ae0SRandall Stewart 					SCTP_INP_INFO_RLOCK();
302d61a0ae0SRandall Stewart 					SCTP_INP_RLOCK(inp);
303d61a0ae0SRandall Stewart 				}
304d61a0ae0SRandall Stewart 			}
305d61a0ae0SRandall Stewart 		}
306d61a0ae0SRandall Stewart 	} else {
307d61a0ae0SRandall Stewart 		LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
308d61a0ae0SRandall Stewart 			/* ignore if blacklisted at association level */
309d61a0ae0SRandall Stewart 			if (stcb && sctp_is_addr_restricted(stcb, laddr->ifa))
310d61a0ae0SRandall Stewart 				continue;
311851b7298SRandall Stewart 			memset((void *)&xladdr, 0, sizeof(struct xsctp_laddr));
312d61a0ae0SRandall Stewart 			memcpy((void *)&xladdr.address, (const void *)&laddr->ifa->address, sizeof(union sctp_sockstore));
313851b7298SRandall Stewart 			xladdr.start_time.tv_sec = (uint32_t)laddr->start_time.tv_sec;
314851b7298SRandall Stewart 			xladdr.start_time.tv_usec = (uint32_t)laddr->start_time.tv_usec;
315d61a0ae0SRandall Stewart 			SCTP_INP_RUNLOCK(inp);
316d61a0ae0SRandall Stewart 			SCTP_INP_INFO_RUNLOCK();
317d61a0ae0SRandall Stewart 			error = SYSCTL_OUT(req, &xladdr, sizeof(struct xsctp_laddr));
318851b7298SRandall Stewart 			if (error) {
319d61a0ae0SRandall Stewart 				return (error);
320851b7298SRandall Stewart 			} else {
321d61a0ae0SRandall Stewart 				SCTP_INP_INFO_RLOCK();
322d61a0ae0SRandall Stewart 				SCTP_INP_RLOCK(inp);
323d61a0ae0SRandall Stewart 			}
324d61a0ae0SRandall Stewart 		}
325d61a0ae0SRandall Stewart 	}
326851b7298SRandall Stewart 	memset((void *)&xladdr, 0, sizeof(struct xsctp_laddr));
327d61a0ae0SRandall Stewart 	xladdr.last = 1;
3285f26a41dSRandall Stewart 	SCTP_INP_RUNLOCK(inp);
3295f26a41dSRandall Stewart 	SCTP_INP_INFO_RUNLOCK();
330d61a0ae0SRandall Stewart 	error = SYSCTL_OUT(req, &xladdr, sizeof(struct xsctp_laddr));
3315f26a41dSRandall Stewart 
332851b7298SRandall Stewart 	if (error) {
333d61a0ae0SRandall Stewart 		return (error);
334851b7298SRandall Stewart 	} else {
3355f26a41dSRandall Stewart 		SCTP_INP_INFO_RLOCK();
3365f26a41dSRandall Stewart 		SCTP_INP_RLOCK(inp);
337d61a0ae0SRandall Stewart 		return (0);
338d61a0ae0SRandall Stewart 	}
3395f26a41dSRandall Stewart }
340d61a0ae0SRandall Stewart 
34142551e99SRandall Stewart /*
34242551e99SRandall Stewart  * sysctl functions
34342551e99SRandall Stewart  */
34442551e99SRandall Stewart static int
345f47f328dSMichael Tuexen sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS)
34642551e99SRandall Stewart {
34742551e99SRandall Stewart 	unsigned int number_of_endpoints;
34842551e99SRandall Stewart 	unsigned int number_of_local_addresses;
34942551e99SRandall Stewart 	unsigned int number_of_associations;
35042551e99SRandall Stewart 	unsigned int number_of_remote_addresses;
35142551e99SRandall Stewart 	unsigned int n;
35242551e99SRandall Stewart 	int error;
35342551e99SRandall Stewart 	struct sctp_inpcb *inp;
35442551e99SRandall Stewart 	struct sctp_tcb *stcb;
35542551e99SRandall Stewart 	struct sctp_nets *net;
35642551e99SRandall Stewart 	struct xsctp_inpcb xinpcb;
35742551e99SRandall Stewart 	struct xsctp_tcb xstcb;
35842551e99SRandall Stewart 	struct xsctp_raddr xraddr;
3598ce4a9a2SRandall Stewart 	struct socket *so;
36042551e99SRandall Stewart 
36142551e99SRandall Stewart 	number_of_endpoints = 0;
36242551e99SRandall Stewart 	number_of_local_addresses = 0;
36342551e99SRandall Stewart 	number_of_associations = 0;
36442551e99SRandall Stewart 	number_of_remote_addresses = 0;
36542551e99SRandall Stewart 
36642551e99SRandall Stewart 	SCTP_INP_INFO_RLOCK();
367f47f328dSMichael Tuexen 	if (req->oldptr == NULL) {
368b3f1ea41SRandall Stewart 		LIST_FOREACH(inp, &SCTP_BASE_INFO(listhead), sctp_list) {
36942551e99SRandall Stewart 			SCTP_INP_RLOCK(inp);
37042551e99SRandall Stewart 			number_of_endpoints++;
371f47f328dSMichael Tuexen 			number_of_local_addresses += sctp_sysctl_number_of_addresses(inp);
37242551e99SRandall Stewart 			LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
37342551e99SRandall Stewart 				number_of_associations++;
374f47f328dSMichael Tuexen 				number_of_local_addresses += sctp_sysctl_number_of_addresses(inp);
37542551e99SRandall Stewart 				TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
37642551e99SRandall Stewart 					number_of_remote_addresses++;
37742551e99SRandall Stewart 				}
37842551e99SRandall Stewart 			}
37942551e99SRandall Stewart 			SCTP_INP_RUNLOCK(inp);
38042551e99SRandall Stewart 		}
38142551e99SRandall Stewart 		SCTP_INP_INFO_RUNLOCK();
38242551e99SRandall Stewart 		n = (number_of_endpoints + 1) * sizeof(struct xsctp_inpcb) +
383d61a0ae0SRandall Stewart 		    (number_of_local_addresses + number_of_endpoints + number_of_associations) * sizeof(struct xsctp_laddr) +
384d61a0ae0SRandall Stewart 		    (number_of_associations + number_of_endpoints) * sizeof(struct xsctp_tcb) +
385d61a0ae0SRandall Stewart 		    (number_of_remote_addresses + number_of_associations) * sizeof(struct xsctp_raddr);
386d61a0ae0SRandall Stewart 
38742551e99SRandall Stewart 		/* request some more memory than needed */
38842551e99SRandall Stewart 		req->oldidx = (n + n / 8);
38960990c0cSMichael Tuexen 		return (0);
39042551e99SRandall Stewart 	}
391f47f328dSMichael Tuexen 	if (req->newptr != NULL) {
39242551e99SRandall Stewart 		SCTP_INP_INFO_RUNLOCK();
393c4739e2fSRandall Stewart 		SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_SYSCTL, EPERM);
39460990c0cSMichael Tuexen 		return (EPERM);
39542551e99SRandall Stewart 	}
396b3f1ea41SRandall Stewart 	LIST_FOREACH(inp, &SCTP_BASE_INFO(listhead), sctp_list) {
39742551e99SRandall Stewart 		SCTP_INP_RLOCK(inp);
3988ce4a9a2SRandall Stewart 		if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) {
3998ce4a9a2SRandall Stewart 			/* if its allgone it is being freed - skip it  */
4008ce4a9a2SRandall Stewart 			goto skip;
4018ce4a9a2SRandall Stewart 		}
40242551e99SRandall Stewart 		xinpcb.last = 0;
40342551e99SRandall Stewart 		xinpcb.local_port = ntohs(inp->sctp_lport);
40442551e99SRandall Stewart 		xinpcb.flags = inp->sctp_flags;
4056be15a24SMichael Tuexen 		xinpcb.features = inp->sctp_features;
40642551e99SRandall Stewart 		xinpcb.total_sends = inp->total_sends;
40742551e99SRandall Stewart 		xinpcb.total_recvs = inp->total_recvs;
40842551e99SRandall Stewart 		xinpcb.total_nospaces = inp->total_nospaces;
40917205eccSRandall Stewart 		xinpcb.fragmentation_point = inp->sctp_frag_point;
4100694a1bcSMichael Tuexen 		xinpcb.socket = inp->sctp_socket;
4118ce4a9a2SRandall Stewart 		so = inp->sctp_socket;
4128ce4a9a2SRandall Stewart 		if ((so == NULL) ||
413*5d08768aSMichael Tuexen 		    (!SCTP_IS_LISTENING(inp)) ||
414851b7298SRandall Stewart 		    (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
415851b7298SRandall Stewart 			xinpcb.qlen = 0;
416851b7298SRandall Stewart 			xinpcb.maxqlen = 0;
417851b7298SRandall Stewart 		} else {
4188ce4a9a2SRandall Stewart 			xinpcb.qlen = so->so_qlen;
4197325dfbbSAlfred Perlstein 			xinpcb.qlen_old = so->so_qlen > USHRT_MAX ?
4207325dfbbSAlfred Perlstein 			    USHRT_MAX : (uint16_t)so->so_qlen;
4218ce4a9a2SRandall Stewart 			xinpcb.maxqlen = so->so_qlimit;
4227325dfbbSAlfred Perlstein 			xinpcb.maxqlen_old = so->so_qlimit > USHRT_MAX ?
4237325dfbbSAlfred Perlstein 			    USHRT_MAX : (uint16_t)so->so_qlimit;
424851b7298SRandall Stewart 		}
42542551e99SRandall Stewart 		SCTP_INP_INCR_REF(inp);
42642551e99SRandall Stewart 		SCTP_INP_RUNLOCK(inp);
42742551e99SRandall Stewart 		SCTP_INP_INFO_RUNLOCK();
42842551e99SRandall Stewart 		error = SYSCTL_OUT(req, &xinpcb, sizeof(struct xsctp_inpcb));
42942551e99SRandall Stewart 		if (error) {
430d61a0ae0SRandall Stewart 			SCTP_INP_DECR_REF(inp);
43160990c0cSMichael Tuexen 			return (error);
43242551e99SRandall Stewart 		}
43342551e99SRandall Stewart 		SCTP_INP_INFO_RLOCK();
43442551e99SRandall Stewart 		SCTP_INP_RLOCK(inp);
435f47f328dSMichael Tuexen 		error = sctp_sysctl_copy_out_local_addresses(inp, NULL, req);
436d61a0ae0SRandall Stewart 		if (error) {
437d61a0ae0SRandall Stewart 			SCTP_INP_DECR_REF(inp);
43860990c0cSMichael Tuexen 			return (error);
439d61a0ae0SRandall Stewart 		}
44042551e99SRandall Stewart 		LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
44142551e99SRandall Stewart 			SCTP_TCB_LOCK(stcb);
44242551e99SRandall Stewart 			atomic_add_int(&stcb->asoc.refcnt, 1);
44342551e99SRandall Stewart 			SCTP_TCB_UNLOCK(stcb);
444d61a0ae0SRandall Stewart 			xstcb.last = 0;
445d61a0ae0SRandall Stewart 			xstcb.local_port = ntohs(inp->sctp_lport);
446d61a0ae0SRandall Stewart 			xstcb.remote_port = ntohs(stcb->rport);
44742551e99SRandall Stewart 			if (stcb->asoc.primary_destination != NULL)
448d61a0ae0SRandall Stewart 				xstcb.primary_addr = stcb->asoc.primary_destination->ro._l_addr;
449d61a0ae0SRandall Stewart 			xstcb.heartbeat_interval = stcb->asoc.heart_beat_delay;
450e92c2a8dSMichael Tuexen 			xstcb.state = (uint32_t)sctp_map_assoc_state(stcb->asoc.state);
4514f6b4933SRandall Stewart 			/* 7.0 does not support these */
452a99b6783SRandall Stewart 			xstcb.assoc_id = sctp_get_associd(stcb);
4534f6b4933SRandall Stewart 			xstcb.peers_rwnd = stcb->asoc.peers_rwnd;
454d61a0ae0SRandall Stewart 			xstcb.in_streams = stcb->asoc.streamincnt;
455d61a0ae0SRandall Stewart 			xstcb.out_streams = stcb->asoc.streamoutcnt;
456d61a0ae0SRandall Stewart 			xstcb.max_nr_retrans = stcb->asoc.overall_error_count;
457d61a0ae0SRandall Stewart 			xstcb.primary_process = 0;	/* not really supported
458d61a0ae0SRandall Stewart 							 * yet */
459d61a0ae0SRandall Stewart 			xstcb.T1_expireries = stcb->asoc.timoinit + stcb->asoc.timocookie;
460d61a0ae0SRandall Stewart 			xstcb.T2_expireries = stcb->asoc.timoshutdown + stcb->asoc.timoshutdownack;
461d61a0ae0SRandall Stewart 			xstcb.retransmitted_tsns = stcb->asoc.marked_retrans;
462851b7298SRandall Stewart 			xstcb.start_time.tv_sec = (uint32_t)stcb->asoc.start_time.tv_sec;
463851b7298SRandall Stewart 			xstcb.start_time.tv_usec = (uint32_t)stcb->asoc.start_time.tv_usec;
464851b7298SRandall Stewart 			xstcb.discontinuity_time.tv_sec = (uint32_t)stcb->asoc.discontinuity_time.tv_sec;
465851b7298SRandall Stewart 			xstcb.discontinuity_time.tv_usec = (uint32_t)stcb->asoc.discontinuity_time.tv_usec;
46642551e99SRandall Stewart 			xstcb.total_sends = stcb->total_sends;
46742551e99SRandall Stewart 			xstcb.total_recvs = stcb->total_recvs;
46842551e99SRandall Stewart 			xstcb.local_tag = stcb->asoc.my_vtag;
46942551e99SRandall Stewart 			xstcb.remote_tag = stcb->asoc.peer_vtag;
47042551e99SRandall Stewart 			xstcb.initial_tsn = stcb->asoc.init_seq_number;
47142551e99SRandall Stewart 			xstcb.highest_tsn = stcb->asoc.sending_seq - 1;
47242551e99SRandall Stewart 			xstcb.cumulative_tsn = stcb->asoc.last_acked_seq;
47342551e99SRandall Stewart 			xstcb.cumulative_tsn_ack = stcb->asoc.cumulative_tsn;
47417205eccSRandall Stewart 			xstcb.mtu = stcb->asoc.smallest_mtu;
475207304d4SRandall Stewart 			xstcb.refcnt = stcb->asoc.refcnt;
47642551e99SRandall Stewart 			SCTP_INP_RUNLOCK(inp);
47742551e99SRandall Stewart 			SCTP_INP_INFO_RUNLOCK();
47842551e99SRandall Stewart 			error = SYSCTL_OUT(req, &xstcb, sizeof(struct xsctp_tcb));
47942551e99SRandall Stewart 			if (error) {
480d61a0ae0SRandall Stewart 				SCTP_INP_DECR_REF(inp);
481851b7298SRandall Stewart 				atomic_subtract_int(&stcb->asoc.refcnt, 1);
48260990c0cSMichael Tuexen 				return (error);
483d61a0ae0SRandall Stewart 			}
484d61a0ae0SRandall Stewart 			SCTP_INP_INFO_RLOCK();
485d61a0ae0SRandall Stewart 			SCTP_INP_RLOCK(inp);
486f47f328dSMichael Tuexen 			error = sctp_sysctl_copy_out_local_addresses(inp, stcb, req);
487d61a0ae0SRandall Stewart 			if (error) {
488d61a0ae0SRandall Stewart 				SCTP_INP_DECR_REF(inp);
489851b7298SRandall Stewart 				atomic_subtract_int(&stcb->asoc.refcnt, 1);
49060990c0cSMichael Tuexen 				return (error);
49142551e99SRandall Stewart 			}
49242551e99SRandall Stewart 			TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
493d61a0ae0SRandall Stewart 				xraddr.last = 0;
494d61a0ae0SRandall Stewart 				xraddr.address = net->ro._l_addr;
495d61a0ae0SRandall Stewart 				xraddr.active = ((net->dest_state & SCTP_ADDR_REACHABLE) == SCTP_ADDR_REACHABLE);
496d61a0ae0SRandall Stewart 				xraddr.confirmed = ((net->dest_state & SCTP_ADDR_UNCONFIRMED) == 0);
497d61a0ae0SRandall Stewart 				xraddr.heartbeat_enabled = ((net->dest_state & SCTP_ADDR_NOHB) == 0);
498ca85e948SMichael Tuexen 				xraddr.potentially_failed = ((net->dest_state & SCTP_ADDR_PF) == SCTP_ADDR_PF);
499d61a0ae0SRandall Stewart 				xraddr.rto = net->RTO;
500d61a0ae0SRandall Stewart 				xraddr.max_path_rtx = net->failure_threshold;
501d61a0ae0SRandall Stewart 				xraddr.rtx = net->marked_retrans;
502d61a0ae0SRandall Stewart 				xraddr.error_counter = net->error_count;
503d61a0ae0SRandall Stewart 				xraddr.cwnd = net->cwnd;
504d61a0ae0SRandall Stewart 				xraddr.flight_size = net->flight_size;
505d61a0ae0SRandall Stewart 				xraddr.mtu = net->mtu;
506be1d9176SMichael Tuexen 				xraddr.rtt = net->rtt / 1000;
507ca85e948SMichael Tuexen 				xraddr.heartbeat_interval = net->heart_beat_delay;
50829b9533bSMichael Tuexen 				xraddr.ssthresh = net->ssthresh;
509851b7298SRandall Stewart 				xraddr.start_time.tv_sec = (uint32_t)net->start_time.tv_sec;
510851b7298SRandall Stewart 				xraddr.start_time.tv_usec = (uint32_t)net->start_time.tv_usec;
511d61a0ae0SRandall Stewart 				SCTP_INP_RUNLOCK(inp);
512d61a0ae0SRandall Stewart 				SCTP_INP_INFO_RUNLOCK();
51342551e99SRandall Stewart 				error = SYSCTL_OUT(req, &xraddr, sizeof(struct xsctp_raddr));
51442551e99SRandall Stewart 				if (error) {
515d61a0ae0SRandall Stewart 					SCTP_INP_DECR_REF(inp);
516851b7298SRandall Stewart 					atomic_subtract_int(&stcb->asoc.refcnt, 1);
51760990c0cSMichael Tuexen 					return (error);
51842551e99SRandall Stewart 				}
51942551e99SRandall Stewart 				SCTP_INP_INFO_RLOCK();
52042551e99SRandall Stewart 				SCTP_INP_RLOCK(inp);
52142551e99SRandall Stewart 			}
522851b7298SRandall Stewart 			atomic_subtract_int(&stcb->asoc.refcnt, 1);
523d61a0ae0SRandall Stewart 			memset((void *)&xraddr, 0, sizeof(struct xsctp_raddr));
524d61a0ae0SRandall Stewart 			xraddr.last = 1;
52542551e99SRandall Stewart 			SCTP_INP_RUNLOCK(inp);
526d61a0ae0SRandall Stewart 			SCTP_INP_INFO_RUNLOCK();
527d61a0ae0SRandall Stewart 			error = SYSCTL_OUT(req, &xraddr, sizeof(struct xsctp_raddr));
528d61a0ae0SRandall Stewart 			if (error) {
529d61a0ae0SRandall Stewart 				SCTP_INP_DECR_REF(inp);
53060990c0cSMichael Tuexen 				return (error);
531d61a0ae0SRandall Stewart 			}
532d61a0ae0SRandall Stewart 			SCTP_INP_INFO_RLOCK();
533d61a0ae0SRandall Stewart 			SCTP_INP_RLOCK(inp);
534d61a0ae0SRandall Stewart 		}
535851b7298SRandall Stewart 		SCTP_INP_DECR_REF(inp);
536d61a0ae0SRandall Stewart 		SCTP_INP_RUNLOCK(inp);
537d61a0ae0SRandall Stewart 		SCTP_INP_INFO_RUNLOCK();
538d61a0ae0SRandall Stewart 		memset((void *)&xstcb, 0, sizeof(struct xsctp_tcb));
539d61a0ae0SRandall Stewart 		xstcb.last = 1;
540d61a0ae0SRandall Stewart 		error = SYSCTL_OUT(req, &xstcb, sizeof(struct xsctp_tcb));
541d61a0ae0SRandall Stewart 		if (error) {
54260990c0cSMichael Tuexen 			return (error);
543d61a0ae0SRandall Stewart 		}
5448ce4a9a2SRandall Stewart skip:
545d61a0ae0SRandall Stewart 		SCTP_INP_INFO_RLOCK();
54642551e99SRandall Stewart 	}
54742551e99SRandall Stewart 	SCTP_INP_INFO_RUNLOCK();
54842551e99SRandall Stewart 
549d61a0ae0SRandall Stewart 	memset((void *)&xinpcb, 0, sizeof(struct xsctp_inpcb));
55042551e99SRandall Stewart 	xinpcb.last = 1;
55142551e99SRandall Stewart 	error = SYSCTL_OUT(req, &xinpcb, sizeof(struct xsctp_inpcb));
55260990c0cSMichael Tuexen 	return (error);
55342551e99SRandall Stewart }
55442551e99SRandall Stewart 
555851b7298SRandall Stewart static int
556f47f328dSMichael Tuexen sctp_sysctl_handle_udp_tunneling(SYSCTL_HANDLER_ARGS)
557c54a18d2SRandall Stewart {
558c54a18d2SRandall Stewart 	int error;
559f47f328dSMichael Tuexen 	uint32_t old, new;
560c54a18d2SRandall Stewart 
561be27fdd0SRandall Stewart 	SCTP_INP_INFO_RLOCK();
562f47f328dSMichael Tuexen 	old = SCTP_BASE_SYSCTL(sctp_udp_tunneling_port);
563be27fdd0SRandall Stewart 	SCTP_INP_INFO_RUNLOCK();
564f47f328dSMichael Tuexen 	new = old;
565f47f328dSMichael Tuexen 	error = sysctl_handle_int(oidp, &new, 0, req);
566f47f328dSMichael Tuexen 	if ((error == 0) &&
567f47f328dSMichael Tuexen 	    (req->newptr != NULL)) {
568bcbf8c21SMichael Tuexen #if (SCTPCTL_UDP_TUNNELING_PORT_MIN == 0)
569bcbf8c21SMichael Tuexen 		if (new > SCTPCTL_UDP_TUNNELING_PORT_MAX) {
570bcbf8c21SMichael Tuexen #else
571f47f328dSMichael Tuexen 		if ((new < SCTPCTL_UDP_TUNNELING_PORT_MIN) ||
572f47f328dSMichael Tuexen 		    (new > SCTPCTL_UDP_TUNNELING_PORT_MAX)) {
573bcbf8c21SMichael Tuexen #endif
574f47f328dSMichael Tuexen 			error = EINVAL;
575f47f328dSMichael Tuexen 		} else {
576be27fdd0SRandall Stewart 			SCTP_INP_INFO_WLOCK();
577f47f328dSMichael Tuexen 			SCTP_BASE_SYSCTL(sctp_udp_tunneling_port) = new;
578f47f328dSMichael Tuexen 			if (old != 0) {
579c54a18d2SRandall Stewart 				sctp_over_udp_stop();
580c54a18d2SRandall Stewart 			}
581f47f328dSMichael Tuexen 			if (new != 0) {
582f47f328dSMichael Tuexen 				error = sctp_over_udp_start();
583c54a18d2SRandall Stewart 			}
584be27fdd0SRandall Stewart 			SCTP_INP_INFO_WUNLOCK();
585c54a18d2SRandall Stewart 		}
586f47f328dSMichael Tuexen 	}
587c54a18d2SRandall Stewart 	return (error);
588c54a18d2SRandall Stewart }
589c54a18d2SRandall Stewart 
590b3f1ea41SRandall Stewart 
591c54a18d2SRandall Stewart static int
592f47f328dSMichael Tuexen sctp_sysctl_handle_auth(SYSCTL_HANDLER_ARGS)
593f47f328dSMichael Tuexen {
594f47f328dSMichael Tuexen 	int error;
595f47f328dSMichael Tuexen 	uint32_t new;
596f47f328dSMichael Tuexen 
597f47f328dSMichael Tuexen 	new = SCTP_BASE_SYSCTL(sctp_auth_enable);
598f47f328dSMichael Tuexen 	error = sysctl_handle_int(oidp, &new, 0, req);
599f47f328dSMichael Tuexen 	if ((error == 0) &&
600f47f328dSMichael Tuexen 	    (req->newptr != NULL)) {
601bcbf8c21SMichael Tuexen #if (SCTPCTL_AUTH_ENABLE_MIN == 0)
602bcbf8c21SMichael Tuexen 		if ((new > SCTPCTL_AUTH_ENABLE_MAX) ||
603bcbf8c21SMichael Tuexen 		    ((new == 0) && (SCTP_BASE_SYSCTL(sctp_asconf_enable) == 1))) {
604bcbf8c21SMichael Tuexen #else
605f47f328dSMichael Tuexen 		if ((new < SCTPCTL_AUTH_ENABLE_MIN) ||
606f47f328dSMichael Tuexen 		    (new > SCTPCTL_AUTH_ENABLE_MAX) ||
607f47f328dSMichael Tuexen 		    ((new == 0) && (SCTP_BASE_SYSCTL(sctp_asconf_enable) == 1))) {
608bcbf8c21SMichael Tuexen #endif
609f47f328dSMichael Tuexen 			error = EINVAL;
610f47f328dSMichael Tuexen 		} else {
611f47f328dSMichael Tuexen 			SCTP_BASE_SYSCTL(sctp_auth_enable) = new;
612f47f328dSMichael Tuexen 		}
613f47f328dSMichael Tuexen 	}
614f47f328dSMichael Tuexen 	return (error);
615f47f328dSMichael Tuexen }
616f47f328dSMichael Tuexen 
617f47f328dSMichael Tuexen static int
618f47f328dSMichael Tuexen sctp_sysctl_handle_asconf(SYSCTL_HANDLER_ARGS)
619f47f328dSMichael Tuexen {
620f47f328dSMichael Tuexen 	int error;
621f47f328dSMichael Tuexen 	uint32_t new;
622f47f328dSMichael Tuexen 
623f47f328dSMichael Tuexen 	new = SCTP_BASE_SYSCTL(sctp_asconf_enable);
624f47f328dSMichael Tuexen 	error = sysctl_handle_int(oidp, &new, 0, req);
625f47f328dSMichael Tuexen 	if ((error == 0) &&
626f47f328dSMichael Tuexen 	    (req->newptr != NULL)) {
627bcbf8c21SMichael Tuexen #if (SCTPCTL_ASCONF_ENABLE_MIN == 0)
628bcbf8c21SMichael Tuexen 		if ((new > SCTPCTL_ASCONF_ENABLE_MAX) ||
629bcbf8c21SMichael Tuexen 		    ((new == 1) && (SCTP_BASE_SYSCTL(sctp_auth_enable) == 0))) {
630bcbf8c21SMichael Tuexen #else
631f47f328dSMichael Tuexen 		if ((new < SCTPCTL_ASCONF_ENABLE_MIN) ||
632f47f328dSMichael Tuexen 		    (new > SCTPCTL_ASCONF_ENABLE_MAX) ||
633f47f328dSMichael Tuexen 		    ((new == 1) && (SCTP_BASE_SYSCTL(sctp_auth_enable) == 0))) {
634bcbf8c21SMichael Tuexen #endif
635f47f328dSMichael Tuexen 			error = EINVAL;
636f47f328dSMichael Tuexen 		} else {
637f47f328dSMichael Tuexen 			SCTP_BASE_SYSCTL(sctp_asconf_enable) = new;
638f47f328dSMichael Tuexen 		}
639f47f328dSMichael Tuexen 	}
640f47f328dSMichael Tuexen 	return (error);
641f47f328dSMichael Tuexen }
642f47f328dSMichael Tuexen 
643f47f328dSMichael Tuexen static int
644f47f328dSMichael Tuexen sctp_sysctl_handle_stats(SYSCTL_HANDLER_ARGS)
645851b7298SRandall Stewart {
646851b7298SRandall Stewart 	int error;
647f47f328dSMichael Tuexen #if defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
6480e1152fcSHans Petter Selasky 	struct sctpstat *sarry;
6490e1152fcSHans Petter Selasky 	struct sctpstat sb;
650f47f328dSMichael Tuexen 	int cpu;
651b3f1ea41SRandall Stewart #endif
652f885296dSMichael Tuexen 	struct sctpstat sb_temp;
65342551e99SRandall Stewart 
654f47f328dSMichael Tuexen 	if ((req->newptr != NULL) &&
655f47f328dSMichael Tuexen 	    (req->newlen != sizeof(struct sctpstat))) {
656ae26e0a4SRandall Stewart 		return (EINVAL);
657ae26e0a4SRandall Stewart 	}
658f885296dSMichael Tuexen 	memset(&sb_temp, 0, sizeof(struct sctpstat));
6590e1152fcSHans Petter Selasky 
6600e1152fcSHans Petter Selasky 	if (req->newptr != NULL) {
661f885296dSMichael Tuexen 		error = SYSCTL_IN(req, &sb_temp, sizeof(struct sctpstat));
662f885296dSMichael Tuexen 		if (error != 0) {
6630e1152fcSHans Petter Selasky 			return (error);
6640e1152fcSHans Petter Selasky 		}
665f885296dSMichael Tuexen 	}
666f885296dSMichael Tuexen #if defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
667f885296dSMichael Tuexen 	memset(&sb, 0, sizeof(sb));
668dec0177dSRandall Stewart 	for (cpu = 0; cpu < mp_maxid; cpu++) {
669ff014514SRandall Stewart 		sarry = &SCTP_BASE_STATS[cpu];
670ff014514SRandall Stewart 		if (sarry->sctps_discontinuitytime.tv_sec > sb.sctps_discontinuitytime.tv_sec) {
671ff014514SRandall Stewart 			sb.sctps_discontinuitytime.tv_sec = sarry->sctps_discontinuitytime.tv_sec;
672ff014514SRandall Stewart 			sb.sctps_discontinuitytime.tv_usec = sarry->sctps_discontinuitytime.tv_usec;
673ff014514SRandall Stewart 		}
674ff014514SRandall Stewart 		sb.sctps_currestab += sarry->sctps_currestab;
675ff014514SRandall Stewart 		sb.sctps_activeestab += sarry->sctps_activeestab;
676ff014514SRandall Stewart 		sb.sctps_restartestab += sarry->sctps_restartestab;
677ff014514SRandall Stewart 		sb.sctps_collisionestab += sarry->sctps_collisionestab;
678ff014514SRandall Stewart 		sb.sctps_passiveestab += sarry->sctps_passiveestab;
679ff014514SRandall Stewart 		sb.sctps_aborted += sarry->sctps_aborted;
680ff014514SRandall Stewart 		sb.sctps_shutdown += sarry->sctps_shutdown;
681ff014514SRandall Stewart 		sb.sctps_outoftheblue += sarry->sctps_outoftheblue;
682ff014514SRandall Stewart 		sb.sctps_checksumerrors += sarry->sctps_checksumerrors;
683ff014514SRandall Stewart 		sb.sctps_outcontrolchunks += sarry->sctps_outcontrolchunks;
684ff014514SRandall Stewart 		sb.sctps_outorderchunks += sarry->sctps_outorderchunks;
685ff014514SRandall Stewart 		sb.sctps_outunorderchunks += sarry->sctps_outunorderchunks;
686ff014514SRandall Stewart 		sb.sctps_incontrolchunks += sarry->sctps_incontrolchunks;
687ff014514SRandall Stewart 		sb.sctps_inorderchunks += sarry->sctps_inorderchunks;
688ff014514SRandall Stewart 		sb.sctps_inunorderchunks += sarry->sctps_inunorderchunks;
689ff014514SRandall Stewart 		sb.sctps_fragusrmsgs += sarry->sctps_fragusrmsgs;
690ff014514SRandall Stewart 		sb.sctps_reasmusrmsgs += sarry->sctps_reasmusrmsgs;
691ff014514SRandall Stewart 		sb.sctps_outpackets += sarry->sctps_outpackets;
692ff014514SRandall Stewart 		sb.sctps_inpackets += sarry->sctps_inpackets;
693ff014514SRandall Stewart 		sb.sctps_recvpackets += sarry->sctps_recvpackets;
694ff014514SRandall Stewart 		sb.sctps_recvdatagrams += sarry->sctps_recvdatagrams;
695ff014514SRandall Stewart 		sb.sctps_recvpktwithdata += sarry->sctps_recvpktwithdata;
696ff014514SRandall Stewart 		sb.sctps_recvsacks += sarry->sctps_recvsacks;
697ff014514SRandall Stewart 		sb.sctps_recvdata += sarry->sctps_recvdata;
698ff014514SRandall Stewart 		sb.sctps_recvdupdata += sarry->sctps_recvdupdata;
699ff014514SRandall Stewart 		sb.sctps_recvheartbeat += sarry->sctps_recvheartbeat;
700ff014514SRandall Stewart 		sb.sctps_recvheartbeatack += sarry->sctps_recvheartbeatack;
701ff014514SRandall Stewart 		sb.sctps_recvecne += sarry->sctps_recvecne;
702ff014514SRandall Stewart 		sb.sctps_recvauth += sarry->sctps_recvauth;
703ff014514SRandall Stewart 		sb.sctps_recvauthmissing += sarry->sctps_recvauthmissing;
704ff014514SRandall Stewart 		sb.sctps_recvivalhmacid += sarry->sctps_recvivalhmacid;
705ff014514SRandall Stewart 		sb.sctps_recvivalkeyid += sarry->sctps_recvivalkeyid;
706ff014514SRandall Stewart 		sb.sctps_recvauthfailed += sarry->sctps_recvauthfailed;
707ff014514SRandall Stewart 		sb.sctps_recvexpress += sarry->sctps_recvexpress;
708ff014514SRandall Stewart 		sb.sctps_recvexpressm += sarry->sctps_recvexpressm;
709ff014514SRandall Stewart 		sb.sctps_recvnocrc += sarry->sctps_recvnocrc;
710ff014514SRandall Stewart 		sb.sctps_recvswcrc += sarry->sctps_recvswcrc;
711ff014514SRandall Stewart 		sb.sctps_recvhwcrc += sarry->sctps_recvhwcrc;
712ff014514SRandall Stewart 		sb.sctps_sendpackets += sarry->sctps_sendpackets;
713ff014514SRandall Stewart 		sb.sctps_sendsacks += sarry->sctps_sendsacks;
714ff014514SRandall Stewart 		sb.sctps_senddata += sarry->sctps_senddata;
715ff014514SRandall Stewart 		sb.sctps_sendretransdata += sarry->sctps_sendretransdata;
716ff014514SRandall Stewart 		sb.sctps_sendfastretrans += sarry->sctps_sendfastretrans;
717ff014514SRandall Stewart 		sb.sctps_sendmultfastretrans += sarry->sctps_sendmultfastretrans;
718ff014514SRandall Stewart 		sb.sctps_sendheartbeat += sarry->sctps_sendheartbeat;
719ff014514SRandall Stewart 		sb.sctps_sendecne += sarry->sctps_sendecne;
720ff014514SRandall Stewart 		sb.sctps_sendauth += sarry->sctps_sendauth;
721ff014514SRandall Stewart 		sb.sctps_senderrors += sarry->sctps_senderrors;
722ff014514SRandall Stewart 		sb.sctps_sendnocrc += sarry->sctps_sendnocrc;
723ff014514SRandall Stewart 		sb.sctps_sendswcrc += sarry->sctps_sendswcrc;
724ff014514SRandall Stewart 		sb.sctps_sendhwcrc += sarry->sctps_sendhwcrc;
725ff014514SRandall Stewart 		sb.sctps_pdrpfmbox += sarry->sctps_pdrpfmbox;
726ff014514SRandall Stewart 		sb.sctps_pdrpfehos += sarry->sctps_pdrpfehos;
727ff014514SRandall Stewart 		sb.sctps_pdrpmbda += sarry->sctps_pdrpmbda;
728ff014514SRandall Stewart 		sb.sctps_pdrpmbct += sarry->sctps_pdrpmbct;
729ff014514SRandall Stewart 		sb.sctps_pdrpbwrpt += sarry->sctps_pdrpbwrpt;
730ff014514SRandall Stewart 		sb.sctps_pdrpcrupt += sarry->sctps_pdrpcrupt;
731ff014514SRandall Stewart 		sb.sctps_pdrpnedat += sarry->sctps_pdrpnedat;
732ff014514SRandall Stewart 		sb.sctps_pdrppdbrk += sarry->sctps_pdrppdbrk;
733ff014514SRandall Stewart 		sb.sctps_pdrptsnnf += sarry->sctps_pdrptsnnf;
734ff014514SRandall Stewart 		sb.sctps_pdrpdnfnd += sarry->sctps_pdrpdnfnd;
735ff014514SRandall Stewart 		sb.sctps_pdrpdiwnp += sarry->sctps_pdrpdiwnp;
736ff014514SRandall Stewart 		sb.sctps_pdrpdizrw += sarry->sctps_pdrpdizrw;
737ff014514SRandall Stewart 		sb.sctps_pdrpbadd += sarry->sctps_pdrpbadd;
738ff014514SRandall Stewart 		sb.sctps_pdrpmark += sarry->sctps_pdrpmark;
739ff014514SRandall Stewart 		sb.sctps_timoiterator += sarry->sctps_timoiterator;
740ff014514SRandall Stewart 		sb.sctps_timodata += sarry->sctps_timodata;
741ff014514SRandall Stewart 		sb.sctps_timowindowprobe += sarry->sctps_timowindowprobe;
742ff014514SRandall Stewart 		sb.sctps_timoinit += sarry->sctps_timoinit;
743ff014514SRandall Stewart 		sb.sctps_timosack += sarry->sctps_timosack;
744ff014514SRandall Stewart 		sb.sctps_timoshutdown += sarry->sctps_timoshutdown;
745ff014514SRandall Stewart 		sb.sctps_timoheartbeat += sarry->sctps_timoheartbeat;
746ff014514SRandall Stewart 		sb.sctps_timocookie += sarry->sctps_timocookie;
747ff014514SRandall Stewart 		sb.sctps_timosecret += sarry->sctps_timosecret;
748ff014514SRandall Stewart 		sb.sctps_timopathmtu += sarry->sctps_timopathmtu;
749ff014514SRandall Stewart 		sb.sctps_timoshutdownack += sarry->sctps_timoshutdownack;
750ff014514SRandall Stewart 		sb.sctps_timoshutdownguard += sarry->sctps_timoshutdownguard;
751ff014514SRandall Stewart 		sb.sctps_timostrmrst += sarry->sctps_timostrmrst;
752ff014514SRandall Stewart 		sb.sctps_timoearlyfr += sarry->sctps_timoearlyfr;
753ff014514SRandall Stewart 		sb.sctps_timoasconf += sarry->sctps_timoasconf;
754ff014514SRandall Stewart 		sb.sctps_timodelprim += sarry->sctps_timodelprim;
755ff014514SRandall Stewart 		sb.sctps_timoautoclose += sarry->sctps_timoautoclose;
756ff014514SRandall Stewart 		sb.sctps_timoassockill += sarry->sctps_timoassockill;
757ff014514SRandall Stewart 		sb.sctps_timoinpkill += sarry->sctps_timoinpkill;
758ff014514SRandall Stewart 		sb.sctps_hdrops += sarry->sctps_hdrops;
759ff014514SRandall Stewart 		sb.sctps_badsum += sarry->sctps_badsum;
760ff014514SRandall Stewart 		sb.sctps_noport += sarry->sctps_noport;
761ff014514SRandall Stewart 		sb.sctps_badvtag += sarry->sctps_badvtag;
762ff014514SRandall Stewart 		sb.sctps_badsid += sarry->sctps_badsid;
763ff014514SRandall Stewart 		sb.sctps_nomem += sarry->sctps_nomem;
764ff014514SRandall Stewart 		sb.sctps_fastretransinrtt += sarry->sctps_fastretransinrtt;
765ff014514SRandall Stewart 		sb.sctps_markedretrans += sarry->sctps_markedretrans;
766ff014514SRandall Stewart 		sb.sctps_naglesent += sarry->sctps_naglesent;
767ff014514SRandall Stewart 		sb.sctps_naglequeued += sarry->sctps_naglequeued;
768ff014514SRandall Stewart 		sb.sctps_maxburstqueued += sarry->sctps_maxburstqueued;
769ff014514SRandall Stewart 		sb.sctps_ifnomemqueued += sarry->sctps_ifnomemqueued;
770ff014514SRandall Stewart 		sb.sctps_windowprobed += sarry->sctps_windowprobed;
771ff014514SRandall Stewart 		sb.sctps_lowlevelerr += sarry->sctps_lowlevelerr;
772ff014514SRandall Stewart 		sb.sctps_lowlevelerrusr += sarry->sctps_lowlevelerrusr;
773ff014514SRandall Stewart 		sb.sctps_datadropchklmt += sarry->sctps_datadropchklmt;
774ff014514SRandall Stewart 		sb.sctps_datadroprwnd += sarry->sctps_datadroprwnd;
775ff014514SRandall Stewart 		sb.sctps_ecnereducedcwnd += sarry->sctps_ecnereducedcwnd;
776ff014514SRandall Stewart 		sb.sctps_vtagexpress += sarry->sctps_vtagexpress;
777ff014514SRandall Stewart 		sb.sctps_vtagbogus += sarry->sctps_vtagbogus;
778ff014514SRandall Stewart 		sb.sctps_primary_randry += sarry->sctps_primary_randry;
779ff014514SRandall Stewart 		sb.sctps_cmt_randry += sarry->sctps_cmt_randry;
780ff014514SRandall Stewart 		sb.sctps_slowpath_sack += sarry->sctps_slowpath_sack;
781ff014514SRandall Stewart 		sb.sctps_wu_sacks_sent += sarry->sctps_wu_sacks_sent;
782ff014514SRandall Stewart 		sb.sctps_sends_with_flags += sarry->sctps_sends_with_flags;
783ff014514SRandall Stewart 		sb.sctps_sends_with_unord += sarry->sctps_sends_with_unord;
784ff014514SRandall Stewart 		sb.sctps_sends_with_eof += sarry->sctps_sends_with_eof;
785ff014514SRandall Stewart 		sb.sctps_sends_with_abort += sarry->sctps_sends_with_abort;
786ff014514SRandall Stewart 		sb.sctps_protocol_drain_calls += sarry->sctps_protocol_drain_calls;
787ff014514SRandall Stewart 		sb.sctps_protocol_drains_done += sarry->sctps_protocol_drains_done;
788ff014514SRandall Stewart 		sb.sctps_read_peeks += sarry->sctps_read_peeks;
789ff014514SRandall Stewart 		sb.sctps_cached_chk += sarry->sctps_cached_chk;
790ff014514SRandall Stewart 		sb.sctps_cached_strmoq += sarry->sctps_cached_strmoq;
791ff014514SRandall Stewart 		sb.sctps_left_abandon += sarry->sctps_left_abandon;
792ff014514SRandall Stewart 		sb.sctps_send_burst_avoid += sarry->sctps_send_burst_avoid;
793ff014514SRandall Stewart 		sb.sctps_send_cwnd_avoid += sarry->sctps_send_cwnd_avoid;
794ff014514SRandall Stewart 		sb.sctps_fwdtsn_map_over += sarry->sctps_fwdtsn_map_over;
795f885296dSMichael Tuexen 		if (req->newptr != NULL) {
7960e1152fcSHans Petter Selasky 			memcpy(sarry, &sb_temp, sizeof(struct sctpstat));
797ff014514SRandall Stewart 		}
798f885296dSMichael Tuexen 	}
799f47f328dSMichael Tuexen 	error = SYSCTL_OUT(req, &sb, sizeof(struct sctpstat));
800f47f328dSMichael Tuexen #else
801f47f328dSMichael Tuexen 	error = SYSCTL_OUT(req, &SCTP_BASE_STATS, sizeof(struct sctpstat));
802f885296dSMichael Tuexen 	if (error != 0) {
803f885296dSMichael Tuexen 		return (error);
804f885296dSMichael Tuexen 	}
805f885296dSMichael Tuexen 	if (req->newptr != NULL) {
806f885296dSMichael Tuexen 		memcpy(&SCTP_BASE_STATS, &sb_temp, sizeof(struct sctpstat));
807f885296dSMichael Tuexen 	}
808f47f328dSMichael Tuexen #endif
809ff014514SRandall Stewart 	return (error);
810ff014514SRandall Stewart }
811ff014514SRandall Stewart 
812b3f1ea41SRandall Stewart #if defined(SCTP_LOCAL_TRACE_BUF)
813b3f1ea41SRandall Stewart static int
814f47f328dSMichael Tuexen sctp_sysctl_handle_trace_log(SYSCTL_HANDLER_ARGS)
815f47f328dSMichael Tuexen {
816f47f328dSMichael Tuexen 	int error;
817f47f328dSMichael Tuexen 
818f47f328dSMichael Tuexen 	error = SYSCTL_OUT(req, &SCTP_BASE_SYSCTL(sctp_log), sizeof(struct sctp_log));
819f47f328dSMichael Tuexen 	return (error);
820f47f328dSMichael Tuexen }
821f47f328dSMichael Tuexen 
822f47f328dSMichael Tuexen static int
823f47f328dSMichael Tuexen sctp_sysctl_handle_trace_log_clear(SYSCTL_HANDLER_ARGS)
824b3f1ea41SRandall Stewart {
825a99b6783SRandall Stewart 	int error = 0;
826a99b6783SRandall Stewart 
827b3f1ea41SRandall Stewart 	memset(&SCTP_BASE_SYSCTL(sctp_log), 0, sizeof(struct sctp_log));
828a99b6783SRandall Stewart 	return (error);
829b3f1ea41SRandall Stewart }
830b3f1ea41SRandall Stewart #endif
831b3f1ea41SRandall Stewart 
832f47f328dSMichael Tuexen #define SCTP_UINT_SYSCTL(mib_name, var_name, prefix)			\
833f47f328dSMichael Tuexen 	static int							\
834f47f328dSMichael Tuexen 	sctp_sysctl_handle_##mib_name(SYSCTL_HANDLER_ARGS)		\
835f47f328dSMichael Tuexen 	{								\
836f47f328dSMichael Tuexen 		int error;						\
837f47f328dSMichael Tuexen 		uint32_t new;						\
838f47f328dSMichael Tuexen 									\
839f47f328dSMichael Tuexen 		new = SCTP_BASE_SYSCTL(var_name);			\
840f47f328dSMichael Tuexen 		error = sysctl_handle_int(oidp, &new, 0, req);		\
841f47f328dSMichael Tuexen 		if ((error == 0) && (req->newptr != NULL)) {		\
842f47f328dSMichael Tuexen 			if ((new < prefix##_MIN) ||			\
843f47f328dSMichael Tuexen 			    (new > prefix##_MAX)) {			\
844f47f328dSMichael Tuexen 				error = EINVAL;				\
845f47f328dSMichael Tuexen 			} else {					\
846f47f328dSMichael Tuexen 				SCTP_BASE_SYSCTL(var_name) = new;	\
847f47f328dSMichael Tuexen 			}						\
848f47f328dSMichael Tuexen 		}							\
849f47f328dSMichael Tuexen 		return (error);						\
850f47f328dSMichael Tuexen 	}								\
85195e55080SMichael Tuexen 	SYSCTL_PROC(_net_inet_sctp, OID_AUTO, mib_name,			\
85295e55080SMichael Tuexen 	                 CTLFLAG_VNET|CTLTYPE_UINT|CTLFLAG_RW, NULL, 0,	\
853f47f328dSMichael Tuexen 	                 sctp_sysctl_handle_##mib_name, "UI", prefix##_DESC);
854b3f1ea41SRandall Stewart 
85542551e99SRandall Stewart /*
85642551e99SRandall Stewart  * sysctl definitions
85742551e99SRandall Stewart  */
85842551e99SRandall Stewart 
859f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(sendspace, sctp_sendspace, SCTPCTL_MAXDGRAM)
860f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(recvspace, sctp_recvspace, SCTPCTL_RECVSPACE)
861f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(auto_asconf, sctp_auto_asconf, SCTPCTL_AUTOASCONF)
862f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(ecn_enable, sctp_ecn_enable, SCTPCTL_ECN_ENABLE)
863f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(pr_enable, sctp_pr_enable, SCTPCTL_PR_ENABLE)
86495e55080SMichael Tuexen SYSCTL_PROC(_net_inet_sctp, OID_AUTO, auth_enable, CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW,
865f47f328dSMichael Tuexen     NULL, 0, sctp_sysctl_handle_auth, "IU", SCTPCTL_AUTH_ENABLE_DESC);
86695e55080SMichael Tuexen SYSCTL_PROC(_net_inet_sctp, OID_AUTO, asconf_enable, CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW,
867f47f328dSMichael Tuexen     NULL, 0, sctp_sysctl_handle_asconf, "IU", SCTPCTL_ASCONF_ENABLE_DESC);
868f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(reconfig_enable, sctp_reconfig_enable, SCTPCTL_RECONFIG_ENABLE)
869f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(nrsack_enable, sctp_nrsack_enable, SCTPCTL_NRSACK_ENABLE)
870f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(pktdrop_enable, sctp_pktdrop_enable, SCTPCTL_PKTDROP_ENABLE)
871f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(peer_chkoh, sctp_peer_chunk_oh, SCTPCTL_PEER_CHKOH)
872f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(maxburst, sctp_max_burst_default, SCTPCTL_MAXBURST)
873f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(fr_maxburst, sctp_fr_max_burst_default, SCTPCTL_FRMAXBURST)
874f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(maxchunks, sctp_max_chunks_on_queue, SCTPCTL_MAXCHUNKS)
875f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(tcbhashsize, sctp_hashtblsize, SCTPCTL_TCBHASHSIZE)
876f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(pcbhashsize, sctp_pcbtblsize, SCTPCTL_PCBHASHSIZE)
877f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(min_split_point, sctp_min_split_point, SCTPCTL_MIN_SPLIT_POINT)
878f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(chunkscale, sctp_chunkscale, SCTPCTL_CHUNKSCALE)
879f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(delayed_sack_time, sctp_delayed_sack_time_default, SCTPCTL_DELAYED_SACK_TIME)
880f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(sack_freq, sctp_sack_freq_default, SCTPCTL_SACK_FREQ)
881f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(sys_resource, sctp_system_free_resc_limit, SCTPCTL_SYS_RESOURCE)
882f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(asoc_resource, sctp_asoc_free_resc_limit, SCTPCTL_ASOC_RESOURCE)
883f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(heartbeat_interval, sctp_heartbeat_interval_default, SCTPCTL_HEARTBEAT_INTERVAL)
884f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(pmtu_raise_time, sctp_pmtu_raise_time_default, SCTPCTL_PMTU_RAISE_TIME)
885f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(shutdown_guard_time, sctp_shutdown_guard_time_default, SCTPCTL_SHUTDOWN_GUARD_TIME)
886f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(secret_lifetime, sctp_secret_lifetime_default, SCTPCTL_SECRET_LIFETIME)
887f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(rto_max, sctp_rto_max_default, SCTPCTL_RTO_MAX)
888f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(rto_min, sctp_rto_min_default, SCTPCTL_RTO_MIN)
889f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(rto_initial, sctp_rto_initial_default, SCTPCTL_RTO_INITIAL)
890f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(init_rto_max, sctp_init_rto_max_default, SCTPCTL_INIT_RTO_MAX)
891f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(valid_cookie_life, sctp_valid_cookie_life_default, SCTPCTL_VALID_COOKIE_LIFE)
892f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(init_rtx_max, sctp_init_rtx_max_default, SCTPCTL_INIT_RTX_MAX)
893f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(assoc_rtx_max, sctp_assoc_rtx_max_default, SCTPCTL_ASSOC_RTX_MAX)
894f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(path_rtx_max, sctp_path_rtx_max_default, SCTPCTL_PATH_RTX_MAX)
895f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(path_pf_threshold, sctp_path_pf_threshold, SCTPCTL_PATH_PF_THRESHOLD)
896f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(add_more_on_output, sctp_add_more_threshold, SCTPCTL_ADD_MORE_ON_OUTPUT)
897f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(incoming_streams, sctp_nr_incoming_streams_default, SCTPCTL_INCOMING_STREAMS)
898f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(outgoing_streams, sctp_nr_outgoing_streams_default, SCTPCTL_OUTGOING_STREAMS)
899f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(cmt_on_off, sctp_cmt_on_off, SCTPCTL_CMT_ON_OFF)
900f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(cmt_use_dac, sctp_cmt_use_dac, SCTPCTL_CMT_USE_DAC)
901f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(cwnd_maxburst, sctp_use_cwnd_based_maxburst, SCTPCTL_CWND_MAXBURST)
902f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(nat_friendly, sctp_nat_friendly, SCTPCTL_NAT_FRIENDLY)
903f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(abc_l_var, sctp_L2_abc_variable, SCTPCTL_ABC_L_VAR)
904f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(max_chained_mbufs, sctp_mbuf_threshold_count, SCTPCTL_MAX_CHAINED_MBUFS)
905f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(do_sctp_drain, sctp_do_drain, SCTPCTL_DO_SCTP_DRAIN)
906f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(hb_max_burst, sctp_hb_maxburst, SCTPCTL_HB_MAX_BURST)
907f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(abort_at_limit, sctp_abort_if_one_2_one_hits_limit, SCTPCTL_ABORT_AT_LIMIT)
908f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(min_residual, sctp_min_residual, SCTPCTL_MIN_RESIDUAL)
909f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(max_retran_chunk, sctp_max_retran_chunk, SCTPCTL_MAX_RETRAN_CHUNK)
910f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(log_level, sctp_logging_level, SCTPCTL_LOGGING_LEVEL)
911f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(default_cc_module, sctp_default_cc_module, SCTPCTL_DEFAULT_CC_MODULE)
912f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(default_ss_module, sctp_default_ss_module, SCTPCTL_DEFAULT_SS_MODULE)
913f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(default_frag_interleave, sctp_default_frag_interleave, SCTPCTL_DEFAULT_FRAG_INTERLEAVE)
914f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(mobility_base, sctp_mobility_base, SCTPCTL_MOBILITY_BASE)
915f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(mobility_fasthandoff, sctp_mobility_fasthandoff, SCTPCTL_MOBILITY_FASTHANDOFF)
916b27a6b7dSRandall Stewart #if defined(SCTP_LOCAL_TRACE_BUF)
91795e55080SMichael Tuexen SYSCTL_PROC(_net_inet_sctp, OID_AUTO, log, CTLFLAG_VNET | CTLTYPE_STRUCT | CTLFLAG_RD,
918f47f328dSMichael Tuexen     NULL, 0, sctp_sysctl_handle_trace_log, "S,sctplog", "SCTP logging (struct sctp_log)");
91995e55080SMichael Tuexen SYSCTL_PROC(_net_inet_sctp, OID_AUTO, clear_trace, CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW,
920f47f328dSMichael Tuexen     NULL, 0, sctp_sysctl_handle_trace_log_clear, "IU", "Clear SCTP Logging buffer");
921b27a6b7dSRandall Stewart #endif
92295e55080SMichael Tuexen SYSCTL_PROC(_net_inet_sctp, OID_AUTO, udp_tunneling_port, CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW,
923f47f328dSMichael Tuexen     NULL, 0, sctp_sysctl_handle_udp_tunneling, "IU", SCTPCTL_UDP_TUNNELING_PORT_DESC);
924f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(enable_sack_immediately, sctp_enable_sack_immediately, SCTPCTL_SACK_IMMEDIATELY_ENABLE)
925f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(nat_friendly_init, sctp_inits_include_nat_friendly, SCTPCTL_NAT_FRIENDLY_INITS)
926f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(vtag_time_wait, sctp_vtag_time_wait, SCTPCTL_TIME_WAIT)
927f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(buffer_splitting, sctp_buffer_splitting, SCTPCTL_BUFFER_SPLITTING)
928f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(initial_cwnd, sctp_initial_cwnd, SCTPCTL_INITIAL_CWND)
929f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(rttvar_bw, sctp_rttvar_bw, SCTPCTL_RTTVAR_BW)
930f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(rttvar_rtt, sctp_rttvar_rtt, SCTPCTL_RTTVAR_RTT)
931f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(rttvar_eqret, sctp_rttvar_eqret, SCTPCTL_RTTVAR_EQRET)
932f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(rttvar_steady_step, sctp_steady_step, SCTPCTL_RTTVAR_STEADYS)
933f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(use_dcccecn, sctp_use_dccc_ecn, SCTPCTL_RTTVAR_DCCCECN)
934f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(blackhole, sctp_blackhole, SCTPCTL_BLACKHOLE)
935f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(diag_info_code, sctp_diag_info_code, SCTPCTL_DIAG_INFO_CODE)
936851b7298SRandall Stewart #ifdef SCTP_DEBUG
937f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(debug, sctp_debug_on, SCTPCTL_DEBUG)
938f0878bdcSMichael Tuexen #endif
939b3f1ea41SRandall Stewart #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
940f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(output_unlocked, sctp_output_unlocked, SCTPCTL_OUTPUT_UNLOCKED)
941b3f1ea41SRandall Stewart #endif
94295e55080SMichael Tuexen SYSCTL_PROC(_net_inet_sctp, OID_AUTO, stats, CTLFLAG_VNET | CTLTYPE_STRUCT | CTLFLAG_RW,
943f47f328dSMichael Tuexen     NULL, 0, sctp_sysctl_handle_stats, "S,sctpstat", "SCTP statistics (struct sctp_stat)");
94495e55080SMichael Tuexen SYSCTL_PROC(_net_inet_sctp, OID_AUTO, assoclist, CTLFLAG_VNET | CTLTYPE_OPAQUE | CTLFLAG_RD,
945f47f328dSMichael Tuexen     NULL, 0, sctp_sysctl_handle_assoclist, "S,xassoc", "List of active SCTP associations");
946