<div class="__aliyun_email_body_block"><div  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun"><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;">Hi <span  style="color: rgb(0, 0, 0); font-family: Tahoma, Arial, STHeiti, SimSun; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; word-spacing: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; float: none; display: inline !important;">Stephen,</span></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span ><br ></span></span></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span ><span >Thank you for your review.<br ></span></span></span></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span ><span ><br ></span></span></span></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span ><span ><span >I'd like to explain why we need to implement a custom VLAN insertion function.</span></span></span></span></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span >As shown in the code below, we first call `rte_vlan_insert` to insert the VLAN header.<br ></span></span><div  style="clear: both;">Only if this fails will we call our own implementation, `nbl_res_txrx_vlan_insert_out_mbuf`, to insert the VLAN header.<br ></div><div  style="clear: both;">This mainly corresponds to the scenario where `mbuf->refcnt > 1`.<br ></div><div  style="clear: both;">In this case, the content of `mbuf` cannot be modified, so `rte_vlan_insert` will fail.<br ></div><div  style="clear: both;">Our own implementation, `nbl_res_txrx_vlan_insert_out_mbuf`, puts the Ethernet header and VLAN header in a Tx desc,<br ></div><div  style="clear: both;">and then puts the remaining header and data in the next Tx desc.<br ></div><div  style="clear: both;">This achieves VLAN header insertion without modifying the `mbuf` content.<br ></div><div  style="clear: both;"><br ></div><div  style="clear: both;"><br ></div><div  style="clear: both;"><span  style="font-style: italic;">if (tx_pkt->ol_flags & RTE_MBUF_F_TX_VLAN) {<br ></span></div><div  style="clear: both;"><span  style="font-style: italic;">    if (likely(can_push)) {<br ></span></div><div  style="clear: both;"><span  style="font-style: italic;">        if (<span  style="font-style: italic; font-weight: 700;">rte_vlan_insert</span>(&tx_pkt)) {<br ></span></div><div  style="clear: both;"><span  style="font-style: italic;">            can_push = 0;<br ></span></div><div  style="clear: both;"><span  style="font-style: italic;">            u = (union nbl_tx_extend_head *)(&tx_region[desc_index]);<br ></span></div><div  style="clear: both;"><span  style="font-style: italic;">        }<br ></span></div><div  style="clear: both;"><span  style="font-style: italic;">    }<br ></span></div><div  style="clear: both;"><span  style="font-style: italic;">    if (unlikely(!can_push)) {<br ></span></div><div  style="clear: both;"><span  style="font-style: italic;">        addr_offset += sizeof(struct rte_ether_hdr);<br ></span></div><div  style="clear: both;"><span  style="font-style: italic;">        <span  style="font-style: italic; font-weight: 700;">nbl_res_txrx_vlan_insert_out_mbuf</span>(tx_pkt, u, RTE_ETHER_TYPE_VLAN,<br ></span></div><div  style="clear: both;"><span  style="font-style: italic;">                                          tx_pkt->vlan_tci);<br ></span></div><div  style="clear: both;"><span  style="font-style: italic;">    }<br ></span></div><div ><span  style="font-style: italic;">}</span></div><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><div  style="clear: both; font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><span  style="font-family: Tahoma, Arial, STHeitiSC-Light, SimSun;"><br ></span></div><blockquote  _quote="1" style="margin-right: 0px; margin-top: 0px; margin-bottom: 0px; font-family: Tahoma, Arial, STHeiti, SimSun; font-size: 14px; color: rgb(0, 0, 0);"><div  class="alimail-quote"><div  style="clear: both;">------------------------------------------------------------------</div><div  style="clear: both;">发件人:Stephen Hemminger <stephen@networkplumber.org></div><div  style="clear: both;">发送时间:2025年11月8日(周六) 00:10</div><div  style="clear: both;">收件人:Dimon<dimon.zhao@nebula-matrix.com></div><div  style="clear: both;">抄 送:dev<dev@dpdk.org>; Alvin<alvin.wang@nebula-matrix.com>; Leon<leon.yu@nebula-matrix.com>; Sam<sam.chen@nebula-matrix.com></div><div  style="clear: both;">主 题:Re: [PATCH v1 2/4] net/nbl: add support for Tx and Rx VLAN offload</div><div  style="clear: both;"><br ></div>On Thu,  6 Nov 2025 23:34:57 -0800<br >Dimon Zhao <dimon.zhao@nebula-matrix.com> wrote:<br ><br >> +static inline void nbl_res_txrx_vlan_insert_out_mbuf(struct rte_mbuf *tx_pkt,<br >> +           union nbl_tx_extend_head *u,<br >> +           u16 vlan_proto, u16 vlan_tci)<br >> +{<br >> + struct rte_vlan_hdr *vlan_hdr;<br >> + struct rte_ether_hdr *ether_hdr;<br >> +<br >> + ether_hdr = (struct rte_ether_hdr *)((u8 *)u + sizeof(struct nbl_tx_ehdr_leonis));<br >> + rte_memcpy(ether_hdr, rte_pktmbuf_mtod(tx_pkt, u8 *), sizeof(struct rte_ether_hdr));<br >> +<br >> + vlan_hdr = (struct rte_vlan_hdr *)(ether_hdr + 1);<br >> + vlan_hdr->vlan_tci = rte_cpu_to_be_16(vlan_tci);<br >> + vlan_hdr->eth_proto = ether_hdr->ether_type;<br >> +<br >> + ether_hdr->ether_type = rte_cpu_to_be_16(vlan_proto);<br >> +}<br >> +<br ><br >Please do not use rte_memcpy for small fixed size structures.<br >Prefer:<br > rte_ether_addr_copy<br > struct assignment<br > memcpy<br ><br >There already is a standard function for vlan insert, could this be used here?</div></blockquote><div  style="line-height: 20px; clear: both;"><br ></div></div></div>
<div style="clear: both;"><span style="font-size: 10px; color: rgb(216, 216, 216);">本邮件所含信息及其任何附件为保密信息且可能属于专有信息。任何非指定接收人均无权访问本邮件。如果您不是该邮件的指定接收人,那么任何对本邮件内容进行披露,复制或使用的行为均是禁止的。如果您不是该邮件的指定接收人,请您立即通过邮件通知 compliance@nebula-matrix.com并立即删除您错误接受的邮件。</span></div><div style="clear: both;"><span style="font-size: 10px; color: rgb(216, 216, 216);">The information in this message and any attachments is confidential and may be privileged.  Access to this email by anyone other than the intended recipient is not authorized.  If you are not the intended recipient, disclosure, copying or use of the contents of this email is prohibited.  If you are not the intended recipient, please notify  compliance@nebula-matrix.com immediately by email, and please destroy the email you received in error.</span></div>