Merge in SNORT/snort3 from ~AKAYAMBU/snort3:add_instance_number to master
Squashed commit of the following:
commit
52fa22e84bfcb080b6f94c95f1401d0778b1ee2a
Author: Arunkumar Kayambu <akayambu@cisco.com>
Date: Mon Oct 14 18:00:22 2024 -0400
stream: add thread instance number to dump_flows control command output
switch ( flow.pkt_type )
{
case PktType::IP:
- out << "IP " << flow.key->addressSpaceId << ": " << src_ip << " " << dst_ip;
+ out << "Instance-ID: " << get_relative_instance_number() << " IP " << flow.key->addressSpaceId << ": " << src_ip << " " << dst_ip;
break;
case PktType::ICMP:
- out << "ICMP " << flow.key->addressSpaceId << ": " << src_ip << " type " << src_port << " "
+ out << "Instance-ID: " << get_relative_instance_number() << " ICMP " << flow.key->addressSpaceId << ": " << src_ip << " type " << src_port << " "
<< dst_ip;
break;
case PktType::TCP:
- out << "TCP " << flow.key->addressSpaceId << ": " << src_ip << "/" << src_port << " "
+ out << "Instance-ID: " << get_relative_instance_number() << " TCP " << flow.key->addressSpaceId << ": " << src_ip << "/" << src_port << " "
<< dst_ip << "/" << dst_port;
if (flow.session)
{
break;
case PktType::UDP:
- out << "UDP " << flow.key->addressSpaceId << ": "<< src_ip << "/" << src_port << " "
+ out << "Instance-ID: " << get_relative_instance_number() << " UDP " << flow.key->addressSpaceId << ": "<< src_ip << "/" << src_port << " "
<< dst_ip << "/" << dst_port;
break;
void trace_vprintf(const char*, TraceLevel, const char*, const Packet*, const char*, va_list) {}
unsigned get_instance_id() { return 0; }
+unsigned get_relative_instance_number() { return 1; }
namespace ip
{
performance or behavior. This, alongside with libhwloc, presents an efficient
cross-platform mechanism for thread configuration and managing CPU affinity
of threads, not only considering CPU architecture but also memory access policies,
-providing a more balanced and optimized execution environment.
\ No newline at end of file
+providing a more balanced and optimized execution environment.
+
+use of get_relative_instance_number() in thread.cc:
+
+packet thread's instance_id is zero indexed. id_offset if used will determine
+starting id of the thread relative to all snort processes in a multiprocess environment.
+get_relative_instance_number() is used by dump_flows to print the instance number
+of a thread. Please note relative instance number starts from 1 so thread with
+instance_id 0 will have relative instance number as 1.
+If there are 2 snort processes run in multi process environment each with 3 threads,
+snort process 1 threads will have relative instance number 1,2 and 3.
+The second process's threads will have relative instance number 4,5 and 6.
unsigned get_instance_id()
{ return instance_id; }
+unsigned get_relative_instance_number()
+{
+ // Added +1 here so we get instance numbers starting from 1 for display purposes
+ const SnortConfig* sc = SnortConfig::get_conf();
+ return instance_id + sc->id_offset + 1;
+}
+
SThreadType get_thread_type()
{ return thread_type; }
namespace snort
{
SO_PUBLIC unsigned get_instance_id();
+SO_PUBLIC unsigned get_relative_instance_number();
SO_PUBLIC SThreadType get_thread_type();
SO_PUBLIC inline bool in_main_thread()