Skip to content

Commit

Permalink
chore(driver/bpf): build probe from within CMAKE_CURRENT_BINARY_DIR l…
Browse files Browse the repository at this point in the history
…ike we do for kmod.

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
  • Loading branch information
FedeDP authored and poiana committed Mar 1, 2024
1 parent f803ea2 commit 3f03a2c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 35 deletions.
66 changes: 38 additions & 28 deletions driver/bpf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,24 @@ configure_file(../driver_config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/../driver_confi

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

if(NOT BUILD_BPF)
return()
endif()
if(BUILD_BPF)
# Check minimum kernel version
set(bpf_min_kver_map_x86_64 4.14)
set(bpf_min_kver_map_aarch64 4.17)
set(bpf_min_kver_map_s390x 5.5)
set(bpf_min_kver_map_ppc64le 4.18)
if (LINUX_KERNEL_VERSION VERSION_LESS ${bpf_min_kver_map_${TARGET_ARCH}})
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()

# Check minimum kernel version
set(bpf_min_kver_map_x86_64 4.14)
set(bpf_min_kver_map_aarch64 4.17)
set(bpf_min_kver_map_s390x 5.5)
set(bpf_min_kver_map_ppc64le 4.18)
if (LINUX_KERNEL_VERSION VERSION_LESS ${bpf_min_kver_map_${TARGET_ARCH}})
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}")
add_custom_target(bpf ALL
COMMAND make
COMMAND "${CMAKE_COMMAND}" -E copy_if_different probe.o "${CMAKE_CURRENT_BINARY_DIR}"
WORKING_DIRECTORY src
VERBATIM)
endif()

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}"
VERBATIM)

if(NOT DEFINED DRIVER_BPF_COMPONENT_NAME)
set(DRIVER_BPF_COMPONENT_NAME ${DRIVER_COMPONENT_NAME})
endif()

install(DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/../src/
DESTINATION "src/${DRIVER_PACKAGE_NAME}-${DRIVER_VERSION}"
COMPONENT ${DRIVER_BPF_COMPONENT_NAME}
FILES_MATCHING PATTERN "*.h")

install(FILES
set(BPF_SOURCES
bpf_helpers.h
builtins.h
filler_helpers.h
Expand All @@ -52,5 +40,27 @@ install(FILES
ring_helpers.h
missing_definitions.h
types.h
)

# Append driver headers too since they are used by bpf headers
file(GLOB DRIVER_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/../*.h)
list(APPEND BPF_SOURCES ${DRIVER_HEADERS})

set(INSTALL_SET "")
# Copy all needed sources under src folder in current binary dir
# and add them to the set of installed files
foreach(SOURCE IN LISTS BPF_SOURCES)
get_filename_component(FILENAME ${SOURCE} NAME)
configure_file(${SOURCE} src/${FILENAME} COPYONLY)
list(APPEND INSTALL_SET ${CMAKE_CURRENT_BINARY_DIR}/src/${FILENAME})
endforeach()

if(NOT DEFINED DRIVER_BPF_COMPONENT_NAME)
set(DRIVER_BPF_COMPONENT_NAME ${DRIVER_COMPONENT_NAME})
endif()

install(FILES
${INSTALL_SET}
DESTINATION "src/${DRIVER_PACKAGE_NAME}-${DRIVER_VERSION}/bpf"
COMPONENT ${DRIVER_BPF_COMPONENT_NAME})
COMPONENT ${DRIVER_BPF_COMPONENT_NAME}
)
2 changes: 1 addition & 1 deletion driver/bpf/filler_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,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"
#include "missing_definitions.h"

Expand Down
6 changes: 3 additions & 3 deletions driver/bpf/fillers.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,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 <linux/tty.h>
Expand Down
2 changes: 1 addition & 1 deletion driver/bpf/plumbing_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ or GPL2.txt for full copies of the license.

#include "types.h"
#include "builtins.h"
#include "../socketcall_to_syscall.h"
#include "socketcall_to_syscall.h"

#define _READ(P) ({ typeof(P) _val; \
bpf_probe_read_kernel(&_val, sizeof(_val), &P); \
Expand Down
4 changes: 2 additions & 2 deletions driver/bpf/probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,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 3f03a2c

Please sign in to comment.