From: Willy Tarreau Date: Wed, 16 Sep 2020 18:35:12 +0000 (+0200) Subject: MEDIUM: tools: make str2sa_range() only report AF_CUST_UDP on listeners X-Git-Tag: v2.3-dev5~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3baec249b199048721299820f8543e8552fd98ee;p=thirdparty%2Fhaproxy.git 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 392a2bd1ae..fa546d3d3a 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -984,12 +984,6 @@ int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm) 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 a0898aadce..8e4606af3c 100644 --- a/src/log.c +++ b/src/log.c @@ -1028,12 +1028,6 @@ int parse_logsrv(char **args, struct list *logsrvs, int do_del, char **err) 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 0c4366408b..473de79df9 100644 --- a/src/tools.c +++ b/src/tools.c @@ -1151,13 +1151,17 @@ struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int } } 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)) {