From 556c90b346be7bdb2eac60e4a437edd41c92fe8b Mon Sep 17 00:00:00 2001 From: mikeb Date: Mon, 13 Apr 2015 16:48:01 +0000 Subject: [PATCH] Rename gettdbbyaddr to gettdbbydst; OK markus, hshoexer, mpi --- sys/netinet/ip_ipsp.c | 49 +++++++++++++++++++++++-------------------- sys/netinet/ip_ipsp.h | 6 +++--- sys/netinet/ip_spd.c | 8 +++---- 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/sys/netinet/ip_ipsp.c b/sys/netinet/ip_ipsp.c index 901fe77542f..524d339ceeb 100644 --- a/sys/netinet/ip_ipsp.c +++ b/sys/netinet/ip_ipsp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_ipsp.c,v 1.206 2015/04/13 16:45:52 mikeb Exp $ */ +/* $OpenBSD: ip_ipsp.c,v 1.207 2015/04/13 16:48:01 mikeb Exp $ */ /* * The authors of this code are John Ioannidis (ji@tla.org), * Angelos D. Keromytis (kermit@csd.uch.gr), @@ -126,7 +126,7 @@ struct xformsw *xformswNXFORMSW = &xformsw[nitems(xformsw)]; static SIPHASH_KEY tdbkey; static struct tdb **tdbh = NULL; -static struct tdb **tdbaddr = NULL; +static struct tdb **tdbdst = NULL; static struct tdb **tdbsrc = NULL; static u_int tdb_hashmask = TDB_HASHSIZE_INIT - 1; static int tdb_count; @@ -382,7 +382,7 @@ ipsp_aux_match(struct tdb *tdb, * the desired IDs. */ struct tdb * -gettdbbyaddr(u_int rdomain, union sockaddr_union *dst, u_int8_t sproto, +gettdbbydst(u_int rdomain, union sockaddr_union *dst, u_int8_t sproto, struct ipsec_ref *srcid, struct ipsec_ref *dstid, struct ipsec_ref *local_cred, struct sockaddr_encap *filter, struct sockaddr_encap *filtermask) @@ -390,12 +390,12 @@ gettdbbyaddr(u_int rdomain, union sockaddr_union *dst, u_int8_t sproto, u_int32_t hashval; struct tdb *tdbp; - if (tdbaddr == NULL) + if (tdbdst == NULL) return (struct tdb *) NULL; hashval = tdb_hash(rdomain, 0, dst, sproto); - for (tdbp = tdbaddr[hashval]; tdbp != NULL; tdbp = tdbp->tdb_anext) + for (tdbp = tdbdst[hashval]; tdbp != NULL; tdbp = tdbp->tdb_dnext) if ((tdbp->tdb_sproto == sproto) && (tdbp->tdb_rdomain == rdomain) && ((tdbp->tdb_flags & TDBF_INVALID) == 0) && @@ -565,7 +565,7 @@ tdb_soft_firstuse(void *v) void tdb_rehash(void) { - struct tdb **new_tdbh, **new_tdbaddr, **new_srcaddr, *tdbp, *tdbnp; + struct tdb **new_tdbh, **new_tdbdst, **new_srcaddr, *tdbp, *tdbnp; u_int i, old_hashmask = tdb_hashmask; u_int32_t hashval; @@ -574,7 +574,7 @@ tdb_rehash(void) arc4random_buf(&tdbkey, sizeof(tdbkey)); new_tdbh = mallocarray(tdb_hashmask + 1, sizeof(struct tdb *), M_TDB, M_WAITOK | M_ZERO); - new_tdbaddr = mallocarray(tdb_hashmask + 1, sizeof(struct tdb *), M_TDB, + new_tdbdst = mallocarray(tdb_hashmask + 1, sizeof(struct tdb *), M_TDB, M_WAITOK | M_ZERO); new_srcaddr = mallocarray(tdb_hashmask + 1, sizeof(struct tdb *), M_TDB, M_WAITOK | M_ZERO); @@ -589,13 +589,13 @@ tdb_rehash(void) new_tdbh[hashval] = tdbp; } - for (tdbp = tdbaddr[i]; tdbp != NULL; tdbp = tdbnp) { - tdbnp = tdbp->tdb_anext; + for (tdbp = tdbdst[i]; tdbp != NULL; tdbp = tdbnp) { + tdbnp = tdbp->tdb_dnext; hashval = tdb_hash(tdbp->tdb_rdomain, 0, &tdbp->tdb_dst, tdbp->tdb_sproto); - tdbp->tdb_anext = new_tdbaddr[hashval]; - new_tdbaddr[hashval] = tdbp; + tdbp->tdb_dnext = new_tdbdst[hashval]; + new_tdbdst[hashval] = tdbp; } for (tdbp = tdbsrc[i]; tdbp != NULL; tdbp = tdbnp) { @@ -611,8 +611,8 @@ tdb_rehash(void) free(tdbh, M_TDB, 0); tdbh = new_tdbh; - free(tdbaddr, M_TDB, 0); - tdbaddr = new_tdbaddr; + free(tdbdst, M_TDB, 0); + tdbdst = new_tdbdst; free(tdbsrc, M_TDB, 0); tdbsrc = new_srcaddr; @@ -631,7 +631,7 @@ puttdb(struct tdb *tdbp) arc4random_buf(&tdbkey, sizeof(tdbkey)); tdbh = mallocarray(tdb_hashmask + 1, sizeof(struct tdb *), M_TDB, M_WAITOK | M_ZERO); - tdbaddr = mallocarray(tdb_hashmask + 1, sizeof(struct tdb *), + tdbdst = mallocarray(tdb_hashmask + 1, sizeof(struct tdb *), M_TDB, M_WAITOK | M_ZERO); tdbsrc = mallocarray(tdb_hashmask + 1, sizeof(struct tdb *), M_TDB, M_WAITOK | M_ZERO); @@ -660,8 +660,8 @@ puttdb(struct tdb *tdbp) hashval = tdb_hash(tdbp->tdb_rdomain, 0, &tdbp->tdb_dst, tdbp->tdb_sproto); - tdbp->tdb_anext = tdbaddr[hashval]; - tdbaddr[hashval] = tdbp; + tdbp->tdb_dnext = tdbdst[hashval]; + tdbdst[hashval] = tdbp; hashval = tdb_hash(tdbp->tdb_rdomain, 0, &tdbp->tdb_src, tdbp->tdb_sproto); @@ -688,10 +688,11 @@ tdb_delete(struct tdb *tdbp) if (tdbh == NULL) return; + s = splsoftnet(); + hashval = tdb_hash(tdbp->tdb_rdomain, tdbp->tdb_spi, &tdbp->tdb_dst, tdbp->tdb_sproto); - s = splsoftnet(); if (tdbh[hashval] == tdbp) { tdbh[hashval] = tdbp->tdb_hnext; } else { @@ -709,18 +710,20 @@ tdb_delete(struct tdb *tdbp) hashval = tdb_hash(tdbp->tdb_rdomain, 0, &tdbp->tdb_dst, tdbp->tdb_sproto); - if (tdbaddr[hashval] == tdbp) { - tdbaddr[hashval] = tdbp->tdb_anext; + if (tdbdst[hashval] == tdbp) { + tdbdst[hashval] = tdbp->tdb_dnext; } else { - for (tdbpp = tdbaddr[hashval]; tdbpp != NULL; - tdbpp = tdbpp->tdb_anext) { - if (tdbpp->tdb_anext == tdbp) { - tdbpp->tdb_anext = tdbp->tdb_anext; + for (tdbpp = tdbdst[hashval]; tdbpp != NULL; + tdbpp = tdbpp->tdb_dnext) { + if (tdbpp->tdb_dnext == tdbp) { + tdbpp->tdb_dnext = tdbp->tdb_dnext; break; } } } + tdbp->tdb_dnext = NULL; + hashval = tdb_hash(tdbp->tdb_rdomain, 0, &tdbp->tdb_src, tdbp->tdb_sproto); diff --git a/sys/netinet/ip_ipsp.h b/sys/netinet/ip_ipsp.h index 8550918a22f..f436e4935eb 100644 --- a/sys/netinet/ip_ipsp.h +++ b/sys/netinet/ip_ipsp.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_ipsp.h,v 1.162 2015/04/13 16:45:52 mikeb Exp $ */ +/* $OpenBSD: ip_ipsp.h,v 1.163 2015/04/13 16:48:01 mikeb Exp $ */ /* * The authors of this code are John Ioannidis (ji@tla.org), * Angelos D. Keromytis (kermit@csd.uch.gr), @@ -271,7 +271,7 @@ struct tdb { /* tunnel descriptor block */ * queues in those three tables. */ struct tdb *tdb_hnext; /* dst/spi/sproto table */ - struct tdb *tdb_anext; /* dst/sproto table */ + struct tdb *tdb_dnext; /* dst/sproto table */ struct tdb *tdb_snext; /* src/sproto table */ struct tdb *tdb_inext; struct tdb *tdb_onext; @@ -504,7 +504,7 @@ void tdb_add_inp(struct tdb *, struct inpcb *, int); uint32_t reserve_spi(u_int, u_int32_t, u_int32_t, union sockaddr_union *, union sockaddr_union *, u_int8_t, int *); struct tdb *gettdb(u_int, u_int32_t, union sockaddr_union *, u_int8_t); -struct tdb *gettdbbyaddr(u_int, union sockaddr_union *, u_int8_t, +struct tdb *gettdbbydst(u_int, union sockaddr_union *, u_int8_t, struct ipsec_ref *, struct ipsec_ref *, struct ipsec_ref *, struct sockaddr_encap *, struct sockaddr_encap *); struct tdb *gettdbbysrc(u_int, union sockaddr_union *, u_int8_t, diff --git a/sys/netinet/ip_spd.c b/sys/netinet/ip_spd.c index 0170dc1d85c..4fe95bfd127 100644 --- a/sys/netinet/ip_spd.c +++ b/sys/netinet/ip_spd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_spd.c,v 1.79 2015/04/13 16:45:52 mikeb Exp $ */ +/* $OpenBSD: ip_spd.c,v 1.80 2015/04/13 16:48:01 mikeb Exp $ */ /* * The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu) * @@ -400,7 +400,7 @@ ipsp_spd_lookup(struct mbuf *m, int af, int hlen, int *error, int direction, /* Find an appropriate SA from the existing ones. */ ipo->ipo_tdb = - gettdbbyaddr(rdomain, + gettdbbydst(rdomain, dignore ? &sdst : &ipo->ipo_dst, ipo->ipo_sproto, srcid ? srcid : ipo->ipo_srcid, @@ -1063,7 +1063,7 @@ ipsp_spd_inp(struct mbuf *m, int af, int hlen, int *error, int direction, ipsec_update_policy(inp, inp->inp_ipo, af, IPSP_DIRECTION_OUT); - tdb = gettdbbyaddr(rtable_l2(inp->inp_rtableid), + tdb = gettdbbydst(rtable_l2(inp->inp_rtableid), &inp->inp_ipo->ipo_dst, inp->inp_ipo->ipo_sproto, inp->inp_ipo->ipo_srcid, @@ -1080,7 +1080,7 @@ ipsp_spd_inp(struct mbuf *m, int af, int hlen, int *error, int direction, ipsec_update_policy(inp, &sipon, af, IPSP_DIRECTION_OUT); - tdb = gettdbbyaddr(rtable_l2(inp->inp_rtableid), + tdb = gettdbbydst(rtable_l2(inp->inp_rtableid), &sipon.ipo_dst, IPPROTO_ESP, NULL, NULL, NULL, &sipon.ipo_addr, &sipon.ipo_mask); } -- 2.20.1