The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=6538742c1aaca3ce522ccea95007dfa9686c78dd
commit 6538742c1aaca3ce522ccea95007dfa9686c78dd Author: Gleb Smirnoff <gleb...@freebsd.org> AuthorDate: 2025-06-17 15:50:01 +0000 Commit: Gleb Smirnoff <gleb...@freebsd.org> CommitDate: 2025-06-17 15:50:01 +0000 tcp: rename syncookie_lookup() into syncookie_expand() and make it bool This function always returns the same pointer it was passed. With new name and return type the code is easier to understand. Mark the hash bucket argument as pointer to const, since function doesn't modify it, just uses value as integer. No functional changes. Reviewed by: tuexen Differential Revision: https://reviews.freebsd.org/D50895 --- sys/netinet/tcp_syncache.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/sys/netinet/tcp_syncache.c b/sys/netinet/tcp_syncache.c index 606d808676e1..bcbc028cfbdc 100644 --- a/sys/netinet/tcp_syncache.c +++ b/sys/netinet/tcp_syncache.c @@ -131,10 +131,10 @@ static void syncache_timer(void *); static uint32_t syncookie_mac(struct in_conninfo *, tcp_seq, uint8_t, uint8_t *, uintptr_t); static tcp_seq syncookie_generate(struct syncache_head *, struct syncache *); -static struct syncache - *syncookie_lookup(struct in_conninfo *, struct syncache_head *, - struct syncache *, struct tcphdr *, struct tcpopt *, - struct socket *, uint16_t); +static bool syncookie_expand(struct in_conninfo *, + const struct syncache_head *, struct syncache *, + struct tcphdr *, struct tcpopt *, struct socket *, + uint16_t); static void syncache_pause(struct in_conninfo *); static void syncache_unpause(void *); static void syncookie_reseed(void *); @@ -1112,7 +1112,8 @@ syncache_expand(struct in_conninfo *inc, struct tcpopt *to, struct tcphdr *th, goto failed; } bzero(&scs, sizeof(scs)); - sc = syncookie_lookup(inc, sch, &scs, th, to, *lsop, port); + if (syncookie_expand(inc, sch, &scs, th, to, *lsop, port)) + sc = &scs; if (locked) SCH_UNLOCK(sch); if (sc == NULL) { @@ -2251,8 +2252,8 @@ syncookie_generate(struct syncache_head *sch, struct syncache *sc) return (iss); } -static struct syncache * -syncookie_lookup(struct in_conninfo *inc, struct syncache_head *sch, +static bool +syncookie_expand(struct in_conninfo *inc, const struct syncache_head *sch, struct syncache *sc, struct tcphdr *th, struct tcpopt *to, struct socket *lso, uint16_t port) { @@ -2282,7 +2283,7 @@ syncookie_lookup(struct in_conninfo *inc, struct syncache_head *sch, /* The recomputed hash matches the ACK if this was a genuine cookie. */ if ((ack & ~0xff) != (hash & ~0xff)) - return (NULL); + return (false); /* Fill in the syncache values. */ sc->sc_flags = 0; @@ -2343,7 +2344,7 @@ syncookie_lookup(struct in_conninfo *inc, struct syncache_head *sch, sc->sc_port = port; TCPSTAT_INC(tcps_sc_recvcookie); - return (sc); + return (true); } #ifdef INVARIANTS @@ -2352,11 +2353,12 @@ syncookie_cmp(struct in_conninfo *inc, struct syncache_head *sch, struct syncache *sc, struct tcphdr *th, struct tcpopt *to, struct socket *lso, uint16_t port) { - struct syncache scs, *scx; + struct syncache scs, *scx = NULL; char *s; bzero(&scs, sizeof(scs)); - scx = syncookie_lookup(inc, sch, &scs, th, to, lso, port); + if (syncookie_expand(inc, sch, &scs, th, to, lso, port)) + scx = &scs; if ((s = tcp_log_addrs(inc, th, NULL, NULL)) == NULL) return (0);