[NETFILTER]: xt_policy: remove dups in .family
[linux-2.6.git] / net / netfilter / xt_limit.c
index e91c1a4..8bfcbdf 100644 (file)
@@ -110,7 +110,6 @@ ipt_limit_checkentry(const char *tablename,
                     const void *inf,
                     const struct xt_match *match,
                     void *matchinfo,
-                    unsigned int matchsize,
                     unsigned int hook_mask)
 {
        struct xt_rateinfo *r = matchinfo;
@@ -123,56 +122,47 @@ ipt_limit_checkentry(const char *tablename,
                return 0;
        }
 
-       /* User avg in seconds * XT_LIMIT_SCALE: convert to jiffies *
-          128. */
-       r->prev = jiffies;
-       r->credit = user2credits(r->avg * r->burst);     /* Credits full. */
-       r->credit_cap = user2credits(r->avg * r->burst); /* Credits full. */
-       r->cost = user2credits(r->avg);
-
        /* For SMP, we only want to use one set of counters. */
        r->master = r;
-
+       if (r->cost == 0) {
+               /* User avg in seconds * XT_LIMIT_SCALE: convert to jiffies *
+                  128. */
+               r->prev = jiffies;
+               r->credit = user2credits(r->avg * r->burst);     /* Credits full. */
+               r->credit_cap = user2credits(r->avg * r->burst); /* Credits full. */
+               r->cost = user2credits(r->avg);
+       }
        return 1;
 }
 
-static struct xt_match ipt_limit_reg = {
-       .name           = "limit",
-       .match          = ipt_limit_match,
-       .matchsize      = sizeof(struct xt_rateinfo),
-       .checkentry     = ipt_limit_checkentry,
-       .family         = AF_INET,
-       .me             = THIS_MODULE,
-};
-static struct xt_match limit6_reg = {
-       .name           = "limit",
-       .match          = ipt_limit_match,
-       .matchsize      = sizeof(struct xt_rateinfo),
-       .checkentry     = ipt_limit_checkentry,
-       .family         = AF_INET6,
-       .me             = THIS_MODULE,
+static struct xt_match xt_limit_match[] = {
+       {
+               .name           = "limit",
+               .family         = AF_INET,
+               .checkentry     = ipt_limit_checkentry,
+               .match          = ipt_limit_match,
+               .matchsize      = sizeof(struct xt_rateinfo),
+               .me             = THIS_MODULE,
+       },
+       {
+               .name           = "limit",
+               .family         = AF_INET6,
+               .checkentry     = ipt_limit_checkentry,
+               .match          = ipt_limit_match,
+               .matchsize      = sizeof(struct xt_rateinfo),
+               .me             = THIS_MODULE,
+       },
 };
 
-static int __init init(void)
+static int __init xt_limit_init(void)
 {
-       int ret;
-       
-       ret = xt_register_match(&ipt_limit_reg);
-       if (ret)
-               return ret;
-       
-       ret = xt_register_match(&limit6_reg);
-       if (ret)
-               xt_unregister_match(&ipt_limit_reg);
-
-       return ret;
+       return xt_register_matches(xt_limit_match, ARRAY_SIZE(xt_limit_match));
 }
 
-static void __exit fini(void)
+static void __exit xt_limit_fini(void)
 {
-       xt_unregister_match(&ipt_limit_reg);
-       xt_unregister_match(&limit6_reg);
+       xt_unregister_matches(xt_limit_match, ARRAY_SIZE(xt_limit_match));
 }
 
-module_init(init);
-module_exit(fini);
+module_init(xt_limit_init);
+module_exit(xt_limit_fini);