inet_diag.c 30 KB

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