Commit 7677fd01 authored by David S. Miller's avatar David S. Miller

Merge branch 'net-sched-cls-add-extack-support'

Alexander Aring says:

====================
net: sched: cls: add extack support

this patch adds extack support for TC classifier subsystem. The first
patch fixes some code style issues for this patch series pointed out
by checkpatch. The other patches until the last one prepares extack
handling for the TC classifier subsystem and handle generic extack
errors.

The last patch is an example for u32 classifier to add extack support
inside the callbacks delete and change. There exists a init callback as
well, but most classifier implementation run a kalloc() once to allocate
something. Not necessary _yet_ to add extack support now.

- Alex

Cc: David Ahern <dsahern@gmail.com>

changes since v3:
 - fix accidentally move of config option mismatch message in PATCH 2/8
   correct one is 4/8, detected by kbuildbot (Thank you)
 - Removed patch "net: sched: cls: add extack support for tc_setup_cb_call"
   PATCH 7/8 in version v2 as suggested by Jakub Kicinski (Thank you)
 - changed NL_SET_ERR_MSG to NL_SET_ERR_MSG_MOD as suggested by Jakub Kicinski
   in u32 cls (Thank You)
 - Removed text from cover letter that I was waiting for Jiri's Patches as
   detected by Jamal Hadi Salim (Thank you).

changes since v2:
 - rebased on Jiri's patches (Thank you)
 - several spelling fixes pointed out by Cong Wang (Thank you)
 - several spelling fixes pointed out by David Ahern (Thank you)
 - use David Ahern recommendation if config option is mismatch, but
   combine it with Cong Wang recommendation to put config name into it
   (Thank you)
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents fd5204cd 4b981dbc
...@@ -376,7 +376,8 @@ tcf_exts_exec(struct sk_buff *skb, struct tcf_exts *exts, ...@@ -376,7 +376,8 @@ tcf_exts_exec(struct sk_buff *skb, struct tcf_exts *exts,
int tcf_exts_validate(struct net *net, struct tcf_proto *tp, int tcf_exts_validate(struct net *net, struct tcf_proto *tp,
struct nlattr **tb, struct nlattr *rate_tlv, struct nlattr **tb, struct nlattr *rate_tlv,
struct tcf_exts *exts, bool ovr); struct tcf_exts *exts, bool ovr,
struct netlink_ext_ack *extack);
void tcf_exts_destroy(struct tcf_exts *exts); void tcf_exts_destroy(struct tcf_exts *exts);
void tcf_exts_change(struct tcf_exts *dst, struct tcf_exts *src); void tcf_exts_change(struct tcf_exts *dst, struct tcf_exts *src);
int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts); int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts);
...@@ -556,13 +557,16 @@ static inline int tcf_valid_offset(const struct sk_buff *skb, ...@@ -556,13 +557,16 @@ static inline int tcf_valid_offset(const struct sk_buff *skb,
#include <net/net_namespace.h> #include <net/net_namespace.h>
static inline int static inline int
tcf_change_indev(struct net *net, struct nlattr *indev_tlv) tcf_change_indev(struct net *net, struct nlattr *indev_tlv,
struct netlink_ext_ack *extack)
{ {
char indev[IFNAMSIZ]; char indev[IFNAMSIZ];
struct net_device *dev; struct net_device *dev;
if (nla_strlcpy(indev, indev_tlv, IFNAMSIZ) >= IFNAMSIZ) if (nla_strlcpy(indev, indev_tlv, IFNAMSIZ) >= IFNAMSIZ) {
NL_SET_ERR_MSG(extack, "Interface name too long");
return -EINVAL; return -EINVAL;
}
dev = __dev_get_by_name(net, indev); dev = __dev_get_by_name(net, indev);
if (!dev) if (!dev)
return -ENODEV; return -ENODEV;
......
...@@ -239,8 +239,11 @@ struct tcf_proto_ops { ...@@ -239,8 +239,11 @@ struct tcf_proto_ops {
int (*change)(struct net *net, struct sk_buff *, int (*change)(struct net *net, struct sk_buff *,
struct tcf_proto*, unsigned long, struct tcf_proto*, unsigned long,
u32 handle, struct nlattr **, u32 handle, struct nlattr **,
void **, bool); void **, bool,
int (*delete)(struct tcf_proto*, void *, bool*); struct netlink_ext_ack *);
int (*delete)(struct tcf_proto *tp, void *arg,
bool *last,
struct netlink_ext_ack *);
void (*walk)(struct tcf_proto*, struct tcf_walker *arg); void (*walk)(struct tcf_proto*, struct tcf_walker *arg);
void (*bind_class)(void *, u32, unsigned long); void (*bind_class)(void *, u32, unsigned long);
......
...@@ -122,7 +122,8 @@ static inline u32 tcf_auto_prio(struct tcf_proto *tp) ...@@ -122,7 +122,8 @@ static inline u32 tcf_auto_prio(struct tcf_proto *tp)
} }
static struct tcf_proto *tcf_proto_create(const char *kind, u32 protocol, static struct tcf_proto *tcf_proto_create(const char *kind, u32 protocol,
u32 prio, struct tcf_chain *chain) u32 prio, struct tcf_chain *chain,
struct netlink_ext_ack *extack)
{ {
struct tcf_proto *tp; struct tcf_proto *tp;
int err; int err;
...@@ -148,6 +149,7 @@ static struct tcf_proto *tcf_proto_create(const char *kind, u32 protocol, ...@@ -148,6 +149,7 @@ static struct tcf_proto *tcf_proto_create(const char *kind, u32 protocol,
module_put(tp->ops->owner); module_put(tp->ops->owner);
err = -EAGAIN; err = -EAGAIN;
} else { } else {
NL_SET_ERR_MSG(extack, "TC classifier not found");
err = -ENOENT; err = -ENOENT;
} }
goto errout; goto errout;
...@@ -935,7 +937,8 @@ static int tfilter_notify(struct net *net, struct sk_buff *oskb, ...@@ -935,7 +937,8 @@ static int tfilter_notify(struct net *net, struct sk_buff *oskb,
static int tfilter_del_notify(struct net *net, struct sk_buff *oskb, static int tfilter_del_notify(struct net *net, struct sk_buff *oskb,
struct nlmsghdr *n, struct tcf_proto *tp, struct nlmsghdr *n, struct tcf_proto *tp,
struct tcf_block *block, struct Qdisc *q, struct tcf_block *block, struct Qdisc *q,
u32 parent, void *fh, bool unicast, bool *last) u32 parent, void *fh, bool unicast, bool *last,
struct netlink_ext_ack *extack)
{ {
struct sk_buff *skb; struct sk_buff *skb;
u32 portid = oskb ? NETLINK_CB(oskb).portid : 0; u32 portid = oskb ? NETLINK_CB(oskb).portid : 0;
...@@ -947,11 +950,12 @@ static int tfilter_del_notify(struct net *net, struct sk_buff *oskb, ...@@ -947,11 +950,12 @@ static int tfilter_del_notify(struct net *net, struct sk_buff *oskb,
if (tcf_fill_node(net, skb, tp, block, q, parent, fh, portid, if (tcf_fill_node(net, skb, tp, block, q, parent, fh, portid,
n->nlmsg_seq, n->nlmsg_flags, RTM_DELTFILTER) <= 0) { n->nlmsg_seq, n->nlmsg_flags, RTM_DELTFILTER) <= 0) {
NL_SET_ERR_MSG(extack, "Failed to build del event notification");
kfree_skb(skb); kfree_skb(skb);
return -EINVAL; return -EINVAL;
} }
err = tp->ops->delete(tp, fh, last); err = tp->ops->delete(tp, fh, last, extack);
if (err) { if (err) {
kfree_skb(skb); kfree_skb(skb);
return err; return err;
...@@ -960,8 +964,11 @@ static int tfilter_del_notify(struct net *net, struct sk_buff *oskb, ...@@ -960,8 +964,11 @@ static int tfilter_del_notify(struct net *net, struct sk_buff *oskb,
if (unicast) if (unicast)
return netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT); return netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT);
return rtnetlink_send(skb, net, portid, RTNLGRP_TC, err = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
n->nlmsg_flags & NLM_F_ECHO); n->nlmsg_flags & NLM_F_ECHO);
if (err < 0)
NL_SET_ERR_MSG(extack, "Failed to send filter delete notification");
return err;
} }
static void tfilter_notify_chain(struct net *net, struct sk_buff *oskb, static void tfilter_notify_chain(struct net *net, struct sk_buff *oskb,
...@@ -1021,8 +1028,10 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, ...@@ -1021,8 +1028,10 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
if (prio == 0) { if (prio == 0) {
switch (n->nlmsg_type) { switch (n->nlmsg_type) {
case RTM_DELTFILTER: case RTM_DELTFILTER:
if (protocol || t->tcm_handle || tca[TCA_KIND]) if (protocol || t->tcm_handle || tca[TCA_KIND]) {
NL_SET_ERR_MSG(extack, "Cannot flush filters with protocol, handle or kind set");
return -ENOENT; return -ENOENT;
}
break; break;
case RTM_NEWTFILTER: case RTM_NEWTFILTER:
/* If no priority is provided by the user, /* If no priority is provided by the user,
...@@ -1035,6 +1044,7 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, ...@@ -1035,6 +1044,7 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
} }
/* fall-through */ /* fall-through */
default: default:
NL_SET_ERR_MSG(extack, "Invalid filter command with priority of zero");
return -ENOENT; return -ENOENT;
} }
} }
...@@ -1063,23 +1073,31 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, ...@@ -1063,23 +1073,31 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
parent = q->handle; parent = q->handle;
} else { } else {
q = qdisc_lookup(dev, TC_H_MAJ(t->tcm_parent)); q = qdisc_lookup(dev, TC_H_MAJ(t->tcm_parent));
if (!q) if (!q) {
NL_SET_ERR_MSG(extack, "Parent Qdisc doesn't exists");
return -EINVAL; return -EINVAL;
}
} }
/* Is it classful? */ /* Is it classful? */
cops = q->ops->cl_ops; cops = q->ops->cl_ops;
if (!cops) if (!cops) {
NL_SET_ERR_MSG(extack, "Qdisc not classful");
return -EINVAL; return -EINVAL;
}
if (!cops->tcf_block) if (!cops->tcf_block) {
NL_SET_ERR_MSG(extack, "Class doesn't support blocks");
return -EOPNOTSUPP; return -EOPNOTSUPP;
}
/* Do we search for filter, attached to class? */ /* Do we search for filter, attached to class? */
if (TC_H_MIN(parent)) { if (TC_H_MIN(parent)) {
cl = cops->find(q, parent); cl = cops->find(q, parent);
if (cl == 0) if (cl == 0) {
NL_SET_ERR_MSG(extack, "Specified class doesn't exist");
return -ENOENT; return -ENOENT;
}
} }
/* And the last stroke */ /* And the last stroke */
...@@ -1097,12 +1115,14 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, ...@@ -1097,12 +1115,14 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
chain_index = tca[TCA_CHAIN] ? nla_get_u32(tca[TCA_CHAIN]) : 0; chain_index = tca[TCA_CHAIN] ? nla_get_u32(tca[TCA_CHAIN]) : 0;
if (chain_index > TC_ACT_EXT_VAL_MASK) { if (chain_index > TC_ACT_EXT_VAL_MASK) {
NL_SET_ERR_MSG(extack, "Specified chain index exceeds upper limit");
err = -EINVAL; err = -EINVAL;
goto errout; goto errout;
} }
chain = tcf_chain_get(block, chain_index, chain = tcf_chain_get(block, chain_index,
n->nlmsg_type == RTM_NEWTFILTER); n->nlmsg_type == RTM_NEWTFILTER);
if (!chain) { if (!chain) {
NL_SET_ERR_MSG(extack, "Cannot find specified filter chain");
err = n->nlmsg_type == RTM_NEWTFILTER ? -ENOMEM : -EINVAL; err = n->nlmsg_type == RTM_NEWTFILTER ? -ENOMEM : -EINVAL;
goto errout; goto errout;
} }
...@@ -1118,6 +1138,7 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, ...@@ -1118,6 +1138,7 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
tp = tcf_chain_tp_find(chain, &chain_info, protocol, tp = tcf_chain_tp_find(chain, &chain_info, protocol,
prio, prio_allocate); prio, prio_allocate);
if (IS_ERR(tp)) { if (IS_ERR(tp)) {
NL_SET_ERR_MSG(extack, "Filter with specified priority/protocol not found");
err = PTR_ERR(tp); err = PTR_ERR(tp);
goto errout; goto errout;
} }
...@@ -1126,12 +1147,14 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, ...@@ -1126,12 +1147,14 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
/* Proto-tcf does not exist, create new one */ /* Proto-tcf does not exist, create new one */
if (tca[TCA_KIND] == NULL || !protocol) { if (tca[TCA_KIND] == NULL || !protocol) {
NL_SET_ERR_MSG(extack, "Filter kind and protocol must be specified");
err = -EINVAL; err = -EINVAL;
goto errout; goto errout;
} }
if (n->nlmsg_type != RTM_NEWTFILTER || if (n->nlmsg_type != RTM_NEWTFILTER ||
!(n->nlmsg_flags & NLM_F_CREATE)) { !(n->nlmsg_flags & NLM_F_CREATE)) {
NL_SET_ERR_MSG(extack, "Need both RTM_NEWTFILTER and NLM_F_CREATE to create a new filter");
err = -ENOENT; err = -ENOENT;
goto errout; goto errout;
} }
...@@ -1140,13 +1163,14 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, ...@@ -1140,13 +1163,14 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
prio = tcf_auto_prio(tcf_chain_tp_prev(&chain_info)); prio = tcf_auto_prio(tcf_chain_tp_prev(&chain_info));
tp = tcf_proto_create(nla_data(tca[TCA_KIND]), tp = tcf_proto_create(nla_data(tca[TCA_KIND]),
protocol, prio, chain); protocol, prio, chain, extack);
if (IS_ERR(tp)) { if (IS_ERR(tp)) {
err = PTR_ERR(tp); err = PTR_ERR(tp);
goto errout; goto errout;
} }
tp_created = 1; tp_created = 1;
} else if (tca[TCA_KIND] && nla_strcmp(tca[TCA_KIND], tp->ops->kind)) { } else if (tca[TCA_KIND] && nla_strcmp(tca[TCA_KIND], tp->ops->kind)) {
NL_SET_ERR_MSG(extack, "Specified filter kind does not match existing one");
err = -EINVAL; err = -EINVAL;
goto errout; goto errout;
} }
...@@ -1165,6 +1189,7 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, ...@@ -1165,6 +1189,7 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
if (n->nlmsg_type != RTM_NEWTFILTER || if (n->nlmsg_type != RTM_NEWTFILTER ||
!(n->nlmsg_flags & NLM_F_CREATE)) { !(n->nlmsg_flags & NLM_F_CREATE)) {
NL_SET_ERR_MSG(extack, "Need both RTM_NEWTFILTER and NLM_F_CREATE to create a new filter");
err = -ENOENT; err = -ENOENT;
goto errout; goto errout;
} }
...@@ -1176,13 +1201,15 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, ...@@ -1176,13 +1201,15 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
if (n->nlmsg_flags & NLM_F_EXCL) { if (n->nlmsg_flags & NLM_F_EXCL) {
if (tp_created) if (tp_created)
tcf_proto_destroy(tp); tcf_proto_destroy(tp);
NL_SET_ERR_MSG(extack, "Filter already exists");
err = -EEXIST; err = -EEXIST;
goto errout; goto errout;
} }
break; break;
case RTM_DELTFILTER: case RTM_DELTFILTER:
err = tfilter_del_notify(net, skb, n, tp, block, err = tfilter_del_notify(net, skb, n, tp, block,
q, parent, fh, false, &last); q, parent, fh, false, &last,
extack);
if (err) if (err)
goto errout; goto errout;
if (last) { if (last) {
...@@ -1193,15 +1220,19 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n, ...@@ -1193,15 +1220,19 @@ static int tc_ctl_tfilter(struct sk_buff *skb, struct nlmsghdr *n,
case RTM_GETTFILTER: case RTM_GETTFILTER:
err = tfilter_notify(net, skb, n, tp, block, q, parent, err = tfilter_notify(net, skb, n, tp, block, q, parent,
fh, RTM_NEWTFILTER, true); fh, RTM_NEWTFILTER, true);
if (err < 0)
NL_SET_ERR_MSG(extack, "Failed to send filter notify message");
goto errout; goto errout;
default: default:
NL_SET_ERR_MSG(extack, "Invalid netlink message type");
err = -EINVAL; err = -EINVAL;
goto errout; goto errout;
} }
} }
err = tp->ops->change(net, skb, tp, cl, t->tcm_handle, tca, &fh, err = tp->ops->change(net, skb, tp, cl, t->tcm_handle, tca, &fh,
n->nlmsg_flags & NLM_F_CREATE ? TCA_ACT_NOREPLACE : TCA_ACT_REPLACE); n->nlmsg_flags & NLM_F_CREATE ? TCA_ACT_NOREPLACE : TCA_ACT_REPLACE,
extack);
if (err == 0) { if (err == 0) {
if (tp_created) if (tp_created)
tcf_chain_tp_insert(chain, &chain_info, tp); tcf_chain_tp_insert(chain, &chain_info, tp);
...@@ -1392,7 +1423,8 @@ void tcf_exts_destroy(struct tcf_exts *exts) ...@@ -1392,7 +1423,8 @@ void tcf_exts_destroy(struct tcf_exts *exts)
EXPORT_SYMBOL(tcf_exts_destroy); EXPORT_SYMBOL(tcf_exts_destroy);
int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb, int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb,
struct nlattr *rate_tlv, struct tcf_exts *exts, bool ovr) struct nlattr *rate_tlv, struct tcf_exts *exts, bool ovr,
struct netlink_ext_ack *extack)
{ {
#ifdef CONFIG_NET_CLS_ACT #ifdef CONFIG_NET_CLS_ACT
{ {
...@@ -1425,8 +1457,10 @@ int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb, ...@@ -1425,8 +1457,10 @@ int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb,
} }
#else #else
if ((exts->action && tb[exts->action]) || if ((exts->action && tb[exts->action]) ||
(exts->police && tb[exts->police])) (exts->police && tb[exts->police])) {
NL_SET_ERR_MSG(extack, "Classifier actions are not supported per compile options (CONFIG_NET_CLS_ACT)");
return -EOPNOTSUPP; return -EOPNOTSUPP;
}
#endif #endif
return 0; return 0;
......
...@@ -130,7 +130,8 @@ static void basic_destroy(struct tcf_proto *tp) ...@@ -130,7 +130,8 @@ static void basic_destroy(struct tcf_proto *tp)
kfree_rcu(head, rcu); kfree_rcu(head, rcu);
} }
static int basic_delete(struct tcf_proto *tp, void *arg, bool *last) static int basic_delete(struct tcf_proto *tp, void *arg, bool *last,
struct netlink_ext_ack *extack)
{ {
struct basic_head *head = rtnl_dereference(tp->root); struct basic_head *head = rtnl_dereference(tp->root);
struct basic_filter *f = arg; struct basic_filter *f = arg;
...@@ -152,11 +153,12 @@ static const struct nla_policy basic_policy[TCA_BASIC_MAX + 1] = { ...@@ -152,11 +153,12 @@ static const struct nla_policy basic_policy[TCA_BASIC_MAX + 1] = {
static int basic_set_parms(struct net *net, struct tcf_proto *tp, static int basic_set_parms(struct net *net, struct tcf_proto *tp,
struct basic_filter *f, unsigned long base, struct basic_filter *f, unsigned long base,
struct nlattr **tb, struct nlattr **tb,
struct nlattr *est, bool ovr) struct nlattr *est, bool ovr,
struct netlink_ext_ack *extack)
{ {
int err; int err;
err = tcf_exts_validate(net, tp, tb, est, &f->exts, ovr); err = tcf_exts_validate(net, tp, tb, est, &f->exts, ovr, extack);
if (err < 0) if (err < 0)
return err; return err;
...@@ -175,7 +177,8 @@ static int basic_set_parms(struct net *net, struct tcf_proto *tp, ...@@ -175,7 +177,8 @@ static int basic_set_parms(struct net *net, struct tcf_proto *tp,
static int basic_change(struct net *net, struct sk_buff *in_skb, static int basic_change(struct net *net, struct sk_buff *in_skb,
struct tcf_proto *tp, unsigned long base, u32 handle, struct tcf_proto *tp, unsigned long base, u32 handle,
struct nlattr **tca, void **arg, bool ovr) struct nlattr **tca, void **arg, bool ovr,
struct netlink_ext_ack *extack)
{ {
int err; int err;
struct basic_head *head = rtnl_dereference(tp->root); struct basic_head *head = rtnl_dereference(tp->root);
...@@ -221,7 +224,8 @@ static int basic_change(struct net *net, struct sk_buff *in_skb, ...@@ -221,7 +224,8 @@ static int basic_change(struct net *net, struct sk_buff *in_skb,
fnew->handle = idr_index; fnew->handle = idr_index;
} }
err = basic_set_parms(net, tp, fnew, base, tb, tca[TCA_RATE], ovr); err = basic_set_parms(net, tp, fnew, base, tb, tca[TCA_RATE], ovr,
extack);
if (err < 0) { if (err < 0) {
if (!fold) if (!fold)
idr_remove_ext(&head->handle_idr, fnew->handle); idr_remove_ext(&head->handle_idr, fnew->handle);
......
...@@ -295,7 +295,8 @@ static void __cls_bpf_delete(struct tcf_proto *tp, struct cls_bpf_prog *prog) ...@@ -295,7 +295,8 @@ static void __cls_bpf_delete(struct tcf_proto *tp, struct cls_bpf_prog *prog)
__cls_bpf_delete_prog(prog); __cls_bpf_delete_prog(prog);
} }
static int cls_bpf_delete(struct tcf_proto *tp, void *arg, bool *last) static int cls_bpf_delete(struct tcf_proto *tp, void *arg, bool *last,
struct netlink_ext_ack *extack)
{ {
struct cls_bpf_head *head = rtnl_dereference(tp->root); struct cls_bpf_head *head = rtnl_dereference(tp->root);
...@@ -403,7 +404,8 @@ static int cls_bpf_prog_from_efd(struct nlattr **tb, struct cls_bpf_prog *prog, ...@@ -403,7 +404,8 @@ static int cls_bpf_prog_from_efd(struct nlattr **tb, struct cls_bpf_prog *prog,
static int cls_bpf_set_parms(struct net *net, struct tcf_proto *tp, static int cls_bpf_set_parms(struct net *net, struct tcf_proto *tp,
struct cls_bpf_prog *prog, unsigned long base, struct cls_bpf_prog *prog, unsigned long base,
struct nlattr **tb, struct nlattr *est, bool ovr) struct nlattr **tb, struct nlattr *est, bool ovr,
struct netlink_ext_ack *extack)
{ {
bool is_bpf, is_ebpf, have_exts = false; bool is_bpf, is_ebpf, have_exts = false;
u32 gen_flags = 0; u32 gen_flags = 0;
...@@ -414,7 +416,7 @@ static int cls_bpf_set_parms(struct net *net, struct tcf_proto *tp, ...@@ -414,7 +416,7 @@ static int cls_bpf_set_parms(struct net *net, struct tcf_proto *tp,
if ((!is_bpf && !is_ebpf) || (is_bpf && is_ebpf)) if ((!is_bpf && !is_ebpf) || (is_bpf && is_ebpf))
return -EINVAL; return -EINVAL;
ret = tcf_exts_validate(net, tp, tb, est, &prog->exts, ovr); ret = tcf_exts_validate(net, tp, tb, est, &prog->exts, ovr, extack);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -452,7 +454,7 @@ static int cls_bpf_set_parms(struct net *net, struct tcf_proto *tp, ...@@ -452,7 +454,7 @@ static int cls_bpf_set_parms(struct net *net, struct tcf_proto *tp,
static int cls_bpf_change(struct net *net, struct sk_buff *in_skb, static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
struct tcf_proto *tp, unsigned long base, struct tcf_proto *tp, unsigned long base,
u32 handle, struct nlattr **tca, u32 handle, struct nlattr **tca,
void **arg, bool ovr) void **arg, bool ovr, struct netlink_ext_ack *extack)
{ {
struct cls_bpf_head *head = rtnl_dereference(tp->root); struct cls_bpf_head *head = rtnl_dereference(tp->root);
struct cls_bpf_prog *oldprog = *arg; struct cls_bpf_prog *oldprog = *arg;
...@@ -500,7 +502,8 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb, ...@@ -500,7 +502,8 @@ static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
prog->handle = handle; prog->handle = handle;
} }
ret = cls_bpf_set_parms(net, tp, prog, base, tb, tca[TCA_RATE], ovr); ret = cls_bpf_set_parms(net, tp, prog, base, tb, tca[TCA_RATE], ovr,
extack);
if (ret < 0) if (ret < 0)
goto errout_idr; goto errout_idr;
......
...@@ -91,7 +91,8 @@ static void cls_cgroup_destroy_rcu(struct rcu_head *root) ...@@ -91,7 +91,8 @@ static void cls_cgroup_destroy_rcu(struct rcu_head *root)
static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb, static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb,
struct tcf_proto *tp, unsigned long base, struct tcf_proto *tp, unsigned long base,
u32 handle, struct nlattr **tca, u32 handle, struct nlattr **tca,
void **arg, bool ovr) void **arg, bool ovr,
struct netlink_ext_ack *extack)
{ {
struct nlattr *tb[TCA_CGROUP_MAX + 1]; struct nlattr *tb[TCA_CGROUP_MAX + 1];
struct cls_cgroup_head *head = rtnl_dereference(tp->root); struct cls_cgroup_head *head = rtnl_dereference(tp->root);
...@@ -121,7 +122,8 @@ static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb, ...@@ -121,7 +122,8 @@ static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb,
if (err < 0) if (err < 0)
goto errout; goto errout;
err = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &new->exts, ovr); err = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &new->exts, ovr,
extack);
if (err < 0) if (err < 0)
goto errout; goto errout;
...@@ -154,7 +156,8 @@ static void cls_cgroup_destroy(struct tcf_proto *tp) ...@@ -154,7 +156,8 @@ static void cls_cgroup_destroy(struct tcf_proto *tp)
} }
} }
static int cls_cgroup_delete(struct tcf_proto *tp, void *arg, bool *last) static int cls_cgroup_delete(struct tcf_proto *tp, void *arg, bool *last,
struct netlink_ext_ack *extack)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
......
...@@ -401,7 +401,7 @@ static void flow_destroy_filter(struct rcu_head *head) ...@@ -401,7 +401,7 @@ static void flow_destroy_filter(struct rcu_head *head)
static int flow_change(struct net *net, struct sk_buff *in_skb, static int flow_change(struct net *net, struct sk_buff *in_skb,
struct tcf_proto *tp, unsigned long base, struct tcf_proto *tp, unsigned long base,
u32 handle, struct nlattr **tca, u32 handle, struct nlattr **tca,
void **arg, bool ovr) void **arg, bool ovr, struct netlink_ext_ack *extack)
{ {
struct flow_head *head = rtnl_dereference(tp->root); struct flow_head *head = rtnl_dereference(tp->root);
struct flow_filter *fold, *fnew; struct flow_filter *fold, *fnew;
...@@ -454,7 +454,8 @@ static int flow_change(struct net *net, struct sk_buff *in_skb, ...@@ -454,7 +454,8 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,
if (err < 0) if (err < 0)
goto err2; goto err2;
err = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &fnew->exts, ovr); err = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &fnew->exts, ovr,
extack);
if (err < 0) if (err < 0)
goto err2; goto err2;
...@@ -574,7 +575,8 @@ static int flow_change(struct net *net, struct sk_buff *in_skb, ...@@ -574,7 +575,8 @@ static int flow_change(struct net *net, struct sk_buff *in_skb,
return err; return err;
} }
static int flow_delete(struct tcf_proto *tp, void *arg, bool *last) static int flow_delete(struct tcf_proto *tp, void *arg, bool *last,
struct netlink_ext_ack *extack)
{ {
struct flow_head *head = rtnl_dereference(tp->root); struct flow_head *head = rtnl_dereference(tp->root);
struct flow_filter *f = arg; struct flow_filter *f = arg;
......
...@@ -526,13 +526,14 @@ static void fl_set_key_ip(struct nlattr **tb, ...@@ -526,13 +526,14 @@ static void fl_set_key_ip(struct nlattr **tb,
} }
static int fl_set_key(struct net *net, struct nlattr **tb, static int fl_set_key(struct net *net, struct nlattr **tb,
struct fl_flow_key *key, struct fl_flow_key *mask) struct fl_flow_key *key, struct fl_flow_key *mask,
struct netlink_ext_ack *extack)
{ {
__be16 ethertype; __be16 ethertype;
int ret = 0; int ret = 0;
#ifdef CONFIG_NET_CLS_IND #ifdef CONFIG_NET_CLS_IND
if (tb[TCA_FLOWER_INDEV]) { if (tb[TCA_FLOWER_INDEV]) {
int err = tcf_change_indev(net, tb[TCA_FLOWER_INDEV]); int err = tcf_change_indev(net, tb[TCA_FLOWER_INDEV], extack);
if (err < 0) if (err < 0)
return err; return err;
key->indev_ifindex = err; key->indev_ifindex = err;
...@@ -827,11 +828,12 @@ static int fl_check_assign_mask(struct cls_fl_head *head, ...@@ -827,11 +828,12 @@ static int fl_check_assign_mask(struct cls_fl_head *head,
static int fl_set_parms(struct net *net, struct tcf_proto *tp, static int fl_set_parms(struct net *net, struct tcf_proto *tp,
struct cls_fl_filter *f, struct fl_flow_mask *mask, struct cls_fl_filter *f, struct fl_flow_mask *mask,
unsigned long base, struct nlattr **tb, unsigned long base, struct nlattr **tb,
struct nlattr *est, bool ovr) struct nlattr *est, bool ovr,
struct netlink_ext_ack *extack)
{ {
int err; int err;
err = tcf_exts_validate(net, tp, tb, est, &f->exts, ovr); err = tcf_exts_validate(net, tp, tb, est, &f->exts, ovr, extack);
if (err < 0) if (err < 0)
return err; return err;
...@@ -840,7 +842,7 @@ static int fl_set_parms(struct net *net, struct tcf_proto *tp, ...@@ -840,7 +842,7 @@ static int fl_set_parms(struct net *net, struct tcf_proto *tp,
tcf_bind_filter(tp, &f->res, base); tcf_bind_filter(tp, &f->res, base);
} }
err = fl_set_key(net, tb, &f->key, &mask->key); err = fl_set_key(net, tb, &f->key, &mask->key, extack);
if (err) if (err)
return err; return err;
...@@ -853,7 +855,7 @@ static int fl_set_parms(struct net *net, struct tcf_proto *tp, ...@@ -853,7 +855,7 @@ static int fl_set_parms(struct net *net, struct tcf_proto *tp,
static int fl_change(struct net *net, struct sk_buff *in_skb, static int fl_change(struct net *net, struct sk_buff *in_skb,
struct tcf_proto *tp, unsigned long base, struct tcf_proto *tp, unsigned long base,
u32 handle, struct nlattr **tca, u32 handle, struct nlattr **tca,
void **arg, bool ovr) void **arg, bool ovr, struct netlink_ext_ack *extack)
{ {
struct cls_fl_head *head = rtnl_dereference(tp->root); struct cls_fl_head *head = rtnl_dereference(tp->root);
struct cls_fl_filter *fold = *arg; struct cls_fl_filter *fold = *arg;
...@@ -916,7 +918,8 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, ...@@ -916,7 +918,8 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,
} }
} }
err = fl_set_parms(net, tp, fnew, &mask, base, tb, tca[TCA_RATE], ovr); err = fl_set_parms(net, tp, fnew, &mask, base, tb, tca[TCA_RATE], ovr,
extack);
if (err) if (err)
goto errout_idr; goto errout_idr;
...@@ -983,7 +986,8 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, ...@@ -983,7 +986,8 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,
return err; return err;
} }
static int fl_delete(struct tcf_proto *tp, void *arg, bool *last) static int fl_delete(struct tcf_proto *tp, void *arg, bool *last,
struct netlink_ext_ack *extack)
{ {
struct cls_fl_head *head = rtnl_dereference(tp->root); struct cls_fl_head *head = rtnl_dereference(tp->root);
struct cls_fl_filter *f = arg; struct cls_fl_filter *f = arg;
......
...@@ -172,7 +172,8 @@ static void fw_destroy(struct tcf_proto *tp) ...@@ -172,7 +172,8 @@ static void fw_destroy(struct tcf_proto *tp)
kfree_rcu(head, rcu); kfree_rcu(head, rcu);
} }
static int fw_delete(struct tcf_proto *tp, void *arg, bool *last) static int fw_delete(struct tcf_proto *tp, void *arg, bool *last,
struct netlink_ext_ack *extack)
{ {
struct fw_head *head = rtnl_dereference(tp->root); struct fw_head *head = rtnl_dereference(tp->root);
struct fw_filter *f = arg; struct fw_filter *f = arg;
...@@ -218,13 +219,15 @@ static const struct nla_policy fw_policy[TCA_FW_MAX + 1] = { ...@@ -218,13 +219,15 @@ static const struct nla_policy fw_policy[TCA_FW_MAX + 1] = {
static int fw_set_parms(struct net *net, struct tcf_proto *tp, static int fw_set_parms(struct net *net, struct tcf_proto *tp,
struct fw_filter *f, struct nlattr **tb, struct fw_filter *f, struct nlattr **tb,
struct nlattr **tca, unsigned long base, bool ovr) struct nlattr **tca, unsigned long base, bool ovr,
struct netlink_ext_ack *extack)
{ {
struct fw_head *head = rtnl_dereference(tp->root); struct fw_head *head = rtnl_dereference(tp->root);
u32 mask; u32 mask;
int err; int err;
err = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &f->exts, ovr); err = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &f->exts, ovr,
extack);
if (err < 0) if (err < 0)
return err; return err;
...@@ -236,7 +239,7 @@ static int fw_set_parms(struct net *net, struct tcf_proto *tp, ...@@ -236,7 +239,7 @@ static int fw_set_parms(struct net *net, struct tcf_proto *tp,
#ifdef CONFIG_NET_CLS_IND #ifdef CONFIG_NET_CLS_IND
if (tb[TCA_FW_INDEV]) { if (tb[TCA_FW_INDEV]) {
int ret; int ret;
ret = tcf_change_indev(net, tb[TCA_FW_INDEV]); ret = tcf_change_indev(net, tb[TCA_FW_INDEV], extack);
if (ret < 0) if (ret < 0)
return ret; return ret;
f->ifindex = ret; f->ifindex = ret;
...@@ -257,7 +260,7 @@ static int fw_set_parms(struct net *net, struct tcf_proto *tp, ...@@ -257,7 +260,7 @@ static int fw_set_parms(struct net *net, struct tcf_proto *tp,
static int fw_change(struct net *net, struct sk_buff *in_skb, static int fw_change(struct net *net, struct sk_buff *in_skb,
struct tcf_proto *tp, unsigned long base, struct tcf_proto *tp, unsigned long base,
u32 handle, struct nlattr **tca, void **arg, u32 handle, struct nlattr **tca, void **arg,
bool ovr) bool ovr, struct netlink_ext_ack *extack)
{ {
struct fw_head *head = rtnl_dereference(tp->root); struct fw_head *head = rtnl_dereference(tp->root);
struct fw_filter *f = *arg; struct fw_filter *f = *arg;
...@@ -296,7 +299,7 @@ static int fw_change(struct net *net, struct sk_buff *in_skb, ...@@ -296,7 +299,7 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,
return err; return err;
} }
err = fw_set_parms(net, tp, fnew, tb, tca, base, ovr); err = fw_set_parms(net, tp, fnew, tb, tca, base, ovr, extack);
if (err < 0) { if (err < 0) {
tcf_exts_destroy(&fnew->exts); tcf_exts_destroy(&fnew->exts);
kfree(fnew); kfree(fnew);
...@@ -345,7 +348,7 @@ static int fw_change(struct net *net, struct sk_buff *in_skb, ...@@ -345,7 +348,7 @@ static int fw_change(struct net *net, struct sk_buff *in_skb,
f->id = handle; f->id = handle;
f->tp = tp; f->tp = tp;
err = fw_set_parms(net, tp, f, tb, tca, base, ovr); err = fw_set_parms(net, tp, f, tb, tca, base, ovr, extack);
if (err < 0) if (err < 0)
goto errout; goto errout;
......
...@@ -142,11 +142,12 @@ static const struct nla_policy mall_policy[TCA_MATCHALL_MAX + 1] = { ...@@ -142,11 +142,12 @@ static const struct nla_policy mall_policy[TCA_MATCHALL_MAX + 1] = {
static int mall_set_parms(struct net *net, struct tcf_proto *tp, static int mall_set_parms(struct net *net, struct tcf_proto *tp,
struct cls_mall_head *head, struct cls_mall_head *head,
unsigned long base, struct nlattr **tb, unsigned long base, struct nlattr **tb,
struct nlattr *est, bool ovr) struct nlattr *est, bool ovr,
struct netlink_ext_ack *extack)
{ {
int err; int err;
err = tcf_exts_validate(net, tp, tb, est, &head->exts, ovr); err = tcf_exts_validate(net, tp, tb, est, &head->exts, ovr, extack);
if (err < 0) if (err < 0)
return err; return err;
...@@ -160,7 +161,7 @@ static int mall_set_parms(struct net *net, struct tcf_proto *tp, ...@@ -160,7 +161,7 @@ static int mall_set_parms(struct net *net, struct tcf_proto *tp,
static int mall_change(struct net *net, struct sk_buff *in_skb, static int mall_change(struct net *net, struct sk_buff *in_skb,
struct tcf_proto *tp, unsigned long base, struct tcf_proto *tp, unsigned long base,
u32 handle, struct nlattr **tca, u32 handle, struct nlattr **tca,
void **arg, bool ovr) void **arg, bool ovr, struct netlink_ext_ack *extack)
{ {
struct cls_mall_head *head = rtnl_dereference(tp->root); struct cls_mall_head *head = rtnl_dereference(tp->root);
struct nlattr *tb[TCA_MATCHALL_MAX + 1]; struct nlattr *tb[TCA_MATCHALL_MAX + 1];
...@@ -198,12 +199,13 @@ static int mall_change(struct net *net, struct sk_buff *in_skb, ...@@ -198,12 +199,13 @@ static int mall_change(struct net *net, struct sk_buff *in_skb,
new->handle = handle; new->handle = handle;
new->flags = flags; new->flags = flags;
err = mall_set_parms(net, tp, new, base, tb, tca[TCA_RATE], ovr); err = mall_set_parms(net, tp, new, base, tb, tca[TCA_RATE], ovr,
extack);
if (err) if (err)
goto err_set_parms; goto err_set_parms;
if (!tc_skip_hw(new->flags)) { if (!tc_skip_hw(new->flags)) {
err = mall_replace_hw_filter(tp, new, (unsigned long) new); err = mall_replace_hw_filter(tp, new, (unsigned long)new);
if (err) if (err)
goto err_replace_hw_filter; goto err_replace_hw_filter;
} }
...@@ -223,7 +225,8 @@ static int mall_change(struct net *net, struct sk_buff *in_skb, ...@@ -223,7 +225,8 @@ static int mall_change(struct net *net, struct sk_buff *in_skb,
return err; return err;
} }
static int mall_delete(struct tcf_proto *tp, void *arg, bool *last) static int mall_delete(struct tcf_proto *tp, void *arg, bool *last,
struct netlink_ext_ack *extack)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
......
...@@ -316,7 +316,8 @@ static void route4_destroy(struct tcf_proto *tp) ...@@ -316,7 +316,8 @@ static void route4_destroy(struct tcf_proto *tp)
kfree_rcu(head, rcu); kfree_rcu(head, rcu);
} }
static int route4_delete(struct tcf_proto *tp, void *arg, bool *last) static int route4_delete(struct tcf_proto *tp, void *arg, bool *last,
struct netlink_ext_ack *extack)
{ {
struct route4_head *head = rtnl_dereference(tp->root); struct route4_head *head = rtnl_dereference(tp->root);
struct route4_filter *f = arg; struct route4_filter *f = arg;
...@@ -389,7 +390,7 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp, ...@@ -389,7 +390,7 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp,
unsigned long base, struct route4_filter *f, unsigned long base, struct route4_filter *f,
u32 handle, struct route4_head *head, u32 handle, struct route4_head *head,
struct nlattr **tb, struct nlattr *est, int new, struct nlattr **tb, struct nlattr *est, int new,
bool ovr) bool ovr, struct netlink_ext_ack *extack)
{ {
u32 id = 0, to = 0, nhandle = 0x8000; u32 id = 0, to = 0, nhandle = 0x8000;
struct route4_filter *fp; struct route4_filter *fp;
...@@ -397,7 +398,7 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp, ...@@ -397,7 +398,7 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp,
struct route4_bucket *b; struct route4_bucket *b;
int err; int err;
err = tcf_exts_validate(net, tp, tb, est, &f->exts, ovr); err = tcf_exts_validate(net, tp, tb, est, &f->exts, ovr, extack);
if (err < 0) if (err < 0)
return err; return err;
...@@ -471,7 +472,8 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp, ...@@ -471,7 +472,8 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp,
static int route4_change(struct net *net, struct sk_buff *in_skb, static int route4_change(struct net *net, struct sk_buff *in_skb,
struct tcf_proto *tp, unsigned long base, u32 handle, struct tcf_proto *tp, unsigned long base, u32 handle,
struct nlattr **tca, void **arg, bool ovr) struct nlattr **tca, void **arg, bool ovr,
struct netlink_ext_ack *extack)
{ {
struct route4_head *head = rtnl_dereference(tp->root); struct route4_head *head = rtnl_dereference(tp->root);
struct route4_filter __rcu **fp; struct route4_filter __rcu **fp;
...@@ -515,7 +517,7 @@ static int route4_change(struct net *net, struct sk_buff *in_skb, ...@@ -515,7 +517,7 @@ static int route4_change(struct net *net, struct sk_buff *in_skb,
} }
err = route4_set_parms(net, tp, base, f, handle, head, tb, err = route4_set_parms(net, tp, base, f, handle, head, tb,
tca[TCA_RATE], new, ovr); tca[TCA_RATE], new, ovr, extack);
if (err < 0) if (err < 0)
goto errout; goto errout;
......
...@@ -350,7 +350,8 @@ static void rsvp_destroy(struct tcf_proto *tp) ...@@ -350,7 +350,8 @@ static void rsvp_destroy(struct tcf_proto *tp)
kfree_rcu(data, rcu); kfree_rcu(data, rcu);
} }
static int rsvp_delete(struct tcf_proto *tp, void *arg, bool *last) static int rsvp_delete(struct tcf_proto *tp, void *arg, bool *last,
struct netlink_ext_ack *extack)
{ {
struct rsvp_head *head = rtnl_dereference(tp->root); struct rsvp_head *head = rtnl_dereference(tp->root);
struct rsvp_filter *nfp, *f = arg; struct rsvp_filter *nfp, *f = arg;
...@@ -486,7 +487,7 @@ static int rsvp_change(struct net *net, struct sk_buff *in_skb, ...@@ -486,7 +487,7 @@ static int rsvp_change(struct net *net, struct sk_buff *in_skb,
struct tcf_proto *tp, unsigned long base, struct tcf_proto *tp, unsigned long base,
u32 handle, u32 handle,
struct nlattr **tca, struct nlattr **tca,
void **arg, bool ovr) void **arg, bool ovr, struct netlink_ext_ack *extack)
{ {
struct rsvp_head *data = rtnl_dereference(tp->root); struct rsvp_head *data = rtnl_dereference(tp->root);
struct rsvp_filter *f, *nfp; struct rsvp_filter *f, *nfp;
...@@ -511,7 +512,7 @@ static int rsvp_change(struct net *net, struct sk_buff *in_skb, ...@@ -511,7 +512,7 @@ static int rsvp_change(struct net *net, struct sk_buff *in_skb,
err = tcf_exts_init(&e, TCA_RSVP_ACT, TCA_RSVP_POLICE); err = tcf_exts_init(&e, TCA_RSVP_ACT, TCA_RSVP_POLICE);
if (err < 0) if (err < 0)
return err; return err;
err = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &e, ovr); err = tcf_exts_validate(net, tp, tb, tca[TCA_RATE], &e, ovr, extack);
if (err < 0) if (err < 0)
goto errout2; goto errout2;
......
...@@ -193,7 +193,8 @@ static void tcindex_destroy_fexts(struct rcu_head *head) ...@@ -193,7 +193,8 @@ static void tcindex_destroy_fexts(struct rcu_head *head)
tcf_queue_work(&f->work); tcf_queue_work(&f->work);
} }
static int tcindex_delete(struct tcf_proto *tp, void *arg, bool *last) static int tcindex_delete(struct tcf_proto *tp, void *arg, bool *last,
struct netlink_ext_ack *extack)
{ {
struct tcindex_data *p = rtnl_dereference(tp->root); struct tcindex_data *p = rtnl_dereference(tp->root);
struct tcindex_filter_result *r = arg; struct tcindex_filter_result *r = arg;
...@@ -246,7 +247,7 @@ static int tcindex_destroy_element(struct tcf_proto *tp, ...@@ -246,7 +247,7 @@ static int tcindex_destroy_element(struct tcf_proto *tp,
{ {
bool last; bool last;
return tcindex_delete(tp, arg, &last); return tcindex_delete(tp, arg, &last, NULL);
} }
static void __tcindex_destroy(struct rcu_head *head) static void __tcindex_destroy(struct rcu_head *head)
...@@ -322,7 +323,7 @@ static int ...@@ -322,7 +323,7 @@ static int
tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base, tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,
u32 handle, struct tcindex_data *p, u32 handle, struct tcindex_data *p,
struct tcindex_filter_result *r, struct nlattr **tb, struct tcindex_filter_result *r, struct nlattr **tb,
struct nlattr *est, bool ovr) struct nlattr *est, bool ovr, struct netlink_ext_ack *extack)
{ {
struct tcindex_filter_result new_filter_result, *old_r = r; struct tcindex_filter_result new_filter_result, *old_r = r;
struct tcindex_filter_result cr; struct tcindex_filter_result cr;
...@@ -334,7 +335,7 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base, ...@@ -334,7 +335,7 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,
err = tcf_exts_init(&e, TCA_TCINDEX_ACT, TCA_TCINDEX_POLICE); err = tcf_exts_init(&e, TCA_TCINDEX_ACT, TCA_TCINDEX_POLICE);
if (err < 0) if (err < 0)
return err; return err;
err = tcf_exts_validate(net, tp, tb, est, &e, ovr); err = tcf_exts_validate(net, tp, tb, est, &e, ovr, extack);
if (err < 0) if (err < 0)
goto errout; goto errout;
...@@ -520,7 +521,8 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base, ...@@ -520,7 +521,8 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,
static int static int
tcindex_change(struct net *net, struct sk_buff *in_skb, tcindex_change(struct net *net, struct sk_buff *in_skb,
struct tcf_proto *tp, unsigned long base, u32 handle, struct tcf_proto *tp, unsigned long base, u32 handle,
struct nlattr **tca, void **arg, bool ovr) struct nlattr **tca, void **arg, bool ovr,
struct netlink_ext_ack *extack)
{ {
struct nlattr *opt = tca[TCA_OPTIONS]; struct nlattr *opt = tca[TCA_OPTIONS];
struct nlattr *tb[TCA_TCINDEX_MAX + 1]; struct nlattr *tb[TCA_TCINDEX_MAX + 1];
...@@ -540,7 +542,7 @@ tcindex_change(struct net *net, struct sk_buff *in_skb, ...@@ -540,7 +542,7 @@ tcindex_change(struct net *net, struct sk_buff *in_skb,
return err; return err;
return tcindex_set_parms(net, tp, base, handle, p, r, tb, return tcindex_set_parms(net, tp, base, handle, p, r, tb,
tca[TCA_RATE], ovr); tca[TCA_RATE], ovr, extack);
} }
static void tcindex_walk(struct tcf_proto *tp, struct tcf_walker *walker) static void tcindex_walk(struct tcf_proto *tp, struct tcf_walker *walker)
......
...@@ -672,7 +672,8 @@ static void u32_destroy(struct tcf_proto *tp) ...@@ -672,7 +672,8 @@ static void u32_destroy(struct tcf_proto *tp)
tp->data = NULL; tp->data = NULL;
} }
static int u32_delete(struct tcf_proto *tp, void *arg, bool *last) static int u32_delete(struct tcf_proto *tp, void *arg, bool *last,
struct netlink_ext_ack *extack)
{ {
struct tc_u_hnode *ht = arg; struct tc_u_hnode *ht = arg;
struct tc_u_hnode *root_ht = rtnl_dereference(tp->root); struct tc_u_hnode *root_ht = rtnl_dereference(tp->root);
...@@ -688,13 +689,16 @@ static int u32_delete(struct tcf_proto *tp, void *arg, bool *last) ...@@ -688,13 +689,16 @@ static int u32_delete(struct tcf_proto *tp, void *arg, bool *last)
goto out; goto out;
} }
if (root_ht == ht) if (root_ht == ht) {
NL_SET_ERR_MSG_MOD(extack, "Not allowed to delete root node");
return -EINVAL; return -EINVAL;
}
if (ht->refcnt == 1) { if (ht->refcnt == 1) {
ht->refcnt--; ht->refcnt--;
u32_destroy_hnode(tp, ht); u32_destroy_hnode(tp, ht);
} else { } else {
NL_SET_ERR_MSG_MOD(extack, "Can not delete in-use filter");
return -EBUSY; return -EBUSY;
} }
...@@ -765,11 +769,12 @@ static const struct nla_policy u32_policy[TCA_U32_MAX + 1] = { ...@@ -765,11 +769,12 @@ static const struct nla_policy u32_policy[TCA_U32_MAX + 1] = {
static int u32_set_parms(struct net *net, struct tcf_proto *tp, static int u32_set_parms(struct net *net, struct tcf_proto *tp,
unsigned long base, struct tc_u_hnode *ht, unsigned long base, struct tc_u_hnode *ht,
struct tc_u_knode *n, struct nlattr **tb, struct tc_u_knode *n, struct nlattr **tb,
struct nlattr *est, bool ovr) struct nlattr *est, bool ovr,
struct netlink_ext_ack *extack)
{ {
int err; int err;
err = tcf_exts_validate(net, tp, tb, est, &n->exts, ovr); err = tcf_exts_validate(net, tp, tb, est, &n->exts, ovr, extack);
if (err < 0) if (err < 0)
return err; return err;
...@@ -777,14 +782,18 @@ static int u32_set_parms(struct net *net, struct tcf_proto *tp, ...@@ -777,14 +782,18 @@ static int u32_set_parms(struct net *net, struct tcf_proto *tp,
u32 handle = nla_get_u32(tb[TCA_U32_LINK]); u32 handle = nla_get_u32(tb[TCA_U32_LINK]);
struct tc_u_hnode *ht_down = NULL, *ht_old; struct tc_u_hnode *ht_down = NULL, *ht_old;
if (TC_U32_KEY(handle)) if (TC_U32_KEY(handle)) {
NL_SET_ERR_MSG_MOD(extack, "u32 Link handle must be a hash table");
return -EINVAL; return -EINVAL;
}
if (handle) { if (handle) {
ht_down = u32_lookup_ht(ht->tp_c, handle); ht_down = u32_lookup_ht(ht->tp_c, handle);
if (ht_down == NULL) if (!ht_down) {
NL_SET_ERR_MSG_MOD(extack, "Link hash table not found");
return -EINVAL; return -EINVAL;
}
ht_down->refcnt++; ht_down->refcnt++;
} }
...@@ -802,7 +811,7 @@ static int u32_set_parms(struct net *net, struct tcf_proto *tp, ...@@ -802,7 +811,7 @@ static int u32_set_parms(struct net *net, struct tcf_proto *tp,
#ifdef CONFIG_NET_CLS_IND #ifdef CONFIG_NET_CLS_IND
if (tb[TCA_U32_INDEV]) { if (tb[TCA_U32_INDEV]) {
int ret; int ret;
ret = tcf_change_indev(net, tb[TCA_U32_INDEV]); ret = tcf_change_indev(net, tb[TCA_U32_INDEV], extack);
if (ret < 0) if (ret < 0)
return -EINVAL; return -EINVAL;
n->ifindex = ret; n->ifindex = ret;
...@@ -893,7 +902,8 @@ static struct tc_u_knode *u32_init_knode(struct tcf_proto *tp, ...@@ -893,7 +902,8 @@ static struct tc_u_knode *u32_init_knode(struct tcf_proto *tp,
static int u32_change(struct net *net, struct sk_buff *in_skb, static int u32_change(struct net *net, struct sk_buff *in_skb,
struct tcf_proto *tp, unsigned long base, u32 handle, struct tcf_proto *tp, unsigned long base, u32 handle,
struct nlattr **tca, void **arg, bool ovr) struct nlattr **tca, void **arg, bool ovr,
struct netlink_ext_ack *extack)
{ {
struct tc_u_common *tp_c = tp->data; struct tc_u_common *tp_c = tp->data;
struct tc_u_hnode *ht; struct tc_u_hnode *ht;
...@@ -907,28 +917,40 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, ...@@ -907,28 +917,40 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,
size_t size; size_t size;
#endif #endif
if (opt == NULL) if (!opt) {
return handle ? -EINVAL : 0; if (handle) {
NL_SET_ERR_MSG_MOD(extack, "Filter handle requires options");
return -EINVAL;
} else {
return 0;
}
}
err = nla_parse_nested(tb, TCA_U32_MAX, opt, u32_policy, NULL); err = nla_parse_nested(tb, TCA_U32_MAX, opt, u32_policy, extack);
if (err < 0) if (err < 0)
return err; return err;
if (tb[TCA_U32_FLAGS]) { if (tb[TCA_U32_FLAGS]) {
flags = nla_get_u32(tb[TCA_U32_FLAGS]); flags = nla_get_u32(tb[TCA_U32_FLAGS]);
if (!tc_flags_valid(flags)) if (!tc_flags_valid(flags)) {
NL_SET_ERR_MSG_MOD(extack, "Invalid filter flags");
return -EINVAL; return -EINVAL;
}
} }
n = *arg; n = *arg;
if (n) { if (n) {
struct tc_u_knode *new; struct tc_u_knode *new;
if (TC_U32_KEY(n->handle) == 0) if (TC_U32_KEY(n->handle) == 0) {
NL_SET_ERR_MSG_MOD(extack, "Key node id cannot be zero");
return -EINVAL; return -EINVAL;
}
if (n->flags != flags) if (n->flags != flags) {
NL_SET_ERR_MSG_MOD(extack, "Key node flags do not match passed flags");
return -EINVAL; return -EINVAL;
}
new = u32_init_knode(tp, n); new = u32_init_knode(tp, n);
if (!new) if (!new)
...@@ -936,7 +958,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, ...@@ -936,7 +958,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,
err = u32_set_parms(net, tp, base, err = u32_set_parms(net, tp, base,
rtnl_dereference(n->ht_up), new, tb, rtnl_dereference(n->ht_up), new, tb,
tca[TCA_RATE], ovr); tca[TCA_RATE], ovr, extack);
if (err) { if (err) {
u32_destroy_key(tp, new, false); u32_destroy_key(tp, new, false);
...@@ -962,10 +984,14 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, ...@@ -962,10 +984,14 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,
if (tb[TCA_U32_DIVISOR]) { if (tb[TCA_U32_DIVISOR]) {
unsigned int divisor = nla_get_u32(tb[TCA_U32_DIVISOR]); unsigned int divisor = nla_get_u32(tb[TCA_U32_DIVISOR]);
if (--divisor > 0x100) if (--divisor > 0x100) {
NL_SET_ERR_MSG_MOD(extack, "Exceeded maximum 256 hash buckets");
return -EINVAL; return -EINVAL;
if (TC_U32_KEY(handle)) }
if (TC_U32_KEY(handle)) {
NL_SET_ERR_MSG_MOD(extack, "Divisor can only be used on a hash table");
return -EINVAL; return -EINVAL;
}
ht = kzalloc(sizeof(*ht) + divisor*sizeof(void *), GFP_KERNEL); ht = kzalloc(sizeof(*ht) + divisor*sizeof(void *), GFP_KERNEL);
if (ht == NULL) if (ht == NULL)
return -ENOBUFS; return -ENOBUFS;
...@@ -1011,20 +1037,26 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, ...@@ -1011,20 +1037,26 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,
htid = ht->handle; htid = ht->handle;
} else { } else {
ht = u32_lookup_ht(tp->data, TC_U32_HTID(htid)); ht = u32_lookup_ht(tp->data, TC_U32_HTID(htid));
if (ht == NULL) if (!ht) {
NL_SET_ERR_MSG_MOD(extack, "Specified hash table not found");
return -EINVAL; return -EINVAL;
}
} }
} else { } else {
ht = rtnl_dereference(tp->root); ht = rtnl_dereference(tp->root);
htid = ht->handle; htid = ht->handle;
} }
if (ht->divisor < TC_U32_HASH(htid)) if (ht->divisor < TC_U32_HASH(htid)) {
NL_SET_ERR_MSG_MOD(extack, "Specified hash table buckets exceed configured value");
return -EINVAL; return -EINVAL;
}
if (handle) { if (handle) {
if (TC_U32_HTID(handle) && TC_U32_HTID(handle^htid)) if (TC_U32_HTID(handle) && TC_U32_HTID(handle ^ htid)) {
NL_SET_ERR_MSG_MOD(extack, "Handle specified hash table address mismatch");
return -EINVAL; return -EINVAL;
}
handle = htid | TC_U32_NODE(handle); handle = htid | TC_U32_NODE(handle);
err = idr_alloc_ext(&ht->handle_idr, NULL, NULL, err = idr_alloc_ext(&ht->handle_idr, NULL, NULL,
handle, handle + 1, handle, handle + 1,
...@@ -1035,6 +1067,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, ...@@ -1035,6 +1067,7 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,
handle = gen_new_kid(ht, htid); handle = gen_new_kid(ht, htid);
if (tb[TCA_U32_SEL] == NULL) { if (tb[TCA_U32_SEL] == NULL) {
NL_SET_ERR_MSG_MOD(extack, "Selector not specified");
err = -EINVAL; err = -EINVAL;
goto erridr; goto erridr;
} }
...@@ -1083,7 +1116,8 @@ static int u32_change(struct net *net, struct sk_buff *in_skb, ...@@ -1083,7 +1116,8 @@ static int u32_change(struct net *net, struct sk_buff *in_skb,
} }
#endif #endif
err = u32_set_parms(net, tp, base, ht, n, tb, tca[TCA_RATE], ovr); err = u32_set_parms(net, tp, base, ht, n, tb, tca[TCA_RATE], ovr,
extack);
if (err == 0) { if (err == 0) {
struct tc_u_knode __rcu **ins; struct tc_u_knode __rcu **ins;
struct tc_u_knode *pins; struct tc_u_knode *pins;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment