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 <lu.feng@6wind.com>
Reviewed-by: Alain Ritoux <alain.ritoux@6wind.com>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Acked-by: Vincent JARDIN <vincent.jardin@6wind.com>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c
index 9765096..7059e8a 100644
--- a/bgpd/bgp_network.c
+++ b/bgpd/bgp_network.c
@@ -402,7 +402,7 @@
 
 #ifdef HAVE_IPV6
   if (peer->ifname)
-    ifindex = if_nametoindex (peer->ifname);
+    ifindex = ifname2ifindex (peer->ifname);
 #endif /* HAVE_IPV6 */
 
   if (BGP_DEBUG (events, EVENTS))
diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c
index f18d916..8ae7f46 100644
--- a/bgpd/bgp_zebra.c
+++ b/bgpd/bgp_zebra.c
@@ -572,7 +572,7 @@
       if (IN6_IS_ADDR_LINKLOCAL (&local->sin6.sin6_addr))
 	{
 	  if (peer->ifname)
-	    ifp = if_lookup_by_index (if_nametoindex (peer->ifname));
+	    ifp = if_lookup_by_name (peer->ifname);
 	}
       else
 	ifp = if_lookup_by_ipv6 (&local->sin6.sin6_addr);
@@ -792,7 +792,7 @@
       if (IN6_IS_ADDR_LINKLOCAL (nexthop) && ! ifindex)
 	{
 	  if (info->peer->ifname)
-	    ifindex = if_nametoindex (info->peer->ifname);
+	    ifindex = ifname2ifindex (info->peer->ifname);
 	  else if (info->peer->nexthop.ifp)
 	    ifindex = info->peer->nexthop.ifp->ifindex;
 	}
@@ -913,7 +913,7 @@
 
       if (IN6_IS_ADDR_LINKLOCAL (nexthop) && ! ifindex)
 	if (info->peer->ifname)
-	  ifindex = if_nametoindex (info->peer->ifname);
+	  ifindex = ifname2ifindex (info->peer->ifname);
 
       api.flags = flags;
       api.type = ZEBRA_ROUTE_BGP;
diff --git a/ospf6d/ospf6_route.c b/ospf6d/ospf6_route.c
index 3092773..5057556 100644
--- a/ospf6d/ospf6_route.c
+++ b/ospf6d/ospf6_route.c
@@ -792,7 +792,8 @@
 {
   int i;
   char destination[64], nexthop[64];
-  char duration[16], ifname[IFNAMSIZ];
+  char duration[16];
+  const char *ifname;
   struct timeval now, res;
 
   quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
@@ -812,8 +813,7 @@
   /* nexthop */
   inet_ntop (AF_INET6, &route->nexthop[0].address, nexthop,
              sizeof (nexthop));
-  if (! if_indextoname (route->nexthop[0].ifindex, ifname))
-    snprintf (ifname, sizeof (ifname), "%d", route->nexthop[0].ifindex);
+  ifname = ifindex2ifname (route->nexthop[0].ifindex);
 
   vty_out (vty, "%c%1s %2s %-30s %-25s %6.*s %s%s",
            (ospf6_route_is_best (route) ? '*' : ' '),
@@ -827,8 +827,7 @@
       /* nexthop */
       inet_ntop (AF_INET6, &route->nexthop[i].address, nexthop,
                  sizeof (nexthop));
-      if (! if_indextoname (route->nexthop[i].ifindex, ifname))
-        snprintf (ifname, sizeof (ifname), "%d", route->nexthop[i].ifindex);
+      ifname = ifindex2ifname (route->nexthop[i].ifindex);
 
       vty_out (vty, "%c%1s %2s %-30s %-25s %6.*s %s%s",
                ' ', "", "", "", nexthop, IFNAMSIZ, ifname, "", VNL);
@@ -838,7 +837,8 @@
 void
 ospf6_route_show_detail (struct vty *vty, struct ospf6_route *route)
 {
-  char destination[64], nexthop[64], ifname[IFNAMSIZ];
+  const char *ifname;
+  char destination[64], nexthop[64];
   char area_id[16], id[16], adv_router[16], capa[16], options[16];
   struct timeval now, res;
   char duration[16];
@@ -924,8 +924,7 @@
       /* nexthop */
       inet_ntop (AF_INET6, &route->nexthop[i].address, nexthop,
                  sizeof (nexthop));
-      if (! if_indextoname (route->nexthop[i].ifindex, ifname))
-        snprintf (ifname, sizeof (ifname), "%d", route->nexthop[i].ifindex);
+      ifname = ifindex2ifname (route->nexthop[i].ifindex);
       vty_out (vty, "  %s %.*s%s", nexthop, IFNAMSIZ, ifname, VNL);
     }
   vty_out (vty, "%s", VNL);
diff --git a/ospf6d/ospf6_zebra.c b/ospf6d/ospf6_zebra.c
index 85f7064..ac3235c 100644
--- a/ospf6d/ospf6_zebra.c
+++ b/ospf6d/ospf6_zebra.c
@@ -443,11 +443,10 @@
     {
       if (IS_OSPF6_DEBUG_ZEBRA (SEND))
 	{
-	  char ifname[IFNAMSIZ];
+	  const char *ifname;
 	  inet_ntop (AF_INET6, &request->nexthop[i].address,
 		     buf, sizeof (buf));
-	  if (!if_indextoname(request->nexthop[i].ifindex, ifname))
-	    strlcpy(ifname, "unknown", sizeof(ifname));
+	  ifname = ifindex2ifname (request->nexthop[i].ifindex);
 	  zlog_debug ("  nexthop: %s%%%.*s(%d)", buf, IFNAMSIZ, ifname,
 		      request->nexthop[i].ifindex);
 	}