Commit c63044f0 authored by Eric Dumazet's avatar Eric Dumazet Committed by David S. Miller

rtnetlink: rtnl_link_register() sanity test

Before adding a struct rtnl_link_ops into link_ops list, check it doesnt
clash with a prior one.

Based on a previous patch from Alexander Smirnov
Signed-off-by: default avatarEric Dumazet <eric.dumazet@gmail.com>
CC: Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b43faac6
...@@ -273,6 +273,17 @@ EXPORT_SYMBOL_GPL(rtnl_unregister_all); ...@@ -273,6 +273,17 @@ EXPORT_SYMBOL_GPL(rtnl_unregister_all);
static LIST_HEAD(link_ops); static LIST_HEAD(link_ops);
static const struct rtnl_link_ops *rtnl_link_ops_get(const char *kind)
{
const struct rtnl_link_ops *ops;
list_for_each_entry(ops, &link_ops, list) {
if (!strcmp(ops->kind, kind))
return ops;
}
return NULL;
}
/** /**
* __rtnl_link_register - Register rtnl_link_ops with rtnetlink. * __rtnl_link_register - Register rtnl_link_ops with rtnetlink.
* @ops: struct rtnl_link_ops * to register * @ops: struct rtnl_link_ops * to register
...@@ -285,6 +296,9 @@ static LIST_HEAD(link_ops); ...@@ -285,6 +296,9 @@ static LIST_HEAD(link_ops);
*/ */
int __rtnl_link_register(struct rtnl_link_ops *ops) int __rtnl_link_register(struct rtnl_link_ops *ops)
{ {
if (rtnl_link_ops_get(ops->kind))
return -EEXIST;
if (!ops->dellink) if (!ops->dellink)
ops->dellink = unregister_netdevice_queue; ops->dellink = unregister_netdevice_queue;
...@@ -351,17 +365,6 @@ void rtnl_link_unregister(struct rtnl_link_ops *ops) ...@@ -351,17 +365,6 @@ void rtnl_link_unregister(struct rtnl_link_ops *ops)
} }
EXPORT_SYMBOL_GPL(rtnl_link_unregister); EXPORT_SYMBOL_GPL(rtnl_link_unregister);
static const struct rtnl_link_ops *rtnl_link_ops_get(const char *kind)
{
const struct rtnl_link_ops *ops;
list_for_each_entry(ops, &link_ops, list) {
if (!strcmp(ops->kind, kind))
return ops;
}
return NULL;
}
static size_t rtnl_link_get_size(const struct net_device *dev) static size_t rtnl_link_get_size(const struct net_device *dev)
{ {
const struct rtnl_link_ops *ops = dev->rtnl_link_ops; const struct rtnl_link_ops *ops = dev->rtnl_link_ops;
......
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