Commit bd7d4c12819b60b161939bc2f43053955d24d0df

Authored by Guillaume Nault
Committed by David S. Miller
1 parent 442f730e48

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 <gnault@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 1 changed file with 18 additions and 8 deletions Side-by-side Diff

net/sched/cls_flower.c
... ... @@ -738,7 +738,8 @@
738 738 }
739 739  
740 740 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)
742 743 {
743 744 fl_set_key_val(tb, &key->tp_range.tp_min.dst,
744 745 TCA_FLOWER_KEY_PORT_DST_MIN, &mask->tp_range.tp_min.dst,
745 746  
... ... @@ -753,13 +754,22 @@
753 754 TCA_FLOWER_KEY_PORT_SRC_MAX, &mask->tp_range.tp_max.src,
754 755 TCA_FLOWER_UNSPEC, sizeof(key->tp_range.tp_max.src));
755 756  
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)");
762 763 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 + }
763 773  
764 774 return 0;
765 775 }
... ... @@ -1402,7 +1412,7 @@
1402 1412 if (key->basic.ip_proto == IPPROTO_TCP ||
1403 1413 key->basic.ip_proto == IPPROTO_UDP ||
1404 1414 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);
1406 1416 if (ret)
1407 1417 return ret;
1408 1418 }