# 3.2.dpdk nic offload:2

* vlan strip offloading

make sure the nic supports `DEV_RX_OFFLOAD_VLAN_STRIP` feature by checking device information .

there are two ways to configure vlan striping in DPDK,one is to set the `.hw_vlan_strip` bit of rte\_eth\_conf during device configuration phase,another way is to configure at runtime,`rte_eth_dev_set_vlan_offload(port_id,rte_eth_dev_get_vlan_offload()|ETH_VLAN_STRIP_OFFLOAD)` .

upon receiving a packet,we see if it's a vlan packet ,'PKT\_RX\_VLAN\_PKT' will be set,and then we could also find `PKT_RX_VLAN_STRIPPED` bit is set ,and `rte-mbuf.vlan_tci` is the tci of real vlan header .

-vlan filter offloading

vlan filtering offloading allows nic to filter VLAN packets basing on the vlan white list,still ,we need to configure by doing so:`rte_eth_dev_set_vlan_offload(port_id,rte_eth_dev_get_vlan_offload()|ETH_VLAN_FILTER_OFFLOAD)` ,and then we could call `rte_eth_dev_vlan_filter()` to add a vlan to white list. there is no feature bit indicating the packet is allowed after vlan filtering in rte\_mbuf.

-vlan insertion offloading

if NIC supports `DEV_TX_OFFLOAD_VLAN_INSERT` ,then we could use the following code to make NIC insert a vlan header during transmission:

```c
mbufs[idx]->vlan_tci=0xef00;
mbufs[idx]->ol_flags|=PKT_TX_VLAN_PKT;
```

-tx checksum offloading

first check TX checksum features the NIC supports . for example ,the NIC supports IP checksum tx offloading ,then before transmission ,we set setup offloading flags as follows:

```c
buffer=rte_pktmbuf_mtod(mbufs[idx],char*);
ip4=(struct ipv4_hdr*)(buffer+14);
ip4->hdr_checksum=0;
mbufs[idx]->l2_len=14;
mbufs[idx]->l3_len=20;
mbufs[idx]->ol_flags=PKT_TX_IP_CKSUM|PKT_TX_IPV4;
```

different checksum types require different pre-setups , please refer to `rte_mbuf.h`.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://linkthedevil.gitbook.io/little-things-about-dataplane/3.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
