1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

Minor changes on TCPIP::StreamFollower

This commit is contained in:
Matias Fontanini
2016-03-06 13:40:10 -08:00
parent 331bc57b44
commit c082dfad67
3 changed files with 36 additions and 32 deletions

View File

@@ -124,14 +124,16 @@ public:
stream_id(const address_type& client_addr, uint16_t client_port, stream_id(const address_type& client_addr, uint16_t client_port,
const address_type& server_addr, uint16_t server_port); const address_type& server_addr, uint16_t server_port);
bool operator<(const stream_id& rhs) const;
bool operator==(const stream_id& rhs) const;
address_type min_address; address_type min_address;
address_type max_address; address_type max_address;
uint16_t min_address_port; uint16_t min_address_port;
uint16_t max_address_port; uint16_t max_address_port;
bool operator<(const stream_id& rhs) const; static address_type serialize(IPv4Address address);
static address_type serialize(const IPv6Address& address);
static size_t hash(const stream_id& id);
}; };
/** /**
@@ -228,8 +230,6 @@ private:
static stream_id make_stream_id(const PDU& packet); static stream_id make_stream_id(const PDU& packet);
Stream& find_stream(const stream_id& id); Stream& find_stream(const stream_id& id);
static stream_id::address_type serialize(IPv4Address address);
static stream_id::address_type serialize(const IPv6Address& address);
void process_packet(PDU& packet, const timestamp_type& ts); void process_packet(PDU& packet, const timestamp_type& ts);
void cleanup_streams(const timestamp_type& now); void cleanup_streams(const timestamp_type& now);

View File

@@ -161,15 +161,15 @@ void StreamFollower::stream_termination_callback(const stream_termination_callba
Stream& StreamFollower::find_stream(const IPv4Address& client_addr, uint16_t client_port, Stream& StreamFollower::find_stream(const IPv4Address& client_addr, uint16_t client_port,
const IPv4Address& server_addr, uint16_t server_port) { const IPv4Address& server_addr, uint16_t server_port) {
stream_id identifier(serialize(client_addr), client_port, stream_id identifier(stream_id::serialize(client_addr), client_port,
serialize(server_addr), server_port); stream_id::serialize(server_addr), server_port);
return find_stream(identifier); return find_stream(identifier);
} }
Stream& StreamFollower::find_stream(const IPv6Address& client_addr, uint16_t client_port, Stream& StreamFollower::find_stream(const IPv6Address& client_addr, uint16_t client_port,
const IPv6Address& server_addr, uint16_t server_port) { const IPv6Address& server_addr, uint16_t server_port) {
stream_id identifier(serialize(client_addr), client_port, stream_id identifier(stream_id::serialize(client_addr), client_port,
serialize(server_addr), server_port); stream_id::serialize(server_addr), server_port);
return find_stream(identifier); return find_stream(identifier);
} }
@@ -179,12 +179,12 @@ StreamFollower::stream_id StreamFollower::make_stream_id(const PDU& packet) {
throw invalid_packet(); throw invalid_packet();
} }
if (const IP* ip = packet.find_pdu<IP>()) { if (const IP* ip = packet.find_pdu<IP>()) {
return stream_id(serialize(ip->src_addr()), tcp->sport(), return stream_id(stream_id::serialize(ip->src_addr()), tcp->sport(),
serialize(ip->dst_addr()), tcp->dport()); stream_id::serialize(ip->dst_addr()), tcp->dport());
} }
else if (const IPv6* ip = packet.find_pdu<IPv6>()) { else if (const IPv6* ip = packet.find_pdu<IPv6>()) {
return stream_id(serialize(ip->src_addr()), tcp->sport(), return stream_id(stream_id::serialize(ip->src_addr()), tcp->sport(),
serialize(ip->dst_addr()), tcp->dport()); stream_id::serialize(ip->dst_addr()), tcp->dport());
} }
else { else {
throw invalid_packet(); throw invalid_packet();
@@ -201,22 +201,6 @@ Stream& StreamFollower::find_stream(const stream_id& id) {
} }
} }
StreamFollower::stream_id::address_type StreamFollower::serialize(IPv4Address address) {
stream_id::address_type addr;
OutputMemoryStream output(addr.data(), addr.size());
addr.fill(0);
output.write(address);
return addr;
}
StreamFollower::stream_id::address_type StreamFollower::serialize(const IPv6Address& address) {
stream_id::address_type addr;
OutputMemoryStream output(addr.data(), addr.size());
addr.fill(0);
output.write(address);
return addr;
}
void StreamFollower::cleanup_streams(const timestamp_type& now) { void StreamFollower::cleanup_streams(const timestamp_type& now) {
streams_type::iterator iter = streams_.begin(); streams_type::iterator iter = streams_.begin();
while (iter != streams_.end()) { while (iter != streams_.end()) {
@@ -259,8 +243,29 @@ StreamFollower::stream_id::stream_id(const address_type& client_addr,
} }
bool StreamFollower::stream_id::operator<(const stream_id& rhs) const { bool StreamFollower::stream_id::operator<(const stream_id& rhs) const {
return tie(min_address, min_address_port, max_address, max_address_port) < return tie(min_address, max_address, min_address_port, max_address_port) <
tie(rhs.min_address, rhs.min_address_port, rhs.max_address, rhs.max_address_port); tie(rhs.min_address, rhs.max_address, rhs.min_address_port, rhs.max_address_port);
}
bool StreamFollower::stream_id::operator==(const stream_id& rhs) const {
return tie(min_address, min_address_port, max_address, max_address_port) ==
tie(rhs.min_address, rhs.min_address_port, rhs.max_address, rhs.max_address_port);
}
StreamFollower::stream_id::address_type StreamFollower::stream_id::serialize(IPv4Address address) {
address_type addr;
OutputMemoryStream output(addr.data(), addr.size());
addr.fill(0);
output.write(address);
return addr;
}
StreamFollower::stream_id::address_type StreamFollower::stream_id::serialize(const IPv6Address& address) {
address_type addr;
OutputMemoryStream output(addr.data(), addr.size());
addr.fill(0);
output.write(address);
return addr;
} }
} // TCPIP } // TCPIP

View File

@@ -512,7 +512,6 @@ TEST_F(FlowTest, StreamFollower_FollowStream) {
EXPECT_EQ(payload, merge_chunks(stream_client_payload_chunks)); EXPECT_EQ(payload, merge_chunks(stream_client_payload_chunks));
} }
#ifdef TINS_HAVE_ACK_TRACKER #ifdef TINS_HAVE_ACK_TRACKER
using namespace boost; using namespace boost;