Support QinQ offload

Signed-off-by: Allen Chen <[email protected]>
---
 NEWS                      |  4 ++++
 lib/netdev-offload-dpdk.c | 31 +++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/NEWS b/NEWS
index 6e3f56d73..22218e966 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,7 @@
+v3.4.0 - 11 Dec 2024
+---------------------
+    - Add support for QinQ offload
+
 Post-v3.4.0
 --------------------
    - The limit on the number of fields for address prefix tracking in flow
diff --git a/lib/netdev-offload-dpdk.c b/lib/netdev-offload-dpdk.c
index 1a6e100ff..7a519cd68 100644
--- a/lib/netdev-offload-dpdk.c
+++ b/lib/netdev-offload-dpdk.c
@@ -1379,6 +1379,7 @@ parse_flow_match(struct netdev *netdev,
                  struct match *match)
 {
     struct rte_flow_item_eth *eth_spec = NULL, *eth_mask = NULL;
+    struct rte_flow_item_vlan *vlan_spec = NULL, *vlan_mask = NULL;
     struct flow *consumed_masks;
     uint8_t proto = 0;
 
@@ -1451,6 +1452,9 @@ parse_flow_match(struct netdev *netdev,
             eth_mask->type = match->wc.masks.vlans[0].tpid;
         }
 
+        vlan_spec = spec;
+        vlan_mask = mask;
+
         add_flow_pattern(patterns, RTE_FLOW_ITEM_TYPE_VLAN, spec, mask, NULL);
     }
     /* For untagged matching match->wc.masks.vlans[0].tci is 0xFFFF and
@@ -1459,6 +1463,33 @@ parse_flow_match(struct netdev *netdev,
      */
     memset(&consumed_masks->vlans[0], 0, sizeof consumed_masks->vlans[0]);
 
+    /* VLAN */
+    if (match->wc.masks.vlans[1].tci && match->flow.vlans[1].tci) {
+        struct rte_flow_item_vlan *spec, *mask;
+
+        spec = xzalloc(sizeof *spec);
+        mask = xzalloc(sizeof *mask);
+
+        spec->tci = match->flow.vlans[1].tci & ~htons(VLAN_CFI);
+        mask->tci = match->wc.masks.vlans[1].tci & ~htons(VLAN_CFI);
+
+        if (vlan_spec && vlan_mask) {
+            vlan_spec->has_more_vlan = 1;
+            vlan_mask->has_more_vlan = 1;
+            spec->inner_type = vlan_spec->inner_type;
+            mask->inner_type = vlan_mask->inner_type;
+            vlan_spec->inner_type = match->flow.vlans[1].tpid;
+            vlan_mask->inner_type = match->wc.masks.vlans[1].tpid;
+        }
+
+        add_flow_pattern(patterns, RTE_FLOW_ITEM_TYPE_VLAN, spec, mask, NULL);
+    }
+    /* For untagged matching match->wc.masks.vlans[0].tci is 0xFFFF and
+     * match->flow.vlans[0].tci is 0. Consuming is needed outside of the if
+     * scope to handle that.
+     */
+    memset(&consumed_masks->vlans[1], 0, sizeof consumed_masks->vlans[1]);
+
     /* IP v4 */
     if (match->flow.dl_type == htons(ETH_TYPE_IP)) {
         struct rte_flow_item_ipv4 *spec, *mask, *last = NULL;
-- 
2.33.0.windows.2

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to