]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blame - include/net/act_api.h
Merge tag 'wireless-drivers-for-davem-2019-03-19' of git://git.kernel.org/pub/scm...
[mirror_ubuntu-eoan-kernel.git] / include / net / act_api.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
1da177e4
LT
2#ifndef __NET_ACT_API_H
3#define __NET_ACT_API_H
4
5/*
0b0f43fe
JHS
6 * Public action API for classifiers/qdiscs
7*/
1da177e4 8
036bb443 9#include <linux/refcount.h>
1da177e4
LT
10#include <net/sch_generic.h>
11#include <net/pkt_sched.h>
ddf97ccd
WC
12#include <net/net_namespace.h>
13#include <net/netns/generic.h>
1da177e4 14
65a206c0 15struct tcf_idrinfo {
95278dda 16 struct mutex lock;
65a206c0 17 struct idr action_idr;
a85a970a
WC
18};
19
20struct tc_action_ops;
21
22struct tc_action {
23 const struct tc_action_ops *ops;
ec0595cc
WC
24 __u32 type; /* for backward compat(TCA_OLD_COMPAT) */
25 __u32 order;
65a206c0 26 struct tcf_idrinfo *idrinfo;
a85a970a 27
ec0595cc 28 u32 tcfa_index;
036bb443
VB
29 refcount_t tcfa_refcnt;
30 atomic_t tcfa_bindcnt;
ec0595cc
WC
31 int tcfa_action;
32 struct tcf_t tcfa_tm;
33 struct gnet_stats_basic_packed tcfa_bstats;
28169aba 34 struct gnet_stats_basic_packed tcfa_bstats_hw;
ec0595cc 35 struct gnet_stats_queue tcfa_qstats;
1c0d32fd 36 struct net_rate_estimator __rcu *tcfa_rate_est;
ec0595cc 37 spinlock_t tcfa_lock;
519c818e 38 struct gnet_stats_basic_cpu __percpu *cpu_bstats;
28169aba 39 struct gnet_stats_basic_cpu __percpu *cpu_bstats_hw;
519c818e 40 struct gnet_stats_queue __percpu *cpu_qstats;
eec94fdb 41 struct tc_cookie __rcu *act_cookie;
db50514f 42 struct tcf_chain *goto_chain;
e9ce1cd3 43};
ec0595cc
WC
44#define tcf_index common.tcfa_index
45#define tcf_refcnt common.tcfa_refcnt
46#define tcf_bindcnt common.tcfa_bindcnt
ec0595cc
WC
47#define tcf_action common.tcfa_action
48#define tcf_tm common.tcfa_tm
49#define tcf_bstats common.tcfa_bstats
50#define tcf_qstats common.tcfa_qstats
51#define tcf_rate_est common.tcfa_rate_est
52#define tcf_lock common.tcfa_lock
e9ce1cd3 53
56e5d1ca
ED
54/* Update lastuse only if needed, to avoid dirtying a cache line.
55 * We use a temp variable to avoid fetching jiffies twice.
56 */
57static inline void tcf_lastuse_update(struct tcf_t *tm)
58{
59 unsigned long now = jiffies;
60
61 if (tm->lastuse != now)
62 tm->lastuse = now;
53eb440f
JHS
63 if (unlikely(!tm->firstuse))
64 tm->firstuse = now;
56e5d1ca
ED
65}
66
48d8ee16
JHS
67static inline void tcf_tm_dump(struct tcf_t *dtm, const struct tcf_t *stm)
68{
69 dtm->install = jiffies_to_clock_t(jiffies - stm->install);
70 dtm->lastuse = jiffies_to_clock_t(jiffies - stm->lastuse);
71 dtm->firstuse = jiffies_to_clock_t(jiffies - stm->firstuse);
72 dtm->expires = jiffies_to_clock_t(stm->expires);
73}
74
00175aec
AV
75#ifdef CONFIG_NET_CLS_ACT
76
77#define ACT_P_CREATED 1
78#define ACT_P_DELETED 1
79
e9ce1cd3 80struct tc_action_ops {
1f747c26 81 struct list_head head;
1da177e4 82 char kind[IFNAMSIZ];
eddd2cf1 83 enum tca_id id; /* identifier should match kind */
a85a970a 84 size_t size;
1da177e4 85 struct module *owner;
0b0f43fe 86 int (*act)(struct sk_buff *, const struct tc_action *,
7fd4b288 87 struct tcf_result *); /* called under RCU BH lock*/
e9ce1cd3 88 int (*dump)(struct sk_buff *, struct tc_action *, int, int);
9a63b255 89 void (*cleanup)(struct tc_action *);
f061b48c 90 int (*lookup)(struct net *net, struct tc_action **a, u32 index);
c1b52739 91 int (*init)(struct net *net, struct nlattr *nla,
a85a970a 92 struct nlattr *est, struct tc_action **act, int ovr,
789871bb
VB
93 int bind, bool rtnl_held,
94 struct netlink_ext_ack *extack);
ddf97ccd 95 int (*walk)(struct net *, struct sk_buff *,
1af85155 96 struct netlink_callback *, int,
41780105
AA
97 const struct tc_action_ops *,
98 struct netlink_ext_ack *);
28169aba 99 void (*stats_update)(struct tc_action *, u64, u32, u64, bool);
a03b91b1 100 size_t (*get_fill_size)(const struct tc_action *act);
843e79d0 101 struct net_device *(*get_dev)(const struct tc_action *a);
84a75b32 102 void (*put_dev)(struct net_device *dev);
ddf97ccd
WC
103};
104
105struct tc_action_net {
65a206c0 106 struct tcf_idrinfo *idrinfo;
ddf97ccd 107 const struct tc_action_ops *ops;
1da177e4
LT
108};
109
ddf97ccd 110static inline
0b0f43fe 111int tc_action_net_init(struct tc_action_net *tn,
c7e460ce 112 const struct tc_action_ops *ops)
ddf97ccd
WC
113{
114 int err = 0;
115
65a206c0
CM
116 tn->idrinfo = kmalloc(sizeof(*tn->idrinfo), GFP_KERNEL);
117 if (!tn->idrinfo)
ddf97ccd
WC
118 return -ENOMEM;
119 tn->ops = ops;
95278dda 120 mutex_init(&tn->idrinfo->lock);
65a206c0 121 idr_init(&tn->idrinfo->action_idr);
ddf97ccd
WC
122 return err;
123}
124
65a206c0
CM
125void tcf_idrinfo_destroy(const struct tc_action_ops *ops,
126 struct tcf_idrinfo *idrinfo);
ddf97ccd 127
039af9c6
CW
128static inline void tc_action_net_exit(struct list_head *net_list,
129 unsigned int id)
ddf97ccd 130{
039af9c6
CW
131 struct net *net;
132
a159d3c4 133 rtnl_lock();
039af9c6
CW
134 list_for_each_entry(net, net_list, exit_list) {
135 struct tc_action_net *tn = net_generic(net, id);
136
137 tcf_idrinfo_destroy(tn->ops, tn->idrinfo);
138 kfree(tn->idrinfo);
139 }
a159d3c4 140 rtnl_unlock();
ddf97ccd
WC
141}
142
143int tcf_generic_walker(struct tc_action_net *tn, struct sk_buff *skb,
144 struct netlink_callback *cb, int type,
b3620145
AA
145 const struct tc_action_ops *ops,
146 struct netlink_ext_ack *extack);
65a206c0 147int tcf_idr_search(struct tc_action_net *tn, struct tc_action **a, u32 index);
65a206c0
CM
148int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est,
149 struct tc_action **a, const struct tc_action_ops *ops,
150 int bind, bool cpustats);
65a206c0 151void tcf_idr_insert(struct tc_action_net *tn, struct tc_action *a);
e9ce1cd3 152
0190c1d4
VB
153void tcf_idr_cleanup(struct tc_action_net *tn, u32 index);
154int tcf_idr_check_alloc(struct tc_action_net *tn, u32 *index,
155 struct tc_action **a, int bind);
65a206c0 156int __tcf_idr_release(struct tc_action *a, bool bind, bool strict);
28e6b67f 157
65a206c0 158static inline int tcf_idr_release(struct tc_action *a, bool bind)
28e6b67f 159{
65a206c0 160 return __tcf_idr_release(a, bind, false);
28e6b67f
DB
161}
162
ddf97ccd 163int tcf_register_action(struct tc_action_ops *a, struct pernet_operations *ops);
0b0f43fe
JHS
164int tcf_unregister_action(struct tc_action_ops *a,
165 struct pernet_operations *ops);
90b73b77 166int tcf_action_destroy(struct tc_action *actions[], int bind);
22dc13c8
WC
167int tcf_action_exec(struct sk_buff *skb, struct tc_action **actions,
168 int nr_actions, struct tcf_result *res);
9fb9f251
JP
169int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla,
170 struct nlattr *est, char *name, int ovr, int bind,
90b73b77 171 struct tc_action *actions[], size_t *attr_size,
789871bb 172 bool rtnl_held, struct netlink_ext_ack *extack);
9fb9f251
JP
173struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp,
174 struct nlattr *nla, struct nlattr *est,
aea0d727 175 char *name, int ovr, int bind,
789871bb 176 bool rtnl_held,
aea0d727 177 struct netlink_ext_ack *extack);
90b73b77
VB
178int tcf_action_dump(struct sk_buff *skb, struct tc_action *actions[], int bind,
179 int ref);
5c15257f
JP
180int tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int, int);
181int tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int, int);
182int tcf_action_copy_stats(struct sk_buff *, struct tc_action *, int);
00175aec 183
2734437e 184#endif /* CONFIG_NET_CLS_ACT */
86cb13e4 185
38040702 186static inline void tcf_action_stats_update(struct tc_action *a, u64 bytes,
28169aba 187 u64 packets, u64 lastuse, bool hw)
38040702 188{
2734437e 189#ifdef CONFIG_NET_CLS_ACT
38040702
AV
190 if (!a->ops->stats_update)
191 return;
192
28169aba 193 a->ops->stats_update(a, bytes, packets, lastuse, hw);
2734437e 194#endif
38040702
AV
195}
196
b3f55bdd 197
1da177e4 198#endif