pimd: Cleanup deep nesting in pim_cmd.c

Cleanup some deep nesting in pim_cmd.c so that functions
look easier on the eyes.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
This commit is contained in:
Donald Sharp 2017-10-09 10:54:20 -04:00
parent 48f41fe829
commit 5fe58e3d62

View File

@ -1063,59 +1063,49 @@ static void pim_show_interfaces_single(struct pim_instance *pim,
// FHR // FHR
for (ALL_LIST_ELEMENTS_RO(pim->upstream_list, upnode, for (ALL_LIST_ELEMENTS_RO(pim->upstream_list, upnode,
up)) { up)) {
if (ifp == up->rpf.source_nexthop.interface) { if (ifp != up->rpf.source_nexthop.interface)
if (up->flags continue;
& PIM_UPSTREAM_FLAG_MASK_FHR) {
if (!json_fhr_sources) { if (!(up->flags & PIM_UPSTREAM_FLAG_MASK_FHR))
continue;
if (!json_fhr_sources)
json_fhr_sources = json_fhr_sources =
json_object_new_object(); json_object_new_object();
}
pim_inet4_dump("<src?>", pim_inet4_dump("<src?>", up->sg.src,
up->sg.src, src_str, sizeof(src_str));
src_str, pim_inet4_dump("<grp?>", up->sg.grp,
sizeof(src_str)); grp_str, sizeof(grp_str));
pim_inet4_dump("<grp?>", pim_time_uptime(uptime, sizeof(uptime),
up->sg.grp,
grp_str,
sizeof(grp_str));
pim_time_uptime(
uptime, sizeof(uptime),
now - up->state_transition); now - up->state_transition);
/* Does this group live in /*
* json_fhr_sources? If not * Does this group live in json_fhr_sources?
* create it. */ * If not create it.
json_object_object_get_ex( */
json_fhr_sources, json_object_object_get_ex(json_fhr_sources,
grp_str, &json_group); grp_str,
&json_group);
if (!json_group) { if (!json_group) {
json_group = json_group = json_object_new_object();
json_object_new_object();
json_object_object_add( json_object_object_add(
json_fhr_sources, json_fhr_sources,
grp_str, grp_str,
json_group); json_group);
} }
json_group_source = json_group_source = json_object_new_object();
json_object_new_object(); json_object_string_add(json_group_source,
json_object_string_add(
json_group_source,
"source", src_str); "source", src_str);
json_object_string_add( json_object_string_add(json_group_source,
json_group_source,
"group", grp_str); "group", grp_str);
json_object_string_add( json_object_string_add(json_group_source,
json_group_source,
"upTime", uptime); "upTime", uptime);
json_object_object_add( json_object_object_add(json_group, src_str,
json_group, src_str,
json_group_source); json_group_source);
} }
}
}
if (json_fhr_sources) { if (json_fhr_sources) {
json_object_object_add(json_row, json_object_object_add(json_row,
@ -1237,11 +1227,14 @@ static void pim_show_interfaces_single(struct pim_instance *pim,
print_header = 1; print_header = 1;
for (ALL_LIST_ELEMENTS_RO(pim->upstream_list, upnode, for (ALL_LIST_ELEMENTS_RO(pim->upstream_list, upnode,
up)) { up)) {
if (strcmp(ifp->name, up->rpf.source_nexthop
.interface->name) if (strcmp(ifp->name,
== 0) { up->rpf.source_nexthop.
if (up->flags interface->name) != 0)
& PIM_UPSTREAM_FLAG_MASK_FHR) { continue;
if (!(up->flags & PIM_UPSTREAM_FLAG_MASK_FHR))
continue;
if (print_header) { if (print_header) {
vty_out(vty, vty_out(vty,
@ -1251,24 +1244,17 @@ static void pim_show_interfaces_single(struct pim_instance *pim,
print_header = 0; print_header = 0;
} }
pim_inet4_dump("<src?>", pim_inet4_dump("<src?>", up->sg.src,
up->sg.src, src_str, sizeof(src_str));
src_str, pim_inet4_dump("<grp?>", up->sg.grp,
sizeof(src_str)); grp_str, sizeof(grp_str));
pim_inet4_dump("<grp?>", pim_time_uptime(uptime, sizeof(uptime),
up->sg.grp,
grp_str,
sizeof(grp_str));
pim_time_uptime(
uptime, sizeof(uptime),
now - up->state_transition); now - up->state_transition);
vty_out(vty, vty_out(vty,
"%s : %s is a source, uptime is %s\n", "%s : %s is a source, uptime is %s\n",
grp_str, src_str, grp_str, src_str,
uptime); uptime);
} }
}
}
if (!print_header) { if (!print_header) {
vty_out(vty, "\n"); vty_out(vty, "\n");