*/
#include <linux/bpf.h>
#include <linux/version.h>
+#include <sys/utsname.h>
#include <clang/AST/ASTConsumer.h>
#include <clang/AST/ASTContext.h>
map_type = BPF_MAP_TYPE_HASH;
else if (A->getName() == "maps/array")
map_type = BPF_MAP_TYPE_ARRAY;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0)
- else if (A->getName() == "maps/prog")
- map_type = BPF_MAP_TYPE_PROG_ARRAY;
-#endif
+ else if (A->getName() == "maps/prog") {
+ struct utsname un;
+ if (uname(&un) == 0) {
+ int major = 0, minor = 0;
+ // release format: <major>.<minor>.<revision>[-<othertag>]
+ sscanf(un.release, "%d.%d.", &major, &minor);
+ if (KERNEL_VERSION(major,minor,0) >= KERNEL_VERSION(4,2,0))
+ map_type = BPF_MAP_TYPE_PROG_ARRAY;
+ }
+ }
table.fd = bpf_create_map(map_type, table.key_size, table.leaf_size, table.max_entries);
if (table.fd < 0) {
llvm::errs() << "error: could not open bpf fd\n";