Commit 4af4f7e8 authored by David S. Miller's avatar David S. Miller

Merge branch 'Introduce-matching-on-double-vlan-QinQ-headers-for-TC-flower'

Jianbo Liu says:

====================
Introduce matching on double vlan/QinQ headers for TC flower

Currently TC flower supports only one vlan tag, it doesn't match on both outer
and inner vlan headers for QinQ. To do this, we add support to get both outer
and inner vlan headers for flow dissector, and then TC flower do matching on
those information.

We also plan to extend TC command to support this feature. We add new
cvlan_id/cvlan_prio/cvlan_ethtype keywords for inner vlan header. The existing
vlan_id/vlan_prio/vlan_ethtype are for outer vlan header, and vlan_ethtype must
be 802.1q or 802.1ad.

The examples for command and output are as the following.
        flower vlan_id 1000 vlan_ethtype 802.1q \
        cvlan_id 100 cvlan_ethtype ipv4 \
        action vlan pop \
        action vlan pop \
        action mirred egress redirect dev ens1f1_0

filter protocol 802.1ad pref 33 flower chain 0
filter protocol 802.1ad pref 33 flower chain 0 handle 0x1
  vlan_id 1000
  vlan_ethtype 802.1Q
  cvlan_id 100
  cvlan_ethtype ip
  eth_type ipv4
  in_hw
    ...

v2:
  fix sparse warning.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 94c76351 d64efd09
...@@ -47,7 +47,7 @@ struct flow_dissector_key_tags { ...@@ -47,7 +47,7 @@ struct flow_dissector_key_tags {
struct flow_dissector_key_vlan { struct flow_dissector_key_vlan {
u16 vlan_id:12, u16 vlan_id:12,
vlan_priority:3; vlan_priority:3;
u16 padding; __be16 vlan_tpid;
}; };
struct flow_dissector_key_mpls { struct flow_dissector_key_mpls {
...@@ -206,6 +206,7 @@ enum flow_dissector_key_id { ...@@ -206,6 +206,7 @@ enum flow_dissector_key_id {
FLOW_DISSECTOR_KEY_MPLS, /* struct flow_dissector_key_mpls */ FLOW_DISSECTOR_KEY_MPLS, /* struct flow_dissector_key_mpls */
FLOW_DISSECTOR_KEY_TCP, /* struct flow_dissector_key_tcp */ FLOW_DISSECTOR_KEY_TCP, /* struct flow_dissector_key_tcp */
FLOW_DISSECTOR_KEY_IP, /* struct flow_dissector_key_ip */ FLOW_DISSECTOR_KEY_IP, /* struct flow_dissector_key_ip */
FLOW_DISSECTOR_KEY_CVLAN, /* struct flow_dissector_key_flow_vlan */
FLOW_DISSECTOR_KEY_MAX, FLOW_DISSECTOR_KEY_MAX,
}; };
...@@ -237,6 +238,7 @@ struct flow_keys { ...@@ -237,6 +238,7 @@ struct flow_keys {
struct flow_dissector_key_basic basic; struct flow_dissector_key_basic basic;
struct flow_dissector_key_tags tags; struct flow_dissector_key_tags tags;
struct flow_dissector_key_vlan vlan; struct flow_dissector_key_vlan vlan;
struct flow_dissector_key_vlan cvlan;
struct flow_dissector_key_keyid keyid; struct flow_dissector_key_keyid keyid;
struct flow_dissector_key_ports ports; struct flow_dissector_key_ports ports;
struct flow_dissector_key_addrs addrs; struct flow_dissector_key_addrs addrs;
......
...@@ -469,6 +469,10 @@ enum { ...@@ -469,6 +469,10 @@ enum {
TCA_FLOWER_KEY_IP_TTL, /* u8 */ TCA_FLOWER_KEY_IP_TTL, /* u8 */
TCA_FLOWER_KEY_IP_TTL_MASK, /* u8 */ TCA_FLOWER_KEY_IP_TTL_MASK, /* u8 */
TCA_FLOWER_KEY_CVLAN_ID, /* be16 */
TCA_FLOWER_KEY_CVLAN_PRIO, /* u8 */
TCA_FLOWER_KEY_CVLAN_ETH_TYPE, /* be16 */
__TCA_FLOWER_MAX, __TCA_FLOWER_MAX,
}; };
......
...@@ -589,7 +589,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb, ...@@ -589,7 +589,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
struct flow_dissector_key_tags *key_tags; struct flow_dissector_key_tags *key_tags;
struct flow_dissector_key_vlan *key_vlan; struct flow_dissector_key_vlan *key_vlan;
enum flow_dissect_ret fdret; enum flow_dissect_ret fdret;
bool skip_vlan = false; enum flow_dissector_key_id dissector_vlan = FLOW_DISSECTOR_KEY_MAX;
int num_hdrs = 0; int num_hdrs = 0;
u8 ip_proto = 0; u8 ip_proto = 0;
bool ret; bool ret;
...@@ -748,14 +748,14 @@ bool __skb_flow_dissect(const struct sk_buff *skb, ...@@ -748,14 +748,14 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
} }
case htons(ETH_P_8021AD): case htons(ETH_P_8021AD):
case htons(ETH_P_8021Q): { case htons(ETH_P_8021Q): {
const struct vlan_hdr *vlan; const struct vlan_hdr *vlan = NULL;
struct vlan_hdr _vlan; struct vlan_hdr _vlan;
bool vlan_tag_present = skb && skb_vlan_tag_present(skb); __be16 saved_vlan_tpid = proto;
if (vlan_tag_present) if (dissector_vlan == FLOW_DISSECTOR_KEY_MAX &&
skb && skb_vlan_tag_present(skb)) {
proto = skb->protocol; proto = skb->protocol;
} else {
if (!vlan_tag_present || eth_type_vlan(skb->protocol)) {
vlan = __skb_header_pointer(skb, nhoff, sizeof(_vlan), vlan = __skb_header_pointer(skb, nhoff, sizeof(_vlan),
data, hlen, &_vlan); data, hlen, &_vlan);
if (!vlan) { if (!vlan) {
...@@ -765,20 +765,23 @@ bool __skb_flow_dissect(const struct sk_buff *skb, ...@@ -765,20 +765,23 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
proto = vlan->h_vlan_encapsulated_proto; proto = vlan->h_vlan_encapsulated_proto;
nhoff += sizeof(*vlan); nhoff += sizeof(*vlan);
if (skip_vlan) { }
if (dissector_vlan == FLOW_DISSECTOR_KEY_MAX) {
dissector_vlan = FLOW_DISSECTOR_KEY_VLAN;
} else if (dissector_vlan == FLOW_DISSECTOR_KEY_VLAN) {
dissector_vlan = FLOW_DISSECTOR_KEY_CVLAN;
} else {
fdret = FLOW_DISSECT_RET_PROTO_AGAIN; fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
break; break;
} }
}
skip_vlan = true; if (dissector_uses_key(flow_dissector, dissector_vlan)) {
if (dissector_uses_key(flow_dissector,
FLOW_DISSECTOR_KEY_VLAN)) {
key_vlan = skb_flow_dissector_target(flow_dissector, key_vlan = skb_flow_dissector_target(flow_dissector,
FLOW_DISSECTOR_KEY_VLAN, dissector_vlan,
target_container); target_container);
if (vlan_tag_present) { if (!vlan) {
key_vlan->vlan_id = skb_vlan_tag_get_id(skb); key_vlan->vlan_id = skb_vlan_tag_get_id(skb);
key_vlan->vlan_priority = key_vlan->vlan_priority =
(skb_vlan_tag_get_prio(skb) >> VLAN_PRIO_SHIFT); (skb_vlan_tag_get_prio(skb) >> VLAN_PRIO_SHIFT);
...@@ -789,6 +792,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb, ...@@ -789,6 +792,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
(ntohs(vlan->h_vlan_TCI) & (ntohs(vlan->h_vlan_TCI) &
VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT; VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
} }
key_vlan->vlan_tpid = saved_vlan_tpid;
} }
fdret = FLOW_DISSECT_RET_PROTO_AGAIN; fdret = FLOW_DISSECT_RET_PROTO_AGAIN;
......
...@@ -35,6 +35,7 @@ struct fl_flow_key { ...@@ -35,6 +35,7 @@ struct fl_flow_key {
struct flow_dissector_key_basic basic; struct flow_dissector_key_basic basic;
struct flow_dissector_key_eth_addrs eth; struct flow_dissector_key_eth_addrs eth;
struct flow_dissector_key_vlan vlan; struct flow_dissector_key_vlan vlan;
struct flow_dissector_key_vlan cvlan;
union { union {
struct flow_dissector_key_ipv4_addrs ipv4; struct flow_dissector_key_ipv4_addrs ipv4;
struct flow_dissector_key_ipv6_addrs ipv6; struct flow_dissector_key_ipv6_addrs ipv6;
...@@ -449,6 +450,9 @@ static const struct nla_policy fl_policy[TCA_FLOWER_MAX + 1] = { ...@@ -449,6 +450,9 @@ static const struct nla_policy fl_policy[TCA_FLOWER_MAX + 1] = {
[TCA_FLOWER_KEY_IP_TOS_MASK] = { .type = NLA_U8 }, [TCA_FLOWER_KEY_IP_TOS_MASK] = { .type = NLA_U8 },
[TCA_FLOWER_KEY_IP_TTL] = { .type = NLA_U8 }, [TCA_FLOWER_KEY_IP_TTL] = { .type = NLA_U8 },
[TCA_FLOWER_KEY_IP_TTL_MASK] = { .type = NLA_U8 }, [TCA_FLOWER_KEY_IP_TTL_MASK] = { .type = NLA_U8 },
[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 },
}; };
static void fl_set_key_val(struct nlattr **tb, static void fl_set_key_val(struct nlattr **tb,
...@@ -500,22 +504,26 @@ static int fl_set_key_mpls(struct nlattr **tb, ...@@ -500,22 +504,26 @@ static int fl_set_key_mpls(struct nlattr **tb,
} }
static void fl_set_key_vlan(struct nlattr **tb, static void fl_set_key_vlan(struct nlattr **tb,
__be16 ethertype,
int vlan_id_key, int vlan_prio_key,
struct flow_dissector_key_vlan *key_val, struct flow_dissector_key_vlan *key_val,
struct flow_dissector_key_vlan *key_mask) struct flow_dissector_key_vlan *key_mask)
{ {
#define VLAN_PRIORITY_MASK 0x7 #define VLAN_PRIORITY_MASK 0x7
if (tb[TCA_FLOWER_KEY_VLAN_ID]) { if (tb[vlan_id_key]) {
key_val->vlan_id = key_val->vlan_id =
nla_get_u16(tb[TCA_FLOWER_KEY_VLAN_ID]) & VLAN_VID_MASK; nla_get_u16(tb[vlan_id_key]) & VLAN_VID_MASK;
key_mask->vlan_id = VLAN_VID_MASK; key_mask->vlan_id = VLAN_VID_MASK;
} }
if (tb[TCA_FLOWER_KEY_VLAN_PRIO]) { if (tb[vlan_prio_key]) {
key_val->vlan_priority = key_val->vlan_priority =
nla_get_u8(tb[TCA_FLOWER_KEY_VLAN_PRIO]) & nla_get_u8(tb[vlan_prio_key]) &
VLAN_PRIORITY_MASK; VLAN_PRIORITY_MASK;
key_mask->vlan_priority = VLAN_PRIORITY_MASK; key_mask->vlan_priority = VLAN_PRIORITY_MASK;
} }
key_val->vlan_tpid = ethertype;
key_mask->vlan_tpid = cpu_to_be16(~0);
} }
static void fl_set_key_flag(u32 flower_key, u32 flower_mask, static void fl_set_key_flag(u32 flower_key, u32 flower_mask,
...@@ -592,16 +600,30 @@ static int fl_set_key(struct net *net, struct nlattr **tb, ...@@ -592,16 +600,30 @@ static int fl_set_key(struct net *net, struct nlattr **tb,
if (tb[TCA_FLOWER_KEY_ETH_TYPE]) { if (tb[TCA_FLOWER_KEY_ETH_TYPE]) {
ethertype = nla_get_be16(tb[TCA_FLOWER_KEY_ETH_TYPE]); ethertype = nla_get_be16(tb[TCA_FLOWER_KEY_ETH_TYPE]);
if (ethertype == htons(ETH_P_8021Q)) { if (eth_type_vlan(ethertype)) {
fl_set_key_vlan(tb, &key->vlan, &mask->vlan); fl_set_key_vlan(tb, ethertype, TCA_FLOWER_KEY_VLAN_ID,
TCA_FLOWER_KEY_VLAN_PRIO, &key->vlan,
&mask->vlan);
ethertype = nla_get_be16(tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE]);
if (eth_type_vlan(ethertype)) {
fl_set_key_vlan(tb, ethertype,
TCA_FLOWER_KEY_CVLAN_ID,
TCA_FLOWER_KEY_CVLAN_PRIO,
&key->cvlan, &mask->cvlan);
fl_set_key_val(tb, &key->basic.n_proto, fl_set_key_val(tb, &key->basic.n_proto,
TCA_FLOWER_KEY_VLAN_ETH_TYPE, TCA_FLOWER_KEY_CVLAN_ETH_TYPE,
&mask->basic.n_proto, TCA_FLOWER_UNSPEC, &mask->basic.n_proto,
TCA_FLOWER_UNSPEC,
sizeof(key->basic.n_proto)); sizeof(key->basic.n_proto));
} else { } else {
key->basic.n_proto = ethertype; key->basic.n_proto = ethertype;
mask->basic.n_proto = cpu_to_be16(~0); mask->basic.n_proto = cpu_to_be16(~0);
} }
} else {
key->basic.n_proto = ethertype;
mask->basic.n_proto = cpu_to_be16(~0);
}
} }
if (key->basic.n_proto == htons(ETH_P_IP) || if (key->basic.n_proto == htons(ETH_P_IP) ||
...@@ -822,6 +844,8 @@ static void fl_init_dissector(struct fl_flow_mask *mask) ...@@ -822,6 +844,8 @@ static void fl_init_dissector(struct fl_flow_mask *mask)
FLOW_DISSECTOR_KEY_MPLS, mpls); FLOW_DISSECTOR_KEY_MPLS, mpls);
FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt, FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
FLOW_DISSECTOR_KEY_VLAN, vlan); FLOW_DISSECTOR_KEY_VLAN, vlan);
FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
FLOW_DISSECTOR_KEY_CVLAN, cvlan);
FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt, FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
FLOW_DISSECTOR_KEY_ENC_KEYID, enc_key_id); FLOW_DISSECTOR_KEY_ENC_KEYID, enc_key_id);
FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt, FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
...@@ -1198,6 +1222,7 @@ static int fl_dump_key_ip(struct sk_buff *skb, ...@@ -1198,6 +1222,7 @@ static int fl_dump_key_ip(struct sk_buff *skb,
} }
static int fl_dump_key_vlan(struct sk_buff *skb, static int fl_dump_key_vlan(struct sk_buff *skb,
int vlan_id_key, int vlan_prio_key,
struct flow_dissector_key_vlan *vlan_key, struct flow_dissector_key_vlan *vlan_key,
struct flow_dissector_key_vlan *vlan_mask) struct flow_dissector_key_vlan *vlan_mask)
{ {
...@@ -1206,13 +1231,13 @@ static int fl_dump_key_vlan(struct sk_buff *skb, ...@@ -1206,13 +1231,13 @@ static int fl_dump_key_vlan(struct sk_buff *skb,
if (!memchr_inv(vlan_mask, 0, sizeof(*vlan_mask))) if (!memchr_inv(vlan_mask, 0, sizeof(*vlan_mask)))
return 0; return 0;
if (vlan_mask->vlan_id) { if (vlan_mask->vlan_id) {
err = nla_put_u16(skb, TCA_FLOWER_KEY_VLAN_ID, err = nla_put_u16(skb, vlan_id_key,
vlan_key->vlan_id); vlan_key->vlan_id);
if (err) if (err)
return err; return err;
} }
if (vlan_mask->vlan_priority) { if (vlan_mask->vlan_priority) {
err = nla_put_u8(skb, TCA_FLOWER_KEY_VLAN_PRIO, err = nla_put_u8(skb, vlan_prio_key,
vlan_key->vlan_priority); vlan_key->vlan_priority);
if (err) if (err)
return err; return err;
...@@ -1307,9 +1332,28 @@ static int fl_dump(struct net *net, struct tcf_proto *tp, void *fh, ...@@ -1307,9 +1332,28 @@ static int fl_dump(struct net *net, struct tcf_proto *tp, void *fh,
if (fl_dump_key_mpls(skb, &key->mpls, &mask->mpls)) if (fl_dump_key_mpls(skb, &key->mpls, &mask->mpls))
goto nla_put_failure; goto nla_put_failure;
if (fl_dump_key_vlan(skb, &key->vlan, &mask->vlan)) if (fl_dump_key_vlan(skb, TCA_FLOWER_KEY_VLAN_ID,
TCA_FLOWER_KEY_VLAN_PRIO, &key->vlan, &mask->vlan))
goto nla_put_failure; goto nla_put_failure;
if (fl_dump_key_vlan(skb, TCA_FLOWER_KEY_CVLAN_ID,
TCA_FLOWER_KEY_CVLAN_PRIO,
&key->cvlan, &mask->cvlan) ||
(mask->cvlan.vlan_tpid &&
nla_put_u16(skb, TCA_FLOWER_KEY_VLAN_ETH_TYPE,
key->cvlan.vlan_tpid)))
goto nla_put_failure;
if (mask->cvlan.vlan_tpid) {
if (nla_put_be16(skb, TCA_FLOWER_KEY_CVLAN_ETH_TYPE,
key->basic.n_proto))
goto nla_put_failure;
} else if (mask->vlan.vlan_tpid) {
if (nla_put_be16(skb, TCA_FLOWER_KEY_VLAN_ETH_TYPE,
key->basic.n_proto))
goto nla_put_failure;
}
if ((key->basic.n_proto == htons(ETH_P_IP) || if ((key->basic.n_proto == htons(ETH_P_IP) ||
key->basic.n_proto == htons(ETH_P_IPV6)) && key->basic.n_proto == htons(ETH_P_IPV6)) &&
(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,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment