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