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