blob: 13d54a1c3337bd311c7245f331367296f07b0558 [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>
14
15static struct xfrm_state_afinfo xfrm4_state_afinfo;
16
Herbert Xudd871472005-06-20 13:21:43 -070017static int xfrm4_init_flags(struct xfrm_state *x)
18{
19 if (ipv4_config.no_pmtu_disc)
20 x->props.flags |= XFRM_STATE_NOPMTUDISC;
21 return 0;
22}
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024static void
25__xfrm4_init_tempsel(struct xfrm_state *x, struct flowi *fl,
26 struct xfrm_tmpl *tmpl,
27 xfrm_address_t *daddr, xfrm_address_t *saddr)
28{
29 x->sel.daddr.a4 = fl->fl4_dst;
30 x->sel.saddr.a4 = fl->fl4_src;
31 x->sel.dport = xfrm_flowi_dport(fl);
Al Viro8f83f232006-09-27 18:46:11 -070032 x->sel.dport_mask = htons(0xffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 x->sel.sport = xfrm_flowi_sport(fl);
Al Viro8f83f232006-09-27 18:46:11 -070034 x->sel.sport_mask = htons(0xffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 x->sel.prefixlen_d = 32;
36 x->sel.prefixlen_s = 32;
37 x->sel.proto = fl->proto;
38 x->sel.ifindex = fl->oif;
39 x->id = tmpl->id;
40 if (x->id.daddr.a4 == 0)
41 x->id.daddr.a4 = daddr->a4;
42 x->props.saddr = tmpl->saddr;
43 if (x->props.saddr.a4 == 0)
44 x->props.saddr.a4 = saddr->a4;
45 x->props.mode = tmpl->mode;
46 x->props.reqid = tmpl->reqid;
47 x->props.family = AF_INET;
48}
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050static struct xfrm_state_afinfo xfrm4_state_afinfo = {
51 .family = AF_INET,
Herbert Xu17c2a422007-10-17 21:33:12 -070052 .owner = THIS_MODULE,
Herbert Xudd871472005-06-20 13:21:43 -070053 .init_flags = xfrm4_init_flags,
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 .init_tempsel = __xfrm4_init_tempsel,
Miika Komucdca7262007-02-06 14:24:56 -080055 .output = xfrm4_output,
Linus Torvalds1da177e2005-04-16 15:20:36 -070056};
57
58void __init xfrm4_state_init(void)
59{
60 xfrm_state_register_afinfo(&xfrm4_state_afinfo);
61}
62
Adrian Bunk0742fd52005-08-09 19:35:47 -070063#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070064void __exit xfrm4_state_fini(void)
65{
66 xfrm_state_unregister_afinfo(&xfrm4_state_afinfo);
67}
Adrian Bunk0742fd52005-08-09 19:35:47 -070068#endif /* 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070069