Skip to content

Commit fff0edf

Browse files
VictorNogueiraRiolneto
authored andcommitted
add LuaData submodule
1 parent 5bf1c3f commit fff0edf

7 files changed

Lines changed: 53 additions & 0 deletions

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "lib/lunatik"]
22
path = lib/lunatik
33
url = https://github.com/luainkernel/lunatik.git
4+
[submodule "lib/luadata"]
5+
path = lib/luadata
6+
url = https://github.com/luainkernel/luadata

include/uapi/linux/bpf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2826,6 +2826,8 @@ union bpf_attr {
28262826
FN(sk_storage_delete), \
28272827
FN(send_signal), \
28282828
/* #ifdef CONFIG_XDPLUA */ \
2829+
FN(lua_dataref), \
2830+
FN(lua_dataunref), \
28292831
FN(lua_pcall), \
28302832
FN(lua_pop), \
28312833
FN(lua_pushinteger), \

lib/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,5 +296,7 @@ obj-$(CONFIG_GENERIC_LIB_UCMPDI2) += ucmpdi2.o
296296
obj-$(CONFIG_OBJAGG) += objagg.o
297297

298298
subdir-ccflags-y += -I$(srctree)/lib/lunatik/lua \
299+
-I$(srctree)/lib/luadata/ \
299300
-D_KERNEL
300301
obj-$(CONFIG_LUNATIK) += lunatik/
302+
obj-$(CONFIG_LUADATA) += luadata/

lib/luadata

Submodule luadata added at 21137a0

net/core/filter.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5857,6 +5857,41 @@ static const struct bpf_func_proto bpf_tcp_check_syncookie_proto = {
58575857
#endif /* CONFIG_INET */
58585858

58595859
#ifdef CONFIG_XDPLUA
5860+
BPF_CALL_2(bpf_lua_dataref, struct xdp_buff *, ctx, int, offset) {
5861+
if (offset + ctx->data < ctx->data_end) {
5862+
int data_ref;
5863+
5864+
data_ref = ldata_newref(ctx->L, ctx->data + offset,
5865+
ctx->data_end - ctx->data - offset);
5866+
return data_ref;
5867+
}
5868+
5869+
return -1;
5870+
}
5871+
5872+
static const struct bpf_func_proto bpf_lua_dataref_proto = {
5873+
.func = bpf_lua_dataref,
5874+
.gpl_only = false,
5875+
.pkt_access = false,
5876+
.ret_type = RET_INTEGER,
5877+
.arg1_type = ARG_PTR_TO_CTX,
5878+
.arg1_type = ARG_ANYTHING,
5879+
};
5880+
5881+
BPF_CALL_2(bpf_lua_dataunref, struct xdp_buff *, ctx, int, data_ref) {
5882+
ldata_unref(ctx->L, data_ref);
5883+
return 0;
5884+
}
5885+
5886+
static const struct bpf_func_proto bpf_lua_dataunref_proto = {
5887+
.func = bpf_lua_dataunref,
5888+
.gpl_only = false,
5889+
.pkt_access = false,
5890+
.ret_type = RET_VOID,
5891+
.arg1_type = ARG_PTR_TO_CTX,
5892+
.arg2_type = ARG_ANYTHING,
5893+
};
5894+
58605895
BPF_CALL_4(bpf_lua_pcall, struct xdp_buff *, ctx, char *, funcname,
58615896
int, num_args, int, num_rets) {
58625897
if (lua_getglobal(ctx->L, funcname) != LUA_TFUNCTION) {
@@ -6106,6 +6141,10 @@ bpf_base_func_proto(enum bpf_func_id func_id)
61066141
case BPF_FUNC_trace_printk:
61076142
return bpf_get_trace_printk_proto();
61086143
#ifdef CONFIG_XDPLUA
6144+
case BPF_FUNC_lua_dataref:
6145+
return &bpf_lua_dataref_proto;
6146+
case BPF_FUNC_lua_dataunref:
6147+
return &bpf_lua_dataunref_proto;
61096148
case BPF_FUNC_lua_pcall:
61106149
return &bpf_lua_pcall_proto;
61116150
case BPF_FUNC_lua_pop:

tools/include/uapi/linux/bpf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2825,6 +2825,8 @@ union bpf_attr {
28252825
FN(sk_storage_get), \
28262826
FN(sk_storage_delete), \
28272827
/* #ifdef CONFIG_XDPLUA */ \
2828+
FN(lua_dataref), \
2829+
FN(lua_dataunref), \
28282830
FN(lua_pcall), \
28292831
FN(lua_pop), \
28302832
FN(lua_pushinteger), \

tools/testing/selftests/bpf/bpf_helpers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ static int (*bpf_sk_storage_delete)(void *map, struct bpf_sock *sk) =
230230
static int (*bpf_send_signal)(unsigned sig) = (void *)BPF_FUNC_send_signal;
231231

232232
/* #fidef CONFIG_XDPLUA */
233+
static int (*bpf_lua_dataref)(void *ctx, int offset) =
234+
(void *)BPF_FUNC_lua_dataref;
235+
static void (*bpf_lua_dataunref)(void *ctx, int data_ref) =
236+
(void *)BPF_FUNC_lua_dataunref;
233237
static void (*bpf_lua_pcall)(void *ctx, char *funcname, int num_args,
234238
int num_rets) =
235239
(void *) BPF_FUNC_lua_pcall;

0 commit comments

Comments
 (0)