MINOR: connection: create conn_get_best_mux_entry()

We currently have conn_get_best_mux() to return the best mux for a
given protocol name, side and proxy mode. But we need the mux entry
as well in order to fix the bind_conf and servers at the end of the
config parsing. Let's split the function in two parts. It's worth
noting that the <conn> argument is never used anymore so this part
is eligible to some cleanup.
This commit is contained in:
Willy Tarreau 2018-12-02 13:04:43 +01:00
parent a004ae3e66
commit 5fc311c001

View File

@ -930,13 +930,13 @@ static inline void list_mux_proto(FILE *out)
} }
} }
/* returns the first mux in the list matching the exact same <mux_proto> and /* returns the first mux entry in the list matching the exact same <mux_proto>
* compatible with the <proto_side> (FE or BE) and the <proto_mode> (TCP or * and compatible with the <proto_side> (FE or BE) and the <proto_mode> (TCP or
* HTTP). <mux_proto> can be empty. Will fall back to the first compatible mux * HTTP). <mux_proto> can be empty. Will fall back to the first compatible mux
* with exactly the same <proto_mode> or with an empty name. May return * with exactly the same <proto_mode> or with an empty name. May return
* null if the code improperly registered the default mux to use as a fallback. * null if the code improperly registered the default mux to use as a fallback.
*/ */
static inline const struct mux_ops *conn_get_best_mux(struct connection *conn, static inline const struct mux_proto_list *conn_get_best_mux_entry(
const struct ist mux_proto, const struct ist mux_proto,
int proto_side, int proto_mode) int proto_side, int proto_mode)
{ {
@ -947,16 +947,33 @@ static inline const struct mux_ops *conn_get_best_mux(struct connection *conn,
if (!(item->side & proto_side) || !(item->mode & proto_mode)) if (!(item->side & proto_side) || !(item->mode & proto_mode))
continue; continue;
if (istlen(mux_proto) && isteq(mux_proto, item->token)) if (istlen(mux_proto) && isteq(mux_proto, item->token))
return item->mux; return item;
else if (!istlen(item->token)) { else if (!istlen(item->token)) {
if (!fallback || (item->mode == proto_mode && fallback->mode != proto_mode)) if (!fallback || (item->mode == proto_mode && fallback->mode != proto_mode))
fallback = item; fallback = item;
} }
} }
return (fallback ? fallback->mux : NULL); return fallback;
} }
/* returns the first mux in the list matching the exact same <mux_proto> and
* compatible with the <proto_side> (FE or BE) and the <proto_mode> (TCP or
* HTTP). <mux_proto> can be empty. Will fall back to the first compatible mux
* with exactly the same <proto_mode> or with an empty name. May return
* null if the code improperly registered the default mux to use as a fallback.
*/
static inline const struct mux_ops *conn_get_best_mux(struct connection *conn,
const struct ist mux_proto,
int proto_side, int proto_mode)
{
const struct mux_proto_list *item;
item = conn_get_best_mux_entry(mux_proto, proto_side, proto_mode);
return item ? item->mux : NULL;
}
/* returns 0 if the connection is valid and is a frontend connection, otherwise /* returns 0 if the connection is valid and is a frontend connection, otherwise
* returns 1 indicating it's a backend connection. And uninitialized connection * returns 1 indicating it's a backend connection. And uninitialized connection
* also returns 1 to better handle the usage in the middle of initialization. * also returns 1 to better handle the usage in the middle of initialization.