MEDIUM: tools: make str2sa_range() only report AF_CUST_UDP on listeners
For now only listeners can make use of AF_CUST_UDP and it requires hacks
in the DNS and logsrv code to remap it to AF_INET. Make str2sa_range()
smarter by detecting that it's called for a listener and only set these
protocol families for listeners. This way we can get rid of the hacks.
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 392a2bd..fa546d3 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -984,12 +984,6 @@
goto out;
}
- /* handle nicely the case where "udp@" is forced */
- if (sk->ss_family == AF_CUST_UDP4)
- sk->ss_family = AF_INET;
- else if (sk->ss_family == AF_CUST_UDP6)
- sk->ss_family = AF_INET6;
-
proto = protocol_by_family(sk->ss_family);
if (!proto) {
ha_alert("parsing [%s:%d] : '%s %s' : connect() not supported for this address family.\n",
diff --git a/src/log.c b/src/log.c
index a0898aa..8e4606a 100644
--- a/src/log.c
+++ b/src/log.c
@@ -1028,12 +1028,6 @@
logsrv->type = LOG_TARGET_FD;
logsrv->addr = *sk;
- /* handle nicely the case where "udp@" is forced */
- if (sk->ss_family == AF_CUST_UDP4)
- sk->ss_family = AF_INET;
- else if (sk->ss_family == AF_CUST_UDP6)
- sk->ss_family = AF_INET6;
-
if (sk->ss_family == AF_INET || sk->ss_family == AF_INET6) {
logsrv->addr = *sk;
if (!port1)
diff --git a/src/tools.c b/src/tools.c
index 0c43664..473de79 100644
--- a/src/tools.c
+++ b/src/tools.c
@@ -1151,13 +1151,17 @@
}
}
set_host_port(&ss, porta);
- if (is_udp) {
+ if (is_udp && opts & PA_O_SOCKET_FD) {
+ /* FIXME: for now UDP is still its own family. However some UDP clients
+ * (logs, dns) use AF_INET and are not aware of AF_CUST_UDP*. Since we
+ * only want this mapping for listeners and they are the only ones
+ * setting PA_O_SOCKET_FD, for now we condition this mapping to this.
+ */
if (ss.ss_family == AF_INET6)
ss.ss_family = AF_CUST_UDP6;
else
ss.ss_family = AF_CUST_UDP4;
}
-
}
if (ctrl_type == SOCK_STREAM && !(opts & PA_O_STREAM)) {