Home | History | Annotate | Line # | Download | only in netinet
tcp_usrreq.c revision 1.113.4.1
      1 /*	$NetBSD: tcp_usrreq.c,v 1.113.4.1 2006/02/05 03:09:11 rpaulo 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.113.4.1 2006/02/05 03:09:11 rpaulo 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 #include <netinet/in_offload.h>
    134 
    135 #ifdef INET6
    136 #ifndef INET
    137 #include <netinet/in.h>
    138 #endif
    139 #include <netinet/ip6.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, p);
    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, p);
    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_uidinfo->ui_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_uidinfo->ui_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  * sysctl helper for the inet and inet6 pcblists.  handles tcp/udp and
   1187  * inet/inet6, as well as raw pcbs for each.  specifically not
   1188  * declared static so that raw sockets and udp/udp6 can use it as
   1189  * well.
   1190  */
   1191 int
   1192 sysctl_inpcblist(SYSCTLFN_ARGS)
   1193 {
   1194 #ifdef INET
   1195 	struct sockaddr_in *in;
   1196 	const struct inpcb *inp;
   1197 #endif
   1198 #ifdef INET6
   1199 	struct sockaddr_in6 *in6;
   1200 	const struct in6pcb *in6p;
   1201 #endif
   1202 	/*
   1203 	 * sysctl_data is const, but CIRCLEQ_FOREACH can't use a const
   1204 	 * struct inpcbtable pointer, so we have to discard const.  :-/
   1205 	 */
   1206 	struct inpcbtable *pcbtbl = __UNCONST(rnode->sysctl_data);
   1207 	const struct inpcb_hdr *inph;
   1208 	struct tcpcb *tp;
   1209 	struct kinfo_pcb pcb;
   1210 	char *dp;
   1211 	u_int op, arg;
   1212 	size_t len, needed, elem_size, out_size;
   1213 	int error, elem_count, pf, proto, pf2;
   1214 
   1215 	if (namelen != 4)
   1216 		return (EINVAL);
   1217 
   1218 	error = 0;
   1219 	dp = oldp;
   1220 	len = (oldp != NULL) ? *oldlenp : 0;
   1221 	op = name[0];
   1222 	arg = name[1];
   1223 	elem_size = name[2];
   1224 	elem_count = name[3];
   1225 	out_size = MIN(sizeof(pcb), elem_size);
   1226 	needed = 0;
   1227 
   1228 	elem_count = INT_MAX;
   1229 	elem_size = out_size = sizeof(pcb);
   1230 
   1231 	if (namelen == 1 && name[0] == CTL_QUERY)
   1232 		return (sysctl_query(SYSCTLFN_CALL(rnode)));
   1233 
   1234 	if (name - oname != 4)
   1235 		return (EINVAL);
   1236 
   1237 	pf = oname[1];
   1238 	proto = oname[2];
   1239 	pf2 = (oldp == NULL) ? 0 : pf;
   1240 
   1241 	CIRCLEQ_FOREACH(inph, &pcbtbl->inpt_queue, inph_queue) {
   1242 #ifdef INET
   1243 		inp = (const struct inpcb *)inph;
   1244 #endif
   1245 #ifdef INET6
   1246 		in6p = (const struct in6pcb *)inph;
   1247 #endif
   1248 
   1249 		if (inph->inph_af != pf)
   1250 			continue;
   1251 
   1252 		if (CURTAIN(l->l_proc->p_ucred->cr_uid,
   1253 			    inph->inph_socket->so_uidinfo->ui_uid))
   1254 			continue;
   1255 
   1256 		memset(&pcb, 0, sizeof(pcb));
   1257 
   1258 		pcb.ki_family = pf;
   1259 		pcb.ki_type = proto;
   1260 
   1261 		switch (pf2) {
   1262 		case 0:
   1263 			/* just probing for size */
   1264 			break;
   1265 #ifdef INET
   1266 		case PF_INET:
   1267 			pcb.ki_family = inp->inp_socket->so_proto->
   1268 			    pr_domain->dom_family;
   1269 			pcb.ki_type = inp->inp_socket->so_proto->
   1270 			    pr_type;
   1271 			pcb.ki_protocol = inp->inp_socket->so_proto->
   1272 			    pr_protocol;
   1273 			pcb.ki_pflags = inp->inp_flags;
   1274 
   1275 			pcb.ki_sostate = inp->inp_socket->so_state;
   1276 			pcb.ki_prstate = inp->inp_state;
   1277 			if (proto == IPPROTO_TCP) {
   1278 				tp = intotcpcb(inp);
   1279 				pcb.ki_tstate = tp->t_state;
   1280 				pcb.ki_tflags = tp->t_flags;
   1281 			}
   1282 
   1283 			pcb.ki_pcbaddr = PTRTOUINT64(inp);
   1284 			pcb.ki_ppcbaddr = PTRTOUINT64(inp->inp_ppcb);
   1285 			pcb.ki_sockaddr = PTRTOUINT64(inp->inp_socket);
   1286 
   1287 			pcb.ki_rcvq = inp->inp_socket->so_rcv.sb_cc;
   1288 			pcb.ki_sndq = inp->inp_socket->so_snd.sb_cc;
   1289 
   1290 			in = satosin(&pcb.ki_src);
   1291 			in->sin_len = sizeof(*in);
   1292 			in->sin_family = pf;
   1293 			in->sin_port = inp->inp_lport;
   1294 			in->sin_addr = inp->inp_laddr;
   1295 			if (pcb.ki_prstate >= INP_CONNECTED) {
   1296 				in = satosin(&pcb.ki_dst);
   1297 				in->sin_len = sizeof(*in);
   1298 				in->sin_family = pf;
   1299 				in->sin_port = inp->inp_fport;
   1300 				in->sin_addr = inp->inp_faddr;
   1301 			}
   1302 			break;
   1303 #endif
   1304 #ifdef INET6
   1305 		case PF_INET6:
   1306 			pcb.ki_family = in6p->in6p_socket->so_proto->
   1307 			    pr_domain->dom_family;
   1308 			pcb.ki_type = in6p->in6p_socket->so_proto->pr_type;
   1309 			pcb.ki_protocol = in6p->in6p_socket->so_proto->
   1310 			    pr_protocol;
   1311 			pcb.ki_pflags = in6p->in6p_flags;
   1312 
   1313 			pcb.ki_sostate = in6p->in6p_socket->so_state;
   1314 			pcb.ki_prstate = in6p->in6p_state;
   1315 			if (proto == IPPROTO_TCP) {
   1316 				tp = in6totcpcb(in6p);
   1317 				pcb.ki_tstate = tp->t_state;
   1318 				pcb.ki_tflags = tp->t_flags;
   1319 			}
   1320 
   1321 			pcb.ki_pcbaddr = PTRTOUINT64(in6p);
   1322 			pcb.ki_ppcbaddr = PTRTOUINT64(in6p->in6p_ppcb);
   1323 			pcb.ki_sockaddr = PTRTOUINT64(in6p->in6p_socket);
   1324 
   1325 			pcb.ki_rcvq = in6p->in6p_socket->so_rcv.sb_cc;
   1326 			pcb.ki_sndq = in6p->in6p_socket->so_snd.sb_cc;
   1327 
   1328 			in6 = satosin6(&pcb.ki_src);
   1329 			in6->sin6_len = sizeof(*in6);
   1330 			in6->sin6_family = pf;
   1331 			in6->sin6_port = in6p->in6p_lport;
   1332 			in6->sin6_flowinfo = in6p->in6p_flowinfo;
   1333 			in6->sin6_addr = in6p->in6p_laddr;
   1334 			in6->sin6_scope_id = 0; /* XXX? */
   1335 
   1336 			if (pcb.ki_prstate >= IN6P_CONNECTED) {
   1337 				in6 = satosin6(&pcb.ki_dst);
   1338 				in6->sin6_len = sizeof(*in6);
   1339 				in6->sin6_family = pf;
   1340 				in6->sin6_port = in6p->in6p_fport;
   1341 				in6->sin6_flowinfo = in6p->in6p_flowinfo;
   1342 				in6->sin6_addr = in6p->in6p_faddr;
   1343 				in6->sin6_scope_id = 0; /* XXX? */
   1344 			}
   1345 			break;
   1346 #endif
   1347 		}
   1348 
   1349 		if (len >= elem_size && elem_count > 0) {
   1350 			error = copyout(&pcb, dp, out_size);
   1351 			if (error)
   1352 				return (error);
   1353 			dp += elem_size;
   1354 			len -= elem_size;
   1355 		}
   1356 		if (elem_count > 0) {
   1357 			needed += elem_size;
   1358 			if (elem_count != INT_MAX)
   1359 				elem_count--;
   1360 		}
   1361 	}
   1362 
   1363 	*oldlenp = needed;
   1364 	if (oldp == NULL)
   1365 		*oldlenp += PCB_SLOP * sizeof(struct kinfo_pcb);
   1366 
   1367 	return (error);
   1368 }
   1369 
   1370 /*
   1371  * this (second stage) setup routine is a replacement for tcp_sysctl()
   1372  * (which is currently used for ipv4 and ipv6)
   1373  */
   1374 static void
   1375 sysctl_net_inet_tcp_setup2(struct sysctllog **clog, int pf, const char *pfname,
   1376 			   const char *tcpname)
   1377 {
   1378 	const struct sysctlnode *sack_node;
   1379 #ifdef TCP_DEBUG
   1380 	extern struct tcp_debug tcp_debug[TCP_NDEBUG];
   1381 	extern int tcp_debx;
   1382 #endif
   1383 
   1384 	sysctl_createv(clog, 0, NULL, NULL,
   1385 		       CTLFLAG_PERMANENT,
   1386 		       CTLTYPE_NODE, "net", NULL,
   1387 		       NULL, 0, NULL, 0,
   1388 		       CTL_NET, CTL_EOL);
   1389 	sysctl_createv(clog, 0, NULL, NULL,
   1390 		       CTLFLAG_PERMANENT,
   1391 		       CTLTYPE_NODE, pfname, NULL,
   1392 		       NULL, 0, NULL, 0,
   1393 		       CTL_NET, pf, CTL_EOL);
   1394 	sysctl_createv(clog, 0, NULL, NULL,
   1395 		       CTLFLAG_PERMANENT,
   1396 		       CTLTYPE_NODE, tcpname,
   1397 		       SYSCTL_DESCR("TCP related settings"),
   1398 		       NULL, 0, NULL, 0,
   1399 		       CTL_NET, pf, IPPROTO_TCP, CTL_EOL);
   1400 
   1401 	sysctl_createv(clog, 0, NULL, NULL,
   1402 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1403 		       CTLTYPE_INT, "rfc1323",
   1404 		       SYSCTL_DESCR("Enable RFC1323 TCP extensions"),
   1405 		       NULL, 0, &tcp_do_rfc1323, 0,
   1406 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_RFC1323, CTL_EOL);
   1407 	sysctl_createv(clog, 0, NULL, NULL,
   1408 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1409 		       CTLTYPE_INT, "sendspace",
   1410 		       SYSCTL_DESCR("Default TCP send buffer size"),
   1411 		       NULL, 0, &tcp_sendspace, 0,
   1412 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_SENDSPACE, CTL_EOL);
   1413 	sysctl_createv(clog, 0, NULL, NULL,
   1414 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1415 		       CTLTYPE_INT, "recvspace",
   1416 		       SYSCTL_DESCR("Default TCP receive buffer size"),
   1417 		       NULL, 0, &tcp_recvspace, 0,
   1418 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_RECVSPACE, CTL_EOL);
   1419 	sysctl_createv(clog, 0, NULL, NULL,
   1420 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1421 		       CTLTYPE_INT, "mssdflt",
   1422 		       SYSCTL_DESCR("Default maximum segment size"),
   1423 		       sysctl_net_inet_tcp_mssdflt, 0, &tcp_mssdflt, 0,
   1424 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_MSSDFLT, CTL_EOL);
   1425 	sysctl_createv(clog, 0, NULL, NULL,
   1426 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1427 		       CTLTYPE_INT, "syn_cache_limit",
   1428 		       SYSCTL_DESCR("Maximum number of entries in the TCP "
   1429 				    "compressed state engine"),
   1430 		       NULL, 0, &tcp_syn_cache_limit, 0,
   1431 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_SYN_CACHE_LIMIT,
   1432 		       CTL_EOL);
   1433 	sysctl_createv(clog, 0, NULL, NULL,
   1434 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1435 		       CTLTYPE_INT, "syn_bucket_limit",
   1436 		       SYSCTL_DESCR("Maximum number of entries per hash "
   1437 				    "bucket in the TCP compressed state "
   1438 				    "engine"),
   1439 		       NULL, 0, &tcp_syn_bucket_limit, 0,
   1440 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_SYN_BUCKET_LIMIT,
   1441 		       CTL_EOL);
   1442 #if 0 /* obsoleted */
   1443 	sysctl_createv(clog, 0, NULL, NULL,
   1444 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1445 		       CTLTYPE_INT, "syn_cache_interval",
   1446 		       SYSCTL_DESCR("TCP compressed state engine's timer interval"),
   1447 		       NULL, 0, &tcp_syn_cache_interval, 0,
   1448 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_SYN_CACHE_INTER,
   1449 		       CTL_EOL);
   1450 #endif
   1451 	sysctl_createv(clog, 0, NULL, NULL,
   1452 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1453 		       CTLTYPE_INT, "init_win",
   1454 		       SYSCTL_DESCR("Initial TCP congestion window"),
   1455 		       NULL, 0, &tcp_init_win, 0,
   1456 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_INIT_WIN, CTL_EOL);
   1457 	sysctl_createv(clog, 0, NULL, NULL,
   1458 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1459 		       CTLTYPE_INT, "mss_ifmtu",
   1460 		       SYSCTL_DESCR("Use interface MTU for calculating MSS"),
   1461 		       NULL, 0, &tcp_mss_ifmtu, 0,
   1462 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_MSS_IFMTU, CTL_EOL);
   1463 	sysctl_createv(clog, 0, NULL, &sack_node,
   1464 		       CTLFLAG_PERMANENT,
   1465 		       CTLTYPE_NODE, "sack",
   1466 		       SYSCTL_DESCR("RFC2018 Selective ACKnowledgement tunables"),
   1467 		       NULL, 0, NULL, 0,
   1468 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_SACK, CTL_EOL);
   1469 	sysctl_createv(clog, 0, NULL, NULL,
   1470 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1471 		       CTLTYPE_INT, "win_scale",
   1472 		       SYSCTL_DESCR("Use RFC1323 window scale options"),
   1473 		       NULL, 0, &tcp_do_win_scale, 0,
   1474 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_WSCALE, CTL_EOL);
   1475 	sysctl_createv(clog, 0, NULL, NULL,
   1476 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1477 		       CTLTYPE_INT, "timestamps",
   1478 		       SYSCTL_DESCR("Use RFC1323 time stamp options"),
   1479 		       NULL, 0, &tcp_do_timestamps, 0,
   1480 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_TSTAMP, CTL_EOL);
   1481 	sysctl_createv(clog, 0, NULL, NULL,
   1482 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1483 		       CTLTYPE_INT, "compat_42",
   1484 		       SYSCTL_DESCR("Enable workarounds for 4.2BSD TCP bugs"),
   1485 		       NULL, 0, &tcp_compat_42, 0,
   1486 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_COMPAT_42, CTL_EOL);
   1487 	sysctl_createv(clog, 0, NULL, NULL,
   1488 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1489 		       CTLTYPE_INT, "cwm",
   1490 		       SYSCTL_DESCR("Hughes/Touch/Heidemann Congestion Window "
   1491 				    "Monitoring"),
   1492 		       NULL, 0, &tcp_cwm, 0,
   1493 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_CWM, CTL_EOL);
   1494 	sysctl_createv(clog, 0, NULL, NULL,
   1495 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1496 		       CTLTYPE_INT, "cwm_burstsize",
   1497 		       SYSCTL_DESCR("Congestion Window Monitoring allowed "
   1498 				    "burst count in packets"),
   1499 		       NULL, 0, &tcp_cwm_burstsize, 0,
   1500 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_CWM_BURSTSIZE,
   1501 		       CTL_EOL);
   1502 	sysctl_createv(clog, 0, NULL, NULL,
   1503 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1504 		       CTLTYPE_INT, "ack_on_push",
   1505 		       SYSCTL_DESCR("Immediately return ACK when PSH is "
   1506 				    "received"),
   1507 		       NULL, 0, &tcp_ack_on_push, 0,
   1508 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_ACK_ON_PUSH, CTL_EOL);
   1509 	sysctl_createv(clog, 0, NULL, NULL,
   1510 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1511 		       CTLTYPE_INT, "keepidle",
   1512 		       SYSCTL_DESCR("Allowed connection idle ticks before a "
   1513 				    "keepalive probe is sent"),
   1514 		       NULL, 0, &tcp_keepidle, 0,
   1515 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_KEEPIDLE, CTL_EOL);
   1516 	sysctl_createv(clog, 0, NULL, NULL,
   1517 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1518 		       CTLTYPE_INT, "keepintvl",
   1519 		       SYSCTL_DESCR("Ticks before next keepalive probe is sent"),
   1520 		       NULL, 0, &tcp_keepintvl, 0,
   1521 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_KEEPINTVL, CTL_EOL);
   1522 	sysctl_createv(clog, 0, NULL, NULL,
   1523 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1524 		       CTLTYPE_INT, "keepcnt",
   1525 		       SYSCTL_DESCR("Number of keepalive probes to send"),
   1526 		       NULL, 0, &tcp_keepcnt, 0,
   1527 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_KEEPCNT, CTL_EOL);
   1528 	sysctl_createv(clog, 0, NULL, NULL,
   1529 		       CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
   1530 		       CTLTYPE_INT, "slowhz",
   1531 		       SYSCTL_DESCR("Keepalive ticks per second"),
   1532 		       NULL, PR_SLOWHZ, NULL, 0,
   1533 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_SLOWHZ, CTL_EOL);
   1534 	sysctl_createv(clog, 0, NULL, NULL,
   1535 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1536 		       CTLTYPE_INT, "newreno",
   1537 		       SYSCTL_DESCR("NewReno congestion control algorithm"),
   1538 		       NULL, 0, &tcp_do_newreno, 0,
   1539 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_NEWRENO, CTL_EOL);
   1540 	sysctl_createv(clog, 0, NULL, NULL,
   1541 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1542 		       CTLTYPE_INT, "log_refused",
   1543 		       SYSCTL_DESCR("Log refused TCP connections"),
   1544 		       NULL, 0, &tcp_log_refused, 0,
   1545 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_LOG_REFUSED, CTL_EOL);
   1546 #if 0 /* obsoleted */
   1547 	sysctl_createv(clog, 0, NULL, NULL,
   1548 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1549 		       CTLTYPE_INT, "rstratelimit", NULL,
   1550 		       NULL, 0, &tcp_rst_ratelim, 0,
   1551 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_RSTRATELIMIT, CTL_EOL);
   1552 #endif
   1553 	sysctl_createv(clog, 0, NULL, NULL,
   1554 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1555 		       CTLTYPE_INT, "rstppslimit",
   1556 		       SYSCTL_DESCR("Maximum number of RST packets to send "
   1557 				    "per second"),
   1558 		       NULL, 0, &tcp_rst_ppslim, 0,
   1559 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_RSTPPSLIMIT, CTL_EOL);
   1560 	sysctl_createv(clog, 0, NULL, NULL,
   1561 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1562 		       CTLTYPE_INT, "delack_ticks",
   1563 		       SYSCTL_DESCR("Number of ticks to delay sending an ACK"),
   1564 		       NULL, 0, &tcp_delack_ticks, 0,
   1565 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_DELACK_TICKS, CTL_EOL);
   1566 	sysctl_createv(clog, 0, NULL, NULL,
   1567 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1568 		       CTLTYPE_INT, "init_win_local",
   1569 		       SYSCTL_DESCR("Initial TCP window size (in segments)"),
   1570 		       NULL, 0, &tcp_init_win_local, 0,
   1571 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_INIT_WIN_LOCAL,
   1572 		       CTL_EOL);
   1573 	sysctl_createv(clog, 0, NULL, NULL,
   1574 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1575 		       CTLTYPE_STRUCT, "ident",
   1576 		       SYSCTL_DESCR("RFC1413 Identification Protocol lookups"),
   1577 		       sysctl_net_inet_tcp_ident, 0, NULL, sizeof(uid_t),
   1578 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_IDENT, CTL_EOL);
   1579 	sysctl_createv(clog, 0, NULL, NULL,
   1580 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1581 		       CTLTYPE_INT, "do_loopback_cksum",
   1582 		       SYSCTL_DESCR("Perform TCP checksum on loopback"),
   1583 		       NULL, 0, &tcp_do_loopback_cksum, 0,
   1584 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_LOOPBACKCKSUM,
   1585 		       CTL_EOL);
   1586 	sysctl_createv(clog, 0, NULL, NULL,
   1587 		       CTLFLAG_PERMANENT,
   1588 		       CTLTYPE_STRUCT, "pcblist",
   1589 		       SYSCTL_DESCR("TCP protocol control block list"),
   1590 		       sysctl_inpcblist, 0, &tcbtable, 0,
   1591 		       CTL_NET, pf, IPPROTO_TCP, CTL_CREATE,
   1592 		       CTL_EOL);
   1593 
   1594 	/* SACK gets it's own little subtree. */
   1595 	sysctl_createv(clog, 0, NULL, &sack_node,
   1596 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1597 		       CTLTYPE_INT, "enable",
   1598 		       SYSCTL_DESCR("Enable RFC2018 Selective ACKnowledgement"),
   1599 		       NULL, 0, &tcp_do_sack, 0,
   1600 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_SACK, CTL_CREATE, CTL_EOL);
   1601 	sysctl_createv(clog, 0, NULL, &sack_node,
   1602 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1603 		       CTLTYPE_INT, "maxholes",
   1604 		       SYSCTL_DESCR("Maximum number of TCP SACK holes allowed per connection"),
   1605 		       NULL, 0, &tcp_sack_tp_maxholes, 0,
   1606 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_SACK, CTL_CREATE, CTL_EOL);
   1607 	sysctl_createv(clog, 0, NULL, &sack_node,
   1608 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1609 		       CTLTYPE_INT, "globalmaxholes",
   1610 		       SYSCTL_DESCR("Global maximum number of TCP SACK holes"),
   1611 		       NULL, 0, &tcp_sack_globalmaxholes, 0,
   1612 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_SACK, CTL_CREATE, CTL_EOL);
   1613 	sysctl_createv(clog, 0, NULL, &sack_node,
   1614 		       CTLFLAG_PERMANENT,
   1615 		       CTLTYPE_INT, "globalholes",
   1616 		       SYSCTL_DESCR("Global number of TCP SACK holes"),
   1617 		       NULL, 0, &tcp_sack_globalholes, 0,
   1618 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_SACK, CTL_CREATE, CTL_EOL);
   1619 
   1620 	sysctl_createv(clog, 0, NULL, NULL,
   1621 		       CTLFLAG_PERMANENT,
   1622 		       CTLTYPE_STRUCT, "stats",
   1623 		       SYSCTL_DESCR("TCP statistics"),
   1624 		       NULL, 0, &tcpstat, sizeof(tcpstat),
   1625 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_STATS,
   1626 		       CTL_EOL);
   1627 #ifdef TCP_DEBUG
   1628 	sysctl_createv(clog, 0, NULL, NULL,
   1629 		       CTLFLAG_PERMANENT,
   1630 		       CTLTYPE_STRUCT, "debug",
   1631 		       SYSCTL_DESCR("TCP sockets debug information"),
   1632 		       NULL, 0, &tcp_debug, sizeof(tcp_debug),
   1633 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_DEBUG,
   1634 		       CTL_EOL);
   1635 	sysctl_createv(clog, 0, NULL, NULL,
   1636 		       CTLFLAG_PERMANENT,
   1637 		       CTLTYPE_INT, "debx",
   1638 		       SYSCTL_DESCR("Number of TCP debug sockets messages"),
   1639 		       NULL, 0, &tcp_debx, sizeof(tcp_debx),
   1640 		       CTL_NET, pf, IPPROTO_TCP, TCPCTL_DEBX,
   1641 		       CTL_EOL);
   1642 #endif
   1643 
   1644 }
   1645 
   1646 /*
   1647  * Sysctl for tcp variables.
   1648  */
   1649 #ifdef INET
   1650 SYSCTL_SETUP(sysctl_net_inet_tcp_setup, "sysctl net.inet.tcp subtree setup")
   1651 {
   1652 
   1653 	sysctl_net_inet_tcp_setup2(clog, PF_INET, "inet", "tcp");
   1654 }
   1655 #endif /* INET */
   1656 
   1657 #ifdef INET6
   1658 SYSCTL_SETUP(sysctl_net_inet6_tcp6_setup, "sysctl net.inet6.tcp6 subtree setup")
   1659 {
   1660 
   1661 	sysctl_net_inet_tcp_setup2(clog, PF_INET6, "inet6", "tcp6");
   1662 }
   1663 #endif /* INET6 */
   1664