Skip to content

Commit 48884fc

Browse files
add LuaUnpack submodule
1 parent fc3fe38 commit 48884fc

8 files changed

Lines changed: 34 additions & 5 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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,8 +2240,7 @@ union bpf_attr {
22402240
FN(lua_pushstring), \
22412241
FN(lua_toboolean), \
22422242
FN(lua_tointeger), \
2243-
FN(lua_newpacket), \
2244-
FN(lua_type),
2243+
FN(lua_newpacket),
22452244
/* #endif CONFIG_XDP_LUA */
22462245

22472246
/* 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
@@ -272,9 +272,10 @@ obj-$(CONFIG_GENERIC_LIB_CMPDI2) += cmpdi2.o
272272
obj-$(CONFIG_GENERIC_LIB_UCMPDI2) += ucmpdi2.o
273273

274274
subdir-ccflags-y += -I$(srctree)/lib/lunatik/lua \
275-
-I$(srctree)/lib/luadata/ \
275+
-I$(srctree)/lib/luadata/ -I$(srctree)/lib/luaunpack/ \
276276
-D_KERNEL
277277
obj-$(CONFIG_LUNATIK) += lunatik/
278278
obj-$(CONFIG_LUADATA) += luadata/
279279
obj-$(CONFIG_LUAXDP) += luaxdp/
280280
obj-$(CONFIG_LUARCU) += luarcu/
281+
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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171

7272
#ifdef CONFIG_XDP_LUA
7373
#include <lua.h>
74+
#include <luadata.h>
75+
#include <luaunpack.h>
7476
#endif /* CONFIG_XDP_LUA */
7577

7678
/**
@@ -5008,6 +5010,24 @@ static const struct bpf_func_proto bpf_lua_tointeger_proto = {
50085010
.arg1_type = ARG_PTR_TO_CTX,
50095011
.arg2_type = ARG_ANYTHING,
50105012
};
5013+
5014+
BPF_CALL_2(bpf_lua_newpacket, struct xdp_buff *, ctx, int, offset) {
5015+
if (offset + ctx->data < ctx->data_end) {
5016+
return lunpack_newpacket(ctx->L, ctx->data + offset,
5017+
ctx->data_end - ctx->data - offset);
5018+
}
5019+
5020+
return -EINVAL;
5021+
}
5022+
5023+
static const struct bpf_func_proto bpf_lua_newpacket_proto = {
5024+
.func = bpf_lua_newpacket,
5025+
.gpl_only = false,
5026+
.pkt_access = false,
5027+
.ret_type = RET_INTEGER,
5028+
.arg1_type = ARG_PTR_TO_CTX,
5029+
.arg2_type = ARG_ANYTHING,
5030+
};
50115031
#endif /* CONFIG_XDP_LUA */
50125032

50135033
bool bpf_helper_changes_pkt_data(void *func)
@@ -5090,6 +5110,8 @@ bpf_base_func_proto(enum bpf_func_id func_id)
50905110
return &bpf_lua_toboolean_proto;
50915111
case BPF_FUNC_lua_tointeger:
50925112
return &bpf_lua_tointeger_proto;
5113+
case BPF_FUNC_lua_newpacket:
5114+
return &bpf_lua_newpacket_proto;
50935115
#endif /* CONFIG_XDP_LUA */
50945116
default:
50955117
return NULL;

tools/include/uapi/linux/bpf.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2239,7 +2239,8 @@ union bpf_attr {
22392239
FN(lua_pushskb), \
22402240
FN(lua_pushstring), \
22412241
FN(lua_toboolean), \
2242-
FN(lua_tointeger),
2242+
FN(lua_tointeger), \
2243+
FN(lua_newpacket),
22432244
/* #endif CONFIG_XDP_LUA */
22442245

22452246
/* 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
@@ -171,6 +171,8 @@ static int (*bpf_lua_toboolean)(void *ctx, int index) =
171171
(void *)BPF_FUNC_lua_toboolean;
172172
static int (*bpf_lua_tointeger)(void *ctx, int index) =
173173
(void *)BPF_FUNC_lua_tointeger;
174+
static int (*bpf_lua_newpacket)(void *ctx, int offset) =
175+
(void *)BPF_FUNC_lua_newpacket;
174176
/* #endif CONFIG_XDP_LUA */
175177

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

0 commit comments

Comments
 (0)