GNU Linux-libre 4.19.245-gnu1
[releases.git] / net / ipv4 / inet_diag.c
1 /*
2  * inet_diag.c  Module for monitoring INET transport protocols sockets.
3  *
4  * Authors:     Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
5  *
6  *      This program is free software; you can redistribute it and/or
7  *      modify it under the terms of the GNU General Public License
8  *      as published by the Free Software Foundation; either version
9  *      2 of the License, or (at your option) any later version.
10  */
11
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/types.h>
15 #include <linux/fcntl.h>
16 #include <linux/random.h>
17 #include <linux/slab.h>
18 #include <linux/cache.h>
19 #include <linux/init.h>
20 #include <linux/time.h>
21
22 #include <net/icmp.h>
23 #include <net/tcp.h>
24 #include <net/ipv6.h>
25 #include <net/inet_common.h>
26 #include <net/inet_connection_sock.h>
27 #include <net/inet_hashtables.h>
28 #include <net/inet_timewait_sock.h>
29 #include <net/inet6_hashtables.h>
30 #include <net/netlink.h>
31
32 #include <linux/inet.h>
33 #include <linux/stddef.h>
34
35 #include <linux/inet_diag.h>
36 #include <linux/sock_diag.h>
37
38 static const struct inet_diag_handler **inet_diag_table;
39
40 struct inet_diag_entry {
41         const __be32 *saddr;
42         const __be32 *daddr;
43         u16 sport;
44         u16 dport;
45         u16 family;
46         u16 userlocks;
47         u32 ifindex;
48         u32 mark;
49 };
50
51 static DEFINE_MUTEX(inet_diag_table_mutex);
52
53 static const struct inet_diag_handler *inet_diag_lock_handler(int proto)
54 {
55         if (!inet_diag_table[proto])
56                 sock_load_diag_module(AF_INET, proto);
57
58         mutex_lock(&inet_diag_table_mutex);
59         if (!inet_diag_table[proto])
60                 return ERR_PTR(-ENOENT);
61
62         return inet_diag_table[proto];
63 }
64
65 static void inet_diag_unlock_handler(const struct inet_diag_handler *handler)
66 {
67         mutex_unlock(&inet_diag_table_mutex);
68 }
69
70 void inet_diag_msg_common_fill(struct inet_diag_msg *r, struct sock *sk)
71 {
72         r->idiag_family = sk->sk_family;
73
74         r->id.idiag_sport = htons(sk->sk_num);
75         r->id.idiag_dport = sk->sk_dport;
76         r->id.idiag_if = sk->sk_bound_dev_if;
77         sock_diag_save_cookie(sk, r->id.idiag_cookie);
78
79 #if IS_ENABLED(CONFIG_IPV6)
80         if (sk->sk_family == AF_INET6) {
81                 *(struct in6_addr *)r->id.idiag_src = sk->sk_v6_rcv_saddr;
82                 *(struct in6_addr *)r->id.idiag_dst = sk->sk_v6_daddr;
83         } else
84 #endif
85         {
86         memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
87         memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
88
89         r->id.idiag_src[0] = sk->sk_rcv_saddr;
90         r->id.idiag_dst[0] = sk->sk_daddr;
91         }
92 }
93 EXPORT_SYMBOL_GPL(inet_diag_msg_common_fill);
94
95 static size_t inet_sk_attr_size(struct sock *sk,
96                                 const struct inet_diag_req_v2 *req,
97                                 bool net_admin)
98 {
99         const struct inet_diag_handler *handler;
100         size_t aux = 0;
101
102         handler = inet_diag_table[req->sdiag_protocol];
103         if (handler && handler->idiag_get_aux_size)
104                 aux = handler->idiag_get_aux_size(sk, net_admin);
105
106         return    nla_total_size(sizeof(struct tcp_info))
107                 + nla_total_size(sizeof(struct inet_diag_msg))
108                 + inet_diag_msg_attrs_size()
109                 + nla_total_size(sizeof(struct inet_diag_meminfo))
110                 + nla_total_size(SK_MEMINFO_VARS * sizeof(u32))
111                 + nla_total_size(TCP_CA_NAME_MAX)
112                 + nla_total_size(sizeof(struct tcpvegas_info))
113                 + aux
114                 + 64;
115 }
116
117 int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb,
118                              struct inet_diag_msg *r, int ext,
119                              struct user_namespace *user_ns,
120                              bool net_admin)
121 {
122         const struct inet_sock *inet = inet_sk(sk);
123
124         if (nla_put_u8(skb, INET_DIAG_SHUTDOWN, sk->sk_shutdown))
125                 goto errout;
126
127         /* IPv6 dual-stack sockets use inet->tos for IPv4 connections,
128          * hence this needs to be included regardless of socket family.
129          */
130         if (ext & (1 << (INET_DIAG_TOS - 1)))
131                 if (nla_put_u8(skb, INET_DIAG_TOS, inet->tos) < 0)
132                         goto errout;
133
134 #if IS_ENABLED(CONFIG_IPV6)
135         if (r->idiag_family == AF_INET6) {
136                 if (ext & (1 << (INET_DIAG_TCLASS - 1)))
137                         if (nla_put_u8(skb, INET_DIAG_TCLASS,
138                                        inet6_sk(sk)->tclass) < 0)
139                                 goto errout;
140
141                 if (((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) &&
142                     nla_put_u8(skb, INET_DIAG_SKV6ONLY, ipv6_only_sock(sk)))
143                         goto errout;
144         }
145 #endif
146
147         if (net_admin && nla_put_u32(skb, INET_DIAG_MARK, sk->sk_mark))
148                 goto errout;
149
150         if (ext & (1 << (INET_DIAG_CLASS_ID - 1)) ||
151             ext & (1 << (INET_DIAG_TCLASS - 1))) {
152                 u32 classid = 0;
153
154 #ifdef CONFIG_SOCK_CGROUP_DATA
155                 classid = sock_cgroup_classid(&sk->sk_cgrp_data);
156 #endif
157                 /* Fallback to socket priority if class id isn't set.
158                  * Classful qdiscs use it as direct reference to class.
159                  * For cgroup2 classid is always zero.
160                  */
161                 if (!classid)
162                         classid = sk->sk_priority;
163
164                 if (nla_put_u32(skb, INET_DIAG_CLASS_ID, classid))
165                         goto errout;
166         }
167
168         r->idiag_uid = from_kuid_munged(user_ns, sock_i_uid(sk));
169         r->idiag_inode = sock_i_ino(sk);
170
171         return 0;
172 errout:
173         return 1;
174 }
175 EXPORT_SYMBOL_GPL(inet_diag_msg_attrs_fill);
176
177 int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
178                       struct sk_buff *skb, const struct inet_diag_req_v2 *req,
179                       struct user_namespace *user_ns,
180                       u32 portid, u32 seq, u16 nlmsg_flags,
181                       const struct nlmsghdr *unlh,
182                       bool net_admin)
183 {
184         const struct tcp_congestion_ops *ca_ops;
185         const struct inet_diag_handler *handler;
186         int ext = req->idiag_ext;
187         struct inet_diag_msg *r;
188         struct nlmsghdr  *nlh;
189         struct nlattr *attr;
190         void *info = NULL;
191
192         handler = inet_diag_table[req->sdiag_protocol];
193         BUG_ON(!handler);
194
195         nlh = nlmsg_put(skb, portid, seq, unlh->nlmsg_type, sizeof(*r),
196                         nlmsg_flags);
197         if (!nlh)
198                 return -EMSGSIZE;
199
200         r = nlmsg_data(nlh);
201         BUG_ON(!sk_fullsock(sk));
202
203         inet_diag_msg_common_fill(r, sk);
204         r->idiag_state = sk->sk_state;
205         r->idiag_timer = 0;
206         r->idiag_retrans = 0;
207
208         if (inet_diag_msg_attrs_fill(sk, skb, r, ext, user_ns, net_admin))
209                 goto errout;
210
211         if (ext & (1 << (INET_DIAG_MEMINFO - 1))) {
212                 struct inet_diag_meminfo minfo = {
213                         .idiag_rmem = sk_rmem_alloc_get(sk),
214                         .idiag_wmem = sk->sk_wmem_queued,
215                         .idiag_fmem = sk->sk_forward_alloc,
216                         .idiag_tmem = sk_wmem_alloc_get(sk),
217                 };
218
219                 if (nla_put(skb, INET_DIAG_MEMINFO, sizeof(minfo), &minfo) < 0)
220                         goto errout;
221         }
222
223         if (ext & (1 << (INET_DIAG_SKMEMINFO - 1)))
224                 if (sock_diag_put_meminfo(sk, skb, INET_DIAG_SKMEMINFO))
225                         goto errout;
226
227         /*
228          * RAW sockets might have user-defined protocols assigned,
229          * so report the one supplied on socket creation.
230          */
231         if (sk->sk_type == SOCK_RAW) {
232                 if (nla_put_u8(skb, INET_DIAG_PROTOCOL, sk->sk_protocol))
233                         goto errout;
234         }
235
236         if (!icsk) {
237                 handler->idiag_get_info(sk, r, NULL);
238                 goto out;
239         }
240
241         if (icsk->icsk_pending == ICSK_TIME_RETRANS ||
242             icsk->icsk_pending == ICSK_TIME_REO_TIMEOUT ||
243             icsk->icsk_pending == ICSK_TIME_LOSS_PROBE) {
244                 r->idiag_timer = 1;
245                 r->idiag_retrans = icsk->icsk_retransmits;
246                 r->idiag_expires =
247                         jiffies_to_msecs(icsk->icsk_timeout - jiffies);
248         } else if (icsk->icsk_pending == ICSK_TIME_PROBE0) {
249                 r->idiag_timer = 4;
250                 r->idiag_retrans = icsk->icsk_probes_out;
251                 r->idiag_expires =
252                         jiffies_to_msecs(icsk->icsk_timeout - jiffies);
253         } else if (timer_pending(&sk->sk_timer)) {
254                 r->idiag_timer = 2;
255                 r->idiag_retrans = icsk->icsk_probes_out;
256                 r->idiag_expires =
257                         jiffies_to_msecs(sk->sk_timer.expires - jiffies);
258         } else {
259                 r->idiag_timer = 0;
260                 r->idiag_expires = 0;
261         }
262
263         if ((ext & (1 << (INET_DIAG_INFO - 1))) && handler->idiag_info_size) {
264                 attr = nla_reserve_64bit(skb, INET_DIAG_INFO,
265                                          handler->idiag_info_size,
266                                          INET_DIAG_PAD);
267                 if (!attr)
268                         goto errout;
269
270                 info = nla_data(attr);
271         }
272
273         if (ext & (1 << (INET_DIAG_CONG - 1))) {
274                 int err = 0;
275
276                 rcu_read_lock();
277                 ca_ops = READ_ONCE(icsk->icsk_ca_ops);
278                 if (ca_ops)
279                         err = nla_put_string(skb, INET_DIAG_CONG, ca_ops->name);
280                 rcu_read_unlock();
281                 if (err < 0)
282                         goto errout;
283         }
284
285         handler->idiag_get_info(sk, r, info);
286
287         if (ext & (1 << (INET_DIAG_INFO - 1)) && handler->idiag_get_aux)
288                 if (handler->idiag_get_aux(sk, net_admin, skb) < 0)
289                         goto errout;
290
291         if (sk->sk_state < TCP_TIME_WAIT) {
292                 union tcp_cc_info info;
293                 size_t sz = 0;
294                 int attr;
295
296                 rcu_read_lock();
297                 ca_ops = READ_ONCE(icsk->icsk_ca_ops);
298                 if (ca_ops && ca_ops->get_info)
299                         sz = ca_ops->get_info(sk, ext, &attr, &info);
300                 rcu_read_unlock();
301                 if (sz && nla_put(skb, attr, sz, &info) < 0)
302                         goto errout;
303         }
304
305 out:
306         nlmsg_end(skb, nlh);
307         return 0;
308
309 errout:
310         nlmsg_cancel(skb, nlh);
311         return -EMSGSIZE;
312 }
313 EXPORT_SYMBOL_GPL(inet_sk_diag_fill);
314
315 static int inet_csk_diag_fill(struct sock *sk,
316                               struct sk_buff *skb,
317                               const struct inet_diag_req_v2 *req,
318                               struct user_namespace *user_ns,
319                               u32 portid, u32 seq, u16 nlmsg_flags,
320                               const struct nlmsghdr *unlh,
321                               bool net_admin)
322 {
323         return inet_sk_diag_fill(sk, inet_csk(sk), skb, req, user_ns,
324                                  portid, seq, nlmsg_flags, unlh, net_admin);
325 }
326
327 static int inet_twsk_diag_fill(struct sock *sk,
328                                struct sk_buff *skb,
329                                u32 portid, u32 seq, u16 nlmsg_flags,
330                                const struct nlmsghdr *unlh)
331 {
332         struct inet_timewait_sock *tw = inet_twsk(sk);
333         struct inet_diag_msg *r;
334         struct nlmsghdr *nlh;
335         long tmo;
336
337         nlh = nlmsg_put(skb, portid, seq, unlh->nlmsg_type, sizeof(*r),
338                         nlmsg_flags);
339         if (!nlh)
340                 return -EMSGSIZE;
341
342         r = nlmsg_data(nlh);
343         BUG_ON(tw->tw_state != TCP_TIME_WAIT);
344
345         tmo = tw->tw_timer.expires - jiffies;
346         if (tmo < 0)
347                 tmo = 0;
348
349         inet_diag_msg_common_fill(r, sk);
350         r->idiag_retrans      = 0;
351
352         r->idiag_state        = tw->tw_substate;
353         r->idiag_timer        = 3;
354         r->idiag_expires      = jiffies_to_msecs(tmo);
355         r->idiag_rqueue       = 0;
356         r->idiag_wqueue       = 0;
357         r->idiag_uid          = 0;
358         r->idiag_inode        = 0;
359
360         nlmsg_end(skb, nlh);
361         return 0;
362 }
363
364 static int inet_req_diag_fill(struct sock *sk, struct sk_buff *skb,
365                               u32 portid, u32 seq, u16 nlmsg_flags,
366                               const struct nlmsghdr *unlh, bool net_admin)
367 {
368         struct request_sock *reqsk = inet_reqsk(sk);
369         struct inet_diag_msg *r;
370         struct nlmsghdr *nlh;
371         long tmo;
372
373         nlh = nlmsg_put(skb, portid, seq, unlh->nlmsg_type, sizeof(*r),
374                         nlmsg_flags);
375         if (!nlh)
376                 return -EMSGSIZE;
377
378         r = nlmsg_data(nlh);
379         inet_diag_msg_common_fill(r, sk);
380         r->idiag_state = TCP_SYN_RECV;
381         r->idiag_timer = 1;
382         r->idiag_retrans = reqsk->num_retrans;
383
384         BUILD_BUG_ON(offsetof(struct inet_request_sock, ir_cookie) !=
385                      offsetof(struct sock, sk_cookie));
386
387         tmo = inet_reqsk(sk)->rsk_timer.expires - jiffies;
388         r->idiag_expires = (tmo >= 0) ? jiffies_to_msecs(tmo) : 0;
389         r->idiag_rqueue = 0;
390         r->idiag_wqueue = 0;
391         r->idiag_uid    = 0;
392         r->idiag_inode  = 0;
393
394         if (net_admin && nla_put_u32(skb, INET_DIAG_MARK,
395                                      inet_rsk(reqsk)->ir_mark)) {
396                 nlmsg_cancel(skb, nlh);
397                 return -EMSGSIZE;
398         }
399
400         nlmsg_end(skb, nlh);
401         return 0;
402 }
403
404 static int sk_diag_fill(struct sock *sk, struct sk_buff *skb,
405                         const struct inet_diag_req_v2 *r,
406                         struct user_namespace *user_ns,
407                         u32 portid, u32 seq, u16 nlmsg_flags,
408                         const struct nlmsghdr *unlh, bool net_admin)
409 {
410         if (sk->sk_state == TCP_TIME_WAIT)
411                 return inet_twsk_diag_fill(sk, skb, portid, seq,
412                                            nlmsg_flags, unlh);
413
414         if (sk->sk_state == TCP_NEW_SYN_RECV)
415                 return inet_req_diag_fill(sk, skb, portid, seq,
416                                           nlmsg_flags, unlh, net_admin);
417
418         return inet_csk_diag_fill(sk, skb, r, user_ns, portid, seq,
419                                   nlmsg_flags, unlh, net_admin);
420 }
421
422 struct sock *inet_diag_find_one_icsk(struct net *net,
423                                      struct inet_hashinfo *hashinfo,
424                                      const struct inet_diag_req_v2 *req)
425 {
426         struct sock *sk;
427
428         rcu_read_lock();
429         if (req->sdiag_family == AF_INET)
430                 sk = inet_lookup(net, hashinfo, NULL, 0, req->id.idiag_dst[0],
431                                  req->id.idiag_dport, req->id.idiag_src[0],
432                                  req->id.idiag_sport, req->id.idiag_if);
433 #if IS_ENABLED(CONFIG_IPV6)
434         else if (req->sdiag_family == AF_INET6) {
435                 if (ipv6_addr_v4mapped((struct in6_addr *)req->id.idiag_dst) &&
436                     ipv6_addr_v4mapped((struct in6_addr *)req->id.idiag_src))
437                         sk = inet_lookup(net, hashinfo, NULL, 0, req->id.idiag_dst[3],
438                                          req->id.idiag_dport, req->id.idiag_src[3],
439                                          req->id.idiag_sport, req->id.idiag_if);
440                 else
441                         sk = inet6_lookup(net, hashinfo, NULL, 0,
442                                           (struct in6_addr *)req->id.idiag_dst,
443                                           req->id.idiag_dport,
444                                           (struct in6_addr *)req->id.idiag_src,
445                                           req->id.idiag_sport,
446                                           req->id.idiag_if);
447         }
448 #endif
449         else {
450                 rcu_read_unlock();
451                 return ERR_PTR(-EINVAL);
452         }
453         rcu_read_unlock();
454         if (!sk)
455                 return ERR_PTR(-ENOENT);
456
457         if (sock_diag_check_cookie(sk, req->id.idiag_cookie)) {
458                 sock_gen_put(sk);
459                 return ERR_PTR(-ENOENT);
460         }
461
462         return sk;
463 }
464 EXPORT_SYMBOL_GPL(inet_diag_find_one_icsk);
465
466 int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo,
467                             struct sk_buff *in_skb,
468                             const struct nlmsghdr *nlh,
469                             const struct inet_diag_req_v2 *req)
470 {
471         bool net_admin = netlink_net_capable(in_skb, CAP_NET_ADMIN);
472         struct net *net = sock_net(in_skb->sk);
473         struct sk_buff *rep;
474         struct sock *sk;
475         int err;
476
477         sk = inet_diag_find_one_icsk(net, hashinfo, req);
478         if (IS_ERR(sk))
479                 return PTR_ERR(sk);
480
481         rep = nlmsg_new(inet_sk_attr_size(sk, req, net_admin), GFP_KERNEL);
482         if (!rep) {
483                 err = -ENOMEM;
484                 goto out;
485         }
486
487         err = sk_diag_fill(sk, rep, req,
488                            sk_user_ns(NETLINK_CB(in_skb).sk),
489                            NETLINK_CB(in_skb).portid,
490                            nlh->nlmsg_seq, 0, nlh, net_admin);
491         if (err < 0) {
492                 WARN_ON(err == -EMSGSIZE);
493                 nlmsg_free(rep);
494                 goto out;
495         }
496         err = netlink_unicast(net->diag_nlsk, rep, NETLINK_CB(in_skb).portid,
497                               MSG_DONTWAIT);
498         if (err > 0)
499                 err = 0;
500
501 out:
502         if (sk)
503                 sock_gen_put(sk);
504
505         return err;
506 }
507 EXPORT_SYMBOL_GPL(inet_diag_dump_one_icsk);
508
509 static int inet_diag_cmd_exact(int cmd, struct sk_buff *in_skb,
510                                const struct nlmsghdr *nlh,
511                                const struct inet_diag_req_v2 *req)
512 {
513         const struct inet_diag_handler *handler;
514         int err;
515
516         handler = inet_diag_lock_handler(req->sdiag_protocol);
517         if (IS_ERR(handler))
518                 err = PTR_ERR(handler);
519         else if (cmd == SOCK_DIAG_BY_FAMILY)
520                 err = handler->dump_one(in_skb, nlh, req);
521         else if (cmd == SOCK_DESTROY && handler->destroy)
522                 err = handler->destroy(in_skb, req);
523         else
524                 err = -EOPNOTSUPP;
525         inet_diag_unlock_handler(handler);
526
527         return err;
528 }
529
530 static int bitstring_match(const __be32 *a1, const __be32 *a2, int bits)
531 {
532         int words = bits >> 5;
533
534         bits &= 0x1f;
535
536         if (words) {
537                 if (memcmp(a1, a2, words << 2))
538                         return 0;
539         }
540         if (bits) {
541                 __be32 w1, w2;
542                 __be32 mask;
543
544                 w1 = a1[words];
545                 w2 = a2[words];
546
547                 mask = htonl((0xffffffff) << (32 - bits));
548
549                 if ((w1 ^ w2) & mask)
550                         return 0;
551         }
552
553         return 1;
554 }
555
556 static int inet_diag_bc_run(const struct nlattr *_bc,
557                             const struct inet_diag_entry *entry)
558 {
559         const void *bc = nla_data(_bc);
560         int len = nla_len(_bc);
561
562         while (len > 0) {
563                 int yes = 1;
564                 const struct inet_diag_bc_op *op = bc;
565
566                 switch (op->code) {
567                 case INET_DIAG_BC_NOP:
568                         break;
569                 case INET_DIAG_BC_JMP:
570                         yes = 0;
571                         break;
572                 case INET_DIAG_BC_S_EQ:
573                         yes = entry->sport == op[1].no;
574                         break;
575                 case INET_DIAG_BC_S_GE:
576                         yes = entry->sport >= op[1].no;
577                         break;
578                 case INET_DIAG_BC_S_LE:
579                         yes = entry->sport <= op[1].no;
580                         break;
581                 case INET_DIAG_BC_D_EQ:
582                         yes = entry->dport == op[1].no;
583                         break;
584                 case INET_DIAG_BC_D_GE:
585                         yes = entry->dport >= op[1].no;
586                         break;
587                 case INET_DIAG_BC_D_LE:
588                         yes = entry->dport <= op[1].no;
589                         break;
590                 case INET_DIAG_BC_AUTO:
591                         yes = !(entry->userlocks & SOCK_BINDPORT_LOCK);
592                         break;
593                 case INET_DIAG_BC_S_COND:
594                 case INET_DIAG_BC_D_COND: {
595                         const struct inet_diag_hostcond *cond;
596                         const __be32 *addr;
597
598                         cond = (const struct inet_diag_hostcond *)(op + 1);
599                         if (cond->port != -1 &&
600                             cond->port != (op->code == INET_DIAG_BC_S_COND ?
601                                              entry->sport : entry->dport)) {
602                                 yes = 0;
603                                 break;
604                         }
605
606                         if (op->code == INET_DIAG_BC_S_COND)
607                                 addr = entry->saddr;
608                         else
609                                 addr = entry->daddr;
610
611                         if (cond->family != AF_UNSPEC &&
612                             cond->family != entry->family) {
613                                 if (entry->family == AF_INET6 &&
614                                     cond->family == AF_INET) {
615                                         if (addr[0] == 0 && addr[1] == 0 &&
616                                             addr[2] == htonl(0xffff) &&
617                                             bitstring_match(addr + 3,
618                                                             cond->addr,
619                                                             cond->prefix_len))
620                                                 break;
621                                 }
622                                 yes = 0;
623                                 break;
624                         }
625
626                         if (cond->prefix_len == 0)
627                                 break;
628                         if (bitstring_match(addr, cond->addr,
629                                             cond->prefix_len))
630                                 break;
631                         yes = 0;
632                         break;
633                 }
634                 case INET_DIAG_BC_DEV_COND: {
635                         u32 ifindex;
636
637                         ifindex = *((const u32 *)(op + 1));
638                         if (ifindex != entry->ifindex)
639                                 yes = 0;
640                         break;
641                 }
642                 case INET_DIAG_BC_MARK_COND: {
643                         struct inet_diag_markcond *cond;
644
645                         cond = (struct inet_diag_markcond *)(op + 1);
646                         if ((entry->mark & cond->mask) != cond->mark)
647                                 yes = 0;
648                         break;
649                 }
650                 }
651
652                 if (yes) {
653                         len -= op->yes;
654                         bc += op->yes;
655                 } else {
656                         len -= op->no;
657                         bc += op->no;
658                 }
659         }
660         return len == 0;
661 }
662
663 /* This helper is available for all sockets (ESTABLISH, TIMEWAIT, SYN_RECV)
664  */
665 static void entry_fill_addrs(struct inet_diag_entry *entry,
666                              const struct sock *sk)
667 {
668 #if IS_ENABLED(CONFIG_IPV6)
669         if (sk->sk_family == AF_INET6) {
670                 entry->saddr = sk->sk_v6_rcv_saddr.s6_addr32;
671                 entry->daddr = sk->sk_v6_daddr.s6_addr32;
672         } else
673 #endif
674         {
675                 entry->saddr = &sk->sk_rcv_saddr;
676                 entry->daddr = &sk->sk_daddr;
677         }
678 }
679
680 int inet_diag_bc_sk(const struct nlattr *bc, struct sock *sk)
681 {
682         struct inet_sock *inet = inet_sk(sk);
683         struct inet_diag_entry entry;
684
685         if (!bc)
686                 return 1;
687
688         entry.family = sk->sk_family;
689         entry_fill_addrs(&entry, sk);
690         entry.sport = inet->inet_num;
691         entry.dport = ntohs(inet->inet_dport);
692         entry.ifindex = sk->sk_bound_dev_if;
693         entry.userlocks = sk_fullsock(sk) ? sk->sk_userlocks : 0;
694         if (sk_fullsock(sk))
695                 entry.mark = sk->sk_mark;
696         else if (sk->sk_state == TCP_NEW_SYN_RECV)
697                 entry.mark = inet_rsk(inet_reqsk(sk))->ir_mark;
698         else
699                 entry.mark = 0;
700
701         return inet_diag_bc_run(bc, &entry);
702 }
703 EXPORT_SYMBOL_GPL(inet_diag_bc_sk);
704
705 static int valid_cc(const void *bc, int len, int cc)
706 {
707         while (len >= 0) {
708                 const struct inet_diag_bc_op *op = bc;
709
710                 if (cc > len)
711                         return 0;
712                 if (cc == len)
713                         return 1;
714                 if (op->yes < 4 || op->yes & 3)
715                         return 0;
716                 len -= op->yes;
717                 bc  += op->yes;
718         }
719         return 0;
720 }
721
722 /* data is u32 ifindex */
723 static bool valid_devcond(const struct inet_diag_bc_op *op, int len,
724                           int *min_len)
725 {
726         /* Check ifindex space. */
727         *min_len += sizeof(u32);
728         if (len < *min_len)
729                 return false;
730
731         return true;
732 }
733 /* Validate an inet_diag_hostcond. */
734 static bool valid_hostcond(const struct inet_diag_bc_op *op, int len,
735                            int *min_len)
736 {
737         struct inet_diag_hostcond *cond;
738         int addr_len;
739
740         /* Check hostcond space. */
741         *min_len += sizeof(struct inet_diag_hostcond);
742         if (len < *min_len)
743                 return false;
744         cond = (struct inet_diag_hostcond *)(op + 1);
745
746         /* Check address family and address length. */
747         switch (cond->family) {
748         case AF_UNSPEC:
749                 addr_len = 0;
750                 break;
751         case AF_INET:
752                 addr_len = sizeof(struct in_addr);
753                 break;
754         case AF_INET6:
755                 addr_len = sizeof(struct in6_addr);
756                 break;
757         default:
758                 return false;
759         }
760         *min_len += addr_len;
761         if (len < *min_len)
762                 return false;
763
764         /* Check prefix length (in bits) vs address length (in bytes). */
765         if (cond->prefix_len > 8 * addr_len)
766                 return false;
767
768         return true;
769 }
770
771 /* Validate a port comparison operator. */
772 static bool valid_port_comparison(const struct inet_diag_bc_op *op,
773                                   int len, int *min_len)
774 {
775         /* Port comparisons put the port in a follow-on inet_diag_bc_op. */
776         *min_len += sizeof(struct inet_diag_bc_op);
777         if (len < *min_len)
778                 return false;
779         return true;
780 }
781
782 static bool valid_markcond(const struct inet_diag_bc_op *op, int len,
783                            int *min_len)
784 {
785         *min_len += sizeof(struct inet_diag_markcond);
786         return len >= *min_len;
787 }
788
789 static int inet_diag_bc_audit(const struct nlattr *attr,
790                               const struct sk_buff *skb)
791 {
792         bool net_admin = netlink_net_capable(skb, CAP_NET_ADMIN);
793         const void *bytecode, *bc;
794         int bytecode_len, len;
795
796         if (!attr || nla_len(attr) < sizeof(struct inet_diag_bc_op))
797                 return -EINVAL;
798
799         bytecode = bc = nla_data(attr);
800         len = bytecode_len = nla_len(attr);
801
802         while (len > 0) {
803                 int min_len = sizeof(struct inet_diag_bc_op);
804                 const struct inet_diag_bc_op *op = bc;
805
806                 switch (op->code) {
807                 case INET_DIAG_BC_S_COND:
808                 case INET_DIAG_BC_D_COND:
809                         if (!valid_hostcond(bc, len, &min_len))
810                                 return -EINVAL;
811                         break;
812                 case INET_DIAG_BC_DEV_COND:
813                         if (!valid_devcond(bc, len, &min_len))
814                                 return -EINVAL;
815                         break;
816                 case INET_DIAG_BC_S_EQ:
817                 case INET_DIAG_BC_S_GE:
818                 case INET_DIAG_BC_S_LE:
819                 case INET_DIAG_BC_D_EQ:
820                 case INET_DIAG_BC_D_GE:
821                 case INET_DIAG_BC_D_LE:
822                         if (!valid_port_comparison(bc, len, &min_len))
823                                 return -EINVAL;
824                         break;
825                 case INET_DIAG_BC_MARK_COND:
826                         if (!net_admin)
827                                 return -EPERM;
828                         if (!valid_markcond(bc, len, &min_len))
829                                 return -EINVAL;
830                         break;
831                 case INET_DIAG_BC_AUTO:
832                 case INET_DIAG_BC_JMP:
833                 case INET_DIAG_BC_NOP:
834                         break;
835                 default:
836                         return -EINVAL;
837                 }
838
839                 if (op->code != INET_DIAG_BC_NOP) {
840                         if (op->no < min_len || op->no > len + 4 || op->no & 3)
841                                 return -EINVAL;
842                         if (op->no < len &&
843                             !valid_cc(bytecode, bytecode_len, len - op->no))
844                                 return -EINVAL;
845                 }
846
847                 if (op->yes < min_len || op->yes > len + 4 || op->yes & 3)
848                         return -EINVAL;
849                 bc  += op->yes;
850                 len -= op->yes;
851         }
852         return len == 0 ? 0 : -EINVAL;
853 }
854
855 static int inet_csk_diag_dump(struct sock *sk,
856                               struct sk_buff *skb,
857                               struct netlink_callback *cb,
858                               const struct inet_diag_req_v2 *r,
859                               const struct nlattr *bc,
860                               bool net_admin)
861 {
862         if (!inet_diag_bc_sk(bc, sk))
863                 return 0;
864
865         return inet_csk_diag_fill(sk, skb, r,
866                                   sk_user_ns(NETLINK_CB(cb->skb).sk),
867                                   NETLINK_CB(cb->skb).portid,
868                                   cb->nlh->nlmsg_seq, NLM_F_MULTI, cb->nlh,
869                                   net_admin);
870 }
871
872 static void twsk_build_assert(void)
873 {
874         BUILD_BUG_ON(offsetof(struct inet_timewait_sock, tw_family) !=
875                      offsetof(struct sock, sk_family));
876
877         BUILD_BUG_ON(offsetof(struct inet_timewait_sock, tw_num) !=
878                      offsetof(struct inet_sock, inet_num));
879
880         BUILD_BUG_ON(offsetof(struct inet_timewait_sock, tw_dport) !=
881                      offsetof(struct inet_sock, inet_dport));
882
883         BUILD_BUG_ON(offsetof(struct inet_timewait_sock, tw_rcv_saddr) !=
884                      offsetof(struct inet_sock, inet_rcv_saddr));
885
886         BUILD_BUG_ON(offsetof(struct inet_timewait_sock, tw_daddr) !=
887                      offsetof(struct inet_sock, inet_daddr));
888
889 #if IS_ENABLED(CONFIG_IPV6)
890         BUILD_BUG_ON(offsetof(struct inet_timewait_sock, tw_v6_rcv_saddr) !=
891                      offsetof(struct sock, sk_v6_rcv_saddr));
892
893         BUILD_BUG_ON(offsetof(struct inet_timewait_sock, tw_v6_daddr) !=
894                      offsetof(struct sock, sk_v6_daddr));
895 #endif
896 }
897
898 void inet_diag_dump_icsk(struct inet_hashinfo *hashinfo, struct sk_buff *skb,
899                          struct netlink_callback *cb,
900                          const struct inet_diag_req_v2 *r, struct nlattr *bc)
901 {
902         bool net_admin = netlink_net_capable(cb->skb, CAP_NET_ADMIN);
903         struct net *net = sock_net(skb->sk);
904         u32 idiag_states = r->idiag_states;
905         int i, num, s_i, s_num;
906         struct sock *sk;
907
908         if (idiag_states & TCPF_SYN_RECV)
909                 idiag_states |= TCPF_NEW_SYN_RECV;
910         s_i = cb->args[1];
911         s_num = num = cb->args[2];
912
913         if (cb->args[0] == 0) {
914                 if (!(idiag_states & TCPF_LISTEN) || r->id.idiag_dport)
915                         goto skip_listen_ht;
916
917                 for (i = s_i; i < INET_LHTABLE_SIZE; i++) {
918                         struct inet_listen_hashbucket *ilb;
919                         struct hlist_nulls_node *node;
920
921                         num = 0;
922                         ilb = &hashinfo->listening_hash[i];
923                         spin_lock(&ilb->lock);
924                         sk_nulls_for_each(sk, node, &ilb->nulls_head) {
925                                 struct inet_sock *inet = inet_sk(sk);
926
927                                 if (!net_eq(sock_net(sk), net))
928                                         continue;
929
930                                 if (num < s_num) {
931                                         num++;
932                                         continue;
933                                 }
934
935                                 if (r->sdiag_family != AF_UNSPEC &&
936                                     sk->sk_family != r->sdiag_family)
937                                         goto next_listen;
938
939                                 if (r->id.idiag_sport != inet->inet_sport &&
940                                     r->id.idiag_sport)
941                                         goto next_listen;
942
943                                 if (inet_csk_diag_dump(sk, skb, cb, r,
944                                                        bc, net_admin) < 0) {
945                                         spin_unlock(&ilb->lock);
946                                         goto done;
947                                 }
948
949 next_listen:
950                                 ++num;
951                         }
952                         spin_unlock(&ilb->lock);
953
954                         s_num = 0;
955                 }
956 skip_listen_ht:
957                 cb->args[0] = 1;
958                 s_i = num = s_num = 0;
959         }
960
961         if (!(idiag_states & ~TCPF_LISTEN))
962                 goto out;
963
964 #define SKARR_SZ 16
965         for (i = s_i; i <= hashinfo->ehash_mask; i++) {
966                 struct inet_ehash_bucket *head = &hashinfo->ehash[i];
967                 spinlock_t *lock = inet_ehash_lockp(hashinfo, i);
968                 struct hlist_nulls_node *node;
969                 struct sock *sk_arr[SKARR_SZ];
970                 int num_arr[SKARR_SZ];
971                 int idx, accum, res;
972
973                 if (hlist_nulls_empty(&head->chain))
974                         continue;
975
976                 if (i > s_i)
977                         s_num = 0;
978
979 next_chunk:
980                 num = 0;
981                 accum = 0;
982                 spin_lock_bh(lock);
983                 sk_nulls_for_each(sk, node, &head->chain) {
984                         int state;
985
986                         if (!net_eq(sock_net(sk), net))
987                                 continue;
988                         if (num < s_num)
989                                 goto next_normal;
990                         state = (sk->sk_state == TCP_TIME_WAIT) ?
991                                 inet_twsk(sk)->tw_substate : sk->sk_state;
992                         if (!(idiag_states & (1 << state)))
993                                 goto next_normal;
994                         if (r->sdiag_family != AF_UNSPEC &&
995                             sk->sk_family != r->sdiag_family)
996                                 goto next_normal;
997                         if (r->id.idiag_sport != htons(sk->sk_num) &&
998                             r->id.idiag_sport)
999                                 goto next_normal;
1000                         if (r->id.idiag_dport != sk->sk_dport &&
1001                             r->id.idiag_dport)
1002                                 goto next_normal;
1003                         twsk_build_assert();
1004
1005                         if (!inet_diag_bc_sk(bc, sk))
1006                                 goto next_normal;
1007
1008                         if (!refcount_inc_not_zero(&sk->sk_refcnt))
1009                                 goto next_normal;
1010
1011                         num_arr[accum] = num;
1012                         sk_arr[accum] = sk;
1013                         if (++accum == SKARR_SZ)
1014                                 break;
1015 next_normal:
1016                         ++num;
1017                 }
1018                 spin_unlock_bh(lock);
1019                 res = 0;
1020                 for (idx = 0; idx < accum; idx++) {
1021                         if (res >= 0) {
1022                                 res = sk_diag_fill(sk_arr[idx], skb, r,
1023                                            sk_user_ns(NETLINK_CB(cb->skb).sk),
1024                                            NETLINK_CB(cb->skb).portid,
1025                                            cb->nlh->nlmsg_seq, NLM_F_MULTI,
1026                                            cb->nlh, net_admin);
1027                                 if (res < 0)
1028                                         num = num_arr[idx];
1029                         }
1030                         sock_gen_put(sk_arr[idx]);
1031                 }
1032                 if (res < 0)
1033                         break;
1034                 cond_resched();
1035                 if (accum == SKARR_SZ) {
1036                         s_num = num + 1;
1037                         goto next_chunk;
1038                 }
1039         }
1040
1041 done:
1042         cb->args[1] = i;
1043         cb->args[2] = num;
1044 out:
1045         ;
1046 }
1047 EXPORT_SYMBOL_GPL(inet_diag_dump_icsk);
1048
1049 static int __inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
1050                             const struct inet_diag_req_v2 *r,
1051                             struct nlattr *bc)
1052 {
1053         const struct inet_diag_handler *handler;
1054         int err = 0;
1055
1056         handler = inet_diag_lock_handler(r->sdiag_protocol);
1057         if (!IS_ERR(handler))
1058                 handler->dump(skb, cb, r, bc);
1059         else
1060                 err = PTR_ERR(handler);
1061         inet_diag_unlock_handler(handler);
1062
1063         return err ? : skb->len;
1064 }
1065
1066 static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
1067 {
1068         int hdrlen = sizeof(struct inet_diag_req_v2);
1069         struct nlattr *bc = NULL;
1070
1071         if (nlmsg_attrlen(cb->nlh, hdrlen))
1072                 bc = nlmsg_find_attr(cb->nlh, hdrlen, INET_DIAG_REQ_BYTECODE);
1073
1074         return __inet_diag_dump(skb, cb, nlmsg_data(cb->nlh), bc);
1075 }
1076
1077 static int inet_diag_type2proto(int type)
1078 {
1079         switch (type) {
1080         case TCPDIAG_GETSOCK:
1081                 return IPPROTO_TCP;
1082         case DCCPDIAG_GETSOCK:
1083                 return IPPROTO_DCCP;
1084         default:
1085                 return 0;
1086         }
1087 }
1088
1089 static int inet_diag_dump_compat(struct sk_buff *skb,
1090                                  struct netlink_callback *cb)
1091 {
1092         struct inet_diag_req *rc = nlmsg_data(cb->nlh);
1093         int hdrlen = sizeof(struct inet_diag_req);
1094         struct inet_diag_req_v2 req;
1095         struct nlattr *bc = NULL;
1096
1097         req.sdiag_family = AF_UNSPEC; /* compatibility */
1098         req.sdiag_protocol = inet_diag_type2proto(cb->nlh->nlmsg_type);
1099         req.idiag_ext = rc->idiag_ext;
1100         req.idiag_states = rc->idiag_states;
1101         req.id = rc->id;
1102
1103         if (nlmsg_attrlen(cb->nlh, hdrlen))
1104                 bc = nlmsg_find_attr(cb->nlh, hdrlen, INET_DIAG_REQ_BYTECODE);
1105
1106         return __inet_diag_dump(skb, cb, &req, bc);
1107 }
1108
1109 static int inet_diag_get_exact_compat(struct sk_buff *in_skb,
1110                                       const struct nlmsghdr *nlh)
1111 {
1112         struct inet_diag_req *rc = nlmsg_data(nlh);
1113         struct inet_diag_req_v2 req;
1114
1115         req.sdiag_family = rc->idiag_family;
1116         req.sdiag_protocol = inet_diag_type2proto(nlh->nlmsg_type);
1117         req.idiag_ext = rc->idiag_ext;
1118         req.idiag_states = rc->idiag_states;
1119         req.id = rc->id;
1120
1121         return inet_diag_cmd_exact(SOCK_DIAG_BY_FAMILY, in_skb, nlh, &req);
1122 }
1123
1124 static int inet_diag_rcv_msg_compat(struct sk_buff *skb, struct nlmsghdr *nlh)
1125 {
1126         int hdrlen = sizeof(struct inet_diag_req);
1127         struct net *net = sock_net(skb->sk);
1128
1129         if (nlh->nlmsg_type >= INET_DIAG_GETSOCK_MAX ||
1130             nlmsg_len(nlh) < hdrlen)
1131                 return -EINVAL;
1132
1133         if (nlh->nlmsg_flags & NLM_F_DUMP) {
1134                 if (nlmsg_attrlen(nlh, hdrlen)) {
1135                         struct nlattr *attr;
1136                         int err;
1137
1138                         attr = nlmsg_find_attr(nlh, hdrlen,
1139                                                INET_DIAG_REQ_BYTECODE);
1140                         err = inet_diag_bc_audit(attr, skb);
1141                         if (err)
1142                                 return err;
1143                 }
1144                 {
1145                         struct netlink_dump_control c = {
1146                                 .dump = inet_diag_dump_compat,
1147                         };
1148                         return netlink_dump_start(net->diag_nlsk, skb, nlh, &c);
1149                 }
1150         }
1151
1152         return inet_diag_get_exact_compat(skb, nlh);
1153 }
1154
1155 static int inet_diag_handler_cmd(struct sk_buff *skb, struct nlmsghdr *h)
1156 {
1157         int hdrlen = sizeof(struct inet_diag_req_v2);
1158         struct net *net = sock_net(skb->sk);
1159
1160         if (nlmsg_len(h) < hdrlen)
1161                 return -EINVAL;
1162
1163         if (h->nlmsg_type == SOCK_DIAG_BY_FAMILY &&
1164             h->nlmsg_flags & NLM_F_DUMP) {
1165                 if (nlmsg_attrlen(h, hdrlen)) {
1166                         struct nlattr *attr;
1167                         int err;
1168
1169                         attr = nlmsg_find_attr(h, hdrlen,
1170                                                INET_DIAG_REQ_BYTECODE);
1171                         err = inet_diag_bc_audit(attr, skb);
1172                         if (err)
1173                                 return err;
1174                 }
1175                 {
1176                         struct netlink_dump_control c = {
1177                                 .dump = inet_diag_dump,
1178                         };
1179                         return netlink_dump_start(net->diag_nlsk, skb, h, &c);
1180                 }
1181         }
1182
1183         return inet_diag_cmd_exact(h->nlmsg_type, skb, h, nlmsg_data(h));
1184 }
1185
1186 static
1187 int inet_diag_handler_get_info(struct sk_buff *skb, struct sock *sk)
1188 {
1189         const struct inet_diag_handler *handler;
1190         struct nlmsghdr *nlh;
1191         struct nlattr *attr;
1192         struct inet_diag_msg *r;
1193         void *info = NULL;
1194         int err = 0;
1195
1196         nlh = nlmsg_put(skb, 0, 0, SOCK_DIAG_BY_FAMILY, sizeof(*r), 0);
1197         if (!nlh)
1198                 return -ENOMEM;
1199
1200         r = nlmsg_data(nlh);
1201         memset(r, 0, sizeof(*r));
1202         inet_diag_msg_common_fill(r, sk);
1203         if (sk->sk_type == SOCK_DGRAM || sk->sk_type == SOCK_STREAM)
1204                 r->id.idiag_sport = inet_sk(sk)->inet_sport;
1205         r->idiag_state = sk->sk_state;
1206
1207         if ((err = nla_put_u8(skb, INET_DIAG_PROTOCOL, sk->sk_protocol))) {
1208                 nlmsg_cancel(skb, nlh);
1209                 return err;
1210         }
1211
1212         handler = inet_diag_lock_handler(sk->sk_protocol);
1213         if (IS_ERR(handler)) {
1214                 inet_diag_unlock_handler(handler);
1215                 nlmsg_cancel(skb, nlh);
1216                 return PTR_ERR(handler);
1217         }
1218
1219         attr = handler->idiag_info_size
1220                 ? nla_reserve_64bit(skb, INET_DIAG_INFO,
1221                                     handler->idiag_info_size,
1222                                     INET_DIAG_PAD)
1223                 : NULL;
1224         if (attr)
1225                 info = nla_data(attr);
1226
1227         handler->idiag_get_info(sk, r, info);
1228         inet_diag_unlock_handler(handler);
1229
1230         nlmsg_end(skb, nlh);
1231         return 0;
1232 }
1233
1234 static const struct sock_diag_handler inet_diag_handler = {
1235         .family = AF_INET,
1236         .dump = inet_diag_handler_cmd,
1237         .get_info = inet_diag_handler_get_info,
1238         .destroy = inet_diag_handler_cmd,
1239 };
1240
1241 static const struct sock_diag_handler inet6_diag_handler = {
1242         .family = AF_INET6,
1243         .dump = inet_diag_handler_cmd,
1244         .get_info = inet_diag_handler_get_info,
1245         .destroy = inet_diag_handler_cmd,
1246 };
1247
1248 int inet_diag_register(const struct inet_diag_handler *h)
1249 {
1250         const __u16 type = h->idiag_type;
1251         int err = -EINVAL;
1252
1253         if (type >= IPPROTO_MAX)
1254                 goto out;
1255
1256         mutex_lock(&inet_diag_table_mutex);
1257         err = -EEXIST;
1258         if (!inet_diag_table[type]) {
1259                 inet_diag_table[type] = h;
1260                 err = 0;
1261         }
1262         mutex_unlock(&inet_diag_table_mutex);
1263 out:
1264         return err;
1265 }
1266 EXPORT_SYMBOL_GPL(inet_diag_register);
1267
1268 void inet_diag_unregister(const struct inet_diag_handler *h)
1269 {
1270         const __u16 type = h->idiag_type;
1271
1272         if (type >= IPPROTO_MAX)
1273                 return;
1274
1275         mutex_lock(&inet_diag_table_mutex);
1276         inet_diag_table[type] = NULL;
1277         mutex_unlock(&inet_diag_table_mutex);
1278 }
1279 EXPORT_SYMBOL_GPL(inet_diag_unregister);
1280
1281 static int __init inet_diag_init(void)
1282 {
1283         const int inet_diag_table_size = (IPPROTO_MAX *
1284                                           sizeof(struct inet_diag_handler *));
1285         int err = -ENOMEM;
1286
1287         inet_diag_table = kzalloc(inet_diag_table_size, GFP_KERNEL);
1288         if (!inet_diag_table)
1289                 goto out;
1290
1291         err = sock_diag_register(&inet_diag_handler);
1292         if (err)
1293                 goto out_free_nl;
1294
1295         err = sock_diag_register(&inet6_diag_handler);
1296         if (err)
1297                 goto out_free_inet;
1298
1299         sock_diag_register_inet_compat(inet_diag_rcv_msg_compat);
1300 out:
1301         return err;
1302
1303 out_free_inet:
1304         sock_diag_unregister(&inet_diag_handler);
1305 out_free_nl:
1306         kfree(inet_diag_table);
1307         goto out;
1308 }
1309
1310 static void __exit inet_diag_exit(void)
1311 {
1312         sock_diag_unregister(&inet6_diag_handler);
1313         sock_diag_unregister(&inet_diag_handler);
1314         sock_diag_unregister_inet_compat(inet_diag_rcv_msg_compat);
1315         kfree(inet_diag_table);
1316 }
1317
1318 module_init(inet_diag_init);
1319 module_exit(inet_diag_exit);
1320 MODULE_LICENSE("GPL");
1321 MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_NETLINK, NETLINK_SOCK_DIAG, 2 /* AF_INET */);
1322 MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_NETLINK, NETLINK_SOCK_DIAG, 10 /* AF_INET6 */);