Go to the documentation of this file.
69 "Single threaded af-packet mode",
72 "Workers af-packet mode, each thread does all"
73 " tasks from acquisition to logging",
76 "Multi socket AF_PACKET mode. Packets from "
77 "each flow are assigned to a single detect "
86 static void AFPDerefConfig(
void *conf)
97 static int cluster_id_auto = 1;
109 static void *ParseAFPConfig(
const char *iface)
111 const char *threadsstr = NULL;
115 const char *tmpclusterid;
116 const char *tmpctype;
117 const char *copymodestr;
120 const char *bpf_filter = NULL;
121 const char *out_iface = NULL;
123 const char *ebpf_file = NULL;
155 #ifdef HAVE_PACKET_EBPF
159 if (
ConfGet(
"bpf-filter", &bpf_filter) == 1) {
160 if (strlen(bpf_filter) > 0) {
162 SCLogConfig(
"Going to use command-line provided bpf filter '%s'",
169 if (af_packet_node == NULL) {
170 SCLogInfo(
"unable to find af-packet config using default values");
177 if (if_root == NULL && if_default == NULL) {
178 SCLogInfo(
"unable to find af-packet config for "
179 "interface \"%s\" or \"default\", using default values",
185 if (if_root == NULL) {
186 if_root = if_default;
190 if (active_runmode && !strcmp(
"single", active_runmode)) {
195 if (threadsstr != NULL) {
196 if (strcmp(threadsstr,
"auto") == 0) {
201 "threads, resetting to default");
209 if (strlen(out_iface) > 0) {
217 "%s: \"use-mmap\" option is obsolete: mmap is always enabled", aconf->
iface);
230 #ifdef HAVE_TPACKET_V3
234 SCLogNotice(
"System too old for tpacket v3 switching to v2");
239 " Switching to tpacket v2.");
248 if_root, if_default,
"use-emergency-flush", (
int *)&boolval);
256 SCLogInfo(
"Copy mode activated but no destination"
257 " iface. Disabling feature");
258 }
else if (strlen(copymodestr) <= 0) {
260 }
else if (strcmp(copymodestr,
"ips") == 0) {
261 SCLogInfo(
"AF_PACKET IPS mode activated %s->%s",
268 }
else if (strcmp(copymodestr,
"tap") == 0) {
269 SCLogInfo(
"AF_PACKET TAP mode activated %s->%s",
277 SCLogInfo(
"Invalid mode (not in tap, ips)");
282 aconf->
cluster_id = (uint16_t)(cluster_id_auto++);
295 }
else if (strcmp(tmpctype,
"cluster_round_robin") == 0) {
296 SCLogConfig(
"Using round-robin cluster mode for AF_PACKET (iface %s)",
300 }
else if (strcmp(tmpctype,
"cluster_flow") == 0) {
305 SCLogConfig(
"Using flow cluster mode for AF_PACKET (iface %s)",
309 SCLogConfig(
"Using defrag kernel functionality for AF_PACKET (iface %s)",
315 }
else if (strcmp(tmpctype,
"cluster_cpu") == 0) {
316 SCLogConfig(
"Using cpu cluster mode for AF_PACKET (iface %s)",
320 }
else if (strcmp(tmpctype,
"cluster_qm") == 0) {
321 SCLogConfig(
"Using queue based cluster mode for AF_PACKET (iface %s)",
325 }
else if (strcmp(tmpctype,
"cluster_random") == 0) {
326 SCLogConfig(
"Using random based cluster mode for AF_PACKET (iface %s)",
330 }
else if (strcmp(tmpctype,
"cluster_rollover") == 0) {
331 SCLogConfig(
"Using rollover based cluster mode for AF_PACKET (iface %s)",
334 "tracking issues, use it at your own risk.");
337 #ifdef HAVE_PACKET_EBPF
338 }
else if (strcmp(tmpctype,
"cluster_ebpf") == 0) {
339 SCLogInfo(
"Using ebpf based cluster mode for AF_PACKET (iface %s)",
342 cluster_type = PACKET_FANOUT_EBPF;
351 SCLogConfig(
"Using rollover kernel functionality for AF_PACKET (iface %s)",
355 "tracking issues, use it at your own risk.");
360 if (
ConfGet(
"bpf-filter", &bpf_filter) != 1) {
362 if (strlen(bpf_filter) > 0) {
372 #ifdef HAVE_PACKET_EBPF
373 SCLogConfig(
"af-packet will use '%s' as eBPF load balancing file",
376 aconf->ebpf_t_config.
flags |= EBPF_SOCKET_FILTER;
380 #ifdef HAVE_PACKET_EBPF
386 aconf->ebpf_t_config.
flags |= EBPF_PINNED_MAPS;
388 const char *pinned_maps_name = NULL;
391 &pinned_maps_name) != 1) {
392 aconf->ebpf_t_config.pinned_maps_name = pinned_maps_name;
394 aconf->ebpf_t_config.pinned_maps_name = NULL;
397 aconf->ebpf_t_config.pinned_maps_name = NULL;
401 #ifdef HAVE_PACKET_EBPF
403 if (aconf->
ebpf_lb_file && cluster_type == PACKET_FANOUT_EBPF) {
406 &aconf->ebpf_t_config);
420 #ifdef HAVE_PACKET_EBPF
421 SCLogConfig(
"af-packet will use '%s' as eBPF filter file",
424 aconf->ebpf_t_config.mode = AFP_MODE_EBPF_BYPASS;
425 aconf->ebpf_t_config.
flags |= EBPF_SOCKET_FILTER;
429 #ifdef HAVE_PACKET_EBPF
430 SCLogConfig(
"Using bypass kernel functionality for AF_PACKET (iface %s)",
442 #ifdef HAVE_PACKET_EBPF
445 &aconf->ebpf_t_config);
448 "Error when loading eBPF filter file");
458 #ifdef HAVE_PACKET_XDP
459 aconf->ebpf_t_config.mode = AFP_MODE_XDP_BYPASS;
460 aconf->ebpf_t_config.
flags |= EBPF_XDP_CODE;
464 SCLogConfig(
"Using bypass kernel functionality for AF_PACKET (iface %s)",
468 if (aconf->ebpf_t_config.
flags & EBPF_PINNED_MAPS) {
470 struct ebpf_timeout_config *ebt =
SCCalloc(1,
sizeof(
struct ebpf_timeout_config));
474 memcpy(ebt, &(aconf->ebpf_t_config),
sizeof(
struct ebpf_timeout_config));
476 EBPFCheckBypassedFlowCreate,
485 #ifdef HAVE_PACKET_XDP
486 const char *xdp_mode;
488 aconf->
xdp_mode = XDP_FLAGS_SKB_MODE;
490 if (!strcmp(xdp_mode,
"soft")) {
491 aconf->
xdp_mode = XDP_FLAGS_SKB_MODE;
492 }
else if (!strcmp(xdp_mode,
"driver")) {
493 aconf->
xdp_mode = XDP_FLAGS_DRV_MODE;
494 }
else if (!strcmp(xdp_mode,
"hw")) {
495 aconf->
xdp_mode = XDP_FLAGS_HW_MODE;
496 aconf->ebpf_t_config.
flags |= EBPF_XDP_HW_MODE;
499 "Invalid xdp-mode value: '%s'", xdp_mode);
505 if (boolval ==
false) {
508 aconf->ebpf_t_config.cpus_count = 1;
516 #ifdef HAVE_PACKET_XDP
519 &aconf->ebpf_t_config);
522 SCLogInfo(
"Loaded pinned maps from sysfs");
526 "Error when loading XDP filter file");
532 "Error when setting up XDP");
537 "xdp-cpu-redirect", &cpuset) == 1) {
542 "Previously found node has disappeared");
544 EBPFBuildCPUSet(node, aconf->
iface);
548 EBPFBuildCPUSet(NULL, aconf->
iface);
571 if (value % getpagesize()) {
586 SCLogConfig(
"Disabling promiscuous mode on iface %s",
592 if (strcmp(tmpctype,
"auto") == 0) {
598 }
else if (strcmp(tmpctype,
"kernel") == 0) {
612 SCLogNotice(
"fanout not supported on this system, falling "
613 "back to 1 capture thread");
629 if (rss_queues > 0) {
631 SCLogPerf(
"%d RSS queues, so using %u threads", rss_queues, aconf->
threads);
636 SCLogPerf(
"Using %d AF_PACKET threads for interface %s",
650 "Resetting to decent value %d.", aconf->
ring_size);
668 "Using AF_PACKET with offloading activated leads to capture problems");
679 if (active_runmode == NULL || strcmp(
"workers", active_runmode) != 0) {
687 static int AFPConfigGeThreadsCount(
void *conf)
705 if (af_packet_node == NULL) {
711 for (ldev = 0; ldev < nlive; ldev++) {
713 if (live_dev == NULL) {
717 const char *copymodestr = NULL;
720 if (if_root == NULL) {
721 if (if_default == NULL) {
725 if_root = if_default;
729 if (strcmp(copymodestr,
"ips") == 0) {
739 if (has_ids && has_ips) {
740 SCLogInfo(
"AF_PACKET mode using IPS and IDS mode");
741 for (ldev = 0; ldev < nlive; ldev++) {
743 if (live_dev == NULL) {
748 const char *copymodestr = NULL;
750 if (if_root == NULL) {
751 if (if_default == NULL) {
755 if_root = if_default;
759 (strcmp(copymodestr,
"ips") == 0))) {
761 "AF_PACKET IPS mode used and interface '%s' is in IDS or TAP mode. "
762 "Sniffing '%s' but expect bad result as stream-inline is activated.",
779 #ifdef HAVE_AF_PACKET
781 const char *live_dev = NULL;
787 (void)
ConfGet(
"af-packet.live-interface", &live_dev);
796 AFPConfigGeThreadsCount,
809 SCLogDebug(
"RunModeIdsAFPAutoFp initialised");
821 #ifdef HAVE_AF_PACKET
823 const char *live_dev = NULL;
828 (void)
ConfGet(
"af-packet.live-interface", &live_dev);
835 AFPConfigGeThreadsCount,
848 SCLogDebug(
"RunModeIdsAFPSingle initialised");
863 #ifdef HAVE_AF_PACKET
865 const char *live_dev = NULL;
870 (void)
ConfGet(
"af-packet.live-interface", &live_dev);
877 AFPConfigGeThreadsCount,
890 SCLogDebug(
"RunModeIdsAFPWorkers initialised");
const char * thread_name_workers
ChecksumValidationMode checksum_mode
#define PACKET_FANOUT_FLAG_DEFRAG
int RunModeIdsAFPWorkers(void)
Workers version of the AF_PACKET processing.
int RunModeSetLiveCaptureWorkers(ConfigIfaceParserFunc ConfigParser, ConfigIfaceThreadsCountFunc ModThreadsCount, const char *recv_mod_name, const char *decode_mod_name, const char *thread_name, const char *live_dev)
TmEcode AFPPeersListCheck()
Check that all AFPPeer got a peer.
int GetIfaceRSSQueuesNum(const char *pcap_dev)
#define SC_ATOMIC_INIT(name)
wrapper for initializing an atomic variable.
#define AFP_COPY_MODE_NONE
int RunModeIdsAFPSingle(void)
Single thread version of the AF_PACKET processing.
@ SC_ERR_INVALID_CLUSTER_TYPE
void RunModeIdsAFPRegister(void)
int ConfGetChildValueBoolWithDefault(const ConfNode *base, const ConfNode *dflt, const char *name, int *val)
ConfNode * ConfGetNode(const char *name)
Get a ConfNode by name.
#define PACKET_FANOUT_RND
uint16_t UtilCpuGetNumProcessorsConfigured(void)
Get the number of cpus configured in the system.
#define PACKET_FANOUT_HASH
#define SC_ATOMIC_ADD(name, val)
add a value to our atomic variable
const char * RunModeAFPGetDefaultMode(void)
int StringParseUint16(uint16_t *res, int base, size_t len, const char *str)
void RunModeInitialize(void)
const char * thread_name_autofp
#define PACKET_FANOUT_ROLLOVER
ConfNode * ConfNodeLookupKeyValue(const ConfNode *base, const char *key, const char *value)
Lookup for a key value under a specific node.
@ CHECKSUM_VALIDATION_DISABLE
@ CHECKSUM_VALIDATION_KERNEL
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 * thread_name_single
ConfNode * ConfGetChildWithDefault(const ConfNode *base, const ConfNode *dflt, const char *name)
int AFPGetLinkType(const char *ifname)
int ConfValIsTrue(const char *val)
Check if a value is true.
#define AFP_BLOCK_SIZE_DEFAULT_ORDER
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)
@ CHECKSUM_VALIDATION_ENABLE
int ConfGet(const char *name, const char **vptr)
Retrieve the value of a configuration node.
@ CHECKSUM_VALIDATION_AUTO
const char * ebpf_filter_file
void RunModeEnablesBypassManager(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.
#define PACKET_FANOUT_CPU
int ConfGetChildValueWithDefault(const ConfNode *base, const ConfNode *dflt, const char *name, const char **vptr)
void(* DerefFunc)(void *)
@ SC_ERR_INVALID_ARGUMENT
#define AFP_COPY_MODE_TAP
#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.
const char * xdp_filter_file
#define FatalError(x,...)
int RunModeIdsAFPAutoFp(void)
#define SC_ATOMIC_RESET(name)
wrapper for reinitializing an atomic variable.
int BypassedFlowManagerRegisterUpdateFunc(BypassedUpdateFunc UpdateFunc, void *data)
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
#define SCLogWarning(err_code,...)
Macro used to log WARNING messages.
#define AFP_COPY_MODE_IPS
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
char iface[AFP_IFACE_NAME_LENGTH]
int LiveGetDeviceCount(void)
Get the number of registered devices.
uint16_t UtilCpuGetNumProcessorsOnline(void)
Get the number of cpus online in the system.
const char * ebpf_lb_file
#define SCLogNotice(...)
Macro used to log NOTICE messages.
int BypassedFlowManagerRegisterCheckFunc(BypassedCheckFunc CheckFunc, BypassedCheckFuncInit CheckFuncInit, void *data)
#define PACKET_FANOUT_FLAG_ROLLOVER
TmEcode AFPPeersListInit()
Init the global list of AFPPeer.
int AFPIsFanoutSupported(uint16_t cluster_id)
test if we can use FANOUT. Older kernels like those in CentOS6 have HAVE_PACKET_FANOUT defined but fa...
#define LINKTYPE_ETHERNET
#define AFP_EMERGENCY_MODE