Skip to content

Commit b44a69f

Browse files
Add bpf_lua_tostring function
1 parent 08fd5c8 commit b44a69f

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

include/uapi/linux/bpf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2233,6 +2233,7 @@ union bpf_attr {
22332233
FN(lua_dataref), \
22342234
FN(lua_dataunref), \
22352235
FN(lua_pcall), \
2236+
FN(lua_tostring), \
22362237
FN(lua_pop), \
22372238
FN(lua_pushinteger), \
22382239
FN(lua_pushlightuserdata), \

net/core/filter.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5016,6 +5016,26 @@ static const struct bpf_func_proto bpf_lua_tointeger_proto = {
50165016
.arg2_type = ARG_ANYTHING,
50175017
};
50185018

5019+
BPF_CALL_4(bpf_lua_tostring, struct xdp_buff *, ctx, char *, str, u32, size, int, index) {
5020+
if (lua_isstring(ctx->L, index)) {
5021+
strncpy(str, lua_tostring(ctx->L, index), size);
5022+
return 1;
5023+
}
5024+
5025+
return 0;
5026+
}
5027+
5028+
static const struct bpf_func_proto bpf_lua_tostring_proto = {
5029+
.func = bpf_lua_tostring,
5030+
.gpl_only = false,
5031+
.pkt_access = false,
5032+
.ret_type = RET_INTEGER,
5033+
.arg1_type = ARG_PTR_TO_CTX,
5034+
.arg2_type = ARG_PTR_TO_UNINIT_MEM,
5035+
.arg3_type = ARG_CONST_SIZE,
5036+
.arg4_type = ARG_ANYTHING,
5037+
};
5038+
50195039
BPF_CALL_2(bpf_lua_newpacket, struct xdp_buff *, ctx, int, offset) {
50205040
if (offset + ctx->data < ctx->data_end) {
50215041
return lunpack_newpacket(ctx->L, ctx->data + offset,
@@ -5113,6 +5133,8 @@ bpf_base_func_proto(enum bpf_func_id func_id)
51135133
return &bpf_lua_pushstring_proto;
51145134
case BPF_FUNC_lua_toboolean:
51155135
return &bpf_lua_toboolean_proto;
5136+
case BPF_FUNC_lua_tostring:
5137+
return &bpf_lua_tostring_proto;
51165138
case BPF_FUNC_lua_tointeger:
51175139
return &bpf_lua_tointeger_proto;
51185140
case BPF_FUNC_lua_newpacket:

tools/include/uapi/linux/bpf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2231,6 +2231,7 @@ union bpf_attr {
22312231
FN(lua_dataref), \
22322232
FN(lua_dataunref), \
22332233
FN(lua_pcall), \
2234+
FN(lua_tostring), \
22342235
FN(lua_pop), \
22352236
FN(lua_pushinteger), \
22362237
FN(lua_pushlightuserdata), \

tools/testing/selftests/bpf/bpf_helpers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ static void (*bpf_lua_dataunref)(void *ctx, int data_ref) =
152152
static int (*bpf_lua_pcall)(void *ctx, char *funcname, int num_args,
153153
int num_rets) =
154154
(void *) BPF_FUNC_lua_pcall;
155+
static int (*bpf_lua_tostring)(void *ctx, char *sslsni, u32 size, int index) =
156+
(void *)BPF_FUNC_lua_tostring;
155157
static void (*bpf_lua_pop)(void *ctx, int index) =
156158
(void *)BPF_FUNC_lua_pop;
157159
static void (*bpf_lua_pushinteger)(void *ctx, int num) =

0 commit comments

Comments
 (0)