act_api.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #ifndef __NET_ACT_API_H
  2. #define __NET_ACT_API_H
  3. /*
  4. * Public police action API for classifiers/qdiscs
  5. */
  6. #include <net/sch_generic.h>
  7. #include <net/pkt_sched.h>
  8. struct tcf_common {
  9. struct hlist_node tcfc_head;
  10. u32 tcfc_index;
  11. int tcfc_refcnt;
  12. int tcfc_bindcnt;
  13. u32 tcfc_capab;
  14. int tcfc_action;
  15. struct tcf_t tcfc_tm;
  16. struct gnet_stats_basic_packed tcfc_bstats;
  17. struct gnet_stats_queue tcfc_qstats;
  18. struct gnet_stats_rate_est64 tcfc_rate_est;
  19. spinlock_t tcfc_lock;
  20. struct rcu_head tcfc_rcu;
  21. struct gnet_stats_basic_cpu __percpu *cpu_bstats;
  22. struct gnet_stats_queue __percpu *cpu_qstats;
  23. };
  24. #define tcf_head common.tcfc_head
  25. #define tcf_index common.tcfc_index
  26. #define tcf_refcnt common.tcfc_refcnt
  27. #define tcf_bindcnt common.tcfc_bindcnt
  28. #define tcf_capab common.tcfc_capab
  29. #define tcf_action common.tcfc_action
  30. #define tcf_tm common.tcfc_tm
  31. #define tcf_bstats common.tcfc_bstats
  32. #define tcf_qstats common.tcfc_qstats
  33. #define tcf_rate_est common.tcfc_rate_est
  34. #define tcf_lock common.tcfc_lock
  35. #define tcf_rcu common.tcfc_rcu
  36. struct tcf_hashinfo {
  37. struct hlist_head *htab;
  38. unsigned int hmask;
  39. spinlock_t lock;
  40. u32 index;
  41. };
  42. static inline unsigned int tcf_hash(u32 index, unsigned int hmask)
  43. {
  44. return index & hmask;
  45. }
  46. static inline int tcf_hashinfo_init(struct tcf_hashinfo *hf, unsigned int mask)
  47. {
  48. int i;
  49. spin_lock_init(&hf->lock);
  50. hf->index = 0;
  51. hf->hmask = mask;
  52. hf->htab = kzalloc((mask + 1) * sizeof(struct hlist_head),
  53. GFP_KERNEL);
  54. if (!hf->htab)
  55. return -ENOMEM;
  56. for (i = 0; i < mask + 1; i++)
  57. INIT_HLIST_HEAD(&hf->htab[i]);
  58. return 0;
  59. }
  60. static inline void tcf_hashinfo_destroy(struct tcf_hashinfo *hf)
  61. {
  62. kfree(hf->htab);
  63. }
  64. /* Update lastuse only if needed, to avoid dirtying a cache line.
  65. * We use a temp variable to avoid fetching jiffies twice.
  66. */
  67. static inline void tcf_lastuse_update(struct tcf_t *tm)
  68. {
  69. unsigned long now = jiffies;
  70. if (tm->lastuse != now)
  71. tm->lastuse = now;
  72. }
  73. #ifdef CONFIG_NET_CLS_ACT
  74. #define ACT_P_CREATED 1
  75. #define ACT_P_DELETED 1
  76. struct tc_action {
  77. void *priv;
  78. const struct tc_action_ops *ops;
  79. __u32 type; /* for backward compat(TCA_OLD_COMPAT) */
  80. __u32 order;
  81. struct list_head list;
  82. };
  83. struct tc_action_ops {
  84. struct list_head head;
  85. struct tcf_hashinfo *hinfo;
  86. char kind[IFNAMSIZ];
  87. __u32 type; /* TBD to match kind */
  88. struct module *owner;
  89. int (*act)(struct sk_buff *, const struct tc_action *, struct tcf_result *);
  90. int (*dump)(struct sk_buff *, struct tc_action *, int, int);
  91. void (*cleanup)(struct tc_action *, int bind);
  92. int (*lookup)(struct tc_action *, u32);
  93. int (*init)(struct net *net, struct nlattr *nla,
  94. struct nlattr *est, struct tc_action *act, int ovr,
  95. int bind);
  96. int (*walk)(struct sk_buff *, struct netlink_callback *, int, struct tc_action *);
  97. };
  98. int tcf_hash_search(struct tc_action *a, u32 index);
  99. u32 tcf_hash_new_index(struct tcf_hashinfo *hinfo);
  100. int tcf_hash_check(u32 index, struct tc_action *a, int bind);
  101. int tcf_hash_create(u32 index, struct nlattr *est, struct tc_action *a,
  102. int size, int bind, bool cpustats);
  103. void tcf_hash_cleanup(struct tc_action *a, struct nlattr *est);
  104. void tcf_hash_insert(struct tc_action *a);
  105. int __tcf_hash_release(struct tc_action *a, bool bind, bool strict);
  106. static inline int tcf_hash_release(struct tc_action *a, bool bind)
  107. {
  108. return __tcf_hash_release(a, bind, false);
  109. }
  110. int tcf_register_action(struct tc_action_ops *a, unsigned int mask);
  111. int tcf_unregister_action(struct tc_action_ops *a);
  112. int tcf_action_destroy(struct list_head *actions, int bind);
  113. int tcf_action_exec(struct sk_buff *skb, const struct list_head *actions,
  114. struct tcf_result *res);
  115. int tcf_action_init(struct net *net, struct nlattr *nla,
  116. struct nlattr *est, char *n, int ovr,
  117. int bind, struct list_head *);
  118. struct tc_action *tcf_action_init_1(struct net *net, struct nlattr *nla,
  119. struct nlattr *est, char *n, int ovr,
  120. int bind);
  121. int tcf_action_dump(struct sk_buff *skb, struct list_head *, int, int);
  122. int tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int, int);
  123. int tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int, int);
  124. int tcf_action_copy_stats(struct sk_buff *, struct tc_action *, int);
  125. #endif /* CONFIG_NET_CLS_ACT */
  126. #endif