Commit 8c713dc9 authored by Johannes Berg's avatar Johannes Berg Committed by David S. Miller

rtnetlink: add alloc() method to rtnl_link_ops

In order to make rtnetlink ops that can create different
kinds of devices, like what we want to add to the WWAN
framework, the priv_size and setup parameters aren't quite
sufficient. Make this easier to manage by allowing ops to
allocate their own netdev via an @alloc method that gets
the tb netlink data.
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
Signed-off-by: default avatarSergey Ryazanov <ryazanov.s.a@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 73214a69
...@@ -37,6 +37,9 @@ static inline int rtnl_msg_family(const struct nlmsghdr *nlh) ...@@ -37,6 +37,9 @@ static inline int rtnl_msg_family(const struct nlmsghdr *nlh)
* @maxtype: Highest device specific netlink attribute number * @maxtype: Highest device specific netlink attribute number
* @policy: Netlink policy for device specific attribute validation * @policy: Netlink policy for device specific attribute validation
* @validate: Optional validation function for netlink/changelink parameters * @validate: Optional validation function for netlink/changelink parameters
* @alloc: netdev allocation function, can be %NULL and is then used
* in place of alloc_netdev_mqs(), in this case @priv_size
* and @setup are unused. Returns a netdev or ERR_PTR().
* @priv_size: sizeof net_device private space * @priv_size: sizeof net_device private space
* @setup: net_device setup function * @setup: net_device setup function
* @newlink: Function for configuring and registering a new device * @newlink: Function for configuring and registering a new device
...@@ -63,6 +66,11 @@ struct rtnl_link_ops { ...@@ -63,6 +66,11 @@ struct rtnl_link_ops {
const char *kind; const char *kind;
size_t priv_size; size_t priv_size;
struct net_device *(*alloc)(struct nlattr *tb[],
const char *ifname,
unsigned char name_assign_type,
unsigned int num_tx_queues,
unsigned int num_rx_queues);
void (*setup)(struct net_device *dev); void (*setup)(struct net_device *dev);
bool netns_refund; bool netns_refund;
......
...@@ -376,12 +376,12 @@ int __rtnl_link_register(struct rtnl_link_ops *ops) ...@@ -376,12 +376,12 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
if (rtnl_link_ops_get(ops->kind)) if (rtnl_link_ops_get(ops->kind))
return -EEXIST; return -EEXIST;
/* The check for setup is here because if ops /* The check for alloc/setup is here because if ops
* does not have that filled up, it is not possible * does not have that filled up, it is not possible
* to use the ops for creating device. So do not * to use the ops for creating device. So do not
* fill up dellink as well. That disables rtnl_dellink. * fill up dellink as well. That disables rtnl_dellink.
*/ */
if (ops->setup && !ops->dellink) if ((ops->alloc || ops->setup) && !ops->dellink)
ops->dellink = unregister_netdevice_queue; ops->dellink = unregister_netdevice_queue;
list_add_tail(&ops->list, &link_ops); list_add_tail(&ops->list, &link_ops);
...@@ -3165,8 +3165,17 @@ struct net_device *rtnl_create_link(struct net *net, const char *ifname, ...@@ -3165,8 +3165,17 @@ struct net_device *rtnl_create_link(struct net *net, const char *ifname,
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
dev = alloc_netdev_mqs(ops->priv_size, ifname, name_assign_type, if (ops->alloc) {
ops->setup, num_tx_queues, num_rx_queues); dev = ops->alloc(tb, ifname, name_assign_type,
num_tx_queues, num_rx_queues);
if (IS_ERR(dev))
return dev;
} else {
dev = alloc_netdev_mqs(ops->priv_size, ifname,
name_assign_type, ops->setup,
num_tx_queues, num_rx_queues);
}
if (!dev) if (!dev)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
...@@ -3399,7 +3408,7 @@ static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -3399,7 +3408,7 @@ static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
if (!ops->setup) if (!ops->alloc && !ops->setup)
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (!ifname[0]) { if (!ifname[0]) {
......
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