mac80211: fix vlan and optimise RX
[safe/jmp/linux-2.6] / net / netfilter / xt_physdev.c
index f47cab7..8d28ca5 100644 (file)
 #include <linux/netfilter_bridge.h>
 #include <linux/netfilter/xt_physdev.h>
 #include <linux/netfilter/x_tables.h>
-#include <linux/netfilter_bridge.h>
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Bart De Schuymer <bdschuym@pandora.be>");
-MODULE_DESCRIPTION("iptables bridge physical device match module");
+MODULE_DESCRIPTION("Xtables: Bridge physical device match");
 MODULE_ALIAS("ipt_physdev");
 MODULE_ALIAS("ip6t_physdev");
 
+
 static bool
-match(const struct sk_buff *skb,
-      const struct net_device *in,
-      const struct net_device *out,
-      const struct xt_match *match,
-      const void *matchinfo,
-      int offset,
-      unsigned int protoff,
-      bool *hotdrop)
+physdev_mt(const struct sk_buff *skb, const struct xt_match_param *par)
 {
-       int i;
-       static const char nulldevname[IFNAMSIZ];
-       const struct xt_physdev_info *info = matchinfo;
-       bool ret;
+       static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long))));
+       const struct xt_physdev_info *info = par->matchinfo;
+       unsigned long ret;
        const char *indev, *outdev;
        const struct nf_bridge_info *nf_bridge;
 
@@ -76,11 +68,7 @@ match(const struct sk_buff *skb,
        if (!(info->bitmask & XT_PHYSDEV_OP_IN))
                goto match_outdev;
        indev = nf_bridge->physindev ? nf_bridge->physindev->name : nulldevname;
-       for (i = 0, ret = false; i < IFNAMSIZ/sizeof(unsigned int); i++) {
-               ret |= (((const unsigned int *)indev)[i]
-                       ^ ((const unsigned int *)info->physindev)[i])
-                       & ((const unsigned int *)info->in_mask)[i];
-       }
+       ret = ifname_compare_aligned(indev, info->physindev, info->in_mask);
 
        if (!ret ^ !(info->invert & XT_PHYSDEV_OP_IN))
                return false;
@@ -90,23 +78,14 @@ match_outdev:
                return true;
        outdev = nf_bridge->physoutdev ?
                 nf_bridge->physoutdev->name : nulldevname;
-       for (i = 0, ret = false; i < IFNAMSIZ/sizeof(unsigned int); i++) {
-               ret |= (((const unsigned int *)outdev)[i]
-                       ^ ((const unsigned int *)info->physoutdev)[i])
-                       & ((const unsigned int *)info->out_mask)[i];
-       }
+       ret = ifname_compare_aligned(outdev, info->physoutdev, info->out_mask);
 
-       return ret ^ !(info->invert & XT_PHYSDEV_OP_OUT);
+       return (!!ret ^ !(info->invert & XT_PHYSDEV_OP_OUT));
 }
 
-static bool
-checkentry(const char *tablename,
-                      const void *ip,
-                      const struct xt_match *match,
-                      void *matchinfo,
-                      unsigned int hook_mask)
+static bool physdev_mt_check(const struct xt_mtchk_param *par)
 {
-       const struct xt_physdev_info *info = matchinfo;
+       const struct xt_physdev_info *info = par->matchinfo;
 
        if (!(info->bitmask & XT_PHYSDEV_OP_MASK) ||
            info->bitmask & ~XT_PHYSDEV_OP_MASK)
@@ -114,46 +93,36 @@ checkentry(const char *tablename,
        if (info->bitmask & XT_PHYSDEV_OP_OUT &&
            (!(info->bitmask & XT_PHYSDEV_OP_BRIDGED) ||
             info->invert & XT_PHYSDEV_OP_BRIDGED) &&
-           hook_mask & ((1 << NF_IP_LOCAL_OUT) | (1 << NF_IP_FORWARD) |
-                        (1 << NF_IP_POST_ROUTING))) {
+           par->hook_mask & ((1 << NF_INET_LOCAL_OUT) |
+           (1 << NF_INET_FORWARD) | (1 << NF_INET_POST_ROUTING))) {
                printk(KERN_WARNING "physdev match: using --physdev-out in the "
                       "OUTPUT, FORWARD and POSTROUTING chains for non-bridged "
                       "traffic is not supported anymore.\n");
-               if (hook_mask & (1 << NF_IP_LOCAL_OUT))
+               if (par->hook_mask & (1 << NF_INET_LOCAL_OUT))
                        return false;
        }
        return true;
 }
 
-static struct xt_match xt_physdev_match[] __read_mostly = {
-       {
-               .name           = "physdev",
-               .family         = AF_INET,
-               .checkentry     = checkentry,
-               .match          = match,
-               .matchsize      = sizeof(struct xt_physdev_info),
-               .me             = THIS_MODULE,
-       },
-       {
-               .name           = "physdev",
-               .family         = AF_INET6,
-               .checkentry     = checkentry,
-               .match          = match,
-               .matchsize      = sizeof(struct xt_physdev_info),
-               .me             = THIS_MODULE,
-       },
+static struct xt_match physdev_mt_reg __read_mostly = {
+       .name       = "physdev",
+       .revision   = 0,
+       .family     = NFPROTO_UNSPEC,
+       .checkentry = physdev_mt_check,
+       .match      = physdev_mt,
+       .matchsize  = sizeof(struct xt_physdev_info),
+       .me         = THIS_MODULE,
 };
 
-static int __init xt_physdev_init(void)
+static int __init physdev_mt_init(void)
 {
-       return xt_register_matches(xt_physdev_match,
-                                  ARRAY_SIZE(xt_physdev_match));
+       return xt_register_match(&physdev_mt_reg);
 }
 
-static void __exit xt_physdev_fini(void)
+static void __exit physdev_mt_exit(void)
 {
-       xt_unregister_matches(xt_physdev_match, ARRAY_SIZE(xt_physdev_match));
+       xt_unregister_match(&physdev_mt_reg);
 }
 
-module_init(xt_physdev_init);
-module_exit(xt_physdev_fini);
+module_init(physdev_mt_init);
+module_exit(physdev_mt_exit);