]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
net/sched: cls_flower: Support matching on ip tos and ttl for tunnels
authorOr Gerlitz <ogerlitz@mellanox.com>
Tue, 17 Jul 2018 16:27:18 +0000 (19:27 +0300)
committerDavid S. Miller <davem@davemloft.net>
Fri, 20 Jul 2018 06:26:01 +0000 (23:26 -0700)
Allow users to set rules matching on ipv4 tos and ttl or
ipv6 traffic-class and hoplimit of tunnel headers.

Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com>
Reviewed-by: Roi Dayan <roid@mellanox.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 c4262d91159650b7f649b1a0655bc1902e9b6af5..b4512254036b9658b3e0a176103a47d911579f76 100644 (file)
@@ -473,6 +473,11 @@ enum {
        TCA_FLOWER_KEY_CVLAN_PRIO,      /* u8   */
        TCA_FLOWER_KEY_CVLAN_ETH_TYPE,  /* be16 */
 
+       TCA_FLOWER_KEY_ENC_IP_TOS,      /* u8 */
+       TCA_FLOWER_KEY_ENC_IP_TOS_MASK, /* u8 */
+       TCA_FLOWER_KEY_ENC_IP_TTL,      /* u8 */
+       TCA_FLOWER_KEY_ENC_IP_TTL_MASK, /* u8 */
+
        __TCA_FLOWER_MAX,
 };
 
index c53fdd411f90def307e88ee22098313806f51e9e..38d74803e2df4f32a1cc3593c5fb0ec8ba1395a9 100644 (file)
@@ -52,6 +52,7 @@ struct fl_flow_key {
        struct flow_dissector_key_mpls mpls;
        struct flow_dissector_key_tcp tcp;
        struct flow_dissector_key_ip ip;
+       struct flow_dissector_key_ip enc_ip;
 } __aligned(BITS_PER_LONG / 8); /* Ensure that we can do comparisons as longs. */
 
 struct fl_flow_mask_range {
@@ -453,6 +454,10 @@ static const struct nla_policy fl_policy[TCA_FLOWER_MAX + 1] = {
        [TCA_FLOWER_KEY_CVLAN_ID]       = { .type = NLA_U16 },
        [TCA_FLOWER_KEY_CVLAN_PRIO]     = { .type = NLA_U8 },
        [TCA_FLOWER_KEY_CVLAN_ETH_TYPE] = { .type = NLA_U16 },
+       [TCA_FLOWER_KEY_ENC_IP_TOS]     = { .type = NLA_U8 },
+       [TCA_FLOWER_KEY_ENC_IP_TOS_MASK] = { .type = NLA_U8 },
+       [TCA_FLOWER_KEY_ENC_IP_TTL]      = { .type = NLA_U8 },
+       [TCA_FLOWER_KEY_ENC_IP_TTL_MASK] = { .type = NLA_U8 },
 };
 
 static void fl_set_key_val(struct nlattr **tb,
@@ -561,17 +566,17 @@ static int fl_set_key_flags(struct nlattr **tb,
        return 0;
 }
 
-static void fl_set_key_ip(struct nlattr **tb,
+static void fl_set_key_ip(struct nlattr **tb, bool encap,
                          struct flow_dissector_key_ip *key,
                          struct flow_dissector_key_ip *mask)
 {
-               fl_set_key_val(tb, &key->tos, TCA_FLOWER_KEY_IP_TOS,
-                              &mask->tos, TCA_FLOWER_KEY_IP_TOS_MASK,
-                              sizeof(key->tos));
+       int tos_key = encap ? TCA_FLOWER_KEY_ENC_IP_TOS : TCA_FLOWER_KEY_IP_TOS;
+       int ttl_key = encap ? TCA_FLOWER_KEY_ENC_IP_TTL : TCA_FLOWER_KEY_IP_TTL;
+       int tos_mask = encap ? TCA_FLOWER_KEY_ENC_IP_TOS_MASK : TCA_FLOWER_KEY_IP_TOS_MASK;
+       int ttl_mask = encap ? TCA_FLOWER_KEY_ENC_IP_TTL_MASK : TCA_FLOWER_KEY_IP_TTL_MASK;
 
-               fl_set_key_val(tb, &key->ttl, TCA_FLOWER_KEY_IP_TTL,
-                              &mask->ttl, TCA_FLOWER_KEY_IP_TTL_MASK,
-                              sizeof(key->ttl));
+       fl_set_key_val(tb, &key->tos, tos_key, &mask->tos, tos_mask, sizeof(key->tos));
+       fl_set_key_val(tb, &key->ttl, ttl_key, &mask->ttl, ttl_mask, sizeof(key->ttl));
 }
 
 static int fl_set_key(struct net *net, struct nlattr **tb,
@@ -633,7 +638,7 @@ static int fl_set_key(struct net *net, struct nlattr **tb,
                fl_set_key_val(tb, &key->basic.ip_proto, TCA_FLOWER_KEY_IP_PROTO,
                               &mask->basic.ip_proto, TCA_FLOWER_UNSPEC,
                               sizeof(key->basic.ip_proto));
-               fl_set_key_ip(tb, &key->ip, &mask->ip);
+               fl_set_key_ip(tb, false, &key->ip, &mask->ip);
        }
 
        if (tb[TCA_FLOWER_KEY_IPV4_SRC] || tb[TCA_FLOWER_KEY_IPV4_DST]) {
@@ -768,6 +773,8 @@ static int fl_set_key(struct net *net, struct nlattr **tb,
                       &mask->enc_tp.dst, TCA_FLOWER_KEY_ENC_UDP_DST_PORT_MASK,
                       sizeof(key->enc_tp.dst));
 
+       fl_set_key_ip(tb, true, &key->enc_ip, &mask->enc_ip);
+
        if (tb[TCA_FLOWER_KEY_FLAGS])
                ret = fl_set_key_flags(tb, &key->control.flags, &mask->control.flags);
 
@@ -860,6 +867,8 @@ static void fl_init_dissector(struct fl_flow_mask *mask)
                           enc_control);
        FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
                             FLOW_DISSECTOR_KEY_ENC_PORTS, enc_tp);
+       FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
+                            FLOW_DISSECTOR_KEY_ENC_IP, enc_ip);
 
        skb_flow_dissector_init(&mask->dissector, keys, cnt);
 }
@@ -1208,14 +1217,17 @@ static int fl_dump_key_mpls(struct sk_buff *skb,
        return 0;
 }
 
-static int fl_dump_key_ip(struct sk_buff *skb,
+static int fl_dump_key_ip(struct sk_buff *skb, bool encap,
                          struct flow_dissector_key_ip *key,
                          struct flow_dissector_key_ip *mask)
 {
-       if (fl_dump_key_val(skb, &key->tos, TCA_FLOWER_KEY_IP_TOS, &mask->tos,
-                           TCA_FLOWER_KEY_IP_TOS_MASK, sizeof(key->tos)) ||
-           fl_dump_key_val(skb, &key->ttl, TCA_FLOWER_KEY_IP_TTL, &mask->ttl,
-                           TCA_FLOWER_KEY_IP_TTL_MASK, sizeof(key->ttl)))
+       int tos_key = encap ? TCA_FLOWER_KEY_ENC_IP_TOS : TCA_FLOWER_KEY_IP_TOS;
+       int ttl_key = encap ? TCA_FLOWER_KEY_ENC_IP_TTL : TCA_FLOWER_KEY_IP_TTL;
+       int tos_mask = encap ? TCA_FLOWER_KEY_ENC_IP_TOS_MASK : TCA_FLOWER_KEY_IP_TOS_MASK;
+       int ttl_mask = encap ? TCA_FLOWER_KEY_ENC_IP_TTL_MASK : TCA_FLOWER_KEY_IP_TTL_MASK;
+
+       if (fl_dump_key_val(skb, &key->tos, tos_key, &mask->tos, tos_mask, sizeof(key->tos)) ||
+           fl_dump_key_val(skb, &key->ttl, ttl_key, &mask->ttl, ttl_mask, sizeof(key->ttl)))
                return -1;
 
        return 0;
@@ -1361,7 +1373,7 @@ static int fl_dump(struct net *net, struct tcf_proto *tp, void *fh,
            (fl_dump_key_val(skb, &key->basic.ip_proto, TCA_FLOWER_KEY_IP_PROTO,
                            &mask->basic.ip_proto, TCA_FLOWER_UNSPEC,
                            sizeof(key->basic.ip_proto)) ||
-           fl_dump_key_ip(skb, &key->ip, &mask->ip)))
+           fl_dump_key_ip(skb, false, &key->ip, &mask->ip)))
                goto nla_put_failure;
 
        if (key->control.addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS &&
@@ -1486,7 +1498,8 @@ static int fl_dump(struct net *net, struct tcf_proto *tp, void *fh,
                            TCA_FLOWER_KEY_ENC_UDP_DST_PORT,
                            &mask->enc_tp.dst,
                            TCA_FLOWER_KEY_ENC_UDP_DST_PORT_MASK,
-                           sizeof(key->enc_tp.dst)))
+                           sizeof(key->enc_tp.dst)) ||
+           fl_dump_key_ip(skb, true, &key->enc_ip, &mask->enc_ip))
                goto nla_put_failure;
 
        if (fl_dump_key_flags(skb, key->control.flags, mask->control.flags))