Hi Aaron, I'll start sending feedback for part of the series, but I'm going through all the patches.
On 18 Nov 2026 at 04:55:50 PM, Aaron Conole <[email protected]> wrote: > Currently, if a conntrack submodule wants to add per-connection > private details, the pattern looks like: > > struct private_conn { > struct conn conn_; > ... private data ... > } > > ... > > new_conn = xalloc(sizeof struct private_conn); > ... > return &new_conn->conn_; > > ... > > struct private_conn *module_conn = (struct private_conn *)conn_; > > This is a common pattern where the underlying allocations are > delegated to the submodule areas, and the main processing module > always assumes that each module allocates a conn_ storage area at the > head of the connection struct anyway. > > However, this means that some storage details can't be shared in a > convenient way between modules without leaking details about the > underlying implementations of the module. For example, TCP based > connections may want to share some TCP block details, but not want to > expose the full private TCP connection module internals. > > To facilitate this, introduce a private storage section into > connection objects. This will allow storing pre-defined details that > each module can fill and guarantee some kind of compatibility without > needing to completely expose the internals. Because this affects how > the conn objects get initialized, add a new init routine and call it > at all the init sites. > > Signed-off-by: Aaron Conole <[email protected]> > --- > lib/conntrack-icmp.c | 1 + > lib/conntrack-other.c | 1 + > lib/conntrack-private.h | 39 ++++++++ > lib/conntrack-tcp.c | 1 + > lib/conntrack.c | 36 +++++++- > lib/conntrack.h | 21 +++++ > tests/library.at | 24 +++++ > tests/test-conntrack.c | 165 +++++++++++++++++++++++++++++++++- > utilities/checkpatch_dict.txt | 5 ++ > 9 files changed, 290 insertions(+), 3 deletions(-) > [...] > --- a/tests/test-conntrack.c > +++ b/tests/test-conntrack.c > @@ -16,6 +16,9 @@ > > #include <config.h> > #include "conntrack.h" > +#include "conntrack-private.h" > + > +#include <errno.h> > > #include "dp-packet.h" > #include "fatal-signal.h" > @@ -496,7 +499,7 @@ test_pcap(struct ovs_cmdl_context *ctx) > ovs_pcap_close(pcap); > } > [...] > + > +/* Register a destructor, commit a real connection, attach a sentinel pointer > + * as private data, then destroy the conntrack instance. After draining the > + * RCU queue (ovsrcu_exit) the destructor must have been called exactly once > + * with the sentinel value. */ > +static void > +test_private_destructor(struct ovs_cmdl_context *ctx OVS_UNUSED) > +{ > + /* Sentinel: a non-NULL pointer value we can identify unambiguously. */ > + void *sentinel = (void *)(uintptr_t) EINVAL; > + > + static ct_private_id_t dtor_id = CT_PRIVATE_ID_INVALID; > + dtor_id = conn_private_id_alloc(record_destructor); > + ovs_assert(dtor_id != CT_PRIVATE_ID_INVALID); > + > + /* Create a conntrack instance and commit one UDP connection. */ > + struct conntrack *lct = conntrack_init(); > + ovs_be16 dl_type; > + struct dp_packet *pkt = build_packet(1, 2, &dl_type); > + struct dp_packet_batch batch; > + dp_packet_batch_init(&batch); > + dp_packet_batch_add(&batch, pkt); > + > + long long now = time_msec(); > + conntrack_execute(lct, &batch, dl_type, false, true, 0, > + NULL, NULL, NULL, NULL, now, 0); > + > + /* After a committed execute the packet carries a cached conn pointer. */ > + struct conn *conn = pkt->md.conn; > + ovs_assert(conn != NULL); > + > + /* Attach the sentinel as private data for our slot. */ > + ovs_mutex_lock(&conn->lock); > + conn_private_set(conn, dtor_id, sentinel); > + ovs_mutex_unlock(&conn->lock); > + > + /* Destroying the tracker flushes all connections, queuing delete_conn() > + * callbacks via ovsrcu_postpone(). The destructor fires once those > + * callbacks are processed. */ > + conntrack_destroy(lct); > + > + /* ovsrcu_exit() stops the urcu background thread and synchronously > drains > + * all pending postponed callbacks (including delete_conn__ / destructor > + * chain) before returning. ovsrcu_synchronize() is insufficient here: > it > + * only waits for threads to quiesce, not for the urcu thread to have > + * actually executed the queued callbacks. */ > + ovsrcu_exit(); > + I guess ovsrcu_barrier() should be enough here, but it doesn't make much difference. Up to you. Other than that: Acked-by: Paolo Valerio <[email protected]> > + ovs_assert(dtor_call_count == 1); > + > + ovs_assert(dtor_last_ptr == sentinel); > + > + dp_packet_delete_batch(&batch, true); > + printf(".\n"); > +} > + > +/* Verify that multiple slots on the same connection are independent: writing > + * to slot A does not clobber slot B and vice versa. */ > +static void > +test_private_multi_slot(struct ovs_cmdl_context *ctx OVS_UNUSED) > +{ > + ct_private_id_t id_a = conn_private_id_alloc(NULL); > + ct_private_id_t id_b = conn_private_id_alloc(NULL); > + ovs_assert(id_a != CT_PRIVATE_ID_INVALID); > + ovs_assert(id_b != CT_PRIVATE_ID_INVALID); > + ovs_assert(id_a != id_b); > + > + struct conntrack *lct = conntrack_init(); > + ovs_be16 dl_type; > + struct dp_packet *pkt = build_packet(1, 2, &dl_type); > + struct dp_packet_batch batch; > + dp_packet_batch_init(&batch); > + dp_packet_batch_add(&batch, pkt); > + > + long long now = time_msec(); > + conntrack_execute(lct, &batch, dl_type, false, true, 0, > + NULL, NULL, NULL, NULL, now, 0); > + > + struct conn *conn = pkt->md.conn; > + ovs_assert(conn != NULL); > + > + void *sentinel_a = (void *) (uintptr_t) 0xAAAAULL; > + void *sentinel_b = (void *) (uintptr_t) 0xBBBBULL; > + > + ovs_mutex_lock(&conn->lock); > + conn_private_set(conn, id_a, sentinel_a); > + conn_private_set(conn, id_b, sentinel_b); > + ovs_assert(conn_private_get(conn, id_a) == sentinel_a); > + ovs_assert(conn_private_get(conn, id_b) == sentinel_b); > + /* Overwrite A and confirm B is unchanged. */ > + conn_private_set(conn, id_a, NULL); > + ovs_assert(conn_private_get(conn, id_a) == NULL); > + ovs_assert(conn_private_get(conn, id_b) == sentinel_b); > + ovs_mutex_unlock(&conn->lock); > + > + conntrack_destroy(lct); > + ovsrcu_exit(); > + dp_packet_delete_batch(&batch, true); > + printf(".\n"); > +} > > static const struct ovs_cmdl_command commands[] = { > /* Connection tracker tests. */ > @@ -601,6 +753,17 @@ static const struct ovs_cmdl_command commands[] = { > * is rewritten to the SNAT target rather than causing a crash. */ > {"ftp-alg-large-payload", "", 0, 0, > test_ftp_alg_large_payload, OVS_RO}, > + /* Private per-connection storage registry tests. > + * Each MUST be run as a separate ovstest invocation so the > process-global > + * slot counter is fresh (starts at 0). */ > + {"private-id-alloc", "", 0, 0, > + test_private_id_alloc, OVS_RO}, > + {"private-id-exhaustion", "", 0, 0, > + test_private_id_exhaustion, OVS_RO}, > + {"private-destructor", "", 0, 0, > + test_private_destructor, OVS_RO}, > + {"private-multi-slot", "", 0, 0, > + test_private_multi_slot, OVS_RO}, > > {NULL, NULL, 0, 0, NULL, OVS_RO}, > }; > diff --git a/utilities/checkpatch_dict.txt b/utilities/checkpatch_dict.txt > index 7b4a346aec..d5e1f3092d 100644 > --- a/utilities/checkpatch_dict.txt > +++ b/utilities/checkpatch_dict.txt > @@ -1,3 +1,4 @@ > +accessors > acl > addresssanitizer > afxdp > @@ -49,6 +50,8 @@ defragment > deref > dereference > dest > +destructor > +destructors > detrace > dhcp > dhcpv4 > @@ -268,6 +271,7 @@ stime > strcasecmp > strcmp > struct > +submodule > subnet > subtable > syscall > @@ -304,6 +308,7 @@ unixctl > untrusted > upcall > upcalls > +urcu > us > usec > userspace > -- > 2.56.1 _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
