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