14 #ifndef _INET_HASHTABLES_H
15 #define _INET_HASHTABLES_H
20 #include <linux/ipv6.h>
21 #include <linux/list.h>
22 #include <linux/slab.h>
23 #include <linux/socket.h>
25 #include <linux/types.h>
26 #include <linux/wait.h>
37 #include <asm/byteorder.h>
95 #define inet_bind_bucket_for_each(tb, pos, head) \
96 hlist_for_each_entry(tb, pos, head, node)
109 #define LISTENING_NULLS_BASE (1U << 29)
116 #define INET_LHTABLE_SIZE 32
171 static inline int inet_ehash_locks_alloc(
struct inet_hashinfo *hashinfo)
173 unsigned int i,
size = 256;
174 #if defined(CONFIG_PROVE_LOCKING)
175 unsigned int nr_pcpus = 2;
197 for (i = 0; i <
size; i++)
204 static inline void inet_ehash_locks_free(
struct inet_hashinfo *hashinfo)
223 const unsigned short snum);
227 static inline int inet_bhashfn(
struct net *
net,
230 return (lport + net_hash_mix(net)) & (bhash_size - 1);
234 const unsigned short snum);
237 static inline int inet_lhashfn(
struct net *net,
const unsigned short num)
242 static inline int inet_sk_listen_hashfn(
const struct sock *
sk)
244 return inet_lhashfn(sock_net(sk), inet_sk(sk)->inet_num);
261 const unsigned short hnum,
264 static inline struct sock *inet_lookup_listener(
struct net *net,
282 #define INET_COMBINED_PORTS(__sport, __dport) \
283 ((__force __portpair)(((__force __u32)(__be16)(__sport) << 16) | (__u32)(__dport)))
285 #define INET_COMBINED_PORTS(__sport, __dport) \
286 ((__force __portpair)(((__u32)(__dport) << 16) | (__force __u32)(__be16)(__sport)))
289 #if (BITS_PER_LONG == 64)
292 #define INET_ADDR_COOKIE(__name, __saddr, __daddr) \
293 const __addrpair __name = (__force __addrpair) ( \
294 (((__force __u64)(__be32)(__saddr)) << 32) | \
295 ((__force __u64)(__be32)(__daddr)));
297 #define INET_ADDR_COOKIE(__name, __saddr, __daddr) \
298 const __addrpair __name = (__force __addrpair) ( \
299 (((__force __u64)(__be32)(__daddr)) << 32) | \
300 ((__force __u64)(__be32)(__saddr)));
302 #define INET_MATCH(__sk, __net, __hash, __cookie, __saddr, __daddr, __ports, __dif)\
303 (((__sk)->sk_hash == (__hash)) && net_eq(sock_net(__sk), (__net)) && \
304 ((*((__addrpair *)&(inet_sk(__sk)->inet_daddr))) == (__cookie)) && \
305 ((*((__portpair *)&(inet_sk(__sk)->inet_dport))) == (__ports)) && \
306 (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
307 #define INET_TW_MATCH(__sk, __net, __hash, __cookie, __saddr, __daddr, __ports, __dif)\
308 (((__sk)->sk_hash == (__hash)) && net_eq(sock_net(__sk), (__net)) && \
309 ((*((__addrpair *)&(inet_twsk(__sk)->tw_daddr))) == (__cookie)) && \
310 ((*((__portpair *)&(inet_twsk(__sk)->tw_dport))) == (__ports)) && \
311 (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
313 #define INET_ADDR_COOKIE(__name, __saddr, __daddr)
314 #define INET_MATCH(__sk, __net, __hash, __cookie, __saddr, __daddr, __ports, __dif) \
315 (((__sk)->sk_hash == (__hash)) && net_eq(sock_net(__sk), (__net)) && \
316 (inet_sk(__sk)->inet_daddr == (__saddr)) && \
317 (inet_sk(__sk)->inet_rcv_saddr == (__daddr)) && \
318 ((*((__portpair *)&(inet_sk(__sk)->inet_dport))) == (__ports)) && \
319 (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
320 #define INET_TW_MATCH(__sk, __net, __hash,__cookie, __saddr, __daddr, __ports, __dif) \
321 (((__sk)->sk_hash == (__hash)) && net_eq(sock_net(__sk), (__net)) && \
322 (inet_twsk(__sk)->tw_daddr == (__saddr)) && \
323 (inet_twsk(__sk)->tw_rcv_saddr == (__daddr)) && \
324 ((*((__portpair *)&(inet_twsk(__sk)->tw_dport))) == (__ports)) && \
325 (!((__sk)->sk_bound_dev_if) || ((__sk)->sk_bound_dev_if == (__dif))))
337 const __be32 daddr,
const u16 hnum,
const int dif);
339 static inline struct sock *
340 inet_lookup_established(
struct net *net,
struct inet_hashinfo *hashinfo,
349 static inline struct sock *__inet_lookup(
struct net *net,
357 saddr, sport, daddr, hnum, dif);
362 static inline struct sock *inet_lookup(
struct net *net,
371 sk = __inet_lookup(net, hashinfo, saddr, sport, daddr, dport, dif);
382 struct sock *sk = skb_steal_sock(skb);
383 const struct iphdr *iph = ip_hdr(skb);
388 return __inet_lookup(dev_net(skb_dst(skb)->
dev), hashinfo,
390 iph->
daddr, dport, inet_iif(skb));