Merge remote-tracking branch 'origin/topic/timw/mapping'

- Minor whitespace and comment adjustments

* origin/topic/timw/mapping:
  Fix unit tests for new ordering from NetSessions::Drain
  Change FragReassembler to use a tuple as a key and use std::map for fragments in Sessions
  Rework Session/Connection tracking to use a std::map instead of PDict
This commit is contained in:
Jon Siwek 2019-08-23 06:28:44 -04:00
commit e7a2ee6edc
52 changed files with 573 additions and 555 deletions

View file

@ -3,6 +3,9 @@
#ifndef sessions_h
#define sessions_h
#include <map>
#include <utility>
#include "Dict.h"
#include "CompHash.h"
#include "IP.h"
@ -13,8 +16,6 @@
#include "TunnelEncapsulation.h"
#include "analyzer/protocol/tcp/Stats.h"
#include <utility>
class EncapsulationStack;
class Connection;
class ConnCompressor;
@ -27,20 +28,20 @@ namespace analyzer { namespace stepping_stone { class SteppingStoneManager; } }
namespace analyzer { namespace arp { class ARP_Analyzer; } }
struct SessionStats {
int num_TCP_conns;
int max_TCP_conns;
size_t num_TCP_conns;
size_t max_TCP_conns;
uint64_t cumulative_TCP_conns;
int num_UDP_conns;
int max_UDP_conns;
size_t num_UDP_conns;
size_t max_UDP_conns;
uint64_t cumulative_UDP_conns;
int num_ICMP_conns;
int max_ICMP_conns;
size_t num_ICMP_conns;
size_t max_ICMP_conns;
uint64_t cumulative_ICMP_conns;
int num_fragments;
int max_fragments;
size_t num_fragments;
size_t max_fragments;
uint64_t num_packets;
};
@ -112,8 +113,7 @@ public:
unsigned int CurrentConnections()
{
return tcp_conns.Length() + udp_conns.Length() +
icmp_conns.Length();
return tcp_conns.size() + udp_conns.size() + icmp_conns.size();
}
void DoNextPacket(double t, const Packet *pkt, const IP_Hdr* ip_hdr,
@ -172,10 +172,15 @@ protected:
friend class TimerMgrExpireTimer;
friend class IPTunnelTimer;
Connection* NewConn(HashKey* k, double t, const ConnID* id,
using ConnectionMap = std::map<ConnIDKey, Connection*>;
using FragmentMap = std::map<FragReassemblerKey, FragReassembler*>;
Connection* NewConn(const ConnIDKey& k, double t, const ConnID* id,
const u_char* data, int proto, uint32_t flow_label,
const Packet* pkt, const EncapsulationStack* encapsulation);
Connection* LookupConn(const ConnectionMap& conns, const ConnIDKey& key);
// Check whether the tag of the current packet is consistent with
// the given connection. Returns:
// -1 if current packet is to be completely ignored.
@ -212,11 +217,19 @@ protected:
bool CheckHeaderTrunc(int proto, uint32_t len, uint32_t caplen,
const Packet *pkt, const EncapsulationStack* encap);
CompositeHash* ch;
PDict<Connection> tcp_conns;
PDict<Connection> udp_conns;
PDict<Connection> icmp_conns;
PDict<FragReassembler> fragments;
// Inserts a new connection into the sessions map. If a connection with
// the same key already exists in the map, it will be overwritten by
// the new one. Connection count stats get updated either way (so most
// cases should likely check that the key is not already in the map to
// avoid unnecessary incrementing of connecting counts).
void InsertConnection(ConnectionMap* m, const ConnIDKey& key, Connection* conn);
ConnectionMap tcp_conns;
ConnectionMap udp_conns;
ConnectionMap icmp_conns;
FragmentMap fragments;
SessionStats stats;
typedef pair<IPAddr, IPAddr> IPPair;
typedef pair<EncapsulatingConn, double> TunnelActivity;