Skip to content

Commit

Permalink
fixup! Add initial XDPLua helper version
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorNogueiraRio committed Jun 27, 2019
1 parent ca56c3b commit d91ac8c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
38 changes: 29 additions & 9 deletions net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,17 @@
* - netif_rx() feedback
*/

#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "luadata.h"
#ifndef _LUNATIK_H
#define _LUNATIK_H
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#endif

#ifndef _LUADATA_H
#define _LUADATA_H
#include <luadata.h>
#endif

#include <linux/uaccess.h>
#include <linux/bitops.h>
Expand Down Expand Up @@ -891,6 +898,8 @@ u32 lua_prog_run_xdp(struct xdp_buff *ctx, const char *func)
lua_State *L = NULL;
lua_state_cpu *sc;
int cpu;
int base;
int data_ref;
u32 ret = 0;

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

base = lua_gettop(L);
if (lua_getglobal(L, func) != LUA_TFUNCTION) {
printk(KERN_INFO "function %s not found\n", func);
printk(KERN_WARNING "function %s not found\n", func);
goto out;
}

ldata_newref(L, ctx->data, ctx->data_end - ctx->data);
lua_pcall(L, 1, 1, 0);
data_ref = ldata_newref(L, ctx->data, ctx->data_end - ctx->data);
if (lua_pcall(L, 1, 1, 0)) {
printk(KERN_WARNING "%s\n", lua_tostring(L, -1));
goto cleanup;
}
ret = lua_tointeger(L, -1);
lua_pop(L, 1);

cleanup:
lua_settop(L, base);
ldata_unref(L, data_ref);
out:
return ret;
}
Expand Down Expand Up @@ -5219,7 +5234,11 @@ int generic_xdp_lua_install(char *lua_prog) {
lua_state_cpu *sc;

list_for_each_entry(sc, &lua_state_cpu_list, list) {
luaL_dostring(sc->L, lua_prog);
if (luaL_dostring(sc->L, lua_prog)) {
printk(KERN_WARNING "error: %s\nOn cpu: %d\n",
lua_tostring(sc->L, -1), sc->cpu);
return -1;
}
}

return 0;
Expand Down Expand Up @@ -9927,6 +9946,7 @@ static int __init net_dev_init(void)
}

luaL_openlibs(new_state_cpu->L);
luaL_requiref(new_state_cpu->L, "data", luaopen_data, 1);
new_state_cpu->cpu = i;

list_add(&new_state_cpu->list, &lua_state_cpu_list);
Expand Down
2 changes: 1 addition & 1 deletion net/core/rtnetlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1790,11 +1790,11 @@ static const struct nla_policy ifla_port_policy[IFLA_PORT_MAX+1] = {
};

static const struct nla_policy ifla_xdp_policy[IFLA_XDP_MAX + 1] = {
[IFLA_XDP_LUA] = { .type = NLA_STRING, .len = 1024 },
[IFLA_XDP_FD] = { .type = NLA_S32 },
[IFLA_XDP_ATTACHED] = { .type = NLA_U8 },
[IFLA_XDP_FLAGS] = { .type = NLA_U32 },
[IFLA_XDP_PROG_ID] = { .type = NLA_U32 },
[IFLA_XDP_LUA] = { .type = NLA_STRING, .len = 1024 },
};

static const struct rtnl_link_ops *linkinfo_to_kind_ops(const struct nlattr *nla)
Expand Down

0 comments on commit d91ac8c

Please sign in to comment.