|
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 | /** |
@@ -6072,6 +6073,23 @@ static const struct bpf_func_proto bpf_lua_removestate_proto = { |
6072 | 6073 | .ret_type = RET_VOID, |
6073 | 6074 | .arg1_type = ARG_PTR_TO_CTX, |
6074 | 6075 | }; |
| 6076 | +BPF_CALL_2(bpf_lua_newpacket, struct xdp_buff *, ctx, int, offset) { |
| 6077 | + if (offset + ctx->data < ctx->data_end) { |
| 6078 | + return lunpack_newpacket(ctx->xdplua->L, ctx->data + offset, |
| 6079 | + ctx->data_end - ctx->data - offset); |
| 6080 | + } |
| 6081 | + |
| 6082 | + return -EINVAL; |
| 6083 | +} |
| 6084 | + |
| 6085 | +static const struct bpf_func_proto bpf_lua_newpacket_proto = { |
| 6086 | + .func = bpf_lua_newpacket, |
| 6087 | + .gpl_only = false, |
| 6088 | + .pkt_access = false, |
| 6089 | + .ret_type = RET_INTEGER, |
| 6090 | + .arg1_type = ARG_PTR_TO_CTX, |
| 6091 | + .arg2_type = ARG_ANYTHING, |
| 6092 | +}; |
6075 | 6093 | #endif /* CONFIG_XDP_LUA */ |
6076 | 6094 |
|
6077 | 6095 | bool bpf_helper_changes_pkt_data(void *func) |
@@ -6177,6 +6195,8 @@ bpf_base_func_proto(enum bpf_func_id func_id) |
6177 | 6195 | return &bpf_lua_putstate_proto; |
6178 | 6196 | case BPF_FUNC_lua_removestate: |
6179 | 6197 | return &bpf_lua_removestate_proto; |
| 6198 | + case BPF_FUNC_lua_newpacket: |
| 6199 | + return &bpf_lua_newpacket_proto; |
6180 | 6200 | #endif /* CONFIG_XDP_LUA */ |
6181 | 6201 | default: |
6182 | 6202 | return NULL; |
|
0 commit comments