From: Willy Tarreau Date: Fri, 26 Mar 2021 11:03:11 +0000 (+0100) Subject: MINOR: sample: mark the truly constant sample fetch keywords as such X-Git-Tag: v2.4-dev14~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0209c970386d2d5e090f89d3e022d14896fc081d;p=thirdparty%2Fhaproxy.git MINOR: sample: mark the truly constant sample fetch keywords as such A number of keywords are really constant and safe to use at config time. This is the case for str(), int() etc but also env(), hostname(), nbproc() etc. By extension a few other ones which can be useful to preset values in a configuration were enabled as well, like data(), rand() or uuid(). At the moment this doesn't change anything as they are still only usable from runtime rules. The "var()" keyword was also marked as const as it can definitely return stable stuff at boot time. --- diff --git a/src/sample.c b/src/sample.c index 32255cb21a..1b2abfd816 100644 --- a/src/sample.c +++ b/src/sample.c @@ -4036,18 +4036,18 @@ static int smp_fetch_uuid(const struct arg *args, struct sample *smp, const char * instance IPv4/IPv6 must be declared IPv4. */ static struct sample_fetch_kw_list smp_kws = {ILH, { - { "always_false", smp_fetch_false, 0, NULL, SMP_T_BOOL, SMP_USE_INTRN }, - { "always_true", smp_fetch_true, 0, NULL, SMP_T_BOOL, SMP_USE_INTRN }, - { "env", smp_fetch_env, ARG1(1,STR), NULL, SMP_T_STR, SMP_USE_INTRN }, - { "date", smp_fetch_date, ARG2(0,SINT,STR), smp_check_date_unit, SMP_T_SINT, SMP_USE_INTRN }, - { "date_us", smp_fetch_date_us, 0, NULL, SMP_T_SINT, SMP_USE_INTRN }, - { "hostname", smp_fetch_hostname, 0, NULL, SMP_T_STR, SMP_USE_INTRN }, - { "nbproc", smp_fetch_nbproc,0, NULL, SMP_T_SINT, SMP_USE_INTRN }, - { "proc", smp_fetch_proc, 0, NULL, SMP_T_SINT, SMP_USE_INTRN }, - { "thread", smp_fetch_thread, 0, NULL, SMP_T_SINT, SMP_USE_INTRN }, - { "rand", smp_fetch_rand, ARG1(0,SINT), NULL, SMP_T_SINT, SMP_USE_INTRN }, + { "always_false", smp_fetch_false, 0, NULL, SMP_T_BOOL, SMP_USE_CONST }, + { "always_true", smp_fetch_true, 0, NULL, SMP_T_BOOL, SMP_USE_CONST }, + { "env", smp_fetch_env, ARG1(1,STR), NULL, SMP_T_STR, SMP_USE_CONST }, + { "date", smp_fetch_date, ARG2(0,SINT,STR), smp_check_date_unit, SMP_T_SINT, SMP_USE_CONST }, + { "date_us", smp_fetch_date_us, 0, NULL, SMP_T_SINT, SMP_USE_CONST }, + { "hostname", smp_fetch_hostname, 0, NULL, SMP_T_STR, SMP_USE_CONST }, + { "nbproc", smp_fetch_nbproc,0, NULL, SMP_T_SINT, SMP_USE_CONST }, + { "proc", smp_fetch_proc, 0, NULL, SMP_T_SINT, SMP_USE_CONST }, + { "thread", smp_fetch_thread, 0, NULL, SMP_T_SINT, SMP_USE_CONST }, + { "rand", smp_fetch_rand, ARG1(0,SINT), NULL, SMP_T_SINT, SMP_USE_CONST }, { "stopping", smp_fetch_stopping, 0, NULL, SMP_T_BOOL, SMP_USE_INTRN }, - { "uuid", smp_fetch_uuid, ARG1(0, SINT), smp_check_uuid, SMP_T_STR, SMP_USE_INTRN }, + { "uuid", smp_fetch_uuid, ARG1(0, SINT), smp_check_uuid, SMP_T_STR, SMP_USE_CONST }, { "cpu_calls", smp_fetch_cpu_calls, 0, NULL, SMP_T_SINT, SMP_USE_INTRN }, { "cpu_ns_avg", smp_fetch_cpu_ns_avg, 0, NULL, SMP_T_SINT, SMP_USE_INTRN }, @@ -4055,13 +4055,13 @@ static struct sample_fetch_kw_list smp_kws = {ILH, { { "lat_ns_avg", smp_fetch_lat_ns_avg, 0, NULL, SMP_T_SINT, SMP_USE_INTRN }, { "lat_ns_tot", smp_fetch_lat_ns_tot, 0, NULL, SMP_T_SINT, SMP_USE_INTRN }, - { "str", smp_fetch_const_str, ARG1(1,STR), NULL , SMP_T_STR, SMP_USE_INTRN }, - { "bool", smp_fetch_const_bool, ARG1(1,STR), smp_check_const_bool, SMP_T_BOOL, SMP_USE_INTRN }, - { "int", smp_fetch_const_int, ARG1(1,SINT), NULL , SMP_T_SINT, SMP_USE_INTRN }, - { "ipv4", smp_fetch_const_ipv4, ARG1(1,IPV4), NULL , SMP_T_IPV4, SMP_USE_INTRN }, - { "ipv6", smp_fetch_const_ipv6, ARG1(1,IPV6), NULL , SMP_T_IPV6, SMP_USE_INTRN }, - { "bin", smp_fetch_const_bin, ARG1(1,STR), smp_check_const_bin , SMP_T_BIN, SMP_USE_INTRN }, - { "meth", smp_fetch_const_meth, ARG1(1,STR), smp_check_const_meth, SMP_T_METH, SMP_USE_INTRN }, + { "str", smp_fetch_const_str, ARG1(1,STR), NULL , SMP_T_STR, SMP_USE_CONST }, + { "bool", smp_fetch_const_bool, ARG1(1,STR), smp_check_const_bool, SMP_T_BOOL, SMP_USE_CONST }, + { "int", smp_fetch_const_int, ARG1(1,SINT), NULL , SMP_T_SINT, SMP_USE_CONST }, + { "ipv4", smp_fetch_const_ipv4, ARG1(1,IPV4), NULL , SMP_T_IPV4, SMP_USE_CONST }, + { "ipv6", smp_fetch_const_ipv6, ARG1(1,IPV6), NULL , SMP_T_IPV6, SMP_USE_CONST }, + { "bin", smp_fetch_const_bin, ARG1(1,STR), smp_check_const_bin , SMP_T_BIN, SMP_USE_CONST }, + { "meth", smp_fetch_const_meth, ARG1(1,STR), smp_check_const_meth, SMP_T_METH, SMP_USE_CONST }, { /* END */ }, }}; diff --git a/src/vars.c b/src/vars.c index e71d7f1c0a..8690863e84 100644 --- a/src/vars.c +++ b/src/vars.c @@ -864,7 +864,7 @@ REGISTER_POST_DEINIT(vars_deinit); static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, { - { "var", smp_fetch_var, ARG1(1,STR), smp_check_var, SMP_T_STR, SMP_USE_INTRN }, + { "var", smp_fetch_var, ARG1(1,STR), smp_check_var, SMP_T_STR, SMP_USE_CONST }, { /* END */ }, }};