diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e68f8e31..d0b4e20d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/CMakeModules/CMakeToolchains/cheri-cross.cmake b/CMakeModules/CMakeToolchains/cheri-cross.cmake new file mode 100644 index 000000000..64198156c --- /dev/null +++ b/CMakeModules/CMakeToolchains/cheri-cross.cmake @@ -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) diff --git a/CMakeModules/CMakeToolchains/cheri.cmake b/CMakeModules/CMakeToolchains/cheri.cmake new file mode 100644 index 000000000..747076ed2 --- /dev/null +++ b/CMakeModules/CMakeToolchains/cheri.cmake @@ -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") diff --git a/CMakePresets.json b/CMakePresets.json index f947c67b5..d8f8e037f 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -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", @@ -255,6 +272,14 @@ "name": "freebsd", "configurePreset": "freebsd" }, + { + "name": "cheribsd", + "configurePreset": "cheribsd" + }, + { + "name": "cheribsd-cc", + "configurePreset": "cheribsd-cc" + }, { "name": "linux/header", "configurePreset": "linux/header" @@ -341,6 +366,10 @@ "name": "freebsd", "configurePreset": "freebsd" }, + { + "name": "cheribsd", + "configurePreset": "cheribsd" + }, { "name": "openwrt", "configurePreset": "openwrt", diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6194e5aba..fc8e4a643 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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) diff --git a/src/runctl.c b/src/runctl.c index df7954b9b..cc6f2da17 100644 --- a/src/runctl.c +++ b/src/runctl.c @@ -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; @@ -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);