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) {
84 const char *copymodestr = NULL;
87 if (if_root == NULL) {
88 if (if_default == NULL) {
96 if (strcmp(copymodestr,
"ips") == 0) {
106 if (has_ids && has_ips) {
107 SCLogWarning(
"Netmap using both IPS and TAP/IDS mode, this will not be "
108 "allowed in Suricata 8 due to undefined behavior. See ticket #5588.");
109 for (ldev = 0; ldev < nlive; ldev++) {
111 if (live_dev == NULL) {
116 const char *copymodestr = NULL;
118 if (if_root == NULL) {
119 if (if_default == NULL) {
123 if_root = if_default;
128 (strcmp(copymodestr,
"ips") == 0))) {
129 SCLogError(
"Netmap IPS mode used and interface '%s' is in IDS or TAP mode. "
130 "Sniffing '%s' but expect bad result as stream-inline is activated.",
139 static void NetmapRunModeEnableIPS(
void)
141 if (NetmapRunModeIsIPS()) {
152 "Workers netmap mode, each thread does all"
153 " tasks from acquisition to logging",
156 "Multi-threaded netmap mode. Packets from "
157 "each flow are assigned to a single detect "
165 static void NetmapDerefConfig(
void *conf)
186 SCLogWarning(
"%s: interface uses obsolete '+' notation. Using '^' instead", ns->
iface);
189 }
else if (ns->
iface[
len-1] ==
'^') {
195 char base_name[IFNAMSIZ];
197 if (strlen(base_name) > 0 &&
198 (base_name[strlen(base_name) - 1] ==
'^' || base_name[strlen(base_name) - 1] ==
'*')) {
199 base_name[strlen(base_name) - 1] =
'\0';
204 if (strncmp(ns->
iface,
"netmap:", 7) != 0 &&
205 strncmp(ns->
iface,
"vale", 4) != 0) {
209 if (if_root == NULL && if_default == NULL) {
210 SCLogInfo(
"%s: unable to find netmap config for interface \"%s\" or \"default\", using "
216 }
else if (if_root == NULL) {
217 if_root = if_default;
221 const char *threadsstr = NULL;
226 if (strcmp(threadsstr,
"auto") == 0) {
231 SCLogWarning(
"%s: invalid config value for threads: %s, resetting to 0", iface,
247 const char *tmpctype;
249 "checksum-checks", &tmpctype) == 1)
251 if (strcmp(tmpctype,
"auto") == 0) {
258 SCLogWarning(
"%s: invalid value for checksum-checks '%s'", iface, tmpctype);
262 const char *copymodestr;
264 "copy-mode", ©modestr) == 1)
266 if (strcmp(copymodestr,
"ips") == 0) {
268 }
else if (strcmp(copymodestr,
"tap") == 0) {
271 SCLogWarning(
"%s: invalid copy-mode %s (valid are tap, ips)", iface, copymodestr);
305 static void *ParseNetmapConfig(
const char *iface_name)
309 const char *out_iface = NULL;
311 if (iface_name == NULL) {
327 if (netmap_node == NULL) {
328 SCLogInfo(
"%s: unable to find netmap config using default value", iface_name);
335 ParseNetmapSettings(&aconf->
in, aconf->
iface_name, if_root, if_default);
338 if (netmap_node != NULL &&
341 if (strlen(out_iface) > 0) {
343 ParseNetmapSettings(&aconf->
out, out_iface, if_root, if_default);
352 ring_count == 1 ?
"" :
"s");
355 ring_count == 1 ?
"" :
"s");
358 for (
int i = 0; i < ring_count; i++) {
359 char live_buf[32] = { 0 };
360 snprintf(live_buf,
sizeof(live_buf),
"netmap%d", i);
366 char base_name[
sizeof(aconf->
in.
iface)];
370 base_name[strlen(base_name) - 1] =
'\0';
390 static int NetmapConfigGeThreadsCount(
void *conf)
396 typedef enum { NETMAP_AUTOFP, NETMAP_WORKERS, NETMAP_SINGLE } NetmapRunMode_t;
398 static int NetmapRunModeInit(NetmapRunMode_t runmode)
404 const char *live_dev = NULL;
405 (void)
ConfGet(
"netmap.live-interface", &live_dev);
407 const char *runmode_str =
"unknown";
411 runmode_str =
"autofp";
416 runmode_str =
"workers";
421 runmode_str =
"single";
427 FatalError(
"Unable to start runmode %s", runmode_str);
437 return NetmapRunModeInit(NETMAP_AUTOFP);
445 return NetmapRunModeInit(NETMAP_SINGLE);
456 return NetmapRunModeInit(NETMAP_WORKERS);
488 #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
void RunModeRegisterNewRunMode(enum RunModes runmode, const char *name, const char *description, int(*RunModeFunc)(void), void(*RunModeIsIPSEnabled)(void))
Registers a new runmode.
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 *)
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
uint16_t max_pending_packets
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 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)
int RunModeIdsNetmapAutoFp(void)
int LiveGetDeviceCount(void)
Get the number of registered devices.