blob: f8ed3c3bb928f1b3a083a9b904111eb91eb70894 [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 * xfrm4_state.c
4 *
5 * Changes:
6 * YOSHIFUJI Hideaki @USAGI
7 * Split up af-specific portion
8 *
9 */
10
Herbert Xudd871472005-06-20 13:21:43 -070011#include <net/ip.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <net/xfrm.h>
13#include <linux/pfkeyv2.h>
14#include <linux/ipsec.h>
Herbert Xu862b82c2007-11-13 21:43:11 -080015#include <linux/netfilter_ipv4.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040016#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Herbert Xu36cf9ac2007-11-13 21:40:52 -080018int xfrm4_extract_header(struct sk_buff *skb)
19{
Eric Dumazetb71d1d42011-04-22 04:53:02 +000020 const struct iphdr *iph = ip_hdr(skb);
Herbert Xu36cf9ac2007-11-13 21:40:52 -080021
Herbert Xu732c8bd2008-03-26 16:51:09 -070022 XFRM_MODE_SKB_CB(skb)->ihl = sizeof(*iph);
Herbert Xu36cf9ac2007-11-13 21:40:52 -080023 XFRM_MODE_SKB_CB(skb)->id = iph->id;
24 XFRM_MODE_SKB_CB(skb)->frag_off = iph->frag_off;
25 XFRM_MODE_SKB_CB(skb)->tos = iph->tos;
26 XFRM_MODE_SKB_CB(skb)->ttl = iph->ttl;
Herbert Xu732c8bd2008-03-26 16:51:09 -070027 XFRM_MODE_SKB_CB(skb)->optlen = iph->ihl * 4 - sizeof(*iph);
Herbert Xu36cf9ac2007-11-13 21:40:52 -080028 memset(XFRM_MODE_SKB_CB(skb)->flow_lbl, 0,
29 sizeof(XFRM_MODE_SKB_CB(skb)->flow_lbl));
30
31 return 0;
32}
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034static struct xfrm_state_afinfo xfrm4_state_afinfo = {
35 .family = AF_INET,
Herbert Xu36cf9ac2007-11-13 21:40:52 -080036 .proto = IPPROTO_IPIP,
Miika Komucdca7262007-02-06 14:24:56 -080037 .output = xfrm4_output,
Steffen Klassert43a4dea2011-05-09 19:36:38 +000038 .output_finish = xfrm4_output_finish,
Herbert Xu227620e2007-11-13 21:41:28 -080039 .extract_input = xfrm4_extract_input,
Herbert Xu36cf9ac2007-11-13 21:40:52 -080040 .extract_output = xfrm4_extract_output,
Herbert Xu716062f2007-11-13 21:44:23 -080041 .transport_finish = xfrm4_transport_finish,
Hannes Frederic Sowa628e3412013-08-14 13:05:23 +020042 .local_error = xfrm4_local_error,
Linus Torvalds1da177e2005-04-16 15:20:36 -070043};
44
45void __init xfrm4_state_init(void)
46{
47 xfrm_state_register_afinfo(&xfrm4_state_afinfo);
48}