This commit implements ARP/ND responder flows for IC-learned service monitors,
similar to existing local service monitors. Key changes include:

1. Extracted common ARP/ND response logic into helper function
   `build_arp_nd_service_monitor_lflow()` to avoid code duplication
2. Split service monitor flow generation into two separate functions:
   - `build_lswitch_arp_nd_local_svc_mon()` for local service monitors
   - `build_lswitch_arp_nd_ic_learned_svc_mon()` for IC-learned monitors
3. Added flow generation for IC-learned monitors in main flow build path
4. Maintained existing behavior for local service monitors
5. Updated parallel and non-parallel build paths consistently

Signed-off-by: Alexandra Rukomoinikova <[email protected]>
---
v1 --> v2: 1) corrected Mark's comments
           2) added IC handler
---
 northd/en-lflow.c        |  51 ++++++++++++
 northd/en-lflow.h        |   3 +-
 northd/inc-proc-northd.c |   3 +-
 northd/northd.c          | 166 ++++++++++++++++++++++++++-------------
 northd/northd.h          |  11 ++-
 5 files changed, 175 insertions(+), 59 deletions(-)

diff --git a/northd/en-lflow.c b/northd/en-lflow.c
index 08427b52f..f903f5e3a 100644
--- a/northd/en-lflow.c
+++ b/northd/en-lflow.c
@@ -321,6 +321,57 @@ lflow_group_ecmp_route_change_handler(struct engine_node 
*node,
     return EN_HANDLED_UPDATED;
 }
 
+enum engine_input_handler_result
+lflow_ic_learned_svc_mons_handler(struct engine_node *node,
+                                  void *data)
+{
+    struct ic_learned_svc_monitors_data *ic_learned_svc_monitors_data =
+        engine_get_input_data("ic_learned_svcs", node);
+
+    const struct engine_context *eng_ctx = engine_get_context();
+    struct lflow_data *lflow_data = data;
+    struct lflow_input lflow_input;
+    lflow_get_input_data(node, &lflow_input);
+
+    struct svc_monitors_map_data svc_mons_data =
+        svc_monitors_map_data_init(
+            NULL,
+            &ic_learned_svc_monitors_data->ic_learned_svc_monitors_map,
+            ic_learned_svc_monitors_data->lflow_ref);
+
+    if (!lflow_ref_resync_flows(
+            ic_learned_svc_monitors_data->lflow_ref,
+            lflow_data->lflow_table,
+            eng_ctx->ovnsb_idl_txn,
+            lflow_input.ls_datapaths,
+            lflow_input.lr_datapaths,
+            lflow_input.ovn_internal_version_changed,
+            lflow_input.sbrec_logical_flow_table,
+            lflow_input.sbrec_logical_dp_group_table)) {
+        return EN_UNHANDLED;
+    }
+
+    build_lswitch_arp_nd_ic_learned_svc_mon(
+        &svc_mons_data,
+        lflow_input.ls_ports,
+        lflow_input.svc_monitor_mac,
+        lflow_data->lflow_table);
+
+    if (!lflow_ref_sync_lflows(
+            ic_learned_svc_monitors_data->lflow_ref,
+            lflow_data->lflow_table,
+            eng_ctx->ovnsb_idl_txn,
+            lflow_input.ls_datapaths,
+            lflow_input.lr_datapaths,
+            lflow_input.ovn_internal_version_changed,
+            lflow_input.sbrec_logical_flow_table,
+            lflow_input.sbrec_logical_dp_group_table)) {
+        return EN_UNHANDLED;
+    }
+
+    return EN_HANDLED_UPDATED;
+}
+
 void *en_lflow_init(struct engine_node *node OVS_UNUSED,
                      struct engine_arg *arg OVS_UNUSED)
 {
diff --git a/northd/en-lflow.h b/northd/en-lflow.h
index 326be83f9..99bcfda15 100644
--- a/northd/en-lflow.h
+++ b/northd/en-lflow.h
@@ -28,5 +28,6 @@ enum engine_input_handler_result
 lflow_multicast_igmp_handler(struct engine_node *node, void *data);
 enum engine_input_handler_result
 lflow_group_ecmp_route_change_handler(struct engine_node *node, void *data);
-
+enum engine_input_handler_result
+lflow_ic_learned_svc_mons_handler(struct engine_node *node, void *data);
 #endif /* EN_LFLOW_H */
diff --git a/northd/inc-proc-northd.c b/northd/inc-proc-northd.c
index 77767bc76..bfb893a1a 100644
--- a/northd/inc-proc-northd.c
+++ b/northd/inc-proc-northd.c
@@ -393,7 +393,8 @@ void inc_proc_northd_init(struct ovsdb_idl_loop *nb,
     engine_add_input(&en_lflow, &en_multicast_igmp,
                      lflow_multicast_igmp_handler);
     engine_add_input(&en_lflow, &en_sb_acl_id, NULL);
-    engine_add_input(&en_lflow, &en_ic_learned_svc_monitors, NULL);
+    engine_add_input(&en_lflow, &en_ic_learned_svc_monitors,
+                     lflow_ic_learned_svc_mons_handler);
 
     engine_add_input(&en_sync_to_sb_addr_set, &en_northd, NULL);
     engine_add_input(&en_sync_to_sb_addr_set, &en_lr_stateful, NULL);
diff --git a/northd/northd.c b/northd/northd.c
index c36e4a677..290fd2970 100644
--- a/northd/northd.c
+++ b/northd/northd.c
@@ -717,7 +717,7 @@ init_mcast_info_for_datapath(struct ovn_datapath *od)
     }
 }
 
-static inline struct svc_monitors_map_data
+struct svc_monitors_map_data
 svc_monitors_map_data_init(const struct hmap *local_svc_monitors_map,
                            const struct hmap *ic_learned_svc_monitors_map,
                            struct lflow_ref *ic_learned_svc_monitors_lflow_ref)
@@ -9252,6 +9252,48 @@ build_lswitch_lflows_admission_control(struct 
ovn_datapath *od,
                   lflow_ref);
 }
 
+static void
+build_arp_nd_service_monitor_lflow(const char *svc_monitor_mac,
+                                   const char *svc_src_ip,
+                                   struct ds *action,
+                                   struct ds *match,
+                                   bool is_ipv4)
+{
+    if (is_ipv4) {
+        ds_put_format(match, "arp.tpa == %s && arp.op == 1",
+                      svc_src_ip);
+        ds_put_format(action,
+            "eth.dst = eth.src; "
+            "eth.src = %s; "
+            "arp.op = 2; /* ARP reply */ "
+            "arp.tha = arp.sha; "
+            "arp.sha = %s; "
+            "arp.tpa = arp.spa; "
+            "arp.spa = %s; "
+            "outport = inport; "
+            "flags.loopback = 1; "
+            "output;",
+            svc_monitor_mac, svc_monitor_mac,
+            svc_src_ip);
+    } else {
+        ds_put_format(match, "nd_ns && nd.target == %s",
+                      svc_src_ip);
+        ds_put_format(action,
+            "nd_na { "
+            "eth.dst = eth.src; "
+            "eth.src = %s; "
+            "ip6.src = %s; "
+            "nd.target = %s; "
+            "nd.tll = %s; "
+            "outport = inport; "
+            "flags.loopback = 1; "
+            "output; "
+            "};",
+            svc_monitor_mac, svc_src_ip,
+            svc_src_ip, svc_monitor_mac);
+    }
+}
+
 /* Ingress table 24: ARP/ND responder, skip requests coming from localnet
  * ports. (priority 100); see ovn-northd.8.xml for the rationale. */
 
@@ -9622,12 +9664,12 @@ build_lswitch_arp_nd_responder_default(struct 
ovn_datapath *od,
 /* Ingress table 24: ARP/ND responder for service monitor source ip.
  * (priority 110)*/
 static void
-build_lswitch_arp_nd_service_monitor(const struct ovn_lb_datapaths *lb_dps,
-                                     const struct hmap *ls_ports,
-                                     const char *svc_monitor_mac,
-                                     struct lflow_table *lflows,
-                                     struct ds *actions,
-                                     struct ds *match)
+build_lswitch_arp_nd_local_svc_mon(const struct ovn_lb_datapaths *lb_dps,
+                                   const struct hmap *ls_ports,
+                                   const char *svc_monitor_mac,
+                                   struct lflow_table *lflows,
+                                   struct ds *actions,
+                                   struct ds *match)
 {
     const struct ovn_northd_lb *lb = lb_dps->lb;
     for (size_t i = 0; i < lb->n_vips; i++) {
@@ -9653,41 +9695,11 @@ build_lswitch_arp_nd_service_monitor(const struct 
ovn_lb_datapaths *lb_dps,
 
             ds_clear(match);
             ds_clear(actions);
-            if (IN6_IS_ADDR_V4MAPPED(&lb_vip->vip)) {
-                ds_put_format(match, "arp.tpa == %s && arp.op == 1",
-                              backend_nb->svc_mon_src_ip);
-                ds_put_format(actions,
-                    "eth.dst = eth.src; "
-                    "eth.src = %s; "
-                    "arp.op = 2; /* ARP reply */ "
-                    "arp.tha = arp.sha; "
-                    "arp.sha = %s; "
-                    "arp.tpa = arp.spa; "
-                    "arp.spa = %s; "
-                    "outport = inport; "
-                    "flags.loopback = 1; "
-                    "output;",
-                    svc_monitor_mac, svc_monitor_mac,
-                    backend_nb->svc_mon_src_ip);
-            } else {
-                ds_put_format(match, "nd_ns && nd.target == %s",
-                              backend_nb->svc_mon_src_ip);
-                ds_put_format(actions,
-                        "nd_na { "
-                        "eth.dst = eth.src; "
-                        "eth.src = %s; "
-                        "ip6.src = %s; "
-                        "nd.target = %s; "
-                        "nd.tll = %s; "
-                        "outport = inport; "
-                        "flags.loopback = 1; "
-                        "output; "
-                        "};",
-                        svc_monitor_mac,
-                        backend_nb->svc_mon_src_ip,
-                        backend_nb->svc_mon_src_ip,
-                        svc_monitor_mac);
-            }
+
+            build_arp_nd_service_monitor_lflow(svc_monitor_mac,
+                backend_nb->svc_mon_src_ip, actions, match,
+                IN6_IS_ADDR_V4MAPPED(&lb_vip->vip) ? true : false);
+
             ovn_lflow_add_with_hint(lflows,
                                     op->od,
                                     S_SWITCH_IN_ARP_ND_RSP, 110,
@@ -9698,6 +9710,43 @@ build_lswitch_arp_nd_service_monitor(const struct 
ovn_lb_datapaths *lb_dps,
     }
 }
 
+void
+build_lswitch_arp_nd_ic_learned_svc_mon(
+    struct svc_monitors_map_data *svc_mons_data,
+    const struct hmap *ls_ports,
+    const char *svc_monitor_mac,
+    struct lflow_table *lflows)
+{
+    struct ds action = DS_EMPTY_INITIALIZER;
+    struct ds match = DS_EMPTY_INITIALIZER;
+
+    struct service_monitor_info *mon_info;
+    HMAP_FOR_EACH (mon_info, hmap_node,
+        svc_mons_data->ic_learned_svc_monitors_map) {
+        struct ovn_port *op = ovn_port_find(ls_ports,
+                                            mon_info->sbrec_mon->logical_port);
+
+        if (!op || !mon_info->sbrec_mon->src_ip) {
+            continue;
+        }
+
+        bool is_ipv4 = strchr(mon_info->sbrec_mon->ip, '.') ? true : false;
+
+        build_arp_nd_service_monitor_lflow(svc_monitor_mac,
+                                           mon_info->sbrec_mon->src_ip,
+                                           &action, &match, is_ipv4);
+
+        ovn_lflow_add(lflows, op->od, S_SWITCH_IN_ARP_ND_RSP,
+                      110, ds_cstr(&match), ds_cstr(&action),
+                      svc_mons_data->lflow_ref);
+
+        ds_clear(&match);
+        ds_clear(&action);
+    }
+
+    ds_destroy(&match);
+    ds_destroy(&action);
+}
 
 /* Logical switch ingress table 25 and 26: DHCP options and response
  * priority 100 flows. */
@@ -17677,12 +17726,12 @@ build_lflows_thread(void *arg)
                         lsi->local_svc_monitor_map,
                         lsi->ic_learned_svc_monitor_map,
                         NULL);
-                    build_lswitch_arp_nd_service_monitor(lb_dps,
-                                                         lsi->ls_ports,
-                                                         lsi->svc_monitor_mac,
-                                                         lsi->lflows,
-                                                         &lsi->match,
-                                                         &lsi->actions);
+                    build_lswitch_arp_nd_local_svc_mon(lb_dps,
+                                                       lsi->ls_ports,
+                                                       lsi->svc_monitor_mac,
+                                                       lsi->lflows,
+                                                       &lsi->match,
+                                                       &lsi->actions);
                     build_lrouter_defrag_flows_for_lb(lb_dps, lsi->lflows,
                                                       lsi->lr_datapaths,
                                                       &lsi->match);
@@ -17923,10 +17972,10 @@ build_lswitch_and_lrouter_flows(
         stopwatch_stop(LFLOWS_PORTS_STOPWATCH_NAME, time_msec());
         stopwatch_start(LFLOWS_LBS_STOPWATCH_NAME, time_msec());
         HMAP_FOR_EACH (lb_dps, hmap_node, lb_dps_map) {
-            build_lswitch_arp_nd_service_monitor(lb_dps, lsi.ls_ports,
-                                                 lsi.svc_monitor_mac,
-                                                 lsi.lflows, &lsi.actions,
-                                                 &lsi.match);
+            build_lswitch_arp_nd_local_svc_mon(lb_dps, lsi.ls_ports,
+                                               lsi.svc_monitor_mac,
+                                               lsi.lflows, &lsi.actions,
+                                               &lsi.match);
             build_lrouter_defrag_flows_for_lb(lb_dps, lsi.lflows,
                                               lsi.lr_datapaths, &lsi.match);
             build_lrouter_flows_for_lb(lb_dps, lsi.lflows, lsi.meter_groups,
@@ -18061,6 +18110,11 @@ void build_lflows(struct ovsdb_idl_txn *ovnsb_txn,
     build_igmp_lflows(input_data->igmp_groups,
                       &input_data->ls_datapaths->datapaths,
                       lflows, input_data->igmp_lflow_ref);
+    build_lswitch_arp_nd_ic_learned_svc_mon(
+        &svc_mons_data,
+        input_data->ls_ports,
+        input_data->svc_monitor_mac,
+        lflows);
 
     if (parallelization_state == STATE_INIT_HASH_SIZES) {
         parallelization_state = STATE_USE_PARALLELIZATION;
@@ -18301,10 +18355,10 @@ lflow_handle_northd_lb_changes(struct ovsdb_idl_txn 
*ovnsb_txn,
         struct ds match = DS_EMPTY_INITIALIZER;
         struct ds actions = DS_EMPTY_INITIALIZER;
 
-        build_lswitch_arp_nd_service_monitor(lb_dps, lflow_input->ls_ports,
-                                             lflow_input->svc_monitor_mac,
-                                             lflows, &actions,
-                                             &match);
+        build_lswitch_arp_nd_local_svc_mon(lb_dps, lflow_input->ls_ports,
+                                           lflow_input->svc_monitor_mac,
+                                           lflows, &actions,
+                                           &match);
         build_lrouter_defrag_flows_for_lb(lb_dps, lflows,
                                           lflow_input->lr_datapaths, &match);
         build_lrouter_flows_for_lb(lb_dps, lflows,
diff --git a/northd/northd.h b/northd/northd.h
index 75f03e69b..6f86c078e 100644
--- a/northd/northd.h
+++ b/northd/northd.h
@@ -229,6 +229,11 @@ struct ic_learned_svc_monitors_data {
     struct lflow_ref *lflow_ref;
 };
 
+struct svc_monitors_map_data
+svc_monitors_map_data_init(const struct hmap *local_svc_monitors_map,
+    const struct hmap *ic_learned_svc_monitors_map,
+    struct lflow_ref *ic_learned_svc_monitors_lflow_ref);
+
 struct lflow_ref;
 struct lr_nat_table;
 
@@ -1052,7 +1057,11 @@ void build_igmp_lflows(struct hmap *igmp_groups,
                        const struct hmap *ls_datapaths,
                        struct lflow_table *lflows,
                        struct lflow_ref *lflow_ref);
-
+void build_lswitch_arp_nd_ic_learned_svc_mon(
+    struct svc_monitors_map_data *svc_mons_data,
+    const struct hmap *ls_ports,
+    const char *svc_monitor_mac,
+    struct lflow_table *lflows);
 /* Structure representing logical router port routable addresses. This
  * includes DNAT and Load Balancer addresses. This structure will only
  * be filled in if the router port is a gateway router port. Otherwise,
-- 
2.48.1

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

Reply via email to