Skip to contentSkip to conversation

openvswitch: Add support for 802.1ad

PATCH Superseded Thomas F Herbert 5 participants 12 messages Oct 10, 2015 – Oct 15, 2015 4 messages not in the archive

Subsystems (3)

v15 of 20 Superseded Latest is v20 →

lore
Share & tools
lore
#0 lore raw

v15 cover openvswitch: Add support for 802.1ad

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          |  17 ++++
 include/uapi/linux/openvswitch.h |  17 ++--
 net/openvswitch/actions.c        |   6 +-
 net/openvswitch/flow.c           |  92 ++++++++++++++++++----
 net/openvswitch/flow.h           |  11 ++-
 net/openvswitch/flow_netlink.c   | 166 +++++++++++++++++++++++++++++++++++----
 net/openvswitch/vport-netdev.c   |   4 +-
 7 files changed, 271 insertions(+), 42 deletions(-)

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

V15: Implement reviewer comments.

V14: Add outer tpid to flow_key

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

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

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

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

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

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

V9: Includes changes suggested by reviewers

V8: Includes changes suggested by reviewers

V7: Includes changes suggested by reviewers

V6: Rebased to net-next

V5: Use encapsulated attributes

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

Signature · 1 line
2.4.3

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

#2 lore raw

PATCH v15 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 · 6 lines
2.4.3

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

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

In reply to a message not in the archive

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

---
 net/openvswitch/actions.c      |   6 +-
 net/openvswitch/flow.c         |  92 +++++++++++++++++++----
 net/openvswitch/flow.h         |  11 ++-
 net/openvswitch/flow_netlink.c | 166 +++++++++++++++++++++++++++++++++++++----
 net/openvswitch/vport-netdev.c |   4 +-
 5 files changed, 245 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 +77 -15

110 lines not on this page · raw message

net/openvswitch/flow.h +10 -1
index fe527d2..539494e 100644
@@ -68,7 +68,16 @@ 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 {
+			__be16 tpid;	/* Outer Vlan type 802.1q or 802.1ad.*/
+			__be16 tci;	/* 0 if no VLAN, VLAN_TAG_PRESENT */
+					/* set otherwise. */
+		} vlan;
+		struct {
+			__be16 tpid;	/* Inner Vlan DL_type 802.1q.*/
+			__be16 tci;	/* 0 if no CVLAN, VLAN_TAG_PRESENT */
+					/* set otherwise. */
+		} cvlan;
 		__be16 type;		/* Ethernet frame type. */
 	} eth;
 	union {
net/openvswitch/flow_netlink.c +151 -15

256 lines not on this page · raw message

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

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

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

Quoted 14 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         |  92 +++++++++++++++++++----
 net/openvswitch/flow.h         |  11 ++-
 net/openvswitch/flow_netlink.c | 166 +++++++++++++++++++++++++++++++++++++----
 net/openvswitch/vport-netdev.c |   4 +-
 5 files changed, 245 insertions(+), 34 deletions(-)

...

Quoted 64 lines
net/openvswitch/flow.c +43 -7
index c8db44a..0f9479c 100644
@@ -305,21 +305,83 @@ static bool icmp6hdr_ok(struct sk_buff *skb)
 static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key)
 {
        struct qtag_prefix {
-               __be16 eth_type; /* ETH_P_8021Q */
+               __be16 eth_type; /* ETH_P_8021Q  or ETH_P_8021AD */
                __be16 tci;
        };
-       struct qtag_prefix *qp;
+       struct qtag_prefix *qp = (struct qtag_prefix *)skb->data;
 
-       if (unlikely(skb->len < sizeof(struct qtag_prefix) + sizeof(__be16)))
+       if (likely(skb_vlan_tag_present(skb))) {
+               key->eth.vlan.tci = htons(skb->vlan_tci);
+               key->eth.vlan.tpid = skb->vlan_proto;
+
+               /* Case where upstream
+                * processing has already stripped the outer vlan tag.
+                */
+               if (unlikely(skb->vlan_proto == htons(ETH_P_8021AD))) {
+                       if (unlikely(skb->len < sizeof(struct qtag_prefix) +
+                                       sizeof(__be16))) {
+                               key->eth.vlan.tci = 0;
+                               return 0;
+                       }
+
+                       if (unlikely(!pskb_may_pull(skb,
+                                                   sizeof(struct qtag_prefix) +
+                                                   sizeof(__be16))))
+                               return -ENOMEM;
+
+                       qp = (struct qtag_prefix *)skb->data;
+                       key->eth.cvlan.tci =
+                               qp->tci | htons(VLAN_TAG_PRESENT);
+                       key->eth.cvlan.tpid = qp->eth_type;
+
+                       __skb_pull(skb, sizeof(struct qtag_prefix));
+               }
                return 0;
 
-       if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
-                                        sizeof(__be16))))
-               return -ENOMEM;
+       } else if (qp->eth_type == htons(ETH_P_8021AD)) {
+
+               if (unlikely(skb->len < sizeof(struct qtag_prefix) +
+                                       sizeof(__be16)))
+                       return 0;
+
+               if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
+                               sizeof(__be16))))
+                       return -ENOMEM;
+
+               qp = (struct qtag_prefix *)skb->data;
+               key->eth.vlan.tci = qp->tci | htons(VLAN_TAG_PRESENT);
+               key->eth.vlan.tpid = qp->eth_type;
+
+               __skb_pull(skb, sizeof(struct qtag_prefix));
 
-       qp = (struct qtag_prefix *) skb->data;

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

Quoted 10 lines
net/openvswitch/flow.c +8 -2
-       key->eth.tci = qp->tci | htons(VLAN_TAG_PRESENT);
-       __skb_pull(skb, sizeof(struct qtag_prefix));
+               if (unlikely(skb->len < sizeof(struct qtag_prefix) +
+                                       sizeof(__be16)))
+                       return 0;
+
+               if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
+                               sizeof(__be16))))
+                       return -ENOMEM;
+

There is no check for inner protocol in the packet.

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

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

Quoted 10 lines
net/openvswitch/flow.c +7 -0
+                               sizeof(__be16))))
+                       return -ENOMEM;
+               key->eth.vlan.tci = qp->tci | htons(VLAN_TAG_PRESENT);
+               key->eth.vlan.tpid = qp->eth_type;
+
+               __skb_pull(skb, sizeof(struct qtag_prefix));
+       }
 
        return 0;
 }

I see lot of duplicate code here. How about code below:

struct qtag_prefix {
        __be16 eth_type; /* ETH_P_8021Q  or ETH_P_8021AD */
        __be16 tci;
};

/* Return < 0 on memory error
* Return == 0 on non vlan or incomplete packet packet
* Return > 0 on successfully parsing vlan tag.
*/
static int parse_vlan_tag(__be16 vlan_proto, struct sk_buff *skb,
struct vlan_tag *cvlan)

{
        if (likely(!eth_type_vlan(skb->vlan_proto)))
                return 0;

        if (unlikely(skb->len < sizeof(struct qtag_prefix) + sizeof(__be16))) {
                vlan->tci = 0;
                return 0;
        }

        if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
sizeof(__be16))))
                        return -ENOMEM;

        qp = (struct qtag_prefix *)skb->data;
        key->eth.cvlan.tci = qp->tci | htons(VLAN_TAG_PRESENT);
        key->eth.cvlan.tpid = qp->eth_type;

        __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 upstream
                 * processing has already stripped the outer vlan tag.
                 */
                res = parse_vlan_tag(skb->vlan_proto, skb, &key->eth.cvlan);
                if (res < 0)
                        return res;
                /* Since this was inner tag, return zero in either
success or failure
                 * in parsing inner tag.
                 */
                return 0;
        }
        res = parse_vlan_tag(qp->eth_type, skb, &key->eth.vlan);
        if (res <= 0)
                return res;

        res = parse_vlan_tag(key->eth.vlan.tpid, skb, &key->eth.vlan);
        if (res <= 0)
                return res;

        return 0;
}
Quoted 9 lines
net/openvswitch/flow.h +0 -1
index fe527d2..539494e 100644
@@ -68,7 +68,16 @@ 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. */

net/openvswitch/flow.h struct sw_flow_key { · line 80

Quoted 10 lines
net/openvswitch/flow.h +10 -0
+               struct {
+                       __be16 tpid;    /* Outer Vlan type 802.1q or 802.1ad.*/
+                       __be16 tci;     /* 0 if no VLAN, VLAN_TAG_PRESENT */
+                                       /* set otherwise. */
+               } vlan;
+               struct {
+                       __be16 tpid;    /* Inner Vlan DL_type 802.1q.*/
+                       __be16 tci;     /* 0 if no CVLAN, VLAN_TAG_PRESENT */
+                                       /* set otherwise. */
+               } cvlan;

We need to define structure for vlan tag key here for the pseudo code to work.

Quoted 36 lines
net/openvswitch/flow.h +0 -0
                __be16 type;            /* Ethernet frame type. */
        } eth;
        union {
net/openvswitch/flow_netlink.c +10 -1
index c92d6a2..af06683 100644
@@ -811,6 +811,33 @@ static int metadata_from_nlattrs(struct net *net, struct sw_flow_match *match,
        return 0;
 }
 
 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)
@@ -845,7 +872,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 +1091,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,
+                                  u64 *key_attrs, bool *ie_valid,
+                                  const struct nlattr **a, bool is_mask,
+                                  bool log)
+{
+       int err;
+       const struct nlattr *encap;
+

...

Quoted 9 lines
net/openvswitch/flow_netlink.c +9 -0
+               u64 mask_v_attrs = 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.");

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

Quoted 10 lines
net/openvswitch/flow_netlink.c +10 -0
+                               err = -EINVAL;
+                               return err;
+                       }
+                       encap = a[OVS_KEY_ATTR_ENCAP];
+
+                       err = cust_vlan_from_nlattrs(match, a, is_mask, log);
+                       if (err)
+                               return err;
+                       *nla = encap;
+

There is no checking for ATTR_VLAN or ATTR_ETHERTYPE. This can result in null pointer deference in cust_vlan_from_nlattrs().

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

...

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

Quoted 10 lines
        if (swkey->eth.type == htons(ETH_P_802_2)) {
                /*
net/openvswitch/flow_netlink.c +2 -0
@@ -1525,6 +1659,8 @@ static int __ovs_nla_put_key(const struct sw_flow_key *swkey,
 unencap:
        if (encap)
                nla_nest_end(skb, encap);
+       if (in_encap)
+               nla_nest_end(skb, in_encap);
 

As pointed in last review, inner encap attribute should be terminated first.

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

#6 lore raw

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

Pravin,

Thanks for the review.

Quoted 81 lines · Pravin Shelar
Quoted 14 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         |  92 +++++++++++++++++++----
  net/openvswitch/flow.h         |  11 ++-
  net/openvswitch/flow_netlink.c | 166 +++++++++++++++++++++++++++++++++++++----
  net/openvswitch/vport-netdev.c |   4 +-
  5 files changed, 245 insertions(+), 34 deletions(-)

...

Quoted 63 lines
net/openvswitch/flow.c +43 -6
index c8db44a..0f9479c 100644
@@ -305,21 +305,83 @@ static bool icmp6hdr_ok(struct sk_buff *skb)
  static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key)
  {
         struct qtag_prefix {
-               __be16 eth_type; /* ETH_P_8021Q */
+               __be16 eth_type; /* ETH_P_8021Q  or ETH_P_8021AD */
                 __be16 tci;
         };
-       struct qtag_prefix *qp;
+       struct qtag_prefix *qp = (struct qtag_prefix *)skb->data;
 
-       if (unlikely(skb->len < sizeof(struct qtag_prefix) + sizeof(__be16)))
+       if (likely(skb_vlan_tag_present(skb))) {
+               key->eth.vlan.tci = htons(skb->vlan_tci);
+               key->eth.vlan.tpid = skb->vlan_proto;
+
+               /* Case where upstream
+                * processing has already stripped the outer vlan tag.
+                */
+               if (unlikely(skb->vlan_proto == htons(ETH_P_8021AD))) {
+                       if (unlikely(skb->len < sizeof(struct qtag_prefix) +
+                                       sizeof(__be16))) {
+                               key->eth.vlan.tci = 0;
+                               return 0;
+                       }
+
+                       if (unlikely(!pskb_may_pull(skb,
+                                                   sizeof(struct qtag_prefix) +
+                                                   sizeof(__be16))))
+                               return -ENOMEM;
+
+                       qp = (struct qtag_prefix *)skb->data;
+                       key->eth.cvlan.tci =
+                               qp->tci | htons(VLAN_TAG_PRESENT);
+                       key->eth.cvlan.tpid = qp->eth_type;
+
+                       __skb_pull(skb, sizeof(struct qtag_prefix));
+               }
                 return 0;
 
-       if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
-                                        sizeof(__be16))))
-               return -ENOMEM;
+       } else if (qp->eth_type == htons(ETH_P_8021AD)) {
+
+               if (unlikely(skb->len < sizeof(struct qtag_prefix) +
+                                       sizeof(__be16)))
+                       return 0;
+
+               if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
+                               sizeof(__be16))))
+                       return -ENOMEM;
+
+               qp = (struct qtag_prefix *)skb->data;
+               key->eth.vlan.tci = qp->tci | htons(VLAN_TAG_PRESENT);
+               key->eth.vlan.tpid = qp->eth_type;
+
+               __skb_pull(skb, sizeof(struct qtag_prefix));
 
Quoted 12 lines

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

Quoted 11 lines
net/openvswitch/flow.c +8 -3
-       qp = (struct qtag_prefix *) skb->data;
-       key->eth.tci = qp->tci | htons(VLAN_TAG_PRESENT);
-       __skb_pull(skb, sizeof(struct qtag_prefix));
+               if (unlikely(skb->len < sizeof(struct qtag_prefix) +
+                                       sizeof(__be16)))
+                       return 0;
+
+               if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
+                               sizeof(__be16))))
+                       return -ENOMEM;
+

There is no check for inner protocol in the packet.

Yes, and the code should be generic to use eth_type_vlan() for both inner and outer TPIDs. I think your pseudo code below fixes that.

Quoted 50 lines
Quoted 14 lines
net/openvswitch/flow.c +13 -0
+               key->eth.cvlan.tci = qp->tci | htons(VLAN_TAG_PRESENT);
+               key->eth.cvlan.tpid = qp->eth_type;
+
+               __skb_pull(skb, sizeof(struct qtag_prefix));
+
+               return 0;
+
+       } else if (qp->eth_type == htons(ETH_P_8021Q)) {
+               if (unlikely(skb->len < sizeof(struct qtag_prefix) +
+                                       sizeof(__be16)))
+                       return 0;
+
+               if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +

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

Quoted 10 lines
net/openvswitch/flow.c +7 -0
+                               sizeof(__be16))))
+                       return -ENOMEM;
+               key->eth.vlan.tci = qp->tci | htons(VLAN_TAG_PRESENT);
+               key->eth.vlan.tpid = qp->eth_type;
+
+               __skb_pull(skb, sizeof(struct qtag_prefix));
+       }
 
         return 0;
  }

I see lot of duplicate code here. How about code below:

struct qtag_prefix {
         __be16 eth_type; /* ETH_P_8021Q  or ETH_P_8021AD */
         __be16 tci;
};

/* Return < 0 on memory error
* Return == 0 on non vlan or incomplete packet packet
* Return > 0 on successfully parsing vlan tag.
*/
static int parse_vlan_tag(__be16 vlan_proto, struct sk_buff *skb,
struct vlan_tag *cvlan)

{
         if (likely(!eth_type_vlan(skb->vlan_proto)))
                 return 0;

         if (unlikely(skb->len < sizeof(struct qtag_prefix) + sizeof(__be16))) {
                 vlan->tci = 0;
                 return 0;
         }

         if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
sizeof(__be16))))
                         return -ENOMEM;
Quoted 7 lines
         qp = (struct qtag_prefix *)skb->data;
         key->eth.cvlan.tci = qp->tci | htons(VLAN_TAG_PRESENT);
         key->eth.cvlan.tpid = qp->eth_type;

         __skb_pull(skb, sizeof(struct qtag_prefix));
         return 1;
}

This makes for cleaner code and certainly better for maintainability so I have just implemented it for this next revision. However, note that with this change, we incur the overhead of an additional function call for single tagged vlan packets.

Quoted 105 lines

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 upstream
                  * processing has already stripped the outer vlan tag.
                  */
                 res = parse_vlan_tag(skb->vlan_proto, skb, &key->eth.cvlan);
                 if (res < 0)
                         return res;
                 /* Since this was inner tag, return zero in either
success or failure
                  * in parsing inner tag.
                  */
                 return 0;
         }
         res = parse_vlan_tag(qp->eth_type, skb, &key->eth.vlan);
         if (res <= 0)
                 return res;

         res = parse_vlan_tag(key->eth.vlan.tpid, skb, &key->eth.vlan);
         if (res <= 0)
                 return res;

         return 0;
}
Quoted 9 lines
net/openvswitch/flow.h +0 -1
index fe527d2..539494e 100644
@@ -68,7 +68,16 @@ 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. */

net/openvswitch/flow.h struct sw_flow_key { · line 80

Quoted 10 lines
net/openvswitch/flow.h +10 -0
+               struct {
+                       __be16 tpid;    /* Outer Vlan type 802.1q or 802.1ad.*/
+                       __be16 tci;     /* 0 if no VLAN, VLAN_TAG_PRESENT */
+                                       /* set otherwise. */
+               } vlan;
+               struct {
+                       __be16 tpid;    /* Inner Vlan DL_type 802.1q.*/
+                       __be16 tci;     /* 0 if no CVLAN, VLAN_TAG_PRESENT */
+                                       /* set otherwise. */
+               } cvlan;

We need to define structure for vlan tag key here for the pseudo code to work.

Quoted 36 lines
net/openvswitch/flow.h +0 -0
                 __be16 type;            /* Ethernet frame type. */
         } eth;
         union {
net/openvswitch/flow_netlink.c +10 -1
index c92d6a2..af06683 100644
@@ -811,6 +811,33 @@ static int metadata_from_nlattrs(struct net *net, struct sw_flow_match *match,
         return 0;
  }
 
  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)
@@ -845,7 +872,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 +1091,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,
+                                  u64 *key_attrs, bool *ie_valid,
+                                  const struct nlattr **a, bool is_mask,
+                                  bool log)
+{
+       int err;
+       const struct nlattr *encap;
+

...

Quoted 13 lines
net/openvswitch/flow_netlink.c +13 -0
+               u64 mask_v_attrs = 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];
Quoted 8 lines

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

Quoted 6 lines
net/openvswitch/flow_netlink.c +6 -0
+
+                       err = cust_vlan_from_nlattrs(match, a, is_mask, log);
+                       if (err)
+                               return err;
+                       *nla = encap;
+

There is no checking for ATTR_VLAN or ATTR_ETHERTYPE. This can result in null pointer deference in cust_vlan_from_nlattrs().

The original vlan code does not check for these attribs in the masked case. It does check for them in the non-masked case and then sets a boolean and checks it in the masked case. I do the same thing for the inner vlan. I check for the attributes in the non-masked case and set a boolean and check the boolean in the masked case. Why is this not sufficient?

Quoted 16 lines
Quoted 14 lines
net/openvswitch/flow_netlink.c +13 -0
+                       mask_v_attrs &= ~(1 << OVS_KEY_ATTR_ENCAP);
+                       mask_v_attrs &= ~(1ULL << OVS_KEY_ATTR_VLAN);
+                       mask_v_attrs &= ~(1ULL << OVS_KEY_ATTR_ETHERTYPE);
+
+                       *key_attrs |= mask_v_attrs;
+                       err = parse_flow_mask_nlattrs(*nla, a, key_attrs, log);
+                       if (err)
+                               return err;
+               }
+       }
+       return 0;
+}
+

...

Quoted 10 lines

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

Quoted 9 lines
         if (swkey->eth.type == htons(ETH_P_802_2)) {
                 /*
net/openvswitch/flow_netlink.c +2 -0
@@ -1525,6 +1659,8 @@ static int __ovs_nla_put_key(const struct sw_flow_key *swkey,
  unencap:
         if (encap)
                 nla_nest_end(skb, encap);
+       if (in_encap)
+               nla_nest_end(skb, in_encap);
 

As pointed in last review, inner encap attribute should be terminated first.

Yes, I agree that inner should be first. Sorry I forgot to change that after the last review.

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

#7 lore raw

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

Quoted 27 lines · Thomas F Herbert

Pravin,

Thanks for the review.

Quoted 21 lines · Pravin Shelar
Quoted 16 lines · Thomas F Herbert

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

---
  net/openvswitch/actions.c      |   6 +-
  net/openvswitch/flow.c         |  92 +++++++++++++++++++----
  net/openvswitch/flow.h         |  11 ++-
  net/openvswitch/flow_netlink.c | 166
+++++++++++++++++++++++++++++++++++++----
  net/openvswitch/vport-netdev.c |   4 +-
  5 files changed, 245 insertions(+), 34 deletions(-)

...

...

Quoted 32 lines
Quoted 32 lines

I see lot of duplicate code here. How about code below:

struct qtag_prefix {
         __be16 eth_type; /* ETH_P_8021Q  or ETH_P_8021AD */
         __be16 tci;
};

/* Return < 0 on memory error
* Return == 0 on non vlan or incomplete packet packet
* Return > 0 on successfully parsing vlan tag.
*/
static int parse_vlan_tag(__be16 vlan_proto, struct sk_buff *skb,
struct vlan_tag *cvlan)

{
         if (likely(!eth_type_vlan(skb->vlan_proto)))
                 return 0;

         if (unlikely(skb->len < sizeof(struct qtag_prefix) +
sizeof(__be16))) {
                 vlan->tci = 0;
                 return 0;
         }

         if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
sizeof(__be16))))
                         return -ENOMEM;

         qp = (struct qtag_prefix *)skb->data;
         key->eth.cvlan.tci = qp->tci | htons(VLAN_TAG_PRESENT);
         key->eth.cvlan.tpid = qp->eth_type;
Quoted 9 lines
Quoted 3 lines
         __skb_pull(skb, sizeof(struct qtag_prefix));
         return 1;
}

This makes for cleaner code and certainly better for maintainability so I have just implemented it for this next revision. However, note that with this change, we incur the overhead of an additional function call for single tagged vlan packets.

If there is any performance issue we can fix the code later.

Quoted 4 lines
Quoted 4 lines

static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key)

{
         struct qtag_prefix *qp = (struct qtag_prefix *)skb->data;

...

Quoted 26 lines
Quoted 17 lines
Quoted 17 lines
net/openvswitch/flow_netlink.c +3 -0
+               u64 mask_v_attrs = 0;
+
+               err = parse_flow_mask_nlattrs(*nla, a, &mask_v_attrs,

log);

net/openvswitch/flow_netlink.c +6 -0
+               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.");

net/openvswitch/flow_netlink.c +6 -0
+                               err = -EINVAL;
+                               return err;
+                       }
+                       encap = a[OVS_KEY_ATTR_ENCAP];
+
+                       err = cust_vlan_from_nlattrs(match, a, is_mask,
Quoted 8 lines

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

Quoted 5 lines

log);

net/openvswitch/flow_netlink.c +4 -0
+                       if (err)
+                               return err;
+                       *nla = encap;
+

There is no checking for ATTR_VLAN or ATTR_ETHERTYPE. This can result in null pointer deference in cust_vlan_from_nlattrs().

Quoted 5 lines

The original vlan code does not check for these attribs in the masked case. It does check for them in the non-masked case and then sets a boolean and checks it in the masked case. I do the same thing for the inner vlan. I check for the attributes in the non-masked case and set a boolean and check the boolean in the masked case. Why is this not sufficient?

Original code is checking for attributes before referencing them. For example in function ovs_nla_get_match() before extracting eth_type, it does check a[OVS_KEY_ATTR_ETHERTYPE]. But If you spot bug in current code please send fix for net tree.
Regarding the Boolean, it is for presence of inner vlan for key attribute, mask attribute still could be missing vlan attribute. For vlan mask, we can keep check sanity check as outer vlan. It means eth_type must be specified and should be 0xffff, and tci mask is optional and by default initialized to 0xffff.

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

#9 lore raw

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

Quoted 104 lines · Pravin Shelar
Quoted 25 lines · Thomas F Herbert

Pravin,

Thanks for the review.

Quoted 19 lines · Pravin Shelar
Quoted 15 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         |  92 +++++++++++++++++++----
   net/openvswitch/flow.h         |  11 ++-
   net/openvswitch/flow_netlink.c | 166
+++++++++++++++++++++++++++++++++++++----
   net/openvswitch/vport-netdev.c |   4 +-
   5 files changed, 245 insertions(+), 34 deletions(-)

...

...

Quoted 31 lines
Quoted 31 lines

I see lot of duplicate code here. How about code below:

struct qtag_prefix {
          __be16 eth_type; /* ETH_P_8021Q  or ETH_P_8021AD */
          __be16 tci;
};

/* Return < 0 on memory error
* Return == 0 on non vlan or incomplete packet packet
* Return > 0 on successfully parsing vlan tag.
*/
static int parse_vlan_tag(__be16 vlan_proto, struct sk_buff *skb,
struct vlan_tag *cvlan)

{
          if (likely(!eth_type_vlan(skb->vlan_proto)))
                  return 0;

          if (unlikely(skb->len < sizeof(struct qtag_prefix) +
sizeof(__be16))) {
                  vlan->tci = 0;
                  return 0;
          }

          if (unlikely(!pskb_may_pull(skb, sizeof(struct qtag_prefix) +
sizeof(__be16))))
                          return -ENOMEM;

          qp = (struct qtag_prefix *)skb->data;
          key->eth.cvlan.tci = qp->tci | htons(VLAN_TAG_PRESENT);
          key->eth.cvlan.tpid = qp->eth_type;
Quoted 8 lines
Quoted 3 lines
          __skb_pull(skb, sizeof(struct qtag_prefix));
          return 1;
}

This makes for cleaner code and certainly better for maintainability so I have just implemented it for this next revision. However, note that with this change, we incur the overhead of an additional function call for single tagged vlan packets.

If there is any performance issue we can fix the code later.

Quoted 3 lines
Quoted 3 lines

static int parse_vlan(struct sk_buff *skb, struct sw_flow_key *key)

{
          struct qtag_prefix *qp = (struct qtag_prefix *)skb->data;

...

Quoted 24 lines
Quoted 16 lines
Quoted 16 lines
net/openvswitch/flow_netlink.c +3 -0
+               u64 mask_v_attrs = 0;
+
+               err = parse_flow_mask_nlattrs(*nla, a, &mask_v_attrs,

log);

net/openvswitch/flow_netlink.c +6 -0
+               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.");

net/openvswitch/flow_netlink.c +5 -0
+                               err = -EINVAL;
+                               return err;
+                       }
+                       encap = a[OVS_KEY_ATTR_ENCAP];
+
Quoted 8 lines

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

Quoted 6 lines

+ err = cust_vlan_from_nlattrs(match, a, is_mask,
log);

net/openvswitch/flow_netlink.c +4 -0
+                       if (err)
+                               return err;
+                       *nla = encap;
+

There is no checking for ATTR_VLAN or ATTR_ETHERTYPE. This can result in null pointer deference in cust_vlan_from_nlattrs().

Quoted 5 lines

The original vlan code does not check for these attribs in the masked case. It does check for them in the non-masked case and then sets a boolean and checks it in the masked case. I do the same thing for the inner vlan. I check for the attributes in the non-masked case and set a boolean and check the boolean in the masked case. Why is this not sufficient?

Quoted 9 lines

Original code is checking for attributes before referencing them. For example in function ovs_nla_get_match() before extracting eth_type, it does check a[OVS_KEY_ATTR_ETHERTYPE]. But If you spot bug in current code please send fix for net tree.
Regarding the Boolean, it is for presence of inner vlan for key attribute, mask attribute still could be missing vlan attribute. For vlan mask, we can keep check sanity check as outer vlan. It means eth_type must be specified and should be 0xffff, and tci mask is optional and by default initialized to 0xffff.

You are correct. I was thinking of something else. I had this but must have lost it one of the patch revisions. Fixed it in V16.

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

#10 lore raw

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

In reply to Thomas F Herbert
---
 include/linux/if_vlan.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
include/linux/if_vlan.h +17 -0
index 67ce5bd..88d1be4 100644
@@ -627,6 +627,23 @@ 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)):
+		return true;
+	case (htons(ETH_P_8021AD)):
+		return true;
+	default:
+		return false;
+	}
+}
 
 /**
  * compare_vlan_header - Compare two vlan headers
Signature · 1 line
2.4.3
#11 lore raw

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

Hello.

Quoted 16 lines · Thomas F Herbert
---
  include/linux/if_vlan.h | 17 +++++++++++++++++
  1 file changed, 17 insertions(+)
include/linux/if_vlan.h +3 -0
index 67ce5bd..88d1be4 100644
@@ -627,6 +627,23 @@ 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

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

Quoted 10 lines
include/linux/if_vlan.h +10 -0
+ *
+ * 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)):
+		return true;
+	case (htons(ETH_P_8021AD)):
+		return true;

I'm not sure if I've already suggested that or not but why not merge these
2 cases?

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

Quoted 4 lines
include/linux/if_vlan.h +4 -0
+	default:
+		return false;
+	}
+}

[...]

MBR, Sergei

maintainer
#12 lore raw
In reply to Thomas F Herbert

From: Thomas F Herbert <[email protected]>
Date: Sat, 10 Oct 2015 19:40:30 -0400

Quoted 4 lines

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

I think this patch series has gone long enough, can I get some ACK's ASAP for this V15 posting?

Thanks.

#13 lore raw
Quoted 11 lines · David Miller

From: Thomas F Herbert <[email protected]>
Date: Sat, 10 Oct 2015 19:40:30 -0400

Quoted 4 lines

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

I think this patch series has gone long enough, can I get some ACK's ASAP for this V15 posting?

I know this is taking bit long but this patch-set is touching one of most complex netlink attributes processing code in OVS. I think we are very close to final version. As of now I am seeing couple of bugs, one of the bug is newly introduced in this version. And there is still code duplication in flow extract. So I can not ack the patch yet. Sorry for the delay.

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

#15 lore raw
Quoted 9 lines · David Miller

From: Thomas F Herbert <[email protected]>
Date: Sat, 10 Oct 2015 19:40:30 -0400

Quoted 4 lines

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

I think this patch series has gone long enough, can I get some ACK's ASAP for this V15 posting?

Dave, For quality concerns, I think it is best if I respond to Pravin's latest comments with an updated series. I will submit shortly.

--TFH

Quoted 2 lines

Thanks.

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