diff --git a/src/Conn.cc b/src/Conn.cc index 98fb6577c5..da76dc509c 100644 --- a/src/Conn.cc +++ b/src/Conn.cc @@ -25,8 +25,8 @@ namespace zeek { uint64_t Connection::total_connections = 0; uint64_t Connection::current_connections = 0; -Connection::Connection(const detail::ConnIDKey& k, double t, - const ConnID* id, uint32_t flow, const Packet* pkt) +Connection::Connection(const detail::ConnKey& k, double t, + const ConnTuple* id, uint32_t flow, const Packet* pkt) : Session(t, connection_timeout, connection_status_update, detail::connection_status_update_interval), key(k) diff --git a/src/Conn.h b/src/Conn.h index 910fd255f2..d6ca89a27b 100644 --- a/src/Conn.h +++ b/src/Conn.h @@ -55,7 +55,7 @@ enum ConnEventToFlag { NUM_EVENTS_TO_FLAG, }; -struct ConnID { +struct ConnTuple { IPAddr src_addr; IPAddr dst_addr; uint32_t src_port; @@ -64,6 +64,8 @@ struct ConnID { 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, 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 { 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); ~Connection() override; @@ -113,7 +115,7 @@ public: // Keys are only considered valid for a connection when a // connection is in the session map. If it is removed, the key // 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 { return session::detail::Key{&key, sizeof(key), copy}; } @@ -267,7 +269,7 @@ private: RecordValPtr conn_val; std::shared_ptr encapsulation; // tunnels - detail::ConnIDKey key; + detail::ConnKey key; unsigned int skip:1; unsigned int weird:1; diff --git a/src/IPAddr.cc b/src/IPAddr.cc index 70809353f3..97beebcffa 100644 --- a/src/IPAddr.cc +++ b/src/IPAddr.cc @@ -19,8 +19,8 @@ const IPAddr IPAddr::v6_unspecified = IPAddr(); namespace detail { -ConnIDKey::ConnIDKey(const IPAddr& src, const IPAddr& dst, uint16_t src_port, - uint16_t dst_port, TransportProto t, bool one_way) +ConnKey::ConnKey(const IPAddr& src, const IPAddr& dst, uint16_t src_port, + uint16_t dst_port, TransportProto t, bool one_way) : transport(t) { // 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) - : ConnIDKey(id.src_addr, id.dst_addr, id.src_port, id.dst_port, - id.proto, id.is_one_way) +detail::ConnKey::ConnKey(const ConnTuple& id) + : ConnKey(id.src_addr, id.dst_addr, id.src_port, id.dst_port, + id.proto, id.is_one_way) { } diff --git a/src/IPAddr.h b/src/IPAddr.h index ca9332a93e..fbabc3227c 100644 --- a/src/IPAddr.h +++ b/src/IPAddr.h @@ -15,43 +15,45 @@ typedef in_addr in4_addr; namespace zeek { class String; -struct ConnID; +struct ConnTuple; namespace detail { class HashKey; -struct ConnIDKey { +struct ConnKey { in6_addr ip1; in6_addr ip2; uint16_t port1; uint16_t port2; 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); - ConnIDKey(const ConnID& conn); - ConnIDKey(const ConnIDKey& rhs) + ConnKey(const ConnTuple& conn); + ConnKey(const ConnKey& rhs) { *this = rhs; } - bool operator<(const ConnIDKey& rhs) const { return memcmp(this, &rhs, sizeof(ConnIDKey)) < 0; } - bool operator<=(const ConnIDKey& rhs) const { return memcmp(this, &rhs, sizeof(ConnIDKey)) <= 0; } - bool operator==(const ConnIDKey& rhs) const { return memcmp(this, &rhs, sizeof(ConnIDKey)) == 0; } - bool operator!=(const ConnIDKey& rhs) const { return memcmp(this, &rhs, sizeof(ConnIDKey)) != 0; } - bool operator>=(const ConnIDKey& rhs) const { return memcmp(this, &rhs, sizeof(ConnIDKey)) >= 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 ConnKey& rhs) const { return memcmp(this, &rhs, sizeof(ConnKey)) <= 0; } + bool operator==(const ConnKey& rhs) const { return memcmp(this, &rhs, sizeof(ConnKey)) == 0; } + bool operator!=(const ConnKey& rhs) const { return memcmp(this, &rhs, sizeof(ConnKey)) != 0; } + bool operator>=(const ConnKey& rhs) const { return memcmp(this, &rhs, sizeof(ConnKey)) >= 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 ) - memcpy(this, &rhs, sizeof(ConnIDKey)); + memcpy(this, &rhs, sizeof(ConnKey)); return *this; } }; +using ConnIDKey [[deprecated("Remove in v5.1. Use zeek::detail::ConnKey.")]] = ConnKey; + } // namespace detail /** @@ -441,7 +443,7 @@ public: static const IPAddr v6_unspecified; private: - friend struct detail::ConnIDKey; + friend struct detail::ConnKey; friend class IPPrefix; /** diff --git a/src/fuzzers/pop3-fuzzer.cc b/src/fuzzers/pop3-fuzzer.cc index 66c96bbf98..c5d2b8e2c0 100644 --- a/src/fuzzers/pop3-fuzzer.cc +++ b/src/fuzzers/pop3-fuzzer.cc @@ -19,14 +19,14 @@ static zeek::Connection* add_connection() zeek::run_state::detail::update_network_time(network_time_start); zeek::Packet p; - zeek::ConnID conn_id; + zeek::ConnTuple conn_id; conn_id.src_addr = zeek::IPAddr("1.2.3.4"); conn_id.dst_addr = zeek::IPAddr("5.6.7.8"); conn_id.src_port = htons(23132); conn_id.dst_port = htons(80); conn_id.is_one_way = false; 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, &conn_id, 1, &p); conn->SetTransport(TRANSPORT_TCP); diff --git a/src/session/Key.h b/src/session/Key.h index 25a6a00f00..f07ec8996b 100644 --- a/src/session/Key.h +++ b/src/session/Key.h @@ -10,7 +10,7 @@ namespace zeek::session::detail { /** * 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 - * 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 * 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, diff --git a/src/session/Manager.cc b/src/session/Manager.cc index c0ead0970d..0076cf1305 100644 --- a/src/session/Manager.cc +++ b/src/session/Manager.cc @@ -129,7 +129,7 @@ void Manager::ProcessTransportLayer(double t, const Packet* pkt, size_t remainin const u_char* data = ip_hdr->Payload(); - ConnID id; + ConnTuple id; id.src_addr = ip_hdr->SrcAddr(); id.dst_addr = ip_hdr->DstAddr(); BifEnum::Tunnel::Type tunnel_type = BifEnum::Tunnel::IP; @@ -188,7 +188,7 @@ void Manager::ProcessTransportLayer(double t, const Packet* pkt, size_t remainin return; } - zeek::detail::ConnIDKey conn_key(id); + zeek::detail::ConnKey conn_key(id); detail::Key key(&conn_key, sizeof(conn_key), false); Connection* conn = nullptr; @@ -375,7 +375,7 @@ Connection* Manager::FindConnection(Val* v) auto orig_portv = vl->GetFieldAs(orig_p); auto resp_portv = vl->GetFieldAs(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) resp_portv->Port()), orig_portv->PortType(), false); @@ -482,7 +482,7 @@ void Manager::GetStats(Stats& s) 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 Packet* pkt) { diff --git a/src/session/Manager.h b/src/session/Manager.h index a1a18299c0..b65b245203 100644 --- a/src/session/Manager.h +++ b/src/session/Manager.h @@ -20,7 +20,7 @@ namespace detail { class PacketFilter; } class EncapsulationStack; class Packet; class Connection; -struct ConnID; +struct ConnTuple; class StatBlocks; namespace session { @@ -64,7 +64,7 @@ public: * @param proto The transport protocol for the connection. * @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 Insert(Session* c); @@ -148,7 +148,7 @@ private: using SessionMap = std::map; - 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 Packet* pkt);