vrrp: fix support for VRs in different FIBs 15/34815/1
authorMatthew Smith <mgsmith@netgate.com>
Tue, 21 Dec 2021 15:00:05 +0000 (09:00 -0600)
committerMatthew Smith <mgsmith@netgate.com>
Mon, 3 Jan 2022 21:45:43 +0000 (15:45 -0600)
Type: fix
Fixes: 4b1b13315a3c

When adding or deleting a VR, multicast routes can be added or deleted.
When the first VR is added, a local (dpo-receive) route is added. The
route is deleted when the last VR is deleted.

Perform the check on whether to add or delete the route on a per-FIB
basis. Otherwise, if the route is only added after the first VR is added
without regards to the FIB being used and a second VR is added later on
an interface attached to a different FIB, the necessary route will not be
added to the FIB used by the second interface.

Change-Id: Ib30925ecf45c714cfe3ac6a223754bea918f10e3
Signed-off-by: Matthew Smith <mgsmith@netgate.com>
src/plugins/vrrp/vrrp.c

index b6817b8..dbc122c 100644 (file)
@@ -384,10 +384,9 @@ static int
 vrrp_intf_enable_disable_mcast (u8 enable, u32 sw_if_index, u8 is_ipv6)
 {
   vrrp_main_t *vrm = &vrrp_main;
-  vrrp_vr_t *vr;
   vrrp_intf_t *intf;
-  u32 fib_index;
-  u32 n_vrs = 0;
+  u32 fib_index, i;
+  u32 n_vrs_in_fib = 0;
   const mfib_prefix_t *vrrp_prefix;
   fib_protocol_t proto;
   vnet_link_t link_type;
@@ -422,20 +421,19 @@ vrrp_intf_enable_disable_mcast (u8 enable, u32 sw_if_index, u8 is_ipv6)
   via_itf.frp_proto = fib_proto_to_dpo (proto);
   fib_index = mfib_table_get_index_for_sw_if_index (proto, sw_if_index);
 
-  /* *INDENT-OFF* */
-  pool_foreach (vr, vrm->vrs)
-   {
-    if (vrrp_vr_is_ipv6 (vr) == is_ipv6)
-      n_vrs++;
-  }
-  /* *INDENT-ON* */
+  vec_foreach_index (i, vrm->vrrp_intfs)
+    {
+      if (mfib_table_get_index_for_sw_if_index (proto, i) != fib_index)
+       continue;
+
+      n_vrs_in_fib += vrrp_intf_num_vrs (i, is_ipv6);
+    }
 
   if (enable)
     {
-      /* If this is the first VR configured, add the local mcast routes */
-      if (n_vrs == 1)
-       mfib_table_entry_path_update (fib_index, vrrp_prefix, MFIB_SOURCE_API,
-                                     MFIB_ENTRY_FLAG_NONE, &for_us);
+      /* ensure that the local mcast route exists */
+      mfib_table_entry_path_update (fib_index, vrrp_prefix, MFIB_SOURCE_API,
+                                   MFIB_ENTRY_FLAG_NONE, &for_us);
 
       mfib_table_entry_path_update (fib_index, vrrp_prefix, MFIB_SOURCE_API,
                                    MFIB_ENTRY_FLAG_NONE, &via_itf);
@@ -445,7 +443,7 @@ vrrp_intf_enable_disable_mcast (u8 enable, u32 sw_if_index, u8 is_ipv6)
   else
     {
       /* Remove mcast local routes if this is the last VR being deleted */
-      if (n_vrs == 0)
+      if (n_vrs_in_fib == 0)
        mfib_table_entry_path_remove (fib_index, vrrp_prefix, MFIB_SOURCE_API,
                                      &for_us);