The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
interpret.c
Go to the documentation of this file.
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
15 */
16
17/**
18 * $Id: c3a98af7297be5bc4d315ea55264c53955ae6fc0 $
19 *
20 * @file unlang/interpret.c
21 * @brief Execute compiled unlang structures using an iterative interpret.
22 *
23 * @copyright 2006-2016 The FreeRADIUS server project
24 */
25RCSID("$Id: c3a98af7297be5bc4d315ea55264c53955ae6fc0 $")
26
27#include <freeradius-devel/server/base.h>
28#include <freeradius-devel/server/modpriv.h>
29#include <freeradius-devel/unlang/xlat_func.h>
30#include <freeradius-devel/unlang/xlat.h>
31#include <freeradius-devel/util/time.h>
32
33#include "interpret_priv.h"
34#include "module_priv.h"
35#include "parallel_priv.h"
36
37
38/** The default interpreter instance for this thread
39 */
41
43 { L("unwind"), UNLANG_ACTION_UNWIND },
44 { L("calculate-result"), UNLANG_ACTION_CALCULATE_RESULT },
45 { L("next"), UNLANG_ACTION_EXECUTE_NEXT },
46 { L("pushed-child"), UNLANG_ACTION_PUSHED_CHILD },
48 { L("yield"), UNLANG_ACTION_YIELD }
49};
51
58
59#ifndef NDEBUG
60static void instruction_dump(request_t *request, unlang_t const *instruction)
61{
62 RINDENT();
63 if (!instruction) {
64 RDEBUG2("instruction <none>");
65 REXDENT();
66 return;
67 }
68
69 RDEBUG2("type %s", unlang_ops[instruction->type].name);
70 RDEBUG2("name %s", instruction->name);
71 RDEBUG2("debug_name %s", instruction->debug_name);
72 REXDENT();
73}
74
75static void frame_dump(request_t *request, unlang_stack_frame_t *frame)
76{
77 unlang_op_t *op = NULL;
78
79 if (frame->instruction) op = &unlang_ops[frame->instruction->type];
80
81 instruction_dump(request, frame->instruction);
82
83 RINDENT();
84 if (frame->state) RDEBUG2("state %s (%p)", talloc_get_name(frame->state), frame->state);
85 if (frame->next) {
86 RDEBUG2("next %s", frame->next->debug_name);
87 } else {
88 RDEBUG2("next <none>");
89 }
90 RDEBUG2("result %s", fr_table_str_by_value(mod_rcode_table, frame->result, "<invalid>"));
91 RDEBUG2("priority %d", frame->priority);
92 RDEBUG2("top_frame %s", is_top_frame(frame) ? "yes" : "no");
93 RDEBUG2("repeat %s", is_repeatable(frame) ? "yes" : "no");
94 RDEBUG2("break_point %s", is_break_point(frame) ? "yes" : "no");
95 RDEBUG2("return_point %s", is_return_point(frame) ? "yes" : "no");
96 RDEBUG2("resumable %s", is_yielded(frame) ? "yes" : "no");
97
98 /*
99 * Call the custom frame dump function
100 */
101 if (op && op->dump) op->dump(request, frame);
102
103 REXDENT();
104}
105
106static char *stack_unwind_flag_dump(uint8_t unwind)
107{
108 static __thread char buf[256];
109 size_t len;
110
111#define UNWIND_FLAG_DUMP(attrib) \
112 if (unwind & attrib) strcat(buf, #attrib" ")
113
114 snprintf(buf, sizeof(buf), "unwind=0x%x (", unwind);
115
119
120 len = strlen(buf);
121 if (buf[len - 1] == ' ') buf[len - 1] = '\0'; /* Trim trailing space */
122 strcat(buf, ")");
123
124#undef UNWIND_FLAG_DUMP
125
126 return buf;
127}
128
129static void stack_dump(request_t *request)
130{
131 int i;
132 unlang_stack_t *stack = request->stack;
133
134 RDEBUG2("----- Begin stack debug [depth %i, %s] -----", stack->depth, stack_unwind_flag_dump(stack->unwind));
135 for (i = stack->depth; i >= 0; i--) {
136 unlang_stack_frame_t *frame = &stack->frame[i];
137
138 RDEBUG2("[%d] Frame contents", i);
139 frame_dump(request, frame);
140 }
141 RDEBUG2("----- End stack debug [depth %i, %s] -------", stack->depth, stack_unwind_flag_dump(stack->unwind));
142}
143#define DUMP_STACK if (DEBUG_ENABLED5) stack_dump(request)
144#else
145#define DUMP_STACK
146#endif
147
148/** Push a new frame onto the stack
149 *
150 * @param[in] request to push the frame onto.
151 * @param[in] instruction One or more unlang_t nodes describing the operations to execute.
152 * @param[in] default_rcode The default result.
153 * @param[in] do_next_sibling Whether to only execute the first node in the #unlang_t program
154 * or to execute subsequent nodes.
155 * @param[in] top_frame Return out of the unlang interpret when popping this frame.
156 * Hands execution back to whatever called the interpret.
157 * @return
158 * - 0 on success.
159 * - -1 on call stack too deep.
160 */
161int unlang_interpret_push(request_t *request, unlang_t const *instruction,
162 rlm_rcode_t default_rcode, bool do_next_sibling, bool top_frame)
163{
164 unlang_stack_t *stack = request->stack;
166
167 fr_assert(instruction || top_frame);
168
169#ifndef NDEBUG
170 if (DEBUG_ENABLED5) RDEBUG3("unlang_interpret_push called with instruction type \"%s\" - args %s %s",
171 instruction ? instruction->debug_name : "<none>",
172 do_next_sibling ? "UNLANG_NEXT_SIBLING" : "UNLANG_NEXT_STOP",
173 top_frame ? "UNLANG_TOP_FRAME" : "UNLANG_SUB_FRAME");
174#endif
175
176 /*
177 * This is not a cancellation point.
178 *
179 * If we cancel here bad things happen inside the interpret.
180 */
181 if (stack->depth >= (UNLANG_STACK_MAX - 1)) {
182 RERROR("Call stack is too deep");
183 return - 1;
184 }
185
186 stack->depth++;
187
188 /*
189 * Initialize the next stack frame.
190 */
191 frame = &stack->frame[stack->depth];
192 memset(frame, 0, sizeof(*frame));
193
194 frame->instruction = instruction;
195
196 if (do_next_sibling) {
197 fr_assert(instruction != NULL);
198 frame->next = instruction->next;
199 }
200 /* else frame->next MUST be NULL */
201
202 frame->uflags = UNWIND_FLAG_NONE;
203 if (top_frame) top_frame_set(frame);
204
205 frame->result = default_rcode;
206 frame->priority = -1;
207
208 if (!instruction) return 0;
209
210 frame_state_init(stack, frame);
211
212 return 0;
213}
214
219
221{
222 fr_pair_t *vp, *prev;
223
224 /*
225 * Local variables are appended to the end of the list. So we remove them by walking backwards
226 * from the end of the list.
227 */
228 vp = fr_pair_list_tail(&ref->request->local_pairs);
229 while (vp) {
230 prev = fr_pair_list_prev(&ref->request->local_pairs, vp);
231 if (vp->da->dict != ref->dict) {
232 break;
233 }
234
235 (void) fr_pair_delete(&ref->request->local_pairs, vp);
236 vp = prev;
237 }
238
239 return 0;
240}
241
242/** Push the children of the current frame onto a new frame onto the stack
243 *
244 * @param[out] p_result set to RLM_MOULDE_FAIL if pushing the children fails
245 * @param[in] request to push the frame onto.
246 * @param[in] default_rcode The default result.
247 * @param[in] do_next_sibling Whether to only execute the first node in the #unlang_t program
248 * or to execute subsequent nodes.
249 * @return
250 * - UNLANG_ACTION_PUSHED_CHILD on success.
251 * - UNLANG_ACTION_EXECUTE_NEXT do nothing, but just go to the next sibling instruction
252 * - UNLANG_ACTION_STOP_PROCESSING, fatal error, usually stack overflow.
253 */
255 rlm_rcode_t default_rcode, bool do_next_sibling)
256{
257 unlang_stack_t *stack = request->stack;
258 unlang_stack_frame_t *frame = &stack->frame[stack->depth]; /* Quiet static analysis */
261
263
265
266 /*
267 * The compiler catches most of these, EXCEPT for the
268 * top-level 'recv Access-Request' etc. Which can exist,
269 * and can be empty.
270 */
271 if (!g->children) {
272 RDEBUG2("<ignoring empty subsection>");
274 }
275
276 if (unlang_interpret_push(request, g->children, default_rcode, do_next_sibling, UNLANG_SUB_FRAME) < 0) {
277 *p_result = RLM_MODULE_FAIL;
279 }
280
282
283 /*
284 * Note that we do NOT create the variables, This way we don't have to worry about any
285 * uninitialized values. If the admin tries to use the variable without initializing it, they
286 * will get a "no such attribute" error.
287 */
288 if (!frame->state) {
289 MEM(ref = talloc(stack, unlang_variable_ref_t));
290 frame->state = ref;
291 } else {
292 MEM(ref = talloc(frame->state, unlang_variable_ref_t));
293 }
294
295 /*
296 * Set the destructor to clean up local variables.
297 */
298 ref->dict = g->variables->dict;
299 ref->request = request;
300 talloc_set_destructor(ref, _local_variables_free);
301
303}
304
305static void instruction_timeout_handler(UNUSED fr_timer_list_t *tl, UNUSED fr_time_t now, void *ctx);
306
307/** Update the current result after each instruction, and after popping each stack frame
308 *
309 * @param[in] request The current request.
310 * @param[in] frame The current stack frame.
311 * @param[in,out] result The current section result.
312 * @param[in,out] priority The current section priority.
313 * @return
314 * - UNLANG_FRAME_ACTION_NEXT evaluate more instructions.
315 * - UNLANG_FRAME_ACTION_POP the final result has been calculated for this frame.
316 */
317static inline CC_HINT(always_inline)
319 rlm_rcode_t *result, int *priority)
320{
321 unlang_t const *instruction = frame->instruction;
322 unlang_stack_t *stack = request->stack;
323
324 RDEBUG4("** [%i] %s - have (%s %d) module returned (%s %d)",
325 stack->depth, __FUNCTION__,
326 fr_table_str_by_value(mod_rcode_table, frame->result, "<invalid>"),
327 frame->priority,
328 fr_table_str_by_value(mod_rcode_table, *result, "<invalid>"),
329 *priority);
330
331 /*
332 * Update request->rcode if the instruction says we should
333 * We don't care about priorities for this.
334 */
335 if (unlang_ops[instruction->type].rcode_set) {
336 RDEBUG3("Setting rcode to '%s'",
337 fr_table_str_by_value(rcode_table, *result, "<INVALID>"));
338 request->rcode = *result;
339 }
340
341 /*
342 * Don't set action or priority if we don't have one.
343 */
344 if (*result == RLM_MODULE_NOT_SET) return UNLANG_FRAME_ACTION_NEXT;
345
346 /*
347 * The child's action says return. Do so.
348 */
349 if (instruction->actions.actions[*result] == MOD_ACTION_RETURN) {
350 if (*priority < 0) *priority = 0;
351
352 RDEBUG4("** [%i] %s - action says to return with (%s %d)",
353 stack->depth, __FUNCTION__,
354 fr_table_str_by_value(mod_rcode_table, *result, "<invalid>"),
355 *priority);
356 frame->result = *result;
357 frame->priority = *priority;
359 }
360
361 /*
362 * If "reject", break out of the loop and return
363 * reject.
364 */
365 if (instruction->actions.actions[*result] == MOD_ACTION_REJECT) {
366 if (*priority < 0) *priority = 0;
367
368 RDEBUG4("** [%i] %s - action says to return with (%s %d)",
369 stack->depth, __FUNCTION__,
371 *priority);
372 frame->result = RLM_MODULE_REJECT;
373 frame->priority = *priority;
375 }
376
377 /*
378 * The instruction says it should be retried from the beginning.
379 */
380 if (instruction->actions.actions[*result] == MOD_ACTION_RETRY) {
381 unlang_retry_t *retry = frame->retry;
382
383 RDEBUG4("** [%i] %s - action says to retry with",
384 stack->depth, __FUNCTION__);
385
386 if (*priority < 0) *priority = 0;
387
388 /*
389 * If this is the first time doing the retry,
390 * then allocate the structure and set the timer.
391 */
392 if (!retry) {
393 frame->retry = retry = talloc_zero(stack, unlang_retry_t);
394 if (!frame->retry) goto fail;
395
396 retry->request = request;
397 retry->depth = stack->depth;
398 retry->state = FR_RETRY_CONTINUE;
399 retry->count = 1;
400
401 /*
402 * Set a timer which automatically fires
403 * if there's a timeout. And parent it
404 * from the retry structure, so that the
405 * timer is automatically freed when the
406 * frame is cleaned up.
407 */
408 if (fr_time_delta_ispos(instruction->actions.retry.mrd)) {
409 retry->timeout = fr_time_add(fr_time(), instruction->actions.retry.mrd);
410
411 if (fr_timer_at(retry, unlang_interpret_event_list(request)->tl, &retry->ev, retry->timeout,
412 false, instruction_timeout_handler, request) < 0) {
413 RPEDEBUG("Failed inserting event");
414 goto fail;
415 }
416 }
417
418 } else {
419 /*
420 * We've been told to stop doing retries,
421 * probably from a timeout.
422 */
423 if (retry->state != FR_RETRY_CONTINUE) goto fail;
424
425 /*
426 * Clamp it at the maximum count.
427 */
428 if (instruction->actions.retry.mrc > 0) {
429 retry->count++;
430
431 if (retry->count >= instruction->actions.retry.mrc) {
432 retry->state = FR_RETRY_MRC;
433
434 REDEBUG("Retries hit max_rtx_count (%u) - returning 'fail'", instruction->actions.retry.mrc);
435
436 fail:
437 *result = RLM_MODULE_FAIL;
438 goto finalize;
439 }
440 }
441 }
442
443 RINDENT();
444 if (instruction->actions.retry.mrc) {
445 RDEBUG("... retrying (%u/%u)", retry->count, instruction->actions.retry.mrc);
446 } else {
447 RDEBUG("... retrying");
448 }
449 REXDENT();
450
451 talloc_free(frame->state);
453 frame_state_init(stack, frame);
455 }
456
457finalize:
458 /*
459 * The array holds a default priority for this return
460 * code. Grab it in preference to any unset priority.
461 */
462 if (*priority < 0) {
463 *priority = instruction->actions.actions[*result];
464
465 RDEBUG4("** [%i] %s - setting priority to (%s %d)",
466 stack->depth, __FUNCTION__,
467 fr_table_str_by_value(mod_rcode_table, *result, "<invalid>"),
468 *priority);
469 }
470
471 /*
472 * We're higher than any previous priority, remember this
473 * return code and priority.
474 */
475 if (*priority > frame->priority) {
476 frame->result = *result;
477 frame->priority = *priority;
478
479 RDEBUG4("** [%i] %s - over-riding result from higher priority to (%s %d)",
480 stack->depth, __FUNCTION__,
481 fr_table_str_by_value(mod_rcode_table, *result, "<invalid>"),
482 *priority);
483 }
484
485 /*
486 * Not allowed in frame uflags...
487 */
488 fr_assert(!(frame->uflags & UNWIND_FLAG_NO_CLEAR));
489
490 /*
491 * If we are unwinding the stack due to a break / return,
492 * then handle it now.
493 */
494 if (stack->unwind) {
495 /*
496 * Continue unwinding...
497 */
498 if (!(stack->unwind & frame->uflags) || (stack->unwind & UNWIND_FLAG_NO_CLEAR)) {
499 RDEBUG4("** [%i] %s - unwinding current frame with (%s %d) - flags - stack (%i), frame (%i)",
500 stack->depth, __FUNCTION__,
501 fr_table_str_by_value(mod_rcode_table, frame->result, "<invalid>"),
502 frame->priority, stack->unwind, frame->uflags);
503
505 }
506
507 /*
508 * If we've been told to unwind, and we've hit
509 * the frame we should be unwinding to,
510 * and the "NO_CLEAR" flag hasn't been set, then
511 * clear the unwind field so we stop unwinding.
512 */
513 stack->unwind = UNWIND_FLAG_NONE;
514
515 RDEBUG4("** [%i] %s - unwind stop (%s %d) - flags - stack unwind (%i), frame uflags (%i)",
516 stack->depth, __FUNCTION__,
517 fr_table_str_by_value(mod_rcode_table, frame->result, "<invalid>"),
518 frame->priority, stack->unwind, frame->uflags);
519 }
520
522}
523
524/** Evaluates all the unlang nodes in a section
525 *
526 * @param[in] request The current request.
527 * @param[in] frame The current stack frame.
528 * @param[in,out] result The current section result.
529 * @param[in,out] priority The current section priority.
530 * @return
531 * - UNLANG_FRAME_ACTION_NEXT evaluate more instructions in the current stack frame
532 * which may not be the same frame as when this function
533 * was called.
534 * - UNLANG_FRAME_ACTION_POP the final result has been calculated for this frame.
535 */
536static inline CC_HINT(always_inline)
538{
539 unlang_stack_t *stack = request->stack;
540
541 /*
542 * Loop over all the instructions in this list.
543 */
544 while (frame->instruction) {
545 unlang_t const *instruction = frame->instruction;
548
550
551 fr_assert(instruction->debug_name != NULL); /* if this happens, all bets are off. */
552 fr_assert(unlang_ops[instruction->type].interpret != NULL);
553
554 REQUEST_VERIFY(request);
555
556 /*
557 * We're running this frame, so it can't possibly be yielded.
558 */
559 if (is_yielded(frame)) {
560 RDEBUG("%s - Resuming execution", instruction->debug_name);
561 yielded_clear(frame);
562 }
563
564#ifndef NDEBUG
565 /*
566 * Failure testing!
567 */
568 if (request->ins_max && (request->master_state != REQUEST_STOP_PROCESSING)) {
569 request->ins_count++;
570
571 if (request->ins_count >= request->ins_max) {
572 RERROR("Failing request due to maximum instruction count %" PRIu64, request->ins_max);
573
575 request->master_state = REQUEST_STOP_PROCESSING;
576 }
577 }
578#endif
579
580 /*
581 * unlang_interpret_signal() takes care of
582 * marking the requests as STOP on a CANCEL
583 * signal.
584 */
585 if (request->master_state == REQUEST_STOP_PROCESSING) {
586 do_stop:
587 frame->result = RLM_MODULE_FAIL;
588 frame->priority = MOD_PRIORITY_MAX;
589
590 RDEBUG4("** [%i] %s - STOP current subsection with (%s %d)",
591 stack->depth, __FUNCTION__,
592 fr_table_str_by_value(mod_rcode_table, frame->result, "<invalid>"),
593 frame->priority);
594
597 }
598
599 if (!is_repeatable(frame) && (unlang_ops[instruction->type].debug_braces)) {
600 RDEBUG2("%s {", instruction->debug_name);
601 RINDENT();
602 }
603
604 /*
605 * Execute an operation
606 */
607 RDEBUG4("** [%i] %s >> %s", stack->depth, __FUNCTION__,
608 unlang_ops[instruction->type].name);
609
610 fr_assert(frame->process != NULL);
611
612 /*
613 * Clear the repeatable flag so this frame
614 * won't get executed again unless it specifically
615 * requests it.
616 *
617 * The flag may still be set again during the
618 * process function to indicate that the frame
619 * should be evaluated again.
620 */
621 repeatable_clear(frame);
623 ua = frame->process(result, request, frame);
624
625 /*
626 * If this frame is breaking or returning
627 * frame then clear that unwind flag,
628 * it's been consumed by this call.
629 *
630 * We leave the unwind flags for the eval
631 * call so that the process function knows
632 * that the stack is being unwound.
633 */
634 if (is_break_point(frame)) {
637 }
638 if (is_return_point(frame)) {
641 }
642
643 RDEBUG4("** [%i] %s << %s (%d)", stack->depth, __FUNCTION__,
644 fr_table_str_by_value(unlang_action_table, ua, "<INVALID>"), *priority);
645
646 fr_assert(*priority >= -1);
647 fr_assert(*priority <= MOD_PRIORITY_MAX);
648
649 switch (ua) {
650 /*
651 * The request is now defunct, and we should not
652 * continue processing it.
653 */
655 goto do_stop;
656
657 /*
658 * The operation resulted in additional frames
659 * being pushed onto the stack, execution should
660 * now continue at the deepest frame.
661 */
663 fr_assert_msg(&stack->frame[stack->depth] > frame,
664 "Instruction %s returned UNLANG_ACTION_PUSHED_CHILD, "
665 "but stack depth was not increased",
666 instruction->name);
668 *result = frame->result;
670
671 /*
672 * We're in a looping construct and need to stop
673 * execution of the current section.
674 */
676 if (*priority < 0) *priority = 0;
677 frame->result = *result;
678 frame->priority = *priority;
679 frame->next = NULL;
680 fr_assert(stack->unwind != UNWIND_FLAG_NONE);
682
683 /*
684 * Yield control back to the scheduler, or whatever
685 * called the interpreter.
686 */
688 fr_assert_msg(&stack->frame[stack->depth] == frame,
689 "Instruction %s returned UNLANG_ACTION_YIELD, but pushed additional "
690 "frames for evaluation. Instruction should return UNLANG_ACTION_PUSHED_CHILD "
691 "instead", instruction->name);
693 yielded_set(frame);
694 RDEBUG4("** [%i] %s - yielding with current (%s %d)", stack->depth, __FUNCTION__,
695 fr_table_str_by_value(mod_rcode_table, frame->result, "<invalid>"),
696 frame->priority);
699
700 /*
701 * This action is intended to be returned by library
702 * functions. It reduces boilerplate.
703 */
705 *result = RLM_MODULE_FAIL;
707
708 /*
709 * Instruction finished execution,
710 * check to see what we need to do next, and update
711 * the section rcode and priority.
712 */
714 if (unlang_ops[instruction->type].debug_braces) {
715 REXDENT();
716
717 /*
718 * If we're at debug level 1, don't emit the closing
719 * brace as the opening brace wasn't emitted.
720 */
722 RDEBUG("# %s (%s)", instruction->debug_name,
723 fr_table_str_by_value(mod_rcode_table, *result, "<invalid>"));
724 } else {
725 RDEBUG2("} # %s (%s)", instruction->debug_name,
726 fr_table_str_by_value(mod_rcode_table, *result, "<invalid>"));
727 }
728 }
729
730 /*
731 * RLM_MODULE_NOT_SET means the instruction
732 * doesn't want to modify the result.
733 */
734 if (*result != RLM_MODULE_NOT_SET) *priority = instruction->actions.actions[*result];
735
736 fa = result_calculate(request, frame, result, priority);
737 switch (fa) {
740
742 if (unlang_ops[instruction->type].debug_braces) {
743 REXDENT();
744 RDEBUG2("} # retrying the same section");
745 }
746 continue; /* with the current frame */
747
748 default:
749 break;
750 }
751 break;
752
753 /*
754 * Execute the next instruction in this frame
755 */
757 if (unlang_ops[instruction->type].debug_braces) {
758 REXDENT();
759 RDEBUG2("}");
760 }
761 break;
762 } /* switch over return code from the interpret function */
763
764 frame_next(stack, frame);
765 }
766
767 RDEBUG4("** [%i] %s - done current subsection with (%s %d)",
768 stack->depth, __FUNCTION__,
769 fr_table_str_by_value(mod_rcode_table, frame->result, "<invalid>"),
770 frame->priority);
771
773}
774
775/** Run the interpreter for a current request
776 *
777 * @param[in] request to run. If this is an internal request
778 * the request may be freed by the interpreter.
779 * @param[in] running Is the interpreter already running.
780 * @return The final request rcode.
781 */
782CC_HINT(hot) rlm_rcode_t unlang_interpret(request_t *request, bool running)
783{
785 rlm_rcode_t rcode;
786
787 /*
788 * We don't have a return code yet.
789 */
790 unlang_stack_t *stack = request->stack;
791 unlang_interpret_t *intp = stack->intp;
792 unlang_stack_frame_t *frame = &stack->frame[stack->depth]; /* Quiet static analysis */
793
794 stack->priority = -1; /* Reset */
795
796#ifndef NDEBUG
797 if (DEBUG_ENABLED5) DEBUG("###### unlang_interpret is starting");
799#endif
800
801 fr_assert(!unlang_request_is_scheduled(request)); /* if we're running it, it can't be scheduled */
802 fr_assert_msg(intp, "request has no interpreter associated");
803
804 RDEBUG4("** [%i] %s - interpret entered", stack->depth, __FUNCTION__);
805 if (!running) intp->funcs.resume(request, intp->uctx);
806
807 for (;;) {
808 fr_assert(request->master_state != REQUEST_STOP_PROCESSING);
809
810 RDEBUG4("** [%i] %s - frame action %s", stack->depth, __FUNCTION__,
812 switch (fa) {
813 case UNLANG_FRAME_ACTION_NEXT: /* Evaluate the current frame */
814 fr_assert(stack->depth > 0);
816
817 frame = &stack->frame[stack->depth];
818 fa = frame_eval(request, frame, &stack->result, &stack->priority);
819
820 if (fa != UNLANG_FRAME_ACTION_POP) continue;
821
822 /*
823 * We're supposed to stop processing. Don't pop anything, just stop.
824 */
825 if (request->master_state == REQUEST_STOP_PROCESSING) return RLM_MODULE_FAIL;
826
827 /*
828 * We were executing a frame, frame_eval()
829 * indicated we should pop it, but we're now at
830 * a top_frame, so we need to break out of the loop
831 * and calculate the final result for this substack.
832 *
833 * Note that we only stop on a top frame.
834 * If there's a return point such as in a
835 * policy, then the "return" causes a
836 * "pop" until the return point. BUT we
837 * then continue execution with the next
838 * instruction. And we don't return all
839 * of the way up the stack.
840 */
841 if (is_top_frame(frame)) break;
842
843 continue;
844
845 case UNLANG_FRAME_ACTION_POP: /* Pop this frame and check the one beneath it */
846 /*
847 * The result / priority is returned from the sub-section,
848 * and made into our current result / priority, as
849 * if we had performed a module call.
850 */
851 stack->result = frame->result;
852 stack->priority = frame->priority;
853
854 /*
855 * Head on back up the stack
856 */
857 frame_pop(request, stack);
858 frame = &stack->frame[stack->depth];
860
861 /*
862 * Resume a "foreach" loop, or a "load-balance" section
863 * or anything else that needs to be checked on the way
864 * back on up the stack.
865 */
866 if (is_repeatable(frame)) {
868 continue;
869 }
870
871 /*
872 * Close out the section we entered earlier
873 */
875 REXDENT();
876
877 /*
878 * If we're at debug level 1, don't emit the closing
879 * brace as the opening brace wasn't emitted.
880 */
882 RDEBUG("# %s (%s)", frame->instruction->debug_name,
883 fr_table_str_by_value(mod_rcode_table, stack->result, "<invalid>"));
884 } else {
885 RDEBUG2("} # %s (%s)", frame->instruction->debug_name,
886 fr_table_str_by_value(mod_rcode_table, stack->result, "<invalid>"));
887 }
888 }
889
890 /*
891 * If we're done, merge the last stack->result / priority in.
892 */
893 if (is_top_frame(frame)) break; /* stop */
894
895 fa = result_calculate(request, frame, &stack->result, &stack->priority);
896
897 /*
898 * If we're continuing after popping a frame
899 * then we advance the instruction else we
900 * end up executing the same code over and over...
901 */
902 if (fa == UNLANG_FRAME_ACTION_NEXT) {
903 RDEBUG4("** [%i] %s - continuing after subsection with (%s %d)",
904 stack->depth, __FUNCTION__,
905 fr_table_str_by_value(mod_rcode_table, stack->result, "<invalid>"),
906 stack->priority);
907 frame_next(stack, frame);
908
909 /*
910 * Else if we're really done with this frame
911 * print some helpful debug...
912 */
913 } else {
914 RDEBUG4("** [%i] %s - done current subsection with (%s %d)",
915 stack->depth, __FUNCTION__,
916 fr_table_str_by_value(mod_rcode_table, frame->result, "<invalid>"),
917 frame->priority);
918 }
919 continue;
920
922 /* Cannot yield from a nested call to unlang_interpret */
923 fr_assert(!running);
924
925 RDEBUG4("** [%i] %s - interpret yielding", stack->depth, __FUNCTION__);
926 intp->funcs.yield(request, intp->uctx);
927 return stack->result;
928
929 case UNLANG_FRAME_ACTION_RETRY: /* retry the current frame */
931 continue;
932 }
933 break;
934 }
935
936 /*
937 * Nothing in this section, use the top frame stack->result.
938 */
939 if ((stack->priority < 0) || (stack->result == RLM_MODULE_NOT_SET)) {
940 RDEBUG4("** [%i] %s - empty section, using stack result (%s %d)", stack->depth, __FUNCTION__,
941 fr_table_str_by_value(mod_rcode_table, stack->result, "<invalid>"), stack->priority);
942 stack->result = frame->result;
943 stack->priority = frame->priority;
944 }
945
946 if (stack->priority > frame->priority) {
947 frame->result = stack->result;
948 frame->priority = stack->priority;
949
950 RDEBUG4("** [%i] %s - over-riding stack->result from higher priority to (%s %d)",
951 stack->depth, __FUNCTION__,
952 fr_table_str_by_value(mod_rcode_table, stack->result, "<invalid>"),
953 stack->priority);
954 }
955
956 /*
957 * We're at the top frame, return the result from the
958 * stack, and get rid of the top frame.
959 */
960 RDEBUG4("** [%i] %s - interpret exiting, returning %s", stack->depth, __FUNCTION__,
961 fr_table_str_by_value(mod_rcode_table, frame->result, "<invalid>"));
962
963 stack->result = frame->result;
964
965 stack->depth--;
967
968 /*
969 * Record this now as the done functions may free
970 * the request.
971 */
972 rcode = stack->result;
973
974 /*
975 * This usually means the request is complete in its
976 * entirety.
977 */
978 if ((stack->depth == 0) && !running) unlang_interpret_request_done(request);
979
980 return rcode;
981}
982
984 .self = {
986 .debug_name = "empty-group",
987 .actions = {
988 .actions = {
998 },
999 .retry = RETRY_INIT,
1000 },
1001 },
1002};
1003
1004/** Push a configuration section onto the request stack for later interpretation.
1005 *
1006 */
1007int unlang_interpret_push_section(request_t *request, CONF_SECTION *cs, rlm_rcode_t default_rcode, bool top_frame)
1008{
1009 unlang_t *instruction = NULL;
1010
1011 /*
1012 * Interpretable unlang instructions are stored as CONF_DATA
1013 * associated with sections.
1014 */
1015 if (cs) {
1016 instruction = (unlang_t *)cf_data_value(cf_data_find(cs, unlang_group_t, NULL));
1017 if (!instruction) {
1018 REDEBUG("Failed to find pre-compiled unlang for section %s %s { ... }",
1020 return -1;
1021 }
1022 }
1023
1024 return unlang_interpret_push_instruction(request, instruction, default_rcode, top_frame);
1025}
1026
1027/** Push an instruction onto the request stack for later interpretation.
1028 *
1029 */
1030int unlang_interpret_push_instruction(request_t *request, void *instruction, rlm_rcode_t default_rcode, bool top_frame)
1031{
1032 unlang_stack_t *stack = request->stack;
1033
1034 if (!instruction) {
1035 instruction = unlang_group_to_generic(&empty_group);
1036 }
1037
1038 /*
1039 * Push the default action, and the instruction which has
1040 * no action.
1041 */
1042 if (unlang_interpret_push(request,
1043 instruction, default_rcode, UNLANG_NEXT_SIBLING, top_frame) < 0) {
1044 return -1;
1045 }
1046
1047 RDEBUG4("** [%i] %s - substack begins", stack->depth, __FUNCTION__);
1048
1049 DUMP_STACK;
1050
1051 return 0;
1052}
1053
1054/** Allocate a new unlang stack
1055 *
1056 * @param[in] ctx to allocate stack in.
1057 * @return
1058 * - A new stack on success.
1059 * - NULL on OOM.
1060 */
1061void *unlang_interpret_stack_alloc(TALLOC_CTX *ctx)
1062{
1064
1065 /*
1066 * If we have talloc_pooled_object allocate the
1067 * stack as a combined chunk/pool, with memory
1068 * to hold at mutable data for at least a quarter
1069 * of the maximum number of stack frames.
1070 *
1071 * Having a dedicated pool for mutable stack data
1072 * means we don't have memory fragmentations issues
1073 * as we would if request were used as the pool.
1074 *
1075 * This number is pretty arbitrary, but it seems
1076 * like too low level to make into a tuneable.
1077 */
1078 MEM(stack = talloc_zero_pooled_object(ctx, unlang_stack_t, UNLANG_STACK_MAX, 128)); /* 128 bytes per state */
1079 stack->result = RLM_MODULE_NOT_SET;
1080
1081 return stack;
1082}
1083
1084/** Indicate to the caller of the interpreter that this request is complete
1085 *
1086 */
1088{
1089 unlang_stack_t *stack = request->stack;
1090 unlang_interpret_t *intp;
1091
1092 if (!fr_cond_assert(stack != NULL)) return;
1093
1094 intp = stack->intp;
1095
1096 switch (request->type) {
1098 intp->funcs.done_external(request, stack->result, intp->uctx);
1099 break;
1100
1102 intp->funcs.done_internal(request, stack->result, intp->uctx);
1103 break;
1104
1106 intp->funcs.done_detached(request, stack->result, intp->uctx); /* Callback will usually free the request */
1107 break;
1108 }
1109
1110 request->master_state = REQUEST_DONE;
1111}
1112
1113static inline CC_HINT(always_inline)
1115{
1116 unlang_stack_t *stack = request->stack;
1117 unlang_interpret_t *intp;
1118
1119 if (!fr_cond_assert(stack != NULL)) return;
1120
1121 intp = stack->intp;
1122 intp->funcs.stop(request, intp->uctx);
1123 request->log.indent.unlang = 0; /* nothing unwinds the indentation stack */
1124 request->master_state = REQUEST_STOP_PROCESSING;
1125}
1126
1127static inline CC_HINT(always_inline)
1129{
1130 unlang_stack_t *stack = request->stack;
1131 unlang_interpret_t *intp;
1132
1133 if (!fr_cond_assert(stack != NULL)) return;
1134
1135 if (!request_is_detachable(request)) return;
1136
1137 intp = stack->intp;
1138
1139 intp->funcs.detach(request, intp->uctx);
1140}
1141
1142/** Send a signal (usually stop) to a request
1143 *
1144 * This is typically called via an "async" action, i.e. an action
1145 * outside of the normal processing of the request.
1146 *
1147 * If there is no #unlang_module_signal_t callback defined, the action is ignored.
1148 *
1149 * The signaling stops at the "limit" frame. This is so that keywords
1150 * such as "timeout" and "limit" can signal frames *lower* than theirs
1151 * to stop, but then continue with their own work.
1152 *
1153 * @param[in] request The current request.
1154 * @param[in] action to signal.
1155 * @param[in] limit the frame at which to stop signaling.
1156 */
1157void unlang_frame_signal(request_t *request, fr_signal_t action, int limit)
1158{
1159 unlang_stack_frame_t *frame;
1160 unlang_stack_t *stack = request->stack;
1161 int i, depth = stack->depth;
1162
1163 (void)talloc_get_type_abort(request, request_t); /* Check the request hasn't already been freed */
1164
1165 fr_assert(stack->depth > 0);
1166
1167 /*
1168 * Destructive signal where we clean each of the
1169 * stack frames up in turn.
1170 *
1171 * We do this to avoid possible free ordering
1172 * issues where memory allocated by modules higher
1173 * in the stack is used by modules lower in the
1174 * stack.
1175 */
1176 if (action == FR_SIGNAL_CANCEL) {
1177 for (i = depth; i > limit; i--) {
1178 frame = &stack->frame[i];
1179 if (frame->signal) frame->signal(request, frame, action);
1180 frame_cleanup(frame);
1181 }
1182 stack->depth = i;
1183 return;
1184 }
1185
1186 /*
1187 * Walk back up the stack, calling signal handlers
1188 * to cancel any pending operations and free/release
1189 * any resources.
1190 *
1191 * There may be multiple resumption points in the
1192 * stack, as modules can push xlats and function
1193 * calls.
1194 */
1195 for (i = depth; i > limit; i--) {
1196 frame = &stack->frame[i];
1197 if (frame->signal) frame->signal(request, frame, action);
1198 }
1199}
1200
1201/** Send a signal (usually stop) to a request
1202 *
1203 * This is typically called via an "async" action, i.e. an action
1204 * outside of the normal processing of the request.
1205 *
1206 * If there is no #unlang_module_signal_t callback defined, the action is ignored.
1207 *
1208 * @param[in] request The current request.
1209 * @param[in] action to signal.
1210 */
1212{
1213 unlang_stack_t *stack = request->stack;
1214
1215 switch (action) {
1216 case FR_SIGNAL_DETACH:
1217 /*
1218 * Ensure the request is able to be detached
1219 * else don't signal.
1220 */
1221 if (!fr_cond_assert(request_is_detachable(request))) return;
1222 break;
1223
1224 default:
1225 break;
1226 }
1227
1228 /*
1229 * Requests that haven't been run through the interpreter
1230 * yet should have a stack depth of zero, so we don't
1231 * need to do anything.
1232 */
1233 if (stack && (stack->depth > 0)) unlang_frame_signal(request, action, 0);
1234
1235 switch (action) {
1236 case FR_SIGNAL_CANCEL:
1237 /*
1238 * Detach the request from the parent to cleanup
1239 * any cross-request pointers. This is a noop
1240 * if the request is not detachable.
1241 */
1243
1244 /*
1245 * Get the request into a consistent state,
1246 * removing it from any runnable lists.
1247 */
1249
1250 /*
1251 * As the request is detached, we call the done_detached
1252 * callback which should free the request.
1253 */
1255 break;
1256
1257 case FR_SIGNAL_DETACH:
1258 /*
1259 * Cleanup any cross-request pointers, and mark the
1260 * request as detached. When the request completes it
1261 * should by automatically freed.
1262 */
1264 break;
1265
1266 default:
1267 break;
1268 }
1269}
1270
1272{
1273 unlang_retry_t *retry = talloc_get_type_abort(ctx, unlang_retry_t);
1274 request_t *request = talloc_get_type_abort(retry->request, request_t);
1275
1276 RDEBUG("retry timeout reached, signalling interpreter to cancel.");
1277
1278 /*
1279 * Signal all lower frames to exit.
1280 */
1281 unlang_frame_signal(request, FR_SIGNAL_CANCEL, retry->depth);
1282
1283 retry->state = FR_RETRY_MRD;
1285}
1286
1287/** Return the depth of the request's stack
1288 *
1289 */
1291{
1292 unlang_stack_t *stack = request->stack;
1293
1294 return stack->depth;
1295}
1296
1297/** Get the current rcode for the frame
1298 *
1299 * This can be useful for getting the result of unlang_function_t pushed
1300 * onto the stack for evaluation.
1301 *
1302 * @param[in] request The current request.
1303 * @return the current rcode for the frame.
1304 */
1306{
1307 unlang_stack_t *stack = request->stack;
1308
1309 return stack->result;
1310}
1311
1312/** Overwrite the current stack rcode
1313 *
1314 * @param[in] request The current request.
1315 * @param[in] rcode to set.
1316 */
1318{
1319 unlang_stack_t *stack = request->stack;
1320
1321 stack->result = rcode;
1322}
1323
1324/** Return whether a request is currently scheduled
1325 *
1326 */
1328{
1329 unlang_stack_t *stack = request->stack;
1330 unlang_interpret_t *intp = stack->intp;
1331
1332 return intp->funcs.scheduled(request, intp->uctx);
1333}
1334
1335/** Return whether a request has been cancelled
1336 */
1338{
1339 return (request->master_state == REQUEST_STOP_PROCESSING);
1340}
1341
1342/** Return whether a request has been marked done
1343 */
1345{
1346 return (request->master_state == REQUEST_DONE);
1347}
1348
1349/** Check if a request as resumable.
1350 *
1351 * @param[in] request The current request.
1352 * @return
1353 * - true if the request is resumable (i.e. has yielded)
1354 * - false if the request is not resumable (i.e. has not yielded)
1355 */
1357{
1358 unlang_stack_t *stack = request->stack;
1359 unlang_stack_frame_t *frame = &stack->frame[stack->depth];
1360
1361 return is_yielded(frame);
1362}
1363
1364/** Mark a request as resumable.
1365 *
1366 * It's not called "unlang_interpret", because it doesn't actually
1367 * resume the request, it just schedules it for resumption.
1368 *
1369 * @note that this schedules the request for resumption. It does not immediately
1370 * start running the request.
1371 *
1372 * @param[in] request The current request.
1373 */
1375{
1376 unlang_stack_t *stack = request->stack;
1377 unlang_interpret_t *intp = stack->intp;
1378 unlang_stack_frame_t *frame = &stack->frame[stack->depth];
1379
1380 bool scheduled = unlang_request_is_scheduled(request);
1381
1382 /*
1383 * The request hasn't yielded, OR it's already been
1384 * marked as runnable. Don't do anything.
1385 *
1386 * The IO code, or children have no idea where they're
1387 * being called from. They just ask to mark the parent
1388 * resumable when they're done. So we have to check here
1389 * if this request is resumable.
1390 *
1391 * If the parent called the child directly, then the
1392 * parent hasn't yielded, so it isn't resumable. When
1393 * the child is done, the parent will automatically
1394 * continue running. We therefore don't need to insert
1395 * the parent into the backlog.
1396 *
1397 * Multiple child request may also mark a parent request
1398 * runnable, before the parent request starts running.
1399 */
1400 if (!is_yielded(frame) || scheduled) {
1401 RDEBUG3("Not marking runnable due to%s%s",
1402 !is_yielded(frame) ?
1403 " it not being yielded " : "", scheduled ? " it already being scheduled" : "");
1404 return;
1405 }
1406
1407 RDEBUG3("Interpreter - Request marked as runnable");
1408
1409 intp->funcs.mark_runnable(request, intp->uctx);
1410}
1411
1412/** Get a talloc_ctx which is valid only for this frame
1413 *
1414 * @param[in] request The current request.
1415 * @return
1416 * - a TALLOC_CTX which is valid only for this stack frame
1417 */
1419{
1420 unlang_stack_t *stack = request->stack;
1421 unlang_stack_frame_t *frame = &stack->frame[stack->depth];
1422
1423 if (frame->state) return (TALLOC_CTX *)frame->state;
1424
1425 /*
1426 * If the frame doesn't ordinarily have a
1427 * state, assume the caller knows what it's
1428 * doing and allocate one.
1429 */
1430 return (TALLOC_CTX *)(frame->state = talloc_new(request));
1431}
1432
1434 { .required = false, .single = true, .type = FR_TYPE_TIME_DELTA },
1436};
1437
1438static xlat_action_t unlang_cancel_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out,
1439 UNUSED xlat_ctx_t const *xctx,
1440 request_t *request, fr_value_box_list_t *args);
1441
1442/** Signal the request to stop executing
1443 *
1444 * The request can't be running at this point because we're in the event
1445 * loop. This means the request is always in a consistent state when
1446 * the timeout event fires, even if that's state is waiting on I/O.
1447 */
1449{
1450 request_t *request = talloc_get_type_abort(uctx, request_t);
1451
1452 RDEBUG2("Request canceled by dynamic timeout");
1453
1455
1456 /*
1457 * Cleans up the memory allocated to hold
1458 * the pointer, not the event itself.
1459 */
1460 talloc_free(request_data_get(request, (void *)unlang_cancel_xlat, 0));
1461}
1462
1464 UNUSED xlat_ctx_t const *xctx,
1465 UNUSED request_t *request, UNUSED fr_value_box_list_t *in)
1466{
1467 fr_assert_msg(0, "Should never be run");
1468 return XLAT_ACTION_FAIL;
1469}
1470
1471/** Allows a request to dynamically alter its own lifetime
1472 *
1473 * %cancel(<timeout>)
1474 *
1475 * If timeout is 0, then the request is immediately cancelled.
1476 */
1478 UNUSED xlat_ctx_t const *xctx,
1479 request_t *request, fr_value_box_list_t *args)
1480{
1481 fr_value_box_t *timeout;
1483 fr_timer_t **ev_p, **ev_p_og;
1484 fr_value_box_t *vb;
1485 fr_time_t when = fr_time_from_sec(0); /* Invalid clang complaints if we don't set this */
1486
1487 XLAT_ARGS(args, &timeout);
1488
1489 /*
1490 * First see if we already have a timeout event
1491 * that was previously added by this xlat.
1492 */
1493 ev_p = ev_p_og = request_data_get(request, (void *)unlang_cancel_xlat, 0);
1494 if (ev_p) {
1495 if (*ev_p) when = fr_timer_when(*ev_p); /* *ev_p should never be NULL, really... */
1496 } else {
1497 /*
1498 * Must not be parented from the request
1499 * as this is freed by request data.
1500 */
1501 MEM(ev_p = talloc_zero(NULL, fr_timer_t *));
1502 }
1503
1504 if (unlikely(fr_timer_in(ev_p, el->tl, ev_p,
1505 timeout ? timeout->vb_time_delta : fr_time_delta_from_sec(0),
1506 false, unlang_cancel_event, request) < 0)) {
1507 RPERROR("Failed inserting cancellation event");
1508 talloc_free(ev_p);
1509 return XLAT_ACTION_FAIL;
1510 }
1511 if (unlikely(request_data_add(request, (void *)unlang_cancel_xlat, 0,
1512 UNCONST(fr_timer_t **, ev_p), true, true, false) < 0)) {
1513 RPERROR("Failed associating cancellation event with request");
1514 talloc_free(ev_p);
1515 return XLAT_ACTION_FAIL;
1516 }
1517
1518 /*
1519 * No timeout means cancel immediately, so yield allowing
1520 * the interpreter to run the event we added to cancel
1521 * the request.
1522 *
1523 * We call unlang_xlat_yield to keep the interpreter happy
1524 * as it expects to see a resume function set.
1525 */
1526 if (!timeout || fr_time_delta_eq(timeout->vb_time_delta, fr_time_delta_from_sec(0))) {
1527 return unlang_xlat_yield(request, unlang_cancel_never_run, NULL, 0, NULL);
1528 }
1529
1530 if (ev_p_og) {
1531 MEM(vb = fr_value_box_alloc(ctx, FR_TYPE_TIME_DELTA, NULL));
1532
1533 /*
1534 * Return how long before the previous
1535 * cancel event would have fired.
1536 *
1537 * This can be useful for doing stacked
1538 * cancellations in policy.
1539 */
1540 vb->vb_time_delta = fr_time_sub(when, fr_time());
1542 }
1543
1544 /*
1545 * No value if this is the first cleanup event
1546 */
1547 return XLAT_ACTION_DONE;
1548}
1549
1551 { .required = true, .single = true, .type = FR_TYPE_STRING },
1553};
1554
1555/** Get information about the interpreter state
1556 *
1557 * @ingroup xlat_functions
1558 */
1560 UNUSED xlat_ctx_t const *xctx,
1561 request_t *request, fr_value_box_list_t *in)
1562{
1563 unlang_stack_t *stack = request->stack;
1564 int depth = stack->depth;
1565 unlang_stack_frame_t *frame;
1566 unlang_t const *instruction;
1567 fr_value_box_t *arg = fr_value_box_list_head(in);
1568 char const *fmt = arg->vb_strvalue;
1569 fr_value_box_t *vb;
1570
1571 MEM(vb = fr_value_box_alloc_null(ctx));
1572
1573 /*
1574 * Find the correct stack frame.
1575 */
1576 while (*fmt == '.') {
1577 if (depth <= 1) {
1578 if (fr_value_box_bstrndup(vb, vb, NULL, "<underflow>", 11, false) < 0) {
1579 error:
1580 talloc_free(vb);
1581 return XLAT_ACTION_FAIL;
1582 }
1583 goto finish;
1584 }
1585
1586 fmt++;
1587 depth--;
1588 }
1589
1590 /*
1591 * Get the current instruction.
1592 */
1593 frame = &stack->frame[depth];
1594 instruction = frame->instruction;
1595
1596 /*
1597 * Nothing there...
1598 */
1599 if (!instruction) {
1600 talloc_free(vb);
1601 return XLAT_ACTION_DONE;
1602 }
1603
1604 /*
1605 * How deep the current stack is.
1606 */
1607 if (strcmp(fmt, "depth") == 0) {
1608 fr_value_box_int32(vb, NULL, depth, false);
1609 goto finish;
1610 }
1611
1612 /*
1613 * The current module
1614 */
1615 if (strcmp(fmt, "module") == 0) {
1616 if (fr_value_box_strdup(vb, vb, NULL, request->module, false) < 0) goto error;
1617
1618 goto finish;
1619 }
1620
1621 /*
1622 * Name of the instruction.
1623 */
1624 if (strcmp(fmt, "name") == 0) {
1625 if (fr_value_box_bstrndup(vb, vb, NULL, instruction->name,
1626 strlen(instruction->name), false) < 0) goto error;
1627 goto finish;
1628 }
1629
1630 /*
1631 * The request processing stage.
1632 */
1633 if (strcmp(fmt, "processing_stage") == 0) {
1634 if (fr_value_box_strdup(vb, vb, NULL, request->component, false) < 0) goto error;
1635
1636 goto finish;
1637 }
1638
1639 /*
1640 * The current return code.
1641 */
1642 if (strcmp(fmt, "rcode") == 0) {
1643 if (fr_value_box_strdup(vb, vb, NULL, fr_table_str_by_value(rcode_table, request->rcode, "<INVALID>"), false) < 0) goto error;
1644
1645 goto finish;
1646 }
1647
1648 /*
1649 * The virtual server handling the request
1650 */
1651 if (strcmp(fmt, "server") == 0) {
1652 if (!unlang_call_current(request)) goto finish;
1653
1654 if (fr_value_box_strdup(vb, vb, NULL, cf_section_name2(unlang_call_current(request)), false) < 0) goto error;
1655
1656 goto finish;
1657 }
1658
1659 /*
1660 * Unlang instruction type.
1661 */
1662 if (strcmp(fmt, "type") == 0) {
1663 if (fr_value_box_bstrndup(vb, vb, NULL, unlang_ops[instruction->type].name,
1664 strlen(unlang_ops[instruction->type].name), false) < 0) goto error;
1665
1666 goto finish;
1667 }
1668
1669 /*
1670 * All of the remaining things need a CONF_ITEM.
1671 */
1672 if (!instruction->ci) {
1673 if (fr_value_box_bstrndup(vb, vb, NULL, "<INVALID>", 3, false) < 0) goto error;
1674
1675 goto finish;
1676 }
1677
1678 /*
1679 * Line number of the current section.
1680 */
1681 if (strcmp(fmt, "line") == 0) {
1682 fr_value_box_int32(vb, NULL, cf_lineno(instruction->ci), false);
1683
1684 goto finish;
1685 }
1686
1687 /*
1688 * Filename of the current section.
1689 */
1690 if (strcmp(fmt, "filename") == 0) {
1691 if (fr_value_box_strdup(vb, vb, NULL, cf_filename(instruction->ci), false) < 0) goto error;
1692
1693 goto finish;
1694 }
1695
1696finish:
1697 if (vb->type != FR_TYPE_NULL) {
1699 } else {
1700 talloc_free(vb);
1701 }
1702
1703 return XLAT_ACTION_DONE;
1704}
1705
1706/** Initialize a unlang compiler / interpret.
1707 *
1708 * @param[in] ctx to bind lifetime of the interpret to.
1709 * Shouldn't be any free order issues here as
1710 * the interpret itself has no state.
1711 * But event loop should be stopped before
1712 * freeing the interpret.
1713 * @param[in] el for any timer or I/O events.
1714 * @param[in] funcs Callbacks to used to communicate request
1715 * state to our owner.
1716 * @param[in] uctx Data to pass to callbacks.
1717 */
1719 fr_event_list_t *el, unlang_request_func_t *funcs, void *uctx)
1720{
1721 unlang_interpret_t *intp;
1722
1723 fr_assert(funcs->init_internal);
1724
1725 fr_assert(funcs->done_internal);
1726 fr_assert(funcs->done_detached);
1727 fr_assert(funcs->done_external);
1728
1729 fr_assert(funcs->detach);
1730 fr_assert(funcs->stop);
1731 fr_assert(funcs->yield);
1732 fr_assert(funcs->resume);
1733 fr_assert(funcs->mark_runnable);
1734 fr_assert(funcs->scheduled);
1735
1736 MEM(intp = talloc(ctx, unlang_interpret_t));
1737 *intp = (unlang_interpret_t){
1738 .el = el,
1739 .funcs = *funcs,
1740 .uctx = uctx
1741 };
1742
1743 return intp;
1744}
1745
1746/** Discard the bottom most frame on the request's stack
1747 *
1748 * This is used for cleaning up after errors. i.e. the caller
1749 * uses a push function, and experiences an error and needs to
1750 * remove the frame that was just pushed.
1751 */
1753{
1754 frame_pop(request, request->stack);
1755}
1756
1757/** Set a specific interpreter for a request
1758 *
1759 */
1761{
1762 unlang_stack_t *stack = request->stack;
1763 stack->intp = intp;
1764}
1765
1766/** Get the interpreter set for a request
1767 *
1768 */
1770{
1771 unlang_stack_t *stack = request->stack;
1772
1773 return stack->intp;
1774}
1775
1776/** Get the event list for the current interpreter
1777 *
1778 */
1780{
1781 unlang_stack_t *stack = request->stack;
1782
1783 if (!stack->intp) return NULL;
1784
1785 return stack->intp->el;
1786}
1787
1788/** Set the default interpreter for this thread
1789 *
1790 */
1792{
1793 if (intp) (void)talloc_get_type_abort(intp, unlang_interpret_t);
1794
1795 intp_thread_default = intp;
1796}
1797
1798/** Get the default interpreter for this thread
1799 *
1800 * This allows detached requests to be executed asynchronously
1801 */
1803{
1804 if (!intp_thread_default) return NULL;
1805
1806 return talloc_get_type_abort(intp_thread_default, unlang_interpret_t);
1807}
1808
1810{
1811 xlat_t *xlat;
1812 /*
1813 * Should be void, but someone decided not to register multiple xlats
1814 * breaking the convention we use everywhere else in the server...
1815 */
1816 if (unlikely((xlat = xlat_func_register(ctx, "interpreter", unlang_interpret_xlat, FR_TYPE_VOID)) == NULL)) return -1;
1818
1819 if (unlikely((xlat = xlat_func_register(ctx, "cancel", unlang_cancel_xlat, FR_TYPE_VOID)) == NULL)) return -1;
1821
1822 return 0;
1823}
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
@ UNLANG_ACTION_UNWIND
Break out of the current group.
Definition action.h:41
@ UNLANG_ACTION_PUSHED_CHILD
unlang_t pushed a new child onto the stack, execute it instead of continuing.
Definition action.h:39
@ UNLANG_ACTION_EXECUTE_NEXT
Execute the next unlang_t.
Definition action.h:38
@ UNLANG_ACTION_STOP_PROCESSING
Break out of processing the current request (unwind).
Definition action.h:43
@ 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
@ UNLANG_ACTION_YIELD
Temporarily pause execution until an event occurs.
Definition action.h:42
va_list args
Definition acutest.h:770
static int const char * fmt
Definition acutest.h:573
#define UNCONST(_type, _ptr)
Remove const qualification from a pointer.
Definition build.h:167
#define RCSID(id)
Definition build.h:485
#define L(_str)
Helper for initialising arrays of string literals.
Definition build.h:209
#define FALL_THROUGH
clang 10 doesn't recognised the FALL-THROUGH comment anymore
Definition build.h:324
#define unlikely(_x)
Definition build.h:383
#define UNUSED
Definition build.h:317
#define NUM_ELEMENTS(_t)
Definition build.h:339
CONF_SECTION * unlang_call_current(request_t *request)
Return the last virtual server that was called.
Definition call.c:225
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:101
char const * cf_section_name2(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
Definition cf_util.c:1185
void * cf_data_value(CONF_DATA const *cd)
Return the user assigned value of CONF_DATA.
Definition cf_util.c:1763
char const * cf_section_name1(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
Definition cf_util.c:1171
#define cf_lineno(_cf)
Definition cf_util.h:104
#define cf_data_find(_cf, _type, _name)
Definition cf_util.h:244
#define cf_filename(_cf)
Definition cf_util.h:107
fr_table_num_sorted_t const mod_rcode_table[]
Definition compile.c:82
static int fr_dcursor_append(fr_dcursor_t *cursor, void *v)
Insert a single item at the end of the list.
Definition dcursor.h:406
static int fr_dcursor_insert(fr_dcursor_t *cursor, void *v)
Insert directly after the current item.
Definition dcursor.h:435
#define fr_cond_assert(_x)
Calls panic_action ifndef NDEBUG, else logs error and evaluates to value of _x.
Definition debug.h:139
#define fr_assert_msg(_x, _msg,...)
Calls panic_action ifndef NDEBUG, else logs error and causes the server to exit immediately with code...
Definition debug.h:210
#define MEM(x)
Definition debug.h:36
#define DEBUG(fmt,...)
Definition dhcpclient.c:39
static fr_slen_t in
Definition dict.h:831
static xlat_action_t unlang_interpret_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, UNUSED xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
Get information about the interpreter state.
Definition interpret.c:1559
static size_t unlang_action_table_len
Definition interpret.c:50
static fr_table_num_ordered_t const unlang_frame_action_table[]
Definition interpret.c:52
static void unlang_interpret_request_detach(request_t *request)
Definition interpret.c:1128
rlm_rcode_t unlang_interpret(request_t *request, bool running)
Run the interpreter for a current request.
Definition interpret.c:782
bool unlang_request_is_done(request_t const *request)
Return whether a request has been marked done.
Definition interpret.c:1344
static unlang_frame_action_t frame_eval(request_t *request, unlang_stack_frame_t *frame, rlm_rcode_t *result, int *priority)
Evaluates all the unlang nodes in a section.
Definition interpret.c:537
static unlang_group_t empty_group
Definition interpret.c:983
void unlang_interpet_frame_discard(request_t *request)
Discard the bottom most frame on the request's stack.
Definition interpret.c:1752
static unlang_frame_action_t result_calculate(request_t *request, unlang_stack_frame_t *frame, rlm_rcode_t *result, int *priority)
Update the current result after each instruction, and after popping each stack frame.
Definition interpret.c:318
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 interpret.c:1030
void unlang_interpret_request_done(request_t *request)
Indicate to the caller of the interpreter that this request is complete.
Definition interpret.c:1087
void unlang_interpret_set(request_t *request, unlang_interpret_t *intp)
Set a specific interpreter for a request.
Definition interpret.c:1760
unlang_interpret_t * unlang_interpret_get(request_t *request)
Get the interpreter set for a request.
Definition interpret.c:1769
rlm_rcode_t unlang_interpret_stack_result(request_t *request)
Get the current rcode for the frame.
Definition interpret.c:1305
int unlang_interpret_stack_depth(request_t *request)
Return the depth of the request's stack.
Definition interpret.c:1290
void unlang_interpret_mark_runnable(request_t *request)
Mark a request as resumable.
Definition interpret.c:1374
static xlat_arg_parser_t const unlang_interpret_xlat_args[]
Definition interpret.c:1550
TALLOC_CTX * unlang_interpret_frame_talloc_ctx(request_t *request)
Get a talloc_ctx which is valid only for this frame.
Definition interpret.c:1418
bool unlang_request_is_scheduled(request_t const *request)
Return whether a request is currently scheduled.
Definition interpret.c:1327
void unlang_frame_signal(request_t *request, fr_signal_t action, int limit)
Send a signal (usually stop) to a request.
Definition interpret.c:1157
int unlang_interpret_init_global(TALLOC_CTX *ctx)
Definition interpret.c:1809
unlang_interpret_t * unlang_interpret_get_thread_default(void)
Get the default interpreter for this thread.
Definition interpret.c:1802
void * unlang_interpret_stack_alloc(TALLOC_CTX *ctx)
Allocate a new unlang stack.
Definition interpret.c:1061
void unlang_interpret_set_thread_default(unlang_interpret_t *intp)
Set the default interpreter for this thread.
Definition interpret.c:1791
#define DUMP_STACK
Definition interpret.c:143
int unlang_interpret_push(request_t *request, unlang_t const *instruction, rlm_rcode_t default_rcode, bool do_next_sibling, bool top_frame)
Push a new frame onto the stack.
Definition interpret.c:161
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.
Definition interpret.c:1718
static void instruction_timeout_handler(UNUSED fr_timer_list_t *tl, UNUSED fr_time_t now, void *ctx)
Definition interpret.c:1271
bool unlang_request_is_cancelled(request_t const *request)
Return whether a request has been cancelled.
Definition interpret.c:1337
static void unlang_interpret_request_stop(request_t *request)
Definition interpret.c:1114
static void unlang_cancel_event(UNUSED fr_timer_list_t *tl, UNUSED fr_time_t now, void *uctx)
Signal the request to stop executing.
Definition interpret.c:1448
void unlang_interpret_signal(request_t *request, fr_signal_t action)
Send a signal (usually stop) to a request.
Definition interpret.c:1211
static xlat_arg_parser_t const unlang_cancel_xlat_args[]
Definition interpret.c:1433
static fr_table_num_ordered_t const unlang_action_table[]
Definition interpret.c:42
static void stack_dump(request_t *request)
Definition interpret.c:129
static int _local_variables_free(unlang_variable_ref_t *ref)
Definition interpret.c:220
static void instruction_dump(request_t *request, unlang_t const *instruction)
Definition interpret.c:60
bool unlang_interpret_is_resumable(request_t *request)
Check if a request as resumable.
Definition interpret.c:1356
unlang_action_t unlang_interpret_push_children(rlm_rcode_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:254
int unlang_interpret_push_section(request_t *request, CONF_SECTION *cs, rlm_rcode_t default_rcode, bool top_frame)
Push a configuration section onto the request stack for later interpretation.
Definition interpret.c:1007
void unlang_interpret_stack_result_set(request_t *request, rlm_rcode_t rcode)
Overwrite the current stack rcode.
Definition interpret.c:1317
#define UNWIND_FLAG_DUMP(attrib)
request_t * request
Definition interpret.c:217
static void frame_dump(request_t *request, unlang_stack_frame_t *frame)
Definition interpret.c:75
static xlat_action_t unlang_cancel_never_run(UNUSED TALLOC_CTX *ctx, UNUSED fr_dcursor_t *out, UNUSED xlat_ctx_t const *xctx, UNUSED request_t *request, UNUSED fr_value_box_list_t *in)
Definition interpret.c:1463
static char * stack_unwind_flag_dump(uint8_t unwind)
Definition interpret.c:106
fr_dict_t const * dict
Definition interpret.c:216
static xlat_action_t unlang_cancel_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, UNUSED xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *args)
Allows a request to dynamically alter its own lifetime.
Definition interpret.c:1477
static size_t unlang_frame_action_table_len
Definition interpret.c:57
static _Thread_local unlang_interpret_t * intp_thread_default
The default interpreter instance for this thread.
Definition interpret.c:40
fr_event_list_t * unlang_interpret_event_list(request_t *request)
Get the event list for the current interpreter.
Definition interpret.c:1779
unlang_request_stop_t stop
function called when a request is signalled to stop.
Definition interpret.h:116
#define UNLANG_STACK_MAX
The maximum depth of the stack.
Definition interpret.h:38
unlang_request_done_t done_internal
Function called when an internal request completes.
Definition interpret.h:112
unlang_request_resume_t resume
Function called when a request is resumed.
Definition interpret.h:118
#define UNLANG_SUB_FRAME
Definition interpret.h:36
unlang_request_done_t done_external
Function called when a external request completes.
Definition interpret.h:111
unlang_request_init_t detach
Function called when a request is detached.
Definition interpret.h:115
unlang_request_runnable_t mark_runnable
Function called when a request needs to be added back to the runnable queue.
Definition interpret.h:119
unlang_request_yield_t yield
Function called when a request yields.
Definition interpret.h:117
unlang_request_done_t done_detached
Function called when a detached request completes.
Definition interpret.h:113
unlang_request_scheduled_t scheduled
Function to check if a request is already scheduled.
Definition interpret.h:121
unlang_request_init_t init_internal
Function called to initialise an internal request.
Definition interpret.h:109
struct unlang_interpret_s unlang_interpret_t
Interpreter handle.
Definition interpret.h:47
External functions provided by the owner of the interpret.
Definition interpret.h:103
Private declarations for the unlang interpreter.
fr_event_list_t * el
unlang_request_func_t funcs
#define REXDENT()
Exdent (unindent) R* messages by one level.
Definition log.h:443
#define DEBUG_ENABLED5
True if global debug level 1-5 messages are enabled.
Definition log.h:261
#define RDEBUG3(fmt,...)
Definition log.h:343
#define RERROR(fmt,...)
Definition log.h:298
#define RPERROR(fmt,...)
Definition log.h:302
#define RPEDEBUG(fmt,...)
Definition log.h:376
#define RDEBUG4(fmt,...)
Definition log.h:344
#define RINDENT()
Indent R* messages by one level.
Definition log.h:430
unlang_op_t unlang_ops[UNLANG_TYPE_MAX]
Different operations the interpreter can execute.
Definition base.c:31
talloc_free(reap)
Stores all information relating to an event list.
Definition event.c:380
static char * stack[MAX_STACK]
Definition radmin.c:158
@ FR_TYPE_TIME_DELTA
A period of time measured in nanoseconds.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_NULL
Invalid (uninitialised) attribute type.
@ FR_TYPE_VOID
User data.
unsigned char uint8_t
static uint8_t depth(fr_minmax_heap_index_t i)
Definition minmax_heap.c:83
@ MOD_ACTION_RETURN
Definition mod_action.h:40
@ MOD_ACTION_REJECT
Definition mod_action.h:41
@ MOD_PRIORITY_MAX
Definition mod_action.h:58
@ MOD_ACTION_RETRY
Definition mod_action.h:42
fr_retry_config_t retry
Definition mod_action.h:63
unlang_mod_action_t actions[RLM_MODULE_NUMCODES]
Definition mod_action.h:62
Declarations for the unlang module interface.
int fr_pair_delete(fr_pair_list_t *list, fr_pair_t *vp)
Remove fr_pair_t from a list and free.
Definition pair.c:1828
Declarations for the unlang "parallel" keyword.
#define fr_assert(_expr)
Definition rad_assert.h:38
#define REDEBUG(fmt,...)
Definition radclient.h:52
#define RDEBUG_ENABLED2()
Definition radclient.h:50
#define RDEBUG2(fmt,...)
Definition radclient.h:54
#define RDEBUG(fmt,...)
Definition radclient.h:53
#define RDEBUG_ENABLED()
Definition radclient.h:49
fr_table_num_sorted_t const rcode_table[]
Definition rcode.c:35
rlm_rcode_t
Return codes indicating the result of the module call.
Definition rcode.h:40
@ RLM_MODULE_FAIL
Module failed, don't reply.
Definition rcode.h:42
@ RLM_MODULE_REJECT
Immediately reject the request.
Definition rcode.h:41
@ RLM_MODULE_NOT_SET
Error resolving rcode (should not be returned by modules).
Definition rcode.h:51
#define REQUEST_VERIFY(_x)
Definition request.h:276
@ REQUEST_TYPE_EXTERNAL
A request received on the wire.
Definition request.h:152
@ REQUEST_TYPE_INTERNAL
A request generated internally.
Definition request.h:153
@ REQUEST_TYPE_DETACHED
A request that was generated internally, but is now detached (not associated with a parent request....
Definition request.h:154
#define request_is_detachable(_x)
Definition request.h:161
@ REQUEST_DONE
Request has completed.
Definition request.h:63
@ REQUEST_STOP_PROCESSING
Request has been signalled to stop.
Definition request.h:62
void * request_data_get(request_t *request, void const *unique_ptr, int unique_int)
Get opaque data from a request.
#define request_data_add(_request, _unique_ptr, _unique_int, _opaque, _free_on_replace, _free_on_parent, _persist)
Add opaque data to a request_t.
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_SIGNAL_DETACH
Request is being detached from its parent.
Definition signal.h:45
PUBLIC int snprintf(char *string, size_t length, char *format, va_alist)
Definition snprintf.c:689
fr_pair_t * vp
#define fr_time()
Allow us to arbitrarily manipulate time.
Definition state_test.c:8
Stores an attribute, a value and various bits of other data.
Definition pair.h:68
fr_dict_attr_t const *_CONST da
Dictionary attribute defines the attribute number, vendor and type of the pair.
Definition pair.h:69
#define fr_table_str_by_value(_table, _number, _def)
Convert an integer to a string.
Definition table.h:772
An element in an arbitrarily ordered array of name to num mappings.
Definition table.h:57
#define talloc_zero_pooled_object(_ctx, _type, _num_subobjects, _total_subobjects_size)
Definition talloc.h:177
static fr_time_delta_t fr_time_delta_from_sec(int64_t sec)
Definition time.h:590
#define fr_time_delta_ispos(_a)
Definition time.h:290
#define fr_time_delta_eq(_a, _b)
Definition time.h:287
#define fr_time_add(_a, _b)
Add a time/time delta together.
Definition time.h:196
static fr_time_t fr_time_from_sec(time_t when)
Convert a time_t (wallclock time) to a fr_time_t (internal time)
Definition time.h:858
#define fr_time_sub(_a, _b)
Subtract one time from another.
Definition time.h:229
"server local" time.
Definition time.h:69
fr_time_t fr_timer_when(fr_timer_t *ev)
Internal timestamp representing when the timer should fire.
Definition timer.c:670
An event timer list.
Definition timer.c:53
A timer event.
Definition timer.c:79
#define fr_timer_in(...)
Definition timer.h:86
#define fr_timer_at(...)
Definition timer.h:80
static fr_event_list_t * el
xlat_action_t unlang_xlat_yield(request_t *request, xlat_func_t resume, xlat_func_signal_t signal, fr_signal_t sigmask, void *rctx)
Yield a request back to the interpreter from within a module.
Definition xlat.c:574
bool required
Argument must be present, and non-empty.
Definition xlat.h:148
#define XLAT_ARGS(_list,...)
Populate local variables with value boxes from the input list.
Definition xlat.h:381
#define XLAT_ARG_PARSER_TERMINATOR
Definition xlat.h:168
xlat_action_t
Definition xlat.h:37
@ XLAT_ACTION_FAIL
An xlat function failed.
Definition xlat.h:44
@ XLAT_ACTION_DONE
We're done evaluating this level of nesting.
Definition xlat.h:43
Definition for a single argument consumend by an xlat function.
Definition xlat.h:147
#define UNWIND_FLAG_RETURN_POINT
'return' stops here.
fr_retry_state_t state
#define unlang_frame_perf_resume(_x)
static void frame_pop(request_t *request, unlang_stack_t *stack)
Pop a stack frame, removing any associated dynamically allocated state.
unlang_t * next
Next node (executed on UNLANG_ACTION_EXECUTE_NEXT et al).
static void frame_next(unlang_stack_t *stack, unlang_stack_frame_t *frame)
Advance to the next sibling instruction.
static bool is_repeatable(unlang_stack_frame_t const *frame)
#define UNWIND_FLAG_TOP_FRAME
are we the top frame of the stack? If true, causes the interpreter to stop interpreting and return,...
#define UNLANG_NEXT_SIBLING
Definition unlang_priv.h:93
static void repeatable_clear(unlang_stack_frame_t *frame)
unlang_retry_t * retry
if the frame is being retried.
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.
void * state
Stack frame specialisations.
unlang_mod_actions_t actions
Priorities, etc. for the various return codes.
static void frame_state_init(unlang_stack_t *stack, unlang_stack_frame_t *frame)
bool rcode_set
Set request->rcode to the result of this operation.
int priority
Result priority.
unlang_dump_t dump
Dump additional information about the frame state.
static unlang_t * unlang_group_to_generic(unlang_group_t const *p)
static unlang_action_t unwind_all(unlang_stack_t *stack)
#define UNWIND_FLAG_NO_CLEAR
Keep unwinding, don't clear the unwind flag.
#define UNWIND_FLAG_BREAK_POINT
'break' stops here.
fr_timer_t * ev
unlang_process_t interpret
Function to interpret the keyword.
#define UNWIND_FLAG_NONE
No flags.
uint8_t uflags
Unwind markers.
int depth
of this retry structure
static void frame_cleanup(unlang_stack_frame_t *frame)
Cleanup any lingering frame state.
request_t * request
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)
static void stack_unwind_break_clear(unlang_stack_t *stack)
char const * name
Unknown...
static bool is_break_point(unlang_stack_frame_t const *frame)
@ UNLANG_TYPE_GROUP
Grouping section.
Definition unlang_priv.h:48
unlang_t const * instruction
The unlang node we're evaluating.
bool debug_braces
Whether the operation needs to print braces in debug mode.
static bool is_yielded(unlang_stack_frame_t const *frame)
static void top_frame_set(unlang_stack_frame_t *frame)
unlang_variable_t * variables
rarely used, so we don't usually need it
rlm_rcode_t result
The result from executing the instruction.
char const * name
Name of the operation.
unlang_frame_action_t
Allows the frame evaluator to signal the interpreter.
Definition unlang_priv.h:83
@ 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:84
@ UNLANG_FRAME_ACTION_YIELD
Temporarily return control back to the caller on the C stack.
Definition unlang_priv.h:88
@ UNLANG_FRAME_ACTION_NEXT
Process the next instruction at this level.
Definition unlang_priv.h:87
@ UNLANG_FRAME_ACTION_RETRY
retry the current frame
Definition unlang_priv.h:86
static void yielded_set(unlang_stack_frame_t *frame)
static void yielded_clear(unlang_stack_frame_t *frame)
#define unlang_frame_perf_yield(_x)
fr_time_t timeout
#define unlang_frame_perf_cleanup(_x)
unlang_t const * next
The next unlang node we will evaluate.
static void stack_unwind_return_clear(unlang_stack_t *stack)
fr_dict_t * dict
our dictionary
static bool is_return_point(unlang_stack_frame_t const *frame)
unlang_process_t process
function to call for interpreting this stack frame
unlang_type_t type
The specialisation of this node.
unlang_t * children
Children beneath this group.
static void stack_unwind_top_frame_clear(unlang_stack_t *stack)
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.
fr_pair_t * fr_pair_list_tail(fr_pair_list_t const *list)
Get the tail of a valuepair list.
Definition pair_inline.c:56
fr_pair_t * fr_pair_list_prev(fr_pair_list_t const *list, fr_pair_t const *item))
Get the previous item in a valuepair list before a specific entry.
Definition pair_inline.c:83
#define RETRY_INIT
Definition retry.h:39
uint32_t mrc
Maximum retransmission count.
Definition retry.h:36
@ FR_RETRY_MRC
reached maximum retransmission count
Definition retry.h:47
@ FR_RETRY_CONTINUE
Definition retry.h:46
@ FR_RETRY_MRD
reached maximum retransmission duration
Definition retry.h:48
fr_time_delta_t mrd
Maximum retransmission duration.
Definition retry.h:35
int fr_value_box_strdup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, bool tainted)
Copy a nul terminated string to a fr_value_box_t.
Definition value.c:3957
int fr_value_box_bstrndup(TALLOC_CTX *ctx, fr_value_box_t *dst, fr_dict_attr_t const *enumv, char const *src, size_t len, bool tainted)
Copy a string to to a fr_value_box_t.
Definition value.c:4178
#define fr_value_box_alloc(_ctx, _type, _enumv)
Allocate a value box of a specific type.
Definition value.h:632
#define fr_value_box_alloc_null(_ctx)
Allocate a value box for later use with a value assignment function.
Definition value.h:643
static size_t char ** out
Definition value.h:1012
An xlat calling ctx.
Definition xlat_ctx.h:49
int xlat_func_args_set(xlat_t *x, xlat_arg_parser_t const args[])
Register the arguments of an xlat.
Definition xlat_func.c:365
xlat_t * xlat_func_register(TALLOC_CTX *ctx, char const *name, xlat_func_t func, fr_type_t return_type)
Register an xlat function.
Definition xlat_func.c:218