From 7cfc7bcfe77cc560ae4746b5b49ab17574d8c8cb Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Sun, 21 May 2017 08:29:56 -0400 Subject: [PATCH] pimd: Convert vif and ifindex lookups to use 'struct pim_instance *' Signed-off-by: Donald Sharp --- pimd/pim_cmd.c | 241 +++++++++++++++++++++------------------------ pimd/pim_iface.c | 29 ++---- pimd/pim_iface.h | 6 +- pimd/pim_mroute.c | 3 +- pimd/pim_nht.c | 5 +- pimd/pim_oil.c | 2 +- pimd/pim_static.c | 3 +- pimd/pim_zebra.c | 29 +++--- pimd/pim_zlookup.c | 2 +- 9 files changed, 149 insertions(+), 171 deletions(-) diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 86dda43e9..580486bad 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -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, - const char *group, u_char uj) +static void pim_show_state(struct pim_instance *pim, struct vty *vty, + const char *src_or_group, const char *group, + u_char uj) { struct channel_oil *c_oil; struct listnode *node; @@ -1875,7 +1876,7 @@ static void pim_show_state(struct vty *vty, const char *src_or_group, sizeof(grp_str)); pim_inet4_dump("", c_oil->oil.mfcc_origin, 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) 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) 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( oif_uptime, sizeof(oif_uptime), now - c_oil->oif_creation[oif_vif_index]); @@ -3449,7 +3450,7 @@ DEFUN (show_ip_pim_state, } else if (argc == 5) 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; } @@ -3750,7 +3751,7 @@ DEFUN (show_ip_multicast, 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 channel_oil *c_oil; @@ -3770,8 +3771,6 @@ static void show_mroute(struct vty *vty, u_char uj) int oif_vif_index; struct interface *ifp_in; char proto[100]; - struct vrf *vrf; - struct pim_instance *pim; if (uj) { json = json_object_new_object(); @@ -3793,7 +3792,7 @@ static void show_mroute(struct vty *vty, u_char uj) sizeof(grp_str)); pim_inet4_dump("", c_oil->oil.mfcc_origin, 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) strcpy(in_ifname, ifp_in->name); @@ -3846,7 +3845,7 @@ static void show_mroute(struct vty *vty, u_char uj) if (ttl < 1) 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( oif_uptime, sizeof(oif_uptime), 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 */ - RB_FOREACH(vrf, vrf_name_head, &vrfs_by_name) - { - pim = vrf->info; - if (!pim) + for (ALL_LIST_ELEMENTS_RO(pim->static_routes, node, s_route)) { + first = 1; + + if (!s_route->c_oil.installed) continue; - for (ALL_LIST_ELEMENTS_RO(pim->static_routes, node, s_route)) { - first = 1; + pim_inet4_dump("", s_route->group, grp_str, + sizeof(grp_str)); + pim_inet4_dump("", 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) - continue; + if (ifp_in) + strcpy(in_ifname, ifp_in->name); + else + strcpy(in_ifname, ""); - pim_inet4_dump("", s_route->group, grp_str, - sizeof(grp_str)); - pim_inet4_dump("", s_route->source, src_str, - sizeof(src_str)); - ifp_in = pim_if_find_by_vif_index(s_route->iif); - found_oif = 0; + if (uj) { - if (ifp_in) - strcpy(in_ifname, ifp_in->name); - else - strcpy(in_ifname, ""); + /* Find the group, create it if it doesn't exist */ + json_object_object_get_ex(json, grp_str, &json_group); - if (uj) { + if (!json_group) { + json_group = json_object_new_object(); + json_object_object_add(json, grp_str, + json_group); + } - /* Find the group, create it if it doesn't exist - */ - json_object_object_get_ex(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_group) { - json_group = json_object_new_object(); - json_object_object_add(json, grp_str, - json_group); - } + 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"); + } - /* 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); + for (oif_vif_index = 0; oif_vif_index < MAXVIFS; + ++oif_vif_index) { + struct interface *ifp_out; + char oif_uptime[10]; + int ttl; - if (!json_source) { - json_source = json_object_new_object(); - json_object_object_add(json_group, - src_str, - json_source); - } + ttl = s_route->oif_ttls[oif_vif_index]; + if (ttl < 1) + continue; - json_object_string_add(json_source, "iif", - in_ifname); - json_oil = NULL; - } else { - strcpy(proto, "STATIC"); - } + ifp_out = pim_if_find_by_vif_index(pim, oif_vif_index); + pim_time_uptime( + oif_uptime, sizeof(oif_uptime), + now + - s_route->c_oil + .oif_creation[oif_vif_index]); + found_oif = 1; - 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; - - 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, ""); + if (ifp_out) + strcpy(out_ifname, ifp_out->name); + else + strcpy(out_ifname, ""); - 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; - } + 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); } - } - - if (!uj && !found_oif) { + 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, - "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) { @@ -4105,7 +4084,7 @@ DEFUN (show_ip_mroute, JSON_STR) { u_char uj = use_json(argc, argv); - show_mroute(vty, uj); + show_mroute(pimg, vty, uj); return CMD_SUCCESS; } diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index ef06fdfb8..cc7e03935 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -1054,28 +1054,19 @@ int pim_if_del_vif(struct interface *ifp) } // 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 interface *ifp; - struct pim_instance *pim; - struct vrf *vrf; - RB_FOREACH(vrf, vrf_name_head, &vrfs_by_name) - { - pim = vrf->info; - if (!pim) - continue; - - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), ifnode, - ifp)) { - if (ifp->info) { - struct pim_interface *pim_ifp; - pim_ifp = ifp->info; + for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), ifnode, ifp)) { + if (ifp->info) { + struct pim_interface *pim_ifp; + pim_ifp = ifp->info; - if (vif_index == pim_ifp->mroute_vif_index) - return ifp; - } + 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 */ -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 interface *ifp; - ifp = if_lookup_by_index(ifindex, pimg->vrf_id); + ifp = if_lookup_by_index(ifindex, pim->vrf_id); if (!ifp || !ifp->info) return -1; pim_ifp = ifp->info; diff --git a/pimd/pim_iface.h b/pimd/pim_iface.h index ef81152af..e4b1b8e67 100644 --- a/pimd/pim_iface.h +++ b/pimd/pim_iface.h @@ -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_del_vif_all(struct pim_instance *pim); -struct interface *pim_if_find_by_vif_index(ifindex_t vif_index); -int pim_if_find_vifindex_by_ifindex(ifindex_t ifindex); +struct interface *pim_if_find_by_vif_index(struct pim_instance *pim, + 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); uint16_t pim_if_effective_propagation_delay_msec(struct interface *ifp); diff --git a/pimd/pim_mroute.c b/pimd/pim_mroute.c index 8b9269518..4c0820b60 100644 --- a/pimd/pim_mroute.c +++ b/pimd/pim_mroute.c @@ -197,6 +197,7 @@ static int pim_mroute_msg_nocache(int fd, struct interface *ifp, if (up->channel_oil->oil.mfcc_parent >= MAXVIFS) { int vif_index = 0; vif_index = pim_if_find_vifindex_by_ifindex( + pim_ifp->pim, up->rpf.source_nexthop.interface->ifindex); 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 { 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) return 0; diff --git a/pimd/pim_nht.c b/pimd/pim_nht.c index eb8bfa711..1cc5e78da 100644 --- a/pimd/pim_nht.c +++ b/pimd/pim_nht.c @@ -358,7 +358,8 @@ static int pim_update_upstream_nh(struct pim_instance *pim, if (up->channel_oil) { ifindex_t 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 */ 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); } - 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 (PIM_DEBUG_ZEBRA) { diff --git a/pimd/pim_oil.c b/pimd/pim_oil.c index d4398d1c2..375acbc66 100644 --- a/pimd/pim_oil.c +++ b/pimd/pim_oil.c @@ -169,7 +169,7 @@ struct channel_oil *pim_channel_oil_add(struct prefix_sg *sg, 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) { /* warning only */ zlog_warn( diff --git a/pimd/pim_static.c b/pimd/pim_static.c index 981335ea1..980933aa8 100644 --- a/pimd/pim_static.c +++ b/pimd/pim_static.c @@ -358,7 +358,8 @@ int pim_static_write_mroute(struct vty *vty, struct pim_instance *pim, for (i = 0; i < MAXVIFS; i++) if (sroute->oif_ttls[i]) { struct interface *oifp = - pim_if_find_by_vif_index(i); + pim_if_find_by_vif_index(pim, + i); if (sroute->source.s_addr == 0) vty_out(vty, " ip mroute %s %s\n", diff --git a/pimd/pim_zebra.c b/pimd/pim_zebra.c index f91129321..e77086059 100644 --- a/pimd/pim_zebra.c +++ b/pimd/pim_zebra.c @@ -545,10 +545,10 @@ void pim_scan_individual_oil(struct channel_oil *c_oil, int in_vif_index) } if (PIM_DEBUG_ZEBRA) { - struct interface *old_iif = - pim_if_find_by_vif_index(c_oil->oil.mfcc_parent); - struct interface *new_iif = - pim_if_find_by_vif_index(input_iface_vif_index); + struct interface *old_iif = pim_if_find_by_vif_index( + c_oil->pim, c_oil->oil.mfcc_parent); + struct interface *new_iif = pim_if_find_by_vif_index( + c_oil->pim, input_iface_vif_index); char source_str[INET_ADDRSTRLEN]; char group_str[INET_ADDRSTRLEN]; pim_inet4_dump("", 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 ? */ if (c_oil->oil.mfcc_ttls[input_iface_vif_index]) { - struct interface *new_iif = - pim_if_find_by_vif_index(input_iface_vif_index); + struct interface *new_iif = pim_if_find_by_vif_index( + c_oil->pim, input_iface_vif_index); if (PIM_DEBUG_ZEBRA) { 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_DEBUG_MROUTE) { /* just log warning */ - struct interface *old_iif = - pim_if_find_by_vif_index(old_vif_index); - struct interface *new_iif = - pim_if_find_by_vif_index(input_iface_vif_index); + struct interface *old_iif = pim_if_find_by_vif_index( + c_oil->pim, old_vif_index); + struct interface *new_iif = pim_if_find_by_vif_index( + c_oil->pim, input_iface_vif_index); char source_str[INET_ADDRSTRLEN]; char group_str[INET_ADDRSTRLEN]; pim_inet4_dump("", c_oil->oil.mfcc_origin, @@ -627,7 +627,8 @@ void pim_scan_oil() if (c_oil->up && c_oil->up->rpf.source_nexthop.interface) { ifindex = c_oil->up->rpf.source_nexthop .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 */ if (vif_index) @@ -917,6 +918,7 @@ void igmp_source_forward_start(struct igmp_source *source) if (nexthop.interface) input_iface_vif_index = pim_if_find_vifindex_by_ifindex( + pimg, nexthop.interface->ifindex); } else { if (PIM_DEBUG_ZEBRA) { @@ -1154,6 +1156,7 @@ void pim_forward_start(struct pim_ifchannel *ch) 0)) input_iface_vif_index = pim_if_find_vifindex_by_ifindex( + pimg, up->rpf.source_nexthop .interface->ifindex); else { @@ -1197,8 +1200,8 @@ void pim_forward_start(struct pim_ifchannel *ch) return; } if (PIM_DEBUG_TRACE) { - struct interface *in_intf = - pim_if_find_by_vif_index(input_iface_vif_index); + struct interface *in_intf = pim_if_find_by_vif_index( + pimg, input_iface_vif_index); zlog_debug( "%s: Update channel_oil IIF %s VIFI %d entry %s ", __PRETTY_FUNCTION__, diff --git a/pimd/pim_zlookup.c b/pimd/pim_zlookup.c index bde5042b6..26d0dffe7 100644 --- a/pimd/pim_zlookup.c +++ b/pimd/pim_zlookup.c @@ -472,7 +472,7 @@ int pim_zlookup_sg_statistics(struct channel_oil *c_oil) int count = 0; int ret; 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) { struct prefix_sg more; -- 2.39.5