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