hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/net/sched/act_skbedit.c
....@@ -1,17 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (c) 2008, Intel Corporation.
3
- *
4
- * This program is free software; you can redistribute it and/or modify it
5
- * under the terms and conditions of the GNU General Public License,
6
- * version 2, as published by the Free Software Foundation.
7
- *
8
- * This program is distributed in the hope it will be useful, but WITHOUT
9
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11
- * more details.
12
- *
13
- * You should have received a copy of the GNU General Public License along with
14
- * this program; if not, see <http://www.gnu.org/licenses/>.
154 *
165 * Author: Alexander Duyck <alexander.h.duyck@intel.com>
176 */
....@@ -26,6 +15,7 @@
2615 #include <net/ip.h>
2716 #include <net/ipv6.h>
2817 #include <net/dsfield.h>
18
+#include <net/pkt_cls.h>
2919
3020 #include <linux/tc_act/tc_skbedit.h>
3121 #include <net/tc_act/tc_skbedit.h>
....@@ -83,6 +73,17 @@
8373 return TC_ACT_SHOT;
8474 }
8575
76
+static void tcf_skbedit_stats_update(struct tc_action *a, u64 bytes,
77
+ u64 packets, u64 drops,
78
+ u64 lastuse, bool hw)
79
+{
80
+ struct tcf_skbedit *d = to_skbedit(a);
81
+ struct tcf_t *tm = &d->tcf_tm;
82
+
83
+ tcf_action_update_stats(a, bytes, packets, drops, hw);
84
+ tm->lastuse = max_t(u64, tm->lastuse, lastuse);
85
+}
86
+
8687 static const struct nla_policy skbedit_policy[TCA_SKBEDIT_MAX + 1] = {
8788 [TCA_SKBEDIT_PARMS] = { .len = sizeof(struct tc_skbedit) },
8889 [TCA_SKBEDIT_PRIORITY] = { .len = sizeof(u32) },
....@@ -96,11 +97,13 @@
9697 static int tcf_skbedit_init(struct net *net, struct nlattr *nla,
9798 struct nlattr *est, struct tc_action **a,
9899 int ovr, int bind, bool rtnl_held,
100
+ struct tcf_proto *tp, u32 act_flags,
99101 struct netlink_ext_ack *extack)
100102 {
101103 struct tc_action_net *tn = net_generic(net, skbedit_net_id);
102
- struct tcf_skbedit_params *params_old, *params_new;
104
+ struct tcf_skbedit_params *params_new;
103105 struct nlattr *tb[TCA_SKBEDIT_MAX + 1];
106
+ struct tcf_chain *goto_ch = NULL;
104107 struct tc_skbedit *parm;
105108 struct tcf_skbedit *d;
106109 u32 flags = 0, *priority = NULL, *mark = NULL, *mask = NULL;
....@@ -112,7 +115,8 @@
112115 if (nla == NULL)
113116 return -EINVAL;
114117
115
- err = nla_parse_nested(tb, TCA_SKBEDIT_MAX, nla, skbedit_policy, NULL);
118
+ err = nla_parse_nested_deprecated(tb, TCA_SKBEDIT_MAX, nla,
119
+ skbedit_policy, NULL);
116120 if (err < 0)
117121 return err;
118122
....@@ -172,7 +176,7 @@
172176
173177 if (!exists) {
174178 ret = tcf_idr_create(tn, index, est, a,
175
- &act_skbedit_ops, bind, true);
179
+ &act_skbedit_ops, bind, true, act_flags);
176180 if (ret) {
177181 tcf_idr_cleanup(tn, index);
178182 return ret;
....@@ -187,13 +191,14 @@
187191 return -EEXIST;
188192 }
189193 }
190
-
191
- ASSERT_RTNL();
194
+ err = tcf_action_check_ctrlact(parm->action, tp, &goto_ch, extack);
195
+ if (err < 0)
196
+ goto release_idr;
192197
193198 params_new = kzalloc(sizeof(*params_new), GFP_KERNEL);
194199 if (unlikely(!params_new)) {
195
- tcf_idr_release(*a, bind);
196
- return -ENOMEM;
200
+ err = -ENOMEM;
201
+ goto put_chain;
197202 }
198203
199204 params_new->flags = flags;
....@@ -210,15 +215,23 @@
210215 if (flags & SKBEDIT_F_MASK)
211216 params_new->mask = *mask;
212217
213
- d->tcf_action = parm->action;
214
- params_old = rtnl_dereference(d->params);
215
- rcu_assign_pointer(d->params, params_new);
216
- if (params_old)
217
- kfree_rcu(params_old, rcu);
218
+ spin_lock_bh(&d->tcf_lock);
219
+ goto_ch = tcf_action_set_ctrlact(*a, parm->action, goto_ch);
220
+ params_new = rcu_replace_pointer(d->params, params_new,
221
+ lockdep_is_held(&d->tcf_lock));
222
+ spin_unlock_bh(&d->tcf_lock);
223
+ if (params_new)
224
+ kfree_rcu(params_new, rcu);
225
+ if (goto_ch)
226
+ tcf_chain_put_by_act(goto_ch);
218227
219
- if (ret == ACT_P_CREATED)
220
- tcf_idr_insert(tn, *a);
221228 return ret;
229
+put_chain:
230
+ if (goto_ch)
231
+ tcf_chain_put_by_act(goto_ch);
232
+release_idr:
233
+ tcf_idr_release(*a, bind);
234
+ return err;
222235 }
223236
224237 static int tcf_skbedit_dump(struct sk_buff *skb, struct tc_action *a,
....@@ -231,12 +244,14 @@
231244 .index = d->tcf_index,
232245 .refcnt = refcount_read(&d->tcf_refcnt) - ref,
233246 .bindcnt = atomic_read(&d->tcf_bindcnt) - bind,
234
- .action = d->tcf_action,
235247 };
236248 u64 pure_flags = 0;
237249 struct tcf_t t;
238250
239
- params = rtnl_dereference(d->params);
251
+ spin_lock_bh(&d->tcf_lock);
252
+ params = rcu_dereference_protected(d->params,
253
+ lockdep_is_held(&d->tcf_lock));
254
+ opt.action = d->tcf_action;
240255
241256 if (nla_put(skb, TCA_SKBEDIT_PARMS, sizeof(opt), &opt))
242257 goto nla_put_failure;
....@@ -264,9 +279,12 @@
264279 tcf_tm_dump(&t, &d->tcf_tm);
265280 if (nla_put_64bit(skb, TCA_SKBEDIT_TM, sizeof(t), &t, TCA_SKBEDIT_PAD))
266281 goto nla_put_failure;
282
+ spin_unlock_bh(&d->tcf_lock);
283
+
267284 return skb->len;
268285
269286 nla_put_failure:
287
+ spin_unlock_bh(&d->tcf_lock);
270288 nlmsg_trim(skb, b);
271289 return -1;
272290 }
....@@ -291,23 +309,35 @@
291309 return tcf_generic_walker(tn, skb, cb, type, ops, extack);
292310 }
293311
294
-static int tcf_skbedit_search(struct net *net, struct tc_action **a, u32 index,
295
- struct netlink_ext_ack *extack)
312
+static int tcf_skbedit_search(struct net *net, struct tc_action **a, u32 index)
296313 {
297314 struct tc_action_net *tn = net_generic(net, skbedit_net_id);
298315
299316 return tcf_idr_search(tn, a, index);
300317 }
301318
319
+static size_t tcf_skbedit_get_fill_size(const struct tc_action *act)
320
+{
321
+ return nla_total_size(sizeof(struct tc_skbedit))
322
+ + nla_total_size(sizeof(u32)) /* TCA_SKBEDIT_PRIORITY */
323
+ + nla_total_size(sizeof(u16)) /* TCA_SKBEDIT_QUEUE_MAPPING */
324
+ + nla_total_size(sizeof(u32)) /* TCA_SKBEDIT_MARK */
325
+ + nla_total_size(sizeof(u16)) /* TCA_SKBEDIT_PTYPE */
326
+ + nla_total_size(sizeof(u32)) /* TCA_SKBEDIT_MASK */
327
+ + nla_total_size_64bit(sizeof(u64)); /* TCA_SKBEDIT_FLAGS */
328
+}
329
+
302330 static struct tc_action_ops act_skbedit_ops = {
303331 .kind = "skbedit",
304
- .type = TCA_ACT_SKBEDIT,
332
+ .id = TCA_ID_SKBEDIT,
305333 .owner = THIS_MODULE,
306334 .act = tcf_skbedit_act,
335
+ .stats_update = tcf_skbedit_stats_update,
307336 .dump = tcf_skbedit_dump,
308337 .init = tcf_skbedit_init,
309338 .cleanup = tcf_skbedit_cleanup,
310339 .walk = tcf_skbedit_walker,
340
+ .get_fill_size = tcf_skbedit_get_fill_size,
311341 .lookup = tcf_skbedit_search,
312342 .size = sizeof(struct tcf_skbedit),
313343 };