From 2669c85f55aea3759093e4d56af180924c3f3271 Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Tue, 28 Nov 2023 19:52:32 +0100 Subject: [PATCH 1/6] Update configure script to more modern version This is the version taken straight from the zeek-aux repository. --- configure | 119 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 99 insertions(+), 20 deletions(-) diff --git a/configure b/configure index 3148912..929152a 100755 --- a/configure +++ b/configure @@ -14,23 +14,20 @@ if [ -e `dirname $0`/configure.plugin ]; then . `dirname $0`/configure.plugin fi -# Check for `cmake` command. -type cmake > /dev/null 2>&1 || { - echo "\ -This package requires CMake, please install it first, then you may -use this configure script to access CMake equivalent functionality.\ -" >&2; - exit 1; -} - usage() { cat 1>&2 </dev/null 2>&1; then @@ -53,8 +50,9 @@ append_cache_entry () { # set defaults builddir=build -brodist=`cd ../../.. && pwd` +zeekdist="" installroot="default" +zeek_plugin_begin_opts="" CMakeCacheEntries="" while [ $# -ne 0 ]; do @@ -68,14 +66,40 @@ while [ $# -ne 0 ]; do usage ;; - --bro-dist=*) - brodist=`cd $optarg && pwd` + --cmake=*) + CMakeCommand=$optarg + ;; + + --zeek-dist=*) + zeekdist=`cd $optarg && pwd` ;; --install-root=*) installroot=$optarg ;; + --with-binpac=*) + append_cache_entry BinPAC_ROOT_DIR PATH $optarg + binpac_root=$optarg + ;; + + --with-broker=*) + append_cache_entry BROKER_ROOT_DIR PATH $optarg + broker_root=$optarg + ;; + + --with-bifcl=*) + append_cache_entry BifCl_EXE PATH $optarg + ;; + + --enable-debug) + append_cache_entry BRO_PLUGIN_ENABLE_DEBUG BOOL true + ;; + + --disable-cpp-tests) + zeek_plugin_begin_opts="DISABLE_CPP_TESTS;$zeek_plugin_begin_opts" + ;; + *) if type plugin_option >/dev/null 2>&1; then plugin_option $1 && shift && continue; @@ -88,26 +112,81 @@ while [ $# -ne 0 ]; do shift done -if [ ! -e "$brodist/zeek-path-dev.in" ]; then - echo "Cannot determine Bro source directory, use --bro-dist=DIR." - exit 1 +if [ -z "$CMakeCommand" ]; then + # prefer cmake3 over "regular" cmake (cmake == cmake2 on RHEL) + if command -v cmake3 >/dev/null 2>&1 ; then + CMakeCommand="cmake3" + elif command -v cmake >/dev/null 2>&1 ; then + CMakeCommand="cmake" + else + echo "This plugin requires CMake, please install it first." + echo "Then you may use this script to configure the CMake build." + echo "Note: pass --cmake=PATH to use cmake in non-standard locations." + exit 1; + fi fi -append_cache_entry BRO_DIST PATH $brodist -append_cache_entry CMAKE_MODULE_PATH PATH $brodist/cmake +if [ -z "$zeekdist" ]; then + if type zeek-config >/dev/null 2>&1; then + zeek_config="zeek-config" + else + echo "Either 'zeek-config' must be in PATH or '--zeek-dist=' used" + exit 1 + fi + + append_cache_entry BRO_CONFIG_PREFIX PATH `${zeek_config} --prefix` + append_cache_entry BRO_CONFIG_INCLUDE_DIR PATH `${zeek_config} --include_dir` + append_cache_entry BRO_CONFIG_PLUGIN_DIR PATH `${zeek_config} --plugin_dir` + append_cache_entry BRO_CONFIG_LIB_DIR PATH `${zeek_config} --lib_dir` + append_cache_entry BRO_CONFIG_CMAKE_DIR PATH `${zeek_config} --cmake_dir` + append_cache_entry CMAKE_MODULE_PATH PATH `${zeek_config} --cmake_dir` + + build_type=`${zeek_config} --build_type` + + if [ "$build_type" = "debug" ]; then + append_cache_entry BRO_PLUGIN_ENABLE_DEBUG BOOL true + fi + + if [ -z "$binpac_root" ]; then + append_cache_entry BinPAC_ROOT_DIR PATH `${zeek_config} --binpac_root` + fi + + if [ -z "$broker_root" ]; then + append_cache_entry BROKER_ROOT_DIR PATH `${zeek_config} --broker_root` + fi +else + if [ ! -e "$zeekdist/zeek-path-dev.in" ]; then + echo "$zeekdist does not appear to be a valid Zeek source tree." + exit 1 + fi + + # BRO_DIST is the canonical/historical name used by plugin CMake scripts + # ZEEK_DIST doesn't serve a function at the moment, but set/provided anyway + append_cache_entry BRO_DIST PATH $zeekdist + append_cache_entry ZEEK_DIST PATH $zeekdist + append_cache_entry CMAKE_MODULE_PATH PATH $zeekdist/cmake +fi if [ "$installroot" != "default" ]; then mkdir -p $installroot append_cache_entry BRO_PLUGIN_INSTALL_ROOT PATH $installroot fi +if [ -n "$zeek_plugin_begin_opts" ]; then + append_cache_entry ZEEK_PLUGIN_BEGIN_OPTS STRING "$zeek_plugin_begin_opts" +fi + +if type plugin_addl >/dev/null 2>&1; then + plugin_addl +fi + echo "Build Directory : $builddir" -echo "Bro Source Directory : $brodist" +echo "Zeek Source Directory : $zeekdist" mkdir -p $builddir cd $builddir -cmake $CMakeCacheEntries .. +"$CMakeCommand" $CMakeCacheEntries .. echo "# This is the command used to configure this build" > config.status echo $command >> config.status From 6b00cea8b02e29faea05259b172d2ccaa627a12c Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Tue, 28 Nov 2023 19:56:16 +0100 Subject: [PATCH 2/6] Update CMakeLists.txt to required CMake version 3.15 This is needed for Zeek 6.1 and later. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7cbfec7..77bed48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.6.3) +cmake_minimum_required(VERSION 3.15) project(Plugin) From abcef5adffb3e1dc3b7ddb53c5dec4626e244a7e Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Tue, 28 Nov 2023 19:56:56 +0100 Subject: [PATCH 3/6] Update includes to use 'zeek/' prefix This has been the suggested way for plugins to do since Zeek 3.2. Closes #1 --- src/Napatech.cc | 2 +- src/Napatech.h | 4 ++-- src/Plugin.cc | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Napatech.cc b/src/Napatech.cc index 4dacce2..97f7e29 100644 --- a/src/Napatech.cc +++ b/src/Napatech.cc @@ -30,7 +30,7 @@ */ -#include "zeek-config.h" +#include #include "Napatech.h" #include "Napatech.bif.h" diff --git a/src/Napatech.h b/src/Napatech.h index 3b75419..bf6605e 100644 --- a/src/Napatech.h +++ b/src/Napatech.h @@ -41,8 +41,8 @@ extern "C" { #include } -#include "iosource/PktSrc.h" -#include "iosource/pcap/Source.h" +#include +#include #include diff --git a/src/Plugin.cc b/src/Plugin.cc index e281e9b..3c2c068 100644 --- a/src/Plugin.cc +++ b/src/Plugin.cc @@ -36,14 +36,14 @@ POSSIBILITY OF SUCH DAMAGE. #include "Plugin.h" #include "Napatech.h" #include -#include "iosource/pcap/Source.h" -#include "iosource/BPF_Program.h" -#include "iosource/Component.h" -#include "iosource/IOSource.h" -#include "iosource/Manager.h" -#include "iosource/Packet.h" -#include "iosource/PktDumper.h" -#include "iosource/PktSrc.h" +#include +#include +#include +#include +#include +#include +#include +#include namespace plugin::Zeek_Napatech { Plugin plugin; } From 2ca664355f7be3ea5691772fa5c2fa1b33f8f718 Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Tue, 28 Nov 2023 20:03:34 +0100 Subject: [PATCH 4/6] Update README to remove --bro-dist usage Generally, using `zeek-config` from an installation tree should be preferred if possible. --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9d07df1..999caba 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,17 @@ Installation Follow Napatech's instructions to install its kernel module and userspace libraries. +Ensure that `zeek-config` is found in PATH. This is used by the `configure` +script find information about the Zeek installation. + +``` +zeek-config --version +``` + +Configure, compile and install the plugin. + ``` -./configure --bro-dist= --with-napatech= && make && make install +./configure --with-napatech= && make && make install ``` If everything built and installed correctly, you should be able to verify the installation with the following command and output: From ae2d65a5ed64a618f48e4544033a9b43279e51d5 Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Tue, 28 Nov 2023 20:07:36 +0100 Subject: [PATCH 5/6] Update find_package_handle_standard_args() call Squelches the following warning: CMake Warning (dev) at /usr/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:438 (message): The package name passed to `find_package_handle_standard_args` (NAPATECH) does not match the name of the calling package (Napatech). This can lead to problems in calling code that expects `find_package` result variables (e.g., `_FOUND`) to follow a certain pattern. Call Stack (most recent call first): cmake/FindNapatech.cmake:31 (find_package_handle_standard_args) CMakeLists.txt:7 (find_package) This warning is for project developers. Use -Wno-dev to suppress it. --- CMakeLists.txt | 16 ++++++++-------- cmake/FindNapatech.cmake | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 77bed48..6ce2241 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,19 +2,19 @@ cmake_minimum_required(VERSION 3.15) project(Plugin) -include(BroPlugin) +include(ZeekPlugin) find_package(Napatech) if ( NAPATECH_FOUND ) include_directories(BEFORE ${NAPATECH_INCLUDE_DIR}) - bro_plugin_begin(Zeek Napatech) - bro_plugin_cc(src/Plugin.cc) - bro_plugin_cc(src/Napatech.cc) - bro_plugin_bif(src/Napatech.bif) - bro_plugin_link_library(${NAPATECH_LIBRARY}) - bro_plugin_dist_files(broctl/Napatech.py) - bro_plugin_end() + zeek_plugin_begin(Zeek Napatech) + zeek_plugin_cc(src/Plugin.cc) + zeek_plugin_cc(src/Napatech.cc) + zeek_plugin_bif(src/Napatech.bif) + zeek_plugin_link_library(${NAPATECH_LIBRARY}) + zeek_plugin_dist_files(zeekctl/Napatech.py) + zeek_plugin_end() message(STATUS "Napatech prefix : ${NAPATECH_ROOT_DIR}") else () message(FATAL_ERROR "Napatech library and/or headers not found.") diff --git a/cmake/FindNapatech.cmake b/cmake/FindNapatech.cmake index cfb0ee3..f0b2451 100644 --- a/cmake/FindNapatech.cmake +++ b/cmake/FindNapatech.cmake @@ -28,7 +28,7 @@ find_library(NAPATECH_LIBRARY ) include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(NAPATECH DEFAULT_MSG +find_package_handle_standard_args(Napatech DEFAULT_MSG NAPATECH_LIBRARY NAPATECH_INCLUDE_DIR ) From 30805b3158a852b5e6c08389dd97ca6783200f5e Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Thu, 30 Nov 2023 09:24:53 +0100 Subject: [PATCH 6/6] Update zkg.meta Do not use --bro-dist (or --zeek-dist), but do allow the user to configure the Napatech installation directory. --- zkg.meta | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/zkg.meta b/zkg.meta index c09dda3..5a07a92 100644 --- a/zkg.meta +++ b/zkg.meta @@ -1,8 +1,11 @@ [package] description = Packet source plugin that provides native support for NTAPI tags = packet source, plugin, napatech, ntapi -depends = +depends = zkg >=2.0 zeek >=4.0.0 plugin_dir = build/Zeek_Napatech.tgz -build_command = (./configure --bro-dist=%(bro_dist)s && make) +build_command = (./configure --with-napatech=%(napatech_root_dir)s && make) + +user_vars = + napatech_root_dir [/opt/napatech3] "Path to napatech installation"