25#include <freeradius-devel/server/rcode.h>
26#include <freeradius-devel/util/hash.h>
27#include <freeradius-devel/util/rand.h>
32#define unlang_redundant_load_balance unlang_load_balance
44 if (!redundant->
child) {
74 if (p_result) *p_result = redundant->
result;
106#ifdef STATIC_ANALYZER
117 if (gext && gext->
vpt) {
131 REDEBUG(
"Failed finding attribute %s", gext->
vpt->name);
132 goto randomly_choose;
147 if (slen <= 0)
goto randomly_choose;
154 RDEBUG3(
"load-balance starting at child %d", (
int) start);
157 for (child = redundant->
start = g->
children; child != NULL; child = child->
next) {
159 if (
count == start) {
160 redundant->
start = child;
183 for (child = redundant->
start = g->
children; child != NULL; child = child->
next) {
186 redundant->
start = child;
279 switch (gext->
vpt->type) {
281 cf_log_err(cs,
"Invalid type in '%s': data will not result in a load-balance key", name2);
290 cf_log_err(cs,
"Invalid attribute reference in '%s': load-balancing can only be done on 'leaf' data types", name2);
336 for (child = g->
children; child != NULL; child = child->
next) {
357 .name =
"load-balance",
365 .unlang_name =
"unlang_load_balance_t",
368 .frame_state_type =
"unlang_frame_state_redundant_t",
372 .name =
"redundant-load-balance",
380 .unlang_name =
"unlang_load_balance_t",
383 .frame_state_type =
"unlang_frame_state_redundant_t",
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
@ UNLANG_ACTION_PUSHED_CHILD
unlang_t pushed a new child onto the stack, execute it instead of continuing.
@ UNLANG_ACTION_STOP_PROCESSING
Break out of processing the current request (unwind).
@ UNLANG_ACTION_CALCULATE_RESULT
Calculate a new section rlm_rcode_t value.
static int const char char buffer[256]
#define RULES_VERIFY(_cs, _rules)
Common header for all CONF_* types.
A section grouping multiple CONF_PAIR.
char const * cf_section_name2(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
CONF_ITEM * cf_section_to_item(CONF_SECTION const *cs)
Cast a CONF_SECTION to a CONF_ITEM.
char const * cf_section_name1(CONF_SECTION const *cs)
Return the second identifier of a CONF_SECTION.
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
fr_token_t cf_section_name2_quote(CONF_SECTION const *cs)
Return the quoting of the name2 identifier.
#define cf_log_err(_cf, _fmt,...)
#define cf_canonicalize_error(_ci, _slen, _msg, _str)
#define cf_item_next(_parent, _curr)
unlang_t * unlang_compile_section(unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_SECTION *cs, unlang_type_t type)
bool pass2_fixup_tmpl(UNUSED TALLOC_CTX *ctx, tmpl_t **vpt_p, CONF_ITEM const *ci, fr_dict_t const *dict)
bool unlang_compile_limit_subsection(CONF_SECTION *cs, char const *name)
uint32_t fr_hash(void const *data, size_t size)
int unlang_interpret_push(unlang_result_t *result_p, request_t *request, unlang_t const *instruction, unlang_frame_conf_t const *conf, bool do_next_sibling)
Push a new frame onto the stack.
unlang_mod_action_t priority
The priority or action for that rcode.
#define UNLANG_RESULT_NOT_SET
#define FRAME_CONF(_default_rcode, _top_frame)
rlm_rcode_t rcode
The current rcode, from executing the instruction or merging the result from a frame.
static TALLOC_CTX * unlang_ctx
void unlang_register(unlang_op_t *op)
Register an operation with the interpreter.
static unlang_action_t unlang_load_balance_next(unlang_result_t *p_result, request_t *request, unlang_stack_frame_t *frame)
static unlang_t * compile_load_balance_subsection(unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_SECTION *cs, unlang_type_t type)
void unlang_load_balance_init(void)
static unlang_t * unlang_compile_redundant_load_balance(unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_ITEM const *ci)
static void compile_redundant_actions(unlang_t *c)
static unlang_t * unlang_compile_load_balance(unlang_t *parent, unlang_compile_ctx_t *unlang_ctx, CONF_ITEM const *ci)
static unlang_action_t unlang_load_balance(unlang_result_t *p_result, request_t *request, unlang_stack_frame_t *frame)
#define unlang_redundant_load_balance
static unlang_load_balance_t * unlang_group_to_load_balance(unlang_group_t *g)
Cast a group structure to the load_balance keyword extension.
unlang_result_t result
for intermediate child results
unlang_t * child
the current child we're processing
unlang_t * start
the starting child
State of a redundant operation.
@ MOD_ACTION_RETURN
stop processing the section, and return the rcode with unset priority
unlang_mod_action_t actions[RLM_MODULE_NUMCODES]
uint32_t fr_rand(void)
Return a 32-bit random number.
@ RLM_MODULE_FAIL
Module failed, don't reply.
@ RLM_MODULE_TIMEOUT
Module (or section) timed out.
@ RLM_MODULE_NOT_SET
Error resolving rcode (should not be returned by modules).
@ RLM_MODULE_NUMCODES
How many valid return codes there are.
static unsigned int hash(char const *username, unsigned int tablesize)
#define FR_SBUFF_IN(_start, _len_or_end)
int tmpl_find_vp(fr_pair_t **out, request_t *request, tmpl_t const *vpt))
Returns the first VP matching a tmpl_t.
#define tmpl_is_attr(vpt)
@ TMPL_TYPE_ATTR
Reference to one or more attributes.
@ TMPL_TYPE_XLAT
Pre-parsed xlat expansion.
@ TMPL_TYPE_EXEC
Callout to an external script or program.
ssize_t tmpl_afrom_substr(TALLOC_CTX *ctx, tmpl_t **out, fr_sbuff_t *in, fr_token_t quote, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules))
Convert an arbitrary string into a tmpl_t.
#define tmpl_expand(_out, _buff, _buff_len, _request, _vpt)
Expand a tmpl to a C type, using existing storage to hold variably sized types.
tmpl_attr_rules_t attr
Rules/data for parsing attribute references.
static fr_dict_attr_t const * tmpl_attr_tail_da(tmpl_t const *vpt)
Return the last attribute reference da.
Optional arguments passed to vp_tmpl functions.
fr_aka_sim_id_type_t type
uint8_t allow_unknown
Allow unknown attributes i.e.
Stores an attribute, a value and various bits of other data.
Private interpreter structures and functions.
unlang_t * next
Next node (executed on UNLANG_ACTION_EXECUTE_NEXT et al).
void * state
Stack frame specialisations.
unlang_mod_actions_t actions
Priorities, etc. for the various return codes.
static unlang_group_t * unlang_generic_to_group(unlang_t const *p)
unlang_type_t
Types of unlang_t nodes.
@ UNLANG_TYPE_LOAD_BALANCE
Load balance section.
@ UNLANG_TYPE_REDUNDANT_LOAD_BALANCE
Redundant load balance section.
unlang_t const * instruction
The unlang node we're evaluating.
@ UNLANG_OP_FLAG_DEBUG_BRACES
Print debug braces.
@ UNLANG_OP_FLAG_RCODE_SET
Set request->rcode to the result of this operation.
static void repeatable_set(unlang_stack_frame_t *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.
Generic representation of a grouping.
A node in a graph of unlang_op_t (s) that we execute.
Our interpreter stack, as distinct from the C stack.
#define fr_type_is_leaf(_x)
uint32_t fr_value_box_hash(fr_value_box_t const *vb)
Hash the contents of a value box.