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