Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Afpacket improvements/v13 #6551

Closed
9 changes: 9 additions & 0 deletions src/flow-worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ typedef struct FlowWorkerThreadData_ {

struct {
uint16_t flows_injected;
uint16_t flows_injected_avg;
uint16_t flows_injected_max;
uint16_t flows_removed;
uint16_t flows_removed_max;
uint16_t flows_aside_needs_work;
uint16_t flows_aside_pkt_inject;
} cnt;
Expand Down Expand Up @@ -251,7 +254,10 @@ static TmEcode FlowWorkerThreadInit(ThreadVars *tv, const void *initdata, void *
fw->cnt.flows_aside_needs_work = StatsRegisterCounter("flow.wrk.flows_evicted_needs_work", tv);
fw->cnt.flows_aside_pkt_inject = StatsRegisterCounter("flow.wrk.flows_evicted_pkt_inject", tv);
fw->cnt.flows_removed = StatsRegisterCounter("flow.wrk.flows_evicted", tv);
fw->cnt.flows_removed_max = StatsRegisterMaxCounter("flow.wrk.flows_evicted_max", tv);
fw->cnt.flows_injected = StatsRegisterCounter("flow.wrk.flows_injected", tv);
fw->cnt.flows_injected_avg = StatsRegisterAvgCounter("flow.wrk.flows_injected_avg", tv);
fw->cnt.flows_injected_max = StatsRegisterMaxCounter("flow.wrk.flows_injected_max", tv);

fw->fls.dtv = fw->dtv = DecodeThreadVarsAlloc(tv);
if (fw->dtv == NULL) {
Expand Down Expand Up @@ -453,7 +459,9 @@ static inline void FlowWorkerProcessInjectedFlows(ThreadVars *tv,
if (SC_ATOMIC_GET(tv->flow_queue->non_empty) == true)
injected = FlowQueueExtractPrivate(tv->flow_queue);
if (injected.len > 0) {
StatsAddUI64(tv, fw->cnt.flows_injected_avg, (uint64_t)injected.len);
StatsAddUI64(tv, fw->cnt.flows_injected, (uint64_t)injected.len);
StatsSetUI64(tv, fw->cnt.flows_injected_max, (uint64_t)injected.len);

FlowTimeoutCounters counters = { 0, 0, };
CheckWorkQueue(tv, fw, detect_thread, &counters, &injected);
Expand All @@ -471,6 +479,7 @@ static inline void FlowWorkerProcessLocalFlows(ThreadVars *tv,
FLOWWORKER_PROFILING_START(p, PROFILE_FLOWWORKER_FLOW_EVICTED);
if (fw->fls.work_queue.len) {
StatsAddUI64(tv, fw->cnt.flows_removed, (uint64_t)fw->fls.work_queue.len);
StatsSetUI64(tv, fw->cnt.flows_removed_max, (uint64_t)fw->fls.work_queue.len);

FlowTimeoutCounters counters = { 0, 0, };
CheckWorkQueue(tv, fw, detect_thread, &counters, &fw->fls.work_queue);
Expand Down
78 changes: 27 additions & 51 deletions src/runmode-af-packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ static void *ParseAFPConfig(const char *iface)
aconf->promisc = 1;
aconf->checksum_mode = CHECKSUM_VALIDATION_KERNEL;
aconf->DerefFunc = AFPDerefConfig;
aconf->flags = AFP_RING_MODE;
aconf->flags = 0;
aconf->bpf_filter = NULL;
aconf->ebpf_lb_file = NULL;
aconf->ebpf_lb_fd = -1;
Expand Down Expand Up @@ -213,62 +213,49 @@ static void *ParseAFPConfig(const char *iface)

if (ConfGetChildValueBoolWithDefault(if_root, if_default, "use-mmap", (int *)&boolval) == 1) {
if (!boolval) {
SCLogConfig("Disabling mmaped capture on iface %s",
aconf->iface);
aconf->flags &= ~(AFP_RING_MODE|AFP_TPACKET_V3);
SCLogWarning(SC_WARN_OPTION_OBSOLETE,
"%s: \"use-mmap\" option is obsolete: mmap is always enabled", aconf->iface);
}
}

if (aconf->flags & AFP_RING_MODE) {
(void)ConfGetChildValueBoolWithDefault(if_root, if_default,
"mmap-locked", (int *)&boolval);
if (boolval) {
SCLogConfig("Enabling locked memory for mmap on iface %s",
aconf->iface);
aconf->flags |= AFP_MMAP_LOCKED;
}
(void)ConfGetChildValueBoolWithDefault(if_root, if_default, "mmap-locked", (int *)&boolval);
if (boolval) {
SCLogConfig("Enabling locked memory for mmap on iface %s", aconf->iface);
aconf->flags |= AFP_MMAP_LOCKED;
}

if (ConfGetChildValueBoolWithDefault(if_root, if_default,
"tpacket-v3", (int *)&boolval) == 1)
{
if (boolval) {
if (strcasecmp(RunmodeGetActive(), "workers") == 0) {
if (ConfGetChildValueBoolWithDefault(if_root, if_default, "tpacket-v3", (int *)&boolval) == 1) {
if (boolval) {
if (strcasecmp(RunmodeGetActive(), "workers") == 0) {
#ifdef HAVE_TPACKET_V3
SCLogConfig("Enabling tpacket v3 capture on iface %s",
aconf->iface);
aconf->flags |= AFP_TPACKET_V3;
SCLogConfig("Enabling tpacket v3 capture on iface %s", aconf->iface);
aconf->flags |= AFP_TPACKET_V3;
#else
SCLogNotice("System too old for tpacket v3 switching to v2");
aconf->flags &= ~AFP_TPACKET_V3;
SCLogNotice("System too old for tpacket v3 switching to v2");
aconf->flags &= ~AFP_TPACKET_V3;
#endif
} else {
SCLogWarning(SC_ERR_RUNMODE,
"tpacket v3 is only implemented for 'workers' runmode."
" Switching to tpacket v2.");
aconf->flags &= ~AFP_TPACKET_V3;
}
} else {
SCLogWarning(SC_ERR_RUNMODE, "tpacket v3 is only implemented for 'workers' runmode."
" Switching to tpacket v2.");
aconf->flags &= ~AFP_TPACKET_V3;
}
} else {
aconf->flags &= ~AFP_TPACKET_V3;
}
}

(void)ConfGetChildValueBoolWithDefault(if_root, if_default,
"use-emergency-flush", (int *)&boolval);
if (boolval) {
SCLogConfig("Enabling ring emergency flush on iface %s",
aconf->iface);
aconf->flags |= AFP_EMERGENCY_MODE;
}
(void)ConfGetChildValueBoolWithDefault(
if_root, if_default, "use-emergency-flush", (int *)&boolval);
if (boolval) {
SCLogConfig("Enabling ring emergency flush on iface %s", aconf->iface);
aconf->flags |= AFP_EMERGENCY_MODE;
}

aconf->copy_mode = AFP_COPY_MODE_NONE;
if (ConfGetChildValueWithDefault(if_root, if_default, "copy-mode", &copymodestr) == 1) {
if (aconf->out_iface == NULL) {
SCLogInfo("Copy mode activated but no destination"
" iface. Disabling feature");
} else if (!(aconf->flags & AFP_RING_MODE)) {
SCLogInfo("Copy mode activated but use-mmap "
"set to no. Disabling feature");
} else if (strlen(copymodestr) <= 0) {
aconf->out_iface = NULL;
} else if (strcmp(copymodestr, "ips") == 0) {
Expand Down Expand Up @@ -690,23 +677,12 @@ static void *ParseAFPConfig(const char *iface)
break;
}

if (active_runmode && !strcmp("workers", active_runmode)) {
aconf->flags |= AFP_ZERO_COPY;
} else {
if (active_runmode == NULL || strcmp("workers", active_runmode) != 0) {
/* If we are using copy mode we need a lock */
aconf->flags |= AFP_SOCK_PROTECT;
}

/* If we are in RING mode, then we can use ZERO copy
* by using the data release mechanism */
if (aconf->flags & AFP_RING_MODE) {
aconf->flags |= AFP_ZERO_COPY;
}

if (aconf->flags & AFP_ZERO_COPY) {
SCLogConfig("%s: enabling zero copy mode by using data release call", iface);
}

SCLogConfig("%s: enabling zero copy mode by using data release call", iface);
return aconf;
}

Expand Down
Loading