From: Vladimír Čunát Date: Wed, 17 May 2017 14:17:32 +0000 (+0200) Subject: command line: specify ports via @ but remain compatible X-Git-Tag: v1.3.0~17^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8bbeab096e2c61d4f16c2e51108922e00de0f28e;p=thirdparty%2Fknot-resolver.git command line: specify ports via @ but remain compatible --- diff --git a/.travis.yml b/.travis.yml index 439f3903a..ad7835d41 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,7 @@ script: - CFLAGS="-O2 -g -fno-omit-frame-pointer -DDEBUG" make -j2 install check V=1 COVERAGE=1 PREFIX=${HOME}/.local DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH} - ./daemon/kresd -h - ./daemon/kresd -V - - echo "quit()" | ./daemon/kresd -a 127.0.0.1#53535 . + - echo "quit()" | ./daemon/kresd -a 127.0.0.1@53535 . - CFLAGS="-O2 -g -fno-omit-frame-pointer -DDEBUG" make -j2 check-integration COVERAGE=1 PREFIX=${HOME}/.local DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH} after_success: - if test $TRAVIS_OS_NAME = linux; then coveralls -i lib -i daemon -x ".c" --gcov-options '\-lp'; fi diff --git a/NEWS b/NEWS index fab3ecfbb..a5c1fec6a 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,7 @@ Security Improvements ------------ - allow answering from cache in non-iterative modes (#122) +- command line: specify ports via @ but still support # for compatibility Knot Resolver 1.2.6 (2017-04-24) diff --git a/daemon/bindings.c b/daemon/bindings.c index aa2d41ca1..14fd548cd 100644 --- a/daemon/bindings.c +++ b/daemon/bindings.c @@ -189,7 +189,7 @@ static int net_listen_addrs(lua_State *L, int port, int flags) struct engine *engine = engine_luaget(L); int ret = network_listen(&engine->net, str, port, flags); if (ret != 0) { - kr_log_info("[system] bind to '%s#%d' %s\n", + kr_log_info("[system] bind to '%s@%d' %s\n", str, port, kr_strerror(ret)); } return ret == 0; diff --git a/daemon/lua/config.lua b/daemon/lua/config.lua index dd31cd3b4..877b553ab 100644 --- a/daemon/lua/config.lua +++ b/daemon/lua/config.lua @@ -2,15 +2,15 @@ if not next(net.list()) then local ok, err = pcall(net.listen, '127.0.0.1') if not ok then - error('bind to 127.0.0.1#53 '..err) + error('bind to 127.0.0.1@53 '..err) end -- IPv6 loopback may fail ok, err = pcall(net.listen, '::1') if not ok and verbose() then - print('bind to ::1#53 '..err) + print('bind to ::1@53 '..err) end end -- Open cache if not set/disabled if not cache.current_size then cache.size = 100 * MB -end \ No newline at end of file +end diff --git a/daemon/main.c b/daemon/main.c index e1e7320a2..2ebbf6ad4 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -289,7 +289,10 @@ static void signal_handler(uv_signal_t *handle, int signum) /** Split away port from the address. */ static const char *set_addr(char *addr, int *port) { - char *p = strchr(addr, '#'); + char *p = strchr(addr, '@'); + if (!p) { + p = strchr(addr, '#'); + } if (p) { *port = atoi(p + 1); *p = '\0'; @@ -338,7 +341,7 @@ static void help(int argc, char *argv[]) { printf("Usage: %s [parameters] [rundir]\n", argv[0]); printf("\nParameters:\n" - " -a, --addr=[addr] Server address (default: localhost#53).\n" + " -a, --addr=[addr] Server address (default: localhost@53).\n" " -t, --tls=[addr] Server address for TLS (default: off).\n" " -S, --fd=[fd] Listen on given fd (handed out by supervisor).\n" " -T, --tlsfd=[fd] Listen using TLS on given fd (handed out by supervisor).\n" @@ -609,7 +612,7 @@ int main(int argc, char **argv) const char *addr = set_addr(addr_set.at[i], &port); ret = network_listen(&engine.net, addr, (uint16_t)port, NET_UDP|NET_TCP); if (ret != 0) { - kr_log_error("[system] bind to '%s#%d' %s\n", addr, port, kr_strerror(ret)); + kr_log_error("[system] bind to '%s@%d' %s\n", addr, port, kr_strerror(ret)); ret = EXIT_FAILURE; break; } @@ -622,7 +625,7 @@ int main(int argc, char **argv) const char *addr = set_addr(tls_set.at[i], &port); ret = network_listen(&engine.net, addr, (uint16_t)port, NET_TCP|NET_TLS); if (ret != 0) { - kr_log_error("[system] bind to '%s#%d' (TLS) %s\n", addr, port, kr_strerror(ret)); + kr_log_error("[system] bind to '%s@%d' (TLS) %s\n", addr, port, kr_strerror(ret)); ret = EXIT_FAILURE; break; } diff --git a/doc/kresd.8.in b/doc/kresd.8.in index 29a648d39..620e2f9dc 100644 --- a/doc/kresd.8.in +++ b/doc/kresd.8.in @@ -13,7 +13,7 @@ .SH "SYNOPSIS" .B kresd .RB [ \-a | \-\-addr -.IR addr[#port] ] +.IR addr[@port] ] .RB [ \-S | \-\-fd .IR fd ] .RB [ \-c | \-\-config @@ -92,11 +92,11 @@ EOF .P The available CLI options are: .TP -.B \-a\fI addr[#port]\fR, \fB\-\-addr=\fI +.B \-a\fI addr[@port]\fR, \fB\-\-addr=\fI Listen on given address (and port) pair. If no port is given, \fI53\fR is used as a default. Option may be passed multiple times to listen on more addresses. .TP -.B \-t\fI addr[#port]\fR, \fB\-\-tls=\fI +.B \-t\fI addr[@port]\fR, \fB\-\-tls=\fI Listen using TLS on given address (and port) pair. If no port is given, \fI853\fR is used as a default. Option may be passed multiple times to listen on more addresses. diff --git a/modules/graphite/graphite.lua b/modules/graphite/graphite.lua index aa4354e04..f7c3a4ca0 100644 --- a/modules/graphite/graphite.lua +++ b/modules/graphite/graphite.lua @@ -66,7 +66,7 @@ local function publish_table(metrics, prefix, now) local tcp = M.cli[i]['connect'] ~= nil local host = M.info[i] if tcp and host.seen + 2 * M.interval / 1000 <= now then - print(string.format('[graphite] reconnecting: %s#%d reason: %s', + print(string.format('[graphite] reconnecting: %s@%d reason: %s', host.addr, host.port, err)) M.cli[i] = make_tcp(host.addr, host.port) host.seen = now diff --git a/modules/http/http.lua b/modules/http/http.lua index 4e0143dbf..f064ba98b 100644 --- a/modules/http/http.lua +++ b/modules/http/http.lua @@ -303,7 +303,7 @@ function M.interface(host, port, endpoints, crtfile, keyfile) onstream = routes; } if not s then - panic('failed to listen on %s#%d: %s', host, port, err) + panic('failed to listen on %s@%d: %s', host, port, err) end table.insert(M.servers, s) -- Create certificate renewal timer if ephemeral diff --git a/scripts/supervisor.py b/scripts/supervisor.py index c585c53dc..218eb5223 100755 --- a/scripts/supervisor.py +++ b/scripts/supervisor.py @@ -27,7 +27,10 @@ while len(unparsed) > 0: # Parse address addr = unparsed.pop(0) try: - if '#' in addr: + if '@' in addr: + addr, port = addr.split('@') + port = int(port) + elif '#' in addr: addr, port = addr.split('#') port = int(port) else: @@ -56,4 +59,4 @@ while True: # Fork forever end = datetime.datetime.now() print('[%s] process finished, pid = %d, status = %d, uptime = %s' % \ (start, pid, status, end - start)) - time.sleep(0.5) \ No newline at end of file + time.sleep(0.5)