/* SPDX-License-Identifier: GPL-2.0 */ /* Minimal BPF type stubs for RVF eBPF programs. * * This header provides the essential kernel type definitions so that * BPF C programs can compile without requiring the full kernel headers. * In production, replace this with the vmlinux.h generated by: * bpftool btf dump file /sys/kernel/btf/vmlinux format c */ #ifndef __VMLINUX_H__ #define __VMLINUX_H__ /* ── Scalar typedefs ─────────────────────────────────────────────── */ typedef unsigned char __u8; typedef unsigned short __u16; typedef unsigned int __u32; typedef unsigned long long __u64; typedef signed char __s8; typedef signed short __s16; typedef signed int __s32; typedef signed long long __s64; typedef __u16 __be16; typedef __u32 __be32; typedef __u64 __be64; typedef __u16 __sum16; /* ── Ethernet ────────────────────────────────────────────────────── */ #define ETH_ALEN 6 #define ETH_P_IP 0x0800 #define ETH_P_IPV6 0x86DD struct ethhdr { unsigned char h_dest[ETH_ALEN]; unsigned char h_source[ETH_ALEN]; __be16 h_proto; } __attribute__((packed)); /* ── IPv4 ────────────────────────────────────────────────────────── */ #define IPPROTO_TCP 6 #define IPPROTO_UDP 17 struct iphdr { #if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ __u8 ihl:4, version:4; #else __u8 version:4, ihl:4; #endif __u8 tos; __be16 tot_len; __be16 id; __be16 frag_off; __u8 ttl; __u8 protocol; __sum16 check; __be32 saddr; __be32 daddr; } __attribute__((packed)); /* ── UDP ─────────────────────────────────────────────────────────── */ struct udphdr { __be16 source; __be16 dest; __be16 len; __sum16 check; } __attribute__((packed)); /* ── TCP ─────────────────────────────────────────────────────────── */ struct tcphdr { __be16 source; __be16 dest; __be32 seq; __be32 ack_seq; #if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ __u16 res1:4, doff:4, fin:1, syn:1, rst:1, psh:1, ack:1, urg:1, ece:1, cwr:1; #else __u16 doff:4, res1:4, cwr:1, ece:1, urg:1, ack:1, psh:1, rst:1, syn:1, fin:1; #endif __be16 window; __sum16 check; __be16 urg_ptr; } __attribute__((packed)); /* ── XDP context ─────────────────────────────────────────────────── */ struct xdp_md { __u32 data; __u32 data_end; __u32 data_meta; __u32 ingress_ifindex; __u32 rx_queue_index; __u32 egress_ifindex; }; /* XDP return codes */ #define XDP_ABORTED 0 #define XDP_DROP 1 #define XDP_PASS 2 #define XDP_TX 3 #define XDP_REDIRECT 4 /* ── TC (Traffic Control) context ────────────────────────────────── */ struct __sk_buff { __u32 len; __u32 pkt_type; __u32 mark; __u32 queue_mapping; __u32 protocol; __u32 vlan_present; __u32 vlan_tci; __u32 vlan_proto; __u32 priority; __u32 ingress_ifindex; __u32 ifindex; __u32 tc_index; __u32 cb[5]; __u32 hash; __u32 tc_classid; __u32 data; __u32 data_end; __u32 napi_id; __u32 family; __u32 remote_ip4; __u32 local_ip4; __u32 remote_ip6[4]; __u32 local_ip6[4]; __u32 remote_port; __u32 local_port; __u32 data_meta; }; /* TC action return codes */ #define TC_ACT_UNSPEC (-1) #define TC_ACT_OK 0 #define TC_ACT_RECLASSIFY 1 #define TC_ACT_SHOT 2 #define TC_ACT_PIPE 3 #define TC_ACT_STOLEN 4 #define TC_ACT_QUEUED 5 #define TC_ACT_REPEAT 6 #define TC_ACT_REDIRECT 7 /* ── BPF map type constants ──────────────────────────────────────── */ #define BPF_MAP_TYPE_HASH 1 #define BPF_MAP_TYPE_ARRAY 2 #define BPF_MAP_TYPE_PERCPU_ARRAY 6 #define BPF_MAP_TYPE_LRU_HASH 9 /* ── BPF helper function declarations ────────────────────────────── */ /* SEC / __always_inline macros (if not using bpf/bpf_helpers.h) */ #ifndef SEC #define SEC(name) \ _Pragma("GCC diagnostic push") \ _Pragma("GCC diagnostic ignored \"-Wignored-attributes\"") \ __attribute__((section(name), used)) \ _Pragma("GCC diagnostic pop") #endif #ifndef __always_inline #define __always_inline inline __attribute__((always_inline)) #endif #ifndef __uint #define __uint(name, val) int (*name)[val] #endif #ifndef __type #define __type(name, val) typeof(val) *name #endif /* ── BPF helper IDs (from linux/bpf.h) ──────────────────────────── */ static void *(*bpf_map_lookup_elem)(void *map, const void *key) = (void *) 1; static long (*bpf_map_update_elem)(void *map, const void *key, const void *value, __u64 flags) = (void *) 2; static long (*bpf_map_delete_elem)(void *map, const void *key) = (void *) 3; static __u64 (*bpf_ktime_get_ns)(void) = (void *) 5; static long (*bpf_trace_printk)(const char *fmt, __u32 fmt_size, ...) = (void *) 6; static __u32 (*bpf_get_smp_processor_id)(void) = (void *) 8; static long (*bpf_skb_store_bytes)(struct __sk_buff *skb, __u32 offset, const void *from, __u32 len, __u64 flags) = (void *) 9; static long (*bpf_skb_load_bytes)(const struct __sk_buff *skb, __u32 offset, void *to, __u32 len) = (void *) 26; static __u32 (*bpf_get_prandom_u32)(void) = (void *) 7; /* ── Endian helpers ──────────────────────────────────────────────── */ #ifndef bpf_htons #define bpf_htons(x) __builtin_bswap16(x) #endif #ifndef bpf_ntohs #define bpf_ntohs(x) __builtin_bswap16(x) #endif #ifndef bpf_htonl #define bpf_htonl(x) __builtin_bswap32(x) #endif #ifndef bpf_ntohl #define bpf_ntohl(x) __builtin_bswap32(x) #endif /* memcpy/memset for BPF -- must use builtins */ #ifndef __bpf_memcpy #define __bpf_memcpy __builtin_memcpy #endif #ifndef __bpf_memset #define __bpf_memset __builtin_memset #endif #endif /* __VMLINUX_H__ */