inet_diag.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  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. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/types.h>
  14. #include <linux/fcntl.h>
  15. #include <linux/random.h>
  16. #include <linux/slab.h>
  17. #include <linux/cache.h>
  18. #include <linux/init.h>
  19. #include <linux/time.h>
  20. #include <net/icmp.h>
  21. #include <net/tcp.h>
  22. #include <net/ipv6.h>
  23. #include <net/inet_common.h>
  24. #include <net/inet_connection_sock.h>
  25. #include <net/inet_hashtables.h>
  26. #include <net/inet_timewait_sock.h>
  27. #include <net/inet6_hashtables.h>
  28. #include <net/netlink.h>
  29. #include <linux/inet.h>
  30. #include <linux/stddef.h>
  31. #include <linux/inet_diag.h>
  32. #include <linux/sock_diag.h>
  33. static const struct inet_diag_handler **inet_diag_table;
  34. struct inet_diag_entry {
  35. __be32 *saddr;
  36. __be32 *daddr;
  37. u16 sport;
  38. u16 dport;
  39. u16 family;
  40. u16 userlocks;
  41. #if IS_ENABLED(CONFIG_IPV6)
  42. struct in6_addr saddr_storage; /* for IPv4-mapped-IPv6 addresses */
  43. struct in6_addr daddr_storage; /* for IPv4-mapped-IPv6 addresses */
  44. #endif
  45. };
  46. #define INET_DIAG_PUT(skb, attrtype, attrlen) \
  47. RTA_DATA(__RTA_PUT(skb, attrtype, attrlen))
  48. static DEFINE_MUTEX(inet_diag_table_mutex);
  49. static const struct inet_diag_handler *inet_diag_lock_handler(int proto)
  50. {
  51. if (!inet_diag_table[proto])
  52. request_module("net-pf-%d-proto-%d-type-%d-%d", PF_NETLINK,
  53. NETLINK_SOCK_DIAG, AF_INET, proto);
  54. mutex_lock(&inet_diag_table_mutex);
  55. if (!inet_diag_table[proto])
  56. return ERR_PTR(-ENOENT);
  57. return inet_diag_table[proto];
  58. }
  59. static inline void inet_diag_unlock_handler(
  60. const struct inet_diag_handler *handler)
  61. {
  62. mutex_unlock(&inet_diag_table_mutex);
  63. }
  64. int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
  65. struct sk_buff *skb, struct inet_diag_req_v2 *req,
  66. u32 pid, u32 seq, u16 nlmsg_flags,
  67. const struct nlmsghdr *unlh)
  68. {
  69. const struct inet_sock *inet = inet_sk(sk);
  70. struct inet_diag_msg *r;
  71. struct nlmsghdr *nlh;
  72. void *info = NULL;
  73. struct inet_diag_meminfo *minfo = NULL;
  74. unsigned char *b = skb_tail_pointer(skb);
  75. const struct inet_diag_handler *handler;
  76. int ext = req->idiag_ext;
  77. handler = inet_diag_table[req->sdiag_protocol];
  78. BUG_ON(handler == NULL);
  79. nlh = NLMSG_PUT(skb, pid, seq, unlh->nlmsg_type, sizeof(*r));
  80. nlh->nlmsg_flags = nlmsg_flags;
  81. r = NLMSG_DATA(nlh);
  82. BUG_ON(sk->sk_state == TCP_TIME_WAIT);
  83. if (ext & (1 << (INET_DIAG_MEMINFO - 1)))
  84. minfo = INET_DIAG_PUT(skb, INET_DIAG_MEMINFO, sizeof(*minfo));
  85. r->idiag_family = sk->sk_family;
  86. r->idiag_state = sk->sk_state;
  87. r->idiag_timer = 0;
  88. r->idiag_retrans = 0;
  89. r->id.idiag_if = sk->sk_bound_dev_if;
  90. sock_diag_save_cookie(sk, r->id.idiag_cookie);
  91. r->id.idiag_sport = inet->inet_sport;
  92. r->id.idiag_dport = inet->inet_dport;
  93. memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
  94. memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
  95. r->id.idiag_src[0] = inet->inet_rcv_saddr;
  96. r->id.idiag_dst[0] = inet->inet_daddr;
  97. /* IPv6 dual-stack sockets use inet->tos for IPv4 connections,
  98. * hence this needs to be included regardless of socket family.
  99. */
  100. if (ext & (1 << (INET_DIAG_TOS - 1)))
  101. RTA_PUT_U8(skb, INET_DIAG_TOS, inet->tos);
  102. #if IS_ENABLED(CONFIG_IPV6)
  103. if (r->idiag_family == AF_INET6) {
  104. const struct ipv6_pinfo *np = inet6_sk(sk);
  105. *(struct in6_addr *)r->id.idiag_src = np->rcv_saddr;
  106. *(struct in6_addr *)r->id.idiag_dst = np->daddr;
  107. if (ext & (1 << (INET_DIAG_TCLASS - 1)))
  108. RTA_PUT_U8(skb, INET_DIAG_TCLASS, np->tclass);
  109. }
  110. #endif
  111. r->idiag_uid = sock_i_uid(sk);
  112. r->idiag_inode = sock_i_ino(sk);
  113. if (minfo) {
  114. minfo->idiag_rmem = sk_rmem_alloc_get(sk);
  115. minfo->idiag_wmem = sk->sk_wmem_queued;
  116. minfo->idiag_fmem = sk->sk_forward_alloc;
  117. minfo->idiag_tmem = sk_wmem_alloc_get(sk);
  118. }
  119. if (ext & (1 << (INET_DIAG_SKMEMINFO - 1)))
  120. if (sock_diag_put_meminfo(sk, skb, INET_DIAG_SKMEMINFO))
  121. goto rtattr_failure;
  122. if (icsk == NULL) {
  123. handler->idiag_get_info(sk, r, NULL);
  124. goto out;
  125. }
  126. #define EXPIRES_IN_MS(tmo) DIV_ROUND_UP((tmo - jiffies) * 1000, HZ)
  127. if (icsk->icsk_pending == ICSK_TIME_RETRANS) {
  128. r->idiag_timer = 1;
  129. r->idiag_retrans = icsk->icsk_retransmits;
  130. r->idiag_expires = EXPIRES_IN_MS(icsk->icsk_timeout);
  131. } else if (icsk->icsk_pending == ICSK_TIME_PROBE0) {
  132. r->idiag_timer = 4;
  133. r->idiag_retrans = icsk->icsk_probes_out;
  134. r->idiag_expires = EXPIRES_IN_MS(icsk->icsk_timeout);
  135. } else if (timer_pending(&sk->sk_timer)) {
  136. r->idiag_timer = 2;
  137. r->idiag_retrans = icsk->icsk_probes_out;
  138. r->idiag_expires = EXPIRES_IN_MS(sk->sk_timer.expires);
  139. } else {
  140. r->idiag_timer = 0;
  141. r->idiag_expires = 0;
  142. }
  143. #undef EXPIRES_IN_MS
  144. if (ext & (1 << (INET_DIAG_INFO - 1)))
  145. info = INET_DIAG_PUT(skb, INET_DIAG_INFO, sizeof(struct tcp_info));
  146. if ((ext & (1 << (INET_DIAG_CONG - 1))) && icsk->icsk_ca_ops) {
  147. const size_t len = strlen(icsk->icsk_ca_ops->name);
  148. strcpy(INET_DIAG_PUT(skb, INET_DIAG_CONG, len + 1),
  149. icsk->icsk_ca_ops->name);
  150. }
  151. handler->idiag_get_info(sk, r, info);
  152. if (sk->sk_state < TCP_TIME_WAIT &&
  153. icsk->icsk_ca_ops && icsk->icsk_ca_ops->get_info)
  154. icsk->icsk_ca_ops->get_info(sk, ext, skb);
  155. out:
  156. nlh->nlmsg_len = skb_tail_pointer(skb) - b;
  157. return skb->len;
  158. rtattr_failure:
  159. nlmsg_failure:
  160. nlmsg_trim(skb, b);
  161. return -EMSGSIZE;
  162. }
  163. EXPORT_SYMBOL_GPL(inet_sk_diag_fill);
  164. static int inet_csk_diag_fill(struct sock *sk,
  165. struct sk_buff *skb, struct inet_diag_req_v2 *req,
  166. u32 pid, u32 seq, u16 nlmsg_flags,
  167. const struct nlmsghdr *unlh)
  168. {
  169. return inet_sk_diag_fill(sk, inet_csk(sk),
  170. skb, req, pid, seq, nlmsg_flags, unlh);
  171. }
  172. static int inet_twsk_diag_fill(struct inet_timewait_sock *tw,
  173. struct sk_buff *skb, struct inet_diag_req_v2 *req,
  174. u32 pid, u32 seq, u16 nlmsg_flags,
  175. const struct nlmsghdr *unlh)
  176. {
  177. long tmo;
  178. struct inet_diag_msg *r;
  179. const unsigned char *previous_tail = skb_tail_pointer(skb);
  180. struct nlmsghdr *nlh = NLMSG_PUT(skb, pid, seq,
  181. unlh->nlmsg_type, sizeof(*r));
  182. r = NLMSG_DATA(nlh);
  183. BUG_ON(tw->tw_state != TCP_TIME_WAIT);
  184. nlh->nlmsg_flags = nlmsg_flags;
  185. tmo = tw->tw_ttd - jiffies;
  186. if (tmo < 0)
  187. tmo = 0;
  188. r->idiag_family = tw->tw_family;
  189. r->idiag_retrans = 0;
  190. r->id.idiag_if = tw->tw_bound_dev_if;
  191. sock_diag_save_cookie(tw, r->id.idiag_cookie);
  192. r->id.idiag_sport = tw->tw_sport;
  193. r->id.idiag_dport = tw->tw_dport;
  194. memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
  195. memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
  196. r->id.idiag_src[0] = tw->tw_rcv_saddr;
  197. r->id.idiag_dst[0] = tw->tw_daddr;
  198. r->idiag_state = tw->tw_substate;
  199. r->idiag_timer = 3;
  200. r->idiag_expires = DIV_ROUND_UP(tmo * 1000, HZ);
  201. r->idiag_rqueue = 0;
  202. r->idiag_wqueue = 0;
  203. r->idiag_uid = 0;
  204. r->idiag_inode = 0;
  205. #if IS_ENABLED(CONFIG_IPV6)
  206. if (tw->tw_family == AF_INET6) {
  207. const struct inet6_timewait_sock *tw6 =
  208. inet6_twsk((struct sock *)tw);
  209. *(struct in6_addr *)r->id.idiag_src = tw6->tw_v6_rcv_saddr;
  210. *(struct in6_addr *)r->id.idiag_dst = tw6->tw_v6_daddr;
  211. }
  212. #endif
  213. nlh->nlmsg_len = skb_tail_pointer(skb) - previous_tail;
  214. return skb->len;
  215. nlmsg_failure:
  216. nlmsg_trim(skb, previous_tail);
  217. return -EMSGSIZE;
  218. }
  219. static int sk_diag_fill(struct sock *sk, struct sk_buff *skb,
  220. struct inet_diag_req_v2 *r, u32 pid, u32 seq, u16 nlmsg_flags,
  221. const struct nlmsghdr *unlh)
  222. {
  223. if (sk->sk_state == TCP_TIME_WAIT)
  224. return inet_twsk_diag_fill((struct inet_timewait_sock *)sk,
  225. skb, r, pid, seq, nlmsg_flags,
  226. unlh);
  227. return inet_csk_diag_fill(sk, skb, r, pid, seq, nlmsg_flags, unlh);
  228. }
  229. struct sock *inet_diag_find_one_icsk(struct net *net,
  230. struct inet_hashinfo *hashinfo,
  231. struct inet_diag_req_v2 *req)
  232. {
  233. struct sock *sk;
  234. if (req->sdiag_family == AF_INET) {
  235. sk = inet_lookup(net, hashinfo, req->id.idiag_dst[0],
  236. req->id.idiag_dport, req->id.idiag_src[0],
  237. req->id.idiag_sport, req->id.idiag_if);
  238. }
  239. #if IS_ENABLED(CONFIG_IPV6)
  240. else if (req->sdiag_family == AF_INET6) {
  241. if (ipv6_addr_v4mapped((struct in6_addr *)req->id.idiag_dst) &&
  242. ipv6_addr_v4mapped((struct in6_addr *)req->id.idiag_src))
  243. sk = inet_lookup(net, hashinfo, req->id.idiag_dst[3],
  244. req->id.idiag_dport, req->id.idiag_src[3],
  245. req->id.idiag_sport, req->id.idiag_if);
  246. else
  247. sk = inet6_lookup(net, hashinfo,
  248. (struct in6_addr *)req->id.idiag_dst,
  249. req->id.idiag_dport,
  250. (struct in6_addr *)req->id.idiag_src,
  251. req->id.idiag_sport,
  252. req->id.idiag_if);
  253. }
  254. #endif
  255. else {
  256. return ERR_PTR(-EINVAL);
  257. }
  258. if (!sk)
  259. return ERR_PTR(-ENOENT);
  260. if (sock_diag_check_cookie(sk, req->id.idiag_cookie)) {
  261. if (sk->sk_state == TCP_TIME_WAIT)
  262. inet_twsk_put((struct inet_timewait_sock *)sk);
  263. else
  264. sock_put(sk);
  265. return ERR_PTR(-ENOENT);
  266. }
  267. return sk;
  268. }
  269. EXPORT_SYMBOL_GPL(inet_diag_find_one_icsk);
  270. int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo,
  271. struct sk_buff *in_skb,
  272. const struct nlmsghdr *nlh,
  273. struct inet_diag_req_v2 *req)
  274. {
  275. struct net *net = sock_net(in_skb->sk);
  276. struct sk_buff *rep;
  277. struct sock *sk;
  278. int err;
  279. sk = inet_diag_find_one_icsk(net, hashinfo, req);
  280. if (IS_ERR(sk))
  281. return PTR_ERR(sk);
  282. err = -ENOMEM;
  283. rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
  284. sizeof(struct inet_diag_meminfo) +
  285. sizeof(struct tcp_info) + 64)),
  286. GFP_KERNEL);
  287. if (!rep)
  288. goto out;
  289. err = sk_diag_fill(sk, rep, req,
  290. NETLINK_CB(in_skb).pid,
  291. nlh->nlmsg_seq, 0, nlh);
  292. if (err < 0) {
  293. WARN_ON(err == -EMSGSIZE);
  294. kfree_skb(rep);
  295. goto out;
  296. }
  297. err = netlink_unicast(sock_diag_nlsk, rep, NETLINK_CB(in_skb).pid,
  298. MSG_DONTWAIT);
  299. if (err > 0)
  300. err = 0;
  301. out:
  302. if (sk) {
  303. if (sk->sk_state == TCP_TIME_WAIT)
  304. inet_twsk_put((struct inet_timewait_sock *)sk);
  305. else
  306. sock_put(sk);
  307. }
  308. return err;
  309. }
  310. EXPORT_SYMBOL_GPL(inet_diag_dump_one_icsk);
  311. static int inet_diag_cmd_exact(int cmd, struct sk_buff *in_skb,
  312. const struct nlmsghdr *nlh,
  313. struct inet_diag_req_v2 *req)
  314. {
  315. const struct inet_diag_handler *handler;
  316. int err;
  317. handler = inet_diag_lock_handler(req->sdiag_protocol);
  318. if (IS_ERR(handler))
  319. err = PTR_ERR(handler);
  320. else if (cmd == SOCK_DIAG_BY_FAMILY)
  321. err = handler->dump_one(in_skb, nlh, req);
  322. else if (cmd == SOCK_DESTROY_BACKPORT && handler->destroy)
  323. err = handler->destroy(in_skb, req);
  324. else
  325. err = -EOPNOTSUPP;
  326. inet_diag_unlock_handler(handler);
  327. return err;
  328. }
  329. static int bitstring_match(const __be32 *a1, const __be32 *a2, int bits)
  330. {
  331. int words = bits >> 5;
  332. bits &= 0x1f;
  333. if (words) {
  334. if (memcmp(a1, a2, words << 2))
  335. return 0;
  336. }
  337. if (bits) {
  338. __be32 w1, w2;
  339. __be32 mask;
  340. w1 = a1[words];
  341. w2 = a2[words];
  342. mask = htonl((0xffffffff) << (32 - bits));
  343. if ((w1 ^ w2) & mask)
  344. return 0;
  345. }
  346. return 1;
  347. }
  348. static int inet_diag_bc_run(const struct nlattr *_bc,
  349. const struct inet_diag_entry *entry)
  350. {
  351. const void *bc = nla_data(_bc);
  352. int len = nla_len(_bc);
  353. while (len > 0) {
  354. int yes = 1;
  355. const struct inet_diag_bc_op *op = bc;
  356. switch (op->code) {
  357. case INET_DIAG_BC_NOP:
  358. break;
  359. case INET_DIAG_BC_JMP:
  360. yes = 0;
  361. break;
  362. case INET_DIAG_BC_S_GE:
  363. yes = entry->sport >= op[1].no;
  364. break;
  365. case INET_DIAG_BC_S_LE:
  366. yes = entry->sport <= op[1].no;
  367. break;
  368. case INET_DIAG_BC_D_GE:
  369. yes = entry->dport >= op[1].no;
  370. break;
  371. case INET_DIAG_BC_D_LE:
  372. yes = entry->dport <= op[1].no;
  373. break;
  374. case INET_DIAG_BC_AUTO:
  375. yes = !(entry->userlocks & SOCK_BINDPORT_LOCK);
  376. break;
  377. case INET_DIAG_BC_S_COND:
  378. case INET_DIAG_BC_D_COND: {
  379. struct inet_diag_hostcond *cond;
  380. __be32 *addr;
  381. cond = (struct inet_diag_hostcond *)(op + 1);
  382. if (cond->port != -1 &&
  383. cond->port != (op->code == INET_DIAG_BC_S_COND ?
  384. entry->sport : entry->dport)) {
  385. yes = 0;
  386. break;
  387. }
  388. if (op->code == INET_DIAG_BC_S_COND)
  389. addr = entry->saddr;
  390. else
  391. addr = entry->daddr;
  392. if (cond->family != AF_UNSPEC &&
  393. cond->family != entry->family) {
  394. if (entry->family == AF_INET6 &&
  395. cond->family == AF_INET) {
  396. if (addr[0] == 0 && addr[1] == 0 &&
  397. addr[2] == htonl(0xffff) &&
  398. bitstring_match(addr + 3,
  399. cond->addr,
  400. cond->prefix_len))
  401. break;
  402. }
  403. yes = 0;
  404. break;
  405. }
  406. if (cond->prefix_len == 0)
  407. break;
  408. if (bitstring_match(addr, cond->addr,
  409. cond->prefix_len))
  410. break;
  411. yes = 0;
  412. break;
  413. }
  414. }
  415. if (yes) {
  416. len -= op->yes;
  417. bc += op->yes;
  418. } else {
  419. len -= op->no;
  420. bc += op->no;
  421. }
  422. }
  423. return len == 0;
  424. }
  425. int inet_diag_bc_sk(const struct nlattr *bc, struct sock *sk)
  426. {
  427. struct inet_diag_entry entry;
  428. struct inet_sock *inet = inet_sk(sk);
  429. if (bc == NULL)
  430. return 1;
  431. entry.family = sk->sk_family;
  432. #if IS_ENABLED(CONFIG_IPV6)
  433. if (entry.family == AF_INET6) {
  434. struct ipv6_pinfo *np = inet6_sk(sk);
  435. entry.saddr = np->rcv_saddr.s6_addr32;
  436. entry.daddr = np->daddr.s6_addr32;
  437. } else
  438. #endif
  439. {
  440. entry.saddr = &inet->inet_rcv_saddr;
  441. entry.daddr = &inet->inet_daddr;
  442. }
  443. entry.sport = inet->inet_num;
  444. entry.dport = ntohs(inet->inet_dport);
  445. entry.userlocks = sk->sk_userlocks;
  446. return inet_diag_bc_run(bc, &entry);
  447. }
  448. EXPORT_SYMBOL_GPL(inet_diag_bc_sk);
  449. static int valid_cc(const void *bc, int len, int cc)
  450. {
  451. while (len >= 0) {
  452. const struct inet_diag_bc_op *op = bc;
  453. if (cc > len)
  454. return 0;
  455. if (cc == len)
  456. return 1;
  457. if (op->yes < 4 || op->yes & 3)
  458. return 0;
  459. len -= op->yes;
  460. bc += op->yes;
  461. }
  462. return 0;
  463. }
  464. /* Validate an inet_diag_hostcond. */
  465. static bool valid_hostcond(const struct inet_diag_bc_op *op, int len,
  466. int *min_len)
  467. {
  468. int addr_len;
  469. struct inet_diag_hostcond *cond;
  470. /* Check hostcond space. */
  471. *min_len += sizeof(struct inet_diag_hostcond);
  472. if (len < *min_len)
  473. return false;
  474. cond = (struct inet_diag_hostcond *)(op + 1);
  475. /* Check address family and address length. */
  476. switch (cond->family) {
  477. case AF_UNSPEC:
  478. addr_len = 0;
  479. break;
  480. case AF_INET:
  481. addr_len = sizeof(struct in_addr);
  482. break;
  483. case AF_INET6:
  484. addr_len = sizeof(struct in6_addr);
  485. break;
  486. default:
  487. return false;
  488. }
  489. *min_len += addr_len;
  490. if (len < *min_len)
  491. return false;
  492. /* Check prefix length (in bits) vs address length (in bytes). */
  493. if (cond->prefix_len > 8 * addr_len)
  494. return false;
  495. return true;
  496. }
  497. /* Validate a port comparison operator. */
  498. static inline bool valid_port_comparison(const struct inet_diag_bc_op *op,
  499. int len, int *min_len)
  500. {
  501. /* Port comparisons put the port in a follow-on inet_diag_bc_op. */
  502. *min_len += sizeof(struct inet_diag_bc_op);
  503. if (len < *min_len)
  504. return false;
  505. return true;
  506. }
  507. static int inet_diag_bc_audit(const void *bytecode, int bytecode_len)
  508. {
  509. const void *bc = bytecode;
  510. int len = bytecode_len;
  511. while (len > 0) {
  512. const struct inet_diag_bc_op *op = bc;
  513. int min_len = sizeof(struct inet_diag_bc_op);
  514. //printk("BC: %d %d %d {%d} / %d\n", op->code, op->yes, op->no, op[1].no, len);
  515. switch (op->code) {
  516. case INET_DIAG_BC_S_COND:
  517. case INET_DIAG_BC_D_COND:
  518. if (!valid_hostcond(bc, len, &min_len))
  519. return -EINVAL;
  520. break;
  521. case INET_DIAG_BC_S_GE:
  522. case INET_DIAG_BC_S_LE:
  523. case INET_DIAG_BC_D_GE:
  524. case INET_DIAG_BC_D_LE:
  525. if (!valid_port_comparison(bc, len, &min_len))
  526. return -EINVAL;
  527. break;
  528. case INET_DIAG_BC_AUTO:
  529. case INET_DIAG_BC_JMP:
  530. case INET_DIAG_BC_NOP:
  531. break;
  532. default:
  533. return -EINVAL;
  534. }
  535. if (op->code != INET_DIAG_BC_NOP) {
  536. if (op->no < min_len || op->no > len + 4 || op->no & 3)
  537. return -EINVAL;
  538. if (op->no < len &&
  539. !valid_cc(bytecode, bytecode_len, len - op->no))
  540. return -EINVAL;
  541. }
  542. if (op->yes < min_len || op->yes > len + 4 || op->yes & 3)
  543. return -EINVAL;
  544. bc += op->yes;
  545. len -= op->yes;
  546. }
  547. return len == 0 ? 0 : -EINVAL;
  548. }
  549. static int inet_csk_diag_dump(struct sock *sk,
  550. struct sk_buff *skb,
  551. struct netlink_callback *cb,
  552. struct inet_diag_req_v2 *r,
  553. const struct nlattr *bc)
  554. {
  555. if (!inet_diag_bc_sk(bc, sk))
  556. return 0;
  557. return inet_csk_diag_fill(sk, skb, r,
  558. NETLINK_CB(cb->skb).pid,
  559. cb->nlh->nlmsg_seq, NLM_F_MULTI, cb->nlh);
  560. }
  561. static int inet_twsk_diag_dump(struct inet_timewait_sock *tw,
  562. struct sk_buff *skb,
  563. struct netlink_callback *cb,
  564. struct inet_diag_req_v2 *r,
  565. const struct nlattr *bc)
  566. {
  567. if (bc != NULL) {
  568. struct inet_diag_entry entry;
  569. entry.family = tw->tw_family;
  570. #if IS_ENABLED(CONFIG_IPV6)
  571. if (tw->tw_family == AF_INET6) {
  572. struct inet6_timewait_sock *tw6 =
  573. inet6_twsk((struct sock *)tw);
  574. entry.saddr = tw6->tw_v6_rcv_saddr.s6_addr32;
  575. entry.daddr = tw6->tw_v6_daddr.s6_addr32;
  576. } else
  577. #endif
  578. {
  579. entry.saddr = &tw->tw_rcv_saddr;
  580. entry.daddr = &tw->tw_daddr;
  581. }
  582. entry.sport = tw->tw_num;
  583. entry.dport = ntohs(tw->tw_dport);
  584. entry.userlocks = 0;
  585. if (!inet_diag_bc_run(bc, &entry))
  586. return 0;
  587. }
  588. return inet_twsk_diag_fill(tw, skb, r,
  589. NETLINK_CB(cb->skb).pid,
  590. cb->nlh->nlmsg_seq, NLM_F_MULTI, cb->nlh);
  591. }
  592. /* Get the IPv4, IPv6, or IPv4-mapped-IPv6 local and remote addresses
  593. * from a request_sock. For IPv4-mapped-IPv6 we must map IPv4 to IPv6.
  594. */
  595. static inline void inet_diag_req_addrs(const struct sock *sk,
  596. const struct request_sock *req,
  597. struct inet_diag_entry *entry)
  598. {
  599. struct inet_request_sock *ireq = inet_rsk(req);
  600. #if IS_ENABLED(CONFIG_IPV6)
  601. if (sk->sk_family == AF_INET6) {
  602. if (req->rsk_ops->family == AF_INET6) {
  603. entry->saddr = inet6_rsk(req)->loc_addr.s6_addr32;
  604. entry->daddr = inet6_rsk(req)->rmt_addr.s6_addr32;
  605. } else if (req->rsk_ops->family == AF_INET) {
  606. ipv6_addr_set_v4mapped(ireq->loc_addr,
  607. &entry->saddr_storage);
  608. ipv6_addr_set_v4mapped(ireq->rmt_addr,
  609. &entry->daddr_storage);
  610. entry->saddr = entry->saddr_storage.s6_addr32;
  611. entry->daddr = entry->daddr_storage.s6_addr32;
  612. }
  613. } else
  614. #endif
  615. {
  616. entry->saddr = &ireq->loc_addr;
  617. entry->daddr = &ireq->rmt_addr;
  618. }
  619. }
  620. static int inet_diag_fill_req(struct sk_buff *skb, struct sock *sk,
  621. struct request_sock *req, u32 pid, u32 seq,
  622. const struct nlmsghdr *unlh)
  623. {
  624. const struct inet_request_sock *ireq = inet_rsk(req);
  625. struct inet_sock *inet = inet_sk(sk);
  626. unsigned char *b = skb_tail_pointer(skb);
  627. struct inet_diag_msg *r;
  628. struct nlmsghdr *nlh;
  629. long tmo;
  630. nlh = NLMSG_PUT(skb, pid, seq, unlh->nlmsg_type, sizeof(*r));
  631. nlh->nlmsg_flags = NLM_F_MULTI;
  632. r = NLMSG_DATA(nlh);
  633. r->idiag_family = sk->sk_family;
  634. r->idiag_state = TCP_SYN_RECV;
  635. r->idiag_timer = 1;
  636. r->idiag_retrans = req->retrans;
  637. r->id.idiag_if = sk->sk_bound_dev_if;
  638. sock_diag_save_cookie(req, r->id.idiag_cookie);
  639. tmo = req->expires - jiffies;
  640. if (tmo < 0)
  641. tmo = 0;
  642. r->id.idiag_sport = inet->inet_sport;
  643. r->id.idiag_dport = ireq->rmt_port;
  644. memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src));
  645. memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst));
  646. r->id.idiag_src[0] = ireq->loc_addr;
  647. r->id.idiag_dst[0] = ireq->rmt_addr;
  648. r->idiag_expires = jiffies_to_msecs(tmo);
  649. r->idiag_rqueue = 0;
  650. r->idiag_wqueue = 0;
  651. r->idiag_uid = sock_i_uid(sk);
  652. r->idiag_inode = 0;
  653. #if IS_ENABLED(CONFIG_IPV6)
  654. if (r->idiag_family == AF_INET6) {
  655. struct inet_diag_entry entry;
  656. inet_diag_req_addrs(sk, req, &entry);
  657. memcpy(r->id.idiag_src, entry.saddr, sizeof(struct in6_addr));
  658. memcpy(r->id.idiag_dst, entry.daddr, sizeof(struct in6_addr));
  659. }
  660. #endif
  661. nlh->nlmsg_len = skb_tail_pointer(skb) - b;
  662. return skb->len;
  663. nlmsg_failure:
  664. nlmsg_trim(skb, b);
  665. return -1;
  666. }
  667. static int inet_diag_dump_reqs(struct sk_buff *skb, struct sock *sk,
  668. struct netlink_callback *cb,
  669. struct inet_diag_req_v2 *r,
  670. const struct nlattr *bc)
  671. {
  672. struct inet_diag_entry entry;
  673. struct inet_connection_sock *icsk = inet_csk(sk);
  674. struct listen_sock *lopt;
  675. struct inet_sock *inet = inet_sk(sk);
  676. int j, s_j;
  677. int reqnum, s_reqnum;
  678. int err = 0;
  679. s_j = cb->args[3];
  680. s_reqnum = cb->args[4];
  681. if (s_j > 0)
  682. s_j--;
  683. entry.family = sk->sk_family;
  684. read_lock_bh(&icsk->icsk_accept_queue.syn_wait_lock);
  685. lopt = icsk->icsk_accept_queue.listen_opt;
  686. if (!lopt || !lopt->qlen)
  687. goto out;
  688. if (bc != NULL) {
  689. entry.sport = inet->inet_num;
  690. entry.userlocks = sk->sk_userlocks;
  691. }
  692. for (j = s_j; j < lopt->nr_table_entries; j++) {
  693. struct request_sock *req, *head = lopt->syn_table[j];
  694. reqnum = 0;
  695. for (req = head; req; reqnum++, req = req->dl_next) {
  696. struct inet_request_sock *ireq = inet_rsk(req);
  697. if (reqnum < s_reqnum)
  698. continue;
  699. if (r->id.idiag_dport != ireq->rmt_port &&
  700. r->id.idiag_dport)
  701. continue;
  702. if (bc) {
  703. inet_diag_req_addrs(sk, req, &entry);
  704. entry.dport = ntohs(ireq->rmt_port);
  705. if (!inet_diag_bc_run(bc, &entry))
  706. continue;
  707. }
  708. err = inet_diag_fill_req(skb, sk, req,
  709. NETLINK_CB(cb->skb).pid,
  710. cb->nlh->nlmsg_seq, cb->nlh);
  711. if (err < 0) {
  712. cb->args[3] = j + 1;
  713. cb->args[4] = reqnum;
  714. goto out;
  715. }
  716. }
  717. s_reqnum = 0;
  718. }
  719. out:
  720. read_unlock_bh(&icsk->icsk_accept_queue.syn_wait_lock);
  721. return err;
  722. }
  723. void inet_diag_dump_icsk(struct inet_hashinfo *hashinfo, struct sk_buff *skb,
  724. struct netlink_callback *cb, struct inet_diag_req_v2 *r, struct nlattr *bc)
  725. {
  726. int i, num;
  727. int s_i, s_num;
  728. s_i = cb->args[1];
  729. s_num = num = cb->args[2];
  730. if (cb->args[0] == 0) {
  731. if (!(r->idiag_states & (TCPF_LISTEN | TCPF_SYN_RECV)))
  732. goto skip_listen_ht;
  733. for (i = s_i; i < INET_LHTABLE_SIZE; i++) {
  734. struct sock *sk;
  735. struct hlist_nulls_node *node;
  736. struct inet_listen_hashbucket *ilb;
  737. num = 0;
  738. ilb = &hashinfo->listening_hash[i];
  739. spin_lock_bh(&ilb->lock);
  740. sk_nulls_for_each(sk, node, &ilb->head) {
  741. struct inet_sock *inet = inet_sk(sk);
  742. if (num < s_num) {
  743. num++;
  744. continue;
  745. }
  746. if (r->sdiag_family != AF_UNSPEC &&
  747. sk->sk_family != r->sdiag_family)
  748. goto next_listen;
  749. if (r->id.idiag_sport != inet->inet_sport &&
  750. r->id.idiag_sport)
  751. goto next_listen;
  752. if (!(r->idiag_states & TCPF_LISTEN) ||
  753. r->id.idiag_dport ||
  754. cb->args[3] > 0)
  755. goto syn_recv;
  756. if (inet_csk_diag_dump(sk, skb, cb, r, bc) < 0) {
  757. spin_unlock_bh(&ilb->lock);
  758. goto done;
  759. }
  760. syn_recv:
  761. if (!(r->idiag_states & TCPF_SYN_RECV))
  762. goto next_listen;
  763. if (inet_diag_dump_reqs(skb, sk, cb, r, bc) < 0) {
  764. spin_unlock_bh(&ilb->lock);
  765. goto done;
  766. }
  767. next_listen:
  768. cb->args[3] = 0;
  769. cb->args[4] = 0;
  770. ++num;
  771. }
  772. spin_unlock_bh(&ilb->lock);
  773. s_num = 0;
  774. cb->args[3] = 0;
  775. cb->args[4] = 0;
  776. }
  777. skip_listen_ht:
  778. cb->args[0] = 1;
  779. s_i = num = s_num = 0;
  780. }
  781. if (!(r->idiag_states & ~(TCPF_LISTEN | TCPF_SYN_RECV)))
  782. goto out;
  783. for (i = s_i; i <= hashinfo->ehash_mask; i++) {
  784. struct inet_ehash_bucket *head = &hashinfo->ehash[i];
  785. spinlock_t *lock = inet_ehash_lockp(hashinfo, i);
  786. struct sock *sk;
  787. struct hlist_nulls_node *node;
  788. num = 0;
  789. if (hlist_nulls_empty(&head->chain) &&
  790. hlist_nulls_empty(&head->twchain))
  791. continue;
  792. if (i > s_i)
  793. s_num = 0;
  794. spin_lock_bh(lock);
  795. sk_nulls_for_each(sk, node, &head->chain) {
  796. struct inet_sock *inet = inet_sk(sk);
  797. if (num < s_num)
  798. goto next_normal;
  799. if (!(r->idiag_states & (1 << sk->sk_state)))
  800. goto next_normal;
  801. if (r->sdiag_family != AF_UNSPEC &&
  802. sk->sk_family != r->sdiag_family)
  803. goto next_normal;
  804. if (r->id.idiag_sport != inet->inet_sport &&
  805. r->id.idiag_sport)
  806. goto next_normal;
  807. if (r->id.idiag_dport != inet->inet_dport &&
  808. r->id.idiag_dport)
  809. goto next_normal;
  810. if (inet_csk_diag_dump(sk, skb, cb, r, bc) < 0) {
  811. spin_unlock_bh(lock);
  812. goto done;
  813. }
  814. next_normal:
  815. ++num;
  816. }
  817. if (r->idiag_states & (TCPF_TIME_WAIT | TCPF_FIN_WAIT2)) {
  818. struct inet_timewait_sock *tw;
  819. inet_twsk_for_each(tw, node,
  820. &head->twchain) {
  821. if (num < s_num)
  822. goto next_dying;
  823. if (!(r->idiag_states & (1 << tw->tw_substate)))
  824. goto next_dying;
  825. if (r->sdiag_family != AF_UNSPEC &&
  826. tw->tw_family != r->sdiag_family)
  827. goto next_dying;
  828. if (r->id.idiag_sport != tw->tw_sport &&
  829. r->id.idiag_sport)
  830. goto next_dying;
  831. if (r->id.idiag_dport != tw->tw_dport &&
  832. r->id.idiag_dport)
  833. goto next_dying;
  834. if (inet_twsk_diag_dump(tw, skb, cb, r, bc) < 0) {
  835. spin_unlock_bh(lock);
  836. goto done;
  837. }
  838. next_dying:
  839. ++num;
  840. }
  841. }
  842. spin_unlock_bh(lock);
  843. }
  844. done:
  845. cb->args[1] = i;
  846. cb->args[2] = num;
  847. out:
  848. ;
  849. }
  850. EXPORT_SYMBOL_GPL(inet_diag_dump_icsk);
  851. static int __inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
  852. struct inet_diag_req_v2 *r, struct nlattr *bc)
  853. {
  854. const struct inet_diag_handler *handler;
  855. int err = 0;
  856. handler = inet_diag_lock_handler(r->sdiag_protocol);
  857. if (!IS_ERR(handler))
  858. handler->dump(skb, cb, r, bc);
  859. else
  860. err = PTR_ERR(handler);
  861. inet_diag_unlock_handler(handler);
  862. return err ? : skb->len;
  863. }
  864. static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
  865. {
  866. struct nlattr *bc = NULL;
  867. int hdrlen = sizeof(struct inet_diag_req_v2);
  868. if (nlmsg_attrlen(cb->nlh, hdrlen))
  869. bc = nlmsg_find_attr(cb->nlh, hdrlen, INET_DIAG_REQ_BYTECODE);
  870. return __inet_diag_dump(skb, cb, (struct inet_diag_req_v2 *)NLMSG_DATA(cb->nlh), bc);
  871. }
  872. static inline int inet_diag_type2proto(int type)
  873. {
  874. switch (type) {
  875. case TCPDIAG_GETSOCK:
  876. return IPPROTO_TCP;
  877. case DCCPDIAG_GETSOCK:
  878. return IPPROTO_DCCP;
  879. default:
  880. return 0;
  881. }
  882. }
  883. static int inet_diag_dump_compat(struct sk_buff *skb, struct netlink_callback *cb)
  884. {
  885. struct inet_diag_req *rc = NLMSG_DATA(cb->nlh);
  886. struct inet_diag_req_v2 req;
  887. struct nlattr *bc = NULL;
  888. int hdrlen = sizeof(struct inet_diag_req);
  889. req.sdiag_family = AF_UNSPEC; /* compatibility */
  890. req.sdiag_protocol = inet_diag_type2proto(cb->nlh->nlmsg_type);
  891. req.idiag_ext = rc->idiag_ext;
  892. req.idiag_states = rc->idiag_states;
  893. req.id = rc->id;
  894. if (nlmsg_attrlen(cb->nlh, hdrlen))
  895. bc = nlmsg_find_attr(cb->nlh, hdrlen, INET_DIAG_REQ_BYTECODE);
  896. return __inet_diag_dump(skb, cb, &req, bc);
  897. }
  898. static int inet_diag_get_exact_compat(struct sk_buff *in_skb,
  899. const struct nlmsghdr *nlh)
  900. {
  901. struct inet_diag_req *rc = NLMSG_DATA(nlh);
  902. struct inet_diag_req_v2 req;
  903. req.sdiag_family = rc->idiag_family;
  904. req.sdiag_protocol = inet_diag_type2proto(nlh->nlmsg_type);
  905. req.idiag_ext = rc->idiag_ext;
  906. req.idiag_states = rc->idiag_states;
  907. req.id = rc->id;
  908. return inet_diag_cmd_exact(SOCK_DIAG_BY_FAMILY, in_skb, nlh, &req);
  909. }
  910. static int inet_diag_rcv_msg_compat(struct sk_buff *skb, struct nlmsghdr *nlh)
  911. {
  912. int hdrlen = sizeof(struct inet_diag_req);
  913. if (nlh->nlmsg_type >= INET_DIAG_GETSOCK_MAX ||
  914. nlmsg_len(nlh) < hdrlen)
  915. return -EINVAL;
  916. if (nlh->nlmsg_flags & NLM_F_DUMP) {
  917. if (nlmsg_attrlen(nlh, hdrlen)) {
  918. struct nlattr *attr;
  919. attr = nlmsg_find_attr(nlh, hdrlen,
  920. INET_DIAG_REQ_BYTECODE);
  921. if (attr == NULL ||
  922. nla_len(attr) < sizeof(struct inet_diag_bc_op) ||
  923. inet_diag_bc_audit(nla_data(attr), nla_len(attr)))
  924. return -EINVAL;
  925. }
  926. {
  927. struct netlink_dump_control c = {
  928. .dump = inet_diag_dump_compat,
  929. };
  930. return netlink_dump_start(sock_diag_nlsk, skb, nlh, &c);
  931. }
  932. }
  933. return inet_diag_get_exact_compat(skb, nlh);
  934. }
  935. static int inet_diag_handler_cmd(struct sk_buff *skb, struct nlmsghdr *h)
  936. {
  937. int hdrlen = sizeof(struct inet_diag_req_v2);
  938. if (nlmsg_len(h) < hdrlen)
  939. return -EINVAL;
  940. if (h->nlmsg_type == SOCK_DIAG_BY_FAMILY &&
  941. h->nlmsg_flags & NLM_F_DUMP) {
  942. if (nlmsg_attrlen(h, hdrlen)) {
  943. struct nlattr *attr;
  944. attr = nlmsg_find_attr(h, hdrlen,
  945. INET_DIAG_REQ_BYTECODE);
  946. if (attr == NULL ||
  947. nla_len(attr) < sizeof(struct inet_diag_bc_op) ||
  948. inet_diag_bc_audit(nla_data(attr), nla_len(attr)))
  949. return -EINVAL;
  950. }
  951. {
  952. struct netlink_dump_control c = {
  953. .dump = inet_diag_dump,
  954. };
  955. return netlink_dump_start(sock_diag_nlsk, skb, h, &c);
  956. }
  957. }
  958. return inet_diag_cmd_exact(h->nlmsg_type, skb, h,
  959. (struct inet_diag_req_v2 *)NLMSG_DATA(h));
  960. }
  961. static struct sock_diag_handler inet_diag_handler = {
  962. .family = AF_INET,
  963. .dump = inet_diag_handler_cmd,
  964. .destroy = inet_diag_handler_cmd,
  965. };
  966. static struct sock_diag_handler inet6_diag_handler = {
  967. .family = AF_INET6,
  968. .dump = inet_diag_handler_cmd,
  969. .destroy = inet_diag_handler_cmd,
  970. };
  971. int inet_diag_register(const struct inet_diag_handler *h)
  972. {
  973. const __u16 type = h->idiag_type;
  974. int err = -EINVAL;
  975. if (type >= IPPROTO_MAX)
  976. goto out;
  977. mutex_lock(&inet_diag_table_mutex);
  978. err = -EEXIST;
  979. if (inet_diag_table[type] == NULL) {
  980. inet_diag_table[type] = h;
  981. err = 0;
  982. }
  983. mutex_unlock(&inet_diag_table_mutex);
  984. out:
  985. return err;
  986. }
  987. EXPORT_SYMBOL_GPL(inet_diag_register);
  988. void inet_diag_unregister(const struct inet_diag_handler *h)
  989. {
  990. const __u16 type = h->idiag_type;
  991. if (type >= IPPROTO_MAX)
  992. return;
  993. mutex_lock(&inet_diag_table_mutex);
  994. inet_diag_table[type] = NULL;
  995. mutex_unlock(&inet_diag_table_mutex);
  996. }
  997. EXPORT_SYMBOL_GPL(inet_diag_unregister);
  998. static int __init inet_diag_init(void)
  999. {
  1000. const int inet_diag_table_size = (IPPROTO_MAX *
  1001. sizeof(struct inet_diag_handler *));
  1002. int err = -ENOMEM;
  1003. inet_diag_table = kzalloc(inet_diag_table_size, GFP_KERNEL);
  1004. if (!inet_diag_table)
  1005. goto out;
  1006. err = sock_diag_register(&inet_diag_handler);
  1007. if (err)
  1008. goto out_free_nl;
  1009. err = sock_diag_register(&inet6_diag_handler);
  1010. if (err)
  1011. goto out_free_inet;
  1012. sock_diag_register_inet_compat(inet_diag_rcv_msg_compat);
  1013. out:
  1014. return err;
  1015. out_free_inet:
  1016. sock_diag_unregister(&inet_diag_handler);
  1017. out_free_nl:
  1018. kfree(inet_diag_table);
  1019. goto out;
  1020. }
  1021. static void __exit inet_diag_exit(void)
  1022. {
  1023. sock_diag_unregister(&inet6_diag_handler);
  1024. sock_diag_unregister(&inet_diag_handler);
  1025. sock_diag_unregister_inet_compat(inet_diag_rcv_msg_compat);
  1026. kfree(inet_diag_table);
  1027. }
  1028. module_init(inet_diag_init);
  1029. module_exit(inet_diag_exit);
  1030. MODULE_LICENSE("GPL");
  1031. MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_NETLINK, NETLINK_SOCK_DIAG, 2 /* AF_INET */);
  1032. MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_NETLINK, NETLINK_SOCK_DIAG, 10 /* AF_INET6 */);