Changeset: 8f73d344661d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8f73d344661d
Modified Files:
tools/merovingian/daemon/connections.c
tools/merovingian/daemon/connections.h
tools/merovingian/daemon/merovingian.c
Branch: Oct2020
Log Message:
Use same algorithm for determining IPv4/v6 in monetdbd as in mserver5.
localhost/all is both v4 and v6 (or whichever is available).
127.0.0.1/0.0.0.0 is only v4.
::1/:: is only v6.
hostname is whatever the system (DNS) tells us.
diffs (126 lines):
diff --git a/tools/merovingian/daemon/connections.c
b/tools/merovingian/daemon/connections.c
--- a/tools/merovingian/daemon/connections.c
+++ b/tools/merovingian/daemon/connections.c
@@ -25,7 +25,7 @@
#include "connections.h"
err
-openConnectionIP(int *socks, bool udp, bool bind_ipv6, const char *bindaddr,
unsigned short port, FILE *log)
+openConnectionIP(int *socks, bool udp, const char *bindaddr, unsigned short
port, FILE *log)
{
struct addrinfo *result = NULL, *rp = NULL;
int sock = -1, check = 0;
@@ -35,9 +35,10 @@ openConnectionIP(int *socks, bool udp, b
char host[512] = "";
int e = 0;
const char *msghost = bindaddr ? bindaddr : "any"; /* for messages */
+ int ipv6_vs6only = -1;
struct addrinfo hints = (struct addrinfo) {
- .ai_family = bind_ipv6 ? AF_INET6 : AF_INET,
+ .ai_family = AF_INET6,
.ai_socktype = udp ? SOCK_DGRAM : SOCK_STREAM,
.ai_flags = AI_PASSIVE | AI_NUMERICSERV,
.ai_protocol = udp ? 0 : IPPROTO_TCP,
@@ -46,6 +47,38 @@ openConnectionIP(int *socks, bool udp, b
socks[0] = socks[1] = -1;
+ if (bindaddr == NULL || strcmp(bindaddr, "localhost") == 0) {
+ hints.ai_family = AF_INET6;
+ hints.ai_flags |= AI_NUMERICHOST;
+ ipv6_vs6only = 0;
+ bindaddr = "::1";
+ strcpy_len(host, "localhost", sizeof(host));
+ } else if (strcmp(bindaddr, "all") == 0) {
+ hints.ai_family = AF_INET6;
+ ipv6_vs6only = 0;
+ bindaddr = NULL;
+ } else if (strcmp(bindaddr, "::") == 0) {
+ hints.ai_family = AF_INET6;
+ ipv6_vs6only = 1;
+ bindaddr = NULL;
+ } else if (strcmp(bindaddr, "0.0.0.0") == 0) {
+ hints.ai_family = AF_INET;
+ hints.ai_flags |= AI_NUMERICHOST;
+ bindaddr = NULL;
+ } else if (strcmp(bindaddr, "::1") == 0) {
+ hints.ai_family = AF_INET6;
+ hints.ai_flags |= AI_NUMERICHOST;
+ ipv6_vs6only = 1;
+ strcpy_len(host, "localhost", sizeof(host));
+ } else if (strcmp(bindaddr, "127.0.0.1") == 0) {
+ hints.ai_family = AF_INET;
+ hints.ai_flags |= AI_NUMERICHOST;
+ strcpy_len(host, "localhost", sizeof(host));
+ } else {
+ hints.ai_family = AF_INET6;
+ ipv6_vs6only = 0;
+ }
+
for (;;) { /* max twice */
check = getaddrinfo(bindaddr, sport, &hints, &result);
if (check != 0)
@@ -122,9 +155,12 @@ openConnectionIP(int *socks, bool udp, b
break; /* working */
}
freeaddrinfo(result);
- if (hints.ai_family == AF_INET6)
+ if (ipv6_vs6only == 0) {
+ ipv6_vs6only = -1;
hints.ai_family = AF_INET;
- else
+ if (bindaddr && strcmp(bindaddr, "::1") == 0)
+ bindaddr = "127.0.0.1";
+ } else
break;
}
diff --git a/tools/merovingian/daemon/connections.h
b/tools/merovingian/daemon/connections.h
--- a/tools/merovingian/daemon/connections.h
+++ b/tools/merovingian/daemon/connections.h
@@ -11,7 +11,7 @@
#include "merovingian.h"
-err openConnectionIP(int *socks, bool udp, bool use_ipv6, const char
*bindaddr, unsigned short port, FILE *log);
+err openConnectionIP(int *socks, bool udp, const char *bindaddr, unsigned
short port, FILE *log);
err openConnectionUNIX(int *ret, const char *path, int mode, FILE *log);
#endif
diff --git a/tools/merovingian/daemon/merovingian.c
b/tools/merovingian/daemon/merovingian.c
--- a/tools/merovingian/daemon/merovingian.c
+++ b/tools/merovingian/daemon/merovingian.c
@@ -350,7 +350,6 @@ main(int argc, char *argv[])
FILE *oerr = NULL;
int thret;
bool merodontfork = false;
- bool use_ipv6 = false;
confkeyval ckv[] = {
{"logfile", strdup("merovingian.log"), 0,
STR},
{"pidfile", strdup("merovingian.pid"), 0,
STR},
@@ -655,12 +654,6 @@ main(int argc, char *argv[])
}
host = kv->val;
- use_ipv6 = (strcmp(host, "127.0.0.1") != 0 && strcmp(host, "0.0.0.0")
!= 0);
-
- if (strcmp(host, "all") == 0) {
- host = NULL;
- }
-
kv = findConfKey(_mero_props, "port");
if (kv->ival <= 0 || kv->ival > 65535) {
Mfprintf(stderr, "invalid port number: %s, defaulting to %s\n",
@@ -970,9 +963,9 @@ main(int argc, char *argv[])
Mfprintf(stdout, "monitoring dbfarm %s\n", dbfarm);
/* open up connections */
- if ((e = openConnectionIP(socks, false, use_ipv6, host, port, stdout))
== NO_ERR &&
+ if ((e = openConnectionIP(socks, false, host, port, stdout)) == NO_ERR
&&
(e = openConnectionUNIX(&socks[2], mapi_usock, 0, stdout)) ==
NO_ERR &&
- (!discovery || (e = openConnectionIP(discsocks, true, use_ipv6,
host, port, _mero_discout)) == NO_ERR) &&
+ (!discovery || (e = openConnectionIP(discsocks, true, host,
port, _mero_discout)) == NO_ERR) &&
(e = openConnectionUNIX(&unsock, control_usock, S_IRWXO,
_mero_ctlout)) == NO_ERR) {
pthread_t ctid = 0;
pthread_t dtid = 0;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list