]> git.proxmox.com Git - mirror_frr.git/blobdiff - pimd/pim_cmd.c
lib: Add LIB_ERR_SNMP
[mirror_frr.git] / pimd / pim_cmd.c
index 48b85fc05ec0ce39a1bd91d3e4b61617941297c0..6eb4303fb712aaeb5c1f3e6d75058a90c0d541c7 100644 (file)
@@ -1294,6 +1294,76 @@ static void pim_show_interfaces_single(struct pim_instance *pim,
        }
 }
 
+static void igmp_show_statistics(struct pim_instance *pim, struct vty *vty,
+                                const char *ifname, uint8_t uj)
+{
+       struct interface *ifp;
+       struct igmp_stats rx_stats;
+
+       igmp_stats_init(&rx_stats);
+
+       FOR_ALL_INTERFACES (pim->vrf, ifp) {
+               struct pim_interface *pim_ifp;
+               struct listnode *sock_node;
+               struct igmp_sock *igmp;
+
+               pim_ifp = ifp->info;
+
+               if (!pim_ifp)
+                       continue;
+
+               if (ifname && strcmp(ifname, ifp->name))
+                       continue;
+
+               for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node,
+                                         igmp)) {
+                       igmp_stats_add(&rx_stats, &igmp->rx_stats);
+               }
+       }
+       if (uj) {
+               json_object *json = NULL;
+               json_object *json_row = NULL;
+
+               json = json_object_new_object();
+               json_row = json_object_new_object();
+
+               json_object_string_add(json_row, "name", ifname ? ifname :
+                                      "global");
+               json_object_int_add(json_row, "queryV1", rx_stats.query_v1);
+               json_object_int_add(json_row, "queryV2", rx_stats.query_v2);
+               json_object_int_add(json_row, "queryV3", rx_stats.query_v3);
+               json_object_int_add(json_row, "leaveV3", rx_stats.leave_v2);
+               json_object_int_add(json_row, "reportV1", rx_stats.report_v1);
+               json_object_int_add(json_row, "reportV2", rx_stats.report_v2);
+               json_object_int_add(json_row, "reportV3", rx_stats.report_v3);
+               json_object_int_add(json_row, "mtraceResponse",
+                                   rx_stats.mtrace_rsp);
+               json_object_int_add(json_row, "mtraceRequest",
+                                   rx_stats.mtrace_req);
+               json_object_int_add(json_row, "unsupported",
+                                   rx_stats.unsupported);
+               json_object_object_add(json, ifname ? ifname : "global",
+                                      json_row);
+               vty_out(vty, "%s\n", json_object_to_json_string_ext(
+                                            json, JSON_C_TO_STRING_PRETTY));
+               json_object_free(json);
+       } else {
+               vty_out(vty, "IGMP RX statistics\n");
+               vty_out(vty, "Interface       : %s\n",
+                       ifname ? ifname : "global");
+               vty_out(vty, "V1 query        : %u\n", rx_stats.query_v1);
+               vty_out(vty, "V2 query        : %u\n", rx_stats.query_v2);
+               vty_out(vty, "V3 query        : %u\n", rx_stats.query_v3);
+               vty_out(vty, "V2 leave        : %u\n", rx_stats.leave_v2);
+               vty_out(vty, "V1 report       : %u\n", rx_stats.report_v1);
+               vty_out(vty, "V2 report       : %u\n", rx_stats.report_v2);
+               vty_out(vty, "V3 report       : %u\n", rx_stats.report_v3);
+               vty_out(vty, "mtrace response : %u\n", rx_stats.mtrace_rsp);
+               vty_out(vty, "mtrace request  : %u\n", rx_stats.mtrace_req);
+               vty_out(vty, "unsupported     : %u\n", rx_stats.unsupported);
+       }
+}
+
 static void pim_show_interfaces(struct pim_instance *pim, struct vty *vty,
                                uint8_t uj)
 {
@@ -1968,7 +2038,7 @@ static void pim_show_state(struct pim_instance *pim, struct vty *vty,
                } else {
                        vty_out(vty, "%-9d %-15s  %-15s  %-7s  ",
                                c_oil->installed, src_str, grp_str,
-                               ifp_in->name);
+                               in_ifname);
                }
 
                for (oif_vif_index = 0; oif_vif_index < MAXVIFS;
@@ -3527,6 +3597,33 @@ DEFUN (show_ip_igmp_sources_retransmissions,
        return CMD_SUCCESS;
 }
 
+DEFUN (show_ip_igmp_statistics,
+       show_ip_igmp_statistics_cmd,
+       "show ip igmp [vrf NAME] statistics [interface WORD] [json]",
+       SHOW_STR
+       IP_STR
+       IGMP_STR
+       VRF_CMD_HELP_STR
+       "IGMP statistics\n"
+       "interface\n"
+       "IGMP interface\n"
+       JSON_STR)
+{
+       int idx = 2;
+       struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
+       uint8_t uj = use_json(argc, argv);
+
+       if (!vrf)
+               return CMD_WARNING;
+
+       if (argv_find(argv, argc, "WORD", &idx))
+               igmp_show_statistics(vrf->info, vty, argv[idx]->arg, uj);
+       else
+               igmp_show_statistics(vrf->info, vty, NULL, uj);
+
+       return CMD_SUCCESS;
+}
+
 DEFUN (show_ip_pim_assert,
        show_ip_pim_assert_cmd,
        "show ip pim [vrf NAME] assert",
@@ -4155,7 +4252,7 @@ DEFUN (show_ip_pim_nexthop_lookup,
        "Source/RP address\n"
        "Multicast Group address\n")
 {
-       struct pim_nexthop_cache pnc;
+       struct pim_nexthop_cache *pnc = NULL;
        struct prefix nht_p;
        int result = 0;
        struct in_addr src_addr, grp_addr;
@@ -4167,6 +4264,7 @@ DEFUN (show_ip_pim_nexthop_lookup,
        char grp_str[PREFIX_STRLEN];
        int idx = 2;
        struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
+       struct pim_rpf rpf;
 
        if (!vrf)
                return CMD_WARNING;
@@ -4204,7 +4302,6 @@ DEFUN (show_ip_pim_nexthop_lookup,
                                      grp_addr))
                return CMD_SUCCESS;
 
-       memset(&pnc, 0, sizeof(struct pim_nexthop_cache));
        nht_p.family = AF_INET;
        nht_p.prefixlen = IPV4_MAX_BITLEN;
        nht_p.u.prefix4 = vif_source;
@@ -4213,12 +4310,18 @@ DEFUN (show_ip_pim_nexthop_lookup,
        grp.u.prefix4 = grp_addr;
        memset(&nexthop, 0, sizeof(nexthop));
 
-       if (pim_find_or_track_nexthop(vrf->info, &nht_p, NULL, NULL, &pnc))
-               result = pim_ecmp_nexthop_search(vrf->info, &pnc, &nexthop,
+       memset(&rpf, 0, sizeof(struct pim_rpf));
+       rpf.rpf_addr.family = AF_INET;
+       rpf.rpf_addr.prefixlen = IPV4_MAX_BITLEN;
+       rpf.rpf_addr.u.prefix4 = vif_source;
+
+       pnc = pim_nexthop_cache_find(vrf->info, &rpf);
+       if (pnc)
+               result = pim_ecmp_nexthop_search(vrf->info, pnc, &nexthop,
                                                 &nht_p, &grp, 0);
        else
-               result = pim_ecmp_nexthop_lookup(vrf->info, &nexthop,
-                                                vif_source, &nht_p, &grp, 0);
+               result = pim_ecmp_nexthop_lookup(vrf->info, &nexthop, &nht_p,
+                                                &grp, 0);
 
        if (!result) {
                vty_out(vty,
@@ -4331,9 +4434,9 @@ static void pim_cmd_show_ip_multicast_helper(struct pim_instance *pim,
        vty_out(vty, "\n");
        vty_out(vty, "Upstream Join Timer: %d secs\n", qpim_t_periodic);
        vty_out(vty, "Join/Prune Holdtime: %d secs\n", PIM_JP_HOLDTIME);
-       vty_out(vty, "PIM ECMP: %s\n", qpim_ecmp_enable ? "Enable" : "Disable");
+       vty_out(vty, "PIM ECMP: %s\n", pim->ecmp_enable ? "Enable" : "Disable");
        vty_out(vty, "PIM ECMP Rebalance: %s\n",
-               qpim_ecmp_rebalance_enable ? "Enable" : "Disable");
+               pim->ecmp_rebalance_enable ? "Enable" : "Disable");
 
        vty_out(vty, "\n");
 
@@ -4407,8 +4510,8 @@ static void show_mroute(struct pim_instance *pim, struct vty *vty, bool fill,
        json_object *json_source = NULL;
        json_object *json_oil = NULL;
        json_object *json_ifp_out = NULL;
-       int found_oif = 0;
-       int first = 1;
+       int found_oif;
+       int first;
        char grp_str[INET_ADDRSTRLEN];
        char src_str[INET_ADDRSTRLEN];
        char in_ifname[INTERFACE_NAMSIZ + 1];
@@ -5003,11 +5106,6 @@ static int pim_rp_cmd_worker(struct pim_instance *pim, struct vty *vty,
 
        result = pim_rp_new(pim, rp, group, plist);
 
-       if (result == PIM_MALLOC_FAIL) {
-               vty_out(vty, "%% Out of memory\n");
-               return CMD_WARNING_CONFIG_FAILED;
-       }
-
        if (result == PIM_GROUP_BAD_ADDRESS) {
                vty_out(vty, "%% Bad group address specified: %s\n", group);
                return CMD_WARNING_CONFIG_FAILED;
@@ -5637,7 +5735,7 @@ DEFUN (ip_pim_ecmp,
        "Enable PIM ECMP \n")
 {
        PIM_DECLVAR_CONTEXT(vrf, pim);
-       qpim_ecmp_enable = 1;
+       pim->ecmp_enable = true;
 
        return CMD_SUCCESS;
 }
@@ -5651,7 +5749,7 @@ DEFUN (no_ip_pim_ecmp,
        "Disable PIM ECMP \n")
 {
        PIM_DECLVAR_CONTEXT(vrf, pim);
-       qpim_ecmp_enable = 0;
+       pim->ecmp_enable = false;
 
        return CMD_SUCCESS;
 }
@@ -5665,8 +5763,8 @@ DEFUN (ip_pim_ecmp_rebalance,
        "Enable PIM ECMP Rebalance\n")
 {
        PIM_DECLVAR_CONTEXT(vrf, pim);
-       qpim_ecmp_enable = 1;
-       qpim_ecmp_rebalance_enable = 1;
+       pim->ecmp_enable = true;
+       pim->ecmp_rebalance_enable = true;
 
        return CMD_SUCCESS;
 }
@@ -5681,7 +5779,7 @@ DEFUN (no_ip_pim_ecmp_rebalance,
        "Disable PIM ECMP Rebalance\n")
 {
        PIM_DECLVAR_CONTEXT(vrf, pim);
-       qpim_ecmp_rebalance_enable = 0;
+       pim->ecmp_rebalance_enable = false;
 
        return CMD_SUCCESS;
 }
@@ -7226,8 +7324,13 @@ DEFUN (no_debug_msdp,
        return CMD_SUCCESS;
 }
 
-ALIAS(no_debug_msdp, undebug_msdp_cmd, "undebug msdp",
-      UNDEBUG_STR DEBUG_MSDP_STR)
+#if CONFDATE > 20190402
+CPP_NOTICE("bgpd: time to remove undebug commands")
+#endif
+ALIAS_HIDDEN (no_debug_msdp,
+              undebug_msdp_cmd,
+              "undebug msdp",
+              UNDEBUG_STR DEBUG_MSDP_STR)
 
 DEFUN (debug_msdp_events,
        debug_msdp_events_cmd,
@@ -7252,8 +7355,15 @@ DEFUN (no_debug_msdp_events,
        return CMD_SUCCESS;
 }
 
-ALIAS(no_debug_msdp_events, undebug_msdp_events_cmd, "undebug msdp events",
-      UNDEBUG_STR DEBUG_MSDP_STR DEBUG_MSDP_EVENTS_STR)
+#if CONFDATE > 20190402
+CPP_NOTICE("bgpd: time to remove undebug commands")
+#endif
+ALIAS_HIDDEN (no_debug_msdp_events,
+              undebug_msdp_events_cmd,
+              "undebug msdp events",
+              UNDEBUG_STR
+              DEBUG_MSDP_STR
+              DEBUG_MSDP_EVENTS_STR)
 
 DEFUN (debug_msdp_packets,
        debug_msdp_packets_cmd,
@@ -7278,8 +7388,15 @@ DEFUN (no_debug_msdp_packets,
        return CMD_SUCCESS;
 }
 
-ALIAS(no_debug_msdp_packets, undebug_msdp_packets_cmd, "undebug msdp packets",
-      UNDEBUG_STR DEBUG_MSDP_STR DEBUG_MSDP_PACKETS_STR)
+#if CONFDATE > 20190402
+CPP_NOTICE("bgpd: time to remove undebug commands")
+#endif
+ALIAS_HIDDEN (no_debug_msdp_packets,
+              undebug_msdp_packets_cmd,
+              "undebug msdp packets",
+              UNDEBUG_STR
+              DEBUG_MSDP_STR
+              DEBUG_MSDP_PACKETS_STR)
 
 DEFUN (debug_mtrace,
        debug_mtrace_cmd,
@@ -7425,7 +7542,12 @@ DEFUN (no_ip_pim_bfd,
        return CMD_SUCCESS;
 }
 
-DEFUN (ip_pim_bfd_param,
+#if HAVE_BFDD > 0
+DEFUN_HIDDEN(
+#else
+DEFUN(
+#endif /* HAVE_BFDD */
+       ip_pim_bfd_param,
        ip_pim_bfd_param_cmd,
        "ip pim bfd (2-255) (50-60000) (50-60000)",
        IP_STR
@@ -7463,12 +7585,14 @@ DEFUN (ip_pim_bfd_param,
        return CMD_SUCCESS;
 }
 
+#if HAVE_BFDD == 0
 ALIAS(no_ip_pim_bfd, no_ip_pim_bfd_param_cmd,
       "no ip pim bfd (2-255) (50-60000) (50-60000)", NO_STR IP_STR PIM_STR
       "Enables BFD support\n"
       "Detect Multiplier\n"
       "Required min receive interval\n"
       "Desired min transmit interval\n")
+#endif /* !HAVE_BFDD */
 
 static int ip_msdp_peer_cmd_worker(struct pim_instance *pim, struct vty *vty,
                                   const char *peer, const char *local)
@@ -8625,6 +8749,7 @@ void pim_cmd_init(void)
        install_element(VIEW_NODE, &show_ip_igmp_groups_retransmissions_cmd);
        install_element(VIEW_NODE, &show_ip_igmp_sources_cmd);
        install_element(VIEW_NODE, &show_ip_igmp_sources_retransmissions_cmd);
+       install_element(VIEW_NODE, &show_ip_igmp_statistics_cmd);
        install_element(VIEW_NODE, &show_ip_pim_assert_cmd);
        install_element(VIEW_NODE, &show_ip_pim_assert_internal_cmd);
        install_element(VIEW_NODE, &show_ip_pim_assert_metric_cmd);
@@ -8783,5 +8908,7 @@ void pim_cmd_init(void)
        install_element(INTERFACE_NODE, &ip_pim_bfd_cmd);
        install_element(INTERFACE_NODE, &ip_pim_bfd_param_cmd);
        install_element(INTERFACE_NODE, &no_ip_pim_bfd_cmd);
+#if HAVE_BFDD == 0
        install_element(INTERFACE_NODE, &no_ip_pim_bfd_param_cmd);
+#endif /* !HAVE_BFDD */
 }