Skip to content

Commit 385035b

Browse files
bpf: lb: use dedicated new_backend bool
Update the change introduced by 64527fb ("bpf: dsr: always forward DSR info to newly selected remote backend"), and transport the `new_backend` information via a dedicated bool. This seems to help with BPF program complexity. Signed-off-by: Julian Wiedmann <jwi@isovalent.com>
1 parent 43c1a69 commit 385035b

4 files changed

Lines changed: 23 additions & 16 deletions

File tree

bpf/bpf_lxc.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ static __always_inline int __per_packet_lb_svc_xlate_4(void *ctx, struct iphdr *
205205
#endif /* ENABLE_NODEPORT */
206206

207207
if (svc) {
208+
bool new_backend __maybe_unused = false;
208209
const struct lb4_backend *backend;
209210

210211
#if defined(ENABLE_L7_LB)
@@ -231,7 +232,7 @@ static __always_inline int __per_packet_lb_svc_xlate_4(void *ctx, struct iphdr *
231232

232233
ret = lb4_local(get_ct_map4(&tuple), ctx, fraginfo,
233234
l4_off, &key, &tuple, svc, &ct_state_new,
234-
&backend, ext_err, NULL);
235+
&backend, &new_backend, ext_err, NULL);
235236

236237
if (IS_ERR(ret)) {
237238
if (ret == DROP_NO_SERVICE) {
@@ -383,6 +384,7 @@ static __always_inline int __per_packet_lb_svc_xlate_6(void *ctx, struct ipv6hdr
383384
#endif /* ENABLE_NODEPORT */
384385

385386
if (svc) {
387+
bool new_backend __maybe_unused = false;
386388
const struct lb6_backend *backend;
387389

388390
#if defined(ENABLE_L7_LB)
@@ -401,7 +403,7 @@ static __always_inline int __per_packet_lb_svc_xlate_6(void *ctx, struct ipv6hdr
401403

402404
ret = lb6_local(get_ct_map6(&tuple), ctx, fraginfo,
403405
l4_off, &key, &tuple, svc, &ct_state_new,
404-
&backend, ext_err, NULL);
406+
&backend, &new_backend, ext_err, NULL);
405407

406408
if (IS_ERR(ret)) {
407409
if (ret == DROP_NO_SERVICE) {

bpf/lib/conntrack.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ struct ct_state {
5353
reserved1:1, /* Was auth_required, not used in production anywhere */
5454
from_tunnel:1, /* Connection is from tunnel */
5555
closing:1,
56-
new_backend:1, /* Service connection was assigned a new backend */
57-
reserved:6;
56+
reserved:7;
5857
__u32 src_sec_id;
5958
__u32 backend_id; /* Backend ID in lb4_backends */
6059
};

bpf/lib/lb.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,7 @@ static __always_inline int lb6_local(const void *map, struct __ctx_buff *ctx,
13811381
const struct lb6_service *svc,
13821382
struct ct_state *state,
13831383
const struct lb6_backend **selected_backend,
1384+
bool *new_backend,
13841385
__s8 *ext_err,
13851386
const struct lb6_backend *forced_backend)
13861387
{
@@ -1442,7 +1443,7 @@ static __always_inline int lb6_local(const void *map, struct __ctx_buff *ctx,
14421443
if (backend == NULL)
14431444
goto no_service;
14441445

1445-
state->new_backend = true;
1446+
*new_backend = true;
14461447
}
14471448

14481449
state->backend_id = backend_id;
@@ -1490,7 +1491,7 @@ static __always_inline int lb6_local(const void *map, struct __ctx_buff *ctx,
14901491
if (!backend)
14911492
goto no_service;
14921493

1493-
state->new_backend = true;
1494+
*new_backend = true;
14941495
state->rev_nat_index = svc->rev_nat_index;
14951496
ct_update_svc_entry(map, tuple, backend_id, svc->rev_nat_index);
14961497
}
@@ -2207,6 +2208,7 @@ static __always_inline int lb4_local(const void *map, struct __ctx_buff *ctx,
22072208
const struct lb4_service *svc,
22082209
struct ct_state *state,
22092210
const struct lb4_backend **selected_backend,
2211+
bool *new_backend,
22102212
__s8 *ext_err,
22112213
const struct lb4_backend *forced_backend)
22122214
{
@@ -2272,7 +2274,7 @@ static __always_inline int lb4_local(const void *map, struct __ctx_buff *ctx,
22722274
if (backend == NULL)
22732275
goto no_service;
22742276

2275-
state->new_backend = true;
2277+
*new_backend = true;
22762278
}
22772279

22782280
state->backend_id = backend_id;
@@ -2320,7 +2322,7 @@ static __always_inline int lb4_local(const void *map, struct __ctx_buff *ctx,
23202322
if (!backend)
23212323
goto no_service;
23222324

2323-
state->new_backend = true;
2325+
*new_backend = true;
23242326
state->rev_nat_index = svc->rev_nat_index;
23252327
ct_update_svc_entry(map, tuple, backend_id, svc->rev_nat_index);
23262328
}

bpf/lib/nodeport.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static __always_inline bool nodeport_uses_dsr(bool flip __maybe_unused)
131131
#define NEED_DSR_INFO (1 << 16)
132132

133133
static __always_inline bool
134-
nodeport_need_dsr_info(__u8 nexthdr, const struct ct_state *ct_state)
134+
nodeport_need_dsr_info(__u8 nexthdr, bool syn, bool new_backend)
135135
{
136136
/* We only need to embed the DSR info into the first packet of a connection
137137
* (since it will then be cached on the backend node).
@@ -140,9 +140,7 @@ nodeport_need_dsr_info(__u8 nexthdr, const struct ct_state *ct_state)
140140
* We also send DSR info for the first TCP packet towards a new backend,
141141
* so that it can at least RevDNAT its RST reply.
142142
*/
143-
return (nexthdr != IPPROTO_TCP) ||
144-
ct_state->new_backend ||
145-
ct_state->syn;
143+
return (nexthdr != IPPROTO_TCP) || syn || new_backend;
146144
}
147145

148146
#if defined(ENABLE_IPV4)
@@ -1382,6 +1380,7 @@ static __always_inline int nodeport_svc_lb6(struct __ctx_buff *ctx,
13821380
bool *punt_to_stack __maybe_unused,
13831381
__s8 *ext_err)
13841382
{
1383+
bool new_backend __maybe_unused = false;
13851384
struct ct_state ct_state_svc = {};
13861385
const struct lb6_backend *backend;
13871386
const struct lb6_backend *forced_be_p __maybe_unused = NULL;
@@ -1446,7 +1445,7 @@ static __always_inline int nodeport_svc_lb6(struct __ctx_buff *ctx,
14461445
}
14471446
}
14481447
ret = lb6_local(get_ct_map6(tuple), ctx, fraginfo, l4_off,
1449-
key, tuple, svc, &ct_state_svc, &backend,
1448+
key, tuple, svc, &ct_state_svc, &backend, &new_backend,
14501449
ext_err, forced_be_p);
14511450
if (IS_ERR(ret)) {
14521451
if (ret == DROP_NO_SERVICE) {
@@ -1535,7 +1534,9 @@ static __always_inline int nodeport_svc_lb6(struct __ctx_buff *ctx,
15351534
#elif DSR_ENCAP_MODE == DSR_ENCAP_GENEVE || DSR_ENCAP_MODE == DSR_ENCAP_NONE
15361535
__u32 port = key->dport;
15371536

1538-
if (nodeport_need_dsr_info(tuple->nexthdr, &ct_state_svc))
1537+
if (nodeport_need_dsr_info(tuple->nexthdr,
1538+
ct_state_svc.syn,
1539+
new_backend))
15391540
port |= NEED_DSR_INFO;
15401541

15411542
ctx_store_meta(ctx, CB_PORT, port);
@@ -2710,6 +2711,7 @@ static __always_inline int nodeport_svc_lb4(struct __ctx_buff *ctx,
27102711
bool *punt_to_stack __maybe_unused,
27112712
__s8 *ext_err)
27122713
{
2714+
bool new_backend __maybe_unused = false;
27132715
const struct lb4_backend *backend;
27142716
struct ct_state ct_state_svc = {};
27152717
__u32 cluster_id = 0;
@@ -2796,7 +2798,7 @@ static __always_inline int nodeport_svc_lb4(struct __ctx_buff *ctx,
27962798
}
27972799
ret = lb4_local(get_ct_map4(tuple), ctx, fraginfo, l4_off,
27982800
key, tuple, svc, &ct_state_svc, &backend,
2799-
ext_err, tmp);
2801+
&new_backend, ext_err, tmp);
28002802
if (IS_ERR(ret)) {
28012803
if (ret == DROP_NO_SERVICE) {
28022804
if (!CONFIG(enable_no_service_endpoints_routable))
@@ -2911,7 +2913,9 @@ static __always_inline int nodeport_svc_lb4(struct __ctx_buff *ctx,
29112913
#elif DSR_ENCAP_MODE == DSR_ENCAP_GENEVE || DSR_ENCAP_MODE == DSR_ENCAP_NONE
29122914
__u32 port = key->dport;
29132915

2914-
if (nodeport_need_dsr_info(tuple->nexthdr, &ct_state_svc))
2916+
if (nodeport_need_dsr_info(tuple->nexthdr,
2917+
ct_state_svc.syn,
2918+
new_backend))
29152919
port |= NEED_DSR_INFO;
29162920

29172921
ctx_store_meta(ctx, CB_PORT, port);

0 commit comments

Comments
 (0)