From baaea325e6a425321296cff40cc7a3b47b53efb3 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Sat, 11 Mar 2017 07:47:46 -0500 Subject: [PATCH] *: Refactor ifindex2ifname to be VRF aware Signed-off-by: Donald Sharp --- bgpd/bgp_nexthop.c | 6 +++--- lib/if.c | 8 +------- lib/if.h | 3 +-- ospf6d/ospf6_route.c | 6 +++--- ospfd/ospf_spf.c | 4 ++-- ospfd/ospf_vty.c | 12 ++++++------ pimd/pim_zebra.c | 2 +- ripd/ripd.c | 14 +++++++------- ripngd/ripngd.c | 16 ++++++++-------- zebra/zebra_mpls.c | 8 ++++---- zebra/zebra_rib.c | 2 +- zebra/zebra_vty.c | 22 +++++++++++----------- 12 files changed, 48 insertions(+), 55 deletions(-) diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index 0cf96101c2..c76ff2c098 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -415,7 +415,7 @@ bgp_show_nexthops (struct vty *vty, struct bgp *bgp, int detail) vty_out(vty, " gate %s, if %s%s", inet_ntop(AF_INET6, &nexthop->gate.ipv6, buf, sizeof (buf)), - ifindex2ifname(nexthop->ifindex), + ifindex2ifname(nexthop->ifindex, VRF_DEFAULT), VTY_NEWLINE); break; case NEXTHOP_TYPE_IPV4: @@ -425,13 +425,13 @@ bgp_show_nexthops (struct vty *vty, struct bgp *bgp, int detail) break; case NEXTHOP_TYPE_IFINDEX: vty_out (vty, " if %s%s", - ifindex2ifname(nexthop->ifindex), VTY_NEWLINE); + ifindex2ifname(nexthop->ifindex, VRF_DEFAULT), VTY_NEWLINE); break; case NEXTHOP_TYPE_IPV4_IFINDEX: vty_out (vty, " gate %s, if %s%s", inet_ntop(AF_INET, &nexthop->gate.ipv4, buf, sizeof (buf)), - ifindex2ifname(nexthop->ifindex), VTY_NEWLINE); + ifindex2ifname(nexthop->ifindex, VRF_DEFAULT), VTY_NEWLINE); break; default: vty_out (vty, " invalid nexthop type %u%s", diff --git a/lib/if.c b/lib/if.c index 2e929ac755..f4f7ad7749 100644 --- a/lib/if.c +++ b/lib/if.c @@ -247,7 +247,7 @@ if_lookup_by_index (ifindex_t ifindex, vrf_id_t vrf_id) } const char * -ifindex2ifname_vrf (ifindex_t ifindex, vrf_id_t vrf_id) +ifindex2ifname (ifindex_t ifindex, vrf_id_t vrf_id) { struct interface *ifp; @@ -255,12 +255,6 @@ ifindex2ifname_vrf (ifindex_t ifindex, vrf_id_t vrf_id) ifp->name : "unknown"; } -const char * -ifindex2ifname (ifindex_t ifindex) -{ - return ifindex2ifname_vrf (ifindex, VRF_DEFAULT); -} - ifindex_t ifname2ifindex_vrf (const char *name, vrf_id_t vrf_id) { diff --git a/lib/if.h b/lib/if.h index f8e89d2cfb..bee783d930 100644 --- a/lib/if.h +++ b/lib/if.h @@ -447,8 +447,7 @@ extern const char *if_link_type_str (enum zebra_link_type); /* Please use ifindex2ifname instead of if_indextoname where possible; ifindex2ifname uses internal interface info, whereas if_indextoname must make a system call. */ -extern const char *ifindex2ifname (ifindex_t); -extern const char *ifindex2ifname_vrf (ifindex_t, vrf_id_t vrf_id); +extern const char *ifindex2ifname (ifindex_t, vrf_id_t vrf_id); /* Please use ifname2ifindex instead of if_nametoindex where possible; ifname2ifindex uses internal interface info, whereas if_nametoindex must diff --git a/ospf6d/ospf6_route.c b/ospf6d/ospf6_route.c index 29956c61a0..b8e5ca6196 100644 --- a/ospf6d/ospf6_route.c +++ b/ospf6d/ospf6_route.c @@ -349,7 +349,7 @@ ospf6_route_zebra_copy_nexthops (struct ospf6_route *route, { const char *ifname; inet_ntop (AF_INET6, &nh->address, buf, sizeof (buf)); - ifname = ifindex2ifname (nh->ifindex); + ifname = ifindex2ifname (nh->ifindex, VRF_DEFAULT); zlog_debug (" nexthop: %s%%%.*s(%d)", buf, IFNAMSIZ, ifname, nh->ifindex); } @@ -1040,7 +1040,7 @@ ospf6_route_show (struct vty *vty, struct ospf6_route *route) /* nexthop */ inet_ntop (AF_INET6, &nh->address, nexthop, sizeof (nexthop)); - ifname = ifindex2ifname (nh->ifindex); + ifname = ifindex2ifname (nh->ifindex, VRF_DEFAULT); if (!i) { @@ -1146,7 +1146,7 @@ ospf6_route_show_detail (struct vty *vty, struct ospf6_route *route) { /* nexthop */ inet_ntop (AF_INET6, &nh->address, nexthop, sizeof (nexthop)); - ifname = ifindex2ifname (nh->ifindex); + ifname = ifindex2ifname (nh->ifindex, VRF_DEFAULT); vty_out (vty, " %s %.*s%s", nexthop, IFNAMSIZ, ifname, VNL); } vty_out (vty, "%s", VNL); diff --git a/ospfd/ospf_spf.c b/ospfd/ospf_spf.c index 077d0e68ad..31f0d9d286 100644 --- a/ospfd/ospf_spf.c +++ b/ospfd/ospf_spf.c @@ -1159,14 +1159,14 @@ ospf_rtrs_print (struct route_table *rtrs) { if (IS_DEBUG_OSPF_EVENT) zlog_debug (" directly attached to %s\r\n", - ifindex2ifname (path->ifindex)); + ifindex2ifname (path->ifindex), VRF_DEFAULT); } else { if (IS_DEBUG_OSPF_EVENT) zlog_debug (" via %s, %s\r\n", inet_ntoa (path->nexthop), - ifindex2ifname (path->ifindex)); + ifindex2ifname (path->ifindex), VRF_DEFAULT); } } } diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 059a17fa9f..71befc84b5 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -7952,11 +7952,11 @@ show_ip_ospf_route_network (struct vty *vty, struct route_table *rt) { if (path->nexthop.s_addr == 0) vty_out (vty, "%24s directly attached to %s%s", - "", ifindex2ifname (path->ifindex), VTY_NEWLINE); + "", ifindex2ifname (path->ifindex, VRF_DEFAULT), VTY_NEWLINE); else vty_out (vty, "%24s via %s, %s%s", "", inet_ntoa (path->nexthop), - ifindex2ifname (path->ifindex), VTY_NEWLINE); + ifindex2ifname (path->ifindex, VRF_DEFAULT), VTY_NEWLINE); } } } @@ -8002,12 +8002,12 @@ show_ip_ospf_route_router (struct vty *vty, struct route_table *rtrs) { if (path->nexthop.s_addr == 0) vty_out (vty, "%24s directly attached to %s%s", - "", ifindex2ifname (path->ifindex), + "", ifindex2ifname (path->ifindex, VRF_DEFAULT), VTY_NEWLINE); else vty_out (vty, "%24s via %s, %s%s", "", inet_ntoa (path->nexthop), - ifindex2ifname (path->ifindex), + ifindex2ifname (path->ifindex, VRF_DEFAULT), VTY_NEWLINE); } } @@ -8051,11 +8051,11 @@ show_ip_ospf_route_external (struct vty *vty, struct route_table *rt) { if (path->nexthop.s_addr == 0) vty_out (vty, "%24s directly attached to %s%s", - "", ifindex2ifname (path->ifindex), VTY_NEWLINE); + "", ifindex2ifname (path->ifindex, VRF_DEFAULT), VTY_NEWLINE); else vty_out (vty, "%24s via %s, %s%s", "", inet_ntoa (path->nexthop), - ifindex2ifname (path->ifindex), + ifindex2ifname (path->ifindex, VRF_DEFAULT), VTY_NEWLINE); } } diff --git a/pimd/pim_zebra.c b/pimd/pim_zebra.c index 1db6616c58..fb62fc3f14 100644 --- a/pimd/pim_zebra.c +++ b/pimd/pim_zebra.c @@ -847,7 +847,7 @@ static int fib_lookup_if_vif_index(struct in_addr addr) pim_inet4_dump("", addr, addr_str, sizeof(addr_str)); zlog_debug("%s %s: found nexthop ifindex=%d (interface %s) for address %s", __FILE__, __PRETTY_FUNCTION__, - first_ifindex, ifindex2ifname(first_ifindex), addr_str); + first_ifindex, ifindex2ifname(first_ifindex, VRF_DEFAULT), addr_str); } vif_index = pim_if_find_vifindex_by_ifindex(first_ifindex); diff --git a/ripd/ripd.c b/ripd/ripd.c index fab31b322f..82e460ced8 100644 --- a/ripd/ripd.c +++ b/ripd/ripd.c @@ -1552,12 +1552,12 @@ rip_redistribute_add (int type, int sub_type, struct prefix_ipv4 *p, if (IS_RIP_DEBUG_EVENT) { if (!nexthop) zlog_debug ("Redistribute new prefix %s/%d on the interface %s", - inet_ntoa(p->prefix), p->prefixlen, - ifindex2ifname(ifindex)); + inet_ntoa(p->prefix), p->prefixlen, + ifindex2ifname(ifindex, VRF_DEFAULT)); else zlog_debug ("Redistribute new prefix %s/%d with nexthop %s on the interface %s", - inet_ntoa(p->prefix), p->prefixlen, inet_ntoa(rinfo->nexthop), - ifindex2ifname(ifindex)); + inet_ntoa(p->prefix), p->prefixlen, inet_ntoa(rinfo->nexthop), + ifindex2ifname(ifindex, VRF_DEFAULT)); } rip_event (RIP_TRIGGERED_UPDATE, 0); @@ -1600,7 +1600,7 @@ rip_redistribute_delete (int type, int sub_type, struct prefix_ipv4 *p, zlog_debug ("Poisone %s/%d on the interface %s with an " "infinity metric [delete]", inet_ntoa(p->prefix), p->prefixlen, - ifindex2ifname(ifindex)); + ifindex2ifname(ifindex, VRF_DEFAULT)); rip_event (RIP_TRIGGERED_UPDATE, 0); } @@ -2660,8 +2660,8 @@ rip_redistribute_withdraw (int type) struct prefix_ipv4 *p = (struct prefix_ipv4 *) &rp->p; zlog_debug ("Poisone %s/%d on the interface %s with an infinity metric [withdraw]", - inet_ntoa(p->prefix), p->prefixlen, - ifindex2ifname(rinfo->ifindex)); + inet_ntoa(p->prefix), p->prefixlen, + ifindex2ifname(rinfo->ifindex, VRF_DEFAULT)); } rip_event (RIP_TRIGGERED_UPDATE, 0); diff --git a/ripngd/ripngd.c b/ripngd/ripngd.c index 591316e50f..caad85457a 100644 --- a/ripngd/ripngd.c +++ b/ripngd/ripngd.c @@ -979,12 +979,12 @@ ripng_redistribute_add (int type, int sub_type, struct prefix_ipv6 *p, if (IS_RIPNG_DEBUG_EVENT) { if (!nexthop) zlog_debug ("Redistribute new prefix %s/%d on the interface %s", - inet6_ntoa(p->prefix), p->prefixlen, - ifindex2ifname(ifindex)); + inet6_ntoa(p->prefix), p->prefixlen, + ifindex2ifname(ifindex, VRF_DEFAULT)); else zlog_debug ("Redistribute new prefix %s/%d with nexthop %s on the interface %s", - inet6_ntoa(p->prefix), p->prefixlen, inet6_ntoa(*nexthop), - ifindex2ifname(ifindex)); + inet6_ntoa(p->prefix), p->prefixlen, inet6_ntoa(*nexthop), + ifindex2ifname(ifindex, VRF_DEFAULT)); } ripng_event (RIPNG_TRIGGERED_UPDATE, 0); @@ -1032,7 +1032,7 @@ ripng_redistribute_delete (int type, int sub_type, struct prefix_ipv6 *p, zlog_debug ("Poisone %s/%d on the interface %s with an " "infinity metric [delete]", inet6_ntoa (p->prefix), p->prefixlen, - ifindex2ifname (ifindex)); + ifindex2ifname (ifindex, VRF_DEFAULT)); ripng_event (RIPNG_TRIGGERED_UPDATE, 0); } @@ -1074,8 +1074,8 @@ ripng_redistribute_withdraw (int type) struct prefix_ipv6 *p = (struct prefix_ipv6 *) &rp->p; zlog_debug ("Poisone %s/%d on the interface %s [withdraw]", - inet6_ntoa(p->prefix), p->prefixlen, - ifindex2ifname(rinfo->ifindex)); + inet6_ntoa(p->prefix), p->prefixlen, + ifindex2ifname(rinfo->ifindex, VRF_DEFAULT)); } ripng_event (RIPNG_TRIGGERED_UPDATE, 0); @@ -2066,7 +2066,7 @@ DEFUN (show_ipv6_ripng, if ((rinfo->type == ZEBRA_ROUTE_RIPNG) && (rinfo->sub_type == RIPNG_ROUTE_RTE)) { - len = vty_out (vty, "%s", ifindex2ifname(rinfo->ifindex)); + len = vty_out (vty, "%s", ifindex2ifname(rinfo->ifindex, VRF_DEFAULT)); } else if (rinfo->metric == RIPNG_METRIC_INFINITY) { len = vty_out (vty, "kill"); diff --git a/zebra/zebra_mpls.c b/zebra/zebra_mpls.c index 55a2745b53..5a3ed7545d 100644 --- a/zebra/zebra_mpls.c +++ b/zebra/zebra_mpls.c @@ -869,7 +869,7 @@ nhlfe_json (zebra_nhlfe_t *nhlfe) inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ)); if (nexthop->ifindex) - json_object_string_add(json_nhlfe, "interface", ifindex2ifname (nexthop->ifindex)); + json_object_string_add(json_nhlfe, "interface", ifindex2ifname (nexthop->ifindex, VRF_DEFAULT)); break; default: break; @@ -900,14 +900,14 @@ nhlfe_print (zebra_nhlfe_t *nhlfe, struct vty *vty) case NEXTHOP_TYPE_IPV4_IFINDEX: vty_out (vty, " via %s", inet_ntoa (nexthop->gate.ipv4)); if (nexthop->ifindex) - vty_out (vty, " dev %s", ifindex2ifname (nexthop->ifindex)); + vty_out (vty, " dev %s", ifindex2ifname (nexthop->ifindex, VRF_DEFAULT)); break; case NEXTHOP_TYPE_IPV6: case NEXTHOP_TYPE_IPV6_IFINDEX: vty_out (vty, " via %s", inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ)); if (nexthop->ifindex) - vty_out (vty, " dev %s", ifindex2ifname (nexthop->ifindex)); + vty_out (vty, " dev %s", ifindex2ifname (nexthop->ifindex, VRF_DEFAULT)); break; default: break; @@ -1183,7 +1183,7 @@ snhlfe2str (zebra_snhlfe_t *snhlfe, char *buf, int size) case NEXTHOP_TYPE_IPV6_IFINDEX: inet_ntop (AF_INET6, &snhlfe->gate.ipv6, buf, size); if (snhlfe->ifindex) - strcat (buf, ifindex2ifname (snhlfe->ifindex)); + strcat (buf, ifindex2ifname (snhlfe->ifindex, VRF_DEFAULT)); break; default: break; diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 76c32c3971..f5b54a2c04 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -1021,7 +1021,7 @@ nexthop_active_check (struct route_node *rn, struct rib *rib, srcdest_rnode2str(rn, buf, sizeof(buf)); zlog_debug("%u:%s: Filtering out with NH out %s due to route map", rib->vrf_id, buf, - ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id)); + ifindex2ifname (nexthop->ifindex, rib->vrf_id)); } UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE); } diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 1c315670bd..05c1aa274a 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -725,7 +725,7 @@ vty_show_ip_route_detail (struct vty *vty, struct route_node *rn, int mcast) vty_out (vty, " %s", inet_ntoa (nexthop->gate.ipv4)); if (nexthop->ifindex) vty_out (vty, ", via %s", - ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id)); + ifindex2ifname (nexthop->ifindex, rib->vrf_id)); break; case NEXTHOP_TYPE_IPV6: case NEXTHOP_TYPE_IPV6_IFINDEX: @@ -733,11 +733,11 @@ vty_show_ip_route_detail (struct vty *vty, struct route_node *rn, int mcast) inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ)); if (nexthop->ifindex) vty_out (vty, ", via %s", - ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id)); + ifindex2ifname (nexthop->ifindex, rib->vrf_id)); break; case NEXTHOP_TYPE_IFINDEX: vty_out (vty, " directly connected, %s", - ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id)); + ifindex2ifname (nexthop->ifindex, rib->vrf_id)); break; case NEXTHOP_TYPE_BLACKHOLE: vty_out (vty, " directly connected, Null0"); @@ -874,7 +874,7 @@ vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib, if (nexthop->ifindex) { json_object_int_add(json_nexthop, "interfaceIndex", nexthop->ifindex); - json_object_string_add(json_nexthop, "interfaceName", ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id)); + json_object_string_add(json_nexthop, "interfaceName", ifindex2ifname (nexthop->ifindex, rib->vrf_id)); } break; case NEXTHOP_TYPE_IPV6: @@ -885,14 +885,14 @@ vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib, if (nexthop->ifindex) { json_object_int_add(json_nexthop, "interfaceIndex", nexthop->ifindex); - json_object_string_add(json_nexthop, "interfaceName", ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id)); + json_object_string_add(json_nexthop, "interfaceName", ifindex2ifname (nexthop->ifindex, rib->vrf_id)); } break; case NEXTHOP_TYPE_IFINDEX: json_object_boolean_true_add(json_nexthop, "directlyConnected"); json_object_int_add(json_nexthop, "interfaceIndex", nexthop->ifindex); - json_object_string_add(json_nexthop, "interfaceName", ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id)); + json_object_string_add(json_nexthop, "interfaceName", ifindex2ifname (nexthop->ifindex, rib->vrf_id)); break; case NEXTHOP_TYPE_BLACKHOLE: json_object_boolean_true_add(json_nexthop, "blackhole"); @@ -975,7 +975,7 @@ vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib, vty_out (vty, " via %s", inet_ntoa (nexthop->gate.ipv4)); if (nexthop->ifindex) vty_out (vty, ", %s", - ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id)); + ifindex2ifname (nexthop->ifindex, rib->vrf_id)); break; case NEXTHOP_TYPE_IPV6: case NEXTHOP_TYPE_IPV6_IFINDEX: @@ -983,12 +983,12 @@ vty_show_ip_route (struct vty *vty, struct route_node *rn, struct rib *rib, inet_ntop (AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ)); if (nexthop->ifindex) vty_out (vty, ", %s", - ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id)); + ifindex2ifname (nexthop->ifindex, rib->vrf_id)); break; case NEXTHOP_TYPE_IFINDEX: vty_out (vty, " is directly connected, %s", - ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id)); + ifindex2ifname (nexthop->ifindex, rib->vrf_id)); break; case NEXTHOP_TYPE_BLACKHOLE: vty_out (vty, " is directly connected, Null0"); @@ -2292,7 +2292,7 @@ static_config_ipv4 (struct vty *vty, safi_t safi, const char *cmd) case STATIC_IPV6_GATEWAY_IFINDEX: vty_out (vty, " %s %s", inet_ntop (AF_INET6, &si->addr.ipv6, buf, BUFSIZ), - ifindex2ifname_vrf (si->ifindex, si->vrf_id)); + ifindex2ifname (si->ifindex, si->vrf_id)); break; } @@ -3784,7 +3784,7 @@ static_config_ipv6 (struct vty *vty) case STATIC_IPV6_GATEWAY_IFINDEX: vty_out (vty, " %s %s", inet_ntop (AF_INET6, &si->addr.ipv6, buf, BUFSIZ), - ifindex2ifname_vrf (si->ifindex, si->vrf_id)); + ifindex2ifname (si->ifindex, si->vrf_id)); break; } -- 2.39.5