summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorbluhm <bluhm@openbsd.org>2015-08-24 15:37:03 +0000
committerbluhm <bluhm@openbsd.org>2015-08-24 15:37:03 +0000
commitc694f8b18004a248aa50c2cf0ac13e1defe84b66 (patch)
tree92958de2214ad99ca129798c7ead0ac51f8ebbe4 /sys
parentRename M_RTABLE bucket into "rtable" to match the code and kill unused (diff)
downloadwireguard-openbsd-c694f8b18004a248aa50c2cf0ac13e1defe84b66.tar.xz
wireguard-openbsd-c694f8b18004a248aa50c2cf0ac13e1defe84b66.zip
Rename the syn cache counter into tcp_syn_cache_count to have the
same prefix for all variables. Convert the counter type to int, the limit is also int. Before searching the cache, check that it is not empty. Do not access the counter outside of the syn cache from tcp_ctlinput(), let the syn_cache_lookup() function handle it. OK dlg@
Diffstat (limited to 'sys')
-rw-r--r--sys/netinet/tcp_input.c16
-rw-r--r--sys/netinet/tcp_subr.c16
-rw-r--r--sys/netinet/tcp_var.h3
3 files changed, 17 insertions, 18 deletions
diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c
index 3cd2b0ae0a1..1c9bdbee67f 100644
--- a/sys/netinet/tcp_input.c
+++ b/sys/netinet/tcp_input.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tcp_input.c,v 1.299 2015/08/13 23:42:16 bluhm Exp $ */
+/* $OpenBSD: tcp_input.c,v 1.300 2015/08/24 15:37:03 bluhm Exp $ */
/* $NetBSD: tcp_input.c,v 1.23 1996/02/13 23:43:44 christos Exp $ */
/*
@@ -3276,7 +3276,7 @@ tcp_mss_adv(struct ifnet *ifp, int af)
* state for SYN_RECEIVED.
*/
-u_long syn_cache_count;
+int tcp_syn_cache_count;
u_int32_t syn_hash1, syn_hash2;
#define SYN_HASH(sa, sp, dp) \
@@ -3324,7 +3324,7 @@ syn_cache_rm(struct syn_cache *sc)
LIST_REMOVE(sc, sc_tpq);
tcp_syn_cache[sc->sc_bucketidx].sch_length--;
timeout_del(&sc->sc_timer);
- syn_cache_count--;
+ tcp_syn_cache_count--;
}
void
@@ -3383,7 +3383,7 @@ syn_cache_insert(struct syn_cache *sc, struct tcpcb *tp)
* If there are no entries in the hash table, reinitialize
* the hash secrets.
*/
- if (syn_cache_count == 0) {
+ if (tcp_syn_cache_count == 0) {
syn_hash1 = arc4random();
syn_hash2 = arc4random();
}
@@ -3414,7 +3414,7 @@ syn_cache_insert(struct syn_cache *sc, struct tcpcb *tp)
#endif
syn_cache_rm(sc2);
syn_cache_put(sc2);
- } else if (syn_cache_count >= tcp_syn_cache_limit) {
+ } else if (tcp_syn_cache_count >= tcp_syn_cache_limit) {
struct syn_cache_head *scp2, *sce;
tcpstat.tcps_sc_overflowed++;
@@ -3463,7 +3463,7 @@ syn_cache_insert(struct syn_cache *sc, struct tcpcb *tp)
/* Put it into the bucket. */
TAILQ_INSERT_TAIL(&scp->sch_bucket, sc, sc_bucketq);
scp->sch_length++;
- syn_cache_count++;
+ tcp_syn_cache_count++;
tcpstat.tcps_sc_added++;
splx(s);
@@ -3568,8 +3568,10 @@ syn_cache_lookup(struct sockaddr *src, struct sockaddr *dst,
u_int32_t hash;
int s;
- SYN_HASHALL(hash, src, dst);
+ if (tcp_syn_cache_count == 0)
+ return (NULL);
+ SYN_HASHALL(hash, src, dst);
scp = &tcp_syn_cache[hash % tcp_syn_cache_size];
*headp = scp;
s = splsoftnet();
diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c
index bf7ff297b68..08d23d574fe 100644
--- a/sys/netinet/tcp_subr.c
+++ b/sys/netinet/tcp_subr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tcp_subr.c,v 1.144 2015/07/16 16:12:15 mpi Exp $ */
+/* $OpenBSD: tcp_subr.c,v 1.145 2015/08/24 15:37:03 bluhm Exp $ */
/* $NetBSD: tcp_subr.c,v 1.22 1996/02/13 23:44:00 christos Exp $ */
/*
@@ -731,10 +731,9 @@ tcp6_ctlinput(int cmd, struct sockaddr *sa, u_int rdomain, void *d)
SEQ_GEQ(seq, tp->snd_una) &&
SEQ_LT(seq, tp->snd_max))
notify(inp, inet6ctlerrmap[cmd]);
- } else if (syn_cache_count &&
- (inet6ctlerrmap[cmd] == EHOSTUNREACH ||
- inet6ctlerrmap[cmd] == ENETUNREACH ||
- inet6ctlerrmap[cmd] == EHOSTDOWN))
+ } else if (inet6ctlerrmap[cmd] == EHOSTUNREACH ||
+ inet6ctlerrmap[cmd] == ENETUNREACH ||
+ inet6ctlerrmap[cmd] == EHOSTDOWN)
syn_cache_unreach((struct sockaddr *)sa6_src,
sa, &th, rdomain);
} else {
@@ -849,10 +848,9 @@ tcp_ctlinput(int cmd, struct sockaddr *sa, u_int rdomain, void *v)
SEQ_GEQ(seq, tp->snd_una) &&
SEQ_LT(seq, tp->snd_max))
notify(inp, errno);
- } else if (syn_cache_count &&
- (inetctlerrmap[cmd] == EHOSTUNREACH ||
- inetctlerrmap[cmd] == ENETUNREACH ||
- inetctlerrmap[cmd] == EHOSTDOWN)) {
+ } else if (inetctlerrmap[cmd] == EHOSTUNREACH ||
+ inetctlerrmap[cmd] == ENETUNREACH ||
+ inetctlerrmap[cmd] == EHOSTDOWN) {
struct sockaddr_in sin;
bzero(&sin, sizeof(sin));
diff --git a/sys/netinet/tcp_var.h b/sys/netinet/tcp_var.h
index 3e8ca2bd222..746f49eeefa 100644
--- a/sys/netinet/tcp_var.h
+++ b/sys/netinet/tcp_var.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tcp_var.h,v 1.107 2015/02/08 04:40:50 yasuoka Exp $ */
+/* $OpenBSD: tcp_var.h,v 1.108 2015/08/24 15:37:03 bluhm Exp $ */
/* $NetBSD: tcp_var.h,v 1.17 1996/02/13 23:44:24 christos Exp $ */
/*
@@ -560,7 +560,6 @@ extern int tcp_syn_bucket_limit;/* max entries per hash bucket */
extern int tcp_syn_cache_size;
extern struct syn_cache_head tcp_syn_cache[];
-extern u_long syn_cache_count;
int tcp_attach(struct socket *);
void tcp_canceltimers(struct tcpcb *);