[NETFILTER]: Replate direct proc_fops assignment with proc_create call.
[safe/jmp/linux-2.6] / net / netfilter / nf_conntrack_standalone.c
index 2ad4933..8599068 100644 (file)
@@ -31,8 +31,8 @@ MODULE_LICENSE("GPL");
 #ifdef CONFIG_PROC_FS
 int
 print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple,
-           struct nf_conntrack_l3proto *l3proto,
-           struct nf_conntrack_l4proto *l4proto)
+            const struct nf_conntrack_l3proto *l3proto,
+            const struct nf_conntrack_l4proto *l4proto)
 {
        return l3proto->print_tuple(s, tuple) || l4proto->print_tuple(s, tuple);
 }
@@ -58,12 +58,14 @@ struct ct_iter_state {
 static struct hlist_node *ct_get_first(struct seq_file *seq)
 {
        struct ct_iter_state *st = seq->private;
+       struct hlist_node *n;
 
        for (st->bucket = 0;
             st->bucket < nf_conntrack_htable_size;
             st->bucket++) {
-               if (!hlist_empty(&nf_conntrack_hash[st->bucket]))
-                       return nf_conntrack_hash[st->bucket].first;
+               n = rcu_dereference(nf_conntrack_hash[st->bucket].first);
+               if (n)
+                       return n;
        }
        return NULL;
 }
@@ -73,11 +75,11 @@ static struct hlist_node *ct_get_next(struct seq_file *seq,
 {
        struct ct_iter_state *st = seq->private;
 
-       head = head->next;
+       head = rcu_dereference(head->next);
        while (head == NULL) {
                if (++st->bucket >= nf_conntrack_htable_size)
                        return NULL;
-               head = nf_conntrack_hash[st->bucket].first;
+               head = rcu_dereference(nf_conntrack_hash[st->bucket].first);
        }
        return head;
 }
@@ -93,8 +95,9 @@ static struct hlist_node *ct_get_idx(struct seq_file *seq, loff_t pos)
 }
 
 static void *ct_seq_start(struct seq_file *seq, loff_t *pos)
+       __acquires(RCU)
 {
-       read_lock_bh(&nf_conntrack_lock);
+       rcu_read_lock();
        return ct_get_idx(seq, *pos);
 }
 
@@ -105,82 +108,80 @@ static void *ct_seq_next(struct seq_file *s, void *v, loff_t *pos)
 }
 
 static void ct_seq_stop(struct seq_file *s, void *v)
+       __releases(RCU)
 {
-       read_unlock_bh(&nf_conntrack_lock);
+       rcu_read_unlock();
 }
 
 /* return 0 on success, 1 in case of error */
 static int ct_seq_show(struct seq_file *s, void *v)
 {
        const struct nf_conntrack_tuple_hash *hash = v;
-       const struct nf_conn *conntrack = nf_ct_tuplehash_to_ctrack(hash);
-       struct nf_conntrack_l3proto *l3proto;
-       struct nf_conntrack_l4proto *l4proto;
+       const struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(hash);
+       const struct nf_conntrack_l3proto *l3proto;
+       const struct nf_conntrack_l4proto *l4proto;
 
-       NF_CT_ASSERT(conntrack);
+       NF_CT_ASSERT(ct);
 
        /* we only want to print DIR_ORIGINAL */
        if (NF_CT_DIRECTION(hash))
                return 0;
 
-       l3proto = __nf_ct_l3proto_find(conntrack->tuplehash[IP_CT_DIR_ORIGINAL]
+       l3proto = __nf_ct_l3proto_find(ct->tuplehash[IP_CT_DIR_ORIGINAL]
                                       .tuple.src.l3num);
 
        NF_CT_ASSERT(l3proto);
-       l4proto = __nf_ct_l4proto_find(conntrack->tuplehash[IP_CT_DIR_ORIGINAL]
+       l4proto = __nf_ct_l4proto_find(ct->tuplehash[IP_CT_DIR_ORIGINAL]
                                   .tuple.src.l3num,
-                                  conntrack->tuplehash[IP_CT_DIR_ORIGINAL]
+                                  ct->tuplehash[IP_CT_DIR_ORIGINAL]
                                   .tuple.dst.protonum);
        NF_CT_ASSERT(l4proto);
 
        if (seq_printf(s, "%-8s %u %-8s %u %ld ",
                       l3proto->name,
-                      conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num,
+                      ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num,
                       l4proto->name,
-                      conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum,
-                      timer_pending(&conntrack->timeout)
-                      ? (long)(conntrack->timeout.expires - jiffies)/HZ : 0) != 0)
+                      ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum,
+                      timer_pending(&ct->timeout)
+                      ? (long)(ct->timeout.expires - jiffies)/HZ : 0) != 0)
                return -ENOSPC;
 
-       if (l3proto->print_conntrack(s, conntrack))
+       if (l4proto->print_conntrack && l4proto->print_conntrack(s, ct))
                return -ENOSPC;
 
-       if (l4proto->print_conntrack(s, conntrack))
-               return -ENOSPC;
-
-       if (print_tuple(s, &conntrack->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
+       if (print_tuple(s, &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
                        l3proto, l4proto))
                return -ENOSPC;
 
-       if (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_ORIGINAL]))
+       if (seq_print_counters(s, &ct->counters[IP_CT_DIR_ORIGINAL]))
                return -ENOSPC;
 
-       if (!(test_bit(IPS_SEEN_REPLY_BIT, &conntrack->status)))
+       if (!(test_bit(IPS_SEEN_REPLY_BIT, &ct->status)))
                if (seq_printf(s, "[UNREPLIED] "))
                        return -ENOSPC;
 
-       if (print_tuple(s, &conntrack->tuplehash[IP_CT_DIR_REPLY].tuple,
+       if (print_tuple(s, &ct->tuplehash[IP_CT_DIR_REPLY].tuple,
                        l3proto, l4proto))
                return -ENOSPC;
 
-       if (seq_print_counters(s, &conntrack->counters[IP_CT_DIR_REPLY]))
+       if (seq_print_counters(s, &ct->counters[IP_CT_DIR_REPLY]))
                return -ENOSPC;
 
-       if (test_bit(IPS_ASSURED_BIT, &conntrack->status))
+       if (test_bit(IPS_ASSURED_BIT, &ct->status))
                if (seq_printf(s, "[ASSURED] "))
                        return -ENOSPC;
 
 #if defined(CONFIG_NF_CONNTRACK_MARK)
-       if (seq_printf(s, "mark=%u ", conntrack->mark))
+       if (seq_printf(s, "mark=%u ", ct->mark))
                return -ENOSPC;
 #endif
 
 #ifdef CONFIG_NF_CONNTRACK_SECMARK
-       if (seq_printf(s, "secmark=%u ", conntrack->secmark))
+       if (seq_printf(s, "secmark=%u ", ct->secmark))
                return -ENOSPC;
 #endif
 
-       if (seq_printf(s, "use=%u\n", atomic_read(&conntrack->ct_general.use)))
+       if (seq_printf(s, "use=%u\n", atomic_read(&ct->ct_general.use)))
                return -ENOSPC;
 
        return 0;
@@ -245,7 +246,7 @@ static void ct_cpu_seq_stop(struct seq_file *seq, void *v)
 static int ct_cpu_seq_show(struct seq_file *seq, void *v)
 {
        unsigned int nr_conntracks = atomic_read(&nf_conntrack_count);
-       struct ip_conntrack_stat *st = v;
+       const struct ip_conntrack_stat *st = v;
 
        if (v == SEQ_START_TOKEN) {
                seq_printf(seq, "entries  searched found new invalid ignore delete delete_list insert insert_failed drop early_drop icmp_error  expect_new expect_create expect_delete\n");
@@ -383,7 +384,7 @@ static ctl_table nf_ct_netfilter_table[] = {
        { .ctl_name = 0 }
 };
 
-struct ctl_path nf_ct_path[] = {
+static struct ctl_path nf_ct_path[] = {
        { .procname = "net", .ctl_name = CTL_NET, },
        { }
 };
@@ -394,7 +395,7 @@ EXPORT_SYMBOL_GPL(nf_ct_log_invalid);
 static int __init nf_conntrack_standalone_init(void)
 {
 #ifdef CONFIG_PROC_FS
-       struct proc_dir_entry *proc, *proc_stat;
+       struct proc_dir_entry *proc;
 #endif
        int ret = 0;
 
@@ -406,12 +407,9 @@ static int __init nf_conntrack_standalone_init(void)
        proc = proc_net_fops_create(&init_net, "nf_conntrack", 0440, &ct_file_ops);
        if (!proc) goto cleanup_init;
 
-       proc_stat = create_proc_entry("nf_conntrack", S_IRUGO, init_net.proc_net_stat);
-       if (!proc_stat)
+       if (!proc_create("nf_conntrack", S_IRUGO,
+                        init_net.proc_net_stat, &ct_cpu_seq_fops))
                goto cleanup_proc;
-
-       proc_stat->proc_fops = &ct_cpu_seq_fops;
-       proc_stat->owner = THIS_MODULE;
 #endif
 #ifdef CONFIG_SYSCTL
        nf_ct_sysctl_header = register_sysctl_paths(nf_ct_path,