Merge branch 'master' of /repos/git/net-next-2.6
[safe/jmp/linux-2.6] / net / netfilter / nf_conntrack_helper.c
index 4b1a56b..4509fa6 100644 (file)
@@ -65,7 +65,7 @@ __nf_ct_helper_find(const struct nf_conntrack_tuple *tuple)
 }
 
 struct nf_conntrack_helper *
-__nf_conntrack_helper_find_byname(const char *name)
+__nf_conntrack_helper_find(const char *name, u16 l3num, u8 protonum)
 {
        struct nf_conntrack_helper *h;
        struct hlist_node *n;
@@ -73,13 +73,34 @@ __nf_conntrack_helper_find_byname(const char *name)
 
        for (i = 0; i < nf_ct_helper_hsize; i++) {
                hlist_for_each_entry_rcu(h, n, &nf_ct_helper_hash[i], hnode) {
-                       if (!strcmp(h->name, name))
+                       if (!strcmp(h->name, name) &&
+                           h->tuple.src.l3num == l3num &&
+                           h->tuple.dst.protonum == protonum)
                                return h;
                }
        }
        return NULL;
 }
-EXPORT_SYMBOL_GPL(__nf_conntrack_helper_find_byname);
+EXPORT_SYMBOL_GPL(__nf_conntrack_helper_find);
+
+struct nf_conntrack_helper *
+nf_conntrack_helper_try_module_get(const char *name, u16 l3num, u8 protonum)
+{
+       struct nf_conntrack_helper *h;
+
+       h = __nf_conntrack_helper_find(name, l3num, protonum);
+#ifdef CONFIG_MODULES
+       if (h == NULL) {
+               if (request_module("nfct-helper-%s", name) == 0)
+                       h = __nf_conntrack_helper_find(name, l3num, protonum);
+       }
+#endif
+       if (h != NULL && !try_module_get(h->me))
+               h = NULL;
+
+       return h;
+}
+EXPORT_SYMBOL_GPL(nf_conntrack_helper_try_module_get);
 
 struct nf_conn_help *nf_ct_helper_ext_add(struct nf_conn *ct, gfp_t gfp)
 {
@@ -94,13 +115,22 @@ struct nf_conn_help *nf_ct_helper_ext_add(struct nf_conn *ct, gfp_t gfp)
 }
 EXPORT_SYMBOL_GPL(nf_ct_helper_ext_add);
 
-int __nf_ct_try_assign_helper(struct nf_conn *ct, gfp_t flags)
+int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl,
+                             gfp_t flags)
 {
+       struct nf_conntrack_helper *helper = NULL;
+       struct nf_conn_help *help;
        int ret = 0;
-       struct nf_conntrack_helper *helper;
-       struct nf_conn_help *help = nfct_help(ct);
 
-       helper = __nf_ct_helper_find(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
+       if (tmpl != NULL) {
+               help = nfct_help(tmpl);
+               if (help != NULL)
+                       helper = help->helper;
+       }
+
+       help = nfct_help(ct);
+       if (helper == NULL)
+               helper = __nf_ct_helper_find(&ct->tuplehash[IP_CT_DIR_REPLY].tuple);
        if (helper == NULL) {
                if (help)
                        rcu_assign_pointer(help->helper, NULL);