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: ed3a46e421bdfb64aa9e5f07af2a5275e854e28a $
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 */
25#include "lib/unlang/action.h"
26RCSID("$Id: ed3a46e421bdfb64aa9e5f07af2a5275e854e28a $")
27
28#define LOG_PREFIX mctx->mi->name
29
30#include <freeradius-devel/server/base.h>
31#include <freeradius-devel/server/module_rlm.h>
32#include <freeradius-devel/server/modpriv.h>
33#include <freeradius-devel/server/dl_module.h>
34#include <freeradius-devel/server/rcode.h>
35#include <freeradius-devel/server/tmpl.h>
36#include <freeradius-devel/util/debug.h>
37#include <freeradius-devel/util/types.h>
38#include <freeradius-devel/util/value.h>
39#include <freeradius-devel/unlang/xlat_func.h>
40#include <freeradius-devel/unlang/call_env.h>
41
42#include "rlm_cache.h"
43
45
46int submodule_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule);
47static 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);
48static 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);
49
50static const conf_parser_t module_config[] = {
51 { FR_CONF_OFFSET_TYPE_FLAGS("driver", FR_TYPE_VOID, 0, rlm_cache_t, driver_submodule), .dflt = "rbtree",
53 { FR_CONF_OFFSET("ttl", rlm_cache_config_t, ttl), .dflt = "500s" },
54 { FR_CONF_OFFSET("max_entries", rlm_cache_config_t, max_entries), .dflt = "0" },
55
56 /* Should be a type which matches time_t, @fixme before 2038 */
57 { FR_CONF_OFFSET("epoch", rlm_cache_config_t, epoch), .dflt = "0" },
58 { FR_CONF_OFFSET("add_stats", rlm_cache_config_t, stats), .dflt = "no" },
60};
61
62typedef struct {
63 fr_value_box_t *key; //!< To lookup the cache entry with.
64 map_list_t *maps; //!< Attribute map applied to cache entries.
66
67typedef struct {
68 fr_type_t ktype; //!< Key type
69
71
80
82
85 { .out = &dict_freeradius, .proto = "freeradius" },
86 { NULL }
87};
88
95
98 { .out = &attr_cache_merge_new, .name = "Cache-Merge-New", .type = FR_TYPE_BOOL, .dict = &dict_freeradius },
99 { .out = &attr_cache_status_only, .name = "Cache-Status-Only", .type = FR_TYPE_BOOL, .dict = &dict_freeradius },
100 { .out = &attr_cache_allow_merge, .name = "Cache-Allow-Merge", .type = FR_TYPE_BOOL, .dict = &dict_freeradius },
101 { .out = &attr_cache_allow_insert, .name = "Cache-Allow-Insert", .type = FR_TYPE_BOOL, .dict = &dict_freeradius },
102 { .out = &attr_cache_ttl, .name = "Cache-TTL", .type = FR_TYPE_INT32, .dict = &dict_freeradius },
103 { .out = &attr_cache_entry_hits, .name = "Cache-Entry-Hits", .type = FR_TYPE_UINT32, .dict = &dict_freeradius },
104 { NULL }
105};
106
107int submodule_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
108{
109 rlm_cache_t *inst = talloc_get_type_abort(parent, rlm_cache_t);
111 int ret;
112
113 if (unlikely(ret = module_rlm_submodule_parse(ctx, out, parent, ci, rule) < 0)) return ret;
114
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/** Do caching checks
614 *
615 * Since we can update ANY VP list, we do exactly the same thing for all sections
616 * (autz / auth / etc.)
617 *
618 * If you want to cache something different in different sections, configure
619 * another cache module.
620 */
621static unlang_action_t CC_HINT(nonnull) mod_cache_it(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
622{
623 rlm_cache_entry_t *c = NULL;
625 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
626
627 rlm_cache_handle_t *handle;
628
629 fr_dcursor_t cursor;
630 fr_pair_t *vp;
631
632 bool merge = true, insert = true, expire = false, set_ttl = false;
633 int exists = -1;
634
635 fr_time_delta_t ttl = inst->config.ttl;
636
637 p_result->rcode = RLM_MODULE_NOOP;
638
639 if (fr_type_is_variable_size(env->key->type) && (env->key->vb_length == 0)) {
640 REDEBUG("Zero length key string is invalid");
642 }
643
644 /*
645 * If Cache-Status-Only == yes, only return whether we found a
646 * valid cache entry
647 */
648 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cache_status_only);
649 if (vp && vp->vp_bool) {
650 RINDENT();
651 RDEBUG3("status-only: yes");
652 REXDENT();
653
654 if (cache_acquire(&handle, inst, request) < 0) {
656 }
657
658 cache_find(p_result, &c, inst, request, &handle, env->key);
659 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
660 fr_assert(!inst->driver->acquire || handle);
661
662 p_result->rcode = c ? RLM_MODULE_OK:
664 goto finish;
665 }
666
667 /*
668 * Figure out what operation we're doing
669 */
670 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cache_allow_merge);
671 if (vp) merge = vp->vp_bool;
672
673 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cache_allow_insert);
674 if (vp) insert = vp->vp_bool;
675
676 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cache_ttl);
677 if (vp) {
678 if (vp->vp_int32 == 0) {
679 expire = true;
680 } else if (vp->vp_int32 < 0) {
681 expire = true;
682 ttl = fr_time_delta_from_sec(-(vp->vp_int32));
683 /* Updating the TTL */
684 } else {
685 set_ttl = true;
686 ttl = fr_time_delta_from_sec(vp->vp_int32);
687 }
688 }
689
690 RINDENT();
691 RDEBUG3("merge : %s", merge ? "yes" : "no");
692 RDEBUG3("insert : %s", insert ? "yes" : "no");
693 RDEBUG3("expire : %s", expire ? "yes" : "no");
694 RDEBUG3("ttl : %pV", fr_box_time_delta(ttl));
695 REXDENT();
696 if (cache_acquire(&handle, inst, request) < 0) {
698 }
699
700 /*
701 * Retrieve the cache entry and merge it with the current request
702 * recording whether the entry existed.
703 */
704 if (merge) {
705 cache_find(p_result, &c, inst, request, &handle, env->key);
706 switch (p_result->rcode) {
707 case RLM_MODULE_FAIL:
708 goto finish;
709
710 case RLM_MODULE_OK:
711 p_result->rcode = cache_merge(inst, request, c);
712 exists = 1;
713 break;
714
716 p_result->rcode = RLM_MODULE_NOTFOUND;
717 exists = 0;
718 break;
719
720 default:
721 fr_assert(0);
722 }
723 fr_assert(!inst->driver->acquire || handle);
724 }
725
726 /*
727 * Expire the entry if told to, and we either don't know whether
728 * it exists, or we know it does.
729 *
730 * We only expire if we're not inserting, as driver insert methods
731 * should perform upserts.
732 */
733 if (expire && ((exists == -1) || (exists == 1))) {
734 if (!insert) {
735 unlang_result_t tmp;
736
737 fr_assert(!set_ttl);
738 cache_expire(&tmp, inst, request, &handle, env->key);
739 switch (tmp.rcode) {
740 case RLM_MODULE_FAIL:
741 p_result->rcode = RLM_MODULE_FAIL;
742 goto finish;
743
744 case RLM_MODULE_OK:
745 if (p_result->rcode == RLM_MODULE_NOOP) p_result->rcode = RLM_MODULE_OK;
746 break;
747
749 if (p_result->rcode == RLM_MODULE_NOOP) p_result->rcode = RLM_MODULE_NOTFOUND;
750 break;
751
752 default:
753 fr_assert(0);
754 break;
755 }
756 /* If it previously existed, it doesn't now */
757 }
758 /* Otherwise use insert to overwrite */
759 exists = 0;
760 }
761
762 /*
763 * If we still don't know whether it exists or not
764 * and we need to do an insert or set_ttl operation
765 * determine that now.
766 */
767 if ((exists < 0) && (insert || set_ttl)) {
768 unlang_result_t tmp;
769
770 cache_find(&tmp, &c, inst, request, &handle, env->key);
771 switch (tmp.rcode) {
772 case RLM_MODULE_FAIL:
773 p_result->rcode = RLM_MODULE_FAIL;
774 goto finish;
775
776 case RLM_MODULE_OK:
777 exists = 1;
778 if (p_result->rcode != RLM_MODULE_UPDATED) p_result->rcode = RLM_MODULE_OK;
779 break;
780
782 exists = 0;
783 break;
784
785 default:
786 fr_assert(0);
787 }
788 fr_assert(!inst->driver->acquire || handle);
789 }
790
791 /*
792 * We can only alter the TTL on an entry if it exists.
793 */
794 if (set_ttl && (exists == 1)) {
795 unlang_result_t tmp;
796
797 fr_assert(c);
798
799 c->expires = fr_unix_time_add(fr_time_to_unix_time(request->packet->timestamp), ttl);
800
801 cache_set_ttl(&tmp, inst, request, &handle, c);
802 switch (tmp.rcode) {
803 case RLM_MODULE_FAIL:
804 p_result->rcode = RLM_MODULE_FAIL;
805 goto finish;
806
808 case RLM_MODULE_OK:
809 if (p_result->rcode != RLM_MODULE_UPDATED) p_result->rcode = RLM_MODULE_OK;
810 goto finish;
811
812 default:
813 fr_assert(0);
814 }
815 }
816
817 /*
818 * Inserts are upserts, so we don't care about the
819 * entry state, just that we're not meant to be
820 * setting the TTL, which precludes performing an
821 * insert.
822 */
823 if (insert && (exists == 0)) {
824 unlang_result_t tmp;
825
826 cache_insert(&tmp, inst, request, &handle, env->key, env->maps, ttl);
827 switch (tmp.rcode) {
828 case RLM_MODULE_FAIL:
829 p_result->rcode = RLM_MODULE_FAIL;
830 goto finish;
831
832 case RLM_MODULE_OK:
833 if (p_result->rcode != RLM_MODULE_UPDATED) p_result->rcode = RLM_MODULE_OK;
834 break;
835
837 p_result->rcode = RLM_MODULE_UPDATED;
838 break;
839
840 default:
841 fr_assert(0);
842 }
843 fr_assert(!inst->driver->acquire || handle);
844 goto finish;
845 }
846
847
848finish:
849 cache_free(inst, &c);
850 cache_release(inst, request, &handle);
851
852 /*
853 * Clear control attributes
854 */
855 for (vp = fr_pair_dcursor_init(&cursor, &request->control_pairs);
856 vp;
857 vp = fr_dcursor_next(&cursor)) {
858 again:
859 if (!fr_dict_attr_is_top_level(vp->da)) continue;
860
861 switch (vp->da->attr) {
862 case FR_CACHE_TTL:
863 case FR_CACHE_STATUS_ONLY:
864 case FR_CACHE_ALLOW_MERGE:
865 case FR_CACHE_ALLOW_INSERT:
866 case FR_CACHE_MERGE_NEW:
867 RDEBUG2("Removing control.%s", vp->da->name);
868 vp = fr_dcursor_remove(&cursor);
870 vp = fr_dcursor_current(&cursor);
871 if (!vp) break;
872 goto again;
873 }
874 }
875
877}
878
880 { .required = true, .single = true, .type = FR_TYPE_STRING },
882};
883
884/** Allow single attribute values to be retrieved from the cache
885 *
886 * @ingroup xlat_functions
887 */
888static CC_HINT(nonnull)
890 xlat_ctx_t const *xctx,
891 request_t *request, fr_value_box_list_t *in)
892{
893 rlm_cache_entry_t *c = NULL;
894 rlm_cache_t *inst = talloc_get_type_abort(xctx->mctx->mi->data, rlm_cache_t);
895 cache_call_env_t *env = talloc_get_type_abort(xctx->env_data, cache_call_env_t);
896 rlm_cache_handle_t *handle = NULL;
897
898 ssize_t slen;
899
900 fr_value_box_t *attr = fr_value_box_list_head(in);
901 fr_value_box_t *vb;
902
903 tmpl_t *target = NULL;
904 map_t *map = NULL;
905 unlang_result_t result = { .rcode = RLM_MODULE_NOOP };
906
907 slen = tmpl_afrom_attr_substr(ctx, NULL, &target,
908 &FR_SBUFF_IN(attr->vb_strvalue, attr->vb_length),
909 NULL,
910 &(tmpl_rules_t){
911 .attr = {
912 .dict_def = request->proto_dict,
913 .list_def = request_attr_request,
914 }
915 });
916 if (slen <= 0) {
917 RPEDEBUG("Invalid key");
918 return XLAT_ACTION_FAIL;
919 }
920
921 if (cache_acquire(&handle, inst, request) < 0) {
922 talloc_free(target);
923 return XLAT_ACTION_FAIL;
924 }
925
926 cache_find(&result, &c, inst, request, &handle, env->key);
927 switch (result.rcode) {
928 case RLM_MODULE_OK: /* found */
929 break;
930
931 default:
932 talloc_free(target);
933 cache_release(inst, request, &handle);
934 return XLAT_ACTION_FAIL;
935 }
936
937 while ((map = map_list_next(&c->maps, map))) {
938 if ((tmpl_attr_tail_da(map->lhs) != tmpl_attr_tail_da(target)) ||
939 (tmpl_list(map->lhs) != tmpl_list(target))) continue;
940
941 MEM(vb = fr_value_box_alloc_null(ctx));
942 fr_value_box_copy(vb, vb, tmpl_value(map->rhs));
944 break;
945 }
946
947 talloc_free(target);
948
949 cache_free(inst, &c);
950 cache_release(inst, request, &handle);
951
952 /*
953 * Check if we found a matching map
954 */
955 if (!map) return XLAT_ACTION_FAIL;
956
957 return XLAT_ACTION_DONE;
958}
959
961 xlat_ctx_t const *xctx,
962 request_t *request, UNUSED fr_value_box_list_t *in)
963{
964
965 rlm_cache_entry_t *c = NULL;
966 rlm_cache_t *inst = talloc_get_type_abort(xctx->mctx->mi->data, rlm_cache_t);
967 cache_call_env_t *env = talloc_get_type_abort(xctx->env_data, cache_call_env_t);
968 rlm_cache_handle_t *handle = NULL;
969
970 unlang_result_t result = { .rcode = RLM_MODULE_NOOP };
971
972 fr_value_box_t *vb;
973
974 if (cache_acquire(&handle, inst, request) < 0) {
975 return XLAT_ACTION_FAIL;
976 }
977
978 cache_find(&result, &c, inst, request, &handle, env->key);
979 switch (result.rcode) {
980 case RLM_MODULE_OK: /* found */
981 break;
982
983 default:
984 cache_release(inst, request, &handle);
985 return XLAT_ACTION_DONE;
986 }
987
988 MEM(vb = fr_value_box_alloc(ctx, FR_TYPE_TIME_DELTA, NULL));
989 vb->vb_time_delta = fr_unix_time_sub(c->expires, fr_time_to_unix_time(request->packet->timestamp));
991
992 cache_free(inst, &c);
993 cache_release(inst, request, &handle);
994
995 return XLAT_ACTION_DONE;
996}
997
998/** Release the allocated resources and cleanup the avps
999 */
1000static void cache_unref(request_t *request, rlm_cache_t const *inst, rlm_cache_entry_t *entry,
1001 rlm_cache_handle_t *handle)
1002{
1003 fr_dcursor_t cursor;
1004 fr_pair_t *vp;
1005
1006 /*
1007 * Release the driver calls
1008 */
1009 cache_free(inst, &entry);
1010 cache_release(inst, request, &handle);
1011
1012 /*
1013 * Clear control attributes
1014 */
1015 for (vp = fr_pair_dcursor_init(&cursor, &request->control_pairs);
1016 vp;
1017 vp = fr_dcursor_next(&cursor)) {
1018 again:
1019 if (!fr_dict_attr_is_top_level(vp->da)) continue;
1020
1021 switch (vp->da->attr) {
1022 case FR_CACHE_TTL:
1023 case FR_CACHE_STATUS_ONLY:
1024 case FR_CACHE_ALLOW_MERGE:
1025 case FR_CACHE_ALLOW_INSERT:
1026 case FR_CACHE_MERGE_NEW:
1027 RDEBUG2("Removing control:%s", vp->da->name);
1028 vp = fr_dcursor_remove(&cursor);
1029 TALLOC_FREE(vp);
1030 vp = fr_dcursor_current(&cursor);
1031 if (!vp) break;
1032 goto again;
1033 }
1034 }
1035}
1036
1037/** Get the status by ${key} (without load)
1038 *
1039 * @return
1040 * - #RLM_MODULE_OK on success.
1041 * - #RLM_MODULE_NOTFOUND on cache miss.
1042 * - #RLM_MODULE_FAIL on failure.
1043 */
1044static unlang_action_t CC_HINT(nonnull) mod_method_status(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
1045{
1046 rlm_cache_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1047 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
1048 rlm_cache_entry_t *entry = NULL;
1049 rlm_cache_handle_t *handle = NULL;
1050
1051 p_result->rcode = RLM_MODULE_NOOP;
1052
1053 if (fr_type_is_variable_size(env->key->type) && (env->key->vb_length == 0)) {
1054 REDEBUG("Zero length key string is invalid");
1056 }
1057
1058 /* Good to go? */
1059 if (cache_acquire(&handle, inst, request) < 0) {
1061 }
1062
1063 fr_assert(!inst->driver->acquire || handle);
1064
1065 cache_find(p_result, &entry, inst, request, &handle, env->key);
1066 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1067
1068 p_result->rcode = (entry) ? RLM_MODULE_OK : RLM_MODULE_NOTFOUND;
1069
1070finish:
1071 cache_unref(request, inst, entry, handle);
1072
1074}
1075
1076/** Load the avps by ${key}.
1077 *
1078 * @return
1079 * - #RLM_MODULE_UPDATED on success.
1080 * - #RLM_MODULE_NOTFOUND on cache miss.
1081 * - #RLM_MODULE_FAIL on failure.
1082 */
1083static unlang_action_t CC_HINT(nonnull) mod_method_load(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
1084{
1085 rlm_cache_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1086 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
1087 rlm_cache_entry_t *entry = NULL;
1088 rlm_cache_handle_t *handle = NULL;
1089
1090 p_result->rcode = RLM_MODULE_NOOP;
1091
1092 if (fr_type_is_variable_size(env->key->type) && (env->key->vb_length == 0)) {
1093 REDEBUG("Zero length key string is invalid");
1095 }
1096
1097 /* Good to go? */
1098 if (cache_acquire(&handle, inst, request) < 0) {
1100 }
1101
1102 cache_find(p_result, &entry, inst, request, &handle, env->key);
1103 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1104
1105 if (!entry) {
1106 RDEBUG2("Entry not found to load");
1107 p_result->rcode = RLM_MODULE_NOTFOUND;
1108 goto finish;
1109 }
1110
1111 p_result->rcode = cache_merge(inst, request, entry);
1112
1113finish:
1114 cache_unref(request, inst, entry, handle);
1115
1117}
1118
1119/** Create, or update a cache entry
1120 *
1121 * @return
1122 * - #RLM_MODULE_OK on success.
1123 * - #RLM_MODULE_UPDATED if we merged the cache entry.
1124 * - #RLM_MODULE_FAIL on failure.
1125 */
1126static unlang_action_t CC_HINT(nonnull) mod_method_update(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
1127{
1128 rlm_cache_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1129 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
1130 fr_time_delta_t ttl;
1131 bool expire = false;
1132 rlm_cache_entry_t *entry = NULL;
1133 rlm_cache_handle_t *handle = NULL;
1134 fr_pair_t *vp;
1135
1136 p_result->rcode = RLM_MODULE_NOOP;
1137
1138 if (fr_type_is_variable_size(env->key->type) && (env->key->vb_length == 0)) {
1139 REDEBUG("Zero length key string is invalid");
1141 }
1142
1143 /* Good to go? */
1144 if (cache_acquire(&handle, inst, request) < 0) {
1146 }
1147
1148 /* Process the TTL */
1149 ttl = inst->config.ttl; /* Set the default value from cache { ttl=... } */
1150 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cache_ttl);
1151 if (vp) {
1152 if (vp->vp_int32 == 0) {
1153 expire = true;
1154 } else if (vp->vp_int32 < 0) {
1155 ttl = fr_time_delta_from_sec(-(vp->vp_int32));
1156 /* Updating the TTL */
1157 } else {
1158 ttl = fr_time_delta_from_sec(vp->vp_int32);
1159 }
1160
1161 DEBUG3("Overwriting the default TTL %pV -> %d", fr_box_time_delta(ttl), vp->vp_int32);
1162 }
1163
1164 /*
1165 * We can only alter the TTL on an entry if it exists.
1166 */
1167 cache_find(p_result, &entry, inst, request, &handle, env->key);
1168 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1169
1170 if (p_result->rcode == RLM_MODULE_OK) {
1171 fr_assert(entry != NULL);
1172
1173 DEBUG3("Updating the TTL -> %pV", fr_box_time_delta(ttl));
1174
1175 entry->expires = fr_unix_time_add(fr_time_to_unix_time(request->packet->timestamp), ttl);
1176
1177 cache_set_ttl(p_result, inst, request, &handle, entry);
1178 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1179 }
1180
1181 /*
1182 * Expire the entry if told to, and we either don't know whether
1183 * it exists, or we know it does.
1184 *
1185 * We only expire if we're not inserting, as driver insert methods
1186 * should perform upserts.
1187 */
1188 if (expire) {
1189 DEBUG3("Expiring cache entry");
1190
1191 cache_expire(p_result, inst, request, &handle, env->key);
1192 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1193 }
1194
1195 /*
1196 * Inserts are upserts, so we don't care about the
1197 * entry state.
1198 */
1199 cache_insert(p_result, inst, request, &handle, env->key, env->maps, ttl);
1200 if (p_result->rcode == RLM_MODULE_OK) p_result->rcode = RLM_MODULE_UPDATED;
1201
1202finish:
1203 cache_unref(request, inst, entry, handle);
1204
1206}
1207
1208/** Create, or update a cache entry
1209 *
1210 * @return
1211 * - #RLM_MODULE_NOOP if an entry already existed.
1212 * - #RLM_MODULE_UPDATED if we inserted a cache entry.
1213 * - #RLM_MODULE_FAIL on failure.
1214 */
1215static unlang_action_t CC_HINT(nonnull) mod_method_store(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
1216{
1217 rlm_cache_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1218 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
1219 fr_time_delta_t ttl;
1220 rlm_cache_entry_t *entry = NULL;
1221 rlm_cache_handle_t *handle = NULL;
1222 fr_pair_t *vp;
1223
1224 p_result->rcode = RLM_MODULE_NOOP;
1225
1226 if (fr_type_is_variable_size(env->key->type) && (env->key->vb_length == 0)) {
1227 REDEBUG("Zero length key string is invalid");
1229 }
1230
1231 if (cache_acquire(&handle, inst, request) < 0) {
1233 }
1234
1235 /* Process the TTL */
1236 ttl = inst->config.ttl; /* Set the default value from cache { ttl=... } */
1237 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cache_ttl);
1238 if (vp && (vp->vp_int32 > 0)) {
1239 ttl = fr_time_delta_from_sec(vp->vp_int32);
1240
1241 DEBUG3("Overriding default TTL %pV -> %d", fr_box_time_delta(ttl), vp->vp_int32);
1242 }
1243
1244 /*
1245 * We can only alter the TTL on an entry if it exists.
1246 */
1247 cache_find(p_result, &entry, inst, request, &handle, env->key);
1248 switch (p_result->rcode) {
1249 default:
1250 case RLM_MODULE_OK:
1251 p_result->rcode = RLM_MODULE_NOOP;
1252 goto finish;
1253
1254 case RLM_MODULE_FAIL:
1255 goto finish;
1256
1258 break;
1259 }
1260
1261 /*
1262 * Inserts are upserts, so we don't care about the
1263 * entry state, just that we're not meant to be
1264 * setting the TTL, which precludes performing an
1265 * insert.
1266 */
1267 cache_insert(p_result, inst, request, &handle, env->key, env->maps, ttl);
1268
1269finish:
1270 cache_unref(request, inst, entry, handle);
1271 if (p_result->rcode == RLM_MODULE_OK) p_result->rcode = RLM_MODULE_UPDATED;
1272
1274}
1275
1276/** Delete the entries by ${key}
1277 *
1278 * @return
1279 * - #RLM_MODULE_OK on success.
1280 * - #RLM_MODULE_NOTFOUND on cache miss.
1281 * - #RLM_MODULE_FAIL on failure.
1282 */
1283static unlang_action_t CC_HINT(nonnull) mod_method_clear(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
1284{
1285 rlm_cache_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1286 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
1287 rlm_cache_entry_t *entry = NULL;
1288 rlm_cache_handle_t *handle = NULL;
1289
1290 p_result->rcode = RLM_MODULE_NOOP;
1291
1292 DEBUG3("Calling %s.clear", mctx->mi->name);
1293
1294 if (fr_type_is_variable_size(env->key->type) && (env->key->vb_length == 0)) {
1295 REDEBUG("Zero length key string is invalid");
1297 }
1298
1299 /* Good to go? */
1300 if (cache_acquire(&handle, inst, request) < 0) {
1302 }
1303
1304 cache_find(p_result, &entry, inst, request, &handle, env->key);
1305 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1306
1307 if (!entry) {
1308 REDEBUG2("Entry not found to delete");
1309 p_result->rcode = RLM_MODULE_NOTFOUND;
1310 goto finish;
1311 }
1312
1313 cache_expire(p_result, inst, request, &handle, env->key);
1314
1315finish:
1316 cache_unref(request, inst, entry, handle);
1317
1319}
1320
1321/** Change the TTL on an existing entry.
1322 *
1323 * @return
1324 * - #RLM_MODULE_UPDATED on success.
1325 * - #RLM_MODULE_NOTFOUND on cache miss.
1326 * - #RLM_MODULE_FAIL on failure.
1327 */
1328static unlang_action_t CC_HINT(nonnull) mod_method_ttl(unlang_result_t *p_result, module_ctx_t const *mctx, request_t *request)
1329{
1330 rlm_cache_t const *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1331 cache_call_env_t *env = talloc_get_type_abort(mctx->env_data, cache_call_env_t);
1332 fr_time_delta_t ttl;
1333 rlm_cache_entry_t *entry = NULL;
1334 rlm_cache_handle_t *handle = NULL;
1335 fr_pair_t *vp;
1336
1337 p_result->rcode = RLM_MODULE_NOOP;
1338
1339 DEBUG3("Calling %s.ttl", mctx->mi->name);
1340
1341 if (fr_type_is_variable_size(env->key->type) && (env->key->vb_length == 0)) {
1342 REDEBUG("Zero length key string is invalid");
1344 }
1345
1346 /* Good to go? */
1347 if (cache_acquire(&handle, inst, request) < 0) {
1349 }
1350
1351 /* Process the TTL */
1352 ttl = inst->config.ttl; /* Set the default value from cache { ttl=... } */
1353 vp = fr_pair_find_by_da(&request->control_pairs, NULL, attr_cache_ttl);
1354 if (vp) {
1355 if (vp->vp_int32 < 0) {
1356 ttl = fr_time_delta_from_sec(-(vp->vp_int32));
1357 /* Updating the TTL */
1358 } else {
1359 ttl = fr_time_delta_from_sec(vp->vp_int32);
1360 }
1361
1362 DEBUG3("Overwriting the default TTL %pV -> %d", fr_box_time_delta(inst->config.ttl), vp->vp_int32);
1363 }
1364
1365 /*
1366 * We can only alter the TTL on an entry if it exists.
1367 */
1368 cache_find(p_result, &entry, inst, request, &handle, env->key);
1369 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1370
1371 if (p_result->rcode == RLM_MODULE_OK) {
1372 fr_assert(entry != NULL);
1373
1374 DEBUG3("Updating the TTL -> %pV", fr_box_time_delta(ttl));
1375
1376 entry->expires = fr_unix_time_add(fr_time_to_unix_time(request->packet->timestamp), ttl);
1377
1378 cache_set_ttl(p_result, inst, request, &handle, entry);
1379 if (p_result->rcode == RLM_MODULE_FAIL) goto finish;
1380
1381 p_result->rcode = RLM_MODULE_UPDATED;
1382 }
1383
1384finish:
1385 cache_unref(request, inst, entry, handle);
1386
1388}
1389
1390/** Free any memory allocated under the instance
1391 *
1392 */
1393static int mod_detach(module_detach_ctx_t const *mctx)
1394{
1395 rlm_cache_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1396
1397 /*
1398 * We need to explicitly free all children, so if the driver
1399 * parented any memory off the instance, their destructors
1400 * run before we unload the bytecode for them.
1401 *
1402 * If we don't do this, we get a SEGV deep inside the talloc code
1403 * when it tries to call a destructor that no longer exists.
1404 */
1405 talloc_free_children(inst);
1406
1407 return 0;
1408}
1409
1410/** Verify that a map in the cache section makes sense
1411 *
1412 */
1413static int cache_verify(map_t *map, void *uctx)
1414{
1415 if (unlang_fixup_update(map, uctx) < 0) return -1;
1416
1417 if (!tmpl_is_attr(map->lhs)) {
1418 cf_log_err(map->ci, "Destination must be an attribute ref or a list");
1419 return -1;
1420 }
1421
1422 if (!fr_assignment_op[map->op]) {
1423 cf_log_err(map->ci, "Invalid operator '%s'", fr_tokens[map->op]);
1424 return -1;
1425 }
1426
1427 return 0;
1428}
1429
1430static int cache_update_section_parse(TALLOC_CTX *ctx, call_env_parsed_head_t *out, tmpl_rules_t const *t_rules,
1431 CONF_ITEM *ci,
1432 UNUSED call_env_ctx_t const *cec, UNUSED call_env_parser_t const *rule)
1433{
1434 CONF_SECTION *update = cf_item_to_section(ci);
1435 call_env_parsed_t *parsed;
1436 map_list_t *maps;
1437
1438 MEM(parsed = call_env_parsed_add(ctx, out,
1440
1441 MEM(maps = talloc(parsed, map_list_t));
1442 map_list_init(maps);
1443
1444 if (map_afrom_cs(maps, maps, update,
1445 t_rules, t_rules, cache_verify, NULL, MAX_ATTRMAP) < 0) {
1446 error:
1447 call_env_parsed_free(out, parsed);
1448 return -1;
1449 }
1450
1451 if (map_list_empty(maps)) {
1452 cf_log_err(update, "Update section must not be empty");
1453 goto error;
1454 }
1455
1456 call_env_parsed_set_data(parsed, maps);
1457
1458 return 0;
1459}
1460
1461/** Create a new rlm_cache_instance
1462 *
1463 */
1464static int mod_instantiate(module_inst_ctx_t const *mctx)
1465{
1466 rlm_cache_t *inst = talloc_get_type_abort(mctx->mi->data, rlm_cache_t);
1467 CONF_SECTION *conf = mctx->mi->conf;
1468
1469 /*
1470 * Non optional fields and callbacks
1471 */
1472 fr_assert(inst->driver->common.name);
1473 fr_assert(inst->driver->find);
1474 fr_assert(inst->driver->insert);
1475 fr_assert(inst->driver->expire);
1476
1477 if (!fr_time_delta_ispos(inst->config.ttl)) {
1478 cf_log_err(conf, "Must set 'ttl' to non-zero");
1479 return -1;
1480 }
1481
1482 if (inst->config.epoch != 0) {
1483 cf_log_err(conf, "Must not set 'epoch' in the configuration files");
1484 return -1;
1485 }
1486
1487 return 0;
1488}
1489
1490/** Register module xlats
1491 *
1492 */
1493static int mod_bootstrap(module_inst_ctx_t const *mctx)
1494{
1495 xlat_t *xlat;
1496
1497 /*
1498 * Register the cache xlat function
1499 */
1500 xlat = module_rlm_xlat_register(mctx->mi->boot, mctx, NULL, cache_xlat, FR_TYPE_VOID);
1503
1504 xlat = module_rlm_xlat_register(mctx->mi->boot, mctx, "ttl.get", cache_ttl_get_xlat, FR_TYPE_VOID);
1506
1507 return 0;
1508}
1509
1510/*
1511 * The module name should be the only globally exported symbol.
1512 * That is, everything else should be 'static'.
1513 *
1514 * If the module needs to temporarily modify it's instantiation
1515 * data, the type should be changed to MODULE_TYPE_THREAD_UNSAFE.
1516 * The server will then take care of ensuring that the module
1517 * is single-threaded.
1518 */
1520 .common = {
1521 .magic = MODULE_MAGIC_INIT,
1522 .name = "cache",
1523 .inst_size = sizeof(rlm_cache_t),
1525 .bootstrap = mod_bootstrap,
1527 .detach = mod_detach
1528 },
1529 .method_group = {
1530 .bindings = (module_method_binding_t[]){
1531 { .section = SECTION_NAME("clear", CF_IDENT_ANY), .method = mod_method_clear, .method_env = &cache_method_env },
1532 { .section = SECTION_NAME("load", CF_IDENT_ANY), .method = mod_method_load, .method_env = &cache_method_env },
1533 { .section = SECTION_NAME("status", CF_IDENT_ANY), .method = mod_method_status, .method_env = &cache_method_env },
1534 { .section = SECTION_NAME("store", CF_IDENT_ANY), .method = mod_method_store, .method_env = &cache_method_env },
1535 { .section = SECTION_NAME("ttl", CF_IDENT_ANY), .method = mod_method_ttl, .method_env = &cache_method_env },
1536 { .section = SECTION_NAME("update", CF_IDENT_ANY), .method = mod_method_update, .method_env = &cache_method_env },
1537 { .section = SECTION_NAME(CF_IDENT_ANY, CF_IDENT_ANY), .method = mod_cache_it, .method_env = &cache_method_env },
1539 }
1540 }
1541};
Unlang interpreter actions.
unlang_action_t
Returned by unlang_op_t calls, determine the next action of the interpreter.
Definition action.h:35
@ UNLANG_ACTION_CALCULATE_RESULT
Calculate a new section rlm_rcode_t value.
Definition action.h:37
static int const char char buffer[256]
Definition acutest.h:576
#define RCSID(id)
Definition build.h:485
#define FALL_THROUGH
clang 10 doesn't recognised the FALL-THROUGH comment anymore
Definition build.h:324
#define unlikely(_x)
Definition build.h:383
#define UNUSED
Definition build.h:317
void call_env_parsed_free(call_env_parsed_head_t *parsed, call_env_parsed_t *ptr)
Remove a call_env_parsed_t from the list of parsed call envs.
Definition call_env.c:754
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:667
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:724
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:397
#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:658
cf_parse_t func
Override default parsing behaviour for the specified type with a custom parsing function.
Definition cf_parse.h:612
#define FR_CONF_OFFSET(_name, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:284
#define FR_CONF_OFFSET_TYPE_FLAGS(_name, _type, _flags, _struct, _field)
conf_parser_t which parses a single CONF_PAIR, writing the result to a field in a struct
Definition cf_parse.h:241
Defines a CONF_PAIR to C data type mapping.
Definition cf_parse.h:595
Common header for all CONF_* types.
Definition cf_priv.h:49
A section grouping multiple CONF_PAIR.
Definition cf_priv.h:101
CONF_SECTION * cf_item_to_section(CONF_ITEM const *ci)
Cast a CONF_ITEM to a CONF_SECTION.
Definition cf_util.c:683
#define cf_log_err(_cf, _fmt,...)
Definition cf_util.h:289
#define cf_log_perr(_cf, _fmt,...)
Definition cf_util.h:296
#define CF_IDENT_ANY
Definition cf_util.h:78
static void * fr_dcursor_next(fr_dcursor_t *cursor)
Advanced the cursor to the next item.
Definition dcursor.h:290
static int fr_dcursor_append(fr_dcursor_t *cursor, void *v)
Insert a single item at the end of the list.
Definition dcursor.h:408
static void * fr_dcursor_remove(fr_dcursor_t *cursor)
Remove the current item.
Definition dcursor.h:482
static void * fr_dcursor_current(fr_dcursor_t *cursor)
Return the item the cursor current points to.
Definition dcursor.h:339
#define MEM(x)
Definition debug.h:36
fr_dict_attr_t const ** out
Where to write a pointer to the resolved fr_dict_attr_t.
Definition dict.h:274
fr_dict_t const ** out
Where to write a pointer to the loaded/resolved fr_dict_t.
Definition dict.h:287
static bool fr_dict_attr_is_top_level(fr_dict_attr_t const *da)
Return true if this attribute is parented directly off the dictionary root.
Definition dict.h:768
static fr_slen_t in
Definition dict.h:841
Specifies an attribute which must be present for the module to function.
Definition dict.h:273
Specifies a dictionary which must be loaded/loadable for the module to function.
Definition dict.h:286
#define MODULE_MAGIC_INIT
Stop people using different module/library/server versions together.
Definition dl_module.h:63
static xlat_action_t cache_xlat(TALLOC_CTX *ctx, fr_dcursor_t *out, xlat_ctx_t const *xctx, request_t *request, fr_value_box_list_t *in)
Allow single attribute values to be retrieved from the cache.
Definition rlm_cache.c:889
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:1590
int map_afrom_cs(TALLOC_CTX *ctx, map_list_t *out, CONF_SECTION *cs, tmpl_rules_t const *lhs_rules, tmpl_rules_t const *rhs_rules, map_validate_t validate, void *uctx, unsigned int max)
Convert a config section into an attribute map.
Definition map.c:1131
int map_to_request(request_t *request, map_t const *map, radius_map_getvalue_t func, void *ctx)
Convert map_t to fr_pair_t (s) and add them to a request_t.
Definition map.c:1869
ssize_t map_print(fr_sbuff_t *out, map_t const *map)
Print a map to a string.
Definition map.c:2386
void map_debug_log(request_t *request, map_t const *map, fr_pair_t const *vp)
Definition map.c:2441
talloc_free(reap)
fr_type_t
@ FR_TYPE_TIME_DELTA
A period of time measured in nanoseconds.
@ FR_TYPE_STRING
String of printable characters.
@ FR_TYPE_NULL
Invalid (uninitialised) attribute type.
@ FR_TYPE_UINT32
32 Bit unsigned integer.
@ FR_TYPE_INT32
32 Bit signed integer.
@ FR_TYPE_VOID
User data.
@ FR_TYPE_BOOL
A truth value.
long int ssize_t
static bool is_printable(void const *value, size_t len)
Check whether the string is made up of printable UTF8 chars.
Definition misc.h:88
int unlang_fixup_update(map_t *map, void *ctx)
Validate and fixup a map that's part of an update section.
Definition compile.c:460
void * env_data
Per call environment data.
Definition module_ctx.h:44
module_instance_t const * mi
Instance of the module being instantiated.
Definition module_ctx.h:42
module_instance_t * mi
Module instance to detach.
Definition module_ctx.h:57
module_instance_t * mi
Instance of the module being instantiated.
Definition module_ctx.h:51
Temporary structure to hold arguments for module calls.
Definition module_ctx.h:41
Temporary structure to hold arguments for detach calls.
Definition module_ctx.h:56
Temporary structure to hold arguments for instantiation calls.
Definition module_ctx.h:50
xlat_t * module_rlm_xlat_register(TALLOC_CTX *ctx, module_inst_ctx_t const *mctx, char const *name, xlat_func_t func, fr_type_t return_type)
Definition module_rlm.c:243
int module_rlm_submodule_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Generic conf_parser_t func for loading drivers.
Definition module_rlm.c:936
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:697
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:60
#define RETURN_UNLANG_RCODE(_rcode)
Definition rcode.h:66
#define RETURN_UNLANG_NOTFOUND
Definition rcode.h:62
#define RETURN_UNLANG_FAIL
Definition rcode.h:57
#define RETURN_UNLANG_OK
Definition rcode.h:58
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:43
@ RLM_MODULE_FAIL
Module failed, don't reply.
Definition rcode.h:42
@ RLM_MODULE_NOTFOUND
User not found.
Definition rcode.h:47
@ RLM_MODULE_UPDATED
OK (pairs modified).
Definition rcode.h:49
@ RLM_MODULE_NOOP
Module succeeded without doing anything.
Definition rcode.h:48
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
static int mod_detach(module_detach_ctx_t const *mctx)
Free any memory allocated under the instance.
Definition rlm_cache.c:1393
static fr_dict_attr_t const * attr_cache_allow_merge
Definition rlm_cache.c:91
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:68
fr_value_box_t * key
To lookup the cache entry with.
Definition rlm_cache.c:63
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:1215
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:1044
static fr_dict_attr_t const * attr_cache_ttl
Definition rlm_cache.c:93
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:1083
static fr_dict_attr_t const * attr_cache_merge_new
Definition rlm_cache.c:89
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:81
static int cache_verify(map_t *map, void *uctx)
Verify that a map in the cache section makes sense.
Definition rlm_cache.c:1413
map_list_t * maps
Attribute map applied to cache entries.
Definition rlm_cache.c:64
static rlm_cache_entry_t * cache_alloc(rlm_cache_t const *inst, request_t *request)
Allocate a cache entry.
Definition rlm_cache.c:208
static fr_dict_attr_t const * attr_cache_allow_insert
Definition rlm_cache.c:92
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:1493
static fr_dict_attr_t const * attr_cache_status_only
Definition rlm_cache.c:90
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:94
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:1328
static xlat_arg_parser_t const cache_xlat_args[]
Definition rlm_cache.c:879
module_rlm_t rlm_cache
Definition rlm_cache.c:1519
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:1283
static const call_env_method_t cache_method_env
Definition rlm_cache.c:72
fr_dict_attr_autoload_t rlm_cache_dict_attr[]
Definition rlm_cache.c:97
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:84
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:1126
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:960
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:1000
int submodule_parse(TALLOC_CTX *ctx, void *out, void *parent, CONF_ITEM *ci, conf_parser_t const *rule)
Definition rlm_cache.c:107
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:50
static int mod_instantiate(module_inst_ctx_t const *mctx)
Create a new rlm_cache_instance.
Definition rlm_cache.c:1464
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:621
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
static int instantiate(module_inst_ctx_t const *mctx)
Definition rlm_rest.c:1297
#define FR_SBUFF_IN(_start, _len_or_end)
#define FR_SBUFF_OUT(_start, _len_or_end)
#define SECTION_NAME(_name1, _name2)
Define a section name consisting of a verb and a noun.
Definition section.h:40
#define MAP_VERIFY(_x)
Definition map.h:108
char const * name
Instance name e.g. user_database.
Definition module.h:355
CONF_SECTION * conf
Module's instance configuration.
Definition module.h:349
size_t inst_size
Size of the module's instance data.
Definition module.h:212
void * data
Module's instance data.
Definition module.h:291
void * boot
Data allocated during the boostrap phase.
Definition module.h:294
#define MODULE_BINDING_TERMINATOR
Terminate a module binding list.
Definition module.h:152
module_t * exported
Public module structure.
Definition module.h:296
Module instance data.
Definition module.h:285
Named methods exported by a module.
Definition module.h:174
#define tmpl_value(_tmpl)
Definition tmpl.h:937
tmpl_t * tmpl_alloc(TALLOC_CTX *ctx, tmpl_type_t type, fr_token_t quote, char const *name, ssize_t len)
Create a new heap allocated tmpl_t.
#define tmpl_is_attr(vpt)
Definition tmpl.h:208
static fr_dict_attr_t const * tmpl_list(tmpl_t const *vpt)
Definition tmpl.h:904
@ TMPL_TYPE_ATTR
Reference to one or more attributes.
Definition tmpl.h:142
@ TMPL_TYPE_DATA
Value in native boxed format.
Definition tmpl.h:138
int tmpl_attr_afrom_list(TALLOC_CTX *ctx, tmpl_t **out, tmpl_t const *list, fr_dict_attr_t const *da)
Create a new tmpl from a list tmpl and a da.
static bool tmpl_attr_tail_da_is_structural(tmpl_t const *vpt)
Return true if the the last attribute reference is a structural attribute.
Definition tmpl.h:835
static bool tmpl_is_list(tmpl_t const *vpt)
Definition tmpl.h:920
ssize_t tmpl_afrom_attr_substr(TALLOC_CTX *ctx, tmpl_attr_error_t *err, tmpl_t **out, fr_sbuff_t *name, fr_sbuff_parse_rules_t const *p_rules, tmpl_rules_t const *t_rules))
Parse a string into a TMPL_TYPE_ATTR_* type tmpl_t.
static fr_type_t tmpl_cast_get(tmpl_t *vpt)
Definition tmpl.h:1218
static fr_dict_attr_t const * tmpl_attr_tail_da(tmpl_t const *vpt)
Return the last attribute reference da.
Definition tmpl.h:801
int tmpl_cast_set(tmpl_t *vpt, fr_type_t type)
Set a cast for a tmpl.
fr_type_t tmpl_expanded_type(tmpl_t const *vpt)
Return the native data type of the expression.
Definition tmpl_eval.c:203
Optional arguments passed to vp_tmpl functions.
Definition tmpl.h:332
eap_aka_sim_process_conf_t * inst
fr_pair_t * vp
Value pair map.
Definition map.h:77
fr_token_t op
The operator that controls insertion of the dst attribute.
Definition map.h:82
tmpl_t * lhs
Typically describes the attribute to add, modify or compare.
Definition map.h:78
map_list_t child
parent map, for nested ones
Definition map.h:89
tmpl_t * rhs
Typically describes a literal value or a src attribute to copy or compare.
Definition map.h:79
CONF_ITEM * ci
Config item that the map was created from.
Definition map.h:85
Stores an attribute, a value and various bits of other data.
Definition pair.h:68
fr_dict_attr_t const *_CONST da
Dictionary attribute defines the attribute number, vendor and type of the pair.
Definition pair.h:69
#define talloc_get_type_abort_const
Definition talloc.h:287
static fr_time_delta_t fr_time_delta_from_sec(int64_t sec)
Definition time.h:590
#define fr_time_delta_ispos(_a)
Definition time.h:290
static fr_unix_time_t fr_unix_time_from_sec(int64_t sec)
Definition time.h:449
#define fr_unix_time_sub(_a, _b)
Subtract one time from another.
Definition time.h:357
static fr_unix_time_t fr_time_to_unix_time(fr_time_t when)
Convert an fr_time_t (internal time) to our version of unix time (wallclock time)
Definition time.h:688
#define fr_unix_time_lt(_a, _b)
Definition time.h:367
#define fr_unix_time_add(_a, _b)
Add a time/time delta together.
Definition time.h:324
A time delta, a difference in time measured in nanoseconds.
Definition time.h:80
const bool fr_assignment_op[T_TOKEN_LAST]
Definition token.c:169
char const * fr_tokens[T_TOKEN_LAST]
Definition token.c:79
enum fr_token fr_token_t
@ T_SINGLE_QUOTED_STRING
Definition token.h:122
@ T_BARE_WORD
Definition token.h:120
@ T_DOUBLE_QUOTED_STRING
Definition token.h:121
uint8_t required
Argument must be present, and non-empty.
Definition xlat.h:146
#define XLAT_ARG_PARSER_TERMINATOR
Definition xlat.h:170
xlat_action_t
Definition xlat.h:37
@ XLAT_ACTION_FAIL
An xlat function failed.
Definition xlat.h:44
@ XLAT_ACTION_DONE
We're done evaluating this level of nesting.
Definition xlat.h:43
Definition for a single argument consumend by an xlat function.
Definition xlat.h:145
fr_pair_t * fr_pair_list_next(fr_pair_list_t const *list, fr_pair_t const *item))
Get the next item in a valuepair list after a specific entry.
Definition pair_inline.c:69
#define fr_pair_dcursor_init(_cursor, _list)
Initialises a special dcursor with callbacks that will maintain the attr sublists correctly.
Definition pair.h:587
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:839
#define fr_type_is_variable_size(_x)
Definition types.h:384
static char const * fr_type_to_str(fr_type_t type)
Return a static string containing the type name.
Definition types.h:450
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:3962
#define fr_value_box_alloc(_ctx, _type, _enumv)
Allocate a value box of a specific type.
Definition value.h:640
#define fr_box_time_delta(_val)
Definition value.h:362
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:651
#define fr_box_time(_val)
Definition value.h:345
static size_t char ** out
Definition value.h:1020
#define fr_box_date(_val)
Definition value.h:343
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