]> git.ipfire.org Git - thirdparty/snort3.git/commitdiff
fixed tcp norm counts
authorRuss Combs <rucombs@cisco.com>
Tue, 25 Nov 2014 16:22:12 +0000 (11:22 -0500)
committerRuss Combs <rucombs@cisco.com>
Tue, 25 Nov 2014 16:22:12 +0000 (11:22 -0500)
src/network_inspectors/normalize/norm.cc
src/network_inspectors/normalize/norm.h
src/network_inspectors/normalize/norm_module.cc
src/network_inspectors/normalize/norm_module.h
src/stream/stream.h
src/stream/tcp/tcp_session.cc
src/stream/tcp/tcp_session.h

index 9b465cc62bf9761cc81f28872e0ff6be30901fc9..4210bdbdda938113aa34d857e07263a14de7c6d0 100644 (file)
@@ -63,30 +63,29 @@ typedef enum {
 
 const PegInfo norm_names[] =
 {
-    { "ip4.trim", "eth packets trimmed to datagram size" },
-    { "ip4.tos", "type of service normalizations" },
-    { "ip4.df", "don't frag bit normalizations" },
-    { "ip4.rf", "reserved flag bit clears" },
-    { "ip4.ttl", "time-to-live normalizations" },
-    { "ip4.opts", "ip4 options cleared" },
-    { "icmp4.echo", "icmp4 ping normalizations" },
-    { "ip6.ttl", "ip6 hop limit normalizations" },
-    { "ip6.opts", "ip6 options cleared" },
-    { "icmp6.echo", "icmp6 echo normalizations" },
-    { "tcp.syn_opt", "SYN only options cleared from non-SYN packets" },
-    { "tcp.ts_ecr", "timestamp cleared on non-ACKs" },
-    { "tcp.opt", "packetw with options cleared" },
-    { "tcp.pad", "packetw with padding cleared" },
-    { "tcp.rsv", "packets with reserved bits cleared" },
-    { "tcp.ecn_pkt", "packets with ECN bits cleared" },
-    { "tcp.ns", "packets with nonce bit cleared" },
-    { "tcp.urg", "packets with urgent flag with urgent pointer cleared" },
-    { "tcp.urp", "packets without data with urgent poniter cleared" },
+    { "ip4 trim", "eth packets trimmed to datagram size" },
+    { "ip4 tos", "type of service normalizations" },
+    { "ip4 df", "don't frag bit normalizations" },
+    { "ip4 rf", "reserved flag bit clears" },
+    { "ip4 ttl", "time-to-live normalizations" },
+    { "ip4 opts", "ip4 options cleared" },
+    { "icmp4 echo", "icmp4 ping normalizations" },
+    { "ip6 hops", "ip6 hop limit normalizations" },
+    { "ip6 options", "ip6 options cleared" },
+    { "icmp6 echo", "icmp6 echo normalizations" },
+    { "tcp syn options", "SYN only options cleared from non-SYN packets" },
+    { "tcp ts ecr", "timestamp cleared on non-ACKs" },
+    { "tcp options", "packets with options cleared" },
+    { "tcp paddding", "packets with padding cleared" },
+    { "tcp reserved", "packets with reserved bits cleared" },
+    { "tcp ecn pkt", "packets with ECN bits cleared" },
+    { "tcp nonce", "packets with nonce bit cleared" },
+    { "tcp urgent flag", "packets without urgent flag with urgent pointer cleared" },
+    { "tcp urgent ptr", "packets without data with urgent poniter cleared" },
     { nullptr, nullptr }
 };
 
 static THREAD_LOCAL PegCount normStats[PC_MAX];
-static PegCount gnormStats[PC_MAX];
 
 //static int Norm_Eth(Packet*, uint8_t layer, int changes);
 static int Norm_IP4(NormalizerConfig*, Packet*, uint8_t layer, int changes);
@@ -529,39 +528,13 @@ static int Norm_TCP (
 
 //-----------------------------------------------------------------------
 
-void Norm_SumStats (void)
-{
-    sum_stats((PegCount*)&gnormStats, (PegCount*)&normStats, array_size(norm_names));
-    Stream_SumNormalizationStats();
-}
-
-// need to output the label heading only if not already done
-// the label is emitted only if any counts are non-zero
-// FIXIT-L would prefer to hide this logic in the stats methods somehow
-static bool labeled()
-{
-    unsigned i = 0, max = array_size(norm_names);
-
-    while ( i < max && !gnormStats[i] )
-        ++i;
-
-    return ( i < max );
-}
-
-void Norm_PrintStats (const char* name)
-{
-    show_stats((PegCount*)&gnormStats, norm_names, array_size(norm_names), name);
-
-    if ( labeled() )
-        name = nullptr;
-
-    Stream_PrintNormalizationStats(name);
-}
+const PegInfo* Norm_GetPegs()
+{ return norm_names; }
 
-void Norm_ResetStats (void)
+PegCount* Norm_GetCounts(unsigned& c)
 {
-    memset(gnormStats, 0, sizeof(gnormStats));
-    Stream_ResetNormalizationStats();
+    c = PC_MAX;
+    return normStats;
 }
 
 //-----------------------------------------------------------------------
index ed5ddf28a2460447ae52aae40b58c18a0b0285c2..ef2d92857661927af09214c7b282ccf06d68c483 100644 (file)
@@ -90,9 +90,8 @@ static inline int Norm_TcpIsOptional(const NormalizerConfig* nc, uint8_t opt)
     return ( (nc->normalizer_options[byte] & bit) != 0 );
 }
 
-void Norm_SumStats(void);
-void Norm_PrintStats(const char*);
-void Norm_ResetStats(void);
+const PegInfo* Norm_GetPegs();
+PegCount* Norm_GetCounts(unsigned&);
 
 #endif
 
index 857b7949a083c778c62820e7b07ac237c5a869dd..8a18f8a128c947d18b97358b712bc60a0d028fb0 100644 (file)
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
+ ** Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
  ** Copyright (C) 2010-2013 Sourcefire, Inc.
  **
  ** This program is free software; you can redistribute it and/or modify
@@ -23,6 +23,9 @@
 #include <string.h>
 #include <string>
 #include <sstream>
+#include <vector>
+
+#include "stream/stream.h"
 
 using namespace std;
 
@@ -283,12 +286,40 @@ bool NormalizeModule::end(const char* fqn, int, SnortConfig*)
     return true;
 }
 
-void NormalizeModule::sum_stats()
-{ Norm_SumStats(); }
+const PegInfo* NormalizeModule::get_pegs() const
+{
+    static vector<PegInfo> pegs;
+    pegs.clear();
+
+    const PegInfo* p = Norm_GetPegs();
+
+    while ( p && p->name )
+        pegs.push_back(*p++);
+
+    p = Stream_GetNormPegs();
+
+    while ( p && p->name )
+        pegs.push_back(*p++);
+
+    return &pegs[0];
+}
+
+PegCount* NormalizeModule::get_counts() const
+{
+    static vector<PegCount> counts;
+    counts.clear();
+    unsigned c = 0;
+
+    PegCount* p = Norm_GetCounts(c);
 
-void NormalizeModule::show_stats()
-{ Norm_PrintStats(get_name()); }
+    for ( unsigned i = 0; i < c; ++i )
+        counts.push_back(p[i]);
 
-void NormalizeModule::reset_stats()
-{ Norm_ResetStats(); }
+    p = Stream_GetNormCounts(c);
+
+    for ( unsigned i = 0; i < c; ++i )
+        counts.push_back(p[i]);
+
+    return &counts[0];
+}
 
index f12c1f9baa6b4bffaf56628648324027787b4322..09feb2b6bb804ef3b3d9002e96c6d7760f2efcdb 100644 (file)
 #ifndef NORM_MODULE_H
 #define NORM_MODULE_H
 
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
 #include "framework/module.h"
 #include "norm.h"
 
@@ -44,15 +40,12 @@ public:
     bool end(const char*, int, SnortConfig*) override;
 
     ProfileStats* get_profile() const override;
-    const PegInfo* get_pegs() const override { return norm_names; };
+    const PegInfo* get_pegs() const override;
+    PegCount* get_counts() const override;
 
     const NormalizerConfig* get_config()
     { return &config; };
 
-    void sum_stats() override;
-    void show_stats() override;
-    void reset_stats() override;
-
 private:
     bool set_ip4(const char*, Value&, SnortConfig*);
     bool set_tcp(const char*, Value&, SnortConfig*);
index 473ee7a73e73c554ea2b6d19b1f3ec045e5e5bfc..639af384c75ce7a7250a556199e1c6320e5f5154 100644 (file)
@@ -117,9 +117,8 @@ extern THREAD_LOCAL Memcap* tcp_memcap;
 extern THREAD_LOCAL class FlowControl* flow_con;
 extern const PegInfo base_pegs[];
 
-void Stream_SumNormalizationStats(void);
-void Stream_PrintNormalizationStats(const char* name = nullptr);
-void Stream_ResetNormalizationStats(void);
+const PegInfo* Stream_GetNormPegs();
+PegCount* Stream_GetNormCounts(unsigned&);
 
 #endif
 
index a683c56cf83590da9a70e235da81f1d99a37a4ad..cab72835e0ad7d955381a22dad1465e788aa746b 100644 (file)
@@ -989,32 +989,25 @@ typedef enum {
     PC_MAX
 } PegCounts;
 
-static PegCount gnormStats[PC_MAX];
 static THREAD_LOCAL PegCount normStats[PC_MAX];
 
 static const PegInfo pegName[] =
 {
-    { "tcp.trim", "tcp segments trimmed to correct size" },
-    { "tcp.ecn_ssn", "ECN bits cleared" },
-    { "tcp.ts_nop", "timestamp options cleared" },
-    { "tcp.ips_data", "normalized segments" },
-    { "tcp.block", "blocked segments" },
+    { "tcp trim", "tcp segments trimmed to correct size" },
+    { "tcp ecn session", "ECN bits cleared" },
+    { "tcp ts nop", "timestamp options cleared" },
+    { "tcp ips data", "normalized segments" },
+    { "tcp block", "blocked segments" },
     { nullptr, nullptr }
 };
 
-void Stream_SumNormalizationStats()
-{
-    sum_stats((PegCount*)&gnormStats, (PegCount*)&normStats, array_size(pegName));
-}
-
-void Stream_PrintNormalizationStats (const char* name)
-{
-    show_stats((PegCount*)&gnormStats, pegName, PC_MAX, name);
-}
+const PegInfo* Stream_GetNormPegs()
+{ return pegName; }
 
-void Stream_ResetNormalizationStats (void)
-{
-    memset(gnormStats, 0, sizeof(gnormStats));
+PegCount* Stream_GetNormCounts(unsigned& c)
+{ 
+    c = PC_MAX;
+    return normStats;
 }
 
 //-----------------------------------------------------------------------
index ad4d1e513211534890132cc97f8b4841b9dbde1c..1a5d56fe61ffb5d7aa8637f599b2d4b83b6aed7d 100644 (file)
@@ -228,9 +228,6 @@ private:
     int process_dis(Packet*);
 };
 
-void tcp_sum();
-void tcp_stats();
-void tcp_reset();
 void tcp_show(StreamTcpConfig*);
 
 #endif