net/sched: cls_flower: Support matching on SCTP ports
authorSimon Horman <simon.horman@netronome.com>
Thu, 3 Nov 2016 12:24:21 +0000 (13:24 +0100)
committerDavid S. Miller <davem@davemloft.net>
Thu, 3 Nov 2016 20:26:39 +0000 (16:26 -0400)
Support matching on SCTP ports in the same way that matching
on TCP and UDP ports is already supported.

Example usage:

tc qdisc add dev eth0 ingress

tc filter add dev eth0 protocol ip parent ffff: \
        flower indev eth0 ip_proto sctp dst_port 80 \
        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>
include/uapi/linux/pkt_cls.h
net/sched/cls_flower.c

index 8fd715f806a27f327051d48a8e6b4ab8656c9703..eb94781757eeca1b8d44bb6170bbadc6a1af4855 100644 (file)
@@ -447,6 +447,11 @@ enum {
        TCA_FLOWER_KEY_TCP_DST_MASK,    /* be16 */
        TCA_FLOWER_KEY_UDP_SRC_MASK,    /* be16 */
        TCA_FLOWER_KEY_UDP_DST_MASK,    /* be16 */
+       TCA_FLOWER_KEY_SCTP_SRC_MASK,   /* be16 */
+       TCA_FLOWER_KEY_SCTP_DST_MASK,   /* be16 */
+
+       TCA_FLOWER_KEY_SCTP_SRC,        /* be16 */
+       TCA_FLOWER_KEY_SCTP_DST,        /* be16 */
        __TCA_FLOWER_MAX,
 };
 
index a8fb1ca03b3ea513a2822621db1e03aff92695b6..db4cd882a989c5196aede640d14ce009cb2c2cf6 100644 (file)
@@ -344,6 +344,10 @@ static const struct nla_policy fl_policy[TCA_FLOWER_MAX + 1] = {
        [TCA_FLOWER_KEY_TCP_DST_MASK]   = { .type = NLA_U16 },
        [TCA_FLOWER_KEY_UDP_SRC_MASK]   = { .type = NLA_U16 },
        [TCA_FLOWER_KEY_UDP_DST_MASK]   = { .type = NLA_U16 },
+       [TCA_FLOWER_KEY_SCTP_SRC_MASK]  = { .type = NLA_U16 },
+       [TCA_FLOWER_KEY_SCTP_DST_MASK]  = { .type = NLA_U16 },
+       [TCA_FLOWER_KEY_SCTP_SRC]       = { .type = NLA_U16 },
+       [TCA_FLOWER_KEY_SCTP_DST]       = { .type = NLA_U16 },
 };
 
 static void fl_set_key_val(struct nlattr **tb,
@@ -453,6 +457,13 @@ static int fl_set_key(struct net *net, struct nlattr **tb,
                fl_set_key_val(tb, &key->tp.dst, TCA_FLOWER_KEY_UDP_DST,
                               &mask->tp.dst, TCA_FLOWER_KEY_UDP_DST_MASK,
                               sizeof(key->tp.dst));
+       } else if (key->basic.ip_proto == IPPROTO_SCTP) {
+               fl_set_key_val(tb, &key->tp.src, TCA_FLOWER_KEY_SCTP_SRC,
+                              &mask->tp.src, TCA_FLOWER_KEY_SCTP_SRC_MASK,
+                              sizeof(key->tp.src));
+               fl_set_key_val(tb, &key->tp.dst, TCA_FLOWER_KEY_SCTP_DST,
+                              &mask->tp.dst, TCA_FLOWER_KEY_SCTP_DST_MASK,
+                              sizeof(key->tp.dst));
        }
 
        if (tb[TCA_FLOWER_KEY_ENC_IPV4_SRC] ||
@@ -897,6 +908,14 @@ static int fl_dump(struct net *net, struct tcf_proto *tp, unsigned long fh,
                                  &mask->tp.dst, TCA_FLOWER_KEY_UDP_DST_MASK,
                                  sizeof(key->tp.dst))))
                goto nla_put_failure;
+       else if (key->basic.ip_proto == IPPROTO_SCTP &&
+                (fl_dump_key_val(skb, &key->tp.src, TCA_FLOWER_KEY_SCTP_SRC,
+                                 &mask->tp.src, TCA_FLOWER_KEY_SCTP_SRC_MASK,
+                                 sizeof(key->tp.src)) ||
+                 fl_dump_key_val(skb, &key->tp.dst, TCA_FLOWER_KEY_SCTP_DST,
+                                 &mask->tp.dst, TCA_FLOWER_KEY_SCTP_DST_MASK,
+                                 sizeof(key->tp.dst))))
+               goto nla_put_failure;
 
        if (key->enc_control.addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS &&
            (fl_dump_key_val(skb, &key->enc_ipv4.src,