[NETFILTER]: add some consts, remove some casts
[safe/jmp/linux-2.6] / net / ipv6 / netfilter / ip6t_hbh.c
index 37a8474..bbd2615 100644 (file)
 
 #include <asm/byteorder.h>
 
+#include <linux/netfilter/x_tables.h>
 #include <linux/netfilter_ipv6/ip6_tables.h>
 #include <linux/netfilter_ipv6/ip6t_opts.h>
 
-#define HOPBYHOP       1
-
 MODULE_LICENSE("GPL");
-#if HOPBYHOP
-MODULE_DESCRIPTION("IPv6 HbH match");
-#else
-MODULE_DESCRIPTION("IPv6 DST match");
-#endif
+MODULE_DESCRIPTION("IPv6 opts match");
 MODULE_AUTHOR("Andras Kis-Szabo <kisza@sch.bme.hu>");
+MODULE_ALIAS("ip6t_dst");
 
 #if 0
 #define DEBUGP printk
@@ -51,42 +47,47 @@ MODULE_AUTHOR("Andras Kis-Szabo <kisza@sch.bme.hu>");
  *     5       -> RTALERT 2 x x
  */
 
-static int
+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,
-      int *hotdrop)
+      bool *hotdrop)
 {
-       struct ipv6_opt_hdr _optsh, *oh;
+       struct ipv6_opt_hdr _optsh;
+       const struct ipv6_opt_hdr *oh;
        const struct ip6t_opts *optinfo = matchinfo;
        unsigned int temp;
        unsigned int ptr;
        unsigned int hdrlen = 0;
-       unsigned int ret = 0;
-       u8 _opttype, *tp = NULL;
-       u8 _optlen, *lp = NULL;
+       bool ret = false;
+       u8 _opttype;
+       u8 _optlen;
+       const u_int8_t *tp = NULL;
+       const u_int8_t *lp = NULL;
        unsigned int optlen;
+       int err;
 
-#if HOPBYHOP
-       if (ipv6_find_hdr(skb, &ptr, NEXTHDR_HOP, NULL) < 0)
-#else
-       if (ipv6_find_hdr(skb, &ptr, NEXTHDR_DEST, NULL) < 0)
-#endif
-               return 0;
+       err = ipv6_find_hdr(skb, &ptr, match->data, NULL);
+       if (err < 0) {
+               if (err != -ENOENT)
+                       *hotdrop = true;
+               return false;
+       }
 
        oh = skb_header_pointer(skb, ptr, sizeof(_optsh), &_optsh);
        if (oh == NULL) {
-               *hotdrop = 1;
-               return 0;
+               *hotdrop = true;
+               return false;
        }
 
        hdrlen = ipv6_optlen(oh);
        if (skb->len - ptr < hdrlen) {
                /* Packet smaller than it's length field */
-               return 0;
+               return false;
        }
 
        DEBUGP("IPv6 OPTS LEN %u %u ", hdrlen, oh->hdrlen);
@@ -125,7 +126,7 @@ match(const struct sk_buff *skb,
                                DEBUGP("Tbad %02X %02X\n",
                                       *tp,
                                       (optinfo->opts[temp] & 0xFF00) >> 8);
-                               return 0;
+                               return false;
                        } else {
                                DEBUGP("Tok ");
                        }
@@ -146,7 +147,7 @@ match(const struct sk_buff *skb,
                                if (spec_len != 0x00FF && spec_len != *lp) {
                                        DEBUGP("Lbad %02X %04X\n", *lp,
                                               spec_len);
-                                       return 0;
+                                       return false;
                                }
                                DEBUGP("Lok ");
                                optlen = *lp + 2;
@@ -169,55 +170,59 @@ match(const struct sk_buff *skb,
                if (temp == optinfo->optsnr)
                        return ret;
                else
-                       return 0;
+                       return false;
        }
 
-       return 0;
+       return false;
 }
 
 /* Called when user tries to insert an entry of this type. */
-static int
+static bool
 checkentry(const char *tablename,
           const void *entry,
+          const struct xt_match *match,
           void *matchinfo,
-          unsigned int matchinfosize,
           unsigned int hook_mask)
 {
        const struct ip6t_opts *optsinfo = matchinfo;
 
-       if (matchinfosize != IP6T_ALIGN(sizeof(struct ip6t_opts))) {
-               DEBUGP("ip6t_opts: matchsize %u != %u\n",
-                      matchinfosize, IP6T_ALIGN(sizeof(struct ip6t_opts)));
-               return 0;
-       }
        if (optsinfo->invflags & ~IP6T_OPTS_INV_MASK) {
                DEBUGP("ip6t_opts: unknown flags %X\n", optsinfo->invflags);
-               return 0;
+               return false;
        }
-
-       return 1;
+       return true;
 }
 
-static struct ip6t_match opts_match = {
-#if HOPBYHOP
-       .name           = "hbh",
-#else
-       .name           = "dst",
-#endif
-       .match          = &match,
-       .checkentry     = &checkentry,
-       .me             = THIS_MODULE,
+static struct xt_match opts_match[] = {
+       {
+               .name           = "hbh",
+               .family         = AF_INET6,
+               .match          = match,
+               .matchsize      = sizeof(struct ip6t_opts),
+               .checkentry     = checkentry,
+               .me             = THIS_MODULE,
+               .data           = NEXTHDR_HOP,
+       },
+       {
+               .name           = "dst",
+               .family         = AF_INET6,
+               .match          = match,
+               .matchsize      = sizeof(struct ip6t_opts),
+               .checkentry     = checkentry,
+               .me             = THIS_MODULE,
+               .data           = NEXTHDR_DEST,
+       },
 };
 
-static int __init init(void)
+static int __init ip6t_hbh_init(void)
 {
-       return ip6t_register_match(&opts_match);
+       return xt_register_matches(opts_match, ARRAY_SIZE(opts_match));
 }
 
-static void __exit cleanup(void)
+static void __exit ip6t_hbh_fini(void)
 {
-       ip6t_unregister_match(&opts_match);
+       xt_unregister_matches(opts_match, ARRAY_SIZE(opts_match));
 }
 
-module_init(init);
-module_exit(cleanup);
+module_init(ip6t_hbh_init);
+module_exit(ip6t_hbh_fini);