tcp_usrreq.c revision 1.166.4.3 1 /* $NetBSD: tcp_usrreq.c,v 1.166.4.3 2013/09/23 00:57:53 rmind 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 #include <sys/cdefs.h>
98 __KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.166.4.3 2013/09/23 00:57:53 rmind Exp $");
99
100 #include "opt_inet.h"
101 #include "opt_ipsec.h"
102 #include "opt_tcp_debug.h"
103 #include "opt_mbuftrace.h"
104
105
106 #include <sys/param.h>
107 #include <sys/systm.h>
108 #include <sys/kernel.h>
109 #include <sys/malloc.h>
110 #include <sys/mbuf.h>
111 #include <sys/socket.h>
112 #include <sys/socketvar.h>
113 #include <sys/protosw.h>
114 #include <sys/errno.h>
115 #include <sys/stat.h>
116 #include <sys/proc.h>
117 #include <sys/domain.h>
118 #include <sys/sysctl.h>
119 #include <sys/kauth.h>
120 #include <sys/uidinfo.h>
121
122 #include <net/if.h>
123 #include <net/route.h>
124
125 #include <netinet/in.h>
126 #include <netinet/in_systm.h>
127 #include <netinet/in_var.h>
128 #include <netinet/ip.h>
129 #include <netinet/in_pcb.h>
130 #include <netinet/ip_var.h>
131 #include <netinet/in_offload.h>
132
133 #ifdef INET6
134 #ifndef INET
135 #include <netinet/in.h>
136 #endif
137 #include <netinet/ip6.h>
138 #include <netinet6/in6_pcb.h>
139 #include <netinet6/ip6_var.h>
140 #include <netinet6/scope6_var.h>
141 #endif
142
143 #include <netinet/tcp.h>
144 #include <netinet/tcp_fsm.h>
145 #include <netinet/tcp_seq.h>
146 #include <netinet/tcp_timer.h>
147 #include <netinet/tcp_var.h>
148 #include <netinet/tcp_private.h>
149 #include <netinet/tcp_congctl.h>
150 #include <netinet/tcpip.h>
151 #include <netinet/tcp_debug.h>
152 #include <netinet/tcp_vtw.h>
153
154 #include "opt_tcp_space.h"
155
156 /*
157 * TCP protocol interface to socket abstraction.
158 */
159
160 /*
161 * Process a TCP user request for TCP tb. If this is a send request
162 * then m is the mbuf chain of send data. If this is a timer expiration
163 * (called from the software clock routine), then timertype tells which timer.
164 */
165 static int
166 tcp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
167 struct mbuf *control, struct lwp *l)
168 {
169 inpcb_t *inp;
170 #ifdef INET6
171 struct in6pcb *in6p;
172 #endif
173 struct tcpcb *tp = NULL;
174 int s;
175 int error = 0;
176 #ifdef TCP_DEBUG
177 int ostate = 0;
178 #endif
179 int family; /* family of the socket */
180
181 KASSERT(req != PRU_ATTACH);
182 KASSERT(req != PRU_DETACH);
183
184 family = so->so_proto->pr_domain->dom_family;
185
186 if (req == PRU_CONTROL) {
187 switch (family) {
188 #ifdef INET
189 case PF_INET:
190 return (in_control(so, (long)m, (void *)nam,
191 (struct ifnet *)control, l));
192 #endif
193 #ifdef INET6
194 case PF_INET6:
195 return (in6_control(so, (long)m, (void *)nam,
196 (struct ifnet *)control, l));
197 #endif
198 default:
199 return EAFNOSUPPORT;
200 }
201 }
202
203 s = splsoftnet();
204
205 if (req == PRU_PURGEIF) {
206 mutex_enter(softnet_lock);
207 switch (family) {
208 #ifdef INET
209 case PF_INET:
210 inpcb_purgeif0(tcbtable, (struct ifnet *)control);
211 in_purgeif((struct ifnet *)control);
212 inpcb_purgeif(tcbtable, (struct ifnet *)control);
213 break;
214 #endif
215 #ifdef INET6
216 case PF_INET6:
217 in6_pcbpurgeif0(tcbtable, (struct ifnet *)control);
218 in6_purgeif((struct ifnet *)control);
219 in6_pcbpurgeif(tcbtable, (struct ifnet *)control);
220 break;
221 #endif
222 default:
223 mutex_exit(softnet_lock);
224 splx(s);
225 return (EAFNOSUPPORT);
226 }
227 mutex_exit(softnet_lock);
228 splx(s);
229 return (0);
230 }
231
232 KASSERT(solocked(so));
233
234 switch (family) {
235 #ifdef INET
236 case PF_INET:
237 inp = sotoinpcb(so);
238 #ifdef INET6
239 in6p = NULL;
240 #endif
241 break;
242 #endif
243 #ifdef INET6
244 case PF_INET6:
245 inp = NULL;
246 in6p = sotoin6pcb(so);
247 break;
248 #endif
249 default:
250 splx(s);
251 return EAFNOSUPPORT;
252 }
253
254 #ifdef INET6
255 KASSERT((inp != NULL) ^ (in6p != NULL));
256 #endif
257 KASSERT(!control || (req == PRU_SEND || req == PRU_SENDOOB));
258
259 /*
260 * When a TCP is attached to a socket, then there will be
261 * a (struct inpcb) pointed at by the socket, and this
262 * structure will point at a subsidary (struct tcpcb).
263 */
264 if ((inp == NULL
265 #ifdef INET6
266 && in6p == NULL
267 #endif
268 ) && req != PRU_SENSE)
269 {
270 error = EINVAL;
271 goto release;
272 }
273 #ifdef INET
274 if (inp) {
275 tp = intotcpcb(inp);
276 /* WHAT IF TP IS 0? */
277 #ifdef KPROF
278 tcp_acounts[tp->t_state][req]++;
279 #endif
280 #ifdef TCP_DEBUG
281 ostate = tp->t_state;
282 #endif
283 }
284 #endif
285 #ifdef INET6
286 if (in6p) {
287 tp = in6totcpcb(in6p);
288 /* WHAT IF TP IS 0? */
289 #ifdef KPROF
290 tcp_acounts[tp->t_state][req]++;
291 #endif
292 #ifdef TCP_DEBUG
293 ostate = tp->t_state;
294 #endif
295 }
296 #endif
297
298 switch (req) {
299 /*
300 * Give the socket an address.
301 */
302 case PRU_BIND:
303 switch (family) {
304 #ifdef INET
305 case PF_INET:
306 error = inpcb_bind(inp, nam, l);
307 break;
308 #endif
309 #ifdef INET6
310 case PF_INET6:
311 error = in6_pcbbind(in6p, nam, l);
312 if (!error) {
313 /* mapped addr case */
314 if (IN6_IS_ADDR_V4MAPPED(&in6p->in6p_laddr))
315 tp->t_family = AF_INET;
316 else
317 tp->t_family = AF_INET6;
318 }
319 break;
320 #endif
321 }
322 break;
323
324 /*
325 * Prepare to accept connections.
326 */
327 case PRU_LISTEN:
328 #ifdef INET
329 if (inp) {
330 in_port_t lport;
331
332 inpcb_get_ports(inp, &lport, NULL);
333 if (lport == 0) {
334 error = inpcb_bind(inp, NULL, l);
335 if (error)
336 break;
337 }
338 }
339 #endif
340 #ifdef INET6
341 if (in6p && in6p->in6p_lport == 0) {
342 error = in6_pcbbind(in6p, NULL, l);
343 if (error)
344 break;
345 }
346 #endif
347 tp->t_state = TCPS_LISTEN;
348 break;
349
350 /*
351 * Initiate connection to peer.
352 * Create a template for use in transmissions on this connection.
353 * Enter SYN_SENT state, and mark socket as connecting.
354 * Start keep-alive timer, and seed output sequence space.
355 * Send initial segment on connection.
356 */
357 case PRU_CONNECT:
358 #ifdef INET
359 if (inp) {
360 in_port_t lport;
361
362 inpcb_get_ports(inp, &lport, NULL);
363 if (lport == 0) {
364 error = inpcb_bind(inp, NULL, l);
365 if (error)
366 break;
367 }
368 error = inpcb_connect(inp, nam, l);
369 }
370 #endif
371 #ifdef INET6
372 if (in6p) {
373 if (in6p->in6p_lport == 0) {
374 error = in6_pcbbind(in6p, NULL, l);
375 if (error)
376 break;
377 }
378 error = in6_pcbconnect(in6p, nam, l);
379 if (!error) {
380 /* mapped addr case */
381 if (IN6_IS_ADDR_V4MAPPED(&in6p->in6p_faddr))
382 tp->t_family = AF_INET;
383 else
384 tp->t_family = AF_INET6;
385 }
386 }
387 #endif
388 if (error)
389 break;
390 tp->t_template = tcp_template(tp);
391 if (tp->t_template == 0) {
392 #ifdef INET
393 if (inp)
394 inpcb_disconnect(inp);
395 #endif
396 #ifdef INET6
397 if (in6p)
398 in6_pcbdisconnect(in6p);
399 #endif
400 error = ENOBUFS;
401 break;
402 }
403 /*
404 * Compute window scaling to request.
405 * XXX: This should be moved to tcp_output().
406 */
407 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
408 (TCP_MAXWIN << tp->request_r_scale) < sb_max)
409 tp->request_r_scale++;
410 soisconnecting(so);
411 TCP_STATINC(TCP_STAT_CONNATTEMPT);
412 tp->t_state = TCPS_SYN_SENT;
413 TCP_TIMER_ARM(tp, TCPT_KEEP, tp->t_keepinit);
414 tp->iss = tcp_new_iss(tp, 0);
415 tcp_sendseqinit(tp);
416 error = tcp_output(tp);
417 break;
418
419 /*
420 * Create a TCP connection between two sockets.
421 */
422 case PRU_CONNECT2:
423 error = EOPNOTSUPP;
424 break;
425
426 /*
427 * Initiate disconnect from peer.
428 * If connection never passed embryonic stage, just drop;
429 * else if don't need to let data drain, then can just drop anyways,
430 * else have to begin TCP shutdown process: mark socket disconnecting,
431 * drain unread data, state switch to reflect user close, and
432 * send segment (e.g. FIN) to peer. Socket will be really disconnected
433 * when peer sends FIN and acks ours.
434 *
435 * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
436 */
437 case PRU_DISCONNECT:
438 tp = tcp_disconnect(tp);
439 break;
440
441 /*
442 * Accept a connection. Essentially all the work is
443 * done at higher levels; just return the address
444 * of the peer, storing through addr.
445 */
446 case PRU_ACCEPT:
447 #ifdef INET
448 if (inp)
449 inpcb_fetch_peeraddr(inp, nam);
450 #endif
451 #ifdef INET6
452 if (in6p)
453 in6_setpeeraddr(in6p, nam);
454 #endif
455 break;
456
457 /*
458 * Mark the connection as being incapable of further output.
459 */
460 case PRU_SHUTDOWN:
461 socantsendmore(so);
462 tp = tcp_usrclosed(tp);
463 if (tp)
464 error = tcp_output(tp);
465 break;
466
467 /*
468 * After a receive, possibly send window update to peer.
469 */
470 case PRU_RCVD:
471 /*
472 * soreceive() calls this function when a user receives
473 * ancillary data on a listening socket. We don't call
474 * tcp_output in such a case, since there is no header
475 * template for a listening socket and hence the kernel
476 * will panic.
477 */
478 if ((so->so_state & (SS_ISCONNECTED|SS_ISCONNECTING)) != 0)
479 (void) tcp_output(tp);
480 break;
481
482 /*
483 * Do a send by putting data in output queue and updating urgent
484 * marker if URG set. Possibly send more data.
485 */
486 case PRU_SEND:
487 if (control && control->m_len) {
488 m_freem(control);
489 m_freem(m);
490 error = EINVAL;
491 break;
492 }
493 sbappendstream(&so->so_snd, m);
494 error = tcp_output(tp);
495 break;
496
497 /*
498 * Abort the TCP.
499 */
500 case PRU_ABORT:
501 tp = tcp_drop(tp, ECONNABORTED);
502 break;
503
504 case PRU_SENSE:
505 /*
506 * stat: don't bother with a blocksize.
507 */
508 splx(s);
509 return (0);
510
511 case PRU_RCVOOB:
512 if (control && control->m_len) {
513 m_freem(control);
514 m_freem(m);
515 error = EINVAL;
516 break;
517 }
518 if ((so->so_oobmark == 0 &&
519 (so->so_state & SS_RCVATMARK) == 0) ||
520 so->so_options & SO_OOBINLINE ||
521 tp->t_oobflags & TCPOOB_HADDATA) {
522 error = EINVAL;
523 break;
524 }
525 if ((tp->t_oobflags & TCPOOB_HAVEDATA) == 0) {
526 error = EWOULDBLOCK;
527 break;
528 }
529 m->m_len = 1;
530 *mtod(m, char *) = tp->t_iobc;
531 if (((long)nam & MSG_PEEK) == 0)
532 tp->t_oobflags ^= (TCPOOB_HAVEDATA | TCPOOB_HADDATA);
533 break;
534
535 case PRU_SENDOOB:
536 if (sbspace(&so->so_snd) < -512) {
537 m_freem(m);
538 error = ENOBUFS;
539 break;
540 }
541 /*
542 * According to RFC961 (Assigned Protocols),
543 * the urgent pointer points to the last octet
544 * of urgent data. We continue, however,
545 * to consider it to indicate the first octet
546 * of data past the urgent section.
547 * Otherwise, snd_up should be one lower.
548 */
549 sbappendstream(&so->so_snd, m);
550 tp->snd_up = tp->snd_una + so->so_snd.sb_cc;
551 tp->t_force = 1;
552 error = tcp_output(tp);
553 tp->t_force = 0;
554 break;
555
556 case PRU_SOCKADDR:
557 #ifdef INET
558 if (inp)
559 inpcb_fetch_sockaddr(inp, nam);
560 #endif
561 #ifdef INET6
562 if (in6p)
563 in6_setsockaddr(in6p, nam);
564 #endif
565 break;
566
567 case PRU_PEERADDR:
568 #ifdef INET
569 if (inp)
570 inpcb_fetch_peeraddr(inp, nam);
571 #endif
572 #ifdef INET6
573 if (in6p)
574 in6_setpeeraddr(in6p, nam);
575 #endif
576 break;
577
578 default:
579 panic("tcp_usrreq");
580 }
581 #ifdef TCP_DEBUG
582 if (tp && (so->so_options & SO_DEBUG))
583 tcp_trace(TA_USER, ostate, tp, NULL, req);
584 #endif
585
586 release:
587 splx(s);
588 return (error);
589 }
590
591 static void
592 change_keepalive(struct socket *so, struct tcpcb *tp)
593 {
594 tp->t_maxidle = tp->t_keepcnt * tp->t_keepintvl;
595 TCP_TIMER_DISARM(tp, TCPT_KEEP);
596 TCP_TIMER_DISARM(tp, TCPT_2MSL);
597
598 if (tp->t_state == TCPS_SYN_RECEIVED ||
599 tp->t_state == TCPS_SYN_SENT) {
600 TCP_TIMER_ARM(tp, TCPT_KEEP, tp->t_keepinit);
601 } else if (so->so_options & SO_KEEPALIVE &&
602 tp->t_state <= TCPS_CLOSE_WAIT) {
603 TCP_TIMER_ARM(tp, TCPT_KEEP, tp->t_keepintvl);
604 } else {
605 TCP_TIMER_ARM(tp, TCPT_KEEP, tp->t_keepidle);
606 }
607
608 if ((tp->t_state == TCPS_FIN_WAIT_2) && (tp->t_maxidle > 0))
609 TCP_TIMER_ARM(tp, TCPT_2MSL, tp->t_maxidle);
610 }
611
612
613 int
614 tcp_ctloutput(int op, struct socket *so, struct sockopt *sopt)
615 {
616 int error = 0, s;
617 inpcb_t *inp;
618 #ifdef INET6
619 struct in6pcb *in6p;
620 #endif
621 struct tcpcb *tp;
622 u_int ui;
623 int family; /* family of the socket */
624 int level, optname, optval;
625
626 level = sopt->sopt_level;
627 optname = sopt->sopt_name;
628
629 family = so->so_proto->pr_domain->dom_family;
630
631 s = splsoftnet();
632 switch (family) {
633 #ifdef INET
634 case PF_INET:
635 inp = sotoinpcb(so);
636 #ifdef INET6
637 in6p = NULL;
638 #endif
639 break;
640 #endif
641 #ifdef INET6
642 case PF_INET6:
643 inp = NULL;
644 in6p = sotoin6pcb(so);
645 break;
646 #endif
647 default:
648 splx(s);
649 panic("%s: af %d", __func__, family);
650 }
651 #ifndef INET6
652 if (inp == NULL)
653 #else
654 if (inp == NULL && in6p == NULL)
655 #endif
656 {
657 splx(s);
658 return (ECONNRESET);
659 }
660 if (level != IPPROTO_TCP) {
661 switch (family) {
662 #ifdef INET
663 case PF_INET:
664 error = ip_ctloutput(op, so, sopt);
665 break;
666 #endif
667 #ifdef INET6
668 case PF_INET6:
669 error = ip6_ctloutput(op, so, sopt);
670 break;
671 #endif
672 }
673 splx(s);
674 return (error);
675 }
676 if (inp)
677 tp = intotcpcb(inp);
678 #ifdef INET6
679 else if (in6p)
680 tp = in6totcpcb(in6p);
681 #endif
682 else
683 tp = NULL;
684
685 switch (op) {
686 case PRCO_SETOPT:
687 switch (optname) {
688 #ifdef TCP_SIGNATURE
689 case TCP_MD5SIG:
690 error = sockopt_getint(sopt, &optval);
691 if (error)
692 break;
693 if (optval > 0)
694 tp->t_flags |= TF_SIGNATURE;
695 else
696 tp->t_flags &= ~TF_SIGNATURE;
697 break;
698 #endif /* TCP_SIGNATURE */
699
700 case TCP_NODELAY:
701 error = sockopt_getint(sopt, &optval);
702 if (error)
703 break;
704 if (optval)
705 tp->t_flags |= TF_NODELAY;
706 else
707 tp->t_flags &= ~TF_NODELAY;
708 break;
709
710 case TCP_MAXSEG:
711 error = sockopt_getint(sopt, &optval);
712 if (error)
713 break;
714 if (optval > 0 && optval <= tp->t_peermss)
715 tp->t_peermss = optval; /* limit on send size */
716 else
717 error = EINVAL;
718 break;
719 #ifdef notyet
720 case TCP_CONGCTL:
721 /* XXX string overflow XXX */
722 error = tcp_congctl_select(tp, sopt->sopt_data);
723 break;
724 #endif
725
726 case TCP_KEEPIDLE:
727 error = sockopt_get(sopt, &ui, sizeof(ui));
728 if (error)
729 break;
730 if (ui > 0) {
731 tp->t_keepidle = ui;
732 change_keepalive(so, tp);
733 } else
734 error = EINVAL;
735 break;
736
737 case TCP_KEEPINTVL:
738 error = sockopt_get(sopt, &ui, sizeof(ui));
739 if (error)
740 break;
741 if (ui > 0) {
742 tp->t_keepintvl = ui;
743 change_keepalive(so, tp);
744 } else
745 error = EINVAL;
746 break;
747
748 case TCP_KEEPCNT:
749 error = sockopt_get(sopt, &ui, sizeof(ui));
750 if (error)
751 break;
752 if (ui > 0) {
753 tp->t_keepcnt = ui;
754 change_keepalive(so, tp);
755 } else
756 error = EINVAL;
757 break;
758
759 case TCP_KEEPINIT:
760 error = sockopt_get(sopt, &ui, sizeof(ui));
761 if (error)
762 break;
763 if (ui > 0) {
764 tp->t_keepinit = ui;
765 change_keepalive(so, tp);
766 } else
767 error = EINVAL;
768 break;
769
770 default:
771 error = ENOPROTOOPT;
772 break;
773 }
774 break;
775
776 case PRCO_GETOPT:
777 switch (optname) {
778 #ifdef TCP_SIGNATURE
779 case TCP_MD5SIG:
780 optval = (tp->t_flags & TF_SIGNATURE) ? 1 : 0;
781 error = sockopt_set(sopt, &optval, sizeof(optval));
782 break;
783 #endif
784 case TCP_NODELAY:
785 optval = tp->t_flags & TF_NODELAY;
786 error = sockopt_set(sopt, &optval, sizeof(optval));
787 break;
788 case TCP_MAXSEG:
789 optval = tp->t_peermss;
790 error = sockopt_set(sopt, &optval, sizeof(optval));
791 break;
792 #ifdef notyet
793 case TCP_CONGCTL:
794 break;
795 #endif
796 default:
797 error = ENOPROTOOPT;
798 break;
799 }
800 break;
801 }
802 splx(s);
803 return (error);
804 }
805
806 #ifndef TCP_SENDSPACE
807 #define TCP_SENDSPACE 1024*32
808 #endif
809 int tcp_sendspace = TCP_SENDSPACE;
810 #ifndef TCP_RECVSPACE
811 #define TCP_RECVSPACE 1024*32
812 #endif
813 int tcp_recvspace = TCP_RECVSPACE;
814
815 /*
816 * tcp_attach: attach TCP protocol to socket, allocating internet protocol
817 * control block, TCP control block, buffer space and entering LISTEN state
818 * if to accept connections.
819 */
820 static int
821 tcp_attach(struct socket *so, int proto)
822 {
823 inpcb_t *inp;
824 struct tcpcb *tp;
825 #ifdef INET6
826 struct in6pcb *in6p;
827 #endif
828 int s, error, family;
829
830 s = splsoftnet();
831 sosetlock(so);
832 solock(so);
833
834 family = so->so_proto->pr_domain->dom_family;
835 switch (family) {
836 #ifdef INET
837 case PF_INET:
838 inp = sotoinpcb(so);
839 #ifdef INET6
840 in6p = NULL;
841 #endif
842 break;
843 #endif
844 #ifdef INET6
845 case PF_INET6:
846 inp = NULL;
847 in6p = sotoin6pcb(so);
848 break;
849 #endif
850 default:
851 error = EAFNOSUPPORT;
852 goto out;
853 }
854
855 KASSERT(inp == NULL);
856 #ifdef INET6
857 KASSERT(in6p == NULL);
858 #endif
859
860 #ifdef MBUFTRACE
861 so->so_mowner = &tcp_sock_mowner;
862 so->so_rcv.sb_mowner = &tcp_sock_rx_mowner;
863 so->so_snd.sb_mowner = &tcp_sock_tx_mowner;
864 #endif
865 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
866 error = soreserve(so, tcp_sendspace, tcp_recvspace);
867 if (error) {
868 goto out;
869 }
870 }
871
872 so->so_rcv.sb_flags |= SB_AUTOSIZE;
873 so->so_snd.sb_flags |= SB_AUTOSIZE;
874
875 tp = NULL;
876 switch (family) {
877 #ifdef INET
878 case PF_INET:
879 error = inpcb_create(so, tcbtable);
880 if ((inp = sotoinpcb(so)) != NULL) {
881 tp = tcp_newtcpcb(family, (void *)inp);
882 }
883 #ifdef INET6
884 in6p = NULL;
885 #endif
886 break;
887 #endif
888 #ifdef INET6
889 case PF_INET6:
890 error = in6_pcballoc(so, tcbtable);
891 if ((in6p = sotoin6pcb(so)) != NULL) {
892 tp = tcp_newtcpcb(family, (void *)in6p);
893 }
894 inp = NULL;
895 break;
896 #endif
897 default:
898 error = EAFNOSUPPORT;
899 }
900
901 if (error) {
902 goto out;
903 }
904
905 if (tp == NULL) {
906 int nofd = so->so_state & SS_NOFDREF; /* XXX */
907
908 so->so_state &= ~SS_NOFDREF; /* don't free the socket yet */
909 #ifdef INET
910 if (inp)
911 inpcb_destroy(inp);
912 #endif
913 #ifdef INET6
914 if (in6p)
915 in6_pcbdetach(in6p);
916 #endif
917 so->so_state |= nofd;
918 error = ENOBUFS;
919 goto out;
920 }
921 tp->t_state = TCPS_CLOSED;
922
923 if ((so->so_options & SO_LINGER) && so->so_linger == 0)
924 so->so_linger = TCP_LINGERTIME;
925 tp = sototcpcb(so);
926 out:
927 sounlock(so);
928 splx(s);
929 return error;
930 }
931
932 static void
933 tcp_detach(struct socket *so)
934 {
935 inpcb_t *inp;
936 #ifdef INET6
937 struct in6pcb *in6p;
938 #endif
939 struct tcpcb *tp = NULL;
940 int s, family;
941
942 KASSERT(solocked(so));
943
944 s = splsoftnet();
945 family = so->so_proto->pr_domain->dom_family;
946 switch (family) {
947 #ifdef INET
948 case PF_INET:
949 inp = sotoinpcb(so);
950 tp = intotcpcb(inp);
951 break;
952 #endif
953 #ifdef INET6
954 case PF_INET6:
955 in6p = sotoin6pcb(so);
956 tp = in6totcpcb(in6p);
957 break;
958 #endif
959 default:
960 splx(s);
961 return;
962 }
963 KASSERT(tp != NULL);
964 (void)tcp_disconnect(tp);
965 splx(s);
966 }
967
968 /*
969 * Initiate (or continue) disconnect.
970 * If embryonic state, just send reset (once).
971 * If in ``let data drain'' option and linger null, just drop.
972 * Otherwise (hard), mark socket disconnecting and drop
973 * current input data; switch states based on user close, and
974 * send segment to peer (with FIN).
975 */
976 struct tcpcb *
977 tcp_disconnect(struct tcpcb *tp)
978 {
979 struct socket *so;
980
981 if (tp->t_inpcb)
982 so = inpcb_get_socket(tp->t_inpcb);
983 #ifdef INET6
984 else if (tp->t_in6pcb)
985 so = tp->t_in6pcb->in6p_socket;
986 #endif
987 else
988 so = NULL;
989
990 KASSERT(so != NULL);
991
992 if (TCPS_HAVEESTABLISHED(tp->t_state) == 0)
993 tp = tcp_close(tp);
994 else if ((so->so_options & SO_LINGER) && so->so_linger == 0)
995 tp = tcp_drop(tp, 0);
996 else {
997 soisdisconnecting(so);
998 sbflush(&so->so_rcv);
999 tp = tcp_usrclosed(tp);
1000 if (tp)
1001 (void) tcp_output(tp);
1002 }
1003 return (tp);
1004 }
1005
1006 /*
1007 * User issued close, and wish to trail through shutdown states:
1008 * if never received SYN, just forget it. If got a SYN from peer,
1009 * but haven't sent FIN, then go to FIN_WAIT_1 state to send peer a FIN.
1010 * If already got a FIN from peer, then almost done; go to LAST_ACK
1011 * state. In all other cases, have already sent FIN to peer (e.g.
1012 * after PRU_SHUTDOWN), and just have to play tedious game waiting
1013 * for peer to send FIN or not respond to keep-alives, etc.
1014 * We can let the user exit from the close as soon as the FIN is acked.
1015 */
1016 struct tcpcb *
1017 tcp_usrclosed(struct tcpcb *tp)
1018 {
1019
1020 switch (tp->t_state) {
1021
1022 case TCPS_CLOSED:
1023 case TCPS_LISTEN:
1024 case TCPS_SYN_SENT:
1025 tp->t_state = TCPS_CLOSED;
1026 tp = tcp_close(tp);
1027 break;
1028
1029 case TCPS_SYN_RECEIVED:
1030 case TCPS_ESTABLISHED:
1031 tp->t_state = TCPS_FIN_WAIT_1;
1032 break;
1033
1034 case TCPS_CLOSE_WAIT:
1035 tp->t_state = TCPS_LAST_ACK;
1036 break;
1037 }
1038 if (tp && tp->t_state >= TCPS_FIN_WAIT_2) {
1039 struct socket *so;
1040 if (tp->t_inpcb)
1041 so = inpcb_get_socket(tp->t_inpcb);
1042 #ifdef INET6
1043 else if (tp->t_in6pcb)
1044 so = tp->t_in6pcb->in6p_socket;
1045 #endif
1046 else
1047 so = NULL;
1048 if (so)
1049 soisdisconnected(so);
1050 /*
1051 * If we are in FIN_WAIT_2, we arrived here because the
1052 * application did a shutdown of the send side. Like the
1053 * case of a transition from FIN_WAIT_1 to FIN_WAIT_2 after
1054 * a full close, we start a timer to make sure sockets are
1055 * not left in FIN_WAIT_2 forever.
1056 */
1057 if ((tp->t_state == TCPS_FIN_WAIT_2) && (tp->t_maxidle > 0))
1058 TCP_TIMER_ARM(tp, TCPT_2MSL, tp->t_maxidle);
1059 else if (tp->t_state == TCPS_TIME_WAIT
1060 && ((tp->t_inpcb
1061 && (tcp4_vtw_enable & 1)
1062 && vtw_add(AF_INET, tp))
1063 ||
1064 (tp->t_in6pcb
1065 && (tcp6_vtw_enable & 1)
1066 && vtw_add(AF_INET6, tp)))) {
1067 tp = 0;
1068 }
1069 }
1070 return (tp);
1071 }
1072
1073 /*
1074 * sysctl helper routine for net.inet.ip.mssdflt. it can't be less
1075 * than 32.
1076 */
1077 static int
1078 sysctl_net_inet_tcp_mssdflt(SYSCTLFN_ARGS)
1079 {
1080 int error, mssdflt;
1081 struct sysctlnode node;
1082
1083 mssdflt = tcp_mssdflt;
1084 node = *rnode;
1085 node.sysctl_data = &mssdflt;
1086 error = sysctl_lookup(SYSCTLFN_CALL(&node));
1087 if (error || newp == NULL)
1088 return (error);
1089
1090 if (mssdflt < 32)
1091 return (EINVAL);
1092 tcp_mssdflt = mssdflt;
1093
1094 return (0);
1095 }
1096
1097 /*
1098 * sysctl helper routine for setting port related values under
1099 * net.inet.ip and net.inet6.ip6. does basic range checking and does
1100 * additional checks for each type. this code has placed in
1101 * tcp_input.c since INET and INET6 both use the same tcp code.
1102 *
1103 * this helper is not static so that both inet and inet6 can use it.
1104 */
1105 int
1106 sysctl_net_inet_ip_ports(SYSCTLFN_ARGS)
1107 {
1108 int error, tmp;
1109 int apmin, apmax;
1110 #ifndef IPNOPRIVPORTS
1111 int lpmin, lpmax;
1112 #endif /* IPNOPRIVPORTS */
1113 struct sysctlnode node;
1114
1115 if (namelen != 0)
1116 return (EINVAL);
1117
1118 switch (name[-3]) {
1119 #ifdef INET
1120 case PF_INET:
1121 apmin = anonportmin;
1122 apmax = anonportmax;
1123 #ifndef IPNOPRIVPORTS
1124 lpmin = lowportmin;
1125 lpmax = lowportmax;
1126 #endif /* IPNOPRIVPORTS */
1127 break;
1128 #endif /* INET */
1129 #ifdef INET6
1130 case PF_INET6:
1131 apmin = ip6_anonportmin;
1132 apmax = ip6_anonportmax;
1133 #ifndef IPNOPRIVPORTS
1134 lpmin = ip6_lowportmin;
1135 lpmax = ip6_lowportmax;
1136 #endif /* IPNOPRIVPORTS */
1137 break;
1138 #endif /* INET6 */
1139 default:
1140 return (EINVAL);
1141 }
1142
1143 /*
1144 * insert temporary copy into node, perform lookup on
1145 * temporary, then restore pointer
1146 */
1147 node = *rnode;
1148 tmp = *(int*)rnode->sysctl_data;
1149 node.sysctl_data = &tmp;
1150 error = sysctl_lookup(SYSCTLFN_CALL(&node));
1151 if (error || newp == NULL)
1152 return (error);
1153
1154 /*
1155 * simple port range check
1156 */
1157 if (tmp < 0 || tmp > 65535)
1158 return (EINVAL);
1159
1160 /*
1161 * per-node range checks
1162 */
1163 switch (rnode->sysctl_num) {
1164 case IPCTL_ANONPORTMIN:
1165 case IPV6CTL_ANONPORTMIN:
1166 if (tmp >= apmax)
1167 return (EINVAL);
1168 #ifndef IPNOPRIVPORTS
1169 if (tmp < IPPORT_RESERVED)
1170 return (EINVAL);
1171 #endif /* IPNOPRIVPORTS */
1172 break;
1173
1174 case IPCTL_ANONPORTMAX:
1175 case IPV6CTL_ANONPORTMAX:
1176 if (apmin >= tmp)
1177 return (EINVAL);
1178 #ifndef IPNOPRIVPORTS
1179 if (tmp < IPPORT_RESERVED)
1180 return (EINVAL);
1181 #endif /* IPNOPRIVPORTS */
1182 break;
1183
1184 #ifndef IPNOPRIVPORTS
1185 case IPCTL_LOWPORTMIN:
1186 case IPV6CTL_LOWPORTMIN:
1187 if (tmp >= lpmax ||
1188 tmp > IPPORT_RESERVEDMAX ||
1189 tmp < IPPORT_RESERVEDMIN)
1190 return (EINVAL);
1191 break;
1192
1193 case IPCTL_LOWPORTMAX:
1194 case IPV6CTL_LOWPORTMAX:
1195 if (lpmin >= tmp ||
1196 tmp > IPPORT_RESERVEDMAX ||
1197 tmp < IPPORT_RESERVEDMIN)
1198 return (EINVAL);
1199 break;
1200 #endif /* IPNOPRIVPORTS */
1201
1202 default:
1203 return (EINVAL);
1204 }
1205
1206 *(int*)rnode->sysctl_data = tmp;
1207
1208 return (0);
1209 }
1210
1211 static inline int
1212 copyout_uid(struct socket *sockp, void *oldp, size_t *oldlenp)
1213 {
1214 size_t sz;
1215 int error;
1216 uid_t uid;
1217
1218 uid = kauth_cred_geteuid(sockp->so_cred);
1219 if (oldp) {
1220 sz = MIN(sizeof(uid), *oldlenp);
1221 error = copyout(&uid, oldp, sz);
1222 if (error)
1223 return error;
1224 }
1225 *oldlenp = sizeof(uid);
1226 return 0;
1227 }
1228
1229 static inline int
1230 inet4_ident_core(struct in_addr raddr, u_int rport,
1231 struct in_addr laddr, u_int lport,
1232 void *oldp, size_t *oldlenp,
1233 struct lwp *l, int dodrop)
1234 {
1235 inpcb_t *inp;
1236 struct socket *so;
1237
1238 inp = inpcb_lookup(tcbtable, raddr, rport, laddr, lport, NULL);
1239 if (inp == NULL || (so = inpcb_get_socket(inp)) == NULL)
1240 return ESRCH;
1241
1242 if (dodrop) {
1243 struct tcpcb *tp;
1244 int error;
1245
1246 if ((tp = intotcpcb(inp)) == NULL ||
1247 (so->so_options & SO_ACCEPTCONN) != 0)
1248 return ESRCH;
1249
1250 error = kauth_authorize_network(l->l_cred, KAUTH_NETWORK_SOCKET,
1251 KAUTH_REQ_NETWORK_SOCKET_DROP, so, tp, NULL);
1252 if (error) {
1253 return error;
1254 }
1255
1256 (void)tcp_drop(tp, ECONNABORTED);
1257 return 0;
1258 }
1259
1260 return copyout_uid(so, oldp, oldlenp);
1261 }
1262
1263 #ifdef INET6
1264 static inline int
1265 inet6_ident_core(struct in6_addr *raddr, u_int rport,
1266 struct in6_addr *laddr, u_int lport,
1267 void *oldp, size_t *oldlenp,
1268 struct lwp *l, int dodrop)
1269 {
1270 struct in6pcb *in6p;
1271 struct socket *sockp;
1272
1273 in6p = in6_pcblookup_connect(tcbtable, raddr, rport, laddr, lport, 0, 0);
1274
1275 if (in6p == NULL || (sockp = in6p->in6p_socket) == NULL)
1276 return ESRCH;
1277
1278 if (dodrop) {
1279 struct tcpcb *tp;
1280 int error;
1281
1282 if (in6p == NULL || (tp = in6totcpcb(in6p)) == NULL ||
1283 (in6p->in6p_socket->so_options & SO_ACCEPTCONN) != 0)
1284 return ESRCH;
1285
1286 error = kauth_authorize_network(l->l_cred, KAUTH_NETWORK_SOCKET,
1287 KAUTH_REQ_NETWORK_SOCKET_DROP, in6p->in6p_socket, tp, NULL);
1288 if (error)
1289 return (error);
1290
1291 (void)tcp_drop(tp, ECONNABORTED);
1292 return 0;
1293 }
1294 else
1295 return copyout_uid(sockp, oldp, oldlenp);
1296 }
1297 #endif
1298
1299 /*
1300 * sysctl helper routine for the net.inet.tcp.drop and
1301 * net.inet6.tcp6.drop nodes.
1302 */
1303 #define sysctl_net_inet_tcp_drop sysctl_net_inet_tcp_ident
1304
1305 /*
1306 * sysctl helper routine for the net.inet.tcp.ident and
1307 * net.inet6.tcp6.ident nodes. contains backwards compat code for the
1308 * old way of looking up the ident information for ipv4 which involves
1309 * stuffing the port/addr pairs into the mib lookup.
1310 */
1311 static int
1312 sysctl_net_inet_tcp_ident(SYSCTLFN_ARGS)
1313 {
1314 #ifdef INET
1315 struct sockaddr_in *si4[2];
1316 #endif /* INET */
1317 #ifdef INET6
1318 struct sockaddr_in6 *si6[2];
1319 #endif /* INET6 */
1320 struct sockaddr_storage sa[2];
1321 int error, pf, dodrop;
1322
1323 dodrop = name[-1] == TCPCTL_DROP;
1324 if (dodrop) {
1325 if (oldp != NULL || *oldlenp != 0)
1326 return EINVAL;
1327 if (newp == NULL)
1328 return EPERM;
1329 if (newlen < sizeof(sa))
1330 return ENOMEM;
1331 }
1332 if (namelen != 4 && namelen != 0)
1333 return EINVAL;
1334 if (name[-2] != IPPROTO_TCP)
1335 return EINVAL;
1336 pf = name[-3];
1337
1338 /* old style lookup, ipv4 only */
1339 if (namelen == 4) {
1340 #ifdef INET
1341 struct in_addr laddr, raddr;
1342 u_int lport, rport;
1343
1344 if (pf != PF_INET)
1345 return EPROTONOSUPPORT;
1346 raddr.s_addr = (uint32_t)name[0];
1347 rport = (u_int)name[1];
1348 laddr.s_addr = (uint32_t)name[2];
1349 lport = (u_int)name[3];
1350
1351 mutex_enter(softnet_lock);
1352 error = inet4_ident_core(raddr, rport, laddr, lport,
1353 oldp, oldlenp, l, dodrop);
1354 mutex_exit(softnet_lock);
1355 return error;
1356 #else /* INET */
1357 return EINVAL;
1358 #endif /* INET */
1359 }
1360
1361 if (newp == NULL || newlen != sizeof(sa))
1362 return EINVAL;
1363 error = copyin(newp, &sa, newlen);
1364 if (error)
1365 return error;
1366
1367 /*
1368 * requested families must match
1369 */
1370 if (pf != sa[0].ss_family || sa[0].ss_family != sa[1].ss_family)
1371 return EINVAL;
1372
1373 switch (pf) {
1374 #ifdef INET6
1375 case PF_INET6:
1376 si6[0] = (struct sockaddr_in6*)&sa[0];
1377 si6[1] = (struct sockaddr_in6*)&sa[1];
1378 if (si6[0]->sin6_len != sizeof(*si6[0]) ||
1379 si6[1]->sin6_len != sizeof(*si6[1]))
1380 return EINVAL;
1381
1382 if (!IN6_IS_ADDR_V4MAPPED(&si6[0]->sin6_addr) &&
1383 !IN6_IS_ADDR_V4MAPPED(&si6[1]->sin6_addr)) {
1384 error = sa6_embedscope(si6[0], ip6_use_defzone);
1385 if (error)
1386 return error;
1387 error = sa6_embedscope(si6[1], ip6_use_defzone);
1388 if (error)
1389 return error;
1390
1391 mutex_enter(softnet_lock);
1392 error = inet6_ident_core(&si6[0]->sin6_addr,
1393 si6[0]->sin6_port, &si6[1]->sin6_addr,
1394 si6[1]->sin6_port, oldp, oldlenp, l, dodrop);
1395 mutex_exit(softnet_lock);
1396 return error;
1397 }
1398
1399 if (IN6_IS_ADDR_V4MAPPED(&si6[0]->sin6_addr) !=
1400 IN6_IS_ADDR_V4MAPPED(&si6[1]->sin6_addr))
1401 return EINVAL;
1402
1403 in6_sin6_2_sin_in_sock((struct sockaddr *)&sa[0]);
1404 in6_sin6_2_sin_in_sock((struct sockaddr *)&sa[1]);
1405 /*FALLTHROUGH*/
1406 #endif /* INET6 */
1407 #ifdef INET
1408 case PF_INET:
1409 si4[0] = (struct sockaddr_in*)&sa[0];
1410 si4[1] = (struct sockaddr_in*)&sa[1];
1411 if (si4[0]->sin_len != sizeof(*si4[0]) ||
1412 si4[0]->sin_len != sizeof(*si4[1]))
1413 return EINVAL;
1414
1415 mutex_enter(softnet_lock);
1416 error = inet4_ident_core(si4[0]->sin_addr, si4[0]->sin_port,
1417 si4[1]->sin_addr, si4[1]->sin_port,
1418 oldp, oldlenp, l, dodrop);
1419 mutex_exit(softnet_lock);
1420 return error;
1421 #endif /* INET */
1422 default:
1423 return EPROTONOSUPPORT;
1424 }
1425 }
1426
1427 static int
1428 sysctl_tcp_congctl(SYSCTLFN_ARGS)
1429 {
1430 struct sysctlnode node;
1431 int error;
1432 char newname[TCPCC_MAXLEN];
1433
1434 strlcpy(newname, tcp_congctl_global_name, sizeof(newname) - 1);
1435
1436 node = *rnode;
1437 node.sysctl_data = newname;
1438 node.sysctl_size = sizeof(newname);
1439
1440 error = sysctl_lookup(SYSCTLFN_CALL(&node));
1441
1442 if (error ||
1443 newp == NULL ||
1444 strncmp(newname, tcp_congctl_global_name, sizeof(newname)) == 0)
1445 return error;
1446
1447 mutex_enter(softnet_lock);
1448 error = tcp_congctl_select(NULL, newname);
1449 mutex_exit(softnet_lock);
1450
1451 return error;
1452 }
1453
1454 static int
1455 sysctl_tcp_init_win(SYSCTLFN_ARGS)
1456 {
1457 int error;
1458 u_int iw;
1459 struct sysctlnode node;
1460
1461 iw = *(u_int *)rnode->sysctl_data;
1462 node = *rnode;
1463 node.sysctl_data = &iw;
1464 node.sysctl_size = sizeof(iw);
1465 error = sysctl_lookup(SYSCTLFN_CALL(&node));
1466 if (error || newp == NULL)
1467 return error;
1468
1469 if (iw >= __arraycount(tcp_init_win_max))
1470 return EINVAL;
1471 *(u_int *)rnode->sysctl_data = iw;
1472 return 0;
1473 }
1474
1475 static int
1476 sysctl_tcp_keep(SYSCTLFN_ARGS)
1477 {
1478 int error;
1479 u_int tmp;
1480 struct sysctlnode node;
1481
1482 node = *rnode;
1483 tmp = *(u_int *)rnode->sysctl_data;
1484 node.sysctl_data = &tmp;
1485
1486 error = sysctl_lookup(SYSCTLFN_CALL(&node));
1487 if (error || newp == NULL)
1488 return error;
1489
1490 mutex_enter(softnet_lock);
1491
1492 *(u_int *)rnode->sysctl_data = tmp;
1493 tcp_tcpcb_template(); /* update the template */
1494
1495 mutex_exit(softnet_lock);
1496 return 0;
1497 }
1498
1499 static int
1500 sysctl_net_inet_tcp_stats(SYSCTLFN_ARGS)
1501 {
1502
1503 return (NETSTAT_SYSCTL(tcpstat_percpu, TCP_NSTATS));
1504 }
1505
1506 /*
1507 * this (second stage) setup routine is a replacement for tcp_sysctl()
1508 * (which is currently used for ipv4 and ipv6)
1509 */
1510 static void
1511 sysctl_net_inet_tcp_setup2(struct sysctllog **clog, int pf, const char *pfname,
1512 const char *tcpname)
1513 {
1514 const struct sysctlnode *sack_node;
1515 const struct sysctlnode *abc_node;
1516 const struct sysctlnode *ecn_node;
1517 const struct sysctlnode *congctl_node;
1518 const struct sysctlnode *mslt_node;
1519 const struct sysctlnode *vtw_node;
1520 #ifdef TCP_DEBUG
1521 extern struct tcp_debug tcp_debug[TCP_NDEBUG];
1522 extern int tcp_debx;
1523 #endif
1524
1525 sysctl_createv(clog, 0, NULL, NULL,
1526 CTLFLAG_PERMANENT,
1527 CTLTYPE_NODE, "net", NULL,
1528 NULL, 0, NULL, 0,
1529 CTL_NET, CTL_EOL);
1530 sysctl_createv(clog, 0, NULL, NULL,
1531 CTLFLAG_PERMANENT,
1532 CTLTYPE_NODE, pfname, NULL,
1533 NULL, 0, NULL, 0,
1534 CTL_NET, pf, CTL_EOL);
1535 sysctl_createv(clog, 0, NULL, NULL,
1536 CTLFLAG_PERMANENT,
1537 CTLTYPE_NODE, tcpname,
1538 SYSCTL_DESCR("TCP related settings"),
1539 NULL, 0, NULL, 0,
1540 CTL_NET, pf, IPPROTO_TCP, CTL_EOL);
1541
1542 sysctl_createv(clog, 0, NULL, NULL,
1543 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1544 CTLTYPE_INT, "rfc1323",
1545 SYSCTL_DESCR("Enable RFC1323 TCP extensions"),
1546 NULL, 0, &tcp_do_rfc1323, 0,
1547 CTL_NET, pf, IPPROTO_TCP, TCPCTL_RFC1323, CTL_EOL);
1548 sysctl_createv(clog, 0, NULL, NULL,
1549 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1550 CTLTYPE_INT, "sendspace",
1551 SYSCTL_DESCR("Default TCP send buffer size"),
1552 NULL, 0, &tcp_sendspace, 0,
1553 CTL_NET, pf, IPPROTO_TCP, TCPCTL_SENDSPACE, CTL_EOL);
1554 sysctl_createv(clog, 0, NULL, NULL,
1555 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1556 CTLTYPE_INT, "recvspace",
1557 SYSCTL_DESCR("Default TCP receive buffer size"),
1558 NULL, 0, &tcp_recvspace, 0,
1559 CTL_NET, pf, IPPROTO_TCP, TCPCTL_RECVSPACE, CTL_EOL);
1560 sysctl_createv(clog, 0, NULL, NULL,
1561 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1562 CTLTYPE_INT, "mssdflt",
1563 SYSCTL_DESCR("Default maximum segment size"),
1564 sysctl_net_inet_tcp_mssdflt, 0, &tcp_mssdflt, 0,
1565 CTL_NET, pf, IPPROTO_TCP, TCPCTL_MSSDFLT, CTL_EOL);
1566 sysctl_createv(clog, 0, NULL, NULL,
1567 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1568 CTLTYPE_INT, "minmss",
1569 SYSCTL_DESCR("Lower limit for TCP maximum segment size"),
1570 NULL, 0, &tcp_minmss, 0,
1571 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
1572 sysctl_createv(clog, 0, NULL, NULL,
1573 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1574 CTLTYPE_INT, "msl",
1575 SYSCTL_DESCR("Maximum Segment Life"),
1576 NULL, 0, &tcp_msl, 0,
1577 CTL_NET, pf, IPPROTO_TCP, TCPCTL_MSL, CTL_EOL);
1578 sysctl_createv(clog, 0, NULL, NULL,
1579 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1580 CTLTYPE_INT, "syn_cache_limit",
1581 SYSCTL_DESCR("Maximum number of entries in the TCP "
1582 "compressed state engine"),
1583 NULL, 0, &tcp_syn_cache_limit, 0,
1584 CTL_NET, pf, IPPROTO_TCP, TCPCTL_SYN_CACHE_LIMIT,
1585 CTL_EOL);
1586 sysctl_createv(clog, 0, NULL, NULL,
1587 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1588 CTLTYPE_INT, "syn_bucket_limit",
1589 SYSCTL_DESCR("Maximum number of entries per hash "
1590 "bucket in the TCP compressed state "
1591 "engine"),
1592 NULL, 0, &tcp_syn_bucket_limit, 0,
1593 CTL_NET, pf, IPPROTO_TCP, TCPCTL_SYN_BUCKET_LIMIT,
1594 CTL_EOL);
1595 #if 0 /* obsoleted */
1596 sysctl_createv(clog, 0, NULL, NULL,
1597 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1598 CTLTYPE_INT, "syn_cache_interval",
1599 SYSCTL_DESCR("TCP compressed state engine's timer interval"),
1600 NULL, 0, &tcp_syn_cache_interval, 0,
1601 CTL_NET, pf, IPPROTO_TCP, TCPCTL_SYN_CACHE_INTER,
1602 CTL_EOL);
1603 #endif
1604 sysctl_createv(clog, 0, NULL, NULL,
1605 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1606 CTLTYPE_INT, "init_win",
1607 SYSCTL_DESCR("Initial TCP congestion window"),
1608 sysctl_tcp_init_win, 0, &tcp_init_win, 0,
1609 CTL_NET, pf, IPPROTO_TCP, TCPCTL_INIT_WIN, CTL_EOL);
1610 sysctl_createv(clog, 0, NULL, NULL,
1611 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1612 CTLTYPE_INT, "mss_ifmtu",
1613 SYSCTL_DESCR("Use interface MTU for calculating MSS"),
1614 NULL, 0, &tcp_mss_ifmtu, 0,
1615 CTL_NET, pf, IPPROTO_TCP, TCPCTL_MSS_IFMTU, CTL_EOL);
1616 sysctl_createv(clog, 0, NULL, &sack_node,
1617 CTLFLAG_PERMANENT,
1618 CTLTYPE_NODE, "sack",
1619 SYSCTL_DESCR("RFC2018 Selective ACKnowledgement tunables"),
1620 NULL, 0, NULL, 0,
1621 CTL_NET, pf, IPPROTO_TCP, TCPCTL_SACK, CTL_EOL);
1622
1623 /* Congctl subtree */
1624 sysctl_createv(clog, 0, NULL, &congctl_node,
1625 CTLFLAG_PERMANENT,
1626 CTLTYPE_NODE, "congctl",
1627 SYSCTL_DESCR("TCP Congestion Control"),
1628 NULL, 0, NULL, 0,
1629 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
1630 sysctl_createv(clog, 0, &congctl_node, NULL,
1631 CTLFLAG_PERMANENT,
1632 CTLTYPE_STRING, "available",
1633 SYSCTL_DESCR("Available Congestion Control Mechanisms"),
1634 NULL, 0, tcp_congctl_avail, 0, CTL_CREATE, CTL_EOL);
1635 sysctl_createv(clog, 0, &congctl_node, NULL,
1636 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1637 CTLTYPE_STRING, "selected",
1638 SYSCTL_DESCR("Selected Congestion Control Mechanism"),
1639 sysctl_tcp_congctl, 0, NULL, TCPCC_MAXLEN,
1640 CTL_CREATE, CTL_EOL);
1641
1642 sysctl_createv(clog, 0, NULL, NULL,
1643 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1644 CTLTYPE_INT, "win_scale",
1645 SYSCTL_DESCR("Use RFC1323 window scale options"),
1646 NULL, 0, &tcp_do_win_scale, 0,
1647 CTL_NET, pf, IPPROTO_TCP, TCPCTL_WSCALE, CTL_EOL);
1648 sysctl_createv(clog, 0, NULL, NULL,
1649 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1650 CTLTYPE_INT, "timestamps",
1651 SYSCTL_DESCR("Use RFC1323 time stamp options"),
1652 NULL, 0, &tcp_do_timestamps, 0,
1653 CTL_NET, pf, IPPROTO_TCP, TCPCTL_TSTAMP, CTL_EOL);
1654 sysctl_createv(clog, 0, NULL, NULL,
1655 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1656 CTLTYPE_INT, "compat_42",
1657 SYSCTL_DESCR("Enable workarounds for 4.2BSD TCP bugs"),
1658 NULL, 0, &tcp_compat_42, 0,
1659 CTL_NET, pf, IPPROTO_TCP, TCPCTL_COMPAT_42, CTL_EOL);
1660 sysctl_createv(clog, 0, NULL, NULL,
1661 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1662 CTLTYPE_INT, "cwm",
1663 SYSCTL_DESCR("Hughes/Touch/Heidemann Congestion Window "
1664 "Monitoring"),
1665 NULL, 0, &tcp_cwm, 0,
1666 CTL_NET, pf, IPPROTO_TCP, TCPCTL_CWM, CTL_EOL);
1667 sysctl_createv(clog, 0, NULL, NULL,
1668 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1669 CTLTYPE_INT, "cwm_burstsize",
1670 SYSCTL_DESCR("Congestion Window Monitoring allowed "
1671 "burst count in packets"),
1672 NULL, 0, &tcp_cwm_burstsize, 0,
1673 CTL_NET, pf, IPPROTO_TCP, TCPCTL_CWM_BURSTSIZE,
1674 CTL_EOL);
1675 sysctl_createv(clog, 0, NULL, NULL,
1676 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1677 CTLTYPE_INT, "ack_on_push",
1678 SYSCTL_DESCR("Immediately return ACK when PSH is "
1679 "received"),
1680 NULL, 0, &tcp_ack_on_push, 0,
1681 CTL_NET, pf, IPPROTO_TCP, TCPCTL_ACK_ON_PUSH, CTL_EOL);
1682 sysctl_createv(clog, 0, NULL, NULL,
1683 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1684 CTLTYPE_INT, "keepidle",
1685 SYSCTL_DESCR("Allowed connection idle ticks before a "
1686 "keepalive probe is sent"),
1687 sysctl_tcp_keep, 0, &tcp_keepidle, 0,
1688 CTL_NET, pf, IPPROTO_TCP, TCPCTL_KEEPIDLE, CTL_EOL);
1689 sysctl_createv(clog, 0, NULL, NULL,
1690 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1691 CTLTYPE_INT, "keepintvl",
1692 SYSCTL_DESCR("Ticks before next keepalive probe is sent"),
1693 sysctl_tcp_keep, 0, &tcp_keepintvl, 0,
1694 CTL_NET, pf, IPPROTO_TCP, TCPCTL_KEEPINTVL, CTL_EOL);
1695 sysctl_createv(clog, 0, NULL, NULL,
1696 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1697 CTLTYPE_INT, "keepcnt",
1698 SYSCTL_DESCR("Number of keepalive probes to send"),
1699 sysctl_tcp_keep, 0, &tcp_keepcnt, 0,
1700 CTL_NET, pf, IPPROTO_TCP, TCPCTL_KEEPCNT, CTL_EOL);
1701 sysctl_createv(clog, 0, NULL, NULL,
1702 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
1703 CTLTYPE_INT, "slowhz",
1704 SYSCTL_DESCR("Keepalive ticks per second"),
1705 NULL, PR_SLOWHZ, NULL, 0,
1706 CTL_NET, pf, IPPROTO_TCP, TCPCTL_SLOWHZ, CTL_EOL);
1707 sysctl_createv(clog, 0, NULL, NULL,
1708 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1709 CTLTYPE_INT, "log_refused",
1710 SYSCTL_DESCR("Log refused TCP connections"),
1711 NULL, 0, &tcp_log_refused, 0,
1712 CTL_NET, pf, IPPROTO_TCP, TCPCTL_LOG_REFUSED, CTL_EOL);
1713 #if 0 /* obsoleted */
1714 sysctl_createv(clog, 0, NULL, NULL,
1715 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1716 CTLTYPE_INT, "rstratelimit", NULL,
1717 NULL, 0, &tcp_rst_ratelim, 0,
1718 CTL_NET, pf, IPPROTO_TCP, TCPCTL_RSTRATELIMIT, CTL_EOL);
1719 #endif
1720 sysctl_createv(clog, 0, NULL, NULL,
1721 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1722 CTLTYPE_INT, "rstppslimit",
1723 SYSCTL_DESCR("Maximum number of RST packets to send "
1724 "per second"),
1725 NULL, 0, &tcp_rst_ppslim, 0,
1726 CTL_NET, pf, IPPROTO_TCP, TCPCTL_RSTPPSLIMIT, CTL_EOL);
1727 sysctl_createv(clog, 0, NULL, NULL,
1728 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1729 CTLTYPE_INT, "delack_ticks",
1730 SYSCTL_DESCR("Number of ticks to delay sending an ACK"),
1731 NULL, 0, &tcp_delack_ticks, 0,
1732 CTL_NET, pf, IPPROTO_TCP, TCPCTL_DELACK_TICKS, CTL_EOL);
1733 sysctl_createv(clog, 0, NULL, NULL,
1734 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1735 CTLTYPE_INT, "init_win_local",
1736 SYSCTL_DESCR("Initial TCP window size (in segments)"),
1737 sysctl_tcp_init_win, 0, &tcp_init_win_local, 0,
1738 CTL_NET, pf, IPPROTO_TCP, TCPCTL_INIT_WIN_LOCAL,
1739 CTL_EOL);
1740 sysctl_createv(clog, 0, NULL, NULL,
1741 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1742 CTLTYPE_STRUCT, "ident",
1743 SYSCTL_DESCR("RFC1413 Identification Protocol lookups"),
1744 sysctl_net_inet_tcp_ident, 0, NULL, sizeof(uid_t),
1745 CTL_NET, pf, IPPROTO_TCP, TCPCTL_IDENT, CTL_EOL);
1746 sysctl_createv(clog, 0, NULL, NULL,
1747 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1748 CTLTYPE_INT, "do_loopback_cksum",
1749 SYSCTL_DESCR("Perform TCP checksum on loopback"),
1750 NULL, 0, &tcp_do_loopback_cksum, 0,
1751 CTL_NET, pf, IPPROTO_TCP, TCPCTL_LOOPBACKCKSUM,
1752 CTL_EOL);
1753 sysctl_createv(clog, 0, NULL, NULL,
1754 CTLFLAG_PERMANENT,
1755 CTLTYPE_STRUCT, "pcblist",
1756 SYSCTL_DESCR("TCP protocol control block list"),
1757 sysctl_inpcblist, 0, tcbtable, 0,
1758 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE,
1759 CTL_EOL);
1760 sysctl_createv(clog, 0, NULL, NULL,
1761 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1762 CTLTYPE_INT, "keepinit",
1763 SYSCTL_DESCR("Ticks before initial tcp connection times out"),
1764 sysctl_tcp_keep, 0, &tcp_keepinit, 0,
1765 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
1766
1767 /* TCP socket buffers auto-sizing nodes */
1768 sysctl_createv(clog, 0, NULL, NULL,
1769 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1770 CTLTYPE_INT, "recvbuf_auto",
1771 SYSCTL_DESCR("Enable automatic receive "
1772 "buffer sizing (experimental)"),
1773 NULL, 0, &tcp_do_autorcvbuf, 0,
1774 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
1775 sysctl_createv(clog, 0, NULL, NULL,
1776 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1777 CTLTYPE_INT, "recvbuf_inc",
1778 SYSCTL_DESCR("Incrementor step size of "
1779 "automatic receive buffer"),
1780 NULL, 0, &tcp_autorcvbuf_inc, 0,
1781 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
1782 sysctl_createv(clog, 0, NULL, NULL,
1783 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1784 CTLTYPE_INT, "recvbuf_max",
1785 SYSCTL_DESCR("Max size of automatic receive buffer"),
1786 NULL, 0, &tcp_autorcvbuf_max, 0,
1787 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
1788
1789 sysctl_createv(clog, 0, NULL, NULL,
1790 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1791 CTLTYPE_INT, "sendbuf_auto",
1792 SYSCTL_DESCR("Enable automatic send "
1793 "buffer sizing (experimental)"),
1794 NULL, 0, &tcp_do_autosndbuf, 0,
1795 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
1796 sysctl_createv(clog, 0, NULL, NULL,
1797 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1798 CTLTYPE_INT, "sendbuf_inc",
1799 SYSCTL_DESCR("Incrementor step size of "
1800 "automatic send buffer"),
1801 NULL, 0, &tcp_autosndbuf_inc, 0,
1802 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
1803 sysctl_createv(clog, 0, NULL, NULL,
1804 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1805 CTLTYPE_INT, "sendbuf_max",
1806 SYSCTL_DESCR("Max size of automatic send buffer"),
1807 NULL, 0, &tcp_autosndbuf_max, 0,
1808 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
1809
1810 /* ECN subtree */
1811 sysctl_createv(clog, 0, NULL, &ecn_node,
1812 CTLFLAG_PERMANENT,
1813 CTLTYPE_NODE, "ecn",
1814 SYSCTL_DESCR("RFC3168 Explicit Congestion Notification"),
1815 NULL, 0, NULL, 0,
1816 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
1817 sysctl_createv(clog, 0, &ecn_node, NULL,
1818 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1819 CTLTYPE_INT, "enable",
1820 SYSCTL_DESCR("Enable TCP Explicit Congestion "
1821 "Notification"),
1822 NULL, 0, &tcp_do_ecn, 0, CTL_CREATE, CTL_EOL);
1823 sysctl_createv(clog, 0, &ecn_node, NULL,
1824 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1825 CTLTYPE_INT, "maxretries",
1826 SYSCTL_DESCR("Number of times to retry ECN setup "
1827 "before disabling ECN on the connection"),
1828 NULL, 0, &tcp_ecn_maxretries, 0, CTL_CREATE, CTL_EOL);
1829
1830 /* SACK gets it's own little subtree. */
1831 sysctl_createv(clog, 0, NULL, &sack_node,
1832 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1833 CTLTYPE_INT, "enable",
1834 SYSCTL_DESCR("Enable RFC2018 Selective ACKnowledgement"),
1835 NULL, 0, &tcp_do_sack, 0,
1836 CTL_NET, pf, IPPROTO_TCP, TCPCTL_SACK, CTL_CREATE, CTL_EOL);
1837 sysctl_createv(clog, 0, NULL, &sack_node,
1838 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1839 CTLTYPE_INT, "maxholes",
1840 SYSCTL_DESCR("Maximum number of TCP SACK holes allowed per connection"),
1841 NULL, 0, &tcp_sack_tp_maxholes, 0,
1842 CTL_NET, pf, IPPROTO_TCP, TCPCTL_SACK, CTL_CREATE, CTL_EOL);
1843 sysctl_createv(clog, 0, NULL, &sack_node,
1844 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1845 CTLTYPE_INT, "globalmaxholes",
1846 SYSCTL_DESCR("Global maximum number of TCP SACK holes"),
1847 NULL, 0, &tcp_sack_globalmaxholes, 0,
1848 CTL_NET, pf, IPPROTO_TCP, TCPCTL_SACK, CTL_CREATE, CTL_EOL);
1849 sysctl_createv(clog, 0, NULL, &sack_node,
1850 CTLFLAG_PERMANENT,
1851 CTLTYPE_INT, "globalholes",
1852 SYSCTL_DESCR("Global number of TCP SACK holes"),
1853 NULL, 0, &tcp_sack_globalholes, 0,
1854 CTL_NET, pf, IPPROTO_TCP, TCPCTL_SACK, CTL_CREATE, CTL_EOL);
1855
1856 sysctl_createv(clog, 0, NULL, NULL,
1857 CTLFLAG_PERMANENT,
1858 CTLTYPE_STRUCT, "stats",
1859 SYSCTL_DESCR("TCP statistics"),
1860 sysctl_net_inet_tcp_stats, 0, NULL, 0,
1861 CTL_NET, pf, IPPROTO_TCP, TCPCTL_STATS,
1862 CTL_EOL);
1863 sysctl_createv(clog, 0, NULL, NULL,
1864 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1865 CTLTYPE_INT, "local_by_rtt",
1866 SYSCTL_DESCR("Use RTT estimator to decide which hosts "
1867 "are local"),
1868 NULL, 0, &tcp_rttlocal, 0,
1869 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
1870 #ifdef TCP_DEBUG
1871 sysctl_createv(clog, 0, NULL, NULL,
1872 CTLFLAG_PERMANENT,
1873 CTLTYPE_STRUCT, "debug",
1874 SYSCTL_DESCR("TCP sockets debug information"),
1875 NULL, 0, &tcp_debug, sizeof(tcp_debug),
1876 CTL_NET, pf, IPPROTO_TCP, TCPCTL_DEBUG,
1877 CTL_EOL);
1878 sysctl_createv(clog, 0, NULL, NULL,
1879 CTLFLAG_PERMANENT,
1880 CTLTYPE_INT, "debx",
1881 SYSCTL_DESCR("Number of TCP debug sockets messages"),
1882 NULL, 0, &tcp_debx, sizeof(tcp_debx),
1883 CTL_NET, pf, IPPROTO_TCP, TCPCTL_DEBX,
1884 CTL_EOL);
1885 #endif
1886 sysctl_createv(clog, 0, NULL, NULL,
1887 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1888 CTLTYPE_STRUCT, "drop",
1889 SYSCTL_DESCR("TCP drop connection"),
1890 sysctl_net_inet_tcp_drop, 0, NULL, 0,
1891 CTL_NET, pf, IPPROTO_TCP, TCPCTL_DROP, CTL_EOL);
1892 sysctl_createv(clog, 0, NULL, NULL,
1893 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1894 CTLTYPE_INT, "iss_hash",
1895 SYSCTL_DESCR("Enable RFC 1948 ISS by cryptographic "
1896 "hash computation"),
1897 NULL, 0, &tcp_do_rfc1948, sizeof(tcp_do_rfc1948),
1898 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE,
1899 CTL_EOL);
1900
1901 /* ABC subtree */
1902
1903 sysctl_createv(clog, 0, NULL, &abc_node,
1904 CTLFLAG_PERMANENT, CTLTYPE_NODE, "abc",
1905 SYSCTL_DESCR("RFC3465 Appropriate Byte Counting (ABC)"),
1906 NULL, 0, NULL, 0,
1907 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
1908 sysctl_createv(clog, 0, &abc_node, NULL,
1909 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1910 CTLTYPE_INT, "enable",
1911 SYSCTL_DESCR("Enable RFC3465 Appropriate Byte Counting"),
1912 NULL, 0, &tcp_do_abc, 0, CTL_CREATE, CTL_EOL);
1913 sysctl_createv(clog, 0, &abc_node, NULL,
1914 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1915 CTLTYPE_INT, "aggressive",
1916 SYSCTL_DESCR("1: L=2*SMSS 0: L=1*SMSS"),
1917 NULL, 0, &tcp_abc_aggressive, 0, CTL_CREATE, CTL_EOL);
1918
1919 /* MSL tuning subtree */
1920
1921 sysctl_createv(clog, 0, NULL, &mslt_node,
1922 CTLFLAG_PERMANENT, CTLTYPE_NODE, "mslt",
1923 SYSCTL_DESCR("MSL Tuning for TIME_WAIT truncation"),
1924 NULL, 0, NULL, 0,
1925 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
1926 sysctl_createv(clog, 0, &mslt_node, NULL,
1927 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1928 CTLTYPE_INT, "enable",
1929 SYSCTL_DESCR("Enable TIME_WAIT truncation"),
1930 NULL, 0, &tcp_msl_enable, 0, CTL_CREATE, CTL_EOL);
1931 sysctl_createv(clog, 0, &mslt_node, NULL,
1932 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1933 CTLTYPE_INT, "loopback",
1934 SYSCTL_DESCR("MSL value to use for loopback connections"),
1935 NULL, 0, &tcp_msl_loop, 0, CTL_CREATE, CTL_EOL);
1936 sysctl_createv(clog, 0, &mslt_node, NULL,
1937 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1938 CTLTYPE_INT, "local",
1939 SYSCTL_DESCR("MSL value to use for local connections"),
1940 NULL, 0, &tcp_msl_local, 0, CTL_CREATE, CTL_EOL);
1941 sysctl_createv(clog, 0, &mslt_node, NULL,
1942 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1943 CTLTYPE_INT, "remote",
1944 SYSCTL_DESCR("MSL value to use for remote connections"),
1945 NULL, 0, &tcp_msl_remote, 0, CTL_CREATE, CTL_EOL);
1946 sysctl_createv(clog, 0, &mslt_node, NULL,
1947 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1948 CTLTYPE_INT, "remote_threshold",
1949 SYSCTL_DESCR("RTT estimate value to promote local to remote"),
1950 NULL, 0, &tcp_msl_remote_threshold, 0, CTL_CREATE, CTL_EOL);
1951
1952 /* vestigial TIME_WAIT tuning subtree */
1953
1954 sysctl_createv(clog, 0, NULL, &vtw_node,
1955 CTLFLAG_PERMANENT, CTLTYPE_NODE, "vtw",
1956 SYSCTL_DESCR("Tuning for Vestigial TIME_WAIT"),
1957 NULL, 0, NULL, 0,
1958 CTL_NET, pf, IPPROTO_TCP, CTL_CREATE, CTL_EOL);
1959 sysctl_createv(clog, 0, &vtw_node, NULL,
1960 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1961 CTLTYPE_INT, "enable",
1962 SYSCTL_DESCR("Enable Vestigial TIME_WAIT"),
1963 sysctl_tcp_vtw_enable, 0,
1964 (pf == AF_INET) ? &tcp4_vtw_enable : &tcp6_vtw_enable,
1965 0, CTL_CREATE, CTL_EOL);
1966 sysctl_createv(clog, 0, &vtw_node, NULL,
1967 CTLFLAG_PERMANENT|CTLFLAG_READONLY,
1968 CTLTYPE_INT, "entries",
1969 SYSCTL_DESCR("Maximum number of vestigial TIME_WAIT entries"),
1970 NULL, 0, &tcp_vtw_entries, 0, CTL_CREATE, CTL_EOL);
1971 }
1972
1973 void
1974 tcp_usrreq_init(void)
1975 {
1976
1977 #ifdef INET
1978 sysctl_net_inet_tcp_setup2(NULL, PF_INET, "inet", "tcp");
1979 #endif
1980 #ifdef INET6
1981 sysctl_net_inet_tcp_setup2(NULL, PF_INET6, "inet6", "tcp6");
1982 #endif
1983 }
1984
1985 PR_WRAP_USRREQ(tcp_usrreq)
1986
1987 #define tcp_usrreq tcp_usrreq_wrapper
1988
1989 const struct pr_usrreqs tcp_usrreqs = {
1990 .pr_attach = tcp_attach,
1991 .pr_detach = tcp_detach,
1992 .pr_generic = tcp_usrreq,
1993 };
1994