inet6_hashtables.h 2.9 KB

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