[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20191024102052.4118-4-jiri@resnulli.us>
Date: Thu, 24 Oct 2019 12:20:52 +0200
From: Jiri Pirko <jiri@...nulli.us>
To: netdev@...r.kernel.org
Cc: davem@...emloft.net, jakub.kicinski@...ronome.com,
dsahern@...il.com, stephen@...workplumber.org,
roopa@...ulusnetworks.com, dcbw@...hat.com,
nikolay@...ulusnetworks.com, mkubecek@...e.cz, andrew@...n.ch,
parav@...lanox.com, saeedm@...lanox.com, f.fainelli@...il.com,
sd@...asysnail.net, sbrivio@...hat.com, pabeni@...hat.com,
mlxsw@...lanox.com
Subject: [patch iproute2-next v5 3/3] ip: allow to use alternative names as handle
From: Jiri Pirko <jiri@...lanox.com>
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@...lanox.com>
---
v3->v4:
- moved utils.h include into the first patch
v2->v3:
- removed altnametoindex and doing IFLA_IFNAME/IFLA_ALT_IFNAME in
ll_link_get() instead.
rfc->v1:
- added patch description
---
ip/iplink.c | 5 +++--
lib/ll_map.c | 7 ++++---
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/ip/iplink.c b/ip/iplink.c
index bf90fad1b3ea..47f73988c2d5 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -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);
diff --git a/lib/ll_map.c b/lib/ll_map.c
index 9ec73d166790..70ea3d499c8f 100644
--- a/lib/ll_map.c
+++ b/lib/ll_map.c
@@ -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;
--
2.21.0
Powered by blists - more mailing lists