Skip to content

Commit 287cdfd

Browse files
add LuaData submodule
1 parent 8d652aa commit 287cdfd

9 files changed

Lines changed: 58 additions & 2 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
@@ -2228,6 +2228,8 @@ union bpf_attr {
22282228
FN(sk_select_reuseport), \
22292229
FN(skb_ancestor_cgroup_id), \
22302230
/* #ifdef CONFIG_XDP_LUA */ \
2231+
FN(lua_dataref), \
2232+
FN(lua_dataunref), \
22312233
FN(lua_pcall), \
22322234
FN(lua_pop), \
22332235
FN(lua_pushinteger), \

lib/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,5 +272,7 @@ 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/ \
275276
-D_KERNEL
276277
obj-$(CONFIG_LUNATIK) += lunatik/
278+
obj-$(CONFIG_LUADATA) += luadata/

lib/luadata

Submodule luadata added at 21137a0

net/core/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ obj-y := sock.o request_sock.o skbuff.o datagram.o stream.o scm.o \
88

99
obj-$(CONFIG_SYSCTL) += sysctl_net_core.o
1010

11-
CFLAGS_dev.o = -Ilib/lunatik/lua/ -D_KERNEL
12-
CFLAGS_filter.o = -Ilib/lunatik/lua/ -D_KERNEL
11+
CFLAGS_dev.o = -Ilib/lunatik/lua/ -D_KERNEL \
12+
-Ilib/luadata/
13+
CFLAGS_filter.o = -Ilib/lunatik/lua/ -D_KERNEL \
14+
-Ilib/luadata/
1315
obj-y += dev.o ethtool.o dev_addr_lists.o dst.o netevent.o \
1416
neighbour.o rtnetlink.o utils.o link_watch.o filter.o \
1517
sock_diag.o dev_ioctl.o tso.o sock_reuseport.o \

net/core/dev.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
#include <lua.h>
7777
#include <lauxlib.h>
7878
#include <lualib.h>
79+
#include <luadata.h>
7980
#endif /* CONFIG_XDP_LUA */
8081

8182
#include <linux/uaccess.h>

net/core/filter.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4792,6 +4792,41 @@ static const struct bpf_func_proto bpf_lwt_seg6_adjust_srh_proto = {
47924792
#endif /* CONFIG_IPV6_SEG6_BPF */
47934793

47944794
#ifdef CONFIG_XDP_LUA
4795+
BPF_CALL_2(bpf_lua_dataref, struct xdp_buff *, ctx, int, offset) {
4796+
if (offset + ctx->data < ctx->data_end) {
4797+
int data_ref;
4798+
4799+
data_ref = ldata_newref(ctx->L, ctx->data + offset,
4800+
ctx->data_end - ctx->data - offset);
4801+
return data_ref;
4802+
}
4803+
4804+
return -1;
4805+
}
4806+
4807+
static const struct bpf_func_proto bpf_lua_dataref_proto = {
4808+
.func = bpf_lua_dataref,
4809+
.gpl_only = false,
4810+
.pkt_access = false,
4811+
.ret_type = RET_INTEGER,
4812+
.arg1_type = ARG_PTR_TO_CTX,
4813+
.arg1_type = ARG_ANYTHING,
4814+
};
4815+
4816+
BPF_CALL_2(bpf_lua_dataunref, struct xdp_buff *, ctx, int, data_ref) {
4817+
ldata_unref(ctx->L, data_ref);
4818+
return 0;
4819+
}
4820+
4821+
static const struct bpf_func_proto bpf_lua_dataunref_proto = {
4822+
.func = bpf_lua_dataunref,
4823+
.gpl_only = false,
4824+
.pkt_access = false,
4825+
.ret_type = RET_VOID,
4826+
.arg1_type = ARG_PTR_TO_CTX,
4827+
.arg2_type = ARG_ANYTHING,
4828+
};
4829+
47954830
BPF_CALL_4(bpf_lua_pcall, struct xdp_buff *, ctx, char *, funcname,
47964831
int, num_args, int, num_rets) {
47974832
if (lua_getglobal(ctx->L, funcname) != LUA_TFUNCTION) {
@@ -5022,6 +5057,10 @@ bpf_base_func_proto(enum bpf_func_id func_id)
50225057
return bpf_get_trace_printk_proto();
50235058
/* else: fall through */
50245059
#ifdef CONFIG_XDP_LUA
5060+
case BPF_FUNC_lua_dataref:
5061+
return &bpf_lua_dataref_proto;
5062+
case BPF_FUNC_lua_dataunref:
5063+
return &bpf_lua_dataunref_proto;
50255064
case BPF_FUNC_lua_pcall:
50265065
return &bpf_lua_pcall_proto;
50275066
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
@@ -2228,6 +2228,8 @@ union bpf_attr {
22282228
FN(sk_select_reuseport), \
22292229
FN(skb_ancestor_cgroup_id), \
22302230
/* #ifdef CONFIG_XDP_LUA */ \
2231+
FN(lua_dataref), \
2232+
FN(lua_dataunref), \
22312233
FN(lua_pcall), \
22322234
FN(lua_pop), \
22332235
FN(lua_pushinteger), \

tools/testing/selftests/bpf/bpf_helpers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ static unsigned long long (*bpf_skb_ancestor_cgroup_id)(void *ctx, int level) =
145145
(void *) BPF_FUNC_skb_ancestor_cgroup_id;
146146

147147
/* #ifdef CONFIG_XDP_LUA */
148+
static int (*bpf_lua_dataref)(void *ctx, int offset) =
149+
(void *)BPF_FUNC_lua_dataref;
150+
static void (*bpf_lua_dataunref)(void *ctx, int data_ref) =
151+
(void *)BPF_FUNC_lua_dataunref;
148152
static int (*bpf_lua_pcall)(void *ctx, char *funcname, int num_args,
149153
int num_rets) =
150154
(void *) BPF_FUNC_lua_pcall;

0 commit comments

Comments
 (0)