act_api.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #define tca_gen(name) \
  9. struct tcf_##name *next; \
  10. u32 index; \
  11. int refcnt; \
  12. int bindcnt; \
  13. u32 capab; \
  14. int action; \
  15. struct tcf_t tm; \
  16. struct gnet_stats_basic bstats; \
  17. struct gnet_stats_queue qstats; \
  18. struct gnet_stats_rate_est rate_est; \
  19. spinlock_t *stats_lock; \
  20. spinlock_t lock
  21. struct tcf_police
  22. {
  23. tca_gen(police);
  24. int result;
  25. u32 ewma_rate;
  26. u32 burst;
  27. u32 mtu;
  28. u32 toks;
  29. u32 ptoks;
  30. psched_time_t t_c;
  31. struct qdisc_rate_table *R_tab;
  32. struct qdisc_rate_table *P_tab;
  33. };
  34. #ifdef CONFIG_NET_CLS_ACT
  35. #define ACT_P_CREATED 1
  36. #define ACT_P_DELETED 1
  37. struct tcf_act_hdr
  38. {
  39. tca_gen(act_hdr);
  40. };
  41. struct tc_action
  42. {
  43. void *priv;
  44. struct tc_action_ops *ops;
  45. __u32 type; /* for backward compat(TCA_OLD_COMPAT) */
  46. __u32 order;
  47. struct tc_action *next;
  48. };
  49. #define TCA_CAP_NONE 0
  50. struct tc_action_ops
  51. {
  52. struct tc_action_ops *next;
  53. char kind[IFNAMSIZ];
  54. __u32 type; /* TBD to match kind */
  55. __u32 capab; /* capabilities includes 4 bit version */
  56. struct module *owner;
  57. int (*act)(struct sk_buff *, struct tc_action *, struct tcf_result *);
  58. int (*get_stats)(struct sk_buff *, struct tc_action *);
  59. int (*dump)(struct sk_buff *, struct tc_action *,int , int);
  60. int (*cleanup)(struct tc_action *, int bind);
  61. int (*lookup)(struct tc_action *, u32 );
  62. int (*init)(struct rtattr *,struct rtattr *,struct tc_action *, int , int );
  63. int (*walk)(struct sk_buff *, struct netlink_callback *, int , struct tc_action *);
  64. };
  65. extern int tcf_register_action(struct tc_action_ops *a);
  66. extern int tcf_unregister_action(struct tc_action_ops *a);
  67. extern void tcf_action_destroy(struct tc_action *a, int bind);
  68. extern int tcf_action_exec(struct sk_buff *skb, struct tc_action *a, struct tcf_result *res);
  69. extern struct tc_action *tcf_action_init(struct rtattr *rta, struct rtattr *est, char *n, int ovr, int bind, int *err);
  70. extern struct tc_action *tcf_action_init_1(struct rtattr *rta, struct rtattr *est, char *n, int ovr, int bind, int *err);
  71. extern int tcf_action_dump(struct sk_buff *skb, struct tc_action *a, int, int);
  72. extern int tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int, int);
  73. extern int tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int, int);
  74. extern int tcf_action_copy_stats (struct sk_buff *,struct tc_action *, int);
  75. #endif /* CONFIG_NET_CLS_ACT */
  76. extern int tcf_police(struct sk_buff *skb, struct tcf_police *p);
  77. extern void tcf_police_destroy(struct tcf_police *p);
  78. extern struct tcf_police * tcf_police_locate(struct rtattr *rta, struct rtattr *est);
  79. extern int tcf_police_dump(struct sk_buff *skb, struct tcf_police *p);
  80. extern int tcf_police_dump_stats(struct sk_buff *skb, struct tcf_police *p);
  81. static inline int
  82. tcf_police_release(struct tcf_police *p, int bind)
  83. {
  84. int ret = 0;
  85. #ifdef CONFIG_NET_CLS_ACT
  86. if (p) {
  87. if (bind) {
  88. p->bindcnt--;
  89. }
  90. p->refcnt--;
  91. if (p->refcnt <= 0 && !p->bindcnt) {
  92. tcf_police_destroy(p);
  93. ret = 1;
  94. }
  95. }
  96. #else
  97. if (p && --p->refcnt == 0)
  98. tcf_police_destroy(p);
  99. #endif /* CONFIG_NET_CLS_ACT */
  100. return ret;
  101. }
  102. #endif