]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Fix trigger plumbing in connection.c
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 21 Jul 2025 20:52:51 +0000 (13:52 -0700)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 21 Jul 2025 21:55:42 +0000 (14:55 -0700)
src/lib/server/connection.c
src/lib/server/connection.h

index 045041cd0fe511221593e5c9bc5ac5663d985ba6..91d4f9c837aafcfa73a0187d7913ee5eb7ba2140 100644 (file)
@@ -121,13 +121,14 @@ struct connection_s {
                                                        ///< the connection.
 
        unsigned int            signals_pause;          //!< Temporarily stop processing of signals.
+
+       CONF_SECTION            *trigger_cs;            //!< Where to search locally for triggers.
+       fr_pair_list_t          *trigger_args;          //!< Arguments to pass to the trigger functions.
 };
 
 #define CONN_TRIGGER(_state) do { \
-       if (conn->pub.triggers) { \
-               trigger(unlang_interpret_get_thread_default(), \
-                            NULL, fr_table_str_by_value(connection_trigger_names, _state, "<INVALID>"), true, NULL); \
-       } \
+       trigger(unlang_interpret_get_thread_default(), \
+               conn->trigger_cs, fr_table_str_by_value(connection_trigger_names, _state, "<INVALID>"), true, conn->trigger_args); \
 } while (0)
 
 #define STATE_TRANSITION(_new) \
@@ -1517,10 +1518,10 @@ static int _connection_free(connection_t *conn)
  *     - NULL on failure.
  */
 connection_t *connection_alloc(TALLOC_CTX *ctx, fr_event_list_t *el,
-                                    connection_funcs_t const *funcs,
-                                    connection_conf_t const *conf,
-                                    char const *log_prefix,
-                                    void const *uctx)
+                              connection_funcs_t const *funcs,
+                              connection_conf_t const *conf,
+                              char const *log_prefix,
+                              void const *uctx)
 {
        size_t i;
        connection_t *conn;
@@ -1547,6 +1548,8 @@ connection_t *connection_alloc(TALLOC_CTX *ctx, fr_event_list_t *el,
                .failed = funcs->failed,
                .shutdown = funcs->shutdown,
                .is_closed = true,              /* Starts closed */
+               .trigger_args = conf->trigger_args,
+               .trigger_cs = conf->trigger_cs,
                .pub.name = talloc_asprintf(conn, "%s - [%" PRIu64 "]", log_prefix, id)
        };
        memcpy(&conn->uctx, &uctx, sizeof(conn->uctx));
@@ -1563,7 +1566,7 @@ connection_t *connection_alloc(TALLOC_CTX *ctx, fr_event_list_t *el,
         *      Pre-allocate a on_halt watcher for deferred signal processing
         */
        conn->on_halted = connection_add_watch_post(conn, CONNECTION_STATE_HALTED,
-                                                      _deferred_signal_connection_on_halted, true, NULL);
+                                                   _deferred_signal_connection_on_halted, true, NULL);
        connection_watch_disable(conn->on_halted);      /* Start disabled */
 
        return conn;
index d75ea982f641ee2cde8a37ec8b60bcfb8ffae3c4..cd913ddb55a5986b96d7a133d771214740804267 100644 (file)
@@ -31,6 +31,8 @@ extern "C" {
 #include <freeradius-devel/util/event.h>
 #include <freeradius-devel/util/table.h>
 #include <freeradius-devel/util/talloc.h>
+#include <freeradius-devel/util/pair.h>
+#include <freeradius-devel/server/cf_util.h>
 
 #ifdef _CONST
 #  error _CONST can only be defined in the local header
@@ -77,7 +79,6 @@ struct connection_pub_s {
                                                        ///< re-establish this connection.
        uint64_t _CONST                 timed_out;      //!< How many times has this connection timed out when
                                                        ///< connecting.
-       bool _CONST                     triggers;       //!< do we run the triggers?
 };
 
 typedef enum {
@@ -92,6 +93,12 @@ typedef struct {
        fr_time_delta_t connection_timeout;     //!< How long to wait for the connection to open
                                                //!< or for shutdown to close the connection.
        fr_time_delta_t reconnection_delay;     //!< How long to wait after failures.
+
+       CONF_SECTION    *trigger_cs;            //!< Local configuration section we also search for triggers in.
+                                               ///< Lifetime must be longer than the connection.
+
+       fr_pair_list_t  *trigger_args;          //!< Additional pairs to pass to the trigger function
+                                               ///< Lifetime must be longer than the connection.
 } connection_conf_t;
 
 typedef struct connection_watch_entry_s connection_watch_entry_t;