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: 581102dd54a6dcfe4c946c76ed9c96dd4ec5be12 $
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: 581102dd54a6dcfe4c946c76ed9c96dd4ec5be12 $")
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_list_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" },
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 },
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 mi = talloc_get_type_abort(*((void **)out), module_instance_t);
116 inst->driver = (rlm_cache_driver_t const *)mi->exported; /* Public symbol exported by the submodule */
117
118 return 0;
119}
120
121static int cache_key_parse(TALLOC_CTX *ctx, void *out, tmpl_rules_t const *t_rules, CONF_ITEM *ci,
122 call_env_ctx_t const *cec,
123 call_env_parser_t const *rule)
124{
126 call_env_parse_pair_t func = inst->driver->key_parse ? inst->driver->key_parse : call_env_parse_pair;
127 tmpl_t *key_tmpl;
128 fr_type_t cast;
129 int ret;
130 /*
131 * Call the custom key parse function, OR the standard call_env_parse_pair
132 * function, depending on whether the driver calls a custom parsing function.
133 */
134 if (unlikely((ret = func(ctx, &key_tmpl, t_rules, ci, cec, rule)) < 0)) return ret;
135 *((tmpl_t **)out) = key_tmpl;
136
137 /*
138 * Unless the driver has a custom key parse function, we only allow keys of
139 * type string.
140 */
141 if (inst->driver->key_parse) return 0;
142
143 cast = tmpl_cast_get(key_tmpl);
144 switch (cast) {
145 case FR_TYPE_STRING:
146 case FR_TYPE_NULL:
147 case FR_TYPE_VOID:
148 break;
149
150 default:
151 cf_log_err(ci, "Driver only allows key type '%s', got '%s'",
153 return -1;
154 }
155
156 if (tmpl_cast_set(key_tmpl, FR_TYPE_STRING) < 0) {
157 cf_log_perr(ci, "Can't convert key type '%s' to '%s'",
159 return -1;
160 }
161
162 return 0;
163}
164
165/** Get exclusive use of a handle to access the cache
166 *
167 */
169{
170 if (!inst->driver->acquire) {
171 *out = NULL;
172 return 0;
173 }
174
175 return inst->driver->acquire(out, &inst->config, inst->driver_submodule->data, request);
176}
177
178/** Release a handle we previously acquired
179 *
180 */
181static void cache_release(rlm_cache_t const *inst, request_t *request, rlm_cache_handle_t **handle)
182{
183 if (!inst->driver->release) return;
184 if (!handle || !*handle) return;
185
186 inst->driver->release(&inst->config, inst->driver_submodule->data, request, *handle);
187 *handle = NULL;
188}
189
190/** Reconnect an suspected inviable handle
191 *
192 */
193static int cache_reconnect(rlm_cache_handle_t **handle, rlm_cache_t const *inst, request_t *request)
194{
195 fr_assert(inst->driver->reconnect);
196
197 return inst->driver->reconnect(handle, &inst->config, inst->driver_submodule->data, request);
198}
199
200/** Allocate a cache entry
201 *
202 * This is used so that drivers may use their own allocation functions
203 * to allocate structures larger than the normal rlm_cache_entry_t.
204 *
205 * If the driver doesn't specify a custom allocation function, the cache
206 * entry is talloced in the NULL ctx.
207 */
209{
210 if (inst->driver->alloc) return inst->driver->alloc(&inst->config, inst->driver_submodule->data, request);
211
212 return talloc_zero(NULL, rlm_cache_entry_t);
213}
214
215/** Free memory associated with a cache entry
216 *
217 * This does not necessarily remove the entry from the cache, cache_expire
218 * should be used for that.
219 *
220 * This function should be called when an entry that is known to have been
221 * retrieved or inserted into a data store successfully, is no longer needed.
222 *
223 * Some drivers (like rlm_cache_rbtree) don't register a free function.
224 * This means that the cache entry never needs to be explicitly freed.
225 *
226 * @param[in] inst Module instance.
227 * @param[in,out] c Cache entry to free.
228 */
230{
231 if (!c || !*c || !inst->driver->free) return;
232
233 inst->driver->free(*c);
234 *c = NULL;
235}
236
237/** Merge a cached entry into a #request_t
238 *
239 * @return
240 * - #RLM_MODULE_OK if no entries were merged.
241 * - #RLM_MODULE_UPDATED if entries were merged.
242 */
243static rlm_rcode_t cache_merge(rlm_cache_t const *inst, request_t *request, rlm_cache_entry_t *c) CC_HINT(nonnull);
245{
246 fr_pair_t *vp;
247 map_t *map = NULL;
248 int merged = 0;
249
250 RDEBUG2("Merging cache entry into request");
251 RINDENT();
252 while ((map = map_list_next(&c->maps, map))) {
253 /*
254 * The only reason that the application of a map entry
255 * can fail, is if the destination list or request
256 * isn't valid. For now we don't consider this fatal
257 * and continue merging the rest of the maps.
258 */
259 if (map_to_request(request, map, map_to_vp, NULL) < 0) {
260 char buffer[1024];
261
262 map_print(&FR_SBUFF_OUT(buffer, sizeof(buffer)), map);
263 REXDENT();
264 RDEBUG2("Skipping %s", buffer);
265 RINDENT();
266 continue;
267 }
268 merged++;
269 }
270 REXDENT();
271
272 if (inst->config.stats) {
273 fr_assert(request->packet != NULL);
275 vp->vp_uint32 = c->hits;
276 }
277
278 return merged > 0 ?
281}
282
283/** Find a cached entry.
284 *
285 * @return
286 * - #RLM_MODULE_OK on cache hit.
287 * - #RLM_MODULE_FAIL on failure.
288 * - #RLM_MODULE_NOTFOUND on cache miss.
289 */
291 rlm_cache_t const *inst, request_t *request,
292 rlm_cache_handle_t **handle, fr_value_box_t const *key)
293{
294 cache_status_t ret;
295
297
298 *out = NULL;
299
300 for (;;) {
301 ret = inst->driver->find(&c, &inst->config, inst->driver_submodule->data, request, *handle, key);
302 switch (ret) {
303 case CACHE_RECONNECT:
304 RDEBUG2("Reconnecting...");
305 if (cache_reconnect(handle, inst, request) == 0) continue;
307
308 case CACHE_OK:
309 break;
310
311 case CACHE_MISS:
312 RDEBUG2("No cache entry found for \"%pV\"", key);
314
315 default:
317
318 }
319
320 break;
321 }
322
323 /*
324 * Yes, but it expired, OR the "forget all" epoch has
325 * passed. Delete it, and pretend it doesn't exist.
326 */
327 if (fr_unix_time_lt(c->expires, fr_time_to_unix_time(request->packet->timestamp))) {
328 RDEBUG2("Found entry for \"%pV\", but it expired %pV ago at %pV (packet received %pV). Removing it",
329 key,
330 fr_box_time_delta(fr_unix_time_sub(fr_time_to_unix_time(request->packet->timestamp), c->expires)),
332 fr_box_time(request->packet->timestamp));
333
334 expired:
335 inst->driver->expire(&inst->config, inst->driver_submodule->data, request, handle, key);
336 cache_free(inst, &c);
337 RETURN_UNLANG_NOTFOUND; /* Couldn't find a non-expired entry */
338 }
339
340 if (fr_unix_time_lt(c->created, fr_unix_time_from_sec(inst->config.epoch))) {
341 RDEBUG2("Found entry for \"%pV\", but it was created before the current epoch. Removing it",
342 key);
343 goto expired;
344 }
345 RDEBUG2("Found entry for \"%pV\"", key);
346
347 c->hits++;
348 *out = c;
349
351}
352
353/** Expire a cache entry (removing it from the datastore)
354 *
355 * @return
356 * - #RLM_MODULE_OK on success.
357 * - #RLM_MODULE_NOTFOUND if no entry existed.
358 * - #RLM_MODULE_FAIL on failure.
359 */
361 rlm_cache_t const *inst, request_t *request,
362 rlm_cache_handle_t **handle, fr_value_box_t const *key)
363{
364 RDEBUG2("Expiring cache entry");
365 for (;;) switch (inst->driver->expire(&inst->config, inst->driver_submodule->data, request, *handle, key)) {
366 case CACHE_RECONNECT:
367 if (cache_reconnect(handle, inst, request) == 0) continue;
369
370 default:
372
373 case CACHE_OK:
375
376 case CACHE_MISS:
378 }
379}
380
381/** Create and insert a cache entry
382 *
383 * @return
384 * - #RLM_MODULE_OK on success.
385 * - #RLM_MODULE_UPDATED if we merged the cache entry.
386 * - #RLM_MODULE_FAIL on failure.
387 */
389 rlm_cache_t const *inst, request_t *request, rlm_cache_handle_t **handle,
390 fr_value_box_t const *key, map_list_t const *maps, fr_time_delta_t ttl)
391{
392 map_t const *map = NULL;
393 map_t *c_map;
394
395 fr_pair_t *vp;
396 bool merge = false;
398
399 TALLOC_CTX *pool;
400
401 if ((inst->config.max_entries > 0) && inst->driver->count &&
402 (inst->driver->count(&inst->config, inst->driver_submodule->data, request, handle) > inst->config.max_entries)) {
403 RWDEBUG("Cache is full: %d entries", inst->config.max_entries);
405 }
406
407 c = cache_alloc(inst, request);
408 if (!c) {
410 }
411 map_list_init(&c->maps);
412 if (unlikely(fr_value_box_copy(c, &c->key, key) < 0)) {
413 RERROR("Failed copying key");
414 talloc_free(c);
416 }
417
418 /*
419 * All in NSEC resolution
420 */
421 c->created = c->expires = fr_time_to_unix_time(request->packet->timestamp);
422 c->expires = fr_unix_time_add(c->expires, ttl);
423
424 RDEBUG2("Creating new cache entry");
425
426 /*
427 * We don't have any maps to apply to the cache entry
428 * so don't try to expand them.
429 */
430 if (!maps) goto skip_maps;
431
432 /*
433 * Alloc a pool so we don't have excessive allocs when
434 * gathering fr_pair_ts to cache.
435 */
436 pool = talloc_pool(NULL, 2048);
437 while ((map = map_list_next(maps, map))) {
438 fr_pair_list_t to_cache;
439
440 fr_pair_list_init(&to_cache);
441 fr_assert(map->lhs && map->rhs);
442
443 /*
444 * Calling map_to_vp gives us exactly the same result,
445 * as if this were an update section.
446 */
447 if (map_to_vp(pool, &to_cache, request, map, NULL) < 0) {
448 RDEBUG2("Skipping %s", map->rhs->name);
449 continue;
450 }
451
452 for (vp = fr_pair_list_head(&to_cache);
453 vp;
454 vp = fr_pair_list_next(&to_cache, vp)) {
455 /*
456 * Prevent people from accidentally caching
457 * cache control attributes.
458 */
459 if (tmpl_is_list(map->rhs)) switch (vp->da->attr) {
460 case FR_CACHE_TTL:
461 case FR_CACHE_STATUS_ONLY:
462 case FR_CACHE_MERGE_NEW:
463 case FR_CACHE_ENTRY_HITS:
464 RDEBUG2("Skipping %s", vp->da->name);
465 continue;
466
467 default:
468 break;
469 }
470 RINDENT();
471 if (RDEBUG_ENABLED2) map_debug_log(request, map, vp);
472 REXDENT();
473
474 MEM(c_map = talloc_zero(c, map_t));
475 c_map->op = map->op;
476 map_list_init(&c_map->child);
477
478 /*
479 * Now we turn the fr_pair_ts into maps.
480 */
481 switch (map->lhs->type) {
482 /*
483 * Attributes are easy, reuse the LHS, and create a new
484 * RHS with the fr_value_box_t from the fr_pair_t.
485 */
486 case TMPL_TYPE_ATTR:
487 {
488 fr_token_t quote;
489 /*
490 * If the LHS is structural, we need a new template
491 * which is the combination of the existing LHS and
492 * the attribute.
493 */
495 tmpl_attr_afrom_list(c_map, &c_map->lhs, map->lhs, vp->da);
496 } else {
497 c_map->lhs = map->lhs; /* lhs shouldn't be touched, so this is ok */
498 }
499
500 if (vp->vp_type == FR_TYPE_STRING) {
501 quote = is_printable(vp->vp_strvalue, vp->vp_length) ?
503 } else {
504 quote = T_BARE_WORD;
505 }
506
507 MEM(c_map->rhs = tmpl_alloc(c_map,
508 TMPL_TYPE_DATA, quote, map->rhs->name, map->rhs->len));
509 if (fr_value_box_copy(c_map->rhs, tmpl_value(c_map->rhs), &vp->data) < 0) {
510 REDEBUG("Failed copying attribute value");
511 talloc_free(pool);
512 talloc_free(c);
514 }
515 }
516 break;
517
518 default:
519 fr_assert(0);
520 }
521 MAP_VERIFY(c_map);
522 map_list_insert_tail(&c->maps, c_map);
523 }
524 talloc_free_children(pool); /* reset pool state */
525 }
526 talloc_free(pool);
527
528skip_maps:
529
530 /*
531 * Check to see if we need to merge the entry into the request
532 */
533 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cache_merge_new);
534 if (vp && vp->vp_bool) merge = true;
535
536 if (merge) cache_merge(inst, request, c);
537
538 for (;;) {
539 cache_status_t ret;
540
541 ret = inst->driver->insert(&inst->config, inst->driver_submodule->data, request, *handle, c);
542 switch (ret) {
543 case CACHE_RECONNECT:
544 if (cache_reconnect(handle, inst, request) == 0) continue;
546
547 case CACHE_OK:
548 RDEBUG2("Committed entry, TTL %pV seconds", fr_box_time_delta(ttl));
549 cache_free(inst, &c);
551
552 default:
553 talloc_free(c); /* Failed insertion - use talloc_free not the driver free */
555 }
556 }
557}
558
559/** Update the TTL of an entry
560 *
561 * @return
562 * - #RLM_MODULE_OK on success.
563 * - #RLM_MODULE_FAIL on failure.
564 */
566 rlm_cache_t const *inst, request_t *request,
568{
569 /*
570 * Call the driver's insert method to overwrite the old entry
571 */
572 if (!inst->driver->set_ttl) for (;;) {
573 cache_status_t ret;
574
575 ret = inst->driver->insert(&inst->config, inst->driver_submodule->data, request, *handle, c);
576 switch (ret) {
577 case CACHE_RECONNECT:
578 if (cache_reconnect(handle, inst, request) == 0) continue;
580
581 case CACHE_OK:
582 RDEBUG2("Updated entry TTL");
584
585 default:
587 }
588 }
589
590 /*
591 * Or call the set ttl method if the driver can do this more
592 * efficiently.
593 */
594 for (;;) {
595 cache_status_t ret;
596
597 ret = inst->driver->set_ttl(&inst->config, inst->driver_submodule->data, request, *handle, c);
598 switch (ret) {
599 case CACHE_RECONNECT:
600 if (cache_reconnect(handle, inst, request) == 0) continue;
602
603 case CACHE_OK:
604 RDEBUG2("Updated entry TTL");
606
607 default:
609 }
610 }
611}
612
613/** Macro to reduce boilerplate in all the module methods / xlat functions
614 * If multiple values are in the input list, concat them as a string
615 * Then check that a variable length key is longer than zero bytes
616 */
617#define FIXUP_KEY(_fail, _invalid) \
618if ((fr_value_box_list_num_elements(&env->key) > 1) && \
619 (fr_value_box_list_concat_in_place(key, key, &env->key, FR_TYPE_STRING, \
620 FR_VALUE_BOX_LIST_FREE, true, SIZE_MAX) < 0)) { \
621 REDEBUG("Failed concatenating values to form the key"); \
622 _fail; \
623} \
624if (fr_type_is_variable_size(key->type) && (key->vb_length == 0)) { \
625 REDEBUG("Zero length key string is invalid"); \
626 _invalid; \
627}
628
629/** Do caching checks
630 *
631 * Since we can update ANY VP list, we do exactly the same thing for all sections
632 * (autz / auth / etc.)
633 *
634 * If you want to cache something different in different sections, configure
635 * another cache module.
636 */
637static unlang_action_t CC_HINT(nonnull) mod_cache_it(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
638{
639 rlm_cache_entry_t *c = NULL;
641 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
642 fr_value_box_t *key = fr_value_box_list_head(&env->key);
643 rlm_cache_handle_t *handle;
644
645 fr_dcursor_t cursor;
646 fr_pair_t *vp;
647
648 bool merge = true, insert = true, expire = false, set_ttl = false;
649 int exists = -1;
650
651 fr_time_delta_t ttl = inst->config.ttl;
652
653 p_result->rcode = RLM_MODULE_NOOP;
654
656
657 /*
658 * If Cache-Status-Only == yes, only return whether we found a
659 * valid cache entry
660 */
661 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cache_status_only);
662 if (vp && vp->vp_bool) {
663 RINDENT();
664 RDEBUG3("status-only: yes");
665 REXDENT();
666
667 if (cache_acquire(&handle, inst, request) < 0) {
669 }
670
671 cache_find(p_result, &c, inst, request, &handle, key);
672 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
673 fr_assert(!inst->driver->acquire || handle);
674
675 p_result->rcode = c ? RLM_MODULE_OK:
677 goto finish;
678 }
679
680 /*
681 * Figure out what operation we're doing
682 */
683 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cache_allow_merge);
684 if (vp) merge = vp->vp_bool;
685
686 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cache_allow_insert);
687 if (vp) insert = vp->vp_bool;
688
689 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cache_ttl);
690 if (vp) {
691 if (vp->vp_int32 == 0) {
692 expire = true;
693 } else if (vp->vp_int32 < 0) {
694 expire = true;
695 ttl = fr_time_delta_from_sec(-(vp->vp_int32));
696 /* Updating the TTL */
697 } else {
698 set_ttl = true;
699 ttl = fr_time_delta_from_sec(vp->vp_int32);
700 }
701 }
702
703 RINDENT();
704 RDEBUG3("merge : %s", merge ? "yes" : "no");
705 RDEBUG3("insert : %s", insert ? "yes" : "no");
706 RDEBUG3("expire : %s", expire ? "yes" : "no");
707 RDEBUG3("ttl : %pV", fr_box_time_delta(ttl));
708 REXDENT();
709 if (cache_acquire(&handle, inst, request) < 0) {
711 }
712
713 /*
714 * Retrieve the cache entry and merge it with the current request
715 * recording whether the entry existed.
716 */
717 if (merge) {
718 cache_find(p_result, &c, inst, request, &handle, key);
719 switch (p_result->rcode) {
720 case RLM_MODULE_FAIL:
721 goto finish;
722
723 case RLM_MODULE_OK:
724 p_result->rcode = cache_merge(inst, request, c);
725 exists = 1;
726 break;
727
729 p_result->rcode = RLM_MODULE_NOTFOUND;
730 exists = 0;
731 break;
732
733 default:
734 fr_assert(0);
735 }
736 fr_assert(!inst->driver->acquire || handle);
737 }
738
739 /*
740 * Expire the entry if told to, and we either don't know whether
741 * it exists, or we know it does.
742 *
743 * We only expire if we're not inserting, as driver insert methods
744 * should perform upserts.
745 */
746 if (expire && ((exists == -1) || (exists == 1))) {
747 if (!insert) {
748 unlang_result_t tmp;
749
750 fr_assert(!set_ttl);
751 cache_expire(&tmp, inst, request, &handle, key);
752 switch (tmp.rcode) {
753 case RLM_MODULE_FAIL:
754 p_result->rcode = RLM_MODULE_FAIL;
755 goto finish;
756
757 case RLM_MODULE_OK:
758 if (p_result->rcode == RLM_MODULE_NOOP) p_result->rcode = RLM_MODULE_OK;
759 break;
760
762 if (p_result->rcode == RLM_MODULE_NOOP) p_result->rcode = RLM_MODULE_NOTFOUND;
763 break;
764
765 default:
766 fr_assert(0);
767 break;
768 }
769 /* If it previously existed, it doesn't now */
770 }
771 /* Otherwise use insert to overwrite */
772 exists = 0;
773 }
774
775 /*
776 * If we still don't know whether it exists or not
777 * and we need to do an insert or set_ttl operation
778 * determine that now.
779 */
780 if ((exists < 0) && (insert || set_ttl)) {
781 unlang_result_t tmp;
782
783 cache_find(&tmp, &c, inst, request, &handle, key);
784 switch (tmp.rcode) {
785 case RLM_MODULE_FAIL:
786 p_result->rcode = RLM_MODULE_FAIL;
787 goto finish;
788
789 case RLM_MODULE_OK:
790 exists = 1;
791 if (p_result->rcode != RLM_MODULE_UPDATED) p_result->rcode = RLM_MODULE_OK;
792 break;
793
795 exists = 0;
796 break;
797
798 default:
799 fr_assert(0);
800 }
801 fr_assert(!inst->driver->acquire || handle);
802 }
803
804 /*
805 * We can only alter the TTL on an entry if it exists.
806 */
807 if (set_ttl && (exists == 1)) {
808 unlang_result_t tmp;
809
810 fr_assert(c);
811
812 c->expires = fr_unix_time_add(fr_time_to_unix_time(request->packet->timestamp), ttl);
813
814 cache_set_ttl(&tmp, inst, request, &handle, c);
815 switch (tmp.rcode) {
816 case RLM_MODULE_FAIL:
817 p_result->rcode = RLM_MODULE_FAIL;
818 goto finish;
819
821 case RLM_MODULE_OK:
822 if (p_result->rcode != RLM_MODULE_UPDATED) p_result->rcode = RLM_MODULE_OK;
823 goto finish;
824
825 default:
826 fr_assert(0);
827 }
828 }
829
830 /*
831 * Inserts are upserts, so we don't care about the
832 * entry state, just that we're not meant to be
833 * setting the TTL, which precludes performing an
834 * insert.
835 */
836 if (insert && (exists == 0)) {
837 unlang_result_t tmp;
838
839 cache_insert(&tmp, inst, request, &handle, key, env->maps, ttl);
840 switch (tmp.rcode) {
841 case RLM_MODULE_FAIL:
842 p_result->rcode = RLM_MODULE_FAIL;
843 goto finish;
844
845 case RLM_MODULE_OK:
846 if (p_result->rcode != RLM_MODULE_UPDATED) p_result->rcode = RLM_MODULE_OK;
847 break;
848
850 p_result->rcode = RLM_MODULE_UPDATED;
851 break;
852
853 default:
854 fr_assert(0);
855 }
856 fr_assert(!inst->driver->acquire || handle);
857 goto finish;
858 }
859
860
861finish:
862 cache_free(inst, &c);
863 cache_release(inst, request, &handle);
864
865 /*
866 * Clear control attributes
867 */
868 for (vp = fr_pair_dcursor_init(&cursor, &request->control_pairs);
869 vp;
870 vp = fr_dcursor_next(&cursor)) {
871 again:
872 if (!fr_dict_attr_is_top_level(vp->da)) continue;
873
874 switch (vp->da->attr) {
875 case FR_CACHE_TTL:
876 case FR_CACHE_STATUS_ONLY:
877 case FR_CACHE_ALLOW_MERGE:
878 case FR_CACHE_ALLOW_INSERT:
879 case FR_CACHE_MERGE_NEW:
880 RDEBUG2("Removing control.%s", vp->da->name);
881 vp = fr_dcursor_remove(&cursor);
883 vp = fr_dcursor_current(&cursor);
884 if (!vp) break;
885 goto again;
886 }
887 }
888
890}
891
893 { .required = true, .single = true, .type = FR_TYPE_STRING },
895};
896
897/** Allow single attribute values to be retrieved from the cache
898 *
899 * @ingroup xlat_functions
900 */
901static CC_HINT(nonnull)
903 xlat_ctx_t const *xctx,
904 request_t *request, fr_value_box_list_t *in)
905{
906 rlm_cache_entry_t *c = NULL;
907 rlm_cache_t *inst = talloc_get_type_abort(xctx->mctx->mi->data, rlm_cache_t);
908 cache_call_env_t *env = talloc_get_type_abort(xctx->env_data, cache_call_env_t);
909 fr_value_box_t *key = fr_value_box_list_head(&env->key);
910 rlm_cache_handle_t *handle = NULL;
911
912 ssize_t slen;
913
914 fr_value_box_t *attr = fr_value_box_list_head(in);
915 fr_value_box_t *vb;
916
917 tmpl_t *target = NULL;
918 map_t *map = NULL;
919 unlang_result_t result = { .rcode = RLM_MODULE_NOOP };
920
922
923 slen = tmpl_afrom_attr_substr(ctx, NULL, &target,
924 &FR_SBUFF_IN(attr->vb_strvalue, attr->vb_length),
925 NULL,
926 &(tmpl_rules_t){
927 .attr = {
928 .dict_def = request->local_dict,
929 .list_def = request_attr_request,
930 }
931 });
932 if (slen <= 0) {
933 RPEDEBUG("Invalid key");
934 return XLAT_ACTION_FAIL;
935 }
936
937 if (cache_acquire(&handle, inst, request) < 0) {
938 talloc_free(target);
939 return XLAT_ACTION_FAIL;
940 }
941
942 cache_find(&result, &c, inst, request, &handle, key);
943 switch (result.rcode) {
944 case RLM_MODULE_OK: /* found */
945 break;
946
947 default:
948 talloc_free(target);
949 cache_release(inst, request, &handle);
950 return XLAT_ACTION_FAIL;
951 }
952
953 while ((map = map_list_next(&c->maps, map))) {
954 if ((tmpl_attr_tail_da(map->lhs) != tmpl_attr_tail_da(target)) ||
955 (tmpl_list(map->lhs) != tmpl_list(target))) continue;
956
957 MEM(vb = fr_value_box_alloc_null(ctx));
958 if (unlikely(fr_value_box_copy(vb, vb, tmpl_value(map->rhs)) < 0)) {
959 RPEDEBUG("Failed copying value from cache entry");
960 talloc_free(vb);
961 return XLAT_ACTION_FAIL;
962 }
964 break;
965 }
966
967 talloc_free(target);
968
969 cache_free(inst, &c);
970 cache_release(inst, request, &handle);
971
972 /*
973 * Check if we found a matching map
974 */
975 if (!map) return XLAT_ACTION_FAIL;
976
977 return XLAT_ACTION_DONE;
978}
979
981 xlat_ctx_t const *xctx,
982 request_t *request, UNUSED fr_value_box_list_t *in)
983{
984 rlm_cache_entry_t *c = NULL;
985 rlm_cache_t *inst = talloc_get_type_abort(xctx->mctx->mi->data, rlm_cache_t);
986 cache_call_env_t *env = talloc_get_type_abort(xctx->env_data, cache_call_env_t);
987 fr_value_box_t *key = fr_value_box_list_head(&env->key);
988 rlm_cache_handle_t *handle = NULL;
989
990 unlang_result_t result = { .rcode = RLM_MODULE_NOOP };
991
992 fr_value_box_t *vb;
993
995
996 if (cache_acquire(&handle, inst, request) < 0) {
997 return XLAT_ACTION_FAIL;
998 }
999
1000 cache_find(&result, &c, inst, request, &handle, key);
1001 switch (result.rcode) {
1002 case RLM_MODULE_OK: /* found */
1003 break;
1004
1005 default:
1006 cache_release(inst, request, &handle);
1007 return XLAT_ACTION_DONE;
1008 }
1009
1010 MEM(vb = fr_value_box_alloc(ctx, FR_TYPE_TIME_DELTA, NULL));
1011 vb->vb_time_delta = fr_unix_time_sub(c->expires, fr_time_to_unix_time(request->packet->timestamp));
1013
1014 cache_free(inst, &c);
1015 cache_release(inst, request, &handle);
1016
1017 return XLAT_ACTION_DONE;
1018}
1019
1020/** Release the allocated resources and cleanup the avps
1021 */
1022static void cache_unref(request_t *request, rlm_cache_t const *inst, rlm_cache_entry_t *entry,
1023 rlm_cache_handle_t *handle)
1024{
1025 fr_dcursor_t cursor;
1026 fr_pair_t *vp;
1027
1028 /*
1029 * Release the driver calls
1030 */
1031 cache_free(inst, &entry);
1032 cache_release(inst, request, &handle);
1033
1034 /*
1035 * Clear control attributes
1036 */
1037 for (vp = fr_pair_dcursor_init(&cursor, &request->control_pairs);
1038 vp;
1039 vp = fr_dcursor_next(&cursor)) {
1040 again:
1041 if (!fr_dict_attr_is_top_level(vp->da)) continue;
1042
1043 switch (vp->da->attr) {
1044 case FR_CACHE_TTL:
1045 case FR_CACHE_STATUS_ONLY:
1046 case FR_CACHE_ALLOW_MERGE:
1047 case FR_CACHE_ALLOW_INSERT:
1048 case FR_CACHE_MERGE_NEW:
1049 RDEBUG2("Removing control:%s", vp->da->name);
1050 vp = fr_dcursor_remove(&cursor);
1051 TALLOC_FREE(vp);
1052 vp = fr_dcursor_current(&cursor);
1053 if (!vp) break;
1054 goto again;
1055 }
1056 }
1057}
1058
1059/** Get the status by ${key} (without load)
1060 *
1061 * @return
1062 * - #RLM_MODULE_OK on success.
1063 * - #RLM_MODULE_NOTFOUND on cache miss.
1064 * - #RLM_MODULE_FAIL on failure.
1065 */
1066static unlang_action_t CC_HINT(nonnull) mod_method_status(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
1067{
1068 rlm_cache_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1069 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
1070 fr_value_box_t *key = fr_value_box_list_head(&env->key);
1071 rlm_cache_entry_t *entry = NULL;
1072 rlm_cache_handle_t *handle = NULL;
1073
1074 p_result->rcode = RLM_MODULE_NOOP;
1075
1077
1078 /* Good to go? */
1079 if (cache_acquire(&handle, inst, request) < 0) {
1081 }
1082
1083 fr_assert(!inst->driver->acquire || handle);
1084
1085 cache_find(p_result, &entry, inst, request, &handle, key);
1086 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1087
1088 p_result->rcode = (entry) ? RLM_MODULE_OK : RLM_MODULE_NOTFOUND;
1089
1090finish:
1091 cache_unref(request, inst, entry, handle);
1092
1094}
1095
1096/** Load the avps by ${key}.
1097 *
1098 * @return
1099 * - #RLM_MODULE_UPDATED on success.
1100 * - #RLM_MODULE_NOTFOUND on cache miss.
1101 * - #RLM_MODULE_FAIL on failure.
1102 */
1103static unlang_action_t CC_HINT(nonnull) mod_method_load(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
1104{
1105 rlm_cache_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1106 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
1107 rlm_cache_entry_t *entry = NULL;
1108 rlm_cache_handle_t *handle = NULL;
1109 fr_value_box_t *key = fr_value_box_list_head(&env->key);
1110
1111 p_result->rcode = RLM_MODULE_NOOP;
1112
1114
1115 /* Good to go? */
1116 if (cache_acquire(&handle, inst, request) < 0) {
1118 }
1119
1120 cache_find(p_result, &entry, inst, request, &handle, key);
1121 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1122
1123 if (!entry) {
1124 RDEBUG2("Entry not found to load");
1125 p_result->rcode = RLM_MODULE_NOTFOUND;
1126 goto finish;
1127 }
1128
1129 p_result->rcode = cache_merge(inst, request, entry);
1130
1131finish:
1132 cache_unref(request, inst, entry, handle);
1133
1135}
1136
1137/** Create, or update a cache entry
1138 *
1139 * @return
1140 * - #RLM_MODULE_OK on success.
1141 * - #RLM_MODULE_UPDATED if we merged the cache entry.
1142 * - #RLM_MODULE_FAIL on failure.
1143 */
1144static unlang_action_t CC_HINT(nonnull) mod_method_update(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
1145{
1146 rlm_cache_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1147 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
1148 fr_value_box_t *key = fr_value_box_list_head(&env->key);
1149 fr_time_delta_t ttl;
1150 bool expire = false;
1151 rlm_cache_entry_t *entry = NULL;
1152 rlm_cache_handle_t *handle = NULL;
1153 fr_pair_t *vp;
1154
1155 p_result->rcode = RLM_MODULE_NOOP;
1156
1158
1159 /* Good to go? */
1160 if (cache_acquire(&handle, inst, request) < 0) {
1162 }
1163
1164 /* Process the TTL */
1165 ttl = inst->config.ttl; /* Set the default value from cache { ttl=... } */
1166 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cache_ttl);
1167 if (vp) {
1168 if (vp->vp_int32 == 0) {
1169 expire = true;
1170 } else if (vp->vp_int32 < 0) {
1171 ttl = fr_time_delta_from_sec(-(vp->vp_int32));
1172 /* Updating the TTL */
1173 } else {
1174 ttl = fr_time_delta_from_sec(vp->vp_int32);
1175 }
1176
1177 DEBUG3("Overwriting the default TTL %pV -> %d", fr_box_time_delta(ttl), vp->vp_int32);
1178 }
1179
1180 /*
1181 * We can only alter the TTL on an entry if it exists.
1182 */
1183 cache_find(p_result, &entry, inst, request, &handle, key);
1184 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1185
1186 if (p_result->rcode == RLM_MODULE_OK) {
1187 fr_assert(entry != NULL);
1188
1189 DEBUG3("Updating the TTL -> %pV", fr_box_time_delta(ttl));
1190
1191 entry->expires = fr_unix_time_add(fr_time_to_unix_time(request->packet->timestamp), ttl);
1192
1193 cache_set_ttl(p_result, inst, request, &handle, entry);
1194 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1195 }
1196
1197 /*
1198 * Expire the entry if told to, and we either don't know whether
1199 * it exists, or we know it does.
1200 *
1201 * We only expire if we're not inserting, as driver insert methods
1202 * should perform upserts.
1203 */
1204 if (expire) {
1205 DEBUG3("Expiring cache entry");
1206
1207 cache_expire(p_result, inst, request, &handle, key);
1208 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1209 }
1210
1211 /*
1212 * Inserts are upserts, so we don't care about the
1213 * entry state.
1214 */
1215 cache_insert(p_result, inst, request, &handle, key, env->maps, ttl);
1216 if (p_result->rcode == RLM_MODULE_OK) p_result->rcode = RLM_MODULE_UPDATED;
1217
1218finish:
1219 cache_unref(request, inst, entry, handle);
1220
1222}
1223
1224/** Create, or update a cache entry
1225 *
1226 * @return
1227 * - #RLM_MODULE_NOOP if an entry already existed.
1228 * - #RLM_MODULE_UPDATED if we inserted a cache entry.
1229 * - #RLM_MODULE_FAIL on failure.
1230 */
1231static unlang_action_t CC_HINT(nonnull) mod_method_store(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
1232{
1233 rlm_cache_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1234 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
1235 fr_value_box_t *key = fr_value_box_list_head(&env->key);
1236 fr_time_delta_t ttl;
1237 rlm_cache_entry_t *entry = NULL;
1238 rlm_cache_handle_t *handle = NULL;
1239 fr_pair_t *vp;
1240
1241 p_result->rcode = RLM_MODULE_NOOP;
1242
1244
1245 if (cache_acquire(&handle, inst, request) < 0) {
1247 }
1248
1249 /* Process the TTL */
1250 ttl = inst->config.ttl; /* Set the default value from cache { ttl=... } */
1251 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cache_ttl);
1252 if (vp && (vp->vp_int32 > 0)) {
1253 ttl = fr_time_delta_from_sec(vp->vp_int32);
1254
1255 DEBUG3("Overriding default TTL %pV -> %d", fr_box_time_delta(ttl), vp->vp_int32);
1256 }
1257
1258 /*
1259 * We can only alter the TTL on an entry if it exists.
1260 */
1261 cache_find(p_result, &entry, inst, request, &handle, key);
1262 switch (p_result->rcode) {
1263 default:
1264 case RLM_MODULE_OK:
1265 p_result->rcode = RLM_MODULE_NOOP;
1266 goto finish;
1267
1268 case RLM_MODULE_FAIL:
1269 goto finish;
1270
1272 break;
1273 }
1274
1275 /*
1276 * Inserts are upserts, so we don't care about the
1277 * entry state, just that we're not meant to be
1278 * setting the TTL, which precludes performing an
1279 * insert.
1280 */
1281 cache_insert(p_result, inst, request, &handle, key, env->maps, ttl);
1282
1283finish:
1284 cache_unref(request, inst, entry, handle);
1285 if (p_result->rcode == RLM_MODULE_OK) p_result->rcode = RLM_MODULE_UPDATED;
1286
1288}
1289
1290/** Delete the entries by ${key}
1291 *
1292 * @return
1293 * - #RLM_MODULE_OK on success.
1294 * - #RLM_MODULE_NOTFOUND on cache miss.
1295 * - #RLM_MODULE_FAIL on failure.
1296 */
1297static unlang_action_t CC_HINT(nonnull) mod_method_clear(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
1298{
1299 rlm_cache_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1300 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
1301 fr_value_box_t *key = fr_value_box_list_head(&env->key);
1302 rlm_cache_entry_t *entry = NULL;
1303 rlm_cache_handle_t *handle = NULL;
1304
1305 p_result->rcode = RLM_MODULE_NOOP;
1306
1307 DEBUG3("Calling %s.clear", mctx->mi->name);
1308
1310
1311 /* Good to go? */
1312 if (cache_acquire(&handle, inst, request) < 0) {
1314 }
1315
1316 cache_find(p_result, &entry, inst, request, &handle, key);
1317 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1318
1319 if (!entry) {
1320 REDEBUG2("Entry not found to delete");
1321 p_result->rcode = RLM_MODULE_NOTFOUND;
1322 goto finish;
1323 }
1324
1325 cache_expire(p_result, inst, request, &handle, key);
1326
1327finish:
1328 cache_unref(request, inst, entry, handle);
1329
1331}
1332
1333/** Change the TTL on an existing entry.
1334 *
1335 * @return
1336 * - #RLM_MODULE_UPDATED on success.
1337 * - #RLM_MODULE_NOTFOUND on cache miss.
1338 * - #RLM_MODULE_FAIL on failure.
1339 */
1340static unlang_action_t CC_HINT(nonnull) mod_method_ttl(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
1341{
1342 rlm_cache_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1343 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
1344 fr_value_box_t *key = fr_value_box_list_head(&env->key);
1345 fr_time_delta_t ttl;
1346 rlm_cache_entry_t *entry = NULL;
1347 rlm_cache_handle_t *handle = NULL;
1348 fr_pair_t *vp;
1349
1350 p_result->rcode = RLM_MODULE_NOOP;
1351
1352 DEBUG3("Calling %s.ttl", mctx->mi->name);
1353
1355
1356 /* Good to go? */
1357 if (cache_acquire(&handle, inst, request) < 0) {
1359 }
1360
1361 /* Process the TTL */
1362 ttl = inst->config.ttl; /* Set the default value from cache { ttl=... } */
1363 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cache_ttl);
1364 if (vp) {
1365 if (vp->vp_int32 < 0) {
1366 ttl = fr_time_delta_from_sec(-(vp->vp_int32));
1367 /* Updating the TTL */
1368 } else {
1369 ttl = fr_time_delta_from_sec(vp->vp_int32);
1370 }
1371
1372 DEBUG3("Overwriting the default TTL %pV -> %d", fr_box_time_delta(inst->config.ttl), vp->vp_int32);
1373 }
1374
1375 /*
1376 * We can only alter the TTL on an entry if it exists.
1377 */
1378 cache_find(p_result, &entry, inst, request, &handle, key);
1379 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1380
1381 if (p_result->rcode == RLM_MODULE_OK) {
1382 fr_assert(entry != NULL);
1383
1384 DEBUG3("Updating the TTL -> %pV", fr_box_time_delta(ttl));
1385
1386 entry->expires = fr_unix_time_add(fr_time_to_unix_time(request->packet->timestamp), ttl);
1387
1388 cache_set_ttl(p_result, inst, request, &handle, entry);
1389 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1390
1391 p_result->rcode = RLM_MODULE_UPDATED;
1392 }
1393
1394finish:
1395 cache_unref(request, inst, entry, handle);
1396
1398}
1399
1400/** Free any memory allocated under the instance
1401 *
1402 */
1403static int mod_detach(module_detach_ctx_t const *mctx)
1404{
1405 rlm_cache_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1406
1407 /*
1408 * We need to explicitly free all children, so if the driver
1409 * parented any memory off the instance, their destructors
1410 * run before we unload the bytecode for them.
1411 *
1412 * If we don't do this, we get a SEGV deep inside the talloc code
1413 * when it tries to call a destructor that no longer exists.
1414 */
1415 talloc_free_children(inst);
1416
1417 return 0;
1418}
1419
1420/** Verify that a map in the cache section makes sense
1421 *
1422 */
1423static int cache_verify(map_t *map, void *uctx)
1424{
1425 if (unlang_fixup_update(map, uctx) < 0) return -1;
1426
1427 if (!tmpl_is_attr(map->lhs)) {
1428 cf_log_err(map->ci, "Destination must be an attribute ref or a list");
1429 return -1;
1430 }
1431
1432 if (!fr_assignment_op[map->op]) {
1433 cf_log_err(map->ci, "Invalid operator '%s'", fr_tokens[map->op]);
1434 return -1;
1435 }
1436
1437 return 0;
1438}
1439
1440static int cache_update_section_parse(TALLOC_CTX *ctx, call_env_parsed_head_t *out, tmpl_rules_t const *t_rules,
1441 CONF_ITEM *ci,
1442 UNUSED call_env_ctx_t const *cec, UNUSED call_env_parser_t const *rule)
1443{
1444 CONF_SECTION *update = cf_item_to_section(ci);
1445 call_env_parsed_t *parsed;
1446 map_list_t *maps;
1447
1448 MEM(parsed = call_env_parsed_add(ctx, out,
1450
1451 MEM(maps = talloc(parsed, map_list_t));
1452 map_list_init(maps);
1453
1454 if (map_afrom_cs(maps, maps, update,
1455 t_rules, t_rules, cache_verify, NULL, MAX_ATTRMAP) < 0) {
1456 error:
1457 call_env_parsed_free(out, parsed);
1458 return -1;
1459 }
1460
1461 if (map_list_empty(maps)) {
1462 cf_log_err(update, "Update section must not be empty");
1463 goto error;
1464 }
1465
1466 call_env_parsed_set_data(parsed, maps);
1467
1468 return 0;
1469}
1470
1471/** Create a new rlm_cache_instance
1472 *
1473 */
1474static int mod_instantiate(module_inst_ctx_t const *mctx)
1475{
1476 rlm_cache_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1477 CONF_SECTION *conf = mctx->mi->conf;
1478
1479 /*
1480 * Non optional fields and callbacks
1481 */
1482 fr_assert(inst->driver->common.name);
1483 fr_assert(inst->driver->find);
1484 fr_assert(inst->driver->insert);
1485 fr_assert(inst->driver->expire);
1486
1487 if (!fr_time_delta_ispos(inst->config.ttl)) {
1488 cf_log_err(conf, "Must set 'ttl' to non-zero");
1489 return -1;
1490 }
1491
1492 if (inst->config.epoch != 0) {
1493 cf_log_err(conf, "Must not set 'epoch' in the configuration files");
1494 return -1;
1495 }
1496
1497 return 0;
1498}
1499
1500/** Register module xlats
1501 *
1502 */
1503static int mod_bootstrap(module_inst_ctx_t const *mctx)
1504{
1505 xlat_t *xlat;
1506
1507 /*
1508 * Register the cache xlat function
1509 */
1510 xlat = module_rlm_xlat_register(mctx->mi->boot, mctx, NULL, cache_xlat, FR_TYPE_VOID);
1513
1514 xlat = module_rlm_xlat_register(mctx->mi->boot, mctx, "ttl.get", cache_ttl_get_xlat, FR_TYPE_VOID);
1516
1517 return 0;
1518}
1519
1520/*
1521 * The module name should be the only globally exported symbol.
1522 * That is, everything else should be 'static'.
1523 *
1524 * If the module needs to temporarily modify it's instantiation
1525 * data, the type should be changed to MODULE_TYPE_THREAD_UNSAFE.
1526 * The server will then take care of ensuring that the module
1527 * is single-threaded.
1528 */
1530 .common = {
1531 .magic = MODULE_MAGIC_INIT,
1532 .name = "cache",
1533 .inst_size = sizeof(rlm_cache_t),
1535 .bootstrap = mod_bootstrap,
1536 .instantiate = mod_instantiate,
1537 .detach = mod_detach
1538 },
1539 .method_group = {
1540 .bindings = (module_method_binding_t[]){
1541 { .section = SECTION_NAME("clear", CF_IDENT_ANY), .method = mod_method_clear, .method_env = &cache_method_env },
1542 { .section = SECTION_NAME("load", CF_IDENT_ANY), .method = mod_method_load, .method_env = &cache_method_env },
1543 { .section = SECTION_NAME("status", CF_IDENT_ANY), .method = mod_method_status, .method_env = &cache_method_env },
1544 { .section = SECTION_NAME("store", CF_IDENT_ANY), .method = mod_method_store, .method_env = &cache_method_env },
1545 { .section = SECTION_NAME("ttl", CF_IDENT_ANY), .method = mod_method_ttl, .method_env = &cache_method_env },
1546 { .section = SECTION_NAME("update", CF_IDENT_ANY), .method = mod_method_update, .method_env = &cache_method_env },
1547 { .section = SECTION_NAME(CF_IDENT_ANY, CF_IDENT_ANY), .method = mod_cache_it, .method_env = &cache_method_env },
1549 }
1550 }
1551};
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:578
#define RCSID(id)
Definition build.h:487
#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:660
cf_parse_t func
Override default parsing behaviour for the specified type with a custom parsing function.
Definition cf_parse.h:614
#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:283
#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:597
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:286
#define cf_log_perr(_cf, _fmt,...)
Definition cf_util.h:293
#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:294
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition dict.h:307
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:811
#define DICT_AUTOLOAD_TERMINATOR
Definition dict.h:313
static fr_slen_t in
Definition dict.h:884
Specifies an attribute which must be present for the module to function.
Definition dict.h:293
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition dict.h:306
#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:902
talloc_free(hp)
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:1596
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:1134
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:1876
ssize_t map_print(fr_sbuff_t *out, map_t const *map)
Print a map to a string.
Definition map.c:2393
void map_debug_log(request_t *request, map_t const *map, fr_pair_t const *vp)
Definition map.c:2448
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:350
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:247
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:948
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:703
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:168
fr_value_box_list_t key
To lookup the cache entry with.
Definition rlm_cache.c:64
static int mod_detach(module_detach_ctx_t const *mctx)
Free any memory allocated under the instance.
Definition rlm_cache.c:1403
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:121
fr_type_t ktype
Key type.
Definition rlm_cache.c:69
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:1231
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:1066
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:1103
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:181
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:1423
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:208
#define FIXUP_KEY(_fail, _invalid)
Macro to reduce boilerplate in all the module methods / xlat functions If multiple values are in the ...
Definition rlm_cache.c:617
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:565
static int mod_bootstrap(module_inst_ctx_t const *mctx)
Register module xlats.
Definition rlm_cache.c:1503
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:229
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:1340
static xlat_arg_parser_t const cache_xlat_args[]
Definition rlm_cache.c:892
module_rlm_t rlm_cache
Definition rlm_cache.c:1529
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:193
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:1297
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:388
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:1144
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:980
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:244
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:1022
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:360
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:1474
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:637
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:290
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:1220
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:336
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:244
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
unsigned int 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:605
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:859
static char const * fr_type_to_str(fr_type_t type)
Return a static string containing the type name.
Definition types.h:455
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:4401
#define fr_value_box_alloc(_ctx, _type, _enumv)
Allocate a value box of a specific type.
Definition value.h:644
#define fr_box_time_delta(_val)
Definition value.h:366
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:655
#define fr_box_time(_val)
Definition value.h:349
static size_t char ** out
Definition value.h:1024
#define fr_box_date(_val)
Definition value.h:347
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