]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ip: allow to use alternative names as handle
authorJiri Pirko <jiri@mellanox.com>
Thu, 24 Oct 2019 10:20:52 +0000 (12:20 +0200)
committerDavid Ahern <dsahern@gmail.com>
Mon, 28 Oct 2019 14:35:29 +0000 (07:35 -0700)
Extend ll_name_to_index() to get the index of a netdevice using
alternative interface name. Allow alternative long names to pass checks
in couple of ip link/addr commands.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
ip/iplink.c
lib/ll_map.c

index bf90fad1b3ea4e5bc2fb057f104b236414d27b52..47f73988c2d58da5a7e362b2c2cc2b3afcb64186 100644 (file)
@@ -931,7 +931,7 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type)
                                NEXT_ARG();
                        if (dev != name)
                                duparg2("dev", *argv);
-                       if (check_ifname(*argv))
+                       if (check_altifname(*argv))
                                invarg("\"dev\" not a valid ifname", *argv);
                        dev = *argv;
                }
@@ -1106,7 +1106,8 @@ int iplink_get(char *name, __u32 filt_mask)
 
        if (name) {
                addattr_l(&req.n, sizeof(req),
-                         IFLA_IFNAME, name, strlen(name) + 1);
+                         !check_ifname(name) ? IFLA_IFNAME : IFLA_ALT_IFNAME,
+                         name, strlen(name) + 1);
        }
        addattr32(&req.n, sizeof(req), IFLA_EXT_MASK, filt_mask);
 
index 9ec73d16679060104595f61830b5b895f2ab4893..70ea3d499c8fbb4841696d52d1f37f3462e01c4c 100644 (file)
@@ -72,7 +72,7 @@ static struct ll_cache *ll_get_by_name(const char *name)
                struct ll_cache *im
                        = container_of(n, struct ll_cache, name_hash);
 
-               if (strncmp(im->name, name, IFNAMSIZ) == 0)
+               if (strcmp(im->name, name) == 0)
                        return im;
        }
 
@@ -288,8 +288,9 @@ static int ll_link_get(const char *name, int index)
 
        addattr32(&req.n, sizeof(req), IFLA_EXT_MASK, filt_mask);
        if (name)
-               addattr_l(&req.n, sizeof(req), IFLA_IFNAME, name,
-                         strlen(name) + 1);
+               addattr_l(&req.n, sizeof(req),
+                         !check_ifname(name) ? IFLA_IFNAME : IFLA_ALT_IFNAME,
+                         name, strlen(name) + 1);
 
        if (rtnl_talk_suppress_rtnl_errmsg(&rth, &req.n, &answer) < 0)
                goto out;