[BNX2]: Add init. code to handle RX pages.
[linux-2.6/btrfs-unstable.git] / net / ipv6 / xfrm6_input.c
blob74f3aacebb5e695430bfb05ba0f13ed105af9e57
1 /*
2 * xfrm6_input.c: based on net/ipv4/xfrm4_input.c
4 * Authors:
5 * Mitsuru KANDA @USAGI
6 * Kazunori MIYAZAWA @USAGI
7 * Kunihiro Ishiguro <kunihiro@ipinfusion.com>
8 * YOSHIFUJI Hideaki @USAGI
9 * IPv6 support
12 #include <linux/module.h>
13 #include <linux/string.h>
14 #include <linux/netfilter.h>
15 #include <linux/netfilter_ipv6.h>
16 #include <net/ipv6.h>
17 #include <net/xfrm.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)->family = AF_INET6;
27 XFRM_SPI_SKB_CB(skb)->daddroff = offsetof(struct ipv6hdr, daddr);
28 return xfrm_input(skb, nexthdr, spi, 0);
30 EXPORT_SYMBOL(xfrm6_rcv_spi);
32 int xfrm6_transport_finish(struct sk_buff *skb, int async)
34 skb_network_header(skb)[IP6CB(skb)->nhoff] =
35 XFRM_MODE_SKB_CB(skb)->protocol;
37 #ifdef CONFIG_NETFILTER
38 ipv6_hdr(skb)->payload_len = htons(skb->len);
39 __skb_push(skb, skb->data - skb_network_header(skb));
41 NF_HOOK(PF_INET6, NF_INET_PRE_ROUTING, skb, skb->dev, NULL,
42 ip6_rcv_finish);
43 return -1;
44 #else
45 if (async)
46 return ip6_rcv_finish(skb);
48 return 1;
49 #endif
52 int xfrm6_rcv(struct sk_buff *skb)
54 return xfrm6_rcv_spi(skb, skb_network_header(skb)[IP6CB(skb)->nhoff],
55 0);
58 EXPORT_SYMBOL(xfrm6_rcv);
60 int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr,
61 xfrm_address_t *saddr, u8 proto)
63 struct xfrm_state *x = NULL;
64 int wildcard = 0;
65 xfrm_address_t *xany;
66 struct xfrm_state *xfrm_vec_one = NULL;
67 int nh = 0;
68 int i = 0;
70 xany = (xfrm_address_t *)&in6addr_any;
72 for (i = 0; i < 3; i++) {
73 xfrm_address_t *dst, *src;
74 switch (i) {
75 case 0:
76 dst = daddr;
77 src = saddr;
78 break;
79 case 1:
80 /* lookup state with wild-card source address */
81 wildcard = 1;
82 dst = daddr;
83 src = xany;
84 break;
85 case 2:
86 default:
87 /* lookup state with wild-card addresses */
88 wildcard = 1; /* XXX */
89 dst = xany;
90 src = xany;
91 break;
94 x = xfrm_state_lookup_byaddr(dst, src, proto, AF_INET6);
95 if (!x)
96 continue;
98 spin_lock(&x->lock);
100 if (wildcard) {
101 if ((x->props.flags & XFRM_STATE_WILDRECV) == 0) {
102 spin_unlock(&x->lock);
103 xfrm_state_put(x);
104 x = NULL;
105 continue;
109 if (unlikely(x->km.state != XFRM_STATE_VALID)) {
110 spin_unlock(&x->lock);
111 xfrm_state_put(x);
112 x = NULL;
113 continue;
115 if (xfrm_state_check_expire(x)) {
116 spin_unlock(&x->lock);
117 xfrm_state_put(x);
118 x = NULL;
119 continue;
122 nh = x->type->input(x, skb);
123 if (nh <= 0) {
124 spin_unlock(&x->lock);
125 xfrm_state_put(x);
126 x = NULL;
127 continue;
130 x->curlft.bytes += skb->len;
131 x->curlft.packets++;
133 spin_unlock(&x->lock);
135 xfrm_vec_one = x;
136 break;
139 if (!xfrm_vec_one)
140 goto drop;
142 /* Allocate new secpath or COW existing one. */
143 if (!skb->sp || atomic_read(&skb->sp->refcnt) != 1) {
144 struct sec_path *sp;
145 sp = secpath_dup(skb->sp);
146 if (!sp)
147 goto drop;
148 if (skb->sp)
149 secpath_put(skb->sp);
150 skb->sp = sp;
153 if (1 + skb->sp->len > XFRM_MAX_DEPTH)
154 goto drop;
156 skb->sp->xvec[skb->sp->len] = xfrm_vec_one;
157 skb->sp->len ++;
159 return 1;
160 drop:
161 if (xfrm_vec_one)
162 xfrm_state_put(xfrm_vec_one);
163 return -1;
166 EXPORT_SYMBOL(xfrm6_input_addr);