From 5c91d6294929b86105f16b96de5596a93be3ea68 Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Sun, 12 Jul 2020 21:39:21 +0200 Subject: Make sure listening to IPv4 and IPv6 at the same time works as intended --- minecproxy/server-proxy.c | 14 ++++++++++++-- minecproxy/server.c | 15 +++++++++++---- shared/config-parser.c | 5 ++++- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/minecproxy/server-proxy.c b/minecproxy/server-proxy.c index e486a73..ac41594 100644 --- a/minecproxy/server-proxy.c +++ b/minecproxy/server-proxy.c @@ -487,6 +487,14 @@ bool local_open(struct server_local *local) goto error; } + /* IPv4 and IPv6 sockets are handled separately */ + if (local->local.st.ss_family == AF_INET6) { + option = true; + if (setsockopt(sfd, IPPROTO_IPV6, IPV6_V6ONLY, &option, + sizeof(option)) < 0) + error("setsockopt: %m"); + } + /* The MC protocol expects the client to send data first */ if (cfg->socket_defer) { option = true; @@ -509,16 +517,18 @@ bool local_open(struct server_local *local) socket_set_low_latency(sfd, cfg->socket_keepalive, cfg->socket_iptos, cfg->socket_nodelay); + verbose("%s: attempting to bind to %s", local->server->scfg.name, + local->local.addrstr); r = bind(sfd, (struct sockaddr *)&local->local.st, local->local.addrlen); if (r < 0) { - error("bind: %m"); + error("bind(%s): %m", local->local.addrstr); goto error; } r = listen(sfd, 100); if (r < 0) { - error("listen: %m"); + error("listen(%s): %m", local->local.addrstr); goto error; } diff --git a/minecproxy/server.c b/minecproxy/server.c index 7a992d1..341a353 100644 --- a/minecproxy/server.c +++ b/minecproxy/server.c @@ -94,7 +94,8 @@ void server_delete_by_filename(const char *filename) /* FIXME: Share with minecctl */ static void server_dump(struct server *server) { - struct server_local *local; + struct server_local *listen; + struct saddr *local; struct saddr *remote; struct saddr *rcon; @@ -118,9 +119,15 @@ static void server_dump(struct server *server) verbose(" * Announce port: %" PRIu16, server->scfg.announce_port); if (!list_empty(&server->listenings)) { - verbose(" * Local:"); - list_for_each_entry(local, &server->listenings, list) - verbose(" * %s", local->local.addrstr); + verbose(" * Listening:"); + list_for_each_entry(listen, &server->listenings, list) + verbose(" * %s", listen->local.addrstr); + } + + if (!list_empty(&server->scfg.locals)) { + verbose(" * Locals:"); + list_for_each_entry(local, &server->scfg.locals, list) + verbose(" * %s", local->addrstr); } if (!list_empty(&server->scfg.remotes)) { diff --git a/shared/config-parser.c b/shared/config-parser.c index 8b43ada..8cb6dcd 100644 --- a/shared/config-parser.c +++ b/shared/config-parser.c @@ -155,8 +155,11 @@ static void scfg_queue_dns(struct server_config *scfg, struct cfg_value *value, switch (value->type) { case CFG_VAL_TYPE_ADDRS: - debug(DBG_DNS, "got sync results"); + debug(DBG_DNS, "%s: got sync results", scfg->name); list_for_each_entry_safe(saddr, tmp, &value->saddrs, list) { + debug(DBG_DNS, "%s: sync res %s, any_ok %s", + scfg->name, saddr->addrstr, + any_ok ? "yes" : "no"); list_del(&saddr->list); if (!any_ok) saddr_any_to_loopback(saddr); -- cgit v1.2.3