Skip to content

Commit 53fd9ee

Browse files
committed
fixup! luaxdp: refactor callback API to use ctx object
Signed-off-by: Ashwani Kumar Kamal <ashwanikamal.im421@gmail.com>
1 parent e199437 commit 53fd9ee

1 file changed

Lines changed: 4 additions & 22 deletions

File tree

lib/luaxdp.c

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
#include <linux/bpf.h>
2121

2222
#include <lunatik.h>
23+
#include <lunatik_ebpf.h>
2324

2425
#include "luarcu.h"
2526
#include "luadata.h"
26-
#include "lunatik_bpf.h"
2727

2828
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 4, 0))
2929
#include <linux/btf.h>
@@ -157,31 +157,13 @@ static int luaxdp_handler(lua_State *L, luaxdp_ctx_t *ctx)
157157
return 0;
158158
}
159159

160-
static inline int luaxdp_checkruntimes(void)
161-
{
162-
const char *key = "runtimes";
163-
if (luaxdp_runtimes == NULL &&
164-
(luaxdp_runtimes = luarcu_getobject(lunatik_env, key, sizeof(key))) == NULL)
165-
return -1;
166-
return 0;
167-
}
168-
169160
__bpf_kfunc int bpf_luaxdp_run(char *key, size_t key__sz, struct xdp_md *xdp_ctx, void *arg, size_t arg__sz)
170161
{
171-
lunatik_object_t *runtime;
172162
int action = -1;
173-
size_t keylen = key__sz - 1;
174163

175-
if (unlikely(luaxdp_checkruntimes() != 0)) {
176-
pr_err("couldn't find _ENV.runtimes\n");
164+
lunatik_object_t *runtime = lunatik_ebpf_lookup(luaxdp_runtimes, key, key__sz);
165+
if (runtime == NULL)
177166
goto out;
178-
}
179-
180-
key[keylen] = '\0';
181-
if ((runtime = luarcu_getobject(luaxdp_runtimes, key, keylen)) == NULL) {
182-
pr_err("couldn't find runtime '%s'\n", key);
183-
goto out;
184-
}
185167

186168
luaxdp_ctx_t ctx = {
187169
.xdp = (struct xdp_buff *)xdp_ctx,
@@ -272,7 +254,7 @@ static int luaxdp_detach(lua_State *L)
272254
* local function my_packet_processor(ctx)
273255
* local packet_buffer = ctx:packet()
274256
* print("Packet received, size:", #packet_buffer)
275-
* ctx:action(XDP_PASS)
257+
* ctx:action(action.PASS)
276258
* return nil
277259
* end
278260
* xdp.attach(my_packet_processor)

0 commit comments

Comments
 (0)