]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: protocols: replace protocol_by_family() with protocol_lookup()
authorWilly Tarreau <w@1wt.eu>
Wed, 27 Oct 2021 15:41:07 +0000 (17:41 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 27 Oct 2021 15:41:07 +0000 (17:41 +0200)
At a few places we were still using protocol_by_family() instead of
the richer protocol_lookup(). The former is limited as it enforces
SOCK_STREAM and a stream protocol at the control layer. At least with
protocol_lookup() we don't have this limitationn. The values were still
set for now but later we can imagine making them configurable on the
fly.

include/haproxy/protocol.h
src/backend.c
src/cfgparse.c
src/resolvers.c
src/server.c
src/tcpcheck.c

index 0c52bf705b961b5c83983e57d20a828b90e58548..05bba78d968018b1942f795ce8d5941aed8b1ee8 100644 (file)
@@ -76,16 +76,6 @@ int protocol_resume_all(void);
  */
 int protocol_enable_all(void);
 
-/* returns the protocol associated to family <family> with sock_type and
- * ctrl_type of SOCK_STREAM, or NULL if not found
- */
-static inline struct protocol *protocol_by_family(int family)
-{
-       if (family >= 0 && family < AF_CUST_MAX)
-               return __protocol_by_family[family][0][0];
-       return NULL;
-}
-
 /* returns the protocol associated to family <family> with proto_type among the
  * supported protocol types, and ctrl_type of either SOCK_STREAM or SOCK_DGRAM
  * depending on the requested values, or NULL if not found.
index f170cb4f12ab0d14feb2f88d8c908211000db74e..ee6e2b840c198117b1dcf239965e072e6b0a18d5 100644 (file)
@@ -1542,7 +1542,7 @@ skip_reuse:
        if (!srv_conn->xprt) {
                /* set the correct protocol on the output stream interface */
                if (srv) {
-                       if (conn_prepare(srv_conn, protocol_by_family(srv_conn->dst->ss_family), srv->xprt)) {
+                       if (conn_prepare(srv_conn, protocol_lookup(srv_conn->dst->ss_family, PROTO_TYPE_STREAM, 0), srv->xprt)) {
                                conn_free(srv_conn);
                                return SF_ERR_INTERNAL;
                        }
@@ -1550,7 +1550,7 @@ skip_reuse:
                        int ret;
 
                        /* proxies exclusively run on raw_sock right now */
-                       ret = conn_prepare(srv_conn, protocol_by_family(srv_conn->dst->ss_family), xprt_get(XPRT_RAW));
+                       ret = conn_prepare(srv_conn, protocol_lookup(srv_conn->dst->ss_family, PROTO_TYPE_STREAM, 0), xprt_get(XPRT_RAW));
                        if (ret < 0 || !(srv_conn->ctrl)) {
                                conn_free(srv_conn);
                                return SF_ERR_INTERNAL;
index ed5efda6d81dc80566bf1f264dea27f048d679f6..58067c8edfe35e66c9a6ee6d563ab1f64bc58564 100644 (file)
@@ -918,7 +918,7 @@ int cfg_parse_peers(const char *file, int linenum, char **args, int kwm)
                 */
                if (peer || !local_peer) {
                        newpeer->addr = curpeers->peers_fe->srv->addr;
-                       newpeer->proto = protocol_by_family(newpeer->addr.ss_family);
+                       newpeer->proto = protocol_lookup(newpeer->addr.ss_family, PROTO_TYPE_STREAM, 0);
                }
 
                newpeer->xprt  = xprt_get(XPRT_RAW);
index a8d374e10a1f198ac752f67fe407959cd82be890..a806f3397dfce84288af461d86bf6ad241278dab 100644 (file)
@@ -3417,7 +3417,7 @@ int cfg_parse_resolvers(const char *file, int linenum, char **args, int kwm)
 
                        set_host_port(sk, 53);
 
-                       proto = protocol_by_family(sk->ss_family);
+                       proto = protocol_lookup(sk->ss_family, PROTO_TYPE_STREAM, 0);
                        if (!proto || !proto->connect) {
                                ha_warning("parsing [/etc/resolv.conf:%d] : '%s' : connect() not supported for this address family.\n",
                                           resolv_linenum, address);
index f74bb5cb7f1e70503c278167f74904fb1190c7f8..7b702f5b08439613b43473bf445892f5fa34e2af 100644 (file)
@@ -2558,7 +2558,8 @@ static int _srv_parse_init(struct server **srv, char **args, int *cur_arg,
                 */
                srv_set_addr_desc(newsrv, !(parse_flags & SRV_PARSE_DYNAMIC));
 
-               if (!newsrv->srvrq && !newsrv->hostname && !protocol_by_family(newsrv->addr.ss_family)) {
+               if (!newsrv->srvrq && !newsrv->hostname &&
+                   !protocol_lookup(newsrv->addr.ss_family, PROTO_TYPE_STREAM, 0)) {
                        ha_alert("Unknown protocol family %d '%s'\n",
                                 newsrv->addr.ss_family, args[*cur_arg]);
                        err_code |= ERR_ALERT | ERR_FATAL;
index 133dfe5c090aba9cf66914c69e48a9ec8b80bfe3..14f83eae09e821abf1cf7adb8b12dbff6a087e06 100644 (file)
@@ -1125,7 +1125,7 @@ enum tcpcheck_eval_ret tcpcheck_eval_connect(struct check *check, struct tcpchec
        *conn->dst = (is_addr(&connect->addr)
                      ? connect->addr
                      : (is_addr(&check->addr) ? check->addr : s->addr));
-       proto = protocol_by_family(conn->dst->ss_family);
+       proto = protocol_lookup(conn->dst->ss_family, PROTO_TYPE_STREAM, 0);
 
        port = 0;
        if (connect->port)