Browse Source

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>
Feng Lu 5 years ago
parent
commit
395828eea8
4 changed files with 13 additions and 15 deletions
  1. 1 1
      bgpd/bgp_network.c
  2. 3 3
      bgpd/bgp_zebra.c
  3. 7 8
      ospf6d/ospf6_route.c
  4. 2 3
      ospf6d/ospf6_zebra.c

+ 1 - 1
bgpd/bgp_network.c

@@ -402,7 +402,7 @@ bgp_connect (struct peer *peer)
 
 #ifdef HAVE_IPV6
   if (peer->ifname)
-    ifindex = if_nametoindex (peer->ifname);
+    ifindex = ifname2ifindex (peer->ifname);
 #endif /* HAVE_IPV6 */
 
   if (BGP_DEBUG (events, EVENTS))

+ 3 - 3
bgpd/bgp_zebra.c

@@ -572,7 +572,7 @@ bgp_nexthop_set (union sockunion *local, union sockunion *remote,
       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 @@ bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp, sa
       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 @@ bgp_zebra_withdraw (struct prefix *p, struct bgp_info *info, safi_t safi)
 
       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;

+ 7 - 8
ospf6d/ospf6_route.c

@@ -792,7 +792,8 @@ ospf6_route_show (struct vty *vty, struct ospf6_route *route)
 {
   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 @@ ospf6_route_show (struct vty *vty, struct ospf6_route *route)
   /* 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 @@ ospf6_route_show (struct vty *vty, struct ospf6_route *route)
       /* 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 @@ ospf6_route_show (struct vty *vty, struct ospf6_route *route)
 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 @@ ospf6_route_show_detail (struct vty *vty, struct ospf6_route *route)
       /* 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);

+ 2 - 3
ospf6d/ospf6_zebra.c

@@ -443,11 +443,10 @@ ospf6_zebra_route_update (int type, struct ospf6_route *request)
     {
       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);
 	}