]> err.no Git - linux-2.6/blobdiff - net/ipv4/netfilter/ipt_ecn.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/drzeus/mmc
[linux-2.6] / net / ipv4 / netfilter / ipt_ecn.c
index 37508b2cfea6d491e6ac27434b44386cae494681..d6925c6740692a730c64fc6313bc788fd8a72e45 100644 (file)
@@ -1,6 +1,4 @@
 /* IP tables module for matching the value of the IPv4 and TCP ECN bits
- *
- * ipt_ecn.c,v 1.3 2002/05/29 15:09:00 laforge Exp
  *
  * (C) 2002 by Harald Welte <laforge@gnumonks.org>
  *
@@ -11,6 +9,7 @@
 
 #include <linux/in.h>
 #include <linux/ip.h>
+#include <net/ip.h>
 #include <linux/module.h>
 #include <linux/skbuff.h>
 #include <linux/tcp.h>
@@ -23,96 +22,96 @@ MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
 MODULE_DESCRIPTION("iptables ECN matching module");
 MODULE_LICENSE("GPL");
 
-static inline int match_ip(const struct sk_buff *skb,
-                          const struct ipt_ecn_info *einfo)
+static inline bool match_ip(const struct sk_buff *skb,
+                           const struct ipt_ecn_info *einfo)
 {
-       return ((skb->nh.iph->tos&IPT_ECN_IP_MASK) == einfo->ip_ect);
+       return (ip_hdr(skb)->tos & IPT_ECN_IP_MASK) == einfo->ip_ect;
 }
 
-static inline int match_tcp(const struct sk_buff *skb,
-                           const struct ipt_ecn_info *einfo,
-                           int *hotdrop)
+static inline bool match_tcp(const struct sk_buff *skb,
+                            const struct ipt_ecn_info *einfo,
+                            bool *hotdrop)
 {
-       struct tcphdr _tcph, *th;
+       struct tcphdr _tcph;
+       const struct tcphdr *th;
 
        /* In practice, TCP match does this, so can't fail.  But let's
         * be good citizens.
         */
-       th = skb_header_pointer(skb, skb->nh.iph->ihl * 4,
-                               sizeof(_tcph), &_tcph);
+       th = skb_header_pointer(skb, ip_hdrlen(skb), sizeof(_tcph), &_tcph);
        if (th == NULL) {
-               *hotdrop = 0;
-               return 0;
+               *hotdrop = false;
+               return false;
        }
 
        if (einfo->operation & IPT_ECN_OP_MATCH_ECE) {
                if (einfo->invert & IPT_ECN_OP_MATCH_ECE) {
                        if (th->ece == 1)
-                               return 0;
+                               return false;
                } else {
                        if (th->ece == 0)
-                               return 0;
+                               return false;
                }
        }
 
        if (einfo->operation & IPT_ECN_OP_MATCH_CWR) {
                if (einfo->invert & IPT_ECN_OP_MATCH_CWR) {
                        if (th->cwr == 1)
-                               return 0;
+                               return false;
                } else {
                        if (th->cwr == 0)
-                               return 0;
+                               return false;
                }
        }
 
-       return 1;
+       return true;
 }
 
-static int 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)
+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)
 {
        const struct ipt_ecn_info *info = matchinfo;
 
        if (info->operation & IPT_ECN_OP_MATCH_IP)
                if (!match_ip(skb, info))
-                       return 0;
+                       return false;
 
        if (info->operation & (IPT_ECN_OP_MATCH_ECE|IPT_ECN_OP_MATCH_CWR)) {
-               if (skb->nh.iph->protocol != IPPROTO_TCP)
-                       return 0;
+               if (ip_hdr(skb)->protocol != IPPROTO_TCP)
+                       return false;
                if (!match_tcp(skb, info, hotdrop))
-                       return 0;
+                       return false;
        }
 
-       return 1;
+       return true;
 }
 
-static int checkentry(const char *tablename, const void *ip_void,
-                     const struct xt_match *match,
-                     void *matchinfo, unsigned int hook_mask)
+static bool checkentry(const char *tablename, const void *ip_void,
+                      const struct xt_match *match,
+                      void *matchinfo, unsigned int hook_mask)
 {
        const struct ipt_ecn_info *info = matchinfo;
        const struct ipt_ip *ip = ip_void;
 
        if (info->operation & IPT_ECN_OP_MATCH_MASK)
-               return 0;
+               return false;
 
        if (info->invert & IPT_ECN_OP_MATCH_MASK)
-               return 0;
+               return false;
 
        if (info->operation & (IPT_ECN_OP_MATCH_ECE|IPT_ECN_OP_MATCH_CWR)
            && ip->proto != IPPROTO_TCP) {
                printk(KERN_WARNING "ipt_ecn: can't match TCP bits in rule for"
                       " non-tcp packets\n");
-               return 0;
+               return false;
        }
 
-       return 1;
+       return true;
 }
 
-static struct xt_match ecn_match = {
+static struct xt_match ecn_match __read_mostly = {
        .name           = "ecn",
        .family         = AF_INET,
        .match          = match,