Go to the documentation of this file.
42 #define NETMAP_WITH_LIBS
43 #include <net/netmap_user.h>
59 "Single threaded netmap mode",
62 "Workers netmap mode, each thread does all"
63 " tasks from acquisition to logging",
66 "Multi-threaded netmap mode. Packets from "
67 "each flow are assigned to a single detect "
75 static void NetmapDerefConfig(
void *conf)
97 "netmap interface %s uses obsolete '+' notation. "
98 "Using '^' instead.", ns->
iface);
101 }
else if (ns->
iface[
len-1] ==
'^') {
107 char base_name[IFNAMSIZ];
109 if (strlen(base_name) > 0 &&
110 (base_name[strlen(base_name) - 1] ==
'^' || base_name[strlen(base_name) - 1] ==
'*')) {
111 base_name[strlen(base_name) - 1] =
'\0';
116 if (strncmp(ns->
iface,
"netmap:", 7) != 0 &&
117 strncmp(ns->
iface,
"vale", 4) != 0) {
121 const char *bpf_filter = NULL;
122 if (
ConfGet(
"bpf-filter", &bpf_filter) == 1) {
123 if (strlen(bpf_filter) > 0) {
125 SCLogInfo(
"Going to use command-line provided bpf filter '%s'",
130 if (if_root == NULL && if_default == NULL) {
131 SCLogInfo(
"Unable to find netmap config for "
132 "interface \"%s\" or \"default\", using default values",
137 }
else if (if_root == NULL) {
138 if_root = if_default;
142 const char *threadsstr = NULL;
147 if (strcmp(threadsstr,
"auto") == 0) {
153 "threads: %s, resetting to 0", threadsstr);
163 if (strlen(bpf_filter) > 0) {
177 const char *tmpctype;
179 "checksum-checks", &tmpctype) == 1)
181 if (strcmp(tmpctype,
"auto") == 0) {
189 "checksum-checks for %s", iface);
193 const char *copymodestr;
195 "copy-mode", ©modestr) == 1)
197 if (strcmp(copymodestr,
"ips") == 0) {
199 }
else if (strcmp(copymodestr,
"tap") == 0) {
203 "(valid are tap, ips)");
237 static void *ParseNetmapConfig(
const char *iface_name)
241 const char *out_iface = NULL;
243 if (iface_name == NULL) {
259 if (netmap_node == NULL) {
260 SCLogInfo(
"Unable to find netmap config using default value");
267 ParseNetmapSettings(&aconf->
in, aconf->
iface_name, if_root, if_default);
270 if (netmap_node != NULL &&
273 if (strlen(out_iface) > 0) {
275 ParseNetmapSettings(&aconf->
out, out_iface, if_root, if_default);
284 ring_count == 1 ?
"" :
"s");
287 ring_count == 1 ?
"" :
"s");
290 for (
int i = 0; i < ring_count; i++) {
291 char live_buf[32] = { 0 };
292 snprintf(live_buf,
sizeof(live_buf),
"netmap%d", i);
298 char base_name[
sizeof(aconf->
in.
iface)];
302 base_name[strlen(base_name) - 1] =
'\0';
321 static int NetmapConfigGeThreadsCount(
void *conf)
339 if (netmap_node == NULL) {
345 for (ldev = 0; ldev < nlive; ldev++) {
347 if (live_dev == NULL) {
351 const char *copymodestr = NULL;
354 if (if_root == NULL) {
355 if (if_default == NULL) {
359 if_root = if_default;
363 if (strcmp(copymodestr,
"ips") == 0) {
373 if (has_ids && has_ips) {
374 SCLogInfo(
"Netmap mode using IPS and IDS mode");
375 for (ldev = 0; ldev < nlive; ldev++) {
377 if (live_dev == NULL) {
382 const char *copymodestr = NULL;
384 if (if_root == NULL) {
385 if (if_default == NULL) {
389 if_root = if_default;
393 (strcmp(copymodestr,
"ips") == 0))) {
395 "Netmap IPS mode used and interface '%s' is in IDS or TAP mode. "
396 "Sniffing '%s' but expect bad result as stream-inline is activated.",
405 typedef enum { NETMAP_AUTOFP, NETMAP_WORKERS, NETMAP_SINGLE } NetmapRunMode_t;
407 static int NetmapRunModeInit(NetmapRunMode_t runmode)
414 const char *live_dev = NULL;
415 (void)
ConfGet(
"netmap.live-interface", &live_dev);
434 runmode == NETMAP_AUTOFP ?
"autofp"
435 : runmode == NETMAP_WORKERS ?
"workers" :
"single");
439 runmode == NETMAP_AUTOFP ?
"autofp" : runmode == NETMAP_WORKERS ?
"workers" :
"single");
446 return NetmapRunModeInit(NETMAP_AUTOFP);
454 return NetmapRunModeInit(NETMAP_SINGLE);
465 return NetmapRunModeInit(NETMAP_WORKERS);
497 #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)
int GetIfaceRSSQueuesNum(const char *pcap_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.
void LiveDeviceHasNoStats()
#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)
void RunModeInitialize(void)
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.
@ 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 *)
LiveDevice * LiveGetDevice(const char *name)
Get a pointer to the device at idx.
ConfNode * ConfFindDeviceConfig(ConfNode *node, const char *iface)
Find the configuration node for a specific device.
int ConfGetChildValueWithDefault(const ConfNode *base, const ConfNode *dflt, const char *name, const char **vptr)
@ SC_ERR_INVALID_ARGUMENT
#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.
void TimeModeSetLive(void)
void RunModeRegisterNewRunMode(enum RunModes runmode, const char *name, const char *description, int(*RunModeFunc)(void))
Registers a new runmode.
const char * LiveGetDeviceName(int number)
Get a pointer to the device name at idx.
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
#define FatalError(x,...)
#define SC_ATOMIC_RESET(name)
wrapper for reinitializing an atomic variable.
const char * RunModeNetmapGetDefaultMode(void)
#define SCLogWarning(err_code,...)
Macro used to log WARNING 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)
@ SC_WARN_OPTION_OBSOLETE
int RunModeIdsNetmapAutoFp(void)
int LiveGetDeviceCount(void)
Get the number of registered devices.
int NetmapRunModeIsIPS(void)