Repository navigation
lib: cgen: detach the old Netfilter links on chain update #613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -264,8 +264,14 @@ static int _bf_link_update_nf(struct bf_link *link, int prog_fd) | |
| return bf_err_r(r, "failed to create nf_inet6 BPF link"); | ||
| new_inet6_fd = r; | ||
|
|
||
| // Detach old links - safe now that new ones are active | ||
| /* Detach old links - safe now that new ones are active. They were | ||
| * unpinned, so closing them only drops a reference: they would stay | ||
| * attached until bpffs releases the pinned inode, the old program would | ||
| * keep filtering, and its priority would stay busy. */ | ||
| (void)bf_bpf_link_detach(link->fd); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Claude: nit: This detach sequence (detach |
||
| closep(&link->fd); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Claude: suggestion: This PR doesn't introduce this, but it affects whether the update path is complete. When |
||
| if (link->fd_extra >= 0) | ||
| (void)bf_bpf_link_detach(link->fd_extra); | ||
| closep(&link->fd_extra); | ||
|
|
||
| // Update link with new file descriptors | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Claude: nit: Casting the detach result to
(void)matchesbf_handle_detach(). On this path, though, a failed detach produces no log, and its only symptom comes later: the old program keeps filtering and the nextchain updatefails with-EBUSY, with nothing pointing back to the detach. 414b9b2, which this restores, logged the failure withbf_warn_r(r, "failed to detach existing BPF_NETFILTER link"). Should we keep that warning here, for bothfdandfd_extra, so the laterEBUSYcan be traced? The update should still succeed, since the new links are already attached.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept
(void)likebf_handle_detach(): a Netfilter link's detach always returns 0 (bpf_nf_link_detach()), andlink->fdis valid here, so the warning could never fire.