Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
9006 lines (7777 sloc) 232 KB
/*
* PIM for Quagga
* Copyright (C) 2008 Everton da Silva Marques
*
* 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>
#include "lib/json.h"
#include "command.h"
#include "if.h"
#include "prefix.h"
#include "zclient.h"
#include "plist.h"
#include "hash.h"
#include "nexthop.h"
#include "vrf.h"
#include "ferr.h"
#include "pimd.h"
#include "pim_mroute.h"
#include "pim_cmd.h"
#include "pim_iface.h"
#include "pim_vty.h"
#include "pim_mroute.h"
#include "pim_str.h"
#include "pim_igmp.h"
#include "pim_igmpv3.h"
#include "pim_sock.h"
#include "pim_time.h"
#include "pim_util.h"
#include "pim_oil.h"
#include "pim_neighbor.h"
#include "pim_pim.h"
#include "pim_ifchannel.h"
#include "pim_hello.h"
#include "pim_msg.h"
#include "pim_upstream.h"
#include "pim_rpf.h"
#include "pim_macro.h"
#include "pim_ssmpingd.h"
#include "pim_zebra.h"
#include "pim_static.h"
#include "pim_rp.h"
#include "pim_zlookup.h"
#include "pim_msdp.h"
#include "pim_ssm.h"
#include "pim_nht.h"
#include "pim_bfd.h"
#include "bfd.h"
#ifndef VTYSH_EXTRACT_PL
#include "pimd/pim_cmd_clippy.c"
#endif
static struct cmd_node interface_node = {
INTERFACE_NODE, "%s(config-if)# ", 1 /* vtysh ? yes */
};
static struct cmd_node debug_node = {DEBUG_NODE, "", 1};
static struct vrf *pim_cmd_lookup_vrf(struct vty *vty, struct cmd_token *argv[],
const int argc, int *idx)
{
struct vrf *vrf;
if (argv_find(argv, argc, "NAME", idx))
vrf = vrf_lookup_by_name(argv[*idx]->arg);
else
vrf = vrf_lookup_by_id(VRF_DEFAULT);
if (!vrf)
vty_out(vty, "Specified VRF: %s does not exist\n",
argv[*idx]->arg);
return vrf;
}
static void pim_if_membership_clear(struct interface *ifp)
{
struct pim_interface *pim_ifp;
pim_ifp = ifp->info;
zassert(pim_ifp);
if (PIM_IF_TEST_PIM(pim_ifp->options)
&& PIM_IF_TEST_IGMP(pim_ifp->options)) {
return;
}
pim_ifchannel_membership_clear(ifp);
}
/*
When PIM is disabled on interface, IGMPv3 local membership
information is not injected into PIM interface state.
The function pim_if_membership_refresh() fetches all IGMPv3 local
membership information into PIM. It is intented to be called
whenever PIM is enabled on the interface in order to collect missed
local membership information.
*/
static void pim_if_membership_refresh(struct interface *ifp)
{
struct pim_interface *pim_ifp;
struct listnode *sock_node;
struct igmp_sock *igmp;
pim_ifp = ifp->info;
zassert(pim_ifp);
if (!PIM_IF_TEST_PIM(pim_ifp->options))
return;
if (!PIM_IF_TEST_IGMP(pim_ifp->options))
return;
/*
First clear off membership from all PIM (S,G) entries on the
interface
*/
pim_ifchannel_membership_clear(ifp);
/*
Then restore PIM (S,G) membership from all IGMPv3 (S,G) entries on
the interface
*/
/* scan igmp sockets */
for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node, igmp)) {
struct listnode *grpnode;
struct igmp_group *grp;
/* scan igmp groups */
for (ALL_LIST_ELEMENTS_RO(igmp->igmp_group_list, grpnode,
grp)) {
struct listnode *srcnode;
struct igmp_source *src;
/* scan group sources */
for (ALL_LIST_ELEMENTS_RO(grp->group_source_list,
srcnode, src)) {
if (IGMP_SOURCE_TEST_FORWARDING(
src->source_flags)) {
struct prefix_sg sg;
memset(&sg, 0,
sizeof(struct prefix_sg));
sg.src = src->source_addr;
sg.grp = grp->group_addr;
pim_ifchannel_local_membership_add(ifp,
&sg);
}
} /* scan group sources */
} /* scan igmp groups */
} /* scan igmp sockets */
/*
Finally delete every PIM (S,G) entry lacking all state info
*/
pim_ifchannel_delete_on_noinfo(ifp);
}
static void pim_show_assert_helper(struct vty *vty,
struct pim_interface *pim_ifp,
struct pim_ifchannel *ch, time_t now)
{
char ch_src_str[INET_ADDRSTRLEN];
char ch_grp_str[INET_ADDRSTRLEN];
char winner_str[INET_ADDRSTRLEN];
struct in_addr ifaddr;
char uptime[10];
char timer[10];
ifaddr = pim_ifp->primary_address;
pim_inet4_dump("<ch_src?>", ch->sg.src, ch_src_str, sizeof(ch_src_str));
pim_inet4_dump("<ch_grp?>", ch->sg.grp, ch_grp_str, sizeof(ch_grp_str));
pim_inet4_dump("<assrt_win?>", ch->ifassert_winner, winner_str,
sizeof(winner_str));
pim_time_uptime(uptime, sizeof(uptime), now - ch->ifassert_creation);
pim_time_timer_to_mmss(timer, sizeof(timer), ch->t_ifassert_timer);
vty_out(vty, "%-9s %-15s %-15s %-15s %-6s %-15s %-8s %-5s\n",
ch->interface->name, inet_ntoa(ifaddr), ch_src_str, ch_grp_str,
pim_ifchannel_ifassert_name(ch->ifassert_state), winner_str,
uptime, timer);
}
static void pim_show_assert(struct pim_instance *pim, struct vty *vty)
{
struct pim_interface *pim_ifp;
struct pim_ifchannel *ch;
struct interface *ifp;
time_t now;
now = pim_time_monotonic_sec();
vty_out(vty,
"Interface Address Source Group State Winner Uptime Timer\n");
FOR_ALL_INTERFACES (pim->vrf, ifp) {
pim_ifp = ifp->info;
if (!pim_ifp)
continue;
RB_FOREACH (ch, pim_ifchannel_rb, &pim_ifp->ifchannel_rb) {
pim_show_assert_helper(vty, pim_ifp, ch, now);
} /* scan interface channels */
}
}
static void pim_show_assert_internal_helper(struct vty *vty,
struct pim_interface *pim_ifp,
struct pim_ifchannel *ch)
{
char ch_src_str[INET_ADDRSTRLEN];
char ch_grp_str[INET_ADDRSTRLEN];
struct in_addr ifaddr;
ifaddr = pim_ifp->primary_address;
pim_inet4_dump("<ch_src?>", ch->sg.src, ch_src_str, sizeof(ch_src_str));
pim_inet4_dump("<ch_grp?>", ch->sg.grp, ch_grp_str, sizeof(ch_grp_str));
vty_out(vty, "%-9s %-15s %-15s %-15s %-3s %-3s %-3s %-4s\n",
ch->interface->name, inet_ntoa(ifaddr), ch_src_str, ch_grp_str,
PIM_IF_FLAG_TEST_COULD_ASSERT(ch->flags) ? "yes" : "no",
pim_macro_ch_could_assert_eval(ch) ? "yes" : "no",
PIM_IF_FLAG_TEST_ASSERT_TRACKING_DESIRED(ch->flags) ? "yes"
: "no",
pim_macro_assert_tracking_desired_eval(ch) ? "yes" : "no");
}
static void pim_show_assert_internal(struct pim_instance *pim, struct vty *vty)
{
struct pim_interface *pim_ifp;
struct pim_ifchannel *ch;
struct interface *ifp;
vty_out(vty,
"CA: CouldAssert\n"
"ECA: Evaluate CouldAssert\n"
"ATD: AssertTrackingDesired\n"
"eATD: Evaluate AssertTrackingDesired\n\n");
vty_out(vty,
"Interface Address Source Group CA eCA ATD eATD\n");
FOR_ALL_INTERFACES (pim->vrf, ifp) {
pim_ifp = ifp->info;
if (!pim_ifp)
continue;
RB_FOREACH (ch, pim_ifchannel_rb, &pim_ifp->ifchannel_rb) {
pim_show_assert_internal_helper(vty, pim_ifp, ch);
} /* scan interface channels */
}
}
static void pim_show_assert_metric_helper(struct vty *vty,
struct pim_interface *pim_ifp,
struct pim_ifchannel *ch)
{
char ch_src_str[INET_ADDRSTRLEN];
char ch_grp_str[INET_ADDRSTRLEN];
char addr_str[INET_ADDRSTRLEN];
struct pim_assert_metric am;
struct in_addr ifaddr;
ifaddr = pim_ifp->primary_address;
am = pim_macro_spt_assert_metric(&ch->upstream->rpf,
pim_ifp->primary_address);
pim_inet4_dump("<ch_src?>", ch->sg.src, ch_src_str, sizeof(ch_src_str));
pim_inet4_dump("<ch_grp?>", ch->sg.grp, ch_grp_str, sizeof(ch_grp_str));
pim_inet4_dump("<addr?>", am.ip_address, addr_str, sizeof(addr_str));
vty_out(vty, "%-9s %-15s %-15s %-15s %-3s %4u %6u %-15s\n",
ch->interface->name, inet_ntoa(ifaddr), ch_src_str, ch_grp_str,
am.rpt_bit_flag ? "yes" : "no", am.metric_preference,
am.route_metric, addr_str);
}
static void pim_show_assert_metric(struct pim_instance *pim, struct vty *vty)
{
struct pim_interface *pim_ifp;
struct pim_ifchannel *ch;
struct interface *ifp;
vty_out(vty,
"Interface Address Source Group RPT Pref Metric Address \n");
FOR_ALL_INTERFACES (pim->vrf, ifp) {
pim_ifp = ifp->info;
if (!pim_ifp)
continue;
RB_FOREACH (ch, pim_ifchannel_rb, &pim_ifp->ifchannel_rb) {
pim_show_assert_metric_helper(vty, pim_ifp, ch);
} /* scan interface channels */
}
}
static void pim_show_assert_winner_metric_helper(struct vty *vty,
struct pim_interface *pim_ifp,
struct pim_ifchannel *ch)
{
char ch_src_str[INET_ADDRSTRLEN];
char ch_grp_str[INET_ADDRSTRLEN];
char addr_str[INET_ADDRSTRLEN];
struct pim_assert_metric *am;
struct in_addr ifaddr;
char pref_str[16];
char metr_str[16];
ifaddr = pim_ifp->primary_address;
am = &ch->ifassert_winner_metric;
pim_inet4_dump("<ch_src?>", ch->sg.src, ch_src_str, sizeof(ch_src_str));
pim_inet4_dump("<ch_grp?>", ch->sg.grp, ch_grp_str, sizeof(ch_grp_str));
pim_inet4_dump("<addr?>", am->ip_address, addr_str, sizeof(addr_str));
if (am->metric_preference == PIM_ASSERT_METRIC_PREFERENCE_MAX)
snprintf(pref_str, sizeof(pref_str), "INFI");
else
snprintf(pref_str, sizeof(pref_str), "%4u",
am->metric_preference);
if (am->route_metric == PIM_ASSERT_ROUTE_METRIC_MAX)
snprintf(metr_str, sizeof(metr_str), "INFI");
else
snprintf(metr_str, sizeof(metr_str), "%6u", am->route_metric);
vty_out(vty, "%-9s %-15s %-15s %-15s %-3s %-4s %-6s %-15s\n",
ch->interface->name, inet_ntoa(ifaddr), ch_src_str, ch_grp_str,
am->rpt_bit_flag ? "yes" : "no", pref_str, metr_str, addr_str);
}
static void pim_show_assert_winner_metric(struct pim_instance *pim,
struct vty *vty)
{
struct pim_interface *pim_ifp;
struct pim_ifchannel *ch;
struct interface *ifp;
vty_out(vty,
"Interface Address Source Group RPT Pref Metric Address \n");
FOR_ALL_INTERFACES (pim->vrf, ifp) {
pim_ifp = ifp->info;
if (!pim_ifp)
continue;
RB_FOREACH (ch, pim_ifchannel_rb, &pim_ifp->ifchannel_rb) {
pim_show_assert_winner_metric_helper(vty, pim_ifp, ch);
} /* scan interface channels */
}
}
static void json_object_pim_ifp_add(struct json_object *json,
struct interface *ifp)
{
struct pim_interface *pim_ifp;
pim_ifp = ifp->info;
json_object_string_add(json, "name", ifp->name);
json_object_string_add(json, "state", if_is_up(ifp) ? "up" : "down");
json_object_string_add(json, "address",
inet_ntoa(pim_ifp->primary_address));
json_object_int_add(json, "index", ifp->ifindex);
if (if_is_multicast(ifp))
json_object_boolean_true_add(json, "flagMulticast");
if (if_is_broadcast(ifp))
json_object_boolean_true_add(json, "flagBroadcast");
if (ifp->flags & IFF_ALLMULTI)
json_object_boolean_true_add(json, "flagAllMulticast");
if (ifp->flags & IFF_PROMISC)
json_object_boolean_true_add(json, "flagPromiscuous");
if (PIM_IF_IS_DELETED(ifp))
json_object_boolean_true_add(json, "flagDeleted");
if (pim_if_lan_delay_enabled(ifp))
json_object_boolean_true_add(json, "lanDelayEnabled");
}
static void pim_show_membership_helper(struct vty *vty,
struct pim_interface *pim_ifp,
struct pim_ifchannel *ch,
struct json_object *json)
{
char ch_src_str[INET_ADDRSTRLEN];
char ch_grp_str[INET_ADDRSTRLEN];
json_object *json_iface = NULL;
json_object *json_row = NULL;
pim_inet4_dump("<ch_src?>", ch->sg.src, ch_src_str, sizeof(ch_src_str));
pim_inet4_dump("<ch_grp?>", ch->sg.grp, ch_grp_str, sizeof(ch_grp_str));
json_object_object_get_ex(json, ch->interface->name, &json_iface);
if (!json_iface) {
json_iface = json_object_new_object();
json_object_pim_ifp_add(json_iface, ch->interface);
json_object_object_add(json, ch->interface->name, json_iface);
}
json_row = json_object_new_object();
json_object_string_add(json_row, "source", ch_src_str);
json_object_string_add(json_row, "group", ch_grp_str);
json_object_string_add(json_row, "localMembership",
ch->local_ifmembership == PIM_IFMEMBERSHIP_NOINFO
? "NOINFO"
: "INCLUDE");
json_object_object_add(json_iface, ch_grp_str, json_row);
}
static void pim_show_membership(struct pim_instance *pim, struct vty *vty,
bool uj)
{
struct pim_interface *pim_ifp;
struct pim_ifchannel *ch;
struct interface *ifp;
enum json_type type;
json_object *json = NULL;
json_object *json_tmp = NULL;
json = json_object_new_object();
FOR_ALL_INTERFACES (pim->vrf, ifp) {
pim_ifp = ifp->info;
if (!pim_ifp)
continue;
RB_FOREACH (ch, pim_ifchannel_rb, &pim_ifp->ifchannel_rb) {
pim_show_membership_helper(vty, pim_ifp, ch, json);
} /* scan interface channels */
}
if (uj) {
vty_out(vty, "%s\n", json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
} else {
vty_out(vty,
"Interface Address Source Group Membership\n");
/*
* Example of the json data we are traversing
*
* {
* "swp3":{
* "name":"swp3",
* "state":"up",
* "address":"10.1.20.1",
* "index":5,
* "flagMulticast":true,
* "flagBroadcast":true,
* "lanDelayEnabled":true,
* "226.10.10.10":{
* "source":"*",
* "group":"226.10.10.10",
* "localMembership":"INCLUDE"
* }
* }
* }
*/
/* foreach interface */
json_object_object_foreach(json, key, val)
{
/* Find all of the keys where the val is an object. In
* the example
* above the only one is 226.10.10.10
*/
json_object_object_foreach(val, if_field_key,
if_field_val)
{
type = json_object_get_type(if_field_val);
if (type == json_type_object) {
vty_out(vty, "%-9s ", key);
json_object_object_get_ex(
val, "address", &json_tmp);
vty_out(vty, "%-15s ",
json_object_get_string(
json_tmp));
json_object_object_get_ex(if_field_val,
"source",
&json_tmp);
vty_out(vty, "%-15s ",
json_object_get_string(
json_tmp));
/* Group */
vty_out(vty, "%-15s ", if_field_key);
json_object_object_get_ex(
if_field_val, "localMembership",
&json_tmp);
vty_out(vty, "%-10s\n",
json_object_get_string(
json_tmp));
}
}
}
}
json_object_free(json);
}
static void pim_print_ifp_flags(struct vty *vty, struct interface *ifp,
int mloop)
{
vty_out(vty, "Flags\n");
vty_out(vty, "-----\n");
vty_out(vty, "All Multicast : %s\n",
(ifp->flags & IFF_ALLMULTI) ? "yes" : "no");
vty_out(vty, "Broadcast : %s\n",
if_is_broadcast(ifp) ? "yes" : "no");
vty_out(vty, "Deleted : %s\n",
PIM_IF_IS_DELETED(ifp) ? "yes" : "no");
vty_out(vty, "Interface Index : %d\n", ifp->ifindex);
vty_out(vty, "Multicast : %s\n",
if_is_multicast(ifp) ? "yes" : "no");
vty_out(vty, "Multicast Loop : %d\n", mloop);
vty_out(vty, "Promiscuous : %s\n",
(ifp->flags & IFF_PROMISC) ? "yes" : "no");
vty_out(vty, "\n");
vty_out(vty, "\n");
}
static void igmp_show_interfaces(struct pim_instance *pim, struct vty *vty,
bool uj)
{
struct interface *ifp;
time_t now;
json_object *json = NULL;
json_object *json_row = NULL;
now = pim_time_monotonic_sec();
if (uj)
json = json_object_new_object();
else
vty_out(vty,
"Interface State Address V Querier Query Timer Uptime\n");
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;
for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node,
igmp)) {
char uptime[10];
char query_hhmmss[10];
pim_time_uptime(uptime, sizeof(uptime),
now - igmp->sock_creation);
pim_time_timer_to_hhmmss(query_hhmmss,
sizeof(query_hhmmss),
igmp->t_igmp_query_timer);
if (uj) {
json_row = json_object_new_object();
json_object_pim_ifp_add(json_row, ifp);
json_object_string_add(json_row, "upTime",
uptime);
json_object_int_add(json_row, "version",
pim_ifp->igmp_version);
if (igmp->t_igmp_query_timer) {
json_object_boolean_true_add(json_row,
"querier");
json_object_string_add(json_row,
"queryTimer",
query_hhmmss);
}
json_object_object_add(json, ifp->name,
json_row);
if (igmp->mtrace_only) {
json_object_boolean_true_add(
json_row, "mtraceOnly");
}
} else {
vty_out(vty,
"%-9s %5s %15s %d %7s %11s %8s\n",
ifp->name,
if_is_up(ifp)
? (igmp->mtrace_only ? "mtrc"
: "up")
: "down",
inet_ntoa(igmp->ifaddr),
pim_ifp->igmp_version,
igmp->t_igmp_query_timer ? "local"
: "other",
query_hhmmss, uptime);
}
}
}
if (uj) {
vty_out(vty, "%s\n", json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
}
}
static void igmp_show_interfaces_single(struct pim_instance *pim,
struct vty *vty, const char *ifname,
bool uj)
{
struct igmp_sock *igmp;
struct interface *ifp;
struct listnode *sock_node;
struct pim_interface *pim_ifp;
char uptime[10];
char query_hhmmss[10];
char other_hhmmss[10];
int found_ifname = 0;
int sqi;
int mloop = 0;
long gmi_msec; /* Group Membership Interval */
long lmqt_msec;
long ohpi_msec;
long oqpi_msec; /* Other Querier Present Interval */
long qri_msec;
time_t now;
json_object *json = NULL;
json_object *json_row = NULL;
if (uj)
json = json_object_new_object();
now = pim_time_monotonic_sec();
FOR_ALL_INTERFACES (pim->vrf, ifp) {
pim_ifp = ifp->info;
if (!pim_ifp)
continue;
if (strcmp(ifname, "detail") && strcmp(ifname, ifp->name))
continue;
for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node,
igmp)) {
found_ifname = 1;
pim_time_uptime(uptime, sizeof(uptime),
now - igmp->sock_creation);
pim_time_timer_to_hhmmss(query_hhmmss,
sizeof(query_hhmmss),
igmp->t_igmp_query_timer);
pim_time_timer_to_hhmmss(other_hhmmss,
sizeof(other_hhmmss),
igmp->t_other_querier_timer);
gmi_msec = PIM_IGMP_GMI_MSEC(
igmp->querier_robustness_variable,
igmp->querier_query_interval,
pim_ifp->igmp_query_max_response_time_dsec);
sqi = PIM_IGMP_SQI(
pim_ifp->igmp_default_query_interval);
oqpi_msec = PIM_IGMP_OQPI_MSEC(
igmp->querier_robustness_variable,
igmp->querier_query_interval,
pim_ifp->igmp_query_max_response_time_dsec);
lmqt_msec = PIM_IGMP_LMQT_MSEC(
pim_ifp->igmp_query_max_response_time_dsec,
igmp->querier_robustness_variable);
ohpi_msec =
PIM_IGMP_OHPI_DSEC(
igmp->querier_robustness_variable,
igmp->querier_query_interval,
pim_ifp->igmp_query_max_response_time_dsec)
* 100;
qri_msec = pim_ifp->igmp_query_max_response_time_dsec
* 100;
if (pim_ifp->pim_sock_fd >= 0)
mloop = pim_socket_mcastloop_get(
pim_ifp->pim_sock_fd);
else
mloop = 0;
if (uj) {
json_row = json_object_new_object();
json_object_pim_ifp_add(json_row, ifp);
json_object_string_add(json_row, "upTime",
uptime);
json_object_string_add(json_row, "querier",
igmp->t_igmp_query_timer
? "local"
: "other");
json_object_int_add(json_row, "queryStartCount",
igmp->startup_query_count);
json_object_string_add(json_row,
"queryQueryTimer",
query_hhmmss);
json_object_string_add(json_row,
"queryOtherTimer",
other_hhmmss);
json_object_int_add(json_row, "version",
pim_ifp->igmp_version);
json_object_int_add(
json_row,
"timerGroupMembershipIntervalMsec",
gmi_msec);
json_object_int_add(json_row,
"timerLastMemberQueryMsec",
lmqt_msec);
json_object_int_add(
json_row,
"timerOlderHostPresentIntervalMsec",
ohpi_msec);
json_object_int_add(
json_row,
"timerOtherQuerierPresentIntervalMsec",
oqpi_msec);
json_object_int_add(
json_row, "timerQueryInterval",
igmp->querier_query_interval);
json_object_int_add(
json_row,
"timerQueryResponseIntervalMsec",
qri_msec);
json_object_int_add(
json_row, "timerRobustnessVariable",
igmp->querier_robustness_variable);
json_object_int_add(json_row,
"timerStartupQueryInterval",
sqi);
json_object_object_add(json, ifp->name,
json_row);
if (igmp->mtrace_only) {
json_object_boolean_true_add(
json_row, "mtraceOnly");
}
} else {
vty_out(vty, "Interface : %s\n", ifp->name);
vty_out(vty, "State : %s\n",
if_is_up(ifp)
? (igmp->mtrace_only ? "mtrace"
: "up")
: "down");
vty_out(vty, "Address : %s\n",
inet_ntoa(pim_ifp->primary_address));
vty_out(vty, "Uptime : %s\n", uptime);
vty_out(vty, "Version : %d\n",
pim_ifp->igmp_version);
vty_out(vty, "\n");
vty_out(vty, "\n");
vty_out(vty, "Querier\n");
vty_out(vty, "-------\n");
vty_out(vty, "Querier : %s\n",
igmp->t_igmp_query_timer ? "local"
: "other");
vty_out(vty, "Start Count : %d\n",
igmp->startup_query_count);
vty_out(vty, "Query Timer : %s\n",
query_hhmmss);
vty_out(vty, "Other Timer : %s\n",
other_hhmmss);
vty_out(vty, "\n");
vty_out(vty, "\n");
vty_out(vty, "Timers\n");
vty_out(vty, "------\n");
vty_out(vty,
"Group Membership Interval : %lis\n",
gmi_msec / 1000);
vty_out(vty,
"Last Member Query Time : %lis\n",
lmqt_msec / 1000);
vty_out(vty,
"Older Host Present Interval : %lis\n",
ohpi_msec / 1000);
vty_out(vty,
"Other Querier Present Interval : %lis\n",
oqpi_msec / 1000);
vty_out(vty,
"Query Interval : %ds\n",
igmp->querier_query_interval);
vty_out(vty,
"Query Response Interval : %lis\n",
qri_msec / 1000);
vty_out(vty,
"Robustness Variable : %d\n",
igmp->querier_robustness_variable);
vty_out(vty,
"Startup Query Interval : %ds\n",
sqi);
vty_out(vty, "\n");
vty_out(vty, "\n");
pim_print_ifp_flags(vty, ifp, mloop);
}
}
}
if (uj) {
vty_out(vty, "%s\n", json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
} else {
if (!found_ifname)
vty_out(vty, "%% No such interface\n");
}
}
static void igmp_show_interface_join(struct pim_instance *pim, struct vty *vty)
{
struct interface *ifp;
time_t now;
now = pim_time_monotonic_sec();
vty_out(vty,
"Interface Address Source Group Socket Uptime \n");
FOR_ALL_INTERFACES (pim->vrf, ifp) {
struct pim_interface *pim_ifp;
struct listnode *join_node;
struct igmp_join *ij;
struct in_addr pri_addr;
char pri_addr_str[INET_ADDRSTRLEN];
pim_ifp = ifp->info;
if (!pim_ifp)
continue;
if (!pim_ifp->igmp_join_list)
continue;
pri_addr = pim_find_primary_addr(ifp);
pim_inet4_dump("<pri?>", pri_addr, pri_addr_str,
sizeof(pri_addr_str));
for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_join_list, join_node,
ij)) {
char group_str[INET_ADDRSTRLEN];
char source_str[INET_ADDRSTRLEN];
char uptime[10];
pim_time_uptime(uptime, sizeof(uptime),
now - ij->sock_creation);
pim_inet4_dump("<grp?>", ij->group_addr, group_str,
sizeof(group_str));
pim_inet4_dump("<src?>", ij->source_addr, source_str,
sizeof(source_str));
vty_out(vty, "%-9s %-15s %-15s %-15s %6d %8s\n",
ifp->name, pri_addr_str, source_str, group_str,
ij->sock_fd, uptime);
} /* for (pim_ifp->igmp_join_list) */
} /* for (iflist) */
}
static void pim_show_interfaces_single(struct pim_instance *pim,
struct vty *vty, const char *ifname,
bool uj)
{
struct in_addr ifaddr;
struct interface *ifp;
struct listnode *neighnode;
struct listnode *upnode;
struct pim_interface *pim_ifp;
struct pim_neighbor *neigh;
struct pim_upstream *up;
time_t now;
char dr_str[INET_ADDRSTRLEN];
char dr_uptime[10];
char expire[10];
char grp_str[INET_ADDRSTRLEN];
char hello_period[10];
char hello_timer[10];
char neigh_src_str[INET_ADDRSTRLEN];
char src_str[INET_ADDRSTRLEN];
char stat_uptime[10];
char uptime[10];
int mloop = 0;
int found_ifname = 0;
int print_header;
json_object *json = NULL;
json_object *json_row = NULL;
json_object *json_pim_neighbor = NULL;
json_object *json_pim_neighbors = NULL;
json_object *json_group = NULL;
json_object *json_group_source = NULL;
json_object *json_fhr_sources = NULL;
struct pim_secondary_addr *sec_addr;
struct listnode *sec_node;
now = pim_time_monotonic_sec();
if (uj)
json = json_object_new_object();
FOR_ALL_INTERFACES (pim->vrf, ifp) {
pim_ifp = ifp->info;
if (!pim_ifp)
continue;
if (strcmp(ifname, "detail") && strcmp(ifname, ifp->name))
continue;
found_ifname = 1;
ifaddr = pim_ifp->primary_address;
pim_inet4_dump("<dr?>", pim_ifp->pim_dr_addr, dr_str,
sizeof(dr_str));
pim_time_uptime_begin(dr_uptime, sizeof(dr_uptime), now,
pim_ifp->pim_dr_election_last);
pim_time_timer_to_hhmmss(hello_timer, sizeof(hello_timer),
pim_ifp->t_pim_hello_timer);
pim_time_mmss(hello_period, sizeof(hello_period),
pim_ifp->pim_hello_period);
pim_time_uptime(stat_uptime, sizeof(stat_uptime),
now - pim_ifp->pim_ifstat_start);
if (pim_ifp->pim_sock_fd >= 0)
mloop = pim_socket_mcastloop_get(pim_ifp->pim_sock_fd);
else
mloop = 0;
if (uj) {
char pbuf[PREFIX2STR_BUFFER];
json_row = json_object_new_object();
json_object_pim_ifp_add(json_row, ifp);
if (pim_ifp->update_source.s_addr != INADDR_ANY) {
json_object_string_add(
json_row, "useSource",
inet_ntoa(pim_ifp->update_source));
}
if (pim_ifp->sec_addr_list) {
json_object *sec_list = NULL;
sec_list = json_object_new_array();
for (ALL_LIST_ELEMENTS_RO(
pim_ifp->sec_addr_list, sec_node,
sec_addr)) {
json_object_array_add(
sec_list,
json_object_new_string(
prefix2str(
&sec_addr->addr,
pbuf,
sizeof(pbuf))));
}
json_object_object_add(json_row,
"secondaryAddressList",
sec_list);
}
// PIM neighbors
if (pim_ifp->pim_neighbor_list->count) {
json_pim_neighbors = json_object_new_object();
for (ALL_LIST_ELEMENTS_RO(
pim_ifp->pim_neighbor_list,
neighnode, neigh)) {
json_pim_neighbor =
json_object_new_object();
pim_inet4_dump("<src?>",
neigh->source_addr,
neigh_src_str,
sizeof(neigh_src_str));
pim_time_uptime(uptime, sizeof(uptime),
now - neigh->creation);
pim_time_timer_to_hhmmss(
expire, sizeof(expire),
neigh->t_expire_timer);
json_object_string_add(
json_pim_neighbor, "address",
neigh_src_str);
json_object_string_add(
json_pim_neighbor, "upTime",
uptime);
json_object_string_add(
json_pim_neighbor, "holdtime",
expire);
json_object_object_add(
json_pim_neighbors,
neigh_src_str,
json_pim_neighbor);
}
json_object_object_add(json_row, "neighbors",
json_pim_neighbors);
}
json_object_string_add(json_row, "drAddress", dr_str);
json_object_int_add(json_row, "drPriority",
pim_ifp->pim_dr_priority);
json_object_string_add(json_row, "drUptime", dr_uptime);
json_object_int_add(json_row, "drElections",
pim_ifp->pim_dr_election_count);
json_object_int_add(json_row, "drChanges",
pim_ifp->pim_dr_election_changes);
// FHR
for (ALL_LIST_ELEMENTS_RO(pim->upstream_list, upnode,
up)) {
if (ifp != up->rpf.source_nexthop.interface)
continue;
if (!(up->flags & PIM_UPSTREAM_FLAG_MASK_FHR))
continue;
if (!json_fhr_sources)
json_fhr_sources =
json_object_new_object();
pim_inet4_dump("<src?>", up->sg.src, src_str,
sizeof(src_str));
pim_inet4_dump("<grp?>", up->sg.grp, grp_str,
sizeof(grp_str));
pim_time_uptime(uptime, sizeof(uptime),
now - up->state_transition);
/*
* Does this group live in json_fhr_sources?
* If not create it.
*/
json_object_object_get_ex(json_fhr_sources,
grp_str, &json_group);
if (!json_group) {
json_group = json_object_new_object();
json_object_object_add(json_fhr_sources,
grp_str,
json_group);
}
json_group_source = json_object_new_object();
json_object_string_add(json_group_source,
"source", src_str);
json_object_string_add(json_group_source,
"group", grp_str);
json_object_string_add(json_group_source,
"upTime", uptime);
json_object_object_add(json_group, src_str,
json_group_source);
}
if (json_fhr_sources) {
json_object_object_add(json_row,
"firstHopRouter",
json_fhr_sources);
}
json_object_int_add(json_row, "helloPeriod",
pim_ifp->pim_hello_period);
json_object_string_add(json_row, "helloTimer",
hello_timer);
json_object_string_add(json_row, "helloStatStart",
stat_uptime);
json_object_int_add(json_row, "helloReceived",
pim_ifp->pim_ifstat_hello_recv);
json_object_int_add(json_row, "helloReceivedFailed",
pim_ifp->pim_ifstat_hello_recvfail);
json_object_int_add(json_row, "helloSend",
pim_ifp->pim_ifstat_hello_sent);
json_object_int_add(json_row, "hellosendFailed",
pim_ifp->pim_ifstat_hello_sendfail);
json_object_int_add(json_row, "helloGenerationId",
pim_ifp->pim_generation_id);
json_object_int_add(json_row, "flagMulticastLoop",
mloop);
json_object_int_add(
json_row, "effectivePropagationDelay",
pim_if_effective_propagation_delay_msec(ifp));
json_object_int_add(
json_row, "effectiveOverrideInterval",
pim_if_effective_override_interval_msec(ifp));
json_object_int_add(
json_row, "joinPruneOverrideInterval",
pim_if_jp_override_interval_msec(ifp));
json_object_int_add(
json_row, "propagationDelay",
pim_ifp->pim_propagation_delay_msec);
json_object_int_add(
json_row, "propagationDelayHighest",
pim_ifp->pim_neighbors_highest_propagation_delay_msec);
json_object_int_add(
json_row, "overrideInterval",
pim_ifp->pim_override_interval_msec);
json_object_int_add(
json_row, "overrideIntervalHighest",
pim_ifp->pim_neighbors_highest_override_interval_msec);
json_object_object_add(json, ifp->name, json_row);
} else {
vty_out(vty, "Interface : %s\n", ifp->name);
vty_out(vty, "State : %s\n",
if_is_up(ifp) ? "up" : "down");
if (pim_ifp->update_source.s_addr != INADDR_ANY) {
vty_out(vty, "Use Source : %s\n",
inet_ntoa(pim_ifp->update_source));
}
if (pim_ifp->sec_addr_list) {
char pbuf[PREFIX2STR_BUFFER];
vty_out(vty, "Address : %s (primary)\n",
inet_ntoa(ifaddr));
for (ALL_LIST_ELEMENTS_RO(
pim_ifp->sec_addr_list, sec_node,
sec_addr)) {
vty_out(vty, " %s\n",
prefix2str(&sec_addr->addr,
pbuf, sizeof(pbuf)));
}
} else {
vty_out(vty, "Address : %s\n",
inet_ntoa(ifaddr));
}
vty_out(vty, "\n");
// PIM neighbors
print_header = 1;
for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list,
neighnode, neigh)) {
if (print_header) {
vty_out(vty, "PIM Neighbors\n");
vty_out(vty, "-------------\n");
print_header = 0;
}
pim_inet4_dump("<src?>", neigh->source_addr,
neigh_src_str,
sizeof(neigh_src_str));
pim_time_uptime(uptime, sizeof(uptime),
now - neigh->creation);
pim_time_timer_to_hhmmss(expire, sizeof(expire),
neigh->t_expire_timer);
vty_out(vty,
"%-15s : up for %s, holdtime expires in %s\n",
neigh_src_str, uptime, expire);
}
if (!print_header) {
vty_out(vty, "\n");
vty_out(vty, "\n");
}
vty_out(vty, "Designated Router\n");
vty_out(vty, "-----------------\n");
vty_out(vty, "Address : %s\n", dr_str);
vty_out(vty, "Priority : %u(%d)\n",
pim_ifp->pim_dr_priority,
pim_ifp->pim_dr_num_nondrpri_neighbors);
vty_out(vty, "Uptime : %s\n", dr_uptime);
vty_out(vty, "Elections : %d\n",
pim_ifp->pim_dr_election_count);
vty_out(vty, "Changes : %d\n",
pim_ifp->pim_dr_election_changes);
vty_out(vty, "\n");
vty_out(vty, "\n");
// FHR
print_header = 1;
for (ALL_LIST_ELEMENTS_RO(pim->upstream_list, upnode,
up)) {
if (strcmp(ifp->name,
up->rpf.source_nexthop
.interface->name)
!= 0)
continue;
if (!(up->flags & PIM_UPSTREAM_FLAG_MASK_FHR))
continue;
if (print_header) {
vty_out(vty,
"FHR - First Hop Router\n");
vty_out(vty,
"----------------------\n");
print_header = 0;
}
pim_inet4_dump("<src?>", up->sg.src, src_str,
sizeof(src_str));
pim_inet4_dump("<grp?>", up->sg.grp, grp_str,
sizeof(grp_str));
pim_time_uptime(uptime, sizeof(uptime),
now - up->state_transition);
vty_out(vty,
"%s : %s is a source, uptime is %s\n",
grp_str, src_str, uptime);
}
if (!print_header) {
vty_out(vty, "\n");
vty_out(vty, "\n");
}
vty_out(vty, "Hellos\n");
vty_out(vty, "------\n");
vty_out(vty, "Period : %d\n",
pim_ifp->pim_hello_period);
vty_out(vty, "Timer : %s\n", hello_timer);
vty_out(vty, "StatStart : %s\n", stat_uptime);
vty_out(vty, "Receive : %d\n",
pim_ifp->pim_ifstat_hello_recv);
vty_out(vty, "Receive Failed : %d\n",
pim_ifp->pim_ifstat_hello_recvfail);
vty_out(vty, "Send : %d\n",
pim_ifp->pim_ifstat_hello_sent);
vty_out(vty, "Send Failed : %d\n",
pim_ifp->pim_ifstat_hello_sendfail);
vty_out(vty, "Generation ID : %08x\n",
pim_ifp->pim_generation_id);
vty_out(vty, "\n");
vty_out(vty, "\n");
pim_print_ifp_flags(vty, ifp, mloop);
vty_out(vty, "Join Prune Interval\n");
vty_out(vty, "-------------------\n");
vty_out(vty, "LAN Delay : %s\n",
pim_if_lan_delay_enabled(ifp) ? "yes" : "no");
vty_out(vty, "Effective Propagation Delay : %d msec\n",
pim_if_effective_propagation_delay_msec(ifp));
vty_out(vty, "Effective Override Interval : %d msec\n",
pim_if_effective_override_interval_msec(ifp));
vty_out(vty, "Join Prune Override Interval : %d msec\n",
pim_if_jp_override_interval_msec(ifp));
vty_out(vty, "\n");
vty_out(vty, "\n");
vty_out(vty, "LAN Prune Delay\n");
vty_out(vty, "---------------\n");
vty_out(vty, "Propagation Delay : %d msec\n",
pim_ifp->pim_propagation_delay_msec);
vty_out(vty, "Propagation Delay (Highest) : %d msec\n",
pim_ifp->pim_neighbors_highest_propagation_delay_msec);
vty_out(vty, "Override Interval : %d msec\n",
pim_ifp->pim_override_interval_msec);
vty_out(vty, "Override Interval (Highest) : %d msec\n",
pim_ifp->pim_neighbors_highest_override_interval_msec);
vty_out(vty, "\n");
vty_out(vty, "\n");
}
}
if (uj) {
vty_out(vty, "%s\n", json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
} else {
if (!found_ifname)
vty_out(vty, "%% No such interface\n");
}
}
static void igmp_show_statistics(struct pim_instance *pim, struct vty *vty,
const char *ifname, bool 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,
bool uj)
{
struct interface *ifp;
struct listnode *upnode;
struct pim_interface *pim_ifp;
struct pim_upstream *up;
int fhr = 0;
int pim_nbrs = 0;
int pim_ifchannels = 0;
json_object *json = NULL;
json_object *json_row = NULL;
json_object *json_tmp;
json = json_object_new_object();
FOR_ALL_INTERFACES (pim->vrf, ifp) {
pim_ifp = ifp->info;
if (!pim_ifp)
continue;
pim_nbrs = pim_ifp->pim_neighbor_list->count;
pim_ifchannels = pim_if_ifchannel_count(pim_ifp);
fhr = 0;
for (ALL_LIST_ELEMENTS_RO(pim->upstream_list, upnode, up))
if (ifp == up->rpf.source_nexthop.interface)
if (up->flags & PIM_UPSTREAM_FLAG_MASK_FHR)
fhr++;
json_row = json_object_new_object();
json_object_pim_ifp_add(json_row, ifp);
json_object_int_add(json_row, "pimNeighbors", pim_nbrs);
json_object_int_add(json_row, "pimIfChannels", pim_ifchannels);
json_object_int_add(json_row, "firstHopRouterCount", fhr);
json_object_string_add(json_row, "pimDesignatedRouter",
inet_ntoa(pim_ifp->pim_dr_addr));
if (pim_ifp->pim_dr_addr.s_addr
== pim_ifp->primary_address.s_addr)
json_object_boolean_true_add(
json_row, "pimDesignatedRouterLocal");
json_object_object_add(json, ifp->name, json_row);
}
if (uj) {
vty_out(vty, "%s\n", json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
} else {
vty_out(vty,
"Interface State Address PIM Nbrs PIM DR FHR IfChannels\n");
json_object_object_foreach(json, key, val)
{
vty_out(vty, "%-9s ", key);
json_object_object_get_ex(val, "state", &json_tmp);
vty_out(vty, "%5s ", json_object_get_string(json_tmp));
json_object_object_get_ex(val, "address", &json_tmp);
vty_out(vty, "%15s ",
json_object_get_string(json_tmp));
json_object_object_get_ex(val, "pimNeighbors",
&json_tmp);
vty_out(vty, "%8d ", json_object_get_int(json_tmp));
if (json_object_object_get_ex(
val, "pimDesignatedRouterLocal",
&json_tmp)) {
vty_out(vty, "%15s ", "local");
} else {
json_object_object_get_ex(
val, "pimDesignatedRouter", &json_tmp);
vty_out(vty, "%15s ",
json_object_get_string(json_tmp));
}
json_object_object_get_ex(val, "firstHopRouter",
&json_tmp);
vty_out(vty, "%3d ", json_object_get_int(json_tmp));
json_object_object_get_ex(val, "pimIfChannels",
&json_tmp);
vty_out(vty, "%9d\n", json_object_get_int(json_tmp));
}
}
json_object_free(json);
}
static void pim_show_interface_traffic(struct pim_instance *pim,
struct vty *vty, bool uj)
{
struct interface *ifp = NULL;
struct pim_interface *pim_ifp = NULL;
json_object *json = NULL;
json_object *json_row = NULL;
if (uj)
json = json_object_new_object();
else {
vty_out(vty, "\n");
vty_out(vty, "%-12s%-17s%-17s%-17s%-17s%-17s%-17s\n",
"Interface", " HELLO", " JOIN", " PRUNE",
" REGISTER", " REGISTER-STOP", " ASSERT");
vty_out(vty, "%-10s%-18s%-17s%-17s%-17s%-17s%-17s\n", "",
" Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
" Rx/Tx", " Rx/Tx");
vty_out(vty,
"---------------------------------------------------------------------------------------------------------------\n");
}
FOR_ALL_INTERFACES (pim->vrf, ifp) {
pim_ifp = ifp->info;
if (!pim_ifp)
continue;
if (pim_ifp->pim_sock_fd < 0)
continue;
if (uj) {
json_row = json_object_new_object();
json_object_pim_ifp_add(json_row, ifp);
json_object_int_add(json_row, "helloRx",
pim_ifp->pim_ifstat_hello_recv);
json_object_int_add(json_row, "helloTx",
pim_ifp->pim_ifstat_hello_sent);
json_object_int_add(json_row, "joinRx",
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, "registerRx",
pim_ifp->pim_ifstat_reg_recv);
json_object_int_add(json_row, "registerTx",
pim_ifp->pim_ifstat_reg_recv);
json_object_int_add(json_row, "registerStopRx",
pim_ifp->pim_ifstat_reg_stop_recv);
json_object_int_add(json_row, "registerStopTx",
pim_ifp->pim_ifstat_reg_stop_send);
json_object_int_add(json_row, "assertRx",
pim_ifp->pim_ifstat_assert_recv);
json_object_int_add(json_row, "assertTx",
pim_ifp->pim_ifstat_assert_send);
json_object_object_add(json, ifp->name, json_row);
} else {
vty_out(vty,
"%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u \n",
ifp->name, pim_ifp->pim_ifstat_hello_recv,
pim_ifp->pim_ifstat_hello_sent,
pim_ifp->pim_ifstat_join_recv,
pim_ifp->pim_ifstat_join_send,
pim_ifp->pim_ifstat_prune_recv,
pim_ifp->pim_ifstat_prune_send,
pim_ifp->pim_ifstat_reg_recv,
pim_ifp->pim_ifstat_reg_send,
pim_ifp->pim_ifstat_reg_stop_recv,
pim_ifp->pim_ifstat_reg_stop_send,
pim_ifp->pim_ifstat_assert_recv,
pim_ifp->pim_ifstat_assert_send);
}
}
if (uj) {
vty_out(vty, "%s\n", json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
}
}
static void pim_show_interface_traffic_single(struct pim_instance *pim,
struct vty *vty,
const char *ifname, bool uj)
{
struct interface *ifp = NULL;
struct pim_interface *pim_ifp = NULL;
json_object *json = NULL;
json_object *json_row = NULL;
uint8_t found_ifname = 0;
if (uj)
json = json_object_new_object();
else {
vty_out(vty, "\n");
vty_out(vty, "%-12s%-17s%-17s%-17s%-17s%-17s%-17s\n",
"Interface", " HELLO", " JOIN", " PRUNE",
" REGISTER", " REGISTER-STOP", " ASSERT");
vty_out(vty, "%-10s%-18s%-17s%-17s%-17s%-17s%-17s\n", "",
" Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
" Rx/Tx", " Rx/Tx");
vty_out(vty,
"---------------------------------------------------------------------------------------------------------------\n");
}
FOR_ALL_INTERFACES (pim->vrf, ifp) {
if (strcmp(ifname, ifp->name))
continue;
pim_ifp = ifp->info;
if (!pim_ifp)
continue;
if (pim_ifp->pim_sock_fd < 0)
continue;
found_ifname = 1;
if (uj) {
json_row = json_object_new_object();
json_object_pim_ifp_add(json_row, ifp);
json_object_int_add(json_row, "helloRx",
pim_ifp->pim_ifstat_hello_recv);
json_object_int_add(json_row, "helloTx",
pim_ifp->pim_ifstat_hello_sent);
json_object_int_add(json_row, "joinRx",
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, "registerRx",
pim_ifp->pim_ifstat_reg_recv);
json_object_int_add(json_row, "registerTx",
pim_ifp->pim_ifstat_reg_recv);
json_object_int_add(json_row, "registerStopRx",
pim_ifp->pim_ifstat_reg_stop_recv);
json_object_int_add(json_row, "registerStopTx",
pim_ifp->pim_ifstat_reg_stop_send);
json_object_int_add(json_row, "assertRx",
pim_ifp->pim_ifstat_assert_recv);
json_object_int_add(json_row, "assertTx",
pim_ifp->pim_ifstat_assert_send);
json_object_object_add(json, ifp->name, json_row);
} else {
vty_out(vty,
"%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u \n",
ifp->name, pim_ifp->pim_ifstat_hello_recv,
pim_ifp->pim_ifstat_hello_sent,
pim_ifp->pim_ifstat_join_recv,
pim_ifp->pim_ifstat_join_send,
pim_ifp->pim_ifstat_prune_recv,
pim_ifp->pim_ifstat_prune_send,
pim_ifp->pim_ifstat_reg_recv,
pim_ifp->pim_ifstat_reg_send,
pim_ifp->pim_ifstat_reg_stop_recv,
pim_ifp->pim_ifstat_reg_stop_send,
pim_ifp->pim_ifstat_assert_recv,
pim_ifp->pim_ifstat_assert_send);
}
}
if (uj) {
vty_out(vty, "%s\n", json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
} else {
if (!found_ifname)
vty_out(vty, "%% No such interface\n");
}
}
static void pim_show_join_helper(struct vty *vty, struct pim_interface *pim_ifp,
struct pim_ifchannel *ch, json_object *json,
time_t now, bool uj)
{
char ch_src_str[INET_ADDRSTRLEN];
char ch_grp_str[INET_ADDRSTRLEN];
json_object *json_iface = NULL;
json_object *json_row = NULL;
json_object *json_grp = NULL;
struct in_addr ifaddr;
char uptime[10];
char expire[10];
char prune[10];
ifaddr = pim_ifp->primary_address;
pim_inet4_dump("<ch_src?>", ch->sg.src, ch_src_str, sizeof(ch_src_str));
pim_inet4_dump("<ch_grp?>", ch->sg.grp, ch_grp_str, sizeof(ch_grp_str));
pim_time_uptime_begin(uptime, sizeof(uptime), now, ch->ifjoin_creation);
pim_time_timer_to_mmss(expire, sizeof(expire),
ch->t_ifjoin_expiry_timer);
pim_time_timer_to_mmss(prune, sizeof(prune),
ch->t_ifjoin_prune_pending_timer);
if (uj) {
json_object_object_get_ex(json, ch->interface->name,
&json_iface);
if (!json_iface) {
json_iface = json_object_new_object();
json_object_pim_ifp_add(json_iface, ch->interface);
json_object_object_add(json, ch->interface->name,
json_iface);
}
json_row = json_object_new_object();
json_object_string_add(json_row, "source", ch_src_str);
json_object_string_add(json_row, "group", ch_grp_str);
json_object_string_add(json_row, "upTime", uptime);
json_object_string_add(json_row, "expire", expire);
json_object_string_add(json_row, "prune", prune);
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))
json_object_int_add(json_row, "SGRpt", 1);
json_object_object_get_ex(json_iface, ch_grp_str, &json_grp);
if (!json_grp) {
json_grp = json_object_new_object();
json_object_object_add(json_grp, ch_src_str, json_row);
json_object_object_add(json_iface, ch_grp_str,
json_grp);
} else
json_object_object_add(json_grp, ch_src_str, json_row);
} else {
vty_out(vty, "%-9s %-15s %-15s %-15s %-10s %8s %-6s %5s\n",
ch->interface->name, inet_ntoa(ifaddr), ch_src_str,
ch_grp_str,
pim_ifchannel_ifjoin_name(ch->ifjoin_state, ch->flags),
uptime, expire, prune);
}
}
static void pim_show_join(struct pim_instance *pim, struct vty *vty, bool uj)
{
struct pim_interface *pim_ifp;
struct pim_ifchannel *ch;
struct interface *ifp;
time_t now;
json_object *json = NULL;
now = pim_time_monotonic_sec();
if (uj)
json = json_object_new_object();
else
vty_out(vty,
"Interface Address Source Group State Uptime Expire Prune\n");
FOR_ALL_INTERFACES (pim->vrf, ifp) {
pim_ifp = ifp->info;
if (!pim_ifp)
continue;
RB_FOREACH (ch, pim_ifchannel_rb, &pim_ifp->ifchannel_rb) {
pim_show_join_helper(vty, pim_ifp, ch, json, now, uj);
} /* scan interface channels */
}
if (uj) {
vty_out(vty, "%s\n", json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
}
}
static void pim_show_neighbors_single(struct pim_instance *pim, struct vty *vty,
const char *neighbor, bool uj)
{
struct listnode *neighnode;
struct interface *ifp;
struct pim_interface *pim_ifp;
struct pim_neighbor *neigh;
time_t now;
int found_neighbor = 0;
int option_address_list;
int option_dr_priority;
int option_generation_id;
int option_holdtime;
int option_lan_prune_delay;
int option_t_bit;
char uptime[10];
char expire[10];
char neigh_src_str[INET_ADDRSTRLEN];
json_object *json = NULL;
json_object *json_ifp = NULL;
json_object *json_row = NULL;
now = pim_time_monotonic_sec();
if (uj)
json = json_object_new_object();
FOR_ALL_INTERFACES (pim->vrf, ifp) {
pim_ifp = ifp->info;
if (!pim_ifp)
continue;
if (pim_ifp->pim_sock_fd < 0)
continue;
for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, neighnode,
neigh)) {
pim_inet4_dump("<src?>", neigh->source_addr,
neigh_src_str, sizeof(neigh_src_str));
/*
* The user can specify either the interface name or the
* PIM neighbor IP.
* If this pim_ifp matches neither then skip.
*/
if (strcmp(neighbor, "detail")
&& strcmp(neighbor, ifp->name)
&& strcmp(neighbor, neigh_src_str))
continue;
found_neighbor = 1;
pim_time_uptime(uptime, sizeof(uptime),
now - neigh->creation);
pim_time_timer_to_hhmmss(expire, sizeof(expire),
neigh->t_expire_timer);
option_address_list = 0;
option_dr_priority = 0;
option_generation_id = 0;
option_holdtime = 0;
option_lan_prune_delay = 0;
option_t_bit = 0;
if (PIM_OPTION_IS_SET(neigh->hello_options,
PIM_OPTION_MASK_ADDRESS_LIST))
option_address_list = 1;
if (PIM_OPTION_IS_SET(neigh->hello_options,
PIM_OPTION_MASK_DR_PRIORITY))
option_dr_priority = 1;
if (PIM_OPTION_IS_SET(neigh->hello_options,
PIM_OPTION_MASK_GENERATION_ID))
option_generation_id = 1;
if (PIM_OPTION_IS_SET(neigh->hello_options,
PIM_OPTION_MASK_HOLDTIME))
option_holdtime = 1;
if (PIM_OPTION_IS_SET(neigh->hello_options,
PIM_OPTION_MASK_LAN_PRUNE_DELAY))
option_lan_prune_delay = 1;
if (PIM_OPTION_IS_SET(
neigh->hello_options,
PIM_OPTION_MASK_CAN_DISABLE_JOIN_SUPPRESSION))
option_t_bit = 1;
if (uj) {
/* Does this ifp live in json? If not create
* it. */
json_object_object_get_ex(json, ifp->name,
&json_ifp);
if (!json_ifp) {
json_ifp = json_object_new_object();
json_object_pim_ifp_add(json_ifp, ifp);
json_object_object_add(json, ifp->name,
json_ifp);
}
json_row = json_object_new_object();
json_object_string_add(json_row, "interface",
ifp->name);
json_object_string_add(json_row, "address",
neigh_src_str);
json_object_string_add(json_row, "upTime",
uptime);
json_object_string_add(json_row, "holdtime",
expire);
json_object_int_add(json_row, "drPriority",
neigh->dr_priority);
json_object_int_add(json_row, "generationId",
neigh->generation_id);
if (option_address_list)
json_object_boolean_true_add(
json_row,
"helloOptionAddressList");
if (option_dr_priority)
json_object_boolean_true_add(
json_row,
"helloOptionDrPriority");
if (option_generation_id)
json_object_boolean_true_add(
json_row,
"helloOptionGenerationId");
if (option_holdtime)
json_object_boolean_true_add(
json_row,
"helloOptionHoldtime");
if (option_lan_prune_delay)
json_object_boolean_true_add(
json_row,
"helloOptionLanPruneDelay");
if (option_t_bit)
json_object_boolean_true_add(
json_row, "helloOptionTBit");
json_object_object_add(json_ifp, neigh_src_str,
json_row);
} else {
vty_out(vty, "Interface : %s\n", ifp->name);
vty_out(vty, "Neighbor : %s\n", neigh_src_str);
vty_out(vty,
" Uptime : %s\n",
uptime);
vty_out(vty,
" Holdtime : %s\n",
expire);
vty_out(vty,
" DR Priority : %d\n",
neigh->dr_priority);
vty_out(vty,
" Generation ID : %08x\n",
neigh->generation_id);
vty_out(vty,
" Override Interval (msec) : %d\n",
neigh->override_interval_msec);
vty_out(vty,
" Propagation Delay (msec) : %d\n",
neigh->propagation_delay_msec);
vty_out(vty,
" Hello Option - Address List : %s\n",
option_address_list ? "yes" : "no");
vty_out(vty,
" Hello Option - DR Priority : %s\n",
option_dr_priority ? "yes" : "no");
vty_out(vty,
" Hello Option - Generation ID : %s\n",
option_generation_id ? "yes" : "no");
vty_out(vty,
" Hello Option - Holdtime : %s\n",
option_holdtime ? "yes" : "no");
vty_out(vty,
" Hello Option - LAN Prune Delay : %s\n",
option_lan_prune_delay ? "yes" : "no");
vty_out(vty,
" Hello Option - T-bit : %s\n",
option_t_bit ? "yes" : "no");
pim_bfd_show_info(vty, neigh->bfd_info,
json_ifp, uj, 0);
vty_out(vty, "\n");
}
}
}
if (uj) {
vty_out(vty, "%s\n", json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
} else {
{
if (!found_neighbor)
vty_out(vty,
"%% No such interface or neighbor\n");
}
}
}
static void pim_show_state(struct pim_instance *pim, struct vty *vty,
const char *src_or_group, const char *group, bool uj)
{
struct channel_oil *c_oil;
struct listnode *node;
json_object *json = NULL;
json_object *json_group = NULL;
json_object *json_ifp_in = NULL;
json_object *json_ifp_out = NULL;
json_object *json_source = NULL;
time_t now;
int first_oif;
now = pim_time_monotonic_sec();
if (uj) {
json = json_object_new_object();
} else {
vty_out(vty,
"Codes: J -> Pim Join, I -> IGMP Report, S -> Source, * -> Inherited from (*,G)");
vty_out(vty,
"\nInstalled Source Group IIF OIL\n");
}
for (ALL_LIST_ELEMENTS_RO(pim->channel_oil_list, node, c_oil)) {
char grp_str[INET_ADDRSTRLEN];
char src_str[INET_ADDRSTRLEN];
char in_ifname[INTERFACE_NAMSIZ + 1];
char out_ifname[INTERFACE_NAMSIZ + 1];
int oif_vif_index;
struct interface *ifp_in;
first_oif = 1;
pim_inet4_dump("<group?>", c_oil->oil.mfcc_mcastgrp, grp_str,
sizeof(grp_str));
pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, src_str,
sizeof(src_str));
ifp_in = pim_if_find_by_vif_index(pim, c_oil->oil.mfcc_parent);
if (ifp_in)
strcpy(in_ifname, ifp_in->name);
else
strcpy(in_ifname, "<iif?>");
if (src_or_group) {
if (strcmp(src_or_group, src_str)
&& strcmp(src_or_group, grp_str))
continue;
if (group && strcmp(group, grp_str))
continue;
}
if (uj) {
/* Find the group, create it if it doesn't exist */
json_object_object_get_ex(json, grp_str, &json_group);
if (!json_group) {
json_group = json_object_new_object();
json_object_object_add(json, grp_str,
json_group);
}
/* Find the source nested under the group, create it if
* it doesn't exist */
json_object_object_get_ex(json_group, src_str,
&json_source);
if (!json_source) {
json_source = json_object_new_object();
json_object_object_add(json_group, src_str,
json_source);
}
/* Find the inbound interface nested under the source,
* create it if it doesn't exist */
json_object_object_get_ex(json_source, in_ifname,
&json_ifp_in);
if (!json_ifp_in) {
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, "RefCount",
c_oil->oil_ref_count);
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, "LastUsed",
c_oil->cc.lastused);
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,
"WrongInterface",
c_oil->cc.wrong_if);
}
} else {
vty_out(vty, "%-9d %-15s %-15s %-7s ",
c_oil->installed, src_str, grp_str,
in_ifname);
}
for (oif_vif_index = 0; oif_vif_index < MAXVIFS;
++oif_vif_index) {
struct interface *ifp_out;
char oif_uptime[10];
int ttl;
ttl = c_oil->oil.mfcc_ttls[oif_vif_index];
if (ttl < 1)
continue;
ifp_out = pim_if_find_by_vif_index(pim, oif_vif_index);
pim_time_uptime(
oif_uptime, sizeof(oif_uptime),
now - c_oil->oif_creation[oif_vif_index]);
if (ifp_out)
strcpy(out_ifname, ifp_out->name);
else
strcpy(out_ifname, "<oif?>");
if (uj) {
json_ifp_out = json_object_new_object();
json_object_string_add(json_ifp_out, "source",
src_str);
json_object_string_add(json_ifp_out, "group",
grp_str);
json_object_string_add(json_ifp_out,
"inboundInterface",
in_ifname);
json_object_string_add(json_ifp_out,
"outboundInterface",
out_ifname);
json_object_int_add(json_ifp_out, "installed",
c_oil->installed);
json_object_object_add(json_ifp_in, out_ifname,
json_ifp_out);
} else {
if (first_oif) {
first_oif = 0;
vty_out(vty, "%s(%c%c%c%c)", out_ifname,
(c_oil->oif_flags[oif_vif_index]
& PIM_OIF_FLAG_PROTO_IGMP)
? 'I'
: ' ',
(c_oil->oif_flags[oif_vif_index]
& PIM_OIF_FLAG_PROTO_PIM)
? 'J'
: ' ',
(c_oil->oif_flags[oif_vif_index]
& PIM_OIF_FLAG_PROTO_SOURCE)
? 'S'
: ' ',
(c_oil->oif_flags[oif_vif_index]
& PIM_OIF_FLAG_PROTO_STAR)
? '*'
: ' ');
} else
vty_out(vty, ", %s(%c%c%c%c)",
out_ifname,
(c_oil->oif_flags[oif_vif_index]
& PIM_OIF_FLAG_PROTO_IGMP)
? 'I'
: ' ',
(c_oil->oif_flags[oif_vif_index]
& PIM_OIF_FLAG_PROTO_PIM)
? 'J'
: ' ',
(c_oil->oif_flags[oif_vif_index]
& PIM_OIF_FLAG_PROTO_SOURCE)
? 'S'
: ' ',
(c_oil->oif_flags[oif_vif_index]
& PIM_OIF_FLAG_PROTO_STAR)
? '*'
: ' ');
}
}
if (!uj)
vty_out(vty, "\n");
}
if (uj) {
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, "\n");
}
}
static void pim_show_neighbors(struct pim_instance *pim, struct vty *vty,
bool uj)
{
struct listnode *neighnode;
struct interface *ifp;
struct pim_interface *pim_ifp;
struct pim_neighbor *neigh;
time_t now;
char uptime[10];
char expire[10];
char neigh_src_str[INET_ADDRSTRLEN];
json_object *json = NULL;
json_object *json_ifp_rows = NULL;
json_object *json_row = NULL;
now = pim_time_monotonic_sec();
if (uj) {
json = json_object_new_object();
} else {
vty_out(vty,
"Interface Neighbor Uptime Holdtime DR Pri\n");
}
FOR_ALL_INTERFACES (pim->vrf, ifp) {
pim_ifp = ifp->info;
if (!pim_ifp)
continue;
if (pim_ifp->pim_sock_fd < 0)
continue;
if (uj)
json_ifp_rows = json_object_new_object();
for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, neighnode,
neigh)) {
pim_inet4_dump("<src?>", neigh->source_addr,
neigh_src_str, sizeof(neigh_src_str));
pim_time_uptime(uptime, sizeof(uptime),
now - neigh->creation);
pim_time_timer_to_hhmmss(expire, sizeof(expire),
neigh->t_expire_timer);
if (uj) {
json_row = json_object_new_object();
json_object_string_add(json_row, "interface",
ifp->name);
json_object_string_add(json_row, "neighbor",
neigh_src_str);
json_object_string_add(json_row, "upTime",
uptime);
json_object_string_add(json_row, "holdTime",
expire);
json_object_int_add(json_row, "holdTimeMax",
neigh->holdtime);
json_object_int_add(json_row, "drPriority",
neigh->dr_priority);
json_object_object_add(json_ifp_rows,
neigh_src_str, json_row);
} else {
vty_out(vty, "%-9s %15s %8s %8s %6d\n",
ifp->name, neigh_src_str, uptime,
expire, neigh->dr_priority);
}
}
if (uj) {
json_object_object_add(json, ifp->name, json_ifp_rows);
json_ifp_rows = NULL;
}
}
if (uj) {
vty_out(vty, "%s\n", json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
}
}
static void pim_show_neighbors_secondary(struct pim_instance *pim,
struct vty *vty)
{
struct interface *ifp;
vty_out(vty,
"Interface Address Neighbor Secondary \n");
FOR_ALL_INTERFACES (pim->vrf, ifp) {
struct pim_interface *pim_ifp;
struct in_addr ifaddr;
struct listnode *neighnode;
struct pim_neighbor *neigh;
pim_ifp = ifp->info;
if (!pim_ifp)
continue;
if (pim_ifp->pim_sock_fd < 0)
continue;
ifaddr = pim_ifp->primary_address;
for (ALL_LIST_ELEMENTS_RO(pim_ifp->pim_neighbor_list, neighnode,
neigh)) {
char neigh_src_str[INET_ADDRSTRLEN];
struct listnode *prefix_node;
struct prefix *p;
if (!neigh->prefix_list)
continue;
pim_inet4_dump("<src?>", neigh->source_addr,
neigh_src_str, sizeof(neigh_src_str));
for (ALL_LIST_ELEMENTS_RO(neigh->prefix_list,
prefix_node, p)) {
char neigh_sec_str[PREFIX2STR_BUFFER];
prefix2str(p, neigh_sec_str,
sizeof(neigh_sec_str));
vty_out(vty, "%-9s %-15s %-15s %-15s\n",
ifp->name, inet_ntoa(ifaddr),
neigh_src_str, neigh_sec_str);
}
}
}
}
static void json_object_pim_upstream_add(json_object *json,
struct pim_upstream *up)
{
if (up->flags & PIM_UPSTREAM_FLAG_MASK_DR_JOIN_DESIRED)
json_object_boolean_true_add(json, "drJoinDesired");
if (up->flags & PIM_UPSTREAM_FLAG_MASK_DR_JOIN_DESIRED_UPDATED)
json_object_boolean_true_add(json, "drJoinDesiredUpdated");
if (up->flags & PIM_UPSTREAM_FLAG_MASK_FHR)
json_object_boolean_true_add(json, "firstHopRouter");
if (up->flags & PIM_UPSTREAM_FLAG_MASK_SRC_IGMP)
json_object_boolean_true_add(json, "sourceIgmp");
if (up->flags & PIM_UPSTREAM_FLAG_MASK_SRC_PIM)
json_object_boolean_true_add(json, "sourcePim");
if (up->flags & PIM_UPSTREAM_FLAG_MASK_SRC_STREAM)
json_object_boolean_true_add(json, "sourceStream");
/* XXX: need to print ths flag in the plain text display as well */
if (up->flags & PIM_UPSTREAM_FLAG_MASK_SRC_MSDP)
json_object_boolean_true_add(json, "sourceMsdp");
}
static const char *
pim_upstream_state2brief_str(enum pim_upstream_state join_state,
char *state_str)
{
switch (join_state) {
case PIM_UPSTREAM_NOTJOINED:
strcpy(state_str, "NotJ");
break;
case PIM_UPSTREAM_JOINED:
strcpy(state_str, "J");
break;
default:
strcpy(state_str, "Unk");
}
return state_str;
}
static const char *pim_reg_state2brief_str(enum pim_reg_state reg_state,
char *state_str)
{
switch (reg_state) {
case PIM_REG_NOINFO:
strcpy(state_str, "RegNI");
break;
case PIM_REG_JOIN:
strcpy(state_str, "RegJ");
break;
case PIM_REG_JOIN_PENDING:
case PIM_REG_PRUNE:
strcpy(state_str, "RegP");
break;
default:
strcpy(state_str, "Unk");
}
return state_str;
}
static void pim_show_upstream(struct pim_instance *pim, struct vty *vty,
bool uj)
{
struct listnode *upnode;
struct pim_upstream *up;
time_t now;
json_object *json = NULL;
json_object *json_group = NULL;
json_object *json_row = NULL;
now = pim_time_monotonic_sec();
if (uj)
json = json_object_new_object();
else
vty_out(vty,
"Iif Source Group State Uptime JoinTimer RSTimer KATimer RefCnt\n");
for (ALL_LIST_ELEMENTS_RO(pim->upstream_list, upnode, up)) {
char src_str[INET_ADDRSTRLEN];
char grp_str[INET_ADDRSTRLEN];
char uptime[10];
char join_timer[10];
char rs_timer[10];
char ka_timer[10];
char msdp_reg_timer[10];
char state_str[PIM_REG_STATE_STR_LEN];
pim_inet4_dump("<src?>", up->sg.src, src_str, sizeof(src_str));
pim_inet4_dump("<grp?>", up->sg.grp, grp_str, sizeof(grp_str));
pim_time_uptime(uptime, sizeof(uptime),
now - up->state_transition);
pim_time_timer_to_hhmmss(join_timer, sizeof(join_timer),
up->t_join_timer);
/*
* If the upstream is not dummy and it has a J/P timer for the
* neighbor display that
*/
if (!up->t_join_timer && up->rpf.source_nexthop.interface) {
struct pim_neighbor *nbr;
nbr = pim_neighbor_find(
up->rpf.source_nexthop.interface,
up->rpf.rpf_addr.u.prefix4);
if (nbr)
pim_time_timer_to_hhmmss(join_timer,
sizeof(join_timer),
nbr->jp_timer);
}
pim_time_timer_to_hhmmss(rs_timer, sizeof(rs_timer),
up->t_rs_timer);
pim_time_timer_to_hhmmss(ka_timer, sizeof(ka_timer),
up->t_ka_timer);
pim_time_timer_to_hhmmss(msdp_reg_timer, sizeof(msdp_reg_timer),
up->t_msdp_reg_timer);
pim_upstream_state2brief_str(up->join_state, state_str);
if (up->reg_state != PIM_REG_NOINFO) {
char tmp_str[PIM_REG_STATE_STR_LEN];
sprintf(state_str + strlen(state_str), ",%s",
pim_reg_state2brief_str(up->reg_state,
tmp_str));
}
if (uj) {
json_object_object_get_ex(json, grp_str, &json_group);
if (!json_group) {
json_group = json_object_new_object();
json_object_object_add(json, grp_str,
json_group);
}
json_row = json_object_new_object();
json_object_pim_upstream_add(json_row, up);
json_object_string_add(
json_row, "inboundInterface",
up->rpf.source_nexthop.interface
? up->rpf.source_nexthop.interface->name
: "Unknown");
/*
* The RPF address we use is slightly different
* based upon what we are looking up.
* If we have a S, list that unless
* we are the FHR, else we just put
* the RP as the rpfAddress
*/
if (up->flags & PIM_UPSTREAM_FLAG_MASK_FHR
|| up->sg.src.s_addr == INADDR_ANY) {
char rpf[PREFIX_STRLEN];
struct pim_rpf *rpg;
rpg = RP(pim, up->sg.grp);
pim_inet4_dump("<rpf?>",
rpg->rpf_addr.u.prefix4, rpf,
sizeof(rpf));
json_object_string_add(json_row, "rpfAddress",
rpf);
} else {
json_object_string_add(json_row, "rpfAddress",
src_str);
}
json_object_string_add(json_row, "source", src_str);
json_object_string_add(json_row, "group", grp_str);
json_object_string_add(json_row, "state", state_str);
json_object_string_add(
json_row, "joinState",
pim_upstream_state2str(up->join_state));
json_object_string_add(
json_row, "regState",
pim_reg_state2str(up->reg_state, state_str));
json_object_string_add(json_row, "upTime", uptime);
json_object_string_add(json_row, "joinTimer",
join_timer);
json_object_string_add(json_row, "resetTimer",
rs_timer);
json_object_string_add(json_row, "keepaliveTimer",
ka_timer);
json_object_string_add(json_row, "msdpRegTimer",
msdp_reg_timer);
json_object_int_add(json_row, "refCount",
up->ref_count);
json_object_int_add(json_row, "sptBit", up->sptbit);
json_object_object_add(json_group, src_str, json_row);
} else {
vty_out(vty,
"%-10s%-15s %-15s %-11s %-8s %-9s %-9s %-9s %6d\n",
up->rpf.source_nexthop.interface
? up->rpf.source_nexthop.interface->name
: "Unknown",
src_str, grp_str, state_str, uptime, join_timer,
rs_timer, ka_timer, up->ref_count);
}
}
if (uj) {
vty_out(vty, "%s\n", json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
}
}
static void pim_show_join_desired_helper(struct pim_instance *pim,
struct vty *vty,
struct pim_interface *pim_ifp,
struct pim_ifchannel *ch,
json_object *json, bool uj)
{
struct pim_upstream *up = ch->upstream;
json_object *json_group = NULL;
char src_str[INET_ADDRSTRLEN];
char grp_str[INET_ADDRSTRLEN];
json_object *json_row = NULL;
pim_inet4_dump("<src?>", up->sg.src, src_str, sizeof(src_str));
pim_inet4_dump("<grp?>", up->sg.grp, grp_str, sizeof(grp_str));
if (uj) {
json_object_object_get_ex(json, grp_str, &json_group);
if (!json_group) {
json_group = json_object_new_object();
json_object_object_add(json, grp_str, json_group);
}
json_row = json_object_new_object();
json_object_pim_upstream_add(json_row, up);
json_object_string_add(json_row, "interface",
ch->interface->name);
json_object_string_add(json_row, "source", src_str);
json_object_string_add(json_row, "group", grp_str);
if (pim_macro_ch_lost_assert(ch))
json_object_boolean_true_add(json_row, "lostAssert");
if (pim_macro_chisin_joins(ch))
json_object_boolean_true_add(json_row, "joins");
if (pim_macro_chisin_pim_include(ch))
json_object_boolean_true_add(json_row, "pimInclude");
if (pim_upstream_evaluate_join_desired(pim, up))
json_object_boolean_true_add(json_row,
"evaluateJoinDesired");
json_object_object_add(json_group, src_str, json_row);
} else {
vty_out(vty, "%-9s %-15s %-15s %-10s %-5s %-10s %-11s %-6s\n",
ch->interface->name, src_str, grp_str,
pim_macro_ch_lost_assert(ch) ? "yes" : "no",
pim_macro_chisin_joins(ch) ? "yes" : "no",
pim_macro_chisin_pim_include(ch) ? "yes" : "no",
PIM_UPSTREAM_FLAG_TEST_DR_JOIN_DESIRED(up->flags)
? "yes"
: "no",
pim_upstream_evaluate_join_desired(pim, up) ? "yes"
: "no");
}
}
static void pim_show_join_desired(struct pim_instance *pim, struct vty *vty,
bool uj)
{
struct pim_interface *pim_ifp;
struct pim_ifchannel *ch;
struct interface *ifp;
json_object *json = NULL;
if (uj)
json = json_object_new_object();
else
vty_out(vty,
"Interface Source Group LostAssert Joins PimInclude JoinDesired EvalJD\n");
/* scan per-interface (S,G) state */
FOR_ALL_INTERFACES (pim->vrf, ifp) {
pim_ifp = ifp->info;
if (!pim_ifp)
continue;
RB_FOREACH (ch, pim_ifchannel_rb, &pim_ifp->ifchannel_rb) {
/* scan all interfaces */
pim_show_join_desired_helper(pim, vty, pim_ifp, ch,
json, uj);
}
}
if (uj) {
vty_out(vty, "%s\n", json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
}
}
static void pim_show_upstream_rpf(struct pim_instance *pim, struct vty *vty,
bool uj)
{
struct listnode *upnode;
struct pim_upstream *up;
json_object *json = NULL;
json_object *json_group = NULL;
json_object *json_row = NULL;
if (uj)
json = json_object_new_object();
else
vty_out(vty,
"Source Group RpfIface RibNextHop RpfAddress \n");
for (ALL_LIST_ELEMENTS_RO(pim->upstream_list, upnode, up)) {
char src_str[INET_ADDRSTRLEN];
char grp_str[INET_ADDRSTRLEN];
char rpf_nexthop_str[PREFIX_STRLEN];
char rpf_addr_str[PREFIX_STRLEN];
struct pim_rpf *rpf;
const char *rpf_ifname;
rpf = &up->rpf;
pim_inet4_dump("<src?>", up->sg.src, src_str, sizeof(src_str));
pim_inet4_dump("<grp?>", up->sg.grp, grp_str, sizeof(grp_str));
pim_addr_dump("<nexthop?>",
&rpf->source_nexthop.mrib_nexthop_addr,
rpf_nexthop_str, sizeof(rpf_nexthop_str));
pim_addr_dump("<rpf?>", &rpf->rpf_addr, rpf_addr_str,
sizeof(rpf_addr_str));
rpf_ifname = rpf->source_nexthop.interface ? rpf->source_nexthop.interface->name : "<ifname?>";
if (uj) {
json_object_object_get_ex(json, grp_str, &json_group);
if (!json_group) {
json_group = json_object_new_object();
json_object_object_add(json, grp_str,
json_group);
}
json_row = json_object_new_object();
json_object_pim_upstream_add(json_row, up);
json_object_string_add(json_row, "source", src_str);
json_object_string_add(json_row, "group", grp_str);
json_object_string_add(json_row, "rpfInterface",
rpf_ifname);
json_object_string_add(json_row, "ribNexthop",
rpf_nexthop_str);
json_object_string_add(json_row, "rpfAddress",
rpf_addr_str);
json_object_object_add(json_group, src_str, json_row);
} else {
vty_out(vty, "%-15s %-15s %-8s %-15s %-15s\n", src_str,
grp_str, rpf_ifname, rpf_nexthop_str,
rpf_addr_str);
}
}
if (uj) {
vty_out(vty, "%s\n", json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
}
}
static void show_rpf_refresh_stats(struct vty *vty, struct pim_instance *pim,
time_t now, json_object *json)
{
char refresh_uptime[10];
pim_time_uptime_begin(refresh_uptime, sizeof(refresh_uptime), now,
pim->rpf_cache_refresh_last);
if (json) {
json_object_int_add(json, "rpfCacheRefreshDelayMsecs",
router->rpf_cache_refresh_delay_msec);
json_object_int_add(
json, "rpfCacheRefreshTimer",
pim_time_timer_remain_msec(pim->rpf_cache_refresher));
json_object_int_add(json, "rpfCacheRefreshRequests",
pim->rpf_cache_refresh_requests);
json_object_int_add(json, "rpfCacheRefreshEvents",
pim->rpf_cache_refresh_events);
json_object_string_add(json, "rpfCacheRefreshLast",
refresh_uptime);
json_object_int_add(json, "nexthopLookups",
pim->nexthop_lookups);
json_object_int_add(json, "nexthopLookupsAvoided",
pim->nexthop_lookups_avoided);
} else {
vty_out(vty,
"RPF Cache Refresh Delay: %ld msecs\n"
"RPF Cache Refresh Timer: %ld msecs\n"
"RPF Cache Refresh Requests: %lld\n"
"RPF Cache Refresh Events: %lld\n"
"RPF Cache Refresh Last: %s\n"
"Nexthop Lookups: %lld\n"
"Nexthop Lookups Avoided: %lld\n",
router->rpf_cache_refresh_delay_msec,
pim_time_timer_remain_msec(pim->rpf_cache_refresher),
(long long)pim->rpf_cache_refresh_requests,
(long long)pim->rpf_cache_refresh_events,
refresh_uptime, (long long)pim->nexthop_lookups,
(long long)pim->nexthop_lookups_avoided);
}
}
static void show_scan_oil_stats(struct pim_instance *pim, struct vty *vty,
time_t now)
{
char uptime_scan_oil[10];
char uptime_mroute_add[10];
char uptime_mroute_del[10];
pim_time_uptime_begin(uptime_scan_oil, sizeof(uptime_scan_oil), now,
pim->scan_oil_last);
pim_time_uptime_begin(uptime_mroute_add, sizeof(uptime_mroute_add), now,
pim->mroute_add_last);
pim_time_uptime_begin(uptime_mroute_del, sizeof(uptime_mroute_del), now,
pim->mroute_del_last);
vty_out(vty,
"Scan OIL - Last: %s Events: %lld\n"
"MFC Add - Last: %s Events: %lld\n"
"MFC Del - Last: %s Events: %lld\n",
uptime_scan_oil, (long long)pim->scan_oil_events,
uptime_mroute_add, (long long)pim->mroute_add_events,
uptime_mroute_del, (long long)pim->mroute_del_events);
}
static void pim_show_rpf(struct pim_instance *pim, struct vty *vty, bool uj)
{
struct listnode *up_node;
struct pim_upstream *up;
time_t now = pim_time_monotonic_sec();
json_object *json = NULL;
json_object *json_group = NULL;
json_object *json_row = NULL;
if (uj) {
json = json_object_new_object();
show_rpf_refresh_stats(vty, pim, now, json);
} else {
show_rpf_refresh_stats(vty, pim, now, json);
vty_out(vty, "\n");
vty_out(vty,
"Source Group RpfIface RpfAddress RibNextHop Metric Pref\n");
}
for (ALL_LIST_ELEMENTS_RO(pim->upstream_list, up_node, up)) {
char src_str[INET_ADDRSTRLEN];
char grp_str[INET_ADDRSTRLEN];
char rpf_addr_str[PREFIX_STRLEN];
char rib_nexthop_str[PREFIX_STRLEN];
const char *rpf_ifname;
struct pim_rpf *rpf = &up->rpf;
pim_inet4_dump("<src?>", up->sg.src, src_str, sizeof(src_str));
pim_inet4_dump("<grp?>", up->sg.grp, grp_str, sizeof(grp_str));
pim_addr_dump("<rpf?>", &rpf->rpf_addr, rpf_addr_str,
sizeof(rpf_addr_str));
pim_addr_dump("<nexthop?>",
&rpf->source_nexthop.mrib_nexthop_addr,
rib_nexthop_str, sizeof(rib_nexthop_str));
rpf_ifname = rpf->source_nexthop.interface ? rpf->source_nexthop.interface->name : "<ifname?>";
if (uj) {
json_object_object_get_ex(json, grp_str, &json_group);
if (!json_group) {
json_group = json_object_new_object();
json_object_object_add(json, grp_str,
json_group);
}
json_row = json_object_new_object();
json_object_string_add(json_row, "source", src_str);
json_object_string_add(json_row, "group", grp_str);
json_object_string_add(json_row, "rpfInterface",
rpf_ifname);
json_object_string_add(json_row, "rpfAddress",
rpf_addr_str);
json_object_string_add(json_row, "ribNexthop",
rib_nexthop_str);
json_object_int_add(
json_row, "routeMetric",
rpf->source_nexthop.mrib_route_metric);
json_object_int_add(
json_row, "routePreference",
rpf->source_nexthop.mrib_metric_preference);
json_object_object_add(json_group, src_str, json_row);
} else {
vty_out(vty, "%-15s %-15s %-8s %-15s %-15s %6d %4d\n",
src_str, grp_str, rpf_ifname, rpf_addr_str,
rib_nexthop_str,
rpf->source_nexthop.mrib_route_metric,
rpf->source_nexthop.mrib_metric_preference);
}
}
if (uj) {
vty_out(vty, "%s\n", json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
}
}
struct pnc_cache_walk_data {
struct vty *vty;
struct pim_instance *pim;
};
static int pim_print_pnc_cache_walkcb(struct hash_bucket *bucket, void *arg)
{
struct pim_nexthop_cache *pnc = bucket->data;
struct pnc_cache_walk_data *cwd = arg;
struct vty *vty = cwd->vty;
struct pim_instance *pim = cwd->pim;
struct nexthop *nh_node = NULL;
ifindex_t first_ifindex;
struct interface *ifp = NULL;
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_id);
vty_out(vty, "%-15s ", inet_ntoa(pnc->rpf.rpf_addr.u.prefix4));
vty_out(vty, "%-14s ", ifp ? ifp->name : "NULL");
vty_out(vty, "%s ", inet_ntoa(nh_node->gate.ipv4));
vty_out(vty, "\n");
}
return CMD_SUCCESS;
}
static void pim_show_nexthop(struct pim_instance *pim, struct vty *vty)
{
struct pnc_cache_walk_data cwd;
cwd.vty = vty;
cwd.pim = pim;
vty_out(vty, "Number of registered addresses: %lu\n",
pim->rpf_hash->count);
vty_out(vty, "Address Interface Nexthop\n");
vty_out(vty, "-------------------------------------------\n");
hash_walk(pim->rpf_hash, pim_print_pnc_cache_walkcb, &cwd);
}
static void igmp_show_groups(struct pim_instance *pim, struct vty *vty, bool uj)
{
struct interface *ifp;
time_t now;
json_object *json = NULL;
json_object *json_iface = NULL;
json_object *json_row = NULL;
now = pim_time_monotonic_sec();
if (uj)
json = json_object_new_object();
else
vty_out(vty,
"Interface Address Group Mode Timer Srcs V Uptime \n");
/* scan interfaces */
FOR_ALL_INTERFACES (pim->vrf, ifp) {
struct pim_interface *pim_ifp = ifp->info;
struct listnode *sock_node;
struct igmp_sock *igmp;
if (!pim_ifp)
continue;
/* scan igmp sockets */
for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node,
igmp)) {
char ifaddr_str[INET_ADDRSTRLEN];
struct listnode *grpnode;
struct igmp_group *grp;
pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str,
sizeof(ifaddr_str));
/* scan igmp groups */
for (ALL_LIST_ELEMENTS_RO(igmp->igmp_group_list,
grpnode, grp)) {
char group_str[INET_ADDRSTRLEN];
char hhmmss[10];
char uptime[10];
pim_inet4_dump("<group?>", grp->group_addr,
group_str, sizeof(group_str));
pim_time_timer_to_hhmmss(hhmmss, sizeof(hhmmss),
grp->t_group_timer);
pim_time_uptime(uptime, sizeof(uptime),
now - grp->group_creation);
if (uj) {
json_object_object_get_ex(
json, ifp->name, &json_iface);
if (!json_iface) {
json_iface =
json_object_new_object();
json_object_pim_ifp_add(
json_iface, ifp);
json_object_object_add(
json, ifp->name,
json_iface);
}
json_row = json_object_new_object();
json_object_string_add(
json_row, "source", ifaddr_str);
json_object_string_add(
json_row, "group", group_str);
if (grp->igmp_version == 3)
json_object_string_add(
json_row, "mode",
grp->group_filtermode_isexcl
? "EXCLUDE"
: "INCLUDE");
json_object_string_add(json_row,
"timer", hhmmss);
json_object_int_add(
json_row, "sourcesCount",
grp->group_source_list
? listcount(
grp->group_source_list)
: 0);
json_object_int_add(json_row, "version",
grp->igmp_version);
json_object_string_add(
json_row, "uptime", uptime);
json_object_object_add(json_iface,
group_str,
json_row);
} else {
vty_out(vty,
"%-9s %-15s %-15s %4s %8s %4d %d %8s\n",
ifp->name, ifaddr_str,
group_str,
grp->igmp_version == 3
? (grp->group_filtermode_isexcl
? "EXCL"
: "INCL")
: "----",
hhmmss,
grp->group_source_list
? listcount(
grp->group_source_list)
: 0,
grp->igmp_version, uptime);
}
} /* scan igmp groups */
} /* scan igmp sockets */
} /* scan interfaces */
if (uj) {
vty_out(vty, "%s\n", json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
}
}
static void igmp_show_group_retransmission(struct pim_instance *pim,
struct vty *vty)
{
struct interface *ifp;
vty_out(vty,
"Interface Address Group RetTimer Counter RetSrcs\n");
/* scan interfaces */
FOR_ALL_INTERFACES (pim->vrf, ifp) {
struct pim_interface *pim_ifp = ifp->info;
struct listnode *sock_node;
struct igmp_sock *igmp;
if (!pim_ifp)
continue;
/* scan igmp sockets */
for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node,
igmp)) {
char ifaddr_str[INET_ADDRSTRLEN];
struct listnode *grpnode;
struct igmp_group *grp;
pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str,
sizeof(ifaddr_str));
/* scan igmp groups */
for (ALL_LIST_ELEMENTS_RO(igmp->igmp_group_list,
grpnode, grp)) {
char group_str[INET_ADDRSTRLEN];
char grp_retr_mmss[10];
struct listnode *src_node;
struct igmp_source *src;
int grp_retr_sources = 0;
pim_inet4_dump("<group?>", grp->group_addr,
group_str, sizeof(group_str));
pim_time_timer_to_mmss(
grp_retr_mmss, sizeof(grp_retr_mmss),
grp->t_group_query_retransmit_timer);
/* count group sources with retransmission state
*/
for (ALL_LIST_ELEMENTS_RO(
grp->group_source_list, src_node,
src)) {
if (src->source_query_retransmit_count
> 0) {
++grp_retr_sources;
}
}
vty_out(vty, "%-9s %-15s %-15s %-8s %7d %7d\n",
ifp->name, ifaddr_str, group_str,
grp_retr_mmss,
grp->group_specific_query_retransmit_count,
grp_retr_sources);
} /* scan igmp groups */
} /* scan igmp sockets */
} /* scan interfaces */
}
static void igmp_show_sources(struct pim_instance *pim, struct vty *vty)
{
struct interface *ifp;
time_t now;
now = pim_time_monotonic_sec();
vty_out(vty,
"Interface Address Group Source Timer Fwd Uptime \n");
/* scan interfaces */
FOR_ALL_INTERFACES (pim->vrf, ifp) {
struct pim_interface *pim_ifp = ifp->info;
struct listnode *sock_node;
struct igmp_sock *igmp;
if (!pim_ifp)
continue;
/* scan igmp sockets */
for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node,
igmp)) {
char ifaddr_str[INET_ADDRSTRLEN];
struct listnode *grpnode;
struct igmp_group *grp;
pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str,
sizeof(ifaddr_str));
/* scan igmp groups */
for (ALL_LIST_ELEMENTS_RO(igmp->igmp_group_list,
grpnode, grp)) {
char group_str[INET_ADDRSTRLEN];
struct listnode *srcnode;
struct igmp_source *src;
pim_inet4_dump("<group?>", grp->group_addr,
group_str, sizeof(group_str));
/* scan group sources */
for (ALL_LIST_ELEMENTS_RO(
grp->group_source_list, srcnode,
src)) {
char source_str[INET_ADDRSTRLEN];
char mmss[10];
char uptime[10];
pim_inet4_dump(
"<source?>", src->source_addr,
source_str, sizeof(source_str));
pim_time_timer_to_mmss(
mmss, sizeof(mmss),
src->t_source_timer);
pim_time_uptime(
uptime, sizeof(uptime),
now - src->source_creation);
vty_out(vty,
"%-9s %-15s %-15s %-15s %5s %3s %8s\n",
ifp->name, ifaddr_str,
group_str, source_str, mmss,
IGMP_SOURCE_TEST_FORWARDING(
src->source_flags)
? "Y"
: "N",
uptime);
} /* scan group sources */
} /* scan igmp groups */
} /* scan igmp sockets */
} /* scan interfaces */
}
static void igmp_show_source_retransmission(struct pim_instance *pim,
struct vty *vty)
{
struct interface *ifp;
vty_out(vty,
"Interface Address Group Source Counter\n");
/* scan interfaces */
FOR_ALL_INTERFACES (pim->vrf, ifp) {
struct pim_interface *pim_ifp = ifp->info;
struct listnode *sock_node;
struct igmp_sock *igmp;
if (!pim_ifp)
continue;
/* scan igmp sockets */
for (ALL_LIST_ELEMENTS_RO(pim_ifp->igmp_socket_list, sock_node,
igmp)) {
char ifaddr_str[INET_ADDRSTRLEN];
struct listnode *grpnode;
struct igmp_group *grp;
pim_inet4_dump("<ifaddr?>", igmp->ifaddr, ifaddr_str,
sizeof(ifaddr_str));
/* scan igmp groups */
for (ALL_LIST_ELEMENTS_RO(igmp->igmp_group_list,
grpnode, grp)) {
char group_str[INET_ADDRSTRLEN];
struct listnode *srcnode;
struct igmp_source *src;
pim_inet4_dump("<group?>", grp->group_addr,
group_str, sizeof(group_str));
/* scan group sources */
for (ALL_LIST_ELEMENTS_RO(
grp->group_source_list, srcnode,
src)) {
char source_str[INET_ADDRSTRLEN];
pim_inet4_dump(
"<source?>", src->source_addr,
source_str, sizeof(source_str));
vty_out(vty,
"%-9s %-15s %-15s %-15s %7d\n",
ifp->name, ifaddr_str,
group_str, source_str,
src->source_query_retransmit_count);
} /* scan group sources */
} /* scan igmp groups */
} /* scan igmp sockets */
} /* scan interfaces */
}
static void clear_igmp_interfaces(struct pim_instance *pim)
{
struct interface *ifp;
FOR_ALL_INTERFACES (pim->vrf, ifp)
pim_if_addr_del_all_igmp(ifp);
FOR_ALL_INTERFACES (pim->vrf, ifp)
pim_if_addr_add_all(ifp);
}
static void clear_pim_interfaces(struct pim_instance *pim)
{
struct interface *ifp;
FOR_ALL_INTERFACES (pim->vrf, ifp) {
if (ifp->info) {
pim_neighbor_delete_all(ifp, "interface cleared");
}
}
}
static void clear_interfaces(struct pim_instance *pim)
{
clear_igmp_interfaces(pim);
clear_pim_interfaces(pim);
}
#define PIM_GET_PIM_INTERFACE(pim_ifp, ifp) \
pim_ifp = ifp->info; \
if (!pim_ifp) { \
vty_out(vty, \
"%% Enable PIM and/or IGMP on this interface first\n"); \
return CMD_WARNING_CONFIG_FAILED; \
}
DEFUN (clear_ip_interfaces,
clear_ip_interfaces_cmd,
"clear ip interfaces [vrf NAME]",
CLEAR_STR
IP_STR
"Reset interfaces\n"
VRF_CMD_HELP_STR)
{
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
if (!vrf)
return CMD_WARNING;
clear_interfaces(vrf->info);
return CMD_SUCCESS;
}
DEFUN (clear_ip_igmp_interfaces,
clear_ip_igmp_interfaces_cmd,
"clear ip igmp [vrf NAME] interfaces",
CLEAR_STR
IP_STR
CLEAR_IP_IGMP_STR
VRF_CMD_HELP_STR
"Reset IGMP interfaces\n")
{
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
if (!vrf)
return CMD_WARNING;
clear_igmp_interfaces(vrf->info);
return CMD_SUCCESS;
}
static void mroute_add_all(struct pim_instance *pim)
{
struct listnode *node;
struct channel_oil *c_oil;
for (ALL_LIST_ELEMENTS_RO(pim->channel_oil_list, node, c_oil)) {
if (pim_mroute_add(c_oil, __PRETTY_FUNCTION__)) {
/* just log warning */
char source_str[INET_ADDRSTRLEN];
char group_str[INET_ADDRSTRLEN];
pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin,
source_str, sizeof(source_str));
pim_inet4_dump("<group?>", c_oil->oil.mfcc_mcastgrp,
group_str, sizeof(group_str));
zlog_warn("%s %s: (S,G)=(%s,%s) failure writing MFC",
__FILE__, __PRETTY_FUNCTION__, source_str,
group_str);
}
}
}
static void mroute_del_all(struct pim_instance *pim)
{
struct listnode *node;
struct channel_oil *c_oil;
for (ALL_LIST_ELEMENTS_RO(pim->channel_oil_list, node, c_oil)) {
if (pim_mroute_del(c_oil, __PRETTY_FUNCTION__)) {
/* just log warning */
char source_str[INET_ADDRSTRLEN];
char group_str[INET_ADDRSTRLEN];
pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin,
source_str, sizeof(source_str));
pim_inet4_dump("<group?>", c_oil->oil.mfcc_mcastgrp,
group_str, sizeof(group_str));
zlog_warn("%s %s: (S,G)=(%s,%s) failure clearing MFC",
__FILE__, __PRETTY_FUNCTION__, source_str,
group_str);
}
}
}
DEFUN (clear_ip_mroute,
clear_ip_mroute_cmd,
"clear ip mroute [vrf NAME]",
CLEAR_STR
IP_STR
"Reset multicast routes\n"
VRF_CMD_HELP_STR)
{
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
if (!vrf)
return CMD_WARNING;
mroute_del_all(vrf->info);
mroute_add_all(vrf->info);
return CMD_SUCCESS;
}
DEFUN (clear_ip_pim_interfaces,
clear_ip_pim_interfaces_cmd,
"clear ip pim [vrf NAME] interfaces",
CLEAR_STR
IP_STR
CLEAR_IP_PIM_STR
VRF_CMD_HELP_STR
"Reset PIM interfaces\n")
{
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
if (!vrf)
return CMD_WARNING;
clear_pim_interfaces(vrf->info);
return CMD_SUCCESS;
}
DEFUN (clear_ip_pim_interface_traffic,
clear_ip_pim_interface_traffic_cmd,
"clear ip pim [vrf NAME] interface traffic",
"Reset functions\n"
"IP information\n"
"PIM clear commands\n"
VRF_CMD_HELP_STR
"Reset PIM interfaces\n"
"Reset Protocol Packet counters\n")
{
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
struct interface *ifp = NULL;
struct pim_interface *pim_ifp = NULL;
if (!vrf)
return CMD_WARNING;
FOR_ALL_INTERFACES (vrf, ifp) {
pim_ifp = ifp->info;
if (!pim_ifp)
continue;
pim_ifp->pim_ifstat_hello_recv = 0;
pim_ifp->pim_ifstat_hello_sent = 0;
pim_ifp->pim_ifstat_join_recv = 0;
pim_ifp->pim_ifstat_join_send = 0;
pim_ifp->pim_ifstat_prune_recv = 0;
pim_ifp->pim_ifstat_prune_send = 0;
pim_ifp->pim_ifstat_reg_recv = 0;
pim_ifp->pim_ifstat_reg_send = 0;
pim_ifp->pim_ifstat_reg_stop_recv = 0;
pim_ifp->pim_ifstat_reg_stop_send = 0;
pim_ifp->pim_ifstat_assert_recv = 0;
pim_ifp->pim_ifstat_assert_send = 0;
}
return CMD_SUCCESS;
}
DEFUN (clear_ip_pim_oil,
clear_ip_pim_oil_cmd,
"clear ip pim [vrf NAME] oil",
CLEAR_STR
IP_STR
CLEAR_IP_PIM_STR
VRF_CMD_HELP_STR
"Rescan PIM OIL (output interface list)\n")
{
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
if (!vrf)
return CMD_WARNING;
pim_scan_oil(vrf->info);
return CMD_SUCCESS;
}
DEFUN (show_ip_igmp_interface,
show_ip_igmp_interface_cmd,
"show ip igmp [vrf NAME] interface [detail|WORD] [json]",
SHOW_STR
IP_STR
IGMP_STR
VRF_CMD_HELP_STR
"IGMP interface information\n"
"Detailed output\n"
"interface name\n"
JSON_STR)
{
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
bool uj = use_json(argc, argv);
if (!vrf)
return CMD_WARNING;
if (argv_find(argv, argc, "detail", &idx)
|| argv_find(argv, argc, "WORD", &idx))
igmp_show_interfaces_single(vrf->info, vty, argv[idx]->arg, uj);
else
igmp_show_interfaces(vrf->info, vty, uj);
return CMD_SUCCESS;
}
DEFUN (show_ip_igmp_interface_vrf_all,
show_ip_igmp_interface_vrf_all_cmd,
"show ip igmp vrf all interface [detail|WORD] [json]",
SHOW_STR
IP_STR
IGMP_STR
VRF_CMD_HELP_STR
"IGMP interface information\n"
"Detailed output\n"
"interface name\n"
JSON_STR)
{
int idx = 2;
bool uj = use_json(argc, argv);
struct vrf *vrf;
bool first = true;
if (uj)
vty_out(vty, "{ ");
RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
if (uj) {
if (!first)
vty_out(vty, ", ");
vty_out(vty, " \"%s\": ", vrf->name);
first = false;
} else
vty_out(vty, "VRF: %s\n", vrf->name);
if (argv_find(argv, argc, "detail", &idx)
|| argv_find(argv, argc, "WORD", &idx))
igmp_show_interfaces_single(vrf->info, vty,
argv[idx]->arg, uj);
else
igmp_show_interfaces(vrf->info, vty, uj);
}
if (uj)
vty_out(vty, "}\n");
return CMD_SUCCESS;
}
DEFUN (show_ip_igmp_join,
show_ip_igmp_join_cmd,
"show ip igmp [vrf NAME] join",
SHOW_STR
IP_STR
IGMP_STR
VRF_CMD_HELP_STR
"IGMP static join information\n")
{
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
if (!vrf)
return CMD_WARNING;
igmp_show_interface_join(vrf->info, vty);
return CMD_SUCCESS;
}
DEFUN (show_ip_igmp_join_vrf_all,
show_ip_igmp_join_vrf_all_cmd,
"show ip igmp vrf all join",
SHOW_STR
IP_STR
IGMP_STR
VRF_CMD_HELP_STR
"IGMP static join information\n")
{
bool uj = use_json(argc, argv);
struct vrf *vrf;
bool first = true;
if (uj)
vty_out(vty, "{ ");
RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
if (uj) {
if (!first)
vty_out(vty, ", ");
vty_out(vty, " \"%s\": ", vrf->name);
first = false;
} else
vty_out(vty, "VRF: %s\n", vrf->name);
igmp_show_interface_join(vrf->info, vty);
}
if (uj)
vty_out(vty, "}\n");
return CMD_SUCCESS;
}
DEFUN (show_ip_igmp_groups,
show_ip_igmp_groups_cmd,
"show ip igmp [vrf NAME] groups [json]",
SHOW_STR
IP_STR
IGMP_STR
VRF_CMD_HELP_STR
IGMP_GROUP_STR
JSON_STR)
{
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
bool uj = use_json(argc, argv);
if (!vrf)
return CMD_WARNING;
igmp_show_groups(vrf->info, vty, uj);
return CMD_SUCCESS;
}
DEFUN (show_ip_igmp_groups_vrf_all,
show_ip_igmp_groups_vrf_all_cmd,
"show ip igmp vrf all groups [json]",
SHOW_STR
IP_STR
IGMP_STR
VRF_CMD_HELP_STR
IGMP_GROUP_STR
JSON_STR)
{
bool uj = use_json(argc, argv);
struct vrf *vrf;
bool first = true;
if (uj)
vty_out(vty, "{ ");
RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
if (uj) {
if (!first)
vty_out(vty, ", ");
vty_out(vty, " \"%s\": ", vrf->name);
first = false;
} else
vty_out(vty, "VRF: %s\n", vrf->name);
igmp_show_groups(vrf->info, vty, uj);
}
if (uj)
vty_out(vty, "}\n");
return CMD_SUCCESS;
}
DEFUN (show_ip_igmp_groups_retransmissions,
show_ip_igmp_groups_retransmissions_cmd,
"show ip igmp [vrf NAME] groups retransmissions",
SHOW_STR
IP_STR
IGMP_STR
VRF_CMD_HELP_STR
IGMP_GROUP_STR
"IGMP group retransmissions\n")
{
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
if (!vrf)
return CMD_WARNING;
igmp_show_group_retransmission(vrf->info, vty);
return CMD_SUCCESS;
}
DEFUN (show_ip_igmp_sources,
show_ip_igmp_sources_cmd,
"show ip igmp [vrf NAME] sources",
SHOW_STR
IP_STR
IGMP_STR
VRF_CMD_HELP_STR
IGMP_SOURCE_STR)
{
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
if (!vrf)
return CMD_WARNING;
igmp_show_sources(vrf->info, vty);
return CMD_SUCCESS;
}
DEFUN (show_ip_igmp_sources_retransmissions,
show_ip_igmp_sources_retransmissions_cmd,
"show ip igmp [vrf NAME] sources retransmissions",
SHOW_STR
IP_STR
IGMP_STR
VRF_CMD_HELP_STR
IGMP_SOURCE_STR
"IGMP source retransmissions\n")
{
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
if (!vrf)
return CMD_WARNING;
igmp_show_source_retransmission(vrf->info, vty);
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);
bool 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",
SHOW_STR
IP_STR
PIM_STR
VRF_CMD_HELP_STR
"PIM interface assert\n")
{
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
if (!vrf)
return CMD_WARNING;
pim_show_assert(vrf->info, vty);
return CMD_SUCCESS;
}
DEFUN (show_ip_pim_assert_internal,
show_ip_pim_assert_internal_cmd,
"show ip pim [vrf NAME] assert-internal",
SHOW_STR
IP_STR
PIM_STR
VRF_CMD_HELP_STR
"PIM interface internal assert state\n")
{
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
if (!vrf)
return CMD_WARNING;
pim_show_assert_internal(vrf->info, vty);
return CMD_SUCCESS;
}
DEFUN (show_ip_pim_assert_metric,
show_ip_pim_assert_metric_cmd,
"show ip pim [vrf NAME] assert-metric",
SHOW_STR
IP_STR
PIM_STR
VRF_CMD_HELP_STR
"PIM interface assert metric\n")
{
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
if (!vrf)
return CMD_WARNING;
pim_show_assert_metric(vrf->info, vty);
return CMD_SUCCESS;
}
DEFUN (show_ip_pim_assert_winner_metric,
show_ip_pim_assert_winner_metric_cmd,
"show ip pim [vrf NAME] assert-winner-metric",
SHOW_STR
IP_STR
PIM_STR
VRF_CMD_HELP_STR
"PIM interface assert winner metric\n")
{
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
if (!vrf)
return CMD_WARNING;
pim_show_assert_winner_metric(vrf->info, vty);
return CMD_SUCCESS;
}
DEFUN (show_ip_pim_interface,
show_ip_pim_interface_cmd,
"show ip pim [vrf NAME] interface [detail|WORD] [json]",
SHOW_STR
IP_STR
PIM_STR
VRF_CMD_HELP_STR
"PIM interface information\n"
"Detailed output\n"
"interface name\n"
JSON_STR)
{
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
bool uj = use_json(argc, argv);
if (!vrf)
return CMD_WARNING;
if (argv_find(argv, argc, "WORD", &idx)
|| argv_find(argv, argc, "detail", &idx))
pim_show_interfaces_single(vrf->info, vty, argv[idx]->arg, uj);
else
pim_show_interfaces(vrf->info, vty, uj);
return CMD_SUCCESS;
}
DEFUN (show_ip_pim_interface_vrf_all,
show_ip_pim_interface_vrf_all_cmd,
"show ip pim vrf all interface [detail|WORD] [json]",
SHOW_STR
IP_STR
PIM_STR
VRF_CMD_HELP_STR
"PIM interface information\n"
"Detailed output\n"
"interface name\n"
JSON_STR)
{
int idx = 6;
bool uj = use_json(argc, argv);
struct vrf *vrf;
bool first = true;
if (uj)
vty_out(vty, "{ ");
RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
if (uj) {
if (!first)
vty_out(vty, ", ");
vty_out(vty, " \"%s\": ", vrf->name);
first = false;
} else
vty_out(vty, "VRF: %s\n", vrf->name);
if (argv_find(argv, argc, "WORD", &idx)
|| argv_find(argv, argc, "detail", &idx))
pim_show_interfaces_single(vrf->info, vty,
argv[idx]->arg, uj);
else
pim_show_interfaces(vrf->info, vty, uj);
}
if (uj)
vty_out(vty, "}\n");
return CMD_SUCCESS;
}
DEFUN (show_ip_pim_join,
show_ip_pim_join_cmd,
"show ip pim [vrf NAME] join [json]",
SHOW_STR
IP_STR
PIM_STR
VRF_CMD_HELP_STR
"PIM interface join information\n"
JSON_STR)
{
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
bool uj = use_json(argc, argv);
if (!vrf)
return CMD_WARNING;
pim_show_join(vrf->info, vty, uj);
return CMD_SUCCESS;
}
DEFUN (show_ip_pim_join_vrf_all,
show_ip_pim_join_vrf_all_cmd,
"show ip pim vrf all join [json]",
SHOW_STR
IP_STR
PIM_STR
VRF_CMD_HELP_STR
"PIM interface join information\n"
JSON_STR)
{
bool uj = use_json(argc, argv);
struct vrf *vrf;
bool first = true;
if (uj)
vty_out(vty, "{ ");
RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
if (uj) {
if (!first)
vty_out(vty, ", ");
vty_out(vty, " \"%s\": ", vrf->name);
first = false;
} else
vty_out(vty, "VRF: %s\n", vrf->name);
pim_show_join(vrf->info, vty, uj);
}
if (uj)
vty_out(vty, "}\n");
return CMD_WARNING;
}
DEFUN (show_ip_pim_local_membership,
show_ip_pim_local_membership_cmd,
"show ip pim [vrf NAME] local-membership [json]",
SHOW_STR
IP_STR
PIM_STR
VRF_CMD_HELP_STR
"PIM interface local-membership\n"
JSON_STR)
{
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
bool uj = use_json(argc, argv);
if (!vrf)
return CMD_WARNING;
pim_show_membership(vrf->info, vty, uj);
return CMD_SUCCESS;
}
DEFUN (show_ip_pim_neighbor,
show_ip_pim_neighbor_cmd,
"show ip pim [vrf NAME] neighbor [detail|WORD] [json]",
SHOW_STR
IP_STR
PIM_STR
VRF_CMD_HELP_STR
"PIM neighbor information\n"
"Detailed output\n"
"Name of interface or neighbor\n"
JSON_STR)
{
int idx = 2;
struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx);
bool uj = use_json(argc, argv);
if (!vrf)
return CMD_WARNING;
if (argv_find(argv, argc, "detail", &idx)
|| argv_find(argv, argc, "WORD", &idx))
pim_show_neighbors_single(vrf->info, vty, argv[idx]->arg, uj);
else