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