Skip to content

Conversation

@anujsrv
Copy link

@anujsrv anujsrv commented Nov 21, 2021

Defining SO_ATTACH_BPF and SO_DETACH_BPF to fix go build and go install 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 capabilities were added since kernel
version 3.19 onwards.

Without these changes, this is the error I get on my RHEL7 machine (with 3.10.0-1160 kernel) -

$ git branch -l
* master
  socket_compat
$ go build -a ./elf/
# github.com/iovisor/gobpf/elf
elf/module.go: In function 'bpf_attach_socket':
elf/module.go:96:38: error: 'SO_ATTACH_BPF' undeclared (first use in this function)
  return setsockopt(sock, SOL_SOCKET, SO_ATTACH_BPF, &fd, sizeof(fd));
                                      ^
elf/module.go:96:38: note: each undeclared identifier is reported only once for each function it appears in
elf/module.go: In function 'bpf_detach_socket':
elf/module.go:101:38: error: 'SO_DETACH_BPF' undeclared (first use in this function)
  return setsockopt(sock, SOL_SOCKET, SO_DETACH_BPF, &fd, sizeof(fd));

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.
@anujsrv anujsrv changed the title Make build compatible with RHEL7 elf: Make build compatible with RHEL7 Nov 21, 2021
@anujsrv
Copy link
Author

anujsrv commented Nov 22, 2021

@schu Can you have a look at this? Appreciate it.

@fanfanbj
Copy link

fanfanbj commented Jun 9, 2023

/assign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants