When a logical router routes a packet to a next hop that has no static
ARP/ND entry and no MAC_Binding, lr_in_arp_request punts it to
ovn-controller to generate an ARP/ND request.  If the next hop doesn't
exist anymore, e.g. the IP of a deleted VM, nobody answers and every
packet sent to it is punted again.  Each punt wakes up the
ovn-controller main loop, so a client retrying connections to a stale
IP can keep a core busy.  CoPP can limit the rate, but the meter is
shared with legitimate resolutions, which are then delayed or dropped.

Router policies or ACLs can drop this traffic before the punt, but they
require the CMS to keep the set of valid IPs of each subnet in sync and
to remove the policies when the subnet is deleted, otherwise a stale
"drop" blackholes the prefix.  northd already knows the valid
neighbors: on a switch whose ports' addresses are all known, every
valid next hop has a static ARP/ND entry.

Add a Logical_Router option, neigh_resolve_known_only.  When set, for
each router port connected to such a switch, northd adds a priority 105
flow in lr_in_arp_request that drops packets whose next hop is in one
of the port's networks but was resolved neither statically nor through
a MAC_Binding.  The option is ignored for ports connected to switches
where unknown neighbors are expected: transit switches, switches with
more than one router port, and switches with "unknown" addresses or
localnet, vtep or virtual ports.  IPv6 link-local networks are not
affected.

Assisted-by: Claude Opus 5.5, Claude Code
Signed-off-by: Lucas Vargas Dias <[email protected]>
---
 NEWS                |   4 ++
 northd/northd.c     | 114 ++++++++++++++++++++++++++++++++++++++++++++
 ovn-nb.xml          |  34 +++++++++++++
 tests/ovn-northd.at |  89 ++++++++++++++++++++++++++++++++++
 4 files changed, 241 insertions(+)

diff --git a/NEWS b/NEWS
index b2416f98b..11fd9d124 100644
--- a/NEWS
+++ b/NEWS
@@ -77,6 +77,10 @@ Post v26.09.0
      the replies from the backends of its load balancers.  The CMS must make
      sure that the replies re-enter the router on the chassis that load
      balanced the request.  See ovn-nb(5).
+   - Added a new Logical_Router "options:neigh_resolve_known_only" option
+     to drop, instead of punting to ovn-controller to generate ARP/ND
+     requests, packets whose next hop is in a connected subnet but is not
+     a known neighbor, e.g., the IP of a deleted VM.
 
 OVN v26.09.0 - xxx xx xxxx
 --------------------------
diff --git a/northd/northd.c b/northd/northd.c
index e4acb11ab..2356e0586 100644
--- a/northd/northd.c
+++ b/northd/northd.c
@@ -16268,6 +16268,55 @@ build_lrouter_routing_protocol_redirect(
                   lflow_ref);
 }
 
+/* Returns true if the logical router port 'op' should drop packets whose
+ * next hop belongs to one of its networks but could not be resolved,
+ * instead of sending an ARP/ND request for them.  This is the case when
+ * the router has options:neigh_resolve_known_only=true and the switch the
+ * port is connected to only has neighbors known to OVN, i.e., every valid
+ * next hop has a static ARP/ND entry built from the switch ports'
+ * addresses. */
+static bool
+lrp_neigh_resolve_known_only(const struct ovn_port *op)
+{
+    if (!op->nbrp || !op->od->nbr
+        || !smap_get_bool(&op->od->nbr->options,
+                          "neigh_resolve_known_only", false)) {
+        return false;
+    }
+
+    if (!op->peer || !op->peer->od || !op->peer->od->nbs) {
+        return false;
+    }
+
+    const struct ovn_datapath *ls = op->peer->od;
+
+    /* Addresses outside the switch ports are legitimate when the switch
+     * has "unknown" addresses, is connected to a physical network or a
+     * VTEP gateway, or is a transit switch whose neighbors are routers
+     * in other availability zones. */
+    if (ls->has_unknown || ls_has_localnet_port(ls) || ls->has_vtep_lports
+        || smap_get(&ls->nbs->other_config, "interconn-ts")) {
+        return false;
+    }
+
+    /* Other routers on the same switch might need dynamic resolution
+     * (e.g., with dynamic_neigh_routers). */
+    if (vector_len(&ls->router_ports) > 1) {
+        return false;
+    }
+
+    /* Virtual IPs are resolved dynamically, as the owner of the IP can
+     * change. */
+    const struct ovn_port *lsp;
+    HMAP_FOR_EACH (lsp, dp_node, &ls->ports) {
+        if (lsp->nbsp && !strcmp(lsp->nbsp->type, "virtual")) {
+            return false;
+        }
+    }
+
+    return true;
+}
+
 /* This function adds ARP resolve flows related to a LSP. */
 static void
 build_arp_resolve_flows_for_lsp(
@@ -16770,6 +16819,69 @@ build_lr_gateway_redirect_flows_for_nats(
     }
 }
 
+/* Local router ingress table ARP_REQUEST: drop packets whose next hop is in
+ * one of the networks of router port 'op' but was not resolved, neither
+ * statically nor through a MAC_Binding, if the port only resolves known
+ * neighbors (see lrp_neigh_resolve_known_only()).  This avoids punting
+ * every such packet to ovn-controller to generate an ARP/ND request that
+ * nobody will answer, e.g., for VMs that were deleted. */
+static void
+build_arp_request_flows_for_lrp(const struct ovn_port *op,
+                                struct lflow_table *lflows,
+                                struct ds *match,
+                                struct lflow_ref *lflow_ref)
+{
+    ovs_assert(op->nbrp);
+
+    if (!lrp_neigh_resolve_known_only(op)) {
+        return;
+    }
+
+    /* For distributed gateway ports, lr_in_gw_redirect may have already
+     * changed the outport to the chassis-redirect port. */
+    struct ds outport = DS_EMPTY_INITIALIZER;
+    if (op->cr_port) {
+        ds_put_format(&outport, "{%s, %s}", op->json_key,
+                      op->cr_port->json_key);
+    } else {
+        ds_put_cstr(&outport, op->json_key);
+    }
+
+    for (size_t i = 0; i < op->lrp_networks.n_ipv4_addrs; i++) {
+        const struct ipv4_netaddr *addr = &op->lrp_networks.ipv4_addrs[i];
+
+        ds_clear(match);
+        ds_put_format(match, "eth.dst == 00:00:00:00:00:00 && "
+                      REGBIT_NEXTHOP_IS_IPV4" == 1 && outport == %s && "
+                      REG_NEXT_HOP_IPV4" == %s/%u",
+                      ds_cstr(&outport), addr->network_s, addr->plen);
+        ovn_lflow_add(lflows, op->od, S_ROUTER_IN_ARP_REQUEST, 105,
+                      ds_cstr(match), debug_drop_action(), lflow_ref,
+                      WITH_HINT(&op->nbrp->header_));
+    }
+
+    for (size_t i = 0; i < op->lrp_networks.n_ipv6_addrs; i++) {
+        const struct ipv6_netaddr *addr = &op->lrp_networks.ipv6_addrs[i];
+
+        /* Link-local addresses of the switch ports are not known. */
+        struct in6_addr network = addr->network;
+        if (in6_is_lla(&network)) {
+            continue;
+        }
+
+        ds_clear(match);
+        ds_put_format(match, "eth.dst == 00:00:00:00:00:00 && "
+                      REGBIT_NEXTHOP_IS_IPV4" == 0 && outport == %s && "
+                      REG_NEXT_HOP_IPV6" == %s/%u",
+                      ds_cstr(&outport), addr->network_s, addr->plen);
+        ovn_lflow_add(lflows, op->od, S_ROUTER_IN_ARP_REQUEST, 105,
+                      ds_cstr(match), debug_drop_action(), lflow_ref,
+                      WITH_HINT(&op->nbrp->header_));
+    }
+
+    ds_destroy(&outport);
+}
+
 /* Local router ingress table ARP_REQUEST: ARP request.
  *
  * In the common case where the Ethernet destination has been resolved,
@@ -20521,6 +20633,8 @@ build_lswitch_and_lrouter_iterate_by_lrp(struct 
ovn_port *op,
                                        op->lflow_ref);
     build_arp_resolve_flows_for_lrp(op, lsi->lflows,
                                     &lsi->match, &lsi->actions, op->lflow_ref);
+    build_arp_request_flows_for_lrp(op, lsi->lflows, &lsi->match,
+                                    op->lflow_ref);
     build_egress_delivery_flows_for_lrouter_port(op, lsi->lflows, &lsi->match,
                                                  &lsi->actions,
                                                  op->lflow_ref);
diff --git a/ovn-nb.xml b/ovn-nb.xml
index 0d18010aa..ef2b990e6 100644
--- a/ovn-nb.xml
+++ b/ovn-nb.xml
@@ -3501,6 +3501,40 @@ or
           the automatic creation of these logical flows.
         </p>
       </column>
+      <column name="options" key="neigh_resolve_known_only"
+              type='{"type": "boolean"}'>
+        <p>
+          If set to <code>true</code>, for each router port connected to a
+          logical switch whose neighbors are all known to OVN, the router
+          drops packets whose next hop is in one of the port's
+          <ref column="networks" table="Logical_Router_Port"/> but could
+          not be resolved, neither by a static mapping built from the
+          switch ports' addresses nor by a dynamically learned MAC binding,
+          instead of sending an ARP/ND request for them.  This avoids
+          punting to <code>ovn-controller</code> every packet sent to an
+          address that is not in use anymore, e.g., the IP of a deleted
+          VM, which would only generate ARP/ND requests that nobody
+          answers.  It is <code>false</code> by default.
+        </p>
+
+        <p>
+          Since only the addresses configured in the
+          <ref column="addresses" table="Logical_Switch_Port"/> column of
+          the switch ports are known, other addresses used by the VMs or
+          containers (e.g., secondary IPs or IPv6 addresses assigned by
+          SLAAC that are not configured in the port) become unreachable
+          from the router.  IPv6 link-local addresses are not affected.
+        </p>
+
+        <p>
+          The option is ignored for router ports connected to a logical
+          switch that is an OVN-IC transit switch, that has more than one
+          router port, or that has ports with <code>unknown</code>
+          addresses, or of type <code>localnet</code>, <code>vtep</code>
+          or <code>virtual</code>, as neighbors not known to OVN are
+          expected there.
+        </p>
+      </column>
       <column name="options" key="always_learn_from_arp_request" 
type='{"type": "boolean"}'>
         <p>
           This option controls the behavior when handling IPv4 ARP requests or
diff --git a/tests/ovn-northd.at b/tests/ovn-northd.at
index f1e88b4bd..eaa143c2b 100644
--- a/tests/ovn-northd.at
+++ b/tests/ovn-northd.at
@@ -26191,3 +26191,92 @@ AT_CHECK([grep "lr_out_undnat" lr0flows | 
ovn_strip_lflows | sort], [0], [dnl
 OVN_CLEANUP_NORTHD
 AT_CLEANUP
 ])
+
+OVN_FOR_EACH_NORTHD_NO_HV([
+AT_SETUP([Logical router option neigh_resolve_known_only])
+ovn_start
+
+dnl lr0 is connected to a tenant switch "sw0" and to a transit switch "ts".
+check ovn-nbctl lr-add lr0
+check ovn-nbctl lrp-add lr0 lr0-sw0 00:00:00:00:30:01 \
+    192.168.30.1/24 2001:db8:30::1/64
+check ovn-nbctl ls-add sw0
+check ovn-nbctl lsp-add-router-port sw0 sw0-lr0 lr0-sw0
+check ovn-nbctl lsp-add sw0 vif1 \
+    -- lsp-set-addresses vif1 "00:00:00:00:30:02 192.168.30.2 2001:db8:30::2"
+
+check ovn-nbctl lrp-add lr0 lr0-ts 00:00:00:00:11:03 169.254.11.3/24
+check ovn-nbctl ls-add ts \
+    -- set logical_switch ts other_config:interconn-ts=ts
+check ovn-nbctl lsp-add-router-port ts ts-lr0 lr0-ts
+check ovn-nbctl lsp-add ts remote1 \
+    -- lsp-set-type remote1 remote \
+    -- lsp-set-addresses remote1 "00:00:00:00:11:02 169.254.11.2"
+check ovn-nbctl --wait=sb sync
+
+check_drop_flows() {
+    ovn-sbctl lflow-list lr0 > lr0flows
+    AT_CAPTURE_FILE([lr0flows])
+    grep lr_in_arp_request lr0flows | grep priority=105 | ovn_strip_lflows
+}
+
+dnl Without the option, unresolved next hops are always ARP'ed for.
+AT_CHECK([check_drop_flows], [0], [])
+
+check ovn-nbctl --wait=sb set logical_router lr0 \
+    options:neigh_resolve_known_only=true
+
+dnl Drop flows are added for the tenant switch networks only, not for the
+dnl transit switch nor for the IPv6 link-local network.
+AT_CHECK([check_drop_flows], [0], [dnl
+  table=??(lr_in_arp_request  ), priority=105  , match=(eth.dst == 
00:00:00:00:00:00 && reg9[[9]] == 0 && outport == "lr0-sw0" && xxreg0 == 
2001:db8:30::/64), action=(drop;)
+  table=??(lr_in_arp_request  ), priority=105  , match=(eth.dst == 
00:00:00:00:00:00 && reg9[[9]] == 1 && outport == "lr0-sw0" && reg0 == 
192.168.30.0/24), action=(drop;)
+])
+
+dnl Known neighbors still have static entries.
+AT_CHECK([grep lr_in_arp_resolve lr0flows | grep priority=100 | 
ovn_strip_lflows], [0], [dnl
+  table=??(lr_in_arp_resolve  ), priority=100  , match=(outport == "lr0-sw0" 
&& reg0 == 192.168.30.2), action=(eth.dst = 00:00:00:00:30:02; next;)
+  table=??(lr_in_arp_resolve  ), priority=100  , match=(outport == "lr0-sw0" 
&& xxreg0 == 2001:db8:30::2), action=(eth.dst = 00:00:00:00:30:02; next;)
+  table=??(lr_in_arp_resolve  ), priority=100  , match=(outport == "lr0-ts" && 
reg0 == 169.254.11.2), action=(eth.dst = 00:00:00:00:11:02; next;)
+])
+
+dnl Adding a port with unknown addresses disables the option for the switch.
+check ovn-nbctl --wait=sb lsp-add sw0 vif2 -- lsp-set-addresses vif2 unknown
+AT_CHECK([check_drop_flows], [0], [])
+check ovn-nbctl --wait=sb lsp-del vif2
+AT_CHECK([check_drop_flows | grep -c drop], [0], [2
+])
+
+dnl Same for a localnet port.
+check ovn-nbctl --wait=sb lsp-add-localnet-port sw0 ln0 phys
+AT_CHECK([check_drop_flows], [0], [])
+check ovn-nbctl --wait=sb lsp-del ln0
+AT_CHECK([check_drop_flows | grep -c drop], [0], [2
+])
+
+dnl Same for a virtual port.
+check ovn-nbctl --wait=sb lsp-add sw0 vip \
+    -- lsp-set-type vip virtual \
+    -- lsp-set-options vip virtual-ip=192.168.30.100 virtual-parents=vif1
+AT_CHECK([check_drop_flows], [0], [])
+check ovn-nbctl --wait=sb lsp-del vip
+AT_CHECK([check_drop_flows | grep -c drop], [0], [2
+])
+
+dnl Same if another router is connected to the switch.
+check ovn-nbctl lr-add lr1
+check ovn-nbctl lrp-add lr1 lr1-sw0 00:00:00:00:30:fe 192.168.30.254/24
+check ovn-nbctl --wait=sb lsp-add-router-port sw0 sw0-lr1 lr1-sw0
+AT_CHECK([check_drop_flows], [0], [])
+check ovn-nbctl --wait=sb lsp-del sw0-lr1
+AT_CHECK([check_drop_flows | grep -c drop], [0], [2
+])
+
+dnl Disabling the option removes the drop flows.
+check ovn-nbctl --wait=sb set logical_router lr0 \
+    options:neigh_resolve_known_only=false
+AT_CHECK([check_drop_flows], [0], [])
+
+OVN_CLEANUP_NORTHD
+AT_CLEANUP
+])
-- 
2.43.0


-- 




_'Esta mensagem é direcionada apenas para os endereços constantes no 
cabeçalho inicial. Se você não está listado nos endereços constantes no 
cabeçalho, pedimos-lhe que desconsidere completamente o conteúdo dessa 
mensagem e cuja cópia, encaminhamento e/ou execução das ações citadas estão 
imediatamente anuladas e proibidas'._


* **'Apesar do Magazine Luiza tomar 
todas as precauções razoáveis para assegurar que nenhum vírus esteja 
presente nesse e-mail, a empresa não poderá aceitar a responsabilidade por 
quaisquer perdas ou danos causados por esse e-mail ou por seus anexos'.*



_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to