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/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);