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: 98535fbbf7c2259956196e01366cad486d050719 $
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: 98535fbbf7c2259956196e01366cad486d050719 $")
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 talloc_free(target);
962 cache_free(inst, &c);
963 cache_release(inst, request, &handle);
964 return XLAT_ACTION_FAIL;
965 }
967 break;
968 }
969
970 talloc_free(target);
971
972 cache_free(inst, &c);
973 cache_release(inst, request, &handle);
974
975 /*
976 * Check if we found a matching map
977 */
978 if (!map) return XLAT_ACTION_FAIL;
979
980 return XLAT_ACTION_DONE;
981}
982
984 xlat_ctx_t const *xctx,
985 request_t *request, UNUSED fr_value_box_list_t *in)
986{
987 rlm_cache_entry_t *c = NULL;
988 rlm_cache_t *inst = talloc_get_type_abort(xctx->mctx->mi->data, rlm_cache_t);
989 cache_call_env_t *env = talloc_get_type_abort(xctx->env_data, cache_call_env_t);
990 fr_value_box_t *key = fr_value_box_list_head(&env->key);
991 rlm_cache_handle_t *handle = NULL;
992
993 unlang_result_t result = { .rcode = RLM_MODULE_NOOP };
994
995 fr_value_box_t *vb;
996
998
999 if (cache_acquire(&handle, inst, request) < 0) {
1000 return XLAT_ACTION_FAIL;
1001 }
1002
1003 cache_find(&result, &c, inst, request, &handle, key);
1004 switch (result.rcode) {
1005 case RLM_MODULE_OK: /* found */
1006 break;
1007
1008 default:
1009 cache_release(inst, request, &handle);
1010 return XLAT_ACTION_DONE;
1011 }
1012
1013 MEM(vb = fr_value_box_alloc(ctx, FR_TYPE_TIME_DELTA, NULL));
1014 vb->vb_time_delta = fr_unix_time_sub(c->expires, fr_time_to_unix_time(request->packet->timestamp));
1016
1017 cache_free(inst, &c);
1018 cache_release(inst, request, &handle);
1019
1020 return XLAT_ACTION_DONE;
1021}
1022
1023/** Release the allocated resources and cleanup the avps
1024 */
1025static void cache_unref(request_t *request, rlm_cache_t const *inst, rlm_cache_entry_t *entry,
1026 rlm_cache_handle_t *handle)
1027{
1028 fr_dcursor_t cursor;
1029 fr_pair_t *vp;
1030
1031 /*
1032 * Release the driver calls
1033 */
1034 cache_free(inst, &entry);
1035 cache_release(inst, request, &handle);
1036
1037 /*
1038 * Clear control attributes
1039 */
1040 for (vp = fr_pair_dcursor_init(&cursor, &request->control_pairs);
1041 vp;
1042 vp = fr_dcursor_next(&cursor)) {
1043 again:
1044 if (!fr_dict_attr_is_top_level(vp->da)) continue;
1045
1046 switch (vp->da->attr) {
1047 case FR_CACHE_TTL:
1048 case FR_CACHE_STATUS_ONLY:
1049 case FR_CACHE_ALLOW_MERGE:
1050 case FR_CACHE_ALLOW_INSERT:
1051 case FR_CACHE_MERGE_NEW:
1052 RDEBUG2("Removing control:%s", vp->da->name);
1053 vp = fr_dcursor_remove(&cursor);
1054 TALLOC_FREE(vp);
1055 vp = fr_dcursor_current(&cursor);
1056 if (!vp) break;
1057 goto again;
1058 }
1059 }
1060}
1061
1062/** Get the status by ${key} (without load)
1063 *
1064 * @return
1065 * - #RLM_MODULE_OK on success.
1066 * - #RLM_MODULE_NOTFOUND on cache miss.
1067 * - #RLM_MODULE_FAIL on failure.
1068 */
1069static unlang_action_t CC_HINT(nonnull) mod_method_status(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
1070{
1071 rlm_cache_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1072 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
1073 fr_value_box_t *key = fr_value_box_list_head(&env->key);
1074 rlm_cache_entry_t *entry = NULL;
1075 rlm_cache_handle_t *handle = NULL;
1076
1077 p_result->rcode = RLM_MODULE_NOOP;
1078
1080
1081 /* Good to go? */
1082 if (cache_acquire(&handle, inst, request) < 0) {
1084 }
1085
1086 fr_assert(!inst->driver->acquire || handle);
1087
1088 cache_find(p_result, &entry, inst, request, &handle, key);
1089 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1090
1091 p_result->rcode = (entry) ? RLM_MODULE_OK : RLM_MODULE_NOTFOUND;
1092
1093finish:
1094 cache_unref(request, inst, entry, handle);
1095
1097}
1098
1099/** Load the avps by ${key}.
1100 *
1101 * @return
1102 * - #RLM_MODULE_UPDATED on success.
1103 * - #RLM_MODULE_NOTFOUND on cache miss.
1104 * - #RLM_MODULE_FAIL on failure.
1105 */
1106static unlang_action_t CC_HINT(nonnull) mod_method_load(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
1107{
1108 rlm_cache_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1109 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
1110 rlm_cache_entry_t *entry = NULL;
1111 rlm_cache_handle_t *handle = NULL;
1112 fr_value_box_t *key = fr_value_box_list_head(&env->key);
1113
1114 p_result->rcode = RLM_MODULE_NOOP;
1115
1117
1118 /* Good to go? */
1119 if (cache_acquire(&handle, inst, request) < 0) {
1121 }
1122
1123 cache_find(p_result, &entry, inst, request, &handle, key);
1124 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1125
1126 if (!entry) {
1127 RDEBUG2("Entry not found to load");
1128 p_result->rcode = RLM_MODULE_NOTFOUND;
1129 goto finish;
1130 }
1131
1132 p_result->rcode = cache_merge(inst, request, entry);
1133
1134finish:
1135 cache_unref(request, inst, entry, handle);
1136
1138}
1139
1140/** Create, or update a cache entry
1141 *
1142 * @return
1143 * - #RLM_MODULE_OK on success.
1144 * - #RLM_MODULE_UPDATED if we merged the cache entry.
1145 * - #RLM_MODULE_FAIL on failure.
1146 */
1147static unlang_action_t CC_HINT(nonnull) mod_method_update(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
1148{
1149 rlm_cache_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1150 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
1151 fr_value_box_t *key = fr_value_box_list_head(&env->key);
1152 fr_time_delta_t ttl;
1153 bool expire = false;
1154 rlm_cache_entry_t *entry = NULL;
1155 rlm_cache_handle_t *handle = NULL;
1156 fr_pair_t *vp;
1157
1158 p_result->rcode = RLM_MODULE_NOOP;
1159
1161
1162 /* Good to go? */
1163 if (cache_acquire(&handle, inst, request) < 0) {
1165 }
1166
1167 /* Process the TTL */
1168 ttl = inst->config.ttl; /* Set the default value from cache { ttl=... } */
1169 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cache_ttl);
1170 if (vp) {
1171 if (vp->vp_int32 == 0) {
1172 expire = true;
1173 } else if (vp->vp_int32 < 0) {
1174 ttl = fr_time_delta_from_sec(-(vp->vp_int32));
1175 /* Updating the TTL */
1176 } else {
1177 ttl = fr_time_delta_from_sec(vp->vp_int32);
1178 }
1179
1180 DEBUG3("Overwriting the default TTL %pV -> %d", fr_box_time_delta(ttl), vp->vp_int32);
1181 }
1182
1183 /*
1184 * We can only alter the TTL on an entry if it exists.
1185 */
1186 cache_find(p_result, &entry, inst, request, &handle, key);
1187 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1188
1189 if (p_result->rcode == RLM_MODULE_OK) {
1190 fr_assert(entry != NULL);
1191
1192 DEBUG3("Updating the TTL -> %pV", fr_box_time_delta(ttl));
1193
1194 entry->expires = fr_unix_time_add(fr_time_to_unix_time(request->packet->timestamp), ttl);
1195
1196 cache_set_ttl(p_result, inst, request, &handle, entry);
1197 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1198 }
1199
1200 /*
1201 * Expire the entry if told to, and we either don't know whether
1202 * it exists, or we know it does.
1203 *
1204 * We only expire if we're not inserting, as driver insert methods
1205 * should perform upserts.
1206 */
1207 if (expire) {
1208 DEBUG3("Expiring cache entry");
1209
1210 cache_expire(p_result, inst, request, &handle, key);
1211 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1212 }
1213
1214 /*
1215 * Inserts are upserts, so we don't care about the
1216 * entry state.
1217 */
1218 cache_insert(p_result, inst, request, &handle, key, env->maps, ttl);
1219 if (p_result->rcode == RLM_MODULE_OK) p_result->rcode = RLM_MODULE_UPDATED;
1220
1221finish:
1222 cache_unref(request, inst, entry, handle);
1223
1225}
1226
1227/** Create, or update a cache entry
1228 *
1229 * @return
1230 * - #RLM_MODULE_NOOP if an entry already existed.
1231 * - #RLM_MODULE_UPDATED if we inserted a cache entry.
1232 * - #RLM_MODULE_FAIL on failure.
1233 */
1234static unlang_action_t CC_HINT(nonnull) mod_method_store(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
1235{
1236 rlm_cache_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1237 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
1238 fr_value_box_t *key = fr_value_box_list_head(&env->key);
1239 fr_time_delta_t ttl;
1240 rlm_cache_entry_t *entry = NULL;
1241 rlm_cache_handle_t *handle = NULL;
1242 fr_pair_t *vp;
1243
1244 p_result->rcode = RLM_MODULE_NOOP;
1245
1247
1248 if (cache_acquire(&handle, inst, request) < 0) {
1250 }
1251
1252 /* Process the TTL */
1253 ttl = inst->config.ttl; /* Set the default value from cache { ttl=... } */
1254 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cache_ttl);
1255 if (vp && (vp->vp_int32 > 0)) {
1256 ttl = fr_time_delta_from_sec(vp->vp_int32);
1257
1258 DEBUG3("Overriding default TTL %pV -> %d", fr_box_time_delta(ttl), vp->vp_int32);
1259 }
1260
1261 /*
1262 * We can only alter the TTL on an entry if it exists.
1263 */
1264 cache_find(p_result, &entry, inst, request, &handle, key);
1265 switch (p_result->rcode) {
1266 default:
1267 case RLM_MODULE_OK:
1268 p_result->rcode = RLM_MODULE_NOOP;
1269 goto finish;
1270
1271 case RLM_MODULE_FAIL:
1272 goto finish;
1273
1275 break;
1276 }
1277
1278 /*
1279 * Inserts are upserts, so we don't care about the
1280 * entry state, just that we're not meant to be
1281 * setting the TTL, which precludes performing an
1282 * insert.
1283 */
1284 cache_insert(p_result, inst, request, &handle, key, env->maps, ttl);
1285
1286finish:
1287 cache_unref(request, inst, entry, handle);
1288 if (p_result->rcode == RLM_MODULE_OK) p_result->rcode = RLM_MODULE_UPDATED;
1289
1291}
1292
1293/** Delete the entries by ${key}
1294 *
1295 * @return
1296 * - #RLM_MODULE_OK on success.
1297 * - #RLM_MODULE_NOTFOUND on cache miss.
1298 * - #RLM_MODULE_FAIL on failure.
1299 */
1300static unlang_action_t CC_HINT(nonnull) mod_method_clear(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
1301{
1302 rlm_cache_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1303 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
1304 fr_value_box_t *key = fr_value_box_list_head(&env->key);
1305 rlm_cache_entry_t *entry = NULL;
1306 rlm_cache_handle_t *handle = NULL;
1307
1308 p_result->rcode = RLM_MODULE_NOOP;
1309
1310 DEBUG3("Calling %s.clear", mctx->mi->name);
1311
1313
1314 /* Good to go? */
1315 if (cache_acquire(&handle, inst, request) < 0) {
1317 }
1318
1319 cache_find(p_result, &entry, inst, request, &handle, key);
1320 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1321
1322 if (!entry) {
1323 REDEBUG2("Entry not found to delete");
1324 p_result->rcode = RLM_MODULE_NOTFOUND;
1325 goto finish;
1326 }
1327
1328 cache_expire(p_result, inst, request, &handle, key);
1329
1330finish:
1331 cache_unref(request, inst, entry, handle);
1332
1334}
1335
1336/** Change the TTL on an existing entry.
1337 *
1338 * @return
1339 * - #RLM_MODULE_UPDATED on success.
1340 * - #RLM_MODULE_NOTFOUND on cache miss.
1341 * - #RLM_MODULE_FAIL on failure.
1342 */
1343static unlang_action_t CC_HINT(nonnull) mod_method_ttl(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
1344{
1345 rlm_cache_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1346 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
1347 fr_value_box_t *key = fr_value_box_list_head(&env->key);
1348 fr_time_delta_t ttl;
1349 rlm_cache_entry_t *entry = NULL;
1350 rlm_cache_handle_t *handle = NULL;
1351 fr_pair_t *vp;
1352
1353 p_result->rcode = RLM_MODULE_NOOP;
1354
1355 DEBUG3("Calling %s.ttl", mctx->mi->name);
1356
1358
1359 /* Good to go? */
1360 if (cache_acquire(&handle, inst, request) < 0) {
1362 }
1363
1364 /* Process the TTL */
1365 ttl = inst->config.ttl; /* Set the default value from cache { ttl=... } */
1366 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cache_ttl);
1367 if (vp) {
1368 if (vp->vp_int32 < 0) {
1369 ttl = fr_time_delta_from_sec(-(vp->vp_int32));
1370 /* Updating the TTL */
1371 } else {
1372 ttl = fr_time_delta_from_sec(vp->vp_int32);
1373 }
1374
1375 DEBUG3("Overwriting the default TTL %pV -> %d", fr_box_time_delta(inst->config.ttl), vp->vp_int32);
1376 }
1377
1378 /*
1379 * We can only alter the TTL on an entry if it exists.
1380 */
1381 cache_find(p_result, &entry, inst, request, &handle, key);
1382 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1383
1384 if (p_result->rcode == RLM_MODULE_OK) {
1385 fr_assert(entry != NULL);
1386
1387 DEBUG3("Updating the TTL -> %pV", fr_box_time_delta(ttl));
1388
1389 entry->expires = fr_unix_time_add(fr_time_to_unix_time(request->packet->timestamp), ttl);
1390
1391 cache_set_ttl(p_result, inst, request, &handle, entry);
1392 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1393
1394 p_result->rcode = RLM_MODULE_UPDATED;
1395 }
1396
1397finish:
1398 cache_unref(request, inst, entry, handle);
1399
1401}
1402
1403/** Free any memory allocated under the instance
1404 *
1405 */
1406static int mod_detach(module_detach_ctx_t const *mctx)
1407{
1408 rlm_cache_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1409
1410 /*
1411 * We need to explicitly free all children, so if the driver
1412 * parented any memory off the instance, their destructors
1413 * run before we unload the bytecode for them.
1414 *
1415 * If we don't do this, we get a SEGV deep inside the talloc code
1416 * when it tries to call a destructor that no longer exists.
1417 */
1418 talloc_free_children(inst);
1419
1420 return 0;
1421}
1422
1423/** Verify that a map in the cache section makes sense
1424 *
1425 */
1426static int cache_verify(map_t *map, void *uctx)
1427{
1428 if (unlang_fixup_update(map, uctx) < 0) return -1;
1429
1430 if (!tmpl_is_attr(map->lhs)) {
1431 cf_log_err(map->ci, "Destination must be an attribute ref or a list");
1432 return -1;
1433 }
1434
1435 if (!fr_assignment_op[map->op]) {
1436 cf_log_err(map->ci, "Invalid operator '%s'", fr_tokens[map->op]);
1437 return -1;
1438 }
1439
1440 return 0;
1441}
1442
1443static int cache_update_section_parse(TALLOC_CTX *ctx, call_env_parsed_head_t *out, tmpl_rules_t const *t_rules,
1444 CONF_ITEM *ci,
1445 UNUSED call_env_ctx_t const *cec, UNUSED call_env_parser_t const *rule)
1446{
1447 CONF_SECTION *update = cf_item_to_section(ci);
1448 call_env_parsed_t *parsed;
1449 map_list_t *maps;
1450
1451 MEM(parsed = call_env_parsed_add(ctx, out,
1453
1454 MEM(maps = talloc(parsed, map_list_t));
1455 map_list_init(maps);
1456
1457 if (map_afrom_cs(maps, maps, update,
1458 t_rules, t_rules, cache_verify, NULL, MAX_ATTRMAP) < 0) {
1459 error:
1460 call_env_parsed_free(out, parsed);
1461 return -1;
1462 }
1463
1464 if (map_list_empty(maps)) {
1465 cf_log_err(update, "Update section must not be empty");
1466 goto error;
1467 }
1468
1469 call_env_parsed_set_data(parsed, maps);
1470
1471 return 0;
1472}
1473
1474/** Create a new rlm_cache_instance
1475 *
1476 */
1477static int mod_instantiate(module_inst_ctx_t const *mctx)
1478{
1479 rlm_cache_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1480 CONF_SECTION *conf = mctx->mi->conf;
1481
1482 /*
1483 * Non optional fields and callbacks
1484 */
1485 fr_assert(inst->driver->common.name);
1486 fr_assert(inst->driver->find);
1487 fr_assert(inst->driver->insert);
1488 fr_assert(inst->driver->expire);
1489
1490 if (!fr_time_delta_ispos(inst->config.ttl)) {
1491 cf_log_err(conf, "Must set 'ttl' to non-zero");
1492 return -1;
1493 }
1494
1495 if (inst->config.epoch != 0) {
1496 cf_log_err(conf, "Must not set 'epoch' in the configuration files");
1497 return -1;
1498 }
1499
1500 return 0;
1501}
1502
1503/** Register module xlats
1504 *
1505 */
1506static int mod_bootstrap(module_inst_ctx_t const *mctx)
1507{
1508 xlat_t *xlat;
1509
1510 /*
1511 * Register the cache xlat function
1512 */
1513 xlat = module_rlm_xlat_register(mctx->mi->boot, mctx, NULL, cache_xlat, FR_TYPE_VOID);
1516
1517 xlat = module_rlm_xlat_register(mctx->mi->boot, mctx, "ttl.get", cache_ttl_get_xlat, FR_TYPE_VOID);
1519
1520 return 0;
1521}
1522
1523/*
1524 * The module name should be the only globally exported symbol.
1525 * That is, everything else should be 'static'.
1526 *
1527 * If the module needs to temporarily modify it's instantiation
1528 * data, the type should be changed to MODULE_TYPE_THREAD_UNSAFE.
1529 * The server will then take care of ensuring that the module
1530 * is single-threaded.
1531 */
1533 .common = {
1534 .magic = MODULE_MAGIC_INIT,
1535 .name = "cache",
1536 .inst_size = sizeof(rlm_cache_t),
1538 .bootstrap = mod_bootstrap,
1539 .instantiate = mod_instantiate,
1540 .detach = mod_detach
1541 },
1542 .method_group = {
1543 .bindings = (module_method_binding_t[]){
1544 { .section = SECTION_NAME("clear", CF_IDENT_ANY), .method = mod_method_clear, .method_env = &cache_method_env },
1545 { .section = SECTION_NAME("load", CF_IDENT_ANY), .method = mod_method_load, .method_env = &cache_method_env },
1546 { .section = SECTION_NAME("status", CF_IDENT_ANY), .method = mod_method_status, .method_env = &cache_method_env },
1547 { .section = SECTION_NAME("store", CF_IDENT_ANY), .method = mod_method_store, .method_env = &cache_method_env },
1548 { .section = SECTION_NAME("ttl", CF_IDENT_ANY), .method = mod_method_ttl, .method_env = &cache_method_env },
1549 { .section = SECTION_NAME("update", CF_IDENT_ANY), .method = mod_method_update, .method_env = &cache_method_env },
1550 { .section = SECTION_NAME(CF_IDENT_ANY, CF_IDENT_ANY), .method = mod_cache_it, .method_env = &cache_method_env },
1552 }
1553 }
1554};
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:784
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:697
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:754
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:288
#define cf_log_perr(_cf, _fmt,...)
Definition cf_util.h:295
#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:455
#define DEBUG3(_fmt,...)
Definition log.h:266
#define RWDEBUG(fmt,...)
Definition log.h:373
#define RDEBUG3(fmt,...)
Definition log.h:355
#define RERROR(fmt,...)
Definition log.h:310
#define RPEDEBUG(fmt,...)
Definition log.h:388
#define REDEBUG2(fmt,...)
Definition log.h:384
#define RINDENT()
Indent R* messages by one level.
Definition log.h:442
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:352
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:947
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:704
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:169
#define fr_assert(_expr)
Definition rad_assert.h:38
#define pair_update_request(_attr, _da)
#define REDEBUG(fmt,...)
#define RDEBUG_ENABLED2()
#define RDEBUG2(fmt,...)
static rs_t * conf
Definition radsniff.c:53
#define RETURN_UNLANG_INVALID
Definition rcode.h:66
#define RETURN_UNLANG_RCODE(_rcode)
Definition rcode.h:61
#define RETURN_UNLANG_NOTFOUND
Definition rcode.h:68
#define RETURN_UNLANG_FAIL
Definition rcode.h:63
#define RETURN_UNLANG_OK
Definition rcode.h:64
rlm_rcode_t
Return codes indicating the result of the module call.
Definition rcode.h:44
@ RLM_MODULE_OK
The module is OK, continue.
Definition rcode.h:49
@ RLM_MODULE_FAIL
Module failed, don't reply.
Definition rcode.h:48
@ RLM_MODULE_NOTFOUND
User not found.
Definition rcode.h:53
@ RLM_MODULE_UPDATED
OK (pairs modified).
Definition rcode.h:55
@ RLM_MODULE_NOOP
Module succeeded without doing anything.
Definition rcode.h:54
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:1406
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:1234
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:1069
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:1106
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:1426
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:1506
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:1343
static xlat_arg_parser_t const cache_xlat_args[]
Definition rlm_cache.c:892
module_rlm_t rlm_cache
Definition rlm_cache.c:1532
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:1300
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:1147
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:983
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:1025
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:1477
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:245
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:171
char const * fr_tokens[T_TOKEN_LAST]
Definition token.c:81
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:604
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:858
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:4409
#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