Skip to content

Commit

Permalink
cleanup(build): self-contained BPF probe build
Browse files Browse the repository at this point in the history
The BPF build now no longer touches the source directory
and does not depend on any files outside the (generated)
source directory.

Signed-off-by: Grzegorz Nosek <[email protected]>
  • Loading branch information
gnosek committed Jul 5, 2023
1 parent a483002 commit 8a4c3d2
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 28 deletions.
46 changes: 34 additions & 12 deletions driver/bpf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,32 @@ configure_file(../driver_config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/../driver_confi

option(BUILD_BPF "Build the BPF driver on Linux" OFF)

# Note: probe.c *must* be the first entry to generate a proper Makefile
set(BPF_SOURCES
probe.c
bpf_helpers.h
builtins.h
filler_helpers.h
fillers.h
maps.h
missing_definitions.h
plumbing_helpers.h
quirks.h
ring_helpers.h
types.h
${CMAKE_CURRENT_SOURCE_DIR}/../driver_config.h
../ppm_api_version.h
../ppm_events_public.h
../feature_gates.h
../ppm_version.h
../ppm_fillers.h
../ppm_flag_helpers.h
../ppm.h
../ppm_consumer.h
../capture_macro.h
../systype_compat.h
)

if(BUILD_BPF)
# Check minimum kernel version
set(bpf_min_kver_map_x86_64 4.14)
Expand All @@ -18,25 +44,21 @@ if(BUILD_BPF)
message(WARNING "[BPF] To run this driver you need a Linux kernel version >= ${bpf_min_kver_map_${TARGET_ARCH}} but actual kernel version is: ${UNAME_RESULT}")
endif()

foreach(FILENAME IN LISTS BPF_SOURCES)
get_filename_component(BASENAME ${FILENAME} NAME)
configure_file(${FILENAME} src/${BASENAME} COPYONLY)
string(APPEND BPF_DEPENDENCIES "$(src)/${BASENAME} ")
endforeach()

add_custom_target(bpf ALL
COMMAND make
COMMAND "${CMAKE_COMMAND}" -E copy_if_different probe.o "${CMAKE_CURRENT_BINARY_DIR}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/src"
VERBATIM)
endif()

install(FILES
bpf_helpers.h
builtins.h
filler_helpers.h
fillers.h
${BPF_SOURCES}
Makefile
maps.h
plumbing_helpers.h
probe.c
quirks.h
ring_helpers.h
missing_definitions.h
types.h
DESTINATION "src/${DRIVER_PACKAGE_NAME}-${DRIVER_VERSION}/bpf"
COMPONENT ${DRIVER_COMPONENT_NAME})
11 changes: 1 addition & 10 deletions driver/bpf/Makefile → driver/bpf/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,7 @@ clean:
$(MAKE) -C $(KERNELDIR) M=$$PWD clean
@rm -f *~

$(obj)/probe.o: $(src)/probe.c \
$(src)/bpf_helpers.h \
$(src)/filler_helpers.h \
$(src)/fillers.h \
$(src)/maps.h \
$(src)/plumbing_helpers.h \
$(src)/quirks.h \
$(src)/ring_helpers.h \
$(src)/missing_definitions.h \
$(src)/types.h
$(obj)/probe.o: @BPF_DEPENDENCIES@
$(CLANG) $(LINUXINCLUDE) \
$(KBUILD_CPPFLAGS) \
$(KBUILD_EXTRA_CPPFLAGS) \
Expand Down
2 changes: 1 addition & 1 deletion driver/bpf/filler_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ or GPL2.txt for full copies of the license.
#include <linux/fdtable.h>
#include <linux/net.h>

#include "../ppm_flag_helpers.h"
#include "ppm_flag_helpers.h"
#include "builtins.h"

// Old kernels (like 4.14) have too strict limits on the bpf program length to support 32 path components. For the moment we decrease the limit to 16.
Expand Down
6 changes: 3 additions & 3 deletions driver/bpf/fillers.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ or GPL2.txt for full copies of the license.
#ifndef __FILLERS_H
#define __FILLERS_H

#include "../systype_compat.h"
#include "../ppm_flag_helpers.h"
#include "../ppm_version.h"
#include "systype_compat.h"
#include "ppm_flag_helpers.h"
#include "ppm_version.h"
#include "bpf_helpers.h"
#include "missing_definitions.h"

Expand Down
4 changes: 2 additions & 2 deletions driver/bpf/probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ or GPL2.txt for full copies of the license.
#endif
#include <linux/sched.h>

#include "../driver_config.h"
#include "../ppm_events_public.h"
#include "driver_config.h"
#include "ppm_events_public.h"
#include "bpf_helpers.h"
#include "types.h"
#include "maps.h"
Expand Down

0 comments on commit 8a4c3d2

Please sign in to comment.