diff options
author | Tomas Krizek <tomas.krizek@nic.cz> | 2021-04-08 12:57:33 +0200 |
---|---|---|
committer | Tomas Krizek <tomas.krizek@nic.cz> | 2021-05-24 14:20:15 +0200 |
commit | b0fe8ce6f1f0add1fcea24946363a787c1c8c09a (patch) | |
tree | 7955cf6cf24755a8436ef3d53fd0f8d5329c7891 /daemon/bindings | |
parent | doc/net.tls(): update command example output (diff) | |
download | knot-resolver-b0fe8ce6f1f0add1fcea24946363a787c1c8c09a.tar.xz knot-resolver-b0fe8ce6f1f0add1fcea24946363a787c1c8c09a.zip |
daemon/worker: add doh_headers_in list
Diffstat (limited to 'daemon/bindings')
-rw-r--r-- | daemon/bindings/net.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/daemon/bindings/net.c b/daemon/bindings/net.c index 37ae2400..d41578d4 100644 --- a/daemon/bindings/net.c +++ b/daemon/bindings/net.c @@ -435,6 +435,55 @@ static int net_tls(lua_State *L) return 1; } +/** Select HTTP headers to subscribe to for incoming DoH requests. */ +static int net_doh_headers_in(lua_State *L) +{ + doh_headerlist_t *headers = &the_worker->doh_headers_in; + int i; + const char *name; + + /* Only return current configuration. */ + if (lua_gettop(L) == 0) { + lua_newtable(L); + for (i = 0; i < headers->len; i++) { + lua_pushinteger(L, i + 1); + name = headers->at[i]; + lua_pushlstring(L, name, strlen(name)); + lua_settable(L, -3); + } + return 1; + } + + if (lua_gettop(L) != 1) + lua_error_p(L, "net.doh_headers_in() takes one parameter (string or table)"); + + if (!lua_istable(L, 1) && !lua_isstring(L, 1)) + lua_error_p(L, "net.doh_headers_in() argument must be string or table"); + + /* Clear existing headers. */ + for (i = 0; i < headers->len; i++) + free(headers->at[i]); + array_clear(*headers); + + if (lua_istable(L, 1)) { + for (i = 1; !lua_isnil(L, -1); i++) { + lua_pushinteger(L, i); + lua_gettable(L, 1); + if (lua_isnil(L, -1)) /* missing value - end iteration */ + break; + if (!lua_isstring(L, -1)) + lua_error_p(L, "net.doh_headers_in() argument table can only contain strings"); + name = lua_tostring(L, -1); + array_push(*headers, strdup(name)); + } + } else if (lua_isstring(L, 1)) { + name = lua_tostring(L, 1); + array_push(*headers, strdup(name)); + } + + return 0; +} + /** Return a lua table with TLS authentication parameters. * The format is the same as passed to policy.TLS_FORWARD(); * more precisely, it's in a compatible canonical form. */ @@ -1083,6 +1132,7 @@ int kr_bindings_net(lua_State *L) { "bpf_set", net_bpf_set }, { "bpf_clear", net_bpf_clear }, { "register_endpoint_kind", net_register_endpoint_kind }, + { "doh_headers_in", net_doh_headers_in }, { NULL, NULL } }; luaL_register(L, "net", lib); |