Go to the documentation of this file.
32 #define PCAP_DONT_INCLUDE_PCAP_BPF_H 1
33 #define SC_PCAP_DONT_INCLUDE_PCAP_H 1
62 #include <linux/if_xdp.h>
63 #include <linux/if_link.h>
77 "Workers af-xdp mode, each thread does all"
78 " tasks from acquisition to logging",
86 #define DEFAULT_BUSY_POLL_TIME 20
87 #define DEFAULT_BUSY_POLL_BUDGET 64
88 #define DEFAULT_GRO_FLUSH_TIMEOUT 2000000
89 #define DEFAULT_NAPI_HARD_IRQS 2
91 static void AFXDPDerefConfig(
void *conf)
105 if (active_runmode && !strcmp(
"single", active_runmode)) {
110 if (entry_str == NULL) {
111 SCLogError(
"Number of threads for interface \"%s\" not specified", aconf->
iface);
117 if (strcmp(entry_str,
"auto") == 0) {
122 aconf->
threads = (nr_cores <= nr_queues) ? nr_cores : nr_queues;
123 const char *sys_type = nr_cores <= nr_queues ?
"cores" :
"queues";
130 SCLogError(
"Threads entry for interface %s contain non-numerical characters - \"%s\"",
131 aconf->
iface, entry_str);
136 SCLogError(
"Interface %s has a negative number of threads", aconf->
iface);
140 if (aconf->
threads > nr_queues) {
142 "Selected threads greater than configured queues, using: %d thread(s)", nr_queues);
159 static void *ParseAFXDPConfig(
const char *iface)
161 const char *confstr = NULL;
166 intmax_t conf_val_int = 0;
167 bool boolval =
false;
186 aconf->
mode = XDP_FLAGS_UPDATE_IF_NOEXIST;
193 if (af_xdp_node == NULL) {
194 SCLogInfo(
"unable to find af-xdp config using default values");
201 if (if_root == NULL && if_default == NULL) {
202 SCLogInfo(
"unable to find af-xdp config for "
203 "interface \"%s\" or \"default\", using default values",
209 if (if_root == NULL) {
210 if_root = if_default;
217 if (ConfigSetThreads(aconf, confstr) !=
TM_ECODE_OK) {
235 if (strncasecmp(confstr,
"drv", 3) == 0) {
236 aconf->
mode |= XDP_FLAGS_DRV_MODE;
237 }
else if (strncasecmp(confstr,
"skb", 3) == 0) {
238 aconf->
mode |= XDP_FLAGS_SKB_MODE;
239 }
else if (strncasecmp(confstr,
"none", 4) == 0) {
241 SCLogWarning(
"Incorrect af-xdp xdp-mode setting, default (none) shall be applied");
247 if (strncasecmp(confstr,
"zero", 4) == 0) {
249 }
else if (strncasecmp(confstr,
"copy", 4) == 0) {
251 }
else if (strncasecmp(confstr,
"none", 4) == 0) {
253 SCLogWarning(
"Incorrect af-xdp copy-mode setting, default (none) shall be applied");
259 if (strncasecmp(confstr,
"yes", 3) == 0) {
280 if_root, if_default,
"busy-poll-budget", &conf_val_int) == 1) {
288 if_root, if_default,
"gro-flush-timeout", &conf_val_int) == 1) {
293 if_root, if_default,
"napi-defer-hard-irq", &conf_val_int) == 1) {
302 SCLogWarning(
"Using AF_XDP with offloading activated leads to capture problems");
311 static int AFXDPConfigGetThreadsCount(
void *conf)
331 const char *live_dev = NULL;
335 (void)
ConfGet(
"af-xdp.live-interface", &live_dev);
338 FatalError(
"Unable to init AF_XDP queue protection.");
347 SCLogDebug(
"RunModeIdsAFXDPSingle initialised");
365 const char *live_dev = NULL;
369 (void)
ConfGet(
"af-xdp.live-interface", &live_dev);
372 FatalError(
"Unable to init AF_XDP queue protection.");
381 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.