2 * xfrm6_input.c: based on net/ipv4/xfrm4_input.c
6 * Kazunori MIYAZAWA @USAGI
7 * Kunihiro Ishiguro <kunihiro@ipinfusion.com>
8 * YOSHIFUJI Hideaki @USAGI
12 #include <linux/module.h>
13 #include <linux/string.h>
14 #include <linux/netfilter.h>
15 #include <linux/netfilter_ipv6.h>
19 int xfrm6_extract_input(struct xfrm_state *x, struct sk_buff *skb)
21 return xfrm6_extract_header(skb);
24 int xfrm6_rcv_spi(struct sk_buff *skb, int nexthdr, __be32 spi)
26 XFRM_SPI_SKB_CB(skb)->daddroff = offsetof(struct ipv6hdr, daddr);
27 return xfrm_input(skb, nexthdr, spi, 0);
29 EXPORT_SYMBOL(xfrm6_rcv_spi);
31 int xfrm6_transport_finish(struct sk_buff *skb, int async)
33 skb_network_header(skb)[IP6CB(skb)->nhoff] =
34 XFRM_MODE_SKB_CB(skb)->protocol;
36 #ifdef CONFIG_NETFILTER
37 ipv6_hdr(skb)->payload_len = htons(skb->len);
38 __skb_push(skb, skb->data - skb_network_header(skb));
40 NF_HOOK(PF_INET6, NF_IP6_PRE_ROUTING, skb, skb->dev, NULL,
48 int xfrm6_rcv(struct sk_buff *skb)
50 return xfrm6_rcv_spi(skb, skb_network_header(skb)[IP6CB(skb)->nhoff],
54 EXPORT_SYMBOL(xfrm6_rcv);
56 int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr,
57 xfrm_address_t *saddr, u8 proto)
59 struct xfrm_state *x = NULL;
62 struct xfrm_state *xfrm_vec_one = NULL;
66 xany = (xfrm_address_t *)&in6addr_any;
68 for (i = 0; i < 3; i++) {
69 xfrm_address_t *dst, *src;
76 /* lookup state with wild-card source address */
83 /* lookup state with wild-card addresses */
84 wildcard = 1; /* XXX */
90 x = xfrm_state_lookup_byaddr(dst, src, proto, AF_INET6);
97 if ((x->props.flags & XFRM_STATE_WILDRECV) == 0) {
98 spin_unlock(&x->lock);
105 if (unlikely(x->km.state != XFRM_STATE_VALID)) {
106 spin_unlock(&x->lock);
111 if (xfrm_state_check_expire(x)) {
112 spin_unlock(&x->lock);
118 nh = x->type->input(x, skb);
120 spin_unlock(&x->lock);
126 x->curlft.bytes += skb->len;
129 spin_unlock(&x->lock);
138 /* Allocate new secpath or COW existing one. */
139 if (!skb->sp || atomic_read(&skb->sp->refcnt) != 1) {
141 sp = secpath_dup(skb->sp);
145 secpath_put(skb->sp);
149 if (1 + skb->sp->len > XFRM_MAX_DEPTH)
152 skb->sp->xvec[skb->sp->len] = xfrm_vec_one;
158 xfrm_state_put(xfrm_vec_one);
162 EXPORT_SYMBOL(xfrm6_input_addr);