Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add LuaUnpack submodule
  • Loading branch information
VictorNogueiraRio committed Feb 20, 2020
commit 497fd52846a0bd5b4432db685756a43bd470ab6a
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
[submodule "lib/luarcu"]
path = lib/luarcu
url = https://github.com/luainkernel/luarcu
[submodule "lib/luaunpack"]
path = lib/luaunpack
url = https://github.com/VictorNogueiraRio/luaunpack.git
3 changes: 2 additions & 1 deletion include/uapi/linux/bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -2839,7 +2839,8 @@ union bpf_attr {
FN(lua_toboolean), \
FN(lua_tointeger), \
FN(lua_putstate), \
FN(lua_removestate),
FN(lua_removestate), \
FN(lua_newpacket),
/* #endif CONFIG_XDP_LUA */

/* integer value in 'imm' field of BPF_CALL instruction selects which helper
Expand Down
3 changes: 2 additions & 1 deletion lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,10 @@ obj-$(CONFIG_GENERIC_LIB_UCMPDI2) += ucmpdi2.o
obj-$(CONFIG_OBJAGG) += objagg.o

subdir-ccflags-y += -I$(srctree)/lib/lunatik/lua \
-I$(srctree)/lib/luadata/ \
-I$(srctree)/lib/luadata/ -I$(srctree)/lib/luaunpack/ \
-D_KERNEL
obj-$(CONFIG_LUNATIK) += lunatik/
obj-$(CONFIG_LUADATA) += luadata/
obj-$(CONFIG_LUAXDP) += luaxdp/
obj-$(CONFIG_LUARCU) += luarcu/
obj-$(CONFIG_LUAUNPACK) += luaunpack/
1 change: 1 addition & 0 deletions lib/luaunpack
Submodule luaunpack added at 0589fc
2 changes: 1 addition & 1 deletion net/core/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ obj-$(CONFIG_SYSCTL) += sysctl_net_core.o
CFLAGS_dev.o = -Ilib/lunatik/lua/ -D_KERNEL \
-Ilib/luadata/
CFLAGS_filter.o = -Ilib/lunatik/lua/ -D_KERNEL \
-Ilib/luadata/
-Ilib/luadata/ -Ilib/luaunpack/
obj-y += dev.o ethtool.o dev_addr_lists.o dst.o netevent.o \
neighbour.o rtnetlink.o utils.o link_watch.o filter.o \
sock_diag.o dev_ioctl.o tso.o sock_reuseport.o \
Expand Down
20 changes: 20 additions & 0 deletions net/core/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
#ifdef CONFIG_XDP_LUA
#include <lua.h>
#include <luadata.h>
#include <luaunpack.h>
#endif /* CONFIG_XDP_LUA */

/**
Expand Down Expand Up @@ -6072,6 +6073,23 @@ static const struct bpf_func_proto bpf_lua_removestate_proto = {
.ret_type = RET_VOID,
.arg1_type = ARG_PTR_TO_CTX,
};
BPF_CALL_2(bpf_lua_newpacket, struct xdp_buff *, ctx, int, offset) {
if (offset + ctx->data < ctx->data_end) {
return lunpack_newpacket(ctx->xdplua->L, ctx->data + offset,
ctx->data_end - ctx->data - offset);
}

return -EINVAL;
}

static const struct bpf_func_proto bpf_lua_newpacket_proto = {
.func = bpf_lua_newpacket,
.gpl_only = false,
.pkt_access = false,
.ret_type = RET_INTEGER,
.arg1_type = ARG_PTR_TO_CTX,
.arg2_type = ARG_ANYTHING,
};
#endif /* CONFIG_XDP_LUA */

bool bpf_helper_changes_pkt_data(void *func)
Expand Down Expand Up @@ -6177,6 +6195,8 @@ bpf_base_func_proto(enum bpf_func_id func_id)
return &bpf_lua_putstate_proto;
case BPF_FUNC_lua_removestate:
return &bpf_lua_removestate_proto;
case BPF_FUNC_lua_newpacket:
return &bpf_lua_newpacket_proto;
#endif /* CONFIG_XDP_LUA */
default:
return NULL;
Expand Down
3 changes: 2 additions & 1 deletion tools/include/uapi/linux/bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -2839,7 +2839,8 @@ union bpf_attr {
FN(lua_toboolean), \
FN(lua_tointeger), \
FN(lua_putstate), \
FN(lua_removestate),
FN(lua_removestate), \
FN(lua_newpacket),
/* #endif CONFIG_XDPLUA */

/* integer value in 'imm' field of BPF_CALL instruction selects which helper
Expand Down
2 changes: 2 additions & 0 deletions tools/testing/selftests/bpf/bpf_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ static void (*bpf_lua_putstate)(void *ctx) =
(void *)BPF_FUNC_lua_putstate;
static void (*bpf_lua_removestate)(void *ctx) =
(void *)BPF_FUNC_lua_removestate;
static int (*bpf_lua_newpacket)(void *ctx, int offset) =
(void *)BPF_FUNC_lua_newpacket;
/* #endif CONFIG_XDPLUA */

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