HWPOISON: mention HWPoison in Kconfig entry
[safe/jmp/linux-2.6] / net / netfilter / nf_conntrack_standalone.c
index 64b4f95..028aba6 100644 (file)
@@ -44,40 +44,42 @@ struct ct_iter_state {
        unsigned int bucket;
 };
 
-static struct hlist_node *ct_get_first(struct seq_file *seq)
+static struct hlist_nulls_node *ct_get_first(struct seq_file *seq)
 {
        struct net *net = seq_file_net(seq);
        struct ct_iter_state *st = seq->private;
-       struct hlist_node *n;
+       struct hlist_nulls_node *n;
 
        for (st->bucket = 0;
             st->bucket < nf_conntrack_htable_size;
             st->bucket++) {
                n = rcu_dereference(net->ct.hash[st->bucket].first);
-               if (n)
+               if (!is_a_nulls(n))
                        return n;
        }
        return NULL;
 }
 
-static struct hlist_node *ct_get_next(struct seq_file *seq,
-                                     struct hlist_node *head)
+static struct hlist_nulls_node *ct_get_next(struct seq_file *seq,
+                                     struct hlist_nulls_node *head)
 {
        struct net *net = seq_file_net(seq);
        struct ct_iter_state *st = seq->private;
 
        head = rcu_dereference(head->next);
-       while (head == NULL) {
-               if (++st->bucket >= nf_conntrack_htable_size)
-                       return NULL;
+       while (is_a_nulls(head)) {
+               if (likely(get_nulls_value(head) == st->bucket)) {
+                       if (++st->bucket >= nf_conntrack_htable_size)
+                               return NULL;
+               }
                head = rcu_dereference(net->ct.hash[st->bucket].first);
        }
        return head;
 }
 
-static struct hlist_node *ct_get_idx(struct seq_file *seq, loff_t pos)
+static struct hlist_nulls_node *ct_get_idx(struct seq_file *seq, loff_t pos)
 {
-       struct hlist_node *head = ct_get_first(seq);
+       struct hlist_nulls_node *head = ct_get_first(seq);
 
        if (head)
                while (pos && (head = ct_get_next(seq, head)))
@@ -107,67 +109,74 @@ static void ct_seq_stop(struct seq_file *s, void *v)
 /* 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 *ct = nf_ct_tuplehash_to_ctrack(hash);
+       struct nf_conntrack_tuple_hash *hash = v;
+       struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(hash);
        const struct nf_conntrack_l3proto *l3proto;
        const struct nf_conntrack_l4proto *l4proto;
+       int ret = 0;
 
        NF_CT_ASSERT(ct);
+       if (unlikely(!atomic_inc_not_zero(&ct->ct_general.use)))
+               return 0;
 
        /* we only want to print DIR_ORIGINAL */
        if (NF_CT_DIRECTION(hash))
-               return 0;
+               goto release;
 
        l3proto = __nf_ct_l3proto_find(nf_ct_l3num(ct));
        NF_CT_ASSERT(l3proto);
        l4proto = __nf_ct_l4proto_find(nf_ct_l3num(ct), nf_ct_protonum(ct));
        NF_CT_ASSERT(l4proto);
 
+       ret = -ENOSPC;
        if (seq_printf(s, "%-8s %u %-8s %u %ld ",
                       l3proto->name, nf_ct_l3num(ct),
                       l4proto->name, nf_ct_protonum(ct),
                       timer_pending(&ct->timeout)
                       ? (long)(ct->timeout.expires - jiffies)/HZ : 0) != 0)
-               return -ENOSPC;
+               goto release;
 
        if (l4proto->print_conntrack && l4proto->print_conntrack(s, ct))
-               return -ENOSPC;
+               goto release;
 
        if (print_tuple(s, &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple,
                        l3proto, l4proto))
-               return -ENOSPC;
+               goto release;
 
        if (seq_print_acct(s, ct, IP_CT_DIR_ORIGINAL))
-               return -ENOSPC;
+               goto release;
 
        if (!(test_bit(IPS_SEEN_REPLY_BIT, &ct->status)))
                if (seq_printf(s, "[UNREPLIED] "))
-                       return -ENOSPC;
+                       goto release;
 
        if (print_tuple(s, &ct->tuplehash[IP_CT_DIR_REPLY].tuple,
                        l3proto, l4proto))
-               return -ENOSPC;
+               goto release;
 
        if (seq_print_acct(s, ct, IP_CT_DIR_REPLY))
-               return -ENOSPC;
+               goto release;
 
        if (test_bit(IPS_ASSURED_BIT, &ct->status))
                if (seq_printf(s, "[ASSURED] "))
-                       return -ENOSPC;
+                       goto release;
 
 #if defined(CONFIG_NF_CONNTRACK_MARK)
        if (seq_printf(s, "mark=%u ", ct->mark))
-               return -ENOSPC;
+               goto release;
 #endif
 
 #ifdef CONFIG_NF_CONNTRACK_SECMARK
        if (seq_printf(s, "secmark=%u ", ct->secmark))
-               return -ENOSPC;
+               goto release;
 #endif
 
        if (seq_printf(s, "use=%u\n", atomic_read(&ct->ct_general.use)))
-               return -ENOSPC;
+               goto release;
 
+       ret = 0;
+release:
+       nf_ct_put(ct);
        return 0;
 }
 
@@ -200,7 +209,7 @@ static void *ct_cpu_seq_start(struct seq_file *seq, loff_t *pos)
        if (*pos == 0)
                return SEQ_START_TOKEN;
 
-       for (cpu = *pos-1; cpu < NR_CPUS; ++cpu) {
+       for (cpu = *pos-1; cpu < nr_cpu_ids; ++cpu) {
                if (!cpu_possible(cpu))
                        continue;
                *pos = cpu + 1;
@@ -215,7 +224,7 @@ static void *ct_cpu_seq_next(struct seq_file *seq, void *v, loff_t *pos)
        struct net *net = seq_file_net(seq);
        int cpu;
 
-       for (cpu = *pos; cpu < NR_CPUS; ++cpu) {
+       for (cpu = *pos; cpu < nr_cpu_ids; ++cpu) {
                if (!cpu_possible(cpu))
                        continue;
                *pos = cpu + 1;
@@ -322,9 +331,6 @@ static void nf_conntrack_standalone_fini_proc(struct net *net)
 
 /* Sysctl support */
 
-int nf_conntrack_checksum __read_mostly = 1;
-EXPORT_SYMBOL_GPL(nf_conntrack_checksum);
-
 #ifdef CONFIG_SYSCTL
 /* Log invalid packets of a given protocol */
 static int log_invalid_proto_min = 0;
@@ -334,80 +340,70 @@ static struct ctl_table_header *nf_ct_netfilter_header;
 
 static ctl_table nf_ct_sysctl_table[] = {
        {
-               .ctl_name       = NET_NF_CONNTRACK_MAX,
                .procname       = "nf_conntrack_max",
                .data           = &nf_conntrack_max,
                .maxlen         = sizeof(int),
                .mode           = 0644,
-               .proc_handler   = &proc_dointvec,
+               .proc_handler   = proc_dointvec,
        },
        {
-               .ctl_name       = NET_NF_CONNTRACK_COUNT,
                .procname       = "nf_conntrack_count",
                .data           = &init_net.ct.count,
                .maxlen         = sizeof(int),
                .mode           = 0444,
-               .proc_handler   = &proc_dointvec,
+               .proc_handler   = proc_dointvec,
        },
        {
-               .ctl_name       = NET_NF_CONNTRACK_BUCKETS,
                .procname       = "nf_conntrack_buckets",
                .data           = &nf_conntrack_htable_size,
                .maxlen         = sizeof(unsigned int),
                .mode           = 0444,
-               .proc_handler   = &proc_dointvec,
+               .proc_handler   = proc_dointvec,
        },
        {
-               .ctl_name       = NET_NF_CONNTRACK_CHECKSUM,
                .procname       = "nf_conntrack_checksum",
-               .data           = &nf_conntrack_checksum,
+               .data           = &init_net.ct.sysctl_checksum,
                .maxlen         = sizeof(unsigned int),
                .mode           = 0644,
-               .proc_handler   = &proc_dointvec,
+               .proc_handler   = proc_dointvec,
        },
        {
-               .ctl_name       = NET_NF_CONNTRACK_LOG_INVALID,
                .procname       = "nf_conntrack_log_invalid",
-               .data           = &nf_ct_log_invalid,
+               .data           = &init_net.ct.sysctl_log_invalid,
                .maxlen         = sizeof(unsigned int),
                .mode           = 0644,
-               .proc_handler   = &proc_dointvec_minmax,
-               .strategy       = &sysctl_intvec,
+               .proc_handler   = proc_dointvec_minmax,
                .extra1         = &log_invalid_proto_min,
                .extra2         = &log_invalid_proto_max,
        },
        {
-               .ctl_name       = CTL_UNNUMBERED,
                .procname       = "nf_conntrack_expect_max",
                .data           = &nf_ct_expect_max,
                .maxlen         = sizeof(int),
                .mode           = 0644,
-               .proc_handler   = &proc_dointvec,
+               .proc_handler   = proc_dointvec,
        },
-       { .ctl_name = 0 }
+       { }
 };
 
 #define NET_NF_CONNTRACK_MAX 2089
 
 static ctl_table nf_ct_netfilter_table[] = {
        {
-               .ctl_name       = NET_NF_CONNTRACK_MAX,
                .procname       = "nf_conntrack_max",
                .data           = &nf_conntrack_max,
                .maxlen         = sizeof(int),
                .mode           = 0644,
-               .proc_handler   = &proc_dointvec,
+               .proc_handler   = proc_dointvec,
        },
-       { .ctl_name = 0 }
+       { }
 };
 
 static struct ctl_path nf_ct_path[] = {
-       { .procname = "net", .ctl_name = CTL_NET, },
+       { .procname = "net", },
        { }
 };
 
-EXPORT_SYMBOL_GPL(nf_ct_log_invalid);
-
 static int nf_conntrack_standalone_init_sysctl(struct net *net)
 {
        struct ctl_table *table;
@@ -425,6 +421,8 @@ static int nf_conntrack_standalone_init_sysctl(struct net *net)
                goto out_kmemdup;
 
        table[1].data = &net->ct.count;
+       table[3].data = &net->ct.sysctl_checksum;
+       table[4].data = &net->ct.sysctl_log_invalid;
 
        net->ct.sysctl_header = register_net_sysctl_table(net,
                                        nf_net_netfilter_sysctl_path, table);
@@ -474,6 +472,8 @@ static int nf_conntrack_net_init(struct net *net)
        ret = nf_conntrack_standalone_init_proc(net);
        if (ret < 0)
                goto out_proc;
+       net->ct.sysctl_checksum = 1;
+       net->ct.sysctl_log_invalid = 0;
        ret = nf_conntrack_standalone_init_sysctl(net);
        if (ret < 0)
                goto out_sysctl;