@@ -737,6 +737,39 @@ __bpf_kfunc int bpf_xdp_metadata_rx_hash(const struct xdp_md *ctx, u32 *hash,
737737 return - EOPNOTSUPP ;
738738}
739739
740+ /**
741+ * bpf_xdp_metadata_rx_vlan_tag - Get XDP packet outermost VLAN tag
742+ * @ctx: XDP context pointer.
743+ * @vlan_proto: Destination pointer for VLAN Tag protocol identifier (TPID).
744+ * @vlan_tci: Destination pointer for VLAN TCI (VID + DEI + PCP)
745+ *
746+ * In case of success, ``vlan_proto`` contains *Tag protocol identifier (TPID)*,
747+ * usually ``ETH_P_8021Q`` or ``ETH_P_8021AD``, but some networks can use
748+ * custom TPIDs. ``vlan_proto`` is stored in **network byte order (BE)**
749+ * and should be used as follows:
750+ * ``if (vlan_proto == bpf_htons(ETH_P_8021Q)) do_something();``
751+ *
752+ * ``vlan_tci`` contains the remaining 16 bits of a VLAN tag.
753+ * Driver is expected to provide those in **host byte order (usually LE)**,
754+ * so the bpf program should not perform byte conversion.
755+ * According to 802.1Q standard, *VLAN TCI (Tag control information)*
756+ * is a bit field that contains:
757+ * *VLAN identifier (VID)* that can be read with ``vlan_tci & 0xfff``,
758+ * *Drop eligible indicator (DEI)* - 1 bit,
759+ * *Priority code point (PCP)* - 3 bits.
760+ * For detailed meaning of DEI and PCP, please refer to other sources.
761+ *
762+ * Return:
763+ * * Returns 0 on success or ``-errno`` on error.
764+ * * ``-EOPNOTSUPP`` : device driver doesn't implement kfunc
765+ * * ``-ENODATA`` : VLAN tag was not stripped or is not available
766+ */
767+ __bpf_kfunc int bpf_xdp_metadata_rx_vlan_tag (const struct xdp_md * ctx ,
768+ __be16 * vlan_proto , u16 * vlan_tci )
769+ {
770+ return - EOPNOTSUPP ;
771+ }
772+
740773__bpf_kfunc_end_defs ();
741774
742775BTF_SET8_START (xdp_metadata_kfunc_ids )
0 commit comments