dst_ops.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _NET_DST_OPS_H
  3. #define _NET_DST_OPS_H
  4. #include <linux/types.h>
  5. #include <linux/percpu_counter.h>
  6. #include <linux/cache.h>
  7. struct dst_entry;
  8. struct kmem_cachep;
  9. struct net_device;
  10. struct sk_buff;
  11. struct sock;
  12. struct net;
  13. /* *** ANDROID FIXUP ***
  14. * These typedefs are used to help fixup the ABI break caused by commit
  15. * 92f1655aa2b2 ("net: fix __dst_negative_advice() race") where the
  16. * negative_advice callback changed function signatures.
  17. * See b/343727534 for more details.
  18. * *** ANDROID FIXUP ***
  19. */
  20. typedef void (*android_dst_ops_negative_advice_new_t)(struct sock *sk, struct dst_entry *);
  21. typedef struct dst_entry * (*android_dst_ops_negative_advice_old_t)(struct dst_entry *);
  22. struct dst_ops {
  23. unsigned short family;
  24. unsigned int gc_thresh;
  25. int (*gc)(struct dst_ops *ops);
  26. struct dst_entry * (*check)(struct dst_entry *, __u32 cookie);
  27. unsigned int (*default_advmss)(const struct dst_entry *);
  28. unsigned int (*mtu)(const struct dst_entry *);
  29. u32 * (*cow_metrics)(struct dst_entry *, unsigned long);
  30. void (*destroy)(struct dst_entry *);
  31. void (*ifdown)(struct dst_entry *,
  32. struct net_device *dev, int how);
  33. struct dst_entry * (*negative_advice)(struct dst_entry *);
  34. void (*link_failure)(struct sk_buff *);
  35. void (*update_pmtu)(struct dst_entry *dst, struct sock *sk,
  36. struct sk_buff *skb, u32 mtu,
  37. bool confirm_neigh);
  38. void (*redirect)(struct dst_entry *dst, struct sock *sk,
  39. struct sk_buff *skb);
  40. int (*local_out)(struct net *net, struct sock *sk, struct sk_buff *skb);
  41. struct neighbour * (*neigh_lookup)(const struct dst_entry *dst,
  42. struct sk_buff *skb,
  43. const void *daddr);
  44. void (*confirm_neigh)(const struct dst_entry *dst,
  45. const void *daddr);
  46. struct kmem_cache *kmem_cachep;
  47. struct percpu_counter pcpuc_entries ____cacheline_aligned_in_smp;
  48. };
  49. static inline int dst_entries_get_fast(struct dst_ops *dst)
  50. {
  51. return percpu_counter_read_positive(&dst->pcpuc_entries);
  52. }
  53. static inline int dst_entries_get_slow(struct dst_ops *dst)
  54. {
  55. return percpu_counter_sum_positive(&dst->pcpuc_entries);
  56. }
  57. #define DST_PERCPU_COUNTER_BATCH 32
  58. static inline void dst_entries_add(struct dst_ops *dst, int val)
  59. {
  60. percpu_counter_add_batch(&dst->pcpuc_entries, val,
  61. DST_PERCPU_COUNTER_BATCH);
  62. }
  63. static inline int dst_entries_init(struct dst_ops *dst)
  64. {
  65. return percpu_counter_init(&dst->pcpuc_entries, 0, GFP_KERNEL);
  66. }
  67. static inline void dst_entries_destroy(struct dst_ops *dst)
  68. {
  69. percpu_counter_destroy(&dst->pcpuc_entries);
  70. }
  71. #endif