xref: /freebsd/sys/netinet/sctp_sysctl.c (revision a521f2116473fbd8c09db395518f060a27d02334)
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 #include <sys/cdefs.h>
36 __FBSDID("$FreeBSD$");
37 
38 #include <netinet/sctp_os.h>
39 #include <netinet/sctp.h>
40 #include <netinet/sctp_constants.h>
41 #include <netinet/sctp_sysctl.h>
42 #include <netinet/sctp_pcb.h>
43 #include <netinet/sctputil.h>
44 #include <netinet/sctp_output.h>
45 #include <sys/smp.h>
46 #include <sys/sysctl.h>
47 
48 FEATURE(sctp, "Stream Control Transmission Protocol");
49 
50 /*
51  * sysctl tunable variables
52  */
53 
54 void
55 sctp_init_sysctls()
56 {
57 	SCTP_BASE_SYSCTL(sctp_sendspace) = SCTPCTL_MAXDGRAM_DEFAULT;
58 	SCTP_BASE_SYSCTL(sctp_recvspace) = SCTPCTL_RECVSPACE_DEFAULT;
59 	SCTP_BASE_SYSCTL(sctp_auto_asconf) = SCTPCTL_AUTOASCONF_DEFAULT;
60 	SCTP_BASE_SYSCTL(sctp_multiple_asconfs) = SCTPCTL_MULTIPLEASCONFS_DEFAULT;
61 	SCTP_BASE_SYSCTL(sctp_ecn_enable) = SCTPCTL_ECN_ENABLE_DEFAULT;
62 	SCTP_BASE_SYSCTL(sctp_pr_enable) = SCTPCTL_PR_ENABLE_DEFAULT;
63 	SCTP_BASE_SYSCTL(sctp_auth_enable) = SCTPCTL_AUTH_ENABLE_DEFAULT;
64 	SCTP_BASE_SYSCTL(sctp_asconf_enable) = SCTPCTL_ASCONF_ENABLE_DEFAULT;
65 	SCTP_BASE_SYSCTL(sctp_reconfig_enable) = SCTPCTL_RECONFIG_ENABLE_DEFAULT;
66 	SCTP_BASE_SYSCTL(sctp_nrsack_enable) = SCTPCTL_NRSACK_ENABLE_DEFAULT;
67 	SCTP_BASE_SYSCTL(sctp_pktdrop_enable) = SCTPCTL_PKTDROP_ENABLE_DEFAULT;
68 	SCTP_BASE_SYSCTL(sctp_peer_chunk_oh) = SCTPCTL_PEER_CHKOH_DEFAULT;
69 	SCTP_BASE_SYSCTL(sctp_max_burst_default) = SCTPCTL_MAXBURST_DEFAULT;
70 	SCTP_BASE_SYSCTL(sctp_fr_max_burst_default) = SCTPCTL_FRMAXBURST_DEFAULT;
71 	SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = SCTPCTL_MAXCHUNKS_DEFAULT;
72 	SCTP_BASE_SYSCTL(sctp_hashtblsize) = SCTPCTL_TCBHASHSIZE_DEFAULT;
73 	SCTP_BASE_SYSCTL(sctp_pcbtblsize) = SCTPCTL_PCBHASHSIZE_DEFAULT;
74 	SCTP_BASE_SYSCTL(sctp_min_split_point) = SCTPCTL_MIN_SPLIT_POINT_DEFAULT;
75 	SCTP_BASE_SYSCTL(sctp_chunkscale) = SCTPCTL_CHUNKSCALE_DEFAULT;
76 	SCTP_BASE_SYSCTL(sctp_delayed_sack_time_default) = SCTPCTL_DELAYED_SACK_TIME_DEFAULT;
77 	SCTP_BASE_SYSCTL(sctp_sack_freq_default) = SCTPCTL_SACK_FREQ_DEFAULT;
78 	SCTP_BASE_SYSCTL(sctp_system_free_resc_limit) = SCTPCTL_SYS_RESOURCE_DEFAULT;
79 	SCTP_BASE_SYSCTL(sctp_asoc_free_resc_limit) = SCTPCTL_ASOC_RESOURCE_DEFAULT;
80 	SCTP_BASE_SYSCTL(sctp_heartbeat_interval_default) = SCTPCTL_HEARTBEAT_INTERVAL_DEFAULT;
81 	SCTP_BASE_SYSCTL(sctp_pmtu_raise_time_default) = SCTPCTL_PMTU_RAISE_TIME_DEFAULT;
82 	SCTP_BASE_SYSCTL(sctp_shutdown_guard_time_default) = SCTPCTL_SHUTDOWN_GUARD_TIME_DEFAULT;
83 	SCTP_BASE_SYSCTL(sctp_secret_lifetime_default) = SCTPCTL_SECRET_LIFETIME_DEFAULT;
84 	SCTP_BASE_SYSCTL(sctp_rto_max_default) = SCTPCTL_RTO_MAX_DEFAULT;
85 	SCTP_BASE_SYSCTL(sctp_rto_min_default) = SCTPCTL_RTO_MIN_DEFAULT;
86 	SCTP_BASE_SYSCTL(sctp_rto_initial_default) = SCTPCTL_RTO_INITIAL_DEFAULT;
87 	SCTP_BASE_SYSCTL(sctp_init_rto_max_default) = SCTPCTL_INIT_RTO_MAX_DEFAULT;
88 	SCTP_BASE_SYSCTL(sctp_valid_cookie_life_default) = SCTPCTL_VALID_COOKIE_LIFE_DEFAULT;
89 	SCTP_BASE_SYSCTL(sctp_init_rtx_max_default) = SCTPCTL_INIT_RTX_MAX_DEFAULT;
90 	SCTP_BASE_SYSCTL(sctp_assoc_rtx_max_default) = SCTPCTL_ASSOC_RTX_MAX_DEFAULT;
91 	SCTP_BASE_SYSCTL(sctp_path_rtx_max_default) = SCTPCTL_PATH_RTX_MAX_DEFAULT;
92 	SCTP_BASE_SYSCTL(sctp_path_pf_threshold) = SCTPCTL_PATH_PF_THRESHOLD_DEFAULT;
93 	SCTP_BASE_SYSCTL(sctp_add_more_threshold) = SCTPCTL_ADD_MORE_ON_OUTPUT_DEFAULT;
94 	SCTP_BASE_SYSCTL(sctp_nr_incoming_streams_default) = SCTPCTL_INCOMING_STREAMS_DEFAULT;
95 	SCTP_BASE_SYSCTL(sctp_nr_outgoing_streams_default) = SCTPCTL_OUTGOING_STREAMS_DEFAULT;
96 	SCTP_BASE_SYSCTL(sctp_cmt_on_off) = SCTPCTL_CMT_ON_OFF_DEFAULT;
97 	SCTP_BASE_SYSCTL(sctp_cmt_use_dac) = SCTPCTL_CMT_USE_DAC_DEFAULT;
98 	SCTP_BASE_SYSCTL(sctp_use_cwnd_based_maxburst) = SCTPCTL_CWND_MAXBURST_DEFAULT;
99 	SCTP_BASE_SYSCTL(sctp_nat_friendly) = SCTPCTL_NAT_FRIENDLY_DEFAULT;
100 	SCTP_BASE_SYSCTL(sctp_L2_abc_variable) = SCTPCTL_ABC_L_VAR_DEFAULT;
101 	SCTP_BASE_SYSCTL(sctp_mbuf_threshold_count) = SCTPCTL_MAX_CHAINED_MBUFS_DEFAULT;
102 	SCTP_BASE_SYSCTL(sctp_do_drain) = SCTPCTL_DO_SCTP_DRAIN_DEFAULT;
103 	SCTP_BASE_SYSCTL(sctp_hb_maxburst) = SCTPCTL_HB_MAX_BURST_DEFAULT;
104 	SCTP_BASE_SYSCTL(sctp_abort_if_one_2_one_hits_limit) = SCTPCTL_ABORT_AT_LIMIT_DEFAULT;
105 	SCTP_BASE_SYSCTL(sctp_min_residual) = SCTPCTL_MIN_RESIDUAL_DEFAULT;
106 	SCTP_BASE_SYSCTL(sctp_max_retran_chunk) = SCTPCTL_MAX_RETRAN_CHUNK_DEFAULT;
107 	SCTP_BASE_SYSCTL(sctp_logging_level) = SCTPCTL_LOGGING_LEVEL_DEFAULT;
108 	SCTP_BASE_SYSCTL(sctp_default_cc_module) = SCTPCTL_DEFAULT_CC_MODULE_DEFAULT;
109 	SCTP_BASE_SYSCTL(sctp_default_ss_module) = SCTPCTL_DEFAULT_SS_MODULE_DEFAULT;
110 	SCTP_BASE_SYSCTL(sctp_default_frag_interleave) = SCTPCTL_DEFAULT_FRAG_INTERLEAVE_DEFAULT;
111 	SCTP_BASE_SYSCTL(sctp_mobility_base) = SCTPCTL_MOBILITY_BASE_DEFAULT;
112 	SCTP_BASE_SYSCTL(sctp_mobility_fasthandoff) = SCTPCTL_MOBILITY_FASTHANDOFF_DEFAULT;
113 	SCTP_BASE_SYSCTL(sctp_vtag_time_wait) = SCTPCTL_TIME_WAIT_DEFAULT;
114 	SCTP_BASE_SYSCTL(sctp_buffer_splitting) = SCTPCTL_BUFFER_SPLITTING_DEFAULT;
115 	SCTP_BASE_SYSCTL(sctp_initial_cwnd) = SCTPCTL_INITIAL_CWND_DEFAULT;
116 	SCTP_BASE_SYSCTL(sctp_rttvar_bw) = SCTPCTL_RTTVAR_BW_DEFAULT;
117 	SCTP_BASE_SYSCTL(sctp_rttvar_rtt) = SCTPCTL_RTTVAR_RTT_DEFAULT;
118 	SCTP_BASE_SYSCTL(sctp_rttvar_eqret) = SCTPCTL_RTTVAR_EQRET_DEFAULT;
119 	SCTP_BASE_SYSCTL(sctp_steady_step) = SCTPCTL_RTTVAR_STEADYS_DEFAULT;
120 	SCTP_BASE_SYSCTL(sctp_use_dccc_ecn) = SCTPCTL_RTTVAR_DCCCECN_DEFAULT;
121 	SCTP_BASE_SYSCTL(sctp_blackhole) = SCTPCTL_BLACKHOLE_DEFAULT;
122 	SCTP_BASE_SYSCTL(sctp_sendall_limit) = SCTPCTL_SENDALL_LIMIT_DEFAULT;
123 	SCTP_BASE_SYSCTL(sctp_diag_info_code) = SCTPCTL_DIAG_INFO_CODE_DEFAULT;
124 #if defined(SCTP_LOCAL_TRACE_BUF)
125 	memset(&SCTP_BASE_SYSCTL(sctp_log), 0, sizeof(struct sctp_log));
126 #endif
127 	SCTP_BASE_SYSCTL(sctp_udp_tunneling_port) = SCTPCTL_UDP_TUNNELING_PORT_DEFAULT;
128 	SCTP_BASE_SYSCTL(sctp_enable_sack_immediately) = SCTPCTL_SACK_IMMEDIATELY_ENABLE_DEFAULT;
129 	SCTP_BASE_SYSCTL(sctp_inits_include_nat_friendly) = SCTPCTL_NAT_FRIENDLY_INITS_DEFAULT;
130 #if defined(SCTP_DEBUG)
131 	SCTP_BASE_SYSCTL(sctp_debug_on) = SCTPCTL_DEBUG_DEFAULT;
132 #endif
133 }
134 
135 /* It returns an upper limit. No filtering is done here */
136 static unsigned int
137 sctp_sysctl_number_of_addresses(struct sctp_inpcb *inp)
138 {
139 	unsigned int cnt;
140 	struct sctp_vrf *vrf;
141 	struct sctp_ifn *sctp_ifn;
142 	struct sctp_ifa *sctp_ifa;
143 	struct sctp_laddr *laddr;
144 
145 	cnt = 0;
146 	/* neither Mac OS X nor FreeBSD support mulitple routing functions */
147 	if ((vrf = sctp_find_vrf(inp->def_vrf_id)) == NULL) {
148 		return (0);
149 	}
150 	if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
151 		LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
152 			LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
153 				switch (sctp_ifa->address.sa.sa_family) {
154 #ifdef INET
155 				case AF_INET:
156 #endif
157 #ifdef INET6
158 				case AF_INET6:
159 #endif
160 					cnt++;
161 					break;
162 				default:
163 					break;
164 				}
165 			}
166 		}
167 	} else {
168 		LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
169 			switch (laddr->ifa->address.sa.sa_family) {
170 #ifdef INET
171 			case AF_INET:
172 #endif
173 #ifdef INET6
174 			case AF_INET6:
175 #endif
176 				cnt++;
177 				break;
178 			default:
179 				break;
180 			}
181 		}
182 	}
183 	return (cnt);
184 }
185 
186 static int
187 sctp_sysctl_copy_out_local_addresses(struct sctp_inpcb *inp, struct sctp_tcb *stcb, struct sysctl_req *req)
188 {
189 	struct sctp_ifn *sctp_ifn;
190 	struct sctp_ifa *sctp_ifa;
191 	int loopback_scope, ipv4_local_scope, local_scope, site_scope;
192 	int ipv4_addr_legal, ipv6_addr_legal;
193 	struct sctp_vrf *vrf;
194 	struct xsctp_laddr xladdr;
195 	struct sctp_laddr *laddr;
196 	int error;
197 
198 	/* Turn on all the appropriate scope */
199 	if (stcb) {
200 		/* use association specific values */
201 		loopback_scope = stcb->asoc.scope.loopback_scope;
202 		ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
203 		local_scope = stcb->asoc.scope.local_scope;
204 		site_scope = stcb->asoc.scope.site_scope;
205 		ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
206 		ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
207 	} else {
208 		/* Use generic values for endpoints. */
209 		loopback_scope = 1;
210 		ipv4_local_scope = 1;
211 		local_scope = 1;
212 		site_scope = 1;
213 		if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
214 			ipv6_addr_legal = 1;
215 			if (SCTP_IPV6_V6ONLY(inp)) {
216 				ipv4_addr_legal = 0;
217 			} else {
218 				ipv4_addr_legal = 1;
219 			}
220 		} else {
221 			ipv6_addr_legal = 0;
222 			ipv4_addr_legal = 1;
223 		}
224 	}
225 
226 	/* neither Mac OS X nor FreeBSD support mulitple routing functions */
227 	if ((vrf = sctp_find_vrf(inp->def_vrf_id)) == NULL) {
228 		SCTP_INP_RUNLOCK(inp);
229 		SCTP_INP_INFO_RUNLOCK();
230 		return (-1);
231 	}
232 	if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
233 		LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
234 			if ((loopback_scope == 0) && SCTP_IFN_IS_IFT_LOOP(sctp_ifn))
235 				/* Skip loopback if loopback_scope not set */
236 				continue;
237 			LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
238 				if (stcb) {
239 					/*
240 					 * ignore if blacklisted at
241 					 * association level
242 					 */
243 					if (sctp_is_addr_restricted(stcb, sctp_ifa))
244 						continue;
245 				}
246 				switch (sctp_ifa->address.sa.sa_family) {
247 #ifdef INET
248 				case AF_INET:
249 					if (ipv4_addr_legal) {
250 						struct sockaddr_in *sin;
251 
252 						sin = &sctp_ifa->address.sin;
253 						if (sin->sin_addr.s_addr == 0)
254 							continue;
255 						if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
256 						    &sin->sin_addr) != 0) {
257 							continue;
258 						}
259 						if ((ipv4_local_scope == 0) && (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)))
260 							continue;
261 					} else {
262 						continue;
263 					}
264 					break;
265 #endif
266 #ifdef INET6
267 				case AF_INET6:
268 					if (ipv6_addr_legal) {
269 						struct sockaddr_in6 *sin6;
270 
271 						sin6 = &sctp_ifa->address.sin6;
272 						if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
273 							continue;
274 						if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
275 						    &sin6->sin6_addr) != 0) {
276 							continue;
277 						}
278 						if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
279 							if (local_scope == 0)
280 								continue;
281 						}
282 						if ((site_scope == 0) && (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)))
283 							continue;
284 					} else {
285 						continue;
286 					}
287 					break;
288 #endif
289 				default:
290 					continue;
291 				}
292 				memset((void *)&xladdr, 0, sizeof(struct xsctp_laddr));
293 				memcpy((void *)&xladdr.address, (const void *)&sctp_ifa->address, sizeof(union sctp_sockstore));
294 				SCTP_INP_RUNLOCK(inp);
295 				SCTP_INP_INFO_RUNLOCK();
296 				error = SYSCTL_OUT(req, &xladdr, sizeof(struct xsctp_laddr));
297 				if (error) {
298 					return (error);
299 				} else {
300 					SCTP_INP_INFO_RLOCK();
301 					SCTP_INP_RLOCK(inp);
302 				}
303 			}
304 		}
305 	} else {
306 		LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
307 			/* ignore if blacklisted at association level */
308 			if (stcb && sctp_is_addr_restricted(stcb, laddr->ifa))
309 				continue;
310 			memset((void *)&xladdr, 0, sizeof(struct xsctp_laddr));
311 			memcpy((void *)&xladdr.address, (const void *)&laddr->ifa->address, sizeof(union sctp_sockstore));
312 			xladdr.start_time.tv_sec = (uint32_t)laddr->start_time.tv_sec;
313 			xladdr.start_time.tv_usec = (uint32_t)laddr->start_time.tv_usec;
314 			SCTP_INP_RUNLOCK(inp);
315 			SCTP_INP_INFO_RUNLOCK();
316 			error = SYSCTL_OUT(req, &xladdr, sizeof(struct xsctp_laddr));
317 			if (error) {
318 				return (error);
319 			} else {
320 				SCTP_INP_INFO_RLOCK();
321 				SCTP_INP_RLOCK(inp);
322 			}
323 		}
324 	}
325 	memset((void *)&xladdr, 0, sizeof(struct xsctp_laddr));
326 	xladdr.last = 1;
327 	SCTP_INP_RUNLOCK(inp);
328 	SCTP_INP_INFO_RUNLOCK();
329 	error = SYSCTL_OUT(req, &xladdr, sizeof(struct xsctp_laddr));
330 
331 	if (error) {
332 		return (error);
333 	} else {
334 		SCTP_INP_INFO_RLOCK();
335 		SCTP_INP_RLOCK(inp);
336 		return (0);
337 	}
338 }
339 
340 /*
341  * sysctl functions
342  */
343 static int
344 sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS)
345 {
346 	unsigned int number_of_endpoints;
347 	unsigned int number_of_local_addresses;
348 	unsigned int number_of_associations;
349 	unsigned int number_of_remote_addresses;
350 	unsigned int n;
351 	int error;
352 	struct sctp_inpcb *inp;
353 	struct sctp_tcb *stcb;
354 	struct sctp_nets *net;
355 	struct xsctp_inpcb xinpcb;
356 	struct xsctp_tcb xstcb;
357 	struct xsctp_raddr xraddr;
358 	struct socket *so;
359 
360 	number_of_endpoints = 0;
361 	number_of_local_addresses = 0;
362 	number_of_associations = 0;
363 	number_of_remote_addresses = 0;
364 
365 	SCTP_INP_INFO_RLOCK();
366 	if (req->oldptr == NULL) {
367 		LIST_FOREACH(inp, &SCTP_BASE_INFO(listhead), sctp_list) {
368 			SCTP_INP_RLOCK(inp);
369 			number_of_endpoints++;
370 			number_of_local_addresses += sctp_sysctl_number_of_addresses(inp);
371 			LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
372 				number_of_associations++;
373 				number_of_local_addresses += sctp_sysctl_number_of_addresses(inp);
374 				TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
375 					number_of_remote_addresses++;
376 				}
377 			}
378 			SCTP_INP_RUNLOCK(inp);
379 		}
380 		SCTP_INP_INFO_RUNLOCK();
381 		n = (number_of_endpoints + 1) * sizeof(struct xsctp_inpcb) +
382 		    (number_of_local_addresses + number_of_endpoints + number_of_associations) * sizeof(struct xsctp_laddr) +
383 		    (number_of_associations + number_of_endpoints) * sizeof(struct xsctp_tcb) +
384 		    (number_of_remote_addresses + number_of_associations) * sizeof(struct xsctp_raddr);
385 
386 		/* request some more memory than needed */
387 		req->oldidx = (n + n / 8);
388 		return (0);
389 	}
390 	if (req->newptr != NULL) {
391 		SCTP_INP_INFO_RUNLOCK();
392 		SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_SYSCTL, EPERM);
393 		return (EPERM);
394 	}
395 	memset(&xinpcb, 0, sizeof(xinpcb));
396 	memset(&xstcb, 0, sizeof(xstcb));
397 	memset(&xraddr, 0, sizeof(xraddr));
398 	LIST_FOREACH(inp, &SCTP_BASE_INFO(listhead), sctp_list) {
399 		SCTP_INP_RLOCK(inp);
400 		if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) {
401 			/* if its allgone it is being freed - skip it  */
402 			goto skip;
403 		}
404 		xinpcb.last = 0;
405 		xinpcb.local_port = ntohs(inp->sctp_lport);
406 		xinpcb.flags = inp->sctp_flags;
407 		xinpcb.features = inp->sctp_features;
408 		xinpcb.total_sends = inp->total_sends;
409 		xinpcb.total_recvs = inp->total_recvs;
410 		xinpcb.total_nospaces = inp->total_nospaces;
411 		xinpcb.fragmentation_point = inp->sctp_frag_point;
412 		xinpcb.socket = (uintptr_t)inp->sctp_socket;
413 		so = inp->sctp_socket;
414 		if ((so == NULL) ||
415 		    (!SCTP_IS_LISTENING(inp)) ||
416 		    (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
417 			xinpcb.qlen = 0;
418 			xinpcb.maxqlen = 0;
419 		} else {
420 			xinpcb.qlen = so->sol_qlen;
421 			xinpcb.qlen_old = so->sol_qlen > USHRT_MAX ?
422 			    USHRT_MAX : (uint16_t)so->sol_qlen;
423 			xinpcb.maxqlen = so->sol_qlimit;
424 			xinpcb.maxqlen_old = so->sol_qlimit > USHRT_MAX ?
425 			    USHRT_MAX : (uint16_t)so->sol_qlimit;
426 		}
427 		SCTP_INP_INCR_REF(inp);
428 		SCTP_INP_RUNLOCK(inp);
429 		SCTP_INP_INFO_RUNLOCK();
430 		error = SYSCTL_OUT(req, &xinpcb, sizeof(struct xsctp_inpcb));
431 		if (error) {
432 			SCTP_INP_DECR_REF(inp);
433 			return (error);
434 		}
435 		SCTP_INP_INFO_RLOCK();
436 		SCTP_INP_RLOCK(inp);
437 		error = sctp_sysctl_copy_out_local_addresses(inp, NULL, req);
438 		if (error) {
439 			SCTP_INP_DECR_REF(inp);
440 			return (error);
441 		}
442 		LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
443 			SCTP_TCB_LOCK(stcb);
444 			atomic_add_int(&stcb->asoc.refcnt, 1);
445 			SCTP_TCB_UNLOCK(stcb);
446 			xstcb.last = 0;
447 			xstcb.local_port = ntohs(inp->sctp_lport);
448 			xstcb.remote_port = ntohs(stcb->rport);
449 			if (stcb->asoc.primary_destination != NULL)
450 				xstcb.primary_addr = stcb->asoc.primary_destination->ro._l_addr;
451 			xstcb.heartbeat_interval = stcb->asoc.heart_beat_delay;
452 			xstcb.state = (uint32_t)sctp_map_assoc_state(stcb->asoc.state);
453 			xstcb.assoc_id = sctp_get_associd(stcb);
454 			xstcb.peers_rwnd = stcb->asoc.peers_rwnd;
455 			xstcb.in_streams = stcb->asoc.streamincnt;
456 			xstcb.out_streams = stcb->asoc.streamoutcnt;
457 			xstcb.max_nr_retrans = stcb->asoc.overall_error_count;
458 			xstcb.primary_process = 0;	/* not really supported
459 							 * yet */
460 			xstcb.T1_expireries = stcb->asoc.timoinit + stcb->asoc.timocookie;
461 			xstcb.T2_expireries = stcb->asoc.timoshutdown + stcb->asoc.timoshutdownack;
462 			xstcb.retransmitted_tsns = stcb->asoc.marked_retrans;
463 			xstcb.start_time.tv_sec = (uint32_t)stcb->asoc.start_time.tv_sec;
464 			xstcb.start_time.tv_usec = (uint32_t)stcb->asoc.start_time.tv_usec;
465 			xstcb.discontinuity_time.tv_sec = (uint32_t)stcb->asoc.discontinuity_time.tv_sec;
466 			xstcb.discontinuity_time.tv_usec = (uint32_t)stcb->asoc.discontinuity_time.tv_usec;
467 			xstcb.total_sends = stcb->total_sends;
468 			xstcb.total_recvs = stcb->total_recvs;
469 			xstcb.local_tag = stcb->asoc.my_vtag;
470 			xstcb.remote_tag = stcb->asoc.peer_vtag;
471 			xstcb.initial_tsn = stcb->asoc.init_seq_number;
472 			xstcb.highest_tsn = stcb->asoc.sending_seq - 1;
473 			xstcb.cumulative_tsn = stcb->asoc.last_acked_seq;
474 			xstcb.cumulative_tsn_ack = stcb->asoc.cumulative_tsn;
475 			xstcb.mtu = stcb->asoc.smallest_mtu;
476 			xstcb.refcnt = stcb->asoc.refcnt;
477 			SCTP_INP_RUNLOCK(inp);
478 			SCTP_INP_INFO_RUNLOCK();
479 			error = SYSCTL_OUT(req, &xstcb, sizeof(struct xsctp_tcb));
480 			if (error) {
481 				SCTP_INP_DECR_REF(inp);
482 				atomic_subtract_int(&stcb->asoc.refcnt, 1);
483 				return (error);
484 			}
485 			SCTP_INP_INFO_RLOCK();
486 			SCTP_INP_RLOCK(inp);
487 			error = sctp_sysctl_copy_out_local_addresses(inp, stcb, req);
488 			if (error) {
489 				SCTP_INP_DECR_REF(inp);
490 				atomic_subtract_int(&stcb->asoc.refcnt, 1);
491 				return (error);
492 			}
493 			TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
494 				xraddr.last = 0;
495 				xraddr.address = net->ro._l_addr;
496 				xraddr.active = ((net->dest_state & SCTP_ADDR_REACHABLE) == SCTP_ADDR_REACHABLE);
497 				xraddr.confirmed = ((net->dest_state & SCTP_ADDR_UNCONFIRMED) == 0);
498 				xraddr.heartbeat_enabled = ((net->dest_state & SCTP_ADDR_NOHB) == 0);
499 				xraddr.potentially_failed = ((net->dest_state & SCTP_ADDR_PF) == SCTP_ADDR_PF);
500 				xraddr.rto = net->RTO;
501 				xraddr.max_path_rtx = net->failure_threshold;
502 				xraddr.rtx = net->marked_retrans;
503 				xraddr.error_counter = net->error_count;
504 				xraddr.cwnd = net->cwnd;
505 				xraddr.flight_size = net->flight_size;
506 				xraddr.mtu = net->mtu;
507 				xraddr.rtt = net->rtt / 1000;
508 				xraddr.heartbeat_interval = net->heart_beat_delay;
509 				xraddr.ssthresh = net->ssthresh;
510 				xraddr.encaps_port = net->port;
511 				if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
512 					xraddr.state = SCTP_UNCONFIRMED;
513 				} else if (net->dest_state & SCTP_ADDR_REACHABLE) {
514 					xraddr.state = SCTP_ACTIVE;
515 				} else {
516 					xraddr.state = SCTP_INACTIVE;
517 				}
518 				xraddr.start_time.tv_sec = (uint32_t)net->start_time.tv_sec;
519 				xraddr.start_time.tv_usec = (uint32_t)net->start_time.tv_usec;
520 				SCTP_INP_RUNLOCK(inp);
521 				SCTP_INP_INFO_RUNLOCK();
522 				error = SYSCTL_OUT(req, &xraddr, sizeof(struct xsctp_raddr));
523 				if (error) {
524 					SCTP_INP_DECR_REF(inp);
525 					atomic_subtract_int(&stcb->asoc.refcnt, 1);
526 					return (error);
527 				}
528 				SCTP_INP_INFO_RLOCK();
529 				SCTP_INP_RLOCK(inp);
530 			}
531 			atomic_subtract_int(&stcb->asoc.refcnt, 1);
532 			memset((void *)&xraddr, 0, sizeof(struct xsctp_raddr));
533 			xraddr.last = 1;
534 			SCTP_INP_RUNLOCK(inp);
535 			SCTP_INP_INFO_RUNLOCK();
536 			error = SYSCTL_OUT(req, &xraddr, sizeof(struct xsctp_raddr));
537 			if (error) {
538 				SCTP_INP_DECR_REF(inp);
539 				return (error);
540 			}
541 			SCTP_INP_INFO_RLOCK();
542 			SCTP_INP_RLOCK(inp);
543 		}
544 		SCTP_INP_DECR_REF(inp);
545 		SCTP_INP_RUNLOCK(inp);
546 		SCTP_INP_INFO_RUNLOCK();
547 		memset((void *)&xstcb, 0, sizeof(struct xsctp_tcb));
548 		xstcb.last = 1;
549 		error = SYSCTL_OUT(req, &xstcb, sizeof(struct xsctp_tcb));
550 		if (error) {
551 			return (error);
552 		}
553 skip:
554 		SCTP_INP_INFO_RLOCK();
555 	}
556 	SCTP_INP_INFO_RUNLOCK();
557 
558 	memset((void *)&xinpcb, 0, sizeof(struct xsctp_inpcb));
559 	xinpcb.last = 1;
560 	error = SYSCTL_OUT(req, &xinpcb, sizeof(struct xsctp_inpcb));
561 	return (error);
562 }
563 
564 static int
565 sctp_sysctl_handle_udp_tunneling(SYSCTL_HANDLER_ARGS)
566 {
567 	int error;
568 	uint32_t old, new;
569 
570 	SCTP_INP_INFO_RLOCK();
571 	old = SCTP_BASE_SYSCTL(sctp_udp_tunneling_port);
572 	SCTP_INP_INFO_RUNLOCK();
573 	new = old;
574 	error = sysctl_handle_int(oidp, &new, 0, req);
575 	if ((error == 0) &&
576 	    (req->newptr != NULL)) {
577 #if (SCTPCTL_UDP_TUNNELING_PORT_MIN == 0)
578 		if (new > SCTPCTL_UDP_TUNNELING_PORT_MAX) {
579 #else
580 		if ((new < SCTPCTL_UDP_TUNNELING_PORT_MIN) ||
581 		    (new > SCTPCTL_UDP_TUNNELING_PORT_MAX)) {
582 #endif
583 			error = EINVAL;
584 		} else {
585 			SCTP_INP_INFO_WLOCK();
586 			SCTP_BASE_SYSCTL(sctp_udp_tunneling_port) = new;
587 			if (old != 0) {
588 				sctp_over_udp_stop();
589 			}
590 			if (new != 0) {
591 				error = sctp_over_udp_start();
592 			}
593 			SCTP_INP_INFO_WUNLOCK();
594 		}
595 	}
596 	return (error);
597 }
598 
599 static int
600 sctp_sysctl_handle_auth(SYSCTL_HANDLER_ARGS)
601 {
602 	int error;
603 	uint32_t new;
604 
605 	new = SCTP_BASE_SYSCTL(sctp_auth_enable);
606 	error = sysctl_handle_int(oidp, &new, 0, req);
607 	if ((error == 0) &&
608 	    (req->newptr != NULL)) {
609 #if (SCTPCTL_AUTH_ENABLE_MIN == 0)
610 		if ((new > SCTPCTL_AUTH_ENABLE_MAX) ||
611 		    ((new == 0) && (SCTP_BASE_SYSCTL(sctp_asconf_enable) == 1))) {
612 #else
613 		if ((new < SCTPCTL_AUTH_ENABLE_MIN) ||
614 		    (new > SCTPCTL_AUTH_ENABLE_MAX) ||
615 		    ((new == 0) && (SCTP_BASE_SYSCTL(sctp_asconf_enable) == 1))) {
616 #endif
617 			error = EINVAL;
618 		} else {
619 			SCTP_BASE_SYSCTL(sctp_auth_enable) = new;
620 		}
621 	}
622 	return (error);
623 }
624 
625 static int
626 sctp_sysctl_handle_asconf(SYSCTL_HANDLER_ARGS)
627 {
628 	int error;
629 	uint32_t new;
630 
631 	new = SCTP_BASE_SYSCTL(sctp_asconf_enable);
632 	error = sysctl_handle_int(oidp, &new, 0, req);
633 	if ((error == 0) &&
634 	    (req->newptr != NULL)) {
635 #if (SCTPCTL_ASCONF_ENABLE_MIN == 0)
636 		if ((new > SCTPCTL_ASCONF_ENABLE_MAX) ||
637 		    ((new == 1) && (SCTP_BASE_SYSCTL(sctp_auth_enable) == 0))) {
638 #else
639 		if ((new < SCTPCTL_ASCONF_ENABLE_MIN) ||
640 		    (new > SCTPCTL_ASCONF_ENABLE_MAX) ||
641 		    ((new == 1) && (SCTP_BASE_SYSCTL(sctp_auth_enable) == 0))) {
642 #endif
643 			error = EINVAL;
644 		} else {
645 			SCTP_BASE_SYSCTL(sctp_asconf_enable) = new;
646 		}
647 	}
648 	return (error);
649 }
650 
651 static int
652 sctp_sysctl_handle_stats(SYSCTL_HANDLER_ARGS)
653 {
654 	int error;
655 #if defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
656 	struct sctpstat *sarry;
657 	struct sctpstat sb;
658 	int cpu;
659 #endif
660 	struct sctpstat sb_temp;
661 
662 	if ((req->newptr != NULL) &&
663 	    (req->newlen != sizeof(struct sctpstat))) {
664 		return (EINVAL);
665 	}
666 	memset(&sb_temp, 0, sizeof(struct sctpstat));
667 
668 	if (req->newptr != NULL) {
669 		error = SYSCTL_IN(req, &sb_temp, sizeof(struct sctpstat));
670 		if (error != 0) {
671 			return (error);
672 		}
673 	}
674 #if defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
675 	memset(&sb, 0, sizeof(sb));
676 	for (cpu = 0; cpu < mp_maxid; cpu++) {
677 		sarry = &SCTP_BASE_STATS[cpu];
678 		if (sarry->sctps_discontinuitytime.tv_sec > sb.sctps_discontinuitytime.tv_sec) {
679 			sb.sctps_discontinuitytime.tv_sec = sarry->sctps_discontinuitytime.tv_sec;
680 			sb.sctps_discontinuitytime.tv_usec = sarry->sctps_discontinuitytime.tv_usec;
681 		}
682 		sb.sctps_currestab += sarry->sctps_currestab;
683 		sb.sctps_activeestab += sarry->sctps_activeestab;
684 		sb.sctps_restartestab += sarry->sctps_restartestab;
685 		sb.sctps_collisionestab += sarry->sctps_collisionestab;
686 		sb.sctps_passiveestab += sarry->sctps_passiveestab;
687 		sb.sctps_aborted += sarry->sctps_aborted;
688 		sb.sctps_shutdown += sarry->sctps_shutdown;
689 		sb.sctps_outoftheblue += sarry->sctps_outoftheblue;
690 		sb.sctps_checksumerrors += sarry->sctps_checksumerrors;
691 		sb.sctps_outcontrolchunks += sarry->sctps_outcontrolchunks;
692 		sb.sctps_outorderchunks += sarry->sctps_outorderchunks;
693 		sb.sctps_outunorderchunks += sarry->sctps_outunorderchunks;
694 		sb.sctps_incontrolchunks += sarry->sctps_incontrolchunks;
695 		sb.sctps_inorderchunks += sarry->sctps_inorderchunks;
696 		sb.sctps_inunorderchunks += sarry->sctps_inunorderchunks;
697 		sb.sctps_fragusrmsgs += sarry->sctps_fragusrmsgs;
698 		sb.sctps_reasmusrmsgs += sarry->sctps_reasmusrmsgs;
699 		sb.sctps_outpackets += sarry->sctps_outpackets;
700 		sb.sctps_inpackets += sarry->sctps_inpackets;
701 		sb.sctps_recvpackets += sarry->sctps_recvpackets;
702 		sb.sctps_recvdatagrams += sarry->sctps_recvdatagrams;
703 		sb.sctps_recvpktwithdata += sarry->sctps_recvpktwithdata;
704 		sb.sctps_recvsacks += sarry->sctps_recvsacks;
705 		sb.sctps_recvdata += sarry->sctps_recvdata;
706 		sb.sctps_recvdupdata += sarry->sctps_recvdupdata;
707 		sb.sctps_recvheartbeat += sarry->sctps_recvheartbeat;
708 		sb.sctps_recvheartbeatack += sarry->sctps_recvheartbeatack;
709 		sb.sctps_recvecne += sarry->sctps_recvecne;
710 		sb.sctps_recvauth += sarry->sctps_recvauth;
711 		sb.sctps_recvauthmissing += sarry->sctps_recvauthmissing;
712 		sb.sctps_recvivalhmacid += sarry->sctps_recvivalhmacid;
713 		sb.sctps_recvivalkeyid += sarry->sctps_recvivalkeyid;
714 		sb.sctps_recvauthfailed += sarry->sctps_recvauthfailed;
715 		sb.sctps_recvexpress += sarry->sctps_recvexpress;
716 		sb.sctps_recvexpressm += sarry->sctps_recvexpressm;
717 		sb.sctps_recvswcrc += sarry->sctps_recvswcrc;
718 		sb.sctps_recvhwcrc += sarry->sctps_recvhwcrc;
719 		sb.sctps_sendpackets += sarry->sctps_sendpackets;
720 		sb.sctps_sendsacks += sarry->sctps_sendsacks;
721 		sb.sctps_senddata += sarry->sctps_senddata;
722 		sb.sctps_sendretransdata += sarry->sctps_sendretransdata;
723 		sb.sctps_sendfastretrans += sarry->sctps_sendfastretrans;
724 		sb.sctps_sendmultfastretrans += sarry->sctps_sendmultfastretrans;
725 		sb.sctps_sendheartbeat += sarry->sctps_sendheartbeat;
726 		sb.sctps_sendecne += sarry->sctps_sendecne;
727 		sb.sctps_sendauth += sarry->sctps_sendauth;
728 		sb.sctps_senderrors += sarry->sctps_senderrors;
729 		sb.sctps_sendswcrc += sarry->sctps_sendswcrc;
730 		sb.sctps_sendhwcrc += sarry->sctps_sendhwcrc;
731 		sb.sctps_pdrpfmbox += sarry->sctps_pdrpfmbox;
732 		sb.sctps_pdrpfehos += sarry->sctps_pdrpfehos;
733 		sb.sctps_pdrpmbda += sarry->sctps_pdrpmbda;
734 		sb.sctps_pdrpmbct += sarry->sctps_pdrpmbct;
735 		sb.sctps_pdrpbwrpt += sarry->sctps_pdrpbwrpt;
736 		sb.sctps_pdrpcrupt += sarry->sctps_pdrpcrupt;
737 		sb.sctps_pdrpnedat += sarry->sctps_pdrpnedat;
738 		sb.sctps_pdrppdbrk += sarry->sctps_pdrppdbrk;
739 		sb.sctps_pdrptsnnf += sarry->sctps_pdrptsnnf;
740 		sb.sctps_pdrpdnfnd += sarry->sctps_pdrpdnfnd;
741 		sb.sctps_pdrpdiwnp += sarry->sctps_pdrpdiwnp;
742 		sb.sctps_pdrpdizrw += sarry->sctps_pdrpdizrw;
743 		sb.sctps_pdrpbadd += sarry->sctps_pdrpbadd;
744 		sb.sctps_pdrpmark += sarry->sctps_pdrpmark;
745 		sb.sctps_timoiterator += sarry->sctps_timoiterator;
746 		sb.sctps_timodata += sarry->sctps_timodata;
747 		sb.sctps_timowindowprobe += sarry->sctps_timowindowprobe;
748 		sb.sctps_timoinit += sarry->sctps_timoinit;
749 		sb.sctps_timosack += sarry->sctps_timosack;
750 		sb.sctps_timoshutdown += sarry->sctps_timoshutdown;
751 		sb.sctps_timoheartbeat += sarry->sctps_timoheartbeat;
752 		sb.sctps_timocookie += sarry->sctps_timocookie;
753 		sb.sctps_timosecret += sarry->sctps_timosecret;
754 		sb.sctps_timopathmtu += sarry->sctps_timopathmtu;
755 		sb.sctps_timoshutdownack += sarry->sctps_timoshutdownack;
756 		sb.sctps_timoshutdownguard += sarry->sctps_timoshutdownguard;
757 		sb.sctps_timostrmrst += sarry->sctps_timostrmrst;
758 		sb.sctps_timoearlyfr += sarry->sctps_timoearlyfr;
759 		sb.sctps_timoasconf += sarry->sctps_timoasconf;
760 		sb.sctps_timodelprim += sarry->sctps_timodelprim;
761 		sb.sctps_timoautoclose += sarry->sctps_timoautoclose;
762 		sb.sctps_timoassockill += sarry->sctps_timoassockill;
763 		sb.sctps_timoinpkill += sarry->sctps_timoinpkill;
764 		sb.sctps_hdrops += sarry->sctps_hdrops;
765 		sb.sctps_badsum += sarry->sctps_badsum;
766 		sb.sctps_noport += sarry->sctps_noport;
767 		sb.sctps_badvtag += sarry->sctps_badvtag;
768 		sb.sctps_badsid += sarry->sctps_badsid;
769 		sb.sctps_nomem += sarry->sctps_nomem;
770 		sb.sctps_fastretransinrtt += sarry->sctps_fastretransinrtt;
771 		sb.sctps_markedretrans += sarry->sctps_markedretrans;
772 		sb.sctps_naglesent += sarry->sctps_naglesent;
773 		sb.sctps_naglequeued += sarry->sctps_naglequeued;
774 		sb.sctps_maxburstqueued += sarry->sctps_maxburstqueued;
775 		sb.sctps_ifnomemqueued += sarry->sctps_ifnomemqueued;
776 		sb.sctps_windowprobed += sarry->sctps_windowprobed;
777 		sb.sctps_lowlevelerr += sarry->sctps_lowlevelerr;
778 		sb.sctps_lowlevelerrusr += sarry->sctps_lowlevelerrusr;
779 		sb.sctps_datadropchklmt += sarry->sctps_datadropchklmt;
780 		sb.sctps_datadroprwnd += sarry->sctps_datadroprwnd;
781 		sb.sctps_ecnereducedcwnd += sarry->sctps_ecnereducedcwnd;
782 		sb.sctps_vtagexpress += sarry->sctps_vtagexpress;
783 		sb.sctps_vtagbogus += sarry->sctps_vtagbogus;
784 		sb.sctps_primary_randry += sarry->sctps_primary_randry;
785 		sb.sctps_cmt_randry += sarry->sctps_cmt_randry;
786 		sb.sctps_slowpath_sack += sarry->sctps_slowpath_sack;
787 		sb.sctps_wu_sacks_sent += sarry->sctps_wu_sacks_sent;
788 		sb.sctps_sends_with_flags += sarry->sctps_sends_with_flags;
789 		sb.sctps_sends_with_unord += sarry->sctps_sends_with_unord;
790 		sb.sctps_sends_with_eof += sarry->sctps_sends_with_eof;
791 		sb.sctps_sends_with_abort += sarry->sctps_sends_with_abort;
792 		sb.sctps_protocol_drain_calls += sarry->sctps_protocol_drain_calls;
793 		sb.sctps_protocol_drains_done += sarry->sctps_protocol_drains_done;
794 		sb.sctps_read_peeks += sarry->sctps_read_peeks;
795 		sb.sctps_cached_chk += sarry->sctps_cached_chk;
796 		sb.sctps_cached_strmoq += sarry->sctps_cached_strmoq;
797 		sb.sctps_left_abandon += sarry->sctps_left_abandon;
798 		sb.sctps_send_burst_avoid += sarry->sctps_send_burst_avoid;
799 		sb.sctps_send_cwnd_avoid += sarry->sctps_send_cwnd_avoid;
800 		sb.sctps_fwdtsn_map_over += sarry->sctps_fwdtsn_map_over;
801 		if (req->newptr != NULL) {
802 			memcpy(sarry, &sb_temp, sizeof(struct sctpstat));
803 		}
804 	}
805 	error = SYSCTL_OUT(req, &sb, sizeof(struct sctpstat));
806 #else
807 	error = SYSCTL_OUT(req, &SCTP_BASE_STATS, sizeof(struct sctpstat));
808 	if (error != 0) {
809 		return (error);
810 	}
811 	if (req->newptr != NULL) {
812 		memcpy(&SCTP_BASE_STATS, &sb_temp, sizeof(struct sctpstat));
813 	}
814 #endif
815 	return (error);
816 }
817 
818 #if defined(SCTP_LOCAL_TRACE_BUF)
819 static int
820 sctp_sysctl_handle_trace_log(SYSCTL_HANDLER_ARGS)
821 {
822 	int error;
823 
824 	error = SYSCTL_OUT(req, &SCTP_BASE_SYSCTL(sctp_log), sizeof(struct sctp_log));
825 	return (error);
826 }
827 
828 static int
829 sctp_sysctl_handle_trace_log_clear(SYSCTL_HANDLER_ARGS)
830 {
831 	int error = 0;
832 
833 	memset(&SCTP_BASE_SYSCTL(sctp_log), 0, sizeof(struct sctp_log));
834 	return (error);
835 }
836 #endif
837 
838 #define SCTP_UINT_SYSCTL(mib_name, var_name, prefix)			\
839 	static int							\
840 	sctp_sysctl_handle_##mib_name(SYSCTL_HANDLER_ARGS)		\
841 	{								\
842 		int error;						\
843 		uint32_t new;						\
844 									\
845 		new = SCTP_BASE_SYSCTL(var_name);			\
846 		error = sysctl_handle_int(oidp, &new, 0, req);		\
847 		if ((error == 0) && (req->newptr != NULL)) {		\
848 			if ((new < prefix##_MIN) ||			\
849 			    (new > prefix##_MAX)) {			\
850 				error = EINVAL;				\
851 			} else {					\
852 				SCTP_BASE_SYSCTL(var_name) = new;	\
853 			}						\
854 		}							\
855 		return (error);						\
856 	}								\
857 	SYSCTL_PROC(_net_inet_sctp, OID_AUTO, mib_name,			\
858 	    CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_NEEDGIANT, \
859 	    NULL, 0, sctp_sysctl_handle_##mib_name, "UI", prefix##_DESC);
860 
861 /*
862  * sysctl definitions
863  */
864 
865 SCTP_UINT_SYSCTL(sendspace, sctp_sendspace, SCTPCTL_MAXDGRAM)
866 SCTP_UINT_SYSCTL(recvspace, sctp_recvspace, SCTPCTL_RECVSPACE)
867 SCTP_UINT_SYSCTL(auto_asconf, sctp_auto_asconf, SCTPCTL_AUTOASCONF)
868 SCTP_UINT_SYSCTL(ecn_enable, sctp_ecn_enable, SCTPCTL_ECN_ENABLE)
869 SCTP_UINT_SYSCTL(pr_enable, sctp_pr_enable, SCTPCTL_PR_ENABLE)
870 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, auth_enable,
871     CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
872     NULL, 0, sctp_sysctl_handle_auth, "IU",
873     SCTPCTL_AUTH_ENABLE_DESC);
874 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, asconf_enable,
875     CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
876     NULL, 0, sctp_sysctl_handle_asconf, "IU",
877     SCTPCTL_ASCONF_ENABLE_DESC);
878 SCTP_UINT_SYSCTL(reconfig_enable, sctp_reconfig_enable, SCTPCTL_RECONFIG_ENABLE)
879 SCTP_UINT_SYSCTL(nrsack_enable, sctp_nrsack_enable, SCTPCTL_NRSACK_ENABLE)
880 SCTP_UINT_SYSCTL(pktdrop_enable, sctp_pktdrop_enable, SCTPCTL_PKTDROP_ENABLE)
881 SCTP_UINT_SYSCTL(peer_chkoh, sctp_peer_chunk_oh, SCTPCTL_PEER_CHKOH)
882 SCTP_UINT_SYSCTL(maxburst, sctp_max_burst_default, SCTPCTL_MAXBURST)
883 SCTP_UINT_SYSCTL(fr_maxburst, sctp_fr_max_burst_default, SCTPCTL_FRMAXBURST)
884 SCTP_UINT_SYSCTL(maxchunks, sctp_max_chunks_on_queue, SCTPCTL_MAXCHUNKS)
885 SCTP_UINT_SYSCTL(tcbhashsize, sctp_hashtblsize, SCTPCTL_TCBHASHSIZE)
886 SCTP_UINT_SYSCTL(pcbhashsize, sctp_pcbtblsize, SCTPCTL_PCBHASHSIZE)
887 SCTP_UINT_SYSCTL(min_split_point, sctp_min_split_point, SCTPCTL_MIN_SPLIT_POINT)
888 SCTP_UINT_SYSCTL(chunkscale, sctp_chunkscale, SCTPCTL_CHUNKSCALE)
889 SCTP_UINT_SYSCTL(delayed_sack_time, sctp_delayed_sack_time_default, SCTPCTL_DELAYED_SACK_TIME)
890 SCTP_UINT_SYSCTL(sack_freq, sctp_sack_freq_default, SCTPCTL_SACK_FREQ)
891 SCTP_UINT_SYSCTL(sys_resource, sctp_system_free_resc_limit, SCTPCTL_SYS_RESOURCE)
892 SCTP_UINT_SYSCTL(asoc_resource, sctp_asoc_free_resc_limit, SCTPCTL_ASOC_RESOURCE)
893 SCTP_UINT_SYSCTL(heartbeat_interval, sctp_heartbeat_interval_default, SCTPCTL_HEARTBEAT_INTERVAL)
894 SCTP_UINT_SYSCTL(pmtu_raise_time, sctp_pmtu_raise_time_default, SCTPCTL_PMTU_RAISE_TIME)
895 SCTP_UINT_SYSCTL(shutdown_guard_time, sctp_shutdown_guard_time_default, SCTPCTL_SHUTDOWN_GUARD_TIME)
896 SCTP_UINT_SYSCTL(secret_lifetime, sctp_secret_lifetime_default, SCTPCTL_SECRET_LIFETIME)
897 SCTP_UINT_SYSCTL(rto_max, sctp_rto_max_default, SCTPCTL_RTO_MAX)
898 SCTP_UINT_SYSCTL(rto_min, sctp_rto_min_default, SCTPCTL_RTO_MIN)
899 SCTP_UINT_SYSCTL(rto_initial, sctp_rto_initial_default, SCTPCTL_RTO_INITIAL)
900 SCTP_UINT_SYSCTL(init_rto_max, sctp_init_rto_max_default, SCTPCTL_INIT_RTO_MAX)
901 SCTP_UINT_SYSCTL(valid_cookie_life, sctp_valid_cookie_life_default, SCTPCTL_VALID_COOKIE_LIFE)
902 SCTP_UINT_SYSCTL(init_rtx_max, sctp_init_rtx_max_default, SCTPCTL_INIT_RTX_MAX)
903 SCTP_UINT_SYSCTL(assoc_rtx_max, sctp_assoc_rtx_max_default, SCTPCTL_ASSOC_RTX_MAX)
904 SCTP_UINT_SYSCTL(path_rtx_max, sctp_path_rtx_max_default, SCTPCTL_PATH_RTX_MAX)
905 SCTP_UINT_SYSCTL(path_pf_threshold, sctp_path_pf_threshold, SCTPCTL_PATH_PF_THRESHOLD)
906 SCTP_UINT_SYSCTL(add_more_on_output, sctp_add_more_threshold, SCTPCTL_ADD_MORE_ON_OUTPUT)
907 SCTP_UINT_SYSCTL(incoming_streams, sctp_nr_incoming_streams_default, SCTPCTL_INCOMING_STREAMS)
908 SCTP_UINT_SYSCTL(outgoing_streams, sctp_nr_outgoing_streams_default, SCTPCTL_OUTGOING_STREAMS)
909 SCTP_UINT_SYSCTL(cmt_on_off, sctp_cmt_on_off, SCTPCTL_CMT_ON_OFF)
910 SCTP_UINT_SYSCTL(cmt_use_dac, sctp_cmt_use_dac, SCTPCTL_CMT_USE_DAC)
911 SCTP_UINT_SYSCTL(cwnd_maxburst, sctp_use_cwnd_based_maxburst, SCTPCTL_CWND_MAXBURST)
912 SCTP_UINT_SYSCTL(nat_friendly, sctp_nat_friendly, SCTPCTL_NAT_FRIENDLY)
913 SCTP_UINT_SYSCTL(abc_l_var, sctp_L2_abc_variable, SCTPCTL_ABC_L_VAR)
914 SCTP_UINT_SYSCTL(max_chained_mbufs, sctp_mbuf_threshold_count, SCTPCTL_MAX_CHAINED_MBUFS)
915 SCTP_UINT_SYSCTL(do_sctp_drain, sctp_do_drain, SCTPCTL_DO_SCTP_DRAIN)
916 SCTP_UINT_SYSCTL(hb_max_burst, sctp_hb_maxburst, SCTPCTL_HB_MAX_BURST)
917 SCTP_UINT_SYSCTL(abort_at_limit, sctp_abort_if_one_2_one_hits_limit, SCTPCTL_ABORT_AT_LIMIT)
918 SCTP_UINT_SYSCTL(min_residual, sctp_min_residual, SCTPCTL_MIN_RESIDUAL)
919 SCTP_UINT_SYSCTL(max_retran_chunk, sctp_max_retran_chunk, SCTPCTL_MAX_RETRAN_CHUNK)
920 SCTP_UINT_SYSCTL(log_level, sctp_logging_level, SCTPCTL_LOGGING_LEVEL)
921 SCTP_UINT_SYSCTL(default_cc_module, sctp_default_cc_module, SCTPCTL_DEFAULT_CC_MODULE)
922 SCTP_UINT_SYSCTL(default_ss_module, sctp_default_ss_module, SCTPCTL_DEFAULT_SS_MODULE)
923 SCTP_UINT_SYSCTL(default_frag_interleave, sctp_default_frag_interleave, SCTPCTL_DEFAULT_FRAG_INTERLEAVE)
924 SCTP_UINT_SYSCTL(mobility_base, sctp_mobility_base, SCTPCTL_MOBILITY_BASE)
925 SCTP_UINT_SYSCTL(mobility_fasthandoff, sctp_mobility_fasthandoff, SCTPCTL_MOBILITY_FASTHANDOFF)
926 #if defined(SCTP_LOCAL_TRACE_BUF)
927 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, log,
928     CTLFLAG_VNET | CTLTYPE_STRUCT | CTLFLAG_RD | CTLFLAG_NEEDGIANT,
929     NULL, 0, sctp_sysctl_handle_trace_log, "S,sctplog"a
930     , "SCTP logging (struct sctp_log)");
931 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, clear_trace,
932     CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
933     NULL, 0, sctp_sysctl_handle_trace_log_clear, "IU",
934     "Clear SCTP Logging buffer");
935 #endif
936 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, udp_tunneling_port,
937     CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
938     NULL, 0, sctp_sysctl_handle_udp_tunneling, "IU",
939     SCTPCTL_UDP_TUNNELING_PORT_DESC);
940 SCTP_UINT_SYSCTL(enable_sack_immediately, sctp_enable_sack_immediately, SCTPCTL_SACK_IMMEDIATELY_ENABLE)
941 SCTP_UINT_SYSCTL(nat_friendly_init, sctp_inits_include_nat_friendly, SCTPCTL_NAT_FRIENDLY_INITS)
942 SCTP_UINT_SYSCTL(vtag_time_wait, sctp_vtag_time_wait, SCTPCTL_TIME_WAIT)
943 SCTP_UINT_SYSCTL(buffer_splitting, sctp_buffer_splitting, SCTPCTL_BUFFER_SPLITTING)
944 SCTP_UINT_SYSCTL(initial_cwnd, sctp_initial_cwnd, SCTPCTL_INITIAL_CWND)
945 SCTP_UINT_SYSCTL(rttvar_bw, sctp_rttvar_bw, SCTPCTL_RTTVAR_BW)
946 SCTP_UINT_SYSCTL(rttvar_rtt, sctp_rttvar_rtt, SCTPCTL_RTTVAR_RTT)
947 SCTP_UINT_SYSCTL(rttvar_eqret, sctp_rttvar_eqret, SCTPCTL_RTTVAR_EQRET)
948 SCTP_UINT_SYSCTL(rttvar_steady_step, sctp_steady_step, SCTPCTL_RTTVAR_STEADYS)
949 SCTP_UINT_SYSCTL(use_dcccecn, sctp_use_dccc_ecn, SCTPCTL_RTTVAR_DCCCECN)
950 SCTP_UINT_SYSCTL(blackhole, sctp_blackhole, SCTPCTL_BLACKHOLE)
951 SCTP_UINT_SYSCTL(sendall_limit, sctp_sendall_limit, SCTPCTL_SENDALL_LIMIT)
952 SCTP_UINT_SYSCTL(diag_info_code, sctp_diag_info_code, SCTPCTL_DIAG_INFO_CODE)
953 #ifdef SCTP_DEBUG
954 SCTP_UINT_SYSCTL(debug, sctp_debug_on, SCTPCTL_DEBUG)
955 #endif
956 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, stats,
957     CTLFLAG_VNET | CTLTYPE_STRUCT | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
958     NULL, 0, sctp_sysctl_handle_stats, "S,sctpstat",
959     "SCTP statistics (struct sctp_stat)");
960 SYSCTL_PROC(_net_inet_sctp, OID_AUTO, assoclist,
961     CTLFLAG_VNET | CTLTYPE_OPAQUE | CTLFLAG_RD | CTLFLAG_NEEDGIANT,
962     NULL, 0, sctp_sysctl_handle_assoclist, "S,xassoc",
963     "List of active SCTP associations");
964