Home | History | Annotate | Line # | Download | only in netinet
      1  1.2  ozaki /*	$NetBSD: tcp_syncache.h,v 1.2 2022/09/20 10:12:18 ozaki-r Exp $	*/
      2  1.1  ozaki 
      3  1.1  ozaki /*
      4  1.1  ozaki  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
      5  1.1  ozaki  * All rights reserved.
      6  1.1  ozaki  *
      7  1.1  ozaki  * Redistribution and use in source and binary forms, with or without
      8  1.1  ozaki  * modification, are permitted provided that the following conditions
      9  1.1  ozaki  * are met:
     10  1.1  ozaki  * 1. Redistributions of source code must retain the above copyright
     11  1.1  ozaki  *    notice, this list of conditions and the following disclaimer.
     12  1.1  ozaki  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  ozaki  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  ozaki  *    documentation and/or other materials provided with the distribution.
     15  1.1  ozaki  * 3. Neither the name of the project nor the names of its contributors
     16  1.1  ozaki  *    may be used to endorse or promote products derived from this software
     17  1.1  ozaki  *    without specific prior written permission.
     18  1.1  ozaki  *
     19  1.1  ozaki  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
     20  1.1  ozaki  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  1.1  ozaki  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  1.1  ozaki  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
     23  1.1  ozaki  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  1.1  ozaki  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  1.1  ozaki  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  1.1  ozaki  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  1.1  ozaki  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  1.1  ozaki  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  1.1  ozaki  * SUCH DAMAGE.
     30  1.1  ozaki  */
     31  1.1  ozaki 
     32  1.1  ozaki /*
     33  1.1  ozaki  *      @(#)COPYRIGHT   1.1 (NRL) 17 January 1995
     34  1.1  ozaki  *
     35  1.1  ozaki  * NRL grants permission for redistribution and use in source and binary
     36  1.1  ozaki  * forms, with or without modification, of the software and documentation
     37  1.1  ozaki  * created at NRL provided that the following conditions are met:
     38  1.1  ozaki  *
     39  1.1  ozaki  * 1. Redistributions of source code must retain the above copyright
     40  1.1  ozaki  *    notice, this list of conditions and the following disclaimer.
     41  1.1  ozaki  * 2. Redistributions in binary form must reproduce the above copyright
     42  1.1  ozaki  *    notice, this list of conditions and the following disclaimer in the
     43  1.1  ozaki  *    documentation and/or other materials provided with the distribution.
     44  1.1  ozaki  * 3. All advertising materials mentioning features or use of this software
     45  1.1  ozaki  *    must display the following acknowledgements:
     46  1.1  ozaki  *      This product includes software developed by the University of
     47  1.1  ozaki  *      California, Berkeley and its contributors.
     48  1.1  ozaki  *      This product includes software developed at the Information
     49  1.1  ozaki  *      Technology Division, US Naval Research Laboratory.
     50  1.1  ozaki  * 4. Neither the name of the NRL nor the names of its contributors
     51  1.1  ozaki  *    may be used to endorse or promote products derived from this software
     52  1.1  ozaki  *    without specific prior written permission.
     53  1.1  ozaki  *
     54  1.1  ozaki  * THE SOFTWARE PROVIDED BY NRL IS PROVIDED BY NRL AND CONTRIBUTORS ``AS
     55  1.1  ozaki  * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     56  1.1  ozaki  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
     57  1.1  ozaki  * PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL NRL OR
     58  1.1  ozaki  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     59  1.1  ozaki  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     60  1.1  ozaki  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     61  1.1  ozaki  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
     62  1.1  ozaki  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
     63  1.1  ozaki  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     64  1.1  ozaki  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     65  1.1  ozaki  *
     66  1.1  ozaki  * The views and conclusions contained in the software and documentation
     67  1.1  ozaki  * are those of the authors and should not be interpreted as representing
     68  1.1  ozaki  * official policies, either expressed or implied, of the US Naval
     69  1.1  ozaki  * Research Laboratory (NRL).
     70  1.1  ozaki  */
     71  1.1  ozaki 
     72  1.1  ozaki /*-
     73  1.1  ozaki  * Copyright (c) 1997, 1998, 1999, 2001, 2005 The NetBSD Foundation, Inc.
     74  1.1  ozaki  * All rights reserved.
     75  1.1  ozaki  *
     76  1.1  ozaki  * This code is derived from software contributed to The NetBSD Foundation
     77  1.1  ozaki  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
     78  1.1  ozaki  * NASA Ames Research Center.
     79  1.1  ozaki  * This code is derived from software contributed to The NetBSD Foundation
     80  1.1  ozaki  * by Charles M. Hannum.
     81  1.1  ozaki  *
     82  1.1  ozaki  * Redistribution and use in source and binary forms, with or without
     83  1.1  ozaki  * modification, are permitted provided that the following conditions
     84  1.1  ozaki  * are met:
     85  1.1  ozaki  * 1. Redistributions of source code must retain the above copyright
     86  1.1  ozaki  *    notice, this list of conditions and the following disclaimer.
     87  1.1  ozaki  * 2. Redistributions in binary form must reproduce the above copyright
     88  1.1  ozaki  *    notice, this list of conditions and the following disclaimer in the
     89  1.1  ozaki  *    documentation and/or other materials provided with the distribution.
     90  1.1  ozaki  *
     91  1.1  ozaki  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     92  1.1  ozaki  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     93  1.1  ozaki  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     94  1.1  ozaki  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     95  1.1  ozaki  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     96  1.1  ozaki  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     97  1.1  ozaki  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     98  1.1  ozaki  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     99  1.1  ozaki  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    100  1.1  ozaki  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    101  1.1  ozaki  * POSSIBILITY OF SUCH DAMAGE.
    102  1.1  ozaki  */
    103  1.1  ozaki 
    104  1.1  ozaki /*
    105  1.1  ozaki  * Copyright (c) 1982, 1986, 1993, 1994, 1995
    106  1.1  ozaki  *	The Regents of the University of California.  All rights reserved.
    107  1.1  ozaki  *
    108  1.1  ozaki  * Redistribution and use in source and binary forms, with or without
    109  1.1  ozaki  * modification, are permitted provided that the following conditions
    110  1.1  ozaki  * are met:
    111  1.1  ozaki  * 1. Redistributions of source code must retain the above copyright
    112  1.1  ozaki  *    notice, this list of conditions and the following disclaimer.
    113  1.1  ozaki  * 2. Redistributions in binary form must reproduce the above copyright
    114  1.1  ozaki  *    notice, this list of conditions and the following disclaimer in the
    115  1.1  ozaki  *    documentation and/or other materials provided with the distribution.
    116  1.1  ozaki  * 3. Neither the name of the University nor the names of its contributors
    117  1.1  ozaki  *    may be used to endorse or promote products derived from this software
    118  1.1  ozaki  *    without specific prior written permission.
    119  1.1  ozaki  *
    120  1.1  ozaki  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    121  1.1  ozaki  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    122  1.1  ozaki  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    123  1.1  ozaki  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    124  1.1  ozaki  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    125  1.1  ozaki  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    126  1.1  ozaki  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    127  1.1  ozaki  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    128  1.1  ozaki  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    129  1.1  ozaki  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    130  1.1  ozaki  * SUCH DAMAGE.
    131  1.1  ozaki  *
    132  1.1  ozaki  *	@(#)tcp_var.h	8.4 (Berkeley) 5/24/95
    133  1.1  ozaki  */
    134  1.1  ozaki 
    135  1.1  ozaki #ifndef _NETINET_TCP_SYNCACHE_H_
    136  1.1  ozaki #define _NETINET_TCP_SYNCACHE_H_
    137  1.1  ozaki 
    138  1.1  ozaki #if defined(_KERNEL_OPT)
    139  1.1  ozaki #include "opt_inet.h"
    140  1.1  ozaki #include "opt_mbuftrace.h"
    141  1.1  ozaki #endif
    142  1.1  ozaki 
    143  1.1  ozaki #ifdef _KERNEL
    144  1.1  ozaki #include <sys/callout.h>
    145  1.1  ozaki #include <sys/mbuf.h>
    146  1.1  ozaki #include <sys/queue.h>
    147  1.1  ozaki 
    148  1.1  ozaki #include <net/route.h>
    149  1.1  ozaki 
    150  1.1  ozaki /*
    151  1.1  ozaki  * Data for the TCP compressed state engine.
    152  1.1  ozaki  */
    153  1.1  ozaki union syn_cache_sa {
    154  1.1  ozaki 	struct sockaddr sa;
    155  1.1  ozaki 	struct sockaddr_in sin;
    156  1.1  ozaki #if 1 /*def INET6*/
    157  1.1  ozaki 	struct sockaddr_in6 sin6;
    158  1.1  ozaki #endif
    159  1.1  ozaki };
    160  1.1  ozaki 
    161  1.1  ozaki struct syn_cache {
    162  1.1  ozaki 	TAILQ_ENTRY(syn_cache) sc_bucketq;	/* link on bucket list */
    163  1.1  ozaki 	callout_t sc_timer;			/* rexmt timer */
    164  1.1  ozaki 	struct route sc_route;
    165  1.1  ozaki 	long sc_win;				/* advertised window */
    166  1.1  ozaki 	int sc_bucketidx;			/* our bucket index */
    167  1.1  ozaki 	u_int32_t sc_hash;
    168  1.1  ozaki 	u_int32_t sc_timestamp;			/* timestamp from SYN */
    169  1.1  ozaki 	u_int32_t sc_timebase;			/* our local timebase */
    170  1.1  ozaki 	union syn_cache_sa sc_src;
    171  1.1  ozaki 	union syn_cache_sa sc_dst;
    172  1.1  ozaki 	tcp_seq sc_irs;
    173  1.1  ozaki 	tcp_seq sc_iss;
    174  1.1  ozaki 	u_int sc_rxtcur;			/* current rxt timeout */
    175  1.1  ozaki 	u_int sc_rxttot;			/* total time spend on queues */
    176  1.1  ozaki 	u_short sc_rxtshift;			/* for computing backoff */
    177  1.1  ozaki 	u_short sc_flags;
    178  1.1  ozaki 
    179  1.1  ozaki #define	SCF_UNREACH		0x0001		/* we've had an unreach error */
    180  1.1  ozaki #define	SCF_TIMESTAMP		0x0002		/* peer will do timestamps */
    181  1.1  ozaki #define	SCF_DEAD		0x0004		/* this entry to be released */
    182  1.1  ozaki #define SCF_SACK_PERMIT		0x0008		/* peer will do SACK */
    183  1.1  ozaki #define SCF_ECN_PERMIT		0x0010		/* peer will do ECN */
    184  1.1  ozaki #define SCF_SIGNATURE	0x40			/* send MD5 digests */
    185  1.1  ozaki 
    186  1.1  ozaki 	struct mbuf *sc_ipopts;			/* IP options */
    187  1.1  ozaki 	u_int16_t sc_peermaxseg;
    188  1.1  ozaki 	u_int16_t sc_ourmaxseg;
    189  1.1  ozaki 	u_int8_t sc_request_r_scale	: 4,
    190  1.1  ozaki 		 sc_requested_s_scale	: 4;
    191  1.1  ozaki 
    192  1.1  ozaki 	struct tcpcb *sc_tp;			/* tcb for listening socket */
    193  1.1  ozaki 	LIST_ENTRY(syn_cache) sc_tpq;		/* list of entries by same tp */
    194  1.1  ozaki };
    195  1.1  ozaki 
    196  1.1  ozaki struct syn_cache_head {
    197  1.1  ozaki 	TAILQ_HEAD(, syn_cache) sch_bucket;	/* bucket entries */
    198  1.1  ozaki 	u_short sch_length;			/* # entries in bucket */
    199  1.1  ozaki };
    200  1.1  ozaki 
    201  1.1  ozaki extern	int tcp_syn_bucket_limit;/* max entries per hash bucket */
    202  1.1  ozaki extern	int tcp_syn_cache_limit; /* max entries for compressed state engine */
    203  1.1  ozaki extern	u_long syn_cache_count;
    204  1.1  ozaki 
    205  1.1  ozaki int	 syn_cache_add(struct sockaddr *, struct sockaddr *,
    206  1.1  ozaki 		struct tcphdr *, unsigned int, struct socket *,
    207  1.1  ozaki 		struct mbuf *, u_char *, int, struct tcp_opt_info *);
    208  1.1  ozaki void	 syn_cache_unreach(const struct sockaddr *, const struct sockaddr *,
    209  1.1  ozaki 	   struct tcphdr *);
    210  1.2  ozaki struct socket
    211  1.2  ozaki 	*syn_cache_get(struct sockaddr *, struct sockaddr *,
    212  1.1  ozaki 		struct tcphdr *, struct socket *so, struct mbuf *);
    213  1.1  ozaki void	 syn_cache_init(void);
    214  1.1  ozaki void	 syn_cache_insert(struct syn_cache *, struct tcpcb *);
    215  1.1  ozaki void	 syn_cache_reset(struct sockaddr *, struct sockaddr *,
    216  1.1  ozaki 		struct tcphdr *);
    217  1.1  ozaki void	 syn_cache_cleanup(struct tcpcb *);
    218  1.1  ozaki #endif
    219  1.1  ozaki 
    220  1.1  ozaki #endif /* !_NETINET_TCP_SYNCACHE_H_ */
    221