Skip to content

Commit e20f358

Browse files
add LuaUnpack submodule
1 parent 5eb463c commit e20f358

7 files changed

Lines changed: 37 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
@@ -3100,7 +3100,8 @@ union bpf_attr {
31003100
FN(lua_pushskb), \
31013101
FN(lua_pushstring), \
31023102
FN(lua_toboolean), \
3103-
FN(lua_tointeger),
3103+
FN(lua_tointeger), \
3104+
FN(lua_newpacket),
31043105
/* #endif CONFIG_XDP_LUA */
31053106

31063107
/* 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
@@ -301,9 +301,10 @@ obj-$(CONFIG_OBJAGG) += objagg.o
301301
# KUnit tests
302302
obj-$(CONFIG_LIST_KUNIT_TEST) += list-test.o
303303
subdir-ccflags-y += -I$(srctree)/lib/lunatik/lua \
304-
-I$(srctree)/lib/luadata/ \
304+
-I$(srctree)/lib/luadata/ -I$(srctree)/lib/luaunpack/ \
305305
-D_KERNEL
306306
obj-$(CONFIG_LUNATIK) += lunatik/
307307
obj-$(CONFIG_LUADATA) += luadata/
308308
obj-$(CONFIG_LUAXDP) += luaxdp/
309309
obj-$(CONFIG_LUARCU) += luarcu/
310+
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 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: 21 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
/**
@@ -6073,6 +6074,24 @@ static const struct bpf_func_proto bpf_lua_tointeger_proto = {
60736074
.arg1_type = ARG_PTR_TO_CTX,
60746075
.arg2_type = ARG_ANYTHING,
60756076
};
6077+
6078+
BPF_CALL_2(bpf_lua_newpacket, struct xdp_buff *, ctx, int, offset) {
6079+
if (offset + ctx->data < ctx->data_end) {
6080+
return lunpack_newpacket(ctx->L, ctx->data + offset,
6081+
ctx->data_end - ctx->data - offset);
6082+
}
6083+
6084+
return -EINVAL;
6085+
}
6086+
6087+
static const struct bpf_func_proto bpf_lua_newpacket_proto = {
6088+
.func = bpf_lua_newpacket,
6089+
.gpl_only = false,
6090+
.pkt_access = false,
6091+
.ret_type = RET_INTEGER,
6092+
.arg1_type = ARG_PTR_TO_CTX,
6093+
.arg2_type = ARG_ANYTHING,
6094+
};
60766095
#endif /* CONFIG_XDP_LUA */
60776096

60786097
bool bpf_helper_changes_pkt_data(void *func)
@@ -6176,6 +6195,8 @@ bpf_base_func_proto(enum bpf_func_id func_id)
61766195
return &bpf_lua_toboolean_proto;
61776196
case BPF_FUNC_lua_tointeger:
61786197
return &bpf_lua_tointeger_proto;
6198+
case BPF_FUNC_lua_newpacket:
6199+
return &bpf_lua_newpacket_proto;
61796200
#endif /* CONFIG_XDP_LUA */
61806201
default:
61816202
return NULL;

tools/include/uapi/linux/bpf.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2967,6 +2967,11 @@ union bpf_attr {
29672967
* The converted Lua value at the given index, if the value is
29682968
* convertible to an integer(see the Lua manual for more details
29692969
* on type conversion); otherwise returns 0
2970+
*
2971+
* void bpf_lua_newpacket(void *ctx, int offset)
2972+
* Description
2973+
* Create new luaunpack user data buffer pointing to
2974+
* the captured packet at the specified offset
29702975
*/
29712976
#define __BPF_FUNC_MAPPER(FN) \
29722977
FN(unspec), \
@@ -3100,7 +3105,8 @@ union bpf_attr {
31003105
FN(lua_pushskb), \
31013106
FN(lua_pushstring), \
31023107
FN(lua_toboolean), \
3103-
FN(lua_tointeger),
3108+
FN(lua_tointeger), \
3109+
FN(lua_newpacket),
31043110
/* #endif CONFIG_XDP_LUA */
31053111

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

0 commit comments

Comments
 (0)