| .. | .. |
|---|
| 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 | |
|---|
| .. | .. |
|---|
| 226 | 215 | tcf_bind_filter(tp, &f->res, base); |
|---|
| 227 | 216 | } |
|---|
| 228 | 217 | |
|---|
| 229 | | -#ifdef CONFIG_NET_CLS_IND |
|---|
| 230 | 218 | if (tb[TCA_FW_INDEV]) { |
|---|
| 231 | 219 | int ret; |
|---|
| 232 | 220 | ret = tcf_change_indev(net, tb[TCA_FW_INDEV], extack); |
|---|
| .. | .. |
|---|
| 234 | 222 | return ret; |
|---|
| 235 | 223 | f->ifindex = ret; |
|---|
| 236 | 224 | } |
|---|
| 237 | | -#endif /* CONFIG_NET_CLS_IND */ |
|---|
| 238 | 225 | |
|---|
| 239 | 226 | err = -EINVAL; |
|---|
| 240 | 227 | if (tb[TCA_FW_MASK]) { |
|---|
| .. | .. |
|---|
| 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 | |
|---|
| .. | .. |
|---|
| 278 | 267 | |
|---|
| 279 | 268 | fnew->id = f->id; |
|---|
| 280 | 269 | fnew->res = f->res; |
|---|
| 281 | | -#ifdef CONFIG_NET_CLS_IND |
|---|
| 282 | 270 | fnew->ifindex = f->ifindex; |
|---|
| 283 | | -#endif /* CONFIG_NET_CLS_IND */ |
|---|
| 284 | 271 | fnew->tp = f->tp; |
|---|
| 285 | 272 | |
|---|
| 286 | | - err = tcf_exts_init(&fnew->exts, TCA_FW_ACT, TCA_FW_POLICE); |
|---|
| 273 | + err = tcf_exts_init(&fnew->exts, net, TCA_FW_ACT, |
|---|
| 274 | + TCA_FW_POLICE); |
|---|
| 287 | 275 | if (err < 0) { |
|---|
| 288 | 276 | kfree(fnew); |
|---|
| 289 | 277 | return err; |
|---|
| .. | .. |
|---|
| 332 | 320 | if (f == NULL) |
|---|
| 333 | 321 | return -ENOBUFS; |
|---|
| 334 | 322 | |
|---|
| 335 | | - err = tcf_exts_init(&f->exts, TCA_FW_ACT, TCA_FW_POLICE); |
|---|
| 323 | + err = tcf_exts_init(&f->exts, net, TCA_FW_ACT, TCA_FW_POLICE); |
|---|
| 336 | 324 | if (err < 0) |
|---|
| 337 | 325 | goto errout; |
|---|
| 338 | 326 | f->id = handle; |
|---|
| .. | .. |
|---|
| 354 | 342 | return err; |
|---|
| 355 | 343 | } |
|---|
| 356 | 344 | |
|---|
| 357 | | -static void fw_walk(struct tcf_proto *tp, struct tcf_walker *arg) |
|---|
| 345 | +static void fw_walk(struct tcf_proto *tp, struct tcf_walker *arg, |
|---|
| 346 | + bool rtnl_held) |
|---|
| 358 | 347 | { |
|---|
| 359 | 348 | struct fw_head *head = rtnl_dereference(tp->root); |
|---|
| 360 | 349 | int h; |
|---|
| .. | .. |
|---|
| 384 | 373 | } |
|---|
| 385 | 374 | |
|---|
| 386 | 375 | static int fw_dump(struct net *net, struct tcf_proto *tp, void *fh, |
|---|
| 387 | | - struct sk_buff *skb, struct tcmsg *t) |
|---|
| 376 | + struct sk_buff *skb, struct tcmsg *t, bool rtnl_held) |
|---|
| 388 | 377 | { |
|---|
| 389 | 378 | struct fw_head *head = rtnl_dereference(tp->root); |
|---|
| 390 | 379 | struct fw_filter *f = fh; |
|---|
| .. | .. |
|---|
| 398 | 387 | if (!f->res.classid && !tcf_exts_has_actions(&f->exts)) |
|---|
| 399 | 388 | return skb->len; |
|---|
| 400 | 389 | |
|---|
| 401 | | - nest = nla_nest_start(skb, TCA_OPTIONS); |
|---|
| 390 | + nest = nla_nest_start_noflag(skb, TCA_OPTIONS); |
|---|
| 402 | 391 | if (nest == NULL) |
|---|
| 403 | 392 | goto nla_put_failure; |
|---|
| 404 | 393 | |
|---|
| 405 | 394 | if (f->res.classid && |
|---|
| 406 | 395 | nla_put_u32(skb, TCA_FW_CLASSID, f->res.classid)) |
|---|
| 407 | 396 | goto nla_put_failure; |
|---|
| 408 | | -#ifdef CONFIG_NET_CLS_IND |
|---|
| 409 | 397 | if (f->ifindex) { |
|---|
| 410 | 398 | struct net_device *dev; |
|---|
| 411 | 399 | dev = __dev_get_by_index(net, f->ifindex); |
|---|
| 412 | 400 | if (dev && nla_put_string(skb, TCA_FW_INDEV, dev->name)) |
|---|
| 413 | 401 | goto nla_put_failure; |
|---|
| 414 | 402 | } |
|---|
| 415 | | -#endif /* CONFIG_NET_CLS_IND */ |
|---|
| 416 | 403 | if (head->mask != 0xFFFFFFFF && |
|---|
| 417 | 404 | nla_put_u32(skb, TCA_FW_MASK, head->mask)) |
|---|
| 418 | 405 | goto nla_put_failure; |
|---|