diff options
author | Jiri Pirko <jiri@resnulli.us> | 2013-07-02 04:55:31 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-07-02 15:53:17 -0400 |
commit | 7e6d4da837385d9aa2e5fd84e0a6042cddc9e708 (patch) | |
tree | 9e1f56a738aa5b3ec7be6649a6cfb280f2e8cdc3 /drivers/net/nlmon.c | |
parent | 75a493e60ac4bbe2e977e7129d6d8cbb0dd236be (diff) |
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: Jiri Pirko <jiri@resnulli.us>
Acked-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/nlmon.c')
-rw-r--r-- | drivers/net/nlmon.c | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/drivers/net/nlmon.c b/drivers/net/nlmon.c index a0baf56f5826..b57ce5f48962 100644 --- a/drivers/net/nlmon.c +++ b/drivers/net/nlmon.c | |||
@@ -4,6 +4,7 @@ | |||
4 | #include <linux/netlink.h> | 4 | #include <linux/netlink.h> |
5 | #include <net/net_namespace.h> | 5 | #include <net/net_namespace.h> |
6 | #include <linux/if_arp.h> | 6 | #include <linux/if_arp.h> |
7 | #include <net/rtnetlink.h> | ||
7 | 8 | ||
8 | struct pcpu_lstats { | 9 | struct pcpu_lstats { |
9 | u64 packets; | 10 | u64 packets; |
@@ -56,16 +57,24 @@ static void nlmon_dev_uninit(struct net_device *dev) | |||
56 | free_percpu(dev->lstats); | 57 | free_percpu(dev->lstats); |
57 | } | 58 | } |
58 | 59 | ||
59 | static struct netlink_tap nlmon_tap; | 60 | struct nlmon { |
61 | struct netlink_tap nt; | ||
62 | }; | ||
60 | 63 | ||
61 | static int nlmon_open(struct net_device *dev) | 64 | static int nlmon_open(struct net_device *dev) |
62 | { | 65 | { |
63 | return netlink_add_tap(&nlmon_tap); | 66 | struct nlmon *nlmon = netdev_priv(dev); |
67 | |||
68 | nlmon->nt.dev = dev; | ||
69 | nlmon->nt.module = THIS_MODULE; | ||
70 | return netlink_add_tap(&nlmon->nt); | ||
64 | } | 71 | } |
65 | 72 | ||
66 | static int nlmon_close(struct net_device *dev) | 73 | static int nlmon_close(struct net_device *dev) |
67 | { | 74 | { |
68 | return netlink_remove_tap(&nlmon_tap); | 75 | struct nlmon *nlmon = netdev_priv(dev); |
76 | |||
77 | return netlink_remove_tap(&nlmon->nt); | ||
69 | } | 78 | } |
70 | 79 | ||
71 | static struct rtnl_link_stats64 * | 80 | static struct rtnl_link_stats64 * |
@@ -119,10 +128,6 @@ static const struct net_device_ops nlmon_ops = { | |||
119 | .ndo_change_mtu = nlmon_change_mtu, | 128 | .ndo_change_mtu = nlmon_change_mtu, |
120 | }; | 129 | }; |
121 | 130 | ||
122 | static struct netlink_tap nlmon_tap __read_mostly = { | ||
123 | .module = THIS_MODULE, | ||
124 | }; | ||
125 | |||
126 | static void nlmon_setup(struct net_device *dev) | 131 | static void nlmon_setup(struct net_device *dev) |
127 | { | 132 | { |
128 | dev->type = ARPHRD_NETLINK; | 133 | dev->type = ARPHRD_NETLINK; |
@@ -142,27 +147,28 @@ static void nlmon_setup(struct net_device *dev) | |||
142 | dev->mtu = NLMSG_GOODSIZE; | 147 | dev->mtu = NLMSG_GOODSIZE; |
143 | } | 148 | } |
144 | 149 | ||
145 | static __init int nlmon_register(void) | 150 | static int nlmon_validate(struct nlattr *tb[], struct nlattr *data[]) |
146 | { | 151 | { |
147 | int err; | 152 | if (tb[IFLA_ADDRESS]) |
148 | struct net_device *nldev; | 153 | return -EINVAL; |
149 | 154 | return 0; | |
150 | nldev = nlmon_tap.dev = alloc_netdev(0, "netlink", nlmon_setup); | 155 | } |
151 | if (unlikely(nldev == NULL)) | ||
152 | return -ENOMEM; | ||
153 | 156 | ||
154 | err = register_netdev(nldev); | 157 | static struct rtnl_link_ops nlmon_link_ops __read_mostly = { |
155 | if (unlikely(err)) | 158 | .kind = "nlmon", |
156 | free_netdev(nldev); | 159 | .priv_size = sizeof(struct nlmon), |
160 | .setup = nlmon_setup, | ||
161 | .validate = nlmon_validate, | ||
162 | }; | ||
157 | 163 | ||
158 | return err; | 164 | static __init int nlmon_register(void) |
165 | { | ||
166 | return rtnl_link_register(&nlmon_link_ops); | ||
159 | } | 167 | } |
160 | 168 | ||
161 | static __exit void nlmon_unregister(void) | 169 | static __exit void nlmon_unregister(void) |
162 | { | 170 | { |
163 | struct net_device *nldev = nlmon_tap.dev; | 171 | rtnl_link_unregister(&nlmon_link_ops); |
164 | |||
165 | unregister_netdev(nldev); | ||
166 | } | 172 | } |
167 | 173 | ||
168 | module_init(nlmon_register); | 174 | module_init(nlmon_register); |
@@ -172,3 +178,4 @@ MODULE_LICENSE("GPL v2"); | |||
172 | MODULE_AUTHOR("Daniel Borkmann <dborkman@redhat.com>"); | 178 | MODULE_AUTHOR("Daniel Borkmann <dborkman@redhat.com>"); |
173 | MODULE_AUTHOR("Mathieu Geli <geli@enseirb.fr>"); | 179 | MODULE_AUTHOR("Mathieu Geli <geli@enseirb.fr>"); |
174 | MODULE_DESCRIPTION("Netlink monitoring device"); | 180 | MODULE_DESCRIPTION("Netlink monitoring device"); |
181 | MODULE_ALIAS_RTNL_LINK("nlmon"); | ||