Skip to content

Commit 4654f33

Browse files
hlefdavidchisnall
authored andcommitted
Add debug logs to the firewall.
These new debug logs enable us to catch table entry removal failures which would otherwise go unnoticed. Signed-off-by: Hugo Lefeuvre <[email protected]>
1 parent 1cbd172 commit 4654f33

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

lib/firewall/firewall.cc

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,11 @@ namespace
256256
if (iterator != table.end() && (*iterator == tuple))
257257
{
258258
table.erase(iterator);
259+
return;
259260
}
261+
Debug::log("Failed to remove endpoint (local: {}; remote: {})",
262+
localPort,
263+
remotePort);
260264
}
261265

262266
void add_endpoint(IPProtocolNumber protocol,
@@ -274,6 +278,10 @@ namespace
274278
auto iterator = find_endpoint(table, tuple);
275279
if (iterator != table.end() && (*iterator == tuple))
276280
{
281+
Debug::log("Failed to add endpoint: already in the table "
282+
"(local: {}; remote: {})",
283+
localPort,
284+
remotePort);
277285
return;
278286
}
279287
table.insert(iterator, tuple);
@@ -290,11 +298,18 @@ namespace
290298
// TODO: If we sorted by local port, we could make this O(log(n))
291299
// If we expect n to be < 8 (currently do) then that's too much
292300
// work.
301+
bool found = false;
293302
std::remove_if(table.begin(),
294303
table.end(),
295-
[localPort](const ConnectionTuple &tuple) {
296-
return tuple.localPort == localPort;
304+
[localPort, &found](const ConnectionTuple &tuple) {
305+
bool ret = (tuple.localPort == localPort);
306+
found = found || ret;
307+
return ret;
297308
});
309+
if (!found)
310+
{
311+
Debug::log("Failed to remove endpoint (local: {})", localPort);
312+
}
298313
}
299314

300315
bool is_endpoint_permitted(IPProtocolNumber protocol,

0 commit comments

Comments
 (0)