]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tools: remove the central test for "udp" in str2sa_range()
authorWilly Tarreau <w@1wt.eu>
Wed, 16 Sep 2020 13:20:59 +0000 (15:20 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 16 Sep 2020 20:08:08 +0000 (22:08 +0200)
Now we only rely on dgram type associated with AF_INET/AF_INET6 to infer
UDP4/UDP6. We still keep the hint based on PA_O_SOCKET_FD to detect that
the caller is a listener though. It's still far from optimal but UDP
remains rooted into the protocols and needs to be taken out first.

src/tools.c

index 473de79df9b71ad36fd38bea11233c6384694784..0f0bbae80a494f7af72fbfa6304007cb21a4db8c 100644 (file)
@@ -875,7 +875,6 @@ struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int
        char *port1, *port2;
        int portl, porth, porta;
        int abstract = 0;
-       int is_udp = 0;
        int new_fd = -1;
        int sock_type, ctrl_type;
 
@@ -933,19 +932,16 @@ struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int
                str2 += 5;
                ss.ss_family = AF_INET;
                sock_type = ctrl_type = SOCK_DGRAM;
-               is_udp = 1;
        }
        else if (strncmp(str2, "udp6@", 5) == 0) {
                str2 += 5;
                ss.ss_family = AF_INET6;
                sock_type = ctrl_type = SOCK_DGRAM;
-               is_udp = 1;
        }
        else if (strncmp(str2, "udp@", 4) == 0) {
                str2 += 4;
                ss.ss_family = AF_UNSPEC;
                sock_type = ctrl_type = SOCK_DGRAM;
-               is_udp = 1;
        }
        else if (strncmp(str2, "fd@", 3) == 0) {
                str2 += 3;
@@ -1151,17 +1147,6 @@ struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int
                        }
                }
                set_host_port(&ss, porta);
-               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)) {
@@ -1173,6 +1158,18 @@ 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;
+       }
+
        ret = &ss;
  out:
        if (port)