sctp_sysctl.c revision 303267
1251881Speter/*-
2251881Speter * Copyright (c) 2007, by Cisco Systems, Inc. All rights reserved.
3251881Speter * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
4251881Speter * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
5251881Speter *
6251881Speter * Redistribution and use in source and binary forms, with or without
7251881Speter * modification, are permitted provided that the following conditions are met:
8251881Speter *
9251881Speter * a) Redistributions of source code must retain the above copyright notice,
10251881Speter *    this list of conditions and the following disclaimer.
11251881Speter *
12251881Speter * b) Redistributions in binary form must reproduce the above copyright
13251881Speter *    notice, this list of conditions and the following disclaimer in
14251881Speter *    the documentation and/or other materials provided with the distribution.
15251881Speter *
16251881Speter * c) Neither the name of Cisco Systems, Inc. nor the names of its
17251881Speter *    contributors may be used to endorse or promote products derived
18251881Speter *    from this software without specific prior written permission.
19251881Speter *
20251881Speter * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21251881Speter * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22251881Speter * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23251881Speter * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24251881Speter * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25251881Speter * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26251881Speter * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27251881Speter * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28251881Speter * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29251881Speter * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30251881Speter * THE POSSIBILITY OF SUCH DAMAGE.
31251881Speter */
32251881Speter
33251881Speter#include <sys/cdefs.h>
34251881Speter__FBSDID("$FreeBSD: stable/11/sys/netinet/sctp_sysctl.c 303267 2016-07-24 14:50:16Z tuexen $");
35251881Speter
36251881Speter#include <netinet/sctp_os.h>
37251881Speter#include <netinet/sctp.h>
38251881Speter#include <netinet/sctp_constants.h>
39251881Speter#include <netinet/sctp_sysctl.h>
40251881Speter#include <netinet/sctp_pcb.h>
41251881Speter#include <netinet/sctputil.h>
42251881Speter#include <netinet/sctp_output.h>
43251881Speter#include <sys/smp.h>
44251881Speter#include <sys/sysctl.h>
45251881Speter
46251881SpeterFEATURE(sctp, "Stream Control Transmission Protocol");
47251881Speter
48251881Speter/*
49251881Speter * sysctl tunable variables
50251881Speter */
51251881Speter
52251881Spetervoid
53251881Spetersctp_init_sysctls()
54251881Speter{
55251881Speter	SCTP_BASE_SYSCTL(sctp_sendspace) = SCTPCTL_MAXDGRAM_DEFAULT;
56251881Speter	SCTP_BASE_SYSCTL(sctp_recvspace) = SCTPCTL_RECVSPACE_DEFAULT;
57251881Speter	SCTP_BASE_SYSCTL(sctp_auto_asconf) = SCTPCTL_AUTOASCONF_DEFAULT;
58251881Speter	SCTP_BASE_SYSCTL(sctp_multiple_asconfs) = SCTPCTL_MULTIPLEASCONFS_DEFAULT;
59251881Speter	SCTP_BASE_SYSCTL(sctp_ecn_enable) = SCTPCTL_ECN_ENABLE_DEFAULT;
60251881Speter	SCTP_BASE_SYSCTL(sctp_pr_enable) = SCTPCTL_PR_ENABLE_DEFAULT;
61251881Speter	SCTP_BASE_SYSCTL(sctp_auth_enable) = SCTPCTL_AUTH_ENABLE_DEFAULT;
62251881Speter	SCTP_BASE_SYSCTL(sctp_asconf_enable) = SCTPCTL_ASCONF_ENABLE_DEFAULT;
63251881Speter	SCTP_BASE_SYSCTL(sctp_reconfig_enable) = SCTPCTL_RECONFIG_ENABLE_DEFAULT;
64251881Speter	SCTP_BASE_SYSCTL(sctp_nrsack_enable) = SCTPCTL_NRSACK_ENABLE_DEFAULT;
65251881Speter	SCTP_BASE_SYSCTL(sctp_pktdrop_enable) = SCTPCTL_PKTDROP_ENABLE_DEFAULT;
66251881Speter	SCTP_BASE_SYSCTL(sctp_peer_chunk_oh) = SCTPCTL_PEER_CHKOH_DEFAULT;
67251881Speter	SCTP_BASE_SYSCTL(sctp_max_burst_default) = SCTPCTL_MAXBURST_DEFAULT;
68251881Speter	SCTP_BASE_SYSCTL(sctp_fr_max_burst_default) = SCTPCTL_FRMAXBURST_DEFAULT;
69251881Speter	SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = SCTPCTL_MAXCHUNKS_DEFAULT;
70251881Speter	SCTP_BASE_SYSCTL(sctp_hashtblsize) = SCTPCTL_TCBHASHSIZE_DEFAULT;
71251881Speter	SCTP_BASE_SYSCTL(sctp_pcbtblsize) = SCTPCTL_PCBHASHSIZE_DEFAULT;
72251881Speter	SCTP_BASE_SYSCTL(sctp_min_split_point) = SCTPCTL_MIN_SPLIT_POINT_DEFAULT;
73251881Speter	SCTP_BASE_SYSCTL(sctp_chunkscale) = SCTPCTL_CHUNKSCALE_DEFAULT;
74251881Speter	SCTP_BASE_SYSCTL(sctp_delayed_sack_time_default) = SCTPCTL_DELAYED_SACK_TIME_DEFAULT;
75251881Speter	SCTP_BASE_SYSCTL(sctp_sack_freq_default) = SCTPCTL_SACK_FREQ_DEFAULT;
76251881Speter	SCTP_BASE_SYSCTL(sctp_system_free_resc_limit) = SCTPCTL_SYS_RESOURCE_DEFAULT;
77251881Speter	SCTP_BASE_SYSCTL(sctp_asoc_free_resc_limit) = SCTPCTL_ASOC_RESOURCE_DEFAULT;
78251881Speter	SCTP_BASE_SYSCTL(sctp_heartbeat_interval_default) = SCTPCTL_HEARTBEAT_INTERVAL_DEFAULT;
79251881Speter	SCTP_BASE_SYSCTL(sctp_pmtu_raise_time_default) = SCTPCTL_PMTU_RAISE_TIME_DEFAULT;
80251881Speter	SCTP_BASE_SYSCTL(sctp_shutdown_guard_time_default) = SCTPCTL_SHUTDOWN_GUARD_TIME_DEFAULT;
81251881Speter	SCTP_BASE_SYSCTL(sctp_secret_lifetime_default) = SCTPCTL_SECRET_LIFETIME_DEFAULT;
82251881Speter	SCTP_BASE_SYSCTL(sctp_rto_max_default) = SCTPCTL_RTO_MAX_DEFAULT;
83251881Speter	SCTP_BASE_SYSCTL(sctp_rto_min_default) = SCTPCTL_RTO_MIN_DEFAULT;
84251881Speter	SCTP_BASE_SYSCTL(sctp_rto_initial_default) = SCTPCTL_RTO_INITIAL_DEFAULT;
85251881Speter	SCTP_BASE_SYSCTL(sctp_init_rto_max_default) = SCTPCTL_INIT_RTO_MAX_DEFAULT;
86251881Speter	SCTP_BASE_SYSCTL(sctp_valid_cookie_life_default) = SCTPCTL_VALID_COOKIE_LIFE_DEFAULT;
87251881Speter	SCTP_BASE_SYSCTL(sctp_init_rtx_max_default) = SCTPCTL_INIT_RTX_MAX_DEFAULT;
88251881Speter	SCTP_BASE_SYSCTL(sctp_assoc_rtx_max_default) = SCTPCTL_ASSOC_RTX_MAX_DEFAULT;
89251881Speter	SCTP_BASE_SYSCTL(sctp_path_rtx_max_default) = SCTPCTL_PATH_RTX_MAX_DEFAULT;
90251881Speter	SCTP_BASE_SYSCTL(sctp_path_pf_threshold) = SCTPCTL_PATH_PF_THRESHOLD_DEFAULT;
91251881Speter	SCTP_BASE_SYSCTL(sctp_add_more_threshold) = SCTPCTL_ADD_MORE_ON_OUTPUT_DEFAULT;
92251881Speter	SCTP_BASE_SYSCTL(sctp_nr_incoming_streams_default) = SCTPCTL_INCOMING_STREAMS_DEFAULT;
93251881Speter	SCTP_BASE_SYSCTL(sctp_nr_outgoing_streams_default) = SCTPCTL_OUTGOING_STREAMS_DEFAULT;
94251881Speter	SCTP_BASE_SYSCTL(sctp_cmt_on_off) = SCTPCTL_CMT_ON_OFF_DEFAULT;
95251881Speter	SCTP_BASE_SYSCTL(sctp_cmt_use_dac) = SCTPCTL_CMT_USE_DAC_DEFAULT;
96251881Speter	SCTP_BASE_SYSCTL(sctp_use_cwnd_based_maxburst) = SCTPCTL_CWND_MAXBURST_DEFAULT;
97251881Speter	SCTP_BASE_SYSCTL(sctp_nat_friendly) = SCTPCTL_NAT_FRIENDLY_DEFAULT;
98251881Speter	SCTP_BASE_SYSCTL(sctp_L2_abc_variable) = SCTPCTL_ABC_L_VAR_DEFAULT;
99251881Speter	SCTP_BASE_SYSCTL(sctp_mbuf_threshold_count) = SCTPCTL_MAX_CHAINED_MBUFS_DEFAULT;
100251881Speter	SCTP_BASE_SYSCTL(sctp_do_drain) = SCTPCTL_DO_SCTP_DRAIN_DEFAULT;
101251881Speter	SCTP_BASE_SYSCTL(sctp_hb_maxburst) = SCTPCTL_HB_MAX_BURST_DEFAULT;
102251881Speter	SCTP_BASE_SYSCTL(sctp_abort_if_one_2_one_hits_limit) = SCTPCTL_ABORT_AT_LIMIT_DEFAULT;
103251881Speter	SCTP_BASE_SYSCTL(sctp_min_residual) = SCTPCTL_MIN_RESIDUAL_DEFAULT;
104251881Speter	SCTP_BASE_SYSCTL(sctp_max_retran_chunk) = SCTPCTL_MAX_RETRAN_CHUNK_DEFAULT;
105251881Speter	SCTP_BASE_SYSCTL(sctp_logging_level) = SCTPCTL_LOGGING_LEVEL_DEFAULT;
106251881Speter	SCTP_BASE_SYSCTL(sctp_default_cc_module) = SCTPCTL_DEFAULT_CC_MODULE_DEFAULT;
107251881Speter	SCTP_BASE_SYSCTL(sctp_default_ss_module) = SCTPCTL_DEFAULT_SS_MODULE_DEFAULT;
108251881Speter	SCTP_BASE_SYSCTL(sctp_default_frag_interleave) = SCTPCTL_DEFAULT_FRAG_INTERLEAVE_DEFAULT;
109251881Speter	SCTP_BASE_SYSCTL(sctp_mobility_base) = SCTPCTL_MOBILITY_BASE_DEFAULT;
110251881Speter	SCTP_BASE_SYSCTL(sctp_mobility_fasthandoff) = SCTPCTL_MOBILITY_FASTHANDOFF_DEFAULT;
111251881Speter	SCTP_BASE_SYSCTL(sctp_vtag_time_wait) = SCTPCTL_TIME_WAIT_DEFAULT;
112251881Speter	SCTP_BASE_SYSCTL(sctp_buffer_splitting) = SCTPCTL_BUFFER_SPLITTING_DEFAULT;
113251881Speter	SCTP_BASE_SYSCTL(sctp_initial_cwnd) = SCTPCTL_INITIAL_CWND_DEFAULT;
114251881Speter	SCTP_BASE_SYSCTL(sctp_rttvar_bw) = SCTPCTL_RTTVAR_BW_DEFAULT;
115251881Speter	SCTP_BASE_SYSCTL(sctp_rttvar_rtt) = SCTPCTL_RTTVAR_RTT_DEFAULT;
116251881Speter	SCTP_BASE_SYSCTL(sctp_rttvar_eqret) = SCTPCTL_RTTVAR_EQRET_DEFAULT;
117251881Speter	SCTP_BASE_SYSCTL(sctp_steady_step) = SCTPCTL_RTTVAR_STEADYS_DEFAULT;
118251881Speter	SCTP_BASE_SYSCTL(sctp_use_dccc_ecn) = SCTPCTL_RTTVAR_DCCCECN_DEFAULT;
119251881Speter	SCTP_BASE_SYSCTL(sctp_blackhole) = SCTPCTL_BLACKHOLE_DEFAULT;
120251881Speter	SCTP_BASE_SYSCTL(sctp_diag_info_code) = SCTPCTL_DIAG_INFO_CODE_DEFAULT;
121251881Speter#if defined(SCTP_LOCAL_TRACE_BUF)
122251881Speter	memset(&SCTP_BASE_SYSCTL(sctp_log), 0, sizeof(struct sctp_log));
123251881Speter#endif
124251881Speter	SCTP_BASE_SYSCTL(sctp_udp_tunneling_port) = SCTPCTL_UDP_TUNNELING_PORT_DEFAULT;
125251881Speter	SCTP_BASE_SYSCTL(sctp_enable_sack_immediately) = SCTPCTL_SACK_IMMEDIATELY_ENABLE_DEFAULT;
126251881Speter	SCTP_BASE_SYSCTL(sctp_inits_include_nat_friendly) = SCTPCTL_NAT_FRIENDLY_INITS_DEFAULT;
127251881Speter#if defined(SCTP_DEBUG)
128251881Speter	SCTP_BASE_SYSCTL(sctp_debug_on) = SCTPCTL_DEBUG_DEFAULT;
129251881Speter#endif
130251881Speter#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
131251881Speter	SCTP_BASE_SYSCTL(sctp_output_unlocked) = SCTPCTL_OUTPUT_UNLOCKED_DEFAULT;
132251881Speter#endif
133251881Speter}
134251881Speter
135251881Speter
136251881Speter/* It returns an upper limit. No filtering is done here */
137251881Speterstatic unsigned int
138251881Spetersctp_sysctl_number_of_addresses(struct sctp_inpcb *inp)
139251881Speter{
140251881Speter	unsigned int cnt;
141251881Speter	struct sctp_vrf *vrf;
142251881Speter	struct sctp_ifn *sctp_ifn;
143251881Speter	struct sctp_ifa *sctp_ifa;
144251881Speter	struct sctp_laddr *laddr;
145251881Speter
146251881Speter	cnt = 0;
147251881Speter	/* neither Mac OS X nor FreeBSD support mulitple routing functions */
148251881Speter	if ((vrf = sctp_find_vrf(inp->def_vrf_id)) == NULL) {
149251881Speter		return (0);
150251881Speter	}
151251881Speter	if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
152251881Speter		LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
153251881Speter			LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
154251881Speter				switch (sctp_ifa->address.sa.sa_family) {
155251881Speter#ifdef INET
156251881Speter				case AF_INET:
157251881Speter#endif
158251881Speter#ifdef INET6
159251881Speter				case AF_INET6:
160251881Speter#endif
161251881Speter					cnt++;
162251881Speter					break;
163251881Speter				default:
164251881Speter					break;
165251881Speter				}
166251881Speter			}
167251881Speter		}
168251881Speter	} else {
169251881Speter		LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
170251881Speter			switch (laddr->ifa->address.sa.sa_family) {
171251881Speter#ifdef INET
172251881Speter			case AF_INET:
173251881Speter#endif
174251881Speter#ifdef INET6
175251881Speter			case AF_INET6:
176251881Speter#endif
177251881Speter				cnt++;
178251881Speter				break;
179251881Speter			default:
180251881Speter				break;
181251881Speter			}
182251881Speter		}
183251881Speter	}
184251881Speter	return (cnt);
185251881Speter}
186251881Speter
187251881Speterstatic int
188251881Spetersctp_sysctl_copy_out_local_addresses(struct sctp_inpcb *inp, struct sctp_tcb *stcb, struct sysctl_req *req)
189251881Speter{
190251881Speter	struct sctp_ifn *sctp_ifn;
191251881Speter	struct sctp_ifa *sctp_ifa;
192251881Speter	int loopback_scope, ipv4_local_scope, local_scope, site_scope;
193251881Speter	int ipv4_addr_legal, ipv6_addr_legal;
194251881Speter	struct sctp_vrf *vrf;
195251881Speter	struct xsctp_laddr xladdr;
196251881Speter	struct sctp_laddr *laddr;
197251881Speter	int error;
198251881Speter
199251881Speter	/* 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						}
283						if ((site_scope == 0) && (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)))
284							continue;
285					} else {
286						continue;
287					}
288					break;
289#endif
290				default:
291					continue;
292				}
293				memset((void *)&xladdr, 0, sizeof(struct xsctp_laddr));
294				memcpy((void *)&xladdr.address, (const void *)&sctp_ifa->address, sizeof(union sctp_sockstore));
295				SCTP_INP_RUNLOCK(inp);
296				SCTP_INP_INFO_RUNLOCK();
297				error = SYSCTL_OUT(req, &xladdr, sizeof(struct xsctp_laddr));
298				if (error) {
299					return (error);
300				} else {
301					SCTP_INP_INFO_RLOCK();
302					SCTP_INP_RLOCK(inp);
303				}
304			}
305		}
306	} else {
307		LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
308			/* ignore if blacklisted at association level */
309			if (stcb && sctp_is_addr_restricted(stcb, laddr->ifa))
310				continue;
311			memset((void *)&xladdr, 0, sizeof(struct xsctp_laddr));
312			memcpy((void *)&xladdr.address, (const void *)&laddr->ifa->address, sizeof(union sctp_sockstore));
313			xladdr.start_time.tv_sec = (uint32_t) laddr->start_time.tv_sec;
314			xladdr.start_time.tv_usec = (uint32_t) laddr->start_time.tv_usec;
315			SCTP_INP_RUNLOCK(inp);
316			SCTP_INP_INFO_RUNLOCK();
317			error = SYSCTL_OUT(req, &xladdr, sizeof(struct xsctp_laddr));
318			if (error) {
319				return (error);
320			} else {
321				SCTP_INP_INFO_RLOCK();
322				SCTP_INP_RLOCK(inp);
323			}
324		}
325	}
326	memset((void *)&xladdr, 0, sizeof(struct xsctp_laddr));
327	xladdr.last = 1;
328	SCTP_INP_RUNLOCK(inp);
329	SCTP_INP_INFO_RUNLOCK();
330	error = SYSCTL_OUT(req, &xladdr, sizeof(struct xsctp_laddr));
331
332	if (error) {
333		return (error);
334	} else {
335		SCTP_INP_INFO_RLOCK();
336		SCTP_INP_RLOCK(inp);
337		return (0);
338	}
339}
340
341/*
342 * sysctl functions
343 */
344static int
345sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS)
346{
347	unsigned int number_of_endpoints;
348	unsigned int number_of_local_addresses;
349	unsigned int number_of_associations;
350	unsigned int number_of_remote_addresses;
351	unsigned int n;
352	int error;
353	struct sctp_inpcb *inp;
354	struct sctp_tcb *stcb;
355	struct sctp_nets *net;
356	struct xsctp_inpcb xinpcb;
357	struct xsctp_tcb xstcb;
358	struct xsctp_raddr xraddr;
359	struct socket *so;
360
361	number_of_endpoints = 0;
362	number_of_local_addresses = 0;
363	number_of_associations = 0;
364	number_of_remote_addresses = 0;
365
366	SCTP_INP_INFO_RLOCK();
367	if (req->oldptr == NULL) {
368		LIST_FOREACH(inp, &SCTP_BASE_INFO(listhead), sctp_list) {
369			SCTP_INP_RLOCK(inp);
370			number_of_endpoints++;
371			number_of_local_addresses += sctp_sysctl_number_of_addresses(inp);
372			LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
373				number_of_associations++;
374				number_of_local_addresses += sctp_sysctl_number_of_addresses(inp);
375				TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
376					number_of_remote_addresses++;
377				}
378			}
379			SCTP_INP_RUNLOCK(inp);
380		}
381		SCTP_INP_INFO_RUNLOCK();
382		n = (number_of_endpoints + 1) * sizeof(struct xsctp_inpcb) +
383		    (number_of_local_addresses + number_of_endpoints + number_of_associations) * sizeof(struct xsctp_laddr) +
384		    (number_of_associations + number_of_endpoints) * sizeof(struct xsctp_tcb) +
385		    (number_of_remote_addresses + number_of_associations) * sizeof(struct xsctp_raddr);
386
387		/* request some more memory than needed */
388		req->oldidx = (n + n / 8);
389		return (0);
390	}
391	if (req->newptr != NULL) {
392		SCTP_INP_INFO_RUNLOCK();
393		SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_SYSCTL, EPERM);
394		return (EPERM);
395	}
396	LIST_FOREACH(inp, &SCTP_BASE_INFO(listhead), sctp_list) {
397		SCTP_INP_RLOCK(inp);
398		if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) {
399			/* if its allgone it is being freed - skip it  */
400			goto skip;
401		}
402		xinpcb.last = 0;
403		xinpcb.local_port = ntohs(inp->sctp_lport);
404		xinpcb.flags = inp->sctp_flags;
405		xinpcb.features = inp->sctp_features;
406		xinpcb.total_sends = inp->total_sends;
407		xinpcb.total_recvs = inp->total_recvs;
408		xinpcb.total_nospaces = inp->total_nospaces;
409		xinpcb.fragmentation_point = inp->sctp_frag_point;
410		xinpcb.socket = inp->sctp_socket;
411		so = inp->sctp_socket;
412		if ((so == NULL) ||
413		    (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
414			xinpcb.qlen = 0;
415			xinpcb.maxqlen = 0;
416		} else {
417			xinpcb.qlen = so->so_qlen;
418			xinpcb.qlen_old = so->so_qlen > USHRT_MAX ?
419			    USHRT_MAX : (uint16_t) so->so_qlen;
420			xinpcb.maxqlen = so->so_qlimit;
421			xinpcb.maxqlen_old = so->so_qlimit > USHRT_MAX ?
422			    USHRT_MAX : (uint16_t) so->so_qlimit;
423		}
424		SCTP_INP_INCR_REF(inp);
425		SCTP_INP_RUNLOCK(inp);
426		SCTP_INP_INFO_RUNLOCK();
427		error = SYSCTL_OUT(req, &xinpcb, sizeof(struct xsctp_inpcb));
428		if (error) {
429			SCTP_INP_DECR_REF(inp);
430			return (error);
431		}
432		SCTP_INP_INFO_RLOCK();
433		SCTP_INP_RLOCK(inp);
434		error = sctp_sysctl_copy_out_local_addresses(inp, NULL, req);
435		if (error) {
436			SCTP_INP_DECR_REF(inp);
437			return (error);
438		}
439		LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
440			SCTP_TCB_LOCK(stcb);
441			atomic_add_int(&stcb->asoc.refcnt, 1);
442			SCTP_TCB_UNLOCK(stcb);
443			xstcb.last = 0;
444			xstcb.local_port = ntohs(inp->sctp_lport);
445			xstcb.remote_port = ntohs(stcb->rport);
446			if (stcb->asoc.primary_destination != NULL)
447				xstcb.primary_addr = stcb->asoc.primary_destination->ro._l_addr;
448			xstcb.heartbeat_interval = stcb->asoc.heart_beat_delay;
449			xstcb.state = (uint32_t) sctp_map_assoc_state(stcb->asoc.state);
450			/* 7.0 does not support these */
451			xstcb.assoc_id = sctp_get_associd(stcb);
452			xstcb.peers_rwnd = stcb->asoc.peers_rwnd;
453			xstcb.in_streams = stcb->asoc.streamincnt;
454			xstcb.out_streams = stcb->asoc.streamoutcnt;
455			xstcb.max_nr_retrans = stcb->asoc.overall_error_count;
456			xstcb.primary_process = 0;	/* not really supported
457							 * yet */
458			xstcb.T1_expireries = stcb->asoc.timoinit + stcb->asoc.timocookie;
459			xstcb.T2_expireries = stcb->asoc.timoshutdown + stcb->asoc.timoshutdownack;
460			xstcb.retransmitted_tsns = stcb->asoc.marked_retrans;
461			xstcb.start_time.tv_sec = (uint32_t) stcb->asoc.start_time.tv_sec;
462			xstcb.start_time.tv_usec = (uint32_t) stcb->asoc.start_time.tv_usec;
463			xstcb.discontinuity_time.tv_sec = (uint32_t) stcb->asoc.discontinuity_time.tv_sec;
464			xstcb.discontinuity_time.tv_usec = (uint32_t) stcb->asoc.discontinuity_time.tv_usec;
465			xstcb.total_sends = stcb->total_sends;
466			xstcb.total_recvs = stcb->total_recvs;
467			xstcb.local_tag = stcb->asoc.my_vtag;
468			xstcb.remote_tag = stcb->asoc.peer_vtag;
469			xstcb.initial_tsn = stcb->asoc.init_seq_number;
470			xstcb.highest_tsn = stcb->asoc.sending_seq - 1;
471			xstcb.cumulative_tsn = stcb->asoc.last_acked_seq;
472			xstcb.cumulative_tsn_ack = stcb->asoc.cumulative_tsn;
473			xstcb.mtu = stcb->asoc.smallest_mtu;
474			xstcb.refcnt = stcb->asoc.refcnt;
475			SCTP_INP_RUNLOCK(inp);
476			SCTP_INP_INFO_RUNLOCK();
477			error = SYSCTL_OUT(req, &xstcb, sizeof(struct xsctp_tcb));
478			if (error) {
479				SCTP_INP_DECR_REF(inp);
480				atomic_subtract_int(&stcb->asoc.refcnt, 1);
481				return (error);
482			}
483			SCTP_INP_INFO_RLOCK();
484			SCTP_INP_RLOCK(inp);
485			error = sctp_sysctl_copy_out_local_addresses(inp, stcb, req);
486			if (error) {
487				SCTP_INP_DECR_REF(inp);
488				atomic_subtract_int(&stcb->asoc.refcnt, 1);
489				return (error);
490			}
491			TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
492				xraddr.last = 0;
493				xraddr.address = net->ro._l_addr;
494				xraddr.active = ((net->dest_state & SCTP_ADDR_REACHABLE) == SCTP_ADDR_REACHABLE);
495				xraddr.confirmed = ((net->dest_state & SCTP_ADDR_UNCONFIRMED) == 0);
496				xraddr.heartbeat_enabled = ((net->dest_state & SCTP_ADDR_NOHB) == 0);
497				xraddr.potentially_failed = ((net->dest_state & SCTP_ADDR_PF) == SCTP_ADDR_PF);
498				xraddr.rto = net->RTO;
499				xraddr.max_path_rtx = net->failure_threshold;
500				xraddr.rtx = net->marked_retrans;
501				xraddr.error_counter = net->error_count;
502				xraddr.cwnd = net->cwnd;
503				xraddr.flight_size = net->flight_size;
504				xraddr.mtu = net->mtu;
505				xraddr.rtt = net->rtt / 1000;
506				xraddr.heartbeat_interval = net->heart_beat_delay;
507				xraddr.ssthresh = net->ssthresh;
508				xraddr.start_time.tv_sec = (uint32_t) net->start_time.tv_sec;
509				xraddr.start_time.tv_usec = (uint32_t) net->start_time.tv_usec;
510				SCTP_INP_RUNLOCK(inp);
511				SCTP_INP_INFO_RUNLOCK();
512				error = SYSCTL_OUT(req, &xraddr, sizeof(struct xsctp_raddr));
513				if (error) {
514					SCTP_INP_DECR_REF(inp);
515					atomic_subtract_int(&stcb->asoc.refcnt, 1);
516					return (error);
517				}
518				SCTP_INP_INFO_RLOCK();
519				SCTP_INP_RLOCK(inp);
520			}
521			atomic_subtract_int(&stcb->asoc.refcnt, 1);
522			memset((void *)&xraddr, 0, sizeof(struct xsctp_raddr));
523			xraddr.last = 1;
524			SCTP_INP_RUNLOCK(inp);
525			SCTP_INP_INFO_RUNLOCK();
526			error = SYSCTL_OUT(req, &xraddr, sizeof(struct xsctp_raddr));
527			if (error) {
528				SCTP_INP_DECR_REF(inp);
529				return (error);
530			}
531			SCTP_INP_INFO_RLOCK();
532			SCTP_INP_RLOCK(inp);
533		}
534		SCTP_INP_DECR_REF(inp);
535		SCTP_INP_RUNLOCK(inp);
536		SCTP_INP_INFO_RUNLOCK();
537		memset((void *)&xstcb, 0, sizeof(struct xsctp_tcb));
538		xstcb.last = 1;
539		error = SYSCTL_OUT(req, &xstcb, sizeof(struct xsctp_tcb));
540		if (error) {
541			return (error);
542		}
543skip:
544		SCTP_INP_INFO_RLOCK();
545	}
546	SCTP_INP_INFO_RUNLOCK();
547
548	memset((void *)&xinpcb, 0, sizeof(struct xsctp_inpcb));
549	xinpcb.last = 1;
550	error = SYSCTL_OUT(req, &xinpcb, sizeof(struct xsctp_inpcb));
551	return (error);
552}
553
554static int
555sctp_sysctl_handle_udp_tunneling(SYSCTL_HANDLER_ARGS)
556{
557	int error;
558	uint32_t old, new;
559
560	SCTP_INP_INFO_RLOCK();
561	old = SCTP_BASE_SYSCTL(sctp_udp_tunneling_port);
562	SCTP_INP_INFO_RUNLOCK();
563	new = old;
564	error = sysctl_handle_int(oidp, &new, 0, req);
565	if ((error == 0) &&
566	    (req->newptr != NULL)) {
567#if (SCTPCTL_UDP_TUNNELING_PORT_MIN == 0)
568		if (new > SCTPCTL_UDP_TUNNELING_PORT_MAX) {
569#else
570		if ((new < SCTPCTL_UDP_TUNNELING_PORT_MIN) ||
571		    (new > SCTPCTL_UDP_TUNNELING_PORT_MAX)) {
572#endif
573			error = EINVAL;
574		} else {
575			SCTP_INP_INFO_WLOCK();
576			SCTP_BASE_SYSCTL(sctp_udp_tunneling_port) = new;
577			if (old != 0) {
578				sctp_over_udp_stop();
579			}
580			if (new != 0) {
581				error = sctp_over_udp_start();
582			}
583			SCTP_INP_INFO_WUNLOCK();
584		}
585	}
586	return (error);
587}
588
589
590static int
591sctp_sysctl_handle_auth(SYSCTL_HANDLER_ARGS)
592{
593	int error;
594	uint32_t new;
595
596	new = SCTP_BASE_SYSCTL(sctp_auth_enable);
597	error = sysctl_handle_int(oidp, &new, 0, req);
598	if ((error == 0) &&
599	    (req->newptr != NULL)) {
600#if (SCTPCTL_AUTH_ENABLE_MIN == 0)
601		if ((new > SCTPCTL_AUTH_ENABLE_MAX) ||
602		    ((new == 0) && (SCTP_BASE_SYSCTL(sctp_asconf_enable) == 1))) {
603#else
604		if ((new < SCTPCTL_AUTH_ENABLE_MIN) ||
605		    (new > SCTPCTL_AUTH_ENABLE_MAX) ||
606		    ((new == 0) && (SCTP_BASE_SYSCTL(sctp_asconf_enable) == 1))) {
607#endif
608			error = EINVAL;
609		} else {
610			SCTP_BASE_SYSCTL(sctp_auth_enable) = new;
611		}
612	}
613	return (error);
614}
615
616static int
617sctp_sysctl_handle_asconf(SYSCTL_HANDLER_ARGS)
618{
619	int error;
620	uint32_t new;
621
622	new = SCTP_BASE_SYSCTL(sctp_asconf_enable);
623	error = sysctl_handle_int(oidp, &new, 0, req);
624	if ((error == 0) &&
625	    (req->newptr != NULL)) {
626#if (SCTPCTL_ASCONF_ENABLE_MIN == 0)
627		if ((new > SCTPCTL_ASCONF_ENABLE_MAX) ||
628		    ((new == 1) && (SCTP_BASE_SYSCTL(sctp_auth_enable) == 0))) {
629#else
630		if ((new < SCTPCTL_ASCONF_ENABLE_MIN) ||
631		    (new > SCTPCTL_ASCONF_ENABLE_MAX) ||
632		    ((new == 1) && (SCTP_BASE_SYSCTL(sctp_auth_enable) == 0))) {
633#endif
634			error = EINVAL;
635		} else {
636			SCTP_BASE_SYSCTL(sctp_asconf_enable) = new;
637		}
638	}
639	return (error);
640}
641
642static int
643sctp_sysctl_handle_stats(SYSCTL_HANDLER_ARGS)
644{
645	int error;
646
647#if defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
648	struct sctpstat *sarry;
649	struct sctpstat sb;
650	int cpu;
651
652#endif
653	struct sctpstat sb_temp;
654
655	if ((req->newptr != NULL) &&
656	    (req->newlen != sizeof(struct sctpstat))) {
657		return (EINVAL);
658	}
659	memset(&sb_temp, 0, sizeof(struct sctpstat));
660
661	if (req->newptr != NULL) {
662		error = SYSCTL_IN(req, &sb_temp, sizeof(struct sctpstat));
663		if (error != 0) {
664			return (error);
665		}
666	}
667#if defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
668	memset(&sb, 0, sizeof(sb));
669	for (cpu = 0; cpu < mp_maxid; cpu++) {
670		sarry = &SCTP_BASE_STATS[cpu];
671		if (sarry->sctps_discontinuitytime.tv_sec > sb.sctps_discontinuitytime.tv_sec) {
672			sb.sctps_discontinuitytime.tv_sec = sarry->sctps_discontinuitytime.tv_sec;
673			sb.sctps_discontinuitytime.tv_usec = sarry->sctps_discontinuitytime.tv_usec;
674		}
675		sb.sctps_currestab += sarry->sctps_currestab;
676		sb.sctps_activeestab += sarry->sctps_activeestab;
677		sb.sctps_restartestab += sarry->sctps_restartestab;
678		sb.sctps_collisionestab += sarry->sctps_collisionestab;
679		sb.sctps_passiveestab += sarry->sctps_passiveestab;
680		sb.sctps_aborted += sarry->sctps_aborted;
681		sb.sctps_shutdown += sarry->sctps_shutdown;
682		sb.sctps_outoftheblue += sarry->sctps_outoftheblue;
683		sb.sctps_checksumerrors += sarry->sctps_checksumerrors;
684		sb.sctps_outcontrolchunks += sarry->sctps_outcontrolchunks;
685		sb.sctps_outorderchunks += sarry->sctps_outorderchunks;
686		sb.sctps_outunorderchunks += sarry->sctps_outunorderchunks;
687		sb.sctps_incontrolchunks += sarry->sctps_incontrolchunks;
688		sb.sctps_inorderchunks += sarry->sctps_inorderchunks;
689		sb.sctps_inunorderchunks += sarry->sctps_inunorderchunks;
690		sb.sctps_fragusrmsgs += sarry->sctps_fragusrmsgs;
691		sb.sctps_reasmusrmsgs += sarry->sctps_reasmusrmsgs;
692		sb.sctps_outpackets += sarry->sctps_outpackets;
693		sb.sctps_inpackets += sarry->sctps_inpackets;
694		sb.sctps_recvpackets += sarry->sctps_recvpackets;
695		sb.sctps_recvdatagrams += sarry->sctps_recvdatagrams;
696		sb.sctps_recvpktwithdata += sarry->sctps_recvpktwithdata;
697		sb.sctps_recvsacks += sarry->sctps_recvsacks;
698		sb.sctps_recvdata += sarry->sctps_recvdata;
699		sb.sctps_recvdupdata += sarry->sctps_recvdupdata;
700		sb.sctps_recvheartbeat += sarry->sctps_recvheartbeat;
701		sb.sctps_recvheartbeatack += sarry->sctps_recvheartbeatack;
702		sb.sctps_recvecne += sarry->sctps_recvecne;
703		sb.sctps_recvauth += sarry->sctps_recvauth;
704		sb.sctps_recvauthmissing += sarry->sctps_recvauthmissing;
705		sb.sctps_recvivalhmacid += sarry->sctps_recvivalhmacid;
706		sb.sctps_recvivalkeyid += sarry->sctps_recvivalkeyid;
707		sb.sctps_recvauthfailed += sarry->sctps_recvauthfailed;
708		sb.sctps_recvexpress += sarry->sctps_recvexpress;
709		sb.sctps_recvexpressm += sarry->sctps_recvexpressm;
710		sb.sctps_recvnocrc += sarry->sctps_recvnocrc;
711		sb.sctps_recvswcrc += sarry->sctps_recvswcrc;
712		sb.sctps_recvhwcrc += sarry->sctps_recvhwcrc;
713		sb.sctps_sendpackets += sarry->sctps_sendpackets;
714		sb.sctps_sendsacks += sarry->sctps_sendsacks;
715		sb.sctps_senddata += sarry->sctps_senddata;
716		sb.sctps_sendretransdata += sarry->sctps_sendretransdata;
717		sb.sctps_sendfastretrans += sarry->sctps_sendfastretrans;
718		sb.sctps_sendmultfastretrans += sarry->sctps_sendmultfastretrans;
719		sb.sctps_sendheartbeat += sarry->sctps_sendheartbeat;
720		sb.sctps_sendecne += sarry->sctps_sendecne;
721		sb.sctps_sendauth += sarry->sctps_sendauth;
722		sb.sctps_senderrors += sarry->sctps_senderrors;
723		sb.sctps_sendnocrc += sarry->sctps_sendnocrc;
724		sb.sctps_sendswcrc += sarry->sctps_sendswcrc;
725		sb.sctps_sendhwcrc += sarry->sctps_sendhwcrc;
726		sb.sctps_pdrpfmbox += sarry->sctps_pdrpfmbox;
727		sb.sctps_pdrpfehos += sarry->sctps_pdrpfehos;
728		sb.sctps_pdrpmbda += sarry->sctps_pdrpmbda;
729		sb.sctps_pdrpmbct += sarry->sctps_pdrpmbct;
730		sb.sctps_pdrpbwrpt += sarry->sctps_pdrpbwrpt;
731		sb.sctps_pdrpcrupt += sarry->sctps_pdrpcrupt;
732		sb.sctps_pdrpnedat += sarry->sctps_pdrpnedat;
733		sb.sctps_pdrppdbrk += sarry->sctps_pdrppdbrk;
734		sb.sctps_pdrptsnnf += sarry->sctps_pdrptsnnf;
735		sb.sctps_pdrpdnfnd += sarry->sctps_pdrpdnfnd;
736		sb.sctps_pdrpdiwnp += sarry->sctps_pdrpdiwnp;
737		sb.sctps_pdrpdizrw += sarry->sctps_pdrpdizrw;
738		sb.sctps_pdrpbadd += sarry->sctps_pdrpbadd;
739		sb.sctps_pdrpmark += sarry->sctps_pdrpmark;
740		sb.sctps_timoiterator += sarry->sctps_timoiterator;
741		sb.sctps_timodata += sarry->sctps_timodata;
742		sb.sctps_timowindowprobe += sarry->sctps_timowindowprobe;
743		sb.sctps_timoinit += sarry->sctps_timoinit;
744		sb.sctps_timosack += sarry->sctps_timosack;
745		sb.sctps_timoshutdown += sarry->sctps_timoshutdown;
746		sb.sctps_timoheartbeat += sarry->sctps_timoheartbeat;
747		sb.sctps_timocookie += sarry->sctps_timocookie;
748		sb.sctps_timosecret += sarry->sctps_timosecret;
749		sb.sctps_timopathmtu += sarry->sctps_timopathmtu;
750		sb.sctps_timoshutdownack += sarry->sctps_timoshutdownack;
751		sb.sctps_timoshutdownguard += sarry->sctps_timoshutdownguard;
752		sb.sctps_timostrmrst += sarry->sctps_timostrmrst;
753		sb.sctps_timoearlyfr += sarry->sctps_timoearlyfr;
754		sb.sctps_timoasconf += sarry->sctps_timoasconf;
755		sb.sctps_timodelprim += sarry->sctps_timodelprim;
756		sb.sctps_timoautoclose += sarry->sctps_timoautoclose;
757		sb.sctps_timoassockill += sarry->sctps_timoassockill;
758		sb.sctps_timoinpkill += sarry->sctps_timoinpkill;
759		sb.sctps_hdrops += sarry->sctps_hdrops;
760		sb.sctps_badsum += sarry->sctps_badsum;
761		sb.sctps_noport += sarry->sctps_noport;
762		sb.sctps_badvtag += sarry->sctps_badvtag;
763		sb.sctps_badsid += sarry->sctps_badsid;
764		sb.sctps_nomem += sarry->sctps_nomem;
765		sb.sctps_fastretransinrtt += sarry->sctps_fastretransinrtt;
766		sb.sctps_markedretrans += sarry->sctps_markedretrans;
767		sb.sctps_naglesent += sarry->sctps_naglesent;
768		sb.sctps_naglequeued += sarry->sctps_naglequeued;
769		sb.sctps_maxburstqueued += sarry->sctps_maxburstqueued;
770		sb.sctps_ifnomemqueued += sarry->sctps_ifnomemqueued;
771		sb.sctps_windowprobed += sarry->sctps_windowprobed;
772		sb.sctps_lowlevelerr += sarry->sctps_lowlevelerr;
773		sb.sctps_lowlevelerrusr += sarry->sctps_lowlevelerrusr;
774		sb.sctps_datadropchklmt += sarry->sctps_datadropchklmt;
775		sb.sctps_datadroprwnd += sarry->sctps_datadroprwnd;
776		sb.sctps_ecnereducedcwnd += sarry->sctps_ecnereducedcwnd;
777		sb.sctps_vtagexpress += sarry->sctps_vtagexpress;
778		sb.sctps_vtagbogus += sarry->sctps_vtagbogus;
779		sb.sctps_primary_randry += sarry->sctps_primary_randry;
780		sb.sctps_cmt_randry += sarry->sctps_cmt_randry;
781		sb.sctps_slowpath_sack += sarry->sctps_slowpath_sack;
782		sb.sctps_wu_sacks_sent += sarry->sctps_wu_sacks_sent;
783		sb.sctps_sends_with_flags += sarry->sctps_sends_with_flags;
784		sb.sctps_sends_with_unord += sarry->sctps_sends_with_unord;
785		sb.sctps_sends_with_eof += sarry->sctps_sends_with_eof;
786		sb.sctps_sends_with_abort += sarry->sctps_sends_with_abort;
787		sb.sctps_protocol_drain_calls += sarry->sctps_protocol_drain_calls;
788		sb.sctps_protocol_drains_done += sarry->sctps_protocol_drains_done;
789		sb.sctps_read_peeks += sarry->sctps_read_peeks;
790		sb.sctps_cached_chk += sarry->sctps_cached_chk;
791		sb.sctps_cached_strmoq += sarry->sctps_cached_strmoq;
792		sb.sctps_left_abandon += sarry->sctps_left_abandon;
793		sb.sctps_send_burst_avoid += sarry->sctps_send_burst_avoid;
794		sb.sctps_send_cwnd_avoid += sarry->sctps_send_cwnd_avoid;
795		sb.sctps_fwdtsn_map_over += sarry->sctps_fwdtsn_map_over;
796		if (req->newptr != NULL) {
797			memcpy(sarry, &sb_temp, sizeof(struct sctpstat));
798		}
799	}
800	error = SYSCTL_OUT(req, &sb, sizeof(struct sctpstat));
801#else
802	error = SYSCTL_OUT(req, &SCTP_BASE_STATS, sizeof(struct sctpstat));
803	if (error != 0) {
804		return (error);
805	}
806	if (req->newptr != NULL) {
807		memcpy(&SCTP_BASE_STATS, &sb_temp, sizeof(struct sctpstat));
808	}
809#endif
810	return (error);
811}
812
813#if defined(SCTP_LOCAL_TRACE_BUF)
814static int
815sctp_sysctl_handle_trace_log(SYSCTL_HANDLER_ARGS)
816{
817	int error;
818
819	error = SYSCTL_OUT(req, &SCTP_BASE_SYSCTL(sctp_log), sizeof(struct sctp_log));
820	return (error);
821}
822
823static int
824sctp_sysctl_handle_trace_log_clear(SYSCTL_HANDLER_ARGS)
825{
826	int error = 0;
827
828	memset(&SCTP_BASE_SYSCTL(sctp_log), 0, sizeof(struct sctp_log));
829	return (error);
830}
831
832#endif
833
834#define SCTP_UINT_SYSCTL(mib_name, var_name, prefix)			\
835	static int							\
836	sctp_sysctl_handle_##mib_name(SYSCTL_HANDLER_ARGS)		\
837	{								\
838		int error;						\
839		uint32_t new;						\
840									\
841		new = SCTP_BASE_SYSCTL(var_name);			\
842		error = sysctl_handle_int(oidp, &new, 0, req);		\
843		if ((error == 0) && (req->newptr != NULL)) {		\
844			if ((new < prefix##_MIN) ||			\
845			    (new > prefix##_MAX)) {			\
846				error = EINVAL;				\
847			} else {					\
848				SCTP_BASE_SYSCTL(var_name) = new;	\
849			}						\
850		}							\
851		return (error);						\
852	}								\
853	SYSCTL_PROC(_net_inet_sctp, OID_AUTO, mib_name,			\
854	                 CTLFLAG_VNET|CTLTYPE_UINT|CTLFLAG_RW, NULL, 0,	\
855	                 sctp_sysctl_handle_##mib_name, "UI", prefix##_DESC);
856
857/*
858 * sysctl definitions
859 */
860
861SCTP_UINT_SYSCTL(sendspace, sctp_sendspace, SCTPCTL_MAXDGRAM)
862SCTP_UINT_SYSCTL(recvspace, sctp_recvspace, SCTPCTL_RECVSPACE)
863SCTP_UINT_SYSCTL(auto_asconf, sctp_auto_asconf, SCTPCTL_AUTOASCONF)
864SCTP_UINT_SYSCTL(ecn_enable, sctp_ecn_enable, SCTPCTL_ECN_ENABLE)
865SCTP_UINT_SYSCTL(pr_enable, sctp_pr_enable, SCTPCTL_PR_ENABLE)
866SYSCTL_PROC(_net_inet_sctp, OID_AUTO, auth_enable, CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW,
867    NULL, 0, sctp_sysctl_handle_auth, "IU", SCTPCTL_AUTH_ENABLE_DESC);
868SYSCTL_PROC(_net_inet_sctp, OID_AUTO, asconf_enable, CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW,
869    NULL, 0, sctp_sysctl_handle_asconf, "IU", SCTPCTL_ASCONF_ENABLE_DESC);
870SCTP_UINT_SYSCTL(reconfig_enable, sctp_reconfig_enable, SCTPCTL_RECONFIG_ENABLE)
871SCTP_UINT_SYSCTL(nrsack_enable, sctp_nrsack_enable, SCTPCTL_NRSACK_ENABLE)
872SCTP_UINT_SYSCTL(pktdrop_enable, sctp_pktdrop_enable, SCTPCTL_PKTDROP_ENABLE)
873SCTP_UINT_SYSCTL(peer_chkoh, sctp_peer_chunk_oh, SCTPCTL_PEER_CHKOH)
874SCTP_UINT_SYSCTL(maxburst, sctp_max_burst_default, SCTPCTL_MAXBURST)
875SCTP_UINT_SYSCTL(fr_maxburst, sctp_fr_max_burst_default, SCTPCTL_FRMAXBURST)
876SCTP_UINT_SYSCTL(maxchunks, sctp_max_chunks_on_queue, SCTPCTL_MAXCHUNKS)
877SCTP_UINT_SYSCTL(tcbhashsize, sctp_hashtblsize, SCTPCTL_TCBHASHSIZE)
878SCTP_UINT_SYSCTL(pcbhashsize, sctp_pcbtblsize, SCTPCTL_PCBHASHSIZE)
879SCTP_UINT_SYSCTL(min_split_point, sctp_min_split_point, SCTPCTL_MIN_SPLIT_POINT)
880SCTP_UINT_SYSCTL(chunkscale, sctp_chunkscale, SCTPCTL_CHUNKSCALE)
881SCTP_UINT_SYSCTL(delayed_sack_time, sctp_delayed_sack_time_default, SCTPCTL_DELAYED_SACK_TIME)
882SCTP_UINT_SYSCTL(sack_freq, sctp_sack_freq_default, SCTPCTL_SACK_FREQ)
883SCTP_UINT_SYSCTL(sys_resource, sctp_system_free_resc_limit, SCTPCTL_SYS_RESOURCE)
884SCTP_UINT_SYSCTL(asoc_resource, sctp_asoc_free_resc_limit, SCTPCTL_ASOC_RESOURCE)
885SCTP_UINT_SYSCTL(heartbeat_interval, sctp_heartbeat_interval_default, SCTPCTL_HEARTBEAT_INTERVAL)
886SCTP_UINT_SYSCTL(pmtu_raise_time, sctp_pmtu_raise_time_default, SCTPCTL_PMTU_RAISE_TIME)
887SCTP_UINT_SYSCTL(shutdown_guard_time, sctp_shutdown_guard_time_default, SCTPCTL_SHUTDOWN_GUARD_TIME)
888SCTP_UINT_SYSCTL(secret_lifetime, sctp_secret_lifetime_default, SCTPCTL_SECRET_LIFETIME)
889SCTP_UINT_SYSCTL(rto_max, sctp_rto_max_default, SCTPCTL_RTO_MAX)
890SCTP_UINT_SYSCTL(rto_min, sctp_rto_min_default, SCTPCTL_RTO_MIN)
891SCTP_UINT_SYSCTL(rto_initial, sctp_rto_initial_default, SCTPCTL_RTO_INITIAL)
892SCTP_UINT_SYSCTL(init_rto_max, sctp_init_rto_max_default, SCTPCTL_INIT_RTO_MAX)
893SCTP_UINT_SYSCTL(valid_cookie_life, sctp_valid_cookie_life_default, SCTPCTL_VALID_COOKIE_LIFE)
894SCTP_UINT_SYSCTL(init_rtx_max, sctp_init_rtx_max_default, SCTPCTL_INIT_RTX_MAX)
895SCTP_UINT_SYSCTL(assoc_rtx_max, sctp_assoc_rtx_max_default, SCTPCTL_ASSOC_RTX_MAX)
896SCTP_UINT_SYSCTL(path_rtx_max, sctp_path_rtx_max_default, SCTPCTL_PATH_RTX_MAX)
897SCTP_UINT_SYSCTL(path_pf_threshold, sctp_path_pf_threshold, SCTPCTL_PATH_PF_THRESHOLD)
898SCTP_UINT_SYSCTL(add_more_on_output, sctp_add_more_threshold, SCTPCTL_ADD_MORE_ON_OUTPUT)
899SCTP_UINT_SYSCTL(incoming_streams, sctp_nr_incoming_streams_default, SCTPCTL_INCOMING_STREAMS)
900SCTP_UINT_SYSCTL(outgoing_streams, sctp_nr_outgoing_streams_default, SCTPCTL_OUTGOING_STREAMS)
901SCTP_UINT_SYSCTL(cmt_on_off, sctp_cmt_on_off, SCTPCTL_CMT_ON_OFF)
902SCTP_UINT_SYSCTL(cmt_use_dac, sctp_cmt_use_dac, SCTPCTL_CMT_USE_DAC)
903SCTP_UINT_SYSCTL(cwnd_maxburst, sctp_use_cwnd_based_maxburst, SCTPCTL_CWND_MAXBURST)
904SCTP_UINT_SYSCTL(nat_friendly, sctp_nat_friendly, SCTPCTL_NAT_FRIENDLY)
905SCTP_UINT_SYSCTL(abc_l_var, sctp_L2_abc_variable, SCTPCTL_ABC_L_VAR)
906SCTP_UINT_SYSCTL(max_chained_mbufs, sctp_mbuf_threshold_count, SCTPCTL_MAX_CHAINED_MBUFS)
907SCTP_UINT_SYSCTL(do_sctp_drain, sctp_do_drain, SCTPCTL_DO_SCTP_DRAIN)
908SCTP_UINT_SYSCTL(hb_max_burst, sctp_hb_maxburst, SCTPCTL_HB_MAX_BURST)
909SCTP_UINT_SYSCTL(abort_at_limit, sctp_abort_if_one_2_one_hits_limit, SCTPCTL_ABORT_AT_LIMIT)
910SCTP_UINT_SYSCTL(min_residual, sctp_min_residual, SCTPCTL_MIN_RESIDUAL)
911SCTP_UINT_SYSCTL(max_retran_chunk, sctp_max_retran_chunk, SCTPCTL_MAX_RETRAN_CHUNK)
912SCTP_UINT_SYSCTL(log_level, sctp_logging_level, SCTPCTL_LOGGING_LEVEL)
913SCTP_UINT_SYSCTL(default_cc_module, sctp_default_cc_module, SCTPCTL_DEFAULT_CC_MODULE)
914SCTP_UINT_SYSCTL(default_ss_module, sctp_default_ss_module, SCTPCTL_DEFAULT_SS_MODULE)
915SCTP_UINT_SYSCTL(default_frag_interleave, sctp_default_frag_interleave, SCTPCTL_DEFAULT_FRAG_INTERLEAVE)
916SCTP_UINT_SYSCTL(mobility_base, sctp_mobility_base, SCTPCTL_MOBILITY_BASE)
917SCTP_UINT_SYSCTL(mobility_fasthandoff, sctp_mobility_fasthandoff, SCTPCTL_MOBILITY_FASTHANDOFF)
918#if defined(SCTP_LOCAL_TRACE_BUF)
919SYSCTL_PROC(_net_inet_sctp, OID_AUTO, log, CTLFLAG_VNET | CTLTYPE_STRUCT | CTLFLAG_RD,
920    NULL, 0, sctp_sysctl_handle_trace_log, "S,sctplog", "SCTP logging (struct sctp_log)");
921SYSCTL_PROC(_net_inet_sctp, OID_AUTO, clear_trace, CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW,
922    NULL, 0, sctp_sysctl_handle_trace_log_clear, "IU", "Clear SCTP Logging buffer");
923#endif
924SYSCTL_PROC(_net_inet_sctp, OID_AUTO, udp_tunneling_port, CTLFLAG_VNET | CTLTYPE_UINT | CTLFLAG_RW,
925    NULL, 0, sctp_sysctl_handle_udp_tunneling, "IU", SCTPCTL_UDP_TUNNELING_PORT_DESC);
926SCTP_UINT_SYSCTL(enable_sack_immediately, sctp_enable_sack_immediately, SCTPCTL_SACK_IMMEDIATELY_ENABLE)
927SCTP_UINT_SYSCTL(nat_friendly_init, sctp_inits_include_nat_friendly, SCTPCTL_NAT_FRIENDLY_INITS)
928SCTP_UINT_SYSCTL(vtag_time_wait, sctp_vtag_time_wait, SCTPCTL_TIME_WAIT)
929SCTP_UINT_SYSCTL(buffer_splitting, sctp_buffer_splitting, SCTPCTL_BUFFER_SPLITTING)
930SCTP_UINT_SYSCTL(initial_cwnd, sctp_initial_cwnd, SCTPCTL_INITIAL_CWND)
931SCTP_UINT_SYSCTL(rttvar_bw, sctp_rttvar_bw, SCTPCTL_RTTVAR_BW)
932SCTP_UINT_SYSCTL(rttvar_rtt, sctp_rttvar_rtt, SCTPCTL_RTTVAR_RTT)
933SCTP_UINT_SYSCTL(rttvar_eqret, sctp_rttvar_eqret, SCTPCTL_RTTVAR_EQRET)
934SCTP_UINT_SYSCTL(rttvar_steady_step, sctp_steady_step, SCTPCTL_RTTVAR_STEADYS)
935SCTP_UINT_SYSCTL(use_dcccecn, sctp_use_dccc_ecn, SCTPCTL_RTTVAR_DCCCECN)
936SCTP_UINT_SYSCTL(blackhole, sctp_blackhole, SCTPCTL_BLACKHOLE)
937SCTP_UINT_SYSCTL(diag_info_code, sctp_diag_info_code, SCTPCTL_DIAG_INFO_CODE)
938#ifdef SCTP_DEBUG
939SCTP_UINT_SYSCTL(debug, sctp_debug_on, SCTPCTL_DEBUG)
940#endif
941#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
942SCTP_UINT_SYSCTL(output_unlocked, sctp_output_unlocked, SCTPCTL_OUTPUT_UNLOCKED)
943#endif
944SYSCTL_PROC(_net_inet_sctp, OID_AUTO, stats, CTLFLAG_VNET | CTLTYPE_STRUCT | CTLFLAG_RW,
945    NULL, 0, sctp_sysctl_handle_stats, "S,sctpstat", "SCTP statistics (struct sctp_stat)");
946SYSCTL_PROC(_net_inet_sctp, OID_AUTO, assoclist, CTLFLAG_VNET | CTLTYPE_OPAQUE | CTLFLAG_RD,
947    NULL, 0, sctp_sysctl_handle_assoclist, "S,xassoc", "List of active SCTP associations");
948