xfrm6_tunnel.c (2d8ad8719591fa803b0d589ed057fa46f49b7155) | xfrm6_tunnel.c (b71d1d426d263b0b6cb5760322efebbfc89d4463) |
---|---|
1/* 2 * Copyright (C)2003,2004 USAGI/WIDE Project 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * --- 54 unchanged lines hidden (view full) --- 63 atomic_t refcnt; 64 struct rcu_head rcu_head; 65}; 66 67static DEFINE_SPINLOCK(xfrm6_tunnel_spi_lock); 68 69static struct kmem_cache *xfrm6_tunnel_spi_kmem __read_mostly; 70 | 1/* 2 * Copyright (C)2003,2004 USAGI/WIDE Project 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * --- 54 unchanged lines hidden (view full) --- 63 atomic_t refcnt; 64 struct rcu_head rcu_head; 65}; 66 67static DEFINE_SPINLOCK(xfrm6_tunnel_spi_lock); 68 69static struct kmem_cache *xfrm6_tunnel_spi_kmem __read_mostly; 70 |
71static inline unsigned xfrm6_tunnel_spi_hash_byaddr(xfrm_address_t *addr) | 71static inline unsigned xfrm6_tunnel_spi_hash_byaddr(const xfrm_address_t *addr) |
72{ 73 unsigned h; 74 75 h = (__force u32)(addr->a6[0] ^ addr->a6[1] ^ addr->a6[2] ^ addr->a6[3]); 76 h ^= h >> 16; 77 h ^= h >> 8; 78 h &= XFRM6_TUNNEL_SPI_BYADDR_HSIZE - 1; 79 80 return h; 81} 82 83static inline unsigned xfrm6_tunnel_spi_hash_byspi(u32 spi) 84{ 85 return spi % XFRM6_TUNNEL_SPI_BYSPI_HSIZE; 86} 87 | 72{ 73 unsigned h; 74 75 h = (__force u32)(addr->a6[0] ^ addr->a6[1] ^ addr->a6[2] ^ addr->a6[3]); 76 h ^= h >> 16; 77 h ^= h >> 8; 78 h &= XFRM6_TUNNEL_SPI_BYADDR_HSIZE - 1; 79 80 return h; 81} 82 83static inline unsigned xfrm6_tunnel_spi_hash_byspi(u32 spi) 84{ 85 return spi % XFRM6_TUNNEL_SPI_BYSPI_HSIZE; 86} 87 |
88static struct xfrm6_tunnel_spi *__xfrm6_tunnel_spi_lookup(struct net *net, xfrm_address_t *saddr) | 88static struct xfrm6_tunnel_spi *__xfrm6_tunnel_spi_lookup(struct net *net, const xfrm_address_t *saddr) |
89{ 90 struct xfrm6_tunnel_net *xfrm6_tn = xfrm6_tunnel_pernet(net); 91 struct xfrm6_tunnel_spi *x6spi; 92 struct hlist_node *pos; 93 94 hlist_for_each_entry_rcu(x6spi, pos, 95 &xfrm6_tn->spi_byaddr[xfrm6_tunnel_spi_hash_byaddr(saddr)], 96 list_byaddr) { 97 if (memcmp(&x6spi->addr, saddr, sizeof(x6spi->addr)) == 0) 98 return x6spi; 99 } 100 101 return NULL; 102} 103 | 89{ 90 struct xfrm6_tunnel_net *xfrm6_tn = xfrm6_tunnel_pernet(net); 91 struct xfrm6_tunnel_spi *x6spi; 92 struct hlist_node *pos; 93 94 hlist_for_each_entry_rcu(x6spi, pos, 95 &xfrm6_tn->spi_byaddr[xfrm6_tunnel_spi_hash_byaddr(saddr)], 96 list_byaddr) { 97 if (memcmp(&x6spi->addr, saddr, sizeof(x6spi->addr)) == 0) 98 return x6spi; 99 } 100 101 return NULL; 102} 103 |
104__be32 xfrm6_tunnel_spi_lookup(struct net *net, xfrm_address_t *saddr) | 104__be32 xfrm6_tunnel_spi_lookup(struct net *net, const xfrm_address_t *saddr) |
105{ 106 struct xfrm6_tunnel_spi *x6spi; 107 u32 spi; 108 109 rcu_read_lock_bh(); 110 x6spi = __xfrm6_tunnel_spi_lookup(net, saddr); 111 spi = x6spi ? x6spi->spi : 0; 112 rcu_read_unlock_bh(); --- 119 unchanged lines hidden (view full) --- 232static int xfrm6_tunnel_input(struct xfrm_state *x, struct sk_buff *skb) 233{ 234 return skb_network_header(skb)[IP6CB(skb)->nhoff]; 235} 236 237static int xfrm6_tunnel_rcv(struct sk_buff *skb) 238{ 239 struct net *net = dev_net(skb->dev); | 105{ 106 struct xfrm6_tunnel_spi *x6spi; 107 u32 spi; 108 109 rcu_read_lock_bh(); 110 x6spi = __xfrm6_tunnel_spi_lookup(net, saddr); 111 spi = x6spi ? x6spi->spi : 0; 112 rcu_read_unlock_bh(); --- 119 unchanged lines hidden (view full) --- 232static int xfrm6_tunnel_input(struct xfrm_state *x, struct sk_buff *skb) 233{ 234 return skb_network_header(skb)[IP6CB(skb)->nhoff]; 235} 236 237static int xfrm6_tunnel_rcv(struct sk_buff *skb) 238{ 239 struct net *net = dev_net(skb->dev); |
240 struct ipv6hdr *iph = ipv6_hdr(skb); | 240 const struct ipv6hdr *iph = ipv6_hdr(skb); |
241 __be32 spi; 242 | 241 __be32 spi; 242 |
243 spi = xfrm6_tunnel_spi_lookup(net, (xfrm_address_t *)&iph->saddr); | 243 spi = xfrm6_tunnel_spi_lookup(net, (const xfrm_address_t *)&iph->saddr); |
244 return xfrm6_rcv_spi(skb, IPPROTO_IPV6, spi) > 0 ? : 0; 245} 246 247static int xfrm6_tunnel_err(struct sk_buff *skb, struct inet6_skb_parm *opt, 248 u8 type, u8 code, int offset, __be32 info) 249{ 250 /* xfrm6_tunnel native err handling */ 251 switch (type) { --- 151 unchanged lines hidden --- | 244 return xfrm6_rcv_spi(skb, IPPROTO_IPV6, spi) > 0 ? : 0; 245} 246 247static int xfrm6_tunnel_err(struct sk_buff *skb, struct inet6_skb_parm *opt, 248 u8 type, u8 code, int offset, __be32 info) 249{ 250 /* xfrm6_tunnel native err handling */ 251 switch (type) { --- 151 unchanged lines hidden --- |