5 * YOSHIFUJI Hideaki @USAGI
6 * Split up af-specific portion
10 #include <linux/slab.h>
11 #include <linux/module.h>
15 static struct kmem_cache
*secpath_cachep __read_mostly
;
17 void __secpath_destroy(struct sec_path
*sp
)
20 for (i
= 0; i
< sp
->len
; i
++)
21 xfrm_state_put(sp
->xvec
[i
]);
22 kmem_cache_free(secpath_cachep
, sp
);
24 EXPORT_SYMBOL(__secpath_destroy
);
26 struct sec_path
*secpath_dup(struct sec_path
*src
)
30 sp
= kmem_cache_alloc(secpath_cachep
, GFP_ATOMIC
);
38 memcpy(sp
, src
, sizeof(*sp
));
39 for (i
= 0; i
< sp
->len
; i
++)
40 xfrm_state_hold(sp
->xvec
[i
]);
42 atomic_set(&sp
->refcnt
, 1);
45 EXPORT_SYMBOL(secpath_dup
);
47 /* Fetch spi and seq from ipsec header */
49 int xfrm_parse_spi(struct sk_buff
*skb
, u8 nexthdr
, __be32
*spi
, __be32
*seq
)
51 int offset
, offset_seq
;
56 hlen
= sizeof(struct ip_auth_hdr
);
57 offset
= offsetof(struct ip_auth_hdr
, spi
);
58 offset_seq
= offsetof(struct ip_auth_hdr
, seq_no
);
61 hlen
= sizeof(struct ip_esp_hdr
);
62 offset
= offsetof(struct ip_esp_hdr
, spi
);
63 offset_seq
= offsetof(struct ip_esp_hdr
, seq_no
);
66 if (!pskb_may_pull(skb
, sizeof(struct ip_comp_hdr
)))
68 *spi
= htonl(ntohs(*(__be16
*)(skb_transport_header(skb
) + 2)));
75 if (!pskb_may_pull(skb
, hlen
))
78 *spi
= *(__be32
*)(skb_transport_header(skb
) + offset
);
79 *seq
= *(__be32
*)(skb_transport_header(skb
) + offset_seq
);
82 EXPORT_SYMBOL(xfrm_parse_spi
);
84 int xfrm_prepare_input(struct xfrm_state
*x
, struct sk_buff
*skb
)
88 err
= x
->outer_mode
->afinfo
->extract_input(x
, skb
);
92 skb
->protocol
= x
->inner_mode
->afinfo
->eth_proto
;
93 return x
->inner_mode
->input2(x
, skb
);
95 EXPORT_SYMBOL(xfrm_prepare_input
);
97 void __init
xfrm_input_init(void)
99 secpath_cachep
= kmem_cache_create("secpath_cache",
100 sizeof(struct sec_path
),
101 0, SLAB_HWCACHE_ALIGN
|SLAB_PANIC
,