2 * inet_diag.c Module for monitoring INET transport protocols sockets.
4 * Version: $Id: inet_diag.c,v 1.3 2002/02/01 22:01:04 davem Exp $
6 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
14 #include <linux/module.h>
15 #include <linux/types.h>
16 #include <linux/fcntl.h>
17 #include <linux/random.h>
18 #include <linux/cache.h>
19 #include <linux/init.h>
20 #include <linux/time.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>
31 #include <linux/inet.h>
32 #include <linux/stddef.h>
34 #include <linux/inet_diag.h>
36 static const struct inet_diag_handler **inet_diag_table;
38 struct inet_diag_entry {
47 static struct sock *idiagnl;
49 #define INET_DIAG_PUT(skb, attrtype, attrlen) \
50 RTA_DATA(__RTA_PUT(skb, attrtype, attrlen))
52 static int inet_csk_diag_fill(struct sock *sk,
54 int ext, u32 pid, u32 seq, u16 nlmsg_flags,
55 const struct nlmsghdr *unlh)
57 const struct inet_sock *inet = inet_sk(sk);
58 const struct inet_connection_sock *icsk = inet_csk(sk);
59 struct inet_diag_msg *r;
62 struct inet_diag_meminfo *minfo = NULL;
63 unsigned char *b = skb->tail;
64 const struct inet_diag_handler *handler;
66 handler = inet_diag_table[unlh->nlmsg_type];
67 BUG_ON(handler == NULL);
69 nlh = NLMSG_PUT(skb, pid, seq, unlh->nlmsg_type, sizeof(*r));
70 nlh->nlmsg_flags = nlmsg_flags;
73 BUG_ON(sk->sk_state == TCP_TIME_WAIT);
75 if (ext & (1 << (INET_DIAG_MEMINFO - 1)))
76 minfo = INET_DIAG_PUT(skb, INET_DIAG_MEMINFO, sizeof(*minfo));
78 if (ext & (1 << (INET_DIAG_INFO - 1)))
79 info = INET_DIAG_PUT(skb, INET_DIAG_INFO,
80 handler->idiag_info_size);
82 if ((ext & (1 << (INET_DIAG_CONG - 1))) && icsk->icsk_ca_ops) {
83 const size_t len = strlen(icsk->icsk_ca_ops->name);
85 strcpy(INET_DIAG_PUT(skb, INET_DIAG_CONG, len + 1),
86 icsk->icsk_ca_ops->name);
89 r->idiag_family = sk->sk_family;
90 r->idiag_state = sk->sk_state;
94 r->id.idiag_if = sk->sk_bound_dev_if;
95 r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
96 r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
98 r->id.idiag_sport = inet->sport;
99 r->id.idiag_dport = inet->dport;
100 r->id.idiag_src[0] = inet->rcv_saddr;
101 r->id.idiag_dst[0] = inet->daddr;
103 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
104 if (r->idiag_family == AF_INET6) {
105 struct ipv6_pinfo *np = inet6_sk(sk);
107 ipv6_addr_copy((struct in6_addr *)r->id.idiag_src,
109 ipv6_addr_copy((struct in6_addr *)r->id.idiag_dst,
114 #define EXPIRES_IN_MS(tmo) ((tmo - jiffies) * 1000 + HZ - 1) / HZ
116 if (icsk->icsk_pending == ICSK_TIME_RETRANS) {
118 r->idiag_retrans = icsk->icsk_retransmits;
119 r->idiag_expires = EXPIRES_IN_MS(icsk->icsk_timeout);
120 } else if (icsk->icsk_pending == ICSK_TIME_PROBE0) {
122 r->idiag_retrans = icsk->icsk_probes_out;
123 r->idiag_expires = EXPIRES_IN_MS(icsk->icsk_timeout);
124 } else if (timer_pending(&sk->sk_timer)) {
126 r->idiag_retrans = icsk->icsk_probes_out;
127 r->idiag_expires = EXPIRES_IN_MS(sk->sk_timer.expires);
130 r->idiag_expires = 0;
134 r->idiag_uid = sock_i_uid(sk);
135 r->idiag_inode = sock_i_ino(sk);
138 minfo->idiag_rmem = atomic_read(&sk->sk_rmem_alloc);
139 minfo->idiag_wmem = sk->sk_wmem_queued;
140 minfo->idiag_fmem = sk->sk_forward_alloc;
141 minfo->idiag_tmem = atomic_read(&sk->sk_wmem_alloc);
144 handler->idiag_get_info(sk, r, info);
146 if (sk->sk_state < TCP_TIME_WAIT &&
147 icsk->icsk_ca_ops && icsk->icsk_ca_ops->get_info)
148 icsk->icsk_ca_ops->get_info(sk, ext, skb);
150 nlh->nlmsg_len = skb->tail - b;
155 skb_trim(skb, b - skb->data);
159 static int inet_twsk_diag_fill(struct inet_timewait_sock *tw,
160 struct sk_buff *skb, int ext, u32 pid,
161 u32 seq, u16 nlmsg_flags,
162 const struct nlmsghdr *unlh)
165 struct inet_diag_msg *r;
166 const unsigned char *previous_tail = skb->tail;
167 struct nlmsghdr *nlh = NLMSG_PUT(skb, pid, seq,
168 unlh->nlmsg_type, sizeof(*r));
171 BUG_ON(tw->tw_state != TCP_TIME_WAIT);
173 nlh->nlmsg_flags = nlmsg_flags;
175 tmo = tw->tw_ttd - jiffies;
179 r->idiag_family = tw->tw_family;
180 r->idiag_state = tw->tw_state;
182 r->idiag_retrans = 0;
183 r->id.idiag_if = tw->tw_bound_dev_if;
184 r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
185 r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
186 r->id.idiag_sport = tw->tw_sport;
187 r->id.idiag_dport = tw->tw_dport;
188 r->id.idiag_src[0] = tw->tw_rcv_saddr;
189 r->id.idiag_dst[0] = tw->tw_daddr;
190 r->idiag_state = tw->tw_substate;
192 r->idiag_expires = (tmo * 1000 + HZ - 1) / HZ;
197 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
198 if (tw->tw_family == AF_INET6) {
199 const struct inet6_timewait_sock *tw6 =
200 inet6_twsk((struct sock *)tw);
202 ipv6_addr_copy((struct in6_addr *)r->id.idiag_src,
203 &tw6->tw_v6_rcv_saddr);
204 ipv6_addr_copy((struct in6_addr *)r->id.idiag_dst,
208 nlh->nlmsg_len = skb->tail - previous_tail;
211 skb_trim(skb, previous_tail - skb->data);
215 static int sk_diag_fill(struct sock *sk, struct sk_buff *skb,
216 int ext, u32 pid, u32 seq, u16 nlmsg_flags,
217 const struct nlmsghdr *unlh)
219 if (sk->sk_state == TCP_TIME_WAIT)
220 return inet_twsk_diag_fill((struct inet_timewait_sock *)sk,
221 skb, ext, pid, seq, nlmsg_flags,
223 return inet_csk_diag_fill(sk, skb, ext, pid, seq, nlmsg_flags, unlh);
226 static int inet_diag_get_exact(struct sk_buff *in_skb,
227 const struct nlmsghdr *nlh)
231 struct inet_diag_req *req = NLMSG_DATA(nlh);
233 struct inet_hashinfo *hashinfo;
234 const struct inet_diag_handler *handler;
236 handler = inet_diag_table[nlh->nlmsg_type];
237 BUG_ON(handler == NULL);
238 hashinfo = handler->idiag_hashinfo;
240 if (req->idiag_family == AF_INET) {
241 sk = inet_lookup(hashinfo, req->id.idiag_dst[0],
242 req->id.idiag_dport, req->id.idiag_src[0],
243 req->id.idiag_sport, req->id.idiag_if);
245 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
246 else if (req->idiag_family == AF_INET6) {
247 sk = inet6_lookup(hashinfo,
248 (struct in6_addr *)req->id.idiag_dst,
250 (struct in6_addr *)req->id.idiag_src,
263 if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
264 req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
265 ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
266 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
270 rep = alloc_skb(NLMSG_SPACE((sizeof(struct inet_diag_msg) +
271 sizeof(struct inet_diag_meminfo) +
272 handler->idiag_info_size + 64)),
277 if (sk_diag_fill(sk, rep, req->idiag_ext,
278 NETLINK_CB(in_skb).pid,
279 nlh->nlmsg_seq, 0, nlh) <= 0)
282 err = netlink_unicast(idiagnl, rep, NETLINK_CB(in_skb).pid,
289 if (sk->sk_state == TCP_TIME_WAIT)
290 inet_twsk_put((struct inet_timewait_sock *)sk);
297 static int bitstring_match(const __be32 *a1, const __be32 *a2, int bits)
299 int words = bits >> 5;
304 if (memcmp(a1, a2, words << 2))
314 mask = htonl((0xffffffff) << (32 - bits));
316 if ((w1 ^ w2) & mask)
324 static int inet_diag_bc_run(const void *bc, int len,
325 const struct inet_diag_entry *entry)
329 const struct inet_diag_bc_op *op = bc;
332 case INET_DIAG_BC_NOP:
334 case INET_DIAG_BC_JMP:
337 case INET_DIAG_BC_S_GE:
338 yes = entry->sport >= op[1].no;
340 case INET_DIAG_BC_S_LE:
341 yes = entry->dport <= op[1].no;
343 case INET_DIAG_BC_D_GE:
344 yes = entry->dport >= op[1].no;
346 case INET_DIAG_BC_D_LE:
347 yes = entry->dport <= op[1].no;
349 case INET_DIAG_BC_AUTO:
350 yes = !(entry->userlocks & SOCK_BINDPORT_LOCK);
352 case INET_DIAG_BC_S_COND:
353 case INET_DIAG_BC_D_COND: {
354 struct inet_diag_hostcond *cond;
357 cond = (struct inet_diag_hostcond *)(op + 1);
358 if (cond->port != -1 &&
359 cond->port != (op->code == INET_DIAG_BC_S_COND ?
360 entry->sport : entry->dport)) {
365 if (cond->prefix_len == 0)
368 if (op->code == INET_DIAG_BC_S_COND)
373 if (bitstring_match(addr, cond->addr,
376 if (entry->family == AF_INET6 &&
377 cond->family == AF_INET) {
378 if (addr[0] == 0 && addr[1] == 0 &&
379 addr[2] == htonl(0xffff) &&
380 bitstring_match(addr + 3, cond->addr,
400 static int valid_cc(const void *bc, int len, int cc)
403 const struct inet_diag_bc_op *op = bc;
417 static int inet_diag_bc_audit(const void *bytecode, int bytecode_len)
419 const unsigned char *bc = bytecode;
420 int len = bytecode_len;
423 struct inet_diag_bc_op *op = (struct inet_diag_bc_op *)bc;
425 //printk("BC: %d %d %d {%d} / %d\n", op->code, op->yes, op->no, op[1].no, len);
427 case INET_DIAG_BC_AUTO:
428 case INET_DIAG_BC_S_COND:
429 case INET_DIAG_BC_D_COND:
430 case INET_DIAG_BC_S_GE:
431 case INET_DIAG_BC_S_LE:
432 case INET_DIAG_BC_D_GE:
433 case INET_DIAG_BC_D_LE:
434 if (op->yes < 4 || op->yes > len + 4)
436 case INET_DIAG_BC_JMP:
437 if (op->no < 4 || op->no > len + 4)
440 !valid_cc(bytecode, bytecode_len, len - op->no))
443 case INET_DIAG_BC_NOP:
444 if (op->yes < 4 || op->yes > len + 4)
453 return len == 0 ? 0 : -EINVAL;
456 static int inet_csk_diag_dump(struct sock *sk,
458 struct netlink_callback *cb)
460 struct inet_diag_req *r = NLMSG_DATA(cb->nlh);
462 if (cb->nlh->nlmsg_len > 4 + NLMSG_SPACE(sizeof(*r))) {
463 struct inet_diag_entry entry;
464 struct rtattr *bc = (struct rtattr *)(r + 1);
465 struct inet_sock *inet = inet_sk(sk);
467 entry.family = sk->sk_family;
468 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
469 if (entry.family == AF_INET6) {
470 struct ipv6_pinfo *np = inet6_sk(sk);
472 entry.saddr = np->rcv_saddr.s6_addr32;
473 entry.daddr = np->daddr.s6_addr32;
477 entry.saddr = &inet->rcv_saddr;
478 entry.daddr = &inet->daddr;
480 entry.sport = inet->num;
481 entry.dport = ntohs(inet->dport);
482 entry.userlocks = sk->sk_userlocks;
484 if (!inet_diag_bc_run(RTA_DATA(bc), RTA_PAYLOAD(bc), &entry))
488 return inet_csk_diag_fill(sk, skb, r->idiag_ext,
489 NETLINK_CB(cb->skb).pid,
490 cb->nlh->nlmsg_seq, NLM_F_MULTI, cb->nlh);
493 static int inet_twsk_diag_dump(struct inet_timewait_sock *tw,
495 struct netlink_callback *cb)
497 struct inet_diag_req *r = NLMSG_DATA(cb->nlh);
499 if (cb->nlh->nlmsg_len > 4 + NLMSG_SPACE(sizeof(*r))) {
500 struct inet_diag_entry entry;
501 struct rtattr *bc = (struct rtattr *)(r + 1);
503 entry.family = tw->tw_family;
504 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
505 if (tw->tw_family == AF_INET6) {
506 struct inet6_timewait_sock *tw6 =
507 inet6_twsk((struct sock *)tw);
508 entry.saddr = tw6->tw_v6_rcv_saddr.s6_addr32;
509 entry.daddr = tw6->tw_v6_daddr.s6_addr32;
513 entry.saddr = &tw->tw_rcv_saddr;
514 entry.daddr = &tw->tw_daddr;
516 entry.sport = tw->tw_num;
517 entry.dport = ntohs(tw->tw_dport);
520 if (!inet_diag_bc_run(RTA_DATA(bc), RTA_PAYLOAD(bc), &entry))
524 return inet_twsk_diag_fill(tw, skb, r->idiag_ext,
525 NETLINK_CB(cb->skb).pid,
526 cb->nlh->nlmsg_seq, NLM_F_MULTI, cb->nlh);
529 static int inet_diag_fill_req(struct sk_buff *skb, struct sock *sk,
530 struct request_sock *req, u32 pid, u32 seq,
531 const struct nlmsghdr *unlh)
533 const struct inet_request_sock *ireq = inet_rsk(req);
534 struct inet_sock *inet = inet_sk(sk);
535 unsigned char *b = skb->tail;
536 struct inet_diag_msg *r;
537 struct nlmsghdr *nlh;
540 nlh = NLMSG_PUT(skb, pid, seq, unlh->nlmsg_type, sizeof(*r));
541 nlh->nlmsg_flags = NLM_F_MULTI;
544 r->idiag_family = sk->sk_family;
545 r->idiag_state = TCP_SYN_RECV;
547 r->idiag_retrans = req->retrans;
549 r->id.idiag_if = sk->sk_bound_dev_if;
550 r->id.idiag_cookie[0] = (u32)(unsigned long)req;
551 r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
553 tmo = req->expires - jiffies;
557 r->id.idiag_sport = inet->sport;
558 r->id.idiag_dport = ireq->rmt_port;
559 r->id.idiag_src[0] = ireq->loc_addr;
560 r->id.idiag_dst[0] = ireq->rmt_addr;
561 r->idiag_expires = jiffies_to_msecs(tmo);
564 r->idiag_uid = sock_i_uid(sk);
566 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
567 if (r->idiag_family == AF_INET6) {
568 ipv6_addr_copy((struct in6_addr *)r->id.idiag_src,
569 &inet6_rsk(req)->loc_addr);
570 ipv6_addr_copy((struct in6_addr *)r->id.idiag_dst,
571 &inet6_rsk(req)->rmt_addr);
574 nlh->nlmsg_len = skb->tail - b;
579 skb_trim(skb, b - skb->data);
583 static int inet_diag_dump_reqs(struct sk_buff *skb, struct sock *sk,
584 struct netlink_callback *cb)
586 struct inet_diag_entry entry;
587 struct inet_diag_req *r = NLMSG_DATA(cb->nlh);
588 struct inet_connection_sock *icsk = inet_csk(sk);
589 struct listen_sock *lopt;
590 struct rtattr *bc = NULL;
591 struct inet_sock *inet = inet_sk(sk);
593 int reqnum, s_reqnum;
597 s_reqnum = cb->args[4];
602 entry.family = sk->sk_family;
604 read_lock_bh(&icsk->icsk_accept_queue.syn_wait_lock);
606 lopt = icsk->icsk_accept_queue.listen_opt;
607 if (!lopt || !lopt->qlen)
610 if (cb->nlh->nlmsg_len > 4 + NLMSG_SPACE(sizeof(*r))) {
611 bc = (struct rtattr *)(r + 1);
612 entry.sport = inet->num;
613 entry.userlocks = sk->sk_userlocks;
616 for (j = s_j; j < lopt->nr_table_entries; j++) {
617 struct request_sock *req, *head = lopt->syn_table[j];
620 for (req = head; req; reqnum++, req = req->dl_next) {
621 struct inet_request_sock *ireq = inet_rsk(req);
623 if (reqnum < s_reqnum)
625 if (r->id.idiag_dport != ireq->rmt_port &&
631 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
632 (entry.family == AF_INET6) ?
633 inet6_rsk(req)->loc_addr.s6_addr32 :
637 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
638 (entry.family == AF_INET6) ?
639 inet6_rsk(req)->rmt_addr.s6_addr32 :
642 entry.dport = ntohs(ireq->rmt_port);
644 if (!inet_diag_bc_run(RTA_DATA(bc),
645 RTA_PAYLOAD(bc), &entry))
649 err = inet_diag_fill_req(skb, sk, req,
650 NETLINK_CB(cb->skb).pid,
651 cb->nlh->nlmsg_seq, cb->nlh);
654 cb->args[4] = reqnum;
663 read_unlock_bh(&icsk->icsk_accept_queue.syn_wait_lock);
668 static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
672 struct inet_diag_req *r = NLMSG_DATA(cb->nlh);
673 const struct inet_diag_handler *handler;
674 struct inet_hashinfo *hashinfo;
676 handler = inet_diag_table[cb->nlh->nlmsg_type];
677 BUG_ON(handler == NULL);
678 hashinfo = handler->idiag_hashinfo;
681 s_num = num = cb->args[2];
683 if (cb->args[0] == 0) {
684 if (!(r->idiag_states & (TCPF_LISTEN | TCPF_SYN_RECV)))
687 inet_listen_lock(hashinfo);
688 for (i = s_i; i < INET_LHTABLE_SIZE; i++) {
690 struct hlist_node *node;
693 sk_for_each(sk, node, &hashinfo->listening_hash[i]) {
694 struct inet_sock *inet = inet_sk(sk);
701 if (r->id.idiag_sport != inet->sport &&
705 if (!(r->idiag_states & TCPF_LISTEN) ||
710 if (inet_csk_diag_dump(sk, skb, cb) < 0) {
711 inet_listen_unlock(hashinfo);
716 if (!(r->idiag_states & TCPF_SYN_RECV))
719 if (inet_diag_dump_reqs(skb, sk, cb) < 0) {
720 inet_listen_unlock(hashinfo);
734 inet_listen_unlock(hashinfo);
737 s_i = num = s_num = 0;
740 if (!(r->idiag_states & ~(TCPF_LISTEN | TCPF_SYN_RECV)))
743 for (i = s_i; i < hashinfo->ehash_size; i++) {
744 struct inet_ehash_bucket *head = &hashinfo->ehash[i];
746 struct hlist_node *node;
751 read_lock_bh(&head->lock);
753 sk_for_each(sk, node, &head->chain) {
754 struct inet_sock *inet = inet_sk(sk);
758 if (!(r->idiag_states & (1 << sk->sk_state)))
760 if (r->id.idiag_sport != inet->sport &&
763 if (r->id.idiag_dport != inet->dport &&
766 if (inet_csk_diag_dump(sk, skb, cb) < 0) {
767 read_unlock_bh(&head->lock);
774 if (r->idiag_states & TCPF_TIME_WAIT) {
775 struct inet_timewait_sock *tw;
777 inet_twsk_for_each(tw, node,
778 &hashinfo->ehash[i + hashinfo->ehash_size].chain) {
782 if (r->id.idiag_sport != tw->tw_sport &&
785 if (r->id.idiag_dport != tw->tw_dport &&
788 if (inet_twsk_diag_dump(tw, skb, cb) < 0) {
789 read_unlock_bh(&head->lock);
796 read_unlock_bh(&head->lock);
805 static inline int inet_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
807 if (!(nlh->nlmsg_flags&NLM_F_REQUEST))
810 if (nlh->nlmsg_type >= INET_DIAG_GETSOCK_MAX)
813 if (inet_diag_table[nlh->nlmsg_type] == NULL)
816 if (NLMSG_LENGTH(sizeof(struct inet_diag_req)) > skb->len)
819 if (nlh->nlmsg_flags&NLM_F_DUMP) {
821 (4 + NLMSG_SPACE(sizeof(struct inet_diag_req)))) {
822 struct rtattr *rta = (void *)(NLMSG_DATA(nlh) +
823 sizeof(struct inet_diag_req));
824 if (rta->rta_type != INET_DIAG_REQ_BYTECODE ||
828 NLMSG_SPACE(sizeof(struct inet_diag_req))))
830 if (inet_diag_bc_audit(RTA_DATA(rta), RTA_PAYLOAD(rta)))
833 return netlink_dump_start(idiagnl, skb, nlh,
834 inet_diag_dump, NULL);
836 return inet_diag_get_exact(skb, nlh);
843 static inline void inet_diag_rcv_skb(struct sk_buff *skb)
845 if (skb->len >= NLMSG_SPACE(0)) {
847 struct nlmsghdr *nlh = (struct nlmsghdr *)skb->data;
849 if (nlh->nlmsg_len < sizeof(*nlh) ||
850 skb->len < nlh->nlmsg_len)
852 err = inet_diag_rcv_msg(skb, nlh);
853 if (err || nlh->nlmsg_flags & NLM_F_ACK)
854 netlink_ack(skb, nlh, err);
858 static void inet_diag_rcv(struct sock *sk, int len)
861 unsigned int qlen = skb_queue_len(&sk->sk_receive_queue);
863 while (qlen-- && (skb = skb_dequeue(&sk->sk_receive_queue))) {
864 inet_diag_rcv_skb(skb);
869 static DEFINE_SPINLOCK(inet_diag_register_lock);
871 int inet_diag_register(const struct inet_diag_handler *h)
873 const __u16 type = h->idiag_type;
876 if (type >= INET_DIAG_GETSOCK_MAX)
879 spin_lock(&inet_diag_register_lock);
881 if (inet_diag_table[type] == NULL) {
882 inet_diag_table[type] = h;
885 spin_unlock(&inet_diag_register_lock);
889 EXPORT_SYMBOL_GPL(inet_diag_register);
891 void inet_diag_unregister(const struct inet_diag_handler *h)
893 const __u16 type = h->idiag_type;
895 if (type >= INET_DIAG_GETSOCK_MAX)
898 spin_lock(&inet_diag_register_lock);
899 inet_diag_table[type] = NULL;
900 spin_unlock(&inet_diag_register_lock);
904 EXPORT_SYMBOL_GPL(inet_diag_unregister);
906 static int __init inet_diag_init(void)
908 const int inet_diag_table_size = (INET_DIAG_GETSOCK_MAX *
909 sizeof(struct inet_diag_handler *));
912 inet_diag_table = kzalloc(inet_diag_table_size, GFP_KERNEL);
913 if (!inet_diag_table)
916 idiagnl = netlink_kernel_create(NETLINK_INET_DIAG, 0, inet_diag_rcv,
924 kfree(inet_diag_table);
928 static void __exit inet_diag_exit(void)
930 sock_release(idiagnl->sk_socket);
931 kfree(inet_diag_table);
934 module_init(inet_diag_init);
935 module_exit(inet_diag_exit);
936 MODULE_LICENSE("GPL");