]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
initial integration of hosts into binder
authorRuss Combs <rucombs@cisco.com>
Mon, 17 Nov 2014 20:40:40 +0000 (15:40 -0500)
committerRuss Combs <rucombs@cisco.com>
Mon, 17 Nov 2014 20:40:40 +0000 (15:40 -0500)
35 files changed:
ChangeLog
doc/start.txt
src/detection/detect.cc
src/detection/fpcreate.cc
src/detection/fpcreate.h
src/detection/fpdetect.cc
src/detection/signature.cc
src/file_api/file_service.cc
src/flow/flow.h
src/flow/session.h
src/main/modules.cc
src/main/snort.cc
src/managers/inspector_manager.cc
src/network_inspectors/binder/binder.cc
src/parser/config_file.cc
src/parser/parse_rule.cc
src/parser/parser.cc
src/parser/vars.cc
src/sfip/sfip_t.h
src/stream/ip/ip_defrag.cc
src/stream/ip/ip_session.h
src/stream/stream.h
src/stream/stream_api.cc
src/stream/stream_api.h
src/stream/tcp/stream_paf.cc
src/stream/tcp/stream_tcp.h
src/stream/tcp/tcp_session.cc
src/target_based/sftarget_data.h
src/target_based/sftarget_hostentry.cc
src/target_based/sftarget_hostentry.h
src/target_based/sftarget_protocol_reference.cc
src/target_based/sftarget_protocol_reference.h
src/target_based/sftarget_reader.cc
src/target_based/sftarget_reader.h
src/utils/util.cc

index bab84f61fa693a1e61dfcfed28184f7dae3e4ceb..e7b603e657356efe94066356edc054ec05aa6dfe 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -35,6 +35,7 @@
 -- update from josh
 -- ensure stream normalizations get proper header iff needed
 -- fixed stream_reassemble.direction
+-- initial integration of hosts into binder
 
 127
 -- REG_TEST out logging tcp options for rebuilt packets to match snort bug
index 38b1baabcf34a1a49adb048ee65bb27b80d38410..a1ca1d5d1335ae68aaaf6b1d9a2b14ce2992c259 100644 (file)
@@ -13,7 +13,7 @@ Required:
 
 * LuaJIT from http://luajit.org for configuration and scripting.
 
-* pcap from http://www.tcpdump.org for tcpdump logging.
+* pcap from http://www.tcpdump.org for tcpdump style logging.
 
 * pcre from http://www.pcre.org for regular expression pattern matching.
 
@@ -33,11 +33,12 @@ Optional:
 
 * Optionally built features are listed in the reference section.
 
-* You should build Snort++ with --prefix $install_dir where install_dir is
-  something you can easily delete.
+* You should build Snort++ with an install prefix so that you can easily
+  delete older versions.
 
 * To build with autotools, the usual ./configure, make, make install from
-  the top level directory will suffice.
+  the top level directory will suffice.  If you don't have ./configure,
+  then autoreconf -isvf must be done first.
 
 * To build with Cmake and make, first create a separate directory for the
   build and cd into that directory.  Then:
@@ -69,8 +70,8 @@ Optional:
 
 === Using Lua
 
-* Snort++ needs a lua conf.  use $install_dir/conf/snort.lua, like -c
-   $install_dir/conf/snort.lua.
+* Snort++ needs a lua conf.  You can use $install_dir/conf/snort.lua, like
+  -c $install_dir/conf/snort.lua.
 
 * lua/snort.lua is always the latest working example configuration.
 
index d7c499c981219c51cc60afd9e7d098d319b49bba..0e27ecd90b1c3cee788a701675721d4c66a9e71f 100644 (file)
@@ -59,7 +59,6 @@
 #include "detection_util.h"
 #include "managers/inspector_manager.h"
 #include "managers/event_manager.h"
-#include "target_based/sftarget_protocol_reference.h"
 #include "detection_defines.h"
 #include "protocols/ip.h"
 #include "sfip/sf_ipvar.h"
@@ -468,19 +467,8 @@ bail:
 
     if (!(mode & (CHECK_SRC_PORT | CHECK_DST_PORT)))
     {
-        DEBUG_WRAP(
-            DebugMessage(DEBUG_ATTRIBUTE, "detect.c: CheckAddrPort..."
-                "target-based-protocol=%d,ignoring ports\n",
-                GetProtocolReference(p)););
         return 1;
     }
-    else
-    {
-        DEBUG_WRAP(
-            DebugMessage(DEBUG_ATTRIBUTE, "detect.c: CheckAddrPort..."
-                "target-based-protocol=%d,not ignoring ports\n",
-                GetProtocolReference(p)););
-    }
 
     /* check the packet port against the rule port */
     if( !PortObjectHasPort(po,pkt_port) )
@@ -691,19 +679,8 @@ int CheckSrcPortEqual(Packet *p, RuleTreeNode *rtn_idx,
     /* Check if attributes provided match earlier */
     if (check_ports == 0)
     {
-        DEBUG_WRAP(
-            DebugMessage(DEBUG_ATTRIBUTE, "detect.c: CheckSrcPortEq..."
-                "target-based-protocol=%d,ignoring ports\n",
-                GetProtocolReference(p)););
         return fp_list->next->RuleHeadFunc(p, rtn_idx, fp_list->next, check_ports);
     }
-    else
-    {
-        DEBUG_WRAP(
-            DebugMessage(DEBUG_ATTRIBUTE, "detect.c: CheckSrcPortEq..."
-                "target-based-protocol=%d,not ignoring ports\n",
-                GetProtocolReference(p)););
-    }
     if( PortObjectHasPort(rtn_idx->src_portobject,p->ptrs.sp) )
     {
         DEBUG_WRAP(DebugMessage(DEBUG_DETECT, "  SP match!\n"););
@@ -725,19 +702,8 @@ int CheckSrcPortNotEq(Packet *p, RuleTreeNode *rtn_idx,
     /* Check if attributes provided match earlier */
     if (check_ports == 0)
     {
-        DEBUG_WRAP(
-            DebugMessage(DEBUG_ATTRIBUTE, "detect.c: CheckSrcPortNotEq..."
-                "target-based-protocol=%d,ignoring ports\n",
-                GetProtocolReference(p)););
         return fp_list->next->RuleHeadFunc(p, rtn_idx, fp_list->next, check_ports);
     }
-    else
-    {
-        DEBUG_WRAP(
-            DebugMessage(DEBUG_ATTRIBUTE, "detect.c: CheckSrcPortNotEq..."
-                "target-based-protocol=%d,not ignoring ports\n",
-                GetProtocolReference(p)););
-    }
     if( !PortObjectHasPort(rtn_idx->src_portobject,p->ptrs.sp) )
     {
         DEBUG_WRAP(DebugMessage(DEBUG_DETECT, "  !SP match!\n"););
@@ -759,19 +725,8 @@ int CheckDstPortEqual(Packet *p, RuleTreeNode *rtn_idx,
     /* Check if attributes provided match earlier */
     if (check_ports == 0)
     {
-        DEBUG_WRAP(
-            DebugMessage(DEBUG_ATTRIBUTE, "detect.c: CheckDstPortEq..."
-            "target-based-protocol=%d,ignoring ports\n",
-            GetProtocolReference(p)););
         return fp_list->next->RuleHeadFunc(p, rtn_idx, fp_list->next, check_ports);
     }
-    else
-    {
-        DEBUG_WRAP(
-            DebugMessage(DEBUG_ATTRIBUTE, "detect.c: CheckDstPortEq..."
-            "target-based-protocol=%d,not ignoring ports\n",
-            GetProtocolReference(p)););
-    }
     if( PortObjectHasPort(rtn_idx->dst_portobject,p->ptrs.dp) )
     {
         DEBUG_WRAP(DebugMessage(DEBUG_DETECT, " DP match!\n"););
@@ -793,19 +748,8 @@ int CheckDstPortNotEq(Packet *p, RuleTreeNode *rtn_idx,
     /* Check if attributes provided match earlier */
     if (check_ports == 0)
     {
-        DEBUG_WRAP(
-            DebugMessage(DEBUG_ATTRIBUTE, "detect.c: CheckDstPortNotEq..."
-            "target-based-protocol=%d,ignoring ports\n",
-            GetProtocolReference(p)););
         return fp_list->next->RuleHeadFunc(p, rtn_idx, fp_list->next, check_ports);
     }
-    else
-    {
-        DEBUG_WRAP(
-            DebugMessage(DEBUG_ATTRIBUTE, "detect.c: CheckDstPortNotEq..."
-            "target-based-protocol=%d,not ignoring ports\n",
-            GetProtocolReference(p)););
-    }
     if( !PortObjectHasPort(rtn_idx->dst_portobject,p->ptrs.dp) )
     {
         DEBUG_WRAP(DebugMessage(DEBUG_DETECT, " !DP match!\n"););
index 65a0cd09cec9b7a06a2b7c5c6a6122cc4b0de164..c17eebe8fb5f4f2d030eededee20b0516007bec6 100644 (file)
@@ -54,7 +54,6 @@
 #include "utils/stats.h"
 #include "treenodes.h"
 #include "parser.h"
-#include "target_based/sftarget_reader.h"
 #include "framework/mpse.h"
 #include "framework/ips_option.h"
 #include "managers/mpse_manager.h"
@@ -104,8 +103,6 @@ static const char* const pm_type_strings[PM_TYPE__MAX] =
 #define LOCAL_DEBUG
 */
 
-#include "target_based/sftarget_protocol_reference.h"
-
 static sopg_table_t * ServicePortGroupTableNew(void)
 {
     return (sopg_table_t *)SnortAlloc(sizeof(sopg_table_t));
@@ -2504,8 +2501,6 @@ int fpCreateFastPacketDetection(SnortConfig *sc)
     if (fpDetectGetDebugPrintRuleGroupBuildDetails(fp))
         LogMessage("Rule Maps Done....\n");
 
-    if (IsAdaptiveConfigured()
-            || fpDetectGetDebugPrintFastPatterns(fp))
     {
         if (fpDetectGetDebugPrintRuleGroupBuildDetails(fp))
             LogMessage("Creating Service Based Rule Maps....\n");
index 091344325e7524c619619808525f7316ae047cbe..d8306b1e60ebb7fd3dc8d35b614fd2ef3466dfb8 100644 (file)
 
 #include "hash/sfghash.h"
 #include "pcrm.h"
+#include "target_based/sftarget_protocol_reference.h"
 
 struct SnortConfig;
 
-/*
- *  Max Number of Protocols Supported by Rules in fpcreate.c
- *  for tcp,udp,icmp,ip ... this is an array dimesnion used to
- *  map protocol-ordinals to port_groups ...
- */
-/* This is now defined in sftarget_protocol_refererence.h"
- * #define MAX_PROTOCOL_ORDINAL 8192 */
-#include "target_based/sftarget_protocol_reference.h"
-
 /*
  *  This controls how many fast pattern match contents may be
  *  used/retrieved per rule in fpcreate.c.
index a1679d28919858c362ff32672338c68843b13551..227ff3d91c54f4ab8cbfe901880e209863cd274b 100644 (file)
@@ -64,8 +64,6 @@
 #include "packet_io/active.h"
 #include "ips_options/ips_content.h"
 #include "stream/stream_api.h"
-#include "target_based/sftarget_protocol_reference.h"
-#include "target_based/sftarget_reader.h"
 #include "utils/sflsq.h"
 #include "ppm.h"
 #include "detection_util.h"
@@ -1241,10 +1239,9 @@ static inline int fpEvalHeaderUdp(Packet *p, OTNX_MATCH_DATA *omd)
 {
     PORT_GROUP *src = NULL, *dst = NULL, *gen = NULL;
 
-    if (IsAdaptiveConfigured())
     {
         /* Check for a service/protocol ordinal for this packet */
-        int16_t proto_ordinal = GetProtocolReference(p);
+        int16_t proto_ordinal = p->flow->s5_state.application_protocol;
 
         DEBUG_WRAP( DebugMessage(DEBUG_ATTRIBUTE,"proto_ordinal=%d\n",proto_ordinal););
 
@@ -1314,9 +1311,8 @@ static inline int fpEvalHeaderTcp(Packet *p, OTNX_MATCH_DATA *omd)
 {
     PORT_GROUP *src = NULL, *dst = NULL, *gen = NULL;
 
-    if (IsAdaptiveConfigured())
     {
-        int16_t proto_ordinal = GetProtocolReference(p);
+        int16_t proto_ordinal = p->flow->s5_state.application_protocol;
 
         DEBUG_WRAP(DebugMessage(DEBUG_ATTRIBUTE, "proto_ordinal=%d\n", proto_ordinal););
 
index 3e9773b91666fbc0b0a279bbc578e11341eeecf0..33a8d0b29729dc68add84339873c72c2e9dd5f74 100644 (file)
@@ -32,9 +32,6 @@
 #include "snort.h"
 #include "parser.h"
 
-#include "target_based/sftarget_protocol_reference.h"
-#include "parser.h"
-
 /* for eval and free functions */
 #include "ips_options/ips_content.h"
 
index a82dbfced5002df9b149a7c1cf7914613adb60a5..b440556621137e3aec4f890f9a073faef7bb3f61 100644 (file)
@@ -52,9 +52,6 @@
 #include "detection_util.h"
 #include "service_inspectors/http_inspect/hi_main.h" // FIXIT-M bad dependency; use inspector::get_buf()
 
-#include "target_based/sftarget_protocol_reference.h"
-#include "target_based/sftarget_reader.h"
-
 static bool file_type_id_enabled = false;  // STATIC
 static bool file_signature_enabled = false;
 static bool file_processing_initiated = false;
@@ -1031,7 +1028,6 @@ static void print_file_stats(int exiting)
     }
     LogMessage("   %12s:           " FMTu64("-10") " \n", "Total",verdicts_total);
 
-    if (IsAdaptiveConfigured())
     {
         LogMessage("\nFiles processed by protocol IDs:\n");
         for (i = 0; i < MAX_PROTOCOL_ORDINAL; i++)
index 389946523a77c48b0e3d213b436a7a12eaf115da..6917fcf08d73f482d86180c2e965d94ce4dc8b26 100644 (file)
@@ -258,10 +258,12 @@ public:  // FIXIT-M privatize if possible
     uint16_t client_port;
     uint16_t server_port;
 
+    uint16_t ssn_policy;
     uint16_t session_state;
-    uint8_t  handler[SE_MAX];
 
+    uint8_t  handler[SE_MAX];
     uint8_t  response_count;
+
     uint8_t  inner_client_ttl, inner_server_ttl;
     uint8_t  outer_client_ttl, outer_server_ttl;
 };
index 6ecaff27eeb3813e9b3ed596d2265e74a0dd0719..c737a25030bd7121f98b7bee36de74db40c7737c 100644 (file)
@@ -1,6 +1,6 @@
 /****************************************************************************
  *
-** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+ * Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
  * Copyright (C) 2013-2013 Sourcefire, Inc.
  *
  * This program is free software; you can redistribute it and/or modify
index b43b12ff98e6a120f8d2dd250b4e6e3f2a197891..46a0c562ef0ba6760fa7f479824e1d6ad080a0be 100644 (file)
@@ -1717,11 +1717,11 @@ bool RuleStateModule::end(const char*, int idx, SnortConfig* sc)
 // FIXIT-L these are cloned from ip_module.cc and tcp_module.cc
 
 #define ip_policies \
-    "first | linux | bsd | bsd_right |last | windows | solaris"
+    "unknown | first | linux | bsd | bsd_right |last | windows | solaris"
 
 #define tcp_policies \
-    "first | last | bsd | linux | old-linux | windows | win-2003 | vista " \
-    "solaris | hpux | hpux10 | irix | macos"
+    "unknown | first | last | bsd | linux | old-linux | windows | win-2003 | " \
+    "vista | solaris | hpux | hpux10 | irix | macos"
 
 static const Parameter service_params[] =
 {
@@ -1780,15 +1780,11 @@ bool HostsModule::set(const char*, Value& v, SnortConfig*)
 
     else if ( v.is("frag_policy") )
     {
-        strncpy(host->hostInfo.fragPolicyName, v.get_string(),
-            sizeof(host->hostInfo.fragPolicyName));
-        host->hostInfo.fragPolicy = v.get_long() + 1;
+        host->hostInfo.fragPolicy = v.get_long();
     }
     else if ( v.is("tcp_policy") )
     {
-        strncpy(host->hostInfo.streamPolicyName, v.get_string(),
-            sizeof(host->hostInfo.streamPolicyName));
-        host->hostInfo.streamPolicy = v.get_long() + 1;
+        host->hostInfo.streamPolicy = v.get_long();
     }
     else if ( v.is("name") )
         app->protocol = AddProtocolReference(v.get_string());
index 84e279afad331fb31386a65ed612aa5b7b812aff..5490657b457f0105c5d23afcfc5b2a21c71ff529 100644 (file)
@@ -106,11 +106,11 @@ using namespace std;
 #include "time/periodic.h"
 #include "parser/config_file.h"
 #include "parser/cmd_line.h"
-#include "target_based/sftarget_reader.h"
 #include "stream/stream_api.h"
 #include "stream/stream.h"
 #include "actions/act_replace.h"
 #include "filters/detection_filter.h"
+#include "target_based/sftarget_reader.h"
 
 #ifdef INTEL_SOFT_CPM
 #include "search/intel_soft_cpm.h"
index f34fadabfbcb9f82809fc4ddcca9dc4d84683528..3054b4fc948ebc32d45d5dae872249905262cf96 100644 (file)
@@ -315,6 +315,8 @@ void InspectorManager::delete_policy (InspectionPolicy* pi)
     pi->framework_policy = nullptr;
 }
 
+// FIXIT-L allowing lookup by name or type or key is kinda hinky
+// would be helpful to have specific lookups
 static PHInstance* get_instance(
     FrameworkPolicy* fp, const char* keyword, bool dflt_only = false)
 {
index 0bf416cd2f6d3902c4fe56af0147417aef27781f..5ada24728514f02085f57c705c1271b37c073969 100644 (file)
@@ -24,6 +24,7 @@ using namespace std;
 #include "binding.h"
 #include "bind_module.h"
 #include "flow/flow.h"
+#include "flow/session.h"
 #include "framework/inspector.h"
 #include "framework/plug_data.h"
 #include "stream/stream_splitter.h"
@@ -40,6 +41,9 @@ using namespace std;
 #include "main/snort.h"
 #include "main/policy.h"
 #include "parser/parser.h"
+#include "target_based/sftarget_data.h"
+#include "target_based/sftarget_protocol_reference.h"
+#include "target_based/sftarget_reader.h"
 
 THREAD_LOCAL ProfileStats bindPerfStats;
 
@@ -159,7 +163,7 @@ bool Binding::check_all(const Flow* flow) const
     if ( !check_vlan(flow) )
         return false;
 
-    // FIXIT-H need to check role and addr/ports relative to it
+    // FIXIT-M need to check role and addr/ports relative to it
     if ( !check_addr(flow) )
         return false;
 
@@ -185,6 +189,7 @@ static void set_session(Flow* flow, const char* key)
 
     if ( pin )
     {
+        // FIXIT-M need to set ssn client and server independently
         flow->set_client(pin);
         flow->set_server(pin);
         flow->clouseau = nullptr;
@@ -198,6 +203,18 @@ static void set_session(Flow* flow)
     flow->clouseau = nullptr;
 }
 
+static Inspector* get_gadget(Flow* flow, const HostAttributeEntry* host)
+{
+    stream.set_application_protocol_id_from_host_entry(flow, host, SSN_DIR_SERVER);
+
+    if ( !flow->s5_state.application_protocol )
+        return nullptr;
+
+    const char* s = get_protocol_name(flow->s5_state.application_protocol);
+
+    return InspectorManager::get_inspector(s);
+}
+
 //-------------------------------------------------------------------------
 // stuff stuff
 //-------------------------------------------------------------------------
@@ -222,9 +239,9 @@ struct Stuff
 
     bool update(Binding*);
 
-    void apply_action(Flow*);
-    void apply_session(Flow*);
-    void apply_service(Flow*);
+    bool apply_action(Flow*);
+    void apply_session(Flow*, const HostAttributeEntry*);
+    void apply_service(Flow*, const HostAttributeEntry*);
 };
 
 bool Stuff::update(Binding* pb)
@@ -260,26 +277,27 @@ bool Stuff::update(Binding* pb)
     return false;
 }
 
-void Stuff::apply_action(Flow* flow)
+bool Stuff::apply_action(Flow* flow)
 {
     switch ( action )
     {
     case BA_BLOCK:
         stream.drop_traffic(flow, SSN_DIR_BOTH);
         flow->set_state(Flow::BLOCK);
-        return;
+        return false;
 
     case BA_ALLOW:
         flow->set_state(Flow::ALLOW);
-        return;
+        return false;
 
-    case BA_INSPECT:
-        flow->set_state(Flow::INSPECT);
+    default:
         break;
     }
+    flow->set_state(Flow::INSPECT);
+    return true;
 }
 
-void Stuff::apply_session(Flow* flow)
+void Stuff::apply_session(Flow* flow, const HostAttributeEntry* host)
 {
     if ( server )
     {
@@ -292,10 +310,12 @@ void Stuff::apply_session(Flow* flow)
 
         return;
     }
+
     switch ( flow->protocol )
     {
     case PktType::IP:
         set_session(flow, INS_IP);
+        flow->ssn_policy = host ? host->hostInfo.fragPolicy : 0;
         break;
 
     case PktType::ICMP:
@@ -304,6 +324,7 @@ void Stuff::apply_session(Flow* flow)
 
     case PktType::TCP:
         set_session(flow, INS_TCP);
+        flow->ssn_policy = host ? host->hostInfo.streamPolicy : 0;
         break;
 
     case PktType::UDP:
@@ -315,11 +336,14 @@ void Stuff::apply_session(Flow* flow)
     }
 }
 
-void Stuff::apply_service(Flow* flow)
+void Stuff::apply_service(Flow* flow, const HostAttributeEntry* host)
 {
     if ( data )
         flow->set_data(data);
 
+    if ( host && !gadget )
+        gadget = get_gadget(flow, host);
+
     if ( gadget )
         flow->set_gadget(gadget);
 
@@ -509,13 +533,16 @@ Inspector* Binder::find_gadget(Flow* flow)
 void Binder::apply(Flow* flow, Stuff& stuff)
 {
     // setup action
-    stuff.apply_action(flow);
+    if ( !stuff.apply_action(flow) )
+        return;
+
+    const HostAttributeEntry* host = SFAT_LookupHostEntryByIP(&flow->server_ip);
 
     // setup session
-    stuff.apply_session(flow);
+    stuff.apply_session(flow, host);
 
     // setup service
-    stuff.apply_service(flow);
+    stuff.apply_service(flow, host);
 }
 
 //-------------------------------------------------------------------------
index b4e36ff498dab67ce9ae1f0eaba1b27c801adc62..8287269edf5b6ef8476d55772f3bd1b0eee3b340 100644 (file)
@@ -52,7 +52,6 @@
 #include "ips_options/ips_flowbits.h"
 #include "file_api/file_service_config.h"
 #include "packet_io/sfdaq.h"
-#include "target_based/sftarget_reader.h"
 #include "managers/event_manager.h"
 #include "detection/detect.h"
 #include "sfip/sf_ip.h"
index e719ef28efb1e808304b2b7907fa7260958a7fa9..2a24a11671effca531c1558da170af3e8cc8bd52 100644 (file)
@@ -74,7 +74,6 @@
 #include "managers/so_manager.h"
 #include "config_file.h"
 #include "keywords.h"
-#include "target_based/sftarget_reader.h"
 
 #define SRC  0
 #define DST  1
index b8ec94fc58bab11062ec466ce1b7087061b66225..9bbeea7883b14a58dc277a505b0c8c696052e2d8 100644 (file)
@@ -81,7 +81,6 @@
 #include "parse_rule.h"
 #include "parse_stream.h"
 #include "vars.h"
-#include "target_based/sftarget_reader.h"
 
 static unsigned parse_errors = 0;
 static unsigned parse_warnings = 0;
index eff77dc66dd63c0c7c56e6459e4b521311b5e45f..03e6047fc27ec000b846ac54f9550b407aa2c7c7 100644 (file)
@@ -69,7 +69,6 @@
 #include "framework/ips_option.h"
 #include "config_file.h"
 #include "keywords.h"
-#include "target_based/sftarget_reader.h"
 
 //-------------------------------------------------------------------------
 // var node stuff
index 6a4fbe4a17a0f06790557224e291123c8244a4ee..32bd79f5001b853a63555a91cb34dfa634746b4e 100644 (file)
@@ -77,7 +77,7 @@ struct sfip_t {
 #undef inet_ntoa
 #endif
 
-SO_PUBLIC char *sfip_to_str(const sfip_t *ip);
+SO_PUBLIC char *sfip_to_str(const sfip_t*);
 #define sfip_ntoa(x) sfip_to_str(x)
 #define inet_ntoa sfip_ntoa
 
index bc5b679c21b8c3a1c1f22dbfa4584bc95d57b708..a8d7fc5e8cc765720cc5b7aa3b2898724fca5eaf 100644 (file)
@@ -680,40 +680,6 @@ static int FragHandleIPOptions(FragTracker *ft,
     return 1;
 }
 
-int FragGetPolicy(Packet *p, FragEngine *engine)
-{
-    int frag_policy;
-    /* Not caching this host_entry in the frag tracker so we can
-     * swap the table out after processing this packet if we need
-     * to.  */
-    HostAttributeEntry *host_entry;
-
-    if (!IsAdaptiveConfigured())
-        return engine->frag_policy;
-
-    host_entry = SFAT_LookupHostEntryByDst(p);
-
-    if (host_entry && (isFragPolicySet(host_entry) == POLICY_SET))
-    {
-        frag_policy = getFragPolicy(host_entry);
-
-        if (frag_policy != SFAT_UNKNOWN_FRAG_POLICY)
-        {
-            DEBUG_WRAP(DebugMessage(DEBUG_FRAG,
-                "FragGetPolicy: Policy Map Entry: %d(%s)\n",
-                frag_policy, frag_policy_names[frag_policy]););
-
-            return frag_policy;
-        }
-    }
-
-    DEBUG_WRAP(DebugMessage(DEBUG_FRAG,
-        "FragGetPolicy: Using configured default %d(%s)\n",
-        engine->frag_policy, frag_policy_names[engine->frag_policy]););
-
-    return engine->frag_policy;
-}
-
 /** checks for tiny fragments and raises appropriate alarm
  *
  * @param p Current packet to insert
@@ -1187,82 +1153,6 @@ static void release_tracker(FragTracker* ft)
     t_stats.trackers_released++;
 }
 
-int fragGetApplicationProtocolId(Packet *p)
-{
-    FragTracker *ft;
-    /* Not caching this host_entry in the frag tracker so we can
-     * swap the table out after processing this packet if we need
-     * to.  */
-    HostAttributeEntry *host_entry = NULL;
-    uint16_t src_port = 0;
-    uint16_t dst_port = 0;
-
-    if ( !p->flow || p->flow->protocol != PktType::IP )
-    {
-        return 0;
-    }
-
-    /* Must be a rebuilt frag... */
-    if (!(p->packet_flags & PKT_REBUILT_FRAG))
-    {
-        return 0;
-    }
-
-    ft = &((IpSession*)p->flow->session)->tracker;
-
-    if (ft->application_protocol != 0)
-    {
-        return ft->application_protocol;
-    }
-
-    switch (p->type())
-    {
-    case PktType::TCP:
-        ft->ipprotocol = protocolReferenceTCP;
-        src_port = p->ptrs.sp;
-        dst_port = p->ptrs.dp;
-        break;
-    case PktType::UDP:
-        ft->ipprotocol = protocolReferenceUDP;
-        src_port = p->ptrs.sp;
-        dst_port = p->ptrs.dp;
-        break;
-    case PktType::ICMP:
-        ft->ipprotocol = protocolReferenceICMP;
-        break;
-    default:
-        break;
-    }
-
-    host_entry = SFAT_LookupHostEntryBySrc(p);
-    if (host_entry)
-    {
-        ft->application_protocol = getApplicationProtocolId(host_entry,
-                                    ft->ipprotocol,
-                                    src_port,
-                                    SFAT_SERVICE);
-        if (ft->application_protocol != 0)
-        {
-            return ft->application_protocol;
-        }
-    }
-
-    host_entry = SFAT_LookupHostEntryByDst(p);
-    if (host_entry)
-    {
-        ft->application_protocol = getApplicationProtocolId(host_entry,
-                                    ft->ipprotocol,
-                                    dst_port,
-                                    SFAT_SERVICE);
-        if (ft->application_protocol != 0)
-        {
-            return ft->application_protocol;
-        }
-    }
-
-    return ft->application_protocol;
-}
-
 //-------------------------------------------------------------------------
 // Defrag methods
 //-------------------------------------------------------------------------
@@ -2314,7 +2204,7 @@ int Defrag::new_tracker(Packet *p, FragTracker* ft)
     ft->ip_options_data = NULL;
     ft->copied_ip_options_len = 0;
     ft->ordinal = 0;
-    ft->frag_policy = FragGetPolicy(p, &engine);
+    ft->frag_policy = p->flow->ssn_policy ? p->flow->ssn_policy : engine.frag_policy;
     ft->engine = &engine;
 
     /*
index 38163b033e5e6f7e8534ce123e22522df6d66f82..996ee3029a72fe3e6207852cd10a0208f50b913f 100644 (file)
@@ -75,7 +75,7 @@ class IpSession : public Session
 public:
     IpSession(Flow*);
 
-    bool setup (Packet*) override;
+    bool setup(Packet*) override;
     int process(Packet*) override;
     void clear() override;
 
index cf041f6d717451ab790b0f0d695bee37c12cfb27..4b9b666871c7a8b79285b4bc42725a71c0ff0ffe 100644 (file)
@@ -1,6 +1,6 @@
 /****************************************************************************
  *
-** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+ * Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
  * Copyright (C) 2005-2013 Sourcefire, Inc.
  *
  * This program is free software; you can redistribute it and/or modify
 #include <sys/types.h>
 #include <netinet/in.h>
 
-#include "target_based/sftarget_protocol_reference.h"
 #include "framework/counts.h"
 #include "utils/bitop_funcs.h"
 #include "framework/inspector.h"
-
 #include "snort_types.h"
 #include "snort.h"
 #include "detect.h"
 #include "stream/stream_api.h"
-
-#include "target_based/sftarget_hostentry.h"
+#include "target_based/sftarget_protocol_reference.h"
 
 //#define DEBUG_STREAM5 DEBUG
 
@@ -107,7 +104,7 @@ struct Stream5Config
 };
 
 #if 0
-FIXIT-1 delete?
+FIXIT-M delete?
 typedef struct {
     PegCount  filtered;
     PegCount  inspected;
index a20fadfac8cea9092beb1a6ebcdb5eaf7a4f10b0..064094eab82be231968a0dffb2b97f4c663e5e5d 100644 (file)
@@ -58,7 +58,6 @@
 #include "target_based/sftarget_protocol_reference.h"
 #include "target_based/sftarget_hostentry.h"
 
-
 Stream stream;  // FIXIT-L global for SnortContext
 
 Stream::Stream()
@@ -386,7 +385,7 @@ int Stream::set_application_protocol_id_expected(
 }
 
 void Stream::set_application_protocol_id_from_host_entry(
-    Flow* flow, HostAttributeEntry *host_entry, int direction)
+    Flow* flow, const HostAttributeEntry *host_entry, int direction)
 {
     int16_t application_protocol;
 
@@ -406,13 +405,13 @@ void Stream::set_application_protocol_id_from_host_entry(
     {
         application_protocol = getApplicationProtocolId(
             host_entry, flow->s5_state.ipprotocol,
-            ntohs(flow->server_port), SFAT_SERVICE);
+            flow->server_port, SFAT_SERVICE);
     }
     else
     {
         application_protocol = getApplicationProtocolId(
             host_entry, flow->s5_state.ipprotocol,
-            ntohs(flow->client_port), SFAT_SERVICE);
+            flow->client_port, SFAT_SERVICE);
 
         if ( application_protocol &&
             (flow->s5_state.session_flags & SSNFLAG_MIDSTREAM) )
@@ -442,9 +441,6 @@ int16_t Stream::get_application_protocol_id(Flow* flow)
     if (flow->s5_state.application_protocol != 0)
         return flow->s5_state.application_protocol;
 
-    if (!IsAdaptiveConfigured())
-        return flow->s5_state.application_protocol;
-
     if (flow->s5_state.ipprotocol == 0)
     {
         set_ip_protocol(flow);
@@ -483,9 +479,6 @@ int16_t Stream::set_application_protocol_id(Flow* flow, int16_t id)
     if (!flow)
         return 0;
 
-    if (!IsAdaptiveConfigured())
-        return 0;
-
     if (flow->s5_state.application_protocol != id)
     {
         flow->s5_state.application_protocol = id;
@@ -495,7 +488,7 @@ int16_t Stream::set_application_protocol_id(Flow* flow, int16_t id)
         set_ip_protocol(flow);
 
     SFAT_UpdateApplicationProtocol(
-        &flow->server_ip, ntohs(flow->server_port),
+        &flow->server_ip, flow->server_port,
         flow->s5_state.ipprotocol, id);
 
     return id;
index 5dc67cb62099b31d154ccf5eda5414fa40dc8c79..fde7277b959400357eaf289d7000c955be8dc015 100644 (file)
@@ -300,7 +300,7 @@ public:
     void update_direction(Flow*, char dir, const sfip_t *ip, uint16_t port);
 
     static void set_application_protocol_id_from_host_entry(
-        Flow *lwssn, struct _HostAttributeEntry *host_entry, int direction);
+        Flow*, const struct HostAttributeEntry*, int direction);
 
     static uint32_t set_session_flags(Flow*, uint32_t flags);
     static uint32_t get_session_flags(Flow*);
index c22dbdf09cd5dd2c0cdb145a959aff9816fa6e22..40b95d197b9520255841549fb63413a51a2a1a01 100644 (file)
@@ -51,7 +51,6 @@
 #include "snort.h"
 #include "stream/stream.h"
 #include "stream/stream_api.h"
-#include "target_based/sftarget_protocol_reference.h"
 
 //--------------------------------------------------------------------
 // private state
index c2be544089516771905952d8cce80220f24eb06b..291b5cbf068975ba5480ad874567a4afd1d7c22a 100644 (file)
@@ -25,7 +25,6 @@
 #include "flow/flow.h"
 #include "stream/stream_api.h"
 #include "protocols/packet.h"
-#include "target_based/sftarget_protocol_reference.h"
 #include "framework/bits.h"
 
 struct StreamTcpConfig
index 9bb11556b03b08d11f5c4fb2df174f6c1e60eddf..a6976e30f8ae15d8f139be2c4da0bdb666bedad5 100644 (file)
@@ -2415,30 +2415,6 @@ int Stream5FlushListener(Packet *p, Flow *lwssn)
     return flushed;
 }
 
-void TcpSession::restart(Packet* p)
-{
-    StreamTracker* talker, * listener;
-    TcpSession* tcpssn = (TcpSession*)p->flow->session;
-
-    if ( p->packet_flags & PKT_FROM_SERVER )
-    {
-        talker = &tcpssn->server;
-        listener = &tcpssn->client;
-    }
-    else
-    {
-        talker = &tcpssn->client;
-        listener = &tcpssn->server;
-    }
-
-    // FIXTHIS-H on data / on ack must be based on flush policy
-    if ( p->dsize > 0 )
-        CheckFlushPolicyOnData(this, talker, listener, p);
-
-    if ( p->ptrs.tcph->is_ack() )
-        CheckFlushPolicyOnAck(this, talker, listener, p);
-}
-
 int Stream5FlushTalker(Packet *p, Flow *lwssn)
 {
     StreamTracker *talker = NULL;
@@ -4116,69 +4092,24 @@ static int ProcessTcpData(
     return S5_UNALIGNED;
 }
 
-uint16_t StreamGetPolicy(
-    Flow *lwssn, StreamTcpConfig *config, int direction)
-{
-    uint16_t policy_id;
-    /* Not caching this host_entry in the frag tracker so we can
-     * swap the table out after processing this packet if we need
-     * to.  */
-    HostAttributeEntry *host_entry = NULL;
-    int ssn_dir;
-
-    if (!IsAdaptiveConfigured())
-        return config->policy;
-
-    if (direction == FROM_CLIENT)
-    {
-        host_entry = SFAT_LookupHostEntryByIP(&lwssn->server_ip);
-        ssn_dir = SSN_DIR_SERVER;
-    }
-    else
-    {
-        host_entry = SFAT_LookupHostEntryByIP(&lwssn->client_ip);
-        ssn_dir = SSN_DIR_CLIENT;
-    }
-    if (host_entry && (isStreamPolicySet(host_entry) == POLICY_SET))
-    {
-        policy_id = getStreamPolicy(host_entry);
-
-        if (policy_id != SFAT_UNKNOWN_STREAM_POLICY)
-        {
-            STREAM5_DEBUG_WRAP(DebugMessage(DEBUG_STREAM_STATE,
-                "StreamGetPolicy: Policy Map Entry: %d(%s)\n",
-                policy_id, reassembly_policy_names[policy_id]););
-
-            /* Since we've already done the lookup, try to get the
-             * application protocol id with that host_entry. */
-            stream.set_application_protocol_id_from_host_entry(lwssn, host_entry, ssn_dir);
-            return policy_id;
-        }
-    }
-
-    STREAM5_DEBUG_WRAP(DebugMessage(DEBUG_STREAM_STATE,
-        "StreamGetPolicy: Using configured default %d(%s)\n",
-        config->policy, reassembly_policy_names[config->policy]););
-
-    return config->policy;
-}
-
 void SetTcpReassemblyPolicy(StreamTracker *st)
 {
     st->reassembly_policy = GetTcpReassemblyPolicy(st->os_policy);
 }
 
-static void SetOSPolicy(TcpSession *tcpssn)
+static void SetOSPolicy(Flow* flow, TcpSession *tcpssn)
 {
-    if (tcpssn->client.os_policy == 0)
+    if ( !tcpssn->client.os_policy )
     {
-        tcpssn->client.os_policy = StreamGetPolicy(tcpssn->flow, tcpssn->client.config, FROM_SERVER);
+        tcpssn->client.os_policy = flow->ssn_policy ? flow->ssn_policy :
+            tcpssn->client.config->policy;
         SetTcpReassemblyPolicy(&tcpssn->client);
     }
 
-    if (tcpssn->server.os_policy == 0)
+    if ( !tcpssn->server.os_policy )
     {
-        tcpssn->server.os_policy = StreamGetPolicy(tcpssn->flow, tcpssn->server.config, FROM_CLIENT);
+        tcpssn->server.os_policy = flow->ssn_policy ? flow->ssn_policy :
+            tcpssn->server.config->policy;
         SetTcpReassemblyPolicy(&tcpssn->server);
     }
 }
@@ -4300,7 +4231,7 @@ static void NewTcpSession(
         if (lwssn->s5_state.session_flags & SSNFLAG_RESET)
             lwssn->s5_state.session_flags &= ~SSNFLAG_RESET;
 
-        SetOSPolicy(tmp);
+        SetOSPolicy(lwssn, tmp);
 
         if ( (lwssn->s5_state.session_flags & SSNFLAG_CLIENT_SWAP) &&
             !(lwssn->s5_state.session_flags & SSNFLAG_CLIENT_SWAPPED) )
@@ -5056,8 +4987,7 @@ static int ProcessTcp(
     if ((p->dsize) && p->ptrs.tcph->is_syn())
     {
         /* MacOS accepts data on SYN, so don't alert if policy is MACOS */
-        if (StreamGetPolicy(lwssn, config, FROM_CLIENT) !=
-            STREAM_POLICY_MACOS)
+        if ( talker->os_policy != STREAM_POLICY_MACOS)
         {
             if ( Normalize_IsEnabled(NORM_TCP_TRIM) )
             {
@@ -6672,6 +6602,30 @@ void TcpSession::clear()
         TcpSessionClear(flow, this, 1);
 }
 
+void TcpSession::restart(Packet* p)
+{
+    StreamTracker* talker, * listener;
+    TcpSession* tcpssn = (TcpSession*)p->flow->session;
+
+    if ( p->packet_flags & PKT_FROM_SERVER )
+    {
+        talker = &tcpssn->server;
+        listener = &tcpssn->client;
+    }
+    else
+    {
+        talker = &tcpssn->client;
+        listener = &tcpssn->server;
+    }
+
+    // FIXTHIS-H on data / on ack must be based on flush policy
+    if ( p->dsize > 0 )
+        CheckFlushPolicyOnData(this, talker, listener, p);
+
+    if ( p->ptrs.tcph->is_ack() )
+        CheckFlushPolicyOnAck(this, talker, listener, p);
+}
+
 void TcpSession::update_direction(
     char dir, const sfip_t *ip, uint16_t port)
 {
index 8a45c33fe0a720ba9d440ca257a3c1044bd416ee..439264ace6ab9fc638ed311868099c416feef106 100644 (file)
@@ -66,30 +66,23 @@ typedef ApplicationEntry ApplicationList;
 #define HOST_INFO_VERSION 3
 #define HOST_INFO_FRAG_POLICY 4
 #define HOST_INFO_STREAM_POLICY 5
-#define POLICY_SET 1
-#define POLICY_NOT_SET 0
-typedef struct _HostInfo
-{
-    char streamPolicyName[16];
-    char fragPolicyName[16];
-
-    uint16_t streamPolicy;
-    uint16_t fragPolicy;
 
-    char streamPolicySet;
-    char fragPolicySet;
-} HostInfo;
+struct HostInfo
+{
+    uint8_t streamPolicy;
+    uint8_t fragPolicy;
+};
 
 #define SFAT_SERVICE 1
 #define SFAT_CLIENT 2
-typedef struct _HostAttributeEntry
+
+struct HostAttributeEntry
 {
     sfip_t ipAddr;
-
     HostInfo hostInfo;
     ApplicationList *services;
     ApplicationList *clients;
-} HostAttributeEntry;
+};
 
 int SFAT_AddHost(HostAttributeEntry*);
 int SFAT_AddService(HostAttributeEntry*, ApplicationEntry*);
index d27d96c14840ea41bf270c35eb43edb1d14dccf9..1686ba1daa1b89713329ca6e6625f40597b3b6da 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "sftarget_hostentry.h"
 
-int hasService(HostAttributeEntry *host_entry,
+int hasService(const HostAttributeEntry *host_entry,
                int ipprotocol,
                int protocol,
                int application)
@@ -61,7 +61,7 @@ int hasService(HostAttributeEntry *host_entry,
     return SFTARGET_NOMATCH;
 }
 
-int hasClient(HostAttributeEntry *host_entry,
+int hasClient(const HostAttributeEntry *host_entry,
                int ipprotocol,
                int protocol,
                int application)
@@ -97,7 +97,7 @@ int hasClient(HostAttributeEntry *host_entry,
     return SFTARGET_NOMATCH;
 }
 
-int hasProtocol(HostAttributeEntry *host_entry,
+int hasProtocol(const HostAttributeEntry *host_entry,
                int ipprotocol,
                int protocol,
                int application)
@@ -115,47 +115,23 @@ int hasProtocol(HostAttributeEntry *host_entry,
     return ret;
 }
 
-char isFragPolicySet(HostAttributeEntry *host_entry)
-{
-    if (host_entry && host_entry->hostInfo.fragPolicySet)
-    {
-        return POLICY_SET;
-    }
-    return POLICY_NOT_SET;
-}
-
-char isStreamPolicySet(HostAttributeEntry *host_entry)
-{
-    if (host_entry && host_entry->hostInfo.streamPolicySet)
-    {
-        return POLICY_SET;
-    }
-    return POLICY_NOT_SET;
-}
-
-uint16_t getFragPolicy(HostAttributeEntry *host_entry)
+uint16_t getFragPolicy(const HostAttributeEntry *host_entry)
 {
     if (!host_entry)
         return SFAT_UNKNOWN_FRAG_POLICY;
 
-    if (!host_entry->hostInfo.fragPolicySet)
-        return SFAT_UNKNOWN_FRAG_POLICY;
-
     return host_entry->hostInfo.fragPolicy;
 }
 
-uint16_t getStreamPolicy(HostAttributeEntry *host_entry)
+uint16_t getStreamPolicy(const HostAttributeEntry *host_entry)
 {
     if (!host_entry)
         return SFAT_UNKNOWN_STREAM_POLICY;
 
-    if (!host_entry->hostInfo.streamPolicySet)
-        return SFAT_UNKNOWN_STREAM_POLICY;
-
     return host_entry->hostInfo.streamPolicy;
 }
 
-int getApplicationProtocolId(HostAttributeEntry *host_entry,
+int getApplicationProtocolId(const HostAttributeEntry *host_entry,
                int ipprotocol,
                uint16_t port,
                char direction)
index c4d934ae93feee481942606ad39c819fa154f2d9..043559672989b2d4fad1a78109c303d158a97533 100644 (file)
 
 /* API for HostAttributeEntry 'class' */
 
-int hasService(HostAttributeEntry *hostEntry,
+int hasService(const HostAttributeEntry *hostEntry,
                int ipprotocol,
                int protocol,
                int application);
-int hasClient(HostAttributeEntry *hostEntry,
+int hasClient(const HostAttributeEntry *hostEntry,
                int ipprotocol,
                int protocol,
                int application);
-int hasProtocol(HostAttributeEntry *hostEntry,
+int hasProtocol(const HostAttributeEntry *hostEntry,
                int ipprotocol,
                int protocol,
                int application);
 
-int getProtocol(HostAttributeEntry *hostEntry,
+int getProtocol(const HostAttributeEntry *hostEntry,
                int ipprotocol,
                uint16_t port);
 
-int getApplicationProtocolId(HostAttributeEntry *host_entry,
+int getApplicationProtocolId(const HostAttributeEntry *host_entry,
                int ipprotocol,
                uint16_t port,
                char direction);
 
 #define SFAT_UNKNOWN_STREAM_POLICY 0
-uint16_t getStreamPolicy(HostAttributeEntry *host_entry);
-char isStreamPolicySet(HostAttributeEntry *host_entry);
+uint16_t getStreamPolicy(const HostAttributeEntry *host_entry);
 #define SFAT_UNKNOWN_FRAG_POLICY 0
-uint16_t getFragPolicy(HostAttributeEntry *host_entry);
-char isFragPolicySet(HostAttributeEntry *host_entry);
+uint16_t getFragPolicy(const HostAttributeEntry *host_entry);
+
+#endif
 
-#endif /* SFTARGET_HOSTENTRY_H */
index 81156ac3435c7dfa0ffcf344f1fd47b6bc7f3404..2e1718e78ce59f8294529d3b8f392f4b0cb17f4b 100644 (file)
 
 #include "sftarget_protocol_reference.h"
 
+#include <string>
+#include <vector>
+using namespace std;
+
 #include "hash/sfghash.h"
 #include "util.h"
 #include "snort_debug.h"
@@ -46,6 +50,16 @@ int16_t protocolReferenceICMP;
 static SFGHASH *proto_reference_table = NULL;  // STATIC
 static int16_t protocol_number = 1;
 
+static vector<string> id_map;
+
+const char* get_protocol_name(uint16_t id)
+{
+    if ( id >= id_map.size() )
+        id = 0;
+
+    return id_map[id].c_str();
+}
+
 /* XXX XXX Probably need to do this during swap time since the
  * proto_reference_table is accessed during runtime */
 int16_t AddProtocolReference(const char *protocol)
@@ -65,6 +79,11 @@ int16_t AddProtocolReference(const char *protocol)
         return reference->ordinal;
     }
 
+    if ( protocol_number == 1 )
+        id_map.push_back("unknown");
+
+    id_map.push_back(protocol);
+
     reference = (SFTargetProtocolReference*)SnortAlloc(sizeof(SFTargetProtocolReference));
     reference->ordinal = protocol_number++;
     if (protocol_number > MAX_PROTOCOL_ORDINAL)
index 5fa72bf6935f42a83852914e8e35582803cd18d2..fcfc721cd5f7c6394ad2317c8a01dbb1ffd3db00 100644 (file)
@@ -37,6 +37,7 @@ extern int16_t protocolReferenceICMP;
 void InitializeProtocolReferenceTable(void);
 void FreeProtoocolReferenceTable(void);
 
+const char* get_protocol_name(uint16_t id);
 int16_t AddProtocolReference(const char *protocol);
 SO_PUBLIC int16_t FindProtocolReference(const char *protocol);
 
index 95a0877c43b40fb8fe25c4ff46a1ba874e73dbfe..e4bf304761ebe03e38fecb6dd816a45851337bd3 100644 (file)
@@ -183,11 +183,8 @@ int SFAT_AddApplicationData(HostAttributeEntry* host, ApplicationEntry* app)
 
     if ((app->fields & required_fields) != required_fields)
     {
-        sfip_t host_addr;
-        sfip_set_ip(&host_addr, &host->ipAddr);
-        host_addr.ip32[0] = ntohl(host_addr.ip32[0]);
         ParseError("Missing required field in Service attribute table for host %s",
-            inet_ntoa(&host_addr));
+            inet_ntoa(&host->ipAddr));
     }
     AppendApplicationData(&host->services, app);
 
@@ -199,22 +196,21 @@ void PrintHostAttributeEntry(HostAttributeEntry *host)
 {
     ApplicationEntry *app;
     int i = 0;
-    sfip_t host_addr;
 
     if (!host)
         return;
 
-    sfip_set_ip(&host_addr, &host->ipAddr);
-    host_addr.ip32[0] = ntohl(host_addr.ip32[0]);
-
     DebugMessage(DEBUG_ATTRIBUTE, "Host IP: %s/%d\n",
-            inet_ntoa(&host_addr),
-            host->ipAddr.bits
-            );
-    DebugMessage(DEBUG_ATTRIBUTE, "\tPolicy Information: frag:%s (%s %u) stream: %s (%s %u)\n",
-            host->hostInfo.fragPolicyName, host->hostInfo.fragPolicySet ? "set":"unset", host->hostInfo.fragPolicy,
-            host->hostInfo.streamPolicyName, host->hostInfo.streamPolicySet ? "set":"unset", host->hostInfo.streamPolicy);
+        inet_ntoa(&host->ipAddr),
+        host->ipAddr.bits);
+
+    DebugMessage(DEBUG_ATTRIBUTE,
+        "\tPolicy Information: frag:%s (%u) stream: %s (%u)\n",
+        "look-me-up", host->hostInfo.fragPolicy,
+        "look-me-up", host->hostInfo.streamPolicy);
+
     DebugMessage(DEBUG_ATTRIBUTE, "\tServices:\n");
+
     for (i=0, app = host->services; app; app = app->next,i++)
     {
         DebugMessage(DEBUG_ATTRIBUTE, "\tService #%d:\n", i);
@@ -293,24 +289,11 @@ int SFAT_AddHostEntryToMap(HostAttributeEntry* host)
 HostAttributeEntry *SFAT_LookupHostEntryByIP(const sfip_t *ipAddr)
 {
     HostAttributeEntry *host = NULL;
-    sfip_t local_ipAddr;
 
     if ( !curr_cfg )
         return NULL;
 
-    sfip_set_ip(&local_ipAddr, ipAddr);
-    if (local_ipAddr.family == AF_INET)
-    {
-        local_ipAddr.ip32[0] = ntohl(local_ipAddr.ip32[0]);
-    }
-
-    host = (HostAttributeEntry*)sfrt_lookup(&local_ipAddr, curr_cfg->lookupTable);
-
-    if (host)
-    {
-        /* Set the policy values for Frag & Stream if not already set */
-        //TODO: SetTargetBasedPolicy(host);
-    }
+    host = (HostAttributeEntry*)sfrt_lookup((void*)ipAddr, curr_cfg->lookupTable);
 
     return host;
 }
@@ -380,27 +363,14 @@ tTargetBasedConfig* SFAT_Swap()
     return curr_cfg;
 }
 
-int IsAdaptiveConfigured()
-{
-    if ( curr_cfg || next_cfg )
-        return 1;
-
-    return 0;
-}
-
 void SFAT_UpdateApplicationProtocol(sfip_t *ipAddr, uint16_t port, uint16_t protocol, uint16_t id)
 {
     HostAttributeEntry *host_entry;
     ApplicationEntry *service;
-    sfip_t local_ipAddr;
     unsigned service_count = 0;
     int rval;
 
-    sfip_set_ip(&local_ipAddr, ipAddr);
-    if (local_ipAddr.family == AF_INET)
-        local_ipAddr.ip32[0] = ntohl(local_ipAddr.ip32[0]);
-
-    host_entry = (HostAttributeEntry*)sfrt_lookup(&local_ipAddr, curr_cfg->lookupTable);
+    host_entry = (HostAttributeEntry*)sfrt_lookup(ipAddr, curr_cfg->lookupTable);
 
     if (!host_entry)
     {
@@ -408,9 +378,10 @@ void SFAT_UpdateApplicationProtocol(sfip_t *ipAddr, uint16_t port, uint16_t prot
             return;
 
         host_entry = (HostAttributeEntry*)SnortAlloc(sizeof(*host_entry));
-        sfip_set_ip(&host_entry->ipAddr, &local_ipAddr);
-        if ((rval = sfrt_insert(&local_ipAddr, (unsigned char)local_ipAddr.bits, host_entry,
-                                RT_FAVOR_SPECIFIC, curr_cfg->lookupTable)) != RT_SUCCESS)
+        sfip_set_ip(&host_entry->ipAddr, ipAddr);
+
+        if ((rval = sfrt_insert(ipAddr, (unsigned char)ipAddr->bits, host_entry,
+            RT_FAVOR_SPECIFIC, curr_cfg->lookupTable)) != RT_SUCCESS)
         {
             FreeHostEntry(host_entry);
             return;
index 28154c28de21e36b794b7161f1022710a2328fd8..1938e5a8fa5124ad19d70c0f719955800ff61d67 100644 (file)
@@ -63,8 +63,5 @@ tTargetBasedConfig* SFAT_GetConfig();
 void SFAT_SetConfig(tTargetBasedConfig*);
 void SFAT_Free(tTargetBasedConfig*);
 
-/* Returns whether this has been configured */
-int IsAdaptiveConfigured();
-
-#endif /* SFTARGET_READER_H */
+#endif
 
index 6ea4b17bff3f89a011f12d4ad98e621d25d921f6..bfea29a76bd0e055b96f2b02fcfe49d9ca7a0370 100644 (file)
@@ -59,7 +59,6 @@
 #include "ppm.h"
 #include "packet_io/active.h"
 #include "packet_time.h"
-#include "target_based/sftarget_reader.h"
 #include "stream/stream.h"
 
 #ifdef PATH_MAX