From: Alan T. DeKok Date: Wed, 25 Oct 2023 20:52:59 +0000 (-0400) Subject: allow local variables in redundant and load-balance X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8f733814799b52fc2f91ed614587f7ee1bea286b;p=thirdparty%2Ffreeradius-server.git allow local variables in redundant and load-balance --- diff --git a/doc/antora/modules/reference/pages/unlang/local.adoc b/doc/antora/modules/reference/pages/unlang/local.adoc index de25bde0e60..80efd608f79 100644 --- a/doc/antora/modules/reference/pages/unlang/local.adoc +++ b/doc/antora/modules/reference/pages/unlang/local.adoc @@ -16,7 +16,23 @@ section (i.e. scope), and cannot be sent in a packet over the network. } ---- -:: One of xref:unlang/case.adoc[case], xref:unlang/else.adoc[else], xref:unlang/elsif.adoc[elsif], xref:unlang/foreach.adoc[foreach], xref:unlang/group.adoc[group], xref:unlang/if.adoc[if] ,xref:unlang/limit.adoc[limit], or xref:unlang/timeout.adoc[timeout]. Local variables are forbidden in all other locations. +:: An `unlang` keywords which does not create create a subrequest. i.e. One of: + +* xref:unlang/case.adoc[case] +* xref:unlang/else.adoc[else] +* xref:unlang/elsif.adoc[elsif] +* xref:unlang/foreach.adoc[foreach] +* xref:unlang/group.adoc[group] +* xref:unlang/if.adoc[if] +* xref:unlang/limit.adoc[limit] +* xref:unlang/load-balance.adoc[load-balance] +* xref:unlang/redundant.adoc[redundant] +* xref:unlang/redundant-load-balance.adoc[redundant-load-balance] +* xref:unlang/timeout.adoc[timeout] + +Local variables are forbidden in all other locations. + +For the xref:unlang/redundant.adoc[redundant] and unlang/redundant-load-balance.adoc[redundant-load-balance] keyword, local variables are keep their value across the different subsections. This behavior can be used to track state inside of the xref:unlang/redundant.adoc[redundant] section. :: A "leaf" xref:type/all_types.adoc[data type]. Structural types such as `group`, `struct`, `tlv`, etc. are not allowed. diff --git a/src/lib/unlang/compile.c b/src/lib/unlang/compile.c index 7f8ebcda659..ddfe4708059 100644 --- a/src/lib/unlang/compile.c +++ b/src/lib/unlang/compile.c @@ -1745,6 +1745,9 @@ static unlang_t *compile_variable(unlang_t *parent, unlang_compile_t *unlang_ctx case UNLANG_TYPE_TIMEOUT: case UNLANG_TYPE_LIMIT: case UNLANG_TYPE_POLICY: + case UNLANG_TYPE_REDUNDANT: + case UNLANG_TYPE_LOAD_BALANCE: + case UNLANG_TYPE_REDUNDANT_LOAD_BALANCE: break; default: @@ -3527,7 +3530,7 @@ static unlang_t *compile_else(unlang_t *parent, unlang_compile_t *unlang_ctx, CO * redundant, load-balance and parallel have limits on what can * go in them. */ -static int validate_limited_subsection(CONF_SECTION *cs, char const *name) +static bool validate_limited_subsection(CONF_SECTION *cs, char const *name) { CONF_ITEM *ci; @@ -3556,21 +3559,24 @@ static int validate_limited_subsection(CONF_SECTION *cs, char const *name) (strcmp(name1, "elsif") == 0)) { cf_log_err(ci, "%s sections cannot contain a \"%s\" statement", name, name1); - return 0; + return false; } continue; } if (cf_item_is_pair(ci)) { CONF_PAIR *cp = cf_item_to_pair(ci); + + if (cf_pair_operator(cp) == T_OP_CMP_TRUE) return true; + if (cf_pair_value(cp) != NULL) { cf_log_err(cp, "Unknown keyword '%s', or invalid location", cf_pair_attr(cp)); - return 0; + return false; } } } - return 1; + return true; } diff --git a/src/tests/keywords/redundant b/src/tests/keywords/redundant index 94cf59f7559..019604ae521 100644 --- a/src/tests/keywords/redundant +++ b/src/tests/keywords/redundant @@ -19,11 +19,17 @@ } redundant { + uint32 foo + group { + &foo := 1 fail } group { + if !(&foo == 1) { + test_fail + } success } }