chiark / gitweb /
udp: Insist on only one successful default socket setup
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 25 Oct 2014 15:56:50 +0000 (16:56 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 25 Oct 2014 17:13:43 +0000 (18:13 +0100)
If we default the addresses to use, we only insist that at least one
of them can be successfully set up.

(This is particularly significant when upgrading an existing secnet
installation to the new secnet, with IPv6 support, but on a host with
no IPv6, and no address configured in the config file.  Without this
patch, secnet would fail to start up because it would try, and fail,
to bind the IPv6 address.)

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
udp.c

diff --git a/udp.c b/udp.c
index c526765..dde73ef 100644 (file)
--- a/udp.c
+++ b/udp.c
@@ -397,8 +397,14 @@ static void udp_phase_hook(void *sst, uint32_t new_phase)
     struct udpsocks *socks=&st->socks;
     struct udpcommon *uc=&st->uc;
     int i;
-    for (i=0; i<socks->n_socks; i++)
-       udp_make_socket(uc,&socks->socks[i],M_FATAL);
+    bool_t anydone=0;
+
+    for (i=0; i<socks->n_socks; i++) {
+       bool_t required=st->addr_configured
+           || (!anydone && i==socks->n_socks-1);
+       anydone += udp_make_socket(uc,&socks->socks[i],
+                                  required ? M_FATAL : M_WARNING);
+    }
 
     udp_socks_register(uc,socks, uc->use_proxy ? "proxy" : "socket");