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