Skip to content

Commit

Permalink
Added a proxy only mode
Browse files Browse the repository at this point in the history
  • Loading branch information
TrekkieCoder committed Jul 25, 2024
1 parent 855224b commit fce6119
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
91 changes: 90 additions & 1 deletion kernel/loxilb_libdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ typedef struct llb_dp_struct
int have_loader;
int have_sockrwr;
int have_sockmap;
int have_noebpf;
struct llb_kern_mon *monp;
const char *cgroup_dfl_path;
int cgfd;
Expand Down Expand Up @@ -399,6 +400,10 @@ llb_packet_trace_en(int en)
struct dp_intf_tact l2a;
void *next_key = &nkey;

if (xh->have_noebpf) {
return 0;
}

if (en < 0 || en > 2) {
return -1;
}
Expand Down Expand Up @@ -638,6 +643,10 @@ llb_setup_kern_sock(const char *cgroup_path)
int cgfd = -1;
int pfd;

if (xh->have_noebpf) {
return 0;
}

if (xh->cgfd <= 0) {
cgfd = cgroup_create_get(cgroup_path);
if (cgfd < 0) {
Expand Down Expand Up @@ -709,6 +718,10 @@ llb_setup_kern_mon(void)
struct llb_kern_mon *prog;
int err;

if (xh->have_noebpf) {
return 0;
}

// Open and load eBPF Program
prog = llb_kern_mon__open();
if (!prog) {
Expand Down Expand Up @@ -813,6 +826,10 @@ llb_setup_kern_sockmap_skmsg_helper(int map_fd)
struct bpf_object *bpf_obj2;
int pfd2;

if (xh->have_noebpf) {
return 0;
}

bpf_obj2 = bpf_object__open(LLB_SOCK_DIR_IMG_BPF);
map2 = bpf_object__find_map_by_name(bpf_obj2, "sock_proxy_map");
if (map2 == NULL) {
Expand Down Expand Up @@ -872,6 +889,10 @@ llb_setup_kern_sockmap_strparser_helper(int sockmap_fd)
int map_fd;
int pfd2;

if (xh->have_noebpf) {
return 0;
}

bpf_obj2 = bpf_object__open(LLB_SOCK_SP_IMG_BPF);
#ifdef HAVE_SOCKOPS
map2 = bpf_object__find_map_by_name(bpf_obj2, "sock_proxy_map");
Expand Down Expand Up @@ -940,6 +961,10 @@ llb_setup_kern_sockmap_strparser_helper(int sockmap_fd)
static int
llb_sockmap_op(struct llb_sockmap_key *key, int fd, int doadd)
{
if (xh->have_noebpf) {
return 0;
}

if (xh->smfd <= 0) {
assert(0);
}
Expand All @@ -966,6 +991,10 @@ llb_setup_kern_sockmap(const char *cgroup_path)
int map_fd = -1;
int map_fd2 = -1;

if (xh->have_noebpf) {
return 0;
}

#ifdef HAVE_SOCKOPS
if (xh->cgfd <= 0) {
cgfd = cgroup_create_get(cgroup_path);
Expand Down Expand Up @@ -1523,7 +1552,9 @@ llb_xh_init(llb_dp_struct_t *xh)
assert(0);
}
} else {
llb_dp_maps_attach(xh);
if (!xh->have_noebpf) {
llb_dp_maps_attach(xh);
}
}

if (xh->have_mtrace) {
Expand Down Expand Up @@ -1723,6 +1754,10 @@ llb_fetch_map_stats_used(int tbl, uint32_t e, int clr, int *used)
void
llb_collect_map_stats(int tid)
{
if (xh->have_noebpf) {
return;
}

return llb_fetch_map_stats_raw(tid, NULL, NULL);
}

Expand All @@ -1732,6 +1767,10 @@ llb_fetch_pol_map_stats(int tid, uint32_t e, void *ppass, void *pdrop)
llb_dp_map_t *t;
struct dp_pol_tact pa;

if (xh->have_noebpf) {
return 0;
}

if (tid < 0 || tid >= LL_DP_MAX_MAP)
return -1;

Expand Down Expand Up @@ -1764,6 +1803,10 @@ llb_map_loop_and_delete(int tid, dp_map_walker_t cb, dp_map_ita_t *it)
llb_dp_map_t *t;
uint32_t n = 0;

if (xh->have_noebpf) {
return;
}

if (!cb) return;

if (tid < 0 || tid >= LL_DP_MAX_MAP)
Expand Down Expand Up @@ -1800,6 +1843,9 @@ llb_clear_map_stats_internal(int tid, __u32 idx, bool wipe)
if (tid < 0 || tid >= LL_DP_MAX_MAP)
return;

if (xh->have_noebpf)
return;

t = &xh->maps[tid];
if (t->has_pb) {
if (t->pb_xtid > 0) {
Expand Down Expand Up @@ -2157,6 +2203,11 @@ llb_add_map_elem(int tbl, void *k, void *v)
}
}

if (xh->have_noebpf) {
ret = 0;
goto ulock_out;
}

if (tbl == LL_DP_FW4_MAP) {
ret = llb_add_mf_map_elem__(tbl, k, v);
} else {
Expand All @@ -2171,6 +2222,7 @@ llb_add_map_elem(int tbl, void *k, void *v)
llb_add_map_elem_nat_post_proc(k, v);
}
}
ulock_out:
XH_UNLOCK();

return ret;
Expand Down Expand Up @@ -2294,13 +2346,23 @@ llb_del_map_elem_wval(int tbl, void *k, void *v)
proxy_delete_entry(&pk, &pa);
}

if (xh->have_noebpf) {
XH_UNLOCK();
return 0;
}

ret = bpf_map_lookup_elem(llb_map2fd(tbl), k, &t);
if (ret != 0) {
XH_UNLOCK();
return -EINVAL;
}
}

if (xh->have_noebpf) {
XH_UNLOCK();
return 0;
}

if (tbl == LL_DP_FW4_MAP) {
ret = llb_del_mf_map_elem__(tbl, k);
} else {
Expand Down Expand Up @@ -2371,6 +2433,10 @@ ll_age_fcmap(void)
struct dp_fc_tacts *fc_val;
uint64_t ns = get_os_nsecs();

if (xh->have_noebpf) {
return;
}

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

Expand Down Expand Up @@ -2682,6 +2748,10 @@ ll_age_ctmap(void)
ct_arg_struct_t *as;
uint64_t ns = get_os_nsecs();

if (xh->have_noebpf) {
return;
}

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

Expand Down Expand Up @@ -3086,6 +3156,10 @@ llb_ebpf_link_detach(struct config *cfg)
{
char cmd[PATH_MAX];

if (xh->have_noebpf) {
return 0;
}

if (cfg->tc_bpf) {
/* ntc is netlox's modified tc tool */
if (cfg->tc_egr_bpf) {
Expand Down Expand Up @@ -3114,6 +3188,10 @@ llb_dp_link_attach(const char *ifname,
int nr = 0;
int must_load = 0;

if (xh->have_noebpf) {
return 0;
}

assert(psec);
assert(ifname);

Expand Down Expand Up @@ -3224,14 +3302,25 @@ loxilb_main(struct ebpfcfg *cfg)
xh->have_ptrace = cfg->have_ptrace;
xh->nodenum = cfg->nodenum;
xh->logfp = fp;
xh->have_noebpf = cfg->have_noebpf;

// FIXME - Experimental
xh->have_sockrwr = cfg->have_sockrwr;
xh->have_sockmap = cfg->have_sockmap;

xh->egr_hooks = cfg->egr_hooks;
if (xh->have_sockrwr != 0) {
xh->cgroup_dfl_path = CGROUP_PATH;
}

if (xh->have_noebpf) {
xh->have_loader = 0;
xh->have_mtrace = 0;
xh->have_ptrace = 0;
xh->have_sockrwr = 0;
xh->have_sockmap = 0;
xh->egr_hooks = 0;
}
}

llb_xh_init(xh);
Expand Down
1 change: 1 addition & 0 deletions kernel/loxilb_libdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct ebpfcfg {
int egr_hooks;
int have_sockrwr;
int have_sockmap;
int have_noebpf;
};

void loxilb_set_loglevel(struct ebpfcfg *cfg);
Expand Down

0 comments on commit fce6119

Please sign in to comment.