Skip to content

Commit 41109ea

Browse files
committed
Directly make use of the ExternalIPsConfig in ConnTracker
1 parent 2e17cf4 commit 41109ea

File tree

4 files changed

+9
-14
lines changed

4 files changed

+9
-14
lines changed

collector/lib/ConnTracker.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,12 @@ void ConnectionTracker::CloseExternalUnnormalizedConnections(bool is_server, Con
158158
}
159159

160160
void ConnectionTracker::CloseConnectionsOnRuntimeConfigChange(ConnMap* old_conn_state, ConnMap* delta_conn) {
161-
if (enable_external_ips_egress_) {
161+
if (external_IPs_config_.IsEnabled(ExternalIPsConfig::Direction::EGRESS)) {
162162
CloseNormalizedConnections(/* egress is when we are not server */ false, old_conn_state, delta_conn);
163163
} else {
164164
CloseExternalUnnormalizedConnections(/* egress is when we are not server */ false, old_conn_state, delta_conn);
165165
}
166-
if (enable_external_ips_ingress_) {
166+
if (external_IPs_config_.IsEnabled(ExternalIPsConfig::Direction::INGRESS)) {
167167
CloseNormalizedConnections(/* ingress is when we are server */ true, old_conn_state, delta_conn);
168168
} else {
169169
CloseExternalUnnormalizedConnections(/* ingress is when we are server */ true, old_conn_state, delta_conn);
@@ -182,11 +182,11 @@ Connection ConnectionTracker::NormalizeConnectionNoLock(const Connection& conn)
182182
if (is_server) {
183183
// If this is the server, only the local port is relevant, while the remote port does not matter.
184184
local = Endpoint(IPNet(Address()), conn.local().port());
185-
remote = Endpoint(NormalizeAddressNoLock(conn.remote().address(), enable_external_ips_ingress_), 0);
185+
remote = Endpoint(NormalizeAddressNoLock(conn.remote().address(), external_IPs_config_.IsEnabled(ExternalIPsConfig::Direction::INGRESS)), 0);
186186
} else {
187187
// If this is the client, the local port and address are not relevant.
188188
local = Endpoint();
189-
remote = Endpoint(NormalizeAddressNoLock(remote.address(), enable_external_ips_egress_), remote.port());
189+
remote = Endpoint(NormalizeAddressNoLock(remote.address(), external_IPs_config_.IsEnabled(ExternalIPsConfig::Direction::EGRESS)), remote.port());
190190
}
191191

192192
return Connection(conn.container(), local, remote, conn.l4proto(), is_server);

collector/lib/ConnTracker.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <vector>
55

66
#include "Containers.h"
7+
#include "ExternalIPsConfig.h"
78
#include "Hash.h"
89
#include "NRadix.h"
910
#include "NetworkConnection.h"
@@ -131,10 +132,7 @@ class ConnectionTracker {
131132

132133
void UpdateKnownPublicIPs(UnorderedSet<Address>&& known_public_ips);
133134
void UpdateKnownIPNetworks(UnorderedMap<Address::Family, std::vector<IPNet>>&& known_ip_networks);
134-
void EnableExternalIPs(bool enable_ingress, bool enable_egress) {
135-
enable_external_ips_ingress_ = enable_ingress;
136-
enable_external_ips_egress_ = enable_egress;
137-
}
135+
void SetExternalIPsConfig(ExternalIPsConfig config) { external_IPs_config_ = config; }
138136
void UpdateIgnoredL4ProtoPortPairs(UnorderedSet<L4ProtoPortPair>&& ignored_l4proto_port_pairs);
139137
void UpdateIgnoredNetworks(const std::vector<IPNet>& network_list);
140138
void UpdateNonAggregatedNetworks(const std::vector<IPNet>& network_list);
@@ -205,8 +203,7 @@ class ConnectionTracker {
205203

206204
UnorderedSet<Address> known_public_ips_;
207205
NRadixTree known_ip_networks_;
208-
bool enable_external_ips_ingress_ = false;
209-
bool enable_external_ips_egress_ = false;
206+
ExternalIPsConfig external_IPs_config_;
210207
UnorderedMap<Address::Family, bool> known_private_networks_exists_;
211208
UnorderedSet<L4ProtoPortPair> ignored_l4proto_port_pairs_;
212209
NRadixTree ignored_networks_;

collector/lib/NetworkStatusNotifier.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,7 @@ void NetworkStatusNotifier::RunSingle(IDuplexClientWriter<sensor::NetworkConnect
245245
ExternalIPsConfig externalIPsConfig = config_.ExternalIPsConf();
246246

247247
WITH_TIMER(CollectorStats::net_fetch_state) {
248-
conn_tracker_->EnableExternalIPs(
249-
externalIPsConfig.IsEnabled(ExternalIPsConfig::Direction::INGRESS),
250-
externalIPsConfig.IsEnabled(ExternalIPsConfig::Direction::EGRESS));
248+
conn_tracker_->SetExternalIPsConfig(externalIPsConfig);
251249

252250
new_conn_state = conn_tracker_->FetchConnState(true, true);
253251
if (config_.EnableAfterglow()) {

collector/test/ConnTrackerTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ TEST(ConnTrackerTest, TestNormalizedEnableExternalIPs) {
415415
int64_t time_micros = 1000;
416416

417417
ConnectionTracker tracker;
418-
tracker.EnableExternalIPs(true, true);
418+
tracker.SetExternalIPsConfig(ExternalIPsConfig(std::nullopt, true));
419419

420420
UnorderedMap<Address::Family, std::vector<IPNet>> known_networks = {{Address::Family::IPV4, {IPNet(Address(35, 127, 1, 0), 24)}}};
421421
tracker.UpdateKnownIPNetworks(std::move(known_networks));

0 commit comments

Comments
 (0)