dst_cache.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef _NET_DST_CACHE_H
  2. #define _NET_DST_CACHE_H
  3. #include <linux/jiffies.h>
  4. #include <net/dst.h>
  5. #if IS_ENABLED(CONFIG_IPV6)
  6. #include <net/ip6_fib.h>
  7. #endif
  8. struct dst_cache {
  9. struct dst_cache_pcpu __percpu *cache;
  10. unsigned long reset_ts;
  11. };
  12. /**
  13. * dst_cache_get - perform cache lookup
  14. * @dst_cache: the cache
  15. *
  16. * The caller should use dst_cache_get_ip4() if it need to retrieve the
  17. * source address to be used when xmitting to the cached dst.
  18. * local BH must be disabled.
  19. */
  20. struct dst_entry *dst_cache_get(struct dst_cache *dst_cache);
  21. /**
  22. * dst_cache_get_ip4 - perform cache lookup and fetch ipv4 source address
  23. * @dst_cache: the cache
  24. * @saddr: return value for the retrieved source address
  25. *
  26. * local BH must be disabled.
  27. */
  28. struct rtable *dst_cache_get_ip4(struct dst_cache *dst_cache, __be32 *saddr);
  29. /**
  30. * dst_cache_set_ip4 - store the ipv4 dst into the cache
  31. * @dst_cache: the cache
  32. * @dst: the entry to be cached
  33. * @saddr: the source address to be stored inside the cache
  34. *
  35. * local BH must be disabled.
  36. */
  37. void dst_cache_set_ip4(struct dst_cache *dst_cache, struct dst_entry *dst,
  38. __be32 saddr);
  39. #if IS_ENABLED(CONFIG_IPV6)
  40. /**
  41. * dst_cache_set_ip6 - store the ipv6 dst into the cache
  42. * @dst_cache: the cache
  43. * @dst: the entry to be cached
  44. * @saddr: the source address to be stored inside the cache
  45. *
  46. * local BH must be disabled.
  47. */
  48. void dst_cache_set_ip6(struct dst_cache *dst_cache, struct dst_entry *dst,
  49. const struct in6_addr *addr);
  50. /**
  51. * dst_cache_get_ip6 - perform cache lookup and fetch ipv6 source address
  52. * @dst_cache: the cache
  53. * @saddr: return value for the retrieved source address
  54. *
  55. * local BH must be disabled.
  56. */
  57. struct dst_entry *dst_cache_get_ip6(struct dst_cache *dst_cache,
  58. struct in6_addr *saddr);
  59. #endif
  60. /**
  61. * dst_cache_reset - invalidate the cache contents
  62. * @dst_cache: the cache
  63. *
  64. * This do not free the cached dst to avoid races and contentions.
  65. * the dst will be freed on later cache lookup.
  66. */
  67. static inline void dst_cache_reset(struct dst_cache *dst_cache)
  68. {
  69. dst_cache->reset_ts = jiffies;
  70. }
  71. /**
  72. * dst_cache_init - initialize the cache, allocating the required storage
  73. * @dst_cache: the cache
  74. * @gfp: allocation flags
  75. */
  76. int dst_cache_init(struct dst_cache *dst_cache, gfp_t gfp);
  77. /**
  78. * dst_cache_destroy - empty the cache and free the allocated storage
  79. * @dst_cache: the cache
  80. *
  81. * No synchronization is enforced: it must be called only when the cache
  82. * is unsed.
  83. */
  84. void dst_cache_destroy(struct dst_cache *dst_cache);
  85. #endif