Commit 7e6d4da8 authored by Jiri Pirko's avatar Jiri Pirko Committed by David S. Miller

nlmon: use standard rtnetlink link api for add/del devices

It is not nice when netdev is created right after module load and with
some implicit name. So rather change nlmon to use standard rtnl link API.
Signed-off-by: default avatarJiri Pirko <jiri@resnulli.us>
Acked-by: default avatarDaniel Borkmann <dborkman@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 75a493e6
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <linux/netlink.h> #include <linux/netlink.h>
#include <net/net_namespace.h> #include <net/net_namespace.h>
#include <linux/if_arp.h> #include <linux/if_arp.h>
#include <net/rtnetlink.h>
struct pcpu_lstats { struct pcpu_lstats {
u64 packets; u64 packets;
...@@ -56,16 +57,24 @@ static void nlmon_dev_uninit(struct net_device *dev) ...@@ -56,16 +57,24 @@ static void nlmon_dev_uninit(struct net_device *dev)
free_percpu(dev->lstats); free_percpu(dev->lstats);
} }
static struct netlink_tap nlmon_tap; struct nlmon {
struct netlink_tap nt;
};
static int nlmon_open(struct net_device *dev) static int nlmon_open(struct net_device *dev)
{ {
return netlink_add_tap(&nlmon_tap); struct nlmon *nlmon = netdev_priv(dev);
nlmon->nt.dev = dev;
nlmon->nt.module = THIS_MODULE;
return netlink_add_tap(&nlmon->nt);
} }
static int nlmon_close(struct net_device *dev) static int nlmon_close(struct net_device *dev)
{ {
return netlink_remove_tap(&nlmon_tap); struct nlmon *nlmon = netdev_priv(dev);
return netlink_remove_tap(&nlmon->nt);
} }
static struct rtnl_link_stats64 * static struct rtnl_link_stats64 *
...@@ -119,10 +128,6 @@ static const struct net_device_ops nlmon_ops = { ...@@ -119,10 +128,6 @@ static const struct net_device_ops nlmon_ops = {
.ndo_change_mtu = nlmon_change_mtu, .ndo_change_mtu = nlmon_change_mtu,
}; };
static struct netlink_tap nlmon_tap __read_mostly = {
.module = THIS_MODULE,
};
static void nlmon_setup(struct net_device *dev) static void nlmon_setup(struct net_device *dev)
{ {
dev->type = ARPHRD_NETLINK; dev->type = ARPHRD_NETLINK;
...@@ -142,27 +147,28 @@ static void nlmon_setup(struct net_device *dev) ...@@ -142,27 +147,28 @@ static void nlmon_setup(struct net_device *dev)
dev->mtu = NLMSG_GOODSIZE; dev->mtu = NLMSG_GOODSIZE;
} }
static __init int nlmon_register(void) static int nlmon_validate(struct nlattr *tb[], struct nlattr *data[])
{ {
int err; if (tb[IFLA_ADDRESS])
struct net_device *nldev; return -EINVAL;
return 0;
nldev = nlmon_tap.dev = alloc_netdev(0, "netlink", nlmon_setup); }
if (unlikely(nldev == NULL))
return -ENOMEM;
err = register_netdev(nldev); static struct rtnl_link_ops nlmon_link_ops __read_mostly = {
if (unlikely(err)) .kind = "nlmon",
free_netdev(nldev); .priv_size = sizeof(struct nlmon),
.setup = nlmon_setup,
.validate = nlmon_validate,
};
return err; static __init int nlmon_register(void)
{
return rtnl_link_register(&nlmon_link_ops);
} }
static __exit void nlmon_unregister(void) static __exit void nlmon_unregister(void)
{ {
struct net_device *nldev = nlmon_tap.dev; rtnl_link_unregister(&nlmon_link_ops);
unregister_netdev(nldev);
} }
module_init(nlmon_register); module_init(nlmon_register);
...@@ -172,3 +178,4 @@ MODULE_LICENSE("GPL v2"); ...@@ -172,3 +178,4 @@ MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("Daniel Borkmann <dborkman@redhat.com>"); MODULE_AUTHOR("Daniel Borkmann <dborkman@redhat.com>");
MODULE_AUTHOR("Mathieu Geli <geli@enseirb.fr>"); MODULE_AUTHOR("Mathieu Geli <geli@enseirb.fr>");
MODULE_DESCRIPTION("Netlink monitoring device"); MODULE_DESCRIPTION("Netlink monitoring device");
MODULE_ALIAS_RTNL_LINK("nlmon");
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