diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
index a4549f5ef..973fc922a 100644
--- a/northd/ovn-northd.c
+++ b/northd/ovn-northd.c
@@ -6644,7 +6644,18 @@ build_lswitch_flows_admission_control(struct ovn_datapath *od, struct hmap *lflo
 }
 
 static void
-build_lswitch_flows_arp_nd_responder(struct ovn_port *op, struct hmap *lflows)
+build_lswitch_flows_arp_nd_responder_od(
+        struct ovn_datapath *od, struct hmap *lflows)
+{
+    /* Ingress table 13: ARP/ND responder, by default goto next.
+     * (priority 0)*/
+    if (od->nbs) {
+        ovn_lflow_add(lflows, od, S_SWITCH_IN_ARP_ND_RSP, 0, "1", "next;");
+    }
+}
+
+static void
+build_lswitch_flows_arp_nd_responder_op(struct ovn_port *op, struct hmap *lflows)
 {
     struct ds match = DS_EMPTY_INITIALIZER;
 
@@ -6665,53 +6676,15 @@ build_lswitch_flows_arp_nd_responder(struct ovn_port *op, struct hmap *lflows)
 }
 
 static void
-build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
-                    struct hmap *port_groups, struct hmap *lflows,
-                    struct hmap *mcgroups, struct hmap *igmp_groups,
-                    struct shash *meter_groups,
-                    struct hmap *lbs)
+build_lswitch_flows_arp_nd_responder_known_ips_op(
+        struct ovn_port *op, struct hmap *lflows, struct hmap *ports)
 {
-    /* This flow table structure is documented in ovn-northd(8), so please
-     * update ovn-northd.8.xml if you change anything. */
-
     struct ds match = DS_EMPTY_INITIALIZER;
     struct ds actions = DS_EMPTY_INITIALIZER;
 
-    struct ovn_datapath *od;
-    struct ovn_port *op;
-
-    HMAP_FOR_EACH (od, key_node, datapaths) {
-        build_lswitch_flows_pre_acl_and_acl_od(
-                od, lflows, meter_groups, lbs, port_groups);
-    }
-
-    HMAP_FOR_EACH (od, key_node, datapaths) {
-        build_lswitch_flows_forwarding_groups(od, lflows);
-    }
-
-    HMAP_FOR_EACH (od, key_node, datapaths) {
-        build_lswitch_flows_admission_control(od, lflows);
-    }
-
-    HMAP_FOR_EACH (op, key_node, ports) {
-        build_lswitch_input_port_sec_op(op, lflows);
-    }
-
-    HMAP_FOR_EACH (od, key_node, datapaths) {
-        build_lswitch_input_port_sec_od(od, lflows);
-    }
-
-    HMAP_FOR_EACH (op, key_node, ports) {
-        build_lswitch_flows_arp_nd_responder(op, lflows);
-    }
-
     /* Ingress table 13: ARP/ND responder, reply for known IPs.
      * (priority 50). */
-    HMAP_FOR_EACH (op, key_node, ports) {
-        if (!op->nbsp) {
-            continue;
-        }
-
+    if (op->nbsp) {
         if (!strcmp(op->nbsp->type, "virtual")) {
             /* Handle
              *  - GARPs for virtual ip which belongs to a logical port
@@ -6727,7 +6700,7 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
                                                    "virtual-parents");
             if (!virtual_ip || !virtual_parents ||
                 !ip_parse(virtual_ip, &ip)) {
-                continue;
+                goto arp_nd_responder_known_ips_done;
             }
 
             char *tokstr = xstrdup(virtual_parents);
@@ -6770,11 +6743,11 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
              */
             if (!lsp_is_up(op->nbsp) && strcmp(op->nbsp->type, "router") &&
                 strcmp(op->nbsp->type, "localport")) {
-                continue;
+                goto arp_nd_responder_known_ips_done;
             }
 
             if (lsp_is_external(op->nbsp) || op->has_unknown) {
-                continue;
+                goto arp_nd_responder_known_ips_done;
             }
 
             for (size_t i = 0; i < op->n_lsp_addrs; i++) {
@@ -6866,15 +6839,59 @@ build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
             }
         }
     }
+arp_nd_responder_known_ips_done:
+    ds_destroy(&actions);
+    ds_destroy(&match);
+}
+
+static void
+build_lswitch_flows(struct hmap *datapaths, struct hmap *ports,
+                    struct hmap *port_groups, struct hmap *lflows,
+                    struct hmap *mcgroups, struct hmap *igmp_groups,
+                    struct shash *meter_groups,
+                    struct hmap *lbs)
+{
+    /* This flow table structure is documented in ovn-northd(8), so please
+     * update ovn-northd.8.xml if you change anything. */
+
+    struct ds match = DS_EMPTY_INITIALIZER;
+    struct ds actions = DS_EMPTY_INITIALIZER;
+
+    struct ovn_datapath *od;
+    struct ovn_port *op;
 
-    /* Ingress table 13: ARP/ND responder, by default goto next.
-     * (priority 0)*/
     HMAP_FOR_EACH (od, key_node, datapaths) {
-        if (!od->nbs) {
-            continue;
-        }
+        build_lswitch_flows_pre_acl_and_acl_od(
+                od, lflows, meter_groups, lbs, port_groups);
+    }
 
-        ovn_lflow_add(lflows, od, S_SWITCH_IN_ARP_ND_RSP, 0, "1", "next;");
+    HMAP_FOR_EACH (od, key_node, datapaths) {
+        build_lswitch_flows_forwarding_groups(od, lflows);
+    }
+
+    HMAP_FOR_EACH (od, key_node, datapaths) {
+        build_lswitch_flows_admission_control(od, lflows);
+    }
+
+    HMAP_FOR_EACH (op, key_node, ports) {
+        build_lswitch_input_port_sec_op(op, lflows);
+    }
+
+    HMAP_FOR_EACH (od, key_node, datapaths) {
+        build_lswitch_input_port_sec_od(od, lflows);
+    }
+
+    HMAP_FOR_EACH (op, key_node, ports) {
+        build_lswitch_flows_arp_nd_responder_op(op, lflows);
+    }
+
+    HMAP_FOR_EACH (op, key_node, ports) {
+        build_lswitch_flows_arp_nd_responder_known_ips_op(
+                op, lflows, ports);
+    }
+
+    HMAP_FOR_EACH (od, key_node, datapaths) {
+        build_lswitch_flows_arp_nd_responder_od(od, lflows);
     }
 
     /* Ingress table 13: ARP/ND responder for service monitor source ip.
