Skip to content

Commit 497fd52

Browse files
add LuaUnpack submodule
1 parent aa6b663 commit 497fd52

8 files changed

Lines changed: 33 additions & 4 deletions

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@
1010
[submodule "lib/luarcu"]
1111
path = lib/luarcu
1212
url = https://github.com/luainkernel/luarcu
13+
[submodule "lib/luaunpack"]
14+
path = lib/luaunpack
15+
url = https://github.com/VictorNogueiraRio/luaunpack.git

include/uapi/linux/bpf.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2839,7 +2839,8 @@ union bpf_attr {
28392839
FN(lua_toboolean), \
28402840
FN(lua_tointeger), \
28412841
FN(lua_putstate), \
2842-
FN(lua_removestate),
2842+
FN(lua_removestate), \
2843+
FN(lua_newpacket),
28432844
/* #endif CONFIG_XDP_LUA */
28442845

28452846
/* integer value in 'imm' field of BPF_CALL instruction selects which helper

lib/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,10 @@ 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/ \
299+
-I$(srctree)/lib/luadata/ -I$(srctree)/lib/luaunpack/ \
300300
-D_KERNEL
301301
obj-$(CONFIG_LUNATIK) += lunatik/
302302
obj-$(CONFIG_LUADATA) += luadata/
303303
obj-$(CONFIG_LUAXDP) += luaxdp/
304304
obj-$(CONFIG_LUARCU) += luarcu/
305+
obj-$(CONFIG_LUAUNPACK) += luaunpack/

lib/luaunpack

Submodule luaunpack added at 0589fc2

net/core/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ obj-$(CONFIG_SYSCTL) += sysctl_net_core.o
1111
CFLAGS_dev.o = -Ilib/lunatik/lua/ -D_KERNEL \
1212
-Ilib/luadata/
1313
CFLAGS_filter.o = -Ilib/lunatik/lua/ -D_KERNEL \
14-
-Ilib/luadata/
14+
-Ilib/luadata/ -Ilib/luaunpack/
1515
obj-y += dev.o ethtool.o dev_addr_lists.o dst.o netevent.o \
1616
neighbour.o rtnetlink.o utils.o link_watch.o filter.o \
1717
sock_diag.o dev_ioctl.o tso.o sock_reuseport.o \

net/core/filter.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
#ifdef CONFIG_XDP_LUA
7878
#include <lua.h>
7979
#include <luadata.h>
80+
#include <luaunpack.h>
8081
#endif /* CONFIG_XDP_LUA */
8182

8283
/**
@@ -6072,6 +6073,23 @@ static const struct bpf_func_proto bpf_lua_removestate_proto = {
60726073
.ret_type = RET_VOID,
60736074
.arg1_type = ARG_PTR_TO_CTX,
60746075
};
6076+
BPF_CALL_2(bpf_lua_newpacket, struct xdp_buff *, ctx, int, offset) {
6077+
if (offset + ctx->data < ctx->data_end) {
6078+
return lunpack_newpacket(ctx->xdplua->L, ctx->data + offset,
6079+
ctx->data_end - ctx->data - offset);
6080+
}
6081+
6082+
return -EINVAL;
6083+
}
6084+
6085+
static const struct bpf_func_proto bpf_lua_newpacket_proto = {
6086+
.func = bpf_lua_newpacket,
6087+
.gpl_only = false,
6088+
.pkt_access = false,
6089+
.ret_type = RET_INTEGER,
6090+
.arg1_type = ARG_PTR_TO_CTX,
6091+
.arg2_type = ARG_ANYTHING,
6092+
};
60756093
#endif /* CONFIG_XDP_LUA */
60766094

60776095
bool bpf_helper_changes_pkt_data(void *func)
@@ -6177,6 +6195,8 @@ bpf_base_func_proto(enum bpf_func_id func_id)
61776195
return &bpf_lua_putstate_proto;
61786196
case BPF_FUNC_lua_removestate:
61796197
return &bpf_lua_removestate_proto;
6198+
case BPF_FUNC_lua_newpacket:
6199+
return &bpf_lua_newpacket_proto;
61806200
#endif /* CONFIG_XDP_LUA */
61816201
default:
61826202
return NULL;

tools/include/uapi/linux/bpf.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2839,7 +2839,8 @@ union bpf_attr {
28392839
FN(lua_toboolean), \
28402840
FN(lua_tointeger), \
28412841
FN(lua_putstate), \
2842-
FN(lua_removestate),
2842+
FN(lua_removestate), \
2843+
FN(lua_newpacket),
28432844
/* #endif CONFIG_XDPLUA */
28442845

28452846
/* integer value in 'imm' field of BPF_CALL instruction selects which helper

tools/testing/selftests/bpf/bpf_helpers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ static void (*bpf_lua_putstate)(void *ctx) =
260260
(void *)BPF_FUNC_lua_putstate;
261261
static void (*bpf_lua_removestate)(void *ctx) =
262262
(void *)BPF_FUNC_lua_removestate;
263+
static int (*bpf_lua_newpacket)(void *ctx, int offset) =
264+
(void *)BPF_FUNC_lua_newpacket;
263265
/* #endif CONFIG_XDPLUA */
264266

265267
/* llvm builtin functions that eBPF C program may use to

0 commit comments

Comments
 (0)