]> git.puffer.fish Git - mirror/frr.git/commitdiff
pimd,yang: Reimplement RPF lookup vty in router pim
authorNathan Bahr <nbahr@atcorp.com>
Wed, 2 Oct 2024 19:03:48 +0000 (19:03 +0000)
committerNathan Bahr <nbahr@atcorp.com>
Fri, 13 Dec 2024 17:36:34 +0000 (17:36 +0000)
Add rpf-lookup-mode MODE vty command under router pim block.
Including NB piping and config write. Using the mode still pending.

Signed-off-by: Nathan Bahr <nbahr@atcorp.com>
pimd/pim_cmd.c
pimd/pim_instance.h
pimd/pim_nb.c
pimd/pim_nb.h
pimd/pim_nb_config.c
pimd/pim_rpf.h
pimd/pim_vty.c
yang/frr-pim.yang

index 3fabe1706c8019530973a7659c5ae13211b68a17..1d89ec100adeab6625877b4a4f153b4eb97f6665 100644 (file)
@@ -8851,6 +8851,24 @@ done:
        return ret;
 }
 
+DEFPY_YANG(pim_rpf_lookup_mode, pim_rpf_lookup_mode_cmd,
+           "[no] rpf-lookup-mode ![urib-only|mrib-only|mrib-then-urib|lower-distance|longer-prefix]$mode",
+           NO_STR
+           "RPF lookup behavior\n"
+           "Lookup in unicast RIB only\n"
+           "Lookup in multicast RIB only\n"
+           "Try multicast RIB first, fall back to unicast RIB\n"
+           "Lookup both, use entry with lower distance\n"
+           "Lookup both, use entry with longer prefix\n")
+{
+       if (no)
+               nb_cli_enqueue_change(vty, "./mcast-rpf-lookup", NB_OP_DESTROY, NULL);
+       else
+               nb_cli_enqueue_change(vty, "./mcast-rpf-lookup", NB_OP_MODIFY, mode);
+
+       return nb_cli_apply_changes(vty, NULL);
+}
+
 struct cmd_node pim_node = {
        .name = "pim",
        .node = PIM_NODE,
@@ -9017,6 +9035,8 @@ void pim_cmd_init(void)
        install_element(PIM_NODE, &pim_bsr_candidate_rp_group_cmd);
        install_element(PIM_NODE, &pim_bsr_candidate_bsr_cmd);
 
+       install_element(PIM_NODE, &pim_rpf_lookup_mode_cmd);
+
        install_element(INTERFACE_NODE, &interface_ip_igmp_cmd);
        install_element(INTERFACE_NODE, &interface_no_ip_igmp_cmd);
        install_element(INTERFACE_NODE, &interface_ip_igmp_join_cmd);
index 93acb5e9fd6b3378c806e5ba45e8a7eb3124530d..d491cd63c69d804b88b3a6b94aa72e6b0675b328 100644 (file)
@@ -116,6 +116,7 @@ struct pim_instance {
        char *register_plist;
 
        struct hash *rpf_hash;
+       enum pim_rpf_lookup_mode rpf_mode;
 
        void *ssm_info; /* per-vrf SSM configuration */
 
index b5d20419dd1d16e8450f48e8c9fe163b029ed2f5..7bb529d44c26bf3454715b6c581a3bb4a3628718 100644 (file)
@@ -256,6 +256,12 @@ const struct frr_yang_module_info frr_pim_info = {
                                .destroy = routing_control_plane_protocols_control_plane_protocol_pim_address_family_register_accept_list_destroy,
                        }
                },
+               {
+                       .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-pim:pim/address-family/mcast-rpf-lookup",
+                       .cbs = {
+                               .modify = routing_control_plane_protocols_control_plane_protocol_pim_address_family_mcast_rpf_lookup_modify,
+                       }
+               },
                {
                        .xpath = "/frr-interface:lib/interface/frr-pim:pim/address-family",
                        .cbs = {
index 7d30db04be0cc5a5b4c8e1abe750087f853bf20e..15ae74e71122c1c26355ca3689bd12f5f4ef82d0 100644 (file)
@@ -100,6 +100,8 @@ int routing_control_plane_protocols_control_plane_protocol_pim_address_family_re
        struct nb_cb_modify_args *args);
 int routing_control_plane_protocols_control_plane_protocol_pim_address_family_register_accept_list_destroy(
        struct nb_cb_destroy_args *args);
+int routing_control_plane_protocols_control_plane_protocol_pim_address_family_mcast_rpf_lookup_modify(
+       struct nb_cb_modify_args *args);
 int lib_interface_pim_address_family_dr_priority_modify(
        struct nb_cb_modify_args *args);
 int lib_interface_pim_address_family_create(struct nb_cb_create_args *args);
index fb7047aa49830972e7a250eefd887d65b582b3ff..905bc5a13782721f379332216a8bb1fc54646407 100644 (file)
@@ -1846,6 +1846,34 @@ int routing_control_plane_protocols_control_plane_protocol_pim_address_family_re
        return NB_OK;
 }
 
+/*
+ * XPath: /frr-routing:routing/control-plane-protocols/control-plane-protocol/frr-pim:pim/address-family/mcast-rpf-lookup
+ */
+int routing_control_plane_protocols_control_plane_protocol_pim_address_family_mcast_rpf_lookup_modify(
+       struct nb_cb_modify_args *args)
+{
+       struct vrf *vrf;
+       struct pim_instance *pim;
+       enum pim_rpf_lookup_mode old_mode;
+
+       switch (args->event) {
+       case NB_EV_VALIDATE:
+       case NB_EV_PREPARE:
+       case NB_EV_ABORT:
+               break;
+       case NB_EV_APPLY:
+               vrf = nb_running_get_entry(args->dnode, NULL, true);
+               pim = vrf->info;
+               old_mode = pim->rpf_mode;
+               pim->rpf_mode = yang_dnode_get_enum(args->dnode, NULL);
+
+               /* TODO: Signal to redo lookups? */
+               break;
+       }
+
+       return NB_OK;
+}
+
 /*
  * XPath: /frr-interface:lib/interface/frr-pim:pim/address-family
  */
@@ -2666,9 +2694,8 @@ int lib_interface_pim_address_family_mroute_oif_modify(
 
 #ifdef PIM_ENFORCE_LOOPFREE_MFC
                iif = nb_running_get_entry(args->dnode, NULL, false);
-               if (!iif) {
+               if (!iif)
                        return NB_OK;
-               }
 
                pim_iifp = iif->info;
                pim = pim_iifp->pim;
index 7dae53f8fc810b8773e5ceb553f2932ab79af472..6ff4d87b55c7ace003063a381a4f5fe1480f9539 100644 (file)
@@ -41,6 +41,17 @@ struct pim_rpf {
 
 enum pim_rpf_result { PIM_RPF_OK = 0, PIM_RPF_CHANGED, PIM_RPF_FAILURE };
 
+/* RPF lookup behaviour */
+enum pim_rpf_lookup_mode {
+       MCAST_NO_CONFIG = 0,  /* MIX_MRIB_FIRST, but no show in config write */
+       MCAST_MRIB_ONLY,      /* MRIB only */
+       MCAST_URIB_ONLY,      /* URIB only */
+       MCAST_MIX_MRIB_FIRST, /* MRIB, if nothing at all then URIB */
+       MCAST_MIX_DISTANCE,   /* MRIB & URIB, lower distance wins */
+       MCAST_MIX_PFXLEN,     /* MRIB & URIB, longer prefix wins */
+                             /* on equal value, MRIB wins for last 2 */
+};
+
 struct pim_upstream;
 
 unsigned int pim_rpf_hash_key(const void *arg);
index fc9781b239c5645217accc43b6809d81e5f0aa3a..974cf30cf1ed6024a9a0f9b9f3080ce983997d51 100644 (file)
@@ -275,6 +275,16 @@ int pim_global_config_write_worker(struct pim_instance *pim, struct vty *vty)
                }
        }
 
+       if (pim->rpf_mode != MCAST_NO_CONFIG) {
+               ++writes;
+               vty_out(vty, " rpf-lookup-mode %s\n",
+                       pim->rpf_mode == MCAST_URIB_ONLY        ? "urib-only"
+                       : pim->rpf_mode == MCAST_MRIB_ONLY      ? "mrib-only"
+                       : pim->rpf_mode == MCAST_MIX_MRIB_FIRST ? "mrib-then-urib"
+                       : pim->rpf_mode == MCAST_MIX_DISTANCE   ? "lower-distance"
+                                                               : "longer-prefix");
+       }
+
        return writes;
 }
 
index 6e5fc3c6ce5db0dbe8b35c5d4c6825c515c2ead7..e37189447406fd6cf891a6d8df4b4a11c8e1ac04 100644 (file)
@@ -82,6 +82,47 @@ module frr-pim {
     type string;
   }
 
+  /*
+   * Multicast RPF mode configurable type
+   */
+
+  typedef mcast-rpf-lookup-mode {
+    type enumeration {
+      enum "none" {
+        value 0;
+        description
+          "No mode set.";
+      }
+      enum "mrib-only" {
+        value 1;
+        description
+          "Lookup in unicast RIB only.";
+      }
+      enum "urib-only" {
+        value 2;
+        description
+          "Lookup in multicast RIB only.";
+      }
+      enum "mrib-then-urib" {
+        value 3;
+        description
+          "Try multicast RIB first, fall back to unicast RIB.";
+      }
+      enum "lower-distance" {
+        value 4;
+        description
+          "Lookup both unicast and mcast, use entry with lower distance.";
+      }
+      enum "longer-prefix" {
+        value 5;
+        description
+          "Lookup both unicast and mcast, use entry with longer prefix.";
+      }
+    }
+    description
+      "Multicast RPF lookup behavior";
+  }
+
   /*
    * Groupings
    */
@@ -161,20 +202,27 @@ module frr-pim {
     description
       "A grouping defining per address family pim global attributes";
 
+    leaf mcast-rpf-lookup {
+      type mcast-rpf-lookup-mode;
+      default "none";
+      description
+        "Multicast RPF lookup behavior.";
+    }
+
     leaf ecmp {
       type boolean;
       default "false";
       description
         "Enable PIM ECMP.";
     }
-    
+
     leaf ecmp-rebalance {
       type boolean;
       default "false";
       description
         "Enable PIM ECMP Rebalance.";
     }
-    
+
     leaf keep-alive-timer {
       type uint16 {
         range "1..max";
@@ -183,7 +231,7 @@ module frr-pim {
       description
         "Keep alive Timer in seconds.";
     }
-    
+
     leaf rp-keep-alive-timer {
       type uint16 {
         range "1..max";