From: Mike Stepanek (mstepane) Date: Wed, 26 Jun 2019 22:39:52 +0000 (-0400) Subject: Merge pull request #1655 in SNORT/snort3 from ~AMSATHYA/snort3:identity_plugin to... X-Git-Tag: 3.0.0-258~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f31d1eeb54b01e7b217495ae5e84d1247832f01;p=thirdparty%2Fsnort3.git Merge pull request #1655 in SNORT/snort3 from ~AMSATHYA/snort3:identity_plugin to master Squashed commit of the following: commit c02b0069cf999ed917432358ee7df8c5734b0bf0 Author: haow3 Date: Mon Jun 24 12:56:26 2019 -0400 flow: Extend stash to support uint32_t and make it SO_PUBLIC --- diff --git a/src/flow/flow_stash.cc b/src/flow/flow_stash.cc index 7a9681cba..13a2f3156 100644 --- a/src/flow/flow_stash.cc +++ b/src/flow/flow_stash.cc @@ -18,6 +18,10 @@ // flow_stash.cc author Shravan Rangaraju +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "flow_stash.h" #include @@ -46,6 +50,11 @@ bool FlowStash::get(const string& key, int32_t& val) return get(key, val, STASH_ITEM_TYPE_INT32); } +bool FlowStash::get(const string& key, uint32_t& val) +{ + return get(key, val, STASH_ITEM_TYPE_UINT32); +} + bool FlowStash::get(const string& key, string& val) { return get(key, val, STASH_ITEM_TYPE_STRING); @@ -61,6 +70,11 @@ void FlowStash::store(const string& key, int32_t val) store(key, val, STASH_ITEM_TYPE_INT32); } +void FlowStash::store(const string& key, uint32_t val) +{ + store(key, val, STASH_ITEM_TYPE_UINT32); +} + void FlowStash::store(const string& key, const string& val) { store(key, val, STASH_ITEM_TYPE_STRING); diff --git a/src/flow/flow_stash.h b/src/flow/flow_stash.h index 5e53d9844..a422555e3 100644 --- a/src/flow/flow_stash.h +++ b/src/flow/flow_stash.h @@ -31,15 +31,17 @@ namespace snort { -class FlowStash +class SO_PUBLIC FlowStash { public: ~FlowStash(); void reset(); bool get(const std::string& key, int32_t& val); + bool get(const std::string& key, uint32_t& val); bool get(const std::string& key, std::string& val); bool get(const std::string& key, StashGenericObject* &val); void store(const std::string& key, int32_t val); + void store(const std::string& key, uint32_t val); void store(const std::string& key, const std::string& val); void store(const std::string& key, std::string* val); void store(const std::string& key, StashGenericObject* val); diff --git a/src/flow/stash_item.h b/src/flow/stash_item.h index df26f0f47..63daf304c 100644 --- a/src/flow/stash_item.h +++ b/src/flow/stash_item.h @@ -46,6 +46,7 @@ private: enum StashItemType { STASH_ITEM_TYPE_INT32, + STASH_ITEM_TYPE_UINT32, STASH_ITEM_TYPE_STRING, STASH_ITEM_TYPE_GENERIC_OBJECT }; @@ -53,6 +54,7 @@ enum StashItemType union StashItemVal { int32_t int32_val; + uint32_t uint32_val; std::string* str_val; StashGenericObject* generic_obj_val; }; @@ -66,6 +68,12 @@ public: val.int32_val = int32_val; } + StashItem(uint32_t uint32_val) + { + type = STASH_ITEM_TYPE_UINT32; + val.uint32_val = uint32_val; + } + StashItem(const std::string& str_val) { type = STASH_ITEM_TYPE_STRING; @@ -104,6 +112,9 @@ public: void get_val(int32_t& int32_val) const { int32_val = val.int32_val; } + void get_val(uint32_t& uint32_val) const + { uint32_val = val.uint32_val; } + void get_val(std::string& str_val) const { str_val = *(val.str_val); } diff --git a/src/flow/test/flow_stash_test.cc b/src/flow/test/flow_stash_test.cc index 74f554e6d..ffd1200e4 100644 --- a/src/flow/test/flow_stash_test.cc +++ b/src/flow/test/flow_stash_test.cc @@ -209,6 +209,31 @@ TEST(stash_tests, update_int32_item) CHECK_EQUAL(val, 20); } +TEST(stash_tests, new_uint32_item) +{ + FlowStash stash; + + stash.store("item_1", 10u); + + uint32_t val; + + CHECK(stash.get("item_1", val)); + CHECK_EQUAL(val, 10u); +} + +TEST(stash_tests, update_uint32_item) +{ + FlowStash stash; + + stash.store("item_1", 10u); + stash.store("item_1", 20u); + + uint32_t val; + + CHECK(stash.get("item_1", val)); + CHECK_EQUAL(val, 20u); +} + TEST(stash_tests, new_str_item_ref) { FlowStash stash;