pkt_sched: pedit use proper struct
[safe/jmp/linux-2.6] / net / ipv6 / ah6.c
index ff904a7..c1589e2 100644 (file)
 #include <net/ah.h>
 #include <linux/crypto.h>
 #include <linux/pfkeyv2.h>
+#include <linux/spinlock.h>
 #include <linux/string.h>
 #include <net/icmp.h>
 #include <net/ipv6.h>
 #include <net/protocol.h>
 #include <net/xfrm.h>
-#include <asm/scatterlist.h>
 
 static int zero_out_mutable_opts(struct ipv6_opt_hdr *opthdr)
 {
@@ -235,6 +235,7 @@ static int ah6_output(struct xfrm_state *x, struct sk_buff *skb)
                char hdrs[0];
        } *tmp_ext;
 
+       skb_push(skb, -skb_network_offset(skb));
        top_iph = ipv6_hdr(skb);
        top_iph->payload_len = htons(skb->len - sizeof(*top_iph));
 
@@ -268,7 +269,7 @@ static int ah6_output(struct xfrm_state *x, struct sk_buff *skb)
                        goto error_free_iph;
        }
 
-       ah = (struct ip_auth_hdr *)skb_transport_header(skb);
+       ah = ip_auth_hdr(skb);
        ah->nexthdr = nexthdr;
 
        top_iph->priority    = 0;
@@ -278,18 +279,19 @@ static int ah6_output(struct xfrm_state *x, struct sk_buff *skb)
        top_iph->hop_limit   = 0;
 
        ahp = x->data;
-       ah->hdrlen  = (XFRM_ALIGN8(sizeof(struct ipv6_auth_hdr) +
-                                  ahp->icv_trunc_len) >> 2) - 2;
+       ah->hdrlen  = (XFRM_ALIGN8(sizeof(*ah) + ahp->icv_trunc_len) >> 2) - 2;
 
        ah->reserved = 0;
        ah->spi = x->id.spi;
-       ah->seq_no = htonl(XFRM_SKB_CB(skb)->seq);
+       ah->seq_no = htonl(XFRM_SKB_CB(skb)->seq.output);
+
+       spin_lock_bh(&x->lock);
        err = ah_mac_digest(ahp, skb, ah->auth_data);
-       if (err)
-               goto error_free_iph;
        memcpy(ah->auth_data, ahp->work_icv, ahp->icv_trunc_len);
+       spin_unlock_bh(&x->lock);
 
-       err = 0;
+       if (err)
+               goto error_free_iph;
 
        memcpy(top_iph, tmp_base, sizeof(tmp_base));
        if (tmp_ext) {
@@ -323,7 +325,7 @@ static int ah6_input(struct xfrm_state *x, struct sk_buff *skb)
         * There is offset of AH before IPv6 header after the process.
         */
 
-       struct ipv6_auth_hdr *ah;
+       struct ip_auth_hdr *ah;
        struct ipv6hdr *ip6h;
        struct ah_data *ahp;
        unsigned char *tmp_hdr = NULL;
@@ -341,14 +343,16 @@ static int ah6_input(struct xfrm_state *x, struct sk_buff *skb)
            pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
                goto out;
 
+       skb->ip_summed = CHECKSUM_NONE;
+
        hdr_len = skb->data - skb_network_header(skb);
-       ah = (struct ipv6_auth_hdr*)skb->data;
+       ah = (struct ip_auth_hdr *)skb->data;
        ahp = x->data;
        nexthdr = ah->nexthdr;
        ah_hlen = (ah->hdrlen + 2) << 2;
 
-       if (ah_hlen != XFRM_ALIGN8(sizeof(struct ipv6_auth_hdr) + ahp->icv_full_len) &&
-           ah_hlen != XFRM_ALIGN8(sizeof(struct ipv6_auth_hdr) + ahp->icv_trunc_len))
+       if (ah_hlen != XFRM_ALIGN8(sizeof(*ah) + ahp->icv_full_len) &&
+           ah_hlen != XFRM_ALIGN8(sizeof(*ah) + ahp->icv_trunc_len))
                goto out;
 
        if (!pskb_may_pull(skb, ah_hlen))
@@ -366,6 +370,7 @@ static int ah6_input(struct xfrm_state *x, struct sk_buff *skb)
        ip6h->flow_lbl[2] = 0;
        ip6h->hop_limit   = 0;
 
+       spin_lock(&x->lock);
        {
                u8 auth_data[MAX_AH_AUTH_LEN];
 
@@ -374,14 +379,15 @@ static int ah6_input(struct xfrm_state *x, struct sk_buff *skb)
                skb_push(skb, hdr_len);
                err = ah_mac_digest(ahp, skb, ah->auth_data);
                if (err)
-                       goto free_out;
-               err = -EINVAL;
-               if (memcmp(ahp->work_icv, auth_data, ahp->icv_trunc_len)) {
-                       LIMIT_NETDEBUG(KERN_WARNING "ipsec ah authentication error\n");
-                       x->stats.integrity_failed++;
-                       goto free_out;
-               }
+                       goto unlock;
+               if (memcmp(ahp->work_icv, auth_data, ahp->icv_trunc_len))
+                       err = -EBADMSG;
        }
+unlock:
+       spin_unlock(&x->lock);
+
+       if (err)
+               goto free_out;
 
        skb->network_header += ah_hlen;
        memcpy(skb_network_header(skb), tmp_hdr, hdr_len);
@@ -399,8 +405,9 @@ out:
 }
 
 static void ah6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
-                   int type, int code, int offset, __be32 info)
+                   u8 type, u8 code, int offset, __be32 info)
 {
+       struct net *net = dev_net(skb->dev);
        struct ipv6hdr *iph = (struct ipv6hdr*)skb->data;
        struct ip_auth_hdr *ah = (struct ip_auth_hdr*)(skb->data+offset);
        struct xfrm_state *x;
@@ -409,12 +416,12 @@ static void ah6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
            type != ICMPV6_PKT_TOOBIG)
                return;
 
-       x = xfrm_state_lookup((xfrm_address_t *)&iph->daddr, ah->spi, IPPROTO_AH, AF_INET6);
+       x = xfrm_state_lookup(net, (xfrm_address_t *)&iph->daddr, ah->spi, IPPROTO_AH, AF_INET6);
        if (!x)
                return;
 
-       NETDEBUG(KERN_DEBUG "pmtu discovery on SA AH/%08x/" NIP6_FMT "\n",
-                ntohl(ah->spi), NIP6(iph->daddr));
+       NETDEBUG(KERN_DEBUG "pmtu discovery on SA AH/%08x/%pI6\n",
+                ntohl(ah->spi), &iph->daddr);
 
        xfrm_state_put(x);
 }
@@ -470,9 +477,18 @@ static int ah6_init_state(struct xfrm_state *x)
        if (!ahp->work_icv)
                goto error;
 
-       x->props.header_len = XFRM_ALIGN8(sizeof(struct ipv6_auth_hdr) + ahp->icv_trunc_len);
-       if (x->props.mode == XFRM_MODE_TUNNEL)
+       x->props.header_len = XFRM_ALIGN8(sizeof(struct ip_auth_hdr) +
+                                         ahp->icv_trunc_len);
+       switch (x->props.mode) {
+       case XFRM_MODE_BEET:
+       case XFRM_MODE_TRANSPORT:
+               break;
+       case XFRM_MODE_TUNNEL:
                x->props.header_len += sizeof(struct ipv6hdr);
+               break;
+       default:
+               goto error;
+       }
        x->data = ahp;
 
        return 0;
@@ -494,13 +510,11 @@ static void ah6_destroy(struct xfrm_state *x)
                return;
 
        kfree(ahp->work_icv);
-       ahp->work_icv = NULL;
        crypto_free_hash(ahp->tfm);
-       ahp->tfm = NULL;
        kfree(ahp);
 }
 
-static struct xfrm_type ah6_type =
+static const struct xfrm_type ah6_type =
 {
        .description    = "AH6",
        .owner          = THIS_MODULE,
@@ -513,7 +527,7 @@ static struct xfrm_type ah6_type =
        .hdr_offset     = xfrm6_find_1stfragopt,
 };
 
-static struct inet6_protocol ah6_protocol = {
+static const struct inet6_protocol ah6_protocol = {
        .handler        =       xfrm6_rcv,
        .err_handler    =       ah6_err,
        .flags          =       INET6_PROTO_NOPOLICY,