Skip to content

Commit 4554211

Browse files
eBPF library support for SONiC applications
It provides a generic library support for filtering the netlink message using eBPF based packet filtering. Linux netlink messaging system is a broadcast domain, every netlink message is broadcasted to all the subscribed appplications regardless whether the application is interested in it or not. In a scaled scenario, more than 1 million message is being broadcasted across applications. This framework helps to filter the unwanted netlink message at the kernel space itself and eliminates the unnecessary passing of message to the user space application and then it get dropped. This improves the system performance and scale the system to higher level.
1 parent 54681f1 commit 4554211

File tree

30 files changed

+3599
-0
lines changed

30 files changed

+3599
-0
lines changed

dockers/docker-base-stretch/Dockerfile.j2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ RUN apt-get -y purge \
111111
{{ install_debian_packages(docker_base_stretch_debs.split(' ')) }}
112112
{%- endif %}
113113

114+
# Base packages for bpf
115+
RUN apt-get install -f -y libbpf-dev libelf-dev
116+
114117
# Clean up apt
115118
# Remove /var/lib/apt/lists/*, could be obsoleted for derived images
116119
RUN apt-get clean -y && \

files/build_templates/docker_image_ctl.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ start() {
390390
{%- if sonic_asic_platform != "mellanox" %}
391391
--tmpfs /tmp \
392392
{%- endif %}
393+
-v /sys/kernel/debug:/sys/kernel/debug \
394+
--ulimit memlock=67108864:67108864 \
393395
--tmpfs /var/tmp \
394396
--env "NAMESPACE_ID"="$DEV" \
395397
--env "NAMESPACE_PREFIX"="$NAMESPACE_PREFIX" \

rules/libebpf.dep

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
SPATH := $($(LIBEBPF)_SRC_PATH)
3+
DEP_FILES := $(SONIC_COMMON_FILES_LIST) rules/libebpf.mk rules/libebpf.dep
4+
DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST)
5+
DEP_FILES += $(shell git ls-files $(SPATH))
6+
7+
$(LIBEBPF)_CACHE_MODE := GIT_CONTENT_SHA
8+
$(LIBEBPF)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST)
9+
$(LIBEBPF)_DEP_FILES := $(DEP_FILES)
10+

rules/libebpf.mk

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# BPF package
2+
BPF_VERSION := 1.0.0
3+
LIBEBPF = libebpf_$(BPF_VERSION)_$(CONFIGURED_ARCH).deb
4+
$(LIBEBPF)_SRC_PATH = $(SRC_PATH)/libebpf
5+
$(LIBEBPF)_DEPENDS += $(LINUX_HEADERS) $(LINUX_COMMON_HEADERS)
6+
SONIC_MAKE_DEBS += $(LIBEBPF)
7+
8+
LIBEBPF_DBG = libebpf-dbgsym_$(BPF_VERSION)_$(CONFIGURED_ARCH).deb
9+
$(LIBEBPF_DBG)_DEPENDS += $(LIBEBPF)
10+
$(eval $(call add_derived_package,$(LIBEBPF),$(LIBEBPF_DBG)))
11+
12+
export LIBEBPF LIBEBPF_DBG BPF_VERSION
13+

sonic-slave-stretch/Dockerfile.j2

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,11 @@ RUN apt-get update && apt-get install -y \
291291
# For iptables
292292
libnetfilter-conntrack-dev \
293293
libnftnl-dev \
294+
# eBPF tools
295+
clang-6.0 \
296+
llvm-6.0 \
297+
libbpf-dev \
298+
libelf-dev \
294299
# For SAI3.7
295300
protobuf-compiler \
296301
libprotobuf-dev \

src/libebpf/Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
SHELL = /bin/bash
2+
.ONESHELL:
3+
.SHELLFLAGS += -e
4+
5+
MAIN_TARGET := libebpf_$(EBPF_VERSION)_$(CONFIGURED_ARCH).deb
6+
7+
$(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% :
8+
9+
pushd src
10+
[ ! -f ./autogen.sh ] || ./autogen.sh
11+
dpkg-buildpackage -us -uc -b -j$(SONIC_CONFIG_MAKE_JOBS)
12+
popd
13+
14+
mv $(LIBEBPF_DBG) $* $(DEST)/

src/libebpf/src/Makefile.am

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ACLOCAL_AMFLAGS = -I m4
2+
3+
SUBDIRS = libutil samples/ebpf-kern-mod samples/ebpf-user-mod

src/libebpf/src/autogen.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
libtoolize --force --copy &&
4+
autoreconf --force --install -I m4
5+
rm -Rf autom4te.cache
6+

0 commit comments

Comments
 (0)