git: 9880323a99de - main - netipsec: use SYSINIT(9) instead of dom_init/dom_destroy
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 03 Jan 2022 18:22:55 UTC
The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=9880323a99de1e39a82b75cd91d64f35d36c8559 commit 9880323a99de1e39a82b75cd91d64f35d36c8559 Author: Gleb Smirnoff <glebius@FreeBSD.org> AuthorDate: 2022-01-03 18:15:21 +0000 Commit: Gleb Smirnoff <glebius@FreeBSD.org> CommitDate: 2022-01-03 18:15:21 +0000 netipsec: use SYSINIT(9) instead of dom_init/dom_destroy While here, use just static initializer for key_cb. Differential revision: https://reviews.freebsd.org/D33539 --- sys/netipsec/key.c | 34 ++++++++++++++++++++++++---------- sys/netipsec/key.h | 4 ---- sys/netipsec/keysock.c | 17 ++--------------- 3 files changed, 26 insertions(+), 29 deletions(-) diff --git a/sys/netipsec/key.c b/sys/netipsec/key.c index 168ec3441faf..480879a58aa4 100644 --- a/sys/netipsec/key.c +++ b/sys/netipsec/key.c @@ -8300,8 +8300,9 @@ spdcache_destroy(void) } } #endif -void -key_init(void) + +static void +key_vnet_init(void *arg __unused) { int i; @@ -8327,9 +8328,13 @@ key_init(void) LIST_INIT(&V_acqtree); LIST_INIT(&V_spacqtree); +} +VNET_SYSINIT(key_vnet_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_SECOND, + key_vnet_init, NULL); - if (!IS_DEFAULT_VNET(curvnet)) - return; +static void +key_init(void *arg __unused) +{ ipsec_key_lft_zone = uma_zcreate("IPsec SA lft_c", sizeof(uint64_t) * 2, NULL, NULL, NULL, NULL, @@ -8353,10 +8358,11 @@ key_init(void) if (bootverbose) printf("IPsec: Initialized Security Association Processing.\n"); } +SYSINIT(key_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_FIRST, key_init, NULL); #ifdef VIMAGE -void -key_destroy(void) +static void +key_vnet_destroy(void *arg __unused) { struct secashead_queue sahdrainq; struct secpolicy_queue drainq; @@ -8451,10 +8457,18 @@ key_destroy(void) SPACQ_UNLOCK(); hashdestroy(V_acqaddrhashtbl, M_IPSEC_SAQ, V_acqaddrhash_mask); hashdestroy(V_acqseqhashtbl, M_IPSEC_SAQ, V_acqseqhash_mask); +} +VNET_SYSUNINIT(key_vnet_destroy, SI_SUB_PROTO_DOMAIN, SI_ORDER_SECOND, + key_vnet_destroy, NULL); +#endif - if (!IS_DEFAULT_VNET(curvnet)) - return; - +/* + * XXX: as long as domains are not unloadable, this function is never called, + * provided for consistensy and future unload support. + */ +static void +key_destroy(void *arg __unused) +{ uma_zdestroy(ipsec_key_lft_zone); #ifndef IPSEC_DEBUG2 @@ -8467,7 +8481,7 @@ key_destroy(void) SPACQ_LOCK_DESTROY(); SPI_ALLOC_LOCK_DESTROY(); } -#endif +SYSUNINIT(key_destroy, SI_SUB_PROTO_DOMAIN, SI_ORDER_FIRST, key_destroy, NULL); /* record data transfer on SA, and update timestamps */ void diff --git a/sys/netipsec/key.h b/sys/netipsec/key.h index 2ee7c208f195..4d0f4b1ea512 100644 --- a/sys/netipsec/key.h +++ b/sys/netipsec/key.h @@ -80,10 +80,6 @@ void key_delete_xform(const struct xformsw *); extern u_long key_random(void); extern void key_freereg(struct socket *); extern int key_parse(struct mbuf *, struct socket *); -extern void key_init(void); -#ifdef VIMAGE -extern void key_destroy(void); -#endif extern void key_sa_recordxfer(struct secasvar *, struct mbuf *); uint16_t key_portfromsaddr(struct sockaddr *); void key_porttosaddr(struct sockaddr *, uint16_t port); diff --git a/sys/netipsec/keysock.c b/sys/netipsec/keysock.c index 83ed2bca2f47..1ee1f619b860 100644 --- a/sys/netipsec/keysock.c +++ b/sys/netipsec/keysock.c @@ -71,7 +71,7 @@ struct key_cb { int key_count; int any_count; }; -VNET_DEFINE_STATIC(struct key_cb, key_cb); +VNET_DEFINE_STATIC(struct key_cb, key_cb) = {}; #define V_key_cb VNET(key_cb) static struct sockaddr key_src = { 2, PF_KEY, }; @@ -452,23 +452,10 @@ struct protosw keysw[] = { } }; -static void -key_init0(void) -{ - - bzero((caddr_t)&V_key_cb, sizeof(V_key_cb)); - key_init(); -} - struct domain keydomain = { .dom_family = PF_KEY, .dom_name = "key", - .dom_init = key_init0, -#ifdef VIMAGE - .dom_destroy = key_destroy, -#endif .dom_protosw = keysw, .dom_protoswNPROTOSW = &keysw[nitems(keysw)] }; - -VNET_DOMAIN_SET(key); +DOMAIN_SET(key);