From: Feng Lu Date: Fri, 22 May 2015 09:39:55 +0000 (+0200) Subject: ospf6d, bgpd: avoid calling if_nametoindex X-Git-Tag: frr-2.0-rc1~550^2~13 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=322e59645d6d5a0863c383faf4fd6900ab7c630f;p=mirror%2Ffrr.git ospf6d, bgpd: avoid calling if_nametoindex As the comments in if.h, it is better to call ifname2ifindex() instead of if_nametoindex(). And ifname2ifindex() can work for VRF by appending a parameter while if_nametoindex() can not. Signed-off-by: Feng Lu Reviewed-by: Alain Ritoux Signed-off-by: Nicolas Dichtel Acked-by: Vincent JARDIN Signed-off-by: David Lamparter (cherry picked from commit 395828eea809e8b2b8c5824d3639cefedd7aa9f0) --- diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c index c797d0d236..61972aabf1 100644 --- a/bgpd/bgp_network.c +++ b/bgpd/bgp_network.c @@ -619,7 +619,7 @@ bgp_connect (struct peer *peer) #ifdef HAVE_IPV6 if (peer->conf_if || peer->ifname) - ifindex = if_nametoindex (peer->conf_if ? peer->conf_if : peer->ifname); + ifindex = ifname2ifindex (peer->conf_if ? peer->conf_if : peer->ifname); #endif /* HAVE_IPV6 */ if (bgp_debug_neighbor_events(peer)) diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 06106d87f6..ceded236cd 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -1038,7 +1038,7 @@ bgp_nexthop_set (union sockunion *local, union sockunion *remote, if (IN6_IS_ADDR_LINKLOCAL (&local->sin6.sin6_addr)) { if (peer->conf_if || peer->ifname) - ifp = if_lookup_by_index_vrf (if_nametoindex (peer->conf_if ? peer->conf_if : peer->ifname), peer->bgp->vrf_id); + ifp = if_lookup_by_name_vrf (peer->conf_if ? peer->conf_if : peer->ifname, peer->bgp->vrf_id); } else if (peer->update_if) ifp = if_lookup_by_name_vrf (peer->update_if, peer->bgp->vrf_id); @@ -1513,7 +1513,7 @@ bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp, if (!ifindex) { if (mpinfo->peer->conf_if || mpinfo->peer->ifname) - ifindex = if_nametoindex (mpinfo->peer->conf_if ? mpinfo->peer->conf_if : mpinfo->peer->ifname); + ifindex = ifname2ifindex (mpinfo->peer->conf_if ? mpinfo->peer->conf_if : mpinfo->peer->ifname); else if (mpinfo->peer->nexthop.ifp) ifindex = mpinfo->peer->nexthop.ifp->ifindex; } @@ -1705,7 +1705,7 @@ bgp_zebra_withdraw (struct prefix *p, struct bgp_info *info, safi_t safi) struct zapi_ipv6 api; assert (info->attr->extra); - + api.vrf_id = peer->bgp->vrf_id; api.flags = flags; api.type = ZEBRA_ROUTE_BGP; diff --git a/ospf6d/ospf6_route.c b/ospf6d/ospf6_route.c index d174cfbb91..0a98c8f082 100644 --- a/ospf6d/ospf6_route.c +++ b/ospf6d/ospf6_route.c @@ -347,10 +347,9 @@ ospf6_route_zebra_copy_nexthops (struct ospf6_route *route, { if (IS_OSPF6_DEBUG_ZEBRA (SEND)) { - char ifname[IFNAMSIZ]; + const char *ifname; inet_ntop (AF_INET6, &nh->address, buf, sizeof (buf)); - if (!if_indextoname(nh->ifindex, ifname)) - strlcpy(ifname, "unknown", sizeof(ifname)); + ifname = ifindex2ifname (nh->ifindex); zlog_debug (" nexthop: %s%%%.*s(%d)", buf, IFNAMSIZ, ifname, nh->ifindex); } @@ -1015,7 +1014,8 @@ ospf6_route_show (struct vty *vty, struct ospf6_route *route) { int i; char destination[PREFIX2STR_BUFFER], nexthop[64]; - char duration[16], ifname[IFNAMSIZ]; + char duration[16]; + const char *ifname; struct timeval now, res; struct listnode *node; struct ospf6_nexthop *nh; @@ -1034,15 +1034,13 @@ ospf6_route_show (struct vty *vty, struct ospf6_route *route) else prefix2str (&route->prefix, destination, sizeof (destination)); - i = 0; for (ALL_LIST_ELEMENTS_RO (route->nh_list, node, nh)) { /* nexthop */ inet_ntop (AF_INET6, &nh->address, nexthop, sizeof (nexthop)); - if (! if_indextoname (nh->ifindex, ifname)) - snprintf (ifname, sizeof (ifname), "%d", nh->ifindex); + ifname = ifindex2ifname (nh->ifindex); if (!i) { @@ -1062,7 +1060,8 @@ ospf6_route_show (struct vty *vty, struct ospf6_route *route) void ospf6_route_show_detail (struct vty *vty, struct ospf6_route *route) { - char destination[PREFIX2STR_BUFFER], nexthop[64], ifname[IFNAMSIZ]; + const char *ifname; + char destination[PREFIX2STR_BUFFER], nexthop[64]; char area_id[16], id[16], adv_router[16], capa[16], options[16]; struct timeval now, res; char duration[16]; @@ -1147,8 +1146,7 @@ ospf6_route_show_detail (struct vty *vty, struct ospf6_route *route) { /* nexthop */ inet_ntop (AF_INET6, &nh->address, nexthop, sizeof (nexthop)); - if (! if_indextoname (nh->ifindex, ifname)) - snprintf (ifname, sizeof (ifname), "%d", nh->ifindex); + ifname = ifindex2ifname (nh->ifindex); vty_out (vty, " %s %.*s%s", nexthop, IFNAMSIZ, ifname, VNL); } vty_out (vty, "%s", VNL);