Skip to contentSkip to conversation

openvswitch: Add support for 802.1ad

PATCH Superseded Thomas F Herbert 5 participants 12 messages Oct 18, 2015 – Oct 23, 2015 6 messages not in the archive

Subsystems (3)

v17 of 20 Superseded Latest is v20 →

lore
Share & tools
lore
#0 lore raw

v17 cover openvswitch: Add support for 802.1ad

V17,V16: Implement reviewer's comments.

V15: Implement reviewer comments.

V14: Add outer tpid to flow_key

V13: Fix incorrect encoding and decoding of netlink to/from key attributes.

V12: Fix some problems and issues pointed out by reviewers. When parsing netlink attributes Ether types other then 0x88a8 as outer tpid.

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

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          |  16 ++++
 include/uapi/linux/openvswitch.h |  17 ++--
 net/openvswitch/actions.c        |   6 +-
 net/openvswitch/flow.c           |  76 +++++++++++++----
 net/openvswitch/flow.h           |   8 +-
 net/openvswitch/flow_netlink.c   | 172 +++++++++++++++++++++++++++++++++++----
 net/openvswitch/vport-netdev.c   |   4 +-
 7 files changed, 252 insertions(+), 47 deletions(-)
Signature · 6 lines
2.4.3

_______________________________________________
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): 1445130748-27671-1-git-send-email-thomasfherbert-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#2 lore raw

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

---
 include/linux/if_vlan.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
include/linux/if_vlan.h +16 -0
index 67ce5bd..d2494b5 100644
@@ -627,6 +627,22 @@ static inline netdev_features_t vlan_features_check(const struct sk_buff *skb,
 
 	return features;
 }
+/**
+ * eth_type_vlan - check for valid vlan ether type.
+ * @ethertype: ether type to check
+ *
+ * Returns true if the ether type is a vlan ether type.
+ */
+static inline bool eth_type_vlan(__be16 ethertype)
+{
+	switch (ethertype) {
+	case htons(ETH_P_8021Q):
+	case htons(ETH_P_8021AD):
+		return true;
+	default:
+		return false;
+	}
+}
 
 /**
  * compare_vlan_header - Compare two vlan headers
Signature · 6 lines
2.4.3

_______________________________________________
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): 1445130748-27671-3-git-send-email-thomasfherbert-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#5 lore raw

PATCH v17 3/3 802.1AD: Flow handling, actions, vlan parsing and netlink attributes

In reply to a message not in the archive

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/actions.c      |   6 +-
 net/openvswitch/flow.c         |  76 +++++++++++++-----
 net/openvswitch/flow.h         |   8 +-
 net/openvswitch/flow_netlink.c | 172 +++++++++++++++++++++++++++++++++++++----
 net/openvswitch/vport-netdev.c |   4 +-
 5 files changed, 227 insertions(+), 39 deletions(-)
net/openvswitch/actions.c +4 -2
index 315f533..09cc1c9 100644
@@ -236,7 +236,8 @@ static int pop_vlan(struct sk_buff *skb, struct sw_flow_key *key)
 	if (skb_vlan_tag_present(skb))
 		invalidate_flow_key(key);
 	else
-		key->eth.tci = 0;
+		key->eth.vlan.tci = 0;
+		key->eth.vlan.tpid = 0;
 	return err;
 }
 
@@ -246,7 +247,8 @@ static int push_vlan(struct sk_buff *skb, struct sw_flow_key *key,
 	if (skb_vlan_tag_present(skb))
 		invalidate_flow_key(key);
 	else
-		key->eth.tci = vlan->vlan_tci;
+		key->eth.vlan.tci = vlan->vlan_tci;
+		key->eth.vlan.tpid = vlan->vlan_tpid;
 	return skb_vlan_push(skb, vlan->vlan_tpid,
 			     ntohs(vlan->vlan_tci) & ~VLAN_TAG_PRESENT);
 }
net/openvswitch/flow.c +58 -18

94 lines not on this page · raw message

net/openvswitch/flow.h +7 -1
index fe527d2..7ea8deb 100644
@@ -50,6 +50,11 @@ struct ovs_tunnel_info {
 	struct metadata_dst	*tun_dst;
 };
 
+struct vlan_head {
+	__be16 tpid;	/* Vlan type. Generally 802.1q or 802.1ad.*/
+	__be16 tci;	/* 0 if no VLAN, VLAN_TAG_PRESENT set otherwise. */
+};
+
 #define OVS_SW_FLOW_KEY_METADATA_SIZE			\
 	(offsetof(struct sw_flow_key, recirc_id) +	\
 	FIELD_SIZEOF(struct sw_flow_key, recirc_id))
@@ -68,7 +73,8 @@ struct sw_flow_key {
 	struct {
 		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 vlan_head vlan;
+		struct vlan_head cvlan;
 		__be16 type;		/* Ethernet frame type. */
 	} eth;
 	union {
net/openvswitch/flow_netlink.c +155 -17

260 lines not on this page · raw message

net/openvswitch/vport-netdev.c +3 -1
index f7e8dcc..d2581b7 100644
@@ -194,7 +194,9 @@ static unsigned int packet_length(const struct sk_buff *skb)
 {
 	unsigned int length = skb->len - ETH_HLEN;
 
-	if (skb->protocol == htons(ETH_P_8021Q))
+	if (eth_type_vlan(skb->protocol))
+		length -= VLAN_HLEN;
+	if (skb->protocol == htons(ETH_P_8021AD))
 		length -= VLAN_HLEN;
 
 	return length;
Signature · 6 lines
2.4.3

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

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

Quoted 16 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/actions.c      |   6 +-
 net/openvswitch/flow.c         |  76 +++++++++++++-----
 net/openvswitch/flow.h         |   8 +-
 net/openvswitch/flow_netlink.c | 172 +++++++++++++++++++++++++++++++++++++----
 net/openvswitch/vport-netdev.c |   4 +-
 5 files changed, 227 insertions(+), 39 deletions(-)
net/openvswitch/actions.c +0 -0
index 315f533..09cc1c9 100644

...

Quoted 4 lines
net/openvswitch/flow_netlink.c +0 -0
index c92d6a2..97a6d12 100644

...

Quoted 32 lines
net/openvswitch/flow_netlink.c +11 -7
@@ -1320,6 +1443,7 @@ static int __ovs_nla_put_key(const struct sw_flow_key *swkey,
 {
        struct ovs_key_ethernet *eth_key;
        struct nlattr *nla, *encap;
+       struct nlattr *in_encap = NULL;
 
        if (nla_put_u32(skb, OVS_KEY_ATTR_RECIRC_ID, output->recirc_id))
                goto nla_put_failure;
@@ -1368,17 +1492,29 @@ static int __ovs_nla_put_key(const struct sw_flow_key *swkey,
        ether_addr_copy(eth_key->eth_src, output->eth.src);
        ether_addr_copy(eth_key->eth_dst, output->eth.dst);
 
-       if (swkey->eth.tci || swkey->eth.type == htons(ETH_P_8021Q)) {
-               __be16 eth_type;
-               eth_type = !is_mask ? htons(ETH_P_8021Q) : htons(0xffff);
-               if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE, eth_type) ||
-                   nla_put_be16(skb, OVS_KEY_ATTR_VLAN, output->eth.tci))
+       if (swkey->eth.vlan.tci || eth_type_vlan(swkey->eth.type)) {
+               if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE,
+                                output->eth.vlan.tpid) ||
+                   nla_put_be16(skb, OVS_KEY_ATTR_VLAN, output->eth.vlan.tci))
                        goto nla_put_failure;
                encap = nla_nest_start(skb, OVS_KEY_ATTR_ENCAP);
-               if (!swkey->eth.tci)
+               if (!swkey->eth.vlan.tci)
                        goto unencap;
-       } else
+               if (swkey->eth.cvlan.tci) {
+                       /* Customer tci is nested but uses same key attribute.
+                        */
+                       if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE,
+                                        output->eth.cvlan.tpid) ||

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

Quoted 10 lines
net/openvswitch/flow_netlink.c +9 -0
+                           nla_put_be16(skb, OVS_KEY_ATTR_VLAN,
+                                        output->eth.cvlan.tci))
+                               goto nla_put_failure;
+                       in_encap = nla_nest_start(skb, OVS_KEY_ATTR_ENCAP);
+                       if (!swkey->eth.cvlan.tci)
+                               goto unencap;
+               }
+       } else {
                encap = NULL;
+       }

After the vlan parsing changes, we need to encode cvlan in outer netlink attribute and then encode regular vlan. Currently we are reversing netlink encoding while sending back the vlan attributes. cvlan and vlan is independent, therefore we need to check swkey->eth.cvlan.tc outside of swkey->eth.vlan.tci block. Also redundant check for swkey->eth.cvlan.tci should be removed.

Can you also post changes for userspace vswitchd so that I can try next patch.

#7 lore raw

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

Quoted 62 lines · Pravin Shelar
Quoted 16 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/actions.c      |   6 +-
  net/openvswitch/flow.c         |  76 +++++++++++++-----
  net/openvswitch/flow.h         |   8 +-
  net/openvswitch/flow_netlink.c | 172 +++++++++++++++++++++++++++++++++++++----
  net/openvswitch/vport-netdev.c |   4 +-
  5 files changed, 227 insertions(+), 39 deletions(-)
net/openvswitch/actions.c +0 -0
index 315f533..09cc1c9 100644

...

Quoted 4 lines
net/openvswitch/flow_netlink.c +0 -0
index c92d6a2..97a6d12 100644

...

Quoted 36 lines
net/openvswitch/flow_netlink.c +15 -7
@@ -1320,6 +1443,7 @@ static int __ovs_nla_put_key(const struct sw_flow_key *swkey,
  {
         struct ovs_key_ethernet *eth_key;
         struct nlattr *nla, *encap;
+       struct nlattr *in_encap = NULL;
 
         if (nla_put_u32(skb, OVS_KEY_ATTR_RECIRC_ID, output->recirc_id))
                 goto nla_put_failure;
@@ -1368,17 +1492,29 @@ static int __ovs_nla_put_key(const struct sw_flow_key *swkey,
         ether_addr_copy(eth_key->eth_src, output->eth.src);
         ether_addr_copy(eth_key->eth_dst, output->eth.dst);
 
-       if (swkey->eth.tci || swkey->eth.type == htons(ETH_P_8021Q)) {
-               __be16 eth_type;
-               eth_type = !is_mask ? htons(ETH_P_8021Q) : htons(0xffff);
-               if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE, eth_type) ||
-                   nla_put_be16(skb, OVS_KEY_ATTR_VLAN, output->eth.tci))
+       if (swkey->eth.vlan.tci || eth_type_vlan(swkey->eth.type)) {
+               if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE,
+                                output->eth.vlan.tpid) ||
+                   nla_put_be16(skb, OVS_KEY_ATTR_VLAN, output->eth.vlan.tci))
                         goto nla_put_failure;
                 encap = nla_nest_start(skb, OVS_KEY_ATTR_ENCAP);
-               if (!swkey->eth.tci)
+               if (!swkey->eth.vlan.tci)
                         goto unencap;
-       } else
+               if (swkey->eth.cvlan.tci) {
+                       /* Customer tci is nested but uses same key attribute.
+                        */
+                       if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE,
+                                        output->eth.cvlan.tpid) ||
+                           nla_put_be16(skb, OVS_KEY_ATTR_VLAN,
+                                        output->eth.cvlan.tci))
+                               goto nla_put_failure;
+                       in_encap = nla_nest_start(skb, OVS_KEY_ATTR_ENCAP);
Quoted 8 lines

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

Quoted 6 lines
net/openvswitch/flow_netlink.c +5 -0
+                       if (!swkey->eth.cvlan.tci)
+                               goto unencap;
+               }
+       } else {
                 encap = NULL;
+       }

After the vlan parsing changes, we need to encode cvlan in outer netlink attribute and then encode regular vlan.

I don't understand this. cvlan is inner vlan, why would it be encoded in outer vlan without the 2nd layer of encapsulation?

One think I see I should have done is check for eth_type_vlan() on the inner tag as well.

Quoted 3 lines

Currently we are
reversing netlink encoding while sending back the vlan attributes. cvlan and vlan is independent,

Are you talking about a corner case where the incoming packet has an inner vlan but no outer vlN?

Quoted 3 lines

therefore we need to check
swkey->eth.cvlan.tc outside of swkey->eth.vlan.tci block. Also redundant check for swkey->eth.cvlan.tci should be removed

I must be missing something because I don't understand this either. First my patch encodes the outer vlan and then sets the encap bit and then encodes the inner vlan. The encoding shows up correctly in user space.

Quoted 2 lines

Can you also post changes for userspace vswitchd so that I can try next patch.

I posted a patch for user space (V14) to ovs dev on October 2nd. I haven't made any changes since then.
http://openvswitch.org/pipermail/dev/2015-October/060874.html

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

#9 lore raw

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

Quoted 86 lines · Thomas F Herbert
Quoted 76 lines · Pravin Shelar
Quoted 18 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/actions.c      |   6 +-
  net/openvswitch/flow.c         |  76 +++++++++++++-----
  net/openvswitch/flow.h         |   8 +-
  net/openvswitch/flow_netlink.c | 172
+++++++++++++++++++++++++++++++++++++----
  net/openvswitch/vport-netdev.c |   4 +-
  5 files changed, 227 insertions(+), 39 deletions(-)
net/openvswitch/actions.c +0 -0
index 315f533..09cc1c9 100644

...

Quoted 5 lines
net/openvswitch/flow_netlink.c +0 -0
index c92d6a2..97a6d12 100644

...

Quoted 44 lines
net/openvswitch/flow_netlink.c +1 -0
@@ -1320,6 +1443,7 @@ static int __ovs_nla_put_key(const struct
 sw_flow_key *swkey,
  {
         struct ovs_key_ethernet *eth_key;
         struct nlattr *nla, *encap;
+       struct nlattr *in_encap = NULL;
 
         if (nla_put_u32(skb, OVS_KEY_ATTR_RECIRC_ID, output->recirc_id))
                 goto nla_put_failure;
net/openvswitch/flow_netlink.c +0 -4
@@ -1368,17 +1492,29 @@ static int __ovs_nla_put_key(const struct
 sw_flow_key *swkey,
         ether_addr_copy(eth_key->eth_src, output->eth.src);
         ether_addr_copy(eth_key->eth_dst, output->eth.dst);
 
-       if (swkey->eth.tci || swkey->eth.type == htons(ETH_P_8021Q)) {
-               __be16 eth_type;
-               eth_type = !is_mask ? htons(ETH_P_8021Q) : htons(0xffff);
-               if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE, eth_type)
||
-                   nla_put_be16(skb, OVS_KEY_ATTR_VLAN,

output->eth.tci))

net/openvswitch/flow_netlink.c +4 -0
+       if (swkey->eth.vlan.tci || eth_type_vlan(swkey->eth.type)) {
+               if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE,
+                                output->eth.vlan.tpid) ||
+                   nla_put_be16(skb, OVS_KEY_ATTR_VLAN,

output->eth.vlan.tci))

                         goto nla_put_failure;
                 encap = nla_nest_start(skb, OVS_KEY_ATTR_ENCAP);
net/openvswitch/flow_netlink.c +3 -2
-               if (!swkey->eth.tci)
+               if (!swkey->eth.vlan.tci)
                         goto unencap;
-       } else
+               if (swkey->eth.cvlan.tci) {
+                       /* Customer tci is nested but uses same key

attribute.

net/openvswitch/flow_netlink.c +7 -0
+                        */
+                       if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE,
+                                        output->eth.cvlan.tpid) ||
+                           nla_put_be16(skb, OVS_KEY_ATTR_VLAN,
+                                        output->eth.cvlan.tci))
+                               goto nla_put_failure;
+                       in_encap = nla_nest_start(skb,

OVS_KEY_ATTR_ENCAP);
+ if (!swkey->eth.cvlan.tci)

Quoted 8 lines

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

Quoted 5 lines
net/openvswitch/flow_netlink.c +4 -0
+                               goto unencap;
+               }
+       } else {
                 encap = NULL;
+       }

After the vlan parsing changes, we need to encode cvlan in outer netlink attribute and then encode regular vlan.

Quoted 3 lines

I don't understand this. cvlan is inner vlan, why would it be encoded in outer vlan without the 2nd layer of encapsulation?

Lets start with double tagged packet.
packet: eth, vlan 10, inner vlan 20, ip.
flow key would be:
flow_key: vlan = 10, cvlan = 20
That would get serialize over netlink like:
eth_type(0x8100),vlan(vid=10,pcp=0),encap(eth_type(0x8100),vlan(vid=20,pcp=0), encap(eth_type(0x0800),ipv4(frag=no))...
So far looks good.

Now userspace sends back same key and installs flow in kernel datapath. But ovs_nla_get_match() parses netink key and sets vlan in reverse order. After parsing netlink in ovs_nla_get_match() vlans flow-key would look like:
flow_key: vlan = 20, cvlan = 10. This is not what we started with.

Now I think rather than fixing __ovs_nla_put_key (), we need to fix ovs_nla_get_match() to keep vlan order.
I also noticed that eth.vlan.tpid is never initialized from netlink attributes. Call to parse_flow_nlattrs in parse_vlan_from_nlattrs() has no effect so it should be removed.

Quoted 10 lines

One think I see I should have done is check for eth_type_vlan() on the inner tag as well.

Quoted 4 lines

Currently we are
reversing netlink encoding while sending back the vlan attributes. cvlan and vlan is independent,

Are you talking about a corner case where the incoming packet has an inner vlan but no outer vlN?

Quoted 1 line

nope, this is usual case.

Quoted 8 lines
Quoted 3 lines

therefore we need to check
swkey->eth.cvlan.tc outside of swkey->eth.vlan.tci block. Also redundant check for swkey->eth.cvlan.tci should be removed

I must be missing something because I don't understand this either. First my patch encodes the outer vlan and then sets the encap bit and then encodes the inner vlan. The encoding shows up correctly in user space.

Quoted 1 line

Once ovs_nla_get_match() is fixed, there is no need to change this function to fix that ordering.

I was talking about following redundant check:

                if (swkey->eth.cvlan.tci) {
                        /* Customer tci is nested but uses same key attribute.
                         */
                        if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE,
                                         output->eth.cvlan.tpid) ||
                            nla_put_be16(skb, OVS_KEY_ATTR_VLAN,
                                         output->eth.cvlan.tci))
                                goto nla_put_failure;
                        in_encap = nla_nest_start(skb, OVS_KEY_ATTR_ENCAP);
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
              if (!swkey->eth.cvlan.tci)  <<<<<<<<<<<<<
                                goto unencap;
                }
Quoted 8 lines
Quoted 3 lines

Can you also post changes for userspace vswitchd so that I can try next patch.

I posted a patch for user space (V14) to ovs dev on October 2nd. I haven't made any changes since then.
http://openvswitch.org/pipermail/dev/2015-October/060874.html

That patch does not apply on OVS master. You could also send me link to ovs userpsace github repo with these patches applied so that I can try kernel datapath changes.
_______________________________________________
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+rjNNwvuRRa2hktwHukTvnTx=AC4PegiAvwOT9UGtZKFw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#11 lore raw

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

Quoted 100 lines · Pravin Shelar
Quoted 80 lines · Thomas F Herbert
Quoted 71 lines · Pravin Shelar
Quoted 17 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/actions.c      |   6 +-
   net/openvswitch/flow.c         |  76 +++++++++++++-----
   net/openvswitch/flow.h         |   8 +-
   net/openvswitch/flow_netlink.c | 172
+++++++++++++++++++++++++++++++++++++----
   net/openvswitch/vport-netdev.c |   4 +-
   5 files changed, 227 insertions(+), 39 deletions(-)
net/openvswitch/actions.c +0 -0
index 315f533..09cc1c9 100644

...

Quoted 5 lines
net/openvswitch/flow_netlink.c +0 -0
index c92d6a2..97a6d12 100644

...

Quoted 43 lines
net/openvswitch/flow_netlink.c +1 -0
@@ -1320,6 +1443,7 @@ static int __ovs_nla_put_key(const struct
 sw_flow_key *swkey,
   {
          struct ovs_key_ethernet *eth_key;
          struct nlattr *nla, *encap;
+       struct nlattr *in_encap = NULL;
 
          if (nla_put_u32(skb, OVS_KEY_ATTR_RECIRC_ID, output->recirc_id))
                  goto nla_put_failure;
net/openvswitch/flow_netlink.c +0 -4
@@ -1368,17 +1492,29 @@ static int __ovs_nla_put_key(const struct
 sw_flow_key *swkey,
          ether_addr_copy(eth_key->eth_src, output->eth.src);
          ether_addr_copy(eth_key->eth_dst, output->eth.dst);
 
-       if (swkey->eth.tci || swkey->eth.type == htons(ETH_P_8021Q)) {
-               __be16 eth_type;
-               eth_type = !is_mask ? htons(ETH_P_8021Q) : htons(0xffff);
-               if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE, eth_type)
||
-                   nla_put_be16(skb, OVS_KEY_ATTR_VLAN,

output->eth.tci))

net/openvswitch/flow_netlink.c +4 -0
+       if (swkey->eth.vlan.tci || eth_type_vlan(swkey->eth.type)) {
+               if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE,
+                                output->eth.vlan.tpid) ||
+                   nla_put_be16(skb, OVS_KEY_ATTR_VLAN,

output->eth.vlan.tci))

                          goto nla_put_failure;
                  encap = nla_nest_start(skb, OVS_KEY_ATTR_ENCAP);
net/openvswitch/flow_netlink.c +3 -2
-               if (!swkey->eth.tci)
+               if (!swkey->eth.vlan.tci)
                          goto unencap;
-       } else
+               if (swkey->eth.cvlan.tci) {
+                       /* Customer tci is nested but uses same key

attribute.

net/openvswitch/flow_netlink.c +7 -0
+                        */
+                       if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE,
+                                        output->eth.cvlan.tpid) ||
+                           nla_put_be16(skb, OVS_KEY_ATTR_VLAN,
+                                        output->eth.cvlan.tci))
+                               goto nla_put_failure;
+                       in_encap = nla_nest_start(skb,

OVS_KEY_ATTR_ENCAP);

Quoted 8 lines

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

Quoted 6 lines
net/openvswitch/flow_netlink.c +5 -0
+                       if (!swkey->eth.cvlan.tci)
+                               goto unencap;
+               }
+       } else {
                  encap = NULL;
+       }

After the vlan parsing changes, we need to encode cvlan in outer netlink attribute and then encode regular vlan.

Quoted 3 lines

I don't understand this. cvlan is inner vlan, why would it be encoded in outer vlan without the 2nd layer of encapsulation?

Lets start with double tagged packet.
packet: eth, vlan 10, inner vlan 20, ip.
flow key would be:
flow_key: vlan = 10, cvlan = 20
That would get serialize over netlink like:
eth_type(0x8100),vlan(vid=10,pcp=0),encap(eth_type(0x8100),vlan(vid=20,pcp=0), encap(eth_type(0x0800),ipv4(frag=no))...
So far looks good.

Now userspace sends back same key and installs flow in kernel datapath. But ovs_nla_get_match() parses netink key and sets vlan in reverse order. After parsing netlink in ovs_nla_get_match() vlans flow-key would look like:
flow_key: vlan = 20, cvlan = 10. This is not what we started with.

Quoted 3 lines

Now I think rather than fixing __ovs_nla_put_key (), we need to fix ovs_nla_get_match() to keep vlan order.
I also noticed that eth.vlan.tpid is never initialized from netlink attributes.

Yes, you are right. The code in master never encoded the tpid in the key and I didn't add it when I modified the swkey for the addition of the vlan struct.

Yes, you are right the code is wrong. The intention was to leave the old code which left the outer tci in the key for later processing. In the code in master, after checking proper vlan the function ovs_key_from_nlattrs() encoded the tci.

Now I see that I must refactor the code in ovs_nla_get_match() and parse_vlan_from_nlattrs to explicitly encode the outer vlan including tpid before the inner vlan.

Quoted 2 lines

Call to parse_flow_nlattrs in parse_vlan_from_nlattrs() has no effect so it should be removed

parse_flow_nlattrs() is called for each level of encapsulation. It sets v_attrs with the keys found in the flow key. This is to insure that I am looking only at the keys for the current level of encapsulation. Then it is called a final time to parse out the l3 attributes for encoding.

Quoted 16 lines
Quoted 8 lines

One think I see I should have done is check for eth_type_vlan() on the inner tag as well.

Quoted 3 lines

Currently we are
reversing netlink encoding while sending back the vlan attributes. cvlan and vlan is independent,

Are you talking about a corner case where the incoming packet has an inner vlan but no outer vlN?

nope, this is usual case.

Quoted 6 lines
Quoted 3 lines

therefore we need to check
swkey->eth.cvlan.tc outside of swkey->eth.vlan.tci block. Also redundant check for swkey->eth.cvlan.tci should be removed

I must be missing something because I don't understand this either. First my patch encodes the outer vlan and then sets the encap bit and then encodes the inner vlan. The encoding shows up correctly in user space.

Quoted 6 lines

Once ovs_nla_get_match() is fixed, there is no need to change this function to fix that ordering.

I was talking about following redundant check:

                 if (swkey->eth.cvlan.tci) {

I think this should be the fix: Maybe it should be: if ((eth_type_vlan(swkey->eth.cvlan.tpid) || (eth.cvlan.tci)) {

Quoted 9 lines
                         /* Customer tci is nested but uses same key attribute.
                          */
                         if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE,
                                          output->eth.cvlan.tpid) ||
                             nla_put_be16(skb, OVS_KEY_ATTR_VLAN,
                                          output->eth.cvlan.tci))
                                 goto nla_put_failure;
                         in_encap = nla_nest_start(skb, OVS_KEY_ATTR_ENCAP);
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
               if (!swkey->eth.cvlan.tci)  <<<<<<<<<<<<<

OK, I see what you mean. It looks redundant because it checks for cvlan.tci before the encap and then checks again after the encap. I got this from the original code which checks for 8021Q || eth.tci. Then after the encap, if it sees a zero tci, it unencaps. I guess this was to make sure it didn't encode a zero tci. See pseudo-code above.

Quoted 5 lines
                                 goto unencap;
                 }
Quoted 2 lines
Quoted 2 lines

Can you also post changes for userspace vswitchd so that I can try next patch.

Quoted 7 lines
Quoted 4 lines

I posted a patch for user space (V14) to ovs dev on October 2nd. I haven't made any changes since then.
http://openvswitch.org/pipermail/dev/2015-October/060874.html

That patch does not apply on OVS master. You could also send me link to ovs userpsace github repo with these patches applied so that I can try kernel datapath changes.

https://github.com/tfherbert/ovs_8021ad/tree/8021AD

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]

#13 lore raw

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

Quoted 132 lines · Thomas F Herbert
Quoted 111 lines · Pravin Shelar
Quoted 89 lines · Thomas F Herbert
Quoted 78 lines · Pravin Shelar
Quoted 18 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/actions.c      |   6 +-
   net/openvswitch/flow.c         |  76 +++++++++++++-----
   net/openvswitch/flow.h         |   8 +-
   net/openvswitch/flow_netlink.c | 172
+++++++++++++++++++++++++++++++++++++----
   net/openvswitch/vport-netdev.c |   4 +-
   5 files changed, 227 insertions(+), 39 deletions(-)
net/openvswitch/actions.c +0 -0
index 315f533..09cc1c9 100644

...

Quoted 5 lines
net/openvswitch/flow_netlink.c +0 -0
index c92d6a2..97a6d12 100644

...

Quoted 46 lines
net/openvswitch/flow_netlink.c +1 -0
@@ -1320,6 +1443,7 @@ static int __ovs_nla_put_key(const struct
 sw_flow_key *swkey,
   {
          struct ovs_key_ethernet *eth_key;
          struct nlattr *nla, *encap;
+       struct nlattr *in_encap = NULL;
 
          if (nla_put_u32(skb, OVS_KEY_ATTR_RECIRC_ID,

output->recirc_id))

                  goto nla_put_failure;
net/openvswitch/flow_netlink.c +0 -4
@@ -1368,17 +1492,29 @@ static int __ovs_nla_put_key(const struct
 sw_flow_key *swkey,
          ether_addr_copy(eth_key->eth_src, output->eth.src);
          ether_addr_copy(eth_key->eth_dst, output->eth.dst);
 
-       if (swkey->eth.tci || swkey->eth.type == htons(ETH_P_8021Q)) {
-               __be16 eth_type;
-               eth_type = !is_mask ? htons(ETH_P_8021Q) :
 htons(0xffff);
-               if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE, eth_type)
||
-                   nla_put_be16(skb, OVS_KEY_ATTR_VLAN,

output->eth.tci))

net/openvswitch/flow_netlink.c +4 -0
+       if (swkey->eth.vlan.tci || eth_type_vlan(swkey->eth.type)) {
+               if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE,
+                                output->eth.vlan.tpid) ||
+                   nla_put_be16(skb, OVS_KEY_ATTR_VLAN,

output->eth.vlan.tci))

                          goto nla_put_failure;
                  encap = nla_nest_start(skb, OVS_KEY_ATTR_ENCAP);
net/openvswitch/flow_netlink.c +3 -2
-               if (!swkey->eth.tci)
+               if (!swkey->eth.vlan.tci)
                          goto unencap;
-       } else
+               if (swkey->eth.cvlan.tci) {
+                       /* Customer tci is nested but uses same key

attribute.

net/openvswitch/flow_netlink.c +7 -0
+                        */
+                       if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE,
+                                        output->eth.cvlan.tpid) ||
+                           nla_put_be16(skb, OVS_KEY_ATTR_VLAN,
+                                        output->eth.cvlan.tci))
+                               goto nla_put_failure;
+                       in_encap = nla_nest_start(skb,

OVS_KEY_ATTR_ENCAP);
+ if (!swkey->eth.cvlan.tci)

Quoted 8 lines

net/openvswitch/flow_netlink.c

Quoted 5 lines
net/openvswitch/flow_netlink.c +4 -0
+                               goto unencap;
+               }
+       } else {
                  encap = NULL;
+       }

After the vlan parsing changes, we need to encode cvlan in outer netlink attribute and then encode regular vlan.

Quoted 3 lines

I don't understand this. cvlan is inner vlan, why would it be encoded in outer vlan without the 2nd layer of encapsulation?

Lets start with double tagged packet.
packet: eth, vlan 10, inner vlan 20, ip.
flow key would be:
flow_key: vlan = 10, cvlan = 20
That would get serialize over netlink like:

eth_type(0x8100),vlan(vid=10,pcp=0),encap(eth_type(0x8100),vlan(vid=20,pcp=0), encap(eth_type(0x0800),ipv4(frag=no))...
So far looks good.

Now userspace sends back same key and installs flow in kernel datapath. But ovs_nla_get_match() parses netink key and sets vlan in reverse order. After parsing netlink in ovs_nla_get_match() vlans flow-key would look like:
flow_key: vlan = 20, cvlan = 10. This is not what we started with.

Quoted 4 lines

Now I think rather than fixing __ovs_nla_put_key (), we need to fix ovs_nla_get_match() to keep vlan order.
I also noticed that eth.vlan.tpid is never initialized from netlink attributes.

Yes, you are right. The code in master never encoded the tpid in the key and I didn't add it when I modified the swkey for the addition of the vlan struct.

Yes, you are right the code is wrong. The intention was to leave the old code which left the outer tci in the key for later processing. In the code in master, after checking proper vlan the function ovs_key_from_nlattrs() encoded the tci.

Now I see that I must refactor the code in ovs_nla_get_match() and parse_vlan_from_nlattrs to explicitly encode the outer vlan including tpid before the inner vlan.

Quoted 1 line
Quoted 7 lines
Quoted 2 lines

Call to parse_flow_nlattrs in parse_vlan_from_nlattrs() has no effect so it should be removed

parse_flow_nlattrs() is called for each level of encapsulation. It sets v_attrs with the keys found in the flow key. This is to insure that I am looking only at the keys for the current level of encapsulation. Then it is called a final time to parse out the l3 attributes for encoding.

ovs_nla_get_match() calls parse_flow_nlattrs() and then again in parse_vlan_from_nlattrs(), second parse_flow_nlattr() can potentially overwrite vlan attributes. Therefore it should called after the outer vlan attributes are read.
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev

#14 lore raw

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

Quoted 124 lines · Pravin Shelar
Quoted 123 lines · Thomas F Herbert
Quoted 103 lines · Pravin Shelar
Quoted 82 lines · Thomas F Herbert
Quoted 73 lines · Pravin Shelar
Quoted 17 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/actions.c      |   6 +-
    net/openvswitch/flow.c         |  76 +++++++++++++-----
    net/openvswitch/flow.h         |   8 +-
    net/openvswitch/flow_netlink.c | 172
+++++++++++++++++++++++++++++++++++++----
    net/openvswitch/vport-netdev.c |   4 +-
    5 files changed, 227 insertions(+), 39 deletions(-)
net/openvswitch/actions.c +0 -0
index 315f533..09cc1c9 100644

...

Quoted 5 lines
net/openvswitch/flow_netlink.c +0 -0
index c92d6a2..97a6d12 100644

...

Quoted 45 lines
net/openvswitch/flow_netlink.c +1 -0
@@ -1320,6 +1443,7 @@ static int __ovs_nla_put_key(const struct
 sw_flow_key *swkey,
    {
           struct ovs_key_ethernet *eth_key;
           struct nlattr *nla, *encap;
+       struct nlattr *in_encap = NULL;
 
           if (nla_put_u32(skb, OVS_KEY_ATTR_RECIRC_ID,

output->recirc_id))

                   goto nla_put_failure;
net/openvswitch/flow_netlink.c +0 -4
@@ -1368,17 +1492,29 @@ static int __ovs_nla_put_key(const struct
 sw_flow_key *swkey,
           ether_addr_copy(eth_key->eth_src, output->eth.src);
           ether_addr_copy(eth_key->eth_dst, output->eth.dst);
 
-       if (swkey->eth.tci || swkey->eth.type == htons(ETH_P_8021Q)) {
-               __be16 eth_type;
-               eth_type = !is_mask ? htons(ETH_P_8021Q) :
 htons(0xffff);
-               if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE, eth_type)
||
-                   nla_put_be16(skb, OVS_KEY_ATTR_VLAN,

output->eth.tci))

net/openvswitch/flow_netlink.c +4 -0
+       if (swkey->eth.vlan.tci || eth_type_vlan(swkey->eth.type)) {
+               if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE,
+                                output->eth.vlan.tpid) ||
+                   nla_put_be16(skb, OVS_KEY_ATTR_VLAN,

output->eth.vlan.tci))

                           goto nla_put_failure;
                   encap = nla_nest_start(skb, OVS_KEY_ATTR_ENCAP);
net/openvswitch/flow_netlink.c +3 -2
-               if (!swkey->eth.tci)
+               if (!swkey->eth.vlan.tci)
                           goto unencap;
-       } else
+               if (swkey->eth.cvlan.tci) {
+                       /* Customer tci is nested but uses same key

attribute.

net/openvswitch/flow_netlink.c +7 -0
+                        */
+                       if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE,
+                                        output->eth.cvlan.tpid) ||
+                           nla_put_be16(skb, OVS_KEY_ATTR_VLAN,
+                                        output->eth.cvlan.tci))
+                               goto nla_put_failure;
+                       in_encap = nla_nest_start(skb,

OVS_KEY_ATTR_ENCAP);

Quoted 8 lines

net/openvswitch/flow_netlink.c

Quoted 6 lines
net/openvswitch/flow_netlink.c +5 -0
+                       if (!swkey->eth.cvlan.tci)
+                               goto unencap;
+               }
+       } else {
                   encap = NULL;
+       }

After the vlan parsing changes, we need to encode cvlan in outer netlink attribute and then encode regular vlan.

Quoted 3 lines

I don't understand this. cvlan is inner vlan, why would it be encoded in outer vlan without the 2nd layer of encapsulation?

Lets start with double tagged packet.
packet: eth, vlan 10, inner vlan 20, ip.
flow key would be:
flow_key: vlan = 10, cvlan = 20
That would get serialize over netlink like:

eth_type(0x8100),vlan(vid=10,pcp=0),encap(eth_type(0x8100),vlan(vid=20,pcp=0), encap(eth_type(0x0800),ipv4(frag=no))...
So far looks good.

Now userspace sends back same key and installs flow in kernel datapath. But ovs_nla_get_match() parses netink key and sets vlan in reverse order. After parsing netlink in ovs_nla_get_match() vlans flow-key would look like:
flow_key: vlan = 20, cvlan = 10. This is not what we started with.

Quoted 4 lines

Now I think rather than fixing __ovs_nla_put_key (), we need to fix ovs_nla_get_match() to keep vlan order.
I also noticed that eth.vlan.tpid is never initialized from netlink attributes.

Yes, you are right. The code in master never encoded the tpid in the key and I didn't add it when I modified the swkey for the addition of the vlan struct.

Yes, you are right the code is wrong. The intention was to leave the old code which left the outer tci in the key for later processing. In the code in master, after checking proper vlan the function ovs_key_from_nlattrs() encoded the tci.

Now I see that I must refactor the code in ovs_nla_get_match() and parse_vlan_from_nlattrs to explicitly encode the outer vlan including tpid before the inner vlan.

Quoted 2 lines

Call to parse_flow_nlattrs in parse_vlan_from_nlattrs() has no effect so it should be removed

Quoted 8 lines
Quoted 4 lines

parse_flow_nlattrs() is called for each level of encapsulation. It sets v_attrs with the keys found in the flow key. This is to insure that I am looking only at the keys for the current level of encapsulation. Then it is called a final time to parse out the l3 attributes for encoding.

ovs_nla_get_match() calls parse_flow_nlattrs() and then again in parse_vlan_from_nlattrs(), second parse_flow_nlattr() can potentially overwrite vlan attributes. Therefore it should called after the outer vlan attributes are read.

Thanks! Yes, I agree. I am fixing this with the refactoring I am doing now.

#15 lore raw

PATCH v17 1/3 openvswitch: 802.1ad uapi changes.

In reply to Thomas F Herbert

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 32e07d8..b0c959c 100644
@@ -585,13 +585,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). */
 };
 
@@ -664,9 +664,10 @@ enum ovs_ct_attr {
  * 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.4.3

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