Commit 8bbeab09 authored by Vladimír Čunát's avatar Vladimír Čunát

command line: specify ports via @ but remain compatible

parent ccafba8e
...@@ -33,7 +33,7 @@ script: ...@@ -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} - 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 -h
- ./daemon/kresd -V - ./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} - 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: after_success:
- if test $TRAVIS_OS_NAME = linux; then coveralls -i lib -i daemon -x ".c" --gcov-options '\-lp'; fi - if test $TRAVIS_OS_NAME = linux; then coveralls -i lib -i daemon -x ".c" --gcov-options '\-lp'; fi
......
...@@ -11,6 +11,7 @@ Security ...@@ -11,6 +11,7 @@ Security
Improvements Improvements
------------ ------------
- allow answering from cache in non-iterative modes (#122) - 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) Knot Resolver 1.2.6 (2017-04-24)
......
...@@ -189,7 +189,7 @@ static int net_listen_addrs(lua_State *L, int port, int flags) ...@@ -189,7 +189,7 @@ static int net_listen_addrs(lua_State *L, int port, int flags)
struct engine *engine = engine_luaget(L); struct engine *engine = engine_luaget(L);
int ret = network_listen(&engine->net, str, port, flags); int ret = network_listen(&engine->net, str, port, flags);
if (ret != 0) { 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)); str, port, kr_strerror(ret));
} }
return ret == 0; return ret == 0;
......
...@@ -2,15 +2,15 @@ ...@@ -2,15 +2,15 @@
if not next(net.list()) then if not next(net.list()) then
local ok, err = pcall(net.listen, '127.0.0.1') local ok, err = pcall(net.listen, '127.0.0.1')
if not ok then if not ok then
error('bind to 127.0.0.1#53 '..err) error('bind to 127.0.0.1@53 '..err)
end end
-- IPv6 loopback may fail -- IPv6 loopback may fail
ok, err = pcall(net.listen, '::1') ok, err = pcall(net.listen, '::1')
if not ok and verbose() then if not ok and verbose() then
print('bind to ::1#53 '..err) print('bind to ::1@53 '..err)
end end
end end
-- Open cache if not set/disabled -- Open cache if not set/disabled
if not cache.current_size then if not cache.current_size then
cache.size = 100 * MB cache.size = 100 * MB
end end
\ No newline at end of file
...@@ -289,7 +289,10 @@ static void signal_handler(uv_signal_t *handle, int signum) ...@@ -289,7 +289,10 @@ static void signal_handler(uv_signal_t *handle, int signum)
/** Split away port from the address. */ /** Split away port from the address. */
static const char *set_addr(char *addr, int *port) static const char *set_addr(char *addr, int *port)
{ {
char *p = strchr(addr, '#'); char *p = strchr(addr, '@');
if (!p) {
p = strchr(addr, '#');
}
if (p) { if (p) {
*port = atoi(p + 1); *port = atoi(p + 1);
*p = '\0'; *p = '\0';
...@@ -338,7 +341,7 @@ static void help(int argc, char *argv[]) ...@@ -338,7 +341,7 @@ static void help(int argc, char *argv[])
{ {
printf("Usage: %s [parameters] [rundir]\n", argv[0]); printf("Usage: %s [parameters] [rundir]\n", argv[0]);
printf("\nParameters:\n" 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" " -t, --tls=[addr] Server address for TLS (default: off).\n"
" -S, --fd=[fd] Listen on given fd (handed out by supervisor).\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" " -T, --tlsfd=[fd] Listen using TLS on given fd (handed out by supervisor).\n"
...@@ -609,7 +612,7 @@ int main(int argc, char **argv) ...@@ -609,7 +612,7 @@ int main(int argc, char **argv)
const char *addr = set_addr(addr_set.at[i], &port); const char *addr = set_addr(addr_set.at[i], &port);
ret = network_listen(&engine.net, addr, (uint16_t)port, NET_UDP|NET_TCP); ret = network_listen(&engine.net, addr, (uint16_t)port, NET_UDP|NET_TCP);
if (ret != 0) { 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; ret = EXIT_FAILURE;
break; break;
} }
...@@ -622,7 +625,7 @@ int main(int argc, char **argv) ...@@ -622,7 +625,7 @@ int main(int argc, char **argv)
const char *addr = set_addr(tls_set.at[i], &port); const char *addr = set_addr(tls_set.at[i], &port);
ret = network_listen(&engine.net, addr, (uint16_t)port, NET_TCP|NET_TLS); ret = network_listen(&engine.net, addr, (uint16_t)port, NET_TCP|NET_TLS);
if (ret != 0) { 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; ret = EXIT_FAILURE;
break; break;
} }
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
.SH "SYNOPSIS" .SH "SYNOPSIS"
.B kresd .B kresd
.RB [ \-a | \-\-addr .RB [ \-a | \-\-addr
.IR addr[#port] ] .IR addr[@port] ]
.RB [ \-S | \-\-fd .RB [ \-S | \-\-fd
.IR fd ] .IR fd ]
.RB [ \-c | \-\-config .RB [ \-c | \-\-config
...@@ -92,11 +92,11 @@ EOF ...@@ -92,11 +92,11 @@ EOF
.P .P
The available CLI options are: The available CLI options are:
.TP .TP
.B \-a\fI addr[#port]\fR, \fB\-\-addr=\fI<addr[#port]> .B \-a\fI addr[@port]\fR, \fB\-\-addr=\fI<addr[@port]>
Listen on given address (and port) pair. If no port is given, \fI53\fR is used as a default. 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. Option may be passed multiple times to listen on more addresses.
.TP .TP
.B \-t\fI addr[#port]\fR, \fB\-\-tls=\fI<addr[#port]> .B \-t\fI addr[@port]\fR, \fB\-\-tls=\fI<addr[@port]>
Listen using TLS on given address (and port) pair. If no port is 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 given, \fI853\fR is used as a default. Option may be passed multiple
times to listen on more addresses. times to listen on more addresses.
......
...@@ -66,7 +66,7 @@ local function publish_table(metrics, prefix, now) ...@@ -66,7 +66,7 @@ local function publish_table(metrics, prefix, now)
local tcp = M.cli[i]['connect'] ~= nil local tcp = M.cli[i]['connect'] ~= nil
local host = M.info[i] local host = M.info[i]
if tcp and host.seen + 2 * M.interval / 1000 <= now then 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)) host.addr, host.port, err))
M.cli[i] = make_tcp(host.addr, host.port) M.cli[i] = make_tcp(host.addr, host.port)
host.seen = now host.seen = now
......
...@@ -303,7 +303,7 @@ function M.interface(host, port, endpoints, crtfile, keyfile) ...@@ -303,7 +303,7 @@ function M.interface(host, port, endpoints, crtfile, keyfile)
onstream = routes; onstream = routes;
} }
if not s then 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 end
table.insert(M.servers, s) table.insert(M.servers, s)
-- Create certificate renewal timer if ephemeral -- Create certificate renewal timer if ephemeral
......
...@@ -27,7 +27,10 @@ while len(unparsed) > 0: ...@@ -27,7 +27,10 @@ while len(unparsed) > 0:
# Parse address # Parse address
addr = unparsed.pop(0) addr = unparsed.pop(0)
try: try:
if '#' in addr: if '@' in addr:
addr, port = addr.split('@')
port = int(port)
elif '#' in addr:
addr, port = addr.split('#') addr, port = addr.split('#')
port = int(port) port = int(port)
else: else:
...@@ -56,4 +59,4 @@ while True: # Fork forever ...@@ -56,4 +59,4 @@ while True: # Fork forever
end = datetime.datetime.now() end = datetime.datetime.now()
print('[%s] process finished, pid = %d, status = %d, uptime = %s' % \ print('[%s] process finished, pid = %d, status = %d, uptime = %s' % \
(start, pid, status, end - start)) (start, pid, status, end - start))
time.sleep(0.5) time.sleep(0.5)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment