]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
Merge pull request #288 in SNORT/snort3 from ~JOCORNET/snort3:lua_logger_updates...
authorRuss Combs (rucombs) <rucombs@cisco.com>
Mon, 29 Feb 2016 20:26:47 +0000 (15:26 -0500)
committerRuss Combs (rucombs) <rucombs@cisco.com>
Mon, 29 Feb 2016 20:26:47 +0000 (15:26 -0500)
Squashed commit of the following:

commit b1fd88ad59a3933f88c4fc35a7946da7785f6bab
Author: Joel Cornett <joel.cornett@gmail.com>
Date:   Fri Feb 26 16:16:02 2016 -0500

    added automake for snort_plugin

commit e749d639e0fc11829ae0a0e02cdee903279fe5fb
Author: Joel Cornett <joel.cornett@gmail.com>
Date:   Tue Feb 23 15:06:05 2016 -0500

    fixed copyright header

commit c5f5f09ee9b4c6848384c46f15d733e7be4e27fd
Author: Joel Cornett <joel.cornett@gmail.com>
Date:   Tue Feb 23 15:01:28 2016 -0500

    added SnortBuffer defs

commit b021bd99e38223b906619216b815e54169b5b45d
Author: Joel Cornett <joel.cornett@gmail.com>
Date:   Tue Feb 23 14:59:21 2016 -0500

    initial

src/ips_options/ips_luajit.cc
src/loggers/alert_luajit.cc
src/managers/CMakeLists.txt
src/managers/Makefile.am
src/managers/ffi_wrap.sh [new file with mode: 0755]
src/managers/lua_plugin_defs.h [new file with mode: 0644]
src/managers/snort_plugin.lua [deleted file]

index d985616ff1d59803f81539939485deff18d6c3d6..b0fac9792536a0fa9a5af73266ad37cd70b8b708 100644 (file)
@@ -25,6 +25,7 @@
 #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"
@@ -41,22 +42,6 @@ static THREAD_LOCAL ProfileStats luaIpsPerfStats;
 
 #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;
 
index fc152e1a880c39faec8e18e566fd389f98c72896..bb5255164e39921ae651d5b1c1926bb3f6ece3bb 100644 (file)
@@ -27,6 +27,7 @@
 #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;
 
index 910c9ff9570a309a423f8042f3d92468fa142dd2..cfb672e9a4f3b89aa8578c61fba08854b509f1ac 100644 (file)
@@ -1,7 +1,7 @@
 
 set (LUA_INCLUDES
     snort_config.lua
-    snort_plugin.lua
+    ${CMAKE_CURRENT_BINARY_DIR}/snort_plugin.lua
 )
 
 add_library( managers
@@ -15,6 +15,7 @@ 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
@@ -40,6 +41,16 @@ target_link_libraries(managers
     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"
 )
index 1f50919cbb650f2db539aa6fbaba37d476f0893f..b650218fe40da746f75fb2dc94351506df9d8fe6 100644 (file)
@@ -19,3 +19,5 @@ plugin_manager.cc plugin_manager.h \
 script_manager.cc script_manager.h \
 so_manager.cc so_manager.h
 
+snort_plugin.lua:
+       $(srcdir)/ffi_wrap.sh $(srcdir)/lua_plugin_defs.h >$@
diff --git a/src/managers/ffi_wrap.sh b/src/managers/ffi_wrap.sh
new file mode 100755 (executable)
index 0000000..418fc36
--- /dev/null
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+cat << EOF
+ffi = require("ffi")
+ffi.cdef[[
+$(grep -v -e '^ *//' -e '^ *#' -e '^ *extern "C"' $1)
+]]
+EOF
diff --git a/src/managers/lua_plugin_defs.h b/src/managers/lua_plugin_defs.h
new file mode 100644 (file)
index 0000000..78274b3
--- /dev/null
@@ -0,0 +1,63 @@
+//--------------------------------------------------------------------------
+// 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
diff --git a/src/managers/snort_plugin.lua b/src/managers/snort_plugin.lua
deleted file mode 100644 (file)
index c36fda7..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
----------------------------------------------------------------------------
--- 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();
-]]
-