1 //-------------------------------------------------------------------------- 2 // Copyright (C) 2014-2021 Cisco and/or its affiliates. All rights reserved. 3 // 4 // This program is free software; you can redistribute it and/or modify it 5 // under the terms of the GNU General Public License Version 2 as published 6 // by the Free Software Foundation. You may not use, modify or distribute 7 // this program under any other version of the GNU General Public License. 8 // 9 // This program is distributed in the hope that it will be useful, but 10 // WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 // General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License along 15 // with this program; if not, write to the Free Software Foundation, Inc., 16 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 //-------------------------------------------------------------------------- 18 // ips_manager.h author Russ Combs <rucombs@cisco.com> 19 20 #ifndef IPS_MANAGER_H 21 #define IPS_MANAGER_H 22 23 // Factory for IpsOptions. 24 // Runtime use of IpsOptions is via detection option tree. 25 26 #include "detection/detection_options.h" 27 #include "framework/ips_option.h" 28 #include "framework/module.h" 29 30 namespace snort 31 { 32 struct IpsApi; 33 class IpsOption; 34 struct SnortConfig; 35 } 36 37 //------------------------------------------------------------------------- 38 39 #ifdef PIGLET 40 struct IpsOptionWrapper 41 { IpsOptionWrapperIpsOptionWrapper42 IpsOptionWrapper(const snort::IpsApi* a, snort::IpsOption* p) : 43 api { a }, instance { p } { } 44 ~IpsOptionWrapperIpsOptionWrapper45 ~IpsOptionWrapper() 46 { 47 if ( api && instance && api->dtor ) 48 api->dtor(instance); 49 } 50 51 const snort::IpsApi* api; 52 snort::IpsOption* instance; 53 }; 54 #endif 55 56 class IpsManager 57 { 58 public: 59 static void add_plugin(const snort::IpsApi*); 60 static void dump_plugins(); 61 static void release_plugins(); 62 static void instantiate(const snort::IpsApi*, snort::Module*, snort::SnortConfig*); 63 64 static bool option_begin(snort::SnortConfig*, const char* key, SnortProtocolId); 65 static bool option_set( 66 snort::SnortConfig*, const char* key, const char* opt, const char* val); 67 static snort::IpsOption* option_end( 68 snort::SnortConfig*, OptTreeNode*, SnortProtocolId, const char* key, snort::RuleOptType&); 69 70 static void delete_option(snort::IpsOption*); 71 static const char* get_option_keyword(); 72 73 SO_PUBLIC static const snort::IpsApi* get_option_api(const char* keyword); 74 75 static void global_init(const snort::SnortConfig*); 76 static void global_term(const snort::SnortConfig*); 77 78 static void reset_options(); 79 static void setup_options(const snort::SnortConfig*); 80 static void clear_options(const snort::SnortConfig*); 81 82 static bool verify(snort::SnortConfig*); 83 84 #ifdef PIGLET 85 static IpsOptionWrapper* instantiate(const char*, snort::Module*, struct OptTreeNode*); 86 #endif 87 }; 88 89 #endif 90 91