|
71 | 71 |
|
72 | 72 | #ifdef CONFIG_XDP_LUA |
73 | 73 | #include <lua.h> |
| 74 | +#include <luadata.h> |
| 75 | +#include <luaunpack.h> |
74 | 76 | #endif /* CONFIG_XDP_LUA */ |
75 | 77 |
|
76 | 78 | /** |
@@ -5013,6 +5015,24 @@ static const struct bpf_func_proto bpf_lua_tointeger_proto = { |
5013 | 5015 | .arg1_type = ARG_PTR_TO_CTX, |
5014 | 5016 | .arg2_type = ARG_ANYTHING, |
5015 | 5017 | }; |
| 5018 | + |
| 5019 | +BPF_CALL_2(bpf_lua_newpacket, struct xdp_buff *, ctx, int, offset) { |
| 5020 | + if (offset + ctx->data < ctx->data_end) { |
| 5021 | + return lunpack_newpacket(ctx->L, ctx->data + offset, |
| 5022 | + ctx->data_end - ctx->data - offset); |
| 5023 | + } |
| 5024 | + |
| 5025 | + return -EINVAL; |
| 5026 | +} |
| 5027 | + |
| 5028 | +static const struct bpf_func_proto bpf_lua_newpacket_proto = { |
| 5029 | + .func = bpf_lua_newpacket, |
| 5030 | + .gpl_only = false, |
| 5031 | + .pkt_access = false, |
| 5032 | + .ret_type = RET_INTEGER, |
| 5033 | + .arg1_type = ARG_PTR_TO_CTX, |
| 5034 | + .arg2_type = ARG_ANYTHING, |
| 5035 | +}; |
5016 | 5036 | #endif /* CONFIG_XDP_LUA */ |
5017 | 5037 |
|
5018 | 5038 | bool bpf_helper_changes_pkt_data(void *func) |
@@ -5095,6 +5115,8 @@ bpf_base_func_proto(enum bpf_func_id func_id) |
5095 | 5115 | return &bpf_lua_toboolean_proto; |
5096 | 5116 | case BPF_FUNC_lua_tointeger: |
5097 | 5117 | return &bpf_lua_tointeger_proto; |
| 5118 | + case BPF_FUNC_lua_newpacket: |
| 5119 | + return &bpf_lua_newpacket_proto; |
5098 | 5120 | #endif /* CONFIG_XDP_LUA */ |
5099 | 5121 | default: |
5100 | 5122 | return NULL; |
|
0 commit comments