inet6_hashtables.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 <net/ipv6.h>
  20. struct inet_hashinfo;
  21. /* I have no idea if this is a good hash for v6 or not. -DaveM */
  22. static inline unsigned int inet6_ehashfn(const struct in6_addr *laddr, const u16 lport,
  23. const struct in6_addr *faddr, const u16 fport)
  24. {
  25. unsigned int hashent = (lport ^ fport);
  26. hashent ^= (laddr->s6_addr32[3] ^ faddr->s6_addr32[3]);
  27. hashent ^= hashent >> 16;
  28. hashent ^= hashent >> 8;
  29. return hashent;
  30. }
  31. static inline int inet6_sk_ehashfn(const struct sock *sk)
  32. {
  33. const struct inet_sock *inet = inet_sk(sk);
  34. const struct ipv6_pinfo *np = inet6_sk(sk);
  35. const struct in6_addr *laddr = &np->rcv_saddr;
  36. const struct in6_addr *faddr = &np->daddr;
  37. const __u16 lport = inet->num;
  38. const __u16 fport = inet->dport;
  39. return inet6_ehashfn(laddr, lport, faddr, fport);
  40. }
  41. extern void __inet6_hash(struct inet_hashinfo *hashinfo, struct sock *sk);
  42. /*
  43. * Sockets in TCP_CLOSE state are _always_ taken out of the hash, so
  44. * we need not check it for TCP lookups anymore, thanks Alexey. -DaveM
  45. *
  46. * The sockhash lock must be held as a reader here.
  47. */
  48. extern struct sock *__inet6_lookup_established(struct inet_hashinfo *hashinfo,
  49. const struct in6_addr *saddr,
  50. const u16 sport,
  51. const struct in6_addr *daddr,
  52. const u16 hnum,
  53. const int dif);
  54. extern struct sock *inet6_lookup_listener(struct inet_hashinfo *hashinfo,
  55. const struct in6_addr *daddr,
  56. const unsigned short hnum,
  57. const int dif);
  58. static inline struct sock *__inet6_lookup(struct inet_hashinfo *hashinfo,
  59. const struct in6_addr *saddr,
  60. const u16 sport,
  61. const struct in6_addr *daddr,
  62. const u16 hnum,
  63. const int dif)
  64. {
  65. struct sock *sk = __inet6_lookup_established(hashinfo, saddr, sport,
  66. daddr, hnum, dif);
  67. if (sk)
  68. return sk;
  69. return inet6_lookup_listener(hashinfo, daddr, hnum, dif);
  70. }
  71. extern struct sock *inet6_lookup(struct inet_hashinfo *hashinfo,
  72. const struct in6_addr *saddr, const u16 sport,
  73. const struct in6_addr *daddr, const u16 dport,
  74. const int dif);
  75. #endif /* defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE) */
  76. #endif /* _INET6_HASHTABLES_H */