tcp_usrreq.c revision 1.81.2.7 1 /* $NetBSD: tcp_usrreq.c,v 1.81.2.7 2005/03/04 16:53:30 skrll 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 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 *
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
44 * are met:
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
50 * 3. All advertising materials mentioning features or use of this software
51 * must display the following acknowledgement:
52 * This product includes software developed by the NetBSD
53 * Foundation, Inc. and its contributors.
54 * 4. Neither the name of The NetBSD Foundation nor the names of its
55 * contributors may be used to endorse or promote products derived
56 * from this software without specific prior written permission.
57 *
58 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
59 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
60 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
61 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
62 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
63 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
64 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
65 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
66 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
67 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
68 * POSSIBILITY OF SUCH DAMAGE.
69 */
70
71 /*
72 * Copyright (c) 1982, 1986, 1988, 1993, 1995
73 * The Regents of the University of California. All rights reserved.
74 *
75 * Redistribution and use in source and binary forms, with or without
76 * modification, are permitted provided that the following conditions
77 * are met:
78 * 1. Redistributions of source code must retain the above copyright
79 * notice, this list of conditions and the following disclaimer.
80 * 2. Redistributions in binary form must reproduce the above copyright
81 * notice, this list of conditions and the following disclaimer in the
82 * documentation and/or other materials provided with the distribution.
83 * 3. Neither the name of the University nor the names of its contributors
84 * may be used to endorse or promote products derived from this software
85 * without specific prior written permission.
86 *
87 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
88 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
89 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
90 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
91 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
92 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
93 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
94 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
95 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
96 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
97 * SUCH DAMAGE.
98 *
99 * @(#)tcp_usrreq.c 8.5 (Berkeley) 6/21/95
100 */
101
102 #include <sys/cdefs.h>
103 __KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.81.2.7 2005/03/04 16:53:30 skrll Exp $");
104
105 #include "opt_inet.h"
106 #include "opt_ipsec.h"
107 #include "opt_tcp_debug.h"
108 #include "opt_mbuftrace.h"
109
110 #include <sys/param.h>
111 #include <sys/systm.h>
112 #include <sys/kernel.h>
113 #include <sys/malloc.h>
114 #include <sys/mbuf.h>
115 #include <sys/socket.h>
116 #include <sys/socketvar.h>
117 #include <sys/protosw.h>
118 #include <sys/errno.h>
119 #include <sys/stat.h>
120 #include <sys/proc.h>
121 #include <sys/domain.h>
122 #include <sys/sysctl.h>
123
124 #include <net/if.h>
125 #include <net/route.h>
126
127 #include <netinet/in.h>
128 #include <netinet/in_systm.h>
129 #include <netinet/in_var.h>
130 #include <netinet/ip.h>
131 #include <netinet/in_pcb.h>
132 #include <netinet/ip_var.h>
133
134 #ifdef INET6
135 #ifndef INET
136 #include <netinet/in.h>
137 #endif
138 #include <netinet/ip6.h>
139 #include <netinet6/in6_pcb.h>
140 #include <netinet6/ip6_var.h>
141 #endif
142
143 #include <netinet/tcp.h>
144 #include <netinet/tcp_fsm.h>
145 #include <netinet/tcp_seq.h>
146 #include <netinet/tcp_timer.h>
147 #include <netinet/tcp_var.h>
148 #include <netinet/tcpip.h>
149 #include <netinet/tcp_debug.h>
150
151 #include "opt_tcp_space.h"
152
153 #ifdef IPSEC
154 #include <netinet6/ipsec.h>
155 #endif /*IPSEC*/
156
157 /*
158 * TCP protocol interface to socket abstraction.
159 */
160
161 /*
162 * Process a TCP user request for TCP tb. If this is a send request
163 * then m is the mbuf chain of send data. If this is a timer expiration
164 * (called from the software clock routine), then timertype tells which timer.
165 */
166 /*ARGSUSED*/
167 int
168 tcp_usrreq(struct socket *so, int req,
169 struct mbuf *m, struct mbuf *nam, struct mbuf *control, struct lwp *l)
170 {
171 struct inpcb *inp;
172 #ifdef INET6
173 struct in6pcb *in6p;
174 #endif
175 struct tcpcb *tp = NULL;
176 struct proc *p;
177 int s;
178 int error = 0;
179 #ifdef TCP_DEBUG
180 int ostate = 0;
181 #endif
182 int family; /* family of the socket */
183
184 p = l ? l->l_proc : NULL;
185 family = so->so_proto->pr_domain->dom_family;
186
187 if (req == PRU_CONTROL) {
188 switch (family) {
189 #ifdef INET
190 case PF_INET:
191 return (in_control(so, (long)m, (caddr_t)nam,
192 (struct ifnet *)control, p));
193 #endif
194 #ifdef INET6
195 case PF_INET6:
196 return (in6_control(so, (long)m, (caddr_t)nam,
197 (struct ifnet *)control, p));
198 #endif
199 default:
200 return EAFNOSUPPORT;
201 }
202 }
203
204 if (req == PRU_PURGEIF) {
205 switch (family) {
206 #ifdef INET
207 case PF_INET:
208 in_pcbpurgeif0(&tcbtable, (struct ifnet *)control);
209 in_purgeif((struct ifnet *)control);
210 in_pcbpurgeif(&tcbtable, (struct ifnet *)control);
211 break;
212 #endif
213 #ifdef INET6
214 case PF_INET6:
215 in6_pcbpurgeif0(&tcbtable, (struct ifnet *)control);
216 in6_purgeif((struct ifnet *)control);
217 in6_pcbpurgeif(&tcbtable, (struct ifnet *)control);
218 break;
219 #endif
220 default:
221 return (EAFNOSUPPORT);
222 }
223 return (0);
224 }
225
226 s = splsoftnet();
227 switch (family) {
228 #ifdef INET
229 case PF_INET:
230 inp = sotoinpcb(so);
231 #ifdef INET6
232 in6p = NULL;
233 #endif
234 break;
235 #endif
236 #ifdef INET6
237 case PF_INET6:
238 inp = NULL;
239 in6p = sotoin6pcb(so);
240 break;
241 #endif
242 default:
243 splx(s);
244 return EAFNOSUPPORT;
245 }
246
247 #ifdef DIAGNOSTIC
248 #ifdef INET6
249 if (inp && in6p)
250 panic("tcp_usrreq: both inp and in6p set to non-NULL");
251 #endif
252 if (req != PRU_SEND && req != PRU_SENDOOB && control)
253 panic("tcp_usrreq: unexpected control mbuf");
254 #endif
255 /*
256 * When a TCP is attached to a socket, then there will be
257 * a (struct inpcb) pointed at by the socket, and this
258 * structure will point at a subsidary (struct tcpcb).
259 */
260 #ifndef INET6
261 if (inp == 0 && req != PRU_ATTACH)
262 #else
263 if ((inp == 0 && in6p == 0) && req != PRU_ATTACH)
264 #endif
265 {
266 error = EINVAL;
267 goto release;
268 }
269 #ifdef INET
270 if (inp) {
271 tp = intotcpcb(inp);
272 /* WHAT IF TP IS 0? */
273 #ifdef KPROF
274 tcp_acounts[tp->t_state][req]++;
275 #endif
276 #ifdef TCP_DEBUG
277 ostate = tp->t_state;
278 #endif
279 }
280 #endif
281 #ifdef INET6
282 if (in6p) {
283 tp = in6totcpcb(in6p);
284 /* WHAT IF TP IS 0? */
285 #ifdef KPROF
286 tcp_acounts[tp->t_state][req]++;
287 #endif
288 #ifdef TCP_DEBUG
289 ostate = tp->t_state;
290 #endif
291 }
292 #endif
293
294 switch (req) {
295
296 /*
297 * TCP attaches to socket via PRU_ATTACH, reserving space,
298 * and an internet control block.
299 */
300 case PRU_ATTACH:
301 #ifndef INET6
302 if (inp != 0)
303 #else
304 if (inp != 0 || in6p != 0)
305 #endif
306 {
307 error = EISCONN;
308 break;
309 }
310 error = tcp_attach(so);
311 if (error)
312 break;
313 if ((so->so_options & SO_LINGER) && so->so_linger == 0)
314 so->so_linger = TCP_LINGERTIME;
315 tp = sototcpcb(so);
316 break;
317
318 /*
319 * PRU_DETACH detaches the TCP protocol from the socket.
320 */
321 case PRU_DETACH:
322 tp = tcp_disconnect(tp);
323 break;
324
325 /*
326 * Give the socket an address.
327 */
328 case PRU_BIND:
329 switch (family) {
330 #ifdef INET
331 case PF_INET:
332 error = in_pcbbind(inp, nam, p);
333 break;
334 #endif
335 #ifdef INET6
336 case PF_INET6:
337 error = in6_pcbbind(in6p, nam, p);
338 if (!error) {
339 /* mapped addr case */
340 if (IN6_IS_ADDR_V4MAPPED(&in6p->in6p_laddr))
341 tp->t_family = AF_INET;
342 else
343 tp->t_family = AF_INET6;
344 }
345 break;
346 #endif
347 }
348 break;
349
350 /*
351 * Prepare to accept connections.
352 */
353 case PRU_LISTEN:
354 #ifdef INET
355 if (inp && inp->inp_lport == 0) {
356 error = in_pcbbind(inp, (struct mbuf *)0,
357 (struct proc *)0);
358 if (error)
359 break;
360 }
361 #endif
362 #ifdef INET6
363 if (in6p && in6p->in6p_lport == 0) {
364 error = in6_pcbbind(in6p, (struct mbuf *)0,
365 (struct proc *)0);
366 if (error)
367 break;
368 }
369 #endif
370 tp->t_state = TCPS_LISTEN;
371 break;
372
373 /*
374 * Initiate connection to peer.
375 * Create a template for use in transmissions on this connection.
376 * Enter SYN_SENT state, and mark socket as connecting.
377 * Start keep-alive timer, and seed output sequence space.
378 * Send initial segment on connection.
379 */
380 case PRU_CONNECT:
381 #ifdef INET
382 if (inp) {
383 if (inp->inp_lport == 0) {
384 error = in_pcbbind(inp, (struct mbuf *)0,
385 (struct proc *)0);
386 if (error)
387 break;
388 }
389 error = in_pcbconnect(inp, nam);
390 }
391 #endif
392 #ifdef INET6
393 if (in6p) {
394 if (in6p->in6p_lport == 0) {
395 error = in6_pcbbind(in6p, (struct mbuf *)0,
396 (struct proc *)0);
397 if (error)
398 break;
399 }
400 error = in6_pcbconnect(in6p, nam);
401 if (!error) {
402 /* mapped addr case */
403 if (IN6_IS_ADDR_V4MAPPED(&in6p->in6p_faddr))
404 tp->t_family = AF_INET;
405 else
406 tp->t_family = AF_INET6;
407 }
408 }
409 #endif
410 if (error)
411 break;
412 tp->t_template = tcp_template(tp);
413 if (tp->t_template == 0) {
414 #ifdef INET
415 if (inp)
416 in_pcbdisconnect(inp);
417 #endif
418 #ifdef INET6
419 if (in6p)
420 in6_pcbdisconnect(in6p);
421 #endif
422 error = ENOBUFS;
423 break;
424 }
425 /* Compute window scaling to request. */
426 while (tp->request_r_scale < TCP_MAX_WINSHIFT &&
427 (TCP_MAXWIN << tp->request_r_scale) < so->so_rcv.sb_hiwat)
428 tp->request_r_scale++;
429 soisconnecting(so);
430 tcpstat.tcps_connattempt++;
431 tp->t_state = TCPS_SYN_SENT;
432 TCP_TIMER_ARM(tp, TCPT_KEEP, TCPTV_KEEP_INIT);
433 tp->iss = tcp_new_iss(tp, 0);
434 tcp_sendseqinit(tp);
435 error = tcp_output(tp);
436 break;
437
438 /*
439 * Create a TCP connection between two sockets.
440 */
441 case PRU_CONNECT2:
442 error = EOPNOTSUPP;
443 break;
444
445 /*
446 * Initiate disconnect from peer.
447 * If connection never passed embryonic stage, just drop;
448 * else if don't need to let data drain, then can just drop anyways,
449 * else have to begin TCP shutdown process: mark socket disconnecting,
450 * drain unread data, state switch to reflect user close, and
451 * send segment (e.g. FIN) to peer. Socket will be really disconnected
452 * when peer sends FIN and acks ours.
453 *
454 * SHOULD IMPLEMENT LATER PRU_CONNECT VIA REALLOC TCPCB.
455 */
456 case PRU_DISCONNECT:
457 tp = tcp_disconnect(tp);
458 break;
459
460 /*
461 * Accept a connection. Essentially all the work is
462 * done at higher levels; just return the address
463 * of the peer, storing through addr.
464 */
465 case PRU_ACCEPT:
466 #ifdef INET
467 if (inp)
468 in_setpeeraddr(inp, nam);
469 #endif
470 #ifdef INET6
471 if (in6p)
472 in6_setpeeraddr(in6p, nam);
473 #endif
474 break;
475
476 /*
477 * Mark the connection as being incapable of further output.
478 */
479 case PRU_SHUTDOWN:
480 socantsendmore(so);
481 tp = tcp_usrclosed(tp);
482 if (tp)
483 error = tcp_output(tp);
484 break;
485
486 /*
487 * After a receive, possibly send window update to peer.
488 */
489 case PRU_RCVD:
490 /*
491 * soreceive() calls this function when a user receives
492 * ancillary data on a listening socket. We don't call
493 * tcp_output in such a case, since there is no header
494 * template for a listening socket and hence the kernel
495 * will panic.
496 */
497 if ((so->so_state & (SS_ISCONNECTED|SS_ISCONNECTING)) != 0)
498 (void) tcp_output(tp);
499 break;
500
501 /*
502 * Do a send by putting data in output queue and updating urgent
503 * marker if URG set. Possibly send more data.
504 */
505 case PRU_SEND:
506 if (control && control->m_len) {
507 m_freem(control);
508 m_freem(m);
509 error = EINVAL;
510 break;
511 }
512 sbappendstream(&so->so_snd, m);
513 error = tcp_output(tp);
514 break;
515
516 /*
517 * Abort the TCP.
518 */
519 case PRU_ABORT:
520 tp = tcp_drop(tp, ECONNABORTED);
521 break;
522
523 case PRU_SENSE:
524 /*
525 * stat: don't bother with a blocksize.
526 */
527 splx(s);
528 return (0);
529
530 case PRU_RCVOOB:
531 if (control && control->m_len) {
532 m_freem(control);
533 m_freem(m);
534 error = EINVAL;
535 break;
536 }
537 if ((so->so_oobmark == 0 &&
538 (so->so_state & SS_RCVATMARK) == 0) ||
539 so->so_options & SO_OOBINLINE ||
540 tp->t_oobflags & TCPOOB_HADDATA) {
541 error = EINVAL;
542 break;
543 }
544 if ((tp->t_oobflags & TCPOOB_HAVEDATA) == 0) {
545 error = EWOULDBLOCK;
546 break;
547 }
548 m->m_len = 1;
549 *mtod(m, caddr_t) = tp->t_iobc;
550 if (((long)nam & MSG_PEEK) == 0)
551 tp->t_oobflags ^= (TCPOOB_HAVEDATA | TCPOOB_HADDATA);
552 break;
553
554 case PRU_SENDOOB:
555 if (sbspace(&so->so_snd) < -512) {
556 m_freem(m);
557 error = ENOBUFS;
558 break;
559 }
560 /*
561 * According to RFC961 (Assigned Protocols),
562 * the urgent pointer points to the last octet
563 * of urgent data. We continue, however,
564 * to consider it to indicate the first octet
565 * of data past the urgent section.
566 * Otherwise, snd_up should be one lower.
567 */
568 sbappendstream(&so->so_snd, m);
569 tp->snd_up = tp->snd_una + so->so_snd.sb_cc;
570 tp->t_force = 1;
571 error = tcp_output(tp);
572 tp->t_force = 0;
573 break;
574
575 case PRU_SOCKADDR:
576 #ifdef INET
577 if (inp)
578 in_setsockaddr(inp, nam);
579 #endif
580 #ifdef INET6
581 if (in6p)
582 in6_setsockaddr(in6p, nam);
583 #endif
584 break;
585
586 case PRU_PEERADDR:
587 #ifdef INET
588 if (inp)
589 in_setpeeraddr(inp, nam);
590 #endif
591 #ifdef INET6
592 if (in6p)
593 in6_setpeeraddr(in6p, nam);
594 #endif
595 break;
596
597 default:
598 panic("tcp_usrreq");
599 }
600 #ifdef TCP_DEBUG
601 if (tp && (so->so_options & SO_DEBUG))
602 tcp_trace(TA_USER, ostate, tp, NULL, req);
603 #endif
604
605 release:
606 splx(s);
607 return (error);
608 }
609
610 int
611 tcp_ctloutput(int op, struct socket *so, int level, int optname,
612 struct mbuf **mp)
613 {
614 int error = 0, s;
615 struct inpcb *inp;
616 #ifdef INET6
617 struct in6pcb *in6p;
618 #endif
619 struct tcpcb *tp;
620 struct mbuf *m;
621 int i;
622 int family; /* family of the socket */
623
624 family = so->so_proto->pr_domain->dom_family;
625
626 s = splsoftnet();
627 switch (family) {
628 #ifdef INET
629 case PF_INET:
630 inp = sotoinpcb(so);
631 #ifdef INET6
632 in6p = NULL;
633 #endif
634 break;
635 #endif
636 #ifdef INET6
637 case PF_INET6:
638 inp = NULL;
639 in6p = sotoin6pcb(so);
640 break;
641 #endif
642 default:
643 splx(s);
644 return EAFNOSUPPORT;
645 }
646 #ifndef INET6
647 if (inp == NULL)
648 #else
649 if (inp == NULL && in6p == NULL)
650 #endif
651 {
652 splx(s);
653 if (op == PRCO_SETOPT && *mp)
654 (void) m_free(*mp);
655 return (ECONNRESET);
656 }
657 if (level != IPPROTO_TCP) {
658 switch (family) {
659 #ifdef INET
660 case PF_INET:
661 error = ip_ctloutput(op, so, level, optname, mp);
662 break;
663 #endif
664 #ifdef INET6
665 case PF_INET6:
666 error = ip6_ctloutput(op, so, level, optname, mp);
667 break;
668 #endif
669 }
670 splx(s);
671 return (error);
672 }
673 if (inp)
674 tp = intotcpcb(inp);
675 #ifdef INET6
676 else if (in6p)
677 tp = in6totcpcb(in6p);
678 #endif
679 else
680 tp = NULL;
681
682 switch (op) {
683
684 case PRCO_SETOPT:
685 m = *mp;
686 switch (optname) {
687
688 #ifdef TCP_SIGNATURE
689 case TCP_MD5SIG:
690 if (m == NULL || m->m_len < sizeof (int))
691 error = EINVAL;
692 if (error)
693 break;
694 if (*mtod(m, int *) > 0)
695 tp->t_flags |= TF_SIGNATURE;
696 else
697 tp->t_flags &= ~TF_SIGNATURE;
698 break;
699 #endif /* TCP_SIGNATURE */
700
701 case TCP_NODELAY:
702 if (m == NULL || m->m_len < sizeof (int))
703 error = EINVAL;
704 else if (*mtod(m, int *))
705 tp->t_flags |= TF_NODELAY;
706 else
707 tp->t_flags &= ~TF_NODELAY;
708 break;
709
710 case TCP_MAXSEG:
711 if (m && (i = *mtod(m, int *)) > 0 &&
712 i <= tp->t_peermss)
713 tp->t_peermss = i; /* limit on send size */
714 else
715 error = EINVAL;
716 break;
717
718 default:
719 error = ENOPROTOOPT;
720 break;
721 }
722 if (m)
723 (void) m_free(m);
724 break;
725
726 case PRCO_GETOPT:
727 *mp = m = m_get(M_WAIT, MT_SOOPTS);
728 m->m_len = sizeof(int);
729 MCLAIM(m, so->so_mowner);
730
731 switch (optname) {
732 #ifdef TCP_SIGNATURE
733 case TCP_MD5SIG:
734 *mtod(m, int *) = (tp->t_flags & TF_SIGNATURE) ? 1 : 0;
735 break;
736 #endif
737 case TCP_NODELAY:
738 *mtod(m, int *) = tp->t_flags & TF_NODELAY;
739 break;
740 case TCP_MAXSEG:
741 *mtod(m, int *) = tp->t_peermss;
742 break;
743 default:
744 error = ENOPROTOOPT;
745 break;
746 }
747 break;
748 }
749 splx(s);
750 return (error);
751 }
752
753 #ifndef TCP_SENDSPACE
754 #define TCP_SENDSPACE 1024*32
755 #endif
756 int tcp_sendspace = TCP_SENDSPACE;
757 #ifndef TCP_RECVSPACE
758 #define TCP_RECVSPACE 1024*32
759 #endif
760 int tcp_recvspace = TCP_RECVSPACE;
761
762 /*
763 * Attach TCP protocol to socket, allocating
764 * internet protocol control block, tcp control block,
765 * bufer space, and entering LISTEN state if to accept connections.
766 */
767 int
768 tcp_attach(struct socket *so)
769 {
770 struct tcpcb *tp;
771 struct inpcb *inp;
772 #ifdef INET6
773 struct in6pcb *in6p;
774 #endif
775 int error;
776 int family; /* family of the socket */
777
778 family = so->so_proto->pr_domain->dom_family;
779
780 #ifdef MBUFTRACE
781 so->so_mowner = &tcp_mowner;
782 so->so_rcv.sb_mowner = &tcp_rx_mowner;
783 so->so_snd.sb_mowner = &tcp_tx_mowner;
784 #endif
785 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
786 error = soreserve(so, tcp_sendspace, tcp_recvspace);
787 if (error)
788 return (error);
789 }
790 switch (family) {
791 #ifdef INET
792 case PF_INET:
793 error = in_pcballoc(so, &tcbtable);
794 if (error)
795 return (error);
796 inp = sotoinpcb(so);
797 #ifdef INET6
798 in6p = NULL;
799 #endif
800 break;
801 #endif
802 #ifdef INET6
803 case PF_INET6:
804 error = in6_pcballoc(so, &tcbtable);
805 if (error)
806 return (error);
807 inp = NULL;
808 in6p = sotoin6pcb(so);
809 break;
810 #endif
811 default:
812 return EAFNOSUPPORT;
813 }
814 if (inp)
815 tp = tcp_newtcpcb(family, (void *)inp);
816 #ifdef INET6
817 else if (in6p)
818 tp = tcp_newtcpcb(family, (void *)in6p);
819 #endif
820 else
821 tp = NULL;
822
823 if (tp == 0) {
824 int nofd = so->so_state & SS_NOFDREF; /* XXX */
825
826 so->so_state &= ~SS_NOFDREF; /* don't free the socket yet */
827 #ifdef INET
828 if (inp)
829 in_pcbdetach(inp);
830 #endif
831 #ifdef INET6
832 if (in6p)
833 in6_pcbdetach(in6p);
834 #endif
835 so->so_state |= nofd;
836 return (ENOBUFS);
837 }
838 tp->t_state = TCPS_CLOSED;
839 return (0);
840 }
841
842 /*
843 * Initiate (or continue) disconnect.
844 * If embryonic state, just send reset (once).
845 * If in ``let data drain'' option and linger null, just drop.
846 * Otherwise (hard), mark socket disconnecting and drop
847 * current input data; switch states based on user close, and
848 * send segment to peer (with FIN).
849 */
850 struct tcpcb *
851 tcp_disconnect(struct tcpcb *tp)
852 {
853 struct socket *so;
854
855 if (tp->t_inpcb)
856 so = tp->t_inpcb->inp_socket;
857 #ifdef INET6
858 else if (tp->t_in6pcb)
859 so = tp->t_in6pcb->in6p_socket;
860 #endif
861 else
862 so = NULL;
863
864 if (TCPS_HAVEESTABLISHED(tp->t_state) == 0)
865 tp = tcp_close(tp);
866 else if ((so->so_options & SO_LINGER) && so->so_linger == 0)
867 tp = tcp_drop(tp, 0);
868 else {
869 soisdisconnecting(so);
870 sbflush(&so->so_rcv);
871 tp = tcp_usrclosed(tp);
872 if (tp)
873 (void) tcp_output(tp);
874 }
875 return (tp);
876 }
877
878 /*
879 * User issued close, and wish to trail through shutdown states:
880 * if never received SYN, just forget it. If got a SYN from peer,
881 * but haven't sent FIN, then go to FIN_WAIT_1 state to send peer a FIN.
882 * If already got a FIN from peer, then almost done; go to LAST_ACK
883 * state. In all other cases, have already sent FIN to peer (e.g.
884 * after PRU_SHUTDOWN), and just have to play tedious game waiting
885 * for peer to send FIN or not respond to keep-alives, etc.
886 * We can let the user exit from the close as soon as the FIN is acked.
887 */
888 struct tcpcb *
889 tcp_usrclosed(struct tcpcb *tp)
890 {
891
892 switch (tp->t_state) {
893
894 case TCPS_CLOSED:
895 case TCPS_LISTEN:
896 case TCPS_SYN_SENT:
897 tp->t_state = TCPS_CLOSED;
898 tp = tcp_close(tp);
899 break;
900
901 case TCPS_SYN_RECEIVED:
902 case TCPS_ESTABLISHED:
903 tp->t_state = TCPS_FIN_WAIT_1;
904 break;
905
906 case TCPS_CLOSE_WAIT:
907 tp->t_state = TCPS_LAST_ACK;
908 break;
909 }
910 if (tp && tp->t_state >= TCPS_FIN_WAIT_2) {
911 struct socket *so;
912 if (tp->t_inpcb)
913 so = tp->t_inpcb->inp_socket;
914 #ifdef INET6
915 else if (tp->t_in6pcb)
916 so = tp->t_in6pcb->in6p_socket;
917 #endif
918 else
919 so = NULL;
920 soisdisconnected(so);
921 /*
922 * If we are in FIN_WAIT_2, we arrived here because the
923 * application did a shutdown of the send side. Like the
924 * case of a transition from FIN_WAIT_1 to FIN_WAIT_2 after
925 * a full close, we start a timer to make sure sockets are
926 * not left in FIN_WAIT_2 forever.
927 */
928 if ((tp->t_state == TCPS_FIN_WAIT_2) && (tcp_maxidle > 0))
929 TCP_TIMER_ARM(tp, TCPT_2MSL, tcp_maxidle);
930 }
931 return (tp);
932 }
933
934 /*
935 * sysctl helper routine for net.inet.ip.mssdflt. it can't be less
936 * than 32.
937 */
938 static int
939 sysctl_net_inet_tcp_mssdflt(SYSCTLFN_ARGS)
940 {
941 int error, mssdflt;
942 struct sysctlnode node;
943
944 mssdflt = tcp_mssdflt;
945 node = *rnode;
946 node.sysctl_data = &mssdflt;
947 error = sysctl_lookup(SYSCTLFN_CALL(&node));
948 if (error || newp == NULL)
949 return (error);
950
951 if (mssdflt < 32)
952 return (EINVAL);
953 tcp_mssdflt = mssdflt;
954
955 return (0);
956 }
957
958 /*
959 * sysctl helper routine for setting port related values under
960 * net.inet.ip and net.inet6.ip6. does basic range checking and does
961 * additional checks for each type. this code has placed in
962 * tcp_input.c since INET and INET6 both use the same tcp code.
963 *
964 * this helper is not static so that both inet and inet6 can use it.
965 */
966 int
967 sysctl_net_inet_ip_ports(SYSCTLFN_ARGS)
968 {
969 int error, tmp;
970 int apmin, apmax;
971 #ifndef IPNOPRIVPORTS
972 int lpmin, lpmax;
973 #endif /* IPNOPRIVPORTS */
974 struct sysctlnode node;
975
976 if (namelen != 0)
977 return (EINVAL);
978
979 switch (name[-3]) {
980 #ifdef INET
981 case PF_INET:
982 apmin = anonportmin;
983 apmax = anonportmax;
984 #ifndef IPNOPRIVPORTS
985 lpmin = lowportmin;
986 lpmax = lowportmax;
987 #endif /* IPNOPRIVPORTS */
988 break;
989 #endif /* INET */
990 #ifdef INET6
991 case PF_INET6:
992 apmin = ip6_anonportmin;
993 apmax = ip6_anonportmax;
994 #ifndef IPNOPRIVPORTS
995 lpmin = ip6_lowportmin;
996 lpmax = ip6_lowportmax;
997 #endif /* IPNOPRIVPORTS */
998 break;
999 #endif /* INET6 */
1000 default:
1001 return (EINVAL);
1002 }
1003
1004 /*
1005 * insert temporary copy into node, perform lookup on
1006 * temporary, then restore pointer
1007 */
1008 node = *rnode;
1009 tmp = *(int*)rnode->sysctl_data;
1010 node.sysctl_data = &tmp;
1011 error = sysctl_lookup(SYSCTLFN_CALL(&node));
1012 if (error || newp == NULL)
1013 return (error);
1014
1015 /*
1016 * simple port range check
1017 */
1018 if (tmp < 0 || tmp > 65535)
1019 return (EINVAL);
1020
1021 /*
1022 * per-node range checks
1023 */
1024 switch (rnode->sysctl_num) {
1025 case IPCTL_ANONPORTMIN:
1026 if (tmp >= apmax)
1027 return (EINVAL);
1028 #ifndef IPNOPRIVPORTS
1029 if (tmp < IPPORT_RESERVED)
1030 return (EINVAL);
1031 #endif /* IPNOPRIVPORTS */
1032 break;
1033
1034 case IPCTL_ANONPORTMAX:
1035 if (apmin >= tmp)
1036 return (EINVAL);
1037 #ifndef IPNOPRIVPORTS
1038 if (tmp < IPPORT_RESERVED)
1039 return (EINVAL);
1040 #endif /* IPNOPRIVPORTS */
1041 break;
1042
1043 #ifndef IPNOPRIVPORTS
1044 case IPCTL_LOWPORTMIN:
1045 if (tmp >= lpmax ||
1046 tmp > IPPORT_RESERVEDMAX ||
1047 tmp < IPPORT_RESERVEDMIN)
1048 return (EINVAL);
1049 break;
1050
1051 case IPCTL_LOWPORTMAX:
1052 if (lpmin >= tmp ||
1053 tmp > IPPORT_RESERVEDMAX ||
1054 tmp < IPPORT_RESERVEDMIN)
1055 return (EINVAL);
1056 break;
1057 #endif /* IPNOPRIVPORTS */
1058
1059 default:
1060 return (EINVAL);
1061 }
1062
1063 *(int*)rnode->sysctl_data = tmp;
1064
1065 return (0);
1066 }
1067
1068 /*
1069 * sysctl helper routine for the net.inet.tcp.ident and
1070 * net.inet6.tcp6.ident nodes. contains backwards compat code for the
1071 * old way of looking up the ident information for ipv4 which involves
1072 * stuffing the port/addr pairs into the mib lookup.
1073 */
1074 static int
1075 sysctl_net_inet_tcp_ident(SYSCTLFN_ARGS)
1076 {
1077 #ifdef INET
1078 struct inpcb *inb;
1079 struct sockaddr_in *si4[2];
1080 #endif /* INET */
1081 #ifdef INET6
1082 struct in6pcb *in6b;
1083 struct sockaddr_in6 *si6[2];
1084 #endif /* INET6 */
1085 struct sockaddr_storage sa[2];
1086 struct socket *sockp;
1087 size_t sz;
1088 uid_t uid;
1089 int error, pf;
1090
1091 if (namelen != 4 && namelen != 0)
1092 return (EINVAL);
1093 if (name[-2] != IPPROTO_TCP)
1094 return (EINVAL);
1095 pf = name[-3];
1096
1097 /* old style lookup, ipv4 only */
1098 if (namelen == 4) {
1099 #ifdef INET
1100 struct in_addr laddr, raddr;
1101 u_int lport, rport;
1102
1103 if (pf != PF_INET)
1104 return (EPROTONOSUPPORT);
1105 raddr.s_addr = (uint32_t)name[0];
1106 rport = (u_int)name[1];
1107 laddr.s_addr = (uint32_t)name[2];
1108 lport = (u_int)name[3];
1109 inb = in_pcblookup_connect(&tcbtable, raddr, rport,
1110 laddr, lport);
1111 if (inb == NULL || (sockp = inb->inp_socket) == NULL)
1112 return (ESRCH);
1113 uid = sockp->so_uid;
1114 if (oldp) {
1115 sz = MIN(sizeof(uid), *oldlenp);
1116 error = copyout(&uid, oldp, sz);
1117 if (error)
1118 return (error);
1119 }
1120 *oldlenp = sizeof(uid);
1121 return (0);
1122 #else /* INET */
1123 return (EINVAL);
1124 #endif /* INET */
1125 }
1126
1127 if (newp == NULL || newlen != sizeof(sa))
1128 return (EINVAL);
1129 error = copyin(newp, &sa, newlen);
1130 if (error)
1131 return (error);
1132
1133 /*
1134 * requested families must match
1135 */
1136 if (pf != sa[0].ss_family || sa[0].ss_family != sa[1].ss_family)
1137 return (EINVAL);
1138
1139 switch (pf) {
1140 #ifdef INET
1141 case PF_INET:
1142 si4[0] = (struct sockaddr_in*)&sa[0];
1143 si4[1] = (struct sockaddr_in*)&sa[1];
1144 if (si4[0]->sin_len != sizeof(*si4[0]) ||
1145 si4[0]->sin_len != si4[1]->sin_len)
1146 return (EINVAL);
1147 inb = in_pcblookup_connect(&tcbtable,
1148 si4[0]->sin_addr, si4[0]->sin_port,
1149 si4[1]->sin_addr, si4[1]->sin_port);
1150 if (inb == NULL || (sockp = inb->inp_socket) == NULL)
1151 return (ESRCH);
1152 break;
1153 #endif /* INET */
1154 #ifdef INET6
1155 case PF_INET6:
1156 si6[0] = (struct sockaddr_in6*)&sa[0];
1157 si6[1] = (struct sockaddr_in6*)&sa[1];
1158 if (si6[0]->sin6_len != sizeof(*si6[0]) ||
1159 si6[0]->sin6_len != si6[1]->sin6_len)
1160 return (EINVAL);
1161 in6b = in6_pcblookup_connect(&tcbtable,
1162 &si6[0]->sin6_addr, si6[0]->sin6_port,
1163 &si6[1]->sin6_addr, si6[1]->sin6_port, 0);
1164 if (in6b == NULL || (sockp = in6b->in6p_socket) == NULL)
1165 return (ESRCH);
1166 break;
1167 #endif /* INET6 */
1168 default:
1169 return (EPROTONOSUPPORT);
1170 }
1171 *oldlenp = sizeof(uid);
1172
1173 uid = sockp->so_uid;
1174 if (oldp) {
1175 sz = MIN(sizeof(uid), *oldlenp);
1176 error = copyout(&uid, oldp, sz);
1177 if (error)
1178 return (error);
1179 }
1180 *oldlenp = sizeof(uid);
1181
1182 return (0);
1183 }
1184
1185 /*
1186 * this (second stage) setup routine is a replacement for tcp_sysctl()
1187 * (which is currently used for ipv4 and ipv6)
1188 */
1189 static void
1190 sysctl_net_inet_tcp_setup2(struct sysctllog **clog, int pf, const char *pfname,
1191 const char *tcpname)
1192 {
1193
1194 sysctl_createv(clog, 0, NULL, NULL,
1195 CTLFLAG_PERMANENT,
1196 CTLTYPE_NODE, "net", NULL,
1197 NULL, 0, NULL, 0,
1198 CTL_NET, CTL_EOL);
1199 sysctl_createv(clog, 0, NULL, NULL,
1200 CTLFLAG_PERMANENT,
1201 CTLTYPE_NODE, pfname, NULL,
1202 NULL, 0, NULL, 0,
1203 CTL_NET, pf, CTL_EOL);
1204 sysctl_createv(clog, 0, NULL, NULL,
1205 CTLFLAG_PERMANENT,
1206 CTLTYPE_NODE, tcpname,
1207 SYSCTL_DESCR("TCP related settings"),
1208 NULL, 0, NULL, 0,
1209 CTL_NET, pf, IPPROTO_TCP, CTL_EOL);
1210
1211 sysctl_createv(clog, 0, NULL, NULL,
1212 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1213 CTLTYPE_INT, "rfc1323",
1214 SYSCTL_DESCR("Enable RFC1323 TCP extensions"),
1215 NULL, 0, &tcp_do_rfc1323, 0,
1216 CTL_NET, pf, IPPROTO_TCP, TCPCTL_RFC1323, CTL_EOL);
1217 sysctl_createv(clog, 0, NULL, NULL,
1218 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1219 CTLTYPE_INT, "sendspace",
1220 SYSCTL_DESCR("Default TCP send buffer size"),
1221 NULL, 0, &tcp_sendspace, 0,
1222 CTL_NET, pf, IPPROTO_TCP, TCPCTL_SENDSPACE, CTL_EOL);
1223 sysctl_createv(clog, 0, NULL, NULL,
1224 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1225 CTLTYPE_INT, "recvspace",
1226 SYSCTL_DESCR("Default TCP receive buffer size"),
1227 NULL, 0, &tcp_recvspace, 0,
1228 CTL_NET, pf, IPPROTO_TCP, TCPCTL_RECVSPACE, CTL_EOL);
1229 sysctl_createv(clog, 0, NULL, NULL,
1230 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1231 CTLTYPE_INT, "mssdflt",
1232 SYSCTL_DESCR("Default maximum segment size"),
1233 sysctl_net_inet_tcp_mssdflt, 0, &tcp_mssdflt, 0,
1234 CTL_NET, pf, IPPROTO_TCP, TCPCTL_MSSDFLT, CTL_EOL);
1235 sysctl_createv(clog, 0, NULL, NULL,
1236 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1237 CTLTYPE_INT, "syn_cache_limit",
1238 SYSCTL_DESCR("Maximum number of entries in the TCP "
1239 "compressed state engine"),
1240 NULL, 0, &tcp_syn_cache_limit, 0,
1241 CTL_NET, pf, IPPROTO_TCP, TCPCTL_SYN_CACHE_LIMIT,
1242 CTL_EOL);
1243 sysctl_createv(clog, 0, NULL, NULL,
1244 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1245 CTLTYPE_INT, "syn_bucket_limit",
1246 SYSCTL_DESCR("Maximum number of entries per hash "
1247 "bucket in the TCP compressed state "
1248 "engine"),
1249 NULL, 0, &tcp_syn_bucket_limit, 0,
1250 CTL_NET, pf, IPPROTO_TCP, TCPCTL_SYN_BUCKET_LIMIT,
1251 CTL_EOL);
1252 #if 0 /* obsoleted */
1253 sysctl_createv(clog, 0, NULL, NULL,
1254 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1255 CTLTYPE_INT, "syn_cache_interval",
1256 SYSCTL_DESCR("TCP compressed state engine's timer interval"),
1257 NULL, 0, &tcp_syn_cache_interval, 0,
1258 CTL_NET, pf, IPPROTO_TCP, TCPCTL_SYN_CACHE_INTER,
1259 CTL_EOL);
1260 #endif
1261 sysctl_createv(clog, 0, NULL, NULL,
1262 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1263 CTLTYPE_INT, "init_win",
1264 SYSCTL_DESCR("Initial TCP congestion window"),
1265 NULL, 0, &tcp_init_win, 0,
1266 CTL_NET, pf, IPPROTO_TCP, TCPCTL_INIT_WIN, CTL_EOL);
1267 sysctl_createv(clog, 0, NULL, NULL,
1268 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1269 CTLTYPE_INT, "mss_ifmtu",
1270 SYSCTL_DESCR("Use interface MTU for calculating MSS"),
1271 NULL, 0, &tcp_mss_ifmtu, 0,
1272 CTL_NET, pf, IPPROTO_TCP, TCPCTL_MSS_IFMTU, CTL_EOL);
1273 sysctl_createv(clog, 0, NULL, NULL,
1274 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1275 CTLTYPE_INT, "sack",
1276 SYSCTL_DESCR("Enable RFC2018 Selection ACKnowledgement "
1277 "(not implemented)"),
1278 NULL, 0, &tcp_do_sack, 0,
1279 CTL_NET, pf, IPPROTO_TCP, TCPCTL_SACK, CTL_EOL);
1280 sysctl_createv(clog, 0, NULL, NULL,
1281 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1282 CTLTYPE_INT, "win_scale",
1283 SYSCTL_DESCR("Use RFC1323 window scale options"),
1284 NULL, 0, &tcp_do_win_scale, 0,
1285 CTL_NET, pf, IPPROTO_TCP, TCPCTL_WSCALE, CTL_EOL);
1286 sysctl_createv(clog, 0, NULL, NULL,
1287 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1288 CTLTYPE_INT, "timestamps",
1289 SYSCTL_DESCR("Use RFC1323 time stamp options"),
1290 NULL, 0, &tcp_do_timestamps, 0,
1291 CTL_NET, pf, IPPROTO_TCP, TCPCTL_TSTAMP, CTL_EOL);
1292 sysctl_createv(clog, 0, NULL, NULL,
1293 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1294 CTLTYPE_INT, "compat_42",
1295 SYSCTL_DESCR("Enable workarounds for 4.2BSD TCP bugs"),
1296 NULL, 0, &tcp_compat_42, 0,
1297 CTL_NET, pf, IPPROTO_TCP, TCPCTL_COMPAT_42, CTL_EOL);
1298 sysctl_createv(clog, 0, NULL, NULL,
1299 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1300 CTLTYPE_INT, "cwm",
1301 SYSCTL_DESCR("Hughes/Touch/Heidemann Congestion Window "
1302 "Monitoring"),
1303 NULL, 0, &tcp_cwm, 0,
1304 CTL_NET, pf, IPPROTO_TCP, TCPCTL_CWM, CTL_EOL);
1305 sysctl_createv(clog, 0, NULL, NULL,
1306 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1307 CTLTYPE_INT, "cwm_burstsize",
1308 SYSCTL_DESCR("Congestion Window Monitoring allowed "
1309 "burst count in packets"),
1310 NULL, 0, &tcp_cwm_burstsize, 0,
1311 CTL_NET, pf, IPPROTO_TCP, TCPCTL_CWM_BURSTSIZE,
1312 CTL_EOL);
1313 sysctl_createv(clog, 0, NULL, NULL,
1314 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1315 CTLTYPE_INT, "ack_on_push",
1316 SYSCTL_DESCR("Immediately return ACK when PSH is "
1317 "received"),
1318 NULL, 0, &tcp_ack_on_push, 0,
1319 CTL_NET, pf, IPPROTO_TCP, TCPCTL_ACK_ON_PUSH, CTL_EOL);
1320 sysctl_createv(clog, 0, NULL, NULL,
1321 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1322 CTLTYPE_INT, "keepidle",
1323 SYSCTL_DESCR("Allowed connection idle ticks before a "
1324 "keepalive probe is sent"),
1325 NULL, 0, &tcp_keepidle, 0,
1326 CTL_NET, pf, IPPROTO_TCP, TCPCTL_KEEPIDLE, CTL_EOL);
1327 sysctl_createv(clog, 0, NULL, NULL,
1328 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1329 CTLTYPE_INT, "keepintvl",
1330 SYSCTL_DESCR("Ticks before next keepalive probe is sent"),
1331 NULL, 0, &tcp_keepintvl, 0,
1332 CTL_NET, pf, IPPROTO_TCP, TCPCTL_KEEPINTVL, CTL_EOL);
1333 sysctl_createv(clog, 0, NULL, NULL,
1334 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1335 CTLTYPE_INT, "keepcnt",
1336 SYSCTL_DESCR("Number of keepalive probes to send"),
1337 NULL, 0, &tcp_keepcnt, 0,
1338 CTL_NET, pf, IPPROTO_TCP, TCPCTL_KEEPCNT, CTL_EOL);
1339 sysctl_createv(clog, 0, NULL, NULL,
1340 CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
1341 CTLTYPE_INT, "slowhz",
1342 SYSCTL_DESCR("Keepalive ticks per second"),
1343 NULL, PR_SLOWHZ, NULL, 0,
1344 CTL_NET, pf, IPPROTO_TCP, TCPCTL_SLOWHZ, CTL_EOL);
1345 sysctl_createv(clog, 0, NULL, NULL,
1346 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1347 CTLTYPE_INT, "newreno",
1348 SYSCTL_DESCR("NewReno congestion control algorithm"),
1349 NULL, 0, &tcp_do_newreno, 0,
1350 CTL_NET, pf, IPPROTO_TCP, TCPCTL_NEWRENO, CTL_EOL);
1351 sysctl_createv(clog, 0, NULL, NULL,
1352 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1353 CTLTYPE_INT, "log_refused",
1354 SYSCTL_DESCR("Log refused TCP connections"),
1355 NULL, 0, &tcp_log_refused, 0,
1356 CTL_NET, pf, IPPROTO_TCP, TCPCTL_LOG_REFUSED, CTL_EOL);
1357 #if 0 /* obsoleted */
1358 sysctl_createv(clog, 0, NULL, NULL,
1359 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1360 CTLTYPE_INT, "rstratelimit", NULL,
1361 NULL, 0, &tcp_rst_ratelim, 0,
1362 CTL_NET, pf, IPPROTO_TCP, TCPCTL_RSTRATELIMIT, CTL_EOL);
1363 #endif
1364 sysctl_createv(clog, 0, NULL, NULL,
1365 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1366 CTLTYPE_INT, "rstppslimit",
1367 SYSCTL_DESCR("Maximum number of RST packets to send "
1368 "per second"),
1369 NULL, 0, &tcp_rst_ppslim, 0,
1370 CTL_NET, pf, IPPROTO_TCP, TCPCTL_RSTPPSLIMIT, CTL_EOL);
1371 sysctl_createv(clog, 0, NULL, NULL,
1372 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1373 CTLTYPE_INT, "delack_ticks",
1374 SYSCTL_DESCR("Number of ticks to delay sending an ACK"),
1375 NULL, 0, &tcp_delack_ticks, 0,
1376 CTL_NET, pf, IPPROTO_TCP, TCPCTL_DELACK_TICKS, CTL_EOL);
1377 sysctl_createv(clog, 0, NULL, NULL,
1378 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1379 CTLTYPE_INT, "init_win_local",
1380 SYSCTL_DESCR("Initial TCP window size (in segments)"),
1381 NULL, 0, &tcp_init_win_local, 0,
1382 CTL_NET, pf, IPPROTO_TCP, TCPCTL_INIT_WIN_LOCAL,
1383 CTL_EOL);
1384 sysctl_createv(clog, 0, NULL, NULL,
1385 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1386 CTLTYPE_STRUCT, "ident",
1387 SYSCTL_DESCR("RFC1413 Identification Protocol lookups"),
1388 sysctl_net_inet_tcp_ident, 0, NULL, sizeof(uid_t),
1389 CTL_NET, pf, IPPROTO_TCP, TCPCTL_IDENT, CTL_EOL);
1390 sysctl_createv(clog, 0, NULL, NULL,
1391 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1392 CTLTYPE_INT, "do_loopback_cksum",
1393 SYSCTL_DESCR("Perform TCP checksum on loopback"),
1394 NULL, 0, &tcp_do_loopback_cksum, 0,
1395 CTL_NET, pf, IPPROTO_TCP, TCPCTL_LOOPBACKCKSUM,
1396 CTL_EOL);
1397 }
1398
1399 /*
1400 * Sysctl for tcp variables.
1401 */
1402 #ifdef INET
1403 SYSCTL_SETUP(sysctl_net_inet_tcp_setup, "sysctl net.inet.tcp subtree setup")
1404 {
1405
1406 sysctl_net_inet_tcp_setup2(clog, PF_INET, "inet", "tcp");
1407 }
1408 #endif /* INET */
1409
1410 #ifdef INET6
1411 SYSCTL_SETUP(sysctl_net_inet6_tcp6_setup, "sysctl net.inet6.tcp6 subtree setup")
1412 {
1413
1414 sysctl_net_inet_tcp_setup2(clog, PF_INET6, "inet6", "tcp6");
1415 }
1416 #endif /* INET6 */
1417
1418