bpf_xdp_meta..._rx_vlan_tag(9)
π bpf_xdp_meta..._rx_vlan_tag(9) β like, the Kernel API Manual entry, bestie
okay so this is a page from the Kernel API Manual, and it's all about bpf_xdp_metadata_rx_vlan_tag β yes the title is long, no we're not shortening it, it's iconic that way π
β¨ NAME β¨
bpf_xdp_metadata_rx_vlan_tag β grab the outermost VLAN tag off an XDP packet, no cap π¦
πΈ SYNOPSIS πΈ
__bpf_kfunc int bpf_xdp_metadata_rx_vlan_tag (const struct xdp_md *ctx ,
__be16 *vlan_proto , u16 *vlan_tci );
π ARGUMENTS π
ctxβ the XDP context pointer. your main character pointer, honestly.vlan_protoβ destination pointer for the VLAN Tag protocol identifier (TPID).vlan_tciβ destination pointer for the VLAN TCI (VID + DEI + PCP). three besties in one field fr fr.
π DESCRIPTION π
In case of success, vlan_proto contains the Tag protocol identifier (TPID) β usually ETH_P_8021Q or ETH_P_8021AD, but some networks can use custom TPIDs, so don't assume π. vlan_proto is stored in network byte order (BE) and should be used like this:
if (vlan_proto == bpf_htons(ETH_P_8021Q)) do_something;
vlan_tci contains the remaining 16 bits of a VLAN tag. The driver is expected to provide those in host byte order (usually LE), so the bpf program should not perform byte conversion β literally don't, it's already been done for you π
.
Per the 802.1Q standard, VLAN TCI (Tag control information) is a bit field containing:
- VLAN identifier (VID) β readable with
vlan_tci & 0xfff - Drop eligible indicator (DEI) β 1 bit
- Priority code point (PCP) β 3 bits
For the detailed meaning of DEI and PCP, please refer to other sources β that's not this page's job, and honestly, respect the boundaries π§
π₯ RETURN π₯
- Returns
0on success or-errnoon error. -EOPNOTSUPPβ the device driver doesn't implement kfunc. it's giving "not my department" π-ENODATAβ the VLAN tag was not stripped or is not available. the vibe check came back empty π
π SEE ALSO π
Kernel file ./net/core/xdp.c, plus these absolute legends:
xdp_reg_page_pool(9)xdp_unreg_page_pool(9)xdp_rxq_info_attach_page_pool(9)xdp_return_frag(9)xdp_build_skb_from_buff(9)xdp_copy_frags_from_zc(9)xdp_build_skb_from_zc(9)bpf_xdp_metadata_rx_timestamp(9)bpf_xdp_metadata_rx_hash(9)
β friendly reminder from your girl: byte order is not a suggestion, it's a whole lifestyle. check BE vs host order before you ship, bestie π«Ά
and that's the page!! π it lives in ./net/core, it's dated October 2026, and yeah the footer name is still the same gloriously long bpf_xdp_meta..._rx_vlan_tag(9) β we love a consistent brand πβ¨π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms