]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
rrdcached: support wildcard listen specifications
authorPeter A. Bigot <pab@pabigot.com>
Mon, 19 May 2014 19:47:44 +0000 (14:47 -0500)
committerPeter A. Bigot <pab@pabigot.com>
Tue, 20 May 2014 15:11:18 +0000 (10:11 -0500)
The documentation suggested that the syntax "-l :42217" would cause the
daemon to listen on all available interfaces.  The implementation didn't
follow through, until now.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
doc/rrdcached.pod
src/rrd_daemon.c

index 04b075e8df1a81a2ab0751012ac4451e5e313065..58c34f71c358b9f5addd170d1e30a7134a56d58f 100644 (file)
@@ -43,7 +43,7 @@ section below.
 
 =item B<-l> I<address>
 
-Tells the daemon to bind to I<address> and accept incoming connections on that
+Tells the daemon to bind to I<address> and accept incoming TCP connections on that
 socket. If I<address> begins with C<unix:>, everything following that prefix is
 interpreted as the path to a UNIX domain socket. Otherwise the address or node
 name are resolved using C<getaddrinfo()>.
@@ -52,7 +52,7 @@ For network sockets, a port may be specified by using the form
 C<B<[>I<address>B<]:>I<port>>. If the address is an IPv4 address or a fully
 qualified domain name (i.E<nbsp>e. the address contains at least one dot
 (C<.>)), the square brackets can be omitted, resulting in the (simpler)
-C<I<address>B<:>I<port>> pattern. The default port is B<42217/tcp>. If you
+C<I<address>B<:>I<port>> pattern. The default port is B<42217>. If you
 specify a network socket, it is mandatory to read the
 L</"SECURITY CONSIDERATIONS"> section.
 
@@ -65,8 +65,12 @@ domain socket B<must> start with a slash in the second case!
    [<hostname-or-ip>]:<port>
    <hostname-or-ipv4>:<port>
 
-If the B<-l> option is not specified the default address,
+Given a port without a host (e.g. C<-l :42217>) the daemon will listen
+on that port on all network interfaces.
+
+If no B<-l> option is not specified the default address,
 C<unix:/tmp/rrdcached.sock>, will be used.
+Multiple B<-l> options may be provided.
 
 =item B<-s> I<group_name>|I<gid>
 
index 2e8e0489b070bcbea20b074e5d01ca09c72b44e1..742d258f3478e10d44ce1a6c74a30ed3b7b38629 100644 (file)
@@ -92,6 +92,7 @@
 #include <signal.h>
 #include <sys/un.h>
 #include <netdb.h>
+#include <arpa/inet.h>
 #include <poll.h>
 #include <syslog.h>
 #include <pthread.h>
@@ -2951,6 +2952,7 @@ static int open_listen_socket_network(const listen_socket_t *sock) /* {{{ */
   char addr_copy[NI_MAXHOST];
   char *addr;
   char *port;
+  int addr_is_wildcard = 0;
   int status;
 
   strncpy (addr_copy, sock->addr, sizeof(addr_copy)-1);
@@ -2999,8 +3001,14 @@ static int open_listen_socket_network(const listen_socket_t *sock) /* {{{ */
       port++;
     }
   }
+  /* Empty string for address should be treated as wildcard (open on
+   * all interfaces) */
+  addr_is_wildcard = (0 == *addr);
+  if (addr_is_wildcard)
+    ai_hints.ai_flags |= AI_PASSIVE;
+
   ai_res = NULL;
-  status = getaddrinfo (addr,
+  status = getaddrinfo (addr_is_wildcard ? NULL : addr,
                         port == NULL ? RRDCACHED_DEFAULT_PORT : port,
                         &ai_hints, &ai_res);
   if (status != 0)
@@ -3036,6 +3044,12 @@ static int open_listen_socket_network(const listen_socket_t *sock) /* {{{ */
     }
 
     setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
+#ifdef IPV6_V6ONLY
+    /* Prevent EADDRINUSE bind errors on dual-stack configurations
+     * with IPv4-mapped-on-IPv6 enabled */
+    if (AF_INET6 == ai_ptr->ai_family)
+      setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &one, sizeof(one));
+#endif /* IPV6_V6ONLY */
 
     status = bind (fd, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
     if (status != 0)