]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: tools: make str2sa_range() use protocol_lookup()
authorWilly Tarreau <w@1wt.eu>
Wed, 16 Sep 2020 19:37:31 +0000 (21:37 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 16 Sep 2020 20:08:08 +0000 (22:08 +0200)
By doing so we can remove the hard-coded mapping from AF_INET to AF_CUST_UDP
but we still need to keep the test on the listeners as long as these dummy
families remain present in the code.

src/tools.c

index c4bc821fabeed9ca53627077015c685fd93e93e3..54cf2d644b64a3afff8451cace3a62c03790d0be 100644 (file)
@@ -1164,25 +1164,23 @@ struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int
                goto out;
        }
 
-       if (opts & PA_O_SOCKET_FD && sock_type == SOCK_DGRAM && ctrl_type == SOCK_DGRAM) {
-               /* 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 if (ss.ss_family == AF_INET)
-                       ss.ss_family = AF_CUST_UDP4;
-       }
-
        if (proto || (opts & PA_O_CONNECT)) {
                /* Note: if the caller asks for a proto, we must find one,
                 * except if we return with an fqdn that will resolve later,
                 * in which case the address is not known yet (this is only
                 * for servers actually).
                 */
-               new_proto = protocol_by_family(ss.ss_family);
+
+               /* 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.
+                * This effectively means that for now we return TCPv4/v6 for UDP senders.
+                */
+               new_proto = protocol_lookup(ss.ss_family,
+                                           (opts & PA_O_SOCKET_FD) && sock_type == SOCK_DGRAM,
+                                           (opts & PA_O_SOCKET_FD) && ctrl_type == SOCK_DGRAM);
+
                if (!new_proto && (!fqdn || !*fqdn)) {
                        memprintf(err, "unsupported protocol family %d for address '%s'", ss.ss_family, str);
                        goto out;