Skip to contentSkip to conversation

openvswitch: Add support for 802.1ad

PATCH Superseded Thomas F Herbert 6 participants 11 messages Oct 15, 2015 – Oct 16, 2015 3 messages not in the archive

Subsystems (3)

v16 of 20 Superseded Latest is v20 →

lore
Share & tools
lore
#0 lore raw

v16 cover openvswitch: Add support for 802.1ad

This patch accompanies version 14 of the user level openvswitch patch submitted to openvswitch dev list.

V16,15: 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           |  75 +++++++++++++----
 net/openvswitch/flow.h           |   8 +-
 net/openvswitch/flow_netlink.c   | 169 +++++++++++++++++++++++++++++++++++----
 net/openvswitch/vport-netdev.c   |   4 +-
 7 files changed, 253 insertions(+), 42 deletions(-)
Signature · 1 line
2.4.3
#1 lore raw

PATCH v16 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 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
#2 lore raw

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

In reply to Thomas F Herbert
---
 include/linux/if_vlan.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
include/linux/if_vlan.h +16 -0
index 67ce5bd..ac23521 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 · 1 line
2.4.3
#3 lore raw

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

On 10/15/2015 5:01 PM, Thomas F Herbert wrote:

Hm, I'm seeing no sign-off on this patch.

Quoted 13 lines
---
  include/linux/if_vlan.h | 16 ++++++++++++++++
  1 file changed, 16 insertions(+)
include/linux/if_vlan.h +1 -0
index 67ce5bd..ac23521 100644
@@ -627,6 +627,22 @@ static inline netdev_features_t vlan_features_check(const struct sk_buff *skb,
 
  	return features;
  }
+/**

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

Quoted 10 lines
include/linux/if_vlan.h +10 -0
+ * 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)):

Hm, I thought you had a request to delete the outer parens already...

[...]

MBR, Sergei

#4 lore raw

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

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/actions.c      |   6 +-
 net/openvswitch/flow.c         |  75 ++++++++++++++----
 net/openvswitch/flow.h         |   8 +-
 net/openvswitch/flow_netlink.c | 169 +++++++++++++++++++++++++++++++++++++----
 net/openvswitch/vport-netdev.c |   4 +-
 5 files changed, 228 insertions(+), 34 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 +60 -15

96 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 +154 -15

259 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 · 1 line
2.4.3
#5 lore raw

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

Quoted 43 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         |  75 ++++++++++++++----
 net/openvswitch/flow.h         |   8 +-
 net/openvswitch/flow_netlink.c | 169 +++++++++++++++++++++++++++++++++++++----
 net/openvswitch/vport-netdev.c |   4 +-
 5 files changed, 228 insertions(+), 34 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 +0 -0
index c8db44a..8a4e298 100644

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

Quoted 9 lines
net/openvswitch/flow.c +5 -1
@@ -302,24 +302,69 @@ static bool icmp6hdr_ok(struct sk_buff *skb)
                                  sizeof(struct icmp6hdr));
 }
 
-static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key)
+struct qtag_prefix {
+       __be16 eth_type; /* ETH_P_8021Q  or ETH_P_8021AD */
+       __be16 tci;
+};
+

Now we can just use newly defined struct vlan_header here.

Quoted 57 lines
net/openvswitch/flow.c +40 -8
+/* 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, __be16 vlan_proto,
+                         __be16 vlan_tci, struct vlan_head *vlan)
 {
-       struct qtag_prefix {
-               __be16 eth_type; /* ETH_P_8021Q */
-               __be16 tci;
-       };
-       struct qtag_prefix *qp;
+       if (likely(!eth_type_vlan(vlan_proto)))
+               return 0;
 
        if (unlikely(skb->len < sizeof(struct qtag_prefix) + sizeof(__be16)))
                return 0;
 
        if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
-                                        sizeof(__be16))))
+                                sizeof(__be16))))
                return -ENOMEM;
 
-       qp = (struct qtag_prefix *) skb->data;
-       key->eth.tci = qp->tci | htons(VLAN_TAG_PRESENT);
+       vlan->tci = vlan_tci | htons(VLAN_TAG_PRESENT);
+       vlan->tpid = vlan_proto;
+
        __skb_pull(skb, sizeof(struct qtag_prefix));
+       return 1;
+}
+
+static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key)
+{
+       struct qtag_prefix *qp = (struct qtag_prefix *)skb->data;
+       int res;
+
+       if (likely(skb_vlan_tag_present(skb))) {
+               key->eth.vlan.tci = htons(skb->vlan_tci);
+               key->eth.vlan.tpid = skb->vlan_proto;
+
+               /* Case where ingress processing has already stripped
+                * the outer vlan tag.
+                */
+               res = parse_vlan_tag(skb, qp->eth_type, qp->tci,
+                                    &key->eth.cvlan);
+               if (res < 0)
+                       return res;
+               /* For inner tag, return 0 because neither
+                * non-existant nor partial inner tag is an error.
+                */
+               return 0;
+       }
+       res = parse_vlan_tag(skb, qp->eth_type, qp->tci, &key->eth.vlan);
+       if (res <= 0)

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

Quoted 10 lines
net/openvswitch/flow.c +9 -0
+               /* This is an outer tag in the non-accelerated VLAN
+                * case. Return error unless it is a complete vlan tag.
+                */
+               return res;
+
+       /* Parse inner vlan tag if present for non-accelerated case. */
+       res = parse_vlan_tag(skb, qp->eth_type, qp->tci, &key->eth.cvlan);
+       if (res <= 0)
+               return res;
 

same qp pointer is passed for inner and outer vlan parameters here. It is better to just pass skb and keep qp inside parse_vlan_tag() function.

Quoted 6 lines
net/openvswitch/flow.c +0 -0
        return 0;
 }
@@ -480,12 +525,12 @@ static int key_extract(struct sk_buff *skb, struct sw_flow_key *key)
         * update skb->csum here.
         */
 

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

Quoted 10 lines
net/openvswitch/flow.c +4 -6
-       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))
-               if (unlikely(parse_vlan(skb, key)))
-                       return -ENOMEM;
+       key->eth.vlan.tci = 0;
+       key->eth.vlan.tpid = 0;
+       key->eth.cvlan.tci = 0;
+       key->eth.cvlan.tpid = 0;

Lets move this over to parse_vlan().

Quoted 9 lines
net/openvswitch/flow.c +2 -0
+       if (unlikely(parse_vlan(skb, key)))
+               return -ENOMEM;
 
        key->eth.type = parse_ethertype(skb);
        if (unlikely(key->eth.type == htons(0)))
net/openvswitch/flow_netlink.c +0 -0
index c92d6a2..5cff83c 100644

...

Quoted 18 lines

static int ovs_key_from_nlattrs(struct net *net, struct sw_flow_match *match,
u64 attrs, const struct nlattr **a, bool is_mask, bool log)

net/openvswitch/flow_netlink.c +3 -1
@@ -845,7 +875,7 @@ static int ovs_key_from_nlattrs(struct net *net, struct sw_flow_match *match,
                        return -EINVAL;
                }
 
-               SW_FLOW_KEY_PUT(match, eth.tci, tci, is_mask);
+               SW_FLOW_KEY_PUT(match, eth.vlan.tci, tci, is_mask);
                attrs &= ~(1 << OVS_KEY_ATTR_VLAN);
        }
 
@@ -1064,6 +1094,86 @@ 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,

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

Quoted 10 lines
net/openvswitch/flow_netlink.c +10 -0
+                                  u64 *key_attrs, bool *ie_valid,
+                                  const struct nlattr **a, bool is_mask,
+                                  bool log)
+{
+       int err;
+       const struct nlattr *encap;
+
+       if (!is_mask) {
+               u64 v_attrs = 0;
+

attributes does not need 64 bits, 32 bits are sufficient.

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

Quoted 10 lines
net/openvswitch/flow_netlink.c +10 -0
+               err = parse_flow_nlattrs(*nla, a, &v_attrs, log);
+               if (err)
+                       return err;
+               /* Another encap attribute here indicates
+                * the presence of a double tagged vlan.
+                */
+               if ((v_attrs & (1 << OVS_KEY_ATTR_ETHERTYPE)) &&
+                   eth_type_vlan(nla_get_be16(a[OVS_KEY_ATTR_ETHERTYPE]))) {
+                       if (!((v_attrs & (1ULL << OVS_KEY_ATTR_VLAN)) &&
+                             (v_attrs & (1ULL << OVS_KEY_ATTR_ENCAP)))) {

After changing v_attrs type, there is no need to use 1ULL.

Quoted 14 lines
net/openvswitch/flow_netlink.c +14 -0
+                               OVS_NLERR(log, "Invalid Inner VLAN frame");
+                               return -EINVAL;
+                       }
+                       encap = a[OVS_KEY_ATTR_ENCAP];
+
+                       err = cust_vlan_from_nlattrs(match, a, is_mask, log);
+                       if (err)
+                               return err;
+                       *ie_valid = true;
+                       *nla = encap;
+
+                       /* Insure that tci key attribute isn't
+                        * overwritten by encapsulated customer tci.
+                        * Ethertype is cleared because it is c_tpid.

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

Quoted 10 lines
net/openvswitch/flow_netlink.c +10 -0
+                        */
+                       v_attrs &= ~(1 << OVS_KEY_ATTR_ENCAP);
+                       v_attrs &= ~(1 << OVS_KEY_ATTR_VLAN);
+                       v_attrs &= ~(1 << OVS_KEY_ATTR_ETHERTYPE);
+
+                       *key_attrs |= v_attrs;
+                       err = parse_flow_nlattrs(*nla, a, key_attrs, log);
+                       if (err)
+                               return err;
+               }

Apart from the check for vlan and encap attribute, this whole block looks pretty much same for key and mask attribute. Can you define another function to factor out this code.

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

Quoted 4 lines
net/openvswitch/flow_netlink.c +4 -0
+
+       } else {
+               u64 mask_v_attrs = 0;
+

same as above mask_v_attrs does not need 64 bits, u32 is fine here.

Quoted 11 lines
net/openvswitch/flow_netlink.c +11 -0
+               err = parse_flow_mask_nlattrs(*nla, a, &mask_v_attrs, log);
+               if (err)
+                       return err;
+
+               if (mask_v_attrs & 1 << OVS_KEY_ATTR_ENCAP) {
+                       if (!*ie_valid) {
+                               OVS_NLERR(log, "Encap mask attribute is set for non-CVLAN frame.");
+                               err = -EINVAL;
+                               return err;
+                       }
+                       encap = a[OVS_KEY_ATTR_ENCAP];

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

Quoted 10 lines
net/openvswitch/flow_netlink.c +10 -0
+
+                       err = cust_vlan_from_nlattrs(match, a, is_mask, log);
+                       if (err)
+                               return err;
+                       *nla = encap;
+
+                       mask_v_attrs &= ~(1 << OVS_KEY_ATTR_ENCAP);
+                       mask_v_attrs &= ~(1ULL << OVS_KEY_ATTR_VLAN);
+                       mask_v_attrs &= ~(1ULL << OVS_KEY_ATTR_ETHERTYPE);
+

After changing the type, there is no need to use 1ULL.

Quoted 12 lines
net/openvswitch/flow_netlink.c +9 -0
+                       *key_attrs |= mask_v_attrs;
+                       err = parse_flow_mask_nlattrs(*nla, a, key_attrs, log);
+                       if (err)
+                               return err;
+               }
+       }
+       return 0;
+}
+
 /**
  * ovs_nla_get_match - parses Netlink attributes into a flow key and
  * mask. In case the 'mask' is NULL, the flow is treated as exact match

...

Quoted 9 lines
net/openvswitch/flow_netlink.c +1 -0
@@ -1320,6 +1437,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 static int __ovs_nla_put_key(const struct sw_flow_key *swkey, · line 1493

Quoted 10 lines
net/openvswitch/flow_netlink.c +4 -2
@@ -1368,17 +1486,36 @@ 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);
+

Since tpid mask is checked at flow install time, lets just return output->eth.vlan.tpid for mask too.

Quoted 6 lines
net/openvswitch/flow_netlink.c +1 -2
                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)

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

Quoted 10 lines
net/openvswitch/flow_netlink.c +8 -1
+               if (!swkey->eth.vlan.tci)
                        goto unencap;
-       } else
+               if (swkey->eth.cvlan.tci) {
+                       __be16 eth_type;
+
+                       /* Customer tci is nested but uses same key attribute.
+                        */
+                       eth_type = !is_mask ? output->eth.cvlan.tpid :
+                                             htons(0xffff);

same as above, Lets just return output->eth.cvlan.tpid even for mask.

A message that is not in the archive (sent off-list or not yet received): CALnjE+o4o1RWf12F9wyeZfb9=Y+nw+Bta=NA+we1zQ+4yGLYNA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#7 lore raw

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

On 10/15/15 7:02 PM, Pravin Shelar wrote:
Thanks for the review. See my comment below.

--TFH

Quoted 173 lines
Quoted 43 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         |  75 ++++++++++++++----
  net/openvswitch/flow.h         |   8 +-
  net/openvswitch/flow_netlink.c | 169 +++++++++++++++++++++++++++++++++++++----
  net/openvswitch/vport-netdev.c |   4 +-
  5 files changed, 228 insertions(+), 34 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 +0 -0
index c8db44a..8a4e298 100644

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

Quoted 9 lines
net/openvswitch/flow.c +5 -1
@@ -302,24 +302,69 @@ static bool icmp6hdr_ok(struct sk_buff *skb)
                                   sizeof(struct icmp6hdr));
  }
 
-static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key)
+struct qtag_prefix {
+       __be16 eth_type; /* ETH_P_8021Q  or ETH_P_8021AD */
+       __be16 tci;
+};
+

Now we can just use newly defined struct vlan_header here.

Quoted 57 lines
net/openvswitch/flow.c +40 -8
+/* 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, __be16 vlan_proto,
+                         __be16 vlan_tci, struct vlan_head *vlan)
  {
-       struct qtag_prefix {
-               __be16 eth_type; /* ETH_P_8021Q */
-               __be16 tci;
-       };
-       struct qtag_prefix *qp;
+       if (likely(!eth_type_vlan(vlan_proto)))
+               return 0;
 
         if (unlikely(skb->len < sizeof(struct qtag_prefix) + sizeof(__be16)))
                 return 0;
 
         if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
-                                        sizeof(__be16))))
+                                sizeof(__be16))))
                 return -ENOMEM;
 
-       qp = (struct qtag_prefix *) skb->data;
-       key->eth.tci = qp->tci | htons(VLAN_TAG_PRESENT);
+       vlan->tci = vlan_tci | htons(VLAN_TAG_PRESENT);
+       vlan->tpid = vlan_proto;
+
         __skb_pull(skb, sizeof(struct qtag_prefix));
+       return 1;
+}
+
+static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key)
+{
+       struct qtag_prefix *qp = (struct qtag_prefix *)skb->data;
+       int res;
+
+       if (likely(skb_vlan_tag_present(skb))) {
+               key->eth.vlan.tci = htons(skb->vlan_tci);
+               key->eth.vlan.tpid = skb->vlan_proto;
+
+               /* Case where ingress processing has already stripped
+                * the outer vlan tag.
+                */
+               res = parse_vlan_tag(skb, qp->eth_type, qp->tci,
+                                    &key->eth.cvlan);
+               if (res < 0)
+                       return res;
+               /* For inner tag, return 0 because neither
+                * non-existant nor partial inner tag is an error.
+                */
+               return 0;
+       }
+       res = parse_vlan_tag(skb, qp->eth_type, qp->tci, &key->eth.vlan);
+       if (res <= 0)

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

Quoted 10 lines
net/openvswitch/flow.c +9 -0
+               /* This is an outer tag in the non-accelerated VLAN
+                * case. Return error unless it is a complete vlan tag.
+                */
+               return res;
+
+       /* Parse inner vlan tag if present for non-accelerated case. */
+       res = parse_vlan_tag(skb, qp->eth_type, qp->tci, &key->eth.cvlan);
+       if (res <= 0)
+               return res;
 

same qp pointer is passed for inner and outer vlan parameters here. It is better to just pass skb and keep qp inside parse_vlan_tag() function.

Quoted 6 lines
net/openvswitch/flow.c +0 -0
         return 0;
  }
@@ -480,12 +525,12 @@ static int key_extract(struct sk_buff *skb, struct sw_flow_key *key)
          * update skb->csum here.
          */
 

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

Quoted 10 lines
net/openvswitch/flow.c +4 -6
-       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))
-               if (unlikely(parse_vlan(skb, key)))
-                       return -ENOMEM;
+       key->eth.vlan.tci = 0;
+       key->eth.vlan.tpid = 0;
+       key->eth.cvlan.tci = 0;
+       key->eth.cvlan.tpid = 0;

Lets move this over to parse_vlan().

Quoted 9 lines
net/openvswitch/flow.c +2 -0
+       if (unlikely(parse_vlan(skb, key)))
+               return -ENOMEM;
 
         key->eth.type = parse_ethertype(skb);
         if (unlikely(key->eth.type == htons(0)))
net/openvswitch/flow_netlink.c +0 -0
index c92d6a2..5cff83c 100644

...

Quoted 16 lines

static int ovs_key_from_nlattrs(struct net *net, struct sw_flow_match *match,
u64 attrs, const struct nlattr **a, bool is_mask, bool log)

net/openvswitch/flow_netlink.c +1 -1
@@ -845,7 +875,7 @@ static int ovs_key_from_nlattrs(struct net *net, struct sw_flow_match *match,
                         return -EINVAL;
                 }
 
-               SW_FLOW_KEY_PUT(match, eth.tci, tci, is_mask);
+               SW_FLOW_KEY_PUT(match, eth.vlan.tci, tci, is_mask);
                 attrs &= ~(1 << OVS_KEY_ATTR_VLAN);
         }
 
@@ -1064,6 +1094,86 @@ static void mask_set_nlattr(struct nlattr *attr, u8 val)
         nlattr_set(attr, val, ovs_key_lens);
  }
 
Quoted 13 lines

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

Quoted 12 lines
net/openvswitch/flow_netlink.c +12 -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;
+       const struct nlattr *encap;
+
+       if (!is_mask) {
+               u64 v_attrs = 0;
+

attributes does not need 64 bits, 32 bits are sufficient.

Yes, there certainly not more then 32 attributes in this layer of nesting but in the parse_flow_nlattrs() function argument 3 is a u64 *
Don't you think this might be dangerous? Maybe are you saying that I should rewrite that generic function to only support a maximum of 32 netlink attributes per level of nesting. The current OVS kernel module is optimized for 64 bit architectures where there is no extra cost for a 64 bit value and I think what you are suggesting might go beyond the scope of this patch. If it is a good idea, shouldn't it be considered for a separate patch?

--TFH

Quoted 11 lines

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

Quoted 10 lines
net/openvswitch/flow_netlink.c +10 -0
+               err = parse_flow_nlattrs(*nla, a, &v_attrs, log);
+               if (err)
+                       return err;
+               /* Another encap attribute here indicates
+                * the presence of a double tagged vlan.
+                */
+               if ((v_attrs & (1 << OVS_KEY_ATTR_ETHERTYPE)) &&
+                   eth_type_vlan(nla_get_be16(a[OVS_KEY_ATTR_ETHERTYPE]))) {
+                       if (!((v_attrs & (1ULL << OVS_KEY_ATTR_VLAN)) &&
+                             (v_attrs & (1ULL << OVS_KEY_ATTR_ENCAP)))) {

After changing v_attrs type, there is no need to use 1ULL.

See remark above.

Quoted 29 lines
Quoted 15 lines
net/openvswitch/flow_netlink.c +14 -0
+                               OVS_NLERR(log, "Invalid Inner VLAN frame");
+                               return -EINVAL;
+                       }
+                       encap = a[OVS_KEY_ATTR_ENCAP];
+
+                       err = cust_vlan_from_nlattrs(match, a, is_mask, log);
+                       if (err)
+                               return err;
+                       *ie_valid = true;
+                       *nla = encap;
+
+                       /* Insure that tci key attribute isn't
+                        * overwritten by encapsulated customer tci.
+                        * Ethertype is cleared because it is c_tpid.

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

Quoted 10 lines
net/openvswitch/flow_netlink.c +10 -0
+                        */
+                       v_attrs &= ~(1 << OVS_KEY_ATTR_ENCAP);
+                       v_attrs &= ~(1 << OVS_KEY_ATTR_VLAN);
+                       v_attrs &= ~(1 << OVS_KEY_ATTR_ETHERTYPE);
+
+                       *key_attrs |= v_attrs;
+                       err = parse_flow_nlattrs(*nla, a, key_attrs, log);
+                       if (err)
+                               return err;
+               }

Apart from the check for vlan and encap attribute, this whole block looks pretty much same for key and mask attribute. Can you define another function to factor out this code.

Quoted 5 lines

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

Quoted 4 lines
net/openvswitch/flow_netlink.c +4 -0
+
+       } else {
+               u64 mask_v_attrs = 0;
+

same as above mask_v_attrs does not need 64 bits, u32 is fine here.

Again, see remark above. In the function below, the 3rd argument is a u64 *.

Quoted 76 lines
Quoted 12 lines
net/openvswitch/flow_netlink.c +11 -0
+               err = parse_flow_mask_nlattrs(*nla, a, &mask_v_attrs, log);
+               if (err)
+                       return err;
+
+               if (mask_v_attrs & 1 << OVS_KEY_ATTR_ENCAP) {
+                       if (!*ie_valid) {
+                               OVS_NLERR(log, "Encap mask attribute is set for non-CVLAN frame.");
+                               err = -EINVAL;
+                               return err;
+                       }
+                       encap = a[OVS_KEY_ATTR_ENCAP];

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

Quoted 10 lines
net/openvswitch/flow_netlink.c +10 -0
+
+                       err = cust_vlan_from_nlattrs(match, a, is_mask, log);
+                       if (err)
+                               return err;
+                       *nla = encap;
+
+                       mask_v_attrs &= ~(1 << OVS_KEY_ATTR_ENCAP);
+                       mask_v_attrs &= ~(1ULL << OVS_KEY_ATTR_VLAN);
+                       mask_v_attrs &= ~(1ULL << OVS_KEY_ATTR_ETHERTYPE);
+

After changing the type, there is no need to use 1ULL.

Quoted 12 lines
net/openvswitch/flow_netlink.c +9 -0
+                       *key_attrs |= mask_v_attrs;
+                       err = parse_flow_mask_nlattrs(*nla, a, key_attrs, log);
+                       if (err)
+                               return err;
+               }
+       }
+       return 0;
+}
+
  /**
   * ovs_nla_get_match - parses Netlink attributes into a flow key and
   * mask. In case the 'mask' is NULL, the flow is treated as exact match

...

Quoted 9 lines
net/openvswitch/flow_netlink.c +1 -0
@@ -1320,6 +1437,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 static int __ovs_nla_put_key(const struct sw_flow_key *swkey, · line 1493

Quoted 10 lines
net/openvswitch/flow_netlink.c +4 -2
@@ -1368,17 +1486,36 @@ 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);
+

Since tpid mask is checked at flow install time, lets just return output->eth.vlan.tpid for mask too.

Quoted 6 lines
net/openvswitch/flow_netlink.c +1 -2
                 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)

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

Quoted 10 lines
net/openvswitch/flow_netlink.c +8 -1
+               if (!swkey->eth.vlan.tci)
                         goto unencap;
-       } else
+               if (swkey->eth.cvlan.tci) {
+                       __be16 eth_type;
+
+                       /* Customer tci is nested but uses same key attribute.
+                        */
+                       eth_type = !is_mask ? output->eth.cvlan.tpid :
+                                             htons(0xffff);
Quoted 1 line

same as above, Lets just return output->eth.cvlan.tpid even for mask.

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

#9 lore raw

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

Quoted 208 lines · Thomas F Herbert

On 10/15/15 7:02 PM, Pravin Shelar wrote:
Thanks for the review. See my comment below.

--TFH

Quoted 187 lines
Quoted 47 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         |  75 ++++++++++++++----
  net/openvswitch/flow.h         |   8 +-
  net/openvswitch/flow_netlink.c | 169
+++++++++++++++++++++++++++++++++++++----
  net/openvswitch/vport-netdev.c |   4 +-
  5 files changed, 228 insertions(+), 34 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 +0 -0
index c8db44a..8a4e298 100644

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

Quoted 9 lines
net/openvswitch/flow.c +5 -1
@@ -302,24 +302,69 @@ static bool icmp6hdr_ok(struct sk_buff *skb)
                                   sizeof(struct icmp6hdr));
  }
 
-static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key)
+struct qtag_prefix {
+       __be16 eth_type; /* ETH_P_8021Q  or ETH_P_8021AD */
+       __be16 tci;
+};
+

Now we can just use newly defined struct vlan_header here.

Quoted 59 lines
net/openvswitch/flow.c +41 -8
+/* 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, __be16 vlan_proto,
+                         __be16 vlan_tci, struct vlan_head *vlan)
  {
-       struct qtag_prefix {
-               __be16 eth_type; /* ETH_P_8021Q */
-               __be16 tci;
-       };
-       struct qtag_prefix *qp;
+       if (likely(!eth_type_vlan(vlan_proto)))
+               return 0;
 
         if (unlikely(skb->len < sizeof(struct qtag_prefix) +
 sizeof(__be16)))
                 return 0;
 
         if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
-                                        sizeof(__be16))))
+                                sizeof(__be16))))
                 return -ENOMEM;
 
-       qp = (struct qtag_prefix *) skb->data;
-       key->eth.tci = qp->tci | htons(VLAN_TAG_PRESENT);
+       vlan->tci = vlan_tci | htons(VLAN_TAG_PRESENT);
+       vlan->tpid = vlan_proto;
+
         __skb_pull(skb, sizeof(struct qtag_prefix));
+       return 1;
+}
+
+static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key)
+{
+       struct qtag_prefix *qp = (struct qtag_prefix *)skb->data;
+       int res;
+
+       if (likely(skb_vlan_tag_present(skb))) {
+               key->eth.vlan.tci = htons(skb->vlan_tci);
+               key->eth.vlan.tpid = skb->vlan_proto;
+
+               /* Case where ingress processing has already stripped
+                * the outer vlan tag.
+                */
+               res = parse_vlan_tag(skb, qp->eth_type, qp->tci,
+                                    &key->eth.cvlan);
+               if (res < 0)
+                       return res;
+               /* For inner tag, return 0 because neither
+                * non-existant nor partial inner tag is an error.
+                */
+               return 0;
+       }
+       res = parse_vlan_tag(skb, qp->eth_type, qp->tci, &key->eth.vlan);
+       if (res <= 0)
+               /* This is an outer tag in the non-accelerated VLAN

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

Quoted 10 lines
net/openvswitch/flow.c +8 -0
+                * case. Return error unless it is a complete vlan tag.
+                */
+               return res;
+
+       /* Parse inner vlan tag if present for non-accelerated case. */
+       res = parse_vlan_tag(skb, qp->eth_type, qp->tci,
 &key->eth.cvlan);
+       if (res <= 0)
+               return res;
 

same qp pointer is passed for inner and outer vlan parameters here. It is better to just pass skb and keep qp inside parse_vlan_tag() function.

Quoted 7 lines
         return 0;

}

net/openvswitch/flow.c +0 -0
@@ -480,12 +525,12 @@ static int key_extract(struct sk_buff *skb, struct
 sw_flow_key *key)
          * update skb->csum here.
          */
 

net/openvswitch/flow.c static int key_extract(struct sk_buff *skb, struct · line 532

Quoted 10 lines
net/openvswitch/flow.c +4 -6
-       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))
-               if (unlikely(parse_vlan(skb, key)))
-                       return -ENOMEM;
+       key->eth.vlan.tci = 0;
+       key->eth.vlan.tpid = 0;
+       key->eth.cvlan.tci = 0;
+       key->eth.cvlan.tpid = 0;

Lets move this over to parse_vlan().

Quoted 10 lines
net/openvswitch/flow.c +2 -0
+       if (unlikely(parse_vlan(skb, key)))
+               return -ENOMEM;
 
         key->eth.type = parse_ethertype(skb);
         if (unlikely(key->eth.type == htons(0)))
net/openvswitch/flow_netlink.c +0 -0
index c92d6a2..5cff83c 100644

...

Quoted 19 lines

static int ovs_key_from_nlattrs(struct net *net, struct sw_flow_match
*match,
u64 attrs, const struct nlattr **a, bool is_mask, bool log)

net/openvswitch/flow_netlink.c +1 -1
@@ -845,7 +875,7 @@ static int ovs_key_from_nlattrs(struct net *net,
 struct sw_flow_match *match,
                         return -EINVAL;
                 }
 
-               SW_FLOW_KEY_PUT(match, eth.tci, tci, is_mask);
+               SW_FLOW_KEY_PUT(match, eth.vlan.tci, tci, is_mask);
                 attrs &= ~(1 << OVS_KEY_ATTR_VLAN);
         }
@@ -1064,6 +1094,86 @@ static void mask_set_nlattr(struct nlattr *attr,
 u8 val)
         nlattr_set(attr, val, ovs_key_lens);
  }
 
Quoted 14 lines

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

Quoted 12 lines
net/openvswitch/flow_netlink.c +12 -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;
+       const struct nlattr *encap;
+
+       if (!is_mask) {
+               u64 v_attrs = 0;
+

attributes does not need 64 bits, 32 bits are sufficient.

Quoted 9 lines

Yes, there certainly not more then 32 attributes in this layer of nesting but in the parse_flow_nlattrs() function argument 3 is a u64 * Don't you think this might be dangerous? Maybe are you saying that I should rewrite that generic function to only support a maximum of 32 netlink attributes per level of nesting. The current OVS kernel module is optimized for 64 bit architectures where there is no extra cost for a 64 bit value and I think what you are suggesting might go beyond the scope of this patch. If it is a good idea, shouldn't it be considered for a separate patch?

OK. Lets keep it as it is.

Quoted 15 lines

--TFH

Quoted 14 lines
Quoted 13 lines
net/openvswitch/flow_netlink.c +10 -0
+               err = parse_flow_nlattrs(*nla, a, &v_attrs, log);
+               if (err)
+                       return err;
+               /* Another encap attribute here indicates
+                * the presence of a double tagged vlan.
+                */
+               if ((v_attrs & (1 << OVS_KEY_ATTR_ETHERTYPE)) &&
+
 eth_type_vlan(nla_get_be16(a[OVS_KEY_ATTR_ETHERTYPE]))) {
+                       if (!((v_attrs & (1ULL << OVS_KEY_ATTR_VLAN)) &&
+                             (v_attrs & (1ULL << OVS_KEY_ATTR_ENCAP))))
 {
Quoted 4 lines
Quoted 1 line

After changing v_attrs type, there is no need to use 1ULL.

See remark above.

Just to be consistent, lets use 32 bit value of one here and other such instances.
_______________________________________________
dev mailing list
[email protected]
http://openvswitch.org/mailman/listinfo/dev

#10 lore raw

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

Quoted 228 lines · Pravin Shelar
Quoted 202 lines · Thomas F Herbert

On 10/15/15 7:02 PM, Pravin Shelar wrote:
Thanks for the review. See my comment below.

--TFH

Quoted 183 lines
Quoted 46 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         |  75 ++++++++++++++----
   net/openvswitch/flow.h         |   8 +-
   net/openvswitch/flow_netlink.c | 169
+++++++++++++++++++++++++++++++++++++----
   net/openvswitch/vport-netdev.c |   4 +-
   5 files changed, 228 insertions(+), 34 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 +0 -0
index c8db44a..8a4e298 100644

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

Quoted 9 lines
net/openvswitch/flow.c +5 -1
@@ -302,24 +302,69 @@ static bool icmp6hdr_ok(struct sk_buff *skb)
                                    sizeof(struct icmp6hdr));
   }
 
-static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key)
+struct qtag_prefix {
+       __be16 eth_type; /* ETH_P_8021Q  or ETH_P_8021AD */
+       __be16 tci;
+};
+

Now we can just use newly defined struct vlan_header here.

Quoted 59 lines
net/openvswitch/flow.c +41 -8
+/* 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, __be16 vlan_proto,
+                         __be16 vlan_tci, struct vlan_head *vlan)
   {
-       struct qtag_prefix {
-               __be16 eth_type; /* ETH_P_8021Q */
-               __be16 tci;
-       };
-       struct qtag_prefix *qp;
+       if (likely(!eth_type_vlan(vlan_proto)))
+               return 0;
 
          if (unlikely(skb->len < sizeof(struct qtag_prefix) +
 sizeof(__be16)))
                  return 0;
 
          if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
-                                        sizeof(__be16))))
+                                sizeof(__be16))))
                  return -ENOMEM;
 
-       qp = (struct qtag_prefix *) skb->data;
-       key->eth.tci = qp->tci | htons(VLAN_TAG_PRESENT);
+       vlan->tci = vlan_tci | htons(VLAN_TAG_PRESENT);
+       vlan->tpid = vlan_proto;
+
          __skb_pull(skb, sizeof(struct qtag_prefix));
+       return 1;
+}
+
+static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key)
+{
+       struct qtag_prefix *qp = (struct qtag_prefix *)skb->data;
+       int res;
+
+       if (likely(skb_vlan_tag_present(skb))) {
+               key->eth.vlan.tci = htons(skb->vlan_tci);
+               key->eth.vlan.tpid = skb->vlan_proto;
+
+               /* Case where ingress processing has already stripped
+                * the outer vlan tag.
+                */
+               res = parse_vlan_tag(skb, qp->eth_type, qp->tci,
+                                    &key->eth.cvlan);
+               if (res < 0)
+                       return res;
+               /* For inner tag, return 0 because neither
+                * non-existant nor partial inner tag is an error.
+                */
+               return 0;
+       }
+       res = parse_vlan_tag(skb, qp->eth_type, qp->tci, &key->eth.vlan);
+       if (res <= 0)
+               /* This is an outer tag in the non-accelerated VLAN

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

Quoted 10 lines
net/openvswitch/flow.c +8 -0
+                * case. Return error unless it is a complete vlan tag.
+                */
+               return res;
+
+       /* Parse inner vlan tag if present for non-accelerated case. */
+       res = parse_vlan_tag(skb, qp->eth_type, qp->tci,
 &key->eth.cvlan);
+       if (res <= 0)
+               return res;
 

same qp pointer is passed for inner and outer vlan parameters here. It is better to just pass skb and keep qp inside parse_vlan_tag() function.

Quoted 7 lines
          return 0;

}

net/openvswitch/flow.c +0 -0
@@ -480,12 +525,12 @@ static int key_extract(struct sk_buff *skb, struct
 sw_flow_key *key)
           * update skb->csum here.
           */
 

net/openvswitch/flow.c static int key_extract(struct sk_buff *skb, struct · line 532

Quoted 10 lines
net/openvswitch/flow.c +4 -6
-       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))
-               if (unlikely(parse_vlan(skb, key)))
-                       return -ENOMEM;
+       key->eth.vlan.tci = 0;
+       key->eth.vlan.tpid = 0;
+       key->eth.cvlan.tci = 0;
+       key->eth.cvlan.tpid = 0;

Lets move this over to parse_vlan().

Quoted 10 lines
net/openvswitch/flow.c +2 -0
+       if (unlikely(parse_vlan(skb, key)))
+               return -ENOMEM;
 
          key->eth.type = parse_ethertype(skb);
          if (unlikely(key->eth.type == htons(0)))
net/openvswitch/flow_netlink.c +0 -0
index c92d6a2..5cff83c 100644

...

Quoted 19 lines

static int ovs_key_from_nlattrs(struct net *net, struct sw_flow_match
*match,
u64 attrs, const struct nlattr **a, bool is_mask, bool log)

net/openvswitch/flow_netlink.c +1 -1
@@ -845,7 +875,7 @@ static int ovs_key_from_nlattrs(struct net *net,
 struct sw_flow_match *match,
                          return -EINVAL;
                  }
 
-               SW_FLOW_KEY_PUT(match, eth.tci, tci, is_mask);
+               SW_FLOW_KEY_PUT(match, eth.vlan.tci, tci, is_mask);
                  attrs &= ~(1 << OVS_KEY_ATTR_VLAN);
          }
@@ -1064,6 +1094,86 @@ static void mask_set_nlattr(struct nlattr *attr,
 u8 val)
          nlattr_set(attr, val, ovs_key_lens);
   }
 
Quoted 13 lines

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

Quoted 12 lines
net/openvswitch/flow_netlink.c +12 -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;
+       const struct nlattr *encap;
+
+       if (!is_mask) {
+               u64 v_attrs = 0;
+

attributes does not need 64 bits, 32 bits are sufficient.

Quoted 9 lines

Yes, there certainly not more then 32 attributes in this layer of nesting but in the parse_flow_nlattrs() function argument 3 is a u64 * Don't you think this might be dangerous? Maybe are you saying that I should rewrite that generic function to only support a maximum of 32 netlink attributes per level of nesting. The current OVS kernel module is optimized for 64 bit architectures where there is no extra cost for a 64 bit value and I think what you are suggesting might go beyond the scope of this patch. If it is a good idea, shouldn't it be considered for a separate patch?

OK. Lets keep it as it is.

Quoted 13 lines

--TFH

Quoted 12 lines
Quoted 12 lines
net/openvswitch/flow_netlink.c +10 -0
+               err = parse_flow_nlattrs(*nla, a, &v_attrs, log);
+               if (err)
+                       return err;
+               /* Another encap attribute here indicates
+                * the presence of a double tagged vlan.
+                */
+               if ((v_attrs & (1 << OVS_KEY_ATTR_ETHERTYPE)) &&
+
 eth_type_vlan(nla_get_be16(a[OVS_KEY_ATTR_ETHERTYPE]))) {
+                       if (!((v_attrs & (1ULL << OVS_KEY_ATTR_VLAN)) &&
+                             (v_attrs & (1ULL << OVS_KEY_ATTR_ENCAP))))
 {
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

After changing v_attrs type, there is no need to use 1ULL.

See remark above.

Just to be consistent, lets use 32 bit value of one here and other such instances.

OK, I agree. The 1ULL is not necessary in my opinion.

maintainer
#11 lore raw
In reply to Thomas F Herbert

From: Thomas F Herbert <[email protected]>
Date: Thu, 15 Oct 2015 10:01:52 -0400

Quoted 4 lines

This patch accompanies version 14 of the user level openvswitch patch submitted to openvswitch dev list.

V16,15: Implement reviewer comments.

Missing signoffs, missed handling of feedback from Sergei, so sorry this still needs work :-/

A message that is not in the archive (sent off-list or not yet received): 20151015.231643.799590798559891150.davem-fT/PcQaiUtIeIZ0/[email protected]

#13 lore raw
Quoted 9 lines · David Miller

From: Thomas F Herbert <[email protected]>
Date: Thu, 15 Oct 2015 10:01:52 -0400

Quoted 4 lines

This patch accompanies version 14 of the user level openvswitch patch submitted to openvswitch dev list.

V16,15: Implement reviewer comments.

Missing signoffs, missed handling of feedback from Sergei, so sorry this still needs work :-/

Sorry, I was focused on Pravin's review and missed that. Next series today will delete the redundant parens, Thanks Sergei. and some rework after Pravin's reviews.

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