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 0c52bf7..05bba78 100644
--- a/include/haproxy/protocol.h
+++ b/include/haproxy/protocol.h
@@ -76,16 +76,6 @@
*/
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.
diff --git a/src/backend.c b/src/backend.c
index f170cb4..ee6e2b8 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -1542,7 +1542,7 @@
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 @@
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 ed5efda..58067c8 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -918,7 +918,7 @@
*/
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 a8d374e..a806f33 100644
--- a/src/resolvers.c
+++ b/src/resolvers.c
@@ -3417,7 +3417,7 @@
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 f74bb5c..7b702f5 100644
--- a/src/server.c
+++ b/src/server.c
@@ -2558,7 +2558,8 @@
*/
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 133dfe5..14f83ea 100644
--- a/src/tcpcheck.c
+++ b/src/tcpcheck.c
@@ -1125,7 +1125,7 @@
*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)