Blame view
include/net/act_api.h
7.71 KB
b24413180 License cleanup: ... |
1 |
/* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4c Linux-2.6.12-rc2 |
2 3 4 5 |
#ifndef __NET_ACT_API_H #define __NET_ACT_API_H /* |
0b0f43fe2 net sched: indent... |
6 7 |
* Public action API for classifiers/qdiscs */ |
1da177e4c Linux-2.6.12-rc2 |
8 |
|
036bb4432 net: sched: chang... |
9 |
#include <linux/refcount.h> |
1da177e4c Linux-2.6.12-rc2 |
10 11 |
#include <net/sch_generic.h> #include <net/pkt_sched.h> |
ddf97ccdd net_sched: add ne... |
12 13 |
#include <net/net_namespace.h> #include <net/netns/generic.h> |
1da177e4c Linux-2.6.12-rc2 |
14 |
|
65a206c01 net/sched: Change... |
15 |
struct tcf_idrinfo { |
95278ddaa net_sched: conver... |
16 |
struct mutex lock; |
65a206c01 net/sched: Change... |
17 |
struct idr action_idr; |
981471bd3 net_sched: fix a ... |
18 |
struct net *net; |
a85a970af net_sched: move t... |
19 20 21 22 23 24 |
}; struct tc_action_ops; struct tc_action { const struct tc_action_ops *ops; |
ec0595cc4 net_sched: get ri... |
25 |
__u32 type; /* for backward compat(TCA_OLD_COMPAT) */ |
65a206c01 net/sched: Change... |
26 |
struct tcf_idrinfo *idrinfo; |
a85a970af net_sched: move t... |
27 |
|
ec0595cc4 net_sched: get ri... |
28 |
u32 tcfa_index; |
036bb4432 net: sched: chang... |
29 30 |
refcount_t tcfa_refcnt; atomic_t tcfa_bindcnt; |
ec0595cc4 net_sched: get ri... |
31 32 33 |
int tcfa_action; struct tcf_t tcfa_tm; struct gnet_stats_basic_packed tcfa_bstats; |
28169abad net/sched: Add ha... |
34 |
struct gnet_stats_basic_packed tcfa_bstats_hw; |
ec0595cc4 net_sched: get ri... |
35 |
struct gnet_stats_queue tcfa_qstats; |
1c0d32fde net_sched: gen_es... |
36 |
struct net_rate_estimator __rcu *tcfa_rate_est; |
ec0595cc4 net_sched: get ri... |
37 |
spinlock_t tcfa_lock; |
519c818e8 net: sched: add p... |
38 |
struct gnet_stats_basic_cpu __percpu *cpu_bstats; |
28169abad net/sched: Add ha... |
39 |
struct gnet_stats_basic_cpu __percpu *cpu_bstats_hw; |
519c818e8 net: sched: add p... |
40 |
struct gnet_stats_queue __percpu *cpu_qstats; |
eec94fdb0 net: sched: use r... |
41 |
struct tc_cookie __rcu *act_cookie; |
ee3bbfe80 net/sched: let ac... |
42 |
struct tcf_chain __rcu *goto_chain; |
e38226786 net: sched: updat... |
43 |
u32 tcfa_flags; |
e9ce1cd3c [PKT_SCHED]: Kill... |
44 |
}; |
ec0595cc4 net_sched: get ri... |
45 46 47 |
#define tcf_index common.tcfa_index #define tcf_refcnt common.tcfa_refcnt #define tcf_bindcnt common.tcfa_bindcnt |
ec0595cc4 net_sched: get ri... |
48 49 50 51 52 53 |
#define tcf_action common.tcfa_action #define tcf_tm common.tcfa_tm #define tcf_bstats common.tcfa_bstats #define tcf_qstats common.tcfa_qstats #define tcf_rate_est common.tcfa_rate_est #define tcf_lock common.tcfa_lock |
e9ce1cd3c [PKT_SCHED]: Kill... |
54 |
|
56e5d1ca1 net_sched: act_ga... |
55 56 57 58 59 60 61 62 63 |
/* Update lastuse only if needed, to avoid dirtying a cache line. * We use a temp variable to avoid fetching jiffies twice. */ static inline void tcf_lastuse_update(struct tcf_t *tm) { unsigned long now = jiffies; if (tm->lastuse != now) tm->lastuse = now; |
53eb440f4 net sched actions... |
64 65 |
if (unlikely(!tm->firstuse)) tm->firstuse = now; |
56e5d1ca1 net_sched: act_ga... |
66 |
} |
48d8ee169 net sched actions... |
67 68 69 70 71 72 73 |
static inline void tcf_tm_dump(struct tcf_t *dtm, const struct tcf_t *stm) { dtm->install = jiffies_to_clock_t(jiffies - stm->install); dtm->lastuse = jiffies_to_clock_t(jiffies - stm->lastuse); dtm->firstuse = jiffies_to_clock_t(jiffies - stm->firstuse); dtm->expires = jiffies_to_clock_t(stm->expires); } |
00175aec9 net/sched: Macro ... |
74 75 76 77 |
#ifdef CONFIG_NET_CLS_ACT #define ACT_P_CREATED 1 #define ACT_P_DELETED 1 |
4a5da47d5 net: sched: take ... |
78 |
typedef void (*tc_action_priv_destructor)(void *priv); |
e9ce1cd3c [PKT_SCHED]: Kill... |
79 |
struct tc_action_ops { |
1f747c26c net_sched: conver... |
80 |
struct list_head head; |
1da177e4c Linux-2.6.12-rc2 |
81 |
char kind[IFNAMSIZ]; |
eddd2cf19 net: Change TCA_A... |
82 |
enum tca_id id; /* identifier should match kind */ |
a85a970af net_sched: move t... |
83 |
size_t size; |
1da177e4c Linux-2.6.12-rc2 |
84 |
struct module *owner; |
0b0f43fe2 net sched: indent... |
85 |
int (*act)(struct sk_buff *, const struct tc_action *, |
7fd4b288e tc/act: remove un... |
86 |
struct tcf_result *); /* called under RCU BH lock*/ |
e9ce1cd3c [PKT_SCHED]: Kill... |
87 |
int (*dump)(struct sk_buff *, struct tc_action *, int, int); |
9a63b255d net_sched: remove... |
88 |
void (*cleanup)(struct tc_action *); |
f061b48c1 Revert "net: sche... |
89 |
int (*lookup)(struct net *net, struct tc_action **a, u32 index); |
c1b52739e pkt_sched: namesp... |
90 |
int (*init)(struct net *net, struct nlattr *nla, |
a85a970af net_sched: move t... |
91 |
struct nlattr *est, struct tc_action **act, int ovr, |
85d0966fa net/sched: prepar... |
92 |
int bind, bool rtnl_held, struct tcf_proto *tp, |
abbb0d336 net: sched: exten... |
93 |
u32 flags, struct netlink_ext_ack *extack); |
ddf97ccdd net_sched: add ne... |
94 |
int (*walk)(struct net *, struct sk_buff *, |
1af851558 net: sched: act: ... |
95 |
struct netlink_callback *, int, |
417801055 net: sched: act: ... |
96 97 |
const struct tc_action_ops *, struct netlink_ext_ack *); |
28169abad net/sched: Add ha... |
98 |
void (*stats_update)(struct tc_action *, u64, u32, u64, bool); |
a03b91b17 net sched actions... |
99 |
size_t (*get_fill_size)(const struct tc_action *act); |
470d5060e net: sched: use g... |
100 101 |
struct net_device *(*get_dev)(const struct tc_action *a, tc_action_priv_destructor *destructor); |
4a5da47d5 net: sched: take ... |
102 103 104 |
struct psample_group * (*get_psample_group)(const struct tc_action *a, tc_action_priv_destructor *destructor); |
ddf97ccdd net_sched: add ne... |
105 106 107 |
}; struct tc_action_net { |
65a206c01 net/sched: Change... |
108 |
struct tcf_idrinfo *idrinfo; |
ddf97ccdd net_sched: add ne... |
109 |
const struct tc_action_ops *ops; |
1da177e4c Linux-2.6.12-rc2 |
110 |
}; |
ddf97ccdd net_sched: add ne... |
111 |
static inline |
981471bd3 net_sched: fix a ... |
112 |
int tc_action_net_init(struct net *net, struct tc_action_net *tn, |
c7e460ce5 Revert "net_sched... |
113 |
const struct tc_action_ops *ops) |
ddf97ccdd net_sched: add ne... |
114 115 |
{ int err = 0; |
65a206c01 net/sched: Change... |
116 117 |
tn->idrinfo = kmalloc(sizeof(*tn->idrinfo), GFP_KERNEL); if (!tn->idrinfo) |
ddf97ccdd net_sched: add ne... |
118 119 |
return -ENOMEM; tn->ops = ops; |
981471bd3 net_sched: fix a ... |
120 |
tn->idrinfo->net = net; |
95278ddaa net_sched: conver... |
121 |
mutex_init(&tn->idrinfo->lock); |
65a206c01 net/sched: Change... |
122 |
idr_init(&tn->idrinfo->action_idr); |
ddf97ccdd net_sched: add ne... |
123 124 |
return err; } |
65a206c01 net/sched: Change... |
125 126 |
void tcf_idrinfo_destroy(const struct tc_action_ops *ops, struct tcf_idrinfo *idrinfo); |
ddf97ccdd net_sched: add ne... |
127 |
|
039af9c66 net_sched: switch... |
128 129 |
static inline void tc_action_net_exit(struct list_head *net_list, unsigned int id) |
ddf97ccdd net_sched: add ne... |
130 |
{ |
039af9c66 net_sched: switch... |
131 |
struct net *net; |
a159d3c4b net_sched: acquir... |
132 |
rtnl_lock(); |
039af9c66 net_sched: switch... |
133 134 135 136 137 138 |
list_for_each_entry(net, net_list, exit_list) { struct tc_action_net *tn = net_generic(net, id); tcf_idrinfo_destroy(tn->ops, tn->idrinfo); kfree(tn->idrinfo); } |
a159d3c4b net_sched: acquir... |
139 |
rtnl_unlock(); |
ddf97ccdd net_sched: add ne... |
140 141 142 143 |
} int tcf_generic_walker(struct tc_action_net *tn, struct sk_buff *skb, struct netlink_callback *cb, int type, |
b36201455 net: sched: act: ... |
144 145 |
const struct tc_action_ops *ops, struct netlink_ext_ack *extack); |
65a206c01 net/sched: Change... |
146 |
int tcf_idr_search(struct tc_action_net *tn, struct tc_action **a, u32 index); |
65a206c01 net/sched: Change... |
147 148 |
int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est, struct tc_action **a, const struct tc_action_ops *ops, |
e38226786 net: sched: updat... |
149 150 151 152 153 |
int bind, bool cpustats, u32 flags); int tcf_idr_create_from_flags(struct tc_action_net *tn, u32 index, struct nlattr *est, struct tc_action **a, const struct tc_action_ops *ops, int bind, u32 flags); |
65a206c01 net/sched: Change... |
154 |
void tcf_idr_insert(struct tc_action_net *tn, struct tc_action *a); |
e9ce1cd3c [PKT_SCHED]: Kill... |
155 |
|
0190c1d45 net: sched: atomi... |
156 157 158 |
void tcf_idr_cleanup(struct tc_action_net *tn, u32 index); int tcf_idr_check_alloc(struct tc_action_net *tn, u32 *index, struct tc_action **a, int bind); |
65a206c01 net/sched: Change... |
159 |
int __tcf_idr_release(struct tc_action *a, bool bind, bool strict); |
28e6b67f0 net: sched: fix r... |
160 |
|
65a206c01 net/sched: Change... |
161 |
static inline int tcf_idr_release(struct tc_action *a, bool bind) |
28e6b67f0 net: sched: fix r... |
162 |
{ |
65a206c01 net/sched: Change... |
163 |
return __tcf_idr_release(a, bind, false); |
28e6b67f0 net: sched: fix r... |
164 |
} |
ddf97ccdd net_sched: add ne... |
165 |
int tcf_register_action(struct tc_action_ops *a, struct pernet_operations *ops); |
0b0f43fe2 net sched: indent... |
166 167 |
int tcf_unregister_action(struct tc_action_ops *a, struct pernet_operations *ops); |
90b73b77d net: sched: chang... |
168 |
int tcf_action_destroy(struct tc_action *actions[], int bind); |
22dc13c83 net_sched: conver... |
169 170 |
int tcf_action_exec(struct sk_buff *skb, struct tc_action **actions, int nr_actions, struct tcf_result *res); |
9fb9f251d net: sched: push ... |
171 172 |
int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla, struct nlattr *est, char *name, int ovr, int bind, |
90b73b77d net: sched: chang... |
173 |
struct tc_action *actions[], size_t *attr_size, |
789871bb2 net: sched: imple... |
174 |
bool rtnl_held, struct netlink_ext_ack *extack); |
9fb9f251d net: sched: push ... |
175 176 |
struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp, struct nlattr *nla, struct nlattr *est, |
aea0d7278 net: sched: act: ... |
177 |
char *name, int ovr, int bind, |
789871bb2 net: sched: imple... |
178 |
bool rtnl_held, |
aea0d7278 net: sched: act: ... |
179 |
struct netlink_ext_ack *extack); |
90b73b77d net: sched: chang... |
180 181 |
int tcf_action_dump(struct sk_buff *skb, struct tc_action *actions[], int bind, int ref); |
5c15257f9 net: Remove exter... |
182 183 |
int tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int, int); int tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int, int); |
5e1ad95b6 net: sched: extra... |
184 185 186 187 |
static inline void tcf_action_update_bstats(struct tc_action *a, struct sk_buff *skb) { |
5e174d5e7 net: sched: modif... |
188 189 190 191 192 193 194 |
if (likely(a->cpu_bstats)) { bstats_cpu_update(this_cpu_ptr(a->cpu_bstats), skb); return; } spin_lock(&a->tcfa_lock); bstats_update(&a->tcfa_bstats, skb); spin_unlock(&a->tcfa_lock); |
26b537a88 net: sched: extra... |
195 196 197 198 |
} static inline void tcf_action_inc_drop_qstats(struct tc_action *a) { |
5e174d5e7 net: sched: modif... |
199 200 201 202 203 204 205 |
if (likely(a->cpu_qstats)) { qstats_drop_inc(this_cpu_ptr(a->cpu_qstats)); return; } spin_lock(&a->tcfa_lock); qstats_drop_inc(&a->tcfa_qstats); spin_unlock(&a->tcfa_lock); |
26b537a88 net: sched: extra... |
206 207 208 209 |
} static inline void tcf_action_inc_overlimit_qstats(struct tc_action *a) { |
5e174d5e7 net: sched: modif... |
210 211 212 213 214 215 216 |
if (likely(a->cpu_qstats)) { qstats_overlimit_inc(this_cpu_ptr(a->cpu_qstats)); return; } spin_lock(&a->tcfa_lock); qstats_overlimit_inc(&a->tcfa_qstats); spin_unlock(&a->tcfa_lock); |
26b537a88 net: sched: extra... |
217 |
} |
c8ecebd04 net: sched: extra... |
218 219 |
void tcf_action_update_stats(struct tc_action *a, u64 bytes, u32 packets, bool drop, bool hw); |
5c15257f9 net: Remove exter... |
220 |
int tcf_action_copy_stats(struct sk_buff *, struct tc_action *, int); |
00175aec9 net/sched: Macro ... |
221 |
|
85d0966fa net/sched: prepar... |
222 223 224 225 226 |
int tcf_action_check_ctrlact(int action, struct tcf_proto *tp, struct tcf_chain **handle, struct netlink_ext_ack *newchain); struct tcf_chain *tcf_action_set_ctrlact(struct tc_action *a, int action, struct tcf_chain *newchain); |
2734437ef net_sched: move t... |
227 |
#endif /* CONFIG_NET_CLS_ACT */ |
86cb13e4e mlxsw: spectrum: ... |
228 |
|
380407023 net/sched: Enable... |
229 |
static inline void tcf_action_stats_update(struct tc_action *a, u64 bytes, |
28169abad net/sched: Add ha... |
230 |
u64 packets, u64 lastuse, bool hw) |
380407023 net/sched: Enable... |
231 |
{ |
2734437ef net_sched: move t... |
232 |
#ifdef CONFIG_NET_CLS_ACT |
380407023 net/sched: Enable... |
233 234 |
if (!a->ops->stats_update) return; |
28169abad net/sched: Add ha... |
235 |
a->ops->stats_update(a, bytes, packets, lastuse, hw); |
2734437ef net_sched: move t... |
236 |
#endif |
380407023 net/sched: Enable... |
237 |
} |
b3f55bdda net: sched: intro... |
238 |
|
1da177e4c Linux-2.6.12-rc2 |
239 |
#endif |