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_TUNNEL_SKB_CB(skb
)->tunnel
.ip6
= NULL
;
27 XFRM_SPI_SKB_CB(skb
)->family
= AF_INET6
;
28 XFRM_SPI_SKB_CB(skb
)->daddroff
= offsetof(struct ipv6hdr
, daddr
);
29 return xfrm_input(skb
, nexthdr
, spi
, 0);
31 EXPORT_SYMBOL(xfrm6_rcv_spi
);
33 int xfrm6_transport_finish(struct sk_buff
*skb
, int async
)
35 skb_network_header(skb
)[IP6CB(skb
)->nhoff
] =
36 XFRM_MODE_SKB_CB(skb
)->protocol
;
38 #ifndef CONFIG_NETFILTER
43 ipv6_hdr(skb
)->payload_len
= htons(skb
->len
);
44 __skb_push(skb
, skb
->data
- skb_network_header(skb
));
46 NF_HOOK(NFPROTO_IPV6
, NF_INET_PRE_ROUTING
,
47 dev_net(skb
->dev
), NULL
, skb
, skb
->dev
, NULL
,
52 int xfrm6_rcv(struct sk_buff
*skb
)
54 return xfrm6_rcv_spi(skb
, skb_network_header(skb
)[IP6CB(skb
)->nhoff
],
57 EXPORT_SYMBOL(xfrm6_rcv
);
59 int xfrm6_input_addr(struct sk_buff
*skb
, xfrm_address_t
*daddr
,
60 xfrm_address_t
*saddr
, u8 proto
)
62 struct net
*net
= dev_net(skb
->dev
);
63 struct xfrm_state
*x
= NULL
;
66 /* Allocate new secpath or COW existing one. */
67 if (!skb
->sp
|| atomic_read(&skb
->sp
->refcnt
) != 1) {
70 sp
= secpath_dup(skb
->sp
);
72 XFRM_INC_STATS(net
, LINUX_MIB_XFRMINERROR
);
80 if (1 + skb
->sp
->len
== XFRM_MAX_DEPTH
) {
81 XFRM_INC_STATS(net
, LINUX_MIB_XFRMINBUFFERERROR
);
85 for (i
= 0; i
< 3; i
++) {
86 xfrm_address_t
*dst
, *src
;
94 /* lookup state with wild-card source address */
96 src
= (xfrm_address_t
*)&in6addr_any
;
99 /* lookup state with wild-card addresses */
100 dst
= (xfrm_address_t
*)&in6addr_any
;
101 src
= (xfrm_address_t
*)&in6addr_any
;
105 x
= xfrm_state_lookup_byaddr(net
, skb
->mark
, dst
, src
, proto
, AF_INET6
);
111 if ((!i
|| (x
->props
.flags
& XFRM_STATE_WILDRECV
)) &&
112 likely(x
->km
.state
== XFRM_STATE_VALID
) &&
113 !xfrm_state_check_expire(x
)) {
114 spin_unlock(&x
->lock
);
115 if (x
->type
->input(x
, skb
) > 0) {
116 /* found a valid state */
120 spin_unlock(&x
->lock
);
127 XFRM_INC_STATS(net
, LINUX_MIB_XFRMINNOSTATES
);
128 xfrm_audit_state_notfound_simple(skb
, AF_INET6
);
132 skb
->sp
->xvec
[skb
->sp
->len
++] = x
;
136 x
->curlft
.bytes
+= skb
->len
;
139 spin_unlock(&x
->lock
);
146 EXPORT_SYMBOL(xfrm6_input_addr
);