#include "helpers/chunk.h"
#include "lua/lua.h"
#include "managers/ips_manager.h"
+#include "managers/lua_plugin_defs.h"
#include "managers/plugin_manager.h"
#include "managers/script_manager.h"
#include "hash/sfhashfcn.h"
#define opt_eval "eval"
-//-------------------------------------------------------------------------
-// ffi stuff
-//-------------------------------------------------------------------------
-
-struct SnortBuffer
-{
- const char* type;
- const uint8_t* data;
- unsigned len;
-};
-
-extern "C" {
-// ensure Lua can link with this
- const SnortBuffer* get_buffer();
-}
-
static THREAD_LOCAL Cursor* cursor;
static THREAD_LOCAL SnortBuffer buf;
#include "log/messages.h"
#include "lua/lua.h"
#include "managers/event_manager.h"
+#include "managers/lua_plugin_defs.h"
#include "managers/module_manager.h"
#include "managers/plugin_manager.h"
#include "managers/script_manager.h"
static THREAD_LOCAL ProfileStats luaLogPerfStats;
-//-------------------------------------------------------------------------
-// ffi stuff
-//
-// IMPORTANT - if you change these structs, you must also update
-// snort_plugins.lua.
-//-------------------------------------------------------------------------
-
-struct SnortEvent
-{
- unsigned gid;
- unsigned sid;
- unsigned rev;
-
- uint32_t event_id;
- uint32_t event_ref;
-
- const char* msg;
- const char* svc;
-};
-
-struct SnortPacket
-{
- // FIXIT-L add ip addrs and other useful foo to lua packet
- const char* type;
- uint64_t num;
- unsigned sp;
- unsigned dp;
-};
-
-extern "C" {
-// ensure Lua can link with this
- const SnortEvent* get_event();
- const SnortPacket* get_packet();
-}
-
static THREAD_LOCAL Event* event;
static THREAD_LOCAL SnortEvent lua_event;
set (LUA_INCLUDES
snort_config.lua
- snort_plugin.lua
+ ${CMAKE_CURRENT_BINARY_DIR}/snort_plugin.lua
)
add_library( managers
inspector_manager.h
ips_manager.cc
ips_manager.h
+ lua_plugin_defs.h
module_manager.cc
module_manager.h
mpse_manager.cc
ips_actions
)
+add_custom_command (
+ OUTPUT snort_plugin.lua
+ COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/ffi_wrap.sh ${CMAKE_CURRENT_SOURCE_DIR}/lua_plugin_defs.h > snort_plugin.lua
+)
+
+add_custom_target ( snort_plugin DEPENDS snort_plugin.lua )
+
+# FIXIT-L probably not the ideal way to ensure this gets built
+add_dependencies ( managers snort_plugin )
+
install (FILES ${LUA_INCLUDES}
DESTINATION "${INCLUDE_INSTALL_PATH}/lua"
)
script_manager.cc script_manager.h \
so_manager.cc so_manager.h
+snort_plugin.lua:
+ $(srcdir)/ffi_wrap.sh $(srcdir)/lua_plugin_defs.h >$@
--- /dev/null
+#!/bin/bash
+
+cat << EOF
+ffi = require("ffi")
+ffi.cdef[[
+$(grep -v -e '^ *//' -e '^ *#' -e '^ *extern "C"' $1)
+]]
+EOF
--- /dev/null
+//--------------------------------------------------------------------------
+// Copyright (C) 2016-2016 Cisco and/or its affiliates. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License Version 2 as published
+// by the Free Software Foundation. You may not use, modify or distribute
+// this program under any other version of the GNU General Public License.
+//
+// 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 along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//--------------------------------------------------------------------------
+// lua_plugin_defs.h
+
+#ifndef LUA_PLUGIN_DEFS_H
+#define LUA_PLUGIN_DEFS_H
+
+#include <stdint.h>
+
+struct SnortBuffer
+{
+ const char* type;
+ const uint8_t* data;
+ unsigned len;
+};
+
+extern "C"
+const struct SnortBuffer* get_buffer();
+
+struct SnortEvent
+{
+ unsigned gid;
+ unsigned sid;
+ unsigned rev;
+
+ uint32_t event_id;
+ uint32_t event_ref;
+
+ const char* msg;
+ const char* svc;
+};
+
+extern "C"
+const struct SnortEvent* get_event();
+
+struct SnortPacket
+{
+ // FIXIT-L add ip addrs and other useful foo to lua packet
+ const char* type;
+ uint64_t num;
+ unsigned sp;
+ unsigned dp;
+};
+
+extern "C"
+const struct SnortPacket* get_packet();
+
+#endif
+++ /dev/null
----------------------------------------------------------------------------
--- Copyright (C) 2014-2016 Cisco and/or its affiliates. All rights reserved.
---
--- This program is free software; you can redistribute it and/or modify it
--- under the terms of the GNU General Public License Version 2 as published
--- by the Free Software Foundation. You may not use, modify or distribute
--- this program under any other version of the GNU General Public License.
---
--- 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 along
--- with this program; if not, write to the Free Software Foundation, Inc.,
--- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
----------------------------------------------------------------------------
--- snort_plugin.lua author Russ Combs <rucombs@cisco.com>
-
-ffi = require("ffi")
-
-ffi.cdef[[
-struct SnortBuffer
-{
- const char* type;
- const uint8_t* data;
- unsigned len;
-};
-const struct SnortBuffer* get_buffer();
-
-struct SnortEvent
-{
- unsigned gid;
- unsigned sid;
- unsigned rev;
-
- uint32_t event_id;
- uint32_t event_ref;
-
- const char* msg;
- const char* svc;
- const char* os;
-};
-const struct SnortEvent* get_event();
-
-struct SnortPacket
-{
- const char* type;
- uint64_t num;
- unsigned sp;
- unsigned dp;
-};
-const struct SnortPacket* get_packet();
-]]
-