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