The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
unlang_priv.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2, or (at your option)
6 * any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 */
17
18/**
19 * $Id: 1d443e8f6b0fc8cdcf6b8d757b11113229dfb690 $
20 *
21 * @file unlang/unlang_priv.h
22 * @brief Private interpreter structures and functions
23 *
24 * @author Alan DeKok (aland@freeradius.org)
25 *
26 * @copyright 2016-2019 The FreeRADIUS server project
27 */
28#include <freeradius-devel/server/cf_util.h> /* Need CONF_* definitions */
29#include <freeradius-devel/server/map_proc.h>
30#include <freeradius-devel/server/modpriv.h>
31#include <freeradius-devel/server/time_tracking.h>
32#include <freeradius-devel/util/debug.h>
33#include <freeradius-devel/util/dlist.h>
34#include <freeradius-devel/unlang/base.h>
35#include <freeradius-devel/unlang/map.h>
36#include <freeradius-devel/io/listen.h>
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
42/** Types of unlang_t nodes
43 *
44 * Here are our basic types: unlang_t, unlang_group_t, and unlang_module_t. For an
45 * explanation of what they are all about, see doc/unlang/configurable_failover.adoc
46 */
47typedef enum {
48 UNLANG_TYPE_NULL = 0, //!< unlang type not set.
49 UNLANG_TYPE_MODULE = 1, //!< Module method.
50 UNLANG_TYPE_FUNCTION, //!< Internal call to a function or submodule.
51 UNLANG_TYPE_GROUP, //!< Grouping section.
52 UNLANG_TYPE_REDUNDANT, //!< exactly like group, but with different default return codes
53 UNLANG_TYPE_LOAD_BALANCE, //!< Load balance section.
54 UNLANG_TYPE_REDUNDANT_LOAD_BALANCE, //!< Redundant load balance section.
55 UNLANG_TYPE_PARALLEL, //!< execute statements in parallel
56 UNLANG_TYPE_IF, //!< Condition.
57 UNLANG_TYPE_ELSE, //!< !Condition.
58 UNLANG_TYPE_ELSIF, //!< !Condition && Condition.
59 UNLANG_TYPE_SWITCH, //!< Switch section.
60 UNLANG_TYPE_CASE, //!< Case section (within a #UNLANG_TYPE_SWITCH).
61 UNLANG_TYPE_FOREACH, //!< Foreach section.
62 UNLANG_TYPE_BREAK, //!< Break statement (within a #UNLANG_TYPE_FOREACH or #UNLANG_TYPE_CASE).
63 UNLANG_TYPE_CONTINUE, //!< Break statement (within a #UNLANG_TYPE_FOREACH).
64 UNLANG_TYPE_RETURN, //!< Return statement.
65 UNLANG_TYPE_MAP, //!< Mapping section (like #UNLANG_TYPE_UPDATE, but uses
66 //!< values from a #map_proc_t call).
67 UNLANG_TYPE_SUBREQUEST, //!< create a child subrequest
68 UNLANG_TYPE_CHILD_REQUEST, //!< a frame at the top of a child's request stack used to signal the
69 ///< parent when the child is complete.
70 UNLANG_TYPE_DETACH, //!< detach a child
71 UNLANG_TYPE_CALL, //!< call another virtual server
72 UNLANG_TYPE_CALLER, //!< conditionally check parent dictionary type
73 UNLANG_TYPE_TIMEOUT, //!< time-based timeouts.
74 UNLANG_TYPE_LIMIT, //!< limit number of requests in a section
75 UNLANG_TYPE_TRANSACTION, //!< transactions for editing lists
76 UNLANG_TYPE_TRY, //!< try / catch blocks
77 UNLANG_TYPE_CATCH, //!< catch a previous try
78 UNLANG_TYPE_FINALLY, //!< run at the end of a virtual server.
79 UNLANG_TYPE_POLICY, //!< Policy section.
80 UNLANG_TYPE_XLAT, //!< Represents one level of an xlat expansion.
81 UNLANG_TYPE_TMPL, //!< asynchronously expand a tmpl_t
82 UNLANG_TYPE_EDIT, //!< edit VPs in place. After 20 years!
85
86/** Allows the frame evaluator to signal the interpreter
87 *
88 */
89typedef enum {
90 UNLANG_FRAME_ACTION_POP = 1, //!< Pop the current frame, and check the next one further
91 ///< up in the stack for what to do next.
92 UNLANG_FRAME_ACTION_RETRY, //!< retry the current frame
93 UNLANG_FRAME_ACTION_NEXT, //!< Process the next instruction at this level.
94 UNLANG_FRAME_ACTION_YIELD //!< Temporarily return control back to the caller on the C
95 ///< stack.
97
98#define UNLANG_NEXT_STOP (false)
99#define UNLANG_NEXT_SIBLING (true)
100
101#define UNLANG_DETACHABLE (true)
102#define UNLANG_NORMAL_CHILD (false)
103
104DIAG_OFF(attributes)
105typedef enum CC_HINT(flag_enum) {
106 UNLANG_FRAME_FLAG_NONE = 0x00, //!< No flags.
107 UNLANG_FRAME_FLAG_REPEAT = 0x01, //!< Repeat the frame on the way up the stack.
108 UNLANG_FRAME_FLAG_TOP_FRAME = 0x02, //!< are we the top frame of the stack?
109 ///< If true, causes the interpreter to stop
110 ///< interpreting and return, control then passes
111 ///< to whatever called the interpreter.
112 UNLANG_FRAME_FLAG_YIELDED = 0x04, //!< frame has yielded
113 UNLANG_FRAME_FLAG_UNWIND = 0x08, //!< This frame should be unwound without evaluation.
115DIAG_ON(attributes)
116
117typedef struct unlang_s unlang_t;
119
121FR_DLIST_TYPEDEFS(unlang_list, unlang_list_t, unlang_entry_t)
122
123/** A node in a graph of #unlang_op_t (s) that we execute
124 *
125 * The interpreter acts like a turing machine, with #unlang_t nodes forming the tape
126 * and the #unlang_action_t the instructions.
127 *
128 * This is the parent 'class' for multiple #unlang_t node specialisations.
129 * The #unlang_t struct is listed first in the specialisation so that we can cast between
130 * parent/child classes without knowledge of the layout of the structures.
131 *
132 * The specialisations of the nodes describe additional details of the operation to be performed.
133 */
134struct unlang_s {
135 unlang_t *parent; //!< Previous node.
136 unlang_list_t *list; //!< so we have fewer run-time dereferences
137 unlang_entry_t entry; //!< next / prev entries
138 char const *name; //!< Unknown...
139 char const *debug_name; //!< Printed in log messages when the node is executed.
140 unlang_type_t type; //!< The specialisation of this node.
141 bool closed; //!< whether or not this section is closed to new statements
142 CONF_ITEM *ci; //!< used to generate this item
143 unsigned int number; //!< unique node number
144 unlang_mod_actions_t actions; //!< Priorities, etc. for the various return codes.
145};
146
148#define unlang_list_foreach(_list_head, _iter) fr_dlist_foreach(unlang_list_dlist_head(_list_head), unlang_t, _iter)
149
150typedef struct {
151 fr_dict_t *dict; //!< our dictionary
152 fr_dict_attr_t const *root; //!< the root of our dictionary
153 int max_attr; //!< 1..N local attributes have been defined
155
156/** Generic representation of a grouping
157 *
158 * Can represent IF statements, maps, update sections etc...
159 */
160typedef struct {
162
164 unlang_list_t children;
165
166 unlang_variable_t *variables; //!< rarely used, so we don't usually need it
168
169/** A naked xlat
170 *
171 * @note These are vestigial and may be removed in future.
172 */
173typedef struct {
175 tmpl_t const *tmpl;
177
178/** Function to call when interpreting a frame
179 *
180 * @param[in,out] p_result Pointer to the current rcode, may be modified by the function.
181 * @param[in] request The current request.
182 * @param[in] frame being executed.
183 *
184 * @return an action for the interpreter to perform.
185 */
187 unlang_stack_frame_t *frame);
188
189/** Function to call if the request was signalled
190 *
191 * This is the instruction specific cancellation function.
192 * This function will usually either call a more specialised cancellation function
193 * set when something like a module yielded, or just cleanup the state of the original
194 * #unlang_process_t.
195 *
196 * @param[in] request The current request.
197 * @param[in] frame being signalled.
198 * @param[in] action We're being signalled with.
199 */
200typedef void (*unlang_signal_t)(request_t *request,
201 unlang_stack_frame_t *frame, fr_signal_t action);
202
203/** Custom callback for dumping information about frame state
204 *
205 * @param[in] request The current request.
206 * @param[in] frame to provide additional information for.
207 */
208typedef void (*unlang_dump_t)(request_t *request, unlang_stack_frame_t *frame);
209
210typedef int (*unlang_thread_instantiate_t)(unlang_t const *instruction, void *thread_inst);
211
212typedef struct {
213 virtual_server_t const *vs; //!< Virtual server we're compiling in the context of.
214 ///< This shouldn't change during the compilation of
215 ///< a single unlang section.
216 char const *section_name1;
217 char const *section_name2;
221
222typedef unlang_t *(*unlang_compile_t)(unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_ITEM const *ci);
223
224#define UNLANG_IGNORE ((unlang_t *) -1)
225
227
229
231
233
235 fr_dict_attr_t const *ref);
236
238
239/*
240 * @todo - These functions should be made private once all of they keywords have been moved to foo(args) syntax.
241 */
242bool pass2_fixup_tmpl(UNUSED TALLOC_CTX *ctx, tmpl_t **vpt_p, CONF_ITEM const *ci, fr_dict_t const *dict);
243bool pass2_fixup_map(map_t *map, tmpl_rules_t const *rules, fr_dict_attr_t const *parent);
244bool pass2_fixup_update(unlang_group_t *g, tmpl_rules_t const *rules);
245bool pass2_fixup_map_rhs(unlang_group_t *g, tmpl_rules_t const *rules);
246
247/*
248 * When we switch to a new unlang ctx, we use the new component
249 * name and number, but we use the CURRENT actions.
250 */
251static inline CC_HINT(always_inline)
253{
254#ifndef NDEBUG
255 int i;
256#endif
257
258 *dst = *src;
259
260#ifndef NDEBUG
261 /*
262 * Ensure that none of the actions are RETRY. The actions { ... } section is applied to the
263 * instruction, and not to the unlang_compile_ctx_t
264 */
265 for (i = 0; i < RLM_MODULE_NUMCODES; i++) {
266 fr_assert(dst->actions.actions[i] != MOD_ACTION_RETRY);
267 fr_assert(MOD_ACTION_VALID(dst->actions.actions[i]));
268 }
269#endif
270}
271
272
273#ifndef NDEBUG
274static inline CC_HINT(always_inline) int unlang_attr_rules_verify(tmpl_attr_rules_t const *rules)
275{
276 if (!fr_cond_assert_msg(rules->dict_def, "No protocol dictionary set")) return -1;
277 if (!fr_cond_assert_msg(rules->dict_def != fr_dict_internal(), "rules->attr.dict_def must not be the internal dictionary")) return -1;
278 if (!fr_cond_assert_msg(!rules->allow_foreign, "rules->attr.allow_foreign must be false")) return -1;
279
280 return 0;
281}
282
283static inline CC_HINT(always_inline) int unlang_rules_verify(tmpl_rules_t const *rules)
284{
285 if (!fr_cond_assert_msg(!rules->at_runtime, "rules->at_runtime must be false")) return -1;
286 return unlang_attr_rules_verify(&rules->attr);
287}
288
289#define RULES_VERIFY(_rules) do { if (unlang_rules_verify(_rules) < 0) return NULL; } while (0)
290#else
291#define RULES_VERIFY(_rules)
292#endif
293
294DIAG_OFF(attributes)
295typedef enum CC_HINT(flag_enum) {
296 UNLANG_OP_FLAG_NONE = 0x00, //!< No flags.
297 UNLANG_OP_FLAG_DEBUG_BRACES = 0x01, //!< Print debug braces.
298 UNLANG_OP_FLAG_RCODE_SET = 0x02, //!< Set request->rcode to the result of this operation.
299 UNLANG_OP_FLAG_NO_FORCE_UNWIND = 0x04, //!< Must not be cancelled.
300 ///< @Note Slightly confusingly, a cancellation signal
301 ///< can still be delivered to a frame that is not
302 ///< cancellable, but the frame won't be automatically
303 ///< unwound. This lets the frame know that cancellation
304 ///< is desired, but can be ignored.
305 UNLANG_OP_FLAG_BREAK_POINT = 0x08, //!< Break point.
306 UNLANG_OP_FLAG_RETURN_POINT = 0x10, //!< Return point.
307 UNLANG_OP_FLAG_CONTINUE_POINT = 0x20, //!< Continue point.
308
309 UNLANG_OP_FLAG_SINGLE_WORD = 0x1000, //!< the operation is parsed and compiled as a single word
310 UNLANG_OP_FLAG_INTERNAL = 0x2000, //!< it's not a real keyword
311
313DIAG_ON(attributes)
314
315/** An unlang operation
316 *
317 * These are like the opcodes in other interpreters. Each operation, when executed
318 * will return an #unlang_action_t, which determines what the interpreter does next.
319 */
320typedef struct {
321 char const *name; //!< Name of the keyword
322 unlang_type_t type; //!< enum value for the keyword
323
324 unlang_compile_t compile; //!< compile the keyword
325
326 unlang_process_t interpret; //!< Function to interpret the keyword
327
328 unlang_signal_t signal; //!< Function to signal stop / dup / whatever
329
330 unlang_dump_t dump; //!< Dump additional information about the frame state.
331
332 size_t unlang_size; //!< Total length of the unlang_t + specialisation struct.
333 char const *unlang_name; //!< Talloc type name for the unlang_t
334
335 unsigned pool_headers; //!< How much additional space to allocate for chunk headers.
336 size_t pool_len; //!< How much additional space to allocate for chunks
337
338
339 unlang_thread_instantiate_t thread_instantiate; //!< per-thread instantiation function
341 char const *thread_inst_type;
342
343 unlang_op_flag_t flag; //!< Interpreter flags for this operation.
344
345 size_t frame_state_size; //!< size of instance data in the stack frame
346
347 char const *frame_state_type; //!< talloc name of the frame instance data
348
349 size_t frame_state_pool_objects; //!< How many sub-allocations we expect.
350
351 size_t frame_state_pool_size; //!< The total size of the pool to alloc.
353
354typedef struct {
355 unlang_t const *instruction; //!< instruction which we're executing
356 void *thread_inst; //!< thread-specific instance data
357#ifdef WITH_PERF
358 uint64_t use_count; //!< how many packets it has processed
359 uint64_t running; //!< currently running this instruction
360 uint64_t yielded; //!< currently yielded
361 fr_time_tracking_t tracking; //!< tracking cpu time
362#endif
364
365void *unlang_thread_instance(unlang_t const *instruction);
366
367#ifdef WITH_PERF
372#else
373#define unlang_frame_perf_init(_x)
374#define unlang_frame_perf_yield(_x)
375#define unlang_frame_perf_resume(_x)
376#define unlang_frame_perf_cleanup(_x)
377#endif
378
379void unlang_stack_signal(request_t *request, fr_signal_t action, int limit);
380
381typedef struct {
383 int depth; //!< of this retry structure
388
389/** Our interpreter stack, as distinct from the C stack
390 *
391 * We don't call the modules recursively. Instead we iterate over a list of #unlang_t and
392 * and manage the call stack ourselves.
393 *
394 * After looking at various green thread implementations, it was decided that using the existing
395 * unlang interpreter stack was the best way to perform async I/O.
396 *
397 * Each request as an unlang interpreter stack associated with it, which represents its progress
398 * through the server. Because the interpreter stack is distinct from the C stack, we can have
399 * a single system thread with many thousands of pending requests.
400 */
402 unlang_t const *instruction; //!< The unlang node we're evaluating.
403 unlang_t const *next; //!< The next unlang node we will evaluate
404
405 unlang_process_t process; //!< function to call for interpreting this stack frame
406 unlang_signal_t signal; //!< function to call when signalling this stack frame
407
408 /** Stack frame specialisations
409 *
410 * These store extra (mutable) state data, for the immutable (#unlang_t)
411 * instruction. Instructions can't be used to store data because they
412 * might be shared between multiple threads.
413 *
414 * Which stack_entry specialisation to use is determined by the
415 * instruction->type.
416 */
417 void *state;
418
419 unlang_result_t section_result; //!< The aggregate result of executing all siblings
420 ///< in this section. This will be merged with the
421 ///< higher stack frame's rcode when the frame is popped.
422 ///< If the rcode is set to RLM_MODULE_NOT_SET when
423 ///< the frame is popped, then the rcode of the frame
424 ///< does not modify the rcode of the frame above it.
425
426 unlang_result_t scratch_result; //!< The result of executing the current instruction.
427 ///< This will be set to RLM_MODULE_NOT_SET, and
428 ///< MOD_ACTION_NOT_SET when a new instruction is set
429 ///< for the frame. If p_result does not point to this
430 ///< field, the rcode and priority returned will be
431 ///< left as NOT_SET and will be ignored.
432 ///< This values here will persist between yields.
433
434 unlang_result_t *p_result; //!< Where to write the result of executing the current
435 ///< instruction. Will either point to `scratch_result`,
436 ///< OR if the parent does not want its rcode to be updated
437 ///< by a child it pushed for evaluation, it will point to
438 ///< memory in the parent's frame state, so that the parent
439 ///< can manually process the rcode.
440
441 unlang_retry_t *retry; //!< if the frame is being retried.
442
443
444 rindent_t indent; //!< Indent level of the request when the frame was
445 ///< created. This is used to restore the indent
446 ///< level when the stack is being forcefully unwound.
447
448 unlang_frame_flag_t flag; //!< Flags that mark up the frame for various things
449 ///< such as being the point where break, return or
450 ///< continue stop, or for forced unwinding.
451
452#ifdef WITH_PERF
453 fr_time_tracking_t tracking; //!< track this instance of this instruction
454#endif
455};
456
457/** An unlang stack associated with a request
458 *
459 */
460typedef struct {
461 unlang_interpret_t *intp; //!< Interpreter that the request is currently
462 ///< associated with.
463
464 int depth; //!< Current depth we're executing at.
465 uint8_t unwind; //!< Unwind to this frame if it exists.
466 ///< This is used for break and return.
467 unlang_stack_frame_t frame[UNLANG_STACK_MAX]; //!< The stack...
469
470/** Different operations the interpreter can execute
471 */
472extern unlang_op_t unlang_ops[];
474
475#define MOD_NUM_TYPES (UNLANG_TYPE_XLAT + 1)
476
478extern size_t mod_rcode_table_len;
479
480static inline void repeatable_set(unlang_stack_frame_t *frame) { frame->flag |= UNLANG_FRAME_FLAG_REPEAT; }
482static inline void yielded_set(unlang_stack_frame_t *frame) { frame->flag |= UNLANG_FRAME_FLAG_YIELDED; }
483static inline void unwind_set(unlang_stack_frame_t *frame) { frame->flag |= UNLANG_FRAME_FLAG_UNWIND; }
484
485static inline void repeatable_clear(unlang_stack_frame_t *frame) { frame->flag &= ~UNLANG_FRAME_FLAG_REPEAT; }
486static inline void top_frame_clear(unlang_stack_frame_t *frame) { frame->flag &= ~UNLANG_FRAME_FLAG_TOP_FRAME; }
487static inline void yielded_clear(unlang_stack_frame_t *frame) { frame->flag &= ~UNLANG_FRAME_FLAG_YIELDED; }
488static inline void unwind_clear(unlang_stack_frame_t *frame) { frame->flag &= ~UNLANG_FRAME_FLAG_UNWIND; }
489
490static inline bool is_repeatable(unlang_stack_frame_t const *frame) { return frame->flag & UNLANG_FRAME_FLAG_REPEAT; }
491static inline bool is_top_frame(unlang_stack_frame_t const *frame) { return frame->flag & UNLANG_FRAME_FLAG_TOP_FRAME; }
492static inline bool is_yielded(unlang_stack_frame_t const *frame) { return frame->flag & UNLANG_FRAME_FLAG_YIELDED; }
493static inline bool is_unwinding(unlang_stack_frame_t const *frame) { return frame->flag & UNLANG_FRAME_FLAG_UNWIND; }
494static inline bool is_private_result(unlang_stack_frame_t const *frame) { return !(frame->p_result == &frame->section_result); }
495
496static inline bool _instruction_has_debug_braces(unlang_t const *instruction) { return unlang_ops[instruction->type].flag & UNLANG_OP_FLAG_DEBUG_BRACES; }
498#define has_debug_braces(_thing) \
499 _Generic((_thing), \
500 unlang_t *: _instruction_has_debug_braces((unlang_t const *)(_thing)), \
501 unlang_t const *: _instruction_has_debug_braces((unlang_t const *)(_thing)), \
502 unlang_stack_frame_t *: _frame_has_debug_braces((unlang_stack_frame_t const *)(_thing)), \
503 unlang_stack_frame_t const *: _frame_has_debug_braces((unlang_stack_frame_t const *)(_thing)) \
504 )
505static inline bool is_rcode_set(unlang_stack_frame_t const *frame) { return unlang_ops[frame->instruction->type].flag & UNLANG_OP_FLAG_RCODE_SET; }
506static inline bool is_cancellable(unlang_stack_frame_t const *frame) { return !(unlang_ops[frame->instruction->type].flag & UNLANG_OP_FLAG_NO_FORCE_UNWIND); }
507static inline bool is_break_point(unlang_stack_frame_t const *frame) { return unlang_ops[frame->instruction->type].flag & UNLANG_OP_FLAG_BREAK_POINT; }
510
511/** @name Debug functions
512 *
513 * @{
514 */
515void stack_dump(request_t *request);
517/** @} */
518
519/** Find the first frame with a given flag
520 *
521 * @return
522 * - 0 if no frame has the flag.
523 * - The index of the first frame with the flag.
524 */
526{
527 unsigned int i;
528
529 for (i = stack->depth; i > 0; i--) {
530 unlang_stack_frame_t *frame = &stack->frame[i];
531
532 if (frame->flag & flag) return i;
533 }
534 return 0;
535}
536
537/** Find the first frame with a given flag
538 *
539 * @return
540 * - 0 if no frame has the flag.
541 * - The index of the first frame with the flag.
542 */
544{
545 unsigned int i;
546
547 for (i = stack->depth; i > 0; i--) {
548 unlang_stack_frame_t *frame = &stack->frame[i];
549
550 if (unlang_ops[frame->instruction->type].flag & flag) return i;
551 }
552 return 0;
553}
554
555/** Mark up frames as cancelled so they're immediately popped by the interpreter
556 *
557 * @note We used to do this asynchronously, but now we may need to execute timeout sections
558 * which means it's not enough to pop and cleanup the stack, we need continue executing
559 * the request.
560 *
561 * @param[in] stack The current stack.
562 * @param[in] to_depth mark all frames below this depth as cancelled.
563 */
564static inline unlang_action_t unwind_to_depth(unlang_stack_t *stack, unsigned int to_depth)
565{
567 unsigned int i, depth = stack->depth; /* must be signed to avoid underflow */
568
569 if (!fr_cond_assert(to_depth >= 1)) return UNLANG_ACTION_FAIL;
570
571 for (i = depth; i >= to_depth; i--) {
572 frame = &stack->frame[i];
573 if (!is_cancellable(frame)) continue;
574 unwind_set(frame);
575 }
576
578}
579
580/** Mark the entire stack as cancelled
581 *
582 * This cancels all frames up to the next "break" frame.
583 *
584 * @param[out] depth_p Depth of the break || return || continue point.
585 * @param[in] stack The current stack.
586 * @param[in] flag Flag to search for. One of:
587 * - UNLANG_OP_FLAG_BREAK_POINT
588 * - UNLANG_OP_FLAG_RETURN_POINT
589 * - UNLANG_OP_FLAG_CONTINUE_POINT
590 * @return UNLANG_ACTION_CALCULATE_RESULT
591 */
592static inline unlang_action_t unwind_to_op_flag(unsigned int *depth_p, unlang_stack_t *stack, unlang_op_flag_t flag)
593{
594 unsigned int depth;
595
597 if (depth == 0) {
598 if (depth_p) *depth_p = stack->depth + 1; /* Don't cancel any frames! */
600 }
601
602 unwind_to_depth(stack, depth + 1); /* cancel UP TO the break point */
603
604 if (depth_p) *depth_p = depth;
605
607}
608
610{
611 unlang_stack_t *stack = request->stack;
612
613 return &stack->frame[stack->depth];
614}
615
616static inline int stack_depth_current(request_t *request)
617{
618 unlang_stack_t *stack = request->stack;
619
620 return stack->depth;
621}
622
623/** Initialise memory and instruction for a frame when a new instruction is to be evaluated
624 *
625 * @note We don't change frame->p_result here, we only reset the scratch values. This is because
626 * Whatever pushed the frame onto the stack generally wants the aggregate result of
627 * the complete section, not just the first instruction.
628 *
629 * @param[in] stack the current request stack.
630 * @param[in] frame frame to initialise
631 */
633{
634 unlang_t const *instruction = frame->instruction;
635 unlang_op_t *op;
636 char const *name;
637
639
640 op = &unlang_ops[instruction->type];
641 name = op->frame_state_type ? op->frame_state_type : __location__;
642
643 /*
644 * Reset for each instruction
645 */
647
648 frame->process = op->interpret;
649 frame->signal = op->signal;
650
651#ifdef HAVE_TALLOC_ZERO_POOLED_OBJECT
652 /*
653 * Pooled object
654 */
656 MEM(frame->state = _talloc_zero_pooled_object(stack,
660 } else
661#endif
662 /*
663 * Pool
664 */
665 if (op->frame_state_pool_size && !op->frame_state_size) {
666 MEM(frame->state = talloc_pool(stack,
668 ((20 + 68 + 15) * op->frame_state_pool_objects))); /* from samba talloc.c */
669 talloc_set_name_const(frame->state, name);
670 /*
671 * Object
672 */
673 } else if (op->frame_state_size) {
674 MEM(frame->state = _talloc_zero(stack, op->frame_state_size, name));
675 }
676
677 /*
678 * Don't change frame->retry, it may be left over from a previous retry.
679 */
680}
681
682/** Cleanup any lingering frame state
683 *
684 */
685static inline void frame_cleanup(unlang_stack_frame_t *frame)
686{
688
689 /*
690 * Don't clear top_frame flag, bad things happen...
691 */
693 TALLOC_FREE(frame->retry);
694 if (frame->state) {
695 talloc_free_children(frame->state); /* *(ev->parent) = NULL in event.c */
696 TALLOC_FREE(frame->state);
697 }
698}
699
700/** Advance to the next sibling instruction
701 *
702 */
704{
705 frame_cleanup(frame);
706 frame->instruction = frame->next;
707
708 if (!frame->instruction) return; /* No siblings, need to pop instead */
709
710 frame->next = unlang_list_next(frame->instruction->list, frame->instruction);
711
712 /*
713 * We _may_ want to take a new frame->p_result value in future but
714 * for now default to the scratch result. Generally the thing
715 * advancing the frame is within this library, and doesn't
716 * need custom behaviour for rcodes.
717 */
718 frame_state_init(stack, frame);
719}
720
721/** Pop a stack frame, removing any associated dynamically allocated state
722 *
723 * @param[in] request The current request.
724 * @param[in] stack frame to pop.
725 */
726static inline void frame_pop(request_t *request, unlang_stack_t *stack)
727{
729
730 fr_assert(stack->depth >= 1);
731
732 frame = &stack->frame[stack->depth];
733
734 /*
735 * Signal the frame to get it back into a consistent state
736 * as we won't be calling the resume function.
737 *
738 * If the frame was cancelled, the signal function will
739 * have already been called.
740 */
741 if (!is_unwinding(frame) && is_repeatable(frame)) {
742 if (frame->signal) frame->signal(request, frame, FR_SIGNAL_CANCEL);
743 repeatable_clear(frame);
744 }
745
746 /*
747 * We clean up the retries when we pop the frame, not
748 * when we do a frame_cleanup(). That's because
749 * frame_cleanup() is called from the signal handler, and
750 * we need to keep frame->retry around to ensure that we
751 * know how to _stop_ the retries after they've hit a timeout.
752 */
753 TALLOC_FREE(frame->retry);
754
755 /*
756 * Ensure log indent is at the same level as it was when
757 * the frame was pushed. This is important when we're
758 * unwinding the stack and forcefully cancelling calls.
759 */
760 request->log.indent = frame->indent;
761
762 frame_cleanup(frame);
763
764 stack->depth--;
765}
766
767/** Mark the current stack frame up for repeat, and set a new process function
768 *
769 */
770static inline void frame_repeat(unlang_stack_frame_t *frame, unlang_process_t process)
771{
772 repeatable_set(frame);
773 frame->process = process;
774}
775
777{
778 /*
779 * We're skipping the remaining siblings, stop the
780 * interpreter from continuing and have it pop
781 * this frame, running cleanups normally.
782 *
783 * We don't explicitly cleanup here, otherwise we
784 * end up doing it twice and bad things happen.
785 */
786 if (!unlang) {
787 frame->next = NULL;
789 }
790
791 /*
792 * Clean up this frame now, so that stats, etc. will be
793 * processed using the correct frame.
794 */
795 frame_cleanup(frame);
796
797 /*
798 * frame_next() will call cleanup *before* resetting the frame->instruction.
799 * but since the instruction is NULL, no duplicate cleanups will happen.
800 *
801 * frame_next() will then set frame->instruction = frame->next, and everything will be OK.
802 */
803 frame->instruction = NULL;
804 frame->next = unlang;
806}
807
808/** @name Conversion functions for converting #unlang_t to its specialisations
809 *
810 * Simple conversions: #unlang_module_t and #unlang_group_t are subclasses of #unlang_t,
811 * so we often want to go back and forth between them.
812 *
813 * @{
814 */
816{
818
819 return UNCONST(unlang_group_t *, p);
820}
821
823{
824 return UNCONST(unlang_t *, p);
825}
826
827static inline CC_HINT(always_inline) unlang_list_t *unlang_list(unlang_t *unlang)
828{
829 return &unlang_generic_to_group(unlang)->children;
830}
831
832static inline CC_HINT(always_inline) void unlang_type_init(unlang_t *unlang, unlang_t *parent, unlang_type_t type)
833{
834 unlang->type = type;
835 unlang->parent = parent;
836 if (parent) unlang->list = unlang_list(parent);
837 unlang_list_entry_init(unlang);
838}
839
840static inline CC_HINT(always_inline) void unlang_group_type_init(unlang_t *unlang, unlang_t *parent, unlang_type_t type)
841{
842 unlang_type_init(unlang, parent, type);
843 unlang_list_init(&((unlang_group_t *) unlang)->children);
844}
845
851
853{
854 return UNCONST(unlang_t *, p);
855}
856/** @} */
857
858/** @name Internal interpreter functions needed by ops
859 *
860 * @{
861 */
862int unlang_interpret_push(unlang_result_t *p_result, request_t *request, unlang_t const *instruction,
863 unlang_frame_conf_t const *conf, bool do_next_sibling)
864 CC_HINT(warn_unused_result);
865
867 rlm_rcode_t default_rcode, bool do_next_sibling)
868 CC_HINT(warn_unused_result);
869
871
872void unlang_op_free(void);
873
874/** @} */
875
876/** @name io shims
877 *
878 * Functions to simulate a 'proto' module when we're running 'fake'
879 * requests. i.e. those created by parallel and subrequest.
880 *
881 * @{
882 */
883request_t *unlang_io_subrequest_alloc(request_t *parent, fr_dict_t const *namespace, bool detachable);
884
885/** @} */
886
887/** @name op init functions
888 *
889 * Functions to trigger registration of the various unlang ops.
890 *
891 * @{
892 */
893void unlang_register(unlang_op_t *op) CC_HINT(nonnull);
894
895void unlang_call_init(void);
896
897void unlang_caller_init(void);
898
899void unlang_condition_init(void);
900
901void unlang_finally_init(void);
902
903void unlang_foreach_init(void);
904
905void unlang_function_init(void);
906
907void unlang_group_init(void);
908
909void unlang_load_balance_init(void);
910
911void unlang_map_init(void);
912
913void unlang_module_init(void);
914
915void unlang_return_init(void);
916
917void unlang_parallel_init(void);
918
920
921void unlang_detach_init(void);
922
923void unlang_switch_init(void);
924
925void unlang_tmpl_init(void);
926
927void unlang_edit_init(void);
928
929void unlang_timeout_init(void);
930
931void unlang_transaction_init(void);
932
933void unlang_limit_init(void);
934
935void unlang_try_init(void);
936
937void unlang_catch_init(void);
938
939 /** @} */
940
941#ifdef __cplusplus
942}
943#endif
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
@ UNLANG_ACTION_EXECUTE_NEXT
Execute the next unlang_t.
Definition action.h:38
@ UNLANG_ACTION_FAIL
Encountered an unexpected error.
Definition action.h:36
@ UNLANG_ACTION_CALCULATE_RESULT
Calculate a new section rlm_rcode_t value.
Definition action.h:37
#define UNCONST(_type, _ptr)
Remove const qualification from a pointer.
Definition build.h:167
#define DIAG_ON(_x)
Definition build.h:460
#define UNUSED
Definition build.h:317
#define DIAG_OFF(_x)
Definition build.h:459
Common header for all CONF_* types.
Definition cf_priv.h:49
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:101
#define fr_cond_assert(_x)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
Definition debug.h:131
#define fr_cond_assert_msg(_x, _fmt,...)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
Definition debug.h:148
#define MEM(x)
Definition debug.h:36
fr_dict_t const * fr_dict_internal(void)
Definition dict_util.c:4745
#define FR_DLIST_TYPES(_name)
Define type specific wrapper structs for dlists.
Definition dlist.h:1129
#define FR_DLIST_FUNCS(_name, _element_type, _element_entry)
Define type specific wrapper functions for dlists.
Definition dlist.h:1152
#define FR_DLIST_TYPEDEFS(_name, _head, _entry)
Define friendly names for type specific dlist head and entry structures.
Definition dlist.h:1139
#define UNLANG_STACK_MAX
The maximum depth of the stack.
Definition interpret.h:39
#define UNLANG_RESULT_NOT_SET
Definition interpret.h:139
Configuration structure to make it easier to pass configuration options to initialise the frame with.
Definition interpret.h:144
static TALLOC_CTX * unlang_ctx
Definition base.c:71
static char * stack[MAX_STACK]
Definition radmin.c:159
fr_type_t
unsigned int uint32_t
unsigned char uint8_t
static uint8_t depth(fr_minmax_heap_index_t i)
Definition minmax_heap.c:83
@ MOD_ACTION_RETRY
retry the instruction, MUST also set a retry config
Definition mod_action.h:38
#define MOD_ACTION_VALID(_x)
Definition mod_action.h:60
unlang_mod_action_t actions[RLM_MODULE_NUMCODES]
Definition mod_action.h:64
#define fr_assert(_expr)
Definition rad_assert.h:38
static rs_t * conf
Definition radsniff.c:53
rlm_rcode_t
Return codes indicating the result of the module call.
Definition rcode.h:40
@ RLM_MODULE_NUMCODES
How many valid return codes there are.
Definition rcode.h:53
static char const * name
bool at_runtime
Produce an ephemeral/runtime tmpl.
Definition tmpl.h:344
tmpl_attr_rules_t attr
Rules/data for parsing attribute references.
Definition tmpl.h:335
Optional arguments passed to vp_tmpl functions.
Definition tmpl.h:332
fr_signal_t
Signals that can be generated/processed by request signal handlers.
Definition signal.h:38
@ FR_SIGNAL_CANCEL
Request has been cancelled.
Definition signal.h:40
fr_aka_sim_id_type_t type
Value pair map.
Definition map.h:77
Define entry and head types for tmpl request references.
Definition tmpl.h:272
uint8_t allow_foreign
Allow arguments not found in dict_def.
Definition tmpl.h:312
fr_dict_t const * dict_def
Default dictionary to use with unqualified attribute references.
Definition tmpl.h:273
An element in a lexicographically sorted array of name to num mappings.
Definition table.h:49
#define talloc_get_type_abort_const
Definition talloc.h:287
A timer event.
Definition timer.c:84
fr_retry_state_t state
#define unlang_frame_perf_resume(_x)
void stack_dump_with_actions(request_t *request)
Definition interpret.c:253
unlang_result_t section_result
The aggregate result of executing all siblings in this section.
static unlang_action_t unwind_to_op_flag(unsigned int *depth_p, unlang_stack_t *stack, unlang_op_flag_t flag)
Mark the entire stack as cancelled.
static unlang_action_t frame_set_next(unlang_stack_frame_t *frame, unlang_t const *unlang)
unlang_t * unlang_compile_children(unlang_group_t *g, unlang_compile_ctx_t *unlang_ctx)
Definition compile.c:1287
size_t frame_state_pool_objects
How many sub-allocations we expect.
static void frame_pop(request_t *request, unlang_stack_t *stack)
Pop a stack frame, removing any associated dynamically allocated state.
static void frame_next(unlang_stack_t *stack, unlang_stack_frame_t *frame)
Advance to the next sibling instruction.
unlang_frame_flag_t
@ UNLANG_FRAME_FLAG_TOP_FRAME
are we the top frame of the stack? If true, causes the interpreter to stop interpreting and return,...
@ UNLANG_FRAME_FLAG_REPEAT
Repeat the frame on the way up the stack.
@ UNLANG_FRAME_FLAG_NONE
No flags.
@ UNLANG_FRAME_FLAG_UNWIND
This frame should be unwound without evaluation.
@ UNLANG_FRAME_FLAG_YIELDED
frame has yielded
void unlang_switch_init(void)
Definition switch.c:518
static bool _instruction_has_debug_braces(unlang_t const *instruction)
static unsigned int unlang_frame_by_flag(unlang_stack_t *stack, unlang_frame_flag_t flag)
Find the first frame with a given flag.
unlang_t * unlang_compile_section(unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_SECTION *cs, unlang_type_t type)
Definition compile.c:1507
static bool is_cancellable(unlang_stack_frame_t const *frame)
static bool is_repeatable(unlang_stack_frame_t const *frame)
unlang_interpret_t * intp
Interpreter that the request is currently associated with.
CONF_SECTION * cs
unlang_result_t * p_result
Where to write the result of executing the current instruction.
static void repeatable_clear(unlang_stack_frame_t *frame)
static unlang_action_t unwind_to_depth(unlang_stack_t *stack, unsigned int to_depth)
Mark up frames as cancelled so they're immediately popped by the interpreter.
bool pass2_fixup_map_rhs(unlang_group_t *g, tmpl_rules_t const *rules)
Definition compile.c:214
unlang_retry_t * retry
if the frame is being retried.
void unlang_finally_init(void)
Definition finally.c:172
unlang_signal_t signal
function to call when signalling this stack frame
char const * debug_name
Printed in log messages when the node is executed.
unlang_mod_actions_t actions
char const * frame_state_type
talloc name of the frame instance data
void * state
Stack frame specialisations.
unlang_mod_actions_t actions
Priorities, etc. for the various return codes.
void(* unlang_signal_t)(request_t *request, unlang_stack_frame_t *frame, fr_signal_t action)
Function to call if the request was signalled.
virtual_server_t const * vs
Virtual server we're compiling in the context of.
tmpl_rules_t const * rules
bool pass2_fixup_tmpl(UNUSED TALLOC_CTX *ctx, tmpl_t **vpt_p, CONF_ITEM const *ci, fr_dict_t const *dict)
Definition compile.c:95
unlang_t * parent
Previous node.
static unsigned int unlang_frame_by_op_flag(unlang_stack_t *stack, unlang_op_flag_t flag)
Find the first frame with a given flag.
void unlang_limit_init(void)
Definition limit.c:229
bool unlang_compile_limit_subsection(CONF_SECTION *cs, char const *name)
Definition compile.c:1585
static void unlang_type_init(unlang_t *unlang, unlang_t *parent, unlang_type_t type)
unlang_signal_t signal
Function to signal stop / dup / whatever.
int unlang_subrequest_op_init(void)
Initialise subrequest ops.
Definition subrequest.c:803
size_t frame_state_size
size of instance data in the stack frame
static void unwind_set(unlang_stack_frame_t *frame)
unlang_t *(* unlang_compile_t)(unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_ITEM const *ci)
char const * thread_inst_type
fr_dict_attr_t const * root
the root of our dictionary
int(* unlang_thread_instantiate_t)(unlang_t const *instruction, void *thread_inst)
void unlang_timeout_init(void)
Definition timeout.c:274
size_t pool_len
How much additional space to allocate for chunks.
static void frame_state_init(unlang_stack_t *stack, unlang_stack_frame_t *frame)
Initialise memory and instruction for a frame when a new instruction is to be evaluated.
static void unlang_compile_ctx_copy(unlang_compile_ctx_t *dst, unlang_compile_ctx_t const *src)
#define unlang_frame_perf_init(_x)
unlang_t * unlang_compile_empty(unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_SECTION *cs, unlang_type_t type)
void unlang_edit_init(void)
Definition edit.c:1750
void stack_dump(request_t *request)
Definition interpret.c:248
void unlang_tmpl_init(void)
Definition tmpl.c:366
void unlang_call_init(void)
Definition call.c:313
void unlang_map_init(void)
Definition map.c:440
bool closed
whether or not this section is closed to new statements
unlang_dump_t dump
Dump additional information about the frame state.
static bool _frame_has_debug_braces(unlang_stack_frame_t const *frame)
static unlang_t * unlang_group_to_generic(unlang_group_t const *p)
void unlang_condition_init(void)
Definition condition.c:277
rindent_t indent
Indent level of the request when the frame was created.
uint8_t unwind
Unwind to this frame if it exists.
static void top_frame_clear(unlang_stack_frame_t *frame)
fr_timer_t * ev
unlang_process_t interpret
Function to interpret the keyword.
unlang_result_t scratch_result
The result of executing the current instruction.
unlang_t self
int depth
of this retry structure
char const * unlang_name
Talloc type name for the unlang_t.
static void frame_cleanup(unlang_stack_frame_t *frame)
Cleanup any lingering frame state.
static unlang_t * unlang_tmpl_to_generic(unlang_tmpl_t const *p)
void unlang_op_free(void)
request_t * request
void unlang_load_balance_init(void)
CONF_ITEM * ci
used to generate this item
static bool is_top_frame(unlang_stack_frame_t const *frame)
static unlang_group_t * unlang_generic_to_group(unlang_t const *p)
void(* unlang_dump_t)(request_t *request, unlang_stack_frame_t *frame)
Custom callback for dumping information about frame state.
unsigned int number
unique node number
void unlang_group_init(void)
Definition group.c:49
size_t unlang_size
Total length of the unlang_t + specialisation struct.
char const * section_name1
size_t mod_rcode_table_len
Definition compile.c:88
void unlang_parallel_init(void)
Definition parallel.c:446
static unlang_stack_frame_t * frame_current(request_t *request)
unlang_list_t children
void unlang_transaction_init(void)
static bool is_private_result(unlang_stack_frame_t const *frame)
int depth
Current depth we're executing at.
char const * name
Unknown...
request_t * unlang_io_subrequest_alloc(request_t *parent, fr_dict_t const *namespace, bool detachable)
Allocate a child request based on the parent.
Definition io.c:39
static int stack_depth_current(request_t *request)
static bool is_break_point(unlang_stack_frame_t const *frame)
static void unwind_clear(unlang_stack_frame_t *frame)
void unlang_return_init(void)
Definition return.c:68
void unlang_detach_init(void)
Initialise subrequest ops.
Definition detach.c:82
unlang_type_t
Types of unlang_t nodes.
Definition unlang_priv.h:47
@ UNLANG_TYPE_SWITCH
Switch section.
Definition unlang_priv.h:59
@ UNLANG_TYPE_TRANSACTION
transactions for editing lists
Definition unlang_priv.h:75
@ UNLANG_TYPE_FINALLY
run at the end of a virtual server.
Definition unlang_priv.h:78
@ UNLANG_TYPE_SUBREQUEST
create a child subrequest
Definition unlang_priv.h:67
@ UNLANG_TYPE_CONTINUE
Break statement (within a UNLANG_TYPE_FOREACH).
Definition unlang_priv.h:63
@ UNLANG_TYPE_ELSIF
!Condition && Condition.
Definition unlang_priv.h:58
@ UNLANG_TYPE_ELSE
!Condition.
Definition unlang_priv.h:57
@ UNLANG_TYPE_LOAD_BALANCE
Load balance section.
Definition unlang_priv.h:53
@ UNLANG_TYPE_DETACH
detach a child
Definition unlang_priv.h:70
@ UNLANG_TYPE_GROUP
Grouping section.
Definition unlang_priv.h:51
@ UNLANG_TYPE_POLICY
Policy section.
Definition unlang_priv.h:79
@ UNLANG_TYPE_TMPL
asynchronously expand a tmpl_t
Definition unlang_priv.h:81
@ UNLANG_TYPE_CASE
Case section (within a UNLANG_TYPE_SWITCH).
Definition unlang_priv.h:60
@ UNLANG_TYPE_LIMIT
limit number of requests in a section
Definition unlang_priv.h:74
@ UNLANG_TYPE_BREAK
Break statement (within a UNLANG_TYPE_FOREACH or UNLANG_TYPE_CASE).
Definition unlang_priv.h:62
@ UNLANG_TYPE_TRY
try / catch blocks
Definition unlang_priv.h:76
@ UNLANG_TYPE_CALL
call another virtual server
Definition unlang_priv.h:71
@ UNLANG_TYPE_RETURN
Return statement.
Definition unlang_priv.h:64
@ UNLANG_TYPE_REDUNDANT
exactly like group, but with different default return codes
Definition unlang_priv.h:52
@ UNLANG_TYPE_MAX
Definition unlang_priv.h:83
@ UNLANG_TYPE_IF
Condition.
Definition unlang_priv.h:56
@ UNLANG_TYPE_XLAT
Represents one level of an xlat expansion.
Definition unlang_priv.h:80
@ UNLANG_TYPE_NULL
unlang type not set.
Definition unlang_priv.h:48
@ UNLANG_TYPE_MAP
Mapping section (like #UNLANG_TYPE_UPDATE, but uses values from a map_proc_t call).
Definition unlang_priv.h:65
@ UNLANG_TYPE_CALLER
conditionally check parent dictionary type
Definition unlang_priv.h:72
@ UNLANG_TYPE_TIMEOUT
time-based timeouts.
Definition unlang_priv.h:73
@ UNLANG_TYPE_MODULE
Module method.
Definition unlang_priv.h:49
@ UNLANG_TYPE_REDUNDANT_LOAD_BALANCE
Redundant load balance section.
Definition unlang_priv.h:54
@ UNLANG_TYPE_CHILD_REQUEST
a frame at the top of a child's request stack used to signal the parent when the child is complete.
Definition unlang_priv.h:68
@ UNLANG_TYPE_CATCH
catch a previous try
Definition unlang_priv.h:77
@ UNLANG_TYPE_FUNCTION
Internal call to a function or submodule.
Definition unlang_priv.h:50
@ UNLANG_TYPE_EDIT
edit VPs in place. After 20 years!
Definition unlang_priv.h:82
@ UNLANG_TYPE_FOREACH
Foreach section.
Definition unlang_priv.h:61
@ UNLANG_TYPE_PARALLEL
execute statements in parallel
Definition unlang_priv.h:55
static void frame_repeat(unlang_stack_frame_t *frame, unlang_process_t process)
Mark the current stack frame up for repeat, and set a new process function.
unlang_t const * instruction
The unlang node we're evaluating.
static unlang_list_t * unlang_list(unlang_t *unlang)
unsigned pool_headers
How much additional space to allocate for chunk headers.
static bool is_rcode_set(unlang_stack_frame_t const *frame)
void unlang_try_init(void)
Definition try.c:254
static bool is_yielded(unlang_stack_frame_t const *frame)
fr_hash_table_t * unlang_op_table
Definition base.c:45
void unlang_catch_init(void)
Definition catch.c:132
size_t frame_state_pool_size
The total size of the pool to alloc.
unlang_compile_t compile
compile the keyword
static void top_frame_set(unlang_stack_frame_t *frame)
unlang_variable_t * variables
rarely used, so we don't usually need it
unlang_type_t type
enum value for the keyword
unlang_group_t * unlang_group_allocate(unlang_t *parent, CONF_SECTION *cs, unlang_type_t type)
Definition compile.c:446
int unlang_interpret_push(unlang_result_t *p_result, request_t *request, unlang_t const *instruction, unlang_frame_conf_t const *conf, bool do_next_sibling)
Push a new frame onto the stack.
Definition interpret.c:280
static unlang_tmpl_t * unlang_generic_to_tmpl(unlang_t const *p)
void unlang_module_init(void)
Definition module.c:991
unlang_t const * instruction
instruction which we're executing
bool pass2_fixup_map(map_t *map, tmpl_rules_t const *rules, fr_dict_attr_t const *parent)
Fixup ONE map (recursively)
Definition compile.c:123
char const * name
Name of the keyword.
unlang_frame_action_t
Allows the frame evaluator to signal the interpreter.
Definition unlang_priv.h:89
@ UNLANG_FRAME_ACTION_POP
Pop the current frame, and check the next one further up in the stack for what to do next.
Definition unlang_priv.h:90
@ UNLANG_FRAME_ACTION_YIELD
Temporarily return control back to the caller on the C stack.
Definition unlang_priv.h:94
@ UNLANG_FRAME_ACTION_NEXT
Process the next instruction at this level.
Definition unlang_priv.h:93
@ UNLANG_FRAME_ACTION_RETRY
retry the current frame
Definition unlang_priv.h:92
static void yielded_set(unlang_stack_frame_t *frame)
static bool is_continue_point(unlang_stack_frame_t const *frame)
bool pass2_fixup_update(unlang_group_t *g, tmpl_rules_t const *rules)
Definition compile.c:187
void unlang_function_init(void)
Definition function.c:559
static void yielded_clear(unlang_stack_frame_t *frame)
#define unlang_frame_perf_yield(_x)
#define unlang_frame_perf_cleanup(_x)
unlang_t const * next
The next unlang node we will evaluate.
unlang_op_t unlang_ops[]
Different operations the interpreter can execute.
Definition base.c:31
fr_table_num_sorted_t const mod_rcode_table[]
Definition compile.c:75
unlang_entry_t entry
next / prev entries
int max_attr
1..N local attributes have been defined
static int unlang_attr_rules_verify(tmpl_attr_rules_t const *rules)
unlang_thread_instantiate_t thread_instantiate
per-thread instantiation function
fr_dict_t * dict
our dictionary
static void unlang_group_type_init(unlang_t *unlang, unlang_t *parent, unlang_type_t type)
void unlang_stack_signal(request_t *request, fr_signal_t action, int limit)
Delivers a frame to one or more frames in the stack.
Definition interpret.c:1337
void * unlang_thread_instance(unlang_t const *instruction)
Get the thread-instance data for an instruction.
Definition compile.c:2339
static bool is_return_point(unlang_stack_frame_t const *frame)
tmpl_t const * tmpl
unlang_op_flag_t
@ UNLANG_OP_FLAG_RETURN_POINT
Return point.
@ UNLANG_OP_FLAG_NO_FORCE_UNWIND
Must not be cancelled.
@ UNLANG_OP_FLAG_SINGLE_WORD
the operation is parsed and compiled as a single word
@ UNLANG_OP_FLAG_CONTINUE_POINT
Continue point.
@ UNLANG_OP_FLAG_DEBUG_BRACES
Print debug braces.
@ UNLANG_OP_FLAG_NONE
No flags.
@ UNLANG_OP_FLAG_RCODE_SET
Set request->rcode to the result of this operation.
@ UNLANG_OP_FLAG_INTERNAL
it's not a real keyword
@ UNLANG_OP_FLAG_BREAK_POINT
Break point.
static void repeatable_set(unlang_stack_frame_t *frame)
unlang_action_t(* unlang_process_t)(unlang_result_t *p_result, request_t *request, unlang_stack_frame_t *frame)
Function to call when interpreting a frame.
void unlang_foreach_init(void)
Definition foreach.c:842
void unlang_register(unlang_op_t *op)
Register an operation with the interpreter.
Definition base.c:56
void unlang_caller_init(void)
Definition caller.c:142
unlang_process_t process
function to call for interpreting this stack frame
unlang_type_t type
The specialisation of this node.
unlang_frame_flag_t flag
Flags that mark up the frame for various things such as being the point where break,...
char const * section_name2
unlang_action_t unlang_interpret_push_children(unlang_result_t *p_result, request_t *request, rlm_rcode_t default_rcode, bool do_next_sibling)
Push the children of the current frame onto a new frame onto the stack.
Definition interpret.c:384
int unlang_define_local_variable(CONF_ITEM *ci, unlang_variable_t *var, tmpl_rules_t *t_rules, fr_type_t type, char const *name, fr_dict_attr_t const *ref)
Definition compile.c:1884
size_t thread_inst_size
unlang_op_flag_t flag
Interpreter flags for this operation.
int unlang_op_init(void)
unlang_list_t * list
so we have fewer run-time dereferences
static bool is_unwinding(unlang_stack_frame_t const *frame)
void * thread_inst
thread-specific instance data
static int unlang_rules_verify(tmpl_rules_t const *rules)
Generic representation of a grouping.
An unlang operation.
A node in a graph of unlang_op_t (s) that we execute.
Our interpreter stack, as distinct from the C stack.
An unlang stack associated with a request.
A naked xlat.
static fr_slen_t parent
Definition pair.h:841
fr_retry_state_t
Definition retry.h:45
int nonnull(2, 5))