With "lb" redistribution northd advertises every VIP of every load
balancer on the router and its neighbours.  A load balancer that serves
a VIP on a private network and exposes it through a second VIP on the
provider network (the way ovn-octavia-provider adds a floating IP as an
extra VIP) then also announces the private address to the fabric.
Private networks overlap between tenants, so the private address must
not be advertised to the fabric.  The existing option
dynamic-routing-advertise covers the whole load balancer and cannot
keep one VIP while dropping the other.

Add the Load_Balancer option dynamic-routing-advertise-vips.  When set,
only the listed VIPs are advertised and forwarded.  An empty list keeps
every VIP private.  Addresses are compared in canonical form.  An entry
that does not parse is ignored with a warning.

Signed-off-by: Dmitrii Shcherbakov <[email protected]>
---
 NEWS                              |   3 +
 northd/en-advertised-route-sync.c |  80 ++++++++++++++++++++++
 ovn-nb.xml                        |  13 ++++
 tests/ovn-northd.at               | 109 ++++++++++++++++++++++++++++++
 4 files changed, 205 insertions(+)

diff --git a/NEWS b/NEWS
index ab33399be..62e4ca349 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,9 @@ Post v26.09.0
      balancer of the same router is no longer advertised as a NAT route.
      The load balancer routes carry the locality and health of the
      address.
+   - Added a new "options:dynamic-routing-advertise-vips" key on the NB
+     Load_Balancer table to limit route advertisement to a subset of the
+     load balancer VIPs.
    - Learn ARP sender hardware address (arp.sha) and IPv6 Neighbor
      Discovery link-layer addresses (nd.tll, nd.sll) into the FDB
      table in addition to eth.src.  This allows VRRP virtual MACs to
diff --git a/northd/en-advertised-route-sync.c 
b/northd/en-advertised-route-sync.c
index c43e73228..c150874db 100644
--- a/northd/en-advertised-route-sync.c
+++ b/northd/en-advertised-route-sync.c
@@ -25,6 +25,8 @@
 #include "openvswitch/hmap.h"
 #include "openvswitch/vlog.h"
 #include "ovn-util.h"
+#include "packets.h"
+#include "sset.h"
 #include "util.h"
 
 VLOG_DEFINE_THIS_MODULE(en_advertised_route_sync);
@@ -394,6 +396,75 @@ distributed_lb_route_exists(const struct sset 
*distributed_lb_routes,
     return exists;
 }
 
+/* Store the address of vip in ip and return true, or return false for a
+ * template VIP, which has no address.  The address was parsed when the
+ * load balancer key was read.  A template load balancer keeps literal
+ * VIPs as strings only, those are parsed here. */
+static bool
+lb_vip_address(const struct ovn_lb_vip *vip, struct in6_addr *ip)
+{
+    if (vip->template_vips) {
+        return false;
+    }
+    if (!ipv6_is_zero(&vip->vip)) {
+        *ip = vip->vip;
+        return true;
+    }
+    return ip46_parse(vip->vip_str, ip);
+}
+
+/* Fill vips with the canonical addresses listed in the load balancer's
+ * dynamic-routing-advertise-vips option.  Returns false when the option is
+ * absent, in which case every VIP is advertised. */
+static bool
+lb_advertised_vips_init(const struct nbrec_load_balancer *nbrec_lb,
+                        struct sset *vips)
+{
+    const char *list = smap_get(&nbrec_lb->options,
+                                "dynamic-routing-advertise-vips");
+    if (!list) {
+        return false;
+    }
+
+    struct sset tokens = SSET_INITIALIZER(&tokens);
+    sset_from_delimited_string(&tokens, list, ", ");
+
+    const char *token;
+    SSET_FOR_EACH (token, &tokens) {
+        struct in6_addr ip;
+        if (!ip46_parse(token, &ip)) {
+            static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 1);
+            VLOG_WARN_RL(&rl, "Ignoring invalid IP address '%s' in "
+                         "dynamic-routing-advertise-vips of load balancer "
+                         "%s", token, nbrec_lb->name);
+            continue;
+        }
+        char buf[INET6_ADDRSTRLEN];
+        ipv6_string_mapped(buf, &ip);
+        sset_add(vips, buf);
+    }
+    sset_destroy(&tokens);
+    return true;
+}
+
+/* The VIP address was parsed when the load balancer key was read, so the
+ * canonical string only needs formatting, no second parse. */
+static bool
+lb_vip_is_advertised(const struct ovn_lb_vip *vip, bool filtered,
+                     const struct sset *advertised_vips)
+{
+    if (!filtered) {
+        return true;
+    }
+    struct in6_addr ip;
+    if (!lb_vip_address(vip, &ip)) {
+        return false;
+    }
+    char buf[INET6_ADDRSTRLEN];
+    ipv6_string_mapped(buf, &ip);
+    return sset_contains(advertised_vips, buf);
+}
+
 /* This function adds a new route for each entry in lr_nat record
  * to "routes". Logical port of the route is set to "advertising_op" and
  * tracked port is set to NAT's distributed gw port. If NAT doesn't have
@@ -615,10 +686,17 @@ build_lb_routes_for_lb(const struct ovn_port 
*advertising_op,
     const struct ovn_northd_lb *lb = lb_dps->lb;
     const char *protocol = lb->nlb->protocol && lb->nlb->protocol[0]
                            ? lb->nlb->protocol : "tcp";
+    struct sset advertised_vips = SSET_INITIALIZER(&advertised_vips);
+    bool filtered = lb_advertised_vips_init(nbrec_lb, &advertised_vips);
+
     for (size_t v = 0; v < lb->n_vips; v++) {
         const struct ovn_lb_vip *vip = &lb->vips[v];
         const struct ovn_northd_lb_vip *vip_nb = &lb->vips_nb[v];
 
+        if (!lb_vip_is_advertised(vip, filtered, &advertised_vips)) {
+            continue;
+        }
+
         if (parsed_routes_out) {
             add_redistribute_parsed_route(
                 parsed_routes_out, advertising_od, advertising_op,
@@ -691,6 +769,8 @@ build_lb_routes_for_lb(const struct ovn_port 
*advertising_op,
             route_e->distributed_lb = true;
         }
     }
+
+    sset_destroy(&advertised_vips);
 }
 
 /* Process LBs attached directly to peer_lr_nbr and through its LB groups. */
diff --git a/ovn-nb.xml b/ovn-nb.xml
index 1e3f63f62..d866ff52a 100644
--- a/ovn-nb.xml
+++ b/ovn-nb.xml
@@ -2862,6 +2862,19 @@ or
         Service IP via the <ref table="Advertised_Route" db="OVN_Southbound"/>
         table.  Default: <code>true</code>.
       </column>
+
+      <column name="options" key="dynamic-routing-advertise-vips">
+        A comma separated list of VIP IP addresses of this load balancer.
+        When set, only the listed VIPs are advertised via the
+        <ref table="Advertised_Route" db="OVN_Southbound"/> table and
+        forwarded by the advertising routers.  The other VIPs of the load
+        balancer are not advertised, for example a VIP on a private network
+        that must stay private while the VIP on the provider network is
+        advertised.  An empty list advertises none of the VIPs, for a
+        load balancer that must stay private.  Only relevant if
+        <ref column="options" key="dynamic-routing-advertise"/> is
+        <code>true</code>.  By default all VIPs are advertised.
+      </column>
     </group>
   </table>
 
diff --git a/tests/ovn-northd.at b/tests/ovn-northd.at
index 8a498f349..564e21dde 100644
--- a/tests/ovn-northd.at
+++ b/tests/ovn-northd.at
@@ -20006,6 +20006,115 @@ OVN_CLEANUP_NORTHD
 AT_CLEANUP
 ])
 
+OVN_FOR_EACH_NORTHD_NO_HV([
+AT_SETUP([dynamic-routing - LB advertised VIPs filter])
+AT_KEYWORDS([dynamic-routing])
+ovn_start
+
+# lb0 has a VIP on the provider network and one on a private network.
+# dynamic-routing-advertise-vips limits advertisement and forwarding to the
+# listed VIPs.
+
+check ovn-nbctl lr-add lr0
+check ovn-nbctl set Logical_Router lr0 \
+    options:dynamic-routing=true       \
+    options:chassis=hv1
+check ovn-nbctl lrp-add lr0 lr0-up 00:00:00:00:00:01
+check ovn-nbctl lrp-set-options lr0-up dynamic-routing-redistribute=lb
+check ovn-nbctl ls-add up
+check ovn-nbctl lsp-add-router-port up up-lr0 lr0-up
+
+check ovn-nbctl lr-add lr1
+check ovn-nbctl lrp-add lr1 lr1-up 00:00:00:00:00:02 10.0.0.1/24
+check ovn-nbctl lsp-add-router-port up up-lr1 lr1-up
+check ovn-nbctl lrp-add lr1 lr1-be 00:00:00:00:00:03 192.168.1.1/24
+check ovn-nbctl ls-add be
+check ovn-nbctl lsp-add-router-port be be-lr1 lr1-be
+check ovn-nbctl lsp-add be be-vm1
+check ovn-nbctl lsp-set-addresses be-vm1 "00:00:00:00:01:01 192.168.1.10"
+check ovn-nbctl lsp-add be be-vm2
+check ovn-nbctl lsp-set-addresses be-vm2 "00:00:00:00:01:02 192.168.1.11"
+
+check ovn-nbctl \
+    -- lb-add lb0 172.16.1.10:80 192.168.1.10:80,192.168.1.11:80 \
+    -- lb-add lb0 192.168.1.100:80 192.168.1.10:80,192.168.1.11:80 \
+    -- set Load_Balancer lb0 options:distributed=true \
+        ip_port_mappings:192.168.1.10="be-vm1:192.168.1.1" \
+        ip_port_mappings:192.168.1.11="be-vm2:192.168.1.1" \
+    -- lr-lb-add lr1 lb0
+check ovn-nbctl --wait=sb sync
+
+# Both VIPs are advertised and forwarded by default.
+check_row_count Advertised_Route 4
+check_row_count Advertised_Route 2 ip_prefix="172.16.1.10"
+check_row_count Advertised_Route 2 ip_prefix="192.168.1.100"
+ovn-sbctl lflow-list lr0 > lr0_flows
+AT_CHECK([grep -c 'lr_in_ip_routing.*172.16.1.10/32' lr0_flows], [0], [1
+])
+AT_CHECK([grep -c 'lr_in_ip_routing.*192.168.1.100/32' lr0_flows], [0], [1
+])
+
+# Only the listed VIP is advertised and forwarded.
+check ovn-nbctl --wait=sb set Load_Balancer lb0 \
+    options:dynamic-routing-advertise-vips="172.16.1.10"
+check_row_count Advertised_Route 2
+check_row_count Advertised_Route 2 ip_prefix="172.16.1.10"
+ovn-sbctl lflow-list lr0 > lr0_flows
+AT_CHECK([grep -c 'lr_in_ip_routing.*172.16.1.10/32' lr0_flows], [0], [1
+])
+AT_CHECK([grep -c 'lr_in_ip_routing.*192.168.1.100/32' lr0_flows], [1], [0
+])
+
+# Addresses are compared in canonical form.
+check ovn-nbctl --wait=sb set Load_Balancer lb0 \
+    options:dynamic-routing-advertise-vips="::ffff:172.16.1.10, 192.168.1.100"
+check_row_count Advertised_Route 4
+
+# An invalid entry is ignored with a warning.
+check ovn-nbctl --wait=sb set Load_Balancer lb0 \
+    options:dynamic-routing-advertise-vips="bogus,192.168.1.100"
+check_row_count Advertised_Route 2
+check_row_count Advertised_Route 2 ip_prefix="192.168.1.100"
+AT_CHECK([grep -q "Ignoring invalid IP address 'bogus'" northd/ovn-northd.log])
+
+# An empty list keeps every VIP private.
+check ovn-nbctl --wait=sb set Load_Balancer lb0 \
+    options:dynamic-routing-advertise-vips='""'
+check_row_count Advertised_Route 0
+ovn-sbctl lflow-list lr0 > lr0_flows
+AT_CHECK([grep -c 'lr_in_ip_routing.*172.16.1.10/32' lr0_flows], [1], [0
+])
+
+# Removing the option advertises every VIP again.
+check ovn-nbctl --wait=sb remove Load_Balancer lb0 options \
+    dynamic-routing-advertise-vips
+check_row_count Advertised_Route 4
+
+
+# A NAT entry for the public VIP is replaced by the per-backend LB routes
+# only while the LB advertises that VIP.  With the VIP left out of the
+# list the NAT route is advertised as before.
+check ovn-nbctl lrp-set-gateway-chassis lr1-up hv1
+check ovn-nbctl lrp-set-options lr0-up dynamic-routing-redistribute=lb,nat
+check ovn-nbctl --wait=sb lr-nat-add lr1 dnat_and_snat \
+    172.16.1.10 192.168.1.100
+pb_lr1_up=$(fetch_column Port_Binding _uuid logical_port=lr1-up)
+check_row_count Advertised_Route 4
+check_row_count Advertised_Route 0 tracked_port=$pb_lr1_up
+check ovn-nbctl --wait=sb set Load_Balancer lb0 \
+    options:dynamic-routing-advertise-vips="172.16.1.10"
+check_row_count Advertised_Route 2
+check_row_count Advertised_Route 0 tracked_port=$pb_lr1_up
+check ovn-nbctl --wait=sb set Load_Balancer lb0 \
+    options:dynamic-routing-advertise-vips='""'
+check_row_count Advertised_Route 1
+check_row_count Advertised_Route 1 \
+    ip_prefix="172.16.1.10"         \
+    tracked_port=$pb_lr1_up
+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])
-- 
2.53.0


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

Reply via email to