Skip to content

Commit 7b68488

Browse files
shorman-netronomedavem330
authored andcommitted
net/sched: cls_flower: Support matching on ICMP type and code
Support matching on ICMP type and code. Example usage: tc qdisc add dev eth0 ingress tc filter add dev eth0 protocol ip parent ffff: flower \ indev eth0 ip_proto icmp type 8 code 0 action drop tc filter add dev eth0 protocol ipv6 parent ffff: flower \ indev eth0 ip_proto icmpv6 type 128 code 0 action drop Signed-off-by: Simon Horman <simon.horman@netronome.com> Acked-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 972d387 commit 7b68488

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

include/uapi/linux/pkt_cls.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,16 @@ enum {
461461

462462
TCA_FLOWER_KEY_FLAGS, /* be32 */
463463
TCA_FLOWER_KEY_FLAGS_MASK, /* be32 */
464+
465+
TCA_FLOWER_KEY_ICMPV4_CODE, /* u8 */
466+
TCA_FLOWER_KEY_ICMPV4_CODE_MASK,/* u8 */
467+
TCA_FLOWER_KEY_ICMPV4_TYPE, /* u8 */
468+
TCA_FLOWER_KEY_ICMPV4_TYPE_MASK,/* u8 */
469+
TCA_FLOWER_KEY_ICMPV6_CODE, /* u8 */
470+
TCA_FLOWER_KEY_ICMPV6_CODE_MASK,/* u8 */
471+
TCA_FLOWER_KEY_ICMPV6_TYPE, /* u8 */
472+
TCA_FLOWER_KEY_ICMPV6_TYPE_MASK,/* u8 */
473+
464474
__TCA_FLOWER_MAX,
465475
};
466476

net/sched/cls_flower.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ struct fl_flow_key {
3939
struct flow_dissector_key_ipv6_addrs ipv6;
4040
};
4141
struct flow_dissector_key_ports tp;
42+
struct flow_dissector_key_icmp icmp;
4243
struct flow_dissector_key_keyid enc_key_id;
4344
union {
4445
struct flow_dissector_key_ipv4_addrs enc_ipv4;
@@ -388,6 +389,14 @@ static const struct nla_policy fl_policy[TCA_FLOWER_MAX + 1] = {
388389
[TCA_FLOWER_KEY_ENC_UDP_DST_PORT_MASK] = { .type = NLA_U16 },
389390
[TCA_FLOWER_KEY_FLAGS] = { .type = NLA_U32 },
390391
[TCA_FLOWER_KEY_FLAGS_MASK] = { .type = NLA_U32 },
392+
[TCA_FLOWER_KEY_ICMPV4_TYPE] = { .type = NLA_U8 },
393+
[TCA_FLOWER_KEY_ICMPV4_TYPE_MASK] = { .type = NLA_U8 },
394+
[TCA_FLOWER_KEY_ICMPV4_CODE] = { .type = NLA_U8 },
395+
[TCA_FLOWER_KEY_ICMPV4_CODE_MASK] = { .type = NLA_U8 },
396+
[TCA_FLOWER_KEY_ICMPV6_TYPE] = { .type = NLA_U8 },
397+
[TCA_FLOWER_KEY_ICMPV6_TYPE_MASK] = { .type = NLA_U8 },
398+
[TCA_FLOWER_KEY_ICMPV6_CODE] = { .type = NLA_U8 },
399+
[TCA_FLOWER_KEY_ICMPV6_CODE_MASK] = { .type = NLA_U8 },
391400
};
392401

393402
static void fl_set_key_val(struct nlattr **tb,
@@ -537,6 +546,26 @@ static int fl_set_key(struct net *net, struct nlattr **tb,
537546
fl_set_key_val(tb, &key->tp.dst, TCA_FLOWER_KEY_SCTP_DST,
538547
&mask->tp.dst, TCA_FLOWER_KEY_SCTP_DST_MASK,
539548
sizeof(key->tp.dst));
549+
} else if (key->basic.n_proto == htons(ETH_P_IP) &&
550+
key->basic.ip_proto == IPPROTO_ICMP) {
551+
fl_set_key_val(tb, &key->icmp.type, TCA_FLOWER_KEY_ICMPV4_TYPE,
552+
&mask->icmp.type,
553+
TCA_FLOWER_KEY_ICMPV4_TYPE_MASK,
554+
sizeof(key->icmp.type));
555+
fl_set_key_val(tb, &key->icmp.code, TCA_FLOWER_KEY_ICMPV4_CODE,
556+
&mask->icmp.code,
557+
TCA_FLOWER_KEY_ICMPV4_CODE_MASK,
558+
sizeof(key->icmp.code));
559+
} else if (key->basic.n_proto == htons(ETH_P_IPV6) &&
560+
key->basic.ip_proto == IPPROTO_ICMPV6) {
561+
fl_set_key_val(tb, &key->icmp.type, TCA_FLOWER_KEY_ICMPV6_TYPE,
562+
&mask->icmp.type,
563+
TCA_FLOWER_KEY_ICMPV6_TYPE_MASK,
564+
sizeof(key->icmp.type));
565+
fl_set_key_val(tb, &key->icmp.code, TCA_FLOWER_KEY_ICMPV4_CODE,
566+
&mask->icmp.code,
567+
TCA_FLOWER_KEY_ICMPV4_CODE_MASK,
568+
sizeof(key->icmp.code));
540569
}
541570

542571
if (tb[TCA_FLOWER_KEY_ENC_IPV4_SRC] ||
@@ -648,6 +677,8 @@ static void fl_init_dissector(struct cls_fl_head *head,
648677
FLOW_DISSECTOR_KEY_IPV6_ADDRS, ipv6);
649678
FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
650679
FLOW_DISSECTOR_KEY_PORTS, tp);
680+
FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
681+
FLOW_DISSECTOR_KEY_ICMP, icmp);
651682
FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
652683
FLOW_DISSECTOR_KEY_VLAN, vlan);
653684
FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
@@ -1050,6 +1081,28 @@ static int fl_dump(struct net *net, struct tcf_proto *tp, unsigned long fh,
10501081
&mask->tp.dst, TCA_FLOWER_KEY_SCTP_DST_MASK,
10511082
sizeof(key->tp.dst))))
10521083
goto nla_put_failure;
1084+
else if (key->basic.n_proto == htons(ETH_P_IP) &&
1085+
key->basic.ip_proto == IPPROTO_ICMP &&
1086+
(fl_dump_key_val(skb, &key->icmp.type,
1087+
TCA_FLOWER_KEY_ICMPV4_TYPE, &mask->icmp.type,
1088+
TCA_FLOWER_KEY_ICMPV4_TYPE_MASK,
1089+
sizeof(key->icmp.type)) ||
1090+
fl_dump_key_val(skb, &key->icmp.code,
1091+
TCA_FLOWER_KEY_ICMPV4_CODE, &mask->icmp.code,
1092+
TCA_FLOWER_KEY_ICMPV4_CODE_MASK,
1093+
sizeof(key->icmp.code))))
1094+
goto nla_put_failure;
1095+
else if (key->basic.n_proto == htons(ETH_P_IPV6) &&
1096+
key->basic.ip_proto == IPPROTO_ICMPV6 &&
1097+
(fl_dump_key_val(skb, &key->icmp.type,
1098+
TCA_FLOWER_KEY_ICMPV6_TYPE, &mask->icmp.type,
1099+
TCA_FLOWER_KEY_ICMPV6_TYPE_MASK,
1100+
sizeof(key->icmp.type)) ||
1101+
fl_dump_key_val(skb, &key->icmp.code,
1102+
TCA_FLOWER_KEY_ICMPV6_CODE, &mask->icmp.code,
1103+
TCA_FLOWER_KEY_ICMPV6_CODE_MASK,
1104+
sizeof(key->icmp.code))))
1105+
goto nla_put_failure;
10531106

10541107
if (key->enc_control.addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS &&
10551108
(fl_dump_key_val(skb, &key->enc_ipv4.src,

0 commit comments

Comments
 (0)