Merge branch 'for_paulus' of master.kernel.org:/pub/scm/linux/kernel/git/galak/powerpc
[pandora-kernel.git] / net / ipv4 / netfilter / ip_conntrack_proto_icmp.c
index 5198f3a..d8b14a9 100644 (file)
 #include <linux/in.h>
 #include <linux/icmp.h>
 #include <linux/seq_file.h>
+#include <linux/skbuff.h>
 #include <net/ip.h>
 #include <net/checksum.h>
-#include <linux/netfilter.h>
 #include <linux/netfilter_ipv4.h>
 #include <linux/netfilter_ipv4/ip_conntrack.h>
 #include <linux/netfilter_ipv4/ip_conntrack_core.h>
 #include <linux/netfilter_ipv4/ip_conntrack_protocol.h>
 
-unsigned long ip_ct_icmp_timeout = 30*HZ;
+unsigned int ip_ct_icmp_timeout = 30*HZ;
 
 #if 0
 #define DEBUGP printk
@@ -46,20 +46,21 @@ static int icmp_pkt_to_tuple(const struct sk_buff *skb,
        return 1;
 }
 
+/* Add 1; spaces filled with 0. */
+static const u_int8_t invmap[] = {
+       [ICMP_ECHO] = ICMP_ECHOREPLY + 1,
+       [ICMP_ECHOREPLY] = ICMP_ECHO + 1,
+       [ICMP_TIMESTAMP] = ICMP_TIMESTAMPREPLY + 1,
+       [ICMP_TIMESTAMPREPLY] = ICMP_TIMESTAMP + 1,
+       [ICMP_INFO_REQUEST] = ICMP_INFO_REPLY + 1,
+       [ICMP_INFO_REPLY] = ICMP_INFO_REQUEST + 1,
+       [ICMP_ADDRESS] = ICMP_ADDRESSREPLY + 1,
+       [ICMP_ADDRESSREPLY] = ICMP_ADDRESS + 1
+};
+
 static int icmp_invert_tuple(struct ip_conntrack_tuple *tuple,
                             const struct ip_conntrack_tuple *orig)
 {
-       /* Add 1; spaces filled with 0. */
-       static u_int8_t invmap[]
-               = { [ICMP_ECHO] = ICMP_ECHOREPLY + 1,
-                   [ICMP_ECHOREPLY] = ICMP_ECHO + 1,
-                   [ICMP_TIMESTAMP] = ICMP_TIMESTAMPREPLY + 1,
-                   [ICMP_TIMESTAMPREPLY] = ICMP_TIMESTAMP + 1,
-                   [ICMP_INFO_REQUEST] = ICMP_INFO_REPLY + 1,
-                   [ICMP_INFO_REPLY] = ICMP_INFO_REQUEST + 1,
-                   [ICMP_ADDRESS] = ICMP_ADDRESSREPLY + 1,
-                   [ICMP_ADDRESSREPLY] = ICMP_ADDRESS + 1};
-
        if (orig->dst.u.icmp.type >= sizeof(invmap)
            || !invmap[orig->dst.u.icmp.type])
                return 0;
@@ -109,17 +110,17 @@ static int icmp_packet(struct ip_conntrack *ct,
        return NF_ACCEPT;
 }
 
-static u_int8_t valid_new[] = { 
-       [ICMP_ECHO] = 1,
-       [ICMP_TIMESTAMP] = 1,
-       [ICMP_INFO_REQUEST] = 1,
-       [ICMP_ADDRESS] = 1 
-};
-
 /* Called when a new connection for this protocol found. */
 static int icmp_new(struct ip_conntrack *conntrack,
                    const struct sk_buff *skb)
 {
+       static const u_int8_t valid_new[] = { 
+               [ICMP_ECHO] = 1,
+               [ICMP_TIMESTAMP] = 1,
+               [ICMP_INFO_REQUEST] = 1,
+               [ICMP_ADDRESS] = 1 
+       };
+
        if (conntrack->tuplehash[0].tuple.dst.u.icmp.type >= sizeof(valid_new)
            || !valid_new[conntrack->tuplehash[0].tuple.dst.u.icmp.type]) {
                /* Can't create a new ICMP `conn' with this. */
@@ -223,29 +224,14 @@ icmp_error(struct sk_buff *skb, enum ip_conntrack_info *ctinfo,
        }
 
        /* See ip_conntrack_proto_tcp.c */
-       if (hooknum != NF_IP_PRE_ROUTING)
-               goto checksum_skipped;
-
-       switch (skb->ip_summed) {
-       case CHECKSUM_HW:
-               if (!(u16)csum_fold(skb->csum)) 
-                       break;
+       if (hooknum == NF_IP_PRE_ROUTING &&
+           nf_ip_checksum(skb, hooknum, skb->nh.iph->ihl * 4, 0)) {
                if (LOG_INVALID(IPPROTO_ICMP))
                        nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL,
-                                     "ip_ct_icmp: bad HW ICMP checksum ");
+                                     "ip_ct_icmp: bad ICMP checksum ");
                return -NF_ACCEPT;
-       case CHECKSUM_NONE:
-               if ((u16)csum_fold(skb_checksum(skb, 0, skb->len, 0))) {
-                       if (LOG_INVALID(IPPROTO_ICMP))
-                               nf_log_packet(PF_INET, 0, skb, NULL, NULL, NULL,
-                                             "ip_ct_icmp: bad ICMP checksum ");
-                       return -NF_ACCEPT;
-               }
-       default:
-               break;
        }
 
-checksum_skipped:
        /*
         *      18 is the highest 'known' ICMP type. Anything else is a mystery
         *
@@ -282,10 +268,6 @@ static int icmp_tuple_to_nfattr(struct sk_buff *skb,
        NFA_PUT(skb, CTA_PROTO_ICMP_CODE, sizeof(u_int8_t),
                &t->dst.u.icmp.code);
 
-       if (t->dst.u.icmp.type >= sizeof(valid_new) 
-           || !valid_new[t->dst.u.icmp.type])
-               return -EINVAL;
-
        return 0;
 
 nfattr_failure:
@@ -298,7 +280,7 @@ static int icmp_nfattr_to_tuple(struct nfattr *tb[],
        if (!tb[CTA_PROTO_ICMP_TYPE-1]
            || !tb[CTA_PROTO_ICMP_CODE-1]
            || !tb[CTA_PROTO_ICMP_ID-1])
-               return -1;
+               return -EINVAL;
 
        tuple->dst.u.icmp.type = 
                        *(u_int8_t *)NFA_DATA(tb[CTA_PROTO_ICMP_TYPE-1]);
@@ -307,6 +289,10 @@ static int icmp_nfattr_to_tuple(struct nfattr *tb[],
        tuple->src.u.icmp.id =
                        *(u_int16_t *)NFA_DATA(tb[CTA_PROTO_ICMP_ID-1]);
 
+       if (tuple->dst.u.icmp.type >= sizeof(invmap)
+           || !invmap[tuple->dst.u.icmp.type])
+               return -EINVAL;
+
        return 0;
 }
 #endif