af-packet: bypass with init function

pull/3952/head
Eric Leblond 7 years ago committed by Victor Julien
parent f93573ac5e
commit 880c42f11c

@ -40,6 +40,7 @@ typedef struct BypassedFlowManagerThreadData_ {
typedef struct BypassedCheckFuncItem_ { typedef struct BypassedCheckFuncItem_ {
BypassedCheckFunc Func; BypassedCheckFunc Func;
BypassedCheckFuncInit FuncInit;
void *data; void *data;
} BypassedCheckFuncItem; } BypassedCheckFuncItem;
@ -58,11 +59,22 @@ static TmEcode BypassedFlowManager(ThreadVars *th_v, void *thread_data)
{ {
#ifdef HAVE_PACKET_EBPF #ifdef HAVE_PACKET_EBPF
int tcount = 0; int tcount = 0;
int i;
BypassedFlowManagerThreadData *ftd = thread_data; BypassedFlowManagerThreadData *ftd = thread_data;
struct timespec curtime = {0, 0};
if (clock_gettime(CLOCK_MONOTONIC, &curtime) != 0) {
SCLogWarning(SC_ERR_INVALID_VALUE, "Can't get time: %s (%d)",
strerror(errno), errno);
}
for (i = 0; i < g_bypassed_func_max_index; i++) {
if (BypassedFuncList[i].FuncInit) {
BypassedFuncList[i].FuncInit(&curtime, BypassedFuncList[i].data);
}
}
while (1) { while (1) {
int i;
SCLogDebug("Dumping the table"); SCLogDebug("Dumping the table");
struct timespec curtime;
if (clock_gettime(CLOCK_MONOTONIC, &curtime) != 0) { if (clock_gettime(CLOCK_MONOTONIC, &curtime) != 0) {
SCLogWarning(SC_ERR_INVALID_VALUE, "Can't get time: %s (%d)", SCLogWarning(SC_ERR_INVALID_VALUE, "Can't get time: %s (%d)",
strerror(errno), errno); strerror(errno), errno);
@ -152,6 +164,7 @@ void BypassedFlowManagerThreadSpawn()
} }
int BypassedFlowManagerRegisterCheckFunc(BypassedCheckFunc CheckFunc, int BypassedFlowManagerRegisterCheckFunc(BypassedCheckFunc CheckFunc,
BypassedCheckFuncInit CheckFuncInit,
void *data) void *data)
{ {
if (!CheckFunc) { if (!CheckFunc) {
@ -159,6 +172,7 @@ int BypassedFlowManagerRegisterCheckFunc(BypassedCheckFunc CheckFunc,
} }
if (g_bypassed_func_max_index < BYPASSFUNCMAX) { if (g_bypassed_func_max_index < BYPASSFUNCMAX) {
BypassedFuncList[g_bypassed_func_max_index].Func = CheckFunc; BypassedFuncList[g_bypassed_func_max_index].Func = CheckFunc;
BypassedFuncList[g_bypassed_func_max_index].FuncInit = CheckFuncInit;
BypassedFuncList[g_bypassed_func_max_index].data = data; BypassedFuncList[g_bypassed_func_max_index].data = data;
g_bypassed_func_max_index++; g_bypassed_func_max_index++;
} else { } else {

@ -32,6 +32,7 @@ struct flows_stats {
typedef int (*BypassedCheckFunc)(struct flows_stats *bypassstats, typedef int (*BypassedCheckFunc)(struct flows_stats *bypassstats,
struct timespec *curtime, void *data); struct timespec *curtime, void *data);
typedef int (*BypassedCheckFuncInit)(struct timespec *curtime, void *data);
typedef int (*BypassedUpdateFunc)(Flow *f, Packet *p, void *data); typedef int (*BypassedUpdateFunc)(Flow *f, Packet *p, void *data);
void FlowAddToBypassed(Flow *f); void FlowAddToBypassed(Flow *f);
@ -39,7 +40,8 @@ void FlowAddToBypassed(Flow *f);
void BypassedFlowManagerThreadSpawn(void); void BypassedFlowManagerThreadSpawn(void);
void TmModuleBypassedFlowManagerRegister(void); void TmModuleBypassedFlowManagerRegister(void);
int BypassedFlowManagerRegisterCheckFunc(BypassedCheckFunc CheckFunc, void *data); int BypassedFlowManagerRegisterCheckFunc(BypassedCheckFunc CheckFunc,
BypassedCheckFuncInit CheckFuncInit, void *data);
int BypassedFlowManagerRegisterUpdateFunc(BypassedUpdateFunc UpdateFunc, void *data); int BypassedFlowManagerRegisterUpdateFunc(BypassedUpdateFunc UpdateFunc, void *data);
void BypassedFlowUpdate(Flow *f, Packet *p); void BypassedFlowUpdate(Flow *f, Packet *p);

@ -438,7 +438,9 @@ static void *ParseAFPConfig(const char *iface)
aconf->iface); aconf->iface);
aconf->flags |= AFP_BYPASS; aconf->flags |= AFP_BYPASS;
RunModeEnablesBypassManager(); RunModeEnablesBypassManager();
BypassedFlowManagerRegisterCheckFunc(EBPFCheckBypassedFlowTimeout, (void *) &(aconf->ebpf_t_config)); BypassedFlowManagerRegisterCheckFunc(EBPFCheckBypassedFlowTimeout,
NULL,
(void *) &(aconf->ebpf_t_config));
BypassedFlowManagerRegisterUpdateFunc(EBPFUpdateFlow, NULL); BypassedFlowManagerRegisterUpdateFunc(EBPFUpdateFlow, NULL);
#else #else
SCLogError(SC_ERR_UNIMPLEMENTED, "Bypass set but eBPF support is not built-in"); SCLogError(SC_ERR_UNIMPLEMENTED, "Bypass set but eBPF support is not built-in");
@ -477,7 +479,10 @@ static void *ParseAFPConfig(const char *iface)
aconf->iface); aconf->iface);
aconf->flags |= AFP_XDPBYPASS; aconf->flags |= AFP_XDPBYPASS;
RunModeEnablesBypassManager(); RunModeEnablesBypassManager();
BypassedFlowManagerRegisterCheckFunc(EBPFCheckBypassedFlowTimeout, (void *) &(aconf->ebpf_t_config)); /* TODO move that to get it conditional on pinned maps */
BypassedFlowManagerRegisterCheckFunc(EBPFCheckBypassedFlowTimeout,
EBPFCheckBypassedFlowCreate,
(void *) &(aconf->ebpf_t_config));
BypassedFlowManagerRegisterUpdateFunc(EBPFUpdateFlow, NULL); BypassedFlowManagerRegisterUpdateFunc(EBPFUpdateFlow, NULL);
} }
#else #else

@ -1,4 +1,4 @@
/* Copyright (C) 2018 Open Information Security Foundation /* Copyright (C) 2018-2019 Open Information Security Foundation
* *
* You can copy, redistribute or modify this Program under the terms of * You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free * the GNU General Public License version 2 as published by the Free
@ -661,6 +661,18 @@ static int EBPFForEachFlowV6Table(LiveDevice *dev, const char *name,
return found; return found;
} }
int EBPFCheckBypassedFlowCreate(struct timespec *curtime, void *data)
{
/* loop on v4 table */
/* create flow key*/
/* look for flow in hash, create entry if not found */
/* loop on v6*/
return 0;
}
/** /**
* Flow timeout checking function * Flow timeout checking function
* *

@ -74,6 +74,7 @@ int EBPFSetupXDP(const char *iface, int fd, uint8_t flags);
int EBPFCheckBypassedFlowTimeout(struct flows_stats *bypassstats, int EBPFCheckBypassedFlowTimeout(struct flows_stats *bypassstats,
struct timespec *curtime, struct timespec *curtime,
void *data); void *data);
int EBPFCheckBypassedFlowCreate(struct timespec *curtime, void *data);
void EBPFRegisterExtension(void); void EBPFRegisterExtension(void);

Loading…
Cancel
Save