synclink_gt endianness annotations
[pv_ops_mirror.git] / net / ipv6 / xfrm6_mode_beet.c
blob13bb1e85676467e8e3a03d19b38518736d44e2ce
1 /*
2 * xfrm6_mode_beet.c - BEET mode encapsulation for IPv6.
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 */
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>
22 /* Add encapsulation header.
24 * The top IP header will be constructed per draft-nikander-esp-beet-mode-06.txt.
26 static int xfrm6_beet_output(struct xfrm_state *x, struct sk_buff *skb)
28 struct ipv6hdr *iph, *top_iph;
29 u8 *prevhdr;
30 int hdr_len;
32 iph = ipv6_hdr(skb);
34 hdr_len = ip6_find_1stfragopt(skb, &prevhdr);
36 skb_set_mac_header(skb, (prevhdr - x->props.header_len) - skb->data);
37 skb_set_network_header(skb, -x->props.header_len);
38 skb->transport_header = skb->network_header + hdr_len;
39 __skb_pull(skb, hdr_len);
41 top_iph = ipv6_hdr(skb);
42 memmove(top_iph, iph, hdr_len);
44 ipv6_addr_copy(&top_iph->saddr, (struct in6_addr *)&x->props.saddr);
45 ipv6_addr_copy(&top_iph->daddr, (struct in6_addr *)&x->id.daddr);
47 return 0;
50 static int xfrm6_beet_input(struct xfrm_state *x, struct sk_buff *skb)
52 struct ipv6hdr *ip6h;
53 const unsigned char *old_mac;
54 int size = sizeof(struct ipv6hdr);
55 int err = -EINVAL;
57 if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
58 goto out;
60 skb_push(skb, size);
61 memmove(skb->data, skb_network_header(skb), size);
62 skb_reset_network_header(skb);
64 old_mac = skb_mac_header(skb);
65 skb_set_mac_header(skb, -skb->mac_len);
66 memmove(skb_mac_header(skb), old_mac, skb->mac_len);
68 ip6h = ipv6_hdr(skb);
69 ip6h->payload_len = htons(skb->len - size);
70 ipv6_addr_copy(&ip6h->daddr, (struct in6_addr *) &x->sel.daddr.a6);
71 ipv6_addr_copy(&ip6h->saddr, (struct in6_addr *) &x->sel.saddr.a6);
72 err = 0;
73 out:
74 return err;
77 static struct xfrm_mode xfrm6_beet_mode = {
78 .input = xfrm6_beet_input,
79 .output = xfrm6_beet_output,
80 .owner = THIS_MODULE,
81 .encap = XFRM_MODE_BEET,
84 static int __init xfrm6_beet_init(void)
86 return xfrm_register_mode(&xfrm6_beet_mode, AF_INET6);
89 static void __exit xfrm6_beet_exit(void)
91 int err;
93 err = xfrm_unregister_mode(&xfrm6_beet_mode, AF_INET6);
94 BUG_ON(err);
97 module_init(xfrm6_beet_init);
98 module_exit(xfrm6_beet_exit);
99 MODULE_LICENSE("GPL");
100 MODULE_ALIAS_XFRM_MODE(AF_INET6, XFRM_MODE_BEET);