Tc filter selective removal - #234
Merged
Merged
Conversation
Remove NLM_F_EXCL so adding the clsact qdisc succeeds even when it already exists, e.g. from a previous endpoint run or a third-party tool.
Add ELASTIC_TC_FILTER_MARKER ("el-endpo") and two new functions:
- netlink_filter_exists: checks if an interface has our BPF tc filter
- netlink_filter_del: removes only our BPF tc filter by marker match
Both scan RTM_GETTFILTER dumps on ingress and egress parents and match
by TCA_BPF_NAME substring. TCA_KIND is intentionally omitted from the
dump request — some Linux 6.x kernels silently drop dumps that carry
TCA_KIND, causing recvmsg to block forever.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
CI uses clang-format 14.0.6 via pip. The previous formatting commit used v21 which formats macro binary-op spacing differently. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- netlink_filter_del_on_parent: stop on first match bug - open del_rth
once before the loop and continue scanning after each delete instead
of goto out, so all matching filters are removed
- Both functions: check NLM_F_DUMP_INTR and NLMSG_DONE error payload to
detect interrupted or failed netlink dumps
- Both functions: reject empty marker_name to prevent strstr("") matching
every BPF filter and causing mass deletion
- netlink_filter_exists_on_parent: accept nlmsg_pid == 0 to match del's
existing behaviour (some kernels send pid=0 in dump responses)
- netlink_filter_exists_on_parent: remove dead found variable
NETLINK_EXT_ACK was added in kernel 4.12; failing the socket open on ENOPROTOOPT breaks qdisc/filter operations on 4.5-4.11 kernels. Mirror iproute2 libnetlink.c which deliberately ignores the return value. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Endpoint attaches its tc BPF filters only to chain 0. Parse TCA_CHAIN from filter dumps and ignore entries from other chains so a nonzero-chain entry cannot drive a chain-0 deletion.
TC filter dumps use live cursors rather than snapshots. Delete only one matching filter per dump, then close the listing socket and start a fresh dump so stale Endpoint filters cannot be skipped.
Use one canonical el-endpo_ prefix when creating and identifying Endpoint tc filters. Prefix matching avoids deleting unrelated BPF filters that merely contain the shorter marker elsewhere in their names.
Restore exclusive qdisc creation so repeated setup cannot modify existing qdisc state. Preserve the kernel errno and accept EEXIST as the idempotent success case without logging it as an error.
Contributor
Author
|
Added more robustness fixes in separate commits. Compared with official kernel code for all the APIs as well. Compatibility remains wide as before, 4.13+ |
When RTM_NEWQDISC returns EEXIST, TC_H_CLSACT == TC_H_INGRESS (0xFFFFFFF1), so the occupied handle may belong to an ingress qdisc instead of clsact. Silent success in that case would leave us with no clsact attached and BPF filters would not be installed. Add netlink_qdisc_verify_clsact() which dumps qdiscs on the interface and checks TCA_KIND of the entry at TC_H_MAKE(TC_H_CLSACT, 0). Returns 0 only when the kind is "clsact"; returns -EINVAL otherwise. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Author
|
Fixed remaining issues - DUMP_INTR should now be handled properly everywhere, also if a |
The kernel may set NLM_F_DUMP_INTR on any message in a dump, not necessarily on the final NLMSG_DONE. Track it with a persistent flag checked at NLMSG_DONE, matching netlink_qdisc_verify_clsact, so an interrupted dump cannot be reported as a complete successful scan. Reset the flag when netlink_filter_del_on_parent restarts its dump. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
nicholasberlin
approved these changes
Jul 23, 2026
nicholasberlin
left a comment
Contributor
There was a problem hiding this comment.
Bots are happy, and LGTH(uman)
fearful-symmetry
approved these changes
Jul 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add functions to check if a TC filter exists, and to selectively delete one based on name, without touching other TC filters.