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>
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>
18 #include <net/inet_ecn.h>
22 /* Add encapsulation header.
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:
28 * On exit, skb->h will be set to the start of the encapsulation header to be
29 * filled in by x->type->output and skb->nh will be set to the nextheader field
30 * of the extension header directly preceding the encapsulation header, or in
31 * its absence, that of the top IP header. The value of skb->data will always
32 * point to the top IP header.
34 static int xfrm6_beet_output(struct xfrm_state
*x
, struct sk_buff
*skb
)
36 struct ipv6hdr
*iph
, *top_iph
;
40 skb_push(skb
, x
->props
.header_len
);
43 hdr_len
= ip6_find_1stfragopt(skb
, &prevhdr
);
44 skb
->nh
.raw
= prevhdr
- x
->props
.header_len
;
45 skb
->h
.raw
= skb
->data
+ hdr_len
;
46 memmove(skb
->data
, iph
, hdr_len
);
48 skb
->nh
.raw
= skb
->data
;
49 top_iph
= skb
->nh
.ipv6h
;
50 skb
->nh
.raw
= &top_iph
->nexthdr
;
51 skb
->h
.ipv6h
= top_iph
+ 1;
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
);
59 static int xfrm6_beet_input(struct xfrm_state
*x
, struct sk_buff
*skb
)
62 int size
= sizeof(struct ipv6hdr
);
65 if (!pskb_may_pull(skb
, sizeof(struct ipv6hdr
)))
69 memmove(skb
->data
, skb
->nh
.raw
, size
);
70 skb
->nh
.raw
= skb
->data
;
72 skb
->mac
.raw
= memmove(skb
->data
- skb
->mac_len
,
73 skb
->mac
.raw
, skb
->mac_len
);
76 ip6h
->payload_len
= htons(skb
->len
- size
);
77 ipv6_addr_copy(&ip6h
->daddr
, (struct in6_addr
*) &x
->sel
.daddr
.a6
);
78 ipv6_addr_copy(&ip6h
->saddr
, (struct in6_addr
*) &x
->sel
.saddr
.a6
);
84 static struct xfrm_mode xfrm6_beet_mode
= {
85 .input
= xfrm6_beet_input
,
86 .output
= xfrm6_beet_output
,
88 .encap
= XFRM_MODE_BEET
,
91 static int __init
xfrm6_beet_init(void)
93 return xfrm_register_mode(&xfrm6_beet_mode
, AF_INET6
);
96 static void __exit
xfrm6_beet_exit(void)
100 err
= xfrm_unregister_mode(&xfrm6_beet_mode
, AF_INET6
);
104 module_init(xfrm6_beet_init
);
105 module_exit(xfrm6_beet_exit
);
106 MODULE_LICENSE("GPL");
107 MODULE_ALIAS_XFRM_MODE(AF_INET6
, XFRM_MODE_BEET
);