From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, jakub.kicinski@netronome.com,
dsahern@gmail.com, 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,
stephen@networkplumber.org, sd@queasysnail.net,
sbrivio@redhat.com, pabeni@redhat.com, mlxsw@mellanox.com
Subject: [patch net-next 7/7] net: rtnetlink: add possibility to use alternative names as message handle
Date: Mon, 30 Sep 2019 11:48:20 +0200 [thread overview]
Message-ID: <20190930094820.11281-8-jiri@resnulli.us> (raw)
In-Reply-To: <20190930094820.11281-1-jiri@resnulli.us>
From: Jiri Pirko <jiri@mellanox.com>
Extend the basic rtnetlink commands to use alternative interface names
as a handle instead of ifindex and ifname.
Signed-off-by: Jiri Pirko <jiri@mellanox.com>
---
rfc->v1:
- rebased on top of changes in the previous patches
---
net/core/rtnetlink.c | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 77d4719e5be0..49fa910b58af 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -2780,14 +2780,17 @@ static int do_setlink(const struct sk_buff *skb,
static struct net_device *rtnl_dev_get(struct net *net,
struct nlattr *ifname_attr,
+ struct nlattr *altifname_attr,
char *ifname)
{
- char buffer[IFNAMSIZ];
+ char buffer[ALTIFNAMSIZ];
if (!ifname) {
ifname = buffer;
if (ifname_attr)
nla_strlcpy(ifname, ifname_attr, IFNAMSIZ);
+ else if (altifname_attr)
+ nla_strlcpy(ifname, altifname_attr, ALTIFNAMSIZ);
else
return NULL;
}
@@ -2823,8 +2826,8 @@ static int rtnl_setlink(struct sk_buff *skb, struct nlmsghdr *nlh,
ifm = nlmsg_data(nlh);
if (ifm->ifi_index > 0)
dev = __dev_get_by_index(net, ifm->ifi_index);
- else if (tb[IFLA_IFNAME])
- dev = rtnl_dev_get(net, NULL, ifname);
+ else if (tb[IFLA_IFNAME] || tb[IFLA_ALT_IFNAME])
+ dev = rtnl_dev_get(net, NULL, tb[IFLA_ALT_IFNAME], ifname);
else
goto errout;
@@ -2921,8 +2924,9 @@ static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh,
ifm = nlmsg_data(nlh);
if (ifm->ifi_index > 0)
dev = __dev_get_by_index(tgt_net, ifm->ifi_index);
- else if (tb[IFLA_IFNAME])
- dev = rtnl_dev_get(net, tb[IFLA_IFNAME], NULL);
+ else if (tb[IFLA_IFNAME] || tb[IFLA_ALT_IFNAME])
+ dev = rtnl_dev_get(net, tb[IFLA_IFNAME],
+ tb[IFLA_ALT_IFNAME], NULL);
else if (tb[IFLA_GROUP])
err = rtnl_group_dellink(tgt_net, nla_get_u32(tb[IFLA_GROUP]));
else
@@ -3093,8 +3097,8 @@ static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
ifm = nlmsg_data(nlh);
if (ifm->ifi_index > 0)
dev = __dev_get_by_index(net, ifm->ifi_index);
- else if (tb[IFLA_IFNAME])
- dev = rtnl_dev_get(net, NULL, ifname);
+ else if (tb[IFLA_IFNAME] || tb[IFLA_ALT_IFNAME])
+ dev = rtnl_dev_get(net, NULL, tb[IFLA_ALT_IFNAME], ifname);
else
dev = NULL;
@@ -3358,6 +3362,7 @@ static int rtnl_valid_getlink_req(struct sk_buff *skb,
switch (i) {
case IFLA_IFNAME:
+ case IFLA_ALT_IFNAME:
case IFLA_EXT_MASK:
case IFLA_TARGET_NETNSID:
break;
@@ -3405,8 +3410,9 @@ static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr *nlh,
ifm = nlmsg_data(nlh);
if (ifm->ifi_index > 0)
dev = __dev_get_by_index(tgt_net, ifm->ifi_index);
- else if (tb[IFLA_IFNAME])
- dev = rtnl_dev_get(tgt_net, tb[IFLA_IFNAME], NULL);
+ else if (tb[IFLA_IFNAME] || tb[IFLA_ALT_IFNAME])
+ dev = rtnl_dev_get(tgt_net, tb[IFLA_IFNAME],
+ tb[IFLA_ALT_IFNAME], NULL);
else
goto out;
@@ -3491,8 +3497,9 @@ static int rtnl_linkprop(int cmd, struct sk_buff *skb, struct nlmsghdr *nlh,
ifm = nlmsg_data(nlh);
if (ifm->ifi_index > 0)
dev = __dev_get_by_index(net, ifm->ifi_index);
- else if (tb[IFLA_IFNAME])
- dev = rtnl_dev_get(net, tb[IFLA_IFNAME], NULL);
+ else if (tb[IFLA_IFNAME] || tb[IFLA_ALT_IFNAME])
+ dev = rtnl_dev_get(net, tb[IFLA_IFNAME],
+ tb[IFLA_ALT_IFNAME], NULL);
else
return -EINVAL;
--
2.21.0
next prev parent reply other threads:[~2019-09-30 9:48 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-30 9:48 [patch net-next 0/7] net: introduce alternative names for network interfaces Jiri Pirko
2019-09-30 9:48 ` [patch net-next 1/7] net: procfs: use index hashlist instead of name hashlist Jiri Pirko
2019-09-30 9:48 ` [patch net-next 2/7] net: introduce name_node struct to be used in hashlist Jiri Pirko
2019-09-30 9:48 ` [patch net-next 3/7] net: rtnetlink: add linkprop commands to add and delete alternative ifnames Jiri Pirko
2019-09-30 9:48 ` [patch net-next 4/7] net: rtnetlink: put alternative names to getlink message Jiri Pirko
2019-09-30 9:48 ` [patch net-next 5/7] net: rtnetlink: unify the code in __rtnl_newlink get dev with the rest Jiri Pirko
2019-09-30 9:48 ` [patch net-next 6/7] net: rtnetlink: introduce helper to get net_device instance by ifname Jiri Pirko
2019-09-30 9:48 ` Jiri Pirko [this message]
2019-09-30 9:59 ` [patch net-next 1/2] ip: add support for alternative name addition/deletion/list Jiri Pirko
2019-09-30 10:09 ` Jiri Pirko
2019-09-30 16:27 ` Stephen Hemminger
2019-09-30 17:51 ` Jiri Pirko
2019-09-30 9:59 ` [patch net-next 2/2] ip: allow to use alternative names as handle Jiri Pirko
2019-10-01 21:51 ` [patch net-next 0/7] net: introduce alternative names for network interfaces David Miller
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=20190930094820.11281-8-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).