mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 07:37:02 +02:00
MINOR: cfgcond: Implement enabled condition expression
Implement a way to test if some options are enabled at run-time. For now, following options may be detected: POLL, EPOLL, KQUEUE, EVPORTS, SPLICE, GETADDRINFO, REUSEPORT, FAST-FORWARD, SERVER-SSL-VERIFY-NONE These options are those that can be disabled on the command line. This way it is possible, from a reg-test for instance, to know if a feature is supported or not : feature cmd "$HAPROXY_PROGRAM -cc '!(globa.tune & GTUNE_NO_FAST_FWD)'"
This commit is contained in:
parent
a1fdad784b
commit
c13f3028e8
@ -877,6 +877,12 @@ The list of currently supported predicates is the following:
|
|||||||
version syntax is the same as shown by "haproxy -v"
|
version syntax is the same as shown by "haproxy -v"
|
||||||
and missing components are assumed as being zero.
|
and missing components are assumed as being zero.
|
||||||
|
|
||||||
|
- enabled(<opt>) : returns true if the option <opt> is enabled at
|
||||||
|
run-time. Only a subset of options are supported:
|
||||||
|
POLL, EPOLL, KQUEUE, EVPORTS, SPLICE,
|
||||||
|
GETADDRINFO, REUSEPORT, FAST-FORWARD,
|
||||||
|
SERVER-SSL-VERIFY-NONE
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
.if defined(HAPROXY_MWORKER)
|
.if defined(HAPROXY_MWORKER)
|
||||||
|
@ -54,6 +54,7 @@ enum cond_predicate {
|
|||||||
CFG_PRED_OSSL_VERSION_ATLEAST, // "openssl_version_atleast"
|
CFG_PRED_OSSL_VERSION_ATLEAST, // "openssl_version_atleast"
|
||||||
CFG_PRED_OSSL_VERSION_BEFORE, // "openssl_version_before"
|
CFG_PRED_OSSL_VERSION_BEFORE, // "openssl_version_before"
|
||||||
CFG_PRED_SSLLIB_NAME_STARTSWITH, // "ssllib_name_startswith"
|
CFG_PRED_SSLLIB_NAME_STARTSWITH, // "ssllib_name_startswith"
|
||||||
|
CFG_PRED_ENABLED, // "enabled"
|
||||||
};
|
};
|
||||||
|
|
||||||
/* types for condition terms */
|
/* types for condition terms */
|
||||||
|
@ -28,6 +28,7 @@ const struct cond_pred_kw cond_predicates[] = {
|
|||||||
{ "openssl_version_atleast", CFG_PRED_OSSL_VERSION_ATLEAST, ARG1(1, STR) },
|
{ "openssl_version_atleast", CFG_PRED_OSSL_VERSION_ATLEAST, ARG1(1, STR) },
|
||||||
{ "openssl_version_before", CFG_PRED_OSSL_VERSION_BEFORE, ARG1(1, STR) },
|
{ "openssl_version_before", CFG_PRED_OSSL_VERSION_BEFORE, ARG1(1, STR) },
|
||||||
{ "ssllib_name_startswith", CFG_PRED_SSLLIB_NAME_STARTSWITH, ARG1(1, STR) },
|
{ "ssllib_name_startswith", CFG_PRED_SSLLIB_NAME_STARTSWITH, ARG1(1, STR) },
|
||||||
|
{ "enabled", CFG_PRED_ENABLED, ARG1(1, STR) },
|
||||||
{ NULL, CFG_PRED_NONE, 0 }
|
{ NULL, CFG_PRED_NONE, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -175,6 +176,33 @@ int cfg_parse_cond_term(const char **text, struct cfg_cond_term **term, char **e
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* evaluate a "enabled" expression. Only a subset of options are matched. It
|
||||||
|
* returns 1 if the option is enabled. 0 is returned is the option is not
|
||||||
|
* enabled or if it is not recognized.
|
||||||
|
*/
|
||||||
|
static int cfg_eval_cond_enabled(const char *str)
|
||||||
|
{
|
||||||
|
if (strcmp(str, "POLL") == 0)
|
||||||
|
return !!(global.tune.options & GTUNE_USE_POLL);
|
||||||
|
else if (strcmp(str, "EPOLL") == 0)
|
||||||
|
return !!(global.tune.options & GTUNE_USE_EPOLL);
|
||||||
|
else if (strcmp(str, "KQUEUE") == 0)
|
||||||
|
return !!(global.tune.options & GTUNE_USE_EPOLL);
|
||||||
|
else if (strcmp(str, "EVPORTS") == 0)
|
||||||
|
return !!(global.tune.options & GTUNE_USE_EVPORTS);
|
||||||
|
else if (strcmp(str, "SPLICE") == 0)
|
||||||
|
return !!(global.tune.options & GTUNE_USE_SPLICE);
|
||||||
|
else if (strcmp(str, "GETADDRINFO") == 0)
|
||||||
|
return !!(global.tune.options & GTUNE_USE_GAI);
|
||||||
|
else if (strcmp(str, "REUSEPORT") == 0)
|
||||||
|
return !!(global.tune.options & GTUNE_USE_REUSEPORT);
|
||||||
|
else if (strcmp(str, "FAST-FORWARD") == 0)
|
||||||
|
return !!(global.tune.options & GTUNE_USE_FAST_FWD);
|
||||||
|
else if (strcmp(str, "SERVER-SSL-VERIFY-NONE") == 0)
|
||||||
|
return !!(global.ssl_server_verify == SSL_SERVER_VERIFY_NONE);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* evaluate a condition term on a .if/.elif line. The condition was already
|
/* evaluate a condition term on a .if/.elif line. The condition was already
|
||||||
* parsed in <term>. Returns -1 on error (in which case err is filled with a
|
* parsed in <term>. Returns -1 on error (in which case err is filled with a
|
||||||
* message, and only in this case), 0 if the condition is false, 1 if it's
|
* message, and only in this case), 0 if the condition is false, 1 if it's
|
||||||
@ -260,6 +288,10 @@ int cfg_eval_cond_term(const struct cfg_cond_term *term, char **err)
|
|||||||
ret = openssl_compare_current_name(term->args[0].data.str.area) == 0;
|
ret = openssl_compare_current_name(term->args[0].data.str.area) == 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case CFG_PRED_ENABLED: { // checks if the arg matches on a subset of enabled options
|
||||||
|
ret = cfg_eval_cond_enabled(term->args[0].data.str.area) != 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
memprintf(err, "internal error: unhandled conditional expression predicate '%s'", term->pred->word);
|
memprintf(err, "internal error: unhandled conditional expression predicate '%s'", term->pred->word);
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user