Ability to extract LB addresses from lr_stateful_record
was part of "get_nat_addresses" with "include_vips=true".
This change moves it into a separate function so it can be
used independently.

Signed-off-by: Martin Kalcok <[email protected]>
---
 northd/northd.c | 60 ++++++++++++++++++++++++++++++-------------------
 1 file changed, 37 insertions(+), 23 deletions(-)

diff --git a/northd/northd.c b/northd/northd.c
index ec047ccbe..630466812 100644
--- a/northd/northd.c
+++ b/northd/northd.c
@@ -2504,6 +2504,40 @@ join_logical_ports(const struct sbrec_port_binding_table 
*sbrec_pb_table,
     }
 }
 
+static bool
+get_lb_addresses(const struct lr_stateful_record *lr_stateful_rec,
+                 struct ds *addresses, bool routable_only)
+{
+    bool lbs_found = false;
+    if (!lr_stateful_rec) {
+        return lbs_found;
+    }
+
+    const char *ip_address;
+    if (routable_only) {
+        SSET_FOR_EACH (ip_address,
+                       &lr_stateful_rec->lb_ips->ips_v4_routable) {
+            ds_put_format(addresses, " %s", ip_address);
+            lbs_found = true;
+        }
+        SSET_FOR_EACH (ip_address,
+                       &lr_stateful_rec->lb_ips->ips_v6_routable) {
+            ds_put_format(addresses, " %s", ip_address);
+            lbs_found = true;
+        }
+    } else {
+        SSET_FOR_EACH (ip_address, &lr_stateful_rec->lb_ips->ips_v4) {
+            ds_put_format(addresses, " %s", ip_address);
+            lbs_found = true;
+        }
+        SSET_FOR_EACH (ip_address, &lr_stateful_rec->lb_ips->ips_v6) {
+            ds_put_format(addresses, " %s", ip_address);
+            lbs_found = true;
+        }
+    }
+
+    return lbs_found;
+}
 /* Returns an array of strings, each consisting of a MAC address followed
  * by one or more IP addresses, and if the port is a distributed gateway
  * port, followed by 'is_chassis_resident("LPORT_NAME")', where the
@@ -2614,29 +2648,9 @@ get_nat_addresses(const struct ovn_port *op, size_t *n, 
bool routable_only,
         }
     }
 
-    if (include_lb_ips && lr_stateful_rec) {
-        const char *ip_address;
-        if (routable_only) {
-            SSET_FOR_EACH (ip_address,
-                           &lr_stateful_rec->lb_ips->ips_v4_routable) {
-                ds_put_format(&c_addresses, " %s", ip_address);
-                central_ip_address = true;
-            }
-            SSET_FOR_EACH (ip_address,
-                           &lr_stateful_rec->lb_ips->ips_v6_routable) {
-                ds_put_format(&c_addresses, " %s", ip_address);
-                central_ip_address = true;
-            }
-        } else {
-            SSET_FOR_EACH (ip_address, &lr_stateful_rec->lb_ips->ips_v4) {
-                ds_put_format(&c_addresses, " %s", ip_address);
-                central_ip_address = true;
-            }
-            SSET_FOR_EACH (ip_address, &lr_stateful_rec->lb_ips->ips_v6) {
-                ds_put_format(&c_addresses, " %s", ip_address);
-                central_ip_address = true;
-            }
-        }
+    if (include_lb_ips) {
+        central_ip_address = get_lb_addresses(lr_stateful_rec, &c_addresses,
+                                              routable_only);
     }
 
     if (central_ip_address) {
-- 
2.43.0

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

Reply via email to