Skip to content

Commit e462d21

Browse files
Add bpf_lua_type function
1 parent fe1927c commit e462d21

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
@@ -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

net/core/filter.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5048,6 +5048,19 @@ static const struct bpf_func_proto bpf_lua_newpacket_proto = {
50485048
.arg1_type = ARG_PTR_TO_CTX,
50495049
.arg2_type = ARG_ANYTHING,
50505050
};
5051+
5052+
BPF_CALL_2(bpf_lua_type, struct xdp_buff *, ctx, int, index) {
5053+
return lua_type(ctx->L, index);
5054+
}
5055+
5056+
static const struct bpf_func_proto bpf_lua_type_proto = {
5057+
.func = bpf_lua_type,
5058+
.gpl_only = false,
5059+
.pkt_access = false,
5060+
.ret_type = RET_INTEGER,
5061+
.arg1_type = ARG_PTR_TO_CTX,
5062+
.arg2_type = ARG_ANYTHING,
5063+
};
50515064
#endif /* CONFIG_XDP_LUA */
50525065

50535066
bool bpf_helper_changes_pkt_data(void *func)
@@ -5134,6 +5147,8 @@ bpf_base_func_proto(enum bpf_func_id func_id)
51345147
return &bpf_lua_tointeger_proto;
51355148
case BPF_FUNC_lua_newpacket:
51365149
return &bpf_lua_newpacket_proto;
5150+
case BPF_FUNC_lua_type:
5151+
return &bpf_lua_type_proto;
51375152
#endif /* CONFIG_XDP_LUA */
51385153
default:
51395154
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)