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.
This commit is contained in:
Willy Tarreau 2021-10-27 17:41:07 +02:00
parent e3b4518414
commit 14e7f29e86
6 changed files with 7 additions and 16 deletions

View 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.

View 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;

View 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);

View 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);

View 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;

View 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)