From 95f00d7a735b20cf352f6712529547b3720614cb Mon Sep 17 00:00:00 2001
From: jiangheng <jiangheng14@huawei.com>
Date: Mon, 5 Feb 2024 17:35:32 +0800
Subject: add vlanid in netif

---
 src/core/netif.c         | 14 ++++++++++++++
 src/core/tcp.c           |  2 ++
 src/core/tcp_in.c        |  2 ++
 src/include/lwip/netif.h |  9 +++++++++
 src/netif/ethernet.c     |  6 ++++++
 5 files changed, 33 insertions(+)

diff --git a/src/core/netif.c b/src/core/netif.c
index 8a1ccec..eff3cae 100644
--- a/src/core/netif.c
+++ b/src/core/netif.c
@@ -369,6 +369,11 @@ netif_add(struct netif *netif,
   netif->acd_list = NULL;
 #endif /* LWIP_ACD */
   NETIF_RESET_HINTS(netif);
+
+#if GAZELLE_ENABLE
+  netif->vlan_enable=false;
+#endif
+
 #if ENABLE_LOOPBACK
   netif->loop_first = NULL;
   netif->loop_last = NULL;
@@ -455,6 +460,15 @@ netif_add(struct netif *netif,
   return netif;
 }
 
+#if GAZELLE_ENABLE
+void
+netif_set_vlan_tci(struct netif *netif, u16_t vlan_tci)
+{
+  netif->vlan_enable = true;
+  netif->vlan_tci = vlan_tci;
+}
+#endif
+
 static void
 netif_do_ip_addr_changed(const ip_addr_t *old_addr, const ip_addr_t *new_addr)
 {
diff --git a/src/core/tcp.c b/src/core/tcp.c
index 1d02574..b889a4e 100644
--- a/src/core/tcp.c
+++ b/src/core/tcp.c
@@ -996,7 +996,9 @@ tcp_listen_with_backlog_and_err(struct tcp_pcb *pcb, u8_t backlog, err_t *err)
 #endif
 
 #if LWIP_VLAN_PCP
+#if !GAZELLE_ENABLE
   lpcb->netif_hints.tci = pcb->netif_hints.tci;
+#endif
 #endif /* LWIP_VLAN_PCP */
 #if LWIP_IPV4 && LWIP_IPV6
   IP_SET_TYPE_VAL(lpcb->remote_ip, pcb->local_ip.type);
diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c
index 9b1ec9c..10f8a14 100644
--- a/src/core/tcp_in.c
+++ b/src/core/tcp_in.c
@@ -808,7 +808,9 @@ tcp_listen_input(struct tcp_pcb_listen *pcb)
     npcb->listener = pcb;
 #endif /* LWIP_CALLBACK_API || TCP_LISTEN_BACKLOG */
 #if LWIP_VLAN_PCP
+#if !GAZELLE_ENABLE
     npcb->netif_hints.tci = pcb->netif_hints.tci;
+#endif
 #endif /* LWIP_VLAN_PCP */
     /* inherit socket options */
     npcb->so_options = pcb->so_options & SOF_INHERITED;
diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h
index 502a151..368b89a 100644
--- a/src/include/lwip/netif.h
+++ b/src/include/lwip/netif.h
@@ -45,6 +45,10 @@
 
 #include "lwip/ip_addr.h"
 
+#if GAZELLE_ENABLE
+#include <stdbool.h>
+#endif
+
 #include "lwip/def.h"
 #include "lwip/pbuf.h"
 #include "lwip/stats.h"
@@ -360,6 +364,10 @@ struct netif {
 #if GAZELLE_ENABLE
   u64_t rxol_flags;
   u64_t txol_flags;
+  bool vlan_enable;
+  /** vlan id is an attribute of NIC. The variable 'netif_hints' is not used because it is assigned by pcb,
+   *  while non transport layers without pcb cannot be enabled */
+  u16_t vlan_tci;
 #endif
   /** descriptive abbreviation */
   char name[2];
@@ -492,6 +500,7 @@ void netif_set_down(struct netif *netif);
 #define netif_get_rxol_flags(netif)  ((netif)->rxol_flags)
 #define netif_get_txol_flags(netif)  ((netif)->txol_flags)
 
+void netif_set_vlan_tci(struct netif *netif, u16_t vlan_tci);
 void netif_set_rtc_mode(struct netif *netif);
 void netif_set_rxol_flags(struct netif *netif, u64_t flags);
 void netif_set_txol_flags(struct netif *netif, u64_t flags);
diff --git a/src/netif/ethernet.c b/src/netif/ethernet.c
index dc89566..af4cffc 100644
--- a/src/netif/ethernet.c
+++ b/src/netif/ethernet.c
@@ -283,9 +283,15 @@ ethernet_output(struct netif * netif, struct pbuf * p,
   vlan_prio_vid = LWIP_HOOK_VLAN_SET(netif, p, src, dst, eth_type);
 #elif LWIP_VLAN_PCP
   vlan_prio_vid = -1;
+#if !GAZELLE_ENABLE
   if (netif->hints && (netif->hints->tci >= 0)) {
     vlan_prio_vid = (u16_t)netif->hints->tci;
   }
+#else
+  if (netif->vlan_enable) {
+    vlan_prio_vid = netif->vlan_tci;
+  }
+#endif /* GAZELLE_ENABLE */
 #endif
   if (vlan_prio_vid >= 0) {
     struct eth_vlan_hdr *vlanhdr;
-- 
2.33.0
