Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src tcp: separate syn cache stuffs into tcp_syncache.[ch] files
details: https://anonhg.NetBSD.org/src/rev/cf81643f9a71
branches: trunk
changeset: 370167:cf81643f9a71
user: ozaki-r <ozaki-r%NetBSD.org@localhost>
date: Tue Sep 20 07:19:14 2022 +0000
description:
tcp: separate syn cache stuffs into tcp_syncache.[ch] files
No functional change.
diffstat:
distrib/sets/lists/comp/mi | 3 +-
sys/netinet/Makefile | 6 +-
sys/netinet/files.netinet | 3 +-
sys/netinet/tcp_input.c | 1190 +-------------------------
sys/netinet/tcp_subr.c | 13 +-
sys/netinet/tcp_syncache.c | 1380 ++++++++++++++++++++++++++++++
sys/netinet/tcp_syncache.h | 222 ++++
sys/netinet/tcp_usrreq.c | 5 +-
sys/netinet/tcp_var.h | 80 +-
sys/rump/net/lib/libnetinet/Makefile.inc | 4 +-
10 files changed, 1627 insertions(+), 1279 deletions(-)
diffs (truncated from 3110 to 300 lines):
diff -r e5d988a9c2a2 -r cf81643f9a71 distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi Tue Sep 20 07:18:23 2022 +0000
+++ b/distrib/sets/lists/comp/mi Tue Sep 20 07:19:14 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.2423 2022/09/10 15:50:57 rillig Exp $
+# $NetBSD: mi,v 1.2424 2022/09/20 07:19:14 ozaki-r Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
./etc/mtree/set.comp comp-sys-root
@@ -2745,6 +2745,7 @@
./usr/include/netinet/tcp_debug.h comp-c-include
./usr/include/netinet/tcp_fsm.h comp-c-include
./usr/include/netinet/tcp_seq.h comp-c-include
+./usr/include/netinet/tcp_syncache.h comp-c-include
./usr/include/netinet/tcp_timer.h comp-c-include
./usr/include/netinet/tcp_var.h comp-c-include
./usr/include/netinet/tcp_vtw.h comp-c-include
diff -r e5d988a9c2a2 -r cf81643f9a71 sys/netinet/Makefile
--- a/sys/netinet/Makefile Tue Sep 20 07:18:23 2022 +0000
+++ b/sys/netinet/Makefile Tue Sep 20 07:19:14 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.30 2018/09/06 06:42:00 maxv Exp $
+# $NetBSD: Makefile,v 1.31 2022/09/20 07:19:14 ozaki-r Exp $
INCSDIR= /usr/include/netinet
@@ -8,8 +8,8 @@
in_var.h ip.h ip_carp.h ip6.h ip_ecn.h ip_encap.h \
ip_icmp.h ip_mroute.h ip_var.h pim.h pim_var.h portalgo.h \
sctp.h sctp_uio.h \
- tcp.h tcp_debug.h tcp_fsm.h tcp_seq.h tcp_timer.h tcp_var.h \
- tcpip.h udp.h udp_var.h \
+ tcp.h tcp_debug.h tcp_fsm.h tcp_seq.h tcp_syncache.h tcp_timer.h \
+ tcp_var.h tcpip.h udp.h udp_var.h \
tcp_vtw.h
# ipfilter headers
diff -r e5d988a9c2a2 -r cf81643f9a71 sys/netinet/files.netinet
--- a/sys/netinet/files.netinet Tue Sep 20 07:18:23 2022 +0000
+++ b/sys/netinet/files.netinet Tue Sep 20 07:19:14 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.netinet,v 1.29 2021/03/08 18:03:25 christos Exp $
+# $NetBSD: files.netinet,v 1.30 2022/09/20 07:19:14 ozaki-r Exp $
defflag opt_tcp_debug.h TCP_DEBUG
defparam opt_tcp_debug.h TCP_NDEBUG
@@ -45,6 +45,7 @@
file netinet/tcp_output.c inet | inet6
file netinet/tcp_sack.c inet | inet6
file netinet/tcp_subr.c inet | inet6
+file netinet/tcp_syncache.c inet | inet6
file netinet/tcp_timer.c inet | inet6
file netinet/tcp_usrreq.c inet | inet6
file netinet/tcp_congctl.c inet | inet6
diff -r e5d988a9c2a2 -r cf81643f9a71 sys/netinet/tcp_input.c
--- a/sys/netinet/tcp_input.c Tue Sep 20 07:18:23 2022 +0000
+++ b/sys/netinet/tcp_input.c Tue Sep 20 07:19:14 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tcp_input.c,v 1.433 2022/05/24 20:50:20 andvar Exp $ */
+/* $NetBSD: tcp_input.c,v 1.434 2022/09/20 07:19:14 ozaki-r Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -137,18 +137,8 @@
* @(#)tcp_input.c 8.12 (Berkeley) 5/24/95
*/
-/*
- * TODO list for SYN cache stuff:
- *
- * Find room for a "state" field, which is needed to keep a
- * compressed state for TIME_WAIT TCBs. It's been noted already
- * that this is fairly important for very high-volume web and
- * mail servers, which use a large number of short-lived
- * connections.
- */
-
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.433 2022/05/24 20:50:20 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.434 2022/09/20 07:19:14 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@@ -214,6 +204,7 @@
#include <netinet/tcp_private.h>
#include <netinet/tcp_congctl.h>
#include <netinet/tcp_debug.h>
+#include <netinet/tcp_syncache.h>
#ifdef INET6
#include "faith.h"
@@ -245,8 +236,6 @@
static int tcp_ackdrop_ppslim_count = 0;
static struct timeval tcp_ackdrop_ppslim_last;
-static void syn_cache_timer(void *);
-
#define TCP_PAWS_IDLE (24U * 24 * 60 * 60 * PR_SLOWHZ)
/* for modulo comparisons of timestamps */
@@ -426,8 +415,6 @@
static int tcp_reass(struct tcpcb *, const struct tcphdr *, struct mbuf *,
int);
-static int tcp_dooptions(struct tcpcb *, const u_char *, int,
- struct tcphdr *, struct mbuf *, int, struct tcp_opt_info *);
static void tcp4_log_refused(const struct ip *, const struct tcphdr *);
#ifdef INET6
@@ -3155,7 +3142,7 @@
* Returns -1 if this segment should be dropped. (eg. wrong signature)
* Otherwise returns 0.
*/
-static int
+int
tcp_dooptions(struct tcpcb *tp, const u_char *cp, int cnt, struct tcphdr *th,
struct mbuf *m, int toff, struct tcp_opt_info *oi)
{
@@ -3470,1172 +3457,3 @@
*/
tp->t_softerror = 0;
}
-
-
-/*
- * TCP compressed state engine. Currently used to hold compressed
- * state for SYN_RECEIVED.
- */
-
-u_long syn_cache_count;
-u_int32_t syn_hash1, syn_hash2;
-
-#define SYN_HASH(sa, sp, dp) \
- ((((sa)->s_addr^syn_hash1)*(((((u_int32_t)(dp))<<16) + \
- ((u_int32_t)(sp)))^syn_hash2)))
-#ifndef INET6
-#define SYN_HASHALL(hash, src, dst) \
-do { \
- hash = SYN_HASH(&((const struct sockaddr_in *)(src))->sin_addr, \
- ((const struct sockaddr_in *)(src))->sin_port, \
- ((const struct sockaddr_in *)(dst))->sin_port); \
-} while (/*CONSTCOND*/ 0)
-#else
-#define SYN_HASH6(sa, sp, dp) \
- ((((sa)->s6_addr32[0] ^ (sa)->s6_addr32[3] ^ syn_hash1) * \
- (((((u_int32_t)(dp))<<16) + ((u_int32_t)(sp)))^syn_hash2)) \
- & 0x7fffffff)
-
-#define SYN_HASHALL(hash, src, dst) \
-do { \
- switch ((src)->sa_family) { \
- case AF_INET: \
- hash = SYN_HASH(&((const struct sockaddr_in *)(src))->sin_addr, \
- ((const struct sockaddr_in *)(src))->sin_port, \
- ((const struct sockaddr_in *)(dst))->sin_port); \
- break; \
- case AF_INET6: \
- hash = SYN_HASH6(&((const struct sockaddr_in6 *)(src))->sin6_addr, \
- ((const struct sockaddr_in6 *)(src))->sin6_port, \
- ((const struct sockaddr_in6 *)(dst))->sin6_port); \
- break; \
- default: \
- hash = 0; \
- } \
-} while (/*CONSTCOND*/0)
-#endif /* INET6 */
-
-static struct pool syn_cache_pool;
-
-/*
- * We don't estimate RTT with SYNs, so each packet starts with the default
- * RTT and each timer step has a fixed timeout value.
- */
-static inline void
-syn_cache_timer_arm(struct syn_cache *sc)
-{
-
- TCPT_RANGESET(sc->sc_rxtcur,
- TCPTV_SRTTDFLT * tcp_backoff[sc->sc_rxtshift], TCPTV_MIN,
- TCPTV_REXMTMAX);
- callout_reset(&sc->sc_timer,
- sc->sc_rxtcur * (hz / PR_SLOWHZ), syn_cache_timer, sc);
-}
-
-#define SYN_CACHE_TIMESTAMP(sc) (tcp_now - (sc)->sc_timebase)
-
-static inline void
-syn_cache_rm(struct syn_cache *sc)
-{
- TAILQ_REMOVE(&tcp_syn_cache[sc->sc_bucketidx].sch_bucket,
- sc, sc_bucketq);
- sc->sc_tp = NULL;
- LIST_REMOVE(sc, sc_tpq);
- tcp_syn_cache[sc->sc_bucketidx].sch_length--;
- callout_stop(&sc->sc_timer);
- syn_cache_count--;
-}
-
-static inline void
-syn_cache_put(struct syn_cache *sc)
-{
- if (sc->sc_ipopts)
- (void) m_free(sc->sc_ipopts);
- rtcache_free(&sc->sc_route);
- sc->sc_flags |= SCF_DEAD;
- if (!callout_invoking(&sc->sc_timer))
- callout_schedule(&(sc)->sc_timer, 1);
-}
-
-void
-syn_cache_init(void)
-{
- int i;
-
- pool_init(&syn_cache_pool, sizeof(struct syn_cache), 0, 0, 0,
- "synpl", NULL, IPL_SOFTNET);
-
- /* Initialize the hash buckets. */
- for (i = 0; i < tcp_syn_cache_size; i++)
- TAILQ_INIT(&tcp_syn_cache[i].sch_bucket);
-}
-
-void
-syn_cache_insert(struct syn_cache *sc, struct tcpcb *tp)
-{
- struct syn_cache_head *scp;
- struct syn_cache *sc2;
- int s;
-
- /*
- * If there are no entries in the hash table, reinitialize
- * the hash secrets.
- */
- if (syn_cache_count == 0) {
- syn_hash1 = cprng_fast32();
- syn_hash2 = cprng_fast32();
- }
-
- SYN_HASHALL(sc->sc_hash, &sc->sc_src.sa, &sc->sc_dst.sa);
- sc->sc_bucketidx = sc->sc_hash % tcp_syn_cache_size;
- scp = &tcp_syn_cache[sc->sc_bucketidx];
-
- /*
- * Make sure that we don't overflow the per-bucket
- * limit or the total cache size limit.
- */
- s = splsoftnet();
- if (scp->sch_length >= tcp_syn_bucket_limit) {
- TCP_STATINC(TCP_STAT_SC_BUCKETOVERFLOW);
- /*
- * The bucket is full. Toss the oldest element in the
- * bucket. This will be the first entry in the bucket.
- */
- sc2 = TAILQ_FIRST(&scp->sch_bucket);
-#ifdef DIAGNOSTIC
- /*
- * This should never happen; we should always find an
- * entry in our bucket.
- */
- if (sc2 == NULL)
- panic("syn_cache_insert: bucketoverflow: impossible");
-#endif
- syn_cache_rm(sc2);
- syn_cache_put(sc2); /* calls pool_put but see spl above */
- } else if (syn_cache_count >= tcp_syn_cache_limit) {
- struct syn_cache_head *scp2, *sce;
-
- TCP_STATINC(TCP_STAT_SC_OVERFLOWED);
- /*
- * The cache is full. Toss the oldest entry in the
- * first non-empty bucket we can find.
- *
- * XXX We would really like to toss the oldest
- * entry in the cache, but we hope that this
- * condition doesn't happen very often.
- */
- scp2 = scp;
- if (TAILQ_EMPTY(&scp2->sch_bucket)) {
- sce = &tcp_syn_cache[tcp_syn_cache_size];
- for (++scp2; scp2 != scp; scp2++) {
- if (scp2 >= sce)
- scp2 = &tcp_syn_cache[0];
- if (! TAILQ_EMPTY(&scp2->sch_bucket))
- break;
- }
-#ifdef DIAGNOSTIC
- /*
- * This should never happen; we should always find a
- * non-empty bucket.
- */
- if (scp2 == scp)
- panic("syn_cache_insert: cacheoverflow: "
- "impossible");
-#endif
- }
- sc2 = TAILQ_FIRST(&scp2->sch_bucket);
- syn_cache_rm(sc2);
- syn_cache_put(sc2); /* calls pool_put but see spl above */
- }
-
Home |
Main Index |
Thread Index |
Old Index