net/cxgbe: fix parsing VLAN ID rewrite action
authorRahul Lakkireddy <rahul.lakkireddy@chelsio.com>
Fri, 27 Sep 2019 20:30:04 +0000 (02:00 +0530)
committerFerruh Yigit <ferruh.yigit@intel.com>
Mon, 7 Oct 2019 13:00:57 +0000 (15:00 +0200)
Set VLAN action mode to VLAN_REWRITE only if VLAN_INSERT has not been
set yet. Otherwise, the resulting VLAN packets will have their VLAN
header rewritten, instead of pushing a new outer VLAN header.

Also fix the VLAN ID extraction logic and endianness issues.

Fixes: 1decc62b1cbe ("net/cxgbe: add flow operations to offload VLAN actions")
Cc: stable@dpdk.org
Signed-off-by: Rahul Lakkireddy <rahul.lakkireddy@chelsio.com>
drivers/net/cxgbe/cxgbe_flow.c

index 8a5d06f..4c85530 100644 (file)
@@ -446,18 +446,27 @@ ch_rte_parse_atype_switch(const struct rte_flow_action *a,
        const struct rte_flow_action_set_tp *tp_port;
        const struct rte_flow_action_phy_port *port;
        int item_index;
+       u16 tmp_vlan;
 
        switch (a->type) {
        case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
                vlanid = (const struct rte_flow_action_of_set_vlan_vid *)
                          a->conf;
-               fs->newvlan = VLAN_REWRITE;
-               fs->vlan = vlanid->vlan_vid;
+               /* If explicitly asked to push a new VLAN header,
+                * then don't set rewrite mode. Otherwise, the
+                * incoming VLAN packets will get their VLAN fields
+                * rewritten, instead of adding an additional outer
+                * VLAN header.
+                */
+               if (fs->newvlan != VLAN_INSERT)
+                       fs->newvlan = VLAN_REWRITE;
+               tmp_vlan = fs->vlan & 0xe000;
+               fs->vlan = (be16_to_cpu(vlanid->vlan_vid) & 0xfff) | tmp_vlan;
                break;
        case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
                pushvlan = (const struct rte_flow_action_of_push_vlan *)
                            a->conf;
-               if (pushvlan->ethertype != RTE_ETHER_TYPE_VLAN)
+               if (be16_to_cpu(pushvlan->ethertype) != RTE_ETHER_TYPE_VLAN)
                        return rte_flow_error_set(e, EINVAL,
                                                  RTE_FLOW_ERROR_TYPE_ACTION, a,
                                                  "only ethertype 0x8100 "