Go to the documentation of this file.
44 #define NETMAP_WITH_LIBS
45 #include <net/netmap_user.h>
60 static int NetmapRunModeIsIPS(
void)
72 if (netmap_node == NULL) {
78 for (ldev = 0; ldev < nlive; ldev++) {
80 if (live_dev == NULL) {
86 if (if_root == NULL) {
87 if (if_default == NULL) {
94 const char *copymodestr = NULL;
95 const char *copyifacestr = NULL;
98 if (strcmp(copymodestr,
"ips") == 0) {
108 if (has_ids && has_ips) {
109 SCLogError(
"using both IPS and TAP/IDS mode is not allowed due to undefined behavior. See "
117 static int NetmapRunModeEnableIPS(
void)
119 int r = NetmapRunModeIsIPS();
132 "Workers netmap mode, each thread does all"
133 " tasks from acquisition to logging",
136 "Multi-threaded netmap mode. Packets from "
137 "each flow are assigned to a single detect "
144 static void NetmapDerefConfig(
void *conf)
165 SCLogWarning(
"%s: interface uses obsolete '+' notation. Using '^' instead", ns->
iface);
168 }
else if (ns->
iface[
len-1] ==
'^') {
174 char base_name[IFNAMSIZ];
176 if (strlen(base_name) > 0 &&
177 (base_name[strlen(base_name) - 1] ==
'^' || base_name[strlen(base_name) - 1] ==
'*')) {
178 base_name[strlen(base_name) - 1] =
'\0';
183 if (strncmp(ns->
iface,
"netmap:", 7) != 0 &&
184 strncmp(ns->
iface,
"vale", 4) != 0) {
188 if (if_root == NULL && if_default == NULL) {
189 SCLogInfo(
"%s: unable to find netmap config for interface \"%s\" or \"default\", using "
195 }
else if (if_root == NULL) {
196 if_root = if_default;
200 const char *threadsstr = NULL;
205 if (strcmp(threadsstr,
"auto") == 0) {
210 SCLogWarning(
"%s: invalid config value for threads: %s, resetting to 0", iface,
226 const char *tmpctype;
228 "checksum-checks", &tmpctype) == 1)
230 if (strcmp(tmpctype,
"auto") == 0) {
237 SCLogWarning(
"%s: invalid value for checksum-checks '%s'", iface, tmpctype);
241 const char *copymodestr;
243 "copy-mode", ©modestr) == 1)
245 if (strcmp(copymodestr,
"ips") == 0) {
247 }
else if (strcmp(copymodestr,
"tap") == 0) {
250 SCLogWarning(
"%s: invalid copy-mode %s (valid are tap, ips)", iface, copymodestr);
284 static void *ParseNetmapConfig(
const char *iface_name)
288 const char *out_iface = NULL;
290 if (iface_name == NULL) {
306 if (netmap_node == NULL) {
307 SCLogInfo(
"%s: unable to find netmap config using default value", iface_name);
314 ParseNetmapSettings(&aconf->
in, aconf->
iface_name, if_root, if_default);
317 if (netmap_node != NULL &&
320 if (strlen(out_iface) > 0) {
322 ParseNetmapSettings(&aconf->
out, out_iface, if_root, if_default);
333 ring_count == 1 ?
"" :
"s");
336 ring_count == 1 ?
"" :
"s");
339 for (
int i = 0; i < ring_count; i++) {
340 char live_buf[32] = { 0 };
341 snprintf(live_buf,
sizeof(live_buf),
"netmap%d", i);
347 char base_name[
sizeof(aconf->
in.
iface)];
351 base_name[strlen(base_name) - 1] =
'\0';
371 static int NetmapConfigGeThreadsCount(
void *conf)
377 typedef enum { NETMAP_AUTOFP, NETMAP_WORKERS, NETMAP_SINGLE } NetmapRunMode_t;
379 static int NetmapRunModeInit(NetmapRunMode_t runmode)
385 const char *live_dev = NULL;
386 (void)
ConfGet(
"netmap.live-interface", &live_dev);
388 const char *runmode_str =
"unknown";
392 runmode_str =
"autofp";
397 runmode_str =
"workers";
402 runmode_str =
"single";
408 FatalError(
"Unable to start runmode %s", runmode_str);
418 return NetmapRunModeInit(NETMAP_AUTOFP);
426 return NetmapRunModeInit(NETMAP_SINGLE);
437 return NetmapRunModeInit(NETMAP_WORKERS);
469 #endif // #ifdef HAVE_NETMAP
const char * thread_name_workers
int RunModeIdsNetmapSingle(void)
Single thread version of the netmap processing.
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)
#define SC_ATOMIC_INIT(name)
wrapper for initializing an atomic variable.
ChecksumValidationMode checksum_mode
int ConfGetChildValueBoolWithDefault(const ConfNode *base, const ConfNode *dflt, const char *name, int *val)
ConfNode * ConfGetNode(const char *name)
Get a ConfNode by name.
#define SC_ATOMIC_ADD(name, val)
add a value to our atomic variable
int StringParseUint16(uint16_t *res, int base, size_t len, const char *str)
const char * thread_name_autofp
ConfNode * ConfNodeLookupKeyValue(const ConfNode *base, const char *key, const char *value)
Lookup for a key value under a specific node.
void LiveDeviceHasNoStats(void)
@ CHECKSUM_VALIDATION_DISABLE
char iface[NETMAP_IFACE_NAME_LENGTH]
const char * thread_name_single
int ConfValIsTrue(const char *val)
Check if a value is true.
int RunModeIdsNetmapWorkers(void)
Workers version of the netmap processing.
size_t strlcpy(char *dst, const char *src, size_t siz)
int RunModeSetLiveCaptureAutoFp(ConfigIfaceParserFunc ConfigParser, ConfigIfaceThreadsCountFunc ModThreadsCount, const char *recv_mod_name, const char *decode_mod_name, const char *thread_name, const char *live_dev)
int NetmapGetRSSCount(const char *ifname)
@ CHECKSUM_VALIDATION_ENABLE
int ConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
@ CHECKSUM_VALIDATION_AUTO
void(* DerefFunc)(void *)
void RunModeRegisterNewRunMode(enum RunModes runmode, const char *name, const char *description, int(*RunModeFunc)(void), int(*RunModeIsIPSEnabled)(void))
Registers a new runmode.
LiveDevice * LiveGetDevice(const char *name)
Get a pointer to the device at idx.
int GetIfaceRSSQueuesNum(const char *dev)
ConfNode * ConfFindDeviceConfig(ConfNode *node, const char *iface)
Find the configuration node for a specific device.
void EngineModeSetIPS(void)
int ConfGetChildValueWithDefault(const ConfNode *base, const ConfNode *dflt, const char *name, const char **vptr)
#define SCLogWarning(...)
Macro used to log WARNING messages.
#define SC_ATOMIC_SUB(name, val)
sub a value from our atomic variable
int GetIfaceOffloading(const char *dev, int csum, int other)
output offloading status of the link
int DisableIfaceOffloading(LiveDevice *dev, int csum, int other)
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
int ConfGetChildValue(const ConfNode *base, const char *name, const char **vptr)
void TimeModeSetLive(void)
void ConfSetBPFFilter(ConfNode *if_root, ConfNode *if_default, const char *iface, const char **bpf_filter)
const char * LiveGetDeviceName(int number)
Get a pointer to the device name at idx.
#define SC_ATOMIC_RESET(name)
wrapper for reinitializing an atomic variable.
const char * RunModeNetmapGetDefaultMode(void)
#define SCLogError(...)
Macro used to log ERROR messages.
void RunModeIdsNetmapRegister(void)
char iface_name[NETMAP_IFACE_NAME_LENGTH]
int ConfValIsFalse(const char *val)
Check if a value is false.
int RunModeSetLiveCaptureSingle(ConfigIfaceParserFunc ConfigParser, ConfigIfaceThreadsCountFunc ModThreadsCount, const char *recv_mod_name, const char *decode_mod_name, const char *thread_name, const char *live_dev)
uint32_t max_pending_packets
int RunModeIdsNetmapAutoFp(void)
int LiveGetDeviceCount(void)
Get the number of registered devices.