The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Data Structures | Macros | Typedefs | Functions
interpret.h File Reference

Declarations for the unlang interpreter. More...

#include <freeradius-devel/server/cf_util.h>
#include <freeradius-devel/server/request.h>
#include <freeradius-devel/unlang/action.h>
+ Include dependency graph for interpret.h:

Go to the source code of this file.

Data Structures

struct  unlang_request_func_t
 External functions provided by the owner of the interpret. More...
 

Macros

#define UNLANG_FRAME_PRE_ALLOC   (128)
 How much memory we pre-alloc for each frame. More...
 
#define UNLANG_STACK_MAX   (64)
 The maximum depth of the stack. More...
 
#define UNLANG_SUB_FRAME   (false)
 
#define UNLANG_TOP_FRAME   (true)
 

Typedefs

typedef struct unlang_interpret_s unlang_interpret_t
 Interpreter handle. More...
 
typedef void(* unlang_request_done_t) (request_t *request, rlm_rcode_t rcode, void *uctx)
 Signal the owner of the interpreter that this request completed processing. More...
 
typedef void(* unlang_request_init_t) (request_t *request, void *uctx)
 Signal the owner of the interpreter that this request should be initialised and executed. More...
 
typedef void(* unlang_request_resume_t) (request_t *request, void *uctx)
 Signal the owner of the interpreter that a request is ready to be resumed. More...
 
typedef void(* unlang_request_runnable_t) (request_t *request, void *uctx)
 Signal the owner of the interpreter that a request is now runnable. More...
 
typedef bool(* unlang_request_scheduled_t) (request_t const *request, void *uctx)
 Signal the owner of the interpreter that a request is now runnable. More...
 
typedef void(* unlang_request_stop_t) (request_t *request, void *uctx)
 Stop a request from running. More...
 
typedef void(* unlang_request_yield_t) (request_t *request, void *uctx)
 Signal the owner of the interpreter that a request has yielded. More...
 

Functions

void unlang_interpet_frame_discard (request_t *request)
 Discard the bottom most frame on the request's stack. More...
 
rlm_rcode_t unlang_interpret (request_t *request)
 Run the interpreter for a current request. More...
 
fr_event_list_tunlang_interpret_event_list (request_t *request)
 Get the event list for the current interpreter. More...
 
TALLOC_CTX * unlang_interpret_frame_talloc_ctx (request_t *request)
 Get a talloc_ctx which is valid only for this frame. More...
 
unlang_interpret_tunlang_interpret_get (request_t *request)
 Get the interpreter set for a request. More...
 
unlang_interpret_tunlang_interpret_get_thread_default (void)
 Get the default interpreter for this thread. More...
 
unlang_interpret_tunlang_interpret_init (TALLOC_CTX *ctx, fr_event_list_t *el, unlang_request_func_t *func, void *uctx)
 Initialize a unlang compiler / interpret. More...
 
int unlang_interpret_init_global (TALLOC_CTX *ctx)
 
bool unlang_interpret_is_resumable (request_t *request)
 Check if a request as resumable. More...
 
void unlang_interpret_mark_runnable (request_t *request)
 Mark a request as resumable. More...
 
int unlang_interpret_push_instruction (request_t *request, void *instruction, rlm_rcode_t default_rcode, bool top_frame)
 Push an instruction onto the request stack for later interpretation. More...
 
int unlang_interpret_push_section (request_t *request, CONF_SECTION *cs, rlm_rcode_t default_action, bool top_frame)
 Push a configuration section onto the request stack for later interpretation. More...
 
void unlang_interpret_request_done (request_t *request)
 Indicate to the caller of the interpreter that this request is complete. More...
 
void unlang_interpret_set (request_t *request, unlang_interpret_t *intp)
 Set a specific interpreter for a request. More...
 
void unlang_interpret_set_thread_default (unlang_interpret_t *intp)
 Set the default interpreter for this thread. More...
 
void unlang_interpret_signal (request_t *request, fr_signal_t action)
 Send a signal (usually stop) to a request. More...
 
void * unlang_interpret_stack_alloc (TALLOC_CTX *ctx)
 Allocate a new unlang stack. More...
 
int unlang_interpret_stack_depth (request_t *request)
 Return the depth of the request's stack. More...
 
rlm_rcode_t unlang_interpret_stack_result (request_t *request)
 Get the current rcode for the frame. More...
 
void unlang_interpret_stack_result_set (request_t *request, rlm_rcode_t code)
 Overwrite the current stack rcode. More...
 
rlm_rcode_t unlang_interpret_synchronous (fr_event_list_t *el, request_t *request)
 Execute an unlang section synchronously. More...
 
bool unlang_request_is_cancelled (request_t const *request)
 Return whether a request has been cancelled. More...
 
bool unlang_request_is_scheduled (request_t const *request)
 Return whether a request is currently scheduled. More...
 

Detailed Description

Declarations for the unlang interpreter.

Id
8e47bd453380ee2e203dbdb95b857bf243d232aa

Definition in file interpret.h.


Data Structure Documentation

◆ unlang_request_func_t

struct unlang_request_func_t

External functions provided by the owner of the interpret.

These functions allow the event loop to signal the caller when a given request is ready to run for the first time, and when it should be resumed and passed back to unlang_interpret to continue execution.

This is the cleanest way to separate the interpret and the code that's managing requests.

Test harnesses (for example) need to perform far less initialisation and request management than FeeRADIUS worker threads.

Definition at line 100 of file interpret.h.

+ Collaboration diagram for unlang_request_func_t:
Data Fields
unlang_request_init_t detach Function called when a request is detached.
unlang_request_done_t done_detached Function called when a detached request completes.
unlang_request_done_t done_external Function called when a external request completes.
unlang_request_done_t done_internal Function called when an internal request completes.
unlang_request_init_t init_internal Function called to initialise an internal request.
unlang_request_runnable_t mark_runnable Function called when a request needs to be added back to the runnable queue.
unlang_request_resume_t resume Function called when a request is resumed.
unlang_request_scheduled_t scheduled Function to check if a request is already scheduled.
unlang_request_stop_t stop function called when a request is signalled to stop.
unlang_request_yield_t yield Function called when a request yields.

Macro Definition Documentation

◆ UNLANG_FRAME_PRE_ALLOC

#define UNLANG_FRAME_PRE_ALLOC   (128)

How much memory we pre-alloc for each frame.

Definition at line 39 of file interpret.h.

◆ UNLANG_STACK_MAX

#define UNLANG_STACK_MAX   (64)

The maximum depth of the stack.

Definition at line 38 of file interpret.h.

◆ UNLANG_SUB_FRAME

#define UNLANG_SUB_FRAME   (false)

Definition at line 36 of file interpret.h.

◆ UNLANG_TOP_FRAME

#define UNLANG_TOP_FRAME   (true)

Definition at line 35 of file interpret.h.

Typedef Documentation

◆ unlang_interpret_t

Interpreter handle.

Definition at line 1 of file interpret.h.

◆ unlang_request_done_t

typedef void(* unlang_request_done_t) (request_t *request, rlm_rcode_t rcode, void *uctx)

Signal the owner of the interpreter that this request completed processing.

This is called once per request, when the interpret is about to stop processing it.

Definition at line 56 of file interpret.h.

◆ unlang_request_init_t

typedef void(* unlang_request_init_t) (request_t *request, void *uctx)

Signal the owner of the interpreter that this request should be initialised and executed.

This is called once per request, when it's about to start executing.

Definition at line 50 of file interpret.h.

◆ unlang_request_resume_t

typedef void(* unlang_request_resume_t) (request_t *request, void *uctx)

Signal the owner of the interpreter that a request is ready to be resumed.

This is called any time a yielded request has resumed.

Definition at line 74 of file interpret.h.

◆ unlang_request_runnable_t

typedef void(* unlang_request_runnable_t) (request_t *request, void *uctx)

Signal the owner of the interpreter that a request is now runnable.

This is called any time a yielded request has been marked runnable.

Definition at line 80 of file interpret.h.

◆ unlang_request_scheduled_t

typedef bool(* unlang_request_scheduled_t) (request_t const *request, void *uctx)

Signal the owner of the interpreter that a request is now runnable.

This is called any time a yielded request has been marked runnable.

Definition at line 86 of file interpret.h.

◆ unlang_request_stop_t

typedef void(* unlang_request_stop_t) (request_t *request, void *uctx)

Stop a request from running.

This is called whenever a request has been signalled to stop

Definition at line 62 of file interpret.h.

◆ unlang_request_yield_t

typedef void(* unlang_request_yield_t) (request_t *request, void *uctx)

Signal the owner of the interpreter that a request has yielded.

This is called whenever a request has given control back to the interpreter.

Definition at line 68 of file interpret.h.

Function Documentation

◆ unlang_interpet_frame_discard()

void unlang_interpet_frame_discard ( request_t request)

Discard the bottom most frame on the request's stack.

This is used for cleaning up after errors. i.e. the caller uses a push function, and experiences an error and needs to remove the frame that was just pushed.

Definition at line 1718 of file interpret.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unlang_interpret()

rlm_rcode_t unlang_interpret ( request_t request)

Run the interpreter for a current request.

Parameters
[in]requestto run. If this is an internal request the request may be freed by the interpreter.
Returns
The final request rcode.

Definition at line 760 of file interpret.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unlang_interpret_event_list()

fr_event_list_t* unlang_interpret_event_list ( request_t request)

Get the event list for the current interpreter.

Definition at line 1745 of file interpret.c.

+ Here is the caller graph for this function:

◆ unlang_interpret_frame_talloc_ctx()

TALLOC_CTX* unlang_interpret_frame_talloc_ctx ( request_t request)

Get a talloc_ctx which is valid only for this frame.

Parameters
[in]requestThe current request.
Returns
  • a TALLOC_CTX which is valid only for this stack frame

Definition at line 1384 of file interpret.c.

+ Here is the caller graph for this function:

◆ unlang_interpret_get()

unlang_interpret_t* unlang_interpret_get ( request_t request)

Get the interpreter set for a request.

Definition at line 1735 of file interpret.c.

+ Here is the caller graph for this function:

◆ unlang_interpret_get_thread_default()

unlang_interpret_t* unlang_interpret_get_thread_default ( void  )

Get the default interpreter for this thread.

This allows detached requests to be executed asynchronously

Definition at line 1768 of file interpret.c.

+ Here is the caller graph for this function:

◆ unlang_interpret_init()

unlang_interpret_t* unlang_interpret_init ( TALLOC_CTX *  ctx,
fr_event_list_t el,
unlang_request_func_t funcs,
void *  uctx 
)

Initialize a unlang compiler / interpret.

Parameters
[in]ctxto bind lifetime of the interpret to. Shouldn't be any free order issues here as the interpret itself has no state. But event loop should be stopped before freeing the interpret.
[in]elfor any timer or I/O events.
[in]funcsCallbacks to used to communicate request state to our owner.
[in]uctxData to pass to callbacks.

Definition at line 1684 of file interpret.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unlang_interpret_init_global()

int unlang_interpret_init_global ( TALLOC_CTX *  ctx)

Definition at line 1775 of file interpret.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unlang_interpret_is_resumable()

bool unlang_interpret_is_resumable ( request_t request)

Check if a request as resumable.

Parameters
[in]requestThe current request.
Returns
  • true if the request is resumable (i.e. has yielded)
  • false if the request is not resumable (i.e. has not yielded)

Definition at line 1322 of file interpret.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unlang_interpret_mark_runnable()

void unlang_interpret_mark_runnable ( request_t request)

Mark a request as resumable.

It's not called "unlang_interpret", because it doesn't actually resume the request, it just schedules it for resumption.

Note
that this schedules the request for resumption. It does not immediately start running the request.
Parameters
[in]requestThe current request.

Definition at line 1340 of file interpret.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unlang_interpret_push_instruction()

int unlang_interpret_push_instruction ( request_t request,
void *  instruction,
rlm_rcode_t  default_rcode,
bool  top_frame 
)

Push an instruction onto the request stack for later interpretation.

Definition at line 1005 of file interpret.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unlang_interpret_push_section()

int unlang_interpret_push_section ( request_t request,
CONF_SECTION cs,
rlm_rcode_t  default_action,
bool  top_frame 
)

Push a configuration section onto the request stack for later interpretation.

Definition at line 982 of file interpret.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unlang_interpret_request_done()

void unlang_interpret_request_done ( request_t request)

Indicate to the caller of the interpreter that this request is complete.

Definition at line 1062 of file interpret.c.

+ Here is the caller graph for this function:

◆ unlang_interpret_set()

void unlang_interpret_set ( request_t request,
unlang_interpret_t intp 
)

Set a specific interpreter for a request.

Definition at line 1726 of file interpret.c.

+ Here is the caller graph for this function:

◆ unlang_interpret_set_thread_default()

void unlang_interpret_set_thread_default ( unlang_interpret_t intp)

Set the default interpreter for this thread.

Definition at line 1757 of file interpret.c.

+ Here is the caller graph for this function:

◆ unlang_interpret_signal()

void unlang_interpret_signal ( request_t request,
fr_signal_t  action 
)

Send a signal (usually stop) to a request.

This is typically called via an "async" action, i.e. an action outside of the normal processing of the request.

If there is no unlang_module_signal_t callback defined, the action is ignored.

Parameters
[in]requestThe current request.
[in]actionto signal.

Definition at line 1184 of file interpret.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unlang_interpret_stack_alloc()

void* unlang_interpret_stack_alloc ( TALLOC_CTX *  ctx)

Allocate a new unlang stack.

Parameters
[in]ctxto allocate stack in.
Returns
  • A new stack on success.
  • NULL on OOM.

Definition at line 1036 of file interpret.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unlang_interpret_stack_depth()

int unlang_interpret_stack_depth ( request_t request)

Return the depth of the request's stack.

Definition at line 1263 of file interpret.c.

+ Here is the caller graph for this function:

◆ unlang_interpret_stack_result()

rlm_rcode_t unlang_interpret_stack_result ( request_t request)

Get the current rcode for the frame.

This can be useful for getting the result of unlang_function_t pushed onto the stack for evaluation.

Parameters
[in]requestThe current request.
Returns
the current rcode for the frame.

Definition at line 1278 of file interpret.c.

+ Here is the caller graph for this function:

◆ unlang_interpret_stack_result_set()

void unlang_interpret_stack_result_set ( request_t request,
rlm_rcode_t  rcode 
)

Overwrite the current stack rcode.

Parameters
[in]requestThe current request.
[in]rcodeto set.

Definition at line 1290 of file interpret.c.

+ Here is the caller graph for this function:

◆ unlang_interpret_synchronous()

rlm_rcode_t unlang_interpret_synchronous ( fr_event_list_t el,
request_t request 
)

Execute an unlang section synchronously.

Create a temporary event loop and swap it out for the one in the request. Execute unlang operations until we receive a non-yield return code then return.

Note
The use cases for this are very limited. If you need to use it, chances are what you're doing could be done better using one of the thread event loops.
Parameters
[in]elEvent list for the temporary interpreter. If NULL a temporary list will be allocated.
[in]requestThe current request.
Returns
One of the RLM_MODULE_* macros.

Definition at line 212 of file interpret_synchronous.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unlang_request_is_cancelled()

bool unlang_request_is_cancelled ( request_t const *  request)

Return whether a request has been cancelled.

Definition at line 1310 of file interpret.c.

◆ unlang_request_is_scheduled()

bool unlang_request_is_scheduled ( request_t const *  request)

Return whether a request is currently scheduled.

Definition at line 1300 of file interpret.c.

+ Here is the caller graph for this function: