OSDN Git Service

Merge branch 'kvm-updates/3.3' of git://git.kernel.org/pub/scm/virt/kvm/kvm
[uclinux-h8/linux.git] / net / netfilter / nf_conntrack_expect.c
index 340c80d..4147ba3 100644 (file)
@@ -38,8 +38,6 @@ unsigned int nf_ct_expect_max __read_mostly;
 
 static struct kmem_cache *nf_ct_expect_cachep __read_mostly;
 
-static HLIST_HEAD(nf_ct_userspace_expect_list);
-
 /* nf_conntrack_expect helper functions */
 void nf_ct_unlink_expect_report(struct nf_conntrack_expect *exp,
                                u32 pid, int report)
@@ -47,14 +45,14 @@ void nf_ct_unlink_expect_report(struct nf_conntrack_expect *exp,
        struct nf_conn_help *master_help = nfct_help(exp->master);
        struct net *net = nf_ct_exp_net(exp);
 
+       NF_CT_ASSERT(master_help);
        NF_CT_ASSERT(!timer_pending(&exp->timeout));
 
        hlist_del_rcu(&exp->hnode);
        net->ct.expect_count--;
 
        hlist_del(&exp->lnode);
-       if (!(exp->flags & NF_CT_EXPECT_USERSPACE))
-               master_help->expecting[exp->class]--;
+       master_help->expecting[exp->class]--;
 
        nf_ct_expect_event_report(IPEXP_DESTROY, exp, pid, report);
        nf_ct_expect_put(exp);
@@ -314,37 +312,34 @@ void nf_ct_expect_put(struct nf_conntrack_expect *exp)
 }
 EXPORT_SYMBOL_GPL(nf_ct_expect_put);
 
-static void nf_ct_expect_insert(struct nf_conntrack_expect *exp)
+static int nf_ct_expect_insert(struct nf_conntrack_expect *exp)
 {
        struct nf_conn_help *master_help = nfct_help(exp->master);
+       struct nf_conntrack_helper *helper;
        struct net *net = nf_ct_exp_net(exp);
-       const struct nf_conntrack_expect_policy *p;
        unsigned int h = nf_ct_expect_dst_hash(&exp->tuple);
 
        /* two references : one for hash insert, one for the timer */
        atomic_add(2, &exp->use);
 
-       if (master_help) {
-               hlist_add_head(&exp->lnode, &master_help->expectations);
-               master_help->expecting[exp->class]++;
-       } else if (exp->flags & NF_CT_EXPECT_USERSPACE)
-               hlist_add_head(&exp->lnode, &nf_ct_userspace_expect_list);
+       hlist_add_head(&exp->lnode, &master_help->expectations);
+       master_help->expecting[exp->class]++;
 
        hlist_add_head_rcu(&exp->hnode, &net->ct.expect_hash[h]);
        net->ct.expect_count++;
 
        setup_timer(&exp->timeout, nf_ct_expectation_timed_out,
                    (unsigned long)exp);
-       if (master_help) {
-               p = &rcu_dereference_protected(
-                               master_help->helper,
-                               lockdep_is_held(&nf_conntrack_lock)
-                               )->expect_policy[exp->class];
-               exp->timeout.expires = jiffies + p->timeout * HZ;
+       helper = rcu_dereference_protected(master_help->helper,
+                                          lockdep_is_held(&nf_conntrack_lock));
+       if (helper) {
+               exp->timeout.expires = jiffies +
+                       helper->expect_policy[exp->class].timeout * HZ;
        }
        add_timer(&exp->timeout);
 
        NF_CT_STAT_INC(net, expect_create);
+       return 0;
 }
 
 /* Race with expectations being used means we could have none to find; OK. */
@@ -389,14 +384,13 @@ static inline int __nf_ct_expect_check(struct nf_conntrack_expect *expect)
        struct nf_conntrack_expect *i;
        struct nf_conn *master = expect->master;
        struct nf_conn_help *master_help = nfct_help(master);
+       struct nf_conntrack_helper *helper;
        struct net *net = nf_ct_exp_net(expect);
        struct hlist_node *n;
        unsigned int h;
        int ret = 1;
 
-       /* Don't allow expectations created from kernel-space with no helper */
-       if (!(expect->flags & NF_CT_EXPECT_USERSPACE) &&
-           (!master_help || (master_help && !master_help->helper))) {
+       if (!master_help) {
                ret = -ESHUTDOWN;
                goto out;
        }
@@ -414,11 +408,10 @@ static inline int __nf_ct_expect_check(struct nf_conntrack_expect *expect)
                }
        }
        /* Will be over limit? */
-       if (master_help) {
-               p = &rcu_dereference_protected(
-                       master_help->helper,
-                       lockdep_is_held(&nf_conntrack_lock)
-                       )->expect_policy[expect->class];
+       helper = rcu_dereference_protected(master_help->helper,
+                                          lockdep_is_held(&nf_conntrack_lock));
+       if (helper) {
+               p = &helper->expect_policy[expect->class];
                if (p->max_expected &&
                    master_help->expecting[expect->class] >= p->max_expected) {
                        evict_oldest_expect(master, expect);
@@ -450,8 +443,9 @@ int nf_ct_expect_related_report(struct nf_conntrack_expect *expect,
        if (ret <= 0)
                goto out;
 
-       ret = 0;
-       nf_ct_expect_insert(expect);
+       ret = nf_ct_expect_insert(expect);
+       if (ret < 0)
+               goto out;
        spin_unlock_bh(&nf_conntrack_lock);
        nf_ct_expect_event_report(IPEXP_NEW, expect, pid, report);
        return ret;
@@ -461,22 +455,7 @@ out:
 }
 EXPORT_SYMBOL_GPL(nf_ct_expect_related_report);
 
-void nf_ct_remove_userspace_expectations(void)
-{
-       struct nf_conntrack_expect *exp;
-       struct hlist_node *n, *next;
-
-       hlist_for_each_entry_safe(exp, n, next,
-                                 &nf_ct_userspace_expect_list, lnode) {
-               if (del_timer(&exp->timeout)) {
-                       nf_ct_unlink_expect(exp);
-                       nf_ct_expect_put(exp);
-               }
-       }
-}
-EXPORT_SYMBOL_GPL(nf_ct_remove_userspace_expectations);
-
-#ifdef CONFIG_PROC_FS
+#ifdef CONFIG_NF_CONNTRACK_PROCFS
 struct ct_expect_iter_state {
        struct seq_net_private p;
        unsigned int bucket;
@@ -604,25 +583,25 @@ static const struct file_operations exp_file_ops = {
        .llseek  = seq_lseek,
        .release = seq_release_net,
 };
-#endif /* CONFIG_PROC_FS */
+#endif /* CONFIG_NF_CONNTRACK_PROCFS */
 
 static int exp_proc_init(struct net *net)
 {
-#ifdef CONFIG_PROC_FS
+#ifdef CONFIG_NF_CONNTRACK_PROCFS
        struct proc_dir_entry *proc;
 
        proc = proc_net_fops_create(net, "nf_conntrack_expect", 0440, &exp_file_ops);
        if (!proc)
                return -ENOMEM;
-#endif /* CONFIG_PROC_FS */
+#endif /* CONFIG_NF_CONNTRACK_PROCFS */
        return 0;
 }
 
 static void exp_proc_remove(struct net *net)
 {
-#ifdef CONFIG_PROC_FS
+#ifdef CONFIG_NF_CONNTRACK_PROCFS
        proc_net_remove(net, "nf_conntrack_expect");
-#endif /* CONFIG_PROC_FS */
+#endif /* CONFIG_NF_CONNTRACK_PROCFS */
 }
 
 module_param_named(expect_hashsize, nf_ct_expect_hsize, uint, 0400);