[IPSEC] esp: Remove NAT-T checksum invalidation for BEET
[deliverable/linux.git] / net / ipv6 / xfrm6_mode_beet.c
CommitLineData
0a69452c
DB
1/*
2 * xfrm6_mode_beet.c - BEET mode encapsulation for IPv6.
3 *
4 * Copyright (c) 2006 Diego Beltrami <diego.beltrami@gmail.com>
5 * Miika Komu <miika@iki.fi>
6 * Herbert Xu <herbert@gondor.apana.org.au>
7 * Abhinav Pathak <abhinav.pathak@hiit.fi>
8 * Jeff Ahrenholz <ahrenholz@gmail.com>
9 */
10
11#include <linux/init.h>
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/skbuff.h>
15#include <linux/stringify.h>
16#include <net/dsfield.h>
17#include <net/dst.h>
18#include <net/inet_ecn.h>
19#include <net/ipv6.h>
20#include <net/xfrm.h>
21
22/* Add encapsulation header.
23 *
24 * The top IP header will be constructed per draft-nikander-esp-beet-mode-06.txt.
25 * The following fields in it shall be filled in by x->type->output:
26 * payload_len
27 *
28 * On exit, skb->h will be set to the start of the encapsulation header to be
007f0211
HX
29 * filled in by x->type->output and the mac header will be set to the
30 * nextheader field of the extension header directly preceding the
31 * encapsulation header, or in its absence, that of the top IP header.
32 * The value of skb->data and the network header will always point to the
33 * top IP header.
0a69452c
DB
34 */
35static int xfrm6_beet_output(struct xfrm_state *x, struct sk_buff *skb)
36{
37 struct ipv6hdr *iph, *top_iph;
38 u8 *prevhdr;
39 int hdr_len;
40
41 skb_push(skb, x->props.header_len);
0660e03f 42 iph = ipv6_hdr(skb);
0a69452c
DB
43
44 hdr_len = ip6_find_1stfragopt(skb, &prevhdr);
0a69452c
DB
45 memmove(skb->data, iph, hdr_len);
46
007f0211 47 skb_set_mac_header(skb, offsetof(struct ipv6hdr, nexthdr));
c1d2bbe1 48 skb_reset_network_header(skb);
007f0211 49 skb_set_transport_header(skb, sizeof(struct ipv6hdr));
0660e03f 50 top_iph = ipv6_hdr(skb);
0a69452c
DB
51
52 ipv6_addr_copy(&top_iph->saddr, (struct in6_addr *)&x->props.saddr);
53 ipv6_addr_copy(&top_iph->daddr, (struct in6_addr *)&x->id.daddr);
54
55 return 0;
56}
57
58static int xfrm6_beet_input(struct xfrm_state *x, struct sk_buff *skb)
59{
60 struct ipv6hdr *ip6h;
39f69c6f 61 const unsigned char *old_mac;
0a69452c
DB
62 int size = sizeof(struct ipv6hdr);
63 int err = -EINVAL;
64
65 if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
66 goto out;
67
68 skb_push(skb, size);
d56f90a7 69 memmove(skb->data, skb_network_header(skb), size);
c1d2bbe1 70 skb_reset_network_header(skb);
0a69452c 71
98e399f8 72 old_mac = skb_mac_header(skb);
39f69c6f 73 skb_set_mac_header(skb, -skb->mac_len);
98e399f8 74 memmove(skb_mac_header(skb), old_mac, skb->mac_len);
0a69452c 75
0660e03f 76 ip6h = ipv6_hdr(skb);
0a69452c
DB
77 ip6h->payload_len = htons(skb->len - size);
78 ipv6_addr_copy(&ip6h->daddr, (struct in6_addr *) &x->sel.daddr.a6);
79 ipv6_addr_copy(&ip6h->saddr, (struct in6_addr *) &x->sel.saddr.a6);
80 err = 0;
81out:
82 return err;
83}
84
85static struct xfrm_mode xfrm6_beet_mode = {
86 .input = xfrm6_beet_input,
87 .output = xfrm6_beet_output,
88 .owner = THIS_MODULE,
89 .encap = XFRM_MODE_BEET,
90};
91
92static int __init xfrm6_beet_init(void)
93{
94 return xfrm_register_mode(&xfrm6_beet_mode, AF_INET6);
95}
96
97static void __exit xfrm6_beet_exit(void)
98{
99 int err;
100
101 err = xfrm_unregister_mode(&xfrm6_beet_mode, AF_INET6);
102 BUG_ON(err);
103}
104
105module_init(xfrm6_beet_init);
106module_exit(xfrm6_beet_exit);
107MODULE_LICENSE("GPL");
108MODULE_ALIAS_XFRM_MODE(AF_INET6, XFRM_MODE_BEET);
This page took 0.112158 seconds and 5 git commands to generate.