Skip to contentSkip to conversation

openvswitch: Add support for 802.1AD

PATCH Superseded Thomas F Herbert 3 participants 8 messages Apr 28, 2015 – May 6, 2015

Subsystems (3)

v7 of 14 Superseded Latest is v14 →

lore
Share & tools
lore
#0 lore raw

v7 cover openvswitch: Add support for 802.1AD

Add support for 802.1AD to the openvswitch kernel module.

Although the Open Flow specification specified support for 802.1AD (qinq) as well as push and pop vlan headers, So far Open vSwitch has only supported a single tag header.

This accompanies version 7 of the patch submitted to openvswitch dev list.

For discussion, history and previous versions, of the kernel patch, see the OVS dev mailing list, openvswitch.org/pipermail/dev/..

Thomas F Herbert (2):
add flow key field for ctag
Flow handling, actions, and vlan parsing for 8021AD

 include/uapi/linux/openvswitch.h | 17 ++++----
 net/openvswitch/actions.c        |  6 ++-
 net/openvswitch/flow.c           | 83 +++++++++++++++++++++++++++++++++-------
 net/openvswitch/flow.h           |  1 +
 net/openvswitch/flow_netlink.c   | 81 ++++++++++++++++++++++++++++++++++++---
 5 files changed, 160 insertions(+), 28 deletions(-)
Signature · 1 line
2.1.0
#1 lore raw

PATCH v7 1/2 openvswitch: 802.1ad uapi changes.

openvswitch: Add support for 8021.AD

Change the description of the VLAN tpid field.

---
 include/uapi/linux/openvswitch.h | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
include/uapi/linux/openvswitch.h +9 -8
index bbd49a0..f2ccdef 100644
@@ -559,13 +559,13 @@ struct ovs_action_push_mpls {
  * @vlan_tci: Tag control identifier (TCI) to push.  The CFI bit must be set
  * (but it will not be set in the 802.1Q header that is pushed).
  *
- * The @vlan_tpid value is typically %ETH_P_8021Q.  The only acceptable TPID
- * values are those that the kernel module also parses as 802.1Q headers, to
- * prevent %OVS_ACTION_ATTR_PUSH_VLAN followed by %OVS_ACTION_ATTR_POP_VLAN
- * from having surprising results.
+ * The @vlan_tpid value is typically %ETH_P_8021Q or %ETH_P_8021AD.
+ * The only acceptable TPID values are those that the kernel module also parses
+ * as 802.1Q or 802.1AD headers, to prevent %OVS_ACTION_ATTR_PUSH_VLAN followed
+ * by %OVS_ACTION_ATTR_POP_VLAN from having surprising results.
  */
 struct ovs_action_push_vlan {
-	__be16 vlan_tpid;	/* 802.1Q TPID. */
+	__be16 vlan_tpid;	/* 802.1Q or 802.1ad TPID. */
 	__be16 vlan_tci;	/* 802.1Q TCI (VLAN ID and priority). */
 };
 
@@ -605,9 +605,10 @@ struct ovs_action_hash {
  * is copied from the value to the packet header field, rest of the bits are
  * left unchanged.  The non-masked value bits must be passed in as zeroes.
  * Masking is not supported for the %OVS_KEY_ATTR_TUNNEL attribute.
- * @OVS_ACTION_ATTR_PUSH_VLAN: Push a new outermost 802.1Q header onto the
- * packet.
- * @OVS_ACTION_ATTR_POP_VLAN: Pop the outermost 802.1Q header off the packet.
+ * @OVS_ACTION_ATTR_PUSH_VLAN: Push a new outermost 802.1Q or 802.1ad header
+ * onto the packet.
+ * @OVS_ACTION_ATTR_POP_VLAN: Pop the outermost 802.1Q or 802.1ad header
+ * from the packet.
  * @OVS_ACTION_ATTR_SAMPLE: Probabilitically executes actions, as specified in
  * the nested %OVS_SAMPLE_ATTR_* attributes.
  * @OVS_ACTION_ATTR_PUSH_MPLS: Push a new MPLS label stack entry onto the
Signature · 1 line
2.1.0
#2 lore raw

PATCH v7 2/2 openvswitch: 802.1ad: Flow handling, actions, and vlan parsing

In reply to Thomas F Herbert

Add support for 802.1ad including the ability to push and pop double tagged vlans.

---
 net/openvswitch/actions.c      |  6 ++-
 net/openvswitch/flow.c         | 83 +++++++++++++++++++++++++++++++++++-------
 net/openvswitch/flow.h         |  1 +
 net/openvswitch/flow_netlink.c | 81 ++++++++++++++++++++++++++++++++++++++---
 4 files changed, 151 insertions(+), 20 deletions(-)
net/openvswitch/actions.c +4 -2
index b491c1c..0831019 100644
@@ -219,7 +219,8 @@ static int pop_vlan(struct sk_buff *skb, struct sw_flow_key *key)
 	int err;
 
 	err = skb_vlan_pop(skb);
-	if (skb_vlan_tag_present(skb))
+	if (skb_vlan_tag_present(skb) &&
+	    skb->protocol != htons(ETH_P_8021Q))
 		invalidate_flow_key(key);
 	else
 		key->eth.tci = 0;
@@ -229,7 +230,8 @@ static int pop_vlan(struct sk_buff *skb, struct sw_flow_key *key)
 static int push_vlan(struct sk_buff *skb, struct sw_flow_key *key,
 		     const struct ovs_action_push_vlan *vlan)
 {
-	if (skb_vlan_tag_present(skb))
+	if (skb_vlan_tag_present(skb) &&
+	    skb->protocol != htons(ETH_P_8021Q))
 		invalidate_flow_key(key);
 	else
 		key->eth.tci = vlan->vlan_tci;
net/openvswitch/flow.c +70 -13

100 lines not on this page · raw message

net/openvswitch/flow.h +1 -0
index a076e44..1057de6 100644
@@ -134,6 +134,7 @@ struct sw_flow_key {
 		u8     src[ETH_ALEN];	/* Ethernet source address. */
 		u8     dst[ETH_ALEN];	/* Ethernet destination address. */
 		__be16 tci;		/* 0 if no VLAN, VLAN_TAG_PRESENT set otherwise. */
+		__be16 ctci;		/* 0 if no CVLAN, VLAN_TAG_PRESENT set otherwise. */
 		__be16 type;		/* Ethernet frame type. */
 	} eth;
 	union {
net/openvswitch/flow_netlink.c +76 -5

129 lines not on this page · raw message

Signature · 1 line
2.1.0
#3 lore raw

Re: [PATCH net-next V7 2/2] openvswitch: 802.1ad: Flow handling, actions, and vlan parsing

Quoted 3 lines · Thomas F Herbert

Add support for 802.1ad including the ability to push and pop double tagged vlans.

I saw multiple checkpatch.pl errors and warning.

Quoted 1 line

...

Quoted 18 lines
net/openvswitch/flow.c +3 -4
index 2dacc7b..6989451 100644
@@ -298,21 +298,78 @@ static bool icmp6hdr_ok(struct sk_buff *skb)
 static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key)
 {
        struct qtag_prefix {
-               __be16 eth_type; /* ETH_P_8021Q */
+               __be16 eth_type; /* ETH_P_8021Q  or ETH_P_8021AD */
                __be16 tci;
        };
-       struct qtag_prefix *qp;
+       struct qtag_prefix *qp = (struct qtag_prefix *) skb->data;
 
-       if (unlikely(skb->len < sizeof(struct qtag_prefix) + sizeof(__be16)))
-               return 0;
+       struct qinqtag_prefix {

net/openvswitch/flow.c static bool icmp6hdr_ok(struct sk_buff *skb) · line 316

Quoted 10 lines
net/openvswitch/flow.c +10 -0
+               __be16 eth_type; /* ETH_P_8021Q  or ETH_P_8021AD */
+               __be16 tci;
+               __be16 inner_tpid; /* ETH_P_8021Q */
+               __be16 ctci;
+       };
+
+       if (likely(skb_vlan_tag_present(skb))) {
+
+               key->eth.tci = htons(skb->vlan_tci);
+

I think there is bug in existing OVS where it does not check vlan_proto before populating the flow key. Can you send a separate patch to fix this issue?.

net/openvswitch/flow.c static bool icmp6hdr_ok(struct sk_buff *skb) · line 326

Quoted 10 lines
net/openvswitch/flow.c +10 -0
+               /*
+                * Case where upstream
+                * processing has already stripped the outer vlan tag.
+                */
+               if (unlikely(skb->vlan_proto == htons(ETH_P_8021AD))) {
+
+                       if (unlikely(skb->len < sizeof(struct qtag_prefix) +
+                                       sizeof(__be16)))
+                               return 0;
+

If this returns from here then it can match on flow with tci which expect vlan_proto to be 8021Q but with vlan_proto equal to 8021AD.

Quoted 13 lines
net/openvswitch/flow.c +12 -0
+                       if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
+                                       sizeof(__be16)))) {
+                               return -ENOMEM;
+                       }
+
+                       if (likely(qp->eth_type == htons(ETH_P_8021Q))) {
+                               key->eth.ctci = qp->tci | htons(VLAN_TAG_PRESENT);
+                               __skb_pull(skb, sizeof(struct qtag_prefix));
+                       }
+               }
+                return 0;
+       }
 

...

net/openvswitch/flow.c int ovs_nla_get_match(struct sw_flow_match *match, · line 1104

Quoted 10 lines
net/openvswitch/flow.c +3 -3
@@ -1074,9 +1099,28 @@ int ovs_nla_get_match(struct sw_flow_match *match,
                encap_valid = true;
 
                if (tci & htons(VLAN_TAG_PRESENT)) {
-                       err = parse_flow_nlattrs(encap, a, &key_attrs, log);
-                       if (err)
-                               return err;
+
+                       if (unlikely((nla_get_be16(a[OVS_KEY_ATTR_ETHERTYPE]) ==
+                           htons(ETH_P_8021AD)))) {

Incorrect alignment.

net/openvswitch/flow.c int ovs_nla_get_match(struct sw_flow_match *match, · line 1109

Quoted 5 lines
net/openvswitch/flow.c +5 -0
+
+                               err = parse_flow_nlattrs(encap, a, &v_attrs, log);
+                               if (err)
+                                       return err;
+                               if (v_attrs) {

v_attrs can to be defined in inner block where is actually used.

...

Quoted 8 lines
net/openvswitch/flow.c +4 -0
@@ -1167,6 +1212,22 @@ int ovs_nla_get_match(struct sw_flow_match *match,
                                err = -EINVAL;
                                goto free_newmask;
                        }
+                       err = parse_flow_mask_nlattrs(encap, a, &mask_v_attrs, log);
+                       if (err)
+                               goto free_newmask;
+

net/openvswitch/flow.c int ovs_nla_get_match(struct sw_flow_match *match, · line 1228

Quoted 10 lines
net/openvswitch/flow.c +10 -0
+                       if (mask_v_attrs & (1ULL << OVS_KEY_ATTR_VLAN)) {
+                               ctci = nla_get_be16(a[OVS_KEY_ATTR_VLAN]);
+                               if (!(ctci & htons(VLAN_TAG_PRESENT))) {
+                                       OVS_NLERR(log, "VLAN ctag present bit must have an exact match (ctci_mask=%x).",
+                                                 ntohs(ctci));
+                                       err = -EINVAL;
+                                       goto free_newmask;
+                               }
+                               mask_v_attrs &= ~(1ULL << OVS_KEY_ATTR_VLAN);
+                               mask_attrs |= mask_v_attrs;

mask_v_attrs can be defined in block where it is used.

net/openvswitch/flow.c static int __ovs_nla_put_key(const struct sw_flow_key *swkey, · line 1395

Quoted 10 lines
net/openvswitch/flow.c +3 -0
+                       }
+
                }
 
                err = ovs_key_from_nlattrs(match, mask_attrs, a, true, log);
@@ -1331,6 +1392,15 @@ static int __ovs_nla_put_key(const struct sw_flow_key *swkey,
                encap = nla_nest_start(skb, OVS_KEY_ATTR_ENCAP);
                if (!swkey->eth.tci)
                        goto unencap;
+       } else if (swkey->eth.tci || swkey->eth.type == htons(ETH_P_8021AD)) {

Checking for swkey->eth.tci does not make sense here. There is check for it in previous if condition.

net/openvswitch/flow.c static int __ovs_nla_put_key(const struct sw_flow_key *swkey, · line 1399

Quoted 4 lines
net/openvswitch/flow.c +4 -0
+               __be16 eth_type;
+               eth_type = !is_mask ? htons(ETH_P_8021AD) : htons(0xffff);
+               if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE, eth_type) ||
+                   nla_put_be16(skb, OVS_KEY_ATTR_VLAN, output->eth.tci))

What about eth.ctci?

#4 lore raw

Re: [PATCH net-next V7 2/2] openvswitch: 802.1ad: Flow handling, actions, and vlan parsing

Quoted 24 lines · Pravin Shelar
Quoted 3 lines · Thomas F Herbert

Add support for 802.1ad including the ability to push and pop double tagged vlans.

I saw multiple checkpatch.pl errors and warning.

Quoted 1 line

...

Quoted 15 lines
net/openvswitch/flow.c +2 -2
index 2dacc7b..6989451 100644
@@ -298,21 +298,78 @@ static bool icmp6hdr_ok(struct sk_buff *skb)
  static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key)
  {
         struct qtag_prefix {
-               __be16 eth_type; /* ETH_P_8021Q */
+               __be16 eth_type; /* ETH_P_8021Q  or ETH_P_8021AD */
                 __be16 tci;
         };
-       struct qtag_prefix *qp;
+       struct qtag_prefix *qp = (struct qtag_prefix *) skb->data;
 
Quoted 16 lines

net/openvswitch/flow.c static bool icmp6hdr_ok(struct sk_buff *skb) · line 316

Quoted 13 lines
net/openvswitch/flow.c +11 -2
-       if (unlikely(skb->len < sizeof(struct qtag_prefix) + sizeof(__be16)))
-               return 0;
+       struct qinqtag_prefix {
+               __be16 eth_type; /* ETH_P_8021Q  or ETH_P_8021AD */
+               __be16 tci;
+               __be16 inner_tpid; /* ETH_P_8021Q */
+               __be16 ctci;
+       };
+
+       if (likely(skb_vlan_tag_present(skb))) {
+
+               key->eth.tci = htons(skb->vlan_tci);
+

I think there is bug in existing OVS where it does not check vlan_proto before populating the flow key. Can you send a separate patch to fix this issue?.

Pravin,

Thanks for your review.

OK. I will find and fix this bug.

Quoted 9 lines

Checking for swkey->eth.tci does not make sense here. There is check for it in previous if condition.

net/openvswitch/flow.c static bool icmp6hdr_ok(struct sk_buff *skb) · line 320

Quoted 4 lines
net/openvswitch/flow.c +4 -0
+               __be16 eth_type;
+               eth_type = !is_mask ? htons(ETH_P_8021AD) : htons(0xffff);
+               if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE, eth_type) ||
+                   nla_put_be16(skb, OVS_KEY_ATTR_VLAN, output->eth.tci))

What about eth.ctci?

OK, yes the logic seems wrong so I will fix the check for ctci above and fix the checkpatch issues and resubmit to net-next.

Signature · 1 line
Thomas F. Herbert
#5 lore raw

Re: [PATCH net-next V7 2/2] openvswitch: 802.1ad: Flow handling, actions, and vlan parsing

In reply to Pravin Shelar
Quoted 11 lines · Pravin Shelar

On Tue, Apr 28, 2015 at 3:44 PM, Thomas F Herbert
<[email protected]> wrote:

net/openvswitch/flow.c +5 -0
+
+       if (likely(skb_vlan_tag_present(skb))) {
+
+               key->eth.tci = htons(skb->vlan_tci);
+

I think there is bug in existing OVS where it does not check vlan_proto before populating the flow key. Can you send a separate patch to fix this issue?.

Pravin, I realized I needed to address this comment in more detail. I would appreciate your and anybody else's thoughts on the following:
1. the newer if_vlan header in the upstream kernel has a function that probably should be used here and elsewhere when checking for tags, skb_vlan_tagged() which also checks skb->protocol field.
2. What about the compat "stuff" in the linux datapath of openvswitch? Should any fix for this issue also be applied to the compat layer which has different semantics for vlans or should the compat layer be updated to be the same as the 3.19, 4.0 kernel semantics?
3. In spite of my comment #2 above, I am not convinced that the generalized skb vlan functions in if_vlan.h are truly independent of hardware acceleration. I can see cases where the vlan headers in the payload of the skb are not checked. I am thinking a patch to the upstream kernel may also be necessary.

Quoted 13 lines

net/openvswitch/flow.c static bool icmp6hdr_ok(struct sk_buff *skb) · line 326

Quoted 11 lines
net/openvswitch/flow.c +10 -0
+               /*
+                * Case where upstream
+                * processing has already stripped the outer vlan tag.
+                */
+               if (unlikely(skb->vlan_proto == htons(ETH_P_8021AD))) {
+
+                       if (unlikely(skb->len < sizeof(struct qtag_prefix) +
+                                       sizeof(__be16)))
+                               return 0;
+

If this returns from here then it can match on flow with tci which expect vlan_proto to be 8021Q but with vlan_proto equal to 8021AD.

I did not fix this. This double checking has come up before when I submitted an earlier revision of this patch. The double checking done here is also used in the single tagged vlan code. I think that the consensus is that Open vSwitch wants to allow incomplete headers to allow user space processing to decide how to process incomplete vlan tags. For more discussion, see the following thread:
http://openvswitch.org/pipermail/dev/2014-December/049984.html

Thanks,

--TFH

Signature · 1 line
Thomas F. Herbert
#6 lore raw

Re: [PATCH net-next V7 2/2] openvswitch: 802.1ad: Flow handling, actions, and vlan parsing

Quoted 5 lines · Thomas F Herbert
Quoted 4 lines · Pravin Shelar

On Tue, Apr 28, 2015 at 3:44 PM, Thomas F Herbert
<[email protected]> wrote:

Quoted 16 lines
Quoted 8 lines
net/openvswitch/flow.c +5 -0
+
+       if (likely(skb_vlan_tag_present(skb))) {
+
+               key->eth.tci = htons(skb->vlan_tci);
+

I think there is bug in existing OVS where it does not check vlan_proto before populating the flow key. Can you send a separate patch to fix this issue?.

Pravin, I realized I needed to address this comment in more detail. I would appreciate your and anybody
else's thoughts on the following:
1. the newer if_vlan header in the upstream kernel has a function that probably should be used here and
elsewhere when checking for tags, skb_vlan_tagged() which also checks skb->protocol field.

When we populate flow key, we need to check skb->vlan_proto if it is 8021Q. This bug fix should be targeted to net tree.

Quoted 5 lines

2. What about the compat "stuff" in the linux datapath of openvswitch? Should any fix for this issue also be
applied to the compat layer which has different semantics for vlans or should the compat layer be updated to
be the same as the 3.19, 4.0 kernel semantics?

I think compat layer is fine. But if you find any issue you can send fix.

Quoted 5 lines

3. In spite of my comment #2 above, I am not convinced that the generalized skb vlan functions in if_vlan.h are truly
independent of hardware acceleration. I can see cases where the vlan headers in the payload of the skb are not
checked. I am thinking a patch to the upstream kernel may also be necessary.

ok.

Quoted 17 lines
Quoted 16 lines

net/openvswitch/flow.c static bool icmp6hdr_ok(struct sk_buff *skb) · line 326

Quoted 13 lines
net/openvswitch/flow.c +7 -0
+               /*
+                * Case where upstream
+                * processing has already stripped the outer vlan tag.
+                */
+               if (unlikely(skb->vlan_proto == htons(ETH_P_8021AD))) {
+
+                       if (unlikely(skb->len < sizeof(struct

qtag_prefix) +

net/openvswitch/flow.c +3 -0
+                                       sizeof(__be16)))
+                               return 0;
+

If this returns from here then it can match on flow with tci which expect vlan_proto to be 8021Q but with vlan_proto equal to 8021AD.

Quoted 9 lines

I did not fix this. This double checking has come up before when I submitted an earlier revision of this patch.
The double checking done here is also used in the single tagged vlan code. I think that the consensus is that
Open vSwitch wants to allow incomplete headers to allow user space processing to decide how to
process incomplete vlan tags. For more discussion, see the following thread:
http://openvswitch.org/pipermail/dev/2014-December/049984.html

When you return from error case you need to clear the key->eth.tci, so that it does not match on wrong flow.

#7 lore raw

Re: [PATCH net-next V7 2/2] openvswitch: 802.1ad: Flow handling, actions, and vlan parsing

Quoted 21 lines · Pravin Shelar
Quoted 4 lines · Thomas F Herbert
Quoted 3 lines · Pravin Shelar

On Tue, Apr 28, 2015 at 3:44 PM, Thomas F Herbert
<[email protected]> wrote:

Quoted 15 lines
Quoted 8 lines
net/openvswitch/flow.c +5 -0
+
+       if (likely(skb_vlan_tag_present(skb))) {
+
+               key->eth.tci = htons(skb->vlan_tci);
+

I think there is bug in existing OVS where it does not check vlan_proto before populating the flow key. Can you send a separate patch to fix this issue?.

Pravin, I realized I needed to address this comment in more detail. I would appreciate your and anybody
else's thoughts on the following:
1. the newer if_vlan header in the upstream kernel has a function that probably should be used here and
elsewhere when checking for tags, skb_vlan_tagged() which also checks skb->protocol field.

Quoted 2 lines

When we populate flow key, we need to check skb->vlan_proto if it is 8021Q. This bug fix should be targeted to net tree.

OK

Quoted 38 lines
Quoted 6 lines

2. What about the compat "stuff" in the linux datapath of openvswitch? Should any fix for this issue also be
applied to the compat layer which has different semantics for vlans or should the compat layer be updated to
be the same as the 3.19, 4.0 kernel semantics?

I think compat layer is fine. But if you find any issue you can send fix.

Quoted 5 lines

3. In spite of my comment #2 above, I am not convinced that the generalized skb vlan functions in if_vlan.h are truly
independent of hardware acceleration. I can see cases where the vlan headers in the payload of the skb are not
checked. I am thinking a patch to the upstream kernel may also be necessary.

ok.

Quoted 14 lines
Quoted 14 lines

net/openvswitch/flow.c static bool icmp6hdr_ok(struct sk_buff *skb) · line 326

Quoted 12 lines
net/openvswitch/flow.c +7 -0
+               /*
+                * Case where upstream
+                * processing has already stripped the outer vlan tag.
+                */
+               if (unlikely(skb->vlan_proto == htons(ETH_P_8021AD))) {
+
+                       if (unlikely(skb->len < sizeof(struct

qtag_prefix) +

net/openvswitch/flow.c +3 -0
+                                       sizeof(__be16)))
+                               return 0;
+

If this returns from here then it can match on flow with tci which expect vlan_proto to be 8021Q but with vlan_proto equal to 8021AD.

Quoted 9 lines

I did not fix this. This double checking has come up before when I submitted an earlier revision of this patch.
The double checking done here is also used in the single tagged vlan code. I think that the consensus is that
Open vSwitch wants to allow incomplete headers to allow user space processing to decide how to
process incomplete vlan tags. For more discussion, see the following thread:
http://openvswitch.org/pipermail/dev/2014-December/049984.html

Quoted 2 lines

When you return from error case you need to clear the key->eth.tci, so that it does not match on wrong flow.

Yes, you are correct. I see the the bug now. I will fix in a V9.

--TFH

Signature · 6 lines
Thomas F Herbert
Principal Software Engineer
Red Hat
[email protected]
Office: 919-301-3295
Mobile: 804-741-2695