From: Arran Cudbard-Bell Date: Thu, 23 Aug 2012 15:58:50 +0000 (+0100) Subject: Add 'Cache-Status-Only' control attribute, to check the status of X-Git-Tag: release_2_2_0~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4fa67bc0daf6928307da0c8671c6a20cfc420ed8;p=thirdparty%2Ffreeradius-server.git Add 'Cache-Status-Only' control attribute, to check the status of an entry, but not add or merge it. Update documentation. Only control:Cache-TTL may extend the TTL of an entry, or expire an entry. --- diff --git a/raddb/modules/cache b/raddb/modules/cache index 5e42a626046..902ae358d41 100644 --- a/raddb/modules/cache +++ b/raddb/modules/cache @@ -15,8 +15,8 @@ # If you want different things cached for authorize and post-auth, # you will need to define two instances of the "cache" module. # -# The module returns "updated" if it found a cache entry. -# The module returns "ok" if it added a new cache entry. +# The module returns "ok" if it found a cache entry. +# The module returns "updated" if it added a new cache entry. # The module returns "noop" if it did nothing. # cache { @@ -43,6 +43,16 @@ cache { # # You should ALWAYS leave it as "epoch = 0" here. epoch = 0 + + # The module can also operate in status-only mode where it will + # not add new cache entries, or merge existing ones. + # + # To enable set the control variable "Cache-Status-Only" to "yes" + # The module will return "ok" if it found a cache entry. + # The module will return "notfound" if it failed to find a cache entry, + # or the entry had expired. + # + # Note: expired entries will still be removed. # The list of attributes to cache for a particular key. # Each key gets the same set of cached attributes. @@ -51,9 +61,11 @@ cache { # You can specify which list the attribute goes into by # prefixing the attribute name with the list. This allows # you to update multiple lists with one configuration. - update cache { + # + # If no list is specified the request list will be updated. + attributes { # list:Attr-Name - reply:Filter-Id += "%l" + reply:Reply-Message += "I'm the cached reply from %t" control:Class := 0x010203 } diff --git a/share/dictionary.freeradius.internal b/share/dictionary.freeradius.internal index 04859b13490..177191055a7 100644 --- a/share/dictionary.freeradius.internal +++ b/share/dictionary.freeradius.internal @@ -219,7 +219,10 @@ ATTRIBUTE MS-CHAP-Password 1133 string ATTRIBUTE Packet-Transmit-Counter 1134 integer ATTRIBUTE Cached-Session-Policy 1135 string ATTRIBUTE Cache-TTL 1136 integer +ATTRIBUTE Cache-Status-Only 1137 integer +VALUE Cache-Status-Only no 0 +VALUE Cache-Status-Only yes 1 # # Range: 1200-1279 # EAP-SIM (and other EAP type) weirdness. diff --git a/src/include/radius.h b/src/include/radius.h index 0b577232290..775ec5c90af 100644 --- a/src/include/radius.h +++ b/src/include/radius.h @@ -233,6 +233,7 @@ #define PW_PACKET_TRANSMIT_COUNTER 1134 #define PW_CACHED_SESSION_POLICY 1135 #define PW_CACHE_TTL 1136 +#define PW_CACHE_STATUS_ONLY 1137 /* * Integer Translations diff --git a/src/modules/rlm_cache/rlm_cache.c b/src/modules/rlm_cache/rlm_cache.c index 6a651bec33b..d711356a7a5 100644 --- a/src/modules/rlm_cache/rlm_cache.c +++ b/src/modules/rlm_cache/rlm_cache.c @@ -17,8 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA * - * Copyright 2000,2006 The FreeRADIUS server project - * Copyright 2000 your name + * Copyright 2012 The FreeRADIUS server project */ #include @@ -166,11 +165,16 @@ static rlm_cache_entry_t *cache_find(rlm_cache_t *inst, REQUEST *request, if ((c->expires < request->timestamp) || (c->created < inst->epoch)) { delete: + DEBUG("rlm_cache: Entry has expired, removing"); + fr_heap_extract(inst->heap, c); rbtree_deletebydata(inst->cache, c); + return NULL; } + DEBUG("rlm_cache: Found entry for \"%s\"", key); + /* * Update the expiry time based on the TTL. * A TTL of 0 means "delete from the cache". @@ -178,16 +182,12 @@ static rlm_cache_entry_t *cache_find(rlm_cache_t *inst, REQUEST *request, vp = pairfind(request->config_items, PW_CACHE_TTL); if (vp) { if (vp->vp_integer == 0) goto delete; - + ttl = vp->vp_integer; - } else { - ttl = inst->ttl; + c->expires = request->timestamp + ttl; + DEBUG("rlm_cache: Adding %d to the TTL", ttl); } - DEBUG("rlm_cache: Found entry for \"%s\". Adding %d to the TTL", - key, ttl); - c->expires = request->timestamp + ttl; - return c; } @@ -354,7 +354,7 @@ static const CONF_PARSER module_config[] = { { "ttl", PW_TYPE_INTEGER, offsetof(rlm_cache_t, ttl), NULL, "500" }, { "epoch", PW_TYPE_INTEGER, - offsetof(rlm_cache_t, epoch), NULL, NULL }, + offsetof(rlm_cache_t, epoch), NULL, "0" }, { NULL, -1, 0, NULL, NULL } /* end the list */ }; @@ -410,6 +410,12 @@ static int cache_instantiate(CONF_SECTION *conf, void **instance) cache_detach(inst); return -1; } + + if (inst->epoch != 0){ + radlog(L_ERR, "rlm_cache: Epoch should only be set dynamically"); + cache_detach(inst); + return -1; + } /* * The cache. @@ -431,6 +437,7 @@ static int cache_instantiate(CONF_SECTION *conf, void **instance) cache_detach(inst); return -1; } + inst->cs = cf_section_sub_find(conf, "update"); if (!inst->cs) { @@ -463,14 +470,26 @@ static int cache_it(void *instance, REQUEST *request) { rlm_cache_entry_t *c; rlm_cache_t *inst = instance; + VALUE_PAIR *vp; char buffer[1024]; radius_xlat(buffer, sizeof(buffer), inst->key, request, NULL); c = cache_find(inst, request, buffer); + + /* + * If yes, only return whether we found a valid cache entry + */ + vp = pairfind(request->config_items, PW_CACHE_STATUS_ONLY); + if (vp && vp->vp_integer) { + return c ? + RLM_MODULE_OK: + RLM_MODULE_NOTFOUND; + } + if (c) { cache_merge(request, c); - return RLM_MODULE_UPDATED; + return RLM_MODULE_OK; } c = cache_add(inst, request, buffer); @@ -478,7 +497,7 @@ static int cache_it(void *instance, REQUEST *request) cache_merge(request, c); - return RLM_MODULE_OK; + return RLM_MODULE_UPDATED; }