blob: 07735ed280d720f32ac7269c5099c1e840d866d7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * xfrm4_state.c
3 *
4 * Changes:
5 * YOSHIFUJI Hideaki @USAGI
6 * Split up af-specific portion
7 *
8 */
9
Herbert Xudd871472005-06-20 13:21:43 -070010#include <net/ip.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <net/xfrm.h>
12#include <linux/pfkeyv2.h>
13#include <linux/ipsec.h>
Herbert Xu862b82c2007-11-13 21:43:11 -080014#include <linux/netfilter_ipv4.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16static struct xfrm_state_afinfo xfrm4_state_afinfo;
17
Herbert Xudd871472005-06-20 13:21:43 -070018static int xfrm4_init_flags(struct xfrm_state *x)
19{
20 if (ipv4_config.no_pmtu_disc)
21 x->props.flags |= XFRM_STATE_NOPMTUDISC;
22 return 0;
23}
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025static void
26__xfrm4_init_tempsel(struct xfrm_state *x, struct flowi *fl,
27 struct xfrm_tmpl *tmpl,
28 xfrm_address_t *daddr, xfrm_address_t *saddr)
29{
30 x->sel.daddr.a4 = fl->fl4_dst;
31 x->sel.saddr.a4 = fl->fl4_src;
32 x->sel.dport = xfrm_flowi_dport(fl);
Al Viro8f83f232006-09-27 18:46:11 -070033 x->sel.dport_mask = htons(0xffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 x->sel.sport = xfrm_flowi_sport(fl);
Al Viro8f83f232006-09-27 18:46:11 -070035 x->sel.sport_mask = htons(0xffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 x->sel.prefixlen_d = 32;
37 x->sel.prefixlen_s = 32;
38 x->sel.proto = fl->proto;
39 x->sel.ifindex = fl->oif;
40 x->id = tmpl->id;
41 if (x->id.daddr.a4 == 0)
42 x->id.daddr.a4 = daddr->a4;
43 x->props.saddr = tmpl->saddr;
44 if (x->props.saddr.a4 == 0)
45 x->props.saddr.a4 = saddr->a4;
46 x->props.mode = tmpl->mode;
47 x->props.reqid = tmpl->reqid;
48 x->props.family = AF_INET;
49}
50
Herbert Xu36cf9ac2007-11-13 21:40:52 -080051int xfrm4_extract_header(struct sk_buff *skb)
52{
53 struct iphdr *iph = ip_hdr(skb);
54
Herbert Xu732c8bd2008-03-26 16:51:09 -070055 XFRM_MODE_SKB_CB(skb)->ihl = sizeof(*iph);
Herbert Xu36cf9ac2007-11-13 21:40:52 -080056 XFRM_MODE_SKB_CB(skb)->id = iph->id;
57 XFRM_MODE_SKB_CB(skb)->frag_off = iph->frag_off;
58 XFRM_MODE_SKB_CB(skb)->tos = iph->tos;
59 XFRM_MODE_SKB_CB(skb)->ttl = iph->ttl;
Herbert Xu732c8bd2008-03-26 16:51:09 -070060 XFRM_MODE_SKB_CB(skb)->optlen = iph->ihl * 4 - sizeof(*iph);
Herbert Xu36cf9ac2007-11-13 21:40:52 -080061 memset(XFRM_MODE_SKB_CB(skb)->flow_lbl, 0,
62 sizeof(XFRM_MODE_SKB_CB(skb)->flow_lbl));
63
64 return 0;
65}
66
Linus Torvalds1da177e2005-04-16 15:20:36 -070067static struct xfrm_state_afinfo xfrm4_state_afinfo = {
68 .family = AF_INET,
Herbert Xu36cf9ac2007-11-13 21:40:52 -080069 .proto = IPPROTO_IPIP,
Herbert Xu227620e2007-11-13 21:41:28 -080070 .eth_proto = htons(ETH_P_IP),
Herbert Xu17c2a422007-10-17 21:33:12 -070071 .owner = THIS_MODULE,
Herbert Xudd871472005-06-20 13:21:43 -070072 .init_flags = xfrm4_init_flags,
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 .init_tempsel = __xfrm4_init_tempsel,
Miika Komucdca7262007-02-06 14:24:56 -080074 .output = xfrm4_output,
Herbert Xu227620e2007-11-13 21:41:28 -080075 .extract_input = xfrm4_extract_input,
Herbert Xu36cf9ac2007-11-13 21:40:52 -080076 .extract_output = xfrm4_extract_output,
Herbert Xu716062f2007-11-13 21:44:23 -080077 .transport_finish = xfrm4_transport_finish,
Linus Torvalds1da177e2005-04-16 15:20:36 -070078};
79
80void __init xfrm4_state_init(void)
81{
82 xfrm_state_register_afinfo(&xfrm4_state_afinfo);
83}
84
Adrian Bunk0742fd52005-08-09 19:35:47 -070085#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070086void __exit xfrm4_state_fini(void)
87{
88 xfrm_state_unregister_afinfo(&xfrm4_state_afinfo);
89}
Adrian Bunk0742fd52005-08-09 19:35:47 -070090#endif /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091