mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 08:08:19 +00:00
Rename ConnID and ConnIDKey
This commit is contained in:
parent
0b7ca5e7bc
commit
9684624a52
8 changed files with 39 additions and 35 deletions
|
@ -25,8 +25,8 @@ namespace zeek {
|
||||||
uint64_t Connection::total_connections = 0;
|
uint64_t Connection::total_connections = 0;
|
||||||
uint64_t Connection::current_connections = 0;
|
uint64_t Connection::current_connections = 0;
|
||||||
|
|
||||||
Connection::Connection(const detail::ConnIDKey& k, double t,
|
Connection::Connection(const detail::ConnKey& k, double t,
|
||||||
const ConnID* id, uint32_t flow, const Packet* pkt)
|
const ConnTuple* id, uint32_t flow, const Packet* pkt)
|
||||||
: Session(t, connection_timeout, connection_status_update,
|
: Session(t, connection_timeout, connection_status_update,
|
||||||
detail::connection_status_update_interval),
|
detail::connection_status_update_interval),
|
||||||
key(k)
|
key(k)
|
||||||
|
|
10
src/Conn.h
10
src/Conn.h
|
@ -55,7 +55,7 @@ enum ConnEventToFlag {
|
||||||
NUM_EVENTS_TO_FLAG,
|
NUM_EVENTS_TO_FLAG,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ConnID {
|
struct ConnTuple {
|
||||||
IPAddr src_addr;
|
IPAddr src_addr;
|
||||||
IPAddr dst_addr;
|
IPAddr dst_addr;
|
||||||
uint32_t src_port;
|
uint32_t src_port;
|
||||||
|
@ -64,6 +64,8 @@ struct ConnID {
|
||||||
TransportProto proto;
|
TransportProto proto;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using ConnID [[deprecated("Remove in v5.1. Use zeek::ConnTuple.")]] = ConnTuple;
|
||||||
|
|
||||||
static inline int addr_port_canon_lt(const IPAddr& addr1, uint32_t p1,
|
static inline int addr_port_canon_lt(const IPAddr& addr1, uint32_t p1,
|
||||||
const IPAddr& addr2, uint32_t p2)
|
const IPAddr& addr2, uint32_t p2)
|
||||||
{
|
{
|
||||||
|
@ -73,7 +75,7 @@ static inline int addr_port_canon_lt(const IPAddr& addr1, uint32_t p1,
|
||||||
class Connection final : public session::Session {
|
class Connection final : public session::Session {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Connection(const detail::ConnIDKey& k, double t, const ConnID* id,
|
Connection(const detail::ConnKey& k, double t, const ConnTuple* id,
|
||||||
uint32_t flow, const Packet* pkt);
|
uint32_t flow, const Packet* pkt);
|
||||||
~Connection() override;
|
~Connection() override;
|
||||||
|
|
||||||
|
@ -113,7 +115,7 @@ public:
|
||||||
// Keys are only considered valid for a connection when a
|
// Keys are only considered valid for a connection when a
|
||||||
// connection is in the session map. If it is removed, the key
|
// connection is in the session map. If it is removed, the key
|
||||||
// should be marked invalid.
|
// should be marked invalid.
|
||||||
const detail::ConnIDKey& Key() const { return key; }
|
const detail::ConnKey& Key() const { return key; }
|
||||||
session::detail::Key SessionKey(bool copy) const override
|
session::detail::Key SessionKey(bool copy) const override
|
||||||
{ return session::detail::Key{&key, sizeof(key), copy}; }
|
{ return session::detail::Key{&key, sizeof(key), copy}; }
|
||||||
|
|
||||||
|
@ -267,7 +269,7 @@ private:
|
||||||
RecordValPtr conn_val;
|
RecordValPtr conn_val;
|
||||||
std::shared_ptr<EncapsulationStack> encapsulation; // tunnels
|
std::shared_ptr<EncapsulationStack> encapsulation; // tunnels
|
||||||
|
|
||||||
detail::ConnIDKey key;
|
detail::ConnKey key;
|
||||||
|
|
||||||
unsigned int skip:1;
|
unsigned int skip:1;
|
||||||
unsigned int weird:1;
|
unsigned int weird:1;
|
||||||
|
|
|
@ -19,8 +19,8 @@ const IPAddr IPAddr::v6_unspecified = IPAddr();
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
ConnIDKey::ConnIDKey(const IPAddr& src, const IPAddr& dst, uint16_t src_port,
|
ConnKey::ConnKey(const IPAddr& src, const IPAddr& dst, uint16_t src_port,
|
||||||
uint16_t dst_port, TransportProto t, bool one_way)
|
uint16_t dst_port, TransportProto t, bool one_way)
|
||||||
: transport(t)
|
: transport(t)
|
||||||
{
|
{
|
||||||
// Lookup up connection based on canonical ordering, which is
|
// Lookup up connection based on canonical ordering, which is
|
||||||
|
@ -44,9 +44,9 @@ ConnIDKey::ConnIDKey(const IPAddr& src, const IPAddr& dst, uint16_t src_port,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
detail::ConnIDKey::ConnIDKey(const ConnID& id)
|
detail::ConnKey::ConnKey(const ConnTuple& id)
|
||||||
: ConnIDKey(id.src_addr, id.dst_addr, id.src_port, id.dst_port,
|
: ConnKey(id.src_addr, id.dst_addr, id.src_port, id.dst_port,
|
||||||
id.proto, id.is_one_way)
|
id.proto, id.is_one_way)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
30
src/IPAddr.h
30
src/IPAddr.h
|
@ -15,43 +15,45 @@ typedef in_addr in4_addr;
|
||||||
namespace zeek {
|
namespace zeek {
|
||||||
|
|
||||||
class String;
|
class String;
|
||||||
struct ConnID;
|
struct ConnTuple;
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
class HashKey;
|
class HashKey;
|
||||||
|
|
||||||
struct ConnIDKey {
|
struct ConnKey {
|
||||||
in6_addr ip1;
|
in6_addr ip1;
|
||||||
in6_addr ip2;
|
in6_addr ip2;
|
||||||
uint16_t port1;
|
uint16_t port1;
|
||||||
uint16_t port2;
|
uint16_t port2;
|
||||||
TransportProto transport;
|
TransportProto transport;
|
||||||
|
|
||||||
ConnIDKey(const IPAddr& src, const IPAddr& dst, uint16_t src_port,
|
ConnKey(const IPAddr& src, const IPAddr& dst, uint16_t src_port,
|
||||||
uint16_t dst_port, TransportProto t, bool one_way);
|
uint16_t dst_port, TransportProto t, bool one_way);
|
||||||
ConnIDKey(const ConnID& conn);
|
ConnKey(const ConnTuple& conn);
|
||||||
ConnIDKey(const ConnIDKey& rhs)
|
ConnKey(const ConnKey& rhs)
|
||||||
{
|
{
|
||||||
*this = rhs;
|
*this = rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator<(const ConnIDKey& rhs) const { return memcmp(this, &rhs, sizeof(ConnIDKey)) < 0; }
|
bool operator<(const ConnKey& rhs) const { return memcmp(this, &rhs, sizeof(ConnKey)) < 0; }
|
||||||
bool operator<=(const ConnIDKey& rhs) const { return memcmp(this, &rhs, sizeof(ConnIDKey)) <= 0; }
|
bool operator<=(const ConnKey& rhs) const { return memcmp(this, &rhs, sizeof(ConnKey)) <= 0; }
|
||||||
bool operator==(const ConnIDKey& rhs) const { return memcmp(this, &rhs, sizeof(ConnIDKey)) == 0; }
|
bool operator==(const ConnKey& rhs) const { return memcmp(this, &rhs, sizeof(ConnKey)) == 0; }
|
||||||
bool operator!=(const ConnIDKey& rhs) const { return memcmp(this, &rhs, sizeof(ConnIDKey)) != 0; }
|
bool operator!=(const ConnKey& rhs) const { return memcmp(this, &rhs, sizeof(ConnKey)) != 0; }
|
||||||
bool operator>=(const ConnIDKey& rhs) const { return memcmp(this, &rhs, sizeof(ConnIDKey)) >= 0; }
|
bool operator>=(const ConnKey& rhs) const { return memcmp(this, &rhs, sizeof(ConnKey)) >= 0; }
|
||||||
bool operator>(const ConnIDKey& rhs) const { return memcmp(this, &rhs, sizeof(ConnIDKey)) > 0; }
|
bool operator>(const ConnKey& rhs) const { return memcmp(this, &rhs, sizeof(ConnKey)) > 0; }
|
||||||
|
|
||||||
ConnIDKey& operator=(const ConnIDKey& rhs)
|
ConnKey& operator=(const ConnKey& rhs)
|
||||||
{
|
{
|
||||||
if ( this != &rhs )
|
if ( this != &rhs )
|
||||||
memcpy(this, &rhs, sizeof(ConnIDKey));
|
memcpy(this, &rhs, sizeof(ConnKey));
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using ConnIDKey [[deprecated("Remove in v5.1. Use zeek::detail::ConnKey.")]] = ConnKey;
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -441,7 +443,7 @@ public:
|
||||||
static const IPAddr v6_unspecified;
|
static const IPAddr v6_unspecified;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend struct detail::ConnIDKey;
|
friend struct detail::ConnKey;
|
||||||
friend class IPPrefix;
|
friend class IPPrefix;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -19,14 +19,14 @@ static zeek::Connection* add_connection()
|
||||||
zeek::run_state::detail::update_network_time(network_time_start);
|
zeek::run_state::detail::update_network_time(network_time_start);
|
||||||
|
|
||||||
zeek::Packet p;
|
zeek::Packet p;
|
||||||
zeek::ConnID conn_id;
|
zeek::ConnTuple conn_id;
|
||||||
conn_id.src_addr = zeek::IPAddr("1.2.3.4");
|
conn_id.src_addr = zeek::IPAddr("1.2.3.4");
|
||||||
conn_id.dst_addr = zeek::IPAddr("5.6.7.8");
|
conn_id.dst_addr = zeek::IPAddr("5.6.7.8");
|
||||||
conn_id.src_port = htons(23132);
|
conn_id.src_port = htons(23132);
|
||||||
conn_id.dst_port = htons(80);
|
conn_id.dst_port = htons(80);
|
||||||
conn_id.is_one_way = false;
|
conn_id.is_one_way = false;
|
||||||
conn_id.proto = TRANSPORT_TCP;
|
conn_id.proto = TRANSPORT_TCP;
|
||||||
zeek::detail::ConnIDKey key(conn_id);
|
zeek::detail::ConnKey key(conn_id);
|
||||||
zeek::Connection* conn = new zeek::Connection(key, network_time_start,
|
zeek::Connection* conn = new zeek::Connection(key, network_time_start,
|
||||||
&conn_id, 1, &p);
|
&conn_id, 1, &p);
|
||||||
conn->SetTransport(TRANSPORT_TCP);
|
conn->SetTransport(TRANSPORT_TCP);
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace zeek::session::detail {
|
||||||
/**
|
/**
|
||||||
* This type is used as the key for the map in SessionManager. It represents a
|
* This type is used as the key for the map in SessionManager. It represents a
|
||||||
* raw block of memory that points to a key of some type for a session, such as
|
* raw block of memory that points to a key of some type for a session, such as
|
||||||
* a ConnIDKey for a Connection. This allows us to do type-independent
|
* a ConnKey for a Connection. This allows us to do type-independent
|
||||||
* comparison of the keys in the map. By default, this type does not maintain
|
* comparison of the keys in the map. By default, this type does not maintain
|
||||||
* the lifetime of the data pointed to by the Key. It only holds a
|
* the lifetime of the data pointed to by the Key. It only holds a
|
||||||
* pointer. When a Key object is inserted into the SessionManager's map,
|
* pointer. When a Key object is inserted into the SessionManager's map,
|
||||||
|
|
|
@ -129,7 +129,7 @@ void Manager::ProcessTransportLayer(double t, const Packet* pkt, size_t remainin
|
||||||
|
|
||||||
const u_char* data = ip_hdr->Payload();
|
const u_char* data = ip_hdr->Payload();
|
||||||
|
|
||||||
ConnID id;
|
ConnTuple id;
|
||||||
id.src_addr = ip_hdr->SrcAddr();
|
id.src_addr = ip_hdr->SrcAddr();
|
||||||
id.dst_addr = ip_hdr->DstAddr();
|
id.dst_addr = ip_hdr->DstAddr();
|
||||||
BifEnum::Tunnel::Type tunnel_type = BifEnum::Tunnel::IP;
|
BifEnum::Tunnel::Type tunnel_type = BifEnum::Tunnel::IP;
|
||||||
|
@ -188,7 +188,7 @@ void Manager::ProcessTransportLayer(double t, const Packet* pkt, size_t remainin
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
zeek::detail::ConnIDKey conn_key(id);
|
zeek::detail::ConnKey conn_key(id);
|
||||||
detail::Key key(&conn_key, sizeof(conn_key), false);
|
detail::Key key(&conn_key, sizeof(conn_key), false);
|
||||||
Connection* conn = nullptr;
|
Connection* conn = nullptr;
|
||||||
|
|
||||||
|
@ -375,7 +375,7 @@ Connection* Manager::FindConnection(Val* v)
|
||||||
auto orig_portv = vl->GetFieldAs<PortVal>(orig_p);
|
auto orig_portv = vl->GetFieldAs<PortVal>(orig_p);
|
||||||
auto resp_portv = vl->GetFieldAs<PortVal>(resp_p);
|
auto resp_portv = vl->GetFieldAs<PortVal>(resp_p);
|
||||||
|
|
||||||
zeek::detail::ConnIDKey conn_key(orig_addr, resp_addr,
|
zeek::detail::ConnKey conn_key(orig_addr, resp_addr,
|
||||||
htons((unsigned short) orig_portv->Port()),
|
htons((unsigned short) orig_portv->Port()),
|
||||||
htons((unsigned short) resp_portv->Port()),
|
htons((unsigned short) resp_portv->Port()),
|
||||||
orig_portv->PortType(), false);
|
orig_portv->PortType(), false);
|
||||||
|
@ -482,7 +482,7 @@ void Manager::GetStats(Stats& s)
|
||||||
s.num_packets = packet_mgr->PacketsProcessed();
|
s.num_packets = packet_mgr->PacketsProcessed();
|
||||||
}
|
}
|
||||||
|
|
||||||
Connection* Manager::NewConn(const zeek::detail::ConnIDKey& k, double t, const ConnID* id,
|
Connection* Manager::NewConn(const zeek::detail::ConnKey& k, double t, const ConnTuple* id,
|
||||||
const u_char* data, int proto, uint32_t flow_label,
|
const u_char* data, int proto, uint32_t flow_label,
|
||||||
const Packet* pkt)
|
const Packet* pkt)
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace detail { class PacketFilter; }
|
||||||
class EncapsulationStack;
|
class EncapsulationStack;
|
||||||
class Packet;
|
class Packet;
|
||||||
class Connection;
|
class Connection;
|
||||||
struct ConnID;
|
struct ConnTuple;
|
||||||
class StatBlocks;
|
class StatBlocks;
|
||||||
|
|
||||||
namespace session {
|
namespace session {
|
||||||
|
@ -64,7 +64,7 @@ public:
|
||||||
* @param proto The transport protocol for the connection.
|
* @param proto The transport protocol for the connection.
|
||||||
* @return The connection, or nullptr if one doesn't exist.
|
* @return The connection, or nullptr if one doesn't exist.
|
||||||
*/
|
*/
|
||||||
Connection* FindConnection(const zeek::detail::ConnIDKey& key, TransportProto proto);
|
Connection* FindConnection(const zeek::detail::ConnKey& key, TransportProto proto);
|
||||||
|
|
||||||
void Remove(Session* s);
|
void Remove(Session* s);
|
||||||
void Insert(Session* c);
|
void Insert(Session* c);
|
||||||
|
@ -148,7 +148,7 @@ private:
|
||||||
|
|
||||||
using SessionMap = std::map<detail::Key, Session*>;
|
using SessionMap = std::map<detail::Key, Session*>;
|
||||||
|
|
||||||
Connection* NewConn(const zeek::detail::ConnIDKey& k, double t, const ConnID* id,
|
Connection* NewConn(const zeek::detail::ConnKey& k, double t, const ConnTuple* id,
|
||||||
const u_char* data, int proto, uint32_t flow_label,
|
const u_char* data, int proto, uint32_t flow_label,
|
||||||
const Packet* pkt);
|
const Packet* pkt);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue