This ties ct offload activation to the hardware offload configuration: the per-packet conn-add and conn-established notifications are gated on ct_offload_enabled(), which delegates to the dpif-offload hw-offload flag. Enabling is one-way at runtime (pre-existing connections are not back-filled).
The ct_sweep expiration path stays ungated: it only expires or extends already-offloaded connections, which is correct regardless of whether offload is currently enabled. Signed-off-by: Aaron Conole <[email protected]> --- lib/conntrack.c | 4 ++-- lib/ct-offload.c | 41 ++++++++++++++++++++++++++++++++--- lib/ct-offload.h | 4 ++++ lib/dpif-offload.c | 14 ++++++++++++ lib/dpif-offload.h | 1 + utilities/checkpatch_dict.txt | 1 + 6 files changed, 60 insertions(+), 5 deletions(-) diff --git a/lib/conntrack.c b/lib/conntrack.c index ccc7764370..53fd3114f7 100644 --- a/lib/conntrack.c +++ b/lib/conntrack.c @@ -1382,7 +1382,7 @@ process_one(struct conntrack *ct, struct dp_packet *pkt, } ovs_mutex_unlock(&ct->ct_lock); - if (conn) { + if (ct_offload_enabled() && conn) { struct ct_offload_ctx offload_ctx = { .conn = conn, .netdev_in = NULL, @@ -1393,7 +1393,7 @@ process_one(struct conntrack *ct, struct dp_packet *pkt, } } - if (!create_new_conn && conn && ctx->reply && + if (ct_offload_enabled() && !create_new_conn && conn && ctx->reply && (pkt->md.ct_state & CS_ESTABLISHED)) { /* EST notify: the reply packet carries the reverse-direction * input port. */ diff --git a/lib/ct-offload.c b/lib/ct-offload.c index d6c73c3452..8c1ac79dca 100644 --- a/lib/ct-offload.c +++ b/lib/ct-offload.c @@ -20,7 +20,9 @@ #include <errno.h> +#include "conntrack.h" #include "conntrack-private.h" +#include "dpif-offload.h" #include "ovs-thread.h" #include "timeval.h" #include "util.h" @@ -30,6 +32,14 @@ VLOG_DEFINE_THIS_MODULE(ct_offload); +/* Built-in CT offload provider classes. Only those whose name matches a + * registered dpif offload class are activated by ct_offload_module_init(), + * tying CT offload to the active hardware offload provider. Populated as + * concrete providers are added in later patches. */ +static const struct ct_offload_class *base_ct_offload_classes[] + OVS_UNUSED = { +}; + /* Private slot for storing per-connection offload state. Allocated when * the first provider class is registered, which must happen before any * connections are created. */ @@ -231,12 +241,37 @@ out: /* ct_offload_module_init() - register built-in CT offload providers. * - * Must be called once before any connections are created. */ + * Only registers providers whose name matches a currently-registered dpif + * offload class, so CT offload is automatically tied to the active + * hardware offload provider. */ void ct_offload_module_init(void) { - /* No built-in providers yet; third parties call ct_offload_register() - * directly from their own module-init routines. */ + size_t n_classes = ARRAY_SIZE(base_ct_offload_classes); + + for (size_t i = 0; i < n_classes; i++) { + const struct ct_offload_class *class = base_ct_offload_classes[i]; + + if (!dpif_offload_class_is_registered(class->name)) { + continue; + } + + int error = ct_offload_register(class); + if (error && error != EEXIST) { + VLOG_WARN("failed to register ct offload class %s: %s", + class->name, ovs_strerror(error)); + } + } +} + +/* ct_offload_enabled() - returns true when hardware offload is active. + * + * Delegates to dpif_offload_enabled() so CT offload shares the same global + * enable/disable knob as datapath hardware offload. */ +bool +ct_offload_enabled(void) +{ + return dpif_offload_enabled(); } /* ct_offload_op_batch_add() - append one operation to 'batch'. diff --git a/lib/ct-offload.h b/lib/ct-offload.h index ac50d9023d..830a39b548 100644 --- a/lib/ct-offload.h +++ b/lib/ct-offload.h @@ -207,6 +207,10 @@ void ct_offload_close(const char *name); * slot used to track offload state. */ void ct_offload_module_init(void); +/* Returns true when CT offload is enabled (delegates to + * dpif_offload_enabled()). */ +bool ct_offload_enabled(void); + /* Offload state of a connection, tracked in a conn-private slot: * tracked (a provider accepted the ADD op) or hw-confirmed (a provider * acknowledged the entry in hardware). Both require conn->lock. */ diff --git a/lib/dpif-offload.c b/lib/dpif-offload.c index 3d9a8a1fc4..fbf252dd25 100644 --- a/lib/dpif-offload.c +++ b/lib/dpif-offload.c @@ -18,6 +18,7 @@ #include <errno.h> #include "dpif-offload.h" +#include "ct-offload.h" #include "dpif-offload-provider.h" #include "dpif-provider.h" #include "netdev-provider.h" @@ -517,6 +518,19 @@ dpif_offload_enabled(void) return enabled; } +/* dpif_offload_class_is_registered() - returns true if a dpif offload class + * with the given name has been successfully registered. */ +bool +dpif_offload_class_is_registered(const char *name) +{ + bool found; + + ovs_mutex_lock(&dpif_offload_mutex); + found = shash_find(&dpif_offload_classes, name) != NULL; + ovs_mutex_unlock(&dpif_offload_mutex); + return found; +} + bool dpif_offload_rebalance_policy_enabled(void) { diff --git a/lib/dpif-offload.h b/lib/dpif-offload.h index b6d3c1f370..a5774d3c13 100644 --- a/lib/dpif-offload.h +++ b/lib/dpif-offload.h @@ -45,6 +45,7 @@ enum dpif_offload_impl_type { void dpif_offload_set_global_cfg(const struct ovsrec_open_vswitch *); bool dpif_offload_enabled(void); bool dpif_offload_rebalance_policy_enabled(void); +bool dpif_offload_class_is_registered(const char *name); /* Per dpif specific functions. */ diff --git a/utilities/checkpatch_dict.txt b/utilities/checkpatch_dict.txt index b7313b807d..fe6365d5f7 100644 --- a/utilities/checkpatch_dict.txt +++ b/utilities/checkpatch_dict.txt @@ -308,6 +308,7 @@ ukey umask unassociated unclosed +ungated unicast unixctl unregister -- 2.56.1 _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
