Merge branch 'merge' of git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc
[sfrench/cifs-2.6.git] / net / ipv4 / inet_diag.c
index 985c5730e4fb6ccd0a83804c56b8de3c4b3e5dbe..77761ac4f7bb0589bc22d89127e3d64abb14c65a 100644 (file)
@@ -11,7 +11,6 @@
  *      2 of the License, or (at your option) any later version.
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/fcntl.h>
@@ -37,8 +36,8 @@
 static const struct inet_diag_handler **inet_diag_table;
 
 struct inet_diag_entry {
-       u32 *saddr;
-       u32 *daddr;
+       __be32 *saddr;
+       __be32 *daddr;
        u16 sport;
        u16 dport;
        u16 family;
@@ -50,9 +49,10 @@ static struct sock *idiagnl;
 #define INET_DIAG_PUT(skb, attrtype, attrlen) \
        RTA_DATA(__RTA_PUT(skb, attrtype, attrlen))
 
-static int inet_diag_fill(struct sk_buff *skb, struct sock *sk,
-                         int ext, u32 pid, u32 seq, u16 nlmsg_flags,
-                         const struct nlmsghdr *unlh)
+static int inet_csk_diag_fill(struct sock *sk,
+                             struct sk_buff *skb,
+                             int ext, u32 pid, u32 seq, u16 nlmsg_flags,
+                             const struct nlmsghdr *unlh)
 {
        const struct inet_sock *inet = inet_sk(sk);
        const struct inet_connection_sock *icsk = inet_csk(sk);
@@ -212,6 +212,17 @@ nlmsg_failure:
        return -1;
 }
 
+static int sk_diag_fill(struct sock *sk, struct sk_buff *skb,
+                       int ext, u32 pid, u32 seq, u16 nlmsg_flags,
+                       const struct nlmsghdr *unlh)
+{
+       if (sk->sk_state == TCP_TIME_WAIT)
+               return inet_twsk_diag_fill((struct inet_timewait_sock *)sk,
+                                          skb, ext, pid, seq, nlmsg_flags,
+                                          unlh);
+       return inet_csk_diag_fill(sk, skb, ext, pid, seq, nlmsg_flags, unlh);
+}
+
 static int inet_diag_get_exact(struct sk_buff *in_skb,
                               const struct nlmsghdr *nlh)
 {
@@ -263,7 +274,7 @@ static int inet_diag_get_exact(struct sk_buff *in_skb,
        if (!rep)
                goto out;
 
-       if (inet_diag_fill(rep, sk, req->idiag_ext,
+       if (sk_diag_fill(sk, rep, req->idiag_ext,
                         NETLINK_CB(in_skb).pid,
                         nlh->nlmsg_seq, 0, nlh) <= 0)
                BUG();
@@ -283,7 +294,7 @@ out:
        return err;
 }
 
-static int bitstring_match(const u32 *a1, const u32 *a2, int bits)
+static int bitstring_match(const __be32 *a1, const __be32 *a2, int bits)
 {
        int words = bits >> 5;
 
@@ -294,8 +305,8 @@ static int bitstring_match(const u32 *a1, const u32 *a2, int bits)
                        return 0;
        }
        if (bits) {
-               __u32 w1, w2;
-               __u32 mask;
+               __be32 w1, w2;
+               __be32 mask;
 
                w1 = a1[words];
                w2 = a2[words];
@@ -341,7 +352,7 @@ static int inet_diag_bc_run(const void *bc, int len,
                case INET_DIAG_BC_S_COND:
                case INET_DIAG_BC_D_COND: {
                        struct inet_diag_hostcond *cond;
-                       u32 *addr;
+                       __be32 *addr;
 
                        cond = (struct inet_diag_hostcond *)(op + 1);
                        if (cond->port != -1 &&
@@ -442,8 +453,9 @@ static int inet_diag_bc_audit(const void *bytecode, int bytecode_len)
        return len == 0 ? 0 : -EINVAL;
 }
 
-static int inet_diag_dump_sock(struct sk_buff *skb, struct sock *sk,
-                              struct netlink_callback *cb)
+static int inet_csk_diag_dump(struct sock *sk,
+                             struct sk_buff *skb,
+                             struct netlink_callback *cb)
 {
        struct inet_diag_req *r = NLMSG_DATA(cb->nlh);
 
@@ -473,8 +485,9 @@ static int inet_diag_dump_sock(struct sk_buff *skb, struct sock *sk,
                        return 0;
        }
 
-       return inet_diag_fill(skb, sk, r->idiag_ext, NETLINK_CB(cb->skb).pid,
-                             cb->nlh->nlmsg_seq, NLM_F_MULTI, cb->nlh);
+       return inet_csk_diag_fill(sk, skb, r->idiag_ext,
+                                 NETLINK_CB(cb->skb).pid,
+                                 cb->nlh->nlmsg_seq, NLM_F_MULTI, cb->nlh);
 }
 
 static int inet_twsk_diag_dump(struct inet_timewait_sock *tw,
@@ -694,7 +707,7 @@ static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
                                    cb->args[3] > 0)
                                        goto syn_recv;
 
-                               if (inet_diag_dump_sock(skb, sk, cb) < 0) {
+                               if (inet_csk_diag_dump(sk, skb, cb) < 0) {
                                        inet_listen_unlock(hashinfo);
                                        goto done;
                                }
@@ -750,7 +763,7 @@ skip_listen_ht:
                        if (r->id.idiag_dport != inet->dport &&
                            r->id.idiag_dport)
                                goto next_normal;
-                       if (inet_diag_dump_sock(skb, sk, cb) < 0) {
+                       if (inet_csk_diag_dump(sk, skb, cb) < 0) {
                                read_unlock_bh(&head->lock);
                                goto done;
                        }
@@ -896,11 +909,10 @@ static int __init inet_diag_init(void)
                                          sizeof(struct inet_diag_handler *));
        int err = -ENOMEM;
 
-       inet_diag_table = kmalloc(inet_diag_table_size, GFP_KERNEL);
+       inet_diag_table = kzalloc(inet_diag_table_size, GFP_KERNEL);
        if (!inet_diag_table)
                goto out;
 
-       memset(inet_diag_table, 0, inet_diag_table_size);
        idiagnl = netlink_kernel_create(NETLINK_INET_DIAG, 0, inet_diag_rcv,
                                        THIS_MODULE);
        if (idiagnl == NULL)