From: Russ Combs (rucombs) Date: Mon, 29 Feb 2016 20:26:47 +0000 (-0500) Subject: Merge pull request #288 in SNORT/snort3 from ~JOCORNET/snort3:lua_logger_updates... X-Git-Tag: 3.0.0-233~570 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e56ee55e75d7ae31d6ae76ee13ea7d9564283a9c;p=thirdparty%2Fsnort3.git Merge pull request #288 in SNORT/snort3 from ~JOCORNET/snort3:lua_logger_updates to master Squashed commit of the following: commit b1fd88ad59a3933f88c4fc35a7946da7785f6bab Author: Joel Cornett Date: Fri Feb 26 16:16:02 2016 -0500 added automake for snort_plugin commit e749d639e0fc11829ae0a0e02cdee903279fe5fb Author: Joel Cornett Date: Tue Feb 23 15:06:05 2016 -0500 fixed copyright header commit c5f5f09ee9b4c6848384c46f15d733e7be4e27fd Author: Joel Cornett Date: Tue Feb 23 15:01:28 2016 -0500 added SnortBuffer defs commit b021bd99e38223b906619216b815e54169b5b45d Author: Joel Cornett Date: Tue Feb 23 14:59:21 2016 -0500 initial --- diff --git a/src/ips_options/ips_luajit.cc b/src/ips_options/ips_luajit.cc index d985616ff..b0fac9792 100644 --- a/src/ips_options/ips_luajit.cc +++ b/src/ips_options/ips_luajit.cc @@ -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; diff --git a/src/loggers/alert_luajit.cc b/src/loggers/alert_luajit.cc index fc152e1a8..bb5255164 100644 --- a/src/loggers/alert_luajit.cc +++ b/src/loggers/alert_luajit.cc @@ -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" @@ -41,41 +42,6 @@ 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; diff --git a/src/managers/CMakeLists.txt b/src/managers/CMakeLists.txt index 910c9ff95..cfb672e9a 100644 --- a/src/managers/CMakeLists.txt +++ b/src/managers/CMakeLists.txt @@ -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" ) diff --git a/src/managers/Makefile.am b/src/managers/Makefile.am index 1f50919cb..b650218fe 100644 --- a/src/managers/Makefile.am +++ b/src/managers/Makefile.am @@ -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 index 000000000..418fc36ee --- /dev/null +++ b/src/managers/ffi_wrap.sh @@ -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 index 000000000..78274b337 --- /dev/null +++ b/src/managers/lua_plugin_defs.h @@ -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 + +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 index c36fda7c7..000000000 --- a/src/managers/snort_plugin.lua +++ /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 - -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(); -]] -