Skip to content

Commit

Permalink
Better handling of FC map
Browse files Browse the repository at this point in the history
  • Loading branch information
TrekkieCoder committed Jan 11, 2025
1 parent 4fff6e4 commit 73f2349
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 11 deletions.
10 changes: 6 additions & 4 deletions common/llb_dpapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@

#define LLB_NAT_STAT_CID(rid, aid) ((((rid) & 0xfff) << 4) | (aid & 0xf))

/* Hard-timeout of 40s for fc dp entry */
#define FC_V4_DPTO (60000000000)
/* Hard-timeout of 120s for fc dp entry */
#define FC_V4_DPTO (120000000000)

/* Hard-timeout of 2m for fc cp entry */
#define FC_V4_CPTO (120000000000)
/* fc cp sweep period od 30m */
#define FC_SWEEP_PERIOD (1800000000000)
/* Hard-timeout of 15m for fc cp entry */
#define FC_V4_CPTO ( 900000000000)

/* Hard-timeout of 30m for ct entry */
#define CT_V4_CPTO (1800000000000)
Expand Down
23 changes: 23 additions & 0 deletions kernel/llb_kern_ct.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,27 @@ dp_run_ct_helper(struct xfi *xf)
return 0;
}

static void __always_inline
dp_ct_related_fc_rm(struct dp_ct_key *ctk)
{
struct dp_fcv4_key key;

if (ctk->v6 || ctk->ident || ctk->type) {
return;
}

key.daddr = ctk->daddr4;
key.saddr = ctk->saddr4;
key.sport = ctk->sport;
key.dport = ctk->dport;
key.l4proto = ctk->l4proto;
key.pad = 0;
key.in_port = 0;

bpf_map_delete_elem(&fc_v4_map, &key);
return;
}

#ifdef HAVE_DP_EXTCT
#define DP_RUN_CT_HELPER(x) \
do { \
Expand Down Expand Up @@ -1808,6 +1829,8 @@ dp_ct_in(void *ctx, struct xfi *xf)
} else if (smr == CT_SMR_ERR || smr == CT_SMR_CTD) {
bpf_map_delete_elem(&ct_map, &xkey);
bpf_map_delete_elem(&ct_map, &key);
dp_ct_related_fc_rm(&xkey);
dp_ct_related_fc_rm(&key);

if (atdat->ctd.dir == CT_DIR_IN) {
dp_ct_ctd(xf, &key, &xkey, atdat, axtdat);
Expand Down
10 changes: 6 additions & 4 deletions kernel/llb_kern_fcfwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ dp_do_fcv4_lkup(void *ctx, struct xfi *xf)
return 0;
}

#ifdef HAVE_DP_FC_TMO
/* Check timeout */
if (bpf_ktime_get_ns() - acts->its > FC_V4_DPTO) {
LL_FC_PRINTK("[FCH4] hto");
Expand All @@ -78,6 +79,7 @@ dp_do_fcv4_lkup(void *ctx, struct xfi *xf)
xf->pm.rcode |= LLB_PIPE_RC_FCTO;
return 0;
}
#endif

LL_FC_PRINTK("[FCH4] key found act-sz %d\n", sizeof(struct dp_fc_tacts));

Expand Down Expand Up @@ -161,13 +163,13 @@ dp_do_fcv4_lkup(void *ctx, struct xfi *xf)
LL_FC_PRINTK("[FCH4] to-cp-act\n");
LLBS_PPLN_TRAPC(xf, LLB_PIPE_RC_ACT_TRAP);
} else {
goto del_out;
goto slow_pout;
}

/* Catch any conditions which need us to go to cp/ct */
if (xf->pm.l4fin) {
acts->ca.ftrap = 1;
goto del_out;
goto slow_pout;
}

DP_RUN_CT_HELPER(xf);
Expand All @@ -186,8 +188,8 @@ dp_do_fcv4_lkup(void *ctx, struct xfi *xf)

return ret;

del_out:
bpf_map_delete_elem(&fc_v4_map, &key);
slow_pout:
//bpf_map_delete_elem(&fc_v4_map, &key);
xf->pm.rcode |= LLB_PIPE_RC_FCBP;
return 0;
}
Expand Down
39 changes: 36 additions & 3 deletions kernel/loxilb_libdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ typedef struct llb_dp_struct
FILE *logfp;
struct throttler cpt;
uint64_t lctts;
uint64_t lfcts;
} llb_dp_struct_t;

#define XH_LOCK() pthread_rwlock_wrlock(&xh->lock)
Expand Down Expand Up @@ -2480,6 +2481,14 @@ ll_age_fcmap(void)
return;
}

if (ns - xh->lfcts < FC_SWEEP_PERIOD) {
return;
}

log_error("FC TIMEO");

xh->lfcts = ns;

fc_val = calloc(1, sizeof(*fc_val));
if (!fc_val) return;

Expand Down Expand Up @@ -2663,6 +2672,27 @@ ll_ct_get_state(struct dp_ct_key *key, struct dp_ct_tact *adat, bool *est, uint6
}
}

static void __always_inline
dp_ct_related_fc_rm(struct dp_ct_key *ctk)
{
struct dp_fcv4_key key;

if (ctk->v6 || ctk->ident || ctk->type) {
return;
}

key.daddr = ctk->daddr4;
key.saddr = ctk->saddr4;
key.sport = ctk->sport;
key.dport = ctk->dport;
key.l4proto = ctk->l4proto;
key.pad = 0;
key.in_port = 0;

bpf_map_delete_elem(llb_map2fd(LL_DP_FCV4_MAP), &key);
return;
}

static int
ll_ct_map_ent_has_aged(int tid, void *k, void *ita)
{
Expand Down Expand Up @@ -2732,6 +2762,8 @@ ll_ct_map_ent_has_aged(int tid, void *k, void *ita)
return 0;
}

dp_ct_related_fc_rm(key);

log_trace("ct: rdir not found #%s:%d -> %s:%d (%d)#",
sstr, ntohs(xkey.sport),
dstr, ntohs(xkey.dport),
Expand Down Expand Up @@ -2784,8 +2816,10 @@ ll_ct_map_ent_has_aged(int tid, void *k, void *ita)
ll_send_ctep_reset(&xkey, &axdat);
llb_maptrace_uhook(LL_DP_CT_MAP, 0, &xkey, sizeof(xkey), NULL, 0);
bpf_map_delete_elem(t->map_fd, &xkey);
dp_ct_related_fc_rm(&xkey);
llb_clear_map_stats(LL_DP_CT_STATS_MAP, axdat.ca.cidx);
}
dp_ct_related_fc_rm(key);
return 1;
}

Expand Down Expand Up @@ -2842,8 +2876,7 @@ ll_age_ctmap(void)
}

llb_map_loop_and_delete(LL_DP_CT_MAP, ll_ct_map_ent_has_aged, &it);

if (ns - xh->lctts > 240000000000) {
if (ns - xh->lctts > 120000000000) {
as->dir = CT_DIR_OUT;
llb_map_loop_and_delete(LL_DP_CT_MAP, ll_ct_map_ent_has_aged, &it);
xh->lctts = ns;
Expand Down Expand Up @@ -3008,7 +3041,6 @@ static void
ll_map_ct_rm_any(void)
{
dp_map_ita_t it;
int i = 0;
struct dp_ct_key next_key;
struct dp_ct_tact *adat;
ct_arg_struct_t *as;
Expand Down Expand Up @@ -3429,6 +3461,7 @@ loxilb_main(struct ebpfcfg *cfg)
}

xh->lctts = get_os_nsecs();
xh->lfcts = get_os_nsecs();

if (xh->have_noebpf) {
xh->have_loader = 0;
Expand Down

0 comments on commit 73f2349

Please sign in to comment.