Skip to contentSkip to conversation

openvswitch: Add support for 802.1AD

PATCH Superseded Thomas F Herbert 6 participants 11 messages Jun 23, 2015 – Jul 26, 2015 7 messages not in the archive

Subsystems (3)

v11 of 20 Superseded Latest is v20 →

lore
Share & tools
lore
#0 lore raw

v11 cover openvswitch: Add support for 802.1AD

V11: Add inner tpid to flow key. Fix separate inner encap attribute when parsing netlink attributes. Merge 2 patches to consolidate qinq changes.

V10: Implement reviewer comments: Consolidate vlan parsing functions. Splits netlink parsing and flow conversion into a separate patch. Uses double encap attribute encapsulation for 802.1ad. Netlink attributes now look like this:

    eth_type(0x88a8),vlan(vid=100),encap(eth_type(0x8100), vlan(vid=200),
        encap(eth_type(0x0800), ...))

The double encap atributes in this version of the patch is incompatible with old versions of the user level 802.1ad patch. A new user level patch which is also being submitted simultaneously to openvswitch dev mailing list.

V9: Includes changes suggested by reviewers

V8: Includes changes suggested by reviewers

V7: Includes changes suggested by reviewers

V6: Rebased to net-next

V5: Use encapsulated attributes

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 patch accompanies version 10 of the user level openvswitch patch submitted to openvswitch dev list.
For discussion, history and previous versions of the kernel module patch and the user code patch see the OVS dev mailing list, openvswitch.org/pipermail/dev/..

Thomas F Herbert (3):
openvswitch: 802.1ad uapi changes.
Check for vlan ethernet types for 8021.q or 802.1ad 802.1AD: Flow handling, actions, vlan parsing and netlink attributes

 include/linux/if_vlan.h          |   9 ++
 include/uapi/linux/openvswitch.h |  17 ++--
 net/openvswitch/flow.c           |  84 ++++++++++++++---
 net/openvswitch/flow.h           |   5 +
 net/openvswitch/flow_netlink.c   | 195 +++++++++++++++++++++++++++++++++------
 5 files changed, 260 insertions(+), 50 deletions(-)
Signature · 6 lines
2.1.0

_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev

A message that is not in the archive (sent off-list or not yet received): 1435083990-12986-1-git-send-email-thomasfherbert-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#2 lore raw

PATCH v11 1/3 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 · 6 lines
2.1.0

_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev
#3 lore raw

PATCH v11 2/3 Check for vlan ethernet types for 8021.q or 802.1ad

In reply to Thomas F Herbert
---
 include/linux/if_vlan.h | 9 +++++++++
 1 file changed, 9 insertions(+)
include/linux/if_vlan.h +9 -0
index 920e445..3713454 100644
@@ -627,5 +627,14 @@ static inline netdev_features_t vlan_features_check(const struct sk_buff *skb,
 
 	return features;
 }
+/**
+ * Check for legal valid vlan ether type.
+ */
+static inline bool eth_type_vlan(__be16 ethertype)
+{
+	if (ethertype == htons(ETH_P_8021Q) || ethertype == htons(ETH_P_8021AD))
+		return true;
+	return false;
+}
 
 #endif /* !(_LINUX_IF_VLAN_H_) */
Signature · 1 line
2.1.0

A message that is not in the archive (sent off-list or not yet received): 1435083990-12986-3-git-send-email-thomasfherbert-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#5 lore raw

Re: [PATCH net-next V11 2/3] Check for vlan ethernet types for 8021.q or 802.1ad

Hello.

Quoted 1 line · Thomas F Herbert

[...]

include/linux/if_vlan.h static inline netdev_features_t vlan_features_check(const struct sk_buff *skb, · line 631

Quoted 10 lines
include/linux/if_vlan.h +2 -0
index 920e445..3713454 100644
@@ -627,5 +627,14 @@ static inline netdev_features_t vlan_features_check(const struct sk_buff *skb,
 
  	return features;
  }
+/**
+ * Check for legal valid vlan ether type.

The comment doesn't follow the kernel-doc format determined by /**.

include/linux/if_vlan.h static inline netdev_features_t vlan_features_check(const struct sk_buff *skb, · line 637

Quoted 6 lines
include/linux/if_vlan.h +6 -0
+ */
+static inline bool eth_type_vlan(__be16 ethertype)
+{
+	if (ethertype == htons(ETH_P_8021Q) || ethertype == htons(ETH_P_8021AD))
+		return true;
+	return false;

Perhaps *switch*?

[...]

WBR, Sergei

_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev

#6 lore raw

Re: [PATCH net-next V11 2/3] Check for vlan ethernet types for 8021.q or 802.1ad

Quoted 14 lines · Sergei Shtylyov

Hello.

Quoted 1 line · Thomas F Herbert

[...]

Quoted 7 lines
include/linux/if_vlan.h +0 -0
index 920e445..3713454 100644
@@ -627,5 +627,14 @@ static inline netdev_features_t
 vlan_features_check(const struct sk_buff *skb,
 
Quoted 6 lines

include/linux/if_vlan.h static inline netdev_features_t vlan_features_check(const struct sk_buff *skb, · line 631

Quoted 4 lines
include/linux/if_vlan.h +2 -0
      return features;
  }
+/**
+ * Check for legal valid vlan ether type.

The comment doesn't follow the kernel-doc format determined by /**.

OK, I will change it to the proper kernel doc format.

Quoted 10 lines

include/linux/if_vlan.h static inline netdev_features_t vlan_features_check(const struct sk_buff *skb, · line 637

Quoted 8 lines
include/linux/if_vlan.h +6 -0
+ */
+static inline bool eth_type_vlan(__be16 ethertype)
+{
+    if (ethertype == htons(ETH_P_8021Q) || ethertype ==
 htons(ETH_P_8021AD))
+        return true;
+    return false;

Perhaps *switch*?

I have no objection to changing this to a switch statement.

Quoted 5 lines

[...]

WBR, Sergei

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

PATCH 3/3 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. Add support for 802.1ad to netlink parsing and flow conversion. Uses double nested encap attributes to represent double tagged vlan. Inner TPID encoded along with ctci in nested attributes.

---
 net/openvswitch/flow.c         |  84 +++++++++++++++---
 net/openvswitch/flow.h         |   5 ++
 net/openvswitch/flow_netlink.c | 195 ++++++++++++++++++++++++++++++++++-------
 3 files changed, 242 insertions(+), 42 deletions(-)
net/openvswitch/flow.c +72 -12
index 2dacc7b..e268865 100644
@@ -298,21 +298,80 @@ 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)))
+	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);
+
+		/* 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))) {
+				key->eth.tci = 0;
+				return 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.cvlan.ctci =
+					qp->tci | htons(VLAN_TAG_PRESENT);
+				key->eth.cvlan.c_tpid = skb->vlan_proto;
+				__skb_pull(skb, sizeof(struct qtag_prefix));
+			}
+		}
 		return 0;
+	}
 
-	if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
-					 sizeof(__be16))))
-		return -ENOMEM;
 
-	qp = (struct qtag_prefix *) skb->data;
-	key->eth.tci = qp->tci | htons(VLAN_TAG_PRESENT);
-	__skb_pull(skb, sizeof(struct qtag_prefix));
+	if (qp->eth_type == htons(ETH_P_8021AD)) {
+		struct qinqtag_prefix *qinqp =
+					(struct qinqtag_prefix *)skb->data;
+
+		if (unlikely(skb->len < sizeof(struct qinqtag_prefix) +
+					sizeof(__be16)))
+			return 0;
+
+		if (unlikely(!pskb_may_pull(skb, sizeof(struct qinqtag_prefix) +
+				sizeof(__be16)))) {
+			return -ENOMEM;
+		}
+		key->eth.tci = qinqp->tci | htons(VLAN_TAG_PRESENT);
+		key->eth.cvlan.ctci = qinqp->ctci | htons(VLAN_TAG_PRESENT);
+		key->eth.cvlan.c_tpid = qinqp->inner_tpid;
+
+		__skb_pull(skb, sizeof(struct qinqtag_prefix));
+
+		return 0;
+	}
+	if (qp->eth_type == htons(ETH_P_8021Q)) {
+		if (unlikely(skb->len < sizeof(struct qtag_prefix) +
+					sizeof(__be16)))
+			return -ENOMEM;
+
+		if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
+				sizeof(__be16))))
+			return 0;
+		key->eth.tci = qp->tci | htons(VLAN_TAG_PRESENT);
+
+		__skb_pull(skb, sizeof(struct qtag_prefix));
+	}
 
 	return 0;
 }
@@ -474,9 +533,10 @@ static int key_extract(struct sk_buff *skb, struct sw_flow_key *key)
 	 */
 
 	key->eth.tci = 0;
-	if (skb_vlan_tag_present(skb))
-		key->eth.tci = htons(skb->vlan_tci);
-	else if (eth->h_proto == htons(ETH_P_8021Q))
+	key->eth.cvlan.ctci = 0;
+	if ((skb_vlan_tag_present(skb)) ||
+	    (eth->h_proto == htons(ETH_P_8021Q)) ||
+	    (eth->h_proto == htons(ETH_P_8021AD)))
 		if (unlikely(parse_vlan(skb, key)))
 			return -ENOMEM;
 
net/openvswitch/flow.h +5 -0
index a076e44..d41f3cc 100644
@@ -134,6 +134,11 @@ 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. */
+		struct {
+			__be16 c_tpid;	/* Vlan DL_type 802.1q or 802.1ad */
+			__be16 ctci;	/* 0 if no CVLAN, VLAN_TAG_PRESENT */
+					/* set otherwise. */
+		} cvlan;
 		__be16 type;		/* Ethernet frame type. */
 	} eth;
 	union {
net/openvswitch/flow_netlink.c +165 -30

267 lines not on this page · raw message

Signature · 1 line
2.1.0

A message that is not in the archive (sent off-list or not yet received): 1435083990-12986-4-git-send-email-thomasfherbert-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#9 lore raw

Re: [PATCH net-next 3/3] openvswitch: 802.1AD: Flow handling, actions, and vlan parsing

Quoted 48 lines · Thomas F Herbert

Add support for 802.1ad including the ability to push and pop double tagged vlans. Add support for 802.1ad to netlink parsing and flow conversion. Uses double nested encap attributes to represent double tagged vlan. Inner TPID encoded along with ctci in nested attributes.

---
 net/openvswitch/flow.c         |  84 +++++++++++++++---
 net/openvswitch/flow.h         |   5 ++
 net/openvswitch/flow_netlink.c | 195 ++++++++++++++++++++++++++++++++++-------
 3 files changed, 242 insertions(+), 42 deletions(-)
net/openvswitch/flow.c +22 -3
index 2dacc7b..e268865 100644
@@ -298,21 +298,80 @@ 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)))
+       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);
+
+               /* 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))) {
+                               key->eth.tci = 0;
+                               return 0;
+                       }
+

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

Quoted 10 lines
net/openvswitch/flow.c +10 -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.cvlan.ctci =
+                                       qp->tci | htons(VLAN_TAG_PRESENT);
+                               key->eth.cvlan.c_tpid = skb->vlan_proto;

We should directly copy qp->inner_tpid here. As you have done it for non offloaded case below.

Quoted 49 lines
net/openvswitch/flow.c +36 -6
+                               __skb_pull(skb, sizeof(struct qtag_prefix));
+                       }
+               }
                return 0;
+       }
 
-       if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
-                                        sizeof(__be16))))
-               return -ENOMEM;
 
-       qp = (struct qtag_prefix *) skb->data;
-       key->eth.tci = qp->tci | htons(VLAN_TAG_PRESENT);
-       __skb_pull(skb, sizeof(struct qtag_prefix));
+       if (qp->eth_type == htons(ETH_P_8021AD)) {
+               struct qinqtag_prefix *qinqp =
+                                       (struct qinqtag_prefix *)skb->data;
+
+               if (unlikely(skb->len < sizeof(struct qinqtag_prefix) +
+                                       sizeof(__be16)))
+                       return 0;
+
+               if (unlikely(!pskb_may_pull(skb, sizeof(struct qinqtag_prefix) +
+                               sizeof(__be16)))) {
+                       return -ENOMEM;
+               }
+               key->eth.tci = qinqp->tci | htons(VLAN_TAG_PRESENT);
+               key->eth.cvlan.ctci = qinqp->ctci | htons(VLAN_TAG_PRESENT);
+               key->eth.cvlan.c_tpid = qinqp->inner_tpid;
+
+               __skb_pull(skb, sizeof(struct qinqtag_prefix));
+
+               return 0;
+       }
+       if (qp->eth_type == htons(ETH_P_8021Q)) {
+               if (unlikely(skb->len < sizeof(struct qtag_prefix) +
+                                       sizeof(__be16)))
+                       return -ENOMEM;
+
+               if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
+                               sizeof(__be16))))
+                       return 0;
+               key->eth.tci = qp->tci | htons(VLAN_TAG_PRESENT);
+
+               __skb_pull(skb, sizeof(struct qtag_prefix));
+       }
 
        return 0;
 }

net/openvswitch/flow.c static int key_extract(struct sk_buff *skb, struct sw_flow_key *key) · line 536

Quoted 7 lines
net/openvswitch/flow.c +1 -3
@@ -474,9 +533,10 @@ static int key_extract(struct sk_buff *skb, struct sw_flow_key *key)
         */
 
        key->eth.tci = 0;
-       if (skb_vlan_tag_present(skb))
-               key->eth.tci = htons(skb->vlan_tci);
-       else if (eth->h_proto == htons(ETH_P_8021Q))
+       key->eth.cvlan.ctci = 0;

cvlan.c_tpid is not initialized for all cases.

net/openvswitch/flow.c static int key_extract(struct sk_buff *skb, struct sw_flow_key *key) · line 539

Quoted 3 lines
net/openvswitch/flow.c +3 -0
+       if ((skb_vlan_tag_present(skb)) ||
+           (eth->h_proto == htons(ETH_P_8021Q)) ||
+           (eth->h_proto == htons(ETH_P_8021AD)))

These are redundant check. so we can directly call this function.

Quoted 3 lines
net/openvswitch/flow.c +0 -0
                if (unlikely(parse_vlan(skb, key)))
                        return -ENOMEM;
 

...

Quoted 11 lines
net/openvswitch/flow.c +10 -0
+static int cust_vlan_from_nlattrs(struct sw_flow_match *match, u64 attrs,
+                                 const struct nlattr **a, bool is_mask,
+                                 bool log)
+{
+       /* This should be nested inner or "customer" tci" */
+       if (attrs & (1 << OVS_KEY_ATTR_VLAN)) {
+               __be16 ctci;
+
+               ctci = nla_get_be16(a[OVS_KEY_ATTR_VLAN]);
+               if (!(ctci & htons(VLAN_TAG_PRESENT))) {

net/openvswitch/flow.c

Quoted 10 lines
net/openvswitch/flow.c +10 -0
+                       if (is_mask)
+                               OVS_NLERR(log, "VLAN CTCI mask does not have exact match for VLAN_TAG_PRESENT bit.");
+                       else
+                               OVS_NLERR(log, "VLAN CTCI does not have VLAN_TAG_PRESENT bit set.");
+
+                       return -EINVAL;
+               }
+               SW_FLOW_KEY_PUT(match, eth.cvlan.c_tpid, ctci, is_mask);
+               SW_FLOW_KEY_PUT(match, eth.cvlan.ctci, ctci, is_mask);
+       }

Same value is set to tpid and tci.

Quoted 18 lines
net/openvswitch/flow.c +11 -0
+       return 0;
+}
+
 static int ovs_key_from_nlattrs(struct sw_flow_match *match, u64 attrs,
                                const struct nlattr **a, bool is_mask,
                                bool log)
@@ -1024,6 +1047,105 @@ static void mask_set_nlattr(struct nlattr *attr, u8 val)
        nlattr_set(attr, val, ovs_key_lens);
 }
 
+static int parse_vlan_from_nlattrs(const struct nlattr *nla,
+                                  struct sw_flow_match *match,
+                                  u64 *key_attrs, bool *ie_valid,
+                                  const struct nlattr **a, bool is_mask,
+                                  bool log)
+{
+       int err;
+       __be16 tci;

net/openvswitch/flow.c static void mask_set_nlattr(struct nlattr *attr, u8 val) · line 1067

Quoted 10 lines
net/openvswitch/flow.c +10 -0
+       const struct nlattr *encap;
+
+       if (!is_mask) {
+               u64 v_attrs = 0;
+
+               tci = nla_get_be16(a[OVS_KEY_ATTR_VLAN]);
+
+               if (tci & htons(VLAN_TAG_PRESENT)) {
+                       if (unlikely((nla_get_be16(a[OVS_KEY_ATTR_ETHERTYPE]) ==
+                                     htons(ETH_P_8021AD)))) {

Since we have added tpid to flow key, we have flexibility of supporting generic double encapsulation. Therefore in netlink parsing of key, double encap should not be limited to just 8021AD. for example it should allow 8021Q in 8021Q header as valid key.

net/openvswitch/flow.c static void mask_set_nlattr(struct nlattr *attr, u8 val) · line 1073

Quoted 6 lines
net/openvswitch/flow.c +6 -0
+                               err = parse_flow_nlattrs(nla, a, &v_attrs, log);
+                               if (err)
+                                       return err;
+                               if (!v_attrs)
+                                       return -EINVAL;
+

_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev

A message that is not in the archive (sent off-list or not yet received): CALnjE+pZB+NkG2Q=ZsLzGNLy4PixwY+U9+HwgfmLQLv+Vd_hgg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#11 lore raw

Re: [PATCH net-next 3/3] openvswitch: 802.1AD: Flow handling, actions, and vlan parsing

Quoted 1 line · Pravin Shelar

On Tue, Jun 23, 2015 at 11:26 AM, Thomas F Herbert

Pravin, I apologize because I realize now that I am finishing V12 of this patch that I never responded to your comments in this email.

Quoted 54 lines
Quoted 53 lines · <[email protected]> wrote:

Add support for 802.1ad including the ability to push and pop double tagged vlans. Add support for 802.1ad to netlink parsing and flow conversion. Uses double nested encap attributes to represent double tagged vlan. Inner TPID encoded along with ctci in nested attributes.

---
  net/openvswitch/flow.c         |  84 +++++++++++++++---
  net/openvswitch/flow.h         |   5 ++
  net/openvswitch/flow_netlink.c | 195 ++++++++++++++++++++++++++++++++++-------
  3 files changed, 242 insertions(+), 42 deletions(-)
net/openvswitch/flow.c +27 -3
index 2dacc7b..e268865 100644
@@ -298,21 +298,80 @@ 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)))
+       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);
+
+               /* 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))) {
+                               key->eth.tci = 0;
+                               return 0;
+                       }
+
+                       if (unlikely(!pskb_may_pull(skb,
+                                                   sizeof(struct qtag_prefix) +
+                                                   sizeof(__be16)))) {
+                               return -ENOMEM;
+                       }
Quoted 8 lines

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

Quoted 5 lines
net/openvswitch/flow.c +5 -0
+
+                       if (likely(qp->eth_type == htons(ETH_P_8021Q))) {
+                               key->eth.cvlan.ctci =
+                                       qp->tci | htons(VLAN_TAG_PRESENT);
+                               key->eth.cvlan.c_tpid = skb->vlan_proto;

We should directly copy qp->inner_tpid here. As you have done it for non offloaded case below.

Thanks! It is copied but it is set to the wrong tpid. The c_tpid field in the key should be set to the ethertype in the packet itself which is the inner tpid, not the offloaded skb-vlan_proto which is the outer tpid. Fixed in V12.

Quoted 52 lines
Quoted 52 lines
net/openvswitch/flow.c +36 -6
+                               __skb_pull(skb, sizeof(struct qtag_prefix));
+                       }
+               }
                 return 0;
+       }
 
-       if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
-                                        sizeof(__be16))))
-               return -ENOMEM;
 
-       qp = (struct qtag_prefix *) skb->data;
-       key->eth.tci = qp->tci | htons(VLAN_TAG_PRESENT);
-       __skb_pull(skb, sizeof(struct qtag_prefix));
+       if (qp->eth_type == htons(ETH_P_8021AD)) {
+               struct qinqtag_prefix *qinqp =
+                                       (struct qinqtag_prefix *)skb->data;
+
+               if (unlikely(skb->len < sizeof(struct qinqtag_prefix) +
+                                       sizeof(__be16)))
+                       return 0;
+
+               if (unlikely(!pskb_may_pull(skb, sizeof(struct qinqtag_prefix) +
+                               sizeof(__be16)))) {
+                       return -ENOMEM;
+               }
+               key->eth.tci = qinqp->tci | htons(VLAN_TAG_PRESENT);
+               key->eth.cvlan.ctci = qinqp->ctci | htons(VLAN_TAG_PRESENT);
+               key->eth.cvlan.c_tpid = qinqp->inner_tpid;
+
+               __skb_pull(skb, sizeof(struct qinqtag_prefix));
+
+               return 0;
+       }
+       if (qp->eth_type == htons(ETH_P_8021Q)) {
+               if (unlikely(skb->len < sizeof(struct qtag_prefix) +
+                                       sizeof(__be16)))
+                       return -ENOMEM;
+
+               if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
+                               sizeof(__be16))))
+                       return 0;
+               key->eth.tci = qp->tci | htons(VLAN_TAG_PRESENT);
+
+               __skb_pull(skb, sizeof(struct qtag_prefix));
+       }
 
         return 0;
  }
@@ -474,9 +533,10 @@ static int key_extract(struct sk_buff *skb, struct sw_flow_key *key)
          */
 
Quoted 6 lines

net/openvswitch/flow.c static int key_extract(struct sk_buff *skb, struct sw_flow_key *key) · line 536

Quoted 5 lines
net/openvswitch/flow.c +1 -3
         key->eth.tci = 0;
-       if (skb_vlan_tag_present(skb))
-               key->eth.tci = htons(skb->vlan_tci);
-       else if (eth->h_proto == htons(ETH_P_8021Q))
+       key->eth.cvlan.ctci = 0;

cvlan.c_tpid is not initialized for all cases.

Fixed in V12

Quoted 5 lines

net/openvswitch/flow.c static int key_extract(struct sk_buff *skb, struct sw_flow_key *key) · line 539

Quoted 4 lines
net/openvswitch/flow.c +3 -0
+       if ((skb_vlan_tag_present(skb)) ||
+           (eth->h_proto == htons(ETH_P_8021Q)) ||
+           (eth->h_proto == htons(ETH_P_8021AD)))

These are redundant check. so we can directly call this function.

I don't agree that these 3 checks are redundant. parse_vlan parses both the offloaded and non-offloaded cases. In V12, I changed it to call eth_type_vlan() to do the checks for the non-offloaded ethertypes.

Hmmm ... maybe I should add another function to if_vlan.h to check if a packet is a vlan regardless of whether it is offloaded or not?

Quoted 20 lines
Quoted 4 lines
net/openvswitch/flow.c +0 -0
                 if (unlikely(parse_vlan(skb, key)))
                         return -ENOMEM;
 

...

Quoted 14 lines
net/openvswitch/flow.c +13 -0
+static int cust_vlan_from_nlattrs(struct sw_flow_match *match, u64 attrs,
+                                 const struct nlattr **a, bool is_mask,
+                                 bool log)
+{
+       /* This should be nested inner or "customer" tci" */
+       if (attrs & (1 << OVS_KEY_ATTR_VLAN)) {
+               __be16 ctci;
+
+               ctci = nla_get_be16(a[OVS_KEY_ATTR_VLAN]);
+               if (!(ctci & htons(VLAN_TAG_PRESENT))) {
+                       if (is_mask)
+                               OVS_NLERR(log, "VLAN CTCI mask does not have exact match for VLAN_TAG_PRESENT bit.");
+                       else
Quoted 8 lines

net/openvswitch/flow.c

Quoted 7 lines
net/openvswitch/flow.c +7 -0
+                               OVS_NLERR(log, "VLAN CTCI does not have VLAN_TAG_PRESENT bit set.");
+
+                       return -EINVAL;
+               }
+               SW_FLOW_KEY_PUT(match, eth.cvlan.c_tpid, ctci, is_mask);
+               SW_FLOW_KEY_PUT(match, eth.cvlan.ctci, ctci, is_mask);
+       }

Same value is set to tpid and tci.

Thanks! Fixed in V12.

Quoted 25 lines
Quoted 25 lines
net/openvswitch/flow.c +17 -0
+       return 0;
+}
+
  static int ovs_key_from_nlattrs(struct sw_flow_match *match, u64 attrs,
                                 const struct nlattr **a, bool is_mask,
                                 bool log)
@@ -1024,6 +1047,105 @@ static void mask_set_nlattr(struct nlattr *attr, u8 val)
         nlattr_set(attr, val, ovs_key_lens);
  }
 
+static int parse_vlan_from_nlattrs(const struct nlattr *nla,
+                                  struct sw_flow_match *match,
+                                  u64 *key_attrs, bool *ie_valid,
+                                  const struct nlattr **a, bool is_mask,
+                                  bool log)
+{
+       int err;
+       __be16 tci;
+       const struct nlattr *encap;
+
+       if (!is_mask) {
+               u64 v_attrs = 0;
+
+               tci = nla_get_be16(a[OVS_KEY_ATTR_VLAN]);
Quoted 8 lines

net/openvswitch/flow.c static void mask_set_nlattr(struct nlattr *attr, u8 val) · line 1067

Quoted 4 lines
net/openvswitch/flow.c +4 -0
+
+               if (tci & htons(VLAN_TAG_PRESENT)) {
+                       if (unlikely((nla_get_be16(a[OVS_KEY_ATTR_ETHERTYPE]) ==
+                                     htons(ETH_P_8021AD)))) {

Since we have added tpid to flow key, we have flexibility of supporting generic double encapsulation. Therefore in netlink parsing of key, double encap should not be limited to just 8021AD. for example it should allow 8021Q in 8021Q header as valid key.

I agree. Although Open Flow specification doesn't support non 802.1AD double tagged vlans, we probably should be as least restrictive as possible here in the kernel module. I recoded this in V12 to allow a more "generic" qinq.

Quoted 7 lines

net/openvswitch/flow.c static void mask_set_nlattr(struct nlattr *attr, u8 val) · line 1073

Quoted 7 lines
net/openvswitch/flow.c +6 -0
+                               err = parse_flow_nlattrs(nla, a, &v_attrs, log);
+                               if (err)
+                                       return err;
+                               if (!v_attrs)
+                                       return -EINVAL;
+

_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev

A message that is not in the archive (sent off-list or not yet received): [email protected]

#13 lore raw

Re: [PATCH net-next 3/3] openvswitch: 802.1AD: Flow handling, actions, and vlan parsing

Hi Thomas,

I am currently using the beta version of ovs(2.3.90). In my phy-phy scenario , I am configuring the two physical ports(eth0, eth1) attached to ovs bridge as trunk ports using the below commands.

ovs-vsctl --no-wait add-port br0 eth0 vlan_mode=trunk ovs-vsctl --no-wait add-port br0 eth1 vlan_mode=trunk

I configured the bridge to work in legacy mode as shown below

$ ovs-ofctl dump-flows br0
NXST_FLOW reply (xid=0x4):
cookie=0x0, duration=15.458s, table=0, n_packets=0, n_bytes=0, idle_age=15, priority=0 actions=NORMAL

I tried sending 802.1ad tagged(outer tag tpid=0x88a8, inter tag tpid=ox8100) packet from packetgen to phyport1 (eth0), and receiving back on phyport2(eth2). When I captured the received packet on eth1 , the received packet is not same as sent packet, means outer vlan TPID is not 0x88a8(instead 0x8100).

Could you please let me know , whether the below mentioned patch helps here.

Thanks in Advance,
Uday

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Thomas F Herbert
Sent: Sunday, July 26, 2015 6:03 AM
To: Pravin Shelar
Cc: [email protected]; netdev; [email protected]
Subject: Re: [ovs-dev] [PATCH net-next 3/3] openvswitch: 802.1AD: Flow handling, actions, and vlan parsing

Quoted 1 line · Pravin Shelar

On Tue, Jun 23, 2015 at 11:26 AM, Thomas F Herbert

Pravin, I apologize because I realize now that I am finishing V12 of this patch that I never responded to your comments in this email.

Quoted 55 lines
Quoted 54 lines · <[email protected]> wrote:

Add support for 802.1ad including the ability to push and pop double tagged vlans. Add support for 802.1ad to netlink parsing and flow conversion. Uses double nested encap attributes to represent double tagged vlan. Inner TPID encoded along with ctci in nested attributes.

---
  net/openvswitch/flow.c         |  84 +++++++++++++++---
  net/openvswitch/flow.h         |   5 ++
  net/openvswitch/flow_netlink.c | 195 ++++++++++++++++++++++++++++++++++-------
  3 files changed, 242 insertions(+), 42 deletions(-)
net/openvswitch/flow.c index renamed from net/openvswitch/flow.c +0 -0

2dacc7b..e268865 100644

net/openvswitch/flow.c +28 -3
@@ -298,21 +298,80 @@ 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)))
+       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);
+
+               /* 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))) {
+                               key->eth.tci = 0;
+                               return 0;
+                       }
+
+                       if (unlikely(!pskb_may_pull(skb,
+                                                   sizeof(struct qtag_prefix) +
+                                                   sizeof(__be16)))) {
+                               return -ENOMEM;
+                       }
+
Quoted 8 lines

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

Quoted 5 lines
net/openvswitch/flow.c +5 -0
+                       if (likely(qp->eth_type == htons(ETH_P_8021Q))) {
+                               key->eth.cvlan.ctci =
+                                       qp->tci | htons(VLAN_TAG_PRESENT);
+                               key->eth.cvlan.c_tpid =
+ skb->vlan_proto;

We should directly copy qp->inner_tpid here. As you have done it for non offloaded case below.

Thanks! It is copied but it is set to the wrong tpid. The c_tpid field in the key should be set to the ethertype in the packet itself which is the inner tpid, not the offloaded skb-vlan_proto which is the outer tpid. Fixed in V12.

Quoted 53 lines
Quoted 53 lines
net/openvswitch/flow.c +37 -6
+                               __skb_pull(skb, sizeof(struct qtag_prefix));
+                       }
+               }
                 return 0;
+       }
 
-       if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
-                                        sizeof(__be16))))
-               return -ENOMEM;
 
-       qp = (struct qtag_prefix *) skb->data;
-       key->eth.tci = qp->tci | htons(VLAN_TAG_PRESENT);
-       __skb_pull(skb, sizeof(struct qtag_prefix));
+       if (qp->eth_type == htons(ETH_P_8021AD)) {
+               struct qinqtag_prefix *qinqp =
+                                       (struct qinqtag_prefix
+ *)skb->data;
+
+               if (unlikely(skb->len < sizeof(struct qinqtag_prefix) +
+                                       sizeof(__be16)))
+                       return 0;
+
+               if (unlikely(!pskb_may_pull(skb, sizeof(struct qinqtag_prefix) +
+                               sizeof(__be16)))) {
+                       return -ENOMEM;
+               }
+               key->eth.tci = qinqp->tci | htons(VLAN_TAG_PRESENT);
+               key->eth.cvlan.ctci = qinqp->ctci | htons(VLAN_TAG_PRESENT);
+               key->eth.cvlan.c_tpid = qinqp->inner_tpid;
+
+               __skb_pull(skb, sizeof(struct qinqtag_prefix));
+
+               return 0;
+       }
+       if (qp->eth_type == htons(ETH_P_8021Q)) {
+               if (unlikely(skb->len < sizeof(struct qtag_prefix) +
+                                       sizeof(__be16)))
+                       return -ENOMEM;
+
+               if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
+                               sizeof(__be16))))
+                       return 0;
+               key->eth.tci = qp->tci | htons(VLAN_TAG_PRESENT);
+
+               __skb_pull(skb, sizeof(struct qtag_prefix));
+       }
 
         return 0;
  }
@@ -474,9 +533,10 @@ static int key_extract(struct sk_buff *skb, struct sw_flow_key *key)
          */
 
Quoted 6 lines

net/openvswitch/flow.c static int key_extract(struct sk_buff *skb, struct sw_flow_key *key) · line 536

Quoted 5 lines
net/openvswitch/flow.c +1 -3
         key->eth.tci = 0;
-       if (skb_vlan_tag_present(skb))
-               key->eth.tci = htons(skb->vlan_tci);
-       else if (eth->h_proto == htons(ETH_P_8021Q))
+       key->eth.cvlan.ctci = 0;

cvlan.c_tpid is not initialized for all cases.

Fixed in V12

Quoted 5 lines

net/openvswitch/flow.c static int key_extract(struct sk_buff *skb, struct sw_flow_key *key) · line 539

Quoted 4 lines
net/openvswitch/flow.c +3 -0
+       if ((skb_vlan_tag_present(skb)) ||
+           (eth->h_proto == htons(ETH_P_8021Q)) ||
+           (eth->h_proto == htons(ETH_P_8021AD)))

These are redundant check. so we can directly call this function.

I don't agree that these 3 checks are redundant. parse_vlan parses both the offloaded and non-offloaded cases. In V12, I changed it to call eth_type_vlan() to do the checks for the non-offloaded ethertypes.

Hmmm ... maybe I should add another function to if_vlan.h to check if a packet is a vlan regardless of whether it is offloaded or not?

Quoted 20 lines
Quoted 4 lines
net/openvswitch/flow.c +0 -0
                 if (unlikely(parse_vlan(skb, key)))
                         return -ENOMEM;
 

...

Quoted 14 lines
net/openvswitch/flow.c +13 -0
+static int cust_vlan_from_nlattrs(struct sw_flow_match *match, u64 attrs,
+                                 const struct nlattr **a, bool is_mask,
+                                 bool log) {
+       /* This should be nested inner or "customer" tci" */
+       if (attrs & (1 << OVS_KEY_ATTR_VLAN)) {
+               __be16 ctci;
+
+               ctci = nla_get_be16(a[OVS_KEY_ATTR_VLAN]);
+               if (!(ctci & htons(VLAN_TAG_PRESENT))) {
+                       if (is_mask)
+                               OVS_NLERR(log, "VLAN CTCI mask does not have exact match for VLAN_TAG_PRESENT bit.");
+                       else
+                               OVS_NLERR(log, "VLAN CTCI does not
Quoted 8 lines

net/openvswitch/flow.c

Quoted 7 lines

+ have VLAN_TAG_PRESENT bit set.");

net/openvswitch/flow.c +6 -0
+
+                       return -EINVAL;
+               }
+               SW_FLOW_KEY_PUT(match, eth.cvlan.c_tpid, ctci, is_mask);
+               SW_FLOW_KEY_PUT(match, eth.cvlan.ctci, ctci, is_mask);
+       }

Same value is set to tpid and tci.

Thanks! Fixed in V12.

Quoted 24 lines
Quoted 24 lines
net/openvswitch/flow.c +3 -0
+       return 0;
+}
+
  static int ovs_key_from_nlattrs(struct sw_flow_match *match, u64 attrs,
                                 const struct nlattr **a, bool is_mask,
                                 bool log) @@ -1024,6 +1047,105 @@

static void mask_set_nlattr(struct nlattr *attr, u8 val)

         nlattr_set(attr, val, ovs_key_lens);

}

net/openvswitch/flow.c +13 -0
+static int parse_vlan_from_nlattrs(const struct nlattr *nla,
+                                  struct sw_flow_match *match,
+                                  u64 *key_attrs, bool *ie_valid,
+                                  const struct nlattr **a, bool is_mask,
+                                  bool log) {
+       int err;
+       __be16 tci;
+       const struct nlattr *encap;
+
+       if (!is_mask) {
+               u64 v_attrs = 0;
+
+               tci = nla_get_be16(a[OVS_KEY_ATTR_VLAN]);
Quoted 8 lines

net/openvswitch/flow.c

Quoted 4 lines
net/openvswitch/flow.c +4 -0
+
+               if (tci & htons(VLAN_TAG_PRESENT)) {
+                       if (unlikely((nla_get_be16(a[OVS_KEY_ATTR_ETHERTYPE]) ==
+                                     htons(ETH_P_8021AD)))) {

Since we have added tpid to flow key, we have flexibility of supporting generic double encapsulation. Therefore in netlink parsing of key, double encap should not be limited to just 8021AD. for example it should allow 8021Q in 8021Q header as valid key.

I agree. Although Open Flow specification doesn't support non 802.1AD double tagged vlans, we probably should be as least restrictive as possible here in the kernel module. I recoded this in V12 to allow a more "generic" qinq.

Quoted 7 lines

net/openvswitch/flow.c

Quoted 7 lines
net/openvswitch/flow.c +6 -0
+                               err = parse_flow_nlattrs(nla, a, &v_attrs, log);
+                               if (err)
+                                       return err;
+                               if (!v_attrs)
+                                       return -EINVAL;
+

_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev
The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. www.wipro.com
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev

A message that is not in the archive (sent off-list or not yet received): SG2PR03MB07969B4C4555CB2E370AE8F3E48F0-ePYYJTVkT3RaLI7+W3dM6q82SN/[email protected]

#15 lore raw

Re: [PATCH net-next 3/3] openvswitch: 802.1AD: Flow handling, actions, and vlan parsing

Quoted 8 lines · On 7/26/15 9:57 AM, [email protected] wrote:

Hi Thomas,

I am currently using the beta version of ovs(2.3.90). In my phy-phy scenario , I am configuring the two physical ports(eth0, eth1) attached to ovs bridge as trunk ports using the below commands.

ovs-vsctl --no-wait add-port br0 eth0 vlan_mode=trunk ovs-vsctl --no-wait add-port br0 eth1 vlan_mode=trunk

Quoted 9 lines

I configured the bridge to work in legacy mode as shown below

$ ovs-ofctl dump-flows br0
NXST_FLOW reply (xid=0x4):
cookie=0x0, duration=15.458s, table=0, n_packets=0, n_bytes=0, idle_age=15, priority=0 actions=NORMAL

I tried sending 802.1ad tagged(outer tag tpid=0x88a8, inter tag tpid=ox8100) packet from packetgen to phyport1 (eth0), and receiving back on phyport2(eth2). When I captured the received packet on eth1 , the received packet is not same as sent packet, means outer vlan TPID is not 0x88a8(instead 0x8100).

This patch supports pushing and popping of double tagged vlans. It shouldn't affect double tagged traffic flowing through the switch unless your ovs bridge has flows to pop or push a vlan.

Are you using tcpdump to look at the packets? There is a bug in libpcap where the outer TPID of outgoing packets is miss-reported as 0x8100 whether or not the tpid is actually 0x88a8

Quoted 223 lines

Could you please let me know , whether the below mentioned patch helps here.

Thanks in Advance,
Uday

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Thomas F Herbert
Sent: Sunday, July 26, 2015 6:03 AM
To: Pravin Shelar
Cc: [email protected]; netdev; [email protected]
Subject: Re: [ovs-dev] [PATCH net-next 3/3] openvswitch: 802.1AD: Flow handling, actions, and vlan parsing

Quoted 1 line · Pravin Shelar

On Tue, Jun 23, 2015 at 11:26 AM, Thomas F Herbert

Pravin, I apologize because I realize now that I am finishing V12 of this patch that I never responded to your comments in this email.

Quoted 55 lines
Quoted 54 lines · <[email protected]> wrote:

Add support for 802.1ad including the ability to push and pop double tagged vlans. Add support for 802.1ad to netlink parsing and flow conversion. Uses double nested encap attributes to represent double tagged vlan. Inner TPID encoded along with ctci in nested attributes.

---
   net/openvswitch/flow.c         |  84 +++++++++++++++---
   net/openvswitch/flow.h         |   5 ++
   net/openvswitch/flow_netlink.c | 195 ++++++++++++++++++++++++++++++++++-------
   3 files changed, 242 insertions(+), 42 deletions(-)
net/openvswitch/flow.c index renamed from net/openvswitch/flow.c +0 -0

2dacc7b..e268865 100644

net/openvswitch/flow.c +28 -3
@@ -298,21 +298,80 @@ 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)))
+       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);
+
+               /* 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))) {
+                               key->eth.tci = 0;
+                               return 0;
+                       }
+
+                       if (unlikely(!pskb_may_pull(skb,
+                                                   sizeof(struct qtag_prefix) +
+                                                   sizeof(__be16)))) {
+                               return -ENOMEM;
+                       }
+
Quoted 8 lines

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

Quoted 5 lines
net/openvswitch/flow.c +5 -0
+                       if (likely(qp->eth_type == htons(ETH_P_8021Q))) {
+                               key->eth.cvlan.ctci =
+                                       qp->tci | htons(VLAN_TAG_PRESENT);
+                               key->eth.cvlan.c_tpid =
+ skb->vlan_proto;

We should directly copy qp->inner_tpid here. As you have done it for non offloaded case below.

Thanks! It is copied but it is set to the wrong tpid. The c_tpid field in the key should be set to the ethertype in the packet itself which is the inner tpid, not the offloaded skb-vlan_proto which is the outer tpid. Fixed in V12.

Quoted 53 lines
Quoted 53 lines
net/openvswitch/flow.c +37 -6
+                               __skb_pull(skb, sizeof(struct qtag_prefix));
+                       }
+               }
                  return 0;
+       }
 
-       if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
-                                        sizeof(__be16))))
-               return -ENOMEM;
 
-       qp = (struct qtag_prefix *) skb->data;
-       key->eth.tci = qp->tci | htons(VLAN_TAG_PRESENT);
-       __skb_pull(skb, sizeof(struct qtag_prefix));
+       if (qp->eth_type == htons(ETH_P_8021AD)) {
+               struct qinqtag_prefix *qinqp =
+                                       (struct qinqtag_prefix
+ *)skb->data;
+
+               if (unlikely(skb->len < sizeof(struct qinqtag_prefix) +
+                                       sizeof(__be16)))
+                       return 0;
+
+               if (unlikely(!pskb_may_pull(skb, sizeof(struct qinqtag_prefix) +
+                               sizeof(__be16)))) {
+                       return -ENOMEM;
+               }
+               key->eth.tci = qinqp->tci | htons(VLAN_TAG_PRESENT);
+               key->eth.cvlan.ctci = qinqp->ctci | htons(VLAN_TAG_PRESENT);
+               key->eth.cvlan.c_tpid = qinqp->inner_tpid;
+
+               __skb_pull(skb, sizeof(struct qinqtag_prefix));
+
+               return 0;
+       }
+       if (qp->eth_type == htons(ETH_P_8021Q)) {
+               if (unlikely(skb->len < sizeof(struct qtag_prefix) +
+                                       sizeof(__be16)))
+                       return -ENOMEM;
+
+               if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
+                               sizeof(__be16))))
+                       return 0;
+               key->eth.tci = qp->tci | htons(VLAN_TAG_PRESENT);
+
+               __skb_pull(skb, sizeof(struct qtag_prefix));
+       }
 
          return 0;
   }
@@ -474,9 +533,10 @@ static int key_extract(struct sk_buff *skb, struct sw_flow_key *key)
           */
 
Quoted 6 lines

net/openvswitch/flow.c static int key_extract(struct sk_buff *skb, struct sw_flow_key *key) · line 536

Quoted 5 lines
net/openvswitch/flow.c +1 -3
          key->eth.tci = 0;
-       if (skb_vlan_tag_present(skb))
-               key->eth.tci = htons(skb->vlan_tci);
-       else if (eth->h_proto == htons(ETH_P_8021Q))
+       key->eth.cvlan.ctci = 0;

cvlan.c_tpid is not initialized for all cases.

Fixed in V12

Quoted 5 lines

net/openvswitch/flow.c static int key_extract(struct sk_buff *skb, struct sw_flow_key *key) · line 539

Quoted 4 lines
net/openvswitch/flow.c +3 -0
+       if ((skb_vlan_tag_present(skb)) ||
+           (eth->h_proto == htons(ETH_P_8021Q)) ||
+           (eth->h_proto == htons(ETH_P_8021AD)))

These are redundant check. so we can directly call this function.

I don't agree that these 3 checks are redundant. parse_vlan parses both the offloaded and non-offloaded cases. In V12, I changed it to call eth_type_vlan() to do the checks for the non-offloaded ethertypes.

Hmmm ... maybe I should add another function to if_vlan.h to check if a packet is a vlan regardless of whether it is offloaded or not?

Quoted 20 lines
Quoted 4 lines
net/openvswitch/flow.c +0 -0
                  if (unlikely(parse_vlan(skb, key)))
                          return -ENOMEM;
 

...

Quoted 14 lines
net/openvswitch/flow.c +13 -0
+static int cust_vlan_from_nlattrs(struct sw_flow_match *match, u64 attrs,
+                                 const struct nlattr **a, bool is_mask,
+                                 bool log) {
+       /* This should be nested inner or "customer" tci" */
+       if (attrs & (1 << OVS_KEY_ATTR_VLAN)) {
+               __be16 ctci;
+
+               ctci = nla_get_be16(a[OVS_KEY_ATTR_VLAN]);
+               if (!(ctci & htons(VLAN_TAG_PRESENT))) {
+                       if (is_mask)
+                               OVS_NLERR(log, "VLAN CTCI mask does not have exact match for VLAN_TAG_PRESENT bit.");
+                       else
+                               OVS_NLERR(log, "VLAN CTCI does not
Quoted 8 lines

net/openvswitch/flow.c

Quoted 7 lines

+ have VLAN_TAG_PRESENT bit set.");

net/openvswitch/flow.c +6 -0
+
+                       return -EINVAL;
+               }
+               SW_FLOW_KEY_PUT(match, eth.cvlan.c_tpid, ctci, is_mask);
+               SW_FLOW_KEY_PUT(match, eth.cvlan.ctci, ctci, is_mask);
+       }

Same value is set to tpid and tci.

Thanks! Fixed in V12.

Quoted 24 lines
Quoted 24 lines
net/openvswitch/flow.c +3 -0
+       return 0;
+}
+
   static int ovs_key_from_nlattrs(struct sw_flow_match *match, u64 attrs,
                                  const struct nlattr **a, bool is_mask,
                                  bool log) @@ -1024,6 +1047,105 @@

static void mask_set_nlattr(struct nlattr *attr, u8 val)

          nlattr_set(attr, val, ovs_key_lens);

}

net/openvswitch/flow.c +13 -0
+static int parse_vlan_from_nlattrs(const struct nlattr *nla,
+                                  struct sw_flow_match *match,
+                                  u64 *key_attrs, bool *ie_valid,
+                                  const struct nlattr **a, bool is_mask,
+                                  bool log) {
+       int err;
+       __be16 tci;
+       const struct nlattr *encap;
+
+       if (!is_mask) {
+               u64 v_attrs = 0;
+
+               tci = nla_get_be16(a[OVS_KEY_ATTR_VLAN]);
Quoted 8 lines

net/openvswitch/flow.c

Quoted 4 lines
net/openvswitch/flow.c +4 -0
+
+               if (tci & htons(VLAN_TAG_PRESENT)) {
+                       if (unlikely((nla_get_be16(a[OVS_KEY_ATTR_ETHERTYPE]) ==
+                                     htons(ETH_P_8021AD)))) {

Since we have added tpid to flow key, we have flexibility of supporting generic double encapsulation. Therefore in netlink parsing of key, double encap should not be limited to just 8021AD. for example it should allow 8021Q in 8021Q header as valid key.

I agree. Although Open Flow specification doesn't support non 802.1AD double tagged vlans, we probably should be as least restrictive as possible here in the kernel module. I recoded this in V12 to allow a more "generic" qinq.

Quoted 7 lines

net/openvswitch/flow.c

Quoted 7 lines
net/openvswitch/flow.c +6 -0
+                               err = parse_flow_nlattrs(nla, a, &v_attrs, log);
+                               if (err)
+                                       return err;
+                               if (!v_attrs)
+                                       return -EINVAL;
+

_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev

Signature · 5 lines
Thomas F Herbert Red Hat
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev

A message that is not in the archive (sent off-list or not yet received): [email protected]

#17 lore raw

Re: [PATCH net-next 3/3] openvswitch: 802.1AD: Flow handling, actions, and vlan parsing

Hi Thomas,

Thank you very much for your response.
Does this patch adds 802.1ad tag on ingress and pops the same on egress by default? or is it to be configured via ofctl commands explicitly?

Thanks in Advance,
Uday

________________________________________
From: Thomas F Herbert <[email protected]>
Sent: Sunday, July 26, 2015 8:03 PM
To: Ravulakollu Udaya Kumar (WT01 - Digital Marketing); [email protected]; [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [ovs-dev] [PATCH net-next 3/3] openvswitch: 802.1AD: Flow handling, actions, and vlan parsing

Quoted 8 lines · On 7/26/15 9:57 AM, [email protected] wrote:

Hi Thomas,

I am currently using the beta version of ovs(2.3.90). In my phy-phy scenario , I am configuring the two physical ports(eth0, eth1) attached to ovs bridge as trunk ports using the below commands.

ovs-vsctl --no-wait add-port br0 eth0 vlan_mode=trunk ovs-vsctl --no-wait add-port br0 eth1 vlan_mode=trunk

Quoted 9 lines

I configured the bridge to work in legacy mode as shown below

$ ovs-ofctl dump-flows br0
NXST_FLOW reply (xid=0x4):
cookie=0x0, duration=15.458s, table=0, n_packets=0, n_bytes=0, idle_age=15, priority=0 actions=NORMAL

I tried sending 802.1ad tagged(outer tag tpid=0x88a8, inter tag tpid=ox8100) packet from packetgen to phyport1 (eth0), and receiving back on phyport2(eth2). When I captured the received packet on eth1 , the received packet is not same as sent packet, means outer vlan TPID is not 0x88a8(instead 0x8100).

This patch supports pushing and popping of double tagged vlans. It shouldn't affect double tagged traffic flowing through the switch unless your ovs bridge has flows to pop or push a vlan.

Are you using tcpdump to look at the packets? There is a bug in libpcap where the outer TPID of outgoing packets is miss-reported as 0x8100 whether or not the tpid is actually 0x88a8

Quoted 218 lines

Could you please let me know , whether the below mentioned patch helps here.

Thanks in Advance,
Uday

-----Original Message-----
From: dev [mailto:[email protected]] On Behalf Of Thomas F Herbert
Sent: Sunday, July 26, 2015 6:03 AM
To: Pravin Shelar
Cc: [email protected]; netdev; [email protected]
Subject: Re: [ovs-dev] [PATCH net-next 3/3] openvswitch: 802.1AD: Flow handling, actions, and vlan parsing

Quoted 1 line · Pravin Shelar

On Tue, Jun 23, 2015 at 11:26 AM, Thomas F Herbert

Pravin, I apologize because I realize now that I am finishing V12 of this patch that I never responded to your comments in this email.

Quoted 55 lines
Quoted 54 lines · <[email protected]> wrote:

Add support for 802.1ad including the ability to push and pop double tagged vlans. Add support for 802.1ad to netlink parsing and flow conversion. Uses double nested encap attributes to represent double tagged vlan. Inner TPID encoded along with ctci in nested attributes.

---
   net/openvswitch/flow.c         |  84 +++++++++++++++---
   net/openvswitch/flow.h         |   5 ++
   net/openvswitch/flow_netlink.c | 195 ++++++++++++++++++++++++++++++++++-------
   3 files changed, 242 insertions(+), 42 deletions(-)
net/openvswitch/flow.c index renamed from net/openvswitch/flow.c +0 -0

2dacc7b..e268865 100644

net/openvswitch/flow.c +28 -3
@@ -298,21 +298,80 @@ 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)))
+       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);
+
+               /* 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))) {
+                               key->eth.tci = 0;
+                               return 0;
+                       }
+
+                       if (unlikely(!pskb_may_pull(skb,
+                                                   sizeof(struct qtag_prefix) +
+                                                   sizeof(__be16)))) {
+                               return -ENOMEM;
+                       }
+
Quoted 8 lines

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

Quoted 5 lines
net/openvswitch/flow.c +5 -0
+                       if (likely(qp->eth_type == htons(ETH_P_8021Q))) {
+                               key->eth.cvlan.ctci =
+                                       qp->tci | htons(VLAN_TAG_PRESENT);
+                               key->eth.cvlan.c_tpid =
+ skb->vlan_proto;

We should directly copy qp->inner_tpid here. As you have done it for non offloaded case below.

Thanks! It is copied but it is set to the wrong tpid. The c_tpid field in the key should be set to the ethertype in the packet itself which is the inner tpid, not the offloaded skb-vlan_proto which is the outer tpid. Fixed in V12.

Quoted 53 lines
Quoted 53 lines
net/openvswitch/flow.c +37 -6
+                               __skb_pull(skb, sizeof(struct qtag_prefix));
+                       }
+               }
                  return 0;
+       }
 
-       if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
-                                        sizeof(__be16))))
-               return -ENOMEM;
 
-       qp = (struct qtag_prefix *) skb->data;
-       key->eth.tci = qp->tci | htons(VLAN_TAG_PRESENT);
-       __skb_pull(skb, sizeof(struct qtag_prefix));
+       if (qp->eth_type == htons(ETH_P_8021AD)) {
+               struct qinqtag_prefix *qinqp =
+                                       (struct qinqtag_prefix
+ *)skb->data;
+
+               if (unlikely(skb->len < sizeof(struct qinqtag_prefix) +
+                                       sizeof(__be16)))
+                       return 0;
+
+               if (unlikely(!pskb_may_pull(skb, sizeof(struct qinqtag_prefix) +
+                               sizeof(__be16)))) {
+                       return -ENOMEM;
+               }
+               key->eth.tci = qinqp->tci | htons(VLAN_TAG_PRESENT);
+               key->eth.cvlan.ctci = qinqp->ctci | htons(VLAN_TAG_PRESENT);
+               key->eth.cvlan.c_tpid = qinqp->inner_tpid;
+
+               __skb_pull(skb, sizeof(struct qinqtag_prefix));
+
+               return 0;
+       }
+       if (qp->eth_type == htons(ETH_P_8021Q)) {
+               if (unlikely(skb->len < sizeof(struct qtag_prefix) +
+                                       sizeof(__be16)))
+                       return -ENOMEM;
+
+               if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
+                               sizeof(__be16))))
+                       return 0;
+               key->eth.tci = qp->tci | htons(VLAN_TAG_PRESENT);
+
+               __skb_pull(skb, sizeof(struct qtag_prefix));
+       }
 
          return 0;
   }
@@ -474,9 +533,10 @@ static int key_extract(struct sk_buff *skb, struct sw_flow_key *key)
           */
 
Quoted 6 lines

net/openvswitch/flow.c static int key_extract(struct sk_buff *skb, struct sw_flow_key *key) · line 536

Quoted 5 lines
net/openvswitch/flow.c +1 -3
          key->eth.tci = 0;
-       if (skb_vlan_tag_present(skb))
-               key->eth.tci = htons(skb->vlan_tci);
-       else if (eth->h_proto == htons(ETH_P_8021Q))
+       key->eth.cvlan.ctci = 0;

cvlan.c_tpid is not initialized for all cases.

Fixed in V12

Quoted 5 lines

net/openvswitch/flow.c static int key_extract(struct sk_buff *skb, struct sw_flow_key *key) · line 539

Quoted 4 lines
net/openvswitch/flow.c +3 -0
+       if ((skb_vlan_tag_present(skb)) ||
+           (eth->h_proto == htons(ETH_P_8021Q)) ||
+           (eth->h_proto == htons(ETH_P_8021AD)))

These are redundant check. so we can directly call this function.

I don't agree that these 3 checks are redundant. parse_vlan parses both the offloaded and non-offloaded cases. In V12, I changed it to call eth_type_vlan() to do the checks for the non-offloaded ethertypes.

Hmmm ... maybe I should add another function to if_vlan.h to check if a packet is a vlan regardless of whether it is offloaded or not?

Quoted 20 lines
Quoted 4 lines
net/openvswitch/flow.c +0 -0
                  if (unlikely(parse_vlan(skb, key)))
                          return -ENOMEM;
 

...

Quoted 14 lines
net/openvswitch/flow.c +13 -0
+static int cust_vlan_from_nlattrs(struct sw_flow_match *match, u64 attrs,
+                                 const struct nlattr **a, bool is_mask,
+                                 bool log) {
+       /* This should be nested inner or "customer" tci" */
+       if (attrs & (1 << OVS_KEY_ATTR_VLAN)) {
+               __be16 ctci;
+
+               ctci = nla_get_be16(a[OVS_KEY_ATTR_VLAN]);
+               if (!(ctci & htons(VLAN_TAG_PRESENT))) {
+                       if (is_mask)
+                               OVS_NLERR(log, "VLAN CTCI mask does not have exact match for VLAN_TAG_PRESENT bit.");
+                       else
+                               OVS_NLERR(log, "VLAN CTCI does not
Quoted 8 lines

net/openvswitch/flow.c

Quoted 7 lines

+ have VLAN_TAG_PRESENT bit set.");

net/openvswitch/flow.c +6 -0
+
+                       return -EINVAL;
+               }
+               SW_FLOW_KEY_PUT(match, eth.cvlan.c_tpid, ctci, is_mask);
+               SW_FLOW_KEY_PUT(match, eth.cvlan.ctci, ctci, is_mask);
+       }

Same value is set to tpid and tci.

Thanks! Fixed in V12.

Quoted 24 lines
Quoted 24 lines
net/openvswitch/flow.c +3 -0
+       return 0;
+}
+
   static int ovs_key_from_nlattrs(struct sw_flow_match *match, u64 attrs,
                                  const struct nlattr **a, bool is_mask,
                                  bool log) @@ -1024,6 +1047,105 @@

static void mask_set_nlattr(struct nlattr *attr, u8 val)

          nlattr_set(attr, val, ovs_key_lens);

}

net/openvswitch/flow.c +13 -0
+static int parse_vlan_from_nlattrs(const struct nlattr *nla,
+                                  struct sw_flow_match *match,
+                                  u64 *key_attrs, bool *ie_valid,
+                                  const struct nlattr **a, bool is_mask,
+                                  bool log) {
+       int err;
+       __be16 tci;
+       const struct nlattr *encap;
+
+       if (!is_mask) {
+               u64 v_attrs = 0;
+
+               tci = nla_get_be16(a[OVS_KEY_ATTR_VLAN]);
Quoted 8 lines

net/openvswitch/flow.c

Quoted 4 lines
net/openvswitch/flow.c +4 -0
+
+               if (tci & htons(VLAN_TAG_PRESENT)) {
+                       if (unlikely((nla_get_be16(a[OVS_KEY_ATTR_ETHERTYPE]) ==
+                                     htons(ETH_P_8021AD)))) {

Since we have added tpid to flow key, we have flexibility of supporting generic double encapsulation. Therefore in netlink parsing of key, double encap should not be limited to just 8021AD. for example it should allow 8021Q in 8021Q header as valid key.

I agree. Although Open Flow specification doesn't support non 802.1AD double tagged vlans, we probably should be as least restrictive as possible here in the kernel module. I recoded this in V12 to allow a more "generic" qinq.

Quoted 7 lines

net/openvswitch/flow.c

Quoted 7 lines
net/openvswitch/flow.c +6 -0
+                               err = parse_flow_nlattrs(nla, a, &v_attrs, log);
+                               if (err)
+                                       return err;
+                               if (!v_attrs)
+                                       return -EINVAL;
+
Quoted 5 lines

_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev

--
Thomas F Herbert Red Hat
The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. www.wipro.com
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev