inet6_hashtables.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * INET An implementation of the TCP/IP protocol suite for the LINUX
  3. * operating system. INET is implemented using the BSD Socket
  4. * interface as the means of communication with the user level.
  5. *
  6. * Authors: Lotsa people, from code originally in tcp
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version
  11. * 2 of the License, or (at your option) any later version.
  12. */
  13. #ifndef _INET6_HASHTABLES_H
  14. #define _INET6_HASHTABLES_H
  15. #if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
  16. #include <linux/in6.h>
  17. #include <linux/ipv6.h>
  18. #include <linux/types.h>
  19. #include <linux/jhash.h>
  20. #include <net/inet_sock.h>
  21. #include <net/ipv6.h>
  22. #include <net/netns/hash.h>
  23. struct inet_hashinfo;
  24. /* I have no idea if this is a good hash for v6 or not. -DaveM */
  25. static inline unsigned int inet6_ehashfn(struct net *net,
  26. const struct in6_addr *laddr, const u16 lport,
  27. const struct in6_addr *faddr, const __be16 fport)
  28. {
  29. u32 ports = (lport ^ (__force u16)fport);
  30. return jhash_3words((__force u32)laddr->s6_addr32[3],
  31. (__force u32)faddr->s6_addr32[3],
  32. ports, inet_ehash_secret + net_hash_mix(net));
  33. }
  34. static inline int inet6_sk_ehashfn(const struct sock *sk)
  35. {
  36. const struct inet_sock *inet = inet_sk(sk);
  37. const struct ipv6_pinfo *np = inet6_sk(sk);
  38. const struct in6_addr *laddr = &np->rcv_saddr;
  39. const struct in6_addr *faddr = &np->daddr;
  40. const __u16 lport = inet->inet_num;
  41. const __be16 fport = inet->inet_dport;
  42. struct net *net = sock_net(sk);
  43. return inet6_ehashfn(net, laddr, lport, faddr, fport);
  44. }
  45. extern int __inet6_hash(struct sock *sk, struct inet_timewait_sock *twp);
  46. /*
  47. * Sockets in TCP_CLOSE state are _always_ taken out of the hash, so
  48. * we need not check it for TCP lookups anymore, thanks Alexey. -DaveM
  49. *
  50. * The sockhash lock must be held as a reader here.
  51. */
  52. extern struct sock *__inet6_lookup_established(struct net *net,
  53. struct inet_hashinfo *hashinfo,
  54. const struct in6_addr *saddr,
  55. const __be16 sport,
  56. const struct in6_addr *daddr,
  57. const u16 hnum,
  58. const int dif);
  59. extern struct sock *inet6_lookup_listener(struct net *net,
  60. struct inet_hashinfo *hashinfo,
  61. const struct in6_addr *daddr,
  62. const unsigned short hnum,
  63. const int dif);
  64. static inline struct sock *__inet6_lookup(struct net *net,
  65. struct inet_hashinfo *hashinfo,
  66. const struct in6_addr *saddr,
  67. const __be16 sport,
  68. const struct in6_addr *daddr,
  69. const u16 hnum,
  70. const int dif)
  71. {
  72. struct sock *sk = __inet6_lookup_established(net, hashinfo, saddr,
  73. sport, daddr, hnum, dif);
  74. if (sk)
  75. return sk;
  76. return inet6_lookup_listener(net, hashinfo, daddr, hnum, dif);
  77. }
  78. static inline struct sock *__inet6_lookup_skb(struct inet_hashinfo *hashinfo,
  79. struct sk_buff *skb,
  80. const __be16 sport,
  81. const __be16 dport)
  82. {
  83. struct sock *sk;
  84. if (unlikely(sk = skb_steal_sock(skb)))
  85. return sk;
  86. else return __inet6_lookup(dev_net(skb_dst(skb)->dev), hashinfo,
  87. &ipv6_hdr(skb)->saddr, sport,
  88. &ipv6_hdr(skb)->daddr, ntohs(dport),
  89. inet6_iif(skb));
  90. }
  91. extern struct sock *inet6_lookup(struct net *net, struct inet_hashinfo *hashinfo,
  92. const struct in6_addr *saddr, const __be16 sport,
  93. const struct in6_addr *daddr, const __be16 dport,
  94. const int dif);
  95. #endif /* defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE) */
  96. #endif /* _INET6_HASHTABLES_H */