inet6_hashtables.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 IS_ENABLED(CONFIG_IPV6)
  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. static inline unsigned int __inet6_ehashfn(const u32 lhash,
  25. const u16 lport,
  26. const u32 fhash,
  27. const __be16 fport,
  28. const u32 initval)
  29. {
  30. const u32 ports = (((u32)lport) << 16) | (__force u32)fport;
  31. return jhash_3words(lhash, fhash, ports, initval);
  32. }
  33. int __inet6_hash(struct sock *sk, struct inet_timewait_sock *twp);
  34. /*
  35. * Sockets in TCP_CLOSE state are _always_ taken out of the hash, so
  36. * we need not check it for TCP lookups anymore, thanks Alexey. -DaveM
  37. *
  38. * The sockhash lock must be held as a reader here.
  39. */
  40. struct sock *__inet6_lookup_established(struct net *net,
  41. struct inet_hashinfo *hashinfo,
  42. const struct in6_addr *saddr,
  43. const __be16 sport,
  44. const struct in6_addr *daddr,
  45. const u16 hnum, const int dif);
  46. struct sock *inet6_lookup_listener(struct net *net,
  47. struct inet_hashinfo *hashinfo,
  48. const struct in6_addr *saddr,
  49. const __be16 sport,
  50. const struct in6_addr *daddr,
  51. const unsigned short hnum, const int dif);
  52. static inline struct sock *__inet6_lookup(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. {
  60. struct sock *sk = __inet6_lookup_established(net, hashinfo, saddr,
  61. sport, daddr, hnum, dif);
  62. if (sk)
  63. return sk;
  64. return inet6_lookup_listener(net, hashinfo, saddr, sport,
  65. daddr, hnum, dif);
  66. }
  67. static inline struct sock *__inet6_lookup_skb(struct inet_hashinfo *hashinfo,
  68. struct sk_buff *skb,
  69. const __be16 sport,
  70. const __be16 dport)
  71. {
  72. struct sock *sk = skb_steal_sock(skb);
  73. if (sk)
  74. return sk;
  75. return __inet6_lookup(dev_net(skb_dst(skb)->dev), hashinfo,
  76. &ipv6_hdr(skb)->saddr, sport,
  77. &ipv6_hdr(skb)->daddr, ntohs(dport),
  78. inet6_iif(skb));
  79. }
  80. struct sock *inet6_lookup(struct net *net, struct inet_hashinfo *hashinfo,
  81. const struct in6_addr *saddr, const __be16 sport,
  82. const struct in6_addr *daddr, const __be16 dport,
  83. const int dif);
  84. #endif /* IS_ENABLED(CONFIG_IPV6) */
  85. #endif /* _INET6_HASHTABLES_H */