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 0c52bf7..05bba78 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 f170cb4..ee6e2b8 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 ed5efda..58067c8 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 a8d374e..a806f33 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 f74bb5c..7b702f5 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 133dfe5..14f83ea 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)