From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, jakub.kicinski@netronome.com,
dsahern@gmail.com, stephen@networkplumber.org,
roopa@cumulusnetworks.com, dcbw@redhat.com,
nikolay@cumulusnetworks.com, mkubecek@suse.cz, andrew@lunn.ch,
parav@mellanox.com, saeedm@mellanox.com, f.fainelli@gmail.com,
sd@queasysnail.net, sbrivio@redhat.com, pabeni@redhat.com,
mlxsw@mellanox.com
Subject: [patch iproute2-next v4 3/3] ip: allow to use alternative names as handle
Date: Sat, 19 Oct 2019 19:37:49 +0200 [thread overview]
Message-ID: <20191019173749.19068-4-jiri@resnulli.us> (raw)
In-Reply-To: <20191019173749.19068-1-jiri@resnulli.us>
From: Jiri Pirko <jiri@mellanox.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@mellanox.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 1b382b5cec94..52d149dcd91b 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;
}
@@ -287,8 +287,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
prev parent reply other threads:[~2019-10-19 17:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-19 17:37 [patch iproute2-next v4 0/3] ip: add support for alternative names Jiri Pirko
2019-10-19 17:37 ` [patch iproute2-next v4 1/3] lib/ll_map: cache " Jiri Pirko
2019-10-23 15:11 ` David Ahern
2019-10-23 16:08 ` Jiri Pirko
2019-10-19 17:37 ` [patch iproute2-next v4 2/3] ip: add support for alternative name addition/deletion/list Jiri Pirko
2019-10-19 17:37 ` Jiri Pirko [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191019173749.19068-4-jiri@resnulli.us \
--to=jiri@resnulli.us \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=dcbw@redhat.com \
--cc=dsahern@gmail.com \
--cc=f.fainelli@gmail.com \
--cc=jakub.kicinski@netronome.com \
--cc=mkubecek@suse.cz \
--cc=mlxsw@mellanox.com \
--cc=netdev@vger.kernel.org \
--cc=nikolay@cumulusnetworks.com \
--cc=pabeni@redhat.com \
--cc=parav@mellanox.com \
--cc=roopa@cumulusnetworks.com \
--cc=saeedm@mellanox.com \
--cc=sbrivio@redhat.com \
--cc=sd@queasysnail.net \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).