git: 65f264dcf737 - main - ipsec_offload: indirect two more functions on the ipsec.ko module load

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Tue, 30 Jul 2024 15:00:51 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=65f264dcf7374d71781cebf4c7c84bc312e33352

commit 65f264dcf7374d71781cebf4c7c84bc312e33352
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-07-23 07:20:10 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-07-30 14:59:49 +0000

    ipsec_offload: indirect two more functions on the ipsec.ko module load
    
    Specifically, ipsec_accel_on_ifdown() and ipsec_accel_drv_sa_lifetime_update()
    should be present in kernel for future mlx5en driver to be statically
    linkable into the kernel built with IPSEC_HOOKS + IPSEC_OFFLOAD.
    
    Sponsored by:   NVIDIA networking
---
 sys/netipsec/ipsec_offload.c | 16 ++++++++++++----
 sys/netipsec/ipsec_offload.h |  3 +++
 sys/netipsec/key.c           | 27 +++++++++++++++++++++++++++
 3 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/sys/netipsec/ipsec_offload.c b/sys/netipsec/ipsec_offload.c
index 8ccae7a94f2a..984134539d8b 100644
--- a/sys/netipsec/ipsec_offload.c
+++ b/sys/netipsec/ipsec_offload.c
@@ -151,6 +151,9 @@ static void ipsec_accel_sa_recordxfer(struct secasvar *sav, struct mbuf *m);
 static void ipsec_accel_sync_imp(void);
 static bool ipsec_accel_is_accel_sav_impl(struct secasvar *sav);
 static struct mbuf *ipsec_accel_key_setaccelif_impl(struct secasvar *sav);
+static void ipsec_accel_on_ifdown_impl(struct ifnet *ifp);
+static void ipsec_accel_drv_sa_lifetime_update_impl(struct secasvar *sav,
+    if_t ifp, u_int drv_spi, uint64_t octets, uint64_t allocs);
 
 static void
 ipsec_accel_init(void *arg)
@@ -167,6 +170,9 @@ ipsec_accel_init(void *arg)
 	ipsec_accel_sync_p = ipsec_accel_sync_imp;
 	ipsec_accel_is_accel_sav_p = ipsec_accel_is_accel_sav_impl;
 	ipsec_accel_key_setaccelif_p = ipsec_accel_key_setaccelif_impl;
+	ipsec_accel_on_ifdown_p = ipsec_accel_on_ifdown_impl;
+	ipsec_accel_drv_sa_lifetime_update_p =
+	    ipsec_accel_drv_sa_lifetime_update_impl;
 	pctrie_init(&drv_spi_pctrie);
 }
 SYSINIT(ipsec_accel_init, SI_SUB_VNET_DONE, SI_ORDER_ANY,
@@ -183,6 +189,8 @@ ipsec_accel_fini(void *arg)
 	ipsec_accel_sync_p = NULL;
 	ipsec_accel_is_accel_sav_p = NULL;
 	ipsec_accel_key_setaccelif_p = NULL;
+	ipsec_accel_on_ifdown_p = NULL;
+	ipsec_accel_drv_sa_lifetime_update_p = NULL;
 	ipsec_accel_sync_imp();
 	clean_unrhdr(drv_spi_unr);	/* avoid panic, should go later */
 	clear_unrhdr(drv_spi_unr);
@@ -784,8 +792,8 @@ ipsec_accel_on_ifdown_sp(struct ifnet *ifp)
 	free(marker, M_IPSEC_MISC);
 }
 
-void
-ipsec_accel_on_ifdown(struct ifnet *ifp)
+static void
+ipsec_accel_on_ifdown_impl(struct ifnet *ifp)
 {
 	ipsec_accel_on_ifdown_sp(ifp);
 	ipsec_accel_on_ifdown_sav(ifp);
@@ -949,8 +957,8 @@ ipsec_accel_sa_lifetime_update(struct seclifetime *lft_c,
 	lft_c->usetime = min(lft_c->usetime, lft_l->usetime);
 }
 
-void
-ipsec_accel_drv_sa_lifetime_update(struct secasvar *sav, if_t ifp,
+static void
+ipsec_accel_drv_sa_lifetime_update_impl(struct secasvar *sav, if_t ifp,
     u_int drv_spi, uint64_t octets, uint64_t allocs)
 {
 	struct epoch_tracker et;
diff --git a/sys/netipsec/ipsec_offload.h b/sys/netipsec/ipsec_offload.h
index 27b9c938832e..72055a110951 100644
--- a/sys/netipsec/ipsec_offload.h
+++ b/sys/netipsec/ipsec_offload.h
@@ -61,6 +61,9 @@ extern int (*ipsec_accel_sa_lifetime_op_p)(struct secasvar *sav,
 extern void (*ipsec_accel_sync_p)(void);
 extern bool (*ipsec_accel_is_accel_sav_p)(struct secasvar *sav);
 extern struct mbuf *(*ipsec_accel_key_setaccelif_p)(struct secasvar *sav);
+extern void (*ipsec_accel_on_ifdown_p)(struct ifnet *ifp);
+extern void (*ipsec_accel_drv_sa_lifetime_update_p)(struct secasvar *sav,
+    if_t ifp, u_int drv_spi, uint64_t octets, uint64_t allocs);
 
 #ifdef IPSEC_OFFLOAD
 /*
diff --git a/sys/netipsec/key.c b/sys/netipsec/key.c
index 38dd2bc5c1a6..149173e0b5f6 100644
--- a/sys/netipsec/key.c
+++ b/sys/netipsec/key.c
@@ -109,6 +109,9 @@ int (*ipsec_accel_sa_lifetime_op_p)(struct secasvar *sav,
 void (*ipsec_accel_sync_p)(void);
 bool (*ipsec_accel_is_accel_sav_p)(struct secasvar *sav);
 struct mbuf *(*ipsec_accel_key_setaccelif_p)(struct secasvar *sav);
+void (*ipsec_accel_on_ifdown_p)(struct ifnet *ifp);
+void (*ipsec_accel_drv_sa_lifetime_update_p)(struct secasvar *sav, if_t ifp,
+    u_int drv_spi, uint64_t octets, uint64_t allocs);
 #endif
 
 #define FULLMASK	0xff
@@ -8964,3 +8967,27 @@ ipsec_sahtree_rlock(struct rm_priotracker *sahtree_trackerp)
 {
 	rm_rlock(&sahtree_lock, sahtree_trackerp);
 }
+
+#ifdef IPSEC_OFFLOAD
+void
+ipsec_accel_on_ifdown(struct ifnet *ifp)
+{
+	void (*p)(struct ifnet *ifp);
+
+	p = atomic_load_ptr(&ipsec_accel_on_ifdown_p);
+	if (p != NULL)
+		p(ifp);
+}
+
+void
+ipsec_accel_drv_sa_lifetime_update(struct secasvar *sav, if_t ifp,
+    u_int drv_spi, uint64_t octets, uint64_t allocs)
+{
+	void (*p)(struct secasvar *sav, if_t ifp, u_int drv_spi,
+	    uint64_t octets, uint64_t allocs);
+
+	p = atomic_load_ptr(&ipsec_accel_drv_sa_lifetime_update_p);
+	if (p != NULL)
+		p(sav, ifp, drv_spi, octets, allocs);
+}
+#endif