x86: 64-bit, add the new split_large_page() function
[wrt350n-kernel.git] / net / ipv6 / xfrm6_mode_beet.c
blob0527d11c1ae37a304964cd5c85baf4d99e3b6fbe
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 static void xfrm6_beet_make_header(struct sk_buff *skb)
24 struct ipv6hdr *iph = ipv6_hdr(skb);
26 iph->version = 6;
28 memcpy(iph->flow_lbl, XFRM_MODE_SKB_CB(skb)->flow_lbl,
29 sizeof(iph->flow_lbl));
30 iph->nexthdr = XFRM_MODE_SKB_CB(skb)->protocol;
32 ipv6_change_dsfield(iph, 0, XFRM_MODE_SKB_CB(skb)->tos);
33 iph->hop_limit = XFRM_MODE_SKB_CB(skb)->ttl;
36 /* Add encapsulation header.
38 * The top IP header will be constructed per draft-nikander-esp-beet-mode-06.txt.
40 static int xfrm6_beet_output(struct xfrm_state *x, struct sk_buff *skb)
42 struct ipv6hdr *top_iph;
44 skb_set_network_header(skb, -x->props.header_len);
45 skb->mac_header = skb->network_header +
46 offsetof(struct ipv6hdr, nexthdr);
47 skb->transport_header = skb->network_header + sizeof(*top_iph);
49 xfrm6_beet_make_header(skb);
51 top_iph = ipv6_hdr(skb);
53 ipv6_addr_copy(&top_iph->saddr, (struct in6_addr *)&x->props.saddr);
54 ipv6_addr_copy(&top_iph->daddr, (struct in6_addr *)&x->id.daddr);
55 return 0;
58 static int xfrm6_beet_input(struct xfrm_state *x, struct sk_buff *skb)
60 struct ipv6hdr *ip6h;
61 const unsigned char *old_mac;
62 int size = sizeof(struct ipv6hdr);
63 int err;
65 err = skb_cow_head(skb, size + skb->mac_len);
66 if (err)
67 goto out;
69 __skb_push(skb, size);
70 skb_reset_network_header(skb);
72 old_mac = skb_mac_header(skb);
73 skb_set_mac_header(skb, -skb->mac_len);
74 memmove(skb_mac_header(skb), old_mac, skb->mac_len);
76 xfrm6_beet_make_header(skb);
78 ip6h = ipv6_hdr(skb);
79 ip6h->payload_len = htons(skb->len - size);
80 ipv6_addr_copy(&ip6h->daddr, (struct in6_addr *) &x->sel.daddr.a6);
81 ipv6_addr_copy(&ip6h->saddr, (struct in6_addr *) &x->sel.saddr.a6);
82 err = 0;
83 out:
84 return err;
87 static struct xfrm_mode xfrm6_beet_mode = {
88 .input2 = xfrm6_beet_input,
89 .input = xfrm_prepare_input,
90 .output2 = xfrm6_beet_output,
91 .output = xfrm6_prepare_output,
92 .owner = THIS_MODULE,
93 .encap = XFRM_MODE_BEET,
94 .flags = XFRM_MODE_FLAG_TUNNEL,
97 static int __init xfrm6_beet_init(void)
99 return xfrm_register_mode(&xfrm6_beet_mode, AF_INET6);
102 static void __exit xfrm6_beet_exit(void)
104 int err;
106 err = xfrm_unregister_mode(&xfrm6_beet_mode, AF_INET6);
107 BUG_ON(err);
110 module_init(xfrm6_beet_init);
111 module_exit(xfrm6_beet_exit);
112 MODULE_LICENSE("GPL");
113 MODULE_ALIAS_XFRM_MODE(AF_INET6, XFRM_MODE_BEET);