Paul Gortmaker | b6191ae | 2015-10-07 17:27:43 -0400 | [diff] [blame] | 1 | /* License: GPL */ |
| 2 | |
Pavel Emelyanov | 8ef874b | 2011-12-06 07:59:52 +0000 | [diff] [blame] | 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> |
Pavel Emelyanov | 5d2e5f2 | 2011-12-30 00:53:13 +0000 | [diff] [blame] | 9 | #include <net/sock.h> |
Craig Gallek | eb4cb00 | 2015-06-15 11:26:18 -0400 | [diff] [blame] | 10 | #include <linux/kernel.h> |
| 11 | #include <linux/tcp.h> |
| 12 | #include <linux/workqueue.h> |
Pavel Emelyanov | 8ef874b | 2011-12-06 07:59:52 +0000 | [diff] [blame] | 13 | |
| 14 | #include <linux/inet_diag.h> |
| 15 | #include <linux/sock_diag.h> |
| 16 | |
Shan Wei | 8dcf01f | 2012-04-24 18:21:07 +0000 | [diff] [blame] | 17 | static const struct sock_diag_handler *sock_diag_handlers[AF_MAX]; |
Pavel Emelyanov | 8ef874b | 2011-12-06 07:59:52 +0000 | [diff] [blame] | 18 | static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh); |
| 19 | static DEFINE_MUTEX(sock_diag_table_mutex); |
Craig Gallek | eb4cb00 | 2015-06-15 11:26:18 -0400 | [diff] [blame] | 20 | static struct workqueue_struct *broadcast_wq; |
Pavel Emelyanov | 8ef874b | 2011-12-06 07:59:52 +0000 | [diff] [blame] | 21 | |
Eric Dumazet | 33cf7c9 | 2015-03-11 18:53:14 -0700 | [diff] [blame] | 22 | static u64 sock_gen_cookie(struct sock *sk) |
Pavel Emelyanov | f65c1b5 | 2011-12-15 02:43:44 +0000 | [diff] [blame] | 23 | { |
Eric Dumazet | 33cf7c9 | 2015-03-11 18:53:14 -0700 | [diff] [blame] | 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 | |
| 34 | int 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) |
Pavel Emelyanov | f65c1b5 | 2011-12-15 02:43:44 +0000 | [diff] [blame] | 39 | return 0; |
Eric Dumazet | 33cf7c9 | 2015-03-11 18:53:14 -0700 | [diff] [blame] | 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; |
Pavel Emelyanov | f65c1b5 | 2011-12-15 02:43:44 +0000 | [diff] [blame] | 46 | } |
| 47 | EXPORT_SYMBOL_GPL(sock_diag_check_cookie); |
| 48 | |
Eric Dumazet | 33cf7c9 | 2015-03-11 18:53:14 -0700 | [diff] [blame] | 49 | void sock_diag_save_cookie(struct sock *sk, __u32 *cookie) |
Pavel Emelyanov | f65c1b5 | 2011-12-15 02:43:44 +0000 | [diff] [blame] | 50 | { |
Eric Dumazet | 33cf7c9 | 2015-03-11 18:53:14 -0700 | [diff] [blame] | 51 | u64 res = sock_gen_cookie(sk); |
| 52 | |
| 53 | cookie[0] = (u32)res; |
| 54 | cookie[1] = (u32)(res >> 32); |
Pavel Emelyanov | f65c1b5 | 2011-12-15 02:43:44 +0000 | [diff] [blame] | 55 | } |
| 56 | EXPORT_SYMBOL_GPL(sock_diag_save_cookie); |
| 57 | |
Pavel Emelyanov | 5d2e5f2 | 2011-12-30 00:53:13 +0000 | [diff] [blame] | 58 | int sock_diag_put_meminfo(struct sock *sk, struct sk_buff *skb, int attrtype) |
| 59 | { |
Thomas Graf | 7b46866 | 2012-06-26 23:36:11 +0000 | [diff] [blame] | 60 | u32 mem[SK_MEMINFO_VARS]; |
Pavel Emelyanov | 5d2e5f2 | 2011-12-30 00:53:13 +0000 | [diff] [blame] | 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); |
Eric Dumazet | d594e98 | 2012-06-04 03:50:35 +0000 | [diff] [blame] | 69 | mem[SK_MEMINFO_BACKLOG] = sk->sk_backlog.len; |
Eric Dumazet | 1523930 | 2016-04-01 08:52:18 -0700 | [diff] [blame] | 70 | mem[SK_MEMINFO_DROPS] = atomic_read(&sk->sk_drops); |
Pavel Emelyanov | 5d2e5f2 | 2011-12-30 00:53:13 +0000 | [diff] [blame] | 71 | |
Thomas Graf | 7b46866 | 2012-06-26 23:36:11 +0000 | [diff] [blame] | 72 | return nla_put(skb, attrtype, sizeof(mem), &mem); |
Pavel Emelyanov | 5d2e5f2 | 2011-12-30 00:53:13 +0000 | [diff] [blame] | 73 | } |
| 74 | EXPORT_SYMBOL_GPL(sock_diag_put_meminfo); |
| 75 | |
Eric W. Biederman | a53b72c | 2014-04-23 14:26:25 -0700 | [diff] [blame] | 76 | int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk, |
Nicolas Dichtel | e8d9612 | 2013-04-25 06:53:54 +0000 | [diff] [blame] | 77 | struct sk_buff *skb, int attrtype) |
| 78 | { |
Daniel Borkmann | a3ea269 | 2014-03-28 18:58:19 +0100 | [diff] [blame] | 79 | struct sock_fprog_kern *fprog; |
Nicolas Dichtel | e8d9612 | 2013-04-25 06:53:54 +0000 | [diff] [blame] | 80 | struct sk_filter *filter; |
Daniel Borkmann | a3ea269 | 2014-03-28 18:58:19 +0100 | [diff] [blame] | 81 | struct nlattr *attr; |
| 82 | unsigned int flen; |
Nicolas Dichtel | e8d9612 | 2013-04-25 06:53:54 +0000 | [diff] [blame] | 83 | int err = 0; |
| 84 | |
Eric W. Biederman | a53b72c | 2014-04-23 14:26:25 -0700 | [diff] [blame] | 85 | if (!may_report_filterinfo) { |
Nicolas Dichtel | e8d9612 | 2013-04-25 06:53:54 +0000 | [diff] [blame] | 86 | nla_reserve(skb, attrtype, 0); |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | rcu_read_lock(); |
Nicolas Dichtel | e8d9612 | 2013-04-25 06:53:54 +0000 | [diff] [blame] | 91 | filter = rcu_dereference(sk->sk_filter); |
Daniel Borkmann | a3ea269 | 2014-03-28 18:58:19 +0100 | [diff] [blame] | 92 | if (!filter) |
| 93 | goto out; |
Nicolas Dichtel | e8d9612 | 2013-04-25 06:53:54 +0000 | [diff] [blame] | 94 | |
Alexei Starovoitov | 7ae457c | 2014-07-30 20:34:16 -0700 | [diff] [blame] | 95 | fprog = filter->prog->orig_prog; |
Daniel Borkmann | b382c08 | 2015-09-02 14:00:36 +0200 | [diff] [blame] | 96 | if (!fprog) |
| 97 | goto out; |
| 98 | |
Alexei Starovoitov | 009937e | 2014-07-30 20:34:13 -0700 | [diff] [blame] | 99 | flen = bpf_classic_proglen(fprog); |
Daniel Borkmann | a3ea269 | 2014-03-28 18:58:19 +0100 | [diff] [blame] | 100 | |
| 101 | attr = nla_reserve(skb, attrtype, flen); |
Nicolas Dichtel | e8d9612 | 2013-04-25 06:53:54 +0000 | [diff] [blame] | 102 | if (attr == NULL) { |
| 103 | err = -EMSGSIZE; |
| 104 | goto out; |
| 105 | } |
| 106 | |
Daniel Borkmann | a3ea269 | 2014-03-28 18:58:19 +0100 | [diff] [blame] | 107 | memcpy(nla_data(attr), fprog->filter, flen); |
Nicolas Dichtel | e8d9612 | 2013-04-25 06:53:54 +0000 | [diff] [blame] | 108 | out: |
| 109 | rcu_read_unlock(); |
| 110 | return err; |
| 111 | } |
| 112 | EXPORT_SYMBOL(sock_diag_put_filterinfo); |
| 113 | |
Craig Gallek | eb4cb00 | 2015-06-15 11:26:18 -0400 | [diff] [blame] | 114 | struct broadcast_sk { |
| 115 | struct sock *sk; |
| 116 | struct work_struct work; |
| 117 | }; |
| 118 | |
| 119 | static 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 */ |
Nicolas Dichtel | 6ed46d1 | 2016-04-26 10:06:14 +0200 | [diff] [blame] | 123 | + nla_total_size_64bit(sizeof(struct tcp_info))); /* INET_DIAG_INFO */ |
Craig Gallek | eb4cb00 | 2015-06-15 11:26:18 -0400 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | static 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); |
| 153 | out: |
| 154 | sk_destruct(sk); |
| 155 | kfree(bsk); |
| 156 | } |
| 157 | |
| 158 | void 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 | |
Pavel Emelyanov | 8ef874b | 2011-12-06 07:59:52 +0000 | [diff] [blame] | 170 | void 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 | } |
| 176 | EXPORT_SYMBOL_GPL(sock_diag_register_inet_compat); |
| 177 | |
| 178 | void 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 | } |
| 184 | EXPORT_SYMBOL_GPL(sock_diag_unregister_inet_compat); |
| 185 | |
Shan Wei | 8dcf01f | 2012-04-24 18:21:07 +0000 | [diff] [blame] | 186 | int sock_diag_register(const struct sock_diag_handler *hndl) |
Pavel Emelyanov | 8ef874b | 2011-12-06 07:59:52 +0000 | [diff] [blame] | 187 | { |
| 188 | int err = 0; |
| 189 | |
Dan Carpenter | 6f8e4ad | 2011-12-07 20:49:38 +0000 | [diff] [blame] | 190 | if (hndl->family >= AF_MAX) |
Pavel Emelyanov | 8ef874b | 2011-12-06 07:59:52 +0000 | [diff] [blame] | 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 | } |
| 202 | EXPORT_SYMBOL_GPL(sock_diag_register); |
| 203 | |
Shan Wei | 8dcf01f | 2012-04-24 18:21:07 +0000 | [diff] [blame] | 204 | void sock_diag_unregister(const struct sock_diag_handler *hnld) |
Pavel Emelyanov | 8ef874b | 2011-12-06 07:59:52 +0000 | [diff] [blame] | 205 | { |
| 206 | int family = hnld->family; |
| 207 | |
Dan Carpenter | 6f8e4ad | 2011-12-07 20:49:38 +0000 | [diff] [blame] | 208 | if (family >= AF_MAX) |
Pavel Emelyanov | 8ef874b | 2011-12-06 07:59:52 +0000 | [diff] [blame] | 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 | } |
| 216 | EXPORT_SYMBOL_GPL(sock_diag_unregister); |
| 217 | |
Lorenzo Colitti | 64be0ae | 2015-12-16 12:30:03 +0900 | [diff] [blame] | 218 | static int __sock_diag_cmd(struct sk_buff *skb, struct nlmsghdr *nlh) |
Pavel Emelyanov | 8ef874b | 2011-12-06 07:59:52 +0000 | [diff] [blame] | 219 | { |
| 220 | int err; |
Thomas Graf | 7b46866 | 2012-06-26 23:36:11 +0000 | [diff] [blame] | 221 | struct sock_diag_req *req = nlmsg_data(nlh); |
Shan Wei | 8dcf01f | 2012-04-24 18:21:07 +0000 | [diff] [blame] | 222 | const struct sock_diag_handler *hndl; |
Pavel Emelyanov | 8ef874b | 2011-12-06 07:59:52 +0000 | [diff] [blame] | 223 | |
| 224 | if (nlmsg_len(nlh) < sizeof(*req)) |
| 225 | return -EINVAL; |
| 226 | |
Mathias Krause | 6e601a5 | 2013-02-23 01:13:47 +0000 | [diff] [blame] | 227 | if (req->sdiag_family >= AF_MAX) |
| 228 | return -EINVAL; |
| 229 | |
Mathias Krause | 8e90455 | 2013-02-23 01:13:48 +0000 | [diff] [blame] | 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]; |
Pavel Emelyanov | 8ef874b | 2011-12-06 07:59:52 +0000 | [diff] [blame] | 236 | if (hndl == NULL) |
| 237 | err = -ENOENT; |
Lorenzo Colitti | 64be0ae | 2015-12-16 12:30:03 +0900 | [diff] [blame] | 238 | else if (nlh->nlmsg_type == SOCK_DIAG_BY_FAMILY) |
Pavel Emelyanov | 8ef874b | 2011-12-06 07:59:52 +0000 | [diff] [blame] | 239 | err = hndl->dump(skb, nlh); |
Lorenzo Colitti | 64be0ae | 2015-12-16 12:30:03 +0900 | [diff] [blame] | 240 | else if (nlh->nlmsg_type == SOCK_DESTROY && hndl->destroy) |
| 241 | err = hndl->destroy(skb, nlh); |
| 242 | else |
| 243 | err = -EOPNOTSUPP; |
Mathias Krause | 8e90455 | 2013-02-23 01:13:48 +0000 | [diff] [blame] | 244 | mutex_unlock(&sock_diag_table_mutex); |
Pavel Emelyanov | 8ef874b | 2011-12-06 07:59:52 +0000 | [diff] [blame] | 245 | |
| 246 | return err; |
| 247 | } |
| 248 | |
| 249 | static 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, |
Pavel Emelyanov | aec8dc6 | 2011-12-15 02:43:27 +0000 | [diff] [blame] | 258 | NETLINK_SOCK_DIAG, AF_INET); |
Pavel Emelyanov | 8ef874b | 2011-12-06 07:59:52 +0000 | [diff] [blame] | 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: |
Lorenzo Colitti | 64be0ae | 2015-12-16 12:30:03 +0900 | [diff] [blame] | 269 | case SOCK_DESTROY: |
| 270 | return __sock_diag_cmd(skb, nlh); |
Pavel Emelyanov | 8ef874b | 2011-12-06 07:59:52 +0000 | [diff] [blame] | 271 | default: |
| 272 | return -EINVAL; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | static DEFINE_MUTEX(sock_diag_mutex); |
| 277 | |
| 278 | static 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 | |
Craig Gallek | eb4cb00 | 2015-06-15 11:26:18 -0400 | [diff] [blame] | 285 | static 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 | |
Lorenzo Colitti | 64be0ae | 2015-12-16 12:30:03 +0900 | [diff] [blame] | 304 | int 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 | } |
| 314 | EXPORT_SYMBOL_GPL(sock_diag_destroy); |
| 315 | |
Andrey Vagin | 51d7ccc | 2012-07-16 04:28:49 +0000 | [diff] [blame] | 316 | static int __net_init diag_net_init(struct net *net) |
Pavel Emelyanov | 8ef874b | 2011-12-06 07:59:52 +0000 | [diff] [blame] | 317 | { |
Pablo Neira Ayuso | a31f2d1 | 2012-06-29 06:15:21 +0000 | [diff] [blame] | 318 | struct netlink_kernel_cfg cfg = { |
Craig Gallek | eb4cb00 | 2015-06-15 11:26:18 -0400 | [diff] [blame] | 319 | .groups = SKNLGRP_MAX, |
Pablo Neira Ayuso | a31f2d1 | 2012-06-29 06:15:21 +0000 | [diff] [blame] | 320 | .input = sock_diag_rcv, |
Craig Gallek | eb4cb00 | 2015-06-15 11:26:18 -0400 | [diff] [blame] | 321 | .bind = sock_diag_bind, |
| 322 | .flags = NL_CFG_F_NONROOT_RECV, |
Pablo Neira Ayuso | a31f2d1 | 2012-06-29 06:15:21 +0000 | [diff] [blame] | 323 | }; |
| 324 | |
Pablo Neira Ayuso | 9f00d97 | 2012-09-08 02:53:54 +0000 | [diff] [blame] | 325 | net->diag_nlsk = netlink_kernel_create(net, NETLINK_SOCK_DIAG, &cfg); |
Andrey Vagin | 51d7ccc | 2012-07-16 04:28:49 +0000 | [diff] [blame] | 326 | return net->diag_nlsk == NULL ? -ENOMEM : 0; |
| 327 | } |
| 328 | |
| 329 | static void __net_exit diag_net_exit(struct net *net) |
| 330 | { |
| 331 | netlink_kernel_release(net->diag_nlsk); |
| 332 | net->diag_nlsk = NULL; |
| 333 | } |
| 334 | |
| 335 | static struct pernet_operations diag_net_ops = { |
| 336 | .init = diag_net_init, |
| 337 | .exit = diag_net_exit, |
| 338 | }; |
| 339 | |
| 340 | static int __init sock_diag_init(void) |
| 341 | { |
Craig Gallek | eb4cb00 | 2015-06-15 11:26:18 -0400 | [diff] [blame] | 342 | broadcast_wq = alloc_workqueue("sock_diag_events", 0, 0); |
| 343 | BUG_ON(!broadcast_wq); |
Andrey Vagin | 51d7ccc | 2012-07-16 04:28:49 +0000 | [diff] [blame] | 344 | return register_pernet_subsys(&diag_net_ops); |
Pavel Emelyanov | 8ef874b | 2011-12-06 07:59:52 +0000 | [diff] [blame] | 345 | } |
Paul Gortmaker | b6191ae | 2015-10-07 17:27:43 -0400 | [diff] [blame] | 346 | device_initcall(sock_diag_init); |