xref: /netbsd-src/sys/netinet/tcp_syncache.h (revision 9815eb9b9c3e45d11fa8ab21893139cd9fe6a226)
1*9815eb9bSozaki-r /*	$NetBSD: tcp_syncache.h,v 1.2 2022/09/20 10:12:18 ozaki-r Exp $	*/
23761620bSozaki-r 
33761620bSozaki-r /*
43761620bSozaki-r  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
53761620bSozaki-r  * All rights reserved.
63761620bSozaki-r  *
73761620bSozaki-r  * Redistribution and use in source and binary forms, with or without
83761620bSozaki-r  * modification, are permitted provided that the following conditions
93761620bSozaki-r  * are met:
103761620bSozaki-r  * 1. Redistributions of source code must retain the above copyright
113761620bSozaki-r  *    notice, this list of conditions and the following disclaimer.
123761620bSozaki-r  * 2. Redistributions in binary form must reproduce the above copyright
133761620bSozaki-r  *    notice, this list of conditions and the following disclaimer in the
143761620bSozaki-r  *    documentation and/or other materials provided with the distribution.
153761620bSozaki-r  * 3. Neither the name of the project nor the names of its contributors
163761620bSozaki-r  *    may be used to endorse or promote products derived from this software
173761620bSozaki-r  *    without specific prior written permission.
183761620bSozaki-r  *
193761620bSozaki-r  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
203761620bSozaki-r  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
213761620bSozaki-r  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
223761620bSozaki-r  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
233761620bSozaki-r  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
243761620bSozaki-r  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
253761620bSozaki-r  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
263761620bSozaki-r  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
273761620bSozaki-r  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
283761620bSozaki-r  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
293761620bSozaki-r  * SUCH DAMAGE.
303761620bSozaki-r  */
313761620bSozaki-r 
323761620bSozaki-r /*
333761620bSozaki-r  *      @(#)COPYRIGHT   1.1 (NRL) 17 January 1995
343761620bSozaki-r  *
353761620bSozaki-r  * NRL grants permission for redistribution and use in source and binary
363761620bSozaki-r  * forms, with or without modification, of the software and documentation
373761620bSozaki-r  * created at NRL provided that the following conditions are met:
383761620bSozaki-r  *
393761620bSozaki-r  * 1. Redistributions of source code must retain the above copyright
403761620bSozaki-r  *    notice, this list of conditions and the following disclaimer.
413761620bSozaki-r  * 2. Redistributions in binary form must reproduce the above copyright
423761620bSozaki-r  *    notice, this list of conditions and the following disclaimer in the
433761620bSozaki-r  *    documentation and/or other materials provided with the distribution.
443761620bSozaki-r  * 3. All advertising materials mentioning features or use of this software
453761620bSozaki-r  *    must display the following acknowledgements:
463761620bSozaki-r  *      This product includes software developed by the University of
473761620bSozaki-r  *      California, Berkeley and its contributors.
483761620bSozaki-r  *      This product includes software developed at the Information
493761620bSozaki-r  *      Technology Division, US Naval Research Laboratory.
503761620bSozaki-r  * 4. Neither the name of the NRL nor the names of its contributors
513761620bSozaki-r  *    may be used to endorse or promote products derived from this software
523761620bSozaki-r  *    without specific prior written permission.
533761620bSozaki-r  *
543761620bSozaki-r  * THE SOFTWARE PROVIDED BY NRL IS PROVIDED BY NRL AND CONTRIBUTORS ``AS
553761620bSozaki-r  * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
563761620bSozaki-r  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
573761620bSozaki-r  * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL NRL OR
583761620bSozaki-r  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
593761620bSozaki-r  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
603761620bSozaki-r  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
613761620bSozaki-r  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
623761620bSozaki-r  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
633761620bSozaki-r  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
643761620bSozaki-r  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
653761620bSozaki-r  *
663761620bSozaki-r  * The views and conclusions contained in the software and documentation
673761620bSozaki-r  * are those of the authors and should not be interpreted as representing
683761620bSozaki-r  * official policies, either expressed or implied, of the US Naval
693761620bSozaki-r  * Research Laboratory (NRL).
703761620bSozaki-r  */
713761620bSozaki-r 
723761620bSozaki-r /*-
733761620bSozaki-r  * Copyright (c) 1997, 1998, 1999, 2001, 2005 The NetBSD Foundation, Inc.
743761620bSozaki-r  * All rights reserved.
753761620bSozaki-r  *
763761620bSozaki-r  * This code is derived from software contributed to The NetBSD Foundation
773761620bSozaki-r  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
783761620bSozaki-r  * NASA Ames Research Center.
793761620bSozaki-r  * This code is derived from software contributed to The NetBSD Foundation
803761620bSozaki-r  * by Charles M. Hannum.
813761620bSozaki-r  *
823761620bSozaki-r  * Redistribution and use in source and binary forms, with or without
833761620bSozaki-r  * modification, are permitted provided that the following conditions
843761620bSozaki-r  * are met:
853761620bSozaki-r  * 1. Redistributions of source code must retain the above copyright
863761620bSozaki-r  *    notice, this list of conditions and the following disclaimer.
873761620bSozaki-r  * 2. Redistributions in binary form must reproduce the above copyright
883761620bSozaki-r  *    notice, this list of conditions and the following disclaimer in the
893761620bSozaki-r  *    documentation and/or other materials provided with the distribution.
903761620bSozaki-r  *
913761620bSozaki-r  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
923761620bSozaki-r  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
933761620bSozaki-r  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
943761620bSozaki-r  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
953761620bSozaki-r  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
963761620bSozaki-r  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
973761620bSozaki-r  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
983761620bSozaki-r  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
993761620bSozaki-r  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1003761620bSozaki-r  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1013761620bSozaki-r  * POSSIBILITY OF SUCH DAMAGE.
1023761620bSozaki-r  */
1033761620bSozaki-r 
1043761620bSozaki-r /*
1053761620bSozaki-r  * Copyright (c) 1982, 1986, 1993, 1994, 1995
1063761620bSozaki-r  *	The Regents of the University of California.  All rights reserved.
1073761620bSozaki-r  *
1083761620bSozaki-r  * Redistribution and use in source and binary forms, with or without
1093761620bSozaki-r  * modification, are permitted provided that the following conditions
1103761620bSozaki-r  * are met:
1113761620bSozaki-r  * 1. Redistributions of source code must retain the above copyright
1123761620bSozaki-r  *    notice, this list of conditions and the following disclaimer.
1133761620bSozaki-r  * 2. Redistributions in binary form must reproduce the above copyright
1143761620bSozaki-r  *    notice, this list of conditions and the following disclaimer in the
1153761620bSozaki-r  *    documentation and/or other materials provided with the distribution.
1163761620bSozaki-r  * 3. Neither the name of the University nor the names of its contributors
1173761620bSozaki-r  *    may be used to endorse or promote products derived from this software
1183761620bSozaki-r  *    without specific prior written permission.
1193761620bSozaki-r  *
1203761620bSozaki-r  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1213761620bSozaki-r  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1223761620bSozaki-r  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1233761620bSozaki-r  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1243761620bSozaki-r  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1253761620bSozaki-r  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1263761620bSozaki-r  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1273761620bSozaki-r  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1283761620bSozaki-r  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1293761620bSozaki-r  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1303761620bSozaki-r  * SUCH DAMAGE.
1313761620bSozaki-r  *
1323761620bSozaki-r  *	@(#)tcp_var.h	8.4 (Berkeley) 5/24/95
1333761620bSozaki-r  */
1343761620bSozaki-r 
1353761620bSozaki-r #ifndef _NETINET_TCP_SYNCACHE_H_
1363761620bSozaki-r #define _NETINET_TCP_SYNCACHE_H_
1373761620bSozaki-r 
1383761620bSozaki-r #if defined(_KERNEL_OPT)
1393761620bSozaki-r #include "opt_inet.h"
1403761620bSozaki-r #include "opt_mbuftrace.h"
1413761620bSozaki-r #endif
1423761620bSozaki-r 
1433761620bSozaki-r #ifdef _KERNEL
1443761620bSozaki-r #include <sys/callout.h>
1453761620bSozaki-r #include <sys/mbuf.h>
1463761620bSozaki-r #include <sys/queue.h>
1473761620bSozaki-r 
1483761620bSozaki-r #include <net/route.h>
1493761620bSozaki-r 
1503761620bSozaki-r /*
1513761620bSozaki-r  * Data for the TCP compressed state engine.
1523761620bSozaki-r  */
1533761620bSozaki-r union syn_cache_sa {
1543761620bSozaki-r 	struct sockaddr sa;
1553761620bSozaki-r 	struct sockaddr_in sin;
1563761620bSozaki-r #if 1 /*def INET6*/
1573761620bSozaki-r 	struct sockaddr_in6 sin6;
1583761620bSozaki-r #endif
1593761620bSozaki-r };
1603761620bSozaki-r 
1613761620bSozaki-r struct syn_cache {
1623761620bSozaki-r 	TAILQ_ENTRY(syn_cache) sc_bucketq;	/* link on bucket list */
1633761620bSozaki-r 	callout_t sc_timer;			/* rexmt timer */
1643761620bSozaki-r 	struct route sc_route;
1653761620bSozaki-r 	long sc_win;				/* advertised window */
1663761620bSozaki-r 	int sc_bucketidx;			/* our bucket index */
1673761620bSozaki-r 	u_int32_t sc_hash;
1683761620bSozaki-r 	u_int32_t sc_timestamp;			/* timestamp from SYN */
1693761620bSozaki-r 	u_int32_t sc_timebase;			/* our local timebase */
1703761620bSozaki-r 	union syn_cache_sa sc_src;
1713761620bSozaki-r 	union syn_cache_sa sc_dst;
1723761620bSozaki-r 	tcp_seq sc_irs;
1733761620bSozaki-r 	tcp_seq sc_iss;
1743761620bSozaki-r 	u_int sc_rxtcur;			/* current rxt timeout */
1753761620bSozaki-r 	u_int sc_rxttot;			/* total time spend on queues */
1763761620bSozaki-r 	u_short sc_rxtshift;			/* for computing backoff */
1773761620bSozaki-r 	u_short sc_flags;
1783761620bSozaki-r 
1793761620bSozaki-r #define	SCF_UNREACH		0x0001		/* we've had an unreach error */
1803761620bSozaki-r #define	SCF_TIMESTAMP		0x0002		/* peer will do timestamps */
1813761620bSozaki-r #define	SCF_DEAD		0x0004		/* this entry to be released */
1823761620bSozaki-r #define SCF_SACK_PERMIT		0x0008		/* peer will do SACK */
1833761620bSozaki-r #define SCF_ECN_PERMIT		0x0010		/* peer will do ECN */
1843761620bSozaki-r #define SCF_SIGNATURE	0x40			/* send MD5 digests */
1853761620bSozaki-r 
1863761620bSozaki-r 	struct mbuf *sc_ipopts;			/* IP options */
1873761620bSozaki-r 	u_int16_t sc_peermaxseg;
1883761620bSozaki-r 	u_int16_t sc_ourmaxseg;
1893761620bSozaki-r 	u_int8_t sc_request_r_scale	: 4,
1903761620bSozaki-r 		 sc_requested_s_scale	: 4;
1913761620bSozaki-r 
1923761620bSozaki-r 	struct tcpcb *sc_tp;			/* tcb for listening socket */
1933761620bSozaki-r 	LIST_ENTRY(syn_cache) sc_tpq;		/* list of entries by same tp */
1943761620bSozaki-r };
1953761620bSozaki-r 
1963761620bSozaki-r struct syn_cache_head {
1973761620bSozaki-r 	TAILQ_HEAD(, syn_cache) sch_bucket;	/* bucket entries */
1983761620bSozaki-r 	u_short sch_length;			/* # entries in bucket */
1993761620bSozaki-r };
2003761620bSozaki-r 
2013761620bSozaki-r extern	int tcp_syn_bucket_limit;/* max entries per hash bucket */
2023761620bSozaki-r extern	int tcp_syn_cache_limit; /* max entries for compressed state engine */
2033761620bSozaki-r extern	u_long syn_cache_count;
2043761620bSozaki-r 
2053761620bSozaki-r int	 syn_cache_add(struct sockaddr *, struct sockaddr *,
2063761620bSozaki-r 		struct tcphdr *, unsigned int, struct socket *,
2073761620bSozaki-r 		struct mbuf *, u_char *, int, struct tcp_opt_info *);
2083761620bSozaki-r void	 syn_cache_unreach(const struct sockaddr *, const struct sockaddr *,
2093761620bSozaki-r 	   struct tcphdr *);
210*9815eb9bSozaki-r struct socket
211*9815eb9bSozaki-r 	*syn_cache_get(struct sockaddr *, struct sockaddr *,
2123761620bSozaki-r 		struct tcphdr *, struct socket *so, struct mbuf *);
2133761620bSozaki-r void	 syn_cache_init(void);
2143761620bSozaki-r void	 syn_cache_insert(struct syn_cache *, struct tcpcb *);
2153761620bSozaki-r void	 syn_cache_reset(struct sockaddr *, struct sockaddr *,
2163761620bSozaki-r 		struct tcphdr *);
2173761620bSozaki-r void	 syn_cache_cleanup(struct tcpcb *);
2183761620bSozaki-r #endif
2193761620bSozaki-r 
2203761620bSozaki-r #endif /* !_NETINET_TCP_SYNCACHE_H_ */
221