From: Vladimír Čunát Date: Wed, 17 Apr 2019 16:23:25 +0000 (+0200) Subject: lua net.listen() tweaks (+docs) X-Git-Tag: v4.0.0~4^2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b6d0e8cef536daf313202e5e90d18b045aaeb7ea;p=thirdparty%2Fknot-resolver.git lua net.listen() tweaks (+docs) --- diff --git a/NEWS b/NEWS index fe5429b15..0f2d2c305 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,7 @@ Incompatible changes - upstream packages for Debian now require systemd - libknot >= 2.8 is required - net.list() output format changed +- net.listen() reports error when address-port pair is in use Improvements ------------ diff --git a/daemon/bindings/net.rst b/daemon/bindings/net.rst index 774568f74..cd49f73d9 100644 --- a/daemon/bindings/net.rst +++ b/daemon/bindings/net.rst @@ -104,15 +104,17 @@ configured in the config file. Enable/disable using IPv4 for contacting upstream nameservers. -.. function:: net.listen(addresses, [port = 53, flags = {tls = (port == 853)}]) +.. function:: net.listen(addresses, [port = 53, { kind = 'dns' }]) :return: boolean Listen on addresses; port and flags are optional. The addresses can be specified as a string or device, or a list of addresses (recursively). - The command can be given multiple times, but note that it silently skips - any addresses that have already been bound. + The command can be given multiple times, + but repeating an address-port combination is an error. + + If you specify port 853, ``kind = 'tls'`` by default. Examples: @@ -120,7 +122,8 @@ configured in the config file. net.listen('::1') net.listen(net.lo, 5353) - net.listen({net.eth0, '127.0.0.1'}, 53853, {tls = true}) + net.listen({net.eth0, '127.0.0.1'}, 53853, { kind = 'tls' }) + net.listen('::', 8453, { kind = 'webmgmt' }) -- see http module .. function:: net.close(address, [port]) diff --git a/daemon/network.c b/daemon/network.c index 925d5faf5..d1a870350 100644 --- a/daemon/network.c +++ b/daemon/network.c @@ -375,7 +375,7 @@ int network_listen(struct network *net, const char *addr, uint16_t port, return kr_error(EINVAL); } if (endpoint_get(net, addr, port, flags)) { - return kr_ok(); /* Already listening */ + return kr_error(EADDRINUSE); /* Already listening */ } /* Parse address. */ diff --git a/daemon/network.h b/daemon/network.h index 7da4bb737..4832f4ceb 100644 --- a/daemon/network.h +++ b/daemon/network.h @@ -95,7 +95,7 @@ void network_deinit(struct network *net); /** Start listenting on addr#port with flags. * \note if we did listen on that combination already, - * nothing is done and kr_ok() is returned. + * nothing is done and kr_error(EADDRINUSE) is returned. * \note there's no short-hand to listen both on UDP and TCP. * \note ownership of flags.* is taken on success. TODO: non-success? */