Skip to content

Commit d91ac8c

Browse files
fixup! Add initial XDPLua helper version
1 parent ca56c3b commit d91ac8c

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

net/core/dev.c

+29-9
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,17 @@
7272
* - netif_rx() feedback
7373
*/
7474

75-
#include "lua.h"
76-
#include "lauxlib.h"
77-
#include "lualib.h"
78-
#include "luadata.h"
75+
#ifndef _LUNATIK_H
76+
#define _LUNATIK_H
77+
#include <lua.h>
78+
#include <lauxlib.h>
79+
#include <lualib.h>
80+
#endif
81+
82+
#ifndef _LUADATA_H
83+
#define _LUADATA_H
84+
#include <luadata.h>
85+
#endif
7986

8087
#include <linux/uaccess.h>
8188
#include <linux/bitops.h>
@@ -891,6 +898,8 @@ u32 lua_prog_run_xdp(struct xdp_buff *ctx, const char *func)
891898
lua_State *L = NULL;
892899
lua_state_cpu *sc;
893900
int cpu;
901+
int base;
902+
int data_ref;
894903
u32 ret = 0;
895904

896905
cpu = smp_processor_id();
@@ -904,16 +913,22 @@ u32 lua_prog_run_xdp(struct xdp_buff *ctx, const char *func)
904913
if (!L)
905914
goto out;
906915

916+
base = lua_gettop(L);
907917
if (lua_getglobal(L, func) != LUA_TFUNCTION) {
908-
printk(KERN_INFO "function %s not found\n", func);
918+
printk(KERN_WARNING "function %s not found\n", func);
909919
goto out;
910920
}
911921

912-
ldata_newref(L, ctx->data, ctx->data_end - ctx->data);
913-
lua_pcall(L, 1, 1, 0);
922+
data_ref = ldata_newref(L, ctx->data, ctx->data_end - ctx->data);
923+
if (lua_pcall(L, 1, 1, 0)) {
924+
printk(KERN_WARNING "%s\n", lua_tostring(L, -1));
925+
goto cleanup;
926+
}
914927
ret = lua_tointeger(L, -1);
915-
lua_pop(L, 1);
916928

929+
cleanup:
930+
lua_settop(L, base);
931+
ldata_unref(L, data_ref);
917932
out:
918933
return ret;
919934
}
@@ -5219,7 +5234,11 @@ int generic_xdp_lua_install(char *lua_prog) {
52195234
lua_state_cpu *sc;
52205235

52215236
list_for_each_entry(sc, &lua_state_cpu_list, list) {
5222-
luaL_dostring(sc->L, lua_prog);
5237+
if (luaL_dostring(sc->L, lua_prog)) {
5238+
printk(KERN_WARNING "error: %s\nOn cpu: %d\n",
5239+
lua_tostring(sc->L, -1), sc->cpu);
5240+
return -1;
5241+
}
52235242
}
52245243

52255244
return 0;
@@ -9927,6 +9946,7 @@ static int __init net_dev_init(void)
99279946
}
99289947

99299948
luaL_openlibs(new_state_cpu->L);
9949+
luaL_requiref(new_state_cpu->L, "data", luaopen_data, 1);
99309950
new_state_cpu->cpu = i;
99319951

99329952
list_add(&new_state_cpu->list, &lua_state_cpu_list);

net/core/rtnetlink.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1790,11 +1790,11 @@ static const struct nla_policy ifla_port_policy[IFLA_PORT_MAX+1] = {
17901790
};
17911791

17921792
static const struct nla_policy ifla_xdp_policy[IFLA_XDP_MAX + 1] = {
1793-
[IFLA_XDP_LUA] = { .type = NLA_STRING, .len = 1024 },
17941793
[IFLA_XDP_FD] = { .type = NLA_S32 },
17951794
[IFLA_XDP_ATTACHED] = { .type = NLA_U8 },
17961795
[IFLA_XDP_FLAGS] = { .type = NLA_U32 },
17971796
[IFLA_XDP_PROG_ID] = { .type = NLA_U32 },
1797+
[IFLA_XDP_LUA] = { .type = NLA_STRING, .len = 1024 },
17981798
};
17991799

18001800
static const struct rtnl_link_ops *linkinfo_to_kind_ops(const struct nlattr *nla)

0 commit comments

Comments
 (0)