From: Christopher Faulet Date: Wed, 13 Jan 2021 11:10:00 +0000 (+0100) Subject: MINOR: config: Add failifnotcap() to emit an alert on proxy capabilities X-Git-Tag: v2.4-dev6~61 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d4a83dd6b30a68605f13a447b398a15ab38f28d4;p=thirdparty%2Fhaproxy.git MINOR: config: Add failifnotcap() to emit an alert on proxy capabilities This function must be used to emit an alert if a proxy does not have at least one of the requested capabilities. An additional message may be appended to the alert. --- diff --git a/include/haproxy/cfgparse.h b/include/haproxy/cfgparse.h index 85bd164f67..ecb5ffd1e4 100644 --- a/include/haproxy/cfgparse.h +++ b/include/haproxy/cfgparse.h @@ -141,6 +141,31 @@ static inline int warnifnotcap(struct proxy *proxy, int cap, const char *file, i return 0; } +/* + * Sends an alert if proxy does not have at least one of the + * capabilities in . An optional may be added at the end + * of the alert to help the user. Returns 1 if an alert was emitted + * or 0 if the condition is valid. + */ +static inline int failifnotcap(struct proxy *proxy, int cap, const char *file, int line, const char *arg, const char *hint) +{ + char *msg; + + switch (cap) { + case PR_CAP_BE: msg = "no backend"; break; + case PR_CAP_FE: msg = "no frontend"; break; + case PR_CAP_BE|PR_CAP_FE: msg = "neither frontend nor backend"; break; + default: msg = "not enough"; break; + } + + if (!(proxy->cap & cap)) { + ha_alert("parsing [%s:%d] : '%s' not allowed because %s '%s' has %s capability.%s\n", + file, line, arg, proxy_type_str(proxy), proxy->id, msg, hint ? hint : ""); + return 1; + } + return 0; +} + /* simplified way to define a section parser */ #define REGISTER_CONFIG_SECTION(name, parse, post) \ INITCALL3(STG_REGISTER, cfg_register_section, (name), (parse), (post))