Skip to contentSkip to conversation

openvswitch: add 802.1ad support

PATCH Superseded Eric Garver 4 participants 14 messages Sep 1, 2016 – Sep 6, 2016 5 messages not in the archive

Subsystems (3)

v21 of 22 Superseded Latest is v22 →

lore
Share & tools
lore
#0 lore raw

v21 cover openvswitch: add 802.1ad support

This series adds 802.1ad support to openvswitch. It is a continuation of the work originally started by Thomas F Herbert - hence the large rev number.

The extra VLAN is implemented by using an additional level of the OVS_KEY_ATTR_ENCAP netlink attribute.
In OVS flow speak, this looks like

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

                                        encap(eth_type(0x0800), ...))

The userspace counterpart has also seen recent activity on the ovs-dev mailing lists. There are some new 802.1ad OVS tests being added - also on the ovs-dev list. This patch series has been tested using the most recent version of userspace (v3) and tests (v2).

v21 changes:
- Fix (and simplify) netlink attribute parsing
- re-add handling of truncated VLAN tags
- fix if/else dangling assignment in {push,pop}_vlan()
- simplify parse_vlan()

Eric Garver (3):
vlan: Check for vlan ethernet types for 8021.q or 802.1ad
openvswitch: 802.1AD Flow handling, actions, vlan parsing, netlink
attributes
openvswitch: report error on VLAN nlattr in ovs_key_from_nlattrs()

Thomas F Herbert (1):
openvswitch: 802.1ad uapi changes.

 include/linux/if_vlan.h          |  33 ++++--
 include/uapi/linux/openvswitch.h |  17 +--
 net/openvswitch/actions.c        |  16 ++-
 net/openvswitch/flow.c           |  64 +++++++---
 net/openvswitch/flow.h           |   8 +-
 net/openvswitch/flow_netlink.c   | 244 +++++++++++++++++++++++++++------------
 net/openvswitch/vport.c          |   7 +-
 7 files changed, 271 insertions(+), 118 deletions(-)
Signature · 6 lines
2.5.5

_______________________________________________
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]

#2 lore raw

PATCH v21 1/4 openvswitch: 802.1ad uapi changes.

From: Thomas F Herbert <[email protected]>

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 54c3b4f4aceb..59ed3992c760 100644
@@ -605,13 +605,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). */
 };
 
@@ -721,9 +721,10 @@ enum ovs_nat_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 · 6 lines
2.5.5

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

PATCH v21 2/4 vlan: Check for vlan ethernet types for 8021.q or 802.1ad

In reply to a message not in the archive

This is to simplify using double tagged vlans. This function allows all valid vlan ethertypes to be checked in a single function call. Also replace some instances that check for both ETH_P_8021Q and ETH_P_8021AD.

Patch based on one originally by Thomas F Herbert.

---
 include/linux/if_vlan.h | 33 +++++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)
include/linux/if_vlan.h +23 -10
index 49d4aef1f789..3319d97d789d 100644
@@ -272,6 +272,23 @@ static inline int vlan_get_encap_level(struct net_device *dev)
 }
 #endif
 
+/**
+ * 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;
+	}
+}
+
 static inline bool vlan_hw_offload_capable(netdev_features_t features,
 					   __be16 proto)
 {
@@ -425,8 +442,7 @@ static inline int __vlan_get_tag(const struct sk_buff *skb, u16 *vlan_tci)
 {
 	struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb->data;
 
-	if (veth->h_vlan_proto != htons(ETH_P_8021Q) &&
-	    veth->h_vlan_proto != htons(ETH_P_8021AD))
+	if (!eth_type_vlan(veth->h_vlan_proto))
 		return -EINVAL;
 
 	*vlan_tci = ntohs(veth->h_vlan_TCI);
@@ -488,7 +504,7 @@ static inline __be16 __vlan_get_protocol(struct sk_buff *skb, __be16 type,
 	 * present at mac_len - VLAN_HLEN (if mac_len > 0), or at
 	 * ETH_HLEN otherwise
 	 */
-	if (type == htons(ETH_P_8021Q) || type == htons(ETH_P_8021AD)) {
+	if (eth_type_vlan(type)) {
 		if (vlan_depth) {
 			if (WARN_ON(vlan_depth < VLAN_HLEN))
 				return 0;
@@ -506,8 +522,7 @@ static inline __be16 __vlan_get_protocol(struct sk_buff *skb, __be16 type,
 			vh = (struct vlan_hdr *)(skb->data + vlan_depth);
 			type = vh->h_vlan_encapsulated_proto;
 			vlan_depth += VLAN_HLEN;
-		} while (type == htons(ETH_P_8021Q) ||
-			 type == htons(ETH_P_8021AD));
+		} while (eth_type_vlan(type));
 	}
 
 	if (depth)
@@ -572,8 +587,7 @@ static inline void vlan_set_encap_proto(struct sk_buff *skb,
 static inline bool skb_vlan_tagged(const struct sk_buff *skb)
 {
 	if (!skb_vlan_tag_present(skb) &&
-	    likely(skb->protocol != htons(ETH_P_8021Q) &&
-		   skb->protocol != htons(ETH_P_8021AD)))
+	    likely(!eth_type_vlan(skb->protocol)))
 		return false;
 
 	return true;
@@ -593,15 +607,14 @@ static inline bool skb_vlan_tagged_multi(const struct sk_buff *skb)
 	if (!skb_vlan_tag_present(skb)) {
 		struct vlan_ethhdr *veh;
 
-		if (likely(protocol != htons(ETH_P_8021Q) &&
-			   protocol != htons(ETH_P_8021AD)))
+		if (likely(!eth_type_vlan(protocol)))
 			return false;
 
 		veh = (struct vlan_ethhdr *)skb->data;
 		protocol = veh->h_vlan_encapsulated_proto;
 	}
 
-	if (protocol != htons(ETH_P_8021Q) && protocol != htons(ETH_P_8021AD))
+	if (!eth_type_vlan(protocol))
 		return false;
 
 	return true;
Signature · 6 lines
2.5.5

_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev
Acked-by on v21 2/4
#5 lore raw

Re: [ovs-dev] [PATCH net-next v21 2/4] vlan: Check for vlan ethernet types for 8021.q or 802.1ad

Quoted 9 lines · Eric Garver

This is to simplify using double tagged vlans. This function allows all valid vlan ethertypes to be checked in a single function call. Also replace some instances that check for both ETH_P_8021Q and ETH_P_8021AD.

Patch based on one originally by Thomas F Herbert.

#6 lore raw

PATCH v21 3/4 openvswitch: 802.1AD Flow handling, actions, vlan parsing, 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.

This is based on Thomas F Herbert's original v20 patch. I made some small clean ups and bug fixes.

---
 net/openvswitch/actions.c      |  16 +--
 net/openvswitch/flow.c         |  64 ++++++++----
 net/openvswitch/flow.h         |   8 +-
 net/openvswitch/flow_netlink.c | 227 ++++++++++++++++++++++++++++++-----------
 net/openvswitch/vport.c        |   7 +-
 5 files changed, 235 insertions(+), 87 deletions(-)
net/openvswitch/actions.c +10 -6
index ca91fc33f8a9..4fe9032b1160 100644
@@ -246,20 +246,24 @@ static int pop_vlan(struct sk_buff *skb, struct sw_flow_key *key)
 	int err;
 
 	err = skb_vlan_pop(skb);
-	if (skb_vlan_tag_present(skb))
+	if (skb_vlan_tag_present(skb)) {
 		invalidate_flow_key(key);
-	else
-		key->eth.tci = 0;
+	} else {
+		key->eth.vlan.tci = 0;
+		key->eth.vlan.tpid = 0;
+	}
 	return err;
 }
 
 static int push_vlan(struct sk_buff *skb, struct sw_flow_key *key,
 		     const struct ovs_action_push_vlan *vlan)
 {
-	if (skb_vlan_tag_present(skb))
+	if (skb_vlan_tag_present(skb)) {
 		invalidate_flow_key(key);
-	else
-		key->eth.tci = vlan->vlan_tci;
+	} else {
+		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 +46 -18

82 lines not on this page · raw message

net/openvswitch/flow.h +7 -1
index 03378e75a67c..156a3029c17b 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))
@@ -69,7 +74,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 +166 -61

313 lines not on this page · raw message

net/openvswitch/vport.c +6 -1
index 6b21fd068d87..8f198437c724 100644
@@ -485,9 +485,14 @@ 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 (skb_vlan_tagged(skb))
 		length -= VLAN_HLEN;
 
+	/* Don't subtract for multiple VLAN tags. Most (all?) drivers allow
+	 * (ETH_LEN + VLAN_HLEN) in addition to the mtu value, but almost none
+	 * account for 802.1ad. e.g. is_skb_forwardable().
+	 */
+
 	return length;
 }
 
Signature · 6 lines
2.5.5

_______________________________________________
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]

#8 lore raw

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

Quoted 10 lines · Eric Garver

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.

This is based on Thomas F Herbert's original v20 patch. I made some small clean ups and bug fixes.

Thanks for working on this. This version looks pretty clone to complete.

Quoted 8 lines
---
 net/openvswitch/actions.c      |  16 +--
 net/openvswitch/flow.c         |  64 ++++++++----
 net/openvswitch/flow.h         |   8 +-
 net/openvswitch/flow_netlink.c | 227 ++++++++++++++++++++++++++++++-----------
 net/openvswitch/vport.c        |   7 +-
 5 files changed, 235 insertions(+), 87 deletions(-)

...

Quoted 27 lines
net/openvswitch/flow.c +9 -7
index 0ea128eeeab2..13f6ebdf379b 100644
@@ -302,24 +302,56 @@ static bool icmp6hdr_ok(struct sk_buff *skb)
                                  sizeof(struct icmp6hdr));
 }
 
-static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key)
+/**
+ * Parse vlan tag from vlan header.
+ * Returns ERROR on memory error.
+ * Returns 0 if it encounters a non-vlan or incomplete packet.
+ * Returns 1 after successfully parsing vlan tag.
+ */
+static int parse_vlan_tag(struct sk_buff *skb, struct vlan_head *vlan)
 {
-       struct qtag_prefix {
-               __be16 eth_type; /* ETH_P_8021Q */
-               __be16 tci;
-       };
-       struct qtag_prefix *qp;
+       struct vlan_head *qp = (struct vlan_head *)skb->data;
 
-       if (unlikely(skb->len < sizeof(struct qtag_prefix) + sizeof(__be16)))
+       if (likely(!eth_type_vlan(qp->tpid)))
                return 0;

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

Quoted 10 lines
net/openvswitch/flow.c +5 -2
 
-       if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
-                                        sizeof(__be16))))
+       if (unlikely(skb->len < sizeof(struct vlan_head) + sizeof(__be16)))
+               return 0;
+
+       if (unlikely(!pskb_may_pull(skb, sizeof(struct vlan_head) +
+                                sizeof(__be16))))
                return -ENOMEM;
 

pskb_may_pull() can change skb->data, so you need to refresh qp pointer.

Quoted 10 lines
net/openvswitch/flow.c +7 -3
-       qp = (struct qtag_prefix *) skb->data;
-       key->eth.tci = qp->tci | htons(VLAN_TAG_PRESENT);
-       __skb_pull(skb, sizeof(struct qtag_prefix));
+       vlan->tci = qp->tci | htons(VLAN_TAG_PRESENT);
+       vlan->tpid = qp->tpid;
+
+       __skb_pull(skb, sizeof(struct vlan_head));
+       return 1;
+}
+

...
...

Quoted 4 lines
net/openvswitch/flow_netlink.c +0 -0
index c78a6a1476fb..fbe9e0e4792d 100644

...

Quoted 53 lines
net/openvswitch/flow_netlink.c +53 -0
+static int __parse_vlan_from_nlattrs(struct sw_flow_match *match,
+                                    u64 *key_attrs, bool inner,
+                                    const struct nlattr **a, bool is_mask,
+                                    bool log)
+{
+       int err;
+       const struct nlattr *encap;
+
+       err = encode_vlan_from_nlattrs(match, a, is_mask, inner, log);
+       if (err)
+               return err;
+
+       *key_attrs &= ~(1 << OVS_KEY_ATTR_ENCAP);
+
+       /* Ensure that tci key attribute isn't
+        * overwritten by encapsulated customer tci.
+        * Ethertype is cleared because it is c_tpid.
+        */
+       *key_attrs &= ~(1 << OVS_KEY_ATTR_VLAN);
+       *key_attrs &= ~(1 << OVS_KEY_ATTR_ETHERTYPE);
+
+       encap = a[OVS_KEY_ATTR_ENCAP];
+
+       if (is_mask)
+               err = parse_flow_mask_nlattrs(encap, a, key_attrs, log);
+       else
+               err = parse_flow_nlattrs(encap, a, key_attrs, log);
+
+       return err;
+}
+
+static int parse_vlan_from_nlattrs(struct sw_flow_match *match,
+                                  u64 *key_attrs, bool *ie_valid,
+                                  const struct nlattr **a, bool is_mask,
+                                  bool log)
+{
+       int err;
+
+       err = __parse_vlan_from_nlattrs(match, key_attrs,
+                                       false, a, is_mask, log);
+       if (err)
+               return err;
+
+       if (!is_mask) {
+               if ((*key_attrs & (1 << OVS_KEY_ATTR_ETHERTYPE)) &&
+                   eth_type_vlan(nla_get_be16(a[OVS_KEY_ATTR_ETHERTYPE]))) {
+
+                       if (!((*key_attrs & (1 << OVS_KEY_ATTR_VLAN)) &&
+                             (*key_attrs & (1 << OVS_KEY_ATTR_ENCAP)))) {
+                               OVS_NLERR(log, "Invalid Inner VLAN frame");
+                               return -EINVAL;
+                       }
+                       *ie_valid = true;

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

Quoted 10 lines
net/openvswitch/flow_netlink.c +10 -0
+               }
+       } else {
+               if (*key_attrs & (1 << OVS_KEY_ATTR_ENCAP)) {
+                       if (!*ie_valid) {
+                               OVS_NLERR(log, "Encap mask attribute is set for non-CVLAN frame.");
+                               return -EINVAL;
+                       }
+               }
+       }
+

This check can be moved to __parse_vlan_from_nlattrs(). This way there is no need to check ATTR_VLAN and ATTR_ENCAP here and in ovs_nla_get_match() function.
...

Quoted 26 lines
net/openvswitch/flow_netlink.c +2 -3
@@ -1182,11 +1301,11 @@ int ovs_nla_get_match(struct net *net, struct sw_flow_match *match,
                      bool log)
 {
        const struct nlattr *a[OVS_KEY_ATTR_MAX + 1];
-       const struct nlattr *encap;
        struct nlattr *newmask = NULL;
        u64 key_attrs = 0;
        u64 mask_attrs = 0;
        bool encap_valid = false;
+       bool i_encap_valid = false;
        int err;
 
        err = parse_flow_nlattrs(nla_key, a, &key_attrs, log);
@@ -1195,35 +1314,20 @@ int ovs_nla_get_match(struct net *net, struct sw_flow_match *match,
 
        if ((key_attrs & (1 << OVS_KEY_ATTR_ETHERNET)) &&
            (key_attrs & (1 << OVS_KEY_ATTR_ETHERTYPE)) &&
-           (nla_get_be16(a[OVS_KEY_ATTR_ETHERTYPE]) == htons(ETH_P_8021Q))) {
-               __be16 tci;
+           eth_type_vlan(nla_get_be16(a[OVS_KEY_ATTR_ETHERTYPE]))) {
 
                if (!((key_attrs & (1 << OVS_KEY_ATTR_VLAN)) &&
                      (key_attrs & (1 << OVS_KEY_ATTR_ENCAP)))) {
                        OVS_NLERR(log, "Invalid Vlan frame.");
                        return -EINVAL;
                }

...
...

Quoted 22 lines
net/openvswitch/flow_netlink.c +7 -6
@@ -1464,17 +1547,37 @@ 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)) {
+       if (swkey->eth.vlan.tci || eth_type_vlan(swkey->eth.type)) {
                __be16 eth_type;
-               eth_type = !is_mask ? htons(ETH_P_8021Q) : htons(0xffff);
+               eth_type = !is_mask ? output->eth.vlan.tpid : htons(0xffff);
                if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE, eth_type) ||
-                   nla_put_be16(skb, OVS_KEY_ATTR_VLAN, output->eth.tci))
+                   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
-               encap = NULL;
+
+               if (swkey->eth.cvlan.tci || eth_type_vlan(swkey->eth.type)) {
+                       /* Customer tci is nested but uses same key attribute.

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

Quoted 10 lines
net/openvswitch/flow_netlink.c +10 -0
+                        */
+                       eth_type = !is_mask ? output->eth.cvlan.tpid : htons(0xffff);
+                       if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE, eth_type) ||
+                           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;
+               }
+       }

there could be helper function to serialize "struct vlan_head" to avoid duplicate code above.

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

Quoted 2 lines
net/openvswitch/flow_netlink.c +2 -0
+
+       if (eth_type_vlan(swkey->eth.type) && encap && in_encap) {

I think check for eth.type is sufficient here. encap and in_encap should be true in this case anyways.

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

Quoted 4 lines
net/openvswitch/flow_netlink.c +4 -0
+               /* There are 3 VLAN tags, we don't know anything about the rest of the
+                * packet, so truncate here.
+                */
+               if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE, output->eth.type))

After this output->eth.type would be serialized three times, can you move the check for third vlan tag after it is serialized so as to avoid it.

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

Quoted 6 lines
net/openvswitch/flow_netlink.c +3 -0
+                       goto nla_put_failure;
+               goto unencap;
+       }
 
        if (swkey->eth.type == htons(ETH_P_802_2)) {
                /*

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

#9 lore raw

Re: [ovs-dev] [PATCH net-next v21 3/4] openvswitch: 802.1AD Flow handling, actions, vlan parsing, netlink attributes

Quoted 6 lines · pravin shelar
Quoted 5 lines · Eric Garver

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.

Quoted 6 lines
Quoted 5 lines

This is based on Thomas F Herbert's original v20 patch. I made some small clean ups and bug fixes.

checkpatch.pl is also not happy with the patch, It found bunch of issues.

./scripts/checkpatch.pl 0003-openvswitch-802.1AD-Flow-handling-actions-vlan-parsi.patch
...
...
total: 6 errors, 9 warnings, 1 checks, 460 lines checked

A message that is not in the archive (sent off-list or not yet received): CAOrHB_A6Twwp+S514orUZ5RaKS1hGXgc1uUi7Lj8dxPQrk_sxg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#11 lore raw

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

Pravin,

Thanks for the feedback. Some replies below.

Thanks.
Eric.

Quoted 51 lines · pravin shelar
Quoted 10 lines · Eric Garver

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.

This is based on Thomas F Herbert's original v20 patch. I made some small clean ups and bug fixes.

Thanks for working on this. This version looks pretty clone to complete.

Quoted 8 lines
---
 net/openvswitch/actions.c      |  16 +--
 net/openvswitch/flow.c         |  64 ++++++++----
 net/openvswitch/flow.h         |   8 +-
 net/openvswitch/flow_netlink.c | 227 ++++++++++++++++++++++++++++++-----------
 net/openvswitch/vport.c        |   7 +-
 5 files changed, 235 insertions(+), 87 deletions(-)

...

Quoted 28 lines
net/openvswitch/flow.c +9 -7
index 0ea128eeeab2..13f6ebdf379b 100644
@@ -302,24 +302,56 @@ static bool icmp6hdr_ok(struct sk_buff *skb)
                                  sizeof(struct icmp6hdr));
 }
 
-static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key)
+/**
+ * Parse vlan tag from vlan header.
+ * Returns ERROR on memory error.
+ * Returns 0 if it encounters a non-vlan or incomplete packet.
+ * Returns 1 after successfully parsing vlan tag.
+ */
+static int parse_vlan_tag(struct sk_buff *skb, struct vlan_head *vlan)
 {
-       struct qtag_prefix {
-               __be16 eth_type; /* ETH_P_8021Q */
-               __be16 tci;
-       };
-       struct qtag_prefix *qp;
+       struct vlan_head *qp = (struct vlan_head *)skb->data;
 
-       if (unlikely(skb->len < sizeof(struct qtag_prefix) + sizeof(__be16)))
+       if (likely(!eth_type_vlan(qp->tpid)))
                return 0;
 
Quoted 11 lines

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

Quoted 9 lines
net/openvswitch/flow.c +5 -2
-       if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
-                                        sizeof(__be16))))
+       if (unlikely(skb->len < sizeof(struct vlan_head) + sizeof(__be16)))
+               return 0;
+
+       if (unlikely(!pskb_may_pull(skb, sizeof(struct vlan_head) +
+                                sizeof(__be16))))
                return -ENOMEM;
 

pskb_may_pull() can change skb->data, so you need to refresh qp pointer.

Good catch!

Quoted 78 lines
Quoted 10 lines
net/openvswitch/flow.c +7 -3
-       qp = (struct qtag_prefix *) skb->data;
-       key->eth.tci = qp->tci | htons(VLAN_TAG_PRESENT);
-       __skb_pull(skb, sizeof(struct qtag_prefix));
+       vlan->tci = qp->tci | htons(VLAN_TAG_PRESENT);
+       vlan->tpid = qp->tpid;
+
+       __skb_pull(skb, sizeof(struct vlan_head));
+       return 1;
+}
+

...
...

Quoted 4 lines
net/openvswitch/flow_netlink.c +0 -0
index c78a6a1476fb..fbe9e0e4792d 100644

...

Quoted 59 lines
net/openvswitch/flow_netlink.c +59 -0
+static int __parse_vlan_from_nlattrs(struct sw_flow_match *match,
+                                    u64 *key_attrs, bool inner,
+                                    const struct nlattr **a, bool is_mask,
+                                    bool log)
+{
+       int err;
+       const struct nlattr *encap;
+
+       err = encode_vlan_from_nlattrs(match, a, is_mask, inner, log);
+       if (err)
+               return err;
+
+       *key_attrs &= ~(1 << OVS_KEY_ATTR_ENCAP);
+
+       /* Ensure that tci key attribute isn't
+        * overwritten by encapsulated customer tci.
+        * Ethertype is cleared because it is c_tpid.
+        */
+       *key_attrs &= ~(1 << OVS_KEY_ATTR_VLAN);
+       *key_attrs &= ~(1 << OVS_KEY_ATTR_ETHERTYPE);
+
+       encap = a[OVS_KEY_ATTR_ENCAP];
+
+       if (is_mask)
+               err = parse_flow_mask_nlattrs(encap, a, key_attrs, log);
+       else
+               err = parse_flow_nlattrs(encap, a, key_attrs, log);
+
+       return err;
+}
+
+static int parse_vlan_from_nlattrs(struct sw_flow_match *match,
+                                  u64 *key_attrs, bool *ie_valid,
+                                  const struct nlattr **a, bool is_mask,
+                                  bool log)
+{
+       int err;
+
+       err = __parse_vlan_from_nlattrs(match, key_attrs,
+                                       false, a, is_mask, log);
+       if (err)
+               return err;
+
+       if (!is_mask) {
+               if ((*key_attrs & (1 << OVS_KEY_ATTR_ETHERTYPE)) &&
+                   eth_type_vlan(nla_get_be16(a[OVS_KEY_ATTR_ETHERTYPE]))) {
+
+                       if (!((*key_attrs & (1 << OVS_KEY_ATTR_VLAN)) &&
+                             (*key_attrs & (1 << OVS_KEY_ATTR_ENCAP)))) {
+                               OVS_NLERR(log, "Invalid Inner VLAN frame");
+                               return -EINVAL;
+                       }
+                       *ie_valid = true;
+               }
+       } else {
+               if (*key_attrs & (1 << OVS_KEY_ATTR_ENCAP)) {
+                       if (!*ie_valid) {
+                               OVS_NLERR(log, "Encap mask attribute is set for non-CVLAN frame.");
+                               return -EINVAL;
Quoted 9 lines

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

Quoted 4 lines
net/openvswitch/flow_netlink.c +4 -0
+                       }
+               }
+       }
+

This check can be moved to __parse_vlan_from_nlattrs(). This way there is no need to check ATTR_VLAN and ATTR_ENCAP here and in ovs_nla_get_match() function.
...

I agree there could be some refactoring done here.

Quoted 54 lines
Quoted 26 lines
net/openvswitch/flow_netlink.c +2 -3
@@ -1182,11 +1301,11 @@ int ovs_nla_get_match(struct net *net, struct sw_flow_match *match,
                      bool log)
 {
        const struct nlattr *a[OVS_KEY_ATTR_MAX + 1];
-       const struct nlattr *encap;
        struct nlattr *newmask = NULL;
        u64 key_attrs = 0;
        u64 mask_attrs = 0;
        bool encap_valid = false;
+       bool i_encap_valid = false;
        int err;
 
        err = parse_flow_nlattrs(nla_key, a, &key_attrs, log);
@@ -1195,35 +1314,20 @@ int ovs_nla_get_match(struct net *net, struct sw_flow_match *match,
 
        if ((key_attrs & (1 << OVS_KEY_ATTR_ETHERNET)) &&
            (key_attrs & (1 << OVS_KEY_ATTR_ETHERTYPE)) &&
-           (nla_get_be16(a[OVS_KEY_ATTR_ETHERTYPE]) == htons(ETH_P_8021Q))) {
-               __be16 tci;
+           eth_type_vlan(nla_get_be16(a[OVS_KEY_ATTR_ETHERTYPE]))) {
 
                if (!((key_attrs & (1 << OVS_KEY_ATTR_VLAN)) &&
                      (key_attrs & (1 << OVS_KEY_ATTR_ENCAP)))) {
                        OVS_NLERR(log, "Invalid Vlan frame.");
                        return -EINVAL;
                }

...
...

Quoted 26 lines
net/openvswitch/flow_netlink.c +11 -6
@@ -1464,17 +1547,37 @@ 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)) {
+       if (swkey->eth.vlan.tci || eth_type_vlan(swkey->eth.type)) {
                __be16 eth_type;
-               eth_type = !is_mask ? htons(ETH_P_8021Q) : htons(0xffff);
+               eth_type = !is_mask ? output->eth.vlan.tpid : htons(0xffff);
                if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE, eth_type) ||
-                   nla_put_be16(skb, OVS_KEY_ATTR_VLAN, output->eth.tci))
+                   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
-               encap = NULL;
+
+               if (swkey->eth.cvlan.tci || eth_type_vlan(swkey->eth.type)) {
+                       /* Customer tci is nested but uses same key attribute.
+                        */
+                       eth_type = !is_mask ? output->eth.cvlan.tpid : htons(0xffff);
+                       if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE, eth_type) ||
+                           nla_put_be16(skb, OVS_KEY_ATTR_VLAN, output->eth.cvlan.tci))
Quoted 9 lines

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

Quoted 6 lines
net/openvswitch/flow_netlink.c +6 -0
+                               goto nla_put_failure;
+                       in_encap = nla_nest_start(skb, OVS_KEY_ATTR_ENCAP);
+                       if (!swkey->eth.cvlan.tci)
+                               goto unencap;
+               }
+       }

there could be helper function to serialize "struct vlan_head" to avoid duplicate code above.

Good idea. I'll add a helper.

Quoted 6 lines

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

Quoted 2 lines
net/openvswitch/flow_netlink.c +2 -0
+
+       if (eth_type_vlan(swkey->eth.type) && encap && in_encap) {

I think check for eth.type is sufficient here. encap and in_encap should be true in this case anyways.

Yes. You're right. Call it paranoia.
Would a BUG_ON(!(encap && in_encap)) be better?

Quoted 9 lines

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

Quoted 4 lines
net/openvswitch/flow_netlink.c +4 -0
+               /* There are 3 VLAN tags, we don't know anything about the rest of the
+                * packet, so truncate here.
+                */
+               if (nla_put_be16(skb, OVS_KEY_ATTR_ETHERTYPE, output->eth.type))

After this output->eth.type would be serialized three times, can you move the check for third vlan tag after it is serialized so as to avoid it.

Will do.

Quoted 6 lines

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

Quoted 6 lines
net/openvswitch/flow_netlink.c +3 -0
+                       goto nla_put_failure;
+               goto unencap;
+       }
 
        if (swkey->eth.type == htons(ETH_P_802_2)) {
                /*

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

#12 lore raw

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

Quoted 1 line · Eric Garver

Would a BUG_ON(!(encap && in_encap)) be better?

Please don't crash the kernel for something that could very well continue without problems. Use WARN_ON at most.

And if you go that way, WARN_ON_ONCE or rate limiting seems to be even more appropriate, because if this triggers, it's quite possible it will trigger repeatedly and the resulting log flood would practically make the machine useless anyway.

Thanks,

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

#13 lore raw

Re: [ovs-dev] [PATCH net-next v21 3/4] openvswitch: 802.1AD Flow handling, actions, vlan parsing, netlink attributes

Quoted 5 lines · Jiri Benc
Quoted 1 line · Eric Garver

Would a BUG_ON(!(encap && in_encap)) be better?

Please don't crash the kernel for something that could very well continue without problems. Use WARN_ON at most.

Thanks Jiri. WARN_ON_ONCE() is more appropriate for what I was looking for.

Quoted 8 lines

And if you go that way, WARN_ON_ONCE or rate limiting seems to be even more appropriate, because if this triggers, it's quite possible it will trigger repeatedly and the resulting log flood would practically make the machine useless anyway.

Thanks,

Jiri

#14 lore raw

PATCH v21 4/4 openvswitch: report error on VLAN nlattr in ovs_key_from_nlattrs()

In reply to a message not in the archive

With 802.1ad support these are parsed and set upfront by parse_vlan_from_nlattrs() before ovs_key_from_nlattrs() is ever called. As such we should never see a VLAN attribute in ovs_key_from_nlattrs().

---
 net/openvswitch/flow_netlink.c | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)
net/openvswitch/flow_netlink.c +5 -14
index fbe9e0e4792d..0f36aead744b 100644
@@ -923,20 +923,11 @@ static int ovs_key_from_nlattrs(struct net *net, struct sw_flow_match *match,
 	}
 
 	if (attrs & (1 << OVS_KEY_ATTR_VLAN)) {
-		__be16 tci;
-
-		tci = nla_get_be16(a[OVS_KEY_ATTR_VLAN]);
-		if (!(tci & htons(VLAN_TAG_PRESENT))) {
-			if (is_mask)
-				OVS_NLERR(log, "VLAN TCI mask does not have exact match for VLAN_TAG_PRESENT bit.");
-			else
-				OVS_NLERR(log, "VLAN TCI does not have VLAN_TAG_PRESENT bit set.");
-
-			return -EINVAL;
-		}
-
-		SW_FLOW_KEY_PUT(match, eth.vlan.tci, tci, is_mask);
-		attrs &= ~(1 << OVS_KEY_ATTR_VLAN);
+		/* VLAN attribute is always parsed before getting here since it may
+		 * occur multiple times.
+		 */
+		OVS_NLERR(log, "VLAN attribute unexpected.");
+		return -EINVAL;
 	}
 
 	if (attrs & (1 << OVS_KEY_ATTR_ETHERTYPE)) {
Signature · 6 lines
2.5.5

_______________________________________________
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]

#16 lore raw

Re: [PATCH net-next v21 4/4] openvswitch: report error on VLAN nlattr in ovs_key_from_nlattrs()

Quoted 28 lines · Eric Garver

With 802.1ad support these are parsed and set upfront by parse_vlan_from_nlattrs() before ovs_key_from_nlattrs() is ever called. As such we should never see a VLAN attribute in ovs_key_from_nlattrs().

---
 net/openvswitch/flow_netlink.c | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)
net/openvswitch/flow_netlink.c +0 -11
index fbe9e0e4792d..0f36aead744b 100644
@@ -923,20 +923,11 @@ static int ovs_key_from_nlattrs(struct net *net, struct sw_flow_match *match,
        }
 
        if (attrs & (1 << OVS_KEY_ATTR_VLAN)) {
-               __be16 tci;
-
-               tci = nla_get_be16(a[OVS_KEY_ATTR_VLAN]);
-               if (!(tci & htons(VLAN_TAG_PRESENT))) {
-                       if (is_mask)
-                               OVS_NLERR(log, "VLAN TCI mask does not have exact match for VLAN_TAG_PRESENT bit.");
-                       else
-                               OVS_NLERR(log, "VLAN TCI does not have VLAN_TAG_PRESENT bit set.");
-
-                       return -EINVAL;
-               }

net/openvswitch/flow_netlink.c static int ovs_key_from_nlattrs(struct net *net, struct sw_flow_match *match, · line 932

Quoted 10 lines
net/openvswitch/flow_netlink.c +5 -3
-
-               SW_FLOW_KEY_PUT(match, eth.vlan.tci, tci, is_mask);
-               attrs &= ~(1 << OVS_KEY_ATTR_VLAN);
+               /* VLAN attribute is always parsed before getting here since it may
+                * occur multiple times.
+                */
+               OVS_NLERR(log, "VLAN attribute unexpected.");
+               return -EINVAL;
        }
 

Is there reason for not merging this patch with earlier patch?
_______________________________________________
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): CAOrHB_BhPvf_rM3YR5mRSCQPhvnosBDoBEyFvags98CHtM9Z+g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#18 lore raw

Re: [PATCH net-next v21 4/4] openvswitch: report error on VLAN nlattr in ovs_key_from_nlattrs()

Quoted 32 lines · pravin shelar
Quoted 31 lines · Eric Garver

With 802.1ad support these are parsed and set upfront by parse_vlan_from_nlattrs() before ovs_key_from_nlattrs() is ever called. As such we should never see a VLAN attribute in ovs_key_from_nlattrs().

---
 net/openvswitch/flow_netlink.c | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)
net/openvswitch/flow_netlink.c +0 -14
index fbe9e0e4792d..0f36aead744b 100644
@@ -923,20 +923,11 @@ static int ovs_key_from_nlattrs(struct net *net, struct sw_flow_match *match,
        }
 
        if (attrs & (1 << OVS_KEY_ATTR_VLAN)) {
-               __be16 tci;
-
-               tci = nla_get_be16(a[OVS_KEY_ATTR_VLAN]);
-               if (!(tci & htons(VLAN_TAG_PRESENT))) {
-                       if (is_mask)
-                               OVS_NLERR(log, "VLAN TCI mask does not have exact match for VLAN_TAG_PRESENT bit.");
-                       else
-                               OVS_NLERR(log, "VLAN TCI does not have VLAN_TAG_PRESENT bit set.");
-
-                       return -EINVAL;
-               }
-
-               SW_FLOW_KEY_PUT(match, eth.vlan.tci, tci, is_mask);
-               attrs &= ~(1 << OVS_KEY_ATTR_VLAN);
Quoted 8 lines

net/openvswitch/flow_netlink.c static int ovs_key_from_nlattrs(struct net *net, struct sw_flow_match *match, · line 932

Quoted 7 lines
net/openvswitch/flow_netlink.c +5 -0
+               /* VLAN attribute is always parsed before getting here since it may
+                * occur multiple times.
+                */
+               OVS_NLERR(log, "VLAN attribute unexpected.");
+               return -EINVAL;
        }
 

Is there reason for not merging this patch with earlier patch?

Not a particularly good one. I'll merge it into patch 3.
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev