From c4d433726abd3713c9e15957d2d4992bf47a97d2 Mon Sep 17 00:00:00 2001 From: tobhe Date: Fri, 3 Dec 2021 19:04:49 +0000 Subject: [PATCH] Add tdb_delete_locked() to replace duplicate tdb deletion code in pfkey_flush(). ok bluhm@ mvs@ --- sys/net/pfkeyv2.c | 16 +++------------- sys/netinet/ip_ipsp.c | 23 ++++++++++++++++++++--- sys/netinet/ip_ipsp.h | 3 ++- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/sys/net/pfkeyv2.c b/sys/net/pfkeyv2.c index aa4c9ed3173..6384162d0e4 100644 --- a/sys/net/pfkeyv2.c +++ b/sys/net/pfkeyv2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfkeyv2.c,v 1.225 2021/12/01 22:34:31 bluhm Exp $ */ +/* $OpenBSD: pfkeyv2.c,v 1.226 2021/12/03 19:04:49 tobhe Exp $ */ /* * @(#)COPYRIGHT 1.1 (NRL) 17 January 1995 @@ -1042,18 +1042,8 @@ int pfkeyv2_sa_flush(struct tdb *tdb, void *satype_vp, int last) { if (!(*((u_int8_t *) satype_vp)) || - tdb->tdb_satype == *((u_int8_t *) satype_vp)) { - /* keep in sync with tdb_delete() */ - NET_ASSERT_LOCKED(); - - if (tdb->tdb_flags & TDBF_DELETED) - return (0); - tdb->tdb_flags |= TDBF_DELETED; - tdb_unlink_locked(tdb); - tdb_unbundle(tdb); - tdb_deltimeouts(tdb); - tdb_unref(tdb); - } + tdb->tdb_satype == *((u_int8_t *) satype_vp)) + tdb_delete_locked(tdb); return (0); } diff --git a/sys/netinet/ip_ipsp.c b/sys/netinet/ip_ipsp.c index c5c228e1828..4789c635473 100644 --- a/sys/netinet/ip_ipsp.c +++ b/sys/netinet/ip_ipsp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_ipsp.c,v 1.260 2021/12/02 12:39:15 bluhm Exp $ */ +/* $OpenBSD: ip_ipsp.c,v 1.261 2021/12/03 19:04:49 tobhe Exp $ */ /* * The authors of this code are John Ioannidis (ji@tla.org), * Angelos D. Keromytis (kermit@csd.uch.gr), @@ -90,6 +90,7 @@ void tdb_firstuse(void *); void tdb_soft_timeout(void *); void tdb_soft_firstuse(void *); int tdb_hash(u_int32_t, union sockaddr_union *, u_int8_t); +void tdb_dodelete(struct tdb *, int locked); int ipsec_in_use = 0; u_int64_t ipsec_last_added = 0; @@ -977,13 +978,29 @@ tdb_unref(struct tdb *tdb) void tdb_delete(struct tdb *tdbp) { - /* keep in sync with pfkeyv2_sa_flush() */ + tdb_dodelete(tdbp, 0); +} + +void +tdb_delete_locked(struct tdb *tdbp) +{ + MUTEX_ASSERT_LOCKED(&tdb_sadb_mtx); + tdb_dodelete(tdbp, 1); +} + +void +tdb_dodelete(struct tdb *tdbp, int locked) +{ NET_ASSERT_LOCKED(); if (tdbp->tdb_flags & TDBF_DELETED) return; tdbp->tdb_flags |= TDBF_DELETED; - tdb_unlink(tdbp); + if (locked) + tdb_unlink_locked(tdbp); + else + tdb_unlink(tdbp); + /* release tdb_onext/tdb_inext references */ tdb_unbundle(tdbp); /* delete timeouts and release references */ diff --git a/sys/netinet/ip_ipsp.h b/sys/netinet/ip_ipsp.h index 70f70ca9e59..06d069fe949 100644 --- a/sys/netinet/ip_ipsp.h +++ b/sys/netinet/ip_ipsp.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ip_ipsp.h,v 1.226 2021/12/01 22:34:31 bluhm Exp $ */ +/* $OpenBSD: ip_ipsp.h,v 1.227 2021/12/03 19:04:49 tobhe Exp $ */ /* * The authors of this code are John Ioannidis (ji@tla.org), * Angelos D. Keromytis (kermit@csd.uch.gr), @@ -569,6 +569,7 @@ struct tdb *gettdbbysrcdst_dir(u_int, u_int32_t, union sockaddr_union *, void puttdb(struct tdb *); void puttdb_locked(struct tdb *); void tdb_delete(struct tdb *); +void tdb_delete_locked(struct tdb *); struct tdb *tdb_alloc(u_int); struct tdb *tdb_ref(struct tdb *); void tdb_unref(struct tdb *); -- 2.20.1