]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
allow local variables in redundant and load-balance
authorAlan T. DeKok <aland@freeradius.org>
Wed, 25 Oct 2023 20:52:59 +0000 (16:52 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Wed, 25 Oct 2023 20:53:46 +0000 (16:53 -0400)
doc/antora/modules/reference/pages/unlang/local.adoc
src/lib/unlang/compile.c
src/tests/keywords/redundant

index de25bde0e607d989b686611a68e0c0f202a905fc..80efd608f79e0228e1c5ac411f66542644f80b2a 100644 (file)
@@ -16,7 +16,23 @@ section (i.e. scope), and cannot be sent in a packet over the network.
 }
 ----
 
-<keyword>:: 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.
+<keyword>:: 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.
 
 <data-type>:: A "leaf" xref:type/all_types.adoc[data type].  Structural types such as `group`, `struct`, `tlv`, etc. are not allowed.
 
index 7f8ebcda6596767090b14511d4c16b759c19aadd..ddfe4708059bf10783a0ae881135e4d43072b12b 100644 (file)
@@ -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;
 }
 
 
index 94cf59f755901d532b9052c0d1d40d237262fbef..019604ae521fb7c9fb4fce89d8363290d7411f81 100644 (file)
 }
 
 redundant {
+       uint32 foo
+
        group {
+               &foo := 1
                fail
        }
 
        group {
+               if !(&foo == 1) {
+                       test_fail
+               }
                success
        }
 }