Skip to content

Commit 904bb0e

Browse files
Add bpf_lua_type function
1 parent 42219e1 commit 904bb0e

4 files changed

Lines changed: 22 additions & 2 deletions

File tree

include/uapi/linux/bpf.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2841,7 +2841,8 @@ union bpf_attr {
28412841
FN(lua_tointeger), \
28422842
FN(lua_putstate), \
28432843
FN(lua_removestate), \
2844-
FN(lua_newpacket),
2844+
FN(lua_newpacket), \
2845+
FN(lua_type),
28452846
/* #endif CONFIG_XDP_LUA */
28462847

28472848
/* integer value in 'imm' field of BPF_CALL instruction selects which helper

net/core/filter.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6093,6 +6093,7 @@ static const struct bpf_func_proto bpf_lua_removestate_proto = {
60936093
.ret_type = RET_VOID,
60946094
.arg1_type = ARG_PTR_TO_CTX,
60956095
};
6096+
60966097
BPF_CALL_2(bpf_lua_newpacket, struct xdp_buff *, ctx, int, offset) {
60976098
if (offset + ctx->data < ctx->data_end) {
60986099
return lunpack_newpacket(ctx->xdplua->L, ctx->data + offset,
@@ -6110,6 +6111,19 @@ static const struct bpf_func_proto bpf_lua_newpacket_proto = {
61106111
.arg1_type = ARG_PTR_TO_CTX,
61116112
.arg2_type = ARG_ANYTHING,
61126113
};
6114+
6115+
BPF_CALL_2(bpf_lua_type, struct xdp_buff *, ctx, int, index) {
6116+
return lua_type(ctx->xdplua->L, index);
6117+
}
6118+
6119+
static const struct bpf_func_proto bpf_lua_type_proto = {
6120+
.func = bpf_lua_type,
6121+
.gpl_only = false,
6122+
.pkt_access = false,
6123+
.ret_type = RET_INTEGER,
6124+
.arg1_type = ARG_PTR_TO_CTX,
6125+
.arg2_type = ARG_ANYTHING,
6126+
};
61136127
#endif /* CONFIG_XDP_LUA */
61146128

61156129
bool bpf_helper_changes_pkt_data(void *func)
@@ -6219,6 +6233,8 @@ bpf_base_func_proto(enum bpf_func_id func_id)
62196233
return &bpf_lua_removestate_proto;
62206234
case BPF_FUNC_lua_newpacket:
62216235
return &bpf_lua_newpacket_proto;
6236+
case BPF_FUNC_lua_type:
6237+
return &bpf_lua_type_proto;
62226238
#endif /* CONFIG_XDP_LUA */
62236239
default:
62246240
return NULL;

tools/include/uapi/linux/bpf.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2841,7 +2841,8 @@ union bpf_attr {
28412841
FN(lua_tointeger), \
28422842
FN(lua_putstate), \
28432843
FN(lua_removestate), \
2844-
FN(lua_newpacket),
2844+
FN(lua_newpacket), \
2845+
FN(lua_type),
28452846
/* #endif CONFIG_XDPLUA */
28462847

28472848
/* 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
@@ -264,6 +264,8 @@ static void (*bpf_lua_removestate)(void *ctx) =
264264
(void *)BPF_FUNC_lua_removestate;
265265
static int (*bpf_lua_newpacket)(void *ctx, int offset) =
266266
(void *)BPF_FUNC_lua_newpacket;
267+
static int (*bpf_lua_type)(void *ctx, int index) =
268+
(void *)BPF_FUNC_lua_type;
267269
/* #endif CONFIG_XDPLUA */
268270

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

0 commit comments

Comments
 (0)