Introduce and use garbage collector for 'ipsec_ids' struct entities
authormvs <mvs@openbsd.org>
Sun, 18 Jul 2021 18:19:22 +0000 (18:19 +0000)
committermvs <mvs@openbsd.org>
Sun, 18 Jul 2021 18:19:22 +0000 (18:19 +0000)
commit70a5362259ed76e5f2c4a4ea920fe713f2f990e6
treef439500b3ed2ffdce784eeda9793b61acec38f0c
parent95df50b134b92800c9d32b10956d6172a8977767
Introduce and use garbage collector for 'ipsec_ids' struct entities
destruction instead of using per-entity timeout. This fixes the races
between ipsp_ids_insert(), ipsp_ids_free() and ipsp_ids_timeout().

ipsp_ids_insert() can't stop ipsp_ids_timeout() timeout handler which is
already running and awaiting netlock to be released, so reused `ids' will
be silently removed in this case.

ipsp_ids_free() can't determine is ipsp_ids_timeout() timeout handler
running because timeout_del(9) called by ipsp_ids_insert() clears it's
triggered state. So ipsp_ids_timeout() could be scheduled to run twice in
this case.

Also hrvoje@ reported about ipsec(4) throughput increased with this diff
so it seems we caught significant count of ipsp_ids_insert() races.

tests and feedback by hrvoje@
ok bluhm@
sys/netinet/ip_ipsp.c
sys/netinet/ip_ipsp.h