|
|
|
/* Copyright (C) 2007-2013 Open Information Security Foundation
|
|
|
|
*
|
|
|
|
* You can copy, redistribute or modify this Program under the terms of
|
|
|
|
* the GNU General Public License version 2 as published by the Free
|
|
|
|
* Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* version 2 along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
*
|
|
|
|
* \author Victor Julien <victor@inliniac.net>
|
|
|
|
* \author Pablo Rincon <pablo.rincon.crespo@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __FLOW_VAR_H__
|
|
|
|
#define __FLOW_VAR_H__
|
|
|
|
|
|
|
|
#include "flow.h"
|
|
|
|
#include "util-var.h"
|
|
|
|
|
|
|
|
/** Available data types for Flowvars */
|
|
|
|
|
|
|
|
#define FLOWVAR_TYPE_STR 1
|
|
|
|
#define FLOWVAR_TYPE_INT 2
|
|
|
|
|
|
|
|
/** Struct used to hold the string data type for flowvars */
|
|
|
|
typedef struct FlowVarTypeStr {
|
|
|
|
uint8_t *value;
|
|
|
|
uint16_t value_len;
|
|
|
|
} FlowVarTypeStr;
|
|
|
|
|
|
|
|
/** Struct used to hold the integer data type for flowvars */
|
|
|
|
typedef struct FlowVarTypeInt_ {
|
|
|
|
uint32_t value;
|
|
|
|
} FlowVarTypeInt;
|
|
|
|
|
|
|
|
/** Generic Flowvar Structure */
|
|
|
|
typedef struct FlowVar_ {
|
|
|
|
uint8_t type; /* type, DETECT_FLOWVAR in this case */
|
|
|
|
uint8_t datatype;
|
|
|
|
uint16_t keylen;
|
var-names: expose outside of detect engine
Until now variable names, such as flowbit names, were local to a detect
engine. This made sense as they were only ever used in that context.
For the purpose of logging these names, this needs a different approach.
The loggers live outside of the detect engine. Also, in the case of
reloads and multi-tenancy, there are even multiple detect engines, so
it would be even more tricky to access them from the outside.
This patch brings a new approach. A any time, there is a single active
hash table mapping the variable names and their id's. For multiple
tenants the table is shared between tenants.
The table is set up in a 'staging' area, where locking makes sure that
multiple loading threads don't mess things up. Then when the preparing
of a detection engine is ready, but before the detect threads are made
aware of the new detect engine, the active varname hash is swapped with
the staging instance.
For this to work, all the mappings from the 'current' or active mapping
are added to the staging table.
After the threads have reloaded and the new detection engine is active,
the old table can be freed.
For multi tenancy things are similar. The staging area is used for
setting up until the new detection engines / tenants are applied to
the system.
This patch also changes the variable 'id'/'idx' field to uint32_t. Due
to data structure padding and alignment, this should have no practical
drawback while allowing for a lot more vars.
9 years ago
|
|
|
uint32_t idx; /* name idx */
|
|
|
|
GenericVar *next; /* right now just implement this as a list,
|
|
|
|
* in the long run we have think of something
|
|
|
|
* faster. */
|
|
|
|
union {
|
|
|
|
FlowVarTypeStr fv_str;
|
|
|
|
FlowVarTypeInt fv_int;
|
|
|
|
} data;
|
|
|
|
uint8_t *key;
|
|
|
|
} FlowVar;
|
|
|
|
|
|
|
|
/** Flowvar Interface API */
|
|
|
|
|
|
|
|
void FlowVarAddIdValue(Flow *, uint32_t id, uint8_t *value, uint16_t size);
|
|
|
|
void FlowVarAddKeyValue(Flow *f, uint8_t *key, uint16_t keysize, uint8_t *value, uint16_t size);
|
|
|
|
|
var-names: expose outside of detect engine
Until now variable names, such as flowbit names, were local to a detect
engine. This made sense as they were only ever used in that context.
For the purpose of logging these names, this needs a different approach.
The loggers live outside of the detect engine. Also, in the case of
reloads and multi-tenancy, there are even multiple detect engines, so
it would be even more tricky to access them from the outside.
This patch brings a new approach. A any time, there is a single active
hash table mapping the variable names and their id's. For multiple
tenants the table is shared between tenants.
The table is set up in a 'staging' area, where locking makes sure that
multiple loading threads don't mess things up. Then when the preparing
of a detection engine is ready, but before the detect threads are made
aware of the new detect engine, the active varname hash is swapped with
the staging instance.
For this to work, all the mappings from the 'current' or active mapping
are added to the staging table.
After the threads have reloaded and the new detection engine is active,
the old table can be freed.
For multi tenancy things are similar. The staging area is used for
setting up until the new detection engines / tenants are applied to
the system.
This patch also changes the variable 'id'/'idx' field to uint32_t. Due
to data structure padding and alignment, this should have no practical
drawback while allowing for a lot more vars.
9 years ago
|
|
|
void FlowVarAddIntNoLock(Flow *, uint32_t, uint32_t);
|
|
|
|
void FlowVarAddInt(Flow *, uint32_t, uint32_t);
|
|
|
|
FlowVar *FlowVarGet(Flow *, uint32_t);
|
|
|
|
FlowVar *FlowVarGetByKey(Flow *f, const uint8_t *key, uint16_t keylen);
|
|
|
|
void FlowVarFree(FlowVar *);
|
|
|
|
void FlowVarPrint(GenericVar *);
|
|
|
|
|
|
|
|
#endif /* __FLOW_VAR_H__ */
|
|
|
|
|