]> git.proxmox.com Git - mirror_frr.git/blobdiff - pimd/pim_cmd.c
*: move CLI node names to cmd_node->name
[mirror_frr.git] / pimd / pim_cmd.c
index abc154896731b8375790144ae1eb99b0ab219821..f99888b3afadcae021fe50545b050ccd3e8308ba 100644 (file)
 #endif
 
 static struct cmd_node interface_node = {
-       INTERFACE_NODE, "%s(config-if)# ", 1 /* vtysh ? yes */
+       .name = "interface",
+       .node = INTERFACE_NODE,
+       .parent_node = CONFIG_NODE,
+       .prompt = "%s(config-if)# ",
+       .config_write = pim_interface_config_write,
 };
 
-static struct cmd_node debug_node = {DEBUG_NODE, "", 1};
+static struct cmd_node debug_node = {
+       .name = "debug",
+       .node = DEBUG_NODE,
+       .prompt = "",
+       .config_write = pim_debug_config_write,
+};
 
 static struct vrf *pim_cmd_lookup_vrf(struct vty *vty, struct cmd_token *argv[],
                                      const int argc, int *idx)
@@ -1520,6 +1529,10 @@ static void pim_show_interface_traffic(struct pim_instance *pim,
                                            pim_ifp->pim_ifstat_join_recv);
                        json_object_int_add(json_row, "joinTx",
                                            pim_ifp->pim_ifstat_join_send);
+                       json_object_int_add(json_row, "pruneTx",
+                                           pim_ifp->pim_ifstat_prune_send);
+                       json_object_int_add(json_row, "pruneRx",
+                                           pim_ifp->pim_ifstat_prune_recv);
                        json_object_int_add(json_row, "registerRx",
                                            pim_ifp->pim_ifstat_reg_recv);
                        json_object_int_add(json_row, "registerTx",
@@ -1706,7 +1719,10 @@ static void pim_show_join_helper(struct vty *vty, struct pim_interface *pim_ifp,
                        pim_ifchannel_ifjoin_name(ch->ifjoin_state, ch->flags));
                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))
+                       json_object_int_add(json_row, "protocolIgmp", 1);
                json_object_object_get_ex(json_iface, ch_grp_str, &json_grp);
                if (!json_grp) {
                        json_grp = json_object_new_object();
@@ -3016,7 +3032,7 @@ static void pim_show_bsm_db(struct pim_instance *pim, struct vty *vty, bool uj)
        }
 
        for (ALL_LIST_ELEMENTS_RO(pim->global_scope.bsm_list, bsmnode, bsm)) {
-               char grp_str[INET_ADDRSTRLEN];
+               char grp_str[PREFIX_STRLEN];
                char rp_str[INET_ADDRSTRLEN];
                char bsr_str[INET_ADDRSTRLEN];
                struct bsmmsg_grpinfo *group;
@@ -3185,7 +3201,7 @@ static void pim_show_group_rp_mappings_info(struct pim_instance *pim,
                if (!bsgrp)
                        continue;
 
-               char grp_str[INET_ADDRSTRLEN];
+               char grp_str[PREFIX_STRLEN];
 
                prefix2str(&bsgrp->group, grp_str, sizeof(grp_str));
 
@@ -3312,12 +3328,9 @@ static void pim_show_statistics(struct pim_instance *pim, struct vty *vty,
 
        if (uj) {
                json = json_object_new_object();
-               json_object_int_add(json, "Number of Received BSMs",
-                                   pim->bsm_rcvd);
-               json_object_int_add(json, "Number of Forwared BSMs",
-                                   pim->bsm_sent);
-               json_object_int_add(json, "Number of Dropped BSMs",
-                                   pim->bsm_dropped);
+               json_object_int_add(json, "bsmRx", pim->bsm_rcvd);
+               json_object_int_add(json, "bsmTx", pim->bsm_sent);
+               json_object_int_add(json, "bsmDropped", pim->bsm_dropped);
        } else {
                vty_out(vty, "BSM Statistics :\n");
                vty_out(vty, "----------------\n");
@@ -3359,15 +3372,13 @@ static void pim_show_statistics(struct pim_instance *pim, struct vty *vty,
                        json_row = json_object_new_object();
 
                        json_object_string_add(json_row, "If Name", ifp->name);
+                       json_object_int_add(json_row, "bsmDroppedConfig",
+                                           pim_ifp->pim_ifstat_bsm_cfg_miss);
                        json_object_int_add(
-                               json_row,
-                               "Number of BSMs dropped due to config miss",
-                               pim_ifp->pim_ifstat_bsm_cfg_miss);
-                       json_object_int_add(
-                               json_row, "Number of unicast BSMs dropped",
+                               json_row, "bsmDroppedUnicast",
                                pim_ifp->pim_ifstat_ucast_bsm_cfg_miss);
                        json_object_int_add(json_row,
-                                           "Number of BSMs dropped due to invalid scope zone",
+                                           "bsmDroppedInvalidScopeZone",
                                            pim_ifp->pim_ifstat_bsm_invalid_sz);
                        json_object_object_add(json, ifp->name, json_row);
                }
@@ -3732,8 +3743,6 @@ static void pim_show_bsr(struct pim_instance *pim,
        char bsr_str[PREFIX_STRLEN];
        json_object *json = NULL;
 
-       vty_out(vty, "PIMv2 Bootstrap information\n");
-
        if (pim->global_scope.current_bsr.s_addr == INADDR_ANY) {
                strlcpy(bsr_str, "0.0.0.0", sizeof(bsr_str));
                pim_time_uptime(uptime, sizeof(uptime),
@@ -3771,14 +3780,15 @@ static void pim_show_bsr(struct pim_instance *pim,
                json_object_string_add(json, "bsr", bsr_str);
                json_object_int_add(json, "priority",
                                    pim->global_scope.current_bsr_prio);
-               json_object_int_add(json, "fragment_tag",
+               json_object_int_add(json, "fragmentTag",
                                    pim->global_scope.bsm_frag_tag);
                json_object_string_add(json, "state", bsr_state);
                json_object_string_add(json, "upTime", uptime);
-               json_object_string_add(json, "last_bsm_seen", last_bsm_seen);
+               json_object_string_add(json, "lastBsmSeen", last_bsm_seen);
        }
 
        else {
+               vty_out(vty, "PIMv2 Bootstrap information\n");
                vty_out(vty, "Current preferred BSR address: %s\n", bsr_str);
                vty_out(vty,
                        "Priority        Fragment-Tag       State           UpTime\n");
@@ -5790,13 +5800,18 @@ static void show_mroute(struct pim_instance *pim, struct vty *vty,
        int oif_vif_index;
        struct interface *ifp_in;
        char proto[100];
+       char state_str[PIM_REG_STATE_STR_LEN];
        char mroute_uptime[10];
 
        if (uj) {
                json = json_object_new_object();
        } else {
+               vty_out(vty, "IP Multicast Routing Table\n");
+               vty_out(vty, "Flags: S- Sparse, C - Connected, P - Pruned\n");
                vty_out(vty,
-                       "Source          Group           Proto  Input            Output           TTL  Uptime\n");
+                       "       R - RP-bit set, F - Register flag, T - SPT-bit set\n");
+               vty_out(vty,
+                       "\nSource          Group           Flags   Proto  Input            Output           TTL  Uptime\n");
        }
 
        now = pim_time_monotonic_sec();
@@ -5819,6 +5834,23 @@ static void show_mroute(struct pim_instance *pim, struct vty *vty,
                               sizeof(grp_str));
                pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, src_str,
                               sizeof(src_str));
+
+               strlcpy(state_str, "S", sizeof(state_str));
+               /* When a non DR receives a igmp join, it creates a (*,G)
+                * channel_oil without any upstream creation */
+               if (c_oil->up) {
+                       if (PIM_UPSTREAM_FLAG_TEST_SRC_IGMP(c_oil->up->flags))
+                               strlcat(state_str, "C", sizeof(state_str));
+                       if (pim_upstream_is_sg_rpt(c_oil->up))
+                               strlcat(state_str, "R", sizeof(state_str));
+                       if (PIM_UPSTREAM_FLAG_TEST_FHR(c_oil->up->flags))
+                               strlcat(state_str, "F", sizeof(state_str));
+                       if (c_oil->up->sptbit == PIM_UPSTREAM_SPTBIT_TRUE)
+                               strlcat(state_str, "T", sizeof(state_str));
+               }
+               if (pim_channel_oil_empty(c_oil))
+                       strlcat(state_str, "P", sizeof(state_str));
+
                ifp_in = pim_if_find_by_vif_index(pim, c_oil->oil.mfcc_parent);
 
                if (ifp_in)
@@ -5842,7 +5874,8 @@ static void show_mroute(struct pim_instance *pim, struct vty *vty,
                        }
 
                        /* Find the source nested under the group, create it if
-                        * it doesn't exist */
+                        * it doesn't exist
+                        */
                        json_object_object_get_ex(json_group, src_str,
                                                  &json_source);
 
@@ -5965,14 +5998,16 @@ static void show_mroute(struct pim_instance *pim, struct vty *vty,
                                }
 
                                vty_out(vty,
-                                       "%-15s %-15s %-6s %-16s %-16s %-3d  %8s\n",
-                                       src_str, grp_str, proto, in_ifname,
-                                       out_ifname, ttl, mroute_uptime);
+                                       "%-15s %-15s %-15s %-6s %-16s %-16s %-3d  %8s\n",
+                                       src_str, grp_str, state_str, proto,
+                                       in_ifname, out_ifname, ttl,
+                                       mroute_uptime);
 
                                if (first) {
                                        src_str[0] = '\0';
                                        grp_str[0] = '\0';
                                        in_ifname[0] = '\0';
+                                       state_str[0] = '\0';
                                        mroute_uptime[0] = '\0';
                                        first = 0;
                                }
@@ -5980,9 +6015,10 @@ static void show_mroute(struct pim_instance *pim, struct vty *vty,
                }
 
                if (!uj && !found_oif) {
-                       vty_out(vty, "%-15s %-15s %-6s %-16s %-16s %-3d  %8s\n",
-                               src_str, grp_str, "none", in_ifname, "none", 0,
-                               "--:--:--");
+                       vty_out(vty,
+                               "%-15s %-15s %-15s %-6s %-16s %-16s %-3d  %8s\n",
+                               src_str, grp_str, state_str, "none", in_ifname,
+                               "none", 0, "--:--:--");
                }
        }
 
@@ -6600,18 +6636,18 @@ static int pim_cmd_spt_switchover(struct pim_instance *pim,
 
        switch (pim->spt.switchover) {
        case PIM_SPT_IMMEDIATE:
-               XFREE(MTYPE_PIM_SPT_PLIST_NAME, pim->spt.plist);
+               XFREE(MTYPE_PIM_PLIST_NAME, pim->spt.plist);
 
                pim_upstream_add_lhr_star_pimreg(pim);
                break;
        case PIM_SPT_INFINITY:
                pim_upstream_remove_lhr_star_pimreg(pim, plist);
 
-               XFREE(MTYPE_PIM_SPT_PLIST_NAME, pim->spt.plist);
+               XFREE(MTYPE_PIM_PLIST_NAME, pim->spt.plist);
 
                if (plist)
                        pim->spt.plist =
-                               XSTRDUP(MTYPE_PIM_SPT_PLIST_NAME, plist);
+                               XSTRDUP(MTYPE_PIM_PLIST_NAME, plist);
                break;
        }
 
@@ -6672,6 +6708,26 @@ DEFUN (no_ip_pim_spt_switchover_infinity_plist,
        return pim_cmd_spt_switchover(pim, PIM_SPT_IMMEDIATE, NULL);
 }
 
+DEFPY (pim_register_accept_list,
+       pim_register_accept_list_cmd,
+       "[no] ip pim register-accept-list WORD$word",
+       NO_STR
+       IP_STR
+       PIM_STR
+       "Only accept registers from a specific source prefix list\n"
+       "Prefix-List name\n")
+{
+       PIM_DECLVAR_CONTEXT(vrf, pim);
+
+       if (no)
+               XFREE(MTYPE_PIM_PLIST_NAME, pim->register_plist);
+       else {
+               XFREE(MTYPE_PIM_PLIST_NAME, pim->register_plist);
+               pim->register_plist = XSTRDUP(MTYPE_PIM_PLIST_NAME, word);
+       }
+       return CMD_SUCCESS;
+}
+
 DEFUN (ip_pim_joinprune_time,
        ip_pim_joinprune_time_cmd,
        "ip pim join-prune-interval (60-600)",
@@ -7237,11 +7293,20 @@ DEFUN (no_ip_pim_ecmp_rebalance,
 static int pim_cmd_igmp_start(struct vty *vty, struct interface *ifp)
 {
        struct pim_interface *pim_ifp;
+       struct pim_instance *pim;
        uint8_t need_startup = 0;
 
        pim_ifp = ifp->info;
 
        if (!pim_ifp) {
+               pim = pim_get_pim_instance(ifp->vrf_id);
+               /* Limit mcast interfaces to number of vifs available */
+               if (pim->mcast_if_count == MAXVIFS) {
+                       vty_out(vty,
+                               "Max multicast interfaces(%d) Reached. Could not enable IGMP on interface %s\n",
+                               MAXVIFS, ifp->name);
+                       return CMD_WARNING_CONFIG_FAILED;
+               }
                (void)pim_if_new(ifp, true, false, false, false);
                need_startup = 1;
        } else {
@@ -7991,13 +8056,21 @@ DEFPY_HIDDEN (interface_ip_igmp_query_generate,
        return CMD_SUCCESS;
 }
 
-static int pim_cmd_interface_add(struct interface *ifp)
+static int pim_cmd_interface_add(struct vty *vty, struct interface *ifp)
 {
        struct pim_interface *pim_ifp = ifp->info;
+       struct pim_instance *pim;
 
-       if (!pim_ifp)
+       if (!pim_ifp) {
+               pim = pim_get_pim_instance(ifp->vrf_id);
+               /* Limiting mcast interfaces to number of VIFs */
+               if (pim->mcast_if_count == MAXVIFS) {
+                       vty_out(vty, "Max multicast interfaces(%d) reached.",
+                               MAXVIFS);
+                       return 0;
+               }
                pim_ifp = pim_if_new(ifp, false, true, false, false);
-       else
+       else
                PIM_IF_DO_PIM(pim_ifp->options);
 
        pim_if_addr_add_all(ifp);
@@ -8068,15 +8141,17 @@ DEFPY (interface_ip_pim_activeactive,
        VTY_DECLVAR_CONTEXT(interface, ifp);
        struct pim_interface *pim_ifp;
 
-       if (!no && !pim_cmd_interface_add(ifp)) {
-               vty_out(vty, "Could not enable PIM SM active-active on interface\n");
+       if (!no && !pim_cmd_interface_add(vty, ifp)) {
+               vty_out(vty,
+                       "Could not enable PIM SM active-active on interface %s\n",
+                       ifp->name);
                return CMD_WARNING_CONFIG_FAILED;
        }
 
 
-        if (PIM_DEBUG_MLAG)
-                zlog_debug("%sConfiguring PIM active-active on Interface: %s",
-                           no ? "Un-":" ", ifp->name);
+       if (PIM_DEBUG_MLAG)
+               zlog_debug("%sConfiguring PIM active-active on Interface: %s",
+                          no ? "Un-" : " ", ifp->name);
 
        pim_ifp = ifp->info;
        if (no)
@@ -8096,8 +8171,9 @@ DEFUN_HIDDEN (interface_ip_pim_ssm,
 {
        VTY_DECLVAR_CONTEXT(interface, ifp);
 
-       if (!pim_cmd_interface_add(ifp)) {
-               vty_out(vty, "Could not enable PIM SM on interface\n");
+       if (!pim_cmd_interface_add(vty, ifp)) {
+               vty_out(vty, "Could not enable PIM SM on interface %s\n",
+                       ifp->name);
                return CMD_WARNING_CONFIG_FAILED;
        }
 
@@ -8113,8 +8189,9 @@ static int interface_ip_pim_helper(struct vty *vty)
 
        VTY_DECLVAR_CONTEXT(interface, ifp);
 
-       if (!pim_cmd_interface_add(ifp)) {
-               vty_out(vty, "Could not enable PIM SM on interface\n");
+       if (!pim_cmd_interface_add(vty, ifp)) {
+               vty_out(vty, "Could not enable PIM SM on interface %s\n",
+                       ifp->name);
                return CMD_WARNING_CONFIG_FAILED;
        }
 
@@ -8402,8 +8479,10 @@ DEFUN (interface_ip_pim_hello,
        struct pim_interface *pim_ifp = ifp->info;
 
        if (!pim_ifp) {
-               if (!pim_cmd_interface_add(ifp)) {
-                       vty_out(vty, "Could not enable PIM SM on interface\n");
+               if (!pim_cmd_interface_add(vty, ifp)) {
+                       vty_out(vty,
+                               "Could not enable PIM SM on interface %s\n",
+                               ifp->name);
                        return CMD_WARNING_CONFIG_FAILED;
                }
        }
@@ -9145,8 +9224,10 @@ DEFUN (ip_pim_bfd,
        struct bfd_info *bfd_info = NULL;
 
        if (!pim_ifp) {
-               if (!pim_cmd_interface_add(ifp)) {
-                       vty_out(vty, "Could not enable PIM SM on interface\n");
+               if (!pim_cmd_interface_add(vty, ifp)) {
+                       vty_out(vty,
+                               "Could not enable PIM SM on interface %s\n",
+                               ifp->name);
                        return CMD_WARNING;
                }
        }
@@ -9196,8 +9277,10 @@ DEFUN (ip_pim_bsm,
        struct pim_interface *pim_ifp = ifp->info;
 
        if (!pim_ifp) {
-               if (!pim_cmd_interface_add(ifp)) {
-                       vty_out(vty, "Could not enable PIM SM on interface\n");
+               if (!pim_cmd_interface_add(vty, ifp)) {
+                       vty_out(vty,
+                               "Could not enable PIM SM on interface %s\n",
+                               ifp->name);
                        return CMD_WARNING;
                }
        }
@@ -9240,8 +9323,10 @@ DEFUN (ip_pim_ucast_bsm,
        struct pim_interface *pim_ifp = ifp->info;
 
        if (!pim_ifp) {
-               if (!pim_cmd_interface_add(ifp)) {
-                       vty_out(vty, "Could not enable PIM SM on interface\n");
+               if (!pim_cmd_interface_add(vty, ifp)) {
+                       vty_out(vty,
+                               "Could not enable PIM SM on interface %s\n",
+                               ifp->name);
                        return CMD_WARNING;
                }
        }
@@ -9308,8 +9393,10 @@ DEFUN(
        struct pim_interface *pim_ifp = ifp->info;
 
        if (!pim_ifp) {
-               if (!pim_cmd_interface_add(ifp)) {
-                       vty_out(vty, "Could not enable PIM SM on interface\n");
+               if (!pim_cmd_interface_add(vty, ifp)) {
+                       vty_out(vty,
+                               "Could not enable PIM SM on interface %s\n",
+                               ifp->name);
                        return CMD_WARNING;
                }
        }
@@ -9634,11 +9721,25 @@ DEFUN (no_ip_msdp_mesh_group_source,
        "mesh group local address\n")
 {
        PIM_DECLVAR_CONTEXT(vrf, pim);
-       if (argc == 7)
-               return ip_no_msdp_mesh_group_cmd_worker(pim, vty, argv[6]->arg);
+
+       return ip_no_msdp_mesh_group_source_cmd_worker(pim, vty, argv[4]->arg);
+}
+
+DEFUN (no_ip_msdp_mesh_group,
+       no_ip_msdp_mesh_group_cmd,
+       "no ip msdp mesh-group [WORD]",
+       NO_STR
+       IP_STR
+       CFG_MSDP_STR
+       "Delete MSDP mesh-group\n"
+       "mesh group name")
+{
+       PIM_DECLVAR_CONTEXT(vrf, pim);
+
+       if (argc == 5)
+               return ip_no_msdp_mesh_group_cmd_worker(pim, vty, argv[4]->arg);
        else
-               return ip_no_msdp_mesh_group_source_cmd_worker(pim, vty,
-                                                              argv[4]->arg);
+               return ip_no_msdp_mesh_group_cmd_worker(pim, vty, NULL);
 }
 
 static void print_empty_json_obj(struct vty *vty)
@@ -10735,11 +10836,10 @@ DEFUN_HIDDEN (ip_pim_mlag,
 
 void pim_cmd_init(void)
 {
-       install_node(&interface_node,
-                    pim_interface_config_write); /* INTERFACE_NODE */
+       install_node(&interface_node); /* INTERFACE_NODE */
        if_cmd_init();
 
-       install_node(&debug_node, pim_debug_config_write);
+       install_node(&debug_node);
 
        install_element(ENABLE_NODE, &pim_test_sg_keepalive_cmd);
 
@@ -10770,6 +10870,8 @@ void pim_cmd_init(void)
        install_element(CONFIG_NODE,
                        &no_ip_pim_spt_switchover_infinity_plist_cmd);
        install_element(VRF_NODE, &no_ip_pim_spt_switchover_infinity_plist_cmd);
+       install_element(CONFIG_NODE, &pim_register_accept_list_cmd);
+       install_element(VRF_NODE, &pim_register_accept_list_cmd);
        install_element(CONFIG_NODE, &ip_pim_joinprune_time_cmd);
        install_element(VRF_NODE, &ip_pim_joinprune_time_cmd);
        install_element(CONFIG_NODE, &no_ip_pim_joinprune_time_cmd);
@@ -11024,6 +11126,8 @@ void pim_cmd_init(void)
        install_element(VRF_NODE, &ip_msdp_mesh_group_source_cmd);
        install_element(CONFIG_NODE, &no_ip_msdp_mesh_group_source_cmd);
        install_element(VRF_NODE, &no_ip_msdp_mesh_group_source_cmd);
+       install_element(CONFIG_NODE, &no_ip_msdp_mesh_group_cmd);
+       install_element(VRF_NODE, &no_ip_msdp_mesh_group_cmd);
        install_element(VIEW_NODE, &show_ip_msdp_peer_detail_cmd);
        install_element(VIEW_NODE, &show_ip_msdp_peer_detail_vrf_all_cmd);
        install_element(VIEW_NODE, &show_ip_msdp_sa_detail_cmd);