diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2018-09-26 23:06:35 +0200 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2019-02-23 19:34:03 +0000 |
commit | 8deb9475a15e4a83a97bc892328605f284b2f40f (patch) | |
tree | ab02b3e1ad6db25fad0fb924fc3aa4edbe3f7d3b | |
parent | bbbef80214337552c252b86c8f07e142d7f8190b (diff) |
Lua: WIP tunnel encap
-rw-r--r-- | filter/filter.c | 1 | ||||
-rw-r--r-- | lua/common.c | 41 | ||||
-rw-r--r-- | lua/filter.c | 1 | ||||
-rw-r--r-- | lua/lua.h | 1 |
4 files changed, 44 insertions, 0 deletions
diff --git a/filter/filter.c b/filter/filter.c index 933b8a90..d047b814 100644 --- a/filter/filter.c +++ b/filter/filter.c @@ -1779,6 +1779,7 @@ f_run(struct filter *filter, struct rte **rte, struct linpool *tmp_pool, int fla res = interpret(filter->root); break; case FILTER_LUA: + ACCESS_EATTRS; res = lua_interpret(filter->lua_chunk, rte, &f_old_rta, f_eattrs, tmp_pool, flags); break; default: diff --git a/lua/common.c b/lua/common.c index 9bb52c59..c414005c 100644 --- a/lua/common.c +++ b/lua/common.c @@ -1,4 +1,6 @@ #include "nest/bird.h" +#include "nest/protocol.h" +#include "nest/route.h" #include "conf/conf.h" #include "filter/filter.h" #include "lua.h" @@ -66,6 +68,7 @@ static int luaB_trace(lua_State *L) { #define lua_settableinteger(L, idx, val) lua_sett(L, idx, val, integer) #define lua_settableip4(L, idx, val) lua_sett(L, idx, val, ip4) #define lua_settablelightuserdata(L, idx, val) lua_sett(L, idx, val, lightuserdata) +#define lua_settableeattr(L, idx, val) lua_sett(L, idx, val, eattr) #define lua_setglobalcfunction(L, n, val) do { \ lua_pushcfunction(L, val); \ @@ -163,6 +166,25 @@ static void lua_pushaddr(lua_State *L, net_addr *addr) { lua_setmetatable(L, -2); } +static void lua_pusheattr(lua_State *L, eattr *ea) { + /* if (ea->type == EAF_TYPE_IP_ADDRESS) { */ + /* lua_settableinteger(L, "data", 17); */ + /* /\* lua_pushaddr(L, "addr", (net_addr*)ea->u.ptr->data); *\/ */ + /* } */ + lua_newtable(L); + lua_settableinteger(L, "id", ea->id); + lua_settableinteger(L, "type", ea->type); + if (ea->u.ptr && ea->u.ptr->data) { + lua_pushliteral(L, "data"); + lua_pushlstring(L, ea->u.ptr->data, ea->u.ptr->length); + lua_settable(L, -3); + } + + /* lua_settablecfunction(L, "__tostring", luaB_addr_tostring); */ + /* lua_settablecfunction(L, "__concat", luaB_generic_concat); */ + /* lua_setmetatable(L, -2); */ +} + static lua_bird_state *luaB_getinternalstate(lua_State *L) { lua_getglobal(L, "bird"); lua_pushstring(L, "_internal_state"); @@ -220,3 +242,22 @@ void luaB_push_route(lua_State *L, struct rte *e) { lua_settableaddr(L, "prefix", e->net->n.addr); lua_setglobal(L, "route"); } + +#define BA_TUNNEL_ENCAP 0x17 + +void luaB_push_eattrs(lua_State *L, struct ea_list *ea) { + lua_newtable(L); + + if (!ea) { + log(L_ERR "Null eattrs"); + } + + eattr *t = ea_find(ea, EA_CODE(PROTOCOL_BGP, BA_TUNNEL_ENCAP)); + + if (t) { + lua_settableeattr(L, "tunnel_encap", t); + } else + log(L_ERR "Tunnel encap not found"); + + lua_setglobal(L, "eattrs"); +} diff --git a/lua/filter.c b/lua/filter.c index a5c8cbbb..9fa655a8 100644 --- a/lua/filter.c +++ b/lua/filter.c @@ -100,6 +100,7 @@ struct f_val lua_interpret(struct lua_filter_chunk *chunk, struct rte **e, struc lua_bird_state *lbs = luaB_init(L, lp); luaB_push_route(L, *e); + luaB_push_eattrs(L, *ea); struct lua_filter_chunk **rptr = &chunk; lua_load(L, lua_interpret_reader, rptr, "", "b"); @@ -14,4 +14,5 @@ typedef struct lua_bird_state { lua_bird_state *luaB_init(lua_State *L, struct linpool *lp); void luaB_push_route(lua_State *L, rte *e); +void luaB_push_eattrs(lua_State *L, struct ea_list *ea); |