Skip to content
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

datapath: Fix back-edge in bpf_sock for older kernels #11739

Merged
merged 1 commit into from May 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 24 additions & 20 deletions bpf/bpf_sock.c
Expand Up @@ -289,10 +289,23 @@ static __always_inline int __sock4_xlate_fwd(struct bpf_sock_addr *ctx,
if (svc->affinity) {
backend_id = lb4_affinity_backend_id_by_netns(svc, &id);
backend_from_affinity = true;

if (backend_id != 0) {
backend = __lb4_lookup_backend(backend_id);
if (!backend) {
/* Backend from the session affinity no longer exists,
* thus select a new one. Also, remove the affinity,
* so that if the svc doesn't have any backend, a
* subsequent request to the svc doesn't hit the
* reselection again.
*/
lb4_delete_affinity_by_netns(svc, &id);
backend_id = 0;
}
}
}

if (backend_id == 0) {
reselect_backend:
backend_from_affinity = false;

key.slave = (sock_local_cookie(ctx_full) % svc->count) + 1;
Expand All @@ -303,21 +316,10 @@ static __always_inline int __sock4_xlate_fwd(struct bpf_sock_addr *ctx,
}

backend_id = slave_svc->backend_id;
backend = __lb4_lookup_backend(backend_id);
}

backend = __lb4_lookup_backend(backend_id);
if (!backend) {
if (backend_from_affinity) {
/* Backend from the session affinity no longer exists,
* thus select a new one. Also, remove the affinity,
* so that if the svc doesn't have any backend, a
* subsequent request to the svc doesn't hit the
* reselection again.
*/
lb4_delete_affinity_by_netns(svc, &id);
goto reselect_backend;
}

update_metrics(0, METRIC_EGRESS, REASON_LB_NO_BACKEND);
return -ENOENT;
}
Expand Down Expand Up @@ -717,10 +719,17 @@ static __always_inline int __sock6_xlate_fwd(struct bpf_sock_addr *ctx,
if (svc->affinity) {
backend_id = lb6_affinity_backend_id_by_netns(svc, &id);
backend_from_affinity = true;

if (backend_id != 0) {
backend = __lb6_lookup_backend(backend_id);
if (!backend) {
lb6_delete_affinity_by_netns(svc, &id);
backend_id = 0;
}
}
}

if (backend_id == 0) {
reselect_backend:
backend_from_affinity = false;

key.slave = (sock_local_cookie(ctx) % svc->count) + 1;
Expand All @@ -731,15 +740,10 @@ static __always_inline int __sock6_xlate_fwd(struct bpf_sock_addr *ctx,
}

backend_id = slave_svc->backend_id;
backend = __lb6_lookup_backend(backend_id);
}

backend = __lb6_lookup_backend(backend_id);
if (!backend) {
if (backend_from_affinity) {
lb6_delete_affinity_by_netns(svc, &id);
goto reselect_backend;
}

update_metrics(0, METRIC_EGRESS, REASON_LB_NO_BACKEND);
return -ENOENT;
}
Expand Down