]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ospf6d, bgpd: avoid calling if_nametoindex
authorFeng Lu <lu.feng@6wind.com>
Fri, 22 May 2015 09:39:55 +0000 (11:39 +0200)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 9 Jun 2016 13:25:49 +0000 (09:25 -0400)
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>
(cherry picked from commit 395828eea809e8b2b8c5824d3639cefedd7aa9f0)

bgpd/bgp_network.c
bgpd/bgp_zebra.c
ospf6d/ospf6_route.c

index c797d0d23609935e2f800e3b76f8df9372249cf8..61972aabf1f145cb4afacacb6a3833c55dfc605f 100644 (file)
@@ -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))
index 06106d87f671b28506794cfdb59083d7d9d2bfe2..ceded236cd66cb7bf57d3863018b0896a21719bd 100644 (file)
@@ -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;
index d174cfbb9164e8b9ce140c1d59e13a3cda5509ce..0a98c8f082aa8c23c049a60961ff6a97bcb5bdd3 100644 (file)
@@ -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);