Skip to content

Commit 040b06b

Browse files
Add bpf_lua_type function
1 parent 36ceb19 commit 040b06b

3 files changed

Lines changed: 47 additions & 2 deletions

File tree

include/uapi/linux/bpf.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2976,6 +2976,20 @@ union bpf_attr {
29762976
* Return
29772977
* 1 if the value at the given index of the Lua stack is a
29782978
* string; otherwise it returns 0
2979+
*
2980+
* void bpf_lua_type(void *ctx, int index)
2981+
* Description
2982+
* Obtains the type of the Lua value at the given index
2983+
* of the Lua stack
2984+
*
2985+
* Return
2986+
* Type of the value in the given valid index,
2987+
* or LUA_TNONE for a non-valid (but acceptable) index.
2988+
* The types returned by lua_type are coded by the
2989+
* following constants defined in lua.h: LUA_TNIL (0),
2990+
* LUA_TNUMBER, LUA_TBOOLEAN, LUA_TSTRING, LUA_TTABLE,
2991+
* LUA_TFUNCTION, LUA_TUSERDATA, LUA_TTHREAD, and
2992+
* LUA_TLIGHTUSERDATA.
29792993
*/
29802994
#define __BPF_FUNC_MAPPER(FN) \
29812995
FN(unspec), \
@@ -3111,7 +3125,8 @@ union bpf_attr {
31113125
FN(lua_toboolean), \
31123126
FN(lua_tointeger), \
31133127
FN(lua_newpacket), \
3114-
FN(lua_tostring),
3128+
FN(lua_tostring), \
3129+
FN(lua_type),
31153130
/* #endif CONFIG_XDP_LUA */
31163131

31173132
/* 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
@@ -6112,6 +6112,19 @@ static const struct bpf_func_proto bpf_lua_tostring_proto = {
61126112
.arg3_type = ARG_CONST_SIZE,
61136113
.arg4_type = ARG_ANYTHING,
61146114
};
6115+
6116+
BPF_CALL_2(bpf_lua_type, struct xdp_buff *, ctx, int, index) {
6117+
return lua_type(ctx->L, index);
6118+
}
6119+
6120+
static const struct bpf_func_proto bpf_lua_type_proto = {
6121+
.func = bpf_lua_type,
6122+
.gpl_only = false,
6123+
.pkt_access = false,
6124+
.ret_type = RET_INTEGER,
6125+
.arg1_type = ARG_PTR_TO_CTX,
6126+
.arg2_type = ARG_ANYTHING,
6127+
};
61156128
#endif /* CONFIG_XDP_LUA */
61166129

61176130
bool bpf_helper_changes_pkt_data(void *func)
@@ -6219,6 +6232,8 @@ bpf_base_func_proto(enum bpf_func_id func_id)
62196232
return &bpf_lua_newpacket_proto;
62206233
case BPF_FUNC_lua_tostring:
62216234
return &bpf_lua_tostring_proto;
6235+
case BPF_FUNC_lua_type:
6236+
return &bpf_lua_type_proto;
62226237
#endif /* CONFIG_XDP_LUA */
62236238
default:
62246239
return NULL;

tools/include/uapi/linux/bpf.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2981,6 +2981,20 @@ union bpf_attr {
29812981
* Return
29822982
* 1 if the value at the given index of the Lua stack is a
29832983
* string; otherwise it returns 0
2984+
*
2985+
* void bpf_lua_type(void *ctx, int index)
2986+
* Description
2987+
* Obtains the type of the Lua value at the given index
2988+
* of the Lua stack
2989+
*
2990+
* Return
2991+
* Type of the value in the given valid index,
2992+
* or LUA_TNONE for a non-valid (but acceptable) index.
2993+
* The types returned by lua_type are coded by the
2994+
* following constants defined in lua.h: LUA_TNIL (0),
2995+
* LUA_TNUMBER, LUA_TBOOLEAN, LUA_TSTRING, LUA_TTABLE,
2996+
* LUA_TFUNCTION, LUA_TUSERDATA, LUA_TTHREAD, and
2997+
* LUA_TLIGHTUSERDATA.
29842998
*/
29852999
#define __BPF_FUNC_MAPPER(FN) \
29863000
FN(unspec), \
@@ -3116,7 +3130,8 @@ union bpf_attr {
31163130
FN(lua_toboolean), \
31173131
FN(lua_tointeger), \
31183132
FN(lua_newpacket), \
3119-
FN(lua_tostring),
3133+
FN(lua_tostring), \
3134+
FN(lua_type),
31203135
/* #endif CONFIG_XDP_LUA */
31213136

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

0 commit comments

Comments
 (0)