Go to the documentation of this file.
32 #define SC_PCAP_DONT_INCLUDE_PCAP_H 1
61 #include <linux/if_xdp.h>
62 #include <linux/if_link.h>
76 "Workers af-xdp mode, each thread does all"
77 " tasks from acquisition to logging",
83 #define DEFAULT_BUSY_POLL_TIME 20
84 #define DEFAULT_BUSY_POLL_BUDGET 64
85 #define DEFAULT_GRO_FLUSH_TIMEOUT 2000000
86 #define DEFAULT_NAPI_HARD_IRQS 2
88 static void AFXDPDerefConfig(
void *conf)
102 if (active_runmode && !strcmp(
"single", active_runmode)) {
107 if (entry_str == NULL) {
108 SCLogError(
"Number of threads for interface \"%s\" not specified", aconf->
iface);
114 if (strcmp(entry_str,
"auto") == 0) {
119 aconf->
threads = (nr_cores <= nr_queues) ? nr_cores : nr_queues;
120 const char *sys_type = nr_cores <= nr_queues ?
"cores" :
"queues";
127 SCLogError(
"Threads entry for interface %s contain non-numerical characters - \"%s\"",
128 aconf->
iface, entry_str);
133 SCLogError(
"Interface %s has a negative number of threads", aconf->
iface);
137 if (aconf->
threads > nr_queues) {
139 "Selected threads greater than configured queues, using: %d thread(s)", nr_queues);
156 static void *ParseAFXDPConfig(
const char *iface)
158 const char *confstr = NULL;
163 intmax_t conf_val_int = 0;
183 aconf->
mode = XDP_FLAGS_UPDATE_IF_NOEXIST;
190 if (af_xdp_node == NULL) {
191 SCLogInfo(
"unable to find af-xdp config using default values");
198 if (if_root == NULL && if_default == NULL) {
199 SCLogInfo(
"unable to find af-xdp config for "
200 "interface \"%s\" or \"default\", using default values",
206 if (if_root == NULL) {
207 if_root = if_default;
214 if (ConfigSetThreads(aconf, confstr) !=
TM_ECODE_OK) {
232 if (strncasecmp(confstr,
"drv", 3) == 0) {
233 aconf->
mode |= XDP_FLAGS_DRV_MODE;
234 }
else if (strncasecmp(confstr,
"skb", 3) == 0) {
235 aconf->
mode |= XDP_FLAGS_SKB_MODE;
236 }
else if (strncasecmp(confstr,
"none", 4) == 0) {
238 SCLogWarning(
"Incorrect af-xdp xdp-mode setting, default (none) shall be applied");
244 if (strncasecmp(confstr,
"zero", 4) == 0) {
246 }
else if (strncasecmp(confstr,
"copy", 4) == 0) {
248 }
else if (strncasecmp(confstr,
"none", 4) == 0) {
250 SCLogWarning(
"Incorrect af-xdp copy-mode setting, default (none) shall be applied");
256 if (strncasecmp(confstr,
"yes", 3) == 0) {
277 if_root, if_default,
"busy-poll-budget", &conf_val_int) == 1) {
285 if_root, if_default,
"gro-flush-timeout", &conf_val_int) == 1) {
290 if_root, if_default,
"napi-defer-hard-irq", &conf_val_int) == 1) {
299 SCLogWarning(
"Using AF_XDP with offloading activated leads to capture problems");
308 static int AFXDPConfigGetThreadsCount(
void *conf)
328 const char *live_dev = NULL;
332 (void)
ConfGet(
"af-xdp.live-interface", &live_dev);
335 FatalError(
"Unable to init AF_XDP queue protection.");
344 SCLogDebug(
"RunModeIdsAFXDPSingle initialised");
362 const char *live_dev = NULL;
366 (void)
ConfGet(
"af-xdp.live-interface", &live_dev);
369 FatalError(
"Unable to init AF_XDP queue protection.");
378 SCLogDebug(
"RunModeIdsAFXDPWorkers initialised");
const char * thread_name_workers
int RunModeSetLiveCaptureWorkers(ConfigIfaceParserFunc ConfigParser, ConfigIfaceThreadsCountFunc ModThreadsCount, const char *recv_mod_name, const char *decode_mod_name, const char *thread_name, const char *live_dev)
char iface[AFXDP_IFACE_NAME_LENGTH]
int ConfGetChildValueBoolWithDefault(const ConfNode *base, const ConfNode *dflt, const char *name, int *val)
uint32_t gro_flush_timeout
void(* DerefFunc)(void *)
ConfNode * ConfGetNode(const char *name)
Get a ConfNode by name.
#define SC_ATOMIC_ADD(name, val)
add a value to our atomic variable
char * RunmodeGetActive(void)
int StringParseInt32(int32_t *res, int base, size_t len, const char *str)
int ConfGetChildValueIntWithDefault(const ConfNode *base, const ConfNode *dflt, const char *name, intmax_t *val)
const char * RunModeAFXDPGetDefaultMode(void)
const char * thread_name_single
uint32_t napi_defer_hard_irqs
TmEcode AFXDPQueueProtectionInit(void)
size_t strlcpy(char *dst, const char *src, size_t siz)
int ConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
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.
uint32_t busy_poll_budget
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.
void TimeModeSetLive(void)
void RunModeIdsAFXDPRegister(void)
int RunModeIdsAFXDPWorkers(void)
Workers version of the AF_XDP processing.
#define SC_ATOMIC_RESET(name)
wrapper for reinitializing an atomic variable.
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
#define SCLogError(...)
Macro used to log ERROR messages.
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 RunModeIdsAFXDPSingle(void)
Single thread version of the AF_XDP processing.
uint16_t UtilCpuGetNumProcessorsOnline(void)
Get the number of cpus online in the system.