The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
rlm_cache.c
Go to the documentation of this file.
1/*
2 * This program is 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 (at
5 * 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: 2311d32b05100e642e8048e9a7ff43471ce94435 $
19 * @file rlm_cache.c
20 * @brief Cache values and merge them back into future requests.
21 *
22 * @copyright 2024 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
23 * @copyright 2012-2014 The FreeRADIUS server project
24 */
25RCSID("$Id: 2311d32b05100e642e8048e9a7ff43471ce94435 $")
26
27#define LOG_PREFIX mctx->mi->name
28
29#include <freeradius-devel/server/base.h>
30#include <freeradius-devel/server/module_rlm.h>
31#include <freeradius-devel/server/modpriv.h>
32#include <freeradius-devel/server/dl_module.h>
33#include <freeradius-devel/server/rcode.h>
34#include <freeradius-devel/server/tmpl.h>
35#include <freeradius-devel/util/debug.h>
36#include <freeradius-devel/util/types.h>
37#include <freeradius-devel/util/value.h>
38#include <freeradius-devel/unlang/action.h>
39#include <freeradius-devel/unlang/xlat_func.h>
40#include <freeradius-devel/unlang/call_env.h>
41#include <freeradius-devel/unlang/xlat.h>
42
43#include "rlm_cache.h"
44
46
47int submodule_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule);
48static int cache_key_parse(TALLOC_CTX *ctx, void *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci, call_env_ctx_t const *cec, call_env_parser_t const *rule);
49static int cache_update_section_parse(TALLOC_CTX *ctx, call_env_parsed_head_t *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci, call_env_ctx_t const *cec, call_env_parser_t const *rule);
50
51static const conf_parser_t module_config[] = {
52 { FR_CONF_OFFSET_TYPE_FLAGS("driver", FR_TYPE_VOID, 0, rlm_cache_t, driver_submodule), .dflt = "rbtree",
54 { FR_CONF_OFFSET("ttl", rlm_cache_config_t, ttl), .dflt = "500s" },
55 { FR_CONF_OFFSET("max_entries", rlm_cache_config_t, max_entries), .dflt = "0" },
56
57 /* Should be a type which matches time_t, @fixme before 2038 */
58 { FR_CONF_OFFSET("epoch", rlm_cache_config_t, epoch), .dflt = "0" },
59 { FR_CONF_OFFSET("add_stats", rlm_cache_config_t, stats), .dflt = "no" },
61};
62
63typedef struct {
64 fr_value_box_t *key; //!< To lookup the cache entry with.
65 map_list_t *maps; //!< Attribute map applied to cache entries.
67
68typedef struct {
69 fr_type_t ktype; //!< Key type
70
72
81
83
86 { .out = &dict_freeradius, .proto = "freeradius" },
87 { NULL }
88};
89
96
99 { .out = &attr_cache_merge_new, .name = "Cache-Merge-New", .type = FR_TYPE_BOOL, .dict = &dict_freeradius },
100 { .out = &attr_cache_status_only, .name = "Cache-Status-Only", .type = FR_TYPE_BOOL, .dict = &dict_freeradius },
101 { .out = &attr_cache_allow_merge, .name = "Cache-Allow-Merge", .type = FR_TYPE_BOOL, .dict = &dict_freeradius },
102 { .out = &attr_cache_allow_insert, .name = "Cache-Allow-Insert", .type = FR_TYPE_BOOL, .dict = &dict_freeradius },
103 { .out = &attr_cache_ttl, .name = "Cache-TTL", .type = FR_TYPE_INT32, .dict = &dict_freeradius },
104 { .out = &attr_cache_entry_hits, .name = "Cache-Entry-Hits", .type = FR_TYPE_UINT32, .dict = &dict_freeradius },
105 { NULL }
106};
107
108int submodule_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
109{
110 rlm_cache_t *inst = talloc_get_type_abort(parent, rlm_cache_t);
112 int ret;
113
114 if (unlikely(ret = module_rlm_submodule_parse(ctx, out, parent, ci, rule) < 0)) return ret;
115
116 mi = talloc_get_type_abort(*((void **)out), module_instance_t);
117 inst->driver = (rlm_cache_driver_t const *)mi->exported; /* Public symbol exported by the submodule */
118
119 return 0;
120}
121
122static int cache_key_parse(TALLOC_CTX *ctx, void *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci,
123 call_env_ctx_t const *cec,
124 call_env_parser_t const *rule)
125{
127 call_env_parse_pair_t func = inst->driver->key_parse ? inst->driver->key_parse : call_env_parse_pair;
128 tmpl_t *key_tmpl;
129 fr_type_t cast;
130 int ret;
131 /*
132 * Call the custom key parse function, OR the standard call_env_parse_pair
133 * function, depending on whether the driver calls a custom parsing function.
134 */
135 if (unlikely((ret = func(ctx, &key_tmpl, t_rules, ci, cec, rule)) < 0)) return ret;
136 *((tmpl_t **)out) = key_tmpl;
137
138 /*
139 * Unless the driver has a custom key parse function, we only allow keys of
140 * type string.
141 */
142 if (inst->driver->key_parse) return 0;
143
144 cast = tmpl_cast_get(key_tmpl);
145 switch (cast) {
146 case FR_TYPE_STRING:
147 case FR_TYPE_NULL:
148 case FR_TYPE_VOID:
149 break;
150
151 default:
152 cf_log_err(ci, "Driver only allows key type '%s', got '%s'",
154 return -1;
155 }
156
157 if (tmpl_cast_set(key_tmpl, FR_TYPE_STRING) < 0) {
158 cf_log_perr(ci, "Can't convert key type '%s' to '%s'",
160 return -1;
161 }
162
163 return 0;
164}
165
166/** Get exclusive use of a handle to access the cache
167 *
168 */
170{
171 if (!inst->driver->acquire) {
172 *out = NULL;
173 return 0;
174 }
175
176 return inst->driver->acquire(out, &inst->config, inst->driver_submodule->data, request);
177}
178
179/** Release a handle we previously acquired
180 *
181 */
182static void cache_release(rlm_cache_t const *inst, request_t *request, rlm_cache_handle_t **handle)
183{
184 if (!inst->driver->release) return;
185 if (!handle || !*handle) return;
186
187 inst->driver->release(&inst->config, inst->driver_submodule->data, request, *handle);
188 *handle = NULL;
189}
190
191/** Reconnect an suspected inviable handle
192 *
193 */
194static int cache_reconnect(rlm_cache_handle_t **handle, rlm_cache_t const *inst, request_t *request)
195{
196 fr_assert(inst->driver->reconnect);
197
198 return inst->driver->reconnect(handle, &inst->config, inst->driver_submodule->data, request);
199}
200
201/** Allocate a cache entry
202 *
203 * This is used so that drivers may use their own allocation functions
204 * to allocate structures larger than the normal rlm_cache_entry_t.
205 *
206 * If the driver doesn't specify a custom allocation function, the cache
207 * entry is talloced in the NULL ctx.
208 */
210{
211 if (inst->driver->alloc) return inst->driver->alloc(&inst->config, inst->driver_submodule->data, request);
212
213 return talloc_zero(NULL, rlm_cache_entry_t);
214}
215
216/** Free memory associated with a cache entry
217 *
218 * This does not necessarily remove the entry from the cache, cache_expire
219 * should be used for that.
220 *
221 * This function should be called when an entry that is known to have been
222 * retrieved or inserted into a data store successfully, is no longer needed.
223 *
224 * Some drivers (like rlm_cache_rbtree) don't register a free function.
225 * This means that the cache entry never needs to be explicitly freed.
226 *
227 * @param[in] inst Module instance.
228 * @param[in,out] c Cache entry to free.
229 */
231{
232 if (!c || !*c || !inst->driver->free) return;
233
234 inst->driver->free(*c);
235 *c = NULL;
236}
237
238/** Merge a cached entry into a #request_t
239 *
240 * @return
241 * - #RLM_MODULE_OK if no entries were merged.
242 * - #RLM_MODULE_UPDATED if entries were merged.
243 */
244static rlm_rcode_t cache_merge(rlm_cache_t const *inst, request_t *request, rlm_cache_entry_t *c) CC_HINT(nonnull);
246{
247 fr_pair_t *vp;
248 map_t *map = NULL;
249 int merged = 0;
250
251 RDEBUG2("Merging cache entry into request");
252 RINDENT();
253 while ((map = map_list_next(&c->maps, map))) {
254 /*
255 * The only reason that the application of a map entry
256 * can fail, is if the destination list or request
257 * isn't valid. For now we don't consider this fatal
258 * and continue merging the rest of the maps.
259 */
260 if (map_to_request(request, map, map_to_vp, NULL) < 0) {
261 char buffer[1024];
262
263 map_print(&FR_SBUFF_OUT(buffer, sizeof(buffer)), map);
264 REXDENT();
265 RDEBUG2("Skipping %s", buffer);
266 RINDENT();
267 continue;
268 }
269 merged++;
270 }
271 REXDENT();
272
273 if (inst->config.stats) {
274 fr_assert(request->packet != NULL);
276 vp->vp_uint32 = c->hits;
277 }
278
279 return merged > 0 ?
282}
283
284/** Find a cached entry.
285 *
286 * @return
287 * - #RLM_MODULE_OK on cache hit.
288 * - #RLM_MODULE_FAIL on failure.
289 * - #RLM_MODULE_NOTFOUND on cache miss.
290 */
292 rlm_cache_t const *inst, request_t *request,
293 rlm_cache_handle_t **handle, fr_value_box_t const *key)
294{
295 cache_status_t ret;
296
298
299 *out = NULL;
300
301 for (;;) {
302 ret = inst->driver->find(&c, &inst->config, inst->driver_submodule->data, request, *handle, key);
303 switch (ret) {
304 case CACHE_RECONNECT:
305 RDEBUG2("Reconnecting...");
306 if (cache_reconnect(handle, inst, request) == 0) continue;
308
309 case CACHE_OK:
310 break;
311
312 case CACHE_MISS:
313 RDEBUG2("No cache entry found for \"%pV\"", key);
315
316 default:
318
319 }
320
321 break;
322 }
323
324 /*
325 * Yes, but it expired, OR the "forget all" epoch has
326 * passed. Delete it, and pretend it doesn't exist.
327 */
328 if (fr_unix_time_lt(c->expires, fr_time_to_unix_time(request->packet->timestamp))) {
329 RDEBUG2("Found entry for \"%pV\", but it expired %pV ago at %pV (packet received %pV). Removing it",
330 key,
331 fr_box_time_delta(fr_unix_time_sub(fr_time_to_unix_time(request->packet->timestamp), c->expires)),
333 fr_box_time(request->packet->timestamp));
334
335 expired:
336 inst->driver->expire(&inst->config, inst->driver_submodule->data, request, handle, key);
337 cache_free(inst, &c);
338 RETURN_UNLANG_NOTFOUND; /* Couldn't find a non-expired entry */
339 }
340
341 if (fr_unix_time_lt(c->created, fr_unix_time_from_sec(inst->config.epoch))) {
342 RDEBUG2("Found entry for \"%pV\", but it was created before the current epoch. Removing it",
343 key);
344 goto expired;
345 }
346 RDEBUG2("Found entry for \"%pV\"", key);
347
348 c->hits++;
349 *out = c;
350
352}
353
354/** Expire a cache entry (removing it from the datastore)
355 *
356 * @return
357 * - #RLM_MODULE_OK on success.
358 * - #RLM_MODULE_NOTFOUND if no entry existed.
359 * - #RLM_MODULE_FAIL on failure.
360 */
362 rlm_cache_t const *inst, request_t *request,
363 rlm_cache_handle_t **handle, fr_value_box_t const *key)
364{
365 RDEBUG2("Expiring cache entry");
366 for (;;) switch (inst->driver->expire(&inst->config, inst->driver_submodule->data, request, *handle, key)) {
367 case CACHE_RECONNECT:
368 if (cache_reconnect(handle, inst, request) == 0) continue;
370
371 default:
373
374 case CACHE_OK:
376
377 case CACHE_MISS:
379 }
380}
381
382/** Create and insert a cache entry
383 *
384 * @return
385 * - #RLM_MODULE_OK on success.
386 * - #RLM_MODULE_UPDATED if we merged the cache entry.
387 * - #RLM_MODULE_FAIL on failure.
388 */
390 rlm_cache_t const *inst, request_t *request, rlm_cache_handle_t **handle,
391 fr_value_box_t const *key, map_list_t const *maps, fr_time_delta_t ttl)
392{
393 map_t const *map = NULL;
394 map_t *c_map;
395
396 fr_pair_t *vp;
397 bool merge = false;
399
400 TALLOC_CTX *pool;
401
402 if ((inst->config.max_entries > 0) && inst->driver->count &&
403 (inst->driver->count(&inst->config, inst->driver_submodule->data, request, handle) > inst->config.max_entries)) {
404 RWDEBUG("Cache is full: %d entries", inst->config.max_entries);
406 }
407
408 c = cache_alloc(inst, request);
409 if (!c) {
411 }
412 map_list_init(&c->maps);
413 if (unlikely(fr_value_box_copy(c, &c->key, key) < 0)) {
414 RERROR("Failed copying key");
415 talloc_free(c);
417 }
418
419 /*
420 * All in NSEC resolution
421 */
422 c->created = c->expires = fr_time_to_unix_time(request->packet->timestamp);
423 c->expires = fr_unix_time_add(c->expires, ttl);
424
425 RDEBUG2("Creating new cache entry");
426
427 /*
428 * We don't have any maps to apply to the cache entry
429 * so don't try to expand them.
430 */
431 if (!maps) goto skip_maps;
432
433 /*
434 * Alloc a pool so we don't have excessive allocs when
435 * gathering fr_pair_ts to cache.
436 */
437 pool = talloc_pool(NULL, 2048);
438 while ((map = map_list_next(maps, map))) {
439 fr_pair_list_t to_cache;
440
441 fr_pair_list_init(&to_cache);
442 fr_assert(map->lhs && map->rhs);
443
444 /*
445 * Calling map_to_vp gives us exactly the same result,
446 * as if this were an update section.
447 */
448 if (map_to_vp(pool, &to_cache, request, map, NULL) < 0) {
449 RDEBUG2("Skipping %s", map->rhs->name);
450 continue;
451 }
452
453 for (vp = fr_pair_list_head(&to_cache);
454 vp;
455 vp = fr_pair_list_next(&to_cache, vp)) {
456 /*
457 * Prevent people from accidentally caching
458 * cache control attributes.
459 */
460 if (tmpl_is_list(map->rhs)) switch (vp->da->attr) {
461 case FR_CACHE_TTL:
462 case FR_CACHE_STATUS_ONLY:
463 case FR_CACHE_MERGE_NEW:
464 case FR_CACHE_ENTRY_HITS:
465 RDEBUG2("Skipping %s", vp->da->name);
466 continue;
467
468 default:
469 break;
470 }
471 RINDENT();
472 if (RDEBUG_ENABLED2) map_debug_log(request, map, vp);
473 REXDENT();
474
475 MEM(c_map = talloc_zero(c, map_t));
476 c_map->op = map->op;
477 map_list_init(&c_map->child);
478
479 /*
480 * Now we turn the fr_pair_ts into maps.
481 */
482 switch (map->lhs->type) {
483 /*
484 * Attributes are easy, reuse the LHS, and create a new
485 * RHS with the fr_value_box_t from the fr_pair_t.
486 */
487 case TMPL_TYPE_ATTR:
488 {
489 fr_token_t quote;
490 /*
491 * If the LHS is structural, we need a new template
492 * which is the combination of the existing LHS and
493 * the attribute.
494 */
496 tmpl_attr_afrom_list(c_map, &c_map->lhs, map->lhs, vp->da);
497 } else {
498 c_map->lhs = map->lhs; /* lhs shouldn't be touched, so this is ok */
499 }
500
501 if (vp->vp_type == FR_TYPE_STRING) {
502 quote = is_printable(vp->vp_strvalue, vp->vp_length) ?
504 } else {
505 quote = T_BARE_WORD;
506 }
507
508 MEM(c_map->rhs = tmpl_alloc(c_map,
509 TMPL_TYPE_DATA, quote, map->rhs->name, map->rhs->len));
510 if (fr_value_box_copy(c_map->rhs, tmpl_value(c_map->rhs), &vp->data) < 0) {
511 REDEBUG("Failed copying attribute value");
512 talloc_free(pool);
513 talloc_free(c);
515 }
516 }
517 break;
518
519 default:
520 fr_assert(0);
521 }
522 MAP_VERIFY(c_map);
523 map_list_insert_tail(&c->maps, c_map);
524 }
525 talloc_free_children(pool); /* reset pool state */
526 }
527 talloc_free(pool);
528
529skip_maps:
530
531 /*
532 * Check to see if we need to merge the entry into the request
533 */
534 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cache_merge_new);
535 if (vp && vp->vp_bool) merge = true;
536
537 if (merge) cache_merge(inst, request, c);
538
539 for (;;) {
540 cache_status_t ret;
541
542 ret = inst->driver->insert(&inst->config, inst->driver_submodule->data, request, *handle, c);
543 switch (ret) {
544 case CACHE_RECONNECT:
545 if (cache_reconnect(handle, inst, request) == 0) continue;
547
548 case CACHE_OK:
549 RDEBUG2("Committed entry, TTL %pV seconds", fr_box_time_delta(ttl));
550 cache_free(inst, &c);
552
553 default:
554 talloc_free(c); /* Failed insertion - use talloc_free not the driver free */
556 }
557 }
558}
559
560/** Update the TTL of an entry
561 *
562 * @return
563 * - #RLM_MODULE_OK on success.
564 * - #RLM_MODULE_FAIL on failure.
565 */
567 rlm_cache_t const *inst, request_t *request,
569{
570 /*
571 * Call the driver's insert method to overwrite the old entry
572 */
573 if (!inst->driver->set_ttl) for (;;) {
574 cache_status_t ret;
575
576 ret = inst->driver->insert(&inst->config, inst->driver_submodule->data, request, *handle, c);
577 switch (ret) {
578 case CACHE_RECONNECT:
579 if (cache_reconnect(handle, inst, request) == 0) continue;
581
582 case CACHE_OK:
583 RDEBUG2("Updated entry TTL");
585
586 default:
588 }
589 }
590
591 /*
592 * Or call the set ttl method if the driver can do this more
593 * efficiently.
594 */
595 for (;;) {
596 cache_status_t ret;
597
598 ret = inst->driver->set_ttl(&inst->config, inst->driver_submodule->data, request, *handle, c);
599 switch (ret) {
600 case CACHE_RECONNECT:
601 if (cache_reconnect(handle, inst, request) == 0) continue;
603
604 case CACHE_OK:
605 RDEBUG2("Updated entry TTL");
607
608 default:
610 }
611 }
612}
613
614/** Do caching checks
615 *
616 * Since we can update ANY VP list, we do exactly the same thing for all sections
617 * (autz / auth / etc.)
618 *
619 * If you want to cache something different in different sections, configure
620 * another cache module.
621 */
622static unlang_action_t CC_HINT(nonnull) mod_cache_it(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
623{
624 rlm_cache_entry_t *c = NULL;
626 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
627
628 rlm_cache_handle_t *handle;
629
630 fr_dcursor_t cursor;
631 fr_pair_t *vp;
632
633 bool merge = true, insert = true, expire = false, set_ttl = false;
634 int exists = -1;
635
636 fr_time_delta_t ttl = inst->config.ttl;
637
638 p_result->rcode = RLM_MODULE_NOOP;
639
640 if (fr_type_is_variable_size(env->key->type) && (env->key->vb_length == 0)) {
641 REDEBUG("Zero length key string is invalid");
643 }
644
645 /*
646 * If Cache-Status-Only == yes, only return whether we found a
647 * valid cache entry
648 */
649 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cache_status_only);
650 if (vp && vp->vp_bool) {
651 RINDENT();
652 RDEBUG3("status-only: yes");
653 REXDENT();
654
655 if (cache_acquire(&handle, inst, request) < 0) {
657 }
658
659 cache_find(p_result, &c, inst, request, &handle, env->key);
660 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
661 fr_assert(!inst->driver->acquire || handle);
662
663 p_result->rcode = c ? RLM_MODULE_OK:
665 goto finish;
666 }
667
668 /*
669 * Figure out what operation we're doing
670 */
671 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cache_allow_merge);
672 if (vp) merge = vp->vp_bool;
673
674 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cache_allow_insert);
675 if (vp) insert = vp->vp_bool;
676
677 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cache_ttl);
678 if (vp) {
679 if (vp->vp_int32 == 0) {
680 expire = true;
681 } else if (vp->vp_int32 < 0) {
682 expire = true;
683 ttl = fr_time_delta_from_sec(-(vp->vp_int32));
684 /* Updating the TTL */
685 } else {
686 set_ttl = true;
687 ttl = fr_time_delta_from_sec(vp->vp_int32);
688 }
689 }
690
691 RINDENT();
692 RDEBUG3("merge : %s", merge ? "yes" : "no");
693 RDEBUG3("insert : %s", insert ? "yes" : "no");
694 RDEBUG3("expire : %s", expire ? "yes" : "no");
695 RDEBUG3("ttl : %pV", fr_box_time_delta(ttl));
696 REXDENT();
697 if (cache_acquire(&handle, inst, request) < 0) {
699 }
700
701 /*
702 * Retrieve the cache entry and merge it with the current request
703 * recording whether the entry existed.
704 */
705 if (merge) {
706 cache_find(p_result, &c, inst, request, &handle, env->key);
707 switch (p_result->rcode) {
708 case RLM_MODULE_FAIL:
709 goto finish;
710
711 case RLM_MODULE_OK:
712 p_result->rcode = cache_merge(inst, request, c);
713 exists = 1;
714 break;
715
717 p_result->rcode = RLM_MODULE_NOTFOUND;
718 exists = 0;
719 break;
720
721 default:
722 fr_assert(0);
723 }
724 fr_assert(!inst->driver->acquire || handle);
725 }
726
727 /*
728 * Expire the entry if told to, and we either don't know whether
729 * it exists, or we know it does.
730 *
731 * We only expire if we're not inserting, as driver insert methods
732 * should perform upserts.
733 */
734 if (expire && ((exists == -1) || (exists == 1))) {
735 if (!insert) {
736 unlang_result_t tmp;
737
738 fr_assert(!set_ttl);
739 cache_expire(&tmp, inst, request, &handle, env->key);
740 switch (tmp.rcode) {
741 case RLM_MODULE_FAIL:
742 p_result->rcode = RLM_MODULE_FAIL;
743 goto finish;
744
745 case RLM_MODULE_OK:
746 if (p_result->rcode == RLM_MODULE_NOOP) p_result->rcode = RLM_MODULE_OK;
747 break;
748
750 if (p_result->rcode == RLM_MODULE_NOOP) p_result->rcode = RLM_MODULE_NOTFOUND;
751 break;
752
753 default:
754 fr_assert(0);
755 break;
756 }
757 /* If it previously existed, it doesn't now */
758 }
759 /* Otherwise use insert to overwrite */
760 exists = 0;
761 }
762
763 /*
764 * If we still don't know whether it exists or not
765 * and we need to do an insert or set_ttl operation
766 * determine that now.
767 */
768 if ((exists < 0) && (insert || set_ttl)) {
769 unlang_result_t tmp;
770
771 cache_find(&tmp, &c, inst, request, &handle, env->key);
772 switch (tmp.rcode) {
773 case RLM_MODULE_FAIL:
774 p_result->rcode = RLM_MODULE_FAIL;
775 goto finish;
776
777 case RLM_MODULE_OK:
778 exists = 1;
779 if (p_result->rcode != RLM_MODULE_UPDATED) p_result->rcode = RLM_MODULE_OK;
780 break;
781
783 exists = 0;
784 break;
785
786 default:
787 fr_assert(0);
788 }
789 fr_assert(!inst->driver->acquire || handle);
790 }
791
792 /*
793 * We can only alter the TTL on an entry if it exists.
794 */
795 if (set_ttl && (exists == 1)) {
796 unlang_result_t tmp;
797
798 fr_assert(c);
799
800 c->expires = fr_unix_time_add(fr_time_to_unix_time(request->packet->timestamp), ttl);
801
802 cache_set_ttl(&tmp, inst, request, &handle, c);
803 switch (tmp.rcode) {
804 case RLM_MODULE_FAIL:
805 p_result->rcode = RLM_MODULE_FAIL;
806 goto finish;
807
809 case RLM_MODULE_OK:
810 if (p_result->rcode != RLM_MODULE_UPDATED) p_result->rcode = RLM_MODULE_OK;
811 goto finish;
812
813 default:
814 fr_assert(0);
815 }
816 }
817
818 /*
819 * Inserts are upserts, so we don't care about the
820 * entry state, just that we're not meant to be
821 * setting the TTL, which precludes performing an
822 * insert.
823 */
824 if (insert && (exists == 0)) {
825 unlang_result_t tmp;
826
827 cache_insert(&tmp, inst, request, &handle, env->key, env->maps, ttl);
828 switch (tmp.rcode) {
829 case RLM_MODULE_FAIL:
830 p_result->rcode = RLM_MODULE_FAIL;
831 goto finish;
832
833 case RLM_MODULE_OK:
834 if (p_result->rcode != RLM_MODULE_UPDATED) p_result->rcode = RLM_MODULE_OK;
835 break;
836
838 p_result->rcode = RLM_MODULE_UPDATED;
839 break;
840
841 default:
842 fr_assert(0);
843 }
844 fr_assert(!inst->driver->acquire || handle);
845 goto finish;
846 }
847
848
849finish:
850 cache_free(inst, &c);
851 cache_release(inst, request, &handle);
852
853 /*
854 * Clear control attributes
855 */
856 for (vp = fr_pair_dcursor_init(&cursor, &request->control_pairs);
857 vp;
858 vp = fr_dcursor_next(&cursor)) {
859 again:
860 if (!fr_dict_attr_is_top_level(vp->da)) continue;
861
862 switch (vp->da->attr) {
863 case FR_CACHE_TTL:
864 case FR_CACHE_STATUS_ONLY:
865 case FR_CACHE_ALLOW_MERGE:
866 case FR_CACHE_ALLOW_INSERT:
867 case FR_CACHE_MERGE_NEW:
868 RDEBUG2("Removing control.%s", vp->da->name);
869 vp = fr_dcursor_remove(&cursor);
871 vp = fr_dcursor_current(&cursor);
872 if (!vp) break;
873 goto again;
874 }
875 }
876
878}
879
881 { .required = true, .single = true, .type = FR_TYPE_STRING },
883};
884
885/** Allow single attribute values to be retrieved from the cache
886 *
887 * @ingroup xlat_functions
888 */
889static CC_HINT(nonnull)
891 xlat_ctx_t const *xctx,
892 request_t *request, fr_value_box_list_t *in)
893{
894 rlm_cache_entry_t *c = NULL;
895 rlm_cache_t *inst = talloc_get_type_abort(xctx->mctx->mi->data, rlm_cache_t);
896 cache_call_env_t *env = talloc_get_type_abort(xctx->env_data, cache_call_env_t);
897 rlm_cache_handle_t *handle = NULL;
898
899 ssize_t slen;
900
901 fr_value_box_t *attr = fr_value_box_list_head(in);
902 fr_value_box_t *vb;
903
904 tmpl_t *target = NULL;
905 map_t *map = NULL;
906 unlang_result_t result = { .rcode = RLM_MODULE_NOOP };
907
908 slen = tmpl_afrom_attr_substr(ctx, NULL, &target,
909 &FR_SBUFF_IN(attr->vb_strvalue, attr->vb_length),
910 NULL,
911 &(tmpl_rules_t){
912 .attr = {
913 .dict_def = request->proto_dict,
914 .list_def = request_attr_request,
915 }
916 });
917 if (slen <= 0) {
918 RPEDEBUG("Invalid key");
919 return XLAT_ACTION_FAIL;
920 }
921
922 if (cache_acquire(&handle, inst, request) < 0) {
923 talloc_free(target);
924 return XLAT_ACTION_FAIL;
925 }
926
927 cache_find(&result, &c, inst, request, &handle, env->key);
928 switch (result.rcode) {
929 case RLM_MODULE_OK: /* found */
930 break;
931
932 default:
933 talloc_free(target);
934 cache_release(inst, request, &handle);
935 return XLAT_ACTION_FAIL;
936 }
937
938 while ((map = map_list_next(&c->maps, map))) {
939 if ((tmpl_attr_tail_da(map->lhs) != tmpl_attr_tail_da(target)) ||
940 (tmpl_list(map->lhs) != tmpl_list(target))) continue;
941
942 MEM(vb = fr_value_box_alloc_null(ctx));
943 if (unlikely(fr_value_box_copy(vb, vb, tmpl_value(map->rhs)) < 0)) {
944 RPEDEBUG("Failed copying value from cache entry");
945 talloc_free(vb);
946 return XLAT_ACTION_FAIL;
947 }
949 break;
950 }
951
952 talloc_free(target);
953
954 cache_free(inst, &c);
955 cache_release(inst, request, &handle);
956
957 /*
958 * Check if we found a matching map
959 */
960 if (!map) return XLAT_ACTION_FAIL;
961
962 return XLAT_ACTION_DONE;
963}
964
966 xlat_ctx_t const *xctx,
967 request_t *request, UNUSED fr_value_box_list_t *in)
968{
969
970 rlm_cache_entry_t *c = NULL;
971 rlm_cache_t *inst = talloc_get_type_abort(xctx->mctx->mi->data, rlm_cache_t);
972 cache_call_env_t *env = talloc_get_type_abort(xctx->env_data, cache_call_env_t);
973 rlm_cache_handle_t *handle = NULL;
974
975 unlang_result_t result = { .rcode = RLM_MODULE_NOOP };
976
977 fr_value_box_t *vb;
978
979 if (cache_acquire(&handle, inst, request) < 0) {
980 return XLAT_ACTION_FAIL;
981 }
982
983 cache_find(&result, &c, inst, request, &handle, env->key);
984 switch (result.rcode) {
985 case RLM_MODULE_OK: /* found */
986 break;
987
988 default:
989 cache_release(inst, request, &handle);
990 return XLAT_ACTION_DONE;
991 }
992
993 MEM(vb = fr_value_box_alloc(ctx, FR_TYPE_TIME_DELTA, NULL));
994 vb->vb_time_delta = fr_unix_time_sub(c->expires, fr_time_to_unix_time(request->packet->timestamp));
996
997 cache_free(inst, &c);
998 cache_release(inst, request, &handle);
999
1000 return XLAT_ACTION_DONE;
1001}
1002
1003/** Release the allocated resources and cleanup the avps
1004 */
1005static void cache_unref(request_t *request, rlm_cache_t const *inst, rlm_cache_entry_t *entry,
1006 rlm_cache_handle_t *handle)
1007{
1008 fr_dcursor_t cursor;
1009 fr_pair_t *vp;
1010
1011 /*
1012 * Release the driver calls
1013 */
1014 cache_free(inst, &entry);
1015 cache_release(inst, request, &handle);
1016
1017 /*
1018 * Clear control attributes
1019 */
1020 for (vp = fr_pair_dcursor_init(&cursor, &request->control_pairs);
1021 vp;
1022 vp = fr_dcursor_next(&cursor)) {
1023 again:
1024 if (!fr_dict_attr_is_top_level(vp->da)) continue;
1025
1026 switch (vp->da->attr) {
1027 case FR_CACHE_TTL:
1028 case FR_CACHE_STATUS_ONLY:
1029 case FR_CACHE_ALLOW_MERGE:
1030 case FR_CACHE_ALLOW_INSERT:
1031 case FR_CACHE_MERGE_NEW:
1032 RDEBUG2("Removing control:%s", vp->da->name);
1033 vp = fr_dcursor_remove(&cursor);
1034 TALLOC_FREE(vp);
1035 vp = fr_dcursor_current(&cursor);
1036 if (!vp) break;
1037 goto again;
1038 }
1039 }
1040}
1041
1042/** Get the status by ${key} (without load)
1043 *
1044 * @return
1045 * - #RLM_MODULE_OK on success.
1046 * - #RLM_MODULE_NOTFOUND on cache miss.
1047 * - #RLM_MODULE_FAIL on failure.
1048 */
1049static unlang_action_t CC_HINT(nonnull) mod_method_status(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
1050{
1051 rlm_cache_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1052 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
1053 rlm_cache_entry_t *entry = NULL;
1054 rlm_cache_handle_t *handle = NULL;
1055
1056 p_result->rcode = RLM_MODULE_NOOP;
1057
1058 if (fr_type_is_variable_size(env->key->type) && (env->key->vb_length == 0)) {
1059 REDEBUG("Zero length key string is invalid");
1061 }
1062
1063 /* Good to go? */
1064 if (cache_acquire(&handle, inst, request) < 0) {
1066 }
1067
1068 fr_assert(!inst->driver->acquire || handle);
1069
1070 cache_find(p_result, &entry, inst, request, &handle, env->key);
1071 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1072
1073 p_result->rcode = (entry) ? RLM_MODULE_OK : RLM_MODULE_NOTFOUND;
1074
1075finish:
1076 cache_unref(request, inst, entry, handle);
1077
1079}
1080
1081/** Load the avps by ${key}.
1082 *
1083 * @return
1084 * - #RLM_MODULE_UPDATED on success.
1085 * - #RLM_MODULE_NOTFOUND on cache miss.
1086 * - #RLM_MODULE_FAIL on failure.
1087 */
1088static unlang_action_t CC_HINT(nonnull) mod_method_load(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
1089{
1090 rlm_cache_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1091 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
1092 rlm_cache_entry_t *entry = NULL;
1093 rlm_cache_handle_t *handle = NULL;
1094
1095 p_result->rcode = RLM_MODULE_NOOP;
1096
1097 if (fr_type_is_variable_size(env->key->type) && (env->key->vb_length == 0)) {
1098 REDEBUG("Zero length key string is invalid");
1100 }
1101
1102 /* Good to go? */
1103 if (cache_acquire(&handle, inst, request) < 0) {
1105 }
1106
1107 cache_find(p_result, &entry, inst, request, &handle, env->key);
1108 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1109
1110 if (!entry) {
1111 RDEBUG2("Entry not found to load");
1112 p_result->rcode = RLM_MODULE_NOTFOUND;
1113 goto finish;
1114 }
1115
1116 p_result->rcode = cache_merge(inst, request, entry);
1117
1118finish:
1119 cache_unref(request, inst, entry, handle);
1120
1122}
1123
1124/** Create, or update a cache entry
1125 *
1126 * @return
1127 * - #RLM_MODULE_OK on success.
1128 * - #RLM_MODULE_UPDATED if we merged the cache entry.
1129 * - #RLM_MODULE_FAIL on failure.
1130 */
1131static unlang_action_t CC_HINT(nonnull) mod_method_update(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
1132{
1133 rlm_cache_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1134 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
1135 fr_time_delta_t ttl;
1136 bool expire = false;
1137 rlm_cache_entry_t *entry = NULL;
1138 rlm_cache_handle_t *handle = NULL;
1139 fr_pair_t *vp;
1140
1141 p_result->rcode = RLM_MODULE_NOOP;
1142
1143 if (fr_type_is_variable_size(env->key->type) && (env->key->vb_length == 0)) {
1144 REDEBUG("Zero length key string is invalid");
1146 }
1147
1148 /* Good to go? */
1149 if (cache_acquire(&handle, inst, request) < 0) {
1151 }
1152
1153 /* Process the TTL */
1154 ttl = inst->config.ttl; /* Set the default value from cache { ttl=... } */
1155 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cache_ttl);
1156 if (vp) {
1157 if (vp->vp_int32 == 0) {
1158 expire = true;
1159 } else if (vp->vp_int32 < 0) {
1160 ttl = fr_time_delta_from_sec(-(vp->vp_int32));
1161 /* Updating the TTL */
1162 } else {
1163 ttl = fr_time_delta_from_sec(vp->vp_int32);
1164 }
1165
1166 DEBUG3("Overwriting the default TTL %pV -> %d", fr_box_time_delta(ttl), vp->vp_int32);
1167 }
1168
1169 /*
1170 * We can only alter the TTL on an entry if it exists.
1171 */
1172 cache_find(p_result, &entry, inst, request, &handle, env->key);
1173 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1174
1175 if (p_result->rcode == RLM_MODULE_OK) {
1176 fr_assert(entry != NULL);
1177
1178 DEBUG3("Updating the TTL -> %pV", fr_box_time_delta(ttl));
1179
1180 entry->expires = fr_unix_time_add(fr_time_to_unix_time(request->packet->timestamp), ttl);
1181
1182 cache_set_ttl(p_result, inst, request, &handle, entry);
1183 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1184 }
1185
1186 /*
1187 * Expire the entry if told to, and we either don't know whether
1188 * it exists, or we know it does.
1189 *
1190 * We only expire if we're not inserting, as driver insert methods
1191 * should perform upserts.
1192 */
1193 if (expire) {
1194 DEBUG3("Expiring cache entry");
1195
1196 cache_expire(p_result, inst, request, &handle, env->key);
1197 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1198 }
1199
1200 /*
1201 * Inserts are upserts, so we don't care about the
1202 * entry state.
1203 */
1204 cache_insert(p_result, inst, request, &handle, env->key, env->maps, ttl);
1205 if (p_result->rcode == RLM_MODULE_OK) p_result->rcode = RLM_MODULE_UPDATED;
1206
1207finish:
1208 cache_unref(request, inst, entry, handle);
1209
1211}
1212
1213/** Create, or update a cache entry
1214 *
1215 * @return
1216 * - #RLM_MODULE_NOOP if an entry already existed.
1217 * - #RLM_MODULE_UPDATED if we inserted a cache entry.
1218 * - #RLM_MODULE_FAIL on failure.
1219 */
1220static unlang_action_t CC_HINT(nonnull) mod_method_store(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
1221{
1222 rlm_cache_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1223 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
1224 fr_time_delta_t ttl;
1225 rlm_cache_entry_t *entry = NULL;
1226 rlm_cache_handle_t *handle = NULL;
1227 fr_pair_t *vp;
1228
1229 p_result->rcode = RLM_MODULE_NOOP;
1230
1231 if (fr_type_is_variable_size(env->key->type) && (env->key->vb_length == 0)) {
1232 REDEBUG("Zero length key string is invalid");
1234 }
1235
1236 if (cache_acquire(&handle, inst, request) < 0) {
1238 }
1239
1240 /* Process the TTL */
1241 ttl = inst->config.ttl; /* Set the default value from cache { ttl=... } */
1242 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cache_ttl);
1243 if (vp && (vp->vp_int32 > 0)) {
1244 ttl = fr_time_delta_from_sec(vp->vp_int32);
1245
1246 DEBUG3("Overriding default TTL %pV -> %d", fr_box_time_delta(ttl), vp->vp_int32);
1247 }
1248
1249 /*
1250 * We can only alter the TTL on an entry if it exists.
1251 */
1252 cache_find(p_result, &entry, inst, request, &handle, env->key);
1253 switch (p_result->rcode) {
1254 default:
1255 case RLM_MODULE_OK:
1256 p_result->rcode = RLM_MODULE_NOOP;
1257 goto finish;
1258
1259 case RLM_MODULE_FAIL:
1260 goto finish;
1261
1263 break;
1264 }
1265
1266 /*
1267 * Inserts are upserts, so we don't care about the
1268 * entry state, just that we're not meant to be
1269 * setting the TTL, which precludes performing an
1270 * insert.
1271 */
1272 cache_insert(p_result, inst, request, &handle, env->key, env->maps, ttl);
1273
1274finish:
1275 cache_unref(request, inst, entry, handle);
1276 if (p_result->rcode == RLM_MODULE_OK) p_result->rcode = RLM_MODULE_UPDATED;
1277
1279}
1280
1281/** Delete the entries by ${key}
1282 *
1283 * @return
1284 * - #RLM_MODULE_OK on success.
1285 * - #RLM_MODULE_NOTFOUND on cache miss.
1286 * - #RLM_MODULE_FAIL on failure.
1287 */
1288static unlang_action_t CC_HINT(nonnull) mod_method_clear(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
1289{
1290 rlm_cache_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1291 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
1292 rlm_cache_entry_t *entry = NULL;
1293 rlm_cache_handle_t *handle = NULL;
1294
1295 p_result->rcode = RLM_MODULE_NOOP;
1296
1297 DEBUG3("Calling %s.clear", mctx->mi->name);
1298
1299 if (fr_type_is_variable_size(env->key->type) && (env->key->vb_length == 0)) {
1300 REDEBUG("Zero length key string is invalid");
1302 }
1303
1304 /* Good to go? */
1305 if (cache_acquire(&handle, inst, request) < 0) {
1307 }
1308
1309 cache_find(p_result, &entry, inst, request, &handle, env->key);
1310 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1311
1312 if (!entry) {
1313 REDEBUG2("Entry not found to delete");
1314 p_result->rcode = RLM_MODULE_NOTFOUND;
1315 goto finish;
1316 }
1317
1318 cache_expire(p_result, inst, request, &handle, env->key);
1319
1320finish:
1321 cache_unref(request, inst, entry, handle);
1322
1324}
1325
1326/** Change the TTL on an existing entry.
1327 *
1328 * @return
1329 * - #RLM_MODULE_UPDATED on success.
1330 * - #RLM_MODULE_NOTFOUND on cache miss.
1331 * - #RLM_MODULE_FAIL on failure.
1332 */
1333static unlang_action_t CC_HINT(nonnull) mod_method_ttl(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
1334{
1335 rlm_cache_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1336 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
1337 fr_time_delta_t ttl;
1338 rlm_cache_entry_t *entry = NULL;
1339 rlm_cache_handle_t *handle = NULL;
1340 fr_pair_t *vp;
1341
1342 p_result->rcode = RLM_MODULE_NOOP;
1343
1344 DEBUG3("Calling %s.ttl", mctx->mi->name);
1345
1346 if (fr_type_is_variable_size(env->key->type) && (env->key->vb_length == 0)) {
1347 REDEBUG("Zero length key string is invalid");
1349 }
1350
1351 /* Good to go? */
1352 if (cache_acquire(&handle, inst, request) < 0) {
1354 }
1355
1356 /* Process the TTL */
1357 ttl = inst->config.ttl; /* Set the default value from cache { ttl=... } */
1358 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cache_ttl);
1359 if (vp) {
1360 if (vp->vp_int32 < 0) {
1361 ttl = fr_time_delta_from_sec(-(vp->vp_int32));
1362 /* Updating the TTL */
1363 } else {
1364 ttl = fr_time_delta_from_sec(vp->vp_int32);
1365 }
1366
1367 DEBUG3("Overwriting the default TTL %pV -> %d", fr_box_time_delta(inst->config.ttl), vp->vp_int32);
1368 }
1369
1370 /*
1371 * We can only alter the TTL on an entry if it exists.
1372 */
1373 cache_find(p_result, &entry, inst, request, &handle, env->key);
1374 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1375
1376 if (p_result->rcode == RLM_MODULE_OK) {
1377 fr_assert(entry != NULL);
1378
1379 DEBUG3("Updating the TTL -> %pV", fr_box_time_delta(ttl));
1380
1381 entry->expires = fr_unix_time_add(fr_time_to_unix_time(request->packet->timestamp), ttl);
1382
1383 cache_set_ttl(p_result, inst, request, &handle, entry);
1384 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1385
1386 p_result->rcode = RLM_MODULE_UPDATED;
1387 }
1388
1389finish:
1390 cache_unref(request, inst, entry, handle);
1391
1393}
1394
1395/** Free any memory allocated under the instance
1396 *
1397 */
1398static int mod_detach(module_detach_ctx_t const *mctx)
1399{
1400 rlm_cache_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1401
1402 /*
1403 * We need to explicitly free all children, so if the driver
1404 * parented any memory off the instance, their destructors
1405 * run before we unload the bytecode for them.
1406 *
1407 * If we don't do this, we get a SEGV deep inside the talloc code
1408 * when it tries to call a destructor that no longer exists.
1409 */
1410 talloc_free_children(inst);
1411
1412 return 0;
1413}
1414
1415/** Verify that a map in the cache section makes sense
1416 *
1417 */
1418static int cache_verify(map_t *map, void *uctx)
1419{
1420 if (unlang_fixup_update(map, uctx) < 0) return -1;
1421
1422 if (!tmpl_is_attr(map->lhs)) {
1423 cf_log_err(map->ci, "Destination must be an attribute ref or a list");
1424 return -1;
1425 }
1426
1427 if (!fr_assignment_op[map->op]) {
1428 cf_log_err(map->ci, "Invalid operator '%s'", fr_tokens[map->op]);
1429 return -1;
1430 }
1431
1432 return 0;
1433}
1434
1435static int cache_update_section_parse(TALLOC_CTX *ctx, call_env_parsed_head_t *out, tmpl_rules_t const *t_rules,
1436 CONF_ITEM *ci,
1437 UNUSED call_env_ctx_t const *cec, UNUSED call_env_parser_t const *rule)
1438{
1439 CONF_SECTION *update = cf_item_to_section(ci);
1440 call_env_parsed_t *parsed;
1441 map_list_t *maps;
1442
1443 MEM(parsed = call_env_parsed_add(ctx, out,
1445
1446 MEM(maps = talloc(parsed, map_list_t));
1447 map_list_init(maps);
1448
1449 if (map_afrom_cs(maps, maps, update,
1450 t_rules, t_rules, cache_verify, NULL, MAX_ATTRMAP) < 0) {
1451 error:
1452 call_env_parsed_free(out, parsed);
1453 return -1;
1454 }
1455
1456 if (map_list_empty(maps)) {
1457 cf_log_err(update, "Update section must not be empty");
1458 goto error;
1459 }
1460
1461 call_env_parsed_set_data(parsed, maps);
1462
1463 return 0;
1464}
1465
1466/** Create a new rlm_cache_instance
1467 *
1468 */
1469static int mod_instantiate(module_inst_ctx_t const *mctx)
1470{
1471 rlm_cache_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1472 CONF_SECTION *conf = mctx->mi->conf;
1473
1474 /*
1475 * Non optional fields and callbacks
1476 */
1477 fr_assert(inst->driver->common.name);
1478 fr_assert(inst->driver->find);
1479 fr_assert(inst->driver->insert);
1480 fr_assert(inst->driver->expire);
1481
1482 if (!fr_time_delta_ispos(inst->config.ttl)) {
1483 cf_log_err(conf, "Must set 'ttl' to non-zero");
1484 return -1;
1485 }
1486
1487 if (inst->config.epoch != 0) {
1488 cf_log_err(conf, "Must not set 'epoch' in the configuration files");
1489 return -1;
1490 }
1491
1492 return 0;
1493}
1494
1495/** Register module xlats
1496 *
1497 */
1498static int mod_bootstrap(module_inst_ctx_t const *mctx)
1499{
1500 xlat_t *xlat;
1501
1502 /*
1503 * Register the cache xlat function
1504 */
1505 xlat = module_rlm_xlat_register(mctx->mi->boot, mctx, NULL, cache_xlat, FR_TYPE_VOID);
1508
1509 xlat = module_rlm_xlat_register(mctx->mi->boot, mctx, "ttl.get", cache_ttl_get_xlat, FR_TYPE_VOID);
1511
1512 return 0;
1513}
1514
1515/*
1516 * The module name should be the only globally exported symbol.
1517 * That is, everything else should be 'static'.
1518 *
1519 * If the module needs to temporarily modify it's instantiation
1520 * data, the type should be changed to MODULE_TYPE_THREAD_UNSAFE.
1521 * The server will then take care of ensuring that the module
1522 * is single-threaded.
1523 */
1525 .common = {
1526 .magic = MODULE_MAGIC_INIT,
1527 .name = "cache",
1528 .inst_size = sizeof(rlm_cache_t),
1530 .bootstrap = mod_bootstrap,
1531 .instantiate = mod_instantiate,
1532 .detach = mod_detach
1533 },
1534 .method_group = {
1535 .bindings = (module_method_binding_t[]){
1536 { .section = SECTION_NAME("clear", CF_IDENT_ANY), .method = mod_method_clear, .method_env = &cache_method_env },
1537 { .section = SECTION_NAME("load", CF_IDENT_ANY), .method = mod_method_load, .method_env = &cache_method_env },
1538 { .section = SECTION_NAME("status", CF_IDENT_ANY), .method = mod_method_status, .method_env = &cache_method_env },
1539 { .section = SECTION_NAME("store", CF_IDENT_ANY), .method = mod_method_store, .method_env = &cache_method_env },
1540 { .section = SECTION_NAME("ttl", CF_IDENT_ANY), .method = mod_method_ttl, .method_env = &cache_method_env },
1541 { .section = SECTION_NAME("update", CF_IDENT_ANY), .method = mod_method_update, .method_env = &cache_method_env },
1542 { .section = SECTION_NAME(CF_IDENT_ANY, CF_IDENT_ANY), .method = mod_cache_it, .method_env = &cache_method_env },
1544 }
1545 }
1546};
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
@ UNLANG_ACTION_CALCULATE_RESULT
Calculate a new section rlm_rcode_t value.
Definition action.h:37
static int const char char buffer[256]
Definition acutest.h:576
#define RCSID(id)
Definition build.h:485
#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
void call_env_parsed_free(call_env_parsed_head_t *parsed, call_env_parsed_t *ptr)
Remove a call_env_parsed_t from the list of parsed call envs.
Definition call_env.c:775
call_env_parsed_t * call_env_parsed_add(TALLOC_CTX *ctx, call_env_parsed_head_t *head, call_env_parser_t const *rule)
Allocate a new call_env_parsed_t structure and add it to the list of parsed call envs.
Definition call_env.c:688
void call_env_parsed_set_data(call_env_parsed_t *parsed, void const *data)
Assign data to a call_env_parsed_t.
Definition call_env.c:745
int call_env_parse_pair(TALLOC_CTX *ctx, void *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci, UNUSED call_env_ctx_t const *cec, call_env_parser_t const *rule)
Standard function we use for parsing call env pairs.
Definition call_env.c:418
#define CALL_ENV_TERMINATOR
Definition call_env.h:236
#define FR_CALL_ENV_METHOD_OUT(_inst)
Helper macro for populating the size/type fields of a call_env_method_t from the output structure typ...
Definition call_env.h:240
call_env_parser_t const * env
Parsing rules for call method env.
Definition call_env.h:247
@ CALL_ENV_FLAG_NONE
Definition call_env.h:74
@ CALL_ENV_FLAG_REQUIRED
Associated conf pair or section is required.
Definition call_env.h:75
module_instance_t const * mi
Module instance that the callenv is registered to.
Definition call_env.h:229
#define FR_CALL_ENV_SUBSECTION_FUNC(_name, _name2, _flags, _func)
Specify a call_env_parser_t which parses a subsection using a callback function.
Definition call_env.h:412
int(* call_env_parse_pair_t)(TALLOC_CTX *ctx, void *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci, call_env_ctx_t const *cec, call_env_parser_t const *rule)
Callback for performing custom parsing of a CONF_PAIR.
Definition call_env.h:151
#define FR_CALL_ENV_OFFSET(_name, _cast_type, _flags, _struct, _field)
Specify a call_env_parser_t which writes out runtime results to the specified field.
Definition call_env.h:340
#define FR_CALL_ENV_PARSE_ONLY_OFFSET(_name, _cast_type, _flags, _struct, _parse_field)
Specify a call_env_parser_t which writes out the result of the parsing phase to the field specified.
Definition call_env.h:389
Per method call config.
Definition call_env.h:180
#define CONF_PARSER_TERMINATOR
Definition cf_parse.h:662
cf_parse_t func
Override default parsing behaviour for the specified type with a custom parsing function.
Definition cf_parse.h:616
#define FR_CONF_OFFSET(_name, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:284
#define FR_CONF_OFFSET_TYPE_FLAGS(_name, _type, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:241
Defines a CONF_PAIR to C data type mapping.
Definition cf_parse.h:599
Common header for all CONF_* types.
Definition cf_priv.h:49
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:101
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
Definition cf_util.c:683
#define cf_log_err(_cf, _fmt,...)
Definition cf_util.h:289
#define cf_log_perr(_cf, _fmt,...)
Definition cf_util.h:296
#define CF_IDENT_ANY
Definition cf_util.h:78
static void * fr_dcursor_next(fr_dcursor_t *cursor)
Advanced the cursor to the next item.
Definition dcursor.h:290
static int fr_dcursor_append(fr_dcursor_t *cursor, void *v)
Insert a single item at the end of the list.
Definition dcursor.h:408
static void * fr_dcursor_remove(fr_dcursor_t *cursor)
Remove the current item.
Definition dcursor.h:482
static void * fr_dcursor_current(fr_dcursor_t *cursor)
Return the item the cursor current points to.
Definition dcursor.h:339
#define MEM(x)
Definition debug.h:36
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
Definition dict.h:274
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition dict.h:287
static bool fr_dict_attr_is_top_level(fr_dict_attr_t const *da)
Return true if this attribute is parented directly off the dictionary root.
Definition dict.h:775
static fr_slen_t in
Definition dict.h:848
Specifies an attribute which must be present for the module to function.
Definition dict.h:273
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition dict.h:286
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
static xlat_action_t cache_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
Allow single attribute values to be retrieved from the cache.
Definition rlm_cache.c:890
rlm_rcode_t rcode
The current rcode, from executing the instruction or merging the result from a frame.
Definition interpret.h:134
#define REXDENT()
Exdent (unindent) R* messages by one level.
Definition log.h:443
#define DEBUG3(_fmt,...)
Definition log.h:266
#define RWDEBUG(fmt,...)
Definition log.h:361
#define RDEBUG3(fmt,...)
Definition log.h:343
#define RERROR(fmt,...)
Definition log.h:298
#define RPEDEBUG(fmt,...)
Definition log.h:376
#define REDEBUG2(fmt,...)
Definition log.h:372
#define RINDENT()
Indent R* messages by one level.
Definition log.h:430
int map_to_vp(TALLOC_CTX *ctx, fr_pair_list_t *out, request_t *request, map_t const *map, UNUSED void *uctx)
Convert a map to a fr_pair_t.
Definition map.c:1593
int map_afrom_cs(TALLOC_CTX *ctx, map_list_t *out, CONF_SECTION *cs, tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules, map_validate_t validate, void *uctx, unsigned int max)
Convert a config section into an attribute map.
Definition map.c:1131
int map_to_request(request_t *request, map_t const *map, radius_map_getvalue_t func, void *ctx)
Convert map_t to fr_pair_t (s) and add them to a request_t.
Definition map.c:1873
ssize_t map_print(fr_sbuff_t *out, map_t const *map)
Print a map to a string.
Definition map.c:2390
void map_debug_log(request_t *request, map_t const *map, fr_pair_t const *vp)
Definition map.c:2445
talloc_free(reap)
fr_type_t
@ 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_UINT32
32 Bit unsigned integer.
@ FR_TYPE_INT32
32 Bit signed integer.
@ FR_TYPE_VOID
User data.
@ FR_TYPE_BOOL
A truth value.
long int ssize_t
static bool is_printable(void const *value, size_t len)
Check whether the string is made up of printable UTF8 chars.
Definition misc.h:88
int unlang_fixup_update(map_t *map, void *ctx)
Validate and fixup a map that's part of an update section.
Definition compile.c:351
void * env_data
Per call environment data.
Definition module_ctx.h:44
module_instance_t const * mi
Instance of the module being instantiated.
Definition module_ctx.h:42
module_instance_t * mi
Module instance to detach.
Definition module_ctx.h:57
module_instance_t * mi
Instance of the module being instantiated.
Definition module_ctx.h:51
Temporary structure to hold arguments for module calls.
Definition module_ctx.h:41
Temporary structure to hold arguments for detach calls.
Definition module_ctx.h:56
Temporary structure to hold arguments for instantiation calls.
Definition module_ctx.h:50
xlat_t * module_rlm_xlat_register(TALLOC_CTX *ctx, module_inst_ctx_t const *mctx, char const *name, xlat_func_t func, fr_type_t return_type)
Definition module_rlm.c:243
int module_rlm_submodule_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Generic conf_parser_t func for loading drivers.
Definition module_rlm.c:939
module_t common
Common fields presented by all modules.
Definition module_rlm.h:39
fr_pair_t * fr_pair_find_by_da(fr_pair_list_t const *list, fr_pair_t const *prev, fr_dict_attr_t const *da)
Find the first pair with a matching da.
Definition pair.c:698
void fr_pair_list_init(fr_pair_list_t *list)
Initialise a pair list header.
Definition pair.c:46
static const conf_parser_t config[]
Definition base.c:186
#define fr_assert(_expr)
Definition rad_assert.h:38
#define pair_update_request(_attr, _da)
#define REDEBUG(fmt,...)
Definition radclient.h:52
#define RDEBUG_ENABLED2()
Definition radclient.h:50
#define RDEBUG2(fmt,...)
Definition radclient.h:54
static rs_t * conf
Definition radsniff.c:53
#define RETURN_UNLANG_INVALID
Definition rcode.h:62
#define RETURN_UNLANG_RCODE(_rcode)
Definition rcode.h:57
#define RETURN_UNLANG_NOTFOUND
Definition rcode.h:64
#define RETURN_UNLANG_FAIL
Definition rcode.h:59
#define RETURN_UNLANG_OK
Definition rcode.h:60
rlm_rcode_t
Return codes indicating the result of the module call.
Definition rcode.h:40
@ RLM_MODULE_OK
The module is OK, continue.
Definition rcode.h:45
@ RLM_MODULE_FAIL
Module failed, don't reply.
Definition rcode.h:44
@ RLM_MODULE_NOTFOUND
User not found.
Definition rcode.h:49
@ RLM_MODULE_UPDATED
OK (pairs modified).
Definition rcode.h:51
@ RLM_MODULE_NOOP
Module succeeded without doing anything.
Definition rcode.h:50
static int cache_acquire(rlm_cache_handle_t **out, rlm_cache_t const *inst, request_t *request)
Get exclusive use of a handle to access the cache.
Definition rlm_cache.c:169
static int mod_detach(module_detach_ctx_t const *mctx)
Free any memory allocated under the instance.
Definition rlm_cache.c:1398
static fr_dict_attr_t const * attr_cache_allow_merge
Definition rlm_cache.c:92
static int cache_key_parse(TALLOC_CTX *ctx, void *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci, call_env_ctx_t const *cec, call_env_parser_t const *rule)
Definition rlm_cache.c:122
fr_type_t ktype
Key type.
Definition rlm_cache.c:69
fr_value_box_t * key
To lookup the cache entry with.
Definition rlm_cache.c:64
static unlang_action_t mod_method_store(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Create, or update a cache entry.
Definition rlm_cache.c:1220
static int cache_update_section_parse(TALLOC_CTX *ctx, call_env_parsed_head_t *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci, call_env_ctx_t const *cec, call_env_parser_t const *rule)
static unlang_action_t mod_method_status(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Get the status by ${key} (without load)
Definition rlm_cache.c:1049
static fr_dict_attr_t const * attr_cache_ttl
Definition rlm_cache.c:94
static unlang_action_t mod_method_load(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Load the avps by ${key}.
Definition rlm_cache.c:1088
static fr_dict_attr_t const * attr_cache_merge_new
Definition rlm_cache.c:90
static void cache_release(rlm_cache_t const *inst, request_t *request, rlm_cache_handle_t **handle)
Release a handle we previously acquired.
Definition rlm_cache.c:182
static fr_dict_t const * dict_freeradius
Definition rlm_cache.c:82
static int cache_verify(map_t *map, void *uctx)
Verify that a map in the cache section makes sense.
Definition rlm_cache.c:1418
map_list_t * maps
Attribute map applied to cache entries.
Definition rlm_cache.c:65
static rlm_cache_entry_t * cache_alloc(rlm_cache_t const *inst, request_t *request)
Allocate a cache entry.
Definition rlm_cache.c:209
static fr_dict_attr_t const * attr_cache_allow_insert
Definition rlm_cache.c:93
static unlang_action_t cache_set_ttl(unlang_result_t *p_result, rlm_cache_t const *inst, request_t *request, rlm_cache_handle_t **handle, rlm_cache_entry_t *c)
Update the TTL of an entry.
Definition rlm_cache.c:566
static int mod_bootstrap(module_inst_ctx_t const *mctx)
Register module xlats.
Definition rlm_cache.c:1498
static fr_dict_attr_t const * attr_cache_status_only
Definition rlm_cache.c:91
static void cache_free(rlm_cache_t const *inst, rlm_cache_entry_t **c)
Free memory associated with a cache entry.
Definition rlm_cache.c:230
static fr_dict_attr_t const * attr_cache_entry_hits
Definition rlm_cache.c:95
static unlang_action_t mod_method_ttl(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Change the TTL on an existing entry.
Definition rlm_cache.c:1333
static xlat_arg_parser_t const cache_xlat_args[]
Definition rlm_cache.c:880
module_rlm_t rlm_cache
Definition rlm_cache.c:1524
static int cache_reconnect(rlm_cache_handle_t **handle, rlm_cache_t const *inst, request_t *request)
Reconnect an suspected inviable handle.
Definition rlm_cache.c:194
static unlang_action_t mod_method_clear(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Delete the entries by ${key}.
Definition rlm_cache.c:1288
static const call_env_method_t cache_method_env
Definition rlm_cache.c:73
fr_dict_attr_autoload_t rlm_cache_dict_attr[]
Definition rlm_cache.c:98
static unlang_action_t cache_insert(unlang_result_t *p_result, rlm_cache_t const *inst, request_t *request, rlm_cache_handle_t **handle, fr_value_box_t const *key, map_list_t const *maps, fr_time_delta_t ttl)
Create and insert a cache entry.
Definition rlm_cache.c:389
fr_dict_autoload_t rlm_cache_dict[]
Definition rlm_cache.c:85
static unlang_action_t mod_method_update(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Create, or update a cache entry.
Definition rlm_cache.c:1131
static xlat_action_t cache_ttl_get_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, UNUSED fr_value_box_list_t *in)
Definition rlm_cache.c:965
static rlm_rcode_t cache_merge(rlm_cache_t const *inst, request_t *request, rlm_cache_entry_t *c)
Merge a cached entry into a request_t.
Definition rlm_cache.c:245
static void cache_unref(request_t *request, rlm_cache_t const *inst, rlm_cache_entry_t *entry, rlm_cache_handle_t *handle)
Release the allocated resources and cleanup the avps.
Definition rlm_cache.c:1005
int submodule_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Definition rlm_cache.c:108
static unlang_action_t cache_expire(unlang_result_t *p_result, rlm_cache_t const *inst, request_t *request, rlm_cache_handle_t **handle, fr_value_box_t const *key)
Expire a cache entry (removing it from the datastore)
Definition rlm_cache.c:361
static const conf_parser_t module_config[]
Definition rlm_cache.c:51
static int mod_instantiate(module_inst_ctx_t const *mctx)
Create a new rlm_cache_instance.
Definition rlm_cache.c:1469
static unlang_action_t mod_cache_it(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
Do caching checks.
Definition rlm_cache.c:622
static unlang_action_t cache_find(unlang_result_t *p_result, rlm_cache_entry_t **out, rlm_cache_t const *inst, request_t *request, rlm_cache_handle_t **handle, fr_value_box_t const *key)
Find a cached entry.
Definition rlm_cache.c:291
fr_value_box_t key
Key used to identify entry.
Definition rlm_cache.h:73
map_list_t maps
Head of the maps list.
Definition rlm_cache.h:78
fr_unix_time_t created
When the entry was created.
Definition rlm_cache.h:75
long long int hits
How many times the entry has been retrieved.
Definition rlm_cache.h:74
#define MAX_ATTRMAP
Definition rlm_cache.h:37
cache_status_t
Definition rlm_cache.h:39
@ CACHE_RECONNECT
Handle needs to be reconnected.
Definition rlm_cache.h:40
@ CACHE_OK
Cache entry found/updated.
Definition rlm_cache.h:42
@ CACHE_MISS
Cache entry notfound.
Definition rlm_cache.h:43
void rlm_cache_handle_t
Definition rlm_cache.h:35
fr_unix_time_t expires
When the entry expires.
Definition rlm_cache.h:76
Configuration for the rlm_cache module.
Definition rlm_cache.h:51
Definition rlm_cache.h:72
#define FR_SBUFF_IN(_start, _len_or_end)
#define FR_SBUFF_OUT(_start, _len_or_end)
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
Definition section.h:40
#define MAP_VERIFY(_x)
Definition map.h:108
char const * name
Instance name e.g. user_database.
Definition module.h:355
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:349
size_t inst_size
Size of the module's instance data.
Definition module.h:212
void * data
Module's instance data.
Definition module.h:291
void * boot
Data allocated during the boostrap phase.
Definition module.h:294
#define MODULE_BINDING_TERMINATOR
Terminate a module binding list.
Definition module.h:152
module_t * exported
Public module structure.
Definition module.h:296
Module instance data.
Definition module.h:285
Named methods exported by a module.
Definition module.h:174
#define tmpl_value(_tmpl)
Definition tmpl.h:937
tmpl_t * tmpl_alloc(TALLOC_CTX *ctx, tmpl_type_t type, fr_token_t quote, char const *name, ssize_t len)
Create a new heap allocated tmpl_t.
#define tmpl_is_attr(vpt)
Definition tmpl.h:208
static fr_dict_attr_t const * tmpl_list(tmpl_t const *vpt)
Definition tmpl.h:904
@ TMPL_TYPE_ATTR
Reference to one or more attributes.
Definition tmpl.h:142
@ TMPL_TYPE_DATA
Value in native boxed format.
Definition tmpl.h:138
int tmpl_attr_afrom_list(TALLOC_CTX *ctx, tmpl_t **out, tmpl_t const *list, fr_dict_attr_t const *da)
Create a new tmpl from a list tmpl and a da.
static bool tmpl_attr_tail_da_is_structural(tmpl_t const *vpt)
Return true if the the last attribute reference is a structural attribute.
Definition tmpl.h:835
static bool tmpl_is_list(tmpl_t const *vpt)
Definition tmpl.h:920
ssize_t tmpl_afrom_attr_substr(TALLOC_CTX *ctx, tmpl_attr_error_t *err, tmpl_t **out, fr_sbuff_t *name, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules))
Parse a string into a TMPL_TYPE_ATTR_* type tmpl_t.
static fr_type_t tmpl_cast_get(tmpl_t *vpt)
Definition tmpl.h:1218
static fr_dict_attr_t const * tmpl_attr_tail_da(tmpl_t const *vpt)
Return the last attribute reference da.
Definition tmpl.h:801
int tmpl_cast_set(tmpl_t *vpt, fr_type_t type)
Set a cast for a tmpl.
fr_type_t tmpl_expanded_type(tmpl_t const *vpt)
Return the native data type of the expression.
Definition tmpl_eval.c:203
Optional arguments passed to vp_tmpl functions.
Definition tmpl.h:332
eap_aka_sim_process_conf_t * inst
fr_pair_t * vp
Value pair map.
Definition map.h:77
fr_token_t op
The operator that controls insertion of the dst attribute.
Definition map.h:82
tmpl_t * lhs
Typically describes the attribute to add, modify or compare.
Definition map.h:78
map_list_t child
parent map, for nested ones
Definition map.h:89
tmpl_t * rhs
Typically describes a literal value or a src attribute to copy or compare.
Definition map.h:79
CONF_ITEM * ci
Config item that the map was created from.
Definition map.h:85
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 talloc_get_type_abort_const
Definition talloc.h:287
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
static fr_unix_time_t fr_unix_time_from_sec(int64_t sec)
Definition time.h:449
#define fr_unix_time_sub(_a, _b)
Subtract one time from another.
Definition time.h:357
static fr_unix_time_t fr_time_to_unix_time(fr_time_t when)
Convert an fr_time_t (internal time) to our version of unix time (wallclock time)
Definition time.h:688
#define fr_unix_time_lt(_a, _b)
Definition time.h:367
#define fr_unix_time_add(_a, _b)
Add a time/time delta together.
Definition time.h:324
A time delta, a difference in time measured in nanoseconds.
Definition time.h:80
const bool fr_assignment_op[T_TOKEN_LAST]
Definition token.c:169
char const * fr_tokens[T_TOKEN_LAST]
Definition token.c:79
enum fr_token fr_token_t
@ T_SINGLE_QUOTED_STRING
Definition token.h:122
@ T_BARE_WORD
Definition token.h:120
@ T_DOUBLE_QUOTED_STRING
Definition token.h:121
uint8_t required
Argument must be present, and non-empty.
Definition xlat.h:146
#define XLAT_ARG_PARSER_TERMINATOR
Definition xlat.h:170
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:145
fr_pair_t * fr_pair_list_next(fr_pair_list_t const *list, fr_pair_t const *item))
Get the next item in a valuepair list after a specific entry.
Definition pair_inline.c:69
#define fr_pair_dcursor_init(_cursor, _list)
Initialises a special dcursor with callbacks that will maintain the attr sublists correctly.
Definition pair.h:589
fr_pair_t * fr_pair_list_head(fr_pair_list_t const *list)
Get the head of a valuepair list.
Definition pair_inline.c:42
static fr_slen_t parent
Definition pair.h:841
#define fr_type_is_variable_size(_x)
Definition types.h:386
static char const * fr_type_to_str(fr_type_t type)
Return a static string containing the type name.
Definition types.h:452
int fr_value_box_copy(TALLOC_CTX *ctx, fr_value_box_t *dst, const fr_value_box_t *src)
Copy value data verbatim duplicating any buffers.
Definition value.c:4156
#define fr_value_box_alloc(_ctx, _type, _enumv)
Allocate a value box of a specific type.
Definition value.h:643
#define fr_box_time_delta(_val)
Definition value.h:365
int nonnull(2, 5))
#define fr_value_box_alloc_null(_ctx)
Allocate a value box for later use with a value assignment function.
Definition value.h:654
#define fr_box_time(_val)
Definition value.h:348
static size_t char ** out
Definition value.h:1023
#define fr_box_date(_val)
Definition value.h:346
void * env_data
Expanded call env data.
Definition xlat_ctx.h:53
module_ctx_t const * mctx
Synthesised module calling ctx.
Definition xlat_ctx.h:52
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:363
void xlat_func_call_env_set(xlat_t *x, call_env_method_t const *env_method)
Register call environment of an xlat.
Definition xlat_func.c:389