|
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 | /** |
@@ -5008,6 +5010,24 @@ static const struct bpf_func_proto bpf_lua_tointeger_proto = { |
5008 | 5010 | .arg1_type = ARG_PTR_TO_CTX, |
5009 | 5011 | .arg2_type = ARG_ANYTHING, |
5010 | 5012 | }; |
| 5013 | + |
| 5014 | +BPF_CALL_2(bpf_lua_newpacket, struct xdp_buff *, ctx, int, offset) { |
| 5015 | + if (offset + ctx->data < ctx->data_end) { |
| 5016 | + return lunpack_newpacket(ctx->L, ctx->data + offset, |
| 5017 | + ctx->data_end - ctx->data - offset); |
| 5018 | + } |
| 5019 | + |
| 5020 | + return -EINVAL; |
| 5021 | +} |
| 5022 | + |
| 5023 | +static const struct bpf_func_proto bpf_lua_newpacket_proto = { |
| 5024 | + .func = bpf_lua_newpacket, |
| 5025 | + .gpl_only = false, |
| 5026 | + .pkt_access = false, |
| 5027 | + .ret_type = RET_INTEGER, |
| 5028 | + .arg1_type = ARG_PTR_TO_CTX, |
| 5029 | + .arg2_type = ARG_ANYTHING, |
| 5030 | +}; |
5011 | 5031 | #endif /* CONFIG_XDP_LUA */ |
5012 | 5032 |
|
5013 | 5033 | bool bpf_helper_changes_pkt_data(void *func) |
@@ -5090,6 +5110,8 @@ bpf_base_func_proto(enum bpf_func_id func_id) |
5090 | 5110 | return &bpf_lua_toboolean_proto; |
5091 | 5111 | case BPF_FUNC_lua_tointeger: |
5092 | 5112 | return &bpf_lua_tointeger_proto; |
| 5113 | + case BPF_FUNC_lua_newpacket: |
| 5114 | + return &bpf_lua_newpacket_proto; |
5093 | 5115 | #endif /* CONFIG_XDP_LUA */ |
5094 | 5116 | default: |
5095 | 5117 | return NULL; |
|
0 commit comments