pimd: Convert vif and ifindex lookups to use 'struct pim_instance *'

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
This commit is contained in:
Donald Sharp 2017-05-21 08:29:56 -04:00
parent f88df3a642
commit 7cfc7bcfe7
9 changed files with 152 additions and 174 deletions

View File

@ -1839,8 +1839,9 @@ static void pim_show_neighbors_single(struct vty *vty, const char *neighbor,
} }
} }
static void pim_show_state(struct vty *vty, const char *src_or_group, static void pim_show_state(struct pim_instance *pim, struct vty *vty,
const char *group, u_char uj) const char *src_or_group, const char *group,
u_char uj)
{ {
struct channel_oil *c_oil; struct channel_oil *c_oil;
struct listnode *node; struct listnode *node;
@ -1875,7 +1876,7 @@ static void pim_show_state(struct vty *vty, const char *src_or_group,
sizeof(grp_str)); sizeof(grp_str));
pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, src_str, pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, src_str,
sizeof(src_str)); sizeof(src_str));
ifp_in = pim_if_find_by_vif_index(c_oil->oil.mfcc_parent); ifp_in = pim_if_find_by_vif_index(pim, c_oil->oil.mfcc_parent);
if (ifp_in) if (ifp_in)
strcpy(in_ifname, ifp_in->name); strcpy(in_ifname, ifp_in->name);
@ -1957,7 +1958,7 @@ static void pim_show_state(struct vty *vty, const char *src_or_group,
if (ttl < 1) if (ttl < 1)
continue; continue;
ifp_out = pim_if_find_by_vif_index(oif_vif_index); ifp_out = pim_if_find_by_vif_index(pim, oif_vif_index);
pim_time_uptime( pim_time_uptime(
oif_uptime, sizeof(oif_uptime), oif_uptime, sizeof(oif_uptime),
now - c_oil->oif_creation[oif_vif_index]); now - c_oil->oif_creation[oif_vif_index]);
@ -3449,7 +3450,7 @@ DEFUN (show_ip_pim_state,
} else if (argc == 5) } else if (argc == 5)
src_or_group = argv[4]->arg; src_or_group = argv[4]->arg;
pim_show_state(vty, src_or_group, group, uj); pim_show_state(pimg, vty, src_or_group, group, uj);
return CMD_SUCCESS; return CMD_SUCCESS;
} }
@ -3750,7 +3751,7 @@ DEFUN (show_ip_multicast,
return CMD_SUCCESS; return CMD_SUCCESS;
} }
static void show_mroute(struct vty *vty, u_char uj) static void show_mroute(struct pim_instance *pim, struct vty *vty, u_char uj)
{ {
struct listnode *node; struct listnode *node;
struct channel_oil *c_oil; struct channel_oil *c_oil;
@ -3770,8 +3771,6 @@ static void show_mroute(struct vty *vty, u_char uj)
int oif_vif_index; int oif_vif_index;
struct interface *ifp_in; struct interface *ifp_in;
char proto[100]; char proto[100];
struct vrf *vrf;
struct pim_instance *pim;
if (uj) { if (uj) {
json = json_object_new_object(); json = json_object_new_object();
@ -3793,7 +3792,7 @@ static void show_mroute(struct vty *vty, u_char uj)
sizeof(grp_str)); sizeof(grp_str));
pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, src_str, pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, src_str,
sizeof(src_str)); sizeof(src_str));
ifp_in = pim_if_find_by_vif_index(c_oil->oil.mfcc_parent); ifp_in = pim_if_find_by_vif_index(pim, c_oil->oil.mfcc_parent);
if (ifp_in) if (ifp_in)
strcpy(in_ifname, ifp_in->name); strcpy(in_ifname, ifp_in->name);
@ -3846,7 +3845,7 @@ static void show_mroute(struct vty *vty, u_char uj)
if (ttl < 1) if (ttl < 1)
continue; continue;
ifp_out = pim_if_find_by_vif_index(oif_vif_index); ifp_out = pim_if_find_by_vif_index(pim, oif_vif_index);
pim_time_uptime( pim_time_uptime(
oif_uptime, sizeof(oif_uptime), oif_uptime, sizeof(oif_uptime),
now - c_oil->oif_creation[oif_vif_index]); now - c_oil->oif_creation[oif_vif_index]);
@ -3948,145 +3947,125 @@ static void show_mroute(struct vty *vty, u_char uj)
} }
/* Print list of static routes */ /* Print list of static routes */
RB_FOREACH(vrf, vrf_name_head, &vrfs_by_name) for (ALL_LIST_ELEMENTS_RO(pim->static_routes, node, s_route)) {
{ first = 1;
pim = vrf->info;
if (!pim) if (!s_route->c_oil.installed)
continue; continue;
for (ALL_LIST_ELEMENTS_RO(pim->static_routes, node, s_route)) { pim_inet4_dump("<group?>", s_route->group, grp_str,
first = 1; sizeof(grp_str));
pim_inet4_dump("<source?>", s_route->source, src_str,
sizeof(src_str));
ifp_in = pim_if_find_by_vif_index(pim, s_route->iif);
found_oif = 0;
if (!s_route->c_oil.installed) if (ifp_in)
strcpy(in_ifname, ifp_in->name);
else
strcpy(in_ifname, "<iif?>");
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);
}
json_object_string_add(json_source, "iif", in_ifname);
json_oil = NULL;
} else {
strcpy(proto, "STATIC");
}
for (oif_vif_index = 0; oif_vif_index < MAXVIFS;
++oif_vif_index) {
struct interface *ifp_out;
char oif_uptime[10];
int ttl;
ttl = s_route->oif_ttls[oif_vif_index];
if (ttl < 1)
continue; continue;
pim_inet4_dump("<group?>", s_route->group, grp_str, ifp_out = pim_if_find_by_vif_index(pim, oif_vif_index);
sizeof(grp_str)); pim_time_uptime(
pim_inet4_dump("<source?>", s_route->source, src_str, oif_uptime, sizeof(oif_uptime),
sizeof(src_str)); now
ifp_in = pim_if_find_by_vif_index(s_route->iif); - s_route->c_oil
found_oif = 0; .oif_creation[oif_vif_index]);
found_oif = 1;
if (ifp_in) if (ifp_out)
strcpy(in_ifname, ifp_in->name); strcpy(out_ifname, ifp_out->name);
else else
strcpy(in_ifname, "<iif?>"); strcpy(out_ifname, "<oif?>");
if (uj) { if (uj) {
json_ifp_out = json_object_new_object();
/* Find the group, create it if it doesn't exist json_object_string_add(json_ifp_out, "source",
*/ src_str);
json_object_object_get_ex(json, grp_str, json_object_string_add(json_ifp_out, "group",
&json_group); grp_str);
json_object_boolean_true_add(json_ifp_out,
if (!json_group) { "protocolStatic");
json_group = json_object_new_object(); json_object_string_add(json_ifp_out,
json_object_object_add(json, grp_str, "inboundInterface",
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);
}
json_object_string_add(json_source, "iif",
in_ifname); in_ifname);
json_oil = NULL; json_object_int_add(
} else { json_ifp_out, "iVifI",
strcpy(proto, "STATIC"); s_route->c_oil.oil.mfcc_parent);
} json_object_string_add(json_ifp_out,
"outboundInterface",
for (oif_vif_index = 0; oif_vif_index < MAXVIFS; out_ifname);
++oif_vif_index) { json_object_int_add(json_ifp_out, "oVifI",
struct interface *ifp_out; oif_vif_index);
char oif_uptime[10]; json_object_int_add(json_ifp_out, "ttl", ttl);
int ttl; json_object_string_add(json_ifp_out, "upTime",
oif_uptime);
ttl = s_route->oif_ttls[oif_vif_index]; if (!json_oil) {
if (ttl < 1) json_oil = json_object_new_object();
continue; json_object_object_add(json_source,
"oil", json_oil);
ifp_out =
pim_if_find_by_vif_index(oif_vif_index);
pim_time_uptime(
oif_uptime, sizeof(oif_uptime),
now
- s_route->c_oil.oif_creation
[oif_vif_index]);
found_oif = 1;
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_boolean_true_add(
json_ifp_out, "protocolStatic");
json_object_string_add(
json_ifp_out,
"inboundInterface", in_ifname);
json_object_int_add(
json_ifp_out, "iVifI",
s_route->c_oil.oil.mfcc_parent);
json_object_string_add(
json_ifp_out,
"outboundInterface",
out_ifname);
json_object_int_add(json_ifp_out,
"oVifI",
oif_vif_index);
json_object_int_add(json_ifp_out, "ttl",
ttl);
json_object_string_add(json_ifp_out,
"upTime",
oif_uptime);
if (!json_oil) {
json_oil =
json_object_new_object();
json_object_object_add(
json_source, "oil",
json_oil);
}
json_object_object_add(json_oil,
out_ifname,
json_ifp_out);
} else {
vty_out(vty,
"%-15s %-15s %-6s %-10s %-10s %-3d %8s %s\n",
src_str, grp_str, proto,
in_ifname, out_ifname, ttl,
oif_uptime, vrf->name);
if (first) {
src_str[0] = '\0';
grp_str[0] = '\0';
in_ifname[0] = '\0';
first = 0;
}
} }
} json_object_object_add(json_oil, out_ifname,
json_ifp_out);
if (!uj && !found_oif) { } else {
vty_out(vty, vty_out(vty,
"%-15s %-15s %-6s %-10s %-10s %-3d %8s %s\n", "%-15s %-15s %-6s %-10s %-10s %-3d %8s %s\n",
src_str, grp_str, proto, in_ifname, src_str, grp_str, proto, in_ifname,
"none", 0, "--:--:--", vrf->name); out_ifname, ttl, oif_uptime,
pim->vrf->name);
if (first) {
src_str[0] = '\0';
grp_str[0] = '\0';
in_ifname[0] = '\0';
first = 0;
}
} }
} }
if (!uj && !found_oif) {
vty_out(vty,
"%-15s %-15s %-6s %-10s %-10s %-3d %8s %s\n",
src_str, grp_str, proto, in_ifname, "none", 0,
"--:--:--", pim->vrf->name);
}
} }
if (uj) { if (uj) {
@ -4105,7 +4084,7 @@ DEFUN (show_ip_mroute,
JSON_STR) JSON_STR)
{ {
u_char uj = use_json(argc, argv); u_char uj = use_json(argc, argv);
show_mroute(vty, uj); show_mroute(pimg, vty, uj);
return CMD_SUCCESS; return CMD_SUCCESS;
} }

View File

@ -1054,28 +1054,19 @@ int pim_if_del_vif(struct interface *ifp)
} }
// DBS - VRF Revist // DBS - VRF Revist
struct interface *pim_if_find_by_vif_index(ifindex_t vif_index) struct interface *pim_if_find_by_vif_index(struct pim_instance *pim,
ifindex_t vif_index)
{ {
struct listnode *ifnode; struct listnode *ifnode;
struct interface *ifp; struct interface *ifp;
struct pim_instance *pim;
struct vrf *vrf;
RB_FOREACH(vrf, vrf_name_head, &vrfs_by_name) for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), ifnode, ifp)) {
{ if (ifp->info) {
pim = vrf->info; struct pim_interface *pim_ifp;
if (!pim) pim_ifp = ifp->info;
continue;
for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), ifnode, if (vif_index == pim_ifp->mroute_vif_index)
ifp)) { return ifp;
if (ifp->info) {
struct pim_interface *pim_ifp;
pim_ifp = ifp->info;
if (vif_index == pim_ifp->mroute_vif_index)
return ifp;
}
} }
} }
@ -1085,12 +1076,12 @@ struct interface *pim_if_find_by_vif_index(ifindex_t vif_index)
/* /*
pim_if_add_vif() uses ifindex as vif_index pim_if_add_vif() uses ifindex as vif_index
*/ */
int pim_if_find_vifindex_by_ifindex(ifindex_t ifindex) int pim_if_find_vifindex_by_ifindex(struct pim_instance *pim, ifindex_t ifindex)
{ {
struct pim_interface *pim_ifp; struct pim_interface *pim_ifp;
struct interface *ifp; struct interface *ifp;
ifp = if_lookup_by_index(ifindex, pimg->vrf_id); ifp = if_lookup_by_index(ifindex, pim->vrf_id);
if (!ifp || !ifp->info) if (!ifp || !ifp->info)
return -1; return -1;
pim_ifp = ifp->info; pim_ifp = ifp->info;

View File

@ -169,8 +169,10 @@ int pim_if_del_vif(struct interface *ifp);
void pim_if_add_vif_all(struct pim_instance *pim); void pim_if_add_vif_all(struct pim_instance *pim);
void pim_if_del_vif_all(struct pim_instance *pim); void pim_if_del_vif_all(struct pim_instance *pim);
struct interface *pim_if_find_by_vif_index(ifindex_t vif_index); struct interface *pim_if_find_by_vif_index(struct pim_instance *pim,
int pim_if_find_vifindex_by_ifindex(ifindex_t ifindex); ifindex_t vif_index);
int pim_if_find_vifindex_by_ifindex(struct pim_instance *pim,
ifindex_t ifindex);
int pim_if_lan_delay_enabled(struct interface *ifp); int pim_if_lan_delay_enabled(struct interface *ifp);
uint16_t pim_if_effective_propagation_delay_msec(struct interface *ifp); uint16_t pim_if_effective_propagation_delay_msec(struct interface *ifp);

View File

@ -197,6 +197,7 @@ static int pim_mroute_msg_nocache(int fd, struct interface *ifp,
if (up->channel_oil->oil.mfcc_parent >= MAXVIFS) { if (up->channel_oil->oil.mfcc_parent >= MAXVIFS) {
int vif_index = 0; int vif_index = 0;
vif_index = pim_if_find_vifindex_by_ifindex( vif_index = pim_if_find_vifindex_by_ifindex(
pim_ifp->pim,
up->rpf.source_nexthop.interface->ifindex); up->rpf.source_nexthop.interface->ifindex);
up->channel_oil->oil.mfcc_parent = vif_index; up->channel_oil->oil.mfcc_parent = vif_index;
} }
@ -597,7 +598,7 @@ static int pim_mroute_msg(struct pim_instance *pim, const char *buf,
} else { } else {
msg = (const struct igmpmsg *)buf; msg = (const struct igmpmsg *)buf;
ifp = pim_if_find_by_vif_index(msg->im_vif); ifp = pim_if_find_by_vif_index(pim, msg->im_vif);
if (!ifp) if (!ifp)
return 0; return 0;

View File

@ -358,7 +358,8 @@ static int pim_update_upstream_nh(struct pim_instance *pim,
if (up->channel_oil) { if (up->channel_oil) {
ifindex_t ifindex = ifindex_t ifindex =
up->rpf.source_nexthop.interface->ifindex; up->rpf.source_nexthop.interface->ifindex;
vif_index = pim_if_find_vifindex_by_ifindex(ifindex); vif_index =
pim_if_find_vifindex_by_ifindex(pim, ifindex);
/* Pass Current selected NH vif index to mroute download /* Pass Current selected NH vif index to mroute download
*/ */
if (vif_index) if (vif_index)
@ -1063,7 +1064,7 @@ int pim_ecmp_fib_lookup_if_vif_index(struct pim_instance *pim,
ifindex2ifname(first_ifindex, pim->vrf_id), addr_str); ifindex2ifname(first_ifindex, pim->vrf_id), addr_str);
} }
vif_index = pim_if_find_vifindex_by_ifindex(first_ifindex); vif_index = pim_if_find_vifindex_by_ifindex(pim, first_ifindex);
if (vif_index < 0) { if (vif_index < 0) {
if (PIM_DEBUG_ZEBRA) { if (PIM_DEBUG_ZEBRA) {

View File

@ -169,7 +169,7 @@ struct channel_oil *pim_channel_oil_add(struct prefix_sg *sg,
return c_oil; return c_oil;
} }
ifp = pim_if_find_by_vif_index(input_vif_index); ifp = pim_if_find_by_vif_index(pimg, input_vif_index);
if (!ifp) { if (!ifp) {
/* warning only */ /* warning only */
zlog_warn( zlog_warn(

View File

@ -358,7 +358,8 @@ int pim_static_write_mroute(struct vty *vty, struct pim_instance *pim,
for (i = 0; i < MAXVIFS; i++) for (i = 0; i < MAXVIFS; i++)
if (sroute->oif_ttls[i]) { if (sroute->oif_ttls[i]) {
struct interface *oifp = struct interface *oifp =
pim_if_find_by_vif_index(i); pim_if_find_by_vif_index(pim,
i);
if (sroute->source.s_addr == 0) if (sroute->source.s_addr == 0)
vty_out(vty, vty_out(vty,
" ip mroute %s %s\n", " ip mroute %s %s\n",

View File

@ -545,10 +545,10 @@ void pim_scan_individual_oil(struct channel_oil *c_oil, int in_vif_index)
} }
if (PIM_DEBUG_ZEBRA) { if (PIM_DEBUG_ZEBRA) {
struct interface *old_iif = struct interface *old_iif = pim_if_find_by_vif_index(
pim_if_find_by_vif_index(c_oil->oil.mfcc_parent); c_oil->pim, c_oil->oil.mfcc_parent);
struct interface *new_iif = struct interface *new_iif = pim_if_find_by_vif_index(
pim_if_find_by_vif_index(input_iface_vif_index); c_oil->pim, input_iface_vif_index);
char source_str[INET_ADDRSTRLEN]; char source_str[INET_ADDRSTRLEN];
char group_str[INET_ADDRSTRLEN]; char group_str[INET_ADDRSTRLEN];
pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, source_str, pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, source_str,
@ -564,8 +564,8 @@ void pim_scan_individual_oil(struct channel_oil *c_oil, int in_vif_index)
/* new iif loops to existing oif ? */ /* new iif loops to existing oif ? */
if (c_oil->oil.mfcc_ttls[input_iface_vif_index]) { if (c_oil->oil.mfcc_ttls[input_iface_vif_index]) {
struct interface *new_iif = struct interface *new_iif = pim_if_find_by_vif_index(
pim_if_find_by_vif_index(input_iface_vif_index); c_oil->pim, input_iface_vif_index);
if (PIM_DEBUG_ZEBRA) { if (PIM_DEBUG_ZEBRA) {
char source_str[INET_ADDRSTRLEN]; char source_str[INET_ADDRSTRLEN];
@ -590,10 +590,10 @@ void pim_scan_individual_oil(struct channel_oil *c_oil, int in_vif_index)
if (pim_mroute_add(c_oil, __PRETTY_FUNCTION__)) { if (pim_mroute_add(c_oil, __PRETTY_FUNCTION__)) {
if (PIM_DEBUG_MROUTE) { if (PIM_DEBUG_MROUTE) {
/* just log warning */ /* just log warning */
struct interface *old_iif = struct interface *old_iif = pim_if_find_by_vif_index(
pim_if_find_by_vif_index(old_vif_index); c_oil->pim, old_vif_index);
struct interface *new_iif = struct interface *new_iif = pim_if_find_by_vif_index(
pim_if_find_by_vif_index(input_iface_vif_index); c_oil->pim, input_iface_vif_index);
char source_str[INET_ADDRSTRLEN]; char source_str[INET_ADDRSTRLEN];
char group_str[INET_ADDRSTRLEN]; char group_str[INET_ADDRSTRLEN];
pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin, pim_inet4_dump("<source?>", c_oil->oil.mfcc_origin,
@ -627,7 +627,8 @@ void pim_scan_oil()
if (c_oil->up && c_oil->up->rpf.source_nexthop.interface) { if (c_oil->up && c_oil->up->rpf.source_nexthop.interface) {
ifindex = c_oil->up->rpf.source_nexthop ifindex = c_oil->up->rpf.source_nexthop
.interface->ifindex; .interface->ifindex;
vif_index = pim_if_find_vifindex_by_ifindex(ifindex); vif_index = pim_if_find_vifindex_by_ifindex(c_oil->pim,
ifindex);
/* Pass Current selected NH vif index to mroute download /* Pass Current selected NH vif index to mroute download
*/ */
if (vif_index) if (vif_index)
@ -917,6 +918,7 @@ void igmp_source_forward_start(struct igmp_source *source)
if (nexthop.interface) if (nexthop.interface)
input_iface_vif_index = input_iface_vif_index =
pim_if_find_vifindex_by_ifindex( pim_if_find_vifindex_by_ifindex(
pimg,
nexthop.interface->ifindex); nexthop.interface->ifindex);
} else { } else {
if (PIM_DEBUG_ZEBRA) { if (PIM_DEBUG_ZEBRA) {
@ -1154,6 +1156,7 @@ void pim_forward_start(struct pim_ifchannel *ch)
0)) 0))
input_iface_vif_index = input_iface_vif_index =
pim_if_find_vifindex_by_ifindex( pim_if_find_vifindex_by_ifindex(
pimg,
up->rpf.source_nexthop up->rpf.source_nexthop
.interface->ifindex); .interface->ifindex);
else { else {
@ -1197,8 +1200,8 @@ void pim_forward_start(struct pim_ifchannel *ch)
return; return;
} }
if (PIM_DEBUG_TRACE) { if (PIM_DEBUG_TRACE) {
struct interface *in_intf = struct interface *in_intf = pim_if_find_by_vif_index(
pim_if_find_by_vif_index(input_iface_vif_index); pimg, input_iface_vif_index);
zlog_debug( zlog_debug(
"%s: Update channel_oil IIF %s VIFI %d entry %s ", "%s: Update channel_oil IIF %s VIFI %d entry %s ",
__PRETTY_FUNCTION__, __PRETTY_FUNCTION__,

View File

@ -472,7 +472,7 @@ int pim_zlookup_sg_statistics(struct channel_oil *c_oil)
int count = 0; int count = 0;
int ret; int ret;
struct interface *ifp = struct interface *ifp =
pim_if_find_by_vif_index(c_oil->oil.mfcc_parent); pim_if_find_by_vif_index(c_oil->pim, c_oil->oil.mfcc_parent);
if (PIM_DEBUG_ZEBRA) { if (PIM_DEBUG_ZEBRA) {
struct prefix_sg more; struct prefix_sg more;