-/* $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),
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;
* 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)
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) &&
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;
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);
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) {
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;
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);
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);
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 {
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);
-/* $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),
* 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;
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,
-/* $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)
*
/* 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,
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,
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);
}