1171605Ssilby/*- 2171605Ssilby * Copyright (c) 1982, 1986, 1993, 1994, 1995 3171605Ssilby * The Regents of the University of California. All rights reserved. 4171605Ssilby * 5171605Ssilby * Redistribution and use in source and binary forms, with or without 6171605Ssilby * modification, are permitted provided that the following conditions 7171605Ssilby * are met: 8171605Ssilby * 1. Redistributions of source code must retain the above copyright 9171605Ssilby * notice, this list of conditions and the following disclaimer. 10171605Ssilby * 2. Redistributions in binary form must reproduce the above copyright 11171605Ssilby * notice, this list of conditions and the following disclaimer in the 12171605Ssilby * documentation and/or other materials provided with the distribution. 13171605Ssilby * 4. Neither the name of the University nor the names of its contributors 14171605Ssilby * may be used to endorse or promote products derived from this software 15171605Ssilby * without specific prior written permission. 16171605Ssilby * 17171605Ssilby * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18171605Ssilby * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19171605Ssilby * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20171605Ssilby * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21171605Ssilby * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22171605Ssilby * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23171605Ssilby * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24171605Ssilby * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25171605Ssilby * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26171605Ssilby * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27171605Ssilby * SUCH DAMAGE. 28171605Ssilby * 29171605Ssilby * @(#)tcp_var.h 8.4 (Berkeley) 5/24/95 30171605Ssilby * $FreeBSD: stable/10/sys/netinet/tcp_syncache.h 322315 2017-08-09 13:26:12Z tuexen $ 31171605Ssilby */ 32171605Ssilby 33171605Ssilby#ifndef _NETINET_TCP_SYNCACHE_H_ 34171605Ssilby#define _NETINET_TCP_SYNCACHE_H_ 35171605Ssilby#ifdef _KERNEL 36171605Ssilby 37171605Ssilbyvoid syncache_init(void); 38193731Szec#ifdef VIMAGE 39193731Szecvoid syncache_destroy(void); 40193731Szec#endif 41171605Ssilbyvoid syncache_unreach(struct in_conninfo *, struct tcphdr *); 42171605Ssilbyint syncache_expand(struct in_conninfo *, struct tcpopt *, 43171605Ssilby struct tcphdr *, struct socket **, struct mbuf *); 44292823Spkelseyint syncache_add(struct in_conninfo *, struct tcpopt *, 45237263Snp struct tcphdr *, struct inpcb *, struct socket **, struct mbuf *, 46237263Snp void *, void *); 47171605Ssilbyvoid syncache_chkrst(struct in_conninfo *, struct tcphdr *); 48171605Ssilbyvoid syncache_badack(struct in_conninfo *); 49171605Ssilbyint syncache_pcbcount(void); 50171605Ssilbyint syncache_pcblist(struct sysctl_req *req, int max_pcbs, int *pcbs_exported); 51171605Ssilby 52182129Sjulianstruct syncache { 53182129Sjulian TAILQ_ENTRY(syncache) sc_hash; 54182129Sjulian struct in_conninfo sc_inc; /* addresses */ 55182129Sjulian int sc_rxttime; /* retransmit time */ 56182129Sjulian u_int16_t sc_rxmits; /* retransmit counter */ 57182129Sjulian u_int32_t sc_tsreflect; /* timestamp to reflect */ 58182129Sjulian u_int32_t sc_ts; /* our timestamp to send */ 59182129Sjulian u_int32_t sc_tsoff; /* ts offset w/ syncookies */ 60182129Sjulian u_int32_t sc_flowlabel; /* IPv6 flowlabel */ 61182129Sjulian tcp_seq sc_irs; /* seq from peer */ 62182129Sjulian tcp_seq sc_iss; /* our ISS */ 63182129Sjulian struct mbuf *sc_ipopts; /* source route */ 64182129Sjulian u_int16_t sc_peer_mss; /* peer's MSS */ 65182129Sjulian u_int16_t sc_wnd; /* advertised window */ 66182129Sjulian u_int8_t sc_ip_ttl; /* IPv4 TTL */ 67182129Sjulian u_int8_t sc_ip_tos; /* IPv4 TOS */ 68182129Sjulian u_int8_t sc_requested_s_scale:4, 69182129Sjulian sc_requested_r_scale:4; 70182129Sjulian u_int16_t sc_flags; 71237263Snp#if defined(TCP_OFFLOAD) || !defined(TCP_OFFLOAD_DISABLE) 72237263Snp struct toedev *sc_tod; /* entry added by this TOE */ 73237263Snp void *sc_todctx; /* TOE driver context */ 74237263Snp#endif 75182129Sjulian struct label *sc_label; /* MAC label reference */ 76182129Sjulian struct ucred *sc_cred; /* cred cache for jail checks */ 77292823Spkelsey#ifdef TCP_RFC7413 78292823Spkelsey void *sc_tfo_cookie; /* for TCP Fast Open response */ 79292823Spkelsey#endif 80255759Sbz void *sc_pspare; /* TCP_SIGNATURE */ 81224151Sbz u_int32_t sc_spare[2]; /* UTO */ 82182129Sjulian}; 83182129Sjulian 84185857Srwatson/* 85185857Srwatson * Flags for the sc_flags field. 86185857Srwatson */ 87185857Srwatson#define SCF_NOOPT 0x01 /* no TCP options */ 88185857Srwatson#define SCF_WINSCALE 0x02 /* negotiated window scaling */ 89185857Srwatson#define SCF_TIMESTAMP 0x04 /* negotiated timestamps */ 90185857Srwatson /* MSS is implicit */ 91185857Srwatson#define SCF_UNREACH 0x10 /* icmp unreachable received */ 92185857Srwatson#define SCF_SIGNATURE 0x20 /* send MD5 digests */ 93185857Srwatson#define SCF_SACK 0x80 /* send SACK option */ 94185857Srwatson#define SCF_ECN 0x100 /* send ECN setup packet */ 95185857Srwatson 96182129Sjulianstruct syncache_head { 97182129Sjulian struct mtx sch_mtx; 98182129Sjulian TAILQ_HEAD(sch_head, syncache) sch_bucket; 99182129Sjulian struct callout sch_timer; 100182129Sjulian int sch_nextc; 101182129Sjulian u_int sch_length; 102253210Sandre struct tcp_syncache *sch_sc; 103322315Stuexen time_t sch_last_overflow; 104182129Sjulian}; 105182129Sjulian 106253210Sandre#define SYNCOOKIE_SECRET_SIZE 16 107253210Sandre#define SYNCOOKIE_LIFETIME 15 /* seconds */ 108253210Sandre 109253210Sandrestruct syncookie_secret { 110253210Sandre volatile u_int oddeven; 111253210Sandre uint8_t key[2][SYNCOOKIE_SECRET_SIZE]; 112253210Sandre struct callout reseed; 113253210Sandre u_int lifetime; 114253210Sandre}; 115253210Sandre 116182129Sjulianstruct tcp_syncache { 117182129Sjulian struct syncache_head *hashbase; 118182129Sjulian uma_zone_t zone; 119182129Sjulian u_int hashsize; 120182129Sjulian u_int hashmask; 121182129Sjulian u_int bucket_limit; 122182129Sjulian u_int cache_limit; 123182129Sjulian u_int rexmt_limit; 124182129Sjulian u_int hash_secret; 125253254Sandre struct vnet *vnet; 126253210Sandre struct syncookie_secret secret; 127182129Sjulian}; 128182129Sjulian 129253210Sandre/* Internal use for the syncookie functions. */ 130253210Sandreunion syncookie { 131253210Sandre uint8_t cookie; 132253210Sandre struct { 133253210Sandre uint8_t odd_even:1, 134253210Sandre sack_ok:1, 135253210Sandre wscale_idx:3, 136253210Sandre mss_idx:3; 137253210Sandre } flags; 138253210Sandre}; 139253210Sandre 140171605Ssilby#endif /* _KERNEL */ 141182129Sjulian#endif /* !_NETINET_TCP_SYNCACHE_H_ */ 142