dst_ops.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef _NET_DST_OPS_H
  2. #define _NET_DST_OPS_H
  3. #include <linux/types.h>
  4. #include <linux/percpu_counter.h>
  5. struct dst_entry;
  6. struct kmem_cachep;
  7. struct net_device;
  8. struct sk_buff;
  9. struct dst_ops {
  10. unsigned short family;
  11. __be16 protocol;
  12. unsigned gc_thresh;
  13. int (*gc)(struct dst_ops *ops);
  14. struct dst_entry * (*check)(struct dst_entry *, __u32 cookie);
  15. void (*destroy)(struct dst_entry *);
  16. void (*ifdown)(struct dst_entry *,
  17. struct net_device *dev, int how);
  18. struct dst_entry * (*negative_advice)(struct dst_entry *);
  19. void (*link_failure)(struct sk_buff *);
  20. void (*update_pmtu)(struct dst_entry *dst, u32 mtu);
  21. int (*local_out)(struct sk_buff *skb);
  22. struct kmem_cache *kmem_cachep;
  23. struct percpu_counter pcpuc_entries ____cacheline_aligned_in_smp;
  24. };
  25. static inline int dst_entries_get_fast(struct dst_ops *dst)
  26. {
  27. return percpu_counter_read_positive(&dst->pcpuc_entries);
  28. }
  29. static inline int dst_entries_get_slow(struct dst_ops *dst)
  30. {
  31. int res;
  32. local_bh_disable();
  33. res = percpu_counter_sum_positive(&dst->pcpuc_entries);
  34. local_bh_enable();
  35. return res;
  36. }
  37. static inline void dst_entries_add(struct dst_ops *dst, int val)
  38. {
  39. local_bh_disable();
  40. percpu_counter_add(&dst->pcpuc_entries, val);
  41. local_bh_enable();
  42. }
  43. static inline int dst_entries_init(struct dst_ops *dst)
  44. {
  45. return percpu_counter_init(&dst->pcpuc_entries, 0);
  46. }
  47. static inline void dst_entries_destroy(struct dst_ops *dst)
  48. {
  49. percpu_counter_destroy(&dst->pcpuc_entries);
  50. }
  51. #endif