ipv6: fix an oops when force unload ipv6 module
[safe/jmp/linux-2.6] / net / netfilter / xt_RATEEST.c
index c5ba525..d80b819 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/rtnetlink.h>
 #include <linux/random.h>
 #include <net/gen_stats.h>
+#include <net/netlink.h>
 
 #include <linux/netfilter/x_tables.h>
 #include <linux/netfilter/xt_RATEEST.h>
@@ -70,15 +71,10 @@ void xt_rateest_put(struct xt_rateest *est)
 EXPORT_SYMBOL_GPL(xt_rateest_put);
 
 static unsigned int
-xt_rateest_tg(struct sk_buff *skb,
-             const struct net_device *in,
-             const struct net_device *out,
-             unsigned int hooknum,
-             const struct xt_target *target,
-             const void *targinfo)
+xt_rateest_tg(struct sk_buff *skb, const struct xt_target_param *par)
 {
-       const struct xt_rateest_target_info *info = targinfo;
-       struct gnet_stats_basic *stats = &info->est->bstats;
+       const struct xt_rateest_target_info *info = par->targinfo;
+       struct gnet_stats_basic_packed *stats = &info->est->bstats;
 
        spin_lock_bh(&info->est->lock);
        stats->bytes += skb->len;
@@ -88,17 +84,12 @@ xt_rateest_tg(struct sk_buff *skb,
        return XT_CONTINUE;
 }
 
-static bool
-xt_rateest_tg_checkentry(const char *tablename,
-                        const void *entry,
-                        const struct xt_target *target,
-                        void *targinfo,
-                        unsigned int hook_mask)
+static bool xt_rateest_tg_checkentry(const struct xt_tgchk_param *par)
 {
-       struct xt_rateest_target_info *info = (void *)targinfo;
+       struct xt_rateest_target_info *info = par->targinfo;
        struct xt_rateest *est;
        struct {
-               struct rtattr           opt;
+               struct nlattr           opt;
                struct gnet_estimator   est;
        } cfg;
 
@@ -128,8 +119,8 @@ xt_rateest_tg_checkentry(const char *tablename,
        est->params.interval    = info->interval;
        est->params.ewma_log    = info->ewma_log;
 
-       cfg.opt.rta_len         = RTA_LENGTH(sizeof(cfg.est));
-       cfg.opt.rta_type        = TCA_STATS_RATE_EST;
+       cfg.opt.nla_len         = nla_attr_size(sizeof(cfg.est));
+       cfg.opt.nla_type        = TCA_STATS_RATE_EST;
        cfg.est.interval        = info->interval;
        cfg.est.ewma_log        = info->ewma_log;
 
@@ -148,33 +139,22 @@ err1:
        return false;
 }
 
-static void xt_rateest_tg_destroy(const struct xt_target *target,
-                                 void *targinfo)
+static void xt_rateest_tg_destroy(const struct xt_tgdtor_param *par)
 {
-       struct xt_rateest_target_info *info = targinfo;
+       struct xt_rateest_target_info *info = par->targinfo;
 
        xt_rateest_put(info->est);
 }
 
-static struct xt_target xt_rateest_target[] __read_mostly = {
-       {
-               .family         = AF_INET,
-               .name           = "RATEEST",
-               .target         = xt_rateest_tg,
-               .checkentry     = xt_rateest_tg_checkentry,
-               .destroy        = xt_rateest_tg_destroy,
-               .targetsize     = sizeof(struct xt_rateest_target_info),
-               .me             = THIS_MODULE,
-       },
-       {
-               .family         = AF_INET6,
-               .name           = "RATEEST",
-               .target         = xt_rateest_tg,
-               .checkentry     = xt_rateest_tg_checkentry,
-               .destroy        = xt_rateest_tg_destroy,
-               .targetsize     = sizeof(struct xt_rateest_target_info),
-               .me             = THIS_MODULE,
-       },
+static struct xt_target xt_rateest_tg_reg __read_mostly = {
+       .name       = "RATEEST",
+       .revision   = 0,
+       .family     = NFPROTO_UNSPEC,
+       .target     = xt_rateest_tg,
+       .checkentry = xt_rateest_tg_checkentry,
+       .destroy    = xt_rateest_tg_destroy,
+       .targetsize = sizeof(struct xt_rateest_target_info),
+       .me         = THIS_MODULE,
 };
 
 static int __init xt_rateest_tg_init(void)
@@ -185,13 +165,12 @@ static int __init xt_rateest_tg_init(void)
                INIT_HLIST_HEAD(&rateest_hash[i]);
 
        get_random_bytes(&jhash_rnd, sizeof(jhash_rnd));
-       return xt_register_targets(xt_rateest_target,
-                                  ARRAY_SIZE(xt_rateest_target));
+       return xt_register_target(&xt_rateest_tg_reg);
 }
 
 static void __exit xt_rateest_tg_fini(void)
 {
-       xt_unregister_targets(xt_rateest_target, ARRAY_SIZE(xt_rateest_target));
+       xt_unregister_target(&xt_rateest_tg_reg);
 }