.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * net/sched/cls_basic.c Basic Packet Classifier. |
---|
3 | | - * |
---|
4 | | - * This program is free software; you can redistribute it and/or |
---|
5 | | - * modify it under the terms of the GNU General Public License |
---|
6 | | - * as published by the Free Software Foundation; either version |
---|
7 | | - * 2 of the License, or (at your option) any later version. |
---|
8 | 4 | * |
---|
9 | 5 | * Authors: Thomas Graf <tgraf@suug.ch> |
---|
10 | 6 | */ |
---|
.. | .. |
---|
18 | 14 | #include <linux/rtnetlink.h> |
---|
19 | 15 | #include <linux/skbuff.h> |
---|
20 | 16 | #include <linux/idr.h> |
---|
| 17 | +#include <linux/percpu.h> |
---|
21 | 18 | #include <net/netlink.h> |
---|
22 | 19 | #include <net/act_api.h> |
---|
23 | 20 | #include <net/pkt_cls.h> |
---|
.. | .. |
---|
35 | 32 | struct tcf_result res; |
---|
36 | 33 | struct tcf_proto *tp; |
---|
37 | 34 | struct list_head link; |
---|
| 35 | + struct tc_basic_pcnt __percpu *pf; |
---|
38 | 36 | struct rcu_work rwork; |
---|
39 | 37 | }; |
---|
40 | 38 | |
---|
.. | .. |
---|
46 | 44 | struct basic_filter *f; |
---|
47 | 45 | |
---|
48 | 46 | list_for_each_entry_rcu(f, &head->flist, link) { |
---|
| 47 | + __this_cpu_inc(f->pf->rcnt); |
---|
49 | 48 | if (!tcf_em_tree_match(skb, &f->ematches, NULL)) |
---|
50 | 49 | continue; |
---|
| 50 | + __this_cpu_inc(f->pf->rhit); |
---|
51 | 51 | *res = f->res; |
---|
52 | 52 | r = tcf_exts_exec(skb, &f->exts, res); |
---|
53 | 53 | if (r < 0) |
---|
.. | .. |
---|
89 | 89 | tcf_exts_destroy(&f->exts); |
---|
90 | 90 | tcf_em_tree_destroy(&f->ematches); |
---|
91 | 91 | tcf_exts_put_net(&f->exts); |
---|
| 92 | + free_percpu(f->pf); |
---|
92 | 93 | kfree(f); |
---|
93 | 94 | } |
---|
94 | 95 | |
---|
.. | .. |
---|
102 | 103 | rtnl_unlock(); |
---|
103 | 104 | } |
---|
104 | 105 | |
---|
105 | | -static void basic_destroy(struct tcf_proto *tp, struct netlink_ext_ack *extack) |
---|
| 106 | +static void basic_destroy(struct tcf_proto *tp, bool rtnl_held, |
---|
| 107 | + struct netlink_ext_ack *extack) |
---|
106 | 108 | { |
---|
107 | 109 | struct basic_head *head = rtnl_dereference(tp->root); |
---|
108 | 110 | struct basic_filter *f, *n; |
---|
.. | .. |
---|
121 | 123 | } |
---|
122 | 124 | |
---|
123 | 125 | static int basic_delete(struct tcf_proto *tp, void *arg, bool *last, |
---|
124 | | - struct netlink_ext_ack *extack) |
---|
| 126 | + bool rtnl_held, struct netlink_ext_ack *extack) |
---|
125 | 127 | { |
---|
126 | 128 | struct basic_head *head = rtnl_dereference(tp->root); |
---|
127 | 129 | struct basic_filter *f = arg; |
---|
.. | .. |
---|
148 | 150 | { |
---|
149 | 151 | int err; |
---|
150 | 152 | |
---|
151 | | - err = tcf_exts_validate(net, tp, tb, est, &f->exts, ovr, extack); |
---|
| 153 | + err = tcf_exts_validate(net, tp, tb, est, &f->exts, ovr, true, extack); |
---|
152 | 154 | if (err < 0) |
---|
153 | 155 | return err; |
---|
154 | 156 | |
---|
.. | .. |
---|
168 | 170 | static int basic_change(struct net *net, struct sk_buff *in_skb, |
---|
169 | 171 | struct tcf_proto *tp, unsigned long base, u32 handle, |
---|
170 | 172 | struct nlattr **tca, void **arg, bool ovr, |
---|
171 | | - struct netlink_ext_ack *extack) |
---|
| 173 | + bool rtnl_held, struct netlink_ext_ack *extack) |
---|
172 | 174 | { |
---|
173 | 175 | int err; |
---|
174 | 176 | struct basic_head *head = rtnl_dereference(tp->root); |
---|
.. | .. |
---|
179 | 181 | if (tca[TCA_OPTIONS] == NULL) |
---|
180 | 182 | return -EINVAL; |
---|
181 | 183 | |
---|
182 | | - err = nla_parse_nested(tb, TCA_BASIC_MAX, tca[TCA_OPTIONS], |
---|
183 | | - basic_policy, NULL); |
---|
| 184 | + err = nla_parse_nested_deprecated(tb, TCA_BASIC_MAX, tca[TCA_OPTIONS], |
---|
| 185 | + basic_policy, NULL); |
---|
184 | 186 | if (err < 0) |
---|
185 | 187 | return err; |
---|
186 | 188 | |
---|
.. | .. |
---|
193 | 195 | if (!fnew) |
---|
194 | 196 | return -ENOBUFS; |
---|
195 | 197 | |
---|
196 | | - err = tcf_exts_init(&fnew->exts, TCA_BASIC_ACT, TCA_BASIC_POLICE); |
---|
| 198 | + err = tcf_exts_init(&fnew->exts, net, TCA_BASIC_ACT, TCA_BASIC_POLICE); |
---|
197 | 199 | if (err < 0) |
---|
198 | 200 | goto errout; |
---|
199 | 201 | |
---|
.. | .. |
---|
208 | 210 | if (err) |
---|
209 | 211 | goto errout; |
---|
210 | 212 | fnew->handle = handle; |
---|
| 213 | + fnew->pf = alloc_percpu(struct tc_basic_pcnt); |
---|
| 214 | + if (!fnew->pf) { |
---|
| 215 | + err = -ENOMEM; |
---|
| 216 | + goto errout; |
---|
| 217 | + } |
---|
211 | 218 | |
---|
212 | 219 | err = basic_set_parms(net, tp, fnew, base, tb, tca[TCA_RATE], ovr, |
---|
213 | 220 | extack); |
---|
.. | .. |
---|
231 | 238 | |
---|
232 | 239 | return 0; |
---|
233 | 240 | errout: |
---|
| 241 | + free_percpu(fnew->pf); |
---|
234 | 242 | tcf_exts_destroy(&fnew->exts); |
---|
235 | 243 | kfree(fnew); |
---|
236 | 244 | return err; |
---|
237 | 245 | } |
---|
238 | 246 | |
---|
239 | | -static void basic_walk(struct tcf_proto *tp, struct tcf_walker *arg) |
---|
| 247 | +static void basic_walk(struct tcf_proto *tp, struct tcf_walker *arg, |
---|
| 248 | + bool rtnl_held) |
---|
240 | 249 | { |
---|
241 | 250 | struct basic_head *head = rtnl_dereference(tp->root); |
---|
242 | 251 | struct basic_filter *f; |
---|
.. | .. |
---|
268 | 277 | } |
---|
269 | 278 | |
---|
270 | 279 | static int basic_dump(struct net *net, struct tcf_proto *tp, void *fh, |
---|
271 | | - struct sk_buff *skb, struct tcmsg *t) |
---|
| 280 | + struct sk_buff *skb, struct tcmsg *t, bool rtnl_held) |
---|
272 | 281 | { |
---|
| 282 | + struct tc_basic_pcnt gpf = {}; |
---|
273 | 283 | struct basic_filter *f = fh; |
---|
274 | 284 | struct nlattr *nest; |
---|
| 285 | + int cpu; |
---|
275 | 286 | |
---|
276 | 287 | if (f == NULL) |
---|
277 | 288 | return skb->len; |
---|
278 | 289 | |
---|
279 | 290 | t->tcm_handle = f->handle; |
---|
280 | 291 | |
---|
281 | | - nest = nla_nest_start(skb, TCA_OPTIONS); |
---|
| 292 | + nest = nla_nest_start_noflag(skb, TCA_OPTIONS); |
---|
282 | 293 | if (nest == NULL) |
---|
283 | 294 | goto nla_put_failure; |
---|
284 | 295 | |
---|
.. | .. |
---|
286 | 297 | nla_put_u32(skb, TCA_BASIC_CLASSID, f->res.classid)) |
---|
287 | 298 | goto nla_put_failure; |
---|
288 | 299 | |
---|
| 300 | + for_each_possible_cpu(cpu) { |
---|
| 301 | + struct tc_basic_pcnt *pf = per_cpu_ptr(f->pf, cpu); |
---|
| 302 | + |
---|
| 303 | + gpf.rcnt += pf->rcnt; |
---|
| 304 | + gpf.rhit += pf->rhit; |
---|
| 305 | + } |
---|
| 306 | + |
---|
| 307 | + if (nla_put_64bit(skb, TCA_BASIC_PCNT, |
---|
| 308 | + sizeof(struct tc_basic_pcnt), |
---|
| 309 | + &gpf, TCA_BASIC_PAD)) |
---|
| 310 | + goto nla_put_failure; |
---|
| 311 | + |
---|
289 | 312 | if (tcf_exts_dump(skb, &f->exts) < 0 || |
---|
290 | 313 | tcf_em_tree_dump(skb, &f->ematches, TCA_BASIC_EMATCHES) < 0) |
---|
291 | 314 | goto nla_put_failure; |
---|