While benefit from using ll_name_to_index() with populated
cache can potentially be exploited only in few places
(e.g. bridge fdb/mdb/vlan show routines) there is another
advantage of ll_name_to_index() over plain if_nametoindex():

  in case of if_nametoindex() failure ll_name_to_index()
  will attempt to get index from common name in form "if%d"
  that may be returned from ll_index_to_name().

This makes output from ip(8) coherent with it's input.

Note that most of the code already switched from plain
if_nametoindex() to ll_name_to_index() to cached variant.

Signed-off-by: Serhey Popovych <serhe.popov...@gmail.com>
---
 bridge/fdb.c          |    4 ++--
 bridge/mdb.c          |    2 +-
 bridge/vlan.c         |    2 +-
 ip/iplink_bond.c      |    4 ++--
 ip/iplink_bridge.c    |    2 +-
 ip/iplink_vxlan.c     |    2 +-
 ip/iproute_lwtunnel.c |    4 ++--
 ip/link_gre.c         |    2 +-
 ip/link_gre6.c        |    2 +-
 ip/link_ip6tnl.c      |    2 +-
 ip/link_iptnl.c       |    2 +-
 ip/link_vti.c         |    2 +-
 ip/link_vti6.c        |    2 +-
 13 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/bridge/fdb.c b/bridge/fdb.c
index 4d55fb0..8b133f9 100644
--- a/bridge/fdb.c
+++ b/bridge/fdb.c
@@ -374,7 +374,7 @@ static int fdb_show(int argc, char **argv)
 
        /*we'll keep around filter_dev for older kernels */
        if (filter_dev) {
-               filter_index = if_nametoindex(filter_dev);
+               filter_index = ll_name_to_index(filter_dev);
                if (filter_index == 0) {
                        fprintf(stderr, "Cannot find device \"%s\"\n",
                                filter_dev);
@@ -463,7 +463,7 @@ static int fdb_modify(int cmd, int flags, int argc, char 
**argv)
                                invarg("invalid VNI\n", *argv);
                } else if (strcmp(*argv, "via") == 0) {
                        NEXT_ARG();
-                       via = if_nametoindex(*argv);
+                       via = ll_name_to_index(*argv);
                        if (via == 0)
                                invarg("invalid device\n", *argv);
                } else if (strcmp(*argv, "self") == 0) {
diff --git a/bridge/mdb.c b/bridge/mdb.c
index 7b7b81f..62dc8a0 100644
--- a/bridge/mdb.c
+++ b/bridge/mdb.c
@@ -311,7 +311,7 @@ static int mdb_show(int argc, char **argv)
        }
 
        if (filter_dev) {
-               filter_index = if_nametoindex(filter_dev);
+               filter_index = ll_name_to_index(filter_dev);
                if (filter_index == 0) {
                        fprintf(stderr, "Cannot find device \"%s\"\n",
                                filter_dev);
diff --git a/bridge/vlan.c b/bridge/vlan.c
index 69fb542..f42d7e6 100644
--- a/bridge/vlan.c
+++ b/bridge/vlan.c
@@ -567,7 +567,7 @@ static int vlan_show(int argc, char **argv)
        }
 
        if (filter_dev) {
-               filter_index = if_nametoindex(filter_dev);
+               filter_index = ll_name_to_index(filter_dev);
                if (filter_index == 0) {
                        fprintf(stderr, "Cannot find device \"%s\"\n",
                                filter_dev);
diff --git a/ip/iplink_bond.c b/ip/iplink_bond.c
index f01fd8d..8e8723a 100644
--- a/ip/iplink_bond.c
+++ b/ip/iplink_bond.c
@@ -177,7 +177,7 @@ static int bond_parse_opt(struct link_util *lu, int argc, 
char **argv,
                        addattr8(n, 1024, IFLA_BOND_MODE, mode);
                } else if (matches(*argv, "active_slave") == 0) {
                        NEXT_ARG();
-                       ifindex = if_nametoindex(*argv);
+                       ifindex = ll_name_to_index(*argv);
                        if (!ifindex)
                                return -1;
                        addattr32(n, 1024, IFLA_BOND_ACTIVE_SLAVE, ifindex);
@@ -240,7 +240,7 @@ static int bond_parse_opt(struct link_util *lu, int argc, 
char **argv,
                        addattr32(n, 1024, IFLA_BOND_ARP_ALL_TARGETS, 
arp_all_targets);
                } else if (matches(*argv, "primary") == 0) {
                        NEXT_ARG();
-                       ifindex = if_nametoindex(*argv);
+                       ifindex = ll_name_to_index(*argv);
                        if (!ifindex)
                                return -1;
                        addattr32(n, 1024, IFLA_BOND_PRIMARY, ifindex);
diff --git a/ip/iplink_bridge.c b/ip/iplink_bridge.c
index d325098..06ec092 100644
--- a/ip/iplink_bridge.c
+++ b/ip/iplink_bridge.c
@@ -792,7 +792,7 @@ int bridge_parse_xstats(struct link_util *lu, int argc, 
char **argv)
                        xstats_print_attr = BRIDGE_XSTATS_MCAST;
                } else if (strcmp(*argv, "dev") == 0) {
                        NEXT_ARG();
-                       filter_index = if_nametoindex(*argv);
+                       filter_index = ll_name_to_index(*argv);
                        if (filter_index == 0) {
                                fprintf(stderr, "Cannot find device \"%s\"\n",
                                        *argv);
diff --git a/ip/iplink_vxlan.c b/ip/iplink_vxlan.c
index 88b5662..7ea908e 100644
--- a/ip/iplink_vxlan.c
+++ b/ip/iplink_vxlan.c
@@ -151,7 +151,7 @@ static int vxlan_parse_opt(struct link_util *lu, int argc, 
char **argv,
 
                        NEXT_ARG();
                        check_duparg(&attrs, IFLA_VXLAN_LINK, "dev", *argv);
-                       link = if_nametoindex(*argv);
+                       link = ll_name_to_index(*argv);
                        if (link == 0) {
                                fprintf(stderr, "Cannot find device \"%s\"\n",
                                        *argv);
diff --git a/ip/iproute_lwtunnel.c b/ip/iproute_lwtunnel.c
index a1d36ba..da6ebb8 100644
--- a/ip/iproute_lwtunnel.c
+++ b/ip/iproute_lwtunnel.c
@@ -556,7 +556,7 @@ static int parse_encap_seg6local(struct rtattr *rta, size_t 
len, int *argcp,
                        NEXT_ARG();
                        if (iif_ok++)
                                duparg2("iif", *argv);
-                       iif = if_nametoindex(*argv);
+                       iif = ll_name_to_index(*argv);
                        if (!iif)
                                invarg("\"iif\" interface not found\n", *argv);
                        rta_addattr32(rta, len, SEG6_LOCAL_IIF, iif);
@@ -564,7 +564,7 @@ static int parse_encap_seg6local(struct rtattr *rta, size_t 
len, int *argcp,
                        NEXT_ARG();
                        if (oif_ok++)
                                duparg2("oif", *argv);
-                       oif = if_nametoindex(*argv);
+                       oif = ll_name_to_index(*argv);
                        if (!oif)
                                invarg("\"oif\" interface not found\n", *argv);
                        rta_addattr32(rta, len, SEG6_LOCAL_OIF, oif);
diff --git a/ip/link_gre.c b/ip/link_gre.c
index 009ddfc..512695d 100644
--- a/ip/link_gre.c
+++ b/ip/link_gre.c
@@ -222,7 +222,7 @@ get_failed:
                        saddr = get_addr32(*argv);
                } else if (!matches(*argv, "dev")) {
                        NEXT_ARG();
-                       link = if_nametoindex(*argv);
+                       link = ll_name_to_index(*argv);
                        if (link == 0) {
                                fprintf(stderr, "Cannot find device \"%s\"\n",
                                        *argv);
diff --git a/ip/link_gre6.c b/ip/link_gre6.c
index 3d02e16..29846cf 100644
--- a/ip/link_gre6.c
+++ b/ip/link_gre6.c
@@ -231,7 +231,7 @@ get_failed:
                        memcpy(&laddr, &addr.data, sizeof(laddr));
                } else if (!matches(*argv, "dev")) {
                        NEXT_ARG();
-                       link = if_nametoindex(*argv);
+                       link = ll_name_to_index(*argv);
                        if (link == 0) {
                                fprintf(stderr, "Cannot find device \"%s\"\n",
                                        *argv);
diff --git a/ip/link_ip6tnl.c b/ip/link_ip6tnl.c
index f6c52ac..fdf113e 100644
--- a/ip/link_ip6tnl.c
+++ b/ip/link_ip6tnl.c
@@ -193,7 +193,7 @@ get_failed:
                        memcpy(&laddr, addr.data, sizeof(laddr));
                } else if (matches(*argv, "dev") == 0) {
                        NEXT_ARG();
-                       link = if_nametoindex(*argv);
+                       link = ll_name_to_index(*argv);
                        if (link == 0)
                                invarg("\"dev\" is invalid", *argv);
                } else if (strcmp(*argv, "ttl") == 0 ||
diff --git a/ip/link_iptnl.c b/ip/link_iptnl.c
index a6213d2..96048e2 100644
--- a/ip/link_iptnl.c
+++ b/ip/link_iptnl.c
@@ -200,7 +200,7 @@ get_failed:
                        laddr = get_addr32(*argv);
                } else if (matches(*argv, "dev") == 0) {
                        NEXT_ARG();
-                       link = if_nametoindex(*argv);
+                       link = ll_name_to_index(*argv);
                        if (link == 0)
                                invarg("\"dev\" is invalid", *argv);
                } else if (strcmp(*argv, "ttl") == 0 ||
diff --git a/ip/link_vti.c b/ip/link_vti.c
index 6a088c6..f1a1123 100644
--- a/ip/link_vti.c
+++ b/ip/link_vti.c
@@ -137,7 +137,7 @@ get_failed:
                        saddr = get_addr32(*argv);
                } else if (!matches(*argv, "dev")) {
                        NEXT_ARG();
-                       link = if_nametoindex(*argv);
+                       link = ll_name_to_index(*argv);
                        if (link == 0) {
                                fprintf(stderr, "Cannot find device \"%s\"\n",
                                        *argv);
diff --git a/ip/link_vti6.c b/ip/link_vti6.c
index a11f389..c394dbc 100644
--- a/ip/link_vti6.c
+++ b/ip/link_vti6.c
@@ -143,7 +143,7 @@ get_failed:
                        memcpy(&saddr, addr.data, sizeof(saddr));
                } else if (!matches(*argv, "dev")) {
                        NEXT_ARG();
-                       link = if_nametoindex(*argv);
+                       link = ll_name_to_index(*argv);
                        if (link == 0) {
                                fprintf(stderr, "Cannot find device \"%s\"\n",
                                        *argv);
-- 
1.7.10.4

Reply via email to