From 3d8a848dde959ef95796e8215cdb1882a3496ce4 Mon Sep 17 00:00:00 2001
From: zhengjiebing <zhengjiebing_yewu@cmss.chinamobile.com>
Date: Thu, 21 Mar 2024 11:24:26 +0800
Subject: [PATCH] dpdk add vlan filter

---
 src/common/dpdk_common.c      |  6 ++++++
 src/lstack/core/lstack_dpdk.c | 19 +++++++++++++------
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/src/common/dpdk_common.c b/src/common/dpdk_common.c
index c0c4f63..c03b2ec 100644
--- a/src/common/dpdk_common.c
+++ b/src/common/dpdk_common.c
@@ -223,6 +223,12 @@ void eth_params_checksum(struct rte_eth_conf *conf, struct rte_eth_dev_info *dev
         COMMON_INFO("RTE_ETH_RX_OFFLOAD_VLAN_STRIP\n");
     }
 
+    // rx vlan filter
+    if (rx_ol_capa & RTE_ETH_RX_OFFLOAD_VLAN_FILTER) {
+        rx_ol |= RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
+        COMMON_INFO("RTE_ETH_RX_OFFLOAD_VLAN_STRIP\n");
+    }
+
     // tx ip
     if (tx_ol_capa & RTE_ETH_TX_OFFLOAD_IPV4_CKSUM) {
         tx_ol |= RTE_ETH_TX_OFFLOAD_IPV4_CKSUM;
diff --git a/src/lstack/core/lstack_dpdk.c b/src/lstack/core/lstack_dpdk.c
index a774d45..42981f4 100644
--- a/src/lstack/core/lstack_dpdk.c
+++ b/src/lstack/core/lstack_dpdk.c
@@ -572,13 +572,13 @@ int32_t dpdk_ethdev_init(int port_id, bool bond_port)
         int slave_id = rte_eth_bond_primary_get(port_id);
         if (slave_id < 0) {
             LSTACK_LOG(ERR, LSTACK, "dpdk get bond primary port failed port = %d\n", slave_id);
-	    free(eth_params);
+            free(eth_params);
             return slave_id;
         }
         ret = rte_eth_dev_info_get(slave_id, &slave_dev_info);
         if (ret != 0) {
             LSTACK_LOG(ERR, LSTACK, "dpdk get bond dev info failed ret = %d\n", ret);
-	    free(eth_params);
+            free(eth_params);
             return ret;
         }
         dev_info.rx_offload_capa = slave_dev_info.rx_offload_capa;
@@ -623,6 +623,13 @@ int32_t dpdk_ethdev_init(int port_id, bool bond_port)
         }
     }
 
+    /* after rte_eth_dev_configure */
+    ret = rte_eth_dev_vlan_filter(port_id, get_global_cfg_params()->nic.vlan_mode, 1);
+    if (ret != 0) {
+        LSTACK_LOG(ERR, LSTACK, "dpdk add vlan filter failed ret = %d\n", ret);
+        return -1;
+    }
+
     rte_eth_allmulticast_enable(port_id);
 
     return 0;
@@ -733,7 +740,7 @@ int32_t init_dpdk_ethdev(void)
         }
 
         ret = dpdk_ethdev_init(bond_port_id, 1);
-	if (ret != 0) {
+        if (ret != 0) {
             LSTACK_LOG(ERR, LSTACK, "dpdk_ethdev_init failed ret = %d\n", ret);
             return -1;
         }
@@ -765,18 +772,18 @@ int32_t init_dpdk_ethdev(void)
 
         ret = rte_eth_promiscuous_enable(bond_port_id);
         if (ret < 0) {
-	    LSTACK_LOG(ERR, LSTACK, "dpdk enable promiscuous failed ret = %d\n", ret);
+            LSTACK_LOG(ERR, LSTACK, "dpdk enable promiscuous failed ret = %d\n", ret);
             return -1;
         }
 
         ret = rte_eth_allmulticast_enable(bond_port_id);
         if (ret < 0) {
-	    LSTACK_LOG(ERR, LSTACK, "dpdk enable allmulticast failed ret = %d\n", ret);
+            LSTACK_LOG(ERR, LSTACK, "dpdk enable allmulticast failed ret = %d\n", ret);
             return -1;
         }
 
         ret = rte_eth_dev_start(bond_port_id);
-	if (ret < 0) {
+        if (ret < 0) {
             LSTACK_LOG(ERR, LSTACK, "dpdk start bond port failed ret = %d\n", ret);
             return -1;
         }
-- 
2.33.0

