Skip to content

bpf: fix svc annotation handling#41310

Merged
borkmann merged 2 commits intomainfrom
pr/lb-alg
Aug 21, 2025
Merged

bpf: fix svc annotation handling#41310
borkmann merged 2 commits intomainfrom
pr/lb-alg

Conversation

@borkmann
Copy link
Copy Markdown
Member

(see commit msg)

Make it more clear that the Cilium agent never pulls in this code, but
that this is really only used from unit tests.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
@borkmann borkmann added area/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages. release-note/misc This PR makes changes that have no direct user impact. needs-backport/1.18 This PR / issue needs backporting to the v1.18 branch labels Aug 21, 2025
Dmitriy says:

  When --bpf-lb-algorithm-annotation feature is enabled, BPF code
  in run-time may not select load balancer algorithm for service at
  all for previously existing services. Thus, this behavior broke
  all new network connections to the service if it had an unknown
  algorithm value in service bpf map entry. This bug is stably
  reproducible for NodePort, HostPort, LocalRedirect service types.

  This commit solves the problem as follows: in the situation where
  the BPF service map contains an unknown LB algorithm, it simply uses
  the default LB algorithm from the --bpf-lb-algorithm option.

lb{4,6}_algorithm() should return a proper algorithm that is going to
be used in the datapath. Either a service had an annotation, or if not
then the user configured default should be picked.

One corner case is when we come from a future Cilium version where
users had an algorithm annotation on the service, which the current
Cilium version does not support. In that case we can only treat this
as a hint and need to fallback to the default.

Note that in the old code before the LB control plane rework, the
GetAnnotationServiceLoadBalancingAlgorithm() was pushing through
any annotation which was not loadbalancer.SVCLoadBalancingAlgorithmUndef
and otherwise the function was returning the default selected algorithm.
After the rework we just propagate loadbalancer.ToSVCLoadBalancingAlgorithm()
directly.

This meant that handling of loadbalancer.SVCLoadBalancingAlgorithmUndef
was pushed to runtime, therefore for services with no explicit annotation
this triggered the default case which led to drops.

Another side-note: loadbalancer.ToSVCLoadBalancingAlgorithm() does not
translate LB_SELECTION_FIRST. The latter is only ever used in BPF unit
tests.

Co-developed-by: Dmitriy Andreychenko <dmitriy.andreychenko@flant.com>
Signed-off-by: Dmitriy Andreychenko <dmitriy.andreychenko@flant.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
@borkmann
Copy link
Copy Markdown
Member Author

/test

@borkmann borkmann requested review from aspsk and joamaki August 21, 2025 11:19
@borkmann borkmann marked this pull request as ready for review August 21, 2025 11:19
@borkmann borkmann requested a review from a team as a code owner August 21, 2025 11:19
@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Aug 21, 2025
@borkmann borkmann merged commit 26b5bbc into main Aug 21, 2025
384 of 387 checks passed
@borkmann borkmann deleted the pr/lb-alg branch August 21, 2025 15:46
@pippolo84 pippolo84 mentioned this pull request Aug 25, 2025
17 tasks
@pippolo84 pippolo84 added backport-pending/1.18 The backport for Cilium 1.18.x for this PR is in progress. and removed needs-backport/1.18 This PR / issue needs backporting to the v1.18 branch labels Aug 25, 2025
@github-actions github-actions bot added backport-done/1.18 The backport for Cilium 1.18.x for this PR is done. and removed backport-pending/1.18 The backport for Cilium 1.18.x for this PR is in progress. labels Sep 1, 2025
@cilium-release-bot cilium-release-bot bot moved this to Released in cilium v1.19.0 Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/datapath Impacts bpf/ or low-level forwarding details, including map management and monitor messages. backport-done/1.18 The backport for Cilium 1.18.x for this PR is done. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/misc This PR makes changes that have no direct user impact.

Projects

No open projects
Status: Released

Development

Successfully merging this pull request may close these issues.

6 participants