]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: tools: report explicit address type selection
authorManu Nicolas <e.nicolas@criteo.com>
Tue, 1 Sep 2026 10:44:47 +0000 (10:44 +0000)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 1 Sep 2026 15:59:15 +0000 (17:59 +0200)
str2sa_range() reports the resulting socket and transport types through
net_addr_type. It does not tell callers whether these types came from
defaults or from an explicit prefix. Callers that need to distinguish
the two must duplicate the parser prefix list, which can fall out of
sync.

Add explicit_type and set it for prefixes that select a socket or
transport type. Family-only prefixes leave it unset. This has no effect
on existing callers.

include/haproxy/tools-t.h
src/tools.c

index 13cfe5d3f8c00cf409c19e30fbbe56e7752793d6..00f4598c82a3e26da4162d3c2ec4dde872d89a25 100644 (file)
@@ -156,8 +156,9 @@ struct net_addr {
 
 /* holds socket and xprt types for a given address */
 struct net_addr_type {
-       int proto_type; // socket layer
-       int xprt_type;  // transport layer
+       int proto_type;    /* socket layer */
+       int xprt_type;     /* transport layer */
+       int explicit_type; /* protocol or transport type was forced by a prefix */
 };
 
 /* An indexed file name node, to be used at various places where a config file
index 0a41c7a3cfc75318fd47efcfc74a0fbfecaecc99..24a40a4b13ee4fcbdb9d25f6f2861c48c113d3b9 100644 (file)
@@ -994,6 +994,7 @@ struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int
         * Currently, only MPTCP is defined as an alternate protocol for TCP
         */
        int alt_proto = 0;
+       int explicit_type = 0;
 
        portl = porth = porta = 0;
        if (fqdn)
@@ -1026,16 +1027,19 @@ struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int
                str2 += 7;
                proto_type = PROTO_TYPE_STREAM;
                ctrl_type = SOCK_STREAM;
+               explicit_type = 1;
        }
        else if (strncmp(str2, "dgram+", 6) == 0) {
                str2 += 6;
                proto_type = PROTO_TYPE_DGRAM;
                ctrl_type = SOCK_DGRAM;
+               explicit_type = 1;
        }
        else if (strncmp(str2, "quic+", 5) == 0) {
                str2 += 5;
                proto_type = PROTO_TYPE_DGRAM;
                ctrl_type = SOCK_STREAM;
+               explicit_type = 1;
        }
 
        if (strncmp(str2, "unix@", 5) == 0) {
@@ -1047,12 +1051,14 @@ struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int
                ss.ss_family = AF_UNIX;
                proto_type = PROTO_TYPE_DGRAM;
                ctrl_type = SOCK_DGRAM;
+               explicit_type = 1;
        }
        else if (strncmp(str2, "uxst@", 5) == 0) {
                str2 += 5;
                ss.ss_family = AF_UNIX;
                proto_type = PROTO_TYPE_STREAM;
                ctrl_type = SOCK_STREAM;
+               explicit_type = 1;
        }
        else if (strncmp(str2, "abns@", 5) == 0) {
                str2 += 5;
@@ -1079,6 +1085,7 @@ struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int
                ss.ss_family = AF_INET;
                proto_type = PROTO_TYPE_STREAM;
                ctrl_type = SOCK_STREAM;
+               explicit_type = 1;
        }
        else if (strncmp(str2, "mptcp4@", 7) == 0) {
                str2 += 7;
@@ -1086,18 +1093,21 @@ struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int
                proto_type = PROTO_TYPE_STREAM;
                ctrl_type = SOCK_STREAM;
                alt_proto = 1;
+               explicit_type = 1;
        }
        else if (strncmp(str2, "udp4@", 5) == 0) {
                str2 += 5;
                ss.ss_family = AF_INET;
                proto_type = PROTO_TYPE_DGRAM;
                ctrl_type = SOCK_DGRAM;
+               explicit_type = 1;
        }
        else if (strncmp(str2, "tcp6@", 5) == 0) {
                str2 += 5;
                ss.ss_family = AF_INET6;
                proto_type = PROTO_TYPE_STREAM;
                ctrl_type = SOCK_STREAM;
+               explicit_type = 1;
        }
        else if (strncmp(str2, "mptcp6@", 7) == 0) {
                str2 += 7;
@@ -1105,18 +1115,21 @@ struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int
                proto_type = PROTO_TYPE_STREAM;
                ctrl_type = SOCK_STREAM;
                alt_proto = 1;
+               explicit_type = 1;
        }
        else if (strncmp(str2, "udp6@", 5) == 0) {
                str2 += 5;
                ss.ss_family = AF_INET6;
                proto_type = PROTO_TYPE_DGRAM;
                ctrl_type = SOCK_DGRAM;
+               explicit_type = 1;
        }
        else if (strncmp(str2, "tcp@", 4) == 0) {
                str2 += 4;
                ss.ss_family = AF_UNSPEC;
                proto_type = PROTO_TYPE_STREAM;
                ctrl_type = SOCK_STREAM;
+               explicit_type = 1;
        }
        else if (strncmp(str2, "mptcp@", 6) == 0) {
                str2 += 6;
@@ -1124,24 +1137,28 @@ struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int
                proto_type = PROTO_TYPE_STREAM;
                ctrl_type = SOCK_STREAM;
                alt_proto = 1;
+               explicit_type = 1;
        }
        else if (strncmp(str2, "udp@", 4) == 0) {
                str2 += 4;
                ss.ss_family = AF_UNSPEC;
                proto_type = PROTO_TYPE_DGRAM;
                ctrl_type = SOCK_DGRAM;
+               explicit_type = 1;
        }
        else if (strncmp(str2, "quic4@", 6) == 0) {
                str2 += 6;
                ss.ss_family = AF_INET;
                proto_type = PROTO_TYPE_DGRAM;
                ctrl_type = SOCK_STREAM;
+               explicit_type = 1;
        }
        else if (strncmp(str2, "quic6@", 6) == 0) {
                str2 += 6;
                ss.ss_family = AF_INET6;
                proto_type = PROTO_TYPE_DGRAM;
                ctrl_type = SOCK_STREAM;
+               explicit_type = 1;
        }
        else if (strncmp(str2, "fd@", 3) == 0) {
                str2 += 3;
@@ -1449,6 +1466,7 @@ struct sockaddr_storage *str2sa_range(const char *str, int *port, int *low, int
        if (sa_type) {
                sa_type->proto_type = proto_type;
                sa_type->xprt_type = (ctrl_type == SOCK_DGRAM) ? PROTO_TYPE_DGRAM : PROTO_TYPE_STREAM;
+               sa_type->explicit_type = explicit_type;
        }
        if (alt)
                *alt = alt_proto;