blob: 78daadecbdef5f0beabaa4acc2ce9b4a8a189d6a [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * xfrm6_state.c: based on xfrm4_state.c
4 *
5 * Authors:
6 * Mitsuru KANDA @USAGI
Ian Morris67ba4152014-08-24 21:53:10 +01007 * Kazunori MIYAZAWA @USAGI
8 * Kunihiro Ishiguro <kunihiro@ipinfusion.com>
9 * IPv6 support
10 * YOSHIFUJI Hideaki @USAGI
11 * Split up af-specific portion
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +090012 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 */
14
15#include <net/xfrm.h>
16#include <linux/pfkeyv2.h>
17#include <linux/ipsec.h>
Herbert Xu862b82c2007-11-13 21:43:11 -080018#include <linux/netfilter_ipv6.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040019#include <linux/export.h>
Herbert Xu36cf9ac2007-11-13 21:40:52 -080020#include <net/dsfield.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <net/ipv6.h>
Patrick McHardyee51b1b2006-01-13 14:34:36 -080022#include <net/addrconf.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Herbert Xu36cf9ac2007-11-13 21:40:52 -080024int xfrm6_extract_header(struct sk_buff *skb)
25{
26 struct ipv6hdr *iph = ipv6_hdr(skb);
27
Herbert Xu732c8bd2008-03-26 16:51:09 -070028 XFRM_MODE_SKB_CB(skb)->ihl = sizeof(*iph);
Herbert Xu36cf9ac2007-11-13 21:40:52 -080029 XFRM_MODE_SKB_CB(skb)->id = 0;
30 XFRM_MODE_SKB_CB(skb)->frag_off = htons(IP_DF);
31 XFRM_MODE_SKB_CB(skb)->tos = ipv6_get_dsfield(iph);
32 XFRM_MODE_SKB_CB(skb)->ttl = iph->hop_limit;
Herbert Xu732c8bd2008-03-26 16:51:09 -070033 XFRM_MODE_SKB_CB(skb)->optlen = 0;
Herbert Xu36cf9ac2007-11-13 21:40:52 -080034 memcpy(XFRM_MODE_SKB_CB(skb)->flow_lbl, iph->flow_lbl,
35 sizeof(XFRM_MODE_SKB_CB(skb)->flow_lbl));
36
37 return 0;
38}
39
Linus Torvalds1da177e2005-04-16 15:20:36 -070040static struct xfrm_state_afinfo xfrm6_state_afinfo = {
41 .family = AF_INET6,
Herbert Xu36cf9ac2007-11-13 21:40:52 -080042 .proto = IPPROTO_IPV6,
Miika Komucdca7262007-02-06 14:24:56 -080043 .output = xfrm6_output,
Steffen Klassert43a4dea2011-05-09 19:36:38 +000044 .output_finish = xfrm6_output_finish,
Herbert Xu227620e2007-11-13 21:41:28 -080045 .extract_input = xfrm6_extract_input,
Herbert Xu36cf9ac2007-11-13 21:40:52 -080046 .extract_output = xfrm6_extract_output,
Herbert Xu716062f2007-11-13 21:44:23 -080047 .transport_finish = xfrm6_transport_finish,
Hannes Frederic Sowa628e3412013-08-14 13:05:23 +020048 .local_error = xfrm6_local_error,
Linus Torvalds1da177e2005-04-16 15:20:36 -070049};
50
Daniel Lezcano0013cab2007-12-07 00:42:11 -080051int __init xfrm6_state_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052{
Daniel Lezcano0013cab2007-12-07 00:42:11 -080053 return xfrm_state_register_afinfo(&xfrm6_state_afinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054}
55
56void xfrm6_state_fini(void)
57{
58 xfrm_state_unregister_afinfo(&xfrm6_state_afinfo);
59}