net/sched: cls_flower: Support matching on ip tos and ttl for tunnels
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>
This commit is contained in:

committed by
David S. Miller

parent
5544adb970
commit
0e2c17b64d
@@ -473,6 +473,11 @@ enum {
|
|||||||
TCA_FLOWER_KEY_CVLAN_PRIO, /* u8 */
|
TCA_FLOWER_KEY_CVLAN_PRIO, /* u8 */
|
||||||
TCA_FLOWER_KEY_CVLAN_ETH_TYPE, /* be16 */
|
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,
|
__TCA_FLOWER_MAX,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -52,6 +52,7 @@ struct fl_flow_key {
|
|||||||
struct flow_dissector_key_mpls mpls;
|
struct flow_dissector_key_mpls mpls;
|
||||||
struct flow_dissector_key_tcp tcp;
|
struct flow_dissector_key_tcp tcp;
|
||||||
struct flow_dissector_key_ip ip;
|
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. */
|
} __aligned(BITS_PER_LONG / 8); /* Ensure that we can do comparisons as longs. */
|
||||||
|
|
||||||
struct fl_flow_mask_range {
|
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_ID] = { .type = NLA_U16 },
|
||||||
[TCA_FLOWER_KEY_CVLAN_PRIO] = { .type = NLA_U8 },
|
[TCA_FLOWER_KEY_CVLAN_PRIO] = { .type = NLA_U8 },
|
||||||
[TCA_FLOWER_KEY_CVLAN_ETH_TYPE] = { .type = NLA_U16 },
|
[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,
|
static void fl_set_key_val(struct nlattr **tb,
|
||||||
@@ -561,17 +566,17 @@ static int fl_set_key_flags(struct nlattr **tb,
|
|||||||
return 0;
|
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 *key,
|
||||||
struct flow_dissector_key_ip *mask)
|
struct flow_dissector_key_ip *mask)
|
||||||
{
|
{
|
||||||
fl_set_key_val(tb, &key->tos, TCA_FLOWER_KEY_IP_TOS,
|
int tos_key = encap ? TCA_FLOWER_KEY_ENC_IP_TOS : TCA_FLOWER_KEY_IP_TOS;
|
||||||
&mask->tos, TCA_FLOWER_KEY_IP_TOS_MASK,
|
int ttl_key = encap ? TCA_FLOWER_KEY_ENC_IP_TTL : TCA_FLOWER_KEY_IP_TTL;
|
||||||
sizeof(key->tos));
|
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,
|
fl_set_key_val(tb, &key->tos, tos_key, &mask->tos, tos_mask, sizeof(key->tos));
|
||||||
&mask->ttl, TCA_FLOWER_KEY_IP_TTL_MASK,
|
fl_set_key_val(tb, &key->ttl, ttl_key, &mask->ttl, ttl_mask, sizeof(key->ttl));
|
||||||
sizeof(key->ttl));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fl_set_key(struct net *net, struct nlattr **tb,
|
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,
|
fl_set_key_val(tb, &key->basic.ip_proto, TCA_FLOWER_KEY_IP_PROTO,
|
||||||
&mask->basic.ip_proto, TCA_FLOWER_UNSPEC,
|
&mask->basic.ip_proto, TCA_FLOWER_UNSPEC,
|
||||||
sizeof(key->basic.ip_proto));
|
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]) {
|
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,
|
&mask->enc_tp.dst, TCA_FLOWER_KEY_ENC_UDP_DST_PORT_MASK,
|
||||||
sizeof(key->enc_tp.dst));
|
sizeof(key->enc_tp.dst));
|
||||||
|
|
||||||
|
fl_set_key_ip(tb, true, &key->enc_ip, &mask->enc_ip);
|
||||||
|
|
||||||
if (tb[TCA_FLOWER_KEY_FLAGS])
|
if (tb[TCA_FLOWER_KEY_FLAGS])
|
||||||
ret = fl_set_key_flags(tb, &key->control.flags, &mask->control.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);
|
enc_control);
|
||||||
FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
|
FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
|
||||||
FLOW_DISSECTOR_KEY_ENC_PORTS, enc_tp);
|
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);
|
skb_flow_dissector_init(&mask->dissector, keys, cnt);
|
||||||
}
|
}
|
||||||
@@ -1208,14 +1217,17 @@ static int fl_dump_key_mpls(struct sk_buff *skb,
|
|||||||
return 0;
|
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 *key,
|
||||||
struct flow_dissector_key_ip *mask)
|
struct flow_dissector_key_ip *mask)
|
||||||
{
|
{
|
||||||
if (fl_dump_key_val(skb, &key->tos, TCA_FLOWER_KEY_IP_TOS, &mask->tos,
|
int tos_key = encap ? TCA_FLOWER_KEY_ENC_IP_TOS : TCA_FLOWER_KEY_IP_TOS;
|
||||||
TCA_FLOWER_KEY_IP_TOS_MASK, sizeof(key->tos)) ||
|
int ttl_key = encap ? TCA_FLOWER_KEY_ENC_IP_TTL : TCA_FLOWER_KEY_IP_TTL;
|
||||||
fl_dump_key_val(skb, &key->ttl, TCA_FLOWER_KEY_IP_TTL, &mask->ttl,
|
int tos_mask = encap ? TCA_FLOWER_KEY_ENC_IP_TOS_MASK : TCA_FLOWER_KEY_IP_TOS_MASK;
|
||||||
TCA_FLOWER_KEY_IP_TTL_MASK, sizeof(key->ttl)))
|
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 -1;
|
||||||
|
|
||||||
return 0;
|
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,
|
(fl_dump_key_val(skb, &key->basic.ip_proto, TCA_FLOWER_KEY_IP_PROTO,
|
||||||
&mask->basic.ip_proto, TCA_FLOWER_UNSPEC,
|
&mask->basic.ip_proto, TCA_FLOWER_UNSPEC,
|
||||||
sizeof(key->basic.ip_proto)) ||
|
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;
|
goto nla_put_failure;
|
||||||
|
|
||||||
if (key->control.addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS &&
|
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,
|
TCA_FLOWER_KEY_ENC_UDP_DST_PORT,
|
||||||
&mask->enc_tp.dst,
|
&mask->enc_tp.dst,
|
||||||
TCA_FLOWER_KEY_ENC_UDP_DST_PORT_MASK,
|
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;
|
goto nla_put_failure;
|
||||||
|
|
||||||
if (fl_dump_key_flags(skb, key->control.flags, mask->control.flags))
|
if (fl_dump_key_flags(skb, key->control.flags, mask->control.flags))
|
||||||
|
Reference in New Issue
Block a user