]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add thread argument to unlang continuation functions
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 26 Nov 2016 22:20:01 +0000 (17:20 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sat, 26 Nov 2016 22:20:01 +0000 (17:20 -0500)
src/include/interpreter.h
src/include/modules.h
src/main/unlang.c
src/modules/rlm_delay/rlm_delay.c
src/modules/rlm_radius_client/rlm_radius_client.c

index 4096325960e659f14b8a8a2707521d93bc2fe681..7386bb76c22c32b8b8b6c283231bdc1a309b2bc5 100644 (file)
@@ -163,6 +163,7 @@ typedef struct {
  */
 typedef struct {
        unlang_module_call_t    module;         //!< Module call that returned #RLM_MODULE_YIELD.
+       void                    *thread;        //!< data specific to the module.
        fr_unlang_resume_t      callback;       //!< Function the yielding module indicated should
                                                //!< be called when the request could be resumed.
        fr_unlang_action_t      action_callback;  //!< Function the yielding module indicated should
@@ -181,6 +182,10 @@ typedef struct {
        char                    *xlat_name;
 } unlang_xlat_inline_t;
 
+typedef struct {
+       void                    *thread;        //!< Thread specific module instance.
+} unlang_stack_entry_modcall_t;
+
 /** State of a foreach loop
  *
  */
@@ -223,6 +228,7 @@ typedef struct {
        unlang_t                *instruction;
 
        union {
+               unlang_stack_entry_modcall_t    modcall;
                unlang_stack_entry_foreach_t    foreach;
                unlang_stack_entry_redundant_t  redundant;
        };
index 0f7579dbf919b90b702033fd7b755217b7601e3b..1693b2a3514a996545848d00d6765c6736972caa 100644 (file)
@@ -227,11 +227,13 @@ int               unlang_compile(CONF_SECTION *cs, rlm_components_t component);
  *     on a registered FD occurs before the timeout event fires.
  *
  * @param[in] request          the request.
- * @param[in] module_instance  the module instance.
+ * @param[in] instance         the module instance.
+ * @param[in] thread           data specific to this module instance.
  * @param[in] ctx              a local context for the callback.
  * @param[in] fired            the time the timeout event actually fired.
  */
-typedef        void (*fr_unlang_timeout_callback_t)(REQUEST *request, void *module_instance, void *ctx, struct timeval *fired);
+typedef        void (*fr_unlang_timeout_callback_t)(REQUEST *request, void *instance, void *thread, void *ctx,
+                                            struct timeval *fired);
 
 /** A callback when the FD is ready for reading
  *
@@ -241,22 +243,24 @@ typedef   void (*fr_unlang_timeout_callback_t)(REQUEST *request, void *module_inst
  * @note The callback is automatically removed on unlang_resumable(), so
  *
  * @param[in] request          the current request.
- * @param[in] module_instance  the module instance.
+ * @param[in] instance         the module instance.
+ * @param[in] thread           data specific to this module instance.
  * @param[in] ctx              a local context for the callback.
  * @param[in] fd               the file descriptor.
  */
-typedef void (*fr_unlang_fd_callback_t)(REQUEST *request, void *module_instance, void *ctx, int fd);
+typedef void (*fr_unlang_fd_callback_t)(REQUEST *request, void *instance, void *thread, void *ctx, int fd);
 
 /** A callback for when the request is resumed.
  *
  * The resumed request cannot call the normal "authorize", etc. method.  It needs a separate callback.
  *
  * @param[in] request          the current request.
- * @param[in] module_instance  The module instance.
+ * @param[in] instance         The module instance.
+ * @param[in] thread           data specific to this module instance.
  * @param[in] ctx              a local context for the callback.
  * @return a normal rlm_rcode_t.
  */
-typedef rlm_rcode_t (*fr_unlang_resume_t)(REQUEST *request, void *module_instance, void *ctx);
+typedef rlm_rcode_t (*fr_unlang_resume_t)(REQUEST *request, void *instance, void *thread, void *ctx);
 
 /** A callback when the request gets a fr_state_action_t.
  *
@@ -265,12 +269,14 @@ typedef rlm_rcode_t (*fr_unlang_resume_t)(REQUEST *request, void *module_instanc
  *
  * @note The callback is automatically removed on unlang_resumable().
  *
- * param[in] request           The current request.
- * param[in] module_instance   The module instance.
- * param[in] ctx               for the callback.
- * param[in] action            which is signalling the request.
+ * @param[in] request          The current request.
+ * @param[in] instance         The module instance.
+ * @param[in] thread           data specific to this module instance.
+ * @param[in] ctx              for the callback.
+ * @param[in] action           which is signalling the request.
  */
-typedef void (*fr_unlang_action_t)(REQUEST *request, void *module_instance, void *ctx, fr_state_action_t action);
+typedef void (*fr_unlang_action_t)(REQUEST *request, void *instance, void *thread, void *ctx,
+                                  fr_state_action_t action);
 
 int            unlang_event_timeout_add(REQUEST *request, fr_unlang_timeout_callback_t callback,
                                         void const *ctx, struct timeval *timeout);
index 099a2b04ec32df4f22e44bd9bdd1dbba31a56b86..3040500cc07c81e7d23280a6913e74707b53d800 100644 (file)
@@ -669,7 +669,6 @@ static unlang_action_t unlang_module_call(REQUEST *request, unlang_stack_t *stac
        unlang_module_call_t            *sp;
        unlang_stack_frame_t            *frame = &stack->frame[stack->depth];
        unlang_t                        *instruction = frame->instruction;
-       module_thread_instance_t        *thread_inst;
 
        /*
         *      Process a stand-alone child, and fall through
@@ -692,7 +691,7 @@ static unlang_action_t unlang_module_call(REQUEST *request, unlang_stack_t *stac
        /*
         *      Grab the thread/module specific data if any exists.
         */
-       thread_inst = module_thread_instance_find(sp->module_instance);
+       frame->modcall.thread = module_thread_instance_find(sp->module_instance);
 
        /*
         *      For logging unresponsive children.
@@ -700,7 +699,7 @@ static unlang_action_t unlang_module_call(REQUEST *request, unlang_stack_t *stac
        request->module = sp->module_instance->name;
 
        safe_lock(sp->module_instance);
-       request->rcode = sp->method(sp->module_instance->data, thread_inst, request);
+       request->rcode = sp->method(sp->module_instance->data, frame->modcall.thread, request);
        safe_unlock(sp->module_instance);
 
        request->module = NULL;
@@ -851,7 +850,7 @@ static unlang_action_t unlang_resumption(REQUEST *request, unlang_stack_t *stack
        memcpy(&mutable, &mr->ctx, sizeof(mutable));
 
        safe_lock(sp->module_instance);
-       *presult = mr->callback(request, mr->module.module_instance->data, mutable);
+       *presult = mr->callback(request, mr->module.module_instance->data, mr->thread, mutable);
        safe_unlock(sp->module_instance);
 
        RDEBUG2("%s (%s)", instruction->name ? instruction->name : "",
@@ -1275,6 +1274,7 @@ typedef struct unlang_event_t {
        fr_unlang_timeout_callback_t    timeout_callback;               //!< Function to call on timeout.
        fr_unlang_fd_callback_t         fd_callback;                    //!< Function to call when FD is readable.
        void const                      *inst;                          //!< Module instance to pass to callbacks.
+       void                            *thread;                        //!< Thread specific module instance.
        void const                      *ctx;                           //!< ctx data to pass to callbacks.
        fr_event_timer_t                *ev;                            //!< Event in this worker's event heap.
 } unlang_event_t;
@@ -1312,7 +1312,7 @@ static void unlang_event_timeout_handler(struct timeval *now, void *ctx)
        memcpy(&mutable_ctx, &ev->ctx, sizeof(mutable_ctx));
        memcpy(&mutable_inst, &ev->inst, sizeof(mutable_inst));
 
-       ev->timeout_callback(ev->request, mutable_inst, mutable_ctx, now);
+       ev->timeout_callback(ev->request, mutable_inst, ev->thread, mutable_ctx, now);
        talloc_free(ev);
 }
 
@@ -1337,7 +1337,7 @@ static void unlang_event_fd_handler(UNUSED fr_event_list_t *el, int fd, void *ct
        memcpy(&mutable_ctx, &ev->ctx, sizeof(mutable_ctx));
        memcpy(&mutable_inst, &ev->inst, sizeof(mutable_inst));
 
-       ev->fd_callback(ev->request, mutable_inst, mutable_ctx, fd);
+       ev->fd_callback(ev->request, mutable_inst, ev->thread, mutable_ctx, fd);
 }
 
 /** Set a timeout for the request.
@@ -1377,6 +1377,7 @@ int unlang_event_timeout_add(REQUEST *request, fr_unlang_timeout_callback_t call
        ev->fd = -1;
        ev->timeout_callback = callback;
        ev->inst = sp->module_instance->data;
+       ev->thread = frame->modcall.thread;
        ev->ctx = ctx;
 
        if (fr_event_timer_insert(request->el, unlang_event_timeout_handler, ev, when, &(ev->ev)) < 0) {
@@ -1431,6 +1432,7 @@ int unlang_event_fd_readable_add(REQUEST *request, fr_unlang_fd_callback_t callb
        ev->fd = fd;
        ev->fd_callback = callback;
        ev->inst = sp->module_instance->data;
+       ev->thread = frame->modcall.thread;
        ev->ctx = ctx;
 
        if (!fr_event_fd_insert(request->el, fd, unlang_event_fd_handler, NULL, NULL, ev)) {
@@ -1522,7 +1524,7 @@ void unlang_action(REQUEST *request, fr_state_action_t action)
 
        memcpy(&mutable, &mr->ctx, sizeof(mutable));
 
-       mr->action_callback(request, mr->module.module_instance->data, mutable, action);
+       mr->action_callback(request, mr->module.module_instance->data, mr->thread, mutable, action);
 }
 
 /** Yield a request
@@ -1550,10 +1552,11 @@ rlm_rcode_t unlang_yield(REQUEST *request, fr_unlang_resume_t callback,
        rad_assert(mr != NULL);
 
        memcpy(&mr->module, frame->instruction, sizeof(mr->module));
-
+       mr->thread = frame->modcall.thread;
        mr->module.self.type = UNLANG_TYPE_RESUME;
        mr->callback = callback;
        mr->action_callback = action_callback;
+       mr->thread = module_thread_instance_find(mr->module.module_instance->data); /* Could have caller pass this? */
        mr->ctx = ctx;
 
        frame->instruction = unlang_resumption_to_generic(mr);
index 62d696739a2b3a1734b3303219aec51a6f7b070b..42473cb4963f7913bafe19ce49cacb0b69f0cba7 100644 (file)
@@ -49,7 +49,7 @@ static const CONF_PARSER module_config[] = {
 /** Called when the delay is complete, and we're running from the interpreter
  *
  */
-static rlm_rcode_t delay_return(UNUSED REQUEST *request, UNUSED void *instance, UNUSED void *ctx)
+static rlm_rcode_t delay_return(UNUSED REQUEST *request, UNUSED void *instance, UNUSED void *thread, UNUSED void *ctx)
 {
        return RLM_MODULE_OK;
 }
@@ -63,7 +63,7 @@ static rlm_rcode_t delay_return(UNUSED REQUEST *request, UNUSED void *instance,
  * @param[in] ctx              Scheduled end of the delay.
  * @param[in] fired            When request processing was resumed.
  */
-static void delay_done(REQUEST *request, UNUSED void *instance, void *ctx, struct timeval *fired)
+static void delay_done(REQUEST *request, UNUSED void *instance, UNUSED void *thread, void *ctx, struct timeval *fired)
 {
        struct timeval *when = talloc_get_type_abort(ctx, struct timeval);
 
index 75157206f8f7e0619a3df591447fb3fcc828b277..99c07c639b895e1d42af806fd805060c357a44ad 100644 (file)
@@ -176,7 +176,8 @@ static void mod_event_fd(UNUSED fr_event_list_t *el, int fd, void *ctx)
        unlang_resumable(ccr->request);
 }
 
-static void mod_proxy_no_reply(REQUEST *request, UNUSED void *instance, void *ctx, UNUSED struct timeval *now)
+static void mod_proxy_no_reply(REQUEST *request, UNUSED void *instance, UNUSED void *thread, void *ctx,
+                              UNUSED struct timeval *now)
 {
        rlm_radius_client_request_t *ccr = ctx;
 
@@ -186,7 +187,7 @@ static void mod_proxy_no_reply(REQUEST *request, UNUSED void *instance, void *ct
 }
 
 
-static rlm_rcode_t mod_resume_recv(REQUEST *request, void *instance, void *ctx)
+static rlm_rcode_t mod_resume_recv(REQUEST *request, void *instance, UNUSED void *thread, void *ctx)
 {
        rlm_rcode_t                     rcode;
        rlm_radius_client_instance_t    *inst = instance;
@@ -212,7 +213,7 @@ static rlm_rcode_t mod_resume_recv(REQUEST *request, void *instance, void *ctx)
        return rcode;
 }
 
-static rlm_rcode_t mod_resume_continue(REQUEST *request, void *instance, void *ctx)
+static rlm_rcode_t mod_resume_continue(REQUEST *request, void *instance, void *thread, void *ctx)
 {
        rlm_rcode_t rcode;
        CONF_SECTION *unlang;
@@ -246,11 +247,11 @@ static rlm_rcode_t mod_resume_continue(REQUEST *request, void *instance, void *c
 
        child->request_state = REQUEST_RECV;
 
-       return mod_resume_recv(request, instance, ccr);
+       return mod_resume_recv(request, instance, thread, ccr);
 }
 
 
-static void mod_action_dup(REQUEST *request, void *instance, void *ctx, fr_state_action_t action)
+static void mod_action_dup(REQUEST *request, void *instance, UNUSED void *thread, void *ctx, fr_state_action_t action)
 {
        rlm_radius_client_instance_t const *inst = instance;
        rlm_radius_client_request_t *ccr = ctx;
@@ -428,7 +429,7 @@ static rlm_rcode_t mod_wait_for_reply(REQUEST *request, rlm_radius_client_instan
        return unlang_yield(request, mod_resume_continue, mod_action_dup, ccr);
 }
 
-static rlm_rcode_t mod_resume_send(REQUEST *request, void *instance, void *ctx)
+static rlm_rcode_t mod_resume_send(REQUEST *request, void *instance, UNUSED void *thread, void *ctx)
 {
        rlm_rcode_t rcode;
        rlm_radius_client_instance_t const *inst = instance;
@@ -454,7 +455,7 @@ static rlm_rcode_t mod_resume_send(REQUEST *request, void *instance, void *ctx)
 /** Send packets outbound.
  *
  */
-static rlm_rcode_t CC_HINT(nonnull) mod_process(void *instance, UNUSED void *thread, REQUEST *request)
+static rlm_rcode_t CC_HINT(nonnull) mod_process(void *instance, void *thread, REQUEST *request)
 {
        rlm_radius_client_instance_t const *inst = instance;
        rlm_radius_client_conn_t *conn;
@@ -597,7 +598,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_process(void *instance, UNUSED void *thr
 
        child->request_state = REQUEST_SEND;
 
-       return mod_resume_send(request, instance, ccr);
+       return mod_resume_send(request, instance, thread, ccr);
 }
 
 static char const *auth_names[][2] = {