build: allow disabling eBPF support in n-acd

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.
This commit is contained in:
Beniamino Galvani 2018-09-04 08:25:07 +02:00
parent d9a4b59c18
commit 691c71a7f2
5 changed files with 31 additions and 4 deletions

View file

@ -48,7 +48,7 @@ addons:
coverity_scan: coverity_scan:
project: project:
name: NetworkManager/NetworkManager 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 build_command: make -j4
branch_pattern: .*coverity.* branch_pattern: .*coverity.*
@ -114,6 +114,7 @@ script:
-D ifcfg_rh=false \ -D ifcfg_rh=false \
-D ibft=true \ -D ibft=true \
-D ifupdown=true \ -D ifupdown=true \
-D ebpf=false \
&& &&
ninja -C build && ninja -C build &&
ninja -C build test ninja -C build test
@ -136,6 +137,7 @@ script:
--enable-more-warnings=no \ --enable-more-warnings=no \
--enable-tests=yes \ --enable-tests=yes \
--with-crypto=$CRYPTO \ --with-crypto=$CRYPTO \
--without-ebpf \
\ \
--with-libnm-glib=yes \ --with-libnm-glib=yes \
--with-iwd=yes \ --with-iwd=yes \

View file

@ -1370,6 +1370,7 @@ shared_libnacd_la_LIBADD = shared/libcrbtree.la
shared_libnacd_la_CPPFLAGS = \ shared_libnacd_la_CPPFLAGS = \
-D_GNU_SOURCE \ -D_GNU_SOURCE \
-DSO_ATTACH_BPF=50 \
$(CODE_COVERAGE_CFLAGS) \ $(CODE_COVERAGE_CFLAGS) \
$(SANITIZER_LIB_CFLAGS) \ $(SANITIZER_LIB_CFLAGS) \
-I$(srcdir)/shared/c-list/src \ -I$(srcdir)/shared/c-list/src \
@ -1380,12 +1381,17 @@ shared_libnacd_la_CPPFLAGS = \
shared_libnacd_la_SOURCES = \ shared_libnacd_la_SOURCES = \
shared/n-acd/src/n-acd.c \ shared/n-acd/src/n-acd.c \
shared/n-acd/src/n-acd.h \ 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-private.h \
shared/n-acd/src/n-acd-probe.c \ shared/n-acd/src/n-acd-probe.c \
shared/n-acd/src/util/timer.c \ shared/n-acd/src/util/timer.c \
shared/n-acd/src/util/timer.h 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 EXTRA_DIST += shared/c-list/src/c-list.h
############################################################################### ###############################################################################

View file

@ -518,6 +518,15 @@ case $with_suspend_resume in
;; ;;
esac 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 # SELinux support
AC_ARG_WITH(selinux, AC_ARG_WITH(selinux,
AS_HELP_STRING([--with-selinux=yes|no|auto], [Build with SELinux (default: auto)]), AS_HELP_STRING([--with-selinux=yes|no|auto], [Build with SELinux (default: auto)]),
@ -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 " crypto: $with_crypto (have-gnutls: $have_crypto_gnutls, have-nss: $have_crypto_nss)"
echo " sanitizers: $sanitizers" echo " sanitizers: $sanitizers"
echo " Mozilla Public Suffix List: $with_libpsl" echo " Mozilla Public Suffix List: $with_libpsl"
echo " eBPF: $with_ebpf"
echo echo

View file

@ -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('nmcli', type: 'boolean', value: true, description: 'Build nmcli')
option('nmtui', type: 'boolean', value: true, description: 'Build nmtui') option('nmtui', type: 'boolean', value: true, description: 'Build nmtui')
option('bluez5_dun', type: 'boolean', value: false, description: 'enable Bluez5 DUN support') 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 # 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') option('config_plugins_default', type: 'string', value: '', description: 'Default configuration option for main.plugins setting, used as fallback if the configuration option is unset')

View file

@ -23,17 +23,25 @@ shared_c_rbtree_dep = declare_dependency(
link_with: shared_c_rbtree, 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( shared_n_acd = static_library(
'n-acd', 'n-acd',
sources: files('n-acd/src/n-acd.c', sources: files('n-acd/src/n-acd.c',
'n-acd/src/n-acd.h', '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-private.h',
'n-acd/src/n-acd-probe.c', 'n-acd/src/n-acd-probe.c',
'n-acd/src/util/timer.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: [ c_args: [
'-D_GNU_SOURCE', '-D_GNU_SOURCE',
'-DSO_ATTACH_BPF=50',
'-std=c11', '-std=c11',
'-Wno-pointer-arith', '-Wno-pointer-arith',
'-Wno-vla', '-Wno-vla',