act_api.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. };
  22. #define tcf_head common.tcfc_head
  23. #define tcf_index common.tcfc_index
  24. #define tcf_refcnt common.tcfc_refcnt
  25. #define tcf_bindcnt common.tcfc_bindcnt
  26. #define tcf_capab common.tcfc_capab
  27. #define tcf_action common.tcfc_action
  28. #define tcf_tm common.tcfc_tm
  29. #define tcf_bstats common.tcfc_bstats
  30. #define tcf_qstats common.tcfc_qstats
  31. #define tcf_rate_est common.tcfc_rate_est
  32. #define tcf_lock common.tcfc_lock
  33. #define tcf_rcu common.tcfc_rcu
  34. struct tcf_hashinfo {
  35. struct hlist_head *htab;
  36. unsigned int hmask;
  37. spinlock_t lock;
  38. u32 index;
  39. };
  40. static inline unsigned int tcf_hash(u32 index, unsigned int hmask)
  41. {
  42. return index & hmask;
  43. }
  44. static inline int tcf_hashinfo_init(struct tcf_hashinfo *hf, unsigned int mask)
  45. {
  46. int i;
  47. spin_lock_init(&hf->lock);
  48. hf->index = 0;
  49. hf->hmask = mask;
  50. hf->htab = kzalloc((mask + 1) * sizeof(struct hlist_head),
  51. GFP_KERNEL);
  52. if (!hf->htab)
  53. return -ENOMEM;
  54. for (i = 0; i < mask + 1; i++)
  55. INIT_HLIST_HEAD(&hf->htab[i]);
  56. return 0;
  57. }
  58. static inline void tcf_hashinfo_destroy(struct tcf_hashinfo *hf)
  59. {
  60. kfree(hf->htab);
  61. }
  62. #ifdef CONFIG_NET_CLS_ACT
  63. #define ACT_P_CREATED 1
  64. #define ACT_P_DELETED 1
  65. struct tc_action {
  66. void *priv;
  67. const struct tc_action_ops *ops;
  68. __u32 type; /* for backward compat(TCA_OLD_COMPAT) */
  69. __u32 order;
  70. struct list_head list;
  71. };
  72. struct tc_action_ops {
  73. struct list_head head;
  74. struct tcf_hashinfo *hinfo;
  75. char kind[IFNAMSIZ];
  76. __u32 type; /* TBD to match kind */
  77. struct module *owner;
  78. int (*act)(struct sk_buff *, const struct tc_action *, struct tcf_result *);
  79. int (*dump)(struct sk_buff *, struct tc_action *, int, int);
  80. void (*cleanup)(struct tc_action *, int bind);
  81. int (*lookup)(struct tc_action *, u32);
  82. int (*init)(struct net *net, struct nlattr *nla,
  83. struct nlattr *est, struct tc_action *act, int ovr,
  84. int bind);
  85. int (*walk)(struct sk_buff *, struct netlink_callback *, int, struct tc_action *);
  86. };
  87. int tcf_hash_search(struct tc_action *a, u32 index);
  88. void tcf_hash_destroy(struct tc_action *a);
  89. int tcf_hash_release(struct tc_action *a, int bind);
  90. u32 tcf_hash_new_index(struct tcf_hashinfo *hinfo);
  91. int tcf_hash_check(u32 index, struct tc_action *a, int bind);
  92. int tcf_hash_create(u32 index, struct nlattr *est, struct tc_action *a,
  93. int size, int bind);
  94. void tcf_hash_cleanup(struct tc_action *a, struct nlattr *est);
  95. void tcf_hash_insert(struct tc_action *a);
  96. int tcf_register_action(struct tc_action_ops *a, unsigned int mask);
  97. int tcf_unregister_action(struct tc_action_ops *a);
  98. int tcf_action_destroy(struct list_head *actions, int bind);
  99. int tcf_action_exec(struct sk_buff *skb, const struct list_head *actions,
  100. struct tcf_result *res);
  101. int tcf_action_init(struct net *net, struct nlattr *nla,
  102. struct nlattr *est, char *n, int ovr,
  103. int bind, struct list_head *);
  104. struct tc_action *tcf_action_init_1(struct net *net, struct nlattr *nla,
  105. struct nlattr *est, char *n, int ovr,
  106. int bind);
  107. int tcf_action_dump(struct sk_buff *skb, struct list_head *, int, int);
  108. int tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int, int);
  109. int tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int, int);
  110. int tcf_action_copy_stats(struct sk_buff *, struct tc_action *, int);
  111. #endif /* CONFIG_NET_CLS_ACT */
  112. #endif