1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 2007, by Cisco Systems, Inc. All rights reserved.
5  * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
6  * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * a) Redistributions of source code must retain the above copyright notice,
12  *    this list of conditions and the following disclaimer.
13  *
14  * b) Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in
16  *    the documentation and/or other materials provided with the distribution.
17  *
18  * c) Neither the name of Cisco Systems, Inc. nor the names of its
19  *    contributors may be used to endorse or promote products derived
20  *    from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
32  * THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #if defined(__FreeBSD__) && !defined(__Userspace__)
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD: head/sys/netinet/sctp_sysctl.c 361934 2020-06-08 20:23:20Z tuexen $");
38 #endif
39 
40 #include <netinet/sctp_os.h>
41 #include <netinet/sctp.h>
42 #include <netinet/sctp_constants.h>
43 #include <netinet/sctp_sysctl.h>
44 #include <netinet/sctp_pcb.h>
45 #include <netinet/sctputil.h>
46 #include <netinet/sctp_output.h>
47 #if defined(__FreeBSD__) && !defined(__Userspace__)
48 #include <sys/smp.h>
49 #include <sys/sysctl.h>
50 #endif
51 #if defined(__APPLE__) && !defined(__Userspace__)
52 #include <netinet/sctp_bsd_addr.h>
53 #endif
54 
55 #if defined(__FreeBSD__) && !defined(__Userspace__)
56 FEATURE(sctp, "Stream Control Transmission Protocol");
57 #endif
58 
59 /*
60  * sysctl tunable variables
61  */
62 
63 void
sctp_init_sysctls()64 sctp_init_sysctls()
65 {
66 	SCTP_BASE_SYSCTL(sctp_sendspace) = SCTPCTL_MAXDGRAM_DEFAULT;
67 	SCTP_BASE_SYSCTL(sctp_recvspace) = SCTPCTL_RECVSPACE_DEFAULT;
68 	SCTP_BASE_SYSCTL(sctp_auto_asconf) = SCTPCTL_AUTOASCONF_DEFAULT;
69 	SCTP_BASE_SYSCTL(sctp_multiple_asconfs) = SCTPCTL_MULTIPLEASCONFS_DEFAULT;
70 	SCTP_BASE_SYSCTL(sctp_ecn_enable) = SCTPCTL_ECN_ENABLE_DEFAULT;
71 	SCTP_BASE_SYSCTL(sctp_pr_enable) = SCTPCTL_PR_ENABLE_DEFAULT;
72 	SCTP_BASE_SYSCTL(sctp_auth_enable) = SCTPCTL_AUTH_ENABLE_DEFAULT;
73 	SCTP_BASE_SYSCTL(sctp_asconf_enable) = SCTPCTL_ASCONF_ENABLE_DEFAULT;
74 	SCTP_BASE_SYSCTL(sctp_reconfig_enable) = SCTPCTL_RECONFIG_ENABLE_DEFAULT;
75 	SCTP_BASE_SYSCTL(sctp_nrsack_enable) = SCTPCTL_NRSACK_ENABLE_DEFAULT;
76 	SCTP_BASE_SYSCTL(sctp_pktdrop_enable) = SCTPCTL_PKTDROP_ENABLE_DEFAULT;
77 #if !(defined(__FreeBSD__) && !defined(__Userspace__))
78 	SCTP_BASE_SYSCTL(sctp_no_csum_on_loopback) = SCTPCTL_LOOPBACK_NOCSUM_DEFAULT;
79 #endif
80 	SCTP_BASE_SYSCTL(sctp_peer_chunk_oh) = SCTPCTL_PEER_CHKOH_DEFAULT;
81 	SCTP_BASE_SYSCTL(sctp_max_burst_default) = SCTPCTL_MAXBURST_DEFAULT;
82 	SCTP_BASE_SYSCTL(sctp_fr_max_burst_default) = SCTPCTL_FRMAXBURST_DEFAULT;
83 	SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = SCTPCTL_MAXCHUNKS_DEFAULT;
84 #if defined(__Userspace__)
85 	if (SCTP_BASE_SYSCTL(sctp_hashtblsize) == 0) {
86 		SCTP_BASE_SYSCTL(sctp_hashtblsize) = SCTPCTL_TCBHASHSIZE_DEFAULT;
87 	}
88 #else
89 	SCTP_BASE_SYSCTL(sctp_hashtblsize) = SCTPCTL_TCBHASHSIZE_DEFAULT;
90 #endif
91 #if defined(__Userspace__)
92 	if (SCTP_BASE_SYSCTL(sctp_pcbtblsize) == 0) {
93 		SCTP_BASE_SYSCTL(sctp_pcbtblsize) = SCTPCTL_PCBHASHSIZE_DEFAULT;
94 	}
95 #else
96 	SCTP_BASE_SYSCTL(sctp_pcbtblsize) = SCTPCTL_PCBHASHSIZE_DEFAULT;
97 #endif
98 	SCTP_BASE_SYSCTL(sctp_min_split_point) = SCTPCTL_MIN_SPLIT_POINT_DEFAULT;
99 #if defined(__Userspace__)
100 	if (SCTP_BASE_SYSCTL(sctp_chunkscale) == 0) {
101 		SCTP_BASE_SYSCTL(sctp_chunkscale) = SCTPCTL_CHUNKSCALE_DEFAULT;
102 	}
103 #else
104 	SCTP_BASE_SYSCTL(sctp_chunkscale) = SCTPCTL_CHUNKSCALE_DEFAULT;
105 #endif
106 	SCTP_BASE_SYSCTL(sctp_delayed_sack_time_default) = SCTPCTL_DELAYED_SACK_TIME_DEFAULT;
107 	SCTP_BASE_SYSCTL(sctp_sack_freq_default) = SCTPCTL_SACK_FREQ_DEFAULT;
108 	SCTP_BASE_SYSCTL(sctp_system_free_resc_limit) = SCTPCTL_SYS_RESOURCE_DEFAULT;
109 	SCTP_BASE_SYSCTL(sctp_asoc_free_resc_limit) = SCTPCTL_ASOC_RESOURCE_DEFAULT;
110 	SCTP_BASE_SYSCTL(sctp_heartbeat_interval_default) = SCTPCTL_HEARTBEAT_INTERVAL_DEFAULT;
111 	SCTP_BASE_SYSCTL(sctp_pmtu_raise_time_default) = SCTPCTL_PMTU_RAISE_TIME_DEFAULT;
112 	SCTP_BASE_SYSCTL(sctp_shutdown_guard_time_default) = SCTPCTL_SHUTDOWN_GUARD_TIME_DEFAULT;
113 	SCTP_BASE_SYSCTL(sctp_secret_lifetime_default) = SCTPCTL_SECRET_LIFETIME_DEFAULT;
114 	SCTP_BASE_SYSCTL(sctp_rto_max_default) = SCTPCTL_RTO_MAX_DEFAULT;
115 	SCTP_BASE_SYSCTL(sctp_rto_min_default) = SCTPCTL_RTO_MIN_DEFAULT;
116 	SCTP_BASE_SYSCTL(sctp_rto_initial_default) = SCTPCTL_RTO_INITIAL_DEFAULT;
117 	SCTP_BASE_SYSCTL(sctp_init_rto_max_default) = SCTPCTL_INIT_RTO_MAX_DEFAULT;
118 	SCTP_BASE_SYSCTL(sctp_valid_cookie_life_default) = SCTPCTL_VALID_COOKIE_LIFE_DEFAULT;
119 	SCTP_BASE_SYSCTL(sctp_init_rtx_max_default) = SCTPCTL_INIT_RTX_MAX_DEFAULT;
120 	SCTP_BASE_SYSCTL(sctp_assoc_rtx_max_default) = SCTPCTL_ASSOC_RTX_MAX_DEFAULT;
121 	SCTP_BASE_SYSCTL(sctp_path_rtx_max_default) = SCTPCTL_PATH_RTX_MAX_DEFAULT;
122 	SCTP_BASE_SYSCTL(sctp_path_pf_threshold) = SCTPCTL_PATH_PF_THRESHOLD_DEFAULT;
123 	SCTP_BASE_SYSCTL(sctp_add_more_threshold) = SCTPCTL_ADD_MORE_ON_OUTPUT_DEFAULT;
124 	SCTP_BASE_SYSCTL(sctp_nr_incoming_streams_default) = SCTPCTL_INCOMING_STREAMS_DEFAULT;
125 	SCTP_BASE_SYSCTL(sctp_nr_outgoing_streams_default) = SCTPCTL_OUTGOING_STREAMS_DEFAULT;
126 	SCTP_BASE_SYSCTL(sctp_cmt_on_off) = SCTPCTL_CMT_ON_OFF_DEFAULT;
127 	SCTP_BASE_SYSCTL(sctp_cmt_use_dac) = SCTPCTL_CMT_USE_DAC_DEFAULT;
128 	SCTP_BASE_SYSCTL(sctp_use_cwnd_based_maxburst) = SCTPCTL_CWND_MAXBURST_DEFAULT;
129 	SCTP_BASE_SYSCTL(sctp_nat_friendly) = SCTPCTL_NAT_FRIENDLY_DEFAULT;
130 	SCTP_BASE_SYSCTL(sctp_L2_abc_variable) = SCTPCTL_ABC_L_VAR_DEFAULT;
131 	SCTP_BASE_SYSCTL(sctp_mbuf_threshold_count) = SCTPCTL_MAX_CHAINED_MBUFS_DEFAULT;
132 	SCTP_BASE_SYSCTL(sctp_do_drain) = SCTPCTL_DO_SCTP_DRAIN_DEFAULT;
133 	SCTP_BASE_SYSCTL(sctp_hb_maxburst) = SCTPCTL_HB_MAX_BURST_DEFAULT;
134 	SCTP_BASE_SYSCTL(sctp_abort_if_one_2_one_hits_limit) = SCTPCTL_ABORT_AT_LIMIT_DEFAULT;
135 	SCTP_BASE_SYSCTL(sctp_min_residual) = SCTPCTL_MIN_RESIDUAL_DEFAULT;
136 	SCTP_BASE_SYSCTL(sctp_max_retran_chunk) = SCTPCTL_MAX_RETRAN_CHUNK_DEFAULT;
137 	SCTP_BASE_SYSCTL(sctp_logging_level) = SCTPCTL_LOGGING_LEVEL_DEFAULT;
138 	SCTP_BASE_SYSCTL(sctp_default_cc_module) = SCTPCTL_DEFAULT_CC_MODULE_DEFAULT;
139 	SCTP_BASE_SYSCTL(sctp_default_ss_module) = SCTPCTL_DEFAULT_SS_MODULE_DEFAULT;
140 	SCTP_BASE_SYSCTL(sctp_default_frag_interleave) = SCTPCTL_DEFAULT_FRAG_INTERLEAVE_DEFAULT;
141 	SCTP_BASE_SYSCTL(sctp_mobility_base) = SCTPCTL_MOBILITY_BASE_DEFAULT;
142 	SCTP_BASE_SYSCTL(sctp_mobility_fasthandoff) = SCTPCTL_MOBILITY_FASTHANDOFF_DEFAULT;
143 	SCTP_BASE_SYSCTL(sctp_vtag_time_wait) = SCTPCTL_TIME_WAIT_DEFAULT;
144 	SCTP_BASE_SYSCTL(sctp_buffer_splitting) = SCTPCTL_BUFFER_SPLITTING_DEFAULT;
145 	SCTP_BASE_SYSCTL(sctp_initial_cwnd) = SCTPCTL_INITIAL_CWND_DEFAULT;
146 	SCTP_BASE_SYSCTL(sctp_rttvar_bw) = SCTPCTL_RTTVAR_BW_DEFAULT;
147 	SCTP_BASE_SYSCTL(sctp_rttvar_rtt) = SCTPCTL_RTTVAR_RTT_DEFAULT;
148 	SCTP_BASE_SYSCTL(sctp_rttvar_eqret) = SCTPCTL_RTTVAR_EQRET_DEFAULT;
149 	SCTP_BASE_SYSCTL(sctp_steady_step) = SCTPCTL_RTTVAR_STEADYS_DEFAULT;
150 	SCTP_BASE_SYSCTL(sctp_use_dccc_ecn) = SCTPCTL_RTTVAR_DCCCECN_DEFAULT;
151 	SCTP_BASE_SYSCTL(sctp_blackhole) = SCTPCTL_BLACKHOLE_DEFAULT;
152 	SCTP_BASE_SYSCTL(sctp_sendall_limit) = SCTPCTL_SENDALL_LIMIT_DEFAULT;
153 	SCTP_BASE_SYSCTL(sctp_diag_info_code) = SCTPCTL_DIAG_INFO_CODE_DEFAULT;
154 #if defined(SCTP_LOCAL_TRACE_BUF)
155 #if defined(_WIN32) && !defined(__Userspace__)
156 	/* On Windows, the resource for global variables is limited. */
157 	MALLOC(SCTP_BASE_SYSCTL(sctp_log), struct sctp_log *, sizeof(struct sctp_log), M_SYSCTL, M_ZERO);
158 #else
159 	memset(&SCTP_BASE_SYSCTL(sctp_log), 0, sizeof(struct sctp_log));
160 #endif
161 #endif
162 	SCTP_BASE_SYSCTL(sctp_udp_tunneling_port) = SCTPCTL_UDP_TUNNELING_PORT_DEFAULT;
163 	SCTP_BASE_SYSCTL(sctp_enable_sack_immediately) = SCTPCTL_SACK_IMMEDIATELY_ENABLE_DEFAULT;
164 	SCTP_BASE_SYSCTL(sctp_inits_include_nat_friendly) = SCTPCTL_NAT_FRIENDLY_INITS_DEFAULT;
165 #if defined(SCTP_DEBUG)
166 	SCTP_BASE_SYSCTL(sctp_debug_on) = SCTPCTL_DEBUG_DEFAULT;
167 #endif
168 #if defined(__APPLE__) && !defined(__Userspace__)
169 	SCTP_BASE_SYSCTL(sctp_ignore_vmware_interfaces) = SCTPCTL_IGNORE_VMWARE_INTERFACES_DEFAULT;
170 	SCTP_BASE_SYSCTL(sctp_main_timer) = SCTPCTL_MAIN_TIMER_DEFAULT;
171 	SCTP_BASE_SYSCTL(sctp_addr_watchdog_limit) = SCTPCTL_ADDR_WATCHDOG_LIMIT_DEFAULT;
172 	SCTP_BASE_SYSCTL(sctp_vtag_watchdog_limit) = SCTPCTL_VTAG_WATCHDOG_LIMIT_DEFAULT;
173 #endif
174 #if defined(__APPLE__) && !defined(__Userspace__)
175 	SCTP_BASE_SYSCTL(sctp_output_unlocked) = SCTPCTL_OUTPUT_UNLOCKED_DEFAULT;
176 #endif
177 }
178 
179 #if defined(_WIN32) && !defined(__Userspace__)
180 void
sctp_finish_sysctls()181 sctp_finish_sysctls()
182 {
183 #if defined(SCTP_LOCAL_TRACE_BUF)
184 	if (SCTP_BASE_SYSCTL(sctp_log) != NULL) {
185 		FREE(SCTP_BASE_SYSCTL(sctp_log), M_SYSCTL);
186 		SCTP_BASE_SYSCTL(sctp_log) = NULL;
187 	}
188 #endif
189 }
190 #endif
191 
192 #if !defined(__Userspace__)
193 /* It returns an upper limit. No filtering is done here */
194 static unsigned int
sctp_sysctl_number_of_addresses(struct sctp_inpcb * inp)195 sctp_sysctl_number_of_addresses(struct sctp_inpcb *inp)
196 {
197 	unsigned int cnt;
198 	struct sctp_vrf *vrf;
199 	struct sctp_ifn *sctp_ifn;
200 	struct sctp_ifa *sctp_ifa;
201 	struct sctp_laddr *laddr;
202 
203 	cnt = 0;
204 	/* neither Mac OS X nor FreeBSD support mulitple routing functions */
205 	if ((vrf = sctp_find_vrf(inp->def_vrf_id)) == NULL) {
206 		return (0);
207 	}
208 	if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
209 		LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
210 			LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
211 				switch (sctp_ifa->address.sa.sa_family) {
212 #ifdef INET
213 				case AF_INET:
214 #endif
215 #ifdef INET6
216 				case AF_INET6:
217 #endif
218 					cnt++;
219 					break;
220 				default:
221 					break;
222 				}
223 			}
224 		}
225 	} else {
226 		LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
227 			switch (laddr->ifa->address.sa.sa_family) {
228 #ifdef INET
229 			case AF_INET:
230 #endif
231 #ifdef INET6
232 			case AF_INET6:
233 #endif
234 				cnt++;
235 				break;
236 			default:
237 				break;
238 			}
239 		}
240 	}
241 	return (cnt);
242 }
243 
244 static int
sctp_sysctl_copy_out_local_addresses(struct sctp_inpcb * inp,struct sctp_tcb * stcb,struct sysctl_req * req)245 sctp_sysctl_copy_out_local_addresses(struct sctp_inpcb *inp, struct sctp_tcb *stcb, struct sysctl_req *req)
246 {
247 	struct sctp_ifn *sctp_ifn;
248 	struct sctp_ifa *sctp_ifa;
249 	int loopback_scope, ipv4_local_scope, local_scope, site_scope;
250 	int ipv4_addr_legal, ipv6_addr_legal;
251 #if defined(__Userspace__)
252 	int conn_addr_legal;
253 #endif
254 	struct sctp_vrf *vrf;
255 	struct xsctp_laddr xladdr;
256 	struct sctp_laddr *laddr;
257 	int error;
258 
259 	/* Turn on all the appropriate scope */
260 	if (stcb) {
261 		/* use association specific values */
262 		loopback_scope = stcb->asoc.scope.loopback_scope;
263 		ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
264 		local_scope = stcb->asoc.scope.local_scope;
265 		site_scope = stcb->asoc.scope.site_scope;
266 		ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
267 		ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
268 #if defined(__Userspace__)
269 		conn_addr_legal = stcb->asoc.scope.conn_addr_legal;
270 #endif
271 	} else {
272 		/* Use generic values for endpoints. */
273 		loopback_scope = 1;
274 		ipv4_local_scope = 1;
275 		local_scope = 1;
276 		site_scope = 1;
277 		if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
278 			ipv6_addr_legal = 1;
279 			if (SCTP_IPV6_V6ONLY(inp)) {
280 				ipv4_addr_legal = 0;
281 			} else {
282 				ipv4_addr_legal = 1;
283 			}
284 #if defined(__Userspace__)
285 			conn_addr_legal = 0;
286 #endif
287 		} else {
288 			ipv6_addr_legal = 0;
289 #if defined(__Userspace__)
290 			if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_CONN) {
291 				conn_addr_legal = 1;
292 				ipv4_addr_legal = 0;
293 			} else {
294 				conn_addr_legal = 0;
295 				ipv4_addr_legal = 1;
296 			}
297 #else
298 			ipv4_addr_legal = 1;
299 #endif
300 		}
301 	}
302 
303 	/* neither Mac OS X nor FreeBSD support mulitple routing functions */
304 	if ((vrf = sctp_find_vrf(inp->def_vrf_id)) == NULL) {
305 		SCTP_INP_RUNLOCK(inp);
306 		SCTP_INP_INFO_RUNLOCK();
307 		return (-1);
308 	}
309 	if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
310 		LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
311 			if ((loopback_scope == 0) && SCTP_IFN_IS_IFT_LOOP(sctp_ifn))
312 				/* Skip loopback if loopback_scope not set */
313 				continue;
314 			LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
315 				if (stcb) {
316 					/*
317 					 * ignore if blacklisted at
318 					 * association level
319 					 */
320 					if (sctp_is_addr_restricted(stcb, sctp_ifa))
321 						continue;
322 				}
323 				switch (sctp_ifa->address.sa.sa_family) {
324 #ifdef INET
325 				case AF_INET:
326 					if (ipv4_addr_legal) {
327 						struct sockaddr_in *sin;
328 
329 						sin = &sctp_ifa->address.sin;
330 						if (sin->sin_addr.s_addr == 0)
331 							continue;
332 #if defined(__FreeBSD__) && !defined(__Userspace__)
333 						if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
334 						                     &sin->sin_addr) != 0) {
335 							continue;
336 						}
337 #endif
338 						if ((ipv4_local_scope == 0) && (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)))
339 							continue;
340 					} else {
341 						continue;
342 					}
343 					break;
344 #endif
345 #ifdef INET6
346 				case AF_INET6:
347 					if (ipv6_addr_legal) {
348 						struct sockaddr_in6 *sin6;
349 
350 						sin6 = &sctp_ifa->address.sin6;
351 						if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
352 							continue;
353 #if defined(__FreeBSD__) && !defined(__Userspace__)
354 						if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
355 						                     &sin6->sin6_addr) != 0) {
356 							continue;
357 						}
358 #endif
359 						if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
360 							if (local_scope == 0)
361 								continue;
362 						}
363 						if ((site_scope == 0) && (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)))
364 							continue;
365 					} else {
366 						continue;
367 					}
368 					break;
369 #endif
370 #if defined(__Userspace__)
371 				case AF_CONN:
372 					if (!conn_addr_legal) {
373 						continue;
374 					}
375 					break;
376 #endif
377 				default:
378 					continue;
379 				}
380 				memset((void *)&xladdr, 0, sizeof(struct xsctp_laddr));
381 				memcpy((void *)&xladdr.address, (const void *)&sctp_ifa->address, sizeof(union sctp_sockstore));
382 				SCTP_INP_RUNLOCK(inp);
383 				SCTP_INP_INFO_RUNLOCK();
384 				error = SYSCTL_OUT(req, &xladdr, sizeof(struct xsctp_laddr));
385 				if (error) {
386 					return (error);
387 				} else {
388 					SCTP_INP_INFO_RLOCK();
389 					SCTP_INP_RLOCK(inp);
390 				}
391 			}
392 		}
393 	} else {
394 		LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
395 			/* ignore if blacklisted at association level */
396 			if (stcb && sctp_is_addr_restricted(stcb, laddr->ifa))
397 				continue;
398 			memset((void *)&xladdr, 0, sizeof(struct xsctp_laddr));
399 			memcpy((void *)&xladdr.address, (const void *)&laddr->ifa->address, sizeof(union sctp_sockstore));
400 			xladdr.start_time.tv_sec = (uint32_t)laddr->start_time.tv_sec;
401 			xladdr.start_time.tv_usec = (uint32_t)laddr->start_time.tv_usec;
402 			SCTP_INP_RUNLOCK(inp);
403 			SCTP_INP_INFO_RUNLOCK();
404 			error = SYSCTL_OUT(req, &xladdr, sizeof(struct xsctp_laddr));
405 			if (error) {
406 				return (error);
407 			} else {
408 				SCTP_INP_INFO_RLOCK();
409 				SCTP_INP_RLOCK(inp);
410 			}
411 		}
412 	}
413 	memset((void *)&xladdr, 0, sizeof(struct xsctp_laddr));
414 	xladdr.last = 1;
415 	SCTP_INP_RUNLOCK(inp);
416 	SCTP_INP_INFO_RUNLOCK();
417 	error = SYSCTL_OUT(req, &xladdr, sizeof(struct xsctp_laddr));
418 
419 	if (error) {
420 		return (error);
421 	} else {
422 		SCTP_INP_INFO_RLOCK();
423 		SCTP_INP_RLOCK(inp);
424 		return (0);
425 	}
426 }
427 
428 /*
429  * sysctl functions
430  */
431 #if defined(__APPLE__) && !defined(__Userspace__)
432 static int
433 sctp_sysctl_handle_assoclist SYSCTL_HANDLER_ARGS
434 {
435 #pragma unused(oidp, arg1, arg2)
436 #else
437 static int
438 sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS)
439 {
440 #endif
441 	unsigned int number_of_endpoints;
442 	unsigned int number_of_local_addresses;
443 	unsigned int number_of_associations;
444 	unsigned int number_of_remote_addresses;
445 	unsigned int n;
446 	int error;
447 	struct sctp_inpcb *inp;
448 	struct sctp_tcb *stcb;
449 	struct sctp_nets *net;
450 	struct xsctp_inpcb xinpcb;
451 	struct xsctp_tcb xstcb;
452 	struct xsctp_raddr xraddr;
453 	struct socket *so;
454 
455 	number_of_endpoints = 0;
456 	number_of_local_addresses = 0;
457 	number_of_associations = 0;
458 	number_of_remote_addresses = 0;
459 
460 	SCTP_INP_INFO_RLOCK();
461 #if defined(__APPLE__) && !defined(__Userspace__)
462 	if (req->oldptr == USER_ADDR_NULL) {
463 #else
464 	if (req->oldptr == NULL) {
465 #endif
466 		LIST_FOREACH(inp, &SCTP_BASE_INFO(listhead), sctp_list) {
467 			SCTP_INP_RLOCK(inp);
468 			number_of_endpoints++;
469 			number_of_local_addresses += sctp_sysctl_number_of_addresses(inp);
470 			LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
471 				number_of_associations++;
472 				number_of_local_addresses += sctp_sysctl_number_of_addresses(inp);
473 				TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
474 					number_of_remote_addresses++;
475 				}
476 			}
477 			SCTP_INP_RUNLOCK(inp);
478 		}
479 		SCTP_INP_INFO_RUNLOCK();
480 		n = (number_of_endpoints + 1) * sizeof(struct xsctp_inpcb) +
481 		    (number_of_local_addresses + number_of_endpoints + number_of_associations) * sizeof(struct xsctp_laddr) +
482 		    (number_of_associations + number_of_endpoints) * sizeof(struct xsctp_tcb) +
483 		    (number_of_remote_addresses + number_of_associations) * sizeof(struct xsctp_raddr);
484 
485 		/* request some more memory than needed */
486 #if !(defined(_WIN32) && !defined(__Userspace__))
487 		req->oldidx = (n + n / 8);
488 #else
489 		req->dataidx = (n + n / 8);
490 #endif
491 		return (0);
492 	}
493 #if defined(__APPLE__) && !defined(__Userspace__)
494 	if (req->newptr != USER_ADDR_NULL) {
495 #else
496 	if (req->newptr != NULL) {
497 #endif
498 		SCTP_INP_INFO_RUNLOCK();
499 		SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_SYSCTL, EPERM);
500 		return (EPERM);
501 	}
502 	memset(&xinpcb, 0, sizeof(xinpcb));
503 	memset(&xstcb, 0, sizeof(xstcb));
504 	memset(&xraddr, 0, sizeof(xraddr));
505 	LIST_FOREACH(inp, &SCTP_BASE_INFO(listhead), sctp_list) {
506 		SCTP_INP_RLOCK(inp);
507 		if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) {
508 			/* if its allgone it is being freed - skip it  */
509 			goto skip;
510 		}
511 		xinpcb.last = 0;
512 		xinpcb.local_port = ntohs(inp->sctp_lport);
513 		xinpcb.flags = inp->sctp_flags;
514 		xinpcb.features = inp->sctp_features;
515 		xinpcb.total_sends = inp->total_sends;
516 		xinpcb.total_recvs = inp->total_recvs;
517 		xinpcb.total_nospaces = inp->total_nospaces;
518 		xinpcb.fragmentation_point = inp->sctp_frag_point;
519 #if defined(__FreeBSD__) && !defined(__Userspace__)
520 		xinpcb.socket = (uintptr_t)inp->sctp_socket;
521 #else
522 		xinpcb.socket = inp->sctp_socket;
523 #endif
524 		so = inp->sctp_socket;
525 		if ((so == NULL) ||
526 		    (!SCTP_IS_LISTENING(inp)) ||
527 		    (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
528 			xinpcb.qlen = 0;
529 			xinpcb.maxqlen = 0;
530 		} else {
531 #if defined(__FreeBSD__) && !defined(__Userspace__)
532 			xinpcb.qlen = so->sol_qlen;
533 			xinpcb.qlen_old = so->sol_qlen > USHRT_MAX ?
534 			    USHRT_MAX : (uint16_t) so->sol_qlen;
535 			xinpcb.maxqlen = so->sol_qlimit;
536 			xinpcb.maxqlen_old = so->sol_qlimit > USHRT_MAX ?
537 			    USHRT_MAX : (uint16_t) so->sol_qlimit;
538 #else
539 			xinpcb.qlen = so->so_qlen;
540 			xinpcb.maxqlen = so->so_qlimit;
541 #endif
542 		}
543 		SCTP_INP_INCR_REF(inp);
544 		SCTP_INP_RUNLOCK(inp);
545 		SCTP_INP_INFO_RUNLOCK();
546 		error = SYSCTL_OUT(req, &xinpcb, sizeof(struct xsctp_inpcb));
547 		if (error) {
548 			SCTP_INP_DECR_REF(inp);
549 			return (error);
550 		}
551 		SCTP_INP_INFO_RLOCK();
552 		SCTP_INP_RLOCK(inp);
553 		error = sctp_sysctl_copy_out_local_addresses(inp, NULL, req);
554 		if (error) {
555 			SCTP_INP_DECR_REF(inp);
556 			return (error);
557 		}
558 		LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
559 			SCTP_TCB_LOCK(stcb);
560 			atomic_add_int(&stcb->asoc.refcnt, 1);
561 			SCTP_TCB_UNLOCK(stcb);
562 			xstcb.last = 0;
563 			xstcb.local_port = ntohs(inp->sctp_lport);
564 			xstcb.remote_port = ntohs(stcb->rport);
565 			if (stcb->asoc.primary_destination != NULL)
566 				xstcb.primary_addr = stcb->asoc.primary_destination->ro._l_addr;
567 			xstcb.heartbeat_interval = stcb->asoc.heart_beat_delay;
568 			xstcb.state = (uint32_t)sctp_map_assoc_state(stcb->asoc.state);
569 			xstcb.assoc_id = sctp_get_associd(stcb);
570 			xstcb.peers_rwnd = stcb->asoc.peers_rwnd;
571 			xstcb.in_streams = stcb->asoc.streamincnt;
572 			xstcb.out_streams = stcb->asoc.streamoutcnt;
573 			xstcb.max_nr_retrans = stcb->asoc.overall_error_count;
574 			xstcb.primary_process = 0; /* not really supported yet */
575 			xstcb.T1_expireries = stcb->asoc.timoinit + stcb->asoc.timocookie;
576 			xstcb.T2_expireries = stcb->asoc.timoshutdown + stcb->asoc.timoshutdownack;
577 			xstcb.retransmitted_tsns = stcb->asoc.marked_retrans;
578 			xstcb.start_time.tv_sec = (uint32_t)stcb->asoc.start_time.tv_sec;
579 			xstcb.start_time.tv_usec = (uint32_t)stcb->asoc.start_time.tv_usec;
580 			xstcb.discontinuity_time.tv_sec = (uint32_t)stcb->asoc.discontinuity_time.tv_sec;
581 			xstcb.discontinuity_time.tv_usec = (uint32_t)stcb->asoc.discontinuity_time.tv_usec;
582 			xstcb.total_sends = stcb->total_sends;
583 			xstcb.total_recvs = stcb->total_recvs;
584 			xstcb.local_tag = stcb->asoc.my_vtag;
585 			xstcb.remote_tag = stcb->asoc.peer_vtag;
586 			xstcb.initial_tsn = stcb->asoc.init_seq_number;
587 			xstcb.highest_tsn = stcb->asoc.sending_seq - 1;
588 			xstcb.cumulative_tsn = stcb->asoc.last_acked_seq;
589 			xstcb.cumulative_tsn_ack = stcb->asoc.cumulative_tsn;
590 			xstcb.mtu = stcb->asoc.smallest_mtu;
591 			xstcb.refcnt = stcb->asoc.refcnt;
592 			SCTP_INP_RUNLOCK(inp);
593 			SCTP_INP_INFO_RUNLOCK();
594 			error = SYSCTL_OUT(req, &xstcb, sizeof(struct xsctp_tcb));
595 			if (error) {
596 				SCTP_INP_DECR_REF(inp);
597 				atomic_subtract_int(&stcb->asoc.refcnt, 1);
598 				return (error);
599 			}
600 			SCTP_INP_INFO_RLOCK();
601 			SCTP_INP_RLOCK(inp);
602 			error = sctp_sysctl_copy_out_local_addresses(inp, stcb, req);
603 			if (error) {
604 				SCTP_INP_DECR_REF(inp);
605 				atomic_subtract_int(&stcb->asoc.refcnt, 1);
606 				return (error);
607 			}
608 			TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
609 				xraddr.last = 0;
610 				xraddr.address = net->ro._l_addr;
611 				xraddr.active = ((net->dest_state & SCTP_ADDR_REACHABLE) == SCTP_ADDR_REACHABLE);
612 				xraddr.confirmed = ((net->dest_state & SCTP_ADDR_UNCONFIRMED) == 0);
613 				xraddr.heartbeat_enabled = ((net->dest_state & SCTP_ADDR_NOHB) == 0);
614 				xraddr.potentially_failed = ((net->dest_state & SCTP_ADDR_PF) == SCTP_ADDR_PF);
615 				xraddr.rto = net->RTO;
616 				xraddr.max_path_rtx = net->failure_threshold;
617 				xraddr.rtx = net->marked_retrans;
618 				xraddr.error_counter = net->error_count;
619 				xraddr.cwnd = net->cwnd;
620 				xraddr.flight_size = net->flight_size;
621 				xraddr.mtu = net->mtu;
622 				xraddr.rtt = net->rtt / 1000;
623 				xraddr.heartbeat_interval = net->heart_beat_delay;
624 				xraddr.ssthresh = net->ssthresh;
625 				xraddr.encaps_port = net->port;
626 				if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
627 					xraddr.state = SCTP_UNCONFIRMED;
628 				} else if (net->dest_state & SCTP_ADDR_REACHABLE) {
629 					xraddr.state = SCTP_ACTIVE;
630 				} else {
631 					xraddr.state = SCTP_INACTIVE;
632 				}
633 				xraddr.start_time.tv_sec = (uint32_t)net->start_time.tv_sec;
634 				xraddr.start_time.tv_usec = (uint32_t)net->start_time.tv_usec;
635 				SCTP_INP_RUNLOCK(inp);
636 				SCTP_INP_INFO_RUNLOCK();
637 				error = SYSCTL_OUT(req, &xraddr, sizeof(struct xsctp_raddr));
638 				if (error) {
639 					SCTP_INP_DECR_REF(inp);
640 					atomic_subtract_int(&stcb->asoc.refcnt, 1);
641 					return (error);
642 				}
643 				SCTP_INP_INFO_RLOCK();
644 				SCTP_INP_RLOCK(inp);
645 			}
646 			atomic_subtract_int(&stcb->asoc.refcnt, 1);
647 			memset((void *)&xraddr, 0, sizeof(struct xsctp_raddr));
648 			xraddr.last = 1;
649 			SCTP_INP_RUNLOCK(inp);
650 			SCTP_INP_INFO_RUNLOCK();
651 			error = SYSCTL_OUT(req, &xraddr, sizeof(struct xsctp_raddr));
652 			if (error) {
653 				SCTP_INP_DECR_REF(inp);
654 				return (error);
655 			}
656 			SCTP_INP_INFO_RLOCK();
657 			SCTP_INP_RLOCK(inp);
658 		}
659 		SCTP_INP_DECR_REF(inp);
660 		SCTP_INP_RUNLOCK(inp);
661 		SCTP_INP_INFO_RUNLOCK();
662 		memset((void *)&xstcb, 0, sizeof(struct xsctp_tcb));
663 		xstcb.last = 1;
664 		error = SYSCTL_OUT(req, &xstcb, sizeof(struct xsctp_tcb));
665 		if (error) {
666 			return (error);
667 		}
668 skip:
669 		SCTP_INP_INFO_RLOCK();
670 	}
671 	SCTP_INP_INFO_RUNLOCK();
672 
673 	memset((void *)&xinpcb, 0, sizeof(struct xsctp_inpcb));
674 	xinpcb.last = 1;
675 	error = SYSCTL_OUT(req, &xinpcb, sizeof(struct xsctp_inpcb));
676 	return (error);
677 }
678 
679 #if defined(__APPLE__) && !defined(__Userspace__)
680 static int
681 sctp_sysctl_handle_udp_tunneling SYSCTL_HANDLER_ARGS
682 {
683 #pragma unused(arg1, arg2)
684 #else
685 static int
686 sctp_sysctl_handle_udp_tunneling(SYSCTL_HANDLER_ARGS)
687 {
688 #endif
689 	int error;
690 	uint32_t old, new;
691 
692 	SCTP_INP_INFO_RLOCK();
693 	old = SCTP_BASE_SYSCTL(sctp_udp_tunneling_port);
694 	SCTP_INP_INFO_RUNLOCK();
695 	new = old;
696 	error = sysctl_handle_int(oidp, &new, 0, req);
697 	if ((error == 0) &&
698 #if defined(__APPLE__) && !defined(__Userspace__)
699 	    (req->newptr != USER_ADDR_NULL)) {
700 #else
701 	    (req->newptr != NULL)) {
702 #endif
703 #if defined(_WIN32) && !defined(__Userspace__)
704 		SCTP_INP_INFO_WLOCK();
705 		sctp_over_udp_restart();
706 		SCTP_INP_INFO_WUNLOCK();
707 #else
708 #if (SCTPCTL_UDP_TUNNELING_PORT_MIN == 0)
709 		if (new > SCTPCTL_UDP_TUNNELING_PORT_MAX) {
710 #else
711 		if ((new < SCTPCTL_UDP_TUNNELING_PORT_MIN) ||
712 		    (new > SCTPCTL_UDP_TUNNELING_PORT_MAX)) {
713 #endif
714 			error = EINVAL;
715 		} else {
716 			SCTP_INP_INFO_WLOCK();
717 			SCTP_BASE_SYSCTL(sctp_udp_tunneling_port) = new;
718 			if (old != 0) {
719 				sctp_over_udp_stop();
720 			}
721 			if (new != 0) {
722 				error = sctp_over_udp_start();
723 			}
724 			SCTP_INP_INFO_WUNLOCK();
725 		}
726 #endif
727 	}
728 	return (error);
729 }
730 
731 #if defined(__APPLE__) && !defined(__Userspace__)
732 int sctp_is_vmware_interface(struct ifnet *);
733 
734 static int
735 sctp_sysctl_handle_vmware_interfaces SYSCTL_HANDLER_ARGS
736 {
737 #pragma unused(arg1, arg2)
738 	int error;
739 	uint32_t old, new;
740 
741 	old = SCTP_BASE_SYSCTL(sctp_ignore_vmware_interfaces);
742 	new = old;
743 	error = sysctl_handle_int(oidp, &new, 0, req);
744 	if ((error == 0) && (req->newptr != USER_ADDR_NULL)) {
745 		if ((new < SCTPCTL_IGNORE_VMWARE_INTERFACES_MIN) ||
746 		    (new > SCTPCTL_IGNORE_VMWARE_INTERFACES_MAX)) {
747 			error = EINVAL;
748 		} else {
749 			if ((old == 1) && (new == 0)) {
750 				sctp_add_or_del_interfaces(sctp_is_vmware_interface, 1);
751 			}
752 			if ((old == 0) && (new == 1)) {
753 				sctp_add_or_del_interfaces(sctp_is_vmware_interface, 0);
754 			}
755 			if (old != new) {
756 				SCTP_BASE_SYSCTL(sctp_ignore_vmware_interfaces) = new;
757 			}
758 		}
759 	}
760 	return (error);
761 }
762 #endif
763 
764 #if defined(__APPLE__) && !defined(__Userspace__)
765 static int
766 sctp_sysctl_handle_auth SYSCTL_HANDLER_ARGS
767 {
768 #pragma unused(arg1, arg2)
769 #else
770 static int
771 sctp_sysctl_handle_auth(SYSCTL_HANDLER_ARGS)
772 {
773 #endif
774 	int error;
775 	uint32_t new;
776 
777 	new = SCTP_BASE_SYSCTL(sctp_auth_enable);
778 	error = sysctl_handle_int(oidp, &new, 0, req);
779 	if ((error == 0) &&
780 #if defined(__APPLE__) && !defined(__Userspace__)
781 	    (req->newptr != USER_ADDR_NULL)) {
782 #else
783 	    (req->newptr != NULL)) {
784 #endif
785 #if (SCTPCTL_AUTH_ENABLE_MIN == 0)
786 		if ((new > SCTPCTL_AUTH_ENABLE_MAX) ||
787 		    ((new == 0) && (SCTP_BASE_SYSCTL(sctp_asconf_enable) == 1))) {
788 #else
789 		if ((new < SCTPCTL_AUTH_ENABLE_MIN) ||
790 		    (new > SCTPCTL_AUTH_ENABLE_MAX) ||
791 		    ((new == 0) && (SCTP_BASE_SYSCTL(sctp_asconf_enable) == 1))) {
792 #endif
793 			error = EINVAL;
794 		} else {
795 			SCTP_BASE_SYSCTL(sctp_auth_enable) = new;
796 		}
797 	}
798 	return (error);
799 }
800 
801 #if defined(__APPLE__) && !defined(__Userspace__)
802 static int
803 sctp_sysctl_handle_asconf SYSCTL_HANDLER_ARGS
804 {
805 #pragma unused(arg1, arg2)
806 #else
807 static int
808 sctp_sysctl_handle_asconf(SYSCTL_HANDLER_ARGS)
809 {
810 #endif
811 	int error;
812 	uint32_t new;
813 
814 	new = SCTP_BASE_SYSCTL(sctp_asconf_enable);
815 	error = sysctl_handle_int(oidp, &new, 0, req);
816 	if ((error == 0) &&
817 #if defined(__APPLE__) && !defined(__Userspace__)
818 	    (req->newptr != USER_ADDR_NULL)) {
819 #else
820 	    (req->newptr != NULL)) {
821 #endif
822 #if (SCTPCTL_ASCONF_ENABLE_MIN == 0)
823 		if ((new > SCTPCTL_ASCONF_ENABLE_MAX) ||
824 		    ((new == 1) && (SCTP_BASE_SYSCTL(sctp_auth_enable) == 0))) {
825 #else
826 		if ((new < SCTPCTL_ASCONF_ENABLE_MIN) ||
827 		    (new > SCTPCTL_ASCONF_ENABLE_MAX) ||
828 		    ((new == 1) && (SCTP_BASE_SYSCTL(sctp_auth_enable) == 0))) {
829 #endif
830 			error = EINVAL;
831 		} else {
832 			SCTP_BASE_SYSCTL(sctp_asconf_enable) = new;
833 		}
834 	}
835 	return (error);
836 }
837 
838 #if defined(__APPLE__) && !defined(__Userspace__)
839 static int
840 sctp_sysctl_handle_stats SYSCTL_HANDLER_ARGS
841 {
842 #pragma unused(oidp, arg1, arg2)
843 #else
844 static int
845 sctp_sysctl_handle_stats(SYSCTL_HANDLER_ARGS)
846 {
847 #endif
848 	int error;
849 #if defined(__FreeBSD__) && !defined(__Userspace__)
850 #if defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
851 	struct sctpstat *sarry;
852 	struct sctpstat sb;
853 	int cpu;
854 #endif
855 	struct sctpstat sb_temp;
856 #endif
857 
858 #if defined(__APPLE__) && !defined(__Userspace__)
859 	if ((req->newptr != USER_ADDR_NULL) &&
860 #else
861 	if ((req->newptr != NULL) &&
862 #endif
863 	    (req->newlen != sizeof(struct sctpstat))) {
864 		return (EINVAL);
865 	}
866 #if defined(__FreeBSD__) && !defined(__Userspace__)
867 	memset(&sb_temp, 0, sizeof(struct sctpstat));
868 
869 	if (req->newptr != NULL) {
870 		error = SYSCTL_IN(req, &sb_temp, sizeof(struct sctpstat));
871 		if (error != 0) {
872 			return (error);
873 		}
874 	}
875 #if defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
876 	memset(&sb, 0, sizeof(sb));
877 	for (cpu = 0; cpu < mp_maxid; cpu++) {
878 		sarry = &SCTP_BASE_STATS[cpu];
879 		if (sarry->sctps_discontinuitytime.tv_sec > sb.sctps_discontinuitytime.tv_sec) {
880 			sb.sctps_discontinuitytime.tv_sec = sarry->sctps_discontinuitytime.tv_sec;
881 			sb.sctps_discontinuitytime.tv_usec = sarry->sctps_discontinuitytime.tv_usec;
882 		}
883 		sb.sctps_currestab += sarry->sctps_currestab;
884 		sb.sctps_activeestab += sarry->sctps_activeestab;
885 		sb.sctps_restartestab += sarry->sctps_restartestab;
886 		sb.sctps_collisionestab += sarry->sctps_collisionestab;
887 		sb.sctps_passiveestab += sarry->sctps_passiveestab;
888 		sb.sctps_aborted += sarry->sctps_aborted;
889 		sb.sctps_shutdown += sarry->sctps_shutdown;
890 		sb.sctps_outoftheblue += sarry->sctps_outoftheblue;
891 		sb.sctps_checksumerrors += sarry->sctps_checksumerrors;
892 		sb.sctps_outcontrolchunks += sarry->sctps_outcontrolchunks;
893 		sb.sctps_outorderchunks += sarry->sctps_outorderchunks;
894 		sb.sctps_outunorderchunks += sarry->sctps_outunorderchunks;
895 		sb.sctps_incontrolchunks += sarry->sctps_incontrolchunks;
896 		sb.sctps_inorderchunks += sarry->sctps_inorderchunks;
897 		sb.sctps_inunorderchunks += sarry->sctps_inunorderchunks;
898 		sb.sctps_fragusrmsgs += sarry->sctps_fragusrmsgs;
899 		sb.sctps_reasmusrmsgs += sarry->sctps_reasmusrmsgs;
900 		sb.sctps_outpackets += sarry->sctps_outpackets;
901 		sb.sctps_inpackets += sarry->sctps_inpackets;
902 		sb.sctps_recvpackets += sarry->sctps_recvpackets;
903 		sb.sctps_recvdatagrams += sarry->sctps_recvdatagrams;
904 		sb.sctps_recvpktwithdata += sarry->sctps_recvpktwithdata;
905 		sb.sctps_recvsacks += sarry->sctps_recvsacks;
906 		sb.sctps_recvdata += sarry->sctps_recvdata;
907 		sb.sctps_recvdupdata += sarry->sctps_recvdupdata;
908 		sb.sctps_recvheartbeat += sarry->sctps_recvheartbeat;
909 		sb.sctps_recvheartbeatack += sarry->sctps_recvheartbeatack;
910 		sb.sctps_recvecne += sarry->sctps_recvecne;
911 		sb.sctps_recvauth += sarry->sctps_recvauth;
912 		sb.sctps_recvauthmissing += sarry->sctps_recvauthmissing;
913 		sb.sctps_recvivalhmacid += sarry->sctps_recvivalhmacid;
914 		sb.sctps_recvivalkeyid += sarry->sctps_recvivalkeyid;
915 		sb.sctps_recvauthfailed += sarry->sctps_recvauthfailed;
916 		sb.sctps_recvexpress += sarry->sctps_recvexpress;
917 		sb.sctps_recvexpressm += sarry->sctps_recvexpressm;
918 		sb.sctps_recvswcrc += sarry->sctps_recvswcrc;
919 		sb.sctps_recvhwcrc += sarry->sctps_recvhwcrc;
920 		sb.sctps_sendpackets += sarry->sctps_sendpackets;
921 		sb.sctps_sendsacks += sarry->sctps_sendsacks;
922 		sb.sctps_senddata += sarry->sctps_senddata;
923 		sb.sctps_sendretransdata += sarry->sctps_sendretransdata;
924 		sb.sctps_sendfastretrans += sarry->sctps_sendfastretrans;
925 		sb.sctps_sendmultfastretrans += sarry->sctps_sendmultfastretrans;
926 		sb.sctps_sendheartbeat += sarry->sctps_sendheartbeat;
927 		sb.sctps_sendecne += sarry->sctps_sendecne;
928 		sb.sctps_sendauth += sarry->sctps_sendauth;
929 		sb.sctps_senderrors += sarry->sctps_senderrors;
930 		sb.sctps_sendswcrc += sarry->sctps_sendswcrc;
931 		sb.sctps_sendhwcrc += sarry->sctps_sendhwcrc;
932 		sb.sctps_pdrpfmbox += sarry->sctps_pdrpfmbox;
933 		sb.sctps_pdrpfehos += sarry->sctps_pdrpfehos;
934 		sb.sctps_pdrpmbda += sarry->sctps_pdrpmbda;
935 		sb.sctps_pdrpmbct += sarry->sctps_pdrpmbct;
936 		sb.sctps_pdrpbwrpt += sarry->sctps_pdrpbwrpt;
937 		sb.sctps_pdrpcrupt += sarry->sctps_pdrpcrupt;
938 		sb.sctps_pdrpnedat += sarry->sctps_pdrpnedat;
939 		sb.sctps_pdrppdbrk += sarry->sctps_pdrppdbrk;
940 		sb.sctps_pdrptsnnf += sarry->sctps_pdrptsnnf;
941 		sb.sctps_pdrpdnfnd += sarry->sctps_pdrpdnfnd;
942 		sb.sctps_pdrpdiwnp += sarry->sctps_pdrpdiwnp;
943 		sb.sctps_pdrpdizrw += sarry->sctps_pdrpdizrw;
944 		sb.sctps_pdrpbadd += sarry->sctps_pdrpbadd;
945 		sb.sctps_pdrpmark += sarry->sctps_pdrpmark;
946 		sb.sctps_timoiterator += sarry->sctps_timoiterator;
947 		sb.sctps_timodata += sarry->sctps_timodata;
948 		sb.sctps_timowindowprobe += sarry->sctps_timowindowprobe;
949 		sb.sctps_timoinit += sarry->sctps_timoinit;
950 		sb.sctps_timosack += sarry->sctps_timosack;
951 		sb.sctps_timoshutdown += sarry->sctps_timoshutdown;
952 		sb.sctps_timoheartbeat += sarry->sctps_timoheartbeat;
953 		sb.sctps_timocookie += sarry->sctps_timocookie;
954 		sb.sctps_timosecret += sarry->sctps_timosecret;
955 		sb.sctps_timopathmtu += sarry->sctps_timopathmtu;
956 		sb.sctps_timoshutdownack += sarry->sctps_timoshutdownack;
957 		sb.sctps_timoshutdownguard += sarry->sctps_timoshutdownguard;
958 		sb.sctps_timostrmrst += sarry->sctps_timostrmrst;
959 		sb.sctps_timoearlyfr += sarry->sctps_timoearlyfr;
960 		sb.sctps_timoasconf += sarry->sctps_timoasconf;
961 		sb.sctps_timodelprim += sarry->sctps_timodelprim;
962 		sb.sctps_timoautoclose += sarry->sctps_timoautoclose;
963 		sb.sctps_timoassockill += sarry->sctps_timoassockill;
964 		sb.sctps_timoinpkill += sarry->sctps_timoinpkill;
965 		sb.sctps_hdrops += sarry->sctps_hdrops;
966 		sb.sctps_badsum += sarry->sctps_badsum;
967 		sb.sctps_noport += sarry->sctps_noport;
968 		sb.sctps_badvtag += sarry->sctps_badvtag;
969 		sb.sctps_badsid += sarry->sctps_badsid;
970 		sb.sctps_nomem += sarry->sctps_nomem;
971 		sb.sctps_fastretransinrtt += sarry->sctps_fastretransinrtt;
972 		sb.sctps_markedretrans += sarry->sctps_markedretrans;
973 		sb.sctps_naglesent += sarry->sctps_naglesent;
974 		sb.sctps_naglequeued += sarry->sctps_naglequeued;
975 		sb.sctps_maxburstqueued += sarry->sctps_maxburstqueued;
976 		sb.sctps_ifnomemqueued += sarry->sctps_ifnomemqueued;
977 		sb.sctps_windowprobed += sarry->sctps_windowprobed;
978 		sb.sctps_lowlevelerr += sarry->sctps_lowlevelerr;
979 		sb.sctps_lowlevelerrusr += sarry->sctps_lowlevelerrusr;
980 		sb.sctps_datadropchklmt += sarry->sctps_datadropchklmt;
981 		sb.sctps_datadroprwnd += sarry->sctps_datadroprwnd;
982 		sb.sctps_ecnereducedcwnd += sarry->sctps_ecnereducedcwnd;
983 		sb.sctps_vtagexpress += sarry->sctps_vtagexpress;
984 		sb.sctps_vtagbogus += sarry->sctps_vtagbogus;
985 		sb.sctps_primary_randry += sarry->sctps_primary_randry;
986 		sb.sctps_cmt_randry += sarry->sctps_cmt_randry;
987 		sb.sctps_slowpath_sack += sarry->sctps_slowpath_sack;
988 		sb.sctps_wu_sacks_sent += sarry->sctps_wu_sacks_sent;
989 		sb.sctps_sends_with_flags += sarry->sctps_sends_with_flags;
990 		sb.sctps_sends_with_unord += sarry->sctps_sends_with_unord;
991 		sb.sctps_sends_with_eof += sarry->sctps_sends_with_eof;
992 		sb.sctps_sends_with_abort += sarry->sctps_sends_with_abort;
993 		sb.sctps_protocol_drain_calls += sarry->sctps_protocol_drain_calls;
994 		sb.sctps_protocol_drains_done += sarry->sctps_protocol_drains_done;
995 		sb.sctps_read_peeks += sarry->sctps_read_peeks;
996 		sb.sctps_cached_chk += sarry->sctps_cached_chk;
997 		sb.sctps_cached_strmoq += sarry->sctps_cached_strmoq;
998 		sb.sctps_left_abandon += sarry->sctps_left_abandon;
999 		sb.sctps_send_burst_avoid += sarry->sctps_send_burst_avoid;
1000 		sb.sctps_send_cwnd_avoid += sarry->sctps_send_cwnd_avoid;
1001 		sb.sctps_fwdtsn_map_over += sarry->sctps_fwdtsn_map_over;
1002 		if (req->newptr != NULL) {
1003 			memcpy(sarry, &sb_temp, sizeof(struct sctpstat));
1004 		}
1005 	}
1006 	error = SYSCTL_OUT(req, &sb, sizeof(struct sctpstat));
1007 #else
1008 	error = SYSCTL_OUT(req, &SCTP_BASE_STATS, sizeof(struct sctpstat));
1009 	if (error != 0) {
1010 		return (error);
1011 	}
1012 	if (req->newptr != NULL) {
1013 		memcpy(&SCTP_BASE_STATS, &sb_temp, sizeof(struct sctpstat));
1014 	}
1015 #endif
1016 #else
1017 	error = SYSCTL_OUT(req, &SCTP_BASE_STATS, sizeof(struct sctpstat));
1018 #endif
1019 	return (error);
1020 }
1021 
1022 #if defined(SCTP_LOCAL_TRACE_BUF)
1023 #if defined(__APPLE__) && !defined(__Userspace__)
1024 static int
1025 sctp_sysctl_handle_trace_log SYSCTL_HANDLER_ARGS
1026 {
1027 #pragma unused(arg1, arg2, oidp)
1028 #else
1029 static int
1030 sctp_sysctl_handle_trace_log(SYSCTL_HANDLER_ARGS)
1031 {
1032 #endif
1033 	int error;
1034 
1035 #if defined(_WIN32) && !defined(__Userspace__)
1036 	error = SYSCTL_OUT(req, SCTP_BASE_SYSCTL(sctp_log), sizeof(struct sctp_log));
1037 #else
1038 	error = SYSCTL_OUT(req, &SCTP_BASE_SYSCTL(sctp_log), sizeof(struct sctp_log));
1039 #endif
1040 	return (error);
1041 }
1042 
1043 #if defined(__APPLE__) && !defined(__Userspace__)
1044 static int
1045 sctp_sysctl_handle_trace_log_clear SYSCTL_HANDLER_ARGS
1046 {
1047 #pragma unused(arg1, arg2, req, oidp)
1048 #else
1049 static int
1050 sctp_sysctl_handle_trace_log_clear(SYSCTL_HANDLER_ARGS)
1051 {
1052 #endif
1053 	int error = 0;
1054 #if defined(_WIN32) && !defined(__Userspace__)
1055 	int value = 0;
1056 
1057 	if (req->new_data == NULL) {
1058 		return (error);
1059 	}
1060 	error = SYSCTL_IN(req, &value, sizeof(int));
1061 	if (error == 0 && value != 0 && SCTP_BASE_SYSCTL(sctp_log) != NULL) {
1062 		memset(SCTP_BASE_SYSCTL(sctp_log), 0, sizeof(struct sctp_log));
1063 	}
1064 #else
1065 
1066 	memset(&SCTP_BASE_SYSCTL(sctp_log), 0, sizeof(struct sctp_log));
1067 #endif
1068 	return (error);
1069 }
1070 #endif
1071 
1072 #if (defined(__APPLE__) || defined(__FreeBSD__)) && !defined(__Userspace__)
1073 #if defined(__FreeBSD__)
1074 #define SCTP_UINT_SYSCTL(mib_name, var_name, prefix)			\
1075 	static int							\
1076 	sctp_sysctl_handle_##mib_name(SYSCTL_HANDLER_ARGS)		\
1077 	{								\
1078 		int error;						\
1079 		uint32_t new;						\
1080 									\
1081 		new = SCTP_BASE_SYSCTL(var_name);			\
1082 		error = sysctl_handle_int(oidp, &new, 0, req);		\
1083 		if ((error == 0) && (req->newptr != NULL)) {		\
1084 			if ((new < prefix##_MIN) ||			\
1085 			    (new > prefix##_MAX)) {			\
1086 				error = EINVAL;				\
1087 			} else {					\
1088 				SCTP_BASE_SYSCTL(var_name) = new;	\
1089 			}						\
1090 		}							\
1091 		return (error);						\
1092 	}								\
1093 	SYSCTL_PROC(_net_inet_sctp, OID_AUTO, mib_name,			\
1094 	                 CTLFLAG_VNET|CTLTYPE_UINT|CTLFLAG_RW, NULL, 0,	\
1095 	                 sctp_sysctl_handle_##mib_name, "UI", prefix##_DESC);
1096 #else
1097 #define SCTP_UINT_SYSCTL(mib_name, var_name, prefix)			\
1098 	static int							\
1099 	sctp_sysctl_handle_##mib_name(struct sysctl_oid *oidp,		\
1100 	                          void *arg1 __attribute__((unused)),	\
1101 	                          int arg2 __attribute__((unused)),	\
1102 	                          struct sysctl_req *req)		\
1103 	{								\
1104 		int error;						\
1105 		uint32_t new;						\
1106 									\
1107 		new = SCTP_BASE_SYSCTL(var_name);			\
1108 		error = sysctl_handle_int(oidp, &new, 0, req);		\
1109 		if ((error == 0) && (req->newptr != USER_ADDR_NULL)) {	\
1110 			if ((new < prefix##_MIN) ||			\
1111 			    (new > prefix##_MAX)) {			\
1112 				error = EINVAL;				\
1113 			} else {					\
1114 				SCTP_BASE_SYSCTL(var_name) = new;	\
1115 			}						\
1116 		}							\
1117 		return (error);						\
1118 	}								\
1119 	SYSCTL_PROC(_net_inet_sctp, OID_AUTO, mib_name,			\
1120 	            CTLTYPE_INT | CTLFLAG_RW, NULL, 0,			\
1121 	            sctp_sysctl_handle_##mib_name, "I", prefix##_DESC);
1122 #define CTLTYPE_UINT CTLTYPE_INT
1123 #define CTLFLAG_VNET 0
1124 #endif
1125 
1126 /*
1127  * sysctl definitions
1128  */
1129 
1130 SCTP_UINT_SYSCTL(sendspace, sctp_sendspace, SCTPCTL_MAXDGRAM)
1131 SCTP_UINT_SYSCTL(recvspace, sctp_recvspace, SCTPCTL_RECVSPACE)
1132 SCTP_UINT_SYSCTL(auto_asconf, sctp_auto_asconf, SCTPCTL_AUTOASCONF)
1133 SCTP_UINT_SYSCTL(ecn_enable, sctp_ecn_enable, SCTPCTL_ECN_ENABLE)
1134 SCTP_UINT_SYSCTL(pr_enable, sctp_pr_enable, SCTPCTL_PR_ENABLE)
1135 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, auth_enable, CTLFLAG_VNET|CTLTYPE_UINT|CTLFLAG_RW,
1136             NULL, 0, sctp_sysctl_handle_auth, "IU", SCTPCTL_AUTH_ENABLE_DESC);
1137 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, asconf_enable, CTLFLAG_VNET|CTLTYPE_UINT|CTLFLAG_RW,
1138             NULL, 0, sctp_sysctl_handle_asconf, "IU", SCTPCTL_ASCONF_ENABLE_DESC);
1139 SCTP_UINT_SYSCTL(reconfig_enable, sctp_reconfig_enable, SCTPCTL_RECONFIG_ENABLE)
1140 SCTP_UINT_SYSCTL(nrsack_enable, sctp_nrsack_enable, SCTPCTL_NRSACK_ENABLE)
1141 SCTP_UINT_SYSCTL(pktdrop_enable, sctp_pktdrop_enable, SCTPCTL_PKTDROP_ENABLE)
1142 #if defined(__APPLE__) && !defined(__Userspace__)
1143 SCTP_UINT_SYSCTL(loopback_nocsum, sctp_no_csum_on_loopback, SCTPCTL_LOOPBACK_NOCSUM)
1144 #endif
1145 SCTP_UINT_SYSCTL(peer_chkoh, sctp_peer_chunk_oh, SCTPCTL_PEER_CHKOH)
1146 SCTP_UINT_SYSCTL(maxburst, sctp_max_burst_default, SCTPCTL_MAXBURST)
1147 SCTP_UINT_SYSCTL(fr_maxburst, sctp_fr_max_burst_default, SCTPCTL_FRMAXBURST)
1148 SCTP_UINT_SYSCTL(maxchunks, sctp_max_chunks_on_queue, SCTPCTL_MAXCHUNKS)
1149 SCTP_UINT_SYSCTL(tcbhashsize, sctp_hashtblsize, SCTPCTL_TCBHASHSIZE)
1150 SCTP_UINT_SYSCTL(pcbhashsize, sctp_pcbtblsize, SCTPCTL_PCBHASHSIZE)
1151 SCTP_UINT_SYSCTL(min_split_point, sctp_min_split_point, SCTPCTL_MIN_SPLIT_POINT)
1152 SCTP_UINT_SYSCTL(chunkscale, sctp_chunkscale, SCTPCTL_CHUNKSCALE)
1153 SCTP_UINT_SYSCTL(delayed_sack_time, sctp_delayed_sack_time_default, SCTPCTL_DELAYED_SACK_TIME)
1154 SCTP_UINT_SYSCTL(sack_freq, sctp_sack_freq_default, SCTPCTL_SACK_FREQ)
1155 SCTP_UINT_SYSCTL(sys_resource, sctp_system_free_resc_limit, SCTPCTL_SYS_RESOURCE)
1156 SCTP_UINT_SYSCTL(asoc_resource, sctp_asoc_free_resc_limit, SCTPCTL_ASOC_RESOURCE)
1157 SCTP_UINT_SYSCTL(heartbeat_interval, sctp_heartbeat_interval_default, SCTPCTL_HEARTBEAT_INTERVAL)
1158 SCTP_UINT_SYSCTL(pmtu_raise_time, sctp_pmtu_raise_time_default, SCTPCTL_PMTU_RAISE_TIME)
1159 SCTP_UINT_SYSCTL(shutdown_guard_time, sctp_shutdown_guard_time_default, SCTPCTL_SHUTDOWN_GUARD_TIME)
1160 SCTP_UINT_SYSCTL(secret_lifetime, sctp_secret_lifetime_default, SCTPCTL_SECRET_LIFETIME)
1161 SCTP_UINT_SYSCTL(rto_max, sctp_rto_max_default, SCTPCTL_RTO_MAX)
1162 SCTP_UINT_SYSCTL(rto_min, sctp_rto_min_default, SCTPCTL_RTO_MIN)
1163 SCTP_UINT_SYSCTL(rto_initial, sctp_rto_initial_default, SCTPCTL_RTO_INITIAL)
1164 SCTP_UINT_SYSCTL(init_rto_max, sctp_init_rto_max_default, SCTPCTL_INIT_RTO_MAX)
1165 SCTP_UINT_SYSCTL(valid_cookie_life, sctp_valid_cookie_life_default, SCTPCTL_VALID_COOKIE_LIFE)
1166 SCTP_UINT_SYSCTL(init_rtx_max, sctp_init_rtx_max_default, SCTPCTL_INIT_RTX_MAX)
1167 SCTP_UINT_SYSCTL(assoc_rtx_max, sctp_assoc_rtx_max_default, SCTPCTL_ASSOC_RTX_MAX)
1168 SCTP_UINT_SYSCTL(path_rtx_max, sctp_path_rtx_max_default, SCTPCTL_PATH_RTX_MAX)
1169 SCTP_UINT_SYSCTL(path_pf_threshold, sctp_path_pf_threshold, SCTPCTL_PATH_PF_THRESHOLD)
1170 SCTP_UINT_SYSCTL(add_more_on_output, sctp_add_more_threshold, SCTPCTL_ADD_MORE_ON_OUTPUT)
1171 SCTP_UINT_SYSCTL(incoming_streams, sctp_nr_incoming_streams_default, SCTPCTL_INCOMING_STREAMS)
1172 SCTP_UINT_SYSCTL(outgoing_streams, sctp_nr_outgoing_streams_default, SCTPCTL_OUTGOING_STREAMS)
1173 SCTP_UINT_SYSCTL(cmt_on_off, sctp_cmt_on_off, SCTPCTL_CMT_ON_OFF)
1174 SCTP_UINT_SYSCTL(cmt_use_dac, sctp_cmt_use_dac, SCTPCTL_CMT_USE_DAC)
1175 SCTP_UINT_SYSCTL(cwnd_maxburst, sctp_use_cwnd_based_maxburst, SCTPCTL_CWND_MAXBURST)
1176 SCTP_UINT_SYSCTL(nat_friendly, sctp_nat_friendly, SCTPCTL_NAT_FRIENDLY)
1177 SCTP_UINT_SYSCTL(abc_l_var, sctp_L2_abc_variable, SCTPCTL_ABC_L_VAR)
1178 SCTP_UINT_SYSCTL(max_chained_mbufs, sctp_mbuf_threshold_count, SCTPCTL_MAX_CHAINED_MBUFS)
1179 SCTP_UINT_SYSCTL(do_sctp_drain, sctp_do_drain, SCTPCTL_DO_SCTP_DRAIN)
1180 SCTP_UINT_SYSCTL(hb_max_burst, sctp_hb_maxburst, SCTPCTL_HB_MAX_BURST)
1181 SCTP_UINT_SYSCTL(abort_at_limit, sctp_abort_if_one_2_one_hits_limit, SCTPCTL_ABORT_AT_LIMIT)
1182 SCTP_UINT_SYSCTL(min_residual, sctp_min_residual, SCTPCTL_MIN_RESIDUAL)
1183 SCTP_UINT_SYSCTL(max_retran_chunk, sctp_max_retran_chunk, SCTPCTL_MAX_RETRAN_CHUNK)
1184 SCTP_UINT_SYSCTL(log_level, sctp_logging_level, SCTPCTL_LOGGING_LEVEL)
1185 SCTP_UINT_SYSCTL(default_cc_module, sctp_default_cc_module, SCTPCTL_DEFAULT_CC_MODULE)
1186 SCTP_UINT_SYSCTL(default_ss_module, sctp_default_ss_module, SCTPCTL_DEFAULT_SS_MODULE)
1187 SCTP_UINT_SYSCTL(default_frag_interleave, sctp_default_frag_interleave, SCTPCTL_DEFAULT_FRAG_INTERLEAVE)
1188 SCTP_UINT_SYSCTL(mobility_base, sctp_mobility_base, SCTPCTL_MOBILITY_BASE)
1189 SCTP_UINT_SYSCTL(mobility_fasthandoff, sctp_mobility_fasthandoff, SCTPCTL_MOBILITY_FASTHANDOFF)
1190 #if defined(SCTP_LOCAL_TRACE_BUF)
1191 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, log, CTLFLAG_VNET|CTLTYPE_STRUCT|CTLFLAG_RD,
1192             NULL, 0, sctp_sysctl_handle_trace_log, "S,sctplog", "SCTP logging (struct sctp_log)");
1193 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, clear_trace, CTLFLAG_VNET|CTLTYPE_UINT | CTLFLAG_RW,
1194             NULL, 0, sctp_sysctl_handle_trace_log_clear, "IU", "Clear SCTP Logging buffer");
1195 #endif
1196 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, udp_tunneling_port, CTLFLAG_VNET|CTLTYPE_UINT|CTLFLAG_RW,
1197             NULL, 0, sctp_sysctl_handle_udp_tunneling, "IU", SCTPCTL_UDP_TUNNELING_PORT_DESC);
1198 SCTP_UINT_SYSCTL(enable_sack_immediately, sctp_enable_sack_immediately, SCTPCTL_SACK_IMMEDIATELY_ENABLE)
1199 SCTP_UINT_SYSCTL(nat_friendly_init, sctp_inits_include_nat_friendly, SCTPCTL_NAT_FRIENDLY_INITS)
1200 SCTP_UINT_SYSCTL(vtag_time_wait, sctp_vtag_time_wait, SCTPCTL_TIME_WAIT)
1201 SCTP_UINT_SYSCTL(buffer_splitting, sctp_buffer_splitting, SCTPCTL_BUFFER_SPLITTING)
1202 SCTP_UINT_SYSCTL(initial_cwnd, sctp_initial_cwnd, SCTPCTL_INITIAL_CWND)
1203 SCTP_UINT_SYSCTL(rttvar_bw, sctp_rttvar_bw, SCTPCTL_RTTVAR_BW)
1204 SCTP_UINT_SYSCTL(rttvar_rtt, sctp_rttvar_rtt, SCTPCTL_RTTVAR_RTT)
1205 SCTP_UINT_SYSCTL(rttvar_eqret, sctp_rttvar_eqret, SCTPCTL_RTTVAR_EQRET)
1206 SCTP_UINT_SYSCTL(rttvar_steady_step, sctp_steady_step, SCTPCTL_RTTVAR_STEADYS)
1207 SCTP_UINT_SYSCTL(use_dcccecn, sctp_use_dccc_ecn, SCTPCTL_RTTVAR_DCCCECN)
1208 SCTP_UINT_SYSCTL(blackhole, sctp_blackhole, SCTPCTL_BLACKHOLE)
1209 SCTP_UINT_SYSCTL(sendall_limit, sctp_sendall_limit, SCTPCTL_SENDALL_LIMIT)
1210 SCTP_UINT_SYSCTL(diag_info_code, sctp_diag_info_code, SCTPCTL_DIAG_INFO_CODE)
1211 #ifdef SCTP_DEBUG
1212 SCTP_UINT_SYSCTL(debug, sctp_debug_on, SCTPCTL_DEBUG)
1213 #endif
1214 #if defined(__APPLE__) && !defined(__Userspace__)
1215 SCTP_UINT_SYSCTL(main_timer, sctp_main_timer, SCTPCTL_MAIN_TIMER)
1216 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, ignore_vmware_interfaces, CTLTYPE_UINT|CTLFLAG_RW,
1217             NULL, 0, sctp_sysctl_handle_vmware_interfaces, "IU", SCTPCTL_IGNORE_VMWARE_INTERFACES_DESC);
1218 SCTP_UINT_SYSCTL(addr_watchdog_limit, sctp_addr_watchdog_limit, SCTPCTL_ADDR_WATCHDOG_LIMIT)
1219 SCTP_UINT_SYSCTL(vtag_watchdog_limit, sctp_vtag_watchdog_limit, SCTPCTL_VTAG_WATCHDOG_LIMIT)
1220 #endif
1221 #if defined(__APPLE__) && !defined(__Userspace__)
1222 SCTP_UINT_SYSCTL(output_unlocked, sctp_output_unlocked, SCTPCTL_OUTPUT_UNLOCKED)
1223 #endif
1224 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, stats, CTLFLAG_VNET|CTLTYPE_STRUCT|CTLFLAG_RW,
1225             NULL, 0, sctp_sysctl_handle_stats, "S,sctpstat", "SCTP statistics (struct sctp_stat)");
1226 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, assoclist, CTLFLAG_VNET|CTLTYPE_OPAQUE|CTLFLAG_RD,
1227             NULL, 0, sctp_sysctl_handle_assoclist, "S,xassoc", "List of active SCTP associations");
1228 
1229 #elif defined(_WIN32) && !defined(__Userspace__)
1230 
1231 #define RANGECHK(var, min, max) \
1232 	if ((var) < (min)) { (var) = (min); } \
1233 	else if ((var) > (max)) { (var) = (max); }
1234 
1235 static int
sctp_sysctl_handle_int(SYSCTL_HANDLER_ARGS)1236 sctp_sysctl_handle_int(SYSCTL_HANDLER_ARGS)
1237 {
1238 	int error;
1239 
1240 	error = sysctl_handle_int(oidp, oidp->oid_arg1, oidp->oid_arg2, req);
1241 	if (error == 0) {
1242 		RANGECHK(SCTP_BASE_SYSCTL(sctp_sendspace), SCTPCTL_MAXDGRAM_MIN, SCTPCTL_MAXDGRAM_MAX);
1243 		RANGECHK(SCTP_BASE_SYSCTL(sctp_recvspace), SCTPCTL_RECVSPACE_MIN, SCTPCTL_RECVSPACE_MAX);
1244 		RANGECHK(SCTP_BASE_SYSCTL(sctp_auto_asconf), SCTPCTL_AUTOASCONF_MIN, SCTPCTL_AUTOASCONF_MAX);
1245 		RANGECHK(SCTP_BASE_SYSCTL(sctp_auto_asconf), SCTPCTL_AUTOASCONF_MIN, SCTPCTL_AUTOASCONF_MAX);
1246 		RANGECHK(SCTP_BASE_SYSCTL(sctp_ecn_enable), SCTPCTL_ECN_ENABLE_MIN, SCTPCTL_ECN_ENABLE_MAX);
1247 		RANGECHK(SCTP_BASE_SYSCTL(sctp_pr_enable), SCTPCTL_PR_ENABLE_MIN, SCTPCTL_PR_ENABLE_MAX);
1248 		RANGECHK(SCTP_BASE_SYSCTL(sctp_reconfig_enable), SCTPCTL_RECONFIG_ENABLE_MIN, SCTPCTL_RECONFIG_ENABLE_MAX);
1249 		RANGECHK(SCTP_BASE_SYSCTL(sctp_nrsack_enable), SCTPCTL_NRSACK_ENABLE_MIN, SCTPCTL_NRSACK_ENABLE_MAX);
1250 		RANGECHK(SCTP_BASE_SYSCTL(sctp_pktdrop_enable), SCTPCTL_PKTDROP_ENABLE_MIN, SCTPCTL_PKTDROP_ENABLE_MAX);
1251 		RANGECHK(SCTP_BASE_SYSCTL(sctp_no_csum_on_loopback), SCTPCTL_LOOPBACK_NOCSUM_MIN, SCTPCTL_LOOPBACK_NOCSUM_MAX);
1252 		RANGECHK(SCTP_BASE_SYSCTL(sctp_peer_chunk_oh), SCTPCTL_PEER_CHKOH_MIN, SCTPCTL_PEER_CHKOH_MAX);
1253 		RANGECHK(SCTP_BASE_SYSCTL(sctp_max_burst_default), SCTPCTL_MAXBURST_MIN, SCTPCTL_MAXBURST_MAX);
1254 		RANGECHK(SCTP_BASE_SYSCTL(sctp_fr_max_burst_default), SCTPCTL_FRMAXBURST_MIN, SCTPCTL_FRMAXBURST_MAX);
1255 		RANGECHK(SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue), SCTPCTL_MAXCHUNKS_MIN, SCTPCTL_MAXCHUNKS_MAX);
1256 		RANGECHK(SCTP_BASE_SYSCTL(sctp_hashtblsize), SCTPCTL_TCBHASHSIZE_MIN, SCTPCTL_TCBHASHSIZE_MAX);
1257 		RANGECHK(SCTP_BASE_SYSCTL(sctp_pcbtblsize), SCTPCTL_PCBHASHSIZE_MIN, SCTPCTL_PCBHASHSIZE_MAX);
1258 		RANGECHK(SCTP_BASE_SYSCTL(sctp_min_split_point), SCTPCTL_MIN_SPLIT_POINT_MIN, SCTPCTL_MIN_SPLIT_POINT_MAX);
1259 		RANGECHK(SCTP_BASE_SYSCTL(sctp_chunkscale), SCTPCTL_CHUNKSCALE_MIN, SCTPCTL_CHUNKSCALE_MAX);
1260 		RANGECHK(SCTP_BASE_SYSCTL(sctp_delayed_sack_time_default), SCTPCTL_DELAYED_SACK_TIME_MIN, SCTPCTL_DELAYED_SACK_TIME_MAX);
1261 		RANGECHK(SCTP_BASE_SYSCTL(sctp_sack_freq_default), SCTPCTL_SACK_FREQ_MIN, SCTPCTL_SACK_FREQ_MAX);
1262 		RANGECHK(SCTP_BASE_SYSCTL(sctp_system_free_resc_limit), SCTPCTL_SYS_RESOURCE_MIN, SCTPCTL_SYS_RESOURCE_MAX);
1263 		RANGECHK(SCTP_BASE_SYSCTL(sctp_asoc_free_resc_limit), SCTPCTL_ASOC_RESOURCE_MIN, SCTPCTL_ASOC_RESOURCE_MAX);
1264 		RANGECHK(SCTP_BASE_SYSCTL(sctp_heartbeat_interval_default), SCTPCTL_HEARTBEAT_INTERVAL_MIN, SCTPCTL_HEARTBEAT_INTERVAL_MAX);
1265 		RANGECHK(SCTP_BASE_SYSCTL(sctp_pmtu_raise_time_default), SCTPCTL_PMTU_RAISE_TIME_MIN, SCTPCTL_PMTU_RAISE_TIME_MAX);
1266 		RANGECHK(SCTP_BASE_SYSCTL(sctp_shutdown_guard_time_default), SCTPCTL_SHUTDOWN_GUARD_TIME_MIN, SCTPCTL_SHUTDOWN_GUARD_TIME_MAX);
1267 		RANGECHK(SCTP_BASE_SYSCTL(sctp_secret_lifetime_default), SCTPCTL_SECRET_LIFETIME_MIN, SCTPCTL_SECRET_LIFETIME_MAX);
1268 		RANGECHK(SCTP_BASE_SYSCTL(sctp_rto_max_default), SCTPCTL_RTO_MAX_MIN, SCTPCTL_RTO_MAX_MAX);
1269 		RANGECHK(SCTP_BASE_SYSCTL(sctp_rto_min_default), SCTPCTL_RTO_MIN_MIN, SCTPCTL_RTO_MIN_MAX);
1270 		RANGECHK(SCTP_BASE_SYSCTL(sctp_rto_initial_default), SCTPCTL_RTO_INITIAL_MIN, SCTPCTL_RTO_INITIAL_MAX);
1271 		RANGECHK(SCTP_BASE_SYSCTL(sctp_init_rto_max_default), SCTPCTL_INIT_RTO_MAX_MIN, SCTPCTL_INIT_RTO_MAX_MAX);
1272 		RANGECHK(SCTP_BASE_SYSCTL(sctp_valid_cookie_life_default), SCTPCTL_VALID_COOKIE_LIFE_MIN, SCTPCTL_VALID_COOKIE_LIFE_MAX);
1273 		RANGECHK(SCTP_BASE_SYSCTL(sctp_init_rtx_max_default), SCTPCTL_INIT_RTX_MAX_MIN, SCTPCTL_INIT_RTX_MAX_MAX);
1274 		RANGECHK(SCTP_BASE_SYSCTL(sctp_assoc_rtx_max_default), SCTPCTL_ASSOC_RTX_MAX_MIN, SCTPCTL_ASSOC_RTX_MAX_MAX);
1275 		RANGECHK(SCTP_BASE_SYSCTL(sctp_path_rtx_max_default), SCTPCTL_PATH_RTX_MAX_MIN, SCTPCTL_PATH_RTX_MAX_MAX);
1276 		RANGECHK(SCTP_BASE_SYSCTL(sctp_path_pf_threshold), SCTPCTL_PATH_PF_THRESHOLD_MIN, SCTPCTL_PATH_PF_THRESHOLD_MAX);
1277 		RANGECHK(SCTP_BASE_SYSCTL(sctp_add_more_threshold), SCTPCTL_ADD_MORE_ON_OUTPUT_MIN, SCTPCTL_ADD_MORE_ON_OUTPUT_MAX);
1278 		RANGECHK(SCTP_BASE_SYSCTL(sctp_nr_incoming_streams_default), SCTPCTL_INCOMING_STREAMS_MIN, SCTPCTL_INCOMING_STREAMS_MAX);
1279 		RANGECHK(SCTP_BASE_SYSCTL(sctp_nr_outgoing_streams_default), SCTPCTL_OUTGOING_STREAMS_MIN, SCTPCTL_OUTGOING_STREAMS_MAX);
1280 		RANGECHK(SCTP_BASE_SYSCTL(sctp_cmt_on_off), SCTPCTL_CMT_ON_OFF_MIN, SCTPCTL_CMT_ON_OFF_MAX);
1281 		RANGECHK(SCTP_BASE_SYSCTL(sctp_cmt_use_dac), SCTPCTL_CMT_USE_DAC_MIN, SCTPCTL_CMT_USE_DAC_MAX);
1282 		RANGECHK(SCTP_BASE_SYSCTL(sctp_use_cwnd_based_maxburst), SCTPCTL_CWND_MAXBURST_MIN, SCTPCTL_CWND_MAXBURST_MAX);
1283 		RANGECHK(SCTP_BASE_SYSCTL(sctp_nat_friendly), SCTPCTL_NAT_FRIENDLY_MIN, SCTPCTL_NAT_FRIENDLY_MAX);
1284 		RANGECHK(SCTP_BASE_SYSCTL(sctp_L2_abc_variable), SCTPCTL_ABC_L_VAR_MIN, SCTPCTL_ABC_L_VAR_MAX);
1285 		RANGECHK(SCTP_BASE_SYSCTL(sctp_mbuf_threshold_count), SCTPCTL_MAX_CHAINED_MBUFS_MIN, SCTPCTL_MAX_CHAINED_MBUFS_MAX);
1286 		RANGECHK(SCTP_BASE_SYSCTL(sctp_do_drain), SCTPCTL_DO_SCTP_DRAIN_MIN, SCTPCTL_DO_SCTP_DRAIN_MAX);
1287 		RANGECHK(SCTP_BASE_SYSCTL(sctp_hb_maxburst), SCTPCTL_HB_MAX_BURST_MIN, SCTPCTL_HB_MAX_BURST_MAX);
1288 		RANGECHK(SCTP_BASE_SYSCTL(sctp_abort_if_one_2_one_hits_limit), SCTPCTL_ABORT_AT_LIMIT_MIN, SCTPCTL_ABORT_AT_LIMIT_MAX);
1289 		RANGECHK(SCTP_BASE_SYSCTL(sctp_min_residual), SCTPCTL_MIN_RESIDUAL_MIN, SCTPCTL_MIN_RESIDUAL_MAX);
1290 		RANGECHK(SCTP_BASE_SYSCTL(sctp_max_retran_chunk), SCTPCTL_MAX_RETRAN_CHUNK_MIN, SCTPCTL_MAX_RETRAN_CHUNK_MAX);
1291 		RANGECHK(SCTP_BASE_SYSCTL(sctp_logging_level), SCTPCTL_LOGGING_LEVEL_MIN, SCTPCTL_LOGGING_LEVEL_MAX);
1292 		RANGECHK(SCTP_BASE_SYSCTL(sctp_default_cc_module), SCTPCTL_DEFAULT_CC_MODULE_MIN, SCTPCTL_DEFAULT_CC_MODULE_MAX);
1293 		RANGECHK(SCTP_BASE_SYSCTL(sctp_default_ss_module), SCTPCTL_DEFAULT_SS_MODULE_MIN, SCTPCTL_DEFAULT_SS_MODULE_MAX);
1294 		RANGECHK(SCTP_BASE_SYSCTL(sctp_default_frag_interleave), SCTPCTL_DEFAULT_FRAG_INTERLEAVE_MIN, SCTPCTL_DEFAULT_FRAG_INTERLEAVE_MAX);
1295 		RANGECHK(SCTP_BASE_SYSCTL(sctp_vtag_time_wait), SCTPCTL_TIME_WAIT_MIN, SCTPCTL_TIME_WAIT_MAX);
1296 		RANGECHK(SCTP_BASE_SYSCTL(sctp_buffer_splitting), SCTPCTL_BUFFER_SPLITTING_MIN, SCTPCTL_BUFFER_SPLITTING_MAX);
1297 		RANGECHK(SCTP_BASE_SYSCTL(sctp_initial_cwnd), SCTPCTL_INITIAL_CWND_MIN, SCTPCTL_INITIAL_CWND_MAX);
1298 		RANGECHK(SCTP_BASE_SYSCTL(sctp_rttvar_bw), SCTPCTL_RTTVAR_BW_MIN, SCTPCTL_RTTVAR_BW_MAX);
1299 		RANGECHK(SCTP_BASE_SYSCTL(sctp_rttvar_rtt), SCTPCTL_RTTVAR_RTT_MIN, SCTPCTL_RTTVAR_RTT_MAX);
1300 		RANGECHK(SCTP_BASE_SYSCTL(sctp_rttvar_eqret), SCTPCTL_RTTVAR_EQRET_MIN, SCTPCTL_RTTVAR_EQRET_MAX);
1301 		RANGECHK(SCTP_BASE_SYSCTL(sctp_steady_step), SCTPCTL_RTTVAR_STEADYS_MIN, SCTPCTL_RTTVAR_STEADYS_MAX);
1302 		RANGECHK(SCTP_BASE_SYSCTL(sctp_use_dccc_ecn), SCTPCTL_RTTVAR_DCCCECN_MIN, SCTPCTL_RTTVAR_DCCCECN_MAX);
1303 		RANGECHK(SCTP_BASE_SYSCTL(sctp_mobility_base), SCTPCTL_MOBILITY_BASE_MIN, SCTPCTL_MOBILITY_BASE_MAX);
1304 		RANGECHK(SCTP_BASE_SYSCTL(sctp_mobility_fasthandoff), SCTPCTL_MOBILITY_FASTHANDOFF_MIN, SCTPCTL_MOBILITY_FASTHANDOFF_MAX);
1305 		RANGECHK(SCTP_BASE_SYSCTL(sctp_enable_sack_immediately), SCTPCTL_SACK_IMMEDIATELY_ENABLE_MIN, SCTPCTL_SACK_IMMEDIATELY_ENABLE_MAX);
1306 		RANGECHK(SCTP_BASE_SYSCTL(sctp_inits_include_nat_friendly), SCTPCTL_NAT_FRIENDLY_INITS_MIN, SCTPCTL_NAT_FRIENDLY_INITS_MAX);
1307 		RANGECHK(SCTP_BASE_SYSCTL(sctp_blackhole), SCTPCTL_BLACKHOLE_MIN, SCTPCTL_BLACKHOLE_MAX);
1308 		RANGECHK(SCTP_BASE_SYSCTL(sctp_sendall_limit), SCTPCTL_SENDALL_LIMIT_MIN, SCTPCTL_SENDALL_LIMIT_MAX);
1309 		RANGECHK(SCTP_BASE_SYSCTL(sctp_diag_info_code), SCTPCTL_DIAG_INFO_CODE_MIN, SCTPCTL_DIAG_INFO_CODE_MAX);
1310 #ifdef SCTP_DEBUG
1311 		RANGECHK(SCTP_BASE_SYSCTL(sctp_debug_on), SCTPCTL_DEBUG_MIN, SCTPCTL_DEBUG_MAX);
1312 #endif
1313 	}
1314 	return (error);
1315 }
1316 
1317 void
sysctl_setup_sctp(void)1318 sysctl_setup_sctp(void)
1319 {
1320 	sysctl_add_oid(&sysctl_oid_top, "sendspace", CTLTYPE_INT|CTLFLAG_RW,
1321 	    &SCTP_BASE_SYSCTL(sctp_sendspace), 0, sctp_sysctl_handle_int,
1322 	    SCTPCTL_MAXDGRAM_DESC);
1323 
1324 	sysctl_add_oid(&sysctl_oid_top, "recvspace", CTLTYPE_INT|CTLFLAG_RW,
1325 	    &SCTP_BASE_SYSCTL(sctp_recvspace), 0, sctp_sysctl_handle_int,
1326 	    SCTPCTL_RECVSPACE_DESC);
1327 
1328 	sysctl_add_oid(&sysctl_oid_top, "auto_asconf", CTLTYPE_INT|CTLFLAG_RW,
1329 	    &SCTP_BASE_SYSCTL(sctp_auto_asconf), 0, sctp_sysctl_handle_int,
1330 	    SCTPCTL_AUTOASCONF_DESC);
1331 
1332 	sysctl_add_oid(&sysctl_oid_top, "ecn_enable", CTLTYPE_INT|CTLFLAG_RW,
1333 	    &SCTP_BASE_SYSCTL(sctp_ecn_enable), 0, sctp_sysctl_handle_int,
1334 	    SCTPCTL_ECN_ENABLE_DESC);
1335 
1336 	sysctl_add_oid(&sysctl_oid_top, "pr_enable", CTLTYPE_INT|CTLFLAG_RW,
1337 	    &SCTP_BASE_SYSCTL(sctp_pr_enable), 0, sctp_sysctl_handle_int,
1338 	    SCTPCTL_PR_ENABLE_DESC);
1339 
1340 	sysctl_add_oid(&sysctl_oid_top, "auth_enable", CTLTYPE_INT|CTLFLAG_RW,
1341 	    &SCTP_BASE_SYSCTL(sctp_auth_enable), 0, sctp_sysctl_handle_auth,
1342 	    SCTPCTL_AUTH_ENABLE_DESC);
1343 
1344 	sysctl_add_oid(&sysctl_oid_top, "asconf_enable", CTLTYPE_INT|CTLFLAG_RW,
1345 	    &SCTP_BASE_SYSCTL(sctp_asconf_enable), 0, sctp_sysctl_handle_asconf,
1346 	    SCTPCTL_ASCONF_ENABLE_DESC);
1347 
1348 	sysctl_add_oid(&sysctl_oid_top, "reconfig_enable", CTLTYPE_INT|CTLFLAG_RW,
1349 	    &SCTP_BASE_SYSCTL(sctp_reconfig_enable), 0, sctp_sysctl_handle_int,
1350 	    SCTPCTL_RECONFIG_ENABLE_DESC);
1351 
1352 	sysctl_add_oid(&sysctl_oid_top, "nrsack_enable", CTLTYPE_INT|CTLFLAG_RW,
1353 	    &SCTP_BASE_SYSCTL(sctp_nrsack_enable), 0, sctp_sysctl_handle_int,
1354 	    SCTPCTL_NRSACK_ENABLE_DESC);
1355 
1356 	sysctl_add_oid(&sysctl_oid_top, "pktdrop_enable", CTLTYPE_INT|CTLFLAG_RW,
1357 	    &SCTP_BASE_SYSCTL(sctp_pktdrop_enable), 0, sctp_sysctl_handle_int,
1358 	    SCTPCTL_PKTDROP_ENABLE_DESC);
1359 
1360 	sysctl_add_oid(&sysctl_oid_top, "loopback_nocsum", CTLTYPE_INT|CTLFLAG_RW,
1361 	    &SCTP_BASE_SYSCTL(sctp_no_csum_on_loopback), 0, sctp_sysctl_handle_int,
1362 	    SCTPCTL_LOOPBACK_NOCSUM_DESC);
1363 
1364 	sysctl_add_oid(&sysctl_oid_top, "peer_chkoh", CTLTYPE_INT|CTLFLAG_RW,
1365 	    &SCTP_BASE_SYSCTL(sctp_peer_chunk_oh), 0, sctp_sysctl_handle_int,
1366 	    SCTPCTL_PEER_CHKOH_DESC);
1367 
1368 	sysctl_add_oid(&sysctl_oid_top, "maxburst", CTLTYPE_INT|CTLFLAG_RW,
1369 	    &SCTP_BASE_SYSCTL(sctp_max_burst_default), 0, sctp_sysctl_handle_int,
1370 	    SCTPCTL_MAXBURST_DESC);
1371 
1372 	sysctl_add_oid(&sysctl_oid_top, "fr_maxburst", CTLTYPE_INT|CTLFLAG_RW,
1373 	    &SCTP_BASE_SYSCTL(sctp_fr_max_burst_default), 0, sctp_sysctl_handle_int,
1374 	    SCTPCTL_FRMAXBURST_DESC);
1375 
1376 	sysctl_add_oid(&sysctl_oid_top, "maxchunks", CTLTYPE_INT|CTLFLAG_RW,
1377 	    &SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue), 0, sctp_sysctl_handle_int,
1378 	    SCTPCTL_MAXCHUNKS_DESC);
1379 
1380 	sysctl_add_oid(&sysctl_oid_top, "tcbhashsize", CTLTYPE_INT|CTLFLAG_RW,
1381 	    &SCTP_BASE_SYSCTL(sctp_hashtblsize), 0, sctp_sysctl_handle_int,
1382 	    SCTPCTL_TCBHASHSIZE_DESC);
1383 
1384 	sysctl_add_oid(&sysctl_oid_top, "pcbhashsize", CTLTYPE_INT|CTLFLAG_RW,
1385 	    &SCTP_BASE_SYSCTL(sctp_pcbtblsize), 0, sctp_sysctl_handle_int,
1386 	    SCTPCTL_PCBHASHSIZE_DESC);
1387 
1388 	sysctl_add_oid(&sysctl_oid_top, "min_split_point", CTLTYPE_INT|CTLFLAG_RW,
1389 	    &SCTP_BASE_SYSCTL(sctp_min_split_point), 0, sctp_sysctl_handle_int,
1390 	    SCTPCTL_MIN_SPLIT_POINT_DESC);
1391 
1392 	sysctl_add_oid(&sysctl_oid_top, "chunkscale", CTLTYPE_INT|CTLFLAG_RW,
1393 	    &SCTP_BASE_SYSCTL(sctp_chunkscale), 0, sctp_sysctl_handle_int,
1394 	    SCTPCTL_CHUNKSCALE_DESC);
1395 
1396 	sysctl_add_oid(&sysctl_oid_top, "delayed_sack_time", CTLTYPE_INT|CTLFLAG_RW,
1397 	    &SCTP_BASE_SYSCTL(sctp_delayed_sack_time_default), 0, sctp_sysctl_handle_int,
1398 	    SCTPCTL_DELAYED_SACK_TIME_DESC);
1399 
1400 	sysctl_add_oid(&sysctl_oid_top, "sack_freq", CTLTYPE_INT|CTLFLAG_RW,
1401 	    &SCTP_BASE_SYSCTL(sctp_sack_freq_default), 0, sctp_sysctl_handle_int,
1402 	    SCTPCTL_SACK_FREQ_DESC);
1403 
1404 	sysctl_add_oid(&sysctl_oid_top, "sys_resource", CTLTYPE_INT|CTLFLAG_RW,
1405 	    &SCTP_BASE_SYSCTL(sctp_system_free_resc_limit), 0, sctp_sysctl_handle_int,
1406 	    SCTPCTL_SYS_RESOURCE_DESC);
1407 
1408 	sysctl_add_oid(&sysctl_oid_top, "asoc_resource", CTLTYPE_INT|CTLFLAG_RW,
1409 	    &SCTP_BASE_SYSCTL(sctp_asoc_free_resc_limit), 0, sctp_sysctl_handle_int,
1410 	    SCTPCTL_ASOC_RESOURCE_DESC);
1411 
1412 	sysctl_add_oid(&sysctl_oid_top, "heartbeat_interval", CTLTYPE_INT|CTLFLAG_RW,
1413 	    &SCTP_BASE_SYSCTL(sctp_heartbeat_interval_default), 0, sctp_sysctl_handle_int,
1414 	    SCTPCTL_HEARTBEAT_INTERVAL_DESC);
1415 
1416 	sysctl_add_oid(&sysctl_oid_top, "pmtu_raise_time", CTLTYPE_INT|CTLFLAG_RW,
1417 	    &SCTP_BASE_SYSCTL(sctp_pmtu_raise_time_default), 0, sctp_sysctl_handle_int,
1418 	    SCTPCTL_PMTU_RAISE_TIME_DESC);
1419 
1420 	sysctl_add_oid(&sysctl_oid_top, "shutdown_guard_time", CTLTYPE_INT|CTLFLAG_RW,
1421 	    &SCTP_BASE_SYSCTL(sctp_shutdown_guard_time_default), 0, sctp_sysctl_handle_int,
1422 	    SCTPCTL_SHUTDOWN_GUARD_TIME_DESC);
1423 
1424 	sysctl_add_oid(&sysctl_oid_top, "secret_lifetime", CTLTYPE_INT|CTLFLAG_RW,
1425 	    &SCTP_BASE_SYSCTL(sctp_secret_lifetime_default), 0, sctp_sysctl_handle_int,
1426 	    SCTPCTL_SECRET_LIFETIME_DESC);
1427 
1428 	sysctl_add_oid(&sysctl_oid_top, "rto_max", CTLTYPE_INT|CTLFLAG_RW,
1429 	    &SCTP_BASE_SYSCTL(sctp_rto_max_default), 0, sctp_sysctl_handle_int,
1430 	    SCTPCTL_RTO_MAX_DESC);
1431 
1432 	sysctl_add_oid(&sysctl_oid_top, "rto_min", CTLTYPE_INT|CTLFLAG_RW,
1433 	    &SCTP_BASE_SYSCTL(sctp_rto_min_default), 0, sctp_sysctl_handle_int,
1434 	    SCTPCTL_RTO_MIN_DESC);
1435 
1436 	sysctl_add_oid(&sysctl_oid_top, "rto_initial", CTLTYPE_INT|CTLFLAG_RW,
1437 	    &SCTP_BASE_SYSCTL(sctp_rto_initial_default), 0, sctp_sysctl_handle_int,
1438 	    SCTPCTL_RTO_INITIAL_DESC);
1439 
1440 	sysctl_add_oid(&sysctl_oid_top, "init_rto_max", CTLTYPE_INT|CTLFLAG_RW,
1441 	    &SCTP_BASE_SYSCTL(sctp_init_rto_max_default), 0, sctp_sysctl_handle_int,
1442 	    SCTPCTL_INIT_RTO_MAX_DESC);
1443 
1444 	sysctl_add_oid(&sysctl_oid_top, "valid_cookie_life", CTLTYPE_INT|CTLFLAG_RW,
1445 	    &SCTP_BASE_SYSCTL(sctp_valid_cookie_life_default), 0, sctp_sysctl_handle_int,
1446 	    SCTPCTL_VALID_COOKIE_LIFE_DESC);
1447 
1448 	sysctl_add_oid(&sysctl_oid_top, "init_rtx_max", CTLTYPE_INT|CTLFLAG_RW,
1449 	    &SCTP_BASE_SYSCTL(sctp_init_rtx_max_default), 0, sctp_sysctl_handle_int,
1450 	    SCTPCTL_INIT_RTX_MAX_DESC);
1451 
1452 	sysctl_add_oid(&sysctl_oid_top, "assoc_rtx_max", CTLTYPE_INT|CTLFLAG_RW,
1453 	    &SCTP_BASE_SYSCTL(sctp_assoc_rtx_max_default), 0, sctp_sysctl_handle_int,
1454 	    SCTPCTL_ASSOC_RTX_MAX_DESC);
1455 
1456 	sysctl_add_oid(&sysctl_oid_top, "path_rtx_max", CTLTYPE_INT|CTLFLAG_RW,
1457 	    &SCTP_BASE_SYSCTL(sctp_path_rtx_max_default), 0, sctp_sysctl_handle_int,
1458 	    SCTPCTL_PATH_RTX_MAX_DESC);
1459 
1460 	sysctl_add_oid(&sysctl_oid_top, "path_pf_threshold", CTLTYPE_INT|CTLFLAG_RW,
1461 	    &SCTP_BASE_SYSCTL(sctp_path_pf_threshold), 0, sctp_sysctl_handle_int,
1462 	    SCTPCTL_PATH_PF_THRESHOLD_DESC);
1463 
1464 	sysctl_add_oid(&sysctl_oid_top, "add_more_on_output", CTLTYPE_INT|CTLFLAG_RW,
1465 	    &SCTP_BASE_SYSCTL(sctp_add_more_threshold), 0, sctp_sysctl_handle_int,
1466 	    SCTPCTL_ADD_MORE_ON_OUTPUT_DESC);
1467 
1468 	sysctl_add_oid(&sysctl_oid_top, "incoming_streams", CTLTYPE_INT|CTLFLAG_RW,
1469 	    &SCTP_BASE_SYSCTL(sctp_nr_incoming_streams_default), 0, sctp_sysctl_handle_int,
1470 	    SCTPCTL_INCOMING_STREAMS_DESC);
1471 
1472 	sysctl_add_oid(&sysctl_oid_top, "outgoing_streams", CTLTYPE_INT|CTLFLAG_RW,
1473 	    &SCTP_BASE_SYSCTL(sctp_nr_outgoing_streams_default), 0, sctp_sysctl_handle_int,
1474 	    SCTPCTL_OUTGOING_STREAMS_DESC);
1475 
1476 	sysctl_add_oid(&sysctl_oid_top, "cmt_on_off", CTLTYPE_INT|CTLFLAG_RW,
1477 	    &SCTP_BASE_SYSCTL(sctp_cmt_on_off), 0, sctp_sysctl_handle_int,
1478 	    SCTPCTL_CMT_ON_OFF_DESC);
1479 
1480 	sysctl_add_oid(&sysctl_oid_top, "cmt_use_dac", CTLTYPE_INT|CTLFLAG_RW,
1481 	    &SCTP_BASE_SYSCTL(sctp_cmt_use_dac), 0, sctp_sysctl_handle_int,
1482 	    SCTPCTL_CMT_USE_DAC_DESC);
1483 
1484 	sysctl_add_oid(&sysctl_oid_top, "cwnd_maxburst", CTLTYPE_INT|CTLFLAG_RW,
1485 	    &SCTP_BASE_SYSCTL(sctp_use_cwnd_based_maxburst), 0, sctp_sysctl_handle_int,
1486 	    SCTPCTL_CWND_MAXBURST_DESC);
1487 
1488 	sysctl_add_oid(&sysctl_oid_top, "nat_friendly", CTLTYPE_INT|CTLFLAG_RW,
1489 	    &SCTP_BASE_SYSCTL(sctp_nat_friendly), 0, sctp_sysctl_handle_int,
1490 	    SCTPCTL_NAT_FRIENDLY_DESC);
1491 
1492 	sysctl_add_oid(&sysctl_oid_top, "abc_l_var", CTLTYPE_INT|CTLFLAG_RW,
1493 	    &SCTP_BASE_SYSCTL(sctp_L2_abc_variable), 0, sctp_sysctl_handle_int,
1494 	    SCTPCTL_ABC_L_VAR_DESC);
1495 
1496 	sysctl_add_oid(&sysctl_oid_top, "max_chained_mbufs", CTLTYPE_INT|CTLFLAG_RW,
1497 	    &SCTP_BASE_SYSCTL(sctp_mbuf_threshold_count), 0, sctp_sysctl_handle_int,
1498 	    SCTPCTL_MAX_CHAINED_MBUFS_DESC);
1499 
1500 	sysctl_add_oid(&sysctl_oid_top, "do_sctp_drain", CTLTYPE_INT|CTLFLAG_RW,
1501 	    &SCTP_BASE_SYSCTL(sctp_do_drain), 0, sctp_sysctl_handle_int,
1502 	    SCTPCTL_DO_SCTP_DRAIN_DESC);
1503 
1504 	sysctl_add_oid(&sysctl_oid_top, "hb_max_burst", CTLTYPE_INT|CTLFLAG_RW,
1505 	    &SCTP_BASE_SYSCTL(sctp_hb_maxburst), 0, sctp_sysctl_handle_int,
1506 	    SCTPCTL_HB_MAX_BURST_DESC);
1507 
1508 	sysctl_add_oid(&sysctl_oid_top, "abort_at_limit", CTLTYPE_INT|CTLFLAG_RW,
1509 	    &SCTP_BASE_SYSCTL(sctp_abort_if_one_2_one_hits_limit), 0, sctp_sysctl_handle_int,
1510 	    SCTPCTL_ABORT_AT_LIMIT_DESC);
1511 
1512 	sysctl_add_oid(&sysctl_oid_top, "min_residual", CTLTYPE_INT|CTLFLAG_RW,
1513 	    &SCTP_BASE_SYSCTL(sctp_min_residual), 0, sctp_sysctl_handle_int,
1514 	    SCTPCTL_MIN_RESIDUAL_DESC);
1515 
1516 	sysctl_add_oid(&sysctl_oid_top, "max_retran_chunk", CTLTYPE_INT|CTLFLAG_RW,
1517 	    &SCTP_BASE_SYSCTL(sctp_max_retran_chunk), 0, sctp_sysctl_handle_int,
1518 	    SCTPCTL_MAX_RETRAN_CHUNK_DESC);
1519 
1520 	sysctl_add_oid(&sysctl_oid_top, "log_level", CTLTYPE_INT|CTLFLAG_RW,
1521 	    &SCTP_BASE_SYSCTL(sctp_logging_level), 0, sctp_sysctl_handle_int,
1522 	    SCTPCTL_LOGGING_LEVEL_DESC);
1523 
1524 	sysctl_add_oid(&sysctl_oid_top, "default_cc_module", CTLTYPE_INT|CTLFLAG_RW,
1525 	    &SCTP_BASE_SYSCTL(sctp_default_cc_module), 0, sctp_sysctl_handle_int,
1526 	    SCTPCTL_DEFAULT_CC_MODULE_DESC);
1527 
1528 	sysctl_add_oid(&sysctl_oid_top, "default_ss_module", CTLTYPE_INT|CTLFLAG_RW,
1529 	    &SCTP_BASE_SYSCTL(sctp_default_ss_module), 0, sctp_sysctl_handle_int,
1530 	    SCTPCTL_DEFAULT_SS_MODULE_DESC);
1531 
1532 	sysctl_add_oid(&sysctl_oid_top, "default_frag_interleave", CTLTYPE_INT|CTLFLAG_RW,
1533 	    &SCTP_BASE_SYSCTL(sctp_default_frag_interleave), 0, sctp_sysctl_handle_int,
1534 	    SCTPCTL_DEFAULT_FRAG_INTERLEAVE_DESC);
1535 
1536 	sysctl_add_oid(&sysctl_oid_top, "mobility_base", CTLTYPE_INT|CTLFLAG_RW,
1537 	    &SCTP_BASE_SYSCTL(sctp_mobility_base), 0, sctp_sysctl_handle_int,
1538 	    SCTPCTL_MOBILITY_BASE_DESC);
1539 
1540 	sysctl_add_oid(&sysctl_oid_top, "mobility_fasthandoff", CTLTYPE_INT|CTLFLAG_RW,
1541 	    &SCTP_BASE_SYSCTL(sctp_mobility_fasthandoff), 0, sctp_sysctl_handle_int,
1542 	    SCTPCTL_MOBILITY_FASTHANDOFF_DESC);
1543 
1544 #if defined(SCTP_LOCAL_TRACE_BUF)
1545 	sysctl_add_oid(&sysctl_oid_top, "sctp_log", CTLTYPE_STRUCT|CTLFLAG_RD,
1546 	    SCTP_BASE_SYSCTL(sctp_log), sizeof(struct sctp_log), NULL,
1547 	    "SCTP logging (struct sctp_log)");
1548 
1549 	sysctl_add_oid(&sysctl_oid_top, "clear_trace", CTLTYPE_INT|CTLFLAG_WR,
1550 	    NULL, 0, sctp_sysctl_handle_trace_log_clear,
1551 	    "Clear SCTP Logging buffer");
1552 #endif
1553 
1554 	sysctl_add_oid(&sysctl_oid_top, "udp_tunneling_port", CTLTYPE_INT|CTLFLAG_RW,
1555 	    &SCTP_BASE_SYSCTL(sctp_udp_tunneling_port), 0, sctp_sysctl_handle_udp_tunneling,
1556 	    SCTPCTL_UDP_TUNNELING_PORT_DESC);
1557 
1558 	sysctl_add_oid(&sysctl_oid_top, "enable_sack_immediately", CTLTYPE_INT|CTLFLAG_RW,
1559 	    &SCTP_BASE_SYSCTL(sctp_enable_sack_immediately), 0, sctp_sysctl_handle_int,
1560 	    SCTPCTL_SACK_IMMEDIATELY_ENABLE_DESC);
1561 
1562 	sysctl_add_oid(&sysctl_oid_top, "nat_friendly_init", CTLTYPE_INT|CTLFLAG_RW,
1563 	    &SCTP_BASE_SYSCTL(sctp_inits_include_nat_friendly), 0, sctp_sysctl_handle_int,
1564 	    SCTPCTL_NAT_FRIENDLY_DESC);
1565 
1566 	sysctl_add_oid(&sysctl_oid_top, "vtag_time_wait", CTLTYPE_INT|CTLFLAG_RW,
1567 	    &SCTP_BASE_SYSCTL(sctp_vtag_time_wait), 0, sctp_sysctl_handle_int,
1568 	    SCTPCTL_TIME_WAIT_DESC);
1569 
1570 	sysctl_add_oid(&sysctl_oid_top, "buffer_splitting", CTLTYPE_INT|CTLFLAG_RW,
1571 	    &SCTP_BASE_SYSCTL(sctp_buffer_splitting), 0, sctp_sysctl_handle_int,
1572 	    SCTPCTL_BUFFER_SPLITTING_DESC);
1573 
1574 	sysctl_add_oid(&sysctl_oid_top, "initial_cwnd", CTLTYPE_INT|CTLFLAG_RW,
1575 	    &SCTP_BASE_SYSCTL(sctp_initial_cwnd), 0, sctp_sysctl_handle_int,
1576 	    SCTPCTL_INITIAL_CWND_DESC);
1577 
1578 	sysctl_add_oid(&sysctl_oid_top, "rttvar_bw", CTLTYPE_INT|CTLFLAG_RW,
1579 	    &SCTP_BASE_SYSCTL(sctp_rttvar_bw), 0, sctp_sysctl_handle_int,
1580 	    SCTPCTL_RTTVAR_BW_DESC);
1581 
1582 	sysctl_add_oid(&sysctl_oid_top, "rttvar_rtt", CTLTYPE_INT|CTLFLAG_RW,
1583 	    &SCTP_BASE_SYSCTL(sctp_rttvar_rtt), 0, sctp_sysctl_handle_int,
1584 	    SCTPCTL_RTTVAR_RTT_DESC);
1585 
1586 	sysctl_add_oid(&sysctl_oid_top, "rttvar_eqret", CTLTYPE_INT|CTLFLAG_RW,
1587 	    &SCTP_BASE_SYSCTL(sctp_rttvar_eqret), 0, sctp_sysctl_handle_int,
1588 	    SCTPCTL_RTTVAR_EQRET_DESC);
1589 
1590 	sysctl_add_oid(&sysctl_oid_top, "rttvar_steady_step", CTLTYPE_INT|CTLFLAG_RW,
1591 	    &SCTP_BASE_SYSCTL(sctp_steady_step), 0, sctp_sysctl_handle_int,
1592 	    SCTPCTL_RTTVAR_STEADYS_DESC);
1593 
1594 	sysctl_add_oid(&sysctl_oid_top, "use_dcccecn", CTLTYPE_INT|CTLFLAG_RW,
1595 	    &SCTP_BASE_SYSCTL(sctp_use_dccc_ecn), 0, sctp_sysctl_handle_int,
1596 	    SCTPCTL_RTTVAR_DCCCECN_DESC);
1597 
1598 	sysctl_add_oid(&sysctl_oid_top, "blackhole", CTLTYPE_INT|CTLFLAG_RW,
1599 	    &SCTP_BASE_SYSCTL(sctp_blackhole), 0, sctp_sysctl_handle_int,
1600 	    SCTPCTL_BLACKHOLE_DESC);
1601 
1602 	sysctl_add_oid(&sysctl_oid_top, "sendall_limit", CTLTYPE_INT|CTLFLAG_RW,
1603 	    &SCTP_BASE_SYSCTL(sctp_sendall_limit), 0, sctp_sysctl_handle_int,
1604 	    SCTPCTL_SENDALL_LIMIT_DESC);
1605 
1606 	sysctl_add_oid(&sysctl_oid_top, "diag_info_code", CTLTYPE_INT|CTLFLAG_RW,
1607 	    &SCTP_BASE_SYSCTL(sctp_diag_info_code), 0, sctp_sysctl_handle_int,
1608 	    SCTPCTL_DIAG_INFO_CODE_DESC);
1609 
1610 #ifdef SCTP_DEBUG
1611 	sysctl_add_oid(&sysctl_oid_top, "debug", CTLTYPE_INT|CTLFLAG_RW,
1612 	    &SCTP_BASE_SYSCTL(sctp_debug_on), 0, sctp_sysctl_handle_int,
1613 	    SCTPCTL_DEBUG_DESC);
1614 #endif
1615 
1616 	sysctl_add_oid(&sysctl_oid_top, "stats", CTLTYPE_STRUCT|CTLFLAG_RW,
1617 	    &SCTP_BASE_STATS, sizeof(SCTP_BASE_STATS), NULL,
1618 	    "SCTP statistics (struct sctp_stat)");
1619 
1620 	sysctl_add_oid(&sysctl_oid_top, "assoclist", CTLTYPE_STRUCT|CTLFLAG_RD,
1621 	    NULL, 0, sctp_assoclist,
1622 	    "List of active SCTP associations");
1623 }
1624 #endif
1625 #endif
1626