xref: /freebsd/sys/netinet/sctp_sysctl.c (revision f47f328dc54c5709a53db7f1f066fa94141dbb86)
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_strict_sacks) = SCTPCTL_STRICT_SACKS_DEFAULT;
67b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_peer_chunk_oh) = SCTPCTL_PEER_CHKOH_DEFAULT;
68b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_max_burst_default) = SCTPCTL_MAXBURST_DEFAULT;
69899288aeSRandall Stewart 	SCTP_BASE_SYSCTL(sctp_fr_max_burst_default) = SCTPCTL_FRMAXBURST_DEFAULT;
70b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = SCTPCTL_MAXCHUNKS_DEFAULT;
71b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_hashtblsize) = SCTPCTL_TCBHASHSIZE_DEFAULT;
72b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_pcbtblsize) = SCTPCTL_PCBHASHSIZE_DEFAULT;
73b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_min_split_point) = SCTPCTL_MIN_SPLIT_POINT_DEFAULT;
74b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_chunkscale) = SCTPCTL_CHUNKSCALE_DEFAULT;
75b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_delayed_sack_time_default) = SCTPCTL_DELAYED_SACK_TIME_DEFAULT;
76b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_sack_freq_default) = SCTPCTL_SACK_FREQ_DEFAULT;
77b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_system_free_resc_limit) = SCTPCTL_SYS_RESOURCE_DEFAULT;
78b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_asoc_free_resc_limit) = SCTPCTL_ASOC_RESOURCE_DEFAULT;
79b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_heartbeat_interval_default) = SCTPCTL_HEARTBEAT_INTERVAL_DEFAULT;
80b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_pmtu_raise_time_default) = SCTPCTL_PMTU_RAISE_TIME_DEFAULT;
81b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_shutdown_guard_time_default) = SCTPCTL_SHUTDOWN_GUARD_TIME_DEFAULT;
82b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_secret_lifetime_default) = SCTPCTL_SECRET_LIFETIME_DEFAULT;
83b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_rto_max_default) = SCTPCTL_RTO_MAX_DEFAULT;
84b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_rto_min_default) = SCTPCTL_RTO_MIN_DEFAULT;
85b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_rto_initial_default) = SCTPCTL_RTO_INITIAL_DEFAULT;
86b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_init_rto_max_default) = SCTPCTL_INIT_RTO_MAX_DEFAULT;
87b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_valid_cookie_life_default) = SCTPCTL_VALID_COOKIE_LIFE_DEFAULT;
88b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_init_rtx_max_default) = SCTPCTL_INIT_RTX_MAX_DEFAULT;
89b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_assoc_rtx_max_default) = SCTPCTL_ASSOC_RTX_MAX_DEFAULT;
90b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_path_rtx_max_default) = SCTPCTL_PATH_RTX_MAX_DEFAULT;
91ca85e948SMichael Tuexen 	SCTP_BASE_SYSCTL(sctp_path_pf_threshold) = SCTPCTL_PATH_PF_THRESHOLD_DEFAULT;
92b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_add_more_threshold) = SCTPCTL_ADD_MORE_ON_OUTPUT_DEFAULT;
93ee1ccd92SMichael Tuexen 	SCTP_BASE_SYSCTL(sctp_nr_incoming_streams_default) = SCTPCTL_INCOMING_STREAMS_DEFAULT;
94b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_nr_outgoing_streams_default) = SCTPCTL_OUTGOING_STREAMS_DEFAULT;
95b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_cmt_on_off) = SCTPCTL_CMT_ON_OFF_DEFAULT;
96b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_cmt_use_dac) = SCTPCTL_CMT_USE_DAC_DEFAULT;
97b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_use_cwnd_based_maxburst) = SCTPCTL_CWND_MAXBURST_DEFAULT;
98b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_nat_friendly) = SCTPCTL_NAT_FRIENDLY_DEFAULT;
99b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_L2_abc_variable) = SCTPCTL_ABC_L_VAR_DEFAULT;
100b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_mbuf_threshold_count) = SCTPCTL_MAX_CHAINED_MBUFS_DEFAULT;
101b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_do_drain) = SCTPCTL_DO_SCTP_DRAIN_DEFAULT;
102b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_hb_maxburst) = SCTPCTL_HB_MAX_BURST_DEFAULT;
103b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_abort_if_one_2_one_hits_limit) = SCTPCTL_ABORT_AT_LIMIT_DEFAULT;
104b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_strict_data_order) = SCTPCTL_STRICT_DATA_ORDER_DEFAULT;
105b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_min_residual) = SCTPCTL_MIN_RESIDUAL_DEFAULT;
106b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_max_retran_chunk) = SCTPCTL_MAX_RETRAN_CHUNK_DEFAULT;
107b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_logging_level) = SCTPCTL_LOGGING_LEVEL_DEFAULT;
108b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_default_cc_module) = SCTPCTL_DEFAULT_CC_MODULE_DEFAULT;
109f7a77f6fSMichael Tuexen 	SCTP_BASE_SYSCTL(sctp_default_ss_module) = SCTPCTL_DEFAULT_SS_MODULE_DEFAULT;
110b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_default_frag_interleave) = SCTPCTL_DEFAULT_FRAG_INTERLEAVE_DEFAULT;
111b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_mobility_base) = SCTPCTL_MOBILITY_BASE_DEFAULT;
112b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_mobility_fasthandoff) = SCTPCTL_MOBILITY_FASTHANDOFF_DEFAULT;
113a16ccdceSRandall Stewart 	SCTP_BASE_SYSCTL(sctp_vtag_time_wait) = SCTPCTL_TIME_WAIT_DEFAULT;
11425a2a187SMichael Tuexen 	SCTP_BASE_SYSCTL(sctp_buffer_splitting) = SCTPCTL_BUFFER_SPLITTING_DEFAULT;
115dcfc0625SMichael Tuexen 	SCTP_BASE_SYSCTL(sctp_initial_cwnd) = SCTPCTL_INITIAL_CWND_DEFAULT;
116299108c5SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_rttvar_bw) = SCTPCTL_RTTVAR_BW_DEFAULT;
117299108c5SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_rttvar_rtt) = SCTPCTL_RTTVAR_RTT_DEFAULT;
118299108c5SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_rttvar_eqret) = SCTPCTL_RTTVAR_EQRET_DEFAULT;
119f79aab18SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_steady_step) = SCTPCTL_RTTVAR_STEADYS_DEFAULT;
120f79aab18SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_use_dccc_ecn) = SCTPCTL_RTTVAR_DCCCECN_DEFAULT;
121c58e60beSMichael Tuexen 	SCTP_BASE_SYSCTL(sctp_blackhole) = SCTPCTL_BLACKHOLE_DEFAULT;
122ff1ffd74SMichael Tuexen 	SCTP_BASE_SYSCTL(sctp_diag_info_code) = SCTPCTL_DIAG_INFO_CODE_DEFAULT;
123b27a6b7dSRandall Stewart #if defined(SCTP_LOCAL_TRACE_BUF)
124b3f1ea41SRandall Stewart 	memset(&SCTP_BASE_SYSCTL(sctp_log), 0, sizeof(struct sctp_log));
125b27a6b7dSRandall Stewart #endif
126b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_udp_tunneling_port) = SCTPCTL_UDP_TUNNELING_PORT_DEFAULT;
127b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_enable_sack_immediately) = SCTPCTL_SACK_IMMEDIATELY_ENABLE_DEFAULT;
128bf3d5177SMichael Tuexen 	SCTP_BASE_SYSCTL(sctp_inits_include_nat_friendly) = SCTPCTL_NAT_FRIENDLY_INITS_DEFAULT;
129b3f1ea41SRandall Stewart #if defined(SCTP_DEBUG)
130b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_debug_on) = SCTPCTL_DEBUG_DEFAULT;
13142551e99SRandall Stewart #endif
132b3f1ea41SRandall Stewart #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
133b3f1ea41SRandall Stewart 	SCTP_BASE_SYSCTL(sctp_output_unlocked) = SCTPCTL_OUTPUT_UNLOCKED_DEFAULT;
134b3f1ea41SRandall Stewart #endif
135b3f1ea41SRandall Stewart }
136d61a0ae0SRandall Stewart 
137a99b6783SRandall Stewart 
138d61a0ae0SRandall Stewart /* It returns an upper limit. No filtering is done here */
139d61a0ae0SRandall Stewart static unsigned int
140*f47f328dSMichael Tuexen sctp_sysctl_number_of_addresses(struct sctp_inpcb *inp)
141d61a0ae0SRandall Stewart {
1427215cc1bSMichael Tuexen 	unsigned int cnt;
143d61a0ae0SRandall Stewart 	struct sctp_vrf *vrf;
144d61a0ae0SRandall Stewart 	struct sctp_ifn *sctp_ifn;
145d61a0ae0SRandall Stewart 	struct sctp_ifa *sctp_ifa;
146d61a0ae0SRandall Stewart 	struct sctp_laddr *laddr;
147d61a0ae0SRandall Stewart 
148d61a0ae0SRandall Stewart 	cnt = 0;
149d61a0ae0SRandall Stewart 	/* neither Mac OS X nor FreeBSD support mulitple routing functions */
150d61a0ae0SRandall Stewart 	if ((vrf = sctp_find_vrf(inp->def_vrf_id)) == NULL) {
151d61a0ae0SRandall Stewart 		return (0);
152d61a0ae0SRandall Stewart 	}
153d61a0ae0SRandall Stewart 	if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
154d61a0ae0SRandall Stewart 		LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
155d61a0ae0SRandall Stewart 			LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
156e6194c2eSMichael Tuexen 				switch (sctp_ifa->address.sa.sa_family) {
157e6194c2eSMichael Tuexen #ifdef INET
158e6194c2eSMichael Tuexen 				case AF_INET:
159e6194c2eSMichael Tuexen #endif
160e6194c2eSMichael Tuexen #ifdef INET6
161e6194c2eSMichael Tuexen 				case AF_INET6:
162e6194c2eSMichael Tuexen #endif
163d61a0ae0SRandall Stewart 					cnt++;
164e6194c2eSMichael Tuexen 					break;
165e6194c2eSMichael Tuexen 				default:
166e6194c2eSMichael Tuexen 					break;
167d61a0ae0SRandall Stewart 				}
168d61a0ae0SRandall Stewart 			}
169d61a0ae0SRandall Stewart 		}
170d61a0ae0SRandall Stewart 	} else {
171d61a0ae0SRandall Stewart 		LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
172e6194c2eSMichael Tuexen 			switch (laddr->ifa->address.sa.sa_family) {
173e6194c2eSMichael Tuexen #ifdef INET
174e6194c2eSMichael Tuexen 			case AF_INET:
175e6194c2eSMichael Tuexen #endif
176e6194c2eSMichael Tuexen #ifdef INET6
177e6194c2eSMichael Tuexen 			case AF_INET6:
178e6194c2eSMichael Tuexen #endif
179d61a0ae0SRandall Stewart 				cnt++;
180e6194c2eSMichael Tuexen 				break;
181e6194c2eSMichael Tuexen 			default:
182e6194c2eSMichael Tuexen 				break;
183d61a0ae0SRandall Stewart 			}
184d61a0ae0SRandall Stewart 		}
185d61a0ae0SRandall Stewart 	}
186d61a0ae0SRandall Stewart 	return (cnt);
187d61a0ae0SRandall Stewart }
188d61a0ae0SRandall Stewart 
189d61a0ae0SRandall Stewart static int
190*f47f328dSMichael Tuexen sctp_sysctl_copy_out_local_addresses(struct sctp_inpcb *inp, struct sctp_tcb *stcb, struct sysctl_req *req)
191d61a0ae0SRandall Stewart {
192d61a0ae0SRandall Stewart 	struct sctp_ifn *sctp_ifn;
193d61a0ae0SRandall Stewart 	struct sctp_ifa *sctp_ifa;
194d61a0ae0SRandall Stewart 	int loopback_scope, ipv4_local_scope, local_scope, site_scope;
195d61a0ae0SRandall Stewart 	int ipv4_addr_legal, ipv6_addr_legal;
196d61a0ae0SRandall Stewart 	struct sctp_vrf *vrf;
197d61a0ae0SRandall Stewart 	struct xsctp_laddr xladdr;
198d61a0ae0SRandall Stewart 	struct sctp_laddr *laddr;
199d61a0ae0SRandall Stewart 	int error;
200d61a0ae0SRandall Stewart 
201d61a0ae0SRandall Stewart 	/* Turn on all the appropriate scope */
202d61a0ae0SRandall Stewart 	if (stcb) {
203d61a0ae0SRandall Stewart 		/* use association specific values */
204a1cb341bSMichael Tuexen 		loopback_scope = stcb->asoc.scope.loopback_scope;
205a1cb341bSMichael Tuexen 		ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
206a1cb341bSMichael Tuexen 		local_scope = stcb->asoc.scope.local_scope;
207a1cb341bSMichael Tuexen 		site_scope = stcb->asoc.scope.site_scope;
208a1cb341bSMichael Tuexen 		ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
209a1cb341bSMichael Tuexen 		ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
210d61a0ae0SRandall Stewart 	} else {
211a1cb341bSMichael Tuexen 		/* Use generic values for endpoints. */
212d61a0ae0SRandall Stewart 		loopback_scope = 1;
213d61a0ae0SRandall Stewart 		ipv4_local_scope = 1;
214d61a0ae0SRandall Stewart 		local_scope = 1;
215d61a0ae0SRandall Stewart 		site_scope = 1;
216d61a0ae0SRandall Stewart 		if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
217d61a0ae0SRandall Stewart 			ipv6_addr_legal = 1;
218d61a0ae0SRandall Stewart 			if (SCTP_IPV6_V6ONLY(inp)) {
219d61a0ae0SRandall Stewart 				ipv4_addr_legal = 0;
220d61a0ae0SRandall Stewart 			} else {
221d61a0ae0SRandall Stewart 				ipv4_addr_legal = 1;
222d61a0ae0SRandall Stewart 			}
223d61a0ae0SRandall Stewart 		} else {
224d61a0ae0SRandall Stewart 			ipv6_addr_legal = 0;
225a1cb341bSMichael Tuexen 			ipv4_addr_legal = 1;
226a1cb341bSMichael Tuexen 		}
227d61a0ae0SRandall Stewart 	}
228d61a0ae0SRandall Stewart 
229d61a0ae0SRandall Stewart 	/* neither Mac OS X nor FreeBSD support mulitple routing functions */
230d61a0ae0SRandall Stewart 	if ((vrf = sctp_find_vrf(inp->def_vrf_id)) == NULL) {
2315f26a41dSRandall Stewart 		SCTP_INP_RUNLOCK(inp);
2325f26a41dSRandall Stewart 		SCTP_INP_INFO_RUNLOCK();
233d61a0ae0SRandall Stewart 		return (-1);
234d61a0ae0SRandall Stewart 	}
235d61a0ae0SRandall Stewart 	if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
236d61a0ae0SRandall Stewart 		LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
237d61a0ae0SRandall Stewart 			if ((loopback_scope == 0) && SCTP_IFN_IS_IFT_LOOP(sctp_ifn))
238d61a0ae0SRandall Stewart 				/* Skip loopback if loopback_scope not set */
239d61a0ae0SRandall Stewart 				continue;
240d61a0ae0SRandall Stewart 			LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
241d61a0ae0SRandall Stewart 				if (stcb) {
242d61a0ae0SRandall Stewart 					/*
243d61a0ae0SRandall Stewart 					 * ignore if blacklisted at
244d61a0ae0SRandall Stewart 					 * association level
245d61a0ae0SRandall Stewart 					 */
246d61a0ae0SRandall Stewart 					if (sctp_is_addr_restricted(stcb, sctp_ifa))
247d61a0ae0SRandall Stewart 						continue;
248d61a0ae0SRandall Stewart 				}
2495e2c2d87SRandall Stewart 				switch (sctp_ifa->address.sa.sa_family) {
250e6194c2eSMichael Tuexen #ifdef INET
2515e2c2d87SRandall Stewart 				case AF_INET:
2525e2c2d87SRandall Stewart 					if (ipv4_addr_legal) {
253d61a0ae0SRandall Stewart 						struct sockaddr_in *sin;
254d61a0ae0SRandall Stewart 
255d61a0ae0SRandall Stewart 						sin = (struct sockaddr_in *)&sctp_ifa->address.sa;
256d61a0ae0SRandall Stewart 						if (sin->sin_addr.s_addr == 0)
257d61a0ae0SRandall Stewart 							continue;
2586ba22f19SMichael Tuexen 						if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
2596ba22f19SMichael Tuexen 						    &sin->sin_addr) != 0) {
2606ba22f19SMichael Tuexen 							continue;
2616ba22f19SMichael Tuexen 						}
262d61a0ae0SRandall Stewart 						if ((ipv4_local_scope == 0) && (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)))
263d61a0ae0SRandall Stewart 							continue;
2645e2c2d87SRandall Stewart 					} else {
2655e2c2d87SRandall Stewart 						continue;
2665e2c2d87SRandall Stewart 					}
2675e2c2d87SRandall Stewart 					break;
268e6194c2eSMichael Tuexen #endif
2695e2c2d87SRandall Stewart #ifdef INET6
2705e2c2d87SRandall Stewart 				case AF_INET6:
2715e2c2d87SRandall Stewart 					if (ipv6_addr_legal) {
272d61a0ae0SRandall Stewart 						struct sockaddr_in6 *sin6;
273d61a0ae0SRandall Stewart 
274d61a0ae0SRandall Stewart 						sin6 = (struct sockaddr_in6 *)&sctp_ifa->address.sa;
275d61a0ae0SRandall Stewart 						if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
276d61a0ae0SRandall Stewart 							continue;
2776ba22f19SMichael Tuexen 						if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
2786ba22f19SMichael Tuexen 						    &sin6->sin6_addr) != 0) {
2796ba22f19SMichael Tuexen 							continue;
2806ba22f19SMichael Tuexen 						}
281d61a0ae0SRandall Stewart 						if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
282d61a0ae0SRandall Stewart 							if (local_scope == 0)
283d61a0ae0SRandall Stewart 								continue;
284d61a0ae0SRandall Stewart 							if (sin6->sin6_scope_id == 0) {
285d61a0ae0SRandall Stewart 								/*
2865e2c2d87SRandall Stewart 								 * bad link
2875e2c2d87SRandall Stewart 								 * local
288d61a0ae0SRandall Stewart 								 * address
289d61a0ae0SRandall Stewart 								 */
290d61a0ae0SRandall Stewart 								if (sa6_recoverscope(sin6) != 0)
291d61a0ae0SRandall Stewart 									continue;
292d61a0ae0SRandall Stewart 							}
293d61a0ae0SRandall Stewart 						}
294d61a0ae0SRandall Stewart 						if ((site_scope == 0) && (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)))
295d61a0ae0SRandall Stewart 							continue;
2965e2c2d87SRandall Stewart 					} else {
297d61a0ae0SRandall Stewart 						continue;
2985e2c2d87SRandall Stewart 					}
2995e2c2d87SRandall Stewart 					break;
3005e2c2d87SRandall Stewart #endif
3015e2c2d87SRandall Stewart 				default:
3025e2c2d87SRandall Stewart 					continue;
3035e2c2d87SRandall Stewart 				}
304851b7298SRandall Stewart 				memset((void *)&xladdr, 0, sizeof(struct xsctp_laddr));
305d61a0ae0SRandall Stewart 				memcpy((void *)&xladdr.address, (const void *)&sctp_ifa->address, sizeof(union sctp_sockstore));
306d61a0ae0SRandall Stewart 				SCTP_INP_RUNLOCK(inp);
307d61a0ae0SRandall Stewart 				SCTP_INP_INFO_RUNLOCK();
308d61a0ae0SRandall Stewart 				error = SYSCTL_OUT(req, &xladdr, sizeof(struct xsctp_laddr));
309851b7298SRandall Stewart 				if (error) {
310d61a0ae0SRandall Stewart 					return (error);
311851b7298SRandall Stewart 				} else {
312d61a0ae0SRandall Stewart 					SCTP_INP_INFO_RLOCK();
313d61a0ae0SRandall Stewart 					SCTP_INP_RLOCK(inp);
314d61a0ae0SRandall Stewart 				}
315d61a0ae0SRandall Stewart 			}
316d61a0ae0SRandall Stewart 		}
317d61a0ae0SRandall Stewart 	} else {
318d61a0ae0SRandall Stewart 		LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
319d61a0ae0SRandall Stewart 			/* ignore if blacklisted at association level */
320d61a0ae0SRandall Stewart 			if (stcb && sctp_is_addr_restricted(stcb, laddr->ifa))
321d61a0ae0SRandall Stewart 				continue;
322851b7298SRandall Stewart 			memset((void *)&xladdr, 0, sizeof(struct xsctp_laddr));
323d61a0ae0SRandall Stewart 			memcpy((void *)&xladdr.address, (const void *)&laddr->ifa->address, sizeof(union sctp_sockstore));
324851b7298SRandall Stewart 			xladdr.start_time.tv_sec = (uint32_t) laddr->start_time.tv_sec;
325851b7298SRandall Stewart 			xladdr.start_time.tv_usec = (uint32_t) laddr->start_time.tv_usec;
326d61a0ae0SRandall Stewart 			SCTP_INP_RUNLOCK(inp);
327d61a0ae0SRandall Stewart 			SCTP_INP_INFO_RUNLOCK();
328d61a0ae0SRandall Stewart 			error = SYSCTL_OUT(req, &xladdr, sizeof(struct xsctp_laddr));
329851b7298SRandall Stewart 			if (error) {
330d61a0ae0SRandall Stewart 				return (error);
331851b7298SRandall Stewart 			} else {
332d61a0ae0SRandall Stewart 				SCTP_INP_INFO_RLOCK();
333d61a0ae0SRandall Stewart 				SCTP_INP_RLOCK(inp);
334d61a0ae0SRandall Stewart 			}
335d61a0ae0SRandall Stewart 		}
336d61a0ae0SRandall Stewart 	}
337851b7298SRandall Stewart 	memset((void *)&xladdr, 0, sizeof(struct xsctp_laddr));
338d61a0ae0SRandall Stewart 	xladdr.last = 1;
3395f26a41dSRandall Stewart 	SCTP_INP_RUNLOCK(inp);
3405f26a41dSRandall Stewart 	SCTP_INP_INFO_RUNLOCK();
341d61a0ae0SRandall Stewart 	error = SYSCTL_OUT(req, &xladdr, sizeof(struct xsctp_laddr));
3425f26a41dSRandall Stewart 
343851b7298SRandall Stewart 	if (error) {
344d61a0ae0SRandall Stewart 		return (error);
345851b7298SRandall Stewart 	} else {
3465f26a41dSRandall Stewart 		SCTP_INP_INFO_RLOCK();
3475f26a41dSRandall Stewart 		SCTP_INP_RLOCK(inp);
348d61a0ae0SRandall Stewart 		return (0);
349d61a0ae0SRandall Stewart 	}
3505f26a41dSRandall Stewart }
351d61a0ae0SRandall Stewart 
35242551e99SRandall Stewart /*
35342551e99SRandall Stewart  * sysctl functions
35442551e99SRandall Stewart  */
35542551e99SRandall Stewart static int
356*f47f328dSMichael Tuexen sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS)
35742551e99SRandall Stewart {
35842551e99SRandall Stewart 	unsigned int number_of_endpoints;
35942551e99SRandall Stewart 	unsigned int number_of_local_addresses;
36042551e99SRandall Stewart 	unsigned int number_of_associations;
36142551e99SRandall Stewart 	unsigned int number_of_remote_addresses;
36242551e99SRandall Stewart 	unsigned int n;
36342551e99SRandall Stewart 	int error;
36442551e99SRandall Stewart 	struct sctp_inpcb *inp;
36542551e99SRandall Stewart 	struct sctp_tcb *stcb;
36642551e99SRandall Stewart 	struct sctp_nets *net;
36742551e99SRandall Stewart 	struct xsctp_inpcb xinpcb;
36842551e99SRandall Stewart 	struct xsctp_tcb xstcb;
36942551e99SRandall Stewart 	struct xsctp_raddr xraddr;
3708ce4a9a2SRandall Stewart 	struct socket *so;
37142551e99SRandall Stewart 
37242551e99SRandall Stewart 	number_of_endpoints = 0;
37342551e99SRandall Stewart 	number_of_local_addresses = 0;
37442551e99SRandall Stewart 	number_of_associations = 0;
37542551e99SRandall Stewart 	number_of_remote_addresses = 0;
37642551e99SRandall Stewart 
37742551e99SRandall Stewart 	SCTP_INP_INFO_RLOCK();
378*f47f328dSMichael Tuexen 	if (req->oldptr == NULL) {
379b3f1ea41SRandall Stewart 		LIST_FOREACH(inp, &SCTP_BASE_INFO(listhead), sctp_list) {
38042551e99SRandall Stewart 			SCTP_INP_RLOCK(inp);
38142551e99SRandall Stewart 			number_of_endpoints++;
382*f47f328dSMichael Tuexen 			number_of_local_addresses += sctp_sysctl_number_of_addresses(inp);
38342551e99SRandall Stewart 			LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
38442551e99SRandall Stewart 				number_of_associations++;
385*f47f328dSMichael Tuexen 				number_of_local_addresses += sctp_sysctl_number_of_addresses(inp);
38642551e99SRandall Stewart 				TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
38742551e99SRandall Stewart 					number_of_remote_addresses++;
38842551e99SRandall Stewart 				}
38942551e99SRandall Stewart 			}
39042551e99SRandall Stewart 			SCTP_INP_RUNLOCK(inp);
39142551e99SRandall Stewart 		}
39242551e99SRandall Stewart 		SCTP_INP_INFO_RUNLOCK();
39342551e99SRandall Stewart 		n = (number_of_endpoints + 1) * sizeof(struct xsctp_inpcb) +
394d61a0ae0SRandall Stewart 		    (number_of_local_addresses + number_of_endpoints + number_of_associations) * sizeof(struct xsctp_laddr) +
395d61a0ae0SRandall Stewart 		    (number_of_associations + number_of_endpoints) * sizeof(struct xsctp_tcb) +
396d61a0ae0SRandall Stewart 		    (number_of_remote_addresses + number_of_associations) * sizeof(struct xsctp_raddr);
397d61a0ae0SRandall Stewart 
39842551e99SRandall Stewart 		/* request some more memory than needed */
39942551e99SRandall Stewart 		req->oldidx = (n + n / 8);
40060990c0cSMichael Tuexen 		return (0);
40142551e99SRandall Stewart 	}
402*f47f328dSMichael Tuexen 	if (req->newptr != NULL) {
40342551e99SRandall Stewart 		SCTP_INP_INFO_RUNLOCK();
404c4739e2fSRandall Stewart 		SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_SYSCTL, EPERM);
40560990c0cSMichael Tuexen 		return (EPERM);
40642551e99SRandall Stewart 	}
407b3f1ea41SRandall Stewart 	LIST_FOREACH(inp, &SCTP_BASE_INFO(listhead), sctp_list) {
40842551e99SRandall Stewart 		SCTP_INP_RLOCK(inp);
4098ce4a9a2SRandall Stewart 		if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) {
4108ce4a9a2SRandall Stewart 			/* if its allgone it is being freed - skip it  */
4118ce4a9a2SRandall Stewart 			goto skip;
4128ce4a9a2SRandall Stewart 		}
41342551e99SRandall Stewart 		xinpcb.last = 0;
41442551e99SRandall Stewart 		xinpcb.local_port = ntohs(inp->sctp_lport);
41542551e99SRandall Stewart 		xinpcb.flags = inp->sctp_flags;
4166be15a24SMichael Tuexen 		xinpcb.features = inp->sctp_features;
41742551e99SRandall Stewart 		xinpcb.total_sends = inp->total_sends;
41842551e99SRandall Stewart 		xinpcb.total_recvs = inp->total_recvs;
41942551e99SRandall Stewart 		xinpcb.total_nospaces = inp->total_nospaces;
42017205eccSRandall Stewart 		xinpcb.fragmentation_point = inp->sctp_frag_point;
4218ce4a9a2SRandall Stewart 		so = inp->sctp_socket;
4228ce4a9a2SRandall Stewart 		if ((so == NULL) ||
423851b7298SRandall Stewart 		    (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
424851b7298SRandall Stewart 			xinpcb.qlen = 0;
425851b7298SRandall Stewart 			xinpcb.maxqlen = 0;
426851b7298SRandall Stewart 		} else {
4278ce4a9a2SRandall Stewart 			xinpcb.qlen = so->so_qlen;
4288ce4a9a2SRandall Stewart 			xinpcb.maxqlen = so->so_qlimit;
429851b7298SRandall Stewart 		}
43042551e99SRandall Stewart 		SCTP_INP_INCR_REF(inp);
43142551e99SRandall Stewart 		SCTP_INP_RUNLOCK(inp);
43242551e99SRandall Stewart 		SCTP_INP_INFO_RUNLOCK();
43342551e99SRandall Stewart 		error = SYSCTL_OUT(req, &xinpcb, sizeof(struct xsctp_inpcb));
43442551e99SRandall Stewart 		if (error) {
435d61a0ae0SRandall Stewart 			SCTP_INP_DECR_REF(inp);
43660990c0cSMichael Tuexen 			return (error);
43742551e99SRandall Stewart 		}
43842551e99SRandall Stewart 		SCTP_INP_INFO_RLOCK();
43942551e99SRandall Stewart 		SCTP_INP_RLOCK(inp);
440*f47f328dSMichael Tuexen 		error = sctp_sysctl_copy_out_local_addresses(inp, NULL, req);
441d61a0ae0SRandall Stewart 		if (error) {
442d61a0ae0SRandall Stewart 			SCTP_INP_DECR_REF(inp);
44360990c0cSMichael Tuexen 			return (error);
444d61a0ae0SRandall Stewart 		}
44542551e99SRandall Stewart 		LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
44642551e99SRandall Stewart 			SCTP_TCB_LOCK(stcb);
44742551e99SRandall Stewart 			atomic_add_int(&stcb->asoc.refcnt, 1);
44842551e99SRandall Stewart 			SCTP_TCB_UNLOCK(stcb);
449d61a0ae0SRandall Stewart 			xstcb.last = 0;
450d61a0ae0SRandall Stewart 			xstcb.local_port = ntohs(inp->sctp_lport);
451d61a0ae0SRandall Stewart 			xstcb.remote_port = ntohs(stcb->rport);
45242551e99SRandall Stewart 			if (stcb->asoc.primary_destination != NULL)
453d61a0ae0SRandall Stewart 				xstcb.primary_addr = stcb->asoc.primary_destination->ro._l_addr;
454d61a0ae0SRandall Stewart 			xstcb.heartbeat_interval = stcb->asoc.heart_beat_delay;
455d61a0ae0SRandall Stewart 			xstcb.state = SCTP_GET_STATE(&stcb->asoc);	/* FIXME */
4564f6b4933SRandall Stewart 			/* 7.0 does not support these */
457a99b6783SRandall Stewart 			xstcb.assoc_id = sctp_get_associd(stcb);
4584f6b4933SRandall Stewart 			xstcb.peers_rwnd = stcb->asoc.peers_rwnd;
459d61a0ae0SRandall Stewart 			xstcb.in_streams = stcb->asoc.streamincnt;
460d61a0ae0SRandall Stewart 			xstcb.out_streams = stcb->asoc.streamoutcnt;
461d61a0ae0SRandall Stewart 			xstcb.max_nr_retrans = stcb->asoc.overall_error_count;
462d61a0ae0SRandall Stewart 			xstcb.primary_process = 0;	/* not really supported
463d61a0ae0SRandall Stewart 							 * yet */
464d61a0ae0SRandall Stewart 			xstcb.T1_expireries = stcb->asoc.timoinit + stcb->asoc.timocookie;
465d61a0ae0SRandall Stewart 			xstcb.T2_expireries = stcb->asoc.timoshutdown + stcb->asoc.timoshutdownack;
466d61a0ae0SRandall Stewart 			xstcb.retransmitted_tsns = stcb->asoc.marked_retrans;
467851b7298SRandall Stewart 			xstcb.start_time.tv_sec = (uint32_t) stcb->asoc.start_time.tv_sec;
468851b7298SRandall Stewart 			xstcb.start_time.tv_usec = (uint32_t) stcb->asoc.start_time.tv_usec;
469851b7298SRandall Stewart 			xstcb.discontinuity_time.tv_sec = (uint32_t) stcb->asoc.discontinuity_time.tv_sec;
470851b7298SRandall Stewart 			xstcb.discontinuity_time.tv_usec = (uint32_t) stcb->asoc.discontinuity_time.tv_usec;
47142551e99SRandall Stewart 			xstcb.total_sends = stcb->total_sends;
47242551e99SRandall Stewart 			xstcb.total_recvs = stcb->total_recvs;
47342551e99SRandall Stewart 			xstcb.local_tag = stcb->asoc.my_vtag;
47442551e99SRandall Stewart 			xstcb.remote_tag = stcb->asoc.peer_vtag;
47542551e99SRandall Stewart 			xstcb.initial_tsn = stcb->asoc.init_seq_number;
47642551e99SRandall Stewart 			xstcb.highest_tsn = stcb->asoc.sending_seq - 1;
47742551e99SRandall Stewart 			xstcb.cumulative_tsn = stcb->asoc.last_acked_seq;
47842551e99SRandall Stewart 			xstcb.cumulative_tsn_ack = stcb->asoc.cumulative_tsn;
47917205eccSRandall Stewart 			xstcb.mtu = stcb->asoc.smallest_mtu;
480207304d4SRandall Stewart 			xstcb.refcnt = stcb->asoc.refcnt;
48142551e99SRandall Stewart 			SCTP_INP_RUNLOCK(inp);
48242551e99SRandall Stewart 			SCTP_INP_INFO_RUNLOCK();
48342551e99SRandall Stewart 			error = SYSCTL_OUT(req, &xstcb, sizeof(struct xsctp_tcb));
48442551e99SRandall Stewart 			if (error) {
485d61a0ae0SRandall Stewart 				SCTP_INP_DECR_REF(inp);
486851b7298SRandall Stewart 				atomic_subtract_int(&stcb->asoc.refcnt, 1);
48760990c0cSMichael Tuexen 				return (error);
488d61a0ae0SRandall Stewart 			}
489d61a0ae0SRandall Stewart 			SCTP_INP_INFO_RLOCK();
490d61a0ae0SRandall Stewart 			SCTP_INP_RLOCK(inp);
491*f47f328dSMichael Tuexen 			error = sctp_sysctl_copy_out_local_addresses(inp, stcb, req);
492d61a0ae0SRandall Stewart 			if (error) {
493d61a0ae0SRandall Stewart 				SCTP_INP_DECR_REF(inp);
494851b7298SRandall Stewart 				atomic_subtract_int(&stcb->asoc.refcnt, 1);
49560990c0cSMichael Tuexen 				return (error);
49642551e99SRandall Stewart 			}
49742551e99SRandall Stewart 			TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
498d61a0ae0SRandall Stewart 				xraddr.last = 0;
499d61a0ae0SRandall Stewart 				xraddr.address = net->ro._l_addr;
500d61a0ae0SRandall Stewart 				xraddr.active = ((net->dest_state & SCTP_ADDR_REACHABLE) == SCTP_ADDR_REACHABLE);
501d61a0ae0SRandall Stewart 				xraddr.confirmed = ((net->dest_state & SCTP_ADDR_UNCONFIRMED) == 0);
502d61a0ae0SRandall Stewart 				xraddr.heartbeat_enabled = ((net->dest_state & SCTP_ADDR_NOHB) == 0);
503ca85e948SMichael Tuexen 				xraddr.potentially_failed = ((net->dest_state & SCTP_ADDR_PF) == SCTP_ADDR_PF);
504d61a0ae0SRandall Stewart 				xraddr.rto = net->RTO;
505d61a0ae0SRandall Stewart 				xraddr.max_path_rtx = net->failure_threshold;
506d61a0ae0SRandall Stewart 				xraddr.rtx = net->marked_retrans;
507d61a0ae0SRandall Stewart 				xraddr.error_counter = net->error_count;
508d61a0ae0SRandall Stewart 				xraddr.cwnd = net->cwnd;
509d61a0ae0SRandall Stewart 				xraddr.flight_size = net->flight_size;
510d61a0ae0SRandall Stewart 				xraddr.mtu = net->mtu;
511be1d9176SMichael Tuexen 				xraddr.rtt = net->rtt / 1000;
512ca85e948SMichael Tuexen 				xraddr.heartbeat_interval = net->heart_beat_delay;
513851b7298SRandall Stewart 				xraddr.start_time.tv_sec = (uint32_t) net->start_time.tv_sec;
514851b7298SRandall Stewart 				xraddr.start_time.tv_usec = (uint32_t) net->start_time.tv_usec;
515d61a0ae0SRandall Stewart 				SCTP_INP_RUNLOCK(inp);
516d61a0ae0SRandall Stewart 				SCTP_INP_INFO_RUNLOCK();
51742551e99SRandall Stewart 				error = SYSCTL_OUT(req, &xraddr, sizeof(struct xsctp_raddr));
51842551e99SRandall Stewart 				if (error) {
519d61a0ae0SRandall Stewart 					SCTP_INP_DECR_REF(inp);
520851b7298SRandall Stewart 					atomic_subtract_int(&stcb->asoc.refcnt, 1);
52160990c0cSMichael Tuexen 					return (error);
52242551e99SRandall Stewart 				}
52342551e99SRandall Stewart 				SCTP_INP_INFO_RLOCK();
52442551e99SRandall Stewart 				SCTP_INP_RLOCK(inp);
52542551e99SRandall Stewart 			}
526851b7298SRandall Stewart 			atomic_subtract_int(&stcb->asoc.refcnt, 1);
527d61a0ae0SRandall Stewart 			memset((void *)&xraddr, 0, sizeof(struct xsctp_raddr));
528d61a0ae0SRandall Stewart 			xraddr.last = 1;
52942551e99SRandall Stewart 			SCTP_INP_RUNLOCK(inp);
530d61a0ae0SRandall Stewart 			SCTP_INP_INFO_RUNLOCK();
531d61a0ae0SRandall Stewart 			error = SYSCTL_OUT(req, &xraddr, sizeof(struct xsctp_raddr));
532d61a0ae0SRandall Stewart 			if (error) {
533d61a0ae0SRandall Stewart 				SCTP_INP_DECR_REF(inp);
53460990c0cSMichael Tuexen 				return (error);
535d61a0ae0SRandall Stewart 			}
536d61a0ae0SRandall Stewart 			SCTP_INP_INFO_RLOCK();
537d61a0ae0SRandall Stewart 			SCTP_INP_RLOCK(inp);
538d61a0ae0SRandall Stewart 		}
539851b7298SRandall Stewart 		SCTP_INP_DECR_REF(inp);
540d61a0ae0SRandall Stewart 		SCTP_INP_RUNLOCK(inp);
541d61a0ae0SRandall Stewart 		SCTP_INP_INFO_RUNLOCK();
542d61a0ae0SRandall Stewart 		memset((void *)&xstcb, 0, sizeof(struct xsctp_tcb));
543d61a0ae0SRandall Stewart 		xstcb.last = 1;
544d61a0ae0SRandall Stewart 		error = SYSCTL_OUT(req, &xstcb, sizeof(struct xsctp_tcb));
545d61a0ae0SRandall Stewart 		if (error) {
54660990c0cSMichael Tuexen 			return (error);
547d61a0ae0SRandall Stewart 		}
5488ce4a9a2SRandall Stewart skip:
549d61a0ae0SRandall Stewart 		SCTP_INP_INFO_RLOCK();
55042551e99SRandall Stewart 	}
55142551e99SRandall Stewart 	SCTP_INP_INFO_RUNLOCK();
55242551e99SRandall Stewart 
553d61a0ae0SRandall Stewart 	memset((void *)&xinpcb, 0, sizeof(struct xsctp_inpcb));
55442551e99SRandall Stewart 	xinpcb.last = 1;
55542551e99SRandall Stewart 	error = SYSCTL_OUT(req, &xinpcb, sizeof(struct xsctp_inpcb));
55660990c0cSMichael Tuexen 	return (error);
55742551e99SRandall Stewart }
55842551e99SRandall Stewart 
559851b7298SRandall Stewart static int
560*f47f328dSMichael Tuexen sctp_sysctl_handle_udp_tunneling(SYSCTL_HANDLER_ARGS)
561c54a18d2SRandall Stewart {
562c54a18d2SRandall Stewart 	int error;
563*f47f328dSMichael Tuexen 	uint32_t old, new;
564c54a18d2SRandall Stewart 
565be27fdd0SRandall Stewart 	SCTP_INP_INFO_RLOCK();
566*f47f328dSMichael Tuexen 	old = SCTP_BASE_SYSCTL(sctp_udp_tunneling_port);
567be27fdd0SRandall Stewart 	SCTP_INP_INFO_RUNLOCK();
568*f47f328dSMichael Tuexen 	new = old;
569*f47f328dSMichael Tuexen 	error = sysctl_handle_int(oidp, &new, 0, req);
570*f47f328dSMichael Tuexen 	if ((error == 0) &&
571*f47f328dSMichael Tuexen 	    (req->newptr != NULL)) {
572*f47f328dSMichael Tuexen 		if ((new < SCTPCTL_UDP_TUNNELING_PORT_MIN) ||
573*f47f328dSMichael Tuexen 		    (new > SCTPCTL_UDP_TUNNELING_PORT_MAX)) {
574*f47f328dSMichael Tuexen 			error = EINVAL;
575*f47f328dSMichael Tuexen 		} else {
576be27fdd0SRandall Stewart 			SCTP_INP_INFO_WLOCK();
577*f47f328dSMichael Tuexen 			SCTP_BASE_SYSCTL(sctp_udp_tunneling_port) = new;
578*f47f328dSMichael Tuexen 			if (old != 0) {
579c54a18d2SRandall Stewart 				sctp_over_udp_stop();
580c54a18d2SRandall Stewart 			}
581*f47f328dSMichael Tuexen 			if (new != 0) {
582*f47f328dSMichael Tuexen 				error = sctp_over_udp_start();
583c54a18d2SRandall Stewart 			}
584be27fdd0SRandall Stewart 			SCTP_INP_INFO_WUNLOCK();
585c54a18d2SRandall Stewart 		}
586*f47f328dSMichael Tuexen 	}
587c54a18d2SRandall Stewart 	return (error);
588c54a18d2SRandall Stewart }
589c54a18d2SRandall Stewart 
590b3f1ea41SRandall Stewart 
591c54a18d2SRandall Stewart static int
592*f47f328dSMichael Tuexen sctp_sysctl_handle_auth(SYSCTL_HANDLER_ARGS)
593*f47f328dSMichael Tuexen {
594*f47f328dSMichael Tuexen 	int error;
595*f47f328dSMichael Tuexen 	uint32_t new;
596*f47f328dSMichael Tuexen 
597*f47f328dSMichael Tuexen 	new = SCTP_BASE_SYSCTL(sctp_auth_enable);
598*f47f328dSMichael Tuexen 	error = sysctl_handle_int(oidp, &new, 0, req);
599*f47f328dSMichael Tuexen 	if ((error == 0) &&
600*f47f328dSMichael Tuexen 	    (req->newptr != NULL)) {
601*f47f328dSMichael Tuexen 		if ((new < SCTPCTL_AUTH_ENABLE_MIN) ||
602*f47f328dSMichael Tuexen 		    (new > SCTPCTL_AUTH_ENABLE_MAX) ||
603*f47f328dSMichael Tuexen 		    ((new == 0) && (SCTP_BASE_SYSCTL(sctp_asconf_enable) == 1))) {
604*f47f328dSMichael Tuexen 			error = EINVAL;
605*f47f328dSMichael Tuexen 		} else {
606*f47f328dSMichael Tuexen 			SCTP_BASE_SYSCTL(sctp_auth_enable) = new;
607*f47f328dSMichael Tuexen 		}
608*f47f328dSMichael Tuexen 	}
609*f47f328dSMichael Tuexen 	return (error);
610*f47f328dSMichael Tuexen }
611*f47f328dSMichael Tuexen 
612*f47f328dSMichael Tuexen static int
613*f47f328dSMichael Tuexen sctp_sysctl_handle_asconf(SYSCTL_HANDLER_ARGS)
614*f47f328dSMichael Tuexen {
615*f47f328dSMichael Tuexen 	int error;
616*f47f328dSMichael Tuexen 	uint32_t new;
617*f47f328dSMichael Tuexen 
618*f47f328dSMichael Tuexen 	new = SCTP_BASE_SYSCTL(sctp_asconf_enable);
619*f47f328dSMichael Tuexen 	error = sysctl_handle_int(oidp, &new, 0, req);
620*f47f328dSMichael Tuexen 	if ((error == 0) &&
621*f47f328dSMichael Tuexen 	    (req->newptr != NULL)) {
622*f47f328dSMichael Tuexen 		if ((new < SCTPCTL_ASCONF_ENABLE_MIN) ||
623*f47f328dSMichael Tuexen 		    (new > SCTPCTL_ASCONF_ENABLE_MAX) ||
624*f47f328dSMichael Tuexen 		    ((new == 1) && (SCTP_BASE_SYSCTL(sctp_auth_enable) == 0))) {
625*f47f328dSMichael Tuexen 			error = EINVAL;
626*f47f328dSMichael Tuexen 		} else {
627*f47f328dSMichael Tuexen 			SCTP_BASE_SYSCTL(sctp_asconf_enable) = new;
628*f47f328dSMichael Tuexen 		}
629*f47f328dSMichael Tuexen 	}
630*f47f328dSMichael Tuexen 	return (error);
631*f47f328dSMichael Tuexen }
632*f47f328dSMichael Tuexen 
633*f47f328dSMichael Tuexen static int
634*f47f328dSMichael Tuexen sctp_sysctl_handle_stats(SYSCTL_HANDLER_ARGS)
635851b7298SRandall Stewart {
636851b7298SRandall Stewart 	int error;
637851b7298SRandall Stewart 
638*f47f328dSMichael Tuexen #if defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
639*f47f328dSMichael Tuexen 	int cpu;
640*f47f328dSMichael Tuexen 	struct sctpstat sb, *sarry;
641830d754dSRandall Stewart 
642b3f1ea41SRandall Stewart #endif
64342551e99SRandall Stewart 
644*f47f328dSMichael Tuexen 	if ((req->newptr != NULL) &&
645*f47f328dSMichael Tuexen 	    (req->newlen != sizeof(struct sctpstat))) {
646ae26e0a4SRandall Stewart 		return (EINVAL);
647ae26e0a4SRandall Stewart 	}
648*f47f328dSMichael Tuexen #if defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
649*f47f328dSMichael Tuexen 	memset(&sb, 0, sizeof(struct sctpstat));
650dec0177dSRandall Stewart 	for (cpu = 0; cpu < mp_maxid; cpu++) {
651ff014514SRandall Stewart 		sarry = &SCTP_BASE_STATS[cpu];
652ff014514SRandall Stewart 		if (sarry->sctps_discontinuitytime.tv_sec > sb.sctps_discontinuitytime.tv_sec) {
653ff014514SRandall Stewart 			sb.sctps_discontinuitytime.tv_sec = sarry->sctps_discontinuitytime.tv_sec;
654ff014514SRandall Stewart 			sb.sctps_discontinuitytime.tv_usec = sarry->sctps_discontinuitytime.tv_usec;
655ff014514SRandall Stewart 		}
656ff014514SRandall Stewart 		sb.sctps_currestab += sarry->sctps_currestab;
657ff014514SRandall Stewart 		sb.sctps_activeestab += sarry->sctps_activeestab;
658ff014514SRandall Stewart 		sb.sctps_restartestab += sarry->sctps_restartestab;
659ff014514SRandall Stewart 		sb.sctps_collisionestab += sarry->sctps_collisionestab;
660ff014514SRandall Stewart 		sb.sctps_passiveestab += sarry->sctps_passiveestab;
661ff014514SRandall Stewart 		sb.sctps_aborted += sarry->sctps_aborted;
662ff014514SRandall Stewart 		sb.sctps_shutdown += sarry->sctps_shutdown;
663ff014514SRandall Stewart 		sb.sctps_outoftheblue += sarry->sctps_outoftheblue;
664ff014514SRandall Stewart 		sb.sctps_checksumerrors += sarry->sctps_checksumerrors;
665ff014514SRandall Stewart 		sb.sctps_outcontrolchunks += sarry->sctps_outcontrolchunks;
666ff014514SRandall Stewart 		sb.sctps_outorderchunks += sarry->sctps_outorderchunks;
667ff014514SRandall Stewart 		sb.sctps_outunorderchunks += sarry->sctps_outunorderchunks;
668ff014514SRandall Stewart 		sb.sctps_incontrolchunks += sarry->sctps_incontrolchunks;
669ff014514SRandall Stewart 		sb.sctps_inorderchunks += sarry->sctps_inorderchunks;
670ff014514SRandall Stewart 		sb.sctps_inunorderchunks += sarry->sctps_inunorderchunks;
671ff014514SRandall Stewart 		sb.sctps_fragusrmsgs += sarry->sctps_fragusrmsgs;
672ff014514SRandall Stewart 		sb.sctps_reasmusrmsgs += sarry->sctps_reasmusrmsgs;
673ff014514SRandall Stewart 		sb.sctps_outpackets += sarry->sctps_outpackets;
674ff014514SRandall Stewart 		sb.sctps_inpackets += sarry->sctps_inpackets;
675ff014514SRandall Stewart 		sb.sctps_recvpackets += sarry->sctps_recvpackets;
676ff014514SRandall Stewart 		sb.sctps_recvdatagrams += sarry->sctps_recvdatagrams;
677ff014514SRandall Stewart 		sb.sctps_recvpktwithdata += sarry->sctps_recvpktwithdata;
678ff014514SRandall Stewart 		sb.sctps_recvsacks += sarry->sctps_recvsacks;
679ff014514SRandall Stewart 		sb.sctps_recvdata += sarry->sctps_recvdata;
680ff014514SRandall Stewart 		sb.sctps_recvdupdata += sarry->sctps_recvdupdata;
681ff014514SRandall Stewart 		sb.sctps_recvheartbeat += sarry->sctps_recvheartbeat;
682ff014514SRandall Stewart 		sb.sctps_recvheartbeatack += sarry->sctps_recvheartbeatack;
683ff014514SRandall Stewart 		sb.sctps_recvecne += sarry->sctps_recvecne;
684ff014514SRandall Stewart 		sb.sctps_recvauth += sarry->sctps_recvauth;
685ff014514SRandall Stewart 		sb.sctps_recvauthmissing += sarry->sctps_recvauthmissing;
686ff014514SRandall Stewart 		sb.sctps_recvivalhmacid += sarry->sctps_recvivalhmacid;
687ff014514SRandall Stewart 		sb.sctps_recvivalkeyid += sarry->sctps_recvivalkeyid;
688ff014514SRandall Stewart 		sb.sctps_recvauthfailed += sarry->sctps_recvauthfailed;
689ff014514SRandall Stewart 		sb.sctps_recvexpress += sarry->sctps_recvexpress;
690ff014514SRandall Stewart 		sb.sctps_recvexpressm += sarry->sctps_recvexpressm;
691ff014514SRandall Stewart 		sb.sctps_recvnocrc += sarry->sctps_recvnocrc;
692ff014514SRandall Stewart 		sb.sctps_recvswcrc += sarry->sctps_recvswcrc;
693ff014514SRandall Stewart 		sb.sctps_recvhwcrc += sarry->sctps_recvhwcrc;
694ff014514SRandall Stewart 		sb.sctps_sendpackets += sarry->sctps_sendpackets;
695ff014514SRandall Stewart 		sb.sctps_sendsacks += sarry->sctps_sendsacks;
696ff014514SRandall Stewart 		sb.sctps_senddata += sarry->sctps_senddata;
697ff014514SRandall Stewart 		sb.sctps_sendretransdata += sarry->sctps_sendretransdata;
698ff014514SRandall Stewart 		sb.sctps_sendfastretrans += sarry->sctps_sendfastretrans;
699ff014514SRandall Stewart 		sb.sctps_sendmultfastretrans += sarry->sctps_sendmultfastretrans;
700ff014514SRandall Stewart 		sb.sctps_sendheartbeat += sarry->sctps_sendheartbeat;
701ff014514SRandall Stewart 		sb.sctps_sendecne += sarry->sctps_sendecne;
702ff014514SRandall Stewart 		sb.sctps_sendauth += sarry->sctps_sendauth;
703ff014514SRandall Stewart 		sb.sctps_senderrors += sarry->sctps_senderrors;
704ff014514SRandall Stewart 		sb.sctps_sendnocrc += sarry->sctps_sendnocrc;
705ff014514SRandall Stewart 		sb.sctps_sendswcrc += sarry->sctps_sendswcrc;
706ff014514SRandall Stewart 		sb.sctps_sendhwcrc += sarry->sctps_sendhwcrc;
707ff014514SRandall Stewart 		sb.sctps_pdrpfmbox += sarry->sctps_pdrpfmbox;
708ff014514SRandall Stewart 		sb.sctps_pdrpfehos += sarry->sctps_pdrpfehos;
709ff014514SRandall Stewart 		sb.sctps_pdrpmbda += sarry->sctps_pdrpmbda;
710ff014514SRandall Stewart 		sb.sctps_pdrpmbct += sarry->sctps_pdrpmbct;
711ff014514SRandall Stewart 		sb.sctps_pdrpbwrpt += sarry->sctps_pdrpbwrpt;
712ff014514SRandall Stewart 		sb.sctps_pdrpcrupt += sarry->sctps_pdrpcrupt;
713ff014514SRandall Stewart 		sb.sctps_pdrpnedat += sarry->sctps_pdrpnedat;
714ff014514SRandall Stewart 		sb.sctps_pdrppdbrk += sarry->sctps_pdrppdbrk;
715ff014514SRandall Stewart 		sb.sctps_pdrptsnnf += sarry->sctps_pdrptsnnf;
716ff014514SRandall Stewart 		sb.sctps_pdrpdnfnd += sarry->sctps_pdrpdnfnd;
717ff014514SRandall Stewart 		sb.sctps_pdrpdiwnp += sarry->sctps_pdrpdiwnp;
718ff014514SRandall Stewart 		sb.sctps_pdrpdizrw += sarry->sctps_pdrpdizrw;
719ff014514SRandall Stewart 		sb.sctps_pdrpbadd += sarry->sctps_pdrpbadd;
720ff014514SRandall Stewart 		sb.sctps_pdrpmark += sarry->sctps_pdrpmark;
721ff014514SRandall Stewart 		sb.sctps_timoiterator += sarry->sctps_timoiterator;
722ff014514SRandall Stewart 		sb.sctps_timodata += sarry->sctps_timodata;
723ff014514SRandall Stewart 		sb.sctps_timowindowprobe += sarry->sctps_timowindowprobe;
724ff014514SRandall Stewart 		sb.sctps_timoinit += sarry->sctps_timoinit;
725ff014514SRandall Stewart 		sb.sctps_timosack += sarry->sctps_timosack;
726ff014514SRandall Stewart 		sb.sctps_timoshutdown += sarry->sctps_timoshutdown;
727ff014514SRandall Stewart 		sb.sctps_timoheartbeat += sarry->sctps_timoheartbeat;
728ff014514SRandall Stewart 		sb.sctps_timocookie += sarry->sctps_timocookie;
729ff014514SRandall Stewart 		sb.sctps_timosecret += sarry->sctps_timosecret;
730ff014514SRandall Stewart 		sb.sctps_timopathmtu += sarry->sctps_timopathmtu;
731ff014514SRandall Stewart 		sb.sctps_timoshutdownack += sarry->sctps_timoshutdownack;
732ff014514SRandall Stewart 		sb.sctps_timoshutdownguard += sarry->sctps_timoshutdownguard;
733ff014514SRandall Stewart 		sb.sctps_timostrmrst += sarry->sctps_timostrmrst;
734ff014514SRandall Stewart 		sb.sctps_timoearlyfr += sarry->sctps_timoearlyfr;
735ff014514SRandall Stewart 		sb.sctps_timoasconf += sarry->sctps_timoasconf;
736ff014514SRandall Stewart 		sb.sctps_timodelprim += sarry->sctps_timodelprim;
737ff014514SRandall Stewart 		sb.sctps_timoautoclose += sarry->sctps_timoautoclose;
738ff014514SRandall Stewart 		sb.sctps_timoassockill += sarry->sctps_timoassockill;
739ff014514SRandall Stewart 		sb.sctps_timoinpkill += sarry->sctps_timoinpkill;
740ff014514SRandall Stewart 		sb.sctps_hdrops += sarry->sctps_hdrops;
741ff014514SRandall Stewart 		sb.sctps_badsum += sarry->sctps_badsum;
742ff014514SRandall Stewart 		sb.sctps_noport += sarry->sctps_noport;
743ff014514SRandall Stewart 		sb.sctps_badvtag += sarry->sctps_badvtag;
744ff014514SRandall Stewart 		sb.sctps_badsid += sarry->sctps_badsid;
745ff014514SRandall Stewart 		sb.sctps_nomem += sarry->sctps_nomem;
746ff014514SRandall Stewart 		sb.sctps_fastretransinrtt += sarry->sctps_fastretransinrtt;
747ff014514SRandall Stewart 		sb.sctps_markedretrans += sarry->sctps_markedretrans;
748ff014514SRandall Stewart 		sb.sctps_naglesent += sarry->sctps_naglesent;
749ff014514SRandall Stewart 		sb.sctps_naglequeued += sarry->sctps_naglequeued;
750ff014514SRandall Stewart 		sb.sctps_maxburstqueued += sarry->sctps_maxburstqueued;
751ff014514SRandall Stewart 		sb.sctps_ifnomemqueued += sarry->sctps_ifnomemqueued;
752ff014514SRandall Stewart 		sb.sctps_windowprobed += sarry->sctps_windowprobed;
753ff014514SRandall Stewart 		sb.sctps_lowlevelerr += sarry->sctps_lowlevelerr;
754ff014514SRandall Stewart 		sb.sctps_lowlevelerrusr += sarry->sctps_lowlevelerrusr;
755ff014514SRandall Stewart 		sb.sctps_datadropchklmt += sarry->sctps_datadropchklmt;
756ff014514SRandall Stewart 		sb.sctps_datadroprwnd += sarry->sctps_datadroprwnd;
757ff014514SRandall Stewart 		sb.sctps_ecnereducedcwnd += sarry->sctps_ecnereducedcwnd;
758ff014514SRandall Stewart 		sb.sctps_vtagexpress += sarry->sctps_vtagexpress;
759ff014514SRandall Stewart 		sb.sctps_vtagbogus += sarry->sctps_vtagbogus;
760ff014514SRandall Stewart 		sb.sctps_primary_randry += sarry->sctps_primary_randry;
761ff014514SRandall Stewart 		sb.sctps_cmt_randry += sarry->sctps_cmt_randry;
762ff014514SRandall Stewart 		sb.sctps_slowpath_sack += sarry->sctps_slowpath_sack;
763ff014514SRandall Stewart 		sb.sctps_wu_sacks_sent += sarry->sctps_wu_sacks_sent;
764ff014514SRandall Stewart 		sb.sctps_sends_with_flags += sarry->sctps_sends_with_flags;
765ff014514SRandall Stewart 		sb.sctps_sends_with_unord += sarry->sctps_sends_with_unord;
766ff014514SRandall Stewart 		sb.sctps_sends_with_eof += sarry->sctps_sends_with_eof;
767ff014514SRandall Stewart 		sb.sctps_sends_with_abort += sarry->sctps_sends_with_abort;
768ff014514SRandall Stewart 		sb.sctps_protocol_drain_calls += sarry->sctps_protocol_drain_calls;
769ff014514SRandall Stewart 		sb.sctps_protocol_drains_done += sarry->sctps_protocol_drains_done;
770ff014514SRandall Stewart 		sb.sctps_read_peeks += sarry->sctps_read_peeks;
771ff014514SRandall Stewart 		sb.sctps_cached_chk += sarry->sctps_cached_chk;
772ff014514SRandall Stewart 		sb.sctps_cached_strmoq += sarry->sctps_cached_strmoq;
773ff014514SRandall Stewart 		sb.sctps_left_abandon += sarry->sctps_left_abandon;
774ff014514SRandall Stewart 		sb.sctps_send_burst_avoid += sarry->sctps_send_burst_avoid;
775ff014514SRandall Stewart 		sb.sctps_send_cwnd_avoid += sarry->sctps_send_cwnd_avoid;
776ff014514SRandall Stewart 		sb.sctps_fwdtsn_map_over += sarry->sctps_fwdtsn_map_over;
777*f47f328dSMichael Tuexen 		if (req->newptr != NULL) {
778*f47f328dSMichael Tuexen 			memcpy(sarry, req->newptr, sizeof(struct sctpstat));
779ae26e0a4SRandall Stewart 		}
780ff014514SRandall Stewart 	}
781*f47f328dSMichael Tuexen 	error = SYSCTL_OUT(req, &sb, sizeof(struct sctpstat));
782*f47f328dSMichael Tuexen #else
783*f47f328dSMichael Tuexen 	error = SYSCTL_OUT(req, &SCTP_BASE_STATS, sizeof(struct sctpstat));
784*f47f328dSMichael Tuexen #endif
785ff014514SRandall Stewart 	return (error);
786ff014514SRandall Stewart }
787ff014514SRandall Stewart 
788b3f1ea41SRandall Stewart #if defined(SCTP_LOCAL_TRACE_BUF)
789b3f1ea41SRandall Stewart static int
790*f47f328dSMichael Tuexen sctp_sysctl_handle_trace_log(SYSCTL_HANDLER_ARGS)
791*f47f328dSMichael Tuexen {
792*f47f328dSMichael Tuexen 	int error;
793*f47f328dSMichael Tuexen 
794*f47f328dSMichael Tuexen 	error = SYSCTL_OUT(req, &SCTP_BASE_SYSCTL(sctp_log), sizeof(struct sctp_log));
795*f47f328dSMichael Tuexen 	return (error);
796*f47f328dSMichael Tuexen }
797*f47f328dSMichael Tuexen 
798*f47f328dSMichael Tuexen static int
799*f47f328dSMichael Tuexen sctp_sysctl_handle_trace_log_clear(SYSCTL_HANDLER_ARGS)
800b3f1ea41SRandall Stewart {
801a99b6783SRandall Stewart 	int error = 0;
802a99b6783SRandall Stewart 
803b3f1ea41SRandall Stewart 	memset(&SCTP_BASE_SYSCTL(sctp_log), 0, sizeof(struct sctp_log));
804a99b6783SRandall Stewart 	return (error);
805b3f1ea41SRandall Stewart }
806b3f1ea41SRandall Stewart 
807b3f1ea41SRandall Stewart #endif
808b3f1ea41SRandall Stewart 
809*f47f328dSMichael Tuexen #define SCTP_UINT_SYSCTL(mib_name, var_name, prefix)			\
810*f47f328dSMichael Tuexen 	static int							\
811*f47f328dSMichael Tuexen 	sctp_sysctl_handle_##mib_name(SYSCTL_HANDLER_ARGS)		\
812*f47f328dSMichael Tuexen 	{								\
813*f47f328dSMichael Tuexen 		int error;						\
814*f47f328dSMichael Tuexen 		uint32_t new;						\
815*f47f328dSMichael Tuexen 									\
816*f47f328dSMichael Tuexen 		new = SCTP_BASE_SYSCTL(var_name);			\
817*f47f328dSMichael Tuexen 		error = sysctl_handle_int(oidp, &new, 0, req);		\
818*f47f328dSMichael Tuexen 		if ((error == 0) && (req->newptr != NULL)) {		\
819*f47f328dSMichael Tuexen 			if ((new < prefix##_MIN) ||			\
820*f47f328dSMichael Tuexen 			    (new > prefix##_MAX)) {			\
821*f47f328dSMichael Tuexen 				error = EINVAL;				\
822*f47f328dSMichael Tuexen 			} else {					\
823*f47f328dSMichael Tuexen 				SCTP_BASE_SYSCTL(var_name) = new;	\
824*f47f328dSMichael Tuexen 			}						\
825*f47f328dSMichael Tuexen 		}							\
826*f47f328dSMichael Tuexen 		return (error);						\
827*f47f328dSMichael Tuexen 	}								\
828*f47f328dSMichael Tuexen 	SYSCTL_VNET_PROC(_net_inet_sctp, OID_AUTO, mib_name,		\
829*f47f328dSMichael Tuexen 	                 CTLTYPE_UINT | CTLFLAG_RW, NULL, 0,		\
830*f47f328dSMichael Tuexen 	                 sctp_sysctl_handle_##mib_name, "UI", prefix##_DESC);
831b3f1ea41SRandall Stewart 
83242551e99SRandall Stewart /*
83342551e99SRandall Stewart  * sysctl definitions
83442551e99SRandall Stewart  */
83542551e99SRandall Stewart 
836*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(sendspace, sctp_sendspace, SCTPCTL_MAXDGRAM)
837*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(recvspace, sctp_recvspace, SCTPCTL_RECVSPACE)
838*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(auto_asconf, sctp_auto_asconf, SCTPCTL_AUTOASCONF)
839*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(ecn_enable, sctp_ecn_enable, SCTPCTL_ECN_ENABLE)
840*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(pr_enable, sctp_pr_enable, SCTPCTL_PR_ENABLE)
84197a0ca5bSMichael Tuexen SYSCTL_VNET_PROC(_net_inet_sctp, OID_AUTO, auth_enable, CTLTYPE_UINT | CTLFLAG_RW,
842*f47f328dSMichael Tuexen     NULL, 0, sctp_sysctl_handle_auth, "IU", SCTPCTL_AUTH_ENABLE_DESC);
843c79bec9cSMichael Tuexen SYSCTL_VNET_PROC(_net_inet_sctp, OID_AUTO, asconf_enable, CTLTYPE_UINT | CTLFLAG_RW,
844*f47f328dSMichael Tuexen     NULL, 0, sctp_sysctl_handle_asconf, "IU", SCTPCTL_ASCONF_ENABLE_DESC);
845*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(reconfig_enable, sctp_reconfig_enable, SCTPCTL_RECONFIG_ENABLE)
846*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(nrsack_enable, sctp_nrsack_enable, SCTPCTL_NRSACK_ENABLE)
847*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(pktdrop_enable, sctp_pktdrop_enable, SCTPCTL_PKTDROP_ENABLE)
848*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(strict_sacks, sctp_strict_sacks, SCTPCTL_STRICT_SACKS)
849*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(peer_chkoh, sctp_peer_chunk_oh, SCTPCTL_PEER_CHKOH)
850*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(maxburst, sctp_max_burst_default, SCTPCTL_MAXBURST)
851*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(fr_maxburst, sctp_fr_max_burst_default, SCTPCTL_FRMAXBURST)
852*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(maxchunks, sctp_max_chunks_on_queue, SCTPCTL_MAXCHUNKS)
853*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(tcbhashsize, sctp_hashtblsize, SCTPCTL_TCBHASHSIZE)
854*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(pcbhashsize, sctp_pcbtblsize, SCTPCTL_PCBHASHSIZE)
855*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(min_split_point, sctp_min_split_point, SCTPCTL_MIN_SPLIT_POINT)
856*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(chunkscale, sctp_chunkscale, SCTPCTL_CHUNKSCALE)
857*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(delayed_sack_time, sctp_delayed_sack_time_default, SCTPCTL_DELAYED_SACK_TIME)
858*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(sack_freq, sctp_sack_freq_default, SCTPCTL_SACK_FREQ)
859*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(sys_resource, sctp_system_free_resc_limit, SCTPCTL_SYS_RESOURCE)
860*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(asoc_resource, sctp_asoc_free_resc_limit, SCTPCTL_ASOC_RESOURCE)
861*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(heartbeat_interval, sctp_heartbeat_interval_default, SCTPCTL_HEARTBEAT_INTERVAL)
862*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(pmtu_raise_time, sctp_pmtu_raise_time_default, SCTPCTL_PMTU_RAISE_TIME)
863*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(shutdown_guard_time, sctp_shutdown_guard_time_default, SCTPCTL_SHUTDOWN_GUARD_TIME)
864*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(secret_lifetime, sctp_secret_lifetime_default, SCTPCTL_SECRET_LIFETIME)
865*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(rto_max, sctp_rto_max_default, SCTPCTL_RTO_MAX)
866*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(rto_min, sctp_rto_min_default, SCTPCTL_RTO_MIN)
867*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(rto_initial, sctp_rto_initial_default, SCTPCTL_RTO_INITIAL)
868*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(init_rto_max, sctp_init_rto_max_default, SCTPCTL_INIT_RTO_MAX)
869*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(valid_cookie_life, sctp_valid_cookie_life_default, SCTPCTL_VALID_COOKIE_LIFE)
870*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(init_rtx_max, sctp_init_rtx_max_default, SCTPCTL_INIT_RTX_MAX)
871*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(assoc_rtx_max, sctp_assoc_rtx_max_default, SCTPCTL_ASSOC_RTX_MAX)
872*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(path_rtx_max, sctp_path_rtx_max_default, SCTPCTL_PATH_RTX_MAX)
873*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(path_pf_threshold, sctp_path_pf_threshold, SCTPCTL_PATH_PF_THRESHOLD)
874*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(add_more_on_output, sctp_add_more_threshold, SCTPCTL_ADD_MORE_ON_OUTPUT)
875*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(incoming_streams, sctp_nr_incoming_streams_default, SCTPCTL_INCOMING_STREAMS)
876*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(outgoing_streams, sctp_nr_outgoing_streams_default, SCTPCTL_OUTGOING_STREAMS)
877*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(cmt_on_off, sctp_cmt_on_off, SCTPCTL_CMT_ON_OFF)
878*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(cmt_use_dac, sctp_cmt_use_dac, SCTPCTL_CMT_USE_DAC)
879*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(cwnd_maxburst, sctp_use_cwnd_based_maxburst, SCTPCTL_CWND_MAXBURST)
880*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(nat_friendly, sctp_nat_friendly, SCTPCTL_NAT_FRIENDLY)
881*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(abc_l_var, sctp_L2_abc_variable, SCTPCTL_ABC_L_VAR)
882*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(max_chained_mbufs, sctp_mbuf_threshold_count, SCTPCTL_MAX_CHAINED_MBUFS)
883*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(do_sctp_drain, sctp_do_drain, SCTPCTL_DO_SCTP_DRAIN)
884*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(hb_max_burst, sctp_hb_maxburst, SCTPCTL_HB_MAX_BURST)
885*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(abort_at_limit, sctp_abort_if_one_2_one_hits_limit, SCTPCTL_ABORT_AT_LIMIT)
886*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(strict_data_order, sctp_strict_data_order, SCTPCTL_STRICT_DATA_ORDER)
887*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(min_residual, sctp_min_residual, SCTPCTL_MIN_RESIDUAL)
888*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(max_retran_chunk, sctp_max_retran_chunk, SCTPCTL_MAX_RETRAN_CHUNK)
889*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(log_level, sctp_logging_level, SCTPCTL_LOGGING_LEVEL)
890*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(default_cc_module, sctp_default_cc_module, SCTPCTL_DEFAULT_CC_MODULE)
891*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(default_ss_module, sctp_default_ss_module, SCTPCTL_DEFAULT_SS_MODULE)
892*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(default_frag_interleave, sctp_default_frag_interleave, SCTPCTL_DEFAULT_FRAG_INTERLEAVE)
893*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(mobility_base, sctp_mobility_base, SCTPCTL_MOBILITY_BASE)
894*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(mobility_fasthandoff, sctp_mobility_fasthandoff, SCTPCTL_MOBILITY_FASTHANDOFF)
895b27a6b7dSRandall Stewart #if defined(SCTP_LOCAL_TRACE_BUF)
896*f47f328dSMichael Tuexen SYSCTL_VNET_PROC(_net_inet_sctp, OID_AUTO, log, CTLTYPE_STRUCT | CTLFLAG_RD,
897*f47f328dSMichael Tuexen     NULL, 0, sctp_sysctl_handle_trace_log, "S,sctplog", "SCTP logging (struct sctp_log)");
898f0878bdcSMichael Tuexen SYSCTL_VNET_PROC(_net_inet_sctp, OID_AUTO, clear_trace, CTLTYPE_UINT | CTLFLAG_RW,
899*f47f328dSMichael Tuexen     NULL, 0, sctp_sysctl_handle_trace_log_clear, "IU", "Clear SCTP Logging buffer");
900b27a6b7dSRandall Stewart #endif
901f0878bdcSMichael Tuexen SYSCTL_VNET_PROC(_net_inet_sctp, OID_AUTO, udp_tunneling_port, CTLTYPE_UINT | CTLFLAG_RW,
902*f47f328dSMichael Tuexen     NULL, 0, sctp_sysctl_handle_udp_tunneling, "IU", SCTPCTL_UDP_TUNNELING_PORT_DESC);
903*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(enable_sack_immediately, sctp_enable_sack_immediately, SCTPCTL_SACK_IMMEDIATELY_ENABLE)
904*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(nat_friendly_init, sctp_inits_include_nat_friendly, SCTPCTL_NAT_FRIENDLY_INITS)
905*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(vtag_time_wait, sctp_vtag_time_wait, SCTPCTL_TIME_WAIT)
906*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(buffer_splitting, sctp_buffer_splitting, SCTPCTL_BUFFER_SPLITTING)
907*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(initial_cwnd, sctp_initial_cwnd, SCTPCTL_INITIAL_CWND)
908*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(rttvar_bw, sctp_rttvar_bw, SCTPCTL_RTTVAR_BW)
909*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(rttvar_rtt, sctp_rttvar_rtt, SCTPCTL_RTTVAR_RTT)
910*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(rttvar_eqret, sctp_rttvar_eqret, SCTPCTL_RTTVAR_EQRET)
911*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(rttvar_steady_step, sctp_steady_step, SCTPCTL_RTTVAR_STEADYS)
912*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(use_dcccecn, sctp_use_dccc_ecn, SCTPCTL_RTTVAR_DCCCECN)
913*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(blackhole, sctp_blackhole, SCTPCTL_BLACKHOLE)
914*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(diag_info_code, sctp_diag_info_code, SCTPCTL_DIAG_INFO_CODE)
915851b7298SRandall Stewart #ifdef SCTP_DEBUG
916*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(debug, sctp_debug_on, SCTPCTL_DEBUG)
917f0878bdcSMichael Tuexen #endif
918b3f1ea41SRandall Stewart #if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
919*f47f328dSMichael Tuexen SCTP_UINT_SYSCTL(output_unlocked, sctp_output_unlocked, SCTPCTL_OUTPUT_UNLOCKED)
920b3f1ea41SRandall Stewart #endif
921*f47f328dSMichael Tuexen SYSCTL_VNET_PROC(_net_inet_sctp, OID_AUTO, stats, CTLTYPE_STRUCT | CTLFLAG_RW,
922*f47f328dSMichael Tuexen     NULL, 0, sctp_sysctl_handle_stats, "S,sctpstat", "SCTP statistics (struct sctp_stat)");
923f0878bdcSMichael Tuexen SYSCTL_VNET_PROC(_net_inet_sctp, OID_AUTO, assoclist, CTLTYPE_OPAQUE | CTLFLAG_RD,
924*f47f328dSMichael Tuexen     NULL, 0, sctp_sysctl_handle_assoclist, "S,xassoc", "List of active SCTP associations");
925