summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2019-02-27 19:49:50 +0100
committerMikael Magnusson <mikma@users.sourceforge.net>2019-02-27 22:16:10 +0100
commit0c395cf7a2faa70df52845063a4169743fd3b34a (patch)
tree7b61553a90551fa01250520e3bca0d1726ad8e0f
parent41344e7f27dbc06537745fb7671cfb132a850d73 (diff)
lua: Add route:ea_set_attr_datalua/wireguard
-rw-r--r--lua/common.c32
-rw-r--r--lua/filter.c2
2 files changed, 34 insertions, 0 deletions
diff --git a/lua/common.c b/lua/common.c
index 5b22dd4c..9f617775 100644
--- a/lua/common.c
+++ b/lua/common.c
@@ -9,6 +9,8 @@
#include <lualib.h>
#include <lauxlib.h>
+static linpool *lua_lp;
+
static int luaB_err(lua_State *L) {
int n = lua_gettop(L);
if (n != 1)
@@ -266,11 +268,41 @@ static int luaB_route_ea_find(lua_State *L) {
}
}
+/* ea_set_attr_data(id, flags, type, data(string) */
+static int luaB_route_ea_set_attr_data(lua_State *L) {
+ int n = lua_gettop(L);
+ if (n != 5) {
+ log(L_WARN "ea_set_attr_data needs exactly 4 argument");
+ return 0;
+ }
+
+ lua_pushliteral(L, "_internal");
+ lua_gettable(L, 1);
+ if (!lua_isuserdata(L, -1))
+ luaL_error(L, "fatal: bird internal state not found, type %d", lua_type(L, -1));
+
+ struct rte *e = lua_touserdata(L, -1);
+ uint id = lua_tointeger(L, 2);
+ uint flags = lua_tointeger(L, 3);
+ uint type = lua_tointeger(L, 4);
+ size_t len = 0;
+ const char *data = lua_tolstring(L, 5, &len);
+ lua_pop(L, 5);
+
+ struct ea_list **eattrs = &e->attrs->eattrs;
+ if (!lua_lp)
+ lua_lp = lp_new_default(&root_pool);
+ ea_set_attr_data(eattrs, lua_lp, id, flags, type, data, len);
+ lua_pushboolean(L, 1);
+ return 0;
+}
+
void luaB_push_route(lua_State *L, struct rte *e) {
lua_newtable(L);
lua_settablelightuserdata(L, "_internal", e);
lua_settableaddr(L, "prefix", e->net->n.addr);
lua_settablecfunction(L, "ea_find", luaB_route_ea_find);
+ lua_settablecfunction(L, "ea_set_attr_data", luaB_route_ea_set_attr_data);
lua_newtable(L);
lua_settablevalue(L, "__index", -2-1);
diff --git a/lua/filter.c b/lua/filter.c
index 9fa655a8..f4de8f1f 100644
--- a/lua/filter.c
+++ b/lua/filter.c
@@ -118,6 +118,8 @@ struct f_val lua_interpret(struct lua_filter_chunk *chunk, struct rte **e, struc
out = F_VAL(T_RETURN, i, F_ERROR);
}
+ *ea = (*e)->attrs->eattrs;
+
luaB_close(L);
return out;
}