diff options
-rw-r--r-- | lua/common.c | 32 | ||||
-rw-r--r-- | lua/filter.c | 2 |
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; } |