35 typedef struct PluginListNode_ {
53 if (plugin->
version != SC_API_VERSION) {
54 SCLogError(
"Suricata and plugin versions differ: plugin has %" PRIx64
55 " (%s) vs Suricata %" PRIx64
" (plugin was built with %s)",
64 PluginListNode *node =
SCCalloc(1,
sizeof(*node));
66 SCLogError(
"Failed to allocate memory for plugin");
69 node->plugin = plugin;
72 SCLogNotice(
"Initializing plugin %s; version= %s; author=%s; license=%s; built from %s",
79 static void InitPlugin(
const char *path)
81 void *lib = dlopen(path, RTLD_NOW);
83 SCLogNotice(
"Failed to open %s as a plugin: %s", path, dlerror());
88 if (plugin_register == NULL) {
89 SCLogError(
"Plugin does not export SCPluginRegister function: %s", path);
95 SCLogError(
"Plugin registration failed: %s", path);
102 static void LoadPluginsFromPath(
const char *plugin_path)
105 if (stat(plugin_path, &statbuf) == -1) {
106 SCLogError(
"Bad plugin path: %s: %s", plugin_path, strerror(errno));
109 if (S_ISDIR(statbuf.st_mode)) {
111 DIR *dir = opendir(plugin_path);
113 SCLogError(
"Failed to open plugin directory %s: %s", plugin_path, strerror(errno));
116 struct dirent *entry = NULL;
118 while ((entry = readdir(dir)) != NULL) {
119 if (strstr(entry->d_name,
".so") != NULL) {
120 snprintf(path,
sizeof(path),
"%s/%s", plugin_path, entry->d_name);
126 InitPlugin(plugin_path);
130 void SCPluginsLoad(
const char *capture_plugin_name,
const char *capture_plugin_args,
131 const char **additional_plugins)
137 LoadPluginsFromPath(plugin->
val);
141 if (additional_plugins != NULL) {
142 for (
int i = 0; additional_plugins[i] != NULL; i++) {
143 LoadPluginsFromPath(additional_plugins[i]);
149 if (capture == NULL) {
150 FatalError(
"No capture plugin found with name %s", capture_plugin_name);
168 if (strcmp(
name, plugin->
name) == 0) {