Skip to content

Commit bd7d4c1

Browse files
Guillaume Naultdavem330
authored andcommitted
cls_flower: Add extack support for src and dst port range options
Pass extack down to fl_set_key_port_range() and set message on error. Both the min and max ports would qualify as invalid attributes here. Report the min one as invalid, as it's probably what makes the most sense from a user point of view. Signed-off-by: Guillaume Nault <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 442f730 commit bd7d4c1

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

net/sched/cls_flower.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,8 @@ static void fl_set_key_val(struct nlattr **tb,
738738
}
739739

740740
static int fl_set_key_port_range(struct nlattr **tb, struct fl_flow_key *key,
741-
struct fl_flow_key *mask)
741+
struct fl_flow_key *mask,
742+
struct netlink_ext_ack *extack)
742743
{
743744
fl_set_key_val(tb, &key->tp_range.tp_min.dst,
744745
TCA_FLOWER_KEY_PORT_DST_MIN, &mask->tp_range.tp_min.dst,
@@ -753,13 +754,22 @@ static int fl_set_key_port_range(struct nlattr **tb, struct fl_flow_key *key,
753754
TCA_FLOWER_KEY_PORT_SRC_MAX, &mask->tp_range.tp_max.src,
754755
TCA_FLOWER_UNSPEC, sizeof(key->tp_range.tp_max.src));
755756

756-
if ((mask->tp_range.tp_min.dst && mask->tp_range.tp_max.dst &&
757-
htons(key->tp_range.tp_max.dst) <=
758-
htons(key->tp_range.tp_min.dst)) ||
759-
(mask->tp_range.tp_min.src && mask->tp_range.tp_max.src &&
760-
htons(key->tp_range.tp_max.src) <=
761-
htons(key->tp_range.tp_min.src)))
757+
if (mask->tp_range.tp_min.dst && mask->tp_range.tp_max.dst &&
758+
htons(key->tp_range.tp_max.dst) <=
759+
htons(key->tp_range.tp_min.dst)) {
760+
NL_SET_ERR_MSG_ATTR(extack,
761+
tb[TCA_FLOWER_KEY_PORT_DST_MIN],
762+
"Invalid destination port range (min must be strictly smaller than max)");
762763
return -EINVAL;
764+
}
765+
if (mask->tp_range.tp_min.src && mask->tp_range.tp_max.src &&
766+
htons(key->tp_range.tp_max.src) <=
767+
htons(key->tp_range.tp_min.src)) {
768+
NL_SET_ERR_MSG_ATTR(extack,
769+
tb[TCA_FLOWER_KEY_PORT_SRC_MIN],
770+
"Invalid source port range (min must be strictly smaller than max)");
771+
return -EINVAL;
772+
}
763773

764774
return 0;
765775
}
@@ -1402,7 +1412,7 @@ static int fl_set_key(struct net *net, struct nlattr **tb,
14021412
if (key->basic.ip_proto == IPPROTO_TCP ||
14031413
key->basic.ip_proto == IPPROTO_UDP ||
14041414
key->basic.ip_proto == IPPROTO_SCTP) {
1405-
ret = fl_set_key_port_range(tb, key, mask);
1415+
ret = fl_set_key_port_range(tb, key, mask, extack);
14061416
if (ret)
14071417
return ret;
14081418
}

0 commit comments

Comments
 (0)