]> git.proxmox.com Git - mirror_frr.git/blobdiff - pimd/pim_cmd_common.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / pimd / pim_cmd_common.c
index b39f688cdb9d828a063c1b9f30b7f6517d2bcc51..c7b501ee149e893e1d979729d562519bf77db3c9 100644 (file)
@@ -1,21 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * PIM for IPv6 FRR
  * Copyright (C) 2022  Vmware, Inc.
  *                    Mobashshera Rasool <mrasool@vmware.com>
- *
- * 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>
@@ -299,7 +286,7 @@ int pim_process_no_rp_kat_cmd(struct vty *vty)
                sizeof(rs_timer_xpath));
 
        /* RFC4601 */
-       v = yang_dnode_get_uint16(vty->candidate_config->dnode,
+       v = yang_dnode_get_uint16(vty->candidate_config->dnode, "%s",
                                  rs_timer_xpath);
        v = 3 * v + PIM_REGISTER_PROBE_TIME_DEFAULT;
        if (v > UINT16_MAX)
@@ -688,7 +675,7 @@ int pim_process_no_rp_plist_cmd(struct vty *vty, const char *rp_str,
                return NB_OK;
        }
 
-       plist = yang_dnode_get_string(plist_dnode, plist_xpath);
+       plist = yang_dnode_get_string(plist_dnode, "%s", plist_xpath);
        if (strcmp(prefix_list, plist)) {
                vty_out(vty, "%% Unable to find specified RP\n");
                return NB_OK;
@@ -1140,41 +1127,23 @@ void pim_show_state(struct pim_instance *pim, struct vty *vty,
                                json_ifp_in = json_object_new_object();
                                json_object_object_add(json_source, in_ifname,
                                                       json_ifp_in);
-                               json_object_int_add(json_source, "Installed",
-                                                   c_oil->installed);
                                json_object_int_add(json_source, "installed",
                                                    c_oil->installed);
                                json_object_boolean_add(json_source, "isRpt",
                                                        isRpt);
-                               json_object_int_add(json_source, "RefCount",
-                                                   c_oil->oil_ref_count);
                                json_object_int_add(json_source, "refCount",
                                                    c_oil->oil_ref_count);
-                               json_object_int_add(json_source, "OilListSize",
-                                                   c_oil->oil_size);
                                json_object_int_add(json_source, "oilListSize",
                                                    c_oil->oil_size);
-                               json_object_int_add(
-                                       json_source, "OilRescan",
-                                       c_oil->oil_inherited_rescan);
                                json_object_int_add(
                                        json_source, "oilRescan",
                                        c_oil->oil_inherited_rescan);
-                               json_object_int_add(json_source, "LastUsed",
-                                                   c_oil->cc.lastused);
                                json_object_int_add(json_source, "lastUsed",
                                                    c_oil->cc.lastused);
-                               json_object_int_add(json_source, "PacketCount",
-                                                   c_oil->cc.pktcnt);
                                json_object_int_add(json_source, "packetCount",
                                                    c_oil->cc.pktcnt);
-                               json_object_int_add(json_source, "ByteCount",
-                                                   c_oil->cc.bytecnt);
                                json_object_int_add(json_source, "byteCount",
                                                    c_oil->cc.bytecnt);
-                               json_object_int_add(json_source,
-                                                   "WrongInterface",
-                                                   c_oil->cc.wrong_if);
                                json_object_int_add(json_source,
                                                    "wrongInterface",
                                                    c_oil->cc.wrong_if);
@@ -1728,14 +1697,8 @@ static void pim_show_join_helper(struct pim_interface *pim_ifp,
                json_object_string_add(
                        json_row, "channelJoinName",
                        pim_ifchannel_ifjoin_name(ch->ifjoin_state, ch->flags));
-               if (PIM_IF_FLAG_TEST_S_G_RPT(ch->flags)) {
-#if CONFDATE > 20230131
-                       CPP_NOTICE(
-                               "Remove JSON object commands with keys starting with capital")
-#endif
-                       json_object_int_add(json_row, "SGRpt", 1);
+               if (PIM_IF_FLAG_TEST_S_G_RPT(ch->flags))
                        json_object_int_add(json_row, "sgRpt", 1);
-               }
                if (PIM_IF_FLAG_TEST_PROTO_PIM(ch->flags))
                        json_object_int_add(json_row, "protocolPim", 1);
                if (PIM_IF_FLAG_TEST_PROTO_IGMP(ch->flags))
@@ -2824,21 +2787,35 @@ static int pim_print_vty_pnc_cache_walkcb(struct hash_bucket *bucket, void *arg)
        struct nexthop *nh_node = NULL;
        ifindex_t first_ifindex;
        struct interface *ifp = NULL;
+       struct ttable *tt = NULL;
+       char *table = NULL;
+
+       /* Prepare table. */
+       tt = ttable_new(&ttable_styles[TTSTYLE_BLANK]);
+       ttable_add_row(tt, "Address|Interface|Nexthop");
+       tt->style.cell.rpad = 2;
+       tt->style.corner = '+';
+       ttable_restyle(tt);
 
        for (nh_node = pnc->nexthop; nh_node; nh_node = nh_node->next) {
                first_ifindex = nh_node->ifindex;
 
                ifp = if_lookup_by_index(first_ifindex, pim->vrf->vrf_id);
 
-               vty_out(vty, "%-15pPA ", &pnc->rpf.rpf_addr);
-               vty_out(vty, "%-16s ", ifp ? ifp->name : "NULL");
 #if PIM_IPV == 4
-               vty_out(vty, "%pI4 ", &nh_node->gate.ipv4);
+               ttable_add_row(tt, "%pPA|%s|%pI4", &pnc->rpf.rpf_addr,
+                              ifp ? ifp->name : "NULL", &nh_node->gate.ipv4);
 #else
-               vty_out(vty, "%pI6 ", &nh_node->gate.ipv6);
+               ttable_add_row(tt, "%pPA|%s|%pI6", &pnc->rpf.rpf_addr,
+                              ifp ? ifp->name : "NULL", &nh_node->gate.ipv6);
 #endif
-               vty_out(vty, "\n");
        }
+       /* Dump the generated table. */
+       table = ttable_dump(tt, "\n");
+       vty_out(vty, "%s\n", table);
+       XFREE(MTYPE_TMP, table);
+       ttable_del(tt);
+
        return CMD_SUCCESS;
 }
 
@@ -2966,8 +2943,6 @@ void pim_show_nexthop(struct pim_instance *pim, struct vty *vty, bool uj)
        } else {
                vty_out(vty, "Number of registered addresses: %lu\n",
                        pim->rpf_hash->count);
-               vty_out(vty, "Address         Interface        Nexthop\n");
-               vty_out(vty, "---------------------------------------------\n");
        }
 
        if (uj) {
@@ -3774,8 +3749,6 @@ void show_mroute(struct pim_instance *pim, struct vty *vty, pim_sgaddr *sg,
                                            c_oil->oil_ref_count);
                        json_object_int_add(json_source, "oilSize",
                                            c_oil->oil_size);
-                       json_object_int_add(json_source, "OilInheritedRescan",
-                                           c_oil->oil_inherited_rescan);
                        json_object_int_add(json_source, "oilInheritedRescan",
                                            c_oil->oil_inherited_rescan);
                        json_object_string_add(json_source, "iif", in_ifname);
@@ -5355,6 +5328,7 @@ static void pim_show_group_rp_mappings_info(struct pim_instance *pim,
        json_object *json = NULL;
        json_object *json_group = NULL;
        json_object *json_row = NULL;
+       struct ttable *tt = NULL;
 
        if (uj) {
                json = json_object_new_object();
@@ -5385,10 +5359,15 @@ static void pim_show_group_rp_mappings_info(struct pim_instance *pim,
                } else {
                        vty_out(vty, "Group Address %pFX\n", &bsgrp->group);
                        vty_out(vty, "--------------------------\n");
-                       vty_out(vty, "%-15s %-15s %-15s %-15s\n", "Rp Address",
-                               "priority", "Holdtime", "Hash");
-
-                       vty_out(vty, "(ACTIVE)\n");
+                       /* Prepare table. */
+                       tt = ttable_new(&ttable_styles[TTSTYLE_BLANK]);
+                       ttable_add_row(tt, "Rp Address|priority|Holdtime|Hash");
+                       tt->style.cell.rpad = 2;
+                       tt->style.corner = '+';
+                       ttable_restyle(tt);
+
+                       ttable_add_row(tt, "%s|%c|%c|%c", "(ACTIVE)", ' ', ' ',
+                                      ' ');
                }
 
                frr_each (bsm_rpinfos, bsgrp->bsrp_list, bsm_rp) {
@@ -5408,11 +5387,22 @@ static void pim_show_group_rp_mappings_info(struct pim_instance *pim,
                                                        &bsm_rp->rp_address);
 
                        } else {
-                               vty_out(vty, "%-15pPA %-15u %-15u %-15u\n",
+                               ttable_add_row(
+                                       tt, "%pPA|%u|%u|%u",
                                        &bsm_rp->rp_address, bsm_rp->rp_prio,
                                        bsm_rp->rp_holdtime, bsm_rp->hash);
                        }
                }
+               /* Dump the generated table. */
+               if (tt) {
+                       char *table = NULL;
+
+                       table = ttable_dump(tt, "\n");
+                       vty_out(vty, "%s\n", table);
+                       XFREE(MTYPE_TMP, table);
+                       ttable_del(tt);
+                       tt = NULL;
+               }
                if (!bsm_rpinfos_count(bsgrp->bsrp_list) && !uj)
                        vty_out(vty, "Active List is empty.\n");
 
@@ -5423,10 +5413,16 @@ static void pim_show_group_rp_mappings_info(struct pim_instance *pim,
                        vty_out(vty, "(PENDING)\n");
                        vty_out(vty, "Pending RP count :%d\n",
                                bsgrp->pend_rp_cnt);
-                       if (bsgrp->pend_rp_cnt)
-                               vty_out(vty, "%-15s %-15s %-15s %-15s\n",
-                                       "Rp Address", "priority", "Holdtime",
-                                       "Hash");
+                       if (bsgrp->pend_rp_cnt) {
+                               /* Prepare table. */
+                               tt = ttable_new(&ttable_styles[TTSTYLE_BLANK]);
+                               ttable_add_row(
+                                       tt,
+                                       "Rp Address|priority|Holdtime|Hash");
+                               tt->style.cell.rpad = 2;
+                               tt->style.corner = '+';
+                               ttable_restyle(tt);
+                       }
                }
 
                frr_each (bsm_rpinfos, bsgrp->partial_bsrp_list, bsm_rp) {
@@ -5445,11 +5441,21 @@ static void pim_show_group_rp_mappings_info(struct pim_instance *pim,
                                                        "%pPA",
                                                        &bsm_rp->rp_address);
                        } else {
-                               vty_out(vty, "%-15pPA %-15u %-15u %-15u\n",
+                               ttable_add_row(
+                                       tt, "%pPA|%u|%u|%u",
                                        &bsm_rp->rp_address, bsm_rp->rp_prio,
                                        bsm_rp->rp_holdtime, bsm_rp->hash);
                        }
                }
+               /* Dump the generated table. */
+               if (tt) {
+                       char *table = NULL;
+
+                       table = ttable_dump(tt, "\n");
+                       vty_out(vty, "%s\n", table);
+                       XFREE(MTYPE_TMP, table);
+                       ttable_del(tt);
+               }
                if (!bsm_rpinfos_count(bsgrp->partial_bsrp_list) && !uj)
                        vty_out(vty, "Partial List is empty\n");
 
@@ -5610,7 +5616,7 @@ static void pim_show_bsm_db(struct pim_instance *pim, struct vty *vty, bool uj)
 
                                bsm_rpinfo = (struct bsmmsg_rpinfo *)buf;
                                /* unaligned, again */
-                               memcpy(&rp_addr, &bsm_rpinfo->rpaddr,
+                               memcpy(&rp_addr, &bsm_rpinfo->rpaddr.addr,
                                       sizeof(rp_addr));
 
                                buf += sizeof(struct bsmmsg_rpinfo);