Skip to content

Commit 06ca994

Browse files
Add bpf_lua_type function
1 parent b44a69f commit 06ca994

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

include/uapi/linux/bpf.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2243,7 +2243,8 @@ union bpf_attr {
22432243
FN(lua_pushstring), \
22442244
FN(lua_toboolean), \
22452245
FN(lua_tointeger), \
2246-
FN(lua_newpacket),
2246+
FN(lua_newpacket), \
2247+
FN(lua_type),
22472248
/* #endif CONFIG_XDP_LUA */
22482249

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

net/core/filter.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5053,6 +5053,19 @@ static const struct bpf_func_proto bpf_lua_newpacket_proto = {
50535053
.arg1_type = ARG_PTR_TO_CTX,
50545054
.arg2_type = ARG_ANYTHING,
50555055
};
5056+
5057+
BPF_CALL_2(bpf_lua_type, struct xdp_buff *, ctx, int, index) {
5058+
return lua_type(ctx->L, index);
5059+
}
5060+
5061+
static const struct bpf_func_proto bpf_lua_type_proto = {
5062+
.func = bpf_lua_type,
5063+
.gpl_only = false,
5064+
.pkt_access = false,
5065+
.ret_type = RET_INTEGER,
5066+
.arg1_type = ARG_PTR_TO_CTX,
5067+
.arg2_type = ARG_ANYTHING,
5068+
};
50565069
#endif /* CONFIG_XDP_LUA */
50575070

50585071
bool bpf_helper_changes_pkt_data(void *func)
@@ -5139,6 +5152,8 @@ bpf_base_func_proto(enum bpf_func_id func_id)
51395152
return &bpf_lua_tointeger_proto;
51405153
case BPF_FUNC_lua_newpacket:
51415154
return &bpf_lua_newpacket_proto;
5155+
case BPF_FUNC_lua_type:
5156+
return &bpf_lua_type_proto;
51425157
#endif /* CONFIG_XDP_LUA */
51435158
default:
51445159
return NULL;

tools/include/uapi/linux/bpf.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2241,7 +2241,8 @@ union bpf_attr {
22412241
FN(lua_pushstring), \
22422242
FN(lua_toboolean), \
22432243
FN(lua_tointeger), \
2244-
FN(lua_newpacket),
2244+
FN(lua_newpacket), \
2245+
FN(lua_type),
22452246
/* #endif CONFIG_XDP_LUA */
22462247

22472248
/* 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
@@ -175,6 +175,8 @@ static int (*bpf_lua_tointeger)(void *ctx, int index) =
175175
(void *)BPF_FUNC_lua_tointeger;
176176
static int (*bpf_lua_newpacket)(void *ctx, int offset) =
177177
(void *)BPF_FUNC_lua_newpacket;
178+
static int (*bpf_lua_type)(void *ctx, int index) =
179+
(void *)BPF_FUNC_lua_type;
178180
/* #endif CONFIG_XDP_LUA */
179181

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

0 commit comments

Comments
 (0)