Go to the documentation of this file.
41 #define NT_RUNMODE_AUTOFP 1
42 #define NT_RUNMODE_WORKERS 2
44 static const char *default_mode =
"workers";
48 #define MAX_STREAMS 256
49 static uint16_t num_configured_streams = 0;
50 static uint16_t first_stream = 0xffff;
51 static uint16_t last_stream = 0xffff;
52 static int auto_config = 0;
53 static int use_hw_bypass = 0;
57 return num_configured_streams;
72 return (auto_config != 0);
77 return (use_hw_bypass != 0);
91 "Workers Napatech mode, each thread does all"
92 " tasks from acquisition to logging",
101 static int NapatechRegisterDeviceStreams(
void)
106 if (
ConfGetBool(
"napatech.use-all-streams", &use_all_streams) == 0) {
107 SCLogInfo(
"Could not find napatech.use-all-streams in config file. Defaulting to \"no\".");
111 if (
ConfGetBool(
"napatech.auto-config", &auto_config) == 0) {
112 SCLogInfo(
"napatech.auto-config not found in config file. Defaulting to disabled.");
115 if (
ConfGetBool(
"napatech.hardware-bypass", &use_hw_bypass) == 0) {
116 SCLogInfo(
"napatech.hardware-bypass not found in config file. Defaulting to disabled.");
122 if (use_all_streams && auto_config) {
124 "napatech.auto-config cannot be used in configuration file at the same time as napatech.use-all-streams.");
131 if (use_hw_bypass && auto_config == 0) {
133 "napatech auto-config must be enabled when using napatech.use_hw_bypass.");
140 num_configured_streams = stream_cnt;
141 SCLogDebug(
"Configuring %d Napatech Streams...", stream_cnt);
143 for (uint16_t inst = 0; inst < stream_cnt; ++inst) {
144 char *plive_dev_buf =
SCCalloc(1, 9);
145 if (
unlikely(plive_dev_buf == NULL)) {
147 "Failed to allocate memory for NAPATECH stream counter.");
149 snprintf(plive_dev_buf, 9,
"nt%d",
stream_config[inst].stream_id);
154 "Registering Napatech device: %s - active stream found.",
157 "run /opt/napatech3/bin/ntpl -e \"delete=all\" to delete existing stream");
159 "or disable auto-config in the conf file before running.");
162 SCLogInfo(
"Registering Napatech device: %s - active stream%sfound.",
163 plive_dev_buf,
stream_config[inst].is_active ?
" " :
" NOT ");
167 if (first_stream == 0xffff) {
180 static void *NapatechConfigParser(
const char *device)
183 int dev_len = strlen(device);
184 if (dev_len < 3 || dev_len > 5) {
186 "Could not parse config for device: %s - invalid length", device);
193 "Failed to allocate memory for NAPATECH device name.");
211 "Napatech Host Buffer Allocation (hba) will be deprecated in Suricata v7.0.");
213 return (
void *) conf;
216 static int NapatechGetThreadsCount(
void *conf
__attribute__((unused)))
223 static int NapatechInit(
int runmode)
231 if ((status = NT_Init(NTAPI_VERSION)) != NT_SUCCESS) {
236 status = NapatechRegisterDeviceStreams();
237 if (status < 0 || num_configured_streams <= 0) {
239 "Unable to find existing Napatech Streams");
246 "Failed to allocate memory for NAPATECH device.");
250 SCLogInfo(
"Host Buffer Allowance: %d", (
int) conf->
hba);
254 #ifdef NAPATECH_ENABLE_BYPASS
255 if (NapatechVerifyBypassSupport()) {
256 SCLogInfo(
"Napatech Hardware Bypass is supported and enabled.");
259 "Napatech Hardware Bypass requested in conf but is not supported by the hardware.");
263 "Napatech Hardware Bypass requested in conf but is not enabled by the software.");
266 SCLogInfo(
"Hardware Bypass is disabled in the conf file.");
275 NapatechGetThreadsCount,
276 "NapatechStream",
"NapatechDecode",
const char * thread_name_workers
int ConfGetInt(const char *name, intmax_t *val)
Retrieve a configuration value as an integer.
int RunModeNapatechAutoFp(void)
int LiveRegisterDevice(const char *dev)
Add a pcap device for monitoring and create structure.
int RunModeSetLiveCaptureWorkers(ConfigIfaceParserFunc ConfigParser, ConfigIfaceThreadsCountFunc ModThreadsCount, const char *recv_mod_name, const char *decode_mod_name, const char *thread_name, const char *live_dev)
@ SC_ERR_NAPATECH_INIT_FAILED
int ConfGetBool(const char *name, int *val)
Retrieve a configuration value as an boolen.
void LiveDeviceHasNoStats()
int StringParseUint16(uint16_t *res, int base, size_t len, const char *str)
void RunModeInitialize(void)
bool NapatechIsAutoConfigEnabled(void)
TcpStreamCnf stream_config
enum @24 __attribute__
DNP3 application header.
int NapatechGetStreamConfig(NapatechStreamConfig stream_config[])
Reads and parses the stream configuration defined in the config file.
#define NAPATECH_ERROR(err_type, status)
@ SC_ERR_NAPATECH_PARSE_CONFIG
uint16_t NapatechGetNumConfiguredStreams(void)
#define NT_RUNMODE_AUTOFP
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
void TimeModeSetLive(void)
const char * RunModeNapatechGetDefaultMode(void)
int RunModeNapatechWorkers(void)
void RunModeRegisterNewRunMode(enum RunModes runmode, const char *name, const char *description, int(*RunModeFunc)(void))
Registers a new runmode.
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
void NapatechStartStats(void)
#define FatalError(x,...)
uint16_t NapatechGetNumFirstStream(void)
bool NapatechUseHWBypass(void)
@ SC_ERR_NAPATECH_STREAMS_REGISTER_FAILED
#define NT_RUNMODE_WORKERS
uint16_t NapatechGetNumLastStream(void)
#define SCLogWarning(err_code,...)
Macro used to log WARNING messages.
void RunModeNapatechRegister(void)