From: Willy Tarreau Date: Wed, 27 Oct 2021 15:41:07 +0000 (+0200) Subject: MINOR: protocols: replace protocol_by_family() with protocol_lookup() X-Git-Tag: v2.5-dev12~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=14e7f29e8655fa1ae2f9d409a135cbc07abb75da;p=thirdparty%2Fhaproxy.git MINOR: protocols: replace protocol_by_family() with protocol_lookup() 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. --- diff --git a/include/haproxy/protocol.h b/include/haproxy/protocol.h index 0c52bf705b..05bba78d96 100644 --- a/include/haproxy/protocol.h +++ b/include/haproxy/protocol.h @@ -76,16 +76,6 @@ int protocol_resume_all(void); */ int protocol_enable_all(void); -/* returns the protocol associated to 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 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. diff --git a/src/backend.c b/src/backend.c index f170cb4f12..ee6e2b840c 100644 --- a/src/backend.c +++ b/src/backend.c @@ -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; diff --git a/src/cfgparse.c b/src/cfgparse.c index ed5efda6d8..58067c8edf 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -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); diff --git a/src/resolvers.c b/src/resolvers.c index a8d374e10a..a806f3397d 100644 --- a/src/resolvers.c +++ b/src/resolvers.c @@ -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); diff --git a/src/server.c b/src/server.c index f74bb5cb7f..7b702f5b08 100644 --- a/src/server.c +++ b/src/server.c @@ -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; diff --git a/src/tcpcheck.c b/src/tcpcheck.c index 133dfe5c09..14f83eae09 100644 --- a/src/tcpcheck.c +++ b/src/tcpcheck.c @@ -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)