Skip to content

Commit

Permalink
bpf: lb: un-break terminating backends for service without backend
Browse files Browse the repository at this point in the history
Continue to forward traffic for established connections, even when a
service loses its last active backends.

This needs a small adjustment in a BPF test that was relying on this
behaviour.

Fixes: 1835011 ("bpf: drop SVC traffic if no backend is available")
Signed-off-by: Julian Wiedmann <jwi@isovalent.com>
  • Loading branch information
julianwiedmann committed Apr 8, 2024
1 parent 0d72368 commit 0de6f0f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
16 changes: 12 additions & 4 deletions bpf/lib/lb.h
Original file line number Diff line number Diff line change
Expand Up @@ -870,8 +870,6 @@ static __always_inline int lb6_local(const void *map, struct __ctx_buff *ctx,

ipv6_addr_copy(&client_id.client_ip, &tuple->saddr);
#endif
if (unlikely(svc->count == 0))
return DROP_NO_SERVICE;

state->rev_nat_index = svc->rev_nat_index;

Expand All @@ -880,6 +878,9 @@ static __always_inline int lb6_local(const void *map, struct __ctx_buff *ctx,
SCOPE_REVERSE, CT_ENTRY_SVC, state, &monitor);
switch (ret) {
case CT_NEW:
if (unlikely(svc->count == 0))
goto no_service;

#ifdef ENABLE_SESSION_AFFINITY
if (lb6_svc_is_affinity(svc)) {
backend_id = lb6_affinity_backend_id_by_addr(svc, &client_id);
Expand Down Expand Up @@ -922,6 +923,9 @@ static __always_inline int lb6_local(const void *map, struct __ctx_buff *ctx,
if (backend && !state->syn)
break;

if (unlikely(svc->count == 0))
goto no_service;

backend_id = lb6_select_backend_id(ctx, key, tuple, svc);
backend = lb6_lookup_backend(ctx, backend_id);
if (!backend)
Expand Down Expand Up @@ -1509,15 +1513,16 @@ static __always_inline int lb4_local(const void *map, struct __ctx_buff *ctx,
.client_ip = saddr,
};
#endif
if (unlikely(svc->count == 0))
return DROP_NO_SERVICE;

state->rev_nat_index = svc->rev_nat_index;

ret = ct_lazy_lookup4(map, tuple, ctx, is_fragment, l4_off, has_l4_header,
CT_SERVICE, SCOPE_REVERSE, CT_ENTRY_SVC, state, &monitor);
switch (ret) {
case CT_NEW:
if (unlikely(svc->count == 0))
goto no_service;

#ifdef ENABLE_SESSION_AFFINITY
if (lb4_svc_is_affinity(svc)) {
backend_id = lb4_affinity_backend_id_by_addr(svc, &client_id);
Expand Down Expand Up @@ -1561,6 +1566,9 @@ static __always_inline int lb4_local(const void *map, struct __ctx_buff *ctx,
if (backend && !state->syn)
break;

if (unlikely(svc->count == 0))
goto no_service;

backend_id = lb4_select_backend_id(ctx, key, tuple, svc);
backend = lb4_lookup_backend(ctx, backend_id);
if (!backend)
Expand Down
9 changes: 5 additions & 4 deletions bpf/tests/tc_nodeport_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ struct {
* \---------------------------/
*/

static __always_inline int build_packet(struct __ctx_buff *ctx)
static __always_inline int build_packet(struct __ctx_buff *ctx,
__be16 sport)
{
struct pktgen builder;
volatile const __u8 *src = mac_one;
Expand All @@ -72,7 +73,7 @@ static __always_inline int build_packet(struct __ctx_buff *ctx)
l4 = pktgen__push_ipv4_tcp_packet(&builder,
(__u8 *)src, (__u8 *)dst,
v4_pod_one, v4_svc_one,
tcp_src_one, tcp_svc_one);
sport, tcp_svc_one);
if (!l4)
return TEST_ERROR;

Expand All @@ -90,7 +91,7 @@ static __always_inline int build_packet(struct __ctx_buff *ctx)
PKTGEN("tc", "hairpin_flow_1_forward_v4")
int hairpin_flow_forward_pktgen(struct __ctx_buff *ctx)
{
return build_packet(ctx);
return build_packet(ctx, tcp_src_one);
}

/* Test that sending a packet from a pod to its own service gets source nat-ed
Expand Down Expand Up @@ -398,7 +399,7 @@ int tc_drop_no_backend_setup(struct __ctx_buff *ctx)
{
int ret;

ret = build_packet(ctx);
ret = build_packet(ctx, tcp_src_two);
if (ret)
return ret;

Expand Down

0 comments on commit 0de6f0f

Please sign in to comment.