ok mvs@
> On 3 Dec 2021, at 20:25, Tobias Heider <tobias.hei...@stusta.de> wrote:
>
> Hi,
>
> the diff below adds tdb_delete_locked() for use in pfkeyv2_sa_flush().
> This way we won't have to worry about keeping the inline code and
> tdb_delete() in sync.
>
> ok?
>
> Index: net/pfkeyv2.c
> ===================================================================
> RCS file: /cvs/src/sys/net/pfkeyv2.c,v
> retrieving revision 1.225
> diff -u -p -r1.225 pfkeyv2.c
> --- net/pfkeyv2.c 1 Dec 2021 22:34:31 -0000 1.225
> +++ net/pfkeyv2.c 3 Dec 2021 17:19:57 -0000
> @@ -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);
> }
>
> Index: netinet/ip_ipsp.c
> ===================================================================
> RCS file: /cvs/src/sys/netinet/ip_ipsp.c,v
> retrieving revision 1.260
> diff -u -p -r1.260 ip_ipsp.c
> --- netinet/ip_ipsp.c 2 Dec 2021 12:39:15 -0000 1.260
> +++ netinet/ip_ipsp.c 3 Dec 2021 17:19:57 -0000
> @@ -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 */
> Index: netinet/ip_ipsp.h
> ===================================================================
> RCS file: /cvs/src/sys/netinet/ip_ipsp.h,v
> retrieving revision 1.226
> diff -u -p -r1.226 ip_ipsp.h
> --- netinet/ip_ipsp.h 1 Dec 2021 22:34:31 -0000 1.226
> +++ netinet/ip_ipsp.h 3 Dec 2021 17:19:57 -0000
> @@ -569,6 +569,7 @@ struct tdb *gettdbbysrcdst_dir(u_int, u_
> 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 *);
>