.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * 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. |
---|
8 | 4 | * |
---|
9 | 5 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> |
---|
10 | 6 | * |
---|
.. | .. |
---|
12 | 8 | * Karlis Peisenieks <karlis@mt.lv> : 990415 : fw_walk off by one |
---|
13 | 9 | * Karlis Peisenieks <karlis@mt.lv> : 990415 : fw_delete killed all the filter (and kernel). |
---|
14 | 10 | * 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 | | - * |
---|
19 | 11 | */ |
---|
20 | 12 | |
---|
21 | 13 | #include <linux/module.h> |
---|
.. | .. |
---|
42 | 34 | struct fw_filter __rcu *next; |
---|
43 | 35 | u32 id; |
---|
44 | 36 | struct tcf_result res; |
---|
45 | | -#ifdef CONFIG_NET_CLS_IND |
---|
46 | 37 | int ifindex; |
---|
47 | | -#endif /* CONFIG_NET_CLS_IND */ |
---|
48 | 38 | struct tcf_exts exts; |
---|
49 | 39 | struct tcf_proto *tp; |
---|
50 | 40 | struct rcu_work rwork; |
---|
.. | .. |
---|
72 | 62 | f = rcu_dereference_bh(f->next)) { |
---|
73 | 63 | if (f->id == id) { |
---|
74 | 64 | *res = f->res; |
---|
75 | | -#ifdef CONFIG_NET_CLS_IND |
---|
76 | 65 | if (!tcf_match_indev(skb, f->ifindex)) |
---|
77 | 66 | continue; |
---|
78 | | -#endif /* CONFIG_NET_CLS_IND */ |
---|
79 | 67 | r = tcf_exts_exec(skb, &f->exts, res); |
---|
80 | 68 | if (r < 0) |
---|
81 | 69 | continue; |
---|
.. | .. |
---|
139 | 127 | rtnl_unlock(); |
---|
140 | 128 | } |
---|
141 | 129 | |
---|
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) |
---|
143 | 132 | { |
---|
144 | 133 | struct fw_head *head = rtnl_dereference(tp->root); |
---|
145 | 134 | struct fw_filter *f; |
---|
.. | .. |
---|
163 | 152 | } |
---|
164 | 153 | |
---|
165 | 154 | 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) |
---|
167 | 156 | { |
---|
168 | 157 | struct fw_head *head = rtnl_dereference(tp->root); |
---|
169 | 158 | struct fw_filter *f = arg; |
---|
.. | .. |
---|
217 | 206 | int err; |
---|
218 | 207 | |
---|
219 | 208 | err = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &f->exts, ovr, |
---|
220 | | - extack); |
---|
| 209 | + true, extack); |
---|
221 | 210 | if (err < 0) |
---|
222 | 211 | return err; |
---|
223 | 212 | |
---|
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 |
---|
230 | 213 | if (tb[TCA_FW_INDEV]) { |
---|
231 | 214 | int ret; |
---|
232 | 215 | ret = tcf_change_indev(net, tb[TCA_FW_INDEV], extack); |
---|
.. | .. |
---|
234 | 217 | return ret; |
---|
235 | 218 | f->ifindex = ret; |
---|
236 | 219 | } |
---|
237 | | -#endif /* CONFIG_NET_CLS_IND */ |
---|
238 | 220 | |
---|
239 | 221 | err = -EINVAL; |
---|
240 | 222 | if (tb[TCA_FW_MASK]) { |
---|
.. | .. |
---|
244 | 226 | } else if (head->mask != 0xFFFFFFFF) |
---|
245 | 227 | return err; |
---|
246 | 228 | |
---|
| 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 | + |
---|
247 | 234 | return 0; |
---|
248 | 235 | } |
---|
249 | 236 | |
---|
250 | 237 | static int fw_change(struct net *net, struct sk_buff *in_skb, |
---|
251 | 238 | struct tcf_proto *tp, unsigned long base, |
---|
252 | 239 | 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) |
---|
254 | 242 | { |
---|
255 | 243 | struct fw_head *head = rtnl_dereference(tp->root); |
---|
256 | 244 | struct fw_filter *f = *arg; |
---|
.. | .. |
---|
261 | 249 | if (!opt) |
---|
262 | 250 | return handle ? -EINVAL : 0; /* Succeed if it is old method. */ |
---|
263 | 251 | |
---|
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); |
---|
265 | 254 | if (err < 0) |
---|
266 | 255 | return err; |
---|
267 | 256 | |
---|
.. | .. |
---|
277 | 266 | return -ENOBUFS; |
---|
278 | 267 | |
---|
279 | 268 | fnew->id = f->id; |
---|
280 | | - fnew->res = f->res; |
---|
281 | | -#ifdef CONFIG_NET_CLS_IND |
---|
282 | 269 | fnew->ifindex = f->ifindex; |
---|
283 | | -#endif /* CONFIG_NET_CLS_IND */ |
---|
284 | 270 | fnew->tp = f->tp; |
---|
285 | 271 | |
---|
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); |
---|
287 | 274 | if (err < 0) { |
---|
288 | 275 | kfree(fnew); |
---|
289 | 276 | return err; |
---|
.. | .. |
---|
332 | 319 | if (f == NULL) |
---|
333 | 320 | return -ENOBUFS; |
---|
334 | 321 | |
---|
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); |
---|
336 | 323 | if (err < 0) |
---|
337 | 324 | goto errout; |
---|
338 | 325 | f->id = handle; |
---|
.. | .. |
---|
354 | 341 | return err; |
---|
355 | 342 | } |
---|
356 | 343 | |
---|
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) |
---|
358 | 346 | { |
---|
359 | 347 | struct fw_head *head = rtnl_dereference(tp->root); |
---|
360 | 348 | int h; |
---|
.. | .. |
---|
384 | 372 | } |
---|
385 | 373 | |
---|
386 | 374 | 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) |
---|
388 | 376 | { |
---|
389 | 377 | struct fw_head *head = rtnl_dereference(tp->root); |
---|
390 | 378 | struct fw_filter *f = fh; |
---|
.. | .. |
---|
398 | 386 | if (!f->res.classid && !tcf_exts_has_actions(&f->exts)) |
---|
399 | 387 | return skb->len; |
---|
400 | 388 | |
---|
401 | | - nest = nla_nest_start(skb, TCA_OPTIONS); |
---|
| 389 | + nest = nla_nest_start_noflag(skb, TCA_OPTIONS); |
---|
402 | 390 | if (nest == NULL) |
---|
403 | 391 | goto nla_put_failure; |
---|
404 | 392 | |
---|
405 | 393 | if (f->res.classid && |
---|
406 | 394 | nla_put_u32(skb, TCA_FW_CLASSID, f->res.classid)) |
---|
407 | 395 | goto nla_put_failure; |
---|
408 | | -#ifdef CONFIG_NET_CLS_IND |
---|
409 | 396 | if (f->ifindex) { |
---|
410 | 397 | struct net_device *dev; |
---|
411 | 398 | dev = __dev_get_by_index(net, f->ifindex); |
---|
412 | 399 | if (dev && nla_put_string(skb, TCA_FW_INDEV, dev->name)) |
---|
413 | 400 | goto nla_put_failure; |
---|
414 | 401 | } |
---|
415 | | -#endif /* CONFIG_NET_CLS_IND */ |
---|
416 | 402 | if (head->mask != 0xFFFFFFFF && |
---|
417 | 403 | nla_put_u32(skb, TCA_FW_MASK, head->mask)) |
---|
418 | 404 | goto nla_put_failure; |
---|