]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
don't convert the input key to a string
authorAlan T. DeKok <aland@freeradius.org>
Mon, 28 Apr 2025 12:05:48 +0000 (08:05 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 28 Apr 2025 20:48:17 +0000 (16:48 -0400)
we're hashing it for load-balance purposes.  So we can just hash
the raw data.

and since tmpl_expand() now produces errors, we don't need to

src/lib/unlang/load_balance.c

index ca18dc0db7cba1055a0614b15a6b309fa0cb4a01..0e907dba4fd54aaf6a5879aa6d1789073f032732 100644 (file)
@@ -127,7 +127,6 @@ static unlang_action_t unlang_load_balance(rlm_rcode_t *p_result, request_t *req
        if (gext && gext->vpt) {
                uint32_t hash, start;
                ssize_t slen;
-               char const *p = NULL;
                char buffer[1024];
 
                /*
@@ -169,13 +168,16 @@ static unlang_action_t unlang_load_balance(rlm_rcode_t *p_result, request_t *req
                        }
 
                } else {
-                       slen = tmpl_expand(&p, buffer, sizeof(buffer), request, gext->vpt);
-                       if (slen < 0) {
-                               REDEBUG("Failed expanding template");
-                               goto randomly_choose;
-                       }
+                       uint8_t *octets = NULL;
+
+                       /*
+                        *      If the input is an IP address, prefix, etc., we don't need to convert it to a
+                        *      string.  We can just hash the raw data directly.
+                        */
+                       slen = tmpl_expand(&octets, buffer, sizeof(buffer), request, gext->vpt);
+                       if (slen <= 0) goto randomly_choose;
 
-                       hash = fr_hash(p, slen);
+                       hash = fr_hash(octets, slen);
 
                        start = hash % g->num_children;
                }