#define COUNTERS
#include "suricata-common.h"
+#include "suricata-plugin.h"
#include "threadvars.h"
#include "util-debug.h"
#include "decode-events.h"
WinDivertPacketVars windivert_v;
#endif /* WINDIVERT */
+ /* A chunk of memory that a plugin can use for its packet vars. */
+ uint8_t plugin_v[PLUGIN_VAR_SIZE];
+
/** libpcap vars: shared by Pcap Live mode and Pcap File mode */
PcapPacketVars pcap_v;
};
PreRunInit(RUNMODE_PCAP_FILE);
PreRunPostPrivsDropInit(RUNMODE_PCAP_FILE);
- RunModeDispatch(RUNMODE_PCAP_FILE, NULL);
+ RunModeDispatch(RUNMODE_PCAP_FILE, NULL, NULL, NULL);
/* Un-pause all the paused threads */
TmThreadWaitOnThreadInit();
#include "runmodes.h"
#include "util-unittest.h"
#include "util-misc.h"
+#include "util-plugin.h"
#include "output.h"
#include "flow-bypass.h"
#include "counters.h"
+#include "suricata-plugin.h"
+
int debuglog_enabled = 0;
int threading_set_cpu_affinity = FALSE;
#else
return "PFRING(DISABLED)";
#endif
+ case RUNMODE_PLUGIN:
+ return "PLUGIN";
case RUNMODE_NFQ:
return "NFQ";
case RUNMODE_NFLOG:
/**
*/
-void RunModeDispatch(int runmode, const char *custom_mode)
+void RunModeDispatch(int runmode, const char *custom_mode,
+ const char *capture_plugin_name, const char *capture_plugin_args)
{
char *local_custom_mode = NULL;
custom_mode = RunModeIdsPfringGetDefaultMode();
break;
#endif
+ case RUNMODE_PLUGIN: {
+ SCCapturePlugin *plugin = SCPluginFindCaptureByName(capture_plugin_name);
+ if (plugin == NULL) {
+ FatalError(SC_ERR_PLUGIN, "No capture plugin found with name %s",
+ capture_plugin_name);
+ }
+ custom_mode = (const char *)plugin->GetDefaultMode();
+ break;
+ }
case RUNMODE_NFQ:
custom_mode = RunModeIpsNFQGetDefaultMode();
break;
RUNMODE_NAPATECH,
RUNMODE_UNIX_SOCKET,
RUNMODE_WINDIVERT,
+ RUNMODE_PLUGIN,
RUNMODE_USER_MAX, /* Last standard running mode */
RUNMODE_LIST_KEYWORDS,
RUNMODE_LIST_APP_LAYERS,
const char *RunModeGetMainMode(void);
void RunModeListRunmodes(void);
-void RunModeDispatch(int, const char *);
+void RunModeDispatch(int, const char *, const char *capture_plugin_name, const char *capture_plugin_args);
void RunModeRegisterRunModes(void);
void RunModeRegisterNewRunMode(enum RunModes, const char *, const char *,
int (*RunModeFunc)(void));
#include "conf.h"
+/**
+ * The size of the data chunk inside each packet structure a plugin
+ * has for private data (Packet->plugin_v).
+ */
+#define PLUGIN_VAR_SIZE 64
+
/**
* Structure to define a Suricata plugin.
*/
bool SCPluginRegisterFileType(SCPluginFileType *);
+typedef struct SCCapturePlugin_ {
+ char *name;
+ void (*Init)(const char *args, int plugin_slot, int receive_slot, int decode_slot);
+ const char *(*GetDefaultMode)(void);
+ TAILQ_ENTRY(SCCapturePlugin_) entries;
+} SCCapturePlugin;
+
+int SCPluginRegisterCapture(SCCapturePlugin *);
+
#endif /* __SURICATA_PLUGIN_H */
{"no-random", 0, &g_disable_randomness, 1},
{"strict-rule-keywords", optional_argument, 0, 0},
+ {"capture-plugin", required_argument, 0, 0},
+ {"cpature-plugin-args", required_argument, 0, 0},
+
#ifdef BUILD_UNIX_SOCKET
{"unix-socket", optional_argument, 0, 0},
#endif
return TM_ECODE_FAILED;
#endif /* HAVE_PFRING */
}
+ else if (strcmp((long_opts[option_index]).name , "capture-plugin") == 0){
+ suri->run_mode = RUNMODE_PLUGIN;
+ suri->capture_plugin_name = optarg;
+ }
+ else if (strcmp((long_opts[option_index]).name , "capture-plugin-args") == 0){
+ suri->capture_plugin_args = optarg;
+ }
else if (strcmp((long_opts[option_index]).name , "af-packet") == 0)
{
if (ParseCommandLineAfpacket(suri, optarg) != TM_ECODE_OK) {
FeatureTrackingRegister(); /* must occur prior to output mod registration */
RegisterAllModules();
- SCPluginsLoad();
+ SCPluginsLoad(suri->capture_plugin_name, suri->capture_plugin_args);
AppLayerHtpNeedFileInspection();
}
SCSetStartTime(&suricata);
- RunModeDispatch(suricata.run_mode, suricata.runmode_custom_mode);
+ RunModeDispatch(suricata.run_mode, suricata.runmode_custom_mode,
+ suricata.capture_plugin_name, suricata.capture_plugin_args);
if (suricata.run_mode != RUNMODE_UNIX_SOCKET) {
UnixManagerThreadSpawnNonRunmode();
}
const char *progname; /**< pointer to argv[0] */
const char *conf_filename;
char *strict_rule_parsing_string;
+
+ const char *capture_plugin_name;
+ const char *capture_plugin_args;
} SCInstance;
CASE_CODE (TMM_DECODEPCAPFILE);
CASE_CODE (TMM_RECEIVEPFRING);
CASE_CODE (TMM_DECODEPFRING);
+ CASE_CODE (TMM_RECEIVEPLUGIN);
+ CASE_CODE (TMM_DECODEPLUGIN);
CASE_CODE (TMM_RESPONDREJECT);
CASE_CODE (TMM_DECODEIPFW);
CASE_CODE (TMM_VERDICTIPFW);
TMM_DECODEPCAPFILE,
TMM_RECEIVEPFRING,
TMM_DECODEPFRING,
+ TMM_RECEIVEPLUGIN,
+ TMM_DECODEPLUGIN,
TMM_RESPONDREJECT,
TMM_DECODEIPFW,
TMM_VERDICTIPFW,
static TAILQ_HEAD(, SCPluginFileType_) output_types =
TAILQ_HEAD_INITIALIZER(output_types);
+static TAILQ_HEAD(, SCCapturePlugin_) capture_plugins = TAILQ_HEAD_INITIALIZER(capture_plugins);
+
static void InitPlugin(char *path)
{
void *lib = dlopen(path, RTLD_NOW);
}
}
-void SCPluginsLoad(void)
+void SCPluginsLoad(const char *capture_plugin_name, const char *capture_plugin_args)
{
ConfNode *conf = ConfGetNode("plugins");
if (conf == NULL) {
InitPlugin(plugin->val);
}
}
+
+ if (run_mode == RUNMODE_PLUGIN) {
+ SCCapturePlugin *capture = SCPluginFindCaptureByName(capture_plugin_name);
+ if (capture == NULL) {
+ FatalError(SC_ERR_PLUGIN, "No capture plugin found with name %s",
+ capture_plugin_name);
+ }
+ capture->Init(capture_plugin_args, RUNMODE_PLUGIN, TMM_RECEIVEPLUGIN,
+ TMM_DECODEPLUGIN);
+ }
}
/**
return NULL;
}
+int SCPluginRegisterCapture(SCCapturePlugin *plugin)
+{
+ TAILQ_INSERT_TAIL(&capture_plugins, plugin, entries);
+ SCLogNotice("Capture plugin registered: %s", plugin->name);
+ return 0;
+}
+
+SCCapturePlugin *SCPluginFindCaptureByName(const char *name)
+{
+ SCCapturePlugin *plugin = NULL;
+ TAILQ_FOREACH(plugin, &capture_plugins, entries) {
+ if (strcmp(name, plugin->name) == 0) {
+ return plugin;
+ }
+ }
+ return plugin;
+}
+
#else
void PluginsLoad(void)
#include "suricata-plugin.h"
-void SCPluginsLoad(void);
+void SCPluginsLoad(const char *capture_plugin_name, const char *capture_plugin_args);
SCPluginFileType *SCPluginFindFileType(const char *name);
+SCCapturePlugin *SCPluginFindCaptureByName(const char *name);
#endif /* __UTIL_PLUGIN_H__ */