Skip to content

Commit d4b7008

Browse files
committed
Fix bpf compilation on redhat and centos with kernel 4.18
1 parent 57e2178 commit d4b7008

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

tracee/tracee.bpf.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ BPF_MAP(_name, BPF_MAP_TYPE_PROG_ARRAY, u32, u32, _max_entries);
156156
#define BPF_PERF_OUTPUT(_name) \
157157
BPF_MAP(_name, BPF_MAP_TYPE_PERF_EVENT_ARRAY, int, __u32, 1024);
158158

159+
#ifdef RHEL_RELEASE_CODE
160+
#if (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(8, 0))
161+
#define RHEL_RELEASE_GT_8_0
162+
#endif
163+
#endif
164+
159165
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
160166
#error Minimal required kernel version is 4.14
161167
#endif
@@ -273,7 +279,7 @@ static __always_inline u32 get_task_ns_pid(struct task_struct *task)
273279
{
274280
unsigned int level = READ_KERN(READ_KERN(READ_KERN(task->nsproxy)->pid_ns_for_children)->level);
275281

276-
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0)
282+
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0) && !defined(RHEL_RELEASE_GT_8_0))
277283
// kernel 4.14-4.18:
278284
return READ_KERN(READ_KERN(task->pids[PIDTYPE_PID].pid)->numbers[level].nr);
279285
#else
@@ -287,7 +293,7 @@ static __always_inline u32 get_task_ns_tgid(struct task_struct *task)
287293
unsigned int level = READ_KERN(READ_KERN(READ_KERN(task->nsproxy)->pid_ns_for_children)->level);
288294
struct task_struct *group_leader = READ_KERN(task->group_leader);
289295

290-
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0)
296+
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0) && !defined(RHEL_RELEASE_GT_8_0))
291297
// kernel 4.14-4.18:
292298
return READ_KERN(READ_KERN(group_leader->pids[PIDTYPE_PID].pid)->numbers[level].nr);
293299
#else
@@ -301,7 +307,7 @@ static __always_inline u32 get_task_ns_ppid(struct task_struct *task)
301307
struct task_struct *real_parent = READ_KERN(task->real_parent);
302308
unsigned int level = READ_KERN(READ_KERN(READ_KERN(real_parent->nsproxy)->pid_ns_for_children)->level);
303309

304-
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0)
310+
#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 19, 0) && !defined(RHEL_RELEASE_GT_8_0))
305311
// kernel 4.14-4.18:
306312
return READ_KERN(READ_KERN(real_parent->pids[PIDTYPE_PID].pid)->numbers[level].nr);
307313
#else

0 commit comments

Comments
 (0)