From 0c395cf7a2faa70df52845063a4169743fd3b34a Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Wed, 27 Feb 2019 19:49:50 +0100 Subject: lua: Add route:ea_set_attr_data --- lua/common.c | 32 ++++++++++++++++++++++++++++++++ lua/filter.c | 2 ++ 2 files changed, 34 insertions(+) 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 #include +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; } -- cgit v1.2.3