From: Tomas Krizek Date: Fri, 8 Mar 2019 15:44:24 +0000 (+0100) Subject: daemon/bindings/net: change output format of net.list() X-Git-Tag: v4.0.0~21^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3046eb0ed3fc2ce283bc2cca26a9c7882da2fba4;p=thirdparty%2Fknot-resolver.git daemon/bindings/net: change output format of net.list() --- diff --git a/NEWS b/NEWS index 7c2a17c41..a82954d00 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,7 @@ Incompatible changes - DNSSEC is enabled by default - upstream packages for Debian now require systemd - libknot >= 2.8 is required +- net.list() output format changed Improvements ------------ diff --git a/daemon/bindings/net.c b/daemon/bindings/net.c index 9139b17bf..7bd5fc585 100644 --- a/daemon/bindings/net.c +++ b/daemon/bindings/net.c @@ -27,20 +27,49 @@ static int net_list_add(const char *key, void *val, void *ext) { lua_State *L = (lua_State *)ext; + lua_Integer i = lua_tointeger(L, -1); endpoint_array_t *ep_array = val; - lua_newtable(L); - for (size_t i = ep_array->len; i--;) { - struct endpoint *ep = ep_array->at[i]; - lua_pushinteger(L, ep->port); - lua_setfield(L, -2, "port"); - lua_pushboolean(L, ep->flags & NET_UDP); - lua_setfield(L, -2, "udp"); - lua_pushboolean(L, ep->flags & NET_TCP); - lua_setfield(L, -2, "tcp"); - lua_pushboolean(L, ep->flags & NET_TLS); - lua_setfield(L, -2, "tls"); - } - lua_setfield(L, -2, key); + for (size_t j = ep_array->len; j--;) { + struct endpoint *ep = ep_array->at[j]; + lua_newtable(L); // connection tuple + + lua_pushstring(L, key); + lua_setfield(L, -2, "ip"); + + lua_newtable(L); // "transport" table + if (ep->flags & NET_UDP) { + lua_pushliteral(L, "udp"); + lua_setfield(L, -2, "protocol"); + lua_pushinteger(L, ep->port); + lua_setfield(L, -2, "port"); + lua_pushliteral(L, "none"); + lua_setfield(L, -2, "security"); + } else if (ep->flags & NET_TCP) { + lua_pushliteral(L, "tcp"); + lua_setfield(L, -2, "protocol"); + lua_pushinteger(L, ep->port); + lua_setfield(L, -2, "port"); + if (ep->flags & NET_TLS) { + lua_pushliteral(L, "tls"); + } else { + lua_pushliteral(L, "none"); + } + lua_setfield(L, -2, "security"); + } else { + lua_pushliteral(L, "unknown"); + lua_setfield(L, -2, "protocol"); + } + lua_setfield(L, -2, "transport"); + + lua_newtable(L); // "application" table + lua_pushliteral(L, "dns"); + lua_setfield(L, -2, "protocol"); + lua_setfield(L, -2, "application"); + + lua_settable(L, -3); + i++; + lua_pushinteger(L, i); + } return kr_ok(); } @@ -49,7 +78,9 @@ static int net_list(lua_State *L) { struct engine *engine = engine_luaget(L); lua_newtable(L); + lua_pushinteger(L, 1); map_walk(&engine->net.endpoints, net_list_add, L); + lua_pop(L, 1); return 1; }