Skip to content

Commit 2e642c8

Browse files
add LuaData submodule
1 parent 459ecee commit 2e642c8

File tree

9 files changed

+58
-2
lines changed

9 files changed

+58
-2
lines changed

.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
@@ -2230,6 +2230,8 @@ union bpf_attr {
22302230
FN(sk_select_reuseport), \
22312231
FN(skb_ancestor_cgroup_id), \
22322232
/* #ifdef CONFIG_XDP_LUA */ \
2233+
FN(lua_dataref), \
2234+
FN(lua_dataunref), \
22332235
FN(lua_pcall), \
22342236
FN(lua_pop), \
22352237
FN(lua_pushinteger), \

lib/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,5 +285,7 @@ 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/ \
288289
-D_KERNEL
289290
obj-$(CONFIG_LUNATIK) += lunatik/
291+
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
@@ -4797,6 +4797,41 @@ static const struct bpf_func_proto bpf_lwt_seg6_adjust_srh_proto = {
47974797
#endif /* CONFIG_IPV6_SEG6_BPF */
47984798

47994799
#ifdef CONFIG_XDP_LUA
4800+
BPF_CALL_2(bpf_lua_dataref, struct xdp_buff *, ctx, int, offset) {
4801+
if (offset + ctx->data < ctx->data_end) {
4802+
int data_ref;
4803+
4804+
data_ref = ldata_newref(ctx->L, ctx->data + offset,
4805+
ctx->data_end - ctx->data - offset);
4806+
return data_ref;
4807+
}
4808+
4809+
return -1;
4810+
}
4811+
4812+
static const struct bpf_func_proto bpf_lua_dataref_proto = {
4813+
.func = bpf_lua_dataref,
4814+
.gpl_only = false,
4815+
.pkt_access = false,
4816+
.ret_type = RET_INTEGER,
4817+
.arg1_type = ARG_PTR_TO_CTX,
4818+
.arg1_type = ARG_ANYTHING,
4819+
};
4820+
4821+
BPF_CALL_2(bpf_lua_dataunref, struct xdp_buff *, ctx, int, data_ref) {
4822+
ldata_unref(ctx->L, data_ref);
4823+
return 0;
4824+
}
4825+
4826+
static const struct bpf_func_proto bpf_lua_dataunref_proto = {
4827+
.func = bpf_lua_dataunref,
4828+
.gpl_only = false,
4829+
.pkt_access = false,
4830+
.ret_type = RET_VOID,
4831+
.arg1_type = ARG_PTR_TO_CTX,
4832+
.arg2_type = ARG_ANYTHING,
4833+
};
4834+
48004835
BPF_CALL_4(bpf_lua_pcall, struct xdp_buff *, ctx, char *, funcname,
48014836
int, num_args, int, num_rets) {
48024837
if (lua_getglobal(ctx->L, funcname) != LUA_TFUNCTION) {
@@ -5027,6 +5062,10 @@ bpf_base_func_proto(enum bpf_func_id func_id)
50275062
return bpf_get_trace_printk_proto();
50285063
/* else: fall through */
50295064
#ifdef CONFIG_XDP_LUA
5065+
case BPF_FUNC_lua_dataref:
5066+
return &bpf_lua_dataref_proto;
5067+
case BPF_FUNC_lua_dataunref:
5068+
return &bpf_lua_dataunref_proto;
50305069
case BPF_FUNC_lua_pcall:
50315070
return &bpf_lua_pcall_proto;
50325071
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)