Skip to content

Commit 536b97a

Browse files
Asbjørn Sloth Tønnesenkuba-moo
authored andcommitted
net/sched: cls_flower: propagate tca[TCA_OPTIONS] to NL_REQ_ATTR_CHECK
NL_REQ_ATTR_CHECK() is used in fl_set_key_flags() to set extended attributes about the origin of an error, this patch propagates tca[TCA_OPTIONS] through. Before this patch: $ sudo ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/tc.yaml \ --do newtfilter --json '{ "chain": 0, "family": 0, "handle": 4, "ifindex": 22, "info": 262152, "kind": "flower", "options": { "flags": 0, "key-enc-flags": 8, "key-eth-type": 2048 }, "parent": 4294967283 }' Netlink error: Invalid argument nl_len = 68 (52) nl_flags = 0x300 nl_type = 2 error: -22 extack: {'msg': 'Missing flags mask', 'miss-type': 111} After this patch: [same cmd] Netlink error: Invalid argument nl_len = 76 (60) nl_flags = 0x300 nl_type = 2 error: -22 extack: {'msg': 'Missing flags mask', 'miss-type': 111, 'miss-nest': 56} Suggested-by: Jakub Kicinski <[email protected]> Signed-off-by: Asbjørn Sloth Tønnesen <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 706bf4f commit 536b97a

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

net/sched/cls_flower.c

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,8 +1171,9 @@ static void fl_set_key_flag(u32 flower_key, u32 flower_mask,
11711171
}
11721172
}
11731173

1174-
static int fl_set_key_flags(struct nlattr **tb, bool encap, u32 *flags_key,
1175-
u32 *flags_mask, struct netlink_ext_ack *extack)
1174+
static int fl_set_key_flags(struct nlattr *tca_opts, struct nlattr **tb,
1175+
bool encap, u32 *flags_key, u32 *flags_mask,
1176+
struct netlink_ext_ack *extack)
11761177
{
11771178
int fl_key, fl_mask;
11781179
u32 key, mask;
@@ -1186,7 +1187,7 @@ static int fl_set_key_flags(struct nlattr **tb, bool encap, u32 *flags_key,
11861187
}
11871188

11881189
/* mask is mandatory for flags */
1189-
if (NL_REQ_ATTR_CHECK(extack, NULL, tb, fl_mask)) {
1190+
if (NL_REQ_ATTR_CHECK(extack, tca_opts, tb, fl_mask)) {
11901191
NL_SET_ERR_MSG(extack, "Missing flags mask");
11911192
return -EINVAL;
11921193
}
@@ -1865,9 +1866,9 @@ static int fl_set_key_cfm(struct nlattr **tb,
18651866
return 0;
18661867
}
18671868

1868-
static int fl_set_key(struct net *net, struct nlattr **tb,
1869-
struct fl_flow_key *key, struct fl_flow_key *mask,
1870-
struct netlink_ext_ack *extack)
1869+
static int fl_set_key(struct net *net, struct nlattr *tca_opts,
1870+
struct nlattr **tb, struct fl_flow_key *key,
1871+
struct fl_flow_key *mask, struct netlink_ext_ack *extack)
18711872
{
18721873
__be16 ethertype;
18731874
int ret = 0;
@@ -2100,14 +2101,16 @@ static int fl_set_key(struct net *net, struct nlattr **tb,
21002101
return ret;
21012102

21022103
if (tb[TCA_FLOWER_KEY_FLAGS]) {
2103-
ret = fl_set_key_flags(tb, false, &key->control.flags,
2104+
ret = fl_set_key_flags(tca_opts, tb, false,
2105+
&key->control.flags,
21042106
&mask->control.flags, extack);
21052107
if (ret)
21062108
return ret;
21072109
}
21082110

21092111
if (tb[TCA_FLOWER_KEY_ENC_FLAGS])
2110-
ret = fl_set_key_flags(tb, true, &key->enc_control.flags,
2112+
ret = fl_set_key_flags(tca_opts, tb, true,
2113+
&key->enc_control.flags,
21112114
&mask->enc_control.flags, extack);
21122115

21132116
return ret;
@@ -2358,6 +2361,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,
23582361
{
23592362
struct cls_fl_head *head = fl_head_dereference(tp);
23602363
bool rtnl_held = !(flags & TCA_ACT_FLAGS_NO_RTNL);
2364+
struct nlattr *tca_opts = tca[TCA_OPTIONS];
23612365
struct cls_fl_filter *fold = *arg;
23622366
bool bound_to_filter = false;
23632367
struct cls_fl_filter *fnew;
@@ -2366,7 +2370,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,
23662370
bool in_ht;
23672371
int err;
23682372

2369-
if (!tca[TCA_OPTIONS]) {
2373+
if (!tca_opts) {
23702374
err = -EINVAL;
23712375
goto errout_fold;
23722376
}
@@ -2384,7 +2388,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,
23842388
}
23852389

23862390
err = nla_parse_nested_deprecated(tb, TCA_FLOWER_MAX,
2387-
tca[TCA_OPTIONS], fl_policy, NULL);
2391+
tca_opts, fl_policy, NULL);
23882392
if (err < 0)
23892393
goto errout_tb;
23902394

@@ -2460,7 +2464,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,
24602464
bound_to_filter = true;
24612465
}
24622466

2463-
err = fl_set_key(net, tb, &fnew->key, &mask->key, extack);
2467+
err = fl_set_key(net, tca_opts, tb, &fnew->key, &mask->key, extack);
24642468
if (err)
24652469
goto unbind_filter;
24662470

@@ -2800,18 +2804,19 @@ static void *fl_tmplt_create(struct net *net, struct tcf_chain *chain,
28002804
struct nlattr **tca,
28012805
struct netlink_ext_ack *extack)
28022806
{
2807+
struct nlattr *tca_opts = tca[TCA_OPTIONS];
28032808
struct fl_flow_tmplt *tmplt;
28042809
struct nlattr **tb;
28052810
int err;
28062811

2807-
if (!tca[TCA_OPTIONS])
2812+
if (!tca_opts)
28082813
return ERR_PTR(-EINVAL);
28092814

28102815
tb = kcalloc(TCA_FLOWER_MAX + 1, sizeof(struct nlattr *), GFP_KERNEL);
28112816
if (!tb)
28122817
return ERR_PTR(-ENOBUFS);
28132818
err = nla_parse_nested_deprecated(tb, TCA_FLOWER_MAX,
2814-
tca[TCA_OPTIONS], fl_policy, NULL);
2819+
tca_opts, fl_policy, NULL);
28152820
if (err)
28162821
goto errout_tb;
28172822

@@ -2821,7 +2826,8 @@ static void *fl_tmplt_create(struct net *net, struct tcf_chain *chain,
28212826
goto errout_tb;
28222827
}
28232828
tmplt->chain = chain;
2824-
err = fl_set_key(net, tb, &tmplt->dummy_key, &tmplt->mask, extack);
2829+
err = fl_set_key(net, tca_opts, tb, &tmplt->dummy_key,
2830+
&tmplt->mask, extack);
28252831
if (err)
28262832
goto errout_tmplt;
28272833

0 commit comments

Comments
 (0)