tcp_usrreq.c revision 1.231 1 /* $NetBSD: tcp_usrreq.c,v 1.231 2022/06/28 01:44:19 riastradh Exp $ */
2
3 /*
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32 /*-
33 * Copyright (c) 1997, 1998, 2005, 2006 The NetBSD Foundation, Inc.
34 * All rights reserved.
35 *
36 * This code is derived from software contributed to The NetBSD Foundation
37 * by Jason R. Thorpe and Kevin M. Lahey of the Numerical Aerospace Simulation
38 * Facility, NASA Ames Research Center.
39 * This code is derived from software contributed to The NetBSD Foundation
40 * by Charles M. Hannum.
41 * This code is derived from software contributed to The NetBSD Foundation
42 * by Rui Paulo.
43 *
44 * Redistribution and use in source and binary forms, with or without
45 * modification, are permitted provided that the following conditions
46 * are met:
47 * 1. Redistributions of source code must retain the above copyright
48 * notice, this list of conditions and the following disclaimer.
49 * 2. Redistributions in binary form must reproduce the above copyright
50 * notice, this list of conditions and the following disclaimer in the
51 * documentation and/or other materials provided with the distribution.
52 *
53 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
54 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
55 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
57 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
58 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
59 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
60 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
61 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
62 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
63 * POSSIBILITY OF SUCH DAMAGE.
64 */
65
66 /*
67 * Copyright (c) 1982, 1986, 1988, 1993, 1995
68 * The Regents of the University of California. All rights reserved.
69 *
70 * Redistribution and use in source and binary forms, with or without
71 * modification, are permitted provided that the following conditions
72 * are met:
73 * 1. Redistributions of source code must retain the above copyright
74 * notice, this list of conditions and the following disclaimer.
75 * 2. Redistributions in binary form must reproduce the above copyright
76 * notice, this list of conditions and the following disclaimer in the
77 * documentation and/or other materials provided with the distribution.
78 * 3. Neither the name of the University nor the names of its contributors
79 * may be used to endorse or promote products derived from this software
80 * without specific prior written permission.
81 *
82 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
83 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
84 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
85 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
86 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
87 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
88 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
89 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
90 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
91 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
92 * SUCH DAMAGE.
93 *
94 * @(#)tcp_usrreq.c 8.5 (Berkeley) 6/21/95
95 */
96
97 /*
98 * TCP protocol interface to socket abstraction.
99 */
100
101 #include <sys/cdefs.h>
102 __KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.231 2022/06/28 01:44:19 riastradh Exp $");
103
104 #ifdef _KERNEL_OPT
105 #include "opt_inet.h"
106 #include "opt_tcp_debug.h"
107 #include "opt_mbuftrace.h"
108 #include "opt_tcp_space.h"
109 #include "opt_net_mpsafe.h"
110 #endif
111
112 #include <sys/param.h>
113 #include <sys/systm.h>
114 #include <sys/kernel.h>
115 #include <sys/mbuf.h>
116 #include <sys/socket.h>
117 #include <sys/socketvar.h>
118 #include <sys/protosw.h>
119 #include <sys/errno.h>
120 #include <sys/stat.h>
121 #include <sys/proc.h>
122 #include <sys/domain.h>
123 #include <sys/sysctl.h>
124 #include <sys/kauth.h>
125 #include <sys/kernel.h>
126 #include <sys/uidinfo.h>
127
128 #include <net/if.h>
129
130 #include <netinet/in.h>
131 #include <netinet/in_systm.h>
132 #include <netinet/in_var.h>
133 #include <netinet/ip.h>
134 #include <netinet/in_pcb.h>
135 #include <netinet/ip_var.h>
136 #include <netinet/in_offload.h>
137
138 #ifdef INET6
139 #include <netinet/ip6.h>
140 #include <netinet6/in6_pcb.h>
141 #include <netinet6/ip6_var.h>
142 #include <netinet6/scope6_var.h>
143 #endif
144
145 #include <netinet/tcp.h>
146 #include <netinet/tcp_fsm.h>
147 #include <netinet/tcp_seq.h>
148 #include <netinet/tcp_timer.h>
149 #include <netinet/tcp_var.h>
150 #include <netinet/tcp_private.h>
151 #include <netinet/tcp_congctl.h>
152 #include <netinet/tcp_debug.h>
153 #include <netinet/tcp_vtw.h>
154
155 static int
156 tcp_debug_capture(struct tcpcb *tp, int req)
157 {
158 #ifdef TCP_DEBUG
159 return tp->t_state;
160 #endif
161 return 0;
162 }
163
164 static inline void
165 tcp_debug_trace(struct socket *so, struct tcpcb *tp, int ostate, int req)
166 {
167 #ifdef TCP_DEBUG
168 if (tp && (so->so_options & SO_DEBUG))
169 tcp_trace(TA_USER, ostate, tp, NULL, req);
170 #endif
171 }
172
173 static int
174 tcp_getpcb(struct socket *so, struct inpcb **inp,
175 struct in6pcb **in6p, struct tcpcb **tp)
176 {
177
178 KASSERT(solocked(so));
179
180 /*
181 * When a TCP is attached to a socket, then there will be
182 * a (struct inpcb) pointed at by the socket, and this
183 * structure will point at a subsidary (struct tcpcb).
184 */
185 switch (so->so_proto->pr_domain->dom_family) {
186 case PF_INET:
187 *inp = sotoinpcb(so);
188 if (*inp == NULL)
189 return EINVAL;
190 *tp = intotcpcb(*inp);
191 break;
192 #ifdef INET6
193 case PF_INET6:
194 *in6p = sotoin6pcb(so);
195 if (*in6p == NULL)
196 return EINVAL;
197 *tp = in6totcpcb(*in6p);
198 break;
199 #endif
200 default:
201 return EAFNOSUPPORT;
202 }
203
204 KASSERT(tp != NULL);
205
206 return 0;
207 }
208
209 static void
210 change_keepalive(struct socket *so, struct tcpcb *tp)
211 {
212 tp->t_maxidle = tp->t_keepcnt * MIN(tp->t_keepintvl,
213 TCP_TIMER_MAXTICKS / tp->t_keepcnt);
214 TCP_TIMER_DISARM(tp, TCPT_KEEP);
215 TCP_TIMER_DISARM(tp, TCPT_2MSL);
216
217 if (tp->t_state == TCPS_SYN_RECEIVED ||
218 tp->t_state == TCPS_SYN_SENT) {
219 TCP_TIMER_ARM(tp, TCPT_KEEP, tp->t_keepinit);
220 } else if (so->so_options & SO_KEEPALIVE &&
221 tp->t_state <= TCPS_CLOSE_WAIT) {
222 TCP_TIMER_ARM(tp, TCPT_KEEP, tp->t_keepintvl);
223 } else {
224 TCP_TIMER_ARM(tp, TCPT_KEEP, tp->t_keepidle);
225 }
226
227 if ((tp->t_state == TCPS_FIN_WAIT_2) && (tp->t_maxidle > 0))
228 TCP_TIMER_ARM(tp, TCPT_2MSL, tp->t_maxidle);
229 }
230
231 /*
232 * Export TCP internal state information via a struct tcp_info, based on the
233 * Linux 2.6 API. Not ABI compatible as our constants are mapped differently
234 * (TCP state machine, etc). We export all information using FreeBSD-native
235 * constants -- for example, the numeric values for tcpi_state will differ
236 * from Linux.
237 */
238 static void
239 tcp_fill_info(struct tcpcb *tp, struct tcp_info *ti)
240 {
241
242 bzero(ti, sizeof(*ti));
243
244 ti->tcpi_state = tp->t_state;
245 if ((tp->t_flags & TF_REQ_TSTMP) && (tp->t_flags & TF_RCVD_TSTMP))
246 ti->tcpi_options |= TCPI_OPT_TIMESTAMPS;
247 if (tp->t_flags & TF_SACK_PERMIT)
248 ti->tcpi_options |= TCPI_OPT_SACK;
249 if ((tp->t_flags & TF_REQ_SCALE) && (tp->t_flags & TF_RCVD_SCALE)) {
250 ti->tcpi_options |= TCPI_OPT_WSCALE;
251 ti->tcpi_snd_wscale = tp->snd_scale;
252 ti->tcpi_rcv_wscale = tp->rcv_scale;
253 }
254 if (tp->t_flags & TF_ECN_PERMIT) {
255 ti->tcpi_options |= TCPI_OPT_ECN;
256 }
257
258 ti->tcpi_rto = tp->t_rxtcur * tick;
259 ti->tcpi_last_data_recv = (long)(getticks() -
260 (int)tp->t_rcvtime) * tick;
261 ti->tcpi_rtt = ((u_int64_t)tp->t_srtt * tick / PR_SLOWHZ)
262 >> (TCP_RTT_SHIFT + 2);
263 ti->tcpi_rttvar = ((u_int64_t)tp->t_rttvar * tick / PR_SLOWHZ)
264 >> (TCP_RTTVAR_SHIFT + 2);
265
266 ti->tcpi_snd_ssthresh = tp->snd_ssthresh;
267 /* Linux API wants these in # of segments, apparently */
268 ti->tcpi_snd_cwnd = tp->snd_cwnd / tp->t_segsz;
269 ti->tcpi_snd_wnd = tp->snd_wnd / tp->t_segsz;
270
271 /*
272 * FreeBSD-specific extension fields for tcp_info.
273 */
274 ti->tcpi_rcv_space = tp->rcv_wnd;
275 ti->tcpi_rcv_nxt = tp->rcv_nxt;
276 ti->tcpi_snd_bwnd = 0; /* Unused, kept for compat. */
277 ti->tcpi_snd_nxt = tp->snd_nxt;
278 ti->tcpi_snd_mss = tp->t_segsz;
279 ti->tcpi_rcv_mss = tp->t_segsz;
280 #ifdef TF_TOE
281 if (tp->t_flags & TF_TOE)
282 ti->tcpi_options |= TCPI_OPT_TOE;
283 #endif
284 /* From the redundant department of redundancies... */
285 ti->__tcpi_retransmits = ti->__tcpi_retrans =
286 ti->tcpi_snd_rexmitpack = tp->t_sndrexmitpack;
287
288 ti->tcpi_rcv_ooopack = tp->t_rcvoopack;
289 ti->tcpi_snd_zerowin = tp->t_sndzerowin;
290 }
291
292 int
293 tcp_ctloutput(int op, struct socket *so, struct sockopt *sopt)
294 {
295 int error = 0, s;
296 struct inpcb *inp;
297 #ifdef INET6
298 struct in6pcb *in6p;
299 #endif
300 struct tcpcb *tp;
301 struct tcp_info ti;
302 u_int ui;
303 int family; /* family of the socket */
304 int level, optname, optval;
305
306 level = sopt->sopt_level;
307 optname = sopt->sopt_name;
308
309 family = so->so_proto->pr_domain->dom_family;
310
311 s = splsoftnet();
312 switch (family) {
313 case PF_INET:
314 inp = sotoinpcb(so);
315 #ifdef INET6
316 in6p = NULL;
317 #endif
318 break;
319 #ifdef INET6
320 case PF_INET6:
321 inp = NULL;
322 in6p = sotoin6pcb(so);
323 break;
324 #endif
325 default:
326 splx(s);
327 panic("%s: af %d", __func__, family);
328 }
329 #ifndef INET6
330 if (inp == NULL)
331 #else
332 if (inp == NULL && in6p == NULL)
333 #endif
334 {
335 splx(s);
336 return ECONNRESET;
337 }
338 if (level != IPPROTO_TCP) {
339 switch (family) {
340 case PF_INET:
341 error = ip_ctloutput(op, so, sopt);
342 break;
343 #ifdef INET6
344 case PF_INET6:
345 error = ip6_ctloutput(op, so, sopt);
346 break;
347 #endif
348 }
349 splx(s);
350 return error;
351 }
352 if (inp)
353 tp = intotcpcb(inp);
354 #ifdef INET6
355 else if (in6p)
356 tp = in6totcpcb(in6p);
357 #endif
358 else
359 tp = NULL;
360
361 switch (op) {
362 case PRCO_SETOPT:
363 switch (optname) {
364 #ifdef TCP_SIGNATURE
365 case TCP_MD5SIG:
366 error = sockopt_getint(sopt, &optval);
367 if (error)
368 break;
369 if (optval > 0)
370 tp->t_flags |= TF_SIGNATURE;
371 else
372 tp->t_flags &= ~TF_SIGNATURE;
373 break;
374 #endif /* TCP_SIGNATURE */
375
376 case TCP_NODELAY:
377 error = sockopt_getint(sopt, &optval);
378 if (error)
379 break;
380 if (optval)
381 tp->t_flags |= TF_NODELAY;
382 else
383 tp->t_flags &= ~TF_NODELAY;
384 break;
385
386 case TCP_MAXSEG:
387 error = sockopt_getint(sopt, &optval);
388 if (error)
389 break;
390 if (optval > 0 && optval <= tp->t_peermss)
391 tp->t_peermss = optval; /* limit on send size */
392 else
393 error = EINVAL;
394 break;
395 #ifdef notyet
396 case TCP_CONGCTL:
397 /* XXX string overflow XXX */
398 error = tcp_congctl_select(tp, sopt->sopt_data);
399 break;
400 #endif
401
402 case TCP_KEEPIDLE:
403 error = sockopt_get(sopt, &ui, sizeof(ui));
404 if (error)
405 break;
406 if (ui > 0 && ui <= TCP_TIMER_MAXTICKS) {
407 tp->t_keepidle = ui;
408 change_keepalive(so, tp);
409 } else
410 error = EINVAL;
411 break;
412
413 case TCP_KEEPINTVL:
414 error = sockopt_get(sopt, &ui, sizeof(ui));
415 if (error)
416 break;
417 if (ui > 0 && ui <= TCP_TIMER_MAXTICKS) {
418 tp->t_keepintvl = ui;
419 change_keepalive(so, tp);
420 } else
421 error = EINVAL;
422 break;
423
424 case TCP_KEEPCNT:
425 error = sockopt_get(sopt, &ui, sizeof(ui));
426 if (error)
427 break;
428 if (ui > 0 && ui <= TCP_TIMER_MAXTICKS) {
429 tp->t_keepcnt = ui;
430 change_keepalive(so, tp);
431 } else
432 error = EINVAL;
433 break;
434
435 case TCP_KEEPINIT:
436 error = sockopt_get(sopt, &ui, sizeof(ui));
437 if (error)
438 break;
439 if (ui > 0 && ui <= TCP_TIMER_MAXTICKS) {
440 tp->t_keepinit = ui;
441 change_keepalive(so, tp);
442 } else
443 error = EINVAL;
444 break;
445
446 default:
447 error = ENOPROTOOPT;
448 break;
449 }
450 break;
451
452 case PRCO_GETOPT:
453 switch (optname) {
454 #ifdef TCP_SIGNATURE
455 case TCP_MD5SIG:
456 optval = (tp->t_flags & TF_SIGNATURE) ? 1 : 0;
457 goto setval;
458 #endif
459 case TCP_NODELAY:
460 optval = tp->t_flags & TF_NODELAY;
461 goto setval;
462 case TCP_MAXSEG:
463 optval = tp->t_peermss;
464 goto setval;
465 case TCP_INFO:
466 tcp_fill_info(tp, &ti);
467 error = sockopt_set(sopt, &ti, sizeof ti);
468 break;
469 #ifdef notyet
470 case TCP_CONGCTL:
471 break;
472 #endif
473 case TCP_KEEPIDLE:
474 optval = tp->t_keepidle;
475 goto setval;
476 case TCP_KEEPINTVL:
477 optval = tp->t_keepintvl;
478 goto setval;
479 case TCP_KEEPCNT:
480 optval = tp->t_keepcnt;
481 goto setval;
482 case TCP_KEEPINIT:
483 optval = tp->t_keepinit;
484 setval: error = sockopt_set(sopt, &optval, sizeof(optval));
485 break;
486 default:
487 error = ENOPROTOOPT;
488 break;
489 }
490 break;
491 }
492 splx(s);
493 return error;
494 }
495
496 #ifndef TCP_SENDSPACE
497 #define TCP_SENDSPACE 1024*32
498 #endif
499 int tcp_sendspace = TCP_SENDSPACE;
500 #ifndef TCP_RECVSPACE
501 #define TCP_RECVSPACE 1024*32
502 #endif
503 int tcp_recvspace = TCP_RECVSPACE;
504
505 /*
506 * tcp_attach: attach TCP protocol to socket, allocating internet protocol
507 * control block, TCP control block, buffer space and entering LISTEN state
508 * if to accept connections.
509 */
510 static int
511 tcp_attach(struct socket *so, int proto)
512 {
513 struct tcpcb *tp;
514 struct inpcb *inp;
515 #ifdef INET6
516 struct in6pcb *in6p;
517 #endif
518 int s, error, family;
519
520 /* Assign the lock (must happen even if we will error out). */
521 s = splsoftnet();
522 sosetlock(so);
523 KASSERT(solocked(so));
524
525 family = so->so_proto->pr_domain->dom_family;
526 switch (family) {
527 case PF_INET:
528 inp = sotoinpcb(so);
529 #ifdef INET6
530 in6p = NULL;
531 #endif
532 break;
533 #ifdef INET6
534 case PF_INET6:
535 inp = NULL;
536 in6p = sotoin6pcb(so);
537 break;
538 #endif
539 default:
540 error = EAFNOSUPPORT;
541 goto out;
542 }
543
544 KASSERT(inp == NULL);
545 #ifdef INET6
546 KASSERT(in6p == NULL);
547 #endif
548
549 #ifdef MBUFTRACE
550 so->so_mowner = &tcp_sock_mowner;
551 so->so_rcv.sb_mowner = &tcp_sock_rx_mowner;
552 so->so_snd.sb_mowner = &tcp_sock_tx_mowner;
553 #endif
554 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
555 error = soreserve(so, tcp_sendspace, tcp_recvspace);
556 if (error)
557 goto out;
558 }
559
560 so->so_rcv.sb_flags |= SB_AUTOSIZE;
561 so->so_snd.sb_flags |= SB_AUTOSIZE;
562
563 switch (family) {
564 case PF_INET:
565 error = in_pcballoc(so, &tcbtable);
566 if (error)
567 goto out;
568 inp = sotoinpcb(so);
569 #ifdef INET6
570 in6p = NULL;
571 #endif
572 break;
573 #ifdef INET6
574 case PF_INET6:
575 error = in6_pcballoc(so, &tcbtable);
576 if (error)
577 goto out;
578 inp = NULL;
579 in6p = sotoin6pcb(so);
580 break;
581 #endif
582 default:
583 error = EAFNOSUPPORT;
584 goto out;
585 }
586 if (inp)
587 tp = tcp_newtcpcb(family, (void *)inp);
588 #ifdef INET6
589 else if (in6p)
590 tp = tcp_newtcpcb(family, (void *)in6p);
591 #endif
592 else
593 tp = NULL;
594
595 if (tp == NULL) {
596 int nofd = so->so_state & SS_NOFDREF; /* XXX */
597
598 so->so_state &= ~SS_NOFDREF; /* don't free the socket yet */
599 if (inp)
600 in_pcbdetach(inp);
601 #ifdef INET6
602 if (in6p)
603 in6_pcbdetach(in6p);
604 #endif
605 so->so_state |= nofd;
606 error = ENOBUFS;
607 goto out;
608 }
609 tp->t_state = TCPS_CLOSED;
610 if ((so->so_options & SO_LINGER) && so->so_linger == 0) {
611 so->so_linger = TCP_LINGERTIME;
612 }
613 out:
614 KASSERT(solocked(so));
615 splx(s);
616 return error;
617 }
618
619 static void
620 tcp_detach(struct socket *so)
621 {
622 struct inpcb *inp = NULL;
623 struct in6pcb *in6p = NULL;
624 struct tcpcb *tp = NULL;
625 int s;
626
627 if (tcp_getpcb(so, &inp, &in6p, &tp) != 0)
628 return;
629
630 s = splsoftnet();
631 (void)tcp_disconnect1(tp);
632 splx(s);
633 }
634
635 static int
636 tcp_accept(struct socket *so, struct sockaddr *nam)
637 {
638 struct inpcb *inp = NULL;
639 struct in6pcb *in6p = NULL;
640 struct tcpcb *tp = NULL;
641 int ostate = 0;
642 int error = 0;
643 int s;
644
645 if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0)
646 return error;
647
648 ostate = tcp_debug_capture(tp, PRU_ACCEPT);
649
650 /*
651 * Accept a connection. Essentially all the work is
652 * done at higher levels; just return the address
653 * of the peer, storing through addr.
654 */
655 s = splsoftnet();
656 if (inp) {
657 in_setpeeraddr(inp, (struct sockaddr_in *)nam);
658 }
659 #ifdef INET6
660 if (in6p) {
661 in6_setpeeraddr(in6p, (struct sockaddr_in6 *)nam);
662 }
663 #endif
664 tcp_debug_trace(so, tp, ostate, PRU_ACCEPT);
665 splx(s);
666
667 return 0;
668 }
669
670 static int
671 tcp_bind(struct socket *so, struct sockaddr *nam, struct lwp *l)
672 {
673 struct inpcb *inp = NULL;
674 struct in6pcb *in6p = NULL;
675 struct sockaddr_in *sin = (struct sockaddr_in *)nam;
676 #ifdef INET6
677 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)nam;
678 #endif /* INET6 */
679 struct tcpcb *tp = NULL;
680 int s;
681 int error = 0;
682 int ostate = 0;
683
684 if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0)
685 return error;
686
687 ostate = tcp_debug_capture(tp, PRU_BIND);
688
689 /*
690 * Give the socket an address.
691 */
692 s = splsoftnet();
693 switch (so->so_proto->pr_domain->dom_family) {
694 case PF_INET:
695 error = in_pcbbind(inp, sin, l);
696 break;
697 #ifdef INET6
698 case PF_INET6:
699 error = in6_pcbbind(in6p, sin6, l);
700 if (!error) {
701 /* mapped addr case */
702 if (IN6_IS_ADDR_V4MAPPED(&in6p->in6p_laddr))
703 tp->t_family = AF_INET;
704 else
705 tp->t_family = AF_INET6;
706 }
707 break;
708 #endif
709 }
710 tcp_debug_trace(so, tp, ostate, PRU_BIND);
711 splx(s);
712
713 return error;
714 }
715
716 static int
717 tcp_listen(struct socket *so, struct lwp *l)
718 {
719 struct inpcb *inp = NULL;
720 struct in6pcb *in6p = NULL;
721 struct tcpcb *tp = NULL;
722 int error = 0;
723 int ostate = 0;
724 int s;
725
726 if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0)
727 return error;
728
729 ostate = tcp_debug_capture(tp, PRU_LISTEN);
730
731 /*
732 * Prepare to accept connections.
733 */
734 s = splsoftnet();
735 if (inp && inp->inp_lport == 0) {
736 error = in_pcbbind(inp, NULL, l);
737 if (error)
738 goto release;
739 }
740 #ifdef INET6
741 if (in6p && in6p->in6p_lport == 0) {
742 error = in6_pcbbind(in6p, NULL, l);
743 if (error)
744 goto release;
745 }
746 #endif
747 tp->t_state = TCPS_LISTEN;
748
749 release:
750 tcp_debug_trace(so, tp, ostate, PRU_LISTEN);
751 splx(s);
752
753 return error;
754 }
755
756 static int
757 tcp_connect(struct socket *so, struct sockaddr *nam, struct lwp *l)
758 {
759 struct inpcb *inp = NULL;
760 struct in6pcb *in6p = NULL;
761 struct tcpcb *tp = NULL;
762 int s;
763 int error = 0;
764 int ostate = 0;
765
766 if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0)
767 return error;
768
769 ostate = tcp_debug_capture(tp, PRU_CONNECT);
770
771 /*
772 * Initiate connection to peer.
773 * Create a template for use in transmissions on this connection.
774 * Enter SYN_SENT state, and mark socket as connecting.
775 * Start keep-alive timer, and seed output sequence space.
776 * Send initial segment on connection.
777 */
778 s = splsoftnet();
779
780 if (inp) {
781 if (inp->inp_lport == 0) {
782 error = in_pcbbind(inp, NULL, l);
783 if (error)
784 goto release;
785 }
786 error = in_pcbconnect(inp, (struct sockaddr_in *)nam, l);
787 }
788 #ifdef INET6
789 if (in6p) {
790 if (in6p->in6p_lport == 0) {
791 error = in6_pcbbind(in6p, NULL, l);
792 if (error)
793 goto release;
794 }
795 error = in6_pcbconnect(in6p, (struct sockaddr_in6 *)nam, l);
796 if (!error) {
797 /* mapped addr case */
798 if (IN6_IS_ADDR_V4MAPPED(&in6p->in6p_faddr))
799 tp->t_family = AF_INET;
800 else
801 tp->t_family = AF_INET6;
802 }
803 }
804 #endif
805 if (error)
806 goto release;
807 tp->t_template = tcp_template(tp);
808 if (tp->t_template == 0) {
809 if (inp)
810 in_pcbdisconnect(inp);
811 #ifdef INET6
812 if (in6p)
813 in6_pcbdisconnect(in6p);
814 #endif
815 error = ENOBUFS;
816 goto release;
817 }
818 /*
819 * Compute window scaling to request.
820 * XXX: This should be moved to tcp_output().
821 */
822 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
823 (TCP_MAXWIN << tp->request_r_scale) < sb_max)
824 tp->request_r_scale++;
825 soisconnecting(so);
826 TCP_STATINC(TCP_STAT_CONNATTEMPT);
827 tp->t_state = TCPS_SYN_SENT;
828 TCP_TIMER_ARM(tp, TCPT_KEEP, tp->t_keepinit);
829 tp->iss = tcp_new_iss(tp);
830 tcp_sendseqinit(tp);
831 error = tcp_output(tp);
832
833 release:
834 tcp_debug_trace(so, tp, ostate, PRU_CONNECT);
835 splx(s);
836
837 return error;
838 }
839
840 static int
841 tcp_connect2(struct socket *so, struct socket *so2)
842 {
843 struct inpcb *inp = NULL;
844 struct in6pcb *in6p = NULL;
845 struct tcpcb *tp = NULL;
846 int error = 0;
847 int ostate = 0;
848
849 KASSERT(solocked(so));
850
851 if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0)
852 return error;
853
854 ostate = tcp_debug_capture(tp, PRU_CONNECT2);
855
856 tcp_debug_trace(so, tp, ostate, PRU_CONNECT2);
857
858 return EOPNOTSUPP;
859 }
860
861 static int
862 tcp_disconnect(struct socket *so)
863 {
864 struct inpcb *inp = NULL;
865 struct in6pcb *in6p = NULL;
866 struct tcpcb *tp = NULL;
867 int error = 0;
868 int ostate = 0;
869 int s;
870
871 if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0)
872 return error;
873
874 ostate = tcp_debug_capture(tp, PRU_DISCONNECT);
875
876 /*
877 * Initiate disconnect from peer.
878 * If connection never passed embryonic stage, just drop;
879 * else if don't need to let data drain, then can just drop anyways,
880 * else have to begin TCP shutdown process: mark socket disconnecting,
881 * drain unread data, state switch to reflect user close, and
882 * send segment (e.g. FIN) to peer. Socket will be really disconnected
883 * when peer sends FIN and acks ours.
884 *
885 * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
886 */
887 s = splsoftnet();
888 tp = tcp_disconnect1(tp);
889 tcp_debug_trace(so, tp, ostate, PRU_DISCONNECT);
890 splx(s);
891
892 return error;
893 }
894
895 static int
896 tcp_shutdown(struct socket *so)
897 {
898 struct inpcb *inp = NULL;
899 struct in6pcb *in6p = NULL;
900 struct tcpcb *tp = NULL;
901 int error = 0;
902 int ostate = 0;
903 int s;
904
905 if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0)
906 return error;
907
908 ostate = tcp_debug_capture(tp, PRU_SHUTDOWN);
909 /*
910 * Mark the connection as being incapable of further output.
911 */
912 s = splsoftnet();
913 socantsendmore(so);
914 tp = tcp_usrclosed(tp);
915 if (tp)
916 error = tcp_output(tp);
917 tcp_debug_trace(so, tp, ostate, PRU_SHUTDOWN);
918 splx(s);
919
920 return error;
921 }
922
923 static int
924 tcp_abort(struct socket *so)
925 {
926 struct inpcb *inp = NULL;
927 struct in6pcb *in6p = NULL;
928 struct tcpcb *tp = NULL;
929 int error = 0;
930 int ostate = 0;
931 int s;
932
933 if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0)
934 return error;
935
936 ostate = tcp_debug_capture(tp, PRU_ABORT);
937
938 /*
939 * Abort the TCP.
940 */
941 s = splsoftnet();
942 tp = tcp_drop(tp, ECONNABORTED);
943 tcp_debug_trace(so, tp, ostate, PRU_ABORT);
944 splx(s);
945
946 return error;
947 }
948
949 static int
950 tcp_ioctl(struct socket *so, u_long cmd, void *nam, struct ifnet *ifp)
951 {
952 switch (so->so_proto->pr_domain->dom_family) {
953 case PF_INET:
954 return in_control(so, cmd, nam, ifp);
955 #ifdef INET6
956 case PF_INET6:
957 return in6_control(so, cmd, nam, ifp);
958 #endif
959 default:
960 return EAFNOSUPPORT;
961 }
962 }
963
964 static int
965 tcp_stat(struct socket *so, struct stat *ub)
966 {
967 KASSERT(solocked(so));
968
969 /* stat: don't bother with a blocksize. */
970 return 0;
971 }
972
973 static int
974 tcp_peeraddr(struct socket *so, struct sockaddr *nam)
975 {
976 struct inpcb *inp = NULL;
977 struct in6pcb *in6p = NULL;
978 struct tcpcb *tp = NULL;
979 int ostate = 0;
980 int error = 0;
981 int s;
982
983 if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0)
984 return error;
985
986 ostate = tcp_debug_capture(tp, PRU_PEERADDR);
987
988 s = splsoftnet();
989 if (inp) {
990 in_setpeeraddr(inp, (struct sockaddr_in *)nam);
991 }
992 #ifdef INET6
993 if (in6p) {
994 in6_setpeeraddr(in6p, (struct sockaddr_in6 *)nam);
995 }
996 #endif
997 tcp_debug_trace(so, tp, ostate, PRU_PEERADDR);
998 splx(s);
999
1000 return 0;
1001 }
1002
1003 static int
1004 tcp_sockaddr(struct socket *so, struct sockaddr *nam)
1005 {
1006 struct inpcb *inp = NULL;
1007 struct in6pcb *in6p = NULL;
1008 struct tcpcb *tp = NULL;
1009 int ostate = 0;
1010 int error = 0;
1011 int s;
1012
1013 if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0)
1014 return error;
1015
1016 ostate = tcp_debug_capture(tp, PRU_SOCKADDR);
1017
1018 s = splsoftnet();
1019 if (inp) {
1020 in_setsockaddr(inp, (struct sockaddr_in *)nam);
1021 }
1022 #ifdef INET6
1023 if (in6p) {
1024 in6_setsockaddr(in6p, (struct sockaddr_in6 *)nam);
1025 }
1026 #endif
1027 tcp_debug_trace(so, tp, ostate, PRU_SOCKADDR);
1028 splx(s);
1029
1030 return 0;
1031 }
1032
1033 static int
1034 tcp_rcvd(struct socket *so, int flags, struct lwp *l)
1035 {
1036 struct inpcb *inp = NULL;
1037 struct in6pcb *in6p = NULL;
1038 struct tcpcb *tp = NULL;
1039 int ostate = 0;
1040 int error = 0;
1041 int s;
1042
1043 if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0)
1044 return error;
1045
1046 ostate = tcp_debug_capture(tp, PRU_RCVD);
1047
1048 /*
1049 * After a receive, possibly send window update to peer.
1050 *
1051 * soreceive() calls this function when a user receives
1052 * ancillary data on a listening socket. We don't call
1053 * tcp_output in such a case, since there is no header
1054 * template for a listening socket and hence the kernel
1055 * will panic.
1056 */
1057 s = splsoftnet();
1058 if ((so->so_state & (SS_ISCONNECTED|SS_ISCONNECTING)) != 0)
1059 (void) tcp_output(tp);
1060 splx(s);
1061
1062 tcp_debug_trace(so, tp, ostate, PRU_RCVD);
1063
1064 return 0;
1065 }
1066
1067 static int
1068 tcp_recvoob(struct socket *so, struct mbuf *m, int flags)
1069 {
1070 struct inpcb *inp = NULL;
1071 struct in6pcb *in6p = NULL;
1072 struct tcpcb *tp = NULL;
1073 int ostate = 0;
1074 int error = 0;
1075 int s;
1076
1077 if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0)
1078 return error;
1079
1080 ostate = tcp_debug_capture(tp, PRU_RCVOOB);
1081
1082 s = splsoftnet();
1083 if ((so->so_oobmark == 0 &&
1084 (so->so_state & SS_RCVATMARK) == 0) ||
1085 so->so_options & SO_OOBINLINE ||
1086 tp->t_oobflags & TCPOOB_HADDATA) {
1087 splx(s);
1088 return EINVAL;
1089 }
1090
1091 if ((tp->t_oobflags & TCPOOB_HAVEDATA) == 0) {
1092 splx(s);
1093 return EWOULDBLOCK;
1094 }
1095
1096 m->m_len = 1;
1097 *mtod(m, char *) = tp->t_iobc;
1098 if ((flags & MSG_PEEK) == 0) {
1099 tp->t_oobflags ^= (TCPOOB_HAVEDATA | TCPOOB_HADDATA);
1100 so->so_state &= ~SS_POLLRDBAND;
1101 }
1102
1103 tcp_debug_trace(so, tp, ostate, PRU_RCVOOB);
1104 splx(s);
1105
1106 return 0;
1107 }
1108
1109 static int
1110 tcp_send(struct socket *so, struct mbuf *m, struct sockaddr *nam,
1111 struct mbuf *control, struct lwp *l)
1112 {
1113 struct inpcb *inp = NULL;
1114 struct in6pcb *in6p = NULL;
1115 struct tcpcb *tp = NULL;
1116 int ostate = 0;
1117 int error = 0;
1118 int s;
1119
1120 if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0)
1121 return error;
1122
1123 ostate = tcp_debug_capture(tp, PRU_SEND);
1124
1125 /*
1126 * Do a send by putting data in output queue and updating urgent
1127 * marker if URG set. Possibly send more data.
1128 */
1129 s = splsoftnet();
1130 if (control && control->m_len) {
1131 m_freem(control);
1132 m_freem(m);
1133 tcp_debug_trace(so, tp, ostate, PRU_SEND);
1134 splx(s);
1135 return EINVAL;
1136 }
1137
1138 sbappendstream(&so->so_snd, m);
1139 error = tcp_output(tp);
1140 tcp_debug_trace(so, tp, ostate, PRU_SEND);
1141 splx(s);
1142
1143 return error;
1144 }
1145
1146 static int
1147 tcp_sendoob(struct socket *so, struct mbuf *m, struct mbuf *control)
1148 {
1149 struct inpcb *inp = NULL;
1150 struct in6pcb *in6p = NULL;
1151 struct tcpcb *tp = NULL;
1152 int ostate = 0;
1153 int error = 0;
1154 int s;
1155
1156 if ((error = tcp_getpcb(so, &inp, &in6p, &tp)) != 0) {
1157 m_freem(m);
1158 m_freem(control);
1159 return error;
1160 }
1161 if (tp->t_template == NULL) {
1162 /*
1163 * XXX FreeBSD appears to open the connection
1164 * automagically in this case, but the socket address
1165 * isn't passed through here so we can't do that.
1166 */
1167 m_freem(m);
1168 m_freem(control);
1169 return ENOTCONN;
1170 }
1171
1172 ostate = tcp_debug_capture(tp, PRU_SENDOOB);
1173
1174 s = splsoftnet();
1175 if (sbspace_oob(&so->so_snd) == 0) {
1176 m_freem(m);
1177 m_freem(control);
1178 splx(s);
1179 return ENOBUFS;
1180 }
1181 /*
1182 * According to RFC961 (Assigned Protocols),
1183 * the urgent pointer points to the last octet
1184 * of urgent data. We continue, however,
1185 * to consider it to indicate the first octet
1186 * of data past the urgent section.
1187 * Otherwise, snd_up should be one lower.
1188 */
1189 sbappendstream(&so->so_snd, m);
1190 tp->snd_up = tp->snd_una + so->so_snd.sb_cc;
1191 tp->t_force = 1;
1192 error = tcp_output(tp);
1193 tp->t_force = 0;
1194 tcp_debug_trace(so, tp, ostate, PRU_SENDOOB);
1195 splx(s);
1196 m_freem(control);
1197
1198 return error;
1199 }
1200
1201 static int
1202 tcp_purgeif(struct socket *so, struct ifnet *ifp)
1203 {
1204 int s;
1205 int error = 0;
1206
1207 s = splsoftnet();
1208
1209 mutex_enter(softnet_lock);
1210 switch (so->so_proto->pr_domain->dom_family) {
1211 case PF_INET:
1212 in_pcbpurgeif0(&tcbtable, ifp);
1213 #ifdef NET_MPSAFE
1214 mutex_exit(softnet_lock);
1215 #endif
1216 in_purgeif(ifp);
1217 #ifdef NET_MPSAFE
1218 mutex_enter(softnet_lock);
1219 #endif
1220 in_pcbpurgeif(&tcbtable, ifp);
1221 break;
1222 #ifdef INET6
1223 case PF_INET6:
1224 in6_pcbpurgeif0(&tcbtable, ifp);
1225 #ifdef NET_MPSAFE
1226 mutex_exit(softnet_lock);
1227 #endif
1228 in6_purgeif(ifp);
1229 #ifdef NET_MPSAFE
1230 mutex_enter(softnet_lock);
1231 #endif
1232 in6_pcbpurgeif(&tcbtable, ifp);
1233 break;
1234 #endif
1235 default:
1236 error = EAFNOSUPPORT;
1237 break;
1238 }
1239 mutex_exit(softnet_lock);
1240 splx(s);
1241
1242 return error;
1243 }
1244
1245 /*
1246 * Initiate (or continue) disconnect.
1247 * If embryonic state, just send reset (once).
1248 * If in ``let data drain'' option and linger null, just drop.
1249 * Otherwise (hard), mark socket disconnecting and drop
1250 * current input data; switch states based on user close, and
1251 * send segment to peer (with FIN).
1252 */
1253 struct tcpcb *
1254 tcp_disconnect1(struct tcpcb *tp)
1255 {
1256 struct socket *so;
1257
1258 if (tp->t_inpcb)
1259 so = tp->t_inpcb->inp_socket;
1260 #ifdef INET6
1261 else if (tp->t_in6pcb)
1262 so = tp->t_in6pcb->in6p_socket;
1263 #endif
1264 else
1265 so = NULL;
1266
1267 if (TCPS_HAVEESTABLISHED(tp->t_state) == 0)
1268 tp = tcp_close(tp);
1269 else if ((so->so_options & SO_LINGER) && so->so_linger == 0)
1270 tp = tcp_drop(tp, 0);
1271 else {
1272 soisdisconnecting(so);
1273 sbflush(&so->so_rcv);
1274 tp = tcp_usrclosed(tp);
1275 if (tp)
1276 (void) tcp_output(tp);
1277 }
1278 return tp;
1279 }
1280
1281 /*
1282 * User issued close, and wish to trail through shutdown states:
1283 * if never received SYN, just forget it. If got a SYN from peer,
1284 * but haven't sent FIN, then go to FIN_WAIT_1 state to send peer a FIN.
1285 * If already got a FIN from peer, then almost done; go to LAST_ACK
1286 * state. In all other cases, have already sent FIN to peer (e.g.
1287 * after PRU_SHUTDOWN), and just have to play tedious game waiting
1288 * for peer to send FIN or not respond to keep-alives, etc.
1289 * We can let the user exit from the close as soon as the FIN is acked.
1290 */
1291 struct tcpcb *
1292 tcp_usrclosed(struct tcpcb *tp)
1293 {
1294
1295 switch (tp->t_state) {
1296
1297 case TCPS_CLOSED:
1298 case TCPS_LISTEN:
1299 case TCPS_SYN_SENT:
1300 tp->t_state = TCPS_CLOSED;
1301 tp = tcp_close(tp);
1302 break;
1303
1304 case TCPS_SYN_RECEIVED:
1305 case TCPS_ESTABLISHED:
1306 tp->t_state = TCPS_FIN_WAIT_1;
1307 break;
1308
1309 case TCPS_CLOSE_WAIT:
1310 tp->t_state = TCPS_LAST_ACK;
1311 break;
1312 }
1313 if (tp && tp->t_state >= TCPS_FIN_WAIT_2) {
1314 struct socket *so;
1315 if (tp->t_inpcb)
1316 so = tp->t_inpcb->inp_socket;
1317 #ifdef INET6
1318 else if (tp->t_in6pcb)
1319 so = tp->t_in6pcb->in6p_socket;
1320 #endif
1321 else
1322 so = NULL;
1323 if (so)
1324 soisdisconnected(so);
1325 /*
1326 * If we are in FIN_WAIT_2, we arrived here because the
1327 * application did a shutdown of the send side. Like the
1328 * case of a transition from FIN_WAIT_1 to FIN_WAIT_2 after
1329 * a full close, we start a timer to make sure sockets are
1330 * not left in FIN_WAIT_2 forever.
1331 */
1332 if ((tp->t_state == TCPS_FIN_WAIT_2) && (tp->t_maxidle > 0))
1333 TCP_TIMER_ARM(tp, TCPT_2MSL, tp->t_maxidle);
1334 else if (tp->t_state == TCPS_TIME_WAIT
1335 && ((tp->t_inpcb
1336 && (tcp4_vtw_enable & 1)
1337 && vtw_add(AF_INET, tp))
1338 ||
1339 (tp->t_in6pcb
1340 && (tcp6_vtw_enable & 1)
1341 && vtw_add(AF_INET6, tp)))) {
1342 tp = 0;
1343 }
1344 }
1345 return tp;
1346 }
1347
1348 /*
1349 * sysctl helper routine for net.inet.ip.mssdflt. it can't be less
1350 * than 32.
1351 */
1352 static int
1353 sysctl_net_inet_tcp_mssdflt(SYSCTLFN_ARGS)
1354 {
1355 int error, mssdflt;
1356 struct sysctlnode node;
1357
1358 mssdflt = tcp_mssdflt;
1359 node = *rnode;
1360 node.sysctl_data = &mssdflt;
1361 error = sysctl_lookup(SYSCTLFN_CALL(&node));
1362 if (error || newp == NULL)
1363 return error;
1364
1365 if (mssdflt < 32)
1366 return EINVAL;
1367 tcp_mssdflt = mssdflt;
1368
1369 mutex_enter(softnet_lock);
1370 tcp_tcpcb_template();
1371 mutex_exit(softnet_lock);
1372
1373 return 0;
1374 }
1375
1376 /*
1377 * sysctl helper for TCP CB template update
1378 */
1379 static int
1380 sysctl_update_tcpcb_template(SYSCTLFN_ARGS)
1381 {
1382 int t, error;
1383 struct sysctlnode node;
1384
1385 /* follow procedures in sysctl(9) manpage */
1386 t = *(int *)rnode->sysctl_data;
1387 node = *rnode;
1388 node.sysctl_data = &t;
1389 error = sysctl_lookup(SYSCTLFN_CALL(&node));
1390 if (error || newp == NULL)
1391 return error;
1392
1393 if (t < 0)
1394 return EINVAL;
1395
1396 *(int *)rnode->sysctl_data = t;
1397
1398 mutex_enter(softnet_lock);
1399 tcp_tcpcb_template();
1400 mutex_exit(softnet_lock);
1401
1402 return 0;
1403 }
1404
1405 /*
1406 * sysctl helper routine for setting port related values under
1407 * net.inet.ip and net.inet6.ip6. does basic range checking and does
1408 * additional checks for each type. this code has placed in
1409 * tcp_input.c since INET and INET6 both use the same tcp code.
1410 *
1411 * this helper is not static so that both inet and inet6 can use it.
1412 */
1413 int
1414 sysctl_net_inet_ip_ports(SYSCTLFN_ARGS)
1415 {
1416 int error, tmp;
1417 int apmin, apmax;
1418 #ifndef IPNOPRIVPORTS
1419 int lpmin, lpmax;
1420 #endif /* IPNOPRIVPORTS */
1421 struct sysctlnode node;
1422
1423 if (namelen != 0)
1424 return EINVAL;
1425
1426 switch (name[-3]) {
1427 case PF_INET:
1428 apmin = anonportmin;
1429 apmax = anonportmax;
1430 #ifndef IPNOPRIVPORTS
1431 lpmin = lowportmin;
1432 lpmax = lowportmax;
1433 #endif /* IPNOPRIVPORTS */
1434 break;
1435 #ifdef INET6
1436 case PF_INET6:
1437 apmin = ip6_anonportmin;
1438 apmax = ip6_anonportmax;
1439 #ifndef IPNOPRIVPORTS
1440 lpmin = ip6_lowportmin;
1441 lpmax = ip6_lowportmax;
1442 #endif /* IPNOPRIVPORTS */
1443 break;
1444 #endif /* INET6 */
1445 default:
1446 return EINVAL;
1447 }
1448
1449 /*
1450 * insert temporary copy into node, perform lookup on
1451 * temporary, then restore pointer
1452 */
1453 node = *rnode;
1454 tmp = *(int*)rnode->sysctl_data;
1455 node.sysctl_data = &tmp;
1456 error = sysctl_lookup(SYSCTLFN_CALL(&node));
1457 if (error || newp == NULL)
1458 return error;
1459
1460 /*
1461 * simple port range check
1462 */
1463 if (tmp < 0 || tmp > 65535)
1464 return EINVAL;
1465
1466 /*
1467 * per-node range checks
1468 */
1469 switch (rnode->sysctl_num) {
1470 case IPCTL_ANONPORTMIN:
1471 case IPV6CTL_ANONPORTMIN:
1472 if (tmp >= apmax)
1473 return EINVAL;
1474 #ifndef IPNOPRIVPORTS
1475 if (tmp < IPPORT_RESERVED)
1476 return EINVAL;
1477 #endif /* IPNOPRIVPORTS */
1478 break;
1479
1480 case IPCTL_ANONPORTMAX:
1481 case IPV6CTL_ANONPORTMAX:
1482 if (apmin >= tmp)
1483 return EINVAL;
1484 #ifndef IPNOPRIVPORTS
1485 if (tmp < IPPORT_RESERVED)
1486 return EINVAL;
1487 #endif /* IPNOPRIVPORTS */
1488 break;
1489
1490 #ifndef IPNOPRIVPORTS
1491 case IPCTL_LOWPORTMIN:
1492 case IPV6CTL_LOWPORTMIN:
1493 if (tmp >= lpmax ||
1494 tmp > IPPORT_RESERVEDMAX ||
1495 tmp < IPPORT_RESERVEDMIN)
1496 return EINVAL;
1497 break;
1498
1499 case IPCTL_LOWPORTMAX:
1500 case IPV6CTL_LOWPORTMAX:
1501 if (lpmin >= tmp ||
1502 tmp > IPPORT_RESERVEDMAX ||
1503 tmp < IPPORT_RESERVEDMIN)
1504 return EINVAL;
1505 break;
1506 #endif /* IPNOPRIVPORTS */
1507
1508 default:
1509 return EINVAL;
1510 }
1511
1512 *(int*)rnode->sysctl_data = tmp;
1513
1514 return 0;
1515 }
1516
1517 static inline int
1518 copyout_uid(struct socket *sockp, void *oldp, size_t *oldlenp)
1519 {
1520 if (oldp) {
1521 size_t sz;
1522 uid_t uid;
1523 int error;
1524
1525 if (sockp->so_cred == NULL)
1526 return EPERM;
1527
1528 uid = kauth_cred_geteuid(sockp->so_cred);
1529 sz = MIN(sizeof(uid), *oldlenp);
1530 if ((error = copyout(&uid, oldp, sz)) != 0)
1531 return error;
1532 }
1533 *oldlenp = sizeof(uid_t);
1534 return 0;
1535 }
1536
1537 static inline int
1538 inet4_ident_core(struct in_addr raddr, u_int rport,
1539 struct in_addr laddr, u_int lport,
1540 void *oldp, size_t *oldlenp,
1541 struct lwp *l, int dodrop)
1542 {
1543 struct inpcb *inp;
1544 struct socket *sockp;
1545
1546 inp = in_pcblookup_connect(&tcbtable, raddr, rport, laddr, lport, 0);
1547
1548 if (inp == NULL || (sockp = inp->inp_socket) == NULL)
1549 return ESRCH;
1550
1551 if (dodrop) {
1552 struct tcpcb *tp;
1553 int error;
1554
1555 if (inp == NULL || (tp = intotcpcb(inp)) == NULL ||
1556 (inp->inp_socket->so_options & SO_ACCEPTCONN) != 0)
1557 return ESRCH;
1558
1559 error = kauth_authorize_network(l->l_cred, KAUTH_NETWORK_SOCKET,
1560 KAUTH_REQ_NETWORK_SOCKET_DROP, inp->inp_socket, tp, NULL);
1561 if (error)
1562 return error;
1563
1564 (void)tcp_drop(tp, ECONNABORTED);
1565 return 0;
1566 }
1567
1568 return copyout_uid(sockp, oldp, oldlenp);
1569 }
1570
1571 #ifdef INET6
1572 static inline int
1573 inet6_ident_core(struct in6_addr *raddr, u_int rport,
1574 struct in6_addr *laddr, u_int lport,
1575 void *oldp, size_t *oldlenp,
1576 struct lwp *l, int dodrop)
1577 {
1578 struct in6pcb *in6p;
1579 struct socket *sockp;
1580
1581 in6p = in6_pcblookup_connect(&tcbtable, raddr, rport, laddr, lport, 0, 0);
1582
1583 if (in6p == NULL || (sockp = in6p->in6p_socket) == NULL)
1584 return ESRCH;
1585
1586 if (dodrop) {
1587 struct tcpcb *tp;
1588 int error;
1589
1590 if (in6p == NULL || (tp = in6totcpcb(in6p)) == NULL ||
1591 (in6p->in6p_socket->so_options & SO_ACCEPTCONN) != 0)
1592 return ESRCH;
1593
1594 error = kauth_authorize_network(l->l_cred, KAUTH_NETWORK_SOCKET,
1595 KAUTH_REQ_NETWORK_SOCKET_DROP, in6p->in6p_socket, tp, NULL);
1596 if (error)
1597 return error;
1598
1599 (void)tcp_drop(tp, ECONNABORTED);
1600 return 0;
1601 }
1602
1603 return copyout_uid(sockp, oldp, oldlenp);
1604 }
1605 #endif
1606
1607 /*
1608 * sysctl helper routine for the net.inet.tcp.drop and
1609 * net.inet6.tcp6.drop nodes.
1610 */
1611 #define sysctl_net_inet_tcp_drop sysctl_net_inet_tcp_ident
1612
1613 /*
1614 * sysctl helper routine for the net.inet.tcp.ident and
1615 * net.inet6.tcp6.ident nodes. contains backwards compat code for the
1616 * old way of looking up the ident information for ipv4 which involves
1617 * stuffing the port/addr pairs into the mib lookup.
1618 */
1619 static int
1620 sysctl_net_inet_tcp_ident(SYSCTLFN_ARGS)
1621 {
1622 struct sockaddr_in *si4[2];
1623 #ifdef INET6
1624 struct sockaddr_in6 *si6[2];
1625 #endif
1626 struct sockaddr_storage sa[2];
1627 int error, pf, dodrop;
1628
1629 dodrop = name[-1] == TCPCTL_DROP;
1630 if (dodrop) {
1631 if (oldp != NULL || *oldlenp != 0)
1632 return EINVAL;
1633 if (newp == NULL)
1634 return EPERM;
1635 if (newlen < sizeof(sa))
1636 return ENOMEM;
1637 }
1638 if (namelen != 4 && namelen != 0)
1639 return EINVAL;
1640 if (name[-2] != IPPROTO_TCP)
1641 return EINVAL;
1642 pf = name[-3];
1643
1644 /* old style lookup, ipv4 only */
1645 if (namelen == 4) {
1646 struct in_addr laddr, raddr;
1647 u_int lport, rport;
1648
1649 if (pf != PF_INET)
1650 return EPROTONOSUPPORT;
1651 raddr.s_addr = (uint32_t)name[0];
1652 rport = (u_int)name[1];
1653 laddr.s_addr = (uint32_t)name[2];
1654 lport = (u_int)name[3];
1655
1656 mutex_enter(softnet_lock);
1657 error = inet4_ident_core(raddr, rport, laddr, lport,
1658 oldp, oldlenp, l, dodrop);
1659 mutex_exit(softnet_lock);
1660 return error;
1661 }
1662
1663 if (newp == NULL || newlen != sizeof(sa))
1664 return EINVAL;
1665 error = copyin(newp, &sa, newlen);
1666 if (error)
1667 return error;
1668
1669 /*
1670 * requested families must match
1671 */
1672 if (pf != sa[0].ss_family || sa[0].ss_family != sa[1].ss_family)
1673 return EINVAL;
1674
1675 switch (pf) {
1676 #ifdef INET6
1677 case PF_INET6:
1678 si6[0] = (struct sockaddr_in6*)&sa[0];
1679 si6[1] = (struct sockaddr_in6*)&sa[1];
1680 if (si6[0]->sin6_len != sizeof(*si6[0]) ||
1681 si6[1]->sin6_len != sizeof(*si6[1]))
1682 return EINVAL;
1683
1684 if (!IN6_IS_ADDR_V4MAPPED(&si6[0]->sin6_addr) &&
1685 !IN6_IS_ADDR_V4MAPPED(&si6[1]->sin6_addr)) {
1686 error = sa6_embedscope(si6[0], ip6_use_defzone);
1687 if (error)
1688 return error;
1689 error = sa6_embedscope(si6[1], ip6_use_defzone);
1690 if (error)
1691 return error;
1692
1693 mutex_enter(softnet_lock);
1694 error = inet6_ident_core(&si6[0]->sin6_addr,
1695 si6[0]->sin6_port, &si6[1]->sin6_addr,
1696 si6[1]->sin6_port, oldp, oldlenp, l, dodrop);
1697 mutex_exit(softnet_lock);
1698 return error;
1699 }
1700
1701 if (IN6_IS_ADDR_V4MAPPED(&si6[0]->sin6_addr) !=
1702 IN6_IS_ADDR_V4MAPPED(&si6[1]->sin6_addr))
1703 return EINVAL;
1704
1705 in6_sin6_2_sin_in_sock((struct sockaddr *)&sa[0]);
1706 in6_sin6_2_sin_in_sock((struct sockaddr *)&sa[1]);
1707 #endif /* INET6 */
1708 /*FALLTHROUGH*/
1709 case PF_INET:
1710 si4[0] = (struct sockaddr_in*)&sa[0];
1711 si4[1] = (struct sockaddr_in*)&sa[1];
1712 if (si4[0]->sin_len != sizeof(*si4[0]) ||
1713 si4[0]->sin_len != sizeof(*si4[1]))
1714 return EINVAL;
1715
1716 mutex_enter(softnet_lock);
1717 error = inet4_ident_core(si4[0]->sin_addr, si4[0]->sin_port,
1718 si4[1]->sin_addr, si4[1]->sin_port,
1719 oldp, oldlenp, l, dodrop);
1720 mutex_exit(softnet_lock);
1721 return error;
1722 default:
1723 return EPROTONOSUPPORT;
1724 }
1725 }
1726
1727 /*
1728 * sysctl helper for the inet and inet6 pcblists. handles tcp/udp and
1729 * inet/inet6, as well as raw pcbs for each. specifically not
1730 * declared static so that raw sockets and udp/udp6 can use it as
1731 * well.
1732 */
1733 int
1734 sysctl_inpcblist(SYSCTLFN_ARGS)
1735 {
1736 const bool allowaddr = get_expose_address(curproc);
1737 struct sockaddr_in *in;
1738 const struct inpcb *inp;
1739 #ifdef INET6
1740 struct sockaddr_in6 *in6;
1741 const struct in6pcb *in6p;
1742 #endif
1743 struct inpcbtable *pcbtbl = __UNCONST(rnode->sysctl_data);
1744 const struct inpcb_hdr *inph;
1745 struct tcpcb *tp;
1746 struct kinfo_pcb pcb;
1747 char *dp;
1748 size_t len, needed, elem_size, out_size;
1749 int error, elem_count, pf, proto, pf2;
1750
1751 if (namelen != 4)
1752 return EINVAL;
1753
1754 if (oldp != NULL) {
1755 len = *oldlenp;
1756 elem_size = name[2];
1757 elem_count = name[3];
1758 if (elem_size != sizeof(pcb))
1759 return EINVAL;
1760 } else {
1761 len = 0;
1762 elem_count = INT_MAX;
1763 elem_size = sizeof(pcb);
1764 }
1765 error = 0;
1766 dp = oldp;
1767 out_size = elem_size;
1768 needed = 0;
1769
1770 if (namelen == 1 && name[0] == CTL_QUERY)
1771 return (sysctl_query(SYSCTLFN_CALL(rnode)));
1772
1773 if (name - oname != 4)
1774 return EINVAL;
1775
1776 pf = oname[1];
1777 proto = oname[2];
1778 pf2 = (oldp != NULL) ? pf : 0;
1779
1780 mutex_enter(softnet_lock);
1781
1782 TAILQ_FOREACH(inph, &pcbtbl->inpt_queue, inph_queue) {
1783 inp = (const struct inpcb *)inph;
1784 #ifdef INET6
1785 in6p = (const struct in6pcb *)inph;
1786 #endif
1787
1788 if (inph->inph_af != pf)
1789 continue;
1790
1791 if (kauth_authorize_network(l->l_cred, KAUTH_NETWORK_SOCKET,
1792 KAUTH_REQ_NETWORK_SOCKET_CANSEE, inph->inph_socket, NULL,
1793 NULL) != 0)
1794 continue;
1795
1796 memset(&pcb, 0, sizeof(pcb));
1797
1798 pcb.ki_family = pf;
1799 pcb.ki_type = proto;
1800
1801 switch (pf2) {
1802 case 0:
1803 /* just probing for size */
1804 break;
1805 case PF_INET:
1806 pcb.ki_family = inp->inp_socket->so_proto->
1807 pr_domain->dom_family;
1808 pcb.ki_type = inp->inp_socket->so_proto->
1809 pr_type;
1810 pcb.ki_protocol = inp->inp_socket->so_proto->
1811 pr_protocol;
1812 pcb.ki_pflags = inp->inp_flags;
1813
1814 pcb.ki_sostate = inp->inp_socket->so_state;
1815 pcb.ki_prstate = inp->inp_state;
1816 if (proto == IPPROTO_TCP) {
1817 tp = intotcpcb(inp);
1818 pcb.ki_tstate = tp->t_state;
1819 pcb.ki_tflags = tp->t_flags;
1820 }
1821
1822 COND_SET_VALUE(pcb.ki_pcbaddr,
1823 PTRTOUINT64(inp), allowaddr);
1824 COND_SET_VALUE(pcb.ki_ppcbaddr,
1825 PTRTOUINT64(inp->inp_ppcb), allowaddr);
1826 COND_SET_VALUE(pcb.ki_sockaddr,
1827 PTRTOUINT64(inp->inp_socket), allowaddr);
1828
1829 pcb.ki_rcvq = inp->inp_socket->so_rcv.sb_cc;
1830 pcb.ki_sndq = inp->inp_socket->so_snd.sb_cc;
1831
1832 in = satosin(&pcb.ki_src);
1833 in->sin_len = sizeof(*in);
1834 in->sin_family = pf;
1835 in->sin_port = inp->inp_lport;
1836 in->sin_addr = inp->inp_laddr;
1837 if (pcb.ki_prstate >= INP_CONNECTED) {
1838 in = satosin(&pcb.ki_dst);
1839 in->sin_len = sizeof(*in);
1840 in->sin_family = pf;
1841 in->sin_port = inp->inp_fport;
1842 in->sin_addr = inp->inp_faddr;
1843 }
1844 break;
1845 #ifdef INET6
1846 case PF_INET6:
1847 pcb.ki_family = in6p->in6p_socket->so_proto->
1848 pr_domain->dom_family;
1849 pcb.ki_type = in6p->in6p_socket->so_proto->pr_type;
1850 pcb.ki_protocol = in6p->in6p_socket->so_proto->
1851 pr_protocol;
1852 pcb.ki_pflags = in6p->in6p_flags;
1853
1854 pcb.ki_sostate = in6p->in6p_socket->so_state;
1855 pcb.ki_prstate = in6p->in6p_state;
1856 if (proto == IPPROTO_TCP) {
1857 tp = in6totcpcb(in6p);
1858 pcb.ki_tstate = tp->t_state;
1859 pcb.ki_tflags = tp->t_flags;
1860 }
1861
1862 COND_SET_VALUE(pcb.ki_pcbaddr,
1863 PTRTOUINT64(in6p), allowaddr);
1864 COND_SET_VALUE(pcb.ki_ppcbaddr,
1865 PTRTOUINT64(in6p->in6p_ppcb), allowaddr);
1866 COND_SET_VALUE(pcb.ki_sockaddr,
1867 PTRTOUINT64(in6p->in6p_socket), allowaddr);
1868
1869 pcb.ki_rcvq = in6p->in6p_socket->so_rcv.sb_cc;
1870 pcb.ki_sndq = in6p->in6p_socket->so_snd.sb_cc;
1871
1872 in6 = satosin6(&pcb.ki_src);
1873 in6->sin6_len = sizeof(*in6);
1874 in6->sin6_family = pf;
1875 in6->sin6_port = in6p->in6p_lport;
1876 in6->sin6_flowinfo = in6p->in6p_flowinfo;
1877 in6->sin6_addr = in6p->in6p_laddr;
1878 in6->sin6_scope_id = 0; /* XXX? */
1879
1880 if (pcb.ki_prstate >= IN6P_CONNECTED) {
1881 in6 = satosin6(&pcb.ki_dst);
1882 in6->sin6_len = sizeof(*in6);
1883 in6->sin6_family = pf;
1884 in6->sin6_port = in6p->in6p_fport;
1885 in6->sin6_flowinfo = in6p->in6p_flowinfo;
1886 in6->sin6_addr = in6p->in6p_faddr;
1887 in6->sin6_scope_id = 0; /* XXX? */
1888 }
1889 break;
1890 #endif
1891 }
1892
1893 if (len >= elem_size && elem_count > 0) {
1894 error = copyout(&pcb, dp, out_size);
1895 if (error) {
1896 mutex_exit(softnet_lock);
1897 return error;
1898 }
1899 dp += elem_size;
1900 len -= elem_size;
1901 }
1902 needed += elem_size;
1903 if (elem_count > 0 && elem_count != INT_MAX)
1904 elem_count--;
1905 }
1906
1907 *oldlenp = needed;
1908 if (oldp == NULL)
1909 *oldlenp += PCB_SLOP * sizeof(struct kinfo_pcb);
1910
1911 mutex_exit(softnet_lock);
1912
1913 return error;
1914 }
1915
1916 static int
1917 sysctl_tcp_congctl(SYSCTLFN_ARGS)
1918 {
1919 struct sysctlnode node;
1920 int error;
1921 char newname[TCPCC_MAXLEN];
1922
1923 strlcpy(newname, tcp_congctl_global_name, sizeof(newname) - 1);
1924
1925 node = *rnode;
1926 node.sysctl_data = newname;
1927 node.sysctl_size = sizeof(newname);
1928
1929 error = sysctl_lookup(SYSCTLFN_CALL(&node));
1930
1931 if (error ||
1932 newp == NULL ||
1933 strncmp(newname, tcp_congctl_global_name, sizeof(newname)) == 0)
1934 return error;
1935
1936 mutex_enter(softnet_lock);
1937 error = tcp_congctl_select(NULL, newname);
1938 mutex_exit(softnet_lock);
1939
1940 return error;
1941 }
1942
1943 static int
1944 sysctl_tcp_init_win(SYSCTLFN_ARGS)
1945 {
1946 int error;
1947 u_int iw;
1948 struct sysctlnode node;
1949
1950 iw = *(u_int *)rnode->sysctl_data;
1951 node = *rnode;
1952 node.sysctl_data = &iw;
1953 node.sysctl_size = sizeof(iw);
1954 error = sysctl_lookup(SYSCTLFN_CALL(&node));
1955 if (error || newp == NULL)
1956 return error;
1957
1958 if (iw >= __arraycount(tcp_init_win_max))
1959 return EINVAL;
1960 *(u_int *)rnode->sysctl_data = iw;
1961 return 0;
1962 }
1963
1964 static int
1965 sysctl_tcp_keep(SYSCTLFN_ARGS)
1966 {
1967 int error;
1968 u_int tmp;
1969 struct sysctlnode node;
1970
1971 node = *rnode;
1972 tmp = *(u_int *)rnode->sysctl_data;
1973 node.sysctl_data = &tmp;
1974
1975 error = sysctl_lookup(SYSCTLFN_CALL(&node));
1976 if (error || newp == NULL)
1977 return error;
1978
1979 if (!(tmp > 0 && tmp <= TCP_TIMER_MAXTICKS))
1980 return EINVAL;
1981
1982 mutex_enter(softnet_lock);
1983
1984 *(u_int *)rnode->sysctl_data = tmp;
1985 tcp_tcpcb_template(); /* update the template */
1986
1987 mutex_exit(softnet_lock);
1988 return 0;
1989 }
1990
1991 static int
1992 sysctl_net_inet_tcp_stats(SYSCTLFN_ARGS)
1993 {
1994
1995 return (NETSTAT_SYSCTL(tcpstat_percpu, TCP_NSTATS));
1996 }
1997
1998 /*
1999 * this (second stage) setup routine is a replacement for tcp_sysctl()
2000 * (which is currently used for ipv4 and ipv6)
2001 */
2002 static void
2003 sysctl_net_inet_tcp_setup2(struct sysctllog **clog, int pf, const char *pfname,
2004 const char *tcpname)
2005 {
2006 const struct sysctlnode *sack_node;
2007 const struct sysctlnode *abc_node;
2008 const struct sysctlnode *ecn_node;
2009 const struct sysctlnode *congctl_node;
2010 const struct sysctlnode *mslt_node;
2011 const struct sysctlnode *vtw_node;
2012 #ifdef TCP_DEBUG
2013 extern struct tcp_debug tcp_debug[TCP_NDEBUG];
2014 extern int tcp_debx;
2015 #endif
2016
2017 sysctl_createv(clog, 0, NULL, NULL,
2018 CTLFLAG_PERMANENT,
2019 CTLTYPE_NODE, pfname, NULL,
2020 NULL, 0, NULL, 0,
2021 CTL_NET, pf, CTL_EOL);
2022 sysctl_createv(clog, 0, NULL, NULL,
2023 CTLFLAG_PERMANENT,
2024 CTLTYPE_NODE, tcpname,
2025 SYSCTL_DESCR("TCP related settings"),
2026 NULL, 0, NULL, 0,
2027 CTL_NET, pf, IPPROTO_TCP, CTL_EOL);
2028
2029 sysctl_createv(clog, 0, NULL, NULL,
2030 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2031 CTLTYPE_INT, "rfc1323",
2032 SYSCTL_DESCR("Enable RFC1323 TCP extensions"),
2033 sysctl_update_tcpcb_template, 0, &tcp_do_rfc1323, 0,
2034 CTL_NET, pf, IPPROTO_TCP, TCPCTL_RFC1323, CTL_EOL);
2035 sysctl_createv(clog, 0, NULL, NULL,
2036 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2037 CTLTYPE_INT, "sendspace",
2038 SYSCTL_DESCR("Default TCP send buffer size"),
2039 NULL, 0, &tcp_sendspace, 0,
2040 CTL_NET, pf, IPPROTO_TCP, TCPCTL_SENDSPACE, CTL_EOL);
2041 sysctl_createv(clog, 0, NULL, NULL,
2042 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2043 CTLTYPE_INT, "recvspace",
2044 SYSCTL_DESCR("Default TCP receive buffer size"),
2045 NULL, 0, &tcp_recvspace, 0,
2046 CTL_NET, pf, IPPROTO_TCP, TCPCTL_RECVSPACE, CTL_EOL);
2047 sysctl_createv(clog, 0, NULL, NULL,
2048 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2049 CTLTYPE_INT, "mssdflt",
2050 SYSCTL_DESCR("Default maximum segment size"),
2051 sysctl_net_inet_tcp_mssdflt, 0, &tcp_mssdflt, 0,
2052 CTL_NET, pf, IPPROTO_TCP, TCPCTL_MSSDFLT, CTL_EOL);
2053 sysctl_createv(clog, 0, NULL, NULL,
2054 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2055 CTLTYPE_INT, "minmss",
2056 SYSCTL_DESCR("Lower limit for TCP maximum segment size"),
2057 NULL, 0, &tcp_minmss, 0,
2058 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
2059 sysctl_createv(clog, 0, NULL, NULL,
2060 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2061 CTLTYPE_INT, "msl",
2062 SYSCTL_DESCR("Maximum Segment Life"),
2063 NULL, 0, &tcp_msl, 0,
2064 CTL_NET, pf, IPPROTO_TCP, TCPCTL_MSL, CTL_EOL);
2065 sysctl_createv(clog, 0, NULL, NULL,
2066 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2067 CTLTYPE_INT, "syn_cache_limit",
2068 SYSCTL_DESCR("Maximum number of entries in the TCP "
2069 "compressed state engine"),
2070 NULL, 0, &tcp_syn_cache_limit, 0,
2071 CTL_NET, pf, IPPROTO_TCP, TCPCTL_SYN_CACHE_LIMIT,
2072 CTL_EOL);
2073 sysctl_createv(clog, 0, NULL, NULL,
2074 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2075 CTLTYPE_INT, "syn_bucket_limit",
2076 SYSCTL_DESCR("Maximum number of entries per hash "
2077 "bucket in the TCP compressed state "
2078 "engine"),
2079 NULL, 0, &tcp_syn_bucket_limit, 0,
2080 CTL_NET, pf, IPPROTO_TCP, TCPCTL_SYN_BUCKET_LIMIT,
2081 CTL_EOL);
2082 #if 0 /* obsoleted */
2083 sysctl_createv(clog, 0, NULL, NULL,
2084 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2085 CTLTYPE_INT, "syn_cache_interval",
2086 SYSCTL_DESCR("TCP compressed state engine's timer interval"),
2087 NULL, 0, &tcp_syn_cache_interval, 0,
2088 CTL_NET, pf, IPPROTO_TCP, TCPCTL_SYN_CACHE_INTER,
2089 CTL_EOL);
2090 #endif
2091 sysctl_createv(clog, 0, NULL, NULL,
2092 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2093 CTLTYPE_INT, "init_win",
2094 SYSCTL_DESCR("Initial TCP congestion window"),
2095 sysctl_tcp_init_win, 0, &tcp_init_win, 0,
2096 CTL_NET, pf, IPPROTO_TCP, TCPCTL_INIT_WIN, CTL_EOL);
2097 sysctl_createv(clog, 0, NULL, NULL,
2098 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2099 CTLTYPE_INT, "mss_ifmtu",
2100 SYSCTL_DESCR("Use interface MTU for calculating MSS"),
2101 NULL, 0, &tcp_mss_ifmtu, 0,
2102 CTL_NET, pf, IPPROTO_TCP, TCPCTL_MSS_IFMTU, CTL_EOL);
2103 sysctl_createv(clog, 0, NULL, &sack_node,
2104 CTLFLAG_PERMANENT,
2105 CTLTYPE_NODE, "sack",
2106 SYSCTL_DESCR("RFC2018 Selective ACKnowledgement tunables"),
2107 NULL, 0, NULL, 0,
2108 CTL_NET, pf, IPPROTO_TCP, TCPCTL_SACK, CTL_EOL);
2109
2110 /* Congctl subtree */
2111 sysctl_createv(clog, 0, NULL, &congctl_node,
2112 CTLFLAG_PERMANENT,
2113 CTLTYPE_NODE, "congctl",
2114 SYSCTL_DESCR("TCP Congestion Control"),
2115 NULL, 0, NULL, 0,
2116 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
2117 sysctl_createv(clog, 0, &congctl_node, NULL,
2118 CTLFLAG_PERMANENT,
2119 CTLTYPE_STRING, "available",
2120 SYSCTL_DESCR("Available Congestion Control Mechanisms"),
2121 NULL, 0, tcp_congctl_avail, 0, CTL_CREATE, CTL_EOL);
2122 sysctl_createv(clog, 0, &congctl_node, NULL,
2123 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2124 CTLTYPE_STRING, "selected",
2125 SYSCTL_DESCR("Selected Congestion Control Mechanism"),
2126 sysctl_tcp_congctl, 0, NULL, TCPCC_MAXLEN,
2127 CTL_CREATE, CTL_EOL);
2128
2129 sysctl_createv(clog, 0, NULL, NULL,
2130 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2131 CTLTYPE_INT, "win_scale",
2132 SYSCTL_DESCR("Use RFC1323 window scale options"),
2133 sysctl_update_tcpcb_template, 0, &tcp_do_win_scale, 0,
2134 CTL_NET, pf, IPPROTO_TCP, TCPCTL_WSCALE, CTL_EOL);
2135 sysctl_createv(clog, 0, NULL, NULL,
2136 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2137 CTLTYPE_INT, "timestamps",
2138 SYSCTL_DESCR("Use RFC1323 time stamp options"),
2139 sysctl_update_tcpcb_template, 0, &tcp_do_timestamps, 0,
2140 CTL_NET, pf, IPPROTO_TCP, TCPCTL_TSTAMP, CTL_EOL);
2141 sysctl_createv(clog, 0, NULL, NULL,
2142 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2143 CTLTYPE_INT, "cwm",
2144 SYSCTL_DESCR("Hughes/Touch/Heidemann Congestion Window "
2145 "Monitoring"),
2146 NULL, 0, &tcp_cwm, 0,
2147 CTL_NET, pf, IPPROTO_TCP, TCPCTL_CWM, CTL_EOL);
2148 sysctl_createv(clog, 0, NULL, NULL,
2149 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2150 CTLTYPE_INT, "cwm_burstsize",
2151 SYSCTL_DESCR("Congestion Window Monitoring allowed "
2152 "burst count in packets"),
2153 NULL, 0, &tcp_cwm_burstsize, 0,
2154 CTL_NET, pf, IPPROTO_TCP, TCPCTL_CWM_BURSTSIZE,
2155 CTL_EOL);
2156 sysctl_createv(clog, 0, NULL, NULL,
2157 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2158 CTLTYPE_INT, "ack_on_push",
2159 SYSCTL_DESCR("Immediately return ACK when PSH is "
2160 "received"),
2161 NULL, 0, &tcp_ack_on_push, 0,
2162 CTL_NET, pf, IPPROTO_TCP, TCPCTL_ACK_ON_PUSH, CTL_EOL);
2163 sysctl_createv(clog, 0, NULL, NULL,
2164 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2165 CTLTYPE_INT, "keepidle",
2166 SYSCTL_DESCR("Allowed connection idle ticks before a "
2167 "keepalive probe is sent"),
2168 sysctl_tcp_keep, 0, &tcp_keepidle, 0,
2169 CTL_NET, pf, IPPROTO_TCP, TCPCTL_KEEPIDLE, CTL_EOL);
2170 sysctl_createv(clog, 0, NULL, NULL,
2171 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2172 CTLTYPE_INT, "keepintvl",
2173 SYSCTL_DESCR("Ticks before next keepalive probe is sent"),
2174 sysctl_tcp_keep, 0, &tcp_keepintvl, 0,
2175 CTL_NET, pf, IPPROTO_TCP, TCPCTL_KEEPINTVL, CTL_EOL);
2176 sysctl_createv(clog, 0, NULL, NULL,
2177 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2178 CTLTYPE_INT, "keepcnt",
2179 SYSCTL_DESCR("Number of keepalive probes to send"),
2180 sysctl_tcp_keep, 0, &tcp_keepcnt, 0,
2181 CTL_NET, pf, IPPROTO_TCP, TCPCTL_KEEPCNT, CTL_EOL);
2182 sysctl_createv(clog, 0, NULL, NULL,
2183 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
2184 CTLTYPE_INT, "slowhz",
2185 SYSCTL_DESCR("Keepalive ticks per second"),
2186 NULL, PR_SLOWHZ, NULL, 0,
2187 CTL_NET, pf, IPPROTO_TCP, TCPCTL_SLOWHZ, CTL_EOL);
2188 sysctl_createv(clog, 0, NULL, NULL,
2189 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2190 CTLTYPE_INT, "log_refused",
2191 SYSCTL_DESCR("Log refused TCP connections"),
2192 NULL, 0, &tcp_log_refused, 0,
2193 CTL_NET, pf, IPPROTO_TCP, TCPCTL_LOG_REFUSED, CTL_EOL);
2194 #if 0 /* obsoleted */
2195 sysctl_createv(clog, 0, NULL, NULL,
2196 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2197 CTLTYPE_INT, "rstratelimit", NULL,
2198 NULL, 0, &tcp_rst_ratelim, 0,
2199 CTL_NET, pf, IPPROTO_TCP, TCPCTL_RSTRATELIMIT, CTL_EOL);
2200 #endif
2201 sysctl_createv(clog, 0, NULL, NULL,
2202 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2203 CTLTYPE_INT, "rstppslimit",
2204 SYSCTL_DESCR("Maximum number of RST packets to send "
2205 "per second"),
2206 NULL, 0, &tcp_rst_ppslim, 0,
2207 CTL_NET, pf, IPPROTO_TCP, TCPCTL_RSTPPSLIMIT, CTL_EOL);
2208 sysctl_createv(clog, 0, NULL, NULL,
2209 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2210 CTLTYPE_INT, "delack_ticks",
2211 SYSCTL_DESCR("Number of ticks to delay sending an ACK"),
2212 NULL, 0, &tcp_delack_ticks, 0,
2213 CTL_NET, pf, IPPROTO_TCP, TCPCTL_DELACK_TICKS, CTL_EOL);
2214 sysctl_createv(clog, 0, NULL, NULL,
2215 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2216 CTLTYPE_INT, "init_win_local",
2217 SYSCTL_DESCR("Initial TCP window size (in segments)"),
2218 sysctl_tcp_init_win, 0, &tcp_init_win_local, 0,
2219 CTL_NET, pf, IPPROTO_TCP, TCPCTL_INIT_WIN_LOCAL,
2220 CTL_EOL);
2221 sysctl_createv(clog, 0, NULL, NULL,
2222 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2223 CTLTYPE_STRUCT, "ident",
2224 SYSCTL_DESCR("RFC1413 Identification Protocol lookups"),
2225 sysctl_net_inet_tcp_ident, 0, NULL, sizeof(uid_t),
2226 CTL_NET, pf, IPPROTO_TCP, TCPCTL_IDENT, CTL_EOL);
2227 sysctl_createv(clog, 0, NULL, NULL,
2228 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2229 CTLTYPE_INT, "do_loopback_cksum",
2230 SYSCTL_DESCR("Perform TCP checksum on loopback"),
2231 NULL, 0, &tcp_do_loopback_cksum, 0,
2232 CTL_NET, pf, IPPROTO_TCP, TCPCTL_LOOPBACKCKSUM,
2233 CTL_EOL);
2234 sysctl_createv(clog, 0, NULL, NULL,
2235 CTLFLAG_PERMANENT,
2236 CTLTYPE_STRUCT, "pcblist",
2237 SYSCTL_DESCR("TCP protocol control block list"),
2238 sysctl_inpcblist, 0, &tcbtable, 0,
2239 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE,
2240 CTL_EOL);
2241 sysctl_createv(clog, 0, NULL, NULL,
2242 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2243 CTLTYPE_INT, "keepinit",
2244 SYSCTL_DESCR("Ticks before initial tcp connection times out"),
2245 sysctl_tcp_keep, 0, &tcp_keepinit, 0,
2246 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
2247
2248 /* TCP socket buffers auto-sizing nodes */
2249 sysctl_createv(clog, 0, NULL, NULL,
2250 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2251 CTLTYPE_INT, "recvbuf_auto",
2252 SYSCTL_DESCR("Enable automatic receive "
2253 "buffer sizing (experimental)"),
2254 NULL, 0, &tcp_do_autorcvbuf, 0,
2255 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
2256 sysctl_createv(clog, 0, NULL, NULL,
2257 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2258 CTLTYPE_INT, "recvbuf_inc",
2259 SYSCTL_DESCR("Incrementor step size of "
2260 "automatic receive buffer"),
2261 NULL, 0, &tcp_autorcvbuf_inc, 0,
2262 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
2263 sysctl_createv(clog, 0, NULL, NULL,
2264 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2265 CTLTYPE_INT, "recvbuf_max",
2266 SYSCTL_DESCR("Max size of automatic receive buffer"),
2267 NULL, 0, &tcp_autorcvbuf_max, 0,
2268 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
2269
2270 sysctl_createv(clog, 0, NULL, NULL,
2271 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2272 CTLTYPE_INT, "sendbuf_auto",
2273 SYSCTL_DESCR("Enable automatic send "
2274 "buffer sizing (experimental)"),
2275 NULL, 0, &tcp_do_autosndbuf, 0,
2276 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
2277 sysctl_createv(clog, 0, NULL, NULL,
2278 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2279 CTLTYPE_INT, "sendbuf_inc",
2280 SYSCTL_DESCR("Incrementor step size of "
2281 "automatic send buffer"),
2282 NULL, 0, &tcp_autosndbuf_inc, 0,
2283 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
2284 sysctl_createv(clog, 0, NULL, NULL,
2285 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2286 CTLTYPE_INT, "sendbuf_max",
2287 SYSCTL_DESCR("Max size of automatic send buffer"),
2288 NULL, 0, &tcp_autosndbuf_max, 0,
2289 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
2290
2291 /* ECN subtree */
2292 sysctl_createv(clog, 0, NULL, &ecn_node,
2293 CTLFLAG_PERMANENT,
2294 CTLTYPE_NODE, "ecn",
2295 SYSCTL_DESCR("RFC3168 Explicit Congestion Notification"),
2296 NULL, 0, NULL, 0,
2297 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
2298 sysctl_createv(clog, 0, &ecn_node, NULL,
2299 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2300 CTLTYPE_INT, "enable",
2301 SYSCTL_DESCR("Enable TCP Explicit Congestion "
2302 "Notification"),
2303 NULL, 0, &tcp_do_ecn, 0, CTL_CREATE, CTL_EOL);
2304 sysctl_createv(clog, 0, &ecn_node, NULL,
2305 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2306 CTLTYPE_INT, "maxretries",
2307 SYSCTL_DESCR("Number of times to retry ECN setup "
2308 "before disabling ECN on the connection"),
2309 NULL, 0, &tcp_ecn_maxretries, 0, CTL_CREATE, CTL_EOL);
2310
2311 /* SACK gets its own little subtree. */
2312 sysctl_createv(clog, 0, NULL, &sack_node,
2313 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2314 CTLTYPE_INT, "enable",
2315 SYSCTL_DESCR("Enable RFC2018 Selective ACKnowledgement"),
2316 NULL, 0, &tcp_do_sack, 0,
2317 CTL_NET, pf, IPPROTO_TCP, TCPCTL_SACK, CTL_CREATE, CTL_EOL);
2318 sysctl_createv(clog, 0, NULL, &sack_node,
2319 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2320 CTLTYPE_INT, "maxholes",
2321 SYSCTL_DESCR("Maximum number of TCP SACK holes allowed per connection"),
2322 NULL, 0, &tcp_sack_tp_maxholes, 0,
2323 CTL_NET, pf, IPPROTO_TCP, TCPCTL_SACK, CTL_CREATE, CTL_EOL);
2324 sysctl_createv(clog, 0, NULL, &sack_node,
2325 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2326 CTLTYPE_INT, "globalmaxholes",
2327 SYSCTL_DESCR("Global maximum number of TCP SACK holes"),
2328 NULL, 0, &tcp_sack_globalmaxholes, 0,
2329 CTL_NET, pf, IPPROTO_TCP, TCPCTL_SACK, CTL_CREATE, CTL_EOL);
2330 sysctl_createv(clog, 0, NULL, &sack_node,
2331 CTLFLAG_PERMANENT,
2332 CTLTYPE_INT, "globalholes",
2333 SYSCTL_DESCR("Global number of TCP SACK holes"),
2334 NULL, 0, &tcp_sack_globalholes, 0,
2335 CTL_NET, pf, IPPROTO_TCP, TCPCTL_SACK, CTL_CREATE, CTL_EOL);
2336
2337 sysctl_createv(clog, 0, NULL, NULL,
2338 CTLFLAG_PERMANENT,
2339 CTLTYPE_STRUCT, "stats",
2340 SYSCTL_DESCR("TCP statistics"),
2341 sysctl_net_inet_tcp_stats, 0, NULL, 0,
2342 CTL_NET, pf, IPPROTO_TCP, TCPCTL_STATS,
2343 CTL_EOL);
2344 sysctl_createv(clog, 0, NULL, NULL,
2345 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2346 CTLTYPE_INT, "local_by_rtt",
2347 SYSCTL_DESCR("Use RTT estimator to decide which hosts "
2348 "are local"),
2349 NULL, 0, &tcp_rttlocal, 0,
2350 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
2351 #ifdef TCP_DEBUG
2352 sysctl_createv(clog, 0, NULL, NULL,
2353 CTLFLAG_PERMANENT,
2354 CTLTYPE_STRUCT, "debug",
2355 SYSCTL_DESCR("TCP sockets debug information"),
2356 NULL, 0, &tcp_debug, sizeof(tcp_debug),
2357 CTL_NET, pf, IPPROTO_TCP, TCPCTL_DEBUG,
2358 CTL_EOL);
2359 sysctl_createv(clog, 0, NULL, NULL,
2360 CTLFLAG_PERMANENT,
2361 CTLTYPE_INT, "debx",
2362 SYSCTL_DESCR("Number of TCP debug sockets messages"),
2363 NULL, 0, &tcp_debx, sizeof(tcp_debx),
2364 CTL_NET, pf, IPPROTO_TCP, TCPCTL_DEBX,
2365 CTL_EOL);
2366 #endif
2367 sysctl_createv(clog, 0, NULL, NULL,
2368 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2369 CTLTYPE_STRUCT, "drop",
2370 SYSCTL_DESCR("TCP drop connection"),
2371 sysctl_net_inet_tcp_drop, 0, NULL, 0,
2372 CTL_NET, pf, IPPROTO_TCP, TCPCTL_DROP, CTL_EOL);
2373 sysctl_createv(clog, 0, NULL, NULL,
2374 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2375 CTLTYPE_INT, "iss_hash",
2376 SYSCTL_DESCR("Enable RFC 1948 ISS by cryptographic "
2377 "hash computation"),
2378 NULL, 0, &tcp_do_rfc1948, sizeof(tcp_do_rfc1948),
2379 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE,
2380 CTL_EOL);
2381
2382 /* ABC subtree */
2383
2384 sysctl_createv(clog, 0, NULL, &abc_node,
2385 CTLFLAG_PERMANENT, CTLTYPE_NODE, "abc",
2386 SYSCTL_DESCR("RFC3465 Appropriate Byte Counting (ABC)"),
2387 NULL, 0, NULL, 0,
2388 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
2389 sysctl_createv(clog, 0, &abc_node, NULL,
2390 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2391 CTLTYPE_INT, "enable",
2392 SYSCTL_DESCR("Enable RFC3465 Appropriate Byte Counting"),
2393 NULL, 0, &tcp_do_abc, 0, CTL_CREATE, CTL_EOL);
2394 sysctl_createv(clog, 0, &abc_node, NULL,
2395 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2396 CTLTYPE_INT, "aggressive",
2397 SYSCTL_DESCR("1: L=2*SMSS 0: L=1*SMSS"),
2398 NULL, 0, &tcp_abc_aggressive, 0, CTL_CREATE, CTL_EOL);
2399
2400 /* MSL tuning subtree */
2401
2402 sysctl_createv(clog, 0, NULL, &mslt_node,
2403 CTLFLAG_PERMANENT, CTLTYPE_NODE, "mslt",
2404 SYSCTL_DESCR("MSL Tuning for TIME_WAIT truncation"),
2405 NULL, 0, NULL, 0,
2406 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
2407 sysctl_createv(clog, 0, &mslt_node, NULL,
2408 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2409 CTLTYPE_INT, "enable",
2410 SYSCTL_DESCR("Enable TIME_WAIT truncation"),
2411 NULL, 0, &tcp_msl_enable, 0, CTL_CREATE, CTL_EOL);
2412 sysctl_createv(clog, 0, &mslt_node, NULL,
2413 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2414 CTLTYPE_INT, "loopback",
2415 SYSCTL_DESCR("MSL value to use for loopback connections"),
2416 NULL, 0, &tcp_msl_loop, 0, CTL_CREATE, CTL_EOL);
2417 sysctl_createv(clog, 0, &mslt_node, NULL,
2418 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2419 CTLTYPE_INT, "local",
2420 SYSCTL_DESCR("MSL value to use for local connections"),
2421 NULL, 0, &tcp_msl_local, 0, CTL_CREATE, CTL_EOL);
2422 sysctl_createv(clog, 0, &mslt_node, NULL,
2423 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2424 CTLTYPE_INT, "remote",
2425 SYSCTL_DESCR("MSL value to use for remote connections"),
2426 NULL, 0, &tcp_msl_remote, 0, CTL_CREATE, CTL_EOL);
2427 sysctl_createv(clog, 0, &mslt_node, NULL,
2428 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2429 CTLTYPE_INT, "remote_threshold",
2430 SYSCTL_DESCR("RTT estimate value to promote local to remote"),
2431 NULL, 0, &tcp_msl_remote_threshold, 0, CTL_CREATE, CTL_EOL);
2432
2433 /* vestigial TIME_WAIT tuning subtree */
2434
2435 sysctl_createv(clog, 0, NULL, &vtw_node,
2436 CTLFLAG_PERMANENT, CTLTYPE_NODE, "vtw",
2437 SYSCTL_DESCR("Tuning for Vestigial TIME_WAIT"),
2438 NULL, 0, NULL, 0,
2439 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
2440 sysctl_createv(clog, 0, &vtw_node, NULL,
2441 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
2442 CTLTYPE_INT, "enable",
2443 SYSCTL_DESCR("Enable Vestigial TIME_WAIT"),
2444 sysctl_tcp_vtw_enable, 0,
2445 (pf == AF_INET) ? &tcp4_vtw_enable : &tcp6_vtw_enable,
2446 0, CTL_CREATE, CTL_EOL);
2447 sysctl_createv(clog, 0, &vtw_node, NULL,
2448 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
2449 CTLTYPE_INT, "entries",
2450 SYSCTL_DESCR("Maximum number of vestigial TIME_WAIT entries"),
2451 NULL, 0, &tcp_vtw_entries, 0, CTL_CREATE, CTL_EOL);
2452 }
2453
2454 void
2455 tcp_usrreq_init(void)
2456 {
2457
2458 sysctl_net_inet_tcp_setup2(NULL, PF_INET, "inet", "tcp");
2459 #ifdef INET6
2460 sysctl_net_inet_tcp_setup2(NULL, PF_INET6, "inet6", "tcp6");
2461 #endif
2462 }
2463
2464 PR_WRAP_USRREQS(tcp)
2465 #define tcp_attach tcp_attach_wrapper
2466 #define tcp_detach tcp_detach_wrapper
2467 #define tcp_accept tcp_accept_wrapper
2468 #define tcp_bind tcp_bind_wrapper
2469 #define tcp_listen tcp_listen_wrapper
2470 #define tcp_connect tcp_connect_wrapper
2471 #define tcp_connect2 tcp_connect2_wrapper
2472 #define tcp_disconnect tcp_disconnect_wrapper
2473 #define tcp_shutdown tcp_shutdown_wrapper
2474 #define tcp_abort tcp_abort_wrapper
2475 #define tcp_ioctl tcp_ioctl_wrapper
2476 #define tcp_stat tcp_stat_wrapper
2477 #define tcp_peeraddr tcp_peeraddr_wrapper
2478 #define tcp_sockaddr tcp_sockaddr_wrapper
2479 #define tcp_rcvd tcp_rcvd_wrapper
2480 #define tcp_recvoob tcp_recvoob_wrapper
2481 #define tcp_send tcp_send_wrapper
2482 #define tcp_sendoob tcp_sendoob_wrapper
2483 #define tcp_purgeif tcp_purgeif_wrapper
2484
2485 const struct pr_usrreqs tcp_usrreqs = {
2486 .pr_attach = tcp_attach,
2487 .pr_detach = tcp_detach,
2488 .pr_accept = tcp_accept,
2489 .pr_bind = tcp_bind,
2490 .pr_listen = tcp_listen,
2491 .pr_connect = tcp_connect,
2492 .pr_connect2 = tcp_connect2,
2493 .pr_disconnect = tcp_disconnect,
2494 .pr_shutdown = tcp_shutdown,
2495 .pr_abort = tcp_abort,
2496 .pr_ioctl = tcp_ioctl,
2497 .pr_stat = tcp_stat,
2498 .pr_peeraddr = tcp_peeraddr,
2499 .pr_sockaddr = tcp_sockaddr,
2500 .pr_rcvd = tcp_rcvd,
2501 .pr_recvoob = tcp_recvoob,
2502 .pr_send = tcp_send,
2503 .pr_sendoob = tcp_sendoob,
2504 .pr_purgeif = tcp_purgeif,
2505 };
2506