DISABLE -> BUILTIN : CONFIG_X86_GENERIC
[linux-2.6.git] / net / ipv4 / ah4.c
index 8c16b71..e2e4771 100644 (file)
@@ -1,12 +1,12 @@
 #include <linux/config.h>
 #include <linux/module.h>
-#include <net/inet_ecn.h>
 #include <net/ip.h>
 #include <net/xfrm.h>
 #include <net/ah.h>
 #include <linux/crypto.h>
 #include <linux/pfkeyv2.h>
 #include <net/icmp.h>
+#include <net/protocol.h>
 #include <asm/scatterlist.h>
 
 
@@ -54,11 +54,9 @@ static int ip_clear_mutable_options(struct iphdr *iph, u32 *daddr)
        return 0;
 }
 
-static int ah_output(struct sk_buff **pskb)
+static int ah_output(struct xfrm_state *x, struct sk_buff *skb)
 {
        int err;
-       struct dst_entry *dst = (*pskb)->dst;
-       struct xfrm_state *x  = dst->xfrm;
        struct iphdr *iph, *top_iph;
        struct ip_auth_hdr *ah;
        struct ah_data *ahp;
@@ -67,15 +65,15 @@ static int ah_output(struct sk_buff **pskb)
                char            buf[60];
        } tmp_iph;
 
-       top_iph = (*pskb)->nh.iph;
+       top_iph = skb->nh.iph;
        iph = &tmp_iph.iph;
 
        iph->tos = top_iph->tos;
        iph->ttl = top_iph->ttl;
        iph->frag_off = top_iph->frag_off;
-       iph->daddr = top_iph->daddr;
 
        if (top_iph->ihl != 5) {
+               iph->daddr = top_iph->daddr;
                memcpy(iph+1, top_iph+1, top_iph->ihl*4 - sizeof(struct iphdr));
                err = ip_clear_mutable_options(top_iph, &top_iph->daddr);
                if (err)
@@ -86,7 +84,7 @@ static int ah_output(struct sk_buff **pskb)
        ah->nexthdr = top_iph->protocol;
 
        top_iph->tos = 0;
-       top_iph->tot_len = htons((*pskb)->len);
+       top_iph->tot_len = htons(skb->len);
        top_iph->frag_off = 0;
        top_iph->ttl = 0;
        top_iph->protocol = IPPROTO_AH;
@@ -99,14 +97,16 @@ static int ah_output(struct sk_buff **pskb)
        ah->reserved = 0;
        ah->spi = x->id.spi;
        ah->seq_no = htonl(++x->replay.oseq);
-       ahp->icv(ahp, *pskb, ah->auth_data);
+       xfrm_aevent_doreplay(x);
+       ahp->icv(ahp, skb, ah->auth_data);
 
        top_iph->tos = iph->tos;
        top_iph->ttl = iph->ttl;
        top_iph->frag_off = iph->frag_off;
-       top_iph->daddr = iph->daddr;
-       if (top_iph->ihl != 5)
+       if (top_iph->ihl != 5) {
+               top_iph->daddr = iph->daddr;
                memcpy(top_iph+1, iph+1, top_iph->ihl*4 - sizeof(struct iphdr));
+       }
 
        ip_send_check(top_iph);
 
@@ -116,7 +116,7 @@ error:
        return err;
 }
 
-int ah_input(struct xfrm_state *x, struct xfrm_decap_state *decap, struct sk_buff *skb)
+static int ah_input(struct xfrm_state *x, struct sk_buff *skb)
 {
        int ah_hlen;
        struct iphdr *iph;
@@ -184,7 +184,7 @@ out:
        return -EINVAL;
 }
 
-void ah4_err(struct sk_buff *skb, u32 info)
+static void ah4_err(struct sk_buff *skb, u32 info)
 {
        struct iphdr *iph = (struct iphdr*)skb->data;
        struct ip_auth_hdr *ah = (struct ip_auth_hdr*)(skb->data+(iph->ihl<<2));
@@ -202,7 +202,7 @@ void ah4_err(struct sk_buff *skb, u32 info)
        xfrm_state_put(x);
 }
 
-static int ah_init_state(struct xfrm_state *x, void *args)
+static int ah_init_state(struct xfrm_state *x)
 {
        struct ah_data *ahp = NULL;
        struct xfrm_algo_desc *aalg_desc;
@@ -214,6 +214,9 @@ static int ah_init_state(struct xfrm_state *x, void *args)
        if (x->aalg->alg_key_len > 512)
                goto error;
 
+       if (x->encap)
+               goto error;
+
        ahp = kmalloc(sizeof(*ahp), GFP_KERNEL);
        if (ahp == NULL)
                return -ENOMEM;
@@ -233,7 +236,7 @@ static int ah_init_state(struct xfrm_state *x, void *args)
         * we need for AH processing.  This lookup cannot fail here
         * after a successful crypto_alloc_tfm().
         */
-       aalg_desc = xfrm_aalg_get_byname(x->aalg->alg_name);
+       aalg_desc = xfrm_aalg_get_byname(x->aalg->alg_name, 0);
        BUG_ON(!aalg_desc);
 
        if (aalg_desc->uinfo.auth.icv_fullbits/8 !=
@@ -262,10 +265,8 @@ static int ah_init_state(struct xfrm_state *x, void *args)
 
 error:
        if (ahp) {
-               if (ahp->work_icv)
-                       kfree(ahp->work_icv);
-               if (ahp->tfm)
-                       crypto_free_tfm(ahp->tfm);
+               kfree(ahp->work_icv);
+               crypto_free_tfm(ahp->tfm);
                kfree(ahp);
        }
        return -EINVAL;
@@ -278,14 +279,10 @@ static void ah_destroy(struct xfrm_state *x)
        if (!ahp)
                return;
 
-       if (ahp->work_icv) {
-               kfree(ahp->work_icv);
-               ahp->work_icv = NULL;
-       }
-       if (ahp->tfm) {
-               crypto_free_tfm(ahp->tfm);
-               ahp->tfm = NULL;
-       }
+       kfree(ahp->work_icv);
+       ahp->work_icv = NULL;
+       crypto_free_tfm(ahp->tfm);
+       ahp->tfm = NULL;
        kfree(ahp);
 }