Skip to content

Commit 478b4da

Browse files
authored
Merge pull request #77 from insa-unyte/development
Development
2 parents 2f93551 + 4ae2cfc commit 478b4da

File tree

9 files changed

+550
-0
lines changed

9 files changed

+550
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ sender_continuous
1515
client_continuous
1616
client_monitoring
1717
client_socket
18+
client_ebpf_user
19+
vmlinux.h
1820

1921
docker/tmp
2022

INSTALL.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ $ ./export.sh # Optional: export LD_LIBRARY_PATH with /usr/local/lib in gl
4040
### Configure options
4141
There are some custom `./configure` options :
4242
- `--with-examples`: compile examples directory. Not compiled by default.
43+
- `--with-ebpf-example`: compile eBPF example. Not compiled by default. It check eBPF dependencies too.
4344
- `--with-test`: compile testdirectory. Not compiled by default.
4445
- `--with-pkgconfigdir=[/own_path/pkgconfig]`: overwrite pkgconfig directory to install .pc file [default: ${PREFIX}/lib/pkgconfig]
4546
- `--enable-tcmalloc`: enable compilation with tcmalloc instead of native malloc. tcmalloc should be installed first.
47+
- `--with-linux=[/own_path/linux/src]`: linux source code necesary for eBPF compilation [default: /usr/src/linux]. (On Ubuntu use /usr/src/<linux>-generic version)
4648

4749
## Uninstalling
4850
```shell

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ There are some samples implemented during the development of the project [here](
209209
- `client_socket.c` : example using a custom socket instead of creating a new one from the library.
210210
- `sender_sample.c` : simple example for minimal usage of the sender library.
211211
- `sender_json.c` : sample reading a json file and sending the bytes by the library.
212+
- `eBPF/client_ebpf_user.c`: example with a custom eBPF load balancer.
212213

213214
## Docker
214215
See [Docker docs](docker)

configure.ac

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ AC_ARG_WITH([examples],
2727
[ with_examples=no ]
2828
)
2929

30+
AC_ARG_WITH([ebpf-example],
31+
[AS_HELP_STRING([--with-ebpf-example], [Build eBPF example])],
32+
[ with_ebpf_example=yes ],
33+
[ with_ebpf_example=no ]
34+
)
35+
3036
AM_CONDITIONAL(EXAMPLES, test "x$with_examples" = "xyes")
37+
AM_CONDITIONAL(EBPF_EXAMPLE, test "x$with_ebpf_example" = "xyes")
3138

3239
AC_ARG_WITH([test],
3340
[AS_HELP_STRING([--with-test], [Build test files])],
@@ -56,10 +63,60 @@ then
5663
AC_SUBST([EXTRA_LDFLAGS])
5764
fi
5865

66+
dnl eBPF example
67+
if test "x$with_ebpf_example" = "xyes"
68+
then
69+
AC_CHECK_LIB(bpf, bpf_object__find_map_by_name, [], [
70+
echo "*** Error! You need to install libbpf first. ***"
71+
exit -1
72+
])
73+
74+
AC_CHECK_PROG([CCLANG], [clang], [yes])
75+
AS_IF([ test "x$CCLANG" != xyes ], [
76+
echo "*** Error! eBPF needs CLANG as dependency. Please install it first. ***"
77+
exit -1
78+
])
79+
AC_CHECK_PROG([BPFTOOL], [bpftool], [yes])
80+
AS_IF([ test "x$BPFTOOL" != xyes ], [
81+
echo "*** Error! eBPF needs bpftool as dependency. Please install it first. ***"
82+
exit -1
83+
])
84+
85+
AC_CHECK_FILE([/sys/kernel/btf/vmlinux], [], [
86+
echo "*** Error! eBPF needs vmlinux to compile the eBPF program. ***"
87+
exit -1
88+
])
89+
90+
AC_ARG_WITH([linux],
91+
[AS_HELP_STRING([--with-linux], [Linux source headers [[default: /usr/src/linux]]])],
92+
[LINUX_HEADERS="$withval"],
93+
[LINUX_HEADERS=/usr/src/linux]
94+
)
95+
AC_SUBST([LINUX_HEADERS])
96+
dnl linux source headers
97+
AC_CHECK_FILES([
98+
$LINUX_HEADERS/include/uapi/linux
99+
$LINUX_HEADERS/arch/x86/include
100+
$LINUX_HEADERS/arch/x86/include/generated
101+
$LINUX_HEADERS/include
102+
$LINUX_HEADERS/arch/x86/include/uapi
103+
$LINUX_HEADERS/arch/x86/include/generated/uapi
104+
$LINUX_HEADERS/include/uapi
105+
$LINUX_HEADERS/include/generated/uapi
106+
], [], [
107+
echo "*** Error! eBPFa needs linux source to compile the eBPF program. ***"
108+
echo "*** Linux sources were not found in $LINUX_HEADERS ***"
109+
exit -1
110+
]
111+
)
112+
dnl TODO: check for bpf dependencies
113+
fi
114+
59115
AC_CONFIG_FILES([
60116
Makefile
61117
src/Makefile
62118
examples/Makefile
119+
examples/eBPF/Makefile
63120
test/Makefile
64121
unyte-udp-notif.pc
65122
])

examples/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
AM_LDFLAGS = $(EXTRA_LDFLAGS)
22

3+
if EBPF_EXAMPLE
4+
SUBDIRS = eBPF
5+
endif
6+
37
ACLOCAL_AMFLAGS = -I m4
48

59
bin_PROGRAMS = client_monitoring client_sample client_socket sender_json sender_sample

examples/eBPF/Makefile.am

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
AM_LDFLAGS = $(EXTRA_LDFLAGS)
2+
3+
ACLOCAL_AMFLAGS = -I m4
4+
5+
LINUX_SRC=$(LINUX_HEADERS)
6+
LINUX_H=-I$(LINUX_SRC)/arch/x86/include -I$(LINUX_SRC)/arch/x86/include/generated -I$(LINUX_SRC)/include -I$(LINUX_SRC)/arch/x86/include/uapi -I$(LINUX_SRC)/arch/x86/include/generated/uapi -I$(LINUX_SRC)/include/uapi -I$(LINUX_SRC)/include/generated/uapi
7+
EBPF_CLDFLAGS=-fcolor-diagnostics -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -g -fPIC -g -O2 -D__KERNEL__ -D__TARGET_ARCH_x86 --target=bpf -Wall -Wno-macro-redefined -D__BPF_TRACING__
8+
9+
vmlinux.h:
10+
bpftool btf dump file /sys/kernel/btf/vmlinux format c > $@
11+
12+
reuseport_udp_kern.o: vmlinux.h
13+
clang $(LINUX_H) $(EBPF_CLDFLAGS) -o $@ -c reuseport_udp_kern.c
14+
15+
all-local: reuseport_udp_kern.o
16+
17+
reuseport_udp_kern_odir = $(libdir)
18+
reuseport_udp_kern_o_DATA = \
19+
reuseport_udp_kern.o \
20+
$(NULL)
21+
22+
bin_PROGRAMS = client_ebpf_user
23+
24+
client_ebpf_user_SOURCES = client_ebpf_user.c
25+
client_ebpf_user_CFLAGS = -I$(srcdir)/../../src -Wextra -Wall -ansi -g -std=c11 -D_GNU_SOURCE -fPIC -pthread
26+
client_ebpf_user_LDADD = $(srcdir)/../../src/libunyte-udp-notif.la

examples/eBPF/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# eBPF example
2+
3+
## Dependencies
4+
5+
To use eBPF loadbalancing `Python3` is needed for eBPF compilation.
6+
7+
On Ubuntu:
8+
```shell
9+
$ sudo apt install linux-headers-$(uname -r) clang libbpf-dev linux-tools-$(uname -r)
10+
```
11+
12+
On Centos (tested on `Centos 8`):
13+
```shell
14+
$ sudo yum install kernel-headers clang
15+
$ sudo dnf --enablerepo=powertools install libbpf-devel
16+
$ sudo dnf install bpftool
17+
```
18+
19+
## Install
20+
To build this directory, use the following options on `configure` script:
21+
- `--with-ebpf-example` and `--with-linux=<linux_headers_path>`
22+
```shell
23+
$ ./configure --with-ebpf-example --with-linux=/usr/src/linux
24+
```

0 commit comments

Comments
 (0)