hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/net/sched/cls_fw.c
....@@ -1,10 +1,6 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * net/sched/cls_fw.c Classifier mapping ipchains' fwmark to traffic class.
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.
84 *
95 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
106 *
....@@ -12,10 +8,6 @@
128 * Karlis Peisenieks <karlis@mt.lv> : 990415 : fw_walk off by one
139 * Karlis Peisenieks <karlis@mt.lv> : 990415 : fw_delete killed all the filter (and kernel).
1410 * Alex <alex@pilotsoft.com> : 2004xxyy: Added Action extension
15
- *
16
- * JHS: We should remove the CONFIG_NET_CLS_IND from here
17
- * eventually when the meta match extension is made available
18
- *
1911 */
2012
2113 #include <linux/module.h>
....@@ -42,9 +34,7 @@
4234 struct fw_filter __rcu *next;
4335 u32 id;
4436 struct tcf_result res;
45
-#ifdef CONFIG_NET_CLS_IND
4637 int ifindex;
47
-#endif /* CONFIG_NET_CLS_IND */
4838 struct tcf_exts exts;
4939 struct tcf_proto *tp;
5040 struct rcu_work rwork;
....@@ -72,10 +62,8 @@
7262 f = rcu_dereference_bh(f->next)) {
7363 if (f->id == id) {
7464 *res = f->res;
75
-#ifdef CONFIG_NET_CLS_IND
7665 if (!tcf_match_indev(skb, f->ifindex))
7766 continue;
78
-#endif /* CONFIG_NET_CLS_IND */
7967 r = tcf_exts_exec(skb, &f->exts, res);
8068 if (r < 0)
8169 continue;
....@@ -139,7 +127,8 @@
139127 rtnl_unlock();
140128 }
141129
142
-static void fw_destroy(struct tcf_proto *tp, struct netlink_ext_ack *extack)
130
+static void fw_destroy(struct tcf_proto *tp, bool rtnl_held,
131
+ struct netlink_ext_ack *extack)
143132 {
144133 struct fw_head *head = rtnl_dereference(tp->root);
145134 struct fw_filter *f;
....@@ -163,7 +152,7 @@
163152 }
164153
165154 static int fw_delete(struct tcf_proto *tp, void *arg, bool *last,
166
- struct netlink_ext_ack *extack)
155
+ bool rtnl_held, struct netlink_ext_ack *extack)
167156 {
168157 struct fw_head *head = rtnl_dereference(tp->root);
169158 struct fw_filter *f = arg;
....@@ -217,16 +206,10 @@
217206 int err;
218207
219208 err = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &f->exts, ovr,
220
- extack);
209
+ true, extack);
221210 if (err < 0)
222211 return err;
223212
224
- if (tb[TCA_FW_CLASSID]) {
225
- f->res.classid = nla_get_u32(tb[TCA_FW_CLASSID]);
226
- tcf_bind_filter(tp, &f->res, base);
227
- }
228
-
229
-#ifdef CONFIG_NET_CLS_IND
230213 if (tb[TCA_FW_INDEV]) {
231214 int ret;
232215 ret = tcf_change_indev(net, tb[TCA_FW_INDEV], extack);
....@@ -234,7 +217,6 @@
234217 return ret;
235218 f->ifindex = ret;
236219 }
237
-#endif /* CONFIG_NET_CLS_IND */
238220
239221 err = -EINVAL;
240222 if (tb[TCA_FW_MASK]) {
....@@ -244,13 +226,19 @@
244226 } else if (head->mask != 0xFFFFFFFF)
245227 return err;
246228
229
+ if (tb[TCA_FW_CLASSID]) {
230
+ f->res.classid = nla_get_u32(tb[TCA_FW_CLASSID]);
231
+ tcf_bind_filter(tp, &f->res, base);
232
+ }
233
+
247234 return 0;
248235 }
249236
250237 static int fw_change(struct net *net, struct sk_buff *in_skb,
251238 struct tcf_proto *tp, unsigned long base,
252239 u32 handle, struct nlattr **tca, void **arg,
253
- bool ovr, struct netlink_ext_ack *extack)
240
+ bool ovr, bool rtnl_held,
241
+ struct netlink_ext_ack *extack)
254242 {
255243 struct fw_head *head = rtnl_dereference(tp->root);
256244 struct fw_filter *f = *arg;
....@@ -261,7 +249,8 @@
261249 if (!opt)
262250 return handle ? -EINVAL : 0; /* Succeed if it is old method. */
263251
264
- err = nla_parse_nested(tb, TCA_FW_MAX, opt, fw_policy, NULL);
252
+ err = nla_parse_nested_deprecated(tb, TCA_FW_MAX, opt, fw_policy,
253
+ NULL);
265254 if (err < 0)
266255 return err;
267256
....@@ -277,13 +266,11 @@
277266 return -ENOBUFS;
278267
279268 fnew->id = f->id;
280
- fnew->res = f->res;
281
-#ifdef CONFIG_NET_CLS_IND
282269 fnew->ifindex = f->ifindex;
283
-#endif /* CONFIG_NET_CLS_IND */
284270 fnew->tp = f->tp;
285271
286
- err = tcf_exts_init(&fnew->exts, TCA_FW_ACT, TCA_FW_POLICE);
272
+ err = tcf_exts_init(&fnew->exts, net, TCA_FW_ACT,
273
+ TCA_FW_POLICE);
287274 if (err < 0) {
288275 kfree(fnew);
289276 return err;
....@@ -332,7 +319,7 @@
332319 if (f == NULL)
333320 return -ENOBUFS;
334321
335
- err = tcf_exts_init(&f->exts, TCA_FW_ACT, TCA_FW_POLICE);
322
+ err = tcf_exts_init(&f->exts, net, TCA_FW_ACT, TCA_FW_POLICE);
336323 if (err < 0)
337324 goto errout;
338325 f->id = handle;
....@@ -354,7 +341,8 @@
354341 return err;
355342 }
356343
357
-static void fw_walk(struct tcf_proto *tp, struct tcf_walker *arg)
344
+static void fw_walk(struct tcf_proto *tp, struct tcf_walker *arg,
345
+ bool rtnl_held)
358346 {
359347 struct fw_head *head = rtnl_dereference(tp->root);
360348 int h;
....@@ -384,7 +372,7 @@
384372 }
385373
386374 static int fw_dump(struct net *net, struct tcf_proto *tp, void *fh,
387
- struct sk_buff *skb, struct tcmsg *t)
375
+ struct sk_buff *skb, struct tcmsg *t, bool rtnl_held)
388376 {
389377 struct fw_head *head = rtnl_dereference(tp->root);
390378 struct fw_filter *f = fh;
....@@ -398,21 +386,19 @@
398386 if (!f->res.classid && !tcf_exts_has_actions(&f->exts))
399387 return skb->len;
400388
401
- nest = nla_nest_start(skb, TCA_OPTIONS);
389
+ nest = nla_nest_start_noflag(skb, TCA_OPTIONS);
402390 if (nest == NULL)
403391 goto nla_put_failure;
404392
405393 if (f->res.classid &&
406394 nla_put_u32(skb, TCA_FW_CLASSID, f->res.classid))
407395 goto nla_put_failure;
408
-#ifdef CONFIG_NET_CLS_IND
409396 if (f->ifindex) {
410397 struct net_device *dev;
411398 dev = __dev_get_by_index(net, f->ifindex);
412399 if (dev && nla_put_string(skb, TCA_FW_INDEV, dev->name))
413400 goto nla_put_failure;
414401 }
415
-#endif /* CONFIG_NET_CLS_IND */
416402 if (head->mask != 0xFFFFFFFF &&
417403 nla_put_u32(skb, TCA_FW_MASK, head->mask))
418404 goto nla_put_failure;