|
76 | 76 |
|
77 | 77 | #ifdef CONFIG_XDP_LUA |
78 | 78 | #include <lua.h> |
| 79 | +#include <luadata.h> |
79 | 80 | #endif /* CONFIG_XDP_LUA */ |
80 | 81 |
|
81 | 82 | /** |
@@ -5854,6 +5855,41 @@ static const struct bpf_func_proto bpf_tcp_gen_syncookie_proto = { |
5854 | 5855 | #endif /* CONFIG_INET */ |
5855 | 5856 |
|
5856 | 5857 | #ifdef CONFIG_XDP_LUA |
| 5858 | +BPF_CALL_2(bpf_lua_dataref, struct xdp_buff *, ctx, int, offset) { |
| 5859 | + if (offset + ctx->data < ctx->data_end) { |
| 5860 | + int data_ref; |
| 5861 | + |
| 5862 | + data_ref = ldata_newref(ctx->L, ctx->data + offset, |
| 5863 | + ctx->data_end - ctx->data - offset); |
| 5864 | + return data_ref; |
| 5865 | + } |
| 5866 | + |
| 5867 | + return -1; |
| 5868 | +} |
| 5869 | + |
| 5870 | +static const struct bpf_func_proto bpf_lua_dataref_proto = { |
| 5871 | + .func = bpf_lua_dataref, |
| 5872 | + .gpl_only = false, |
| 5873 | + .pkt_access = false, |
| 5874 | + .ret_type = RET_INTEGER, |
| 5875 | + .arg1_type = ARG_PTR_TO_CTX, |
| 5876 | + .arg1_type = ARG_ANYTHING, |
| 5877 | +}; |
| 5878 | + |
| 5879 | +BPF_CALL_2(bpf_lua_dataunref, struct xdp_buff *, ctx, int, data_ref) { |
| 5880 | + ldata_unref(ctx->L, data_ref); |
| 5881 | + return 0; |
| 5882 | +} |
| 5883 | + |
| 5884 | +static const struct bpf_func_proto bpf_lua_dataunref_proto = { |
| 5885 | + .func = bpf_lua_dataunref, |
| 5886 | + .gpl_only = false, |
| 5887 | + .pkt_access = false, |
| 5888 | + .ret_type = RET_VOID, |
| 5889 | + .arg1_type = ARG_PTR_TO_CTX, |
| 5890 | + .arg2_type = ARG_ANYTHING, |
| 5891 | +}; |
| 5892 | + |
5857 | 5893 | BPF_CALL_4(bpf_lua_pcall, struct xdp_buff *, ctx, char *, funcname, |
5858 | 5894 | int, num_args, int, num_rets) { |
5859 | 5895 | if (lua_getglobal(ctx->L, funcname) != LUA_TFUNCTION) { |
@@ -6105,6 +6141,10 @@ bpf_base_func_proto(enum bpf_func_id func_id) |
6105 | 6141 | case BPF_FUNC_jiffies64: |
6106 | 6142 | return &bpf_jiffies64_proto; |
6107 | 6143 | #ifdef CONFIG_XDP_LUA |
| 6144 | + case BPF_FUNC_lua_dataref: |
| 6145 | + return &bpf_lua_dataref_proto; |
| 6146 | + case BPF_FUNC_lua_dataunref: |
| 6147 | + return &bpf_lua_dataunref_proto; |
6108 | 6148 | case BPF_FUNC_lua_pcall: |
6109 | 6149 | return &bpf_lua_pcall_proto; |
6110 | 6150 | case BPF_FUNC_lua_pop: |
|
0 commit comments