From 5fc311c00198accbd60ab5e988d379034998205f Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Sun, 2 Dec 2018 13:04:43 +0100 Subject: [PATCH] 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 argument is never used anymore so this part is eligible to some cleanup. --- include/proto/connection.h | 43 ++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/include/proto/connection.h b/include/proto/connection.h index 696432280..e2fae5f8f 100644 --- a/include/proto/connection.h +++ b/include/proto/connection.h @@ -930,6 +930,33 @@ static inline void list_mux_proto(FILE *out) } } +/* returns the first mux entry in the list matching the exact same + * and compatible with the (FE or BE) and the (TCP or + * HTTP). can be empty. Will fall back to the first compatible mux + * with exactly the same 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_proto_list *conn_get_best_mux_entry( + const struct ist mux_proto, + int proto_side, int proto_mode) +{ + struct mux_proto_list *item; + struct mux_proto_list *fallback = NULL; + + list_for_each_entry(item, &mux_proto_list.list, list) { + if (!(item->side & proto_side) || !(item->mode & proto_mode)) + continue; + if (istlen(mux_proto) && isteq(mux_proto, item->token)) + return item; + else if (!istlen(item->token)) { + if (!fallback || (item->mode == proto_mode && fallback->mode != proto_mode)) + fallback = item; + } + } + return fallback; + +} + /* returns the first mux in the list matching the exact same and * compatible with the (FE or BE) and the (TCP or * HTTP). can be empty. Will fall back to the first compatible mux @@ -940,21 +967,11 @@ static inline const struct mux_ops *conn_get_best_mux(struct connection *conn, const struct ist mux_proto, int proto_side, int proto_mode) { - struct mux_proto_list *item; - struct mux_proto_list *fallback = NULL; + const struct mux_proto_list *item; - list_for_each_entry(item, &mux_proto_list.list, list) { - if (!(item->side & proto_side) || !(item->mode & proto_mode)) - continue; - if (istlen(mux_proto) && isteq(mux_proto, item->token)) - return item->mux; - else if (!istlen(item->token)) { - if (!fallback || (item->mode == proto_mode && fallback->mode != proto_mode)) - fallback = item; - } - } - return (fallback ? fallback->mux : NULL); + 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