]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
hoist next shortest prefix out of main loop
authorAlan T. DeKok <aland@freeradius.org>
Sun, 24 Dec 2023 12:48:35 +0000 (07:48 -0500)
committerAlan T. DeKok <aland@freeradius.org>
Sun, 24 Dec 2023 12:52:51 +0000 (07:52 -0500)
src/lib/server/users_file.h
src/modules/rlm_files/rlm_files.c

index a4671e1c1bd67b0a1ceb96951ac961bf5b424d2e..caf4b8e3bf22c1f9b645026dbc2ad7bba84b0113 100644 (file)
@@ -41,6 +41,7 @@ typedef struct pair_list {
        map_list_t              reply;          //!< List of maps for modifying reply list
        int                     order;          //!< Sequence of entry in source file
        bool                    fall_through;   //!< go to the next one
+       bool                    next_shortest_prefix;  //!< for prefix tries
        char const              *filename;      //!< Filename entry read from
        int                     lineno;         //!< Line number entry read from
        fr_dlist_t              entry;          //!< Entry in dlist of PAIR_LIST with matching name
index abe737c201f6cc29010395d15bf4028cb7811e3d..cce23dc466b4d2dcad55e9c25a2615859525c670 100644 (file)
@@ -216,12 +216,6 @@ static int getrecv_filename(TALLOC_CTX *ctx, char const *filename, fr_htrie_t **
                                return -1;
                        }
 
-                       if ((htype != FR_HTRIE_TRIE) && (da == attr_next_shortest_prefix)) {
-                               ERROR("%s[%d] Cannot use %s when key is not an IP / IP prefix",
-                                     entry->filename, entry->lineno, da->name);
-                               return -1;
-                       }
-
                        /*
                         *      Regex assignments aren't allowed.
                         *
@@ -233,6 +227,24 @@ static int getrecv_filename(TALLOC_CTX *ctx, char const *filename, fr_htrie_t **
                                return -1;
                        }
 
+                       if (da == attr_next_shortest_prefix) {
+                               if (htype != FR_HTRIE_TRIE) {
+                                       ERROR("%s[%d] Cannot use %s when key is not an IP / IP prefix",
+                                             entry->filename, entry->lineno, da->name);
+                                       return -1;
+                               }
+
+                               if (!tmpl_is_data(map->rhs) || (tmpl_value_type(map->rhs) != FR_TYPE_BOOL)) {
+                                       ERROR("%s[%d] Value for %s must be static boolean",
+                                             entry->filename, entry->lineno, da->name);
+                                       return -1;
+                               }
+
+                               entry->next_shortest_prefix = tmpl_value(map->rhs)->vb_bool;
+                               (void) map_list_remove(&entry->reply, map);
+                               continue;
+                       }
+
                        /*
                         *      Check for Fall-Through in the reply list.  If so, delete it and set the flag
                         *      in the entry.
@@ -242,10 +254,13 @@ static int getrecv_filename(TALLOC_CTX *ctx, char const *filename, fr_htrie_t **
                         *      free all subsequent maps.
                         */
                        if (da == attr_fall_through) {
-                               if (tmpl_is_data(map->rhs) && (tmpl_value_type(map->rhs) == FR_TYPE_BOOL)) {
-                                       entry->fall_through = tmpl_value(map->rhs)->vb_bool;
+                               if (!tmpl_is_data(map->rhs) || (tmpl_value_type(map->rhs) != FR_TYPE_BOOL)) {
+                                       ERROR("%s[%d] Value for %s must be static boolean",
+                                             entry->filename, entry->lineno, da->name);
+                                       return -1;
                                }
 
+                               entry->fall_through = tmpl_value(map->rhs)->vb_bool;
                                (void) map_list_remove(&entry->reply, map);
                                continue;
                        }
@@ -555,21 +570,13 @@ redo:
                        map = NULL;
 
                        while ((map = map_list_next(&pl->reply, map))) {
-                               /*
-                                *      Do Fall-Through style checks for prefix tries.
-                                */
-                               if (trie && (keylen > 0) && (tmpl_attr_tail_da(map->lhs) == attr_next_shortest_prefix)) {
-                                       fr_assert(tmpl_is_data(map->rhs));
-
-                                       next_shortest_prefix = tmpl_value(map->rhs)->vb_bool;
-                                       continue;
-                               }
-
                                if (radius_legacy_map_apply(request, map) < 0) {
                                        RPWARN("Failed parsing map for reply item %s, skipping it", map->lhs->name);
                                        break;
                                }
                        }
+
+                       next_shortest_prefix = pl->next_shortest_prefix;
                }
 
                if (pl->fall_through) {