]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #ifndef __NET_ACT_API_H |
2 | #define __NET_ACT_API_H | |
3 | ||
4 | /* | |
0b0f43fe JHS |
5 | * Public action API for classifiers/qdiscs |
6 | */ | |
1da177e4 LT |
7 | |
8 | #include <net/sch_generic.h> | |
9 | #include <net/pkt_sched.h> | |
ddf97ccd WC |
10 | #include <net/net_namespace.h> |
11 | #include <net/netns/generic.h> | |
1da177e4 | 12 | |
65a206c0 CM |
13 | struct tcf_idrinfo { |
14 | spinlock_t lock; | |
15 | struct idr action_idr; | |
a85a970a WC |
16 | }; |
17 | ||
18 | struct tc_action_ops; | |
19 | ||
20 | struct tc_action { | |
21 | const struct tc_action_ops *ops; | |
ec0595cc WC |
22 | __u32 type; /* for backward compat(TCA_OLD_COMPAT) */ |
23 | __u32 order; | |
24 | struct list_head list; | |
65a206c0 | 25 | struct tcf_idrinfo *idrinfo; |
a85a970a | 26 | |
ec0595cc WC |
27 | u32 tcfa_index; |
28 | int tcfa_refcnt; | |
29 | int tcfa_bindcnt; | |
30 | u32 tcfa_capab; | |
31 | int tcfa_action; | |
32 | struct tcf_t tcfa_tm; | |
33 | struct gnet_stats_basic_packed tcfa_bstats; | |
34 | struct gnet_stats_queue tcfa_qstats; | |
1c0d32fd | 35 | struct net_rate_estimator __rcu *tcfa_rate_est; |
ec0595cc | 36 | spinlock_t tcfa_lock; |
519c818e ED |
37 | struct gnet_stats_basic_cpu __percpu *cpu_bstats; |
38 | struct gnet_stats_queue __percpu *cpu_qstats; | |
1045ba77 | 39 | struct tc_cookie *act_cookie; |
db50514f | 40 | struct tcf_chain *goto_chain; |
e9ce1cd3 | 41 | }; |
ec0595cc WC |
42 | #define tcf_index common.tcfa_index |
43 | #define tcf_refcnt common.tcfa_refcnt | |
44 | #define tcf_bindcnt common.tcfa_bindcnt | |
45 | #define tcf_capab common.tcfa_capab | |
46 | #define tcf_action common.tcfa_action | |
47 | #define tcf_tm common.tcfa_tm | |
48 | #define tcf_bstats common.tcfa_bstats | |
49 | #define tcf_qstats common.tcfa_qstats | |
50 | #define tcf_rate_est common.tcfa_rate_est | |
51 | #define tcf_lock common.tcfa_lock | |
e9ce1cd3 | 52 | |
56e5d1ca ED |
53 | /* Update lastuse only if needed, to avoid dirtying a cache line. |
54 | * We use a temp variable to avoid fetching jiffies twice. | |
55 | */ | |
56 | static inline void tcf_lastuse_update(struct tcf_t *tm) | |
57 | { | |
58 | unsigned long now = jiffies; | |
59 | ||
60 | if (tm->lastuse != now) | |
61 | tm->lastuse = now; | |
53eb440f JHS |
62 | if (unlikely(!tm->firstuse)) |
63 | tm->firstuse = now; | |
56e5d1ca ED |
64 | } |
65 | ||
48d8ee16 JHS |
66 | static inline void tcf_tm_dump(struct tcf_t *dtm, const struct tcf_t *stm) |
67 | { | |
68 | dtm->install = jiffies_to_clock_t(jiffies - stm->install); | |
69 | dtm->lastuse = jiffies_to_clock_t(jiffies - stm->lastuse); | |
70 | dtm->firstuse = jiffies_to_clock_t(jiffies - stm->firstuse); | |
71 | dtm->expires = jiffies_to_clock_t(stm->expires); | |
72 | } | |
73 | ||
00175aec AV |
74 | #ifdef CONFIG_NET_CLS_ACT |
75 | ||
76 | #define ACT_P_CREATED 1 | |
77 | #define ACT_P_DELETED 1 | |
78 | ||
e9ce1cd3 | 79 | struct tc_action_ops { |
1f747c26 | 80 | struct list_head head; |
1da177e4 LT |
81 | char kind[IFNAMSIZ]; |
82 | __u32 type; /* TBD to match kind */ | |
a85a970a | 83 | size_t size; |
1da177e4 | 84 | struct module *owner; |
0b0f43fe JHS |
85 | int (*act)(struct sk_buff *, const struct tc_action *, |
86 | struct tcf_result *); | |
e9ce1cd3 | 87 | int (*dump)(struct sk_buff *, struct tc_action *, int, int); |
a5b5c958 | 88 | void (*cleanup)(struct tc_action *, int bind); |
a85a970a | 89 | int (*lookup)(struct net *, struct tc_action **, u32); |
c1b52739 | 90 | int (*init)(struct net *net, struct nlattr *nla, |
a85a970a | 91 | struct nlattr *est, struct tc_action **act, int ovr, |
c1b52739 | 92 | int bind); |
ddf97ccd | 93 | int (*walk)(struct net *, struct sk_buff *, |
a85a970a | 94 | struct netlink_callback *, int, const struct tc_action_ops *); |
38040702 | 95 | void (*stats_update)(struct tc_action *, u64, u32, u64); |
255cb304 HHZ |
96 | int (*get_dev)(const struct tc_action *a, struct net *net, |
97 | struct net_device **mirred_dev); | |
ddf97ccd WC |
98 | }; |
99 | ||
100 | struct tc_action_net { | |
65a206c0 | 101 | struct tcf_idrinfo *idrinfo; |
ddf97ccd | 102 | const struct tc_action_ops *ops; |
1da177e4 LT |
103 | }; |
104 | ||
ddf97ccd | 105 | static inline |
0b0f43fe | 106 | int tc_action_net_init(struct tc_action_net *tn, |
65a206c0 | 107 | const struct tc_action_ops *ops) |
ddf97ccd WC |
108 | { |
109 | int err = 0; | |
110 | ||
65a206c0 CM |
111 | tn->idrinfo = kmalloc(sizeof(*tn->idrinfo), GFP_KERNEL); |
112 | if (!tn->idrinfo) | |
ddf97ccd WC |
113 | return -ENOMEM; |
114 | tn->ops = ops; | |
65a206c0 CM |
115 | spin_lock_init(&tn->idrinfo->lock); |
116 | idr_init(&tn->idrinfo->action_idr); | |
ddf97ccd WC |
117 | return err; |
118 | } | |
119 | ||
65a206c0 CM |
120 | void tcf_idrinfo_destroy(const struct tc_action_ops *ops, |
121 | struct tcf_idrinfo *idrinfo); | |
ddf97ccd WC |
122 | |
123 | static inline void tc_action_net_exit(struct tc_action_net *tn) | |
124 | { | |
65a206c0 CM |
125 | tcf_idrinfo_destroy(tn->ops, tn->idrinfo); |
126 | kfree(tn->idrinfo); | |
ddf97ccd WC |
127 | } |
128 | ||
129 | int tcf_generic_walker(struct tc_action_net *tn, struct sk_buff *skb, | |
130 | struct netlink_callback *cb, int type, | |
a85a970a | 131 | const struct tc_action_ops *ops); |
65a206c0 CM |
132 | int tcf_idr_search(struct tc_action_net *tn, struct tc_action **a, u32 index); |
133 | bool tcf_idr_check(struct tc_action_net *tn, u32 index, struct tc_action **a, | |
b2313077 | 134 | int bind); |
65a206c0 CM |
135 | int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est, |
136 | struct tc_action **a, const struct tc_action_ops *ops, | |
137 | int bind, bool cpustats); | |
138 | void tcf_idr_cleanup(struct tc_action *a, struct nlattr *est); | |
139 | void tcf_idr_insert(struct tc_action_net *tn, struct tc_action *a); | |
e9ce1cd3 | 140 | |
65a206c0 | 141 | int __tcf_idr_release(struct tc_action *a, bool bind, bool strict); |
28e6b67f | 142 | |
65a206c0 | 143 | static inline int tcf_idr_release(struct tc_action *a, bool bind) |
28e6b67f | 144 | { |
65a206c0 | 145 | return __tcf_idr_release(a, bind, false); |
28e6b67f DB |
146 | } |
147 | ||
ddf97ccd | 148 | int tcf_register_action(struct tc_action_ops *a, struct pernet_operations *ops); |
0b0f43fe JHS |
149 | int tcf_unregister_action(struct tc_action_ops *a, |
150 | struct pernet_operations *ops); | |
55334a5d | 151 | int tcf_action_destroy(struct list_head *actions, int bind); |
22dc13c8 WC |
152 | int tcf_action_exec(struct sk_buff *skb, struct tc_action **actions, |
153 | int nr_actions, struct tcf_result *res); | |
9fb9f251 JP |
154 | int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla, |
155 | struct nlattr *est, char *name, int ovr, int bind, | |
156 | struct list_head *actions); | |
157 | struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp, | |
158 | struct nlattr *nla, struct nlattr *est, | |
159 | char *name, int ovr, int bind); | |
33be6271 | 160 | int tcf_action_dump(struct sk_buff *skb, struct list_head *, int, int); |
5c15257f JP |
161 | int tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int, int); |
162 | int tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int, int); | |
163 | int tcf_action_copy_stats(struct sk_buff *, struct tc_action *, int); | |
00175aec | 164 | |
2734437e | 165 | #endif /* CONFIG_NET_CLS_ACT */ |
86cb13e4 | 166 | |
38040702 AV |
167 | static inline void tcf_action_stats_update(struct tc_action *a, u64 bytes, |
168 | u64 packets, u64 lastuse) | |
169 | { | |
2734437e | 170 | #ifdef CONFIG_NET_CLS_ACT |
38040702 AV |
171 | if (!a->ops->stats_update) |
172 | return; | |
173 | ||
174 | a->ops->stats_update(a, bytes, packets, lastuse); | |
2734437e | 175 | #endif |
38040702 AV |
176 | } |
177 | ||
1da177e4 | 178 | #endif |