Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * xfrm6_state.c: based on xfrm4_state.c |
| 4 | * |
| 5 | * Authors: |
| 6 | * Mitsuru KANDA @USAGI |
Ian Morris | 67ba415 | 2014-08-24 21:53:10 +0100 | [diff] [blame] | 7 | * Kazunori MIYAZAWA @USAGI |
| 8 | * Kunihiro Ishiguro <kunihiro@ipinfusion.com> |
| 9 | * IPv6 support |
| 10 | * YOSHIFUJI Hideaki @USAGI |
| 11 | * Split up af-specific portion |
YOSHIFUJI Hideaki | 1ab1457 | 2007-02-09 23:24:49 +0900 | [diff] [blame] | 12 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #include <net/xfrm.h> |
| 16 | #include <linux/pfkeyv2.h> |
| 17 | #include <linux/ipsec.h> |
Herbert Xu | 862b82c | 2007-11-13 21:43:11 -0800 | [diff] [blame] | 18 | #include <linux/netfilter_ipv6.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 19 | #include <linux/export.h> |
Herbert Xu | 36cf9ac | 2007-11-13 21:40:52 -0800 | [diff] [blame] | 20 | #include <net/dsfield.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <net/ipv6.h> |
Patrick McHardy | ee51b1b | 2006-01-13 14:34:36 -0800 | [diff] [blame] | 22 | #include <net/addrconf.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Herbert Xu | 36cf9ac | 2007-11-13 21:40:52 -0800 | [diff] [blame] | 24 | int xfrm6_extract_header(struct sk_buff *skb) |
| 25 | { |
| 26 | struct ipv6hdr *iph = ipv6_hdr(skb); |
| 27 | |
Herbert Xu | 732c8bd | 2008-03-26 16:51:09 -0700 | [diff] [blame] | 28 | XFRM_MODE_SKB_CB(skb)->ihl = sizeof(*iph); |
Herbert Xu | 36cf9ac | 2007-11-13 21:40:52 -0800 | [diff] [blame] | 29 | 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 Xu | 732c8bd | 2008-03-26 16:51:09 -0700 | [diff] [blame] | 33 | XFRM_MODE_SKB_CB(skb)->optlen = 0; |
Herbert Xu | 36cf9ac | 2007-11-13 21:40:52 -0800 | [diff] [blame] | 34 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | static struct xfrm_state_afinfo xfrm6_state_afinfo = { |
| 41 | .family = AF_INET6, |
Herbert Xu | 36cf9ac | 2007-11-13 21:40:52 -0800 | [diff] [blame] | 42 | .proto = IPPROTO_IPV6, |
Miika Komu | cdca726 | 2007-02-06 14:24:56 -0800 | [diff] [blame] | 43 | .output = xfrm6_output, |
Steffen Klassert | 43a4dea | 2011-05-09 19:36:38 +0000 | [diff] [blame] | 44 | .output_finish = xfrm6_output_finish, |
Herbert Xu | 227620e | 2007-11-13 21:41:28 -0800 | [diff] [blame] | 45 | .extract_input = xfrm6_extract_input, |
Herbert Xu | 36cf9ac | 2007-11-13 21:40:52 -0800 | [diff] [blame] | 46 | .extract_output = xfrm6_extract_output, |
Herbert Xu | 716062f | 2007-11-13 21:44:23 -0800 | [diff] [blame] | 47 | .transport_finish = xfrm6_transport_finish, |
Hannes Frederic Sowa | 628e341 | 2013-08-14 13:05:23 +0200 | [diff] [blame] | 48 | .local_error = xfrm6_local_error, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | }; |
| 50 | |
Daniel Lezcano | 0013cab | 2007-12-07 00:42:11 -0800 | [diff] [blame] | 51 | int __init xfrm6_state_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { |
Daniel Lezcano | 0013cab | 2007-12-07 00:42:11 -0800 | [diff] [blame] | 53 | return xfrm_state_register_afinfo(&xfrm6_state_afinfo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | void xfrm6_state_fini(void) |
| 57 | { |
| 58 | xfrm_state_unregister_afinfo(&xfrm6_state_afinfo); |
| 59 | } |