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