From 274880b339e01cd9f8c1a5d2ff5d4b44474fac33 Mon Sep 17 00:00:00 2001 From: Anuj Srivastava Date: Sun, 21 Nov 2021 04:18:45 -0800 Subject: [PATCH] Make build compatible with RHEL7 Define SO_ATTACH_BPF and SO_DETACH_BPF to fix go build and go install for gobpf on RHEL7 OS. For reference: Kernel version on RHEL7 is 3.10.x with eBPF capabilities backported. (https://access.redhat.com/articles/3078 & https://www.redhat.com/en/blog/introduction-ebpf-red-hat-enterprise-linux-7) But SO_ATTACH_BPF and SO_DETACH_BPF capabilites were added since kernel version 3.19 onwards. --- elf/include/uapi/linux/bpf.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/elf/include/uapi/linux/bpf.h b/elf/include/uapi/linux/bpf.h index 91c43884..6cb317c6 100644 --- a/elf/include/uapi/linux/bpf.h +++ b/elf/include/uapi/linux/bpf.h @@ -837,14 +837,14 @@ union bpf_attr { * * int ret; * struct bpf_tunnel_key key = {}; - * + * * ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), 0); * if (ret < 0) * return TC_ACT_SHOT; // drop packet - * + * * if (key.remote_ipv4 != 0x0a000001) * return TC_ACT_SHOT; // drop packet - * + * * return TC_ACT_OK; // accept packet * * This interface can also be used with all encapsulation devices @@ -3054,4 +3054,12 @@ struct bpf_line_info { __u32 line_col; }; +#ifndef SO_ATTACH_BPF +#define SO_ATTACH_BPF 50 +#endif + +#ifndef SO_DETACH_BPF +#define SO_DETACH_BPF SO_DETACH_FILTER +#endif + #endif /* _UAPI__LINUX_BPF_H__ */