Skip to content

Commit 08fd5c8

Browse files
add LuaUnpack submodule
1 parent d8e92c3 commit 08fd5c8

File tree

8 files changed

+34
-5
lines changed

8 files changed

+34
-5
lines changed

.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
@@ -2242,8 +2242,7 @@ union bpf_attr {
22422242
FN(lua_pushstring), \
22432243
FN(lua_toboolean), \
22442244
FN(lua_tointeger), \
2245-
FN(lua_newpacket), \
2246-
FN(lua_type),
2245+
FN(lua_newpacket),
22472246
/* #endif CONFIG_XDP_LUA */
22482247

22492248
/* 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
@@ -285,9 +285,10 @@ obj-$(CONFIG_GENERIC_LIB_CMPDI2) += cmpdi2.o
285285
obj-$(CONFIG_GENERIC_LIB_UCMPDI2) += ucmpdi2.o
286286

287287
subdir-ccflags-y += -I$(srctree)/lib/lunatik/lua \
288-
-I$(srctree)/lib/luadata/ \
288+
-I$(srctree)/lib/luadata/ -I$(srctree)/lib/luaunpack/ \
289289
-D_KERNEL
290290
obj-$(CONFIG_LUNATIK) += lunatik/
291291
obj-$(CONFIG_LUADATA) += luadata/
292292
obj-$(CONFIG_LUAXDP) += luaxdp/
293293
obj-$(CONFIG_LUARCU) += luarcu/
294+
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
/**
@@ -5013,6 +5015,24 @@ static const struct bpf_func_proto bpf_lua_tointeger_proto = {
50135015
.arg1_type = ARG_PTR_TO_CTX,
50145016
.arg2_type = ARG_ANYTHING,
50155017
};
5018+
5019+
BPF_CALL_2(bpf_lua_newpacket, struct xdp_buff *, ctx, int, offset) {
5020+
if (offset + ctx->data < ctx->data_end) {
5021+
return lunpack_newpacket(ctx->L, ctx->data + offset,
5022+
ctx->data_end - ctx->data - offset);
5023+
}
5024+
5025+
return -EINVAL;
5026+
}
5027+
5028+
static const struct bpf_func_proto bpf_lua_newpacket_proto = {
5029+
.func = bpf_lua_newpacket,
5030+
.gpl_only = false,
5031+
.pkt_access = false,
5032+
.ret_type = RET_INTEGER,
5033+
.arg1_type = ARG_PTR_TO_CTX,
5034+
.arg2_type = ARG_ANYTHING,
5035+
};
50165036
#endif /* CONFIG_XDP_LUA */
50175037

50185038
bool bpf_helper_changes_pkt_data(void *func)
@@ -5095,6 +5115,8 @@ bpf_base_func_proto(enum bpf_func_id func_id)
50955115
return &bpf_lua_toboolean_proto;
50965116
case BPF_FUNC_lua_tointeger:
50975117
return &bpf_lua_tointeger_proto;
5118+
case BPF_FUNC_lua_newpacket:
5119+
return &bpf_lua_newpacket_proto;
50985120
#endif /* CONFIG_XDP_LUA */
50995121
default:
51005122
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)