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