2 * tcp_diag.c Module for monitoring TCP sockets.
4 * Version: $Id: tcp_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/config.h>
15 #include <linux/module.h>
16 #include <linux/types.h>
17 #include <linux/fcntl.h>
18 #include <linux/random.h>
19 #include <linux/cache.h>
20 #include <linux/init.h>
21 #include <linux/time.h>
26 #include <net/inet_common.h>
27 #include <net/inet_connection_sock.h>
28 #include <net/inet_hashtables.h>
29 #include <net/inet_timewait_sock.h>
30 #include <net/inet6_hashtables.h>
32 #include <linux/inet.h>
33 #include <linux/stddef.h>
35 #include <linux/tcp_diag.h>
37 static const struct inet_diag_handler **inet_diag_table;
49 static struct sock *tcpnl;
51 #define TCPDIAG_PUT(skb, attrtype, attrlen) \
52 RTA_DATA(__RTA_PUT(skb, attrtype, attrlen))
54 #ifdef CONFIG_IP_TCPDIAG_DCCP
55 extern struct inet_hashinfo dccp_hashinfo;
58 static int tcpdiag_fill(struct sk_buff *skb, struct sock *sk,
59 int ext, u32 pid, u32 seq, u16 nlmsg_flags,
60 const struct nlmsghdr *unlh)
62 const struct inet_sock *inet = inet_sk(sk);
63 const struct inet_connection_sock *icsk = inet_csk(sk);
67 struct tcpdiag_meminfo *minfo = NULL;
68 unsigned char *b = skb->tail;
69 const struct inet_diag_handler *handler;
71 handler = inet_diag_table[unlh->nlmsg_type];
72 BUG_ON(handler == NULL);
74 nlh = NLMSG_PUT(skb, pid, seq, unlh->nlmsg_type, sizeof(*r));
75 nlh->nlmsg_flags = nlmsg_flags;
78 if (sk->sk_state != TCP_TIME_WAIT) {
79 if (ext & (1<<(TCPDIAG_MEMINFO-1)))
80 minfo = TCPDIAG_PUT(skb, TCPDIAG_MEMINFO, sizeof(*minfo));
81 if (ext & (1<<(TCPDIAG_INFO-1)))
82 info = TCPDIAG_PUT(skb, TCPDIAG_INFO,
83 handler->idiag_info_size);
85 if ((ext & (1 << (TCPDIAG_CONG - 1))) && icsk->icsk_ca_ops) {
86 size_t len = strlen(icsk->icsk_ca_ops->name);
87 strcpy(TCPDIAG_PUT(skb, TCPDIAG_CONG, len+1),
88 icsk->icsk_ca_ops->name);
91 r->tcpdiag_family = sk->sk_family;
92 r->tcpdiag_state = sk->sk_state;
94 r->tcpdiag_retrans = 0;
96 r->id.tcpdiag_if = sk->sk_bound_dev_if;
97 r->id.tcpdiag_cookie[0] = (u32)(unsigned long)sk;
98 r->id.tcpdiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
100 if (r->tcpdiag_state == TCP_TIME_WAIT) {
101 const struct inet_timewait_sock *tw = inet_twsk(sk);
102 long tmo = tw->tw_ttd - jiffies;
106 r->id.tcpdiag_sport = tw->tw_sport;
107 r->id.tcpdiag_dport = tw->tw_dport;
108 r->id.tcpdiag_src[0] = tw->tw_rcv_saddr;
109 r->id.tcpdiag_dst[0] = tw->tw_daddr;
110 r->tcpdiag_state = tw->tw_substate;
111 r->tcpdiag_timer = 3;
112 r->tcpdiag_expires = (tmo*1000+HZ-1)/HZ;
113 r->tcpdiag_rqueue = 0;
114 r->tcpdiag_wqueue = 0;
116 r->tcpdiag_inode = 0;
117 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
118 if (r->tcpdiag_family == AF_INET6) {
119 const struct tcp6_timewait_sock *tcp6tw = tcp6_twsk(sk);
121 ipv6_addr_copy((struct in6_addr *)r->id.tcpdiag_src,
122 &tcp6tw->tw_v6_rcv_saddr);
123 ipv6_addr_copy((struct in6_addr *)r->id.tcpdiag_dst,
124 &tcp6tw->tw_v6_daddr);
127 nlh->nlmsg_len = skb->tail - b;
131 r->id.tcpdiag_sport = inet->sport;
132 r->id.tcpdiag_dport = inet->dport;
133 r->id.tcpdiag_src[0] = inet->rcv_saddr;
134 r->id.tcpdiag_dst[0] = inet->daddr;
136 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
137 if (r->tcpdiag_family == AF_INET6) {
138 struct ipv6_pinfo *np = inet6_sk(sk);
140 ipv6_addr_copy((struct in6_addr *)r->id.tcpdiag_src,
142 ipv6_addr_copy((struct in6_addr *)r->id.tcpdiag_dst,
147 #define EXPIRES_IN_MS(tmo) ((tmo-jiffies)*1000+HZ-1)/HZ
149 if (icsk->icsk_pending == ICSK_TIME_RETRANS) {
150 r->tcpdiag_timer = 1;
151 r->tcpdiag_retrans = icsk->icsk_retransmits;
152 r->tcpdiag_expires = EXPIRES_IN_MS(icsk->icsk_timeout);
153 } else if (icsk->icsk_pending == ICSK_TIME_PROBE0) {
154 r->tcpdiag_timer = 4;
155 r->tcpdiag_retrans = icsk->icsk_probes_out;
156 r->tcpdiag_expires = EXPIRES_IN_MS(icsk->icsk_timeout);
157 } else if (timer_pending(&sk->sk_timer)) {
158 r->tcpdiag_timer = 2;
159 r->tcpdiag_retrans = icsk->icsk_probes_out;
160 r->tcpdiag_expires = EXPIRES_IN_MS(sk->sk_timer.expires);
162 r->tcpdiag_timer = 0;
163 r->tcpdiag_expires = 0;
167 r->tcpdiag_uid = sock_i_uid(sk);
168 r->tcpdiag_inode = sock_i_ino(sk);
171 minfo->tcpdiag_rmem = atomic_read(&sk->sk_rmem_alloc);
172 minfo->tcpdiag_wmem = sk->sk_wmem_queued;
173 minfo->tcpdiag_fmem = sk->sk_forward_alloc;
174 minfo->tcpdiag_tmem = atomic_read(&sk->sk_wmem_alloc);
177 handler->idiag_get_info(sk, r, info);
179 if (sk->sk_state < TCP_TIME_WAIT &&
180 icsk->icsk_ca_ops && icsk->icsk_ca_ops->get_info)
181 icsk->icsk_ca_ops->get_info(sk, ext, skb);
183 nlh->nlmsg_len = skb->tail - b;
188 skb_trim(skb, b - skb->data);
192 static int tcpdiag_get_exact(struct sk_buff *in_skb, const struct nlmsghdr *nlh)
196 struct tcpdiagreq *req = NLMSG_DATA(nlh);
198 struct inet_hashinfo *hashinfo;
199 const struct inet_diag_handler *handler;
201 handler = inet_diag_table[nlh->nlmsg_type];
202 BUG_ON(handler == NULL);
203 hashinfo = handler->idiag_hashinfo;
205 if (req->tcpdiag_family == AF_INET) {
206 sk = inet_lookup(hashinfo, req->id.tcpdiag_dst[0],
207 req->id.tcpdiag_dport, req->id.tcpdiag_src[0],
208 req->id.tcpdiag_sport, req->id.tcpdiag_if);
210 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
211 else if (req->tcpdiag_family == AF_INET6) {
212 sk = inet6_lookup(hashinfo,
213 (struct in6_addr*)req->id.tcpdiag_dst,
214 req->id.tcpdiag_dport,
215 (struct in6_addr*)req->id.tcpdiag_src,
216 req->id.tcpdiag_sport,
228 if ((req->id.tcpdiag_cookie[0] != TCPDIAG_NOCOOKIE ||
229 req->id.tcpdiag_cookie[1] != TCPDIAG_NOCOOKIE) &&
230 ((u32)(unsigned long)sk != req->id.tcpdiag_cookie[0] ||
231 (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.tcpdiag_cookie[1]))
235 rep = alloc_skb(NLMSG_SPACE((sizeof(struct tcpdiagmsg) +
236 sizeof(struct tcpdiag_meminfo) +
237 handler->idiag_info_size + 64)),
242 if (tcpdiag_fill(rep, sk, req->tcpdiag_ext,
243 NETLINK_CB(in_skb).pid,
244 nlh->nlmsg_seq, 0, nlh) <= 0)
247 err = netlink_unicast(tcpnl, rep, NETLINK_CB(in_skb).pid, MSG_DONTWAIT);
253 if (sk->sk_state == TCP_TIME_WAIT)
254 inet_twsk_put((struct inet_timewait_sock *)sk);
261 static int bitstring_match(const u32 *a1, const u32 *a2, int bits)
263 int words = bits >> 5;
268 if (memcmp(a1, a2, words << 2))
278 mask = htonl((0xffffffff) << (32 - bits));
280 if ((w1 ^ w2) & mask)
288 static int tcpdiag_bc_run(const void *bc, int len,
289 const struct tcpdiag_entry *entry)
293 const struct tcpdiag_bc_op *op = bc;
301 case TCPDIAG_BC_S_GE:
302 yes = entry->sport >= op[1].no;
304 case TCPDIAG_BC_S_LE:
305 yes = entry->dport <= op[1].no;
307 case TCPDIAG_BC_D_GE:
308 yes = entry->dport >= op[1].no;
310 case TCPDIAG_BC_D_LE:
311 yes = entry->dport <= op[1].no;
313 case TCPDIAG_BC_AUTO:
314 yes = !(entry->userlocks & SOCK_BINDPORT_LOCK);
316 case TCPDIAG_BC_S_COND:
317 case TCPDIAG_BC_D_COND:
319 struct tcpdiag_hostcond *cond = (struct tcpdiag_hostcond*)(op+1);
322 if (cond->port != -1 &&
323 cond->port != (op->code == TCPDIAG_BC_S_COND ?
324 entry->sport : entry->dport)) {
329 if (cond->prefix_len == 0)
332 if (op->code == TCPDIAG_BC_S_COND)
337 if (bitstring_match(addr, cond->addr, cond->prefix_len))
339 if (entry->family == AF_INET6 &&
340 cond->family == AF_INET) {
341 if (addr[0] == 0 && addr[1] == 0 &&
342 addr[2] == htonl(0xffff) &&
343 bitstring_match(addr+3, cond->addr, cond->prefix_len))
362 static int valid_cc(const void *bc, int len, int cc)
365 const struct tcpdiag_bc_op *op = bc;
379 static int tcpdiag_bc_audit(const void *bytecode, int bytecode_len)
381 const unsigned char *bc = bytecode;
382 int len = bytecode_len;
385 struct tcpdiag_bc_op *op = (struct tcpdiag_bc_op*)bc;
387 //printk("BC: %d %d %d {%d} / %d\n", op->code, op->yes, op->no, op[1].no, len);
389 case TCPDIAG_BC_AUTO:
390 case TCPDIAG_BC_S_COND:
391 case TCPDIAG_BC_D_COND:
392 case TCPDIAG_BC_S_GE:
393 case TCPDIAG_BC_S_LE:
394 case TCPDIAG_BC_D_GE:
395 case TCPDIAG_BC_D_LE:
396 if (op->yes < 4 || op->yes > len+4)
399 if (op->no < 4 || op->no > len+4)
402 !valid_cc(bytecode, bytecode_len, len-op->no))
406 if (op->yes < 4 || op->yes > len+4)
415 return len == 0 ? 0 : -EINVAL;
418 static int tcpdiag_dump_sock(struct sk_buff *skb, struct sock *sk,
419 struct netlink_callback *cb)
421 struct tcpdiagreq *r = NLMSG_DATA(cb->nlh);
423 if (cb->nlh->nlmsg_len > 4 + NLMSG_SPACE(sizeof(*r))) {
424 struct tcpdiag_entry entry;
425 struct rtattr *bc = (struct rtattr *)(r + 1);
426 struct inet_sock *inet = inet_sk(sk);
428 entry.family = sk->sk_family;
429 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
430 if (entry.family == AF_INET6) {
431 struct ipv6_pinfo *np = inet6_sk(sk);
433 entry.saddr = np->rcv_saddr.s6_addr32;
434 entry.daddr = np->daddr.s6_addr32;
438 entry.saddr = &inet->rcv_saddr;
439 entry.daddr = &inet->daddr;
441 entry.sport = inet->num;
442 entry.dport = ntohs(inet->dport);
443 entry.userlocks = sk->sk_userlocks;
445 if (!tcpdiag_bc_run(RTA_DATA(bc), RTA_PAYLOAD(bc), &entry))
449 return tcpdiag_fill(skb, sk, r->tcpdiag_ext, NETLINK_CB(cb->skb).pid,
450 cb->nlh->nlmsg_seq, NLM_F_MULTI, cb->nlh);
453 static int tcpdiag_fill_req(struct sk_buff *skb, struct sock *sk,
454 struct request_sock *req,
456 const struct nlmsghdr *unlh)
458 const struct inet_request_sock *ireq = inet_rsk(req);
459 struct inet_sock *inet = inet_sk(sk);
460 unsigned char *b = skb->tail;
461 struct tcpdiagmsg *r;
462 struct nlmsghdr *nlh;
465 nlh = NLMSG_PUT(skb, pid, seq, unlh->nlmsg_type, sizeof(*r));
466 nlh->nlmsg_flags = NLM_F_MULTI;
469 r->tcpdiag_family = sk->sk_family;
470 r->tcpdiag_state = TCP_SYN_RECV;
471 r->tcpdiag_timer = 1;
472 r->tcpdiag_retrans = req->retrans;
474 r->id.tcpdiag_if = sk->sk_bound_dev_if;
475 r->id.tcpdiag_cookie[0] = (u32)(unsigned long)req;
476 r->id.tcpdiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
478 tmo = req->expires - jiffies;
482 r->id.tcpdiag_sport = inet->sport;
483 r->id.tcpdiag_dport = ireq->rmt_port;
484 r->id.tcpdiag_src[0] = ireq->loc_addr;
485 r->id.tcpdiag_dst[0] = ireq->rmt_addr;
486 r->tcpdiag_expires = jiffies_to_msecs(tmo),
487 r->tcpdiag_rqueue = 0;
488 r->tcpdiag_wqueue = 0;
489 r->tcpdiag_uid = sock_i_uid(sk);
490 r->tcpdiag_inode = 0;
491 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
492 if (r->tcpdiag_family == AF_INET6) {
493 ipv6_addr_copy((struct in6_addr *)r->id.tcpdiag_src,
494 &tcp6_rsk(req)->loc_addr);
495 ipv6_addr_copy((struct in6_addr *)r->id.tcpdiag_dst,
496 &tcp6_rsk(req)->rmt_addr);
499 nlh->nlmsg_len = skb->tail - b;
504 skb_trim(skb, b - skb->data);
508 static int tcpdiag_dump_reqs(struct sk_buff *skb, struct sock *sk,
509 struct netlink_callback *cb)
511 struct tcpdiag_entry entry;
512 struct tcpdiagreq *r = NLMSG_DATA(cb->nlh);
513 struct inet_connection_sock *icsk = inet_csk(sk);
514 struct listen_sock *lopt;
515 struct rtattr *bc = NULL;
516 struct inet_sock *inet = inet_sk(sk);
518 int reqnum, s_reqnum;
522 s_reqnum = cb->args[4];
527 entry.family = sk->sk_family;
529 read_lock_bh(&icsk->icsk_accept_queue.syn_wait_lock);
531 lopt = icsk->icsk_accept_queue.listen_opt;
532 if (!lopt || !lopt->qlen)
535 if (cb->nlh->nlmsg_len > 4 + NLMSG_SPACE(sizeof(*r))) {
536 bc = (struct rtattr *)(r + 1);
537 entry.sport = inet->num;
538 entry.userlocks = sk->sk_userlocks;
541 for (j = s_j; j < lopt->nr_table_entries; j++) {
542 struct request_sock *req, *head = lopt->syn_table[j];
545 for (req = head; req; reqnum++, req = req->dl_next) {
546 struct inet_request_sock *ireq = inet_rsk(req);
548 if (reqnum < s_reqnum)
550 if (r->id.tcpdiag_dport != ireq->rmt_port &&
556 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
557 (entry.family == AF_INET6) ?
558 tcp6_rsk(req)->loc_addr.s6_addr32 :
562 #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
563 (entry.family == AF_INET6) ?
564 tcp6_rsk(req)->rmt_addr.s6_addr32 :
567 entry.dport = ntohs(ireq->rmt_port);
569 if (!tcpdiag_bc_run(RTA_DATA(bc),
570 RTA_PAYLOAD(bc), &entry))
574 err = tcpdiag_fill_req(skb, sk, req,
575 NETLINK_CB(cb->skb).pid,
576 cb->nlh->nlmsg_seq, cb->nlh);
579 cb->args[4] = reqnum;
588 read_unlock_bh(&icsk->icsk_accept_queue.syn_wait_lock);
593 static int tcpdiag_dump(struct sk_buff *skb, struct netlink_callback *cb)
597 struct tcpdiagreq *r = NLMSG_DATA(cb->nlh);
598 const struct inet_diag_handler *handler;
599 struct inet_hashinfo *hashinfo;
601 handler = inet_diag_table[cb->nlh->nlmsg_type];
602 BUG_ON(handler == NULL);
603 hashinfo = handler->idiag_hashinfo;
606 s_num = num = cb->args[2];
608 if (cb->args[0] == 0) {
609 if (!(r->tcpdiag_states&(TCPF_LISTEN|TCPF_SYN_RECV)))
612 inet_listen_lock(hashinfo);
613 for (i = s_i; i < INET_LHTABLE_SIZE; i++) {
615 struct hlist_node *node;
618 sk_for_each(sk, node, &hashinfo->listening_hash[i]) {
619 struct inet_sock *inet = inet_sk(sk);
626 if (r->id.tcpdiag_sport != inet->sport &&
630 if (!(r->tcpdiag_states&TCPF_LISTEN) ||
631 r->id.tcpdiag_dport ||
635 if (tcpdiag_dump_sock(skb, sk, cb) < 0) {
636 inet_listen_unlock(hashinfo);
641 if (!(r->tcpdiag_states&TCPF_SYN_RECV))
644 if (tcpdiag_dump_reqs(skb, sk, cb) < 0) {
645 inet_listen_unlock(hashinfo);
659 inet_listen_unlock(hashinfo);
662 s_i = num = s_num = 0;
665 if (!(r->tcpdiag_states&~(TCPF_LISTEN|TCPF_SYN_RECV)))
668 for (i = s_i; i < hashinfo->ehash_size; i++) {
669 struct inet_ehash_bucket *head = &hashinfo->ehash[i];
671 struct hlist_node *node;
676 read_lock_bh(&head->lock);
679 sk_for_each(sk, node, &head->chain) {
680 struct inet_sock *inet = inet_sk(sk);
684 if (!(r->tcpdiag_states & (1 << sk->sk_state)))
686 if (r->id.tcpdiag_sport != inet->sport &&
689 if (r->id.tcpdiag_dport != inet->dport && r->id.tcpdiag_dport)
691 if (tcpdiag_dump_sock(skb, sk, cb) < 0) {
692 read_unlock_bh(&head->lock);
699 if (r->tcpdiag_states&TCPF_TIME_WAIT) {
700 sk_for_each(sk, node,
701 &hashinfo->ehash[i + hashinfo->ehash_size].chain) {
702 struct inet_sock *inet = inet_sk(sk);
706 if (r->id.tcpdiag_sport != inet->sport &&
709 if (r->id.tcpdiag_dport != inet->dport &&
712 if (tcpdiag_dump_sock(skb, sk, cb) < 0) {
713 read_unlock_bh(&head->lock);
720 read_unlock_bh(&head->lock);
729 static int tcpdiag_dump_done(struct netlink_callback *cb)
735 static __inline__ int
736 tcpdiag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
738 if (!(nlh->nlmsg_flags&NLM_F_REQUEST))
741 if (nlh->nlmsg_type >= INET_DIAG_GETSOCK_MAX)
744 if (inet_diag_table[nlh->nlmsg_type] == NULL)
747 if (NLMSG_LENGTH(sizeof(struct tcpdiagreq)) > skb->len)
750 if (nlh->nlmsg_flags&NLM_F_DUMP) {
751 if (nlh->nlmsg_len > 4 + NLMSG_SPACE(sizeof(struct tcpdiagreq))) {
752 struct rtattr *rta = (struct rtattr*)(NLMSG_DATA(nlh) + sizeof(struct tcpdiagreq));
753 if (rta->rta_type != TCPDIAG_REQ_BYTECODE ||
755 rta->rta_len > nlh->nlmsg_len - NLMSG_SPACE(sizeof(struct tcpdiagreq)))
757 if (tcpdiag_bc_audit(RTA_DATA(rta), RTA_PAYLOAD(rta)))
760 return netlink_dump_start(tcpnl, skb, nlh,
764 return tcpdiag_get_exact(skb, nlh);
772 static inline void tcpdiag_rcv_skb(struct sk_buff *skb)
775 struct nlmsghdr * nlh;
777 if (skb->len >= NLMSG_SPACE(0)) {
778 nlh = (struct nlmsghdr *)skb->data;
779 if (nlh->nlmsg_len < sizeof(*nlh) || skb->len < nlh->nlmsg_len)
781 err = tcpdiag_rcv_msg(skb, nlh);
782 if (err || nlh->nlmsg_flags & NLM_F_ACK)
783 netlink_ack(skb, nlh, err);
787 static void tcpdiag_rcv(struct sock *sk, int len)
790 unsigned int qlen = skb_queue_len(&sk->sk_receive_queue);
792 while (qlen-- && (skb = skb_dequeue(&sk->sk_receive_queue))) {
793 tcpdiag_rcv_skb(skb);
798 static void tcp_diag_get_info(struct sock *sk, struct tcpdiagmsg *r,
801 const struct tcp_sock *tp = tcp_sk(sk);
802 struct tcp_info *info = _info;
804 r->tcpdiag_rqueue = tp->rcv_nxt - tp->copied_seq;
805 r->tcpdiag_wqueue = tp->write_seq - tp->snd_una;
807 tcp_get_info(sk, info);
810 static struct inet_diag_handler tcp_diag_handler = {
811 .idiag_hashinfo = &tcp_hashinfo,
812 .idiag_get_info = tcp_diag_get_info,
813 .idiag_type = TCPDIAG_GETSOCK,
814 .idiag_info_size = sizeof(struct tcp_info),
817 static DEFINE_SPINLOCK(inet_diag_register_lock);
819 int inet_diag_register(const struct inet_diag_handler *h)
821 const __u16 type = h->idiag_type;
824 if (type >= INET_DIAG_GETSOCK_MAX)
827 spin_lock(&inet_diag_register_lock);
829 if (inet_diag_table[type] == NULL) {
830 inet_diag_table[type] = h;
833 spin_unlock(&inet_diag_register_lock);
837 EXPORT_SYMBOL_GPL(inet_diag_register);
839 void inet_diag_unregister(const struct inet_diag_handler *h)
841 const __u16 type = h->idiag_type;
843 if (type >= INET_DIAG_GETSOCK_MAX)
846 spin_lock(&inet_diag_register_lock);
847 inet_diag_table[type] = NULL;
848 spin_unlock(&inet_diag_register_lock);
852 EXPORT_SYMBOL_GPL(inet_diag_unregister);
854 static int __init tcpdiag_init(void)
856 const int inet_diag_table_size = (INET_DIAG_GETSOCK_MAX *
857 sizeof(struct inet_diag_handler *));
860 inet_diag_table = kmalloc(inet_diag_table_size, GFP_KERNEL);
861 if (!inet_diag_table)
864 memset(inet_diag_table, 0, inet_diag_table_size);
866 tcpnl = netlink_kernel_create(NETLINK_TCPDIAG, tcpdiag_rcv,
871 err = inet_diag_register(&tcp_diag_handler);
873 goto out_sock_release;
877 sock_release(tcpnl->sk_socket);
879 kfree(inet_diag_table);
883 static void __exit tcpdiag_exit(void)
885 sock_release(tcpnl->sk_socket);
886 kfree(inet_diag_table);
889 module_init(tcpdiag_init);
890 module_exit(tcpdiag_exit);
891 MODULE_LICENSE("GPL");