xref: /openbmc/linux/net/ipv4/xfrm4_state.c (revision 5e012745)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * xfrm4_state.c
4  *
5  * Changes:
6  * 	YOSHIFUJI Hideaki @USAGI
7  * 		Split up af-specific portion
8  *
9  */
10 
11 #include <net/ip.h>
12 #include <net/xfrm.h>
13 #include <linux/pfkeyv2.h>
14 #include <linux/ipsec.h>
15 #include <linux/netfilter_ipv4.h>
16 #include <linux/export.h>
17 
18 int xfrm4_extract_header(struct sk_buff *skb)
19 {
20 	const struct iphdr *iph = ip_hdr(skb);
21 
22 	XFRM_MODE_SKB_CB(skb)->ihl = sizeof(*iph);
23 	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;
27 	XFRM_MODE_SKB_CB(skb)->optlen = iph->ihl * 4 - sizeof(*iph);
28 	memset(XFRM_MODE_SKB_CB(skb)->flow_lbl, 0,
29 	       sizeof(XFRM_MODE_SKB_CB(skb)->flow_lbl));
30 
31 	return 0;
32 }
33 
34 static struct xfrm_state_afinfo xfrm4_state_afinfo = {
35 	.family			= AF_INET,
36 	.proto			= IPPROTO_IPIP,
37 	.output			= xfrm4_output,
38 	.output_finish		= xfrm4_output_finish,
39 	.extract_input		= xfrm4_extract_input,
40 	.extract_output		= xfrm4_extract_output,
41 	.transport_finish	= xfrm4_transport_finish,
42 	.local_error		= xfrm4_local_error,
43 };
44 
45 void __init xfrm4_state_init(void)
46 {
47 	xfrm_state_register_afinfo(&xfrm4_state_afinfo);
48 }
49