basic modification from way back
[powerpc.git] / net / netfilter / xt_CONNMARK.c
index b554823..b03ce00 100644 (file)
@@ -30,10 +30,7 @@ MODULE_ALIAS("ipt_CONNMARK");
 
 #include <linux/netfilter/x_tables.h>
 #include <linux/netfilter/xt_CONNMARK.h>
-#include <net/netfilter/nf_conntrack_compat.h>
-#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
 #include <net/netfilter/nf_conntrack_ecache.h>
-#endif
 
 static unsigned int
 target(struct sk_buff **pskb,
@@ -44,42 +41,34 @@ target(struct sk_buff **pskb,
        const void *targinfo)
 {
        const struct xt_connmark_target_info *markinfo = targinfo;
+       struct nf_conn *ct;
+       enum ip_conntrack_info ctinfo;
        u_int32_t diff;
        u_int32_t mark;
        u_int32_t newmark;
-       u_int32_t ctinfo;
-       u_int32_t *ctmark = nf_ct_get_mark(*pskb, &ctinfo);
 
-       if (ctmark) {
+       ct = nf_ct_get(*pskb, &ctinfo);
+       if (ct) {
                switch(markinfo->mode) {
                case XT_CONNMARK_SET:
-                       newmark = (*ctmark & ~markinfo->mask) | markinfo->mark;
-                       if (newmark != *ctmark) {
-                               *ctmark = newmark;
-#if defined(CONFIG_IP_NF_CONNTRACK) || defined(CONFIG_IP_NF_CONNTRACK_MODULE)
-                               ip_conntrack_event_cache(IPCT_MARK, *pskb);
-#else
+                       newmark = (ct->mark & ~markinfo->mask) | markinfo->mark;
+                       if (newmark != ct->mark) {
+                               ct->mark = newmark;
                                nf_conntrack_event_cache(IPCT_MARK, *pskb);
-#endif
-               }
+                       }
                        break;
                case XT_CONNMARK_SAVE:
-                       newmark = (*ctmark & ~markinfo->mask) |
+                       newmark = (ct->mark & ~markinfo->mask) |
                                  ((*pskb)->mark & markinfo->mask);
-                       if (*ctmark != newmark) {
-                               *ctmark = newmark;
-#if defined(CONFIG_IP_NF_CONNTRACK) || defined(CONFIG_IP_NF_CONNTRACK_MODULE)
-                               ip_conntrack_event_cache(IPCT_MARK, *pskb);
-#else
+                       if (ct->mark != newmark) {
+                               ct->mark = newmark;
                                nf_conntrack_event_cache(IPCT_MARK, *pskb);
-#endif
                        }
                        break;
                case XT_CONNMARK_RESTORE:
                        mark = (*pskb)->mark;
-                       diff = (*ctmark ^ mark) & markinfo->mask;
-                       if (diff != 0)
-                               (*pskb)->mark = mark ^ diff;
+                       diff = (ct->mark ^ mark) & markinfo->mask;
+                       (*pskb)->mark = mark ^ diff;
                        break;
                }
        }
@@ -96,6 +85,11 @@ checkentry(const char *tablename,
 {
        struct xt_connmark_target_info *matchinfo = targinfo;
 
+       if (nf_ct_l3proto_try_module_get(target->family) < 0) {
+               printk(KERN_WARNING "can't load conntrack support for "
+                                   "proto=%d\n", target->family);
+               return 0;
+       }
        if (matchinfo->mode == XT_CONNMARK_RESTORE) {
                if (strcmp(tablename, "mangle") != 0) {
                        printk(KERN_WARNING "CONNMARK: restore can only be "
@@ -111,6 +105,12 @@ checkentry(const char *tablename,
        return 1;
 }
 
+static void
+destroy(const struct xt_target *target, void *targinfo)
+{
+       nf_ct_l3proto_module_put(target->family);
+}
+
 #ifdef CONFIG_COMPAT
 struct compat_xt_connmark_target_info {
        compat_ulong_t  mark, mask;
@@ -147,6 +147,7 @@ static struct xt_target xt_connmark_target[] = {
                .name           = "CONNMARK",
                .family         = AF_INET,
                .checkentry     = checkentry,
+               .destroy        = destroy,
                .target         = target,
                .targetsize     = sizeof(struct xt_connmark_target_info),
 #ifdef CONFIG_COMPAT
@@ -160,6 +161,7 @@ static struct xt_target xt_connmark_target[] = {
                .name           = "CONNMARK",
                .family         = AF_INET6,
                .checkentry     = checkentry,
+               .destroy        = destroy,
                .target         = target,
                .targetsize     = sizeof(struct xt_connmark_target_info),
                .me             = THIS_MODULE
@@ -168,7 +170,6 @@ static struct xt_target xt_connmark_target[] = {
 
 static int __init xt_connmark_init(void)
 {
-       need_conntrack();
        return xt_register_targets(xt_connmark_target,
                                   ARRAY_SIZE(xt_connmark_target));
 }