Skip to content

Commit 42219e1

Browse files
Add bpf_lua_tostring function
1 parent 497fd52 commit 42219e1

4 files changed

Lines changed: 26 additions & 0 deletions

File tree

include/uapi/linux/bpf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2829,6 +2829,7 @@ union bpf_attr {
28292829
FN(lua_dataref), \
28302830
FN(lua_dataunref), \
28312831
FN(lua_pcall), \
2832+
FN(lua_tostring), \
28322833
FN(lua_pop), \
28332834
FN(lua_pushinteger), \
28342835
FN(lua_pushlightuserdata), \

net/core/filter.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6060,6 +6060,26 @@ static const struct bpf_func_proto bpf_lua_putstate_proto = {
60606060
.arg1_type = ARG_PTR_TO_CTX,
60616061
};
60626062

6063+
BPF_CALL_4(bpf_lua_tostring, struct xdp_buff *, ctx, char *, str, u32, size, int, index) {
6064+
if (lua_isstring(ctx->lstatecpu->L, index)) {
6065+
strncpy(str, lua_tostring(ctx->lstatecpu->L, index), size);
6066+
return 1;
6067+
}
6068+
6069+
return 0;
6070+
}
6071+
6072+
static const struct bpf_func_proto bpf_lua_tostring_proto = {
6073+
.func = bpf_lua_tostring,
6074+
.gpl_only = false,
6075+
.pkt_access = false,
6076+
.ret_type = RET_INTEGER,
6077+
.arg1_type = ARG_PTR_TO_CTX,
6078+
.arg2_type = ARG_PTR_TO_UNINIT_MEM,
6079+
.arg3_type = ARG_CONST_SIZE,
6080+
.arg4_type = ARG_ANYTHING,
6081+
};
6082+
60636083
BPF_CALL_1(bpf_lua_removestate, struct xdp_buff *, ctx) {
60646084
spin_unlock(ctx->xdplua->lock);
60656085
ctx->xdplua = NULL;
@@ -6189,6 +6209,8 @@ bpf_base_func_proto(enum bpf_func_id func_id)
61896209
return &bpf_lua_pushstring_proto;
61906210
case BPF_FUNC_lua_toboolean:
61916211
return &bpf_lua_toboolean_proto;
6212+
case BPF_FUNC_lua_tostring:
6213+
return &bpf_lua_tostring_proto;
61926214
case BPF_FUNC_lua_tointeger:
61936215
return &bpf_lua_tointeger_proto;
61946216
case BPF_FUNC_lua_putstate:

tools/include/uapi/linux/bpf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2829,6 +2829,7 @@ union bpf_attr {
28292829
FN(lua_dataref), \
28302830
FN(lua_dataunref), \
28312831
FN(lua_pcall), \
2832+
FN(lua_tostring), \
28322833
FN(lua_pop), \
28332834
FN(lua_pushinteger), \
28342835
FN(lua_pushlightuserdata), \

tools/testing/selftests/bpf/bpf_helpers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ static void (*bpf_lua_dataunref)(void *ctx, int data_ref) =
237237
static void (*bpf_lua_pcall)(void *ctx, char *funcname, int num_args,
238238
int num_rets) =
239239
(void *) BPF_FUNC_lua_pcall;
240+
static int (*bpf_lua_tostring)(void *ctx, char *sslsni, u32 size, int index) =
241+
(void *)BPF_FUNC_lua_tostring;
240242
static void (*bpf_lua_pop)(void *ctx, int index) =
241243
(void *)BPF_FUNC_lua_pop;
242244
static void (*bpf_lua_pushinteger)(void *ctx, int num) =

0 commit comments

Comments
 (0)