Commit 76c9ac0e authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

net: rtnetlink: add possibility to use alternative names as message handle

Extend the basic rtnetlink commands to use alternative interface names
as a handle instead of ifindex and ifname.
Signed-off-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent cc6090e9
...@@ -2780,14 +2780,17 @@ static int do_setlink(const struct sk_buff *skb, ...@@ -2780,14 +2780,17 @@ static int do_setlink(const struct sk_buff *skb,
static struct net_device *rtnl_dev_get(struct net *net, static struct net_device *rtnl_dev_get(struct net *net,
struct nlattr *ifname_attr, struct nlattr *ifname_attr,
struct nlattr *altifname_attr,
char *ifname) char *ifname)
{ {
char buffer[IFNAMSIZ]; char buffer[ALTIFNAMSIZ];
if (!ifname) { if (!ifname) {
ifname = buffer; ifname = buffer;
if (ifname_attr) if (ifname_attr)
nla_strlcpy(ifname, ifname_attr, IFNAMSIZ); nla_strlcpy(ifname, ifname_attr, IFNAMSIZ);
else if (altifname_attr)
nla_strlcpy(ifname, altifname_attr, ALTIFNAMSIZ);
else else
return NULL; return NULL;
} }
...@@ -2823,8 +2826,8 @@ static int rtnl_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -2823,8 +2826,8 @@ static int rtnl_setlink(struct sk_buff *skb, struct nlmsghdr *nlh,
ifm = nlmsg_data(nlh); ifm = nlmsg_data(nlh);
if (ifm->ifi_index > 0) if (ifm->ifi_index > 0)
dev = __dev_get_by_index(net, ifm->ifi_index); dev = __dev_get_by_index(net, ifm->ifi_index);
else if (tb[IFLA_IFNAME]) else if (tb[IFLA_IFNAME] || tb[IFLA_ALT_IFNAME])
dev = rtnl_dev_get(net, NULL, ifname); dev = rtnl_dev_get(net, NULL, tb[IFLA_ALT_IFNAME], ifname);
else else
goto errout; goto errout;
...@@ -2921,8 +2924,9 @@ static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -2921,8 +2924,9 @@ static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh,
ifm = nlmsg_data(nlh); ifm = nlmsg_data(nlh);
if (ifm->ifi_index > 0) if (ifm->ifi_index > 0)
dev = __dev_get_by_index(tgt_net, ifm->ifi_index); dev = __dev_get_by_index(tgt_net, ifm->ifi_index);
else if (tb[IFLA_IFNAME]) else if (tb[IFLA_IFNAME] || tb[IFLA_ALT_IFNAME])
dev = rtnl_dev_get(net, tb[IFLA_IFNAME], NULL); dev = rtnl_dev_get(net, tb[IFLA_IFNAME],
tb[IFLA_ALT_IFNAME], NULL);
else if (tb[IFLA_GROUP]) else if (tb[IFLA_GROUP])
err = rtnl_group_dellink(tgt_net, nla_get_u32(tb[IFLA_GROUP])); err = rtnl_group_dellink(tgt_net, nla_get_u32(tb[IFLA_GROUP]));
else else
...@@ -3093,8 +3097,8 @@ static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -3093,8 +3097,8 @@ static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
ifm = nlmsg_data(nlh); ifm = nlmsg_data(nlh);
if (ifm->ifi_index > 0) if (ifm->ifi_index > 0)
dev = __dev_get_by_index(net, ifm->ifi_index); dev = __dev_get_by_index(net, ifm->ifi_index);
else if (tb[IFLA_IFNAME]) else if (tb[IFLA_IFNAME] || tb[IFLA_ALT_IFNAME])
dev = rtnl_dev_get(net, NULL, ifname); dev = rtnl_dev_get(net, NULL, tb[IFLA_ALT_IFNAME], ifname);
else else
dev = NULL; dev = NULL;
...@@ -3358,6 +3362,7 @@ static int rtnl_valid_getlink_req(struct sk_buff *skb, ...@@ -3358,6 +3362,7 @@ static int rtnl_valid_getlink_req(struct sk_buff *skb,
switch (i) { switch (i) {
case IFLA_IFNAME: case IFLA_IFNAME:
case IFLA_ALT_IFNAME:
case IFLA_EXT_MASK: case IFLA_EXT_MASK:
case IFLA_TARGET_NETNSID: case IFLA_TARGET_NETNSID:
break; break;
...@@ -3405,8 +3410,9 @@ static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -3405,8 +3410,9 @@ static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr *nlh,
ifm = nlmsg_data(nlh); ifm = nlmsg_data(nlh);
if (ifm->ifi_index > 0) if (ifm->ifi_index > 0)
dev = __dev_get_by_index(tgt_net, ifm->ifi_index); dev = __dev_get_by_index(tgt_net, ifm->ifi_index);
else if (tb[IFLA_IFNAME]) else if (tb[IFLA_IFNAME] || tb[IFLA_ALT_IFNAME])
dev = rtnl_dev_get(tgt_net, tb[IFLA_IFNAME], NULL); dev = rtnl_dev_get(tgt_net, tb[IFLA_IFNAME],
tb[IFLA_ALT_IFNAME], NULL);
else else
goto out; goto out;
...@@ -3491,8 +3497,9 @@ static int rtnl_linkprop(int cmd, struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -3491,8 +3497,9 @@ static int rtnl_linkprop(int cmd, struct sk_buff *skb, struct nlmsghdr *nlh,
ifm = nlmsg_data(nlh); ifm = nlmsg_data(nlh);
if (ifm->ifi_index > 0) if (ifm->ifi_index > 0)
dev = __dev_get_by_index(net, ifm->ifi_index); dev = __dev_get_by_index(net, ifm->ifi_index);
else if (tb[IFLA_IFNAME]) else if (tb[IFLA_IFNAME] || tb[IFLA_ALT_IFNAME])
dev = rtnl_dev_get(net, tb[IFLA_IFNAME], NULL); dev = rtnl_dev_get(net, tb[IFLA_IFNAME],
tb[IFLA_ALT_IFNAME], NULL);
else else
return -EINVAL; return -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment