@@ -35,7 +35,7 @@ static const struct nla_policy pedit_key_ex_policy[TCA_PEDIT_KEY_EX_MAX + 1] = {
};
static struct tcf_pedit_key_ex *tcf_pedit_keys_ex_parse(struct nlattr *nla,
- u8 n)
+ u8 n, struct netlink_ext_ack *extack)
{
struct tcf_pedit_key_ex *keys_ex;
struct tcf_pedit_key_ex *k;
@@ -56,37 +56,51 @@ static struct tcf_pedit_key_ex *tcf_pedit_keys_ex_parse(struct nlattr *nla,
struct nlattr *tb[TCA_PEDIT_KEY_EX_MAX + 1];
int ret;
- if (!n)
+ if (!n) {
+ NL_SET_ERR_MSG_MOD(extack, "Can't parse more extended keys than requested");
goto err_out;
+ }
+
n--;
- if (nla_type(ka) != TCA_PEDIT_KEY_EX)
+ if (nla_type(ka) != TCA_PEDIT_KEY_EX) {
+ NL_SET_ERR_MSG_MOD(extack, "Unknown attribute, expected extended key");
goto err_out;
+ }
- ret = nla_parse_nested_deprecated(tb, TCA_PEDIT_KEY_EX_MAX,
- ka, pedit_key_ex_policy,
- NULL);
+ ret = nla_parse_nested_deprecated(tb, TCA_PEDIT_KEY_EX_MAX, ka,
+ pedit_key_ex_policy, extack);
if (ret) {
err = ret;
goto err_out;
}
- if (!tb[TCA_PEDIT_KEY_EX_HTYPE] ||
- !tb[TCA_PEDIT_KEY_EX_CMD])
+ if (NL_REQ_ATTR_CHECK(extack, nla, tb, TCA_PEDIT_KEY_EX_HTYPE)) {
+ NL_SET_ERR_MSG(extack, "Missing required attribute");
goto err_out;
+ }
+
+ if (NL_REQ_ATTR_CHECK(extack, nla, tb, TCA_PEDIT_KEY_EX_CMD)) {
+ NL_SET_ERR_MSG(extack, "Missing required attribute");
+ goto err_out;
+ }
k->htype = nla_get_u16(tb[TCA_PEDIT_KEY_EX_HTYPE]);
k->cmd = nla_get_u16(tb[TCA_PEDIT_KEY_EX_CMD]);
if (k->htype > TCA_PEDIT_HDR_TYPE_MAX ||
- k->cmd > TCA_PEDIT_CMD_MAX)
+ k->cmd > TCA_PEDIT_CMD_MAX) {
+ NL_SET_ERR_MSG_MOD(extack, "Extended key is malformed");
goto err_out;
+ }
k++;
}
- if (n)
+ if (n) {
+ NL_SET_ERR_MSG_MOD(extack, "Not enough extended keys to parse");
goto err_out;
+ }
return keys_ex;
@@ -215,7 +229,7 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
}
nparms->tcfp_keys_ex =
- tcf_pedit_keys_ex_parse(tb[TCA_PEDIT_KEYS_EX], parm->nkeys);
+ tcf_pedit_keys_ex_parse(tb[TCA_PEDIT_KEYS_EX], parm->nkeys, extack);
if (IS_ERR(nparms->tcfp_keys_ex)) {
ret = PTR_ERR(nparms->tcfp_keys_ex);
goto out_free;
We have extack available when parsing 'ex' keys, so pass it to tcf_pedit_keys_ex_parse and add more detailed error messages. Signed-off-by: Pedro Tammela <pctammela@mojatatu.com> --- net/sched/act_pedit.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-)