1/*-
2 * Copyright (c) 2007, by Cisco Systems, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * a) Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 *
10 * b) Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the distribution.
13 *
14 * c) Neither the name of Cisco Systems, Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sys/netinet/sctp_sysctl.c 170091 2007-05-29 09:29:03Z rrs $");
33
34#include <netinet/sctp_os.h>
35#include <netinet/sctp_constants.h>
36#include <netinet/sctp_sysctl.h>
37#include <netinet/sctp_pcb.h>
38#include <netinet/sctputil.h>
39#include <netinet/sctp_output.h>
40/*
41 * sysctl tunable variables
42 */
43uint32_t sctp_sendspace = (128 * 1024);
44uint32_t sctp_recvspace = 128 * (1024 +
45#ifdef INET6
46 sizeof(struct sockaddr_in6)
47#else
48 sizeof(struct sockaddr_in)
49#endif
50);
51uint32_t sctp_mbuf_threshold_count = SCTP_DEFAULT_MBUFS_IN_CHAIN;
52uint32_t sctp_auto_asconf = SCTP_DEFAULT_AUTO_ASCONF;
53uint32_t sctp_ecn_enable = 1;
54uint32_t sctp_ecn_nonce = 0;
55uint32_t sctp_strict_sacks = 0;
56uint32_t sctp_no_csum_on_loopback = 1;
57uint32_t sctp_strict_init = 1;
58uint32_t sctp_abort_if_one_2_one_hits_limit = 0;
59uint32_t sctp_strict_data_order = 0;
60
61uint32_t sctp_peer_chunk_oh = sizeof(struct mbuf);
62uint32_t sctp_max_burst_default = SCTP_DEF_MAX_BURST;
63uint32_t sctp_use_cwnd_based_maxburst = 1;
64uint32_t sctp_do_drain = 1;
65uint32_t sctp_hb_maxburst = SCTP_DEF_MAX_BURST;
66
67uint32_t sctp_max_chunks_on_queue = SCTP_ASOC_MAX_CHUNKS_ON_QUEUE;
68uint32_t sctp_delayed_sack_time_default = SCTP_RECV_MSEC;
69uint32_t sctp_sack_freq_default = SCTP_DEFAULT_SACK_FREQ;
70uint32_t sctp_heartbeat_interval_default = SCTP_HB_DEFAULT_MSEC;
71uint32_t sctp_pmtu_raise_time_default = SCTP_DEF_PMTU_RAISE_SEC;
72uint32_t sctp_shutdown_guard_time_default = SCTP_DEF_MAX_SHUTDOWN_SEC;
73uint32_t sctp_secret_lifetime_default = SCTP_DEFAULT_SECRET_LIFE_SEC;
74uint32_t sctp_rto_max_default = SCTP_RTO_UPPER_BOUND;
75uint32_t sctp_rto_min_default = SCTP_RTO_LOWER_BOUND;
76uint32_t sctp_rto_initial_default = SCTP_RTO_INITIAL;
77uint32_t sctp_init_rto_max_default = SCTP_RTO_UPPER_BOUND;
78uint32_t sctp_valid_cookie_life_default = SCTP_DEFAULT_COOKIE_LIFE;
79uint32_t sctp_init_rtx_max_default = SCTP_DEF_MAX_INIT;
80uint32_t sctp_assoc_rtx_max_default = SCTP_DEF_MAX_SEND;
81uint32_t sctp_path_rtx_max_default = SCTP_DEF_MAX_PATH_RTX;
82uint32_t sctp_nr_outgoing_streams_default = SCTP_OSTREAM_INITIAL;
83uint32_t sctp_add_more_threshold = SCTP_DEFAULT_ADD_MORE;
84uint32_t sctp_asoc_free_resc_limit = SCTP_DEF_ASOC_RESC_LIMIT;
85uint32_t sctp_system_free_resc_limit = SCTP_DEF_SYSTEM_RESC_LIMIT;
86
87uint32_t sctp_min_split_point = SCTP_DEFAULT_SPLIT_POINT_MIN;
88uint32_t sctp_pcbtblsize = SCTP_PCBHASHSIZE;
89uint32_t sctp_hashtblsize = SCTP_TCBHASHSIZE;
90uint32_t sctp_chunkscale = SCTP_CHUNKQUEUE_SCALE;
91
92uint32_t sctp_cmt_on_off = 0;
93uint32_t sctp_cmt_use_dac = 0;
94uint32_t sctp_max_retran_chunk = SCTPCTL_MAX_RETRAN_CHUNK_DEFAULT;
95
96
97uint32_t sctp_L2_abc_variable = 1;
98uint32_t sctp_early_fr = 0;
99uint32_t sctp_early_fr_msec = SCTP_MINFR_MSEC_TIMER;
100uint32_t sctp_says_check_for_deadlock = 0;
101uint32_t sctp_asconf_auth_nochk = 0;
102uint32_t sctp_auth_disable = 0;
103uint32_t sctp_nat_friendly = 1;
104uint32_t sctp_min_residual = SCTPCTL_MIN_RESIDUAL_DEFAULT;;
105
106
107struct sctpstat sctpstat;
108
109#ifdef SCTP_DEBUG
110uint32_t sctp_debug_on = 0;
111
112#endif
113
114
115
116/* It returns an upper limit. No filtering is done here */
117static unsigned int
118number_of_addresses(struct sctp_inpcb *inp)
119{
120 int cnt;
121 struct sctp_vrf *vrf;
122 struct sctp_ifn *sctp_ifn;
123 struct sctp_ifa *sctp_ifa;
124 struct sctp_laddr *laddr;
125
126 cnt = 0;
127 /* neither Mac OS X nor FreeBSD support mulitple routing functions */
128 if ((vrf = sctp_find_vrf(inp->def_vrf_id)) == NULL) {
129 return (0);
130 }
131 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
132 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
133 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
134 if ((sctp_ifa->address.sa.sa_family == AF_INET) ||
135 (sctp_ifa->address.sa.sa_family == AF_INET6)) {
136 cnt++;
137 }
138 }
139 }
140 } else {
141 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
142 if ((laddr->ifa->address.sa.sa_family == AF_INET) ||
143 (laddr->ifa->address.sa.sa_family == AF_INET6)) {
144 cnt++;
145 }
146 }
147 }
148 return (cnt);
149}
150
151static int
152copy_out_local_addresses(struct sctp_inpcb *inp, struct sctp_tcb *stcb, struct sysctl_req *req)
153{
154 struct sctp_ifn *sctp_ifn;
155 struct sctp_ifa *sctp_ifa;
156 int loopback_scope, ipv4_local_scope, local_scope, site_scope;
157 int ipv4_addr_legal, ipv6_addr_legal;
158 struct sctp_vrf *vrf;
159 struct xsctp_laddr xladdr;
160 struct sctp_laddr *laddr;
161 int error;
162
163 /* Turn on all the appropriate scope */
164 if (stcb) {
165 /* use association specific values */
166 loopback_scope = stcb->asoc.loopback_scope;
167 ipv4_local_scope = stcb->asoc.ipv4_local_scope;
168 local_scope = stcb->asoc.local_scope;
169 site_scope = stcb->asoc.site_scope;
170 } else {
171 /* use generic values for endpoints */
172 loopback_scope = 1;
173 ipv4_local_scope = 1;
174 local_scope = 1;
175 site_scope = 1;
176 }
177
178 /* use only address families of interest */
179 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
180 ipv6_addr_legal = 1;
181 if (SCTP_IPV6_V6ONLY(inp)) {
182 ipv4_addr_legal = 0;
183 } else {
184 ipv4_addr_legal = 1;
185 }
186 } else {
187 ipv4_addr_legal = 1;
188 ipv6_addr_legal = 0;
189 }
190
191 error = 0;
192
193 /* neither Mac OS X nor FreeBSD support mulitple routing functions */
194 if ((vrf = sctp_find_vrf(inp->def_vrf_id)) == NULL) {
195 return (-1);
196 }
197 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
198 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
199 if ((loopback_scope == 0) && SCTP_IFN_IS_IFT_LOOP(sctp_ifn))
200 /* Skip loopback if loopback_scope not set */
201 continue;
202 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
203 if (stcb) {
204 /*
205 * ignore if blacklisted at
206 * association level
207 */
208 if (sctp_is_addr_restricted(stcb, sctp_ifa))
209 continue;
210 }
211 if ((sctp_ifa->address.sa.sa_family == AF_INET) && (ipv4_addr_legal)) {
212 struct sockaddr_in *sin;
213
214 sin = (struct sockaddr_in *)&sctp_ifa->address.sa;
215 if (sin->sin_addr.s_addr == 0)
216 continue;
217 if ((ipv4_local_scope == 0) && (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)))
218 continue;
219 } else if ((sctp_ifa->address.sa.sa_family == AF_INET6) && (ipv6_addr_legal)) {
220 struct sockaddr_in6 *sin6;
221
222 sin6 = (struct sockaddr_in6 *)&sctp_ifa->address.sa;
223 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
224 continue;
225 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
226 if (local_scope == 0)
227 continue;
228 if (sin6->sin6_scope_id == 0) {
229 /*
230 * bad link local
231 * address
232 */
233 if (sa6_recoverscope(sin6) != 0)
234 continue;
235 }
236 }
237 if ((site_scope == 0) && (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)))
238 continue;
239 } else
240 continue;
241 memset((void *)&xladdr, 0, sizeof(union sctp_sockstore));
242 memcpy((void *)&xladdr.address, (const void *)&sctp_ifa->address, sizeof(union sctp_sockstore));
243 (void)SCTP_GETTIME_TIMEVAL(&xladdr.start_time);
244 SCTP_INP_RUNLOCK(inp);
245 SCTP_INP_INFO_RUNLOCK();
246 error = SYSCTL_OUT(req, &xladdr, sizeof(struct xsctp_laddr));
247 if (error)
248 return (error);
249 else {
250 SCTP_INP_INFO_RLOCK();
251 SCTP_INP_RLOCK(inp);
252 }
253 }
254 }
255 } else {
256 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
257 /* ignore if blacklisted at association level */
258 if (stcb && sctp_is_addr_restricted(stcb, laddr->ifa))
259 continue;
260 memset((void *)&xladdr, 0, sizeof(union sctp_sockstore));
261 memcpy((void *)&xladdr.address, (const void *)&laddr->ifa->address, sizeof(union sctp_sockstore));
262 xladdr.start_time = laddr->start_time;
263 SCTP_INP_RUNLOCK(inp);
264 SCTP_INP_INFO_RUNLOCK();
265 error = SYSCTL_OUT(req, &xladdr, sizeof(struct xsctp_laddr));
266 if (error)
267 return (error);
268 else {
269 SCTP_INP_INFO_RLOCK();
270 SCTP_INP_RLOCK(inp);
271 }
272 }
273 }
274 memset((void *)&xladdr, 0, sizeof(union sctp_sockstore));
275 xladdr.last = 1;
276 error = SYSCTL_OUT(req, &xladdr, sizeof(struct xsctp_laddr));
277 if (error)
278 return (error);
279 else
280 return (0);
281}
282
283/*
284 * sysctl functions
285 */
286static int
287sctp_assoclist(SYSCTL_HANDLER_ARGS)
288{
289 unsigned int number_of_endpoints;
290 unsigned int number_of_local_addresses;
291 unsigned int number_of_associations;
292 unsigned int number_of_remote_addresses;
293 unsigned int n;
294 int error;
295 struct sctp_inpcb *inp;
296 struct sctp_tcb *stcb;
297 struct sctp_nets *net;
298 struct xsctp_inpcb xinpcb;
299 struct xsctp_tcb xstcb;
300 struct xsctp_raddr xraddr;
301
302 number_of_endpoints = 0;
303 number_of_local_addresses = 0;
304 number_of_associations = 0;
305 number_of_remote_addresses = 0;
306
307 SCTP_INP_INFO_RLOCK();
308 if (req->oldptr == USER_ADDR_NULL) {
309 LIST_FOREACH(inp, &sctppcbinfo.listhead, sctp_list) {
310 SCTP_INP_RLOCK(inp);
311 number_of_endpoints++;
312 number_of_local_addresses += number_of_addresses(inp);
313 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
314 number_of_associations++;
315 number_of_local_addresses += number_of_addresses(inp);
316 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
317 number_of_remote_addresses++;
318 }
319 }
320 SCTP_INP_RUNLOCK(inp);
321 }
322 SCTP_INP_INFO_RUNLOCK();
323 n = (number_of_endpoints + 1) * sizeof(struct xsctp_inpcb) +
324 (number_of_local_addresses + number_of_endpoints + number_of_associations) * sizeof(struct xsctp_laddr) +
325 (number_of_associations + number_of_endpoints) * sizeof(struct xsctp_tcb) +
326 (number_of_remote_addresses + number_of_associations) * sizeof(struct xsctp_raddr);
327
328 /* request some more memory than needed */
329 req->oldidx = (n + n / 8);
330 return 0;
331 }
332 if (req->newptr != USER_ADDR_NULL) {
333 SCTP_INP_INFO_RUNLOCK();
334 return EPERM;
335 }
336 LIST_FOREACH(inp, &sctppcbinfo.listhead, sctp_list) {
337 SCTP_INP_RLOCK(inp);
338 xinpcb.last = 0;
339 xinpcb.local_port = ntohs(inp->sctp_lport);
340 xinpcb.flags = inp->sctp_flags;
341 xinpcb.features = inp->sctp_features;
342 xinpcb.total_sends = inp->total_sends;
343 xinpcb.total_recvs = inp->total_recvs;
344 xinpcb.total_nospaces = inp->total_nospaces;
345 xinpcb.fragmentation_point = inp->sctp_frag_point;
346 xinpcb.qlen = inp->sctp_socket->so_qlen;
347 xinpcb.maxqlen = inp->sctp_socket->so_qlimit;
348 SCTP_INP_INCR_REF(inp);
349 SCTP_INP_RUNLOCK(inp);
350 SCTP_INP_INFO_RUNLOCK();
351 error = SYSCTL_OUT(req, &xinpcb, sizeof(struct xsctp_inpcb));
352 if (error) {
353 SCTP_INP_DECR_REF(inp);
354 return error;
355 }
356 SCTP_INP_INFO_RLOCK();
357 SCTP_INP_RLOCK(inp);
358 error = copy_out_local_addresses(inp, NULL, req);
359 if (error) {
360 SCTP_INP_DECR_REF(inp);
361 return error;
362 }
363 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
364 SCTP_TCB_LOCK(stcb);
365 atomic_add_int(&stcb->asoc.refcnt, 1);
366 SCTP_TCB_UNLOCK(stcb);
367 xstcb.last = 0;
368 xstcb.local_port = ntohs(inp->sctp_lport);
369 xstcb.remote_port = ntohs(stcb->rport);
370 if (stcb->asoc.primary_destination != NULL)
371 xstcb.primary_addr = stcb->asoc.primary_destination->ro._l_addr;
372 xstcb.heartbeat_interval = stcb->asoc.heart_beat_delay;
373 xstcb.state = SCTP_GET_STATE(&stcb->asoc); /* FIXME */
374 xstcb.in_streams = stcb->asoc.streamincnt;
375 xstcb.out_streams = stcb->asoc.streamoutcnt;
376 xstcb.max_nr_retrans = stcb->asoc.overall_error_count;
377 xstcb.primary_process = 0; /* not really supported
378 * yet */
379 xstcb.T1_expireries = stcb->asoc.timoinit + stcb->asoc.timocookie;
380 xstcb.T2_expireries = stcb->asoc.timoshutdown + stcb->asoc.timoshutdownack;
381 xstcb.retransmitted_tsns = stcb->asoc.marked_retrans;
382 xstcb.start_time = stcb->asoc.start_time;
383 xstcb.discontinuity_time = stcb->asoc.discontinuity_time;
384
385 xstcb.total_sends = stcb->total_sends;
386 xstcb.total_recvs = stcb->total_recvs;
387 xstcb.local_tag = stcb->asoc.my_vtag;
388 xstcb.remote_tag = stcb->asoc.peer_vtag;
389 xstcb.initial_tsn = stcb->asoc.init_seq_number;
390 xstcb.highest_tsn = stcb->asoc.sending_seq - 1;
391 xstcb.cumulative_tsn = stcb->asoc.last_acked_seq;
392 xstcb.cumulative_tsn_ack = stcb->asoc.cumulative_tsn;
393 xstcb.mtu = stcb->asoc.smallest_mtu;
394 xstcb.refcnt = stcb->asoc.refcnt;
395 SCTP_INP_RUNLOCK(inp);
396 SCTP_INP_INFO_RUNLOCK();
397 error = SYSCTL_OUT(req, &xstcb, sizeof(struct xsctp_tcb));
398 if (error) {
399 SCTP_INP_DECR_REF(inp);
400 atomic_add_int(&stcb->asoc.refcnt, -1);
401 return error;
402 }
403 SCTP_INP_INFO_RLOCK();
404 SCTP_INP_RLOCK(inp);
405 error = copy_out_local_addresses(inp, stcb, req);
406 if (error) {
407 SCTP_INP_DECR_REF(inp);
408 atomic_add_int(&stcb->asoc.refcnt, -1);
409 return error;
410 }
411 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
412 xraddr.last = 0;
413 xraddr.address = net->ro._l_addr;
414 xraddr.active = ((net->dest_state & SCTP_ADDR_REACHABLE) == SCTP_ADDR_REACHABLE);
415 xraddr.confirmed = ((net->dest_state & SCTP_ADDR_UNCONFIRMED) == 0);
416 xraddr.heartbeat_enabled = ((net->dest_state & SCTP_ADDR_NOHB) == 0);
417 xraddr.rto = net->RTO;
418 xraddr.max_path_rtx = net->failure_threshold;
419 xraddr.rtx = net->marked_retrans;
420 xraddr.error_counter = net->error_count;
421 xraddr.cwnd = net->cwnd;
422 xraddr.flight_size = net->flight_size;
423 xraddr.mtu = net->mtu;
424 xraddr.start_time = net->start_time;
425 SCTP_INP_RUNLOCK(inp);
426 SCTP_INP_INFO_RUNLOCK();
427 error = SYSCTL_OUT(req, &xraddr, sizeof(struct xsctp_raddr));
428 if (error) {
429 SCTP_INP_DECR_REF(inp);
430 atomic_add_int(&stcb->asoc.refcnt, -1);
431 return error;
432 }
433 SCTP_INP_INFO_RLOCK();
434 SCTP_INP_RLOCK(inp);
435 }
436 atomic_add_int(&stcb->asoc.refcnt, -1);
437 memset((void *)&xraddr, 0, sizeof(struct xsctp_raddr));
438 xraddr.last = 1;
439 SCTP_INP_RUNLOCK(inp);
440 SCTP_INP_INFO_RUNLOCK();
441 error = SYSCTL_OUT(req, &xraddr, sizeof(struct xsctp_raddr));
442 if (error) {
443 SCTP_INP_DECR_REF(inp);
444 return error;
445 }
446 SCTP_INP_INFO_RLOCK();
447 SCTP_INP_RLOCK(inp);
448 }
449 SCTP_INP_RUNLOCK(inp);
450 SCTP_INP_INFO_RUNLOCK();
451 memset((void *)&xstcb, 0, sizeof(struct xsctp_tcb));
452 xstcb.last = 1;
453 error = SYSCTL_OUT(req, &xstcb, sizeof(struct xsctp_tcb));
454 if (error) {
455 return error;
456 }
457 SCTP_INP_INFO_RLOCK();
458 SCTP_INP_DECR_REF(inp);
459 }
460 SCTP_INP_INFO_RUNLOCK();
461
462 memset((void *)&xinpcb, 0, sizeof(struct xsctp_inpcb));
463 xinpcb.last = 1;
464 error = SYSCTL_OUT(req, &xinpcb, sizeof(struct xsctp_inpcb));
465 return error;
466}
467
468
469/*
470 * sysctl definitions
471 */
472
473SYSCTL_INT(_net_inet_sctp, OID_AUTO, sendspace, CTLFLAG_RW,
474 &sctp_sendspace, 0, "Maximum outgoing SCTP buffer size");
475
476SYSCTL_INT(_net_inet_sctp, OID_AUTO, recvspace, CTLFLAG_RW,
477 &sctp_recvspace, 0, "Maximum incoming SCTP buffer size");
478
479#if defined(__FreeBSD__) || defined(SCTP_APPLE_AUTO_ASCONF)
480SYSCTL_INT(_net_inet_sctp, OID_AUTO, auto_asconf, CTLFLAG_RW,
481 &sctp_auto_asconf, 0, "Enable SCTP Auto-ASCONF");
482#endif
483
484SYSCTL_INT(_net_inet_sctp, OID_AUTO, ecn_enable, CTLFLAG_RW,
485 &sctp_ecn_enable, 0, "Enable SCTP ECN");
486
487SYSCTL_INT(_net_inet_sctp, OID_AUTO, ecn_nonce, CTLFLAG_RW,
488 &sctp_ecn_nonce, 0, "Enable SCTP ECN Nonce");
489
490SYSCTL_INT(_net_inet_sctp, OID_AUTO, strict_sacks, CTLFLAG_RW,
491 &sctp_strict_sacks, 0, "Enable SCTP Strict SACK checking");
492
493SYSCTL_INT(_net_inet_sctp, OID_AUTO, loopback_nocsum, CTLFLAG_RW,
494 &sctp_no_csum_on_loopback, 0,
495 "Enable NO Csum on packets sent on loopback");
496
497SYSCTL_INT(_net_inet_sctp, OID_AUTO, strict_init, CTLFLAG_RW,
498 &sctp_strict_init, 0,
499 "Enable strict INIT/INIT-ACK singleton enforcement");
500
501SYSCTL_INT(_net_inet_sctp, OID_AUTO, peer_chkoh, CTLFLAG_RW,
502 &sctp_peer_chunk_oh, 0,
503 "Amount to debit peers rwnd per chunk sent");
504
505SYSCTL_INT(_net_inet_sctp, OID_AUTO, maxburst, CTLFLAG_RW,
506 &sctp_max_burst_default, 0,
507 "Default max burst for sctp endpoints");
508
509SYSCTL_INT(_net_inet_sctp, OID_AUTO, maxchunks, CTLFLAG_RW,
510 &sctp_max_chunks_on_queue, 0,
511 "Default max chunks on queue per asoc");
512
513SYSCTL_INT(_net_inet_sctp, OID_AUTO, tcbhashsize, CTLFLAG_RW,
514 &sctp_hashtblsize, 0,
515 "Tuneable for Hash table sizes");
516
517SYSCTL_INT(_net_inet_sctp, OID_AUTO, min_split_point, CTLFLAG_RW,
518 &sctp_min_split_point, 0,
519 "Minimum size when splitting a chunk");
520
521SYSCTL_INT(_net_inet_sctp, OID_AUTO, pcbhashsize, CTLFLAG_RW,
522 &sctp_pcbtblsize, 0,
523 "Tuneable for PCB Hash table sizes");
524
525SYSCTL_INT(_net_inet_sctp, OID_AUTO, sys_resource, CTLFLAG_RW,
526 &sctp_system_free_resc_limit, 0,
527 "Max number of cached resources in the system");
528
529SYSCTL_INT(_net_inet_sctp, OID_AUTO, asoc_resource, CTLFLAG_RW,
530 &sctp_asoc_free_resc_limit, 0,
531 "Max number of cached resources in an asoc");
532
533SYSCTL_INT(_net_inet_sctp, OID_AUTO, chunkscale, CTLFLAG_RW,
534 &sctp_chunkscale, 0,
535 "Tuneable for Scaling of number of chunks and messages");
536
537SYSCTL_UINT(_net_inet_sctp, OID_AUTO, delayed_sack_time, CTLFLAG_RW,
538 &sctp_delayed_sack_time_default, 0,
539 "Default delayed SACK timer in msec");
540
541SYSCTL_UINT(_net_inet_sctp, OID_AUTO, sack_freq, CTLFLAG_RW,
542 &sctp_sack_freq_default, 0,
543 "Default SACK frequency");
544
545SYSCTL_UINT(_net_inet_sctp, OID_AUTO, heartbeat_interval, CTLFLAG_RW,
546 &sctp_heartbeat_interval_default, 0,
547 "Default heartbeat interval in msec");
548
549SYSCTL_UINT(_net_inet_sctp, OID_AUTO, pmtu_raise_time, CTLFLAG_RW,
550 &sctp_pmtu_raise_time_default, 0,
551 "Default PMTU raise timer in sec");
552
553SYSCTL_UINT(_net_inet_sctp, OID_AUTO, shutdown_guard_time, CTLFLAG_RW,
554 &sctp_shutdown_guard_time_default, 0,
555 "Default shutdown guard timer in sec");
556
557SYSCTL_UINT(_net_inet_sctp, OID_AUTO, secret_lifetime, CTLFLAG_RW,
558 &sctp_secret_lifetime_default, 0,
559 "Default secret lifetime in sec");
560
561SYSCTL_UINT(_net_inet_sctp, OID_AUTO, rto_max, CTLFLAG_RW,
562 &sctp_rto_max_default, 0,
563 "Default maximum retransmission timeout in msec");
564
565SYSCTL_UINT(_net_inet_sctp, OID_AUTO, rto_min, CTLFLAG_RW,
566 &sctp_rto_min_default, 0,
567 "Default minimum retransmission timeout in msec");
568
569SYSCTL_UINT(_net_inet_sctp, OID_AUTO, rto_initial, CTLFLAG_RW,
570 &sctp_rto_initial_default, 0,
571 "Default initial retransmission timeout in msec");
572
573SYSCTL_UINT(_net_inet_sctp, OID_AUTO, init_rto_max, CTLFLAG_RW,
574 &sctp_init_rto_max_default, 0,
575 "Default maximum retransmission timeout during association setup in msec");
576
577SYSCTL_UINT(_net_inet_sctp, OID_AUTO, valid_cookie_life, CTLFLAG_RW,
578 &sctp_valid_cookie_life_default, 0,
579 "Default cookie lifetime in ticks");
580
581SYSCTL_UINT(_net_inet_sctp, OID_AUTO, init_rtx_max, CTLFLAG_RW,
582 &sctp_init_rtx_max_default, 0,
583 "Default maximum number of retransmission for INIT chunks");
584
585SYSCTL_UINT(_net_inet_sctp, OID_AUTO, assoc_rtx_max, CTLFLAG_RW,
586 &sctp_assoc_rtx_max_default, 0,
587 "Default maximum number of retransmissions per association");
588
589SYSCTL_UINT(_net_inet_sctp, OID_AUTO, path_rtx_max, CTLFLAG_RW,
590 &sctp_path_rtx_max_default, 0,
591 "Default maximum of retransmissions per path");
592
593SYSCTL_UINT(_net_inet_sctp, OID_AUTO, add_more_on_output, CTLFLAG_RW,
594 &sctp_add_more_threshold, 0,
595 "When space wise is it worthwhile to try to add more to a socket send buffer");
596
597SYSCTL_UINT(_net_inet_sctp, OID_AUTO, outgoing_streams, CTLFLAG_RW,
598 &sctp_nr_outgoing_streams_default, 0,
599 "Default number of outgoing streams");
600
601SYSCTL_UINT(_net_inet_sctp, OID_AUTO, cmt_on_off, CTLFLAG_RW,
602 &sctp_cmt_on_off, 0,
603 "CMT ON/OFF flag");
604
605SYSCTL_UINT(_net_inet_sctp, OID_AUTO, cwnd_maxburst, CTLFLAG_RW,
606 &sctp_use_cwnd_based_maxburst, 0,
607 "Use a CWND adjusting maxburst");
608
609SYSCTL_UINT(_net_inet_sctp, OID_AUTO, early_fast_retran, CTLFLAG_RW,
610 &sctp_early_fr, 0,
611 "Early Fast Retransmit with timer");
612
613SYSCTL_UINT(_net_inet_sctp, OID_AUTO, deadlock_detect, CTLFLAG_RW,
614 &sctp_says_check_for_deadlock, 0,
615 "SMP Deadlock detection on/off");
616
617SYSCTL_UINT(_net_inet_sctp, OID_AUTO, early_fast_retran_msec, CTLFLAG_RW,
618 &sctp_early_fr_msec, 0,
619 "Early Fast Retransmit minimum timer value");
620
621SYSCTL_UINT(_net_inet_sctp, OID_AUTO, asconf_auth_nochk, CTLFLAG_RW,
622 &sctp_asconf_auth_nochk, 0,
623 "Disable SCTP ASCONF AUTH requirement");
624
625SYSCTL_UINT(_net_inet_sctp, OID_AUTO, auth_disable, CTLFLAG_RW,
626 &sctp_auth_disable, 0,
627 "Disable SCTP AUTH function");
628
629SYSCTL_UINT(_net_inet_sctp, OID_AUTO, nat_friendly, CTLFLAG_RW,
630 &sctp_nat_friendly, 0,
631 "SCTP NAT friendly operation");
632
633SYSCTL_INT(_net_inet_sctp, OID_AUTO, abc_l_var, CTLFLAG_RW,
634 &sctp_L2_abc_variable, 0,
635 "SCTP ABC max increase per SACK (L)");
636
637SYSCTL_INT(_net_inet_sctp, OID_AUTO, max_chained_mbufs, CTLFLAG_RW,
638 &sctp_mbuf_threshold_count, 0,
639 "Default max number of small mbufs on a chain");
640
641SYSCTL_UINT(_net_inet_sctp, OID_AUTO, cmt_use_dac, CTLFLAG_RW,
642 &sctp_cmt_use_dac, 0,
643 "CMT DAC ON/OFF flag");
644
645SYSCTL_INT(_net_inet_sctp, OID_AUTO, do_sctp_drain, CTLFLAG_RW,
646 &sctp_do_drain, 0,
647 "Should SCTP respond to the drain calls");
648
649SYSCTL_INT(_net_inet_sctp, OID_AUTO, hb_max_burst, CTLFLAG_RW,
650 &sctp_hb_maxburst, 0,
651 "Confirmation Heartbeat max burst?");
652
653SYSCTL_INT(_net_inet_sctp, OID_AUTO, abort_at_limit, CTLFLAG_RW,
654 &sctp_abort_if_one_2_one_hits_limit, 0,
655 "When one-2-one hits qlimit abort");
656
657SYSCTL_INT(_net_inet_sctp, OID_AUTO, strict_data_order, CTLFLAG_RW,
658 &sctp_strict_data_order, 0,
659 "Enforce strict data ordering, abort if control inside data");
660
661SYSCTL_STRUCT(_net_inet_sctp, OID_AUTO, stats, CTLFLAG_RW,
662 &sctpstat, sctpstat,
663 "SCTP statistics (struct sctps_stat, netinet/sctp.h");
664
665SYSCTL_PROC(_net_inet_sctp, OID_AUTO, assoclist, CTLFLAG_RD,
666 0, 0, sctp_assoclist,
667 "S,xassoc", "List of active SCTP associations");
668
669SYSCTL_INT(_net_inet_sctp, OID_AUTO, min_residual, CTLFLAG_RW,
670 &sctp_min_residual, 0,
671 SCTPCTL_MIN_RESIDUAL_DESC);
672
673SYSCTL_INT(_net_inet_sctp, OID_AUTO, max_retran_chunk, CTLFLAG_RW,
674 &sctp_max_retran_chunk, 0,
675 SCTPCTL_MAX_RETRAN_CHUNK_DESC);
676
677#ifdef SCTP_DEBUG
678SYSCTL_INT(_net_inet_sctp, OID_AUTO, debug, CTLFLAG_RW,
679 &sctp_debug_on, 0, "Configure debug output");
680#endif /* SCTP_DEBUG */
2 * Copyright (c) 2007, by Cisco Systems, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * a) Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 *
10 * b) Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the distribution.
13 *
14 * c) Neither the name of Cisco Systems, Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include <sys/cdefs.h>
32__FBSDID("$FreeBSD: head/sys/netinet/sctp_sysctl.c 170091 2007-05-29 09:29:03Z rrs $");
33
34#include <netinet/sctp_os.h>
35#include <netinet/sctp_constants.h>
36#include <netinet/sctp_sysctl.h>
37#include <netinet/sctp_pcb.h>
38#include <netinet/sctputil.h>
39#include <netinet/sctp_output.h>
40/*
41 * sysctl tunable variables
42 */
43uint32_t sctp_sendspace = (128 * 1024);
44uint32_t sctp_recvspace = 128 * (1024 +
45#ifdef INET6
46 sizeof(struct sockaddr_in6)
47#else
48 sizeof(struct sockaddr_in)
49#endif
50);
51uint32_t sctp_mbuf_threshold_count = SCTP_DEFAULT_MBUFS_IN_CHAIN;
52uint32_t sctp_auto_asconf = SCTP_DEFAULT_AUTO_ASCONF;
53uint32_t sctp_ecn_enable = 1;
54uint32_t sctp_ecn_nonce = 0;
55uint32_t sctp_strict_sacks = 0;
56uint32_t sctp_no_csum_on_loopback = 1;
57uint32_t sctp_strict_init = 1;
58uint32_t sctp_abort_if_one_2_one_hits_limit = 0;
59uint32_t sctp_strict_data_order = 0;
60
61uint32_t sctp_peer_chunk_oh = sizeof(struct mbuf);
62uint32_t sctp_max_burst_default = SCTP_DEF_MAX_BURST;
63uint32_t sctp_use_cwnd_based_maxburst = 1;
64uint32_t sctp_do_drain = 1;
65uint32_t sctp_hb_maxburst = SCTP_DEF_MAX_BURST;
66
67uint32_t sctp_max_chunks_on_queue = SCTP_ASOC_MAX_CHUNKS_ON_QUEUE;
68uint32_t sctp_delayed_sack_time_default = SCTP_RECV_MSEC;
69uint32_t sctp_sack_freq_default = SCTP_DEFAULT_SACK_FREQ;
70uint32_t sctp_heartbeat_interval_default = SCTP_HB_DEFAULT_MSEC;
71uint32_t sctp_pmtu_raise_time_default = SCTP_DEF_PMTU_RAISE_SEC;
72uint32_t sctp_shutdown_guard_time_default = SCTP_DEF_MAX_SHUTDOWN_SEC;
73uint32_t sctp_secret_lifetime_default = SCTP_DEFAULT_SECRET_LIFE_SEC;
74uint32_t sctp_rto_max_default = SCTP_RTO_UPPER_BOUND;
75uint32_t sctp_rto_min_default = SCTP_RTO_LOWER_BOUND;
76uint32_t sctp_rto_initial_default = SCTP_RTO_INITIAL;
77uint32_t sctp_init_rto_max_default = SCTP_RTO_UPPER_BOUND;
78uint32_t sctp_valid_cookie_life_default = SCTP_DEFAULT_COOKIE_LIFE;
79uint32_t sctp_init_rtx_max_default = SCTP_DEF_MAX_INIT;
80uint32_t sctp_assoc_rtx_max_default = SCTP_DEF_MAX_SEND;
81uint32_t sctp_path_rtx_max_default = SCTP_DEF_MAX_PATH_RTX;
82uint32_t sctp_nr_outgoing_streams_default = SCTP_OSTREAM_INITIAL;
83uint32_t sctp_add_more_threshold = SCTP_DEFAULT_ADD_MORE;
84uint32_t sctp_asoc_free_resc_limit = SCTP_DEF_ASOC_RESC_LIMIT;
85uint32_t sctp_system_free_resc_limit = SCTP_DEF_SYSTEM_RESC_LIMIT;
86
87uint32_t sctp_min_split_point = SCTP_DEFAULT_SPLIT_POINT_MIN;
88uint32_t sctp_pcbtblsize = SCTP_PCBHASHSIZE;
89uint32_t sctp_hashtblsize = SCTP_TCBHASHSIZE;
90uint32_t sctp_chunkscale = SCTP_CHUNKQUEUE_SCALE;
91
92uint32_t sctp_cmt_on_off = 0;
93uint32_t sctp_cmt_use_dac = 0;
94uint32_t sctp_max_retran_chunk = SCTPCTL_MAX_RETRAN_CHUNK_DEFAULT;
95
96
97uint32_t sctp_L2_abc_variable = 1;
98uint32_t sctp_early_fr = 0;
99uint32_t sctp_early_fr_msec = SCTP_MINFR_MSEC_TIMER;
100uint32_t sctp_says_check_for_deadlock = 0;
101uint32_t sctp_asconf_auth_nochk = 0;
102uint32_t sctp_auth_disable = 0;
103uint32_t sctp_nat_friendly = 1;
104uint32_t sctp_min_residual = SCTPCTL_MIN_RESIDUAL_DEFAULT;;
105
106
107struct sctpstat sctpstat;
108
109#ifdef SCTP_DEBUG
110uint32_t sctp_debug_on = 0;
111
112#endif
113
114
115
116/* It returns an upper limit. No filtering is done here */
117static unsigned int
118number_of_addresses(struct sctp_inpcb *inp)
119{
120 int cnt;
121 struct sctp_vrf *vrf;
122 struct sctp_ifn *sctp_ifn;
123 struct sctp_ifa *sctp_ifa;
124 struct sctp_laddr *laddr;
125
126 cnt = 0;
127 /* neither Mac OS X nor FreeBSD support mulitple routing functions */
128 if ((vrf = sctp_find_vrf(inp->def_vrf_id)) == NULL) {
129 return (0);
130 }
131 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
132 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
133 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
134 if ((sctp_ifa->address.sa.sa_family == AF_INET) ||
135 (sctp_ifa->address.sa.sa_family == AF_INET6)) {
136 cnt++;
137 }
138 }
139 }
140 } else {
141 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
142 if ((laddr->ifa->address.sa.sa_family == AF_INET) ||
143 (laddr->ifa->address.sa.sa_family == AF_INET6)) {
144 cnt++;
145 }
146 }
147 }
148 return (cnt);
149}
150
151static int
152copy_out_local_addresses(struct sctp_inpcb *inp, struct sctp_tcb *stcb, struct sysctl_req *req)
153{
154 struct sctp_ifn *sctp_ifn;
155 struct sctp_ifa *sctp_ifa;
156 int loopback_scope, ipv4_local_scope, local_scope, site_scope;
157 int ipv4_addr_legal, ipv6_addr_legal;
158 struct sctp_vrf *vrf;
159 struct xsctp_laddr xladdr;
160 struct sctp_laddr *laddr;
161 int error;
162
163 /* Turn on all the appropriate scope */
164 if (stcb) {
165 /* use association specific values */
166 loopback_scope = stcb->asoc.loopback_scope;
167 ipv4_local_scope = stcb->asoc.ipv4_local_scope;
168 local_scope = stcb->asoc.local_scope;
169 site_scope = stcb->asoc.site_scope;
170 } else {
171 /* use generic values for endpoints */
172 loopback_scope = 1;
173 ipv4_local_scope = 1;
174 local_scope = 1;
175 site_scope = 1;
176 }
177
178 /* use only address families of interest */
179 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
180 ipv6_addr_legal = 1;
181 if (SCTP_IPV6_V6ONLY(inp)) {
182 ipv4_addr_legal = 0;
183 } else {
184 ipv4_addr_legal = 1;
185 }
186 } else {
187 ipv4_addr_legal = 1;
188 ipv6_addr_legal = 0;
189 }
190
191 error = 0;
192
193 /* neither Mac OS X nor FreeBSD support mulitple routing functions */
194 if ((vrf = sctp_find_vrf(inp->def_vrf_id)) == NULL) {
195 return (-1);
196 }
197 if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
198 LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
199 if ((loopback_scope == 0) && SCTP_IFN_IS_IFT_LOOP(sctp_ifn))
200 /* Skip loopback if loopback_scope not set */
201 continue;
202 LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
203 if (stcb) {
204 /*
205 * ignore if blacklisted at
206 * association level
207 */
208 if (sctp_is_addr_restricted(stcb, sctp_ifa))
209 continue;
210 }
211 if ((sctp_ifa->address.sa.sa_family == AF_INET) && (ipv4_addr_legal)) {
212 struct sockaddr_in *sin;
213
214 sin = (struct sockaddr_in *)&sctp_ifa->address.sa;
215 if (sin->sin_addr.s_addr == 0)
216 continue;
217 if ((ipv4_local_scope == 0) && (IN4_ISPRIVATE_ADDRESS(&sin->sin_addr)))
218 continue;
219 } else if ((sctp_ifa->address.sa.sa_family == AF_INET6) && (ipv6_addr_legal)) {
220 struct sockaddr_in6 *sin6;
221
222 sin6 = (struct sockaddr_in6 *)&sctp_ifa->address.sa;
223 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
224 continue;
225 if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
226 if (local_scope == 0)
227 continue;
228 if (sin6->sin6_scope_id == 0) {
229 /*
230 * bad link local
231 * address
232 */
233 if (sa6_recoverscope(sin6) != 0)
234 continue;
235 }
236 }
237 if ((site_scope == 0) && (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr)))
238 continue;
239 } else
240 continue;
241 memset((void *)&xladdr, 0, sizeof(union sctp_sockstore));
242 memcpy((void *)&xladdr.address, (const void *)&sctp_ifa->address, sizeof(union sctp_sockstore));
243 (void)SCTP_GETTIME_TIMEVAL(&xladdr.start_time);
244 SCTP_INP_RUNLOCK(inp);
245 SCTP_INP_INFO_RUNLOCK();
246 error = SYSCTL_OUT(req, &xladdr, sizeof(struct xsctp_laddr));
247 if (error)
248 return (error);
249 else {
250 SCTP_INP_INFO_RLOCK();
251 SCTP_INP_RLOCK(inp);
252 }
253 }
254 }
255 } else {
256 LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
257 /* ignore if blacklisted at association level */
258 if (stcb && sctp_is_addr_restricted(stcb, laddr->ifa))
259 continue;
260 memset((void *)&xladdr, 0, sizeof(union sctp_sockstore));
261 memcpy((void *)&xladdr.address, (const void *)&laddr->ifa->address, sizeof(union sctp_sockstore));
262 xladdr.start_time = laddr->start_time;
263 SCTP_INP_RUNLOCK(inp);
264 SCTP_INP_INFO_RUNLOCK();
265 error = SYSCTL_OUT(req, &xladdr, sizeof(struct xsctp_laddr));
266 if (error)
267 return (error);
268 else {
269 SCTP_INP_INFO_RLOCK();
270 SCTP_INP_RLOCK(inp);
271 }
272 }
273 }
274 memset((void *)&xladdr, 0, sizeof(union sctp_sockstore));
275 xladdr.last = 1;
276 error = SYSCTL_OUT(req, &xladdr, sizeof(struct xsctp_laddr));
277 if (error)
278 return (error);
279 else
280 return (0);
281}
282
283/*
284 * sysctl functions
285 */
286static int
287sctp_assoclist(SYSCTL_HANDLER_ARGS)
288{
289 unsigned int number_of_endpoints;
290 unsigned int number_of_local_addresses;
291 unsigned int number_of_associations;
292 unsigned int number_of_remote_addresses;
293 unsigned int n;
294 int error;
295 struct sctp_inpcb *inp;
296 struct sctp_tcb *stcb;
297 struct sctp_nets *net;
298 struct xsctp_inpcb xinpcb;
299 struct xsctp_tcb xstcb;
300 struct xsctp_raddr xraddr;
301
302 number_of_endpoints = 0;
303 number_of_local_addresses = 0;
304 number_of_associations = 0;
305 number_of_remote_addresses = 0;
306
307 SCTP_INP_INFO_RLOCK();
308 if (req->oldptr == USER_ADDR_NULL) {
309 LIST_FOREACH(inp, &sctppcbinfo.listhead, sctp_list) {
310 SCTP_INP_RLOCK(inp);
311 number_of_endpoints++;
312 number_of_local_addresses += number_of_addresses(inp);
313 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
314 number_of_associations++;
315 number_of_local_addresses += number_of_addresses(inp);
316 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
317 number_of_remote_addresses++;
318 }
319 }
320 SCTP_INP_RUNLOCK(inp);
321 }
322 SCTP_INP_INFO_RUNLOCK();
323 n = (number_of_endpoints + 1) * sizeof(struct xsctp_inpcb) +
324 (number_of_local_addresses + number_of_endpoints + number_of_associations) * sizeof(struct xsctp_laddr) +
325 (number_of_associations + number_of_endpoints) * sizeof(struct xsctp_tcb) +
326 (number_of_remote_addresses + number_of_associations) * sizeof(struct xsctp_raddr);
327
328 /* request some more memory than needed */
329 req->oldidx = (n + n / 8);
330 return 0;
331 }
332 if (req->newptr != USER_ADDR_NULL) {
333 SCTP_INP_INFO_RUNLOCK();
334 return EPERM;
335 }
336 LIST_FOREACH(inp, &sctppcbinfo.listhead, sctp_list) {
337 SCTP_INP_RLOCK(inp);
338 xinpcb.last = 0;
339 xinpcb.local_port = ntohs(inp->sctp_lport);
340 xinpcb.flags = inp->sctp_flags;
341 xinpcb.features = inp->sctp_features;
342 xinpcb.total_sends = inp->total_sends;
343 xinpcb.total_recvs = inp->total_recvs;
344 xinpcb.total_nospaces = inp->total_nospaces;
345 xinpcb.fragmentation_point = inp->sctp_frag_point;
346 xinpcb.qlen = inp->sctp_socket->so_qlen;
347 xinpcb.maxqlen = inp->sctp_socket->so_qlimit;
348 SCTP_INP_INCR_REF(inp);
349 SCTP_INP_RUNLOCK(inp);
350 SCTP_INP_INFO_RUNLOCK();
351 error = SYSCTL_OUT(req, &xinpcb, sizeof(struct xsctp_inpcb));
352 if (error) {
353 SCTP_INP_DECR_REF(inp);
354 return error;
355 }
356 SCTP_INP_INFO_RLOCK();
357 SCTP_INP_RLOCK(inp);
358 error = copy_out_local_addresses(inp, NULL, req);
359 if (error) {
360 SCTP_INP_DECR_REF(inp);
361 return error;
362 }
363 LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) {
364 SCTP_TCB_LOCK(stcb);
365 atomic_add_int(&stcb->asoc.refcnt, 1);
366 SCTP_TCB_UNLOCK(stcb);
367 xstcb.last = 0;
368 xstcb.local_port = ntohs(inp->sctp_lport);
369 xstcb.remote_port = ntohs(stcb->rport);
370 if (stcb->asoc.primary_destination != NULL)
371 xstcb.primary_addr = stcb->asoc.primary_destination->ro._l_addr;
372 xstcb.heartbeat_interval = stcb->asoc.heart_beat_delay;
373 xstcb.state = SCTP_GET_STATE(&stcb->asoc); /* FIXME */
374 xstcb.in_streams = stcb->asoc.streamincnt;
375 xstcb.out_streams = stcb->asoc.streamoutcnt;
376 xstcb.max_nr_retrans = stcb->asoc.overall_error_count;
377 xstcb.primary_process = 0; /* not really supported
378 * yet */
379 xstcb.T1_expireries = stcb->asoc.timoinit + stcb->asoc.timocookie;
380 xstcb.T2_expireries = stcb->asoc.timoshutdown + stcb->asoc.timoshutdownack;
381 xstcb.retransmitted_tsns = stcb->asoc.marked_retrans;
382 xstcb.start_time = stcb->asoc.start_time;
383 xstcb.discontinuity_time = stcb->asoc.discontinuity_time;
384
385 xstcb.total_sends = stcb->total_sends;
386 xstcb.total_recvs = stcb->total_recvs;
387 xstcb.local_tag = stcb->asoc.my_vtag;
388 xstcb.remote_tag = stcb->asoc.peer_vtag;
389 xstcb.initial_tsn = stcb->asoc.init_seq_number;
390 xstcb.highest_tsn = stcb->asoc.sending_seq - 1;
391 xstcb.cumulative_tsn = stcb->asoc.last_acked_seq;
392 xstcb.cumulative_tsn_ack = stcb->asoc.cumulative_tsn;
393 xstcb.mtu = stcb->asoc.smallest_mtu;
394 xstcb.refcnt = stcb->asoc.refcnt;
395 SCTP_INP_RUNLOCK(inp);
396 SCTP_INP_INFO_RUNLOCK();
397 error = SYSCTL_OUT(req, &xstcb, sizeof(struct xsctp_tcb));
398 if (error) {
399 SCTP_INP_DECR_REF(inp);
400 atomic_add_int(&stcb->asoc.refcnt, -1);
401 return error;
402 }
403 SCTP_INP_INFO_RLOCK();
404 SCTP_INP_RLOCK(inp);
405 error = copy_out_local_addresses(inp, stcb, req);
406 if (error) {
407 SCTP_INP_DECR_REF(inp);
408 atomic_add_int(&stcb->asoc.refcnt, -1);
409 return error;
410 }
411 TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
412 xraddr.last = 0;
413 xraddr.address = net->ro._l_addr;
414 xraddr.active = ((net->dest_state & SCTP_ADDR_REACHABLE) == SCTP_ADDR_REACHABLE);
415 xraddr.confirmed = ((net->dest_state & SCTP_ADDR_UNCONFIRMED) == 0);
416 xraddr.heartbeat_enabled = ((net->dest_state & SCTP_ADDR_NOHB) == 0);
417 xraddr.rto = net->RTO;
418 xraddr.max_path_rtx = net->failure_threshold;
419 xraddr.rtx = net->marked_retrans;
420 xraddr.error_counter = net->error_count;
421 xraddr.cwnd = net->cwnd;
422 xraddr.flight_size = net->flight_size;
423 xraddr.mtu = net->mtu;
424 xraddr.start_time = net->start_time;
425 SCTP_INP_RUNLOCK(inp);
426 SCTP_INP_INFO_RUNLOCK();
427 error = SYSCTL_OUT(req, &xraddr, sizeof(struct xsctp_raddr));
428 if (error) {
429 SCTP_INP_DECR_REF(inp);
430 atomic_add_int(&stcb->asoc.refcnt, -1);
431 return error;
432 }
433 SCTP_INP_INFO_RLOCK();
434 SCTP_INP_RLOCK(inp);
435 }
436 atomic_add_int(&stcb->asoc.refcnt, -1);
437 memset((void *)&xraddr, 0, sizeof(struct xsctp_raddr));
438 xraddr.last = 1;
439 SCTP_INP_RUNLOCK(inp);
440 SCTP_INP_INFO_RUNLOCK();
441 error = SYSCTL_OUT(req, &xraddr, sizeof(struct xsctp_raddr));
442 if (error) {
443 SCTP_INP_DECR_REF(inp);
444 return error;
445 }
446 SCTP_INP_INFO_RLOCK();
447 SCTP_INP_RLOCK(inp);
448 }
449 SCTP_INP_RUNLOCK(inp);
450 SCTP_INP_INFO_RUNLOCK();
451 memset((void *)&xstcb, 0, sizeof(struct xsctp_tcb));
452 xstcb.last = 1;
453 error = SYSCTL_OUT(req, &xstcb, sizeof(struct xsctp_tcb));
454 if (error) {
455 return error;
456 }
457 SCTP_INP_INFO_RLOCK();
458 SCTP_INP_DECR_REF(inp);
459 }
460 SCTP_INP_INFO_RUNLOCK();
461
462 memset((void *)&xinpcb, 0, sizeof(struct xsctp_inpcb));
463 xinpcb.last = 1;
464 error = SYSCTL_OUT(req, &xinpcb, sizeof(struct xsctp_inpcb));
465 return error;
466}
467
468
469/*
470 * sysctl definitions
471 */
472
473SYSCTL_INT(_net_inet_sctp, OID_AUTO, sendspace, CTLFLAG_RW,
474 &sctp_sendspace, 0, "Maximum outgoing SCTP buffer size");
475
476SYSCTL_INT(_net_inet_sctp, OID_AUTO, recvspace, CTLFLAG_RW,
477 &sctp_recvspace, 0, "Maximum incoming SCTP buffer size");
478
479#if defined(__FreeBSD__) || defined(SCTP_APPLE_AUTO_ASCONF)
480SYSCTL_INT(_net_inet_sctp, OID_AUTO, auto_asconf, CTLFLAG_RW,
481 &sctp_auto_asconf, 0, "Enable SCTP Auto-ASCONF");
482#endif
483
484SYSCTL_INT(_net_inet_sctp, OID_AUTO, ecn_enable, CTLFLAG_RW,
485 &sctp_ecn_enable, 0, "Enable SCTP ECN");
486
487SYSCTL_INT(_net_inet_sctp, OID_AUTO, ecn_nonce, CTLFLAG_RW,
488 &sctp_ecn_nonce, 0, "Enable SCTP ECN Nonce");
489
490SYSCTL_INT(_net_inet_sctp, OID_AUTO, strict_sacks, CTLFLAG_RW,
491 &sctp_strict_sacks, 0, "Enable SCTP Strict SACK checking");
492
493SYSCTL_INT(_net_inet_sctp, OID_AUTO, loopback_nocsum, CTLFLAG_RW,
494 &sctp_no_csum_on_loopback, 0,
495 "Enable NO Csum on packets sent on loopback");
496
497SYSCTL_INT(_net_inet_sctp, OID_AUTO, strict_init, CTLFLAG_RW,
498 &sctp_strict_init, 0,
499 "Enable strict INIT/INIT-ACK singleton enforcement");
500
501SYSCTL_INT(_net_inet_sctp, OID_AUTO, peer_chkoh, CTLFLAG_RW,
502 &sctp_peer_chunk_oh, 0,
503 "Amount to debit peers rwnd per chunk sent");
504
505SYSCTL_INT(_net_inet_sctp, OID_AUTO, maxburst, CTLFLAG_RW,
506 &sctp_max_burst_default, 0,
507 "Default max burst for sctp endpoints");
508
509SYSCTL_INT(_net_inet_sctp, OID_AUTO, maxchunks, CTLFLAG_RW,
510 &sctp_max_chunks_on_queue, 0,
511 "Default max chunks on queue per asoc");
512
513SYSCTL_INT(_net_inet_sctp, OID_AUTO, tcbhashsize, CTLFLAG_RW,
514 &sctp_hashtblsize, 0,
515 "Tuneable for Hash table sizes");
516
517SYSCTL_INT(_net_inet_sctp, OID_AUTO, min_split_point, CTLFLAG_RW,
518 &sctp_min_split_point, 0,
519 "Minimum size when splitting a chunk");
520
521SYSCTL_INT(_net_inet_sctp, OID_AUTO, pcbhashsize, CTLFLAG_RW,
522 &sctp_pcbtblsize, 0,
523 "Tuneable for PCB Hash table sizes");
524
525SYSCTL_INT(_net_inet_sctp, OID_AUTO, sys_resource, CTLFLAG_RW,
526 &sctp_system_free_resc_limit, 0,
527 "Max number of cached resources in the system");
528
529SYSCTL_INT(_net_inet_sctp, OID_AUTO, asoc_resource, CTLFLAG_RW,
530 &sctp_asoc_free_resc_limit, 0,
531 "Max number of cached resources in an asoc");
532
533SYSCTL_INT(_net_inet_sctp, OID_AUTO, chunkscale, CTLFLAG_RW,
534 &sctp_chunkscale, 0,
535 "Tuneable for Scaling of number of chunks and messages");
536
537SYSCTL_UINT(_net_inet_sctp, OID_AUTO, delayed_sack_time, CTLFLAG_RW,
538 &sctp_delayed_sack_time_default, 0,
539 "Default delayed SACK timer in msec");
540
541SYSCTL_UINT(_net_inet_sctp, OID_AUTO, sack_freq, CTLFLAG_RW,
542 &sctp_sack_freq_default, 0,
543 "Default SACK frequency");
544
545SYSCTL_UINT(_net_inet_sctp, OID_AUTO, heartbeat_interval, CTLFLAG_RW,
546 &sctp_heartbeat_interval_default, 0,
547 "Default heartbeat interval in msec");
548
549SYSCTL_UINT(_net_inet_sctp, OID_AUTO, pmtu_raise_time, CTLFLAG_RW,
550 &sctp_pmtu_raise_time_default, 0,
551 "Default PMTU raise timer in sec");
552
553SYSCTL_UINT(_net_inet_sctp, OID_AUTO, shutdown_guard_time, CTLFLAG_RW,
554 &sctp_shutdown_guard_time_default, 0,
555 "Default shutdown guard timer in sec");
556
557SYSCTL_UINT(_net_inet_sctp, OID_AUTO, secret_lifetime, CTLFLAG_RW,
558 &sctp_secret_lifetime_default, 0,
559 "Default secret lifetime in sec");
560
561SYSCTL_UINT(_net_inet_sctp, OID_AUTO, rto_max, CTLFLAG_RW,
562 &sctp_rto_max_default, 0,
563 "Default maximum retransmission timeout in msec");
564
565SYSCTL_UINT(_net_inet_sctp, OID_AUTO, rto_min, CTLFLAG_RW,
566 &sctp_rto_min_default, 0,
567 "Default minimum retransmission timeout in msec");
568
569SYSCTL_UINT(_net_inet_sctp, OID_AUTO, rto_initial, CTLFLAG_RW,
570 &sctp_rto_initial_default, 0,
571 "Default initial retransmission timeout in msec");
572
573SYSCTL_UINT(_net_inet_sctp, OID_AUTO, init_rto_max, CTLFLAG_RW,
574 &sctp_init_rto_max_default, 0,
575 "Default maximum retransmission timeout during association setup in msec");
576
577SYSCTL_UINT(_net_inet_sctp, OID_AUTO, valid_cookie_life, CTLFLAG_RW,
578 &sctp_valid_cookie_life_default, 0,
579 "Default cookie lifetime in ticks");
580
581SYSCTL_UINT(_net_inet_sctp, OID_AUTO, init_rtx_max, CTLFLAG_RW,
582 &sctp_init_rtx_max_default, 0,
583 "Default maximum number of retransmission for INIT chunks");
584
585SYSCTL_UINT(_net_inet_sctp, OID_AUTO, assoc_rtx_max, CTLFLAG_RW,
586 &sctp_assoc_rtx_max_default, 0,
587 "Default maximum number of retransmissions per association");
588
589SYSCTL_UINT(_net_inet_sctp, OID_AUTO, path_rtx_max, CTLFLAG_RW,
590 &sctp_path_rtx_max_default, 0,
591 "Default maximum of retransmissions per path");
592
593SYSCTL_UINT(_net_inet_sctp, OID_AUTO, add_more_on_output, CTLFLAG_RW,
594 &sctp_add_more_threshold, 0,
595 "When space wise is it worthwhile to try to add more to a socket send buffer");
596
597SYSCTL_UINT(_net_inet_sctp, OID_AUTO, outgoing_streams, CTLFLAG_RW,
598 &sctp_nr_outgoing_streams_default, 0,
599 "Default number of outgoing streams");
600
601SYSCTL_UINT(_net_inet_sctp, OID_AUTO, cmt_on_off, CTLFLAG_RW,
602 &sctp_cmt_on_off, 0,
603 "CMT ON/OFF flag");
604
605SYSCTL_UINT(_net_inet_sctp, OID_AUTO, cwnd_maxburst, CTLFLAG_RW,
606 &sctp_use_cwnd_based_maxburst, 0,
607 "Use a CWND adjusting maxburst");
608
609SYSCTL_UINT(_net_inet_sctp, OID_AUTO, early_fast_retran, CTLFLAG_RW,
610 &sctp_early_fr, 0,
611 "Early Fast Retransmit with timer");
612
613SYSCTL_UINT(_net_inet_sctp, OID_AUTO, deadlock_detect, CTLFLAG_RW,
614 &sctp_says_check_for_deadlock, 0,
615 "SMP Deadlock detection on/off");
616
617SYSCTL_UINT(_net_inet_sctp, OID_AUTO, early_fast_retran_msec, CTLFLAG_RW,
618 &sctp_early_fr_msec, 0,
619 "Early Fast Retransmit minimum timer value");
620
621SYSCTL_UINT(_net_inet_sctp, OID_AUTO, asconf_auth_nochk, CTLFLAG_RW,
622 &sctp_asconf_auth_nochk, 0,
623 "Disable SCTP ASCONF AUTH requirement");
624
625SYSCTL_UINT(_net_inet_sctp, OID_AUTO, auth_disable, CTLFLAG_RW,
626 &sctp_auth_disable, 0,
627 "Disable SCTP AUTH function");
628
629SYSCTL_UINT(_net_inet_sctp, OID_AUTO, nat_friendly, CTLFLAG_RW,
630 &sctp_nat_friendly, 0,
631 "SCTP NAT friendly operation");
632
633SYSCTL_INT(_net_inet_sctp, OID_AUTO, abc_l_var, CTLFLAG_RW,
634 &sctp_L2_abc_variable, 0,
635 "SCTP ABC max increase per SACK (L)");
636
637SYSCTL_INT(_net_inet_sctp, OID_AUTO, max_chained_mbufs, CTLFLAG_RW,
638 &sctp_mbuf_threshold_count, 0,
639 "Default max number of small mbufs on a chain");
640
641SYSCTL_UINT(_net_inet_sctp, OID_AUTO, cmt_use_dac, CTLFLAG_RW,
642 &sctp_cmt_use_dac, 0,
643 "CMT DAC ON/OFF flag");
644
645SYSCTL_INT(_net_inet_sctp, OID_AUTO, do_sctp_drain, CTLFLAG_RW,
646 &sctp_do_drain, 0,
647 "Should SCTP respond to the drain calls");
648
649SYSCTL_INT(_net_inet_sctp, OID_AUTO, hb_max_burst, CTLFLAG_RW,
650 &sctp_hb_maxburst, 0,
651 "Confirmation Heartbeat max burst?");
652
653SYSCTL_INT(_net_inet_sctp, OID_AUTO, abort_at_limit, CTLFLAG_RW,
654 &sctp_abort_if_one_2_one_hits_limit, 0,
655 "When one-2-one hits qlimit abort");
656
657SYSCTL_INT(_net_inet_sctp, OID_AUTO, strict_data_order, CTLFLAG_RW,
658 &sctp_strict_data_order, 0,
659 "Enforce strict data ordering, abort if control inside data");
660
661SYSCTL_STRUCT(_net_inet_sctp, OID_AUTO, stats, CTLFLAG_RW,
662 &sctpstat, sctpstat,
663 "SCTP statistics (struct sctps_stat, netinet/sctp.h");
664
665SYSCTL_PROC(_net_inet_sctp, OID_AUTO, assoclist, CTLFLAG_RD,
666 0, 0, sctp_assoclist,
667 "S,xassoc", "List of active SCTP associations");
668
669SYSCTL_INT(_net_inet_sctp, OID_AUTO, min_residual, CTLFLAG_RW,
670 &sctp_min_residual, 0,
671 SCTPCTL_MIN_RESIDUAL_DESC);
672
673SYSCTL_INT(_net_inet_sctp, OID_AUTO, max_retran_chunk, CTLFLAG_RW,
674 &sctp_max_retran_chunk, 0,
675 SCTPCTL_MAX_RETRAN_CHUNK_DESC);
676
677#ifdef SCTP_DEBUG
678SYSCTL_INT(_net_inet_sctp, OID_AUTO, debug, CTLFLAG_RW,
679 &sctp_debug_on, 0, "Configure debug output");
680#endif /* SCTP_DEBUG */