public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
From: Dumitru Ceara <dceara@redhat.com>
To: git-commits@fedoraproject.org
Subject: [rpms/ovn] f45: Pick up all current bug fixes from upstream branch-26.09.
Date: Wed, 18 Nov 2026 12:46:26 GMT	[thread overview]
Message-ID: <179500598668.1.18101018831933534102.rpms-ovn-3f4a162cfb9c@fedoraproject.org> (raw)

            A new commit has been pushed.

            Repo   : rpms/ovn
            Branch : f45
            Commit : 3f4a162cfb9c7049d8cc6a4f63363d06b4fe9e30
            Author : Dumitru Ceara <dceara@redhat.com>
            Date   : 2026-11-18T13:28:51+01:00
            Stats  : +4669/-207 in 2 file(s)
            URL    : https://src.fedoraproject.org/rpms/ovn/c/3f4a162cfb9c7049d8cc6a4f63363d06b4fe9e30?branch=f45

            Log:
            Pick up all current bug fixes from upstream branch-26.09.

Up to and including:
  67b71ad8d2d4 ("northd: Drop redundant hash checks in ECMP id lookups.")

Notable fixes:
  67b71ad8d2 ("northd: Drop redundant hash checks in ECMP id lookups.")
  b22f18080f ("binding: Don't leave claimed ports in the postponed set.")
  9ac049ddd8 ("northd: Make ECMP group and members independent of processing order.")
  e3f2ee4753 ("controller: Set untracked ports down on release.")
  03e31fa2f9 ("northd: Honor lb_force_snat_ip on distributed routers.")
  10f7db3552 ("mac-cache: Fall back to first LRP address for off-subnet next hops.")
  b71a38bb56 ("controller: Drop a dead outport load in multicast groups.")
  3e37b01198 ("pinctrl: Fan out multicast querier queries per port.")
  313266b112 ("northd: Avoid ct_tuple matches for non-fragments.")
  56748e316b ("northd: Do not delete FDB learned on VTEP with empty address.")
  962564dc7b ("northd: Properly cleanup FDB entries.")
  9ac91d1a96 ("northd: Reset tunnel_port and has_unknown during ovn_port cleanup.")
  89696ccc10 ("northd: Allow FDB learning on ports with port security.")
  d05414d990 ("northd: Learn ARP/ND inner MAC addresses in FDB.")
  66b364e5c9 ("statctrl: Batch timestamp updates.")
  7f3de8ec75 ("controller: Serialize chassis index allocation.")
  437e564e74 ("controller: Retry storing chassis index.")
  79754c3e1d ("controller: Destroy temporary chassis index set.")
  a3c2dce537 ("northd: Scope BFD route flows to their logical inport.")
  df5bec1e89 ("pinctrl: Probe new service monitors after their flows are installed.")
  178465da82 ("controller: Add DHCPDISCOVER and DHCPREQUEST logs.")
  449c8767cf ("mac-cache: Prevent underflow when timestamp is in the future.")
  199f88a3e5 ("northd: Mark unbound ports' service monitors offline.")
  2f5bee3ca6 ("northd: Fix abort when a LR and its LRP are deleted in one iteration.")
  baf332dcc1 ("ovn-lib: Use ovn_bindir for ovn-appctl.")
  f7729129c2 ("Revert "northd: Honor lb_force_snat_ip on distributed routers."")
  2410804ab2 ("northd: Honor lb_force_snat_ip on distributed routers.")
  6b71b60871 ("northd: Fix HM reply lflows for type=external backends on localnet LS.")

Signed-off-by: Dumitru Ceara <dceara@redhat.com>

---
diff --git a/ovn.patch b/ovn.patch
index cdbc7ae..91b7114 100644
--- a/ovn.patch
+++ b/ovn.patch
@@ -1,5 +1,160 @@
+diff --git a/.ci/linux-util.sh b/.ci/linux-util.sh
+index 3b98bdfc4e..e2937f3b48 100755
+--- a/.ci/linux-util.sh
++++ b/.ci/linux-util.sh
+@@ -48,6 +48,7 @@ function disable_apparmor()
+     # https://bugs.launchpad.net/ubuntu/+source/apparmor/+bug/2093797
+     sudo aa-teardown || true
+     sudo systemctl disable --now apparmor.service
++    sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
+ }
+ 
+ # XXX This should be removed when the following issue is fixed and the
+@@ -62,3 +63,15 @@ function fixup_crun()
+     sudo chmod +x /usr/bin/crun
+     echo "New crun version: "$(crun --version)
+ }
++
++function sudo_preserve_env()
++{
++    sudo sh -c 'cat > /etc/sudoers.d/ovn-ci-env' << EOF
++# ovn-fake-multinode
++Defaults env_keep += "RUNC_CMD OS_IMAGE CENTRAL_IMAGE CHASSIS_IMAGE RELAY_IMAGE GW_IMAGE ENABLE_SSL"
++# ovn-ci
++Defaults env_keep += "ARCH CC DPDK LIBS OPTS TESTSUITE TEST_RANGE SANITIZERS UNSTABLE BASE_VERSION"
++EOF
++    sudo chmod 0440 /etc/sudoers.d/ovn-ci-env
++    sudo visudo -cf /etc/sudoers.d/ovn-ci-env
++}
+diff --git a/.github/workflows/containers.yml b/.github/workflows/containers.yml
+index 05875bcaf0..42d6027b1e 100644
+--- a/.github/workflows/containers.yml
++++ b/.github/workflows/containers.yml
+@@ -17,7 +17,7 @@ env:
+ jobs:
+   container:
+     if: github.repository_owner == 'ovn-org'
+-    runs-on: ubuntu-24.04
++    runs-on: ubuntu-26.04
+     strategy:
+       matrix:
+         distro: [ fedora, ubuntu ]
+diff --git a/.github/workflows/ovn-fake-multinode-tests.yml b/.github/workflows/ovn-fake-multinode-tests.yml
+index 73d1b22cf6..cf796963b0 100644
+--- a/.github/workflows/ovn-fake-multinode-tests.yml
++++ b/.github/workflows/ovn-fake-multinode-tests.yml
+@@ -14,7 +14,7 @@ jobs:
+   build:
+     name: Build ovn-fake-multinode image
+     if: github.repository_owner == 'ovn-org' || github.event_name != 'schedule'
+-    runs-on: ubuntu-24.04
++    runs-on: ubuntu-26.04
+     strategy:
+       matrix:
+         cfg:
+@@ -24,9 +24,7 @@ jobs:
+       DEPENDENCIES:
+       PREINSTALLED_DEPENDENCIES: podman
+       RUNC_CMD: podman
+-      OS_IMAGE: "fedora:42"
+-      # https://github.com/actions/runner-images/issues/6282
+-      XDG_RUNTIME_DIR: ''
++      OS_IMAGE: "quay.io/fedora/fedora:44"
+     steps:
+     - name: Check out ovn-fake-multi-node
+       uses: actions/checkout@v6
+@@ -83,10 +81,16 @@ jobs:
+         fixup_crun
+       working-directory: ovn-fake-multinode/ovn
+ 
++    - name: Preserve env
++      run: |
++        . .ci/linux-util.sh
++        sudo_preserve_env
++      working-directory: ovn-fake-multinode/ovn
++
+     - name: Build ovn-fake-multi-node ${{ matrix.cfg.branch }} image
+       run: |
+         set -x
+-        sudo -E ./ovn_cluster.sh build
++        sudo ./ovn_cluster.sh build
+         mkdir -p /tmp/_output
+         sudo podman tag ovn/ovn-multi-node:latest ovn/ovn-multi-node:${{ matrix.cfg.branch }}
+         sudo podman save --format oci-archive ovn/ovn-multi-node:${{ matrix.cfg.branch }} > /tmp/_output/ovn_${{ matrix.cfg.branch }}_image.tar
+@@ -98,7 +102,7 @@ jobs:
+         path: /tmp/_output/ovn_${{ matrix.cfg.branch }}_image.tar
+ 
+   multinode-tests:
+-    runs-on: ubuntu-24.04
++    runs-on: ubuntu-26.04
+     timeout-minutes: 60
+     needs: [build]
+     strategy:
+@@ -110,7 +114,7 @@ jobs:
+     name: multinode tests ${{ join(matrix.cfg.*, ' ') }}
+     env:
+       RUNC_CMD: podman
+-      OS_IMAGE: "fedora:42"
++      OS_IMAGE: "quay.io/fedora/fedora:44"
+       CENTRAL_IMAGE: "ovn/ovn-multi-node:${{ matrix.cfg.branch }}"
+       CHASSIS_IMAGE: "ovn/ovn-multi-node:${{ github.ref_name }}"
+       RELAY_IMAGE: "ovn/ovn-multi-node:${{ github.ref_name }}"
+@@ -126,7 +130,6 @@ jobs:
+         openvswitch-switch libunbound-dev libunwind-dev
+       # https://github.com/actions/runner-images/issues/6282
+       PREINSTALLED_DEPENDENCIES: podman
+-      XDG_RUNTIME_DIR: ''
+ 
+     steps:
+     - name: Check out ovn
+@@ -143,7 +146,7 @@ jobs:
+         if [ -n "${{ env.DEPENDENCIES }}" ]; then
+           sudo apt install -y ${{ env.DEPENDENCIES }}
+         fi
+-        sudo apt install -y linux-modules-extra-$(uname -r)
++        sudo apt install -y linux-modules-$(uname -r)
+ 
+     - name: Fix /etc/hosts file
+       run: |
+@@ -160,6 +163,11 @@ jobs:
+         . .ci/linux-util.sh
+         fixup_crun
+ 
++    - name: Preserve env
++      run: |
++        . .ci/linux-util.sh
++        sudo_preserve_env
++
+     - name: Free up disk space
+       run: |
+         . .ci/linux-util.sh
+@@ -197,7 +205,7 @@ jobs:
+ 
+     - name: Start basic cluster
+       run: |
+-        sudo -E CHASSIS_COUNT=4 GW_COUNT=4 ./ovn_cluster.sh start
++        sudo CHASSIS_COUNT=4 GW_COUNT=4 ./ovn_cluster.sh start
+         sudo podman exec -it ovn-central-az1 ovn-nbctl show
+         sudo podman exec -it ovn-central-az1 ovn-appctl -t ovn-northd version
+         sudo podman exec -it ovn-chassis-1 ovn-appctl -t ovn-controller version
+@@ -234,7 +242,7 @@ jobs:
+ 
+     - name: Run fake-multinode system tests
+       run: |
+-        if ! sudo -E make check-multinode TESTSUITEFLAGS="${{ matrix.cfg.testsuiteflags }}"; then
++        if ! sudo make check-multinode TESTSUITEFLAGS="${{ matrix.cfg.testsuiteflags }}"; then
+           sudo podman exec -it ovn-central-az1 ovn-nbctl show || :
+           sudo podman exec -it ovn-central-az1 ovn-sbctl show || :
+           sudo podman exec -it ovn-chassis-1 ovs-vsctl show || :
+@@ -268,5 +276,5 @@ jobs:
+ 
+     - name: Stop cluster
+       run: |
+-        sudo -E ./ovn_cluster.sh stop
++        sudo ./ovn_cluster.sh stop
+       working-directory: ovn-fake-multinode
 diff --git a/.github/workflows/ovn-kubernetes.yml b/.github/workflows/ovn-kubernetes.yml
-index 4254aae98..025514274 100644
+index 4254aae987..7448a1f376 100644
 --- a/.github/workflows/ovn-kubernetes.yml
 +++ b/.github/workflows/ovn-kubernetes.yml
 @@ -13,7 +13,7 @@ concurrency:
@@ -11,6 +166,33 @@ index 4254aae98..025514274 100644
    KIND_CLUSTER_NAME: ovn
    KIND_INSTALL_INGRESS: true
    KIND_ALLOW_SYSTEM_WRITES: true
+@@ -25,7 +25,7 @@ jobs:
+   build:
+     name: Build
+     if: github.repository_owner == 'ovn-org' || github.event_name != 'schedule'
+-    runs-on: ubuntu-24.04
++    runs-on: ubuntu-26.04
+     steps:
+     - name: Enable Docker experimental features
+       run: |
+@@ -69,7 +69,7 @@ jobs:
+ 
+   e2e:
+     name: e2e
+-    runs-on: ubuntu-24.04
++    runs-on: ubuntu-26.04
+     timeout-minutes: 220
+     strategy:
+       fail-fast: false
+@@ -139,7 +139,7 @@ jobs:
+       run: |
+         set -x
+         sudo apt update
+-        sudo apt-get install linux-modules-extra-$(uname -r) -y
++        sudo apt-get install linux-modules-$(uname -r) -y
+         sudo modprobe vrf
+ 
+     - name: Free up disk space
 @@ -165,11 +165,16 @@ jobs:
          cache-dependency-path: "**/*.sum"
        id: go
@@ -29,8 +211,183 @@ index 4254aae98..025514274 100644
  
      - name: Disable ufw
        # For IPv6 and Dualstack, ufw (Uncomplicated Firewall) should be disabled.
+diff --git a/.github/workflows/ovn-upgrade-tests.yml b/.github/workflows/ovn-upgrade-tests.yml
+index e1117ed271..eedf4dd864 100644
+--- a/.github/workflows/ovn-upgrade-tests.yml
++++ b/.github/workflows/ovn-upgrade-tests.yml
+@@ -14,7 +14,7 @@ jobs:
+   upgrade-tests:
+     name: upgrade-test ${{ matrix.cfg.base_version }} ${{ matrix.cfg.test_range }}
+     if: (github.repository_owner == 'ovn-org' && github.event_name == 'schedule' && github.ref_name == 'main') || github.event_name == 'workflow_dispatch'
+-    runs-on: ubuntu-24.04
++    runs-on: ubuntu-26.04
+     timeout-minutes: 120
+ 
+     strategy:
+@@ -42,7 +42,7 @@ jobs:
+     - name: system-level-dependencies
+       run: |
+         sudo apt update
+-        sudo apt -y install linux-modules-extra-$(uname -r)
++        sudo apt -y install linux-modules-$(uname -r)
+ 
+     - name: checkout
+       uses: actions/checkout@v6
+@@ -64,6 +64,11 @@ jobs:
+         . .ci/linux-util.sh
+         fixup_crun
+ 
++    - name: Preserve env
++      run: |
++        . .ci/linux-util.sh
++        sudo_preserve_env
++
+     - name: Download container
+       run: sudo podman pull ghcr.io/ovn-org/ovn-tests:ubuntu
+ 
+@@ -79,7 +84,7 @@ jobs:
+         echo "name=logs-upgrade-test-${BRANCH_NAME}-${{ matrix.cfg.test_range }}" >> $GITHUB_OUTPUT
+ 
+     - name: build
+-      run: sudo -E ./.ci/ci.sh --archive-logs --timeout=2h
++      run: sudo ./.ci/ci.sh --archive-logs --timeout=2h
+ 
+     - name: upload logs on failure
+       if: failure() || cancelled()
+diff --git a/.github/workflows/test-arm.yml b/.github/workflows/test-arm.yml
+index 64bec214f0..ed693713b0 100644
+--- a/.github/workflows/test-arm.yml
++++ b/.github/workflows/test-arm.yml
+@@ -27,7 +27,7 @@ jobs:
+ 
+     name: linux ${{ join(matrix.cfg.*, ' ') }}
+     if: (github.repository_owner == 'ovn-org' && github.event_name == 'schedule' && github.ref_name == 'main') || github.event_name == 'workflow_dispatch'
+-    runs-on: ubuntu-24.04-arm
++    runs-on: ubuntu-26.04-arm
+ 
+     strategy:
+       fail-fast: false
+@@ -74,7 +74,7 @@ jobs:
+       - name: system-level-dependencies
+         if: ${{ startsWith(matrix.cfg.testsuite, 'system-test') }}
+         run: |
+-          sudo apt -y install linux-modules-extra-$(uname -r)
++          sudo apt -y install linux-modules-$(uname -r)
+ 
+       - name: checkout
+         uses: actions/checkout@v6
+@@ -96,6 +96,11 @@ jobs:
+           . .ci/linux-util.sh
+           fixup_crun
+ 
++      - name: Preserve env
++        run: |
++          . .ci/linux-util.sh
++          sudo_preserve_env
++
+       - name: Download container
+         run: |
+           podman pull ghcr.io/ovn-org/ovn-tests:ubuntu
+@@ -108,7 +113,7 @@ jobs:
+ 
+       - name: build
+         if: ${{ startsWith(matrix.cfg.testsuite, 'system-test') }}
+-        run: sudo -E ./.ci/ci.sh --archive-logs --timeout=2h
++        run: sudo ./.ci/ci.sh --archive-logs --timeout=2h
+ 
+       - name: build
+         if: ${{ !startsWith(matrix.cfg.testsuite, 'system-test') }}
+diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
+index f1a2cd1f7c..7f987355d0 100644
+--- a/.github/workflows/test.yml
++++ b/.github/workflows/test.yml
+@@ -27,7 +27,7 @@ jobs:
+       PREINSTALLED_DEPENDENCIES: podman
+     name: Prepare container
+     if: github.repository_owner == 'ovn-org' || github.event_name != 'schedule'
+-    runs-on: ubuntu-24.04
++    runs-on: ubuntu-26.04
+ 
+     steps:
+       - uses: actions/checkout@v6
+@@ -105,7 +105,7 @@ jobs:
+       UNSTABLE:    ${{ matrix.cfg.unstable }}
+ 
+     name: linux ${{ join(matrix.cfg.*, ' ') }}
+-    runs-on: ubuntu-24.04
++    runs-on: ubuntu-26.04
+ 
+     strategy:
+       fail-fast: false
+@@ -142,7 +142,7 @@ jobs:
+       if: ${{ startsWith(matrix.cfg.testsuite, 'system-test') }}
+       run: |
+         sudo apt update
+-        sudo apt -y install linux-modules-extra-$(uname -r)
++        sudo apt -y install linux-modules-$(uname -r)
+ 
+     - name: checkout
+       if: github.event_name == 'push' || github.event_name == 'pull_request'
+@@ -188,6 +188,11 @@ jobs:
+         . .ci/linux-util.sh
+         fixup_crun
+ 
++    - name: Preserve env
++      run: |
++        . .ci/linux-util.sh
++        sudo_preserve_env
++
+     - name: image cache
+       id: image_cache
+       uses: actions/cache@v5
+@@ -203,7 +208,7 @@ jobs:
+ 
+     - name: build
+       if: ${{ startsWith(matrix.cfg.testsuite, 'system-test') }}
+-      run: sudo -E ./.ci/ci.sh --archive-logs --timeout=2h
++      run: sudo ./.ci/ci.sh --archive-logs --timeout=2h
+ 
+     - name: build
+       if: ${{ !startsWith(matrix.cfg.testsuite, 'system-test') }}
+@@ -278,8 +283,8 @@ jobs:
+   build-linux-rpm:
+     name: linux rpm fedora
+     if: github.repository_owner == 'ovn-org' || github.event_name != 'schedule'
+-    runs-on: ubuntu-24.04
+-    container: fedora:42
++    runs-on: ubuntu-26.04
++    container: quay.io/fedora/fedora:44
+     timeout-minutes: 30
+ 
+     strategy:
+diff --git a/.readthedocs.yaml b/.readthedocs.yaml
+index 8c451663a3..9f7b0cbd55 100644
+--- a/.readthedocs.yaml
++++ b/.readthedocs.yaml
+@@ -7,7 +7,7 @@ version: 2
+ 
+ # Set the OS, Python version, etc.
+ build:
+-  os: ubuntu-22.04
++  os: ubuntu-26.04
+   tools:
+     python: "3.12"
+ 
+diff --git a/Documentation/internals/release-process.rst b/Documentation/internals/release-process.rst
+index 03bbb4163b..9b872e3a16 100644
+--- a/Documentation/internals/release-process.rst
++++ b/Documentation/internals/release-process.rst
+@@ -67,7 +67,7 @@ Scheduling`_ for the timing of each stage:
+ 
+    In order to keep the CI stable on the new release branch, the Ubuntu
+    container should be pinned to the current LTS version in the Dockerfile
+-   e.g. registry.hub.docker.com/library/ubuntu:22.04.
++   e.g. registry.hub.docker.com/library/ubuntu:26.04.
+ 
+ 3. When committers come to rough consensus that the release is ready, they
+    release the .0 release on its branch, e.g. 25.09.0 for branch-25.09.  To
 diff --git a/Documentation/ref/ovn-logical-flows.7.rst b/Documentation/ref/ovn-logical-flows.7.rst
-index 9dc670374..16d4539e7 100644
+index 9dc6703749..16d4539e7f 100644
 --- a/Documentation/ref/ovn-logical-flows.7.rst
 +++ b/Documentation/ref/ovn-logical-flows.7.rst
 @@ -124,14 +124,31 @@ Ingress Table 3: Lookup MAC address learning table
@@ -120,7 +477,7 @@ index 9dc670374..16d4539e7 100644
    multicast snooping is enabled on the logical switch.
  
 diff --git a/NEWS b/NEWS
-index 51b46b326..9bdca4b8d 100644
+index 51b46b3264..9bdca4b8da 100644
 --- a/NEWS
 +++ b/NEWS
 @@ -1,3 +1,13 @@
@@ -138,7 +495,7 @@ index 51b46b326..9bdca4b8d 100644
  --------------------------
     - Logical_Router_Port: Added a new "options:dhcpv4_primary_ip" key
 diff --git a/configure.ac b/configure.ac
-index c5a2777e5..660db3269 100644
+index c5a2777e5f..660db32696 100644
 --- a/configure.ac
 +++ b/configure.ac
 @@ -13,7 +13,7 @@
@@ -150,8 +507,110 @@ index c5a2777e5..660db3269 100644
  AC_CONFIG_MACRO_DIR([m4])
  AC_CONFIG_AUX_DIR([build-aux])
  AC_CONFIG_HEADERS([config.h])
+diff --git a/controller-vtep/vtep.c b/controller-vtep/vtep.c
+index 337c6d3c10..dabccd2ed7 100644
+--- a/controller-vtep/vtep.c
++++ b/controller-vtep/vtep.c
+@@ -270,6 +270,26 @@ vtep_lswitch_run(struct shash *vtep_pbs, struct sset *vtep_pswitches,
+     sset_destroy(&used_ls);
+ }
+ 
++static void
++vtep_cache_mmr_ext(struct mmr_hash_node_data **mmr_ext,
++                   const struct vteprec_logical_switch *vtep_ls,
++                   int64_t tnl_key, struct shash *mcast_macs_rmts)
++{
++    if (*mmr_ext) {
++        return;
++    }
++
++    char *mac_tnlkey = xasprintf("%s_%"PRId64, "unknown-dst", tnl_key);
++    *mmr_ext = shash_find_data(mcast_macs_rmts, mac_tnlkey);
++
++    if (*mmr_ext && (*mmr_ext)->mmr->logical_switch == vtep_ls) {
++        /* Delete the entry from the hash table so the mmr does not get
++         * removed from the DB later on during stale checking. */
++        shash_find_and_delete(mcast_macs_rmts, mac_tnlkey);
++    }
++    free(mac_tnlkey);
++}
++
+ /* Updates the vtep 'Ucast_Macs_Remote' and 'Mcast_Macs_Remote' tables based
+  * on non-vtep port bindings. */
+ static void
+@@ -405,19 +425,8 @@ vtep_macs_run(struct ovsdb_idl_txn *vtep_idl_txn, struct shash *ucast_macs_rmts,
+             shash_add(&ls_node->physical_locators, chassis_ip, pl);
+         }
+ 
+-        if (!ls_node->mmr_ext) {
+-            char *mac_tnlkey = xasprintf("%s_%"PRId64, "unknown-dst", tnl_key);
+-            ls_node->mmr_ext = shash_find_data(mcast_macs_rmts, mac_tnlkey);
+-
+-            if (ls_node->mmr_ext &&
+-                ls_node->mmr_ext->mmr->logical_switch == ls_node->vtep_ls) {
+-
+-                /* Delete the entry from the hash table so the mmr does not get
+-                * removed from the DB later on during stale checking. */
+-                shash_find_and_delete(mcast_macs_rmts, mac_tnlkey);
+-            }
+-            free(mac_tnlkey);
+-        }
++        vtep_cache_mmr_ext(&ls_node->mmr_ext, ls_node->vtep_ls, tnl_key,
++                           mcast_macs_rmts);
+ 
+         for (i = 0; i < port_binding_rec->n_mac; i++) {
+             const struct vteprec_ucast_macs_remote *umr;
+@@ -521,6 +530,9 @@ vtep_macs_run(struct ovsdb_idl_txn *vtep_idl_txn, struct shash *ucast_macs_rmts,
+             shash_add(&ls_node->physical_locators, chassis_ip, pl);
+         }
+ 
++        vtep_cache_mmr_ext(&ls_node->mmr_ext, ls_node->vtep_ls, tnl_key,
++                           mcast_macs_rmts);
++
+         char *fdb_dp_port_key =
+             xasprintf("%"PRId64"_%"PRId64,
+                       port_binding_rec->datapath->tunnel_key,
+diff --git a/controller/binding.c b/controller/binding.c
+index c2bce665e7..b3c03a1d31 100644
+--- a/controller/binding.c
++++ b/controller/binding.c
+@@ -1473,6 +1473,7 @@ claim_lport(const struct sbrec_port_binding *pb,
+             register_claim_timestamp(pb->logical_port, now);
+             sset_find_and_delete(postponed_ports, pb->logical_port);
+         } else {
++            sset_find_and_delete(postponed_ports, pb->logical_port);
+             update_tracked = true;
+             if ((pb->n_up && !pb->up[0]) ||
+                 (is_vif && !smap_get_bool(&iface_rec->external_ids,
+@@ -1593,7 +1594,7 @@ release_lport(const struct sbrec_port_binding *pb,
+         VLOG_INFO("Releasing lport %s", pb->logical_port);
+     }
+     update_lport_tracking(pb, tracked_datapaths, false);
+-    if_status_mgr_release_iface(if_mgr, pb->logical_port);
++    if_status_mgr_release_iface(if_mgr, pb);
+     return true;
+ }
+ 
+@@ -2925,7 +2926,7 @@ handle_deleted_lport(const struct sbrec_port_binding *pb,
+          * it is seen as never claimed.
+          */
+         if (if_status_is_port_claimed(b_ctx_out->if_mgr, pb->logical_port)) {
+-            if_status_mgr_release_iface(b_ctx_out->if_mgr, pb->logical_port);
++            if_status_mgr_release_iface(b_ctx_out->if_mgr, pb);
+         }
+         return;
+     }
+@@ -2948,7 +2949,7 @@ handle_deleted_lport(const struct sbrec_port_binding *pb,
+                                           ld);
+         }
+         if (if_status_is_port_claimed(b_ctx_out->if_mgr, pb->logical_port)) {
+-            if_status_mgr_release_iface(b_ctx_out->if_mgr, pb->logical_port);
++            if_status_mgr_release_iface(b_ctx_out->if_mgr, pb);
+         }
+     }
+ }
 diff --git a/controller/chassis.c b/controller/chassis.c
-index 09d15f5ef..b82683064 100644
+index 09d15f5efb..b826830646 100644
 --- a/controller/chassis.c
 +++ b/controller/chassis.c
 @@ -1117,6 +1117,7 @@ store_chassis_index_if_needed(
@@ -173,8 +632,66 @@ index 09d15f5ef..b82683064 100644
      free(idx_key);
  }
  
+diff --git a/controller/if-status.c b/controller/if-status.c
+index 6c6e9b27b1..5d773f9b7d 100644
+--- a/controller/if-status.c
++++ b/controller/if-status.c
+@@ -390,13 +390,23 @@ get_claimed_cr(struct if_status_mgr *mgr)
+ }
+ 
+ void
+-if_status_mgr_release_iface(struct if_status_mgr *mgr, const char *iface_id)
++if_status_mgr_release_iface(struct if_status_mgr *mgr,
++                            const struct sbrec_port_binding *pb)
+ {
+-    struct ovs_iface *iface = shash_find_data(&mgr->ifaces, iface_id);
++    struct ovs_iface *iface = shash_find_data(&mgr->ifaces, pb->logical_port);
+ 
+     if (!iface) {
++        if (!pb->chassis && pb->n_up && pb->up[0]) {
++            /* Unbound but still up, e.g. bound by a previous ovn-controller
++             * instance and never claimed by this one: set it down. */
++            iface = ovs_iface_create(mgr, pb->logical_port, NULL,
++                                     OIF_UPDATE_PORT);
++            iface->pb_uuid = pb->header_.uuid;
++            return;
++        }
+         static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1);
+-        VLOG_WARN_RL(&rl, "Trying to release unknown interface %s", iface_id);
++        VLOG_WARN_RL(&rl, "Trying to release unknown interface %s",
++                     pb->logical_port);
+         return;
+     }
+ 
+@@ -436,9 +446,10 @@ if_status_mgr_delete_iface(struct if_status_mgr *mgr, const char *iface_id,
+         return;
+     }
+ 
+-    if (iface_rec && strcmp(iface->name, iface_rec->name)) {
++    if (iface_rec && (!iface->name || strcmp(iface->name, iface_rec->name))) {
+         VLOG_DBG("Interface %s not deleted as port %s bound to %s",
+-                 iface_rec->name, iface_id, iface->name);
++                 iface_rec->name, iface_id,
++                 iface->name ? iface->name : "no interface");
+         return;
+     }
+ 
+diff --git a/controller/if-status.h b/controller/if-status.h
+index 75c7bf71c7..eaf7127aa0 100644
+--- a/controller/if-status.h
++++ b/controller/if-status.h
+@@ -36,7 +36,8 @@ void if_status_mgr_claim_iface(struct if_status_mgr *,
+                                bool sb_readonly, enum can_bind bind_type,
+                                bool notify_up,
+                                const struct sbrec_port_binding *parent_pb);
+-void if_status_mgr_release_iface(struct if_status_mgr *, const char *iface_id);
++void if_status_mgr_release_iface(struct if_status_mgr *,
++                                 const struct sbrec_port_binding *);
+ void if_status_mgr_delete_iface(struct if_status_mgr *, const char *iface_id,
+                                 const struct ovsrec_interface *iface_rec);
+ 
 diff --git a/controller/mac-cache.c b/controller/mac-cache.c
-index 62a614ca6..b25115f19 100644
+index 62a614ca61..9811f62da6 100644
 --- a/controller/mac-cache.c
 +++ b/controller/mac-cache.c
 @@ -25,6 +25,7 @@
@@ -383,8 +900,30 @@ index 62a614ca6..b25115f19 100644
                      &mb->data, true, threshold, stats->idle_age_ms,
                      since_updated_ms);
              mb->arp_attempts = 0;
+@@ -946,6 +1033,10 @@ mac_binding_probe_stats_run(struct vector *stats_vec, uint64_t *req_delay,
+ 
+         struct in6_addr local = in6addr_any;
+         if (IN6_IS_ADDR_V4MAPPED(&mb->data.ip)) {
++            if (laddr.n_ipv4_addrs) {
++                local = in6_addr_mapped_ipv4(laddr.ipv4_addrs[0].addr);
++            }
++
+             ovs_be32 ip4 = in6_addr_get_mapped_ipv4(&mb->data.ip);
+             for (size_t i = 0; i < laddr.n_ipv4_addrs; i++) {
+                 struct ipv4_netaddr address = laddr.ipv4_addrs[i];
+@@ -955,6 +1046,10 @@ mac_binding_probe_stats_run(struct vector *stats_vec, uint64_t *req_delay,
+                 }
+             }
+         } else {
++            if (laddr.n_ipv6_addrs) {
++                local = laddr.ipv6_addrs[0].addr;
++            }
++
+             for (size_t i = 0; i < laddr.n_ipv6_addrs; i++) {
+                 struct ipv6_netaddr address = laddr.ipv6_addrs[i];
+                 struct in6_addr neigh_prefix =
 diff --git a/controller/mac-cache.h b/controller/mac-cache.h
-index bf9afaf3a..f27998e40 100644
+index bf9afaf3ad..f27998e401 100644
 --- a/controller/mac-cache.h
 +++ b/controller/mac-cache.h
 @@ -29,6 +29,7 @@
@@ -436,7 +975,7 @@ index bf9afaf3a..f27998e40 100644
  
  #endif /* controller/mac-cache.h */
 diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c
-index 103502c18..5154a9be6 100644
+index 103502c189..5154a9be6a 100644
 --- a/controller/ovn-controller.c
 +++ b/controller/ovn-controller.c
 @@ -1073,6 +1073,7 @@ en_ofctrl_is_connected_run(struct engine_node *node OVS_UNUSED, void *data)
@@ -467,8 +1006,115 @@ index 103502c18..5154a9be6 100644
                      stopwatch_stop(OFCTRL_SEQNO_RUN_STOPWATCH_NAME,
                                     time_msec());
                      stopwatch_start(IF_STATUS_MGR_RUN_STOPWATCH_NAME,
+diff --git a/controller/physical.c b/controller/physical.c
+index 8c5d9b9404..01013be48c 100644
+--- a/controller/physical.c
++++ b/controller/physical.c
+@@ -2922,6 +2922,22 @@ mc_ofctrl_add_flow(const struct sbrec_multicast_group *mc,
+     ofpbuf_clear(&ctx->ofpacts);
+ }
+ 
++/* Appends (port_key, ct_zone) to the array of flood_ports. */
++static void
++flood_querier_port_add(struct mcast_querier_port *flood_ports,
++                       size_t *n_flood_ports, uint32_t port_key,
++                       int zone_id)
++{
++    if (!flood_ports) {
++        return;
++    }
++    size_t i = *n_flood_ports;
++
++    flood_ports[i].port_key = port_key;
++    flood_ports[i].ct_zone = zone_id;
++    (*n_flood_ports)++;
++}
++
+ static void
+ consider_mc_group(const struct physical_ctx *ctx,
+                   const struct sbrec_multicast_group *mc,
+@@ -2930,12 +2946,24 @@ consider_mc_group(const struct physical_ctx *ctx,
+     struct local_datapath *ldp = get_local_datapath(ctx->local_datapaths,
+                                                     mc->datapath->tunnel_key);
+     if (!ldp) {
++        /* No local ports: publish an empty list so the querier can
++         * distinguish this from a list that has not been published yet. */
++        if (mc->tunnel_key == OVN_MCAST_FLOOD_TUNNEL_KEY) {
++            pinctrl_mcast_querier_set_ports(mc->datapath->tunnel_key, NULL,
++                                            0);
++        }
+         return;
+     }
+ 
+     struct sset remote_chassis = SSET_INITIALIZER(&remote_chassis);
+     struct sset vtep_chassis = SSET_INITIALIZER(&vtep_chassis);
+ 
++    struct mcast_querier_port *flood_ports = NULL;
++    size_t n_flood_ports = 0;
++    if (mc->tunnel_key == OVN_MCAST_FLOOD_TUNNEL_KEY) {
++        flood_ports = xzalloc(mc->n_ports * sizeof *flood_ports);
++    }
++
+     /* Go through all of the ports in the multicast group:
+      *
+      *    - For remote ports, add the chassis to 'remote_chassis' or
+@@ -3005,14 +3033,14 @@ consider_mc_group(const struct physical_ctx *ctx,
+             if (ldp->is_transit_switch) {
+                 local_set_ct_zone_and_output_pb(port->tunnel_key, zone_id,
+                                                 &local_ctx->ofpacts);
++                flood_querier_port_add(flood_ports, &n_flood_ports,
++                                       port->tunnel_key, zone_id);
+             } else {
+                 local_output_pb(port->tunnel_key, &remote_ctx->ofpacts);
+                 local_output_pb(port->tunnel_key, &ramp_ctx->ofpacts);
+             }
+         } else if (type == LP_REMOTE) {
+             if (port->chassis) {
+-                put_load(port->tunnel_key, MFF_LOG_OUTPORT, 0, 32,
+-                         &remote_ctx->ofpacts);
+                 tunnel_to_chassis(ctx->mff_ovn_geneve, port->chassis->name,
+                                   ctx->chassis_tunnels, mc->datapath,
+                                   port->tunnel_key, &remote_ctx->ofpacts);
+@@ -3026,9 +3054,13 @@ consider_mc_group(const struct physical_ctx *ctx,
+                        || type == LP_L3GATEWAY)) {
+             local_set_ct_zone_and_output_pb(port->tunnel_key, zone_id,
+                                             &local_ctx->ofpacts);
++            flood_querier_port_add(flood_ports, &n_flood_ports,
++                                   port->tunnel_key, zone_id);
+         } else if (simap_contains(ctx->patch_ofports, port->logical_port)) {
+             local_set_ct_zone_and_output_pb(port->tunnel_key, zone_id,
+                                             &local_ctx->ofpacts);
++            flood_querier_port_add(flood_ports, &n_flood_ports,
++                                   port->tunnel_key, zone_id);
+         } else if (type == LP_CHASSISREDIRECT
+                    && port->chassis == ctx->chassis) {
+             const char *distributed_port = smap_get(&port->options,
+@@ -3042,6 +3074,9 @@ consider_mc_group(const struct physical_ctx *ctx,
+                     local_set_ct_zone_and_output_pb(
+                         distributed_binding->tunnel_key, zone_id,
+                         &local_ctx->ofpacts);
++                    flood_querier_port_add(flood_ports, &n_flood_ports,
++                                           distributed_binding->tunnel_key,
++                                           zone_id);
+                 }
+             }
+         } else if (!get_localnet_port(ctx->local_datapaths,
+@@ -3068,6 +3103,13 @@ consider_mc_group(const struct physical_ctx *ctx,
+         }
+     }
+ 
++    /* Publish the local ports of the flood group to the querier. */
++    if (flood_ports) {
++        pinctrl_mcast_querier_set_ports(mc->datapath->tunnel_key, flood_ports,
++                                        n_flood_ports);
++        free(flood_ports);
++    }
++
+     bool local_lports = local_ctx->ofpacts.size > 0;
+     bool remote_ports = remote_ctx->ofpacts.size > 0;
+     bool ramp_ports = ramp_ctx->ofpacts.size > 0;
 diff --git a/controller/pinctrl.c b/controller/pinctrl.c
-index 333dcedb6..10f95b3b2 100644
+index 333dcedb6e..3ca698ab1e 100644
 --- a/controller/pinctrl.c
 +++ b/controller/pinctrl.c
 @@ -30,6 +30,7 @@
@@ -505,7 +1151,372 @@ index 333dcedb6..10f95b3b2 100644
                           "match offer "IP_FMT,
                           IP_ARGS(dhcp_opts.request_ip),
                           IP_ARGS(*offer_ip));
-@@ -7118,6 +7127,8 @@ pinctrl_handle_bind_vport(
+@@ -5424,6 +5433,23 @@ static struct hmap mcast_snoop_map OVS_GUARDED_BY(pinctrl_mutex);
+  */
+ static struct ovs_list mcast_query_list;
+ 
++/*
++ * Local ports of each datapath's multicast flood group, published by
++ * physical_run() (main thread) for the querier (pinctrl_handler thread).
++ *
++ * An entry exists once the datapath's flood group has been considered at
++ * least once and may be empty when the flood group has no local ports on
++ * this chassis.  Both threads access the hmap under pinctrl_mutex.
++ */
++struct mcast_querier_port_list {
++    struct hmap_node hmap_node;
++    uint32_t dp_key;
++    size_t n_ports;
++    struct mcast_querier_port *ports;
++};
++
++static struct hmap mcast_querier_ports OVS_GUARDED_BY(pinctrl_mutex);
++
+ /* Multicast config information stored independently by datapath key.
+  * Protected by pinctrl_mutex. pinctrl_handler has RO access and pinctrl_main
+  * has RW access. Read accesses from pinctrl_ip_mcast_handle() can be
+@@ -5742,6 +5768,7 @@ ip_mcast_snoop_init(void)
+     hmap_init(&mcast_snoop_map);
+     ovs_list_init(&mcast_query_list);
+     hmap_init(&mcast_cfg_map);
++    hmap_init(&mcast_querier_ports);
+ }
+ 
+ static void
+@@ -5760,6 +5787,14 @@ ip_mcast_snoop_destroy(void)
+     HMAP_FOR_EACH_POP (ip_ms_state, hmap_node, &mcast_cfg_map) {
+         free(ip_ms_state);
+     }
++
++    struct mcast_querier_port_list *port_list;
++
++    HMAP_FOR_EACH_POP (port_list, hmap_node, &mcast_querier_ports) {
++        free(port_list->ports);
++        free(port_list);
++    }
++    hmap_destroy(&mcast_querier_ports);
+ }
+ 
+ static void
+@@ -5883,6 +5918,16 @@ ip_mcast_sync(struct ovsdb_idl_txn *ovnsb_idl_txn,
+         }
+     }
+ 
++    /* Remove the querier port lists of datapaths that no longer exist. */
++    struct mcast_querier_port_list *port_list;
++    HMAP_FOR_EACH_SAFE (port_list, hmap_node, &mcast_querier_ports) {
++        if (!get_local_datapath(local_datapaths, port_list->dp_key)) {
++            hmap_remove(&mcast_querier_ports, &port_list->hmap_node);
++            free(port_list->ports);
++            free(port_list);
++        }
++    }
++
+     const struct sbrec_igmp_group *sbrec_ip_mrouter;
+     const struct sbrec_igmp_group *sbrec_igmp;
+ 
+@@ -6192,10 +6237,12 @@ pinctrl_ip_mcast_handle(struct rconn *swconn,
+     }
+ }
+ 
+-static void
+-ip_mcast_querier_send_igmp(struct rconn *swconn, struct ip_mcast_snoop *ip_ms)
++/* Composes an IGMPv3 multicast query into 'buf' (up to 'buf_size' bytes) and
++ * returns its length in bytes. */
++static size_t
++ip_mcast_querier_compose_igmp(struct ip_mcast_snoop *ip_ms, void *buf,
++                              size_t buf_size)
+ {
+-    /* Compose a multicast query. */
+     uint64_t packet_stub[128 / 8];
+     struct dp_packet packet;
+ 
+@@ -6211,35 +6258,25 @@ ip_mcast_querier_send_igmp(struct rconn *swconn, struct ip_mcast_snoop *ip_ms)
+     uint8_t qqic = max_response;
+     packet_set_igmp3_query(&packet, max_response, 0, false, 0, qqic);
+ 
+-    /* Inject multicast query. */
+-    uint64_t ofpacts_stub[4096 / 8];
+-    struct ofpbuf ofpacts = OFPBUF_STUB_INITIALIZER(ofpacts_stub);
+-    enum ofp_version version = rconn_get_version(swconn);
+-    put_load(ip_ms->dp_key, MFF_LOG_DATAPATH, 0, 64, &ofpacts);
+-    put_load(OVN_MCAST_FLOOD_TUNNEL_KEY, MFF_LOG_OUTPORT, 0, 32, &ofpacts);
+-    put_load(1, MFF_LOG_FLAGS, MLF_LOCAL_ONLY, 1, &ofpacts);
+-    struct ofpact_resubmit *resubmit = ofpact_put_RESUBMIT(&ofpacts);
+-    resubmit->in_port = OFPP_CONTROLLER;
+-    resubmit->table_id = OFTABLE_LOCAL_OUTPUT;
+-
+-    struct ofputil_packet_out po = {
+-        .packet = dp_packet_data(&packet),
+-        .packet_len = dp_packet_size(&packet),
+-        .buffer_id = UINT32_MAX,
+-        .ofpacts = ofpacts.data,
+-        .ofpacts_len = ofpacts.size,
+-    };
+-    match_set_in_port(&po.flow_metadata, OFPP_CONTROLLER);
+-    enum ofputil_protocol proto = ofputil_protocol_from_ofp_version(version);
+-    queue_msg(swconn, ofputil_encode_packet_out(&po, proto));
++    size_t size = dp_packet_size(&packet);
++    if (size > buf_size) {
++        static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
++        VLOG_WARN_RL(&rl, "IGMP query (%"PRIuSIZE" bytes) too large for "
++                     "%"PRIuSIZE"-byte buffer", size, buf_size);
++        dp_packet_uninit(&packet);
++        return 0;
++    }
++    memcpy(buf, dp_packet_data(&packet), size);
+     dp_packet_uninit(&packet);
+-    ofpbuf_uninit(&ofpacts);
++    return size;
+ }
+ 
+-static void
+-ip_mcast_querier_send_mld(struct rconn *swconn, struct ip_mcast_snoop *ip_ms)
++/* Composes an MLDv2 multicast query into 'buf' (up to 'buf_size' bytes) and
++ * returns its length in bytes. */
++static size_t
++ip_mcast_querier_compose_mld(struct ip_mcast_snoop *ip_ms, void *buf,
++                             size_t buf_size)
+ {
+-    /* Compose a multicast query. */
+     uint64_t packet_stub[128 / 8];
+     struct dp_packet packet;
+ 
+@@ -6261,31 +6298,132 @@ ip_mcast_querier_send_mld(struct rconn *swconn, struct ip_mcast_snoop *ip_ms)
+     struct in6_addr unspecified = { { { 0 } } };
+     packet_set_mld_query(&packet, max_response, &unspecified, false, 0, qqic);
+ 
+-    /* Inject multicast query. */
+-    uint64_t ofpacts_stub[4096 / 8];
+-    struct ofpbuf ofpacts = OFPBUF_STUB_INITIALIZER(ofpacts_stub);
+-    enum ofp_version version = rconn_get_version(swconn);
+-    put_load(ip_ms->dp_key, MFF_LOG_DATAPATH, 0, 64, &ofpacts);
+-    put_load(OVN_MCAST_FLOOD_TUNNEL_KEY, MFF_LOG_OUTPORT, 0, 32, &ofpacts);
+-    put_load(1, MFF_LOG_FLAGS, MLF_LOCAL_ONLY, 1, &ofpacts);
+-    struct ofpact_resubmit *resubmit = ofpact_put_RESUBMIT(&ofpacts);
+-    resubmit->in_port = OFPP_CONTROLLER;
+-    resubmit->table_id = OFTABLE_LOCAL_OUTPUT;
+-
+-    struct ofputil_packet_out po = {
+-        .packet = dp_packet_data(&packet),
+-        .packet_len = dp_packet_size(&packet),
+-        .buffer_id = UINT32_MAX,
+-        .ofpacts = ofpacts.data,
+-        .ofpacts_len = ofpacts.size,
+-    };
+-    match_set_in_port(&po.flow_metadata, OFPP_CONTROLLER);
+-    enum ofputil_protocol proto = ofputil_protocol_from_ofp_version(version);
+-    queue_msg(swconn, ofputil_encode_packet_out(&po, proto));
++    size_t size = dp_packet_size(&packet);
++    if (size > buf_size) {
++        static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
++        VLOG_WARN_RL(&rl, "MLD query (%"PRIuSIZE" bytes) too large for "
++                     "%"PRIuSIZE"-byte buffer", size, buf_size);
++        dp_packet_uninit(&packet);
++        return 0;
++    }
++    memcpy(buf, dp_packet_data(&packet), size);
+     dp_packet_uninit(&packet);
+-    ofpbuf_uninit(&ofpacts);
++    return size;
++}
++
++/* Number of local ports per querier PACKET_OUT.
++ *
++ * (MCAST_QUERIER_PORT_BATCH) * (resubmits in egress pipeline) must be
++ * less than MAX_RESUBMITS. */
++#define MCAST_QUERIER_PORT_BATCH 100
++
++/* Sends query to each port in ports in batches of at most
++ * MCAST_QUERIER_PORT_BATCH ports per PACKET_OUT. */
++static void
++ip_mcast_querier_send_port_fanout(struct rconn *swconn,
++                                  struct ip_mcast_snoop *ip_ms,
++                                  const void *query, size_t query_len,
++                                  const struct mcast_querier_port *ports,
++                                  size_t n_ports)
++{
++    enum ofputil_protocol proto = ofputil_protocol_from_ofp_version(
++        rconn_get_version(swconn));
++
++    for (size_t start = 0; start < n_ports;
++         start += MCAST_QUERIER_PORT_BATCH) {
++        size_t end = MIN(start + MCAST_QUERIER_PORT_BATCH, n_ports);
++
++        struct ofpbuf ofpacts;
++        ofpbuf_init(&ofpacts, 0);
++        put_load(ip_ms->dp_key, MFF_LOG_DATAPATH, 0, 64, &ofpacts);
++        for (size_t i = start; i < end; i++) {
++            const struct mcast_querier_port *port = &ports[i];
++
++            if (port->ct_zone) {
++                put_load(port->ct_zone, MFF_LOG_CT_ZONE, 0, 16, &ofpacts);
++            }
++            put_load(port->port_key, MFF_LOG_OUTPORT, 0, 32, &ofpacts);
++            struct ofpact_resubmit *resubmit = ofpact_put_RESUBMIT(&ofpacts);
++            resubmit->in_port = OFPP_CONTROLLER;
++            resubmit->table_id = OFTABLE_CHECK_LOOPBACK;
++        }
++
++        struct ofputil_packet_out po = {
++            .packet = query,
++            .packet_len = query_len,
++            .buffer_id = UINT32_MAX,
++            .ofpacts = ofpacts.data,
++            .ofpacts_len = ofpacts.size,
++        };
++        match_set_in_port(&po.flow_metadata, OFPP_CONTROLLER);
++        queue_msg(swconn, ofputil_encode_packet_out(&po, proto));
++        ofpbuf_uninit(&ofpacts);
++    }
+ }
+ 
++/* Returns a copy of the local ports published for datapath dp_key or NULL if
++ * the list has not been published yet or is empty and if the list of local
++ * ports has been published.
++ *
++ * Takes pinctrl_mutex internally. */
++static struct mcast_querier_port *
++ip_mcast_querier_fetch_ports(int64_t dp_key, size_t *n_ports, bool *published)
++{
++    *published = false;
++    ovs_mutex_lock(&pinctrl_mutex);
++
++    size_t n = 0;
++    struct mcast_querier_port *ports = NULL;
++    struct mcast_querier_port_list *list;
++    HMAP_FOR_EACH_WITH_HASH (list, hmap_node, ip_mcast_snoop_hash(dp_key),
++                             &mcast_querier_ports) {
++        if (list->dp_key != dp_key) {
++            continue;
++        }
++        *published = true;
++        n = list->n_ports;
++        if (n) {
++            ports = xmalloc(n * sizeof *ports);
++            memcpy(ports, list->ports, n * sizeof *ports);
++        }
++        break;
++    }
++
++    ovs_mutex_unlock(&pinctrl_mutex);
++
++    *n_ports = n;
++    return ports;
++}
++
++/* Composes and sends the IGMPv3 and MLDv2 queries (if enabled) to the given
++ * local ports. */
++static void
++ip_mcast_querier_send_query(struct rconn *swconn, struct ip_mcast_snoop *ip_ms,
++                            const struct mcast_querier_port *ports,
++                            size_t n_ports)
++{
++    char query_buf[128];
++    if (ip_ms->cfg.querier_v4_enabled) {
++        size_t query_len = ip_mcast_querier_compose_igmp(ip_ms, query_buf,
++                                                         sizeof query_buf);
++        if (query_len) {
++            ip_mcast_querier_send_port_fanout(swconn, ip_ms, query_buf,
++                                              query_len, ports, n_ports);
++        }
++    }
++    if (ip_ms->cfg.querier_v6_enabled) {
++        size_t query_len = ip_mcast_querier_compose_mld(ip_ms, query_buf,
++                                                        sizeof query_buf);
++        if (query_len) {
++            ip_mcast_querier_send_port_fanout(swconn, ip_ms, query_buf,
++                                              query_len, ports, n_ports);
++        }
++    }
++}
++
++/* Retry interval (ms) while the flood group's local ports are unpublished. */
++#define MCAST_QUERIER_INITIAL_RETRY_MS 1000
++
+ static long long int
+ ip_mcast_querier_send(struct rconn *swconn, struct ip_mcast_snoop *ip_ms,
+                       long long int current_time)
+@@ -6294,16 +6432,26 @@ ip_mcast_querier_send(struct rconn *swconn, struct ip_mcast_snoop *ip_ms,
+         return ip_ms->query_time_ms;
+     }
+ 
+-    if (ip_ms->cfg.querier_v4_enabled) {
+-        ip_mcast_querier_send_igmp(swconn, ip_ms);
+-    }
++    size_t n_ports;
++    bool published;
++    struct mcast_querier_port *ports =
++        ip_mcast_querier_fetch_ports(ip_ms->dp_key, &n_ports, &published);
+ 
+-    if (ip_ms->cfg.querier_v6_enabled) {
+-        ip_mcast_querier_send_mld(swconn, ip_ms);
++    /* Retry at a short backoff until the port list is published. */
++    long long int interval_ms =
++        published ? ip_ms->cfg.query_interval_s * 1000
++                  : MCAST_QUERIER_INITIAL_RETRY_MS;
++
++    ip_ms->query_time_ms = current_time + interval_ms;
++
++    /* Skip if the flood group's local ports are unpublished or empty. */
++    if (!ports) {
++        return ip_ms->query_time_ms;
+     }
+ 
+-    /* Set the next query time. */
+-    ip_ms->query_time_ms = current_time + ip_ms->cfg.query_interval_s * 1000;
++    ip_mcast_querier_send_query(swconn, ip_ms, ports, n_ports);
++    free(ports);
++
+     return ip_ms->query_time_ms;
+ }
+ 
+@@ -6337,6 +6485,44 @@ ip_mcast_querier_wait(long long int query_time)
+     }
+ }
+ 
++/* Sets the local ports of the flood group for datapath dp_key.
++ * ports may be NULL to store an empty list which lets the querier
++ * distinguish "no local ports" from "not yet published". */
++void
++pinctrl_mcast_querier_set_ports(int64_t dp_key,
++                                const struct mcast_querier_port *ports,
++                                size_t n_ports)
++{
++    ovs_mutex_lock(&pinctrl_mutex);
++
++    struct mcast_querier_port_list *list = NULL;
++    bool found = false;
++    HMAP_FOR_EACH_WITH_HASH (list, hmap_node, ip_mcast_snoop_hash(dp_key),
++                             &mcast_querier_ports) {
++        if (list->dp_key == dp_key) {
++            found = true;
++            break;
++        }
++    }
++    if (!found) {
++        list = xzalloc(sizeof *list);
++        list->dp_key = dp_key;
++        hmap_insert(&mcast_querier_ports, &list->hmap_node,
++                    ip_mcast_snoop_hash(dp_key));
++    }
++
++    free(list->ports);
++    if (n_ports) {
++        list->ports = xmalloc(n_ports * sizeof *list->ports);
++        memcpy(list->ports, ports, n_ports * sizeof *list->ports);
++    } else {
++        list->ports = NULL;
++    }
++    list->n_ports = n_ports;
++
++    ovs_mutex_unlock(&pinctrl_mutex);
++}
++
+ static void
+ send_garp_rarp_wait(long long int send_garp_rarp_time)
+ {
+@@ -7118,6 +7304,8 @@ pinctrl_handle_bind_vport(
  }
  
  enum svc_monitor_state {
@@ -514,7 +1525,7 @@ index 333dcedb6..10f95b3b2 100644
      SVC_MON_S_INIT,
      SVC_MON_S_WAITING,
      SVC_MON_S_ONLINE,
-@@ -7201,17 +7212,29 @@ struct svc_monitor {
+@@ -7201,17 +7389,29 @@ struct svc_monitor {
      ovs_be16 icmp_id;
      ovs_be16 icmp_seq_no;
  
@@ -544,7 +1555,7 @@ index 333dcedb6..10f95b3b2 100644
  }
  
  static void
-@@ -7425,13 +7448,13 @@ sync_svc_monitors(struct ovsdb_idl_txn *ovnsb_idl_txn,
+@@ -7425,13 +7625,13 @@ sync_svc_monitors(struct ovsdb_idl_txn *ovnsb_idl_txn,
                                             sb_svc_mon->port, protocol, hash);
  
          if (!svc_mon) {
@@ -560,7 +1571,7 @@ index 333dcedb6..10f95b3b2 100644
              svc_mon->status = SVC_MON_ST_UNKNOWN;
              svc_mon->protocol = protocol;
  
-@@ -7498,10 +7521,74 @@ sync_svc_monitors(struct ovsdb_idl_txn *ovnsb_idl_txn,
+@@ -7498,10 +7698,74 @@ sync_svc_monitors(struct ovsdb_idl_txn *ovnsb_idl_txn,
          }
      }
  
@@ -635,7 +1646,7 @@ index 333dcedb6..10f95b3b2 100644
  }
  
  enum bfd_state {
-@@ -8449,6 +8536,10 @@ svc_monitors_run(struct rconn *swconn,
+@@ -8449,6 +8713,10 @@ svc_monitors_run(struct rconn *swconn,
          long long int next_run_time = LLONG_MAX;
          enum svc_monitor_status old_status = svc_mon->status;
          switch (svc_mon->state) {
@@ -646,7 +1657,7 @@ index 333dcedb6..10f95b3b2 100644
          case SVC_MON_S_INIT:
              svc_monitor_send_health_check(swconn, svc_mon);
              next_run_time = svc_mon->wait_time;
-@@ -8531,6 +8622,11 @@ static void
+@@ -8531,6 +8799,11 @@ static void
  pinctrl_handle_icmp_svc_check(struct dp_packet *pkt_in,
                                struct svc_monitor *svc_mon)
  {
@@ -658,7 +1669,7 @@ index 333dcedb6..10f95b3b2 100644
      if (!svc_mon->is_ip6) {
          /* IPv4 ICMP echo reply */
          struct icmp_header *ih = dp_packet_l4(pkt_in);
-@@ -8570,7 +8666,7 @@ pinctrl_handle_tcp_svc_check(struct rconn *swconn,
+@@ -8570,7 +8843,7 @@ pinctrl_handle_tcp_svc_check(struct rconn *swconn,
  {
      struct tcp_header *th = dp_packet_l4(pkt_in);
  
@@ -667,7 +1678,7 @@ index 333dcedb6..10f95b3b2 100644
          return false;
      }
  
-@@ -8814,6 +8910,10 @@ pinctrl_handle_svc_check(struct rconn *swconn, const struct flow *ip_flow,
+@@ -8814,6 +9087,10 @@ pinctrl_handle_svc_check(struct rconn *swconn, const struct flow *ip_flow,
              return;
          }
  
@@ -679,7 +1690,7 @@ index 333dcedb6..10f95b3b2 100644
              static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
              VLOG_WARN_RL(&rl, "handle service check: UDP src port doesn't "
 diff --git a/controller/pinctrl.h b/controller/pinctrl.h
-index 0667ac34e..a638fe29f 100644
+index 0667ac34ee..3e38ebf519 100644
 --- a/controller/pinctrl.h
 +++ b/controller/pinctrl.h
 @@ -63,6 +63,8 @@ void pinctrl_run(struct ovsdb_idl_txn *ovnsb_idl_txn,
@@ -691,8 +1702,30 @@ index 0667ac34e..a638fe29f 100644
  
  void pinctrl_update_swconn(const char *target, int probe_interval);
  
+@@ -84,4 +86,21 @@ void send_self_originated_neigh_packet(struct rconn *swconn,
+                                        struct in6_addr *local,
+                                        struct in6_addr *target,
+                                        uint8_t table_id);
++
++/* A local port that the multicast flood group would deliver a query to, along
++ * with the conntrack zone that the flood group's per-port action loads. */
++struct mcast_querier_port {
++    uint32_t port_key;
++    uint16_t ct_zone;
++};
++
++/* Records the local ports of the flood group for datapath 'dp_key', so the
++ * querier can send its query to each port directly rather than through the
++ * flood group.  'ports' may be NULL to record an empty list.
++ *
++ * Called from the main thread; read by the handler thread.
++ * Takes pinctrl_mutex internally. */
++void pinctrl_mcast_querier_set_ports(int64_t dp_key,
++                                     const struct mcast_querier_port *ports,
++                                     size_t n_ports);
+ #endif /* controller/pinctrl.h */
 diff --git a/controller/statctrl.c b/controller/statctrl.c
-index 00c0a4450..77453319c 100644
+index 00c0a44503..77453319c1 100644
 --- a/controller/statctrl.c
 +++ b/controller/statctrl.c
 @@ -35,10 +35,13 @@
@@ -863,8 +1896,32 @@ index 00c0a4450..77453319c 100644
      }
  }
  
+diff --git a/controller/vif-plug.c b/controller/vif-plug.c
+index 8a463f6e1a..5a1c056c8c 100644
+--- a/controller/vif-plug.c
++++ b/controller/vif-plug.c
+@@ -438,6 +438,9 @@ consider_plug_lport(const struct sbrec_port_binding *pb,
+                                        vif_plug_ctx_in)) {
+                 return false;
+             }
++            if (!vif_plug_port_ctx) {
++                return true;
++            }
+ 
+             ret = consider_plug_lport_update__(vif_plug, &iface_external_ids,
+                                                pb, lbinding->iface,
+@@ -450,6 +453,9 @@ consider_plug_lport(const struct sbrec_port_binding *pb,
+                                        vif_plug_ctx_in)) {
+                 return false;
+             }
++            if (!vif_plug_port_ctx) {
++                return true;
++            }
+ 
+             const struct ovsrec_interface *iface_rec =
+                 iface_lookup_by_name(vif_plug_ctx_in->ovsrec_interface_by_name,
 diff --git a/debian/changelog b/debian/changelog
-index f54becec4..8d68b4fdd 100644
+index f54becec42..8d68b4fdd5 100644
 --- a/debian/changelog
 +++ b/debian/changelog
 @@ -1,3 +1,9 @@
@@ -877,79 +1934,663 @@ index f54becec4..8d68b4fdd 100644
  ovn (26.09.0-1) unstable; urgency=low
  
     * New upstream version
-diff --git a/dummy_file b/dummy_file
-new file mode 100644
-index 000000000..d7888b7ad
---- /dev/null
-+++ b/dummy_file
-@@ -0,0 +1 @@
-+2026-10-03 00:02:51.442074
-\ No newline at end of file
-diff --git a/northd/northd.c b/northd/northd.c
-index f523234b3..0538bc69a 100644
---- a/northd/northd.c
-+++ b/northd/northd.c
-@@ -142,6 +142,7 @@ static bool vxlan_mode;
- #define REGBIT_IP_FRAG            "reg0[19]"
- #define REGBIT_ACL_PERSIST_ID     "reg0[20]"
- #define REGBIT_ACL_HINT_ALLOW_PERSISTED "reg0[21]"
-+#define REGBIT_LKUP_FDB_DL_INNER  "reg0[22]"
- 
- /* Register definitions for switches and routers. */
+diff --git a/lib/vif-plug-providers/dummy/vif-plug-dummy.c b/lib/vif-plug-providers/dummy/vif-plug-dummy.c
+index bc8953e980..29acbc0e1d 100644
+--- a/lib/vif-plug-providers/dummy/vif-plug-dummy.c
++++ b/lib/vif-plug-providers/dummy/vif-plug-dummy.c
+@@ -70,6 +70,12 @@ vif_plug_dummy_port_prepare(const struct vif_plug_port_ctx_in *ctx_in,
+     VLOG_DBG("vif_plug_dummy_port_prepare: %s", ctx_in->lport_name);
+ 
+     if (ctx_in->op_type == PLUG_OP_CREATE) {
++        if (smap_get_bool(&ctx_in->lport_options,
++                          "vif-plug-dummy-return-false", false)) {
++            VLOG_DBG("vif_plug_dummy_port_prepare: %s - returning false as "
++                     "requested", ctx_in->lport_name);
++            return false;
++        }
+         size_t lport_name_len = strlen(ctx_in->lport_name);
+         ctx_out->name = xzalloc(IFNAMSIZ);
+         memcpy(ctx_out->name, ctx_in->lport_name,
+diff --git a/northd/en-group-ecmp-route.c b/northd/en-group-ecmp-route.c
+index aca1973189..01cca26125 100644
+--- a/northd/en-group-ecmp-route.c
++++ b/northd/en-group-ecmp-route.c
+@@ -24,6 +24,7 @@
+ #include "en-advertised-route-sync.h"
+ #include "en-group-ecmp-route.h"
+ #include "en-learned-route-sync.h"
++#include "hash.h"
+ #include "hmapx.h"
+ #include "openvswitch/hmap.h"
  
-@@ -1174,8 +1175,6 @@ ovn_port_cleanup(struct ovn_port *port)
-         port->peer->peer = NULL;
-     }
+@@ -182,22 +183,26 @@ unique_routes_destroy(struct hmap *unique_routes)
+     hmap_destroy(unique_routes);
+ }
  
--    port->lsp_has_port_sec = false;
+-/* Allow LB and NAT forwarding routes for the same prefix to coexist as
++/* Routes for the same prefix share an ecmp group if their sources map to the
++ * same class.
++ *
++ * LB and NAT forwarding routes are in the same class so that they coexist as
+  * ECMP members instead of one silently replacing the other.  This is an
+  * edge case: it arises only when two different peer LRs independently
+  * use the same IP as a VIP and a NAT external IP, and a CMS would
+  * typically prevent such overlap.  Without this guard, one route
+  * would silently win and traffic to the other service would be
+  * black-holed. */
++static enum route_source
++ecmp_group_source_class(enum route_source source)
++{
++    return source == ROUTE_SOURCE_LB ? ROUTE_SOURCE_NAT : source;
++}
++
+ static bool
+ route_sources_ecmp_compatible(enum route_source a, enum route_source b)
+ {
+-    if (a == b) {
+-        return true;
+-    }
 -
-     destroy_lport_addresses(&port->lrp_networks);
-     destroy_lport_addresses(&port->proxy_arp_addrs);
+-    return (a == ROUTE_SOURCE_NAT || a == ROUTE_SOURCE_LB) &&
+-           (b == ROUTE_SOURCE_NAT || b == ROUTE_SOURCE_LB);
++    return ecmp_group_source_class(a) == ecmp_group_source_class(b);
  }
-@@ -1568,16 +1567,6 @@ parse_lsp_addrs(struct ovn_port *op)
-     if (lsp_is_switch(nbsp)) {
-         op->has_unknown = true;
+ 
+ /* Remove the unique_routes_node from the group, and return the parsed_route
+@@ -228,14 +233,12 @@ ecmp_groups_add_route(struct ecmp_groups_node *group,
+                       const struct parsed_route *route)
+ {
+     static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1);
+-    if (group->route_count == UINT16_MAX) {
++    if (vector_len(&group->route_list) == UINT16_MAX) {
+         VLOG_WARN_RL(&rl, "too many routes in a single ecmp group.");
+         return;
      }
+ 
+     if (route->is_discard_route) {
+-        group->has_discard_route = true;
 -
--    struct eth_addr mac;
--    for (size_t j = 0; j < nbsp->n_port_security; j++) {
--        int n = !strncmp(nbsp->port_security[j], "VRRPv3", 6) ? 7 : 0;
--        if (ovs_scan_len(nbsp->port_security[j], &n, ETH_ADDR_SCAN_FMT,
--                         ETH_ADDR_SCAN_ARGS(mac))) {
--            op->lsp_has_port_sec = true;
--            break;
--        }
+         char *prefix = normalize_v46_prefix(&route->prefix, route->plen);
+         VLOG_WARN_RL(&rl, "The ECMP route \"%s\" contains \"discard\" "
+                      "route, the whole group will drop traffic.", prefix);
+@@ -244,22 +247,13 @@ ecmp_groups_add_route(struct ecmp_groups_node *group,
+ 
+     struct ecmp_route_list_node er = (struct ecmp_route_list_node) {
+         .route = route,
+-        .id = ++group->route_count,
+     };
+ 
+-    if (group->route_count == 1) {
+-        sset_clone(&group->selection_fields, &route->ecmp_selection_fields);
+-    } else {
+-        sset_intersect(&group->selection_fields,
+-                       &route->ecmp_selection_fields);
 -    }
+-
+     vector_push(&group->route_list, &er);
  }
  
- static void
-@@ -1674,7 +1663,7 @@ join_logical_ports_lsp(struct hmap *ports,
- 
-             /* This port exists due to a SB binding, but should
-              * not have been initialized fully. */
--            ovs_assert(!op->n_lsp_addrs && !op->lsp_has_port_sec);
-+            ovs_assert(!op->n_lsp_addrs);
-         }
-     } else {
-         op = ovn_port_create(ports, name, nbsp, NULL, NULL);
-@@ -3522,19 +3511,22 @@ ovn_lb_svc_create(struct ovsdb_idl_txn *ovnsb_txn,
-                     backend_nb->svc_mon_src_ip);
-             }
- 
-+            /* Unbound ports are not probed by any chassis: fail closed. */
-             if (!backend_nb->remote_backend &&
--                (!op->sb->n_up || !op->sb->up[0])
-+                (!op->sb->chassis || !op->sb->n_up || !op->sb->up[0])
-                 && mon_info->sbrec_mon->status
-                 && !strcmp(mon_info->sbrec_mon->status, "online")) {
-                 sbrec_service_monitor_set_status(mon_info->sbrec_mon,
-                                                  "offline");
-             }
+-/* Removes a route from an ecmp group. If the ecmp group should persist
+- * afterwards you must call ecmp_groups_update_ids before any further
+- * insertions. */
++/* Removes a route from an ecmp group.  The ids of the group and of its
++ * members are refreshed by group_ecmp_datapath_finalize(). */
+ static const struct parsed_route *
+ ecmp_groups_remove_route(struct ecmp_groups_node *group,
+                          const struct parsed_route *pr)
+@@ -278,15 +272,280 @@ ecmp_groups_remove_route(struct ecmp_groups_node *group,
+     return NULL;
+ }
  
--            if (!backend_nb->remote_backend && op->sb->chassis &&
--                strcmp(mon_info->sbrec_mon->chassis_name,
--                       op->sb->chassis->name)) {
--                sbrec_service_monitor_set_chassis_name(mon_info->sbrec_mon,
++/* Hashes the key of 'eg', which is unique within a datapath.  It must cover
++ * the fields that ecmp_groups_find() compares.  Unlike the members, the key
++ * does not change when routes are added to or removed from the group. */
++static uint32_t
++ecmp_group_hash(const struct ecmp_groups_node *eg)
++{
++    uint32_t hash = hash_bytes(&eg->prefix, sizeof eg->prefix, 0);
++    hash = hash_add(hash, eg->plen);
++    hash = hash_add(hash, eg->route_table_id);
++    hash = hash_add(hash, eg->is_src_route);
++    hash = hash_add(hash, ecmp_group_source_class(eg->source));
++    return hash_finish(hash, 0);
++}
++
++/* Hashes what makes 'route' unique within its ecmp group.  A NAT or LB row
++ * produces one route per path to the peer router, so its UUID alone is not
++ * enough. */
++static uint32_t
++ecmp_member_hash(const struct parsed_route *route)
++{
++    const struct uuid *uuid = &route->source_hint->uuid;
++    uint32_t hash = hash_bytes(uuid, sizeof *uuid, 0);
++    if (route->nexthop) {
++        hash = hash_bytes(route->nexthop, sizeof *route->nexthop, hash);
++    }
++    if (route->out_port) {
++        hash = hash_string(route->out_port->key, hash);
++    }
++    return hash;
++}
++
++/* Number of rounds after which ecmp_assign_ids() stops retrying hashes that
++ * collide and falls back to the next free id. */
++#define ECMP_ID_MAX_ROUNDS 32
++
++struct ecmp_id_slot {
++    struct hmap_node hmap_node; /* In 'slots', hashed by 'id'. */
++    uint16_t id;
++    bool taken;         /* Assigned to an element. */
++    size_t n_claims;    /* Elements that derived 'id' in the current round. */
++};
++
++static struct ecmp_id_slot *
++ecmp_id_slot_get(struct hmap *slots, uint16_t id)
++{
++    /* The id is the hash itself, so any node with that hash is its slot. */
++    struct hmap_node *node = hmap_first_with_hash(slots, id);
++    if (node) {
++        return CONTAINER_OF(node, struct ecmp_id_slot, hmap_node);
++    }
++
++    struct ecmp_id_slot *slot = xzalloc(sizeof *slot);
++    slot->id = id;
++    hmap_insert(slots, &slot->hmap_node, id);
++    return slot;
++}
++
++struct ecmp_hash_count {
++    struct hmap_node hmap_node; /* In 'counts', hashed by the counted hash. */
++    size_t n;
++};
++
++static struct ecmp_hash_count *
++ecmp_hash_count_get(struct hmap *counts, uint32_t hash)
++{
++    /* The counted hash is used as the hmap hash, so any node with that hash
++     * is its count. */
++    struct hmap_node *node = hmap_first_with_hash(counts, hash);
++    if (node) {
++        return CONTAINER_OF(node, struct ecmp_hash_count, hmap_node);
++    }
++
++    struct ecmp_hash_count *count = xzalloc(sizeof *count);
++    hmap_insert(counts, &count->hmap_node, hash);
++    return count;
++}
++
++/* Sets 'same_hash[i]' for each of the 'n_elements' elements that has no id
++ * yet and shares its hash with another such element. */
+ static void
+-ecmp_group_update_ids(struct ecmp_groups_node *group)
++ecmp_find_same_hash(const uint32_t *hashes, const uint16_t *ids,
++                    bool *same_hash, size_t n_elements)
+ {
++    struct hmap counts = HMAP_INITIALIZER(&counts);
++    struct ecmp_hash_count *count;
++
++    for (size_t i = 0; i < n_elements; i++) {
++        if (!ids[i]) {
++            ecmp_hash_count_get(&counts, hashes[i])->n++;
++        }
++    }
++    for (size_t i = 0; i < n_elements; i++) {
++        if (!ids[i]) {
++            same_hash[i] = ecmp_hash_count_get(&counts, hashes[i])->n > 1;
++        }
++    }
++    HMAP_FOR_EACH_POP (count, hmap_node, &counts) {
++        free(count);
++    }
++    hmap_destroy(&counts);
++}
++
++static uint16_t
++ecmp_id_from_hash(uint32_t hash, size_t round)
++{
++    return hash_int(round, hash) % UINT16_MAX + 1;
++}
++
++/* Gives each of the 'n_elements' elements a distinct id in [1, UINT16_MAX]
++ * derived from 'hashes', so that the id of an element does not depend on the
++ * order in which the elements are passed, nor on the ids of unrelated
++ * elements.
++ *
++ * An element keeps the id derived from its hash unless that id is already
++ * taken or another element derives the same id in the same round.  In that
++ * case all of them retry in the next round, with an id derived from their
++ * hash and the round number.  The result therefore only depends on the set
++ * of hashes.
++ *
++ * Elements whose hashes are equal derive the same id in every round, so they
++ * can't be told apart.  They don't retry and, like elements that still
++ * collide after ECMP_ID_MAX_ROUNDS rounds, take the next free id in the
++ * order they are passed. */
++static void
++ecmp_assign_ids(const uint32_t *hashes, uint16_t *ids, size_t n_elements)
++{
++    struct hmap slots = HMAP_INITIALIZER(&slots);
++    /* The slot that each element claims in the current round. */
++    struct ecmp_id_slot **claims = xmalloc(n_elements * sizeof *claims);
++    /* Whether another element has the same hash. */
++    bool *same_hash = xzalloc(n_elements * sizeof *same_hash);
++    struct ecmp_id_slot *slot;
++    size_t n_unassigned = n_elements;
++    size_t n_retrying = n_elements;
++
++    memset(ids, 0, n_elements * sizeof *ids);
++    for (size_t round = 0; n_retrying && round < ECMP_ID_MAX_ROUNDS;
++         round++) {
++        for (size_t i = 0; i < n_elements; i++) {
++            if (!ids[i] && !same_hash[i]) {
++                uint16_t id = ecmp_id_from_hash(hashes[i], round);
++                claims[i] = ecmp_id_slot_get(&slots, id);
++                claims[i]->n_claims++;
++            }
++        }
++        for (size_t i = 0; i < n_elements; i++) {
++            if (!ids[i] && !same_hash[i]) {
++                slot = claims[i];
++                if (!slot->taken && slot->n_claims == 1) {
++                    slot->taken = true;
++                    ids[i] = slot->id;
++                    n_unassigned--;
++                    n_retrying--;
++                }
++            }
++        }
++        HMAP_FOR_EACH (slot, hmap_node, &slots) {
++            slot->n_claims = 0;
++        }
++
++        if (!round && n_unassigned) {
++            /* Elements with the same hash always claim the same id, so none
++             * of them got one in this round. */
++            ecmp_find_same_hash(hashes, ids, same_hash, n_elements);
++            for (size_t i = 0; i < n_elements; i++) {
++                n_retrying -= same_hash[i];
++            }
++        }
++    }
++    free(claims);
++    free(same_hash);
++
++    for (size_t i = 0; n_unassigned && i < n_elements; i++) {
++        if (ids[i]) {
++            continue;
++        }
++        uint16_t id = ecmp_id_from_hash(hashes[i], 0);
++        while ((slot = ecmp_id_slot_get(&slots, id))->taken) {
++            id = id % UINT16_MAX + 1;
++        }
++        slot->taken = true;
++        ids[i] = id;
++        n_unassigned--;
++    }
++
++    HMAP_FOR_EACH_POP (slot, hmap_node, &slots) {
++        free(slot);
++    }
++    hmap_destroy(&slots);
++}
++
++static int
++ecmp_route_list_node_id_cmp(const void *a_, const void *b_)
++{
++    const struct ecmp_route_list_node *a = a_;
++    const struct ecmp_route_list_node *b = b_;
++
++    return a->id < b->id ? -1 : a->id > b->id;
++}
++
++/* Recomputes everything in 'group' that is derived from its members, so that
++ * the result only depends on the set of members. */
++static void
++ecmp_group_finalize(struct ecmp_groups_node *group)
++{
++    size_t n_members = vector_len(&group->route_list);
++    uint32_t *hashes = xmalloc(n_members * sizeof *hashes);
++    uint16_t *ids = xmalloc(n_members * sizeof *ids);
+     struct ecmp_route_list_node *er;
+     size_t i = 0;
++
+     VECTOR_FOR_EACH_PTR (&group->route_list, er) {
+-        er->id = i++;
++        hashes[i++] = ecmp_member_hash(er->route);
++    }
++    ecmp_assign_ids(hashes, ids, n_members);
++    i = 0;
++    VECTOR_FOR_EACH_PTR (&group->route_list, er) {
++        er->id = ids[i++];
++    }
++    free(hashes);
++    free(ids);
++
++    /* The members are listed in this order in the select() action. */
++    vector_qsort(&group->route_list, ecmp_route_list_node_id_cmp);
++
++    bool first = true;
++    group->has_discard_route = false;
++    VECTOR_FOR_EACH_PTR (&group->route_list, er) {
++        if (er->route->is_discard_route) {
++            group->has_discard_route = true;
++        }
++        if (first) {
++            sset_destroy(&group->selection_fields);
++            sset_clone(&group->selection_fields,
++                       &er->route->ecmp_selection_fields);
++            group->source = er->route->source;
++            first = false;
++        } else {
++            sset_intersect(&group->selection_fields,
++                           &er->route->ecmp_selection_fields);
++        }
+     }
+-    group->route_count = i;
++}
++
++/* Assigns the group and member ids of all ecmp groups of 'gn'.  Must be
++ * called after the ecmp groups of 'gn' changed, both on full recompute and on
++ * incremental processing, so that both yield the same ids for the same set
++ * of routes and the generated logical flows do not change on recompute. */
++static void
++group_ecmp_datapath_finalize(struct group_ecmp_datapath *gn)
++{
++    size_t n_groups = hmap_count(&gn->ecmp_groups);
++    if (!n_groups) {
++        return;
++    }
++
++    struct ecmp_groups_node **groups = xmalloc(n_groups * sizeof *groups);
++    uint32_t *hashes = xmalloc(n_groups * sizeof *hashes);
++    uint16_t *ids = xmalloc(n_groups * sizeof *ids);
++    struct ecmp_groups_node *eg;
++    size_t i = 0;
++
++    HMAP_FOR_EACH (eg, hmap_node, &gn->ecmp_groups) {
++        ecmp_group_finalize(eg);
++        groups[i] = eg;
++        hashes[i++] = ecmp_group_hash(eg);
++    }
++    ecmp_assign_ids(hashes, ids, n_groups);
++    for (i = 0; i < n_groups; i++) {
++        groups[i]->id = ids[i];
++    }
++    free(groups);
++    free(hashes);
++    free(ids);
+ }
+ 
+ static struct ecmp_groups_node *
+@@ -302,7 +561,6 @@ ecmp_groups_add(struct group_ecmp_datapath *gn,
+     struct ecmp_groups_node *eg = xzalloc(sizeof *eg);
+     hmap_insert(&gn->ecmp_groups, &eg->hmap_node, route->hash);
+ 
+-    eg->id = hmap_count(&gn->ecmp_groups);
+     eg->prefix = route->prefix;
+     eg->plen = route->plen;
+     eg->is_src_route = route->is_src_route;
+@@ -321,6 +579,7 @@ ecmp_groups_find(struct group_ecmp_datapath *gn,
+ {
+     struct ecmp_groups_node *eg;
+     HMAP_FOR_EACH_WITH_HASH (eg, hmap_node, route->hash, &gn->ecmp_groups) {
++        /* Keep in sync with ecmp_group_hash(). */
+         if (ipv6_addr_equals(&eg->prefix, &route->prefix) &&
+             eg->plen == route->plen &&
+             eg->is_src_route == route->is_src_route &&
+@@ -396,6 +655,10 @@ group_ecmp_route(struct group_ecmp_route_data *data,
+         gn = group_ecmp_datapath_lookup_or_add(data, pr->od);
+         add_route(gn, pr);
+     }
++
++    HMAP_FOR_EACH (gn, hmap_node, &data->datapaths) {
++        group_ecmp_datapath_finalize(gn);
++    }
+ }
+ 
+ enum engine_node_state
+@@ -472,9 +735,7 @@ handle_deleted_route(struct group_ecmp_route_data *data,
+              * unique route. Otherwise it stays an ecmp group with just one
+              * member. */
+             ecmp_groups_remove_route(eg, pr);
+-            if (ecmp_group_has_symmetric_reply(eg)) {
+-                ecmp_group_update_ids(eg);
+-            } else {
++            if (!ecmp_group_has_symmetric_reply(eg)) {
+                 const struct ecmp_route_list_node *er =
+                     vector_get_ptr(&eg->route_list, 0);
+                 unique_routes_add(node, er->route);
+@@ -482,11 +743,8 @@ handle_deleted_route(struct group_ecmp_route_data *data,
+                 ecmp_groups_node_free(eg);
+             }
+         } else {
+-            /* We can just remove the member from the group. We need to update
+-             * the indices of all routes so that future insertions directly
+-             * have a new index. */
++            /* We can just remove the member from the group. */
+             ecmp_groups_remove_route(eg, pr);
+-            ecmp_group_update_ids(eg);
+         }
+     }
+ 
+@@ -537,6 +795,7 @@ group_ecmp_route_learned_route_change_handler(struct engine_node *eng_node,
+             hmapx_add(&data->trk_data.deleted_datapath_routes, node);
+             hmap_remove(&data->datapaths, &node->hmap_node);
+         } else {
++            group_ecmp_datapath_finalize(node);
+             hmapx_add(&data->trk_data.crupdated_datapath_routes, node);
+         }
+     }
+@@ -589,6 +848,7 @@ group_ecmp_route_routes_change_handler(struct engine_node *eng_node,
+             hmapx_add(&data->trk_data.deleted_datapath_routes, node);
+             hmap_remove(&data->datapaths, &node->hmap_node);
+         } else {
++            group_ecmp_datapath_finalize(node);
+             hmapx_add(&data->trk_data.crupdated_datapath_routes, node);
+         }
+     }
+@@ -645,6 +905,7 @@ group_ecmp_route_dynamic_routes_change_handler(struct engine_node *eng_node,
+             hmapx_add(&gdata->trk_data.deleted_datapath_routes, node);
+             hmap_remove(&gdata->datapaths, &node->hmap_node);
+         } else {
++            group_ecmp_datapath_finalize(node);
+             hmapx_add(&gdata->trk_data.crupdated_datapath_routes, node);
+         }
+     }
+diff --git a/northd/en-group-ecmp-route.h b/northd/en-group-ecmp-route.h
+index b40935be29..13f84a0361 100644
+--- a/northd/en-group-ecmp-route.h
++++ b/northd/en-group-ecmp-route.h
+@@ -37,7 +37,6 @@ struct ecmp_groups_node {
+     bool has_discard_route;
+     enum route_source source;
+     uint32_t route_table_id;
+-    uint16_t route_count;
+     struct vector route_list; /* Contains ecmp_route_list_node */
+     struct sset selection_fields;
+ };
+diff --git a/northd/en-northd.c b/northd/en-northd.c
+index 480dc61cad..96859e4ae3 100644
+--- a/northd/en-northd.c
++++ b/northd/en-northd.c
+@@ -694,32 +694,31 @@ northd_sb_fdb_change_handler(struct engine_node *node, void *data)
+     const struct sbrec_fdb_table *sbrec_fdb_table =
+         EN_OVSDB_GET(engine_get_input("SB_fdb", node));
+ 
++    struct vector to_remove =
++        VECTOR_EMPTY_INITIALIZER(const struct sbrec_fdb *);
++
+     /* check if changed rows are stale and delete them */
+-    const struct sbrec_fdb *fdb_e, *fdb_prev_del = NULL;
++    const struct sbrec_fdb *fdb_e;
+     SBREC_FDB_TABLE_FOR_EACH_TRACKED (fdb_e, sbrec_fdb_table) {
+         if (sbrec_fdb_is_deleted(fdb_e)) {
+             continue;
+         }
+ 
+-        if (fdb_prev_del) {
+-            sbrec_fdb_delete(fdb_prev_del);
+-        }
+-
+-        fdb_prev_del = fdb_e;
+-        struct ovn_datapath *od
+-            = ovn_datapath_find_by_key(&nd->ls_datapaths.datapaths,
+-                                       fdb_e->dp_key);
+-        if (od) {
+-            if (ovn_tnlid_present(&od->port_tnlids, fdb_e->port_key)) {
+-                fdb_prev_del = NULL;
+-            }
++        struct ovn_datapath *od =
++            ovn_datapath_find_by_key(&nd->ls_datapaths.datapaths,
++                                     fdb_e->dp_key);
++        if (!od || ovn_datapath_is_stale(od) ||
++            !ovn_tnlid_present(&od->fdb_ports_tnlids, fdb_e->port_key)) {
++            vector_push(&to_remove, &fdb_e);
+         }
+     }
+ 
+-    if (fdb_prev_del) {
+-        sbrec_fdb_delete(fdb_prev_del);
++    VECTOR_FOR_EACH (&to_remove, fdb_e) {
++        sbrec_fdb_delete(fdb_e);
+     }
+ 
++    vector_destroy(&to_remove);
++
+     return EN_HANDLED_UNCHANGED;
+ }
+ 
+diff --git a/northd/northd.c b/northd/northd.c
+index f523234b36..18425303ac 100644
+--- a/northd/northd.c
++++ b/northd/northd.c
+@@ -142,6 +142,7 @@ static bool vxlan_mode;
+ #define REGBIT_IP_FRAG            "reg0[19]"
+ #define REGBIT_ACL_PERSIST_ID     "reg0[20]"
+ #define REGBIT_ACL_HINT_ALLOW_PERSISTED "reg0[21]"
++#define REGBIT_LKUP_FDB_DL_INNER  "reg0[22]"
+ 
+ /* Register definitions for switches and routers. */
+ 
+@@ -616,6 +617,7 @@ ovn_datapath_create(struct hmap *datapaths, const struct uuid *key,
+     od->sdp = sdp;
+     od->nbs = nbs;
+     od->nbr = nbr;
++    hmap_init(&od->fdb_ports_tnlids);
+     hmap_init(&od->port_tnlids);
+     od->port_key_hint = 0;
+     hmap_insert(datapaths, &od->key_node, uuid_hash(&od->key));
+@@ -652,6 +654,7 @@ ovn_datapath_destroy(struct ovn_datapath *od)
+         /* Don't remove od->list.  It is used within build_datapaths() as a
+          * private list and once we've exited that function it is not safe to
+          * use it. */
++        ovn_destroy_tnlids(&od->fdb_ports_tnlids);
+         ovn_destroy_tnlids(&od->port_tnlids);
+         destroy_ipam_info(&od->ipam_info);
+         vector_destroy(&od->router_ports);
+@@ -1162,6 +1165,8 @@ ovn_port_cleanup(struct ovn_port *port)
+     if (port->tunnel_key) {
+         ovs_assert(port->od);
+         ovn_free_tnlid(&port->od->port_tnlids, port->tunnel_key);
++        ovn_free_tnlid(&port->od->fdb_ports_tnlids, port->tunnel_key);
++        port->tunnel_key = 0;
+     }
+     for (int i = 0; i < port->n_lsp_addrs; i++) {
+         destroy_lport_addresses(&port->lsp_addrs[i]);
+@@ -1169,13 +1174,12 @@ ovn_port_cleanup(struct ovn_port *port)
+     free(port->lsp_addrs);
+     port->n_lsp_addrs = 0;
+     port->lsp_addrs = NULL;
++    port->has_unknown = false;
+ 
+     if (port->peer) {
+         port->peer->peer = NULL;
+     }
+ 
+-    port->lsp_has_port_sec = false;
+-
+     destroy_lport_addresses(&port->lrp_networks);
+     destroy_lport_addresses(&port->proxy_arp_addrs);
+ }
+@@ -1310,6 +1314,13 @@ lsp_disable_arp_nd_rsp(const struct nbrec_logical_switch_port *nbsp)
+     return smap_get_bool(&nbsp->options, "disable_arp_nd_rsp", false);
+ }
+ 
++static bool
++port_can_learn_fdb(const struct ovn_port *op)
++{
++    return op->nbsp && lsp_is_enabled(op->nbsp) &&
++           (op->has_unknown || lsp_is_vtep(op->nbsp));
++ }
++
+ static bool
+ lsp_is_type_changed(const struct sbrec_port_binding *sb,
+                 const struct nbrec_logical_switch_port *nbsp,
+@@ -1568,16 +1579,6 @@ parse_lsp_addrs(struct ovn_port *op)
+     if (lsp_is_switch(nbsp)) {
+         op->has_unknown = true;
+     }
+-
+-    struct eth_addr mac;
+-    for (size_t j = 0; j < nbsp->n_port_security; j++) {
+-        int n = !strncmp(nbsp->port_security[j], "VRRPv3", 6) ? 7 : 0;
+-        if (ovs_scan_len(nbsp->port_security[j], &n, ETH_ADDR_SCAN_FMT,
+-                         ETH_ADDR_SCAN_ARGS(mac))) {
+-            op->lsp_has_port_sec = true;
+-            break;
+-        }
+-    }
+ }
+ 
+ static void
+@@ -1674,7 +1675,7 @@ join_logical_ports_lsp(struct hmap *ports,
+ 
+             /* This port exists due to a SB binding, but should
+              * not have been initialized fully. */
+-            ovs_assert(!op->n_lsp_addrs && !op->lsp_has_port_sec);
++            ovs_assert(!op->n_lsp_addrs);
+         }
+     } else {
+         op = ovn_port_create(ports, name, nbsp, NULL, NULL);
+@@ -3144,16 +3145,10 @@ cleanup_stale_fdb_entries(const struct sbrec_fdb_table *sbrec_fdb_table,
+ {
+     const struct sbrec_fdb *fdb_e;
+     SBREC_FDB_TABLE_FOR_EACH_SAFE (fdb_e, sbrec_fdb_table) {
+-        bool delete = true;
+-        struct ovn_datapath *od
+-            = ovn_datapath_find_by_key(ls_datapaths, fdb_e->dp_key);
+-        if (od) {
+-            if (ovn_tnlid_present(&od->port_tnlids, fdb_e->port_key)) {
+-                delete = false;
+-            }
+-        }
+-
+-        if (delete) {
++        struct ovn_datapath *od =
++            ovn_datapath_find_by_key(ls_datapaths, fdb_e->dp_key);
++        if (!od || ovn_datapath_is_stale(od) ||
++            !ovn_tnlid_present(&od->fdb_ports_tnlids, fdb_e->port_key)) {
+             sbrec_fdb_delete(fdb_e);
+         }
+     }
+@@ -3522,19 +3517,22 @@ ovn_lb_svc_create(struct ovsdb_idl_txn *ovnsb_txn,
+                     backend_nb->svc_mon_src_ip);
+             }
+ 
++            /* Unbound ports are not probed by any chassis: fail closed. */
+             if (!backend_nb->remote_backend &&
+-                (!op->sb->n_up || !op->sb->up[0])
++                (!op->sb->chassis || !op->sb->n_up || !op->sb->up[0])
+                 && mon_info->sbrec_mon->status
+                 && !strcmp(mon_info->sbrec_mon->status, "online")) {
+                 sbrec_service_monitor_set_status(mon_info->sbrec_mon,
+                                                  "offline");
+             }
+ 
+-            if (!backend_nb->remote_backend && op->sb->chassis &&
+-                strcmp(mon_info->sbrec_mon->chassis_name,
+-                       op->sb->chassis->name)) {
+-                sbrec_service_monitor_set_chassis_name(mon_info->sbrec_mon,
 -                                                       op->sb->chassis->name);
 +            if (!backend_nb->remote_backend) {
 +                const char *chassis_name = op->sb->chassis
@@ -961,7 +2602,7 @@ index f523234b3..0538bc69a 100644
              }
          }
      }
-@@ -3853,16 +3845,18 @@ ovn_lsp_svc_monitors_process_port(
+@@ -3853,16 +3851,18 @@ ovn_lsp_svc_monitors_process_port(
                                               lsp_hc->src_ip);
          }
  
@@ -984,7 +2625,41 @@ index f523234b3..0538bc69a 100644
          }
      }
  }
-@@ -5683,6 +5677,7 @@ northd_handle_lr_changes(const struct northd_input *ni,
+@@ -4373,6 +4373,10 @@ ovn_port_add_tnlid(struct ovn_port *op, uint32_t tunnel_key)
+         if (tunnel_key > op->od->port_key_hint) {
+             op->od->port_key_hint = tunnel_key;
+         }
++
++        if (port_can_learn_fdb(op)) {
++            ovs_assert(ovn_add_tnlid(&op->od->fdb_ports_tnlids, tunnel_key));
++        }
+     }
+     return added;
+ }
+@@ -4425,6 +4429,11 @@ ovn_port_allocate_key(struct ovn_port *op)
+         if (!op->tunnel_key) {
+             return false;
+         }
++
++        if (port_can_learn_fdb(op)) {
++            ovs_assert(ovn_add_tnlid(&op->od->fdb_ports_tnlids,
++                                     op->tunnel_key));
++        }
+     }
+     return true;
+ }
+@@ -5095,7 +5104,9 @@ ls_handle_lsp_changes(struct ovsdb_idl_txn *ovnsb_idl_txn,
+                 }
+                 add_op_to_northd_tracked_ports(&trk_lsps->updated, op);
+ 
+-                if (old_tunnel_key != op->tunnel_key) {
++                if (old_tunnel_key != op->tunnel_key ||
++                    !lsp_is_enabled(op->nbsp) ||
++                    !op->has_unknown) {
+                     delete_fdb_entries(ni->sbrec_fdb_by_dp_and_port,
+                                        od->tunnel_key, old_tunnel_key);
+                 }
+@@ -5683,6 +5694,7 @@ northd_handle_lr_changes(const struct northd_input *ni,
          }
  
          if (deleted_lr->copp ||
@@ -992,7 +2667,7 @@ index f523234b3..0538bc69a 100644
              deleted_lr->n_ports > 0 ||
              deleted_lr->n_policies > 0 ||
              deleted_lr->n_static_routes > 0) {
-@@ -6625,11 +6620,25 @@ build_lswitch_learn_fdb_op(
+@@ -6625,11 +6637,25 @@ build_lswitch_learn_fdb_op(
  {
      ovs_assert(op->nbsp);
  
@@ -1019,7 +2694,7 @@ index f523234b3..0538bc69a 100644
  
      if (remote || (!strcmp(op->nbsp->type, "") && lsp_can_learn_mac(op->nbsp))
          || lsp_is_switch(op->nbsp)
-@@ -6640,20 +6649,177 @@ build_lswitch_learn_fdb_op(
+@@ -6640,20 +6666,177 @@ build_lswitch_learn_fdb_op(
          if (lsp_is_localnet(op->nbsp)) {
              ds_put_cstr(actions, "flags.localnet = 1; ");
          }
@@ -1206,7 +2881,7 @@ index f523234b3..0538bc69a 100644
      }
  }
  
-@@ -9220,6 +9386,7 @@ build_lb_health_check_response_lflows(
+@@ -9220,6 +9403,7 @@ build_lb_health_check_response_lflows(
      const struct ovn_northd_lb_vip *lb_vip_nb,
      const struct ovn_lb_datapaths *lb_dps,
      const struct ovn_datapaths *lr_datapaths,
@@ -1214,7 +2889,7 @@ index f523234b3..0538bc69a 100644
      const struct shash *meter_groups,
      struct ds *match,
      struct ds *action)
-@@ -9228,6 +9395,7 @@ build_lb_health_check_response_lflows(
+@@ -9228,6 +9412,7 @@ build_lb_health_check_response_lflows(
       * to a real LRP, install rule that punts service check replies to the
       * controller. */
      const struct ovn_lb_backend *backend;
@@ -1222,7 +2897,7 @@ index f523234b3..0538bc69a 100644
      size_t j = 0;
  
      VECTOR_FOR_EACH_PTR (&lb_vip->backends, backend) {
-@@ -9243,6 +9411,14 @@ build_lb_health_check_response_lflows(
+@@ -9243,6 +9428,14 @@ build_lb_health_check_response_lflows(
              protocol = "tcp";
          }
  
@@ -1237,7 +2912,7 @@ index f523234b3..0538bc69a 100644
          size_t index;
          DYNAMIC_BITMAP_FOR_EACH_1 (index, &lb_dps->nb_lr_map) {
              struct ovn_datapath *od = sparse_array_get(&lr_datapaths->dps,
-@@ -9270,32 +9446,36 @@ build_lb_health_check_response_lflows(
+@@ -9270,32 +9463,36 @@ build_lb_health_check_response_lflows(
  
              ds_clear(match);
              ds_clear(action);
@@ -1283,7 +2958,7 @@ index f523234b3..0538bc69a 100644
                  }
              }
  
-@@ -9305,11 +9485,40 @@ build_lb_health_check_response_lflows(
+@@ -9305,11 +9502,40 @@ build_lb_health_check_response_lflows(
              const char *meter = copp_meter_get(COPP_SVC_MONITOR,
                                                 peer_switch_od->nbs->copp,
                                                 meter_groups);
@@ -1324,7 +2999,7 @@ index f523234b3..0538bc69a 100644
  }
  
  static void
-@@ -13379,6 +13588,13 @@ add_route(struct lflow_table *lflows, const struct ovn_datapath *od,
+@@ -13379,6 +13605,13 @@ add_route(struct lflow_table *lflows, const struct ovn_datapath *od,
                    ds_cstr(&match), ds_cstr(&actions), lflow_ref,
                    WITH_HINT(stage_hint));
      if (op && bfd_is_port_running(bfd_ports, op->key)) {
@@ -1338,7 +3013,42 @@ index f523234b3..0538bc69a 100644
          ds_put_format(&match, " && udp.dst == 3784");
          ovn_lflow_add(lflows, op->od, S_ROUTER_IN_IP_ROUTING, priority + 1,
                        ds_cstr(&match), ds_cstr(&common_actions), lflow_ref,
-@@ -14140,6 +14356,7 @@ build_lrouter_flows_for_lb(struct ovn_lb_datapaths *lb_dps,
+@@ -13676,19 +13909,16 @@ build_distr_lrouter_nat_flows_for_lb(struct lrouter_nat_lb_flows_ctx *ctx,
+     struct ds undnat_action = DS_EMPTY_INITIALIZER;
+ 
+     switch (type) {
+-    case LROUTER_NAT_LB_FLOW_FORCE_SNAT:
+-        ds_put_format(&undnat_action, "flags.force_snat_for_lb = 1; next;");
+-        break;
+     case LROUTER_NAT_LB_FLOW_SKIP_SNAT:
+-        ds_put_format(&undnat_action, "flags.skip_snat_for_lb = 1; next;");
++        ds_put_cstr(&undnat_action, "flags.skip_snat_for_lb = 1; ");
+         break;
++    case LROUTER_NAT_LB_FLOW_FORCE_SNAT:
+     case LROUTER_NAT_LB_FLOW_NORMAL:
+     case LROUTER_NAT_LB_FLOW_MAX:
+-        ds_put_format(&undnat_action, "%s",
+-                      lrouter_use_common_zone(od) ? "ct_dnat_in_czone;"
+-                      : "ct_dnat;");
+         break;
+     }
++    ds_put_cstr(&undnat_action, lrouter_use_common_zone(od)
++                                ? "ct_dnat_in_czone;" : "ct_dnat;");
+ 
+     /* We need to centralize the LB traffic to properly perform
+      * the undnat stage.
+@@ -14134,12 +14364,18 @@ build_lrouter_allow_vip_traffic_template(struct lflow_table *lflows,
+     ds_destroy(&match);
+ }
+ 
++/* Routers with distributed gateway ports shift their lr_out_snat NAT
++ * priorities up by this offset.  Other lr_out_snat flows that have to keep a
++ * fixed ordering relative to the NAT flows must apply the same offset. */
++#define NAT_PRIORITY_DGP_OFFSET 128
++
+ static void
+ build_lrouter_flows_for_lb(struct ovn_lb_datapaths *lb_dps,
+                            struct lflow_table *lflows,
                             const struct shash *meter_groups,
                             const struct ovn_datapaths *lr_datapaths,
                             const struct lr_stateful_table *lr_stateful_table,
@@ -1346,7 +3056,7 @@ index f523234b3..0538bc69a 100644
                             const struct svc_monitors_map_data *svc_mons_data,
                             struct ds *match, struct ds *action)
  {
-@@ -14163,7 +14380,7 @@ build_lrouter_flows_for_lb(struct ovn_lb_datapaths *lb_dps,
+@@ -14163,7 +14399,7 @@ build_lrouter_flows_for_lb(struct ovn_lb_datapaths *lb_dps,
  
          build_lb_health_check_response_lflows(
              lflows, lb, lb_vip, &lb->vips_nb[i], lb_dps, lr_datapaths,
@@ -1355,7 +3065,187 @@ index f523234b3..0538bc69a 100644
  
          if (!build_empty_lb_event_flow(lb_vip, lb, match, action)) {
              continue;
-@@ -20630,6 +20847,7 @@ build_lflows_thread(void *arg)
+@@ -14185,7 +14421,11 @@ build_lrouter_flows_for_lb(struct ovn_lb_datapaths *lb_dps,
+         DYNAMIC_BITMAP_FOR_EACH_1 (index, &lb_dps->nb_lr_map) {
+             struct ovn_datapath *od = sparse_array_get(&lr_datapaths->dps,
+                                                        index);
+-            ovn_lflow_add(lflows, od, S_ROUTER_OUT_SNAT, 120,
++            uint16_t prio = 120;
++            if (!od->is_gw_router && !vector_is_empty(&od->l3dgw_ports)) {
++                prio += NAT_PRIORITY_DGP_OFFSET;
++            }
++            ovn_lflow_add(lflows, od, S_ROUTER_OUT_SNAT, prio,
+                           "flags.skip_snat_for_lb == 1 && ip", "next;",
+                           lb_dps->lflow_ref);
+         }
+@@ -14309,7 +14549,7 @@ lrouter_nat_get_priority(const struct ovn_datapath *od,
+      * priority. */
+     uint16_t priority = prefix_len + 1;
+     if (!od->is_gw_router && !vector_is_empty(&od->l3dgw_ports)) {
+-        priority += 128;
++        priority += NAT_PRIORITY_DGP_OFFSET;
+     }
+ 
+     return priority;
+@@ -14658,23 +14898,47 @@ build_lrouter_force_snat_flows(struct lflow_table *lflows,
+                                const struct ovn_datapath *od,
+                                const char *ip_version, const char *ip_addr,
+                                const char *context,
++                               const struct ovn_port *l3dgw_port,
+                                struct lflow_ref *lflow_ref)
+ {
+     struct ds match = DS_EMPTY_INITIALIZER;
+     struct ds actions = DS_EMPTY_INITIALIZER;
+     ds_put_format(&match, "ip%s && ip%s.dst == %s",
+                   ip_version, ip_version, ip_addr);
++    if (l3dgw_port) {
++        /* Distributed router: only unSNAT on the chassis where the
++         * gateway port is resident. */
++        ds_put_format(&match, " && inport == %s && is_chassis_resident("
++                      "\"%s\")", l3dgw_port->json_key,
++                      l3dgw_port->cr_port->key);
++    }
+     ovn_lflow_add(lflows, od, S_ROUTER_IN_UNSNAT, 110,
+                   ds_cstr(&match), "ct_snat;", lflow_ref);
+ 
+-    /* Higher priority rules to force SNAT with the IP addresses
+-     * configured in the Gateway router.  This only takes effect
+-     * when the packet has already been DNATed or load balanced once. */
++    /* Higher priority rules to force SNAT with the configured IP
++     * addresses.  This only takes effect when the packet has already been
++     * DNATed or load balanced once. */
+     ds_clear(&match);
+     ds_put_format(&match, "flags.force_snat_for_%s == 1 && ip%s",
+                   context, ip_version);
++    uint16_t snat_prio = 100;
++    if (l3dgw_port) {
++        /* Distributed router: force SNAT is applied on the chassis
++         * where the gateway port is resident, consistent with how
++         * regular SNAT entries are handled for such routers.
++         *
++         * The NAT flows of such a router are shifted up by
++         * NAT_PRIORITY_DGP_OFFSET, so shift this flow as well to keep the
++         * same ordering it has on a gateway router.  Without the shift
++         * even a plain subnet SNAT entry would outrank it and the forced
++         * SNAT would never be applied. */
++        ds_put_format(&match, " && outport == %s && is_chassis_resident("
++                      "\"%s\")", l3dgw_port->json_key,
++                      l3dgw_port->cr_port->key);
++        snat_prio += NAT_PRIORITY_DGP_OFFSET;
++    }
+     ds_put_format(&actions, "ct_snat(%s);", ip_addr);
+-    ovn_lflow_add(lflows, od, S_ROUTER_OUT_SNAT, 100,
++    ovn_lflow_add(lflows, od, S_ROUTER_OUT_SNAT, snat_prio,
+                   ds_cstr(&match), ds_cstr(&actions),
+                   lflow_ref);
+ 
+@@ -18173,10 +18437,25 @@ build_lrouter_in_ct_extract_flows(struct lflow_table *lflows,
+     /* Ingress CT_EXTRACT table: Extract connection tracking fields for new
+      * connections. */
+     ovn_lflow_add(lflows, od, S_ROUTER_IN_CT_EXTRACT, 100,
+-                  "ct.new && ip",
++                  "ct.new && ip && ip.is_frag",
+                   REG_CT_PROTO " = ct_proto(); "
+                   REG_CT_TP_DST " = ct_tp_dst(); next;",
+                   lflow_ref);
++    ovn_lflow_add(lflows, od, S_ROUTER_IN_CT_EXTRACT, 100,
++                  "ct.new && ip && tcp && !ip.is_frag",
++                  REG_CT_PROTO " = ip.proto; "
++                  REG_CT_TP_DST " = tcp.dst; next;",
++                  lflow_ref);
++    ovn_lflow_add(lflows, od, S_ROUTER_IN_CT_EXTRACT, 100,
++                  "ct.new && ip && udp && !ip.is_frag",
++                  REG_CT_PROTO " = ip.proto; "
++                  REG_CT_TP_DST " = udp.dst; next;",
++                  lflow_ref);
++    ovn_lflow_add(lflows, od, S_ROUTER_IN_CT_EXTRACT, 100,
++                  "ct.new && ip && sctp && !ip.is_frag",
++                  REG_CT_PROTO " = ip.proto; "
++                  REG_CT_TP_DST " = sctp.dst; next;",
++                  lflow_ref);
+ }
+ 
+ static void
+@@ -19160,30 +19439,46 @@ build_lrouter_nat_defrag_and_lb(
+ 
+     }
+ 
+-    /* Handle force SNAT options set in the gateway router. */
++    /* Consumers for the force SNAT flags produced by the lr_in_dnat and
++     * lr_out_undnat flows above.
++     */
+     if (od->is_gw_router) {
+         if (dnat_force_snat_ip) {
+             if (lrnat_rec->dnat_force_snat_addrs.n_ipv4_addrs) {
+                 build_lrouter_force_snat_flows(lflows, od, "4",
+                     lrnat_rec->dnat_force_snat_addrs.ipv4_addrs[0].addr_s,
+-                    "dnat", lflow_ref);
++                    "dnat", NULL, lflow_ref);
+             }
+             if (lrnat_rec->dnat_force_snat_addrs.n_ipv6_addrs) {
+                 build_lrouter_force_snat_flows(lflows, od, "6",
+                     lrnat_rec->dnat_force_snat_addrs.ipv6_addrs[0].addr_s,
+-                    "dnat", lflow_ref);
++                    "dnat", NULL, lflow_ref);
+             }
+         }
+         if (lb_force_snat_ip) {
+             if (lrnat_rec->lb_force_snat_addrs.n_ipv4_addrs) {
+                 build_lrouter_force_snat_flows(lflows, od, "4",
+                     lrnat_rec->lb_force_snat_addrs.ipv4_addrs[0].addr_s, "lb",
+-                    lflow_ref);
++                    NULL, lflow_ref);
+             }
+             if (lrnat_rec->lb_force_snat_addrs.n_ipv6_addrs) {
+                 build_lrouter_force_snat_flows(lflows, od, "6",
+                     lrnat_rec->lb_force_snat_addrs.ipv6_addrs[0].addr_s, "lb",
+-                    lflow_ref);
++                    NULL, lflow_ref);
++            }
++        }
++    } else if (lb_force_snat_ip) {
++        struct ovn_port *dgp;
++        VECTOR_FOR_EACH (&od->l3dgw_ports, dgp) {
++            if (lrnat_rec->lb_force_snat_addrs.n_ipv4_addrs) {
++                build_lrouter_force_snat_flows(lflows, od, "4",
++                    lrnat_rec->lb_force_snat_addrs.ipv4_addrs[0].addr_s, "lb",
++                    dgp, lflow_ref);
++            }
++            if (lrnat_rec->lb_force_snat_addrs.n_ipv6_addrs) {
++                build_lrouter_force_snat_flows(lflows, od, "6",
++                    lrnat_rec->lb_force_snat_addrs.ipv6_addrs[0].addr_s, "lb",
++                    dgp, lflow_ref);
+             }
+         }
+     }
+@@ -19459,10 +19754,25 @@ build_ls_stateful_flows(const struct ls_stateful_record *ls_stateful_rec,
+      * balancers. */
+     if (ls_stateful_rec->has_lb_vip) {
+         ovn_lflow_add(lflows, od, S_SWITCH_IN_CT_EXTRACT, 100,
+-                      "ct.new && ip",
++                      "ct.new && ip && ip.is_frag",
+                       REG_CT_PROTO " = ct_proto(); "
+                       REG_CT_TP_DST " = ct_tp_dst(); next;",
+                       ls_stateful_rec->lflow_ref);
++        ovn_lflow_add(lflows, od, S_SWITCH_IN_CT_EXTRACT, 100,
++                      "ct.new && ip && tcp && !ip.is_frag",
++                      REG_CT_PROTO " = ip.proto; "
++                      REG_CT_TP_DST " = tcp.dst; next;",
++                      ls_stateful_rec->lflow_ref);
++        ovn_lflow_add(lflows, od, S_SWITCH_IN_CT_EXTRACT, 100,
++                      "ct.new && ip && udp && !ip.is_frag",
++                      REG_CT_PROTO " = ip.proto; "
++                      REG_CT_TP_DST " = udp.dst; next;",
++                      ls_stateful_rec->lflow_ref);
++        ovn_lflow_add(lflows, od, S_SWITCH_IN_CT_EXTRACT, 100,
++                      "ct.new && ip && sctp && !ip.is_frag",
++                      REG_CT_PROTO " = ip.proto; "
++                      REG_CT_TP_DST " = sctp.dst; next;",
++                      ls_stateful_rec->lflow_ref);
+     }
+ 
+     build_lb_hairpin(ls_stateful_rec, od, lflows, ls_stateful_rec->lflow_ref);
+@@ -20630,6 +20940,7 @@ build_lflows_thread(void *arg)
                                                 lsi->meter_groups,
                                                 lsi->lr_datapaths,
                                                 lsi->lr_stateful_table,
@@ -1363,7 +3253,7 @@ index f523234b3..0538bc69a 100644
                                                 &svc_mons_data,
                                                 &lsi->match, &lsi->actions);
                      build_lswitch_flows_for_lb(lb_dps, lsi->lflows,
-@@ -20873,7 +21091,7 @@ build_lswitch_and_lrouter_flows(
+@@ -20873,7 +21184,7 @@ build_lswitch_and_lrouter_flows(
                                                lsi.lr_datapaths, &lsi.match);
              build_lrouter_flows_for_lb(lb_dps, lsi.lflows, lsi.meter_groups,
                                         lsi.lr_datapaths, lsi.lr_stateful_table,
@@ -1372,7 +3262,7 @@ index f523234b3..0538bc69a 100644
                                         &lsi.match, &lsi.actions);
              build_lswitch_flows_for_lb(lb_dps, lsi.lflows, lsi.meter_groups,
                                         lsi.ls_datapaths,
-@@ -21284,6 +21502,7 @@ lflow_handle_northd_lb_changes(struct ovsdb_idl_txn *ovnsb_txn,
+@@ -21284,6 +21595,7 @@ lflow_handle_northd_lb_changes(struct ovsdb_idl_txn *ovnsb_txn,
                                     lflow_input->meter_groups,
                                     lflow_input->lr_datapaths,
                                     lflow_input->lr_stateful_table,
@@ -1381,10 +3271,19 @@ index f523234b3..0538bc69a 100644
                                     &match, &actions);
          build_lswitch_flows_for_lb(lb_dps, lflows,
 diff --git a/northd/northd.h b/northd/northd.h
-index 2e3a9e00d..b4a966b70 100644
+index 2e3a9e00da..ef1e6d1a32 100644
 --- a/northd/northd.h
 +++ b/northd/northd.h
-@@ -742,9 +742,6 @@ struct ovn_port {
+@@ -423,6 +423,8 @@ struct ovn_datapath {
+     struct vector router_ports; /* Vector of struct ovn_port *. */
+     struct vector switch_ports; /* Vector of struct ovn_port * of
+                                  * type 'switch'. */
++    struct hmap fdb_ports_tnlids; /* Tunnel keys for enabled LSP with
++                                   * unknown address. */
+     struct hmap port_tnlids;
+     uint32_t port_key_hint;
+ 
+@@ -742,9 +744,6 @@ struct ovn_port {
                                            * beginning of 'lsp_addrs' extracted
                                            * directly from LSP 'addresses'. */
  
@@ -1395,7 +3294,7 @@ index 2e3a9e00d..b4a966b70 100644
                                        the port changes. */
  
 diff --git a/ovn-nb.xml b/ovn-nb.xml
-index c741a3b32..4637bad50 100644
+index c741a3b327..b8f377dba1 100644
 --- a/ovn-nb.xml
 +++ b/ovn-nb.xml
 @@ -1951,12 +1951,23 @@
@@ -1428,7 +3327,26 @@ index c741a3b32..4637bad50 100644
            </dd>
  
            <dt><code>dynamic</code></dt>
-@@ -4096,7 +4107,7 @@ or
+@@ -3359,6 +3370,18 @@ or
+           character.
+         </p>
+ 
++        <p>
++          A set of IP addresses is also honored on distributed routers
++          with one or more distributed gateway ports.  In that case the
++          SNAT is applied on the chassis where the gateway port is
++          resident, consistent with how regular SNAT entries are handled
++          for such routers.  This is useful, for example, when a load
++          balancer backend reachable through the gateway port connects to
++          its own VIP: without the forced SNAT the un-SNATed reply would
++          arrive at the backend with identical source and destination
++          addresses and be discarded as a martian packet.
++        </p>
++
+         <p>
+           If it is configured with the value <code>router_ip</code>, then
+           the load balanced packet is SNATed with the IP of router port
+@@ -4096,7 +4119,7 @@ or
  
      <column name="rate">
        <p>
@@ -1438,7 +3356,7 @@ index c741a3b32..4637bad50 100644
          entry's <ref column="unit" table="Meter"/> column specified
          <code>kbps</code> or <code>pktps</code>.
 diff --git a/rhel/usr_lib_systemd_system_ovn-br-db.service b/rhel/usr_lib_systemd_system_ovn-br-db.service
-index 6de2a22f1..a6f6631b0 100644
+index 6de2a22f1e..a6f6631b09 100644
 --- a/rhel/usr_lib_systemd_system_ovn-br-db.service
 +++ b/rhel/usr_lib_systemd_system_ovn-br-db.service
 @@ -7,11 +7,11 @@
@@ -1455,8 +3373,83 @@ index 6de2a22f1..a6f6631b0 100644
  
  [Unit]
  Description=OVN Bridge Controller OVSDB server
+diff --git a/tests/ovn-controller-vtep.at b/tests/ovn-controller-vtep.at
+index 0e8a1e0086..aa8da62a6f 100644
+--- a/tests/ovn-controller-vtep.at
++++ b/tests/ovn-controller-vtep.at
+@@ -620,7 +620,11 @@ OVS_WAIT_UNTIL([vtep-ctl list Ucast_Macs_Local | grep -q aa:bb:cc:dd:ff:02])
+ 
+ # Check that first MACs is propagated to FDB table
+ wait_row_count fdb 1 mac='"aa:bb:cc:dd:ff:01"'
++uuid1=$(fetch_column fdb _uuid mac='"aa:bb:cc:dd:ff:01"')
++check test -n "$uuid1"
+ wait_row_count fdb 1 mac='"aa:bb:cc:dd:ff:02"'
++uuid2=$(fetch_column fdb _uuid mac='"aa:bb:cc:dd:ff:02"')
++check test -n "$uuid2"
+ 
+ # Switch context
+ as
+@@ -632,6 +636,9 @@ OVS_WAIT_WHILE([vtep-ctl list-remote-macs lswitch1 | grep -q aa:bb:cc:dd:ff:01])
+ OVS_WAIT_UNTIL([vtep-ctl list-remote-macs lswitch1 | grep -q aa:bb:cc:dd:ff:02])
+ OVS_WAIT_WHILE([vtep-ctl list-remote-macs lswitch0 | grep -q aa:bb:cc:dd:ff:02])
+ 
++check test "$uuid1" = "$(fetch_column fdb _uuid mac='"aa:bb:cc:dd:ff:01"')"
++check test "$uuid2" = "$(fetch_column fdb _uuid mac='"aa:bb:cc:dd:ff:02"')"
++
+ # Switch context to br-vtep1
+ as br-vtep1
+ 
+diff --git a/tests/ovn-controller.at b/tests/ovn-controller.at
+index a7b79fc670..c4a0837566 100644
+--- a/tests/ovn-controller.at
++++ b/tests/ovn-controller.at
+@@ -3070,6 +3070,44 @@ OVN_CLEANUP([hv1])
+ AT_CLEANUP
+ ])
+ 
++OVN_FOR_EACH_NORTHD([
++AT_SETUP([ovn-controller - released untracked port is set down])
++ovn_start
++
++net_add n1
++sim_add hv1
++as hv1
++ovs-vsctl add-br br-phys
++ovn_attach n1 br-phys 192.168.0.1
++
++check ovn-nbctl ls-add sw0
++check ovn-nbctl lsp-add sw0 sw0-p1 -- lsp-set-addresses sw0-p1 \
++"00:00:00:00:00:01 10.0.0.1"
++check ovs-vsctl -- add-port br-int hv1-vif1 -- \
++    set interface hv1-vif1 external-ids:iface-id=sw0-p1
++wait_for_ports_up sw0-p1
++
++# Stop ovn-controller without releasing anything (as after a crash), remove
++# the VIF while it is stopped (the VM did not come back) and start it again.
++# The port is still bound to hv1 in the SB but this ovn-controller instance
++# never claimed it, so if-status does not track it.
++check ovn-appctl -t ovn-controller exit --restart
++check ovs-vsctl del-port br-int hv1-vif1
++start_daemon ovn-controller
++
++# The port must be released and set down.
++wait_row_count Port_Binding 1 logical_port=sw0-p1 'chassis=[[]]' 'up=false'
++wait_row_count nb:Logical_Switch_Port 1 name=sw0-p1 'up=false'
++
++# Adding the VIF back claims the port again as usual.
++check ovs-vsctl -- add-port br-int hv1-vif1 -- \
++    set interface hv1-vif1 external-ids:iface-id=sw0-p1
++wait_for_ports_up sw0-p1
++
++OVN_CLEANUP([hv1])
++AT_CLEANUP
++])
++
+ OVN_FOR_EACH_NORTHD([
+ AT_SETUP([Encap enforce local_ip])
+ ovn_start
 diff --git a/tests/ovn-ic.at b/tests/ovn-ic.at
-index 51ac645b4..82a2be9e4 100644
+index 51ac645b47..82a2be9e4e 100644
 --- a/tests/ovn-ic.at
 +++ b/tests/ovn-ic.at
 @@ -4038,20 +4038,92 @@ dnl Check that FDB learning is enabled for remote ports in the egress pipeline.
@@ -1617,8 +3610,53 @@ index 51ac645b4..82a2be9e4 100644
  AS_BOX([az2 paused])
  check as az2 ovn-appctl -t ic/ovn-ic pause
  OVS_WAIT_UNTIL([test "x$(as az2 ovn-appctl -t ic/ovn-ic status | grep "Status")" = "xStatus: paused"])
+diff --git a/tests/ovn-macros.at b/tests/ovn-macros.at
+index f962bec3ec..ed69736922 100644
+--- a/tests/ovn-macros.at
++++ b/tests/ovn-macros.at
+@@ -1500,6 +1500,40 @@ ovn_strip_lflows() {
+      sed 's/table=[[0-9]]\{1,2\}\s\?/table=??/g' | sort
+ }
+ 
++# The ECMP group and member ids are derived from hashes of the routes, replace
++# them with <gid> and <mid>.
++ovn_strip_ecmp_ids() {
++    sed -e 's/\(reg8\[[0\.\.15\]] =\{1,2\} \)[[1-9]][[0-9]]*/\1<gid>/' \
++        -e 's/\(reg8\[[16\.\.31\]] =\{1,2\} \)[[1-9]][[0-9]]*/\1<mid>/' \
++        -e ':a' \
++        -e 's/\(select[[^)]]*[[(, ]]\)[[0-9]][[0-9]]*/\1<mid>/' \
++        -e 'ta'
++}
++
++# ecmp_ids LR PREFIX: prints the group id and the comma separated member ids
++# of the ECMP group of PREFIX on LR, and fails if the members listed in its
++# select() action are not the ones that have a flow in lr_in_ip_routing_ecmp.
++ecmp_ids() {
++    local flows gid sel mids
++    flows=$(ovn-sbctl dump-flows $1)
++    gid=$(echo "$flows" | sed -n "s|.*ip[[46]]\.dst == $2).*reg8\[[0\.\.15\]] = \([[0-9]]*\);.*|\1|p")
++    sel=$(echo "$flows" | sed -n "s|.*ip[[46]]\.dst == $2).*select(\([[^)]]*\));.*|\1|p" | tr -d ' ')
++    mids=$(echo "$flows" | sed -n "s|.*(reg8\[[0\.\.15\]] == $gid && reg8\[[16\.\.31\]] == \([[0-9]]*\)).*|\1|p" | sort -n | paste -sd, -)
++    if test -z "$gid" || test "$sel" != "$mids"; then
++        echo "$2: group '$gid', select($sel) != members($mids)" >&2
++        return 1
++    fi
++    echo "$gid $sel"
++}
++
++# ecmp_member_id LR PREFIX NEXTHOP: prints the member id of NEXTHOP in the
++# ECMP group of PREFIX on LR.
++ecmp_member_id() {
++    local gid
++    gid=$(ecmp_ids $1 $2 | cut -d' ' -f1)
++    ovn-sbctl dump-flows $1 | sed -n "s|.*(reg8\[[0\.\.15\]] == $gid && reg8\[[16\.\.31\]] == \([[0-9]]*\)), action=(reg0 = $3;.*|\1|p"
++}
++
+ ovn_strip_collector_set() {
+     sed 's/collector_set=[[0-9]]*,\?/collector_set=??,/g'
+ }
 diff --git a/tests/ovn-northd.at b/tests/ovn-northd.at
-index 4acdc677a..3ed3da542 100644
+index 4acdc677ac..e4f7528bb7 100644
 --- a/tests/ovn-northd.at
 +++ b/tests/ovn-northd.at
 @@ -1806,6 +1806,197 @@ OVN_CLEANUP_NORTHD
@@ -1819,8 +3857,110 @@ index 4acdc677a..3ed3da542 100644
  OVN_FOR_EACH_NORTHD_NO_HV([
  AT_SETUP([Load balancer VIP in NAT entries])
  AT_SKIP_IF([test $HAVE_PYTHON = no])
-@@ -4537,6 +4728,47 @@ OVN_CLEANUP_NORTHD
- AT_CLEANUP
+@@ -4126,8 +4317,6 @@ flow="inport == \"lsp1\" && ${flow_eth} && ${flow_ip} && ${flow_tcp}"
+ ovn_trace --ct new --ct new ls "${flow}"
+ AT_CHECK_UNQUOTED([ovn_trace --ct new --ct new --minimal ls "${flow}"], [0], [dnl
+ ct_lb_mark {
+-    reg1[[16..23]] = 6;
+-    reg1[[0..15]] = 80;
+     ct_lb_mark {
+         reg0[[6]] = 0;
+         reg0[[12]] = 0;
+@@ -4141,6 +4330,20 @@ ct_lb_mark {
+ # UDP packets should go to conntrack.
+ flow="inport == \"lsp1\" && ${flow_eth} && ${flow_ip} && ${flow_udp}"
+ AT_CHECK_UNQUOTED([ovn_trace --ct new --ct new --minimal ls "${flow}"], [0], [dnl
++ct_lb_mark {
++    ct_lb_mark {
++        reg0[[6]] = 0;
++        reg0[[12]] = 0;
++        ct_lb_mark /* default (use --ct to customize) */ {
++            output("lsp2");
++        };
++    };
++};
++])
++
++# Fragmented UDP packets should go to conntrack.
++flow="inport == \"lsp1\" && ${flow_eth} && ${flow_ip} && ${flow_udp} && ip.is_frag"
++AT_CHECK_UNQUOTED([ovn_trace --ct new --ct new --minimal ls "${flow}"], [0], [dnl
+ ct_lb_mark {
+     reg1[[16..23]] = 17;
+     reg1[[0..15]] = 80;
+@@ -4169,6 +4372,20 @@ output("lsp2");
+ # UDP packets still go to conntrack.
+ flow="inport == \"lsp1\" && ${flow_eth} && ${flow_ip} && ${flow_udp}"
+ AT_CHECK_UNQUOTED([ovn_trace --ct new --ct new --minimal ls "${flow}"], [0], [dnl
++ct_lb_mark {
++    ct_lb_mark {
++        reg0[[6]] = 0;
++        reg0[[12]] = 0;
++        ct_lb_mark /* default (use --ct to customize) */ {
++            output("lsp2");
++        };
++    };
++};
++])
++
++# Fragmented UDP packets still go to conntrack.
++flow="inport == \"lsp1\" && ${flow_eth} && ${flow_ip} && ${flow_udp} && ip.is_frag"
++AT_CHECK_UNQUOTED([ovn_trace --ct new --ct new --minimal ls "${flow}"], [0], [dnl
+ ct_lb_mark {
+     reg1[[16..23]] = 17;
+     reg1[[0..15]] = 80;
+@@ -4269,8 +4486,6 @@ check ovn-nbctl --wait=sb sync
+ flow="inport == \"lsp1\" && ${flow_eth} && ${flow_ip} && ${flow_tcp}"
+ AT_CHECK_UNQUOTED([ovn_trace --ct new --ct new --minimal ls "${flow}"], [0], [dnl
+ ct_lb_mark {
+-    reg1[[16..23]] = 6;
+-    reg1[[0..15]] = 80;
+     ct_lb_mark {
+         reg0[[6]] = 0;
+         reg0[[12]] = 0;
+@@ -4284,6 +4499,20 @@ ct_lb_mark {
+ # UDP packets should go to conntrack.
+ flow="inport == \"lsp1\" && ${flow_eth} && ${flow_ip} && ${flow_udp}"
+ AT_CHECK_UNQUOTED([ovn_trace --ct new --ct new --minimal ls "${flow}"], [0], [dnl
++ct_lb_mark {
++    ct_lb_mark {
++        reg0[[6]] = 0;
++        reg0[[12]] = 0;
++        ct_lb_mark /* default (use --ct to customize) */ {
++            output("lsp2");
++        };
++    };
++};
++])
++
++# Fragmented UDP packets should go to conntrack.
++flow="inport == \"lsp1\" && ${flow_eth} && ${flow_ip} && ${flow_udp} && ip.is_frag"
++AT_CHECK_UNQUOTED([ovn_trace --ct new --ct new --minimal ls "${flow}"], [0], [dnl
+ ct_lb_mark {
+     reg1[[16..23]] = 17;
+     reg1[[0..15]] = 80;
+@@ -4312,6 +4541,20 @@ output("lsp2");
+ # UDP packets still go to conntrack.
+ flow="inport == \"lsp1\" && ${flow_eth} && ${flow_ip} && ${flow_udp}"
+ AT_CHECK_UNQUOTED([ovn_trace --ct new --ct new --minimal ls "${flow}"], [0], [dnl
++ct_lb_mark {
++    ct_lb_mark {
++        reg0[[6]] = 0;
++        reg0[[12]] = 0;
++        ct_lb_mark /* default (use --ct to customize) */ {
++            output("lsp2");
++        };
++    };
++};
++])
++
++# Fragmented UDP packets still go to conntrack.
++flow="inport == \"lsp1\" && ${flow_eth} && ${flow_ip} && ${flow_udp} && ip.is_frag"
++AT_CHECK_UNQUOTED([ovn_trace --ct new --ct new --minimal ls "${flow}"], [0], [dnl
+ ct_lb_mark {
+     reg1[[16..23]] = 17;
+     reg1[[0..15]] = 80;
+@@ -4537,6 +4780,47 @@ OVN_CLEANUP_NORTHD
+ AT_CLEANUP
  ])
  
 +OVN_FOR_EACH_NORTHD_NO_HV([
@@ -1867,7 +4007,414 @@ index 4acdc677a..3ed3da542 100644
  OVN_FOR_EACH_NORTHD_NO_HV([
  AT_SETUP([ovn -- check CoPP config])
  AT_KEYWORDS([northd-CoPP])
-@@ -7972,7 +8204,19 @@ AT_CAPTURE_FILE([S1flows])
+@@ -5045,6 +5329,109 @@ OVN_CLEANUP_NORTHD
+ AT_CLEANUP
+ ])
+ 
++OVN_FOR_EACH_NORTHD_NO_HV_PARALLELIZATION([
++AT_SETUP([Load Balancers and lb_force_snat_ip for routers with distributed gateway ports])
++ovn_start
++
++check ovn-nbctl ls-add sw0
++
++# Create a logical router with a distributed gateway port.
++check ovn-nbctl lr-add lr0
++check ovn-nbctl lrp-add lr0 lr0-sw0 00:00:00:00:ff:01 10.0.0.1/24
++check ovn-nbctl lsp-add-router-port sw0 sw0-lr0 lr0-sw0
++
++check ovn-nbctl ls-add public
++check ovn-nbctl lrp-add lr0 lr0-public 00:00:20:20:12:13 172.168.0.100/24
++check ovn-nbctl lsp-add-router-port public public-lr0 lr0-public
++check ovn-nbctl lrp-set-gateway-chassis lr0-public ch1
++
++check ovn-nbctl lb-add lb1 10.0.0.10:80 10.0.0.4:8080
++check ovn-nbctl lr-lb-add lr0 lb1
++
++# A plain subnet SNAT entry.  On a router with a distributed gateway port
++# the NAT priorities are shifted up by NAT_PRIORITY_DGP_OFFSET, so this
++# entry outranks an unshifted force SNAT flow.  Keep it in the test to make
++# sure the force SNAT consumer stays above it.
++check ovn-nbctl lr-nat-add lr0 snat 172.168.0.100 10.0.0.0/24
++
++check ovn-nbctl --wait=sb sync
++
++ovn-sbctl dump-flows lr0 > lr0flows
++AT_CAPTURE_FILE([lr0flows])
++
++# Without lb_force_snat_ip there should be no force SNAT flows.
++AT_CHECK([grep "lr_out_snat" lr0flows | grep force_snat_for_lb | ovn_strip_lflows], [0], [dnl
++])
++
++check ovn-nbctl --wait=sb set logical_router lr0 options:lb_force_snat_ip="172.168.0.4 aef0::4"
++
++ovn-sbctl dump-flows lr0 > lr0flows
++AT_CAPTURE_FILE([lr0flows])
++
++AT_CHECK([grep "lr_in_unsnat" lr0flows | ovn_strip_lflows], [0], [dnl
++  table=??(lr_in_unsnat       ), priority=0    , match=(1), action=(next;)
++  table=??(lr_in_unsnat       ), priority=100  , match=(ip && ip4.dst == 172.168.0.100 && inport == "lr0-public" && is_chassis_resident("cr-lr0-public")), action=(ct_snat;)
++  table=??(lr_in_unsnat       ), priority=110  , match=(ip4 && ip4.dst == 172.168.0.4 && inport == "lr0-public" && is_chassis_resident("cr-lr0-public")), action=(ct_snat;)
++  table=??(lr_in_unsnat       ), priority=110  , match=(ip6 && ip6.dst == aef0::4 && inport == "lr0-public" && is_chassis_resident("cr-lr0-public")), action=(ct_snat;)
++])
++
++# The force SNAT flows must sit above the subnet SNAT entry, otherwise the
++# latter would SNAT the load balanced traffic first and lb_force_snat_ip
++# would still be ignored.
++AT_CHECK([grep "lr_out_snat" lr0flows | ovn_strip_lflows], [0], [dnl
++  table=??(lr_out_snat        ), priority=0    , match=(1), action=(next;)
++  table=??(lr_out_snat        ), priority=120  , match=(nd_ns), action=(next;)
++  table=??(lr_out_snat        ), priority=153  , match=(ip && ip4.dst == 10.0.0.0/24 && inport == "lr0-public" && is_chassis_resident("cr-lr0-public") && (!ct.trk || !ct.rpl)), action=(ct_snat;)
++  table=??(lr_out_snat        ), priority=153  , match=(ip && ip4.src == 10.0.0.0/24 && outport == "lr0-public" && is_chassis_resident("cr-lr0-public") && (!ct.trk || !ct.rpl)), action=(ct_snat(172.168.0.100);)
++  table=??(lr_out_snat        ), priority=228  , match=(flags.force_snat_for_lb == 1 && ip4 && outport == "lr0-public" && is_chassis_resident("cr-lr0-public")), action=(ct_snat(172.168.0.4);)
++  table=??(lr_out_snat        ), priority=228  , match=(flags.force_snat_for_lb == 1 && ip6 && outport == "lr0-public" && is_chassis_resident("cr-lr0-public")), action=(ct_snat(aef0::4);)
++])
++
++# The producer and the consumer must both be present: the load balancer
++# DNAT flows on the gateway chassis set flags.force_snat_for_lb, and the
++# flows above consume it.
++AT_CHECK([grep "lr_in_dnat" lr0flows | grep -q "force_snat"], [0], [])
++
++# The reply has to be unDNATed on the gateway chassis.  It must not be flagged
++# for force SNAT: if it leaves through the gateway port as well, the force SNAT
++# consumer would SNAT the reply.
++AT_CHECK([grep "lr_out_undnat" lr0flows | ovn_strip_lflows], [0], [dnl
++  table=??(lr_out_undnat      ), priority=0    , match=(1), action=(next;)
++  table=??(lr_out_undnat      ), priority=120  , match=(ip4 && ((ip4.src == 10.0.0.4 && tcp.src == 8080)) && (inport == "lr0-public" || outport == "lr0-public") && is_chassis_resident("cr-lr0-public")), action=(ct_dnat;)
++])
++
++# With skip_snat on the load balancer the reply is flagged so that the subnet
++# SNAT entry leaves it alone, it is still unDNATed, and the skip_snat consumer
++# has to sit above the subnet SNAT entry.
++check ovn-nbctl --wait=sb set load_balancer lb1 options:skip_snat=true
++
++ovn-sbctl dump-flows lr0 > lr0flows
++AT_CAPTURE_FILE([lr0flows])
++
++AT_CHECK([grep "lr_out_undnat" lr0flows | ovn_strip_lflows], [0], [dnl
++  table=??(lr_out_undnat      ), priority=0    , match=(1), action=(next;)
++  table=??(lr_out_undnat      ), priority=120  , match=(ip4 && ((ip4.src == 10.0.0.4 && tcp.src == 8080)) && (inport == "lr0-public" || outport == "lr0-public") && is_chassis_resident("cr-lr0-public")), action=(flags.skip_snat_for_lb = 1; ct_dnat;)
++])
++
++AT_CHECK([grep "lr_out_snat" lr0flows | grep skip_snat | ovn_strip_lflows], [0], [dnl
++  table=??(lr_out_snat        ), priority=248  , match=(flags.skip_snat_for_lb == 1 && ip), action=(next;)
++])
++
++check ovn-nbctl --wait=sb remove load_balancer lb1 options skip_snat
++
++# Removing the option removes the flows.
++check ovn-nbctl --wait=sb remove logical_router lr0 options lb_force_snat_ip
++
++ovn-sbctl dump-flows lr0 > lr0flows
++AT_CAPTURE_FILE([lr0flows])
++
++AT_CHECK([grep "lr_out_snat" lr0flows | grep force_snat_for_lb | ovn_strip_lflows], [0], [dnl
++])
++
++OVN_CLEANUP_NORTHD
++AT_CLEANUP
++])
++
+ OVN_FOR_EACH_NORTHD_NO_HV([
+ AT_SETUP([HA chassis group cleanup for external port ])
+ ovn_start
+@@ -5094,28 +5481,38 @@ AT_SETUP([FDB cleanup])
+ ovn_start
+ 
+ check ovn-nbctl ls-add sw0
+-check ovn-nbctl lsp-add sw0 sw0-p1
+-check ovn-nbctl lsp-add sw0 sw0-p2
+-check ovn-nbctl lsp-add sw0 sw0-p3
++check ovn-nbctl lsp-add sw0 sw0-p1 -- lsp-set-addresses sw0-p1 unknown
++check ovn-nbctl lsp-add sw0 sw0-p2 -- lsp-set-addresses sw0-p2 unknown
++check ovn-nbctl lsp-add sw0 sw0-p3 -- lsp-set-addresses sw0-p3 unknown \
++    -- set Logical_Switch_Port sw0-p3 enabled=false
++check ovn-nbctl lsp-add sw0 sw0-p4
+ 
+ check ovn-nbctl ls-add sw1
+-check ovn-nbctl lsp-add sw1 sw1-p1
+-check ovn-nbctl lsp-add sw1 sw1-p2
+-check ovn-nbctl --wait=sb lsp-add sw1 sw1-p3
++check ovn-nbctl lsp-add sw1 sw1-p1 -- lsp-set-addresses sw1-p1 unknown
++check ovn-nbctl --wait=sb sync
+ 
+ sw0_key=$(fetch_column datapath_binding tunnel_key external_ids:name=sw0)
+ sw1_key=$(fetch_column datapath_binding tunnel_key external_ids:name=sw1)
+ sw0p1_key=$(fetch_column port_binding tunnel_key logical_port=sw0-p1)
+ sw0p2_key=$(fetch_column port_binding tunnel_key logical_port=sw0-p2)
++sw0p3_key=$(fetch_column port_binding tunnel_key logical_port=sw0-p3)
++sw0p4_key=$(fetch_column port_binding tunnel_key logical_port=sw0-p4)
+ sw1p1_key=$(fetch_column port_binding tunnel_key logical_port=sw1-p1)
+ 
+ check_uuid ovn-sbctl create FDB mac="00\:00\:00\:00\:00\:01" dp_key=$sw0_key port_key=$sw0p1_key
+ check_uuid ovn-sbctl create FDB mac="00\:00\:00\:00\:00\:02" dp_key=$sw0_key port_key=$sw0p1_key
+ check_uuid ovn-sbctl create FDB mac="00\:00\:00\:00\:00\:03" dp_key=$sw0_key port_key=$sw0p2_key
++check_uuid ovn-sbctl create FDB mac="00\:00\:00\:00\:00\:04" dp_key=$sw0_key port_key=$sw0p3_key
++check_uuid ovn-sbctl create FDB mac="00\:00\:00\:00\:00\:05" dp_key=$sw0_key port_key=$sw0p4_key
+ check_uuid ovn-sbctl create FDB mac="00\:00\:00\:00\:01\:01" dp_key=$sw1_key port_key=$sw1p1_key
+ check_uuid ovn-sbctl create FDB mac="00\:00\:00\:00\:01\:02" dp_key=$sw1_key port_key=$sw1p1_key
+ check_uuid ovn-sbctl create FDB mac="00\:00\:00\:00\:01\:03" dp_key=$sw1_key port_key=$sw1p1_key
+ 
++# Disabled port should clear FDB.
++wait_row_count FDB 0 dp_key=$sw0_key port_key=$sw0p3_key
++# Port without "unknown address" should clear FDB.
++wait_row_count FDB 0 dp_key=$sw0_key port_key=$sw0p4_key
++
+ wait_row_count FDB 6
+ 
+ AT_CHECK([ovn-sbctl create fdb mac="00\:00\:00\:00\:01\:03" dp_key=$sw1_key port_key=10], [1], [ignore], [ignore])
+@@ -5133,12 +5530,32 @@ check ovn-nbctl lsp-del sw0-p1
+ wait_row_count FDB 1
+ 
+ check_column '00:00:00:00:00:03' FDB mac
+-ovn-sbctl list fdb
++ovn-sbctl list FDB
+ 
+ check_column $sw0_key FDB dp_key
+ check_column $sw0p2_key FDB port_key
+ 
+-check ovn-nbctl --wait=sb lsp-add sw0 sw0-p1
++check ovn-nbctl --wait=sb lsp-add sw0 sw0-p1 -- lsp-set-addresses sw0-p1 unknown
++sw0p1_key=$(fetch_column port_binding tunnel_key logical_port=sw0-p1)
++wait_row_count FDB 1
++
++check_uuid ovn-sbctl create FDB mac="00\:00\:00\:00\:00\:01" dp_key=$sw0_key port_key=$sw0p1_key
++check_uuid ovn-sbctl create FDB mac="00\:00\:00\:00\:00\:02" dp_key=$sw0_key port_key=$sw0p1_key
++wait_row_count FDB 3
++
++# Disabling clears FDB entries.
++check ovn-nbctl --wait=sb set Logical_Switch_Port sw0-p1 enabled=false
++check_uuid ovn-sbctl create FDB mac="00\:00\:00\:00\:00\:01" dp_key=$sw0_key port_key=$sw0p1_key
++check_uuid ovn-sbctl create FDB mac="00\:00\:00\:00\:00\:02" dp_key=$sw0_key port_key=$sw0p1_key
++wait_row_count FDB 1
++
++check ovn-nbctl --wait=sb set Logical_Switch_Port sw0-p1 enabled=true
++check_uuid ovn-sbctl create FDB mac="00\:00\:00\:00\:00\:01" dp_key=$sw0_key port_key=$sw0p1_key
++check_uuid ovn-sbctl create FDB mac="00\:00\:00\:00\:00\:02" dp_key=$sw0_key port_key=$sw0p1_key
++wait_row_count FDB 3
++
++# Removing unknown clears FDB entries.
++check ovn-nbctl --wait=sb lsp-set-addresses sw0-p1 "00:00:00:00:00:10 192.168.100.10"
+ wait_row_count FDB 1
+ 
+ check ovn-nbctl lsp-del sw0-p2
+@@ -5152,7 +5569,7 @@ AT_CLEANUP
+ ])
+ 
+ OVN_FOR_EACH_NORTHD_NO_HV([
+-AT_SETUP([LS load balancer logical flows])
++AT_SETUP([LS/LR load balancer logical flows])
+ ovn_start
+ 
+ lbg=$(ovn-nbctl create load_balancer_group name=lbg)
+@@ -5162,15 +5579,16 @@ check ovn-nbctl \
+ lbg0=$(fetch_column nb:load_balancer _uuid name=lbg0)
+ 
+ check ovn-nbctl \
++    -- lr-add lr0 -- set logical_router lr0 options:chassis=hv1 \
++    -- lrp-add lr0 lr0-sw0 00:00:00:00:ff:01 10.0.0.1/24 \
+     -- ls-add sw0 \
++    -- lsp-add-router-port sw0 sw0-lr0 lr0-sw0 \
+     -- add logical_switch sw0 load_balancer_group $lbg \
+     -- ls-lb-add sw0 lb0 \
++    -- add logical_router lr0 load_balancer_group $lbg \
++    -- lr-lb-add lr0 lb0 \
+     -- add load_balancer_group $lbg load_balancer $lbg0
+ 
+-check ovn-nbctl lr-add lr0
+-check ovn-nbctl lrp-add lr0 lr0-sw0 00:00:00:00:ff:01 10.0.0.1/24
+-check ovn-nbctl lsp-add-router-port sw0 sw0-lr0 lr0-sw0
+-
+ check ovn-nbctl --wait=sb sync
+ 
+ check_stateful_flows() {
+@@ -5198,6 +5616,14 @@ check_stateful_flows() {
+   table=??(ls_in_pre_stateful ), priority=120  , match=(reg0[[2]] == 1 && ip4.dst == 10.0.0.20 && tcp.dst == 80), action=(reg4 = 10.0.0.20; reg2[[0..15]] = 80; ct_lb_mark;)
+ ])
+ 
++    AT_CHECK([grep "ls_in_ct_extract" sw0flows | ovn_strip_lflows], [0], [dnl
++  table=??(ls_in_ct_extract   ), priority=0    , match=(1), action=(next;)
++  table=??(ls_in_ct_extract   ), priority=100  , match=(ct.new && ip && ip.is_frag), action=(reg1[[16..23]] = ct_proto(); reg1[[0..15]] = ct_tp_dst(); next;)
++  table=??(ls_in_ct_extract   ), priority=100  , match=(ct.new && ip && sctp && !ip.is_frag), action=(reg1[[16..23]] = ip.proto; reg1[[0..15]] = sctp.dst; next;)
++  table=??(ls_in_ct_extract   ), priority=100  , match=(ct.new && ip && tcp && !ip.is_frag), action=(reg1[[16..23]] = ip.proto; reg1[[0..15]] = tcp.dst; next;)
++  table=??(ls_in_ct_extract   ), priority=100  , match=(ct.new && ip && udp && !ip.is_frag), action=(reg1[[16..23]] = ip.proto; reg1[[0..15]] = udp.dst; next;)
++])
++
+     AT_CHECK([grep "ls_in_lb " sw0flows | ovn_strip_lflows], [0], [dnl
+   table=??(ls_in_lb           ), priority=0    , match=(1), action=(next;)
+   table=??(ls_in_lb           ), priority=110  , match=(ct.trk && ct.est && !ct.rpl && reg0[[19]] == 1 && ip4), action=(reg4 = ct_nw_dst(); reg2[[0..15]] = ct_tp_dst(); next;)
+@@ -5239,6 +5665,30 @@ check_stateful_flows() {
+   table=??(ls_out_stateful    ), priority=110  , match=(reg0[[1]] == 1 && reg0[[13]] == 0 && reg8[[21]] == 1), action=(ct_commit { ct_mark.blocked = 0; ct_mark.allow_established = reg0[[20]]; ct_label.acl_id = reg2[[16..31]]; ct_label.nf = 1; ct_label.nf_id = reg0[[22..29]]; }; next;)
+   table=??(ls_out_stateful    ), priority=110  , match=(reg0[[1]] == 1 && reg0[[13]] == 1 && reg8[[21]] == 1), action=(ct_commit { ct_mark.blocked = 0; ct_mark.allow_established = reg0[[20]]; ct_mark.obs_stage = reg8[[19..20]]; ct_mark.obs_collector_id = reg8[[8..15]]; ct_label.obs_point_id = reg9; ct_label.acl_id = reg2[[16..31]]; ct_label.nf = 1; ct_label.nf_id = reg0[[22..29]]; }; next;)
+ ])
++
++    ovn-sbctl dump-flows lr0 > lr0flows
++    AT_CAPTURE_FILE([lr0flows])
++
++    AT_CHECK([grep "lr_in_ct_extract" lr0flows | ovn_strip_lflows], [0], [dnl
++  table=??(lr_in_ct_extract   ), priority=0    , match=(1), action=(next;)
++  table=??(lr_in_ct_extract   ), priority=100  , match=(ct.new && ip && ip.is_frag), action=(reg1[[16..23]] = ct_proto(); reg1[[0..15]] = ct_tp_dst(); next;)
++  table=??(lr_in_ct_extract   ), priority=100  , match=(ct.new && ip && sctp && !ip.is_frag), action=(reg1[[16..23]] = ip.proto; reg1[[0..15]] = sctp.dst; next;)
++  table=??(lr_in_ct_extract   ), priority=100  , match=(ct.new && ip && tcp && !ip.is_frag), action=(reg1[[16..23]] = ip.proto; reg1[[0..15]] = tcp.dst; next;)
++  table=??(lr_in_ct_extract   ), priority=100  , match=(ct.new && ip && udp && !ip.is_frag), action=(reg1[[16..23]] = ip.proto; reg1[[0..15]] = udp.dst; next;)
++])
++
++    AT_CHECK([grep "lr_in_dnat" lr0flows | ovn_strip_lflows], [0], [dnl
++  table=??(lr_in_dnat         ), priority=0    , match=(1), action=(next;)
++  table=??(lr_in_dnat         ), priority=120  , match=(ct.new && !ct.rel && ip4 && ip4.dst == 10.0.0.10 && reg1[[16..23]] == 6 && reg1[[0..15]] == 80), action=(ct_lb_mark(backends=10.0.0.4:8080);)
++  table=??(lr_in_dnat         ), priority=120  , match=(ct.new && !ct.rel && ip4 && ip4.dst == 10.0.0.20 && reg1[[16..23]] == 6 && reg1[[0..15]] == 80), action=(ct_lb_mark(backends=10.0.0.40:8080);)
++  table=??(lr_in_dnat         ), priority=50   , match=(ct.est && !ct.rel && !ct.new && !ct.rpl && ct_mark.natted), action=(next;)
++  table=??(lr_in_dnat         ), priority=50   , match=(ct.rel && !ct.est && !ct.new && !ct.rpl), action=(ct_commit_nat;)
++  table=??(lr_in_dnat         ), priority=70   , match=(ct.est && !ct.rel && !ct.new && !ct.rpl && ct_mark.natted && ct_mark.force_snat == 1), action=(flags.force_snat_for_lb = 1; next;)
++  table=??(lr_in_dnat         ), priority=70   , match=(ct.est && !ct.rel && !ct.new && !ct.rpl && ct_mark.natted && ct_mark.skip_snat == 1), action=(flags.skip_snat_for_lb = 1; next;)
++  table=??(lr_in_dnat         ), priority=70   , match=(ct.rel && !ct.est && !ct.new && !ct.rpl && ct_mark.force_snat == 1), action=(flags.force_snat_for_lb = 1; ct_commit_nat;)
++  table=??(lr_in_dnat         ), priority=70   , match=(ct.rel && !ct.est && !ct.new && !ct.rpl && ct_mark.skip_snat == 1), action=(flags.skip_snat_for_lb = 1; ct_commit_nat;)
++])
++
+ }
+ 
+ check_stateful_flows "flags.pkt_sampled = 0; ct_clear; next;"
+@@ -5309,6 +5759,22 @@ AT_CHECK([grep "ls_out_stateful" sw0flows | ovn_strip_lflows], [0], [dnl
+   table=??(ls_out_stateful    ), priority=110  , match=(reg0[[1]] == 1 && reg0[[13]] == 1 && reg8[[21]] == 1), action=(ct_commit { ct_mark.blocked = 0; ct_mark.allow_established = reg0[[20]]; ct_mark.obs_stage = reg8[[19..20]]; ct_mark.obs_collector_id = reg8[[8..15]]; ct_label.obs_point_id = reg9; ct_label.acl_id = reg2[[16..31]]; ct_label.nf = 1; ct_label.nf_id = reg0[[22..29]]; }; next;)
+ ])
+ 
++# Remove load balancers from lr0
++check ovn-nbctl lr-lb-del lr0 lb0
++check ovn-nbctl clear logical_router lr0 load_balancer_group
++check ovn-nbctl --wait=sb sync
++
++ovn-sbctl dump-flows lr0 > lr0flows
++AT_CAPTURE_FILE([lr0flows])
++
++AT_CHECK([grep "lr_in_ct_extract" lr0flows | ovn_strip_lflows], [0], [dnl
++  table=??(lr_in_ct_extract   ), priority=0    , match=(1), action=(next;)
++])
++
++AT_CHECK([grep "lr_in_dnat" lr0flows | ovn_strip_lflows], [0], [dnl
++  table=??(lr_in_dnat         ), priority=0    , match=(1), action=(next;)
++])
++
+ # LB with event=false and reject=false
+ AT_CHECK([ovn-nbctl create load_balancer name=lb1 options:reject=false options:event=false vips:\"10.0.0.20\"=\"\" protocol=tcp], [0], [ignore])
+ check ovn-nbctl --wait=sb ls-lb-add sw0 lb1
+@@ -5320,6 +5786,18 @@ AT_CHECK([ovn-sbctl dump-flows sw0 | grep "ls_in_lb " | ovn_strip_lflows ], [0],
+   table=??(ls_in_lb           ), priority=110  , match=(ct.trk && ct.est && !ct.rpl && reg0[[19]] == 1 && ip6), action=(xxreg1 = ct_ip6_dst(); reg2[[0..15]] = ct_tp_dst(); next;)
+ ])
+ 
++check ovn-nbctl --wait=sb lr-lb-add lr0 lb1
++AT_CHECK([ovn-sbctl dump-flows lr0 | grep "lr_in_dnat " | ovn_strip_lflows ], [0], [dnl
++  table=??(lr_in_dnat         ), priority=0    , match=(1), action=(next;)
++  table=??(lr_in_dnat         ), priority=110  , match=(ct.new && !ct.rel && ip4 && ip4.dst == 10.0.0.20), action=(drop;)
++  table=??(lr_in_dnat         ), priority=50   , match=(ct.est && !ct.rel && !ct.new && !ct.rpl && ct_mark.natted), action=(next;)
++  table=??(lr_in_dnat         ), priority=50   , match=(ct.rel && !ct.est && !ct.new && !ct.rpl), action=(ct_commit_nat;)
++  table=??(lr_in_dnat         ), priority=70   , match=(ct.est && !ct.rel && !ct.new && !ct.rpl && ct_mark.natted && ct_mark.force_snat == 1), action=(flags.force_snat_for_lb = 1; next;)
++  table=??(lr_in_dnat         ), priority=70   , match=(ct.est && !ct.rel && !ct.new && !ct.rpl && ct_mark.natted && ct_mark.skip_snat == 1), action=(flags.skip_snat_for_lb = 1; next;)
++  table=??(lr_in_dnat         ), priority=70   , match=(ct.rel && !ct.est && !ct.new && !ct.rpl && ct_mark.force_snat == 1), action=(flags.force_snat_for_lb = 1; ct_commit_nat;)
++  table=??(lr_in_dnat         ), priority=70   , match=(ct.rel && !ct.est && !ct.new && !ct.rpl && ct_mark.skip_snat == 1), action=(flags.skip_snat_for_lb = 1; ct_commit_nat;)
++])
++
+ OVN_CLEANUP_NORTHD
+ AT_CLEANUP
+ ])
+@@ -7519,18 +7997,18 @@ check_row_count ECMP_Nexthop 1
+ 
+ ovn-sbctl dump-flows lr0 > lr0flows
+ 
+-AT_CHECK([grep -w "lr_in_ip_routing" lr0flows | ovn_strip_lflows], [0], [dnl
++AT_CHECK([grep -w "lr_in_ip_routing" lr0flows | ovn_strip_ecmp_ids | ovn_strip_lflows], [0], [dnl
+   table=??(lr_in_ip_routing   ), priority=0    , match=(1), action=(drop;)
+   table=??(lr_in_ip_routing   ), priority=10300, match=(ct_mark.ecmp_reply_port == 1 && reg7 == 0 && ip4.dst == 1.0.0.1/32), action=(ip.ttl--; flags.loopback = 1; eth.src = 00:00:20:20:12:13; reg5 = 192.168.0.1; outport = "lr0-public"; next;)
+   table=??(lr_in_ip_routing   ), priority=10550, match=(nd_rs || nd_ra), action=(drop;)
+   table=??(lr_in_ip_routing   ), priority=1842 , match=(ip4.dst == 192.168.0.0/24), action=(ip.ttl--; reg8[[0..15]] = 0; reg0 = ip4.dst; reg5 = 192.168.0.1; eth.src = 00:00:20:20:12:13; outport = "lr0-public"; flags.loopback = 1; reg9[[9]] = 1; next;)
+-  table=??(lr_in_ip_routing   ), priority=1936 , match=(reg7 == 0 && ip4.dst == 1.0.0.1/32), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = 1; reg8[[16..31]] = 1; next;)
++  table=??(lr_in_ip_routing   ), priority=1936 , match=(reg7 == 0 && ip4.dst == 1.0.0.1/32), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = <gid>; reg8[[16..31]] = <mid>; next;)
+   table=??(lr_in_ip_routing   ), priority=2322 , match=(inport == "lr0-public" && ip6.dst == fe80::/64), action=(ip.ttl--; reg8[[0..15]] = 0; xxreg0 = ip6.dst; xxreg1 = fe80::200:20ff:fe20:1213; eth.src = 00:00:20:20:12:13; outport = "lr0-public"; flags.loopback = 1; reg9[[9]] = 0; next;)
+ ])
+ 
+-AT_CHECK([grep -e "lr_in_ip_routing_ecmp" lr0flows | ovn_strip_lflows], [0], [dnl
++AT_CHECK([grep -e "lr_in_ip_routing_ecmp" lr0flows | ovn_strip_ecmp_ids | ovn_strip_lflows], [0], [dnl
+   table=??(lr_in_ip_routing_ecmp), priority=0    , match=(1), action=(drop;)
+-  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == 1 && reg8[[16..31]] == 1), action=(reg0 = 192.168.0.10; reg5 = 192.168.0.1; eth.src = 00:00:20:20:12:13; outport = "lr0-public"; reg9[[9]] = 1; reg9[[10]] = 1; next;)
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(reg0 = 192.168.0.10; reg5 = 192.168.0.1; eth.src = 00:00:20:20:12:13; outport = "lr0-public"; reg9[[9]] = 1; reg9[[10]] = 1; next;)
+   table=??(lr_in_ip_routing_ecmp), priority=150  , match=(reg8[[0..15]] == 0), action=(next;)
+ ])
+ 
+@@ -7545,18 +8023,18 @@ check_column 192.168.0.10 ECMP_Nexthop nexthop nexthop=192.168.0.10
+ check_column 192.168.0.20 ECMP_Nexthop nexthop nexthop=192.168.0.20
+ 
+ ovn-sbctl dump-flows lr0 > lr0flows
+-AT_CHECK([grep -w "lr_in_ip_routing" lr0flows | ovn_strip_lflows], [0], [dnl
++AT_CHECK([grep -w "lr_in_ip_routing" lr0flows | ovn_strip_ecmp_ids | ovn_strip_lflows], [0], [dnl
+   table=??(lr_in_ip_routing   ), priority=0    , match=(1), action=(drop;)
+   table=??(lr_in_ip_routing   ), priority=10300, match=(ct_mark.ecmp_reply_port == 1 && reg7 == 0 && ip4.dst == 1.0.0.1/32), action=(ip.ttl--; flags.loopback = 1; eth.src = 00:00:20:20:12:13; reg5 = 192.168.0.1; outport = "lr0-public"; next;)
+   table=??(lr_in_ip_routing   ), priority=10550, match=(nd_rs || nd_ra), action=(drop;)
+   table=??(lr_in_ip_routing   ), priority=1842 , match=(ip4.dst == 192.168.0.0/24), action=(ip.ttl--; reg8[[0..15]] = 0; reg0 = ip4.dst; reg5 = 192.168.0.1; eth.src = 00:00:20:20:12:13; outport = "lr0-public"; flags.loopback = 1; reg9[[9]] = 1; next;)
+-  table=??(lr_in_ip_routing   ), priority=1936 , match=(reg7 == 0 && ip4.dst == 1.0.0.1/32), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = 1; reg8[[16..31]] = select(1, 2);)
++  table=??(lr_in_ip_routing   ), priority=1936 , match=(reg7 == 0 && ip4.dst == 1.0.0.1/32), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = <gid>; reg8[[16..31]] = select(<mid>, <mid>);)
+   table=??(lr_in_ip_routing   ), priority=2322 , match=(inport == "lr0-public" && ip6.dst == fe80::/64), action=(ip.ttl--; reg8[[0..15]] = 0; xxreg0 = ip6.dst; xxreg1 = fe80::200:20ff:fe20:1213; eth.src = 00:00:20:20:12:13; outport = "lr0-public"; flags.loopback = 1; reg9[[9]] = 0; next;)
+ ])
+-AT_CHECK([grep -e "lr_in_ip_routing_ecmp" lr0flows | sed 's/192\.168\.0\..0/192.168.0.??/' | ovn_strip_lflows], [0], [dnl
++AT_CHECK([grep -e "lr_in_ip_routing_ecmp" lr0flows | sed 's/192\.168\.0\..0/192.168.0.??/' | ovn_strip_ecmp_ids | ovn_strip_lflows], [0], [dnl
+   table=??(lr_in_ip_routing_ecmp), priority=0    , match=(1), action=(drop;)
+-  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == 1 && reg8[[16..31]] == 1), action=(reg0 = 192.168.0.??; reg5 = 192.168.0.1; eth.src = 00:00:20:20:12:13; outport = "lr0-public"; reg9[[9]] = 1; reg9[[10]] = 1; next;)
+-  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == 1 && reg8[[16..31]] == 2), action=(reg0 = 192.168.0.??; reg5 = 192.168.0.1; eth.src = 00:00:20:20:12:13; outport = "lr0-public"; reg9[[9]] = 1; reg9[[10]] = 1; next;)
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(reg0 = 192.168.0.??; reg5 = 192.168.0.1; eth.src = 00:00:20:20:12:13; outport = "lr0-public"; reg9[[9]] = 1; reg9[[10]] = 1; next;)
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(reg0 = 192.168.0.??; reg5 = 192.168.0.1; eth.src = 00:00:20:20:12:13; outport = "lr0-public"; reg9[[9]] = 1; reg9[[10]] = 1; next;)
+   table=??(lr_in_ip_routing_ecmp), priority=150  , match=(reg8[[0..15]] == 0), action=(next;)
+ ])
+ 
+@@ -7587,18 +8065,18 @@ check_column 192.168.0.10 ECMP_Nexthop nexthop nexthop=192.168.0.10
+ check_column 192.168.0.20 ECMP_Nexthop nexthop nexthop=192.168.0.20
+ 
+ ovn-sbctl dump-flows lr0 > lr0flows
+-AT_CHECK([grep -w "lr_in_ip_routing" lr0flows | ovn_strip_lflows], [0], [dnl
++AT_CHECK([grep -w "lr_in_ip_routing" lr0flows | ovn_strip_ecmp_ids | ovn_strip_lflows], [0], [dnl
+   table=??(lr_in_ip_routing   ), priority=0    , match=(1), action=(drop;)
+   table=??(lr_in_ip_routing   ), priority=10300, match=(ct_mark.ecmp_reply_port == 1 && reg7 == 0 && ip4.dst == 1.0.0.1/32), action=(ip.ttl--; flags.loopback = 1; eth.src = 00:00:20:20:12:13; reg5 = 192.168.0.1; outport = "lr0-public"; next;)
+   table=??(lr_in_ip_routing   ), priority=10550, match=(nd_rs || nd_ra), action=(drop;)
+   table=??(lr_in_ip_routing   ), priority=1842 , match=(ip4.dst == 192.168.0.0/24), action=(ip.ttl--; reg8[[0..15]] = 0; reg0 = ip4.dst; reg5 = 192.168.0.1; eth.src = 00:00:20:20:12:13; outport = "lr0-public"; flags.loopback = 1; reg9[[9]] = 1; next;)
+-  table=??(lr_in_ip_routing   ), priority=1936 , match=(reg7 == 0 && ip4.dst == 1.0.0.1/32), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = 1; reg8[[16..31]] = select(1, 2);)
++  table=??(lr_in_ip_routing   ), priority=1936 , match=(reg7 == 0 && ip4.dst == 1.0.0.1/32), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = <gid>; reg8[[16..31]] = select(<mid>, <mid>);)
+   table=??(lr_in_ip_routing   ), priority=2322 , match=(inport == "lr0-public" && ip6.dst == fe80::/64), action=(ip.ttl--; reg8[[0..15]] = 0; xxreg0 = ip6.dst; xxreg1 = fe80::200:20ff:fe20:1213; eth.src = 00:00:20:20:12:13; outport = "lr0-public"; flags.loopback = 1; reg9[[9]] = 0; next;)
+ ])
+-AT_CHECK([grep -e "lr_in_ip_routing_ecmp" lr0flows | sed 's/192\.168\.0\..0/192.168.0.??/' | ovn_strip_lflows], [0], [dnl
++AT_CHECK([grep -e "lr_in_ip_routing_ecmp" lr0flows | sed 's/192\.168\.0\..0/192.168.0.??/' | ovn_strip_ecmp_ids | ovn_strip_lflows], [0], [dnl
+   table=??(lr_in_ip_routing_ecmp), priority=0    , match=(1), action=(drop;)
+-  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == 1 && reg8[[16..31]] == 1), action=(reg0 = 192.168.0.??; reg5 = 192.168.0.1; eth.src = 00:00:20:20:12:13; outport = "lr0-public"; reg9[[9]] = 1; reg9[[10]] = 1; next;)
+-  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == 1 && reg8[[16..31]] == 2), action=(reg0 = 192.168.0.??; reg5 = 192.168.0.1; eth.src = 00:00:20:20:12:13; outport = "lr0-public"; reg9[[9]] = 1; reg9[[10]] = 1; next;)
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(reg0 = 192.168.0.??; reg5 = 192.168.0.1; eth.src = 00:00:20:20:12:13; outport = "lr0-public"; reg9[[9]] = 1; reg9[[10]] = 1; next;)
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(reg0 = 192.168.0.??; reg5 = 192.168.0.1; eth.src = 00:00:20:20:12:13; outport = "lr0-public"; reg9[[9]] = 1; reg9[[10]] = 1; next;)
+   table=??(lr_in_ip_routing_ecmp), priority=150  , match=(reg8[[0..15]] == 0), action=(next;)
+ ])
+ 
+@@ -7636,8 +8114,8 @@ check ovn-nbctl set logical_router_static_route $route2_uuid selection_fields="i
+ 
+ check ovn-nbctl --wait=sb sync
+ ovn-sbctl dump-flows lr0 > lr0flows
+-AT_CHECK([grep -e "(lr_in_ip_routing   ).*3.3.0.0" lr0flows | sed 's/table=../table=??/' | sort], [0], [dnl
+-  table=??(lr_in_ip_routing   ), priority=1744 , match=(reg7 == 0 && ip4.dst == 3.3.0.0/16), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = 1; reg8[[16..31]] = select(values=(1, 2); hash_fields="ip_dst,ip_proto,ip_src");)
++AT_CHECK([grep -e "(lr_in_ip_routing   ).*3.3.0.0" lr0flows | ovn_strip_ecmp_ids | sed 's/table=../table=??/' | sort], [0], [dnl
++  table=??(lr_in_ip_routing   ), priority=1744 , match=(reg7 == 0 && ip4.dst == 3.3.0.0/16), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = <gid>; reg8[[16..31]] = select(values=(<mid>, <mid>); hash_fields="ip_dst,ip_proto,ip_src");)
+ ])
+ 
+ check ovn-nbctl set logical_router_static_route $route1_uuid selection_fields="ip_src,ip_dst,tp_src,tp_dst"
+@@ -7645,11 +8123,11 @@ check ovn-nbctl set logical_router_static_route $route2_uuid selection_fields="i
+ 
+ check ovn-nbctl --wait=sb sync
+ ovn-sbctl dump-flows lr0 > lr0flows
+-AT_CHECK([grep -e "(lr_in_ip_routing   ).*3.3.0.0" lr0flows | sed 's/table=../table=??/' | sort], [0], [dnl
+-  table=??(lr_in_ip_routing   ), priority=1744 , match=(reg7 == 0 && ip4.dst == 3.3.0.0/16), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = 1; reg8[[16..31]] = select(values=(1, 2); hash_fields="ip_dst,ip_proto,ip_src");)
+-  table=??(lr_in_ip_routing   ), priority=1745 , match=(reg7 == 0 && ip4.dst == 3.3.0.0/16 && sctp), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = 1; reg8[[16..31]] = select(values=(1, 2); hash_fields="ip_dst,ip_proto,ip_src,sctp_dst,sctp_src");)
+-  table=??(lr_in_ip_routing   ), priority=1745 , match=(reg7 == 0 && ip4.dst == 3.3.0.0/16 && tcp), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = 1; reg8[[16..31]] = select(values=(1, 2); hash_fields="ip_dst,ip_proto,ip_src,tcp_dst,tcp_src");)
+-  table=??(lr_in_ip_routing   ), priority=1745 , match=(reg7 == 0 && ip4.dst == 3.3.0.0/16 && udp), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = 1; reg8[[16..31]] = select(values=(1, 2); hash_fields="ip_dst,ip_proto,ip_src,udp_dst,udp_src");)
++AT_CHECK([grep -e "(lr_in_ip_routing   ).*3.3.0.0" lr0flows | ovn_strip_ecmp_ids | sed 's/table=../table=??/' | sort], [0], [dnl
++  table=??(lr_in_ip_routing   ), priority=1744 , match=(reg7 == 0 && ip4.dst == 3.3.0.0/16), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = <gid>; reg8[[16..31]] = select(values=(<mid>, <mid>); hash_fields="ip_dst,ip_proto,ip_src");)
++  table=??(lr_in_ip_routing   ), priority=1745 , match=(reg7 == 0 && ip4.dst == 3.3.0.0/16 && sctp), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = <gid>; reg8[[16..31]] = select(values=(<mid>, <mid>); hash_fields="ip_dst,ip_proto,ip_src,sctp_dst,sctp_src");)
++  table=??(lr_in_ip_routing   ), priority=1745 , match=(reg7 == 0 && ip4.dst == 3.3.0.0/16 && tcp), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = <gid>; reg8[[16..31]] = select(values=(<mid>, <mid>); hash_fields="ip_dst,ip_proto,ip_src,tcp_dst,tcp_src");)
++  table=??(lr_in_ip_routing   ), priority=1745 , match=(reg7 == 0 && ip4.dst == 3.3.0.0/16 && udp), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = <gid>; reg8[[16..31]] = select(values=(<mid>, <mid>); hash_fields="ip_dst,ip_proto,ip_src,udp_dst,udp_src");)
+ ])
+ 
+ AT_CHECK([grep -e "lr_in_ecmp_stateful_egr" lr0flows | ovn_strip_lflows], [0], [dnl
+@@ -7972,7 +8450,19 @@ AT_CAPTURE_FILE([S1flows])
  AT_CHECK([grep -e "ls_in_l2_lkup.*S1-vm1" S1flows | grep -e "match=(eth.dst == 50:54:00:00:00:01)"], [1], [])
  AT_CHECK([grep -e "ls_in_.*_fdb.*S1-vm1" S1flows | ovn_strip_lflows], [0], [dnl
    table=??(ls_in_lookup_fdb   ), priority=100  , match=(inport == "S1-vm1"), action=(reg0[[11]] = lookup_fdb(inport, eth.src); next;)
@@ -1887,7 +4434,7 @@ index 4acdc677a..3ed3da542 100644
  ])
  
  #Verify the flows for a non-default port type (localnet port)
-@@ -7985,6 +8229,120 @@ AT_CLEANUP
+@@ -7985,6 +8475,120 @@ AT_CLEANUP
  ])
  
  
@@ -2008,7 +4555,7 @@ index 4acdc677a..3ed3da542 100644
  OVN_FOR_EACH_NORTHD_NO_HV([
  AT_SETUP([check options:pkt_clone_type for LSP])
  ovn_start
-@@ -8056,7 +8414,19 @@ AT_CHECK([grep -E "ls_in_l2_lkup.*S1-|unknown" S1flows | ovn_strip_lflows], [0],
+@@ -8056,7 +8660,19 @@ AT_CHECK([grep -E "ls_in_l2_lkup.*S1-|unknown" S1flows | ovn_strip_lflows], [0],
  dnl Check that FDB learning is enabled for the switch port.
  AT_CHECK([grep -E "ls_.*fdb.*S1-" S1flows | ovn_strip_lflows], [0], [dnl
    table=??(ls_in_lookup_fdb   ), priority=100  , match=(inport == "S1-S2"), action=(reg0[[11]] = lookup_fdb(inport, eth.src); next;)
@@ -2028,7 +4575,7 @@ index 4acdc677a..3ed3da542 100644
  ])
  
  ovn-sbctl dump-flows S2 > S2flows
-@@ -8073,7 +8443,19 @@ AT_CHECK([grep -E "ls_in_l2_lkup.*S2-|unknown" S2flows | ovn_strip_lflows], [0],
+@@ -8073,7 +8689,19 @@ AT_CHECK([grep -E "ls_in_l2_lkup.*S2-|unknown" S2flows | ovn_strip_lflows], [0],
  dnl Check that FDB learning is enabled for the switch port.
  AT_CHECK([grep -E "ls_.*fdb.*S2-" S2flows | ovn_strip_lflows], [0], [dnl
    table=??(ls_in_lookup_fdb   ), priority=100  , match=(inport == "S2-S1"), action=(reg0[[11]] = lookup_fdb(inport, eth.src); next;)
@@ -2048,7 +4595,7 @@ index 4acdc677a..3ed3da542 100644
  ])
  
  dnl Add an explicit address to S1-S2 indicating that the port with
-@@ -8094,7 +8476,19 @@ AT_CHECK([grep -E "ls_in_l2_lkup.*S1-|unknown" S1flows2 | ovn_strip_lflows], [0]
+@@ -8094,7 +8722,19 @@ AT_CHECK([grep -E "ls_in_l2_lkup.*S1-|unknown" S1flows2 | ovn_strip_lflows], [0]
  dnl Check that FDB learning is still enabled for the switch port.
  AT_CHECK([grep -E "ls_.*fdb.*S1-" S1flows | ovn_strip_lflows], [0], [dnl
    table=??(ls_in_lookup_fdb   ), priority=100  , match=(inport == "S1-S2"), action=(reg0[[11]] = lookup_fdb(inport, eth.src); next;)
@@ -2068,7 +4615,16 @@ index 4acdc677a..3ed3da542 100644
  ])
  
  OVN_CLEANUP_NORTHD
-@@ -10375,9 +10769,21 @@ AT_CHECK([ovn-nbctl --wait=sb lsp-set-options ln_port localnet_learn_fdb=true])
+@@ -8138,8 +8778,6 @@ flow="eth.dst == 00:00:00:00:01:00 && inport == \"rtr-ls\" && ip4.src == 42.42.4
+ ovn_trace --ct new "${flow}" --lb-dst 42.42.42.42:4242
+ AT_CHECK_UNQUOTED([ovn_trace --ct new --minimal "${flow}" --lb-dst 42.42.42.42:4242], [0], [dnl
+ ct_dnat /* assuming no un-dnat entry, so no change */ {
+-    reg1[[16..23]] = 6;
+-    reg1[[0..15]] = 4343;
+     ct_lb_mark /* default (use --ct to customize) */ {
+         ip.ttl--;
+         eth.src = 00:00:00:00:01:00;
+@@ -10375,9 +11013,21 @@ AT_CHECK([ovn-nbctl --wait=sb lsp-set-options ln_port localnet_learn_fdb=true])
  AT_CHECK([ovn-sbctl dump-flows ls0 | grep -e 'ls_in_\(put\|lookup\)_fdb' | ovn_strip_lflows], [0], [dnl
    table=??(ls_in_lookup_fdb   ), priority=0    , match=(1), action=(next;)
    table=??(ls_in_lookup_fdb   ), priority=100  , match=(inport == "ln_port"), action=(flags.localnet = 1; reg0[[11]] = lookup_fdb(inport, eth.src); next;)
@@ -2090,7 +4646,7 @@ index 4acdc677a..3ed3da542 100644
  ])
  
  # Disable 'localnet_learn_fdb' and check the flows
-@@ -10798,6 +11204,12 @@ dnl priority 50 fallback.
+@@ -10798,6 +11448,12 @@ dnl priority 50 fallback.
  AT_CHECK([ovn-sbctl dump-flows ls1 | grep -e 'ls_in_lookup_fdb' | ovn_strip_lflows], [0], [dnl
    table=??(ls_in_lookup_fdb   ), priority=0    , match=(1), action=(next;)
    table=??(ls_in_lookup_fdb   ), priority=100  , match=(inport == "ln1"), action=(flags.localnet = 1; reg0[[11]] = lookup_fdb(inport, eth.src); next;)
@@ -2103,7 +4659,275 @@ index 4acdc677a..3ed3da542 100644
    table=??(ls_in_lookup_fdb   ), priority=50   , match=(inport == "ln1"), action=(flags.localnet = 1; next;)
  ])
  
-@@ -20799,6 +21211,114 @@ OVN_CLEANUP_NORTHD
+@@ -16013,7 +16669,7 @@ AT_SETUP([RBAC -- Recover builtin role and permissions])
+ ovn_start
+ 
+ wait_row_count RBAC_Role 1 name=ovn-controller
+-RBR_BUILTIN_PNAMES=$(fetch_column RBAC_Role permissions name=ovn-controller | uuidfilt | sed -e 's/<[[^<>]]>*//g' | tr -d '=,{}')
++RBR_BUILTIN_PNAMES=$(fetch_column RBAC_Role permissions name=ovn-controller | uuidfilt | sed -e 's/<[[^<>]]*>//g' | tr -d '=,{}')
+ 
+ declare -A RBR_BUILTIN_PERM
+ 
+@@ -16024,15 +16680,15 @@ do
+ done
+ 
+ rbr_match_builtin() {
+-  local RBR_REAL_PNAMES=$(fetch_column RBAC_Role permissions name=ovn-controller | uuidfilt | sed -e 's/<[[^<>]]>*//g' | tr -d '=,{}')
++  local RBR_REAL_PNAMES=$(fetch_column RBAC_Role permissions name=ovn-controller | uuidfilt | sed -e 's/<[[^<>]]*>//g' | tr -d '=,{}')
+ 
+-  AT_CHECK([test "$RBR_BUILTIN_PNAMES" == "$RBR_REAL_PNAMES"])
++  test "$RBR_BUILTIN_PNAMES" == "$RBR_REAL_PNAMES" || return 1
+ 
+   for V in $RBR_BUILTIN_PNAMES
+   do
+     local _UUID=`ovn-sbctl get RBAC_Role ovn-controller permissions:$V`
+     local RBR_REAL_PERM=`ovn-sbctl get RBAC_Permission $_UUID authorization insert_delete table update | paste -s -d " "`
+-    AT_CHECK([test "${RBR_BUILTIN_PERM[[$V]]}" == "$RBR_REAL_PERM"])
++    test "${RBR_BUILTIN_PERM[[$V]]}" == "$RBR_REAL_PERM" || return 1
+   done
+ }
+ 
+@@ -16045,13 +16701,13 @@ rbr_match_custom() {
+    [[Load_Balancer]]='[[]] false Load_Balancer [[]]'
+   )
+ 
+-  AT_CHECK([test "$RBR_BUILTIN_ROLE" == "$RBR_REAL_ROLE"])
++  test "$RBR_BUILTIN_ROLE" == "$RBR_REAL_ROLE" || return 1
+ 
+   for V in $RBR_BUILTIN_PNAMES
+   do
+     local _UUID=`ovn-sbctl get RBAC_Role custom-role permissions:$V`
+     local _PREAL=`ovn-sbctl get RBAC_Permission $_UUID authorization insert_delete table update | paste -s -d " "`
+-    AT_CHECK([test "${RBR_BUILTIN_PERM[[$V]]}" == "$_PREAL"])
++    test "${RBR_BUILTIN_PERM[[$V]]}" == "$_PREAL" || return 1
+   done
+ }
+ 
+@@ -16065,7 +16721,7 @@ OVS_WAIT_UNTIL([rbr_match_builtin])
+ 
+ AS_BOX([Recover after permission delete])
+ PERM_UID=`ovn-sbctl get RBAC_Role ovn-controller permissions:Chassis`
+-check check ovn-sbctl destroy RBAC_Permission $PERM_UID
++check ovn-sbctl destroy RBAC_Permission $PERM_UID
+ OVS_WAIT_UNTIL([rbr_match_builtin])
+ 
+ AS_BOX([Recover after permission link removal from role])
+@@ -16861,19 +17517,19 @@ datapath=$(fetch_column datapath_binding _uuid external_ids:name=lr0)
+ 
+ # Validate the routes.
+ ovn-sbctl dump-flows lr0 > lr0flows
+-AT_CHECK([grep -w "lr_in_ip_routing" lr0flows | ovn_strip_lflows], [0], [dnl
++AT_CHECK([grep -w "lr_in_ip_routing" lr0flows | ovn_strip_ecmp_ids | ovn_strip_lflows], [0], [dnl
+   table=??(lr_in_ip_routing   ), priority=0    , match=(1), action=(drop;)
+   table=??(lr_in_ip_routing   ), priority=10550, match=(nd_rs || nd_ra), action=(drop;)
+-  table=??(lr_in_ip_routing   ), priority=1840 , match=(reg7 == 0 && ip4.dst == 192.168.0.0/24), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = 1; reg8[[16..31]] = select(1, 2);)
++  table=??(lr_in_ip_routing   ), priority=1840 , match=(reg7 == 0 && ip4.dst == 192.168.0.0/24), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = <gid>; reg8[[16..31]] = select(<mid>, <mid>);)
+   table=??(lr_in_ip_routing   ), priority=1842 , match=(ip4.dst == 10.0.0.0/24), action=(ip.ttl--; reg8[[0..15]] = 0; reg0 = ip4.dst; reg5 = 10.0.0.1; eth.src = 00:00:00:00:ff:01; outport = "lr0-sw0"; flags.loopback = 1; reg9[[9]] = 1; next;)
+   table=??(lr_in_ip_routing   ), priority=1842 , match=(ip4.dst == 10.0.1.0/24), action=(ip.ttl--; reg8[[0..15]] = 0; reg0 = ip4.dst; reg5 = 10.0.1.1; eth.src = 00:00:00:00:ff:02; outport = "lr0-sw1"; flags.loopback = 1; reg9[[9]] = 1; next;)
+   table=??(lr_in_ip_routing   ), priority=2322 , match=(inport == "lr0-sw0" && ip6.dst == fe80::/64), action=(ip.ttl--; reg8[[0..15]] = 0; xxreg0 = ip6.dst; xxreg1 = fe80::200:ff:fe00:ff01; eth.src = 00:00:00:00:ff:01; outport = "lr0-sw0"; flags.loopback = 1; reg9[[9]] = 0; next;)
+   table=??(lr_in_ip_routing   ), priority=2322 , match=(inport == "lr0-sw1" && ip6.dst == fe80::/64), action=(ip.ttl--; reg8[[0..15]] = 0; xxreg0 = ip6.dst; xxreg1 = fe80::200:ff:fe00:ff02; eth.src = 00:00:00:00:ff:02; outport = "lr0-sw1"; flags.loopback = 1; reg9[[9]] = 0; next;)
+ ])
+-AT_CHECK([grep -e "lr_in_ip_routing_ecmp" lr0flows | sed -e 's/10\.0\..\./10.0.??./g' -e 's/lr0-sw./lr0-sw??/' -e 's/00:ff:0./00:ff:0?/' | ovn_strip_lflows], [0], [dnl
++AT_CHECK([grep -e "lr_in_ip_routing_ecmp" lr0flows | sed -e 's/10\.0\..\./10.0.??./g' -e 's/lr0-sw./lr0-sw??/' -e 's/00:ff:0./00:ff:0?/' | ovn_strip_ecmp_ids | ovn_strip_lflows], [0], [dnl
+   table=??(lr_in_ip_routing_ecmp), priority=0    , match=(1), action=(drop;)
+-  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == 1 && reg8[[16..31]] == 1), action=(reg0 = 10.0.??.10; reg5 = 10.0.??.1; eth.src = 00:00:00:00:ff:0?; outport = "lr0-sw??"; reg9[[9]] = 1; next;)
+-  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == 1 && reg8[[16..31]] == 2), action=(reg0 = 10.0.??.10; reg5 = 10.0.??.1; eth.src = 00:00:00:00:ff:0?; outport = "lr0-sw??"; reg9[[9]] = 1; next;)
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(reg0 = 10.0.??.10; reg5 = 10.0.??.1; eth.src = 00:00:00:00:ff:0?; outport = "lr0-sw??"; reg9[[9]] = 1; next;)
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(reg0 = 10.0.??.10; reg5 = 10.0.??.1; eth.src = 00:00:00:00:ff:0?; outport = "lr0-sw??"; reg9[[9]] = 1; next;)
+   table=??(lr_in_ip_routing_ecmp), priority=150  , match=(reg8[[0..15]] == 0), action=(next;)
+ ])
+ 
+@@ -16887,20 +17543,20 @@ check ovn-nbctl --wait=sb sync
+ check_row_count Advertised_Route 4
+ check_row_count Learned_Route 1
+ ovn-sbctl dump-flows lr0 > lr0flows
+-AT_CHECK([grep -w "lr_in_ip_routing" lr0flows | ovn_strip_lflows], [0], [dnl
++AT_CHECK([grep -w "lr_in_ip_routing" lr0flows | ovn_strip_ecmp_ids | ovn_strip_lflows], [0], [dnl
+   table=??(lr_in_ip_routing   ), priority=0    , match=(1), action=(drop;)
+   table=??(lr_in_ip_routing   ), priority=10550, match=(nd_rs || nd_ra), action=(drop;)
+   table=??(lr_in_ip_routing   ), priority=1838 , match=(reg7 == 0 && ip4.dst == 192.168.1.0/24), action=(ip.ttl--; reg8[[0..15]] = 0; reg0 = 10.0.0.20; reg5 = 10.0.0.1; eth.src = 00:00:00:00:ff:01; outport = "lr0-sw0"; flags.loopback = 1; reg9[[9]] = 1; next;)
+-  table=??(lr_in_ip_routing   ), priority=1840 , match=(reg7 == 0 && ip4.dst == 192.168.0.0/24), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = 1; reg8[[16..31]] = select(1, 2);)
++  table=??(lr_in_ip_routing   ), priority=1840 , match=(reg7 == 0 && ip4.dst == 192.168.0.0/24), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = <gid>; reg8[[16..31]] = select(<mid>, <mid>);)
+   table=??(lr_in_ip_routing   ), priority=1842 , match=(ip4.dst == 10.0.0.0/24), action=(ip.ttl--; reg8[[0..15]] = 0; reg0 = ip4.dst; reg5 = 10.0.0.1; eth.src = 00:00:00:00:ff:01; outport = "lr0-sw0"; flags.loopback = 1; reg9[[9]] = 1; next;)
+   table=??(lr_in_ip_routing   ), priority=1842 , match=(ip4.dst == 10.0.1.0/24), action=(ip.ttl--; reg8[[0..15]] = 0; reg0 = ip4.dst; reg5 = 10.0.1.1; eth.src = 00:00:00:00:ff:02; outport = "lr0-sw1"; flags.loopback = 1; reg9[[9]] = 1; next;)
+   table=??(lr_in_ip_routing   ), priority=2322 , match=(inport == "lr0-sw0" && ip6.dst == fe80::/64), action=(ip.ttl--; reg8[[0..15]] = 0; xxreg0 = ip6.dst; xxreg1 = fe80::200:ff:fe00:ff01; eth.src = 00:00:00:00:ff:01; outport = "lr0-sw0"; flags.loopback = 1; reg9[[9]] = 0; next;)
+   table=??(lr_in_ip_routing   ), priority=2322 , match=(inport == "lr0-sw1" && ip6.dst == fe80::/64), action=(ip.ttl--; reg8[[0..15]] = 0; xxreg0 = ip6.dst; xxreg1 = fe80::200:ff:fe00:ff02; eth.src = 00:00:00:00:ff:02; outport = "lr0-sw1"; flags.loopback = 1; reg9[[9]] = 0; next;)
+ ])
+-AT_CHECK([grep -e "lr_in_ip_routing_ecmp" lr0flows | sed -e 's/10\.0\..\./10.0.??./g' -e 's/lr0-sw./lr0-sw??/' -e 's/00:ff:0./00:ff:0?/' | ovn_strip_lflows], [0], [dnl
++AT_CHECK([grep -e "lr_in_ip_routing_ecmp" lr0flows | sed -e 's/10\.0\..\./10.0.??./g' -e 's/lr0-sw./lr0-sw??/' -e 's/00:ff:0./00:ff:0?/' | ovn_strip_ecmp_ids | ovn_strip_lflows], [0], [dnl
+   table=??(lr_in_ip_routing_ecmp), priority=0    , match=(1), action=(drop;)
+-  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == 1 && reg8[[16..31]] == 1), action=(reg0 = 10.0.??.10; reg5 = 10.0.??.1; eth.src = 00:00:00:00:ff:0?; outport = "lr0-sw??"; reg9[[9]] = 1; next;)
+-  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == 1 && reg8[[16..31]] == 2), action=(reg0 = 10.0.??.10; reg5 = 10.0.??.1; eth.src = 00:00:00:00:ff:0?; outport = "lr0-sw??"; reg9[[9]] = 1; next;)
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(reg0 = 10.0.??.10; reg5 = 10.0.??.1; eth.src = 00:00:00:00:ff:0?; outport = "lr0-sw??"; reg9[[9]] = 1; next;)
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(reg0 = 10.0.??.10; reg5 = 10.0.??.1; eth.src = 00:00:00:00:ff:0?; outport = "lr0-sw??"; reg9[[9]] = 1; next;)
+   table=??(lr_in_ip_routing_ecmp), priority=150  , match=(reg8[[0..15]] == 0), action=(next;)
+ ])
+ 
+@@ -16915,22 +17571,22 @@ check ovn-nbctl --wait=sb sync
+ check_row_count Advertised_Route 4
+ check_row_count Learned_Route 2
+ ovn-sbctl dump-flows lr0 > lr0flows
+-AT_CHECK([grep -w "lr_in_ip_routing" lr0flows | ovn_strip_lflows], [0], [dnl
++AT_CHECK([grep -w "lr_in_ip_routing" lr0flows | ovn_strip_ecmp_ids | ovn_strip_lflows], [0], [dnl
+   table=??(lr_in_ip_routing   ), priority=0    , match=(1), action=(drop;)
+   table=??(lr_in_ip_routing   ), priority=10550, match=(nd_rs || nd_ra), action=(drop;)
+-  table=??(lr_in_ip_routing   ), priority=1838 , match=(reg7 == 0 && ip4.dst == 192.168.1.0/24), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = 2; reg8[[16..31]] = select(1, 2);)
+-  table=??(lr_in_ip_routing   ), priority=1840 , match=(reg7 == 0 && ip4.dst == 192.168.0.0/24), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = 1; reg8[[16..31]] = select(1, 2);)
++  table=??(lr_in_ip_routing   ), priority=1838 , match=(reg7 == 0 && ip4.dst == 192.168.1.0/24), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = <gid>; reg8[[16..31]] = select(<mid>, <mid>);)
++  table=??(lr_in_ip_routing   ), priority=1840 , match=(reg7 == 0 && ip4.dst == 192.168.0.0/24), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = <gid>; reg8[[16..31]] = select(<mid>, <mid>);)
+   table=??(lr_in_ip_routing   ), priority=1842 , match=(ip4.dst == 10.0.0.0/24), action=(ip.ttl--; reg8[[0..15]] = 0; reg0 = ip4.dst; reg5 = 10.0.0.1; eth.src = 00:00:00:00:ff:01; outport = "lr0-sw0"; flags.loopback = 1; reg9[[9]] = 1; next;)
+   table=??(lr_in_ip_routing   ), priority=1842 , match=(ip4.dst == 10.0.1.0/24), action=(ip.ttl--; reg8[[0..15]] = 0; reg0 = ip4.dst; reg5 = 10.0.1.1; eth.src = 00:00:00:00:ff:02; outport = "lr0-sw1"; flags.loopback = 1; reg9[[9]] = 1; next;)
+   table=??(lr_in_ip_routing   ), priority=2322 , match=(inport == "lr0-sw0" && ip6.dst == fe80::/64), action=(ip.ttl--; reg8[[0..15]] = 0; xxreg0 = ip6.dst; xxreg1 = fe80::200:ff:fe00:ff01; eth.src = 00:00:00:00:ff:01; outport = "lr0-sw0"; flags.loopback = 1; reg9[[9]] = 0; next;)
+   table=??(lr_in_ip_routing   ), priority=2322 , match=(inport == "lr0-sw1" && ip6.dst == fe80::/64), action=(ip.ttl--; reg8[[0..15]] = 0; xxreg0 = ip6.dst; xxreg1 = fe80::200:ff:fe00:ff02; eth.src = 00:00:00:00:ff:02; outport = "lr0-sw1"; flags.loopback = 1; reg9[[9]] = 0; next;)
+ ])
+-AT_CHECK([grep -e "lr_in_ip_routing_ecmp" lr0flows | sed -e 's/10\.0\..\./10.0.??./g' -e 's/lr0-sw./lr0-sw??/' -e 's/00:ff:0./00:ff:0?/' | ovn_strip_lflows], [0], [dnl
++AT_CHECK([grep -e "lr_in_ip_routing_ecmp" lr0flows | sed -e 's/10\.0\..\./10.0.??./g' -e 's/lr0-sw./lr0-sw??/' -e 's/00:ff:0./00:ff:0?/' | ovn_strip_ecmp_ids | ovn_strip_lflows], [0], [dnl
+   table=??(lr_in_ip_routing_ecmp), priority=0    , match=(1), action=(drop;)
+-  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == 1 && reg8[[16..31]] == 1), action=(reg0 = 10.0.??.10; reg5 = 10.0.??.1; eth.src = 00:00:00:00:ff:0?; outport = "lr0-sw??"; reg9[[9]] = 1; next;)
+-  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == 1 && reg8[[16..31]] == 2), action=(reg0 = 10.0.??.10; reg5 = 10.0.??.1; eth.src = 00:00:00:00:ff:0?; outport = "lr0-sw??"; reg9[[9]] = 1; next;)
+-  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == 2 && reg8[[16..31]] == 1), action=(reg0 = 10.0.??.20; reg5 = 10.0.??.1; eth.src = 00:00:00:00:ff:0?; outport = "lr0-sw??"; reg9[[9]] = 1; next;)
+-  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == 2 && reg8[[16..31]] == 2), action=(reg0 = 10.0.??.20; reg5 = 10.0.??.1; eth.src = 00:00:00:00:ff:0?; outport = "lr0-sw??"; reg9[[9]] = 1; next;)
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(reg0 = 10.0.??.10; reg5 = 10.0.??.1; eth.src = 00:00:00:00:ff:0?; outport = "lr0-sw??"; reg9[[9]] = 1; next;)
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(reg0 = 10.0.??.10; reg5 = 10.0.??.1; eth.src = 00:00:00:00:ff:0?; outport = "lr0-sw??"; reg9[[9]] = 1; next;)
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(reg0 = 10.0.??.20; reg5 = 10.0.??.1; eth.src = 00:00:00:00:ff:0?; outport = "lr0-sw??"; reg9[[9]] = 1; next;)
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(reg0 = 10.0.??.20; reg5 = 10.0.??.1; eth.src = 00:00:00:00:ff:0?; outport = "lr0-sw??"; reg9[[9]] = 1; next;)
+   table=??(lr_in_ip_routing_ecmp), priority=150  , match=(reg8[[0..15]] == 0), action=(next;)
+ ])
+ 
+@@ -16957,12 +17613,12 @@ check ovn-nbctl --wait=sb sync
+ check_row_count Advertised_Route 4
+ check_row_count Learned_Route 4
+ ovn-sbctl dump-flows lr0 > lr0flows
+-AT_CHECK([grep -w "lr_in_ip_routing" lr0flows | sed -e 's/reg8\[[0..15\]] = [[123]]/reg8\[[0..15\]] = ??/' | ovn_strip_lflows], [0], [dnl
++AT_CHECK([grep -w "lr_in_ip_routing" lr0flows | ovn_strip_ecmp_ids | ovn_strip_lflows], [0], [dnl
+   table=??(lr_in_ip_routing   ), priority=0    , match=(1), action=(drop;)
+   table=??(lr_in_ip_routing   ), priority=10550, match=(nd_rs || nd_ra), action=(drop;)
+-  table=??(lr_in_ip_routing   ), priority=1838 , match=(reg7 == 0 && ip4.dst == 192.168.0.0/24), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = ??; reg8[[16..31]] = select(1, 2);)
+-  table=??(lr_in_ip_routing   ), priority=1838 , match=(reg7 == 0 && ip4.dst == 192.168.1.0/24), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = ??; reg8[[16..31]] = select(1, 2);)
+-  table=??(lr_in_ip_routing   ), priority=1840 , match=(reg7 == 0 && ip4.dst == 192.168.0.0/24), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = ??; reg8[[16..31]] = select(1, 2);)
++  table=??(lr_in_ip_routing   ), priority=1838 , match=(reg7 == 0 && ip4.dst == 192.168.0.0/24), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = <gid>; reg8[[16..31]] = select(<mid>, <mid>);)
++  table=??(lr_in_ip_routing   ), priority=1838 , match=(reg7 == 0 && ip4.dst == 192.168.1.0/24), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = <gid>; reg8[[16..31]] = select(<mid>, <mid>);)
++  table=??(lr_in_ip_routing   ), priority=1840 , match=(reg7 == 0 && ip4.dst == 192.168.0.0/24), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = <gid>; reg8[[16..31]] = select(<mid>, <mid>);)
+   table=??(lr_in_ip_routing   ), priority=1842 , match=(ip4.dst == 10.0.0.0/24), action=(ip.ttl--; reg8[[0..15]] = 0; reg0 = ip4.dst; reg5 = 10.0.0.1; eth.src = 00:00:00:00:ff:01; outport = "lr0-sw0"; flags.loopback = 1; reg9[[9]] = 1; next;)
+   table=??(lr_in_ip_routing   ), priority=1842 , match=(ip4.dst == 10.0.1.0/24), action=(ip.ttl--; reg8[[0..15]] = 0; reg0 = ip4.dst; reg5 = 10.0.1.1; eth.src = 00:00:00:00:ff:02; outport = "lr0-sw1"; flags.loopback = 1; reg9[[9]] = 1; next;)
+   table=??(lr_in_ip_routing   ), priority=2322 , match=(inport == "lr0-sw0" && ip6.dst == fe80::/64), action=(ip.ttl--; reg8[[0..15]] = 0; xxreg0 = ip6.dst; xxreg1 = fe80::200:ff:fe00:ff01; eth.src = 00:00:00:00:ff:01; outport = "lr0-sw0"; flags.loopback = 1; reg9[[9]] = 0; next;)
+@@ -17007,13 +17663,13 @@ check_uuid ovn-sbctl create Learned_Route \
+ check ovn-nbctl --wait=sb sync
+ 
+ ovn-sbctl dump-flows lr0 > lr0flows
+-AT_CHECK([grep -w "lr_in_ip_routing" lr0flows | grep -F "42.42.42.42" | ovn_strip_lflows], [0], [dnl
+-  table=??(lr_in_ip_routing   ), priority=1934 , match=(reg7 == 0 && ip4.dst == 42.42.42.42/32), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = 1; reg8[[16..31]] = select(1, 2);)
++AT_CHECK([grep -w "lr_in_ip_routing" lr0flows | grep -F "42.42.42.42" | ovn_strip_ecmp_ids | ovn_strip_lflows], [0], [dnl
++  table=??(lr_in_ip_routing   ), priority=1934 , match=(reg7 == 0 && ip4.dst == 42.42.42.42/32), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = <gid>; reg8[[16..31]] = select(<mid>, <mid>);)
+ ])
+ 
+-AT_CHECK([grep "lr_in_ip_routing_ecmp" lr0flows | grep "42" | sed -e 's/reg8\[[16..31\]] == [[12]]/reg8\[[16..31\]] == ??/g' | ovn_strip_lflows], [0], [dnl
+-  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == 1 && reg8[[16..31]] == ??), action=(reg0 = 192.168.2.42; eth.src = 00:00:00:00:ff:02; outport = "lrp2"; reg9[[9]] = 1; next;)
+-  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == 1 && reg8[[16..31]] == ??), action=(reg0 = 192.168.3.42; eth.src = 00:00:00:00:ff:03; outport = "lrp3"; reg9[[9]] = 1; next;)
++AT_CHECK([grep "lr_in_ip_routing_ecmp" lr0flows | grep "42" | ovn_strip_ecmp_ids | ovn_strip_lflows], [0], [dnl
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(reg0 = 192.168.2.42; eth.src = 00:00:00:00:ff:02; outport = "lrp2"; reg9[[9]] = 1; next;)
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(reg0 = 192.168.3.42; eth.src = 00:00:00:00:ff:03; outport = "lrp3"; reg9[[9]] = 1; next;)
+ ])
+ 
+ OVN_CLEANUP_NORTHD
+@@ -18771,8 +19427,8 @@ check_row_count Advertised_Route 1 \
+ # One ECMP selection flow covers the prefix and two member flows carry the
+ # respective neighbor nexthops.
+ ovn-sbctl lflow-list lr0 > lr0_flows
+-AT_CHECK([grep 'lr_in_ip_routing.*172.16.1.10/32' lr0_flows | \
+-          grep -c 'select(1, 2)'], [0], [1
++AT_CHECK([grep 'lr_in_ip_routing.*172.16.1.10/32' lr0_flows | ovn_strip_ecmp_ids | \
++          grep -c 'select(<mid>, <mid>)'], [0], [1
+ ])
+ AT_CHECK([grep 'lr_in_ip_routing_ecmp' lr0_flows | \
+           grep -E -c 'reg0 = 10\.0\.0\.[[12]];'], [0], [2
+@@ -18791,6 +19447,85 @@ OVN_CLEANUP_NORTHD
+ AT_CLEANUP
+ ])
+ 
++OVN_FOR_EACH_NORTHD_NO_HV([
++AT_SETUP([dynamic-routing - NAT and LB reachable over several paths use ECMP])
++AT_KEYWORDS([dynamic-routing ecmp])
++ovn_start
++
++# lr0 reaches lr1 over the switches "a" and "b" and redistributes NAT and LB
++# addresses on both ports.  The NAT and the LB of lr1 then produce one
++# forwarding route per path on lr0.  The two routes of each ECMP group share
++# their source row and only differ in the nexthop and output port, they must
++# still get distinct ids that don't depend on the processing order.
++
++check ovn-nbctl lr-add lr0 -- set Logical_Router lr0 \
++    options:dynamic-routing=true options:chassis=hv1
++check ovn-nbctl lr-add lr1 -- set Logical_Router lr1 options:chassis=hv1
++i=0
++for s in a b; do
++    i=$((i + 1))
++    check ovn-nbctl ls-add $s
++    check ovn-nbctl lrp-add lr0 lr0-$s 00:00:00:00:0$i:01 10.0.$i.1/24
++    check ovn-nbctl lrp-set-options lr0-$s dynamic-routing-redistribute=lb,nat
++    check ovn-nbctl lsp-add-router-port $s $s-lr0 lr0-$s
++    check ovn-nbctl lrp-add lr1 lr1-$s 00:00:00:00:0$i:02 10.0.$i.2/24
++    check ovn-nbctl lsp-add-router-port $s $s-lr1 lr1-$s
++done
++check ovn-nbctl lr-nat-add lr1 dnat_and_snat 172.16.1.10 192.168.1.10
++check ovn-nbctl lb-add lb1 172.16.1.20:80 192.168.1.20:80
++check ovn-nbctl --wait=sb lr-lb-add lr1 lb1
++
++ovn-sbctl dump-flows lr0 > lr0flows
++AT_CHECK([grep -w "lr_in_ip_routing" lr0flows | grep "172\.16\.1\." | ovn_strip_ecmp_ids | ovn_strip_lflows], [0], [dnl
++  table=??(lr_in_ip_routing   ), priority=1935 , match=(ip4.dst == 172.16.1.10/32), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = <gid>; reg8[[16..31]] = select(<mid>, <mid>);)
++  table=??(lr_in_ip_routing   ), priority=1935 , match=(ip4.dst == 172.16.1.20/32), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = <gid>; reg8[[16..31]] = select(<mid>, <mid>);)
++])
++AT_CHECK([grep "lr_in_ip_routing_ecmp" lr0flows | grep "reg0 = 10\.0\." | ovn_strip_ecmp_ids | ovn_strip_lflows], [0], [dnl
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(reg0 = 10.0.1.2; reg5 = 10.0.1.1; eth.src = 00:00:00:00:01:01; outport = "lr0-a"; reg9[[9]] = 1; next;)
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(reg0 = 10.0.1.2; reg5 = 10.0.1.1; eth.src = 00:00:00:00:01:01; outport = "lr0-a"; reg9[[9]] = 1; next;)
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(reg0 = 10.0.2.2; reg5 = 10.0.2.1; eth.src = 00:00:00:00:02:01; outport = "lr0-b"; reg9[[9]] = 1; next;)
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(reg0 = 10.0.2.2; reg5 = 10.0.2.1; eth.src = 00:00:00:00:02:01; outport = "lr0-b"; reg9[[9]] = 1; next;)
++])
++
++dnl Both members of each group come from the same NAT or LB row.
++nat=$(fetch_column nb:NAT _uuid external_ip=172.16.1.10)
++lb=$(fetch_column nb:Load_Balancer _uuid name=lb1)
++check_row_count Logical_Flow 2 external_ids:stage-name=lr_in_ip_routing_ecmp \
++    external_ids:stage-hint=${nat:0:8}
++check_row_count Logical_Flow 2 external_ids:stage-name=lr_in_ip_routing_ecmp \
++    external_ids:stage-hint=${lb:0:8}
++
++dnl ecmp_ids also checks that the members have distinct ids.
++nat_ids=$(ecmp_ids lr0 172.16.1.10/32)
++lb_ids=$(ecmp_ids lr0 172.16.1.20/32)
++AT_CHECK([test -n "$nat_ids" && test -n "$lb_ids"])
++CHECK_NO_CHANGE_AFTER_RECOMPUTE
++
++dnl A third path adds a member to each group without changing the ids of the
++dnl existing members.
++check ovn-nbctl ls-add c
++check ovn-nbctl lrp-add lr0 lr0-c 00:00:00:00:03:01 10.0.3.1/24
++check ovn-nbctl lrp-set-options lr0-c dynamic-routing-redistribute=lb,nat
++check ovn-nbctl lsp-add-router-port c c-lr0 lr0-c
++check ovn-nbctl lrp-add lr1 lr1-c 00:00:00:00:03:02 10.0.3.2/24
++check ovn-nbctl --wait=sb lsp-add-router-port c c-lr1 lr1-c
++CHECK_NO_CHANGE_AFTER_RECOMPUTE
++
++for old in "$nat_ids 172.16.1.10/32" "$lb_ids 172.16.1.20/32"; do
++    set -- $old
++    new=$(ecmp_ids lr0 $3)
++    AT_CHECK([test "${new%% *}" = "$1"])
++    AT_CHECK([echo "${new#* }" | tr , '\n' | wc -l], [0], [3
++])
++    for m in $(echo $2 | tr , ' '); do
++        AT_CHECK([echo "${new#* }" | tr , '\n' | grep -qx $m])
++    done
++done
++
++OVN_CLEANUP_NORTHD
++AT_CLEANUP
++])
++
+ OVN_FOR_EACH_NORTHD_NO_HV([
+ AT_SETUP([dynamic-routing - LB redistribute uses backend LSP as tracked_port])
+ AT_KEYWORDS([dynamic-routing])
+@@ -20799,6 +21534,114 @@ OVN_CLEANUP_NORTHD
  AT_CLEANUP
  ])
  
@@ -2218,7 +5042,7 @@ index 4acdc677a..3ed3da542 100644
  OVN_FOR_EACH_NORTHD_NO_HV([
  AT_SETUP([Synced logical switch and router incremental procesesing])
  ovn_start
-@@ -23256,9 +23776,21 @@ AT_CAPTURE_FILE([ls1flows])
+@@ -23256,9 +24099,21 @@ AT_CAPTURE_FILE([ls1flows])
  
  AT_CHECK([grep "ls1-to-spine" ls1flows | ovn_strip_lflows | sort], [0], [dnl
    table=??(ls_in_lookup_fdb   ), priority=100  , match=(inport == "ls1-to-spine"), action=(reg0[[11]] = lookup_fdb(inport, eth.src); next;)
@@ -2240,8 +5064,176 @@ index 4acdc677a..3ed3da542 100644
    table=??(ls_out_pre_acl     ), priority=110  , match=(ip && outport == "ls1-to-spine"), action=(next;)
    table=??(ls_out_pre_lb      ), priority=110  , match=(ip && outport == "ls1-to-spine"), action=(next;)
  ])
+@@ -23393,6 +24248,87 @@ done
+ OVN_CLEANUP_NORTHD
+ AT_CLEANUP
+ 
++OVN_FOR_EACH_NORTHD_NO_HV([
++AT_SETUP([Static routes - ECMP ids stable across recompute])
++AT_KEYWORDS([ecmp])
++ovn_start
++
++check ovn-nbctl lr-add lr0
++for i in 1 2 3 4; do
++    check ovn-nbctl lrp-add lr0 lr0-sw$i 00:00:00:00:0$i:01 10.0.$i.1/24
++done
++check ovn-nbctl --wait=sb sync
++
++dnl Add the routes in "reverse" order, the ids must not depend on it.
++for p in 192.168.30.0/24 192.168.20.0/24 192.168.10.0/24; do
++    for i in 3 2 1; do
++        check ovn-nbctl --wait=sb --ecmp lr-route-add lr0 $p 10.0.$i.10
++    done
++done
++CHECK_NO_CHANGE_AFTER_RECOMPUTE
++
++AT_CHECK([ovn-sbctl dump-flows lr0 | grep -w lr_in_ip_routing | grep select | ovn_strip_ecmp_ids | ovn_strip_lflows], [0], [dnl
++  table=??(lr_in_ip_routing   ), priority=1840 , match=(reg7 == 0 && ip4.dst == 192.168.10.0/24), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = <gid>; reg8[[16..31]] = select(<mid>, <mid>, <mid>);)
++  table=??(lr_in_ip_routing   ), priority=1840 , match=(reg7 == 0 && ip4.dst == 192.168.20.0/24), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = <gid>; reg8[[16..31]] = select(<mid>, <mid>, <mid>);)
++  table=??(lr_in_ip_routing   ), priority=1840 , match=(reg7 == 0 && ip4.dst == 192.168.30.0/24), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = <gid>; reg8[[16..31]] = select(<mid>, <mid>, <mid>);)
++])
++g10=$(ecmp_ids lr0 192.168.10.0/24)
++g20=$(ecmp_ids lr0 192.168.20.0/24)
++g30=$(ecmp_ids lr0 192.168.30.0/24)
++AT_CHECK([test -n "$g10" && test -n "$g20" && test -n "$g30"])
++AT_CHECK([printf '%s\n' "$g10" "$g20" "$g30" | cut -d' ' -f1 | sort -u | wc -l], [0], [3
++])
++
++dnl Remove a member from the middle of a group with more than 2 members, the
++dnl ids of the other members and groups must not change.
++m2=$(ecmp_member_id lr0 192.168.10.0/24 10.0.2.10)
++check as northd ovn-appctl -t ovn-northd inc-engine/clear-stats
++check ovn-nbctl --wait=sb lr-route-del lr0 192.168.10.0/24 10.0.2.10
++check_engine_compute group_ecmp_route incremental
++CHECK_NO_CHANGE_AFTER_RECOMPUTE
++g10_ids=$(echo "${g10#* }" | tr , '\n' | grep -vx "$m2" | paste -sd, -)
++AT_CHECK_UNQUOTED([ecmp_ids lr0 192.168.10.0/24], [0], [${g10%% *} $g10_ids
++])
++AT_CHECK_UNQUOTED([ecmp_ids lr0 192.168.20.0/24], [0], [$g20
++])
++AT_CHECK_UNQUOTED([ecmp_ids lr0 192.168.30.0/24], [0], [$g30
++])
++g10=$(ecmp_ids lr0 192.168.10.0/24)
++
++dnl Remove a whole group and then add a new one, the ids of the other groups
++dnl must not change and the group ids must stay unique.
++check as northd ovn-appctl -t ovn-northd inc-engine/clear-stats
++check ovn-nbctl --wait=sb lr-route-del lr0 192.168.20.0/24
++check ovn-nbctl --wait=sb --ecmp lr-route-add lr0 192.168.40.0/24 10.0.1.10
++check ovn-nbctl --wait=sb --ecmp lr-route-add lr0 192.168.40.0/24 10.0.4.10
++check_engine_compute group_ecmp_route incremental
++CHECK_NO_CHANGE_AFTER_RECOMPUTE
++AT_CHECK_UNQUOTED([ecmp_ids lr0 192.168.10.0/24], [0], [$g10
++])
++AT_CHECK_UNQUOTED([ecmp_ids lr0 192.168.30.0/24], [0], [$g30
++])
++g40=$(ecmp_ids lr0 192.168.40.0/24)
++AT_CHECK([test -n "$g40"])
++AT_CHECK([printf '%s\n' "$g10" "$g30" "$g40" | cut -d' ' -f1 | sort -u | wc -l], [0], [3
++])
++
++dnl Once no member is a discard route anymore the group must stop dropping.
++route=$(ovn-nbctl --bare --columns _uuid find Logical_Router_Static_Route \
++        ip_prefix="192.168.30.0/24" nexthop="10.0.3.10")
++check ovn-nbctl --wait=sb set Logical_Router_Static_Route $route nexthop=discard
++AT_CHECK([ovn-sbctl dump-flows lr0 | grep lr_in_ip_routing_ecmp | grep -c "drop;"], [0], [4
++])
++check as northd ovn-appctl -t ovn-northd inc-engine/clear-stats
++check ovn-nbctl --wait=sb set Logical_Router_Static_Route $route nexthop=10.0.3.10
++check_engine_compute group_ecmp_route incremental
++AT_CHECK([ovn-sbctl dump-flows lr0 | grep lr_in_ip_routing_ecmp | grep -c "drop;"], [0], [1
++])
++CHECK_NO_CHANGE_AFTER_RECOMPUTE
++
++OVN_CLEANUP_NORTHD
++AT_CLEANUP
++])
++
+ OVN_FOR_EACH_NORTHD_NO_HV([
+ AT_SETUP([Static routes - ECMP with discard])
+ ovn_start
+@@ -23407,14 +24343,14 @@ check ovn-nbctl                                                          \
+ check ovn-nbctl --wait=sb sync
+ 
+ ovn-sbctl dump-flows lr0 > lr0flows
+-AT_CHECK([grep 'lr_in_ip_routing' lr0flows | grep 'select' | ovn_strip_lflows], [0], [dnl
+-  table=??(lr_in_ip_routing   ), priority=1840 , match=(reg7 == 0 && ip4.dst == 192.168.10.0/24), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = 1; reg8[[16..31]] = select(1, 2);)
++AT_CHECK([grep 'lr_in_ip_routing' lr0flows | grep 'select' | ovn_strip_ecmp_ids | ovn_strip_lflows], [0], [dnl
++  table=??(lr_in_ip_routing   ), priority=1840 , match=(reg7 == 0 && ip4.dst == 192.168.10.0/24), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = <gid>; reg8[[16..31]] = select(<mid>, <mid>);)
+ ])
+ 
+-AT_CHECK([grep 'lr_in_ip_routing_ecmp' lr0flows | sed -E 's/== [[1-9]]+\)/== \?)/' | ovn_strip_lflows], [0], [dnl
++AT_CHECK([grep 'lr_in_ip_routing_ecmp' lr0flows | ovn_strip_ecmp_ids | ovn_strip_lflows], [0], [dnl
+   table=??(lr_in_ip_routing_ecmp), priority=0    , match=(1), action=(drop;)
+-  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == 1 && reg8[[16..31]] == ?), action=(reg0 = 10.0.10.10; reg5 = 10.0.10.1; eth.src = 00:00:00:00:10:01; outport = "lr0-sw1"; reg9[[9]] = 1; next;)
+-  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == 1 && reg8[[16..31]] == ?), action=(reg0 = 10.0.20.10; reg5 = 10.0.20.1; eth.src = 00:00:00:00:20:01; outport = "lr0-sw2"; reg9[[9]] = 1; next;)
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(reg0 = 10.0.10.10; reg5 = 10.0.10.1; eth.src = 00:00:00:00:10:01; outport = "lr0-sw1"; reg9[[9]] = 1; next;)
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(reg0 = 10.0.20.10; reg5 = 10.0.20.1; eth.src = 00:00:00:00:20:01; outport = "lr0-sw2"; reg9[[9]] = 1; next;)
+   table=??(lr_in_ip_routing_ecmp), priority=150  , match=(reg8[[0..15]] == 0), action=(next;)
+ ])
+ 
+@@ -23425,14 +24361,14 @@ ecmp2=$(fetch_column nb:Logical_Router_Static_Route _uuid nexthop="10.0.20.10")
+ check ovn-nbctl --wait=sb set Logical_Router_Static_Route $ecmp1 nexthop="discard"
+ 
+ ovn-sbctl dump-flows lr0 > lr0flows
+-AT_CHECK([grep 'lr_in_ip_routing' lr0flows | grep 'select' | ovn_strip_lflows], [0], [dnl
+-  table=??(lr_in_ip_routing   ), priority=1840 , match=(reg7 == 0 && ip4.dst == 192.168.10.0/24), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = 1; reg8[[16..31]] = select(1, 2);)
++AT_CHECK([grep 'lr_in_ip_routing' lr0flows | grep 'select' | ovn_strip_ecmp_ids | ovn_strip_lflows], [0], [dnl
++  table=??(lr_in_ip_routing   ), priority=1840 , match=(reg7 == 0 && ip4.dst == 192.168.10.0/24), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = <gid>; reg8[[16..31]] = select(<mid>, <mid>);)
+ ])
+ 
+-AT_CHECK([grep 'lr_in_ip_routing_ecmp' lr0flows | sed -E 's/== [[1-9]]+\)/== \?)/' | ovn_strip_lflows], [0], [dnl
++AT_CHECK([grep 'lr_in_ip_routing_ecmp' lr0flows | ovn_strip_ecmp_ids | ovn_strip_lflows], [0], [dnl
+   table=??(lr_in_ip_routing_ecmp), priority=0    , match=(1), action=(drop;)
+-  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == 1 && reg8[[16..31]] == ?), action=(drop;)
+-  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == 1 && reg8[[16..31]] == ?), action=(drop;)
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(drop;)
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(drop;)
+   table=??(lr_in_ip_routing_ecmp), priority=150  , match=(reg8[[0..15]] == 0), action=(next;)
+ ])
+ 
+@@ -23440,14 +24376,14 @@ AT_CHECK([grep 'lr_in_ip_routing_ecmp' lr0flows | sed -E 's/== [[1-9]]+\)/== \?)
+ check ovn-nbctl --wait=sb set Logical_Router_Static_Route $ecmp2 nexthop="discard"
+ 
+ ovn-sbctl dump-flows lr0 > lr0flows
+-AT_CHECK([grep 'lr_in_ip_routing' lr0flows | grep 'select' | ovn_strip_lflows], [0], [dnl
+-  table=??(lr_in_ip_routing   ), priority=1840 , match=(reg7 == 0 && ip4.dst == 192.168.10.0/24), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = 1; reg8[[16..31]] = select(1, 2);)
++AT_CHECK([grep 'lr_in_ip_routing' lr0flows | grep 'select' | ovn_strip_ecmp_ids | ovn_strip_lflows], [0], [dnl
++  table=??(lr_in_ip_routing   ), priority=1840 , match=(reg7 == 0 && ip4.dst == 192.168.10.0/24), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = <gid>; reg8[[16..31]] = select(<mid>, <mid>);)
+ ])
+ 
+-AT_CHECK([grep 'lr_in_ip_routing_ecmp' lr0flows | sed -E 's/== [[1-9]]+\)/== \?)/' | ovn_strip_lflows], [0], [dnl
++AT_CHECK([grep 'lr_in_ip_routing_ecmp' lr0flows | ovn_strip_ecmp_ids | ovn_strip_lflows], [0], [dnl
+   table=??(lr_in_ip_routing_ecmp), priority=0    , match=(1), action=(drop;)
+-  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == 1 && reg8[[16..31]] == ?), action=(drop;)
+-  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == 1 && reg8[[16..31]] == ?), action=(drop;)
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(drop;)
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(drop;)
+   table=??(lr_in_ip_routing_ecmp), priority=150  , match=(reg8[[0..15]] == 0), action=(next;)
+ ])
+ 
+@@ -23456,14 +24392,14 @@ check ovn-nbctl set Logical_Router_Static_Route $ecmp1 nexthop="10.0.10.10"
+ check ovn-nbctl --wait=sb set Logical_Router_Static_Route $ecmp2 nexthop="10.0.20.10"
+ 
+ ovn-sbctl dump-flows lr0 > lr0flows
+-AT_CHECK([grep 'lr_in_ip_routing' lr0flows | grep 'select' | ovn_strip_lflows], [0], [dnl
+-  table=??(lr_in_ip_routing   ), priority=1840 , match=(reg7 == 0 && ip4.dst == 192.168.10.0/24), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = 1; reg8[[16..31]] = select(1, 2);)
++AT_CHECK([grep 'lr_in_ip_routing' lr0flows | grep 'select' | ovn_strip_ecmp_ids | ovn_strip_lflows], [0], [dnl
++  table=??(lr_in_ip_routing   ), priority=1840 , match=(reg7 == 0 && ip4.dst == 192.168.10.0/24), action=(ip.ttl--; flags.loopback = 1; reg8[[0..15]] = <gid>; reg8[[16..31]] = select(<mid>, <mid>);)
+ ])
+ 
+-AT_CHECK([grep 'lr_in_ip_routing_ecmp' lr0flows | sed -E 's/== [[1-9]]+\)/== \?)/' | ovn_strip_lflows], [0], [dnl
++AT_CHECK([grep 'lr_in_ip_routing_ecmp' lr0flows | ovn_strip_ecmp_ids | ovn_strip_lflows], [0], [dnl
+   table=??(lr_in_ip_routing_ecmp), priority=0    , match=(1), action=(drop;)
+-  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == 1 && reg8[[16..31]] == ?), action=(reg0 = 10.0.10.10; reg5 = 10.0.10.1; eth.src = 00:00:00:00:10:01; outport = "lr0-sw1"; reg9[[9]] = 1; next;)
+-  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == 1 && reg8[[16..31]] == ?), action=(reg0 = 10.0.20.10; reg5 = 10.0.20.1; eth.src = 00:00:00:00:20:01; outport = "lr0-sw2"; reg9[[9]] = 1; next;)
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(reg0 = 10.0.10.10; reg5 = 10.0.10.1; eth.src = 00:00:00:00:10:01; outport = "lr0-sw1"; reg9[[9]] = 1; next;)
++  table=??(lr_in_ip_routing_ecmp), priority=100  , match=(reg8[[0..15]] == <gid> && reg8[[16..31]] == <mid>), action=(reg0 = 10.0.20.10; reg5 = 10.0.20.1; eth.src = 00:00:00:00:20:01; outport = "lr0-sw2"; reg9[[9]] = 1; next;)
+   table=??(lr_in_ip_routing_ecmp), priority=150  , match=(reg8[[0..15]] == 0), action=(next;)
+ ])
+ 
 diff --git a/tests/ovn.at b/tests/ovn.at
-index 09b4d2c61..b6db571ec 100644
+index 09b4d2c611..9de8dbd292 100644
 --- a/tests/ovn.at
 +++ b/tests/ovn.at
 @@ -12697,6 +12697,144 @@ OVN_CLEANUP([hv1])
@@ -2307,89 +5299,748 @@ index 09b4d2c61..b6db571ec 100644
 +OVN_WAIT_PATCH_PORT_FLOWS([ln-ext], [gw1 gw2])
 +check ovn-nbctl --wait=hv sync
 +
-+check_bfd_packets() {
-+    local colocated=$1 gw
++check_bfd_packets() {
++    local colocated=$1 gw
++
++    for gw in gw1 gw2; do
++        as $gw reset_pcap_file br-ex_provider $gw/br-ex_provider
++    done
++    if test "$colocated" = yes; then
++        cat bfd1.expected bfd2.expected | sort > gw1.expected
++        : > gw2.expected
++    else
++        cp bfd1.expected gw1.expected
++        cp bfd2.expected gw2.expected
++    fi
++
++    # These are packets emitted by pinctrl and forwarded by ovs-vswitchd,
++    # not traces or flow dumps.  Ignore ARP and compare the set of BFD
++    # sessions at each provider uplink, including the source MAC selected
++    # by routing.  Wait for several packets, and reject unexpected sessions.
++    OVS_WAIT_UNTIL([
++        for gw in gw1 gw2; do
++            $PYTHON "$ovs_srcdir/utilities/ovs-pcap.in" \
++                $gw/br-ex_provider-tx.pcap | \
++                grep -E '^.{24}080045.{16}11.{24}0ec8' | \
++                cut -c 1-28,53-76,93-100 > $gw.bfd
++            sort -u $gw.bfd > $gw.actual
++        done
++        test $(wc -l < gw1.bfd) -ge 3 &&
++        { test "$colocated" = yes || test $(wc -l < gw2.bfd) -ge 3; } &&
++        diff -u gw1.expected gw1.actual &&
++        diff -u gw2.expected gw2.actual
++    ])
++}
++
++AT_CAPTURE_FILE([gw1.actual])
++AT_CAPTURE_FILE([gw2.actual])
++AT_CAPTURE_FILE([gw1.expected])
++AT_CAPTURE_FILE([gw2.expected])
++
++AS_BOX([BFD sessions on separate gateways])
++# Each gateway must send only its own session through its provider uplink.
++check_bfd_packets no
++
++AS_BOX([BFD sessions after controller recompute])
++# Recomputing the controllers must not change either session's egress path.
++for gw in gw1 gw2; do
++    check as $gw ovn-appctl -t ovn-controller inc-engine/recompute
++done
++check ovn-nbctl --wait=hv sync
++check_bfd_packets no
++
++AS_BOX([BFD sessions on the same gateway])
++# Also check both LRPs on one chassis.  Without the fix only one of the
++# conflicting routes can win, so at least one session gets the wrong source
++# MAC regardless of flow ordering.  This makes the regression deterministic.
++check ovn-nbctl --wait=hv \
++    lrp-del-gateway-chassis r0-ext2 gw2 -- \
++    lrp-set-gateway-chassis r0-ext2 gw1
++chassis=$(fetch_column Chassis _uuid name=gw1)
++wait_column "$chassis" Port_Binding chassis logical_port=cr-r0-ext2
++check ovn-nbctl --wait=hv sync
++check_bfd_packets yes
++
++AS_BOX([BFD sessions back on separate gateways])
++check ovn-nbctl --wait=hv \
++    lrp-del-gateway-chassis r0-ext2 gw1 -- \
++    lrp-set-gateway-chassis r0-ext2 gw2
++chassis=$(fetch_column Chassis _uuid name=gw2)
++wait_column "$chassis" Port_Binding chassis logical_port=cr-r0-ext2
++check ovn-nbctl --wait=hv sync
++check_bfd_packets no
++
++OVN_CLEANUP([gw1
++ignored_tables=OFTABLE_PHY_TO_LOG
++], [gw2
++ignored_tables=OFTABLE_PHY_TO_LOG
++])
++AT_CLEANUP
++])
++
+ OVN_FOR_EACH_NORTHD([
+ AT_SETUP([4 HV, 1 LS, 1 LR, packet test with HA distributed router gateway port])
+ ovn_start
+@@ -25901,6 +26039,658 @@ OVN_CLEANUP([hv1], [hv2])
+ AT_CLEANUP
+ ])
+ 
++OVN_FOR_EACH_NORTHD([
++AT_SETUP([IGMP/MLD querier per-port query fan-out])
++AT_KEYWORDS([IP-multicast snoop querier])
++AT_KEYWORDS([slowtest])
++
++ovn_start
++
++dnl A single chassis with a large number of local VIFs on one logical
++dnl switch.  Each port's querier query egress translation uses ~19
++dnl resubmits, so delivering the queries to all 250 local ports in a
++dnl single flood-group PACKET_OUT would exceed OVS's MAX_RESUBMITS
++dnl (4096) budget.  Instead, the querier sends one PACKET_OUT per
++dnl batch of at most 100 ports.  Verify end to end that (1) every
++dnl local port receives both the IGMP and the MLD queries, with the
++dnl right contents, and (2) the number of OFPT_PACKET_OUT messages
++dnl matches the batch count: three per query type with 250 local
++dnl ports, two with 101, one with 100.
++dnl
++dnl sim_add() starts ovs-vswitchd with -vvconn, so every OpenFlow
++dnl message received from ovn-controller is dumped to
++dnl ovs-vswitchd.log.  Counting the "received: OFPT_PACKET_OUT" log
++dnl lines therefore counts the messages the querier actually sent.
++
++n_ports=250
++
++check ovn-nbctl ls-add ls1
++
++# Create the VIF ports on ls1 in batches.
++batch=""
++for i in $(seq 1 $n_ports); do
++    batch="$batch -- lsp-add ls1 ls1-p$i"
++    if test $((i % 50)) -eq 0; then
++        check ovn-nbctl $batch
++        batch=""
++    fi
++done
++if test -n "$batch"; then
++    check ovn-nbctl $batch
++fi
++
++net_add n1
++sim_add hv1
++as hv1
++check ovs-vsctl add-br br-phys
++ovn_attach n1 br-phys 192.168.0.1
++check ovs-vsctl set open . external-ids:ovn-bridge-mappings=phys:br-phys
++
++# Create the VIFs in batches, keeping tx pcaps on a few of them.
++batch=""
++for i in $(seq 1 $n_ports); do
++    if test $i -eq 1 -o $i -eq 125 -o $i -eq $n_ports; then
++        batch="$batch -- add-port br-int hv1-vif$i -- \
++            set interface hv1-vif$i external-ids:iface-id=ls1-p$i \
++            options:tx_pcap=hv1/vif$i-tx.pcap \
++            options:rxq_pcap=hv1/vif$i-rx.pcap"
++    else
++        batch="$batch -- add-port br-int hv1-vif$i -- \
++            set interface hv1-vif$i external-ids:iface-id=ls1-p$i"
++    fi
++    if test $((i % 25)) -eq 0; then
++        check ovs-vsctl $batch
++        batch=""
++    fi
++done
++if test -n "$batch"; then
++    check ovs-vsctl $batch
++fi
++
++wait_for_ports_up
++check ovn-nbctl --wait=hv sync
++
++# Enable multicast snooping and querier on ls1.  Use the maximum
++# query interval so that only the immediate query round fired when
++# the querier is enabled (and, later, when the interval changes)
++# happens during the test.
++check ovn-nbctl --wait=hv set Logical_Switch ls1 \
++    other_config:mcast_snoop="true" \
++    other_config:mcast_querier="true" \
++    other_config:mcast_query_interval=3600 \
++    other_config:mcast_eth_src="00:00:00:00:02:fe" \
++    other_config:mcast_ip4_src="20.0.0.254" \
++    other_config:mcast_ip6_src="fe80::fe"
++
++# Wait for pinctrl thread to be connected
++OVS_WAIT_UNTIL([grep pinctrl hv1/ovn-controller.log | grep -c connected])
++
++dp_key=$(printf "%x" $(fetch_column Datapath_Binding tunnel_key external_ids:name=ls1))
++
++AS_BOX([Querier queries are fanned out to all local ports])
++dnl Every local port has its own output flow in table 89, the last
++dnl logical egress table.  The querier sends one IGMP query and one
++dnl MLD query per port per round, so once each per-port flow has
++dnl counted both packets, every local port has received both
++dnl queries.
++OVS_WAIT_UNTIL(
++  [test $(as hv1 ovs-ofctl dump-flows br-int table=OFTABLE_LOG_TO_PHY | grep -c "metadata=0x$dp_key ") -eq $n_ports \
++       -a $(as hv1 ovs-ofctl dump-flows br-int table=OFTABLE_LOG_TO_PHY | grep "metadata=0x$dp_key " | grep -c "n_packets=2,") -eq $n_ports],
++  [as hv1 ovs-ofctl dump-flows br-int table=OFTABLE_LOG_TO_PHY])
++
++AS_BOX([Querier query contents])
++AT_CAPTURE_FILE([exp])
++AT_CAPTURE_FILE([rcv])
++check_packets() {
++    > exp
++    > rcv
++    if test "$1" = --uniq; then
++        sort="sort -u"; shift
++    else
++        sort=sort
++    fi
++    for tuple in "$@"; do
++        set $tuple; pcap=$1 type=$2
++        echo "--- $pcap" | tee -a exp >> rcv
++        $sort "$type" >> exp
++        $PYTHON "$ovs_srcdir/utilities/ovs-pcap.in" $pcap | $sort >> rcv
++        echo | tee -a exp >> rcv
++    done
++
++    $at_diff exp rcv >/dev/null
++}
++
++> expected
++store_igmp_v3_query 0000000002fe $(ip_to_hex 20 0 0 254) 84dd expected
++store_mld_query 0000000002fe fe8000000000000000000000000000fe expected
++
++OVS_WAIT_UNTIL(
++  [check_packets --uniq 'hv1/vif1-tx.pcap expected' \
++                 'hv1/vif125-tx.pcap expected' \
++                 'hv1/vif250-tx.pcap expected'],
++  [$at_diff -F'^---' exp rcv])
++
++AS_BOX([250 local ports require three messages per query type])
++dnl One round over 250 local ports: 3 batches of IGMP + 3 batches
++dnl of MLD, i.e. 6 OFPT_PACKET_OUT messages in total.  The round is
++dnl known to be fully delivered at this point (see above), so the
++dnl count is exact.
++OVS_WAIT_UNTIL(
++  [test $(grep -c "received: OFPT_PACKET_OUT" hv1/ovs-vswitchd.log) -eq 6],
++  [grep "received: OFPT_PACKET_OUT" hv1/ovs-vswitchd.log])
++
++AS_BOX([101 local ports require two messages per query type])
++dnl Drop the ports above 101.  Changing the query interval triggers
++dnl an immediate next query round (see ip_mcast_snoop_configure() in
++dnl ovn-controller), now over the 101 remaining ports, i.e. two
++dnl messages per query type, four in total.
++batch=""
++for i in $(seq 102 $n_ports); do
++    batch="$batch -- lsp-del ls1-p$i"
++    if test $((i % 50)) -eq 0; then
++        check ovn-nbctl $batch
++        batch=""
++    fi
++done
++if test -n "$batch"; then
++    check ovn-nbctl $batch
++fi
++
++batch=""
++for i in $(seq 102 $n_ports); do
++    batch="$batch -- del-port br-int hv1-vif$i"
++    if test $((i % 25)) -eq 0; then
++        check ovs-vsctl $batch
++        batch=""
++    fi
++done
++if test -n "$batch"; then
++    check ovs-vsctl $batch
++fi
++
++check ovn-nbctl --wait=hv sync
++check ovn-nbctl --wait=hv set Logical_Switch ls1 other_config:mcast_query_interval=1800
++
++OVS_WAIT_UNTIL(
++  [test $(as hv1 ovs-ofctl dump-flows br-int table=OFTABLE_LOG_TO_PHY | grep -c "metadata=0x$dp_key ") -eq 101 \
++       -a $(as hv1 ovs-ofctl dump-flows br-int table=OFTABLE_LOG_TO_PHY | grep "metadata=0x$dp_key " | grep -c "n_packets=4,") -eq 101],
++  [as hv1 ovs-ofctl dump-flows br-int table=OFTABLE_LOG_TO_PHY])
++
++dnl Two rounds in total: 6 messages from the 250-port round plus 2
++dnl batches of IGMP + 2 batches of MLD over the 101 remaining ports.
++OVS_WAIT_UNTIL(
++  [test $(grep -c "received: OFPT_PACKET_OUT" hv1/ovs-vswitchd.log) -eq 10],
++  [grep "received: OFPT_PACKET_OUT" hv1/ovs-vswitchd.log])
++
++AS_BOX([100 local ports require one message per query type])
++dnl Drop one more local port.  Changing the query interval again
++dnl triggers another immediate query round, now over the 100
++dnl remaining ports, i.e. one message per query type, two in total.
++check ovn-nbctl lsp-del ls1-p101
++check ovs-vsctl --if-exists del-port br-int hv1-vif101
++check ovn-nbctl --wait=hv sync
++check ovn-nbctl --wait=hv set Logical_Switch ls1 other_config:mcast_query_interval=900
++
++OVS_WAIT_UNTIL(
++  [test $(as hv1 ovs-ofctl dump-flows br-int table=OFTABLE_LOG_TO_PHY | grep -c "metadata=0x$dp_key ") -eq 100 \
++       -a $(as hv1 ovs-ofctl dump-flows br-int table=OFTABLE_LOG_TO_PHY | grep "metadata=0x$dp_key " | grep -c "n_packets=6,") -eq 100],
++  [as hv1 ovs-ofctl dump-flows br-int table=OFTABLE_LOG_TO_PHY])
++
++dnl Three rounds in total: the 6 + 4 messages above plus 1 batch of
++dnl IGMP + 1 batch of MLD over the 100 remaining ports.
++OVS_WAIT_UNTIL(
++  [test $(grep -c "received: OFPT_PACKET_OUT" hv1/ovs-vswitchd.log) -eq 12],
++  [grep "received: OFPT_PACKET_OUT" hv1/ovs-vswitchd.log])
++
++OVN_CLEANUP([hv1])
++AT_CLEANUP
++])
++
++OVN_FOR_EACH_NORTHD([
++AT_SETUP([IGMP/MLD querier per-port query fan-out interval cadence])
++AT_KEYWORDS([IP-multicast snoop querier])
++AT_KEYWORDS([slowtest])
++
++ovn_start
++
++dnl A single chassis with two local VIFs on one logical switch.
++dnl Each querier round sends one IGMP query and one MLD query (a
++dnl single batch for both ports), so every round shows up as two
++dnl "received: OFPT_PACKET_OUT" lines in ovs-vswitchd.log, which
++dnl sim_add() starts with -vvconn.
++dnl
++dnl Verify that (1) consecutive rounds are spaced by the configured
++dnl 3s query interval, (2) extending the interval does not reset the
++dnl pending round, and (3) shortening the interval triggers an
++dnl immediate round.
++dnl
++dnl Known limitation: the interval extension is applied by the
++dnl controller asynchronously.  The assertions assume it is applied
++dnl within a couple of seconds; on a heavily loaded system an extra
++dnl round could fire and the exact count checks would fail.
++
++check ovn-nbctl ls-add ls1
++check ovn-nbctl lsp-add ls1 ls1-p1
++check ovn-nbctl lsp-add ls1 ls1-p2
++
++net_add n1
++sim_add hv1
++as hv1
++check ovs-vsctl add-br br-phys
++ovn_attach n1 br-phys 192.168.0.1
++check ovs-vsctl set open . external-ids:ovn-bridge-mappings=phys:br-phys
++check ovs-vsctl add-port br-int hv1-vif1 -- \
++    set interface hv1-vif1 external-ids:iface-id=ls1-p1 \
++    options:tx_pcap=hv1/vif1-tx.pcap
++check ovs-vsctl add-port br-int hv1-vif2 -- \
++    set interface hv1-vif2 external-ids:iface-id=ls1-p2 \
++    options:tx_pcap=hv1/vif2-tx.pcap
++
++wait_for_ports_up
++check ovn-nbctl --wait=hv sync
++
++# Enable multicast snooping and querier on ls1 with a short query
++# interval so that several query rounds fire during the test.
++check ovn-nbctl --wait=hv set Logical_Switch ls1 \
++    other_config:mcast_snoop="true" \
++    other_config:mcast_querier="true" \
++    other_config:mcast_query_interval=3 \
++    other_config:mcast_eth_src="00:00:00:00:02:fe" \
++    other_config:mcast_ip4_src="20.0.0.254" \
++    other_config:mcast_ip6_src="fe80::fe"
++
++# Wait for pinctrl thread to be connected
++OVS_WAIT_UNTIL([grep pinctrl hv1/ovn-controller.log | grep -c connected])
++
++dp_key=$(printf "%x" $(fetch_column Datapath_Binding tunnel_key external_ids:name=ls1))
++
++packet_out_count() {
++    grep -c "received: OFPT_PACKET_OUT" hv1/ovs-vswitchd.log
++}
++packet_out_ts() {
++    dnl Prints the send time (in ms) of the $1-th OFPT_PACKET_OUT
++    dnl message in hv1/ovs-vswitchd.log.  The first field of a log
++    dnl line is the UTC timestamp with millisecond precision.
++    dnl
++    dnl Only the whole-second part is passed to date(1) and the
++    dnl millisecond field is taken from the timestamp itself.
++    dnl The current version of date(1) shipping with Ubuntu 26.04 drops
++    dnl leading zeros in the nanosecond field before truncating for %3N
++    dnl producing the wrong millisecond value.
++    grep "received: OFPT_PACKET_OUT" hv1/ovs-vswitchd.log \
++        | awk -F'|' -v n="$1" 'NR==n { print $1 }' \
++        | while read -r ts; do
++            ms=${ts##*.}; ms=${ms%Z}
++            echo $(( $(date -d "${ts%%.*}Z" +%s) * 1000 + 10#$ms ))
++          done
++}
++round_time() {
++    dnl The IGMP query of round $1 is the (2n-1)-th OFPT_PACKET_OUT.
++    packet_out_ts $((2 * $1 - 1))
++}
++check_interval_gap() {
++    gap=$(( $2 - $1 ))
++    check test "$gap" -ge $3 -a "$gap" -le $4
++}
++
++AS_BOX([Query rounds follow the configured interval])
++OVS_WAIT_UNTIL(
++  [test $(packet_out_count) -ge 2],
++  [grep "received: OFPT_PACKET_OUT" hv1/ovs-vswitchd.log])
++r1=$(round_time 1)
++OVS_WAIT_UNTIL(
++  [test $(packet_out_count) -ge 8],
++  [grep "received: OFPT_PACKET_OUT" hv1/ovs-vswitchd.log])
++r2=$(round_time 2)
++r3=$(round_time 3)
++r4=$(round_time 4)
++
++check_interval_gap $r1 $r2 2600 3600
++check_interval_gap $r2 $r3 2600 3600
++check_interval_gap $r3 $r4 2600 3600
++total=$(( r4 - r1 ))
++check test "$total" -ge 8000 -a "$total" -le 12000
++
++AS_BOX([Extending the interval keeps the pending round])
++dnl The pending fifth round was scheduled with the old 3s interval,
++dnl so it must still fire on time even after the interval is
++dnl extended.
++check ovn-nbctl --wait=hv set Logical_Switch ls1 other_config:mcast_query_interval=3600
++
++OVS_WAIT_UNTIL(
++  [test $(packet_out_count) -ge 10],
++  [grep "received: OFPT_PACKET_OUT" hv1/ovs-vswitchd.log])
++r5=$(round_time 5)
++check_interval_gap $r4 $r5 2600 4500
++
++dnl If the controller had not applied the extended interval before
++dnl the fifth round was rescheduled, a sixth round would have fired
++dnl right after it.
++sleep 4
++check test $(packet_out_count) -eq 10
++
++AS_BOX([Shortening the interval triggers an immediate round])
++check ovn-nbctl --wait=hv set Logical_Switch ls1 other_config:mcast_query_interval=1800
++
++OVS_WAIT_UNTIL(
++  [test $(packet_out_count) -eq 12],
++  [grep "received: OFPT_PACKET_OUT" hv1/ovs-vswitchd.log])
++r6=$(round_time 6)
++dnl The immediate round fires well before the new 1800s interval.
++check test $(( r6 - r5 )) -le 10000
++
++OVS_WAIT_UNTIL(
++  [test $(as hv1 ovs-ofctl dump-flows br-int table=OFTABLE_LOG_TO_PHY | grep -c "metadata=0x$dp_key ") -eq 2 \
++       -a $(as hv1 ovs-ofctl dump-flows br-int table=OFTABLE_LOG_TO_PHY | grep "metadata=0x$dp_key " | grep -c "n_packets=12,") -eq 2],
++  [as hv1 ovs-ofctl dump-flows br-int table=OFTABLE_LOG_TO_PHY])
++
++AS_BOX([Querier query contents])
++AT_CAPTURE_FILE([exp])
++AT_CAPTURE_FILE([rcv])
++check_packets() {
++    > exp
++    > rcv
++    if test "$1" = --uniq; then
++        sort="sort -u"; shift
++    else
++        sort=sort
++    fi
++    for tuple in "$@"; do
++        set $tuple; pcap=$1 type=$2
++        echo "--- $pcap" | tee -a exp >> rcv
++        $sort "$type" >> exp
++        $PYTHON "$ovs_srcdir/utilities/ovs-pcap.in" $pcap | $sort >> rcv
++        echo | tee -a exp >> rcv
++    done
++
++    $at_diff exp rcv >/dev/null
++}
++
++> expected
++store_igmp_v3_query 0000000002fe $(ip_to_hex 20 0 0 254) 84dd expected
++store_mld_query 0000000002fe fe8000000000000000000000000000fe expected
++
++OVS_WAIT_UNTIL(
++  [check_packets --uniq 'hv1/vif1-tx.pcap expected' \
++                 'hv1/vif2-tx.pcap expected'],
++  [$at_diff -F'^---' exp rcv])
++
++OVN_CLEANUP([hv1])
++AT_CLEANUP
++])
++
++OVN_FOR_EACH_NORTHD([
++AT_SETUP([IGMP/MLD querier per-port query fan-out first query at controller startup])
++AT_KEYWORDS([IP-multicast snoop querier])
++AT_KEYWORDS([slowtest])
++
++ovn_start
++
++dnl Multicast snooping and the querier are configured on ls1 before
++dnl the controller starts.  When the VIF on ls1 is bound, the
++dnl querier state for the switch is created and must fire an
++dnl immediate first query round, without waiting for the (maximum)
++dnl query interval to elapse.
++dnl
++dnl Known limitations: (1) the immediate round is observed through
++dnl the OFPT_PACKET_OUT messages it generates; (2) the first round
++dnl may fire before the VIF's egress OpenFlow pipeline is installed,
++dnl in which case its packets are dropped on the way to the port.
++dnl The arrival and content checks therefore run against a second
++dnl round, triggered immediately by shortening the query interval,
++dnl whose packets are certain to reach the port.
++
++check ovn-nbctl ls-add ls1
++check ovn-nbctl lsp-add ls1 ls1-p1
++
++# Enable multicast snooping and querier on ls1 before the controller
++# starts.  Use the maximum query interval so that, if any query round
++# fires during the test, it must be the immediate first one.
++check ovn-nbctl set Logical_Switch ls1 \
++    other_config:mcast_snoop="true" \
++    other_config:mcast_querier="true" \
++    other_config:mcast_query_interval=3600 \
++    other_config:mcast_eth_src="00:00:00:00:02:fe" \
++    other_config:mcast_ip4_src="20.0.0.254" \
++    other_config:mcast_ip6_src="fe80::fe"
++
++dnl Wait until northd has processed the snoop configuration.
++OVS_WAIT_UNTIL([test -n "$(fetch_column Datapath_Binding _uuid external_ids:name=ls1)"])
++dp_uuid=$(fetch_column Datapath_Binding _uuid external_ids:name=ls1)
++wait_column 3600 sb:IP_Multicast query_interval datapath=$dp_uuid
++
++net_add n1
++sim_add hv1
++as hv1
++check ovs-vsctl add-br br-phys
++ovn_attach n1 br-phys 192.168.0.1
++check ovs-vsctl set open . external-ids:ovn-bridge-mappings=phys:br-phys
++check ovs-vsctl add-port br-int hv1-vif1 -- \
++    set interface hv1-vif1 external-ids:iface-id=ls1-p1 \
++    options:tx_pcap=hv1/vif1-tx.pcap
++
++wait_for_ports_up
++
++# Wait for pinctrl thread to be connected
++OVS_WAIT_UNTIL([grep pinctrl hv1/ovn-controller.log | grep -c connected])
++
++packet_out_count() {
++    grep -c "received: OFPT_PACKET_OUT" hv1/ovs-vswitchd.log
++}
++
++pcap_count() {
++    $PYTHON "$ovs_srcdir/utilities/ovs-pcap.in" hv1/vif1-tx.pcap | wc -l
++}
++
++AS_BOX([The first query round fires immediately])
++dnl One IGMP query and one MLD query are sent without waiting for
++dnl the (maximum) query interval to elapse.
++OVS_WAIT_UNTIL(
++  [test $(packet_out_count) -eq 2],
++  [grep "received: OFPT_PACKET_OUT" hv1/ovs-vswitchd.log])
++
++dnl The first round's packets may not have reached the port yet (or
++dnl may be dropped entirely if the egress pipeline is not installed);
++dnl record the captured count either way.
++first_round_count=$(pcap_count)
++
++dnl Let the VIF's egress pipeline settle, then trigger an immediate
++dnl second round by shortening the interval.  Its packets must
++dnl reach the port.
++sleep 2
++check ovn-nbctl --wait=hv set Logical_Switch ls1 other_config:mcast_query_interval=1800
++
++OVS_WAIT_UNTIL(
++  [test $(packet_out_count) -eq 4],
++  [grep "received: OFPT_PACKET_OUT" hv1/ovs-vswitchd.log])
++
++dnl The second round must add its two queries to the capture, so the
++dnl two sets of packets arrive separately.
++OVS_WAIT_UNTIL(
++  [test $(pcap_count) -ge $((first_round_count + 2))],
++  [echo "pcap has $(pcap_count) packets, expected at least $((first_round_count + 2))"])
++
++AS_BOX([Querier query contents])
++AT_CAPTURE_FILE([exp])
++AT_CAPTURE_FILE([rcv])
++check_packets() {
++    > exp
++    > rcv
++    if test "$1" = --uniq; then
++        sort="sort -u"; shift
++    else
++        sort=sort
++    fi
++    for tuple in "$@"; do
++        set $tuple; pcap=$1 type=$2
++        echo "--- $pcap" | tee -a exp >> rcv
++        $sort "$type" >> exp
++        $PYTHON "$ovs_srcdir/utilities/ovs-pcap.in" $pcap | $sort >> rcv
++        echo | tee -a exp >> rcv
++    done
++
++    $at_diff exp rcv >/dev/null
++}
++
++> expected
++store_igmp_v3_query 0000000002fe $(ip_to_hex 20 0 0 254) 84dd expected
++store_mld_query 0000000002fe fe8000000000000000000000000000fe expected
++
++OVS_WAIT_UNTIL(
++  [check_packets --uniq 'hv1/vif1-tx.pcap expected'],
++  [$at_diff -F'^---' exp rcv])
++
++dnl The next round is a full query interval away.
++sleep 10
++check test $(packet_out_count) -eq 4
++
++OVN_CLEANUP([hv1])
++AT_CLEANUP
++])
++
++OVN_FOR_EACH_NORTHD([
++AT_SETUP([IGMP/MLD querier per-port query fan-out empty flood group])
++AT_KEYWORDS([IP-multicast snoop querier])
++AT_KEYWORDS([slowtest])
++
++ovn_start
++
++dnl A switch connected to a router through a static router port.
++dnl The router port belongs to the _MC_flood group, but its queries
++dnl always leave through the remote output and never to a local
++dnl port, so the switch's local flood port list stays empty.  A VIF
++dnl with receive_multicast disabled is claimed by the chassis (which
++dnl makes the switch a local datapath) without joining the
++dnl _MC_flood group.
++dnl
++dnl With an empty (but published) flood port list the querier must
++dnl not send queries and must reschedule the next round at the full
++dnl query interval, not the 1s unpublished retry.  Adding a port to
++dnl the flood group must not trigger an immediate round; shortening
++dnl the interval does.
++dnl
++dnl Known limitation: the "no queries sent" phases rely on the flood
++dnl port list being published before the querier state is created,
++dnl which holds in the current implementation because the port list
++dnl is published within the same controller loop iteration in which
++dnl the switch becomes local.
++
++check ovn-nbctl lr-add lr1
++check ovn-nbctl lrp-add lr1 lrp1 f0:00:00:00:00:f1 192.168.1.1/24
++check ovn-nbctl ls-add ls1
++check ovn-nbctl lsp-add ls1 ls1-lrp1
++check ovn-nbctl set Logical_Switch_Port ls1-lrp1 \
++    type=router \
++    options:router-port=lrp1 \
++    addresses=router
++
++# The VIF makes ls1 a local datapath on hv1 without joining the
++# _MC_flood group.
++check ovn-nbctl lsp-add ls1 ls1-p1
++check ovn-nbctl set Logical_Switch_Port ls1-p1 options:receive_multicast=false
++
++net_add n1
++sim_add hv1
++as hv1
++check ovs-vsctl add-br br-phys
++ovn_attach n1 br-phys 192.168.0.1
++check ovs-vsctl set open . external-ids:ovn-bridge-mappings=phys:br-phys
++check ovs-vsctl add-port br-int hv1-vif1 -- \
++    set interface hv1-vif1 external-ids:iface-id=ls1-p1
++
++wait_for_ports_up
++
++# Enable multicast snooping and querier on ls1 with the maximum
++# query interval.
++check ovn-nbctl --wait=hv set Logical_Switch ls1 \
++    other_config:mcast_snoop="true" \
++    other_config:mcast_querier="true" \
++    other_config:mcast_query_interval=3600 \
++    other_config:mcast_eth_src="00:00:00:00:02:fe" \
++    other_config:mcast_ip4_src="20.0.0.254" \
++    other_config:mcast_ip6_src="fe80::fe"
++
++# Wait for pinctrl thread to be connected
++OVS_WAIT_UNTIL([grep pinctrl hv1/ovn-controller.log | grep -c connected])
++
++dp_key=$(printf "%x" $(fetch_column Datapath_Binding tunnel_key external_ids:name=ls1))
++
++packet_out_count() {
++    grep -c "received: OFPT_PACKET_OUT" hv1/ovs-vswitchd.log
++}
++
++AS_BOX([No queries are sent while the flood group has no local ports])
++dnl The first query round finds an empty (published) local flood
++dnl port list and reschedules at the full interval; well before the
++dnl next due time no queries may have been sent.
++sleep 8
++check test $(packet_out_count) -eq 0
++
++AS_BOX([Adding a port to the flood group does not trigger a round])
++dnl Add a regular VIF.  It joins the _MC_flood group, so the flood
++dnl port list is no longer empty, but the pending round is still a
++dnl full interval away.
++check ovn-nbctl lsp-add ls1 ls1-p2
++check ovs-vsctl add-port br-int hv1-vif2 -- \
++    set interface hv1-vif2 external-ids:iface-id=ls1-p2 \
++    options:tx_pcap=hv1/vif2-tx.pcap
++wait_for_ports_up
 +
-+    for gw in gw1 gw2; do
-+        as $gw reset_pcap_file br-ex_provider $gw/br-ex_provider
-+    done
-+    if test "$colocated" = yes; then
-+        cat bfd1.expected bfd2.expected | sort > gw1.expected
-+        : > gw2.expected
++sleep 8
++check test $(packet_out_count) -eq 0
++
++AS_BOX([Shortening the interval triggers an immediate round])
++check ovn-nbctl --wait=hv set Logical_Switch ls1 other_config:mcast_query_interval=1800
++
++OVS_WAIT_UNTIL(
++  [test $(packet_out_count) -eq 2],
++  [grep "received: OFPT_PACKET_OUT" hv1/ovs-vswitchd.log])
++
++dnl Both queries went to the new port only: the VIF flow is the only
++dnl flow of the datapath that counts packets (the router port's
++dnl flows do not receive the queries).
++OVS_WAIT_UNTIL(
++  [test $(as hv1 ovs-ofctl dump-flows br-int table=OFTABLE_LOG_TO_PHY | grep "metadata=0x$dp_key " | grep -c "n_packets=2,") -eq 1],
++  [as hv1 ovs-ofctl dump-flows br-int table=OFTABLE_LOG_TO_PHY])
++
++AS_BOX([Querier query contents])
++AT_CAPTURE_FILE([exp])
++AT_CAPTURE_FILE([rcv])
++check_packets() {
++    > exp
++    > rcv
++    if test "$1" = --uniq; then
++        sort="sort -u"; shift
 +    else
-+        cp bfd1.expected gw1.expected
-+        cp bfd2.expected gw2.expected
++        sort=sort
 +    fi
++    for tuple in "$@"; do
++        set $tuple; pcap=$1 type=$2
++        echo "--- $pcap" | tee -a exp >> rcv
++        $sort "$type" >> exp
++        $PYTHON "$ovs_srcdir/utilities/ovs-pcap.in" $pcap | $sort >> rcv
++        echo | tee -a exp >> rcv
++    done
 +
-+    # These are packets emitted by pinctrl and forwarded by ovs-vswitchd,
-+    # not traces or flow dumps.  Ignore ARP and compare the set of BFD
-+    # sessions at each provider uplink, including the source MAC selected
-+    # by routing.  Wait for several packets, and reject unexpected sessions.
-+    OVS_WAIT_UNTIL([
-+        for gw in gw1 gw2; do
-+            $PYTHON "$ovs_srcdir/utilities/ovs-pcap.in" \
-+                $gw/br-ex_provider-tx.pcap | \
-+                grep -E '^.{24}080045.{16}11.{24}0ec8' | \
-+                cut -c 1-28,53-76,93-100 > $gw.bfd
-+            sort -u $gw.bfd > $gw.actual
-+        done
-+        test $(wc -l < gw1.bfd) -ge 3 &&
-+        { test "$colocated" = yes || test $(wc -l < gw2.bfd) -ge 3; } &&
-+        diff -u gw1.expected gw1.actual &&
-+        diff -u gw2.expected gw2.actual
-+    ])
++    $at_diff exp rcv >/dev/null
 +}
 +
-+AT_CAPTURE_FILE([gw1.actual])
-+AT_CAPTURE_FILE([gw2.actual])
-+AT_CAPTURE_FILE([gw1.expected])
-+AT_CAPTURE_FILE([gw2.expected])
-+
-+AS_BOX([BFD sessions on separate gateways])
-+# Each gateway must send only its own session through its provider uplink.
-+check_bfd_packets no
-+
-+AS_BOX([BFD sessions after controller recompute])
-+# Recomputing the controllers must not change either session's egress path.
-+for gw in gw1 gw2; do
-+    check as $gw ovn-appctl -t ovn-controller inc-engine/recompute
-+done
-+check ovn-nbctl --wait=hv sync
-+check_bfd_packets no
++> expected
++store_igmp_v3_query 0000000002fe $(ip_to_hex 20 0 0 254) 84dd expected
++store_mld_query 0000000002fe fe8000000000000000000000000000fe expected
 +
-+AS_BOX([BFD sessions on the same gateway])
-+# Also check both LRPs on one chassis.  Without the fix only one of the
-+# conflicting routes can win, so at least one session gets the wrong source
-+# MAC regardless of flow ordering.  This makes the regression deterministic.
-+check ovn-nbctl --wait=hv \
-+    lrp-del-gateway-chassis r0-ext2 gw2 -- \
-+    lrp-set-gateway-chassis r0-ext2 gw1
-+chassis=$(fetch_column Chassis _uuid name=gw1)
-+wait_column "$chassis" Port_Binding chassis logical_port=cr-r0-ext2
-+check ovn-nbctl --wait=hv sync
-+check_bfd_packets yes
++OVS_WAIT_UNTIL(
++  [check_packets --uniq 'hv1/vif2-tx.pcap expected'],
++  [$at_diff -F'^---' exp rcv])
 +
-+AS_BOX([BFD sessions back on separate gateways])
-+check ovn-nbctl --wait=hv \
-+    lrp-del-gateway-chassis r0-ext2 gw1 -- \
-+    lrp-set-gateway-chassis r0-ext2 gw2
-+chassis=$(fetch_column Chassis _uuid name=gw2)
-+wait_column "$chassis" Port_Binding chassis logical_port=cr-r0-ext2
-+check ovn-nbctl --wait=hv sync
-+check_bfd_packets no
++dnl The next round is a full query interval away.
++sleep 10
++check test $(packet_out_count) -eq 2
 +
-+OVN_CLEANUP([gw1
-+ignored_tables=OFTABLE_PHY_TO_LOG
-+], [gw2
-+ignored_tables=OFTABLE_PHY_TO_LOG
-+])
++OVN_CLEANUP([hv1])
 +AT_CLEANUP
 +])
 +
  OVN_FOR_EACH_NORTHD([
- AT_SETUP([4 HV, 1 LS, 1 LR, packet test with HA distributed router gateway port])
+ AT_SETUP([unixctl socket])
  ovn_start
-@@ -33834,6 +33972,30 @@ match=(1), action=(next;)
+@@ -33834,6 +34624,30 @@ match=(1), action=(next;)
  match=(inport == "sw0-p1"), action=(reg0[[11]] = lookup_fdb(inport, eth.src); next;)
    table=??(ls_in_lookup_fdb   ), priority=100  , dnl
  match=(inport == "sw0-p3"), action=(reg0[[11]] = lookup_fdb(inport, eth.src); next;)
@@ -2420,7 +6071,7 @@ index 09b4d2c61..b6db571ec 100644
  ])
  
  AT_CHECK([grep "ls_in_put_fdb" sw0flows | ovn_strip_lflows], [0], [dnl
-@@ -33843,6 +34005,30 @@ match=(1), action=(next;)
+@@ -33843,6 +34657,30 @@ match=(1), action=(next;)
  match=(inport == "sw0-p1" && reg0[[11]] == 0), action=(put_fdb(inport, eth.src); next;)
    table=??(ls_in_put_fdb      ), priority=100  , dnl
  match=(inport == "sw0-p3" && reg0[[11]] == 0), action=(put_fdb(inport, eth.src); next;)
@@ -2451,7 +6102,7 @@ index 09b4d2c61..b6db571ec 100644
  ])
  
  # Send a packet from sw0-p1 with a different mac not present
-@@ -34184,6 +34370,301 @@ OVN_CLEANUP([hv1], [hv2], [hv3])
+@@ -34184,6 +35022,301 @@ OVN_CLEANUP([hv1], [hv2], [hv3])
  AT_CLEANUP
  ])
  
@@ -2753,7 +6404,91 @@ index 09b4d2c61..b6db571ec 100644
  OVN_FOR_EACH_NORTHD([
  AT_SETUP([container port changed to normal port and then deleted])
  ovn_start
-@@ -39002,6 +39483,10 @@ ovn_attach n1 br-phys 192.168.0.1
+@@ -37678,6 +38811,83 @@ OVN_CLEANUP([hv1])
+ AT_CLEANUP
+ ])
+ 
++OVN_FOR_EACH_NORTHD([
++AT_SETUP([MAC binding aging - probing off-subnet next hop])
++CHECK_SCAPY
++ovn_start
++
++aging_th=10
++net_add n1
++sim_add hv1
++as hv1
++check ovs-vsctl add-br br-phys
++ovn_attach n1 br-phys 192.168.0.1
++ovn-appctl -t ovn-controller vlog/set mac_cache:file:dbg pinctrl:file:dbg
++
++check ovn-nbctl                                                             \
++    -- ls-add ls1                                                           \
++    -- lr-add lr                                                            \
++    -- set logical_router lr options:mac_binding_age_threshold=$aging_th    \
++    -- lrp-add lr lr-ls1 00:00:00:00:10:00 10.10.10.1/32 fd11::1/128        \
++    -- lsp-add-router-port ls1 ls1-lr lr-ls1                                \
++    -- lsp-add ls1 vif1                                                     \
++    -- lsp-set-addresses vif1 "unknown"
++
++# Off-subnet next hops reachable through the router port via explicit
++# output_port routes, as documented in ovn-nb.xml.
++check ovn-nbctl lr-route-add lr 10.10.30.0/24 10.10.20.100 lr-ls1
++check ovn-nbctl lr-route-add lr fd30::/64 fd20::64 lr-ls1
++
++check ovs-vsctl                                                             \
++    -- add-port br-int vif1                                                 \
++    -- set interface vif1 external-ids:iface-id=vif1                        \
++    options:tx_pcap=hv1/vif1-tx.pcap options:rxq_pcap=hv1/vif1-rx.pcap
++
++OVN_POPULATE_ARP
++wait_for_ports_up
++check ovn-nbctl --wait=hv sync
++
++# Wait for pinctrl thread to be connected.
++OVS_WAIT_UNTIL([grep pinctrl hv1/ovn-controller.log | grep -q connected])
++
++# Learn MAC bindings for the off-subnet next hops.
++send_garp hv1 vif1 2 00:00:00:00:10:1a ff:ff:ff:ff:ff:ff 10.10.20.100 10.10.20.100
++wait_row_count mac_binding 1 ip="10.10.20.100" logical_port="lr-ls1"
++
++send_na hv1 vif1 00:00:00:00:10:1a 00:00:00:00:10:00 fd20::64 fd11::1
++wait_row_count mac_binding 1 ip=\"fd20::64\" logical_port=\"lr-ls1\"
++
++# Send IPv4 and IPv6 UDP traffic so the router resolves and uses the learned
++# bindings (this refreshes the OFTABLE_MAC_BINDING entries).  Use a src MAC
++# different from the one learned via GARP/NA so OFTABLE_MAC_CACHE_USE is not
++# reset (that would keep the timestamp fresh and suppress probing).
++send_udp hv1 vif1 00:00:00:00:10:00 00:00:00:00:10:2a 10.10.30.1 172.16.1.1
++send_udp6 hv1 vif1 00:00:00:00:10:00 00:00:00:00:10:2a fd30::1 fd55::1
++
++OVS_WAIT_UNTIL([ovs-ofctl dump-flows br-int table=OFTABLE_MAC_BINDING | \
++                sed 's/reg15=0x.,metadata=0x./reg15=<cleared>,metadata=<cleared>/g' | \
++                grep -q "reg0=0xa0a1464,reg15=<cleared>,metadata=<cleared> actions=mod_dl_dst:00:00:00:00:10:1a"])
++
++# Wait until entries in OFTABLE_MAC_CACHE_USE are stale.
++OVS_WAIT_UNTIL([test $(ovs-ofctl dump-flows br-int table=OFTABLE_MAC_CACHE_USE | \
++                       awk '/nw_src=10.10.20.100/{print substr($6,10,1)}') -ge $((aging_th/2))])
++OVS_WAIT_UNTIL([test $(ovs-ofctl dump-flows br-int table=OFTABLE_MAC_CACHE_USE | \
++                       awk '/ipv6_src=fd20::64/{print substr($6,10,1)}') -ge $((aging_th/2))])
++
++# Send traffic to trigger probing for both entries.
++send_udp hv1 vif1 00:00:00:00:10:00 00:00:00:00:10:2a 10.10.30.1 172.16.1.1
++send_udp6 hv1 vif1 00:00:00:00:10:00 00:00:00:00:10:2a fd30::1 fd55::1
++
++# Verify ARP/ND probes use the router port's (only) address as the source.
++dump_arp 1 00:00:00:00:10:00 00:00:00:00:10:1a 10.10.10.1 10.10.20.100 00:00:00:00:10:1a > expected
++OVN_CHECK_PACKETS_CONTAIN([hv1/vif1-tx.pcap], [expected])
++
++dump_ns 00:00:00:00:10:1a 00:00:00:00:10:00 fd20::64 fd11::1 fd20::64 > expected_v6
++OVN_CHECK_PACKETS_CONTAIN([hv1/vif1-tx.pcap], [expected_v6])
++
++OVN_CLEANUP([hv1])
++AT_CLEANUP
++])
+ OVN_FOR_EACH_NORTHD([
+ AT_SETUP([MAC binding aging - probing unicast to broadcast transition])
+ CHECK_SCAPY
+@@ -39002,6 +40212,10 @@ ovn_attach n1 br-phys 192.168.0.1
  OVS_WAIT_UNTIL([ovs-vsctl get Open_vSwitch . other_config:ovn-chassis-idx-hv1])
  OVS_WAIT_UNTIL([test x$(ovs-vsctl get Open_vSwitch . other_config:ovn-chassis-idx-hv1) = 'x""'])
  
@@ -2764,7 +6499,7 @@ index 09b4d2c61..b6db571ec 100644
  # exit ovn-controller which should clean up allocated index in the database
  OVS_APP_EXIT_AND_WAIT([ovn-controller])
  
-@@ -39017,6 +39502,81 @@ OVN_CLEANUP
+@@ -39017,6 +40231,81 @@ OVN_CLEANUP
  AT_CLEANUP
  ])
  
@@ -2846,7 +6581,7 @@ index 09b4d2c61..b6db571ec 100644
  OVN_FOR_EACH_NORTHD([
  AT_SETUP([chassis-specific configuration options])
  ovn_start
-@@ -40124,8 +40684,9 @@ check ovn-nbctl lrp-set-gateway-chassis lr0-public hv2 20
+@@ -40124,8 +41413,9 @@ check ovn-nbctl lrp-set-gateway-chassis lr0-public hv2 20
  check ovn-nbctl lr-nat-add lr0 snat 172.168.0.1 10.0.0.0/24
  check ovn-nbctl lr-nat-add lr0 dnat_and_snat 172.168.0.110 10.0.0.2 sw0-port1 f0:00:00:01:02:03
  
@@ -2857,7 +6592,7 @@ index 09b4d2c61..b6db571ec 100644
  
  # send UDP request to the FIP associated to sw0-port1
  test_ip_req_packet "f0:00:00:01:02:03" "172.168.0.110"
-@@ -40140,7 +40701,7 @@ echo $fip_packet > expected
+@@ -40140,7 +41430,7 @@ echo $fip_packet > expected
  OVN_CHECK_PACKETS_REMOVE_BROADCAST([hv2/vif1-tx.pcap], [expected])
  
  check ovn-nbctl lb-add lb0 172.168.0.1:4369 10.0.0.2:4369 udp
@@ -2866,7 +6601,7 @@ index 09b4d2c61..b6db571ec 100644
  
  # send UDP request to the load-balancer VIP
  test_ip_req_packet "00:00:20:20:12:13" "172.168.0.1"
-@@ -40780,12 +41341,12 @@ sleep_sb
+@@ -40780,12 +42070,12 @@ sleep_sb
  sleep_controller hv2
  
  AS_BOX([$(date +%H:%M:%S.%03N) Sending ARP 14 -> 24])
@@ -2881,7 +6616,7 @@ index 09b4d2c61..b6db571ec 100644
  as hv2 ovs-appctl netdev-dummy/receive vif24 $arp_req
  sleep 1
  
-@@ -40813,12 +41374,12 @@ sleep_sb
+@@ -40813,12 +42103,12 @@ sleep_sb
  sleep_controller hv2
  
  AS_BOX([$(date +%H:%M:%S.%03N) Sending ARP 15 -> 25])
@@ -2896,7 +6631,7 @@ index 09b4d2c61..b6db571ec 100644
  as hv2 ovs-appctl netdev-dummy/receive vif25 $arp_req
  
  sleep 1
-@@ -40842,7 +41403,10 @@ expected_flow_count=$(($expected_flow_count + 4))
+@@ -40842,7 +42132,10 @@ expected_flow_count=$(($expected_flow_count + 4))
  check_flow_count hv1 $expected_flow_count
  check_flow_count hv2 $expected_flow_count
  
@@ -2908,7 +6643,7 @@ index 09b4d2c61..b6db571ec 100644
  # Do not check number of PACKET_IN2 on hv2, as vif14 => 99 as well as vif15 => vif25
  # might have caused PACKET_IN2, but without any guarantee.
  # e.g. (1) packet => hv1 ovs, (2) PACKET_IN2 => hv1 ovn, (3) FDB => sb,
-@@ -40854,7 +41418,7 @@ AT_CHECK([test 5 = `cat hv1/ovs-vswitchd.log | grep NXT_PACKET_IN2 | wc -l`])
+@@ -40854,7 +42147,7 @@ AT_CHECK([test 5 = `cat hv1/ovs-vswitchd.log | grep NXT_PACKET_IN2 | wc -l`])
  # hv1 is expected to be stable.
  
  AS_BOX([$(date +%H:%M:%S.%03N) Packet from external])
@@ -2917,7 +6652,123 @@ index 09b4d2c61..b6db571ec 100644
  as hv2 ovs-appctl netdev-dummy/receive ext0 $arp_req
  wait_column "$ln_port_key" fdb port_key mac='"00:00:00:00:10:40"'
  
-@@ -47258,13 +47822,11 @@ mld_packet=$(fmt_pkt \
+@@ -42142,6 +43435,64 @@ ignored_dp=ls0])
+ AT_CLEANUP
+ ])
+ 
++OVN_FOR_EACH_NORTHD([
++AT_SETUP([Port claimed outside of binding does not stay postponed])
++AT_KEYWORDS([claim postpone])
++ovn_start
++
++check ovn-nbctl ls-add ls0
++check ovn-nbctl lsp-add ls0 lsp0
++
++net_add n1
++sim_add hv1
++as hv1
++check ovs-vsctl add-br br-phys
++ovn_attach n1 br-phys 192.168.0.1
++
++# A chassis that is not running ovn-controller, so that nothing releases or
++# claims the ports bound to it.
++check ovn-sbctl chassis-add fake geneve 192.168.0.100
++hv1_uuid=$(fetch_column Chassis _uuid name=hv1)
++fake_uuid=$(fetch_column Chassis _uuid name=fake)
++
++as hv1 check ovn-appctl -t ovn-controller vlog/set binding:file:dbg
++as hv1 check ovs-vsctl add-port br-int vif -- \
++    set Interface vif external_ids:iface-id=lsp0
++wait_for_ports_up lsp0
++pb_uuid=$(fetch_column Port_Binding _uuid logical_port=lsp0)
++
++# Bind lsp0 to the other chassis shortly after hv1 claimed it, so that hv1
++# postpones claiming it back.  If hv1 was too late to postpone, it claims
++# lsp0 back right away, so just try again.
++OVS_WAIT_UNTIL([
++    check ovn-sbctl set Port_Binding $pb_uuid chassis=$fake_uuid
++    sleep 0.1
++    grep -q "Postponed claim on logical port lsp0" hv1/ovn-controller.log
++])
++
++# Bind lsp0 back to hv1 without going through binding, as if-status does
++# once the claim threshold has passed.  hv1 sees lsp0 bound to itself, so
++# the claim is complete.
++sleep_controller hv1
++check ovn-sbctl set Port_Binding $pb_uuid chassis=$hv1_uuid
++wake_up_controller hv1
++wait_column "$hv1_uuid" Port_Binding chassis logical_port=lsp0
++check ovn-nbctl --wait=hv sync
++
++# lsp0 must not stay postponed, otherwise it is processed again on every
++# engine run.
++as hv1 check ovn-appctl -t ovn-controller vlog/set inc_proc_eng:file:dbg
++check ovn-nbctl --wait=hv sync
++check ovn-nbctl --wait=hv sync
++as hv1 check ovn-appctl -t ovn-controller vlog/set inc_proc_eng:file:info
++AT_CHECK([grep -c "node: postponed_ports, old_state Stale, new_state Updated" \
++    hv1/ovn-controller.log], [1], [0
++])
++
++OVN_CLEANUP([hv1])
++AT_CLEANUP
++])
++
+ dnl This test checks that the megaflows translated by ovs-vswitchd
+ dnl don't match on IPv6 source and destination addresses for
+ dnl simple switching.
+@@ -42722,6 +44073,50 @@ OVN_CLEANUP([hv1])
+ AT_CLEANUP
+ ])
+ 
++OVN_FOR_EACH_NORTHD([
++AT_SETUP([ovn-controller - vif-plug provider returns false])
++AT_KEYWORDS([vif-plug])
++
++ovn_start
++
++net_add n1
++sim_add hv1
++ovs-vsctl add-br br-phys
++ovn_attach n1 br-phys 192.168.0.1
++
++check ovn-nbctl ls-add lsw0
++
++check ovn-nbctl lsp-add lsw0 lsp1
++check ovn-nbctl lsp-set-addresses lsp1 "f0:00:00:00:00:01 172.16.0.101"
++
++# Ask the dummy provider to signal "not ready" from its prepare callback.
++# ovn-controller must defer plugging and keep running instead of crashing.
++check ovn-nbctl lsp-set-options lsp1 \
++    requested-chassis=hv1 \
++    vif-plug-type=dummy \
++    vif-plug-dummy-return-false=true
++
++OVS_WAIT_UNTIL([
++    grep -q "Not plugging/updating lport lsp1 on direction from VIF plug provider." hv1/ovn-controller.log
++])
++
++# The controller must still be alive and the port must not be plugged.
++AT_CHECK([as hv1 ovs-appctl -t ovn-controller version >/dev/null], [0], [], [ignore])
++AT_CHECK([as hv1 ovs-vsctl get Interface lsp1 _uuid], [1], [], [ignore])
++
++# Once the provider is ready again, the port gets plugged.
++check ovn-nbctl lsp-set-options lsp1 \
++    requested-chassis=hv1 \
++    vif-plug-type=dummy
++
++OVS_WAIT_UNTIL([
++    as hv1 ovs-vsctl get Interface lsp1 _uuid >/dev/null 2>&1
++])
++
++OVN_CLEANUP([hv1])
++AT_CLEANUP
++])
++
+ AT_SETUP([Patch ports not owned by OVN])
+ 
+ AT_KEYWORDS([ovn])
+@@ -47258,13 +48653,11 @@ mld_packet=$(fmt_pkt \
  check as hv1 ovs-appctl netdev-dummy/receive br-phys_n1 $mld_packet
  
  # IGMPv3 report.  Same scenario but with IPv4 multicast.
@@ -2937,10 +6788,267 @@ index 09b4d2c61..b6db571ec 100644
  # Wait for pinctrl to fully process the IGMP/MLD reports and sync them
  # to the SB database.  This guarantees that pinctrl has also re-injected
 diff --git a/tests/system-ovn.at b/tests/system-ovn.at
-index 38e15b7d9..872e9ce6b 100644
+index 38e15b7d99..845418630f 100644
 --- a/tests/system-ovn.at
 +++ b/tests/system-ovn.at
-@@ -6265,7 +6265,7 @@ NS_CHECK_EXEC([vm2], [ncat 66.66.66.66 666 -p 2001 -z], [0], [ignore], [ignore])
+@@ -2559,6 +2559,256 @@ OVS_TRAFFIC_VSWITCHD_STOP(["/failed to query port patch-.*/d
+ AT_CLEANUP
+ ])
+ 
++OVN_FOR_EACH_NORTHD([
++AT_SETUP([load balancing with lb_force_snat_ip on a distributed gateway port])
++AT_KEYWORDS([ovnlb])
++
++CHECK_CONNTRACK()
++CHECK_CONNTRACK_NAT()
++ovn_start
++OVS_TRAFFIC_VSWITCHD_START()
++ADD_BR([br-int])
++
++# Set external-ids in br-int needed for ovn-controller.
++check ovs-vsctl \
++        -- set Open_vSwitch . external-ids:system-id=hv1 \
++        -- set Open_vSwitch . external-ids:ovn-remote=unix:$ovs_base/ovn-sb/ovn-sb.sock \
++        -- set Open_vSwitch . external-ids:ovn-encap-type=geneve \
++        -- set Open_vSwitch . external-ids:ovn-encap-ip=169.0.0.1 \
++        -- set bridge br-int fail-mode=secure other-config:disable-in-band=true
++
++# Start ovn-controller.
++start_daemon ovn-controller
++
++# Logical network:
++#
++#    foo -- R1 -- join -- R2 == alice
++#
++# R2 is not a gateway router; its "alice" port is a distributed gateway
++# port.  The load balancer is attached to R2 and its backend sits on
++# "alice", i.e. it is reached through the distributed gateway port, so the
++# load balanced traffic leaves R2 through that port and is what the forced
++# SNAT has to act on.
++
++check_uuid ovn-nbctl create Logical_Router name=R1
++check_uuid ovn-nbctl create Logical_Router name=R2
++
++check ovn-nbctl ls-add foo
++check ovn-nbctl ls-add alice
++check ovn-nbctl ls-add join
++
++# Connect foo to R1.
++check ovn-nbctl lrp-add R1 foo 00:00:01:01:02:03 192.168.1.1/24
++check ovn-nbctl lsp-add foo rp-foo -- set Logical_Switch_Port rp-foo \
++    type=router options:router-port=foo addresses=\"00:00:01:01:02:03\"
++
++# Connect alice to R2 through a distributed gateway port.
++check ovn-nbctl lrp-add R2 alice 00:00:02:01:02:03 172.16.1.1/24
++check ovn-nbctl lrp-set-gateway-chassis alice hv1 20
++check ovn-nbctl lsp-add alice rp-alice -- set Logical_Switch_Port rp-alice \
++    type=router options:router-port=alice addresses=\"00:00:02:01:02:03\"
++
++# Connect R1 to join.
++check ovn-nbctl lrp-add R1 R1_join 00:00:04:01:02:03 20.0.0.1/24
++check ovn-nbctl lsp-add join r1-join -- set Logical_Switch_Port r1-join \
++    type=router options:router-port=R1_join addresses='"00:00:04:01:02:03"'
++
++# Connect R2 to join.
++check ovn-nbctl lrp-add R2 R2_join 00:00:04:01:02:04 20.0.0.2/24
++check ovn-nbctl lsp-add join r2-join -- set Logical_Switch_Port r2-join \
++    type=router options:router-port=R2_join addresses='"00:00:04:01:02:04"'
++
++# Static routes.
++check ovn-nbctl lr-route-add R1 30.0.0.0/24 20.0.0.2
++check ovn-nbctl lr-route-add R1 172.16.1.0/24 20.0.0.2
++check ovn-nbctl lr-route-add R2 192.168.0.0/16 20.0.0.1
++
++# Logical port 'foo1' in switch 'foo'.  This is the client.
++ADD_NAMESPACES(foo1)
++ADD_VETH(foo1, foo1, br-int, "192.168.1.2/24", "f0:00:00:01:02:03", \
++         "192.168.1.1")
++check ovn-nbctl lsp-add foo foo1 \
++-- lsp-set-addresses foo1 "f0:00:00:01:02:03 192.168.1.2"
++
++# Logical port 'alice1' in switch 'alice'.  This is the backend.
++ADD_NAMESPACES(alice1)
++ADD_VETH(alice1, alice1, br-int, "172.16.1.2/24", "f0:00:00:01:02:04", \
++         "172.16.1.1")
++check ovn-nbctl lsp-add alice alice1 \
++-- lsp-set-addresses alice1 "f0:00:00:01:02:04 172.16.1.2"
++
++uuid=`ovn-nbctl create load_balancer vips:'"30.0.0.2:8000"'='"172.16.1.2:80"'`
++check ovn-nbctl set logical_router R2 load_balancer=$uuid
++
++# A plain subnet SNAT entry that also matches the load balanced traffic on
++# its way out of the distributed gateway port.  Its lr_out_snat priority is
++# shifted up on such a router, so it would take precedence over an
++# unshifted force SNAT flow and lb_force_snat_ip would be ignored.
++check ovn-nbctl lr-nat-add R2 snat 172.16.1.100 192.168.0.0/16
++
++check ovn-nbctl set logical_router R2 options:lb_force_snat_ip="172.16.1.1"
++
++check ovn-nbctl --wait=hv sync
++
++snat=$(ovn-debug lflow-stage-to-oftable lr_out_snat)
++OVS_WAIT_UNTIL([ovs-ofctl -O OpenFlow13 dump-flows br-int table=$snat | \
++grep 'nat(src=172.16.1.1)'])
++
++# Start a webserver on the backend.
++OVS_START_L7([alice1], [http])
++
++dnl A client behind R1 connects to the VIP.  The load balanced traffic leaves
++dnl R2 through the distributed gateway port and has to be SNATed to the forced
++dnl address, and the reply has to be unDNATed back to the VIP, otherwise the
++dnl client resets the connection.
++check ovs-appctl dpctl/flush-conntrack
++NS_CHECK_EXEC([foo1], [wget http://30.0.0.2:8000 -t 5 -T 1 --retry-connrefused -v -o wget-foo1.log])
++
++AT_CHECK([ovs-appctl dpctl/dump-conntrack | FORMAT_CT(172.16.1.2) | \
++          grep "src=192.168.1.2,dst=172.16.1.2," | sed -e 's/zone=[[0-9]]*/zone=<cleared>/'], [0], [dnl
++tcp,orig=(src=192.168.1.2,dst=172.16.1.2,sport=<cleared>,dport=<cleared>),reply=(src=172.16.1.2,dst=172.16.1.1,sport=<cleared>,dport=<cleared>),zone=<cleared>,protoinfo=(state=<cleared>)
++])
++
++dnl Hairpin: the backend connects to its own VIP.  Without the forced SNAT the
++dnl reply would carry identical source and destination addresses.
++check ovs-appctl dpctl/flush-conntrack
++NS_CHECK_EXEC([alice1], [wget http://30.0.0.2:8000 -t 5 -T 1 --retry-connrefused -v -o wget-alice1.log])
++
++AT_CHECK([ovs-appctl dpctl/dump-conntrack | FORMAT_CT(172.16.1.1) | \
++          sed -e 's/zone=[[0-9]]*/zone=<cleared>/'], [0], [dnl
++tcp,orig=(src=172.16.1.2,dst=172.16.1.2,sport=<cleared>,dport=<cleared>),reply=(src=172.16.1.2,dst=172.16.1.1,sport=<cleared>,dport=<cleared>),zone=<cleared>,protoinfo=(state=<cleared>)
++])
++
++OVN_CLEANUP_CONTROLLER([hv1])
++
++OVN_CLEANUP_NORTHD
++
++as
++OVS_TRAFFIC_VSWITCHD_STOP(["/failed to query port patch-.*/d
++/Failed to acquire.*/d
++/connection dropped.*/d"])
++AT_CLEANUP
++])
++
++OVN_FOR_EACH_NORTHD([
++AT_SETUP([load balancing with skip_snat on a distributed gateway port])
++AT_KEYWORDS([ovnlb])
++
++CHECK_CONNTRACK()
++CHECK_CONNTRACK_NAT()
++ovn_start
++OVS_TRAFFIC_VSWITCHD_START()
++ADD_BR([br-int])
++
++# Set external-ids in br-int needed for ovn-controller.
++check ovs-vsctl \
++        -- set Open_vSwitch . external-ids:system-id=hv1 \
++        -- set Open_vSwitch . external-ids:ovn-remote=unix:$ovs_base/ovn-sb/ovn-sb.sock \
++        -- set Open_vSwitch . external-ids:ovn-encap-type=geneve \
++        -- set Open_vSwitch . external-ids:ovn-encap-ip=169.0.0.1 \
++        -- set bridge br-int fail-mode=secure other-config:disable-in-band=true
++
++# Start ovn-controller.
++start_daemon ovn-controller
++
++# Logical network:
++#
++#    foo -- R1 -- join -- R2 == alice
++#
++# R2 is not a gateway router; its "alice" port is a distributed gateway
++# port.  The load balancer is attached to R2 and its backend sits on
++# "alice", i.e. it is reached through the distributed gateway port, so the
++# load balanced traffic leaves R2 through that port and is what the forced
++# SNAT has to act on.
++
++check_uuid ovn-nbctl create Logical_Router name=R1
++check_uuid ovn-nbctl create Logical_Router name=R2
++
++check ovn-nbctl ls-add foo
++check ovn-nbctl ls-add alice
++check ovn-nbctl ls-add join
++
++# Connect foo to R1.
++check ovn-nbctl lrp-add R1 foo 00:00:01:01:02:03 192.168.1.1/24
++check ovn-nbctl lsp-add foo rp-foo -- set Logical_Switch_Port rp-foo \
++    type=router options:router-port=foo addresses=\"00:00:01:01:02:03\"
++
++# Connect alice to R2 through a distributed gateway port.
++check ovn-nbctl lrp-add R2 alice 00:00:02:01:02:03 172.16.1.1/24
++check ovn-nbctl lrp-set-gateway-chassis alice hv1 20
++check ovn-nbctl lsp-add alice rp-alice -- set Logical_Switch_Port rp-alice \
++    type=router options:router-port=alice addresses=\"00:00:02:01:02:03\"
++
++# Connect R1 to join.
++check ovn-nbctl lrp-add R1 R1_join 00:00:04:01:02:03 20.0.0.1/24
++check ovn-nbctl lsp-add join r1-join -- set Logical_Switch_Port r1-join \
++    type=router options:router-port=R1_join addresses='"00:00:04:01:02:03"'
++
++# Connect R2 to join.
++check ovn-nbctl lrp-add R2 R2_join 00:00:04:01:02:04 20.0.0.2/24
++check ovn-nbctl lsp-add join r2-join -- set Logical_Switch_Port r2-join \
++    type=router options:router-port=R2_join addresses='"00:00:04:01:02:04"'
++
++# Static routes.
++check ovn-nbctl lr-route-add R1 30.0.0.0/24 20.0.0.2
++check ovn-nbctl lr-route-add R1 172.16.1.0/24 20.0.0.2
++check ovn-nbctl lr-route-add R2 192.168.0.0/16 20.0.0.1
++
++# Logical port 'foo1' in switch 'foo'.  This is the client.
++ADD_NAMESPACES(foo1)
++ADD_VETH(foo1, foo1, br-int, "192.168.1.2/24", "f0:00:00:01:02:03", \
++         "192.168.1.1")
++check ovn-nbctl lsp-add foo foo1 \
++-- lsp-set-addresses foo1 "f0:00:00:01:02:03 192.168.1.2"
++
++# Logical port 'alice1' in switch 'alice'.  This is the backend.
++ADD_NAMESPACES(alice1)
++ADD_VETH(alice1, alice1, br-int, "172.16.1.2/24", "f0:00:00:01:02:04", \
++         "172.16.1.1")
++check ovn-nbctl lsp-add alice alice1 \
++-- lsp-set-addresses alice1 "f0:00:00:01:02:04 172.16.1.2"
++
++uuid=`ovn-nbctl create load_balancer vips:'"30.0.0.2:8000"'='"172.16.1.2:80"'`
++check ovn-nbctl set logical_router R2 load_balancer=$uuid
++
++# A plain subnet SNAT entry that also matches the load balanced traffic on
++# its way out of the distributed gateway port.  Its lr_out_snat priority is
++# shifted up on such a router, so it would take precedence over an
++# unshifted skip_snat flow and the option would be ignored.
++check ovn-nbctl lr-nat-add R2 snat 172.16.1.100 192.168.0.0/16
++
++check ovn-nbctl set load_balancer $uuid options:skip_snat=true
++
++check ovn-nbctl --wait=hv sync
++
++# Start a webserver on the backend.
++OVS_START_L7([alice1], [http])
++
++dnl The load balanced traffic must not be SNATed: the backend replies to the
++dnl client's own address, and the reply has to be unDNATed back to the VIP.
++check ovs-appctl dpctl/flush-conntrack
++NS_CHECK_EXEC([foo1], [wget http://30.0.0.2:8000 -t 5 -T 1 --retry-connrefused -v -o wget-foo1.log])
++
++AT_CHECK([ovs-appctl dpctl/dump-conntrack | FORMAT_CT(192.168.1.2) | \
++          sed -e 's/zone=[[0-9]]*/zone=<cleared>/' -e 's/mark=[[0-9]]*/mark=<cleared>/'], [0], [dnl
++tcp,orig=(src=192.168.1.2,dst=30.0.0.2,sport=<cleared>,dport=<cleared>),reply=(src=172.16.1.2,dst=192.168.1.2,sport=<cleared>,dport=<cleared>),zone=<cleared>,mark=<cleared>,protoinfo=(state=<cleared>)
++])
++
++dnl No SNAT entry at all, in particular not the subnet SNAT one.
++AT_CHECK([ovs-appctl dpctl/dump-conntrack | grep -c "172.16.1.100"], [1], [0
++])
++
++OVN_CLEANUP_CONTROLLER([hv1])
++
++OVN_CLEANUP_NORTHD
++
++as
++OVS_TRAFFIC_VSWITCHD_STOP(["/failed to query port patch-.*/d
++/Failed to acquire.*/d
++/connection dropped.*/d"])
++AT_CLEANUP
++])
++
+ OVN_FOR_EACH_NORTHD([
+ AT_SETUP([load balancing in gateway router - IPv6])
+ AT_KEYWORDS([ovnlb])
+@@ -6265,7 +6515,7 @@ NS_CHECK_EXEC([vm2], [ncat 66.66.66.66 666 -p 2001 -z], [0], [ignore], [ignore])
  # Check conntrack.  We expect two entries:
  # - one in vm1's zone (firewall)
  # - one in vm2's zone (dnat)
@@ -2949,7 +7057,7 @@ index 38e15b7d9..872e9ce6b 100644
  grep "orig=.src=42\.42\.42\.3" |                                    \
  sed -e 's/sport=2001/sport=<clnt_s_port>/g'                         \
      -e 's/dport=2001/dport=<clnt_s_port>/g'                         \
-@@ -6284,7 +6284,7 @@ NS_CHECK_EXEC([vm2], [ncat 42.42.42.2 4242 -p 2001 -z], [0], [ignore], [ignore])
+@@ -6284,7 +6534,7 @@ NS_CHECK_EXEC([vm2], [ncat 42.42.42.2 4242 -p 2001 -z], [0], [ignore], [ignore])
  # - one in vm1's zone (firewall) - reused from the previous connection.
  # - one in vm2's zone (dnat) - still in TIME_WAIT after the previous connection.
  # - one in vm2's zone (firewall + additional all-zero SNAT)
@@ -2958,7 +7066,7 @@ index 38e15b7d9..872e9ce6b 100644
  grep "orig=.src=42\.42\.42\.3" |                                    \
  sed -e 's/port=2001/port=<clnt_s_port>/g'                           \
      -e 's/sport=4242,dport=[[0-9]]\+/sport=4242,dport=<rnd_port>/g' \
-@@ -6365,7 +6365,7 @@ NS_CHECK_EXEC([vm2], [ncat 6666::1 666 -p 2001 -z], [0], [ignore], [ignore])
+@@ -6365,7 +6615,7 @@ NS_CHECK_EXEC([vm2], [ncat 6666::1 666 -p 2001 -z], [0], [ignore], [ignore])
  # Check conntrack.  We expect two entries:
  # - one in vm1's zone (firewall)
  # - one in vm2's zone (dnat)
@@ -2967,7 +7075,7 @@ index 38e15b7d9..872e9ce6b 100644
  grep "orig=.src=4242::3" |                                         \
  sed -e 's/sport=2001/sport=<clnt_s_port>/g'                        \
      -e 's/dport=2001/dport=<clnt_s_port>/g'                        \
-@@ -6384,7 +6384,7 @@ NS_CHECK_EXEC([vm2], [ncat 4242::2 4242 -p 2001 -z], [0], [ignore], [ignore])
+@@ -6384,7 +6634,7 @@ NS_CHECK_EXEC([vm2], [ncat 4242::2 4242 -p 2001 -z], [0], [ignore], [ignore])
  # - one in vm1's zone (firewall) - reused from the previous connection.
  # - one in vm2's zone (dnat) - still in TIME_WAIT after the previous connection.
  # - one in vm2's zone (firewall + additional all-zero SNAT)
@@ -2976,8 +7084,358 @@ index 38e15b7d9..872e9ce6b 100644
  grep "orig=.src=4242::3" |                                          \
  sed -e 's/port=2001/port=<clnt_s_port>/g'                           \
      -e 's/sport=4242,dport=[[0-9]]\+/sport=4242,dport=<rnd_port>/g' \
+@@ -21840,8 +22090,10 @@ check ovn-nbctl --wait=hv set NB_Global . options:acl_ct_translation=true
+ check ovn-nbctl --wait=hv sync
+ check ovs-appctl dpctl/flush-conntrack
+ 
++# Keep listeners from sending FIN on stdin EOF, which can make Ncat clients
++# exit before sending all the data.
+ # Test client -> server direction.
+-NETNS_DAEMONIZE([server], [ncat -l 172.16.1.2 8080 > tcp_server.rcvd], [server.pid])
++NETNS_DAEMONIZE([server], [ncat --no-shutdown -l 172.16.1.2 8080 > tcp_server.rcvd], [server.pid])
+ NS_CHECK_EXEC([client], [ncat -w 1 172.16.1.2 8080 < datafile], [0], [ignore], [ignore])
+ 
+ OVS_WAIT_UNTIL([test -s tcp_server.rcvd])
+@@ -21851,7 +22103,7 @@ check cmp datafile tcp_server.rcvd
+ kill $(cat server.pid) 2>/dev/null || true
+ 
+ # Test server -> client direction.
+-NETNS_DAEMONIZE([client], [ncat -l 172.16.1.3 8081 > tcp_client.rcvd], [client.pid])
++NETNS_DAEMONIZE([client], [ncat --no-shutdown -l 172.16.1.3 8081 > tcp_client.rcvd], [client.pid])
+ NS_CHECK_EXEC([server], [ncat -w 1 172.16.1.3 8081 < datafile], [0], [ignore], [ignore])
+ 
+ OVS_WAIT_UNTIL([test -s tcp_client.rcvd])
+@@ -22219,8 +22471,8 @@ check ovn-nbctl --wait=hv sync
+ 
+ dnl Check mac address of probe requests and replies, they should use the
+ dnl global svc_monitor_mac.
+-NETNS_START_TCPDUMP([lsp], [-nne -i lsp -Q in 'udp port 42'], [lsp_in])
+-NETNS_START_TCPDUMP([lsp], [-nne -i lsp -Q out 'udp port 42 || icmp'], [lsp_out])
++NETNS_START_TCPDUMP([lsp], [-nneq -i lsp -Q in 'udp port 42'], [lsp_in])
++NETNS_START_TCPDUMP([lsp], [-nneq -i lsp -Q out 'udp port 42 || icmp'], [lsp_out])
+ 
+ dnl Start a backend server, the monitor should change status to "online".
+ NETNS_DAEMONIZE([lsp], [ncat -l -u 42], [nc.pid])
+@@ -22749,6 +23001,12 @@ OVS_WAIT_UNTIL([
+     test "$route_recompute_ct" -ne 0
+ ])
+ check ovn-sbctl chassis-add hv2 geneve 169.0.0.2
++OVS_WAIT_UNTIL([
++    tunnel_ofport=$(ovs-vsctl --bare --columns=ofport find Interface \
++                    options:local_ip=169.0.0.1 options:remote_ip=169.0.0.2)
++    test -n "$tunnel_ofport" && test "$tunnel_ofport" -ge 0
++])
++check ovn-nbctl --wait=hv sync
+ hv2=$(fetch_column Chassis _uuid name=hv2)
+ check ovn-sbctl set Port_Binding be0 chassis=$hv2
+ wait_row_count Service_Monitor 1 logical_port=be0 status=offline
+@@ -23605,6 +23863,12 @@ OVS_WAIT_UNTIL([
+ check ovs-vsctl set Interface ovs-be0 external_ids:iface-id="not-be0"
+ wait_column "" Port_Binding chassis logical_port=be0
+ check ovn-sbctl chassis-add hv2 geneve 169.0.0.2
++OVS_WAIT_UNTIL([
++    tunnel_ofport=$(ovs-vsctl --bare --columns=ofport find Interface \
++                    options:local_ip=169.0.0.1 options:remote_ip=169.0.0.2)
++    test -n "$tunnel_ofport" && test "$tunnel_ofport" -ge 0
++])
++check ovn-nbctl --wait=hv sync
+ hv2=$(fetch_column Chassis _uuid name=hv2)
+ check ovn-sbctl set Port_Binding be0 chassis=$hv2
+ 
+@@ -23632,6 +23896,12 @@ check ovn-nbctl --wait=hv set Logical_Router_Port lr-origin-share \
+ check ovs-vsctl set Interface ovs-be0 external_ids:iface-id="not-be0"
+ wait_column "" Port_Binding chassis logical_port=be0
+ check ovn-sbctl chassis-add hv2 geneve 169.0.0.2
++OVS_WAIT_UNTIL([
++    tunnel_ofport=$(ovs-vsctl --bare --columns=ofport find Interface \
++                    options:local_ip=169.0.0.1 options:remote_ip=169.0.0.2)
++    test -n "$tunnel_ofport" && test "$tunnel_ofport" -ge 0
++])
++check ovn-nbctl --wait=hv sync
+ hv2=$(fetch_column Chassis _uuid name=hv2)
+ check ovn-sbctl set Port_Binding be0 chassis=$hv2
+ 
+@@ -23745,3 +24015,106 @@ OVS_TRAFFIC_VSWITCHD_STOP(["/failed to query port patch-.*/d
+ 
+ AT_CLEANUP
+ ])
++
++OVN_FOR_EACH_NORTHD([
++AT_SETUP([CT extraction limited to LB VIPs])
++AT_KEYWORDS([ovnlb ct_extract])
++AT_SKIP_IF([test $HAVE_NCAT = no])
++AT_SKIP_IF([test $HAVE_TCPDUMP = no])
++
++dnl Test that the CT_EXTRACT pipeline stage currently matches doesn't
++dnl generate ct_tuple4 megaflow matches for non fragments.
++
++ovn_start
++
++OVS_TRAFFIC_VSWITCHD_START()
++ADD_BR([br-int])
++
++check ovs-vsctl                                                                         \
++        -- set Open_vSwitch . external-ids:system-id=hv1                                \
++        -- set Open_vSwitch . external-ids:ovn-remote=unix:$ovs_base/ovn-sb/ovn-sb.sock \
++        -- set Open_vSwitch . external-ids:ovn-encap-type=geneve                        \
++        -- set Open_vSwitch . external-ids:ovn-encap-ip=169.0.0.1                       \
++        -- set bridge br-int fail-mode=secure other-config:disable-in-band=true
++
++start_daemon ovn-controller
++
++check ovn-nbctl                                                \
++    -- lr-add lr0                                              \
++      -- lrp-add lr0 lrp aa:bb:cc:dd:ee:03 10.0.0.3/24         \
++      -- set logical_router lr0 options:chassis=hv1            \
++    -- ls-add ls0                                              \
++      -- lsp-add ls0 lsp0                                      \
++        -- lsp-set-addresses lsp0 "aa:bb:cc:dd:ee:01 10.0.0.1" \
++      -- lsp-add ls0 lsp1                                      \
++        -- lsp-set-addresses lsp1 "aa:bb:cc:dd:ee:02 10.0.0.2" \
++      -- lsp-add-router-port ls0 ls0-lr0 lrp                   \
++    -- lb-add lb0 10.0.1.100:5000 10.0.0.2:6000 udp            \
++      -- ls-lb-add ls0 lb0                                     \
++    -- lb-add lb1 10.0.1.101:5001 10.0.0.2:6001 udp            \
++      -- lr-lb-add lr0 lb1
++
++ADD_NAMESPACES(lsp0, lsp1)
++ADD_VETH(lsp0, lsp0, br-int, "10.0.0.1/24", "aa:bb:cc:dd:ee:01", "10.0.0.3")
++ADD_VETH(lsp1, lsp1, br-int, "10.0.0.2/24", "aa:bb:cc:dd:ee:02", "10.0.0.3")
++
++wait_for_ports_up lsp0 lsp1
++check ovn-nbctl --wait=hv sync
++
++dnl Verify basic connectivity before testing megaflows.
++NS_CHECK_EXEC([lsp0], [ping -q -c 3 -i 0.3 -w 2 10.0.0.2 | FORMAT_PING], \
++[0], [dnl
++3 packets transmitted, 3 received, 0% packet loss, time 0ms
++])
++
++check ovs-appctl revalidator/pause
++on_exit 'ovs-appctl revalidator/resume'
++
++dnl --- Unfragmented unidirectional UDP to non-VIP must not have ct_tuple4 ---
++dnl
++dnl Start a UDP listener on lsp1 to absorb traffic.  Start a continuous
++dnl unidirectional UDP sender on lsp0 to port 4791 (a non-VIP port).
++dnl The listener does not send replies, so every packet stays ct.new.
++dnl There should be no ct_tuple4 matches in the megaflows for this traffic.
++NETNS_DAEMONIZE([lsp1], [ncat -u -l 4791 > /dev/null], [udp-listener.pid])
++NETNS_DAEMONIZE([lsp0], [bash -c 'while true; do echo test; sleep 0.2; done | ncat -u 10.0.0.2 4791'], [udp-sender.pid])
++
++dnl Wait until the datapath has a cached flow for the UDP traffic we sent.
++OVS_WAIT_UNTIL([ovs-appctl dpctl/dump-flows | grep -q 'dst=4791'])
++
++ovs-appctl dpctl/dump-flows > dpflows
++AT_CAPTURE_FILE([dpflows])
++
++AT_CHECK([grep 'dst=4791' dpflows | grep -q 'ct_tuple4'], [1])
++
++dnl --- UDP to VIP is DNAT'd correctly ---
++dnl
++NETNS_DAEMONIZE([lsp1], [ncat -u -l 10.0.0.2 6000], [lsp1_udp1.pid])
++NETNS_START_TCPDUMP([lsp1], [-nn -c 1 -i lsp1 'udp and dst port 6000 and dst host 10.0.0.2'], [lb-dnat1])
++NETNS_DAEMONIZE([lsp1], [ncat -u -l 10.0.0.2 6001], [lsp1_udp2.pid])
++NETNS_START_TCPDUMP([lsp1], [-nn -c 1 -i lsp1 'udp and dst port 6001 and dst host 10.0.0.2'], [lb-dnat2])
++
++NS_CHECK_EXEC([lsp0], [echo test | ncat -u 10.0.1.100 5000], [ignore], [ignore], [ignore])
++
++OVS_WAIT_UNTIL([
++    total_pkts=$(cat lb-dnat1.tcpdump | wc -l)
++    test "${total_pkts}" -ge 1
++])
++
++NS_CHECK_EXEC([lsp0], [echo test | ncat -u 10.0.1.101 5001], [ignore], [ignore], [ignore])
++
++OVS_WAIT_UNTIL([
++    total_pkts=$(cat lb-dnat2.tcpdump | wc -l)
++    test "${total_pkts}" -ge 1
++])
++
++check ovs-appctl revalidator/resume
++
++OVN_CLEANUP_CONTROLLER([hv1])
++OVN_CLEANUP_NORTHD
++
++as
++OVS_TRAFFIC_VSWITCHD_STOP(["/failed to query port patch-.*/d
++/connection dropped.*/d"])
++AT_CLEANUP
++])
+diff --git a/tutorial/ovn-lb-benchmark.py b/tutorial/ovn-lb-benchmark.py
+index 658beb94ce..09cf1feacd 100755
+--- a/tutorial/ovn-lb-benchmark.py
++++ b/tutorial/ovn-lb-benchmark.py
+@@ -3,6 +3,7 @@ import argparse
+ import sys
+ 
+ import ovs.db.idl
++import ovs.jsonrpc
+ import ovs.poller
+ import ovs.stream
+ import ovs.vlog
+@@ -16,10 +17,15 @@ SCHEMA = '../ovn-nb.ovsschema'
+ 
+ 
+ def die(msg):
+-    vlog.warn(f'Fatal error encountered: {msg}')
++    sys.stderr.write(f'\nError: {msg}\n')
+     sys.exit(1)
+ 
+ 
++def ip_node(i):
++    """Convert node index to two IP octets, supporting up to 65535 nodes."""
++    return f'{i >> 8}.{i & 0xff}'
++
++
+ def create_topology(idl, n):
+     vlog.info('Creating topology')
+     txn = ovs.db.idl.Transaction(idl)
+@@ -50,18 +56,18 @@ def create_topology(idl, n):
+         vlog.info(f'Provisioning node {i}')
+         chassis = f'chassis-{i}'
+         gwr = txn.insert(idl.tables['Logical_Router'])
+-        gwr.name = f'lr-{i}'
++        gwr.name = f'gw-{i}'
+         gwr.addvalue('load_balancer_group', lbg.uuid)
+         gwr.setkey('options', 'chassis', chassis)
+ 
+         gwr2join = txn.insert(idl.tables['Logical_Router_Port'])
+-        gwr2join.name = f'lr2j-{i}'
++        gwr2join.name = f'gw2j-{i}'
+         gwr2join.mac = '00:00:00:00:00:01'
+         gwr2join.networks = ['10.0.0.1/8']
+         gwr.addvalue('ports', gwr2join.uuid)
+ 
+         join2gwr = txn.insert(idl.tables['Logical_Switch_Port'])
+-        join2gwr.name = f'j2lr-{i}'
++        join2gwr.name = f'j2gw-{i}'
+         join2gwr.type = 'router'
+         join2gwr.addresses = ['router']
+         join2gwr.setkey('options', 'router-port', gwr2join.name)
+@@ -121,7 +127,7 @@ def add_chassis_template_vars(idl, n, n_vips, n_backends):
+         txn = ovs.db.idl.Transaction(idl)
+         tv = txn.insert(idl.tables['Chassis_Template_Var'])
+         tv.chassis = f'chassis-{i}'
+-        tv.setkey('variables', 'vip', f'42.42.42.{i}')
++        tv.setkey('variables', 'vip', f'42.42.{ip_node(i)}')
+ 
+         for j in range(n_vips):
+             port = j + 1
+@@ -142,7 +148,7 @@ def find_by_name(idl, table, name):
+ 
+ def add_explicit_lbs(idl, n, n_vips, n_backends):
+     for i in range(n):
+-        lr = find_by_name(idl, 'Logical_Router', f'lr-{i}')
++        lr = find_by_name(idl, 'Logical_Router', f'gw-{i}')
+         ls = find_by_name(idl, 'Logical_Switch', f'ls-{i}')
+         for j in range(n_vips):
+             vlog.info(f'Adding LB {j} for node {i}')
+@@ -154,7 +160,8 @@ def add_explicit_lbs(idl, n, n_vips, n_backends):
+ 
+             lb = txn.insert(idl.tables['Load_Balancer'])
+             lb.name = f'lb-{j}-{i}'
+-            lb.setkey('vips', f'42.42.42.{i}:{port}', f'{",".join(backends)}')
++            lb.setkey('vips', f'42.42.{ip_node(i)}:{port}',
++                      f'{",".join(backends)}')
+             lb.protocol = 'tcp'
+             lr.addvalue('load_balancer', lb.uuid)
+             ls.addvalue('load_balancer', lb.uuid)
+@@ -167,21 +174,17 @@ def run(remote, n, n_vips, n_backends, templates):
+     schema_helper.register_all()
+     idl = ovs.db.idl.Idl(remote, schema_helper, leader_only=False)
+ 
+-    seqno = 0
+-
+     error, stream = ovs.stream.Stream.open_block(
+         ovs.stream.Stream.open(remote), 2000
+     )
+     if error:
+-        sys.stderr.write(f'failed to connect to \"{remote}\"')
+-        sys.exit(1)
++        die(f'failed to connect to "{remote}"')
+ 
+     if not stream:
+-        sys.stderr.write(f'failed to connect to \"{remote}\"')
+-        sys.exit(1)
++        die(f'failed to connect to "{remote}"')
+     rpc = ovs.jsonrpc.Connection(stream)
+ 
+-    while idl.change_seqno == seqno and not idl.run():
++    while idl.change_seqno == 0 and not idl.run():
+         rpc.run()
+ 
+         poller = ovs.poller.Poller()
+@@ -223,6 +226,22 @@ def main(argv):
+     )
+     parser.set_defaults(template=False)
+     args = parser.parse_args()
++
++    if args.nodes < 1:
++        die('node count must be at least 1')
++    if args.nodes > 65535:
++        die('maximum supported node count is 65535')
++
++    if args.vips < 0:
++        die('VIP count must not be negative')
++    if args.vips > 63999:
++        die('maximum supported VIPs is 63999')
++
++    if args.backends < 0:
++        die('backend count must not be negative')
++    if args.backends > 255:
++        die('maximum supported backends is 255')
++
+     run(args.remote, args.nodes, args.vips, args.backends, args.template)
+ 
+ 
+diff --git a/utilities/containers/fedora/Dockerfile b/utilities/containers/fedora/Dockerfile
+index af05dac620..bb3278d2eb 100755
+--- a/utilities/containers/fedora/Dockerfile
++++ b/utilities/containers/fedora/Dockerfile
+@@ -1,4 +1,4 @@
+-FROM quay.io/fedora/fedora:42
++FROM quay.io/fedora/fedora:44
+ 
+ ARG CONTAINERS_PATH
+ 
+diff --git a/utilities/containers/ubuntu/Dockerfile b/utilities/containers/ubuntu/Dockerfile
+index bf64974de4..c9926b4fc7 100755
+--- a/utilities/containers/ubuntu/Dockerfile
++++ b/utilities/containers/ubuntu/Dockerfile
+@@ -1,4 +1,4 @@
+-FROM registry.hub.docker.com/library/ubuntu:24.04
++FROM registry.hub.docker.com/library/ubuntu:26.04
+ 
+ ARG CONTAINERS_PATH
+ 
+@@ -10,11 +10,13 @@ RUN apt update -y \
+     apt install -y \
+         automake \
+         bc \
++        bsdextrautils \
+         clang \
+         curl \
+         ethtool \
+         gcc \
+         git \
++        gnu-coreutils \
+         init \
+         iproute2 \
+         iputils-arping \
+@@ -49,6 +51,10 @@ RUN apt update -y \
+     && \
+     apt clean
+ 
++# Replace tee with gnutee until uutils 0.13.0 lands in Ubuntu 26.04.
++RUN update-alternatives --install /usr/local/bin/tee \
++    tee "$(command -v gnutee)" 100
++
+ WORKDIR /workspace
+ 
+ COPY $CONTAINERS_PATH/openbfdd.patch /tmp/openbfdd.patch
 diff --git a/utilities/ovn-ctl b/utilities/ovn-ctl
-index 3b62ca9b7..559fffddb 100755
+index 3b62ca9b77..559fffddbb 100755
 --- a/utilities/ovn-ctl
 +++ b/utilities/ovn-ctl
 @@ -25,7 +25,12 @@ esac
@@ -3097,7 +7555,7 @@ index 3b62ca9b7..559fffddb 100755
  
  File location options:
 diff --git a/utilities/ovn-ctl.8.xml b/utilities/ovn-ctl.8.xml
-index c2f52f3b1..5d07871b1 100644
+index c2f52f3b11..5d07871b1c 100644
 --- a/utilities/ovn-ctl.8.xml
 +++ b/utilities/ovn-ctl.8.xml
 @@ -70,101 +70,306 @@
@@ -3613,7 +8071,7 @@ index c2f52f3b1..5d07871b1 100644
      <h1> Extra Options </h1>
      <p>
 diff --git a/utilities/ovn-lib.in b/utilities/ovn-lib.in
-index 5a0766816..8e8eedeab 100644
+index 5a07668165..8e8eedeab6 100644
 --- a/utilities/ovn-lib.in
 +++ b/utilities/ovn-lib.in
 @@ -192,7 +192,7 @@ stop_ovn_daemon () {
@@ -3626,7 +8084,7 @@ index 5a0766816..8e8eedeab 100644
                          # daemon segfault. And if a monitor is running, it
                          # would restart the daemon giving it a new pid.
 diff --git a/utilities/ovn-nbctl.8.xml b/utilities/ovn-nbctl.8.xml
-index ce09bdce5..ffc706dce 100644
+index ce09bdce5d..ffc706dcef 100644
 --- a/utilities/ovn-nbctl.8.xml
 +++ b/utilities/ovn-nbctl.8.xml
 @@ -916,7 +916,7 @@

diff --git a/ovn.spec b/ovn.spec
index 14a0442..b2f3aa6 100644
--- a/ovn.spec
+++ b/ovn.spec
@@ -46,7 +46,7 @@ Name: ovn
 Summary: Open Virtual Network support
 URL: http://www.openvswitch.org/
 Version: 26.09.0
-Release: 33%{?commit0:.%{date}git%{shortcommit0}}%{?dist}
+Release: 61%{?commit0:.%{date}git%{shortcommit0}}%{?dist}
 Obsoletes: openvswitch-ovn-common < %{?epoch_ovs:%{epoch_ovs}:}2.11.0-8
 Provides: openvswitch-ovn-common = %{?epoch:%{epoch}:}%{version}-%{release}
 
@@ -457,6 +457,10 @@ fi
 %{_unitdir}/ovn-br-db.service
 
 %changelog
+* Wed Nov 18 2026 Dumitru Ceara <dceara@redhat.com> - 26.09.0-61
+- Updated the OVN sources to pick up the commits from v26.09.0 till
+  the tip of branch-26.09 (67b71ad8d2d40ee905a706f4687fa576e325fdc1).
+
 * Thu Oct 8 2026 Dumitru Ceara <dceara@redhat.com> - 26.09.0-33
 - Updated the OVN sources to upstream release v26.09.0 with the
   commit da7afdb1bffa5ff752f2e8ae50ffd7aecd2907f3 and picked up

                 reply	other threads:[~2026-11-18 12:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179500598668.1.18101018831933534102.rpms-ovn-3f4a162cfb9c@fedoraproject.org \
    --to=dceara@redhat.com \
    --cc=git-commits@fedoraproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox