|
77 | 77 | #ifdef CONFIG_XDP_LUA |
78 | 78 | #include <lua.h> |
79 | 79 | #include <luadata.h> |
| 80 | +#include <luaunpack.h> |
80 | 81 | #endif /* CONFIG_XDP_LUA */ |
81 | 82 |
|
82 | 83 | /** |
@@ -6073,6 +6074,24 @@ static const struct bpf_func_proto bpf_lua_tointeger_proto = { |
6073 | 6074 | .arg1_type = ARG_PTR_TO_CTX, |
6074 | 6075 | .arg2_type = ARG_ANYTHING, |
6075 | 6076 | }; |
| 6077 | + |
| 6078 | +BPF_CALL_2(bpf_lua_newpacket, struct xdp_buff *, ctx, int, offset) { |
| 6079 | + if (offset + ctx->data < ctx->data_end) { |
| 6080 | + return lunpack_newpacket(ctx->L, ctx->data + offset, |
| 6081 | + ctx->data_end - ctx->data - offset); |
| 6082 | + } |
| 6083 | + |
| 6084 | + return -EINVAL; |
| 6085 | +} |
| 6086 | + |
| 6087 | +static const struct bpf_func_proto bpf_lua_newpacket_proto = { |
| 6088 | + .func = bpf_lua_newpacket, |
| 6089 | + .gpl_only = false, |
| 6090 | + .pkt_access = false, |
| 6091 | + .ret_type = RET_INTEGER, |
| 6092 | + .arg1_type = ARG_PTR_TO_CTX, |
| 6093 | + .arg2_type = ARG_ANYTHING, |
| 6094 | +}; |
6076 | 6095 | #endif /* CONFIG_XDP_LUA */ |
6077 | 6096 |
|
6078 | 6097 | bool bpf_helper_changes_pkt_data(void *func) |
@@ -6176,6 +6195,8 @@ bpf_base_func_proto(enum bpf_func_id func_id) |
6176 | 6195 | return &bpf_lua_toboolean_proto; |
6177 | 6196 | case BPF_FUNC_lua_tointeger: |
6178 | 6197 | return &bpf_lua_tointeger_proto; |
| 6198 | + case BPF_FUNC_lua_newpacket: |
| 6199 | + return &bpf_lua_newpacket_proto; |
6179 | 6200 | #endif /* CONFIG_XDP_LUA */ |
6180 | 6201 | default: |
6181 | 6202 | return NULL; |
|
0 commit comments