Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Napatech bypass v1.09 #4478

Closed
wants to merge 2 commits into from
Closed
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
19 changes: 17 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1915,11 +1915,15 @@
fi
fi

# Napatech - Using the 3GD API
# Napatech - Using the 3GD API
AC_ARG_ENABLE(napatech,
AS_HELP_STRING([--enable-napatech],[Enabled Napatech Devices]),
[ enable_napatech=$enableval ],
[ enable_napatech=no])
AC_ARG_ENABLE(napatech_bypass,
AS_HELP_STRING([--disable-napatech-bypass],[Disable Bypass feature on Napatech cards]),
[ napatech_bypass=$enableval ],
[ napatech_bypass=yes])
AC_ARG_WITH(napatech_includes,
[ --with-napatech-includes=DIR napatech include directory],
[with_napatech_includes="$withval"],[with_napatech_includes="/opt/napatech3/include"])
Expand Down Expand Up @@ -1957,6 +1961,17 @@
fi

AC_DEFINE([HAVE_NAPATECH],[1],(Napatech capture card support))
if test "$napatech_bypass" = "yes"; then
AC_CHECK_LIB(ntapi, NT_FlowOpenAttrInit,NTFLOW="yes",NTFLOW="no")
if test "$NTFLOW" = "yes"; then
echo " Napatech Flow Processing is Enabled (--disable-napatech-bypass if not needed)"
AC_DEFINE([NAPATECH_ENABLE_BYPASS],[1],(Napatech flowdirector support))
else
echo "Napatech Flow Processing is not available"
fi
else
echo "Napatech Flow Processing is Disabled."
fi
fi

# liblua
Expand Down Expand Up @@ -2493,7 +2508,7 @@ fi
if test "${enable_ebpf}" = "yes" || test "${enable_unittests}" = "yes"; then
AC_DEFINE([CAPTURE_OFFLOAD_MANAGER], [1],[Building flow bypass manager code])
fi
if test "${enable_ebpf}" = "yes" || test "${enable_nfqueue}" = "yes" || test "${enable_pfring}" = "yes" || test "${enable_unittests}" = "yes"; then
if test "${enable_ebpf}" = "yes" || test "${enable_nfqueue}" = "yes" || test "${enable_pfring}" = "yes" || test "${enable_napatech}" = "yes" || test "${enable_unittests}" = "yes"; then
AC_DEFINE([CAPTURE_OFFLOAD], [1],[Building flow capture bypass code])
fi

Expand Down
256 changes: 215 additions & 41 deletions doc/userguide/capture-hardware/napatech.rst

Large diffs are not rendered by default.

51 changes: 48 additions & 3 deletions src/runmode-napatech.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@
#define NT_RUNMODE_AUTOFP 1
#define NT_RUNMODE_WORKERS 2

static const char *default_mode = "workers";

#ifdef HAVE_NAPATECH

#define MAX_STREAMS 256
static uint16_t num_configured_streams = 0;
static uint16_t first_stream = 0xffff;
static uint16_t last_stream = 0xffff;
static int auto_config = 0;
static int use_hw_bypass = 0;

uint16_t NapatechGetNumConfiguredStreams(void)
{
Expand All @@ -68,11 +71,16 @@ bool NapatechIsAutoConfigEnabled(void)
return (auto_config != 0);
}

bool NapatechUseHWBypass(void)
{
return (use_hw_bypass != 0);
}

#endif

const char *RunModeNapatechGetDefaultMode(void)
{
return "workers";
return default_mode;
}

void RunModeNapatechRegister(void)
Expand Down Expand Up @@ -103,8 +111,25 @@ static int NapatechRegisterDeviceStreams(void)
SCLogInfo("napatech.auto-config not found in config file. Defaulting to disabled.");
}

if (ConfGetBool("napatech.hardware-bypass", &use_hw_bypass) == 0) {
SCLogInfo("napatech.hardware-bypass not found in config file. Defaulting to disabled.");
}

/* use_all_streams uses existing streams created prior to starting Suricata. auto_config
* automatically creates streams. Therefore, these two options are mutually exclusive.
*/
if (use_all_streams && auto_config) {
SCLogError(SC_ERR_RUNMODE, "auto-config cannot be used with use-all-streams.");
SCLogError(SC_ERR_RUNMODE, "napatech.auto-config cannot be used in configuration file at the same time as napatech.use-all-streams.");
exit(EXIT_FAILURE);
}

/* to use hardware_bypass we need to configure the streams to be consistent.
* with the rest of the configuration. Therefore auto_config is not a valid
* option.
*/
if (use_hw_bypass && auto_config == 0) {
SCLogError(SC_ERR_RUNMODE, "napatech auto-config must be enabled when using napatech.use_hw_bypass.");
exit(EXIT_FAILURE);
}

/* Get the stream ID's either from the conf or by querying Napatech */
Expand All @@ -129,7 +154,9 @@ static int NapatechRegisterDeviceStreams(void)
"Registering Napatech device: %s - active stream found.",
plive_dev_buf);
SCLogError(SC_ERR_NAPATECH_STREAMS_REGISTER_FAILED,
"Delete the stream or disable auto-config before running.");
"run /opt/napatech3/bin/ntpl -e \"delete=all\" to delete existing stream");
SCLogError(SC_ERR_NAPATECH_STREAMS_REGISTER_FAILED,
"or disable auto-config in the conf file before running.");
exit(EXIT_FAILURE);
}
} else {
Expand Down Expand Up @@ -218,6 +245,24 @@ static int NapatechInit(int runmode)
SCLogInfo("Host Buffer Allowance: %d", (int) conf->hba);
}

if (use_hw_bypass) {
#ifdef NAPATECH_ENABLE_BYPASS
if (NapatechInitFlowStreams()) {
SCLogInfo("Napatech Hardware Bypass is supported and enabled.");
} else {
SCLogError(SC_ERR_NAPATECH_PARSE_CONFIG,
"Napatech Hardware Bypass requested in conf but is not supported by the hardware.");
exit(EXIT_FAILURE);
}
#else
SCLogError(SC_ERR_NAPATECH_PARSE_CONFIG,
"Napatech Hardware Bypass requested in conf but is not enabled by the software.");
exit(EXIT_FAILURE);
#endif
} else {
SCLogInfo("Hardware Bypass is disabled in the conf file.");
}

/* Start a thread to process the statistics */
NapatechStartStats();

Expand Down
7 changes: 2 additions & 5 deletions src/runmode-napatech.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
#ifdef HAVE_NAPATECH
#include "util-napatech.h"
#include <nt.h>


#endif
#endif /* HAVE_NAPATECH */

int RunModeNapatechAutoFp(void);
int RunModeNapatechWorkers(void);
Expand All @@ -41,9 +39,8 @@ const char *RunModeNapatechGetDefaultMode(void);
uint16_t NapatechGetNumConfiguredStreams(void);
uint16_t NapatechGetNumFirstStream(void);
uint16_t NapatechGetNumLastStream(void);

bool NapatechIsAutoConfigEnabled(void);

bool NapatechUseHWBypass(void);


#endif /* __RUNMODE_NAPATECH_H__ */
Loading