5 * YOSHIFUJI Hideaki @USAGI
6 * Split up af-specific portion
12 #include <linux/pfkeyv2.h>
13 #include <linux/ipsec.h>
14 #include <linux/netfilter_ipv4.h>
16 static int xfrm4_init_flags(struct xfrm_state *x)
18 if (ipv4_config.no_pmtu_disc)
19 x->props.flags |= XFRM_STATE_NOPMTUDISC;
24 __xfrm4_init_tempsel(struct xfrm_selector *sel, const struct flowi *fl)
26 sel->daddr.a4 = fl->fl4_dst;
27 sel->saddr.a4 = fl->fl4_src;
28 sel->dport = xfrm_flowi_dport(fl, &fl->u.ip4.uli);
29 sel->dport_mask = htons(0xffff);
30 sel->sport = xfrm_flowi_sport(fl, &fl->u.ip4.uli);
31 sel->sport_mask = htons(0xffff);
32 sel->family = AF_INET;
33 sel->prefixlen_d = 32;
34 sel->prefixlen_s = 32;
35 sel->proto = fl->flowi_proto;
36 sel->ifindex = fl->flowi_oif;
40 xfrm4_init_temprop(struct xfrm_state *x, const struct xfrm_tmpl *tmpl,
41 const xfrm_address_t *daddr, const xfrm_address_t *saddr)
44 if (x->id.daddr.a4 == 0)
45 x->id.daddr.a4 = daddr->a4;
46 x->props.saddr = tmpl->saddr;
47 if (x->props.saddr.a4 == 0)
48 x->props.saddr.a4 = saddr->a4;
49 x->props.mode = tmpl->mode;
50 x->props.reqid = tmpl->reqid;
51 x->props.family = AF_INET;
54 int xfrm4_extract_header(struct sk_buff *skb)
56 struct iphdr *iph = ip_hdr(skb);
58 XFRM_MODE_SKB_CB(skb)->ihl = sizeof(*iph);
59 XFRM_MODE_SKB_CB(skb)->id = iph->id;
60 XFRM_MODE_SKB_CB(skb)->frag_off = iph->frag_off;
61 XFRM_MODE_SKB_CB(skb)->tos = iph->tos;
62 XFRM_MODE_SKB_CB(skb)->ttl = iph->ttl;
63 XFRM_MODE_SKB_CB(skb)->optlen = iph->ihl * 4 - sizeof(*iph);
64 memset(XFRM_MODE_SKB_CB(skb)->flow_lbl, 0,
65 sizeof(XFRM_MODE_SKB_CB(skb)->flow_lbl));
70 static struct xfrm_state_afinfo xfrm4_state_afinfo = {
72 .proto = IPPROTO_IPIP,
73 .eth_proto = htons(ETH_P_IP),
75 .init_flags = xfrm4_init_flags,
76 .init_tempsel = __xfrm4_init_tempsel,
77 .init_temprop = xfrm4_init_temprop,
78 .output = xfrm4_output,
79 .extract_input = xfrm4_extract_input,
80 .extract_output = xfrm4_extract_output,
81 .transport_finish = xfrm4_transport_finish,
84 void __init xfrm4_state_init(void)
86 xfrm_state_register_afinfo(&xfrm4_state_afinfo);
90 void __exit xfrm4_state_fini(void)
92 xfrm_state_unregister_afinfo(&xfrm4_state_afinfo);