24 #include <linux/module.h>
26 #include <linux/slab.h>
31 #include <linux/ipv6.h>
32 #include <linux/icmpv6.h>
36 #define XFRM6_TUNNEL_SPI_BYADDR_HSIZE 256
37 #define XFRM6_TUNNEL_SPI_BYSPI_HSIZE 256
39 #define XFRM6_TUNNEL_SPI_MIN 1
40 #define XFRM6_TUNNEL_SPI_MAX 0xffffffff
83 static inline unsigned int xfrm6_tunnel_spi_hash_byspi(
u32 spi)
94 hlist_for_each_entry_rcu(x6spi, pos,
95 &xfrm6_tn->
spi_byaddr[xfrm6_tunnel_spi_hash_byaddr(saddr)],
110 x6spi = __xfrm6_tunnel_spi_lookup(net, saddr);
111 spi = x6spi ? x6spi->
spi : 0;
112 rcu_read_unlock_bh();
118 static int __xfrm6_tunnel_spi_check(
struct net *net,
u32 spi)
122 int index = xfrm6_tunnel_spi_hash_byspi(spi);
128 if (x6spi->
spi == spi)
148 index = __xfrm6_tunnel_spi_check(net, spi);
153 index = __xfrm6_tunnel_spi_check(net, spi);
171 index = xfrm6_tunnel_spi_hash_byaddr(saddr);
182 spin_lock_bh(&xfrm6_tunnel_spi_lock);
183 x6spi = __xfrm6_tunnel_spi_lookup(net, saddr);
188 spi = __xfrm6_tunnel_alloc_spi(net, saddr);
189 spin_unlock_bh(&xfrm6_tunnel_spi_lock);
202 static void xfrm6_tunnel_free_spi(
struct net *net,
xfrm_address_t *saddr)
208 spin_lock_bh(&xfrm6_tunnel_spi_lock);
211 &xfrm6_tn->
spi_byaddr[xfrm6_tunnel_spi_hash_byaddr(saddr)],
223 spin_unlock_bh(&xfrm6_tunnel_spi_lock);
228 skb_push(skb, -skb_network_offset(skb));
234 return skb_network_header(skb)[
IP6CB(skb)->nhoff];
237 static int xfrm6_tunnel_rcv(
struct sk_buff *skb)
239 struct net *net = dev_net(skb->
dev);
240 const struct ipv6hdr *iph = ipv6_hdr(skb);
288 static int xfrm6_tunnel_init_state(
struct xfrm_state *x)
301 static void xfrm6_tunnel_destroy(
struct xfrm_state *x)
303 struct net *net = xs_net(x);
308 static const struct xfrm_type xfrm6_tunnel_type = {
309 .description =
"IP6IP6",
312 .init_state = xfrm6_tunnel_init_state,
313 .destructor = xfrm6_tunnel_destroy,
314 .input = xfrm6_tunnel_input,
315 .output = xfrm6_tunnel_output,
319 .handler = xfrm6_tunnel_rcv,
320 .err_handler = xfrm6_tunnel_err,
324 static struct xfrm6_tunnel xfrm46_tunnel_handler __read_mostly = {
326 .err_handler = xfrm6_tunnel_err,
330 static int __net_init xfrm6_tunnel_net_init(
struct net *net)
344 static void __net_exit xfrm6_tunnel_net_exit(
struct net *net)
349 .init = xfrm6_tunnel_net_init,
350 .exit = xfrm6_tunnel_net_exit,
351 .id = &xfrm6_tunnel_net_id,
355 static int __init xfrm6_tunnel_init(
void)
363 if (!xfrm6_tunnel_spi_kmem)
390 static void __exit xfrm6_tunnel_fini(
void)