/* SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-clause) */ /* SPDX-FileCopyrightText: 2021 The xdp-tutorial Authors */ /* SPDX-FileCopyrightText: 2025 Yureka Lilian */ /* Based on https://github.com/xdp-project/xdp-tutorial/blob/main/common/parsing_helpers.h */ #ifndef __PARSING_HELPERS_H #define __PARSING_HELPERS_H #include //#include #define ETH_P_8021Q 0x8100 /* 802.1Q VLAN Extended Header */ #define ETH_P_8021AD 0x88A8 /* 802.1ad Service VLAN */ static __always_inline int proto_is_vlan(__u16 h_proto) { return !!(h_proto == bpf_htons(ETH_P_8021Q) || h_proto == bpf_htons(ETH_P_8021AD)); } static __always_inline int parse_ethhdr(struct xdp_md *ctx, struct ethhdr **ethhdr) { void *data_end = (void *)(long)ctx->data_end; struct ethhdr *eth = (void *) (long) ctx->data; /* Byte-count bounds check; check if current pointer + size of header * is after data_end. */ if ((void *) (eth + 1) > data_end) return -1; *ethhdr = eth; return eth->h_proto; /* network-byte-order */ } #endif