@@ -112,7 +112,7 @@ IPNet ConnectionTracker::NormalizeAddressNoLock(const Address& address, bool ena
112
112
}
113
113
114
114
bool ConnectionTracker::ShouldNormalizeConnection (const Connection* conn) const {
115
- Endpoint local, remote = conn->remote ();
115
+ Endpoint remote = conn->remote ();
116
116
IPNet ipnet = NormalizeAddressNoLock (remote.address (), false );
117
117
118
118
return Address::IsCanonicalExternalIp (ipnet.address ());
@@ -138,28 +138,35 @@ void ConnectionTracker::CloseConnections(ConnMap* old_conn_state, ConnMap* delta
138
138
139
139
/* *
140
140
* Closes connections that have the 255.255.255.255 external IP address
141
+ * Affects only connections with a matching is_server property
141
142
*/
142
- void ConnectionTracker::CloseNormalizedConnections (ConnMap* old_conn_state, ConnMap* delta_conn) {
143
- CloseConnections (old_conn_state, delta_conn, [](const Connection* conn) {
144
- return Address::IsCanonicalExternalIp (conn->remote ().address ());
143
+ void ConnectionTracker::CloseNormalizedConnections (bool is_server, ConnMap* old_conn_state, ConnMap* delta_conn) {
144
+ CloseConnections (old_conn_state, delta_conn, [is_server ](const Connection* conn) {
145
+ return conn-> is_server () == is_server && Address::IsCanonicalExternalIp (conn->remote ().address ());
145
146
});
146
147
}
147
148
148
149
/* *
149
150
* Closes unnormalized connections that would be normalized to the canonical external
150
151
* IP address if external IPs was enabled
152
+ * Affects only connections with a matching is_server property
151
153
*/
152
- void ConnectionTracker::CloseExternalUnnormalizedConnections (ConnMap* old_conn_state, ConnMap* delta_conn) {
153
- CloseConnections (old_conn_state, delta_conn, [this ](const Connection* conn) {
154
- return ShouldNormalizeConnection (conn) && !Address::IsCanonicalExternalIp (conn->remote ().address ());
154
+ void ConnectionTracker::CloseExternalUnnormalizedConnections (bool is_server, ConnMap* old_conn_state, ConnMap* delta_conn) {
155
+ CloseConnections (old_conn_state, delta_conn, [this , is_server ](const Connection* conn) {
156
+ return conn-> is_server () == is_server && ShouldNormalizeConnection (conn) && !Address::IsCanonicalExternalIp (conn->remote ().address ());
155
157
});
156
158
}
157
159
158
- void ConnectionTracker::CloseConnectionsOnRuntimeConfigChange (ConnMap* old_conn_state, ConnMap* delta_conn, bool enableExternalIPs ) {
159
- if (enableExternalIPs ) {
160
- CloseNormalizedConnections (old_conn_state, delta_conn);
160
+ void ConnectionTracker::CloseConnectionsOnRuntimeConfigChange (ConnMap* old_conn_state, ConnMap* delta_conn) {
161
+ if (enable_external_ips_egress_ ) {
162
+ CloseNormalizedConnections (/* egress is when we are not server */ false , old_conn_state, delta_conn);
161
163
} else {
162
- CloseExternalUnnormalizedConnections (old_conn_state, delta_conn);
164
+ CloseExternalUnnormalizedConnections (/* egress is when we are not server */ false , old_conn_state, delta_conn);
165
+ }
166
+ if (enable_external_ips_ingress_) {
167
+ CloseNormalizedConnections (/* ingress is when we are server */ true , old_conn_state, delta_conn);
168
+ } else {
169
+ CloseExternalUnnormalizedConnections (/* ingress is when we are server */ true , old_conn_state, delta_conn);
163
170
}
164
171
}
165
172
@@ -175,11 +182,11 @@ Connection ConnectionTracker::NormalizeConnectionNoLock(const Connection& conn)
175
182
if (is_server) {
176
183
// If this is the server, only the local port is relevant, while the remote port does not matter.
177
184
local = Endpoint (IPNet (Address ()), conn.local ().port ());
178
- remote = Endpoint (NormalizeAddressNoLock (conn.remote ().address (), enable_external_ips_ ), 0 );
185
+ remote = Endpoint (NormalizeAddressNoLock (conn.remote ().address (), enable_external_ips_ingress_ ), 0 );
179
186
} else {
180
187
// If this is the client, the local port and address are not relevant.
181
188
local = Endpoint ();
182
- remote = Endpoint (NormalizeAddressNoLock (remote.address (), enable_external_ips_ ), remote.port ());
189
+ remote = Endpoint (NormalizeAddressNoLock (remote.address (), enable_external_ips_egress_ ), remote.port ());
183
190
}
184
191
185
192
return Connection (conn.container (), local, remote, conn.l4proto (), is_server);
0 commit comments