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.
Hi! I've been playing around with Go's bindings for
libbpf
(i.e.aquasecurity/libbpfgo
) and found that their example of how to use BPF-based TC filters did not clean the backingqdisc
after the cleanup.Even though this behaviour was not causing any issues, I decided to dive into
libbpf
's implementation and found that, indeed, a backingqdisc
is only removed if the attach point of the hook isBPF_TC_INGRESS|BPF_TC_EGRESS
which is usually not the case. In that way,libbpf
's API is 'forcing' the user to explicitly request the clearing of theqdisc
. This behaviour is documented in the associated patch series.Anyway, this PR simply forces the removal of the backing
qdisc
by settingtc_hook.attach_point = BPF_TC_INGRESS|BPF_TC_EGRESS;
just before the call tobpf_tc_hook_destroy
. Given the example is rather self-contained I suppose that makes sense? The rationale behind opening up the PR is that it took me several hours to get to the patch series and I was hoping the next person wouldn't have to do the same... Maybe this can be left as a comment intc.c
even if one decides not to remove theqdisc
?In a real-world approach I suppose one could use the return value of
bpf_tc_hook_create
to decide whether to remove theqdisc
or not so that the backingqdisc
is only removed if the return value is-EEXIST
? Judging by the comment above the call tobpf_tc_hook_create
I suppose this behaviour was known by the original author oftc.c
, but I feel like a clarification would be great for people using these examples as scaffolding for larger projects.Thanks a ton for all this work! It's really helped me up to this moment and I'm sure it'll continue to do so for quite a while!