Commit 5517750f authored by Tom Gundersen's avatar Tom Gundersen Committed by David S. Miller

net: rtnetlink - make create_link take name_assign_type

This passes down NET_NAME_USER (or NET_NAME_ENUM) to alloc_netdev(),
for any device created over rtnetlink.

v9: restore reverse-christmas-tree order of local variables
Signed-off-by: default avatarTom Gundersen <teg@jklm.no>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent c835a677
...@@ -335,6 +335,7 @@ static int veth_newlink(struct net *src_net, struct net_device *dev, ...@@ -335,6 +335,7 @@ static int veth_newlink(struct net *src_net, struct net_device *dev,
struct veth_priv *priv; struct veth_priv *priv;
char ifname[IFNAMSIZ]; char ifname[IFNAMSIZ];
struct nlattr *peer_tb[IFLA_MAX + 1], **tbp; struct nlattr *peer_tb[IFLA_MAX + 1], **tbp;
unsigned char name_assign_type;
struct ifinfomsg *ifmp; struct ifinfomsg *ifmp;
struct net *net; struct net *net;
...@@ -362,16 +363,20 @@ static int veth_newlink(struct net *src_net, struct net_device *dev, ...@@ -362,16 +363,20 @@ static int veth_newlink(struct net *src_net, struct net_device *dev,
tbp = tb; tbp = tb;
} }
if (tbp[IFLA_IFNAME]) if (tbp[IFLA_IFNAME]) {
nla_strlcpy(ifname, tbp[IFLA_IFNAME], IFNAMSIZ); nla_strlcpy(ifname, tbp[IFLA_IFNAME], IFNAMSIZ);
else name_assign_type = NET_NAME_USER;
} else {
snprintf(ifname, IFNAMSIZ, DRV_NAME "%%d"); snprintf(ifname, IFNAMSIZ, DRV_NAME "%%d");
name_assign_type = NET_NAME_ENUM;
}
net = rtnl_link_get_net(src_net, tbp); net = rtnl_link_get_net(src_net, tbp);
if (IS_ERR(net)) if (IS_ERR(net))
return PTR_ERR(net); return PTR_ERR(net);
peer = rtnl_create_link(net, ifname, &veth_link_ops, tbp); peer = rtnl_create_link(net, ifname, name_assign_type,
&veth_link_ops, tbp);
if (IS_ERR(peer)) { if (IS_ERR(peer)) {
put_net(net); put_net(net);
return PTR_ERR(peer); return PTR_ERR(peer);
......
...@@ -136,6 +136,7 @@ void rtnl_af_unregister(struct rtnl_af_ops *ops); ...@@ -136,6 +136,7 @@ void rtnl_af_unregister(struct rtnl_af_ops *ops);
struct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[]); struct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[]);
struct net_device *rtnl_create_link(struct net *net, char *ifname, struct net_device *rtnl_create_link(struct net *net, char *ifname,
unsigned char name_assign_type,
const struct rtnl_link_ops *ops, const struct rtnl_link_ops *ops,
struct nlattr *tb[]); struct nlattr *tb[]);
int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm); int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm);
......
...@@ -1810,7 +1810,8 @@ int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm) ...@@ -1810,7 +1810,8 @@ int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm)
EXPORT_SYMBOL(rtnl_configure_link); EXPORT_SYMBOL(rtnl_configure_link);
struct net_device *rtnl_create_link(struct net *net, struct net_device *rtnl_create_link(struct net *net,
char *ifname, const struct rtnl_link_ops *ops, struct nlattr *tb[]) char *ifname, unsigned char name_assign_type,
const struct rtnl_link_ops *ops, struct nlattr *tb[])
{ {
int err; int err;
struct net_device *dev; struct net_device *dev;
...@@ -1828,7 +1829,7 @@ struct net_device *rtnl_create_link(struct net *net, ...@@ -1828,7 +1829,7 @@ struct net_device *rtnl_create_link(struct net *net,
num_rx_queues = ops->get_num_rx_queues(); num_rx_queues = ops->get_num_rx_queues();
err = -ENOMEM; err = -ENOMEM;
dev = alloc_netdev_mqs(ops->priv_size, ifname, NET_NAME_UNKNOWN, dev = alloc_netdev_mqs(ops->priv_size, ifname, name_assign_type,
ops->setup, num_tx_queues, num_rx_queues); ops->setup, num_tx_queues, num_rx_queues);
if (!dev) if (!dev)
goto err; goto err;
...@@ -1894,6 +1895,7 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh) ...@@ -1894,6 +1895,7 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh)
char ifname[IFNAMSIZ]; char ifname[IFNAMSIZ];
struct nlattr *tb[IFLA_MAX+1]; struct nlattr *tb[IFLA_MAX+1];
struct nlattr *linkinfo[IFLA_INFO_MAX+1]; struct nlattr *linkinfo[IFLA_INFO_MAX+1];
unsigned char name_assign_type = NET_NAME_USER;
int err; int err;
#ifdef CONFIG_MODULES #ifdef CONFIG_MODULES
...@@ -2046,14 +2048,16 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh) ...@@ -2046,14 +2048,16 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh)
if (!ops->setup) if (!ops->setup)
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (!ifname[0]) if (!ifname[0]) {
snprintf(ifname, IFNAMSIZ, "%s%%d", ops->kind); snprintf(ifname, IFNAMSIZ, "%s%%d", ops->kind);
name_assign_type = NET_NAME_ENUM;
}
dest_net = rtnl_link_get_net(net, tb); dest_net = rtnl_link_get_net(net, tb);
if (IS_ERR(dest_net)) if (IS_ERR(dest_net))
return PTR_ERR(dest_net); return PTR_ERR(dest_net);
dev = rtnl_create_link(dest_net, ifname, ops, tb); dev = rtnl_create_link(dest_net, ifname, name_assign_type, ops, tb);
if (IS_ERR(dev)) { if (IS_ERR(dev)) {
err = PTR_ERR(dev); err = PTR_ERR(dev);
goto out; goto out;
......
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