Skip to content

fix(attach): Keep uplink ingress program attached when Cilium reloads - #1571

Open
privateip wants to merge 1 commit into
mainfrom
fix/issue-1561
Open

privateip wants to merge 1 commit into
mainfrom
fix/issue-1561

Conversation

@privateip

@privateip privateip commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1561

Each time Cilium reloads, it deletes Galactic's uplink ingress filter, so gateways flap their local delivery report for about a second. Galactic now attaches that program through the kernel's tcx mechanism, which Cilium leaves alone, and pins it so it survives a CNI restart. The program runs ahead of Cilium, because Cilium ends processing for the packets it passes and today's filter never sees them. Kernels without tcx keep the classic filter.

Testing

  • Build, full unit suite and lint, including new tests for upgrade, restart, reordering, renamed interfaces, a failed move and the health check
  • Privileged root tests, including the regression test that deletes every classic filter the way Cilium does (CI's "Unit Tests (root)" job runs them)
  • Kind end-to-end test
  • Containerlab run with link churn on a Cilium-managed uplink

This goes ready once CI, including the root unit tests, is green. The Containerlab run follows on the staging labs.

Risk

  • Cilium no longer sees the outer form of the SRv6 packets Galactic decapsulates. It still sees all other traffic.
  • Another agent that also insists on running first would trade places with Galactic's program on every health check.
  • A downgrade leaves the new attachment in place, and the program then runs twice on packets it does not handle. The first comment gives the pins to remove.

@privateip privateip self-assigned this Dec 2, 2026
@privateip

Copy link
Copy Markdown
Contributor Author

Implementation detail for review.

Where. Everything is in internal/plumbing/ebpf/attach. The new tcx.go attaches, updates, moves, adopts, detaches and sweeps the link. Attach, Detach and the watch loop's reconcile go through it. checkAttachedOne and IngressAttachedTo accept the tcx link or the classic galactic_usid_ingress filter.

Pins. Links are pinned at /sys/fs/bpf/galactic/links/usid_ingress/<netns inode>_<interface>. galactic-gateway looks them up by interface name. The inode keeps test namespaces apart, since one bpffs serves the whole host. A renamed device's pin is renamed to match, because the kernel refuses a second link carrying the same program. Every attach and reconcile removes pins whose device is gone (ifindex 0).

Why the head, not the tail. The approved plan put the link at the tail, the order packets see today. tcx runs the next program only after a TC_ACT_UNSPEC verdict, so whatever sits behind Cilium never sees the packets it passes. That blind spot already affects today's classic filter on every device Cilium manages. Bonded uplinks keep working only because their member ports, which Cilium leaves alone, carry their own filter.

Ordering. Links use link.Head(). Cilium v1.20.4 attaches with link.Tail(), and its cil_from_netdev returns CTX_ACT_OK (TC_ACT_OK), which tcx treats as final. usid_ingress returns TC_ACT_UNSPEC for every packet it does not handle. When ingressLinkMisplaced finds ours behind another link, Handle.Healthy nudges the watcher. The move attaches the classic filter, detaches the old link, attaches the new one at the head, and removes the filter. A failed move is logged rather than returned, because Start treats an attach error as fatal.

Health text. The error is now galactic uSID ingress program not attached (no tcx link or tc filter). Nothing in the repo matched the old text.

Tests to run as root. Run sudo -E task test:unit-root, or go test -run 'TCX|Detach|Restart' ./internal/plumbing/ebpf/attach/ as root. TestAttach_SurvivesForeignClassicFilterDeletion is the regression test. The root tests also check three kernel behaviors the unit fakes cannot:

  1. A second link carrying the same program is refused.
  2. Update with the program already on the link succeeds.
  3. A link whose device is gone reports ifindex 0 and detaches cleanly.

Downgrade. The previous release manages only the classic filter. Remove /sys/fs/bpf/galactic/links/usid_ingress/* after rolling back.

@privateip privateip changed the title Keep Galactic's uplink ingress program attached when Cilium reloads fix(attach): Keep uplink ingress program attached when Cilium reloads Dec 2, 2026
Cilium deletes every classic tc filter on a device it attaches to
through tcx, after each reload of its own programs, without checking
whose they are. It reloads on pod and link churn, so
galactic_usid_ingress vanished from shared uplinks for about a second
at a time until the watch loop put it back. In that window the CNI
health check and the gateway's local delivery check both failed, and
core stopped serving the node's backends.

usid_ingress now attaches through a tcx link pinned under
/sys/fs/bpf/galactic/links/usid_ingress, which Cilium does not touch.
The link goes at the head of the chain. Cilium's cil_from_netdev
returns TC_ACT_OK, which tcx treats as final, so a program behind it
never sees the packets it passes; the classic filter had the same
blind spot. usid_ingress returns TC_ACT_UNSPEC for packets it does not
handle, so Cilium still sees all other traffic.

A restart updates the pinned link in place and removes any classic
filter an earlier version left. Kernels without tcx keep the classic
filter. A renamed device's pin is adopted under the new name. Pins
whose device is gone are removed on every attach and reconcile.

When another program's link lands ahead of ours, the health check asks
for a reconcile, which moves ours back to the head. Cilium attaches
its own links at the tail and updates them in place, so it never
triggers this. The kernel refuses one program twice on a hook, so the
classic filter stands in during the move and stays when the move
fails. A failed move is logged, not returned, since Start treats
attach errors as fatal.

The health check and IngressAttachedTo accept either attachment.

Fixes #1561
@privateip
privateip marked this pull request as ready for review December 2, 2026 01:18
@privateip
privateip requested a review from a team as a code owner December 2, 2026 01:18
@privateip

Copy link
Copy Markdown
Contributor Author

First pass: pr-adversary returned hold and pr-conventions-reviewer returned hold. The human decided both decision findings: the overlap with draft #598 is settled by whichever PR lands second rebasing, and this PR goes ready on green CI including the root unit tests, with the Containerlab link-churn run following on the staging labs.

Fixes applied: the classic filter is kept when a tcx move fails, with a test that fails without the fix; the Cilium tail-anchor citation; the conventional title; the checkbox test plan; and the history squashed to one commit wrapped at 72.

Second pass: pr-rereviewer returned merge. pr-conventions-reviewer returned hold on history only, which the squash resolved.

CI's root unit tests then failed four older tests that assumed a classic uplink filter. They were rewritten to count and clear either attachment kind. A narrow re-review found no assertion weakened.

CI on head cdeda23: Unit Tests (root), Unit Tests, Build, Lint and ci / Build and test all pass.

Not run: Kind e2e and the Containerlab run.

Auto-merge was left off on purpose. A person merges after approval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cilium removes Galactic's uplink uSID filter whenever it reloads

1 participant