Skip to content

Clean up code in flow-filter table management#1268

Merged
qmonnet merged 6 commits intomainfrom
pr/qmonnet/flow-filter-table-cleanup
Feb 9, 2026
Merged

Clean up code in flow-filter table management#1268
qmonnet merged 6 commits intomainfrom
pr/qmonnet/flow-filter-table-cleanup

Conversation

@qmonnet
Copy link
Member

@qmonnet qmonnet commented Feb 8, 2026

Some clean-up commits extracted from #1264.

Most of these are by Claude, to whom I asked to clean-up flow-filter/src/tables.rs, because I thought I was about to make the file more complex in coming work (turns out, it's mostly .../setup.rs that I needed to change). I find the gain in clarity is moderate (I hoped I'd get a clearer code organisation) but the clean-ups still simplify some portions of the code, so they're probably worth taking in.

qmonnet and others added 6 commits February 8, 2026 20:26
Drive-by cleanup. No need to check that the count for filtered elements
is strictly positive; just use the .any() iterator method with the
condition.

Signed-off-by: Quentin Monnet <qmo@qmon.net>
Consolidate the duplicated AllPorts/Ranges enum pattern from
SrcConnectionData and RemotePortRangesData into a single generic
PortRangeMap<T> type. This eliminates ~40 lines of duplicate code
for the ValueWithAssociatedRanges trait implementation and the
new/get methods.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Quentin Monnet <qmo@qmon.net>
Replace the repeated get-or-insert pattern in the four insert methods
with a single get_or_create_table helper using HashMap's entry API.
This removes ~40 lines of duplicated boilerplate code.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Quentin Monnet <qmo@qmon.net>
Replace create_default_source and create_default_source_to_default_remote
with a single set_default_source helper that handles the guard logic.
The update_* methods now construct the data inline and call the helper.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Quentin Monnet <qmo@qmon.net>
Rename default_source_opt to default_source for consistency with
default_remote_data. The Option type already indicates optionality.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Quentin Monnet <qmo@qmon.net>
Rewrite the structural comment to clearly explain the lookup flow
with an ASCII diagram and logical descriptions of what each level
provides, making the nested data structure easier to understand.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Quentin Monnet <qmo@qmon.net>
@qmonnet qmonnet self-assigned this Feb 8, 2026
@qmonnet qmonnet added the area/nat Related to Network Address Translation (NAT) label Feb 8, 2026
@qmonnet qmonnet requested a review from a team as a code owner February 8, 2026 20:30
@qmonnet qmonnet enabled auto-merge February 8, 2026 21:01
@qmonnet
Copy link
Member Author

qmonnet commented Feb 8, 2026

Can be merged immediately (pending review, obviously) - I'll rebase #1264 on top of it. I thought of removing these commits from 1264 but it would mean addressing some conflicts now, then redoing the work in the opposite direction once this PR is merged. So rebasing #1264 on top of this one should be simpler.

@qmonnet qmonnet added this pull request to the merge queue Feb 9, 2026
Merged via the queue into main with commit 902449b Feb 9, 2026
23 checks passed
@qmonnet qmonnet deleted the pr/qmonnet/flow-filter-table-cleanup branch February 9, 2026 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/nat Related to Network Address Translation (NAT)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants