]> git.proxmox.com Git - mirror_frr.git/blobdiff - pimd/pim_rp.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / pimd / pim_rp.c
index aa31a67036430f363ccf3ce292a1b4d8c9bbc92b..d59124cebde8cfb4b03f60df512c315170b13031 100644 (file)
@@ -1,21 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * PIM for Quagga
  * Copyright (C) 2015 Cumulus Networks, Inc.
  * Donald Sharp
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; see the file COPYING; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 #include <zebra.h>
 
@@ -51,6 +38,7 @@
 #include "pim_bsm.h"
 #include "pim_util.h"
 #include "pim_ssm.h"
+#include "termtable.h"
 
 /* Cleanup pim->rpf_hash each node data */
 void pim_rp_list_hash_clean(void *data)
@@ -339,9 +327,7 @@ static int pim_rp_check_interface_addrs(struct rp_info *rp_info,
 {
        struct listnode *node;
        struct pim_secondary_addr *sec_addr;
-       struct prefix rpf_addr;
-
-       pim_addr_to_prefix(&rpf_addr, rp_info->rp.rpf_addr);
+       pim_addr sec_paddr;
 
        if (!pim_addr_cmp(pim_ifp->primary_address, rp_info->rp.rpf_addr))
                return 1;
@@ -351,9 +337,11 @@ static int pim_rp_check_interface_addrs(struct rp_info *rp_info,
        }
 
        for (ALL_LIST_ELEMENTS_RO(pim_ifp->sec_addr_list, node, sec_addr)) {
-               if (prefix_same(&sec_addr->addr, &rpf_addr)) {
+               sec_paddr = pim_addr_from_prefix(&sec_addr->addr);
+               /* If an RP-address is self, It should be enough to say
+                * I am RP the prefix-length should not matter here */
+               if (!pim_addr_cmp(sec_paddr, rp_info->rp.rpf_addr))
                        return 1;
-               }
        }
 
        return 0;
@@ -949,10 +937,12 @@ void pim_rp_setup(struct pim_instance *pim)
 
                pim_find_or_track_nexthop(pim, nht_p, NULL, rp_info, NULL);
                if (!pim_ecmp_nexthop_lookup(pim, &rp_info->rp.source_nexthop,
-                                            nht_p, &rp_info->group, 1))
+                                            nht_p, &rp_info->group, 1)) {
                        if (PIM_DEBUG_PIM_NHT_RP)
                                zlog_debug(
                                        "Unable to lookup nexthop for rp specified");
+                       pim_rp_nexthop_del(rp_info);
+               }
        }
 }
 
@@ -1166,14 +1156,25 @@ void pim_rp_show_information(struct pim_instance *pim, struct prefix *range,
        struct rp_info *rp_info;
        struct rp_info *prev_rp_info = NULL;
        struct listnode *node;
+       struct ttable *tt = NULL;
+       char *table = NULL;
        char source[7];
+       char grp[INET6_ADDRSTRLEN];
 
        json_object *json_rp_rows = NULL;
        json_object *json_row = NULL;
 
-       if (!json)
-               vty_out(vty,
-                       "RP address       group/prefix-list   OIF               I am RP    Source   Group-Type\n");
+       if (!json) {
+               /* Prepare table. */
+               tt = ttable_new(&ttable_styles[TTSTYLE_BLANK]);
+               ttable_add_row(
+                       tt,
+                       "RP address|group/prefix-list|OIF|I am RP|Source|Group-Type");
+               tt->style.cell.rpad = 2;
+               tt->style.corner = '+';
+               ttable_restyle(tt);
+       }
+
        for (ALL_LIST_ELEMENTS_RO(pim->rp_list, node, rp_info)) {
                if (pim_rpf_addr_is_inaddr_any(&rp_info->rp))
                        continue;
@@ -1243,32 +1244,31 @@ void pim_rp_show_information(struct pim_instance *pim, struct prefix *range,
 
                        json_object_array_add(json_rp_rows, json_row);
                } else {
-                       vty_out(vty, "%-15pPA  ", &rp_info->rp.rpf_addr);
-
-                       if (rp_info->plist)
-                               vty_out(vty, "%-18s  ", rp_info->plist);
-                       else
-                               vty_out(vty, "%-18pFX  ", &rp_info->group);
-
-                       if (rp_info->rp.source_nexthop.interface)
-                               vty_out(vty, "%-16s  ",
-                                       rp_info->rp.source_nexthop
-                                               .interface->name);
-                       else
-                               vty_out(vty, "%-16s  ", "(Unknown)");
-
-                       if (rp_info->i_am_rp)
-                               vty_out(vty, "yes");
-                       else
-                               vty_out(vty, "no");
-
-                       vty_out(vty, "%14s", source);
-                       vty_out(vty, "%6s\n", group_type);
+                       prefix2str(&rp_info->group, grp, sizeof(grp));
+                       ttable_add_row(tt, "%pPA|%s|%s|%s|%s|%s",
+                                         &rp_info->rp.rpf_addr,
+                                         rp_info->plist
+                                         ? rp_info->plist
+                                         : grp,
+                                         rp_info->rp.source_nexthop.interface
+                                         ? rp_info->rp.source_nexthop
+                                               .interface->name
+                                               : "Unknown",
+                                         rp_info->i_am_rp
+                                         ? "yes"
+                                         : "no",
+                                         source, group_type);
                }
                prev_rp_info = rp_info;
        }
 
-       if (json) {
+       /* Dump the generated table. */
+       if (!json) {
+               table = ttable_dump(tt, "\n");
+               vty_out(vty, "%s\n", table);
+               XFREE(MTYPE_TMP, table);
+               ttable_del(tt);
+       } else {
                if (prev_rp_info && json_rp_rows)
                        json_object_object_addf(json, json_rp_rows, "%pPA",
                                                &prev_rp_info->rp.rpf_addr);