Linux Audio

Check our new training course

Open-source upstreaming

Need help get the support for your hardware in upstream Linux?
Loading...
v6.8
  1/* License: GPL */
  2
  3#include <linux/filter.h>
  4#include <linux/mutex.h>
  5#include <linux/socket.h>
  6#include <linux/skbuff.h>
  7#include <net/netlink.h>
  8#include <net/net_namespace.h>
  9#include <linux/module.h>
 10#include <net/sock.h>
 11#include <linux/kernel.h>
 12#include <linux/tcp.h>
 13#include <linux/workqueue.h>
 14#include <linux/nospec.h>
 15#include <linux/cookie.h>
 16#include <linux/inet_diag.h>
 17#include <linux/sock_diag.h>
 18
 19static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
 20static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
 21static DEFINE_MUTEX(sock_diag_table_mutex);
 22static struct workqueue_struct *broadcast_wq;
 23
 24DEFINE_COOKIE(sock_cookie);
 25
 26u64 __sock_gen_cookie(struct sock *sk)
 27{
 28	u64 res = atomic64_read(&sk->sk_cookie);
 29
 30	if (!res) {
 31		u64 new = gen_cookie_next(&sock_cookie);
 32
 33		atomic64_cmpxchg(&sk->sk_cookie, res, new);
 34
 35		/* Another thread might have changed sk_cookie before us. */
 36		res = atomic64_read(&sk->sk_cookie);
 
 
 37	}
 38	return res;
 39}
 40
 41int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie)
 42{
 43	u64 res;
 44
 45	if (cookie[0] == INET_DIAG_NOCOOKIE && cookie[1] == INET_DIAG_NOCOOKIE)
 46		return 0;
 47
 48	res = sock_gen_cookie(sk);
 49	if ((u32)res != cookie[0] || (u32)(res >> 32) != cookie[1])
 50		return -ESTALE;
 51
 52	return 0;
 53}
 54EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
 55
 56void sock_diag_save_cookie(struct sock *sk, __u32 *cookie)
 57{
 58	u64 res = sock_gen_cookie(sk);
 59
 60	cookie[0] = (u32)res;
 61	cookie[1] = (u32)(res >> 32);
 62}
 63EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
 64
 65int sock_diag_put_meminfo(struct sock *sk, struct sk_buff *skb, int attrtype)
 66{
 67	u32 mem[SK_MEMINFO_VARS];
 68
 69	sk_get_meminfo(sk, mem);
 
 
 
 
 
 
 
 
 70
 71	return nla_put(skb, attrtype, sizeof(mem), &mem);
 72}
 73EXPORT_SYMBOL_GPL(sock_diag_put_meminfo);
 74
 75int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk,
 76			     struct sk_buff *skb, int attrtype)
 77{
 78	struct sock_fprog_kern *fprog;
 79	struct sk_filter *filter;
 80	struct nlattr *attr;
 81	unsigned int flen;
 82	int err = 0;
 83
 84	if (!may_report_filterinfo) {
 85		nla_reserve(skb, attrtype, 0);
 86		return 0;
 87	}
 88
 89	rcu_read_lock();
 90	filter = rcu_dereference(sk->sk_filter);
 91	if (!filter)
 92		goto out;
 93
 94	fprog = filter->prog->orig_prog;
 95	if (!fprog)
 96		goto out;
 97
 98	flen = bpf_classic_proglen(fprog);
 99
100	attr = nla_reserve(skb, attrtype, flen);
101	if (attr == NULL) {
102		err = -EMSGSIZE;
103		goto out;
104	}
105
106	memcpy(nla_data(attr), fprog->filter, flen);
107out:
108	rcu_read_unlock();
109	return err;
110}
111EXPORT_SYMBOL(sock_diag_put_filterinfo);
112
113struct broadcast_sk {
114	struct sock *sk;
115	struct work_struct work;
116};
117
118static size_t sock_diag_nlmsg_size(void)
119{
120	return NLMSG_ALIGN(sizeof(struct inet_diag_msg)
121	       + nla_total_size(sizeof(u8)) /* INET_DIAG_PROTOCOL */
122	       + nla_total_size_64bit(sizeof(struct tcp_info))); /* INET_DIAG_INFO */
123}
124
125static void sock_diag_broadcast_destroy_work(struct work_struct *work)
126{
127	struct broadcast_sk *bsk =
128		container_of(work, struct broadcast_sk, work);
129	struct sock *sk = bsk->sk;
130	const struct sock_diag_handler *hndl;
131	struct sk_buff *skb;
132	const enum sknetlink_groups group = sock_diag_destroy_group(sk);
133	int err = -1;
134
135	WARN_ON(group == SKNLGRP_NONE);
136
137	skb = nlmsg_new(sock_diag_nlmsg_size(), GFP_KERNEL);
138	if (!skb)
139		goto out;
140
141	mutex_lock(&sock_diag_table_mutex);
142	hndl = sock_diag_handlers[sk->sk_family];
143	if (hndl && hndl->get_info)
144		err = hndl->get_info(skb, sk);
145	mutex_unlock(&sock_diag_table_mutex);
146
147	if (!err)
148		nlmsg_multicast(sock_net(sk)->diag_nlsk, skb, 0, group,
149				GFP_KERNEL);
150	else
151		kfree_skb(skb);
152out:
153	sk_destruct(sk);
154	kfree(bsk);
155}
156
157void sock_diag_broadcast_destroy(struct sock *sk)
158{
159	/* Note, this function is often called from an interrupt context. */
160	struct broadcast_sk *bsk =
161		kmalloc(sizeof(struct broadcast_sk), GFP_ATOMIC);
162	if (!bsk)
163		return sk_destruct(sk);
164	bsk->sk = sk;
165	INIT_WORK(&bsk->work, sock_diag_broadcast_destroy_work);
166	queue_work(broadcast_wq, &bsk->work);
167}
168
169void sock_diag_register_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh))
170{
171	mutex_lock(&sock_diag_table_mutex);
172	inet_rcv_compat = fn;
173	mutex_unlock(&sock_diag_table_mutex);
174}
175EXPORT_SYMBOL_GPL(sock_diag_register_inet_compat);
176
177void sock_diag_unregister_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh))
178{
179	mutex_lock(&sock_diag_table_mutex);
180	inet_rcv_compat = NULL;
181	mutex_unlock(&sock_diag_table_mutex);
182}
183EXPORT_SYMBOL_GPL(sock_diag_unregister_inet_compat);
184
185int sock_diag_register(const struct sock_diag_handler *hndl)
186{
187	int err = 0;
188
189	if (hndl->family >= AF_MAX)
190		return -EINVAL;
191
192	mutex_lock(&sock_diag_table_mutex);
193	if (sock_diag_handlers[hndl->family])
194		err = -EBUSY;
195	else
196		sock_diag_handlers[hndl->family] = hndl;
197	mutex_unlock(&sock_diag_table_mutex);
198
199	return err;
200}
201EXPORT_SYMBOL_GPL(sock_diag_register);
202
203void sock_diag_unregister(const struct sock_diag_handler *hnld)
204{
205	int family = hnld->family;
206
207	if (family >= AF_MAX)
208		return;
209
210	mutex_lock(&sock_diag_table_mutex);
211	BUG_ON(sock_diag_handlers[family] != hnld);
212	sock_diag_handlers[family] = NULL;
213	mutex_unlock(&sock_diag_table_mutex);
214}
215EXPORT_SYMBOL_GPL(sock_diag_unregister);
216
217static int __sock_diag_cmd(struct sk_buff *skb, struct nlmsghdr *nlh)
218{
219	int err;
220	struct sock_diag_req *req = nlmsg_data(nlh);
221	const struct sock_diag_handler *hndl;
222
223	if (nlmsg_len(nlh) < sizeof(*req))
224		return -EINVAL;
225
226	if (req->sdiag_family >= AF_MAX)
227		return -EINVAL;
228	req->sdiag_family = array_index_nospec(req->sdiag_family, AF_MAX);
229
230	if (sock_diag_handlers[req->sdiag_family] == NULL)
231		sock_load_diag_module(req->sdiag_family, 0);
 
232
233	mutex_lock(&sock_diag_table_mutex);
234	hndl = sock_diag_handlers[req->sdiag_family];
235	if (hndl == NULL)
236		err = -ENOENT;
237	else if (nlh->nlmsg_type == SOCK_DIAG_BY_FAMILY)
238		err = hndl->dump(skb, nlh);
239	else if (nlh->nlmsg_type == SOCK_DESTROY && hndl->destroy)
240		err = hndl->destroy(skb, nlh);
241	else
242		err = -EOPNOTSUPP;
243	mutex_unlock(&sock_diag_table_mutex);
244
245	return err;
246}
247
248static int sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
249			     struct netlink_ext_ack *extack)
250{
251	int ret;
252
253	switch (nlh->nlmsg_type) {
254	case TCPDIAG_GETSOCK:
255	case DCCPDIAG_GETSOCK:
256		if (inet_rcv_compat == NULL)
257			sock_load_diag_module(AF_INET, 0);
 
258
259		mutex_lock(&sock_diag_table_mutex);
260		if (inet_rcv_compat != NULL)
261			ret = inet_rcv_compat(skb, nlh);
262		else
263			ret = -EOPNOTSUPP;
264		mutex_unlock(&sock_diag_table_mutex);
265
266		return ret;
267	case SOCK_DIAG_BY_FAMILY:
268	case SOCK_DESTROY:
269		return __sock_diag_cmd(skb, nlh);
270	default:
271		return -EINVAL;
272	}
273}
274
275static DEFINE_MUTEX(sock_diag_mutex);
276
277static void sock_diag_rcv(struct sk_buff *skb)
278{
279	mutex_lock(&sock_diag_mutex);
280	netlink_rcv_skb(skb, &sock_diag_rcv_msg);
281	mutex_unlock(&sock_diag_mutex);
282}
283
284static int sock_diag_bind(struct net *net, int group)
285{
286	switch (group) {
287	case SKNLGRP_INET_TCP_DESTROY:
288	case SKNLGRP_INET_UDP_DESTROY:
289		if (!sock_diag_handlers[AF_INET])
290			sock_load_diag_module(AF_INET, 0);
 
291		break;
292	case SKNLGRP_INET6_TCP_DESTROY:
293	case SKNLGRP_INET6_UDP_DESTROY:
294		if (!sock_diag_handlers[AF_INET6])
295			sock_load_diag_module(AF_INET6, 0);
 
296		break;
297	}
298	return 0;
299}
300
301int sock_diag_destroy(struct sock *sk, int err)
302{
303	if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
304		return -EPERM;
305
306	if (!sk->sk_prot->diag_destroy)
307		return -EOPNOTSUPP;
308
309	return sk->sk_prot->diag_destroy(sk, err);
310}
311EXPORT_SYMBOL_GPL(sock_diag_destroy);
312
313static int __net_init diag_net_init(struct net *net)
314{
315	struct netlink_kernel_cfg cfg = {
316		.groups	= SKNLGRP_MAX,
317		.input	= sock_diag_rcv,
318		.bind	= sock_diag_bind,
319		.flags	= NL_CFG_F_NONROOT_RECV,
320	};
321
322	net->diag_nlsk = netlink_kernel_create(net, NETLINK_SOCK_DIAG, &cfg);
323	return net->diag_nlsk == NULL ? -ENOMEM : 0;
324}
325
326static void __net_exit diag_net_exit(struct net *net)
327{
328	netlink_kernel_release(net->diag_nlsk);
329	net->diag_nlsk = NULL;
330}
331
332static struct pernet_operations diag_net_ops = {
333	.init = diag_net_init,
334	.exit = diag_net_exit,
335};
336
337static int __init sock_diag_init(void)
338{
339	broadcast_wq = alloc_workqueue("sock_diag_events", 0, 0);
340	BUG_ON(!broadcast_wq);
341	return register_pernet_subsys(&diag_net_ops);
342}
343device_initcall(sock_diag_init);
v4.10.11
  1/* License: GPL */
  2
 
  3#include <linux/mutex.h>
  4#include <linux/socket.h>
  5#include <linux/skbuff.h>
  6#include <net/netlink.h>
  7#include <net/net_namespace.h>
  8#include <linux/module.h>
  9#include <net/sock.h>
 10#include <linux/kernel.h>
 11#include <linux/tcp.h>
 12#include <linux/workqueue.h>
 13
 
 14#include <linux/inet_diag.h>
 15#include <linux/sock_diag.h>
 16
 17static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
 18static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
 19static DEFINE_MUTEX(sock_diag_table_mutex);
 20static struct workqueue_struct *broadcast_wq;
 21
 22static u64 sock_gen_cookie(struct sock *sk)
 
 
 23{
 24	while (1) {
 25		u64 res = atomic64_read(&sk->sk_cookie);
 
 
 
 
 26
 27		if (res)
 28			return res;
 29		res = atomic64_inc_return(&sock_net(sk)->cookie_gen);
 30		atomic64_cmpxchg(&sk->sk_cookie, 0, res);
 31	}
 
 32}
 33
 34int sock_diag_check_cookie(struct sock *sk, const __u32 *cookie)
 35{
 36	u64 res;
 37
 38	if (cookie[0] == INET_DIAG_NOCOOKIE && cookie[1] == INET_DIAG_NOCOOKIE)
 39		return 0;
 40
 41	res = sock_gen_cookie(sk);
 42	if ((u32)res != cookie[0] || (u32)(res >> 32) != cookie[1])
 43		return -ESTALE;
 44
 45	return 0;
 46}
 47EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
 48
 49void sock_diag_save_cookie(struct sock *sk, __u32 *cookie)
 50{
 51	u64 res = sock_gen_cookie(sk);
 52
 53	cookie[0] = (u32)res;
 54	cookie[1] = (u32)(res >> 32);
 55}
 56EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
 57
 58int sock_diag_put_meminfo(struct sock *sk, struct sk_buff *skb, int attrtype)
 59{
 60	u32 mem[SK_MEMINFO_VARS];
 61
 62	mem[SK_MEMINFO_RMEM_ALLOC] = sk_rmem_alloc_get(sk);
 63	mem[SK_MEMINFO_RCVBUF] = sk->sk_rcvbuf;
 64	mem[SK_MEMINFO_WMEM_ALLOC] = sk_wmem_alloc_get(sk);
 65	mem[SK_MEMINFO_SNDBUF] = sk->sk_sndbuf;
 66	mem[SK_MEMINFO_FWD_ALLOC] = sk->sk_forward_alloc;
 67	mem[SK_MEMINFO_WMEM_QUEUED] = sk->sk_wmem_queued;
 68	mem[SK_MEMINFO_OPTMEM] = atomic_read(&sk->sk_omem_alloc);
 69	mem[SK_MEMINFO_BACKLOG] = sk->sk_backlog.len;
 70	mem[SK_MEMINFO_DROPS] = atomic_read(&sk->sk_drops);
 71
 72	return nla_put(skb, attrtype, sizeof(mem), &mem);
 73}
 74EXPORT_SYMBOL_GPL(sock_diag_put_meminfo);
 75
 76int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk,
 77			     struct sk_buff *skb, int attrtype)
 78{
 79	struct sock_fprog_kern *fprog;
 80	struct sk_filter *filter;
 81	struct nlattr *attr;
 82	unsigned int flen;
 83	int err = 0;
 84
 85	if (!may_report_filterinfo) {
 86		nla_reserve(skb, attrtype, 0);
 87		return 0;
 88	}
 89
 90	rcu_read_lock();
 91	filter = rcu_dereference(sk->sk_filter);
 92	if (!filter)
 93		goto out;
 94
 95	fprog = filter->prog->orig_prog;
 96	if (!fprog)
 97		goto out;
 98
 99	flen = bpf_classic_proglen(fprog);
100
101	attr = nla_reserve(skb, attrtype, flen);
102	if (attr == NULL) {
103		err = -EMSGSIZE;
104		goto out;
105	}
106
107	memcpy(nla_data(attr), fprog->filter, flen);
108out:
109	rcu_read_unlock();
110	return err;
111}
112EXPORT_SYMBOL(sock_diag_put_filterinfo);
113
114struct broadcast_sk {
115	struct sock *sk;
116	struct work_struct work;
117};
118
119static size_t sock_diag_nlmsg_size(void)
120{
121	return NLMSG_ALIGN(sizeof(struct inet_diag_msg)
122	       + nla_total_size(sizeof(u8)) /* INET_DIAG_PROTOCOL */
123	       + nla_total_size_64bit(sizeof(struct tcp_info))); /* INET_DIAG_INFO */
124}
125
126static void sock_diag_broadcast_destroy_work(struct work_struct *work)
127{
128	struct broadcast_sk *bsk =
129		container_of(work, struct broadcast_sk, work);
130	struct sock *sk = bsk->sk;
131	const struct sock_diag_handler *hndl;
132	struct sk_buff *skb;
133	const enum sknetlink_groups group = sock_diag_destroy_group(sk);
134	int err = -1;
135
136	WARN_ON(group == SKNLGRP_NONE);
137
138	skb = nlmsg_new(sock_diag_nlmsg_size(), GFP_KERNEL);
139	if (!skb)
140		goto out;
141
142	mutex_lock(&sock_diag_table_mutex);
143	hndl = sock_diag_handlers[sk->sk_family];
144	if (hndl && hndl->get_info)
145		err = hndl->get_info(skb, sk);
146	mutex_unlock(&sock_diag_table_mutex);
147
148	if (!err)
149		nlmsg_multicast(sock_net(sk)->diag_nlsk, skb, 0, group,
150				GFP_KERNEL);
151	else
152		kfree_skb(skb);
153out:
154	sk_destruct(sk);
155	kfree(bsk);
156}
157
158void sock_diag_broadcast_destroy(struct sock *sk)
159{
160	/* Note, this function is often called from an interrupt context. */
161	struct broadcast_sk *bsk =
162		kmalloc(sizeof(struct broadcast_sk), GFP_ATOMIC);
163	if (!bsk)
164		return sk_destruct(sk);
165	bsk->sk = sk;
166	INIT_WORK(&bsk->work, sock_diag_broadcast_destroy_work);
167	queue_work(broadcast_wq, &bsk->work);
168}
169
170void sock_diag_register_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh))
171{
172	mutex_lock(&sock_diag_table_mutex);
173	inet_rcv_compat = fn;
174	mutex_unlock(&sock_diag_table_mutex);
175}
176EXPORT_SYMBOL_GPL(sock_diag_register_inet_compat);
177
178void sock_diag_unregister_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh))
179{
180	mutex_lock(&sock_diag_table_mutex);
181	inet_rcv_compat = NULL;
182	mutex_unlock(&sock_diag_table_mutex);
183}
184EXPORT_SYMBOL_GPL(sock_diag_unregister_inet_compat);
185
186int sock_diag_register(const struct sock_diag_handler *hndl)
187{
188	int err = 0;
189
190	if (hndl->family >= AF_MAX)
191		return -EINVAL;
192
193	mutex_lock(&sock_diag_table_mutex);
194	if (sock_diag_handlers[hndl->family])
195		err = -EBUSY;
196	else
197		sock_diag_handlers[hndl->family] = hndl;
198	mutex_unlock(&sock_diag_table_mutex);
199
200	return err;
201}
202EXPORT_SYMBOL_GPL(sock_diag_register);
203
204void sock_diag_unregister(const struct sock_diag_handler *hnld)
205{
206	int family = hnld->family;
207
208	if (family >= AF_MAX)
209		return;
210
211	mutex_lock(&sock_diag_table_mutex);
212	BUG_ON(sock_diag_handlers[family] != hnld);
213	sock_diag_handlers[family] = NULL;
214	mutex_unlock(&sock_diag_table_mutex);
215}
216EXPORT_SYMBOL_GPL(sock_diag_unregister);
217
218static int __sock_diag_cmd(struct sk_buff *skb, struct nlmsghdr *nlh)
219{
220	int err;
221	struct sock_diag_req *req = nlmsg_data(nlh);
222	const struct sock_diag_handler *hndl;
223
224	if (nlmsg_len(nlh) < sizeof(*req))
225		return -EINVAL;
226
227	if (req->sdiag_family >= AF_MAX)
228		return -EINVAL;
 
229
230	if (sock_diag_handlers[req->sdiag_family] == NULL)
231		request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
232				NETLINK_SOCK_DIAG, req->sdiag_family);
233
234	mutex_lock(&sock_diag_table_mutex);
235	hndl = sock_diag_handlers[req->sdiag_family];
236	if (hndl == NULL)
237		err = -ENOENT;
238	else if (nlh->nlmsg_type == SOCK_DIAG_BY_FAMILY)
239		err = hndl->dump(skb, nlh);
240	else if (nlh->nlmsg_type == SOCK_DESTROY && hndl->destroy)
241		err = hndl->destroy(skb, nlh);
242	else
243		err = -EOPNOTSUPP;
244	mutex_unlock(&sock_diag_table_mutex);
245
246	return err;
247}
248
249static int sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
 
250{
251	int ret;
252
253	switch (nlh->nlmsg_type) {
254	case TCPDIAG_GETSOCK:
255	case DCCPDIAG_GETSOCK:
256		if (inet_rcv_compat == NULL)
257			request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
258					NETLINK_SOCK_DIAG, AF_INET);
259
260		mutex_lock(&sock_diag_table_mutex);
261		if (inet_rcv_compat != NULL)
262			ret = inet_rcv_compat(skb, nlh);
263		else
264			ret = -EOPNOTSUPP;
265		mutex_unlock(&sock_diag_table_mutex);
266
267		return ret;
268	case SOCK_DIAG_BY_FAMILY:
269	case SOCK_DESTROY:
270		return __sock_diag_cmd(skb, nlh);
271	default:
272		return -EINVAL;
273	}
274}
275
276static DEFINE_MUTEX(sock_diag_mutex);
277
278static void sock_diag_rcv(struct sk_buff *skb)
279{
280	mutex_lock(&sock_diag_mutex);
281	netlink_rcv_skb(skb, &sock_diag_rcv_msg);
282	mutex_unlock(&sock_diag_mutex);
283}
284
285static int sock_diag_bind(struct net *net, int group)
286{
287	switch (group) {
288	case SKNLGRP_INET_TCP_DESTROY:
289	case SKNLGRP_INET_UDP_DESTROY:
290		if (!sock_diag_handlers[AF_INET])
291			request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
292				       NETLINK_SOCK_DIAG, AF_INET);
293		break;
294	case SKNLGRP_INET6_TCP_DESTROY:
295	case SKNLGRP_INET6_UDP_DESTROY:
296		if (!sock_diag_handlers[AF_INET6])
297			request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
298				       NETLINK_SOCK_DIAG, AF_INET);
299		break;
300	}
301	return 0;
302}
303
304int sock_diag_destroy(struct sock *sk, int err)
305{
306	if (!ns_capable(sock_net(sk)->user_ns, CAP_NET_ADMIN))
307		return -EPERM;
308
309	if (!sk->sk_prot->diag_destroy)
310		return -EOPNOTSUPP;
311
312	return sk->sk_prot->diag_destroy(sk, err);
313}
314EXPORT_SYMBOL_GPL(sock_diag_destroy);
315
316static int __net_init diag_net_init(struct net *net)
317{
318	struct netlink_kernel_cfg cfg = {
319		.groups	= SKNLGRP_MAX,
320		.input	= sock_diag_rcv,
321		.bind	= sock_diag_bind,
322		.flags	= NL_CFG_F_NONROOT_RECV,
323	};
324
325	net->diag_nlsk = netlink_kernel_create(net, NETLINK_SOCK_DIAG, &cfg);
326	return net->diag_nlsk == NULL ? -ENOMEM : 0;
327}
328
329static void __net_exit diag_net_exit(struct net *net)
330{
331	netlink_kernel_release(net->diag_nlsk);
332	net->diag_nlsk = NULL;
333}
334
335static struct pernet_operations diag_net_ops = {
336	.init = diag_net_init,
337	.exit = diag_net_exit,
338};
339
340static int __init sock_diag_init(void)
341{
342	broadcast_wq = alloc_workqueue("sock_diag_events", 0, 0);
343	BUG_ON(!broadcast_wq);
344	return register_pernet_subsys(&diag_net_ops);
345}
346device_initcall(sock_diag_init);