]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add optional CONF_PAIR ** argument to trigger()
authorNick Porter <nick@portercomputing.co.uk>
Mon, 25 Aug 2025 08:11:49 +0000 (09:11 +0100)
committerNick Porter <nick@portercomputing.co.uk>
Mon, 25 Aug 2025 13:56:12 +0000 (14:56 +0100)
Allows passing in of known CONF_PAIR and return of found pair, so
triggers which are called often don't have to repeatedly hunt for the
pair.

14 files changed:
src/bin/radiusd.c
src/lib/server/connection.c
src/lib/server/exfile.c
src/lib/server/main_loop.c
src/lib/server/pool.c
src/lib/server/trigger.c
src/lib/server/trigger.h
src/lib/server/trunk.c
src/listen/ldap_sync/active_directory.c
src/listen/ldap_sync/persistent_search.c
src/listen/ldap_sync/proto_ldap_sync_ldap.c
src/listen/ldap_sync/rfc4533.c
src/modules/rlm_crl/rlm_crl.c
src/modules/rlm_test/rlm_test.c

index c1405fced33a6c53cae71022348d8660a9fed235..5791a74abf4000af7e3864e7a9a8c0a219638e7d 100644 (file)
@@ -939,7 +939,7 @@ int main(int argc, char *argv[])
                }
        }
 
-       trigger(NULL, NULL, "server.start", false, NULL);
+       trigger(NULL, NULL, NULL, "server.start", false, NULL);
 
        /*
         *  Inform the parent (who should still be waiting) that the rest of
@@ -1024,8 +1024,8 @@ int main(int argc, char *argv[])
         *   Fire signal and stop triggers after ignoring SIGTERM, so handlers are
         *   not killed with the rest of the process group, below.
         */
-       if (status == 2) trigger(NULL, NULL, "server.signal.term", true, NULL);
-       trigger(NULL, NULL, "server.stop", false, NULL);
+       if (status == 2) trigger(NULL, NULL, NULL, "server.signal.term", true, NULL);
+       trigger(NULL, NULL, NULL, "server.stop", false, NULL);
 
        /*
         *  Stop the scheduler, this signals the network and worker threads
index 4e9118cbe404d4e56cece636ea60d58d86530077..76b8ab22a475b877e10095632e9c5bdb0e503a31 100644 (file)
@@ -129,7 +129,7 @@ struct connection_s {
 
 #define CONN_TRIGGER(_state) do { \
        if (conn->triggers) trigger(unlang_interpret_get_thread_default(), \
-               conn->trigger_cs, fr_table_str_by_value(connection_trigger_names, _state, "<INVALID>"), true, conn->trigger_args); \
+               conn->trigger_cs, NULL, fr_table_str_by_value(connection_trigger_names, _state, "<INVALID>"), true, conn->trigger_args); \
 } while (0)
 
 #define STATE_TRANSITION(_new) \
index e0de5da7e607f15724761e3d393e8fa65f3436a2..8a074e9b9f49bccb24a02f327ca40ea8dccf4012 100644 (file)
@@ -91,7 +91,7 @@ static inline void exfile_trigger(exfile_t *ef, exfile_entry_t *entry, char cons
                                       talloc_array_length(entry->filename) - 1, false);
 
        snprintf(name, sizeof(name), "%s.%s", ef->trigger_prefix, name_suffix);
-       trigger(unlang_interpret_get_thread_default(), ef->conf, name, false, &args);
+       trigger(unlang_interpret_get_thread_default(), ef->conf, NULL, name, false, &args);
 
        fr_pair_list_free(&args);
 }
index 897b786099ad6464ffea4de9346c4bde72e4f8de..d91c634ba4bf994dd4b6995fe7f6f5d647ea0390 100644 (file)
@@ -133,7 +133,7 @@ static void main_loop_signal_process(int flag)
 
                last_hup = when;
 
-               trigger(unlang_interpret_get_thread_default(), NULL, "server.signal.hup", true, NULL);
+               trigger(unlang_interpret_get_thread_default(), NULL, NULL, "server.signal.hup", true, NULL);
                fr_event_loop_exit(event_list, 0x80);
        }
 }
index 280e424e35512210769c0af6987822f83c3ce37d..74e4734ef0bf615af749f49fb2297ecf5b45198a 100644 (file)
@@ -266,7 +266,7 @@ static inline void fr_pool_trigger(fr_pool_t *pool, char const *event)
        if (!pool->triggers_enabled) return;
 
        snprintf(name, sizeof(name), "%s.%s", pool->trigger_prefix, event);
-       trigger(unlang_interpret_get_thread_default(), pool->cs, name, true, &pool->trigger_args);
+       trigger(unlang_interpret_get_thread_default(), pool->cs, NULL, name, true, &pool->trigger_args);
 }
 
 /** Find a connection handle in the connection list
index f72d030a0c4fc5d624f71d69bc7e5d6d635a4179..91c86704fe065c06a7e5de21dc642a564bec9c67 100644 (file)
@@ -132,6 +132,10 @@ typedef struct {
  *                             If cs is not NULL, the portion after the last '.' in name is used for the trigger.
  *                             If cs is NULL, the entire name is used to find the trigger in the global trigger
  *                             section.
+ * @param[in,out] trigger_cp   Optional pointer to a CONF_PAIR pointer.  If populated and the pointer is not
+ *                             NULL, this CONF_PAIR will be used rather than searching.
+ *                             If populated, and the pointer is NULL, the search will happen and the pointer
+ *                             will be populated with the found CONF_PAIR.
  * @param[in] name             the path relative to the global trigger section ending in the trigger name
  *                             e.g. module.ldap.pool.start.
  * @param[in] rate_limit       whether to rate limit triggers.
@@ -142,8 +146,8 @@ typedef struct {
  *     - -2 if the trigger was rate limited.
  *     - -3 on failure.
  */
-int trigger(unlang_interpret_t *intp,
-           CONF_SECTION const *cs, char const *name, bool rate_limit, fr_pair_list_t *args)
+int trigger(unlang_interpret_t *intp, CONF_SECTION const *cs, CONF_PAIR **trigger_cp,
+           char const *name, bool rate_limit, fr_pair_list_t *args)
 {
        CONF_ITEM               *ci;
        CONF_PAIR               *cp;
@@ -164,6 +168,14 @@ int trigger(unlang_interpret_t *intp,
         */
        if (!trigger_cs || check_config) return 0;
 
+       /*
+        *      Do we have a cached conf pair?
+        */
+       if (trigger_cp && *trigger_cp) {
+               cp = *trigger_cp;
+               goto cp_found;
+       }
+
        /*
         *      A module can have a local "trigger" section.  In which
         *      case that is used in preference to the global one.
@@ -215,6 +227,9 @@ int trigger(unlang_interpret_t *intp,
        cp = cf_item_to_pair(ci);
        if (!cp) return -1;
 
+       if (trigger_cp) *trigger_cp = cp;
+
+cp_found:
        value = cf_pair_value(cp);
        if (!value) {
                DEBUG3("Trigger has no value: %s", name);
index de2c36ed9fefd90863c15814de366d55619fbb6d..edeb2fc862db1445872e5f6ae57b22c8b0f4dbe9 100644 (file)
@@ -38,9 +38,8 @@ extern "C" {
 
 int            trigger_init(CONF_SECTION const *cs);
 
-int            trigger(unlang_interpret_t *intp,
-                            CONF_SECTION const *cs, char const *name, bool rate_limit, fr_pair_list_t *args)
-                            CC_HINT(nonnull(3));
+int            trigger(unlang_interpret_t *intp, CONF_SECTION const *cs, CONF_PAIR **trigger_cp,
+                       char const *name, bool rate_limit, fr_pair_list_t *args) CC_HINT(nonnull(4));
 
 bool           trigger_enabled(void);
 
index 47a1f491abb1806b72c63b21d4cf0ebd968f1a65..5c916f483bbfa8016758056c9695463bf79d9dab 100644 (file)
@@ -313,6 +313,8 @@ struct trunk_s {
        /** @} */
 
        bool                    trigger_undef[NUM_ELEMENTS(trunk_conn_trigger_names)];  //!< Record that a specific trigger is undefined.
+
+       CONF_PAIR               *trigger_cp[NUM_ELEMENTS(trunk_conn_trigger_names)];    //!< Cached trigger CONF_PAIRs
 };
 
 int trunk_trigger_cf_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule);
@@ -437,11 +439,13 @@ static fr_table_num_ordered_t const trunk_connection_events[] = {
 static size_t trunk_connection_events_len = NUM_ELEMENTS(trunk_connection_events);
 
 #define CONN_TRIGGER(_state) do { \
-       if (trunk->conf.conn_triggers && !trunk->trigger_undef[fr_high_bit_pos(_state)]) { \
-               if (trigger(unlang_interpret_get_thread_default(), \
-                       trunk->conf.conn_trigger_cs, fr_table_str_by_value(trunk_conn_trigger_names, _state, \
-                                                        "<INVALID>"), true, NULL) == -1) { \
-                       trunk->trigger_undef[fr_high_bit_pos(_state)] = true; \
+       uint8_t idx = fr_high_bit_pos(_state); \
+       if (trunk->conf.conn_triggers && !trunk->trigger_undef[idx]) { \
+               if (trigger(unlang_interpret_get_thread_default(), trunk->conf.conn_trigger_cs, \
+                           &trunk->trigger_cp[idx], \
+                           fr_table_str_by_value(trunk_conn_trigger_names, _state, \
+                                                 "<INVALID>"), true, NULL) == -1) { \
+                       trunk->trigger_undef[idx] = true; \
                } \
        } \
 } while (0)
@@ -472,7 +476,7 @@ void trunk_request_state_log_entry_add(char const *function, int line,
 #define REQUEST_TRIGGER(_state) do { \
        if (trunk->conf.req_triggers) { \
                trigger(unlang_interpret_get_thread_default(), \
-                       trunk->conf.req_trigger_cs, fr_table_str_by_value(trunk_req_trigger_names, _state, \
+                       trunk->conf.req_trigger_cs, NULL, fr_table_str_by_value(trunk_req_trigger_names, _state, \
                                                         "<INVALID>"), true, NULL); \
        } \
 } while (0)
index e489394d586696ecafa7d390023ae655eb95fb72..f224da0d23a2866a99ac09c665147691f4398516 100644 (file)
@@ -142,7 +142,7 @@ int active_directory_sync_state_init(fr_ldap_connection_t *conn, size_t sync_no,
        DEBUG3("Sync created with base dn \"%s\", filter \"%s\", msgid %i",
                sync->config->base_dn, sync->config->filter, sync->msgid);
 
-       trigger(unlang_interpret_get_thread_default(), config->cs, "modules.ldap_sync.start", true, &sync->trigger_args);
+       trigger(unlang_interpret_get_thread_default(), config->cs, NULL, "modules.ldap_sync.start", true, &sync->trigger_args);
 
        return 0;
 }
index f794ac9562223e7f5d512142aba60b87d3760799..e08053c3b22d411846abf7a0339cc778a8634444 100644 (file)
@@ -130,7 +130,7 @@ int persistent_sync_state_init(fr_ldap_connection_t *conn, size_t sync_no, proto
        DEBUG3("Sync created with base dn \"%s\", filter \"%s\", msgid %i",
                sync->config->base_dn, sync->config->filter, sync->msgid);
 
-       trigger(unlang_interpret_get_thread_default(), config->cs, "modules.ldap_sync.start", true, &sync->trigger_args);
+       trigger(unlang_interpret_get_thread_default(), config->cs, NULL, "modules.ldap_sync.start", true, &sync->trigger_args);
 
        /*
         *      Register event to store cookies at a regular interval
index 8c43a2972db8340fb23e1172320ccc1db930bde3..b8f3ba8ef18023e20e6e63edde7224aba95408fe 100644 (file)
@@ -163,7 +163,7 @@ static int sync_state_free(sync_state_t *sync)
 
        DEBUG3("Abandoning sync base dn \"%s\", filter \"%s\"", sync->config->base_dn, sync->config->filter);
 
-       trigger(unlang_interpret_get_thread_default(), sync->config->cs, "modules.ldap_sync.stop", true, &sync->trigger_args);
+       trigger(unlang_interpret_get_thread_default(), sync->config->cs, NULL, "modules.ldap_sync.stop", true, &sync->trigger_args);
 
        if (!sync->conn->handle) return 0;      /* Handled already closed? */
 
index b77fae8c96822e106e1011029506a1c286c7f287..f69cec6a8f2b4f9392897ab4d7473c362ba0fcab 100644 (file)
@@ -147,7 +147,7 @@ int rfc4533_sync_init(fr_ldap_connection_t *conn, size_t sync_no, proto_ldap_syn
        DEBUG3("Sync created with base dn \"%s\", filter \"%s\", msgid %i",
                sync->config->base_dn, sync->config->filter, sync->msgid);
 
-       trigger(unlang_interpret_get_thread_default(), config->cs, "modules.ldap_sync.start", true, &sync->trigger_args);
+       trigger(unlang_interpret_get_thread_default(), config->cs, NULL, "modules.ldap_sync.start", true, &sync->trigger_args);
 
        /*
         *      Register event to store cookies at a regular interval
index 84b384421dd6c4c09ef25bdabf045d21aa14e836..60f30d0a663de84e2d391f70e8edae8fd65251a4 100644 (file)
@@ -220,7 +220,7 @@ static void crl_expire(fr_timer_list_t *tl, UNUSED fr_time_t now, void *uctx)
                fr_pair_list_init(&args);
                MEM((vp = fr_pair_afrom_da_nested(crl, &args, attr_crl_cdp_url)));
                fr_value_box_strdup_shallow(&vp->data, NULL, crl->cdp_url, true);
-               trigger(unlang_interpret_get_thread_default(), crl->inst->cs, "modules.crl.expired",
+               trigger(unlang_interpret_get_thread_default(), crl->inst->cs, NULL, "modules.crl.expired",
                        crl->inst->trigger_rate_limit, &args);
        }
 
@@ -505,7 +505,7 @@ static int crl_tmpl_yield(request_t *request, rlm_crl_t const *inst, rlm_crl_thr
                return -1;
        }
 
-       trigger(unlang_interpret_get_thread_default(), inst->cs, "modules.crl.fetchuri", inst->trigger_rate_limit,
+       trigger(unlang_interpret_get_thread_default(), inst->cs, NULL, "modules.crl.fetchuri", inst->trigger_rate_limit,
                &request->request_pairs);
 
        if (unlang_module_yield_to_tmpl(rctx, &rctx->crl_data, request, vpt,
@@ -535,7 +535,7 @@ static unlang_action_t CC_HINT(nonnull) crl_process_cdp_data(unlang_result_t *p_
        switch (fr_value_box_list_num_elements(&rctx->crl_data)) {
        case 0:
                REDEBUG("No CRL data returned from %pV, failing", rctx->cdp_url);
-               trigger(unlang_interpret_get_thread_default(), inst->cs, "modules.crl.fetchfail",
+               trigger(unlang_interpret_get_thread_default(), inst->cs, NULL, "modules.crl.fetchfail",
                        inst->trigger_rate_limit, &request->request_pairs);
        again:
                talloc_free(rctx->cdp_url);
@@ -570,7 +570,7 @@ static unlang_action_t CC_HINT(nonnull) crl_process_cdp_data(unlang_result_t *p_
                talloc_free(crl_data);
                if (!crl_entry) {
                        RPERROR("Failed to process returned CRL data");
-                       trigger(unlang_interpret_get_thread_default(), inst->cs, "modules.crl.fetchbad",
+                       trigger(unlang_interpret_get_thread_default(), inst->cs, NULL, "modules.crl.fetchbad",
                                inst->trigger_rate_limit, &request->request_pairs);
                        goto again;
                }
index 39784b3b05706900273dc9f02d09186c45e64d4b..124f2d44926270c58646b884af60ff1e7215e25b 100644 (file)
@@ -353,7 +353,7 @@ static xlat_action_t trigger_test_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out,
        fr_value_box_t  *in_head = fr_value_box_list_head(in);
        fr_value_box_t  *vb;
 
-       if (trigger(unlang_interpret_get(request), NULL, in_head->vb_strvalue, false, NULL) < 0) {
+       if (trigger(unlang_interpret_get(request), NULL, NULL, in_head->vb_strvalue, false, NULL) < 0) {
                RPEDEBUG("Running trigger failed");
                return XLAT_ACTION_FAIL;
        }