On 18 Nov 2026, at 22:55, Aaron Conole wrote:
> Offloading providers will need input port details in order to
> correctly map the packet movement. They will also need the output
> port mapping for the batch, but that will come in the future.
>
> Signed-off-by: Aaron Conole <[email protected]>
Hi Aaron,
See my comment below. You also did not answer my earlier general question how
we would deal with ingress ports changing.
> However, one major thing I am wondering about is how port
> changes are detected and handled. For example, a bond could
> change and now the ingress and/or egress netdev changes.
> We might need an additional API for this.
We should discuss this as part of this series.
//Eelco
> ---
> lib/conntrack.c | 10 +++++-----
> lib/conntrack.h | 5 ++++-
> lib/dpif-netdev.c | 21 ++++++++++++++++++++-
> tests/test-conntrack.c | 20 ++++++++++----------
> 4 files changed, 39 insertions(+), 17 deletions(-)
>
> diff --git a/lib/conntrack.c b/lib/conntrack.c
> index 53fd3114f7..a55ebf7400 100644
> --- a/lib/conntrack.c
> +++ b/lib/conntrack.c
> @@ -1310,7 +1310,7 @@ process_one(struct conntrack *ct, struct dp_packet *pkt,
> bool force, bool commit, long long now, const uint32_t *setmark,
> const struct ovs_key_ct_labels *setlabel,
> const struct nat_action_info_t *nat_action_info,
> - const char *helper, uint32_t tp_id)
> + const char *helper, uint32_t tp_id, struct netdev *in_netdev)
> {
> /* Reset ct_state whenever entering a new zone. */
> if (pkt->md.ct_state && pkt->md.ct_zone != zone) {
> @@ -1385,7 +1385,7 @@ process_one(struct conntrack *ct, struct dp_packet *pkt,
> if (ct_offload_enabled() && conn) {
> struct ct_offload_ctx offload_ctx = {
> .conn = conn,
> - .netdev_in = NULL,
> + .netdev_in = in_netdev,
> .input_port_id = pkt->md.orig_in_port,
> .dir = CT_DIR_FWD,
> };
> @@ -1399,7 +1399,7 @@ process_one(struct conntrack *ct, struct dp_packet *pkt,
> * input port. */
> struct ct_offload_ctx offload_ctx = {
> .conn = conn,
> - .netdev_in = NULL,
> + .netdev_in = in_netdev,
> .input_port_id = pkt->md.orig_in_port,
> .dir = CT_DIR_REV,
> };
> @@ -1437,7 +1437,7 @@ conntrack_execute(struct conntrack *ct, struct
> dp_packet_batch *pkt_batch,
> const struct ovs_key_ct_labels *setlabel,
> const char *helper,
> const struct nat_action_info_t *nat_action_info,
> - long long now, uint32_t tp_id)
> + long long now, uint32_t tp_id, struct netdev *in_netdev)
> {
> odp_port_t in_port = ODPP_LOCAL;
> struct conn_lookup_ctx ctx;
> @@ -1474,7 +1474,7 @@ conntrack_execute(struct conntrack *ct, struct
> dp_packet_batch *pkt_batch,
> write_ct_md(packet, zone, NULL, NULL, NULL);
> } else {
> process_one(ct, packet, &ctx, zone, force, commit, now, setmark,
> - setlabel, nat_action_info, helper, tp_id);
> + setlabel, nat_action_info, helper, tp_id, in_netdev);
> }
> }
>
> diff --git a/lib/conntrack.h b/lib/conntrack.h
> index 2ba6e303a1..9831245914 100644
> --- a/lib/conntrack.h
> +++ b/lib/conntrack.h
> @@ -149,6 +149,8 @@ typedef uint32_t ct_private_id_t;
> * connection carrying this slot is created. */
> ct_private_id_t conn_private_id_alloc(void (*destructor)(void *));
>
> +struct netdev;
> +
> struct conntrack *conntrack_init(void);
> void conntrack_destroy(struct conntrack *);
>
> @@ -158,7 +160,8 @@ int conntrack_execute(struct conntrack *ct, struct
> dp_packet_batch *pkt_batch,
> const struct ovs_key_ct_labels *setlabel,
> const char *helper,
> const struct nat_action_info_t *nat_action_info,
> - long long now, uint32_t tp_id);
> + long long now, uint32_t tp_id,
> + struct netdev *in_netdev);
> void conntrack_clear(struct dp_packet *packet);
>
> struct conntrack_dump {
> diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
> index 446482a67a..7ff97034d3 100644
> --- a/lib/dpif-netdev.c
> +++ b/lib/dpif-netdev.c
> @@ -8378,9 +8378,28 @@ dp_execute_cb(void *aux_, struct dp_packet_batch
> *packets_,
> VLOG_WARN_RL(&rl, "NAT specified without commit.");
> }
>
> + /* Resolve the input netdev via the per-PMD caches, like the
> + * output action: a direct dp_netdev_lookup_port() would race
> + * hmap_expand() on port addition. NULL when unknown to this
> + * PMD; offload providers tolerate it. */
> + struct netdev *in_netdev = NULL;
Can we move this higher, at the case level (its done for other variables).
> + if (!dp_packet_batch_is_empty(packets_)) {
> + odp_port_t query_port =
> + packets_->packets[0]->md.orig_in_port;
> + struct tx_port *tx =
> + pmd_send_port_cache_lookup(pmd, query_port);
> + if (!tx) {
> + tx = pmd_tnl_port_cache_lookup(pmd, query_port);
> + }
> + if (tx) {
> + in_netdev = tx->port->netdev;
> + }
Maybe do it like this, so it's easier to read (also updated the comment):
/* Resolve the input netdev via the PMD caches. Direct
* dp_netdev_lookup_port() could race with hmap_expand() when ports are
* added. The result may be NULL; providers must tolerate that. */
if (!dp_packet_batch_is_empty(packets_)) {
struct tx_port *tx_port;
odp_port_t query_port;
query_port = packets_->packets[0]->md.orig_in_port;
tx_port = pmd_send_port_cache_lookup(pmd, query_port);
if (!tx_port) {
tx_port = pmd_tnl_port_cache_lookup(pmd, query_port);
}
if (tx_port) {
in_netdev = tx_port->port->netdev;
}
}
> + }
> +
> conntrack_execute(dp->conntrack, packets_, aux->flow->dl_type, force,
> commit, zone, setmark, setlabel, helper,
> - nat_action_info_ref, pmd->ctx.now / 1000, tp_id);
> + nat_action_info_ref, pmd->ctx.now / 1000, tp_id,
> + in_netdev);
> break;
> }
>
> diff --git a/tests/test-conntrack.c b/tests/test-conntrack.c
> index 719360d0df..8a2ffb2420 100644
> --- a/tests/test-conntrack.c
> +++ b/tests/test-conntrack.c
> @@ -201,7 +201,7 @@ ct_thread_main(void *aux_)
> ovs_barrier_block(&barrier);
> for (i = 0; i < n_pkts; i += batch_size) {
> conntrack_execute(ct, pkt_batch, dl_type, false, true, 0, NULL, NULL,
> - NULL, NULL, now, 0);
> + NULL, NULL, now, 0, NULL);
> DP_PACKET_BATCH_FOR_EACH (j, pkt, pkt_batch) {
> pkt_metadata_init_conn(&pkt->md);
> }
> @@ -314,7 +314,7 @@ test_benchmark_zones(struct ovs_cmdl_context *ctx)
> for (i = 0; i < n_zones; i++) {
> for (j = 0; j < n_conns; j++) {
> conntrack_execute(ct, pkt_batch[j], dl_type, false, true, i,
> - NULL, NULL, NULL, NULL, now, 0);
> + NULL, NULL, NULL, NULL, now, 0, NULL);
> pkt_metadata_init_conn(&pkt_batch[j]->packets[0]->md);
> }
> }
> @@ -337,7 +337,7 @@ test_benchmark_zones(struct ovs_cmdl_context *ctx)
> stopwatch_start(STOPWATCH_CT_EXECUTE_COMMIT, time_usec());
> for (j = 0; j < n_conns; j++) {
> conntrack_execute(ct, pkt_batch[j], dl_type, false, true, zone,
> - NULL, NULL, NULL, NULL, now, 0);
> + NULL, NULL, NULL, NULL, now, 0, NULL);
> pkt_metadata_init_conn(&pkt_batch[j]->packets[0]->md);
> }
> stopwatch_stop(STOPWATCH_CT_EXECUTE_COMMIT, time_usec());
> @@ -346,7 +346,7 @@ test_benchmark_zones(struct ovs_cmdl_context *ctx)
> stopwatch_start(STOPWATCH_CT_EXECUTE_NO_COMMIT, time_usec());
> for (j = 0; j < n_conns; j++) {
> conntrack_execute(ct, pkt_batch[j], dl_type, false, false, zone,
> - NULL, NULL, NULL, NULL, now, 0);
> + NULL, NULL, NULL, NULL, now, 0, NULL);
> pkt_metadata_init_conn(&pkt_batch[j]->packets[0]->md);
> }
> stopwatch_stop(STOPWATCH_CT_EXECUTE_NO_COMMIT, time_usec());
> @@ -423,7 +423,7 @@ pcap_batch_execute_conntrack(struct conntrack *ct_,
>
> if (flow.dl_type != dl_type) {
> conntrack_execute(ct_, &new_batch, dl_type, false, true, 0,
> - NULL, NULL, NULL, NULL, now, 0);
> + NULL, NULL, NULL, NULL, now, 0, NULL);
> dp_packet_batch_reset(&new_batch);
> }
> dp_packet_batch_add(&new_batch, packet);
> @@ -431,7 +431,7 @@ pcap_batch_execute_conntrack(struct conntrack *ct_,
>
> if (!dp_packet_batch_is_empty(&new_batch)) {
> conntrack_execute(ct_, &new_batch, dl_type, false, true, 0, NULL,
> NULL,
> - NULL, NULL, now, 0);
> + NULL, NULL, now, 0, NULL);
> }
>
> dp_packet_batch_destroy(&new_batch);
> @@ -546,7 +546,7 @@ test_ftp_alg_large_payload(struct ovs_cmdl_context *ctx
> OVS_UNUSED)
> struct dp_packet_batch syn_batch;
> dp_packet_batch_init_packet(&syn_batch, syn);
> conntrack_execute(ct, &syn_batch, htons(ETH_TYPE_IP), false, true, 0,
> - NULL, NULL, "ftp", &nat_info, now, 0);
> + NULL, NULL, "ftp", &nat_info, now, 0, NULL);
> dp_packet_delete_batch(&syn_batch, true);
>
> /* We get to skip some of the processing because the conntrack execute
> @@ -569,7 +569,7 @@ test_ftp_alg_large_payload(struct ovs_cmdl_context *ctx
> OVS_UNUSED)
> struct dp_packet_batch port_batch;
> dp_packet_batch_init_packet(&port_batch, port_pkt);
> conntrack_execute(ct, &port_batch, htons(ETH_TYPE_IP), false, true, 0,
> - NULL, NULL, "ftp", &nat_info, now, 0);
> + NULL, NULL, "ftp", &nat_info, now, 0, NULL);
>
> struct tcp_header *th = dp_packet_l4(port_pkt);
> size_t tcp_hdr_len = TCP_OFFSET(th->tcp_ctl) * 4;
> @@ -653,7 +653,7 @@ test_private_destructor(struct ovs_cmdl_context *ctx
> OVS_UNUSED)
>
> long long now = time_msec();
> conntrack_execute(lct, &batch, dl_type, false, true, 0,
> - NULL, NULL, NULL, NULL, now, 0);
> + NULL, NULL, NULL, NULL, now, 0, NULL);
>
> /* After a committed execute the packet carries a cached conn pointer. */
> struct conn *conn = pkt->md.conn;
> @@ -704,7 +704,7 @@ test_private_multi_slot(struct ovs_cmdl_context *ctx
> OVS_UNUSED)
>
> long long now = time_msec();
> conntrack_execute(lct, &batch, dl_type, false, true, 0,
> - NULL, NULL, NULL, NULL, now, 0);
> + NULL, NULL, NULL, NULL, now, 0, NULL);
>
> struct conn *conn = pkt->md.conn;
> ovs_assert(conn != NULL);
> --
> 2.56.1
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev