Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ option(BUILD_CMOCKA_LIB "Build cmocka library" OFF)
option(BUILD_UUID_LIB "Build uuid library" ON)
option(BUILD_PCAP_LIB "Build pcap library" ON)
option(BUILD_PROTOBUFC_LIB "Build protobuf-c library" ON)
option(BUILD_SQLHOOK "Build the sqlhook extension library" OFF)

option(USE_NETLINK_SERVICE "Use netlink service" OFF)
cmake_dependent_option(BUILD_MNL_LIB "Build mnl library" ON USE_NETLINK_SERVICE OFF)
Expand Down
91 changes: 91 additions & 0 deletions CMakeModules/CMakeToolchains/cheri-cross.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Below replaced later with actual toolchaibn download and compile, which takes hours
set(CheriBSD_output_location "/home/alexandru/cheri/output")
set(CheriBSD_toolchain_location "${CheriBSD_output_location}/morello-sdk")
set(CheriBSD_tools_location "${CheriBSD_toolchain_location}/bin")
set(CheriBSD_rootfs_location "${CheriBSD_output_location}/rootfs-morello-purecap")
set(CheriBSD_usr_location "${CheriBSD_rootfs_location}/usr")
set(CheriBSD_package_location "${CheriBSD_usr_location}/local/morello-purecap")
set(CheriBSD_pkgconfig_locations "${CheriBSD_usr_location}/libdata/pkgconfig")
set(CheriBSD_pkgconfig_locations "${CheriBSD_pkgconfig_locations}:${CheriBSD_usr_location}/local/morello-purecap/lib/pkgconfig")
set(CheriBSD_pkgconfig_locations "${CheriBSD_pkgconfig_locations}:${CheriBSD_usr_location}/local/morello-purecap/share/pkgconfig")
set(CheriBSD_pkgconfig_locations "${CheriBSD_pkgconfig_locations}:${CheriBSD_usr_location}/local/morello-purecap/libdata/pkgconfig")
set(CheriBSD_pkgconfig_locations "${CheriBSD_pkgconfig_locations}:${CheriBSD_usr_location}/local/lib/pkgconfig")
set(CheriBSD_pkgconfig_locations "${CheriBSD_pkgconfig_locations}:${CheriBSD_usr_location}/local/share/pkgconfig")
set(CheriBSD_pkgconfig_locations "${CheriBSD_pkgconfig_locations}:${CheriBSD_usr_location}/local/libdata/pkgconfig")

set(CheriBSD_SDK_GNU_TARGET "aarch64-unknown-freebsd")
set(CheriBSD_c_flags "-target ${CheriBSD_SDK_GNU_TARGET} --sysroot=${CheriBSD_rootfs_location} -B${CheriBSD_tools_location} -mcpu=rainier -march=morello+c64 -mabi=purecap -Xclang -morello-vararg=new")
set(CheriBSD_cxx_flags "-target ${CheriBSD_SDK_GNU_TARGET} --sysroot=${CheriBSD_rootfs_location} -B${CheriBSD_tools_location} -mcpu=rainier -march=morello+c64 -mabi=purecap -Xclang -morello-vararg=new")

if (NOT IS_DIRECTORY "${CheriBSD_tools_location}")
message(FATAL_ERROR "CheriBSD SDK toolchain directory TOOLCHAIN_DIR=${CheriBSD_tools_location} is not found")
endif()

set(ENV{STAGING_DIR} "${CMAKE_STAGING_PREFIX}")

# need to add toolchain prefix to path, as dependencies use autoconf ./configure to find compilers
set(ENV{PATH} "$ENV{PATH}:${CheriBSD_tools_location}")

# setting CMAKE_REQUIRED_DEFINITIONS should be better for `check_include_file()`
list(APPEND CMAKE_REQUIRED_DEFINITIONS "-Dcheribsd_toolchain_location=${cheribsd_toolchain_location}")
set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")

set(CMAKE_SYSROOT "${CheriBSD_rootfs_location}")

# where is the target environment
set(CMAKE_FIND_ROOT_PATH "${CheriBSD_rootfs_location}")

set(CMAKE_SYSTEM_NAME FreeBSD) # FreeBSD
set(CMAKE_ASM_COMPILER_TARGET "${CheriBSD_SDK_GNU_TARGET}")
set(CMAKE_C_COMPILER_TARGET "${CheriBSD_SDK_GNU_TARGET}")
set(CMAKE_CXX_COMPILER_TARGET "${CheriBSD_SDK_GNU_TARGET}")
set(CROSS_COMPILE_PREFIX "${CheriBSD_tools_location}/${CheriBSD_SDK_GNU_TARGET}-") # used by lib/openssl.cmake only
#set(CMAKE_SYSTEM_PROCESSOR "${CheriBSD_SDK_SYSTEM_PROCESSOR}")

set(c_compiler "${CheriBSD_tools_location}/${CheriBSD_SDK_GNU_TARGET}-cc${CMAKE_EXECUTABLE_SUFFIX}")
if(NOT EXISTS "${c_compiler}")
message(FATAL_ERROR "C compiler ${c_compiler} does not exist. Please make sure that you have set GNU_TARGET to the GNU target prefix in ${CheriBSD_tools_location}")
endif()

set(CMAKE_AR "${CheriBSD_tools_location}/${CheriBSD_SDK_GNU_TARGET}-ar${CMAKE_EXECUTABLE_SUFFIX}")
set(CMAKE_ASM_COMPILER "${CheriBSD_tools_location}/${CheriBSD_SDK_GNU_TARGET}-cc${CMAKE_EXECUTABLE_SUFFIX}")
set(CMAKE_C_COMPILER "${c_compiler}")
set(CMAKE_CXX_COMPILER "${CheriBSD_tools_location}/${CheriBSD_SDK_GNU_TARGET}-c++${CMAKE_EXECUTABLE_SUFFIX}")
set(CMAKE_LINKER "${CheriBSD_tools_location}/${CheriBSD_SDK_GNU_TARGET}-ld${CMAKE_EXECUTABLE_SUFFIX}")
set(CMAKE_OBJCOPY "${CheriBSD_tools_location}/${CheriBSD_SDK_GNU_TARGET}-objcopy${CMAKE_EXECUTABLE_SUFFIX}")
set(CMAKE_RANLIB "${CheriBSD_tools_location}/${CheriBSD_SDK_GNU_TARGET}-ranlib${CMAKE_EXECUTABLE_SUFFIX}")
set(CMAKE_STRIP "${CheriBSD_tools_location}/${CheriBSD_SDK_GNU_TARGET}-strip${CMAKE_EXECUTABLE_SUFFIX}")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CheriBSD_c_flags}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CheriBSD_cxx_flags}")

# Without this flag CMake is not able to pass test compilation check
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH FALSE)

# PKG_CONFIG_LIBDIR overrides PKG_CONFIG_PATH
set(PKG_CONFIG_LIBDIR "${CheriBSD_pkgconfig_locations}")
set(ENV{PKG_CONFIG_LIBDIR} "${CheriBSD_pkgconfig_locations}")
set(PKG_CONFIG_SYSROOT_DIR ${CheriBSD_rootfs_location})
set(ENV{PKG_CONFIG_SYSROOT_DIR} ${CheriBSD_rootfs_location})
set(PKG_CONFIG_PATH "")
set(ENV{PKG_CONFIG_PATH} "")

# Use -pthread flag https://gitlab.kitware.com/cmake/cmake/issues/16920
set(THREADS_HAVE_PTHREAD_ARG TRUE)

# Ensure we search in the custom install prefix that we install everything to:
set(CMAKE_PREFIX_PATH "${CheriBSD_package_location};${CMAKE_PREFIX_PATH}")


# Standard propgrams like flex, etc
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

# for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

# Debug mode
# set(CMAKE_FIND_DEBUG_MODE TRUE)
4 changes: 4 additions & 0 deletions CMakeModules/CMakeToolchains/cheri.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -target aarch64-unknown-freebsd -march=morello+c64 -mabi=purecap -Xclang -morello-vararg=new")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

31 changes: 30 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,26 @@
"BUILD_HOSTAPD": false,
"USE_CRYPTO_SERVICE": false,
"BUILD_OPENSSL_LIB": false,
"BUILD_CMOCKA_LIB": true
"BUILD_CMOCKA_LIB": true,
"BUILD_SQLITE_LIB": false,
"USE_PROTOBUF_MIDDLEWARE": true,
"USE_CAPTURE_SERVICE": true,
"BUILD_UUID_LIB": true,
"BUILD_PCAP_LIB": true
}
},
{
"name": "cheribsd",
"inherits": "freebsd",
"description": "CheriBSD build (alpha)",
"toolchainFile": "${sourceDir}/CMakeModules/CMakeToolchains/cheri.cmake"
},
{
"name": "cheribsd-cc",
"inherits": "freebsd",
"description": "CheriBSD Cross Compile build (alpha)",
"toolchainFile": "${sourceDir}/CMakeModules/CMakeToolchains/cheri-cross.cmake"
},
{
"name": "linux",
"inherits": "default",
Expand Down Expand Up @@ -255,6 +272,14 @@
"name": "freebsd",
"configurePreset": "freebsd"
},
{
"name": "cheribsd",
"configurePreset": "cheribsd"
},
{
"name": "cheribsd-cc",
"configurePreset": "cheribsd-cc"
},
{
"name": "linux/header",
"configurePreset": "linux/header"
Expand Down Expand Up @@ -341,6 +366,10 @@
"name": "freebsd",
"configurePreset": "freebsd"
},
{
"name": "cheribsd",
"configurePreset": "cheribsd"
},
{
"name": "openwrt",
"configurePreset": "openwrt",
Expand Down
6 changes: 4 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ if (USE_MDNS_SERVICE)
endif ()
add_subdirectory(capture)

if (BUILD_SQLHOOK)
add_library(sqlhook SHARED sqlhook.c)
target_link_libraries(sqlhook PRIVATE sockctl os allocs SQLite::SQLite3 LibUTHash::LibUTHash)
endif ()

add_library(sqlhook SHARED sqlhook.c)
target_link_libraries(sqlhook PRIVATE sockctl os allocs SQLite::SQLite3 LibUTHash::LibUTHash)

add_library(runctl runctl.c)
target_include_directories(runctl PRIVATE SQLite::SQLite3)
Expand Down
11 changes: 7 additions & 4 deletions src/runctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ int construct_ap_ctrlif(char *ctrl_interface, char *interface,

int init_context(struct app_config *app_config,
struct supervisor_context *ctx) {
const char *commands[] = {"ip", "iw", "iptables", "sysctl", NULL};
const char *commands[] = {"ip", "ifconfig", "iw", "iptables", "sysctl", NULL};

ctx->config_ifinfo_array = NULL;
ctx->hmap_bin_paths = NULL;
Expand All @@ -261,10 +261,13 @@ int init_context(struct app_config *app_config,
return -1;
}

const char *ipcmd_path = hmap_str_keychar_get(ctx->hmap_bin_paths, "ip");
char *ipcmd_path = (char *)hmap_str_keychar_get(ctx->hmap_bin_paths, "ip");
if (ipcmd_path == NULL) {
log_error("Couldn't find ip command");
return -1;
if ((ipcmd_path = (char *)hmap_str_keychar_get(ctx->hmap_bin_paths,
"ifconfig")) == NULL) {
log_error("Couldn't find ip/ifconfig commands");
return -1;
}
}

utarray_new(ctx->config_ifinfo_array, &config_ifinfo_icd);
Expand Down