]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * xfrm4_state.c | |
3 | * | |
4 | * Changes: | |
5 | * YOSHIFUJI Hideaki @USAGI | |
6 | * Split up af-specific portion | |
7 | * | |
8 | */ | |
9 | ||
dd87147e | 10 | #include <net/ip.h> |
1da177e4 LT |
11 | #include <net/xfrm.h> |
12 | #include <linux/pfkeyv2.h> | |
13 | #include <linux/ipsec.h> | |
862b82c6 | 14 | #include <linux/netfilter_ipv4.h> |
bc3b2d7f | 15 | #include <linux/export.h> |
1da177e4 | 16 | |
dd87147e HX |
17 | static 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 | ||
1da177e4 | 24 | static void |
73e5ebb2 | 25 | __xfrm4_init_tempsel(struct xfrm_selector *sel, const struct flowi *fl) |
8444cf71 | 26 | { |
7e1dc7b6 DM |
27 | const struct flowi4 *fl4 = &fl->u.ip4; |
28 | ||
29 | sel->daddr.a4 = fl4->daddr; | |
30 | sel->saddr.a4 = fl4->saddr; | |
31 | sel->dport = xfrm_flowi_dport(fl, &fl4->uli); | |
8444cf71 | 32 | sel->dport_mask = htons(0xffff); |
7e1dc7b6 | 33 | sel->sport = xfrm_flowi_sport(fl, &fl4->uli); |
8444cf71 TE |
34 | sel->sport_mask = htons(0xffff); |
35 | sel->family = AF_INET; | |
36 | sel->prefixlen_d = 32; | |
37 | sel->prefixlen_s = 32; | |
7e1dc7b6 DM |
38 | sel->proto = fl4->flowi4_proto; |
39 | sel->ifindex = fl4->flowi4_oif; | |
8444cf71 TE |
40 | } |
41 | ||
42 | static void | |
19bd6244 DM |
43 | xfrm4_init_temprop(struct xfrm_state *x, const struct xfrm_tmpl *tmpl, |
44 | const xfrm_address_t *daddr, const xfrm_address_t *saddr) | |
1da177e4 | 45 | { |
1da177e4 LT |
46 | x->id = tmpl->id; |
47 | if (x->id.daddr.a4 == 0) | |
48 | x->id.daddr.a4 = daddr->a4; | |
49 | x->props.saddr = tmpl->saddr; | |
50 | if (x->props.saddr.a4 == 0) | |
51 | x->props.saddr.a4 = saddr->a4; | |
52 | x->props.mode = tmpl->mode; | |
53 | x->props.reqid = tmpl->reqid; | |
54 | x->props.family = AF_INET; | |
55 | } | |
56 | ||
36cf9acf HX |
57 | int xfrm4_extract_header(struct sk_buff *skb) |
58 | { | |
b71d1d42 | 59 | const struct iphdr *iph = ip_hdr(skb); |
36cf9acf | 60 | |
732c8bd5 | 61 | XFRM_MODE_SKB_CB(skb)->ihl = sizeof(*iph); |
36cf9acf HX |
62 | XFRM_MODE_SKB_CB(skb)->id = iph->id; |
63 | XFRM_MODE_SKB_CB(skb)->frag_off = iph->frag_off; | |
64 | XFRM_MODE_SKB_CB(skb)->tos = iph->tos; | |
65 | XFRM_MODE_SKB_CB(skb)->ttl = iph->ttl; | |
732c8bd5 | 66 | XFRM_MODE_SKB_CB(skb)->optlen = iph->ihl * 4 - sizeof(*iph); |
36cf9acf HX |
67 | memset(XFRM_MODE_SKB_CB(skb)->flow_lbl, 0, |
68 | sizeof(XFRM_MODE_SKB_CB(skb)->flow_lbl)); | |
69 | ||
70 | return 0; | |
71 | } | |
72 | ||
1da177e4 LT |
73 | static struct xfrm_state_afinfo xfrm4_state_afinfo = { |
74 | .family = AF_INET, | |
36cf9acf | 75 | .proto = IPPROTO_IPIP, |
227620e2 | 76 | .eth_proto = htons(ETH_P_IP), |
17c2a42a | 77 | .owner = THIS_MODULE, |
dd87147e | 78 | .init_flags = xfrm4_init_flags, |
1da177e4 | 79 | .init_tempsel = __xfrm4_init_tempsel, |
8444cf71 | 80 | .init_temprop = xfrm4_init_temprop, |
cdca7265 | 81 | .output = xfrm4_output, |
43a4dea4 | 82 | .output_finish = xfrm4_output_finish, |
227620e2 | 83 | .extract_input = xfrm4_extract_input, |
36cf9acf | 84 | .extract_output = xfrm4_extract_output, |
716062fd | 85 | .transport_finish = xfrm4_transport_finish, |
1da177e4 LT |
86 | }; |
87 | ||
88 | void __init xfrm4_state_init(void) | |
89 | { | |
90 | xfrm_state_register_afinfo(&xfrm4_state_afinfo); | |
91 | } | |
92 | ||
0742fd53 | 93 | #if 0 |
1da177e4 LT |
94 | void __exit xfrm4_state_fini(void) |
95 | { | |
96 | xfrm_state_unregister_afinfo(&xfrm4_state_afinfo); | |
97 | } | |
0742fd53 | 98 | #endif /* 0 */ |
1da177e4 | 99 |