fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / net / netfilter / xt_pkttype.c
index 3ac703b..16e7b08 100644 (file)
@@ -9,6 +9,8 @@
 #include <linux/skbuff.h>
 #include <linux/if_ether.h>
 #include <linux/if_packet.h>
+#include <linux/in.h>
+#include <linux/ip.h>
 
 #include <linux/netfilter/xt_pkttype.h>
 #include <linux/netfilter/x_tables.h>
@@ -28,45 +30,45 @@ static int match(const struct sk_buff *skb,
       unsigned int protoff,
       int *hotdrop)
 {
+       u_int8_t type;
        const struct xt_pkttype_info *info = matchinfo;
 
-       return (skb->pkt_type == info->pkttype) ^ info->invert;
-}
+       if (skb->pkt_type == PACKET_LOOPBACK)
+               type = (MULTICAST(skb->nh.iph->daddr)
+                       ? PACKET_MULTICAST
+                       : PACKET_BROADCAST);
+       else
+               type = skb->pkt_type;
 
-static struct xt_match pkttype_match = {
-       .name           = "pkttype",
-       .match          = match,
-       .matchsize      = sizeof(struct xt_pkttype_info),
-       .family         = AF_INET,
-       .me             = THIS_MODULE,
-};
+       return (type == info->pkttype) ^ info->invert;
+}
 
-static struct xt_match pkttype6_match = {
-       .name           = "pkttype",
-       .match          = match,
-       .matchsize      = sizeof(struct xt_pkttype_info),
-       .family         = AF_INET6,
-       .me             = THIS_MODULE,
+static struct xt_match xt_pkttype_match[] = {
+       {
+               .name           = "pkttype",
+               .family         = AF_INET,
+               .match          = match,
+               .matchsize      = sizeof(struct xt_pkttype_info),
+               .me             = THIS_MODULE,
+       },
+       {
+               .name           = "pkttype",
+               .family         = AF_INET6,
+               .match          = match,
+               .matchsize      = sizeof(struct xt_pkttype_info),
+               .me             = THIS_MODULE,
+       },
 };
 
 static int __init xt_pkttype_init(void)
 {
-       int ret;
-       ret = xt_register_match(&pkttype_match);
-       if (ret)
-               return ret;
-
-       ret = xt_register_match(&pkttype6_match);
-       if (ret)
-               xt_unregister_match(&pkttype_match);
-
-       return ret;
+       return xt_register_matches(xt_pkttype_match,
+                                  ARRAY_SIZE(xt_pkttype_match));
 }
 
 static void __exit xt_pkttype_fini(void)
 {
-       xt_unregister_match(&pkttype_match);
-       xt_unregister_match(&pkttype6_match);
+       xt_unregister_matches(xt_pkttype_match, ARRAY_SIZE(xt_pkttype_match));
 }
 
 module_init(xt_pkttype_init);