inet6_hashtables.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 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 net *net,
  50. struct inet_hashinfo *hashinfo,
  51. const struct in6_addr *saddr,
  52. const __be16 sport,
  53. const struct in6_addr *daddr,
  54. const u16 hnum,
  55. const int dif);
  56. extern struct sock *inet6_lookup_listener(struct net *net,
  57. struct inet_hashinfo *hashinfo,
  58. const struct in6_addr *daddr,
  59. const unsigned short hnum,
  60. const int dif);
  61. static inline struct sock *__inet6_lookup(struct net *net,
  62. struct inet_hashinfo *hashinfo,
  63. const struct in6_addr *saddr,
  64. const __be16 sport,
  65. const struct in6_addr *daddr,
  66. const u16 hnum,
  67. const int dif)
  68. {
  69. struct sock *sk = __inet6_lookup_established(net, hashinfo, saddr,
  70. sport, daddr, hnum, dif);
  71. if (sk)
  72. return sk;
  73. return inet6_lookup_listener(net, hashinfo, daddr, hnum, dif);
  74. }
  75. extern struct sock *inet6_lookup(struct net *net, struct inet_hashinfo *hashinfo,
  76. const struct in6_addr *saddr, const __be16 sport,
  77. const struct in6_addr *daddr, const __be16 dport,
  78. const int dif);
  79. #endif /* defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE) */
  80. #endif /* _INET6_HASHTABLES_H */