Skip to content

Commit

Permalink
build: allow disabling eBPF support in n-acd
Browse files Browse the repository at this point in the history
Add a configure option to disable eBPF support in n-acd.

Note that, even if eBPF is not supported, n-acd requires a kernel >
3.19, which means that the setsockopt(..., SO_ATTACH_BPF) option must
be defined. To allow building on older kernels without modifying the
n-acd code, we inject the SO_ATTACH_BPF value as a preprocessor define
in the compiler the command line.
  • Loading branch information
bengal committed Sep 13, 2018
1 parent c9cf6eb commit 34903a6
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Expand Up @@ -48,7 +48,7 @@ addons:
coverity_scan:
project:
name: NetworkManager/NetworkManager
build_command_prepend: sh autogen.sh --with-systemd-logind=no --enable-more-warnings=no --disable-ovs
build_command_prepend: sh autogen.sh --with-systemd-logind=no --enable-more-warnings=no --disable-ovs --without-ebpf
build_command: make -j4
branch_pattern: .*coverity.*

Expand Down Expand Up @@ -114,6 +114,7 @@ script:
-D ifcfg_rh=false \
-D ibft=true \
-D ifupdown=true \
-D ebpf=false \
&&
ninja -C build &&
ninja -C build test
Expand All @@ -136,6 +137,7 @@ script:
--enable-more-warnings=no \
--enable-tests=yes \
--with-crypto=$CRYPTO \
--without-ebpf \
\
--with-libnm-glib=yes \
--with-iwd=yes \
Expand Down
8 changes: 7 additions & 1 deletion Makefile.am
Expand Up @@ -1370,6 +1370,7 @@ shared_libnacd_la_LIBADD = shared/libcrbtree.la

shared_libnacd_la_CPPFLAGS = \
-D_GNU_SOURCE \
-DSO_ATTACH_BPF=50 \
$(CODE_COVERAGE_CFLAGS) \
$(SANITIZER_LIB_CFLAGS) \
-I$(srcdir)/shared/c-list/src \
Expand All @@ -1380,12 +1381,17 @@ shared_libnacd_la_CPPFLAGS = \
shared_libnacd_la_SOURCES = \
shared/n-acd/src/n-acd.c \
shared/n-acd/src/n-acd.h \
shared/n-acd/src/n-acd-bpf.c \
shared/n-acd/src/n-acd-private.h \
shared/n-acd/src/n-acd-probe.c \
shared/n-acd/src/util/timer.c \
shared/n-acd/src/util/timer.h

if WITH_EBPF
shared_libnacd_la_SOURCES += shared/n-acd/src/n-acd-bpf.c
else
shared_libnacd_la_SOURCES += shared/n-acd/src/n-acd-bpf-fallback.c
endif

EXTRA_DIST += shared/c-list/src/c-list.h

###############################################################################
Expand Down
10 changes: 10 additions & 0 deletions configure.ac
Expand Up @@ -518,6 +518,15 @@ case $with_suspend_resume in
;;
esac

# eBPF support
AC_ARG_WITH(ebpf,
AS_HELP_STRING([--with-ebpf=yes|no], [Build with eBPF support (default: yes)]),
[], [with_ebpf=yes])
if test "$with_ebpf" != "yes" -a "$with_ebpf" != "no"; then
AC_MSG_ERROR(--with-ebpf must be one of [yes, no])
fi
AM_CONDITIONAL(WITH_EBPF, test "${with_ebpf}" = "yes")

# SELinux support
AC_ARG_WITH(selinux,
AS_HELP_STRING([--with-selinux=yes|no|auto], [Build with SELinux (default: auto)]),
Expand Down Expand Up @@ -1353,4 +1362,5 @@ echo " JSON validation for libnm: $enable_json_validation"
echo " crypto: $with_crypto (have-gnutls: $have_crypto_gnutls, have-nss: $have_crypto_nss)"
echo " sanitizers: $sanitizers"
echo " Mozilla Public Suffix List: $with_libpsl"
echo " eBPF: $with_ebpf"
echo
1 change: 1 addition & 0 deletions meson_options.txt
Expand Up @@ -41,6 +41,7 @@ option('libnm_glib', type: 'boolean', value: false, description: 'build legacy l
option('nmcli', type: 'boolean', value: true, description: 'Build nmcli')
option('nmtui', type: 'boolean', value: true, description: 'Build nmtui')
option('bluez5_dun', type: 'boolean', value: false, description: 'enable Bluez5 DUN support')
option('ebpf', type: 'boolean', value: true, description: 'Enable or disable eBPF support')

# configuration plugins
option('config_plugins_default', type: 'string', value: '', description: 'Default configuration option for main.plugins setting, used as fallback if the configuration option is unset')
Expand Down
12 changes: 10 additions & 2 deletions shared/meson.build
Expand Up @@ -23,17 +23,25 @@ shared_c_rbtree_dep = declare_dependency(
link_with: shared_c_rbtree,
)


if get_option('ebpf')
shared_n_acd_bpf_files = files('n-acd/src/n-acd-bpf.c')
else
shared_n_acd_bpf_files = files('n-acd/src/n-acd-bpf-fallback.c')
endif

shared_n_acd = static_library(
'n-acd',
sources: files('n-acd/src/n-acd.c',
'n-acd/src/n-acd.h',
'n-acd/src/n-acd-bpf.c',
'n-acd/src/n-acd-private.h',
'n-acd/src/n-acd-probe.c',
'n-acd/src/util/timer.c',
'n-acd/src/util/timer.h'),
'n-acd/src/util/timer.h')
+ shared_n_acd_bpf_files,
c_args: [
'-D_GNU_SOURCE',
'-DSO_ATTACH_BPF=50',
'-std=c11',
'-Wno-pointer-arith',
'-Wno-vla',
Expand Down

0 comments on commit 34903a6

Please sign in to comment.